added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / muimaster / classes / iconlistview.c
blob04b6077647fb8ef7cedad162e88da9aaad7f0b26
1 /*
2 Copyright © 2002, The AROS Development Team.
3 All rights reserved.
5 $Id$
6 */
8 //#define MYDEBUG
9 #include "debug.h"
11 #include <exec/memory.h>
12 #include <intuition/icclass.h>
13 #include <intuition/gadgetclass.h>
14 #include <clib/alib_protos.h>
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/utility.h>
18 #include <proto/muimaster.h>
20 #include "mui.h"
21 #include "muimaster_intern.h"
22 #include "support.h"
23 #include "iconlistview_private.h"
25 extern struct Library *MUIMasterBase;
28 ULONG IconListview_Layout_Function(struct Hook *hook, Object *obj, struct MUI_LayoutMsg *lm)
30 struct IconListview_DATA *data = (struct IconListview_DATA *)hook->h_Data;
32 switch (lm->lm_Type)
34 case MUILM_MINMAX:
36 /* Calulate the minmax dimension of the group,
37 ** We only have a fixed number of children, so we need no NextObject()
40 WORD maxxxxwidth = 0;
41 WORD maxxxxheight = 0;
43 maxxxxwidth = _minwidth(data->iconlist) + _minwidth(data->vert);
44 if (_minwidth(data->horiz) > maxxxxwidth) maxxxxwidth = _minwidth(data->horiz);
45 lm->lm_MinMax.MinWidth = maxxxxwidth;
47 maxxxxheight = _minheight(data->iconlist) + _minheight(data->horiz);
48 if (_minheight(data->vert) > maxxxxheight) maxxxxheight = _minheight(data->vert);
49 lm->lm_MinMax.MinHeight = maxxxxheight;
51 maxxxxwidth = _defwidth(data->iconlist) + _defwidth(data->vert);
52 if (_defwidth(data->horiz) > maxxxxwidth) maxxxxwidth = _defwidth(data->horiz);
53 lm->lm_MinMax.DefWidth = maxxxxwidth;
55 maxxxxheight = _defheight(data->iconlist) + _defheight(data->horiz);
56 if (_defheight(data->vert) > maxxxxheight) maxxxxheight = _defheight(data->vert);
57 lm->lm_MinMax.DefHeight = maxxxxheight;
59 lm->lm_MinMax.MaxWidth = MUI_MAXMAX;
60 lm->lm_MinMax.MaxHeight = MUI_MAXMAX;
62 return 0;
65 case MUILM_LAYOUT:
67 /*
68 Now place the objects between (0,0,lm->lm_Layout.Width-1,lm->lm_Layout.Height-1)
71 LONG virt_width;
72 LONG virt_height;
73 LONG vert_width = _minwidth(data->vert);
74 LONG horiz_height = _minheight(data->horiz);
75 LONG lay_width = lm->lm_Layout.Width;
76 LONG lay_height = lm->lm_Layout.Height;
77 LONG cont_width;
78 LONG cont_height;
80 /* layout the virtual group a first time, to determine the virtual width/height */
81 MUI_Layout(data->iconlist,0,0,lay_width,lay_height,0);
83 get(data->iconlist, MUIA_IconList_Width, &virt_width);
84 get(data->iconlist, MUIA_IconList_Height, &virt_height);
86 virt_width += _subwidth(data->iconlist);
87 virt_height += _subheight(data->iconlist);
89 if (virt_width > lay_width && virt_height > lay_height)
91 /* We need all scrollbars and the button */
92 set(data->vert, MUIA_ShowMe, TRUE); /* We could also overload MUIM_Show... */
93 set(data->horiz, MUIA_ShowMe, TRUE);
94 set(data->button, MUIA_ShowMe, TRUE);
95 cont_width = lay_width - vert_width;
96 cont_height = lay_height - horiz_height;
97 MUI_Layout(data->vert, cont_width, 0, vert_width, cont_height, 0);
98 MUI_Layout(data->horiz, 0, cont_height, cont_width, horiz_height, 0);
99 MUI_Layout(data->button, cont_width, cont_height, vert_width, horiz_height, 0);
101 else
103 if (virt_height > lay_height)
105 set(data->vert, MUIA_ShowMe, TRUE);
106 set(data->horiz, MUIA_ShowMe, FALSE);
107 set(data->button, MUIA_ShowMe, FALSE);
109 cont_width = lay_width - vert_width;
110 cont_height = lay_height;
111 MUI_Layout(data->vert, cont_width, 0, vert_width, cont_height,0);
113 else
115 if (virt_width > lay_width)
117 set(data->vert, MUIA_ShowMe, FALSE);
118 set(data->horiz, MUIA_ShowMe, TRUE);
119 set(data->button, MUIA_ShowMe, FALSE);
121 cont_width = lay_width;
122 cont_height = lay_height - horiz_height;
123 MUI_Layout(data->horiz, 0, cont_height, cont_width, horiz_height, 0);
125 else
127 set(data->vert, MUIA_ShowMe, FALSE);
128 set(data->horiz, MUIA_ShowMe, FALSE);
129 set(data->button, MUIA_ShowMe, FALSE);
131 cont_width = lay_width;
132 cont_height = lay_height;
137 /* Layout the group a second time, note that setting _mwidth() and _mheight() should be enough, or we invent a new flag */
138 MUI_Layout(data->iconlist,0,0,cont_width,cont_height,0);
140 return 1;
143 return 0;
147 ULONG IconListview_Function(struct Hook *hook, APTR dummyobj, void **msg)
149 struct IconListview_DATA *data = (struct IconListview_DATA *)hook->h_Data;
150 int type = (int)msg[0];
151 LONG val = (LONG)msg[1];
153 switch (type)
155 case 1:
157 get(data->vert,MUIA_Prop_First,&val);
158 SetAttrs(data->iconlist,MUIA_IconList_Top, val, MUIA_NoNotify, TRUE, TAG_DONE);
159 break;
162 case 2:
164 get(data->horiz,MUIA_Prop_First,&val);
165 SetAttrs(data->iconlist,MUIA_IconList_Left, val, MUIA_NoNotify, TRUE, TAG_DONE);
166 break;
168 case 3:
169 nnset(data->horiz, MUIA_Prop_First, val);
170 break;
171 case 4:
172 nnset(data->vert, MUIA_Prop_First, val);
173 break;
176 return 0;
180 IPTR IconListview__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
182 struct IconListview_DATA *data;
183 //struct TagItem *tags,*tag;
184 Object *iconlist = (Object*)GetTagData(MUIA_IconListview_IconList, NULL, msg->ops_AttrList);
185 Object *vert,*horiz,*button,*group;
187 struct Hook *layout_hook = mui_alloc_struct(struct Hook);
188 int usewinborder;
190 if (!layout_hook)
191 return NULL;
192 usewinborder = GetTagData(MUIA_IconListview_UseWinBorder, FALSE, msg->ops_AttrList);
194 if (!usewinborder)
195 button = ScrollbuttonObject, End;
196 else
197 button = NULL;
199 layout_hook->h_Entry = HookEntry;
200 layout_hook->h_SubEntry = (HOOKFUNC)IconListview_Layout_Function;
202 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
203 MUIA_Group_Horiz, FALSE,
204 MUIA_Group_HorizSpacing, 0,
205 MUIA_Group_VertSpacing, 0,
206 MUIA_Frame, MUIV_Frame_None,
208 Child, (IPTR) (
209 group = GroupObject,
210 usewinborder ? TAG_IGNORE : MUIA_Group_LayoutHook, layout_hook,
211 Child, iconlist,
212 Child, vert = ScrollbarObject,
213 usewinborder ? MUIA_Prop_UseWinBorder : TAG_IGNORE, MUIV_Prop_UseWinBorder_Right,
214 MUIA_Prop_DeltaFactor, 20,
215 MUIA_Group_Horiz, FALSE,
216 End,
217 Child, horiz = ScrollbarObject,
218 usewinborder ? MUIA_Prop_UseWinBorder : TAG_IGNORE, MUIV_Prop_UseWinBorder_Bottom,
219 MUIA_Prop_DeltaFactor, 20,
220 MUIA_Group_Horiz, TRUE,
221 End,
222 usewinborder ? TAG_IGNORE : Child, button,
223 End ),
224 TAG_DONE
227 if (!obj)
229 mui_free(layout_hook);
230 return NULL;
233 data = INST_DATA(cl, obj);
235 D(bug("[IconListview] IconListview__OM_NEW: SELF = 0x%p\n", obj));
237 data->vert = vert;
238 data->horiz = horiz;
239 data->button = button;
240 data->iconlist = iconlist;
242 data->hook.h_Entry = HookEntry;
243 data->hook.h_SubEntry = (HOOKFUNC)IconListview_Function;
244 data->hook.h_Data = data;
245 data->layout_hook = layout_hook;
246 layout_hook->h_Data = data;
248 DoMethod(vert, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 1, MUIV_TriggerValue);
249 DoMethod(horiz, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 2, MUIV_TriggerValue);
250 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Left, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 3, MUIV_TriggerValue);
251 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Top, MUIV_EveryTime, (IPTR)obj, 4, MUIM_CallHook, (IPTR)&data->hook, 4, MUIV_TriggerValue);
252 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Width, MUIV_EveryTime, (IPTR)horiz, 3, MUIM_NoNotifySet, MUIA_Prop_Entries, MUIV_TriggerValue);
253 DoMethod(iconlist, MUIM_Notify, MUIA_IconList_Height, MUIV_EveryTime, (IPTR)vert, 3, MUIM_NoNotifySet, MUIA_Prop_Entries, MUIV_TriggerValue);
255 return (ULONG)obj;
259 IPTR IconListview__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
261 struct IconListview_DATA *data = INST_DATA(cl, obj);
263 mui_free(data->layout_hook);
265 return DoSuperMethodA(cl,obj,msg);
268 IPTR IconListview__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
270 struct IconListview_DATA *data = INST_DATA(cl, obj);
271 struct TagItem *tag, *tags;
273 for (tags = msg->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
275 switch (tag->ti_Tag)
277 case MUIA_Background:
278 D(bug("[IconListview] IconListview__OM_SET: MUIA_Background!\n"));
279 break;
283 return DoSuperMethodA(cl, obj, (Msg)msg);
286 IPTR IconListview__MUIM_Show(struct IClass *cl, Object *obj, struct MUIP_Show *msg)
288 struct IconListview_DATA *data = INST_DATA(cl, obj);
289 LONG top,left,width,height;
291 get(data->iconlist, MUIA_IconList_Left, &left);
292 get(data->iconlist, MUIA_IconList_Top, &top);
293 get(data->iconlist, MUIA_IconList_Width, &width);
294 get(data->iconlist, MUIA_IconList_Height, &height);
296 SetAttrs(
297 data->horiz,
298 MUIA_Prop_First, left,
299 MUIA_Prop_Entries, width,
300 MUIA_Prop_Visible, _mwidth(data->iconlist),
301 TAG_DONE
304 SetAttrs(
305 data->vert,
306 MUIA_Prop_First, top,
307 MUIA_Prop_Entries, height,
308 MUIA_Prop_Visible, _mheight(data->iconlist),
309 TAG_DONE
312 return DoSuperMethodA(cl,obj,(Msg)msg);
315 #if ZUNE_BUILTIN_ICONLISTVIEW
316 BOOPSI_DISPATCHER(IPTR,IconListview_Dispatcher, cl, obj, msg)
318 switch (msg->MethodID)
320 case OM_NEW:
321 return IconListview__OM_NEW(cl, obj, (struct opSet *) msg);
322 case OM_DISPOSE:
323 return IconListview__OM_DISPOSE(cl, obj, msg);
324 case MUIM_Show:
325 return IconListview__MUIM_Show(cl, obj, (struct MUIP_Show*)msg);
326 case OM_SET:
327 return IconListview__OM_SET(cl, obj, (struct opSet *) msg);
329 return DoSuperMethodA(cl, obj, msg);
331 BOOPSI_DISPATCHER_END
333 const struct __MUIBuiltinClass _MUI_IconListview_desc =
335 MUIC_IconListview,
336 MUIC_Group,
337 sizeof(struct IconListview_DATA),
338 (void*)IconListview_Dispatcher
340 #endif /* ZUNE_BUILTIN_ICONLISTVIEW */