Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / Wanderer / Classes / iconlistview.c
blob9bcdddab0a631b57787cca76e15e1303c98cd5a6
1 /*
2 Copyright © 2002-2011, The AROS Development Team.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <exec/memory.h>
9 #include <intuition/icclass.h>
10 #include <intuition/gadgetclass.h>
12 #ifdef __AROS__
13 #include <aros/debug.h>
14 #include <clib/alib_protos.h>
15 #else
16 #include "../portable_macros.h"
17 #define WANDERER_BUILTIN_ICONLISTVIEW 1
18 #endif
20 #include <proto/exec.h>
21 #include <proto/utility.h>
23 #if defined(__AMIGA__) && !defined(__PPC__)
24 #define NO_INLINE_STDARG
25 #endif
26 #include <proto/intuition.h>
27 #include <proto/muimaster.h>
29 #include <libraries/mui.h>
30 //#include "muimaster_intern.h"
31 //#include "support.h"
32 #include "iconlist.h"
33 #include "iconlistview.h"
34 #include "iconlistview_private.h"
36 #ifndef __AROS__
38 #ifdef DEBUG
39 #define D(x) if (DEBUG) x
40 #ifdef __amigaos4__
41 #define bug DebugPrintF
42 #else
43 #define bug kprintf
44 #endif
45 #else
46 #define D(...)
47 #endif
49 #define ScrollbuttonObject MUI_MakeObject(MUIO_Button, (IPTR)"scroll"
51 #endif
53 extern struct Library *MUIMasterBase;
55 ///IconListview_Layout_Function()
56 ULONG IconListview_Layout_Function(struct Hook *hook, Object *obj, struct MUI_LayoutMsg *lm)
58 struct IconListview_DATA *data = (struct IconListview_DATA *)hook->h_Data;
60 switch (lm->lm_Type)
62 case MUILM_MINMAX:
64 /* Calulate the minmax dimension of the group,
65 ** We only have a fixed number of children, so we need no NextObject()
68 WORD maxxxxwidth = 0;
69 WORD maxxxxheight = 0;
71 maxxxxwidth = _minwidth(data->iconlist) + _minwidth(data->vert);
72 if (_minwidth(data->horiz) > maxxxxwidth) maxxxxwidth = _minwidth(data->horiz);
73 lm->lm_MinMax.MinWidth = maxxxxwidth;
75 maxxxxheight = _minheight(data->iconlist) + _minheight(data->horiz);
76 if (_minheight(data->vert) > maxxxxheight) maxxxxheight = _minheight(data->vert);
77 lm->lm_MinMax.MinHeight = maxxxxheight;
79 maxxxxwidth = _defwidth(data->iconlist) + _defwidth(data->vert);
80 if (_defwidth(data->horiz) > maxxxxwidth) maxxxxwidth = _defwidth(data->horiz);
81 lm->lm_MinMax.DefWidth = maxxxxwidth;
83 maxxxxheight = _defheight(data->iconlist) + _defheight(data->horiz);
84 if (_defheight(data->vert) > maxxxxheight) maxxxxheight = _defheight(data->vert);
85 lm->lm_MinMax.DefHeight = maxxxxheight;
87 lm->lm_MinMax.MaxWidth = MUI_MAXMAX;
88 lm->lm_MinMax.MaxHeight = MUI_MAXMAX;
90 return 0;
93 case MUILM_LAYOUT:
95 /*
96 Now place the objects between (0,0,lm->lm_Layout.Width-1,lm->lm_Layout.Height-1)
99 LONG virt_width = 0;
100 LONG virt_height = 0;
101 LONG vert_width = _minwidth(data->vert);
102 LONG horiz_height = _minheight(data->horiz);
103 LONG lay_width = lm->lm_Layout.Width;
104 LONG lay_height = lm->lm_Layout.Height;
105 LONG cont_width;
106 LONG cont_height;
108 /* layout the virtual group a first time, to determine the virtual width/height */
109 MUI_Layout(data->iconlist,0,0,lay_width,lay_height,0);
111 get(data->iconlist, MUIA_IconList_Width, &virt_width);
112 get(data->iconlist, MUIA_IconList_Height, &virt_height);
114 virt_width += _subwidth(data->iconlist);
115 virt_height += _subheight(data->iconlist);
117 if (virt_width > lay_width && virt_height > lay_height)
119 /* We need all scrollbars and the button */
120 set(data->vert, MUIA_ShowMe, TRUE); /* We could also overload MUIM_Show... */
121 set(data->horiz, MUIA_ShowMe, TRUE);
122 set(data->button, MUIA_ShowMe, TRUE);
123 cont_width = lay_width - vert_width;
124 cont_height = lay_height - horiz_height;
125 MUI_Layout(data->vert, cont_width, 0, vert_width, cont_height, 0);
126 MUI_Layout(data->horiz, 0, cont_height, cont_width, horiz_height, 0);
127 MUI_Layout(data->button, cont_width, cont_height, vert_width, horiz_height, 0);
129 else
131 if (virt_height > lay_height)
133 set(data->vert, MUIA_ShowMe, TRUE);
134 set(data->horiz, MUIA_ShowMe, FALSE);
135 set(data->button, MUIA_ShowMe, FALSE);
137 cont_width = lay_width - vert_width;
138 cont_height = lay_height;
139 MUI_Layout(data->vert, cont_width, 0, vert_width, cont_height,0);
141 else
143 if (virt_width > lay_width)
145 set(data->vert, MUIA_ShowMe, FALSE);
146 set(data->horiz, MUIA_ShowMe, TRUE);
147 set(data->button, MUIA_ShowMe, FALSE);
149 cont_width = lay_width;
150 cont_height = lay_height - horiz_height;
151 MUI_Layout(data->horiz, 0, cont_height, cont_width, horiz_height, 0);
153 else
155 set(data->vert, MUIA_ShowMe, FALSE);
156 set(data->horiz, MUIA_ShowMe, FALSE);
157 set(data->button, MUIA_ShowMe, FALSE);
159 cont_width = lay_width;
160 cont_height = lay_height;
165 /* Layout the group a second time, note that setting _mwidth() and _mheight() should be enough, or we invent a new flag */
166 MUI_Layout(data->iconlist,0,0,cont_width,cont_height,0);
168 return 1;
171 return 0;
175 ///IconListview_Function()
176 ULONG IconListview_Function(struct Hook *hook, APTR dummyobj, void **msg)
178 struct IconListview_DATA *data = (struct IconListview_DATA *)hook->h_Data;
179 int type = (IPTR)msg[0];
180 LONG val = (IPTR)msg[1];
182 switch (type)
184 case 1:
186 get(data->vert,MUIA_Prop_First,&val);
187 SetAttrs(data->iconlist,MUIA_Virtgroup_Top, val, MUIA_NoNotify, TRUE, TAG_DONE);
188 break;
191 case 2:
193 get(data->horiz,MUIA_Prop_First,&val);
194 SetAttrs(data->iconlist,MUIA_Virtgroup_Left, val, MUIA_NoNotify, TRUE, TAG_DONE);
195 break;
197 case 3:
198 nnset(data->horiz, MUIA_Prop_First, val);
199 break;
200 case 4:
201 nnset(data->vert, MUIA_Prop_First, val);
202 break;
205 return 0;
209 ///OM_NEW()
210 IPTR IconListview__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
212 struct IconListview_DATA *data;
213 //struct TagItem *tags,*tag;
214 Object *iconlist = (Object*)GetTagData(MUIA_IconListview_IconList, 0, msg->ops_AttrList);
215 Object *vert,*horiz,*button,*group;
217 struct Hook *layout_hook = AllocVec(sizeof(struct Hook), MEMF_CLEAR);
218 int usewinborder;
220 if (!layout_hook)
221 return 0;
222 usewinborder = GetTagData(MUIA_IconListview_UseWinBorder, FALSE, msg->ops_AttrList);
224 if (!usewinborder)
225 button = ScrollbuttonObject, End;
226 else
227 button = NULL;
229 #ifndef __amigaos4__
230 layout_hook->h_Entry = HookEntry;
231 #endif
232 layout_hook->h_SubEntry = (HOOKFUNC)IconListview_Layout_Function;
234 group = MUI_NewObject(MUIC_Group,
235 (usewinborder ? TAG_IGNORE : MUIA_Group_LayoutHook), layout_hook,
236 (iconlist ? Child : TAG_IGNORE), iconlist,
237 Child, vert= MUI_NewObject(MUIC_Scrollbar,
238 (usewinborder ? MUIA_Prop_UseWinBorder : TAG_IGNORE), MUIV_Prop_UseWinBorder_Right,
239 MUIA_Prop_DeltaFactor, 20,
240 MUIA_Group_Horiz, FALSE,
241 TAG_DONE),
242 Child, horiz = MUI_NewObject(MUIC_Scrollbar,
243 (usewinborder ? MUIA_Prop_UseWinBorder : TAG_IGNORE), MUIV_Prop_UseWinBorder_Bottom,
244 MUIA_Prop_DeltaFactor, 20,
245 MUIA_Group_Horiz, TRUE,
246 TAG_DONE),
247 (usewinborder ? TAG_IGNORE : Child), button,
248 TAG_DONE);
250 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
251 MUIA_Group_Horiz, FALSE,
252 MUIA_Group_HorizSpacing, 0,
253 MUIA_Group_VertSpacing, 0,
254 MUIA_Frame, MUIV_Frame_None,
256 Child, (IPTR) group,
257 TAG_DONE);
259 if (!obj)
261 MUI_DisposeObject(group);
262 FreeVec(layout_hook);
263 return 0;
266 data = INST_DATA(cl, obj);
268 D(bug("[IconListview] %s: SELF = 0x%p\n", __PRETTY_FUNCTION__, obj));
270 data->vert = vert;
271 data->horiz = horiz;
272 data->button = button;
273 data->iconlist = iconlist;
275 #ifndef __amigaos4__
276 data->hook.h_Entry = HookEntry;
277 #endif
278 data->hook.h_SubEntry = (HOOKFUNC)IconListview_Function;
279 data->hook.h_Data = data;
280 data->layout_hook = layout_hook;
281 layout_hook->h_Data = data;
283 DoMethod(vert, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 1, MUIV_TriggerValue);
284 DoMethod(horiz, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 2, MUIV_TriggerValue);
285 DoMethod(iconlist, MUIM_Notify, MUIA_Virtgroup_Left, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 3, MUIV_TriggerValue);
286 DoMethod(iconlist, MUIM_Notify, MUIA_Virtgroup_Top, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 4, MUIV_TriggerValue);
287 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Width, MUIV_EveryTime, (IPTR)horiz, 3, MUIM_NoNotifySet, MUIA_Prop_Entries, MUIV_TriggerValue);
288 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Height, MUIV_EveryTime, (IPTR)vert, 3, MUIM_NoNotifySet, MUIA_Prop_Entries, MUIV_TriggerValue);
290 D(bug("[IconListview] obj = %ld\n", obj));
291 return (IPTR)obj;
295 ///OM_DISPOSE()
296 IPTR IconListview__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
298 struct IconListview_DATA *data = INST_DATA(cl, obj);
300 FreeVec(data->layout_hook);
302 return DoSuperMethodA(cl,obj,msg);
305 IPTR IconListview__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
307 struct TagItem *tag, *tags;
309 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
311 switch (tag->ti_Tag)
313 case MUIA_Background:
314 D(bug("[IconListview] %s: MUIA_Background!\n", __PRETTY_FUNCTION__));
315 break;
319 return DoSuperMethodA(cl, obj, (Msg)msg);
324 ///OM_GET()
325 /**************************************************************************
326 OM_GET
327 **************************************************************************/
328 IPTR IconListview__OM_GET(struct IClass *CLASS, Object *obj, struct opGet *message)
330 #define STORE *(message->opg_Storage)
332 D(bug("[IconListview]: %s()\n", __PRETTY_FUNCTION__));
334 switch (message->opg_AttrID)
336 /* TODO: Get the version/revision from our config.. */
337 case MUIA_Version: STORE = (IPTR)1; return 1;
338 case MUIA_Revision: STORE = (IPTR)3; return 1;
341 return DoSuperMethodA(CLASS, obj, (Msg) message);
342 #undef STORE
346 ///MUIM_Show()
347 IPTR IconListview__MUIM_Show(struct IClass *cl, Object *obj, struct MUIP_Show *msg)
349 struct IconListview_DATA *data = INST_DATA(cl, obj);
350 IPTR top = 0;
351 IPTR left = 0;
352 IPTR width = 0;
353 IPTR height = 0;
355 get(data->iconlist, MUIA_Virtgroup_Left, &left);
356 get(data->iconlist, MUIA_Virtgroup_Top, &top);
357 get(data->iconlist, MUIA_IconList_Width, &width);
358 get(data->iconlist, MUIA_IconList_Height, &height);
360 SetAttrs(
361 data->horiz,
362 MUIA_Prop_First, left,
363 MUIA_Prop_Entries, width,
364 MUIA_Prop_Visible, _mwidth(data->iconlist),
365 TAG_DONE
368 SetAttrs(
369 data->vert,
370 MUIA_Prop_First, top,
371 MUIA_Prop_Entries, height,
372 MUIA_Prop_Visible, _mheight(data->iconlist),
373 TAG_DONE
376 return DoSuperMethodA(cl,obj,(Msg)msg);
380 #if WANDERER_BUILTIN_ICONLISTVIEW
381 BOOPSI_DISPATCHER(IPTR,IconListview_Dispatcher, cl, obj, msg)
383 switch (msg->MethodID)
385 case OM_NEW: return IconListview__OM_NEW(cl, obj, (struct opSet *) msg);
386 case OM_DISPOSE: return IconListview__OM_DISPOSE(cl, obj, msg);
387 case MUIM_Show: return IconListview__MUIM_Show(cl, obj, (struct MUIP_Show*)msg);
388 case OM_SET: return IconListview__OM_SET(cl, obj, (struct opGet *) msg);
389 case OM_GET: return IconListview__OM_GET(cl, obj, (struct opSet *) msg);
391 return DoSuperMethodA(cl, obj, msg);
393 BOOPSI_DISPATCHER_END
395 #ifdef __AROS__
396 const struct __MUIBuiltinClass _MUI_IconListview_desc =
398 MUIC_IconListview,
399 MUIC_Group,
400 sizeof(struct IconListview_DATA),
401 (void*)IconListview_Dispatcher
403 #endif
404 #endif /* ZUNE_BUILTIN_ICONLISTVIEW */
406 #ifndef __AROS__
407 struct MUI_CustomClass *initIconListviewClass(void)
409 return (struct MUI_CustomClass *) MUI_CreateCustomClass(NULL, MUIC_Group, NULL, sizeof(struct IconListview_DATA), ENTRY(IconListview_Dispatcher));
412 #endif