Some compiler warnings removed.
[cake.git] / workbench / classes / zune / systemprefswindow / systemprefswindow.c
bloba5974ce759f6684c1806459d96b360572b04345b
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 This file is part of the SystemPrefsWindow class, which is distributed under
4 the terms of version 2.1 of the GNU Lesser General Public License.
6 $Id$
7 */
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <proto/muimaster.h>
12 #include <proto/intuition.h>
13 #include <proto/utility.h>
14 #include <proto/locale.h>
16 #include <utility/tagitem.h>
17 #include <libraries/gadtools.h>
18 #include <libraries/mui.h>
19 #include <zune/prefseditor.h>
20 #include <zune/prefswindow.h>
22 #include "systemprefswindow.h"
23 #include "systemprefswindow_private.h"
25 #define CATCOMP_ARRAY
26 #include "strings.h"
28 #define DEBUG 1
29 #include <aros/debug.h>
31 /*** Macros *****************************************************************/
32 #define SETUP_INST_DATA struct SystemPrefsWindow_DATA *data = INST_DATA(CLASS, self)
34 /*** Locale functions *******************************************************/
35 CONST_STRPTR MSG(struct Catalog *catalog, ULONG id)
37 if (catalog != NULL)
39 return GetCatalogStr(catalog, id, CatCompArray[id].cca_Str);
41 else
43 return CatCompArray[id].cca_Str;
47 #define _(id) MSG(catalog, (id))
48 #define __(id) (IPTR) MSG(catalog, (id))
50 /*** Utility functions ******************************************************/
51 Object *MakeMenuitem(CONST_STRPTR text)
53 CONST_STRPTR title = NULL,
54 shortcut = NULL;
56 if (text != NM_BARLABEL && text[1] == '\0')
58 title = text + 2;
59 shortcut = text;
61 else
63 title = text;
64 shortcut = NULL;
67 return (Object *)MenuitemObject,
68 MUIA_Menuitem_Title, (IPTR) title,
69 shortcut != NULL ?
70 MUIA_Menuitem_Shortcut :
71 TAG_IGNORE, (IPTR) shortcut,
72 End;
75 /*** Methods ****************************************************************/
76 Object *SystemPrefsWindow__OM_NEW
78 Class *CLASS, Object *self, struct opSet *message
81 struct SystemPrefsWindow_DATA *data = NULL;
82 struct TagItem *tag = NULL;
83 struct Catalog *catalog = NULL;
84 Object *editor, /* *importMI, *exportMI, */ *testMI, *revertMI,
85 *saveMI, *useMI, *cancelMI;
87 tag = FindTagItem(WindowContents, message->ops_AttrList);
88 if (tag != NULL) editor = (Object *) tag->ti_Data;
89 if (editor == NULL) return NULL;
91 /*--- Initialize locale ------------------------------------------------*/
92 catalog = OpenCatalogA
94 NULL, "System/Classes/Zune/SystemPrefsWindow.catalog", NULL
97 /*--- Create object ----------------------------------------------------*/
98 self = (Object *) DoSuperNewTags
100 CLASS, self, NULL,
102 MUIA_Window_Title, XGET(editor, MUIA_PrefsEditor_Name),
104 MUIA_Window_Menustrip, (IPTR) MenustripObject,
105 Child, (IPTR) MenuObject,
106 MUIA_Menu_Title, __(MSG_MENU_PREFS),
108 /* FIXME: implement
109 Child, (IPTR) importMI = MakeMenuitem(_(MSG_MENU_PREFS_IMPORT)),
110 Child, (IPTR) exportMI = MakeMenuitem(_(MSG_MENU_PREFS_EXPORT)),
111 Child, (IPTR) MakeMenuitem(NM_BARLABEL),
114 Child, (IPTR)(testMI = MakeMenuitem(_(MSG_MENU_PREFS_TEST))),
115 Child, (IPTR)(revertMI = MakeMenuitem(_(MSG_MENU_PREFS_REVERT))),
116 Child, MakeMenuitem(NM_BARLABEL),
117 Child, (IPTR)(saveMI = MakeMenuitem(_(MSG_MENU_PREFS_SAVE))),
118 Child, (IPTR)(useMI = MakeMenuitem(_(MSG_MENU_PREFS_USE))),
119 Child, (IPTR)(cancelMI = MakeMenuitem(_(MSG_MENU_PREFS_CANCEL))),
120 End,
121 End,
123 TAG_MORE, (IPTR) message->ops_AttrList
127 if (self != NULL)
129 data = INST_DATA(CLASS, self);
130 data->spwd_Catalog = catalog;
131 data->spwd_Editor = editor;
133 /*-- Handle initial attribute values -------------------------------*/
134 SetAttrsA(self, message->ops_AttrList);
136 /*-- Setup initial button states -----------------------------------*/
137 SET(self, MUIA_PrefsWindow_Test_Disabled, TRUE);
138 SET(self, MUIA_PrefsWindow_Revert_Disabled, TRUE);
139 SET(self, MUIA_PrefsWindow_Save_Disabled, TRUE);
140 SET(self, MUIA_PrefsWindow_Use_Disabled, TRUE);
142 /*-- Setup notifications -------------------------------------------*/
143 DoMethod
145 editor, MUIM_Notify, MUIA_PrefsEditor_Changed, MUIV_EveryTime,
146 (IPTR) self, 1, MUIM_SystemPrefsWindow_UpdateButtons
148 DoMethod
150 editor, MUIM_Notify, MUIA_PrefsEditor_Testing, MUIV_EveryTime,
151 (IPTR) self, 1, MUIM_SystemPrefsWindow_UpdateButtons
154 DoMethod
156 testMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
157 (IPTR) self, 1, MUIM_PrefsWindow_Test
159 DoMethod
161 revertMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
162 (IPTR) self, 1, MUIM_PrefsWindow_Revert
164 DoMethod
166 saveMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
167 (IPTR) self, 1, MUIM_PrefsWindow_Save
169 DoMethod
171 useMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
172 (IPTR) self, 1, MUIM_PrefsWindow_Use
174 DoMethod
176 cancelMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
177 (IPTR) self, 1, MUIM_PrefsWindow_Cancel
180 else
182 if (catalog != NULL) CloseCatalog(catalog);
185 return self;
188 IPTR SystemPrefsWindow__OM_DISPOSE
190 Class *CLASS, Object *self, Msg message
193 SETUP_INST_DATA;
195 if (data->spwd_Catalog != NULL) CloseCatalog(data->spwd_Catalog);
197 return DoSuperMethodA(CLASS, self, message);
200 IPTR SystemPrefsWindow__MUIM_SystemPrefsWindow_UpdateButtons
202 Class *CLASS, Object *self, Msg message
205 SETUP_INST_DATA;
207 BOOL changed = XGET(data->spwd_Editor, MUIA_PrefsEditor_Changed);
208 BOOL testing = XGET(data->spwd_Editor, MUIA_PrefsEditor_Testing);
210 SET(self, MUIA_PrefsWindow_Test_Disabled, !changed);
211 SET(self, MUIA_PrefsWindow_Revert_Disabled, !testing);
213 SET(self, MUIA_PrefsWindow_Save_Disabled, !(changed || testing));
214 SET(self, MUIA_PrefsWindow_Use_Disabled, !(changed || testing));
216 return 0;
219 IPTR SystemPrefsWindow__OM_SET
221 Class *CLASS, Object *self, struct opSet *message
224 SETUP_INST_DATA;
225 const struct TagItem *tstate = message->ops_AttrList;
226 struct TagItem *tag;
228 while ((tag = NextTagItem(&tstate)) != NULL)
230 switch (tag->ti_Tag)
232 case MUIA_PrefsWindow_Save_Disabled:
233 if (!XGET(data->spwd_Editor, MUIA_PrefsEditor_CanSave))
235 tag->ti_Tag = TAG_IGNORE;
237 break;
239 case MUIA_PrefsWindow_Test_Disabled:
240 case MUIA_PrefsWindow_Revert_Disabled:
241 if (!XGET(data->spwd_Editor, MUIA_PrefsEditor_CanTest))
243 tag->ti_Tag = TAG_IGNORE;
245 break;
249 return DoSuperMethodA(CLASS, self, (Msg) message);
252 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Test
254 Class *CLASS, Object *self, Msg message
257 SETUP_INST_DATA;
259 if (!DoMethod(data->spwd_Editor, MUIM_PrefsEditor_Test))
261 // FIXME: error reporting
262 return FALSE;
265 return TRUE;
268 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Revert
270 Class *CLASS, Object *self, Msg message
273 SETUP_INST_DATA;
275 if (!DoMethod(data->spwd_Editor, MUIM_PrefsEditor_Revert))
277 // FIXME: error reporting
278 return FALSE;
281 return TRUE;
284 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Save
286 Class *CLASS, Object *self, Msg message
289 SETUP_INST_DATA;
291 if (!DoMethod(data->spwd_Editor, MUIM_PrefsEditor_Save))
293 // FIXME: error reporting
294 return FALSE;
297 DoMethod
299 _app(self), MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
302 return TRUE;
305 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Use
307 Class *CLASS, Object *self, Msg message
310 SETUP_INST_DATA;
312 if (!DoMethod(data->spwd_Editor, MUIM_PrefsEditor_Use))
314 // FIXME: error reporting
315 return FALSE;
318 DoMethod
320 _app(self), MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
323 return TRUE;
326 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Cancel
328 Class *CLASS, Object *self, Msg message
331 SETUP_INST_DATA;
333 if (!DoMethod(data->spwd_Editor, MUIM_PrefsEditor_Cancel))
335 // FIXME: error reporting
336 return FALSE;
339 DoMethod
341 _app(self), MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
344 return TRUE;