revert between 56095 -> 55830 in arch
[AROS.git] / workbench / prefs / locale / page_region.c
blobac18b4d158376dcffa294fcb63dcf7fa135c878e
1 /*
2 Copyright © 2003-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <proto/alib.h>
9 #include <proto/exec.h>
10 #include <proto/intuition.h>
11 #include <proto/utility.h>
12 #include <proto/muimaster.h>
13 #include <proto/dos.h>
14 #include <proto/alib.h>
16 #include <zune/customclasses.h>
17 #include <zune/prefseditor.h>
19 #include <stdio.h>
21 #include "prefs.h"
22 #include "page_region.h"
23 #include "registertab.h"
25 static struct Hook display_hook;
27 /*** Instance Data **********************************************************/
29 struct Region_DATA
31 Object *me;
32 Object *child;
33 Object *prefs;
34 ULONG active;
37 struct MUI_CustomClass *Region_CLASS;
39 /*** Helpers *****************************************************************/
41 /**********************************************
42 * The display function for the Region listview
43 **********************************************/
44 STATIC VOID region_display_func(struct Hook *h, char **array, struct ListviewEntry *entry)
46 *array++ = entry->displayflag;
47 *array = entry->node.ln_Name;
50 /*** Methods ****************************************************************
54 Object *Region__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
56 struct Region_DATA *data;
57 struct TagItem *tstate, *tag;
58 struct RegionEntry *entry;
60 D(bug("[LocalePrefs-RegionClass] Region Class New\n"));
62 display_hook.h_Entry = HookEntry;
63 display_hook.h_SubEntry = (HOOKFUNC)region_display_func;
66 * region flags are at the moment 17 pixels high
67 * MUIA_List_MinLineHeight, 19 leaves at least two
68 * pixel space between the images
69 * If images ever get bigger, this should be
70 * no problem.
73 obj = (Object *) DoSuperNewTags
75 cl, obj, NULL,
77 InputListFrame,
78 MUIA_List_MinLineHeight, 20,
79 MUIA_List_Format, "P=\033c,",
80 MUIA_List_DisplayHook, &display_hook,
81 TAG_DONE
84 if (obj == NULL)
86 D(bug("[LocalePrefs-RegionClass] ERROR: DoSuperNewTags failed!\n"));
87 return NULL;
90 data = INST_DATA(cl, obj);
92 tstate = ((struct opSet *)msg)->ops_AttrList;
93 while ((tag = (struct TagItem *) NextTagItem((APTR) &tstate)))
95 switch (tag->ti_Tag)
97 case MUIA_UserData:
98 data->prefs = (Object *) tag->ti_Data;
99 break;
103 data->child = obj;
105 ForeachNode(&region_list, entry)
107 DoMethod
109 data->child,
110 MUIM_List_InsertSingle,
111 (IPTR)entry,
112 MUIV_List_Insert_Bottom
116 /* we did remember that */
117 NNSET(data->child, MUIA_List_Active, data->active);
118 /* changed hook */
119 DoMethod(obj, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime, (IPTR) data->prefs, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
121 data->me = obj;
122 return obj;
125 /*** Get ******************************************************************/
126 static IPTR Region__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
128 struct Region_DATA *data = INST_DATA(cl, obj);
129 struct RegionEntry *entry;
130 IPTR rc;
131 IPTR nr = 0;
132 ULONG i;
135 switch (msg->opg_AttrID)
137 case MUIA_Region_Regionname:
138 GET(data->child, MUIA_List_Active, &nr);
139 rc = -1;
140 i = 0;
141 ForeachNode(&region_list, entry)
143 if (i == nr)
145 rc = (IPTR)entry->lve.realname;
147 i++;
150 if (rc == -1)
152 *msg->opg_Storage = 0;
153 return FALSE;
155 break;
157 default:
158 return DoSuperMethodA(cl, obj, (Msg)msg);
161 *msg->opg_Storage = rc;
162 return TRUE;
165 /*** Set ******************************************************************/
166 static IPTR Region__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
168 struct Region_DATA *data = INST_DATA(cl, obj);
169 struct TagItem *tstate, *tag;
170 struct RegionEntry *entry;
171 ULONG update;
172 ULONG nr;
173 ULONG i;
175 tstate = msg->ops_AttrList;
176 update = FALSE;
178 while ((tag = (struct TagItem *) NextTagItem((APTR) &tstate)))
180 switch (tag->ti_Tag)
182 case MUIA_Region_Regionname:
184 nr = -1;
185 i = 0;
186 ForeachNode(&region_list, entry)
188 if (!stricmp(entry->lve.realname, (STRPTR)tag->ti_Data))
190 nr=i;
192 i++;
195 if (nr < 0)
197 D(bug("[LocalePrefs-RegionClass] ERROR: could not find >%s< !?\n",tag->ti_Data));
199 else
201 NNSET(data->child, MUIA_List_Active, nr);
202 update = TRUE;
204 break;
206 default:
207 return DoSuperMethodA(cl, obj, (Msg)msg);
211 if(update)
213 MUI_Redraw(obj, MADF_DRAWOBJECT);
216 return TRUE;
219 /*** Setup ******************************************************************/
220 ZUNE_CUSTOMCLASS_3
222 Region, NULL, MUIC_List, NULL,
223 OM_NEW, struct opSet *,
224 OM_SET, struct opSet *,
225 OM_GET, struct opGet *