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