1 /*
2 From: CP Hennessy <cp.hennessy@iname.com>
3 To: danny@hungry.com, rwscott@hungry.com
4 Subject: Re: [Bug 53] Changed - incorrect size of form used when doing
5 query_geometry
6 Date: Mon, 01 Feb 1999 01:24:31 +0100
7
8 Hi,
9
10 bughungry-daemon@lust.hungry.com wrote:
11 >
12 > http://bugs.hungry.com/show_bug.cgi?id=53
13 > + ------- Additional Comments From rwscott@hungry.com 01/27/99 15:49 -------
14 > + Could you come up with an example that shows the problem that this fixes?
15 > + I am hesitant to commit this without more detail.
16
17 I am adding a piece of source code ( less than 200 lines )
18 which should show you the problem. When you run it just
19 click on the "File" button, and resize the window, click on the
20 "File" button again.
21
22 This may have something to do with the way the help button is used
23 also.
24
25 BTW when the fix I suggested is not used then the form seems to
26 try to get the maximum size it can ( i.e. the screen size ?? ).
27
28 I hope that I have give you enough.
29
30 Should I fill in some info in the bug report ?
31
32 CPFrom: CP Hennessy <cp.hennessy@iname.com>
33 To: danny@hungry.com, rwscott@hungry.com
34 Subject: Re: [Bug 53] Changed - incorrect size of form used when doing
35 query_geometry
36 Date: Mon, 01 Feb 1999 01:24:31 +0100
37 */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <Xm/Form.h>
42 #include <Xm/Label.h>
43 #include <Xm/MainW.h>
44 #include <Xm/PanedW.h>
45 #include <Xm/Text.h>
46 #include <Xm/RowColumn.h>
47 #include <Xm/CascadeB.h>
48
49 static XtWidgetGeometry Expected[] = {
50 CWWidth | CWHeight , 135, 413, 517, 380, 0,0,0, /* main */
51 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 31, 0,0,0, /* main-menu */
52 CWWidth | CWHeight | CWX | CWY, 436, 5, 76, 21, 0,0,0, /* helpButton */
53 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
54 CWWidth | CWHeight | CWX | CWY, 0, 31, 517, 349, 0,0,0, /* form */
55 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 349, 0,0,0, /* textSW */
56 CWWidth | CWHeight | CWX | CWY, 0, 334, 498, 15, 0,0,0, /* HorScrollBar */
57 CWWidth | CWHeight | CWX | CWY, 502, 0, 15, 330, 0,0,0, /* VertScrollBar */
58 CWWidth | CWHeight | CWX | CWY, 0, 0, 498, 330, 0,0,0, /* text */
59
60 CWWidth | CWHeight , 135, 413, 517, 380, 0,0,0, /* main */
61 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 31, 0,0,0, /* main-menu */
62 CWWidth | CWHeight | CWX | CWY, 490, 5, 22, 21, 0,0,0, /* helpButton */
63 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
64 CWWidth | CWHeight | CWX | CWY, 0, 31, 517, 349, 0,0,0, /* form */
65 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 349, 0,0,0, /* textSW */
66 CWWidth | CWHeight | CWX | CWY, 0, 334, 498, 15, 0,0,0, /* HorScrollBar */
67 CWWidth | CWHeight | CWX | CWY, 502, 0, 15, 330, 0,0,0, /* VertScrollBar */
68 CWWidth | CWHeight | CWX | CWY, 0, 0, 498, 330, 0,0,0, /* text */
69
70 CWWidth | CWHeight , 135, 413, 517, 380, 0,0,0, /* main */
71 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 31, 0,0,0, /* main-menu */
72 CWWidth | CWHeight | CWX | CWY, 424, 5, 88, 21, 0,0,0, /* helpButton */
73 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
74 CWWidth | CWHeight | CWX | CWY, 0, 31, 517, 349, 0,0,0, /* form */
75 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 349, 0,0,0, /* textSW */
76 CWWidth | CWHeight | CWX | CWY, 0, 334, 498, 15, 0,0,0, /* HorScrollBar */
77 CWWidth | CWHeight | CWX | CWY, 502, 0, 15, 330, 0,0,0, /* VertScrollBar */
78 CWWidth | CWHeight | CWX | CWY, 0, 0, 498, 330, 0,0,0, /* text */
79
80 CWWidth | CWHeight , 135, 413, 517, 380, 0,0,0, /* main */
81 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 31, 0,0,0, /* main-menu */
82 CWWidth | CWHeight | CWX | CWY, 490, 5, 22, 21, 0,0,0, /* helpButton */
83 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
84 CWWidth | CWHeight | CWX | CWY, 0, 31, 517, 349, 0,0,0, /* form */
85 CWWidth | CWHeight | CWX | CWY, 0, 0, 517, 349, 0,0,0, /* textSW */
86 CWWidth | CWHeight | CWX | CWY, 0, 334, 498, 15, 0,0,0, /* HorScrollBar */
87 CWWidth | CWHeight | CWX | CWY, 502, 0, 15, 330, 0,0,0, /* VertScrollBar */
88 CWWidth | CWHeight | CWX | CWY, 0, 0, 498, 330, 0,0,0, /* text */
89
90 CWWidth | CWHeight , 135, 413, 775, 380, 0,0,0, /* main */
91 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 31, 0,0,0, /* main-menu */
92 CWWidth | CWHeight | CWX | CWY, 748, 5, 22, 21, 0,0,0, /* helpButton */
93 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
94 CWWidth | CWHeight | CWX | CWY, 0, 31, 775, 349, 0,0,0, /* form */
95 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 349, 0,0,0, /* textSW */
96 CWWidth | CWHeight | CWX | CWY, 0, 334, 756, 15, 0,0,0, /* HorScrollBar */
97 CWWidth | CWHeight | CWX | CWY, 760, 0, 15, 330, 0,0,0, /* VertScrollBar */
98 CWWidth | CWHeight | CWX | CWY, 0, 0, 756, 330, 0,0,0, /* text */
99
100 CWWidth | CWHeight , 135, 413, 775, 380, 0,0,0, /* main */
101 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 31, 0,0,0, /* main-menu */
102 CWWidth | CWHeight | CWX | CWY, 682, 5, 88, 21, 0,0,0, /* helpButton */
103 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
104 CWWidth | CWHeight | CWX | CWY, 0, 31, 775, 349, 0,0,0, /* form */
105 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 349, 0,0,0, /* textSW */
106 CWWidth | CWHeight | CWX | CWY, 0, 334, 756, 15, 0,0,0, /* HorScrollBar */
107 CWWidth | CWHeight | CWX | CWY, 760, 0, 15, 330, 0,0,0, /* VertScrollBar */
108 CWWidth | CWHeight | CWX | CWY, 0, 0, 756, 330, 0,0,0, /* text */
109
110 CWWidth | CWHeight , 135, 413, 775, 380, 0,0,0, /* main */
111 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 31, 0,0,0, /* main-menu */
112 CWWidth | CWHeight | CWX | CWY, 748, 5, 22, 21, 0,0,0, /* helpButton */
113 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
114 CWWidth | CWHeight | CWX | CWY, 0, 31, 775, 349, 0,0,0, /* form */
115 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 349, 0,0,0, /* textSW */
116 CWWidth | CWHeight | CWX | CWY, 0, 334, 756, 15, 0,0,0, /* HorScrollBar */
117 CWWidth | CWHeight | CWX | CWY, 760, 0, 15, 330, 0,0,0, /* VertScrollBar */
118 CWWidth | CWHeight | CWX | CWY, 0, 0, 756, 330, 0,0,0, /* text */
119
120 CWWidth | CWHeight , 135, 413, 775, 380, 0,0,0, /* main */
121 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 31, 0,0,0, /* main-menu */
122 CWWidth | CWHeight | CWX | CWY, 748, 5, 22, 21, 0,0,0, /* helpButton */
123 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
124 CWWidth | CWHeight | CWX | CWY, 0, 31, 775, 349, 0,0,0, /* form */
125 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 349, 0,0,0, /* textSW */
126 CWWidth | CWHeight | CWX | CWY, 0, 334, 756, 15, 0,0,0, /* HorScrollBar */
127 CWWidth | CWHeight | CWX | CWY, 760, 0, 15, 330, 0,0,0, /* VertScrollBar */
128 CWWidth | CWHeight | CWX | CWY, 0, 0, 756, 330, 0,0,0, /* text */
129
130 CWWidth | CWHeight , 135, 413, 775, 380, 0,0,0, /* main */
131 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 31, 0,0,0, /* main-menu */
132 CWWidth | CWHeight | CWX | CWY, 682, 5, 88, 21, 0,0,0, /* helpButton */
133 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
134 CWWidth | CWHeight | CWX | CWY, 0, 31, 775, 349, 0,0,0, /* form */
135 CWWidth | CWHeight | CWX | CWY, 0, 0, 775, 349, 0,0,0, /* textSW */
136 CWWidth | CWHeight | CWX | CWY, 0, 334, 756, 15, 0,0,0, /* HorScrollBar */
137 CWWidth | CWHeight | CWX | CWY, 760, 0, 15, 330, 0,0,0, /* VertScrollBar */
138 CWWidth | CWHeight | CWX | CWY, 0, 0, 756, 330, 0,0,0, /* text */
139 };
140
141 Widget button, menuBar, mainW, text, helpButton, form;
142
ChangeHelpButton(Widget fileB,Widget helpButton,XtPointer call_data)143 void ChangeHelpButton
144 (
145 Widget fileB,
146 Widget helpButton,
147 XtPointer call_data)
148 {
149 static int index = 1;
150 XmString xmstr;
151 switch (index)
152 {
153 case 1:
154 XmTextSetString(text, "1:a small test");
155 break;
156
157 case 2:
158 XmTextSetString(text, "2:a bigger test");
159 break;
160
161 case 3:
162 XmTextSetString(text, "3:another small test");
163
164 default:
165 index = 0;
166 }
167
168 switch (index)
169 {
170 case 1:
171 xmstr = XmStringCreateLocalized("1");
172 break;
173
174 case 2:
175 xmstr = XmStringCreateLocalized("a bit bigger");
176 break;
177
178 case 3:
179 xmstr = XmStringCreateLocalized("small");
180 break;
181
182 case 4:
183 xmstr = XmStringCreateLocalized("really enormously big");
184 break;
185
186 default:
187 xmstr = XmStringCreateLocalized("0");
188 index = 0;
189 }
190 index++;
191
192 XtVaSetValues(helpButton,
193 XmNlabelString, xmstr,
194 (String *)NULL);
195
196 XmStringFree(xmstr);
197
198 }
199
200 /*-------------------------------------------------------------
201 ** CreateMainEditorWindow
202 ** Create MainWindow and subwidgets.
203 */
CreateMainEditorWindow(Widget app_shell)204 Widget CreateMainEditorWindow
205 (
206 Widget app_shell)
207 {
208 Arg al[10]; /* arg list */
209 Cardinal ac; /* arg count */
210
211 ac = 0;
212 XtSetArg(al[ac], XmNshadowThickness, 0);
213 ac++;
214 XtSetArg(al[ac], XmNgeometry, "80x24");
215 ac++;
216 mainW = XmCreateMainWindow(app_shell, "main", al, ac);
217
218 menuBar = XmCreateMenuBar(mainW, "main-menu", NULL, 0);
219 XtManageChild(menuBar);
220
221 helpButton = XmCreateCascadeButton(menuBar, "helpButton", NULL, 0);
222 XtManageChild(helpButton);
223
224 button = XmCreateCascadeButton(menuBar, "File", NULL, 0);
225 XtManageChild(button);
226 XtAddCallback(button, XmNactivateCallback,
227 (XtCallbackProc)ChangeHelpButton, (XtPointer)helpButton);
228
229 ac = 0;
230 form = XmCreateForm(mainW, "form", al, ac);
231 XtManageChild(form);
232
233 ac = 0;
234 XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT);
235 ac++;
236 XtSetArg(al[ac], XmNrows, 24);
237 ac++;
238 XtSetArg(al[ac], XmNcolumns, 80);
239 ac++;
240 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM);
241 ac++;
242 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM);
243 ac++;
244 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM);
245 ac++;
246 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM);
247 ac++;
248 text = XmCreateScrolledText(form, "text", al, ac);
249 XtManageChild(text);
250
251 XtVaSetValues(menuBar,
252 XmNmenuHelpWidget, (XtArgVal)helpButton,
253 (String *)NULL);
254 XtManageChild(mainW);
255 XtManageChild(button);
256
257 return (mainW);
258 }
259
CreateTopLevel(String applicationName,Display * display)260 Widget CreateTopLevel
261 (
262 String applicationName,
263 Display *display)
264 {
265 Widget toplevel;
266 toplevel = XtVaAppCreateShell(NULL, applicationName,
267 applicationShellWidgetClass, display,
268 XmNallowShellResize, (XtArgVal)True,
269 NULL);
270
271 return (toplevel);
272 }
273
initX(XtAppContext * context,String application,XrmOptionDescList options,Cardinal num_options,unsigned int * argc,String * argv)274 Widget initX
275 (
276 XtAppContext *context,
277 String application,
278 XrmOptionDescList options,
279 Cardinal num_options,
280 unsigned int *argc,
281 String *argv)
282 {
283 Display *disp;
284 XtToolkitInitialize();
285 *context = XtCreateApplicationContext();
286
287 disp = XtOpenDisplay(*context, NULL, application, application,
288 options, num_options, (int *)argc, argv);
289
290 if (disp == NULL)
291 {
292 (void)fprintf(stderr, "ERROR:Cannot open display :%s\n", (String)getenv("DISPLAY"));
293 exit(1);
294 }
295
296 return (CreateTopLevel(application, disp));
297 }
298
main(int argc,String * argv)299 int main
300 (
301 int argc,
302 String *argv)
303
304 {
305 XtAppContext context;
306
307 Widget topLevel = initX(&context, "textHelpButton", NULL,
308 0, &argc, argv);
309
310 Widget mainWindow = CreateMainEditorWindow(topLevel);
311
312 XtManageChild(mainWindow);
313
314 XtRealizeWidget(topLevel);
315
316 LessTifTestWaitForIt(topLevel);
317 PrintDetails(topLevel, Expected);
318
319 LessTifTestBtn1Down(button);
320 LessTifTestBtn1Up(button);
321 PrintDetails(topLevel, Expected);
322
323 LessTifTestBtn1Down(button);
324 LessTifTestBtn1Up(button);
325 PrintDetails(topLevel, Expected);
326
327 LessTifTestBtn1Down(button);
328 LessTifTestBtn1Up(button);
329 PrintDetails(topLevel, Expected);
330
331 LessTifTestBtn1Down(button);
332 LessTifTestBtn1Up(button);
333 PrintDetails(topLevel, Expected);
334
335 {
336 Dimension w;
337
338 XtVaGetValues(topLevel,
339 XmNwidth, &w,
340 NULL);
341 XtVaSetValues(topLevel,
342 XmNwidth, (3 * w) / 2,
343 NULL);
344 }
345
346 LessTifTestBtn1Down(button);
347 LessTifTestBtn1Up(button);
348 PrintDetails(topLevel, Expected);
349
350 LessTifTestBtn1Down(button);
351 LessTifTestBtn1Up(button);
352 PrintDetails(topLevel, Expected);
353
354 LessTifTestBtn1Down(button);
355 LessTifTestBtn1Up(button);
356 PrintDetails(topLevel, Expected);
357
358 LessTifTestBtn1Down(button);
359 LessTifTestBtn1Up(button);
360 PrintDetails(topLevel, Expected);
361
362 LessTifTestMainLoop(topLevel);
363 /*
364 XtAppMainLoop ( context );
365 */
366
367 return (-1);
368 }
369