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
|
/*
* 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: OptionMenu5.c /main/8 1995/07/13 18:50:41 drk $"
#endif
#endif
/*
* (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
#include <testlib.h>
#include <X11/bitmaps/star>
#include <X11/bitmaps/opendot>
#include <X11/bitmaps/black>
#include <X11/bitmaps/boxes>
#include <X11/bitmaps/icon>
#include <X11/bitmaps/xlogo16>
#include <X11/bitmaps/xlogo32>
#include <X11/bitmaps/wide_weave>
#include <X11/bitmaps/target>
#define NUM_CHILDREN 6
#define NUM_VALUES 8
Pixmap
makepixmap(Widget toplevel, char bits[], int width, int height)
{
return (Pixmap)XCreatePixmapFromBitmapData(XtDisplay(toplevel),
DefaultRootWindow(XtDisplay(toplevel)),
bits,
width,
height,
BlackPixelOfScreen(XtScreen(toplevel)),
WhitePixelOfScreen(XtScreen(toplevel)),
DefaultDepthOfScreen(XtScreen(toplevel)));
}
/*
** change the labelString and labelPixmap for the object by cycling through
** a pre-prepared set of values
*/
/*ARGSUSED*/
void cycle_values (Widget w, XtPointer client_data, XtPointer call_data)
{
Widget entry = (Widget) client_data;
static char *orig_strings[NUM_VALUES] = {
"1",
"second in series",
"third in series",
"fourth in series",
"fifth in series",
"sixth in series",
"the seventh in the series",
"last in series"
};
static struct bitmap_data {
char *bits;
int width;
int height;
} orig_pixmap[] =
{
{(char *) star_bits, star_width, star_height},
{(char *) opendot_bits, opendot_width, opendot_height},
{(char *) black_bits, black_width, black_height},
{(char *) boxes_bits, boxes_width, boxes_height},
{(char *) icon_bits, icon_width, icon_height},
{(char *) xlogo16_bits, xlogo16_width, xlogo16_height},
{(char *) xlogo32_bits, xlogo32_width, xlogo32_height},
{(char *) wide_weave_bits, wide_weave_width, wide_weave_height},
};
static XmString strings[NUM_VALUES];
static Pixmap pixmaps[NUM_VALUES];
Arg args[5];
int n;
int i;
static Boolean values_set = False;
static int which_one = 0;
if (!values_set)
{
values_set = True;
for (i=0; i < NUM_VALUES; i++)
{
strings[i] = XmStringCreateSimple(orig_strings[i]);
pixmaps[i] = makepixmap(w,orig_pixmap[i].bits,
orig_pixmap[i].width,orig_pixmap[i].height);
}
/* gosh; remember to destroy these ! */
}
n = 0;
XtSetArg(args[n], XmNlabelString, strings[which_one]); n++;
XtSetArg(args[n], XmNlabelPixmap, pixmaps[which_one]); n++;
XtSetValues (entry, args, n);
which_one++;
which_one %= NUM_VALUES;
}
/*ARGSUSED*/
void change_sensitive (Widget w, XtPointer client_data, XtPointer call_data)
{
Widget option = (Widget) client_data;
XmToggleButtonCallbackStruct *info =
(XmToggleButtonCallbackStruct *)call_data;
Arg args[1];
int n;
XmString tcs;
n = 0;
XtSetArg (args[n], XmNsensitive, info->set); n++;
XtSetValues (option, args, n);
if (! info->set)
tcs = XmStringCreateSimple("Option's XmNsensitive = False");
else
tcs = XmStringCreateSimple("Option's XmNsensitive = True");
n = 0;
XtSetArg(args[n], XmNlabelString, tcs); n++;
XtSetValues(w, args, n);
}
/*ARGSUSED*/
void change_labelType(Widget w, XtPointer client_data, XtPointer call_data)
{
Widget *entries = (Widget *)client_data;
XmToggleButtonCallbackStruct *info =
(XmToggleButtonCallbackStruct *)call_data;
unsigned char labelType;
XmString tcs;
int i, n;
Arg args[2];
/* find the value from the first, change it in all the others */
n = 0;
XtSetArg(args[n], XmNlabelType, &labelType); n++;
XtGetValues(entries[0], args, n);
if (XmSTRING == labelType)
XtSetArg(args[0], XmNlabelType, XmPIXMAP);
else
XtSetArg(args[0], XmNlabelType, XmSTRING);
for (i=0; i < NUM_CHILDREN; i++)
XtSetValues(entries[i], args, 1);
if (! info->set)
tcs = XmStringCreateSimple("Menu items' XmNlabelType = XmPIXMAP");
else
tcs = XmStringCreateSimple("Menu items' XmNlabelType = XmSTRING");
n = 0;
XtSetArg(args[n], XmNlabelString, tcs); n++;
XtSetValues(w, args, n);
}
main(argc, argv)
int argc;
char *argv[];
{
Widget form, rc, option, buttons[NUM_CHILDREN], entries[NUM_CHILDREN], toggles;
Widget sensitive, labelType;
Widget pulldown, bb;
Arg args[10];
int n;
int i;
XmString dummy;
/* initialize toolkit; classname is XMcommon; sets global Shell1 */
CommonTestInit(argc, argv);
n = 0;
form = XmCreateForm (Shell1, "form", args, n); n++;
n = 0;
toggles = XmCreateForm (form, "toggles", args, n); n++;
n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
XtSetArg(args[n], XmNtopPosition, 1); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomPosition, 23); n++;
XtSetArg(args[n], XmNfractionBase, 100); n++;
XtSetValues (toggles, args, n);
n = 0;
rc = XmCreateForm (form, "rc", args, n);
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNtopPosition, 24); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomPosition, 64); n++;
XtSetArg(args[n], XmNfractionBase, 100); n++;
XtSetValues (rc, args, n);
dummy = XmStringCreateSimple("Option's XmNsensitive = True");
n = 0;
XtSetArg(args[n], XmNset, True); n++;
XtSetArg(args[n], XmNlabelString, dummy); n++;
sensitive = XmCreateToggleButton(toggles, "sensitivity", args, n);
XtManageChild(sensitive);
XmStringFree(dummy);
n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomPosition, 50); n++;
XtSetValues (sensitive, args, n);
dummy = XmStringCreateSimple("Menu items' XmNlabelType = XmSTRING");
n = 0;
XtSetArg(args[n], XmNset, True); n++;
XtSetArg(args[n], XmNlabelString, dummy); n++;
labelType = XmCreateToggleButton(toggles, "labelType", args, n);
XtManageChild(labelType);
XmStringFree(dummy);
n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopPosition, 50); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetValues (labelType, args, n);
n = 0;
bb = XmCreateBulletinBoard(form, "bb", args, n);
XtManageChild(bb);
n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNtopPosition, 65); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNbottomPosition, 99); n++;
XtSetValues (bb, args, n);
n = 0;
pulldown = XmCreatePulldownMenu(bb, "pulldown", args, n);
dummy = XmStringCreateSimple("Label/LabelG Menu Items");
n = 0;
XtSetArg(args[n],XmNsubMenuId, pulldown); n++;
XtSetArg(args[n], XmNlabelString, dummy); n++;
option=XmCreateOptionMenu(bb, "option_menu", args, n);
XmStringFree(dummy);
XtAddCallback(sensitive, XmNvalueChangedCallback, change_sensitive,
(Widget)option);
XtAddCallback(labelType, XmNvalueChangedCallback, change_labelType,
(Widget *)entries);
/* enumerate interesting subclasses of Label and LabelGadget */
entries[0] = XmCreateLabelGadget (pulldown, "lg", NULL, 0);
entries[1] = XmCreateLabel (pulldown, "label", NULL, 0);
entries[2] = XmCreatePushButtonGadget (pulldown, "pbg",NULL,0);
entries[3] = XmCreatePushButton (pulldown, "pb", NULL, 0);
entries[4] = XmCreateToggleButtonGadget (pulldown, "tbg", NULL, 0);
entries[5] = XmCreateToggleButton (pulldown, "tb", NULL, 0);
{
/* give an initial harmless XmNlabelPixmap */
int i;
Pixmap target = makepixmap(Shell1,target_bits, target_width,target_height);
XtSetArg(args[0], XmNlabelPixmap, target);
for (i=0; i< NUM_CHILDREN; i++)
XtSetValues(entries[i], args,1);
}
/* if the option appears as the name then the
** updating of the label is busted
*/
for (i=0; i < NUM_CHILDREN; i++) {
char buffer[100];
char lab[50];
sprintf(buffer, "Change pulldown entry #%d", i);
sprintf(lab, "entry%d", i);
dummy = XmStringCreateSimple(buffer);
n = 0;
XtSetArg(args[n], XmNlabelString, dummy); n++;
buttons[i] = XmCreatePushButton(rc, lab, args, n);
XmStringFree(dummy);
XtAddCallback(buttons[i], XmNactivateCallback, cycle_values,
entries[i]);
n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
XtSetArg(args[n], XmNtopPosition, i*100/NUM_CHILDREN); n++;
XtSetValues(buttons[i], args, n);
}
XtManageChildren(buttons, NUM_CHILDREN);
XtManageChildren(entries, NUM_CHILDREN);
XtManageChild(rc);
XtManageChild(toggles);
XtManageChild(form);
XtManageChild(option);
/* if we realize after setting the labels, there is no problem; it works.
** The sequence of realizing is important only because the option menu
** sets the cascade label at realize time, so we set afterwards so that if
** the name as the label shows we know it's wrong.
*/
#ifdef DONT_SHOW_INITIAL_BUG
XtRealizeWidget(Shell1);
#endif
{
/* confirm that we can change the labels programmatically and have the
** labels appear correctly in the XmOptionButtonGadget before the menu has
** been popped up by the user . So we set them here to what they should
** appear as. We should see "Label Gadget" echoed.
** Optimally, we will also see correct geometry for the CBG.
*/
static char *strings[NUM_VALUES]=
{
"Label Gadget",
"Label",
"Push Button Gadget",
"Push Button",
"Toggle Button Gadget",
"Toggle Button"
};
int i;
XmString dummy;
for (i=0; i< NUM_CHILDREN; i++)
{
dummy = XmStringCreateSimple(strings[i]);
n = 0;
XtSetArg(args[n], XmNlabelString, dummy); n++;
XtSetValues(entries[i], args, n);
XmStringFree(dummy);
}
}
#ifndef DONT_SHOW_INITIAL_BUG
XtRealizeWidget(Shell1);
#endif
CommonPause();
CommonPause();
CommonPause();
CommonPause();
CommonPause();
CommonPause();
/* declared elsewhere */
XtAppMainLoop(app_context);
}
|