diff options
-rw-r--r-- | plugingui/eventhandler.cc | 60 | ||||
-rw-r--r-- | plugingui/guievent.h | 11 | ||||
-rw-r--r-- | plugingui/listbox.cc | 9 | ||||
-rw-r--r-- | plugingui/listbox.h | 1 | ||||
-rw-r--r-- | plugingui/widget.h | 1 |
5 files changed, 67 insertions, 15 deletions
diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc index 3570b77..13a8dbf 100644 --- a/plugingui/eventhandler.cc +++ b/plugingui/eventhandler.cc @@ -122,10 +122,17 @@ LRESULT CALLBACK dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) break; case WM_MOUSEWHEEL: - //fwKeys = LOWORD(wp); - //zDelta = (short) HIWORD(wp); - //xPos = (short) LOWORD(lp); - //yPos = (short) HIWORD(lp); + { + GUI::ScrollEvent *e = new GUI::ScrollEvent(); + e->x = (int)(short) LOWORD(lp); + e->y = (int)(short) HIWORD(lp); + e->delta = (int)(short) HIWORD(wp); + handler->event = e; + //fwKeys = LOWORD(wp); + //zDelta = (short) HIWORD(wp); + //xPos = (short) LOWORD(lp); + //yPos = (short) HIWORD(lp); + } break; case WM_LBUTTONUP: @@ -480,17 +487,26 @@ GUI::Event *GUI::EventHandler::getNextEvent() } if(xe.type == ButtonPress || xe.type == ButtonRelease) { - ButtonEvent *e = new ButtonEvent(); - e->window_id = xe.xbutton.window; - e->x = xe.xbutton.x; - e->y = xe.xbutton.y; - e->button = 0; - e->direction = xe.type == ButtonPress?1:-1; - e->doubleclick = - xe.type == ButtonPress && (xe.xbutton.time - last_click) < 200; - - if(xe.type == ButtonPress) last_click = xe.xbutton.time; - event = e; + if(xe.xbutton.button == 4 || xe.xbutton.button == 5) { + ScrollEvent *e = new ScrollEvent(); + e->window_id = xe.xbutton.window; + e->x = xe.xbutton.x; + e->y = xe.xbutton.y; + e->delta = xe.xbutton.button==4?-1:1; + event = e; + } else { + ButtonEvent *e = new ButtonEvent(); + e->window_id = xe.xbutton.window; + e->x = xe.xbutton.x; + e->y = xe.xbutton.y; + e->button = 0; + e->direction = xe.type == ButtonPress?1:-1; + e->doubleclick = + xe.type == ButtonPress && (xe.xbutton.time - last_click) < 200; + + if(xe.type == ButtonPress) last_click = xe.xbutton.time; + event = e; + } } if(xe.type == KeyPress || xe.type == KeyRelease) { @@ -640,6 +656,20 @@ void GUI::EventHandler::processEvents(Window *window) } } break; + case Event::Scroll: + { + ScrollEvent *se = (ScrollEvent *)event; + + Widget *w = window->find(se->x, se->y); + + if(w) { + se->x -= w->windowX(); + se->y -= w->windowY(); + + w->scrollEvent(se); + } + } + break; case Event::Key: // window->key((KeyEvent*)event); // lineedit->keyEvent((KeyEvent*)event); diff --git a/plugingui/guievent.h b/plugingui/guievent.h index d8d6955..db0328c 100644 --- a/plugingui/guievent.h +++ b/plugingui/guievent.h @@ -44,6 +44,7 @@ public: MouseMove, Repaint, Button, + Scroll, Key, Close, Resize @@ -77,6 +78,16 @@ public: int doubleclick; }; +class ScrollEvent : public Event { +public: + Type type() { return Scroll; } + + int x; + int y; + + int delta; +}; + class RepaintEvent : public Event { public: Type type() { return Repaint; } diff --git a/plugingui/listbox.cc b/plugingui/listbox.cc index dfb5f07..f917368 100644 --- a/plugingui/listbox.cc +++ b/plugingui/listbox.cc @@ -125,6 +125,15 @@ void GUI::ListBox::repaintEvent(GUI::RepaintEvent *e) width() - 1, height() - 1); } +void GUI::ListBox::scrollEvent(ScrollEvent *e) +{ + scroll_offset += e->delta; + if(scroll_offset < 0) scroll_offset = 0; + if(scroll_offset > (items.size() - 1)) + scroll_offset = (items.size() - 1); + repaintEvent(NULL); +} + void GUI::ListBox::buttonEvent(ButtonEvent *e) { //printf("click %d %d [dc: %d]\n", e->x, e->y, e->doubleclick); diff --git a/plugingui/listbox.h b/plugingui/listbox.h index 2a8dc4f..061a0eb 100644 --- a/plugingui/listbox.h +++ b/plugingui/listbox.h @@ -53,6 +53,7 @@ public: virtual void repaintEvent(RepaintEvent *e); virtual void buttonEvent(ButtonEvent *e); + virtual void scrollEvent(ScrollEvent *e); private: std::map<std::string, std::string> items; diff --git a/plugingui/widget.h b/plugingui/widget.h index c0d0a73..4a03d2a 100644 --- a/plugingui/widget.h +++ b/plugingui/widget.h @@ -63,6 +63,7 @@ public: virtual void repaintEvent(RepaintEvent *e) {} virtual void mouseMoveEvent(MouseMoveEvent *e) {} virtual void buttonEvent(ButtonEvent *e) {} + virtual void scrollEvent(ScrollEvent *e) {} virtual void keyEvent(KeyEvent *e) {} Widget *find(size_t x, size_t y); |