aboutsummaryrefslogtreecommitdiff
path: root/src/IntResMenuItem.hh
diff options
context:
space:
mode:
authorsimonb <simonb>2007-01-07 11:55:14 (GMT)
committersimonb <simonb>2007-01-07 11:55:14 (GMT)
commit1cc7b60aa2c2e7a26f9ff6f1461ca0b8a97be8de (patch)
tree1de2b149b23e589a36c81bd2aa51092db7b6e190 /src/IntResMenuItem.hh
parentcfd33dd7a8f392253d8af9f418d86dc3083fc27d (diff)
downloadfluxbox-1cc7b60aa2c2e7a26f9ff6f1461ca0b8a97be8de.zip
fluxbox-1cc7b60aa2c2e7a26f9ff6f1461ca0b8a97be8de.tar.bz2
per-window transparency, including apps and menu support, plus some
infrastructure and related changes. Thanks for original patch from Julien Trolet, dmxen at sourceforge dot net
Diffstat (limited to 'src/IntResMenuItem.hh')
-rw-r--r--src/IntResMenuItem.hh59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh
index a0e102d..0be2775 100644
--- a/src/IntResMenuItem.hh
+++ b/src/IntResMenuItem.hh
@@ -27,18 +27,71 @@
27#include "MenuItem.hh" 27#include "MenuItem.hh"
28#include "Resource.hh" 28#include "Resource.hh"
29 29
30#include <string>
31
30/// Changes an resource integer value between min and max 32/// Changes an resource integer value between min and max
33template <typename Type>
31class IntResMenuItem: public FbTk::MenuItem { 34class IntResMenuItem: public FbTk::MenuItem {
32public: 35public:
33 IntResMenuItem(const FbTk::FbString &label, FbTk::Resource<int> &res, int min_val, int max_val, FbTk::Menu &host_menu); 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 }
41
42 /* Utility, but doesn't get found in anonymous namespace? */
43 std::string appendIntValue(const std::string &label, int value) {
44 char *buff = new char[label.size() + 16];
45 sprintf(buff, "%s: %d", label.c_str(), value);
46 std::string ret(buff);
47 delete [] buff;
48 return ret;
49 }
50
51 void click(int button, int time) {
52 static int last_time = -201;
53 int inc_val = 1;
54 // check double click
55 //!! TODO: must have some sort of "global" double click time in FbTk
56 if (time - last_time <= 200)
57 inc_val = 5;
58
34 59
35 void click(int button, int time); 60 last_time = time;
61
62 if ((button == 4 || button == 3)&& *m_res < m_max) // scroll up
63 m_res.get() += inc_val;
64 else if ((button == 5 || button == 1) && *m_res > m_min) // scroll down
65 m_res.get() -= inc_val;
66
67 // clamp value
68 if (*m_res > m_max)
69 m_res.get() = m_max;
70 else if (*m_res < m_min)
71 m_res.get() = m_min;
72
73 // update label
74 updateLabel();
75 // call other commands
76 FbTk::MenuItem::click(button, time);
77
78 // show new value, which for us means forcing a full menu update
79 // since the text is drawn onto the background!
80 if (menu()) {
81 menu()->frameWindow().updateBackground(false);
82 menu()->clearWindow();
83 }
84 }
36 85
86 void updateLabel() {
87 setLabel(appendIntValue(m_org_label, *m_res));
88 }
89
37private: 90private:
38 std::string m_org_label; ///< original label 91 std::string m_org_label; ///< original label
39 const int m_max; ///< maximum value the integer can have 92 const int m_max; ///< maximum value the integer can have
40 const int m_min; ///< minimum value the integer can have 93 const int m_min; ///< minimum value the integer can have
41 FbTk::Resource<int> &m_res; ///< resource item to be changed 94 Type &m_res; ///< resource item to be changed
42}; 95};
43 96
44#endif // INTRESMENUITEM_HH 97#endif // INTRESMENUITEM_HH