setvalues.c revision 278eca22
1706f2543Smrg/* 2706f2543Smrg * $Xorg: setvalues.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ 3706f2543Smrg * 4706f2543SmrgCopyright 1989, 1998 The Open Group 5706f2543Smrg 6706f2543SmrgPermission to use, copy, modify, distribute, and sell this software and its 7706f2543Smrgdocumentation for any purpose is hereby granted without fee, provided that 8706f2543Smrgthe above copyright notice appear in all copies and that both that 9706f2543Smrgcopyright notice and this permission notice appear in supporting 10706f2543Smrgdocumentation. 11706f2543Smrg 12706f2543SmrgThe above copyright notice and this permission notice shall be included in 13706f2543Smrgall copies or substantial portions of the Software. 14706f2543Smrg 15706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18706f2543SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19706f2543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20706f2543SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21706f2543Smrg 22706f2543SmrgExcept as contained in this notice, the name of The Open Group shall not be 23706f2543Smrgused in advertising or otherwise to promote the sale, use or other dealings 24706f2543Smrgin this Software without prior written authorization from The Open Group. 25706f2543Smrg * 26706f2543Smrg * Author: Chris D. Peterson, MIT X Consortium 27706f2543Smrg */ 28706f2543Smrg/* $XFree86: xc/programs/editres/setvalues.c,v 1.4 2001/01/17 23:44:52 dawes Exp $ */ 29706f2543Smrg 30706f2543Smrg#include <X11/Intrinsic.h> 31706f2543Smrg#include <X11/StringDefs.h> 32706f2543Smrg#include <X11/Xresource.h> 33706f2543Smrg 34706f2543Smrg#include <stdio.h> 35706f2543Smrg 36706f2543Smrg#include <X11/Xaw/AsciiText.h> 37706f2543Smrg#include <X11/Xaw/Cardinals.h> 38706f2543Smrg#include <X11/Xfuncs.h> 39706f2543Smrg#include <X11/Xos.h> 40706f2543Smrg#include "editresP.h" 41706f2543Smrg 42#define RESOURCE_NAME ("name") 43#define RESOURCE_CLASS ("Class") 44 45/* Function Name: PrintSetValuesError 46 * Description: Allow the SetValues error to be printed. 47 * Arguments: event - the set values call that caused this event. 48 * Returns: str - a string contining the errors. 49 */ 50 51char * 52PrintSetValuesError(Event *event) 53{ 54 char * errors = NULL; 55 WNode * node; 56 int i; 57 SetValuesEvent * sv_event = (SetValuesEvent *) event; 58 char buf[BUFSIZ]; 59 60 if (sv_event->num_entries == 0) 61 return(XtNewString("SetValues was Successful.")); 62 63 for (i = 0 ; i < (int)sv_event->num_entries ; i++) { 64 node = FindNode(global_tree_info->top_node, 65 sv_event->info[i].widgets.ids, 66 sv_event->info[i].widgets.num_widgets); 67 68 if (node == NULL) { 69 sprintf(buf, "Editres Internal Error: Unable to FindNode.\n"); 70 AddString(&errors, buf); 71 continue; 72 } 73 74 sprintf(buf, "%s(0x%lx) - %s\n", node->name, node->id, 75 sv_event->info[i].message); 76 AddString(&errors, buf); 77 } 78 return(errors); 79} 80 81/* Function Name: GetResourceValueForSetValues(node); 82 * Description: Returns the value that should be sent to SetValues. 83 * Arguments: node - the node which contains the resource box. 84 * Returns: value - allocated value. 85 */ 86 87char * 88GetResourceValueForSetValues(WNode *node, unsigned short *size) 89{ 90 Arg args[1]; 91 char *ptr, *temp; 92 XrmDatabase db = NULL; 93 XrmValue value; 94 95 XtSetArg(args[0], XtNstring, &ptr); 96 XtGetValues(node->resources->res_box->value_wid, args, ONE); 97 98 /* 99 * This makes sure that exactly the same thing happens during a set 100 * values, that would happend of we were to insert this value into 101 * the resource database. 102 */ 103 104 temp = XtMalloc(sizeof(char) * (strlen(ptr) + strlen(RESOURCE_NAME) + 2)); 105 sprintf(temp, "%s:%s", RESOURCE_NAME, ptr); 106 XrmPutLineResource(&db, temp); 107 XtFree(temp); 108 109 XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value); 110 111 ptr = XtMalloc(sizeof(char) * value.size); 112 memmove( ptr, value.addr, value.size); 113 XrmDestroyDatabase(db); 114 115 *size = (unsigned short) value.size; 116 return(ptr); 117} 118