the 'fitCursor fix'

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8624 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2004-04-07 20:20:15 +00:00
parent 6f851a34d2
commit db2c1d5917
28 changed files with 329 additions and 244 deletions

View File

@ -379,23 +379,10 @@ void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
par[i].inset().edit(cursor(), true);
cursor().setCursor(makeDocIterator(par, pos), false);
par.bottom().text()->redoParagraph(par.bottom().par());
}
/*
if the fitCursor call refers to some point in never-explored-land, then we
don't have y information in insets there, then we cannot even do an update
to get it (because we need the y infomation for setting top_y first). So
this is solved in putSelectionAt with:
- setting top_y to the y of the outerPar (that has good info)
- calling update
- calling cursor().updatePos()
- then call fitCursor()
Ab.
*/
void BufferView::putSelectionAt(DocIterator const & cur,
int length, bool backwards)
{
@ -403,16 +390,8 @@ void BufferView::putSelectionAt(DocIterator const & cur,
cursor().clearSelection();
LyXText & text = *cur[0].text();
setCursor(par, cur.pos());
// hack for the chicken and egg problem
top_y(text.getPar(par.outerPar()).y);
update();
//text.setCursor(cursor(), cur.par(), cur.pos());
cursor().updatePos();
if (length) {
if (backwards) {
cursor().setSelection(cursor(), -length);
@ -422,9 +401,6 @@ void BufferView::putSelectionAt(DocIterator const & cur,
} else
cursor().setSelection(cursor(), length);
}
fitCursor();
update();
}

View File

@ -44,6 +44,7 @@
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "pariterator.h"
#include "rowpainter.h"
#include "undo.h"
#include "vspace.h"
@ -66,6 +67,7 @@
#include "support/globbing.h"
#include "support/path_defines.h"
#include "support/tostr.h"
#include "support/types.h"
#include <boost/bind.hpp>
@ -358,6 +360,12 @@ void BufferView::Pimpl::setBuffer(Buffer * b)
bool BufferView::Pimpl::fitCursor()
{
// to get the correct y cursor info
lyxerr << "BufferView::fitCursor" << std::endl;
lyx::par_type const pit = bv_->cursor().bottom().par();
bv_->text()->redoParagraph(pit);
refreshPar(*bv_, *bv_->text(), pit);
if (!screen().fitCursor(bv_))
return false;
updateScrollbar();
@ -388,7 +396,6 @@ void BufferView::Pimpl::resizeCurrentBuffer()
text->init(bv_);
update();
bv_->cursor().updatePos();
fitCursor();
switchKeyMap();
@ -896,11 +903,11 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
if (!res.dispatched())
res = cur.dispatch(cmd);
if (res.dispatched()) {
// Redraw if requested or necessary.
if (res.update())
update();
if (fitCursor())
if (fitCursor() || res.update())
update();
}
// see workAreaKeyPress
cursor_timeout.restart();
@ -1089,7 +1096,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
#endif
while (lyx::find::findNextChange(bv_))
bv_->getLyXText()->rejectChange(bv_->cursor());
update();
break;
}
@ -1103,7 +1109,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
case LFUN_MARK_OFF:
cur.clearSelection();
update();
cur.resetAnchor();
cur.message(N_("Mark off"));
break;
@ -1111,7 +1116,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
case LFUN_MARK_ON:
cur.clearSelection();
cur.mark() = true;
update();
cur.resetAnchor();
cur.message(N_("Mark on"));
break;
@ -1126,7 +1130,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
cur.message(N_("Mark set"));
}
cur.resetAnchor();
update();
break;
case LFUN_CENTER:

View File

@ -1,3 +1,31 @@
2004-04-07 Alfredo Braunstein <abraunst@lyx.org>
* BufferView.C (setCursor): call redoParagraph (some insets could
have been opened)
(putSelectionAt): remove the 'double update' trick
* BufferView_pimpl.C (fitCursor): call refreshPar
(workAreaDispatch): remove an uneeded update call
(dispatch): remove some manual update calls
* cursor.[Ch]: remove cached_y_, updatePos
(selHandle): set noUpdate when appropriate
* lyxfunc.C (dispatch): track if we need an update
* metricsinfo.[Ch]: PainterInfo receive a Painter & on construction
* rowpainter.[Ch] (RowPainter): remove superfluous xo_ parameter
(paintSelection): cheap optimization, do not call cursorX when not
needed
(paintPars): change signature
(refreshPar): add
(paintText): adjust
(paintTextInset): adjust
* text.C: adjust
2004-04-05 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lengthcommon.C: compilation fix: remove explicit array size from

View File

@ -84,8 +84,7 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
LCursor::LCursor(BufferView & bv)
: DocIterator(), bv_(&bv),
anchor_(), cached_y_(0), x_target_(-1),
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
selection_(false), mark_(false)
{}
@ -95,7 +94,6 @@ void LCursor::reset(InsetBase & inset)
clear();
push_back(CursorSlice(inset));
anchor_ = DocIterator(inset);
cached_y_ = 0;
clearTargetX();
selection_ = false;
mark_ = false;
@ -139,6 +137,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
if (!disp_.dispatched()) {
lyxerr << "RESTORING OLD CURSOR!" << endl;
operator=(safe);
disp_.dispatched(false);
}
return disp_;
}
@ -236,15 +235,6 @@ int LCursor::currentMode()
}
void LCursor::updatePos()
{
BOOST_ASSERT(!empty());
if (size() > 1)
cached_y_ = bv().top_y() + back().inset().yo();
//cached_y_ = back().inset().yo();
}
void LCursor::getDim(int & asc, int & des) const
{
if (inMathed()) {
@ -270,16 +260,6 @@ void LCursor::getPos(int & x, int & y) const
y = 0;
if (!empty())
inset().getCursorPos(back(), x, y);
// getCursorPos gives _screen_ coordinates. We need to add
// top_y to get document coordinates. This is hidden in cached_y_.
//y += cached_y_ - inset().yo();
// The rest is non-obvious. The reason we have to have these
// extra computation is that the getCursorPos() calls rely
// on the inset's own knowledge of its screen position.
// If we scroll up or down in a big enough increment,
// inset->draw() is not called: this doesn't update
// inset.yo_, so getCursor() returns an old value.
// Ugly as you like.
}
@ -535,8 +515,12 @@ void LCursor::selPaste(size_t n)
void LCursor::selHandle(bool sel)
{
//lyxerr << "LCursor::selHandle" << endl;
if (sel == selection())
if (sel == selection()) {
if (!sel)
noUpdate();
return;
}
resetAnchor();
selection() = sel;
}

View File

@ -142,8 +142,6 @@ public:
/// access to normalized selection anchor
CursorSlice anchor() const;
/// cache the absolute coordinate from the top inset
void updatePos();
/// sets anchor to cursor position
void resetAnchor();
/// access to owning BufferView
@ -180,8 +178,6 @@ public:
DispatchResult disp_;
private:
///
int cached_y_;
/**
* The target x position of the cursor. This is used for when
* we have text like :

View File

@ -1,3 +1,13 @@
2004-04-07 Alfredo Braunstein <abraunst@lyx.org>
* Makefile.am: adjust
* Painter.[Ch]: remove Painter & return value everywhere, make
virtual all remaining nonvirtual methods
* nullpainter.[Ch]: add no-op painter
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.h: remove redundant header file. Clean up comments.

View File

@ -35,5 +35,7 @@ libfrontends_la_SOURCES = \
key_state.h \
lyx_gui.h \
mouse_state.h \
nullpainter.C \
nullpainter.h \
screen.C \
screen.h

View File

@ -22,15 +22,14 @@ using std::max;
using std::string;
Painter & Painter::button(int x, int y, int w, int h)
void Painter::button(int x, int y, int w, int h)
{
fillRectangle(x, y, w, h, LColor::buttonbg);
buttonFrame(x, y, w, h);
return * this;
}
Painter & Painter::buttonFrame(int x, int y, int w, int h)
void Painter::buttonFrame(int x, int y, int w, int h)
{
// Width of a side of the button
int const d = 2;
@ -52,12 +51,10 @@ Painter & Painter::buttonFrame(int x, int y, int w, int h)
x1[2] = x + w; y1[2] = (y + h - d);
x1[3] = x + w; y1[3] = y;
fillPolygon(x1, y1, 4, LColor::right);
return *this;
}
Painter & Painter::rectText(int x, int baseline,
void Painter::rectText(int x, int baseline,
string const & str,
LyXFont const & font,
LColor_color back,
@ -79,11 +76,10 @@ Painter & Painter::rectText(int x, int baseline,
}
text(x + 3, baseline, str, font);
return *this;
}
Painter & Painter::buttonText(int x, int baseline,
void Painter::buttonText(int x, int baseline,
string const & str,
LyXFont const & font)
{
@ -95,7 +91,6 @@ Painter & Painter::buttonText(int x, int baseline,
button(x, baseline - ascent, width, descent + ascent);
text(x + 4, baseline, str, font);
return *this;
}

View File

@ -74,7 +74,7 @@ public:
virtual int paperHeight() const = 0;
/// draw a line from point to point
virtual Painter & line(
virtual void line(
int x1, int y1,
int x2, int y2,
LColor_color,
@ -87,7 +87,7 @@ public:
* @param yp array of points' y co-ords
* @param np size of the points array
*/
virtual Painter & lines(
virtual void lines(
int const * xp,
int const * yp,
int np,
@ -96,7 +96,7 @@ public:
line_width = line_thin) = 0;
/// draw a rectangle
virtual Painter & rectangle(
virtual void rectangle(
int x, int y,
int w, int h,
LColor_color,
@ -104,53 +104,53 @@ public:
line_width = line_thin) = 0;
/// draw a filled rectangle
virtual Painter & fillRectangle(
virtual void fillRectangle(
int x, int y,
int w, int h,
LColor_color) = 0;
/// draw a filled (irregular) polygon
virtual Painter & fillPolygon(
virtual void fillPolygon(
int const * xp,
int const * yp,
int np,
LColor_color) = 0;
/// draw an arc
virtual Painter & arc(
virtual void arc(
int x, int y,
unsigned int w, unsigned int h,
int a1, int a2,
LColor_color) = 0;
/// draw a pixel
virtual Painter & point(
virtual void point(
int x, int y,
LColor_color) = 0;
/// draw a filled rectangle with the shape of a 3D button
virtual Painter & button(int x, int y,
virtual void button(int x, int y,
int w, int h);
/// draw an image from the image cache
virtual Painter & image(int x, int y,
virtual void image(int x, int y,
int w, int h,
lyx::graphics::Image const & image) = 0;
/// draw a string at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
std::string const & str, LyXFont const & f) = 0;
/**
* Draw a string at position x, y (y is the baseline)
* This is just for fast drawing
*/
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char const * str, size_t l,
LyXFont const & f) = 0;
/// draw a char at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char c, LyXFont const & f) = 0;
/**
@ -159,24 +159,24 @@ public:
* the given color. If frame is specified, a thin frame is drawn
* around the text with the given color.
*/
Painter & rectText(int x, int baseline,
virtual void rectText(int x, int baseline,
std::string const & str,
LyXFont const & font,
LColor_color back,
LColor_color frame);
/// draw a string and enclose it inside a button frame
Painter & buttonText(int x,
virtual void buttonText(int x,
int baseline, std::string const & s,
LyXFont const & font);
protected:
/// check the font, and if set, draw an underline
void underline(LyXFont const & f,
virtual void underline(LyXFont const & f,
int x, int y, int width);
/// draw a bevelled button border
Painter & buttonFrame(int x, int y, int w, int h);
virtual void buttonFrame(int x, int y, int w, int h);
};
#endif // PAINTER_H

View File

@ -1,3 +1,8 @@
2004-04-07 Alfredo Braunstein <abraunst@lyx.org>
* GPainter.[Ch]: adjust to changes in Painter.h
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): set the preferences dialog button policy to

View File

@ -86,7 +86,7 @@ void GPainter::setLineParam(Glib::RefPtr<Gdk::GC> gc,
}
Painter & GPainter::point(int x, int y, LColor_color c)
void GPainter::point(int x, int y, LColor_color c)
{
setForeground(owner_.getGC(), c);
owner_.getPixmap()->draw_point(owner_.getGC(), x, y);
@ -94,7 +94,7 @@ Painter & GPainter::point(int x, int y, LColor_color c)
}
Painter & GPainter::line(int x1, int y1,
void GPainter::line(int x1, int y1,
int x2, int y2,
LColor_color col,
line_style ls,
@ -107,8 +107,7 @@ Painter & GPainter::line(int x1, int y1,
}
Painter & GPainter::lines(int const * xp, int const * yp,
int np,
void GPainter::lines(int const * xp, int const * yp, int np,
LColor_color col,
line_style ls,
line_width lw)
@ -126,8 +125,7 @@ Painter & GPainter::lines(int const * xp, int const * yp,
}
Painter & GPainter::rectangle(int x, int y,
int w, int h,
void GPainter::rectangle(int x, int y, int w, int h,
LColor_color col,
line_style ls,
line_width lw)
@ -139,8 +137,7 @@ Painter & GPainter::rectangle(int x, int y,
}
Painter & GPainter::fillRectangle(int x, int y,
int w, int h,
void GPainter::fillRectangle(int x, int y, int w, int h,
LColor_color col)
{
setForeground(owner_.getGC(), col);
@ -149,7 +146,7 @@ Painter & GPainter::fillRectangle(int x, int y,
}
Painter & GPainter::fillPolygon(int const * xp, int const * yp,
void GPainter::fillPolygon(int const * xp, int const * yp,
int np, LColor_color col)
{
setForeground(owner_.getGC(), col);
@ -164,8 +161,7 @@ Painter & GPainter::fillPolygon(int const * xp, int const * yp,
}
Painter & GPainter::arc(int x, int y,
unsigned int w, unsigned int h,
void GPainter::arc(int x, int y, unsigned int w, unsigned int h,
int a1, int a2, LColor_color col)
{
setForeground(owner_.getGC(), col);
@ -175,8 +171,7 @@ Painter & GPainter::arc(int x, int y,
}
Painter & GPainter::image(int x, int y,
int w, int h,
void GPainter::image(int x, int y, int w, int h,
lyx::graphics::Image const & i)
{
lyx::graphics::xformsImage const & image =
@ -189,8 +184,7 @@ Painter & GPainter::image(int x, int y,
}
Painter & GPainter::text(int x, int y,
std::string const & s, LyXFont const & f)
void GPainter::text(int x, int y, std::string const & s, LyXFont const & f)
{
size_t size = s.length() + 1;
wchar_t * wcs = (wchar_t *) alloca(size * sizeof(wchar_t));
@ -199,8 +193,7 @@ Painter & GPainter::text(int x, int y,
}
Painter & GPainter::text(int x, int y,
char c, LyXFont const & f)
void GPainter::text(int x, int y, char c, LyXFont const & f)
{
char s[2] = { c, '\0' };
return text(x, y, s, 1, f);
@ -222,8 +215,7 @@ int width(wchar_t const *s, size_t n, LyXFont const & f);
}
Painter & GPainter::text(int x, int y, wchar_t const * s, int ls,
LyXFont const & f)
void GPainter::text(int x, int y, wchar_t const * s, int ls, LyXFont const & f)
{
XftFont * font = getXftFont(f);
XftColor * xftClr = owner_.getColorHandler().
@ -258,9 +250,7 @@ Painter & GPainter::text(int x, int y, wchar_t const * s, int ls,
}
Painter & GPainter::text(int x, int y,
char const * s, size_t ls,
LyXFont const & f)
void GPainter::text(int x, int y, char const * s, size_t ls, LyXFont const & f)
{
boost::scoped_array<wchar_t> wcs(new wchar_t[ls + 1]);
size_t len;

View File

@ -38,7 +38,7 @@ public:
line_style ls, line_width lw);
XftColor * getXftColor(LColor_color clr);
/// draw a line from point to point
virtual Painter & line(
virtual void line(
int x1, int y1,
int x2, int y2,
LColor_color,
@ -51,7 +51,7 @@ public:
* @param yp array of points' y co-ords
* @param np size of the points array
*/
virtual Painter & lines(
virtual void lines(
int const * xp,
int const * yp,
int np,
@ -60,7 +60,7 @@ public:
line_width = line_thin);
/// draw a rectangle
virtual Painter & rectangle(
virtual void rectangle(
int x, int y,
int w, int h,
LColor_color,
@ -68,55 +68,55 @@ public:
line_width = line_thin);
/// draw a filled rectangle
virtual Painter & fillRectangle(
virtual void fillRectangle(
int x, int y,
int w, int h,
LColor_color);
/// draw a filled (irregular) polygon
virtual Painter & fillPolygon(
virtual void fillPolygon(
int const * xp,
int const * yp,
int np,
LColor_color);
/// draw an arc
virtual Painter & arc(
virtual void arc(
int x, int y,
unsigned int w, unsigned int h,
int a1, int a2,
LColor_color);
/// draw a pixel
virtual Painter & point(
virtual void point(
int x, int y,
LColor_color);
/// draw an image from the image cache
virtual Painter & image(int x, int y,
virtual void image(int x, int y,
int w, int h,
lyx::graphics::Image const & image);
/// draw a string at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
std::string const & str, LyXFont const & f);
/** Draw a string at position x, y (y is the baseline)
* This is just for fast drawing
*/
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char const * str, size_t l,
LyXFont const & f);
virtual Painter & text(int x, int y, wchar_t const * str, int l,
virtual void text(int x, int y, wchar_t const * str, int l,
LyXFont const & f);
/// draw a char at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char c, LyXFont const & f);
/// draw a wide string at position x, y
Painter & text(int x, int y,
void text(int x, int y,
XChar2b const * str, size_t l,
LyXFont const & f);

View File

@ -0,0 +1,22 @@
/**
* \file nullpainter.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alfredo Braunstein
* \author John Levon
*
* Full author contact details are available in file CREDITS.
*/
#include "nullpainter.h"
#include "LColor.h"
#include <limits>
int NullPainter::paperHeight() const
{
return std::numeric_limits<int>::max();
}

View File

@ -0,0 +1,76 @@
// -*- C++ -*-
/**
* \file nullpainter.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alfredo Braunstein
*
* Full author contact details are available in file CREDITS.
*/
#ifndef NULLPAINTER_H
#define NULLPAINTER_H
#include <config.h>
#include "LColor.h"
#include "Painter.h"
class NullPainter : public Painter {
public:
///
NullPainter() {}
virtual ~NullPainter() {}
/// begin painting
void start() {}
/// end painting
void end() {}
///
int paperWidth() const { return 0; }
///
int paperHeight() const;
///
void line(int, int, int, int, LColor_color,
line_style = line_solid, line_width = line_thin) {}
///
void lines(int const *, int const *, int, LColor_color,
line_style = line_solid, line_width = line_thin) {}
///
void rectangle(int, int, int, int, LColor_color,
line_style = line_solid, line_width = line_thin) {}
///
void fillRectangle(int, int, int, int, LColor_color) {}
///
void fillPolygon(int const *, int const *, int, LColor_color) {}
///
void arc(int, int, unsigned int, unsigned int,
int, int, LColor_color) {}
///
void point(int, int, LColor_color) {}
///
void button(int, int, int, int) {}
///
void image(int, int, int, int, lyx::graphics::Image const &) {}
///
void text(int, int, std::string const &, LyXFont const &) {}
///
void text(int, int, char const *, size_t, LyXFont const &) {}
///
void text(int, int, char, LyXFont const &) {}
///
void rectText(int, int, std::string const &,
LyXFont const &, LColor_color, LColor_color) {}
///
void buttonText(int, int, std::string const &, LyXFont const &) {}
///
void underline(LyXFont const &, int, int, int) {}
///
void buttonFrame(int, int, int, int) {}
};
#endif // NULLPAINTER_H

View File

@ -1,3 +1,7 @@
2004-04-07 Alfredo Braunstein <abraunst@lyx.org>
* QLPainter.[Ch]: adjust to changes in Painter.h
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): set the preferences dialog button policy to

View File

@ -86,26 +86,22 @@ QPainter & QLPainter::setPen(LColor_color c,
}
Painter & QLPainter::point(int x, int y, LColor_color c)
void QLPainter::point(int x, int y, LColor_color c)
{
setPen(c).drawPoint(x, y);
return *this;
}
Painter & QLPainter::line(int x1, int y1,
int x2, int y2,
void QLPainter::line(int x1, int y1, int x2, int y2,
LColor_color col,
line_style ls,
line_width lw)
{
setPen(col, ls, lw).drawLine(x1, y1, x2, y2);
return *this;
}
Painter & QLPainter::lines(int const * xp, int const * yp,
int np,
void QLPainter::lines(int const * xp, int const * yp, int np,
LColor_color col,
line_style ls,
line_width lw)
@ -121,38 +117,31 @@ Painter & QLPainter::lines(int const * xp, int const * yp,
}
setPen(col, ls, lw).drawPolyline(QPointArray(np, points.get()));
return *this;
}
Painter & QLPainter::rectangle(int x, int y,
int w, int h,
void QLPainter::rectangle(int x, int y, int w, int h,
LColor_color col,
line_style ls,
line_width lw)
{
setPen(col, ls, lw).drawRect(x, y, w, h);
return *this;
}
Painter & QLPainter::fillRectangle(int x, int y,
int w, int h,
LColor_color col)
void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
{
qp_->fillRect(x, y, w, h, lcolorcache.get(col));
return *this;
}
Painter & QLPainter::fillPolygon(int const * xp, int const * yp,
void QLPainter::fillPolygon(int const * xp, int const * yp,
int np, LColor_color col)
{
// Must use new as np is not known at compile time.
boost::scoped_array<QCOORD> points(new QCOORD[np * 2]);
//if (1) return *this;
//if (1) return;
for (int i = 0, j = 0; i < np; ++i) {
points[j++] = xp[i];
@ -163,39 +152,31 @@ Painter & QLPainter::fillPolygon(int const * xp, int const * yp,
qp_->setBrush(lcolorcache.get(col));
qp_->drawPolygon(QPointArray(np, points.get()));
qp_->setBrush(Qt::NoBrush);
return *this;
}
Painter & QLPainter::arc(int x, int y,
unsigned int w, unsigned int h,
void QLPainter::arc(int x, int y, unsigned int w, unsigned int h,
int a1, int a2, LColor_color col)
{
// LyX usings 1/64ths degree, Qt usings 1/16th
setPen(col).drawArc(x, y, w, h, a1 / 4, a2 / 4);
return *this;
}
Painter & QLPainter::image(int x, int y,
int w, int h,
void QLPainter::image(int x, int y, int w, int h,
lyx::graphics::Image const & i)
{
qp_->drawPixmap(x, y, static_cast<lyx::graphics::QLImage const &>(i).qpixmap(), 0, 0, w, h);
return *this;
}
Painter & QLPainter::text(int x, int y,
string const & s, LyXFont const & f)
void QLPainter::text(int x, int y, string const & s, LyXFont const & f)
{
return text(x, y, s.data(), s.length(), f);
}
Painter & QLPainter::text(int x, int y,
char c, LyXFont const & f)
void QLPainter::text(int x, int y, char c, LyXFont const & f)
{
char s[2] = { c, '\0' };
return text(x, y, s, 1, f);
@ -230,8 +211,7 @@ void QLPainter::smallCapsText(int x, int y,
}
Painter & QLPainter::text(int x, int y,
char const * s, size_t ls,
void QLPainter::text(int x, int y, char const * s, size_t ls,
LyXFont const & f)
{
setPen(f.realColor());
@ -269,6 +249,4 @@ Painter & QLPainter::text(int x, int y,
if (f.underbar() == LyXFont::ON) {
underline(f, x, y, font_metrics::width(s, ls, f));
}
return *this;
}

View File

@ -40,7 +40,7 @@ public:
virtual int paperHeight() const;
/// draw a line from point to point
virtual Painter & line(
virtual void line(
int x1, int y1,
int x2, int y2,
LColor_color,
@ -53,7 +53,7 @@ public:
* @param yp array of points' y co-ords
* @param np size of the points array
*/
virtual Painter & lines(
virtual void lines(
int const * xp,
int const * yp,
int np,
@ -62,7 +62,7 @@ public:
line_width = line_thin);
/// draw a rectangle
virtual Painter & rectangle(
virtual void rectangle(
int x, int y,
int w, int h,
LColor_color,
@ -70,48 +70,48 @@ public:
line_width = line_thin);
/// draw a filled rectangle
virtual Painter & fillRectangle(
virtual void fillRectangle(
int x, int y,
int w, int h,
LColor_color);
/// draw a filled (irregular) polygon
virtual Painter & fillPolygon(
virtual void fillPolygon(
int const * xp,
int const * yp,
int np,
LColor_color);
/// draw an arc
virtual Painter & arc(
virtual void arc(
int x, int y,
unsigned int w, unsigned int h,
int a1, int a2,
LColor_color);
/// draw a pixel
virtual Painter & point(
virtual void point(
int x, int y,
LColor_color);
/// draw an image from the image cache
virtual Painter & image(int x, int y,
virtual void image(int x, int y,
int w, int h,
lyx::graphics::Image const & image);
/// draw a string at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
std::string const & str, LyXFont const & f);
/** Draw a string at position x, y (y is the baseline)
* This is just for fast drawing
*/
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char const * str, size_t l,
LyXFont const & f);
/// draw a char at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char c, LyXFont const & f);
private:
/// draw small caps text

View File

@ -213,8 +213,8 @@ bool LyXScreen::fitCursor(BufferView * bv)
bv->cursor().getPos(x, y);
bv->cursor().getDim(asc, desc);
//lyxerr << "LyXScreen::fitCursor: x: " << x << " y: " << y
// << " top_y: " << top_y << endl;
lyxerr << "LyXScreen::fitCursor: x: " << x << " y: " << y
<< " top_y: " << top_y << endl;
bool const big_row = h / 4 < asc + desc && asc + desc < h;

View File

@ -1,3 +1,8 @@
2004-04-07 Alfredo Braunstein <abraunst@lyx.org>
* XPainter.[Ch]: adjust to changes in Painter.h
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): set the preferences dialog button policy to

View File

@ -51,15 +51,14 @@ int XPainter::paperHeight() const
}
Painter & XPainter::point(int x, int y, LColor_color c)
void XPainter::point(int x, int y, LColor_color c)
{
XDrawPoint(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCForeground(c), x, y);
return *this;
}
Painter & XPainter::line(int x1, int y1,
void XPainter::line(int x1, int y1,
int x2, int y2,
LColor_color col,
line_style ls,
@ -68,11 +67,10 @@ Painter & XPainter::line(int x1, int y1,
XDrawLine(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col),
x1, y1, x2, y2);
return *this;
}
Painter & XPainter::lines(int const * xp, int const * yp,
void XPainter::lines(int const * xp, int const * yp,
int np,
LColor_color col,
line_style ls,
@ -88,12 +86,10 @@ Painter & XPainter::lines(int const * xp, int const * yp,
XDrawLines(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col),
points.get(), np, CoordModeOrigin);
return *this;
}
Painter & XPainter::rectangle(int x, int y,
void XPainter::rectangle(int x, int y,
int w, int h,
LColor_color col,
line_style ls,
@ -102,21 +98,19 @@ Painter & XPainter::rectangle(int x, int y,
XDrawRectangle(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col),
x, y, w, h);
return *this;
}
Painter & XPainter::fillRectangle(int x, int y,
void XPainter::fillRectangle(int x, int y,
int w, int h,
LColor_color col)
{
XFillRectangle(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCForeground(col), x, y, w, h);
return *this;
}
Painter & XPainter::fillPolygon(int const * xp, int const * yp,
void XPainter::fillPolygon(int const * xp, int const * yp,
int np, LColor_color col)
{
boost::scoped_array<XPoint> points(new XPoint[np]);
@ -129,23 +123,20 @@ Painter & XPainter::fillPolygon(int const * xp, int const * yp,
XFillPolygon(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCForeground(col), points.get(),
np, Nonconvex, CoordModeOrigin);
return *this;
}
Painter & XPainter::arc(int x, int y,
void XPainter::arc(int x, int y,
unsigned int w, unsigned int h,
int a1, int a2, LColor_color col)
{
XDrawArc(fl_get_display(), owner_.getPixmap(),
lyxColorHandler->getGCForeground(col),
x, y, w, h, a1, a2);
return *this;
}
Painter & XPainter::image(int x, int y,
void XPainter::image(int x, int y,
int w, int h,
lyx::graphics::Image const & i)
{
@ -159,18 +150,17 @@ Painter & XPainter::image(int x, int y,
XCopyArea(fl_get_display(), image.getPixmap(), owner_.getPixmap(),
gc, 0, 0, w, h, x, y);
XFreeGC(fl_get_display(), gc);
return *this;
}
Painter & XPainter::text(int x, int y,
void XPainter::text(int x, int y,
string const & s, LyXFont const & f)
{
return text(x, y, s.data(), s.length(), f);
}
Painter & XPainter::text(int x, int y,
void XPainter::text(int x, int y,
char c, LyXFont const & f)
{
char s[2] = { c, '\0' };
@ -178,7 +168,7 @@ Painter & XPainter::text(int x, int y,
}
Painter & XPainter::text(int x, int y,
void XPainter::text(int x, int y,
char const * s, size_t ls,
LyXFont const & f)
{
@ -199,7 +189,7 @@ Painter & XPainter::text(int x, int y,
xs[i].byte2 = c & 0xff;
}
text(x, y, xs.get(), ls, font);
return *this;
return;
}
GC gc = lyxColorHandler->getGCForeground(f.realColor());
@ -229,12 +219,10 @@ Painter & XPainter::text(int x, int y,
if (f.underbar() == LyXFont::ON) {
underline(f, x, y, font_metrics::width(s, ls, f));
}
return *this;
}
Painter & XPainter::text(int x, int y,
void XPainter::text(int x, int y,
XChar2b const * s, size_t ls,
LyXFont const & f)
{
@ -271,6 +259,4 @@ Painter & XPainter::text(int x, int y,
if (f.underbar() == LyXFont::ON) {
underline(f, x, y, xfont_metrics::width(s, ls, f));
}
return *this;
}

View File

@ -34,7 +34,7 @@ public:
virtual int paperHeight() const;
/// draw a line from point to point
virtual Painter & line(
virtual void line(
int x1, int y1,
int x2, int y2,
LColor_color,
@ -47,7 +47,7 @@ public:
* @param yp array of points' y co-ords
* @param np size of the points array
*/
virtual Painter & lines(
virtual void lines(
int const * xp,
int const * yp,
int np,
@ -56,7 +56,7 @@ public:
line_width = line_thin);
/// draw a rectangle
virtual Painter & rectangle(
virtual void rectangle(
int x, int y,
int w, int h,
LColor_color,
@ -64,52 +64,52 @@ public:
line_width = line_thin);
/// draw a filled rectangle
virtual Painter & fillRectangle(
virtual void fillRectangle(
int x, int y,
int w, int h,
LColor_color);
/// draw a filled (irregular) polygon
virtual Painter & fillPolygon(
virtual void fillPolygon(
int const * xp,
int const * yp,
int np,
LColor_color);
/// draw an arc
virtual Painter & arc(
virtual void arc(
int x, int y,
unsigned int w, unsigned int h,
int a1, int a2,
LColor_color);
/// draw a pixel
virtual Painter & point(
virtual void point(
int x, int y,
LColor_color);
/// draw an image from the image cache
virtual Painter & image(int x, int y,
virtual void image(int x, int y,
int w, int h,
lyx::graphics::Image const & image);
/// draw a string at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
std::string const & str, LyXFont const & f);
/** Draw a string at position x, y (y is the baseline)
* This is just for fast drawing
*/
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char const * str, size_t l,
LyXFont const & f);
/// draw a char at position x, y (y is the baseline)
virtual Painter & text(int x, int y,
virtual void text(int x, int y,
char c, LyXFont const & f);
/// draw a wide string at position x, y
Painter & text(int x, int y,
void text(int x, int y,
XChar2b const * str, size_t l,
LyXFont const & f);

View File

@ -586,6 +586,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
dispatch_buffer.erase();
selection_possible = false;
bool update = true;
// We cannot use this function here
if (!getStatus(cmd).enabled()) {
lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
@ -1356,17 +1358,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
}
default: {
update = false;
DispatchResult res = view()->cursor().dispatch(cmd);
if (!res.dispatched());
view()->dispatch(cmd);
if (res.dispatched())
update |= res.update();
else
update |= view()->dispatch(cmd);
break;
}
}
if (view()->available()) {
view()->fitCursor();
if (view()->fitCursor() || update)
view()->update();
view()->cursor().updatePos();
// if we executed a mutating lfun, mark the buffer as dirty
if (getStatus(cmd).enabled()
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)

View File

@ -144,7 +144,7 @@ void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
LyXFont font = p.base.font;
font.setColor(LColor::math);
PainterInfo pi(p.base.bv);
PainterInfo pi(p.base.bv, p.pain);
pi.base.style = LM_ST_TEXT;
pi.base.font = font;

View File

@ -43,8 +43,8 @@ MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
PainterInfo::PainterInfo(BufferView * bv)
: pain(bv->painter())
PainterInfo::PainterInfo(BufferView * bv, Painter & pa)
: pain(pa)
{
base.bv = bv;
}

View File

@ -76,7 +76,7 @@ struct MetricsInfo {
//
struct PainterInfo {
///
explicit PainterInfo(BufferView * bv);
PainterInfo(BufferView * bv, Painter & pain);
///
void draw(int x, int y, char c);

View File

@ -32,6 +32,7 @@
#include "vspace.h"
#include "frontends/font_metrics.h"
#include "frontends/nullpainter.h"
#include "frontends/Painter.h"
#include "insets/insettext.h"
@ -57,8 +58,8 @@ namespace {
class RowPainter {
public:
/// initialise and run painter
RowPainter(BufferView const & bv, LyXText const & text,
par_type pit, RowList::iterator rit, int xo, int yo);
RowPainter(BufferView const & bv, Painter & pain, LyXText const & text,
par_type pit, RowList::iterator rit, int y);
private:
// paint various parts
void paintBackground();
@ -118,10 +119,11 @@ private:
};
RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
par_type pit, RowList::iterator rit, int xo, int yo)
: bv_(bv), pain_(bv_.painter()), text_(text), pars_(text.paragraphs()),
rit_(rit), row_(*rit), pit_(pit), xo_(xo), yo_(yo), width_(text_.width())
RowPainter::RowPainter(BufferView const & bv, Painter & pain,
LyXText const & text, par_type pit, RowList::iterator rit, int y)
: bv_(bv), pain_(pain), text_(text), pars_(text.paragraphs()),
rit_(rit), row_(*rit), pit_(pit),
xo_(text_.xo_), yo_(y), width_(text_.width())
{
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo
// << " pit->y: " << pit_->y
@ -196,7 +198,7 @@ void RowPainter::paintInset(pos_type const pos)
{
InsetBase const * inset = pars_[pit_].getInset(pos);
BOOST_ASSERT(inset);
PainterInfo pi(const_cast<BufferView *>(&bv_));
PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
pi.base.font = getFont(pos);
inset->drawSelection(pi, int(x_), yo_ + row_.baseline());
inset->draw(pi, int(x_), yo_ + row_.baseline());
@ -396,8 +398,6 @@ void RowPainter::paintSelection()
// the current selection
LCursor const & cur = bv_.cursor();
int const startx = text_.cursorX(cur.selBegin());
int const endx = text_.cursorX(cur.selEnd());
int const starty = text_.cursorY(cur.selBegin());
int const endy = text_.cursorY(cur.selEnd());
par_type startpit = cur.selBegin().par();
@ -414,14 +414,18 @@ void RowPainter::paintSelection()
if (text_.bidi.same_direction()) {
if (sel_on_one_row) {
int const startx = text_.cursorX(cur.selBegin());
int const endx = text_.cursorX(cur.selEnd());
int const x1 = is_rtl ? endx : startx;
int const x2 = is_rtl ? startx : endx;
pain_.fillRectangle(x1, yo_, x2 - x1, h, LColor::selection);
} else if (sel_starts_here) {
int const startx = text_.cursorX(cur.selBegin());
int const x1 = is_rtl ? int(xo_) : startx;
int const x2 = is_rtl ? startx : int(xo_) + width_;
pain_.fillRectangle(x1, yo_, x2 - x1, h, LColor::selection);
} else if (sel_ends_here) {
int const endx = text_.cursorX(cur.selEnd());
int const x1 = is_rtl ? endx : int(xo_);
int const x2 = is_rtl ? int(xo_) + width_ : endx;
pain_.fillRectangle(x1, yo_, x2 - x1, h, LColor::selection);
@ -844,43 +848,53 @@ void RowPainter::paintText()
}
int paintPars(BufferView const & bv, LyXText const & text,
par_type pit, int xo, int yo, int y)
int paintPars(BufferView const & bv, Painter & pain,
LyXText const & text, par_type pit, par_type end)
{
//lyxerr << " paintRows: pit: " << &*pit << endl;
int const y2 = bv.painter().paperHeight();
y -= bv.top_y();
ParagraphList & pars = text.paragraphs();
for ( ; pit != par_type(pars.size()); ++pit) {
int y = pars[pit].y + text.yo_ - bv.top_y();
int const y2 = pain.paperHeight();
for (; pit != end; ++pit) {
RowList::iterator row = pars[pit].rows.begin();
RowList::iterator rend = pars[pit].rows.end();
for ( ; row != rend; ++row) {
RowPainter(bv, text, pit, row, xo, y + yo);
RowPainter(bv, pain, text, pit, row, y);
y += row->height();
}
if (yo + y >= y2)
if (y >= y2)
break;
}
}
return y;
}
} // namespace anon
void refreshPar(BufferView const & bv, LyXText const & text, par_type pit)
{
static NullPainter nop;
paintPars(bv, nop, text, pit, pit + 1);
}
int paintText(BufferView const & bv)
{
par_type pit;
bv.text()->updateParPositions();
bv.text()->getRowNearY(bv.top_y(), pit);
par_type pit, end;
getParsInRange(bv.text()->paragraphs(), bv.top_y(),
bv.top_y() + bv.workHeight(), pit, end);
//lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl;
return paintPars(bv, *bv.text(), pit, 0, 0, bv.text()->paragraphs()[pit].y);
return paintPars(bv, bv.painter(), *bv.text(), pit, end);
}
void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo)
void paintTextInset(LyXText const & text, PainterInfo & pi)
{
paintPars(*pi.base.bv, text, 0, xo, yo, 0);
paintPars(*pi.base.bv, pi.pain, text, 0, text.paragraphs().size());
}

View File

@ -13,6 +13,8 @@
#ifndef ROWPAINTER_H
#define ROWPAINTER_H
#include "support/types.h"
class LyXText;
class BufferView;
class PainterInfo;
@ -20,7 +22,11 @@ class PainterInfo;
/// paint the rows of the main text, return last drawn y value
int paintText(BufferView const & bv);
/// refresh a par of the main text
void refreshPar(BufferView const & bv, LyXText const & text,
lyx::par_type pit);
/// paint the rows of a text inset
void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y);
void paintTextInset(LyXText const & text, PainterInfo & pi);
#endif // ROWPAINTER_H

View File

@ -1863,7 +1863,7 @@ void LyXText::draw(PainterInfo & pi, int x, int y) const
{
xo_ = x;
yo_ = y;
paintTextInset(*this, pi, x, y);
paintTextInset(*this, pi);
}