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