aboutsummaryrefslogtreecommitdiff
path: root/src/IntResMenuItem.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-02-17 12:45:59 (GMT)
committerfluxgen <fluxgen>2003-02-17 12:45:59 (GMT)
commit584440f2b02ba5dba824efee8b7f47da65439d9b (patch)
treea04156ab83360a01bc4b681517ecedc592cf6719 /src/IntResMenuItem.cc
parent2f8e99f9dfcb3212842e7c2b55203d36550a999c (diff)
downloadfluxbox-584440f2b02ba5dba824efee8b7f47da65439d9b.zip
fluxbox-584440f2b02ba5dba824efee8b7f47da65439d9b.tar.bz2
changes resource integer value in the menu
Diffstat (limited to 'src/IntResMenuItem.cc')
-rw-r--r--src/IntResMenuItem.cc70
1 files changed, 70 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
27namespace {
28
29std::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
39IntResMenuItem::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
45void 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}