Debian Codegraph @

libSoXt/src/motif/SoXtMltSldr.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990-93 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.3 $
44 |
45 | Classes:
46 | Multiple slider within one container for grouping values
47 |
48 | Author(s) : Paul Isaacs
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54
55
56 #include "SoXtMultiSlider.h"
57 #include "SoXtSliderTool.h"
58 #include <X11/StringDefs.h>
59 #include <Xm/Form.h>
60 #include <Inventor/errors/SoDebugError.h>
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Public constructor - build the widget right now
65 //
66 SoXtMultiSlider::SoXtMultiSlider(
67 Widget parent,
68 const char *name,
69 SbBool buildInsideParent)
70 : SoXtSliderSetBase(
71 parent,
72 name,
73 buildInsideParent,
74 NULL)
75 //
76 ////////////////////////////////////////////////////////////////////////
77 {
78 // In this case, this component is what the app wants, so buildNow = TRUE
79 constructorCommon(TRUE);
80 }
81
82 ////////////////////////////////////////////////////////////////////////
83 //
84 // SoEXTENDER constructor - the subclass tells us whether to build or not
85 //
86 SoXtMultiSlider::SoXtMultiSlider(
87 Widget parent,
88 const char *name,
89 SbBool buildInsideParent,
90 SbBool buildNow)
91 : SoXtSliderSetBase(
92 parent,
93 name,
94 buildInsideParent,
95 NULL)
96 //
97 ////////////////////////////////////////////////////////////////////////
98 {
99 // In this case, this component may be what the app wants,
100 // or it may want a subclass of this component. Pass along buildNow
101 // as it was passed to us.
102 constructorCommon(buildNow);
103 }
104
105 ///////////////////////////////////////////////////////////////////////
106 //
107 // Called by the constructors.
108 //
109 // Use: public
110 void
111 SoXtMultiSlider::constructorCommon(SbBool buildNow)
112 //
113 //////////////////////////////////////////////////////////////////////
114 {
115 addVisibilityChangeCallback(visibilityChangeCB, this);
116 inventorSensor = NULL;
117
118 // Build the widget tree, and let SoXtComponent know about our base widget.
119 if (buildNow) {
120 Widget w = buildWidget(getParentWidget());
121 setBaseWidget(w);
122 }
123 }
124
125 SoXtMultiSlider::~SoXtMultiSlider()
126 {
127 if (inventorSensor != NULL)
128 delete inventorSensor;
129 }
130
131 // Subclasses should call this to build a form,
132 // then create their _subComponentArray, then
133 // call buildWidget.
134 Widget
135 SoXtMultiSlider::buildForm(Widget parent)
136 {
137 widget = XtCreateManagedWidget(
138 getWidgetName(), xmFormWidgetClass, parent, NULL, 0);
139
140 return widget;
141 }
142
143 Widget
144 SoXtMultiSlider::buildWidget( Widget parent )
145 {
146 Arg wargs[10];
147 int nargs, topPos, bottomPos;
148 Widget theContainer;
149
150 #ifdef DEBUG
151 // sanity check
152 if (widget != parent)
153 fprintf(stderr, "INTERNAL ERROR SoXtMultiSlider::buildWidget - widget != parent\n");
154 #endif
155
156 nargs = 0;
157 //???XtSetArg( wargs[nargs], XmNtopAttachment, XmATTACH_POSITION); nargs++;
158 XtSetArg( wargs[nargs], XmNtopAttachment, XmATTACH_FORM); nargs++;
159 XtSetArg( wargs[nargs], XmNbottomAttachment, XmATTACH_FORM); nargs++;
160 XtSetArg( wargs[nargs], XmNleftAttachment, XmATTACH_FORM); nargs++;
161 XtSetArg( wargs[nargs], XmNrightAttachment, XmATTACH_FORM); nargs++;
162 XtSetValues( widget, wargs, nargs );
163
164 // set sizes of the subComponents
165 for ( int i = 0; i < _numSubComponents; i++ ) {
166
167 // set its relative size in the container
168 theContainer = ((SoXtSliderTool *) _subComponentArray[i])->getContainer();
169 topPos = (int) (100.0 * ((float) i /(float) _numSubComponents));
170 bottomPos = (int) (100.0 * ((float) (i + 1)/(float) _numSubComponents));
171 nargs = 0;
172 XtSetArg( wargs[nargs], XmNtopAttachment, XmATTACH_POSITION); nargs++;
173 XtSetArg( wargs[nargs], XmNtopPosition, topPos ); nargs++;
174 XtSetArg( wargs[nargs], XmNbottomAttachment, XmATTACH_POSITION);nargs++;
175 XtSetArg( wargs[nargs], XmNbottomPosition, bottomPos ); nargs++;
176 XtSetArg( wargs[nargs], XmNleftAttachment, XmATTACH_FORM); nargs++;
177 XtSetArg( wargs[nargs], XmNrightAttachment, XmATTACH_FORM); nargs++;
178 XtSetValues( theContainer, wargs, nargs );
179 }
180
181 importValuesFromInventor();
182 makeSensor();
183
184 return widget;
185 }
186
187 void
188 SoXtMultiSlider::setNode( SoNode *newNode )
189 {
190 if ((newNode != NULL) && (! validNodeType(newNode))) {
191 #ifdef DEBUG
192 SoDebugError::post("SoXtMultiSlider::setNode",
193 "- node is not valid type\n");
194 #endif
195 return;
196 }
197
198 if (newNode) // ref the input
199 newNode->ref();
200
201 if (_editNode) // out with the old
202 _editNode->unref();
203
204 _editNode = newNode;
205 for( int i = 0; i < _numSubComponents; i++ )
206 _subComponentArray[i]->setNode( newNode );
207
208 /* connect new node */
209 makeSensor();
210
211 /* copy values from node into slider */
212 if (widget)
213 importValuesFromInventor();
214 }
215
216 // sensor callback
217 void
218 SoXtMultiSlider::inventorCallback( SoXtMultiSlider *slider, SoSensor * )
219 {
220 if (!slider->isVisible())
221 return;
222
223 slider->importValuesFromInventor();
224 }
225
226 void
227 SoXtMultiSlider::makeSensor()
228 {
229 if ( widget && _editNode) {
230 if ( !inventorSensor ) {
231 inventorSensor = new SoNodeSensor((SoSensorCB *)
232 &SoXtMultiSlider::inventorCallback,
233 this);
234 }
235 deactivate();
236 activate();
237 }
238 }
239
240 //
241 // called whenever the component becomes visibble or not
242 //
243 void
244 SoXtMultiSlider::visibilityChangeCB(void *pt, SbBool visible)
245 {
246 SoXtMultiSlider *p = (SoXtMultiSlider *)pt;
247
248 if (visible)
249 p->activate();
250 else
251 p->deactivate();
252 }
253
254
255 ////////////////////////////////////////////////////////////////////////
256 //
257 // Attach the sensor (if necessary).
258 //
259 void
260 SoXtMultiSlider::activate()
261 //
262 // use: private
263 ////////////////////////////////////////////////////////////////////////
264 {
265 // attach sensor to top node for redrawing purpose
266 if ( _editNode
267 && inventorSensor && inventorSensor->getAttachedNode() == NULL) {
268 importValuesFromInventor();
269 inventorSensor->attach(_editNode);
270 }
271 }
272
273 ////////////////////////////////////////////////////////////////////////
274 //
275 // Detach the sensor.
276 //
277 void
278 SoXtMultiSlider::deactivate()
279 //
280 // use: private
281 ////////////////////////////////////////////////////////////////////////
282 {
283 // detach sensor
284 if (inventorSensor != NULL && inventorSensor->getAttachedNode() != NULL) {
285 inventorSensor->detach();
286 }
287 }
288
289 void
290 SoXtMultiSlider::openMinMax()
291 {
292 // openMinMax each slider
293 for ( int i = 0; i < _numSubComponents; i++ )
294 ((SoXtSliderTool *) _subComponentArray[i])->openMinMax();
295 }
296
297 void
298 SoXtMultiSlider::closeMinMax()
299 {
300 // closeMinMax each slider
301 for ( int i = 0; i < _numSubComponents; i++ )
302 ((SoXtSliderTool *) _subComponentArray[i])->closeMinMax();
303 }
304
305 void
306 SoXtMultiSlider::makeSkinnyOpen()
307 {
308 // treat each slider
309 for ( int i = 0; i < _numSubComponents; i++ )
310 ((SoXtSliderTool *) _subComponentArray[i])->makeSkinnyOpen();
311 }
312
313 void
314 SoXtMultiSlider::makeSkinnyClosed()
315 {
316 // treat each slider
317 for ( int i = 0; i < _numSubComponents; i++ )
318 ((SoXtSliderTool *) _subComponentArray[i])->makeSkinnyClosed();
319 }
320
321 void
322 SoXtMultiSlider::getLayoutSize( int &w, int &h )
323 {
324 int tempW, tempH;
325
326 _layoutWidth = 0;
327 _layoutHeight = 0;
328 for ( int i = 0; i < _numSubComponents; i++ ) {
329 _subComponentArray[i]->getLayoutSize( tempW, tempH );
330 _layoutWidth += tempW;
331 _layoutHeight += tempH;
332 }
333 w = _layoutWidth;
334 h = _layoutHeight;
335 }
336
337 static XtResource _titleResource[] = {
338 { XmNtitleString, XmCTitleString, XmRXmString, sizeof( XmString ),
339 0, XtRString, (XtPointer) NULL }
340 };
341
342 void
343 SoXtMultiSlider::initTitles( char **titleList )
344 {
345 Arg wargs[10];
346 XmString newString;
347 Widget theWidget;
348 SoXtMinMaxSlider *theSlider;
349
350 for ( int i = 0; i < _numSubComponents; i++ ) {
351 theSlider = ((SoXtSliderTool *) _subComponentArray[i])->getSlider();
352 theWidget = theSlider->getWidget();
353
354 _titleResource[0].default_addr = (XtPointer) titleList[i];
355 XtGetApplicationResources( theWidget, (XtPointer) &newString,
356 _titleResource, XtNumber( _titleResource ), NULL, 0 );
357
358 XtSetArg( wargs[0], XmNtitleString, newString );
359 XtSetValues( theWidget, wargs, 1 );
360 XmStringFree(newString);
361 }
362 }
363
364