aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbWindow.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FbWindow.hh')
-rw-r--r--src/FbTk/FbWindow.hh212
1 files changed, 212 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh
new file mode 100644
index 0000000..499d3ad
--- /dev/null
+++ b/src/FbTk/FbWindow.hh
@@ -0,0 +1,212 @@
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.27 2003/12/30 17:17:05 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#include <memory>
31
32
33namespace FbTk {
34
35class Color;
36class Transparent;
37
38/// Wrapper for X window
39/**
40 * Example:
41 * FbWindow window(0, 10, 10, 100, 100, ExposeMask | ButtonPressMask); \n
42 * this will create a window on screen 0, position 10 10, size 100 100 \n
43 * and with eventmask Expose and ButtonPress. \n
44 * You need to register it to some eventhandler so you can catch events: \n
45 * EventManager::instance()->add(your_eventhandler, window); \n
46 * @see EventHandler
47 * @see EventManager
48 */
49class FbWindow: public FbDrawable {
50public:
51 FbWindow();
52
53 FbWindow(const FbWindow &win_copy);
54
55 FbWindow(int screen_num,
56 int x, int y, unsigned int width, unsigned int height, long eventmask,
57 bool overrride_redirect = false,
58 int depth = CopyFromParent,
59 int class_type = InputOutput);
60
61 FbWindow(const FbWindow &parent,
62 int x, int y,
63 unsigned int width, unsigned int height,
64 long eventmask,
65 bool overrride_redirect = false,
66 int depth = CopyFromParent,
67 int class_type = InputOutput);
68
69 virtual ~FbWindow();
70 virtual void setBackgroundColor(const FbTk::Color &bg_color);
71 virtual void setBackgroundPixmap(Pixmap bg_pixmap);
72 virtual void setBorderColor(const FbTk::Color &border_color);
73 virtual void setBorderWidth(unsigned int size);
74 /// set window name ("title")
75 void setName(const char *name);
76 void setEventMask(long mask);
77 /// clear window with background pixmap or color
78 virtual void clear();
79 /// @param exposures wheter Expose event should be generated
80 virtual void clearArea(int x, int y,
81 unsigned int width, unsigned int height,
82 bool exposures = false);
83 void updateTransparent(int x = -1, int y = -1, unsigned int width = 0, unsigned int height = 0);
84
85 void setAlpha(unsigned char alpha);
86
87 virtual FbWindow &operator = (const FbWindow &win);
88 /// assign a new X window to this
89 virtual FbWindow &operator = (Window win);
90 virtual void hide();
91 virtual void show();
92 virtual void showSubwindows();
93
94 virtual inline void move(int x, int y) {
95 XMoveWindow(s_display, m_window, x, y);
96 m_x = x;
97 m_y = y;
98 }
99
100 virtual inline void resize(unsigned int width, unsigned int height) {
101 XResizeWindow(s_display, m_window, width, height);
102 m_width = width;
103 m_height = height;
104 }
105
106 virtual inline void moveResize(int x, int y, unsigned int width, unsigned int height) {
107 XMoveResizeWindow(s_display, m_window, x, y, width, height);
108 m_x = x;
109 m_y = y;
110 m_width = width;
111 m_height = height;
112 }
113 virtual void lower();
114 virtual void raise();
115 void setInputFocus(int revert_to, int time);
116 /// defines a cursor for this window
117 void setCursor(Cursor cur);
118 /// uses the parents cursor instead
119 void unsetCursor();
120 void reparent(const FbWindow &parent, int x, int y);
121
122 bool property(Atom property,
123 long long_offset, long long_length,
124 bool do_delete,
125 Atom req_type,
126 Atom *actual_type_return,
127 int *actual_format_return,
128 unsigned long *nitems_return,
129 unsigned long *bytes_after_return,
130 unsigned char **prop_return) const;
131
132 void changeProperty(Atom property, Atom type,
133 int format,
134 int mode,
135 unsigned char *data,
136 int nelements);
137
138 /// @return parent FbWindow
139 const FbWindow *parent() const { return m_parent; }
140 /// @return real X window
141 inline Window window() const { return m_window; }
142 /// @return drawable (the X window)
143 inline Drawable drawable() const { return window(); }
144 int x() const { return m_x; }
145 int y() const { return m_y; }
146 unsigned int width() const { return m_width; }
147 unsigned int height() const { return m_height; }
148 unsigned int borderWidth() const { return m_border_width; }
149 int depth() const { return m_depth; }
150 int screenNumber() const;
151 long eventMask() const;
152 /// compare X window
153 bool operator == (Window win) const { return m_window == win; }
154 bool operator != (Window win) const { return m_window != win; }
155 /// compare two windows
156 bool operator == (const FbWindow &win) const { return m_window == win.m_window; }
157 bool operator != (const FbWindow &win) const { return m_window != win.m_window; }
158
159protected:
160 /// creates a window with x window client (m_window = client)
161 explicit FbWindow(Window client);
162 void setBufferPixmap(Pixmap pm);
163 /// updates x,y, width, height and screen num from X window
164 void updateGeometry();
165private:
166 /// sets new X window and destroys old
167 void setNew(Window win);
168 /// creates a new X window
169 void create(Window parent, int x, int y, unsigned int width, unsigned int height,
170 long eventmask,
171 bool override_redirect,
172 int depth,
173 int class_type);
174 static Display *s_display; ///< display connection
175 const FbWindow *m_parent; ///< parent FbWindow
176 int m_screen_num; ///< screen num on which this window exist
177 mutable Window m_window; ///< the X window
178 int m_x, m_y; ///< position of window
179 unsigned int m_width, m_height; ///< size of window
180 unsigned int m_border_width; ///< border size
181 int m_depth; ///< bit depth
182 bool m_destroy; ///< wheter the x window was created before
183 std::auto_ptr<FbTk::Transparent> m_transparent;
184 Pixmap m_buffer_pm;
185};
186
187bool operator == (Window win, const FbWindow &fbwin);
188
189/// helper class for some STL routines
190class ChangeProperty {
191public:
192 ChangeProperty(Display *disp, Atom prop, int mode,
193 unsigned char *state, int num):m_disp(disp),
194 m_prop(prop), m_state(state), m_num(num), m_mode(mode){
195
196 }
197 void operator () (FbTk::FbWindow *win) {
198 XChangeProperty(m_disp, win->window(), m_prop, m_prop, 32, m_mode,
199 m_state, m_num);
200 }
201private:
202 Display *m_disp;
203 Atom m_prop;
204 unsigned char *m_state;
205 int m_num;
206 int m_mode;
207
208};
209
210} // end namespace FbTk
211
212#endif // FBTK_FBWINDOW_HH