Disabled, because it makes the nightly builds fail quite often and it's already
[AROS-Contrib.git] / mui / gtk-mui / classes / table.c
blob9884572995669cb98c7dac685296a853844b649a
1 /*****************************************************************************
2 *
3 * mui-gtk - a wrapper library to wrap GTK+ calls to MUI
5 * Copyright (C) 2005 Oliver Brunner
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Contact information:
23 * Oliver Brunner
25 * E-Mail: mui-gtk "at" oliver-brunner.de
27 * $Id$
29 *****************************************************************************/
31 /* table class
33 ** emulates table widget in gtk
35 ** supports:
37 ** gtk_table_attach() (no options, no padding)
38 ** gtk_table_attach_defaults()
39 ** gtk_table_set_row_spacings()
40 ** gtk_table_set_col_spacings()
41 ** gtk_table_get_default_col_spacing()
42 ** gtk_table_get_default_row_spacing()
44 ** todo:
46 ** gtk_table_set_homogeneous()
47 ** gtk_table_get_col_spacing()
48 ** gtk_table_get_row_spacing()
50 ** in short, cells are homogenous
54 #include <clib/alib_protos.h>
55 #include <proto/utility.h>
56 #include <exec/types.h>
57 #include <mui.h>
59 #include "classes.h"
60 #include "gtk_globals.h"
61 #include "gtk.h"
62 #include "debug.h"
64 /*********************************************************************/
66 struct Data
68 struct Hook LayoutHook;
69 struct MinList ChildList;
71 ULONG columns, rows, vertspacing, horizspacing;
72 LONG defwidth, defheight;
75 struct TableNode
77 struct MinNode node;
78 GtkWidget *widget;
79 UWORD left, right, top, bottom;
82 static VOID mSet(struct Data *data, APTR obj, struct opSet *msg, ULONG is_new);
84 #ifndef __AROS__
85 HOOKPROTO(LayoutHook, ULONG, APTR obj, struct MUI_LayoutMsg *lm)
87 #else
88 AROS_UFH3(static ULONG, LayoutHook, AROS_UFHA(struct Hook *, hook, a0), AROS_UFHA(APTR, obj, a2), AROS_UFHA(struct MUI_LayoutMsg *, lm, a1))
89 #endif
90 switch (lm->lm_Type)
92 case MUILM_MINMAX:
94 struct Data *data = hook->h_Data;
95 struct TableNode *node;
96 ULONG mincw, minch, defcw, defch, maxcw, maxch;
98 mincw = 0;
99 minch = 0;
100 defcw = data->horizspacing;
101 defch = data->vertspacing;
102 maxcw = 0;
103 maxch = 0;
105 ForeachNode(&data->ChildList, node)
107 ULONG w, h, cols, rows;
109 w = _minwidth(node->widget->MuiObject);
110 h = _minheight(node->widget->MuiObject);
112 cols = node->right - node->left;
113 rows = node->bottom - node->top;
115 if (cols)
117 ULONG s = w / cols;
119 if (s > mincw)
121 mincw = s + (s % cols ? 1 : 0);
125 if (rows)
127 ULONG s = h / rows;
129 if (s > minch)
131 minch = s + (s % rows ? 1 : 0);
135 // calculate default cell width/height
137 w = _defwidth(node->widget->MuiObject);
138 h = _defheight(node->widget->MuiObject);
140 if (cols)
142 ULONG s = w / cols;
144 if (s > defcw)
146 defcw = s + (s % cols ? 1 : 0);
150 if (rows)
152 ULONG s = h / rows;
154 if (s > defch)
156 defch = s + (s % rows ? 1 : 0);
160 // calculate max cell width/height
162 w = _maxwidth(node->widget->MuiObject);
163 h = _maxheight(node->widget->MuiObject);
165 if (cols)
167 ULONG s = w / cols;
169 if (s > maxcw)
171 maxcw = s + (s % cols ? 1 : 0);
175 if (rows)
177 ULONG s = h / rows;
179 if (s > maxch)
181 maxch = s + (s % rows ? 1 : 0);
186 lm->lm_MinMax.MinWidth = mincw * data->columns;
187 lm->lm_MinMax.MinHeight = minch * data->rows;
188 lm->lm_MinMax.DefWidth = defcw * data->columns;
189 lm->lm_MinMax.DefHeight = defch * data->rows;
190 lm->lm_MinMax.MaxWidth = maxcw * data->columns;
191 lm->lm_MinMax.MaxHeight = maxch * data->rows;
193 return 0;
195 case MUILM_LAYOUT:
197 struct Data *data = hook->h_Data;
199 if (data->columns && data->rows)
201 struct TableNode *node;
202 ULONG cw, ch;
204 cw = lm->lm_Layout.Width / data->columns;
205 ch = lm->lm_Layout.Height / data->rows; /* +1 ? */
207 ForeachNode(&data->ChildList, node)
209 if (!MUI_Layout(node->widget->MuiObject,
210 node->left * cw,
211 node->top * ch ,
212 (node->right - node->left) * cw,
213 (node->bottom - node->top ) * ch,
216 return FALSE;
221 return TRUE;
224 return MUILM_UNKNOWN;
227 static ULONG mNew(struct IClass *cl, APTR obj, Msg msg)
229 obj = (APTR)DoSuperMethodA(cl, obj, msg);
231 if (obj)
233 GETDATA;
235 SETUPHOOK(&data->LayoutHook, LayoutHook, data);
236 //afxgroup - Is this a typo? (&data->ChildList)
237 MGTK_NEWLIST(data->ChildList);
239 data->vertspacing = 0;
240 data->horizspacing = 0;
241 data->defwidth = -1;
242 data->defheight = -1;
244 set(obj, MUIA_Group_LayoutHook, &data->LayoutHook);
245 mSet(data, obj, (APTR)msg, TRUE);
248 return (ULONG)obj;
251 static ULONG mGet(struct Data *data, APTR obj, struct opGet *msg, struct IClass *cl)
253 ULONG rc;
255 switch (msg->opg_AttrID)
257 case MA_Table_VertSpacing : rc = data->vertspacing; break;
258 case MA_Table_HorizSpacing: rc = data->horizspacing; break;
260 default: return DoSuperMethodA(cl, obj, (Msg)msg);
263 *msg->opg_Storage = rc;
264 return TRUE;
267 static VOID mSet(struct Data *data, APTR obj, struct opSet *msg, ULONG is_new)
269 struct TagItem *tstate, *tag;
270 ULONG relayout = 0;
272 tstate = msg->ops_AttrList;
274 while ((tag = NextTagItem(&tstate)))
276 switch (tag->ti_Tag)
278 case MA_Table_Columns:
279 data->columns = tag->ti_Data;
280 break;
282 case MA_Table_Rows:
283 data->rows = tag->ti_Data;
284 break;
286 case MA_Table_VertSpacing:
287 if (data->vertspacing != tag->ti_Data)
289 data->vertspacing = tag->ti_Data;
290 relayout = 1;
292 break;
294 case MA_Table_HorizSpacing:
295 if (data->horizspacing != tag->ti_Data)
297 data->horizspacing = tag->ti_Data;
298 relayout = 1;
300 break;
302 case MA_DefWidth:
303 if (data->defwidth != tag->ti_Data)
305 data->defwidth = tag->ti_Data;
306 relayout = 1;
308 break;
310 case MA_DefHeight:
311 if (data->defheight != tag->ti_Data)
313 data->defheight = tag->ti_Data;
314 relayout = 1;
316 break;
320 if (relayout)
322 DoMethod(obj, MUIM_Group_InitChange);
323 DoMethod(obj, MUIM_Group_ExitChange);
327 static VOID mRemMember(struct Data *data, struct opMember *msg)
329 struct TableNode *node;
331 ForeachNode(&data->ChildList, node)
333 if (node->widget->MuiObject == msg->opam_Object)
335 REMOVE(node);
336 mgtk_freemem(node, sizeof(*node));
337 return;
342 static ULONG mAttach(struct Data *data, APTR obj, struct MUIP_Table_Attach *msg) {
343 struct TableNode *node;
344 //afxgroup - msg redeclared as different kind of symbol
346 DebOut("mAttach(..)\n");
348 DebOut("msg=%lx\n",msg);
350 node = mgtk_allocmem(sizeof(*node), MEMF_ANY);
352 if (node)
354 ADDTAIL(&data->ChildList, node);
356 node->widget = msg->widget;
357 node->left = msg->left;
358 node->right = msg->right;
359 node->top = msg->top;
360 node->bottom = msg->bottom;
362 DebOut(" msg->widget: %lx\n",msg->widget);
363 DebOut(" msg->widget->MuiObject: %lx\n",msg->widget->MuiObject);
364 DebOut(" obj: %lx\n",obj);
365 DoMethod(obj, MUIM_Group_InitChange);
366 DoMethod(obj, OM_ADDMEMBER, msg->widget->MuiObject);
367 DoMethod(obj, MUIM_Group_ExitChange);
370 return 0;
373 BEGINMTABLE
374 GETDATA;
376 switch (msg->MethodID)
378 case OM_NEW : return mNew (cl, obj, msg);
379 case OM_SET : mSet (data, obj, (APTR)msg, FALSE); break;
380 case OM_GET : return mGet (data, obj, (APTR)msg, cl);
381 case OM_REMMEMBER : mRemMember (data, (APTR)msg); break;
382 case MM_Table_Attach: return mAttach (data, obj, (APTR)msg);
385 ENDMTABLE
387 int mgtk_create_table_class(void)
389 CL_Table = MUI_CreateCustomClass(NULL, MUIC_Group, NULL, sizeof(struct Data), (APTR)&mDispatcher);
390 return CL_Table ? 1 : 0;
393 void mgtk_delete_table_class(void)
395 if (CL_Table)
397 MUI_DeleteCustomClass(CL_Table);