summaryrefslogtreecommitdiff
path: root/gtk/gtkbuilderprivate.h
blob: 913fa263a92e10d7d0a68e19da3d316cf05c8d25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* gtkbuilderprivate.h
 * Copyright (C) 2006-2007 Async Open Source,
 *                         Johan Dahlin <jdahlin@async.com.br>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __GTK_BUILDER_PRIVATE_H__
#define __GTK_BUILDER_PRIVATE_H__

#include "gtkbuilder.h"
#include "gtkbuildable.h"
#include "gtkexpression.h"

enum {
  TAG_PROPERTY,
  TAG_BINDING,
  TAG_BINDING_EXPRESSION,
  TAG_REQUIRES,
  TAG_OBJECT,
  TAG_CHILD,
  TAG_SIGNAL,
  TAG_INTERFACE,
  TAG_TEMPLATE,
  TAG_EXPRESSION,
};

typedef struct {
  guint tag_type;
} CommonInfo;

typedef struct {
  guint tag_type;
  GType type;
  GObjectClass *oclass;
  char *id;
  char *constructor;

  GPtrArray *properties;
  GPtrArray *signals;
  GSList *bindings;

  GObject *object;
  CommonInfo *parent;
  gboolean applied_properties;
} ObjectInfo;

typedef struct {
  guint tag_type;
  GSList *packing_properties;
  GObject *object;
  CommonInfo *parent;
  char *type;
  char *internal_child;
  gboolean added;
} ChildInfo;

typedef struct {
  guint tag_type;
  GParamSpec *pspec;
  gpointer value;
  GString *text;
  gboolean translatable:1;
  gboolean bound:1;
  char *context;
  int line;
  int col;
} PropertyInfo;

typedef struct _ExpressionInfo ExpressionInfo;
struct _ExpressionInfo {
  guint tag_type;
  enum {
    EXPRESSION_EXPRESSION,
    EXPRESSION_CONSTANT,
    EXPRESSION_CLOSURE,
    EXPRESSION_PROPERTY
  } expression_type;
  union {
    GtkExpression *expression;
    struct {
      GType type;
      GString *text;
    } constant;
    struct {
      GType type;
      char *function_name;
      char *object_name;
      gboolean swapped;
      GSList *params;
    } closure;
    struct {
      GType this_type;
      char *property_name;
      ExpressionInfo *expression;
    } property;
  };
};

typedef struct {
  guint tag_type;
  char *object_name;
  guint  id;
  GQuark detail;
  char *handler;
  GConnectFlags flags;
  char *connect_object_name;
} SignalInfo;

typedef struct
{
  guint tag_type;
  GObject *target;
  GParamSpec *target_pspec;
  char *source;
  char *source_property;
  GBindingFlags flags;
  int line;
  int col;
} BindingInfo;

typedef struct
{
  guint tag_type;
  GObject *target;
  GParamSpec *target_pspec;
  char *object_name;
  ExpressionInfo *expr;
  int line;
  int col;
} BindingExpressionInfo;

typedef struct {
  guint    tag_type;
  char    *library;
  int      major;
  int      minor;
} RequiresInfo;

struct _GtkBuildableParseContext {
  const GMarkupParser *internal_callbacks;
  GMarkupParseContext *ctx;

  const GtkBuildableParser *parser;
  gpointer user_data;

  GPtrArray *tag_stack;

  GArray *subparser_stack;
  gpointer held_user_data;
  gboolean awaiting_pop;
};

typedef struct {
  GtkBuildableParser *parser;
  char *tagname;
  const char *start;
  gpointer data;
  GObject *object;
  GObject *child;
} SubParser;

typedef struct {
  const char *last_element;
  GtkBuilder *builder;
  char *domain;
  GPtrArray *stack;
  SubParser *subparser;
  GtkBuildableParseContext ctx;
  const char *filename;
  GPtrArray *finalizers;
  GSList *custom_finalizers;

  const char **requested_objects; /* NULL if all the objects are requested */
  gboolean inside_requested_object;
  int requested_object_level;
  int cur_object_level;

  int object_counter;

  GHashTable *object_ids;
} ParserData;

/* Things only GtkBuilder should use */
GBytes * _gtk_buildable_parser_precompile (const char               *text,
                                           gssize                    text_len,
                                           GError                  **error);
gboolean _gtk_buildable_parser_is_precompiled (const char           *data,
                                               gssize                data_len);
gboolean _gtk_buildable_parser_replay_precompiled (GtkBuildableParseContext *context,
                                                   const char           *data,
                                                   gssize                data_len,
                                                   GError              **error);
void _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
                                       const char *filename,
                                       const char *buffer,
                                       gssize length,
                                       const char **requested_objs,
                                       GError **error);
GObject * _gtk_builder_construct (GtkBuilder *builder,
                                  ObjectInfo *info,
				  GError    **error);
void      _gtk_builder_apply_properties (GtkBuilder *builder,
					 ObjectInfo *info,
					 GError **error);
void      _gtk_builder_add_object (GtkBuilder  *builder,
                                   const char *id,
                                   GObject     *object);
void      _gtk_builder_add (GtkBuilder *builder,
                            ChildInfo *child_info);
void      _gtk_builder_add_signals (GtkBuilder *builder,
                                    GPtrArray  *signals);
gboolean  _gtk_builder_finish (GtkBuilder  *builder,
                               GError     **error);
void _free_signal_info (SignalInfo *info,
                        gpointer user_data);
void _free_binding_info (BindingInfo *info,
                         gpointer user_data);
void free_binding_expression_info (BindingExpressionInfo *info);
GtkExpression * expression_info_construct (GtkBuilder      *builder,
                                           ExpressionInfo  *info,
                                           GError         **error);

/* Internal API which might be made public at some point */
gboolean _gtk_builder_enum_from_string (GType         type,
                                        const char   *string,
                                        int          *enum_value,
                                        GError      **error);
gboolean  _gtk_builder_flags_from_string (GType         type,
                                          const char   *string,
                                          guint        *value,
                                          GError      **error);
gboolean _gtk_builder_boolean_from_string (const char   *string,
                                           gboolean     *value,
                                           GError      **error);

const char * _gtk_builder_parser_translate (const char *domain,
                                             const char *context,
                                             const char *text);
char *   _gtk_builder_get_resource_path (GtkBuilder *builder,
					  const char *string) G_GNUC_MALLOC;
char *   _gtk_builder_get_absolute_filename (GtkBuilder *builder,
					      const char *string) G_GNUC_MALLOC;

void      _gtk_builder_menu_start (ParserData   *parser_data,
                                   const char   *element_name,
                                   const char **attribute_names,
                                   const char **attribute_values,
                                   GError      **error);
void      _gtk_builder_menu_end   (ParserData  *parser_data);

GType     _gtk_builder_get_template_type (GtkBuilder *builder);

void     _gtk_builder_prefix_error        (GtkBuilder                *builder,
                                           GtkBuildableParseContext  *context,
                                           GError                   **error);
void     _gtk_builder_error_unhandled_tag (GtkBuilder                *builder,
                                           GtkBuildableParseContext  *context,
                                           const char                *object,
                                           const char                *element_name,
                                           GError                   **error);
gboolean _gtk_builder_check_parent        (GtkBuilder                *builder,
                                           GtkBuildableParseContext  *context,
                                           const char                *parent_name,
                                           GError                   **error);
GObject *gtk_builder_lookup_object        (GtkBuilder                *builder,
                                           const char                *name,
                                           int                        line,
                                           int                        col,
                                           GError                   **error);
GObject *_gtk_builder_lookup_object       (GtkBuilder                *builder,
                                           const char                *name,
                                           int                        line,
                                           int                        col);
gboolean _gtk_builder_lookup_failed       (GtkBuilder                *builder,
                                           GError                   **error);

#endif /* __GTK_BUILDER_PRIVATE_H__ */