On 08/01/2013 02:00 PM, Hashini Senaratne wrote:
Hello Jean-Marc,

+++ b/src/Cursor.cpp
  <at>  <at>  -278,7 +278,7  <at>  <at>  CursorData::CursorData(DocIterator
const & dit)
   // bv functions are not yet available!
   Cursor::Cursor(BufferView & bv)
          : CursorData(&bv.buffer()), bv_(&bv),
-         x_target_(-1), textTargetOffset_(0)
+         x_target_(-1), textTargetOffset_(0),left_edge_(0)
   {}

Didn't you forget too_wide_row_?

  <at>  <at>  -538,7 +538,33  <at>  <at>  Row const & Cursor::textRow() const
   {
          CursorSlice const & cs = innerTextSlice();
          ParagraphMetrics const & pm = bv().parMetrics(cs.text(), cs.pit());
-       return pm.getRow(pos(), boundary());
+       bool const bndry = inTexted() ? boundary() : false;
+       return pm.getRow(cs.pos(), bndry);
+}
+
+int Cursor::getLeftEdge() const
+{
+       return left_edge_;
+}
+
+Row const & Cursor::getToowideRow()
+{
+       return *too_wide_row_;
+}

As I already said, I think this name is not good. I would propose
current_row_ or current_bottpm_row_. THe question is not to know whether
the row is to wide, but what is the row to which the value of left_edge
makes reference.
What I thought from the beginning is to save the finally found actual too
wide row to this variable. So until we find a too wide row, we cannot save
something to this. That is why I have not initialized too_wide_row in the
constructor of Cursor. So in that case we have to identify a wide row in
TextMetrics.cpp and save the value from there.

That is what I have tried in this commit:
http://git.lyx.org/?p=gsoc.git;a=commitdiff;h=5ac5e4cd540eb3b9ca9e06dd14aef63d4361b37a
But unexpectedly it stops by giving a runtime error at a point we need to
slide a row. After some debugging I hope the error is within setToowideRow()
method.

Yes, I think it is. You have:

+void Cursor::setToowideRow(Row const & wideRow) const
 {
        *too_wide_row_ = wideRow;
 }

What this says is: Find what too_wide_row_ points at, and save wideRow there. If too_wide_row_ is not initialized properly, or is 0, then this will crash. What you want is:

    too_wide_row_ = &wideRow;

That saves the address of wideRow to too_wide_row_, which is a pointer to a Row.

An alternative would be to save some other sort of identifier of the Row. Do they have indices or something?


+
+void Cursor::setLeftEdge(int leftEdge)
+{
+       left_edge_ = leftEdge;
+}
+
+void Cursor::setLeftEdge(int leftEdge) const
+{
+       const_cast<Cursor *>(this)->setLeftEdge(leftEdge);
+}

When you have to do something like this, then something is usually
wrong. I think it would be better to make a cast the cursor to an
unconstified version in drawParagraphs that to create const methods that
are not const. This is just cheating.
Yes, I will try that too.

You could also try making setLeftEdge non-const, or making whatever it's saving mutable.

Richard

Reply via email to