aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/IconButton.cc148
-rw-r--r--src/IconButton.hh59
2 files changed, 207 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>
44using namespace std;
45
46IconButton::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
60IconButton::~IconButton() {
61
62}
63
64void IconButton::exposeEvent(XExposeEvent &event) {
65 if (m_icon_window == event.window)
66 m_icon_window.clear();
67 else
68 FbTk::Button::exposeEvent(event);
69}
70void 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
80void 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
87void IconButton::clear() {
88 FbTk::Button::clear();
89 setupWindow();
90}
91
92void 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
141void 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
diff --git a/src/IconButton.hh b/src/IconButton.hh
new file mode 100644
index 0000000..de5440c
--- /dev/null
+++ b/src/IconButton.hh
@@ -0,0 +1,59 @@
1// IconButton.hh
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.hh,v 1.1 2003/08/11 15:45:50 fluxgen Exp $
24
25#ifndef ICONBUTTON_HH
26#define ICONBUTTON_HH
27
28#include "FbTk/FbPixmap.hh"
29#include "FbTk/Observer.hh"
30
31#include "TextButton.hh"
32
33class FluxboxWindow;
34
35class IconButton: public TextButton, public FbTk::Observer {
36public:
37 IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, FluxboxWindow &window);
38 virtual ~IconButton();
39
40 void exposeEvent(XExposeEvent &event);
41 void clear();
42 void moveResize(int x, int y,
43 unsigned int width, unsigned int height);
44 void resize(unsigned int width, unsigned int height);
45
46 void update(FbTk::Subject *subj);
47 FluxboxWindow &win() { return m_win; }
48 const FluxboxWindow &win() const { return m_win; }
49
50private:
51 void setupWindow();
52
53 FluxboxWindow &m_win;
54 FbTk::FbWindow m_icon_window;
55 FbTk::FbPixmap m_icon_pixmap;
56 FbTk::FbPixmap m_icon_mask;
57};
58
59#endif // ICONBUTTON_HH