add casts to zune macros to silence some warnings
[tangerine.git] / workbench / prefs / locale / page_country.c
blob2dacfb525e4e3c32517f8951a1e592d4c4844cd2
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
12 #include <string.h>
14 /*********************************************************************************************/
16 static struct Gadget *gadlist, *countrygad, *gad;
17 static struct Hook lvhook;
18 static WORD domleft, domtop, domwidth, domheight;
19 static WORD max_flagw, max_flagh;
20 static WORD active_country = 0;
21 static BOOL page_active;
23 /*********************************************************************************************/
25 static LONG country_init(void)
27 struct CountryEntry *entry;
28 static UBYTE filename[256];
30 if (!DataTypesBase) return TRUE;
32 ForeachNode(&country_list, entry)
34 strcpy(filename, "LOCALE:Flags/Countries");
35 AddPart(filename, entry->lve.realname, 256);
37 entry->dto = NewDTObject(filename, DTA_GroupID , GID_PICTURE ,
38 OBP_Precision , PRECISION_IMAGE ,
39 PDTA_Screen , (IPTR)scr ,
40 PDTA_Remap , TRUE ,
41 PDTA_FreeSourceBitMap, TRUE ,
42 PDTA_DestMode , PMODE_V43 ,
43 PDTA_UseFriendBitMap , TRUE ,
44 TAG_DONE);
46 if (entry->dto)
48 IPTR val;
50 DoMethod(entry->dto, DTM_PROCLAYOUT, (IPTR) NULL, 1);
52 GetDTAttrs(entry->dto, PDTA_DestBitMap, (IPTR) &entry->flagbm, TAG_DONE);
53 if (!entry->flagbm)
55 GetDTAttrs(entry->dto, PDTA_BitMap, (IPTR) &entry->flagbm, TAG_DONE);
58 GetDTAttrs(entry->dto, DTA_NominalHoriz, (IPTR) &val, TAG_DONE);
59 entry->flagw = (WORD)val;
61 GetDTAttrs(entry->dto, DTA_NominalVert, (IPTR) &val, TAG_DONE);
62 entry->flagh = (WORD)val;
64 if (entry->flagbm)
66 if (entry->flagw > max_flagw) max_flagw = entry->flagw;
67 if (entry->flagh > max_flagh) max_flagh = entry->flagh;
69 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) >= 15)
71 struct BitMap *bm;
73 bm = AllocBitMap(entry->flagw,
74 entry->flagh,
75 GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH),
76 BMF_MINPLANES | BMF_INTERLEAVED,
77 scr->RastPort.BitMap);
79 if (bm)
81 BltBitMap(entry->flagbm, 0, 0, bm, 0, 0, entry->flagw, entry->flagh, 192, 255, 0);
82 DisposeDTObject(entry->dto);
84 entry->dto = NULL;
85 entry->flagbm = bm;
89 else
91 DisposeDTObject(entry->dto);
92 entry->dto = NULL;
95 } /* if (entry->dto) */
97 } /* ForeachNode(&country_list, entry) */
99 return TRUE;
102 /*********************************************************************************************/
104 static IPTR LVRenderHook(struct Hook *hook, struct Node *node, struct LVDrawMsg *msg)
106 IPTR retval;
108 if (msg->lvdm_MethodID == LV_DRAW)
110 struct DrawInfo *dri = msg->lvdm_DrawInfo;
111 struct RastPort *rp = msg->lvdm_RastPort;
113 WORD min_x = msg->lvdm_Bounds.MinX;
114 WORD min_y = msg->lvdm_Bounds.MinY;
115 WORD max_x = msg->lvdm_Bounds.MaxX;
116 WORD max_y = msg->lvdm_Bounds.MaxY;
118 UWORD erasepen = BACKGROUNDPEN;
120 SetDrMd(rp, JAM1);
122 switch (msg->lvdm_State)
124 case LVR_SELECTED:
125 case LVR_SELECTEDDISABLED:
126 erasepen = FILLPEN;
127 /* Fall through */
129 case LVR_NORMAL:
130 case LVR_NORMALDISABLED:
133 struct TextExtent te;
134 struct CountryEntry *ce;
135 WORD numfit;
137 SetAPen(rp, dri->dri_Pens[erasepen]);
138 RectFill(rp, min_x, min_y, max_x, max_y);
140 ce = (struct CountryEntry *)node;
141 if (ce->flagbm)
143 BltBitMapRastPort(ce->flagbm,
147 min_x + 1,
148 (min_y + max_y + 1 - ce->flagh) / 2,
149 ce->flagw,
150 ce->flagh,
151 192);
154 if (max_flagh) min_x += max_flagw + 3;
156 numfit = TextFit(rp, node->ln_Name, strlen(node->ln_Name),
157 &te, NULL, 1, max_x - min_x + 1, max_y - min_y + 1);
159 SetAPen(rp, dri->dri_Pens[TEXTPEN]);
161 /* Render text */
162 Move(rp, min_x, (min_y + max_y + 1 - rp->Font->tf_YSize) / 2 + rp->Font->tf_Baseline);
163 Text(rp, node->ln_Name, numfit);
165 break;
169 retval = LVCB_OK;
171 else
173 retval = LVCB_UNKNOWN;
176 return retval;
179 /*********************************************************************************************/
181 static LONG country_makegadgets(void)
183 struct NewGadget ng;
184 WORD itemheight;
186 gad = CreateContext(&gadlist);
188 ng.ng_LeftEdge = domleft;
189 ng.ng_TopEdge = domtop;
190 ng.ng_Width = domwidth;
191 ng.ng_Height = domheight;
192 ng.ng_GadgetText = NULL;
193 ng.ng_TextAttr = 0;
194 ng.ng_GadgetID = MSG_GAD_TAB_COUNTRY;
195 ng.ng_Flags = 0;
196 ng.ng_VisualInfo = vi;
198 itemheight = dri->dri_Font->tf_YSize;
199 if (max_flagh > itemheight) itemheight = max_flagh;
200 itemheight += 2;
202 lvhook.h_Entry = HookEntry;
203 lvhook.h_SubEntry = LVRenderHook;
205 gad = countrygad = CreateGadget(LISTVIEW_KIND, gad, &ng, GTLV_Labels , (IPTR)&country_list,
206 GTLV_ShowSelected , (IPTR) NULL ,
207 GTLV_Selected , active_country ,
208 GTLV_MakeVisible , active_country ,
209 GTLV_ItemHeight , itemheight ,
210 GTLV_CallBack , (IPTR)&lvhook ,
211 TAG_DONE);
214 return gad ? TRUE : FALSE;
217 /*********************************************************************************************/
219 static void country_cleanup(void)
221 struct CountryEntry *entry;
223 ForeachNode(&country_list, entry)
225 if (entry->dto)
227 DisposeDTObject(entry->dto);
229 else if (entry->flagbm)
231 FreeBitMap(entry->flagbm);
235 if (gadlist) FreeGadgets(gadlist);
236 gadlist = NULL;
239 /*********************************************************************************************/
241 static LONG country_input(struct IntuiMessage *msg)
243 struct CountryEntry *entry;
244 LONG retval = FALSE;
246 if (msg->Class == IDCMP_GADGETUP)
248 struct Gadget *gad = (struct Gadget *)msg->IAddress;
250 switch(gad->GadgetID)
252 case MSG_GAD_TAB_COUNTRY:
253 if ((entry = (struct CountryEntry *)FindListNode(&country_list, msg->Code)))
255 if (active_country != msg->Code)
257 active_country = msg->Code;
258 strcpy(localeprefs.lp_CountryName, entry->lve.realname);
259 LoadCountry(localeprefs.lp_CountryName, &localeprefs.lp_CountryData);
262 retval = TRUE;
263 break;
265 } /* switch(gad->GadgetID) */
267 } /* if (msg->Class == IDCMP_GADGETUP) */
268 else if (msg->Class == IDCMP_RAWKEY)
270 switch(msg->Code)
272 case RAWKEY_NM_WHEEL_UP:
273 ScrollListview(countrygad, -1);
274 break;
276 case RAWKEY_NM_WHEEL_DOWN:
277 ScrollListview(countrygad, 1);
278 break;
282 return retval;
285 /*********************************************************************************************/
287 static void country_prefs_changed(void)
289 struct CountryEntry *entry;
290 WORD i = 0;
292 active_country = 0;
294 ForeachNode(&country_list, entry)
296 if (Stricmp(localeprefs.lp_CountryName, entry->lve.realname) == 0)
298 active_country = i;
299 break;
301 i++;
304 if (gadlist)
306 struct Window *winparam = page_active ? win : NULL;
308 GT_SetGadgetAttrs(countrygad, winparam, NULL, GTLV_Selected , active_country,
309 GTLV_MakeVisible, active_country,
310 TAG_DONE);
314 /*********************************************************************************************/
316 LONG page_country_handler(LONG cmd, IPTR param)
318 LONG retval = TRUE;
320 switch(cmd)
322 case PAGECMD_INIT:
323 retval = country_init();
324 break;
326 case PAGECMD_LAYOUT:
327 break;
329 case PAGECMD_GETMINWIDTH:
330 retval = 20;
331 break;
333 case PAGECMD_GETMINHEIGHT:
334 retval = 20;
335 break;
337 case PAGECMD_SETDOMLEFT:
338 domleft = param;
339 break;
341 case PAGECMD_SETDOMTOP:
342 domtop = param;
343 break;
345 case PAGECMD_SETDOMWIDTH:
346 domwidth = param;
347 break;
349 case PAGECMD_SETDOMHEIGHT:
350 domheight = param;
351 break;
353 case PAGECMD_MAKEGADGETS:
354 retval = country_makegadgets();
355 break;
357 case PAGECMD_ADDGADGETS:
358 if (!page_active)
360 GT_SetGadgetAttrs(countrygad, NULL, NULL, GTLV_MakeVisible, active_country, TAG_DONE);
361 AddGList(win, gadlist, -1, -1, NULL);
362 GT_RefreshWindow(win, NULL);
363 RefreshGList(gadlist, win, NULL, -1);
365 page_active = TRUE;
367 break;
369 case PAGECMD_REMGADGETS:
370 if (page_active)
372 if (gadlist) RemoveGList(win, gadlist, -1);
374 page_active = FALSE;
376 break;
378 case PAGECMD_PREFS_CHANGED:
379 country_prefs_changed();
380 break;
382 case PAGECMD_HANDLEINPUT:
383 retval = country_input((struct IntuiMessage *)param);
384 break;
386 case PAGECMD_CLEANUP:
387 country_cleanup();
388 break;
391 return retval;