view include/App.h @ 7:713e3c5db1e1

just comments
author Eris Caffee <discordia@eldalin.com>
date Wed, 18 Apr 2012 00:53:10 -0500
parents 1b73e60d53b4
children c5c33bf5f1fb
line source
1 #include <map>
2 #include <string>
4 #include <X11/Xlib.h>
6 ////////////////////////////////////////////////////////////////////////////////
7 class App
8 {
9 public:
11 /////////////////////////////////////
12 class BitMap
13 {
14 public:
15 BitMap(const std::string & file);
16 ~BitMap();
18 void make_pixmap(Display * dpy, Drawable d);
20 // Yeah, it's all public here. Keeping it simple.
21 std::string name;
22 unsigned int width;
23 unsigned int height;
24 unsigned char * data;
25 Pixmap pixmap;
27 private:
28 BitMap(const App::BitMap & b);
30 int read_from_file(const std::string & file);
31 };
33 /////////////////////////////////////
34 // TODO: Need to be able to support child windows.
35 // Thus, I need a tree and this class should be a node of the tree.
36 // I could use an STL multimap container that maps child nodes onto parent nodes
37 // The root node would need to be a bit special. Perhaps it would map to itself.
38 // Use the equal_range() method to get the children of the specified node.
39 // I would still need to implement my own tree walking methods: get root node,
40 // for each child (get children and recurse).
41 //
42 // It may be more efficient to implement the tree directly instead of using
43 // std::map as an intermediary.
45 class WindowData
46 {
47 public:
48 WindowData(const std::string & n, Window w, App::BitMap * i) :
49 name(n), win(w), icon(i) {};
50 ~WindowData()
51 {
52 if (icon) { delete icon; icon = NULL; }
53 }
56 std::string name;
57 Window win;
58 App::BitMap * icon;
59 };
61 /////////////////////////////////////
63 typedef std::pair<std::string, App::WindowData *> win_pair;
64 typedef std::map<std::string, App::WindowData *> WindowMap;
66 App(const std::string & appname);
67 ~App();
69 static int x_error_handler(Display * dpy, XErrorEvent *err);
71 void create_window(const std::string& win_name,
72 int x, int y,
73 unsigned int width, unsigned int height,
74 App::BitMap * icon);
76 inline int display_height(void) const
77 { return DisplayHeight(dpy, DefaultScreen(dpy)); };
79 inline int display_width(void) const
80 { return DisplayWidth(dpy, DefaultScreen(dpy)); };
82 void run(void);
84 private:
85 App();
86 App(const App & a);
88 Display * dpy;
89 WindowMap windows;
90 long event_mask;
91 Atom wm_delete_window; // Need this in contructor and run().
93 };