Debian Codegraph @

libSoXt/src/motif/SoXtSldrSet.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 | SoXtSliderSets for creating organized groups of sliders
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 #include <inttypes.h>
55 #include <Inventor/Xt/SoXtSliderSet.h>
56 #include <X11/StringDefs.h>
57 #include <Xm/Form.h>
58
59 static XtResource _editorWidthResource[] = {
60 { XtNwidth, XtCWidth, XtRDimension, sizeof( unsigned short),
61 0, XtRImmediate, (XtPointer) 0 }
62 };
63
64 static XtResource _editorHeightResource[] = {
65 { XtNheight, XtCHeight, XtRDimension, sizeof( unsigned short),
66 0, XtRImmediate, (XtPointer) 0 }
67 };
68
69 SoXtSliderSet::SoXtSliderSet(
70 Widget parent,
71 const char *name,
72 SbBool buildInsideParent,
73 SoNode *newEditNode)
74 : SoXtSliderSetBase(
75 parent,
76 name,
77 buildInsideParent,
78 newEditNode)
79 {
80 _parentShellWidget = NULL;
81 }
82
83 SoXtSliderSet::~SoXtSliderSet()
84 {
85 }
86
87 void
88 SoXtSliderSet::updateLayout()
89 {
90 int newLayoutH, newLayoutW;
91 Dimension initialWidth, initialHeight;
92 Dimension oldWidgetHeight, newWidgetHeight;
93 int tempW, tempH;
94 float topPos, bottomPos;
95 Widget theSubWidget;
96 Arg wargs[10];
97 int nargs;
98
99 newLayoutH = 0;
100 newLayoutW = 0;
101
102 int i;
103 for (i = 0; i < _numSubComponents; i++ ) {
104 _subComponentArray[i]->getLayoutSize( tempW, tempH );
105 newLayoutH += tempH;
106 newLayoutW = ( tempW > newLayoutW ) ? tempW : newLayoutW;
107 }
108
109 // set attachment and position for each module
110 topPos = 0;
111 bottomPos = 0;
112 for (i = 0; i < _numSubComponents; i++ ) {
113
114 // set its relative size in the container
115 theSubWidget = _subComponentArray[i]->getWidget();
116 topPos = bottomPos;
117
118 _subComponentArray[i]->getLayoutSize( tempW, tempH );
119 bottomPos += 100.0 * ((float) tempH / (float) newLayoutH);
120
121 nargs = 0;
122 XtSetArg( wargs[nargs], XmNtopAttachment, XmATTACH_POSITION); nargs++;
123 XtSetArg( wargs[nargs], XmNtopPosition, (int) topPos ); nargs++;
124 XtSetArg( wargs[nargs], XmNbottomAttachment, XmATTACH_POSITION);nargs++;
125 XtSetArg( wargs[nargs], XmNbottomPosition, (int) bottomPos ); nargs++;
126 XtSetArg( wargs[nargs], XmNleftAttachment, XmATTACH_FORM); nargs++;
127 XtSetArg( wargs[nargs], XmNrightAttachment, XmATTACH_FORM); nargs++;
128
129 XtSetValues( theSubWidget, wargs, nargs );
130 }
131
132 // Now deal with adjusting SIZE of the ENTIRE EDITOR.
133 if (widget == NULL)
134 return;
135
136 if ( _layoutHeight == 0 || _layoutWidth == 0 ) {
137 // if first time throught, _layoutHeight and _layoutWidth will still
138 // be at their initialized values of 0. In this case, just copy.
139 _layoutHeight = newLayoutH;
140 _layoutWidth = newLayoutW;
141 // if the user has not specified a size for the window through the
142 // resource system, then use the layout size.
143 // otherwise, leave it alone.
144 _editorHeightResource[0].default_addr = (XtPointer) (unsigned long) newLayoutH;
145 _editorWidthResource[0].default_addr = (XtPointer) (unsigned long) newLayoutW;
146 XtGetApplicationResources( widget, (XtPointer) &initialWidth,
147 _editorWidthResource, XtNumber( _editorWidthResource ), NULL, 0);
148 XtGetApplicationResources(widget, (XtPointer) &initialHeight,
149 _editorHeightResource, XtNumber( _editorHeightResource ), NULL, 0);
150 XtSetArg( wargs[0], XmNwidth, initialWidth );
151 XtSetArg( wargs[1], XmNheight, initialHeight );
152 XtSetValues( widget, wargs, 2 );
153 XtSetValues( _parentShellWidget, wargs, 2 );
154 }
155 else if ( _layoutHeight != newLayoutH ) {
156 // If layout height has changed (this will happen if modules
157 // changed size, typically by opening or closing the multiSliders.)
158 // Then we must calculate a new size for the editor.
159 // To calculate, we keep these two ratios equal:
160 // newWidgetHeight / newLayoutH = oldWidgetHeight / _layoutHeight
161 XtSetArg( wargs[0], XmNheight, &oldWidgetHeight );
162 XtGetValues( _parentShellWidget, wargs, 1 );
163
164 // note that previous if statement prevents us from dividing by zero
165 if (oldWidgetHeight == 0)
166 newWidgetHeight = newLayoutH;
167 else
168 newWidgetHeight = (Dimension) (((float) newLayoutH )
169 * ((float) oldWidgetHeight / (float) _layoutHeight));
170
171 XtSetArg( wargs[0], XmNheight, newWidgetHeight );
172 XtSetValues( _parentShellWidget, wargs, 1 );
173 XtSetValues( widget, wargs, 1 );
174
175 _layoutHeight = newLayoutH;
176 _layoutWidth = newLayoutW;
177 }
178 }