2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
static void RadioButton_activate(GtkToggleButton* toggleButton, RadioButton* self) {
|
2013-03-15 13:11:33 +00:00
|
|
|
self->p.onActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
Size pRadioButton::minimumSize() {
|
|
|
|
Size size = pFont::size(widget.state.font, radioButton.state.text);
|
2013-11-28 10:29:01 +00:00
|
|
|
|
|
|
|
if(radioButton.state.orientation == Orientation::Horizontal) {
|
|
|
|
size.width += radioButton.state.image.width;
|
|
|
|
size.height = max(radioButton.state.image.height, size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(radioButton.state.orientation == Orientation::Vertical) {
|
|
|
|
size.width = max(radioButton.state.image.width, size.width);
|
|
|
|
size.height += radioButton.state.image.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {size.width + 24, size.height + 12};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::setChecked() {
|
|
|
|
parent().locked = true;
|
2013-11-28 10:29:01 +00:00
|
|
|
for(auto& item : radioButton.state.group) {
|
|
|
|
bool checked = &item == &radioButton;
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item.p.gtkWidget), item.state.checked = checked);
|
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
parent().locked = false;
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pRadioButton::setGroup(const group<RadioButton>& group) {
|
2013-03-15 13:11:33 +00:00
|
|
|
parent().locked = true;
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& item : radioButton.state.group) {
|
2013-11-28 10:29:01 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item.p.gtkWidget), item.state.checked);
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
parent().locked = false;
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pRadioButton::setImage(const image& image, Orientation orientation) {
|
|
|
|
if(image.empty() == false) {
|
|
|
|
GtkImage* gtkImage = CreateImage(image);
|
|
|
|
gtk_button_set_image(GTK_BUTTON(gtkWidget), (GtkWidget*)gtkImage);
|
|
|
|
} else {
|
|
|
|
gtk_button_set_image(GTK_BUTTON(gtkWidget), nullptr);
|
|
|
|
}
|
|
|
|
switch(orientation) {
|
|
|
|
case Orientation::Horizontal: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_LEFT); break;
|
|
|
|
case Orientation::Vertical: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_TOP); break;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pRadioButton::setText(string text) {
|
|
|
|
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
|
|
|
setFont(widget.state.font);
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::constructor() {
|
2013-11-28 10:29:01 +00:00
|
|
|
gtkWidget = gtk_toggle_button_new();
|
|
|
|
g_signal_connect(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioButton_activate), (gpointer)&radioButton);
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
setGroup(radioButton.state.group);
|
|
|
|
setText(radioButton.state.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::destructor() {
|
|
|
|
gtk_widget_destroy(gtkWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pRadioButton::onActivate() {
|
|
|
|
if(parent().locked) return;
|
|
|
|
bool wasChecked = radioButton.state.checked;
|
|
|
|
setChecked();
|
|
|
|
if(!wasChecked) {
|
|
|
|
if(radioButton.onActivate) radioButton.onActivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pRadioButton& pRadioButton::parent() {
|
|
|
|
if(radioButton.state.group.size()) return radioButton.state.group.first().p;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|