mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 00:10:59 +00:00
globalize the cursor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8339 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d8f81752eb
commit
7cfc5e86a4
@ -260,8 +260,6 @@ lyx_SOURCES = \
|
||||
text.C \
|
||||
text2.C \
|
||||
text3.C \
|
||||
textcursor.C \
|
||||
textcursor.h \
|
||||
toc.C \
|
||||
toc.h \
|
||||
trans.C \
|
||||
|
@ -12,7 +12,6 @@
|
||||
#ifndef CURSOR_H
|
||||
#define CURSOR_H
|
||||
|
||||
#include "textcursor.h"
|
||||
#include "cursor_slice.h"
|
||||
|
||||
#include <iosfwd>
|
||||
@ -30,7 +29,6 @@ class InsetTabular;
|
||||
* The cursor class describes the position of a cursor within a document.
|
||||
*/
|
||||
|
||||
|
||||
class LCursor {
|
||||
public:
|
||||
/// type for cell number in inset
|
||||
|
@ -112,7 +112,7 @@ void CursorSlice::setPos(int pos)
|
||||
|
||||
LyXText * CursorSlice::text() const
|
||||
{
|
||||
return asUpdatableInset()->getText(idx_);
|
||||
return asUpdatableInset() ? asUpdatableInset()->getText(idx_) : 0;
|
||||
}
|
||||
|
||||
|
||||
@ -155,24 +155,15 @@ bool operator>(CursorSlice const & p, CursorSlice const & q)
|
||||
}
|
||||
|
||||
|
||||
//std::ostream & operator<<(std::ostream & os, CursorSlice const & p)
|
||||
//{
|
||||
// os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
|
||||
// return os;
|
||||
//}
|
||||
|
||||
|
||||
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
|
||||
{
|
||||
os << " inset: " << item.inset_
|
||||
// << " text: " << item.text()
|
||||
<< " text: " << item.text()
|
||||
<< " idx: " << item.idx_
|
||||
// << " par: " << item.par_
|
||||
// << " pos: " << item.pos_
|
||||
<< " par: " << item.par_
|
||||
<< " pos: " << item.pos_
|
||||
// << " x: " << item.inset_->x()
|
||||
// << " y: " << item.inset_->y()
|
||||
;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,13 +15,13 @@
|
||||
#define LYXTEXT_H
|
||||
|
||||
#include "bufferview_funcs.h"
|
||||
#include "cursor_slice.h"
|
||||
#include "Bidi.h"
|
||||
#include "layout.h"
|
||||
#include "lyxfont.h"
|
||||
#include "lyxtextclass.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "RowList_fwd.h"
|
||||
#include "textcursor.h"
|
||||
|
||||
#include "insets/inset.h"
|
||||
|
||||
@ -41,17 +41,31 @@ class UpdatableInset;
|
||||
class VSpace;
|
||||
|
||||
|
||||
/**
|
||||
This class used to hold the mapping between buffer paragraphs and
|
||||
screen rows. Nowadays, the Paragraphs take care of their rows
|
||||
themselves and this contains just most of the code for manipulating
|
||||
them and interaction with the Cursor.
|
||||
*/
|
||||
// The structure that keeps track of the selections set.
|
||||
struct Selection {
|
||||
Selection()
|
||||
: set_(false), mark_(false)
|
||||
{}
|
||||
bool set() const {
|
||||
return set_;
|
||||
}
|
||||
void set(bool s) {
|
||||
set_ = s;
|
||||
}
|
||||
bool mark() const {
|
||||
return mark_;
|
||||
}
|
||||
void mark(bool m) {
|
||||
mark_ = m;
|
||||
}
|
||||
private:
|
||||
bool set_; // former selection
|
||||
bool mark_; // former mark_set
|
||||
};
|
||||
|
||||
// The inheritance from TextCursor should go. It's just there to ease
|
||||
// transition...
|
||||
class LyXText : public TextCursor {
|
||||
// Public Functions
|
||||
|
||||
/// This class encapsulates the main text data and operations in LyX
|
||||
class LyXText {
|
||||
public:
|
||||
/// Constructor
|
||||
LyXText(BufferView *, bool ininset);
|
||||
@ -164,11 +178,6 @@ public:
|
||||
lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
|
||||
Row const & row, int & x, bool & boundary) const;
|
||||
|
||||
/// need the selection cursor:
|
||||
void setSelection();
|
||||
///
|
||||
void clearSelection();
|
||||
|
||||
/// select the word we need depending on word_location
|
||||
void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
|
||||
/// just selects the word the cursor is in
|
||||
@ -415,8 +424,38 @@ public:
|
||||
/// access to the selection anchor
|
||||
CursorSlice const & anchor() const;
|
||||
|
||||
///
|
||||
void setSelection();
|
||||
///
|
||||
void clearSelection();
|
||||
///
|
||||
CursorSlice const & selStart() const;
|
||||
///
|
||||
CursorSlice const & selEnd() const;
|
||||
///
|
||||
CursorSlice & selStart();
|
||||
///
|
||||
CursorSlice & selEnd();
|
||||
|
||||
|
||||
public:
|
||||
/** The cursor.
|
||||
Later this variable has to be removed. There should be no internal
|
||||
cursor in a text (and thus not in a buffer). By keeping this it is
|
||||
(I think) impossible to have several views with the same buffer, but
|
||||
the cursor placed at different places.
|
||||
[later]
|
||||
Since the LyXText now has been moved from Buffer to BufferView
|
||||
it should not be absolutely needed to move the cursor...
|
||||
[even later]
|
||||
Nevertheless, it should still be moved, in order to keep classes
|
||||
and interdependencies small.
|
||||
*/
|
||||
// the other end of the selection
|
||||
CursorSlice anchor_;
|
||||
//
|
||||
Selection selection;
|
||||
|
||||
///
|
||||
int height;
|
||||
///
|
||||
|
57
src/text.C
57
src/text.C
@ -21,6 +21,7 @@
|
||||
#include "buffer.h"
|
||||
#include "bufferparams.h"
|
||||
#include "BufferView.h"
|
||||
#include "cursor.h"
|
||||
#include "debug.h"
|
||||
#include "dispatchresult.h"
|
||||
#include "encoding.h"
|
||||
@ -1936,13 +1937,13 @@ int LyXText::cursorY(CursorSlice const & cur) const
|
||||
|
||||
CursorSlice & LyXText::cursor()
|
||||
{
|
||||
return cursor_;
|
||||
return bv()->cursor().top();
|
||||
}
|
||||
|
||||
|
||||
CursorSlice const & LyXText::cursor() const
|
||||
{
|
||||
return cursor_;
|
||||
return bv()->cursor().top();
|
||||
}
|
||||
|
||||
|
||||
@ -1958,3 +1959,55 @@ CursorSlice const & LyXText::anchor() const
|
||||
}
|
||||
|
||||
|
||||
CursorSlice const & LyXText::selStart() const
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor();
|
||||
// can't use std::min as this creates a new object
|
||||
return anchor() < cursor() ? anchor() : cursor();
|
||||
}
|
||||
|
||||
|
||||
CursorSlice const & LyXText::selEnd() const
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor();
|
||||
return anchor() > cursor() ? anchor() : cursor();
|
||||
}
|
||||
|
||||
|
||||
CursorSlice & LyXText::selStart()
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor();
|
||||
return anchor() < cursor() ? anchor() : cursor();
|
||||
}
|
||||
|
||||
|
||||
CursorSlice & LyXText::selEnd()
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor();
|
||||
return anchor() > cursor() ? anchor() : cursor();
|
||||
}
|
||||
|
||||
|
||||
void LyXText::setSelection()
|
||||
{
|
||||
selection.set(true);
|
||||
// a selection with no contents is not a selection
|
||||
if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
|
||||
selection.set(false);
|
||||
}
|
||||
|
||||
|
||||
void LyXText::clearSelection()
|
||||
{
|
||||
selection.set(false);
|
||||
selection.mark(false);
|
||||
anchor() = cursor();
|
||||
// reset this in the bv()!
|
||||
if (bv() && bv()->text())
|
||||
bv()->unsetXSel();
|
||||
}
|
||||
|
||||
|
22
src/text2.C
22
src/text2.C
@ -471,28 +471,8 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
|
||||
}
|
||||
|
||||
|
||||
// important for the screen
|
||||
|
||||
|
||||
// the cursor set functions have a special mechanism. When they
|
||||
// realize, that you left an empty paragraph, they will delete it.
|
||||
|
||||
// need the selection cursor:
|
||||
void LyXText::setSelection()
|
||||
{
|
||||
TextCursor::setSelection();
|
||||
}
|
||||
|
||||
|
||||
void LyXText::clearSelection()
|
||||
{
|
||||
TextCursor::clearSelection();
|
||||
|
||||
// reset this in the bv()!
|
||||
if (bv() && bv()->text())
|
||||
bv()->unsetXSel();
|
||||
}
|
||||
|
||||
// realize you left an empty paragraph, they will delete it.
|
||||
|
||||
void LyXText::cursorHome()
|
||||
{
|
||||
|
@ -1,64 +0,0 @@
|
||||
/**
|
||||
* \file textcursor.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author André Pönitz
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "textcursor.h"
|
||||
|
||||
|
||||
CursorSlice const & TextCursor::selStart() const
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor_;
|
||||
// can't use std::min as this creates a new object
|
||||
return anchor_ < cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
CursorSlice const & TextCursor::selEnd() const
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor_;
|
||||
return anchor_ > cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
CursorSlice & TextCursor::selStart()
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor_;
|
||||
return anchor_ < cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
CursorSlice & TextCursor::selEnd()
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor_;
|
||||
return anchor_ > cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
void TextCursor::setSelection()
|
||||
{
|
||||
selection.set(true);
|
||||
// a selection with no contents is not a selection
|
||||
if (cursor_.par() == anchor_.par() && cursor_.pos() == anchor_.pos())
|
||||
selection.set(false);
|
||||
}
|
||||
|
||||
|
||||
void TextCursor::clearSelection()
|
||||
{
|
||||
selection.set(false);
|
||||
selection.mark(false);
|
||||
anchor_ = cursor_;
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file textcursor.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author unknown
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author John Levon
|
||||
* \author André Pönitz
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef TEXTCURSOR_H
|
||||
#define TEXTCURSOR_H
|
||||
|
||||
#include "cursor_slice.h"
|
||||
|
||||
// Do not even think of forward declaring LyXText/BufferView etc here!
|
||||
// If you need Paragraph proper, go to text_func.h
|
||||
|
||||
/** The cursor.
|
||||
Later this variable has to be removed. There should be no internal
|
||||
cursor in a text (and thus not in a buffer). By keeping this it is
|
||||
(I think) impossible to have several views with the same buffer, but
|
||||
the cursor placed at different places.
|
||||
[later]
|
||||
Since the LyXText now has been moved from Buffer to BufferView
|
||||
it should not be absolutely needed to move the cursor...
|
||||
[even later]
|
||||
Nevertheless, it should still be moved, in order to keep classes
|
||||
and interdependencies small.
|
||||
*/
|
||||
|
||||
// The structure that keeps track of the selections set.
|
||||
struct Selection {
|
||||
Selection()
|
||||
: set_(false), mark_(false)
|
||||
{}
|
||||
bool set() const {
|
||||
return set_;
|
||||
}
|
||||
void set(bool s) {
|
||||
set_ = s;
|
||||
}
|
||||
bool mark() const {
|
||||
return mark_;
|
||||
}
|
||||
void mark(bool m) {
|
||||
mark_ = m;
|
||||
}
|
||||
private:
|
||||
bool set_; // former selection
|
||||
bool mark_; // former mark_set
|
||||
|
||||
};
|
||||
|
||||
struct TextCursor {
|
||||
///
|
||||
void setSelection();
|
||||
///
|
||||
void clearSelection();
|
||||
|
||||
// actual cursor position
|
||||
CursorSlice cursor_;
|
||||
// the other end of the selection
|
||||
CursorSlice anchor_;
|
||||
|
||||
Selection selection;
|
||||
|
||||
CursorSlice const & selStart() const;
|
||||
CursorSlice const & selEnd() const;
|
||||
CursorSlice & selStart();
|
||||
CursorSlice & selEnd();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user