Initial commit of pristine erwise source
[erwise] / Ui / UiDefaults.c
1 static char *rcsid = "$Id$";
2
3 #include "UiIncludes.h"
4
5 static void uibinddefaultsvariables(void);
6 static void uiupdatedefaultsvariables(void);
7 static Widget uicreatedefaultsformdialog();
8 static Widget uicreatedefaultslabel(Widget parent, Widget bottomwdg);
9 static Widget
10  uicreatedefaultsitem(char *name, Widget parent,
11                        Widget bottomwdg);
12 static Widget uicreatedefaultsclose(Widget parent);
13 static void uidefaultsclosecb(char *address, HText_t * htext,
14                            HTextObject_t * htextobject, void *parameter);
15
16
17 int UiDisplayDefaultsDialog()
18 {
19     uiDefaultsGfx_t *defaultsgfx = &uiTopLevel.DefaultsGfx;
20
21     uibinddefaultsvariables();
22
23     if (defaultsgfx->FormWdg) {
24         XtMapWidget(XtParent(defaultsgfx->FormWdg));
25
26         uiupdatedefaultsvariables();
27
28         return UI_OK;
29     }
30     defaultsgfx->FormWdg = uicreatedefaultsformdialog();
31     defaultsgfx->CloseWdg = uicreatedefaultsclose(defaultsgfx->FormWdg);
32     defaultsgfx->PageSettings = uicreatedefaultsitem("Page Settings window",
33                                                      defaultsgfx->FormWdg,
34                                                   defaultsgfx->CloseWdg);
35     defaultsgfx->RecallWindow =
36         uicreatedefaultsitem("Recall window",
37                              defaultsgfx->FormWdg,
38                              defaultsgfx->PageSettings);
39     defaultsgfx->ListWindow = uicreatedefaultsitem("List window",
40                                                    defaultsgfx->FormWdg,
41                                               defaultsgfx->RecallWindow);
42     defaultsgfx->ControlPanel = uicreatedefaultsitem("Control panel",
43                                                      defaultsgfx->FormWdg,
44                                                 defaultsgfx->ListWindow);
45     defaultsgfx->SearchWindow =
46         uicreatedefaultsitem("Search window", defaultsgfx->FormWdg,
47                              defaultsgfx->ControlPanel);
48     defaultsgfx->LabelWdg = uicreatedefaultslabel(defaultsgfx->FormWdg,
49                                               defaultsgfx->SearchWindow);
50
51     XtManageChild(defaultsgfx->FormWdg);
52     XtRealizeWidget(XtParent(defaultsgfx->FormWdg));
53
54     uiupdatedefaultsvariables();
55
56     return UI_OK;
57 }
58
59
60 void uiDefaultsUpdateDialog()
61 {
62     if (uiTopLevel.DefaultsGfx.FormWdg) {
63         if (uiPageInfo.CurrentPage) {
64             uibinddefaultsvariables();
65             uiupdatedefaultsvariables();
66         } else
67             XtUnmapWidget(XtParent(uiTopLevel.DefaultsGfx.FormWdg));
68     }
69 }
70
71
72 static void uibinddefaultsvariables()
73 {
74     UiBindVariable("Page Settings window",
75                (void *) &uiTopLevel.GlobalSettings.PageSettingsPlacement,
76                    uiVTint);
77     UiBindVariable("Recall window",
78                    (void *) &uiTopLevel.GlobalSettings.RecallPlacement,
79                    uiVTint);
80     UiBindVariable("List window",
81                    (void *) &uiTopLevel.GlobalSettings.ListPlacement,
82                    uiVTint);
83     UiBindVariable("Control panel",
84                (void *) &uiTopLevel.GlobalSettings.ControlPanelPlacement,
85                    uiVTint);
86     UiBindVariable("Search window",
87                    (void *) &uiTopLevel.GlobalSettings.SearchPlacement,
88                    uiVTint);
89 }
90
91
92 static void uiupdatedefaultsvariables()
93 {
94     UiUpdateVariable("Page Settings window");
95     UiUpdateVariable("Recall window");
96     UiUpdateVariable("List window");
97     UiUpdateVariable("Control panel");
98     UiUpdateVariable("Search window");
99 }
100
101
102 static Widget
103  uicreatedefaultsformdialog()
104 {
105     ArgList args;
106     Cardinal nargs;
107     Widget formwdg;
108     Widget topwdg;
109
110     topwdg = XtCreateApplicationShell("Defaults",
111                                       topLevelShellWidgetClass,
112                                       NULL, 0);
113     XtVaSetValues(topwdg,
114                   XmNtitle, UI_DEFAULTS_TITLE, NULL);
115
116     args = uiVaSetArgs(&nargs,
117                        XmNresizePolicy, XmRESIZE_NONE,
118                        XmNautoUnmanage, FALSE, NULL);
119     formwdg = XmCreateForm(topwdg, "Defaults", args, nargs);
120
121     return formwdg;
122 }
123
124 static Widget
125  uicreatedefaultslabel(parent, bottomwdg)
126 Widget parent;
127 Widget bottomwdg;
128 {
129     ArgList args;
130     Cardinal nargs;
131     Widget labelwdg;
132     XmString labelstr;
133
134     labelstr = XmStringCreateSimple("Follow pointer");
135
136     args = uiVaSetArgs(&nargs,
137                        XmNlabelString, labelstr,
138                        XmNtopAttachment, XmATTACH_FORM,
139                        XmNtopOffset, UI_DEFAULTS_WDG_OFFSET,
140                        XmNbottomAttachment, XmATTACH_WIDGET,
141                        XmNbottomWidget, bottomwdg,
142                        XmNbottomOffset, UI_DEFAULTS_WDG_OFFSET,
143                        XmNleftAttachment, XmATTACH_FORM,
144                        XmNrightAttachment, XmATTACH_FORM, NULL);
145     labelwdg = XmCreateLabelGadget(parent, "DEFAULTSLabel", args, nargs);
146     XtManageChild(labelwdg);
147
148     return labelwdg;
149 }
150
151
152 static Widget
153  uicreatedefaultsitem(name, parent, bottomwdg)
154 char *name;
155 Widget parent;
156 Widget bottomwdg;
157 {
158     ArgList args;
159     Cardinal nargs;
160     Widget formwdg;
161     Widget togglewdg;
162     static uiActionData_t actiondata;
163
164     args = uiVaSetArgs(&nargs,
165                        XmNbottomAttachment, XmATTACH_WIDGET,
166                        XmNbottomWidget, bottomwdg,
167                        XmNbottomOffset, UI_DEFAULTS_WDG_OFFSET,
168                        XmNleftAttachment, XmATTACH_FORM,
169                        XmNrightAttachment, XmATTACH_FORM, NULL);
170     formwdg = XmCreateForm(parent, name, args, nargs);
171     XtManageChild(formwdg);
172
173     togglewdg = XmCreateToggleButtonGadget(formwdg, name,
174                                            (ArgList) NULL, 0);
175     XtVaSetValues(togglewdg,
176                   XmNbottomAttachment, XmATTACH_FORM,
177                   XmNtopAttachment, XmATTACH_FORM,
178                   XmNleftAttachment, XmATTACH_FORM,
179                   XmNleftOffset, UI_DEFAULTS_WDG_OFFSET,
180                   XmNrightAttachment, XmATTACH_FORM,
181                   XmNrightOffset, UI_DEFAULTS_WDG_OFFSET, NULL);
182     XtAddCallback(togglewdg, XmNvalueChangedCallback,
183                   (XtCallbackProc) uiDialogVariableCB, (caddr_t) name);
184     /* Ignore */
185     (void) uiAddWidgetInfo(name, togglewdg, uiWTcheckbutton);
186     XtManageChild(togglewdg);
187
188     return formwdg;
189 }
190
191
192 static Widget
193  uicreatedefaultsclose(parent)
194 Widget parent;
195 {
196     ArgList args;
197     Cardinal nargs;
198     Widget separatorwdg;
199     Widget tmpwdg;
200     static uiActionData_t actiondata;
201
202     tmpwdg = XmCreatePushButtonGadget(parent, "Close", (ArgList) NULL, 0);
203     XtVaSetValues(tmpwdg,
204                   XmNwidth, 70,
205                   XmNbottomAttachment, XmATTACH_FORM,
206                   XmNbottomOffset, UI_DEFAULTS_WDG_OFFSET,
207                   XmNrightAttachment, XmATTACH_FORM,
208                   XmNrightOffset, UI_DEFAULTS_WDG_OFFSET, NULL);
209     actiondata.ActionName = "DefaultsClose";
210     actiondata.Page = uiPageInfo.CurrentPage;
211     XtAddCallback(tmpwdg, XmNactivateCallback,
212             (XtCallbackProc) uiDialogActivateCB, (caddr_t) & actiondata);
213     UiAttachCallback("DefaultsClose", uidefaultsclosecb,
214                      "DefaultsGfx.FormWdg");
215
216     XtManageChild(tmpwdg);
217
218     args = uiVaSetArgs(&nargs,
219                        XmNbottomAttachment, XmATTACH_WIDGET,
220                        XmNbottomWidget, tmpwdg,
221                        XmNbottomOffset, UI_DEFAULTS_WDG_OFFSET,
222                        XmNleftAttachment, XmATTACH_FORM,
223                        XmNrightAttachment, XmATTACH_FORM, NULL);
224     separatorwdg = XmCreateSeparatorGadget(parent, "DefaultsSeparator",
225                                            args, nargs);
226     XtManageChild(separatorwdg);
227
228     return separatorwdg;
229 }
230
231
232 static void setplacementvalue(uiconfigsetfp, table, item, placementvalue)
233 void *(*uiconfigsetfp) (void *table, char *item, void *value);
234 void *table;
235 char *item;
236 int placementvalue;
237 {
238     if (placementvalue)
239         uiconfigsetfp(table, item, "Mouse");
240     else
241         uiconfigsetfp(table, item, "Fixed");
242 }
243
244
245 static void uidefaultsclosecb(address, htext, htextobject, parameter)
246 char *address;
247 HText_t *htext;
248 HTextObject_t *htextobject;
249 void *parameter;
250 {
251     uiGlobalSettings_t *gs = &uiTopLevel.GlobalSettings;
252     void *table;
253
254     table = uiConfigPF((void *) NULL, C_GLOBALSETTINGS);
255     setplacementvalue(uiConfigSetPF, table, C_SEARCH, gs->SearchPlacement);
256     setplacementvalue(uiConfigSetPF, table, C_CONTROLPANEL, gs->ControlPanelPlacement);
257     setplacementvalue(uiConfigSetPF, table, C_LIST, gs->ListPlacement);
258     setplacementvalue(uiConfigSetPF, table, C_RECALL, gs->RecallPlacement);
259     setplacementvalue(uiConfigSetPF, table, C_PAGESETTINGS, gs->PageSettingsPlacement);
260
261     XtUnmapWidget(XtParent(uiTopLevel.DefaultsGfx.FormWdg));
262 }