]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/toggle.h
Rework how widget ownership works in Container
[libs/gltk.git] / source / toggle.h
index 305c3ca0617f4d2707c509958a3fe72a07469456..7da0e36996150d8256acfde03621a37d0f620fdd 100644 (file)
@@ -1,14 +1,9 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_GLTK_TOGGLE_H_
 #define MSP_GLTK_TOGGLE_H_
 
 #include <sigc++/signal.h>
+#include "mspgltk_api.h"
+#include "text.h"
 #include "widget.h"
 
 namespace Msp {
@@ -17,33 +12,55 @@ namespace GLtk {
 /**
 Allows toggling a value between two states.
 */
-class Toggle: public Widget
+class MSPGLTK_API Toggle: public Widget
 {
 public:
-       class Loader: public Widget::Loader
+       class MSPGLTK_API Loader: public DataFile::DerivedObjectLoader<Toggle, Widget::Loader>
        {
        public:
                Loader(Toggle &);
-               Toggle &get_object() const;
+
+       private:
+               void finish() override;
+
+               void text(const std::string &);
        };
 
+       sigc::signal<void, bool> signal_toggled;
+
 private:
-       std::string text;
-       bool value;
+       Text text;
+       bool pressed = false;
+       bool value = false;
+       bool exclusive = false;
 
 public:
-       sigc::signal<void, bool> signal_toggled;
+       Toggle(const std::string & = std::string());
 
-       Toggle(const Resources &);
+       const char *get_class() const override { return "toggle"; }
 
+private:
+       void autosize_special(const Part &, Geometry &) const override;
+
+public:
+       void set_text(const std::string &);
+       void set_exclusive(bool);
+       bool get_exclusive() const { return exclusive; }
+private:
+       void exclude_siblings();
+public:
+       void set_value(bool);
        bool get_value() const { return value; }
 
-       virtual void button_release(int, int, unsigned);
-       virtual void pointer_enter();
-       virtual void pointer_leave();
 private:
-       virtual const char *get_class() const { return "toggle"; }
-       virtual void render_special(const Part &) const;
+       void rebuild_special(const Part &) override;
+
+public:
+       void button_press(int, int, unsigned) override;
+       void button_release(int, int, unsigned) override;
+       bool navigate(Navigation) override;
+private:
+       void on_style_change() override;
 };
 
 } // namespace GLtk