1 /* $TOG: fileIODialog.c /main/6 1999/06/01 10:55:30 mgreess $ */
2 /*********************************************************************
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
6 * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
8 **********************************************************************/
9 /*******************************************************************************
12 *******************************************************************************/
16 #include <sys/types.h>
18 #include <sys/param.h>
20 #include <Xm/FileSB.h>
21 #include <Xm/DialogS.h>
22 #include <Xm/MwmUtil.h>
24 #include "externals.h"
25 #include <Dt/DtPStrings.h>
27 #include <Xm/FileSB.h>
29 /*******************************************************************************
30 Includes, Defines, and Global variables from the Declarations Editor:
31 *******************************************************************************/
33 extern void Do_FileIO();
37 /*******************************************************************************
38 Forward declarations of functions that are defined later in this file.
39 *******************************************************************************/
41 Widget create_fileIODialog();
43 /*******************************************************************************
44 The following are callback functions.
45 *******************************************************************************/
48 cancelCB_fileIODialog(
51 XtPointer callbackArg )
53 XtUnmanageChild(fileIODialog);
56 /*******************************************************************************
57 The following is the 'Interface function' which is the
58 external entry point for creating this interface.
59 This function should be called from your application or from
61 *******************************************************************************/
63 create_fileIODialog( void )
65 Widget fileIODialog_shell, wid;
66 XmString tmpXmStr, tmpXmStr1, tmpXmStr2, tmpXmStr3, tmpXmStr4,
67 tmpXmStr6, tmpXmStr7, tmpXmStr8;
70 char *userIconPath, *s;
73 userIconPath = getenv("XMICONSEARCHPATH");
74 if (NULL == userIconPath)
75 userIconPath = getenv("XMICONBMSEARCHPATH");
76 if (NULL == userIconPath)
77 userIconPath = getenv("HOME");
79 if (NULL != userIconPath)
83 userIconPath = XtNewString(userIconPath);
84 s = strchr(userIconPath, ':');
85 if (NULL != s) *s = '\0';
86 s = strrchr(userIconPath, '/');
87 if (NULL != s) *s = '\0';
90 fileIODialog_shell = XtVaCreatePopupShell( "fileIODialog_shell",
91 xmDialogShellWidgetClass, mainWindow,
92 XmNtitle, GETSTR(2,2, "Icon Editor - File I/O"),
95 tmpXmStr = GETXMSTR(2,6, "Icon Editor - Save As");
96 tmpXmStr1 = GETXMSTR(2,10, "Filter");
97 tmpXmStr2 = GETXMSTR(2,12, "Folders");
98 tmpXmStr3 = GETXMSTR(2,14, "Files");
99 tmpXmStr4 = GETXMSTR(2,16, "Enter file name:");
100 tmpXmStr6 = GETXMSTR(4,8, "Cancel");
101 tmpXmStr7 = GETXMSTR(4,10, "Help");
103 fileIODialog = XtVaCreateWidget( "fileIODialog",
104 xmFileSelectionBoxWidgetClass, fileIODialog_shell,
105 XmNdialogTitle, tmpXmStr,
106 XmNfilterLabelString, tmpXmStr1,
107 XmNdirListLabelString, tmpXmStr2,
108 XmNfileListLabelString, tmpXmStr3,
109 XmNselectionLabelString, tmpXmStr4,
110 XmNapplyLabelString, tmpXmStr1,
111 XmNcancelLabelString, tmpXmStr6,
112 XmNhelpLabelString, tmpXmStr7,
115 userIconPath = getenv("XMICONSEARCHPATH");
116 if (NULL != userIconPath)
118 userIconPath = XtNewString(userIconPath);
119 s = strchr(userIconPath, ':');
120 if (NULL != s) *s = '\0';
121 s = strrchr(userIconPath, '/');
122 if (NULL != s && userIconPath != s) *s = '\0';
124 if (0 != stat(userIconPath, &sbuf) ||
125 0 == (S_IFDIR & sbuf.st_mode) ||
126 0 == (S_IWUSR & sbuf.st_mode))
128 XtFree(userIconPath);
132 if (NULL == userIconPath)
134 userIconPath = getenv("XMICONBMSEARCHPATH");
135 if (NULL != userIconPath)
137 userIconPath = XtNewString(userIconPath);
138 s = strchr(userIconPath, ':');
139 if (NULL != s) *s = '\0';
140 s = strrchr(userIconPath, '/');
141 if (NULL != s && userIconPath != s) *s = '\0';
143 if (0 != stat(userIconPath, &sbuf) ||
144 0 == (S_IFDIR & sbuf.st_mode) ||
145 0 == (S_IWUSR & sbuf.st_mode))
147 XtFree(userIconPath);
152 if (NULL == userIconPath)
154 char buf[MAXPATHLEN+1];
157 home = getenv("HOME");
158 sprintf(buf, "%s/%s/icons", home, DtPERSONAL_CONFIG_DIRECTORY);
160 if (0 == stat(buf, &sbuf) &&
161 S_IFDIR & sbuf.st_mode &&
162 S_IWUSR & sbuf.st_mode)
164 userIconPath = XtNewString(buf);
167 if (NULL != userIconPath)
169 tmpXmStr8 = XmStringCreateLocalized(userIconPath);
170 XtVaSetValues(fileIODialog, XmNdirectory, tmpXmStr8, NULL);
171 XmStringFree(tmpXmStr8);
174 XmStringFree(tmpXmStr);
175 XmStringFree(tmpXmStr1);
176 XmStringFree(tmpXmStr2);
177 XmStringFree(tmpXmStr3);
178 XmStringFree(tmpXmStr4);
179 XmStringFree(tmpXmStr6);
180 XmStringFree(tmpXmStr7);
182 XtAddCallback(fileIODialog, XmNcancelCallback, cancelCB_fileIODialog, NULL);
183 XtAddCallback(fileIODialog, XmNokCallback, Do_FileIO, NULL);
186 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
187 XtSetArg (args[n], XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++;
188 XtSetValues (fileIODialog_shell, args, n);
191 /* check resources to get rid of unwanted children :-) */
192 if (!xrdb.useFileFilter)
194 /* remove file filter label and text, and filter button */
195 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_FILTER_LABEL);
196 XtUnmanageChild (wid);
197 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_FILTER_TEXT);
198 XtUnmanageChild (wid);
200 /* if no File Lists, unmanage it... otherwise rename it */
201 if (!xrdb.useFileLists)
203 XtUnmanageChild (XmFileSelectionBoxGetChild(fileIODialog,
204 XmDIALOG_APPLY_BUTTON));
209 tmpXmStr = GETXMSTR(2,18, "Update");
210 XtSetArg (args[n], XmNapplyLabelString, tmpXmStr); n++;
211 XtSetValues (fileIODialog, args, n);
212 XmStringFree(tmpXmStr);
215 if (!xrdb.useFileLists)
217 /* remove label and scrolled lists for directories and files */
218 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_DIR_LIST_LABEL);
219 XtUnmanageChild (wid);
220 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_LIST_LABEL);
221 XtUnmanageChild (wid);
222 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_DIR_LIST);
223 XtUnmanageChild (XtParent(wid));
224 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_LIST);
225 XtUnmanageChild (XtParent(wid));
228 return ( fileIODialog );
231 /*******************************************************************************
233 *******************************************************************************/