2003-08-11 15:45:50 +00:00
|
|
|
// IconButton.cc
|
|
|
|
// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
|
|
|
|
// and Simon Bowden (rathnor at users.sourceforge.net)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2003-08-24 16:24:19 +00:00
|
|
|
// $Id: IconButton.cc,v 1.7 2003/08/24 16:24:19 fluxgen Exp $
|
2003-08-11 15:45:50 +00:00
|
|
|
|
|
|
|
#include "IconButton.hh"
|
|
|
|
|
|
|
|
#include "FbTk/App.hh"
|
|
|
|
#include "FbTk/EventManager.hh"
|
|
|
|
|
2003-08-24 16:24:19 +00:00
|
|
|
#include "fluxbox.hh"
|
|
|
|
#include "Screen.hh"
|
2003-08-11 15:45:50 +00:00
|
|
|
#include "Window.hh"
|
|
|
|
#include "WinClient.hh"
|
2003-08-12 00:16:16 +00:00
|
|
|
#include "SimpleCommand.hh"
|
2003-08-11 15:45:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#ifdef SHAPE
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
#endif // SHAPE
|
|
|
|
|
2003-08-24 16:24:19 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ShowMenu: public FbTk::Command {
|
|
|
|
public:
|
|
|
|
explicit ShowMenu(FluxboxWindow &win):m_win(win) { }
|
|
|
|
void execute() {
|
|
|
|
// get last button pos
|
|
|
|
const XEvent &event = Fluxbox::instance()->lastEvent();
|
|
|
|
int x = event.xbutton.x_root - (m_win.menu().width() / 2);
|
|
|
|
int y = event.xbutton.y_root - (m_win.menu().height() / 2);
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
else if (x + m_win.menu().width() > m_win.screen().width())
|
|
|
|
x = m_win.screen().width() - m_win.menu().width();
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
else if (y + m_win.menu().height() > m_win.screen().height())
|
|
|
|
y = m_win.screen().height() - m_win.menu().height();
|
|
|
|
|
|
|
|
m_win.menu().move(x, y);
|
|
|
|
m_win.menu().show();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
FluxboxWindow &m_win;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2003-08-11 15:45:50 +00:00
|
|
|
IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font,
|
|
|
|
FluxboxWindow &win):
|
2003-08-19 16:15:32 +00:00
|
|
|
FbTk::TextButton(parent, font, win.winClient().title()),
|
2003-08-11 15:45:50 +00:00
|
|
|
m_win(win),
|
2003-08-13 10:03:45 +00:00
|
|
|
m_icon_window(*this, 1, 1, 1, 1,
|
2003-08-11 15:45:50 +00:00
|
|
|
ExposureMask | ButtonPressMask | ButtonReleaseMask) {
|
|
|
|
|
2003-08-12 00:16:16 +00:00
|
|
|
FbTk::RefCount<FbTk::Command> focus(new FbTk::SimpleCommand<FluxboxWindow>(m_win, &FluxboxWindow::raiseAndFocus));
|
2003-08-24 16:24:19 +00:00
|
|
|
FbTk::RefCount<FbTk::Command> menu(new ::ShowMenu(m_win));
|
|
|
|
setOnClick(focus, 1);
|
|
|
|
setOnClick(menu, 3);
|
2003-08-11 15:45:50 +00:00
|
|
|
m_win.hintSig().attach(this);
|
2003-08-19 16:15:32 +00:00
|
|
|
|
2003-08-11 15:45:50 +00:00
|
|
|
FbTk::EventManager::instance()->add(*this, m_icon_window);
|
|
|
|
|
|
|
|
update(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
IconButton::~IconButton() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconButton::exposeEvent(XExposeEvent &event) {
|
|
|
|
if (m_icon_window == event.window)
|
|
|
|
m_icon_window.clear();
|
|
|
|
else
|
|
|
|
FbTk::Button::exposeEvent(event);
|
|
|
|
}
|
|
|
|
void IconButton::moveResize(int x, int y,
|
|
|
|
unsigned int width, unsigned int height) {
|
|
|
|
|
|
|
|
FbTk::Button::moveResize(x, y, width, height);
|
|
|
|
|
|
|
|
if (m_icon_window.width() != FbTk::Button::width() ||
|
|
|
|
m_icon_window.height() != FbTk::Button::height())
|
|
|
|
update(0); // update icon window
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconButton::resize(unsigned int width, unsigned int height) {
|
|
|
|
FbTk::Button::resize(width, height);
|
|
|
|
if (m_icon_window.width() != FbTk::Button::width() ||
|
|
|
|
m_icon_window.height() != FbTk::Button::height())
|
|
|
|
update(0); // update icon window
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconButton::clear() {
|
|
|
|
FbTk::Button::clear();
|
|
|
|
setupWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconButton::update(FbTk::Subject *subj) {
|
|
|
|
// we got signal that either title or
|
|
|
|
// icon pixmap was updated,
|
|
|
|
// so we refresh everything
|
|
|
|
|
2003-08-12 01:19:22 +00:00
|
|
|
// we need to check our client first
|
|
|
|
if (m_win.clientList().size() == 0)
|
|
|
|
return;
|
|
|
|
|
2003-08-11 15:45:50 +00:00
|
|
|
XWMHints *hints = XGetWMHints(FbTk::App::instance()->display(), m_win.winClient().window());
|
|
|
|
if (hints == 0)
|
|
|
|
return;
|
|
|
|
|
2003-08-12 01:19:22 +00:00
|
|
|
if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
|
2003-08-11 15:45:50 +00:00
|
|
|
// setup icon window
|
|
|
|
m_icon_window.show();
|
2003-08-12 01:19:22 +00:00
|
|
|
int new_height = height() - m_icon_window.y();
|
|
|
|
int new_width = height();
|
|
|
|
m_icon_window.resize(new_width ? new_width : 1, new_height ? new_height : 1);
|
2003-08-11 15:45:50 +00:00
|
|
|
|
|
|
|
m_icon_pixmap.copy(hints->icon_pixmap);
|
|
|
|
m_icon_pixmap.scale(m_icon_window.height(), m_icon_window.height());
|
|
|
|
|
|
|
|
m_icon_window.setBackgroundPixmap(m_icon_pixmap.drawable());
|
|
|
|
} else {
|
|
|
|
// no icon pixmap
|
2003-08-12 01:19:22 +00:00
|
|
|
m_icon_window.move(0, 0);
|
2003-08-11 15:45:50 +00:00
|
|
|
m_icon_window.hide();
|
|
|
|
m_icon_pixmap = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hints->flags & IconMaskHint) {
|
|
|
|
m_icon_mask.copy(hints->icon_mask);
|
2003-08-12 00:16:16 +00:00
|
|
|
m_icon_mask.scale(m_icon_pixmap.width(), m_icon_pixmap.height());
|
2003-08-11 15:45:50 +00:00
|
|
|
} else
|
|
|
|
m_icon_mask = 0;
|
|
|
|
|
|
|
|
XFree(hints);
|
2003-08-12 00:16:16 +00:00
|
|
|
hints = 0;
|
2003-08-11 15:45:50 +00:00
|
|
|
|
|
|
|
#ifdef SHAPE
|
2003-08-12 00:16:16 +00:00
|
|
|
|
|
|
|
if (m_icon_mask.drawable() != 0) {
|
2003-08-11 15:45:50 +00:00
|
|
|
XShapeCombineMask(FbTk::App::instance()->display(),
|
|
|
|
m_icon_window.drawable(),
|
|
|
|
ShapeBounding,
|
|
|
|
0, 0,
|
|
|
|
m_icon_mask.drawable(),
|
|
|
|
ShapeSet);
|
|
|
|
}
|
2003-08-12 00:16:16 +00:00
|
|
|
|
2003-08-11 15:45:50 +00:00
|
|
|
#endif // SHAPE
|
|
|
|
|
|
|
|
setupWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconButton::setupWindow() {
|
|
|
|
|
|
|
|
m_icon_window.clear();
|
2003-08-12 01:19:22 +00:00
|
|
|
|
|
|
|
if (m_win.clientList().size() == 0)
|
|
|
|
return;
|
|
|
|
|
2003-08-11 15:45:50 +00:00
|
|
|
setText(m_win.winClient().title());
|
|
|
|
// draw with x offset and y offset
|
|
|
|
drawText(m_icon_window.x() + m_icon_window.width() + 1);
|
|
|
|
}
|
|
|
|
|