diff options
Diffstat (limited to 'src/FbTk/Button.hh')
-rw-r--r-- | src/FbTk/Button.hh | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh new file mode 100644 index 0000000..a96dcd8 --- /dev/null +++ b/src/FbTk/Button.hh | |||
@@ -0,0 +1,105 @@ | |||
1 | // Button.hh for FbTk - Fluxbox Toolkit | ||
2 | // Copyright (c) 2002 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: Button.hh,v 1.3 2002/12/25 11:28:43 fluxgen Exp $ | ||
23 | |||
24 | #ifndef FBTK_BUTTON_HH | ||
25 | #define FBTK_BUTTON_HH | ||
26 | |||
27 | #include "EventHandler.hh" | ||
28 | #include "NotCopyable.hh" | ||
29 | #include "RefCount.hh" | ||
30 | #include "FbWindow.hh" | ||
31 | #include "Command.hh" | ||
32 | #include "Color.hh" | ||
33 | |||
34 | #include <X11/Xlib.h> | ||
35 | #include <memory> | ||
36 | |||
37 | namespace FbTk { | ||
38 | |||
39 | class Button:public EventHandler, | ||
40 | private NotCopyable { | ||
41 | public: | ||
42 | Button(int screen_num, int x, int y, unsigned int width, unsigned int height); | ||
43 | Button(const FbWindow &parent, int x, int y, unsigned int width, unsigned int height); | ||
44 | virtual ~Button(); | ||
45 | |||
46 | /// sets action when the button is clicked with #button mouse btn | ||
47 | void setOnClick(RefCount<Command> &com, int button = 1); | ||
48 | |||
49 | void move(int x, int y); | ||
50 | void resize(unsigned int width, unsigned int height); | ||
51 | void moveResize(int x, int y, unsigned int width, unsigned int height); | ||
52 | |||
53 | /// sets foreground pixmap | ||
54 | void setPixmap(Pixmap pm); | ||
55 | /// sets the pixmap to be viewed when the button is pressed | ||
56 | void setPressedPixmap(Pixmap pm); | ||
57 | /// sets graphic context for drawing | ||
58 | void setGC(GC gc) { m_gc = gc; } | ||
59 | /// sets background pixmap, this will override background color | ||
60 | void setBackgroundPixmap(Pixmap pm); | ||
61 | /// sets background color | ||
62 | void setBackgroundColor(const Color &color); | ||
63 | /// show button | ||
64 | void show(); | ||
65 | /// hide button | ||
66 | void hide(); | ||
67 | virtual void clear() { m_win.clear(); } | ||
68 | /** | ||
69 | @name eventhandlers | ||
70 | */ | ||
71 | //@{ | ||
72 | virtual void buttonPressEvent(XButtonEvent &event); | ||
73 | virtual void buttonReleaseEvent(XButtonEvent &event); | ||
74 | virtual void exposeEvent(XExposeEvent &event); | ||
75 | //@} | ||
76 | |||
77 | /// @return true if the button is pressed, else false | ||
78 | bool pressed() const { return m_pressed; } | ||
79 | /** | ||
80 | @name position and size of the button | ||
81 | */ | ||
82 | //@{ | ||
83 | int x() const { return m_win.x(); } | ||
84 | int y() const { return m_win.y(); } | ||
85 | unsigned int width() const { return m_win.width(); } | ||
86 | unsigned int height() const { return m_win.height(); } | ||
87 | //@} | ||
88 | FbWindow &window() { return m_win; } | ||
89 | const FbWindow &window() const { return m_win; } | ||
90 | GC gc() const { return m_gc; } | ||
91 | |||
92 | private: | ||
93 | FbTk::FbWindow m_win; ///< window for button | ||
94 | Pixmap m_foreground_pm; ///< foreground pixmap | ||
95 | Pixmap m_background_pm; ///< background pixmap | ||
96 | Color m_background_color; ///< background color | ||
97 | Pixmap m_pressed_pm; ///< pressed pixmap | ||
98 | GC m_gc; ///< graphic context for button | ||
99 | bool m_pressed; ///< if the button is pressed | ||
100 | RefCount<Command> m_onclick[5]; ///< what to do when this button is clicked with button num | ||
101 | }; | ||
102 | |||
103 | }; | ||
104 | |||
105 | #endif // FBTK_BUTTON_HH | ||