From fa8a2ee7e2539b145a87ac9af0d9748effa91631 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Tue, 27 Jun 2017 15:03:58 +0200 Subject: GdkScreen deprecation fixes --- src/ui/interface.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 7e80c1a2f..9abc1f07b 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -30,6 +30,10 @@ #include #include +#if WITH_GTKMM_3_22 +# include +#endif + #include "inkscape.h" #include "extension/db.h" #include "extension/effect.h" @@ -176,13 +180,26 @@ sp_create_window(SPViewWidget *vw, bool editable) gint full = prefs->getBool("/desktop/geometry/fullscreen"); gint maxed = prefs->getBool("/desktop/geometry/maximized"); if (pw>0 && ph>0) { - gint w = MIN(gdk_screen_width(), pw); - gint h = MIN(gdk_screen_height(), ph); - gint x = MIN(gdk_screen_width() - MIN_ONSCREEN_DISTANCE, px); - gint y = MIN(gdk_screen_height() - MIN_ONSCREEN_DISTANCE, py); +#if WITH_GTKMM_3_22 + auto const display = Gdk::Display::get_default(); + auto const monitor = display->get_primary_monitor(); + + // A Gdk::Rectangle in "application pixel" units + Gdk::Rectangle screen_geometry; + monitor->get_geometry(screen_geometry); + auto const screen_width = screen_geometry.get_width(); + auto const screen_height = screen_geometry.get_height(); +#else + auto const screen_width = gdk_screen_width(); + auto const screen_height = gdk_screen_height(); +#endif + gint w = MIN(screen_width, pw); + gint h = MIN(screen_height, ph); + gint x = MIN(screen_width - MIN_ONSCREEN_DISTANCE, px); + gint y = MIN(screen_height - MIN_ONSCREEN_DISTANCE, py); if (w>0 && h>0) { - x = MIN(gdk_screen_width() - w, x); - y = MIN(gdk_screen_height() - h, y); + x = MIN(screen_width - w, x); + y = MIN(screen_height - h, y); desktop->setWindowSize(w, h); } -- cgit v1.2.3 From 01c2a93d46c214b7e6afe55fd8815d66cf6be9c6 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Tue, 27 Jun 2017 16:33:11 +0200 Subject: Initial addition of menu icons --- src/ui/interface.cpp | 80 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 32 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 9abc1f07b..6c95c65a3 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -406,23 +406,6 @@ sp_ui_menu_deselect(gpointer object) view->tipsMessageContext()->clear(); } -/** - * Creates and attaches a scaled icon to the given menu item. - */ -static void -sp_ui_menuitem_add_icon( GtkWidget *item, gchar *icon_name ) -{ - static bool iconsInjected = false; - if ( !iconsInjected ) { - iconsInjected = true; - injectRenamedIcons(); - } - GtkWidget *icon; - - icon = sp_icon_new( Inkscape::ICON_SIZE_MENU, icon_name ); - gtk_widget_show(icon); - gtk_image_menu_item_set_image((GtkImageMenuItem *) item, icon); -} // end of sp_ui_menu_add_icon void sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) @@ -452,7 +435,6 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) } } - /** * Appends a custom menu UI from a verb. * @@ -460,25 +442,45 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) */ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape::UI::View::View *view, bool radio = false, GSList *group = NULL) { - SPAction *action; GtkWidget *item; + // Just create a menu separator if this isn't a real action. + // Otherwise, create a real menu item if (verb->get_code() == SP_VERB_NONE) { item = gtk_separator_menu_item_new(); } else { + SPAction *action = verb->get_action(Inkscape::ActionContext(view)); - action = verb->get_action(Inkscape::ActionContext(view)); if (!action) return NULL; + // Create a box to contain all the widgets (icon, label, accelerator) + // that will go inside the menu item + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); + + // If there is an image associated with the action, then we can add it as an + // icon for the menu item + if(action->image) { + GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); + gtk_container_add(GTK_CONTAINER(box), icon); + } + + // Now create the label and add it to the menu item + GtkWidget *label = gtk_label_new_with_mnemonic(action->name); + gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name); + gtk_container_add(GTK_CONTAINER(box), label); + + // Create the menu item itself, either as a radio menu item, or just + // a regular menu item depending on whether the "radio" flag is set if (radio) { - item = gtk_radio_menu_item_new_with_mnemonic(group, action->name); + item = gtk_radio_menu_item_new(group); } else { - item = gtk_image_menu_item_new_with_mnemonic(action->name); + item = gtk_menu_item_new(); } - gtk_label_set_markup_with_mnemonic( GTK_LABEL(gtk_bin_get_child(GTK_BIN (item))), action->name); + // Finally, pack all the widgets into the menu item + gtk_container_add(GTK_CONTAINER(item), box); GtkAccelGroup *accel_group = sp_shortcut_get_accel_group(); gtk_menu_set_accel_group(menu, accel_group); @@ -498,9 +500,6 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb gtk_widget_set_sensitive(item, FALSE); } - if (action->image) { - sp_ui_menuitem_add_icon(item, action->image); - } gtk_widget_set_events(item, GDK_KEY_PRESS_MASK); g_object_set_data(G_OBJECT(item), "view", (gpointer) view); g_signal_connect( G_OBJECT(item), "activate", G_CALLBACK(sp_ui_menu_activate), action ); @@ -508,7 +507,7 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb g_signal_connect( G_OBJECT(item), "deselect", G_CALLBACK(sp_ui_menu_deselect_action), action ); } - gtk_widget_show(item); + gtk_widget_show_all(item); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); return item; @@ -1607,6 +1606,7 @@ void ContextMenu::UnHideBelow(std::vector items) } } +// TODO: Update this to allow radio items to be used void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)//, bool radio, GSList *group) { SPAction *action; @@ -1622,7 +1622,25 @@ void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)// return; } - Gtk::ImageMenuItem *item = Gtk::manage(new Gtk::ImageMenuItem(action->name, true)); + // Create a box to contain all the widgets (icon, label, accelerator) + // that will go inside the menu item + auto const box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 6)); + + // If there is an image associated with the action, then we can add it as an + // icon for the menu item + if (action->image) { + auto const icon = Gtk::manage(new Gtk::Image()); + icon->set_from_icon_name(action->image, Gtk::ICON_SIZE_MENU); + box->add(*icon); + } + + // Now create the label and add it to the menu item (with mnemonic + auto const label = Gtk::manage(new Gtk::Label(action->name, true)); + box->add(*label); + + // Create the menu item itself, either as a radio menu item, or just + // a regular menu item depending on whether the "radio" flag is set + auto const item = Gtk::manage(new Gtk::MenuItem(*box)); sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb)); @@ -1633,14 +1651,12 @@ void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)// item->set_sensitive(FALSE); } - if (action->image) { - sp_ui_menuitem_add_icon((GtkWidget*)item->gobj(), action->image); - } + item->set_events(Gdk::KEY_PRESS_MASK); item->signal_activate().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_activate),item,action)); item->signal_select().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_select_action),item,action)); item->signal_deselect().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_deselect_action),item,action)); - item->show(); + item->show_all(); append(*item); } } -- cgit v1.2.3 From 58928f3ed2adc05902c3fb2daf15b27a100c14f3 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Wed, 28 Jun 2017 00:04:40 +0200 Subject: Partial fix for menu items and split contextmenu into separate file --- src/ui/interface.cpp | 929 ++------------------------------------------------- 1 file changed, 36 insertions(+), 893 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 6c95c65a3..c2ce9e568 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -27,8 +27,6 @@ #include #include "file.h" #include -#include -#include #if WITH_GTKMM_3_22 # include @@ -447,45 +445,55 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb // Just create a menu separator if this isn't a real action. // Otherwise, create a real menu item if (verb->get_code() == SP_VERB_NONE) { - item = gtk_separator_menu_item_new(); - } else { SPAction *action = verb->get_action(Inkscape::ActionContext(view)); if (!action) return NULL; + // Create the menu item itself, either as a radio menu item, or just + // a regular menu item depending on whether the "radio" flag is set + if (radio) { + item = gtk_radio_menu_item_new(group); + } else { + item = gtk_menu_item_new(); + } + // Create a box to contain all the widgets (icon, label, accelerator) // that will go inside the menu item - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + + // Now create the label and add it to the menu item + GtkWidget *label = gtk_accel_label_new(action->name); + gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name); + gtk_label_set_use_underline(GTK_LABEL(label), true); + gtk_label_set_xalign(GTK_LABEL(label), 0.0); + + GtkAccelGroup *accel_group = sp_shortcut_get_accel_group(); + gtk_menu_set_accel_group(menu, accel_group); + + sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb)); + gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), item); // If there is an image associated with the action, then we can add it as an - // icon for the menu item + // icon for the menu item. If not, give the label a bit more space if(action->image) { GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); - gtk_container_add(GTK_CONTAINER(box), icon); + gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0); + } + else { + GtkWidget *fake_icon = gtk_label_new(""); + gtk_widget_set_size_request(label, 16, 16); + gtk_widget_set_hexpand(label, true); + gtk_box_pack_start(GTK_BOX(box), fake_icon, FALSE, TRUE, 16); } - // Now create the label and add it to the menu item - GtkWidget *label = gtk_label_new_with_mnemonic(action->name); - gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name); - gtk_container_add(GTK_CONTAINER(box), label); + gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); - // Create the menu item itself, either as a radio menu item, or just - // a regular menu item depending on whether the "radio" flag is set - if (radio) { - item = gtk_radio_menu_item_new(group); - } else { - item = gtk_menu_item_new(); - } // Finally, pack all the widgets into the menu item gtk_container_add(GTK_CONTAINER(item), box); - GtkAccelGroup *accel_group = sp_shortcut_get_accel_group(); - gtk_menu_set_accel_group(menu, accel_group); - - sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb)); action->signal_set_sensitive.connect( sigc::bind<0>( @@ -1398,8 +1406,13 @@ sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name) if (GTK_IS_LABEL(child)) { gtk_label_set_markup_with_mnemonic(GTK_LABEL (child), name.c_str()); } else if (GTK_IS_BOX(child)) { + GList *children = gtk_container_get_children(GTK_CONTAINER(child)); + + // Label is second child in list + GtkWidget *label = GTK_WIDGET(children->next->data); + gtk_label_set_markup_with_mnemonic( - GTK_LABEL (gtk_container_get_children(GTK_CONTAINER (child))->data), + GTK_LABEL (label), name.c_str()); }//else sp_ui_menu_append_item_from_verb has been modified and can set //a menu item in yet another way... @@ -1433,876 +1446,6 @@ void injectRenamedIcons() } } - -ContextMenu::ContextMenu(SPDesktop *desktop, SPItem *item) : - _item(item), - MIGroup(), - MIParent(_("Go to parent")) -{ -// g_message("ContextMenu"); - _object = static_cast(item); - _desktop = desktop; - - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_UNDO)); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_REDO)); - AddSeparator(); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_CUT)); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_COPY)); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_PASTE)); - AddSeparator(); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DUPLICATE)); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DELETE)); - - positionOfLastDialog = 10; // 9 in front + 1 for the separator in the next if; used to position the dialog menu entries below each other - /* Item menu */ - if (item!=NULL) { - AddSeparator(); - MakeObjectMenu(); - } - AddSeparator(); - /* Lock/Unock Hide/Unhide*/ - Geom::Rect b(_desktop->point(),_desktop->point() + Geom::Point(1,1)); - std::vector< SPItem * > down_items = _desktop->getDocument()->getItemsPartiallyInBox( _desktop->dkey, b, true, true); - bool has_down_hidden = false; - bool has_down_locked = false; - for(std::vector< SPItem * >::iterator down = down_items.begin(); down != down_items.end(); ++down){ - if((*down)->isHidden()) { - has_down_hidden = true; - } - if((*down)->isLocked()) { - has_down_locked = true; - } - } - Gtk::MenuItem* mi; - - mi = Gtk::manage(new Gtk::MenuItem(_("Hide selected objects"),1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::HideSelected)); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(false); - } - mi->show(); - append(*mi);//insert(*mi,positionOfLastDialog++); - - mi = Gtk::manage(new Gtk::MenuItem(_("Unhide objects below"),1)); - mi->signal_activate().connect(sigc::bind >(sigc::mem_fun(*this, &ContextMenu::UnHideBelow), down_items)); - if (!has_down_hidden) { - mi->set_sensitive(false); - } - mi->show(); - append(*mi);//insert(*mi,positionOfLastDialog++); - - mi = Gtk::manage(new Gtk::MenuItem(_("Lock selected objects"),1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::LockSelected)); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(false); - } - mi->show(); - append(*mi);//insert(*mi,positionOfLastDialog++); - - mi = Gtk::manage(new Gtk::MenuItem(_("Unlock objects below"),1)); - mi->signal_activate().connect(sigc::bind >(sigc::mem_fun(*this, &ContextMenu::UnLockBelow), down_items)); - if (!has_down_locked) { - mi->set_sensitive(false); - } - mi->show(); - append(*mi);//insert(*mi,positionOfLastDialog++); - /* layer menu */ - SPGroup *group=NULL; - if (item) { - if (SP_IS_GROUP(item)) { - group = SP_GROUP(item); - } else if ( item != _desktop->currentRoot() && SP_IS_GROUP(item->parent) ) { - group = SP_GROUP(item->parent); - } - } - - if (( group && group != _desktop->currentLayer() ) || - ( _desktop->currentLayer() != _desktop->currentRoot() && _desktop->currentLayer()->parent != _desktop->currentRoot() ) ) { - AddSeparator(); - } - - if ( group && group != _desktop->currentLayer() ) { - /* TRANSLATORS: #%1 is the id of the group e.g. , not a number. */ - MIGroup.set_label (Glib::ustring::compose(_("Enter group #%1"), group->getId())); - MIGroup.set_data("group", group); - MIGroup.signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &ContextMenu::EnterGroup),&MIGroup)); - MIGroup.show(); - append(MIGroup); - } - - if ( _desktop->currentLayer() != _desktop->currentRoot() ) { - if ( _desktop->currentLayer()->parent != _desktop->currentRoot() ) { - MIParent.signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::LeaveGroup)); - MIParent.show(); - append(MIParent); - - /* Pop selection out of group */ - Gtk::MenuItem* miu = Gtk::manage(new Gtk::MenuItem(_("_Pop selection out of group"), 1)); - miu->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroupPopSelection)); - miu->show(); - append(*miu); - } - } -} - -ContextMenu::~ContextMenu(void) -{ -} - -Gtk::SeparatorMenuItem* ContextMenu::AddSeparator(void) -{ - Gtk::SeparatorMenuItem* sep = Gtk::manage(new Gtk::SeparatorMenuItem()); - sep->show(); - append(*sep); - return sep; -} - -void ContextMenu::EnterGroup(Gtk::MenuItem* mi) -{ - _desktop->setCurrentLayer(reinterpret_cast(mi->get_data("group"))); - _desktop->selection->clear(); -} - -void ContextMenu::LeaveGroup(void) -{ - _desktop->setCurrentLayer(_desktop->currentLayer()->parent); -} - -void ContextMenu::LockSelected(void) -{ - auto itemlist = _desktop->selection->items(); - for(auto i=itemlist.begin();i!=itemlist.end(); ++i) { - (*i)->setLocked(true); - } -} - -void ContextMenu::HideSelected(void) -{ - auto itemlist =_desktop->selection->items(); - for(auto i=itemlist.begin();i!=itemlist.end(); ++i) { - (*i)->setHidden(true); - } -} - -void ContextMenu::UnLockBelow(std::vector items) -{ - _desktop->selection->clear(); - for(auto i=items.begin();i!=items.end(); ++i) { - if ((*i)->isLocked()) { - (*i)->setLocked(false); - _desktop->selection->add(*i); - } - } -} - -void ContextMenu::UnHideBelow(std::vector items) -{ - _desktop->selection->clear(); - for(auto i=items.begin();i!=items.end(); ++i) { - if ((*i)->isHidden()) { - (*i)->setHidden(false); - _desktop->selection->add(*i); - } - } -} - -// TODO: Update this to allow radio items to be used -void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)//, bool radio, GSList *group) -{ - SPAction *action; - SPDesktop *view = _desktop; - - if (verb->get_code() == SP_VERB_NONE) { - Gtk::MenuItem *item = AddSeparator(); - item->show(); - append(*item); - } else { - action = verb->get_action(Inkscape::ActionContext(view)); - if (!action) { - return; - } - - // Create a box to contain all the widgets (icon, label, accelerator) - // that will go inside the menu item - auto const box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 6)); - - // If there is an image associated with the action, then we can add it as an - // icon for the menu item - if (action->image) { - auto const icon = Gtk::manage(new Gtk::Image()); - icon->set_from_icon_name(action->image, Gtk::ICON_SIZE_MENU); - box->add(*icon); - } - - // Now create the label and add it to the menu item (with mnemonic - auto const label = Gtk::manage(new Gtk::Label(action->name, true)); - box->add(*label); - - // Create the menu item itself, either as a radio menu item, or just - // a regular menu item depending on whether the "radio" flag is set - auto const item = Gtk::manage(new Gtk::MenuItem(*box)); - - sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb)); - - action->signal_set_sensitive.connect(sigc::mem_fun(*this, &ContextMenu::set_sensitive)); - action->signal_set_name.connect(sigc::mem_fun(*item, &ContextMenu::set_name)); - - if (!action->sensitive) { - item->set_sensitive(FALSE); - } - - - item->set_events(Gdk::KEY_PRESS_MASK); - item->signal_activate().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_activate),item,action)); - item->signal_select().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_select_action),item,action)); - item->signal_deselect().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_deselect_action),item,action)); - item->show_all(); - append(*item); - } -} - -void ContextMenu::MakeObjectMenu(void) -{ -// GObjectClass *klass = G_OBJECT_GET_CLASS(_object); //to deduce the object's type from its class -// -// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_ITEM)) -// { -// MakeItemMenu (); -// } -// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_GROUP)) -// { -// MakeGroupMenu(); -// } -// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_ANCHOR)) -// { -// MakeAnchorMenu(); -// } -// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_IMAGE)) -// { -// MakeImageMenu(); -// } -// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_SHAPE)) -// { -// MakeShapeMenu(); -// } -// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_TEXT)) -// { -// MakeTextMenu(); -// } - - if (SP_IS_ITEM(_object)) { - MakeItemMenu(); - } - - if (SP_IS_GROUP(_object)) { - MakeGroupMenu(); - } - - if (SP_IS_ANCHOR(_object)) { - MakeAnchorMenu(); - } - - if (SP_IS_IMAGE(_object)) { - MakeImageMenu(); - } - - if (SP_IS_SHAPE(_object)) { - MakeShapeMenu(); - } - - if (SP_IS_TEXT(_object)) { - MakeTextMenu(); - } -} - -void ContextMenu::MakeItemMenu (void) -{ - Gtk::MenuItem* mi; - - /* Item dialog */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Object Properties..."),1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemProperties)); - mi->show(); - append(*mi);//insert(*mi,positionOfLastDialog++); - - AddSeparator(); - - /* Select item */ - if (Inkscape::Verb::getbyid( "org.inkscape.followlink" )) { - mi = Gtk::manage(new Gtk::MenuItem(_("_Select This"), 1)); - if (_desktop->selection->includes(_item)) { - mi->set_sensitive(FALSE); - } else { - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemSelectThis)); - } - mi->show(); - append(*mi); - } - - - mi = Gtk::manage(new Gtk::MenuItem(_("Select Same"))); - mi->show(); - Gtk::Menu *select_same_submenu = Gtk::manage(new Gtk::Menu()); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(FALSE); - } - mi->set_submenu(*select_same_submenu); - append(*mi); - - /* Select same fill and stroke */ - mi = Gtk::manage(new Gtk::MenuItem(_("Fill and Stroke"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillStroke)); - mi->set_sensitive(!SP_IS_ANCHOR(_item)); - mi->show(); - select_same_submenu->append(*mi); - - /* Select same fill color */ - mi = Gtk::manage(new Gtk::MenuItem(_("Fill Color"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillColor)); - mi->set_sensitive(!SP_IS_ANCHOR(_item)); - mi->show(); - select_same_submenu->append(*mi); - - /* Select same stroke color */ - mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Color"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeColor)); - mi->set_sensitive(!SP_IS_ANCHOR(_item)); - mi->show(); - select_same_submenu->append(*mi); - - /* Select same stroke style */ - mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Style"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeStyle)); - mi->set_sensitive(!SP_IS_ANCHOR(_item)); - mi->show(); - select_same_submenu->append(*mi); - - /* Select same stroke style */ - mi = Gtk::manage(new Gtk::MenuItem(_("Object type"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameObjectType)); - mi->set_sensitive(!SP_IS_ANCHOR(_item)); - mi->show(); - select_same_submenu->append(*mi); - - /* Move to layer */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Move to layer ..."), 1)); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(FALSE); - } else { - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemMoveTo)); - } - mi->show(); - append(*mi); - - /* Create link */ - mi = Gtk::manage(new Gtk::MenuItem(_("Create _Link"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemCreateLink)); - mi->set_sensitive(!SP_IS_ANCHOR(_item)); - mi->show(); - append(*mi); - - bool ClipRefOK=false; - bool MaskRefOK=false; - if (_item){ - if (_item->clip_ref){ - if (_item->clip_ref->getObject()){ - ClipRefOK=true; - } - } - } - if (_item){ - if (_item->mask_ref){ - if (_item->mask_ref->getObject()){ - MaskRefOK=true; - } - } - } - /* Set mask */ - mi = Gtk::manage(new Gtk::MenuItem(_("Set Mask"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetMask)); - if (ClipRefOK || MaskRefOK) { - mi->set_sensitive(FALSE); - } else { - mi->set_sensitive(TRUE); - } - mi->show(); - append(*mi); - - /* Release mask */ - mi = Gtk::manage(new Gtk::MenuItem(_("Release Mask"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseMask)); - if (MaskRefOK) { - mi->set_sensitive(TRUE); - } else { - mi->set_sensitive(FALSE); - } - mi->show(); - append(*mi); - - /*SSet Clip Group */ - mi = Gtk::manage(new Gtk::MenuItem(_("Create Clip G_roup"),1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::CreateGroupClip)); - mi->set_sensitive(TRUE); - mi->show(); - append(*mi); - - /* Set Clip */ - mi = Gtk::manage(new Gtk::MenuItem(_("Set Cl_ip"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetClip)); - if (ClipRefOK || MaskRefOK) { - mi->set_sensitive(FALSE); - } else { - mi->set_sensitive(TRUE); - } - mi->show(); - append(*mi); - - /* Release Clip */ - mi = Gtk::manage(new Gtk::MenuItem(_("Release C_lip"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseClip)); - if (ClipRefOK) { - mi->set_sensitive(TRUE); - } else { - mi->set_sensitive(FALSE); - } - mi->show(); - append(*mi); - - /* Group */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Group"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateGroup)); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(FALSE); - } else { - mi->set_sensitive(TRUE); - } - mi->show(); - append(*mi); -} - -void ContextMenu::SelectSameFillStroke(void) -{ - sp_select_same_fill_stroke_style(_desktop, true, true, true); -} - -void ContextMenu::SelectSameFillColor(void) -{ - sp_select_same_fill_stroke_style(_desktop, true, false, false); -} - -void ContextMenu::SelectSameStrokeColor(void) -{ - sp_select_same_fill_stroke_style(_desktop, false, true, false); -} - -void ContextMenu::SelectSameStrokeStyle(void) -{ - sp_select_same_fill_stroke_style(_desktop, false, false, true); -} - -void ContextMenu::SelectSameObjectType(void) -{ - sp_select_same_object_type(_desktop); -} - -void ContextMenu::ItemProperties(void) -{ - _desktop->selection->set(_item); - _desktop->_dlg_mgr->showDialog("ObjectProperties"); -} - -void ContextMenu::ItemSelectThis(void) -{ - _desktop->selection->set(_item); -} - -void ContextMenu::ItemMoveTo(void) -{ - Inkscape::UI::Dialogs::LayerPropertiesDialog::showMove(_desktop, _desktop->currentLayer()); -} - - - -void ContextMenu::ItemCreateLink(void) -{ - Inkscape::XML::Document *xml_doc = _desktop->doc()->getReprDoc(); - Inkscape::XML::Node *repr = xml_doc->createElement("svg:a"); - _item->parent->getRepr()->addChild(repr, _item->getRepr()); - SPObject *object = _item->document->getObjectByRepr(repr); - g_return_if_fail(SP_IS_ANCHOR(object)); - - const char *id = _item->getRepr()->attribute("id"); - Inkscape::XML::Node *child = _item->getRepr()->duplicate(xml_doc); - _item->deleteObject(false); - repr->addChild(child, NULL); - child->setAttribute("id", id); - - Inkscape::GC::release(repr); - Inkscape::GC::release(child); - - DocumentUndo::done(object->document, SP_VERB_NONE, _("Create link")); - - _desktop->selection->set(SP_ITEM(object)); - _desktop->_dlg_mgr->showDialog("ObjectAttributes"); -} - -void ContextMenu::SetMask(void) -{ - _desktop->selection->setMask(false, false); -} - -void ContextMenu::ReleaseMask(void) -{ - _desktop->selection->unsetMask(false); -} - -void ContextMenu::CreateGroupClip(void) -{ - _desktop->selection->setClipGroup(); -} - -void ContextMenu::SetClip(void) -{ - _desktop->selection->setMask(true, false); -} - - -void ContextMenu::ReleaseClip(void) -{ - _desktop->selection->unsetMask(true); -} - -void ContextMenu::MakeGroupMenu(void) -{ - /* Ungroup */ - Gtk::MenuItem* mi = Gtk::manage(new Gtk::MenuItem(_("_Ungroup"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroup)); - mi->show(); - append(*mi); -} - -void ContextMenu::ActivateGroup(void) -{ - _desktop->selection->group(); -} - -void ContextMenu::ActivateUngroup(void) -{ - std::vector children; - - sp_item_group_ungroup(static_cast(_item), children); - _desktop->selection->setList(children); -} - -void ContextMenu::ActivateUngroupPopSelection(void) -{ - _desktop->selection->popFromGroup(); -} - - -void ContextMenu::MakeAnchorMenu(void) -{ - Gtk::MenuItem* mi; - - /* Link dialog */ - mi = Gtk::manage(new Gtk::MenuItem(_("Link _Properties..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkProperties)); - mi->show(); - insert(*mi,positionOfLastDialog++); - - /* Select item */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Follow Link"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkFollow)); - mi->show(); - append(*mi); - - /* Reset transformations */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Remove Link"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkRemove)); - mi->show(); - append(*mi); -} - -void ContextMenu::AnchorLinkProperties(void) -{ - _desktop->_dlg_mgr->showDialog("ObjectAttributes"); -} - -void ContextMenu::AnchorLinkFollow(void) -{ - - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - // Opening the selected links with a python extension - Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.inkscape.followlink" ); - if (verb) { - SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop)); - if (action) { - sp_action_perform(action, NULL); - } - } -} - -void ContextMenu::AnchorLinkRemove(void) -{ - std::vector children; - sp_item_group_ungroup(static_cast(_item), children, false); - DocumentUndo::done(_desktop->doc(), SP_VERB_NONE, _("Remove link")); -} - -void ContextMenu::MakeImageMenu (void) -{ - Gtk::MenuItem* mi; - Inkscape::XML::Node *ir = _object->getRepr(); - const gchar *href = ir->attribute("xlink:href"); - - /* Image properties */ - mi = Gtk::manage(new Gtk::MenuItem(_("Image _Properties..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageProperties)); - mi->show(); - insert(*mi,positionOfLastDialog++); - - /* Edit externally */ - mi = Gtk::manage(new Gtk::MenuItem(_("Edit Externally..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEdit)); - mi->show(); - insert(*mi,positionOfLastDialog++); - if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) { - mi->set_sensitive( FALSE ); - } - - /* Trace Bitmap */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Trace Bitmap..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTraceBitmap)); - mi->show(); - insert(*mi,positionOfLastDialog++); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(FALSE); - } - - /* Trace Pixel Art */ - mi = Gtk::manage(new Gtk::MenuItem(_("Trace Pixel Art"), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTracePixelArt)); - mi->show(); - insert(*mi,positionOfLastDialog++); - if (_desktop->selection->isEmpty()) { - mi->set_sensitive(FALSE); - } - - /* Embed image */ - if (Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" )) { - mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Embed Image"))); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEmbed)); - mi->show(); - insert(*mi,positionOfLastDialog++); - if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) { - mi->set_sensitive( FALSE ); - } - } - - /* Extract image */ - if (Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" )) { - mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Extract Image..."))); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageExtract)); - mi->show(); - insert(*mi,positionOfLastDialog++); - if ( (!href) || ((strncmp(href, "data:", 5) != 0)) ) { - mi->set_sensitive( FALSE ); - } - } -} - -void ContextMenu::ImageProperties(void) -{ - _desktop->_dlg_mgr->showDialog("ObjectAttributes"); -} - -Glib::ustring ContextMenu::getImageEditorName() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring value; - Glib::ustring choices = prefs->getString("/options/bitmapeditor/value"); - if (!choices.empty()) { - value = choices; - } - else { - value = "gimp"; - } - return value; -} - -void ContextMenu::ImageEdit(void) -{ - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - - GError* errThing = 0; - Glib::ustring cmdline = getImageEditorName(); - Glib::ustring name; - Glib::ustring fullname; - -#ifdef WIN32 - // g_spawn_command_line_sync parsing is done according to Unix shell rules, - // not Windows command interpreter rules. Thus we need to enclose the - // executable path with single quotes. - int index = cmdline.find(".exe"); - if ( index < 0 ) index = cmdline.find(".bat"); - if ( index < 0 ) index = cmdline.find(".com"); - if ( index >= 0 ) { - Glib::ustring editorBin = cmdline.substr(0, index + 4).c_str(); - Glib::ustring args = cmdline.substr(index + 4, cmdline.length()).c_str(); - editorBin.insert(0, "'"); - editorBin.append("'"); - cmdline = editorBin; - cmdline.append(args); - } else { - // Enclose the whole command line if no executable path can be extracted. - cmdline.insert(0, "'"); - cmdline.append("'"); - } -#endif - - auto itemlist= _desktop->selection->items(); - for(auto i=itemlist.begin();i!=itemlist.end();++i){ - Inkscape::XML::Node *ir = (*i)->getRepr(); - const gchar *href = ir->attribute("xlink:href"); - - if (strncmp (href,"file:",5) == 0) { - // URI to filename conversion - name = g_filename_from_uri(href, NULL, NULL); - } else { - name.append(href); - } - - if (Glib::path_is_absolute(name)) { - fullname = name; - } else if (SP_ACTIVE_DOCUMENT->getBase()) { - fullname = Glib::build_filename(SP_ACTIVE_DOCUMENT->getBase(), name); - } else { - fullname = Glib::build_filename(Glib::get_current_dir(), name); - } - - cmdline.append(" '"); - cmdline.append(fullname.c_str()); - cmdline.append("'"); - } - - //g_warning("##Command line: %s\n", cmdline.c_str()); - - g_spawn_command_line_async(cmdline.c_str(), &errThing); - - if ( errThing ) { - g_warning("Problem launching editor (%d). %s", errThing->code, errThing->message); - (_desktop->messageStack())->flash(Inkscape::ERROR_MESSAGE, errThing->message); - g_error_free(errThing); - errThing = 0; - } -} - -void ContextMenu::ImageTraceBitmap(void) -{ - INKSCAPE.dialogs_unhide(); - _desktop->_dlg_mgr->showDialog("Trace"); -} - -void ContextMenu::ImageTracePixelArt(void) -{ - INKSCAPE.dialogs_unhide(); - _desktop->_dlg_mgr->showDialog("PixelArt"); -} - -void ContextMenu::ImageEmbed(void) -{ - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - - Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" ); - if (verb) { - SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop)); - if (action) { - sp_action_perform(action, NULL); - } - } -} - -void ContextMenu::ImageExtract(void) -{ - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - - Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" ); - if (verb) { - SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop)); - if (action) { - sp_action_perform(action, NULL); - } - } -} - -void ContextMenu::MakeShapeMenu (void) -{ - Gtk::MenuItem* mi; - - /* Item dialog */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings)); - mi->show(); - insert(*mi,positionOfLastDialog++); -} - -void ContextMenu::FillSettings(void) -{ - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - - _desktop->_dlg_mgr->showDialog("FillAndStroke"); -} - -void ContextMenu::MakeTextMenu (void) -{ - Gtk::MenuItem* mi; - - /* Fill and Stroke dialog */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings)); - mi->show(); - insert(*mi,positionOfLastDialog++); - - /* Edit Text dialog */ - mi = Gtk::manage(new Gtk::MenuItem(_("_Text and Font..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::TextSettings)); - mi->show(); - insert(*mi,positionOfLastDialog++); - - /* Spellcheck dialog */ - mi = Gtk::manage(new Gtk::MenuItem(_("Check Spellin_g..."), 1)); - mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SpellcheckSettings)); - mi->show(); - insert(*mi,positionOfLastDialog++); -} - -void ContextMenu::TextSettings (void) -{ - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - - _desktop->_dlg_mgr->showDialog("TextFont"); -} - -void ContextMenu::SpellcheckSettings (void) -{ - if (_desktop->selection->isEmpty()) { - _desktop->selection->set(_item); - } - - _desktop->_dlg_mgr->showDialog("SpellCheck"); -} - /* Local Variables: mode:c++ -- cgit v1.2.3 From d483c2ab23354cf5ea58a2d2225ab464b77f6614 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Wed, 28 Jun 2017 15:17:39 +0200 Subject: menu-items: C++ify --- src/ui/interface.cpp | 120 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 49 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index c2ce9e568..c9c00df02 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -24,7 +24,12 @@ #endif #include "ui/dialog/dialog-manager.h" + #include +#include +#include +#include + #include "file.h" #include @@ -438,14 +443,18 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) * * @see ContextMenu::AppendItemFromVerb for a c++ified alternative. Consider dropping sp_ui_menu_append_item_from_verb when c++ifying interface.cpp. */ -static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape::UI::View::View *view, bool radio = false, GSList *group = NULL) +static Gtk::MenuItem * +sp_ui_menu_append_item_from_verb(Gtk::Menu *menu, + Inkscape::Verb *verb, + Inkscape::UI::View::View *view, + bool radio = false) { - GtkWidget *item; + Gtk::MenuItem *item; // Just create a menu separator if this isn't a real action. // Otherwise, create a real menu item if (verb->get_code() == SP_VERB_NONE) { - item = gtk_separator_menu_item_new(); + item = Gtk::manage(new Gtk::SeparatorMenuItem()); } else { SPAction *action = verb->get_action(Inkscape::ActionContext(view)); @@ -453,76 +462,70 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb // Create the menu item itself, either as a radio menu item, or just // a regular menu item depending on whether the "radio" flag is set - if (radio) { - item = gtk_radio_menu_item_new(group); - } else { - item = gtk_menu_item_new(); - } + if(radio) item = Gtk::manage(new Gtk::RadioMenuItem()); + else item = Gtk::manage(new Gtk::MenuItem()); // Create a box to contain all the widgets (icon, label, accelerator) // that will go inside the menu item - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + Gtk::Box *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0)); // Now create the label and add it to the menu item - GtkWidget *label = gtk_accel_label_new(action->name); - gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name); - gtk_label_set_use_underline(GTK_LABEL(label), true); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); + Gtk::AccelLabel *label = Gtk::manage(new Gtk::AccelLabel(action->name)); + label->set_markup_with_mnemonic(action->name); + label->set_use_underline(true); + label->set_xalign(0.0); - GtkAccelGroup *accel_group = sp_shortcut_get_accel_group(); - gtk_menu_set_accel_group(menu, accel_group); + auto accel_group = Gtk::AccelGroup::create(); + menu->set_accel_group(accel_group); - sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb)); - gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), item); + sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb)); + label->set_accel_widget(*item); // If there is an image associated with the action, then we can add it as an // icon for the menu item. If not, give the label a bit more space if(action->image) { - GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); - gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0); + Gtk::Image *icon = Gtk::manage(new Gtk::Image()); + icon->set_from_icon_name(action->image, Gtk::ICON_SIZE_MENU); + box->pack_start(*icon, false, true, 0); } else { - GtkWidget *fake_icon = gtk_label_new(""); - gtk_widget_set_size_request(label, 16, 16); - gtk_widget_set_hexpand(label, true); - gtk_box_pack_start(GTK_BOX(box), fake_icon, FALSE, TRUE, 16); + Gtk::Widget *fake_icon = Gtk::manage(new Gtk::Label("")); + label->set_size_request(16, 16); + label->set_hexpand(true); + box->pack_start(*fake_icon, false, true, 16); } - gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); - + box->pack_start(*label, true, true, 0); // Finally, pack all the widgets into the menu item - gtk_container_add(GTK_CONTAINER(item), box); - + item->add(*box); + // Handle signals from the SPAction action->signal_set_sensitive.connect( - sigc::bind<0>( - sigc::ptr_fun(>k_widget_set_sensitive), - item)); + sigc::mem_fun(*item, &Gtk::MenuItem::set_sensitive)); + action->signal_set_name.connect( sigc::bind<0>( sigc::ptr_fun(&sp_ui_menu_item_set_name), - item)); + GTK_WIDGET(item->gobj()))); if (!action->sensitive) { - gtk_widget_set_sensitive(item, FALSE); + item->set_sensitive(false); } - gtk_widget_set_events(item, GDK_KEY_PRESS_MASK); + item->set_events(Gdk::KEY_PRESS_MASK); g_object_set_data(G_OBJECT(item), "view", (gpointer) view); g_signal_connect( G_OBJECT(item), "activate", G_CALLBACK(sp_ui_menu_activate), action ); g_signal_connect( G_OBJECT(item), "select", G_CALLBACK(sp_ui_menu_select_action), action ); g_signal_connect( G_OBJECT(item), "deselect", G_CALLBACK(sp_ui_menu_deselect_action), action ); } - gtk_widget_show_all(item); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + item->show_all(); + menu->append(*item); return item; - } // end of sp_ui_menu_append_item_from_verb - Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view ) { Glib::ustring prefPath; @@ -797,7 +800,7 @@ private: /** * This function turns XML into a menu. * - * This function is realitively simple as it just goes through the XML + * This function is relatively simple as it just goes through the XML * and parses the individual elements. In the case of a submenu, it * just calls itself recursively. Because it is only reasonable to have * a couple of submenus, it is unlikely this will go more than two or @@ -811,18 +814,19 @@ private: * @param menu Menu to be added to * @param view The View that this menu is being built for */ -static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, Inkscape::UI::View::View *view) +static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, + Gtk::Menu *menu, + Inkscape::UI::View::View *view) { if (menus == NULL) return; if (menu == NULL) return; - GSList *group = NULL; for (Inkscape::XML::Node *menu_pntr = menus; menu_pntr != NULL; menu_pntr = menu_pntr->next()) { if (!strcmp(menu_pntr->name(), "submenu")) { GtkWidget *mitem = gtk_menu_item_new_with_mnemonic(_(menu_pntr->attribute("name"))); - GtkWidget *submenu = gtk_menu_new(); + Gtk::Menu *submenu = Gtk::manage(new Gtk::Menu()); sp_ui_build_dyn_menus(menu_pntr->firstChild(), submenu, view); gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), GTK_WIDGET(submenu)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mitem); @@ -833,9 +837,23 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I Inkscape::Verb *verb = Inkscape::Verb::getbyid(verb_name); if (verb != NULL) { + + // Add a radio item to the menu if (menu_pntr->attribute("radio") != NULL) { - GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, true, group); - group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item)); + auto item = sp_ui_menu_append_item_from_verb (menu, verb, view, true); + + // If the last item was also a radio item, then we need to add the new item to + // its group. Note that the Inkscape dynamic menu XML files do not support + // explicit grouping yet. Instead, groups consist of ALL adjacent radio menu items + // in the file. + Gtk::RadioMenuItem *last_item = dynamic_cast(menu->get_children().back()); + + if(last_item != nullptr) { + auto radioitem = dynamic_cast(item); + radioitem->join_group(*last_item); + } + + if (menu_pntr->attribute("default") != NULL) { gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); } @@ -850,8 +868,7 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I checkitem_toggled, checkitem_update, verb); } } else { - sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view); - group = NULL; + sp_ui_menu_append_item_from_verb(menu, verb, view); } } else { gchar string[120]; @@ -910,11 +927,16 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I } } -GtkWidget *sp_ui_main_menubar(Inkscape::UI::View::View *view) +Gtk::MenuBar * +sp_ui_main_menubar(Inkscape::UI::View::View *view) { - GtkWidget *mbar = gtk_menu_bar_new(); - sp_ui_build_dyn_menus(INKSCAPE.get_menus(), mbar, view); - return mbar; + auto menu_bar = Gtk::manage(new Gtk::MenuBar()); + + sp_ui_build_dyn_menus(INKSCAPE.get_menus(), + dynamic_cast(menu_bar), + view); + + return menu_bar; } -- cgit v1.2.3 From 1da12a921c8a5e9f49de799cf9f3e9a642208bd7 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Wed, 28 Jun 2017 16:25:51 +0200 Subject: Rm unused fn --- src/ui/interface.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index c9c00df02..d31aa19a2 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -142,8 +142,6 @@ static void sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name); static void sp_recent_open(GtkRecentChooser *, gpointer); -static void injectRenamedIcons(); - static const int MIN_ONSCREEN_DISTANCE = 50; void @@ -1441,33 +1439,6 @@ sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name) } } } - -void injectRenamedIcons() -{ - Glib::RefPtr iconTheme = Gtk::IconTheme::get_default(); - - std::vector< std::pair > renamed; - renamed.push_back(std::make_pair("gtk-file", "document-x-generic")); - renamed.push_back(std::make_pair("gtk-directory", "folder")); - - for ( std::vector< std::pair >::iterator it = renamed.begin(); it < renamed.end(); ++it ) { - bool hasIcon = iconTheme->has_icon(it->first); - bool hasSecondIcon = iconTheme->has_icon(it->second); - - if ( !hasIcon && hasSecondIcon ) { - Glib::ArrayHandle sizes = iconTheme->get_icon_sizes(it->second); - for ( Glib::ArrayHandle::iterator it2 = sizes.begin(); it2 < sizes.end(); ++it2 ) { - Glib::RefPtr pb = iconTheme->load_icon( it->second, *it2 ); - if ( pb ) { - // install a private copy of the pixbuf to avoid pinning a theme - Glib::RefPtr pbCopy = pb->copy(); - Gtk::IconTheme::add_builtin_icon( it->first, *it2, pbCopy ); - } - } - } - } -} - /* Local Variables: mode:c++ -- cgit v1.2.3 From ff0dd4905d403242364fa5d63c510b0e1051ee2b Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Wed, 28 Jun 2017 16:57:29 +0200 Subject: Revert "Rm unused fn" This reverts commit 1da12a921c8a5e9f49de799cf9f3e9a642208bd7. --- src/ui/interface.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index d31aa19a2..c9c00df02 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -142,6 +142,8 @@ static void sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name); static void sp_recent_open(GtkRecentChooser *, gpointer); +static void injectRenamedIcons(); + static const int MIN_ONSCREEN_DISTANCE = 50; void @@ -1439,6 +1441,33 @@ sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name) } } } + +void injectRenamedIcons() +{ + Glib::RefPtr iconTheme = Gtk::IconTheme::get_default(); + + std::vector< std::pair > renamed; + renamed.push_back(std::make_pair("gtk-file", "document-x-generic")); + renamed.push_back(std::make_pair("gtk-directory", "folder")); + + for ( std::vector< std::pair >::iterator it = renamed.begin(); it < renamed.end(); ++it ) { + bool hasIcon = iconTheme->has_icon(it->first); + bool hasSecondIcon = iconTheme->has_icon(it->second); + + if ( !hasIcon && hasSecondIcon ) { + Glib::ArrayHandle sizes = iconTheme->get_icon_sizes(it->second); + for ( Glib::ArrayHandle::iterator it2 = sizes.begin(); it2 < sizes.end(); ++it2 ) { + Glib::RefPtr pb = iconTheme->load_icon( it->second, *it2 ); + if ( pb ) { + // install a private copy of the pixbuf to avoid pinning a theme + Glib::RefPtr pbCopy = pb->copy(); + Gtk::IconTheme::add_builtin_icon( it->first, *it2, pbCopy ); + } + } + } + } +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 4e9ea206bf17a0520e154c0fabe0128a4cc4f6fb Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Wed, 28 Jun 2017 16:57:52 +0200 Subject: Revert "menu-items: C++ify" This reverts commit d483c2ab23354cf5ea58a2d2225ab464b77f6614. --- src/ui/interface.cpp | 120 +++++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 71 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index c9c00df02..c2ce9e568 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -24,12 +24,7 @@ #endif #include "ui/dialog/dialog-manager.h" - #include -#include -#include -#include - #include "file.h" #include @@ -443,18 +438,14 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) * * @see ContextMenu::AppendItemFromVerb for a c++ified alternative. Consider dropping sp_ui_menu_append_item_from_verb when c++ifying interface.cpp. */ -static Gtk::MenuItem * -sp_ui_menu_append_item_from_verb(Gtk::Menu *menu, - Inkscape::Verb *verb, - Inkscape::UI::View::View *view, - bool radio = false) +static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape::UI::View::View *view, bool radio = false, GSList *group = NULL) { - Gtk::MenuItem *item; + GtkWidget *item; // Just create a menu separator if this isn't a real action. // Otherwise, create a real menu item if (verb->get_code() == SP_VERB_NONE) { - item = Gtk::manage(new Gtk::SeparatorMenuItem()); + item = gtk_separator_menu_item_new(); } else { SPAction *action = verb->get_action(Inkscape::ActionContext(view)); @@ -462,70 +453,76 @@ sp_ui_menu_append_item_from_verb(Gtk::Menu *menu, // Create the menu item itself, either as a radio menu item, or just // a regular menu item depending on whether the "radio" flag is set - if(radio) item = Gtk::manage(new Gtk::RadioMenuItem()); - else item = Gtk::manage(new Gtk::MenuItem()); + if (radio) { + item = gtk_radio_menu_item_new(group); + } else { + item = gtk_menu_item_new(); + } // Create a box to contain all the widgets (icon, label, accelerator) // that will go inside the menu item - Gtk::Box *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0)); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); // Now create the label and add it to the menu item - Gtk::AccelLabel *label = Gtk::manage(new Gtk::AccelLabel(action->name)); - label->set_markup_with_mnemonic(action->name); - label->set_use_underline(true); - label->set_xalign(0.0); + GtkWidget *label = gtk_accel_label_new(action->name); + gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name); + gtk_label_set_use_underline(GTK_LABEL(label), true); + gtk_label_set_xalign(GTK_LABEL(label), 0.0); - auto accel_group = Gtk::AccelGroup::create(); - menu->set_accel_group(accel_group); + GtkAccelGroup *accel_group = sp_shortcut_get_accel_group(); + gtk_menu_set_accel_group(menu, accel_group); - sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb)); - label->set_accel_widget(*item); + sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb)); + gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), item); // If there is an image associated with the action, then we can add it as an // icon for the menu item. If not, give the label a bit more space if(action->image) { - Gtk::Image *icon = Gtk::manage(new Gtk::Image()); - icon->set_from_icon_name(action->image, Gtk::ICON_SIZE_MENU); - box->pack_start(*icon, false, true, 0); + GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); + gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0); } else { - Gtk::Widget *fake_icon = Gtk::manage(new Gtk::Label("")); - label->set_size_request(16, 16); - label->set_hexpand(true); - box->pack_start(*fake_icon, false, true, 16); + GtkWidget *fake_icon = gtk_label_new(""); + gtk_widget_set_size_request(label, 16, 16); + gtk_widget_set_hexpand(label, true); + gtk_box_pack_start(GTK_BOX(box), fake_icon, FALSE, TRUE, 16); } - box->pack_start(*label, true, true, 0); + gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); + // Finally, pack all the widgets into the menu item - item->add(*box); + gtk_container_add(GTK_CONTAINER(item), box); - // Handle signals from the SPAction - action->signal_set_sensitive.connect( - sigc::mem_fun(*item, &Gtk::MenuItem::set_sensitive)); + action->signal_set_sensitive.connect( + sigc::bind<0>( + sigc::ptr_fun(>k_widget_set_sensitive), + item)); action->signal_set_name.connect( sigc::bind<0>( sigc::ptr_fun(&sp_ui_menu_item_set_name), - GTK_WIDGET(item->gobj()))); + item)); if (!action->sensitive) { - item->set_sensitive(false); + gtk_widget_set_sensitive(item, FALSE); } - item->set_events(Gdk::KEY_PRESS_MASK); + gtk_widget_set_events(item, GDK_KEY_PRESS_MASK); g_object_set_data(G_OBJECT(item), "view", (gpointer) view); g_signal_connect( G_OBJECT(item), "activate", G_CALLBACK(sp_ui_menu_activate), action ); g_signal_connect( G_OBJECT(item), "select", G_CALLBACK(sp_ui_menu_select_action), action ); g_signal_connect( G_OBJECT(item), "deselect", G_CALLBACK(sp_ui_menu_deselect_action), action ); } - item->show_all(); - menu->append(*item); + gtk_widget_show_all(item); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); return item; + } // end of sp_ui_menu_append_item_from_verb + Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view ) { Glib::ustring prefPath; @@ -800,7 +797,7 @@ private: /** * This function turns XML into a menu. * - * This function is relatively simple as it just goes through the XML + * This function is realitively simple as it just goes through the XML * and parses the individual elements. In the case of a submenu, it * just calls itself recursively. Because it is only reasonable to have * a couple of submenus, it is unlikely this will go more than two or @@ -814,19 +811,18 @@ private: * @param menu Menu to be added to * @param view The View that this menu is being built for */ -static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, - Gtk::Menu *menu, - Inkscape::UI::View::View *view) +static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, Inkscape::UI::View::View *view) { if (menus == NULL) return; if (menu == NULL) return; + GSList *group = NULL; for (Inkscape::XML::Node *menu_pntr = menus; menu_pntr != NULL; menu_pntr = menu_pntr->next()) { if (!strcmp(menu_pntr->name(), "submenu")) { GtkWidget *mitem = gtk_menu_item_new_with_mnemonic(_(menu_pntr->attribute("name"))); - Gtk::Menu *submenu = Gtk::manage(new Gtk::Menu()); + GtkWidget *submenu = gtk_menu_new(); sp_ui_build_dyn_menus(menu_pntr->firstChild(), submenu, view); gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), GTK_WIDGET(submenu)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mitem); @@ -837,23 +833,9 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, Inkscape::Verb *verb = Inkscape::Verb::getbyid(verb_name); if (verb != NULL) { - - // Add a radio item to the menu if (menu_pntr->attribute("radio") != NULL) { - auto item = sp_ui_menu_append_item_from_verb (menu, verb, view, true); - - // If the last item was also a radio item, then we need to add the new item to - // its group. Note that the Inkscape dynamic menu XML files do not support - // explicit grouping yet. Instead, groups consist of ALL adjacent radio menu items - // in the file. - Gtk::RadioMenuItem *last_item = dynamic_cast(menu->get_children().back()); - - if(last_item != nullptr) { - auto radioitem = dynamic_cast(item); - radioitem->join_group(*last_item); - } - - + GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, true, group); + group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item)); if (menu_pntr->attribute("default") != NULL) { gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); } @@ -868,7 +850,8 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, checkitem_toggled, checkitem_update, verb); } } else { - sp_ui_menu_append_item_from_verb(menu, verb, view); + sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view); + group = NULL; } } else { gchar string[120]; @@ -927,16 +910,11 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, } } -Gtk::MenuBar * -sp_ui_main_menubar(Inkscape::UI::View::View *view) +GtkWidget *sp_ui_main_menubar(Inkscape::UI::View::View *view) { - auto menu_bar = Gtk::manage(new Gtk::MenuBar()); - - sp_ui_build_dyn_menus(INKSCAPE.get_menus(), - dynamic_cast(menu_bar), - view); - - return menu_bar; + GtkWidget *mbar = gtk_menu_bar_new(); + sp_ui_build_dyn_menus(INKSCAPE.get_menus(), mbar, view); + return mbar; } -- cgit v1.2.3 From 18c0d1f13449856f3c0914d07b645fd3e5da002f Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Wed, 28 Jun 2017 21:26:18 +0200 Subject: Add a show-icon attribute to menu XML --- src/ui/interface.cpp | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index c2ce9e568..d1da47867 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -437,8 +437,25 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) * Appends a custom menu UI from a verb. * * @see ContextMenu::AppendItemFromVerb for a c++ified alternative. Consider dropping sp_ui_menu_append_item_from_verb when c++ifying interface.cpp. + * + * @param menu The menu to which the item will be appended + * @param verb The verb from which the item's label, action and icon (optionally) will be read + * @param view + * @param show_icon True if an icon should be displayed before the menu item's label + * @param radio True if a radio button should be displayed next to the menu item + * @param group The radio button group that the item should belong to + * + * @details The show_icon flag should be used very sparingly because menu icons are not recommended + * any longer under the GNOME HIG. Also, note that the text appears after the icon, and + * so will be indented relative to "normal" menu items. As such, menus will look best if + * all the items with icons are grouped together between a pair of separators. */ -static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape::UI::View::View *view, bool radio = false, GSList *group = NULL) +static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, + Inkscape::Verb *verb, + Inkscape::UI::View::View *view, + bool show_icon = false, + bool radio = false, + GSList *group = NULL) { GtkWidget *item; @@ -475,22 +492,20 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb)); gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), item); + GtkWidget *icon; + // If there is an image associated with the action, then we can add it as an // icon for the menu item. If not, give the label a bit more space - if(action->image) { - GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); - gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0); + if(show_icon && action->image) { + icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); } else { - GtkWidget *fake_icon = gtk_label_new(""); - gtk_widget_set_size_request(label, 16, 16); - gtk_widget_set_hexpand(label, true); - gtk_box_pack_start(GTK_BOX(box), fake_icon, FALSE, TRUE, 16); + icon = gtk_label_new(NULL); // A fake icon just to act as a placeholder } + gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); - // Finally, pack all the widgets into the menu item gtk_container_add(GTK_CONTAINER(item), box); @@ -830,11 +845,19 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I } if (!strcmp(menu_pntr->name(), "verb")) { gchar const *verb_name = menu_pntr->attribute("verb-id"); + + // Check if the "show-icon" attribute is set, and set the flag here accordingly + bool show_icon = false; + + if(menu_pntr->attribute("show-icon") != NULL) { + show_icon = true; + } + Inkscape::Verb *verb = Inkscape::Verb::getbyid(verb_name); if (verb != NULL) { if (menu_pntr->attribute("radio") != NULL) { - GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, true, group); + GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, show_icon, true, group); group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item)); if (menu_pntr->attribute("default") != NULL) { gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); @@ -850,7 +873,7 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I checkitem_toggled, checkitem_update, verb); } } else { - sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view); + sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view, show_icon); group = NULL; } } else { -- cgit v1.2.3 From 22d06152d0fabc7fe50bb6829f00b2bac4ed1796 Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Thu, 29 Jun 2017 13:43:56 +0200 Subject: Remove old icon handling code --- src/ui/interface.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index d1da47867..4246ae34e 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -36,7 +36,6 @@ #include "extension/db.h" #include "extension/effect.h" #include "extension/input.h" -#include "widgets/icon.h" #include "preferences.h" #include "shortcuts.h" #include "document.h" -- cgit v1.2.3 From d0dd42c6b365170d3113251cf87d7ebb74c7ef3e Mon Sep 17 00:00:00 2001 From: Alexander Valavanis Date: Thu, 29 Jun 2017 15:31:52 +0200 Subject: interface: Rm unused function --- src/ui/interface.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'src/ui/interface.cpp') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 4246ae34e..a0ee5c72b 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -136,8 +136,6 @@ static void sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name); static void sp_recent_open(GtkRecentChooser *, gpointer); -static void injectRenamedIcons(); - static const int MIN_ONSCREEN_DISTANCE = 50; void @@ -1441,33 +1439,6 @@ sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name) } } } - -void injectRenamedIcons() -{ - Glib::RefPtr iconTheme = Gtk::IconTheme::get_default(); - - std::vector< std::pair > renamed; - renamed.push_back(std::make_pair("gtk-file", "document-x-generic")); - renamed.push_back(std::make_pair("gtk-directory", "folder")); - - for ( std::vector< std::pair >::iterator it = renamed.begin(); it < renamed.end(); ++it ) { - bool hasIcon = iconTheme->has_icon(it->first); - bool hasSecondIcon = iconTheme->has_icon(it->second); - - if ( !hasIcon && hasSecondIcon ) { - Glib::ArrayHandle sizes = iconTheme->get_icon_sizes(it->second); - for ( Glib::ArrayHandle::iterator it2 = sizes.begin(); it2 < sizes.end(); ++it2 ) { - Glib::RefPtr pb = iconTheme->load_icon( it->second, *it2 ); - if ( pb ) { - // install a private copy of the pixbuf to avoid pinning a theme - Glib::RefPtr pbCopy = pb->copy(); - Gtk::IconTheme::add_builtin_icon( it->first, *it2, pbCopy ); - } - } - } - } -} - /* Local Variables: mode:c++ -- cgit v1.2.3