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