[Motif] Popup Menu

Popup Menu [Motif] - Divers - Programmation

Marsh Posté le 08-10-2003 à 17:35:26    

Hello  
j'ai un logiciel qui date un peu, les ihm sont en motif / x11, il me faut rajouter un popup menu (sur le clic droit donc). Mais voila je galère un peu :D j'ai trouvé l'exemple ci-aprés qui fonctionne mais je me demande s'il faut absolument une drawind area, moi je voudrai qu'un clic n'importe ou dans mon appli affiche le popup  :heink:  

Code :
  1. #include <Xm/RowColumn.h>
  2. #include <Xm/MainW.h>
  3. #include <Xm/DrawingA.h>
  4. #include <stdlib.h>
  5. main(argc, argv)
  6.      int argc;
  7.      char *argv[];
  8. {
  9.   XmString aide, xterm, calculatrice;
  10.   Widget toplevel, main_w, drawing_a, popup_menu;
  11.   void popup_cb(), input();
  12.   XtAppContext app;
  13.   XtSetLanguageProc (NULL, NULL, NULL);
  14.   toplevel = XtVaAppInitialize (&app, "Popup", NULL, 0, &argc, argv, NULL, NULL);
  15.   /* Create a MainWindow widget */
  16.   main_w = XtVaCreateManagedWidget ("main_w", xmMainWindowWidgetClass, toplevel,
  17.        XmNscrollingPolicy, XmAUTOMATIC, NULL);
  18.   /* Create a DrawingArea -- no actual drawing will be done. */
  19.   drawing_a = XtVaCreateManagedWidget ("drawing_a",
  20.           xmDrawingAreaWidgetClass, main_w,
  21.           XmNwidth,  500,
  22.           XmNheight, 500,
  23.           NULL);
  24.  
  25.   aide = XmStringCreateLocalized ("Aide" );
  26.   xterm = XmStringCreateLocalized ("Xterm" );
  27.   calculatrice = XmStringCreateLocalized ("Calculatrice" );
  28.   popup_menu = XmVaCreateSimplePopupMenu (drawing_a, "popup", popup_cb,
  29.       XmVaPUSHBUTTON, aide, 'a', NULL, NULL,
  30.       XmVaPUSHBUTTON, xterm, 'x', NULL, NULL,
  31.       XmVaPUSHBUTTON, calculatrice, 'c', NULL, NULL, NULL);
  32.   XmStringFree (aide); 
  33.   XmStringFree (xterm);
  34.   XmStringFree (calculatrice);
  35.   /* after popup menu is created, add callback for all input events */
  36.   XtAddCallback (drawing_a, XmNinputCallback, input, popup_menu);
  37.   XtRealizeWidget (toplevel);
  38.   XtAppMainLoop (app);
  39. }
  40. /* input() -- called in responses to events;
  41. * button-3 pops up menu.
  42. */
  43. void input(widget, client_data, call_data)
  44.      Widget widget;
  45.      XtPointer client_data;
  46.      XtPointer call_data;
  47. {
  48.   Widget popup = (Widget) client_data;
  49. /*   XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct *) call_data; */
  50.   XmCallbackStruct *cbs = (XmCallbackStruct *) call_data;
  51.   if (cbs->event->xany.type != ButtonPress || cbs->event->xbutton.button != 3) return;
  52.   /* Position the menu where the event occurred */
  53.   XmMenuPosition (popup, (XButtonPressedEvent *) (cbs->event));
  54.   XtManageChild (popup);
  55. }
  56. /* popup_cb() -- invoked when the user selects an item in the popup menu */
  57. void popup_cb(menu_item, client_data, call_data)
  58.      Widget menu_item;
  59.      XtPointer client_data;
  60.      XtPointer call_data;
  61. {
  62.   int item_no = (int) client_data;
  63.   if(item_no == 0) /* Aide was selected -- display html help*/
  64.     system("galeon ../proc/aide/Aide_sosie.html" );
  65.   if(item_no == 1) /* Xterm was selected -- display an xterm*/
  66.     system("xterm" );
  67.   if(item_no == 2) /* Calculatrice was selected -- display the gcalc utility*/
  68.     system("gcalc" );
  69. }

Reply

Marsh Posté le 08-10-2003 à 17:35:26   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed