CoreGTK 3.22.0 CoreGTK is an Objective-C language binding for the GTK+ widget toolkit

CGTKBaseBuilder.m
1 /*
2 * CGTKBaseBuilder.m
3 * This file is part of CoreGTK
4 *
5 * Copyright (C) 2017 - Tyler Burton
6 *
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.
11 *
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.
16 *
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 * Modified by the CoreGTK Team, 2017. See the AUTHORS file for a
24 * list of people on the CoreGTK Team.
25 * See the ChangeLog files for a list of changes.
26 *
27 */
28
29 /*
30 * Objective-C imports
31 */
32 #import "CGTKBaseBuilder.h"
33
34 static BOOL CGTKBuilderDebugMode = NO;
35
36 static void gtkbuilder_connect_signals_handler(GtkBuilder *builder, GObject *object, const gchar *signal_name, const gchar *handler_name, GObject *connect_object, GConnectFlags flags, gpointer user_data)
37 {
38 if(CGTKBuilderDebugMode)
39 {
40 NSLog(@"Signal_name = %@", [NSString stringWithUTF8String:signal_name]);
41 NSLog(@"Handlers_name = %@", [NSString stringWithUTF8String:handler_name]);
42 }
43
44 NSDictionary *objectSignalDictionary = (NSDictionary *)user_data;
45
46 id callbackData = [objectSignalDictionary objectForKey:[NSString stringWithUTF8String:handler_name]];
47
48 id obj = [callbackData object];
49 SEL sel = [callbackData sel];
50
51 if(obj == nil && object != NULL)
52 {
53 if(CGTKBuilderDebugMode)
54 {
55 NSLog(@"Connecting to plain C function");
56 }
57 // Connect to C function
58 g_signal_connect(object, signal_name, G_CALLBACK(handler_name), NULL);
59 }
60 else
61 {
62 if(CGTKBuilderDebugMode)
63 {
64 NSLog(@"Found object %@", obj);
65 }
66
67 // Connect to Objective-C method
68 [CGTKSignalConnector connectGpointer:object withSignal:[NSString stringWithUTF8String:signal_name] toTarget:obj withSelector:sel andData:NULL];
69 }
70 }
71
72 @implementation CGTKBaseBuilder
73
74 +(void)setDebug:(BOOL)debugEnabled
75 {
76 CGTKBuilderDebugMode = debugEnabled;
77 }
78
79 +(void)connectSignalsToObjectsWithBuilder:(CGTKBuilder *)builder andSignalDictionary:(NSDictionary *)objectSignalDictionary;
80 {
81 gtk_builder_connect_signals_full([builder BUILDER], &gtkbuilder_connect_signals_handler, objectSignalDictionary);
82 }
83
84 +(CGTKWidget *)getWidgetFromBuilder:(CGTKBuilder *)builder withName:(NSString *)name
85 {
86 GObject *obj = gtk_builder_get_object([builder BUILDER], [name UTF8String]);
87
88 if(GTK_IS_WIDGET(obj))
89 {
90 return [[[CGTKWidget alloc] initWithGObject:obj] autorelease];
91 }
92 else
93 {
94 return nil;
95 }
96 }
97
98 @end
CGTKSignalConnector
Definition: CGTKSignalConnector.h:43
CGTKWidget
Definition: CGTKWidget.h:34
CGTKBuilder
Definition: CGTKBuilder.h:35
+[CGTKSignalConnector connectGpointer:withSignal:toTarget:withSelector:andData:]
void connectGpointer:withSignal:toTarget:withSelector:andData:(gpointer object, [withSignal] NSString *name, [toTarget] id target, [withSelector] SEL selector, [andData] gpointer data)
Definition: CGTKSignalConnector.m:44
CGTKBaseBuilder
Definition: CGTKBaseBuilder.h:44