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 / xpopup.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  120 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.  *  xpopup.c - basic Motif popup menu
  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 <Xm/Xm.h>
  20.  
  21. /*
  22.  * Public include files for widgets used in this file.
  23.  */
  24. #include <Xm/RowColumn.h>
  25. #include <Xm/PushB.h>
  26. #include <Xm/Label.h>
  27.  
  28.  
  29. /*
  30.  * quit button callback function
  31.  */
  32. /*ARGSUSED*/
  33. void Quit(w, client_data, call_data)
  34. Widget w;
  35. XtPointer client_data, call_data;
  36.     exit(0); 
  37. }
  38.  
  39. /*
  40.  * menu pane button callback function
  41.  */
  42. /*ARGSUSED*/
  43. void PaneChosen(w, client_data, call_data)
  44. Widget w;
  45. XtPointer client_data;   /* cast to pane_number */
  46. XtPointer call_data;
  47.     int pane_number = (int) client_data;
  48.     printf("Pane %d chosen.\n", pane_number);
  49. }
  50.  
  51. static void  
  52. PostMenu (w, client_data, event)
  53. Widget         w;
  54. XtPointer      client_data;
  55. XEvent  *event;
  56. {
  57.     Widget popup = (Widget) client_data;
  58.  
  59.     XmMenuPosition(popup, event);
  60.     XtManageChild (popup);
  61. }
  62.  
  63. main(argc, argv)
  64. int argc;
  65. char **argv;
  66. {
  67.     XtAppContext app_context;
  68.     Widget topLevel, box, quit, label, menu, menupane[10];
  69.     int i;
  70.     String buf[50];
  71.  
  72.     XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
  73.  
  74.     topLevel = XtVaAppInitialize(
  75.         &app_context,       /* Application context */
  76.         "XPopup",           /* application class name */
  77.         NULL, 0,            /* command line option list */
  78.         &argc, argv,        /* command line args */
  79.         NULL,               /* for missing app-defaults file */
  80.         NULL);              /* terminate varargs list */
  81.  
  82.     box = XtVaCreateManagedWidget(
  83.     "box",          /* widget name */
  84.         xmRowColumnWidgetClass, /* widget class */
  85.         topLevel,           /* parent widget*/
  86.         NULL);           /* terminate varargs list*/
  87.  
  88.     label = XtVaCreateManagedWidget(
  89.         "label",            /* widget name */
  90.         xmLabelWidgetClass,       /* widget class */
  91.         box,            /* parent widget*/
  92.         NULL);           /* terminate varargs list*/
  93.  
  94.     quit = XtVaCreateManagedWidget(
  95.         "quit",         /* widget name */
  96.         xmPushButtonWidgetClass,/* widget class */
  97.         box,            /* parent widget*/
  98.         NULL);           /* argument list*/
  99.  
  100.     XtAddCallback(quit, XmNactivateCallback, Quit, NULL);
  101.  
  102.     menu = XmCreatePopupMenu(label, "menu", NULL, 0);
  103.  
  104.     XtAddEventHandler(label, ButtonPressMask, False, PostMenu, menu);
  105.  
  106.     for (i = 0; i < 10; i++) {
  107.       sprintf(buf, "entry%d", i);
  108.       menupane[i] = XtVaCreateManagedWidget(buf,   /* widget name   */
  109.             xmPushButtonWidgetClass, menu, NULL);
  110.  
  111.       XtAddCallback(menupane[i], XmNactivateCallback, PaneChosen, i);
  112.     }
  113.  
  114.     XtRealizeWidget(topLevel);
  115.  
  116.     XtAppMainLoop(app_context);
  117. }
  118.