2 Copyright (C) 1996 Scott W. Sadler
10 03-Mar-96 1.0; Scott W. Sadler (ssadler@cisco.com)
24 #include "XsComponent.h"
28 XsComponent::XsComponent (const char *name)
36 // Copy component name
38 int len = strlen (name);
39 _name = new char [len + 1];
45 XsComponent::~XsComponent ( )
52 _removeDestroyHandler ( );
53 XtDestroyWidget (_base);
61 void XsComponent::show ( )
65 // if (XtIsManaged (_base))
66 // cout << "Re-managing a widget:" << _name << endl;
69 // Make sure the _destroyHandler was installed
71 assert (XtHasCallbacks (_base, XmNdestroyCallback) == XtCallbackHasSome);
74 XtManageChild (_base);
79 void XsComponent::hide ( )
83 // if (!XtIsManaged (_base))
84 // cout << "Re-unmanaging a widget:" << _name << endl;
88 XtUnmanageChild (_base);
91 // Conversion operator
93 XsComponent::operator Widget ( ) const
101 Boolean XsComponent::operator == (const XsComponent& rval)
103 return (_base == rval._base);
108 const char* XsComponent::className ( ) const
110 return ("XsComponent");
113 // _installDestroyHandler
115 void XsComponent::_installDestroyHandler ( )
119 // Install the destroy handler
121 XtAddCallback (_base, XmNdestroyCallback, _componentDestroyedCallback, (XtPointer)this);
124 // _removeDestroyHandler
126 void XsComponent::_removeDestroyHandler ( )
130 // Remove the destroy handler
132 XtRemoveCallback (_base, XmNdestroyCallback, _componentDestroyedCallback, (XtPointer)this);
135 // _componentDestroyed
137 void XsComponent::_componentDestroyed ( )
142 // _componentDestroyedCallback
144 void XsComponent::_componentDestroyedCallback (Widget, XtPointer clientData, XtPointer)
146 XsComponent *obj = (XsComponent*)clientData;
147 obj->_componentDestroyed ( );
152 void XsComponent::_setResources (Widget w, const String *resources)
157 const int bufSize = 200;
158 char buffer[bufSize];
161 // Create an empty resource database
163 rdb = XrmGetStringDatabase ("");
165 // Add the component resources
168 while (resources[loop] != 0)
170 sprintf (buffer, "*%s%s\n", _name, resources[loop++]);
171 assert (strlen (buffer) < bufSize);
172 XrmPutLineResource (&rdb, buffer);
175 // Merge these resources into the database
179 XrmDatabase db = XtDatabase (XtDisplay (w));
180 XrmCombineDatabase (rdb, &db, FALSE);
186 void XsComponent::_getResources (const XtResourceList resources, int num)
189 assert (resources != 0);
196 // Get the subresources
198 XtGetSubresources (XtParent (_base), (XtPointer)this, _name,
199 className ( ), resources, num, 0, 0);