Some compiler warnings removed.
[cake.git] / workbench / system / Wanderer / Classes / iconlistview.c
blob28dca6d39949a9153b3eef904cac1514c547cf2d
1 /*
2 Copyright © 2002-2009, The AROS Development Team.
3 $Id$
4 */
6 #ifndef __AROS__
7 #include "../portable_macros.h"
8 #define WANDERER_BUILTIN_ICONLISTVIEW 1
9 #else
10 #define DEBUG 0
11 #include <aros/debug.h>
12 #endif
14 #include <exec/memory.h>
15 #include <intuition/icclass.h>
16 #include <intuition/gadgetclass.h>
18 #ifdef __AROS__
19 #include <clib/alib_protos.h>
20 #endif
22 #include <proto/exec.h>
23 #include <proto/utility.h>
25 #if defined(__AMIGA__) && !defined(__PPC__)
26 #define NO_INLINE_STDARG
27 #endif
28 #include <proto/intuition.h>
29 #include <proto/muimaster.h>
31 #include <libraries/mui.h>
32 //#include "muimaster_intern.h"
33 //#include "support.h"
34 #include "iconlist.h"
35 #include "iconlistview.h"
36 #include "iconlistview_private.h"
38 #ifndef __AROS__
39 #define DEBUG 1
41 #ifdef DEBUG
42 #define D(x) if (DEBUG) x
43 #ifdef __amigaos4__
44 #define bug DebugPrintF
45 #else
46 #define bug kprintf
47 #endif
48 #else
49 #define D(...)
50 #endif
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;
100 LONG virt_height;
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 = (int)msg[0];
180 LONG val = (LONG)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 #ifdef __AROS__
225 if (!usewinborder)
226 button = ScrollbuttonObject, End;
227 #else
228 if (!usewinborder)
229 button = MUI_MakeObject(MUIO_Button,(IPTR)"scroll", TAG_DONE);
230 #endif
232 else
233 button = NULL;
235 #ifndef __amigaos4__
236 layout_hook->h_Entry = HookEntry;
237 #endif
238 layout_hook->h_SubEntry = (HOOKFUNC)IconListview_Layout_Function;
240 group = MUI_NewObject(MUIC_Group,
241 (usewinborder ? TAG_IGNORE : MUIA_Group_LayoutHook), layout_hook,
242 (iconlist ? Child : TAG_IGNORE), iconlist,
243 Child, vert= MUI_NewObject(MUIC_Scrollbar,
244 (usewinborder ? MUIA_Prop_UseWinBorder : TAG_IGNORE), MUIV_Prop_UseWinBorder_Right,
245 MUIA_Prop_DeltaFactor, 20,
246 MUIA_Group_Horiz, FALSE,
247 TAG_DONE),
248 Child, horiz = MUI_NewObject(MUIC_Scrollbar,
249 (usewinborder ? MUIA_Prop_UseWinBorder : TAG_IGNORE), MUIV_Prop_UseWinBorder_Bottom,
250 MUIA_Prop_DeltaFactor, 20,
251 MUIA_Group_Horiz, TRUE,
252 TAG_DONE),
253 (usewinborder ? TAG_IGNORE : Child), button,
254 TAG_DONE);
256 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
257 MUIA_Group_Horiz, FALSE,
258 MUIA_Group_HorizSpacing, 0,
259 MUIA_Group_VertSpacing, 0,
260 MUIA_Frame, MUIV_Frame_None,
262 Child, (IPTR) group,
263 TAG_DONE);
265 if (!obj)
267 MUI_DisposeObject(group);
268 FreeVec(layout_hook);
269 return 0;
272 data = INST_DATA(cl, obj);
274 D(bug("[IconListview] %s: SELF = 0x%p\n", __PRETTY_FUNCTION__, obj));
276 data->vert = vert;
277 data->horiz = horiz;
278 data->button = button;
279 data->iconlist = iconlist;
281 #ifndef __amigaos4__
282 data->hook.h_Entry = HookEntry;
283 #endif
284 data->hook.h_SubEntry = (HOOKFUNC)IconListview_Function;
285 data->hook.h_Data = data;
286 data->layout_hook = layout_hook;
287 layout_hook->h_Data = data;
289 DoMethod(vert, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 1, MUIV_TriggerValue);
290 DoMethod(horiz, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 2, MUIV_TriggerValue);
291 DoMethod(iconlist, MUIM_Notify, MUIA_Virtgroup_Left, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 3, MUIV_TriggerValue);
292 DoMethod(iconlist, MUIM_Notify, MUIA_Virtgroup_Top, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 4, MUIV_TriggerValue);
293 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Width, MUIV_EveryTime, (IPTR)horiz, 3, MUIM_NoNotifySet, MUIA_Prop_Entries, MUIV_TriggerValue);
294 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Height, MUIV_EveryTime, (IPTR)vert, 3, MUIM_NoNotifySet, MUIA_Prop_Entries, MUIV_TriggerValue);
296 D(bug("[IconListview] obj = %ld\n", obj));
297 return (ULONG)obj;
301 ///OM_DISPOSE()
302 IPTR IconListview__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
304 struct IconListview_DATA *data = INST_DATA(cl, obj);
306 FreeVec(data->layout_hook);
308 return DoSuperMethodA(cl,obj,msg);
311 IPTR IconListview__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
313 struct TagItem *tag, *tags;
315 for (tags = msg->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
317 switch (tag->ti_Tag)
319 case MUIA_Background:
320 D(bug("[IconListview] %s: MUIA_Background!\n", __PRETTY_FUNCTION__));
321 break;
325 return DoSuperMethodA(cl, obj, (Msg)msg);
329 ///MUIM_Show()
330 IPTR IconListview__MUIM_Show(struct IClass *cl, Object *obj, struct MUIP_Show *msg)
332 struct IconListview_DATA *data = INST_DATA(cl, obj);
333 LONG top,left,width,height;
335 get(data->iconlist, MUIA_Virtgroup_Left, &left);
336 get(data->iconlist, MUIA_Virtgroup_Top, &top);
337 get(data->iconlist, MUIA_IconList_Width, &width);
338 get(data->iconlist, MUIA_IconList_Height, &height);
340 SetAttrs(
341 data->horiz,
342 MUIA_Prop_First, left,
343 MUIA_Prop_Entries, width,
344 MUIA_Prop_Visible, _mwidth(data->iconlist),
345 TAG_DONE
348 SetAttrs(
349 data->vert,
350 MUIA_Prop_First, top,
351 MUIA_Prop_Entries, height,
352 MUIA_Prop_Visible, _mheight(data->iconlist),
353 TAG_DONE
356 return DoSuperMethodA(cl,obj,(Msg)msg);
360 #if WANDERER_BUILTIN_ICONLISTVIEW
361 BOOPSI_DISPATCHER(IPTR,IconListview_Dispatcher, cl, obj, msg)
363 switch (msg->MethodID)
365 case OM_NEW:
366 return IconListview__OM_NEW(cl, obj, (struct opSet *) msg);
367 case OM_DISPOSE:
368 return IconListview__OM_DISPOSE(cl, obj, msg);
369 case MUIM_Show:
370 return IconListview__MUIM_Show(cl, obj, (struct MUIP_Show*)msg);
371 case OM_SET:
372 return IconListview__OM_SET(cl, obj, (struct opSet *) msg);
374 return DoSuperMethodA(cl, obj, msg);
376 BOOPSI_DISPATCHER_END
378 #ifdef __AROS__
379 const struct __MUIBuiltinClass _MUI_IconListview_desc =
381 MUIC_IconListview,
382 MUIC_Group,
383 sizeof(struct IconListview_DATA),
384 (void*)IconListview_Dispatcher
386 #endif
387 #endif /* ZUNE_BUILTIN_ICONLISTVIEW */
389 #ifndef __AROS__
390 struct MUI_CustomClass *initIconListviewClass(void)
392 return (struct MUI_CustomClass *) MUI_CreateCustomClass(NULL, MUIC_Group, NULL, sizeof(struct IconListview_DATA), ENTRY(IconListview_Dispatcher));
395 #endif