]> git.tdb.fi Git - libs/gltk.git/blob - source/toggle.h
58a03b6ea1aad0cdc5399213b1709946c4705679
[libs/gltk.git] / source / toggle.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007-2011  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 "text.h"
13 #include "widget.h"
14
15 namespace Msp {
16 namespace GLtk {
17
18 /**
19 Allows toggling a value between two states.
20 */
21 class Toggle: public Widget
22 {
23 public:
24         class Loader: public Widget::Loader
25         {
26         public:
27                 Loader(Toggle &);
28                 Toggle &get_object() const;
29         private:
30                 virtual void finish();
31                 void text(const std::string &);
32         };
33
34         sigc::signal<void, bool> signal_toggled;
35
36 private:
37         Text text;
38         bool pressed;
39         bool value;
40         bool exclusive;
41
42 public:
43         Toggle(const std::string & = std::string());
44
45         virtual const char *get_class() const { return "toggle"; }
46
47         virtual void autosize();
48
49         void set_text(const std::string &);
50         void set_exclusive(bool);
51         bool get_exclusive() const { return exclusive; }
52 private:
53         void exclude_siblings();
54 public:
55         void set_value(bool);
56         bool get_value() const { return value; }
57
58 private:
59         virtual void render_special(const Part &) const;
60
61 public:
62         virtual void button_press(int, int, unsigned);
63         virtual void button_release(int, int, unsigned);
64 private:
65         virtual void on_style_change();
66 };
67
68 } // namespace GLtk
69 } // namespace Msp
70
71 #endif