Debian Codegraph @

phoenix/gtk/action/radio-item.cpp

raw
1 namespace phoenix {
2
3 static void RadioItem_activate(GtkCheckMenuItem* gtkCheckMenuItem, RadioItem* self) {
4 self->p.onActivate();
5 }
6
7 void pRadioItem::setChecked() {
8 parent().locked = true;
9 for(auto& item : radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false);
10 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true);
11 parent().locked = false;
12 }
13
14 void pRadioItem::setGroup(const group<RadioItem>& group) {
15 parent().locked = true;
16 for(auto& item : group) {
17 if(&item == &group.first()) continue;
18 GSList* currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group.first().p.widget));
19 if(currentGroup != gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item.p.widget))) {
20 gtk_radio_menu_item_set_group(GTK_RADIO_MENU_ITEM(item.p.widget), currentGroup);
21 }
22 }
23 parent().locked = false;
24 }
25
26 void pRadioItem::setText(string text) {
27 gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text));
28 }
29
30 void pRadioItem::constructor() {
31 widget = gtk_radio_menu_item_new_with_mnemonic(0, "");
32 setGroup(radioItem.state.group);
33 setText(radioItem.state.text);
34 for(auto& item : radioItem.state.group) {
35 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), item.state.checked);
36 }
37 g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_activate), (gpointer)&radioItem);
38 }
39
40 void pRadioItem::destructor() {
41 gtk_widget_destroy(widget);
42 }
43
44 void pRadioItem::orphan() {
45 destructor();
46 constructor();
47 }
48
49 void pRadioItem::onActivate() {
50 if(parent().locked) return;
51 bool wasChecked = radioItem.state.checked;
52 radioItem.setChecked();
53 if(wasChecked) return;
54 if(radioItem.onActivate) radioItem.onActivate();
55 }
56
57 pRadioItem& pRadioItem::parent() {
58 if(radioItem.state.group.size()) return radioItem.state.group.first().p;
59 return *this;
60 }
61
62 }