~ubuntu-branches/ubuntu/quantal/glom/quantal

« back to all changes in this revision

Viewing changes to glom/utility_widgets/egg/util/egg-macros.h

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2009-01-11 17:12:01 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090111171201-0ov9zh1fxfueshxc
Tags: 1.8.5-0ubuntu1
* New upstream release (LP: #256701), fixes LP bugs: 
  + Clear the text in property dialogs for text items (LP: #309147)
  + Don't crash when showing and then hiding the grid (LP: #303453)
  + Temporarily remember the sort order so it is the same when navigating 
    away and back (LP: #303422)
  + Use the list's sort order for the top-level records in the report 
    (LP: #303425)
  + Users/Groups: Disable drag-and-drop for the treeview, because it is
    useless and confusing (LP: #299573)
  + Import: Sort the fields list alphabetically (LP: #306593)
  + delete primary key make unusuable the database (LP: #299549)
  + Spanish translate incomplete (LP: #299556)
  + import date format error (LP: #299591)
  + can't delete data from table list view (LP: #299853)
  + Field definition: default value not saved (LP: #299896)
  + reports crashing (LP: #300054)
  + Year error with date fields (LP: #300057)
  + list view: 2 records added instead of 1 (LP: #300819)
* debian/control: Refreshed dependencies for libglom-dev.
* debian/control: Updated build-deps to match configure checks. goocavnasmm
  build-dep bumped to version without .la files.
* debian/rules: Don't delete the directory containing the templates.
* debian/control, debian/rules, debian/glom-doc.*: Split out
  arch-independent manual and examples into separate package glom-doc, which
  is now recommended by glom (glom will still work if they're not available)
* debian/copyright: Rewritten to new machine-readable format. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Useful macros.
 
3
 *
 
4
 * Author:
 
5
 *   Darin Adler <darin@bentspoon.com>
 
6
 *
 
7
 * Copyright 2001 Ben Tea Spoons, Inc.
 
8
 */
 
9
#ifndef _EGG_MACROS_H_
 
10
#define _EGG_MACROS_H_
 
11
 
 
12
#include <glib/gmacros.h>
 
13
 
 
14
G_BEGIN_DECLS
 
15
 
 
16
/* Macros for defining classes.  Ideas taken from Nautilus and GOB. */
 
17
 
 
18
/* Define the boilerplate type stuff to reduce typos and code size.  Defines
 
19
 * the get_type method and the parent_class static variable. */
 
20
 
 
21
#define EGG_BOILERPLATE(type, type_as_function, corba_type,             \
 
22
                           parent_type, parent_type_macro,              \
 
23
                           register_type_macro)                         \
 
24
static void type_as_function ## _class_init    (type ## Class *klass);  \
 
25
static void type_as_function ## _instance_init (type          *object); \
 
26
static parent_type ## Class *parent_class = NULL;                       \
 
27
static void                                                             \
 
28
type_as_function ## _class_init_trampoline (gpointer klass,             \
 
29
                                            gpointer data)              \
 
30
{                                                                       \
 
31
        parent_class = (parent_type ## Class *)g_type_class_ref (       \
 
32
                parent_type_macro);                                     \
 
33
        type_as_function ## _class_init ((type ## Class *)klass);       \
 
34
}                                                                       \
 
35
GType                                                                   \
 
36
type_as_function ## _get_type (void)                                    \
 
37
{                                                                       \
 
38
        static GType object_type = 0;                                   \
 
39
        if (object_type == 0) {                                         \
 
40
                static const GTypeInfo object_info = {                  \
 
41
                    sizeof (type ## Class),                             \
 
42
                    NULL,               /* base_init */                 \
 
43
                    NULL,               /* base_finalize */             \
 
44
                    type_as_function ## _class_init_trampoline,         \
 
45
                    NULL,               /* class_finalize */            \
 
46
                    NULL,               /* class_data */                \
 
47
                    sizeof (type),                                      \
 
48
                    0,                  /* n_preallocs */               \
 
49
                    (GInstanceInitFunc) type_as_function ## _instance_init \
 
50
                };                                                      \
 
51
                object_type = register_type_macro                       \
 
52
                        (type, type_as_function, corba_type,            \
 
53
                         parent_type, parent_type_macro);               \
 
54
        }                                                               \
 
55
        return object_type;                                             \
 
56
}
 
57
 
 
58
/* Just call the parent handler.  This assumes that there is a variable
 
59
 * named parent_class that points to the (duh!) parent class.  Note that
 
60
 * this macro is not to be used with things that return something, use
 
61
 * the _WITH_DEFAULT version for that */
 
62
#define EGG_CALL_PARENT(parent_class_cast, name, args)          \
 
63
        ((parent_class_cast(parent_class)->name != NULL) ?              \
 
64
         parent_class_cast(parent_class)->name args : (void)0)
 
65
 
 
66
/* Same as above, but in case there is no implementation, it evaluates
 
67
 * to def_return */
 
68
#define EGG_CALL_PARENT_WITH_DEFAULT(parent_class_cast,         \
 
69
                                        name, args, def_return)         \
 
70
        ((parent_class_cast(parent_class)->name != NULL) ?              \
 
71
         parent_class_cast(parent_class)->name args : def_return)
 
72
 
 
73
/* Call a virtual method */
 
74
#define EGG_CALL_VIRTUAL(object, get_class_cast, method, args) \
 
75
    (get_class_cast (object)->method ? (* get_class_cast (object)->method) args : (void)0)
 
76
 
 
77
/* Call a virtual method with default */
 
78
#define EGG_CALL_VIRTUAL_WITH_DEFAULT(object, get_class_cast, method, args, default) \
 
79
    (get_class_cast (object)->method ? (* get_class_cast (object)->method) args : default)
 
80
 
 
81
#define EGG_CLASS_BOILERPLATE(type, type_as_function,           \
 
82
                                 parent_type, parent_type_macro)        \
 
83
        EGG_BOILERPLATE(type, type_as_function, type,           \
 
84
                           parent_type, parent_type_macro,              \
 
85
                           EGG_REGISTER_TYPE)
 
86
 
 
87
#define EGG_REGISTER_TYPE(type, type_as_function, corba_type,           \
 
88
                            parent_type, parent_type_macro)             \
 
89
        g_type_register_static (parent_type_macro, #type, &object_info, 0)
 
90
 
 
91
 
 
92
#define EGG_DEFINE_BOXED_TYPE(TN, t_n) \
 
93
EGG_DEFINE_BOXED_TYPE_WITH_CODE(TN, t_n, {});
 
94
 
 
95
#define EGG_DEFINE_BOXED_TYPE_WITH_CODE(TN, t_n, _C_) \
 
96
\
 
97
static gpointer t_n##_copy (gpointer boxed); \
 
98
static void t_n##_free (gpointer boxed); \
 
99
\
 
100
EGG_DEFINE_BOXED_TYPE_EXTENDED(TN, t_n, t_n##_copy, t_n##_free, _C_);
 
101
 
 
102
#define EGG_DEFINE_BOXED_TYPE_EXTENDED(TN, t_n, b_c, b_f, _C_) \
 
103
\
 
104
_EGG_DEFINE_BOXED_TYPE_EXTENDED_BEGIN(TN, t_n, b_c, b_f) {_C_;} \
 
105
_EGG_DEFINE_BOXED_TYPE_EXTENDED_END()
 
106
 
 
107
#define _EGG_DEFINE_BOXED_TYPE_EXTENDED_BEGIN(TypeName, type_name, boxed_copy, boxed_free) \
 
108
\
 
109
GType \
 
110
type_name##_get_type (void) \
 
111
{ \
 
112
  static volatile gsize g_define_type_id__volatile = 0; \
 
113
  if (g_once_init_enter (&g_define_type_id__volatile)) \
 
114
    { \
 
115
      GType g_define_type_id = \
 
116
        g_boxed_type_register_static (g_intern_static_string (#TypeName), \
 
117
                                      boxed_copy, boxed_free); \
 
118
      { /* custom code follows */
 
119
#define _EGG_DEFINE_BOXED_TYPE_EXTENDED_END() \
 
120
        /* following custom code */ \
 
121
      } \
 
122
      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
 
123
    } \
 
124
  return g_define_type_id__volatile; \
 
125
} /* closes type_name##_get_type() */
 
126
 
 
127
#define EGG_DEFINE_QUARK(QN, q_n) \
 
128
\
 
129
GQuark \
 
130
q_n##_quark (void) \
 
131
{ \
 
132
  static volatile gsize g_define_quark__volatile = 0; \
 
133
  if (g_once_init_enter (&g_define_quark__volatile)) \
 
134
    { \
 
135
      GQuark g_define_quark = g_quark_from_string (#QN); \
 
136
      g_once_init_leave (&g_define_quark__volatile, g_define_quark); \
 
137
    } \
 
138
  return g_define_quark__volatile; \
 
139
}
 
140
 
 
141
#define EGG_IS_POSITIVE_RESPONSE(response_id) \
 
142
  ((response_id) == GTK_RESPONSE_ACCEPT || \
 
143
   (response_id) == GTK_RESPONSE_OK     || \
 
144
   (response_id) == GTK_RESPONSE_YES    || \
 
145
   (response_id) == GTK_RESPONSE_APPLY)
 
146
 
 
147
#define EGG_IS_NEGATIVE_RESPONSE(response_id) \
 
148
  ((response_id) == GTK_RESPONSE_REJECT || \
 
149
   (response_id) == GTK_RESPONSE_CANCEL || \
 
150
   (response_id) == GTK_RESPONSE_NO)
 
151
 
 
152
G_END_DECLS
 
153
 
 
154
#endif /* _EGG_MACROS_H_ */