setvalues.c revision 38d718bd
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 * Author: Chris D. Peterson, MIT X Consortium 26 */ 27 28#ifdef HAVE_CONFIG_H 29# include "config.h" 30#endif 31 32#include <X11/Intrinsic.h> 33#include <X11/StringDefs.h> 34#include <X11/Xresource.h> 35 36#include <stdio.h> 37 38#include <X11/Xaw/AsciiText.h> 39#include <X11/Xaw/Cardinals.h> 40#include <X11/Xfuncs.h> 41#include <X11/Xos.h> 42#include "editresP.h" 43 44#define RESOURCE_NAME ("name") 45#define RESOURCE_CLASS ("Class") 46 47/* Function Name: PrintSetValuesError 48 * Description: Allow the SetValues error to be printed. 49 * Arguments: event - the set values call that caused this event. 50 * Returns: str - a string contining the errors. 51 */ 52 53char * 54PrintSetValuesError(Event *event) 55{ 56 char * errors = NULL; 57 WNode * node; 58 int i; 59 SetValuesEvent * sv_event = (SetValuesEvent *) event; 60 char buf[BUFSIZ]; 61 62 if (sv_event->num_entries == 0) 63 return(XtNewString("SetValues was Successful.")); 64 65 for (i = 0 ; i < (int)sv_event->num_entries ; i++) { 66 node = FindNode(global_tree_info->top_node, 67 sv_event->info[i].widgets.ids, 68 sv_event->info[i].widgets.num_widgets); 69 70 if (node == NULL) { 71 snprintf(buf, sizeof(buf), 72 "Editres Internal Error: Unable to FindNode.\n"); 73 AddString(&errors, buf); 74 continue; 75 } 76 77 snprintf(buf, sizeof(buf), "%s(0x%lx) - %s\n", node->name, node->id, 78 sv_event->info[i].message); 79 AddString(&errors, buf); 80 } 81 return(errors); 82} 83 84/* Function Name: GetResourceValueForSetValues(node); 85 * Description: Returns the value that should be sent to SetValues. 86 * Arguments: node - the node which contains the resource box. 87 * Returns: value - allocated value. 88 */ 89 90char * 91GetResourceValueForSetValues(WNode *node, unsigned short *size) 92{ 93 Arg args[1]; 94 char *ptr, *temp; 95 XrmDatabase db = NULL; 96 XrmValue value; 97 98 XtSetArg(args[0], XtNstring, &ptr); 99 XtGetValues(node->resources->res_box->value_wid, args, ONE); 100 101 /* 102 * This makes sure that exactly the same thing happens during a set 103 * values, that would happen if we were to insert this value into 104 * the resource database. 105 */ 106 107 XtAsprintf(&temp, "%s:%s", RESOURCE_NAME, ptr); 108 XrmPutLineResource(&db, temp); 109 XtFree(temp); 110 111 XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value); 112 113 ptr = XtMalloc(sizeof(char) * value.size); 114 memmove( ptr, value.addr, value.size); 115 XrmDestroyDatabase(db); 116 117 *size = (unsigned short) value.size; 118 return(ptr); 119} 120