-
Notifications
You must be signed in to change notification settings - Fork 2
/
productDescriptionShell.c
532 lines (470 loc) · 14.9 KB
/
productDescriptionShell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* productDescriptionShell.c */
/************************DESCRIPTION***********************************
routine to create product description shell for all Motif-based EPICS tools
input parameters are the product name, and product description
**********************************************************************/
#define VERSION 1.1.0
#define DEBUG_POSITION 0
#include <stdio.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Xatom.h>
#include <Xm/Xm.h>
#include <Xm/Protocols.h>
#include <Xm/Label.h>
#include <Xm/Form.h>
#include <Xm/Separator.h>
#include <Xm/PushB.h>
#include <Xm/MwmUtil.h>
#ifdef WIN32
/* Hummingbird extra functions including lprintf
* Needs to be included after Intrinsic.h for Exceed 5 */
#include <X11/XlibXtra.h>
#define printf lprintf
#endif
static Widget okButton;
/* forward declarations */
static void closeProductDescriptionCallback(Widget w,
XtPointer client_data, XtPointer call_data);
static void popdownProductDescriptionShell(XtPointer xtPointer);
/*********************************************************
closeProductDescriptionCallback
*********************************************************/
static void closeProductDescriptionCallback(Widget w,
XtPointer client_data, XtPointer call_data)
{
Widget shell = (Widget)client_data;
XtPopdown(shell);
}
/*********************************************************
popdownProductDescriptionShell
*********************************************************/
static void popdownProductDescriptionShell(XtPointer xtPointer)
{
Arg args[3];
Widget widget;
Atom WM_DELETE_WINDOW;
widget = (Widget) xtPointer;
XtPopdown(widget);
XtSetArg(args[0],XmNmwmDecorations,MWM_DECOR_ALL);
XtSetArg(args[1],XmNdeleteResponse,XmDO_NOTHING);
XtSetValues(widget,args,2);
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(widget),
"WM_DELETE_WINDOW",False);
XmAddWMProtocolCallback(widget,WM_DELETE_WINDOW,
(XtCallbackProc)closeProductDescriptionCallback,(XtPointer)widget);
/* Next time up the OK button will show */
XtManageChild(okButton);
}
/*********************************************************
* createAndPopupProductDescriptionShell
*
* function to create, set and popup an EPICS product description shell
* widget hierarchy:
*
* productDescriptionShell
* form
* nameLabel
* separator
* descriptionLabel
* versionInfoLabel
* developedAtLabel
* okButton
*********************************************************/
Widget createAndPopupProductDescriptionShell(
XtAppContext appContext, /* application context */
Widget topLevelShell, /* application's topLevel shell */
char *name, /* product/program name */
XmFontList nameFontList, /* and font list (or NULL) */
Pixmap namePixmap, /* name Pixmap (or NULL) */
char *description, /* product description */
XmFontList descriptionFontList,/* and font list (or NULL) */
char *versionInfo, /* product version number */
char *developedAt, /* at and by... */
XmFontList otherFontList, /* and font list (or NULL) */
int background, /* background color (or -1) */
int foreground, /* foreground color (or -1) */
int seconds) /* seconds to leave posted */
{
Display *display;
Widget productDescriptionShell, form;
Arg args[15];
Widget children[6], nameLabel, descriptionLabel, versionInfoLabel,
separator, developedAtLabel;
XmString nameXmString = (XmString)NULL, descriptionXmString = (XmString)NULL,
versionInfoXmString = (XmString)NULL,
developedAtXmString = (XmString)NULL, okXmString = (XmString)NULL;
Dimension formHeight, nameHeight;
Dimension shellHeight, shellWidth;
Dimension screenHeight, screenWidth;
Position newY, newX;
int n, offset, screen;
/* Create the shell */
n = 0;
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
XtSetArg(args[n],XmNmwmDecorations, MWM_DECOR_ALL|
MWM_DECOR_BORDER|MWM_DECOR_RESIZEH|MWM_DECOR_TITLE|MWM_DECOR_MENU|
MWM_DECOR_MINIMIZE|MWM_DECOR_MAXIMIZE);
n++;
XtSetArg(args[n],XmNtitle,"Version");
n++;
productDescriptionShell = XtCreatePopupShell("productDescriptionShell",
topLevelShellWidgetClass,topLevelShell,args, n);
display=XtDisplay(productDescriptionShell);
screen=DefaultScreen(display);
n = 0;
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
XtSetArg(args[n],XmNnoResize,True);
n++;
XtSetArg(args[n],XmNshadowThickness,2);
n++;
XtSetArg(args[n],XmNshadowType,XmSHADOW_OUT);
n++;
XtSetArg(args[n],XmNautoUnmanage,False);
n++;
form = XmCreateForm(productDescriptionShell,"form",args,n);
/* Generate XmStrings */
if (name != NULL) nameXmString = XmStringCreateLtoR(name,
XmFONTLIST_DEFAULT_TAG);
if (description != NULL) descriptionXmString =
XmStringCreateLtoR(description,XmFONTLIST_DEFAULT_TAG);
if (versionInfo != NULL) versionInfoXmString =
XmStringCreateLtoR(versionInfo,XmFONTLIST_DEFAULT_TAG);
if (developedAt != NULL) developedAtXmString =
XmStringCreateLtoR(developedAt,XmFONTLIST_DEFAULT_TAG);
/* Create the label children */
/* Name */
n = 0;
if (namePixmap == (Pixmap) NULL) {
XtSetArg(args[n],XmNlabelString,nameXmString);
n++;
if (nameFontList != NULL) {
XtSetArg(args[n],XmNfontList,nameFontList);
n++;
}
} else {
XtSetArg(args[n],XmNlabelType,XmPIXMAP);
n++;
XtSetArg(args[n],XmNlabelPixmap,namePixmap);
n++;
}
XtSetArg(args[n],XmNalignment,XmALIGNMENT_BEGINNING);
n++;
XtSetArg(args[n],XmNleftAttachment,XmATTACH_POSITION);
n++;
XtSetArg(args[n],XmNleftPosition,1);
n++;
XtSetArg(args[n],XmNresizable,False);
n++;
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
nameLabel = XmCreateLabel(form,"nameLabel",args,n);
/* Separator */
n = 0;
XtSetArg(args[n],XmNtopAttachment,XmATTACH_FORM);
n++;
XtSetArg(args[n],XmNbottomAttachment,XmATTACH_FORM);
n++;
XtSetArg(args[n],XmNleftAttachment,XmATTACH_WIDGET);
n++;
XtSetArg(args[n],XmNleftWidget,nameLabel);
n++;
XtSetArg(args[n],XmNorientation,XmVERTICAL);
n++;
XtSetArg(args[n],XmNshadowThickness,2);
n++;
XtSetArg(args[n],XmNseparatorType,XmSHADOW_ETCHED_IN);
n++;
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
separator = XmCreateSeparator(form,"separator",args,n);
/* Description */
n = 0;
XtSetArg(args[n],XmNalignment,XmALIGNMENT_BEGINNING);
n++;
XtSetArg(args[n],XmNlabelString,descriptionXmString);
n++;
XtSetArg(args[n],XmNtopAttachment,XmATTACH_POSITION);
n++;
XtSetArg(args[n],XmNtopPosition,5);
n++;
XtSetArg(args[n],XmNleftAttachment,XmATTACH_WIDGET);
n++;
XtSetArg(args[n],XmNleftWidget,separator);
n++;
XtSetArg(args[n],XmNrightAttachment,XmATTACH_POSITION);
n++;
XtSetArg(args[n],XmNrightPosition,90);
n++;
if (descriptionFontList != NULL) {
XtSetArg(args[n],XmNfontList,descriptionFontList);
n++;
}
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
descriptionLabel = XmCreateLabel(form,"descriptionLabel",args,n);
/* Version info */
n = 0;
XtSetArg(args[n],XmNalignment,XmALIGNMENT_BEGINNING);
n++;
XtSetArg(args[n],XmNlabelString,versionInfoXmString);
n++;
XtSetArg(args[n],XmNtopAttachment,XmATTACH_WIDGET);
n++;
XtSetArg(args[n],XmNtopWidget,descriptionLabel);
n++;
XtSetArg(args[n],XmNleftAttachment,XmATTACH_OPPOSITE_WIDGET);
n++;
XtSetArg(args[n],XmNleftWidget,descriptionLabel);
n++;
XtSetArg(args[n],XmNrightAttachment,XmATTACH_POSITION);
n++;
XtSetArg(args[n],XmNrightPosition,90);
n++;
if (otherFontList != NULL) {
XtSetArg(args[n],XmNfontList,otherFontList);
n++;
}
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
versionInfoLabel = XmCreateLabel(form,"versionInfoLabel",args,n);
/* Developed at/by... */
n = 0;
XtSetArg(args[n],XmNalignment,XmALIGNMENT_BEGINNING);
n++;
XtSetArg(args[n],XmNlabelString,developedAtXmString);
n++;
XtSetArg(args[n],XmNtopAttachment,XmATTACH_WIDGET);
n++;
XtSetArg(args[n],XmNtopWidget,versionInfoLabel);
n++;
XtSetArg(args[n],XmNleftAttachment,XmATTACH_OPPOSITE_WIDGET);
n++;
XtSetArg(args[n],XmNleftWidget,versionInfoLabel);
n++;
XtSetArg(args[n],XmNrightAttachment,XmATTACH_POSITION);
n++;
XtSetArg(args[n],XmNrightPosition,90);
n++;
XtSetArg(args[n],XmNbottomAttachment,XmATTACH_POSITION);
n++;
XtSetArg(args[n],XmNbottomPosition,90);
n++;
if (otherFontList != NULL) {
XtSetArg(args[n],XmNfontList,otherFontList);
n++;
}
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
developedAtLabel = XmCreateLabel(form,"developedAtLabel",args,n);
/* OK button */
okXmString = XmStringCreateLocalized("OK");
n = 0;
XtSetArg(args[n],XmNlabelString,okXmString);
n++;
XtSetArg(args[n],XmNtopAttachment,XmATTACH_FORM);
n++;
XtSetArg(args[n],XmNtopOffset,8);
n++;
XtSetArg(args[n],XmNrightAttachment,XmATTACH_FORM);
n++;
XtSetArg(args[n],XmNrightOffset,8);
n++;
if (otherFontList != NULL) {
XtSetArg(args[n],XmNfontList,otherFontList);
n++;
}
if (background >= 0) {
XtSetArg(args[n],XmNbackground,(unsigned long)background);
n++;
}
if (foreground >= 0) {
XtSetArg(args[n],XmNforeground,(unsigned long)foreground);
n++;
}
okButton = XmCreatePushButton(form,"okButton",args,n);
XtAddCallback(okButton,XmNactivateCallback,
(XtCallbackProc)closeProductDescriptionCallback,
(XtPointer)productDescriptionShell);
n++;
XmStringFree(okXmString);
children[0] = nameLabel;
children[1] = descriptionLabel;
children[2] = versionInfoLabel;
children[3] = developedAtLabel;
children[4] = separator;
XtManageChildren(children,5);
XtManageChild(form);
XtPopup(productDescriptionShell,XtGrabNone);
/* Center nameLabel vertically in form space */
XtSetArg(args[0],XmNheight,&nameHeight);
XtGetValues(nameLabel,args,1);
XtSetArg(args[0],XmNheight,&formHeight);
XtGetValues(form,args,1);
offset = (formHeight - nameHeight);
offset = offset/2;
XtSetArg(args[0],XmNtopOffset,offset);
XtSetValues(nameLabel,args,1);
/* Center the whole thing on the screen */
screenHeight=DisplayHeight(display,screen);
screenWidth=DisplayWidth(display,screen);
n=0;
XtSetArg(args[n],XmNheight,&shellHeight);
n++;
XtSetArg(args[n],XmNwidth,&shellWidth);
n++;
XtGetValues(productDescriptionShell,args,n);
newY=(screenHeight-shellHeight)/2;
newX=(screenWidth-shellWidth)/2;
n=0;
XtSetArg(args[n],XmNy,newY);
n++;
XtSetArg(args[n],XmNx,newX);
n++;
XtSetValues(productDescriptionShell,args,n);
#ifdef WIN32
/* Seems to be an Exceed bug that it doesn't get set the first time */
n=0;
XtSetArg(args[n],XmNy,newY);
n++;
XtSetArg(args[n],XmNx,newX);
n++;
XtSetValues(productDescriptionShell,args,n);
#endif
#if DEBUG_POSITION
{
Position newx, newy;
printf("createAndPopupProductDescriptionShell:\n");
printf(" sizeof(XtArgVal)=%d sizeof(Position)=%d sizeof(Dimension)=%d sizeof(100)=%d\n",
sizeof(XtArgVal),sizeof(Position),sizeof(Dimension),sizeof(100));
printf(" shellHeight=%d shellWidth=%d\n",shellHeight,shellWidth);
printf(" screenHeight=%d screenWidth=%d\n",screenHeight,screenWidth);
printf(" newY=%hd newX=%hd\n",newY,newX);
printf(" newY=%hx newX=%hx\n",newY,newX);
printf(" newY=%x newX=%x\n",newY,newX);
printf("(1) args[0].value=%4x args[1].value=%4x\n",args[0].value,args[1].value);
n=0;
XtSetArg(args[n],XmNy,&newy);
n++;
XtSetArg(args[n],XmNx,&newx);
n++;
XtGetValues(productDescriptionShell,args,n);
printf("(1) newy=%d newx=%d\n",newy,newx);
n=0;
XtSetArg(args[n],XmNy,474);
n++;
XtSetArg(args[n],XmNx,440);
n++;
XtSetValues(productDescriptionShell,args,n);
printf("(2) args[0].value=%4x args[1].value=%4x\n",args[0].value,args[1].value);
n=0;
XtSetArg(args[n],XmNy,&newy);
n++;
XtSetArg(args[n],XmNx,&newx);
n++;
XtGetValues(productDescriptionShell,args,n);
printf("(2) newy=%d newx=%d\n",newy,newx);
n=0;
XtSetArg(args[n],XmNy,newY);
n++;
XtSetArg(args[n],XmNx,newX);
n++;
XtSetValues(productDescriptionShell,args,n);
printf("(3) args[0].value=%4x args[1].value=%4x\n",args[0].value,args[1].value);
n=0;
XtSetArg(args[n],XmNy,&newy);
n++;
XtSetArg(args[n],XmNx,&newx);
n++;
XtGetValues(productDescriptionShell,args,n);
printf("(3) newy=%d newx=%d\n",newy,newx);
}
#endif
/* Free strings */
if (nameXmString != (XmString)NULL) XmStringFree(nameXmString);
if (descriptionXmString != (XmString)NULL) XmStringFree(descriptionXmString);
if (versionInfoXmString != (XmString)NULL) XmStringFree(versionInfoXmString);
if (developedAtXmString != (XmString)NULL) XmStringFree(developedAtXmString);
/* Register timeout procedure to make the dialog go away after N seconds */
XtAppAddTimeOut(appContext,(unsigned long)(1000*seconds),
(XtTimerCallbackProc)popdownProductDescriptionShell,
(XtPointer)productDescriptionShell);
return(productDescriptionShell);
}
#ifdef TEST_PRODUCT_DESCRIPTION_SHELL
/*************************************************************************/
main(int argc, char **argv)
{
Widget topLevel, shell;
XtAppContext appContext;
topLevel = XtAppInitialize(&appContext, "TEST", NULL, 0, &argc, argv,
fallbackResources, NULL, 0);
XmRegisterConverters();
shell = createAndPopupProductDescriptionShell(appContext,topLevel,
"MEDM", NULL,(Pixmap)NULL,
"Motif-based Editor & Display Manager", NULL,
"Version "VERSION,
"developed at Argonne National Laboratory, by Mark Anderson", NULL,
-1, -1, 3);
XtRealizeWidget(topLevel);
XtAppMainLoop(appContext);
}
#endif /* TEST */