aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbWindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FbWindow.cc')
-rw-r--r--src/FbTk/FbWindow.cc277
1 files changed, 277 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc
new file mode 100644
index 0000000..722b414
--- /dev/null
+++ b/src/FbTk/FbWindow.cc
@@ -0,0 +1,277 @@
1// FbWindow.cc 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.cc,v 1.20 2003/05/19 22:38:55 fluxgen Exp $
23
24#include "FbWindow.hh"
25#include "EventManager.hh"
26
27#include "Color.hh"
28#include "App.hh"
29
30#include <cassert>
31
32namespace FbTk {
33
34Display *FbWindow::s_display = 0;
35
36FbWindow::FbWindow():m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),
37 m_width(0), m_height(0), m_border_width(0), m_depth(0), m_destroy(true) {
38
39 if (s_display == 0)
40 s_display = App::instance()->display();
41}
42
43FbWindow::FbWindow(int screen_num,
44 int x, int y,
45 unsigned int width, unsigned int height,
46 long eventmask,
47 bool override_redirect,
48 int depth,
49 int class_type):
50 m_screen_num(screen_num),
51 m_parent(0), m_destroy(true) {
52
53 create(RootWindow(FbTk::App::instance()->display(), screen_num),
54 x, y, width, height, eventmask,
55 override_redirect, depth, class_type);
56};
57
58FbWindow::FbWindow(const FbWindow &parent,
59 int x, int y, unsigned int width, unsigned int height,
60 long eventmask,
61 bool override_redirect,
62 int depth, int class_type):
63 m_parent(&parent),
64 m_screen_num(parent.screenNumber()), m_destroy(true) {
65
66 create(parent.window(), x, y, width, height, eventmask,
67 override_redirect, depth, class_type);
68
69
70};
71
72FbWindow::FbWindow(Window client):m_parent(0), m_window(0),
73 m_screen_num(0),
74 m_destroy(false) { // don't destroy this window
75
76 setNew(client);
77}
78
79FbWindow::~FbWindow() {
80
81 if (m_window != 0) {
82 // so we don't get any dangling eventhandler for this window
83 FbTk::EventManager::instance()->remove(m_window);
84 if (m_destroy)
85 XDestroyWindow(s_display, m_window);
86 }
87}
88
89
90void FbWindow::setBackgroundColor(const FbTk::Color &bg_color) {
91 XSetWindowBackground(s_display, m_window, bg_color.pixel());
92}
93
94void FbWindow::setBackgroundPixmap(Pixmap bg_pixmap) {
95 XSetWindowBackgroundPixmap(s_display, m_window, bg_pixmap);
96}
97
98void FbWindow::setBorderColor(const FbTk::Color &border_color) {
99 XSetWindowBorder(s_display, m_window, border_color.pixel());
100}
101void FbWindow::setBorderWidth(unsigned int size) {
102 XSetWindowBorderWidth(s_display, m_window, size);
103 m_border_width = size;
104}
105
106void FbWindow::setName(const char *name) {
107 XStoreName(s_display, m_window, name);
108}
109
110void FbWindow::setEventMask(long mask) {
111 XSelectInput(s_display, m_window, mask);
112}
113
114void FbWindow::clear() {
115 XClearWindow(s_display, m_window);
116}
117
118FbWindow &FbWindow::operator = (Window win) {
119 setNew(win);
120 return *this;
121}
122
123void FbWindow::setNew(Window win) {
124 if (s_display == 0)
125 s_display = App::instance()->display();
126
127 if (m_window != 0 && m_destroy)
128 XDestroyWindow(s_display, m_window);
129 m_window = win;
130 if (m_window != 0) {
131 updateGeometry();
132 XWindowAttributes attr;
133 attr.screen = 0;
134 //get screen number
135 if (XGetWindowAttributes(s_display,
136 m_window,
137 &attr) != 0 && attr.screen != 0) {
138 m_screen_num = XScreenNumberOfScreen(attr.screen);
139 }
140 }
141}
142
143void FbWindow::show() {
144 XMapWindow(s_display, m_window);
145}
146
147void FbWindow::showSubwindows() {
148 XMapSubwindows(s_display, m_window);
149}
150
151void FbWindow::hide() {
152 XUnmapWindow(s_display, m_window);
153}
154
155void FbWindow::move(int x, int y) {
156 XMoveWindow(s_display, m_window, x, y);
157 m_x = x;
158 m_y = y;
159}
160
161void FbWindow::resize(unsigned int width, unsigned int height) {
162 XResizeWindow(s_display, m_window, width, height);
163 m_width = width;
164 m_height = height;
165}
166
167void FbWindow::moveResize(int x, int y, unsigned int width, unsigned int height) {
168 XMoveResizeWindow(s_display, m_window, x, y, width, height);
169 m_x = x;
170 m_y = y;
171 m_width = width;
172 m_height = height;
173}
174
175void FbWindow::lower() {
176 XLowerWindow(s_display, m_window);
177}
178
179void FbWindow::raise() {
180 XRaiseWindow(s_display, m_window);
181}
182
183void FbWindow::setCursor(Cursor cur) {
184 XDefineCursor(s_display, window(), cur);
185}
186
187void FbWindow::unsetCursor() {
188 XUndefineCursor(s_display, window());
189}
190
191
192bool FbWindow::property(Atom property,
193 long long_offset, long long_length,
194 bool do_delete,
195 Atom req_type,
196 Atom *actual_type_return,
197 int *actual_format_return,
198 unsigned long *nitems_return,
199 unsigned long *bytes_after_return,
200 unsigned char **prop_return) const {
201 if (XGetWindowProperty(s_display, window(),
202 property, long_offset, long_length, do_delete,
203 req_type, actual_type_return,
204 actual_format_return, nitems_return,
205 bytes_after_return, prop_return) == Success)
206 return true;
207
208 return false;
209}
210
211void FbWindow::changeProperty(Atom property, Atom type,
212 int format,
213 int mode,
214 unsigned char *data,
215 int nelements) {
216
217 XChangeProperty(s_display, m_window, property, type,
218 format, mode,
219 data, nelements);
220}
221
222int FbWindow::screenNumber() const {
223 return m_screen_num;
224}
225
226void FbWindow::updateGeometry() {
227 if (m_window == 0)
228 return;
229
230 Window root;
231 unsigned int border_width, depth;
232 XGetGeometry(s_display, m_window, &root, &m_x, &m_y,
233 (unsigned int *)&m_width, (unsigned int *)&m_height,
234 &border_width, &depth);
235 m_depth = depth;
236}
237
238void FbWindow::create(Window parent, int x, int y,
239 unsigned int width, unsigned int height,
240 long eventmask, bool override_redirect,
241 int depth, int class_type) {
242
243
244 if (s_display == 0)
245 s_display = FbTk::App::instance()->display();
246
247 assert(s_display);
248
249 m_border_width = 0;
250
251 long valmask = CWEventMask;
252 XSetWindowAttributes values;
253 values.event_mask = eventmask;
254
255 if (override_redirect) {
256 valmask |= CWOverrideRedirect;
257 values.override_redirect = True;
258 }
259
260 m_window = XCreateWindow(s_display, parent, x, y, width, height,
261 0, // border width
262 depth, // depth
263 class_type, // class
264 CopyFromParent, // visual
265 valmask, // create mask
266 &values); // create atrribs
267
268 assert(m_window);
269
270 updateGeometry();
271}
272
273bool operator == (Window win, const FbWindow &fbwin) {
274 return win == fbwin.window();
275}
276
277};