diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2017-06-29 12:35:19 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2017-06-29 12:35:19 +0000 |
| commit | 2380b3e055e1fb4167d2aff01a79b1d06f1d10f7 (patch) | |
| tree | adc5683e882c8a04bb8177350deb0072491c8edc /src/ui | |
| parent | Add replacements for themedir for osx and win32 (diff) | |
| parent | Add missing icon (diff) | |
| download | inkscape-2380b3e055e1fb4167d2aff01a79b1d06f1d10f7.tar.gz inkscape-2380b3e055e1fb4167d2aff01a79b1d06f1d10f7.zip | |
Hackfest icon work: restore selected menu icons and make theming easier
Diffstat (limited to 'src/ui')
43 files changed, 1552 insertions, 1260 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 389e8902a..c253daed9 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -1,5 +1,6 @@ set(ui_SRC clipboard.cpp + contextmenu.cpp control-manager.cpp dialog-events.cpp draw-anchor.cpp @@ -173,6 +174,7 @@ set(ui_SRC # ------- # Headers clipboard.h + contextmenu.h control-manager.h control-types.h dialog-events.h diff --git a/src/ui/contextmenu.cpp b/src/ui/contextmenu.cpp new file mode 100644 index 000000000..1bc87574e --- /dev/null +++ b/src/ui/contextmenu.cpp @@ -0,0 +1,914 @@ +/** + * @file + * Context menu + */ +/* Authors: + * Lauris Kaplinski <lauris@kaplinski.com> + * Frank Felfe <innerspace@iname.com> + * bulia byak <buliabyak@users.sf.net> + * Jon A. Cruz <jon@joncruz.org> + * Abhishek Sharma + * Kris De Gussem <Kris.DeGussem@gmail.com> + * + * Copyright (C) 2012 Kris De Gussem + * Copyright (C) 2010 authors + * Copyright (C) 1999-2005 authors + * Copyright (C) 2004 David Turner + * Copyright (C) 2001-2002 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "contextmenu.h" + +#include <glibmm/i18n.h> +#include <glibmm/miscutils.h> + +#include <gtkmm/box.h> +#include <gtkmm/image.h> +#include <gtkmm/separatormenuitem.h> + +#include "desktop.h" +#include "document.h" +#include "document-undo.h" +#include "helper/action.h" +#include "helper/action-context.h" +#include "inkscape.h" +#include "message-context.h" +#include "message-stack.h" +#include "selection.h" +#include "selection-chemistry.h" +#include "shortcuts.h" +#include "sp-anchor.h" +#include "sp-clippath.h" +#include "sp-image.h" +#include "sp-item.h" +#include "sp-mask.h" +#include "sp-shape.h" +#include "sp-text.h" +#include "ui/dialog/dialog-manager.h" +#include "ui/dialog/layer-properties.h" +#include "verbs.h" + +static bool temporarily_block_actions = false; + +ContextMenu::ContextMenu(SPDesktop *desktop, SPItem *item) : + _item(item), + MIGroup(), + MIParent(_("Go to parent")) +{ +// g_message("ContextMenu"); + _object = static_cast<SPObject *>(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<std::vector< SPItem * > >(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<std::vector< SPItem * > >(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. <g id="#g7">, 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<SPObject *>(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<SPItem *> 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<SPItem *> items) +{ + _desktop->selection->clear(); + for(auto i=items.begin();i!=items.end(); ++i) { + if ((*i)->isHidden()) { + (*i)->setHidden(false); + _desktop->selection->add(*i); + } + } +} + +/* + * Some day when the right-click menus are ready to start working + * smarter with the verbs, we'll need to change this NULL being + * sent to sp_action_perform to something useful, or set some kind + * of global "right-clicked position" variable for actions to + * investigate when they're called. + */ +static void +context_menu_item_on_my_activate(void */*object*/, SPAction *action) +{ + if (!temporarily_block_actions) { + sp_action_perform(action, NULL); + } +} + +static void +context_menu_item_on_my_select(void */*object*/, SPAction *action) +{ + sp_action_get_view(action)->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, action->tip); +} + +static void +context_menu_item_on_my_deselect(void */*object*/, SPAction *action) +{ + sp_action_get_view(action)->tipsMessageContext()->clear(); +} + + +// 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; + } + + auto const item = Gtk::manage(new Gtk::MenuItem(action->name, true)); + + 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(context_menu_item_on_my_activate),item,action)); + item->signal_select().connect(sigc::bind(sigc::ptr_fun(context_menu_item_on_my_select),item,action)); + item->signal_deselect().connect(sigc::bind(sigc::ptr_fun(context_menu_item_on_my_deselect),item,action)); + item->show_all(); + append(*item); + } +} + +void ContextMenu::MakeObjectMenu(void) +{ + 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); + + Inkscape::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<SPItem*> children; + + sp_item_group_ungroup(static_cast<SPGroup*>(_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<SPItem*> children; + sp_item_group_ungroup(static_cast<SPAnchor*>(_item), children, false); + Inkscape::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++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/contextmenu.h b/src/ui/contextmenu.h new file mode 100644 index 000000000..faae6358f --- /dev/null +++ b/src/ui/contextmenu.h @@ -0,0 +1,218 @@ +#ifndef SEEN_CONTEXTMENU_H +#define SEEN_CONTEXTMENU_H + +/* + * Context menu + * + * Authors: + * Lauris Kaplinski <lauris@kaplinski.com> + * Frank Felfe <innerspace@iname.com> + * Abhishek Sharma + * Kris De Gussem <Kris.DeGussem@gmail.com> + * + * Copyright (C) 2012 Kris De Gussem + * Copyright (C) 1999-2002 authors + * Copyright (C) 2001-2002 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <gtkmm/menu.h> + +class SPDesktop; +class SPItem; +class SPObject; + +namespace Gtk { +class SeparatorMenuItem; +} + +namespace Inkscape { +class Verb; +} + +/** + * Implements the Inkscape context menu. + * + * For the context menu implementation, the ContextMenu class stores the object + * that was selected in a private data member. This should be farely safe to do + * and a pointer to the SPItem as well as SPObject class are kept. + * All callbacks of the context menu entries are implemented as private + * functions. + * + * @todo add callbacks to destroy the context menu when it is closed (=key or mouse button pressed out of the scope of the context menu) + */ +class ContextMenu : public Gtk::Menu +{ + public: + /** + * The ContextMenu constructor contains all code to create and show the + * menu entries (aka child widgets). + * + * @param desktop pointer to the desktop the user is currently working on. + * @param item SPItem pointer to the object selected at the time the ContextMenu is created. + */ + ContextMenu(SPDesktop *desktop, SPItem *item); + ~ContextMenu(void); + + private: + SPItem *_item; // pointer to the object selected at the time the ContextMenu is created + SPObject *_object; // pointer to the object selected at the time the ContextMenu is created + SPDesktop *_desktop; //pointer to the desktop the user was currently working on at the time the ContextMenu is created + + int positionOfLastDialog; + + Gtk::MenuItem MIGroup; //menu entry to enter a group + Gtk::MenuItem MIParent; //menu entry to leave a group + + /** + * auxiliary function that adds a separator line in the context menu + */ + Gtk::SeparatorMenuItem* AddSeparator(void); + + /** + * c++ified version of sp_ui_menu_append_item. + * + * @see sp_ui_menu_append_item_from_verb and synchronize/drop that function when c++ifying other code in interface.cpp + */ + void AppendItemFromVerb(Inkscape::Verb *verb); + + /** + * main function which is responsible for creating the context sensitive menu items, + * calls subfunctions below to create the menu entry widgets. + */ + void MakeObjectMenu (void); + /** + * creates menu entries for an SP_TYPE_ITEM object + */ + void MakeItemMenu (void); + /** + * creates menu entries for a grouped object + */ + void MakeGroupMenu (void); + /** + * creates menu entries for an anchor object + */ + void MakeAnchorMenu (void); + /** + * creates menu entries for a bitmap image object + */ + void MakeImageMenu (void); + /** + * creates menu entries for a shape object + */ + void MakeShapeMenu (void); + /** + * creates menu entries for a text object + */ + void MakeTextMenu (void); + + void EnterGroup(Gtk::MenuItem* mi); + void LeaveGroup(void); + void LockSelected(void); + void HideSelected(void); + void UnLockBelow(std::vector<SPItem *> items); + void UnHideBelow(std::vector<SPItem *> items); + ////////////////////////////////////////// + //callbacks for the context menu entries of an SP_TYPE_ITEM object + void ItemProperties(void); + void ItemSelectThis(void); + void ItemMoveTo(void); + void SelectSameFillStroke(void); + void SelectSameFillColor(void); + void SelectSameStrokeColor(void); + void SelectSameStrokeStyle(void); + void SelectSameObjectType(void); + void ItemCreateLink(void); + void CreateGroupClip(void); + void SetMask(void); + void ReleaseMask(void); + void SetClip(void); + void ReleaseClip(void); + ////////////////////////////////////////// + + + /** + * callback, is executed on clicking the anchor "Group" and "Ungroup" menu entry + */ + void ActivateUngroupPopSelection(void); + void ActivateUngroup(void); + void ActivateGroup(void); + + void AnchorLinkProperties(void); + /** + * placeholder for callback to be executed on clicking the anchor "Follow link" context menu entry + * @todo add code to follow link externally + */ + void AnchorLinkFollow(void); + + /** + * callback, is executed on clicking the anchor "Link remove" menu entry + */ + void AnchorLinkRemove(void); + + + /** + * callback, opens the image properties dialog and is executed on clicking the context menu entry with similar name + */ + void ImageProperties(void); + + /** + * callback, is executed on clicking the image "Edit Externally" menu entry + */ + void ImageEdit(void); + + /** + * auxiliary function that loads the external image editor name from the settings. + */ + Glib::ustring getImageEditorName(); + + /** + * callback, is executed on clicking the "Embed Image" menu entry + */ + void ImageEmbed(void); + + /** + * callback, is executed on clicking the "Trace Bitmap" menu entry + */ + void ImageTraceBitmap(void); + + /** + * callback, is executed on clicking the "Trace Pixel Art" menu entry + */ + void ImageTracePixelArt(void); + + /** + * callback, is executed on clicking the "Extract Image" menu entry + */ + void ImageExtract(void); + + + /** + * callback, is executed on clicking the "Fill and Stroke" menu entry + */ + void FillSettings(void); + + + /** + * callback, is executed on clicking the "Text and Font" menu entry + */ + void TextSettings(void); + + /** + * callback, is executed on clicking the "Check spelling" menu entry + */ + void SpellcheckSettings(void); +}; +#endif // SEEN_CONTEXT_MENU_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 1c88fc849..27bfa681f 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -41,7 +41,6 @@ #include "ui/tool/multi-path-manipulator.h" #include "ui/tool/control-point-selection.h" #include "verbs.h" -#include "widgets/icon.h" #include "sp-root.h" #include "document-undo.h" #include "desktop.h" @@ -64,7 +63,8 @@ Action::Action(const Glib::ustring &id, _id(id), _parent(parent) { - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( _id, Inkscape::ICON_SIZE_LARGE_TOOLBAR) ); + Gtk::Image* pIcon = Gtk::manage(new Gtk::Image()); + pIcon->set_from_icon_name( _id, Gtk::ICON_SIZE_LARGE_TOOLBAR); Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 3cdcf594a..cef3c0c71 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -49,7 +49,6 @@ #include "ui/widget/spinbutton.h" #include "unclump.h" #include "verbs.h" -#include "widgets/icon.h" using Inkscape::DocumentUndo; using Inkscape::Util::unit_table; @@ -2678,7 +2677,7 @@ GtkWidget * CloneTiler::table_x_y_rand(int values) auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); - GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON("object-rows")); + GtkWidget *i = gtk_image_new_from_icon_name (INKSCAPE_ICON("object-rows"), GTK_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2); GtkWidget *l = gtk_label_new (""); @@ -2692,7 +2691,7 @@ GtkWidget * CloneTiler::table_x_y_rand(int values) auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); - GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON("object-columns")); + GtkWidget *i = gtk_image_new_from_icon_name (INKSCAPE_ICON("object-columns"), GTK_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2); GtkWidget *l = gtk_label_new (""); diff --git a/src/ui/dialog/cssdialog.cpp b/src/ui/dialog/cssdialog.cpp index 85c804b75..0443d7c44 100644 --- a/src/ui/dialog/cssdialog.cpp +++ b/src/ui/dialog/cssdialog.cpp @@ -13,7 +13,6 @@ #include "cssdialog.h" #include "ui/widget/addtoicon.h" -#include "widgets/icon.h" #include "verbs.h" #include "sp-object.h" #include "selection.h" @@ -122,7 +121,7 @@ void CssDialog::setDesktop(SPDesktop* desktop) void CssDialog::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { - GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + GtkWidget *child = gtk_image_new_from_icon_name(iconName, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show(child); btn.add(*manage(Glib::wrap(child))); btn.set_relief(Gtk::RELIEF_NONE); diff --git a/src/ui/dialog/dock-behavior.cpp b/src/ui/dialog/dock-behavior.cpp index 02955b9a8..299584a31 100644 --- a/src/ui/dialog/dock-behavior.cpp +++ b/src/ui/dialog/dock-behavior.cpp @@ -19,7 +19,6 @@ #include "inkscape.h" #include "desktop.h" #include "ui/interface.h" -#include "widgets/icon.h" #include "ui/widget/dock.h" #include "verbs.h" #include "dialog.h" diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 8593223c1..1b074bb0c 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -34,7 +34,6 @@ #include "ui/tools-switch.h" #include "ui/dialog/filedialog.h" #include "verbs.h" -#include "widgets/icon.h" #include "xml/node-event-vector.h" #include "rdf.h" @@ -74,7 +73,7 @@ static Inkscape::XML::NodeEventVector const _repr_events = { static void docprops_style_button(Gtk::Button& btn, char const* iconName) { - GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + GtkWidget *child = gtk_image_new_from_icon_name(iconName, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show( child ); btn.add(*Gtk::manage(Glib::wrap(child))); btn.set_relief(Gtk::RELIEF_NONE); @@ -1429,8 +1428,10 @@ DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char * { Gtk::HBox *_tab_label_box = Gtk::manage(new Gtk::HBox(false, 0)); _tab_label_box->set_spacing(4); - _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION, - label_image))); + + auto img = Gtk::manage(new Gtk::Image()); + img->set_from_icon_name(label_image, Gtk::ICON_SIZE_MENU); + _tab_label_box->pack_start(*img); Gtk::Label *_tab_label = Gtk::manage(new Gtk::Label(label, true)); _tab_label_box->pack_start(*_tab_label); diff --git a/src/ui/dialog/fill-and-stroke.cpp b/src/ui/dialog/fill-and-stroke.cpp index 0b3b468e9..b271c951b 100644 --- a/src/ui/dialog/fill-and-stroke.cpp +++ b/src/ui/dialog/fill-and-stroke.cpp @@ -28,7 +28,6 @@ #include "ui/icon-names.h" #include "verbs.h" #include "widgets/fill-style.h" -#include "widgets/icon.h" #include "widgets/paint-selector.h" #include "widgets/stroke-style.h" @@ -173,8 +172,10 @@ Gtk::HBox& FillAndStroke::_createPageTabLabel(const Glib::ustring& label, const char *label_image) { Gtk::HBox *_tab_label_box = Gtk::manage(new Gtk::HBox(false, 4)); - _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION, - label_image))); + + auto img = Gtk::manage(new Gtk::Image()); + img->set_from_icon_name(label_image, Gtk::ICON_SIZE_MENU); + _tab_label_box->pack_start(*img); Gtk::Label *_tab_label = Gtk::manage(new Gtk::Label(label, true)); _tab_label_box->pack_start(*_tab_label); diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 9ec8d3148..5d7422279 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -28,7 +28,6 @@ #include "document.h" #include "document-undo.h" -#include "widgets/icon.h" #include "desktop.h" //#include "sp-item-transform.h" FIXME #include "ui/dialog/tile.h" // for Inkscape::UI::Dialog::ArrangeDialog diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 19050fb1d..7b1e531b4 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -31,9 +31,12 @@ #include "desktop.h" +#include "display/cairo-utils.h" #include "display/drawing.h" +#include "display/drawing-context.h" #include "document.h" #include "inkscape.h" +#include "sp-namedview.h" #include "sp-root.h" #include "verbs.h" @@ -41,7 +44,6 @@ extern "C" { // takes doc, drawing, icon, and icon name to produce pixels -// this is defined in widgets/icon.cpp guchar * sp_icon_doc_icon( SPDocument *doc, Inkscape::Drawing &drawing, const gchar *name, unsigned int psize, unsigned &stride); @@ -428,6 +430,190 @@ void IconPreviewPanel::modeToggled() refreshPreview(); } +void overlayPixels(guchar *px, int width, int height, int stride, + unsigned r, unsigned g, unsigned b) +{ + int bytesPerPixel = 4; + int spacing = 4; + for ( int y = 0; y < height; y += spacing ) { + guchar *ptr = px + y * stride; + for ( int x = 0; x < width; x += spacing ) { + *(ptr++) = r; + *(ptr++) = g; + *(ptr++) = b; + *(ptr++) = 0xff; + + ptr += bytesPerPixel * (spacing - 1); + } + } + + if ( width > 1 && height > 1 ) { + // point at the last pixel + guchar *ptr = px + ((height-1) * stride) + ((width - 1) * bytesPerPixel); + + if ( width > 2 ) { + px[4] = r; + px[5] = g; + px[6] = b; + px[7] = 0xff; + + ptr[-12] = r; + ptr[-11] = g; + ptr[-10] = b; + ptr[-9] = 0xff; + } + + ptr[-4] = r; + ptr[-3] = g; + ptr[-2] = b; + ptr[-1] = 0xff; + + px[0 + stride] = r; + px[1 + stride] = g; + px[2 + stride] = b; + px[3 + stride] = 0xff; + + ptr[0 - stride] = r; + ptr[1 - stride] = g; + ptr[2 - stride] = b; + ptr[3 - stride] = 0xff; + + if ( height > 2 ) { + ptr[0 - stride * 3] = r; + ptr[1 - stride * 3] = g; + ptr[2 - stride * 3] = b; + ptr[3 - stride * 3] = 0xff; + } + } +} + +// takes doc, drawing, icon, and icon name to produce pixels +extern "C" guchar * +sp_icon_doc_icon( SPDocument *doc, Inkscape::Drawing &drawing, + gchar const *name, unsigned psize, + unsigned &stride) +{ + bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg"); + guchar *px = NULL; + + if (doc) { + SPObject *object = doc->getObjectById(name); + if (object && SP_IS_ITEM(object)) { + SPItem *item = SP_ITEM(object); + // Find bbox in document + Geom::OptRect dbox = item->documentVisualBounds(); + + if ( object->parent == NULL ) + { + dbox = Geom::Rect(Geom::Point(0, 0), + Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px"))); + } + + /* This is in document coordinates, i.e. pixels */ + if ( dbox ) { + /* Update to renderable state */ + double sf = 1.0; + drawing.root()->setTransform(Geom::Scale(sf)); + drawing.update(); + /* Item integer bbox in points */ + // NOTE: previously, each rect coordinate was rounded using floor(c + 0.5) + Geom::IntRect ibox = dbox->roundOutwards(); + + if ( dump ) { + g_message( " box --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.left(), (double)ibox.top(), (double)ibox.right(), (double)ibox.bottom() ); + } + + /* Find button visible area */ + int width = ibox.width(); + int height = ibox.height(); + + if ( dump ) { + g_message( " vis --'%s' (%d,%d)", name, width, height ); + } + + { + int block = std::max(width, height); + if (block != static_cast<int>(psize) ) { + if ( dump ) { + g_message(" resizing" ); + } + sf = (double)psize / (double)block; + + drawing.root()->setTransform(Geom::Scale(sf)); + drawing.update(); + + auto scaled_box = *dbox * Geom::Scale(sf); + ibox = scaled_box.roundOutwards(); + if ( dump ) { + g_message( " box2 --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.left(), (double)ibox.top(), (double)ibox.right(), (double)ibox.bottom() ); + } + + /* Find button visible area */ + width = ibox.width(); + height = ibox.height(); + if ( dump ) { + g_message( " vis2 --'%s' (%d,%d)", name, width, height ); + } + } + } + + Geom::IntPoint pdim(psize, psize); + int dx, dy; + //dx = (psize - width) / 2; + //dy = (psize - height) / 2; + dx=dy=psize; + dx=(dx-width)/2; // watch out for psize, since 'unsigned'-'signed' can cause problems if the result is negative + dy=(dy-height)/2; + Geom::IntRect area = Geom::IntRect::from_xywh(ibox.min() - Geom::IntPoint(dx,dy), pdim); + /* Actual renderable area */ + Geom::IntRect ua = *Geom::intersect(ibox, area); + + if ( dump ) { + g_message( " area --'%s' (%f,%f)-(%f,%f)", name, (double)area.left(), (double)area.top(), (double)area.right(), (double)area.bottom() ); + g_message( " ua --'%s' (%f,%f)-(%f,%f)", name, (double)ua.left(), (double)ua.top(), (double)ua.right(), (double)ua.bottom() ); + } + + stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, psize); + + /* Set up pixblock */ + px = g_new(guchar, stride * psize); + memset(px, 0x00, stride * psize); + + /* Render */ + cairo_surface_t *s = cairo_image_surface_create_for_data(px, + CAIRO_FORMAT_ARGB32, psize, psize, stride); + Inkscape::DrawingContext dc(s, ua.min()); + + SPNamedView *nv = sp_document_namedview(doc, NULL); + float bg_r = SP_RGBA32_R_F(nv->pagecolor); + float bg_g = SP_RGBA32_G_F(nv->pagecolor); + float bg_b = SP_RGBA32_B_F(nv->pagecolor); + float bg_a = SP_RGBA32_A_F(nv->pagecolor); + + cairo_t *cr = cairo_create(s); + cairo_set_source_rgba(cr, bg_r, bg_g, bg_b, bg_a); + cairo_rectangle(cr, 0, 0, psize, psize); + cairo_fill(cr); + cairo_save(cr); + cairo_destroy(cr); + + drawing.render(dc, ua); + cairo_surface_destroy(s); + + // convert to GdkPixbuf format + convert_pixels_argb32_to_pixbuf(px, psize, psize, stride); + + if ( Inkscape::Preferences::get()->getBool("/debug/icons/overlaySvg") ) { + overlayPixels( px, psize, psize, stride, 0x00, 0x00, 0xff ); + } + } + } + } + + return px; +} // end of sp_icon_doc_icon() + + void IconPreviewPanel::renderPreview( SPObject* obj ) { SPDocument * doc = obj->document; diff --git a/src/ui/dialog/layers.cpp b/src/ui/dialog/layers.cpp index dd9d7ec25..be3b4af06 100644 --- a/src/ui/dialog/layers.cpp +++ b/src/ui/dialog/layers.cpp @@ -31,7 +31,6 @@ #include "ui/icon-names.h" #include "ui/widget/imagetoggler.h" #include "verbs.h" -#include "widgets/icon.h" #include "sp-root.h" #include "ui/tools/tool-base.h" #include "selection-chemistry.h" @@ -82,7 +81,7 @@ void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned i bool set = false; if ( iconName ) { - GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName ); + GtkWidget *child = gtk_image_new_from_icon_name( iconName, GTK_ICON_SIZE_SMALL_TOOLBAR ); gtk_widget_show( child ); btn.add( *Gtk::manage(Glib::wrap(child)) ); btn.set_relief(Gtk::RELIEF_NONE); @@ -94,7 +93,7 @@ void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned i if ( verb ) { SPAction *action = verb->get_action(Inkscape::ActionContext(desktop)); if ( !set && action && action->image ) { - GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image ); + GtkWidget *child = gtk_image_new_from_icon_name( action->image, GTK_ICON_SIZE_SMALL_TOOLBAR ); gtk_widget_show( child ); btn.add( *Gtk::manage(Glib::wrap(child)) ); set = true; @@ -118,7 +117,7 @@ Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code const char* label = 0; if ( iconName ) { - iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName ); + iconWidget = gtk_image_new_from_icon_name( iconName, GTK_ICON_SIZE_MENU ); } if ( desktop ) { @@ -126,7 +125,7 @@ Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code if ( verb ) { SPAction *action = verb->get_action(Inkscape::ActionContext(desktop)); if ( !iconWidget && action && action->image ) { - iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image ); + iconWidget = gtk_image_new_from_icon_name( action->image, GTK_ICON_SIZE_MENU ); } if ( action ) { diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index bb9b61504..98789f7b2 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -36,7 +36,6 @@ #include "ui/icon-names.h" #include "ui/widget/imagetoggler.h" #include "verbs.h" -#include "widgets/icon.h" #include "livepatheffect-add.h" namespace Inkscape { @@ -67,7 +66,7 @@ void lpeeditor_selection_modified (Inkscape::Selection * selection, guint /*flag static void lpe_style_button(Gtk::Button& btn, char const* iconName) { - GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + GtkWidget *child = gtk_image_new_from_icon_name(iconName, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show( child ); btn.add(*Gtk::manage(Glib::wrap(child))); btn.set_relief(Gtk::RELIEF_NONE); diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index fd78fec90..e76da241a 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -47,7 +47,6 @@ #include "ui/tools/node-tool.h" #include "verbs.h" #include "ui/widget/color-notebook.h" -#include "widgets/icon.h" #include "xml/node-observer.h" //#define DUMP_LAYERS 1 @@ -224,7 +223,7 @@ public: */ void ObjectsPanel::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { - GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName ); + GtkWidget *child = gtk_image_new_from_icon_name( iconName, GTK_ICON_SIZE_SMALL_TOOLBAR ); gtk_widget_show( child ); btn.add( *Gtk::manage(Glib::wrap(child)) ); btn.set_relief(Gtk::RELIEF_NONE); @@ -246,7 +245,7 @@ Gtk::MenuItem& ObjectsPanel::_addPopupItem( SPDesktop *desktop, unsigned int cod const char* label = 0; if ( iconName ) { - iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName ); + iconWidget = gtk_image_new_from_icon_name( iconName, GTK_ICON_SIZE_MENU ); } if ( desktop ) { @@ -254,7 +253,7 @@ Gtk::MenuItem& ObjectsPanel::_addPopupItem( SPDesktop *desktop, unsigned int cod if ( verb ) { SPAction *action = verb->get_action(desktop); if ( !iconWidget && action && action->image ) { - iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image ); + iconWidget = gtk_image_new_from_icon_name( action->image, GTK_ICON_SIZE_MENU ); } if ( action ) { diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 9485b6ba3..b65a67e06 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -19,7 +19,6 @@ #include "document.h" #include "document-undo.h" -#include "widgets/icon.h" #include "desktop.h" #include "sp-ellipse.h" #include "sp-item-transform.h" diff --git a/src/ui/dialog/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp index 045ce3459..4f7657f4f 100644 --- a/src/ui/dialog/spellcheck.cpp +++ b/src/ui/dialog/spellcheck.cpp @@ -13,7 +13,6 @@ */ #include "spellcheck.h" -#include "widgets/icon.h" #include "message-stack.h" #include "helper/window.h" diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 8679659ce..73dd6937a 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -13,7 +13,6 @@ #include "styledialog.h" #include "ui/widget/addtoicon.h" -#include "widgets/icon.h" #include "verbs.h" #include "sp-object.h" #include "selection.h" @@ -1515,7 +1514,7 @@ bool StyleDialog::_delProperty(GdkEventButton *event) void StyleDialog::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { - GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + GtkWidget *child = gtk_image_new_from_icon_name(iconName, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show(child); btn.add(*manage(Glib::wrap(child))); btn.set_relief(Gtk::RELIEF_NONE); diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index b7a43a1ca..aa3d86b00 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -48,7 +48,6 @@ #include "sp-use.h" #include "sp-defs.h" #include "sp-symbol.h" -#include "widgets/icon.h" #ifdef WITH_LIBVISIO #include <libvisio/libvisio.h> @@ -175,18 +174,22 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : scroller->set_hexpand(); table->attach(*Gtk::manage(tools),0,row,2,1); + auto addSymbolImage = Gtk::manage(new Gtk::Image()); + addSymbolImage->set_from_icon_name("symbol-add", Gtk::ICON_SIZE_SMALL_TOOLBAR); + addSymbol = Gtk::manage(new Gtk::Button()); - addSymbol->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("symbol-add")))) ); + addSymbol->add(*addSymbolImage); addSymbol->set_tooltip_text(_("Add Symbol from the current document.")); addSymbol->set_relief( Gtk::RELIEF_NONE ); addSymbol->set_focus_on_click( false ); addSymbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); tools->pack_start(* addSymbol, Gtk::PACK_SHRINK); + auto removeSymbolImage = Gtk::manage(new Gtk::Image()); + removeSymbolImage->set_from_icon_name("symbol-remove", Gtk::ICON_SIZE_SMALL_TOOLBAR); + removeSymbol = Gtk::manage(new Gtk::Button()); - removeSymbol->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("symbol-remove")))) ); + removeSymbol->add(*removeSymbolImage); removeSymbol->set_tooltip_text(_("Remove Symbol from the current document.")); removeSymbol->set_relief( Gtk::RELIEF_NONE ); removeSymbol->set_focus_on_click( false ); @@ -198,18 +201,23 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : // Pack size (controls display area) pack_size = 2; // Default 32px + + auto packMoreImage = Gtk::manage(new Gtk::Image()); + packMoreImage->set_from_icon_name("pack-more", Gtk::ICON_SIZE_SMALL_TOOLBAR); + button = Gtk::manage(new Gtk::Button()); - button->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("pack-more")))) ); + button->add(*packMoreImage); button->set_tooltip_text(_("Display more icons in row.")); button->set_relief( Gtk::RELIEF_NONE ); button->set_focus_on_click( false ); button->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::packmore)); tools->pack_start(* button, Gtk::PACK_SHRINK); + auto packLessImage = Gtk::manage(new Gtk::Image()); + packLessImage->set_from_icon_name("pack-less", Gtk::ICON_SIZE_SMALL_TOOLBAR); + button = Gtk::manage(new Gtk::Button()); - button->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("pack-less")))) ); + button->add(*packLessImage); button->set_tooltip_text(_("Display fewer icons in row.")); button->set_relief( Gtk::RELIEF_NONE ); button->set_focus_on_click( false ); @@ -217,9 +225,11 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : tools->pack_start(* button, Gtk::PACK_SHRINK); // Toggle scale to fit on/off + auto fitSymbolImage = Gtk::manage(new Gtk::Image()); + fitSymbolImage->set_from_icon_name("symbol-fit", Gtk::ICON_SIZE_SMALL_TOOLBAR); + fitSymbol = Gtk::manage(new Gtk::ToggleButton()); - fitSymbol->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("symbol-fit")))) ); + fitSymbol->add(*fitSymbolImage); fitSymbol->set_tooltip_text(_("Toggle 'fit' symbols in icon space.")); fitSymbol->set_relief( Gtk::RELIEF_NONE ); fitSymbol->set_focus_on_click( false ); @@ -229,9 +239,11 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : // Render size (scales symbols within display area) scale_factor = 0; // Default 1:1 * pack_size/pack_size default + auto zoomOutImage = Gtk::manage(new Gtk::Image()); + zoomOutImage->set_from_icon_name("symbol-smaller", Gtk::ICON_SIZE_SMALL_TOOLBAR); + zoomOut = Gtk::manage(new Gtk::Button()); - zoomOut->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("symbol-smaller")))) ); + zoomOut->add(*zoomOutImage); zoomOut->set_tooltip_text(_("Make symbols smaller by zooming out.")); zoomOut->set_relief( Gtk::RELIEF_NONE ); zoomOut->set_focus_on_click( false ); @@ -239,9 +251,11 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : zoomOut->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::zoomout)); tools->pack_start(* zoomOut, Gtk::PACK_SHRINK); + auto zoomInImage = Gtk::manage(new Gtk::Image()); + zoomInImage->set_from_icon_name("symbol-bigger", Gtk::ICON_SIZE_SMALL_TOOLBAR); + zoomIn = Gtk::manage(new Gtk::Button()); - zoomIn->add(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("symbol-bigger")))) ); + zoomIn->add(*zoomInImage); zoomIn->set_tooltip_text(_("Make symbols bigger by zooming in.")); zoomIn->set_relief( Gtk::RELIEF_NONE ); zoomIn->set_focus_on_click( false ); diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index dfe71bddb..b990ccfef 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -31,7 +31,6 @@ #include "ui/widget/layertypeicon.h" #include "ui/widget/addtoicon.h" #include "verbs.h" -#include "widgets/icon.h" #include "xml/node-observer.h" #include "sp-root.h" #include "ui/tools/tool-base.h" //"event-context.h" @@ -130,7 +129,7 @@ public: void TagsPanel::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { - GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + GtkWidget *child = gtk_image_new_from_icon_name(iconName, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show(child); btn.add(*manage(Glib::wrap(child))); btn.set_relief(Gtk::RELIEF_NONE); @@ -144,7 +143,7 @@ Gtk::MenuItem& TagsPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, const char* label = 0; if ( iconName ) { - iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName ); + iconWidget = gtk_image_new_from_icon_name( iconName, GTK_ICON_SIZE_MENU ); } if ( desktop ) { @@ -152,7 +151,7 @@ Gtk::MenuItem& TagsPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, if ( verb ) { SPAction *action = verb->get_action(desktop); if ( !iconWidget && action && action->image ) { - iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image ); + iconWidget = gtk_image_new_from_icon_name( action->image, GTK_ICON_SIZE_MENU ); } if ( action ) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 94f307828..c7d899f45 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -45,7 +45,6 @@ extern "C" { #include "verbs.h" #include "ui/interface.h" #include "svg/css-ostringstream.h" -#include "widgets/icon.h" #include "widgets/font-selector.h" #include <glibmm/i18n.h> #include <glibmm/markup.h> @@ -103,26 +102,6 @@ TextEdit::TextEdit() layout_hbox.pack_start(text_sep, false, false, 10); - /* Line Spacing */ - /* Commented out as this does not handle non-percentage values - GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("text_line_spacing") ); - layout_hbox.pack_start(*Gtk::manage(Glib::wrap(px)), false, false); - - spacing_combo = gtk_combo_box_text_new_with_entry (); - gtk_widget_set_size_request (spacing_combo, 90, -1); - - const gchar *spacings[] = {"50%", "80%", "90%", "100%", "110%", "120%", "130%", "140%", "150%", "200%", "300%", NULL}; - for (int i = 0; spacings[i]; i++) { - gtk_combo_box_text_append_text((GtkComboBoxText *) spacing_combo, spacings[i]); - } - - gtk_widget_set_tooltip_text (px, _("Spacing between baselines (percent of font size)")); - gtk_widget_set_tooltip_text (spacing_combo, _("Spacing between baselines (percent of font size)")); - layout_hbox.pack_start(*Gtk::manage(Glib::wrap(spacing_combo)), false, false); - layout_frame.set_padding(4,4,4,4); - layout_frame.add(layout_hbox); - */ - // Text start Offset { startOffset = gtk_combo_box_text_new_with_entry (); @@ -223,10 +202,7 @@ TextEdit::~TextEdit() void TextEdit::styleButton(Gtk::RadioButton *button, gchar const *tooltip, gchar const *icon_name, Gtk::RadioButton *group_button ) { - GtkWidget *icon = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, icon_name ); - if (!GTK_IS_IMAGE(icon)) { - icon = gtk_image_new_from_icon_name ( icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR ); - } + GtkWidget *icon = gtk_image_new_from_icon_name( icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR ); if (group_button) { Gtk::RadioButton::Group group = group_button->get_group(); diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index d209a450c..5ad1b9ec5 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -31,7 +31,6 @@ #include "sp-namedview.h" #include "sp-item-transform.h" #include "ui/icon-names.h" -#include "widgets/icon.h" namespace Inkscape { @@ -278,14 +277,18 @@ void Transformation::layoutPageRotate() _scalar_rotate.setDigits(3); _scalar_rotate.setIncrements(0.1, 1.0); - _counterclockwise_rotate.add(*manage( Glib::wrap( - sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("object-rotate-left"))))); + auto object_rotate_left_icon = Gtk::manage(new Gtk::Image()); + object_rotate_left_icon->set_from_icon_name("object-rotate-left", Gtk::ICON_SIZE_SMALL_TOOLBAR); + + _counterclockwise_rotate.add(*object_rotate_left_icon); _counterclockwise_rotate.set_mode(false); _counterclockwise_rotate.set_relief(Gtk::RELIEF_NONE); _counterclockwise_rotate.set_tooltip_text(_("Rotate in a counterclockwise direction")); - _clockwise_rotate.add(*manage( Glib::wrap( - sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("object-rotate-right"))))); + auto object_rotate_right_icon = Gtk::manage(new Gtk::Image()); + object_rotate_right_icon->set_from_icon_name("object-rotate-right", Gtk::ICON_SIZE_SMALL_TOOLBAR); + + _clockwise_rotate.add(*object_rotate_right_icon); _clockwise_rotate.set_mode(false); _clockwise_rotate.set_relief(Gtk::RELIEF_NONE); _clockwise_rotate.set_tooltip_text(_("Rotate in a clockwise direction")); diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index bf5bdc76d..3d6d71e9a 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -44,16 +44,13 @@ void CellRendererSPIcon::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr, if ( !_icon_cache[_property_event_type] ) { Glib::ustring image_name = Inkscape::Verb::get(_property_event_type)->get_image(); - Gtk::Widget* icon = sp_icon_get_icon(image_name, Inkscape::ICON_SIZE_MENU); + Gtk::Image* icon = Gtk::manage(new Gtk::Image()); + icon->set_from_icon_name(image_name, Gtk::ICON_SIZE_MENU); if (icon) { // check icon type (inkscape, gtk, none) - if ( SP_IS_ICON(icon->gobj()) ) { - SPIcon* sp_icon = SP_ICON(icon->gobj()); - sp_icon_fetch_pixbuf(sp_icon); - _property_icon = Glib::wrap(sp_icon->pb, true); - } else if ( GTK_IS_IMAGE(icon->gobj()) ) { + if ( GTK_IS_IMAGE(icon->gobj()) ) { auto icon_theme = Gtk::IconTheme::get_default(); _property_icon = icon_theme->load_icon(image_name, 16); } else { diff --git a/src/ui/dialog/undo-history.h b/src/ui/dialog/undo-history.h index 48929a0d0..3efc25f15 100644 --- a/src/ui/dialog/undo-history.h +++ b/src/ui/dialog/undo-history.h @@ -24,7 +24,6 @@ #include "event-log.h" -#include "widgets/icon.h" #include "ui/dialog/desktop-tracker.h" class SPDesktop; diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index fa35b092a..d9ea73673 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -17,7 +17,6 @@ */ #include "xml-tree.h" -#include "widgets/icon.h" #include <glibmm/i18n.h> #include "desktop.h" @@ -109,57 +108,74 @@ XmlTree::XmlTree (void) : gtk_widget_set_tooltip_text( GTK_WIDGET(tree), _("Drag to reorder nodes") ); tree_toolbar.set_toolbar_style(Gtk::TOOLBAR_ICONS); - xml_element_new_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("xml-element-new")))) ); + + auto xml_element_new_icon = Gtk::manage(new Gtk::Image()); + xml_element_new_icon->set_from_icon_name("xml-element-new", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + xml_element_new_button.set_icon_widget(*xml_element_new_icon); xml_element_new_button.set_tooltip_text(_("New element node")); xml_element_new_button.set_sensitive(false); tree_toolbar.add(xml_element_new_button); - xml_text_new_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("xml-text-new"))))); + auto xml_text_new_icon = Gtk::manage(new Gtk::Image()); + xml_text_new_icon->set_from_icon_name("xml-text-new", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + xml_text_new_button.set_icon_widget(*xml_text_new_icon); xml_text_new_button.set_tooltip_text(_("New text node")); xml_text_new_button.set_sensitive(false); tree_toolbar.add(xml_text_new_button); - xml_node_duplicate_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("xml-node-duplicate"))))); + auto xml_node_duplicate_icon = Gtk::manage(new Gtk::Image()); + xml_node_duplicate_icon->set_from_icon_name("xml-node-duplicate", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + xml_node_duplicate_button.set_icon_widget(*xml_node_duplicate_icon); xml_node_duplicate_button.set_tooltip_text(_("Duplicate node")); xml_node_duplicate_button.set_sensitive(false); tree_toolbar.add(xml_node_duplicate_button); tree_toolbar.add(separator); - xml_node_delete_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("xml-node-delete"))))); + auto xml_node_delete_icon = Gtk::manage(new Gtk::Image()); + xml_node_delete_icon->set_from_icon_name("xml-node-delete", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + xml_node_delete_button.set_icon_widget(*xml_node_delete_icon); xml_node_delete_button.set_tooltip_text(Q_("nodeAsInXMLdialogTooltip|Delete node")); xml_node_delete_button.set_sensitive(false); tree_toolbar.add(xml_node_delete_button); tree_toolbar.add(separator2); - unindent_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("format-indent-less"))))); + auto format_indent_less_icon = Gtk::manage(new Gtk::Image()); + format_indent_less_icon->set_from_icon_name("format-indent-less", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + unindent_node_button.set_icon_widget(*format_indent_less_icon); unindent_node_button.set_label(_("Unindent node")); unindent_node_button.set_tooltip_text(_("Unindent node")); unindent_node_button.set_sensitive(false); tree_toolbar.add(unindent_node_button); - indent_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("format-indent-more"))))); + auto format_indent_more_icon = Gtk::manage(new Gtk::Image()); + format_indent_more_icon->set_from_icon_name("format-indent-more", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + indent_node_button.set_icon_widget(*format_indent_more_icon); indent_node_button.set_label(_("Indent node")); indent_node_button.set_tooltip_text(_("Indent node")); indent_node_button.set_sensitive(false); tree_toolbar.add(indent_node_button); - raise_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("go-up"))))); + auto go_up_icon = Gtk::manage(new Gtk::Image()); + go_up_icon->set_from_icon_name("go-up", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + raise_node_button.set_icon_widget(*go_up_icon); raise_node_button.set_label(_("Raise node")); raise_node_button.set_tooltip_text(_("Raise node")); raise_node_button.set_sensitive(false); tree_toolbar.add(raise_node_button); - lower_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( - sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("go-down"))))); + auto go_down_icon = Gtk::manage(new Gtk::Image()); + go_down_icon->set_from_icon_name("go-down", Gtk::ICON_SIZE_LARGE_TOOLBAR); + + lower_node_button.set_icon_widget(*go_down_icon); lower_node_button.set_label(_("Lower node")); lower_node_button.set_tooltip_text(_("Lower node")); lower_node_button.set_sensitive(false); @@ -183,7 +199,10 @@ XmlTree::XmlTree (void) : attributes = SP_XMLVIEW_ATTR_LIST(sp_xmlview_attr_list_new(NULL)); attr_toolbar.set_toolbar_style(Gtk::TOOLBAR_ICONS); - xml_attribute_delete_button.set_icon_widget(*Gtk::manage(Glib::wrap(sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("xml-attribute-delete"))))); + + auto xml_attribute_delete_icon = Gtk::manage(new Gtk::Image()); + xml_attribute_delete_icon->set_from_icon_name("xml-attribute-delete", Gtk::ICON_SIZE_LARGE_TOOLBAR); + xml_attribute_delete_button.set_icon_widget(*xml_attribute_delete_icon); xml_attribute_delete_button.set_tooltip_text(_("Delete attribute")); xml_attribute_delete_button.set_sensitive(false); attr_toolbar.add(xml_attribute_delete_button); diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 9abc1f07b..4246ae34e 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -27,8 +27,6 @@ #include <gtkmm/icontheme.h> #include "file.h" #include <glibmm/miscutils.h> -#include <gtkmm/imagemenuitem.h> -#include <gtkmm/separatormenuitem.h> #if WITH_GTKMM_3_22 # include <gdkmm/monitor.h> @@ -38,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" @@ -406,23 +403,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,38 +432,82 @@ 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) { - 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 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); + // 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); + + // 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(); + 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); + + 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(show_icon && action->image) { + icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU); + } + else { + 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); + action->signal_set_sensitive.connect( sigc::bind<0>( @@ -498,9 +522,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 +529,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; @@ -823,11 +844,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); @@ -843,7 +872,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 { @@ -1399,8 +1428,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... @@ -1434,859 +1468,6 @@ void injectRenamedIcons() } } - -ContextMenu::ContextMenu(SPDesktop *desktop, SPItem *item) : - _item(item), - MIGroup(), - MIParent(_("Go to parent")) -{ -// g_message("ContextMenu"); - _object = static_cast<SPObject *>(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<std::vector< SPItem * > >(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<std::vector< SPItem * > >(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. <g id="#g7">, 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<SPObject *>(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<SPItem *> 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<SPItem *> items) -{ - _desktop->selection->clear(); - for(auto i=items.begin();i!=items.end(); ++i) { - if ((*i)->isHidden()) { - (*i)->setHidden(false); - _desktop->selection->add(*i); - } - } -} - -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; - } - - Gtk::ImageMenuItem *item = Gtk::manage(new Gtk::ImageMenuItem(action->name, true)); - - 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); - } - - 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(); - 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<SPItem*> children; - - sp_item_group_ungroup(static_cast<SPGroup*>(_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<SPItem*> children; - sp_item_group_ungroup(static_cast<SPAnchor*>(_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++ diff --git a/src/ui/interface.h b/src/ui/interface.h index a41c36cc3..6e95c161c 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -17,23 +17,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -//#ifdef HAVE_CONFIG_H -//# include <config.h> -//#endif +#include <glibmm/ustring.h> -#include <gtkmm/menu.h> - -class SPItem; -class SPObject; -class SPDesktop; class SPViewWidget; -namespace Gtk { -class SeparatorMenuItem; -} +typedef struct _GtkWidget GtkWidget; namespace Inkscape { - class Verb; namespace UI { @@ -93,181 +83,6 @@ Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view ); void sp_ui_error_dialog (char const* message); bool sp_ui_overwrite_file (char const* filename); - -/** - * Implements the Inkscape context menu. - * - * For the context menu implementation, the ContextMenu class stores the object - * that was selected in a private data member. This should be farely safe to do - * and a pointer to the SPItem as well as SPObject class are kept. - * All callbacks of the context menu entries are implemented as private - * functions. - * - * @todo add callbacks to destroy the context menu when it is closed (=key or mouse button pressed out of the scope of the context menu) - */ -class ContextMenu : public Gtk::Menu -{ - public: - /** - * The ContextMenu constructor contains all code to create and show the - * menu entries (aka child widgets). - * - * @param desktop pointer to the desktop the user is currently working on. - * @param item SPItem pointer to the object selected at the time the ContextMenu is created. - */ - ContextMenu(SPDesktop *desktop, SPItem *item); - ~ContextMenu(void); - - private: - SPItem *_item; // pointer to the object selected at the time the ContextMenu is created - SPObject *_object; // pointer to the object selected at the time the ContextMenu is created - SPDesktop *_desktop; //pointer to the desktop the user was currently working on at the time the ContextMenu is created - - int positionOfLastDialog; - - Gtk::MenuItem MIGroup; //menu entry to enter a group - Gtk::MenuItem MIParent; //menu entry to leave a group - - /** - * auxiliary function that adds a separator line in the context menu - */ - Gtk::SeparatorMenuItem* AddSeparator(void); - - /** - * c++ified version of sp_ui_menu_append_item. - * - * @see sp_ui_menu_append_item_from_verb and synchronize/drop that function when c++ifying other code in interface.cpp - */ - void AppendItemFromVerb(Inkscape::Verb *verb); - - /** - * main function which is responsible for creating the context sensitive menu items, - * calls subfunctions below to create the menu entry widgets. - */ - void MakeObjectMenu (void); - /** - * creates menu entries for an SP_TYPE_ITEM object - */ - void MakeItemMenu (void); - /** - * creates menu entries for a grouped object - */ - void MakeGroupMenu (void); - /** - * creates menu entries for an anchor object - */ - void MakeAnchorMenu (void); - /** - * creates menu entries for a bitmap image object - */ - void MakeImageMenu (void); - /** - * creates menu entries for a shape object - */ - void MakeShapeMenu (void); - /** - * creates menu entries for a text object - */ - void MakeTextMenu (void); - - void EnterGroup(Gtk::MenuItem* mi); - void LeaveGroup(void); - void LockSelected(void); - void HideSelected(void); - void UnLockBelow(std::vector<SPItem *> items); - void UnHideBelow(std::vector<SPItem *> items); - ////////////////////////////////////////// - //callbacks for the context menu entries of an SP_TYPE_ITEM object - void ItemProperties(void); - void ItemSelectThis(void); - void ItemMoveTo(void); - void SelectSameFillStroke(void); - void SelectSameFillColor(void); - void SelectSameStrokeColor(void); - void SelectSameStrokeStyle(void); - void SelectSameObjectType(void); - void ItemCreateLink(void); - void CreateGroupClip(void); - void SetMask(void); - void ReleaseMask(void); - void SetClip(void); - void ReleaseClip(void); - ////////////////////////////////////////// - - - /** - * callback, is executed on clicking the anchor "Group" and "Ungroup" menu entry - */ - void ActivateUngroupPopSelection(void); - void ActivateUngroup(void); - void ActivateGroup(void); - - void AnchorLinkProperties(void); - /** - * placeholder for callback to be executed on clicking the anchor "Follow link" context menu entry - * @todo add code to follow link externally - */ - void AnchorLinkFollow(void); - - /** - * callback, is executed on clicking the anchor "Link remove" menu entry - */ - void AnchorLinkRemove(void); - - - /** - * callback, opens the image properties dialog and is executed on clicking the context menu entry with similar name - */ - void ImageProperties(void); - - /** - * callback, is executed on clicking the image "Edit Externally" menu entry - */ - void ImageEdit(void); - - /** - * auxiliary function that loads the external image editor name from the settings. - */ - Glib::ustring getImageEditorName(); - - /** - * callback, is executed on clicking the "Embed Image" menu entry - */ - void ImageEmbed(void); - - /** - * callback, is executed on clicking the "Trace Bitmap" menu entry - */ - void ImageTraceBitmap(void); - - /** - * callback, is executed on clicking the "Trace Pixel Art" menu entry - */ - void ImageTracePixelArt(void); - - /** - * callback, is executed on clicking the "Extract Image" menu entry - */ - void ImageExtract(void); - - - /** - * callback, is executed on clicking the "Fill and Stroke" menu entry - */ - void FillSettings(void); - - - /** - * callback, is executed on clicking the "Text and Font" menu entry - */ - void TextSettings(void); - - /** - * callback, is executed on clicking the "Check spelling" menu entry - */ - void SpellcheckSettings(void); -}; - #endif // SEEN_SP_INTERFACE_H /* diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 3d755eadc..9231db7c8 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -23,6 +23,7 @@ #include "shortcuts.h" #include "file.h" +#include "ui/contextmenu.h" #include "ui/interface.h" #include "ui/event-debug.h" #include "ui/tool/control-point.h" diff --git a/src/ui/widget/addtoicon.cpp b/src/ui/widget/addtoicon.cpp index 70516ed00..e5119fc60 100644 --- a/src/ui/widget/addtoicon.cpp +++ b/src/ui/widget/addtoicon.cpp @@ -16,7 +16,6 @@ #include <gtkmm/icontheme.h> -#include "widgets/icon.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" #include "layertypeicon.h" @@ -33,7 +32,10 @@ AddToIcon::AddToIcon() : // _property_pixbuf_add(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)) { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; - phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_BUTTON); + + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &width, &height); + phys = width; // Assumes that we have a square icon? // Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); // @@ -43,8 +45,6 @@ AddToIcon::AddToIcon() : // if (icon_theme->has_icon(_pixAddName)) { // _property_pixbuf_add = icon_theme->load_icon(_pixAddName, phys, (Gtk::IconLookupFlags)0); // } -// -// _property_pixbuf_add = Gtk::Widget:: set_pixbuf(); } @@ -104,8 +104,10 @@ void AddToIcon::set_pixbuf() { bool active = property_active().get_value(); - GdkPixbuf *pixbuf = sp_pixbuf_new(Inkscape::ICON_SIZE_BUTTON, active ? INKSCAPE_ICON("list-add") : INKSCAPE_ICON("edit-delete")); - property_pixbuf() = Glib::wrap(pixbuf); + auto icon_theme = Gtk::IconTheme::get_default(); + + property_pixbuf() = icon_theme->load_icon(active ? "list-add" : "edit-delete", + phys); } diff --git a/src/ui/widget/addtoicon.h b/src/ui/widget/addtoicon.h index 3b2228754..93d66c8d5 100644 --- a/src/ui/widget/addtoicon.h +++ b/src/ui/widget/addtoicon.h @@ -54,7 +54,7 @@ protected: private: - int phys; + int phys; ///< Physical size of the icon (px) // Glib::ustring _pixAddName; diff --git a/src/ui/widget/anchor-selector.cpp b/src/ui/widget/anchor-selector.cpp index 087e7375e..ddc25775d 100644 --- a/src/ui/widget/anchor-selector.cpp +++ b/src/ui/widget/anchor-selector.cpp @@ -8,15 +8,17 @@ */ #include "ui/widget/anchor-selector.h" -#include "widgets/icon.h" #include "ui/icon-names.h" +#include <gtkmm/image.h> + namespace Inkscape { namespace UI { namespace Widget { void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) { - Gtk::Widget* buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_SMALL_TOOLBAR)); + Gtk::Image* buttonIcon = Gtk::manage(new Gtk::Image()); + buttonIcon->set_from_icon_name(icon, Gtk::ICON_SIZE_SMALL_TOOLBAR); buttonIcon->show(); button.set_relief(Gtk::RELIEF_NONE); diff --git a/src/ui/widget/clipmaskicon.cpp b/src/ui/widget/clipmaskicon.cpp index a1e3eaf82..c284c035c 100644 --- a/src/ui/widget/clipmaskicon.cpp +++ b/src/ui/widget/clipmaskicon.cpp @@ -15,7 +15,6 @@ #include <gtkmm/icontheme.h> -#include "widgets/icon.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" #include "layertypeicon.h" @@ -37,18 +36,12 @@ ClipMaskIcon::ClipMaskIcon() : { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; - phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION); - Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); - if (!icon_theme->has_icon(_pixClipName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixClipName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (!icon_theme->has_icon(_pixMaskName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixMaskName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (!icon_theme->has_icon(_pixBothName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixBothName.data()), Inkscape::ICON_SIZE_DECORATION ); - } + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + phys = width; + + Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); if (icon_theme->has_icon(_pixClipName)) { _property_pixbuf_clip = icon_theme->load_icon(_pixClipName, phys, (Gtk::IconLookupFlags)0); diff --git a/src/ui/widget/color-notebook.cpp b/src/ui/widget/color-notebook.cpp index 33e22b59d..0c9402c99 100644 --- a/src/ui/widget/color-notebook.cpp +++ b/src/ui/widget/color-notebook.cpp @@ -19,7 +19,6 @@ #include "config.h" #endif -#include "widgets/icon.h" #include <glibmm/i18n.h> #include <gtkmm/label.h> #include <gtkmm/notebook.h> diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp index d124854ae..d268be785 100644 --- a/src/ui/widget/dock-item.cpp +++ b/src/ui/widget/dock-item.cpp @@ -12,7 +12,6 @@ #include "desktop.h" #include "inkscape.h" #include "ui/icon-names.h" -#include "widgets/icon.h" #include <gtkmm/icontheme.h> #include <glibmm/exceptionhandler.h> @@ -43,9 +42,6 @@ DockItem::DockItem(Dock& dock, const Glib::ustring& name, const Glib::ustring& l if (!icon_name.empty()) { Glib::RefPtr<Gtk::IconTheme> iconTheme = Gtk::IconTheme::get_default(); - if (!iconTheme->has_icon(icon_name)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(icon_name.data()), Inkscape::ICON_SIZE_MENU ); - } if ( iconTheme->has_icon(icon_name) ) { int width = 0; int height = 0; diff --git a/src/ui/widget/highlight-picker.cpp b/src/ui/widget/highlight-picker.cpp index 561c1332a..3d8ab50ea 100644 --- a/src/ui/widget/highlight-picker.cpp +++ b/src/ui/widget/highlight-picker.cpp @@ -13,7 +13,6 @@ #include "display/cairo-utils.h" #include "highlight-picker.h" -#include "widgets/icon.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/imagetoggler.cpp b/src/ui/widget/imagetoggler.cpp index 987cc67bb..81d0edd47 100644 --- a/src/ui/widget/imagetoggler.cpp +++ b/src/ui/widget/imagetoggler.cpp @@ -13,7 +13,6 @@ #include <gtkmm/icontheme.h> -#include "widgets/icon.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" @@ -32,15 +31,12 @@ ImageToggler::ImageToggler( char const* on, char const* off) : _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0)) { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; - int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION); - Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); - if (!icon_theme->has_icon(_pixOnName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixOnName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (!icon_theme->has_icon(_pixOffName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixOffName.data()), Inkscape::ICON_SIZE_DECORATION ); - } + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + int phys = width; + + Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); if (icon_theme->has_icon(_pixOnName)) { diff --git a/src/ui/widget/insertordericon.cpp b/src/ui/widget/insertordericon.cpp index 7ed1ed2e2..26913ff98 100644 --- a/src/ui/widget/insertordericon.cpp +++ b/src/ui/widget/insertordericon.cpp @@ -11,7 +11,6 @@ #include <gtkmm/icontheme.h> -#include "widgets/icon.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" #include "layertypeicon.h" @@ -31,15 +30,12 @@ InsertOrderIcon::InsertOrderIcon() : { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; - phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION); - Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); - if (!icon_theme->has_icon(_pixTopName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixTopName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (!icon_theme->has_icon(_pixBottomName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixBottomName.data()), Inkscape::ICON_SIZE_DECORATION ); - } + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + phys=width; + + Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); if (icon_theme->has_icon(_pixTopName)) { _property_pixbuf_top = icon_theme->load_icon(_pixTopName, phys, (Gtk::IconLookupFlags)0); diff --git a/src/ui/widget/labelled.cpp b/src/ui/widget/labelled.cpp index 6e3652830..d3dc6210f 100644 --- a/src/ui/widget/labelled.cpp +++ b/src/ui/widget/labelled.cpp @@ -14,8 +14,7 @@ #include "labelled.h" -/* For getting the Gtkmmified Icon manager */ -#include "widgets/icon.h" +#include <gtkmm/image.h> #include <gtkmm/label.h> namespace Inkscape { @@ -33,8 +32,9 @@ Labelled::Labelled(Glib::ustring const &label, Glib::ustring const &tooltip, { g_assert(g_utf8_validate(icon.c_str(), -1, NULL)); if (icon != "") { - _icon = sp_icon_get_icon(icon.c_str(), Inkscape::ICON_SIZE_LARGE_TOOLBAR); - pack_start(*Gtk::manage(_icon), Gtk::PACK_SHRINK); + _icon = Gtk::manage(new Gtk::Image()); + _icon->set_from_icon_name(icon, Gtk::ICON_SIZE_LARGE_TOOLBAR); + pack_start(*_icon, Gtk::PACK_SHRINK); } pack_start(*Gtk::manage(_label), Gtk::PACK_EXPAND_WIDGET, 6); pack_start(*Gtk::manage(_widget), Gtk::PACK_SHRINK, 6); diff --git a/src/ui/widget/labelled.h b/src/ui/widget/labelled.h index 88eb3ce19..824abf305 100644 --- a/src/ui/widget/labelled.h +++ b/src/ui/widget/labelled.h @@ -14,6 +14,7 @@ #include <gtkmm/box.h> namespace Gtk { +class Image; class Label; } @@ -64,7 +65,7 @@ protected: Gtk::Widget *_widget; Gtk::Label *_label; Gtk::Label *_suffix; - Gtk::Widget *_icon; + Gtk::Image *_icon; }; } // namespace Widget diff --git a/src/ui/widget/layer-selector.cpp b/src/ui/widget/layer-selector.cpp index 4432a6e09..0332143b5 100644 --- a/src/ui/widget/layer-selector.cpp +++ b/src/ui/widget/layer-selector.cpp @@ -31,7 +31,6 @@ #include "util/filter-list.h" #include "util/reverse-list.h" #include "verbs.h" -#include "widgets/icon.h" #include "xml/node-event-vector.h" #include "widgets/gradient-vector.h" @@ -42,17 +41,19 @@ namespace { class AlternateIcons : public Gtk::HBox { public: - AlternateIcons(Inkscape::IconSize size, gchar const *a, gchar const *b) + AlternateIcons(Gtk::IconSize size, Glib::ustring const &a, Glib::ustring const &b) : _a(NULL), _b(NULL) { set_name("AlternateIcons"); - if (a) { - _a = Gtk::manage(sp_icon_get_icon(a, size)); + if (!a.empty()) { + _a = Gtk::manage(new Gtk::Image()); + _a->set_from_icon_name(a, size); _a->set_no_show_all(true); add(*_a); } - if (b) { - _b = Gtk::manage(sp_icon_get_icon(b, size)); + if (!b.empty()) { + _b = Gtk::manage(new Gtk::Image()); + _b->set_from_icon_name(b, size); _b->set_no_show_all(true); add(*_b); } @@ -80,8 +81,8 @@ public: } private: - Gtk::Widget *_a; - Gtk::Widget *_b; + Gtk::Image *_a; + Gtk::Image *_b; bool _state; }; @@ -98,7 +99,7 @@ LayerSelector::LayerSelector(SPDesktop *desktop) set_name("LayerSelector"); AlternateIcons *label; - label = Gtk::manage(new AlternateIcons(Inkscape::ICON_SIZE_DECORATION, + label = Gtk::manage(new AlternateIcons(Gtk::ICON_SIZE_MENU, INKSCAPE_ICON("object-visible"), INKSCAPE_ICON("object-hidden"))); _visibility_toggle.add(*label); _visibility_toggle.signal_toggled().connect( @@ -118,7 +119,7 @@ LayerSelector::LayerSelector(SPDesktop *desktop) _visibility_toggle.set_tooltip_text(_("Toggle current layer visibility")); pack_start(_visibility_toggle, Gtk::PACK_EXPAND_PADDING); - label = Gtk::manage(new AlternateIcons(Inkscape::ICON_SIZE_DECORATION, + label = Gtk::manage(new AlternateIcons(Gtk::ICON_SIZE_MENU, INKSCAPE_ICON("object-unlocked"), INKSCAPE_ICON("object-locked"))); _lock_toggle.add(*label); _lock_toggle.signal_toggled().connect( diff --git a/src/ui/widget/layertypeicon.cpp b/src/ui/widget/layertypeicon.cpp index df85f271a..679a95cd2 100644 --- a/src/ui/widget/layertypeicon.cpp +++ b/src/ui/widget/layertypeicon.cpp @@ -15,7 +15,6 @@ #include <gtkmm/icontheme.h> -#include "widgets/icon.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" @@ -37,19 +36,11 @@ LayerTypeIcon::LayerTypeIcon() : { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; - int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION); + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + int phys = width; Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); - if (!icon_theme->has_icon(_pixLayerName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixLayerName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (!icon_theme->has_icon(_pixGroupName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixGroupName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (!icon_theme->has_icon(_pixPathName)) { - Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixPathName.data()), Inkscape::ICON_SIZE_DECORATION ); - } - if (icon_theme->has_icon(_pixLayerName)) { _property_pixbuf_layer = icon_theme->load_icon(_pixLayerName, phys, (Gtk::IconLookupFlags)0); } diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index 1727660c8..ca33a845c 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -24,7 +24,6 @@ #include "style.h" #include "svg/css-ostringstream.h" #include "verbs.h" -#include "widgets/icon.h" #include "display/sp-canvas.h" #include "ui/widget/style-subject.h" diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index dff92594b..9332fe0f9 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -46,7 +46,7 @@ static const int PANEL_SETTING_NEXTFREE = 5; void Panel::prep() { GtkIconSize sizes[] = { - Inkscape::getRegisteredIconSize(Inkscape::ICON_SIZE_DECORATION), + GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR, GTK_ICON_SIZE_BUTTON, @@ -270,7 +270,7 @@ void Panel::_init() gint height = 0; gtk_image_set_from_icon_name(_temp_arrow.gobj(), "pan-start-symbolic", - Inkscape::getRegisteredIconSize(Inkscape::ICON_SIZE_SMALL_TOOLBAR)); + GTK_ICON_SIZE_SMALL_TOOLBAR); _menu_popper.add(_temp_arrow); _menu_popper.signal_button_press_event().connect_notify(sigc::mem_fun(*this, &Panel::_popper)); } diff --git a/src/ui/widget/random.cpp b/src/ui/widget/random.cpp index ba3b025ba..237144c7c 100644 --- a/src/ui/widget/random.cpp +++ b/src/ui/widget/random.cpp @@ -15,11 +15,11 @@ #include "random.h" -#include "widgets/icon.h" #include <glibmm/i18n.h> #include <gtkmm/button.h> +#include <gtkmm/image.h> namespace Inkscape { namespace UI { @@ -70,7 +70,8 @@ void Random::setStartSeed(long newseed) void Random::addReseedButton() { - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "randomize", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Image* pIcon = Gtk::manage(new Gtk::Image()); + pIcon->set_from_icon_name( "randomize", Gtk::ICON_SIZE_BUTTON); Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); |
