home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / motifpg2.zip / ch03 / xmainwindow.c < prev    next >
C/C++ Source or Header  |  1992-07-08  |  6KB  |  195 lines

  1. /*
  2.  * Copyright 1989, 1992 O'Reilly and Associates, Inc.
  3.  * See ../Copyright for complete rights and liability information.
  4.  */
  5.  
  6. /* 
  7.  *  xmainwindow.c - main window with help and quit
  8.  */
  9.  
  10. /*
  11.  *  So that we can use fprintf:
  12.  */
  13. #include <stdio.h>
  14.  
  15. /* 
  16.  * Standard Toolkit include files:
  17.  */
  18. #include <X11/Intrinsic.h>
  19. #include <Xm/Xm.h>
  20. #include <Xm/RepType.h>
  21. /*
  22.  * Public include files for widgets used in this file.
  23.  */
  24. #include <Xm/PushB.h>
  25. #include <Xm/MainW.h>
  26. #include <Xm/RowColumn.h>
  27. #include <Xm/MessageB.h>
  28. #include <Xm/CascadeB.h>
  29. #include <Xm/Frame.h>
  30.  
  31. /* 
  32.  * callback to pop up help dialog widget 
  33.  */
  34. /*ARGSUSED*/
  35. void ShowHelp(w, client_data, call_data)
  36. Widget w;
  37. XtPointer client_data;
  38. XtPointer call_data;
  39. {
  40.     Widget dialog = (Widget) client_data;
  41.     XtManageChild(dialog);
  42. }
  43.  
  44. /*
  45.  * quit button callback function
  46.  */
  47. /*ARGSUSED*/
  48. void Quit(w, client_data, call_data)
  49. Widget w;
  50. XtPointer client_data, call_data;
  51.     exit(0); 
  52. }
  53.  
  54. main(argc, argv)
  55. int argc;
  56. char **argv;
  57. {
  58.     XtAppContext app_context;
  59.     Widget topLevel, mainWindow, menuBar, frame;
  60.     Widget fileButton, fileMenu, quit, helpButton, helpMenu, help, helpBox;
  61.     Widget temp;
  62.  
  63.     /*
  64.      * Register the default language procedure
  65.      */
  66.     XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
  67.  
  68.     topLevel = XtVaAppInitialize(
  69.             &app_context,       /* Application context */
  70.             "XMainWindow",      /* application class name */
  71.             NULL, 0,            /* command line option list */
  72.             &argc, argv,        /* command line args */
  73.             NULL,               /* for missing app-defaults file */
  74.             NULL);              /* terminate varargs list */
  75.  
  76.     /* create main window */
  77.     mainWindow = XtVaCreateManagedWidget(
  78.             "mainWindow",               /* widget name */
  79.             xmMainWindowWidgetClass,    /* widget class */
  80.             topLevel,                   /* parent widget*/
  81.             NULL);                      /* terminate varargs list */
  82.  
  83.     /* register converter for tearoff menus */
  84.     XmRepTypeInstallTearOffModelConverter();
  85.  
  86.     /* create menu bar along top inside of main window */
  87.     menuBar = XmCreateMenuBar(
  88.             mainWindow, /* parent widget*/
  89.             "menuBar",  /* widget name */
  90.             NULL,       /* no arguments needed */
  91.             0);         /* no arguments needed */
  92.     XtManageChild(menuBar);
  93.  
  94.     frame = XtVaCreateManagedWidget(
  95.             "frame",            /* widget name */
  96.             xmFrameWidgetClass, /* widget class */
  97.             mainWindow,         /* parent widget*/
  98.             NULL);              /* terminate varargs list */
  99.  
  100.     /*  Set MainWindow areas */
  101.     XmMainWindowSetAreas (mainWindow, menuBar, NULL, NULL, NULL, frame);
  102.  
  103.     /*
  104.      *  CREATE FILE MENU AND CHILDREN
  105.      */
  106.  
  107.     /* create button that will pop up the menu */
  108.     fileButton = XtVaCreateManagedWidget(
  109.             "fileButton",               /* widget name */
  110.             xmCascadeButtonWidgetClass, /* widget class */
  111.             menuBar,                    /* parent widget*/
  112.             NULL);                      /* terminate varargs list */
  113.  
  114.     /* create menu (really a Shell widget and RowColumn widget combo) */
  115.     fileMenu = XmCreatePulldownMenu(
  116.             menuBar,    /* parent widget*/
  117.             "fileMenu", /* widget name */
  118.             NULL,       /* no argument list needed */
  119.             0);         /* no argument list needed */
  120.  
  121.     /* create the quit button up in the menu */
  122.     quit = XtVaCreateManagedWidget(
  123.             "quit",                     /* widget name */
  124.             xmPushButtonWidgetClass,    /* widget class */
  125.             fileMenu,                   /* parent widget*/
  126.             NULL);                      /* terminate varargs list */
  127.  
  128.     /* 
  129.      * Specify which menu fileButton will pop up.
  130.      */
  131.     XtVaSetValues(fileButton,
  132.           XmNsubMenuId, fileMenu,
  133.           NULL);
  134.  
  135.     /* arrange for quit button to call function that exits. */
  136.     XtAddCallback(quit, XmNactivateCallback, Quit, 0);
  137.  
  138.     /*
  139.      *  CREATE HELP BUTTON AND BOX
  140.      */
  141.  
  142.     /* create button that will bring up help menu */
  143.     helpButton = XtVaCreateManagedWidget(
  144.             "helpButton",               /* widget name */
  145.             xmCascadeButtonWidgetClass, /* widget class */
  146.             menuBar,                    /* parent widget*/
  147.             NULL);                      /* terminate varargs list */
  148.  
  149.     /* tell menuBar which is the help button (will be specially positioned) */
  150.     XtVaSetValues(menuBar,
  151.           XmNmenuHelpWidget, helpButton,
  152.           NULL);
  153.  
  154.     /* create menu (really a Shell widget and RowColumn widget combo) */
  155.     helpMenu = XmCreatePulldownMenu(
  156.             menuBar,    /* parent widget*/
  157.             "helpMenu", /* widget name */
  158.             NULL,       /* no argument list needed */
  159.             0);         /* no argument list needed */
  160.  
  161.     /* create the help button up in the menu */
  162.     help = XtVaCreateManagedWidget(
  163.             "help",                     /* widget name */
  164.             xmPushButtonWidgetClass,    /* widget class */
  165.             helpMenu,                   /* parent widget*/
  166.             NULL);                      /* terminate varargs list */
  167.  
  168.     /* 
  169.      * Specify which menu helpButton will pop up.
  170.      */
  171.     XtVaSetValues(helpButton,
  172.           XmNsubMenuId, helpMenu,
  173.           NULL);
  174.  
  175.     /* create popup that will contain help */
  176.     helpBox = XmCreateMessageDialog(
  177.         help,       /* parent widget*/
  178.             "helpBox",  /* widget name   */
  179.             NULL,       /* no arguments needed */
  180.             0);         /* no arguments needed */
  181.  
  182.     temp = XmMessageBoxGetChild (helpBox, XmDIALOG_CANCEL_BUTTON);
  183.     XtUnmanageChild (temp);
  184.     temp = XmMessageBoxGetChild (helpBox, XmDIALOG_HELP_BUTTON);
  185.     XtUnmanageChild (temp);
  186.  
  187.     /* arrange for getHelp button to pop up helpBox */
  188.     XtAddCallback(help, XmNactivateCallback, ShowHelp, helpBox);
  189.  
  190.     XtRealizeWidget(topLevel);
  191.  
  192.     XtAppMainLoop(app_context);
  193. }
  194.