add casts to zune macros to silence some warnings
[tangerine.git] / workbench / prefs / locale / registertab.c
blob35aaedf319eb84ba55ac2f1ef2872d4a7f1e7ae1
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include "global.h"
10 #include "registertab.h"
11 #include <string.h>
13 /****************************************************************************************/
15 #define IMWIDTH(x) (((struct Image *)(x))->Width)
16 #define IMHEIGHT(x) (((struct Image *)(x))->Height)
18 /****************************************************************************************/
20 void InitRegisterTab(struct RegisterTab *reg, struct RegisterTabItem *items)
22 reg->items = items;
23 reg->numitems = 0;
25 while(items->text)
27 reg->numitems++;
28 items++;
32 /****************************************************************************************/
34 void LayoutRegisterTab(struct RegisterTab *reg, struct Screen *scr,
35 struct DrawInfo *dri, BOOL samewidth)
37 struct RastPort temprp;
38 WORD i, x, h, biggest_w = 0;
40 InitRastPort(&temprp);
41 SetFont(&temprp, dri->dri_Font);
43 reg->dri = dri;
44 reg->fonth = dri->dri_Font->tf_YSize;
45 reg->fontb = dri->dri_Font->tf_Baseline;
47 h = 0;
48 for(i = 0; i < reg->numitems; i++)
50 if (reg->items[i].image)
52 if (IMHEIGHT(reg->items[i].image) > h) h = IMHEIGHT(reg->items[i].image);
56 if (h) h += REGISTERTAB_IMEXTRA_HEIGHT;
58 i = reg->fonth + REGISTERTAB_EXTRA_HEIGHT;
59 h = (i > h) ? i : h;
61 reg->height = (h + 3) & ~3; /* Multiple of 4 */
63 reg->height += 4;
65 reg->slopew = (reg->height - 4) / 2;
67 for(i = 0; i < reg->numitems; i++)
69 reg->items[i].textlen = strlen(reg->items[i].text);
70 reg->items[i].w = TextLength(&temprp, reg->items[i].text, reg->items[i].textlen);
71 reg->items[i].w += REGISTERTABITEM_EXTRA_WIDTH + reg->slopew * 2;
73 if (reg->items[i].image)
75 reg->items[i].w += REGISTERTAB_IMAGE_TEXT_SPACE +
76 ((struct Image *)reg->items[i].image)->Width;
79 if (reg->items[i].w > biggest_w) biggest_w = reg->items[i].w;
82 if (samewidth)
84 for(i = 0; i < reg->numitems; i++)
86 reg->items[i].w = biggest_w;
90 x = REGISTERTAB_SPACE_LEFT;
91 for(i = 0; i < reg->numitems; i++)
93 WORD itemwidth;
94 WORD to = 0;
95 itemwidth = TextLength(&temprp, reg->items[i].text, reg->items[i].textlen);
97 if (reg->items[i].image)
99 to = IMWIDTH(reg->items[i].image) + REGISTERTAB_IMAGE_TEXT_SPACE;
100 itemwidth += to;
103 reg->items[i].x1 = x;
104 reg->items[i].y1 = 0;
105 reg->items[i].x2 = x + reg->items[i].w - 1;
106 reg->items[i].y2 = reg->height - 1;
107 reg->items[i].h = reg->items[i].y2 - reg->items[i].y1 + 1;
108 reg->items[i].ix = (reg->items[i].w - itemwidth) / 2;
109 if (reg->items[i].image)
111 reg->items[i].iy = (reg->items[i].h - IMHEIGHT(reg->items[i].image)) / 2;
114 reg->items[i].tx = reg->items[i].ix + to;
115 reg->items[i].ty = reg->fontb + (reg->items[i].h - reg->fonth) / 2;
118 x += reg->items[i].w - reg->slopew;
121 reg->width = x + reg->slopew + REGISTERTAB_SPACE_RIGHT;
123 DeinitRastPort(&temprp);
126 /****************************************************************************************/
128 void SetRegisterTabPos(struct RegisterTab *reg, WORD left, WORD top)
130 reg->left = left;
131 reg->top = top;
134 /****************************************************************************************/
136 void SetRegisterTabFrameSize(struct RegisterTab *reg, WORD width, WORD height)
138 reg->framewidth = width;
139 reg->frameheight = height;
142 /****************************************************************************************/
144 void RenderRegisterTabItem(struct RastPort *rp, struct RegisterTab *reg, WORD item)
146 struct RegisterTabItem *ri = &reg->items[item];
147 WORD x, y;
149 SetDrMd(rp, JAM1);
150 SetFont(rp, reg->dri->dri_Font);
152 x = reg->left + ri->x1;
153 y = reg->top + ri->y1;
156 SetAPen(rp, reg->dri->dri_Pens[(reg->active == item) ? TEXTPEN : BACKGROUNDPEN]);
157 Move(rp, x + ri->tx + 1, y + ri->ty);
158 Text(rp, ri->text, ri->textlen);
159 SetAPen(rp, reg->dri->dri_Pens[TEXTPEN]);
160 Move(rp, x + ri->tx, y + ri->ty);
161 Text(rp, ri->text, ri->textlen);
163 if (ri->image)
165 DrawImageState(rp, (struct Image *)ri->image, x + ri->ix, y + ri->iy, IDS_NORMAL, dri);
168 /* upper / at left side */
170 SetAPen(rp, reg->dri->dri_Pens[SHINEPEN]);
171 WritePixel(rp, x + reg->slopew, y + 2);
172 Move(rp, x + reg->slopew / 2, y + 3 + reg->slopew - 1);
173 Draw(rp, x + reg->slopew - 1, y + 3);
175 /* --- at top side */
177 RectFill(rp, x + reg->slopew + 1, y + 1, x + reg->slopew + 2, y + 1);
178 RectFill(rp, x + reg->slopew + 3, y, x + ri->w - 1 - reg->slopew - 3, y);
180 SetAPen(rp, reg->dri->dri_Pens[SHADOWPEN]);
181 RectFill(rp, x + ri->w - 1 - reg->slopew - 2, y + 1, x + ri->w - 1 - reg->slopew - 1, y + 1);
183 /* upper \ at right side */
185 WritePixel(rp, x + ri->w - 1 - reg->slopew, y + 2);
186 Move(rp, x + ri->w - 1 - reg->slopew + 1, y + 3);
187 Draw(rp, x + ri->w - 1 - reg->slopew / 2, y + 3 + reg->slopew - 1);
189 /* lower / at left side. */
191 if ((item == 0) || (reg->active == item))
193 SetAPen(rp, reg->dri->dri_Pens[SHINEPEN]);
195 else
197 SetAPen(rp, reg->dri->dri_Pens[BACKGROUNDPEN]);
199 Move(rp, x, y + ri->h - 2);
200 Draw(rp, x + reg->slopew / 2 - 1, y + ri->h - 2 - reg->slopew + 1);
202 /* lower \ at the lefst side from the previous item */
204 if (item > 0)
206 if (reg->active == item)
208 SetAPen(rp, reg->dri->dri_Pens[BACKGROUNDPEN]);
210 else
212 SetAPen(rp, reg->dri->dri_Pens[SHADOWPEN]);
214 Move(rp, x + reg->slopew / 2, y + ri->h - 2 - reg->slopew + 1);
215 Draw(rp, x + reg->slopew - 1, y + ri->h - 2);
218 /* lower \ at right side. */
220 if (reg->active == item + 1)
222 SetAPen(rp, reg->dri->dri_Pens[BACKGROUNDPEN]);
224 else
226 SetAPen(rp, reg->dri->dri_Pens[SHADOWPEN]);
228 Move(rp, x + ri->w - 1 - reg->slopew / 2 + 1, y + ri->h - 2 - reg->slopew + 1);
229 Draw(rp, x + ri->w - 1, y + ri->h - 2);
231 if (reg->active == item)
233 SetAPen(rp, reg->dri->dri_Pens[BACKGROUNDPEN]);
234 RectFill(rp, x, y + ri->h - 1, x + ri->w - 1, y + ri->h - 1);
236 else
238 WORD x1, x2;
240 x1 = x;
241 x2 = x + ri->w - 1;
243 if (reg->active == item - 1)
244 x1 += reg->slopew;
245 else if (reg->active == item + 1)
246 x2 -= reg->slopew;
248 SetAPen(rp, reg->dri->dri_Pens[SHINEPEN]);
249 RectFill(rp, x1, y + ri->h - 1, x2, y + ri->h - 1);
254 /****************************************************************************************/
256 void RenderRegisterTab(struct RastPort *rp, struct RegisterTab *reg, BOOL alsoframe)
258 WORD i;
260 SetDrMd(rp, JAM1);
262 SetAPen(rp, reg->dri->dri_Pens[SHINEPEN]);
264 RectFill(rp, reg->left,
265 reg->top + reg->height - 1,
266 reg->left + REGISTERTAB_SPACE_LEFT - 1,
267 reg->top + reg->height - 1);
269 RectFill(rp, reg->left + reg->width - REGISTERTAB_SPACE_RIGHT,
270 reg->top + reg->height - 1,
271 reg->left + reg->width - 1,
272 reg->top + reg->height - 1);
274 for(i = 0; i < reg->numitems; i++)
276 RenderRegisterTabItem(rp, reg, i);
279 if (alsoframe)
281 SetAPen(rp, reg->dri->dri_Pens[SHINEPEN]);
283 RectFill(rp, reg->left,
284 reg->top + reg->height - 1,
285 reg->left,
286 reg->top + reg->height + reg->frameheight - 1);
288 RectFill(rp, reg->left + reg->width,
289 reg->top + reg->height - 1,
290 reg->left + reg->framewidth - 2,
291 reg->top + reg->height - 1);
293 SetAPen(rp, reg->dri->dri_Pens[SHADOWPEN]);
295 RectFill(rp, reg->left + reg->framewidth - 1,
296 reg->top + reg->height - 1,
297 reg->left + reg->framewidth - 1,
298 reg->top + reg->height + reg->frameheight - 1);
300 RectFill(rp, reg->left + 1,
301 reg->top + reg->height + reg->frameheight - 1,
302 reg->left + reg->framewidth - 2,
303 reg->top + reg->height + reg->frameheight - 1);
307 /****************************************************************************************/
309 BOOL HandleRegisterTabInput(struct RegisterTab *reg, struct IntuiMessage *msg)
311 struct Window *win = msg->IDCMPWindow;
312 BOOL retval = FALSE;
314 if ((msg->Class == IDCMP_MOUSEBUTTONS) &&
315 (msg->Code == SELECTDOWN))
317 WORD i;
318 WORD x = win->MouseX - reg->left;
319 WORD y = win->MouseY - reg->top;
321 for(i = 0; i < reg->numitems; i++)
323 if ((x >= reg->items[i].x1) &&
324 (y >= reg->items[i].y1) &&
325 (x <= reg->items[i].x2) &&
326 (y <= reg->items[i].y2))
328 retval = TRUE;
330 if (reg->active != i)
332 WORD oldactive = reg->active;
334 reg->active = i;
335 RenderRegisterTabItem(win->RPort, reg, oldactive);
336 RenderRegisterTabItem(win->RPort, reg, i);
338 break;
343 return retval;
348 /****************************************************************************************/
349 /****************************************************************************************/