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 libraries 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 extern Hashtab_t * Wclasses;
74 static void CvtStringToMWMValue(
82 static void CvtMWMValueToString(
92 * Converters for dtksh
96 DtkshCvtWindowToString(
102 static char result[16];
106 if (fval->size != sizeof(Window))
108 errmsg = strdup(GETMESSAGE(6,1,
109 "DtkshCvtWindowToString: The 'from' value is an invalid size"));
116 window = ((Window *)(fval->addr))[0];
118 sprintf(result, "None");
120 sprintf(result, "0x%x", window);
121 toval->addr = result;
122 toval->size = strlen(result)+1;
126 DtkshCvtScreenToString(
132 static char result[16];
136 if (fval->size != sizeof(Screen *))
138 errmsg = strdup(GETMESSAGE(6,14,
139 "DtkshCvtScreenToString: The 'from' value is an invalid size"));
146 screen = ((Screen **)(fval->addr))[0];
147 sprintf(result, "0x%lx", (unsigned long)screen);
148 toval->addr = result;
149 toval->size = strlen(result)+1;
153 DtkshCvtStringToScreen(
159 static Screen * screen;
163 if (fval->size <= 0 || fval->addr == NULL)
170 screen = (Screen *)strtoul(fval->addr, &p, 0);
173 toval->addr = (XtPointer)&screen;
174 toval->size = sizeof(Screen *);
185 DtkshCvtStringToTopItemPosition(
191 static int topItemPosition;
194 if (fval->size <= 0 || fval->addr == NULL)
201 topItemPosition = (int)strtoul(fval->addr, &p, 0);
204 toval->addr = (XtPointer)&topItemPosition;
205 toval->size = sizeof(int);
216 DtkshCvtHexIntToString(
222 static char result[16];
225 if (fval->size != sizeof(long) && fval->size != sizeof(int) &&
226 fval->size != sizeof(short) && fval->size != sizeof(char))
228 errmsg = strdup(GETMESSAGE(6,2,
229 "DtkshCvtHexIntToString: The 'from' value is an invalid size"));
236 if (fval->size == sizeof(long))
237 sprintf(result, "0x%lx", ((long *)(fval->addr))[0]);
238 else if (fval->size == sizeof(int))
239 sprintf(result, "0x%x", ((int *)(fval->addr))[0]);
240 else if (fval->size == sizeof(short))
241 sprintf(result, "0x%x", (int)(((short *)(fval->addr))[0]));
242 else if (fval->size == sizeof(char))
243 sprintf(result, "0x%x", (int)(((char *)(fval->addr))[0]));
244 toval->addr = result;
245 toval->size = strlen(result)+1;
255 static char result[16];
258 if (fval->size != sizeof(int) && fval->size != sizeof(short))
260 errmsg = strdup(GETMESSAGE(6,3,
261 "DtkshCvtIntToString: The 'from' value is an invalid size"));
268 if (fval->size == sizeof(int))
269 sprintf(result, "%d", ((int *)(fval->addr))[0]);
271 sprintf(result, "%d", (int)(((short *)(fval->addr))[0]));
272 toval->addr = result;
273 toval->size = strlen(result)+1;
277 DtkshCvtBooleanToString(
284 Boolean booleanState;
286 if (fval->size != sizeof(int) && fval->size != sizeof(short) &&
287 fval->size != sizeof(char))
289 errmsg = strdup(GETMESSAGE(6,4,
290 "DtkshCvtBooleanToString: The 'from' value is an invalid size"));
298 if (fval->size == sizeof(int))
299 booleanState = (Boolean) (((int *)(fval->addr))[0]);
300 else if (fval->size == sizeof(short))
301 booleanState = (Boolean) (((short *)(fval->addr))[0]);
302 else if (fval->size == sizeof(char))
303 booleanState = (Boolean) (((char *)(fval->addr))[0]);
306 toval->addr = (caddr_t)("true");
308 toval->addr = (caddr_t)("false");
310 toval->size = strlen(toval->addr)+1;
314 DtkshCvtStringToPointer(
320 static XtPointer ret;
322 if (fval->size <= 0 || fval->addr == NULL)
328 ret = (XtPointer)strdup(fval->addr);
329 toval->addr = (XtPointer)&ret;
330 toval->size = sizeof(XtPointer);
335 DtkshCvtStringToWidget(
350 errmsg = strdup(GETMESSAGE(6,5,
351 "DtkshCvtStringToWidget: The 'from' value is an invalid size"));
358 wname = (char *)fval->addr;
359 if (wname == NULL || wname[0] == '\0' || strcmp(wname, "NULL") == 0)
361 static Widget NullWidget = NULL;
363 toval->addr = (XtPointer)&NullWidget;
364 toval->size = sizeof(Widget);
367 if ((w = str_to_wtab("DtkshCvtStringToWidget", wname)) != NULL)
370 toval->addr = (XtPointer)&wid;
371 toval->size = sizeof(Widget);
375 * If we couldn't find it in our table, try looking up the
376 * name in standard resource format.
378 if ((wid = DtkshNameToWidget(wname)) != NULL)
380 toval->addr = (XtPointer)&wid;
381 toval->size = sizeof(Widget);
385 * We failed completely
390 errmsg = strdup(GETMESSAGE(6,6,
391 "DtkshCvtStringToWidget: Unable to find a widget named '%s'"));
392 sprintf(errbuf, errmsg, wname);
401 DtkshCvtStringToCallback(
409 static XtCallbackList cb;
410 dtksh_client_data_t *cdata;
411 classtab_t *c = DTKSHConversionClass;
412 wtab_t *w = DTKSHConversionWidget;
417 errmsg = strdup(GETMESSAGE(6,7,
418 "DtkshCvtStringToCallback: The 'from' value is an invalid size"));
426 cb = (XtCallbackList)XtMalloc(sizeof(XtCallbackRec)*2);
427 cb[0].callback = (XtCallbackProc)stdCB;
429 cdata = GetNewCBData((String)fval->addr, w, DTKSHConversionResource, None);
431 cb[0].closure = (caddr_t)cdata;
432 cb[1].callback = NULL;
433 toval->addr = (XtPointer)&cb;
434 toval->size = sizeof(XtCallbackList);
438 DtkshCvtCallbackToString(
444 XtPointer converterData )
452 if (fval->size != sizeof(XtCallbackList))
454 errmsg = strdup(GETMESSAGE(6,8,
455 "DtkshCvtCallbackToString: The 'from' value is an invalid size"));
462 if (fval->addr == NULL)
470 for (cb = ((XtCallbackList *)(fval->addr))[0]; cb->callback != NULL; cb++)
472 if (cb->callback == (XtCallbackProc)stdCB)
474 dtksh_client_data_t *cdata = (dtksh_client_data_t *)cb->closure;
476 if (p + strlen((String)cdata->ksh_cmd) + 1 - buf > sizeof(buf))
478 errmsg = strdup(GetSharedMsg(DT_CONV_BUF_OVFL));
484 p += sprintf(p, "|%s", (String)cdata->ksh_cmd);
486 p += sprintf(p, "%s", (String)cdata->ksh_cmd);
490 toval->addr = (XtPointer)strdup(buf);
491 toval->size = strlen(buf) + 1;
496 DtkshCvtWidgetToString(
509 if (fval->size != sizeof(Widget) || fval->addr == NULL)
511 errmsg = strdup(GETMESSAGE(6,9,
512 "DtkshCvtWidgetToString: The 'from' value is an invalid size"));
519 widget = ((Widget *)fval->addr)[0];
522 toval->addr = (XtPointer)("NULL");
526 if ((w = widget_to_wtab(widget)) == NULL)
528 errmsg = strdup(GETMESSAGE(6,10,
529 "DtkshCvtWidgetToString: Unable to find a name for the widget"));
536 toval->addr = (XtPointer)w->widid;
537 toval->size = strlen(w->widid) + 1;
541 /***********************************************/
543 static EventMaskTable eventMasks[] = {
544 {"XtAllEvents", XtAllEvents},
545 {"NoEventMask", NoEventMask},
546 {"KeyPressMask", KeyPressMask},
547 {"KeyReleaseMask", KeyReleaseMask},
548 {"ButtonPressMask", ButtonPressMask},
549 {"ButtonReleaseMask", ButtonReleaseMask},
550 {"EnterWindowMask", EnterWindowMask},
551 {"LeaveWindowMask", LeaveWindowMask},
552 {"PointerMotionMask", PointerMotionMask},
553 {"PointerMotionHintMask", PointerMotionHintMask},
554 {"Button1MotionMask", Button1MotionMask},
555 {"Button2MotionMask", Button2MotionMask},
556 {"Button3MotionMask", Button3MotionMask},
557 {"Button4MotionMask", Button4MotionMask},
558 {"Button5MotionMask", Button5MotionMask},
559 {"ButtonMotionMask", ButtonMotionMask},
560 {"KeymapStateMask", KeymapStateMask},
561 {"ExposureMask", ExposureMask},
562 {"VisibilityChangeMask", VisibilityChangeMask},
563 {"StructureNotifyMask", StructureNotifyMask},
564 {"ResizeRedirectMask", ResizeRedirectMask},
565 {"SubstructureNotifyMask", SubstructureNotifyMask},
566 {"SubstructureRedirectMask", SubstructureRedirectMask},
567 {"FocusChangeMask", FocusChangeMask},
568 {"PropertyChangeMask", PropertyChangeMask},
569 {"ColormapChangeMask", ColormapChangeMask},
570 {"OwnerGrabButtonMask", OwnerGrabButtonMask},
576 DtkshCvtStringToEventMask(
584 static EventMask eventMask = 0;
587 char * eventMaskString;
589 toval->addr = (XtPointer)&eventMask;
590 toval->size = sizeof(EventMask);
592 if (fval->size <= 0 || fval->addr == NULL)
595 ptr = eventMaskString = strdup(fval->addr);
597 /* Skip any leading whitespace. */
598 while (isspace(*ptr) && (*ptr != '\0'))
602 ptr = strtok(ptr, "|");
605 for (i = 0; eventMasks[i].name; i++)
607 if (DtCompareISOLatin1(ptr, eventMasks[i].name))
609 eventMask |= eventMasks[i].mask;
613 ptr = strtok(NULL, "|");
616 XtFree(eventMaskString);
621 DtkshCvtStringToListItems(
629 XtConvert(Toplevel, XtRString, fval, XmRXmStringTable, toval);
634 DtkshCvtWidgetClassToString(
642 static char result[16];
647 if (fval->size != sizeof(WidgetClass))
649 errmsg = strdup(GETMESSAGE(6,11,
650 "DtkshCvtWidgetClassToString: The 'from' value is an invalid size"));
658 if ((wc = ((WidgetClass *)(fval->addr))[0]) == NULL)
665 for (i = 0; C[i].cname != NULL; i++)
667 if (C[i].class == wc)
669 toval->addr = C[i].cname;
670 toval->size = strlen(C[i].cname)+1;
676 errmsg = strdup(GETMESSAGE(6,12,
677 "DtkshCvtWidgetClassToString: Unknown widget class"));
686 DtkshCvtStringToWidgetClass(
694 static char result[16];
696 static WidgetClass wc;
700 classtab_t * classtab;
702 if (fval->size <= 0 || fval->addr == NULL)
709 wcName = (char *)(fval->addr);
710 if ((hashInfo = hashget(Wclasses, wcName)) != NULL)
712 classtab = (classtab_t *)hashInfo;
713 wc = classtab->class;
714 toval->addr = (caddr_t)&wc;
715 toval->size = sizeof(WidgetClass);
720 errmsg = strdup(GETMESSAGE(6,13,
721 "DtkshCvtStringToWidgetClass: Unknown widget class name"));
730 static MWMTable mwmDecorations[] = {
731 {"MWM_DECOR_ALL", MWM_DECOR_ALL},
732 {"MWM_DECOR_BORDER", MWM_DECOR_BORDER},
733 {"MWM_DECOR_RESIZEH", MWM_DECOR_RESIZEH},
734 {"MWM_DECOR_TITLE", MWM_DECOR_TITLE},
735 {"MWM_DECOR_MENU", MWM_DECOR_MENU},
736 {"MWM_DECOR_MINIMIZE", MWM_DECOR_MINIMIZE},
737 {"MWM_DECOR_MAXIMIZE", MWM_DECOR_MAXIMIZE},
741 static MWMTable mwmFunctions[] = {
742 {"MWM_FUNC_ALL", MWM_FUNC_ALL},
743 {"MWM_FUNC_RESIZE", MWM_FUNC_RESIZE},
744 {"MWM_FUNC_MOVE", MWM_FUNC_MOVE},
745 {"MWM_FUNC_MINIMIZE", MWM_FUNC_MINIMIZE},
746 {"MWM_FUNC_MAXIMIZE", MWM_FUNC_MAXIMIZE},
747 {"MWM_FUNC_CLOSE", MWM_FUNC_CLOSE},
769 toval->addr = (XtPointer)&value;
770 toval->size = sizeof(int);
772 if (fval->size <= 0 || fval->addr == NULL)
775 ptr = valueString = strdup(fval->addr);
777 /* Skip any leading whitespace. */
778 while (isspace(*ptr) && (*ptr != '\0'))
781 /* Integer values, especially -1, are also supported */
782 intVal = strtol(ptr, &p, 0);
790 ptr = strtok(ptr, "|");
793 for (i = 0; table[i].name; i++)
795 if (DtCompareISOLatin1(ptr, table[i].name))
797 value |= table[i].value;
801 ptr = strtok(NULL, "|");
818 static char *string = NULL;
821 Boolean firstOne = True;
823 value = ((int *)(fval->addr))[0];
827 string = XtRealloc(string, 5);
828 strcpy(string, "-1");
832 string = XtRealloc(string, 1);
835 while (table[i].name)
837 if (value & table[i].value)
841 string = XtRealloc(string,
842 strlen(string) + strlen(table[i].name) + 2);
844 strcat(string, table[i].name);
849 string = XtRealloc(string,
850 strlen(string) + strlen(table[i].name) + 1);
851 strcat(string, table[i].name);
858 toval->addr = (caddr_t)string;
859 toval->size = strlen(string) + 1;
863 DtkshCvtStringToMWMDecoration(
871 CvtStringToMWMValue(mwmDecorations, dpy, args, nargs, fval, toval, data);
876 DtkshCvtMWMDecorationToString(
884 CvtMWMValueToString(mwmDecorations, dpy, args, nargs, fval, toval, data);
888 DtkshCvtStringToMWMFunctions(
896 CvtStringToMWMValue(mwmFunctions, dpy, args, nargs, fval, toval, data);
901 DtkshCvtMWMFunctionsToString(
909 CvtMWMValueToString(mwmFunctions, dpy, args, nargs, fval, toval, data);
913 DtkshCvtStringToPanedWinPosIndex(
925 if (fval->size <= 0 || fval->addr == NULL)
932 pos = (char *)fval->addr;
933 if (DtCompareISOLatin1(pos, "LAST_POSITION"))
934 value = XmLAST_POSITION;
936 value = strtol(pos, &p, 0);
938 toval->addr = (XtPointer)&value;
939 toval->size = sizeof(short);
943 DtkshCvtPanedWinPosIndexToString(
951 static char result[50];
954 if (fval->size != sizeof(short))
960 value = ((short *)(fval->addr))[0];
961 if (value == XmLAST_POSITION)
962 sprintf(result, "LAST_POSITION");
964 sprintf(result, "%d", value);
965 toval->addr = result;
966 toval->size = strlen(result)+1;
971 DtkshCvtStringToPrintSetupProc(
979 static void (*proc)();
980 extern wtab_t *DTKSHConversionWidget;
981 wtab_t *w = DTKSHConversionWidget;
982 extern char *DTKSHConversionResource;
986 if (w->info == NULL) {
987 w->info = (XtPointer)XtMalloc(sizeof(ProcInfo_t));
988 memset(w->info, '\0', sizeof(ProcInfo_t));
990 pinfo = (ProcInfo_t *)w->info;
991 if (strcmp(DTKSHConversionResource, CONSTCHAR "printerInfoProc") == 0) {
992 if (pinfo->printerInfoProcCommand != NULL)
993 XtFree(pinfo->printerInfoProcCommand);
994 pinfo->printerInfoProcCommand = strdup((String)fval->addr);
995 proc = stdPrinterInfoProc;
996 } else if (strcmp(DTKSHConversionResource, CONSTCHAR "selectFileProc") == 0) {
997 if (pinfo->selectFileProcCommand != NULL)
998 XtFree(pinfo->selectFileProcCommand);
999 pinfo->selectFileProcCommand = strdup((String)fval->addr);
1000 proc = stdSelectFileProc;
1002 else if (strcmp(DTKSHConversionResource, CONSTCHAR "selectPrinterProc") == 0) {
1003 if (pinfo->selectPrinterProcCommand != NULL)
1004 XtFree(pinfo->selectPrinterProcCommand);
1005 pinfo->selectPrinterProcCommand = strdup((String)fval->addr);
1006 proc = stdSelectPrinterProc;
1008 else if (strcmp(DTKSHConversionResource, CONSTCHAR "setupProc") == 0) {
1009 if (pinfo->setupProcCommand != NULL)
1010 XtFree(pinfo->setupProcCommand);
1011 pinfo->setupProcCommand = strdup((String)fval->addr);
1012 proc = stdSetupProc;
1014 else if (strcmp(DTKSHConversionResource, CONSTCHAR "verifyPrinterProc") == 0) {
1015 if (pinfo->verifyPrinterProcCommand != NULL)
1016 XtFree(pinfo->verifyPrinterProcCommand);
1017 pinfo->verifyPrinterProcCommand = strdup((String)fval->addr);
1018 proc = stdVerifyPrinterProc;
1021 XtWarningMsg(CONSTCHAR "CvtStringToPrintSetupProc", CONSTCHAR "unsupported DtPrintSetupBox resource.", CONSTCHAR "XtToolkitError", "This resource is not currently supported by dtksh.", NULL, 0);
1024 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);
1030 toval->size = sizeof(DtPrintSetupProc);
1031 toval->addr = (XtPointer)&proc;