1 /*****************************************************************************
3 * mui-gtk - a wrapper library to wrap GTK+ calls to MUI
5 * Copyright (C) 2005 Oliver Brunner
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:
25 * E-Mail: mui-gtk "at" oliver-brunner.de
29 *****************************************************************************/
33 ** emulates table widget in gtk
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()
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>
60 #include "gtk_globals.h"
64 /*********************************************************************/
68 struct Hook LayoutHook
;
69 struct MinList ChildList
;
71 ULONG columns
, rows
, vertspacing
, horizspacing
;
72 LONG defwidth
, defheight
;
79 UWORD left
, right
, top
, bottom
;
82 static VOID
mSet(struct Data
*data
, APTR obj
, struct opSet
*msg
, ULONG is_new
);
85 HOOKPROTO(LayoutHook
, ULONG
, APTR obj
, struct MUI_LayoutMsg
*lm
)
88 AROS_UFH3(static ULONG
, LayoutHook
, AROS_UFHA(struct Hook
*, hook
, a0
), AROS_UFHA(APTR
, obj
, a2
), AROS_UFHA(struct MUI_LayoutMsg
*, lm
, a1
))
94 struct Data
*data
= hook
->h_Data
;
95 struct TableNode
*node
;
96 ULONG mincw
, minch
, defcw
, defch
, maxcw
, maxch
;
100 defcw
= data
->horizspacing
;
101 defch
= data
->vertspacing
;
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
;
121 mincw
= s
+ (s
% cols
? 1 : 0);
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
);
146 defcw
= s
+ (s
% cols
? 1 : 0);
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
);
171 maxcw
= s
+ (s
% cols
? 1 : 0);
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
;
197 struct Data
*data
= hook
->h_Data
;
199 if (data
->columns
&& data
->rows
)
201 struct TableNode
*node
;
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
,
212 (node
->right
- node
->left
) * cw
,
213 (node
->bottom
- node
->top
) * ch
,
224 return MUILM_UNKNOWN
;
227 static ULONG
mNew(struct IClass
*cl
, APTR obj
, Msg msg
)
229 obj
= (APTR
)DoSuperMethodA(cl
, obj
, msg
);
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;
242 data
->defheight
= -1;
244 set(obj
, MUIA_Group_LayoutHook
, &data
->LayoutHook
);
245 mSet(data
, obj
, (APTR
)msg
, TRUE
);
251 static ULONG
mGet(struct Data
*data
, APTR obj
, struct opGet
*msg
, struct IClass
*cl
)
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
;
267 static VOID
mSet(struct Data
*data
, APTR obj
, struct opSet
*msg
, ULONG is_new
)
269 struct TagItem
*tstate
, *tag
;
272 tstate
= msg
->ops_AttrList
;
274 while ((tag
= NextTagItem(&tstate
)))
278 case MA_Table_Columns
:
279 data
->columns
= tag
->ti_Data
;
283 data
->rows
= tag
->ti_Data
;
286 case MA_Table_VertSpacing
:
287 if (data
->vertspacing
!= tag
->ti_Data
)
289 data
->vertspacing
= tag
->ti_Data
;
294 case MA_Table_HorizSpacing
:
295 if (data
->horizspacing
!= tag
->ti_Data
)
297 data
->horizspacing
= tag
->ti_Data
;
303 if (data
->defwidth
!= tag
->ti_Data
)
305 data
->defwidth
= tag
->ti_Data
;
311 if (data
->defheight
!= tag
->ti_Data
)
313 data
->defheight
= tag
->ti_Data
;
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
)
336 mgtk_freemem(node
, sizeof(*node
));
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
);
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
);
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
);
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)
397 MUI_DeleteCustomClass(CL_Table
);