summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbWinFrame.cc119
-rw-r--r--src/FbWinFrame.hh28
2 files changed, 128 insertions, 19 deletions
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index caa6f8f..d467ccd 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbWinFrame.cc,v 1.1 2003/01/05 22:14:10 fluxgen Exp $ 22// $Id: FbWinFrame.cc,v 1.2 2003/01/07 01:30:57 fluxgen Exp $
23 23
24#include "FbWinFrame.hh" 24#include "FbWinFrame.hh"
25#include "ImageControl.hh" 25#include "ImageControl.hh"
@@ -62,7 +62,7 @@ FbWinFrame::FbWinFrame(FbWinFrameTheme &theme, BImageControl &imgctrl, int scree
62 m_clientwin(0), 62 m_clientwin(0),
63 m_bevel(1), 63 m_bevel(1),
64 m_use_titlebar(true), 64 m_use_titlebar(true),
65 m_use_handles(true), 65 m_use_handle(true),
66 m_button_pm(0) { 66 m_button_pm(0) {
67 init(); 67 init();
68} 68}
@@ -96,6 +96,23 @@ FbWinFrame::~FbWinFrame() {
96 96
97} 97}
98 98
99bool FbWinFrame::setOnClickTitlebar(FbTk::RefCount<FbTk::Command> &ref, int mousebutton_num,
100 bool double_click, bool pressed) {
101 // find mousebutton_num
102 if (mousebutton_num < 1 || mousebutton_num > 5)
103 return false;
104 if (double_click)
105 m_commands[mousebutton_num - 1].double_click = ref;
106 else {
107 if (pressed)
108 m_commands[mousebutton_num - 1].click_pressed = ref;
109 else
110 m_commands[mousebutton_num - 1].click = ref;
111 }
112
113 return true;
114}
115
99void FbWinFrame::hide() { 116void FbWinFrame::hide() {
100 m_window.hide(); 117 m_window.hide();
101} 118}
@@ -146,6 +163,10 @@ void FbWinFrame::resizeForClient(unsigned int width, unsigned int height) {
146 // total height for frame without client 163 // total height for frame without client
147 unsigned int total_height = m_handle.height() + m_titlebar.height(); 164 unsigned int total_height = m_handle.height() + m_titlebar.height();
148 // resize frame height with total height + specified height 165 // resize frame height with total height + specified height
166 if (!m_use_titlebar)
167 total_height -= m_titlebar.height();
168 if (!m_use_handle)
169 total_height -= m_handle.height();
149 resize(width, total_height + height); 170 resize(width, total_height + height);
150} 171}
151 172
@@ -167,6 +188,10 @@ void FbWinFrame::setFocus(bool newvalue) {
167 reconfigure(); // reconfigure rendering for new focus value 188 reconfigure(); // reconfigure rendering for new focus value
168} 189}
169 190
191void FbWinFrame::setDoubleClickTime(unsigned int time) {
192 m_double_click_time = time;
193}
194
170void FbWinFrame::setBevel(int bevel) { 195void FbWinFrame::setBevel(int bevel) {
171 m_bevel = bevel; 196 m_bevel = bevel;
172 reconfigure(); 197 reconfigure();
@@ -238,18 +263,41 @@ void FbWinFrame::removeClient() {
238 263
239void FbWinFrame::hideTitlebar() { 264void FbWinFrame::hideTitlebar() {
240 m_titlebar.hide(); 265 m_titlebar.hide();
266 m_use_titlebar = false;
241} 267}
242 268
243void FbWinFrame::showTitlebar() { 269void FbWinFrame::showTitlebar() {
244 m_titlebar.show(); 270 m_titlebar.show();
271 m_use_titlebar = true;
245} 272}
246 273
247void FbWinFrame::hideHandle() { 274void FbWinFrame::hideHandle() {
248 m_handle.hide(); 275 m_handle.hide();
276 m_grip_left.hide();
277 m_grip_right.hide();
278 m_use_handle = false;
249} 279}
250 280
251void FbWinFrame::showHandle() { 281void FbWinFrame::showHandle() {
252 m_handle.show(); 282 m_handle.show();
283 m_grip_left.show();
284 m_grip_right.show();
285 m_use_handle = true;
286}
287
288void FbWinFrame::hideAllDecorations() {
289 hideHandle();
290 hideTitlebar();
291 resizeForClient(m_clientarea.width(), m_clientarea.height() - m_window.borderWidth());
292 reconfigure();
293}
294
295void FbWinFrame::showAllDecorations() {
296 if (!m_use_handle)
297 showHandle();
298 if (!m_use_titlebar)
299 showTitlebar();
300 resizeForClient(m_clientarea.width(), m_clientarea.height() - m_window.borderWidth());
253} 301}
254 302
255/** 303/**
@@ -282,7 +330,37 @@ void FbWinFrame::removeEventHandler() {
282} 330}
283 331
284void FbWinFrame::buttonPressEvent(XButtonEvent &event) { 332void FbWinFrame::buttonPressEvent(XButtonEvent &event) {
285 m_window.raise(); 333 if (event.window != m_titlebar.window() &&
334 event.window != m_label.window())
335 return;
336
337 if (event.button > 5 || event.button < 1)
338 return;
339
340 if (*m_commands[event.button - 1].click_pressed) {
341 cerr<<"Pressed event button = "<<event.button<<endl;
342 m_commands[event.button - 1].click_pressed->execute();
343 }
344}
345
346void FbWinFrame::buttonReleaseEvent(XButtonEvent &event) {
347 if (event.window != m_titlebar.window() &&
348 event.window != m_label.window())
349 return;
350
351 if (event.button < 1 || event.button > 5)
352 return;
353
354 static int last_release_time = 0;
355 bool double_click = (event.time - last_release_time <= m_double_click_time);
356 last_release_time = event.time;
357 int real_button = event.button - 1;
358
359 if (double_click && *m_commands[real_button].double_click)
360 m_commands[real_button].double_click->execute();
361 else if (*m_commands[real_button].click)
362 m_commands[real_button].click->execute();
363
286} 364}
287 365
288void FbWinFrame::exposeEvent(XExposeEvent &event) { 366void FbWinFrame::exposeEvent(XExposeEvent &event) {
@@ -305,11 +383,22 @@ void FbWinFrame::reconfigure() {
305 m_window.clear(); 383 m_window.clear();
306 384
307 // align titlebar and render it 385 // align titlebar and render it
308 reconfigureTitlebar(); 386 if (m_use_titlebar)
387 reconfigureTitlebar();
388 // setup client area size/pos
389 int next_y = m_titlebar.height() + 2*m_titlebar.borderWidth();
390 unsigned int client_height = m_window.height() - m_titlebar.height() - m_handle.height();
391
392 if (!m_use_titlebar) {
393 next_y = 0;
394 if (!m_use_handle)
395 client_height = m_window.height();
396 else
397 client_height = m_window.height() - m_handle.height();
398 }
309 399
310 m_clientarea.moveResize(0, m_titlebar.height() + 2*m_titlebar.borderWidth(), 400 m_clientarea.moveResize(0, next_y,
311 m_window.width(), 401 m_window.width(), client_height);
312 m_window.height() - m_titlebar.height() - m_handle.height());
313 402
314 if (m_clientwin != 0) { 403 if (m_clientwin != 0) {
315 XMoveResizeWindow(FbTk::App::instance()->display(), m_clientwin, 404 XMoveResizeWindow(FbTk::App::instance()->display(), m_clientwin,
@@ -317,6 +406,9 @@ void FbWinFrame::reconfigure() {
317 m_clientarea.width(), m_clientarea.height()); 406 m_clientarea.width(), m_clientarea.height());
318 } 407 }
319 408
409 if (!m_use_handle) // no need to do anything more
410 return;
411
320 // align handle and grips 412 // align handle and grips
321 const int grip_height = m_handle.height(); 413 const int grip_height = m_handle.height();
322 const int grip_width = 20; //TODO 414 const int grip_width = 20; //TODO
@@ -336,7 +428,6 @@ void FbWinFrame::reconfigure() {
336 // render the theme 428 // render the theme
337 renderButtons(); 429 renderButtons();
338 renderHandles(); 430 renderHandles();
339
340} 431}
341 432
342unsigned int FbWinFrame::titleHeight() const { 433unsigned int FbWinFrame::titleHeight() const {
@@ -476,7 +567,7 @@ void FbWinFrame::renderTitlebar() {
476 567
477 568
478void FbWinFrame::renderHandles() { 569void FbWinFrame::renderHandles() {
479 if (!m_use_handles) 570 if (!m_use_handle)
480 return; 571 return;
481 render(m_theme.handleFocusTexture(), m_handle_focused_color, 572 render(m_theme.handleFocusTexture(), m_handle_focused_color,
482 m_handle_focused_pm, 573 m_handle_focused_pm,
@@ -559,7 +650,7 @@ void FbWinFrame::init() {
559 m_title_focused_pm = m_title_unfocused_pm = 0; 650 m_title_focused_pm = m_title_unfocused_pm = 0;
560 m_label_focused_pm = m_label_unfocused_pm = 0; 651 m_label_focused_pm = m_label_unfocused_pm = 0;
561 m_button_unfocused_pm = m_button_pressed_pm = 0; 652 m_button_unfocused_pm = m_button_pressed_pm = 0;
562 653 m_double_click_time = 200;
563 m_button_pm = 0; 654 m_button_pm = 0;
564 m_button_size = 26; 655 m_button_size = 26;
565 m_handle_focused_pm = 656 m_handle_focused_pm =
@@ -567,12 +658,10 @@ void FbWinFrame::init() {
567 m_grip_unfocused_pm = m_grip_focused_pm = 0; 658 m_grip_unfocused_pm = m_grip_focused_pm = 0;
568 659
569 m_shaded = false; 660 m_shaded = false;
570
571 m_label.show(); 661 m_label.show();
572 m_titlebar.show(); 662
573 m_handle.show(); 663 showHandle();
574 m_grip_right.show(); 664 showTitlebar();
575 m_grip_left.show();
576 // note: we don't show clientarea yet 665 // note: we don't show clientarea yet
577 666
578 setEventHandler(*this); 667 setEventHandler(*this);
diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh
index c74b73c..ba553cc 100644
--- a/src/FbWinFrame.hh
+++ b/src/FbWinFrame.hh
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbWinFrame.hh,v 1.1 2003/01/05 22:14:10 fluxgen Exp $ 22// $Id: FbWinFrame.hh,v 1.2 2003/01/07 01:28:16 fluxgen Exp $
23 23
24#ifndef FBWINFRAME_HH 24#ifndef FBWINFRAME_HH
25#define FBWINFRAME_HH 25#define FBWINFRAME_HH
@@ -30,14 +30,17 @@
30#include "Font.hh" 30#include "Font.hh"
31#include "Text.hh" 31#include "Text.hh"
32#include "FbWinFrameTheme.hh" 32#include "FbWinFrameTheme.hh"
33#include "RefCount.hh"
34#include "Command.hh"
33 35
34#include <vector> 36#include <vector>
35#include <string> 37#include <string>
36 38
39
37class FbWinFrameTheme; 40class FbWinFrameTheme;
38class BImageControl; 41class BImageControl;
39 42
40/// holds a window frame with a client window 43/// holds a window frame with a client window (see: <a href="fluxbox_fbwinframe.png">image</a>)
41class FbWinFrame:public FbTk::EventHandler { 44class FbWinFrame:public FbTk::EventHandler {
42public: 45public:
43 46
@@ -53,6 +56,10 @@ public:
53 /// destroy frame 56 /// destroy frame
54 ~FbWinFrame(); 57 ~FbWinFrame();
55 58
59 /// setup actions for titlebar
60 bool setOnClickTitlebar(FbTk::RefCount<FbTk::Command> &cmd, int button_num,
61 bool double_click=false, bool pressed=false);
62
56 void hide(); 63 void hide();
57 void show(); 64 void show();
58 /// shade frame (ie resize to titlebar size) 65 /// shade frame (ie resize to titlebar size)
@@ -66,6 +73,7 @@ public:
66 void setTitle(const std::string &title); 73 void setTitle(const std::string &title);
67 /// set focus/unfocus style 74 /// set focus/unfocus style
68 void setFocus(bool newvalue); 75 void setFocus(bool newvalue);
76 void setDoubleClickTime(unsigned int time);
69 void setBevel(int bevel); 77 void setBevel(int bevel);
70 /// add a button to the left of the label 78 /// add a button to the left of the label
71 void addLeftButton(FbTk::Button *btn); 79 void addLeftButton(FbTk::Button *btn);
@@ -88,12 +96,15 @@ public:
88 void showTitlebar(); 96 void showTitlebar();
89 void hideHandle(); 97 void hideHandle();
90 void showHandle(); 98 void showHandle();
99 void hideAllDecorations();
100 void showAllDecorations();
91 101
92 /** 102 /**
93 @name Event handlers 103 @name Event handlers
94 */ 104 */
95 //@{ 105 //@{
96 void buttonPressEvent(XButtonEvent &event); 106 void buttonPressEvent(XButtonEvent &event);
107 void buttonReleaseEvent(XButtonEvent &event);
97 void exposeEvent(XExposeEvent &event); 108 void exposeEvent(XExposeEvent &event);
98 void configureNotifyEvent(XConfigureEvent &event); 109 void configureNotifyEvent(XConfigureEvent &event);
99 void handleEvent(XEvent &event); 110 void handleEvent(XEvent &event);
@@ -128,7 +139,9 @@ public:
128 inline FbTk::FbWindow &gripRight() { return m_grip_right; } 139 inline FbTk::FbWindow &gripRight() { return m_grip_right; }
129 inline bool focused() const { return m_focused; } 140 inline bool focused() const { return m_focused; }
130 inline bool isShaded() const { return m_shaded; } 141 inline bool isShaded() const { return m_shaded; }
142 /// @return titlebar height
131 unsigned int titleHeight() const; 143 unsigned int titleHeight() const;
144 /// @return size of button
132 unsigned int buttonHeight() const; 145 unsigned int buttonHeight() const;
133 146
134 //@} 147 //@}
@@ -178,8 +191,9 @@ private:
178 std::string m_titletext; ///< text to be displayed int m_label 191 std::string m_titletext; ///< text to be displayed int m_label
179 int m_bevel; ///< bevel between titlebar items and titlebar 192 int m_bevel; ///< bevel between titlebar items and titlebar
180 bool m_use_titlebar; ///< if we should use titlebar 193 bool m_use_titlebar; ///< if we should use titlebar
181 bool m_use_handles; ///< if we should use handles 194 bool m_use_handle; ///< if we should use handle
182 bool m_focused; ///< focused/unfocused mode 195 bool m_focused; ///< focused/unfocused mode
196
183 /** 197 /**
184 @name pixmaps and colors for rendering 198 @name pixmaps and colors for rendering
185 */ 199 */
@@ -215,7 +229,13 @@ private:
215 unsigned int m_width_before_shade, ///< width before shade, so we can restore it when we unshade 229 unsigned int m_width_before_shade, ///< width before shade, so we can restore it when we unshade
216 m_height_before_shade; ///< height before shade, so we can restore it when we unshade 230 m_height_before_shade; ///< height before shade, so we can restore it when we unshade
217 bool m_shaded; ///< wheter we're shaded or not 231 bool m_shaded; ///< wheter we're shaded or not
218 232 unsigned int m_double_click_time; ///< the time period that's considerd to be a double click
233 struct MouseButtonAction {
234 FbTk::RefCount<FbTk::Command> click; ///< what to do when we release mouse button
235 FbTk::RefCount<FbTk::Command> click_pressed; ///< what to do when we press mouse button
236 FbTk::RefCount<FbTk::Command> double_click; ///< what to do when we double click
237 };
238 MouseButtonAction m_commands[5]; ///< hardcoded to five ...TODO, change this
219}; 239};
220 240
221#endif // FBWINFRAME_HH 241#endif // FBWINFRAME_HH