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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
|
/*************************************<+>*************************************
*****************************************************************************
**
** File: MenuMgr.c
**
** Project: X Widgets
**
** Description: Menu Manager Meta Class Widget
**
*****************************************************************************
**
** Copyright (c) 1988 by Hewlett-Packard Company
** Copyright (c) 1988 by the Massachusetts Institute of Technology
**
** Permission to use, copy, modify, and distribute this software
** and its documentation for any purpose and without fee is hereby
** granted, provided that the above copyright notice appear in all
** copies and that both that copyright notice and this permission
** notice appear in supporting documentation, and that the names of
** Hewlett-Packard or M.I.T. not be used in advertising or publicity
** pertaining to distribution of the software without specific, written
** prior permission.
**
*****************************************************************************
*************************************<+>*************************************/
#include <X11/IntrinsicP.h>
#include <X11/Xutil.h>
#include <X11/StringDefs.h>
#include <X11/Xatom.h>
#include <Xw/Xw.h>
#include <Xw/XwP.h>
static void Initialize();
static void Destroy();
static Boolean SetValues();
static void ClassInitialize();
/****************************************************************
*
* MenuPane Resources
*
****************************************************************/
static XtResource resources[] = {
{XtNassociateChildren, XtCAssociateChildren, XtRBoolean, sizeof(Boolean),
XtOffset(XwMenuMgrWidget, menu_mgr.associateChildren), XtRString,
"TRUE"},
{XtNmenuPost, XtCMenuPost, XtRString, sizeof(String),
XtOffset(XwMenuMgrWidget, menu_mgr.postString), XtRString,
"<Btn1Down>"},
{XtNmenuSelect, XtCMenuSelect, XtRString, sizeof(String),
XtOffset(XwMenuMgrWidget, menu_mgr.selectString), XtRString,
"<Btn1Up>"},
{XtNmenuUnpost, XtCMenuUnpost, XtRString, sizeof(String),
XtOffset(XwMenuMgrWidget, menu_mgr.unpostString), XtRString,
NULL},
{XtNkbdSelect, XtCKbdSelect, XtRString, sizeof(String),
XtOffset(XwMenuMgrWidget, menu_mgr.kbdSelectString), XtRString,
"<Key>Select"}
};
/****************************************************************
*
* Full class record constant
*
****************************************************************/
XwMenuMgrClassRec XwmenumgrClassRec = {
{
/* core_class fields */
/* superclass */ (WidgetClass) &XwmanagerClassRec,
/* class_name */ "MenuMgr",
/* widget_size */ sizeof(XwMenuMgrRec),
/* class_initialize */ ClassInitialize,
/* class_part_init */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ NULL,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterlv */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ NULL,
/* expose */ NULL,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* PRIVATE cb list */ NULL,
/* tm_table */ NULL,
/* query_geometry */ NULL,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
},{
/* composite_class fields */
/* geometry_manager */ NULL,
/* change_managed */ NULL,
/* insert_child */ XtInheritInsertChild,
/* delete_child */ XtInheritDeleteChild,
NULL,
},{
/* constraint class fields */
/* resources */ NULL,
/* num_resources */ 0,
/* constraint_size */ 0,
/* initialize */ NULL,
/* destroy */ NULL,
/* set_values */ NULL,
NULL,
},{
/* manager_class fields */
/* traversal handler */ NULL,
/* translations */ NULL,
},{
/* menu manager class - none */
/* attachPane */ NULL,
/* detachPane */ NULL,
/* addPane */ NULL,
/* setSelectAccelerar */ NULL,
/* clearSelectAcceler */ NULL,
/* setPostMnemonic */ NULL,
/* clearPostMnemonic */ NULL,
/* addButton */ NULL,
/* processSelect */ NULL,
/* validEvent */ NULL,
/* doICascade */ NULL,
/* setSelectMnemonic */ NULL,
/* clearSelectMnemon */ NULL,
/* setTitleAttributes */ NULL,
/* paneManagedChildren*/ NULL,
/* traverseLeft */ NULL,
/* traverseRight */ NULL,
/* traverseNext */ NULL,
/* traversePrev */ NULL,
/* traverseHome */ NULL,
/* traverseUp */ NULL,
/* traverseDown */ NULL,
/* traverseNextTop */ NULL,
/* btnSensitivityChan */ NULL,
/* paneSensitivityCha */ NULL,
}
};
WidgetClass XwmenumgrWidgetClass = (WidgetClass)&XwmenumgrClassRec;
/*************************************<->*************************************
*
* ClassInitialize(parameters)
*
* Description:
* -----------
* xxxxxxxxxxxxxxxxxxxxxxx
*
*
* Inputs:
* ------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Outputs:
* -------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Procedures Called
* -----------------
*
*************************************<->***********************************/
static void ClassInitialize ()
{
}
/*************************************<->*************************************
*
* Initialize
*
*
* Description:
* -----------
* Initialize the menu_mgr fields within the widget's instance structure.
*
*
* Inputs:
* ------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Outputs:
* -------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Procedures Called
* -----------------
*
*************************************<->***********************************/
static void Initialize (request, new)
XwMenuMgrWidget request, new;
{
KeySym tempKeysym;
/* FOR NOW, MENUS DO NOT UNDERSTAND TRAVERSAL */
/* new->manager.traversal_on = FALSE; */
/*
* Save a copy of the posting event string, and also convert it
* into a form which can be compared against an X button event.
*/
if ((new->menu_mgr.postString) &&
(strlen(new->menu_mgr.postString) > 0))
{
if (_XwMapBtnEvent (new->menu_mgr.postString,
&new->menu_mgr.postEventType,
&new->menu_mgr.postButton,
&new->menu_mgr.postModifiers) == FALSE)
{
/* String was not valid; use the default one */
XtWarning("MenuMgr: Invalid post event; using <Btn1Down>");
new->menu_mgr.postString = (String) strcpy (XtMalloc (XwStrlen
("<Btn1Down>") + 1), "<Btn1Down>");
_XwMapBtnEvent ("<Btn1Down>",
&new->menu_mgr.postEventType,
&new->menu_mgr.postButton,
&new->menu_mgr.postModifiers);
}
else
{
/* String was valid */
new->menu_mgr.postString = (String) strcpy (XtMalloc (XwStrlen
(new->menu_mgr.postString) + 1), new->menu_mgr.postString);
}
}
else
{
new->menu_mgr.postString = NULL;
new->menu_mgr.postModifiers = 0;
new->menu_mgr.postButton = 0;
}
/*
* Save a copy of the selecting event string, and also convert it
* into a form which can be compared against an X button event.
*/
if ((new->menu_mgr.selectString) &&
(strlen(new->menu_mgr.selectString) > 0))
{
if (_XwMapBtnEvent (new->menu_mgr.selectString,
&new->menu_mgr.selectEventType,
&new->menu_mgr.selectButton,
&new->menu_mgr.selectModifiers) == FALSE)
{
/* String was not valid; use the default one */
XtWarning("MenuMgr: Invalid select event; using <Btn1Up>");
new->menu_mgr.selectString = (String) strcpy (XtMalloc (XwStrlen
("<Btn1Up>") + 1), "<Btn1Up>");
_XwMapBtnEvent ("<Btn1Up>",
&new->menu_mgr.selectEventType,
&new->menu_mgr.selectButton,
&new->menu_mgr.selectModifiers);
}
else
{
/* String was valid */
new->menu_mgr.selectString = (String) strcpy (XtMalloc (XwStrlen
(new->menu_mgr.selectString) + 1), new->menu_mgr.selectString);
}
}
else
{
new->menu_mgr.selectString = NULL;
new->menu_mgr.selectModifiers = 0;
new->menu_mgr.selectButton = 0;
}
/*
* Save a copy of the unposting event string, and also convert it
* into a form which can be compared against an X button event.
*/
if ((new->menu_mgr.unpostString) &&
(strlen(new->menu_mgr.unpostString) > 0))
{
if (_XwMapKeyEvent (new->menu_mgr.unpostString,
&new->menu_mgr.unpostEventType,
&tempKeysym,
&new->menu_mgr.unpostModifiers) == FALSE)
{
/* String was not valid; use the default one */
XtWarning("MenuMgr: Invalid unpost event; disabling option");
new->menu_mgr.unpostString = NULL;
}
else
{
/* String was valid */
new->menu_mgr.unpostKey = XKeysymToKeycode(XtDisplay(new),tempKeysym);
new->menu_mgr.unpostString = (String) strcpy (XtMalloc (XwStrlen
(new->menu_mgr.unpostString) + 1), new->menu_mgr.unpostString);
}
}
else
{
new->menu_mgr.unpostString = NULL;
new->menu_mgr.unpostModifiers = 0;
new->menu_mgr.unpostKey = 0;
}
/*
* Save a copy of the kbd select event string, and also convert it
* into a form which can be compared against an X key event.
*/
if ((new->menu_mgr.kbdSelectString) &&
(strlen(new->menu_mgr.kbdSelectString) > 0))
{
if (_XwMapKeyEvent (new->menu_mgr.kbdSelectString,
&new->menu_mgr.kbdSelectEventType,
&tempKeysym,
&new->menu_mgr.kbdSelectModifiers) == FALSE)
{
/* String was not valid; use the default one */
XtWarning("MenuMgr: Invalid keyboard select event; using default");
new->menu_mgr.kbdSelectString = (String) strcpy (XtMalloc (XwStrlen
("<Key>Select") + 1), "<Key>Select");
_XwMapKeyEvent ("<Key>Select",
&new->menu_mgr.kbdSelectEventType,
&new->menu_mgr.kbdSelectKey,
&new->menu_mgr.kbdSelectModifiers);
}
else
{
/* String was valid */
new->menu_mgr.kbdSelectKey =
XKeysymToKeycode(XtDisplay(new),tempKeysym);
new->menu_mgr.kbdSelectString = (String) strcpy (XtMalloc (XwStrlen
(new->menu_mgr.kbdSelectString) + 1),
new->menu_mgr.kbdSelectString);
}
}
else
{
new->menu_mgr.kbdSelectString = NULL;
new->menu_mgr.kbdSelectModifiers = 0;
new->menu_mgr.kbdSelectKey = 0;
}
/* Allocate space for each of the tables used by a menu manager */
new->menu_mgr.menuBtnAccelTable =
(XwKeyAccel *) XtMalloc(100 * sizeof(XwKeyAccel));
new->menu_mgr.numAccels = 0;
new->menu_mgr.sizeAccelTable = 100;
new->menu_mgr.pendingAttachList =
(XwAttachList *) XtMalloc(25 * sizeof(XwAttachList));
new->menu_mgr.numAttachReqs = 0;
new->menu_mgr.sizeAttachList = 25;
/* Set menu flags */
new->menu_mgr.menuActive = FALSE;
} /* Initialize */
/*************************************<->*************************************
*
* SetValues()
*
* Description:
* -----------
*
* This procedure simply checks to see if the post or select specification
* has changed, and allocates space for the new string and frees up the
* old string. It will also map the new specification into a button/
* modifier pair.
*
* NOTE: When a new post or select string is specified, this routine will
* allocate space for the new string, but will NOT free up the old
* string; thus, our subclasses can check to see if these strings
* differ, and can remove any translations. It is then upto the
* subclass to free the old string and to modify any translations or
* button grabs which are associated with the post or select actions.
*
* It is also the responsibility of the subclass to check the state
* of the 'associate children' flag, and to modify any corresponding
* translations or grabs.
*
* Inputs:
* ------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Outputs:
* -------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Procedures Called
* -----------------
*
*************************************<->***********************************/
static Boolean SetValues (current, request, new)
XwMenuMgrWidget current, request, new;
{
KeySym tempKeysym;
/* FOR NOW, MENUS DO NOT UNDERSTAND TRAVERSAL */
/* new->manager.traversal_on = FALSE; */
/* Handle the case of a changed posting string */
if (current->menu_mgr.postString != new->menu_mgr.postString)
{
/* Allocate a new buffer to hold the string */
if ((new->menu_mgr.postString) &&
(strlen(new->menu_mgr.postString) > 0))
{
if (_XwMapBtnEvent (new->menu_mgr.postString,
&new->menu_mgr.postEventType,
&new->menu_mgr.postButton,
&new->menu_mgr.postModifiers) == FALSE)
{
/* Invalid post string; use the previous one */
XtWarning("MenuMgr: Invalid post event; using previous setting");
new->menu_mgr.postString = current->menu_mgr.postString;
new->menu_mgr.postEventType = current->menu_mgr.postEventType;
new->menu_mgr.postButton = current->menu_mgr.postButton;
new->menu_mgr.postModifiers = current->menu_mgr.postModifiers;
}
else
{
/* Valid post string */
new->menu_mgr.postString = (String)
strcpy (XtMalloc (XwStrlen (new->menu_mgr.postString) + 1),
new->menu_mgr.postString);
}
}
else
{
new->menu_mgr.postString = NULL;
new->menu_mgr.postEventType = 0;
new->menu_mgr.postButton = 0;
new->menu_mgr.postModifiers = 0;
}
/*
* Don't free up the buffer holding the old post string.
* This is to be done by our subclass.
*/
}
/* Handle the case of a changed select string */
if (current->menu_mgr.selectString != new->menu_mgr.selectString)
{
/* Allocate a new buffer to hold the string */
if ((new->menu_mgr.selectString) &&
(strlen(new->menu_mgr.selectString) > 0))
{
if (_XwMapBtnEvent (new->menu_mgr.selectString,
&new->menu_mgr.selectEventType,
&new->menu_mgr.selectButton,
&new->menu_mgr.selectModifiers) == FALSE)
{
/* Invalid select string; use the previous one */
XtWarning("MenuMgr: Invalid select event; using previous setting");
new->menu_mgr.selectString = current->menu_mgr.selectString;
new->menu_mgr.selectEventType = current->menu_mgr.selectEventType;
new->menu_mgr.selectButton = current->menu_mgr.selectButton;
new->menu_mgr.selectModifiers = current->menu_mgr.selectModifiers;
}
else
{
/* Valid select string */
new->menu_mgr.selectString = (String)
strcpy (XtMalloc (XwStrlen (new->menu_mgr.selectString) + 1),
new->menu_mgr.selectString);
}
}
else
{
new->menu_mgr.selectString = NULL;
new->menu_mgr.selectEventType = 0;
new->menu_mgr.selectButton = 0;
new->menu_mgr.selectModifiers = 0;
}
/*
* Don't free up the buffer holding the old select string.
* This is to be done by our subclass.
*/
}
/* Handle the case of a changed unposting string */
if (current->menu_mgr.unpostString != new->menu_mgr.unpostString)
{
/* Allocate a new buffer to hold the string */
if ((new->menu_mgr.unpostString) &&
(strlen(new->menu_mgr.unpostString) > 0))
{
if (_XwMapKeyEvent (new->menu_mgr.unpostString,
&new->menu_mgr.unpostEventType,
&tempKeysym,
&new->menu_mgr.unpostModifiers) == FALSE)
{
/* Invalid unpost string; use the previous one */
XtWarning("MenuMgr: Invalid unpost event; using previous setting");
new->menu_mgr.unpostString = current->menu_mgr.unpostString;
new->menu_mgr.unpostEventType = current->menu_mgr.unpostEventType;
new->menu_mgr.unpostKey = current->menu_mgr.unpostKey;
new->menu_mgr.unpostModifiers = current->menu_mgr.unpostModifiers;
}
else
{
/* Valid unpost string */
new->menu_mgr.unpostKey = XKeysymToKeycode(XtDisplay(new),
tempKeysym);
new->menu_mgr.unpostString = (String)
strcpy (XtMalloc (XwStrlen (new->menu_mgr.unpostString) + 1),
new->menu_mgr.unpostString);
}
}
else
{
new->menu_mgr.unpostString = NULL;
new->menu_mgr.unpostEventType = 0;
new->menu_mgr.unpostKey = 0;
new->menu_mgr.unpostModifiers = 0;
}
/*
* Don't free up the buffer holding the old unpost string.
* This is to be done by our subclass.
*/
}
/* Handle the case of a changed kbd select string */
if (current->menu_mgr.kbdSelectString != new->menu_mgr.kbdSelectString)
{
/* Allocate a new buffer to hold the string */
if ((new->menu_mgr.kbdSelectString) &&
(strlen(new->menu_mgr.kbdSelectString) > 0))
{
if (_XwMapKeyEvent (new->menu_mgr.kbdSelectString,
&new->menu_mgr.kbdSelectEventType,
&tempKeysym,
&new->menu_mgr.kbdSelectModifiers) == FALSE)
{
/* Invalid kbd select string; use the previous one */
XtWarning
("MenuMgr: Invalid keyboard select event; using previous setting");
new->menu_mgr.kbdSelectString = current->menu_mgr.kbdSelectString;
new->menu_mgr.kbdSelectEventType =
current->menu_mgr.kbdSelectEventType;
new->menu_mgr.kbdSelectKey = current->menu_mgr.kbdSelectKey;
new->menu_mgr.kbdSelectModifiers =
current->menu_mgr.kbdSelectModifiers;
}
else
{
/* Valid kbd select string */
new->menu_mgr.kbdSelectKey = XKeysymToKeycode(XtDisplay(new),
tempKeysym);
new->menu_mgr.kbdSelectString = (String)
strcpy (XtMalloc (XwStrlen (new->menu_mgr.kbdSelectString) + 1),
new->menu_mgr.kbdSelectString);
}
}
else
{
new->menu_mgr.kbdSelectString = NULL;
new->menu_mgr.kbdSelectEventType = 0;
new->menu_mgr.kbdSelectKey = 0;
new->menu_mgr.kbdSelectModifiers = 0;
}
/*
* Don't free up the buffer holding the old kbd select string.
* This is to be done by our subclass.
*/
}
return (FALSE);
}
/*************************************<->*************************************
*
* Destroy
*
* Description:
* -----------
*
*
* Inputs:
* ------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Outputs:
* -------
* xxxxxxxxxxxx = xxxxxxxxxxxxx
*
* Procedures Called
* -----------------
*
*************************************<->***********************************/
static void Destroy (mw)
XwMenuMgrWidget mw;
{
/* Free up our resources */
if (mw->menu_mgr.postString)
XtFree (mw->menu_mgr.postString);
if (mw->menu_mgr.selectString)
XtFree (mw->menu_mgr.selectString);
if (mw->menu_mgr.unpostString)
XtFree (mw->menu_mgr.unpostString);
if (mw->menu_mgr.kbdSelectString)
XtFree (mw->menu_mgr.kbdSelectString);
XtFree ((char *)(mw->menu_mgr.menuBtnAccelTable));
XtFree ((char *)(mw->menu_mgr.pendingAttachList));
}
|