Debian Codegraph @

libSoXt/src/motif/SoXtCntlPnl.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.2 $
44 |
45 | Classes:
46 | Control panel, used as part of a 'sliderModule'
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 #include <inttypes.h>
56 #include "SoXtSliderControlPanel.h"
57 #include "SoXtSliderModule.h"
58 #include "SoXtSliderTool.h"
59 #include <Inventor/Xt/SoXtSliderSet.h>
60 #include <X11/StringDefs.h>
61 #include <Xm/Form.h>
62 #include <Xm/ToggleB.h>
63 #include <Xm/PushB.h>
64
65 static XtResource _openCloseResources[] = {
66 { XmNrightPosition, XmCPosition, XtRInt, sizeof( int),
67 0, XtRImmediate, (XtPointer) DEFAULT_SLIDER_CONTROL_PANEL_DIVIDING_POINT }
68 };
69
70 static XtResource _styleLabelResource[] = {
71 { XmNlabelString, XmCLabelString, XmRXmString, sizeof( char *),
72 0, XtRString, (XtPointer) DEFAULT_SLIDER_CONTROL_PANEL_STYLE_LABEL }
73 };
74
75 SoXtSliderControlPanel::SoXtSliderControlPanel(
76 Widget parent,
77 const char *name,
78 SbBool buildInsideParent)
79 : SoXtSliderSetBase(
80 parent,
81 name,
82 buildInsideParent,
83 NULL)
84 {
85 _openCloseButton = NULL;
86 _styleButton = NULL;
87 _dividingPoint = 0;
88 _layoutWidth = 310;
89 _layoutHeight = 40;
90 _sliderModule = NULL;
91 _editor = NULL;
92 _style = SLIDER_TOOL_STYLE_SKINNY_CLOSED;
93
94 // Build that widget!
95 Widget w = buildWidget(getParentWidget());
96 setBaseWidget(w);
97 }
98
99 SoXtSliderControlPanel::~SoXtSliderControlPanel() {}
100
101 Widget
102 SoXtSliderControlPanel::buildWidget( Widget parent )
103 {
104 Arg wargs[10];
105
106 widget = XtCreateManagedWidget(getWidgetName(),xmFormWidgetClass,
107 parent,NULL, 0);
108
109 XtSetArg( wargs[0], XmNshadowThickness, 2 );
110 _openCloseButton = XtCreateManagedWidget("openCloseButton",
111 xmToggleButtonWidgetClass,
112 widget,wargs, 1);
113 XtSetArg( wargs[0], XmNshadowThickness, 1 );
114 _styleButton = XtCreateManagedWidget("styleButton",
115 xmPushButtonWidgetClass,
116 widget,wargs, 1);
117
118 initLayout();
119
120 XtAddCallback( _openCloseButton, XmNvalueChangedCallback,
121 (XtCallbackProc)&SoXtSliderControlPanel::openCloseCallback,
122 (XtPointer) this);
123 XtAddCallback( _styleButton, XmNactivateCallback,
124 (XtCallbackProc)&SoXtSliderControlPanel::styleCallback,
125 (XtPointer) this);
126 return widget;
127 }
128
129 void
130 SoXtSliderControlPanel::openUp()
131 {
132 Arg wargs[10];
133 int nargs;
134
135 // align right edge of button with dissection pt.
136 nargs = 0;
137 XtSetArg(wargs[nargs], XmNrightPosition, _dividingPoint ); nargs++;
138 XtSetValues(_openCloseButton, wargs, nargs);
139
140 XtManageChild(_styleButton);
141 }
142
143 void
144 SoXtSliderControlPanel::closeDown()
145 {
146 Arg wargs[10];
147 int nargs;
148
149 // attach to right side of window
150 nargs = 0;
151 XtSetArg(wargs[nargs], XmNrightPosition, 100 ); nargs++;
152 XtSetValues(_openCloseButton, wargs, nargs);
153
154 XtUnmanageChild(_styleButton);
155 }
156
157 void
158 SoXtSliderControlPanel::openCloseCallback( Widget, void *client_data, void *)
159 {
160 SoXtSliderControlPanel* obj = (SoXtSliderControlPanel *) client_data;
161 if (obj->_sliderModule) {
162
163 // Insure that module is configured properly
164 if ( obj->getStyle() == SLIDER_TOOL_STYLE_SKINNY_CLOSED )
165 obj->_sliderModule->makeSkinnyClosed();
166 else if ( obj->getStyle() == SLIDER_TOOL_STYLE_SKINNY_OPEN )
167 obj->_sliderModule->makeSkinnyOpen();
168 else if ( obj->getStyle() == SLIDER_TOOL_STYLE_OPEN )
169 obj->_sliderModule->openMinMax();
170 else
171 obj->_sliderModule->closeMinMax();
172
173 // Open or close as appropriate.
174 if (XmToggleButtonGetState( obj->_openCloseButton ) )
175 obj->_sliderModule->openUp();
176 else
177 obj->_sliderModule->closeDown();
178 }
179 if (obj->_editor )
180 obj->_editor->updateLayout();
181 }
182
183 void
184 SoXtSliderControlPanel::styleCallback( Widget, void *client_data, void *)
185 {
186 SoXtSliderControlPanel* obj = (SoXtSliderControlPanel *) client_data;
187 if (obj->_sliderModule) {
188
189 if ( obj->getStyle() == SLIDER_TOOL_STYLE_SKINNY_CLOSED ) {
190 obj->_sliderModule->makeSkinnyOpen();
191 obj->setStyle( SLIDER_TOOL_STYLE_SKINNY_OPEN );
192 }
193 else if ( obj->getStyle() == SLIDER_TOOL_STYLE_SKINNY_OPEN ) {
194 obj->_sliderModule->openMinMax();
195 obj->setStyle( SLIDER_TOOL_STYLE_OPEN );
196 }
197 else if ( obj->getStyle() == SLIDER_TOOL_STYLE_OPEN ) {
198 obj->_sliderModule->closeMinMax();
199 obj->setStyle( SLIDER_TOOL_STYLE_CLOSED );
200 }
201 else {
202 obj->_sliderModule->makeSkinnyClosed();
203 obj->setStyle( SLIDER_TOOL_STYLE_SKINNY_CLOSED );
204 }
205 }
206 if (obj->_editor )
207 obj->_editor->updateLayout();
208 }
209
210 void
211 SoXtSliderControlPanel::initLayout()
212 {
213 Arg wargs[10];
214 int nargs;
215 XmString newString;
216
217 /* see if the dividing point resource has been specified. If so, change
218 the value of _dividingPoint to match it
219 */
220 XtGetApplicationResources( _openCloseButton, (XtPointer) &_dividingPoint,
221 _openCloseResources, XtNumber( _openCloseResources),
222 NULL, 0 );
223 nargs = 0;
224 XtSetArg(wargs[nargs],XmNtopAttachment, XmATTACH_FORM ); nargs++;
225 XtSetArg(wargs[nargs],XmNbottomAttachment, XmATTACH_FORM ); nargs++;
226 XtSetArg(wargs[nargs],XmNleftAttachment, XmATTACH_FORM ); nargs++;
227 XtSetArg(wargs[nargs],XmNrightAttachment, XmATTACH_POSITION ); nargs++;
228 XtSetArg(wargs[nargs],XmNrightPosition, _dividingPoint ); nargs++;
229 XtSetValues( _openCloseButton, wargs, nargs );
230
231 XtGetApplicationResources( _styleButton, (XtPointer) &newString,
232 _styleLabelResource, XtNumber( _styleLabelResource),
233 NULL, 0 );
234 nargs = 0;
235 XtSetArg(wargs[nargs],XmNtopAttachment, XmATTACH_FORM ); nargs++;
236 XtSetArg(wargs[nargs],XmNbottomAttachment, XmATTACH_FORM ); nargs++;
237 XtSetArg(wargs[nargs],XmNleftAttachment, XmATTACH_WIDGET ); nargs++;
238 XtSetArg(wargs[nargs],XmNleftWidget, _openCloseButton ); nargs++;
239 XtSetArg(wargs[nargs],XmNrightAttachment, XmATTACH_FORM ); nargs++;
240
241 XtSetArg(wargs[nargs],XmNlabelString, newString ); nargs++;
242 XtSetValues( _styleButton, wargs, nargs );
243 }