zerod atchoum ! | 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 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
Code :
- #include <Xm/RowColumn.h>
- #include <Xm/MainW.h>
- #include <Xm/DrawingA.h>
- #include <stdlib.h>
- main(argc, argv)
- int argc;
- char *argv[];
- {
- XmString aide, xterm, calculatrice;
- Widget toplevel, main_w, drawing_a, popup_menu;
- void popup_cb(), input();
- XtAppContext app;
- XtSetLanguageProc (NULL, NULL, NULL);
- toplevel = XtVaAppInitialize (&app, "Popup", NULL, 0, &argc, argv, NULL, NULL);
- /* Create a MainWindow widget */
- main_w = XtVaCreateManagedWidget ("main_w", xmMainWindowWidgetClass, toplevel,
- XmNscrollingPolicy, XmAUTOMATIC, NULL);
- /* Create a DrawingArea -- no actual drawing will be done. */
- drawing_a = XtVaCreateManagedWidget ("drawing_a",
- xmDrawingAreaWidgetClass, main_w,
- XmNwidth, 500,
- XmNheight, 500,
- NULL);
-
- aide = XmStringCreateLocalized ("Aide" );
- xterm = XmStringCreateLocalized ("Xterm" );
- calculatrice = XmStringCreateLocalized ("Calculatrice" );
- popup_menu = XmVaCreateSimplePopupMenu (drawing_a, "popup", popup_cb,
- XmVaPUSHBUTTON, aide, 'a', NULL, NULL,
- XmVaPUSHBUTTON, xterm, 'x', NULL, NULL,
- XmVaPUSHBUTTON, calculatrice, 'c', NULL, NULL, NULL);
- XmStringFree (aide);
- XmStringFree (xterm);
- XmStringFree (calculatrice);
- /* after popup menu is created, add callback for all input events */
- XtAddCallback (drawing_a, XmNinputCallback, input, popup_menu);
- XtRealizeWidget (toplevel);
- XtAppMainLoop (app);
- }
- /* input() -- called in responses to events;
- * button-3 pops up menu.
- */
- void input(widget, client_data, call_data)
- Widget widget;
- XtPointer client_data;
- XtPointer call_data;
- {
- Widget popup = (Widget) client_data;
- /* XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct *) call_data; */
- XmCallbackStruct *cbs = (XmCallbackStruct *) call_data;
- if (cbs->event->xany.type != ButtonPress || cbs->event->xbutton.button != 3) return;
- /* Position the menu where the event occurred */
- XmMenuPosition (popup, (XButtonPressedEvent *) (cbs->event));
- XtManageChild (popup);
- }
- /* popup_cb() -- invoked when the user selects an item in the popup menu */
- void popup_cb(menu_item, client_data, call_data)
- Widget menu_item;
- XtPointer client_data;
- XtPointer call_data;
- {
- int item_no = (int) client_data;
- if(item_no == 0) /* Aide was selected -- display html help*/
- system("galeon ../proc/aide/Aide_sosie.html" );
- if(item_no == 1) /* Xterm was selected -- display an xterm*/
- system("xterm" );
- if(item_no == 2) /* Calculatrice was selected -- display the gcalc utility*/
- system("gcalc" );
- }
|
|