diff options
Diffstat (limited to 'src/ButtonTool.cc')
-rw-r--r-- | src/ButtonTool.cc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc new file mode 100644 index 0000000..a3b4d7b --- /dev/null +++ b/src/ButtonTool.cc | |||
@@ -0,0 +1,87 @@ | |||
1 | // ButtonTool.cc for Fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: ButtonTool.cc,v 1.3 2004/01/13 14:41:32 rathnor Exp $ | ||
23 | |||
24 | #include "ButtonTool.hh" | ||
25 | |||
26 | #include "FbTk/Button.hh" | ||
27 | #include "FbTk/ImageControl.hh" | ||
28 | #include "ButtonTheme.hh" | ||
29 | |||
30 | ButtonTool::ButtonTool(FbTk::Button *button, | ||
31 | ToolbarItem::Type type, | ||
32 | ButtonTheme &theme, | ||
33 | FbTk::ImageControl &img_ctrl): | ||
34 | GenericTool(button, type, theme), | ||
35 | m_cache_pm(0), | ||
36 | m_cache_pressed_pm(0), | ||
37 | m_image_ctrl(img_ctrl) { | ||
38 | |||
39 | renderTheme(); | ||
40 | } | ||
41 | |||
42 | ButtonTool::~ButtonTool() { | ||
43 | if (m_cache_pm) | ||
44 | m_image_ctrl.removeImage(m_cache_pm); | ||
45 | |||
46 | if (m_cache_pressed_pm) | ||
47 | m_image_ctrl.removeImage(m_cache_pressed_pm); | ||
48 | |||
49 | } | ||
50 | |||
51 | void ButtonTool::renderTheme() { | ||
52 | FbTk::Button &btn = static_cast<FbTk::Button &>(window()); | ||
53 | |||
54 | btn.setGC(static_cast<const ButtonTheme &>(theme()).gc()); | ||
55 | btn.setBorderColor(theme().border().color()); | ||
56 | btn.setBorderWidth(theme().border().width()); | ||
57 | btn.setAlpha(theme().alpha()); | ||
58 | |||
59 | Pixmap old_pm = m_cache_pm; | ||
60 | if (!theme().texture().usePixmap()) { | ||
61 | m_cache_pm = 0; | ||
62 | btn.setBackgroundColor(theme().texture().color()); | ||
63 | } else { | ||
64 | m_cache_pm = m_image_ctrl.renderImage(width(), height(), | ||
65 | theme().texture()); | ||
66 | btn.setBackgroundPixmap(m_cache_pm); | ||
67 | } | ||
68 | if (old_pm) | ||
69 | m_image_ctrl.removeImage(old_pm); | ||
70 | |||
71 | old_pm = m_cache_pressed_pm; | ||
72 | if (! static_cast<const ButtonTheme &>(theme()).pressed().usePixmap()) { | ||
73 | m_cache_pressed_pm = 0; | ||
74 | btn.setPressedColor(static_cast<const ButtonTheme &>(theme()).pressed().color()); | ||
75 | } else { | ||
76 | m_cache_pressed_pm = m_image_ctrl.renderImage(width(), height(), | ||
77 | static_cast<const ButtonTheme &>(theme()).pressed()); | ||
78 | btn.setPressedPixmap(m_cache_pressed_pm); | ||
79 | } | ||
80 | |||
81 | if (old_pm) | ||
82 | m_image_ctrl.removeImage(old_pm); | ||
83 | |||
84 | btn.clear(); | ||
85 | btn.updateTransparent(); | ||
86 | } | ||
87 | |||