setvalues.c revision 33c89af1
133c89af1Smrg/* 233c89af1Smrg * $Xorg: setvalues.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ 333c89af1Smrg * 433c89af1SmrgCopyright 1989, 1998 The Open Group 533c89af1Smrg 633c89af1SmrgPermission to use, copy, modify, distribute, and sell this software and its 733c89af1Smrgdocumentation for any purpose is hereby granted without fee, provided that 833c89af1Smrgthe above copyright notice appear in all copies and that both that 933c89af1Smrgcopyright notice and this permission notice appear in supporting 1033c89af1Smrgdocumentation. 1133c89af1Smrg 1233c89af1SmrgThe above copyright notice and this permission notice shall be included in 1333c89af1Smrgall copies or substantial portions of the Software. 1433c89af1Smrg 1533c89af1SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1633c89af1SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1733c89af1SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1833c89af1SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1933c89af1SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2033c89af1SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2133c89af1Smrg 2233c89af1SmrgExcept as contained in this notice, the name of The Open Group shall not be 2333c89af1Smrgused in advertising or otherwise to promote the sale, use or other dealings 2433c89af1Smrgin this Software without prior written authorization from The Open Group. 2533c89af1Smrg * 2633c89af1Smrg * Author: Chris D. Peterson, MIT X Consortium 2733c89af1Smrg */ 2833c89af1Smrg/* $XFree86: xc/programs/editres/setvalues.c,v 1.4 2001/01/17 23:44:52 dawes Exp $ */ 2933c89af1Smrg 3033c89af1Smrg#include <X11/Intrinsic.h> 3133c89af1Smrg#include <X11/StringDefs.h> 3233c89af1Smrg#include <X11/Xresource.h> 3333c89af1Smrg 3433c89af1Smrg#include <stdio.h> 3533c89af1Smrg 3633c89af1Smrg#include <X11/Xaw/AsciiText.h> 3733c89af1Smrg#include <X11/Xaw/Cardinals.h> 3833c89af1Smrg#include <X11/Xfuncs.h> 3933c89af1Smrg#include <X11/Xos.h> 4033c89af1Smrg#include "editresP.h" 4133c89af1Smrg 4233c89af1Smrg#define RESOURCE_NAME ("name") 4333c89af1Smrg#define RESOURCE_CLASS ("Class") 4433c89af1Smrg 4533c89af1Smrg/* Function Name: PrintSetValuesError 4633c89af1Smrg * Description: Allow the SetValues error to be printed. 4733c89af1Smrg * Arguments: event - the set values call that caused this event. 4833c89af1Smrg * Returns: str - a string contining the errors. 4933c89af1Smrg */ 5033c89af1Smrg 5133c89af1Smrgchar * 5233c89af1SmrgPrintSetValuesError(event) 5333c89af1SmrgEvent * event; 5433c89af1Smrg{ 5533c89af1Smrg char * errors = NULL; 5633c89af1Smrg WNode * node; 5733c89af1Smrg int i; 5833c89af1Smrg SetValuesEvent * sv_event = (SetValuesEvent *) event; 5933c89af1Smrg char buf[BUFSIZ]; 6033c89af1Smrg 6133c89af1Smrg if (sv_event->num_entries == 0) 6233c89af1Smrg return(XtNewString("SetValues was Successful.")); 6333c89af1Smrg 6433c89af1Smrg for (i = 0 ; i < (int)sv_event->num_entries ; i++) { 6533c89af1Smrg node = FindNode(global_tree_info->top_node, 6633c89af1Smrg sv_event->info[i].widgets.ids, 6733c89af1Smrg sv_event->info[i].widgets.num_widgets); 6833c89af1Smrg 6933c89af1Smrg if (node == NULL) { 7033c89af1Smrg sprintf(buf, "Editres Internal Error: Unable to FindNode.\n"); 7133c89af1Smrg AddString(&errors, buf); 7233c89af1Smrg continue; 7333c89af1Smrg } 7433c89af1Smrg 7533c89af1Smrg sprintf(buf, "%s(0x%lx) - %s\n", node->name, node->id, 7633c89af1Smrg sv_event->info[i].message); 7733c89af1Smrg AddString(&errors, buf); 7833c89af1Smrg } 7933c89af1Smrg return(errors); 8033c89af1Smrg} 8133c89af1Smrg 8233c89af1Smrg/* Function Name: GetResourceValueForSetValues(node); 8333c89af1Smrg * Description: Returns the value that should be sent to SetValues. 8433c89af1Smrg * Arguments: node - the node which contains the resource box. 8533c89af1Smrg * Returns: value - allocated value. 8633c89af1Smrg */ 8733c89af1Smrg 8833c89af1Smrgchar * 8933c89af1SmrgGetResourceValueForSetValues(node, size) 9033c89af1SmrgWNode * node; 9133c89af1Smrgunsigned short * size; 9233c89af1Smrg{ 9333c89af1Smrg Arg args[1]; 9433c89af1Smrg char *ptr, *temp; 9533c89af1Smrg XrmDatabase db = NULL; 9633c89af1Smrg XrmValue value; 9733c89af1Smrg 9833c89af1Smrg XtSetArg(args[0], XtNstring, &ptr); 9933c89af1Smrg XtGetValues(node->resources->res_box->value_wid, args, ONE); 10033c89af1Smrg 10133c89af1Smrg /* 10233c89af1Smrg * This makes sure that exactly the same thing happens during a set 10333c89af1Smrg * values, that would happend of we were to insert this value into 10433c89af1Smrg * the resource database. 10533c89af1Smrg */ 10633c89af1Smrg 10733c89af1Smrg temp = XtMalloc(sizeof(char) * (strlen(ptr) + strlen(RESOURCE_NAME) + 2)); 10833c89af1Smrg sprintf(temp, "%s:%s", RESOURCE_NAME, ptr); 10933c89af1Smrg XrmPutLineResource(&db, temp); 11033c89af1Smrg XtFree(temp); 11133c89af1Smrg 11233c89af1Smrg XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value); 11333c89af1Smrg 11433c89af1Smrg ptr = XtMalloc(sizeof(char) * value.size); 11533c89af1Smrg memmove( ptr, value.addr, value.size); 11633c89af1Smrg XrmDestroyDatabase(db); 11733c89af1Smrg 11833c89af1Smrg *size = (unsigned short) value.size; 11933c89af1Smrg return(ptr); 12033c89af1Smrg} 121