1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* This file is part of the GNOME Devtool Libraries
5
* Copyright (C) 1999-2000 Dave Camp <dave@helixcode.com>
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
22
/* Miscellaneous GDL tools/macros */
24
#ifndef __GDL_TOOLS_H__
25
#define __GDL_TOOLS_H__
28
#include <gtk/gtkwidget.h>
30
/* FIXME: Toggle this */
40
#define GDL_TRACE() G_STMT_START { \
41
g_log (G_LOG_DOMAIN, \
43
"file %s: line %d (%s)", \
46
__PRETTY_FUNCTION__); } G_STMT_END
48
#define GDL_TRACE_EXTRA(format, args...) G_STMT_START { \
49
g_log (G_LOG_DOMAIN, \
51
"file %s: line %d (%s): "format, \
54
__PRETTY_FUNCTION__, \
59
#define GDL_TRACE() G_STMT_START { \
60
g_log (G_LOG_DOMAIN, \
64
__LINE__); } G_STMT_END
66
#define GDL_TRACE_EXTRA(format, args...) G_STMT_START { \
67
g_log (G_LOG_DOMAIN, \
69
"file %s: line %d: "format, \
75
#else /* DO_GDL_TRACE */
78
#define GDL_TRACE_EXTRA()
80
#endif /* DO_GDL_TRACE */
83
* Class boilerplate and base class call macros copied from
84
* bonobo/bonobo-macros.h. Original copyright follows.
87
* Darin Adler <darin@bentspoon.com>
89
* Copyright 2001 Ben Tea Spoons, Inc.
92
/* Macros for defining classes. Ideas taken from Nautilus and GOB. */
94
/* Define the boilerplate type stuff to reduce typos and code size. Defines
95
* the get_type method and the parent_class static variable. */
97
#define GDL_BOILERPLATE(type, type_as_function, corba_type, \
98
parent_type, parent_type_macro, \
99
register_type_macro) \
100
static void type_as_function ## _class_init (type ## Class *klass); \
101
static void type_as_function ## _instance_init (type *object); \
102
static parent_type ## Class *parent_class = NULL; \
104
type_as_function ## _class_init_trampoline (gpointer klass, \
107
parent_class = (parent_type ## Class *)g_type_class_ref ( \
108
parent_type_macro); \
109
type_as_function ## _class_init ((type ## Class *)klass); \
112
type_as_function ## _get_type (void) \
114
static GType object_type = 0; \
115
if (object_type == 0) { \
116
static const GTypeInfo object_info = { \
117
sizeof (type ## Class), \
118
NULL, /* base_init */ \
119
NULL, /* base_finalize */ \
120
type_as_function ## _class_init_trampoline, \
121
NULL, /* class_finalize */ \
122
NULL, /* class_data */ \
124
0, /* n_preallocs */ \
125
(GInstanceInitFunc) type_as_function ## _instance_init \
127
object_type = register_type_macro \
128
(type, type_as_function, corba_type, \
129
parent_type, parent_type_macro); \
131
return object_type; \
134
/* Just call the parent handler. This assumes that there is a variable
135
* named parent_class that points to the (duh!) parent class. Note that
136
* this macro is not to be used with things that return something, use
137
* the _WITH_DEFAULT version for that */
138
#define GDL_CALL_PARENT(parent_class_cast, name, args) \
139
((parent_class_cast(parent_class)->name != NULL) ? \
140
parent_class_cast(parent_class)->name args : (void)0)
142
#define GDL_CALL_PARENT_GBOOLEAN(parent_class_cast, name, args) \
143
((parent_class_cast(parent_class)->name != NULL) ? \
144
parent_class_cast(parent_class)->name args : (gboolean)0)
147
/* Same as above, but in case there is no implementation, it evaluates
149
#define GDL_CALL_PARENT_WITH_DEFAULT(parent_class_cast, \
150
name, args, def_return) \
151
((parent_class_cast(parent_class)->name != NULL) ? \
152
parent_class_cast(parent_class)->name args : def_return)
154
/* Define the boilerplate type stuff to reduce typos and code size. Defines
155
* the get_type method and the parent_class static variable. */
156
#define GDL_CLASS_BOILERPLATE(type, type_as_function, \
157
parent_type, parent_type_macro) \
158
GDL_BOILERPLATE(type, type_as_function, type, \
159
parent_type, parent_type_macro, \
161
#define GDL_REGISTER_TYPE(type, type_as_function, corba_type, \
162
parent_type, parent_type_macro) \
163
g_type_register_static (parent_type_macro, #type, &object_info, 0)
166
#define GDL_CALL_VIRTUAL(object, get_class_cast, method, args) \
167
(get_class_cast (object)->method ? (* get_class_cast (object)->method) args : (void)0)
168
#define GDL_CALL_VIRTUAL_WITH_DEFAULT(object, get_class_cast, method, args, default) \
169
(get_class_cast (object)->method ? (* get_class_cast (object)->method) args : default)
171
/* GdlPixmap structure and method have been copied from Evolution. */
172
typedef struct _GdlPixmap {
178
#define GDL_PIXMAP(path,fname) { (path), (fname), NULL }
179
#define GDL_PIXMAP_END { NULL, NULL, NULL }