1 /* $XConsortium: OpenFile.c /main/6 1996/10/17 14:06:40 rswiston $ */
2 /*******************************************************************************
5 Associated Header file: OpenFile.h
6 *******************************************************************************/
10 #include <Xm/MwmUtil.h>
11 #include <Xm/DialogS.h>
12 #include <Xm/MenuShell.h>
13 #include <Xm/FileSB.h>
21 #define CONTEXT_MACRO_ACCESS 1
23 #undef CONTEXT_MACRO_ACCESS
26 _XmStringUngenerate(XmString, XmStringTag, XmTextType, XmTextType);
28 /*******************************************************************************
29 The following are callback functions.
30 *******************************************************************************/
32 static void cancelCB_OpenFile( Widget UxWidget,
33 XtPointer UxClientData,
34 XtPointer UxCallbackArg )
37 _UxCOpenFile *UxSaveCtx, *UxContext;
39 UxSaveCtx = UxOpenFileContext;
40 UxOpenFileContext = UxContext =
41 (_UxCOpenFile *) UxGetContext( UxWidget );
44 UxPopdownInterface(UxWidget);
46 UxOpenFileContext = UxSaveCtx;
49 static void okCallback_OpenFile( Widget UxWidget,
50 XtPointer UxClientData,
51 XtPointer UxCallbackArg )
54 _UxCOpenFile *UxSaveCtx, *UxContext;
55 XmFileSelectionBoxCallbackStruct *cbs;
60 UxSaveCtx = UxOpenFileContext;
61 UxOpenFileContext = UxContext =
62 (_UxCOpenFile *) UxGetContext( UxWidget );
65 /********************************************************************/
66 /* Call file parsing code here! */
67 /********************************************************************/
68 cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
70 XtFree(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);
79 /*****************************************************************/
80 /* If everything ok, then clear out data from action structure */
81 /* and store new data. */
82 /*****************************************************************/
85 memcpy(&AD, &ADTmp, sizeof(ActionData));
88 UxPopdownInterface (UxWidget);
90 /********************************************************************/
91 /* If successfully opened and parsed file, then init the fields of */
92 /* the main window. */
93 /********************************************************************/
95 clear_CreateActionAppShell_fields();
99 UxOpenFileContext = UxSaveCtx;
102 static void helpCallback_OpenFile( Widget UxWidget,
103 XtPointer UxClientData,
104 XtPointer UxCallbackArg )
107 _UxCOpenFile *UxSaveCtx, *UxContext;
109 UxSaveCtx = UxOpenFileContext;
110 UxOpenFileContext = UxContext =
111 (_UxCOpenFile *) UxGetContext( UxWidget );
113 DisplayHelpDialog(UxWidget, HELP_OPENFILE, UxCallbackArg);
115 UxOpenFileContext = UxSaveCtx;
118 /*******************************************************************************
119 The 'build_' function creates all the widgets
120 using the resource values specified in the Property Editor.
121 *******************************************************************************/
123 static Widget _Uxbuild_OpenFile(void)
127 /* Creation of OpenFile */
128 _UxParent = XtVaCreatePopupShell( "OpenFile_shell",
129 xmDialogShellWidgetClass, UxTopLevel,
134 XmNallowShellResize, TRUE,
135 XmNshellUnitType, XmPIXELS,
136 XmNtitle, GETMESSAGE(12, 25, "Create Action - Open"),
139 OpenFile = XtVaCreateWidget( "OpenFile",
140 xmFileSelectionBoxWidgetClass,
142 XmNresizePolicy, XmRESIZE_GROW,
143 XmNunitType, XmPIXELS,
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,
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, "" ),
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);
170 UxPutContext( OpenFile, (char *) UxOpenFileContext );
172 XtAddCallback( OpenFile, XmNdestroyCallback,
173 (XtCallbackProc) UxDestroyContextCB,
174 (XtPointer) UxOpenFileContext);
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
184 *******************************************************************************/
186 Widget create_OpenFile(void)
189 _UxCOpenFile *UxContext;
191 UxOpenFileContext = UxContext =
192 (_UxCOpenFile *) UxNewContext( sizeof(_UxCOpenFile), False );
195 rtrn = _Uxbuild_OpenFile();
200 /*******************************************************************************
202 *******************************************************************************/