1 | /* |
2 | * Copyright © 2019 Benjamin Otte |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * Authors: Benjamin Otte <otte@gnome.org> |
18 | */ |
19 | |
20 | #ifndef __GTK_BUILDER_SCOPE_H__ |
21 | #define __GTK_BUILDER_SCOPE_H__ |
22 | |
23 | #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) |
24 | #error "Only <gtk/gtk.h> can be included directly." |
25 | #endif |
26 | |
27 | #include <gtk/gtktypes.h> |
28 | |
29 | G_BEGIN_DECLS |
30 | |
31 | #define GTK_TYPE_BUILDER_SCOPE (gtk_builder_scope_get_type ()) |
32 | |
33 | GDK_AVAILABLE_IN_ALL |
34 | G_DECLARE_INTERFACE (GtkBuilderScope, gtk_builder_scope, GTK, BUILDER_SCOPE, GObject) |
35 | |
36 | /** |
37 | * GtkBuilderClosureFlags: |
38 | * @GTK_BUILDER_CLOSURE_SWAPPED: The closure should be created swapped. See |
39 | * g_cclosure_new_swap() for details. |
40 | * |
41 | * The list of flags that can be passed to gtk_builder_create_closure(). |
42 | * |
43 | * New values may be added in the future for new features, so external |
44 | * implementations of [iface@Gtk.BuilderScope] should test the flags |
45 | * for unknown values and raise a %GTK_BUILDER_ERROR_INVALID_ATTRIBUTE error |
46 | * when they encounter one. |
47 | */ |
48 | typedef enum { /*< prefix=GTK_BUILDER_CLOSURE >*/ |
49 | GTK_BUILDER_CLOSURE_SWAPPED = (1 << 0) |
50 | } GtkBuilderClosureFlags; |
51 | |
52 | /** |
53 | * GtkBuilderScopeInterface: |
54 | * @get_type_from_name: Try to lookup a `GType` via the its name. See |
55 | * gtk_builder_get_type_from_name() for more details. |
56 | * The C implementation will use g_type_from_name() and if that fails try to guess the |
57 | * correct function name for registering the type and then use dlsym() to load it. |
58 | * The default implementation just tries g_type_from_name() and otherwise fails. |
59 | * @get_type_from_function: Try to lookup a `GType` via the given function name, specified |
60 | * explicitly in a GtkBuilder file, like via the "type-func" attribute in the "<object>" tag. |
61 | * This function is very rarely used. |
62 | * The C implementation will use dlsym() and call the resulting function as a `GTypeFunc`. |
63 | * The default implementation will fail and just return %G_TYPE_INVALID. |
64 | * @create_closure: Create a closure with the given arguments. See gtk_builder_create_closure() |
65 | * for more details on those. |
66 | * The C implementation will try to use dlsym() to locate the function name and then |
67 | * g_cclosure_new() to create a closure for the symbol. |
68 | * The default implementation just fails and returns %NULL. |
69 | * |
70 | * The virtual function table to implement for `GtkBuilderScope` implementations. |
71 | * Default implementations for each function do exist, but they usually just fail, |
72 | * so it is suggested that implementations implement all of them. |
73 | */ |
74 | struct _GtkBuilderScopeInterface |
75 | { |
76 | /*< private >*/ |
77 | GTypeInterface g_iface; |
78 | |
79 | /*< public >*/ |
80 | GType (* get_type_from_name) (GtkBuilderScope *self, |
81 | GtkBuilder *builder, |
82 | const char *type_name); |
83 | GType (* get_type_from_function) (GtkBuilderScope *self, |
84 | GtkBuilder *builder, |
85 | const char *function_name); |
86 | |
87 | GClosure * (* create_closure) (GtkBuilderScope *self, |
88 | GtkBuilder *builder, |
89 | const char *function_name, |
90 | GtkBuilderClosureFlags flags, |
91 | GObject *object, |
92 | GError **error); |
93 | }; |
94 | |
95 | |
96 | |
97 | struct _GtkBuilderCScopeClass |
98 | { |
99 | GObjectClass parent_class; |
100 | }; |
101 | |
102 | #define GTK_TYPE_BUILDER_CSCOPE (gtk_builder_cscope_get_type ()) |
103 | |
104 | GDK_AVAILABLE_IN_ALL |
105 | G_DECLARE_DERIVABLE_TYPE (GtkBuilderCScope, gtk_builder_cscope, GTK, BUILDER_CSCOPE, GObject) |
106 | |
107 | GDK_AVAILABLE_IN_ALL |
108 | GtkBuilderScope * gtk_builder_cscope_new (void); |
109 | GDK_AVAILABLE_IN_ALL |
110 | void gtk_builder_cscope_add_callback_symbol (GtkBuilderCScope *self, |
111 | const char *callback_name, |
112 | GCallback callback_symbol); |
113 | GDK_AVAILABLE_IN_ALL |
114 | void gtk_builder_cscope_add_callback_symbols (GtkBuilderCScope *self, |
115 | const char *first_callback_name, |
116 | GCallback first_callback_symbol, |
117 | ...) G_GNUC_NULL_TERMINATED; |
118 | GDK_AVAILABLE_IN_ALL |
119 | GCallback gtk_builder_cscope_lookup_callback_symbol(GtkBuilderCScope *self, |
120 | const char *callback_name); |
121 | |
122 | |
123 | G_END_DECLS |
124 | |
125 | #endif /* __GTK_BUILDER_SCOPE_H__ */ |
126 | |