setvalues.c revision ad47b356
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
2833c89af1Smrg#include <X11/Intrinsic.h>
2933c89af1Smrg#include <X11/StringDefs.h>
3033c89af1Smrg#include <X11/Xresource.h>
3133c89af1Smrg
3233c89af1Smrg#include <stdio.h>
3333c89af1Smrg
3433c89af1Smrg#include <X11/Xaw/AsciiText.h>
35ad47b356Smrg#include <X11/Xaw/Cardinals.h>
3633c89af1Smrg#include <X11/Xfuncs.h>
3733c89af1Smrg#include <X11/Xos.h>
3833c89af1Smrg#include "editresP.h"
3933c89af1Smrg
4033c89af1Smrg#define RESOURCE_NAME ("name")
4133c89af1Smrg#define RESOURCE_CLASS ("Class")
4233c89af1Smrg
4333c89af1Smrg/*	Function Name: PrintSetValuesError
4433c89af1Smrg *	Description: Allow the SetValues error to be printed.
4533c89af1Smrg *	Arguments: event - the set values call that caused this event.
4633c89af1Smrg *	Returns: str - a string contining the errors.
4733c89af1Smrg */
4833c89af1Smrg
4933c89af1Smrgchar *
50278eca22SmrgPrintSetValuesError(Event *event)
5133c89af1Smrg{
5233c89af1Smrg    char * errors = NULL;
5333c89af1Smrg    WNode * node;
5433c89af1Smrg    int i;
5533c89af1Smrg    SetValuesEvent * sv_event = (SetValuesEvent *) event;
5633c89af1Smrg    char buf[BUFSIZ];
5733c89af1Smrg
58ad47b356Smrg    if (sv_event->num_entries == 0)
5933c89af1Smrg	return(XtNewString("SetValues was Successful."));
6033c89af1Smrg
6133c89af1Smrg    for (i = 0 ; i < (int)sv_event->num_entries ; i++) {
6233c89af1Smrg	node = FindNode(global_tree_info->top_node,
63ad47b356Smrg			sv_event->info[i].widgets.ids,
6433c89af1Smrg			sv_event->info[i].widgets.num_widgets);
6533c89af1Smrg
6633c89af1Smrg	if (node == NULL) {
67ad47b356Smrg	    snprintf(buf, sizeof(buf),
68ad47b356Smrg                     "Editres Internal Error: Unable to FindNode.\n");
69ad47b356Smrg	    AddString(&errors, buf);
7033c89af1Smrg	    continue;
7133c89af1Smrg	}
7233c89af1Smrg
73ad47b356Smrg	snprintf(buf, sizeof(buf), "%s(0x%lx) - %s\n", node->name, node->id,
74ad47b356Smrg                 sv_event->info[i].message);
7533c89af1Smrg	AddString(&errors, buf);
7633c89af1Smrg    }
7733c89af1Smrg    return(errors);
7833c89af1Smrg}
7933c89af1Smrg
8033c89af1Smrg/*	Function Name: GetResourceValueForSetValues(node);
8133c89af1Smrg *	Description: Returns the value that should be sent to SetValues.
8233c89af1Smrg *	Arguments: node - the node which contains the resource box.
8333c89af1Smrg *	Returns: value - allocated value.
8433c89af1Smrg */
8533c89af1Smrg
8633c89af1Smrgchar *
87278eca22SmrgGetResourceValueForSetValues(WNode *node, unsigned short *size)
8833c89af1Smrg{
8933c89af1Smrg    Arg args[1];
9033c89af1Smrg    char *ptr, *temp;
9133c89af1Smrg    XrmDatabase db = NULL;
9233c89af1Smrg    XrmValue value;
9333c89af1Smrg
9433c89af1Smrg    XtSetArg(args[0], XtNstring, &ptr);
9533c89af1Smrg    XtGetValues(node->resources->res_box->value_wid, args, ONE);
9633c89af1Smrg
9733c89af1Smrg    /*
9833c89af1Smrg     * This makes sure that exactly the same thing happens during a set
9933c89af1Smrg     * values, that would happend of we were to insert this value into
10033c89af1Smrg     * the resource database.
10133c89af1Smrg     */
10233c89af1Smrg
103ad47b356Smrg    XtAsprintf(&temp, "%s:%s", RESOURCE_NAME, ptr);
10433c89af1Smrg    XrmPutLineResource(&db, temp);
10533c89af1Smrg    XtFree(temp);
10633c89af1Smrg
10733c89af1Smrg    XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value);
10833c89af1Smrg
10933c89af1Smrg    ptr = XtMalloc(sizeof(char) * value.size);
11033c89af1Smrg    memmove( ptr, value.addr, value.size);
11133c89af1Smrg    XrmDestroyDatabase(db);
112ad47b356Smrg
11333c89af1Smrg    *size = (unsigned short) value.size;
11433c89af1Smrg    return(ptr);
11533c89af1Smrg}
116