Sat, 23 Jan 2016 23:44:41 +0100
improved box container and added radio button (GTK)
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
31 | #include <string.h> |
95
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
32 | #include <stdbool.h> |
0 | 33 | |
34 | #include "toolkit.h" | |
3 | 35 | #include "toolbar.h" |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
36 | #include "model.h" |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
37 | #include "image.h" |
1
eb5269000bc8
added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
38 | #include "../common/document.h" |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
39 | #include "../common/properties.h" |
0 | 40 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
41 | #include <pthread.h> |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
42 | |
0 | 43 | static char *application_name; |
44 | ||
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
45 | static ui_callback appclose_fnc; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
46 | static void *appclose_udata; |
0 | 47 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
48 | static UiObject *active_window; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
49 | |
0 | 50 | void ui_init(char *appname, int argc, char **argv) { |
51 | gtk_init(&argc, &argv); | |
52 | application_name = appname; | |
53 | ||
54 | uic_docmgr_init(); | |
3 | 55 | ui_toolbar_init(); |
0 | 56 | |
57 | // init custom types | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
58 | ui_list_init(); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
59 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
60 | ui_image_init(); |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
61 | |
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
62 | uic_load_app_properties(); |
0 | 63 | } |
64 | ||
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
65 | char* ui_appname() { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
66 | return application_name; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
67 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
68 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
69 | void ui_exitfunc(ui_callback f, void *userdata) { |
0 | 70 | appclose_fnc = f; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
71 | appclose_udata = userdata; |
0 | 72 | } |
73 | ||
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
74 | void ui_openfilefunc(ui_callback f, void *userdata) { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
75 | // OS X only |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
76 | } |
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
77 | |
0 | 78 | void ui_main() { |
79 | gtk_main(); | |
80 | if(appclose_fnc) { | |
81 | appclose_fnc(NULL, appclose_udata); | |
82 | } | |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
83 | uic_store_app_properties(); |
0 | 84 | } |
85 | ||
86 | void ui_show(UiObject *obj) { | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
87 | uic_check_group_widgets(obj->ctx); |
0 | 88 | gtk_widget_show_all(obj->widget); |
89 | } | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
90 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
91 | void ui_close(UiObject *obj) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
92 | gtk_widget_destroy(obj->widget); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
93 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
94 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
95 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
96 | static gboolean ui_job_finished(void *data) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
97 | UiJob *job = data; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
98 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
99 | UiEvent event; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
100 | event.obj = job->obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
101 | event.window = job->obj->window; |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
102 | event.document = job->obj->ctx->document; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
103 | event.intval = 0; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
104 | event.eventdata = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
105 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
106 | job->finish_callback(&event, job->finish_data); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
107 | free(job); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
108 | return FALSE; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
109 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
110 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
111 | static void* ui_jobthread(void *data) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
112 | UiJob *job = data; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
113 | int result = job->job_func(job->job_data); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
114 | if(!result) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
115 | g_idle_add(ui_job_finished, job); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
116 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
117 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
118 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
119 | void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
120 | UiJob *job = malloc(sizeof(UiJob)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
121 | job->obj = obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
122 | job->job_func = tf; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
123 | job->job_data = td; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
124 | job->finish_callback = f; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
125 | job->finish_data = fd; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
126 | pthread_t pid; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
127 | pthread_create(&pid, NULL, ui_jobthread, job); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
128 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
129 | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
130 | void ui_set_enabled(UIWIDGET widget, int enabled) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
131 | gtk_widget_set_sensitive(widget, enabled); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
132 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
133 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
134 | void ui_set_show_all(UIWIDGET widget, int value) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
135 | gtk_widget_set_no_show_all(widget, !value); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
136 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
137 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
138 | void ui_set_visible(UIWIDGET widget, int visible) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
139 | if(visible) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
140 | gtk_widget_set_no_show_all(widget, FALSE); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
141 | gtk_widget_show_all(widget); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
142 | } else { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
143 | gtk_widget_hide(widget); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
144 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
145 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
146 | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
147 | void ui_clipboard_set(char *str) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
148 | GtkClipboard *cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
149 | gtk_clipboard_set_text(cb, str, strlen(str)); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
150 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
151 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
152 | char* ui_clipboard_get() { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
153 | GtkClipboard *cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
154 | char *str = gtk_clipboard_wait_for_text(cb); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
155 | if(str) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
156 | char *copy = strdup(str); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
157 | g_free(str); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
158 | return copy; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
159 | } else { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
160 | return NULL; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
161 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
162 | } |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
163 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
164 | void ui_destroy_userdata(GtkWidget *object, void *userdata) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
165 | free(userdata); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
166 | } |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
167 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
168 | void ui_set_active_window(UiObject *obj) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
169 | active_window = obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
170 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
171 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
172 | UiObject *ui_get_active_window() { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
173 | return active_window; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
174 | } |
95
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
175 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
176 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
177 | /* -------------------- common widget functions -------------------- */ |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
178 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
179 | static gboolean widget_button_pressed( |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
180 | GtkWidget *widget, |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
181 | GdkEvent *event, |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
182 | gpointer userdata) |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
183 | { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
184 | UiEventData *eventdata = userdata; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
185 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
186 | UiMouseEvent me; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
187 | me.x = (int)event->button.x; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
188 | me.y = (int)event->button.y; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
189 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
190 | int exec = 0; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
191 | if(event->button.type == GDK_BUTTON_PRESS) { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
192 | exec = 1; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
193 | me.type = UI_PRESS; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
194 | } else if(event->button.type == GDK_2BUTTON_PRESS) { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
195 | exec = 1; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
196 | me.type = UI_PRESS2; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
197 | } |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
198 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
199 | if(exec) { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
200 | UiEvent e; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
201 | e.obj = eventdata->obj; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
202 | e.window = eventdata->obj->window; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
203 | e.document = eventdata->obj->ctx->document; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
204 | e.eventdata = &me; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
205 | e.intval = 0; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
206 | eventdata->callback(&e, eventdata->userdata); |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
207 | } |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
208 | return true; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
209 | } |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
210 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
211 | void ui_mouse_handler(UiObject *obj, UIWIDGET widget, ui_callback f, void *u) { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
212 | gtk_widget_set_events(widget, GDK_BUTTON_PRESS_MASK); |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
213 | if(f) { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
214 | UiEventData *event = malloc(sizeof(UiEventData)); |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
215 | event->obj = obj; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
216 | event->callback = f; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
217 | event->userdata = u; |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
218 | |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
219 | g_signal_connect(G_OBJECT(widget), |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
220 | "button-press-event", |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
221 | G_CALLBACK(widget_button_pressed), |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
222 | event); |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
223 | } else { |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
224 | // TODO: warning |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
225 | } |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
226 | } |
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
227 |