]> icculus.org git repositories - mikachu/openbox.git/blob - otk/application.cc
almost done the ustring conversion
[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
11 extern "C" {
12 #ifdef HAVE_STDLIB_H
13 # include <stdlib.h>
14 #endif
15 }
16
17 #include <iostream>
18
19 namespace otk {
20
21 Application::Application(int argc, char **argv)
22   : EventDispatcher(),
23     _dockable(false),
24     _appwidget_count(0)
25 {
26   (void)argc;
27   (void)argv;
28
29   Display::initialize(0);
30   const ScreenInfo *s_info =
31     Display::screenInfo(DefaultScreen(Display::display));
32
33   _timer_manager = new TimerQueueManager();
34   _img_ctrl = new ImageControl(_timer_manager, s_info, True, 4, 5, 200);
35   _style_conf = new Configuration(False);
36   _style = new Style(_img_ctrl);
37
38   loadStyle();
39 }
40
41 Application::~Application()
42 {
43   delete _style_conf;
44   delete _img_ctrl;
45   delete _timer_manager;
46   delete _style;
47   
48   Display::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_manager->fire(); // fire pending events
75   }
76 }
77
78 }