mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
mouse selection patch
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8100 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
13dfdf70fc
commit
025cb611e3
@ -896,8 +896,28 @@ namespace {
|
||||
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: {
|
||||
@ -925,7 +945,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
|
||||
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);
|
||||
@ -958,6 +978,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
|
||||
<< " 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();
|
||||
|
@ -1,3 +1,13 @@
|
||||
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
|
||||
|
@ -1,3 +1,9 @@
|
||||
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>
|
||||
|
||||
|
@ -185,7 +185,7 @@ InsetOld::EDITABLE InsetCollapsable::editable() const
|
||||
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;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
|
||||
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);
|
||||
|
||||
@ -311,7 +311,7 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
|
||||
return DispatchResult(true, true);
|
||||
|
||||
default:
|
||||
return inset.dispatch(cmd);
|
||||
return inset.dispatch(adjustCommand(cmd));
|
||||
}
|
||||
lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
|
||||
}
|
||||
|
@ -114,11 +114,8 @@ void InsetText::init()
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -289,7 +286,6 @@ void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/)
|
||||
if (!text_.selection.set())
|
||||
text_.selection.cursor = text_.cursor;
|
||||
|
||||
// bv->fitCursor();
|
||||
bv->owner()->view_state_changed();
|
||||
bv->owner()->updateMenubar();
|
||||
bv->owner()->updateToolbar();
|
||||
@ -320,49 +316,6 @@ void InsetText::sanitizeEmptyText(BufferView * bv)
|
||||
|
||||
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)
|
||||
{
|
||||
@ -403,41 +356,28 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
|
||||
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);
|
||||
@ -513,7 +453,6 @@ bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
|
||||
{
|
||||
inset->setOwner(this);
|
||||
text_.insertInset(inset);
|
||||
// bv->fitCursor();
|
||||
updateLocal(bv, true);
|
||||
return true;
|
||||
}
|
||||
@ -580,7 +519,6 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
|
||||
if (selectall)
|
||||
text_.clearSelection();
|
||||
|
||||
// bv->fitCursor();
|
||||
updateLocal(bv, true);
|
||||
}
|
||||
|
||||
|
@ -177,12 +177,6 @@ protected:
|
||||
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 *);
|
||||
@ -217,15 +211,10 @@ private:
|
||||
///
|
||||
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_;
|
||||
|
@ -612,8 +612,6 @@ Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void getParsInRange(ParagraphList & pl,
|
||||
int ystart, int yend,
|
||||
ParagraphList::iterator & beg,
|
||||
|
@ -75,7 +75,7 @@ ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset);
|
||||
/// 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,
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "rowpainter.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "cursor.h"
|
||||
#include "debug.h"
|
||||
#include "bufferparams.h"
|
||||
#include "BufferView.h"
|
||||
@ -389,11 +390,12 @@ void RowPainter::paintSelection()
|
||||
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;
|
||||
@ -411,7 +413,8 @@ void RowPainter::paintSelection()
|
||||
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;
|
||||
@ -945,7 +948,7 @@ void RowPainter::paint()
|
||||
paintBackground();
|
||||
|
||||
// paint the selection background
|
||||
if (text_.selection.set())
|
||||
if (text_.selection.set() && &text_ == bv_.cursor().innerText())
|
||||
paintSelection();
|
||||
|
||||
// vertical lines for appendix
|
||||
|
@ -1031,6 +1031,7 @@ void LyXText::insertInset(InsetOld * inset)
|
||||
// does not return the inset!
|
||||
if (isHighlyEditableInset(inset))
|
||||
cursorLeft(true);
|
||||
|
||||
unFreezeUndo();
|
||||
}
|
||||
|
||||
|
69
src/text3.C
69
src/text3.C
@ -1289,55 +1289,27 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1369,24 +1341,21 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
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;
|
||||
@ -1414,7 +1383,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
return DispatchResult(true, false);
|
||||
|
||||
selection_possible = false;
|
||||
|
||||
|
||||
if (cmd.button() == mouse_button::button2)
|
||||
break;
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "textcursor.h"
|
||||
#include "paragraph.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -37,9 +38,9 @@ void TextCursor::setSelection()
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user