2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: dtkcvt.c /main/7 1998/04/20 12:54:59 mgreess $ */
25 /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
26 /* All Rights Reserved */
28 /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
29 /* UNIX System Laboratories, Inc. */
30 /* The copyright notice above does not evidence any */
31 /* actual or intended publication of such source code. */
39 #include <X11/Intrinsic.h>
40 #include <X11/IntrinsicP.h>
41 #include <X11/CoreP.h>
42 #include <X11/StringDefs.h>
43 #include <Xm/XmStrDefs.h>
48 #include <Xm/Protocols.h>
49 #include <Xm/MwmUtil.h>
50 #include <Dt/Service.h>
52 #include <Dt/HourGlass.h>
54 #include <Dt/EnvControlP.h>
67 #include "xmwidgets.h"
70 #if defined(SYSV) || defined(SVR4_0) || defined(SVR4) || defined(DEC) \
71 || defined(CSRG_BASED) || defined(linux) || defined(sun)
72 #define lsprintf sprintf
75 extern Hashtab_t * Wclasses;
79 static void CvtStringToMWMValue(
87 static void CvtMWMValueToString(
97 * Converters for dtksh
101 DtkshCvtWindowToString(
107 static char result[16];
111 if (fval->size != sizeof(Window))
113 errmsg = strdup(GETMESSAGE(6,1,
114 "DtkshCvtWindowToString: The 'from' value is an invalid size"));
121 window = ((Window *)(fval->addr))[0];
123 sprintf(result, "None");
125 sprintf(result, "0x%x", window);
126 toval->addr = result;
127 toval->size = strlen(result)+1;
131 DtkshCvtScreenToString(
137 static char result[16];
141 if (fval->size != sizeof(Screen *))
143 errmsg = strdup(GETMESSAGE(6,14,
144 "DtkshCvtScreenToString: The 'from' value is an invalid size"));
151 screen = ((Screen **)(fval->addr))[0];
152 sprintf(result, "0x%lx", (unsigned long)screen);
153 toval->addr = result;
154 toval->size = strlen(result)+1;
158 DtkshCvtStringToScreen(
164 static Screen * screen;
168 if (fval->size <= 0 || fval->addr == NULL)
175 screen = (Screen *)strtoul(fval->addr, &p, 0);
178 toval->addr = (XtPointer)&screen;
179 toval->size = sizeof(Screen *);
190 DtkshCvtStringToTopItemPosition(
196 static int topItemPosition;
199 if (fval->size <= 0 || fval->addr == NULL)
206 topItemPosition = (int)strtoul(fval->addr, &p, 0);
209 toval->addr = (XtPointer)&topItemPosition;
210 toval->size = sizeof(int);
221 DtkshCvtHexIntToString(
227 static char result[16];
230 if (fval->size != sizeof(long) && fval->size != sizeof(int) &&
231 fval->size != sizeof(short) && fval->size != sizeof(char))
233 errmsg = strdup(GETMESSAGE(6,2,
234 "DtkshCvtHexIntToString: The 'from' value is an invalid size"));
241 if (fval->size == sizeof(long))
242 sprintf(result, "0x%lx", ((long *)(fval->addr))[0]);
243 else if (fval->size == sizeof(int))
244 sprintf(result, "0x%x", ((int *)(fval->addr))[0]);
245 else if (fval->size == sizeof(short))
246 sprintf(result, "0x%x", (int)(((short *)(fval->addr))[0]));
247 else if (fval->size == sizeof(char))
248 sprintf(result, "0x%x", (int)(((char *)(fval->addr))[0]));
249 toval->addr = result;
250 toval->size = strlen(result)+1;
260 static char result[16];
263 if (fval->size != sizeof(int) && fval->size != sizeof(short))
265 errmsg = strdup(GETMESSAGE(6,3,
266 "DtkshCvtIntToString: The 'from' value is an invalid size"));
273 if (fval->size == sizeof(int))
274 sprintf(result, "%d", ((int *)(fval->addr))[0]);
276 sprintf(result, "%d", (int)(((short *)(fval->addr))[0]));
277 toval->addr = result;
278 toval->size = strlen(result)+1;
282 DtkshCvtBooleanToString(
289 Boolean booleanState;
291 if (fval->size != sizeof(int) && fval->size != sizeof(short) &&
292 fval->size != sizeof(char))
294 errmsg = strdup(GETMESSAGE(6,4,
295 "DtkshCvtBooleanToString: The 'from' value is an invalid size"));
303 if (fval->size == sizeof(int))
304 booleanState = (Boolean) (((int *)(fval->addr))[0]);
305 else if (fval->size == sizeof(short))
306 booleanState = (Boolean) (((short *)(fval->addr))[0]);
307 else if (fval->size == sizeof(char))
308 booleanState = (Boolean) (((char *)(fval->addr))[0]);
311 toval->addr = (caddr_t)("true");
313 toval->addr = (caddr_t)("false");
315 toval->size = strlen(toval->addr)+1;
319 DtkshCvtStringToPointer(
325 static XtPointer ret;
327 if (fval->size <= 0 || fval->addr == NULL)
333 ret = (XtPointer)strdup(fval->addr);
334 toval->addr = (XtPointer)&ret;
335 toval->size = sizeof(XtPointer);
340 DtkshCvtStringToWidget(
355 errmsg = strdup(GETMESSAGE(6,5,
356 "DtkshCvtStringToWidget: The 'from' value is an invalid size"));
363 wname = (char *)fval->addr;
364 if (wname == NULL || wname[0] == '\0' || strcmp(wname, "NULL") == 0)
366 static Widget NullWidget = NULL;
368 toval->addr = (XtPointer)&NullWidget;
369 toval->size = sizeof(Widget);
372 if ((w = str_to_wtab("DtkshCvtStringToWidget", wname)) != NULL)
375 toval->addr = (XtPointer)&wid;
376 toval->size = sizeof(Widget);
380 * If we couldn't find it in our table, try looking up the
381 * name in standard resource format.
383 if ((wid = DtkshNameToWidget(wname)) != NULL)
385 toval->addr = (XtPointer)&wid;
386 toval->size = sizeof(Widget);
390 * We failed completely
395 errmsg = strdup(GETMESSAGE(6,6,
396 "DtkshCvtStringToWidget: Unable to find a widget named '%s'"));
397 sprintf(errbuf, errmsg, wname);
406 DtkshCvtStringToCallback(
414 static XtCallbackList cb;
415 dtksh_client_data_t *cdata;
416 classtab_t *c = DTKSHConversionClass;
417 wtab_t *w = DTKSHConversionWidget;
422 errmsg = strdup(GETMESSAGE(6,7,
423 "DtkshCvtStringToCallback: The 'from' value is an invalid size"));
431 cb = (XtCallbackList)XtMalloc(sizeof(XtCallbackRec)*2);
432 cb[0].callback = (XtCallbackProc)stdCB;
434 cdata = GetNewCBData((String)fval->addr, w, DTKSHConversionResource, None);
436 cb[0].closure = (caddr_t)cdata;
437 cb[1].callback = NULL;
438 toval->addr = (XtPointer)&cb;
439 toval->size = sizeof(XtCallbackList);
443 DtkshCvtCallbackToString(
449 XtPointer converterData )
457 if (fval->size != sizeof(XtCallbackList))
459 errmsg = strdup(GETMESSAGE(6,8,
460 "DtkshCvtCallbackToString: The 'from' value is an invalid size"));
467 if (fval->addr == NULL)
475 for (cb = ((XtCallbackList *)(fval->addr))[0]; cb->callback != NULL; cb++)
477 if (cb->callback == (XtCallbackProc)stdCB)
479 dtksh_client_data_t *cdata = (dtksh_client_data_t *)cb->closure;
481 if (p + strlen((String)cdata->ksh_cmd) + 1 - buf > sizeof(buf))
483 errmsg = strdup(GetSharedMsg(DT_CONV_BUF_OVFL));
489 p += lsprintf(p, "|%s", (String)cdata->ksh_cmd);
491 p += lsprintf(p, "%s", (String)cdata->ksh_cmd);
495 toval->addr = (XtPointer)strdup(buf);
496 toval->size = strlen(buf) + 1;
501 DtkshCvtWidgetToString(
514 if (fval->size != sizeof(Widget) || fval->addr == NULL)
516 errmsg = strdup(GETMESSAGE(6,9,
517 "DtkshCvtWidgetToString: The 'from' value is an invalid size"));
524 widget = ((Widget *)fval->addr)[0];
527 toval->addr = (XtPointer)("NULL");
531 if ((w = widget_to_wtab(widget)) == NULL)
533 errmsg = strdup(GETMESSAGE(6,10,
534 "DtkshCvtWidgetToString: Unable to find a name for the widget"));
541 toval->addr = (XtPointer)w->widid;
542 toval->size = strlen(w->widid) + 1;
546 /***********************************************/
548 static EventMaskTable eventMasks[] = {
549 {"XtAllEvents", XtAllEvents},
550 {"NoEventMask", NoEventMask},
551 {"KeyPressMask", KeyPressMask},
552 {"KeyReleaseMask", KeyReleaseMask},
553 {"ButtonPressMask", ButtonPressMask},
554 {"ButtonReleaseMask", ButtonReleaseMask},
555 {"EnterWindowMask", EnterWindowMask},
556 {"LeaveWindowMask", LeaveWindowMask},
557 {"PointerMotionMask", PointerMotionMask},
558 {"PointerMotionHintMask", PointerMotionHintMask},
559 {"Button1MotionMask", Button1MotionMask},
560 {"Button2MotionMask", Button2MotionMask},
561 {"Button3MotionMask", Button3MotionMask},
562 {"Button4MotionMask", Button4MotionMask},
563 {"Button5MotionMask", Button5MotionMask},
564 {"ButtonMotionMask", ButtonMotionMask},
565 {"KeymapStateMask", KeymapStateMask},
566 {"ExposureMask", ExposureMask},
567 {"VisibilityChangeMask", VisibilityChangeMask},
568 {"StructureNotifyMask", StructureNotifyMask},
569 {"ResizeRedirectMask", ResizeRedirectMask},
570 {"SubstructureNotifyMask", SubstructureNotifyMask},
571 {"SubstructureRedirectMask", SubstructureRedirectMask},
572 {"FocusChangeMask", FocusChangeMask},
573 {"PropertyChangeMask", PropertyChangeMask},
574 {"ColormapChangeMask", ColormapChangeMask},
575 {"OwnerGrabButtonMask", OwnerGrabButtonMask},
581 DtkshCvtStringToEventMask(
589 static EventMask eventMask = 0;
592 char * eventMaskString;
594 toval->addr = (XtPointer)&eventMask;
595 toval->size = sizeof(EventMask);
597 if (fval->size <= 0 || fval->addr == NULL)
600 ptr = eventMaskString = strdup(fval->addr);
602 /* Skip any leading whitespace. */
603 while (isspace(*ptr) && (*ptr != '\0'))
607 ptr = strtok(ptr, "|");
610 for (i = 0; eventMasks[i].name; i++)
612 if (DtCompareISOLatin1(ptr, eventMasks[i].name))
614 eventMask |= eventMasks[i].mask;
618 ptr = strtok(NULL, "|");
621 XtFree(eventMaskString);
626 DtkshCvtStringToListItems(
634 XtConvert(Toplevel, XtRString, fval, XmRXmStringTable, toval);
639 DtkshCvtWidgetClassToString(
647 static char result[16];
652 if (fval->size != sizeof(WidgetClass))
654 errmsg = strdup(GETMESSAGE(6,11,
655 "DtkshCvtWidgetClassToString: The 'from' value is an invalid size"));
663 if ((wc = ((WidgetClass *)(fval->addr))[0]) == NULL)
670 for (i = 0; C[i].cname != NULL; i++)
672 if (C[i].class == wc)
674 toval->addr = C[i].cname;
675 toval->size = strlen(C[i].cname)+1;
681 errmsg = strdup(GETMESSAGE(6,12,
682 "DtkshCvtWidgetClassToString: Unknown widget class"));
691 DtkshCvtStringToWidgetClass(
699 static char result[16];
701 static WidgetClass wc;
705 classtab_t * classtab;
707 if (fval->size <= 0 || fval->addr == NULL)
714 wcName = (char *)(fval->addr);
715 if ((hashInfo = hashget(Wclasses, wcName)) != NULL)
717 classtab = (classtab_t *)hashInfo;
718 wc = classtab->class;
719 toval->addr = (caddr_t)&wc;
720 toval->size = sizeof(WidgetClass);
725 errmsg = strdup(GETMESSAGE(6,13,
726 "DtkshCvtStringToWidgetClass: Unknown widget class name"));
735 static MWMTable mwmDecorations[] = {
736 {"MWM_DECOR_ALL", MWM_DECOR_ALL},
737 {"MWM_DECOR_BORDER", MWM_DECOR_BORDER},
738 {"MWM_DECOR_RESIZEH", MWM_DECOR_RESIZEH},
739 {"MWM_DECOR_TITLE", MWM_DECOR_TITLE},
740 {"MWM_DECOR_MENU", MWM_DECOR_MENU},
741 {"MWM_DECOR_MINIMIZE", MWM_DECOR_MINIMIZE},
742 {"MWM_DECOR_MAXIMIZE", MWM_DECOR_MAXIMIZE},
746 static MWMTable mwmFunctions[] = {
747 {"MWM_FUNC_ALL", MWM_FUNC_ALL},
748 {"MWM_FUNC_RESIZE", MWM_FUNC_RESIZE},
749 {"MWM_FUNC_MOVE", MWM_FUNC_MOVE},
750 {"MWM_FUNC_MINIMIZE", MWM_FUNC_MINIMIZE},
751 {"MWM_FUNC_MAXIMIZE", MWM_FUNC_MAXIMIZE},
752 {"MWM_FUNC_CLOSE", MWM_FUNC_CLOSE},
774 toval->addr = (XtPointer)&value;
775 toval->size = sizeof(int);
777 if (fval->size <= 0 || fval->addr == NULL)
780 ptr = valueString = strdup(fval->addr);
782 /* Skip any leading whitespace. */
783 while (isspace(*ptr) && (*ptr != '\0'))
786 /* Integer values, especially -1, are also supported */
787 intVal = strtol(ptr, &p, 0);
795 ptr = strtok(ptr, "|");
798 for (i = 0; table[i].name; i++)
800 if (DtCompareISOLatin1(ptr, table[i].name))
802 value |= table[i].value;
806 ptr = strtok(NULL, "|");
823 static char *string = NULL;
826 Boolean firstOne = True;
828 value = ((int *)(fval->addr))[0];
832 string = XtRealloc(string, 5);
833 strcpy(string, "-1");
837 string = XtRealloc(string, 1);
840 while (table[i].name)
842 if (value & table[i].value)
846 string = XtRealloc(string,
847 strlen(string) + strlen(table[i].name) + 2);
849 strcat(string, table[i].name);
854 string = XtRealloc(string,
855 strlen(string) + strlen(table[i].name) + 1);
856 strcat(string, table[i].name);
863 toval->addr = (caddr_t)string;
864 toval->size = strlen(string) + 1;
868 DtkshCvtStringToMWMDecoration(
876 CvtStringToMWMValue(mwmDecorations, dpy, args, nargs, fval, toval, data);
881 DtkshCvtMWMDecorationToString(
889 CvtMWMValueToString(mwmDecorations, dpy, args, nargs, fval, toval, data);
893 DtkshCvtStringToMWMFunctions(
901 CvtStringToMWMValue(mwmFunctions, dpy, args, nargs, fval, toval, data);
906 DtkshCvtMWMFunctionsToString(
914 CvtMWMValueToString(mwmFunctions, dpy, args, nargs, fval, toval, data);
918 DtkshCvtStringToPanedWinPosIndex(
930 if (fval->size <= 0 || fval->addr == NULL)
937 pos = (char *)fval->addr;
938 if (DtCompareISOLatin1(pos, "LAST_POSITION"))
939 value = XmLAST_POSITION;
941 value = strtol(pos, &p, 0);
943 toval->addr = (XtPointer)&value;
944 toval->size = sizeof(short);
948 DtkshCvtPanedWinPosIndexToString(
956 static char result[50];
959 if (fval->size != sizeof(short))
965 value = ((short *)(fval->addr))[0];
966 if (value == XmLAST_POSITION)
967 sprintf(result, "LAST_POSITION");
969 sprintf(result, "%d", value);
970 toval->addr = result;
971 toval->size = strlen(result)+1;
976 DtkshCvtStringToPrintSetupProc(
984 static void (*proc)();
985 extern wtab_t *DTKSHConversionWidget;
986 wtab_t *w = DTKSHConversionWidget;
987 extern char *DTKSHConversionResource;
991 if (w->info == NULL) {
992 w->info = (XtPointer)XtMalloc(sizeof(ProcInfo_t));
993 memset(w->info, '\0', sizeof(ProcInfo_t));
995 pinfo = (ProcInfo_t *)w->info;
996 if (strcmp(DTKSHConversionResource, CONSTCHAR "printerInfoProc") == 0) {
997 if (pinfo->printerInfoProcCommand != NULL)
998 XtFree(pinfo->printerInfoProcCommand);
999 pinfo->printerInfoProcCommand = strdup((String)fval->addr);
1000 proc = stdPrinterInfoProc;
1001 } else if (strcmp(DTKSHConversionResource, CONSTCHAR "selectFileProc") == 0) {
1002 if (pinfo->selectFileProcCommand != NULL)
1003 XtFree(pinfo->selectFileProcCommand);
1004 pinfo->selectFileProcCommand = strdup((String)fval->addr);
1005 proc = stdSelectFileProc;
1007 else if (strcmp(DTKSHConversionResource, CONSTCHAR "selectPrinterProc") == 0) {
1008 if (pinfo->selectPrinterProcCommand != NULL)
1009 XtFree(pinfo->selectPrinterProcCommand);
1010 pinfo->selectPrinterProcCommand = strdup((String)fval->addr);
1011 proc = stdSelectPrinterProc;
1013 else if (strcmp(DTKSHConversionResource, CONSTCHAR "setupProc") == 0) {
1014 if (pinfo->setupProcCommand != NULL)
1015 XtFree(pinfo->setupProcCommand);
1016 pinfo->setupProcCommand = strdup((String)fval->addr);
1017 proc = stdSetupProc;
1019 else if (strcmp(DTKSHConversionResource, CONSTCHAR "verifyPrinterProc") == 0) {
1020 if (pinfo->verifyPrinterProcCommand != NULL)
1021 XtFree(pinfo->verifyPrinterProcCommand);
1022 pinfo->verifyPrinterProcCommand = strdup((String)fval->addr);
1023 proc = stdVerifyPrinterProc;
1026 XtWarningMsg(CONSTCHAR "CvtStringToPrintSetupProc", CONSTCHAR "unsupported DtPrintSetupBox resource.", CONSTCHAR "XtToolkitError", "This resource is not currently supported by dtksh.", NULL, 0);
1029 XtWarningMsg(CONSTCHAR "CvtStringToPrintSetupProc", CONSTCHAR "widget must exist.", CONSTCHAR "XtToolkitError", "This resource cannot be set at creation time by dtksh, use XtSetValues after creation instead.", NULL, 0);
1035 toval->size = sizeof(DtPrintSetupProc);
1036 toval->addr = (XtPointer)&proc;