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
|
/*
* 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: WMShellGeom.c /main/8 1995/07/13 19:21:19 drk $"
#endif
#endif
/*
* (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
/*
* file: WMShellGeom.c
*
* This is a test to test out the variuos WMShell geometry related
* resources. Incodentally, it also shows a bug in RowColumn PIR 3261,
* about RowColumn not resizing its children to fit into its new size.
*
* It also shows a bug in DialogShell PIR 3262. This is about not being
* able to set the various WMShell resources in the DialogShell through
* SetValues.
*
* It also shows a bug apparently in scale PIR 3397. This is about the
* RowColumn not growing to accommodate its scale children when the top
* Shell is realized before thr RowColumn.
*
*/
#include <X11/Xlib.h>
#include <testlib.h>
#include "WMShellGeom.h"
Bool show_scalebug = False; /* PIR 3397 */
void main (argc, argv)
int argc;
char **argv;
{
int i;
int n;
Arg args[MAX_ARGS];
XmString tcs, tcs2;
CommonTestInit(argc, argv);
fontName[0] = '\0';
if (UserData != NULL)
ProcessCommandArgs();
if (fontName[0] == '\0')
strcpy(fontName, "fixed");
/* Init the max values for the scales */
screenHeight = HeightOfScreen(screen);
screenWidth = WidthOfScreen(screen);
for (i = 0; i < NUM_SCALES; i++) {
if (i == BASEWIDTH || i == MINASPECTX || i == MINWIDTH)
Scales[i].maxValue = screenWidth / 2;
else if (i == BASEHEIGHT || i == MINASPECTY || i == MINHEIGHT)
Scales[i].maxValue = screenHeight / 2;
else if (i == ICONX || i == MAXASPECTX || i == MAXWIDTH)
Scales[i].maxValue = screenWidth;
else if (i == ICONY || i == MAXASPECTY || i == MAXHEIGHT)
Scales[i].maxValue = screenHeight;
else if (i == WIDTHINC)
Scales[i].maxValue = screenWidth / 4;
else if (i == HEIGHTINC)
Scales[i].maxValue = screenHeight / 4;
}
n = 0;
XtSetArg(args[n], XmNallowShellResize, True); n++;
XtSetValues(Shell1, args, n);
/* Create Outer Form */
n = 0;
XtSetArg(args[n], XmNbackground, CommonGetColor("darkgreen")); n++;
Form = XmCreateForm(Shell1, "Form", args, n);
XtManageChild(Form);
tcs = XmStringCreateLtoR("WMShell Resources:",
XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, tcs); n++;
XtSetArg(args[n], XmNfontList, CommonGetFontList(fontName)); n++;
XtSetArg(args[n], XmNbackground, CommonGetColor("darkgreen")); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopOffset, 5); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftOffset, 5); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightOffset, 5); n++;
WMShell_Resources = XmCreateLabel(Form, "WMShell_Resources", args, n);
XtManageChild(WMShell_Resources);
if (show_scalebug == True) /* PIR 3397 */
XtRealizeWidget(Shell1);
XmStringFree(tcs);
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNtopOffset, 5); n++;
XtSetArg(args[n], XmNtopWidget, WMShell_Resources); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftOffset, 5); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightOffset, 5); n++;
XtSetArg(args[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
XtSetArg(args[n], XmNspacing, 5); n++;
XtSetArg(args[n], XmNnumColumns, 2); n++;
XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
XtSetArg(args[n], XmNpacking, XmPACK_COLUMN); n++;
/* Begin PIR3261 */
if (no_adjust == True) {
XtSetArg(args[n], XmNadjustLast, False); n++;
XtSetArg(args[n], XmNbackground, CommonGetColor("white")); n++;
}
/* End PIR3261 */
else
XtSetArg(args[n], XmNbackground, CommonGetColor("darkgreen")); n++;
RowCol1 = XmCreateRowColumn(Form, "RowCol1", args, n);
XtManageChild(RowCol1);
CreateWMShellResources(RowCol1);
if (show_scalebug == False) /* PIR 3397 */
XtRealizeWidget(Shell1);
CommonPause();
n = 0;
XtSetArg(args[n], XmNbackground, CommonGetColor("darkgreen")); n++;
WhichShell_Pulldown = XmCreatePulldownMenu(Shell1, "WhichShell_Pulldown",
args, n);
Application_Shell = CreatePushButton(WhichShell_Pulldown,
"ApplicationShell");
Top_Shell = CreatePushButton(WhichShell_Pulldown, "TopShell");
Dialog_Shell = CreatePushButton(WhichShell_Pulldown, "DialogShell");
All_Shells = CreatePushButton(WhichShell_Pulldown, "All Shells");
XtAddCallback(Application_Shell, XmNactivateCallback,
Application_ShellCB, NULL);
XtAddCallback(Top_Shell, XmNactivateCallback, Top_ShellCB, NULL);
XtAddCallback(Dialog_Shell, XmNactivateCallback, Dialog_ShellCB, NULL);
XtAddCallback(All_Shells, XmNactivateCallback, All_ShellsCB, NULL);
n = 0;
XtSetArg(args[n], XmNsensitive, False); n++;
XtSetValues(Dialog_Shell, args, n);
tcs = XmStringLtoRCreate("Apply Changes To ",
XmSTRING_DEFAULT_CHARSET);
n = 0;
XtSetArg(args[n], XmNlabelString, tcs); n++;
XtSetArg(args[n], XmNmenuHistory, Application_Shell); n++;
XtSetArg(args[n], XmNsubMenuId, WhichShell_Pulldown); n++;
XtSetArg(args[n], XmNbackground, CommonGetColor("darkgreen")); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNtopOffset, 5); n++;
XtSetArg(args[n], XmNtopWidget, RowCol1); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftOffset, 5); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightOffset, 5); n++;
WhichShell_Option = XmCreateOptionMenu(Form, "WhichShell_Option",
args, n);
XtManageChild(WhichShell_Option);
XmStringFree(tcs);
/*
* Create an applicationShell.
*/
n = 0;
XtSetArg(args[n], XtNallowShellResize, TRUE); n++;
XtSetArg(args[n], XmNiconX, 200); n++;
XtSetArg(args[n], XmNiconY, 200); n++;
XtSetArg(args[n], XmNminHeight, 100); n++;
XtSetArg(args[n], XmNminWidth, 100); n++;
XtSetArg(args[n], XmNmaxHeight, 200); n++;
XtSetArg(args[n], XmNmaxWidth, 200); n++;
applicationShell = XtAppCreateShell("applicationShell", "ApplicationShell",
applicationShellWidgetClass, display,
args, n);
n = 0;
XtSetArg(args[n], XmNlabelString,
XmStringCreateSimple("applicationShell")); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
application_btn = XmCreatePushButton(applicationShell,
"application_btn", args, n);
XtManageChild(application_btn);
XtRealizeWidget(applicationShell);
n = 0;
XtSetArg(args[n], XmNsensitive, True); n++;
XtSetValues(Application_Shell, args, n);
CommonPause();
/*
* Create a topLevelShell.
*/
n = 0;
XtSetArg(args[n], XtNallowShellResize, TRUE); n++;
XtSetArg(args[n], XmNiconX, 200); n++;
XtSetArg(args[n], XmNiconY, 200); n++;
XtSetArg(args[n], XmNminHeight, 100); n++;
XtSetArg(args[n], XmNminWidth, 100); n++;
XtSetArg(args[n], XmNmaxHeight, 200); n++;
XtSetArg(args[n], XmNmaxWidth, 200); n++;
topLevelShell = XtAppCreateShell("topLevelShell", "TopLevelShell",
topLevelShellWidgetClass, display,
args, n);
n = 0;
XtSetArg(args[n], XmNlabelString,
XmStringCreateSimple("topLevelShell")); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
topLevel_btn = XmCreatePushButton(topLevelShell, "topLevel_btn", args, n);
XtManageChild(topLevel_btn);
XtRealizeWidget(topLevelShell);
n = 0;
XtSetArg(args[n], XmNsensitive, True); n++;
XtSetValues(Top_Shell, args, n);
CommonPause();
/*
* Create a dialog shell
*/
n = 0;
XtSetArg (args[n], XmNmessageString,
XmStringCreateSimple ("This is a modeless dialog box"));
XtSetArg (args[n], XmNtitle, "Modeless Dialog"); n++;
XtSetArg (args[n], XmNdialogStyle, XmDIALOG_MODELESS); n++;
XtSetArg(args[n], XmNminHeight, 100); n++;
XtSetArg(args[n], XmNminWidth, 100); n++;
XtSetArg(args[n], XmNmaxHeight, 200); n++;
XtSetArg(args[n], XmNmaxWidth, 200); n++;
dialogShell = XmCreateMessageDialog(Shell1, "dialogShell", args, n);
XtManageChild(dialogShell);
n = 0;
XtSetArg(args[n], XmNsensitive, True); n++;
XtSetValues(Dialog_Shell, args, n);
CommonPause();
CommonPause();
XtAppMainLoop(app_context);
}
static void CreateWMShellResources(Widget parent)
{
int i;
Arg args[MAX_ARGS];
int n;
/* Create all the scales */
for (i = 0; i < NUM_SCALES; i++) {
n = 0;
XtSetArg(args[n], XmNtitleString,
XmStringCreateSimple(Scales[i].titleString)); n++;
XtSetArg(args[n], XmNminimum, Scales[i].minValue); n++;
XtSetArg(args[n], XmNmaximum, Scales[i].maxValue); n++;
XtSetArg(args[n], XmNvalue, Scales[i].minValue); n++;
XtSetArg(args[n], XmNshowValue, True); n++;
XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
XtSetArg(args[n], XmNscaleMultiple, 10); n++;
Scales[i].widget = XmCreateScale(parent, Scales[i].titleString,
args, n);
XtManageChild(Scales[i].widget);
}
}
static void Application_ShellCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
if (applicationShell == NULL) {
fprintf(stdout, "application Shell not created\n");
return;
}
GetWMShellResources();
SetWMShellResources(applicationShell);
XtUnmapWidget(applicationShell);
XSync(display, False);
XtMapWidget(applicationShell);
XSync(display, False);
}
static void Top_ShellCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
if (topLevelShell == NULL) {
fprintf(stdout, "topLevel Shell not created\n");
return;
}
GetWMShellResources();
SetWMShellResources(topLevelShell);
XtUnmapWidget(topLevelShell);
XSync(display, False);
XtMapWidget(topLevelShell);
XSync(display, False);
}
/* Begin PIR3262 */
static void Dialog_ShellCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
if (dialogShell == NULL) {
fprintf(stdout, "Dialog Shell not created\n");
return;
}
GetWMShellResources();
SetWMShellResources(XtParent(dialogShell));
XtUnmanageChild(dialogShell);
XSync(display, False);
XtManageChild(dialogShell);
XSync(display, False);
}
/* End PIR3262 */
static void All_ShellsCB(Widget w, XtPointer client_data,
XtPointer call_data)
{
GetWMShellResources();
if (applicationShell != NULL) {
SetWMShellResources(applicationShell);
XtUnmapWidget(applicationShell);
XSync(display, False);
XtMapWidget(applicationShell);
}
if (topLevelShell != NULL) {
SetWMShellResources(topLevelShell);
XtUnmapWidget(topLevelShell);
XSync(display, False);
XtMapWidget(topLevelShell);
}
if (dialogShell != NULL) {
SetWMShellResources(XtParent(dialogShell));
XtUnmanageChild(dialogShell);
XSync(display, False);
XtManageChild(dialogShell);
XSync(display, False);
}
}
static void GetWMShellResources()
{
int i;
Arg args[MAX_ARGS];
int n;
for (i = 0; i < NUM_SCALES; i++) {
if (Scales[i].widget == NULL)
scale_values[i].value = -1;
else {
n = 0;
XtSetArg (args[n], XmNvalue, &scale_values[i].value); n++;
XtGetValues (Scales[i].widget, args, n);
}
}
}
static void SetWMShellResources(Widget shell)
{
int i;
Arg args[MAX_ARGS];
int n;
n = 0;
for (i = 0; i < NUM_SCALES; i++) {
if (scale_values[i].value != -1)
XtSetArg (args[n], scale_values[i].name,
scale_values[i].value); n++;
}
XtSetValues (shell, args, n);
}
static Widget CreatePushButton(Widget parent, char *label)
{
Widget widget;
register int n;
Arg args[3];
XmString tcs;
tcs = XmStringLtoRCreate(label, XmSTRING_DEFAULT_CHARSET);
n = 0;
XtSetArg(args[n], XmNlabelString, tcs); n++;
XtSetArg(args[n], XmNbackground, CommonGetColor("darkgreen")); n++;
XtSetArg(args[n], XmNfontList, CommonGetFontList(fontName)); n++;
widget = XmCreatePushButton(parent, label, args, n);
XtManageChild(widget);
XmStringFree(tcs);
return(widget);
}
#define WORD_LEN 32
ProcessCommandArgs()
{
char *user_data;
char next_word[WORD_LEN + 1];
user_data = UserData;
while (*user_data != '\0') {
get_next_word(user_data, next_word);
user_data += strlen(next_word);
if (strcmp(next_word, "-noadjust") == 0) {
no_adjust = True;
continue;
}
if (strcmp(next_word, "-F") == 0) {
get_next_word(user_data, next_word);
strcpy(fontName, next_word);
user_data += strlen(next_word);
continue;
}
if (strcmp(next_word, "-scalebug") == 0) { /* PIR 3397 */
show_scalebug = True;
continue;
}
}
free(UserData);
}
get_next_word(source, dest)
char *source;
char *dest;
{
int n;
while (isspace(*source))
source++;
n = 0;
while (!isspace(*source) && *source != '\0' && n < WORD_LEN) {
*dest++ = *source++;
n++;
}
*dest = '\0';
}
#ifdef DEBUG
PrintResources(widget)
Widget widget;
{
int n;
Arg args[MAX_ARGS];
int i;
int value[NUM_SCALES];
i = 0;
n = 0;
XtSetArg(args[n], XmNbaseHeight, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNbaseWidth, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNheightInc, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNwidthInc, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNiconX, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNiconY, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNmaxAspectX, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNmaxAspectY, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNminAspectX, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNminAspectY, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNmaxHeight, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNmaxWidth, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNminHeight, &value[i]); n++;
XtGetValues(widget, args, n);
i++;
n = 0;
XtSetArg(args[n], XmNminWidth, &value[i]); n++;
XtGetValues(widget, args, n);
for (i = 0; i < NUM_SCALES; i++)
printf("%d\n", value[i]);
}
#endif /* DEBUG */
|