]> git.tdb.fi Git - libs/gltk.git/blob - source/toggle.h
Support exclusive Toggles for implementing option buttons
[libs/gltk.git] / source / toggle.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_TOGGLE_H_
9 #define MSP_GLTK_TOGGLE_H_
10
11 #include <sigc++/signal.h>
12 #include "widget.h"
13
14 namespace Msp {
15 namespace GLtk {
16
17 /**
18 Allows toggling a value between two states.
19 */
20 class Toggle: public Widget
21 {
22 public:
23         class Loader: public Widget::Loader
24         {
25         public:
26                 Loader(Toggle &);
27                 Toggle &get_object() const;
28         private:
29                 virtual void finish();
30         };
31
32 private:
33         std::string text;
34         bool pressed;
35         bool value;
36         bool exclusive;
37
38 public:
39         sigc::signal<void, bool> signal_toggled;
40
41         Toggle(const Resources &);
42
43         void set_text(const std::string &);
44         void set_exclusive(bool);
45         bool get_exclusive() const { return exclusive; }
46         void set_value(bool);
47         bool get_value() const { return value; }
48
49         virtual void button_press(int, int, unsigned);
50         virtual void button_release(int, int, unsigned);
51 private:
52         virtual const char *get_class() const { return "toggle"; }
53         virtual void render_special(const Part &) const;
54
55         void exclude_siblings();
56 };
57
58 } // namespace GLtk
59 } // namespace Msp
60
61 #endif