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 | /* Builder
*
* Demonstrates an interface loaded from a XML description.
*/
#include <ctk/ctk.h>
static void
quit_activate (GSimpleAction *action G_GNUC_UNUSED,
GVariant *parameter G_GNUC_UNUSED,
gpointer user_data)
{
CtkWidget *window = user_data;
ctk_widget_destroy (window);
}
static void
about_activate (GSimpleAction *action G_GNUC_UNUSED,
GVariant *parameter G_GNUC_UNUSED,
gpointer user_data)
{
CtkWidget *window = user_data;
CtkBuilder *builder;
CtkWidget *about_dlg;
builder = g_object_get_data (G_OBJECT (window), "builder");
about_dlg = CTK_WIDGET (ctk_builder_get_object (builder, "aboutdialog1"));
ctk_dialog_run (CTK_DIALOG (about_dlg));
ctk_widget_hide (about_dlg);
}
static void
help_activate (GSimpleAction *action G_GNUC_UNUSED,<--- Parameter 'G_GNUC_UNUSED' can be declared as pointer to const
GVariant *parameter G_GNUC_UNUSED,<--- Parameter 'G_GNUC_UNUSED' can be declared as pointer to const
gpointer user_data G_GNUC_UNUSED)
{
g_print ("Help not available\n");
}
static GActionEntry win_entries[] = {
{ .name = "quit", .activate = quit_activate },
{ .name = "about", .activate = about_activate },
{ .name = "help", .activate = help_activate }
};
CtkWidget *
do_builder (CtkWidget *do_widget)
{
static CtkWidget *window = NULL;
if (!window)
{
CtkWidget *toolbar;
GActionGroup *actions;
CtkAccelGroup *accel_group;
CtkWidget *item;
CtkBuilder *builder;
builder = ctk_builder_new_from_resource ("/builder/demo.ui");
ctk_builder_connect_signals (builder, NULL);
window = CTK_WIDGET (ctk_builder_get_object (builder, "window1"));
ctk_window_set_screen (CTK_WINDOW (window),
ctk_widget_get_screen (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (ctk_widget_destroyed), &window);
toolbar = CTK_WIDGET (ctk_builder_get_object (builder, "toolbar1"));
ctk_style_context_add_class (ctk_widget_get_style_context (toolbar),
"primary-toolbar");
actions = (GActionGroup*)g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (actions),
win_entries, G_N_ELEMENTS (win_entries),
window);
ctk_widget_insert_action_group (window, "win", actions);
accel_group = ctk_accel_group_new ();
ctk_window_add_accel_group (CTK_WINDOW (window), accel_group);
item = (CtkWidget*)ctk_builder_get_object (builder, "new_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_n, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "open_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_o, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "save_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_s, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "quit_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_q, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "copy_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_c, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "cut_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_x, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "paste_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_v, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "help_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_F1, 0, CTK_ACCEL_VISIBLE);
item = (CtkWidget*)ctk_builder_get_object (builder, "about_item");
ctk_widget_add_accelerator (item, "activate", accel_group,
CDK_KEY_F7, 0, CTK_ACCEL_VISIBLE);
g_object_set_data_full (G_OBJECT(window), "builder", builder, g_object_unref);
}
if (!ctk_widget_get_visible (window))
ctk_widget_show_all (window);
else
ctk_widget_destroy (window);
return window;
}
|