2 Copyright © 2002-2011, The AROS Development Team.
8 #include <exec/memory.h>
9 #include <intuition/icclass.h>
10 #include <intuition/gadgetclass.h>
13 #include <aros/debug.h>
14 #include <clib/alib_protos.h>
16 #include "../portable_macros.h"
17 #define WANDERER_BUILTIN_ICONLISTVIEW 1
20 #include <proto/exec.h>
21 #include <proto/utility.h>
23 #if defined(__AMIGA__) && !defined(__PPC__)
24 #define NO_INLINE_STDARG
26 #include <proto/intuition.h>
27 #include <proto/muimaster.h>
29 #include <libraries/mui.h>
30 //#include "muimaster_intern.h"
31 //#include "support.h"
33 #include "iconlistview.h"
34 #include "iconlistview_private.h"
39 #define D(x) if (DEBUG) x
41 #define bug DebugPrintF
49 #define ScrollbuttonObject MUI_MakeObject(MUIO_Button, (IPTR)"scroll"
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
;
64 /* Calulate the minmax dimension of the group,
65 ** We only have a fixed number of children, so we need no NextObject()
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
;
96 Now place the objects between (0,0,lm->lm_Layout.Width-1,lm->lm_Layout.Height-1)
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
;
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);
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);
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);
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);
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];
186 get(data
->vert
,MUIA_Prop_First
,&val
);
187 SetAttrs(data
->iconlist
,MUIA_Virtgroup_Top
, val
, MUIA_NoNotify
, TRUE
, TAG_DONE
);
193 get(data
->horiz
,MUIA_Prop_First
,&val
);
194 SetAttrs(data
->iconlist
,MUIA_Virtgroup_Left
, val
, MUIA_NoNotify
, TRUE
, TAG_DONE
);
198 nnset(data
->horiz
, MUIA_Prop_First
, val
);
201 nnset(data
->vert
, MUIA_Prop_First
, val
);
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
);
222 usewinborder
= GetTagData(MUIA_IconListview_UseWinBorder
, FALSE
, msg
->ops_AttrList
);
225 button
= ScrollbuttonObject
, End
;
230 layout_hook
->h_Entry
= HookEntry
;
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
,
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
,
247 (usewinborder
? TAG_IGNORE
: Child
), button
,
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
,
261 MUI_DisposeObject(group
);
262 FreeVec(layout_hook
);
266 data
= INST_DATA(cl
, obj
);
268 D(bug("[IconListview] %s: SELF = 0x%p\n", __PRETTY_FUNCTION__
, obj
));
272 data
->button
= button
;
273 data
->iconlist
= iconlist
;
276 data
->hook
.h_Entry
= HookEntry
;
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
));
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
)); )
313 case MUIA_Background
:
314 D(bug("[IconListview] %s: MUIA_Background!\n", __PRETTY_FUNCTION__
));
319 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
325 /**************************************************************************
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
);
347 IPTR
IconListview__MUIM_Show(struct IClass
*cl
, Object
*obj
, struct MUIP_Show
*msg
)
349 struct IconListview_DATA
*data
= INST_DATA(cl
, obj
);
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
);
362 MUIA_Prop_First
, left
,
363 MUIA_Prop_Entries
, width
,
364 MUIA_Prop_Visible
, _mwidth(data
->iconlist
),
370 MUIA_Prop_First
, top
,
371 MUIA_Prop_Entries
, height
,
372 MUIA_Prop_Visible
, _mheight(data
->iconlist
),
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
396 const struct __MUIBuiltinClass _MUI_IconListview_desc
=
400 sizeof(struct IconListview_DATA
),
401 (void*)IconListview_Dispatcher
404 #endif /* ZUNE_BUILTIN_ICONLISTVIEW */
407 struct MUI_CustomClass
*initIconListviewClass(void)
409 return (struct MUI_CustomClass
*) MUI_CreateCustomClass(NULL
, MUIC_Group
, NULL
, sizeof(struct IconListview_DATA
), ENTRY(IconListview_Dispatcher
));