Some compile fixes, not enough
[erwise] / Ui / UiFileSelection.c
1 static char *rcsid = "$Id$";
2
3 #include "UiIncludes.h"
4
5
6 static Widget uicreatefsformdialog();
7 static Widget
8  uicreatefsfsbox(Widget formwdg,
9                   void (*callback) (char *topaddress,
10                                      HText_t * htext,
11                                      HTextObject_t * htextobject,
12                                      void *parameter));
13 static void uifileselectionokcb(Widget wdg, caddr_t callback,
14                                  XmPushButtonCallbackStruct * calldata);
15 static void uifileselectioncancelcb(Widget wdg, caddr_t ignored,
16                                   XmPushButtonCallbackStruct * calldata);
17 static void uifileselectionclickcb(Widget wdg, caddr_t ignored,
18                                     XmListCallbackStruct * calldata);
19
20
21 uiTopLevel_t uiTopLevel;
22
23
24 int UiDisplayFileSelection(callback)
25 void (*callback) (char *topaddress, HText_t * htext, HTextObject_t * htextobject,
26                    void *parameter);
27 {
28     uiFileSelectionGfx_t *fsgfx = &uiTopLevel.FSGfx;
29
30     if (fsgfx->FormWdg) {
31         XtMapWidget(XtParent(fsgfx->FormWdg));
32
33         return UI_OK;
34     }
35     fsgfx->FormWdg = uicreatefsformdialog();
36     fsgfx->FSBoxWdg = uicreatefsfsbox(fsgfx->FormWdg, callback);
37
38     XtManageChild(fsgfx->FormWdg);
39     XtRealizeWidget(XtParent(fsgfx->FormWdg));
40
41     return UI_OK;
42 }
43
44
45 static Widget
46  uicreatefsformdialog()
47 {
48     ArgList args;
49     Cardinal nargs;
50     Widget formwdg;
51     Widget topwdg;
52
53     topwdg = XtCreateApplicationShell("FileSelection",
54                                       topLevelShellWidgetClass,
55                                       NULL, 0);
56
57     args = uiVaSetArgs(&nargs,
58                        XmNresizePolicy, XmRESIZE_NONE,
59                        XmNautoUnmanage, FALSE, NULL);
60     formwdg = XmCreateForm(topwdg, "FileSelection",
61                            args, nargs);
62
63     return formwdg;
64 }
65
66
67 static Widget
68  uicreatefsfsbox(formwdg, callback)
69 Widget formwdg;
70 void (*callback) (char *topaddress, HText_t * htext,
71                    HTextObject_t * htextobject, void *parameter);
72 {
73     ArgList args;
74     Cardinal nargs;
75     Widget fsboxwdg, textwdg, okwdg, cancelwdg;
76
77     args = uiVaSetArgs(&nargs,
78                        XmNtopAttachment, XmATTACH_FORM,
79                        XmNtopOffset, 1,
80                        XmNleftAttachment, XmATTACH_FORM,
81                        XmNleftOffset, 1,
82                        XmNrightAttachment, XmATTACH_FORM,
83                        XmNrightOffset, 1,
84                        XmNbottomOffset, 1,
85                        XmNbottomAttachment, XmATTACH_FORM, NULL);
86     fsboxwdg = XmCreateFileSelectionBox(formwdg, "FSBox",
87                                         args, nargs);
88     XtUnmanageChild(XmFileSelectionBoxGetChild(fsboxwdg,
89                                                XmDIALOG_HELP_BUTTON));
90
91     textwdg = XmFileSelectionBoxGetChild(fsboxwdg, XmDIALOG_TEXT);
92     XmTextSetString(textwdg, "");
93
94     okwdg = XmFileSelectionBoxGetChild(fsboxwdg, XmDIALOG_OK_BUTTON);
95     XtAddCallback(okwdg, XmNactivateCallback, uifileselectionokcb,
96                   (caddr_t) callback);
97
98     cancelwdg = XmFileSelectionBoxGetChild(fsboxwdg, XmDIALOG_CANCEL_BUTTON);
99     XtAddCallback(cancelwdg, XmNactivateCallback, uifileselectioncancelcb,
100                   (caddr_t) NULL);
101     XtManageChild(fsboxwdg);
102
103     return fsboxwdg;
104 }
105
106
107 static void uifileselectionokcb(wdg, callback, calldata)
108 Widget wdg;
109 caddr_t callback;
110 XmPushButtonCallbackStruct *calldata;
111 {
112     Widget textwdg;
113     char *selection;
114
115     textwdg = XmFileSelectionBoxGetChild(uiTopLevel.FSGfx.FSBoxWdg,
116                                          XmDIALOG_TEXT);
117     selection = XmTextGetString(textwdg);
118     XtUnmapWidget(XtParent(uiTopLevel.FSGfx.FormWdg));
119     (*(void (*) (char *, HText_t *, HTextObject_t *, void *)) callback)
120         (uiPageInfo.CurrentPage->Hierarchy->Address,
121       uiPageInfo.CurrentPage->HText, uiPageInfo.CurrentPage->HTextObject,
122          (void *) selection);
123
124     XtFree(selection);
125 }
126
127
128 static void uifileselectioncancelcb(wdg, ignored, calldata)
129 Widget wdg;
130 caddr_t ignored;
131 XmPushButtonCallbackStruct *calldata;
132 {
133     XtUnmapWidget(XtParent(uiTopLevel.FSGfx.FormWdg));
134 }
135
136
137 static void uifileselectionclickcb(wdg, ignored, calldata)
138 Widget wdg;
139 caddr_t ignored;
140 XmListCallbackStruct *calldata;
141 {
142     Widget textwdg;
143     char *selection;
144
145     XmStringGetLtoR(calldata->item, XmSTRING_DEFAULT_CHARSET, &selection);
146     textwdg = XmFileSelectionBoxGetChild(uiTopLevel.FSGfx.FSBoxWdg,
147                                          XmDIALOG_TEXT);
148     XmTextSetString(textwdg, selection);
149     XtFree(selection);
150 }