#include "application.hh"
#include "eventhandler.hh"
+#include "widget.hh"
extern "C" {
+#include <X11/Xlib.h>
+
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
namespace otk {
OtkApplication::OtkApplication(int argc, char **argv)
- : OtkEventDispatcher(), _dockable(false)
+ : OtkEventDispatcher(), _main_widget(0), _dockable(false)
{
argc = argc;
argv = argv;
void OtkApplication::exec(void)
{
+ if (!_main_widget) {
+ std::cerr << "No main widget set. You must create a main OtkWidget for " <<
+ "the OtkApplication before calling OtkApplication::exec().\n";
+ ::exit(1);
+ }
while (1) {
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) 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;
+}
+
}
namespace otk {
+class OtkWidget;
+
class OtkApplication : public OtkEventDispatcher {
public:
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
};
}
assert(app);
create();
_event_dispatcher->registerHandler(_window, this);
+ app->setMainWidget(this);
}
OtkWidget::OtkWidget(Style *style, Direction direction,