diff options
Diffstat (limited to 'src/ButtonTool.cc')
-rw-r--r-- | src/ButtonTool.cc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc new file mode 100644 index 0000000..7f350f5 --- /dev/null +++ b/src/ButtonTool.cc | |||
@@ -0,0 +1,86 @@ | |||
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.1 2003/10/13 23:38:17 fluxgen 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 | |||
58 | Pixmap old_pm = m_cache_pm; | ||
59 | if (theme().texture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { | ||
60 | m_cache_pm = 0; | ||
61 | btn.setBackgroundColor(theme().texture().color()); | ||
62 | } else { | ||
63 | m_cache_pm = m_image_ctrl.renderImage(width(), height(), | ||
64 | theme().texture()); | ||
65 | btn.setBackgroundPixmap(m_cache_pm); | ||
66 | } | ||
67 | if (old_pm) | ||
68 | m_image_ctrl.removeImage(old_pm); | ||
69 | |||
70 | old_pm = m_cache_pressed_pm; | ||
71 | if (static_cast<const ButtonTheme &>(theme()).pressed().type() == | ||
72 | (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { | ||
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 | } | ||
86 | |||