From d2d3fbc96c72209c281bd97ba4aee12912c16d89 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Fri, 12 Dec 2003 14:36:22 +0000 Subject: alignment of iconbar buttons --- src/IconbarTool.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/IconbarTool.hh | 8 +++--- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index ee6095e..c14e056 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconbarTool.cc,v 1.21 2003/12/10 23:08:03 fluxgen Exp $ +// $Id: IconbarTool.cc,v 1.22 2003/12/12 14:36:22 fluxgen Exp $ #include "IconbarTool.hh" @@ -63,6 +63,35 @@ void FbTk::Resource::setFromString(const char *strval) { setDefaultValue(); } +template<> +void FbTk::Resource::setDefaultValue() { + m_value = Container::RELATIVE; +} + +template<> +string FbTk::Resource::getString() { + switch (m_value) { + case Container::LEFT: + return string("Left"); + case Container::RIGHT: + return string("Right"); + case Container::RELATIVE: + return string("Relative"); + } + return string("Left"); +} + +template<> +void FbTk::Resource::setFromString(const char *str) { + if (strcasecmp(str, "Left") == 0) + m_value = Container::LEFT; + else if (strcasecmp(str, "Right") == 0) + m_value = Container::RIGHT; + else if (strcasecmp(str, "RELATIVE") == 0) + m_value = Container::RELATIVE; + else + setDefaultValue(); +} template<> string FbTk::Resource::getString() { @@ -108,6 +137,24 @@ private: IconbarTool::Mode m_mode; }; +class ToolbarAlignMenuItem: public FbTk::MenuItem { +public: + ToolbarAlignMenuItem(const char *label, IconbarTool &handler, + Container::Alignment mode, + FbTk::RefCount &cmd): + FbTk::MenuItem(label, cmd), m_handler(handler), m_mode(mode) { + } + bool isEnabled() const { return m_handler.alignment() != m_mode; } + void click(int button, int time) { + m_handler.setAlignment(m_mode); + FbTk::MenuItem::click(button, time); + } + +private: + IconbarTool &m_handler; + Container::Alignment m_mode; +}; + void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) { using namespace FbTk; @@ -129,6 +176,14 @@ void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) { IconbarTool::WORKSPACE, saverc_cmd)); menu.insert(new ToolbarModeMenuItem("All Windows", handler, IconbarTool::ALLWINDOWS, saverc_cmd)); + menu.insert("---"); // separator line + menu.insert(new ToolbarAlignMenuItem("Left", handler, + Container::LEFT, saverc_cmd)); + menu.insert(new ToolbarAlignMenuItem("Relative", handler, + Container::RELATIVE, saverc_cmd)); + menu.insert(new ToolbarAlignMenuItem("Right", handler, + Container::RIGHT, saverc_cmd)); + menu.insert("---"); // separator line menu.update(); } @@ -184,6 +239,10 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, BScr m_empty_pm(0), m_rc_mode(screen.resourceManager(), WORKSPACE, screen.name() + ".iconbar.mode", screen.altName() + ".Iconbar.Mode"), + m_rc_alignment(screen.resourceManager(), Container::LEFT, + screen.name() + ".iconbar.alignment", screen.altName() + ".Iconbar.Alignment"), + m_rc_client_width(screen.resourceManager(), 70, + screen.name() + ".iconbar.clientWidth", screen.altName() + ".Iconbar.ClientWidth"), m_rc_use_pixmap(screen.resourceManager(), true, screen.name() + ".iconbar.usePixmap", screen.altName() + ".Iconbar.UsePixmap"), m_menu(*screen.menuTheme(), screen.imageControl(), @@ -254,6 +313,11 @@ void IconbarTool::hide() { m_icon_container.hide(); } +void IconbarTool::setAlignment(Container::Alignment align) { + *m_rc_alignment = align; + update(0); +} + void IconbarTool::setMode(Mode mode) { if (mode == *m_rc_mode) return; @@ -306,6 +370,16 @@ void IconbarTool::update(FbTk::Subject *subj) { if (m_screen.isShuttingdown()) return; + m_icon_container.setAlignment(*m_rc_alignment); + // clamp to normal values + if (*m_rc_client_width < 1) + *m_rc_client_width = 10; + else if (*m_rc_client_width > 400) + *m_rc_client_width = 400; + + m_icon_container.setMaxSizePerClient(*m_rc_client_width); + + if (mode() == NONE) { if (subj != 0 && typeid(*subj) == typeid(IconbarTheme)) renderTheme(); diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 00e1026..d60d14b 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconbarTool.hh,v 1.10 2003/11/27 14:30:11 fluxgen Exp $ +// $Id: IconbarTool.hh,v 1.11 2003/12/12 14:36:22 fluxgen Exp $ #ifndef ICONBARTOOL_HH #define ICONBARTOOL_HH @@ -66,7 +66,7 @@ public: void update(FbTk::Subject *subj); void show(); void hide(); - + void setAlignment(Container::Alignment a); void setMode(Mode mode); unsigned int width() const; @@ -74,7 +74,7 @@ public: unsigned int borderWidth() const; Mode mode() const { return *m_rc_mode; } - + Container::Alignment alignment() const { return m_icon_container.alignment(); } private: /// render single button that holds win @@ -108,6 +108,8 @@ private: IconList m_icon_list; FbTk::Resource m_rc_mode; + FbTk::Resource m_rc_alignment; ///< alignment of buttons + FbTk::Resource m_rc_client_width; ///< size of client button in LEFT/RIGHT mode FbTk::Resource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not FbMenu m_menu; -- cgit v0.11.2