diff options
Diffstat (limited to 'src/IconButton.cc')
-rw-r--r-- | src/IconButton.cc | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/IconButton.cc b/src/IconButton.cc new file mode 100644 index 0000000..f2fe45c --- /dev/null +++ b/src/IconButton.cc | |||
@@ -0,0 +1,148 @@ | |||
1 | // IconButton.cc | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
4 | // | ||
5 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
6 | // copy of this software and associated documentation files (the "Software"), | ||
7 | // to deal in the Software without restriction, including without limitation | ||
8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
9 | // and/or sell copies of the Software, and to permit persons to whom the | ||
10 | // Software is furnished to do so, subject to the following conditions: | ||
11 | // | ||
12 | // The above copyright notice and this permission notice shall be included in | ||
13 | // all copies or substantial portions of the Software. | ||
14 | // | ||
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
21 | // DEALINGS IN THE SOFTWARE. | ||
22 | |||
23 | // $Id: IconButton.cc,v 1.1 2003/08/11 15:45:50 fluxgen Exp $ | ||
24 | |||
25 | #include "IconButton.hh" | ||
26 | |||
27 | #include "FbTk/App.hh" | ||
28 | #include "FbTk/EventManager.hh" | ||
29 | |||
30 | #include "IconButtonTheme.hh" | ||
31 | #include "Window.hh" | ||
32 | #include "WinClient.hh" | ||
33 | |||
34 | #ifdef HAVE_CONFIG_H | ||
35 | #include "config.h" | ||
36 | #endif // HAVE_CONFIG_H | ||
37 | |||
38 | #include <X11/Xutil.h> | ||
39 | #ifdef SHAPE | ||
40 | #include <X11/extensions/shape.h> | ||
41 | #endif // SHAPE | ||
42 | |||
43 | #include <iostream> | ||
44 | using namespace std; | ||
45 | |||
46 | IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, | ||
47 | FluxboxWindow &win): | ||
48 | TextButton(parent, font, win.winClient().title()), | ||
49 | m_win(win), | ||
50 | m_icon_window(window(), 1, 1, 1, 1, | ||
51 | ExposureMask | ButtonPressMask | ButtonReleaseMask) { | ||
52 | |||
53 | m_win.hintSig().attach(this); | ||
54 | |||
55 | FbTk::EventManager::instance()->add(*this, m_icon_window); | ||
56 | |||
57 | update(0); | ||
58 | } | ||
59 | |||
60 | IconButton::~IconButton() { | ||
61 | |||
62 | } | ||
63 | |||
64 | void IconButton::exposeEvent(XExposeEvent &event) { | ||
65 | if (m_icon_window == event.window) | ||
66 | m_icon_window.clear(); | ||
67 | else | ||
68 | FbTk::Button::exposeEvent(event); | ||
69 | } | ||
70 | void IconButton::moveResize(int x, int y, | ||
71 | unsigned int width, unsigned int height) { | ||
72 | |||
73 | FbTk::Button::moveResize(x, y, width, height); | ||
74 | |||
75 | if (m_icon_window.width() != FbTk::Button::width() || | ||
76 | m_icon_window.height() != FbTk::Button::height()) | ||
77 | update(0); // update icon window | ||
78 | } | ||
79 | |||
80 | void IconButton::resize(unsigned int width, unsigned int height) { | ||
81 | FbTk::Button::resize(width, height); | ||
82 | if (m_icon_window.width() != FbTk::Button::width() || | ||
83 | m_icon_window.height() != FbTk::Button::height()) | ||
84 | update(0); // update icon window | ||
85 | } | ||
86 | |||
87 | void IconButton::clear() { | ||
88 | FbTk::Button::clear(); | ||
89 | setupWindow(); | ||
90 | } | ||
91 | |||
92 | void IconButton::update(FbTk::Subject *subj) { | ||
93 | // we got signal that either title or | ||
94 | // icon pixmap was updated, | ||
95 | // so we refresh everything | ||
96 | |||
97 | XWMHints *hints = XGetWMHints(FbTk::App::instance()->display(), m_win.winClient().window()); | ||
98 | if (hints == 0) | ||
99 | return; | ||
100 | |||
101 | if (hints->flags & IconPixmapHint) { | ||
102 | // setup icon window | ||
103 | m_icon_window.show(); | ||
104 | m_icon_window.resize(height(), height() - m_icon_window.y()); | ||
105 | |||
106 | m_icon_pixmap.copy(hints->icon_pixmap); | ||
107 | m_icon_pixmap.scale(m_icon_window.height(), m_icon_window.height()); | ||
108 | |||
109 | m_icon_window.setBackgroundPixmap(m_icon_pixmap.drawable()); | ||
110 | } else { | ||
111 | // no icon pixmap | ||
112 | m_icon_window.hide(); | ||
113 | m_icon_pixmap = 0; | ||
114 | } | ||
115 | |||
116 | if(hints->flags & IconMaskHint) { | ||
117 | m_icon_mask.copy(hints->icon_mask); | ||
118 | m_icon_mask.scale(height(), height()); | ||
119 | } else | ||
120 | m_icon_mask = 0; | ||
121 | |||
122 | XFree(hints); | ||
123 | |||
124 | #ifdef SHAPE | ||
125 | //!! TODO! bugs!?! | ||
126 | /* | ||
127 | if (m_icon_mask.drawable() != 0) { | ||
128 | XShapeCombineMask(FbTk::App::instance()->display(), | ||
129 | m_icon_window.drawable(), | ||
130 | ShapeBounding, | ||
131 | 0, 0, | ||
132 | m_icon_mask.drawable(), | ||
133 | ShapeSet); | ||
134 | } | ||
135 | */ | ||
136 | #endif // SHAPE | ||
137 | |||
138 | setupWindow(); | ||
139 | } | ||
140 | |||
141 | void IconButton::setupWindow() { | ||
142 | |||
143 | m_icon_window.clear(); | ||
144 | setText(m_win.winClient().title()); | ||
145 | // draw with x offset and y offset | ||
146 | drawText(m_icon_window.x() + m_icon_window.width() + 1); | ||
147 | } | ||
148 | |||