]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | Copyright (C) 1996 Scott W. Sadler | |
3 | All rights reserved. | |
4 | */ | |
5 | ||
6 | /* | |
7 | XsComponent.C | |
8 | ||
9 | History | |
10 | 03-Mar-96 1.0; Scott W. Sadler (ssadler@cisco.com) | |
11 | Created | |
12 | */ | |
13 | ||
14 | // Includes | |
15 | ||
16 | #ifndef NDEBUG | |
17 | #include <iostream.h> | |
18 | #endif | |
19 | ||
20 | #include <assert.h> | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | #include <Xm/Xm.h> | |
24 | #include "XsComponent.h" | |
25 | ||
26 | // Constructor | |
27 | ||
28 | XsComponent::XsComponent (const char *name) | |
29 | { | |
30 | assert (name != 0); | |
31 | ||
32 | // Initialize | |
33 | ||
34 | _base = 0; | |
35 | ||
36 | // Copy component name | |
37 | ||
38 | int len = strlen (name); | |
39 | _name = new char [len + 1]; | |
40 | strcpy (_name, name); | |
41 | } | |
42 | ||
43 | // Destructor | |
44 | ||
45 | XsComponent::~XsComponent ( ) | |
46 | { | |
47 | ||
48 | // Destroy the widget | |
49 | ||
50 | if (_base != 0) | |
51 | { | |
52 | _removeDestroyHandler ( ); | |
53 | XtDestroyWidget (_base); | |
54 | } | |
55 | ||
56 | delete [] _name; | |
57 | } | |
58 | ||
59 | // show | |
60 | ||
61 | void XsComponent::show ( ) | |
62 | { | |
63 | ||
64 | #ifndef NDEBUG | |
65 | // if (XtIsManaged (_base)) | |
66 | // cout << "Re-managing a widget:" << _name << endl; | |
67 | #endif | |
68 | ||
69 | // Make sure the _destroyHandler was installed | |
70 | ||
71 | assert (XtHasCallbacks (_base, XmNdestroyCallback) == XtCallbackHasSome); | |
72 | ||
73 | assert (_base != 0); | |
74 | XtManageChild (_base); | |
75 | } | |
76 | ||
77 | // hide | |
78 | ||
79 | void XsComponent::hide ( ) | |
80 | { | |
81 | ||
82 | #ifndef NDEBUG | |
83 | // if (!XtIsManaged (_base)) | |
84 | // cout << "Re-unmanaging a widget:" << _name << endl; | |
85 | #endif | |
86 | ||
87 | assert (_base != 0); | |
88 | XtUnmanageChild (_base); | |
89 | } | |
90 | ||
91 | // Conversion operator | |
92 | ||
93 | XsComponent::operator Widget ( ) const | |
94 | { | |
95 | assert (_base != 0); | |
96 | return (_base); | |
97 | } | |
98 | ||
99 | // operator == | |
100 | ||
101 | Boolean XsComponent::operator == (const XsComponent& rval) | |
102 | { | |
103 | return (_base == rval._base); | |
104 | } | |
105 | ||
106 | // className | |
107 | ||
108 | const char* XsComponent::className ( ) const | |
109 | { | |
110 | return ("XsComponent"); | |
111 | } | |
112 | ||
113 | // _installDestroyHandler | |
114 | ||
115 | void XsComponent::_installDestroyHandler ( ) | |
116 | { | |
117 | assert (_base != 0); | |
118 | ||
119 | // Install the destroy handler | |
120 | ||
121 | XtAddCallback (_base, XmNdestroyCallback, _componentDestroyedCallback, (XtPointer)this); | |
122 | } | |
123 | ||
124 | // _removeDestroyHandler | |
125 | ||
126 | void XsComponent::_removeDestroyHandler ( ) | |
127 | { | |
128 | assert (_base != 0); | |
129 | ||
130 | // Remove the destroy handler | |
131 | ||
132 | XtRemoveCallback (_base, XmNdestroyCallback, _componentDestroyedCallback, (XtPointer)this); | |
133 | } | |
134 | ||
135 | // _componentDestroyed | |
136 | ||
137 | void XsComponent::_componentDestroyed ( ) | |
138 | { | |
139 | _base = 0; | |
140 | } | |
141 | ||
142 | // _componentDestroyedCallback | |
143 | ||
144 | void XsComponent::_componentDestroyedCallback (Widget, XtPointer clientData, XtPointer) | |
145 | { | |
146 | XsComponent *obj = (XsComponent*)clientData; | |
147 | obj->_componentDestroyed ( ); | |
148 | } | |
149 | ||
150 | // _setResources | |
151 | ||
152 | void XsComponent::_setResources (Widget w, const String *resources) | |
153 | { | |
154 | assert (w != 0); | |
155 | ||
156 | XrmDatabase rdb = 0; | |
157 | const int bufSize = 200; | |
158 | char buffer[bufSize]; | |
159 | int loop; | |
160 | ||
161 | // Create an empty resource database | |
162 | ||
163 | rdb = XrmGetStringDatabase (""); | |
164 | ||
165 | // Add the component resources | |
166 | ||
167 | loop = 0; | |
168 | while (resources[loop] != 0) | |
169 | { | |
170 | sprintf (buffer, "*%s%s\n", _name, resources[loop++]); | |
171 | assert (strlen (buffer) < bufSize); | |
172 | XrmPutLineResource (&rdb, buffer); | |
173 | } | |
174 | ||
175 | // Merge these resources into the database | |
176 | ||
177 | if (rdb != 0) | |
178 | { | |
179 | XrmDatabase db = XtDatabase (XtDisplay (w)); | |
180 | XrmCombineDatabase (rdb, &db, FALSE); | |
181 | } | |
182 | } | |
183 | ||
184 | // _getResources | |
185 | ||
186 | void XsComponent::_getResources (const XtResourceList resources, int num) | |
187 | { | |
188 | assert (_base != 0); | |
189 | assert (resources != 0); | |
190 | ||
191 | // Validate input | |
192 | ||
193 | if (num <= 0) | |
194 | return; | |
195 | ||
196 | // Get the subresources | |
197 | ||
198 | XtGetSubresources (XtParent (_base), (XtPointer)this, _name, | |
199 | className ( ), resources, num, 0, 0); | |
200 | } | |
201 |