diff options
Diffstat (limited to 'src/FbTk/FbWindow.hh')
-rw-r--r-- | src/FbTk/FbWindow.hh | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh new file mode 100644 index 0000000..45928c0 --- /dev/null +++ b/src/FbTk/FbWindow.hh | |||
@@ -0,0 +1,178 @@ | |||
1 | // FbWindow.hh for FbTk - fluxbox toolkit | ||
2 | // Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: FbWindow.hh,v 1.17 2003/05/19 22:38:54 fluxgen Exp $ | ||
23 | |||
24 | #ifndef FBTK_FBWINDOW_HH | ||
25 | #define FBTK_FBWINDOW_HH | ||
26 | |||
27 | #include "FbDrawable.hh" | ||
28 | |||
29 | #include <X11/Xlib.h> | ||
30 | |||
31 | namespace FbTk { | ||
32 | |||
33 | class Color; | ||
34 | |||
35 | /// Wrapper for X window | ||
36 | /** | ||
37 | * Example: | ||
38 | * FbWindow window(0, 10, 10, 100, 100, ExposeMask | ButtonPressMask); \n | ||
39 | * this will create a window on screen 0, position 10 10, size 100 100 \n | ||
40 | * and with eventmask Expose and ButtonPress. \n | ||
41 | * You need to register it to some eventhandler so you can catch events: \n | ||
42 | * EventManager::instance()->add(your_eventhandler, window); \n | ||
43 | * @see EventHandler | ||
44 | * @see EventManager | ||
45 | */ | ||
46 | class FbWindow: public FbDrawable { | ||
47 | public: | ||
48 | FbWindow(); | ||
49 | |||
50 | FbWindow(const FbWindow &win_copy); | ||
51 | |||
52 | FbWindow(int screen_num, | ||
53 | int x, int y, unsigned int width, unsigned int height, long eventmask, | ||
54 | bool overrride_redirect = false, | ||
55 | int depth = CopyFromParent, | ||
56 | int class_type = InputOutput); | ||
57 | |||
58 | FbWindow(const FbWindow &parent, | ||
59 | int x, int y, | ||
60 | unsigned int width, unsigned int height, | ||
61 | long eventmask, | ||
62 | bool overrride_redirect = false, | ||
63 | int depth = CopyFromParent, | ||
64 | int class_type = InputOutput); | ||
65 | |||
66 | virtual ~FbWindow(); | ||
67 | void setBackgroundColor(const FbTk::Color &bg_color); | ||
68 | void setBackgroundPixmap(Pixmap bg_pixmap); | ||
69 | void setBorderColor(const FbTk::Color &border_color); | ||
70 | void setBorderWidth(unsigned int size); | ||
71 | /// set window name (title) | ||
72 | void setName(const char *name); | ||
73 | void setEventMask(long mask); | ||
74 | /// clear window with background pixmap or color | ||
75 | virtual void clear(); | ||
76 | /// assign a new X window to this | ||
77 | virtual FbWindow &operator = (Window win); | ||
78 | virtual void hide(); | ||
79 | virtual void show(); | ||
80 | virtual void showSubwindows(); | ||
81 | |||
82 | virtual void move(int x, int y); | ||
83 | virtual void resize(unsigned int width, unsigned int height); | ||
84 | virtual void moveResize(int x, int y, unsigned int width, unsigned int height); | ||
85 | virtual void lower(); | ||
86 | virtual void raise(); | ||
87 | |||
88 | /// defines a cursor for this window | ||
89 | void setCursor(Cursor cur); | ||
90 | /// uses the parents cursor instead | ||
91 | void unsetCursor(); | ||
92 | |||
93 | bool property(Atom property, | ||
94 | long long_offset, long long_length, | ||
95 | bool do_delete, | ||
96 | Atom req_type, | ||
97 | Atom *actual_type_return, | ||
98 | int *actual_format_return, | ||
99 | unsigned long *nitems_return, | ||
100 | unsigned long *bytes_after_return, | ||
101 | unsigned char **prop_return) const; | ||
102 | |||
103 | void changeProperty(Atom property, Atom type, | ||
104 | int format, | ||
105 | int mode, | ||
106 | unsigned char *data, | ||
107 | int nelements); | ||
108 | |||
109 | /// @return parent FbWindow | ||
110 | const FbWindow *parent() const { return m_parent; } | ||
111 | /// @return real X window | ||
112 | inline Window window() const { return m_window; } | ||
113 | /// @return drawable (the X window) | ||
114 | inline Drawable drawable() const { return window(); } | ||
115 | int x() const { return m_x; } | ||
116 | int y() const { return m_y; } | ||
117 | unsigned int width() const { return m_width; } | ||
118 | unsigned int height() const { return m_height; } | ||
119 | unsigned int borderWidth() const { return m_border_width; } | ||
120 | int depth() const { return m_depth; } | ||
121 | int screenNumber() const; | ||
122 | /// compare X window | ||
123 | bool operator == (Window win) const { return m_window == win; } | ||
124 | bool operator != (Window win) const { return m_window != win; } | ||
125 | /// compare two windows | ||
126 | bool operator == (const FbWindow &win) const { return m_window == win.m_window; } | ||
127 | bool operator != (const FbWindow &win) const { return m_window != win.m_window; } | ||
128 | |||
129 | protected: | ||
130 | /// creates a window with x window client (m_window = client) | ||
131 | explicit FbWindow(Window client); | ||
132 | /// updates x,y, width, height and screen num from X window | ||
133 | void updateGeometry(); | ||
134 | private: | ||
135 | /// sets new X window and destroys old | ||
136 | void setNew(Window win); | ||
137 | /// creates a new X window | ||
138 | void create(Window parent, int x, int y, unsigned int width, unsigned int height, | ||
139 | long eventmask, | ||
140 | bool override_redirect, | ||
141 | int depth, | ||
142 | int class_type); | ||
143 | static Display *s_display; ///< display connection | ||
144 | const FbWindow *m_parent; ///< parent FbWindow | ||
145 | int m_screen_num; ///< screen num on which this window exist | ||
146 | Window m_window; ///< the X window | ||
147 | int m_x, m_y; ///< position of window | ||
148 | unsigned int m_width, m_height; ///< size of window | ||
149 | unsigned int m_border_width; ///< border size | ||
150 | int m_depth; ///< bit depth | ||
151 | bool m_destroy; ///< wheter the x window was created before | ||
152 | }; | ||
153 | |||
154 | bool operator == (Window win, const FbWindow &fbwin); | ||
155 | |||
156 | /// helper class for some STL routines | ||
157 | class ChangeProperty { | ||
158 | public: | ||
159 | ChangeProperty(Display *disp, Atom prop, int mode, | ||
160 | unsigned char *state, int num):m_disp(disp), | ||
161 | m_prop(prop), m_state(state), m_num(num), m_mode(mode){ | ||
162 | |||
163 | } | ||
164 | void operator () (FbTk::FbWindow *win) { | ||
165 | XChangeProperty(m_disp, win->window(), m_prop, m_prop, 32, m_mode, | ||
166 | m_state, m_num); | ||
167 | } | ||
168 | private: | ||
169 | Display *m_disp; | ||
170 | Atom m_prop; | ||
171 | unsigned char *m_state; | ||
172 | int m_num; | ||
173 | int m_mode; | ||
174 | }; | ||
175 | |||
176 | }; // end namespace FbTk | ||
177 | |||
178 | #endif // FBTK_FBWINDOW_HH | ||