Debian Codegraph @

libSoXt/src/motif/SoXtSldrMdl.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.1.1.1 $
44 |
45 | Classes:
46 | A grouping of a control panel and a multi slider that work together
47 | to control a set of related parameters.
48 |
49 | Author(s) : Paul Isaacs
50 |
51 ______________ S I L I C O N G R A P H I C S I N C . ____________
52 _______________________________________________________________________
53 */
54
55
56 #include <inttypes.h>
57 #include "SoXtSliderModules.h"
58 #include "SoXtSliderTool.h"
59 #include <Xm/Form.h>
60 #include <Xm/ToggleB.h>
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Public constructor - build the widget right now
65 //
66 SoXtSliderModule::SoXtSliderModule(
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 SoXtSliderModule::~SoXtSliderModule()
83 {
84 if (_sliderModuleSliders != NULL)
85 delete _sliderModuleSliders;
86 if (_sliderModuleControl != NULL)
87 delete _sliderModuleControl;
88 }
89
90 ////////////////////////////////////////////////////////////////////////
91 //
92 // SoEXTENDER constructor - the subclass tells us whether to build or not
93 //
94 SoXtSliderModule::SoXtSliderModule(
95 Widget parent,
96 const char *name,
97 SbBool buildInsideParent,
98 SbBool buildNow)
99 : SoXtSliderSetBase(
100 parent,
101 name,
102 buildInsideParent,
103 NULL)
104 //
105 ////////////////////////////////////////////////////////////////////////
106 {
107 // In this case, this component may be what the app wants,
108 // or it may want a subclass of this component. Pass along buildNow
109 // as it was passed to us.
110 constructorCommon(buildNow);
111 }
112
113 ///////////////////////////////////////////////////////////////////////
114 //
115 // Called by the constructors.
116 //
117 // Use: public
118 void
119 SoXtSliderModule::constructorCommon(SbBool buildNow)
120 //
121 //////////////////////////////////////////////////////////////////////
122 {
123 _isOpenedUp = FALSE;
124
125 _editor = NULL;
126 _sliderModuleSliders = NULL;
127
128 _sliderModuleControl = NULL;
129
130 // Build the widget tree, and let SoXtComponent know about our base widget.
131 if (buildNow) {
132 Widget w = buildWidget(getParentWidget());
133 setBaseWidget(w);
134 }
135 }
136
137 // Subclasses should call this to build a form,
138 // then create their _sliderModuleSliders, then
139 // call buildWidget.
140 Widget
141 SoXtSliderModule::buildForm(Widget parent)
142 {
143 widget = XtCreateManagedWidget(getWidgetName(),
144 xmFormWidgetClass, parent, NULL, 0);
145 return widget;
146 }
147
148 Widget
149 SoXtSliderModule::buildWidget( Widget )
150 {
151 _sliderModuleControl = new SoXtSliderControlPanel( widget );
152 _sliderModuleControl->setSliderModule( this);
153
154 if ( XmToggleButtonGetState( _sliderModuleControl->getOpenCloseButton() ))
155 openUp();
156 else
157 closeDown();
158
159 if ( _sliderModuleControl->getStyle() == SLIDER_TOOL_STYLE_CLOSED )
160 closeMinMax();
161 else if ( _sliderModuleControl->getStyle() == SLIDER_TOOL_STYLE_OPEN )
162 openMinMax();
163 else if ( _sliderModuleControl->getStyle() == SLIDER_TOOL_STYLE_SKINNY_OPEN)
164 makeSkinnyOpen();
165 else
166 makeSkinnyClosed();
167
168 return widget;
169 }
170
171 void
172 SoXtSliderModule::splitFormBetweenPanelAndSliders()
173 {
174 Arg wargs[10];
175 int nargs;
176
177 int cntlW, cntlH, sldrW, sldrH, splitPoint;
178
179 _sliderModuleControl->getLayoutSize( cntlW, cntlH );
180 _sliderModuleSliders->getLayoutSize( sldrW, sldrH );
181
182 splitPoint = (int) (100.0 * ((float) cntlH / (float) (cntlH + sldrH)));
183
184 nargs = 0;
185 XtSetArg(wargs[nargs],XmNtopAttachment, XmATTACH_FORM ); nargs++;
186 XtSetArg(wargs[nargs],XmNbottomAttachment, XmATTACH_POSITION ); nargs++;
187 XtSetArg(wargs[nargs],XmNbottomPosition, splitPoint ); nargs++;
188 XtSetArg(wargs[nargs],XmNleftAttachment, XmATTACH_FORM ); nargs++;
189 XtSetArg(wargs[nargs],XmNrightAttachment, XmATTACH_FORM ); nargs++;
190 XtSetValues(_sliderModuleControl->getControlPanelContainer(), wargs, nargs);
191
192 nargs = 0;
193 XtSetArg(wargs[nargs],XmNtopAttachment, XmATTACH_POSITION ); nargs++;
194 XtSetArg(wargs[nargs],XmNtopPosition, splitPoint ); nargs++;
195 XtSetArg(wargs[nargs],XmNbottomAttachment, XmATTACH_FORM ); nargs++;
196 XtSetArg(wargs[nargs],XmNleftAttachment, XmATTACH_FORM ); nargs++;
197 XtSetArg(wargs[nargs],XmNrightAttachment, XmATTACH_FORM ); nargs++;
198 XtSetValues(_sliderModuleSliders->getContainer(), wargs, nargs);
199 }
200
201 void
202 SoXtSliderModule::fillFormWithPanel()
203 {
204 Arg wargs[10];
205 int nargs;
206
207 nargs = 0;
208 XtSetArg(wargs[nargs],XmNtopAttachment, XmATTACH_FORM ); nargs++;
209 XtSetArg(wargs[nargs],XmNbottomAttachment, XmATTACH_FORM ); nargs++;
210 XtSetArg(wargs[nargs],XmNleftAttachment, XmATTACH_FORM ); nargs++;
211 XtSetArg(wargs[nargs],XmNrightAttachment, XmATTACH_FORM ); nargs++;
212 XtSetValues(_sliderModuleControl->getControlPanelContainer(), wargs, nargs);
213 }
214
215 void
216 SoXtSliderModule::openUp()
217 {
218 _isOpenedUp = TRUE;
219 splitFormBetweenPanelAndSliders();
220 _sliderModuleSliders->show();
221 _sliderModuleControl->openUp();
222 }
223
224 void
225 SoXtSliderModule::closeDown()
226 {
227 _isOpenedUp = FALSE;
228 fillFormWithPanel();
229 _sliderModuleSliders->hide();
230 _sliderModuleControl->closeDown();
231 }
232
233 void
234 SoXtSliderModule::openMinMax()
235 {
236 _sliderModuleSliders->openMinMax();
237 if ( _isOpenedUp )
238 splitFormBetweenPanelAndSliders();
239 }
240
241 void
242 SoXtSliderModule::closeMinMax()
243 {
244 _sliderModuleSliders->closeMinMax();
245 if ( _isOpenedUp )
246 splitFormBetweenPanelAndSliders();
247 }
248
249 void
250 SoXtSliderModule::makeSkinnyOpen()
251 {
252 _sliderModuleSliders->makeSkinnyOpen();
253 if ( _isOpenedUp )
254 splitFormBetweenPanelAndSliders();
255 }
256
257 void
258 SoXtSliderModule::makeSkinnyClosed()
259 {
260 _sliderModuleSliders->makeSkinnyClosed();
261 if ( _isOpenedUp )
262 splitFormBetweenPanelAndSliders();
263 }
264
265 void
266 SoXtSliderModule::setNode( SoNode *newNode )
267 {
268 if (newNode) // ref the new before unref'ing the old
269 newNode->ref();
270
271 if (_editNode) // out with the old
272 _editNode->unref();
273
274 _editNode = newNode;
275 for( int i = 0; i < _numSubComponents; i++ )
276 _subComponentArray[i]->setNode( newNode );
277
278 _sliderModuleSliders->setNode( newNode );
279 }
280
281 void
282 SoXtSliderModule::getLayoutSize( int &w, int &h )
283 {
284 int tempW, tempH;
285
286 _layoutWidth = 0;
287 _layoutHeight = 0;
288
289 _sliderModuleControl->getLayoutSize( tempW, tempH );
290 _layoutWidth += tempW;
291 _layoutHeight += tempH;
292
293 if ( _isOpenedUp ) {
294 _sliderModuleSliders->getLayoutSize( tempW, tempH );
295 _layoutWidth += tempW;
296 _layoutHeight += tempH;
297 }
298
299 w = _layoutWidth;
300 h = _layoutHeight;
301 }
302
303 void
304 SoXtSliderModule::setEditor( SoXtSliderSet *newOne )
305 {
306 _editor = newOne;
307 _sliderModuleControl->setEditor( newOne );
308 }