grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / nlist / nbitmap_mcc / dispatcher.c
blob336602f9b6d9d340ad7a874f2bd3a873597c20a9
1 /***************************************************************************
3 NBitmap.mcc - New Bitmap MUI Custom Class
4 Copyright (C) 2006 by Daniel Allsopp
5 Copyright (C) 2007-2013 by NList Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 NList classes Support Site: http://www.sf.net/projects/nlist-classes
19 $Id$
21 ***************************************************************************/
23 /* ansi includes */
24 #include <string.h>
26 /* system includes */
27 #include <clib/alib_protos.h>
28 #include <proto/exec.h>
29 #include <proto/intuition.h>
30 #include <proto/muimaster.h>
31 #include <proto/graphics.h>
32 #include <proto/utility.h>
33 #include <proto/locale.h>
34 #include <mui/NBitmap_mcc.h>
36 /* local includes */
37 #include "NBitmap.h"
38 #include "private.h"
40 #include "Debug.h"
42 /* Object *DoSuperNew() */
43 #if !defined(__MORPHOS__)
44 #ifdef __AROS__
45 static __attribute__ ((noinline)) Object * VARARGS68K DoSuperNew(struct IClass *cl, Object *obj, Tag tag1, ...)
47 AROS_SLOWSTACKTAGS_PRE_AS(tag1, Object *)
48 retval = (Object *)DoSuperMethod(cl, obj, OM_NEW, AROS_SLOWSTACKTAGS_ARG(tag1), NULL);
49 AROS_SLOWSTACKTAGS_POST
51 #else
52 static Object * VARARGS68K DoSuperNew(struct IClass *cl, Object *obj, ...)
54 Object *rc;
55 VA_LIST args;
57 ENTER();
59 VA_START(args, obj);
60 rc = (Object *)DoSuperMethod(cl, obj, OM_NEW, VA_ARG(args, ULONG), NULL);
61 VA_END(args);
63 RETURN(rc);
64 return rc;
66 #endif
67 #endif // !__MORPHOS__
69 /* VOID setstr() */
70 static VOID setstr(STRPTR *dest, STRPTR str)
72 ENTER();
74 if(*dest != NULL)
76 FreeVec(*dest);
77 *dest = NULL;
80 if(str != NULL)
82 ULONG len;
84 len = strlen(str) + 1;
85 if((*dest = AllocVecShared(len, MEMF_ANY)) != NULL)
86 strlcpy(*dest, str, len);
89 LEAVE();
92 /* ULONG NBitmap_New() */
93 static IPTR NBitmap_New(struct IClass *cl, Object *obj, struct opSet *msg)
95 if((obj = (Object *)DoSuperNew(cl, obj,
96 MUIA_CycleChain, TRUE,
97 //MUIA_FillArea, FALSE,
98 MUIA_Font, MUIV_Font_Tiny,
99 TAG_MORE, msg->ops_AttrList)) != NULL)
101 struct InstData *data = NULL;
103 if((data = INST_DATA(cl, obj)) != NULL)
105 // assume a valid data type for the moment
106 BOOL typeOk = TRUE;
107 uint32 i;
108 struct TagItem *tags = NULL, *tag = NULL;
110 memset(data, 0, sizeof(struct InstData));
112 data->type = MUIV_NBitmap_Type_File;
113 data->alpha = 0xffffffffUL;
115 // passed tags
116 for(tags = ((struct opSet *)msg)->ops_AttrList; (tag = NextTagItem((APTR)&tags)) != NULL; )
118 switch(tag->ti_Tag)
120 case MUIA_NBitmap_Type:
121 data->type = tag->ti_Data;
122 break;
124 case MUIA_NBitmap_Normal:
125 data->data[0] = (uint32*)tag->ti_Data;
126 break;
128 case MUIA_NBitmap_Ghosted:
129 data->data[1] = (uint32*)tag->ti_Data;
130 break;
132 case MUIA_NBitmap_Selected:
133 data->data[2] = (uint32*)tag->ti_Data;
134 break;
136 case MUIA_NBitmap_Button:
137 data->button = (BOOL)tag->ti_Data;
138 break;
140 case MUIA_NBitmap_Label:
141 setstr(&data->label, (STRPTR)tag->ti_Data);
142 break;
144 case MUIA_NBitmap_Width:
145 data->width = tag->ti_Data;
146 break;
148 case MUIA_NBitmap_Height:
149 data->height = tag->ti_Data;
150 break;
152 case MUIA_NBitmap_CLUT:
153 data->clut = (const uint32 *)tag->ti_Data;
154 break;
156 case MUIA_NBitmap_Alpha:
157 data->alpha = tag->ti_Data;
158 break;
162 // load files
163 switch(data->type)
165 case MUIV_NBitmap_Type_File:
167 for(i=0; i<3; i++)
169 if(data->data[i] != NULL)
170 NBitmap_LoadImage((STRPTR)data->data[i], i, cl, obj);
173 break;
175 case MUIV_NBitmap_Type_DTObject:
177 for(i=0; i<3; i++)
179 if(data->data[i] != NULL)
180 data->dt_obj[i] = (Object *)data->data[i];
183 break;
185 case MUIV_NBitmap_Type_CLUT8:
186 case MUIV_NBitmap_Type_RGB24:
187 case MUIV_NBitmap_Type_ARGB32:
189 // nothing to do here
191 break;
193 default:
195 // this is an invalid type
196 typeOk = FALSE;
198 break;
201 // setup images
202 if(typeOk == TRUE && NBitmap_NewImage(cl, obj) == TRUE)
203 return (IPTR)obj;
207 CoerceMethod(cl, obj, OM_DISPOSE);
208 return (IPTR)NULL;;
211 /* ULONG NBitmap_Get() */
212 static ULONG NBitmap_Get(struct IClass *cl, Object *obj, struct opGet *msg)
214 ULONG result = FALSE;
215 IPTR *store = msg->opg_Storage;
216 struct InstData *data = INST_DATA(cl, obj);
218 ENTER();
220 switch (((struct opGet *)msg)->opg_AttrID)
222 case MUIA_NBitmap_Width:
223 *store = (LONG) data->width;
224 result = TRUE;
225 break;
227 case MUIA_NBitmap_Height:
228 *store = (LONG) data->height;
229 result = TRUE;
230 break;
232 case MUIA_NBitmap_MaxWidth:
233 *store = (LONG) data->maxwidth;
234 result = TRUE;
235 break;
237 case MUIA_NBitmap_MaxHeight:
238 *store = (LONG) data->maxheight;
239 result = TRUE;
240 break;
243 if(result == FALSE)
244 result = DoSuperMethodA(cl, obj, (Msg)msg);
246 RETURN(result);
247 return result;
250 /* ULONG NBitmap_Set() */
251 static IPTR NBitmap_Set(struct IClass *cl,Object *obj, struct opSet *msg)
253 struct InstData *data = INST_DATA(cl, obj);
254 struct TagItem *tags, *tag;
255 IPTR result;
257 ENTER();
259 for(tags = msg->ops_AttrList; (tag = NextTagItem((APTR)&tags)) != NULL; )
261 switch(tag->ti_Tag)
263 case MUIA_NBitmap_Normal:
265 if(data->type == MUIV_NBitmap_Type_File)
267 data->data[0] = (uint32*)tag->ti_Data;
268 NBitmap_UpdateImage(0, (STRPTR)data->data[0], cl, obj);
269 MUI_Redraw(obj, MADF_DRAWOBJECT);
272 tag->ti_Tag = TAG_IGNORE;
274 break;
276 case MUIA_NBitmap_Ghosted:
278 if(data->type == MUIV_NBitmap_Type_File)
280 data->data[1] = (uint32*)tag->ti_Data;
281 NBitmap_UpdateImage(1, (STRPTR)data->data[1], cl, obj);
282 MUI_Redraw(obj, MADF_DRAWOBJECT);
285 tag->ti_Tag = TAG_IGNORE;
287 break;
289 case MUIA_NBitmap_Selected:
291 if(data->type == MUIV_NBitmap_Type_File)
293 data->data[2] = (uint32*)tag->ti_Data;
294 NBitmap_UpdateImage(2, (STRPTR)data->data[2], cl, obj);
295 MUI_Redraw(obj, MADF_DRAWOBJECT);
298 tag->ti_Tag = TAG_IGNORE;
300 break;
302 case MUIA_NBitmap_MaxWidth:
303 data->maxwidth = (uint32)tag->ti_Data;
304 tag->ti_Tag = TAG_IGNORE;
305 break;
307 case MUIA_NBitmap_MaxHeight:
308 data->maxheight = (uint32)tag->ti_Data;
309 tag->ti_Tag = TAG_IGNORE;
310 break;
314 result = DoSuperMethodA(cl, obj, (Msg)msg);
316 RETURN(result);
317 return result;
320 /* ULONG NBitmap_Dispose() */
321 static IPTR NBitmap_Dispose(struct IClass *cl, Object *obj, Msg msg)
323 IPTR result;
325 ENTER();
327 NBitmap_DisposeImage(cl, obj);
329 result = DoSuperMethodA(cl, obj, msg);
331 RETURN(result);
332 return result;
335 /* ULONG NBitmap_Setup() */
336 static IPTR NBitmap_Setup(struct IClass *cl, Object *obj, Msg msg)
338 IPTR result;
340 ENTER();
342 if((result = DoSuperMethodA(cl, obj, msg)) != 0)
344 result = NBitmap_SetupImage(cl, obj);
347 RETURN(result);
348 return result;
351 /* ULONG NBitmap_Cleanup() */
352 static IPTR NBitmap_Cleanup(struct IClass *cl, Object *obj, Msg msg)
354 IPTR result;
356 ENTER();
358 NBitmap_CleanupImage(cl, obj);
360 result = DoSuperMethodA(cl, obj, msg);
362 RETURN(result);
363 return(result);
366 /* ULONG NBitmap_HandleEvent() */
367 static IPTR NBitmap_HandleEvent(struct IClass *cl, Object *obj, struct MUIP_HandleEvent *msg)
369 struct InstData *data;
370 IPTR result;
372 //ENTER();
374 result = 0;
376 if((data = INST_DATA(cl, obj)) != NULL)
378 if(msg->imsg != NULL)
380 switch(msg->imsg->Class)
382 case IDCMP_MOUSEBUTTONS:
384 if(_isinobject(msg->imsg->MouseX, msg->imsg->MouseY))
386 if(msg->imsg->Code == SELECTDOWN)
388 if(data->pressed == FALSE)
390 data->pressed = TRUE;
392 MUI_Redraw(obj, MADF_DRAWUPDATE);
393 SetAttrs(obj, MUIA_Pressed, TRUE, TAG_DONE);
396 else if(msg->imsg->Code == SELECTUP)
398 if(data->overlay && data->pressed)
400 data->pressed = FALSE;
401 data->overlay = FALSE;
403 MUI_Redraw(obj, MADF_DRAWUPDATE);
404 SetAttrs(obj, MUIA_Pressed, FALSE, TAG_DONE);
408 result = MUI_EventHandlerRC_Eat;
410 else
412 if(msg->imsg->Code==SELECTUP)
414 data->pressed = FALSE;
418 break;
420 case IDCMP_MOUSEMOVE:
422 if(_isinobject(msg->imsg->MouseX, msg->imsg->MouseY))
424 if(data->overlay == FALSE)
426 data->overlay = TRUE;
428 MUI_Redraw(obj, MADF_DRAWUPDATE);
431 //result = MUI_EventHandlerRC_Eat;
433 else
435 if(data->overlay)
437 data->overlay = FALSE;
439 MUI_Redraw(obj, MADF_DRAWUPDATE);
443 break;
448 if(result == 0)
449 result = DoSuperMethodA(cl, obj, (Msg)msg);
451 //RETURN(result);
452 return result;
455 /* ULONG NBitmap_AskMinMax() */
456 static IPTR NBitmap_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
458 struct InstData *data;
460 ENTER();
462 DoSuperMethodA(cl, obj, (Msg)msg);
464 if((data = INST_DATA(cl, obj)) != NULL)
466 uint32 oldBorderHoriz = data->border_horiz;
467 uint32 oldBorderVert = data->border_vert;
469 // spacing
470 data->border_horiz = 0;
471 data->border_vert = 0;
473 if(data->button)
475 data->border_horiz += 4;
476 data->border_horiz += data->prefs.spacing_horiz * 2;
478 data->border_vert += 4;
479 data->border_vert += data->prefs.spacing_vert * 2;
482 /* label */
483 data->label_horiz = 0;
484 data->label_vert = 0;
486 if(data->label != NULL && data->button != FALSE)
488 struct RastPort rp;
490 memcpy(&rp, &_screen(obj)->RastPort, sizeof(rp));
492 SetFont(&rp, _font(obj));
493 TextExtent(&rp, (STRPTR)data->label, strlen(data->label), &data->labelte);
495 if(data->width < (uint32)data->labelte.te_Width)
496 data->border_horiz += (data->labelte.te_Width - data->width);
498 data->label_vert = data->labelte.te_Height;
499 data->border_vert += data->labelte.te_Height;
500 data->border_vert += 2;
503 // standard width & height
504 msg->MinMaxInfo->MinWidth = data->width + data->border_horiz;
505 msg->MinMaxInfo->DefWidth = data->width + data->border_horiz;
506 msg->MinMaxInfo->MaxWidth = data->width + data->border_horiz;
508 msg->MinMaxInfo->MinHeight = data->height + data->border_vert;
509 msg->MinMaxInfo->DefHeight = data->height + data->border_vert;
510 msg->MinMaxInfo->MaxHeight = data->height + data->border_vert;
512 if(data->border_horiz != oldBorderHoriz || data->border_vert != oldBorderVert)
514 if(data->depth > 8) {
515 // the border size has changed and we must recalculate the shade arrays
516 NBitmap_CleanupShades(data);
517 NBitmap_SetupShades(data);
522 RETURN(0);
523 return 0;
526 /* ULONG NBitmap_Draw() */
527 static IPTR NBitmap_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
529 IPTR result;
531 ENTER();
533 result = DoSuperMethodA(cl, obj, (Msg)msg);
535 if((msg->flags & MADF_DRAWUPDATE) || (msg->flags & MADF_DRAWOBJECT))
537 NBitmap_DrawImage(cl, obj);
540 RETURN(result);
541 return result;
544 /* DISPATCHER() */
545 DISPATCHER(_Dispatcher)
547 IPTR result;
549 //ENTER();
551 switch(msg->MethodID)
553 case OM_NEW:
554 result = NBitmap_New(cl, obj, (struct opSet *)msg);
555 break;
557 case OM_SET:
558 result = NBitmap_Set(cl, obj, (struct opSet *)msg);
559 break;
561 case OM_GET:
562 result = NBitmap_Get(cl, obj, (struct opGet *)msg);
563 break;
565 case OM_DISPOSE:
566 result = NBitmap_Dispose(cl, obj, msg);
567 break;
569 case MUIM_Setup:
570 result = NBitmap_Setup(cl, obj, msg);
571 break;
573 case MUIM_HandleEvent:
574 result = NBitmap_HandleEvent(cl, obj, (struct MUIP_HandleEvent *)msg);
575 break;
577 case MUIM_Cleanup:
578 result = NBitmap_Cleanup(cl, obj, msg);
579 break;
581 case MUIM_AskMinMax:
582 result = NBitmap_AskMinMax(cl, obj, (struct MUIP_AskMinMax *)msg);
583 break;
585 case MUIM_Draw:
586 result = NBitmap_Draw(cl, obj, (struct MUIP_Draw *)msg);
587 break;
589 default:
590 result = DoSuperMethodA(cl, obj, msg);
591 break;
594 //RETURN(result);
595 return result;