diff options
author | fluxgen <fluxgen> | 2003-02-17 12:45:59 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-02-17 12:45:59 (GMT) |
commit | 584440f2b02ba5dba824efee8b7f47da65439d9b (patch) | |
tree | a04156ab83360a01bc4b681517ecedc592cf6719 | |
parent | 2f8e99f9dfcb3212842e7c2b55203d36550a999c (diff) | |
download | fluxbox_pavel-584440f2b02ba5dba824efee8b7f47da65439d9b.zip fluxbox_pavel-584440f2b02ba5dba824efee8b7f47da65439d9b.tar.bz2 |
changes resource integer value in the menu
-rw-r--r-- | src/IntResMenuItem.cc | 70 | ||||
-rw-r--r-- | src/IntResMenuItem.hh | 44 |
2 files changed, 114 insertions, 0 deletions
diff --git a/src/IntResMenuItem.cc b/src/IntResMenuItem.cc new file mode 100644 index 0000000..b272268 --- /dev/null +++ b/src/IntResMenuItem.cc | |||
@@ -0,0 +1,70 @@ | |||
1 | // IntResMenuItem.cc for Fluxbox Window Manager | ||
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: IntResMenuItem.cc,v 1.1 2003/02/17 12:45:59 fluxgen Exp $ | ||
23 | |||
24 | #include "IntResMenuItem.hh" | ||
25 | #include <cstdio> | ||
26 | |||
27 | namespace { | ||
28 | |||
29 | std::string appendIntValue(const std::string &label, int value) { | ||
30 | char *buff = new char[label.size() + 16]; | ||
31 | sprintf(buff, "%s: %d", label.c_str(), value); | ||
32 | std::string ret(buff); | ||
33 | delete [] buff; | ||
34 | return ret; | ||
35 | } | ||
36 | |||
37 | }; | ||
38 | |||
39 | IntResMenuItem::IntResMenuItem(const char *label, Resource<int> &res, int min_val, int max_val): | ||
40 | FbTk::MenuItem(label), m_org_label(FbTk::MenuItem::label()), | ||
41 | m_max(max_val), m_min(min_val), m_res(res) { | ||
42 | setLabel(appendIntValue(m_org_label, *m_res).c_str()); | ||
43 | } | ||
44 | |||
45 | void IntResMenuItem::click(int button, int time) { | ||
46 | static int last_time = -201; | ||
47 | int inc_val = 1; | ||
48 | // check double click | ||
49 | //!! TODO: must have some sort of "global" double click time in FbTk | ||
50 | if (time - last_time <= 200) | ||
51 | inc_val = 5; | ||
52 | |||
53 | last_time = time; | ||
54 | |||
55 | if ((button == 4 || button == 3)&& *m_res < m_max) // scroll up | ||
56 | (*m_res) += inc_val; | ||
57 | else if ((button == 5 || button == 1) && *m_res > m_min) // scroll down | ||
58 | (*m_res) -= inc_val; | ||
59 | |||
60 | // clamp value | ||
61 | if (*m_res > m_max) | ||
62 | *m_res = m_max; | ||
63 | else if (*m_res < m_min) | ||
64 | *m_res = m_min; | ||
65 | |||
66 | // update label | ||
67 | setLabel(appendIntValue(m_org_label, *m_res).c_str()); | ||
68 | // call other commands | ||
69 | MenuItem::click(button, time); | ||
70 | } | ||
diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh new file mode 100644 index 0000000..3466c91 --- /dev/null +++ b/src/IntResMenuItem.hh | |||
@@ -0,0 +1,44 @@ | |||
1 | // IntResMenuItem.hh for Fluxbox Window Manager | ||
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: IntResMenuItem.hh,v 1.1 2003/02/17 12:45:58 fluxgen Exp $ | ||
23 | |||
24 | #ifndef INTRESMENUITEM_HH | ||
25 | #define INTRESMENUITEM_HH | ||
26 | |||
27 | #include "MenuItem.hh" | ||
28 | #include "Resource.hh" | ||
29 | |||
30 | /// Changes an resource integer value between min and max | ||
31 | class IntResMenuItem: public FbTk::MenuItem { | ||
32 | public: | ||
33 | IntResMenuItem(const char *label, Resource<int> &res, int min_val, int max_val); | ||
34 | |||
35 | void click(int button, int time); | ||
36 | |||
37 | private: | ||
38 | std::string m_org_label; ///< original label | ||
39 | const int m_max; ///< maximum value the integer can have | ||
40 | const int m_min; ///< minimum value the integer can have | ||
41 | Resource<int> &m_res; ///< resource item to be changed | ||
42 | }; | ||
43 | |||
44 | #endif // INTRESMENUITEM_HH | ||