133c89af1Smrg/* 233c89af1Smrg * 333c89af1SmrgCopyright 1989, 1998 The Open Group 433c89af1Smrg 533c89af1SmrgPermission to use, copy, modify, distribute, and sell this software and its 633c89af1Smrgdocumentation for any purpose is hereby granted without fee, provided that 733c89af1Smrgthe above copyright notice appear in all copies and that both that 833c89af1Smrgcopyright notice and this permission notice appear in supporting 933c89af1Smrgdocumentation. 1033c89af1Smrg 1133c89af1SmrgThe above copyright notice and this permission notice shall be included in 1233c89af1Smrgall copies or substantial portions of the Software. 1333c89af1Smrg 1433c89af1SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1533c89af1SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1633c89af1SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1733c89af1SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1833c89af1SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1933c89af1SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2033c89af1Smrg 2133c89af1SmrgExcept as contained in this notice, the name of The Open Group shall not be 2233c89af1Smrgused in advertising or otherwise to promote the sale, use or other dealings 2333c89af1Smrgin this Software without prior written authorization from The Open Group. 2433c89af1Smrg */ 2533c89af1Smrg 2633c89af1Smrg 2738d718bdSmrg#ifdef HAVE_CONFIG_H 2838d718bdSmrg# include "config.h" 2938d718bdSmrg#endif 3038d718bdSmrg 3133c89af1Smrg#include <X11/Intrinsic.h> 3233c89af1Smrg#include <X11/StringDefs.h> 3333c89af1Smrg 3433c89af1Smrg#include <X11/Xaw/Cardinals.h> 3533c89af1Smrg#include <X11/Xaw/List.h> 3633c89af1Smrg#include <X11/Xaw/Panner.h> 3733c89af1Smrg#include <X11/Xaw/Toggle.h> 3833c89af1Smrg#include <X11/Xfuncs.h> 3933c89af1Smrg#include <X11/Xos.h> /* for W_OK def */ 4033c89af1Smrg 4133c89af1Smrg#include <stdio.h> 4233c89af1Smrg#include <stdlib.h> 4333c89af1Smrg 4433c89af1Smrg#include "editresP.h" 4533c89af1Smrg 46ad47b356Smrg/* 4733c89af1Smrg * Local function definitions. 4833c89af1Smrg */ 49352bf44eSmrgstatic String GetResourceName ( ResourceBoxInfo * res_box ); 50ad47b356Smrgstatic void _AppendResourceString ( Widget w, XtPointer res_box_ptr, 5133c89af1Smrg XtPointer filename_ptr ); 52ad47b356Smrgstatic void _SetResourcesFile ( Widget w, XtPointer junk, 5333c89af1Smrg XtPointer filename_ptr ); 5433c89af1Smrgstatic void ObtainResource ( XtPointer node_ptr ); 5533c89af1Smrgstatic void CreateSetValuesCommand ( WNode * node, XtPointer info_ptr ); 5633c89af1Smrgstatic void SetOnlyMatchingWidgets ( WNode * node, XtPointer info_ptr ); 5733c89af1Smrg 5833c89af1Smrg/* Function Name: Quit 5933c89af1Smrg * Description: This function prints a message to stdout. 6033c89af1Smrg * Arguments: w - ** UNUSED ** 6133c89af1Smrg * call_data - ** UNUSED ** 6233c89af1Smrg * client_data - ** UNUSED ** 6333c89af1Smrg * Returns: none 6433c89af1Smrg */ 6533c89af1Smrg 6633c89af1Smrg/* ARGSUSED */ 6733c89af1Smrgvoid 68278eca22SmrgQuit(Widget w, XtPointer client_data, XtPointer call_data) 6933c89af1Smrg{ 7033c89af1Smrg XtDestroyApplicationContext(XtWidgetToApplicationContext(w)); 7133c89af1Smrg exit(0); 7233c89af1Smrg} 7333c89af1Smrg 7433c89af1Smrg/* Function Name: SendTree 7533c89af1Smrg * Description: This function initiates the client communication. 7633c89af1Smrg * by getting the resource tree. 7733c89af1Smrg * Arguments: w - the widget that made the selection. 7833c89af1Smrg * value - a boolean value stored as a pointer. 7933c89af1Smrg * if True then get a new client, otherwise 8033c89af1Smrg * refresh the current client. 8133c89af1Smrg * call_data - ** UNUSED ** 8233c89af1Smrg * Returns: none 8333c89af1Smrg */ 8433c89af1Smrg 8533c89af1Smrg/* ARGSUSED */ 8633c89af1Smrgvoid 87278eca22SmrgSendTree(Widget w, XtPointer value, XtPointer call_data) 8833c89af1Smrg{ 8933c89af1Smrg if ((Boolean)(long) value) 9033c89af1Smrg global_client.window = None; 9133c89af1Smrg 9233c89af1Smrg if (!XtIsWidget(w)) /* Make sure that we use a "Real" widget here. */ 9333c89af1Smrg w = XtParent(w); 9433c89af1Smrg 9533c89af1Smrg _XEditResResetStream(&(global_client.stream)); /* an empty message. */ 96ad47b356Smrg 97ad47b356Smrg SetCommand(w, LocalSendWidgetTree, NULL); 9833c89af1Smrg} 9933c89af1Smrg 10033c89af1Smrg/* Function Name: FindWidget 10133c89af1Smrg * Description: Maps a widget in the client to one in the currently 10233c89af1Smrg * displayed widget tree. 10333c89af1Smrg * Arguments: w - the widget that invoked this action. 10433c89af1Smrg * call_data, client_data ** UNUSED ** 10533c89af1Smrg * Returns: none 10633c89af1Smrg */ 10733c89af1Smrg 10833c89af1Smrg/* ARGSUSED */ 10933c89af1Smrgvoid 110278eca22SmrgFindWidget(Widget w, XtPointer client_data, XtPointer call_data) 11133c89af1Smrg{ 11233c89af1Smrg 11333c89af1Smrg _FindWidget(XtParent(w)); /* Use parent since it is a "real" 11433c89af1Smrg widget not a rect_obj. */ 11533c89af1Smrg} 11633c89af1Smrg 11733c89af1Smrg/* Function Name: InitSetValues 11833c89af1Smrg * Description: This function pops up the setvalues dialog 11933c89af1Smrg * Arguments: w - the widget caused this action. 12033c89af1Smrg * call_data - ** UNUSED ** 12133c89af1Smrg * client_data - ** UNUSED ** 12233c89af1Smrg * Returns: none 12333c89af1Smrg */ 12433c89af1Smrg 12533c89af1Smrg/* ARGSUSED */ 12633c89af1Smrgvoid 127278eca22SmrgInitSetValues(Widget w, XtPointer client_data, XtPointer call_data) 12833c89af1Smrg{ 12933c89af1Smrg if (!XtIsWidget(w)) /* Make sure that we use a "Real" widget here. */ 13033c89af1Smrg w = XtParent(w); 13133c89af1Smrg 13233c89af1Smrg PopupSetValues(w, NULL); 13333c89af1Smrg} 13433c89af1Smrg 13533c89af1Smrg/* Function Name: TreeSelect 13633c89af1Smrg * Description: Selects all widgets. 13733c89af1Smrg * Arguments: w - the widget caused this action. 13833c89af1Smrg * call_data - ** UNUSED ** 13933c89af1Smrg * client_data - The type of thing to select. 14033c89af1Smrg * Returns: none 14133c89af1Smrg */ 14233c89af1Smrg 14333c89af1Smrg/* ARGSUSED */ 14433c89af1Smrgvoid 145278eca22SmrgTreeSelect(Widget w, XtPointer client_data, XtPointer call_data) 14633c89af1Smrg{ 14733c89af1Smrg SelectTypes type = (SelectTypes) (unsigned long) client_data; 14833c89af1Smrg 14933c89af1Smrg _TreeSelect(global_tree_info, type); 15033c89af1Smrg} 15133c89af1Smrg 15233c89af1Smrg/* Function Name: TreeRelabel 15333c89af1Smrg * Description: Relabels a tree to the type specified. 15433c89af1Smrg * Arguments: w - the widget caused this action. 15533c89af1Smrg * call_data - ** UNUSED ** 15633c89af1Smrg * client_data - the type of label to assign to each node. 15733c89af1Smrg * Returns: none 15833c89af1Smrg */ 15933c89af1Smrg 16033c89af1Smrg/* ARGSUSED */ 16133c89af1Smrgvoid 162278eca22SmrgTreeRelabel(Widget w, XtPointer client_data, XtPointer call_data) 16333c89af1Smrg{ 16433c89af1Smrg LabelTypes type = (LabelTypes) (unsigned long) client_data; 16533c89af1Smrg 16633c89af1Smrg _TreeRelabel(global_tree_info, type); 16733c89af1Smrg} 16833c89af1Smrg 16933c89af1Smrg/* Function Name: PannerCallback 17033c89af1Smrg * Description: called when the panner has moved. 17133c89af1Smrg * Arguments: panner - the panner widget. 17233c89af1Smrg * closure - *** NOT USED ***. 17333c89af1Smrg * report_ptr - the panner record. 17433c89af1Smrg * Returns: none. 17533c89af1Smrg */ 17633c89af1Smrg 17733c89af1Smrg/* ARGSUSED */ 178ad47b356Smrgvoid 179278eca22SmrgPannerCallback(Widget w, XtPointer closure, XtPointer report_ptr) 18033c89af1Smrg{ 18133c89af1Smrg Arg args[2]; 18233c89af1Smrg XawPannerReport *report = (XawPannerReport *) report_ptr; 18333c89af1Smrg 184ad47b356Smrg if (global_tree_info == NULL) 18533c89af1Smrg return; 18633c89af1Smrg 18738d718bdSmrg XtSetArg (args[0], (String)XtNx, -report->slider_x); 18838d718bdSmrg XtSetArg (args[1], (String)XtNy, -report->slider_y); 18933c89af1Smrg 19033c89af1Smrg XtSetValues(global_tree_info->tree_widget, args, TWO); 19133c89af1Smrg} 19233c89af1Smrg 19333c89af1Smrg/* Function Name: PortholeCallback 19433c89af1Smrg * Description: called when the porthole or its child has 195ad47b356Smrg * changed 19633c89af1Smrg * Arguments: porthole - the porthole widget. 19733c89af1Smrg * panner_ptr - the panner widget. 19833c89af1Smrg * report_ptr - the porthole record. 19933c89af1Smrg * Returns: none. 20033c89af1Smrg */ 20133c89af1Smrg 20233c89af1Smrg/* ARGSUSED */ 203ad47b356Smrgvoid 204278eca22SmrgPortholeCallback(Widget w, XtPointer panner_ptr, XtPointer report_ptr) 20533c89af1Smrg{ 20633c89af1Smrg Arg args[10]; 20733c89af1Smrg Cardinal n = 0; 20833c89af1Smrg XawPannerReport *report = (XawPannerReport *) report_ptr; 20933c89af1Smrg Widget panner = (Widget) panner_ptr; 21033c89af1Smrg 21138d718bdSmrg XtSetArg (args[n], (String)XtNsliderX, report->slider_x); n++; 21238d718bdSmrg XtSetArg (args[n], (String)XtNsliderY, report->slider_y); n++; 21333c89af1Smrg if (report->changed != (XawPRSliderX | XawPRSliderY)) { 21438d718bdSmrg XtSetArg (args[n], (String)XtNsliderWidth, report->slider_width); n++; 21538d718bdSmrg XtSetArg (args[n], (String)XtNsliderHeight, report->slider_height); n++; 21638d718bdSmrg XtSetArg (args[n], (String)XtNcanvasWidth, report->canvas_width); n++; 21738d718bdSmrg XtSetArg (args[n], (String)XtNcanvasHeight, report->canvas_height); n++; 21833c89af1Smrg } 21933c89af1Smrg XtSetValues (panner, args, n); 22033c89af1Smrg} 22133c89af1Smrg 22233c89af1Smrg/* Function Name: FlashActiveWidgets 223352bf44eSmrg * Description: called to flash all active widgets in the display. 22433c89af1Smrg * Arguments: *** NOT USED *** 22533c89af1Smrg * Returns: none. 22633c89af1Smrg */ 22733c89af1Smrg 22833c89af1Smrg/* ARGSUSED */ 229ad47b356Smrgvoid 230278eca22SmrgFlashActiveWidgets(Widget w, XtPointer junk, XtPointer garbage) 23133c89af1Smrg{ 23233c89af1Smrg _FlashActiveWidgets(global_tree_info); 23333c89af1Smrg} 23433c89af1Smrg 23533c89af1Smrg/* Function Name: GetResourceList 23633c89af1Smrg * Description: Gets the resources lists of all active widgets. 23733c89af1Smrg * Arguments: ** NOT USED ** 23833c89af1Smrg * Returns: none 23933c89af1Smrg */ 24033c89af1Smrg 24133c89af1Smrg/* ARGSUSED */ 24233c89af1Smrgvoid 243278eca22SmrgGetResourceList(Widget w, XtPointer junk, XtPointer garbage) 24433c89af1Smrg{ 24533c89af1Smrg WNode * node; 24633c89af1Smrg ProtocolStream * stream = &(global_client.stream); 24733c89af1Smrg 24833c89af1Smrg if (global_tree_info == NULL) { 24933c89af1Smrg SetMessage(global_screen_data.info_label, 25033c89af1Smrg res_labels[17]); 25133c89af1Smrg return; 25233c89af1Smrg } 25333c89af1Smrg 25433c89af1Smrg if (global_tree_info->num_nodes != 1) { 25533c89af1Smrg SetMessage(global_screen_data.info_label, 25633c89af1Smrg res_labels[19]); 25733c89af1Smrg return; 25833c89af1Smrg } 25933c89af1Smrg 26033c89af1Smrg node = global_tree_info->active_nodes[0]; 26133c89af1Smrg if (node->resources != NULL) { 26233c89af1Smrg char * errors = NULL; 26333c89af1Smrg CreateResourceBox(node, &errors); 26433c89af1Smrg if (errors != NULL) { 26533c89af1Smrg SetMessage(global_screen_data.info_label, errors); 26633c89af1Smrg XtFree(errors); 26733c89af1Smrg } 26833c89af1Smrg return; 26933c89af1Smrg } 27033c89af1Smrg 27133c89af1Smrg /* 272352bf44eSmrg * No resources, fetch them from the client. 27333c89af1Smrg */ 27433c89af1Smrg 275ad47b356Smrg _XEditResResetStream(stream); 27633c89af1Smrg _XEditResPut16(stream, (unsigned short) 1); 27733c89af1Smrg InsertWidgetFromNode(stream, node); 27833c89af1Smrg SetCommand(global_tree_info->tree_widget, LocalGetResources, NULL); 27933c89af1Smrg} 28033c89af1Smrg 28133c89af1Smrg/* Function Name: DumpTreeToFile 28233c89af1Smrg * Description: Dumps all widgets in the tree to a file. 28333c89af1Smrg * Arguments: w - the widget that activated this callback. 28433c89af1Smrg * junk, garbage - ** NOT USED **. 28533c89af1Smrg * Returns: none. 28633c89af1Smrg */ 28733c89af1Smrg 28833c89af1Smrg/* ARGSUSED */ 289ad47b356Smrgvoid 290278eca22SmrgDumpTreeToFile(Widget w, XtPointer junk, XtPointer garbage) 29133c89af1Smrg{ 29233c89af1Smrg _PopupFileDialog(XtParent(w), "Enter the filename:", "", 29333c89af1Smrg _DumpTreeToFile, (XtPointer) global_tree_info); 29433c89af1Smrg} 29533c89af1Smrg 29633c89af1Smrg/************************************************************ 297ad47b356Smrg * 29833c89af1Smrg * Callbacks for the Resource Box. 29933c89af1Smrg * 30033c89af1Smrg ************************************************************/ 30133c89af1Smrg 30233c89af1Smrg 30333c89af1Smrg/* Function Name: AnyChosen 304ad47b356Smrg * Description: Callback that is called when the "any" widget 30533c89af1Smrg * is activated. 30633c89af1Smrg * Arguments: w - the "any" widget that activated this callback. 307ad47b356Smrg * any_info_ptr - pointer to struct containing 30833c89af1Smrg * dot and star widgets to lock. 30933c89af1Smrg * state_ptr - state of the any toggle. 31033c89af1Smrg * Returns: none. 31133c89af1Smrg */ 31233c89af1Smrg 31333c89af1Smrg/* ARGSUSED */ 314ad47b356Smrgvoid 315278eca22SmrgAnyChosen(Widget w, XtPointer any_info_ptr, XtPointer state_ptr) 31633c89af1Smrg{ 31733c89af1Smrg AnyInfo * any_info = (AnyInfo *) any_info_ptr; 31833c89af1Smrg Boolean state = (Boolean)(long) state_ptr; 31933c89af1Smrg Arg args[1]; 32033c89af1Smrg 32133c89af1Smrg if (state) { 32233c89af1Smrg 32333c89af1Smrg if (any_info->left_count == 0) { 32433c89af1Smrg XtSetSensitive(any_info->left_dot, FALSE); 32533c89af1Smrg XtSetSensitive(any_info->left_star, FALSE); 32633c89af1Smrg 32738d718bdSmrg XtSetArg(args[0], (String)XtNstate, TRUE); 32833c89af1Smrg XtSetValues(any_info->left_star, args, ONE); 32933c89af1Smrg } 33033c89af1Smrg 33133c89af1Smrg if ((any_info->right_count == NULL)||(*any_info->right_count == 0)) { 33233c89af1Smrg XtSetSensitive(any_info->right_dot, FALSE); 33333c89af1Smrg XtSetSensitive(any_info->right_star, FALSE); 33433c89af1Smrg 33538d718bdSmrg XtSetArg(args[0], (String)XtNstate, TRUE); 33633c89af1Smrg XtSetValues(any_info->right_star, args, ONE); 33733c89af1Smrg } 33833c89af1Smrg any_info->left_count++; 33933c89af1Smrg 34033c89af1Smrg if (any_info->right_count != NULL) 34133c89af1Smrg (*any_info->right_count)++; 34233c89af1Smrg } 34333c89af1Smrg else { /* state == 0 */ 344ad47b356Smrg if (any_info->left_count > 0) 34533c89af1Smrg any_info->left_count--; 346ad47b356Smrg if ((any_info->right_count != NULL)&&(*any_info->right_count > 0)) 34733c89af1Smrg (*any_info->right_count)--; 34833c89af1Smrg 34933c89af1Smrg if (any_info->left_count == 0) { 35033c89af1Smrg XtSetSensitive(any_info->left_dot, TRUE); 35133c89af1Smrg XtSetSensitive(any_info->left_star, TRUE); 35233c89af1Smrg 35338d718bdSmrg XtSetArg(args[0], (String)XtNstate, TRUE); 35433c89af1Smrg XtSetValues(any_info->left_dot, args, ONE); 35533c89af1Smrg } 35633c89af1Smrg 35733c89af1Smrg if ((any_info->right_count == NULL)||(*any_info->right_count == 0)) { 35833c89af1Smrg XtSetSensitive(any_info->right_dot, TRUE); 35933c89af1Smrg XtSetSensitive(any_info->right_star, TRUE); 36033c89af1Smrg 36138d718bdSmrg XtSetArg(args[0], (String)XtNstate, TRUE); 36233c89af1Smrg XtSetValues(any_info->right_dot, args, ONE); 36333c89af1Smrg } 36433c89af1Smrg } 36533c89af1Smrg SetResourceString(NULL, (XtPointer) any_info->node, NULL); 36633c89af1Smrg ActivateResourceWidgets(NULL, (XtPointer) any_info->node, NULL); 36733c89af1Smrg} 36833c89af1Smrg 36933c89af1Smrg/* Function Name: GetResourceName 37033c89af1Smrg * Description: Gets the name of the current resource. 37133c89af1Smrg * Arguments: res_box - the resource box. 37233c89af1Smrg * Returns: the name of the currently selected resource. 37333c89af1Smrg */ 37433c89af1Smrg 37533c89af1Smrg 376352bf44eSmrgstatic String 377278eca22SmrgGetResourceName(ResourceBoxInfo *res_box) 37833c89af1Smrg{ 37933c89af1Smrg XawListReturnStruct * list_info; 380352bf44eSmrg String result; 381ad47b356Smrg 38233c89af1Smrg list_info = XawListShowCurrent(res_box->norm_list); 383ad47b356Smrg if ((list_info->list_index == XAW_LIST_NONE) && 38433c89af1Smrg (res_box->cons_list != NULL)) { 38533c89af1Smrg list_info = XawListShowCurrent(res_box->cons_list); 38633c89af1Smrg } 38733c89af1Smrg 388ad47b356Smrg if (list_info->list_index == XAW_LIST_NONE) 38938d718bdSmrg result = (String)"unknown"; 39033c89af1Smrg else 391ad47b356Smrg result = list_info->string; 39233c89af1Smrg 39333c89af1Smrg return(result); 39433c89af1Smrg} 39533c89af1Smrg 39633c89af1Smrg 39733c89af1Smrg/* Function Name: ActivateWidgetsAndSetResourceString 39833c89af1Smrg * Description: Sets the new resources string, then 39933c89af1Smrg * activates all widgets that match this resource, 40033c89af1Smrg * Arguments: w - the widget that activated this. 40133c89af1Smrg * node_ptr - the node that owns this resource box. 40233c89af1Smrg * call_data - passed on to other callbacks. 40333c89af1Smrg * Returns: none. 40433c89af1Smrg * 40533c89af1Smrg * NOTE: I cannot just have two callback routines, since I care which 40633c89af1Smrg * order that these are executed in, sigh... 40733c89af1Smrg */ 40833c89af1Smrg 40933c89af1Smrgvoid 410278eca22SmrgActivateWidgetsAndSetResourceString(Widget w, 411278eca22Smrg XtPointer node_ptr, XtPointer call_data) 41233c89af1Smrg{ 41333c89af1Smrg SetResourceString(w, node_ptr, call_data); 41433c89af1Smrg ActivateResourceWidgets(w, node_ptr, call_data); 41533c89af1Smrg} 41633c89af1Smrg 41733c89af1Smrg/* Function Name: SetResourceString 41833c89af1Smrg * Description: Sets the resource label to correspond to the currently 41933c89af1Smrg * chosen string. 42033c89af1Smrg * Arguments: w - The widget that invoked this callback, or NULL. 421352bf44eSmrg * node_ptr - pointer to widget node containing this res box. 42233c89af1Smrg * call_data - The call data for the action that invoked 42333c89af1Smrg * this callback. 42433c89af1Smrg * Returns: none. 42533c89af1Smrg */ 42633c89af1Smrg 42733c89af1Smrgvoid 428278eca22SmrgSetResourceString(Widget w, XtPointer node_ptr, XtPointer junk) 42933c89af1Smrg{ 43033c89af1Smrg static char * malloc_string; /* These are both inited to zero. */ 43133c89af1Smrg static Cardinal malloc_size; 43233c89af1Smrg 43333c89af1Smrg WNode * node = (WNode *) node_ptr; 43433c89af1Smrg ResourceBoxInfo * res_box = node->resources->res_box; 43533c89af1Smrg char * temp, buf[BUFSIZ * 10]; /* here's hoping it's big enough. */ 43633c89af1Smrg NameInfo * name_node = res_box->name_info; 43733c89af1Smrg Arg args[1]; 438ad47b356Smrg Cardinal len; 43933c89af1Smrg 44033c89af1Smrg if ((w != NULL) && XtIsSubclass(w, toggleWidgetClass)) { 44133c89af1Smrg /* 44233c89af1Smrg * Only set resources when toggles are activated, not when they are 443ad47b356Smrg * deactivated. 44433c89af1Smrg */ 44533c89af1Smrg if (!((Boolean)(long) junk)) 44633c89af1Smrg return; 44733c89af1Smrg } 44833c89af1Smrg 44933c89af1Smrg buf[0] = '\0'; /* clear out string. */ 45033c89af1Smrg 45133c89af1Smrg /* 45233c89af1Smrg * Get the widget name/class info. 45333c89af1Smrg */ 45433c89af1Smrg 45533c89af1Smrg if ((temp = (char *) XawToggleGetCurrent(name_node->sep_leader)) != NULL) 45633c89af1Smrg strcat(buf, temp); 45733c89af1Smrg 45833c89af1Smrg for ( ; name_node->next != NULL ; name_node = name_node->next) { 45933c89af1Smrg temp = (char *) XawToggleGetCurrent(name_node->name_leader); 46033c89af1Smrg if ( (temp != NULL) && !streq(temp, ANY_RADIO_DATA) ) { 46133c89af1Smrg strcat(buf, temp); 46233c89af1Smrg temp = (char *) XawToggleGetCurrent(name_node->next->sep_leader); 463ad47b356Smrg if (temp == NULL) 46433c89af1Smrg strcat(buf, "!"); 46533c89af1Smrg else 46633c89af1Smrg strcat(buf, temp); 46733c89af1Smrg } 46833c89af1Smrg } 469ad47b356Smrg 47033c89af1Smrg strcat(buf, GetResourceName(res_box)); 47133c89af1Smrg len = strlen(buf) + 2; /* Leave space for ':' and '\0' */ 47233c89af1Smrg 47333c89af1Smrg#ifdef notdef 47438d718bdSmrg XtSetArg(args[0], (String)XtNstring, &temp); 47533c89af1Smrg XtGetValues(res_box->value_wid, args, ONE); 47633c89af1Smrg len += strlen(temp); 47733c89af1Smrg#endif 47833c89af1Smrg 47933c89af1Smrg if (len > malloc_size) { 48033c89af1Smrg malloc_string = XtRealloc(malloc_string, sizeof(char) * len); 48133c89af1Smrg malloc_size = len; 48233c89af1Smrg } 483ad47b356Smrg 48433c89af1Smrg strcpy(malloc_string, buf); 48533c89af1Smrg strcat(malloc_string, ":"); 48633c89af1Smrg#ifdef notdef 48733c89af1Smrg strcat(malloc_string, temp); 48833c89af1Smrg#endif 48933c89af1Smrg 49038d718bdSmrg XtSetArg(args[0], (String)XtNlabel, malloc_string); 49133c89af1Smrg XtSetValues(res_box->res_label, args, ONE); 49233c89af1Smrg} 493ad47b356Smrg 49433c89af1Smrg/* Function Name: ResourceListCallback 495ad47b356Smrg * Description: Callback functions for the resource lists. This 496352bf44eSmrg * routine is essentially called by the list widgets 49733c89af1Smrg * Notify action. If action EnableGetVal has been 49833c89af1Smrg * invoked, ResourceListCallback will perform a 49933c89af1Smrg * GetValues protocol request. 50033c89af1Smrg * Arguments: list - the list widget that we are dealing with. 501352bf44eSmrg * node_ptr - pointer to widget node containing this res box. 50233c89af1Smrg * junk - UNUSED. 50333c89af1Smrg * Returns: none 50433c89af1Smrg */ 50533c89af1Smrg 50633c89af1Smrgvoid 507278eca22SmrgResourceListCallback(Widget list, XtPointer node_ptr, XtPointer junk) 50833c89af1Smrg{ 50933c89af1Smrg Widget o_list; 51033c89af1Smrg WNode * node = (WNode *) node_ptr; 51133c89af1Smrg ResourceBoxInfo * res_box = node->resources->res_box; 51233c89af1Smrg 513ad47b356Smrg if (list == res_box->norm_list) 51433c89af1Smrg o_list = res_box->cons_list; 51533c89af1Smrg else 51633c89af1Smrg o_list = res_box->norm_list; 51733c89af1Smrg 51833c89af1Smrg if (o_list != NULL) 51933c89af1Smrg XawListUnhighlight(o_list); 52033c89af1Smrg 52133c89af1Smrg SetResourceString(list, node_ptr, junk); 52233c89af1Smrg 52333c89af1Smrg /* get the resource value from the application */ 52433c89af1Smrg if (global_effective_protocol_version >= 52533c89af1Smrg PROTOCOL_VERSION_ONE_POINT_ONE && do_get_values) { 52633c89af1Smrg ObtainResource(node_ptr); 52733c89af1Smrg do_get_values = False; 52833c89af1Smrg } 52933c89af1Smrg} 53033c89af1Smrg 53133c89af1Smrg/* Function Name: PopdownResBox 53233c89af1Smrg * Description: Pops down the resource box. 53333c89af1Smrg * Arguments: w - UNUSED 53433c89af1Smrg * shell_ptr - pointer to the shell to pop down. 53533c89af1Smrg * junk - UNUSED. 53633c89af1Smrg * Returns: none 53733c89af1Smrg */ 53833c89af1Smrg 53933c89af1Smrg/* ARGSUSED */ 54033c89af1Smrgvoid 541278eca22SmrgPopdownResBox(Widget w, XtPointer shell_ptr, XtPointer junk) 54233c89af1Smrg{ 54333c89af1Smrg Widget shell = (Widget) shell_ptr; 54433c89af1Smrg 54533c89af1Smrg XtPopdown(shell); 54633c89af1Smrg XtDestroyWidget(shell); 54733c89af1Smrg} 54833c89af1Smrg 54933c89af1Smrg/* ARGSUSED */ 55033c89af1Smrgstatic void 551278eca22Smrg_AppendResourceString(Widget w, XtPointer res_box_ptr, XtPointer filename_ptr) 55233c89af1Smrg{ 55333c89af1Smrg Arg args[1]; 55433c89af1Smrg FILE * fp; 55533c89af1Smrg char buf[BUFSIZ], * resource_string, *filename = (char *) filename_ptr; 55633c89af1Smrg ResourceBoxInfo * res_box = (ResourceBoxInfo *) res_box_ptr; 55733c89af1Smrg char *value_ptr; 55833c89af1Smrg 55933c89af1Smrg if (filename != NULL) { 560ad47b356Smrg if (global_resources.allocated_save_resources_file) 56133c89af1Smrg XtFree(global_resources.save_resources_file); 56233c89af1Smrg else 56333c89af1Smrg global_resources.allocated_save_resources_file = TRUE; 564ad47b356Smrg 56533c89af1Smrg global_resources.save_resources_file = XtNewString(filename); 56633c89af1Smrg } 56733c89af1Smrg 56833c89af1Smrg if ((fp = fopen(global_resources.save_resources_file, "a+")) == NULL) { 569ad47b356Smrg snprintf(buf, sizeof(buf), "%s", 570ad47b356Smrg "Unable to open this file for writing, would " 571ad47b356Smrg "you like To try again?"); 57233c89af1Smrg _PopupFileDialog(global_toplevel ,buf, 57333c89af1Smrg global_resources.save_resources_file, 57433c89af1Smrg _AppendResourceString, res_box_ptr); 57533c89af1Smrg return; 57633c89af1Smrg } 57733c89af1Smrg 57838d718bdSmrg XtSetArg(args[0], (String)XtNlabel, &resource_string); 57933c89af1Smrg XtGetValues(res_box->res_label, args, ONE); 58033c89af1Smrg 58138d718bdSmrg XtSetArg(args[0], (String)XtNstring, &value_ptr); 58233c89af1Smrg XtGetValues(res_box->value_wid, args, ONE); 58333c89af1Smrg 58433c89af1Smrg fprintf(fp, "%s %s\n", resource_string, value_ptr); 58533c89af1Smrg 58633c89af1Smrg fclose(fp); 58733c89af1Smrg} 58833c89af1Smrg 58933c89af1Smrg/* Function Name: SaveResource 59033c89af1Smrg * Description: Save the current resource to your resource file 59133c89af1Smrg * Arguments: w - any widget in the application. 59233c89af1Smrg * res_box_ptr - the resource box info. 59333c89af1Smrg * junk - UNUSED. 59433c89af1Smrg * Returns: none 59533c89af1Smrg */ 59633c89af1Smrg 59733c89af1Smrg/* ARGSUSED */ 59833c89af1Smrgvoid 599278eca22SmrgSaveResource(Widget w, XtPointer res_box_ptr, XtPointer junk) 60033c89af1Smrg{ 601ad47b356Smrg /* 60233c89af1Smrg * If there is no filename the ask for one, otherwise just save to 60333c89af1Smrg * current file. 60433c89af1Smrg */ 60533c89af1Smrg 60633c89af1Smrg if (streq(global_resources.save_resources_file, "")) 60733c89af1Smrg _PopupFileDialog(XtParent(w), "Enter file to dump resources into:", 60833c89af1Smrg global_resources.save_resources_file, 60933c89af1Smrg _AppendResourceString, res_box_ptr); 61033c89af1Smrg else 61133c89af1Smrg _AppendResourceString(w, res_box_ptr, NULL); 61233c89af1Smrg} 61333c89af1Smrg 61433c89af1Smrg/* Function Name: _SetResourcesFile 61533c89af1Smrg * Description: Sets the filename of the file to save the resources to. 61633c89af1Smrg * Arguments: w - UNUSED 61733c89af1Smrg * junk - UNUSED 61833c89af1Smrg * filename_ptr - a pointer to the filename; 61933c89af1Smrg * Returns: none 62033c89af1Smrg */ 62133c89af1Smrg 62233c89af1Smrg/* ARGSUSED */ 62333c89af1Smrgstatic void 624278eca22Smrg_SetResourcesFile(Widget w, XtPointer junk, XtPointer filename_ptr) 62533c89af1Smrg{ 62633c89af1Smrg char *filename = (char *) filename_ptr; 62733c89af1Smrg 628ad47b356Smrg if (global_resources.allocated_save_resources_file) 62933c89af1Smrg XtFree(global_resources.save_resources_file); 63033c89af1Smrg else 63133c89af1Smrg global_resources.allocated_save_resources_file = TRUE; 63233c89af1Smrg 63333c89af1Smrg global_resources.save_resources_file = XtNewString(filename); 63433c89af1Smrg} 63533c89af1Smrg 63633c89af1Smrg/* Function Name: SetFile 63733c89af1Smrg * Description: Changes the current save file 63833c89af1Smrg * Arguments: w - UNUSED. 63933c89af1Smrg * res_box_ptr - UNUSED. 64033c89af1Smrg * junk - UNUSED. 64133c89af1Smrg * Returns: none 64233c89af1Smrg */ 64333c89af1Smrg 64433c89af1Smrg/* ARGSUSED */ 64533c89af1Smrgvoid 646278eca22SmrgSetFile(Widget w, XtPointer junk, XtPointer garbage) 64733c89af1Smrg{ 648ad47b356Smrg /* 64933c89af1Smrg * If there is no filename the ask for one, otherwise just save to 65033c89af1Smrg * current file. 65133c89af1Smrg */ 65233c89af1Smrg 65333c89af1Smrg _PopupFileDialog(XtParent(w), "Enter file to dump resources into:", 65433c89af1Smrg global_resources.save_resources_file, 65533c89af1Smrg _SetResourcesFile, NULL); 65633c89af1Smrg} 65733c89af1Smrg 65833c89af1Smrg/* Function Name: ApplyResource 65933c89af1Smrg * Description: Apply the current resource to the running application. 66033c89af1Smrg * Arguments: w - any widget in the application. 661ad47b356Smrg * node_ptr - a pointer to the node containing 662352bf44eSmrg * the current resource box. 66333c89af1Smrg * junk - UNUSED. 66433c89af1Smrg * Returns: none 66533c89af1Smrg */ 66633c89af1Smrg 66733c89af1Smrg/* ARGSUSED */ 66833c89af1Smrgvoid 669278eca22SmrgApplyResource(Widget w, XtPointer node_ptr, XtPointer junk) 67033c89af1Smrg{ 67133c89af1Smrg ProtocolStream * stream = &(global_client.stream); 67233c89af1Smrg ApplyResourcesInfo info; 673ad47b356Smrg WNode * node = (WNode *) node_ptr; 67433c89af1Smrg char * value; 67533c89af1Smrg unsigned short size, i; 67633c89af1Smrg long len; 67733c89af1Smrg Arg args[1]; 67833c89af1Smrg 67933c89af1Smrg info.name = GetResourceName(node->resources->res_box); 68033c89af1Smrg info.class = "IGNORE_ME"; /* Not currently used. */ 68133c89af1Smrg info.stream = stream; 68233c89af1Smrg info.count = 0; 68333c89af1Smrg 68438d718bdSmrg XtSetArg(args[0], (String)XtNlabel, &value); 68533c89af1Smrg XtGetValues(node->resources->res_box->res_label, args, ONE); 68633c89af1Smrg 68733c89af1Smrg info.database = NULL; 68833c89af1Smrg XrmPutLineResource(&(info.database), value); 68933c89af1Smrg 69033c89af1Smrg 69133c89af1Smrg _XEditResResetStream(stream); 69233c89af1Smrg _XEditResPutString8(stream, info.name); /* Insert name */ 69333c89af1Smrg _XEditResPutString8(stream, XtRString); /* insert type */ 69433c89af1Smrg 69533c89af1Smrg /* 69633c89af1Smrg * Insert value. 69733c89af1Smrg */ 69833c89af1Smrg 69933c89af1Smrg value = GetResourceValueForSetValues(node, &size); 700ad47b356Smrg _XEditResPut16(stream, size); 701ad47b356Smrg for (i = 0; i < size; i++) 70233c89af1Smrg _XEditResPut8(stream, value[i]); 70333c89af1Smrg XtFree(value); 70433c89af1Smrg len = stream->current - stream->top; 70533c89af1Smrg 706ad47b356Smrg /* 707352bf44eSmrg * Insert the widget count, overridden later. 70833c89af1Smrg */ 70933c89af1Smrg 710ad47b356Smrg _XEditResPut16(stream, 0); 71133c89af1Smrg 71233c89af1Smrg ExecuteOverAllNodes(node->tree_info->top_node, 71333c89af1Smrg CreateSetValuesCommand, (XtPointer) &info); 714ad47b356Smrg 71533c89af1Smrg if (info.count > 0) { 71633c89af1Smrg *(stream->top + len++) = info.count >> XER_NBBY; /* Set the correct */ 71733c89af1Smrg *(stream->top + len) = info.count; /* count. */ 71833c89af1Smrg 71933c89af1Smrg SetCommand(node->tree_info->tree_widget, LocalSetValues, NULL); 72033c89af1Smrg } 721ad47b356Smrg else 72233c89af1Smrg SetMessage(global_screen_data.info_label, 72333c89af1Smrg res_labels[20]); 724ad47b356Smrg 72533c89af1Smrg XrmDestroyDatabase(info.database); 72633c89af1Smrg} 72733c89af1Smrg 72833c89af1Smrg/* Function Name: ObtainResource 72933c89af1Smrg * Description: Obtain the current resource from the running application. 730ad47b356Smrg * Arguments: node_ptr - a pointer to the node containing 731352bf44eSmrg * the current resource box. 73233c89af1Smrg * Returns: none 73333c89af1Smrg */ 73433c89af1Smrg 73533c89af1Smrg/* ARGSUSED */ 73633c89af1Smrgstatic void 737278eca22SmrgObtainResource(XtPointer node_ptr) 73833c89af1Smrg{ 73933c89af1Smrg ProtocolStream * stream = &(global_client.stream); 74033c89af1Smrg ObtainResourcesInfo info; 741ad47b356Smrg WNode * node = (WNode *) node_ptr; 74233c89af1Smrg char * value; 74333c89af1Smrg Arg args[1]; 74433c89af1Smrg 74533c89af1Smrg info.name = GetResourceName(node->resources->res_box); 74633c89af1Smrg info.class = "IGNORE_ME"; /* Not currently used. */ 74733c89af1Smrg info.stream = stream; 74833c89af1Smrg info.count = 1; 74933c89af1Smrg 75038d718bdSmrg XtSetArg(args[0], (String)XtNlabel, &value); 75133c89af1Smrg XtGetValues(node->resources->res_box->res_label, args, ONE); 75233c89af1Smrg 75333c89af1Smrg info.database = NULL; 75433c89af1Smrg XrmPutLineResource(&(info.database), value); 75533c89af1Smrg 75633c89af1Smrg _XEditResResetStream(stream); 75733c89af1Smrg _XEditResPutString8(stream, info.name); /* insert name */ 75833c89af1Smrg 759ad47b356Smrg /* 76033c89af1Smrg * Insert the widget count, always 1 76133c89af1Smrg */ 76233c89af1Smrg 763ad47b356Smrg _XEditResPut16(stream, 1); 76433c89af1Smrg 76533c89af1Smrg /*CreateGetValuesCommand(node, (XtPointer)&info); Inserts widget */ 76633c89af1Smrg 76733c89af1Smrg /* Insert widget */ 76833c89af1Smrg InsertWidgetFromNode(stream, node); 76933c89af1Smrg 77033c89af1Smrg SetCommand(node->tree_info->tree_widget, LocalGetValues, NULL); 77133c89af1Smrg} 77233c89af1Smrg 77333c89af1Smrg/* Function Name: CreateSetValuesCommand 77433c89af1Smrg * Description: Creates the SetValues command if this widget 77533c89af1Smrg * matches the resource string in the database. 77633c89af1Smrg * Arguments: node - the current node. 77733c89af1Smrg * info_ptr - the pointer to the apply info. 77833c89af1Smrg * Returns: none 77933c89af1Smrg */ 78033c89af1Smrg 78133c89af1Smrgstatic void 782278eca22SmrgCreateSetValuesCommand(WNode *node, XtPointer info_ptr) 78333c89af1Smrg{ 78433c89af1Smrg ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr; 78533c89af1Smrg XrmNameList name_quarks; 78633c89af1Smrg XrmClassList class_quarks; 78733c89af1Smrg char ** names, **classes; 78833c89af1Smrg 78933c89af1Smrg GetNamesAndClasses(node, &names, &classes); 79033c89af1Smrg name_quarks = (XrmNameList) Quarkify(names, info->name); 79133c89af1Smrg class_quarks = (XrmNameList) Quarkify(classes, info->class); 79233c89af1Smrg 79333c89af1Smrg if (CheckDatabase(info->database, name_quarks, class_quarks)) { 79433c89af1Smrg InsertWidgetFromNode(info->stream, node); 79533c89af1Smrg info->count++; 79633c89af1Smrg } 79733c89af1Smrg 79833c89af1Smrg XtFree((char *)names); 79933c89af1Smrg XtFree((char *)classes); 80033c89af1Smrg XtFree((char *)name_quarks); 80133c89af1Smrg XtFree((char *)class_quarks); 80233c89af1Smrg} 80333c89af1Smrg 80433c89af1Smrg/* Function Name: CreateGetValuesCommand 80533c89af1Smrg * Description: Creates the GetValues command. 80633c89af1Smrg * Arguments: node - the current node. 80733c89af1Smrg * info_ptr - the pointer to the apply info. 80833c89af1Smrg * Returns: none 80933c89af1Smrg */ 81033c89af1Smrg 81133c89af1Smrg/***** 81233c89af1Smrg 81333c89af1Smrgstatic void 814278eca22SmrgCreateGetValuesCommand(WNode *node, XtPointer info_ptr) 81533c89af1Smrg{ 81633c89af1Smrg ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr; 81733c89af1Smrg XrmNameList name_quarks; 81833c89af1Smrg XrmClassList class_quarks; 81933c89af1Smrg char ** names, **classes; 82033c89af1Smrg 82133c89af1Smrg GetNamesAndClasses(node, &names, &classes); 82233c89af1Smrg name_quarks = (XrmNameList) Quarkify(names, info->name); 82333c89af1Smrg class_quarks = (XrmNameList) Quarkify(classes, info->class); 82433c89af1Smrg 82533c89af1Smrg if (CheckDatabase(info->database, name_quarks, class_quarks)) { 82633c89af1Smrg InsertWidgetFromNode(info->stream, node); 82733c89af1Smrg info->count++; 82833c89af1Smrg } 82933c89af1Smrg 83033c89af1Smrg XtFree((char *)names); 83133c89af1Smrg XtFree((char *)classes); 83233c89af1Smrg XtFree((char *)name_quarks); 83333c89af1Smrg XtFree((char *)class_quarks); 83433c89af1Smrg} 83533c89af1Smrg 83633c89af1Smrg*****/ 83733c89af1Smrg 83833c89af1Smrg/* Function Name: ActivateResourceWidgets 83933c89af1Smrg * Description: Activates all widgets that match this resource. 84033c89af1Smrg * Arguments: w - UNUSED. 84133c89af1Smrg * node_ptr - the node that owns this resource box. 842ad47b356Smrg * junk - UNUSED. 84333c89af1Smrg * Returns: none. 84433c89af1Smrg */ 84533c89af1Smrg 84633c89af1Smrg/* ARGSUSED */ 84733c89af1Smrgvoid 848278eca22SmrgActivateResourceWidgets(Widget w, XtPointer node_ptr, XtPointer junk) 84933c89af1Smrg{ 850ad47b356Smrg WNode * node = (WNode *) node_ptr; 85133c89af1Smrg ApplyResourcesInfo info; 85233c89af1Smrg char * line; 85333c89af1Smrg Arg args[1]; 85433c89af1Smrg 85533c89af1Smrg info.name = GetResourceName(node->resources->res_box); 85633c89af1Smrg info.class = "IGNORE_ME"; /* Not currently used. */ 85733c89af1Smrg 858ad47b356Smrg /* 85933c89af1Smrg * Unused fields. 86033c89af1Smrg */ 86133c89af1Smrg 86233c89af1Smrg info.count = 0; 86333c89af1Smrg info.stream = NULL; 86433c89af1Smrg 86538d718bdSmrg XtSetArg(args[0], (String)XtNlabel, &line); 86633c89af1Smrg XtGetValues(node->resources->res_box->res_label, args, ONE); 86733c89af1Smrg 86833c89af1Smrg info.database = NULL; 86933c89af1Smrg XrmPutLineResource(&(info.database), line); 87033c89af1Smrg 87133c89af1Smrg 87233c89af1Smrg ExecuteOverAllNodes(node->tree_info->top_node, 87333c89af1Smrg SetOnlyMatchingWidgets, (XtPointer) &info); 874ad47b356Smrg 87533c89af1Smrg XrmDestroyDatabase(info.database); 87633c89af1Smrg} 87733c89af1Smrg 87833c89af1Smrg/* Function Name: SetOnlyMatchingWidgets 87933c89af1Smrg * Description: Activates all widgets in the tree that match this 880352bf44eSmrg * resource specification. 88133c89af1Smrg * Arguments: node - the current node. 88233c89af1Smrg * info_ptr - the pointer to the apply info. 88333c89af1Smrg * Returns: none 88433c89af1Smrg */ 88533c89af1Smrg 88633c89af1Smrgstatic void 887278eca22SmrgSetOnlyMatchingWidgets(WNode *node, XtPointer info_ptr) 88833c89af1Smrg{ 88933c89af1Smrg ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr; 89033c89af1Smrg XrmNameList name_quarks; 89133c89af1Smrg XrmClassList class_quarks; 89233c89af1Smrg char ** names, **classes; 89333c89af1Smrg Boolean state; 89433c89af1Smrg Arg args[1]; 89533c89af1Smrg 89633c89af1Smrg GetNamesAndClasses(node, &names, &classes); 89733c89af1Smrg name_quarks = (XrmNameList) Quarkify(names, info->name); 89833c89af1Smrg class_quarks = (XrmNameList) Quarkify(classes, info->class); 89933c89af1Smrg 90033c89af1Smrg state = CheckDatabase(info->database, name_quarks, class_quarks); 90133c89af1Smrg 90238d718bdSmrg XtSetArg(args[0], (String)XtNstate, state); 90333c89af1Smrg XtSetValues(node->widget, args, ONE); 90433c89af1Smrg TreeToggle(node->widget, (XtPointer) node, (XtPointer)(long) state); 90533c89af1Smrg 90633c89af1Smrg XtFree((char *)names); 90733c89af1Smrg XtFree((char *)classes); 90833c89af1Smrg XtFree((char *)name_quarks); 90933c89af1Smrg XtFree((char *)class_quarks); 91033c89af1Smrg} 911