aboutsummaryrefslogtreecommitdiff
path: root/src/IntResMenuItem.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/IntResMenuItem.hh')
-rw-r--r--src/IntResMenuItem.hh100
1 files changed, 0 insertions, 100 deletions
diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh
deleted file mode 100644
index 3de4b5f..0000000
--- a/src/IntResMenuItem.hh
+++ /dev/null
@@ -1,100 +0,0 @@
1// IntResMenuItem.hh for Fluxbox Window Manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
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$
23
24#ifndef INTRESMENUITEM_HH
25#define INTRESMENUITEM_HH
26
27#include "MenuItem.hh"
28#include "Resource.hh"
29
30#include <string>
31
32/// Changes an resource integer value between min and max
33template <typename Type>
34class IntResMenuItem: public FbTk::MenuItem {
35public:
36 IntResMenuItem(const FbTk::FbString &label, Type &res, int min_val, int max_val, FbTk::Menu &host_menu) :
37 FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()),
38 m_max(max_val), m_min(min_val), m_res(res) {
39 updateLabel();
40 setCloseOnClick(false);
41 }
42
43 /* Utility, but doesn't get found in anonymous namespace? */
44 std::string appendIntValue(const std::string &label, int value) {
45 char *buff = new char[label.size() + 16];
46 sprintf(buff, "%s: %d", label.c_str(), value);
47 std::string ret(buff);
48 delete [] buff;
49 return ret;
50 }
51
52 void click(int button, int time, unsigned int mods) {
53 static int last_time = -201;
54 int inc_val = 1;
55 // check double click
56 //!! TODO: must have some sort of "global" double click time in FbTk
57 if (time - last_time <= 200)
58 inc_val = 5;
59
60 last_time = time;
61
62 // make sure values stay within bounds _before_ we try to set m_res
63 // otherwise, this may cause bugs (say, with casting to unsigned char)
64 if ((button == 4 || button == 3) && *m_res < m_max) { // up
65 if (*m_res + inc_val < m_max)
66 m_res.get() += inc_val;
67 else
68 m_res.get() = m_max;
69 } else if ((button == 5 || button == 1) && *m_res > m_min) { // down
70 if (*m_res - inc_val >= m_min)
71 m_res.get() -= inc_val;
72 else
73 m_res.get() = m_min;
74 }
75
76 // update label
77 updateLabel();
78 // call other commands
79 FbTk::MenuItem::click(button, time, mods);
80
81 // show new value, which for us means forcing a full menu update
82 // since the text is drawn onto the background!
83 if (menu()) {
84 menu()->frameWindow().updateBackground(false);
85 menu()->clearWindow();
86 }
87 }
88
89 void updateLabel() {
90 setLabel(appendIntValue(m_org_label, *m_res));
91 }
92
93private:
94 std::string m_org_label; ///< original label
95 const int m_max; ///< maximum value the integer can have
96 const int m_min; ///< minimum value the integer can have
97 Type &m_res; ///< resource item to be changed
98};
99
100#endif // INTRESMENUITEM_HH