git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5126 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-27 16:16:17 +00:00
parent a1e77e762d
commit b9d544874e
2 changed files with 70 additions and 77 deletions

View File

@ -40,6 +40,7 @@
#include "ParagraphParameters.h"
#include "undo_funcs.h"
#include "funcrequest.h"
#include "box.h"
#include "insets/insetbib.h"
#include "insets/insettext.h"
@ -110,6 +111,72 @@ boost::signals::connection kpresscon;
boost::signals::connection selectioncon;
boost::signals::connection lostcon;
/**
* Return the on-screen dimensions of the inset at the cursor.
* Pre-condition: the cursor must be at an inset.
*/
Box insetDimensions(BufferView * bv, LyXText const & text,
LyXCursor const & cursor)
{
Paragraph /*const*/ & par = *cursor.par();
pos_type const pos = cursor.pos();
lyx::Assert(par.getInset(pos));
Inset const & inset(*par.getInset(pos));
LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
int const width = inset.width(bv, font);
int const inset_x = font.isVisibleRightToLeft()
? (cursor.ix() - width) : cursor.ix();
return Box(
inset_x + inset.scroll(),
inset_x + width,
cursor.iy() - inset.ascent(bv, font),
cursor.iy() + inset.descent(bv, font));
}
/**
* check if the given co-ordinates are inside an inset at the
* given cursor, if one exists. If so, the inset is returned,
* and the co-ordinates are made relative. Otherwise, 0 is returned.
*/
Inset * checkInset(BufferView * bv, LyXText const & text,
LyXCursor const & cursor, int & x, int & y)
{
pos_type const pos = cursor.pos();
Paragraph /*const*/ & par(*cursor.par());
if (pos >= par.size() || !par.isInset(pos)) {
return 0;
}
Inset /*const*/ * inset = par.getInset(pos);
if (!isEditableInset(inset))
return 0;
Box b = insetDimensions(bv, text, cursor);
if (!b.contained(x, y)) {
lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
<< " box " << b << endl;
return 0;
}
text.setCursor(bv, &par, pos, true);
x -= b.x1;
// The origin of an inset is on the baseline
y -= text.cursor.iy();
return inset;
}
} // anon namespace
@ -801,63 +868,6 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
}
Box BufferView::Pimpl::insetDimensions(LyXText const & text,
LyXCursor const & cursor) const
{
Paragraph /*const*/ & par = *cursor.par();
pos_type const pos = cursor.pos();
lyx::Assert(par.getInset(pos));
Inset const & inset(*par.getInset(pos));
LyXFont const & font = text.getFont(buffer_, &par, pos);
int const width = inset.width(bv_, font);
int const inset_x = font.isVisibleRightToLeft()
? (cursor.ix() - width) : cursor.ix();
return Box(
inset_x + inset.scroll(),
inset_x + width,
cursor.iy() - inset.ascent(bv_, font),
cursor.iy() + inset.descent(bv_, font));
}
Inset * BufferView::Pimpl::checkInset(LyXText const & text,
LyXCursor const & cursor,
int & x, int & y) const
{
pos_type const pos(cursor.pos());
Paragraph /*const*/ & par(*cursor.par());
if (pos >= par.size() || !par.isInset(pos)) {
return 0;
}
Inset /*const*/ * inset = par.getInset(pos);
if (!isEditableInset(inset)) {
return 0;
}
Box b(insetDimensions(text, cursor));
if (!b.contained(x, y)) {
lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
<< " box " << b << endl;
return 0;
}
text.setCursor(bv_, &par, pos, true);
x -= b.x1;
// The origin of an inset is on the baseline
y -= text.cursor.iy();
return inset;
}
Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
@ -867,7 +877,7 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
LyXCursor cursor;
text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
Inset * inset = checkInset(*text, cursor, x, y_tmp);
Inset * inset = checkInset(bv_, *text, cursor, x, y_tmp);
if (inset) {
y = y_tmp;
@ -882,7 +892,7 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
// move back one
text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
inset = checkInset(*text, cursor, x, y_tmp);
inset = checkInset(bv_, *text, cursor, x, y_tmp);
if (inset) {
y = y_tmp;
}

View File

@ -15,8 +15,6 @@
#include "frontends/key_state.h"
#include "frontends/mouse_state.h"
#include "frontends/LyXKeySym.h"
#include "box.h"
#include "insets/insetspecialchar.h"
#include "support/types.h"
#include <boost/scoped_ptr.hpp>
@ -73,8 +71,7 @@ struct BufferView::Pimpl : public boost::signals::trackable {
/// wheel mouse scroll
int scroll(long time);
///
void workAreaKeyPress(LyXKeySymPtr key,
key_modifier::state state);
void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
///
void workAreaMotionNotify(int x, int y, mouse_button::state state);
///
@ -122,22 +119,8 @@ struct BufferView::Pimpl : public boost::signals::trackable {
///
bool dispatch(FuncRequest const & ev);
private:
/**
* Return the on-screen dimensions of the inset at the cursor.
* Pre-condition: the cursor must be at an inset.
*/
Box insetDimensions(LyXText const & text, LyXCursor const & cursor) const;
/**
* check if the given co-ordinates are inside an inset at the
* given cursor, if one exists. If so, the inset is returned,
* and the co-ordinates are made relative. Otherwise, 0 is returned.
*/
Inset * checkInset(LyXText const & text, LyXCursor const & cursor,
int & x, int & y) const;
///
friend class BufferView;
///
void hfill();
///
BufferView * bv_;