ui/gtk/toolkit.c

changeset 95
29f5cd5f5367
parent 52
25e5390cce41
child 115
102fc0b8fe3e
equal deleted inserted replaced
94:d51e334c1439 95:29f5cd5f5367
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <string.h> 31 #include <string.h>
32 #include <stdbool.h>
32 33
33 #include "toolkit.h" 34 #include "toolkit.h"
34 #include "toolbar.h" 35 #include "toolbar.h"
35 #include "model.h" 36 #include "model.h"
36 #include "image.h" 37 #include "image.h"
169 } 170 }
170 171
171 UiObject *ui_get_active_window() { 172 UiObject *ui_get_active_window() {
172 return active_window; 173 return active_window;
173 } 174 }
175
176
177 /* -------------------- common widget functions -------------------- */
178
179 static gboolean widget_button_pressed(
180 GtkWidget *widget,
181 GdkEvent *event,
182 gpointer userdata)
183 {
184 UiEventData *eventdata = userdata;
185
186 UiMouseEvent me;
187 me.x = (int)event->button.x;
188 me.y = (int)event->button.y;
189
190 int exec = 0;
191 if(event->button.type == GDK_BUTTON_PRESS) {
192 exec = 1;
193 me.type = UI_PRESS;
194 } else if(event->button.type == GDK_2BUTTON_PRESS) {
195 exec = 1;
196 me.type = UI_PRESS2;
197 }
198
199 if(exec) {
200 UiEvent e;
201 e.obj = eventdata->obj;
202 e.window = eventdata->obj->window;
203 e.document = eventdata->obj->ctx->document;
204 e.eventdata = &me;
205 e.intval = 0;
206 eventdata->callback(&e, eventdata->userdata);
207 }
208 return true;
209 }
210
211 void ui_mouse_handler(UiObject *obj, UIWIDGET widget, ui_callback f, void *u) {
212 gtk_widget_set_events(widget, GDK_BUTTON_PRESS_MASK);
213 if(f) {
214 UiEventData *event = malloc(sizeof(UiEventData));
215 event->obj = obj;
216 event->callback = f;
217 event->userdata = u;
218
219 g_signal_connect(G_OBJECT(widget),
220 "button-press-event",
221 G_CALLBACK(widget_button_pressed),
222 event);
223 } else {
224 // TODO: warning
225 }
226 }
227

mercurial