1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-08-04 23:11:50 +00:00
|
|
|
/**
|
|
|
|
* \file lyxcursor.h
|
|
|
|
* Copyright 1995-2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-08-04 23:11:50 +00:00
|
|
|
* \author Matthias Ettrich
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#ifndef LYXCURSOR_H
|
|
|
|
#define LYXCURSOR_H
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
#include "support/types.h"
|
1999-11-04 01:40:20 +00:00
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
class Paragraph;
|
|
|
|
class Row;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
/**
|
2002-08-04 23:11:50 +00:00
|
|
|
* The cursor class describes the position of a cursor within a document.
|
|
|
|
* Several cursors exist within LyX; for example, when locking an inset,
|
|
|
|
* the position of the cursor in the containing inset is stored.
|
|
|
|
*
|
|
|
|
* FIXME: true ?
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
2000-06-08 23:16:16 +00:00
|
|
|
class LyXCursor {
|
|
|
|
public:
|
2001-01-08 14:19:29 +00:00
|
|
|
LyXCursor();
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the paragraph that contains this cursor
|
2001-06-25 00:06:33 +00:00
|
|
|
void par(Paragraph * p);
|
2002-08-04 23:11:50 +00:00
|
|
|
/// return the paragraph this cursor is in
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * par() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the position within the paragraph
|
2001-11-27 10:34:16 +00:00
|
|
|
void pos(lyx::pos_type p);
|
2002-08-04 23:11:50 +00:00
|
|
|
/// return the position within the paragraph
|
2001-11-27 10:34:16 +00:00
|
|
|
lyx::pos_type pos() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// FIXME
|
2000-06-08 23:16:16 +00:00
|
|
|
void boundary(bool b);
|
2002-08-04 23:11:50 +00:00
|
|
|
/// FIXME
|
2000-06-08 23:16:16 +00:00
|
|
|
bool boundary() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the x position in pixels
|
2000-06-08 23:16:16 +00:00
|
|
|
void x(int i);
|
2002-08-04 23:11:50 +00:00
|
|
|
/// return the x position in pixels
|
2000-06-08 23:16:16 +00:00
|
|
|
int x() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the stored next-line position when at the end of a row
|
2002-04-12 15:59:03 +00:00
|
|
|
void ix(int i);
|
2002-08-04 23:11:50 +00:00
|
|
|
/**
|
|
|
|
* Return the x position of the start of the next row, when this
|
|
|
|
* cursor is at the end of the previous row, for insets that take
|
|
|
|
* a full row.
|
|
|
|
*
|
|
|
|
* FIXME: explain why we need this ?
|
|
|
|
*/
|
2002-04-12 15:59:03 +00:00
|
|
|
int ix() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the cached x position
|
2000-06-08 23:16:16 +00:00
|
|
|
void x_fix(int i);
|
2002-08-04 23:11:50 +00:00
|
|
|
/**
|
|
|
|
* Return the cached x position of the cursor. This is used for when
|
|
|
|
* we have text like :
|
|
|
|
*
|
|
|
|
* blah blah blah blah| blah blah blah
|
|
|
|
* blah blah blah
|
|
|
|
* blah blah blah blah blah blah
|
|
|
|
*
|
|
|
|
* When we move onto row 3, we would like to be vertically aligned
|
2002-11-27 10:30:28 +00:00
|
|
|
* with where we were in row 1, despite the fact that row 2 is
|
2002-08-04 23:11:50 +00:00
|
|
|
* shorter than x()
|
|
|
|
*/
|
2000-06-08 23:16:16 +00:00
|
|
|
int x_fix() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the y position in pixels
|
2000-09-29 18:44:07 +00:00
|
|
|
void y(int i);
|
2002-08-04 23:11:50 +00:00
|
|
|
/// return the y position in pixels
|
2000-09-29 18:44:07 +00:00
|
|
|
int y() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the stored next-line y position when at the end of a row
|
2002-04-11 09:53:23 +00:00
|
|
|
void iy(int i);
|
2002-08-04 23:11:50 +00:00
|
|
|
/**
|
|
|
|
* Return the y position of the start of the next row, when this
|
|
|
|
* cursor is at the end of the previous row, for insets that take
|
|
|
|
* a full row.
|
|
|
|
*
|
|
|
|
* FIXME: explain why we need this ? especially for y...
|
|
|
|
*/
|
2002-04-11 09:53:23 +00:00
|
|
|
int iy() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the row of the paragraph the cursor is in
|
2000-06-08 23:16:16 +00:00
|
|
|
void row(Row * r);
|
2002-08-04 23:11:50 +00:00
|
|
|
/// return the row of the paragraph this cursor is in
|
2000-06-08 23:16:16 +00:00
|
|
|
Row * row() const;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// set the stored next row
|
2002-04-16 14:10:39 +00:00
|
|
|
void irow(Row * r);
|
2002-08-04 23:11:50 +00:00
|
|
|
/**
|
|
|
|
* Return the next row, when this
|
|
|
|
* cursor is at the end of the previous row, for insets that take
|
|
|
|
* a full row.
|
|
|
|
*
|
|
|
|
* FIXME: explain why we need this ? especially for y...
|
|
|
|
*/
|
2002-04-16 14:10:39 +00:00
|
|
|
Row * irow() const;
|
2000-06-08 23:16:16 +00:00
|
|
|
private:
|
|
|
|
/// The paragraph the cursor is in.
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * par_;
|
2000-06-08 23:16:16 +00:00
|
|
|
/// The position inside the paragraph
|
2001-11-27 10:34:16 +00:00
|
|
|
lyx::pos_type pos_;
|
2002-09-02 12:10:26 +00:00
|
|
|
/**
|
|
|
|
* When the cursor position is i, is the cursor is after the i-th char
|
|
|
|
* or before the i+1-th char ? Normally, these two interpretations are
|
|
|
|
* equivalent, except when the fonts of the i-th and i+1-th char
|
|
|
|
* differ.
|
|
|
|
* We use boundary_ to distinguish between the two options:
|
|
|
|
* If boundary_=true, then the cursor is after the i-th char
|
|
|
|
* and if boundary_=false, then the cursor is before the i+1-th char.
|
|
|
|
*
|
|
|
|
* We currently use the boundary only when the language direction of
|
|
|
|
* the i-th char is different than the one of the i+1-th char.
|
|
|
|
* In this case it is important to distinguish between the two
|
|
|
|
* cursor interpretations, in order to give a reasonable behavior to
|
|
|
|
* the user.
|
|
|
|
*/
|
2000-06-08 23:16:16 +00:00
|
|
|
bool boundary_;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// the pixel x position
|
2000-06-08 23:16:16 +00:00
|
|
|
int x_;
|
2002-11-27 10:30:28 +00:00
|
|
|
/// the stored next-row x position
|
2002-04-12 15:59:03 +00:00
|
|
|
int ix_;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// the cached x position
|
2000-06-08 23:16:16 +00:00
|
|
|
int x_fix_;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// the pixel y position
|
2000-09-29 18:44:07 +00:00
|
|
|
int y_;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// the stored next-row y position
|
2002-04-11 09:53:23 +00:00
|
|
|
int iy_;
|
2002-08-04 23:11:50 +00:00
|
|
|
/// the containing row
|
2000-06-08 23:16:16 +00:00
|
|
|
Row * row_;
|
2002-11-27 10:30:28 +00:00
|
|
|
/// the containing row for the next line
|
2002-04-16 14:10:39 +00:00
|
|
|
Row * irow_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
/// these three dictate the others
|
2000-06-08 23:16:16 +00:00
|
|
|
inline
|
|
|
|
bool operator==(LyXCursor const & a, LyXCursor const & b)
|
|
|
|
{
|
|
|
|
return (a.par() == b.par())
|
|
|
|
&& (a.pos() == b.pos())
|
|
|
|
&& a.boundary() == b.boundary();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool operator!=(LyXCursor const & a, LyXCursor const & b)
|
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
/// only compares y() and pos(). Can this be done in another way?
|
2001-06-27 18:29:18 +00:00
|
|
|
inline
|
2002-03-21 17:27:08 +00:00
|
|
|
bool operator<(LyXCursor const & a, LyXCursor const & b)
|
2001-06-27 18:29:18 +00:00
|
|
|
{
|
|
|
|
return (a.y() < b.y() && a.pos() < b.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2002-03-21 17:27:08 +00:00
|
|
|
bool operator>(LyXCursor const & a, LyXCursor const & b)
|
2001-06-27 18:29:18 +00:00
|
|
|
{
|
|
|
|
return b < a;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool operator>=(LyXCursor const & a, LyXCursor const & b)
|
|
|
|
{
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool operator<=(LyXCursor const & a, LyXCursor const & b)
|
|
|
|
{
|
|
|
|
return !(a > b);
|
|
|
|
}
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
#endif // LYXCURSOR_H
|