home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / Component.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.3 KB  |  286 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.    Component.cpp -- class for all XFE thingy's which have a widget.
  20.    Created: Chris Toshok <toshok@netscape.com>, 7-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "mozilla.h"
  26. #include "xfe.h"
  27.  
  28. #include "Component.h"
  29. #include "xpassert.h"
  30.  
  31. #include <Xfe/Xfe.h>
  32.  
  33. // Callback message strings.  (Comment about these declarations in header file)
  34.  
  35. const char *XFE_Component::afterRealizeCallback = "XFE_Component::afterRealizeCallback";
  36.  
  37.  
  38. XFE_Component::XFE_Component(XFE_Component *toplevel_component)
  39. {
  40.   m_widget = 0;
  41.   m_toplevel = toplevel_component;
  42. }
  43.  
  44. XFE_Component::XFE_Component(Widget w, XFE_Component *toplevel_component)
  45. {
  46.   m_widget = w;
  47.   m_toplevel = toplevel_component;
  48. }
  49.  
  50. XFE_Component::~XFE_Component()
  51. {
  52.     //
  53.     // delete the widget tree rooted at this frame.
  54.     //
  55.     if (m_widget)
  56.     {
  57.         // first we remove the callback to avoid deleting ourselves twice.
  58.         XtRemoveCallback(m_widget, XmNdestroyCallback, destroy_cb, this);
  59.         
  60.         if (XfeIsAlive(m_widget))
  61.         {
  62.             // then we destroy the widget.
  63.             XtDestroyWidget(m_widget);
  64.         }
  65.         
  66.         m_widget = 0;
  67.     }
  68. }
  69.  
  70. Widget
  71. XFE_Component::getBaseWidget()
  72. {
  73.   return m_widget;
  74. }
  75.  
  76. void
  77. XFE_Component::setBaseWidget(Widget w)
  78. {
  79.   /* we don't allow reassigning the base widget of a component. */
  80.   XP_ASSERT(m_widget == 0);
  81.  
  82.   m_widget = w;
  83. }
  84.  
  85.  
  86. void
  87. XFE_Component::setSensitive(Boolean sensitive)
  88. {
  89.   XtSetSensitive(m_widget, sensitive);
  90. }
  91.  
  92. Boolean
  93. XFE_Component::isSensitive()
  94. {
  95.   return XtIsSensitive(m_widget);
  96. }
  97.  
  98. XFE_Component *
  99. XFE_Component::getToplevel()
  100. {
  101.   return m_toplevel;
  102. }
  103.  
  104. XP_Bool
  105. XFE_Component::isShown()
  106. {
  107.   return XtIsManaged(m_widget);
  108. }
  109.  
  110. XP_Bool
  111. XFE_Component::isAlive()
  112. {
  113.   return XfeIsAlive(m_widget);
  114. }
  115.  
  116.  
  117. void
  118. XFE_Component::show()
  119. {
  120.   XtManageChild(m_widget);
  121. }
  122.  
  123. void
  124. XFE_Component::hide()
  125. {
  126.   XtUnmanageChild(m_widget);
  127. }
  128.  
  129. void
  130. XFE_Component::setManagedState(XP_Bool state)
  131. {
  132.   XfeSetManagedState(m_widget,state);
  133. }
  134.  
  135. void
  136. XFE_Component::toggleManagedState()
  137. {
  138.   XfeToggleManagedState(m_widget);
  139. }
  140.  
  141. fe_colormap *
  142. XFE_Component::getColormap()
  143. {
  144.   XP_ASSERT(0);
  145.   return NULL;
  146. }
  147.  
  148.  
  149. void
  150. XFE_Component::translateFromRootCoords(int x_root, int y_root, 
  151.                        int *x, int *y)
  152. {
  153.   Position my_xroot, my_yroot;
  154.  
  155.   XtTranslateCoords(m_widget, 0, 0, &my_xroot, &my_yroot);
  156.  
  157.   *x = x_root - my_xroot;
  158.   *y = y_root - my_yroot;
  159. }
  160.  
  161. Boolean 
  162. XFE_Component::isWidgetInside(Widget w)
  163. {
  164.   Widget cur;
  165.  
  166.   cur = w;
  167.  
  168.   while (!XtIsShell(cur)
  169.      && cur != m_widget)
  170.     cur = XtParent(cur);
  171.  
  172.   if (cur == m_widget)
  173.     {
  174.       return True;
  175.     }
  176.   else
  177.     {
  178.       return False;
  179.     }
  180. }
  181.  
  182. Pixel
  183. XFE_Component::getFGPixel()
  184. {
  185.   return m_toplevel->getFGPixel();
  186. }
  187.  
  188. Pixel
  189. XFE_Component::getBGPixel()
  190. {
  191.   return m_toplevel->getFGPixel();
  192. }
  193.  
  194. Pixel
  195. XFE_Component::getTopShadowPixel()
  196. {
  197.   return m_toplevel->getFGPixel();
  198. }
  199.  
  200. Pixel
  201. XFE_Component::getBottomShadowPixel()
  202. {
  203.   return m_toplevel->getFGPixel();
  204. }
  205.  
  206. char *
  207. XFE_Component::stringFromResource(char *command_string)
  208. {
  209.   return XfeSubResourceGetWidgetStringValue(m_widget, 
  210.                                             command_string, 
  211.                                             command_string /* XXX */);
  212. }
  213.  
  214. // use this method to get 'cmd.labelString' resources
  215. // for the specified widget (default is the base widget)
  216. char *
  217. XFE_Component::getLabelString(char* cmd, Widget widget)
  218. {
  219.     if (!widget) {
  220.         widget = getBaseWidget();
  221.         if (!widget)
  222.             return NULL;
  223.     }
  224.  
  225.     return XfeSubResourceGetStringValue(widget,
  226.                                         cmd,
  227.                                         XfeClassNameForWidget(widget),
  228.                                         XmNlabelString,
  229.                                         XmCLabelString,
  230.                                         NULL);
  231. }
  232.  
  233. // use this method to get 'cmd.[show|hide]LabelString' resources
  234. // for the specified widget (default is the base widget)
  235. char*
  236. XFE_Component::getShowHideLabelString(char* cmd, Boolean show, Widget widget)
  237. {
  238.     char* name;
  239.  
  240.     if (!widget) {
  241.         widget = getBaseWidget();
  242.         if (!widget)
  243.             return NULL;
  244.     }
  245.  
  246.     if (show)
  247.         name = "showLabelString";
  248.     else
  249.         name = "hideLabelString";
  250.  
  251.     return XfeSubResourceGetStringValue(widget,
  252.                                         cmd,
  253.                                         XfeClassNameForWidget(widget),
  254.                                         name,
  255.                                         XmCLabelString,
  256.                                         NULL);
  257. }
  258.  
  259. void
  260. XFE_Component::installDestroyHandler()
  261. {
  262.   XtAddCallback(m_widget, XmNdestroyCallback, destroy_cb, this);
  263. }
  264.  
  265. void
  266. XFE_Component::destroy_cb(Widget, XtPointer cd, XtPointer)
  267. {
  268.   XFE_Component *obj = (XFE_Component*)cd;
  269.  
  270.   delete obj;
  271. }
  272.  
  273. char *
  274. XFE_Component::getDocString(CommandType /* cmd */)
  275. {
  276.    return NULL;
  277. }
  278.  
  279. char *
  280. XFE_Component::getTipString(CommandType /* cmd */)
  281. {
  282.    return NULL;
  283. }
  284.  
  285.  
  286.