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