From 06f63eec84fa37e0832fee0432cd398f55f7aeba Mon Sep 17 00:00:00 2001 From: fluxgen Date: Tue, 7 Jan 2003 01:30:57 +0000 Subject: added double click interval, fixed actions on titlebar, added hide/show decorations --- src/FbWinFrame.cc | 119 +++++++++++++++++++++++++++++++++++++++++++++++------- src/FbWinFrame.hh | 28 +++++++++++-- 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWinFrame.cc,v 1.1 2003/01/05 22:14:10 fluxgen Exp $ +// $Id: FbWinFrame.cc,v 1.2 2003/01/07 01:30:57 fluxgen Exp $ #include "FbWinFrame.hh" #include "ImageControl.hh" @@ -62,7 +62,7 @@ FbWinFrame::FbWinFrame(FbWinFrameTheme &theme, BImageControl &imgctrl, int scree m_clientwin(0), m_bevel(1), m_use_titlebar(true), - m_use_handles(true), + m_use_handle(true), m_button_pm(0) { init(); } @@ -96,6 +96,23 @@ FbWinFrame::~FbWinFrame() { } +bool FbWinFrame::setOnClickTitlebar(FbTk::RefCount &ref, int mousebutton_num, + bool double_click, bool pressed) { + // find mousebutton_num + if (mousebutton_num < 1 || mousebutton_num > 5) + return false; + if (double_click) + m_commands[mousebutton_num - 1].double_click = ref; + else { + if (pressed) + m_commands[mousebutton_num - 1].click_pressed = ref; + else + m_commands[mousebutton_num - 1].click = ref; + } + + return true; +} + void FbWinFrame::hide() { m_window.hide(); } @@ -146,6 +163,10 @@ void FbWinFrame::resizeForClient(unsigned int width, unsigned int height) { // total height for frame without client unsigned int total_height = m_handle.height() + m_titlebar.height(); // resize frame height with total height + specified height + if (!m_use_titlebar) + total_height -= m_titlebar.height(); + if (!m_use_handle) + total_height -= m_handle.height(); resize(width, total_height + height); } @@ -167,6 +188,10 @@ void FbWinFrame::setFocus(bool newvalue) { reconfigure(); // reconfigure rendering for new focus value } +void FbWinFrame::setDoubleClickTime(unsigned int time) { + m_double_click_time = time; +} + void FbWinFrame::setBevel(int bevel) { m_bevel = bevel; reconfigure(); @@ -238,18 +263,41 @@ void FbWinFrame::removeClient() { void FbWinFrame::hideTitlebar() { m_titlebar.hide(); + m_use_titlebar = false; } void FbWinFrame::showTitlebar() { m_titlebar.show(); + m_use_titlebar = true; } void FbWinFrame::hideHandle() { m_handle.hide(); + m_grip_left.hide(); + m_grip_right.hide(); + m_use_handle = false; } void FbWinFrame::showHandle() { m_handle.show(); + m_grip_left.show(); + m_grip_right.show(); + m_use_handle = true; +} + +void FbWinFrame::hideAllDecorations() { + hideHandle(); + hideTitlebar(); + resizeForClient(m_clientarea.width(), m_clientarea.height() - m_window.borderWidth()); + reconfigure(); +} + +void FbWinFrame::showAllDecorations() { + if (!m_use_handle) + showHandle(); + if (!m_use_titlebar) + showTitlebar(); + resizeForClient(m_clientarea.width(), m_clientarea.height() - m_window.borderWidth()); } /** @@ -282,7 +330,37 @@ void FbWinFrame::removeEventHandler() { } void FbWinFrame::buttonPressEvent(XButtonEvent &event) { - m_window.raise(); + if (event.window != m_titlebar.window() && + event.window != m_label.window()) + return; + + if (event.button > 5 || event.button < 1) + return; + + if (*m_commands[event.button - 1].click_pressed) { + cerr<<"Pressed event button = "<execute(); + } +} + +void FbWinFrame::buttonReleaseEvent(XButtonEvent &event) { + if (event.window != m_titlebar.window() && + event.window != m_label.window()) + return; + + if (event.button < 1 || event.button > 5) + return; + + static int last_release_time = 0; + bool double_click = (event.time - last_release_time <= m_double_click_time); + last_release_time = event.time; + int real_button = event.button - 1; + + if (double_click && *m_commands[real_button].double_click) + m_commands[real_button].double_click->execute(); + else if (*m_commands[real_button].click) + m_commands[real_button].click->execute(); + } void FbWinFrame::exposeEvent(XExposeEvent &event) { @@ -305,11 +383,22 @@ void FbWinFrame::reconfigure() { m_window.clear(); // align titlebar and render it - reconfigureTitlebar(); + if (m_use_titlebar) + reconfigureTitlebar(); + // setup client area size/pos + int next_y = m_titlebar.height() + 2*m_titlebar.borderWidth(); + unsigned int client_height = m_window.height() - m_titlebar.height() - m_handle.height(); + + if (!m_use_titlebar) { + next_y = 0; + if (!m_use_handle) + client_height = m_window.height(); + else + client_height = m_window.height() - m_handle.height(); + } - m_clientarea.moveResize(0, m_titlebar.height() + 2*m_titlebar.borderWidth(), - m_window.width(), - m_window.height() - m_titlebar.height() - m_handle.height()); + m_clientarea.moveResize(0, next_y, + m_window.width(), client_height); if (m_clientwin != 0) { XMoveResizeWindow(FbTk::App::instance()->display(), m_clientwin, @@ -317,6 +406,9 @@ void FbWinFrame::reconfigure() { m_clientarea.width(), m_clientarea.height()); } + if (!m_use_handle) // no need to do anything more + return; + // align handle and grips const int grip_height = m_handle.height(); const int grip_width = 20; //TODO @@ -336,7 +428,6 @@ void FbWinFrame::reconfigure() { // render the theme renderButtons(); renderHandles(); - } unsigned int FbWinFrame::titleHeight() const { @@ -476,7 +567,7 @@ void FbWinFrame::renderTitlebar() { void FbWinFrame::renderHandles() { - if (!m_use_handles) + if (!m_use_handle) return; render(m_theme.handleFocusTexture(), m_handle_focused_color, m_handle_focused_pm, @@ -559,7 +650,7 @@ void FbWinFrame::init() { m_title_focused_pm = m_title_unfocused_pm = 0; m_label_focused_pm = m_label_unfocused_pm = 0; m_button_unfocused_pm = m_button_pressed_pm = 0; - + m_double_click_time = 200; m_button_pm = 0; m_button_size = 26; m_handle_focused_pm = @@ -567,12 +658,10 @@ void FbWinFrame::init() { m_grip_unfocused_pm = m_grip_focused_pm = 0; m_shaded = false; - m_label.show(); - m_titlebar.show(); - m_handle.show(); - m_grip_right.show(); - m_grip_left.show(); + + showHandle(); + showTitlebar(); // note: we don't show clientarea yet 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWinFrame.hh,v 1.1 2003/01/05 22:14:10 fluxgen Exp $ +// $Id: FbWinFrame.hh,v 1.2 2003/01/07 01:28:16 fluxgen Exp $ #ifndef FBWINFRAME_HH #define FBWINFRAME_HH @@ -30,14 +30,17 @@ #include "Font.hh" #include "Text.hh" #include "FbWinFrameTheme.hh" +#include "RefCount.hh" +#include "Command.hh" #include #include + class FbWinFrameTheme; class BImageControl; -/// holds a window frame with a client window +/// holds a window frame with a client window (see: image) class FbWinFrame:public FbTk::EventHandler { public: @@ -53,6 +56,10 @@ public: /// destroy frame ~FbWinFrame(); + /// setup actions for titlebar + bool setOnClickTitlebar(FbTk::RefCount &cmd, int button_num, + bool double_click=false, bool pressed=false); + void hide(); void show(); /// shade frame (ie resize to titlebar size) @@ -66,6 +73,7 @@ public: void setTitle(const std::string &title); /// set focus/unfocus style void setFocus(bool newvalue); + void setDoubleClickTime(unsigned int time); void setBevel(int bevel); /// add a button to the left of the label void addLeftButton(FbTk::Button *btn); @@ -88,12 +96,15 @@ public: void showTitlebar(); void hideHandle(); void showHandle(); + void hideAllDecorations(); + void showAllDecorations(); /** @name Event handlers */ //@{ void buttonPressEvent(XButtonEvent &event); + void buttonReleaseEvent(XButtonEvent &event); void exposeEvent(XExposeEvent &event); void configureNotifyEvent(XConfigureEvent &event); void handleEvent(XEvent &event); @@ -128,7 +139,9 @@ public: inline FbTk::FbWindow &gripRight() { return m_grip_right; } inline bool focused() const { return m_focused; } inline bool isShaded() const { return m_shaded; } + /// @return titlebar height unsigned int titleHeight() const; + /// @return size of button unsigned int buttonHeight() const; //@} @@ -178,8 +191,9 @@ private: std::string m_titletext; ///< text to be displayed int m_label int m_bevel; ///< bevel between titlebar items and titlebar bool m_use_titlebar; ///< if we should use titlebar - bool m_use_handles; ///< if we should use handles + bool m_use_handle; ///< if we should use handle bool m_focused; ///< focused/unfocused mode + /** @name pixmaps and colors for rendering */ @@ -215,7 +229,13 @@ private: unsigned int m_width_before_shade, ///< width before shade, so we can restore it when we unshade m_height_before_shade; ///< height before shade, so we can restore it when we unshade bool m_shaded; ///< wheter we're shaded or not - + unsigned int m_double_click_time; ///< the time period that's considerd to be a double click + struct MouseButtonAction { + FbTk::RefCount click; ///< what to do when we release mouse button + FbTk::RefCount click_pressed; ///< what to do when we press mouse button + FbTk::RefCount double_click; ///< what to do when we double click + }; + MouseButtonAction m_commands[5]; ///< hardcoded to five ...TODO, change this }; #endif // FBWINFRAME_HH -- cgit v0.11.2