}
-Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y)
-{
- return pimpl_->checkInsetHit(text, x, y);
-}
-
-
void BufferView::redoCurrentBuffer()
{
pimpl_->redoCurrentBuffer();
///
void updateScrollbar();
///
- Inset * checkInsetHit(LyXText *, int & x, int & y);
- ///
void redoCurrentBuffer();
///
bool available() const;
#include "ParagraphParameters.h"
#include "undo_funcs.h"
#include "funcrequest.h"
-#include "box.h"
#include "insets/insetbib.h"
#include "insets/insettext.h"
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
}
-
-Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
-{
- int y_tmp = y + text->first_y;
-
- LyXCursor cursor;
- text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
-
- Inset * inset = checkInset(bv_, *text, cursor, x, y_tmp);
-
- if (inset) {
- y = y_tmp;
- return inset;
- }
-
- // look at previous position
- if (cursor.pos() == 0) {
- return 0;
- }
-
- // move back one
- text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
-
- inset = checkInset(bv_, *text, cursor, x, y_tmp);
- if (inset) {
- y = y_tmp;
- }
- return inset;
-}
-
-
void BufferView::Pimpl::workAreaResize()
{
static int work_area_width;
void updateScrollbar();
///
void scrollDocView(int value);
- /**
- * Returns an inset if inset was hit, or 0 if not.
- *
- * If hit, the coordinates are changed relative to the inset.
- */
- Inset * checkInsetHit(LyXText *, int & x, int & y);
/// wheel mouse scroll
int scroll(long time);
///
int tmp_x = cmd.x - drawTextXOffset;
int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
- Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
+ Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
hideInsetCursor(bv);
if (the_locking_inset) {
int tmp_x = cmd.x - drawTextXOffset;
int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
- Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
+ Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
bool ret = false;
if (inset) {
if (isHighlyEditableInset(inset))
x -= drawTextXOffset;
int dummyx = x;
int dummyy = y + insetAscent;
- Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy);
+ Inset * inset = getLyXText(bv)->checkInsetHit(bv, dummyx, dummyy);
// we only do the edit() call if the inset was hit by the mouse
// or if it is a highly editable inset. So we should call this
// function from our own edit with button < 0.
void updateCounters(BufferView *) const;
///
void update(BufferView * bv, bool changed = true);
+ /**
+ * Returns an inset if inset was hit, or 0 if not.
+ * If hit, the coordinates are changed relative to the inset.
+ */
+ Inset * checkInsetHit(BufferView * bv, int & x, int & y) const;
+
private:
///
void setCounter(Buffer const *, Paragraph * par) const;
int y1 = cursor.iy() - first_y;
int y2 = y1;
y -= first_y;
- Inset * inset_hit =
- bview->checkInsetHit(const_cast<LyXText *>(this), x, y1);
+ Inset * inset_hit = checkInsetHit(bview, x, y1);
if (inset_hit && isHighlyEditableInset(inset_hit)) {
inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none);
}
int y1 = cursor.iy() - first_y;
int y2 = y1;
y -= first_y;
- Inset * inset_hit =
- bview->checkInsetHit(const_cast<LyXText *>(this), x, y1);
+ Inset * inset_hit = checkInsetHit(bview, x, y1);
if (inset_hit && isHighlyEditableInset(inset_hit)) {
inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none);
}
#include "gettext.h"
#include "factory.h"
#include "intl.h"
+#include "box.h"
#include "language.h"
#include "support/lstrings.h"
#include "frontends/LyXView.h"
bv->owner()->view_state_changed();
}
+ // 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, int & x, int & y)
+ {
+ LyXCursor const & cursor = text.cursor;
+ lyx::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;
+
+ // get inset dimensions
+ lyx::Assert(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();
+
+ Box b(
+ inset_x + inset->scroll(),
+ inset_x + width,
+ cursor.iy() - inset->ascent(bv, font),
+ cursor.iy() + inset->descent(bv, font));
+
+ 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
+
+
+Inset * LyXText::checkInsetHit(BufferView * bv, int & x, int & y) const
+{
+ int y_tmp = y + first_y;
+
+ LyXCursor cursor;
+ setCursorFromCoordinates(bv, cursor, x, y_tmp);
+
+ Inset * inset = checkInset(bv, *this, x, y_tmp);
+ if (inset) {
+ y = y_tmp;
+ return inset;
+ }
+
+ // look at previous position
+ if (cursor.pos() == 0)
+ return 0;
+
+ // move back one
+ setCursor(bv, cursor, cursor.par(), cursor.pos() - 1, true);
+
+ inset = checkInset(bv, *this, x, y_tmp);
+ if (inset)
+ y = y_tmp;
+ return inset;
}
#endif
// This is to allow jumping over large insets
if (cursorrow == bv->text->cursor.row()) {
- if (cmd.y >= int(bv->workarea().workHeight())) {
+ if (cmd.y >= int(bv->workarea().workHeight()))
bv->text->cursorDown(bv, false);
- } else if (cmd.y < 0) {
+ else if (cmd.y < 0)
bv->text->cursorUp(bv, false);
- }
}
+ // Maybe an empty line was deleted
if (!bv->text->selection.set())
- bv->update(bv->text, BufferView::UPDATE); // Maybe an empty line was deleted
-
+ bv->update(bv->text, BufferView::UPDATE);
bv->text->setSelection(bv);
bv->screen().toggleToggle(bv->text, bv);
bv->fitCursor();
int x = cmd.x;
int y = cmd.y;
- Inset * inset_hit = bv->checkInsetHit(bv->text, x, y);
+ Inset * inset_hit = bv->text->checkInsetHit(bv, x, y);
// Middle button press pastes if we have a selection
// We do this here as if the selection was inside an inset
// inset, inset_hit is 0, and inset_x == x, inset_y == y.
int x = cmd.x;
int y = cmd.y;
- Inset * inset_hit = bv->checkInsetHit(bv->text, x, y);
+ Inset * inset_hit = bv->text->checkInsetHit(bv, x, y);
if (bv->theLockingInset()) {
// We are in inset locking mode.