add an OtkAppWidget which are "root windows", i.e. the managed child of root, to be shown on the display. Exit when all the "root windows" are hidden. Support the WM_DELETE protocol to hide a "root window".
@@ -9,7 +9,7 @@ property.cc imagecontrol.cc rect.cc screeninfo.cc \
texture.cc timer.cc timerqueuemanager.cc style.cc \ configuration.cc util.cc widget.cc focuswidget.cc \ button.cc eventhandler.cc eventdispatcher.cc \ - label.cc focuslabel.cc application.cc + label.cc focuslabel.cc application.cc appwidget.cc MAINTAINERCLEANFILES= Makefile.in@@ -20,26 +20,51 @@ otk_test: libotk.a otk_test.cc
$(CXX) $(CPPFLAGS) -DHAVE_CONFIG_H -I. -I. -I.. -I../src $(XFT_CFLAGS) -Wall -W -pedantic -DNDEBUG -g -O2 -o otk_test otk_test.cc $(XFT_LIBS) ./libotk.a # local dependencies -button.o: button.cc button.hh focuswidget.hh widget.hh rect.hh \ - point.hh texture.hh color.hh util.hh style.hh font.hh image.hh \ - screeninfo.hh timer.hh configuration.hh +application.o: application.cc application.hh eventdispatcher.hh \ + eventhandler.hh display.hh configuration.hh timerqueuemanager.hh \ + timerqueue.hh timer.hh image.hh color.hh screeninfo.hh rect.hh \ + point.hh style.hh font.hh texture.hh util.hh widget.hh +appwidget.o: appwidget.cc appwidget.hh widget.hh rect.hh point.hh \ + texture.hh color.hh util.hh style.hh font.hh image.hh screeninfo.hh \ + timer.hh configuration.hh eventdispatcher.hh eventhandler.hh \ + application.hh display.hh timerqueuemanager.hh timerqueue.hh +button.o: button.cc button.hh focuslabel.hh focuswidget.hh widget.hh \ + rect.hh point.hh texture.hh color.hh util.hh style.hh font.hh \ + image.hh screeninfo.hh timer.hh configuration.hh eventdispatcher.hh \ + eventhandler.hh application.hh display.hh timerqueuemanager.hh \ + timerqueue.hh color.o: color.cc color.hh display.hh screeninfo.hh rect.hh point.hh configuration.o: configuration.cc configuration.hh util.hh +eventdispatcher.o: eventdispatcher.cc eventdispatcher.hh \ + eventhandler.hh display.hh +eventhandler.o: eventhandler.cc eventhandler.hh +focuslabel.o: focuslabel.cc focuslabel.hh focuswidget.hh widget.hh \ + rect.hh point.hh texture.hh color.hh util.hh style.hh font.hh \ + image.hh screeninfo.hh timer.hh configuration.hh eventdispatcher.hh \ + eventhandler.hh application.hh display.hh timerqueuemanager.hh \ + timerqueue.hh focuswidget.o: focuswidget.cc focuswidget.hh widget.hh rect.hh \ point.hh texture.hh color.hh util.hh style.hh font.hh image.hh \ - screeninfo.hh timer.hh configuration.hh -font.o: font.cc font.hh util.hh display.hh display.hh color.hh \ - screeninfo.hh rect.hh point.hh + screeninfo.hh timer.hh configuration.hh eventdispatcher.hh \ + eventhandler.hh application.hh display.hh timerqueuemanager.hh \ + timerqueue.hh +font.o: font.cc font.hh util.hh display.hh color.hh screeninfo.hh \ + rect.hh point.hh gccache.o: gccache.cc gccache.hh display.hh color.hh assassin.hh \ screeninfo.hh rect.hh point.hh image.o: image.cc display.hh gccache.hh color.hh image.hh \ screeninfo.hh rect.hh point.hh timer.hh texture.hh util.hh imagecontrol.o: imagecontrol.cc display.hh color.hh image.hh \ screeninfo.hh rect.hh point.hh timer.hh texture.hh util.hh -otk_test.o: otk_test.cc focuswidget.hh widget.hh rect.hh point.hh \ - texture.hh color.hh util.hh style.hh font.hh image.hh screeninfo.hh \ - timer.hh configuration.hh button.hh display.hh timerqueuemanager.hh \ - timerqueue.hh +label.o: label.cc label.hh widget.hh rect.hh point.hh texture.hh \ + color.hh util.hh style.hh font.hh image.hh screeninfo.hh timer.hh \ + configuration.hh eventdispatcher.hh eventhandler.hh application.hh \ + display.hh timerqueuemanager.hh timerqueue.hh +otk_test.o: otk_test.cc application.hh eventdispatcher.hh \ + eventhandler.hh display.hh configuration.hh timerqueuemanager.hh \ + timerqueue.hh timer.hh image.hh color.hh screeninfo.hh rect.hh \ + point.hh style.hh font.hh texture.hh util.hh focuswidget.hh widget.hh \ + appwidget.hh button.hh focuslabel.hh property.o: property.cc property.hh screeninfo.hh rect.hh point.hh \ display.hh rect.o: rect.cc rect.hh point.hh@@ -56,7 +81,5 @@ timerqueue.hh timer.hh display.hh
util.o: util.cc util.hh widget.o: widget.cc widget.hh rect.hh point.hh texture.hh color.hh \ util.hh style.hh font.hh image.hh screeninfo.hh timer.hh \ - configuration.hh display.hh assassin.hh -eventhandler.o: eventhandler.cc eventhandler.hh -eventdispatcher.o: eventdispatcher.cc eventdispatcher.hh -application.o: application.cc application.hh + configuration.hh eventdispatcher.hh eventhandler.hh application.hh \ + display.hh timerqueuemanager.hh timerqueue.hh assassin.hh
@@ -3,8 +3,6 @@ #include "eventhandler.hh"
#include "widget.hh" extern "C" { -#include <X11/Xlib.h> - #ifdef HAVE_STDLIB_H # include <stdlib.h> #endif@@ -15,13 +13,16 @@
namespace otk { OtkApplication::OtkApplication(int argc, char **argv) - : OtkEventDispatcher(), _main_widget(0), _dockable(false) + : OtkEventDispatcher(), + _dockable(false), + _appwidget_count(0) { argc = argc; argv = argv; OBDisplay::initialize(0); - const ScreenInfo *s_info = OBDisplay::screenInfo(DefaultScreen(OBDisplay::display)); + const ScreenInfo *s_info = + OBDisplay::screenInfo(DefaultScreen(OBDisplay::display)); _timer_manager = new OBTimerQueueManager(); _img_ctrl = new BImageControl(_timer_manager, s_info, True, 4, 5, 200);@@ -55,36 +56,17 @@ }
void OtkApplication::exec(void) { - if (!_main_widget) { - std::cerr << "ERROR: No main widget set. You must create a main " << - "OtkWidget for the OtkApplication before calling " << + if (_appwidget_count <= 0) { + std::cerr << "ERROR: No main widgets exist. You must create and show() " << + "an OtkAppWidget for the OtkApplication before calling " << "OtkApplication::exec().\n"; ::exit(1); } - while (1) { + + while (_appwidget_count > 0) { dispatchEvents(); _timer_manager->fire(); // fire pending events } -} - -bool OtkApplication::setMainWidget(const OtkWidget *main_widget) -{ - // ignore it if it has already been set - if (_main_widget) { - std::cerr << "WARNING: More than one main OtkWidget being created for " << - "the OtkApplication!\n"; - return false; - } - - _main_widget = main_widget; - - // set WM Protocols on the window - Atom protocols[2]; - protocols[0] = XInternAtom(OBDisplay::display, "WM_PROTOCOLS", false); - protocols[1] = XInternAtom(OBDisplay::display, "WM_DELETE_WINDOW", false); - XSetWMProtocols(OBDisplay::display, _main_widget->getWindow(), protocols, 2); - - return true; } }
@@ -10,7 +10,7 @@ #include "style.hh"
namespace otk { -class OtkWidget; +class OtkAppWidget; class OtkApplication : public OtkEventDispatcher {@@ -28,20 +28,18 @@
inline Style *getStyle(void) const { return _style; } // more accessors -protected: - bool setMainWidget(const OtkWidget *main_widget); - private: void loadStyle(void); - const OtkWidget *_main_widget; OBTimerQueueManager *_timer_manager; BImageControl *_img_ctrl; Configuration *_style_conf; Style *_style; bool _dockable; - friend class OtkWidget; // for access to setMainWidget + int _appwidget_count; + + friend class OtkAppWidget; }; }
@@ -0,0 +1,53 @@
+#include "appwidget.hh" +#include "application.hh" + +extern "C" { +#include <X11/Xlib.h> +} + +namespace otk { + +OtkAppWidget::OtkAppWidget(OtkApplication *app, Direction direction, + Cursor cursor, int bevel_width) + : OtkWidget(app, app->getStyle(), direction, cursor, bevel_width), + _application(app) +{ + assert(app); + + _wm_protocols = XInternAtom(OBDisplay::display, "WM_PROTOCOLS", false); + _wm_delete = XInternAtom(OBDisplay::display, "WM_DELETE_WINDOW", false); + + // set WM Protocols on the window + Atom protocols[2]; + protocols[0] = _wm_protocols; + protocols[1] = _wm_delete; + XSetWMProtocols(OBDisplay::display, getWindow(), protocols, 2); +} + +OtkAppWidget::~OtkAppWidget() +{ +} + +void OtkAppWidget::show(void) +{ + OtkWidget::show(); + + _application->_appwidget_count++; +} + +void OtkAppWidget::hide(void) +{ + OtkWidget::hide(); + + _application->_appwidget_count--; +} + +void OtkAppWidget::clientMessageHandler(const XClientMessageEvent &e) +{ + OtkEventHandler::clientMessageHandler(e); + if (e.message_type == _wm_protocols && + static_cast<Atom>(e.data.l[0]) == _wm_delete) + hide(); +} + +}
@@ -0,0 +1,31 @@
+#ifndef __appwidget_hh +#define __appwidget_hh + +#include "widget.hh" + +namespace otk { + +class OtkApplication; + +class OtkAppWidget : public OtkWidget { + +public: + OtkAppWidget(OtkApplication *app, Direction direction = Horizontal, + Cursor cursor = 0, int bevel_width = 1); + virtual ~OtkAppWidget(); + + virtual void show(void); + virtual void hide(void); + + virtual void clientMessageHandler(const XClientMessageEvent &e); + +private: + + OtkApplication *_application; + Atom _wm_protocols; + Atom _wm_delete; +}; + +} + +#endif // __appwidget_hh
@@ -13,7 +13,7 @@ {
} -int OtkEventHandler::handle(const XEvent &e) +void OtkEventHandler::handle(const XEvent &e) { switch(e.type){ case KeyPress:@@ -79,7 +79,6 @@ return selectionHandler(e.xselection);
case SelectionRequest: return selectionRequestHandler(e.xselectionrequest); }; - return 0; } }
@@ -10,104 +10,103 @@
class OtkEventHandler{ public: //! Dispatches events to one of the other handlers based on their type. - virtual int handle(const XEvent &e); + virtual void handle(const XEvent &e); //! Called whenever any key is pressed. - virtual int keyPressHandler(const XKeyEvent &) {return 1;} + virtual void keyPressHandler(const XKeyEvent &) {} //! Called whenever any key is released. - virtual int keyReleaseHandler(const XKeyEvent &) {return 1;} + virtual void keyReleaseHandler(const XKeyEvent &) {} //! Called whenever a button of the pointer is pressed. - virtual int buttonPressHandler(const XButtonEvent &) {return 1;} + virtual void buttonPressHandler(const XButtonEvent &) {} //! Called whenever a button of the pointer is released. - virtual int buttonReleaseHandler(const XButtonEvent &) {return 1;} + virtual void buttonReleaseHandler(const XButtonEvent &) {} //! Called whenever the pointer enters a window. - virtual int enterHandler(const XCrossingEvent &) {return 1;} + virtual void enterHandler(const XCrossingEvent &) {} //! Called whenever the pointer leaves a window. - virtual int leaveHandler(const XCrossingEvent &) {return 1;} + virtual void leaveHandler(const XCrossingEvent &) {} //! Called when a window gains focus. - virtual int focusHandler(const XFocusChangeEvent &) {return 1;} + virtual void focusHandler(const XFocusChangeEvent &) {} //! Called when a window looses focus. - virtual int unfocusHandler(const XFocusChangeEvent &) {return 1;} + virtual void unfocusHandler(const XFocusChangeEvent &) {} //! Called when a window becomes visible to the user. - virtual int exposeHandler(const XExposeEvent &) {return 1;} + virtual void exposeHandler(const XExposeEvent &) {} //! Called to handle GraphicsExpose events. - virtual int graphicsExposeHandler(const XGraphicsExposeEvent &) {return 1;} + virtual void graphicsExposeHandler(const XGraphicsExposeEvent &) {} //! Called to handle NoExpose events. - virtual int noExposeEventHandler(const XNoExposeEvent &) {return 1;} + virtual void noExposeEventHandler(const XNoExposeEvent &) {} //! Called when the window requests a change in its z-order. - virtual int circulateRequestHandler(const XCirculateRequestEvent &) - {return 1;} + virtual void circulateRequestHandler(const XCirculateRequestEvent &) + {} //! Called when a different client initiates a configure window request. - virtual int configureRequestHandler(const XConfigureRequestEvent &) - {return 1;} + virtual void configureRequestHandler(const XConfigureRequestEvent &) + {} //! Called when a different client tries to map a window. - virtual int mapRequestHandler(const XMapRequestEvent &) {return 1;} + virtual void mapRequestHandler(const XMapRequestEvent &) {} //! Called when another client attemps to change the size of a window. - virtual int resizeRequestHandler(const XResizeRequestEvent &) {return 1;} + virtual void resizeRequestHandler(const XResizeRequestEvent &) {} //! Called when the z-order of the window has changed. - virtual int circulateHandler(const XCirculateEvent &) {return 1;} + virtual void circulateHandler(const XCirculateEvent &) {} //! Called when the window as been reconfigured. - virtual int configureHandler(const XConfigureEvent &) {return 1;} + virtual void configureHandler(const XConfigureEvent &) {} //! Called when a window is created. - virtual int createHandler(const XCreateWindowEvent &) {return 1;} + virtual void createHandler(const XCreateWindowEvent &) {} //! Called when a window is destroyed. - virtual int destroyHandler(const XDestroyWindowEvent &) {return 1;} + virtual void destroyHandler(const XDestroyWindowEvent &) {} //! Called when a window is moved because of a change in the size of its //! parent. - virtual int gravityHandler(const XGravityEvent &) {return 1;} + virtual void gravityHandler(const XGravityEvent &) {} //! Called when a window is mapped. - virtual int mapHandler(const XMapEvent &) {return 1;} + virtual void mapHandler(const XMapEvent &) {} //! Called when the server generats a MappingNotify event - virtual int mappingHandler(const XMappingEvent &) {return 1;} + virtual void mappingHandler(const XMappingEvent &) {} //! Called when a window is reparented - virtual int reparentHandler(const XReparentEvent &) {return 1;} + virtual void reparentHandler(const XReparentEvent &) {} //! Called when a window is unmapped - virtual int unmapHandler(const XUnmapEvent &) {return 1;} + virtual void unmapHandler(const XUnmapEvent &) {} //! Called when a the visibilty of a window changes - virtual int visibilityHandler(const XVisibilityEvent &) {return 1;} + virtual void visibilityHandler(const XVisibilityEvent &) {} //! Called when the colormap changes, or is installed or unistalled - virtual int colorMapHandler(const XColormapEvent &) {return 1;} + virtual void colorMapHandler(const XColormapEvent &) {} //! Called when a client calls XSendEvent - virtual int clientMessageHandler(const XClientMessageEvent &) {return 1;} + virtual void clientMessageHandler(const XClientMessageEvent &) {} //! Called when a property of a window changes - virtual int propertyHandler(const XPropertyEvent &) {return 1;} + virtual void propertyHandler(const XPropertyEvent &) {} //! Called when the client loses ownership of a selection - virtual int selectionClearHandler(const XSelectionClearEvent &) {return 1;} + virtual void selectionClearHandler(const XSelectionClearEvent &) {} //! Called when a ConvertSelection protocol request is sent - virtual int selectionHandler(const XSelectionEvent &) {return 1;} + virtual void selectionHandler(const XSelectionEvent &) {} //! Called when a SelectionEvent occurs - virtual int selectionRequestHandler(const XSelectionRequestEvent &) - {return 1;} + virtual void selectionRequestHandler(const XSelectionRequestEvent &) {} virtual ~OtkEventHandler();
@@ -8,20 +8,6 @@ {
_focus_texture = parent->getTexture(); } -OtkFocusWidget::OtkFocusWidget(OtkApplication *app, Direction direction, - Cursor cursor, int bevel_width) - : OtkWidget(app, direction, cursor, bevel_width), - _unfocus_texture(0), _focused(true) -{ -} - -OtkFocusWidget::OtkFocusWidget(Style *style, Direction direction, - Cursor cursor, int bevel_width) - : OtkWidget(style, direction, cursor, bevel_width), - _unfocus_texture(0), _focused(true) -{ -} - OtkFocusWidget::~OtkFocusWidget() { }
@@ -11,10 +11,6 @@
public: OtkFocusWidget(OtkWidget *parent, Direction = Horizontal); - OtkFocusWidget(OtkApplication *app, Direction direction = Horizontal, - Cursor cursor = 0, int bevel_width = 1); - OtkFocusWidget(Style *style, Direction direction = Horizontal, - Cursor cursor = 0, int bevel_width = 1); virtual ~OtkFocusWidget(); virtual void focus(void);
@@ -1,15 +1,16 @@
#include "application.hh" #include "focuswidget.hh" +#include "appwidget.hh" #include "button.hh" int main(int argc, char **argv) { otk::OtkApplication app(argc, argv); - otk::OtkFocusWidget foo(&app); + otk::OtkAppWidget foo(&app); foo.resize(600, 500); foo.setTexture(app.getStyle()->getTitleFocus()); - foo.setUnfocusTexture(app.getStyle()->getTitleUnfocus()); +// foo.setUnfocusTexture(app.getStyle()->getTitleUnfocus()); foo.setBevelWidth(2); foo.setDirection(otk::OtkWidget::Horizontal);
@@ -18,33 +18,16 @@ _visible(false), _focused(false), _grabbed_mouse(false),
_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), - _event_dispatcher(parent->getEventDispatcher()) + _event_dispatcher(parent->getEventDispatcher()), _application(0) { + assert(parent); parent->addChild(this); create(); _event_dispatcher->registerHandler(_window, this); } -OtkWidget::OtkWidget(OtkApplication *app, Direction direction, - Cursor cursor, int bevel_width) - : OtkEventHandler(), - _dirty(false), - _parent(0), _style(app->getStyle()), _direction(direction), _cursor(cursor), - _bevel_width(bevel_width), _ignore_config(0), _visible(false), - _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), - _event_dispatcher(app) -{ - assert(app); - create(); - _event_dispatcher->registerHandler(_window, this); - app->setMainWidget(this); -} - -OtkWidget::OtkWidget(Style *style, Direction direction, - Cursor cursor, int bevel_width) +OtkWidget::OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style, + Direction direction, Cursor cursor, int bevel_width) : OtkEventHandler(), _dirty(false), _parent(0), _style(style), _direction(direction), _cursor(cursor),@@ -52,10 +35,13 @@ _bevel_width(bevel_width), _ignore_config(0), _visible(false),
_focused(false), _grabbed_mouse(false), _grabbed_keyboard(false), _stretchable_vert(false), _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0), _screen(style->getScreen()), - _fixed_width(false), _fixed_height(false) + _fixed_width(false), _fixed_height(false), + _event_dispatcher(event_dispatcher), _application(0) { + assert(event_dispatcher); assert(style); create(); + _event_dispatcher->registerHandler(_window, this); } OtkWidget::~OtkWidget()@@ -427,15 +413,14 @@ _event_dispatcher = disp;
_event_dispatcher->registerHandler(_window, this); } -int OtkWidget::exposeHandler(const XExposeEvent &e) +void OtkWidget::exposeHandler(const XExposeEvent &e) { OtkEventHandler::exposeHandler(e); _dirty = true; update(); - return true; } -int OtkWidget::configureHandler(const XConfigureEvent &e) +void OtkWidget::configureHandler(const XConfigureEvent &e) { OtkEventHandler::configureHandler(e); if (_ignore_config) {@@ -447,8 +432,6 @@ _rect.setSize(e.width, e.height);
} update(); } - - return true; } }
@@ -8,7 +8,7 @@ #include "rect.hh"
#include "point.hh" #include "texture.hh" #include "style.hh" -#include "eventhandler.hh" +#include "eventdispatcher.hh" #include "application.hh" namespace otk {@@ -22,17 +22,16 @@
typedef std::list<OtkWidget *> OtkWidgetList; OtkWidget(OtkWidget *parent, Direction = Horizontal); - OtkWidget(OtkApplication *app, Direction direction = Horizontal, - Cursor cursor = 0, int bevel_width = 1); - OtkWidget(Style *style, Direction direction = Horizontal, - Cursor cursor = 0, int bevel_width = 1); + OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style, + Direction direction = Horizontal, Cursor cursor = 0, + int bevel_width = 1); virtual ~OtkWidget(); virtual void update(void); - int exposeHandler(const XExposeEvent &e); - int configureHandler(const XConfigureEvent &e); + void exposeHandler(const XExposeEvent &e); + void configureHandler(const XConfigureEvent &e); inline Window getWindow(void) const { return _window; } inline const OtkWidget *getParent(void) const { return _parent; }@@ -144,6 +143,7 @@ bool _fixed_width;
bool _fixed_height; OtkEventDispatcher *_event_dispatcher; + OtkApplication *_application; }; }