Link with C++ linker
[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 librararies 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 "ca_aux.h"
41 #include "fileio.h"
42
43 #define CONTEXT_MACRO_ACCESS 1
44 #include "OpenFile.h"
45 #undef CONTEXT_MACRO_ACCESS
46
47 extern XtPointer
48 _XmStringUngenerate(XmString, XmStringTag, XmTextType, XmTextType);
49
50 /*******************************************************************************
51        The following are callback functions.
52 *******************************************************************************/
53
54 static  void    cancelCB_OpenFile( Widget UxWidget,
55                                   XtPointer UxClientData,
56                                   XtPointer UxCallbackArg )
57
58 {
59         _UxCOpenFile            *UxSaveCtx, *UxContext;
60
61         UxSaveCtx = UxOpenFileContext;
62         UxOpenFileContext = UxContext =
63                         (_UxCOpenFile *) UxGetContext( UxWidget );
64         {
65
66         UxPopdownInterface(UxWidget);
67         }
68         UxOpenFileContext = UxSaveCtx;
69 }
70
71 static  void    okCallback_OpenFile( Widget UxWidget,
72                                     XtPointer UxClientData,
73                                     XtPointer UxCallbackArg )
74
75 {
76         _UxCOpenFile                     *UxSaveCtx, *UxContext;
77         XmFileSelectionBoxCallbackStruct *cbs;
78         /*char        *text;*/
79         int         rc;
80         ActionData  ADTmp;
81
82         UxSaveCtx = UxOpenFileContext;
83         UxOpenFileContext = UxContext =
84                         (_UxCOpenFile *) UxGetContext( UxWidget );
85         {
86
87         /********************************************************************/
88         /* Call file parsing code here!                                     */
89         /********************************************************************/
90         cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
91         if (pszFileToEdit) {
92            XtFree(pszFileToEdit);
93         }
94         pszFileToEdit =
95             _XmStringUngenerate(cbs->value, NULL,
96                                 XmCHARSET_TEXT, XmCHARSET_TEXT);
97         if (pszFileToEdit != (char *)NULL) {
98            memset(&ADTmp, 0, sizeof(ActionData));
99            rc = OpenDefinitionFile(pszFileToEdit, &ADTmp);
100            /*XtFree(text);*/
101            /*****************************************************************/
102            /* If everything ok, then clear out data from action structure   */
103            /* and store new data.                                           */
104            /*****************************************************************/
105            if (!rc) {
106               FreeAndClearAD(&AD);
107               memcpy(&AD, &ADTmp, sizeof(ActionData));
108            }
109         }
110         UxPopdownInterface (UxWidget);
111
112         /********************************************************************/
113         /* If successfully opened and parsed file, then init the fields of  */
114         /* the main window.                                                 */
115         /********************************************************************/
116         if (!rc) {
117            clear_CreateActionAppShell_fields();
118            writeCAToGUI(&AD);
119         }
120         }
121         UxOpenFileContext = UxSaveCtx;
122 }
123
124 static  void    helpCallback_OpenFile( Widget UxWidget,
125                                     XtPointer UxClientData,
126                                     XtPointer UxCallbackArg )
127
128 {
129         _UxCOpenFile            *UxSaveCtx, *UxContext;
130
131         UxSaveCtx = UxOpenFileContext;
132         UxOpenFileContext = UxContext =
133                         (_UxCOpenFile *) UxGetContext( UxWidget );
134         {
135         DisplayHelpDialog(UxWidget, HELP_OPENFILE, UxCallbackArg);
136         }
137         UxOpenFileContext = UxSaveCtx;
138 }
139
140 /*******************************************************************************
141        The 'build_' function creates all the widgets
142        using the resource values specified in the Property Editor.
143 *******************************************************************************/
144
145 static Widget   _Uxbuild_OpenFile(void)
146 {
147         Widget          _UxParent;
148
149         /* Creation of OpenFile */
150         _UxParent = XtVaCreatePopupShell( "OpenFile_shell",
151                         xmDialogShellWidgetClass, UxTopLevel,
152                         XmNx, 200,
153                         XmNy, 290,
154                         XmNwidth, 398,
155                         XmNheight, 500,
156                         XmNallowShellResize, TRUE,
157                         XmNshellUnitType, XmPIXELS,
158                         XmNtitle, GETMESSAGE(12, 25, "Create Action - Open"),
159                         NULL );
160
161         OpenFile = XtVaCreateWidget( "OpenFile",
162                         xmFileSelectionBoxWidgetClass,
163                         _UxParent,
164                         XmNresizePolicy, XmRESIZE_GROW,
165                         XmNunitType, XmPIXELS,
166                         XmNwidth, 398,
167                         XmNheight, 500,
168                         RES_CONVERT( XmNdialogTitle, GETMESSAGE(12, 25, "Create Action - Open")),
169                         RES_CONVERT( XmNdirectory, "" ),
170                         RES_CONVERT( XmNtextString, "" ),
171                         RES_CONVERT( XmNdirSpec, "" ),
172                         XmNdialogType, XmDIALOG_FILE_SELECTION,
173                         XmNtextColumns, 20,
174                         XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
175                         XmNallowOverlap, FALSE,
176                         RES_CONVERT( XmNchildPlacement, "place_below_selection" ),
177                         XmNdefaultPosition, FALSE,
178                         RES_CONVERT( XmNdirMask, "" ),
179                         RES_CONVERT( XmNpattern, "" ),
180                         NULL );
181         XtAddCallback( OpenFile, XmNcancelCallback,
182                 (XtCallbackProc) cancelCB_OpenFile,
183                 (XtPointer) UxOpenFileContext );
184         XtAddCallback( OpenFile, XmNokCallback,
185                 (XtCallbackProc) okCallback_OpenFile,
186                 (XtPointer) UxOpenFileContext );
187         XtAddCallback( OpenFile, XmNhelpCallback,
188                 (XtCallbackProc) helpCallback_OpenFile,
189                 (XtPointer) UxOpenFileContext );
190         XtVaSetValues(OpenFile, XmNuserData, OpenFile, NULL);
191
192         UxPutContext( OpenFile, (char *) UxOpenFileContext );
193
194         XtAddCallback( OpenFile, XmNdestroyCallback,
195                 (XtCallbackProc) UxDestroyContextCB,
196                 (XtPointer) UxOpenFileContext);
197
198         return ( OpenFile );
199 }
200
201 /*******************************************************************************
202        The following is the 'Interface function' which is the
203        external entry point for creating this interface.
204        This function should be called from your application or from
205        a callback function.
206 *******************************************************************************/
207
208 Widget  create_OpenFile(void)
209 {
210         Widget                  rtrn;
211         _UxCOpenFile            *UxContext;
212
213         UxOpenFileContext = UxContext =
214                 (_UxCOpenFile *) UxNewContext( sizeof(_UxCOpenFile), False );
215
216
217         rtrn = _Uxbuild_OpenFile();
218
219         return(rtrn);
220 }
221
222 /*******************************************************************************
223        END OF FILE
224 *******************************************************************************/
225