| 1 |
#if defined(Hiro_MenuRadioItem) |
| 2 |
|
| 3 |
namespace hiro { |
| 4 |
|
| 5 |
static auto MenuRadioItem_activate(GtkCheckMenuItem* gtkCheckMenuItem, pMenuRadioItem* p) -> void { |
| 6 |
p->_doActivate(); |
| 7 |
} |
| 8 |
|
| 9 |
auto pMenuRadioItem::construct() -> void { |
| 10 |
widget = gtk_radio_menu_item_new_with_mnemonic(0, ""); |
| 11 |
gtkCheckMenuItem = GTK_CHECK_MENU_ITEM(widget); |
| 12 |
gtkRadioMenuItem = GTK_RADIO_MENU_ITEM(widget); |
| 13 |
|
| 14 |
setText(state().text); |
| 15 |
|
| 16 |
g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(MenuRadioItem_activate), (gpointer)this); |
| 17 |
} |
| 18 |
|
| 19 |
auto pMenuRadioItem::destruct() -> void { |
| 20 |
if(widget) gtk_widget_destroy(widget), widget = nullptr; |
| 21 |
} |
| 22 |
|
| 23 |
auto pMenuRadioItem::setChecked() -> void { |
| 24 |
lock(); |
| 25 |
gtk_check_menu_item_set_active(gtkCheckMenuItem, true); |
| 26 |
unlock(); |
| 27 |
} |
| 28 |
|
| 29 |
auto pMenuRadioItem::setGroup(sGroup group) -> void { |
| 30 |
maybe<GtkRadioMenuItem*> gtkRadioMenuItem; |
| 31 |
for(auto& weak : group->state.objects) { |
| 32 |
if(auto object = weak.lock()) { |
| 33 |
if(auto menuRadioItem = dynamic_cast<mMenuRadioItem*>(object.get())) { |
| 34 |
if(auto self = menuRadioItem->self()) { |
| 35 |
self->lock(); |
| 36 |
gtk_radio_menu_item_set_group(self->gtkRadioMenuItem, nullptr); |
| 37 |
if(!gtkRadioMenuItem) { |
| 38 |
gtkRadioMenuItem = self->gtkRadioMenuItem; |
| 39 |
gtk_check_menu_item_set_active(self->gtkCheckMenuItem, menuRadioItem->state.checked = true); |
| 40 |
} else { |
| 41 |
gtk_radio_menu_item_set_group(self->gtkRadioMenuItem, gtk_radio_menu_item_get_group(*gtkRadioMenuItem)); |
| 42 |
gtk_check_menu_item_set_active(self->gtkCheckMenuItem, menuRadioItem->state.checked = false); |
| 43 |
} |
| 44 |
self->unlock(); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
auto pMenuRadioItem::setText(const string& text) -> void { |
| 52 |
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), _mnemonic(text)); |
| 53 |
} |
| 54 |
|
| 55 |
auto pMenuRadioItem::groupLocked() const -> bool { |
| 56 |
if(auto group = state().group) { |
| 57 |
for(auto& weak : group->state.objects) { |
| 58 |
if(auto object = weak.lock()) { |
| 59 |
if(auto self = object->self()) { |
| 60 |
if(self->locked()) return true; |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
return false; |
| 65 |
} |
| 66 |
return locked(); |
| 67 |
} |
| 68 |
|
| 69 |
auto pMenuRadioItem::_doActivate() -> void { |
| 70 |
if(groupLocked()) return; |
| 71 |
bool wasChecked = state().checked; |
| 72 |
self().setChecked(); |
| 73 |
if(!wasChecked) self().doActivate(); |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
#endif |