cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20577 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-09-29 08:02:37 +00:00
parent bd03eaa571
commit f1687373b1
6 changed files with 35 additions and 48 deletions

View File

@ -252,7 +252,7 @@ Buffer const & BufferView::buffer() const
bool BufferView::fitCursor() bool BufferView::fitCursor()
{ {
if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) { if (cursorStatus(cursor_) == CUR_INSIDE) {
frontend::FontMetrics const & fm = frontend::FontMetrics const & fm =
theFontMetrics(cursor_.getFont()); theFontMetrics(cursor_.getFont());
int const asc = fm.maxAscent(); int const asc = fm.maxAscent();
@ -446,24 +446,22 @@ void BufferView::setCursorFromScrollbar()
int const last = height_ - height; int const last = height_ - height;
Cursor & cur = cursor_; Cursor & cur = cursor_;
bv_funcs::CurStatus st = bv_funcs::status(this, cur); switch (cursorStatus(cur)) {
case CUR_ABOVE:
switch (st) { // We reset the cursor because cursorStatus() does not
case bv_funcs::CUR_ABOVE:
// We reset the cursor because bv_funcs::status() does not
// work when the cursor is within mathed. // work when the cursor is within mathed.
cur.reset(buffer_.inset()); cur.reset(buffer_.inset());
tm.setCursorFromCoordinates(cur, 0, first); tm.setCursorFromCoordinates(cur, 0, first);
cur.clearSelection(); cur.clearSelection();
break; break;
case bv_funcs::CUR_BELOW: case CUR_BELOW:
// We reset the cursor because bv_funcs::status() does not // We reset the cursor because cursorStatus() does not
// work when the cursor is within mathed. // work when the cursor is within mathed.
cur.reset(buffer_.inset()); cur.reset(buffer_.inset());
tm.setCursorFromCoordinates(cur, 0, last); tm.setCursorFromCoordinates(cur, 0, last);
cur.clearSelection(); cur.clearSelection();
break; break;
case bv_funcs::CUR_INSIDE: case CUR_INSIDE:
int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_; int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_;
int const newy = min(last, max(y, first)); int const newy = min(last, max(y, first));
if (y != newy) { if (y != newy) {
@ -484,6 +482,19 @@ Change const BufferView::getCurrentChange() const
} }
// this could be used elsewhere as well?
// FIXME: This does not work within mathed!
CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
{
Point const p = bv_funcs::getPos(*this, dit, dit.boundary());
if (p.y_ < 0)
return CUR_ABOVE;
if (p.y_ > workHeight())
return CUR_BELOW;
return CUR_INSIDE;
}
void BufferView::saveBookmark(unsigned int idx) void BufferView::saveBookmark(unsigned int idx)
{ {
// tenatively save bookmark, id and pos will be used to // tenatively save bookmark, id and pos will be used to

View File

@ -48,6 +48,12 @@ class Text;
class ParIterator; class ParIterator;
class ParagraphMetrics; class ParagraphMetrics;
class ViewMetricsInfo; class ViewMetricsInfo;
enum CursorStatus {
CUR_INSIDE,
CUR_ABOVE,
CUR_BELOW
};
/// Scrollbar Parameters. /// Scrollbar Parameters.
struct ScrollbarParameters struct ScrollbarParameters
@ -171,6 +177,8 @@ public:
/// access to anchor. /// access to anchor.
pit_type anchor_ref() const; pit_type anchor_ref() const;
///
CursorStatus cursorStatus(DocIterator const & dit) const;
/// access to full cursor. /// access to full cursor.
Cursor & cursor(); Cursor & cursor();
/// access to full cursor. /// access to full cursor.
@ -210,13 +218,9 @@ public:
ParagraphMetrics const & parMetrics(Text const *, pit_type) const; ParagraphMetrics const & parMetrics(Text const *, pit_type) const;
/// ///
CoordCache & coordCache() { CoordCache & coordCache() { return coord_cache_; }
return coord_cache_;
}
/// ///
CoordCache const & coordCache() const { CoordCache const & coordCache() const { return coord_cache_; }
return coord_cache_;
}
/// ///
void draw(frontend::Painter & pain); void draw(frontend::Painter & pain);

View File

@ -218,7 +218,7 @@ namespace {
for ( ; it != et; it.forwardPos()) { for ( ; it != et; it.forwardPos()) {
// avoid invalid nesting when selecting // avoid invalid nesting when selecting
if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE if (bv.cursorStatus(it) == CUR_INSIDE
&& (!cur.selection() || positionable(it, cur.anchor_))) { && (!cur.selection() || positionable(it, cur.anchor_))) {
Point p = bv_funcs::getPos(bv, it, false); Point p = bv_funcs::getPos(bv, it, false);
int xo = p.x_; int xo = p.x_;

View File

@ -1177,7 +1177,7 @@ void TextMetrics::newParMetricsDown()
{ {
pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin(); pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
pit_type const pit = last.first + 1; pit_type const pit = last.first + 1;
if (pit == text_->paragraphs().size()) if (pit == int(text_->paragraphs().size()))
return; return;
// do it and update its position. // do it and update its position.
@ -1995,8 +1995,7 @@ void TextMetrics::drawSelection(PainterInfo & pi,
// clip above // clip above
int middleTop; int middleTop;
bool const clipAbove = bool const clipAbove = (bv_->cursorStatus(beg) == CUR_ABOVE);
(bv_funcs::status(bv_, beg) == bv_funcs::CUR_ABOVE);
if (clipAbove) if (clipAbove)
middleTop = 0; middleTop = 0;
else else
@ -2004,15 +2003,14 @@ void TextMetrics::drawSelection(PainterInfo & pi,
// clip below // clip below
int middleBottom; int middleBottom;
bool const clipBelow = bool const clipBelow = (bv_->cursorStatus(end) == CUR_BELOW);
(bv_funcs::status(bv_, end) == bv_funcs::CUR_BELOW);
if (clipBelow) if (clipBelow)
middleBottom = bv_->workHeight(); middleBottom = bv_->workHeight();
else else
middleBottom = bv_funcs::getPos(*bv_, end, end.boundary()).y_ - row2.ascent(); middleBottom = bv_funcs::getPos(*bv_, end, end.boundary()).y_ - row2.ascent();
// start and end in the same line? // start and end in the same line?
if (!(clipAbove || clipBelow) && &row1 == &row2) if (!clipAbove && !clipBelow && &row1 == &row2)
// then only draw this row's selection // then only draw this row's selection
drawRowSelection(pi, x, row1, beg, end, false, false); drawRowSelection(pi, x, row1, beg, end, false, false);
else { else {

View File

@ -253,21 +253,6 @@ Point getPos(BufferView const & bv, DocIterator const & dit, bool boundary)
return p; return p;
} }
// this could be used elsewhere as well?
// FIXME: This does not work within mathed!
CurStatus status(BufferView const * bv, DocIterator const & dit)
{
Point const p = bv_funcs::getPos(*bv, dit, dit.boundary());
if (p.y_ < 0)
return CUR_ABOVE;
if (p.y_ > bv->workHeight())
return CUR_BELOW;
return CUR_INSIDE;
}
} // namespace bv_funcs } // namespace bv_funcs

View File

@ -15,7 +15,6 @@
#define BUFFERVIEW_FUNCS_H #define BUFFERVIEW_FUNCS_H
#include <string> #include <string>
#include <vector>
namespace lyx { namespace lyx {
@ -40,16 +39,6 @@ std::string const freefont2string();
Point getPos(BufferView const & bv, DocIterator const & dit, bool boundary); Point getPos(BufferView const & bv, DocIterator const & dit, bool boundary);
enum CurStatus {
CUR_INSIDE,
CUR_ABOVE,
CUR_BELOW
};
CurStatus status(BufferView const * bv, DocIterator const & dit);
Point coordOffset(BufferView const & bv, DocIterator const & dit, bool boundary); Point coordOffset(BufferView const & bv, DocIterator const & dit, bool boundary);
} // namespace bv_funcs } // namespace bv_funcs