From 5ce35d9fa811358162ae44ee1ca514270d7da466 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 27 Nov 2003 14:30:11 +0000 Subject: toggle pixmap for IconButton --- src/IconButton.cc | 21 ++++++++++++++++----- src/IconButton.hh | 9 +++++++-- src/IconbarTool.cc | 26 +++++++++++++++++++++++--- src/IconbarTool.hh | 3 ++- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/IconButton.cc b/src/IconButton.cc index 20fca8a..6c5e3e4 100644 --- a/src/IconButton.cc +++ b/src/IconButton.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconButton.cc,v 1.12 2003/11/19 12:57:27 rathnor Exp $ +// $Id: IconButton.cc,v 1.13 2003/11/27 14:27:48 fluxgen Exp $ #include "IconButton.hh" @@ -66,7 +66,8 @@ IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, FbTk::TextButton(parent, font, win.winClient().title()), m_win(win), m_icon_window(*this, 1, 1, 1, 1, - ExposureMask | ButtonPressMask | ButtonReleaseMask) { + ExposureMask | ButtonPressMask | ButtonReleaseMask), + m_use_pixmap(true) { FbTk::RefCount focus(new FbTk::SimpleCommand(m_win, &FluxboxWindow::raiseAndFocus)); FbTk::RefCount menu(new ::ShowMenu(m_win)); @@ -117,6 +118,13 @@ void IconButton::clearArea(int x, int y, width, height, exposure); } +void IconButton::setPixmap(bool use) { + if (m_use_pixmap != use) { + m_use_pixmap = use; + update(0); + } +} + void IconButton::update(FbTk::Subject *subj) { // we got signal that either title or // icon pixmap was updated, @@ -130,7 +138,7 @@ void IconButton::update(FbTk::Subject *subj) { if (hints == 0) return; - if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) { + if (m_use_pixmap && (hints->flags & IconPixmapHint) && hints->icon_pixmap != 0) { // setup icon window m_icon_window.show(); int new_height = height() - 2*m_icon_window.y(); // equally padded @@ -148,7 +156,7 @@ void IconButton::update(FbTk::Subject *subj) { m_icon_pixmap = 0; } - if(hints->flags & IconMaskHint) { + if(m_use_pixmap && (hints->flags & IconMaskHint)) { m_icon_mask.copy(hints->icon_mask); m_icon_mask.scale(m_icon_pixmap.width(), m_icon_pixmap.height()); } else @@ -186,7 +194,10 @@ void IconButton::setupWindow() { void IconButton::drawText(int x, int y) { // offset text - FbTk::TextButton::drawText(m_icon_window.x() + m_icon_window.width() + 1, y); + if (m_icon_pixmap.drawable() != 0) + FbTk::TextButton::drawText(m_icon_window.x() + m_icon_window.width() + 1, y); + else + FbTk::TextButton::drawText(1, y); } diff --git a/src/IconButton.hh b/src/IconButton.hh index 6ac08b7..69fbf46 100644 --- a/src/IconButton.hh +++ b/src/IconButton.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconButton.hh,v 1.3 2003/09/10 21:40:01 fluxgen Exp $ +// $Id: IconButton.hh,v 1.4 2003/11/27 14:27:48 fluxgen Exp $ #ifndef ICONBUTTON_HH #define ICONBUTTON_HH @@ -33,7 +33,8 @@ class FluxboxWindow; class IconButton: public FbTk::TextButton, public FbTk::Observer { public: - IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, FluxboxWindow &window); + IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, + FluxboxWindow &window); virtual ~IconButton(); void exposeEvent(XExposeEvent &event); @@ -46,8 +47,11 @@ public: void resize(unsigned int width, unsigned int height); void update(FbTk::Subject *subj); + void setPixmap(bool use); + FluxboxWindow &win() { return m_win; } const FluxboxWindow &win() const { return m_win; } + protected: void drawText(int x = 0, int y = 0); private: @@ -57,6 +61,7 @@ private: FbTk::FbWindow m_icon_window; FbTk::FbPixmap m_icon_pixmap; FbTk::FbPixmap m_icon_mask; + bool m_use_pixmap; }; #endif // ICONBUTTON_HH diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 6bcc6b8..faccc62 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.15 2003/10/26 20:13:11 fluxgen Exp $ +// $Id: IconbarTool.cc,v 1.16 2003/11/27 14:30:11 fluxgen Exp $ #include "IconbarTool.hh" @@ -31,12 +31,15 @@ #include "Workspace.hh" #include "fluxbox.hh" #include "FbMenu.hh" +#include "BoolMenuItem.hh" +#include "CommandParser.hh" #include "FbTk/Menu.hh" #include "FbTk/MenuItem.hh" #include "FbTk/RefCount.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/ImageControl.hh" +#include "FbTk/MacroCommand.hh" #include #include @@ -181,11 +184,26 @@ 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_use_pixmap(screen.resourceManager(), true, + screen.name() + ".iconbar.usePixmap", screen.altName() + ".Iconbar.UsePixmap"), m_menu(*screen.menuTheme(), menu.screenNumber(), screen.imageControl(), *screen.layerManager().getLayer(Fluxbox::instance()->getMenuLayer())) { - // setup menu + // setup mode menu setupModeMenu(m_menu, *this); + + using namespace FbTk; + // setup use pixmap item to reconfig iconbar and save resource on click + MacroCommand *save_and_reconfig = new MacroCommand(); + RefCount reconfig(new SimpleCommand(*this, &IconbarTool::renderTheme)); + RefCount save(CommandParser::instance().parseLine("saverc")); + save_and_reconfig->add(reconfig); + save_and_reconfig->add(save); + RefCount s_and_reconfig(save_and_reconfig); + m_menu.insert(new BoolMenuItem("Use Pixmap", *m_rc_use_pixmap, s_and_reconfig)); + m_menu.update(); + + // add iconbar menu to toolbar menu menu.insert(m_menu.label().c_str(), &m_menu); // setup signals @@ -445,6 +463,8 @@ void IconbarTool::renderTheme() { void IconbarTool::renderButton(IconButton &button) { + button.setPixmap(*m_rc_use_pixmap); + if (button.win().isFocused()) { // focused texture button.setGC(m_theme.focusedText().textGC()); button.setFont(m_theme.focusedText().font()); @@ -517,6 +537,7 @@ void IconbarTool::addWindow(FluxboxWindow &win) { return; IconButton *button = new IconButton(m_icon_container, m_theme.focusedText().font(), win); + button->setPixmap(*m_rc_use_pixmap); m_icon_container.insertItem(button); m_icon_list.push_back(button); @@ -527,7 +548,6 @@ void IconbarTool::addWindow(FluxboxWindow &win) { win.stateSig().attach(this); } - void IconbarTool::updateIcons() { std::list itemlist; // add icons to the itemlist diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index c805fec..00e1026 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.9 2003/10/06 06:22:42 rathnor Exp $ +// $Id: IconbarTool.hh,v 1.10 2003/11/27 14:30:11 fluxgen Exp $ #ifndef ICONBARTOOL_HH #define ICONBARTOOL_HH @@ -108,6 +108,7 @@ private: IconList m_icon_list; FbTk::Resource m_rc_mode; + FbTk::Resource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not FbMenu m_menu; }; -- cgit v0.11.2