From cd788ff08afa7987be56fa58d58a8faa284c7120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Wed, 29 Dec 2010 18:25:16 +0000 Subject: [PATCH] [GB.GTK] * BUG: Keyboard events are now sent to windows the same way as in gb.qt4. git-svn-id: svn://localhost/gambas/trunk@3412 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- .../examples/Drawing/Painting/.src/FMain.form | 5 +- gb.gtk/src/CWidget.cpp | 85 ++++++------------- gb.gtk/src/gapplication.cpp | 31 +++++-- gb.gtk/src/gcontrol.cpp | 5 ++ 4 files changed, 57 insertions(+), 69 deletions(-) diff --git a/examples/examples/Drawing/Painting/.src/FMain.form b/examples/examples/Drawing/Painting/.src/FMain.form index e4a0b1824..1089e3f42 100644 --- a/examples/examples/Drawing/Painting/.src/FMain.form +++ b/examples/examples/Drawing/Painting/.src/FMain.form @@ -2,7 +2,6 @@ { Form Form MoveScaled(0,0,118,86) - Text = ("") Arrangement = Arrange.Fill { HSplit1 HSplit MoveScaled(1,1,96,84) @@ -164,14 +163,14 @@ { DrawingArea1 DrawingArea MoveScaled(2,1,38,45) Background = &HFFFFFF& - Painted = True Border = Border.Plain + Painted = True } Index = 1 Text = ("Source") { Editor1 TextArea MoveScaled(8,2,32,37) - Font = Font["Monospace"] + Font = Font["Monospace,-1"] Text = ("TextArea1") ReadOnly = True } diff --git a/gb.gtk/src/CWidget.cpp b/gb.gtk/src/CWidget.cpp index 6b5df2af7..c9f0e7127 100644 --- a/gb.gtk/src/CWidget.cpp +++ b/gb.gtk/src/CWidget.cpp @@ -136,22 +136,32 @@ void gb_plug_raise_error(gControl *sender) // GB.Unref(POINTER(&_object)); // } +static int to_gambas_event(int type) +{ + switch (type) + { + case gEvent_MousePress: return EVENT_MouseDown; + case gEvent_MouseRelease: return EVENT_MouseUp; + case gEvent_MouseMove: return EVENT_MouseMove; + case gEvent_MouseDrag: return EVENT_MouseDrag; + case gEvent_MouseWheel: return EVENT_MouseWheel; + case gEvent_MouseMenu: return EVENT_Menu; + case gEvent_MouseDblClick: return EVENT_DblClick; + case gEvent_KeyPress: return EVENT_KeyPress; + case gEvent_KeyRelease: return EVENT_KeyRelease; + default: return -1; + } +} + static bool gb_can_raise(gControl *sender, int type) { CWIDGET *ob = GetObject(sender); - if (!ob) return false; - - switch (type) - { - case gEvent_MousePress: type = EVENT_MouseDown; break; - case gEvent_MouseRelease: type = EVENT_MouseUp; break; - case gEvent_MouseMove: type = EVENT_MouseMove; break; - case gEvent_MouseDrag: type = EVENT_MouseDrag; break; - case gEvent_MouseWheel: type =EVENT_MouseWheel; break; - case gEvent_MouseMenu: type = EVENT_Menu; break; - case gEvent_MouseDblClick: type = EVENT_DblClick; break; - default: return true; - } + if (!ob) + return false; + + type = to_gambas_event(type); + if (type < 0) + return false; return GB.CanRaise(ob, type); } @@ -164,27 +174,11 @@ bool gb_raise_MouseEvent(gControl *sender, int type) switch(type) { - case gEvent_MousePress: - GB.Raise(ob, EVENT_MouseDown, 0); - break; - - case gEvent_MouseRelease: - GB.Raise(ob, EVENT_MouseUp, 0); - break; - - case gEvent_MouseMove: - GB.Raise(ob, EVENT_MouseMove, 0); - break; - case gEvent_MouseDrag: if (gMouse::button() && GB.CanRaise(ob, EVENT_MouseDrag)) GB.Raise(ob, EVENT_MouseDrag, 0); break; - case gEvent_MouseWheel: - GB.Raise(ob, EVENT_MouseWheel, 0); - break; - case gEvent_MouseMenu: if (GB.CanRaise(ob, EVENT_Menu)) @@ -204,10 +198,8 @@ bool gb_raise_MouseEvent(gControl *sender, int type) break; - case gEvent_MouseDblClick: - //fprintf(stderr, "dblclick: %s (%p)\n", sender->name(), _ob); - GB.Raise(ob, EVENT_DblClick, 0); - break; + default: + GB.Raise(ob, to_gambas_event(type), 0); } @@ -216,35 +208,12 @@ bool gb_raise_MouseEvent(gControl *sender, int type) bool gb_raise_KeyEvent(gControl *sender, int type) { - CWIDGET *_ob=GetObject(sender); - - if (!_ob) return false; - - switch(type) - { - case gEvent_KeyPress: - return GB.Raise((void*)_ob,EVENT_KeyPress,0); - case gEvent_KeyRelease: - GB.Raise((void*)_ob,EVENT_KeyRelease,0); - return false; - default: - return false; - } + return GB.Raise(GetObject(sender), to_gambas_event(type), 0); } void gb_raise_EnterLeave(gControl *sender, int type) { - CWIDGET *_ob=GetObject(sender); - - if (!_ob) return; - - switch(type) - { - case gEvent_Enter: - GB.Raise((void*)_ob,EVENT_Enter,0); break; - case gEvent_Leave: - GB.Raise((void*)_ob,EVENT_Leave,0); break; - } + GB.Raise(GetObject(sender), to_gambas_event(type), 0); } static void post_focus_change(void *) diff --git a/gb.gtk/src/gapplication.cpp b/gb.gtk/src/gapplication.cpp index 5bdc70ba0..af0be07b2 100644 --- a/gb.gtk/src/gapplication.cpp +++ b/gb.gtk/src/gapplication.cpp @@ -279,6 +279,25 @@ static GtkWindowGroup *get_window_group(GtkWidget *widget) return FALSE; }*/ +static bool raise_key_event_to_parent_window(gControl *control, int type) +{ + gMainWindow *win; + + while (control->parent()) + { + win = control->parent()->window(); + if (win->onKeyEvent && win->canRaise(win, type)) + { + if (win->onKeyEvent(win, type)) + return true; + } + + control = win; + } + + return false; +} + static void gambas_handle_event(GdkEvent *event) { GtkWidget *widget; @@ -558,10 +577,8 @@ static void gambas_handle_event(GdkEvent *event) //fprintf(stderr, "gEvent_KeyPress on %p %s\n", control, control->name()); cancel = control->onKeyEvent(control, gEvent_KeyPress); } - if (!cancel && win != control && win->onKeyEvent) - { - cancel = win->onKeyEvent(win, gEvent_KeyPress); - } + if (!cancel) + cancel = raise_key_event_to_parent_window(control, gEvent_KeyPress); } gKey::disable(); @@ -615,10 +632,8 @@ static void gambas_handle_event(GdkEvent *event) } if (!cancel) control->emit(SIGNAL(control->onKeyEvent), gEvent_KeyRelease); - if (!cancel && win != control && win->onKeyEvent) - { - cancel = win->onKeyEvent(win, gEvent_KeyRelease); - } + if (!cancel) + cancel = raise_key_event_to_parent_window(control, gEvent_KeyRelease); } gKey::disable(); diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index 834b6a6c3..e077a6220 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -195,6 +195,10 @@ void gControl::cleanRemovedControls() controls_destroyed = NULL; } +static bool always_can_raise(gControl *sender, int type) +{ + return true; +} void gControl::initAll(gContainer *parent) { @@ -239,6 +243,7 @@ void gControl::initAll(gContainer *parent) onDragMove = NULL; onDrop = NULL; onEnterLeave = NULL; + canRaise = always_can_raise; frame = border = widget = NULL; _scroll = NULL;