From b4e3a438d70966db15e2160f6e215365767d41b0 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 27 Dec 2012 21:56:35 +0000 Subject: [PATCH] .gtk BE git-svn-id: svn://ultimatepp.org/upp/trunk@5665 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- rainbow/Gtk/Ctrl.h | 3 +- rainbow/Gtk/Event.cpp | 66 +++++++++++++++++++++++----------------- rainbow/Gtk/Top.h | 2 ++ rainbow/GtkMain/main.cpp | 6 +++- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/rainbow/Gtk/Ctrl.h b/rainbow/Gtk/Ctrl.h index e631d57ee..543663313 100644 --- a/rainbow/Gtk/Ctrl.h +++ b/rainbow/Gtk/Ctrl.h @@ -4,7 +4,8 @@ static gboolean GtkProc(GtkWidget *widget, GdkEvent *event, gpointer user_data); static void IMCommit(GtkIMContext *context, gchar *str, gpointer user_data); - + bool DispatchMouseIn(int act, int zd); + void GtkMouseEvent(int action, int act, Point p, int zd); void GtkMouseEvent(int action, GdkEvent *event); void GtkKeyEvent(GdkEventKey *key, bool pressed); diff --git a/rainbow/Gtk/Event.cpp b/rainbow/Gtk/Event.cpp index 7622a310e..ca2bafb86 100644 --- a/rainbow/Gtk/Event.cpp +++ b/rainbow/Gtk/Event.cpp @@ -38,39 +38,44 @@ bool GetMouseRight() { syncMousePos(); return sModmask & GDK_BUTTON3_MASK; } bool GetMouseMiddle() { syncMousePos(); return sModmask & GDK_BUTTON2_MASK; } Point GetMousePos() { syncMousePos(); return sMousepos; } +bool Ctrl::DispatchMouseIn(int act, int zd) +{ + Point p = GetMousePos(); + Rect r = GetScreenRect(); + if(r.Contains(p)) { + p -= r.TopLeft(); + DispatchMouse(act, p, zd); + return true; + } + return false; +} + +void Ctrl::GtkMouseEvent(int action, int act, Point p, int zd) +{ + DDUMP(zd); + if(grabpopup && activePopup.GetCount()) { + for(int i = activePopup.GetCount() - 1; i >= 0; i--) + if(activePopup[i]->DispatchMouseIn(act, zd)) + return; + Ptr w = activePopup[0]->GetTopWindow(); + if(action == DOWN) { // Deactivate active popup(s) if clicked outside of active popups + IgnoreMouseUp(); + activePopup.Top()->GetTopWindow()->ActivateWnd(); + } + else + w->DispatchMouseIn(act, zd); + return; + } + DispatchMouse(act, p, zd); +} + void Ctrl::GtkMouseEvent(int action, GdkEvent *event) { GdkEventButton *e = (GdkEventButton *)event; int act = action; if(action != MOUSEMOVE) act |= e->button == 2 ? MIDDLE : e->button == 3 ? RIGHT : LEFT; - if(grabpopup && activePopup.GetCount()) { - Point p = GetMousePos(); - for(int i = activePopup.GetCount() - 1; i >= 0; i--) { - Ctrl *w = activePopup[i]; - Rect r = w->GetScreenRect(); - if(r.Contains(p)) { - p -= r.TopLeft(); - w->DispatchMouse(act, p); - return; - } - } - if(action == DOWN) { // Deactivate active popup(s) if clicked outside of active popups - IgnoreMouseUp(); - Ptr w = activePopup.Top()->GetTopWindow(); - if(w) - w->ActivateWnd(); - if(w) { - Rect r = w->GetScreenRect(); - if(r.Contains(p)) { - p -= r.TopLeft(); - w->DispatchMouse(MOUSEMOVE, p); - } - } - } - return; - } - DispatchMouse(act, Point((int)e->x, (int)e->y)); + GtkMouseEvent(action, act, Point((int)e->x, (int)e->y), 0); } #ifdef LOG_EVENTS @@ -166,7 +171,6 @@ bool Ctrl::Proc(GdkEvent *event) GdkEventExpose *e = (GdkEventExpose *)event; SystemDraw w(gdk_cairo_create(gdk())); painting = true; - DDUMP(RectC(e->area.x, e->area.y, e->area.width, e->area.height)); UpdateArea(w, RectC(e->area.x, e->area.y, e->area.width, e->area.height)); cairo_destroy(w); if(top->dr) @@ -193,6 +197,12 @@ bool Ctrl::Proc(GdkEvent *event) else GtkMouseEvent(UP, event); break; + case GDK_SCROLL: { + GdkEventScroll *e = (GdkEventScroll *)event; + GtkMouseEvent(MOUSEWHEEL, MOUSEWHEEL, Point((int)e->x, (int)e->y), + findarg(e->direction, GDK_SCROLL_UP, GDK_SCROLL_LEFT) < 0 ? -120 : 120); + break; + } case GDK_KEY_PRESS: pressed = true; key = (GdkEventKey *)event; diff --git a/rainbow/Gtk/Top.h b/rainbow/Gtk/Top.h index 090f5a489..6e0efc8ce 100644 --- a/rainbow/Gtk/Top.h +++ b/rainbow/Gtk/Top.h @@ -1,6 +1,8 @@ //$ class TopWindow : Ctrl { ImageGdk gdk_icon; bool topmost; + + enum { FULLSCREEN = 99 }; void CenterRect(Ctrl *owner); void SetMode(int mode); diff --git a/rainbow/GtkMain/main.cpp b/rainbow/GtkMain/main.cpp index a2b1ce574..70ccf475a 100644 --- a/rainbow/GtkMain/main.cpp +++ b/rainbow/GtkMain/main.cpp @@ -292,6 +292,7 @@ struct MyApp4 : TopWindow { void MainMenu(Bar& bar) { bar.Add("Menu", THISBACK(Menu)); + bar.Add("Menu", THISBACK(Menu)); } void SetMenu() @@ -302,7 +303,10 @@ struct MyApp4 : TopWindow { MyApp4() { ToolWindow(); Title("Complex Rainbow test"); - edit.SetQTF("[A9 [/ Hello] [_ World]!"); + String qtf; + for(int i = 0; i < 100; i++) + qtf << "[A9 [/ Hello] [_ World]!]"; + edit.SetQTF(qtf); Sizeable().Zoomable(); Add(edit.SizePos()); AddFrame(menu);