1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
// 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.
// $Id: IconButton.cc,v 1.9 2003/10/31 10:37:09 rathnor Exp $
#include "IconButton.hh"
#include "FbTk/App.hh"
#include "FbTk/EventManager.hh"
#include "fluxbox.hh"
#include "Screen.hh"
#include "Window.hh"
#include "WinClient.hh"
#include "SimpleCommand.hh"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
#include <X11/Xutil.h>
#ifdef SHAPE
#include <X11/extensions/shape.h>
#endif // SHAPE
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
IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font,
FluxboxWindow &win):
FbTk::TextButton(parent, font, win.winClient().title()),
m_win(win),
m_icon_window(*this, 1, 1, 1, 1,
ExposureMask | ButtonPressMask | ButtonReleaseMask) {
FbTk::RefCount<FbTk::Command> focus(new FbTk::SimpleCommand<FluxboxWindow>(m_win, &FluxboxWindow::raiseAndFocus));
FbTk::RefCount<FbTk::Command> menu(new ::ShowMenu(m_win));
setOnClick(focus, 1);
setOnClick(menu, 3);
m_win.hintSig().attach(this);
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::TextButton::exposeEvent(event);
}
void IconButton::moveResize(int x, int y,
unsigned int width, unsigned int height) {
FbTk::TextButton::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::TextButton::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() {
setupWindow();
}
void IconButton::clearArea(int x, int y,
unsigned int width, unsigned int height,
bool exposure) {
FbTk::TextButton::clearArea(x, y,
width, height, exposure);
}
void IconButton::update(FbTk::Subject *subj) {
// we got signal that either title or
// icon pixmap was updated,
// so we refresh everything
// we need to check our client first
if (m_win.clientList().size() == 0)
return;
XWMHints *hints = XGetWMHints(FbTk::App::instance()->display(), m_win.winClient().window());
if (hints == 0)
return;
if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
// setup icon window
m_icon_window.show();
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);
m_icon_pixmap.copy(hints->icon_pixmap);
m_icon_pixmap.scale(m_icon_window.height(), m_icon_window.height());
setBackgroundPixmap(m_icon_pixmap.drawable());
} else {
// no icon pixmap
m_icon_window.move(0, 0);
m_icon_window.hide();
m_icon_pixmap = 0;
}
if(hints->flags & IconMaskHint) {
m_icon_mask.copy(hints->icon_mask);
m_icon_mask.scale(m_icon_pixmap.width(), m_icon_pixmap.height());
} else
m_icon_mask = 0;
XFree(hints);
hints = 0;
#ifdef SHAPE
if (m_icon_mask.drawable() != 0) {
XShapeCombineMask(FbTk::App::instance()->display(),
m_icon_window.drawable(),
ShapeBounding,
0, 0,
m_icon_mask.drawable(),
ShapeSet);
}
#endif // SHAPE
setupWindow();
}
void IconButton::setupWindow() {
if (!m_win.clientList().empty()) {
setText(m_win.winClient().title());
// draw with x offset and y offset
}
FbTk::TextButton::clear();
}
void IconButton::drawText(int x, int y) {
// offset text
FbTk::TextButton::drawText(m_icon_window.x() + m_icon_window.width() + 1, y);
}
|