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 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
|
/* $XConsortium: Toggle.c,v 1.28 94/04/17 20:13:17 kaleb Exp $ */
/* MODIFIED FOR N*XTSTEP LOOK */
/* Modifications Copyright (c) 1996,1997 by Alfredo Kojima */
/*
Copyright (c) 1989, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
*/
/*
* Toggle.c - Toggle button widget
*
* Author: Chris D. Peterson
* MIT X Consortium
* kit@expo.lcs.mit.edu
*
* Date: January 12, 1989
*
*/
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/neXtaw/XawInit.h>
#include <X11/Xmu/Converters.h>
#include <X11/Xmu/Misc.h>
#include <X11/neXtaw/ToggleP.h>
/****************************************************************
*
* Full class record constant
*
****************************************************************/
/* Private Data */
/*
* The order of toggle and notify are important, as the state has
* to be set when we call the notify proc.
*/
static char defaultTranslations[] =
/* "<EnterWindow>: highlight(Always) \n\
<LeaveWindow>: unhighlight() \n\ */
"<Btn1Down>,<Btn1Up>: toggle() notify()";
#define offset(field) XtOffsetOf(ToggleRec, field)
static XtResource resources[] = {
{XtNstate, XtCState, XtRBoolean, sizeof(Boolean),
offset(command.set), XtRString, "off"},
{XtNradioGroup, XtCWidget, XtRWidget, sizeof(Widget),
offset(toggle.widget), XtRWidget, (XtPointer) NULL },
{XtNradioData, XtCRadioData, XtRPointer, sizeof(XtPointer),
offset(toggle.radio_data), XtRPointer, (XtPointer) NULL },
{XtNtoggleStyle, XtCToggleStyle, XtRToggleStyle, sizeof(XtToggleStyle),
offset(toggle.toggle_style), XtRToggleStyle, (XtPointer)XtToggleSimple },
};
#undef offset
static void Toggle(), Initialize(), Notify(), ToggleSet();
static void ToggleDestroy(), ClassInit();
static Boolean SetValues();
static void Redisplay(), Resize();
static void DisplayCheckBox(), DisplayRadioButton();
/* Functions for handling the Radio Group. */
static RadioGroup * GetRadioGroup();
static void CreateRadioGroup(), AddToRadioGroup(), TurnOffRadioSiblings();
static void RemoveFromRadioGroup();
static XtActionsRec actionsList[] =
{
{"toggle", Toggle},
{"notify", Notify},
{"set", ToggleSet},
};
#define CHECKBOX_SPACE 12
#define SuperClass ((CommandWidgetClass)&commandClassRec)
ToggleClassRec toggleClassRec = {
{
(WidgetClass) SuperClass, /* superclass */
"Toggle", /* class_name */
sizeof(ToggleRec), /* size */
ClassInit, /* class_initialize */
NULL, /* class_part_initialize */
FALSE, /* class_inited */
Initialize, /* initialize */
NULL, /* initialize_hook */
XtInheritRealize, /* realize */
actionsList, /* actions */
XtNumber(actionsList), /* num_actions */
resources, /* resources */
XtNumber(resources), /* resource_count */
NULLQUARK, /* xrm_class */
FALSE, /* compress_motion */
TRUE, /* compress_exposure */
TRUE, /* compress_enterleave */
FALSE, /* visible_interest */
NULL, /* destroy */
Resize, /* resize */
Redisplay, /* expose */
SetValues, /* set_values */
NULL, /* set_values_hook */
XtInheritSetValuesAlmost, /* set_values_almost */
NULL, /* get_values_hook */
NULL, /* accept_focus */
XtVersion, /* version */
NULL, /* callback_private */
defaultTranslations, /* tm_table */
XtInheritQueryGeometry, /* query_geometry */
XtInheritDisplayAccelerator, /* display_accelerator */
NULL /* extension */
}, /* CoreClass fields initialization */
{
XtInheritChangeSensitive /* change_sensitive */
}, /* SimpleClass fields initialization */
{
XtInheritXaw3dShadowDraw /* shadowdraw */
}, /* ThreeDClass fields initialization */
{
0 /* field not used */
}, /* LabelClass fields initialization */
{
0 /* field not used */
}, /* CommandClass fields initialization */
{
NULL, /* Set Procedure. */
NULL, /* Unset Procedure. */
NULL /* extension. */
} /* ToggleClass fields initialization */
};
/* for public consumption */
WidgetClass toggleWidgetClass = (WidgetClass) &toggleClassRec;
/****************************************************************
*
* Private Procedures
*
****************************************************************/
#define done(address, type) \
{ toVal->size = sizeof(type); \
toVal->addr = (XPointer) address; \
return; \
}
static XrmQuark XtQToggleSimple, XtQToggleCheck, XtQToggleRadio;
/* ARGSUSED */
static void _CvtStringToToggleStyle(args, num_args, fromVal, toVal)
XrmValuePtr args; /* unused */
Cardinal *num_args; /* unused */
XrmValuePtr fromVal;
XrmValuePtr toVal;
{
static XtToggleStyle toggleStyle;
XrmQuark q;
char lowerName[1000];
XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr);
q = XrmStringToQuark(lowerName);
if (q == XtQToggleSimple) {
toggleStyle = XtToggleSimple;
done(&toggleStyle, XtToggleStyle);
}
if (q == XtQToggleCheck) {
toggleStyle = XtToggleCheck;
done(&toggleStyle, XtToggleStyle);
}
if (q == XtQToggleRadio) {
toggleStyle = XtToggleRadio;
done(&toggleStyle, XtToggleStyle);
}
XtStringConversionWarning(fromVal->addr, "toggleStyle");
toVal->addr = NULL;
toVal->size = 0;
}
#undef done
static void
ClassInit()
{
XtActionList actions;
Cardinal num_actions;
Cardinal i;
ToggleWidgetClass class = (ToggleWidgetClass) toggleWidgetClass;
static XtConvertArgRec parentCvtArgs[] = {
{XtBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.parent),
sizeof(Widget)}
};
XawInitializeWidgetSet();
XtSetTypeConverter(XtRString, XtRWidget, XmuNewCvtStringToWidget,
parentCvtArgs, XtNumber(parentCvtArgs), XtCacheNone,
(XtDestructor)NULL);
XtQToggleSimple = XrmPermStringToQuark("simple");
XtQToggleCheck = XrmPermStringToQuark("check");
XtQToggleRadio = XrmPermStringToQuark("radio");
XtAddConverter( XtRString, XtRToggleStyle, _CvtStringToToggleStyle,
(XtConvertArgList)NULL, 0 );
/*
* Find the set and unset actions in the command widget's action table.
*/
XtGetActionList(commandWidgetClass, &actions, &num_actions);
for (i = 0 ; i < num_actions ; i++) {
if (streq(actions[i].string, "set"))
class->toggle_class.Set = actions[i].proc;
if (streq(actions[i].string, "unset"))
class->toggle_class.Unset = actions[i].proc;
if ( (class->toggle_class.Set != NULL) &&
(class->toggle_class.Unset != NULL) ) {
XtFree((char *) actions);
return;
}
}
/* We should never get here. */
XtError("Aborting, due to errors resolving bindings in the Toggle widget.");
}
/*ARGSUSED*/
static void Initialize(request, new, args, num_args)
Widget request, new;
ArgList args;
Cardinal *num_args;
{
ToggleWidget tw = (ToggleWidget) new;
ToggleWidget tw_req = (ToggleWidget) request;
tw->toggle.radio_group = NULL;
if (tw->toggle.radio_data == NULL)
tw->toggle.radio_data = (XtPointer) new->core.name;
if (tw->toggle.widget != NULL) {
if ( GetRadioGroup(tw->toggle.widget) == NULL)
CreateRadioGroup(new, tw->toggle.widget);
else
AddToRadioGroup( GetRadioGroup(tw->toggle.widget), new);
}
XtAddCallback(new, XtNdestroyCallback, ToggleDestroy, (XtPointer)NULL);
/*
* Command widget assumes that the widget is unset, so we only
* have to handle the case where it needs to be set.
*
* If this widget is in a radio group then it may cause another
* widget to be unset, thus calling the notify proceedure.
*
* I want to set the toggle if the user set the state to "On" in
* the resource group, reguardless of what my ancestors did.
*/
if (tw_req->command.set)
ToggleSet(new, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
if (tw->toggle.toggle_style==XtToggleCheck
|| tw->toggle.toggle_style==XtToggleRadio) {
/* if we'll use an indicator */
tw->threeD.shadow_width = 0;
XtResizeWidget(new, tw->core.width + CHECKBOX_SPACE, tw->core.height,
tw->core.border_width);
}
}
static void
DisplayRadioButton(w, toggled)
Widget w;
Boolean toggled;
{
ToggleWidget tw = (ToggleWidget) w;
Display *dpy=XtDisplay(w);
Window win=XtWindow(w);
GC light2 = tw->threeD.top_shadow_GC;
GC light = tw->threeD.top_half_shadow_GC;
GC dark2 = tw->threeD.bot_shadow_GC;
GC dark = tw->threeD.bot_half_shadow_GC;
Dimension s = tw->threeD.shadow_width;
int x1, y1;
if (!XtIsRealized(w)) return;
x1 = s+1;
y1 = (tw->core.height-15)/2;
if (y1<0)
y1=0;
/*
* These coords are based on trial and error
*/
#define rad 7
XDrawArc(dpy, win, dark, x1, y1, rad*2-1, rad*2-1, 60*64, 150*64);
XDrawArc(dpy, win, dark2, x1, y1, rad*2, rad*2, 55*64, 160*64);
XDrawArc(dpy, win, light, x1, y1, rad*2, rad*2, 35*64, -160*64);
XDrawArc(dpy, win, dark, x1+1, y1+1, rad*2-1, rad*2-1, 60*64, 150*64);
XDrawArc(dpy, win, light2, x1, y1, rad*2-1, rad*2-1, 30*64, -150*64);
if (tw->command.set) {
XFillArc(dpy, win, light, x1+3, y1+3, (rad-2)*2, (rad-2)*2, 0, 360*64);
}
#undef rad
}
static void
DisplayCheckBox(w)
Widget w;
{
ToggleWidget tw = (ToggleWidget) w;
Display *dpy=XtDisplay(w);
Window win=XtWindow(w);
GC light2 = tw->threeD.top_shadow_GC;
GC light = tw->threeD.top_half_shadow_GC;
GC dark2 = tw->threeD.bot_shadow_GC;
GC dark = tw->threeD.bot_half_shadow_GC;
Dimension s = tw->threeD.shadow_width;
int x1, y1, x2, y2;
if (!XtIsRealized(w)) return;
x1 = s+1;
x2 = s+15;
if (x2>tw->core.width) {
x2=tw->core.width-x1;
}
y1 = (tw->core.height-15)/2;
y2 = y1+15;
if (y1<0) {
y1=0;
y2=tw->core.height;
}
XDrawLine(dpy, win, light, x1, y1, x2, y1);
XDrawLine(dpy, win, light, x1, y1, x1, y2);
XDrawLine(dpy, win, dark, x1, y2, x2, y2);
XDrawLine(dpy, win, dark, x2, y1, x2, y2);
XDrawLine(dpy, win, light2, x1+1, y1+1, x2-1, y1+1);
XDrawLine(dpy, win, light2, x1+1, y1+1, x1+1, y2-1);
XDrawLine(dpy, win, dark2, x1+1, y2-1, x2-1, y2-1);
XDrawLine(dpy, win, dark2, x2-1, y1+1, x2-1, y2-1);
if (tw->command.set) {
int y=(y2-y1)/2-s;
#define x (x1+4)
XDrawLine(dpy, win, dark2, x+1, y+3, x+1, y+6);
XDrawLine(dpy, win, light, x, y+3, x, y+8);
XDrawLine(dpy, win, light, x, y+8, x+8, y);
XDrawLine(dpy, win, dark2, x, y+9, x+8, y+1);
XDrawLine(dpy, win, dark, x+1, y+9, x+8, y+2);
#undef x
}
}
static void
Resize(w)
Widget w;
{
ToggleWidget tw = (ToggleWidget) w;
int tmp;
Pixmap kludge;
/* AAAARGHHH!! */
if (tw->toggle.toggle_style==XtToggleCheck
|| tw->toggle.toggle_style==XtToggleRadio) {
tmp = tw->label.lbm_width;
kludge = tw->label.left_bitmap;
tw->label.lbm_width += CHECKBOX_SPACE;
tw->label.left_bitmap = 1;
}
(*SuperClass->core_class.resize) (w);
if (tw->toggle.toggle_style==XtToggleCheck
|| tw->toggle.toggle_style==XtToggleRadio) {
tw->label.lbm_width = tmp;
tw->label.left_bitmap = kludge;
}
}
static void
Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region;
{
ToggleWidget tw = (ToggleWidget) w;
ToggleWidgetClass twclass = (ToggleWidgetClass) XtClass (w);
Dimension s = tw->threeD.shadow_width;
(*SuperClass->core_class.expose) (w, event, region);
if (tw->toggle.toggle_style==XtToggleCheck) {
DisplayCheckBox(w);
} else if (tw->toggle.toggle_style==XtToggleRadio) {
DisplayRadioButton(w);
}
}
/************************************************************
*
* Action Procedures
*
************************************************************/
/* ARGSUSED */
static void
ToggleSet(w,event,params,num_params)
Widget w;
XEvent *event;
String *params; /* unused */
Cardinal *num_params; /* unused */
{
ToggleWidgetClass class = (ToggleWidgetClass) w->core.widget_class;
TurnOffRadioSiblings(w);
class->toggle_class.Set(w, event, NULL, 0);
if (((ToggleWidget)w)->toggle.toggle_style==XtToggleCheck) {
DisplayCheckBox(w);
} else if (((ToggleWidget)w)->toggle.toggle_style==XtToggleRadio) {
DisplayRadioButton(w);
}
}
/* ARGSUSED */
static void
Toggle(w,event,params,num_params)
Widget w;
XEvent *event;
String *params; /* unused */
Cardinal *num_params; /* unused */
{
ToggleWidget tw = (ToggleWidget)w;
ToggleWidgetClass class = (ToggleWidgetClass) w->core.widget_class;
if (tw->command.set) {
class->toggle_class.Unset(w, event, NULL, 0);
if (tw->toggle.toggle_style==XtToggleCheck) {
DisplayCheckBox(w);
} else if (tw->toggle.toggle_style==XtToggleRadio) {
DisplayRadioButton(w);
}
} else {
ToggleSet(w, event, params, num_params);
}
}
/* ARGSUSED */
static void Notify(w,event,params,num_params)
Widget w;
XEvent *event;
String *params; /* unused */
Cardinal *num_params; /* unused */
{
ToggleWidget tw = (ToggleWidget) w;
long antilint = tw->command.set;
XtCallCallbacks( w, XtNcallback, (XtPointer) antilint );
}
/************************************************************
*
* Set specified arguments into widget
*
***********************************************************/
/* ARGSUSED */
static Boolean
SetValues (current, request, new, args, num_args)
Widget current, request, new;
ArgList args;
Cardinal *num_args;
{
ToggleWidget oldtw = (ToggleWidget) current;
ToggleWidget tw = (ToggleWidget) new;
ToggleWidget rtw = (ToggleWidget) request;
if (oldtw->toggle.widget != tw->toggle.widget)
XawToggleChangeRadioGroup(new, tw->toggle.widget);
if (!tw->core.sensitive && oldtw->core.sensitive && rtw->command.set)
tw->command.set = True;
if (oldtw->command.set != tw->command.set) {
tw->command.set = oldtw->command.set;
Toggle(new, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
}
return(FALSE);
}
/* Function Name: ToggleDestroy
* Description: Destroy Callback for toggle widget.
* Arguments: w - the toggle widget that is being destroyed.
* junk, grabage - not used.
* Returns: none.
*/
/* ARGSUSED */
static void
ToggleDestroy(w, junk, garbage)
Widget w;
XtPointer junk, garbage;
{
RemoveFromRadioGroup(w);
}
/************************************************************
*
* Below are all the private procedures that handle
* radio toggle buttons.
*
************************************************************/
/* Function Name: GetRadioGroup
* Description: Gets the radio group associated with a give toggle
* widget.
* Arguments: w - the toggle widget who's radio group we are getting.
* Returns: the radio group associated with this toggle group.
*/
static RadioGroup *
GetRadioGroup(w)
Widget w;
{
ToggleWidget tw = (ToggleWidget) w;
if (tw == NULL) return(NULL);
return( tw->toggle.radio_group );
}
/* Function Name: CreateRadioGroup
* Description: Creates a radio group. give two widgets.
* Arguments: w1, w2 - the toggle widgets to add to the radio group.
* Returns: none.
*
* NOTE: A pointer to the group is added to each widget's radio_group
* field.
*/
static void
CreateRadioGroup(w1, w2)
Widget w1, w2;
{
char error_buf[BUFSIZ];
ToggleWidget tw1 = (ToggleWidget) w1;
ToggleWidget tw2 = (ToggleWidget) w2;
if ( (tw1->toggle.radio_group != NULL) || (tw2->toggle.radio_group != NULL) ) {
(void) sprintf(error_buf, "%s %s", "Toggle Widget Error - Attempting",
"to create a new toggle group, when one already exists.");
XtWarning(error_buf);
}
AddToRadioGroup( (RadioGroup *)NULL, w1 );
AddToRadioGroup( GetRadioGroup(w1), w2 );
}
/* Function Name: AddToRadioGroup
* Description: Adds a toggle to the radio group.
* Arguments: group - any element of the radio group the we are adding to.
* w - the new toggle widget to add to the group.
* Returns: none.
*/
static void
AddToRadioGroup(group, w)
RadioGroup * group;
Widget w;
{
ToggleWidget tw = (ToggleWidget) w;
RadioGroup * local;
local = (RadioGroup *) XtMalloc( sizeof(RadioGroup) );
local->widget = w;
tw->toggle.radio_group = local;
if (group == NULL) { /* Creating new group. */
group = local;
group->next = NULL;
group->prev = NULL;
return;
}
local->prev = group; /* Adding to previous group. */
if ((local->next = group->next) != NULL)
local->next->prev = local;
group->next = local;
}
/* Function Name: TurnOffRadioSiblings
* Description: Deactivates all radio siblings.
* Arguments: widget - a toggle widget.
* Returns: none.
*/
static void
TurnOffRadioSiblings(w)
Widget w;
{
RadioGroup * group;
ToggleWidgetClass class = (ToggleWidgetClass) w->core.widget_class;
if ( (group = GetRadioGroup(w)) == NULL) /* Punt if there is no group */
return;
/* Go to the top of the group. */
for ( ; group->prev != NULL ; group = group->prev );
while ( group != NULL ) {
ToggleWidget local_tog = (ToggleWidget) group->widget;
if ( local_tog->command.set ) {
class->toggle_class.Unset(group->widget, NULL, NULL, 0);
if (local_tog->toggle.toggle_style==XtToggleCheck) {
DisplayCheckBox((Widget)local_tog);
} else if (local_tog->toggle.toggle_style==XtToggleRadio) {
DisplayRadioButton((Widget)local_tog);
}
Notify( group->widget, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
}
group = group->next;
}
}
/* Function Name: RemoveFromRadioGroup
* Description: Removes a toggle from a RadioGroup.
* Arguments: w - the toggle widget to remove.
* Returns: none.
*/
static void
RemoveFromRadioGroup(w)
Widget w;
{
RadioGroup * group = GetRadioGroup(w);
if (group != NULL) {
if (group->prev != NULL)
(group->prev)->next = group->next;
if (group->next != NULL)
(group->next)->prev = group->prev;
XtFree((char *) group);
}
}
/************************************************************
*
* Public Routines
*
************************************************************/
/* Function Name: XawToggleChangeRadioGroup
* Description: Allows a toggle widget to change radio groups.
* Arguments: w - The toggle widget to change groups.
* radio_group - any widget in the new group.
* Returns: none.
*/
void
#if NeedFunctionPrototypes
XawToggleChangeRadioGroup(Widget w, Widget radio_group)
#else
XawToggleChangeRadioGroup(w, radio_group)
Widget w, radio_group;
#endif
{
ToggleWidget tw = (ToggleWidget) w;
RadioGroup * group;
RemoveFromRadioGroup(w);
/*
* If the toggle that we are about to add is set then we will
* unset all toggles in the new radio group.
*/
if ( tw->command.set && radio_group != NULL )
XawToggleUnsetCurrent(radio_group);
if (radio_group != NULL)
if ((group = GetRadioGroup(radio_group)) == NULL)
CreateRadioGroup(w, radio_group);
else AddToRadioGroup(group, w);
}
/* Function Name: XawToggleGetCurrent
* Description: Returns the RadioData associated with the toggle
* widget that is currently active in a toggle group.
* Arguments: w - any toggle widget in the toggle group.
* Returns: The XtNradioData associated with the toggle widget.
*/
XtPointer
#if NeedFunctionPrototypes
XawToggleGetCurrent(Widget w)
#else
XawToggleGetCurrent(w)
Widget w;
#endif
{
RadioGroup * group;
if ( (group = GetRadioGroup(w)) == NULL) return(NULL);
for ( ; group->prev != NULL ; group = group->prev);
while ( group != NULL ) {
ToggleWidget local_tog = (ToggleWidget) group->widget;
if ( local_tog->command.set )
return( local_tog->toggle.radio_data );
group = group->next;
}
return(NULL);
}
/* Function Name: XawToggleSetCurrent
* Description: Sets the Toggle widget associated with the
* radio_data specified.
* Arguments: radio_group - any toggle widget in the toggle group.
* radio_data - radio data of the toggle widget to set.
* Returns: none.
*/
void
#if NeedFunctionPrototypes
XawToggleSetCurrent(Widget radio_group, XtPointer radio_data)
#else
XawToggleSetCurrent(radio_group, radio_data)
Widget radio_group;
XtPointer radio_data;
#endif
{
RadioGroup * group;
ToggleWidget local_tog;
/* Special case of no radio group. */
if ( (group = GetRadioGroup(radio_group)) == NULL) {
local_tog = (ToggleWidget) radio_group;
if ( (local_tog->toggle.radio_data == radio_data) )
if (!local_tog->command.set) {
ToggleSet((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
Notify((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
}
return;
}
/*
* find top of radio_roup
*/
for ( ; group->prev != NULL ; group = group->prev);
/*
* search for matching radio data.
*/
while ( group != NULL ) {
local_tog = (ToggleWidget) group->widget;
if ( (local_tog->toggle.radio_data == radio_data) ) {
if (!local_tog->command.set) { /* if not already set. */
ToggleSet((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
Notify((Widget) local_tog, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
}
return; /* found it, done */
}
group = group->next;
}
}
/* Function Name: XawToggleUnsetCurrent
* Description: Unsets all Toggles in the radio_group specified.
* Arguments: radio_group - any toggle widget in the toggle group.
* Returns: none.
*/
void
#if NeedFunctionPrototypes
XawToggleUnsetCurrent(Widget radio_group)
#else
XawToggleUnsetCurrent(radio_group)
Widget radio_group;
#endif
{
ToggleWidgetClass class;
ToggleWidget local_tog = (ToggleWidget) radio_group;
/* Special Case no radio group. */
if (local_tog->command.set) {
class = (ToggleWidgetClass) local_tog->core.widget_class;
class->toggle_class.Unset(radio_group, NULL, NULL, 0);
Notify(radio_group, (XEvent *)NULL, (String *)NULL, (Cardinal *)0);
}
if ( GetRadioGroup(radio_group) == NULL) return;
TurnOffRadioSiblings(radio_group);
}
|