aboutsummaryrefslogtreecommitdiff
path: root/src/FbWinFrame.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbWinFrame.hh')
-rw-r--r--src/FbWinFrame.hh304
1 files changed, 304 insertions, 0 deletions
diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh
new file mode 100644
index 0000000..9c26903
--- /dev/null
+++ b/src/FbWinFrame.hh
@@ -0,0 +1,304 @@
1// FbWinFrame.hh for Fluxbox Window Manager
2// Copyright (c) 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: FbWinFrame.hh,v 1.24 2003/10/28 02:17:02 rathnor Exp $
23
24#ifndef FBWINFRAME_HH
25#define FBWINFRAME_HH
26
27#include "FbTk/FbWindow.hh"
28#include "FbTk/EventHandler.hh"
29#include "FbTk/RefCount.hh"
30#include "FbTk/Observer.hh"
31#include "FbTk/Color.hh"
32#include "FbTk/FbPixmap.hh"
33#include "FbTk/Timer.hh"
34
35#include <vector>
36#include <list>
37#include <string>
38#include <memory>
39
40class Shape;
41class FbWinFrameTheme;
42
43namespace FbTk {
44class TextButton;
45class ImageControl;
46class Command;
47class Button;
48class Texture;
49};
50
51/// holds a window frame with a client window
52/// (see: <a href="fluxbox_fbwinframe.png">image</a>)
53class FbWinFrame:public FbTk::EventHandler {
54public:
55
56 /// create a top level window
57 FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl,
58 int screen_num, int x, int y,
59 unsigned int width, unsigned int height);
60
61 /// create a frame window inside another FbWindow, NOT IMPLEMENTED!
62 FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl,
63 const FbTk::FbWindow &parent,
64 int x, int y,
65 unsigned int width, unsigned int height);
66
67 /// destroy frame
68 ~FbWinFrame();
69
70 /// setup actions for titlebar
71 bool setOnClickTitlebar(FbTk::RefCount<FbTk::Command> &cmd, int button_num,
72 bool double_click=false, bool pressed=false);
73
74 void hide();
75 void show();
76 inline bool isVisible() const { return m_visible; }
77 /// shade frame (ie resize to titlebar size)
78 void shade();
79 void move(int x, int y);
80 void resize(unsigned int width, unsigned int height);
81 /// resize client to specified size and resize frame to it
82 void resizeForClient(unsigned int width, unsigned int height);
83
84 // for when there needs to be an atomic move+resize operation
85 void moveResizeForClient(int x, int y, unsigned int width, unsigned int height, bool move = true, bool resize = true);
86
87 // can elect to ignore move or resize (mainly for use of move/resize individual functions
88 void moveResize(int x, int y, unsigned int width, unsigned int height, bool move = true, bool resize = true);
89
90 /// set focus/unfocus style
91 void setFocus(bool newvalue);
92 void setDoubleClickTime(unsigned int time);
93
94 /// add a button to the left of the label
95 void addLeftButton(FbTk::Button *btn);
96 /// add a button to the right of the label
97 void addRightButton(FbTk::Button *btn);
98 /// remove all buttons from titlebar
99 void removeAllButtons();
100 /// adds a button to label window
101 void addLabelButton(FbTk::TextButton &btn);
102 /// removes a specific button from label window
103 void removeLabelButton(FbTk::TextButton &btn);
104 /// move label button to the left
105 void moveLabelButtonLeft(const FbTk::TextButton &btn);
106 /// move label button to the right
107 void moveLabelButtonRight(const FbTk::TextButton &btn);
108 /// which button is to be rendered focused
109 void setLabelButtonFocus(FbTk::TextButton &btn);
110 /// attach a client window for client area
111 void setClientWindow(Window win);
112 /// same as above but with FbWindow
113 void setClientWindow(FbTk::FbWindow &win);
114 /// remove attached client window
115 void removeClient();
116 /// redirect events to another eventhandler
117 void setEventHandler(FbTk::EventHandler &evh);
118 /// remove any handler for the windows
119 void removeEventHandler();
120
121 // these return true/false for if something changed
122 bool hideTitlebar();
123 bool showTitlebar();
124 bool hideHandle();
125 bool showHandle();
126 bool hideAllDecorations();
127 bool showAllDecorations();
128
129 // this function translates its arguments according to win_gravity
130 // if win_gravity is negative, it does an inverse translation
131 void gravityTranslate(int &x, int &y, int win_gravity, bool move_frame = false);
132
133 void setBorderWidth(unsigned int borderW);
134
135 /**
136 @name Event handlers
137 */
138 //@{
139 void buttonPressEvent(XButtonEvent &event);
140 void buttonReleaseEvent(XButtonEvent &event);
141 void exposeEvent(XExposeEvent &event);
142 void configureNotifyEvent(XConfigureEvent &event);
143 void handleEvent(XEvent &event);
144 //@}
145
146 void reconfigure();
147 void setUseShape(bool value);
148
149 void setUpdateDelayTime(long t) { m_update_timer.setTimeout(t); }
150
151 /**
152 @name accessors
153 */
154 //@{
155 inline int x() const { return m_window.x(); }
156 inline int y() const { return m_window.y(); }
157 inline unsigned int width() const { return m_window.width(); }
158 inline unsigned int height() const { return m_window.height(); }
159 inline const FbTk::FbWindow &window() const { return m_window; }
160 inline FbTk::FbWindow &window() { return m_window; }
161 /// @return titlebar window
162 inline const FbTk::FbWindow &titlebar() const { return m_titlebar; }
163 inline FbTk::FbWindow &titlebar() { return m_titlebar; }
164 inline const FbTk::FbWindow &label() const { return m_label; }
165 inline FbTk::FbWindow &label() { return m_label; }
166 /// @return clientarea window
167 inline const FbTk::FbWindow &clientArea() const { return m_clientarea; }
168 inline FbTk::FbWindow &clientArea() { return m_clientarea; }
169 /// @return handle window
170 inline const FbTk::FbWindow &handle() const { return m_handle; }
171 inline FbTk::FbWindow &handle() { return m_handle; }
172 inline const FbTk::FbWindow &gripLeft() const { return m_grip_left; }
173 inline FbTk::FbWindow &gripLeft() { return m_grip_left; }
174 inline const FbTk::FbWindow &gripRight() const { return m_grip_right; }
175 inline FbTk::FbWindow &gripRight() { return m_grip_right; }
176 inline const FbTk::TextButton *currentLabel() const { return m_current_label; }
177 inline bool focused() const { return m_focused; }
178 inline bool isShaded() const { return m_shaded; }
179 inline const FbWinFrameTheme &theme() const { return m_theme; }
180 /// @return titlebar height
181 unsigned int titlebarHeight() const { return m_titlebar.height(); }
182 /// @return size of button
183 unsigned int buttonHeight() const;
184
185 //@}
186
187private:
188 void redrawTitlebar();
189 void redrawTitle();
190
191 /// reposition titlebar items
192 void reconfigureTitlebar();
193 /**
194 @name render helper functions
195 */
196 //@{
197 void renderTitlebar();
198 void renderHandles();
199 void renderButtons();
200 void renderButtonFocus(FbTk::TextButton &button);
201 void renderButtonUnfocus(FbTk::TextButton &button);
202 void renderLabel();
203 /// renders to pixmap or sets color
204 void render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm,
205 unsigned int width, unsigned int height);
206 void getUnfocusPixmap(Pixmap &label_pm, Pixmap &title_pm,
207 FbTk::Color &label_color, FbTk::Color &title_color);
208 void getCurrentFocusPixmap(Pixmap &label_pm, Pixmap &title_pm,
209 FbTk::Color &label_color, FbTk::Color &title_color);
210 void renderLabelButtons();
211 //@}
212
213 /// initiate some commont variables
214 void init();
215 /// initiate inserted buttons for current theme
216 void setupButton(FbTk::Button &btn);
217 void updateTransparent();
218
219 FbWinFrameTheme &m_theme; ///< theme to be used
220 FbTk::ImageControl &m_imagectrl; ///< Image control for rendering
221 /**
222 @name windows
223 */
224 //@{
225 FbTk::FbWindow m_window; ///< base window that holds each decorations (ie titlebar, handles)
226 FbTk::FbWindow m_titlebar; ///< titlebar window
227 FbTk::FbWindow m_label; ///< holds title
228 FbTk::FbWindow m_handle; ///< handle between grips
229 FbTk::FbWindow m_grip_right, ///< rightgrip
230 m_grip_left; ///< left grip
231 FbTk::FbWindow m_clientarea; ///< window that sits behind client window to fill gaps @see setClientWindow
232 //@}
233 typedef std::vector<FbTk::Button *> ButtonList;
234 ButtonList m_buttons_left, ///< buttons to the left
235 m_buttons_right; ///< buttons to the right
236 typedef std::list<FbTk::TextButton *> LabelList;
237 LabelList m_labelbuttons; ///< holds label buttons inside label window
238 FbTk::TextButton *m_current_label; ///< which client button is focused at the moment
239 std::string m_titletext; ///< text to be displayed int m_label
240 int m_bevel; ///< bevel between titlebar items and titlebar
241 bool m_use_titlebar; ///< if we should use titlebar
242 bool m_use_handle; ///< if we should use handle
243 bool m_focused; ///< focused/unfocused mode
244 bool m_visible; ///< if we are currently showing
245
246 /**
247 @name pixmaps and colors for rendering
248 */
249 //@{
250 Pixmap m_title_focused_pm; ///< pixmap for focused title
251 FbTk::Color m_title_focused_color; ///< color for focused title
252 Pixmap m_title_unfocused_pm; ///< pixmap for unfocused title
253 FbTk::Color m_title_unfocused_color; ///< color for unfocued title
254
255 Pixmap m_label_focused_pm; ///< pixmap for focused label
256 FbTk::Color m_label_focused_color; ///< color for focused label
257 Pixmap m_label_unfocused_pm; ///< pixmap for unfocused label
258 FbTk::Color m_label_unfocused_color; ///< color for unfocued label
259
260 FbTk::Color m_handle_focused_color, m_handle_unfocused_color;
261 Pixmap m_handle_focused_pm, m_handle_unfocused_pm;
262
263
264 Pixmap m_button_pm; ///< normal button
265 FbTk::Color m_button_color; ///< normal color button
266 Pixmap m_button_unfocused_pm; ///< unfocused button
267 FbTk::Color m_button_unfocused_color; ///< unfocused color button
268 Pixmap m_button_pressed_pm; ///< pressed button
269 FbTk::Color m_button_pressed_color; ///< pressed button color
270
271 Pixmap m_grip_focused_pm;
272 FbTk::Color m_grip_focused_color; ///< if no pixmap is given for grip, use this color
273 Pixmap m_grip_unfocused_pm; ///< unfocused pixmap for grip
274 FbTk::Color m_grip_unfocused_color; ///< unfocused color for grip if no pixmap is given
275 //@}
276
277 int m_button_size; ///< size for all titlebar buttons
278 unsigned int m_width_before_shade, ///< width before shade, so we can restore it when we unshade
279 m_height_before_shade; ///< height before shade, so we can restore it when we unshade
280 bool m_shaded; ///< wheter we're shaded or not
281 unsigned int m_double_click_time; ///< the time period that's considerd to be a double click
282 struct MouseButtonAction {
283 FbTk::RefCount<FbTk::Command> click; ///< what to do when we release mouse button
284 FbTk::RefCount<FbTk::Command> click_pressed; ///< what to do when we press mouse button
285 FbTk::RefCount<FbTk::Command> double_click; ///< what to do when we double click
286 };
287 MouseButtonAction m_commands[5]; ///< hardcoded to five ... //!! TODO, change this
288
289 class ThemeListener: public FbTk::Observer {
290 public:
291 ThemeListener(FbWinFrame &frame):m_frame(frame) { }
292 void update(FbTk::Subject *subj) {
293 m_frame.reconfigure();
294 }
295 private:
296 FbWinFrame &m_frame;
297 };
298 ThemeListener m_themelistener;
299 std::auto_ptr<Shape> m_shape;
300 bool m_disable_shape;
301 FbTk::Timer m_update_timer;
302};
303
304#endif // FBWINFRAME_HH