Merge branch 'master' into cde-next
[oweals/cde.git] / cde / programs / dtcreate / OpenFile.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: OpenFile.c /main/6 1996/10/17 14:06:40 rswiston $ */
24 /*******************************************************************************
25         OpenFile.c
26
27        Associated Header file: OpenFile.h
28 *******************************************************************************/
29
30 #include <stdio.h>
31 #include <Xm/Xm.h>
32 #include <Xm/MwmUtil.h>
33 #include <Xm/DialogS.h>
34 #include <Xm/MenuShell.h>
35 #include <Xm/FileSB.h>
36 #include <Dt/Icon.h>
37 #include "UxXt.h"
38 #include "dtcreate.h"
39 #include "cmnrtns.h"
40 #include "cmncbs.h"
41 #include "ca_aux.h"
42 #include "fileio.h"
43
44 #define CONTEXT_MACRO_ACCESS 1
45 #include "OpenFile.h"
46 #undef CONTEXT_MACRO_ACCESS
47
48 extern XtPointer
49 _XmStringUngenerate(XmString, XmStringTag, XmTextType, XmTextType);
50
51 /*******************************************************************************
52        The following are callback functions.
53 *******************************************************************************/
54
55 static  void    cancelCB_OpenFile( Widget UxWidget,
56                                   XtPointer UxClientData,
57                                   XtPointer UxCallbackArg )
58
59 {
60         _UxCOpenFile            *UxSaveCtx, *UxContext;
61
62         UxSaveCtx = UxOpenFileContext;
63         UxOpenFileContext = UxContext =
64                         (_UxCOpenFile *) UxGetContext( UxWidget );
65         {
66
67         UxPopdownInterface(UxWidget);
68         }
69         UxOpenFileContext = UxSaveCtx;
70 }
71
72 static  void    okCallback_OpenFile( Widget UxWidget,
73                                     XtPointer UxClientData,
74                                     XtPointer UxCallbackArg )
75
76 {
77         _UxCOpenFile                     *UxSaveCtx, *UxContext;
78         XmFileSelectionBoxCallbackStruct *cbs;
79         /*char        *text;*/
80         int         rc = 1; /* 1 = OpenDefinitionFile() failure */
81         ActionData  ADTmp;
82
83         UxSaveCtx = UxOpenFileContext;
84         UxOpenFileContext = UxContext =
85                         (_UxCOpenFile *) UxGetContext( UxWidget );
86         {
87
88         /********************************************************************/
89         /* Call file parsing code here!                                     */
90         /********************************************************************/
91         cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
92         if (pszFileToEdit) {
93            XtFree(pszFileToEdit);
94         }
95         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);
101            /*XtFree(text);*/
102            /*****************************************************************/
103            /* If everything ok, then clear out data from action structure   */
104            /* and store new data.                                           */
105            /*****************************************************************/
106            if (!rc) {
107               FreeAndClearAD(&AD);
108               memcpy(&AD, &ADTmp, sizeof(ActionData));
109            }
110         }
111         UxPopdownInterface (UxWidget);
112
113         /********************************************************************/
114         /* If successfully opened and parsed file, then init the fields of  */
115         /* the main window.                                                 */
116         /********************************************************************/
117         if (!rc) {
118            clear_CreateActionAppShell_fields();
119            writeCAToGUI(&AD);
120         }
121         }
122         UxOpenFileContext = UxSaveCtx;
123 }
124
125 static  void    helpCallback_OpenFile( Widget UxWidget,
126                                     XtPointer UxClientData,
127                                     XtPointer UxCallbackArg )
128
129 {
130         _UxCOpenFile            *UxSaveCtx, *UxContext;
131
132         UxSaveCtx = UxOpenFileContext;
133         UxOpenFileContext = UxContext =
134                         (_UxCOpenFile *) UxGetContext( UxWidget );
135         {
136         DisplayHelpDialog(UxWidget, (XtPointer)HELP_OPENFILE, UxCallbackArg);
137         }
138         UxOpenFileContext = UxSaveCtx;
139 }
140
141 /*******************************************************************************
142        The 'build_' function creates all the widgets
143        using the resource values specified in the Property Editor.
144 *******************************************************************************/
145
146 static Widget   _Uxbuild_OpenFile(void)
147 {
148         Widget          _UxParent;
149
150         /* Creation of OpenFile */
151         _UxParent = XtVaCreatePopupShell( "OpenFile_shell",
152                         xmDialogShellWidgetClass, UxTopLevel,
153                         XmNx, 200,
154                         XmNy, 290,
155                         XmNwidth, 398,
156                         XmNheight, 500,
157                         XmNallowShellResize, TRUE,
158                         XmNshellUnitType, XmPIXELS,
159                         XmNtitle, GETMESSAGE(12, 25, "Create Action - Open"),
160                         NULL );
161
162         OpenFile = XtVaCreateWidget( "OpenFile",
163                         xmFileSelectionBoxWidgetClass,
164                         _UxParent,
165                         XmNresizePolicy, XmRESIZE_GROW,
166                         XmNunitType, XmPIXELS,
167                         XmNwidth, 398,
168                         XmNheight, 500,
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,
174                         XmNtextColumns, 20,
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, "" ),
181                         NULL );
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);
192
193         UxPutContext( OpenFile, (char *) UxOpenFileContext );
194
195         XtAddCallback( OpenFile, XmNdestroyCallback,
196                 (XtCallbackProc) UxDestroyContextCB,
197                 (XtPointer) UxOpenFileContext);
198
199         return ( OpenFile );
200 }
201
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
206        a callback function.
207 *******************************************************************************/
208
209 Widget  create_OpenFile(void)
210 {
211         Widget                  rtrn;
212         _UxCOpenFile            *UxContext;
213
214         UxOpenFileContext = UxContext =
215                 (_UxCOpenFile *) UxNewContext( sizeof(_UxCOpenFile), False );
216
217
218         rtrn = _Uxbuild_OpenFile();
219
220         return(rtrn);
221 }
222
223 /*******************************************************************************
224        END OF FILE
225 *******************************************************************************/
226