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
|
/*
* $XConsortium: bbox.c,v 2.35 91/07/10 19:34:59 converse Exp $
*
*
* COPYRIGHT 1987, 1989
* DIGITAL EQUIPMENT CORPORATION
* MAYNARD, MASSACHUSETTS
* ALL RIGHTS RESERVED.
*
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
* SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
* DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR
* ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
*
* IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
* RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
* ADDITION TO THAT SET FORTH ABOVE.
*
* 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 name of Digital Equipment Corporation not be
* used in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*/
/* $XFree86: xc/programs/xmh/bbox.c,v 1.3 2002/04/05 21:06:28 dickey Exp $ */
/* bbox.c -- management of buttons and buttonboxes.
*
* This module implements a simple interface to buttonboxes, allowing a client
* to create new buttonboxes and manage their contents.
*/
#include "xmh.h"
#include "bboxint.h"
static XtTranslations RadioButtonTranslations = NULL;
void BBoxInit(void)
{
RadioButtonTranslations =
XtParseTranslationTable("<Btn1Down>,<Btn1Up>:set()\n");
}
/*
* Create a new button box. The widget for it will be a child of the given
* scrn's widget, and it will be added to the scrn's pane.
*/
ButtonBox BBoxCreate(
Scrn scrn,
char *name) /* name of the buttonbox widgets */
{
Cardinal n;
ButtonBox buttonbox = XtNew(ButtonBoxRec);
Arg args[5];
n = 0;
XtSetArg(args[n], XtNallowVert, True); n++;
XtSetArg(args[n], XtNskipAdjust, True); n++;
buttonbox->outer =
XtCreateManagedWidget(name, viewportWidgetClass, scrn->widget,
args, n);
buttonbox->inner =
XtCreateManagedWidget(name, boxWidgetClass, buttonbox->outer,
args, (Cardinal) 0);
buttonbox->numbuttons = 0;
buttonbox->button = (Button *) NULL;
buttonbox->scrn = scrn;
return buttonbox;
}
ButtonBox RadioBBoxCreate(
Scrn scrn,
char *name) /* name of the buttonbox widgets */
{
return BBoxCreate(scrn, name);
}
/* Create a new button, and add it to a buttonbox. */
static void bboxAddButton(
ButtonBox buttonbox,
char *name,
WidgetClass kind,
Boolean enabled,
Boolean radio)
{
Button button;
Cardinal i;
Widget radio_group;
Arg args[5];
buttonbox->numbuttons++;
buttonbox->button = (Button *)
XtRealloc((char *) buttonbox->button,
(unsigned) buttonbox->numbuttons * sizeof(Button));
button = buttonbox->button[buttonbox->numbuttons - 1] = XtNew(ButtonRec);
button->buttonbox = buttonbox;
button->name = XtNewString(name);
button->menu = (Widget) NULL;
i = 0;
if (!enabled) {
XtSetArg(args[i], XtNsensitive, False); i++;
}
if (radio && kind == toggleWidgetClass) {
if (buttonbox->numbuttons > 1)
radio_group = (button == buttonbox->button[0])
? (buttonbox->button[1]->widget)
: (buttonbox->button[0]->widget);
else radio_group = NULL;
XtSetArg(args[i], XtNradioGroup, radio_group); i++;
XtSetArg(args[i], XtNradioData, button->name); i++;
}
/* Prevent the folder buttons from picking up labels from resources */
if (buttonbox == buttonbox->scrn->folderbuttons) {
XtSetArg(args[i], XtNlabel, button->name); i++;
}
button->widget =
XtCreateManagedWidget(name, kind, buttonbox->inner, args, i);
if (radio)
XtOverrideTranslations(button->widget, RadioButtonTranslations);
}
void BBoxAddButton(
ButtonBox buttonbox,
char *name,
WidgetClass kind,
Boolean enabled)
{
bboxAddButton(buttonbox, name, kind, enabled, False);
}
void RadioBBoxAddButton(
ButtonBox buttonbox,
char *name,
Boolean enabled)
{
bboxAddButton(buttonbox, name, toggleWidgetClass, enabled, True);
}
/* Set the current button in a radio buttonbox. */
void RadioBBoxSet(
Button button)
{
XawToggleSetCurrent(button->widget, button->name);
}
/* Get the name of the current button in a radio buttonbox. */
char *RadioBBoxGetCurrent(
ButtonBox buttonbox)
{
return ((char *) XawToggleGetCurrent(buttonbox->button[0]->widget));
}
/* Remove the given button from its buttonbox, and free all resources
* used in association with the button. If the button was the current
* button in a radio buttonbox, the current button becomes the first
* button in the box.
*/
void BBoxDeleteButton(
Button button)
{
ButtonBox buttonbox;
int i, found;
if (button == NULL) return;
buttonbox = button->buttonbox;
found = False;
for (i=0 ; i<buttonbox->numbuttons; i++) {
if (found)
buttonbox->button[i-1] = buttonbox->button[i];
else if (buttonbox->button[i] == button) {
found = True;
/* Free the resources used by the given button. */
if (button->menu != NULL && button->menu != NoMenuForButton)
XtDestroyWidget(button->menu);
XtDestroyWidget(button->widget);
XtFree(button->name);
XtFree((char *) button);
}
}
if (found)
buttonbox->numbuttons--;
}
void RadioBBoxDeleteButton(
Button button)
{
ButtonBox buttonbox;
Boolean reradio = False;
char * current;
if (button == NULL) return;
buttonbox = button->buttonbox;
current = RadioBBoxGetCurrent(buttonbox);
if (current) reradio = ! strcmp(current, button->name);
BBoxDeleteButton(button);
if (reradio && BBoxNumButtons(buttonbox))
RadioBBoxSet(buttonbox->button[0]);
}
/* Enable or disable the given button widget. */
static void SendEnableMsg(
Widget widget,
int value) /* TRUE for enable, FALSE for disable. */
{
static Arg arglist[] = {{XtNsensitive, (XtArgVal)False}};
arglist[0].value = (XtArgVal) value;
XtSetValues(widget, arglist, XtNumber(arglist));
}
/* Enable the given button (if it's not already). */
void BBoxEnable(
Button button)
{
SendEnableMsg(button->widget, True);
}
/* Disable the given button (if it's not already). */
void BBoxDisable(
Button button)
{
SendEnableMsg(button->widget, False);
}
/* Given a buttonbox and a button name, find the button in the box with that
name. */
Button BBoxFindButtonNamed(
ButtonBox buttonbox,
char *name)
{
register int i;
for (i=0 ; i<buttonbox->numbuttons; i++)
if (strcmp(name, buttonbox->button[i]->name) == 0)
return buttonbox->button[i];
return (Button) NULL;
}
/* Given a buttonbox and a widget, find the button which is that widget. */
Button BBoxFindButton(
ButtonBox buttonbox,
Widget w)
{
register int i;
for (i=0; i < buttonbox->numbuttons; i++)
if (buttonbox->button[i]->widget == w)
return buttonbox->button[i];
return (Button) NULL;
}
/* Return the nth button in the given buttonbox. */
Button BBoxButtonNumber(
ButtonBox buttonbox,
int n)
{
return buttonbox->button[n];
}
/* Return how many buttons are in a buttonbox. */
int BBoxNumButtons(
ButtonBox buttonbox)
{
return buttonbox->numbuttons;
}
/* Given a button, return its name. */
char *BBoxNameOfButton(
Button button)
{
return button->name;
}
/* Given a button, return its menu. */
Widget BBoxMenuOfButton(
Button button)
{
return button->menu;
}
/* Set maximum size for a bbox so that it cannot be resized any taller
* than the space needed to stack all the buttons on top of each other.
* Allow the user to set the minimum size.
*/
void BBoxLockSize(
ButtonBox buttonbox)
{
Dimension maxheight;
Arg args[1];
if (buttonbox == NULL) return;
maxheight = (Dimension) GetHeight(buttonbox->inner);
XtSetArg(args[0], XtNmax, maxheight); /* for Paned widget */
XtSetValues(buttonbox->outer, args, (Cardinal) 1);
}
Boolean BBoxIsGrandparent(
ButtonBox buttonbox,
Widget widget)
{
return (XtParent(XtParent(widget)) == buttonbox->inner);
}
void BBoxMailFlag(
ButtonBox buttonbox,
char* name,
int up)
{
Arg args[1];
Pixel flag;
Button button = BBoxFindButtonNamed(buttonbox, name);
if (button) {
/* avoid unnecessary exposures */
XtSetArg(args[0], XtNleftBitmap, &flag);
XtGetValues(button->widget, args, (Cardinal)1);
if (up && flag != app_resources.flag_up) {
XtSetArg(args[0], XtNleftBitmap, app_resources.flag_up);
XtSetValues(button->widget, args, (Cardinal)1);
}
else if (!up && flag != app_resources.flag_down) {
XtSetArg(args[0], XtNleftBitmap, app_resources.flag_down);
XtSetValues(button->widget, args, (Cardinal)1);
}
}
}
|