73e3df4bd29416d6ea6756b7422e7fb602e9f36d
[oweals/cde.git] / cde / programs / dtcreate / OpenFile.c
1 /* $XConsortium: OpenFile.c /main/6 1996/10/17 14:06:40 rswiston $ */
2 /*******************************************************************************
3         OpenFile.c
4
5        Associated Header file: OpenFile.h
6 *******************************************************************************/
7
8 #include <stdio.h>
9 #include <Xm/Xm.h>
10 #include <Xm/MwmUtil.h>
11 #include <Xm/DialogS.h>
12 #include <Xm/MenuShell.h>
13 #include <Xm/FileSB.h>
14 #include <Dt/Icon.h>
15 #include "UxXt.h"
16 #include "dtcreate.h"
17 #include "cmnrtns.h"
18 #include "ca_aux.h"
19 #include "fileio.h"
20
21 #define CONTEXT_MACRO_ACCESS 1
22 #include "OpenFile.h"
23 #undef CONTEXT_MACRO_ACCESS
24
25 extern XtPointer
26 _XmStringUngenerate(XmString, XmStringTag, XmTextType, XmTextType);
27
28 /*******************************************************************************
29        The following are callback functions.
30 *******************************************************************************/
31
32 static  void    cancelCB_OpenFile( Widget UxWidget,
33                                   XtPointer UxClientData,
34                                   XtPointer UxCallbackArg )
35
36 {
37         _UxCOpenFile            *UxSaveCtx, *UxContext;
38
39         UxSaveCtx = UxOpenFileContext;
40         UxOpenFileContext = UxContext =
41                         (_UxCOpenFile *) UxGetContext( UxWidget );
42         {
43
44         UxPopdownInterface(UxWidget);
45         }
46         UxOpenFileContext = UxSaveCtx;
47 }
48
49 static  void    okCallback_OpenFile( Widget UxWidget,
50                                     XtPointer UxClientData,
51                                     XtPointer UxCallbackArg )
52
53 {
54         _UxCOpenFile                     *UxSaveCtx, *UxContext;
55         XmFileSelectionBoxCallbackStruct *cbs;
56         /*char        *text;*/
57         int         rc;
58         ActionData  ADTmp;
59
60         UxSaveCtx = UxOpenFileContext;
61         UxOpenFileContext = UxContext =
62                         (_UxCOpenFile *) UxGetContext( UxWidget );
63         {
64
65         /********************************************************************/
66         /* Call file parsing code here!                                     */
67         /********************************************************************/
68         cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
69         if (pszFileToEdit) {
70            XtFree(pszFileToEdit);
71         }
72         pszFileToEdit =
73             _XmStringUngenerate(cbs->value, NULL,
74                                 XmCHARSET_TEXT, XmCHARSET_TEXT);
75         if (pszFileToEdit != (char *)NULL) {
76            memset(&ADTmp, 0, sizeof(ActionData));
77            rc = OpenDefinitionFile(pszFileToEdit, &ADTmp);
78            /*XtFree(text);*/
79            /*****************************************************************/
80            /* If everything ok, then clear out data from action structure   */
81            /* and store new data.                                           */
82            /*****************************************************************/
83            if (!rc) {
84               FreeAndClearAD(&AD);
85               memcpy(&AD, &ADTmp, sizeof(ActionData));
86            }
87         }
88         UxPopdownInterface (UxWidget);
89
90         /********************************************************************/
91         /* If successfully opened and parsed file, then init the fields of  */
92         /* the main window.                                                 */
93         /********************************************************************/
94         if (!rc) {
95            clear_CreateActionAppShell_fields();
96            writeCAToGUI(&AD);
97         }
98         }
99         UxOpenFileContext = UxSaveCtx;
100 }
101
102 static  void    helpCallback_OpenFile( Widget UxWidget,
103                                     XtPointer UxClientData,
104                                     XtPointer UxCallbackArg )
105
106 {
107         _UxCOpenFile            *UxSaveCtx, *UxContext;
108
109         UxSaveCtx = UxOpenFileContext;
110         UxOpenFileContext = UxContext =
111                         (_UxCOpenFile *) UxGetContext( UxWidget );
112         {
113         DisplayHelpDialog(UxWidget, HELP_OPENFILE, UxCallbackArg);
114         }
115         UxOpenFileContext = UxSaveCtx;
116 }
117
118 /*******************************************************************************
119        The 'build_' function creates all the widgets
120        using the resource values specified in the Property Editor.
121 *******************************************************************************/
122
123 static Widget   _Uxbuild_OpenFile(void)
124 {
125         Widget          _UxParent;
126
127         /* Creation of OpenFile */
128         _UxParent = XtVaCreatePopupShell( "OpenFile_shell",
129                         xmDialogShellWidgetClass, UxTopLevel,
130                         XmNx, 200,
131                         XmNy, 290,
132                         XmNwidth, 398,
133                         XmNheight, 500,
134                         XmNallowShellResize, TRUE,
135                         XmNshellUnitType, XmPIXELS,
136                         XmNtitle, GETMESSAGE(12, 25, "Create Action - Open"),
137                         NULL );
138
139         OpenFile = XtVaCreateWidget( "OpenFile",
140                         xmFileSelectionBoxWidgetClass,
141                         _UxParent,
142                         XmNresizePolicy, XmRESIZE_GROW,
143                         XmNunitType, XmPIXELS,
144                         XmNwidth, 398,
145                         XmNheight, 500,
146                         RES_CONVERT( XmNdialogTitle, GETMESSAGE(12, 25, "Create Action - Open")),
147                         RES_CONVERT( XmNdirectory, "" ),
148                         RES_CONVERT( XmNtextString, "" ),
149                         RES_CONVERT( XmNdirSpec, "" ),
150                         XmNdialogType, XmDIALOG_FILE_SELECTION,
151                         XmNtextColumns, 20,
152                         XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
153                         XmNallowOverlap, FALSE,
154                         RES_CONVERT( XmNchildPlacement, "place_below_selection" ),
155                         XmNdefaultPosition, FALSE,
156                         RES_CONVERT( XmNdirMask, "" ),
157                         RES_CONVERT( XmNpattern, "" ),
158                         NULL );
159         XtAddCallback( OpenFile, XmNcancelCallback,
160                 (XtCallbackProc) cancelCB_OpenFile,
161                 (XtPointer) UxOpenFileContext );
162         XtAddCallback( OpenFile, XmNokCallback,
163                 (XtCallbackProc) okCallback_OpenFile,
164                 (XtPointer) UxOpenFileContext );
165         XtAddCallback( OpenFile, XmNhelpCallback,
166                 (XtCallbackProc) helpCallback_OpenFile,
167                 (XtPointer) UxOpenFileContext );
168         XtVaSetValues(OpenFile, XmNuserData, OpenFile, NULL);
169
170         UxPutContext( OpenFile, (char *) UxOpenFileContext );
171
172         XtAddCallback( OpenFile, XmNdestroyCallback,
173                 (XtCallbackProc) UxDestroyContextCB,
174                 (XtPointer) UxOpenFileContext);
175
176         return ( OpenFile );
177 }
178
179 /*******************************************************************************
180        The following is the 'Interface function' which is the
181        external entry point for creating this interface.
182        This function should be called from your application or from
183        a callback function.
184 *******************************************************************************/
185
186 Widget  create_OpenFile(void)
187 {
188         Widget                  rtrn;
189         _UxCOpenFile            *UxContext;
190
191         UxOpenFileContext = UxContext =
192                 (_UxCOpenFile *) UxNewContext( sizeof(_UxCOpenFile), False );
193
194
195         rtrn = _Uxbuild_OpenFile();
196
197         return(rtrn);
198 }
199
200 /*******************************************************************************
201        END OF FILE
202 *******************************************************************************/
203