toggle pixmap for IconButton

This commit is contained in:
fluxgen 2003-11-27 14:30:11 +00:00
parent 258cb10be2
commit 5ce35d9fa8
4 changed files with 48 additions and 11 deletions

View file

@ -20,7 +20,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // 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" #include "IconButton.hh"
@ -66,7 +66,8 @@ IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font,
FbTk::TextButton(parent, font, win.winClient().title()), FbTk::TextButton(parent, font, win.winClient().title()),
m_win(win), m_win(win),
m_icon_window(*this, 1, 1, 1, 1, m_icon_window(*this, 1, 1, 1, 1,
ExposureMask | ButtonPressMask | ButtonReleaseMask) { ExposureMask | ButtonPressMask | ButtonReleaseMask),
m_use_pixmap(true) {
FbTk::RefCount<FbTk::Command> focus(new FbTk::SimpleCommand<FluxboxWindow>(m_win, &FluxboxWindow::raiseAndFocus)); FbTk::RefCount<FbTk::Command> focus(new FbTk::SimpleCommand<FluxboxWindow>(m_win, &FluxboxWindow::raiseAndFocus));
FbTk::RefCount<FbTk::Command> menu(new ::ShowMenu(m_win)); FbTk::RefCount<FbTk::Command> menu(new ::ShowMenu(m_win));
@ -117,6 +118,13 @@ void IconButton::clearArea(int x, int y,
width, height, exposure); 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) { void IconButton::update(FbTk::Subject *subj) {
// we got signal that either title or // we got signal that either title or
// icon pixmap was updated, // icon pixmap was updated,
@ -130,7 +138,7 @@ void IconButton::update(FbTk::Subject *subj) {
if (hints == 0) if (hints == 0)
return; return;
if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) { if (m_use_pixmap && (hints->flags & IconPixmapHint) && hints->icon_pixmap != 0) {
// setup icon window // setup icon window
m_icon_window.show(); m_icon_window.show();
int new_height = height() - 2*m_icon_window.y(); // equally padded 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; 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.copy(hints->icon_mask);
m_icon_mask.scale(m_icon_pixmap.width(), m_icon_pixmap.height()); m_icon_mask.scale(m_icon_pixmap.width(), m_icon_pixmap.height());
} else } else
@ -186,7 +194,10 @@ void IconButton::setupWindow() {
void IconButton::drawText(int x, int y) { void IconButton::drawText(int x, int y) {
// offset text // offset text
if (m_icon_pixmap.drawable() != 0)
FbTk::TextButton::drawText(m_icon_window.x() + m_icon_window.width() + 1, y); FbTk::TextButton::drawText(m_icon_window.x() + m_icon_window.width() + 1, y);
else
FbTk::TextButton::drawText(1, y);
} }

View file

@ -20,7 +20,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // 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 #ifndef ICONBUTTON_HH
#define ICONBUTTON_HH #define ICONBUTTON_HH
@ -33,7 +33,8 @@ class FluxboxWindow;
class IconButton: public FbTk::TextButton, public FbTk::Observer { class IconButton: public FbTk::TextButton, public FbTk::Observer {
public: 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(); virtual ~IconButton();
void exposeEvent(XExposeEvent &event); void exposeEvent(XExposeEvent &event);
@ -46,8 +47,11 @@ public:
void resize(unsigned int width, unsigned int height); void resize(unsigned int width, unsigned int height);
void update(FbTk::Subject *subj); void update(FbTk::Subject *subj);
void setPixmap(bool use);
FluxboxWindow &win() { return m_win; } FluxboxWindow &win() { return m_win; }
const FluxboxWindow &win() const { return m_win; } const FluxboxWindow &win() const { return m_win; }
protected: protected:
void drawText(int x = 0, int y = 0); void drawText(int x = 0, int y = 0);
private: private:
@ -57,6 +61,7 @@ private:
FbTk::FbWindow m_icon_window; FbTk::FbWindow m_icon_window;
FbTk::FbPixmap m_icon_pixmap; FbTk::FbPixmap m_icon_pixmap;
FbTk::FbPixmap m_icon_mask; FbTk::FbPixmap m_icon_mask;
bool m_use_pixmap;
}; };
#endif // ICONBUTTON_HH #endif // ICONBUTTON_HH

View file

@ -20,7 +20,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // 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" #include "IconbarTool.hh"
@ -31,12 +31,15 @@
#include "Workspace.hh" #include "Workspace.hh"
#include "fluxbox.hh" #include "fluxbox.hh"
#include "FbMenu.hh" #include "FbMenu.hh"
#include "BoolMenuItem.hh"
#include "CommandParser.hh"
#include "FbTk/Menu.hh" #include "FbTk/Menu.hh"
#include "FbTk/MenuItem.hh" #include "FbTk/MenuItem.hh"
#include "FbTk/RefCount.hh" #include "FbTk/RefCount.hh"
#include "FbTk/SimpleCommand.hh" #include "FbTk/SimpleCommand.hh"
#include "FbTk/ImageControl.hh" #include "FbTk/ImageControl.hh"
#include "FbTk/MacroCommand.hh"
#include <typeinfo> #include <typeinfo>
#include <string> #include <string>
@ -181,11 +184,26 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, BScr
m_empty_pm(0), m_empty_pm(0),
m_rc_mode(screen.resourceManager(), WORKSPACE, m_rc_mode(screen.resourceManager(), WORKSPACE,
screen.name() + ".iconbar.mode", screen.altName() + ".Iconbar.Mode"), 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(), m_menu(*screen.menuTheme(), menu.screenNumber(), screen.imageControl(),
*screen.layerManager().getLayer(Fluxbox::instance()->getMenuLayer())) { *screen.layerManager().getLayer(Fluxbox::instance()->getMenuLayer())) {
// setup menu // setup mode menu
setupModeMenu(m_menu, *this); 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<Command> reconfig(new SimpleCommand<IconbarTool>(*this, &IconbarTool::renderTheme));
RefCount<Command> save(CommandParser::instance().parseLine("saverc"));
save_and_reconfig->add(reconfig);
save_and_reconfig->add(save);
RefCount<Command> 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); menu.insert(m_menu.label().c_str(), &m_menu);
// setup signals // setup signals
@ -445,6 +463,8 @@ void IconbarTool::renderTheme() {
void IconbarTool::renderButton(IconButton &button) { void IconbarTool::renderButton(IconButton &button) {
button.setPixmap(*m_rc_use_pixmap);
if (button.win().isFocused()) { // focused texture if (button.win().isFocused()) { // focused texture
button.setGC(m_theme.focusedText().textGC()); button.setGC(m_theme.focusedText().textGC());
button.setFont(m_theme.focusedText().font()); button.setFont(m_theme.focusedText().font());
@ -517,6 +537,7 @@ void IconbarTool::addWindow(FluxboxWindow &win) {
return; return;
IconButton *button = new IconButton(m_icon_container, m_theme.focusedText().font(), win); 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_container.insertItem(button);
m_icon_list.push_back(button); m_icon_list.push_back(button);
@ -527,7 +548,6 @@ void IconbarTool::addWindow(FluxboxWindow &win) {
win.stateSig().attach(this); win.stateSig().attach(this);
} }
void IconbarTool::updateIcons() { void IconbarTool::updateIcons() {
std::list<FluxboxWindow *> itemlist; std::list<FluxboxWindow *> itemlist;
// add icons to the itemlist // add icons to the itemlist

View file

@ -20,7 +20,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // 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 #ifndef ICONBARTOOL_HH
#define ICONBARTOOL_HH #define ICONBARTOOL_HH
@ -108,6 +108,7 @@ private:
IconList m_icon_list; IconList m_icon_list;
FbTk::Resource<Mode> m_rc_mode; FbTk::Resource<Mode> m_rc_mode;
FbTk::Resource<bool> m_rc_use_pixmap; ///< if iconbar should use win pixmap or not
FbMenu m_menu; FbMenu m_menu;
}; };