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 /* $XConsortium: OpenFile.c /main/6 1996/10/17 14:06:40 rswiston $ */
24 /*******************************************************************************
27 Associated Header file: OpenFile.h
28 *******************************************************************************/
32 #include <Xm/MwmUtil.h>
33 #include <Xm/DialogS.h>
34 #include <Xm/MenuShell.h>
35 #include <Xm/FileSB.h>
44 #define CONTEXT_MACRO_ACCESS 1
46 #undef CONTEXT_MACRO_ACCESS
49 _XmStringUngenerate(XmString, XmStringTag, XmTextType, XmTextType);
51 /*******************************************************************************
52 The following are callback functions.
53 *******************************************************************************/
55 static void cancelCB_OpenFile( Widget UxWidget,
56 XtPointer UxClientData,
57 XtPointer UxCallbackArg )
60 _UxCOpenFile *UxSaveCtx, *UxContext;
62 UxSaveCtx = UxOpenFileContext;
63 UxOpenFileContext = UxContext =
64 (_UxCOpenFile *) UxGetContext( UxWidget );
67 UxPopdownInterface(UxWidget);
69 UxOpenFileContext = UxSaveCtx;
72 static void okCallback_OpenFile( Widget UxWidget,
73 XtPointer UxClientData,
74 XtPointer UxCallbackArg )
77 _UxCOpenFile *UxSaveCtx, *UxContext;
78 XmFileSelectionBoxCallbackStruct *cbs;
80 int rc = 1; /* 1 = OpenDefinitionFile() failure */
83 UxSaveCtx = UxOpenFileContext;
84 UxOpenFileContext = UxContext =
85 (_UxCOpenFile *) UxGetContext( UxWidget );
88 /********************************************************************/
89 /* Call file parsing code here! */
90 /********************************************************************/
91 cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
93 XtFree(pszFileToEdit);
96 _XmStringUngenerate(cbs->value, NULL,
97 XmCHARSET_TEXT, XmCHARSET_TEXT);
98 if (pszFileToEdit != (char *)NULL) {
99 memset(&ADTmp, 0, sizeof(ActionData));
100 rc = OpenDefinitionFile(pszFileToEdit, &ADTmp);
102 /*****************************************************************/
103 /* If everything ok, then clear out data from action structure */
104 /* and store new data. */
105 /*****************************************************************/
108 memcpy(&AD, &ADTmp, sizeof(ActionData));
111 UxPopdownInterface (UxWidget);
113 /********************************************************************/
114 /* If successfully opened and parsed file, then init the fields of */
115 /* the main window. */
116 /********************************************************************/
118 clear_CreateActionAppShell_fields();
122 UxOpenFileContext = UxSaveCtx;
125 static void helpCallback_OpenFile( Widget UxWidget,
126 XtPointer UxClientData,
127 XtPointer UxCallbackArg )
130 _UxCOpenFile *UxSaveCtx, *UxContext;
132 UxSaveCtx = UxOpenFileContext;
133 UxOpenFileContext = UxContext =
134 (_UxCOpenFile *) UxGetContext( UxWidget );
136 DisplayHelpDialog(UxWidget, (XtPointer)HELP_OPENFILE, UxCallbackArg);
138 UxOpenFileContext = UxSaveCtx;
141 /*******************************************************************************
142 The 'build_' function creates all the widgets
143 using the resource values specified in the Property Editor.
144 *******************************************************************************/
146 static Widget _Uxbuild_OpenFile(void)
150 /* Creation of OpenFile */
151 _UxParent = XtVaCreatePopupShell( "OpenFile_shell",
152 xmDialogShellWidgetClass, UxTopLevel,
157 XmNallowShellResize, TRUE,
158 XmNshellUnitType, XmPIXELS,
159 XmNtitle, GETMESSAGE(12, 25, "Create Action - Open"),
162 OpenFile = XtVaCreateWidget( "OpenFile",
163 xmFileSelectionBoxWidgetClass,
165 XmNresizePolicy, XmRESIZE_GROW,
166 XmNunitType, XmPIXELS,
169 RES_CONVERT( XmNdialogTitle, GETMESSAGE(12, 25, "Create Action - Open")),
170 RES_CONVERT( XmNdirectory, "" ),
171 RES_CONVERT( XmNtextString, "" ),
172 RES_CONVERT( XmNdirSpec, "" ),
173 XmNdialogType, XmDIALOG_FILE_SELECTION,
175 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
176 XmNallowOverlap, FALSE,
177 RES_CONVERT( XmNchildPlacement, "place_below_selection" ),
178 XmNdefaultPosition, FALSE,
179 RES_CONVERT( XmNdirMask, "" ),
180 RES_CONVERT( XmNpattern, "" ),
182 XtAddCallback( OpenFile, XmNcancelCallback,
183 (XtCallbackProc) cancelCB_OpenFile,
184 (XtPointer) UxOpenFileContext );
185 XtAddCallback( OpenFile, XmNokCallback,
186 (XtCallbackProc) okCallback_OpenFile,
187 (XtPointer) UxOpenFileContext );
188 XtAddCallback( OpenFile, XmNhelpCallback,
189 (XtCallbackProc) helpCallback_OpenFile,
190 (XtPointer) UxOpenFileContext );
191 XtVaSetValues(OpenFile, XmNuserData, OpenFile, NULL);
193 UxPutContext( OpenFile, (char *) UxOpenFileContext );
195 XtAddCallback( OpenFile, XmNdestroyCallback,
196 (XtCallbackProc) UxDestroyContextCB,
197 (XtPointer) UxOpenFileContext);
202 /*******************************************************************************
203 The following is the 'Interface function' which is the
204 external entry point for creating this interface.
205 This function should be called from your application or from
207 *******************************************************************************/
209 Widget create_OpenFile(void)
212 _UxCOpenFile *UxContext;
214 UxOpenFileContext = UxContext =
215 (_UxCOpenFile *) UxNewContext( sizeof(_UxCOpenFile), False );
218 rtrn = _Uxbuild_OpenFile();
223 /*******************************************************************************
225 *******************************************************************************/