23/06/2013 10:36, Hashini Senaratne:
Hello Jean-Marc
I suspect this is not going to work when you want to set cursor by mouse on
a slided row. I think the offset information shall be in bufferview as Richard
said.
I tried it already; but still having some problems. Will continue on working
and report back when I come to a stable point.
Hello Hashini,
I finally managed to checkout your testing repository and give it a try.
Here are a few remarks on where I think we should be going.
--*--
First some explanation about what a Cursor really is. I try to go from
more local to general. Feel free to put this information on the wiki if
you find it useful and to improve it with your own findings.
* a CursorSlice indicates the position of the cursor at local level. It
contains in particular:
* idx(): the cell that contains the cursor (for Tabular or math
arrays). Always 0 for 'plain' insets
* pit(): the index of the current paragraph (only for Texted)
* pos(): the position in the current paragraph (or in the math
equation in Mathed).
* inset(): the inset in which the cursor is.
* a DocIterator indicated the position of the cursor in the document. It
knows about the current buffer (buffer() method) and contains a vector
of CursorSlices that describes the nesting of insets up to the point of
interest. Note that operator<< has been implemented, so that one can
send a DocIterator to a stream to see its value. Try it, it is very
helpful to understand the cursor layout.
* when using idx/pit/pos on a DocIterator, one gets the information
from the inner slice (this slice can be accessed as top())
* inMathed() returns true when the cursor is in a math formula
* inTexted() returns true when the cursor is in text
* innerTextSlice() returns the deepest slice that is text (useful
when one is in a math equation and looks for the enclosing text)
* A CursorData is a descendent of Dociterator that contains
* a second DocIterator object, the anchor, that is useful when
selecting.
* some other data not interesting here
This class is used only for undo and contains the Cursor element that
are not GUI-related. In LyX 2.0, Cursor was directly deriving from
DocIterator
* A Cursor is a descendant of CursorData that contains interesting
display-related information, in particular targetX(), the horizontal
position of the cursor in pixels.
* one interesting method for what you want to do is textRow(), that
returns the inner Row object that contains the cursor
--*--
Now here is a sketch of what you could try to do:
* in Cursor object, add two private members
* current_row_offset_: the value of the offset for the row the cursor
is in. The cursor remembers the offset, which means that, when it goes
out of the right margin the row will slide, but when going back on the
left we could decide not to slide back the row, until it is necessary
because we need to go beyond the left margin. (does this make sense?)
* current_row_: (a pointer to) the row the cursor was in when
applying an offset. If this is not the current row anymore, we shall
reset the offset to 0.
* You could make the members public as a start and later add
accessors and make them private
* then in drawParagraph, use a logic like
* before the main loop, if cursor current_row_ is not equal to
cur.textRow(), reset offset to 0 and current_row_ to new row
* in the loop, when looking at the row that contains the cursor
* if the cursor is visible with current offset, do nothing
* if cursor is not visible (on the left or on the right), adjust
the offset so that cursor is visible
* use the newly computed offset to draw the row.
Does this look like a plan? Please do not hesitate to ask me if some
parts are not clear.
JMarc