Initial commit.
[amiga/xmodule.git] / PrefsWin.c
1 /*
2 **      PrefsWin.c
3 **
4 **      Copyright (C) 1994,95,96,97 by Bernardo Innocenti
5 **
6 **      Preferences panel handling routines.
7 */
8
9 #include <intuition/intuition.h>
10 #include <intuition/gadgetclass.h>
11 #include <libraries/gadtools.h>
12 #include <libraries/asl.h>
13 #include <graphics/displayinfo.h>
14
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/graphics.h>
18 #include <proto/gadtools.h>
19
20 #include "XModulePriv.h"
21 #include "Gui.h"
22 #include "CustomClasses.h"
23
24
25
26 /* Gadgets IDs */
27
28 enum {
29         GD_PrefsGroup0,
30                 GD_PrefsGroup1,
31                         GD_PrefsGroup2,
32                                 GD_PubScreen,
33                                 GD_GetPubScreen,
34                         GD_PrefsGroup3,
35                                 GD_DisplayMode,
36                                 GD_GetDisplayMode,
37                         GD_PrefsGroup4,
38                                 GD_WindowFont,
39                                 GD_GetWindowFont,
40                         GD_PrefsGroup5,
41                                 GD_ListViewFont,
42                                 GD_GetListViewFont,
43                 GD_PrefsGroup6,
44                         GD_PrefsGroup7,
45                                 GD_Requesters,
46                                 GD_Refresh,
47                         GD_PrefsGroup8,
48                                 GD_UseDataTypes,
49                                 GD_AppIcon,
50                 GD_PrefsGroup9,
51                         GD_LogLevel,
52                         GD_PrefsGroup10,
53                                 GD_LogToFile,
54                                 GD_LogFile,
55                 GD_PrefsGroup11,
56                         GD_PrefsGroup12,
57                                 GD_AutosaveTime,
58                                 GD_AskAutosave,
59                         GD_PrefsGroup13,
60                                 GD_DoBackups,
61                                 GD_BackupVersions,
62                         GD_BackupTemplate,
63                 GD_PrefsGroup14,
64                         GD_PrefsUse,
65                         GD_PrefsCancel,
66
67         Prefs_CNT
68 };
69
70
71
72 /* Local functions prototypes */
73
74 static void PrefsPostOpen                       (struct WinUserData *wud);
75 static void PrefsPostClose                      (void);
76
77 static void PubScreenClicked            (struct WinUserData *wud);
78 static void GetPubScreenClicked         (struct WinUserData *wud);
79 static void GetDisplayModeClicked       (struct WinUserData *wud);
80 static void GetWindowFontClicked        (struct WinUserData *wud);
81 static void GetListViewFontClicked      (struct WinUserData *wud);
82 static void RequestersClicked           (struct WinUserData *wud);
83 static void RefreshClicked                      (struct WinUserData *wud);
84 static void LogLevelClicked                     (struct WinUserData *wud);
85 static void LogFileClicked                      (struct WinUserData *wud);
86 static void     BackupTemplateClicked   (struct WinUserData *wud);
87 static void BackupVersionsClicked       (struct WinUserData *wud);
88 static void AutosaveTimeClicked         (struct WinUserData *wud);
89 static void PrefsUseClicked                     (struct WinUserData *wud);
90 static void PrefsCancelClicked          (struct WinUserData *wud);
91
92
93
94 /* Local data */
95
96 static struct ScrInfo NewScrInfo;
97 static struct GuiSwitches NewGuiSwitches;
98 static struct TextAttr NewWindowAttr;
99 static struct TextAttr NewListAttr;
100
101
102
103 static UBYTE *RequestersLabels[] = {
104         (UBYTE *)MSG_ASL_GAD,
105         (UBYTE *)MSG_REQTOOLS_GAD,
106         NULL
107 };
108
109
110 static UBYTE *RefreshLabels[] = {
111         (UBYTE *)MSG_SIMPLE_GAD,
112         (UBYTE *)MSG_SMART_GAD,
113         NULL
114 };
115
116
117
118 static ULONG PrefsArgs[] =
119 {
120         VGROUP_KIND, BBFT_RIDGE,
121                 HGROUP_KIND, 0,
122                         STRING_KIND,            (ULONG)PubScreenClicked,        MSG_PUBLIC_SCREEN_GAD,  32,     TAG_DONE,
123                         IMAGEBUTTON_KIND,       (ULONG)GetPubScreenClicked,     IM_PICK,                                        TAG_DONE,
124                         ENDGROUP_KIND,
125                 HGROUP_KIND, 0,
126                         TEXT_KIND,                      MSG_DISPLAY_MODE_GAD,                   0,                      GTTX_Border,    TRUE,   TAG_DONE,
127                         IMAGEBUTTON_KIND,       (ULONG)GetDisplayModeClicked,   IM_PICK,        TAG_DONE,
128                         ENDGROUP_KIND,
129                 HGROUP_KIND, 0,
130                         TEXT_KIND,                      MSG_WINDOW_FONT_GAD,                    0,                      GTTX_Border,    TRUE,   TAG_DONE,
131                         IMAGEBUTTON_KIND,       (ULONG)GetWindowFontClicked,    IM_PICK,        TAG_DONE,
132                         ENDGROUP_KIND,
133                 HGROUP_KIND, 0,
134                         TEXT_KIND,                      MSG_LISTVIEW_FONT_GAD,                  0,                      GTTX_Border,    TRUE,   TAG_DONE,
135                         IMAGEBUTTON_KIND,       (ULONG)GetListViewFontClicked,  IM_PICK,        TAG_DONE,
136                         ENDGROUP_KIND,
137                 ENDGROUP_KIND,
138         HGROUP_KIND, BBFT_RIDGE,
139                 VGROUP_KIND, 0,
140                         CYCLE_KIND,             (ULONG)RequestersClicked,       MSG_REQUESTERS_GAD,     (ULONG)RequestersLabels,        TAG_DONE,
141                         CYCLE_KIND,             (ULONG)RefreshClicked,          MSG_REFRESH_GAD,        (ULONG)RefreshLabels,           TAG_DONE,
142                         ENDGROUP_KIND,
143                 VGROUP_KIND, 0,
144                         CHECKBOX_KIND,  NULL,   MSG_USE_DATATYPES_GAD,  (ULONG)&NewGuiSwitches.UseDataTypes,    TAG_DONE,
145                         CHECKBOX_KIND,  NULL,   MSG_APPICON_GAD,                (ULONG)&NewGuiSwitches.ShowAppIcon,             TAG_DONE,
146                         ENDGROUP_KIND,
147                 ENDGROUP_KIND,
148                 VGROUP_KIND, BBFT_RIDGE,
149                         SLIDER_KIND,    (ULONG)LogLevelClicked, MSG_LOG_LEVEL_GAD, 0, 8, (ULONG)"%lu", 2, GA_Immediate, TRUE, TAG_DONE,
150                         HGROUP_KIND,    0,
151                                 CHECKBOX_KIND,  NULL,                                   MSG_LOG_TO_FILE_GAD,    (ULONG)&NewGuiSwitches.LogToFile,       TAG_DONE,
152                                 STRING_KIND,    (ULONG)LogFileClicked,  0,                                              128, TAG_DONE,
153                                 ENDGROUP_KIND,
154                         ENDGROUP_KIND,
155                 VGROUP_KIND, BBFT_RIDGE,
156                         HGROUP_KIND, 0,
157                                 CHECKBOX_KIND,  NULL,                                                   MSG_ASK_AUTOSAVE_GAD, (ULONG)&NewGuiSwitches.AskAutosave, TAG_DONE,
158                                 SLIDER_KIND,    (ULONG)AutosaveTimeClicked,             MSG_AUTOSAVE_TIME_GAD,          0,      99,     (ULONG)"%lu",   3, TAG_DONE,
159                                 ENDGROUP_KIND,
160                 HGROUP_KIND, 0,
161                         CHECKBOX_KIND,  NULL,                                                   MSG_DO_BACKUPS_GAD, (ULONG)&NewGuiSwitches.DoBackups, TAG_DONE,
162                         SLIDER_KIND,    (ULONG)BackupVersionsClicked,   MSG_BACKUP_VERSIONS_GAD,        1,      99,     (ULONG)"%lu",   3, TAG_DONE,
163                         ENDGROUP_KIND,
164                 STRING_KIND,    (ULONG)BackupTemplateClicked,   MSG_BACKUP_TEMPLATE_GAD, 64, TAG_DONE,
165                 ENDGROUP_KIND,
166         HGROUP_KIND, 0,
167                 BUTTON_KIND,    (ULONG)PrefsUseClicked,         MSG_UNDERSCORE_USE_GAD,         TAG_DONE,
168                 BUTTON_KIND,    (ULONG)PrefsCancelClicked,      MSG_UNDERSCORE_CANCEL_GAD,      TAG_DONE,
169                 ENDGROUP_KIND,
170         ENDGROUP_KIND
171 };
172
173
174
175 XDEF LONG PrefsWinTags[] =
176 {
177         XMWIN_LayoutArgs,       (LONG)PrefsArgs,
178         XMWIN_GCount,           Prefs_CNT,
179         XMWIN_Title,            MSG_PREFS_TITLE,
180         XMWIN_WindowFlags,      WFLG_CLOSEGADGET,
181         XMWIN_IDCMPFlags,       TEXTIDCMP|STRINGIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|CYCLEIDCMP|SLIDERIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
182         XMWIN_PostOpenFunc,     (LONG)PrefsPostOpen,
183         XMWIN_PostCloseFunc,(LONG)PrefsPostClose,
184         XMWIN_HelpNode,         (LONG)"Prefs",
185         TAG_DONE
186 };
187
188
189
190 static void PrefsPostOpen (struct WinUserData *wud)
191 {
192         memcpy (&NewScrInfo, &ScrInfo, sizeof (struct ScrInfo));
193         memcpy (&NewGuiSwitches, &GuiSwitches, sizeof (struct GuiSwitches));
194         CopyTextAttrPooled (Pool, &WindowAttr,  &NewWindowAttr);
195         CopyTextAttrPooled (Pool, &ListAttr,    &NewListAttr);
196
197         UpdatePrefsWindow();
198 }
199
200
201
202 static void PrefsPostClose (void)
203 {
204         FreeVecPooled (Pool, NewWindowAttr.ta_Name);    NewWindowAttr.ta_Name   = NULL;
205         FreeVecPooled (Pool, NewListAttr.ta_Name);              NewListAttr.ta_Name             = NULL;
206 }
207
208
209
210 /********************/
211 /* Prefs Functions  */
212 /********************/
213
214 GLOBALCALL void UpdatePrefsWindow()
215 {
216         /* These variables are declared static because gadtools text
217          * gadgets do not buffer their texts and require them to be
218          * accessible whenever a refresh is needed :-(.
219          */
220         static UBYTE windowfont[40], listfont[40];
221         static struct NameInfo nameinfo;
222
223         struct WinUserData *wud = WDescr[WID_PREFS].Wud;
224
225
226         if (wud && wud->Win)
227         {
228                 if (NewScrInfo.DisplayID)
229                         GetDisplayInfoData (NULL, (void *)&nameinfo, sizeof (nameinfo), DTAG_NAME, NewScrInfo.DisplayID);
230                 else
231                         strcpy (nameinfo.Name, STR(MSG_CLONE_DEF_SCREEN));
232
233                 SPrintf (windowfont, "%s/%ld", NewWindowAttr.ta_Name, NewWindowAttr.ta_YSize);
234                 SPrintf (listfont, "%s/%ld", NewListAttr.ta_Name, NewListAttr.ta_YSize);
235
236                 SetGadgets (wud,
237                         GD_Requesters,          NewGuiSwitches.UseReqTools,
238                         GD_UseDataTypes,        NewGuiSwitches.UseDataTypes,
239                         GD_Refresh,                     NewGuiSwitches.SmartRefresh,
240                         GD_AppIcon,                     NewGuiSwitches.ShowAppIcon,
241                         GD_DisplayMode,         nameinfo.Name,
242                         GD_PubScreen,           NewScrInfo.PubScreenName,
243                         GD_WindowFont,          windowfont,
244                         GD_ListViewFont,        listfont,
245                         GD_LogLevel,            NewGuiSwitches.LogLevel,
246                         GD_LogToFile,           NewGuiSwitches.LogToFile,
247                         GD_LogFile,                     NewGuiSwitches.LogFile,
248                         GD_AskAutosave,         NewGuiSwitches.AskAutosave,
249                         GD_AutosaveTime,        NewGuiSwitches.AutosaveTime,
250                         GD_DoBackups,           NewGuiSwitches.DoBackups,
251                         GD_BackupTemplate,      NewGuiSwitches.BackupTemplate,
252                         GD_BackupVersions,      NewGuiSwitches.BackupVersions,
253                         -1);
254         }
255 }
256
257
258
259 /******************/
260 /* Prefs Gadgets  */
261 /******************/
262
263 static void PubScreenClicked (struct WinUserData *wud)
264 {
265         strcpy (NewScrInfo.PubScreenName, GetString (wud->Gadgets[GD_PubScreen]));
266 }
267
268
269
270 static void GetPubScreenClicked (struct WinUserData *wud)
271 {
272         /**/
273 }
274
275
276
277 static void GetDisplayModeClicked (struct WinUserData *wud)
278 {
279         ScrModeRequest (&NewScrInfo);
280         UpdatePrefsWindow();
281 }
282
283 static void GetWindowFontClicked (struct WinUserData *wud)
284 {
285         FontRequest (&NewWindowAttr, 0);
286         UpdatePrefsWindow();
287 }
288
289 static void GetListViewFontClicked (struct WinUserData *wud)
290 {
291         FontRequest (&NewListAttr, 0);
292         UpdatePrefsWindow();
293 }
294
295
296
297 static void RequestersClicked (struct WinUserData *wud)
298 {
299         NewGuiSwitches.UseReqTools ^= 1;
300 }
301
302
303
304 static void RefreshClicked (struct WinUserData *wud)
305 {
306         NewGuiSwitches.SmartRefresh ^= 1;
307 }
308
309
310
311 static void LogLevelClicked     (struct WinUserData *wud)
312 {
313         NewGuiSwitches.LogLevel = IntuiMsg.Code;
314 }
315
316
317
318 static void LogFileClicked (struct WinUserData *wud)
319 {
320         strcpy (NewGuiSwitches.LogFile, GetString (wud->Gadgets[GD_LogFile]));
321 }
322
323
324
325 static void AutosaveTimeClicked (struct WinUserData *wud)
326 {
327         NewGuiSwitches.AutosaveTime = IntuiMsg.Code;
328 }
329
330
331
332 static void     BackupTemplateClicked (struct WinUserData *wud)
333 {
334         strcpy (NewGuiSwitches.BackupTemplate, GetString (wud->Gadgets[GD_BackupTemplate]));
335 }
336
337
338
339 static void BackupVersionsClicked (struct WinUserData *wud)
340 {
341         NewGuiSwitches.BackupVersions = IntuiMsg.Code;
342 }
343
344
345
346 static void PrefsUseClicked (struct WinUserData *wud)
347 {
348         BOOL    change_screen   = FALSE,
349                         change_reqs             = FALSE;
350
351         if (memcmp (&ScrInfo, &NewScrInfo, sizeof (struct ScrInfo)))
352         {
353                 change_screen = TRUE;
354                 memcpy (&ScrInfo, &NewScrInfo, sizeof (struct ScrInfo));
355         }
356
357         if (memcmp (&GuiSwitches, &NewGuiSwitches, sizeof (struct GuiSwitches)))
358         {
359                 if (GuiSwitches.UseReqTools != NewGuiSwitches.UseReqTools)
360                         change_reqs = TRUE;
361                 if (GuiSwitches.SmartRefresh != NewGuiSwitches.SmartRefresh)
362                         change_screen = TRUE;
363
364                 memcpy (&GuiSwitches, &NewGuiSwitches, sizeof (struct GuiSwitches));
365         }
366
367         if (CmpTextAttr (&NewWindowAttr, &WindowAttr))
368         {
369                 CopyTextAttrPooled (Pool, &NewWindowAttr, &WindowAttr);
370                 change_screen = TRUE;
371         }
372
373         if (CmpTextAttr (&NewListAttr, &ListAttr))
374         {
375                 CopyTextAttrPooled (Pool, &NewListAttr, &ListAttr);
376                 change_screen = TRUE;
377         }
378
379         MyCloseWindow (wud);
380
381         if (change_reqs)
382                 SetupRequesters();
383
384         if (GuiSwitches.ShowAppIcon)
385                 CreateAppIcon (ToolBoxDropIcon);
386         else
387                 DeleteAppIcon ();
388
389         if (change_screen)
390         {
391                 CloseDownScreen();
392                 if (SetupScreen())
393                 {
394                         /* For some reason we have lost the screen: exit immediatly! */
395                         Quit = TRUE;
396                         ShowRequesters = FALSE;
397                 }
398         }
399 }
400
401
402
403 static void PrefsCancelClicked (struct WinUserData *wud)
404 {
405         MyCloseWindow (wud);
406 }