From 6f5e60f0337e60d904a8f549aeaa631afefc8033 Mon Sep 17 00:00:00 2001 From: Marius Nita Date: Sat, 16 Nov 2002 09:59:37 +0000 Subject: [PATCH] fixed bugs, got otkapp to select on a fd, modded widget to make use of otkapp, press/release events on buttons --- otk/application.cc | 17 +++++- otk/button.cc | 17 ++++++ otk/button.hh | 2 + otk/eventdispatcher.cc | 2 + otk/eventhandler.cc | 131 +++++++++++++++++++++-------------------- otk/eventhandler.hh | 2 +- otk/style.cc | 5 +- otk/style.hh | 5 ++ otk/widget.cc | 28 ++++----- otk/widget.hh | 6 ++ 10 files changed, 131 insertions(+), 84 deletions(-) diff --git a/otk/application.cc b/otk/application.cc index 92d6dfd2..efe6ad85 100644 --- a/otk/application.cc +++ b/otk/application.cc @@ -1,6 +1,8 @@ #include "application.hh" #include "eventhandler.hh" +#include + namespace otk { OtkApplication::OtkApplication(int argc, char **argv) @@ -35,12 +37,23 @@ void OtkApplication::loadStyle(void) // find the style name as a property _style_conf->setFile("/usr/local/share/openbox/styles/artwiz"); _style_conf->load(); - _style->load(_style_conf); + _style->load(*_style_conf); } void OtkApplication::exec(void) { - dispatchEvents(); + const int xfd = ConnectionNumber(OBDisplay::display); + fd_set rfds; + timeval *timeout = 0; + + while (1) { + dispatchEvents(); + + FD_ZERO(&rfds); + FD_SET(xfd, &rfds); + + select(xfd + 1, &rfds, 0, 0, timeout); + } } } diff --git a/otk/button.cc b/otk/button.cc index fd40f7d5..3f283b00 100644 --- a/otk/button.cc +++ b/otk/button.cc @@ -1,3 +1,4 @@ +#include #include "button.hh" namespace otk { @@ -66,6 +67,22 @@ void OtkButton::update(void) _dirty = false; } +int OtkButton::buttonPressHandler(const XButtonEvent &e) +{ + press(); + _dirty = true; + update(); + return OtkFocusWidget::buttonPressHandler(e); +} + +int OtkButton::buttonReleaseHandler(const XButtonEvent &e) +{ + release(); + _dirty = true; + update(); + return OtkFocusWidget::buttonReleaseHandler(e); +} + int OtkButton::exposeHandler(const XExposeEvent &e) { _dirty = true; diff --git a/otk/button.hh b/otk/button.hh index e73b1f12..e32cd028 100644 --- a/otk/button.hh +++ b/otk/button.hh @@ -39,6 +39,8 @@ public: void update(void); int exposeHandler(const XExposeEvent &e); int configureHandler(const XConfigureEvent &e); + int buttonPressHandler(const XButtonEvent &e); + int buttonReleaseHandler(const XButtonEvent &e); private: diff --git a/otk/eventdispatcher.cc b/otk/eventdispatcher.cc index 0d861b36..2de28369 100644 --- a/otk/eventdispatcher.cc +++ b/otk/eventdispatcher.cc @@ -1,9 +1,11 @@ #include "eventdispatcher.hh" #include "display.hh" +#include namespace otk { OtkEventDispatcher::OtkEventDispatcher() + : _fallback(0) { } diff --git a/otk/eventhandler.cc b/otk/eventhandler.cc index 27ad5e73..cab95e17 100644 --- a/otk/eventhandler.cc +++ b/otk/eventhandler.cc @@ -1,4 +1,5 @@ #include "eventhandler.hh" +#include namespace otk { @@ -14,71 +15,71 @@ OtkEventHandler::~OtkEventHandler() int OtkEventHandler::handle(const XEvent &e) { - switch(e.type){ - case KeyPress: - return keyPressHandler(e.xkey); - case KeyRelease: - return keyReleaseHandler(e.xkey); - case ButtonPress: - return buttonPressHandler(e.xbutton); - case ButtonRelease: - return buttonReleaseHandler(e.xbutton); - case EnterNotify: - return enterHandler(e.xcrossing); - case LeaveNotify: - return leaveHandler(e.xcrossing); - case FocusIn: - return focusHandler(e.xfocus); - case FocusOut: - return unfocusHandler(e.xfocus); - case Expose: - return exposeHandler(e.xexpose); - case GraphicsExpose: - return graphicsExposeHandler(e.xgraphicsexpose); - case NoExpose: - return noExposeEventHandler(e.xnoexpose); - case CirculateRequest: - return circulateRequestHandler(e.xcirculaterequest); - case ConfigureRequest: - return configureRequestHandler(e.xconfigurerequest); - case MapRequest: - return mapRequestHandler(e.xmaprequest); - case ResizeRequest: - return resizeRequestHandler(e.xresizerequest); - case CirculateNotify: - return circulateHandler(e.xcirculate); - case ConfigureNotify: - return configureHandler(e.xconfigure); - case CreateNotify: - return createHandler(e.xcreatewindow); - case DestroyNotify: - return destroyHandler(e.xdestroywindow); - case GravityNotify: - return gravityHandler(e.xgravity); - case MapNotify: - return mapHandler(e.xmap); - case MappingNotify: - return mappingHandler(e.xmapping); - case ReparentNotify: - return reparentHandler(e.xreparent); - case UnmapNotify: - return unmapHandler(e.xunmap); - case VisibilityNotify: - return visibilityHandler(e.xvisibility); - case ColormapNotify: - return colorMapHandler(e.xcolormap); - case ClientMessage: - return clientMessageHandler(e.xclient); - case PropertyNotify: - return propertyHandler(e.xproperty); - case SelectionClear: - return selectionClearHandler(e.xselectionclear); - case SelectionNotify: - return selectionHandler(e.xselection); - case SelectionRequest: - return selectionRequestHandler(e.xselectionrequest); - }; - return 0; + switch(e.type){ + case KeyPress: + return keyPressHandler(e.xkey); + case KeyRelease: + return keyReleaseHandler(e.xkey); + case ButtonPress: + return buttonPressHandler(e.xbutton); + case ButtonRelease: + return buttonReleaseHandler(e.xbutton); + case EnterNotify: + return enterHandler(e.xcrossing); + case LeaveNotify: + return leaveHandler(e.xcrossing); + case FocusIn: + return focusHandler(e.xfocus); + case FocusOut: + return unfocusHandler(e.xfocus); + case Expose: + return exposeHandler(e.xexpose); + case GraphicsExpose: + return graphicsExposeHandler(e.xgraphicsexpose); + case NoExpose: + return noExposeEventHandler(e.xnoexpose); + case CirculateRequest: + return circulateRequestHandler(e.xcirculaterequest); + case ConfigureRequest: + return configureRequestHandler(e.xconfigurerequest); + case MapRequest: + return mapRequestHandler(e.xmaprequest); + case ResizeRequest: + return resizeRequestHandler(e.xresizerequest); + case CirculateNotify: + return circulateHandler(e.xcirculate); + case ConfigureNotify: + return configureHandler(e.xconfigure); + case CreateNotify: + return createHandler(e.xcreatewindow); + case DestroyNotify: + return destroyHandler(e.xdestroywindow); + case GravityNotify: + return gravityHandler(e.xgravity); + case MapNotify: + return mapHandler(e.xmap); + case MappingNotify: + return mappingHandler(e.xmapping); + case ReparentNotify: + return reparentHandler(e.xreparent); + case UnmapNotify: + return unmapHandler(e.xunmap); + case VisibilityNotify: + return visibilityHandler(e.xvisibility); + case ColormapNotify: + return colorMapHandler(e.xcolormap); + case ClientMessage: + return clientMessageHandler(e.xclient); + case PropertyNotify: + return propertyHandler(e.xproperty); + case SelectionClear: + return selectionClearHandler(e.xselectionclear); + case SelectionNotify: + return selectionHandler(e.xselection); + case SelectionRequest: + return selectionRequestHandler(e.xselectionrequest); + }; + return 0; } } diff --git a/otk/eventhandler.hh b/otk/eventhandler.hh index 000efb53..ea273ef4 100644 --- a/otk/eventhandler.hh +++ b/otk/eventhandler.hh @@ -10,7 +10,7 @@ namespace otk { class OtkEventHandler{ public: //! Dispatches events to one of the other handlers based on their type. - int handle(const XEvent &e); + virtual int handle(const XEvent &e); //! Called whenever any key is pressed. virtual int keyPressHandler(const XKeyEvent &) {return 1;} diff --git a/otk/style.cc b/otk/style.cc index 6349a6bc..3c40e24b 100644 --- a/otk/style.cc +++ b/otk/style.cc @@ -3,8 +3,9 @@ #endif // HAVE_CONFIG_H #include -#include "display.hh" +#include +#include "display.hh" #include "util.hh" #include "style.hh" @@ -256,7 +257,7 @@ BColor Style::readDatabaseColor(const std::string &rname, BFont *Style::readDatabaseFont(const std::string &rbasename, - const Configuration &style) { + const Configuration &style) { std::string fontname; std::string s; diff --git a/otk/style.hh b/otk/style.hh index 4128d93e..ccf4e49a 100644 --- a/otk/style.hh +++ b/otk/style.hh @@ -123,6 +123,11 @@ public: inline unsigned int getBorderWidth(void) const { return border_width; } inline const BFont &getFont() const { return *font; } + + inline void setShadowFonts(bool fonts) { shadow_fonts = fonts; } + inline bool hasShadowFonts(void) const { return shadow_fonts; } + + inline void setAAFonts(bool fonts) { aa_fonts = fonts; } inline bool hasAAFonts(void) const { return aa_fonts; } inline TextJustify textJustify(void) { return justify; } diff --git a/otk/widget.cc b/otk/widget.cc index 50314775..85b4206e 100644 --- a/otk/widget.cc +++ b/otk/widget.cc @@ -17,10 +17,11 @@ OtkWidget::OtkWidget(OtkWidget *parent, Direction direction) _grabbed_keyboard(false), _stretchable_vert(false), _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0), _screen(parent->getScreen()), _fixed_width(false), _fixed_height(false), - _dirty(false) + _dirty(false), _event_dispatcher(parent->getEventDispatcher()) { parent->addChild(this); create(); + _event_dispatcher->registerHandler(_window, this); } OtkWidget::OtkWidget(OtkApplication *app, Direction direction, @@ -31,11 +32,12 @@ OtkWidget::OtkWidget(OtkApplication *app, Direction direction, _focused(false), _grabbed_mouse(false), _grabbed_keyboard(false), _stretchable_vert(false), _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0), _screen(app->getStyle()->getScreen()), - _fixed_width(false), _fixed_height(false), _dirty(false) + _fixed_width(false), _fixed_height(false), _dirty(false), + _event_dispatcher(app) { assert(app); create(); - app->registerHandler(_window, this); + _event_dispatcher->registerHandler(_window, this); } OtkWidget::OtkWidget(Style *style, Direction direction, @@ -413,6 +415,14 @@ void OtkWidget::removeChild(OtkWidget *child) _children.erase(it); } +void OtkWidget::setEventDispatcher(OtkEventDispatcher *disp) +{ + if (_event_dispatcher) + _event_dispatcher->clearHandler(_window); + _event_dispatcher = disp; + _event_dispatcher->registerHandler(_window, this); +} + int OtkWidget::exposeHandler(const XExposeEvent &e) { OtkEventHandler::exposeHandler(e); @@ -420,11 +430,6 @@ int OtkWidget::exposeHandler(const XExposeEvent &e) _dirty = true; update(); return true; - } else { - OtkWidgetList::iterator it = _children.begin(), end = _children.end(); - for (; it != end; ++it) - if ((*it)->exposeHandler(e)) - return true; } return false; } @@ -436,7 +441,6 @@ int OtkWidget::configureHandler(const XConfigureEvent &e) if (_ignore_config) { _ignore_config--; } else { - std::cout << "configure\n"; if (!(e.width == _rect.width() && e.height == _rect.height())) { _dirty = true; _rect.setSize(e.width, e.height); @@ -444,12 +448,8 @@ int OtkWidget::configureHandler(const XConfigureEvent &e) update(); } return true; - } else { - OtkWidgetList::iterator it = _children.begin(), end = _children.end(); - for (; it != end; ++it) - if ((*it)->configureHandler(e)) - return true; } + return false; } diff --git a/otk/widget.hh b/otk/widget.hh index 473aa812..a8787754 100644 --- a/otk/widget.hh +++ b/otk/widget.hh @@ -96,6 +96,10 @@ public: inline Style *getStyle(void) const { return _style; } void setStyle(Style *style) { _style = style; } + inline OtkEventDispatcher *getEventDispatcher(void) + { return _event_dispatcher; } + void setEventDispatcher(OtkEventDispatcher *disp); + private: void create(void); @@ -136,6 +140,8 @@ private: bool _fixed_height; bool _dirty; + + OtkEventDispatcher *_event_dispatcher; }; } -- 2.39.2