]> icculus.org git repositories - mikachu/openbox.git/blob - otk/application.cc
change the style-load-error msg
[mikachu/openbox.git] / otk / application.cc
1 #include "application.hh"
2 #include "eventhandler.hh"
3 #include "widget.hh"
4
5 extern "C" {
6 #ifdef HAVE_STDLIB_H
7 # include <stdlib.h>
8 #endif
9 }
10
11 #include <iostream>
12
13 namespace otk {
14
15 OtkApplication::OtkApplication(int argc, char **argv)
16   : OtkEventDispatcher(),
17     _dockable(false),
18     _appwidget_count(0)
19 {
20   argc = argc;
21   argv = argv;
22
23   OBDisplay::initialize(0);
24   const ScreenInfo *s_info =
25     OBDisplay::screenInfo(DefaultScreen(OBDisplay::display));
26
27   _timer_manager = new OBTimerQueueManager();
28   _img_ctrl = new BImageControl(_timer_manager, s_info, True, 4, 5, 200);
29   _style_conf = new Configuration(False);
30   _style = new Style(_img_ctrl);
31
32   loadStyle();
33 }
34
35 OtkApplication::~OtkApplication()
36 {
37   delete _style_conf;
38   delete _img_ctrl;
39   delete _timer_manager;
40   delete _style;
41   
42   OBDisplay::destroy();
43 }
44
45 void OtkApplication::loadStyle(void)
46 {
47   // find the style name as a property
48   std::string style = "/usr/local/share/openbox/styles/artwiz";
49   _style_conf->setFile(style);
50   if (!_style_conf->load()) {
51     std::cerr << "ERROR: Unable to load style \"" << style << "\".\n";
52     ::exit(1);
53   }
54   _style->load(*_style_conf);
55 }
56
57 void OtkApplication::exec(void)
58 {
59   if (_appwidget_count <= 0) {
60     std::cerr << "ERROR: No main widgets exist. You must create and show() " <<
61       "an OtkAppWidget for the OtkApplication before calling " <<
62       "OtkApplication::exec().\n";
63     ::exit(1);
64   }
65
66   while (_appwidget_count > 0) {
67     dispatchEvents();
68     _timer_manager->fire(); // fire pending events
69   }
70 }
71
72 }