| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
static void RadioLabel_activate(GtkToggleButton* toggleButton, RadioLabel* self) { |
| 4 |
self->p.onActivate(); |
| 5 |
} |
| 6 |
|
| 7 |
Size pRadioLabel::minimumSize() { |
| 8 |
Size size = pFont::size(widget.state.font, radioLabel.state.text); |
| 9 |
return {size.width + 28, size.height + 4}; |
| 10 |
} |
| 11 |
|
| 12 |
void pRadioLabel::setChecked() { |
| 13 |
parent().locked = true; |
| 14 |
for(auto& item : radioLabel.state.group) item.state.checked = false; |
| 15 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), radioLabel.state.checked = true); |
| 16 |
parent().locked = false; |
| 17 |
} |
| 18 |
|
| 19 |
void pRadioLabel::setGroup(const group<RadioLabel>& group) { |
| 20 |
if(&parent() == this) return; |
| 21 |
parent().locked = true; |
| 22 |
gtk_radio_button_set_group( |
| 23 |
GTK_RADIO_BUTTON(gtkWidget), |
| 24 |
gtk_radio_button_get_group(GTK_RADIO_BUTTON(parent().gtkWidget)) |
| 25 |
); |
| 26 |
for(auto& item : radioLabel.state.group) { |
| 27 |
if(item.state.checked) { |
| 28 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item.p.gtkWidget), true); |
| 29 |
break; |
| 30 |
} |
| 31 |
} |
| 32 |
parent().locked = false; |
| 33 |
} |
| 34 |
|
| 35 |
void pRadioLabel::setText(string text) { |
| 36 |
gtk_button_set_label(GTK_BUTTON(gtkWidget), text); |
| 37 |
} |
| 38 |
|
| 39 |
void pRadioLabel::constructor() { |
| 40 |
gtkWidget = gtk_radio_button_new_with_label(nullptr, ""); |
| 41 |
g_signal_connect(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioLabel_activate), (gpointer)&radioLabel); |
| 42 |
|
| 43 |
setGroup(radioLabel.state.group); |
| 44 |
setText(radioLabel.state.text); |
| 45 |
} |
| 46 |
|
| 47 |
void pRadioLabel::destructor() { |
| 48 |
gtk_widget_destroy(gtkWidget); |
| 49 |
} |
| 50 |
|
| 51 |
void pRadioLabel::orphan() { |
| 52 |
destructor(); |
| 53 |
constructor(); |
| 54 |
} |
| 55 |
|
| 56 |
void pRadioLabel::onActivate() { |
| 57 |
if(parent().locked) return; |
| 58 |
bool wasChecked = radioLabel.state.checked; |
| 59 |
setChecked(); |
| 60 |
if(wasChecked) return; |
| 61 |
if(radioLabel.onActivate) radioLabel.onActivate(); |
| 62 |
} |
| 63 |
|
| 64 |
pRadioLabel& pRadioLabel::parent() { |
| 65 |
if(radioLabel.state.group.size()) return radioLabel.state.group.first().p; |
| 66 |
return *this; |
| 67 |
} |
| 68 |
|
| 69 |
} |