]> git.saurik.com Git - wxWidgets.git/blame - src/motif/mdi/lib/XsComponent.C
(blind) fix for gcc 3.4 warning for an always true comparison in an assert
[wxWidgets.git] / src / motif / mdi / lib / XsComponent.C
CommitLineData
8704bf74
JS
1/*
2 Copyright (C) 1996 Scott W. Sadler
3 All rights reserved.
4*/
5
6/*
7 XsComponent.C
8
9 History
0d57be45 10 03-Mar-96 1.0; Scott W. Sadler (ssadler@cisco.com)
8704bf74
JS
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
28XsComponent::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
45XsComponent::~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
61void XsComponent::show ( )
62{
63
64#ifndef NDEBUG
0d57be45
JS
65 // if (XtIsManaged (_base))
66 // cout << "Re-managing a widget:" << _name << endl;
8704bf74
JS
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
79void XsComponent::hide ( )
80{
81
82#ifndef NDEBUG
0d57be45
JS
83 // if (!XtIsManaged (_base))
84 // cout << "Re-unmanaging a widget:" << _name << endl;
8704bf74
JS
85#endif
86
87 assert (_base != 0);
88 XtUnmanageChild (_base);
89}
90
91// Conversion operator
92
93XsComponent::operator Widget ( ) const
94{
95 assert (_base != 0);
96 return (_base);
97}
98
99// operator ==
100
101Boolean XsComponent::operator == (const XsComponent& rval)
102{
103 return (_base == rval._base);
104}
105
106// className
107
108const char* XsComponent::className ( ) const
109{
110 return ("XsComponent");
111}
112
113// _installDestroyHandler
114
115void 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
126void 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
137void XsComponent::_componentDestroyed ( )
138{
139 _base = 0;
140}
141
142// _componentDestroyedCallback
143
144void XsComponent::_componentDestroyedCallback (Widget, XtPointer clientData, XtPointer)
145{
146 XsComponent *obj = (XsComponent*)clientData;
147 obj->_componentDestroyed ( );
148}
149
150// _setResources
151
152void 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
186void 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