Debian Codegraph @

demos/unsupported/motifshell/motifshell.c

raw
1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5 *
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
22 */
23 /*
24 * HISTORY
25 */
26 #ifdef REV_INFO
27 #ifndef lint
28 static char rcsid[] = "$TOG: motifshell.c /main/7 1997/03/31 13:41:20 dbl $"
29 #endif
30 #endif
31
32 /****************************************************************************
33 ****************************************************************************
34 **
35 ** File: motifShell.c
36 **
37 ** Project: Motif - widget examination program
38 **
39 ** Description: Program which shows resources of widgets
40 **
41 ****************************************************************************
42 ****************************************************************************/
43
44 /***************************************************
45 * *
46 * Revision history: *
47 * *
48 * 05/26/89 strong Initial Version *
49 * 06/01/89 strong 1.0 *
50 * 06/26/89 pjlevine complete rewrite *
51 * 03/12/92 deblois yet another rewrite *
52 * *
53 ****************************************************/
54
55 #include <X11/Xos.h>
56
57 /* Standard C headers */
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <sys/signal.h>
61
62 /* X headers */
63 #include <X11/IntrinsicP.h>
64
65
66 /* Xm headers */
67 #include <Xm/Xm.h>
68 #include <Xm/CascadeB.h>
69 #include <Xm/DialogS.h>
70 #include <Xm/FileSB.h>
71 #include <Xm/Form.h>
72 #include <Xm/Label.h>
73 #include <Xm/List.h>
74 #include <Xm/MainW.h>
75 #include <Xm/MenuShell.h>
76 #include <Xm/PushB.h>
77 #include <Xm/RepType.h>
78 #include <Xm/ScrolledW.h>
79 #include <Xm/SelectioB.h>
80 #include <Xm/Text.h>
81
82
83 #define APP_CLASS "XMdemo"
84 #define DEFAULT_FONT "fixed"
85 #define TEST_STRING "The quick brown fox jumps over the lazy dog."
86 #define TEST_HELP "Type here to test the font.\nApply sets this window.\nOK sets main window."
87 #define HELP_FILE "help"
88 #define WELCOME_FILE "welcome"
89 #define MEMBERSHIP_FILE "membership"
90 #define RESEARCH_FILE "research"
91 #define PRINCIPLES_FILE "principles"
92 #define MOTIF_FILE "motif"
93 #define READ 0
94 #define WRITE 1
95
96 /* Global Variables */
97 Display *display;
98 char filename [256];
99 Widget TextWin;
100 Widget LabelW;
101 XtAppContext AppContext;
102 int perr[2], p;
103
104 /* Declarations */
105 int GetFileLen (int fd);
106
107
108
109
110 /*-------------------------------------------------------------*
111 | ExtractNormalString |
112 | support routine to get normal string from XmString |
113 *-------------------------------------------------------------*/
114 char *ExtractNormalString(XmString cs)
115 {
116 XmStringContext context;
117 XmStringCharSet charset;
118 XmStringDirection direction;
119 Boolean separator;
120 static char *primitiveString;
121
122
123 XmStringInitContext (&context, cs);
124 XmStringGetNextSegment (context, &primitiveString, &charset,
125 &direction, &separator);
126 XmStringFreeContext (context);
127
128 return ((char *) primitiveString);
129 }
130
131
132 /*-------------------------------------------------------------*
133 | FontSelectApply |
134 *-------------------------------------------------------------*/
135 void FontSelectApply (Widget w, XtPointer client_data, XtPointer call_data)
136 {
137 XmSelectionBoxCallbackStruct *cdata = (XmSelectionBoxCallbackStruct *)call_data;
138 Widget textWidget = (Widget)client_data;
139 char *textstr;
140 XmFontList fontList;
141 XFontStruct *mfinfo;
142
143
144 /* no font selected... */
145 if (cdata->value == NULL) return;
146
147 textstr = ExtractNormalString (cdata->value);
148
149 if ((mfinfo = XLoadQueryFont(display, textstr))==NULL)
150 printf ("couldn't open %s font\n", textstr);
151 fontList = XmFontListCreate (mfinfo, XmFONTLIST_DEFAULT_TAG);
152
153 XtVaSetValues(textWidget, XmNfontList, fontList, NULL);
154 }
155
156
157 /*-------------------------------------------------------------*
158 | FontSelectOK |
159 *-------------------------------------------------------------*/
160 void FontSelectOK (Widget w, XtPointer client_data, XtPointer call_data)
161 {
162 XmSelectionBoxCallbackStruct *callback_data =
163 (XmSelectionBoxCallbackStruct *)call_data;
164 char *textstr;
165 XmFontList fontList;
166 XFontStruct *mfinfo;
167
168 if (callback_data->value == (XmString) NULL)
169 return;
170
171 textstr = ExtractNormalString (callback_data->value);
172
173 if ((mfinfo = XLoadQueryFont(display, textstr))==NULL)
174 printf ("couldn't open %s font\n", textstr);
175 fontList = XmFontListCreate (mfinfo, XmFONTLIST_DEFAULT_TAG);
176
177 XtVaSetValues(TextWin, XmNfontList, fontList, NULL);
178 }
179
180
181
182 /*-------------------------------------------------------------*
183 | FontTest |
184 *-------------------------------------------------------------*/
185 void FontTest (Widget w, XtPointer client_data, XtPointer call_data)
186 {
187 XmSelectionBoxCallbackStruct *callback_data =
188 (XmSelectionBoxCallbackStruct *)call_data;
189 Widget txtWidget = (Widget)client_data;
190 char *textstr = DEFAULT_FONT;
191 XmFontList fontList;
192 XFontStruct *mfinfo;
193
194
195 if (callback_data->value == (XmString) NULL)
196 return;
197
198 textstr = ExtractNormalString (callback_data->value);
199 if (textstr == NULL) sprintf(textstr, "%s", DEFAULT_FONT);
200
201 if ((mfinfo = XLoadQueryFont(display, textstr))==NULL)
202 printf ("couldn't open %s font\n", textstr);
203 fontList = XmFontListCreate (mfinfo, " ");
204
205 XtVaSetValues(txtWidget,
206 XmNfontList, fontList,
207 XmNvalue, TEST_HELP,
208 NULL);
209 }
210
211 /*-------------------------------------------------------------*
212 | NextCap |
213 *-------------------------------------------------------------*/
214
215 char *NextCap (char *path, char *cp, int len)
216 {
217 static int finish = 0;
218 int span;
219 char *ep, *np;
220
221
222 if (!finish)
223 return(NULL);
224
225 if ((ep = strchr(cp, ':')))
226 span = ep - cp;
227 else
228 {
229 finish++;
230 ep = strchr(cp, '\0');
231 span = ep - cp;
232 };
233
234 np = malloc(span + len + 2);
235 strncpy(np, cp, span);
236
237 np[span] = '/';
238 np[span+1] = '\0';
239
240 return(np);
241 }
242
243
244 /*-------------------------------------------------------------*
245 | file_exist |
246 *-------------------------------------------------------------*/
247 int file_exist (char *fullname)
248 {
249 /* Save the file pointer so it can be closed */
250 FILE *tmpf;
251
252 if ((tmpf=fopen(fullname,"r")))
253 {
254 fclose(tmpf);
255 return(1);
256 }
257 else
258 return(0);
259 }
260
261
262 /*-------------------------------------------------------------*
263 | search_in_env |
264 *-------------------------------------------------------------*/
265 char *search_in_env (char *filename)
266 {
267 int i, len;
268 char *envpath, *prefix, *cp;
269
270
271 len = strlen(filename);
272 if ((envpath = getenv("PATH")))
273 {
274 cp = envpath;
275 cp += 2;
276
277 while ((prefix = NextCap(envpath, cp, len)))
278 {
279 cp += strlen(prefix);
280 strncat(prefix, filename, len);
281
282 if (file_exist(prefix))
283 return(prefix);
284
285 free(prefix);
286 }
287
288 }
289
290 return(NULL);
291 }
292
293 /*-------------------------------------------------------------*
294 | GetSource |
295 *-------------------------------------------------------------*/
296 char *GetSource (char *fileptr)
297 {
298 static char *retbuff;
299 int fd, flen, catlen;
300 char *capfileptr, *defaultcap, *datahome;
301
302
303 if ((fd = open (fileptr, O_RDONLY)) < 0)
304 {
305 /* Try looking in MSHELLDIR. */
306 char pathname[1024];
307 /* strcpy(pathname, MSHELLDIR); */
308 strcat(pathname, "/");
309 strcat(pathname, fileptr);
310
311 if ((fd = open (pathname, O_RDONLY)) < 0)
312 {
313 if ((defaultcap = getenv("MOTIFSHELLFILES")))
314 {
315 catlen = strlen(defaultcap);
316 datahome = (char *) malloc(catlen + strlen(fileptr) + 2);
317 strncpy(datahome, defaultcap, catlen);
318 datahome[catlen] = '/';
319 datahome[catlen + 1] = '\0';
320 strcat(datahome, fileptr);
321
322 if ((fd = open(datahome, O_RDONLY)) < 0)
323 {
324 printf ("Cannot find the file %s in %s\n", fileptr, datahome);
325 free(datahome);
326 return((char *) NULL);
327 }
328 free(datahome);
329 }
330 else
331 if ((capfileptr = search_in_env(fileptr)))
332 {
333 fd = open (capfileptr, O_RDONLY);
334 free(capfileptr);
335 }
336 else
337 {
338 printf ("Cannot find the file %s\n", fileptr);
339 printf ("Please setup MOTIFSHELLFILES entry in environment and put data files there.\n");
340 return ((char *) NULL);
341 }
342 }
343 }
344
345 flen = GetFileLen(fd);
346 retbuff = (char*) calloc (1, flen + 1);
347
348 if (read (fd, retbuff, flen) <= 0)
349 {
350 printf ("Error reading file %s\n", fileptr);
351 return ((char *) NULL);
352 }
353 close (fd);
354
355 return (retbuff);
356 }
357
358
359 /*-------------------------------------------------------------*
360 | DoTheFont |
361 *-------------------------------------------------------------*/
362 XmString *DoTheFont (int *count)
363 {
364 char **fontlist;
365 int i;
366 static XmString *addrstr;
367
368
369 fontlist = XListFonts (display, "*", 1200, count);
370 addrstr = (XmString *) XtCalloc (*count, sizeof (XmString));
371 for (i = 0; i < *count; i++) addrstr[i] = XmStringCreateLocalized(fontlist[i]);
372
373 return (addrstr);
374 }
375
376
377 /*-------------------------------------------------------------*
378 | PopupHelpShell |
379 *-------------------------------------------------------------*/
380 void PopupHelpShell (Widget w, XtPointer client_data, XtPointer call_data)
381 {
382 Widget helpText = (Widget)client_data;
383 char *buffer;
384
385
386 buffer = GetSource (HELP_FILE);
387 XmTextSetString (helpText, buffer);
388 }
389
390
391 /*-------------------------------------------------------------*
392 | SetLabelStr |
393 *-------------------------------------------------------------*/
394 void SetLabelStr (XmString tcs)
395 {
396 XtVaSetValues(LabelW, XmNlabelString, tcs, NULL);
397 }
398
399
400 /*-------------------------------------------------------------*
401 | SetLabel |
402 *-------------------------------------------------------------*/
403 void SetLabel (char *label)
404 {
405 XmString tcs;
406
407 tcs = XmStringCreateLocalized(label);
408 SetLabelStr(tcs);
409 XmStringFree(tcs);
410 }
411
412 /*-------------------------------------------------------------*
413 | ShowFontDialogShell |
414 *-------------------------------------------------------------*/
415 void ShowFontDialogShell (Widget parent, char *label)
416 {
417 Widget workText, list;
418 static Widget dlog = NULL;
419 int count;
420 XmString *fonts;
421
422
423 if (dlog == NULL)
424 {
425 fonts = DoTheFont(&count);
426
427 dlog = XmCreateSelectionDialog(parent, label, NULL, 0);
428
429 workText = XtVaCreateManagedWidget ("workText", xmTextWidgetClass, dlog,
430 XmNeditable, True,
431 XmNeditMode, XmMULTI_LINE_EDIT,
432 XmNcolumns, 30,
433 XmNrows, 3,
434 XmNresizeHeight, False,
435 XmNwordWrap, True,
436 XmNvalue, TEST_STRING,
437 NULL);
438 XtVaSetValues(dlog,
439 XmNwidth, 450,
440 XmNheight, 450,
441 XmNallowShellResize, True,
442 XmNlistItems, fonts,
443 XmNlistItemCount, count,
444 XmNlistVisibleItemCount, 10,
445 NULL);
446
447 list = XmSelectionBoxGetChild(dlog, XmDIALOG_LIST);
448 XtVaSetValues(list, XmNselectionPolicy, XmSINGLE_SELECT, NULL);
449
450 XtUnmanageChild(XmSelectionBoxGetChild(dlog, XmDIALOG_APPLY_BUTTON));
451
452 XtAddCallback (dlog, XmNokCallback, FontSelectOK, NULL);
453 XtAddCallback (dlog, XmNhelpCallback, FontTest, (XtPointer)workText);
454 XtAddCallback (list, XmNsingleSelectionCallback, FontSelectApply,
455 (XtPointer)workText);
456 }
457
458 XtManageChild(dlog);
459 }
460
461
462
463
464 /*-------------------------------------------------------------*
465 | CreateHelpDialogShell |
466 *-------------------------------------------------------------*/
467 void CreateHelpDialogShell (Widget parent, char *say)
468 {
469 static Widget dlog = NULL;
470 Widget helpText, button;
471
472 if (dlog == NULL)
473 {
474 dlog = XmCreateFormDialog(parent, "Help Window", NULL, 0);
475 helpText = XtVaCreateManagedWidget("helpText", xmTextWidgetClass, dlog,
476 XmNeditable, False,
477 XmNeditMode, XmMULTI_LINE_EDIT,
478 XmNcolumns, 50,
479 XmNresizeHeight, True,
480 XmNwordWrap, True,
481 XmNleftAttachment, XmATTACH_FORM,
482 XmNtopAttachment, XmATTACH_FORM,
483 XmNrightAttachment, XmATTACH_FORM,
484 XmNbottomAttachment, XmATTACH_FORM,
485 XmNbottomOffset, 30,
486 NULL);
487 button = XtVaCreateManagedWidget("dismiss", xmPushButtonWidgetClass, dlog,
488 XmNleftAttachment, XmATTACH_FORM,
489 XmNtopAttachment, XmATTACH_WIDGET,
490 XmNtopWidget, helpText,
491 XmNrightAttachment, XmATTACH_FORM,
492 XmNbottomAttachment, XmATTACH_FORM,
493 NULL);
494 XtAddCallback (XtParent(dlog), XmNpopupCallback, PopupHelpShell,
495 (XtPointer)helpText);
496 }
497
498 XtManageChild(dlog);
499 }
500
501
502
503 /*-------------------------------------------------------------*
504 | CreateTextWin |
505 *-------------------------------------------------------------*/
506 Widget CreateTextWin (Widget parent)
507 {
508 Widget stext;
509 char *buffer;
510 XmString tcs;
511
512
513 tcs = XmStringCreateLocalized ("Welcome to Motif");
514 LabelW = XtVaCreateManagedWidget("Label", xmLabelWidgetClass, parent,
515 XmNleftAttachment, XmATTACH_FORM,
516 XmNtopAttachment, XmATTACH_FORM,
517 XmNrightAttachment, XmATTACH_FORM,
518 XmNlabelString, tcs,
519 XmNmarginHeight, 5,
520 XmNshadowThickness, 1,
521 NULL);
522 XmStringFree (tcs);
523
524 stext = XmCreateScrolledText(parent, "s_text", NULL, 0);
525 XtVaSetValues(stext,
526 XmNeditMode, XmMULTI_LINE_EDIT,
527 XmNeditable, False,
528 XmNcolumns, 80,
529 XmNrows, 30,
530 NULL);
531 XtVaSetValues(XtParent(stext),
532 XmNleftAttachment, XmATTACH_FORM,
533 XmNtopAttachment, XmATTACH_WIDGET,
534 XmNrightAttachment, XmATTACH_FORM,
535 XmNbottomAttachment, XmATTACH_FORM,
536 XmNtopWidget, LabelW,
537 XmNleftOffset, 5,
538 XmNrightOffset, 5,
539 XmNbottomOffset, 5,
540 XmNheight, 550,
541 XmNwidth, 500,
542 XmNresizeWidth, True,
543 XmNresizeHeight, False,
544 NULL);
545 XtManageChild(stext);
546
547 buffer = GetSource (WELCOME_FILE);
548 XmTextSetString (stext, buffer);
549
550 return(stext);
551 }
552
553
554 /*-------------------------------------------------------------*
555 | GetFileLen |
556 *-------------------------------------------------------------*/
557 int GetFileLen (int fd)
558 {
559 static int retval;
560
561 #if defined(L_SET) && defined(L_XTND)
562 lseek (fd, 0, L_SET);
563 retval = lseek (fd, 0, L_XTND);
564 lseek (fd, 0, L_SET);
565 #else
566 lseek (fd, 0, SEEK_SET);
567 retval = lseek (fd, 0, SEEK_END);
568 lseek (fd, 0, SEEK_SET);
569 #endif
570 return (retval);
571 }
572
573
574 /*-------------------------------------------------------------*
575 | SysCall |
576 *-------------------------------------------------------------*/
577 void SysCall (Widget widget, char *systemCommand, Boolean set_uidpath)
578 {
579 #define CMD "find .. -name '%s' \\( -type f -o -type l \\) -print"
580 char str[256];
581 char *findCmd;
582 FILE *file;
583 pid_t p;
584
585 if ((p = fork()) == 0)
586 {
587 /* note - execlp uses PATH */
588 execlp(systemCommand, systemCommand, NULL);
589
590 /* if we fail to find the systemCommand, use 'find' to look for it. */
591 fprintf(stderr, "can't find %s\n", systemCommand);
592
593 findCmd = (char *) XtMalloc(strlen(systemCommand) + sizeof(CMD) + 1);
594 sprintf(findCmd, CMD, systemCommand);
595 file = popen(findCmd, "r");
596 XtFree(findCmd);
597
598 /* If this program is not on our path, then it's uid file */
599 /* probably isn't either. Set UIDPATH if requested and unset. */
600 if (set_uidpath)
601 set_uidpath = (getenv("UIDPATH") == NULL);
602
603 while(fgets(str, 80, file) != NULL)
604 {
605 str[strlen(str)-1] = '\0';
606 printf("Trying: %s\n", str);
607 if (set_uidpath)
608 {
609 #ifndef NO_PUTENV
610 char *uidpath = XtMalloc(8 + strlen(str) + 4 + 1);
611 sprintf(uidpath, "UIDPATH=%s.uid", str);
612 putenv(uidpath);
613 #else
614 char *uidpath = XtMalloc(strlen(str) + 4 + 1);
615 sprintf(uidpath, "%s.uid", str);
616 setenv("UIDPATH", uidpath, 1);
617 #endif
618 }
619 execl(str, systemCommand, NULL);
620 printf("Still can't find %s...\n", systemCommand);
621 }
622 printf("I give up!\n");
623 exit(0);
624 }
625 }
626
627
628 /*-------------------------------------------------------------*
629 | Quit |
630 *-------------------------------------------------------------*/
631 void Quit(int i)
632 {
633 printf("Bye!\n");
634 exit(0);
635 }
636
637
638 /*-------------------------------------------------------------*
639 | Menu1CB |
640 | File pulldown menu items. |
641 *-------------------------------------------------------------*/
642 void Menu1CB (Widget w, XtPointer clientData, XtPointer callData)
643 {
644 int itemNo = (int)clientData;
645
646 switch (itemNo)
647 {
648 case 0: Quit(0); break; /* Quit */
649 }
650 }
651
652
653 /*-------------------------------------------------------------*
654 | Menu2CB |
655 | OSF Happenings pulldown menu items. |
656 *-------------------------------------------------------------*/
657 void Menu2CB (Widget w, XtPointer clientData, XtPointer callData)
658 {
659 int itemNo = (int)clientData;
660 char *buffer = NULL;
661 XmString labelStr;
662
663
664 XtVaGetValues(w, XmNlabelString, &labelStr, NULL);
665 SetLabelStr (labelStr);
666
667 switch (itemNo)
668 {
669 case 0: buffer = GetSource (MEMBERSHIP_FILE); break;
670 case 1: buffer = GetSource (RESEARCH_FILE); break;
671 case 2: buffer = GetSource (PRINCIPLES_FILE); break;
672 case 3: buffer = GetSource (MOTIF_FILE); break;
673 }
674 XmTextSetString (TextWin, buffer);
675 }
676
677
678 /*-------------------------------------------------------------*
679 | Menu3CB |
680 | Demos pulldown menu items. |
681 *-------------------------------------------------------------*/
682 void Menu3CB (Widget w, XtPointer clientData, XtPointer callData)
683 {
684 int itemNo = (int)clientData;
685 XmString labelStr;
686
687
688 XtVaGetValues(w, XmNlabelString, &labelStr, NULL);
689 SetLabelStr (labelStr);
690
691 switch (itemNo)
692 {
693 case 0: SysCall (w, "periodic", True); break;
694 case 1: SysCall (w, "dogs", True); break;
695 case 2: SysCall (w, "motifanim", False); break;
696 }
697 }
698
699
700 /*-------------------------------------------------------------*
701 | Menu4CB |
702 | Unix Commands pulldown menu items. |
703 *-------------------------------------------------------------*/
704 void Menu4CB (Widget w, XtPointer clientData, XtPointer callData)
705 {
706 int itemNo = (int)clientData;
707 char *buffer;
708 XmString labelStr;
709
710 switch (itemNo)
711 {
712 case 0: /* File Listing */
713 {
714 XtVaGetValues(w, XmNlabelString, &labelStr, NULL);
715 SetLabelStr (labelStr);
716 system ("ls -al > /tmp/motifshell.tmp");
717 buffer = GetSource ("/tmp/motifshell.tmp");
718 XmTextSetString (TextWin, buffer);
719 system ("rm -r /tmp/motifshell.tmp");
720 break;
721 }
722 case 1: /* Process Status */
723 {
724 XtVaGetValues(w, XmNlabelString, &labelStr, NULL);
725 SetLabelStr (labelStr);
726 #ifdef linux
727 system ("ps a > /tmp/motifshell.tmp");
728 #else
729 system ("ps -a > /tmp/motifshell.tmp");
730 #endif
731 buffer = GetSource ("/tmp/motifshell.tmp");
732 XmTextSetString (TextWin, buffer);
733 system ("rm -r /tmp/motifshell.tmp");
734 break;
735 }
736 case 2: /* Show Source */
737 {
738 XtVaGetValues(w, XmNlabelString, &labelStr, NULL);
739 SetLabelStr (labelStr);
740 buffer = GetSource (filename);
741 XtVaSetValues(TextWin, XmNvalue, buffer, NULL);
742 break;
743 }
744 }
745 }
746
747
748 /*-------------------------------------------------------------*
749 | Menu5CB |
750 | X Programs pulldown menu items. |
751 *-------------------------------------------------------------*/
752 void Menu5CB (Widget w, XtPointer clientData, XtPointer callData)
753 {
754 int itemNo = (int)clientData;
755
756 switch (itemNo)
757 {
758 case 0: SysCall (w, "xterm", False); break;
759 case 1: SysCall (w, "xclock", False); break;
760 case 2: SysCall (w, "xload", False); break;
761 }
762 }
763
764
765 /*-------------------------------------------------------------*
766 | Menu6CB |
767 | Font pulldown menu items. |
768 *-------------------------------------------------------------*/
769 void Menu6CB (Widget w, XtPointer clientData, XtPointer callData)
770 {
771 int itemNo = (int)clientData;
772
773 switch (itemNo)
774 {
775 case 0: /* Load... */
776 {
777 ShowFontDialogShell (XtParent(w), "List O' Fonts");
778 break;
779 }
780 }
781 }
782
783
784 /*-------------------------------------------------------------*
785 | Menu7CB |
786 | Help pulldown menu items. |
787 *-------------------------------------------------------------*/
788 void Menu7CB (Widget w, XtPointer clientData, XtPointer callData)
789 {
790 int itemNo = (int)clientData;
791
792
793 switch (itemNo)
794 {
795 case 0: /* Are you sure? */
796 {
797 CreateHelpDialogShell (XtParent(w), "Help Window");
798 break;
799 }
800 }
801 }
802
803
804 static char *menuString[] = {
805 "File", "OSF Happenings", "Demos", "Unix Commands", "X Programs", "Font", "Help"
806 };
807 static char *subString[][XtNumber(menuString)] = {
808 { "Quit" },
809 { "OSF Membership", "OSF's Research Institute", "OSF's Principles", "OSF/Motif" },
810 { "Periodic Table", "Dogs", "Animation" },
811 { "File Listing", "Process Status", "Show Source" },
812 { "Xterm", "Xclock", "Xload"},
813 { "Load..." },
814 { "Are you sure ?" }
815 };
816
817
818 /*-------------------------------------------------------------*
819 | CreateMenuBar |
820 *-------------------------------------------------------------*/
821 Widget CreateMenuBar (Widget parent)
822 {
823 int i;
824 XmString s[10];
825 Widget menuBar, helpCascade;
826
827 menuBar = XmVaCreateSimpleMenuBar(parent, "MenuBar",
828 XmVaCASCADEBUTTON, s[0] = XmStringCreateSimple(menuString[0]), menuString[0][0],
829 XmVaCASCADEBUTTON, s[1] = XmStringCreateSimple(menuString[1]), menuString[1][0],
830 XmVaCASCADEBUTTON, s[2] = XmStringCreateSimple(menuString[2]), menuString[2][0],
831 XmVaCASCADEBUTTON, s[3] = XmStringCreateSimple(menuString[3]), menuString[3][0],
832 XmVaCASCADEBUTTON, s[4] = XmStringCreateSimple(menuString[4]), menuString[4][0],
833 XmVaCASCADEBUTTON, s[5] = XmStringCreateSimple(menuString[5]), menuString[5][0],
834 XmVaCASCADEBUTTON, s[6] = XmStringCreateSimple(menuString[6]), menuString[6][0],
835 NULL);
836 for (i=0; i<=6; i++) XmStringFree(s[i]);
837
838 XmVaCreateSimplePulldownMenu(menuBar, menuString[0], 0, Menu1CB, /* File */
839 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[0][0]), NULL, NULL, NULL,
840 NULL);
841 for (i=0; i<1; i++) XmStringFree(s[i]);
842
843 XmVaCreateSimplePulldownMenu(menuBar, menuString[1], 1, Menu2CB, /* OSF Happenings */
844 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[1][0]), NULL, NULL, NULL,
845 XmVaPUSHBUTTON, s[1] = XmStringCreateSimple(subString[1][1]), NULL, NULL, NULL,
846 XmVaPUSHBUTTON, s[2] = XmStringCreateSimple(subString[1][2]), NULL, NULL, NULL,
847 XmVaPUSHBUTTON, s[3] = XmStringCreateSimple(subString[1][3]), NULL, NULL, NULL,
848 NULL);
849 for (i=0; i<=3; i++) XmStringFree(s[i]);
850
851 XmVaCreateSimplePulldownMenu(menuBar, menuString[2], 2, Menu3CB, /* Demos */
852 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[2][0]), NULL, NULL, NULL,
853 XmVaPUSHBUTTON, s[1] = XmStringCreateSimple(subString[2][1]), NULL, NULL, NULL,
854 XmVaPUSHBUTTON, s[2] = XmStringCreateSimple(subString[2][2]), NULL, NULL, NULL,
855 NULL);
856 for (i=0; i<=2; i++) XmStringFree(s[i]);
857
858 XmVaCreateSimplePulldownMenu(menuBar, menuString[3], 3, Menu4CB, /* Unix Commands */
859 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[3][0]), NULL, NULL, NULL,
860 XmVaPUSHBUTTON, s[1] = XmStringCreateSimple(subString[3][1]), NULL, NULL, NULL,
861 XmVaPUSHBUTTON, s[2] = XmStringCreateSimple(subString[3][2]), NULL, NULL, NULL,
862 NULL);
863 for (i=0; i<=2; i++) XmStringFree(s[i]);
864
865 XmVaCreateSimplePulldownMenu(menuBar, menuString[4], 4, Menu5CB, /* X Programs */
866 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[4][0]), NULL, NULL, NULL,
867 XmVaPUSHBUTTON, s[1] = XmStringCreateSimple(subString[4][1]), NULL, NULL, NULL,
868 XmVaPUSHBUTTON, s[2] = XmStringCreateSimple(subString[4][2]), NULL, NULL, NULL,
869 NULL);
870 for (i=0; i<=2; i++) XmStringFree(s[i]);
871
872 XmVaCreateSimplePulldownMenu(menuBar, menuString[5], 5, Menu6CB, /* Font */
873 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[5][0]), NULL, NULL, NULL,
874 NULL);
875 for (i=0; i<=0; i++) XmStringFree(s[i]);
876
877 XmVaCreateSimplePulldownMenu(menuBar, menuString[6], 6, Menu7CB, /* Help */
878 XmVaPUSHBUTTON, s[0] = XmStringCreateSimple(subString[6][0]), NULL, NULL, NULL,
879 NULL);
880 for (i=0; i<=0; i++) XmStringFree(s[i]);
881 XtVaSetValues(menuBar, XmNmenuHelpWidget, XtNameToWidget(menuBar, "button_6"), NULL);
882
883
884 XtManageChild(menuBar);
885
886 return (menuBar);
887 }
888
889
890
891 /*-------------------------------------------------------------*
892 | main |
893 *-------------------------------------------------------------*/
894
895 int main (int argc, char **argv)
896 {
897 Widget shell, mainWindow, workRegion, menuBar;
898
899
900 signal(SIGHUP, Quit);
901 signal(SIGINT, Quit);
902 signal(SIGQUIT, Quit);
903
904 system ("touch /tmp/motifshell.tmp");
905 system ("rm -r /tmp/motifshell.tmp");
906
907 XtToolkitInitialize();
908 AppContext = XtCreateApplicationContext();
909 if ((display = XtOpenDisplay (AppContext, NULL, argv[0], APP_CLASS,
910 NULL, 0, &argc, argv)) == NULL)
911 {
912 fprintf (stderr,"\n%s: Can't open display\n", argv[0]);
913 exit(1);
914 }
915
916 /* capture the source-code file name for use later. */
917 sprintf(filename, "%s.c", argv[0]);
918
919 XmRepTypeInstallTearOffModelConverter();
920
921 shell = XtVaAppCreateShell(argv[0], APP_CLASS, applicationShellWidgetClass,
922 display, XmNallowShellResize, True, NULL);
923
924
925 mainWindow = XtVaCreateManagedWidget("mainWindow", xmMainWindowWidgetClass, shell,
926 XmNmarginWidth, 2,
927 XmNmarginHeight, 2, NULL);
928 workRegion = XtVaCreateManagedWidget("s_text", xmFormWidgetClass, mainWindow, NULL);
929
930 menuBar = CreateMenuBar (mainWindow);
931 TextWin = CreateTextWin (workRegion);
932 XmMainWindowSetAreas(mainWindow, menuBar, NULL, NULL, NULL, workRegion);
933
934
935 XtRealizeWidget(shell);
936
937 XtAppMainLoop(AppContext);
938
939 return 0; /* make compiler happy */
940 }