1 /* 2 * 3 Copyright 1989, 1998 The Open Group 4 5 Permission to use, copy, modify, distribute, and sell this software and its 6 documentation for any purpose is hereby granted without fee, provided that 7 the above copyright notice appear in all copies and that both that 8 copyright notice and this permission notice appear in supporting 9 documentation. 10 11 The above copyright notice and this permission notice shall be included in 12 all copies or substantial portions of the Software. 13 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21 Except as contained in this notice, the name of The Open Group shall not be 22 used in advertising or otherwise to promote the sale, use or other dealings 23 in this Software without prior written authorization from The Open Group. 24 */ 25 26 27 #ifdef HAVE_CONFIG_H 28 # include "config.h" 29 #endif 30 31 #include <X11/Intrinsic.h> 32 #include <X11/StringDefs.h> 33 34 #include <X11/Xaw/Cardinals.h> 35 #include <X11/Xaw/List.h> 36 #include <X11/Xaw/Panner.h> 37 #include <X11/Xaw/Toggle.h> 38 #include <X11/Xfuncs.h> 39 #include <X11/Xos.h> /* for W_OK def */ 40 41 #include <stdio.h> 42 #include <stdlib.h> 43 44 #include "editresP.h" 45 46 /* 47 * Local function definitions. 48 */ 49 static String GetResourceName ( ResourceBoxInfo * res_box ); 50 static void _AppendResourceString ( Widget w, XtPointer res_box_ptr, 51 XtPointer filename_ptr ); 52 static void _SetResourcesFile ( Widget w, XtPointer junk, 53 XtPointer filename_ptr ); 54 static void ObtainResource ( XtPointer node_ptr ); 55 static void CreateSetValuesCommand ( WNode * node, XtPointer info_ptr ); 56 static void SetOnlyMatchingWidgets ( WNode * node, XtPointer info_ptr ); 57 58 /* Function Name: Quit 59 * Description: This function prints a message to stdout. 60 * Arguments: w - ** UNUSED ** 61 * call_data - ** UNUSED ** 62 * client_data - ** UNUSED ** 63 * Returns: none 64 */ 65 66 /* ARGSUSED */ 67 void 68 Quit(Widget w, XtPointer client_data, XtPointer call_data) 69 { 70 XtDestroyApplicationContext(XtWidgetToApplicationContext(w)); 71 exit(0); 72 } 73 74 /* Function Name: SendTree 75 * Description: This function initiates the client communication. 76 * by getting the resource tree. 77 * Arguments: w - the widget that made the selection. 78 * value - a boolean value stored as a pointer. 79 * if True then get a new client, otherwise 80 * refresh the current client. 81 * call_data - ** UNUSED ** 82 * Returns: none 83 */ 84 85 /* ARGSUSED */ 86 void 87 SendTree(Widget w, XtPointer value, XtPointer call_data) 88 { 89 if ((Boolean)(long) value) 90 global_client.window = None; 91 92 if (!XtIsWidget(w)) /* Make sure that we use a "Real" widget here. */ 93 w = XtParent(w); 94 95 _XEditResResetStream(&(global_client.stream)); /* an empty message. */ 96 97 SetCommand(w, LocalSendWidgetTree, NULL); 98 } 99 100 /* Function Name: FindWidget 101 * Description: Maps a widget in the client to one in the currently 102 * displayed widget tree. 103 * Arguments: w - the widget that invoked this action. 104 * call_data, client_data ** UNUSED ** 105 * Returns: none 106 */ 107 108 /* ARGSUSED */ 109 void 110 FindWidget(Widget w, XtPointer client_data, XtPointer call_data) 111 { 112 113 _FindWidget(XtParent(w)); /* Use parent since it is a "real" 114 widget not a rect_obj. */ 115 } 116 117 /* Function Name: InitSetValues 118 * Description: This function pops up the setvalues dialog 119 * Arguments: w - the widget caused this action. 120 * call_data - ** UNUSED ** 121 * client_data - ** UNUSED ** 122 * Returns: none 123 */ 124 125 /* ARGSUSED */ 126 void 127 InitSetValues(Widget w, XtPointer client_data, XtPointer call_data) 128 { 129 if (!XtIsWidget(w)) /* Make sure that we use a "Real" widget here. */ 130 w = XtParent(w); 131 132 PopupSetValues(w, NULL); 133 } 134 135 /* Function Name: TreeSelect 136 * Description: Selects all widgets. 137 * Arguments: w - the widget caused this action. 138 * call_data - ** UNUSED ** 139 * client_data - The type of thing to select. 140 * Returns: none 141 */ 142 143 /* ARGSUSED */ 144 void 145 TreeSelect(Widget w, XtPointer client_data, XtPointer call_data) 146 { 147 SelectTypes type = (SelectTypes) (unsigned long) client_data; 148 149 _TreeSelect(global_tree_info, type); 150 } 151 152 /* Function Name: TreeRelabel 153 * Description: Relabels a tree to the type specified. 154 * Arguments: w - the widget caused this action. 155 * call_data - ** UNUSED ** 156 * client_data - the type of label to assign to each node. 157 * Returns: none 158 */ 159 160 /* ARGSUSED */ 161 void 162 TreeRelabel(Widget w, XtPointer client_data, XtPointer call_data) 163 { 164 LabelTypes type = (LabelTypes) (unsigned long) client_data; 165 166 _TreeRelabel(global_tree_info, type); 167 } 168 169 /* Function Name: PannerCallback 170 * Description: called when the panner has moved. 171 * Arguments: panner - the panner widget. 172 * closure - *** NOT USED ***. 173 * report_ptr - the panner record. 174 * Returns: none. 175 */ 176 177 /* ARGSUSED */ 178 void 179 PannerCallback(Widget w, XtPointer closure, XtPointer report_ptr) 180 { 181 Arg args[2]; 182 XawPannerReport *report = (XawPannerReport *) report_ptr; 183 184 if (global_tree_info == NULL) 185 return; 186 187 XtSetArg (args[0], (String)XtNx, -report->slider_x); 188 XtSetArg (args[1], (String)XtNy, -report->slider_y); 189 190 XtSetValues(global_tree_info->tree_widget, args, TWO); 191 } 192 193 /* Function Name: PortholeCallback 194 * Description: called when the porthole or its child has 195 * changed 196 * Arguments: porthole - the porthole widget. 197 * panner_ptr - the panner widget. 198 * report_ptr - the porthole record. 199 * Returns: none. 200 */ 201 202 /* ARGSUSED */ 203 void 204 PortholeCallback(Widget w, XtPointer panner_ptr, XtPointer report_ptr) 205 { 206 Arg args[10]; 207 Cardinal n = 0; 208 XawPannerReport *report = (XawPannerReport *) report_ptr; 209 Widget panner = (Widget) panner_ptr; 210 211 XtSetArg (args[n], (String)XtNsliderX, report->slider_x); n++; 212 XtSetArg (args[n], (String)XtNsliderY, report->slider_y); n++; 213 if (report->changed != (XawPRSliderX | XawPRSliderY)) { 214 XtSetArg (args[n], (String)XtNsliderWidth, report->slider_width); n++; 215 XtSetArg (args[n], (String)XtNsliderHeight, report->slider_height); n++; 216 XtSetArg (args[n], (String)XtNcanvasWidth, report->canvas_width); n++; 217 XtSetArg (args[n], (String)XtNcanvasHeight, report->canvas_height); n++; 218 } 219 XtSetValues (panner, args, n); 220 } 221 222 /* Function Name: FlashActiveWidgets 223 * Description: called to flash all active widgets in the display. 224 * Arguments: *** NOT USED *** 225 * Returns: none. 226 */ 227 228 /* ARGSUSED */ 229 void 230 FlashActiveWidgets(Widget w, XtPointer junk, XtPointer garbage) 231 { 232 _FlashActiveWidgets(global_tree_info); 233 } 234 235 /* Function Name: GetResourceList 236 * Description: Gets the resources lists of all active widgets. 237 * Arguments: ** NOT USED ** 238 * Returns: none 239 */ 240 241 /* ARGSUSED */ 242 void 243 GetResourceList(Widget w, XtPointer junk, XtPointer garbage) 244 { 245 WNode * node; 246 ProtocolStream * stream = &(global_client.stream); 247 248 if (global_tree_info == NULL) { 249 SetMessage(global_screen_data.info_label, 250 res_labels[17]); 251 return; 252 } 253 254 if (global_tree_info->num_nodes != 1) { 255 SetMessage(global_screen_data.info_label, 256 res_labels[19]); 257 return; 258 } 259 260 node = global_tree_info->active_nodes[0]; 261 if (node->resources != NULL) { 262 char * errors = NULL; 263 CreateResourceBox(node, &errors); 264 if (errors != NULL) { 265 SetMessage(global_screen_data.info_label, errors); 266 XtFree(errors); 267 } 268 return; 269 } 270 271 /* 272 * No resources, fetch them from the client. 273 */ 274 275 _XEditResResetStream(stream); 276 _XEditResPut16(stream, (unsigned short) 1); 277 InsertWidgetFromNode(stream, node); 278 SetCommand(global_tree_info->tree_widget, LocalGetResources, NULL); 279 } 280 281 /* Function Name: DumpTreeToFile 282 * Description: Dumps all widgets in the tree to a file. 283 * Arguments: w - the widget that activated this callback. 284 * junk, garbage - ** NOT USED **. 285 * Returns: none. 286 */ 287 288 /* ARGSUSED */ 289 void 290 DumpTreeToFile(Widget w, XtPointer junk, XtPointer garbage) 291 { 292 _PopupFileDialog(XtParent(w), "Enter the filename:", "", 293 _DumpTreeToFile, (XtPointer) global_tree_info); 294 } 295 296 /************************************************************ 297 * 298 * Callbacks for the Resource Box. 299 * 300 ************************************************************/ 301 302 303 /* Function Name: AnyChosen 304 * Description: Callback that is called when the "any" widget 305 * is activated. 306 * Arguments: w - the "any" widget that activated this callback. 307 * any_info_ptr - pointer to struct containing 308 * dot and star widgets to lock. 309 * state_ptr - state of the any toggle. 310 * Returns: none. 311 */ 312 313 /* ARGSUSED */ 314 void 315 AnyChosen(Widget w, XtPointer any_info_ptr, XtPointer state_ptr) 316 { 317 AnyInfo * any_info = (AnyInfo *) any_info_ptr; 318 Boolean state = (Boolean)(long) state_ptr; 319 Arg args[1]; 320 321 if (state) { 322 323 if (any_info->left_count == 0) { 324 XtSetSensitive(any_info->left_dot, FALSE); 325 XtSetSensitive(any_info->left_star, FALSE); 326 327 XtSetArg(args[0], (String)XtNstate, TRUE); 328 XtSetValues(any_info->left_star, args, ONE); 329 } 330 331 if ((any_info->right_count == NULL)||(*any_info->right_count == 0)) { 332 XtSetSensitive(any_info->right_dot, FALSE); 333 XtSetSensitive(any_info->right_star, FALSE); 334 335 XtSetArg(args[0], (String)XtNstate, TRUE); 336 XtSetValues(any_info->right_star, args, ONE); 337 } 338 any_info->left_count++; 339 340 if (any_info->right_count != NULL) 341 (*any_info->right_count)++; 342 } 343 else { /* state == 0 */ 344 if (any_info->left_count > 0) 345 any_info->left_count--; 346 if ((any_info->right_count != NULL)&&(*any_info->right_count > 0)) 347 (*any_info->right_count)--; 348 349 if (any_info->left_count == 0) { 350 XtSetSensitive(any_info->left_dot, TRUE); 351 XtSetSensitive(any_info->left_star, TRUE); 352 353 XtSetArg(args[0], (String)XtNstate, TRUE); 354 XtSetValues(any_info->left_dot, args, ONE); 355 } 356 357 if ((any_info->right_count == NULL)||(*any_info->right_count == 0)) { 358 XtSetSensitive(any_info->right_dot, TRUE); 359 XtSetSensitive(any_info->right_star, TRUE); 360 361 XtSetArg(args[0], (String)XtNstate, TRUE); 362 XtSetValues(any_info->right_dot, args, ONE); 363 } 364 } 365 SetResourceString(NULL, (XtPointer) any_info->node, NULL); 366 ActivateResourceWidgets(NULL, (XtPointer) any_info->node, NULL); 367 } 368 369 /* Function Name: GetResourceName 370 * Description: Gets the name of the current resource. 371 * Arguments: res_box - the resource box. 372 * Returns: the name of the currently selected resource. 373 */ 374 375 376 static String 377 GetResourceName(ResourceBoxInfo *res_box) 378 { 379 XawListReturnStruct * list_info; 380 String result; 381 382 list_info = XawListShowCurrent(res_box->norm_list); 383 if ((list_info->list_index == XAW_LIST_NONE) && 384 (res_box->cons_list != NULL)) { 385 list_info = XawListShowCurrent(res_box->cons_list); 386 } 387 388 if (list_info->list_index == XAW_LIST_NONE) 389 result = (String)"unknown"; 390 else 391 result = list_info->string; 392 393 return(result); 394 } 395 396 397 /* Function Name: ActivateWidgetsAndSetResourceString 398 * Description: Sets the new resources string, then 399 * activates all widgets that match this resource, 400 * Arguments: w - the widget that activated this. 401 * node_ptr - the node that owns this resource box. 402 * call_data - passed on to other callbacks. 403 * Returns: none. 404 * 405 * NOTE: I cannot just have two callback routines, since I care which 406 * order that these are executed in, sigh... 407 */ 408 409 void 410 ActivateWidgetsAndSetResourceString(Widget w, 411 XtPointer node_ptr, XtPointer call_data) 412 { 413 SetResourceString(w, node_ptr, call_data); 414 ActivateResourceWidgets(w, node_ptr, call_data); 415 } 416 417 /* Function Name: SetResourceString 418 * Description: Sets the resource label to correspond to the currently 419 * chosen string. 420 * Arguments: w - The widget that invoked this callback, or NULL. 421 * node_ptr - pointer to widget node containing this res box. 422 * call_data - The call data for the action that invoked 423 * this callback. 424 * Returns: none. 425 */ 426 427 void 428 SetResourceString(Widget w, XtPointer node_ptr, XtPointer junk) 429 { 430 static char * malloc_string; /* These are both inited to zero. */ 431 static Cardinal malloc_size; 432 433 WNode * node = (WNode *) node_ptr; 434 ResourceBoxInfo * res_box = node->resources->res_box; 435 char * temp, buf[BUFSIZ * 10]; /* here's hoping it's big enough. */ 436 NameInfo * name_node = res_box->name_info; 437 Arg args[1]; 438 Cardinal len; 439 440 if ((w != NULL) && XtIsSubclass(w, toggleWidgetClass)) { 441 /* 442 * Only set resources when toggles are activated, not when they are 443 * deactivated. 444 */ 445 if (!((Boolean)(long) junk)) 446 return; 447 } 448 449 buf[0] = '\0'; /* clear out string. */ 450 451 /* 452 * Get the widget name/class info. 453 */ 454 455 if ((temp = (char *) XawToggleGetCurrent(name_node->sep_leader)) != NULL) 456 strcat(buf, temp); 457 458 for ( ; name_node->next != NULL ; name_node = name_node->next) { 459 temp = (char *) XawToggleGetCurrent(name_node->name_leader); 460 if ( (temp != NULL) && !streq(temp, ANY_RADIO_DATA) ) { 461 strcat(buf, temp); 462 temp = (char *) XawToggleGetCurrent(name_node->next->sep_leader); 463 if (temp == NULL) 464 strcat(buf, "!"); 465 else 466 strcat(buf, temp); 467 } 468 } 469 470 strcat(buf, GetResourceName(res_box)); 471 len = strlen(buf) + 2; /* Leave space for ':' and '\0' */ 472 473 #ifdef notdef 474 XtSetArg(args[0], (String)XtNstring, &temp); 475 XtGetValues(res_box->value_wid, args, ONE); 476 len += strlen(temp); 477 #endif 478 479 if (len > malloc_size) { 480 malloc_string = XtRealloc(malloc_string, sizeof(char) * len); 481 malloc_size = len; 482 } 483 484 strcpy(malloc_string, buf); 485 strcat(malloc_string, ":"); 486 #ifdef notdef 487 strcat(malloc_string, temp); 488 #endif 489 490 XtSetArg(args[0], (String)XtNlabel, malloc_string); 491 XtSetValues(res_box->res_label, args, ONE); 492 } 493 494 /* Function Name: ResourceListCallback 495 * Description: Callback functions for the resource lists. This 496 * routine is essentially called by the list widgets 497 * Notify action. If action EnableGetVal has been 498 * invoked, ResourceListCallback will perform a 499 * GetValues protocol request. 500 * Arguments: list - the list widget that we are dealing with. 501 * node_ptr - pointer to widget node containing this res box. 502 * junk - UNUSED. 503 * Returns: none 504 */ 505 506 void 507 ResourceListCallback(Widget list, XtPointer node_ptr, XtPointer junk) 508 { 509 Widget o_list; 510 WNode * node = (WNode *) node_ptr; 511 ResourceBoxInfo * res_box = node->resources->res_box; 512 513 if (list == res_box->norm_list) 514 o_list = res_box->cons_list; 515 else 516 o_list = res_box->norm_list; 517 518 if (o_list != NULL) 519 XawListUnhighlight(o_list); 520 521 SetResourceString(list, node_ptr, junk); 522 523 /* get the resource value from the application */ 524 if (global_effective_protocol_version >= 5 && do_get_values) { 525 ObtainResource(node_ptr); 526 do_get_values = False; 527 } 528 } 529 530 /* Function Name: PopdownResBox 531 * Description: Pops down the resource box. 532 * Arguments: w - UNUSED 533 * shell_ptr - pointer to the shell to pop down. 534 * junk - UNUSED. 535 * Returns: none 536 */ 537 538 /* ARGSUSED */ 539 void 540 PopdownResBox(Widget w, XtPointer shell_ptr, XtPointer junk) 541 { 542 Widget shell = (Widget) shell_ptr; 543 544 XtPopdown(shell); 545 XtDestroyWidget(shell); 546 } 547 548 /* ARGSUSED */ 549 static void 550 _AppendResourceString(Widget w, XtPointer res_box_ptr, XtPointer filename_ptr) 551 { 552 Arg args[1]; 553 FILE * fp; 554 char buf[BUFSIZ], * resource_string, *filename = (char *) filename_ptr; 555 ResourceBoxInfo * res_box = (ResourceBoxInfo *) res_box_ptr; 556 char *value_ptr; 557 558 if (filename != NULL) { 559 if (global_resources.allocated_save_resources_file) 560 XtFree(global_resources.save_resources_file); 561 else 562 global_resources.allocated_save_resources_file = TRUE; 563 564 global_resources.save_resources_file = XtNewString(filename); 565 } 566 567 if ((fp = fopen(global_resources.save_resources_file, "a+")) == NULL) { 568 snprintf(buf, sizeof(buf), "%s", 569 "Unable to open this file for writing, would " 570 "you like To try again?"); 571 _PopupFileDialog(global_toplevel ,buf, 572 global_resources.save_resources_file, 573 _AppendResourceString, res_box_ptr); 574 return; 575 } 576 577 XtSetArg(args[0], (String)XtNlabel, &resource_string); 578 XtGetValues(res_box->res_label, args, ONE); 579 580 XtSetArg(args[0], (String)XtNstring, &value_ptr); 581 XtGetValues(res_box->value_wid, args, ONE); 582 583 fprintf(fp, "%s %s\n", resource_string, value_ptr); 584 585 fclose(fp); 586 } 587 588 /* Function Name: SaveResource 589 * Description: Save the current resource to your resource file 590 * Arguments: w - any widget in the application. 591 * res_box_ptr - the resource box info. 592 * junk - UNUSED. 593 * Returns: none 594 */ 595 596 /* ARGSUSED */ 597 void 598 SaveResource(Widget w, XtPointer res_box_ptr, XtPointer junk) 599 { 600 /* 601 * If there is no filename the ask for one, otherwise just save to 602 * current file. 603 */ 604 605 if (streq(global_resources.save_resources_file, "")) 606 _PopupFileDialog(XtParent(w), "Enter file to dump resources into:", 607 global_resources.save_resources_file, 608 _AppendResourceString, res_box_ptr); 609 else 610 _AppendResourceString(w, res_box_ptr, NULL); 611 } 612 613 /* Function Name: _SetResourcesFile 614 * Description: Sets the filename of the file to save the resources to. 615 * Arguments: w - UNUSED 616 * junk - UNUSED 617 * filename_ptr - a pointer to the filename; 618 * Returns: none 619 */ 620 621 /* ARGSUSED */ 622 static void 623 _SetResourcesFile(Widget w, XtPointer junk, XtPointer filename_ptr) 624 { 625 char *filename = (char *) filename_ptr; 626 627 if (global_resources.allocated_save_resources_file) 628 XtFree(global_resources.save_resources_file); 629 else 630 global_resources.allocated_save_resources_file = TRUE; 631 632 global_resources.save_resources_file = XtNewString(filename); 633 } 634 635 /* Function Name: SetFile 636 * Description: Changes the current save file 637 * Arguments: w - UNUSED. 638 * res_box_ptr - UNUSED. 639 * junk - UNUSED. 640 * Returns: none 641 */ 642 643 /* ARGSUSED */ 644 void 645 SetFile(Widget w, XtPointer junk, XtPointer garbage) 646 { 647 /* 648 * If there is no filename the ask for one, otherwise just save to 649 * current file. 650 */ 651 652 _PopupFileDialog(XtParent(w), "Enter file to dump resources into:", 653 global_resources.save_resources_file, 654 _SetResourcesFile, NULL); 655 } 656 657 /* Function Name: ApplyResource 658 * Description: Apply the current resource to the running application. 659 * Arguments: w - any widget in the application. 660 * node_ptr - a pointer to the node containing 661 * the current resource box. 662 * junk - UNUSED. 663 * Returns: none 664 */ 665 666 /* ARGSUSED */ 667 void 668 ApplyResource(Widget w, XtPointer node_ptr, XtPointer junk) 669 { 670 ProtocolStream * stream = &(global_client.stream); 671 ApplyResourcesInfo info; 672 WNode * node = (WNode *) node_ptr; 673 char * value; 674 unsigned short size, i; 675 long len; 676 Arg args[1]; 677 678 info.name = GetResourceName(node->resources->res_box); 679 info.class = "IGNORE_ME"; /* Not currently used. */ 680 info.stream = stream; 681 info.count = 0; 682 683 XtSetArg(args[0], (String)XtNlabel, &value); 684 XtGetValues(node->resources->res_box->res_label, args, ONE); 685 686 info.database = NULL; 687 XrmPutLineResource(&(info.database), value); 688 689 690 _XEditResResetStream(stream); 691 _XEditResPutString8(stream, info.name); /* Insert name */ 692 _XEditResPutString8(stream, XtRString); /* insert type */ 693 694 /* 695 * Insert value. 696 */ 697 698 value = GetResourceValueForSetValues(node, &size); 699 _XEditResPut16(stream, size); 700 for (i = 0; i < size; i++) 701 _XEditResPut8(stream, value[i]); 702 XtFree(value); 703 len = stream->current - stream->top; 704 705 /* 706 * Insert the widget count, overridden later. 707 */ 708 709 _XEditResPut16(stream, 0); 710 711 ExecuteOverAllNodes(node->tree_info->top_node, 712 CreateSetValuesCommand, (XtPointer) &info); 713 714 if (info.count > 0) { 715 *(stream->top + len++) = info.count >> XER_NBBY; /* Set the correct */ 716 *(stream->top + len) = info.count; /* count. */ 717 718 SetCommand(node->tree_info->tree_widget, LocalSetValues, NULL); 719 } 720 else 721 SetMessage(global_screen_data.info_label, 722 res_labels[20]); 723 724 XrmDestroyDatabase(info.database); 725 } 726 727 /* Function Name: ObtainResource 728 * Description: Obtain the current resource from the running application. 729 * Arguments: node_ptr - a pointer to the node containing 730 * the current resource box. 731 * Returns: none 732 */ 733 734 /* ARGSUSED */ 735 static void 736 ObtainResource(XtPointer node_ptr) 737 { 738 ProtocolStream * stream = &(global_client.stream); 739 ObtainResourcesInfo info; 740 WNode * node = (WNode *) node_ptr; 741 char * value; 742 Arg args[1]; 743 744 info.name = GetResourceName(node->resources->res_box); 745 info.class = "IGNORE_ME"; /* Not currently used. */ 746 info.stream = stream; 747 info.count = 1; 748 749 XtSetArg(args[0], (String)XtNlabel, &value); 750 XtGetValues(node->resources->res_box->res_label, args, ONE); 751 752 info.database = NULL; 753 XrmPutLineResource(&(info.database), value); 754 755 _XEditResResetStream(stream); 756 _XEditResPutString8(stream, info.name); /* insert name */ 757 758 /* 759 * Insert the widget count, always 1 760 */ 761 762 _XEditResPut16(stream, 1); 763 764 /*CreateGetValuesCommand(node, (XtPointer)&info); Inserts widget */ 765 766 /* Insert widget */ 767 InsertWidgetFromNode(stream, node); 768 769 SetCommand(node->tree_info->tree_widget, LocalGetValues, NULL); 770 } 771 772 /* Function Name: CreateSetValuesCommand 773 * Description: Creates the SetValues command if this widget 774 * matches the resource string in the database. 775 * Arguments: node - the current node. 776 * info_ptr - the pointer to the apply info. 777 * Returns: none 778 */ 779 780 static void 781 CreateSetValuesCommand(WNode *node, XtPointer info_ptr) 782 { 783 ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr; 784 XrmNameList name_quarks; 785 XrmClassList class_quarks; 786 char ** names, **classes; 787 788 GetNamesAndClasses(node, &names, &classes); 789 name_quarks = (XrmNameList) Quarkify(names, info->name); 790 class_quarks = (XrmNameList) Quarkify(classes, info->class); 791 792 if (CheckDatabase(info->database, name_quarks, class_quarks)) { 793 InsertWidgetFromNode(info->stream, node); 794 info->count++; 795 } 796 797 XtFree((char *)names); 798 XtFree((char *)classes); 799 XtFree((char *)name_quarks); 800 XtFree((char *)class_quarks); 801 } 802 803 /* Function Name: CreateGetValuesCommand 804 * Description: Creates the GetValues command. 805 * Arguments: node - the current node. 806 * info_ptr - the pointer to the apply info. 807 * Returns: none 808 */ 809 810 /***** 811 812 static void 813 CreateGetValuesCommand(WNode *node, XtPointer info_ptr) 814 { 815 ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr; 816 XrmNameList name_quarks; 817 XrmClassList class_quarks; 818 char ** names, **classes; 819 820 GetNamesAndClasses(node, &names, &classes); 821 name_quarks = (XrmNameList) Quarkify(names, info->name); 822 class_quarks = (XrmNameList) Quarkify(classes, info->class); 823 824 if (CheckDatabase(info->database, name_quarks, class_quarks)) { 825 InsertWidgetFromNode(info->stream, node); 826 info->count++; 827 } 828 829 XtFree((char *)names); 830 XtFree((char *)classes); 831 XtFree((char *)name_quarks); 832 XtFree((char *)class_quarks); 833 } 834 835 *****/ 836 837 /* Function Name: ActivateResourceWidgets 838 * Description: Activates all widgets that match this resource. 839 * Arguments: w - UNUSED. 840 * node_ptr - the node that owns this resource box. 841 * junk - UNUSED. 842 * Returns: none. 843 */ 844 845 /* ARGSUSED */ 846 void 847 ActivateResourceWidgets(Widget w, XtPointer node_ptr, XtPointer junk) 848 { 849 WNode * node = (WNode *) node_ptr; 850 ApplyResourcesInfo info; 851 char * line; 852 Arg args[1]; 853 854 info.name = GetResourceName(node->resources->res_box); 855 info.class = "IGNORE_ME"; /* Not currently used. */ 856 857 /* 858 * Unused fields. 859 */ 860 861 info.count = 0; 862 info.stream = NULL; 863 864 XtSetArg(args[0], (String)XtNlabel, &line); 865 XtGetValues(node->resources->res_box->res_label, args, ONE); 866 867 info.database = NULL; 868 XrmPutLineResource(&(info.database), line); 869 870 871 ExecuteOverAllNodes(node->tree_info->top_node, 872 SetOnlyMatchingWidgets, (XtPointer) &info); 873 874 XrmDestroyDatabase(info.database); 875 } 876 877 /* Function Name: SetOnlyMatchingWidgets 878 * Description: Activates all widgets in the tree that match this 879 * resource specification. 880 * Arguments: node - the current node. 881 * info_ptr - the pointer to the apply info. 882 * Returns: none 883 */ 884 885 static void 886 SetOnlyMatchingWidgets(WNode *node, XtPointer info_ptr) 887 { 888 ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr; 889 XrmNameList name_quarks; 890 XrmClassList class_quarks; 891 char ** names, **classes; 892 Boolean state; 893 Arg args[1]; 894 895 GetNamesAndClasses(node, &names, &classes); 896 name_quarks = (XrmNameList) Quarkify(names, info->name); 897 class_quarks = (XrmNameList) Quarkify(classes, info->class); 898 899 state = CheckDatabase(info->database, name_quarks, class_quarks); 900 901 XtSetArg(args[0], (String)XtNstate, state); 902 XtSetValues(node->widget, args, ONE); 903 TreeToggle(node->widget, (XtPointer) node, (XtPointer)(long) state); 904 905 XtFree((char *)names); 906 XtFree((char *)classes); 907 XtFree((char *)name_quarks); 908 XtFree((char *)class_quarks); 909 } 910