2003-02-14 00:41:44 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Row.cpp
|
2003-02-14 00:41:44 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-02-14 00:41:44 +00:00
|
|
|
|
* \author unknown
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-06-08 23:16:16 +00:00
|
|
|
|
*
|
2003-02-14 00:41:44 +00:00
|
|
|
|
* Metrics for an on-screen text row.
|
|
|
|
|
*/
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2000-06-15 15:54:05 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Row.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
|
Patch by Vincent that solves a number of problems related to the painting of a selection:
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
2008-09-14 14:32:40 +00:00
|
|
|
|
#include "DocIterator.h"
|
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2003-02-14 00:41:44 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
|
|
|
|
Row::Row()
|
2007-12-06 08:39:42 +00:00
|
|
|
|
: separator(0), label_hfill(0), x(0),
|
2008-09-16 11:32:38 +00:00
|
|
|
|
sel_beg(-1), sel_end(-1),
|
2008-10-13 23:19:06 +00:00
|
|
|
|
begin_margin_sel(false), end_margin_sel(false),
|
2008-09-16 11:32:38 +00:00
|
|
|
|
changed_(false), crc_(0), pos_(0), end_(0)
|
2000-06-08 23:16:16 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
void Row::setCrc(size_type crc) const
|
2000-06-08 23:16:16 +00:00
|
|
|
|
{
|
2007-11-17 11:27:03 +00:00
|
|
|
|
changed_ = crc != crc_;
|
2007-08-29 21:03:41 +00:00
|
|
|
|
crc_ = crc;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-29 21:03:41 +00:00
|
|
|
|
void Row::setDimension(Dimension const & dim)
|
2000-06-08 23:16:16 +00:00
|
|
|
|
{
|
2007-08-29 21:03:41 +00:00
|
|
|
|
dim_ = dim;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-29 21:03:41 +00:00
|
|
|
|
void Row::pos(pos_type p)
|
2003-08-22 07:49:57 +00:00
|
|
|
|
{
|
2007-08-29 21:03:41 +00:00
|
|
|
|
pos_ = p;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-29 21:03:41 +00:00
|
|
|
|
void Row::endpos(pos_type p)
|
2003-08-22 07:49:57 +00:00
|
|
|
|
{
|
2007-08-29 21:03:41 +00:00
|
|
|
|
end_ = p;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-14 22:09:10 +00:00
|
|
|
|
bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
|
|
|
|
|
DocIterator const & end) const
|
Patch by Vincent that solves a number of problems related to the painting of a selection:
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
2008-09-14 14:32:40 +00:00
|
|
|
|
{
|
2008-09-14 22:09:10 +00:00
|
|
|
|
pos_type const sel_pos = left_margin ? sel_beg : sel_end;
|
|
|
|
|
pos_type const margin_pos = left_margin ? pos_ : end_;
|
Patch by Vincent that solves a number of problems related to the painting of a selection:
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
2008-09-14 14:32:40 +00:00
|
|
|
|
|
|
|
|
|
// Is the chosen margin selected ?
|
|
|
|
|
if (sel_pos == margin_pos) {
|
|
|
|
|
if (beg.pos() == end.pos())
|
|
|
|
|
// This is a special case in which the space between after
|
|
|
|
|
// pos i-1 and before pos i is selected, i.e. the margins
|
|
|
|
|
// (see DocIterator::boundary_).
|
|
|
|
|
return beg.boundary() && !end.boundary();
|
|
|
|
|
else if (end.pos() == margin_pos)
|
|
|
|
|
// If the selection ends around the margin, it is only
|
|
|
|
|
// drawn if the cursor is after the margin.
|
|
|
|
|
return !end.boundary();
|
|
|
|
|
else if (beg.pos() == margin_pos)
|
|
|
|
|
// If the selection begins around the margin, it is
|
|
|
|
|
// only drawn if the cursor is before the margin.
|
|
|
|
|
return beg.boundary();
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Row::setSelectionAndMargins(DocIterator const & beg,
|
2008-09-14 22:09:10 +00:00
|
|
|
|
DocIterator const & end) const
|
Patch by Vincent that solves a number of problems related to the painting of a selection:
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
2008-09-14 14:32:40 +00:00
|
|
|
|
{
|
|
|
|
|
setSelection(beg.pos(), end.pos());
|
|
|
|
|
|
|
|
|
|
if (selection()) {
|
2008-10-13 23:19:06 +00:00
|
|
|
|
end_margin_sel = isMarginSelected(false, beg, end);
|
|
|
|
|
begin_margin_sel = isMarginSelected(true, beg, end);
|
Patch by Vincent that solves a number of problems related to the painting of a selection:
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
2008-09-14 14:32:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-03 11:03:47 +00:00
|
|
|
|
void Row::setSelection(pos_type beg, pos_type end) const
|
2007-09-05 13:04:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (pos_ >= beg && pos_ <= end)
|
|
|
|
|
sel_beg = pos_;
|
|
|
|
|
else if (beg > pos_ && beg <= end_)
|
|
|
|
|
sel_beg = beg;
|
|
|
|
|
else
|
|
|
|
|
sel_beg = -1;
|
|
|
|
|
|
|
|
|
|
if (end_ >= beg && end_ <= end)
|
|
|
|
|
sel_end = end_;
|
|
|
|
|
else if (end < end_ && end >= pos_)
|
|
|
|
|
sel_end = end;
|
|
|
|
|
else
|
|
|
|
|
sel_end = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Patch by Vincent that solves a number of problems related to the painting of a selection:
1. When a listing is inserted in a bit of text, the line above the listing is not drawn over the full width like it is done for lines above other insets. This is because InsetListing has a AlignLeft alignment. Now, if you start selecting downwards with the mouse in this empty area, strange selection drawings appear (see attachment).
This is caused by the fact that starting your selection at such a place, causes beg.boundary() to be true in TextMetrics::drawRowSelection(..). This is correct, but this value is true for _all_ selected lines. Now, the selection acts as if it is RTL text. Therefore, just like for end.boundary, this value needs to be reset for every line.
2. Starting your selection in an end margin often causes the selection in this end margin to be painted later. This is because when starting your selection in an end margin, you may have set a (possible empty) selection before really selecting the end margin. The problem is that the checksum (computed later) is the same for this empty selection and for the end margin selection. Therfore, we need a call to cur.setSelection() before evaluating cur.selection().
3. In the following two lines, it is assumed that there is only an end margin to be painted if the selection extends to the next paragraph. This is not true for the above described case of an AlignLeft Inset. Then, the margin has also be drawn within a paragraph
4. The end and begin margins are only painted when the selection extends into the following or previous paragraph. This difference is not resembled in the checksum if you first select a row completely and then procede to the next or previous paragraph as the selection remains at the end of a row. This also holds for the AlignLeft case. Therefore I added a term to the checksum to monitor whether the end and begin margins need to be drawn.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26399 a592a061-630c-0410-9148-cb99ea01b6c8
2008-09-14 14:32:40 +00:00
|
|
|
|
bool Row::selection() const
|
|
|
|
|
{
|
|
|
|
|
return sel_beg != -1 && sel_end != -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-16 10:36:57 +00:00
|
|
|
|
void Row::dump(char const * s) const
|
2003-08-01 14:12:04 +00:00
|
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
|
LYXERR0(s << " pos: " << pos_ << " end: " << end_
|
2007-08-28 09:21:48 +00:00
|
|
|
|
<< " width: " << dim_.wid
|
|
|
|
|
<< " ascent: " << dim_.asc
|
2007-11-28 22:12:03 +00:00
|
|
|
|
<< " descent: " << dim_.des);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|