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: fileIODialog.c /main/6 1999/06/01 10:55:30 mgreess $ */
24 /*********************************************************************
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
28 * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
30 **********************************************************************/
31 /*******************************************************************************
34 *******************************************************************************/
38 #include <sys/types.h>
40 #include <sys/param.h>
42 #include <Xm/FileSB.h>
43 #include <Xm/DialogS.h>
44 #include <Xm/MwmUtil.h>
46 #include "externals.h"
47 #include <Dt/DtPStrings.h>
49 #include <Xm/FileSB.h>
51 /*******************************************************************************
52 Includes, Defines, and Global variables from the Declarations Editor:
53 *******************************************************************************/
55 extern void Do_FileIO();
59 /*******************************************************************************
60 Forward declarations of functions that are defined later in this file.
61 *******************************************************************************/
63 Widget create_fileIODialog();
65 /*******************************************************************************
66 The following are callback functions.
67 *******************************************************************************/
70 cancelCB_fileIODialog(
73 XtPointer callbackArg )
75 XtUnmanageChild(fileIODialog);
78 /*******************************************************************************
79 The following is the 'Interface function' which is the
80 external entry point for creating this interface.
81 This function should be called from your application or from
83 *******************************************************************************/
85 create_fileIODialog( void )
87 Widget fileIODialog_shell, wid;
88 XmString tmpXmStr, tmpXmStr1, tmpXmStr2, tmpXmStr3, tmpXmStr4,
89 tmpXmStr6, tmpXmStr7, tmpXmStr8;
92 char *userIconPath, *s;
95 userIconPath = getenv("XMICONSEARCHPATH");
96 if (NULL == userIconPath)
97 userIconPath = getenv("XMICONBMSEARCHPATH");
98 if (NULL == userIconPath)
99 userIconPath = getenv("HOME");
101 if (NULL != userIconPath)
105 userIconPath = XtNewString(userIconPath);
106 s = strchr(userIconPath, ':');
107 if (NULL != s) *s = '\0';
108 s = strrchr(userIconPath, '/');
109 if (NULL != s) *s = '\0';
112 fileIODialog_shell = XtVaCreatePopupShell( "fileIODialog_shell",
113 xmDialogShellWidgetClass, mainWindow,
114 XmNtitle, GETSTR(2,2, "Icon Editor - File I/O"),
117 tmpXmStr = GETXMSTR(2,6, "Icon Editor - Save As");
118 tmpXmStr1 = GETXMSTR(2,10, "Filter");
119 tmpXmStr2 = GETXMSTR(2,12, "Folders");
120 tmpXmStr3 = GETXMSTR(2,14, "Files");
121 tmpXmStr4 = GETXMSTR(2,16, "Enter file name:");
122 tmpXmStr6 = GETXMSTR(4,8, "Cancel");
123 tmpXmStr7 = GETXMSTR(4,10, "Help");
125 fileIODialog = XtVaCreateWidget( "fileIODialog",
126 xmFileSelectionBoxWidgetClass, fileIODialog_shell,
127 XmNdialogTitle, tmpXmStr,
128 XmNfilterLabelString, tmpXmStr1,
129 XmNdirListLabelString, tmpXmStr2,
130 XmNfileListLabelString, tmpXmStr3,
131 XmNselectionLabelString, tmpXmStr4,
132 XmNapplyLabelString, tmpXmStr1,
133 XmNcancelLabelString, tmpXmStr6,
134 XmNhelpLabelString, tmpXmStr7,
137 userIconPath = getenv("XMICONSEARCHPATH");
138 if (NULL != userIconPath)
140 userIconPath = XtNewString(userIconPath);
141 s = strchr(userIconPath, ':');
142 if (NULL != s) *s = '\0';
143 s = strrchr(userIconPath, '/');
144 if (NULL != s && userIconPath != s) *s = '\0';
146 if (0 != stat(userIconPath, &sbuf) ||
147 0 == (S_IFDIR & sbuf.st_mode) ||
148 0 == (S_IWUSR & sbuf.st_mode))
150 XtFree(userIconPath);
154 if (NULL == userIconPath)
156 userIconPath = getenv("XMICONBMSEARCHPATH");
157 if (NULL != userIconPath)
159 userIconPath = XtNewString(userIconPath);
160 s = strchr(userIconPath, ':');
161 if (NULL != s) *s = '\0';
162 s = strrchr(userIconPath, '/');
163 if (NULL != s && userIconPath != s) *s = '\0';
165 if (0 != stat(userIconPath, &sbuf) ||
166 0 == (S_IFDIR & sbuf.st_mode) ||
167 0 == (S_IWUSR & sbuf.st_mode))
169 XtFree(userIconPath);
174 if (NULL == userIconPath)
176 char buf[MAXPATHLEN+1];
179 home = getenv("HOME");
180 sprintf(buf, "%s/%s/icons", home, DtPERSONAL_CONFIG_DIRECTORY);
182 if (0 == stat(buf, &sbuf) &&
183 S_IFDIR & sbuf.st_mode &&
184 S_IWUSR & sbuf.st_mode)
186 userIconPath = XtNewString(buf);
189 if (NULL != userIconPath)
191 tmpXmStr8 = XmStringCreateLocalized(userIconPath);
192 XtVaSetValues(fileIODialog, XmNdirectory, tmpXmStr8, NULL);
193 XmStringFree(tmpXmStr8);
196 XmStringFree(tmpXmStr);
197 XmStringFree(tmpXmStr1);
198 XmStringFree(tmpXmStr2);
199 XmStringFree(tmpXmStr3);
200 XmStringFree(tmpXmStr4);
201 XmStringFree(tmpXmStr6);
202 XmStringFree(tmpXmStr7);
204 XtAddCallback(fileIODialog, XmNcancelCallback, cancelCB_fileIODialog, NULL);
205 XtAddCallback(fileIODialog, XmNokCallback, Do_FileIO, NULL);
208 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
209 XtSetArg (args[n], XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++;
210 XtSetValues (fileIODialog_shell, args, n);
213 /* check resources to get rid of unwanted children :-) */
214 if (!xrdb.useFileFilter)
216 /* remove file filter label and text, and filter button */
217 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_FILTER_LABEL);
218 XtUnmanageChild (wid);
219 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_FILTER_TEXT);
220 XtUnmanageChild (wid);
222 /* if no File Lists, unmanage it... otherwise rename it */
223 if (!xrdb.useFileLists)
225 XtUnmanageChild (XmFileSelectionBoxGetChild(fileIODialog,
226 XmDIALOG_APPLY_BUTTON));
231 tmpXmStr = GETXMSTR(2,18, "Update");
232 XtSetArg (args[n], XmNapplyLabelString, tmpXmStr); n++;
233 XtSetValues (fileIODialog, args, n);
234 XmStringFree(tmpXmStr);
237 if (!xrdb.useFileLists)
239 /* remove label and scrolled lists for directories and files */
240 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_DIR_LIST_LABEL);
241 XtUnmanageChild (wid);
242 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_LIST_LABEL);
243 XtUnmanageChild (wid);
244 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_DIR_LIST);
245 XtUnmanageChild (XtParent(wid));
246 wid = XmFileSelectionBoxGetChild(fileIODialog, XmDIALOG_LIST);
247 XtUnmanageChild (XtParent(wid));
250 return ( fileIODialog );
253 /*******************************************************************************
255 *******************************************************************************/