1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/***************************************************************************/
/* This code is part of X-toolkit widget library called Nws */
/* Copyright (c) 1997,1998,1999 Ondrejicka Stefan */
/* (ondrej@idata.sk) */
/* Distributed under GPL 2 or later */
/***************************************************************************/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "MwMenuButtonP.h"
#include "MwNws.h"
static XtResource resources [] = {
{
XtNmenu_name ,
XtCMenu_name ,
XtRString ,
sizeof(String) ,
XtOffsetOf(MwMenuButtonRec,mwMenuButton.menu_name) ,
XtRImmediate ,
(XtPointer) "menu" ,
},
};
static void MwPopupMenu(Widget, XEvent *, String *, Cardinal *);
static XtActionsRec action [] = {
{"popup_menu",MwPopupMenu},
};
static char trans_tab [] =
"<Btn1Down>: hide_help() activate() popup_menu() \n\
<Enter>: enter_leave() highlight() show_help() \n\
<Leave>: enter_leave() unhighlight() hide_help() \n\
~Shift<Key>Tab: traverseForward()\n\
Shift<Key>Tab: traverseBackward()\n\
<Key>Return: KBactivate()\n\
<Key>space: KBactivate()\n\
<FocusIn>: focusIn()\n\
<FocusOut>: focusOut()\n\
<BtnDown>: hide_help() \n\
<KeyDown>: hide_help()";
static void ClassInitialize(void);
MwMenuButtonClassRec mwMenuButtonClassRec = {
/* core */
{
/* superclass */ (WidgetClass) &mwButtonClassRec,
/* class_name */ "MwMenuButton",
/* widget_size */ sizeof(MwMenuButtonRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ NULL,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ action,
/* num_actions */ XtNumber(action),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ NULL,
/* resize */ XtInheritResize,
/* expose */ XtInheritExpose,
/* set_values */ NULL,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ XtInheritAcceptFocus,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ trans_tab,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
},
/* base */
{
/* get_internal_dimension */ XtInheritGetInternalDimension,
/* set_internal_dimension */ XtInheritSetInternalDimension,
/* highlight */ XtInheritHighlight,
/* unhighlight */ XtInheritUnhighlight ,
/* highlightBorder */ XtInheritHighlightBorder,
/* unhighlightBorder */ XtInheritUnhighlightBorder,
},
/* sButton */
{
/* empty */ 0
},
/* button */
{
/* empty */ 0
},
/* mwMenuButton */
{
/* empty */ 0
},
};
WidgetClass mwMenuButtonWidgetClass = (WidgetClass) & mwMenuButtonClassRec;
static void ClassInitialize(void)
{
_InitializeWidgetSet();
}
static void MwPopupMenu(Widget w , XEvent *event ,
String *params , Cardinal *num_params)
{
MwMenuButtonWidget cw = (MwMenuButtonWidget) w;
Widget menu = NULL;
Widget parent = w;
int x, y;
Window child;
Display *dpy = XtDisplay(w);
Dimension width , height ,
dwidth = DisplayWidth(dpy,DefaultScreen(dpy)) ,
dheight = DisplayHeight(dpy,DefaultScreen(dpy)) ;
while (parent != NULL && menu == NULL)
{
if ((menu = XtNameToWidget(parent , cw->mwMenuButton.menu_name)) == NULL)
parent = XtParent(parent);
}
if (menu == NULL) return;
if (!XtIsRealized(menu)) XtRealizeWidget(menu);
XtVaGetValues(menu , XtNwidth , &width , XtNheight , &height , NULL);
XTranslateCoordinates(XtDisplay(cw),
XtWindow(cw), DefaultRootWindow(XtDisplay(cw)),
0, cw->core.height, &x, &y, &child);
if ( (x + width) > dwidth ) x = dwidth - width;
if ( (y + height ) > dheight ) y = y - cw->core.height - height;
if ( y < 0 ) y = 0;
XtVaSetValues(menu,XtNx,x,XtNy,y,NULL);
XtPopupSpringLoaded(menu);
}
|