bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
{
switch (cmd.action) {
+ case LFUN_MOUSE_MOTION: {
+ FuncRequest cmd1(cmd, bv_);
+ UpdatableInset * inset = bv_->cursor().innerInset();
+ DispatchResult res;
+ if (inset) {
+ cmd1.x -= inset->x();
+ cmd1.y -= inset->y();
+ res = inset->dispatch(cmd1);
+ } else {
+ cmd1.y += bv_->top_y();
+ res = bv_->cursor().innerText()->dispatch(cmd1);
+ }
+
+ if (bv_->fitCursor() || res.update()) {
+ bv_->update();
+ bv_->cursor().updatePos();
+ }
+
+ return true;
+ }
+
case LFUN_MOUSE_PRESS:
- case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_RELEASE:
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE: {
if (inset) {
FuncRequest cmd2 = cmd1;
lyxerr << "dispatching action " << cmd2.action
- << " to inset " << inset << endl;
+ << " to inset " << inset << endl;
cmd2.x -= inset->x();
cmd2.y -= inset->y();
res = inset->dispatch(cmd2);
<< " to surrounding LyXText "
<< theTempCursor.innerText() << endl;
bv_->cursor() = theTempCursor;
+ cmd1.y += bv_->top_y();
res = bv_->cursor().innerText()->dispatch(cmd1);
if (bv_->fitCursor() || res.update())
bv_->update();
+2003-11-17 Alfredo Braunstein <abraunst@lyx.org>
+
+ * BufferView_pimpl.C: send LFUN_MOUSE_MOTION to the cursor
+ * paragraph_funcs.[Ch]: correct comment
+ * rowpainter.C: do not paint selections away from bv->cursor()
+ Fix a long standing selection painting bug.
+ * text3.C: generalize mouse-selection code to LyXTexts other that
+ top one
+ * textcursor.C: do not use y coords if we can use par offsets
+
2003-11-17 Alfredo Braunstein <abraunst@lyx.org>
* lyxfunc.C (dispatch): add a missing LCursor::updatePos (fix
+2003-11-17 Alfredo Braunstein <abraunst@lyx.org>
+
+ * insetcollapsable.C:
+ * insettext.C:
+ * insettext.h: hand on MOUSE_* events to the LyXText when appropriate
+ remove mouse_x mouse_y etc.
2003-11-17 André Pönitz <poenitz@gmx.net>
FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd)
{
FuncRequest cmd1 = cmd;
- cmd1.y = ascent() + cmd.y - height_collapsed() - inset.ascent();
+ cmd1.y += ascent() - height_collapsed();
return cmd1;
}
return DispatchResult(true, true);
case LFUN_MOUSE_MOTION:
- if (!collapsed_ && cmd.y > button_dim.y2)
+ if (!collapsed_)
inset.dispatch(adjustCommand(cmd));
return DispatchResult(true, true);
return DispatchResult(true, true);
default:
- return inset.dispatch(cmd);
+ return inset.dispatch(adjustCommand(cmd));
}
lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
}
for (; pit != end; ++pit)
pit->setInsetOwner(this);
text_.paragraphs_ = ¶graphs;
- no_selection = true;
old_par = -1;
in_insetAllowed = false;
- mouse_x = 0;
- mouse_y = 0;
}
if (!text_.selection.set())
text_.selection.cursor = text_.cursor;
-// bv->fitCursor();
bv->owner()->view_state_changed();
bv->owner()->updateMenubar();
bv->owner()->updateToolbar();
extern LCursor theTempCursor;
-void InsetText::lfunMousePress(FuncRequest const & cmd)
-{
- lyxerr << "InsetText::lfunMousePress, inset: " << this << endl;
- no_selection = true;
-
- // use this to check mouse motion for selection
- mouse_x = cmd.x;
- mouse_y = cmd.y;
-
- BufferView * bv = cmd.view();
- no_selection = false;
- text_.clearSelection();
-
- // set global cursor
- bv->cursor() = theTempCursor;
- lyxerr << "new global cursor: \n" << bv->cursor() << endl;
- text_.setCursorFromCoordinates(cmd.x, cmd.y);
-}
-
-
-void InsetText::lfunMouseMotion(FuncRequest const & cmd)
-{
- lyxerr << "InsetText::lfunMouseMotion, inset: " << this << endl;
- if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
- return;
-
- BufferView * bv = cmd.view();
- LyXCursor cur = text_.cursor;
- text_.setCursorFromCoordinates(cmd.x, cmd.y + dim_.asc);
- bv->x_target(text_.cursor.x());
- if (cur != text_.cursor) {
- text_.setSelection();
- updateLocal(bv, false);
- }
-}
-
-
-void InsetText::lfunMouseRelease(FuncRequest const &)
-{
- lyxerr << "InsetText::lfunMouseRelease, inset: " << this << endl;
- no_selection = true;
-}
-
void InsetText::edit(BufferView * bv, bool left)
{
idx_type &, pos_type &)
{
lyxerr << "InsetText::priv_dispatch (begin), act: "
- << cmd.action << " " << endl;
+ << cmd.action << " " << endl;
+
BufferView * bv = cmd.view();
setViewCache(bv);
+
DispatchResult result;
result.dispatched(true);
bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1;
- if (cmd.action != LFUN_MOUSE_PRESS
- && cmd.action != LFUN_MOUSE_MOTION
- && cmd.action != LFUN_MOUSE_RELEASE)
- no_selection = false;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- lfunMousePress(cmd);
- result = DispatchResult(true, true);
- break;
-
- case LFUN_MOUSE_MOTION:
- lfunMouseMotion(cmd);
- result = DispatchResult(true, true);
- break;
-
- case LFUN_MOUSE_RELEASE:
- lfunMouseRelease(cmd);
- result = DispatchResult(true, true);
- break;
-
+ bv->cursor() = theTempCursor;
+ // fall through
default:
result = text_.dispatch(cmd);
break;
}
- /// If the action has deleted all text in the inset, we need to change the
- // language to the language of the surronding text.
+ // If the action has deleted all text in the inset, we need
+ // to change the language to the language of the surronding
+ // text.
if (!was_empty && paragraphs.begin()->empty() &&
paragraphs.size() == 1) {
LyXFont font(LyXFont::ALL_IGNORE);
{
inset->setOwner(this);
text_.insertInset(inset);
-// bv->fitCursor();
updateLocal(bv, true);
return true;
}
if (selectall)
text_.clearSelection();
-// bv->fitCursor();
updateLocal(bv, true);
}
private:
///
void init();
- ///
- void lfunMousePress(FuncRequest const &);
- ///
- void lfunMouseMotion(FuncRequest const &);
- ///
- void lfunMouseRelease(FuncRequest const &);
// If the inset is empty set the language of the current font to the
// language to the surronding text (if different).
void sanitizeEmptyText(BufferView *);
///
mutable lyx::paroffset_type old_par;
- ///
- // to remember old painted frame dimensions to clear it on the right spot!
- ///
+ /** to remember old painted frame dimensions to clear it on
+ * the right spot!
+ */
mutable bool in_insetAllowed;
- ///
- // these are used to check for mouse movement in Motion selection code
- ///
- int mouse_x;
- int mouse_y;
public:
///
mutable LyXText text_;
}
-
-
void getParsInRange(ParagraphList & pl,
int ystart, int yend,
ParagraphList::iterator & beg,
/// find owning paragraph containing an inset
Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset);
-/// stretch range beg,end to the minimum containing ystart, yend
+/// return the range of pars [beg, end[ owning the range of y [ystart, yend]
void getParsInRange(ParagraphList & pl,
int ystart, int yend,
ParagraphList::iterator & beg,
#include "rowpainter.h"
#include "buffer.h"
+#include "cursor.h"
#include "debug.h"
#include "bufferparams.h"
#include "BufferView.h"
RowList::iterator endrow = endpit->getRow(text_.selection.end.pos());
int const h = row_.height();
+ int const row_y = pit_->y + row_.y_offset();
+
if (text_.bidi.same_direction()) {
int x;
int y = yo_;
int w;
-
if (startrow == rit_ && endrow == rit_) {
if (startx < endx) {
x = int(xo_) + startx;
int const x = is_rtl ? int(xo_ + endx) : int(xo_);
int const w = is_rtl ? (width_ - endx) : endx;
pain_.fillRectangle(x, y, w, h, LColor::selection);
- } else if (y_ > starty && y_ < endy) {
+ } else if (row_y > starty && row_y < endy) {
+
pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
}
return;
paintBackground();
// paint the selection background
- if (text_.selection.set())
+ if (text_.selection.set() && &text_ == bv_.cursor().innerText())
paintSelection();
// vertical lines for appendix
// does not return the inset!
if (isHighlyEditableInset(inset))
cursorLeft(true);
+
unFreezeUndo();
}
if (!bv->buffer())
break;
-
- // Check for inset locking
-#ifdef LOCK
- if (bv->innerInset()) {
- InsetOld * tli = bv->innerInset();
- LyXCursor cursor = bv->text->cursor;
- LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
- int width = tli->width();
- int inset_x = font.isVisibleRightToLeft()
- ? cursor.x() - width : cursor.x();
- int start_x = inset_x + tli->scroll();
- FuncRequest cmd1 = cmd;
- cmd1.x = cmd.x - start_x;
- cmd1.y = cmd.y - cursor.y() + bv->top_y();
- tli->dispatch(cmd1);
- break;
- }
-#endif
-
- // The test for not selection possible is needed, that only motion
- // events are used, where the bottom press event was on
- // the drawing area too
+ // The test for not selection possible is needed, that
+ // only motion events are used, where the bottom press
+ // event was on the drawing area too
if (!selection_possible) {
- lyxerr[Debug::ACTION]
- << "BufferView::Pimpl::Dispatch: no selection possible\n";
+ lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
+ "Dispatch: no selection possible\n";
break;
}
+ RowList::iterator cursorrow = cursorRow();
+
+ setCursorFromCoordinates(cmd.x, cmd.y);
- RowList::iterator cursorrow = bv->text->cursorRow();
- bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
- #if 0
- // sorry for this but I have a strange error that the y value jumps at
- // a certain point. This seems like an error in my xforms library or
- // in some other local environment, but I would like to leave this here
- // for the moment until I can remove this (Jug 20020418)
- if (y_before < bv->text->cursor.y())
- lyxerr << y_before << ':'
- << bv->text->cursor.y() << endl;
- #endif
// This is to allow jumping over large insets
- if (cursorrow == cursorRow()) {
- if (cmd.y >= bv->workHeight())
+ // FIXME: shouldn't be top-text-specific
+ if (cursorrow == cursorRow() && !in_inset_) {
+ if (cmd.y - bv->top_y() >= bv->workHeight())
cursorDown(false);
- else if (cmd.y < 0)
+ else if (cmd.y - bv->top_y() < 0)
cursorUp(false);
}
-
- bv->text->setSelection();
-// bv->update();
+ setSelection();
break;
}
paste_internally = true;
}
- int const screen_first = bv->top_y();
selection_possible = true;
// Clear the selection
- bv->text->clearSelection();
- bv->update();
- bv->updateScrollbar();
-
+ clearSelection();
+
// Right click on a footnote flag opens float menu
if (cmd.button() == mouse_button::button3) {
selection_possible = false;
break;
}
- bv->text->setCursorFromCoordinates(cmd.x, cmd.y + screen_first);
+ setCursorFromCoordinates(cmd.x, cmd.y);
+ selection.cursor = cursor;
finishUndo();
- bv->text->selection.cursor = bv->text->cursor;
- bv->x_target(bv->text->cursor.x());
+ bv->x_target(cursor.x());
if (bv->fitCursor())
selection_possible = false;
return DispatchResult(true, false);
selection_possible = false;
-
+
if (cmd.button() == mouse_button::button2)
break;
#include "textcursor.h"
#include "paragraph.h"
#include "ParagraphList_fwd.h"
+#include "debug.h"
#include <string>
selection.end = selection.cursor;
selection.start = cursor;
}
- else if (selection.cursor.y() < cursor.y() ||
- (selection.cursor.y() == cursor.y()
- && selection.cursor.x() < cursor.x())) {
+ else if (selection.cursor.par() < cursor.par() ||
+ (selection.cursor.par() == cursor.par()
+ && selection.cursor.pos() < cursor.pos())) {
selection.end = cursor;
selection.start = selection.cursor;
}