2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
static void CheckButton_toggle(GtkToggleButton* toggleButton, CheckButton* self) {
|
|
|
|
self->p.onToggle();
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Size pCheckButton::minimumSize() {
|
|
|
|
Size size = pFont::size(widget.state.font, checkButton.state.text);
|
2013-11-28 10:29:01 +00:00
|
|
|
|
|
|
|
if(checkButton.state.orientation == Orientation::Horizontal) {
|
|
|
|
size.width += checkButton.state.image.width;
|
|
|
|
size.height = max(checkButton.state.image.height, size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(checkButton.state.orientation == Orientation::Vertical) {
|
|
|
|
size.width = max(checkButton.state.image.width, size.width);
|
|
|
|
size.height += checkButton.state.image.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {size.width + 24, size.height + 12};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::setChecked(bool checked) {
|
|
|
|
locked = true;
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), checked);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCheckButton::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-05-05 09:21:30 +00:00
|
|
|
void pCheckButton::setText(string text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
2013-11-28 10:29:01 +00:00
|
|
|
setFont(widget.state.font);
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::constructor() {
|
2013-11-28 10:29:01 +00:00
|
|
|
gtkWidget = gtk_toggle_button_new();
|
|
|
|
g_signal_connect(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckButton_toggle), (gpointer)&checkButton);
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
setChecked(checkButton.state.checked);
|
|
|
|
setText(checkButton.state.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::destructor() {
|
|
|
|
gtk_widget_destroy(gtkWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCheckButton::onToggle() {
|
|
|
|
if(locked) return;
|
|
|
|
checkButton.state.checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget));
|
|
|
|
if(checkButton.onToggle) checkButton.onToggle();
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|