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

  1. /*
  2.  * Copyright 1989, 1992 O'Reilly and Associates, Inc.
  3.  * See ../Copyright for complete rights and liability information.
  4.  */
  5.  
  6.  
  7. /* 
  8.  *  xmenu6.c - alternative pulldown example
  9.  */
  10.  
  11. /*
  12.  *  So that we can use fprintf:
  13.  */
  14. #include <stdio.h>
  15.  
  16. /* 
  17.  * Standard Toolkit include files:
  18.  */
  19. #include <X11/Intrinsic.h>
  20. #include <X11/StringDefs.h>
  21.  
  22. #include <X11/Shell.h>
  23.  
  24. /*
  25.  * Public include files for widgets used in this file.
  26.  */
  27. #include <X11/Xaw/Command.h>
  28. #include <X11/Xaw/Box.h>
  29. #include <X11/Xaw/Label.h>
  30.  
  31. Widget pshell, pressme;
  32.  
  33. /*ARGSUSED*/
  34. void PlaceMenu(w, client_data, call_data)
  35. Widget w;
  36. XtPointer client_data;
  37. XtPointer call_data;
  38. {
  39.     Position x, y;
  40.  
  41.     /*
  42.      * translate coordinates in application top-level window
  43.      * into coordinates from root window origin.
  44.      */
  45.     XtTranslateCoords(pressme,                /* Widget */
  46.         (Position) 0,        /* x */
  47.         (Position) 0,       /* y */
  48.         &x, &y);          /* coords on root window */
  49.  
  50.     /* move popup shell one pixel above and left of this position 
  51.      * (it's not visible yet) */
  52.     XtVaSetValues(pshell, 
  53.         XtNx, x - 1,
  54.         XtNy, y  + 1,
  55.         NULL);
  56. }
  57.  
  58. /*
  59.  * quit button callback function
  60.  */
  61. /*ARGSUSED*/
  62. void Quit(w, client_data, call_data)
  63. Widget w;
  64. XtPointer client_data, call_data;
  65.     exit(0); 
  66. }
  67.  
  68. /*
  69.  * menu pane button callback function
  70.  */
  71. /*ARGSUSED*/
  72. void PaneChosen(w, client_data, call_data)
  73. Widget w;
  74. XtPointer client_data;
  75. XtPointer call_data;
  76.     int pane_number = (int) client_data;
  77.     printf("Pane %d chosen.\n", pane_number);
  78.     XtPopdown(pshell);
  79. }
  80.  
  81. /*ARGSUSED*/
  82. void Resensitize(w, client_data, call_data)
  83. Widget w;
  84. XtPointer client_data;
  85. XtPointer call_data;
  86.     XtSetSensitive(pressme);
  87. }
  88.  
  89. /*ARGSUSED*/
  90. void OurCallbackExclusive(w, client_data, call_data)
  91. Widget w;
  92. XtPointer client_data;
  93. XtPointer call_data;
  94.     XtPopup(pshell, XtGrabExclusive, True);
  95. }
  96.  
  97. main(argc, argv)
  98. int argc;
  99. char **argv;
  100. {
  101.     XtAppContext app_context;
  102.     Widget topLevel, box, quit, menubox, menulabel, menupane[10];
  103.     int i;
  104.     String buf[50];
  105.  
  106.     topLevel = XtVaAppInitialize(
  107.         &app_context,       /* Application context */
  108.         "XMenu6",           /* application class name */
  109.         NULL, 0,            /* command line option list */
  110.         &argc, argv,        /* command line args */
  111.         NULL,               /* for missing app-defaults file */
  112.         NULL);              /* terminate varargs list */
  113.  
  114.     box = XtCreateManagedWidget(
  115.         "box",      /* widget name */
  116.         boxWidgetClass, /* widget class */
  117.         topLevel,       /* parent widget*/
  118.         NULL,       /* argument list*/
  119.         0           /* arglist size */
  120.         );
  121.  
  122.     quit = XtCreateManagedWidget(
  123.         "quit",         /* widget name */
  124.         commandWidgetClass,     /* widget class */
  125.         box,            /* parent widget*/
  126.         NULL,           /* argument list*/
  127.         0               /* arglist size */
  128.         );
  129.  
  130.     pressme = XtCreateManagedWidget(
  131.         "pressme",          /* widget name   */
  132.         commandWidgetClass,     /* widget class */
  133.         box,            /* parent widget*/
  134.         NULL,           /* argument list*/
  135.         0               /* arglist size */
  136.         );
  137.  
  138.     pshell = XtCreatePopupShell(
  139.         "pshell",        /* widget name */
  140.         transientShellWidgetClass, /* widget class */
  141.         pressme,        /* parent widget */
  142.         NULL,            /* argument list */
  143.         0            /* arglist size */
  144.         );
  145.  
  146.     menubox = XtCreateManagedWidget(
  147.         "menubox",              /* widget name   */
  148.         boxWidgetClass,         /* widget class */
  149.         pshell,                 /* parent widget*/
  150.         NULL,                   /* argument list*/
  151.         0                   /* arglist size */
  152.         );
  153.     
  154.     menulabel = XtCreateManagedWidget(
  155.         "menulabel",            /* widget name   */
  156.         labelWidgetClass,       /* widget class */
  157.         menubox,                /* parent widget*/
  158.         NULL,                   /* argument list*/
  159.         0                   /* arglist size */
  160.         );
  161.  
  162.     for (i = 0; i < 10; i++) {
  163.       sprintf(buf, "menupane%d", i);
  164.       menupane[i] = XtCreateManagedWidget(buf,   /* widget name   */
  165.                     commandWidgetClass, menubox, NULL, 0);
  166.  
  167.       XtAddCallback(menupane[i], XtNcallback, PaneChosen, i);
  168.     }
  169.  
  170.     XtAddCallback(quit, XtNcallback, Quit, NULL);
  171.  
  172.     XtAddCallback(pressme, XtNcallback, OurCallbackExclusive, pshell);
  173.     XtAddCallback(pshell, XtNpopupCallback, PlaceMenu, topLevel);
  174.  
  175.     XtAddCallback(pshell, XtNpopdownCallback, Resensitize, pressme);
  176.  
  177.     XtRealizeWidget(topLevel);
  178.  
  179.     XtAppMainLoop(app_context);
  180. }
  181.