diff options
| author | Shlomi Fish <shlomif@shlomifish.org> | 2017-02-23 14:39:39 +0000 |
|---|---|---|
| committer | Shlomi Fish <shlomif@shlomifish.org> | 2017-02-23 14:39:39 +0000 |
| commit | d82d8e6de61b5a3da73af7d7003b8281720c3dc1 (patch) | |
| tree | 50a151920b32f95afd0fa0c04f175322657ebb18 /src/document.cpp | |
| parent | Merged. (diff) | |
| parent | Display style attribute properties when object row selected. Allow their dele... (diff) | |
| download | inkscape-d82d8e6de61b5a3da73af7d7003b8281720c3dc1.tar.gz inkscape-d82d8e6de61b5a3da73af7d7003b8281720c3dc1.zip | |
Merged.
(bzr r15369.1.19)
Diffstat (limited to 'src/document.cpp')
| -rw-r--r-- | src/document.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/document.cpp b/src/document.cpp index b69508751..c7115f906 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -62,6 +62,11 @@ #include "sp-symbol.h" #include "xml/rebase-hrefs.h" +#include "libcroco/cr-sel-eng.h" +#include "libcroco/cr-selector.h" +#include "libcroco/cr-parser.h" +#include "src/xml/croco-node-iface.h" + using Inkscape::DocumentUndo; using Inkscape::Util::unit_table; @@ -1119,6 +1124,50 @@ std::vector<SPObject *> SPDocument::getObjectsByElement(Glib::ustring const &ele return objects; } +void _getObjectsBySelectorRecursive(SPObject *parent, + CRSelEng *sel_eng, CRSimpleSel *simple_sel, + std::vector<SPObject *> &objects) +{ + if (parent) { + gboolean result = false; + cr_sel_eng_matches_node( sel_eng, simple_sel, parent->getRepr(), &result ); + if (result) { + objects.push_back(parent); + } + + // Check children + for (auto& child : parent->children) { + _getObjectsBySelectorRecursive(&child, sel_eng, simple_sel, objects); + } + } +} + +std::vector<SPObject *> SPDocument::getObjectsBySelector(Glib::ustring const &selector) const +{ + // std::cout << "\nSPDocument::getObjectsBySelector: " << selector << std::endl; + + std::vector<SPObject *> objects; + g_return_val_if_fail(!selector.empty(), objects); + + static CRSelEng *sel_eng = NULL; + if (!sel_eng) { + sel_eng = cr_sel_eng_new(); + cr_sel_eng_set_node_iface(sel_eng, &Inkscape::XML::croco_node_iface); + } + + Glib::ustring my_selector = selector + " {"; // Parsing fails sometimes without '{'. Fix me + CRSelector *cr_selector = cr_selector_parse_from_buf ((guchar*)my_selector.c_str(), CR_UTF_8); + // char * cr_string = (char*)cr_selector_to_string( cr_selector ); + // std::cout << " selector: |" << (cr_string?cr_string:"Empty") << "|" << std::endl; + CRSelector const *cur = NULL; + for (cur = cr_selector; cur; cur = cur->next) { + if (cur->simple_sel ) { + _getObjectsBySelectorRecursive(root, sel_eng, cur->simple_sel, objects); + } + } + return objects; +} + void SPDocument::bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object) { if (object) { @@ -1474,7 +1523,9 @@ static SPItem *find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Poin if (SP_IS_GROUP(&o) && SP_GROUP(&o)->effectiveLayerMode(dkey) != SPGroup::LAYER ) { SPItem *child = SP_ITEM(&o); Inkscape::DrawingItem *arenaitem = child->get_arenaitem(dkey); - arenaitem->drawing().update(); + if (arenaitem) { + arenaitem->drawing().update(); + } // seen remembers the last (topmost) of groups pickable at this point if (arenaitem && arenaitem->pick(p, delta, 1) != NULL) { |
