-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include "panel.h"
#include "part.h"
+#include "style.h"
#include "toggle.h"
using namespace std;
set_text(t);
}
+void Toggle::autosize()
+{
+ if(!style)
+ return;
+
+ Widget::autosize();
+
+ if(const Part *text_part = style->get_part("text"))
+ {
+ const Sides &margin = text_part->get_margin();
+ geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
+ geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
+ }
+
+ rebuild();
+}
+
void Toggle::set_text(const string &t)
{
text = t;
+ signal_autosize_changed.emit();
+ rebuild();
}
void Toggle::set_exclusive(bool e)
exclude_siblings();
}
+void Toggle::exclude_siblings()
+{
+ const list<Widget *> &siblings = parent->get_children();
+ for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
+ if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
+ if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
+ tgl->set_value(false);
+}
+
void Toggle::set_value(bool v)
{
value = v;
if(value)
{
- state |= ACTIVE;
+ set_state(ACTIVE);
if(exclusive && parent)
exclude_siblings();
}
else
- state &= ~ACTIVE;
+ clear_state(ACTIVE);
+}
+
+void Toggle::rebuild_special(const Part &part, CachedPart &cache)
+{
+ if(part.get_name()=="text")
+ text.build(part, geom, cache);
}
void Toggle::button_press(int, int, unsigned btn)
}
}
-void Toggle::render_special(const Part &part) const
-{
- if(part.get_name()=="text")
- text.render(part, geom);
-}
-
-void Toggle::exclude_siblings()
-{
- const list<Widget *> &siblings = parent->get_children();
- for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
- if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
- if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
- tgl->set_value(false);
-}
-
void Toggle::on_style_change()
{
text.set_style(style);
Toggle::Loader::Loader(Toggle &t):
- Widget::Loader(t)
+ DataFile::DerivedObjectLoader<Toggle, Widget::Loader>(t)
{
add("exclusive", &Toggle::exclusive);
add("text", &Loader::text);
add("value", &Toggle::value);
}
-Toggle &Toggle::Loader::get_object() const
-{
- return static_cast<Toggle &>(wdg);
-}
-
void Toggle::Loader::finish()
{
- Toggle &tgl = static_cast<Toggle &>(wdg);
- if(tgl.value)
- tgl.state |= ACTIVE;
- else
- tgl.state &= ~ACTIVE;
+ obj.set_state(ACTIVE, (obj.value ? ACTIVE : NORMAL));
}
void Toggle::Loader::text(const string &t)
{
- static_cast<Toggle &>(wdg).text = t;
+ obj.text = t;
}
} // namespace GLtk