2 Copyright © 2002-2009, The AROS Development Team.
7 #include "../portable_macros.h"
8 #define WANDERER_BUILTIN_ICONLISTVIEW 1
11 #include <aros/debug.h>
14 #include <exec/memory.h>
15 #include <intuition/icclass.h>
16 #include <intuition/gadgetclass.h>
19 #include <clib/alib_protos.h>
22 #include <proto/exec.h>
23 #include <proto/utility.h>
25 #if defined(__AMIGA__) && !defined(__PPC__)
26 #define NO_INLINE_STDARG
28 #include <proto/intuition.h>
29 #include <proto/muimaster.h>
31 #include <libraries/mui.h>
32 //#include "muimaster_intern.h"
33 //#include "support.h"
35 #include "iconlistview.h"
36 #include "iconlistview_private.h"
42 #define D(x) if (DEBUG) x
44 #define bug DebugPrintF
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)
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
= (int)msg
[0];
180 LONG val
= (LONG
)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
);
226 button
= ScrollbuttonObject
, End
;
229 button
= MUI_MakeObject(MUIO_Button
,(IPTR
)"scroll", TAG_DONE
);
236 layout_hook
->h_Entry
= HookEntry
;
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
,
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
,
253 (usewinborder
? TAG_IGNORE
: Child
), button
,
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
,
267 MUI_DisposeObject(group
);
268 FreeVec(layout_hook
);
272 data
= INST_DATA(cl
, obj
);
274 D(bug("[IconListview] %s: SELF = 0x%p\n", __PRETTY_FUNCTION__
, obj
));
278 data
->button
= button
;
279 data
->iconlist
= iconlist
;
282 data
->hook
.h_Entry
= HookEntry
;
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
));
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
)); )
319 case MUIA_Background
:
320 D(bug("[IconListview] %s: MUIA_Background!\n", __PRETTY_FUNCTION__
));
325 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
331 /**************************************************************************
333 **************************************************************************/
334 IPTR
IconListview__OM_GET(struct IClass
*CLASS
, Object
*obj
, struct opGet
*message
)
336 #define STORE *(message->opg_Storage)
338 D(bug("[IconListview]: %s()\n", __PRETTY_FUNCTION__
));
340 switch (message
->opg_AttrID
)
342 #warning "TODO: Get the version/revision from our config.."
343 case MUIA_Version
: STORE
= (IPTR
)1; return 1;
344 case MUIA_Revision
: STORE
= (IPTR
)3; return 1;
347 return DoSuperMethodA(CLASS
, obj
, (Msg
) message
);
353 IPTR
IconListview__MUIM_Show(struct IClass
*cl
, Object
*obj
, struct MUIP_Show
*msg
)
355 struct IconListview_DATA
*data
= INST_DATA(cl
, obj
);
356 LONG top
,left
,width
,height
;
358 get(data
->iconlist
, MUIA_Virtgroup_Left
, &left
);
359 get(data
->iconlist
, MUIA_Virtgroup_Top
, &top
);
360 get(data
->iconlist
, MUIA_IconList_Width
, &width
);
361 get(data
->iconlist
, MUIA_IconList_Height
, &height
);
365 MUIA_Prop_First
, left
,
366 MUIA_Prop_Entries
, width
,
367 MUIA_Prop_Visible
, _mwidth(data
->iconlist
),
373 MUIA_Prop_First
, top
,
374 MUIA_Prop_Entries
, height
,
375 MUIA_Prop_Visible
, _mheight(data
->iconlist
),
379 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
383 #if WANDERER_BUILTIN_ICONLISTVIEW
384 BOOPSI_DISPATCHER(IPTR
,IconListview_Dispatcher
, cl
, obj
, msg
)
386 switch (msg
->MethodID
)
388 case OM_NEW
: return IconListview__OM_NEW(cl
, obj
, (struct opSet
*) msg
);
389 case OM_DISPOSE
: return IconListview__OM_DISPOSE(cl
, obj
, msg
);
390 case MUIM_Show
: return IconListview__MUIM_Show(cl
, obj
, (struct MUIP_Show
*)msg
);
391 case OM_SET
: return IconListview__OM_SET(cl
, obj
, (struct opGet
*) msg
);
392 case OM_GET
: return IconListview__OM_GET(cl
, obj
, (struct opSet
*) msg
);
394 return DoSuperMethodA(cl
, obj
, msg
);
396 BOOPSI_DISPATCHER_END
399 const struct __MUIBuiltinClass _MUI_IconListview_desc
=
403 sizeof(struct IconListview_DATA
),
404 (void*)IconListview_Dispatcher
407 #endif /* ZUNE_BUILTIN_ICONLISTVIEW */
410 struct MUI_CustomClass
*initIconListviewClass(void)
412 return (struct MUI_CustomClass
*) MUI_CreateCustomClass(NULL
, MUIC_Group
, NULL
, sizeof(struct IconListview_DATA
), ENTRY(IconListview_Dispatcher
));