setvalues.c revision 38d718bd
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 * Author:  Chris D. Peterson, MIT X Consortium
2633c89af1Smrg */
2733c89af1Smrg
2838d718bdSmrg#ifdef HAVE_CONFIG_H
2938d718bdSmrg# include "config.h"
3038d718bdSmrg#endif
3138d718bdSmrg
3233c89af1Smrg#include <X11/Intrinsic.h>
3333c89af1Smrg#include <X11/StringDefs.h>
3433c89af1Smrg#include <X11/Xresource.h>
3533c89af1Smrg
3633c89af1Smrg#include <stdio.h>
3733c89af1Smrg
3833c89af1Smrg#include <X11/Xaw/AsciiText.h>
39ad47b356Smrg#include <X11/Xaw/Cardinals.h>
4033c89af1Smrg#include <X11/Xfuncs.h>
4133c89af1Smrg#include <X11/Xos.h>
4233c89af1Smrg#include "editresP.h"
4333c89af1Smrg
4433c89af1Smrg#define RESOURCE_NAME ("name")
4533c89af1Smrg#define RESOURCE_CLASS ("Class")
4633c89af1Smrg
4733c89af1Smrg/*	Function Name: PrintSetValuesError
4833c89af1Smrg *	Description: Allow the SetValues error to be printed.
4933c89af1Smrg *	Arguments: event - the set values call that caused this event.
5033c89af1Smrg *	Returns: str - a string contining the errors.
5133c89af1Smrg */
5233c89af1Smrg
5333c89af1Smrgchar *
54278eca22SmrgPrintSetValuesError(Event *event)
5533c89af1Smrg{
5633c89af1Smrg    char * errors = NULL;
5733c89af1Smrg    WNode * node;
5833c89af1Smrg    int i;
5933c89af1Smrg    SetValuesEvent * sv_event = (SetValuesEvent *) event;
6033c89af1Smrg    char buf[BUFSIZ];
6133c89af1Smrg
62ad47b356Smrg    if (sv_event->num_entries == 0)
6333c89af1Smrg	return(XtNewString("SetValues was Successful."));
6433c89af1Smrg
6533c89af1Smrg    for (i = 0 ; i < (int)sv_event->num_entries ; i++) {
6633c89af1Smrg	node = FindNode(global_tree_info->top_node,
67ad47b356Smrg			sv_event->info[i].widgets.ids,
6833c89af1Smrg			sv_event->info[i].widgets.num_widgets);
6933c89af1Smrg
7033c89af1Smrg	if (node == NULL) {
71ad47b356Smrg	    snprintf(buf, sizeof(buf),
72ad47b356Smrg                     "Editres Internal Error: Unable to FindNode.\n");
73ad47b356Smrg	    AddString(&errors, buf);
7433c89af1Smrg	    continue;
7533c89af1Smrg	}
7633c89af1Smrg
77ad47b356Smrg	snprintf(buf, sizeof(buf), "%s(0x%lx) - %s\n", node->name, node->id,
78ad47b356Smrg                 sv_event->info[i].message);
7933c89af1Smrg	AddString(&errors, buf);
8033c89af1Smrg    }
8133c89af1Smrg    return(errors);
8233c89af1Smrg}
8333c89af1Smrg
8433c89af1Smrg/*	Function Name: GetResourceValueForSetValues(node);
8533c89af1Smrg *	Description: Returns the value that should be sent to SetValues.
8633c89af1Smrg *	Arguments: node - the node which contains the resource box.
8733c89af1Smrg *	Returns: value - allocated value.
8833c89af1Smrg */
8933c89af1Smrg
9033c89af1Smrgchar *
91278eca22SmrgGetResourceValueForSetValues(WNode *node, unsigned 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
103352bf44eSmrg     * values, that would happen if we were to insert this value into
10433c89af1Smrg     * the resource database.
10533c89af1Smrg     */
10633c89af1Smrg
107ad47b356Smrg    XtAsprintf(&temp, "%s:%s", RESOURCE_NAME, ptr);
10833c89af1Smrg    XrmPutLineResource(&db, temp);
10933c89af1Smrg    XtFree(temp);
11033c89af1Smrg
11133c89af1Smrg    XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value);
11233c89af1Smrg
11333c89af1Smrg    ptr = XtMalloc(sizeof(char) * value.size);
11433c89af1Smrg    memmove( ptr, value.addr, value.size);
11533c89af1Smrg    XrmDestroyDatabase(db);
116ad47b356Smrg
11733c89af1Smrg    *size = (unsigned short) value.size;
11833c89af1Smrg    return(ptr);
11933c89af1Smrg}
120