home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / master12.zip / mastering / Newapp / Main.c < prev    next >
C/C++ Source or Header  |  1992-08-19  |  4KB  |  141 lines

  1. /* Main.c -- This file contains declarations for global variables and
  2.              the application's main() routine.  */
  3.  
  4. /* Declare information for 'what' strings. */
  5. char ident1[]="@(#)NewApp    --    An example from Mastering Motif.";
  6. char ident2[]="@(#)                Version: A.00.17   [01 Aug 1992]";
  7. char ident3[]="@(#)(c) 1989, 1990, 1991 by Hewlett-Packard Company.";
  8.  
  9. #include "Global.h"
  10. #include "Icon.h"
  11.  
  12. /****************************
  13.   Declare the global widgets. 
  14.   ***************************/
  15. Widget   topLevel;
  16. Widget        mainWindow;
  17. Widget           menuBar;
  18. Widget         workArea;
  19. Widget         printOptions;
  20. Widget      exitDialog;
  21.  
  22.  
  23. /* Declare general-purpose global variables for Xt argument lists. */
  24. Arg      al[20];    /*  arg list        */
  25. int      ac;        /*  arg count        */
  26.  
  27. /*******************************
  28.   Application-defined resources.
  29.   ******************************/
  30.  
  31. static XrmOptionDescRec option_list[] =
  32. {
  33.   {  "-session",      "session",      XrmoptionSepArg,  NULL  },
  34. };
  35.  
  36. typedef struct
  37. {
  38.   char * session;
  39. } ApplicationArgs, *ApplicationArgsPtr;
  40.  
  41. static ApplicationArgs applicationArgs;
  42.  
  43. static XtResource resources[] =
  44. {
  45.   {
  46.     "session", "Session", XmRString, sizeof (char *),
  47.     XtOffset (ApplicationArgsPtr, session), XmRImmediate, (XtPointer) NULL,
  48.   },
  49. };
  50.  
  51.  
  52.  
  53. /******************************************************************************
  54.                 M a i n ( )
  55. ******************************************************************************/
  56. void main (argc,argv)
  57.      unsigned int    argc;
  58.      char         **argv;
  59. {
  60.   XtAppContext app_context;
  61.   char *applicationName = XtNewString (argv[0]);
  62.  
  63.   /*************************************
  64.     Initialize toolkit and open display.
  65.     ************************************/
  66.   topLevel = XtAppInitialize(&app_context, "Newapp", option_list,
  67.   1, &argc, argv, NULL, al, 0);
  68.              
  69.   /* topLevel = XtInitialize(applicationName, "Newapp", 
  70.               option_list, 1, &argc, argv); */
  71.  
  72.   /*** Establish the window manager and session manager protocols. ***/
  73.   CreateWindowManagerProtocols(topLevel);
  74.   CreateSessionManagerProtocols(topLevel);
  75.  
  76.   /*** Get application-specific resources. ***/
  77.   XtGetApplicationResources(topLevel, &applicationArgs, resources, 1, NULL,0);
  78.  
  79.   /*** Create the Exit dialog (as a child of the top-level shell). ***/
  80.   exitDialog = CreateExitDialog(topLevel);
  81.  
  82.   /************************
  83.     Create the Main Window.
  84.     ***********************/
  85.  
  86.   /*** Create the Main Window widget. ***/
  87.   ac = 0;
  88.   mainWindow = XmCreateMainWindow (topLevel, "mainWindow", al, ac);
  89.  
  90.   /*** Create the pulldown menu in the main window. ***/
  91.   menuBar = CreateMenuBar (mainWindow); 
  92.   XtManageChild (menuBar);
  93.  
  94.   /*** Create a form as the work area for the main window. ***/
  95.   ac = 0;
  96.   workArea = XmCreateForm (mainWindow, "workArea", al, ac);
  97.  
  98.   /*** Put the printer options menu in the main window ***/     
  99.   printOptions = CreatePrinterOptionMenu(mainWindow);
  100.   XtManageChild (printOptions);
  101.  
  102.   XmMainWindowSetAreas (mainWindow, menuBar, printOptions, NULL, NULL, workArea);
  103.   XtManageChild (mainWindow);
  104.  
  105.   /******************************
  106.     Set up session manager and
  107.     window manager protocols.
  108.    ******************************/
  109.  
  110. /*
  111.   CreateWindowManagerProtocols(topLevel);
  112.   CreateSessionManagerProtocols(topLevel);
  113. */
  114.  
  115.   /* Set default main window title and icon */
  116.  
  117.   ac = 0;
  118.   XtSetArg (al[ac], XmNtitle, "New Application - (untitled)");  ac++;
  119.   XtSetArg (al[ac], XmNiconName, "Newapp");  ac++;
  120.   XtSetArg (al[ac], XmNwidth, 400);  ac++;  /* The default size can be    */
  121.   XtSetArg (al[ac], XmNheight, 250);  ac++; /* overridden with -geometry. */
  122.   XtSetArg (al[ac], XmNallowShellResize, True);  ac++;
  123.   XtSetArg (al[ac], XmNdeleteResponse, XmDO_NOTHING);  ac++;
  124.   XtSetArg (al[ac], XmNiconPixmap, 
  125.         XCreateBitmapFromData(XtDisplay(topLevel), 
  126.                   RootWindowOfScreen(XtScreen(topLevel)), 
  127.                   Icon_bits, 
  128.                   Icon_width,
  129.                   Icon_height));  ac++;
  130.   XtSetValues (topLevel, al, ac);
  131.  
  132.  
  133.   XtRealizeWidget(topLevel);
  134.   XtAppMainLoop (app_context);
  135.  
  136. }
  137.  
  138.  
  139.  
  140.  
  141.