1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * gdl-dock-object.h - Abstract base class for all dock related objects
4 *
5 * This file is part of the GNOME Devtools Libraries.
6 *
7 * Copyright (C) 2002 Gustavo Giráldez <gustavo.giraldez@gmx.net>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
24 #ifndef __GDL_DOCK_OBJECT_H__
25 #define __GDL_DOCK_OBJECT_H__
27 #include <gtk/gtkcontainer.h>
29 G_BEGIN_DECLS
31 /* standard macros */
32 #define GDL_TYPE_DOCK_OBJECT (gdl_dock_object_get_type ())
33 #define GDL_DOCK_OBJECT(obj) (GTK_CHECK_CAST ((obj), GDL_TYPE_DOCK_OBJECT, GdlDockObject))
34 #define GDL_DOCK_OBJECT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GDL_TYPE_DOCK_OBJECT, GdlDockObjectClass))
35 #define GDL_IS_DOCK_OBJECT(obj) (GTK_CHECK_TYPE ((obj), GDL_TYPE_DOCK_OBJECT))
36 #define GDL_IS_DOCK_OBJECT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDL_TYPE_DOCK_OBJECT))
37 #define GDL_DOCK_OBJECT_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_DOCK_OBJECT, GdlDockObjectClass))
39 /* data types & structures */
40 typedef enum {
41 /* the parameter is to be exported for later layout rebuilding */
42 GDL_DOCK_PARAM_EXPORT = 1 << G_PARAM_USER_SHIFT,
43 /* the parameter must be set after adding the children objects */
44 GDL_DOCK_PARAM_AFTER = 1 << (G_PARAM_USER_SHIFT + 1)
45 } GdlDockParamFlags;
47 #define GDL_DOCK_NAME_PROPERTY "name"
48 #define GDL_DOCK_MASTER_PROPERTY "master"
50 typedef enum {
51 GDL_DOCK_AUTOMATIC = 1 << 0,
52 GDL_DOCK_ATTACHED = 1 << 1,
53 GDL_DOCK_IN_REFLOW = 1 << 2,
54 GDL_DOCK_IN_DETACH = 1 << 3
55 } GdlDockObjectFlags;
57 #define GDL_DOCK_OBJECT_FLAGS_SHIFT 8
59 typedef enum {
60 GDL_DOCK_NONE = 0,
61 GDL_DOCK_TOP,
62 GDL_DOCK_BOTTOM,
63 GDL_DOCK_RIGHT,
64 GDL_DOCK_LEFT,
65 GDL_DOCK_CENTER,
66 GDL_DOCK_FLOATING
67 } GdlDockPlacement;
69 typedef enum {
70 GDL_DOCK_EXPANSION_DIRECTION_NONE = 0,
71 GDL_DOCK_EXPANSION_DIRECTION_UP,
72 GDL_DOCK_EXPANSION_DIRECTION_DOWN,
73 GDL_DOCK_EXPANSION_DIRECTION_LEFT,
74 GDL_DOCK_EXPANSION_DIRECTION_RIGHT
75 } GdlDockExpansionDirection;
77 typedef struct _GdlDockObject GdlDockObject;
78 typedef struct _GdlDockObjectClass GdlDockObjectClass;
79 typedef struct _GdlDockRequest GdlDockRequest;
81 struct _GdlDockRequest {
82 GdlDockObject *applicant;
83 GdlDockObject *target;
84 GdlDockPlacement position;
85 GdkRectangle rect;
86 GValue extra;
87 };
89 struct _GdlDockObject {
90 GtkContainer container;
92 GdlDockObjectFlags flags;
93 gint freeze_count;
95 GObject *master;
96 gchar *name;
97 gchar *long_name;
98 gchar *stock_id;
99 GdkPixbuf *pixbuf_icon;
101 gboolean reduce_pending;
102 };
104 struct _GdlDockObjectClass {
105 GtkContainerClass parent_class;
107 gboolean is_compound;
109 void (* detach) (GdlDockObject *object,
110 gboolean recursive);
111 void (* reduce) (GdlDockObject *object);
113 gboolean (* dock_request) (GdlDockObject *object,
114 gint x,
115 gint y,
116 GdlDockRequest *request);
118 void (* dock) (GdlDockObject *object,
119 GdlDockObject *requestor,
120 GdlDockPlacement position,
121 GValue *other_data);
123 gboolean (* reorder) (GdlDockObject *object,
124 GdlDockObject *child,
125 GdlDockPlacement new_position,
126 GValue *other_data);
128 void (* present) (GdlDockObject *object,
129 GdlDockObject *child);
131 gboolean (* child_placement) (GdlDockObject *object,
132 GdlDockObject *child,
133 GdlDockPlacement *placement);
134 };
136 /* additional macros */
137 #define GDL_DOCK_OBJECT_FLAGS(obj) (GDL_DOCK_OBJECT (obj)->flags)
138 #define GDL_DOCK_OBJECT_AUTOMATIC(obj) \
139 ((GDL_DOCK_OBJECT_FLAGS (obj) & GDL_DOCK_AUTOMATIC) != 0)
140 #define GDL_DOCK_OBJECT_ATTACHED(obj) \
141 ((GDL_DOCK_OBJECT_FLAGS (obj) & GDL_DOCK_ATTACHED) != 0)
142 #define GDL_DOCK_OBJECT_IN_REFLOW(obj) \
143 ((GDL_DOCK_OBJECT_FLAGS (obj) & GDL_DOCK_IN_REFLOW) != 0)
144 #define GDL_DOCK_OBJECT_IN_DETACH(obj) \
145 ((GDL_DOCK_OBJECT_FLAGS (obj) & GDL_DOCK_IN_DETACH) != 0)
147 #define GDL_DOCK_OBJECT_SET_FLAGS(obj,flag) \
148 G_STMT_START { (GDL_DOCK_OBJECT_FLAGS (obj) |= (flag)); } G_STMT_END
149 #define GDL_DOCK_OBJECT_UNSET_FLAGS(obj,flag) \
150 G_STMT_START { (GDL_DOCK_OBJECT_FLAGS (obj) &= ~(flag)); } G_STMT_END
152 #define GDL_DOCK_OBJECT_FROZEN(obj) (GDL_DOCK_OBJECT (obj)->freeze_count > 0)
155 /* public interface */
157 GType gdl_dock_object_get_type (void);
159 gboolean gdl_dock_object_is_compound (GdlDockObject *object);
161 void gdl_dock_object_detach (GdlDockObject *object,
162 gboolean recursive);
164 GdlDockObject *gdl_dock_object_get_parent_object (GdlDockObject *object);
166 void gdl_dock_object_freeze (GdlDockObject *object);
167 void gdl_dock_object_thaw (GdlDockObject *object);
169 void gdl_dock_object_reduce (GdlDockObject *object);
171 gboolean gdl_dock_object_dock_request (GdlDockObject *object,
172 gint x,
173 gint y,
174 GdlDockRequest *request);
175 void gdl_dock_object_dock (GdlDockObject *object,
176 GdlDockObject *requestor,
177 GdlDockPlacement position,
178 GValue *other_data);
180 void gdl_dock_object_bind (GdlDockObject *object,
181 GObject *master);
182 void gdl_dock_object_unbind (GdlDockObject *object);
183 gboolean gdl_dock_object_is_bound (GdlDockObject *object);
185 gboolean gdl_dock_object_reorder (GdlDockObject *object,
186 GdlDockObject *child,
187 GdlDockPlacement new_position,
188 GValue *other_data);
190 void gdl_dock_object_present (GdlDockObject *object,
191 GdlDockObject *child);
193 gboolean gdl_dock_object_child_placement (GdlDockObject *object,
194 GdlDockObject *child,
195 GdlDockPlacement *placement);
197 /* other types */
199 /* this type derives from G_TYPE_STRING and is meant to be the basic
200 type for serializing object parameters which are exported
201 (i.e. those that are needed for layout rebuilding) */
202 #define GDL_TYPE_DOCK_PARAM (gdl_dock_param_get_type ())
204 GType gdl_dock_param_get_type (void);
206 /* functions for setting/retrieving nick names for serializing GdlDockObject types */
207 G_CONST_RETURN gchar *gdl_dock_object_nick_from_type (GType type);
208 GType gdl_dock_object_type_from_nick (const gchar *nick);
209 GType gdl_dock_object_set_type_for_nick (const gchar *nick,
210 GType type);
213 /* helper macros */
214 #define GDL_TRACE_OBJECT(object, format, args...) \
215 G_STMT_START { \
216 g_log (G_LOG_DOMAIN, \
217 G_LOG_LEVEL_DEBUG, \
218 "%s:%d (%s) %s [%p %d%s:%d]: "format, \
219 __FILE__, \
220 __LINE__, \
221 __PRETTY_FUNCTION__, \
222 G_OBJECT_TYPE_NAME (object), object, \
223 G_OBJECT (object)->ref_count, \
224 (GTK_IS_OBJECT (object) && GTK_OBJECT_FLOATING (object)) ? "(float)" : "", \
225 GDL_IS_DOCK_OBJECT (object) ? GDL_DOCK_OBJECT (object)->freeze_count : -1, \
226 ##args); } G_STMT_END
230 G_END_DECLS
232 #endif /* __GDL_DOCK_OBJECT_H__ */