]> git.lyx.org Git - lyx.git/blobdiff - src/bufferview_funcs.cpp
cosmetics
[lyx.git] / src / bufferview_funcs.cpp
index d91ce6c5e720e9530a5830f2b24c232177acf42b..3a3a45c8aabdb032d8bfb6b3a872022a61d6e42b 100644 (file)
@@ -147,200 +147,6 @@ bool string2font(string const & data, Font & font, bool & toggle)
 }
 
 
-// the next two should probably go elsewhere
-// this give the position relative to (0, baseline) of outermost
-// paragraph
-Point coordOffset(BufferView const & bv, DocIterator const & dit,
-               bool boundary)
-{
-       int x = 0;
-       int y = 0;
-       int lastw = 0;
-
-       // Addup ontribution of nested insets, from inside to outside,
-       // keeping the outer paragraph for a special handling below
-       for (size_t i = dit.depth() - 1; i >= 1; --i) {
-               CursorSlice const & sl = dit[i];
-               int xx = 0;
-               int yy = 0;
-               
-               // get relative position inside sl.inset()
-               sl.inset().cursorPos(bv, sl, boundary && ((i+1) == dit.depth()), xx, yy);
-               
-               // Make relative position inside of the edited inset relative to sl.inset()
-               x += xx;
-               y += yy;
-               
-               // In case of an RTL inset, the edited inset will be positioned to the left
-               // of xx:yy
-               if (sl.text()) {
-                       bool boundary_i = boundary && i + 1 == dit.depth();
-                       bool rtl = bv.textMetrics(sl.text()).isRTL(sl, boundary_i);
-                       if (rtl)
-                               x -= lastw;
-               }
-               
-               // remember width for the case that sl.inset() is positioned in an RTL inset
-               Dimension const dim = sl.inset().dimension(bv);
-               lastw = dim.wid;
-               
-               //lyxerr << "Cursor::getPos, i: "
-               // << i << " x: " << xx << " y: " << y << endl;
-       }
-
-       // Add contribution of initial rows of outermost paragraph
-       CursorSlice const & sl = dit[0];
-       TextMetrics const & tm = bv.textMetrics(sl.text());
-       ParagraphMetrics const & pm = tm.parMetrics(sl.pit());
-       BOOST_ASSERT(!pm.rows().empty());
-       y -= pm.rows()[0].ascent();
-#if 1
-       // FIXME: document this mess
-       size_t rend;
-       if (sl.pos() > 0 && dit.depth() == 1) {
-               int pos = sl.pos();
-               if (pos && boundary)
-                       --pos;
-//             lyxerr << "coordOffset: boundary:" << boundary << " depth:" << dit.depth() << " pos:" << pos << " sl.pos:" << sl.pos() << std::endl;
-               rend = pm.pos2row(pos);
-       } else
-               rend = pm.pos2row(sl.pos());
-#else
-       size_t rend = pm.pos2row(sl.pos());
-#endif
-       for (size_t rit = 0; rit != rend; ++rit)
-               y += pm.rows()[rit].height();
-       y += pm.rows()[rend].ascent();
-       
-       TextMetrics const & bottom_tm = bv.textMetrics(dit.bottom().text());
-       
-       // Make relative position from the nested inset now bufferview absolute.
-       int xx = bottom_tm.cursorX(dit.bottom(), boundary && dit.depth() == 1);
-       x += xx;
-       
-       // In the RTL case place the nested inset at the left of the cursor in 
-       // the outer paragraph
-       bool boundary_1 = boundary && 1 == dit.depth();
-       bool rtl = bottom_tm.isRTL(dit.bottom(), boundary_1);
-       if (rtl)
-               x -= lastw;
-       
-       return Point(x, y);
-}
-
-
-Point getPos(BufferView const & bv, DocIterator const & dit, bool boundary)
-{
-       CursorSlice const & bot = dit.bottom();
-       TextMetrics const & tm = bv.textMetrics(bot.text());
-       if (!tm.has(bot.pit()))
-               return Point(-1, -1);
-
-       Point p = coordOffset(bv, dit, boundary); // offset from outer paragraph
-       p.y_ += tm.parMetrics(bot.pit()).position();
-       return p;
-}
-
-
-// this could be used elsewhere as well?
-// FIXME: This does not work within mathed!
-CurStatus status(BufferView const * bv, DocIterator const & dit)
-{
-       // FIXME: it's be better to have something like TextMetrics::status().
-       TextMetrics const & tm = bv->textMetrics(dit.bottom().text());
-       int par_pos = tm.parPosition(dit.bottom().pit());
-       if (par_pos < 0)
-               return CUR_ABOVE;
-       else if (par_pos > bv->workHeight())
-               return CUR_BELOW;
-               
-       return CUR_INSIDE;
-}
-
-namespace {
-
-bool findNextInset(DocIterator & dit,
-                  vector<Inset_code> const & codes,
-                  string const & contents)
-{
-       DocIterator tmpdit = dit;
-
-       while (tmpdit) {
-               Inset const * inset = tmpdit.nextInset();
-               if (inset
-                   && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
-                   && (contents.empty() ||
-                   static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
-                       dit = tmpdit;
-                       return true;
-               }
-               tmpdit.forwardInset();
-       }
-
-       return false;
-}
-
-} // namespace anon
-
-
-bool findInset(DocIterator & dit, vector<Inset_code> const & codes,
-              bool same_content)
-{
-       string contents;
-       DocIterator tmpdit = dit;
-       tmpdit.forwardInset();
-       if (!tmpdit)
-               return false;
-
-       if (same_content) {
-               Inset const * inset = tmpdit.nextInset();
-               if (inset
-                   && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
-                       contents = static_cast<InsetCommand const *>(inset)->getContents();
-               }
-       }
-
-       if (!findNextInset(tmpdit, codes, contents)) {
-               if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
-                       tmpdit  = doc_iterator_begin(tmpdit.bottom().inset());
-                       if (!findNextInset(tmpdit, codes, contents)) {
-                               return false;
-                       }
-               } else
-                       return false;
-       }
-
-       dit = tmpdit;
-       return true;
-}
-
-
-void findInset(DocIterator & dit, Inset_code code, bool same_content)
-{
-       findInset(dit, vector<Inset_code>(1, code), same_content);
-}
-
-
-void gotoInset(BufferView * bv, vector<Inset_code> const & codes,
-              bool same_content)
-{
-       Cursor tmpcur = bv->cursor();
-       if (!findInset(tmpcur, codes, same_content)) {
-               bv->cursor().message(_("No more insets"));
-               return;
-       }
-
-       tmpcur.clearSelection();
-       bv->setCursor(tmpcur);
-}
-
-
-void gotoInset(BufferView * bv, Inset_code code, bool same_content)
-{
-       gotoInset(bv, vector<Inset_code>(1, code), same_content);
-}
-
-
 } // namespace bv_funcs