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