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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
/*
* HISTORY
*/
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$XConsortium: Menu5.c /main/10 1995/07/13 18:45:38 drk $"
#endif
#endif
/*
* (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
#include <testlib.h>
#include <X11/Xlib.h>
#include "armPixft.h"
#include <X11/cursorfont.h>
#include <X11/StringDefs.h>
#include <X11/Vendor.h>
#include <Xm/XmP.h>
#include <Xm/RowColumnP.h>
#include "disarmPixft.h"
#include "arrowPixft.h"
/*************Some Globals***********************/
Widget mainw, menubar, separator;
Widget rc2;
Widget pdbtn1, pdbtn2, pdbtn3;
Widget toggle1, toggle2;
Widget option1, option2, option3;
Widget option1n, option2n, option1h, option2h, option3h, option1o, option2o;
Widget submenu1, submenu2, submenu3;
Widget title, separator2, popup;
Cursor sailboat, heart, man, pirate, shuttle, arrow;
Boolean CallbacksEnabled = False;
int WhichButton = 3;
int WAWhichButton = 1;
#ifdef notdef
Pixmap arm = None;
Pixmap disarm = None;
Pixmap arrowPix = None;
#endif
static void CreatePopup();
static XtTranslations translation1;
void PrintMessage(Widget widget, XtPointer client_data, XtPointer call_data)
{
switch ((int)((XmAnyCallbackStruct *)call_data)->reason) {
case XmCR_VALUE_CHANGED:
printf ("Value changed callback for toggle");
break;
case XmCR_ARM:
printf ("Arm callback for toggle");
break;
case XmCR_DISARM:
printf ("Disarm callback for toggle");
break;
default:
printf ("Some other callback received for toggle");
}
printf (" %d\n", (int)client_data);
}
void _XmRegisterHelpEvent(String event)
{
static String action1 = ": Help()";
static String action2 = ": help()";
String bufr;
if ((event == NULL) || (event[0] == '\0'))
{
printf ("_XmRegisterHelpEvent(): NULL event string specified\n");
return;
}
bufr = XtMalloc(strlen(event) + strlen(action1) + 1);
strcpy(bufr, event);
strcat(bufr, action1);
translation1 = XtParseTranslationTable(bufr);
XtFree(bufr);
}
void _XmBindHelpAction(Widget widget, void (*func)(), XtPointer client_data,
Boolean recursive)
{
int i;
if (widget == NULL || (!XtIsWidget(widget) && !XmIsGadget(widget)))
return;
if (XmIsGadget(widget))
{
XtAddCallback(widget, XmNhelpCallback, func, client_data);
return;
}
if (!XtIsShell(widget))
{
XtOverrideTranslations(widget, translation1);
XtAddCallback(widget, XmNhelpCallback, func, client_data);
}
if (recursive)
{
/* Process normal descendants */
if (XtIsComposite(widget))
{
XmManagerWidget mw = (XmManagerWidget)widget;
for (i = 0; i < mw->composite.num_children; i++)
{
_XmBindHelpAction(mw->composite.children[i], func, client_data,
recursive);
}
}
/* Handle popup descendants */
for (i = 0; i < widget->core.num_popups; i++)
{
_XmBindHelpAction(widget->core.popup_list[i], func, client_data,
recursive);
}
}
}
void PrintName(Widget w,
XtPointer d1,
XtPointer d2)
{
printf ("Widget %s was activated\n", XrmQuarkToString(w->core.xrm_name));
}
void PrintName_2(Widget rc, XtPointer client_data,
XtPointer rc_data)
{
XmRowColumnCallbackStruct *rc_struct;
rc_struct = (XmRowColumnCallbackStruct *) rc_data;
printf ("Widget %s was activated\n",
XrmQuarkToString(rc_struct->widget->core.xrm_name));
}
static XtCallbackRec PrintName_CB[] = {
{PrintName_2, NULL},
{NULL, NULL}
};
void PrintNameAndChangeCursor(Widget rc, XtPointer client_data,
XtPointer rc_data)
{
XmRowColumnCallbackStruct *rc_struct = (XmRowColumnCallbackStruct *)rc_data;
if (rc_struct->data == NULL)
{
printf ("Widget %s was activated\n",
XrmQuarkToString(rc_struct->widget->core.xrm_name));
}
else
{
Cursor cursor = (Cursor)rc_struct->data;
XmSetMenuCursor(XtDisplay(rc), cursor);
if (XmGetMenuCursor(XtDisplay(rc)) != cursor)
printf("Error: problem occurred while changing menu cursor\n");
}
}
static XtCallbackRec PrintNameAndChangeCursor_CB[] = {
{PrintNameAndChangeCursor, NULL},
{NULL, NULL}
};
Help(Widget w)
{
printf ("Help requested for widget %s\n",
XrmQuarkToString(w->core.xrm_name));
}
void PostIt(Widget w, XtPointer p, XEvent *event, Boolean *c)
{
Arg args[5];
Boolean popupEnabled;
Widget popup = (Widget) p;
if (popup == NULL)
return;
if ((event->type == ButtonPress) && (event->xbutton.button != WhichButton))
return;
XtSetArg(args[0], XmNpopupEnabled, &popupEnabled);
XtGetValues(popup, args, 1);
if (popupEnabled)
{
XmMenuPosition(popup, (XButtonPressedEvent *) event);
XtManageChild(popup);
}
}
/*************End of CALLBACK PROCEDURES****************/
int main(unsigned int argc, char **argv)
{
Arg args[15];
int n;
XEvent event;
CommonTestInit(argc, argv);
/****************************************************************/
/* Create the of the top-level frame and row-column manager */
/****************************************************************/
XtSetArg(args[0], XmNradioAlwaysOne, True);
rc2 = XmCreateRadioBox(Shell1, "rc2", args, 1);
XtManageChild(rc2);
/****************************************************************/
/* Create the widget children of the second row-column manager */
/****************************************************************/
toggle1 = XmCreateToggleButtonGadget(rc2, "toggle1", NULL, 0);
XtManageChild(toggle1);
XtAddCallback(toggle1, XmNvalueChangedCallback, PrintMessage, (XtPointer) 1);
XtAddCallback(toggle1, XmNarmCallback, PrintMessage, (XtPointer) 1);
XtAddCallback(toggle1, XmNdisarmCallback, PrintMessage, (XtPointer) 1);
toggle2 = XmCreateToggleButtonGadget(rc2, "toggle2", NULL, 0);
XtManageChild(toggle2);
XtAddCallback(toggle2, XmNvalueChangedCallback, PrintMessage, (XtPointer) 2);
XtAddCallback(toggle2, XmNarmCallback, PrintMessage, (XtPointer) 2);
XtAddCallback(toggle2, XmNdisarmCallback, PrintMessage, (XtPointer) 2);
/**************************/
/* Create the popup menu */
/**************************/
CreatePopup();
sailboat = XCreateFontCursor (display, XC_sailboat);
heart = XCreateFontCursor (display, XC_heart);
man = XCreateFontCursor (display, XC_man);
pirate = XCreateFontCursor (display, XC_pirate);
shuttle = XCreateFontCursor (display, XC_shuttle);
arrow = XCreateFontCursor (display, XC_arrow);
XmSetMenuCursor(display, man);
/****************************************************************/
/* Realize the widget hierarchy, and enter mainloop processing */
/****************************************************************/
XtRealizeWidget (Shell1);
/* _XmRegisterHelpEvent("<Key>F8");
_XmBindHelpAction(Shell1, Help, NULL, True); */
CommonPause();
#ifdef WORKAROUND
XtDestroyWidget(submenu3);
XtDestroyWidget(submenu1);
XtDestroyWidget(submenu2);
XtDestroyWidget(popup);
#endif
XtDestroyWidget(rc2);
CommonPause();
XtAppMainLoop(app_context);
}
static void CreatePopup()
{
int n;
Arg args[10];
n = 0;
XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
XtSetArg(args[n], XmNwhichButton, 3); n++;
popup = XmCreatePopupMenu(rc2, "popup", args, n);
XtAddEventHandler(rc2, ButtonPressMask, False, PostIt, (XtPointer) popup);
title = XmCreateLabelGadget(popup, "Title", NULL, 0);
separator2 =XmCreateSeparatorGadget(popup, "separator2", NULL, 0);
option1 = XmCreatePushButtonGadget(popup, "option1", args, 0);
XtAddCallback(option1, XmNactivateCallback, PrintName, NULL);
option2 = XmCreatePushButtonGadget(popup, "option2", args, 0);
XtAddCallback(option2, XmNactivateCallback, PrintName, NULL);
option3 = XmCreatePushButtonGadget(popup, "option3", args, 0);
XtAddCallback(option3, XmNactivateCallback, PrintName, NULL);
XtManageChild(title);
XtManageChild(separator2);
XtManageChild(option1);
XtManageChild(option2);
XtManageChild(option3);
submenu2 = (Widget)XmCreatePulldownMenu(popup, "submenu2", NULL, 0);
option1h = XmCreatePushButtonGadget(submenu2, "option1h", NULL, 0);
XtAddCallback(option1h, XmNactivateCallback, PrintName, NULL);
option2h = XmCreatePushButtonGadget(submenu2, "option2h", NULL, 0);
XtAddCallback(option2h, XmNactivateCallback, PrintName, NULL);
option3h = XmCreatePushButtonGadget(submenu2, "option3h", NULL, 0);
XtAddCallback(option3h, XmNactivateCallback, PrintName, NULL);
XtManageChild(option1h);
XtManageChild(option2h);
XtManageChild(option3h);
submenu1 = (Widget)XmCreatePulldownMenu(submenu2, "submenu1", NULL, 0);
option1n =XmCreatePushButtonGadget(submenu1, "option1n", NULL, 0);
XtAddCallback(option1n, XmNactivateCallback, PrintName, NULL);
option2n =XmCreatePushButtonGadget(submenu1, "option2n", NULL, 0);
XtAddCallback(option2n, XmNactivateCallback, PrintName, NULL);
XtManageChild(option1n);
XtManageChild(option2n);
submenu3 = XmCreatePulldownMenu(submenu1, "submenu3", NULL, 0);
option1o =XmCreatePushButtonGadget(submenu3, "option1o", NULL, 0);
XtAddCallback(option1o, XmNactivateCallback, PrintName, NULL);
option2o =XmCreatePushButtonGadget(submenu3, "option2o", NULL, 0);
XtAddCallback(option2o, XmNactivateCallback, PrintName, NULL);
XtManageChild(option1o);
XtManageChild(option2o);
n = 0;
XtSetArg(args[n], XmNsubMenuId, submenu3); n++;
pdbtn1 = XmCreateCascadeButtonGadget(submenu1, "pdbtn1", args, n);
XtManageChild(pdbtn1);
n = 0;
XtSetArg(args[n], XmNsubMenuId, submenu1); n++;
pdbtn2 = XmCreateCascadeButton(submenu2, "pdbtn2", args, n);
XtManageChild(pdbtn2);
n = 0;
XtSetArg(args[n], XmNsubMenuId, submenu2); n++;
pdbtn3 = XmCreateCascadeButton(popup, "pdbtn3", args, n);
XtManageChild(pdbtn3);
}
|