From b0cffd9fc0288a639a7271837ae8efb319d704be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 10 Nov 2003 09:06:48 +0000 Subject: [PATCH] The deed is done. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8064 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 129 +----- src/BufferView.h | 27 +- src/BufferView_pimpl.C | 280 +++++------- src/BufferView_pimpl.h | 6 +- src/ChangeLog | 26 ++ src/LyXAction.C | 5 +- src/Makefile.am | 4 +- src/bufferview_funcs.C | 165 +------ src/bufferview_funcs.h | 43 +- src/cursor.C | 168 +++++--- src/cursor.h | 37 +- src/dispatchresult.h | 2 + src/factory.C | 21 +- src/frontends/ChangeLog | 5 + src/frontends/screen.C | 34 +- src/funcrequest.C | 18 + src/funcrequest.h | 9 +- src/insets/ChangeLog | 14 + src/insets/inset.C | 9 - src/insets/inset.h | 10 - src/insets/insetbox.C | 74 ++-- src/insets/insetbox.h | 2 + src/insets/insetcollapsable.C | 243 +++++------ src/insets/insetcollapsable.h | 100 +---- src/insets/insetert.C | 122 ++---- src/insets/insetfloat.C | 17 +- src/insets/insetminipage.C | 5 - src/insets/insettabular.C | 779 +++++++++------------------------- src/insets/insettabular.h | 59 +-- src/insets/insettext.C | 621 ++++----------------------- src/insets/insettext.h | 45 +- src/insets/insetwrap.C | 15 +- src/insets/updatableinset.C | 65 +-- src/insets/updatableinset.h | 48 +-- src/iterators.C | 29 +- src/lfuns.h | 4 + src/lyx_cb.C | 15 +- src/lyxfind.C | 33 +- src/lyxfunc.C | 337 ++------------- src/lyxtext.h | 11 +- src/mathed/ChangeLog | 6 + src/mathed/formula.C | 22 +- src/mathed/formulabase.C | 34 +- src/text.C | 15 +- src/text2.C | 21 +- src/text3.C | 484 ++++++++++++++------- src/undo.C | 8 - 47 files changed, 1312 insertions(+), 2914 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 8f89513cb4..747768eb14 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -19,6 +19,7 @@ #include "buffer.h" #include "bufferlist.h" #include "BufferView_pimpl.h" +#include "debug.h" #include "funcrequest.h" #include "gettext.h" #include "iterators.h" @@ -169,12 +170,6 @@ Change const BufferView::getCurrentChange() } -void BufferView::beforeChange(LyXText * text) -{ - pimpl_->beforeChange(text); -} - - void BufferView::savePosition(unsigned int i) { pimpl_->savePosition(i); @@ -199,12 +194,6 @@ void BufferView::switchKeyMap() } -void BufferView::insetUnlock() -{ - pimpl_->insetUnlock(); -} - - int BufferView::workWidth() const { return pimpl_->workarea().workWidth(); @@ -267,12 +256,10 @@ bool BufferView::insertLyXFile(string const & filen) string const fname = MakeAbsPath(filen); - beforeChange(text); - + text->clearSelection(); text->breakParagraph(buffer()->paragraphs()); bool res = buffer()->readFile(fname, text->cursorPar()); - resize(); return res; } @@ -322,7 +309,7 @@ void BufferView::gotoLabel(string const & label) vector labels; it->getLabelList(*buffer(), labels); if (find(labels.begin(),labels.end(),label) != labels.end()) { - beforeChange(text); + text->clearSelection(); text->setCursor( std::distance(text->ownerParagraphs().begin(), it.getPar()), it.getPos()); @@ -340,7 +327,7 @@ void BufferView::undo() return; owner()->message(_("Undo")); - beforeChange(text); + text->clearSelection(); if (!textUndo(this)) owner()->message(_("No further undo information")); update(); @@ -354,7 +341,7 @@ void BufferView::redo() return; owner()->message(_("Redo")); - beforeChange(text); + text->clearSelection(); if (!textRedo(this)) owner()->message(_("No further redo information")); update(); @@ -382,51 +369,16 @@ void BufferView::replaceWord(string const & replacestring) } -bool BufferView::lockInset(UpdatableInset * inset) -{ - if (!inset) - return false; - - // don't relock if we're already locked - if (theLockingInset() == inset) - return true; - - if (theLockingInset()) - return theLockingInset()->lockInsetInInset(this, inset); - - // first check if it's the inset under the cursor we want lock - // should be most of the time - if (text->cursor.pos() < text->cursorPar()->size() - && text->cursorPar()->getChar(text->cursor.pos()) == - Paragraph::META_INSET) { - if (inset == text->cursorPar()->getInset(text->cursor.pos())) { - theLockingInset(inset); - return true; - } - } - - // then do a deep look at the inset and lock the right one - ParagraphList::iterator pit = buffer()->paragraphs().begin(); - ParagraphList::iterator pend = buffer()->paragraphs().end(); - for (int par = 0; pit != pend; ++pit, ++par) { - InsetList::iterator it = pit->insetlist.begin(); - InsetList::iterator end = pit->insetlist.end(); - for (; it != end; ++it) { - if (it->inset == inset) { - text->setCursorIntern(par, it->pos); - theLockingInset(inset); - return true; - } - } - } - return false; -} - - bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc) { - if (theLockingInset() && available()) { - y += text->cursor.y() + theLockingInset()->insetInInsetY(); + lyxerr << "BufferView::fitLockedInsetCursor x: " << x + << " y: " << y << std::endl; + UpdatableInset * tli = + static_cast(cursor().innerInset()); + if (tli && available()) { + lyxerr << " text->cursor.y: " << text->cursor.y() << std::endl; + lyxerr << " insetInInsetY: " << tli->insetInInsetY() << std::endl; + y += text->cursor.y() + tli->insetInInsetY(); if (screen().fitManualCursor(this, text, x, y, asc, desc)) { updateScrollbar(); return true; @@ -442,32 +394,6 @@ void BufferView::hideCursor() } -int BufferView::unlockInset(UpdatableInset * inset) -{ - if (!inset) - return 0; - if (inset && theLockingInset() == inset) { - inset->insetUnlock(this); - theLockingInset(0); - // make sure we update the combo ! - owner()->setLayout(getLyXText()->cursorPar()->layout()->name()); - // Tell the paragraph dialog that we changed paragraph - dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); - finishUndo(); - return 0; - } - if (inset && theLockingInset() && - theLockingInset()->unlockInsetInInset(this, inset)) { - // Tell the paragraph dialog that we changed paragraph - dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); - // owner inset has updated the layout combo - finishUndo(); - return 0; - } - return 1; -} - - void BufferView::updateInset(InsetOld const * inset) { pimpl_->updateInset(inset); @@ -487,29 +413,15 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to) } -UpdatableInset * BufferView::theLockingInset() const +UpdatableInset * BufferView::innerInset() const { - // If NULL is not allowed we should put an Assert here. (Lgb) - if (text) - return text->the_locking_inset; - return 0; -} - - -void BufferView::theLockingInset(UpdatableInset * inset) -{ - text->the_locking_inset = inset; + return static_cast(cursor().innerInset()); } LyXText * BufferView::getLyXText() const { - if (theLockingInset()) { - LyXText * txt = theLockingInset()->getLyXText(this, true); - if (txt) - return txt; - } - return text; + return cursor().innerText(); } @@ -524,9 +436,6 @@ Language const * BufferView::getParentLanguage(InsetOld * inset) const Encoding const * BufferView::getEncoding() const { LyXText * text = getLyXText(); - if (!text) - return 0; - return text->cursorPar()->getFont( buffer()->params(), text->cursor.pos(), @@ -569,3 +478,9 @@ int BufferView::x_target() const { return x_target_; } + + +void BufferView::updateParagraphDialog() +{ + pimpl_->updateParagraphDialog(); +} diff --git a/src/BufferView.h b/src/BufferView.h index f304f07f09..d3ec1cb833 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -19,7 +19,6 @@ #include - class Buffer; class Change; class Encoding; @@ -90,6 +89,14 @@ public: /** update for a particular inset. Gets a pointer and not a * reference because we really need the pointer information * to find it in the buffer. + * + * Extracted from Matthias notes: + * + * If a inset wishes any redraw and/or update it just has to call + * updateInset(this). It's is completly irrelevant, where the inset is. + * UpdateInset will find it in any paragraph in any buffer. + * Of course the insets in the current paragraph/buffer + * are checked first, so no performance problem should occur. */ void updateInset(InsetOld const *); /// reset the scrollbar to reflect current view position @@ -100,9 +107,6 @@ public: /// FIXME bool available() const; - /// FIXME - void beforeChange(LyXText *); - /// Save the current position as bookmark i void savePosition(unsigned int i); /// Restore the position from bookmark i @@ -121,14 +125,8 @@ public: /// return the lyxtext we are using LyXText * getLyXText() const; - /// Return the current inset we are "locked" in - UpdatableInset * theLockingInset() const; - /// lock the given inset FIXME: return value ? - bool lockInset(UpdatableInset * inset); - /// unlock the given inset - int unlockInset(UpdatableInset * inset); - /// unlock the currently locked inset - void insetUnlock(); + /// update paragraph dialogs + void updateParagraphDialog(); /// return the current encoding at the cursor Encoding const * getEncoding() const; @@ -206,11 +204,10 @@ public: LCursor & cursor(); /// access to cursor LCursor const & cursor() const; + /// + UpdatableInset * innerInset() const; private: - /// Set the current locking inset - void theLockingInset(UpdatableInset * inset); - struct Pimpl; friend struct BufferView::Pimpl; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index bbcc1282af..34df16b03e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -67,17 +67,7 @@ #include -using bv_funcs::bold; -using bv_funcs::code; using bv_funcs::currentState; -using bv_funcs::emph; -using bv_funcs::fontSize; -using bv_funcs::lang; -using bv_funcs::noun; -using bv_funcs::roman; -using bv_funcs::sans; -using bv_funcs::styleReset; -using bv_funcs::underline; using lyx::pos_type; @@ -341,12 +331,9 @@ void BufferView::Pimpl::buffer(Buffer * b) owner_->updateLayoutChoice(); owner_->updateWindowTitle(); - if (buffer_) { - // Don't forget to update the Layout - string const layoutname = - bv_->text->cursorPar()->layout()->name(); - owner_->setLayout(layoutname); - } + // Don't forget to update the Layout + if (buffer_) + owner_->setLayout(bv_->text->cursorPar()->layout()->name()); if (lyx::graphics::Previews::activated() && buffer_) lyx::graphics::Previews::get().generateBufferPreviews(*buffer_); @@ -355,14 +342,21 @@ void BufferView::Pimpl::buffer(Buffer * b) bool BufferView::Pimpl::fitCursor() { + lyxerr << "BufferView::Pimpl::fitCursor." << endl; bool ret; - if (bv_->theLockingInset()) { - bv_->theLockingInset()->fitInsetCursor(bv_); +#ifndef LOCK + UpdatableInset * tli = + static_cast(cursor_.innerInset()); + if (tli) { + tli->fitInsetCursor(bv_); ret = true; } else { ret = screen().fitCursor(bv_->text, bv_); } +#else + ret = screen().fitCursor(bv_->text, bv_); +#endif //dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); @@ -393,7 +387,6 @@ void BufferView::Pimpl::resizeCurrentBuffer() int par = -1; int selstartpar = -1; int selendpar = -1; - UpdatableInset * the_locking_inset = 0; pos_type pos = 0; pos_type selstartpos = 0; @@ -414,12 +407,11 @@ void BufferView::Pimpl::resizeCurrentBuffer() selendpos = bv_->text->selection.end.pos(); selection = bv_->text->selection.set(); mark_set = bv_->text->selection.mark(); - the_locking_inset = bv_->theLockingInset(); bv_->text->fullRebreak(); update(); } else { - bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs()); - bv_->text->init(bv_); + bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs()); + bv_->text->init(bv_); } if (par != -1) { @@ -438,8 +430,6 @@ void BufferView::Pimpl::resizeCurrentBuffer() bv_->text->selection.cursor = bv_->text->cursor; bv_->text->selection.set(false); } - // remake the inset locking - bv_->theLockingInset(the_locking_inset); } top_y(screen().topCursorVisible(bv_->text)); @@ -502,9 +492,8 @@ void BufferView::Pimpl::scrollDocView(int value) void BufferView::Pimpl::scroll(int lines) { - if (!buffer_) { + if (!buffer_) return; - } LyXText const * t = bv_->text; int const line_height = defaultRowHeight(); @@ -627,16 +616,13 @@ void BufferView::Pimpl::cursorToggle() } screen().toggleCursor(*bv_); - cursor_timeout.restart(); } bool BufferView::Pimpl::available() const { - if (buffer_ && bv_->text) - return true; - return false; + return buffer_ && bv_->text; } @@ -655,12 +641,6 @@ Change const BufferView::Pimpl::getCurrentChange() } -void BufferView::Pimpl::beforeChange(LyXText * text) -{ - text->clearSelection(); -} - - void BufferView::Pimpl::savePosition(unsigned int i) { if (i >= saved_positions_num) @@ -680,7 +660,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i) string const fname = saved_positions[i].filename; - beforeChange(bv_->text); + bv_->text->clearSelection(); if (fname != buffer_->fileName()) { Buffer * b = 0; @@ -709,10 +689,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i) bool BufferView::Pimpl::isSavedPosition(unsigned int i) { - if (i >= saved_positions_num) - return false; - - return !saved_positions[i].filename.empty(); + return i < saved_positions_num && !saved_positions[i].filename.empty(); } @@ -721,26 +698,13 @@ void BufferView::Pimpl::switchKeyMap() if (!lyxrc.rtl_support) return; - LyXText * text = bv_->getLyXText(); - if (text->real_current_font.isRightToLeft() - && !(bv_->theLockingInset() - && bv_->theLockingInset()->lyxCode() == InsetOld::ERT_CODE)) - { - if (owner_->getIntl().keymap == Intl::PRIMARY) - owner_->getIntl().KeyMapSec(); + Intl & intl = owner_->getIntl(); + if (bv_->getLyXText()->real_current_font.isRightToLeft()) { + if (intl.keymap == Intl::PRIMARY) + intl.KeyMapSec(); } else { - if (owner_->getIntl().keymap == Intl::SECONDARY) - owner_->getIntl().KeyMapPrim(); - } -} - - -void BufferView::Pimpl::insetUnlock() -{ - if (bv_->theLockingInset()) { - bv_->theLockingInset()->insetUnlock(bv_); - bv_->theLockingInset(0); - finishUndo(); + if (intl.keymap == Intl::SECONDARY) + intl.KeyMapPrim(); } } @@ -749,13 +713,11 @@ void BufferView::Pimpl::center() { LyXText * text = bv_->text; - beforeChange(text); + text->clearSelection(); int const half_height = workarea().workHeight() / 2; int new_y = std::max(0, text->cursor.y() - half_height); // FIXME: look at this comment again ... - - // FIXME: can we do this w/o calling screen directly ? // This updates top_y() but means the fitCursor() call // from the update(FITCUR) doesn't realise that we might // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause @@ -765,7 +727,6 @@ void BufferView::Pimpl::center() // updateScrollbar() currently. Never mind that this is a // pretty obfuscated way of updating t->top_y() top_y(new_y); - //screen().draw(); update(); } @@ -776,12 +737,6 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const } -/* - * Dispatch functions for actions which can be valid for BufferView->text - * and/or InsetText->text!!! - */ - - InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code) { #if 0 @@ -918,16 +873,38 @@ void BufferView::Pimpl::trackChanges() buf->redostack().clear(); } +#warning remove me +LCursor theTempCursor(0); + +namespace { -bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev) + InsetOld * insetFromCoords(BufferView * bv, int x, int y) + { + LyXText * text = bv->text; + InsetOld * inset = 0; + InsetOld * inset_hit = 0; + theTempCursor = LCursor(bv); + while ((inset_hit = text->checkInsetHit(x, y))) { + inset = inset_hit; + text = inset_hit->getText(0); + lyxerr << "Hit inset: " << inset << " at x: " << x + << " y: " << y << endl; + theTempCursor.push(static_cast(inset)); + } + return inset; + } + +} + + +bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) { - switch (ev.action) { + switch (cmd.action) { case LFUN_MOUSE_PRESS: case LFUN_MOUSE_MOTION: case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_DOUBLE: - case LFUN_MOUSE_TRIPLE: - { + case LFUN_MOUSE_TRIPLE: { // We pass those directly to the Bufferview, since // otherwise selection handling breaks down @@ -940,7 +917,35 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev) screen().hideCursor(); - bool const res = dispatch(ev); + // either the inset under the cursor or the surrounding LyXText will + // handle this event. + + // built temporary path to inset + InsetOld * inset = insetFromCoords(bv_, cmd.x, cmd.y); + FuncRequest cmd1(cmd, bv_); + DispatchResult res; + + // try to dispatch to that inset + if (inset) { + FuncRequest cmd2 = cmd1; + lyxerr << "dispatching action " << cmd2.action + << " to inset " << inset << endl; + cmd2.x -= inset->x(); + cmd2.y -= inset->y(); + res = inset->dispatch(cmd2); + if (res.update()) + bv_->updateInset(inset); + res.update(false); + } + + // otherwise set cursor to surrounding LyXText + if (!res.dispatched()) { + lyxerr << "cursor is: " << bv_->cursor() << endl; + lyxerr << "dispatching to surrounding LyXText " + << bv_->cursor().innerText() << endl; + bv_->cursor().innerText()->dispatch(cmd1); + //return DispatchResult(true, true); + } // see workAreaKeyPress cursor_timeout.restart(); @@ -955,11 +960,11 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev) // clicked somewhere, so we force through the display // of the new status here. owner_->clearMessage(); - - return res; + return true; } + default: - owner_->dispatch(ev); + owner_->dispatch(cmd); return true; } } @@ -1001,57 +1006,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) InsertAsciiFile(bv_, ev.argument, false); break; - case LFUN_LANGUAGE: - lang(bv_, ev.argument); - switchKeyMap(); - owner_->view_state_changed(); - break; - - case LFUN_EMPH: - emph(bv_); - owner_->view_state_changed(); - break; - - case LFUN_BOLD: - bold(bv_); - owner_->view_state_changed(); - break; - - case LFUN_NOUN: - noun(bv_); - owner_->view_state_changed(); - break; - - case LFUN_CODE: - code(bv_); - owner_->view_state_changed(); - break; - - case LFUN_SANS: - sans(bv_); - owner_->view_state_changed(); - break; - - case LFUN_ROMAN: - roman(bv_); - owner_->view_state_changed(); - break; - - case LFUN_DEFAULT: - styleReset(bv_); - owner_->view_state_changed(); - break; - - case LFUN_UNDERLINE: - underline(bv_); - owner_->view_state_changed(); - break; - - case LFUN_FONT_SIZE: - fontSize(bv_, ev.argument); - owner_->view_state_changed(); - break; - case LFUN_FONT_STATE: owner_->getLyXFunc().setMessage(currentState(bv_)); break; @@ -1063,8 +1017,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) InsetCommandParams icp("label", contents); string data = InsetCommandMailer::params2string("label", icp); owner_->getDialogs().show("label", data, 0); + break; } - break; case LFUN_BOOKMARK_SAVE: savePosition(strToUnsignedInt(ev.argument)); @@ -1179,36 +1133,20 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) case LFUN_LAYOUT_PARAGRAPH: { string data; params2string(*bv_->getLyXText()->cursorPar(), data); - data = "show\n" + data; bv_->owner()->getDialogs().show("paragraph", data); break; } - case LFUN_PARAGRAPH_UPDATE: { - if (!bv_->owner()->getDialogs().visible("paragraph")) - break; - Paragraph const & par = *bv_->getLyXText()->cursorPar(); - - string data; - params2string(par, data); - - // Will the paragraph accept changes from the dialog? - InsetOld * const inset = par.inInset(); - bool const accept = - !(inset && inset->forceDefaultParagraphs(inset)); - - data = "update " + tostr(accept) + '\n' + data; - bv_->owner()->getDialogs().update("paragraph", data); + case LFUN_PARAGRAPH_UPDATE: + updateParagraphDialog(); break; - } case LFUN_PARAGRAPH_APPLY: setParagraphParams(*bv_, ev.argument); break; - case LFUN_THESAURUS_ENTRY: - { + case LFUN_THESAURUS_ENTRY: { string arg = ev.argument; if (arg.empty()) { @@ -1225,8 +1163,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) } bv_->owner()->getDialogs().show("thesaurus", arg); - } break; + } case LFUN_TRACK_CHANGES: trackChanges(); @@ -1286,6 +1224,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) { +#ifdef LOCK // if we are in a locking inset we should try to insert the // inset there otherwise this is a illegal function now if (bv_->theLockingInset()) { @@ -1293,12 +1232,13 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) return bv_->theLockingInset()->insertInset(bv_, inset); return false; } +#endif // not quite sure if we want this... bv_->text->recUndo(bv_->text->cursor.par()); freezeUndo(); - beforeChange(bv_->text); + bv_->text->clearSelection(); if (!lout.empty()) { bv_->text->breakParagraph(bv_->buffer()->paragraphs()); @@ -1310,17 +1250,8 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) string lres = lout; LyXTextClass const & tclass = buffer_->params().getLyXTextClass(); bool hasLayout = tclass.hasLayout(lres); - string lay = tclass.defaultLayoutName(); - - if (hasLayout != false) { - // layout found - lay = lres; - } else { - // layout not fount using default - lay = tclass.defaultLayoutName(); - } - bv_->text->setLayout(lay); + bv_->text->setLayout(hasLayout ? lres : tclass.defaultLayoutName()); bv_->text->setParagraph( VSpace(VSpace::NONE), VSpace(VSpace::NONE), @@ -1330,7 +1261,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) 0); } - bv_->text->insertInset(inset); + bv_->cursor().innerText()->insertInset(inset); update(); unFreezeUndo(); @@ -1338,15 +1269,16 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) } -void BufferView::Pimpl::updateInset(InsetOld const * inset) +void BufferView::Pimpl::updateInset(InsetOld const * /*inset*/) { if (!available()) return; - bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset)); +#warning used for asynchronous updates? + //bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset)); // this should not be needed, but it is... - // bv_->text->redoParagraph(bv_->text->cursorPar()); + bv_->text->redoParagraph(bv_->text->cursorPar()); // bv_->text->fullRebreak(); update(); @@ -1393,3 +1325,21 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code, bv_->text->setCursorIntern(cursor.par(), cursor.pos()); return need_update; } + + +void BufferView::Pimpl::updateParagraphDialog() +{ + if (!bv_->owner()->getDialogs().visible("paragraph")) + return; + Paragraph const & par = *bv_->getLyXText()->cursorPar(); + string data; + params2string(par, data); + + // Will the paragraph accept changes from the dialog? + InsetOld * const inset = par.inInset(); + bool const accept = + !(inset && inset->forceDefaultParagraphs(inset)); + + data = "update " + tostr(accept) + '\n' + data; + bv_->owner()->getDialogs().update("paragraph", data); +} diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 80a0152ae6..19e702bea2 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -93,8 +93,6 @@ struct BufferView::Pimpl : public boost::signals::trackable { /// get the change at the cursor position Change const getCurrentChange(); /// - void beforeChange(LyXText *); - /// void savePosition(unsigned int i); /// void restorePosition(unsigned int i); @@ -103,8 +101,6 @@ struct BufferView::Pimpl : public boost::signals::trackable { /// void switchKeyMap(); /// - void insetUnlock(); - /// void center(); /// bool insertInset(InsetOld * inset, std::string const & lout = std::string()); @@ -118,6 +114,8 @@ struct BufferView::Pimpl : public boost::signals::trackable { int top_y() const; /// void top_y(int y); + /// update paragraph dialogs + void updateParagraphDialog(); private: /// the y coordinate of the top of the screen int top_y_; diff --git a/src/ChangeLog b/src/ChangeLog index c7a882ee6a..0717046e55 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,29 @@ + +2003-11-10 André Pönitz + + * lfuns.h: new LFUN_FINISHED_LEFT, LFUN_FINISHED_RIGHT, + LFUN_FINISHED_UP, LFUN_FINISHED_DOWN used in dispatch to + indicate that the cursor needs to leave an inset + + * lyxtext.h: remove inset locking + + * cursor.[Ch]: re-implement functionality provided by inset locking + + * BufferView.[Ch]: + * BufferView_pimpl.[Ch]: + * LyXAction.C: + * bufferview_funcs.[Ch]: + * factory.C: + * funcrequest.[Ch]: + * iterators.C: + * lyx_cb.C: + * lyxfind.C: + * lyxfunc.C: + * text.C: + * text2.C: + * text3.C: + * undo.C: adjust + 2003-11-07 Alfredo Braunstein * PosIterator.[Ch]: replace the stack with a vector, add inset diff --git a/src/LyXAction.C b/src/LyXAction.C index 7624280f72..ae7a2b5337 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -370,7 +370,10 @@ bool LyXAction::funcHasFlag(kb_action action, { info_map::const_iterator ici = lyx_info_map.find(action); - BOOST_ASSERT(ici != lyx_info_map.end()); + if (ici == lyx_info_map.end()) { + lyxerr << "action: " << action << " is not known." << endl; + BOOST_ASSERT(false); + } return ici->second.attrib & flag; } diff --git a/src/Makefile.am b/src/Makefile.am index c54871bcd4..d1a5bb06fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -91,8 +91,6 @@ lyx_SOURCES = \ LyXAction.h \ MenuBackend.C \ MenuBackend.h \ - paragraph_funcs.C \ - paragraph_funcs.h \ ParagraphList_fwd.h \ ParagraphParameters.C \ ParagraphParameters.h \ @@ -236,6 +234,8 @@ lyx_SOURCES = \ paper.h \ paragraph.C \ paragraph.h \ + paragraph_funcs.C \ + paragraph_funcs.h \ paragraph_pimpl.C \ paragraph_pimpl.h \ PosIterator.h \ diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 3a0b79de35..2c28e2b81a 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -47,13 +47,6 @@ using std::ostringstream; using std::string; -namespace { - -LyXFont freefont(LyXFont::ALL_IGNORE); -bool toggleall(false); - -} - namespace bv_funcs { // Set data using font and toggle @@ -155,79 +148,6 @@ bool string2font(string const & data, LyXFont & font, bool & toggle) } -string const freefont2string() -{ - string data; - if (font2string(freefont, toggleall, data)) - return data; - return string(); -} - - -void update_and_apply_freefont(BufferView * bv, string const & data) -{ - LyXFont font; - bool toggle; - if (string2font(data, font, toggle)) { - freefont = font; - toggleall = toggle; - apply_freefont(bv); - } -} - - -void apply_freefont(BufferView * bv) -{ - toggleAndShow(bv, freefont, toggleall); - bv->owner()->view_state_changed(); - bv->owner()->message(_("Character set")); -} - - -void emph(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setEmph(LyXFont::TOGGLE); - toggleAndShow(bv, font); -} - - -void bold(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setSeries(LyXFont::BOLD_SERIES); - toggleAndShow(bv, font); -} - - -void noun(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setNoun(LyXFont::TOGGLE); - toggleAndShow(bv, font); -} - - -void number(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setNumber(LyXFont::TOGGLE); - toggleAndShow(bv, font); -} - - -void lang(BufferView * bv, string const & l) -{ - Language const * lang = languages.getLanguage(l); - if (!lang) - return; - - LyXFont font(LyXFont::ALL_IGNORE); - font.setLanguage(lang); - toggleAndShow(bv, font); -} - - bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_only) { if (!bv->available() || !text) @@ -243,53 +163,6 @@ bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_o } -void code(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good - toggleAndShow(bv, font); -} - - -void sans(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setFamily(LyXFont::SANS_FAMILY); - toggleAndShow(bv, font); -} - - -void roman(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setFamily(LyXFont::ROMAN_FAMILY); - toggleAndShow(bv, font); -} - - -void styleReset(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_INHERIT, ignore_language); - toggleAndShow(bv, font); -} - - -void underline(BufferView * bv) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setUnderbar(LyXFont::TOGGLE); - toggleAndShow(bv, font); -} - - -void fontSize(BufferView * bv, string const & size) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setLyXSize(size); - toggleAndShow(bv, font); -} - - // Returns the current font and depth as a message. string const currentState(BufferView * bv) { @@ -372,9 +245,7 @@ string const currentState(BufferView * bv) state << _(", Inset: "); InsetOld * inset = pit->inInset(); if (inset) - state << inset - << " text: " << inset->getLyXText(bv, true) - << " owner: " << inset->owner(); + state << inset << " owner: " << inset->owner(); else state << -1; #endif @@ -382,38 +253,6 @@ string const currentState(BufferView * bv) } -/* Does the actual toggle job of the calls above. - * Also shows the current font state. - */ -void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall) -{ - if (!bv->available()) - return; - - if (bv->theLockingInset()) { - bv->theLockingInset()->setFont(bv, font, toggleall); - return; - } - - LyXText * text = bv->getLyXText(); - text->toggleFree(font, toggleall); - bv->update(); - - if (font.language() != ignore_language || - font.number() != LyXFont::IGNORE) { - LyXCursor & cursor = text->cursor; - Paragraph & par = *text->cursorPar(); - text->bidi.computeTables(par, *bv->buffer(), - *par.getRow(cursor.pos())); - if (cursor.boundary() != - text->bidi.isBoundary(*bv->buffer(), par, - cursor.pos(), - text->real_current_font)) - text->setCursor(cursor.par(), cursor.pos(), - false, !cursor.boundary()); - } -} - // deletes a selection during an insertion void replaceSelection(LyXText * text) @@ -444,10 +283,8 @@ void put_selection_at(BufferView * bv, PosIterator const & cur, text->cursor = text->selection.start; } - bv->fitCursor(); bv->update(); - } diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 78a8b452c3..491dde8781 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -37,15 +37,7 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle); * frontends. */ std::string const freefont2string(); -/** Set the freefont using the contents of \param data dispatched from - * the frontends and apply it at the current cursor location. - */ -void update_and_apply_freefont(BufferView * bv, std::string const & data); -/** Apply the contents of freefont at the current cursor location. - */ -void apply_freefont(BufferView * bv); - - +/// void put_selection_at(BufferView * bv, PosIterator const & cur, int length, bool backwards); @@ -61,39 +53,12 @@ enum DEPTH_CHANGE { * if test_only, don't change any depths. Returns whether something * (would have) changed */ -extern bool changeDepth(BufferView *, LyXText *, DEPTH_CHANGE, bool test_only); +bool changeDepth(BufferView *, LyXText *, DEPTH_CHANGE, bool test_only); -/// -extern void emph(BufferView *); -/// -extern void bold(BufferView *); -/// -extern void noun(BufferView *); -/// -extern void lang(BufferView *, std::string const &); -/// -extern void number(BufferView *); -/// -extern void tex(BufferView *); -/// -extern void code(BufferView *); -/// -extern void sans(BufferView *); -/// -extern void roman(BufferView *); -/// -extern void styleReset(BufferView *); -/// -extern void underline(BufferView *); -/// -extern void fontSize(BufferView *, std::string const &); /// Returns the current font and depth as a message. -extern std::string const currentState(BufferView *); -/// -extern void toggleAndShow(BufferView *, LyXFont const &, - bool toggleall = true); +std::string const currentState(BufferView *); /// replace selection with insertion -extern void replaceSelection(LyXText * lt); +void replaceSelection(LyXText * lt); diff --git a/src/cursor.C b/src/cursor.C index 0f40029809..347780ae81 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -15,11 +15,14 @@ #include "cursor.h" #include "debug.h" #include "dispatchresult.h" +#include "funcrequest.h" #include "iterators.h" +#include "lfuns.h" #include "lyxtext.h" #include "paragraph.h" #include "insets/updatableinset.h" +#include "insets/insettabular.h" #include "insets/insettext.h" #include @@ -31,14 +34,22 @@ using std::endl; std::ostream & operator<<(std::ostream & os, CursorItem const & item) { os << " inset: " << item.inset_ - << " idx: " << item.idx_ - << " text: " << item.text_ - << " par: " << item.par_ - << " pos: " << item.pos_; + << " text: " << item.text() +// << " par: " << item.par_ +// << " pos: " << item.pos_ + << " x: " << item.inset_->x() + << " y: " << item.inset_->y() +; return os; } +LyXText * CursorItem::text() const +{ + return inset_->getText(0); +} + + std::ostream & operator<<(std::ostream & os, LCursor const & cursor) { os << "\n"; @@ -48,14 +59,48 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cursor) } -DispatchResult LCursor::dispatch(FuncRequest const & cmd) +LCursor::LCursor(BufferView * bv) + : bv_(bv) +{} + + +DispatchResult LCursor::dispatch(FuncRequest const & cmd0) { + lyxerr << "\nLCursor::dispatch: " << *this << endl; + FuncRequest cmd = cmd0; + for (int i = data_.size() - 1; i >= 0; --i) { CursorItem const & citem = data_[i]; - lyxerr << "trying to dispatch to inset" << citem.inset_ << endl; + lyxerr << "trying to dispatch to inset " << citem.inset_ << endl; DispatchResult res = citem.inset_->dispatch(cmd); - if (handleResult(res)) + if (res.update()) + bv_->updateInset(citem.inset_); + if (res.dispatched()) { + lyxerr << " successfully dispatched to inset " << citem.inset_ << endl; return DispatchResult(true, true); + } + // remove one level of cursor + switch (res.val()) { + case FINISHED: + pop(i); + cmd = FuncRequest(bv_, LFUN_FINISHED_LEFT); + break; + case FINISHED_RIGHT: + pop(i); + cmd = FuncRequest(bv_, LFUN_FINISHED_RIGHT); + break; + case FINISHED_UP: + pop(i); + cmd = FuncRequest(bv_, LFUN_FINISHED_UP); + break; + case FINISHED_DOWN: + pop(i); + cmd = FuncRequest(bv_, LFUN_FINISHED_DOWN); + break; + default: + lyxerr << "not handled on level " << i << " val: " << res.val() << endl; + break; + } } lyxerr << "trying to dispatch to main text " << bv_->text << endl; DispatchResult res = bv_->text->dispatch(cmd); @@ -64,59 +109,20 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd) } -bool LCursor::handleResult(DispatchResult const & res) +void LCursor::push(UpdatableInset * inset) { - lyxerr << "LCursor::handleResult: " << res.val() << endl; - switch (res.val()) { - case FINISHED: - ///pop(); - return true; - - case FINISHED_RIGHT: { - ///pop(); - //InsetText * inset = static_cast(innerInset()); - //if (inset) - // inset->moveRightIntern(bv_, false, false); - //else - // bv_->text->cursorRight(bv_); - innerText()->cursorRight(bv_); - return true; - } - - case FINISHED_UP: { - ///pop(); - //InsetText * inset = static_cast(inset()); - //if (inset) - // result = inset->moveUp(bv); - return true; - } - - case FINISHED_DOWN: { - ///pop(); - //InsetText * inset = static_cast(inset()); - //if (inset) - // result = inset->moveDown(bv); - return true; - } - - default: - lyxerr << "# unhandled result: " << res.val() << endl; - return false; - } + lyxerr << "LCursor::push() inset: " << inset << endl; + data_.push_back(CursorItem(inset)); } - -LCursor::LCursor(BufferView * bv) - : bv_(bv) -{} - - -void LCursor::push(InsetOld * inset, LyXText * text) +void LCursor::pop(int depth) { - lyxerr << "LCursor::push() inset: " << inset << " text: " << text - << endl; - data_.push_back(CursorItem(inset, text)); + lyxerr << "LCursor::pop() to " << depth << endl; + while (depth < data_.size()) { + lyxerr << "LCursor::pop a level " << endl; + data_.pop_back(); + } } @@ -131,7 +137,7 @@ void LCursor::pop() } -InsetOld * LCursor::innerInset() const +UpdatableInset * LCursor::innerInset() const { return data_.empty() ? 0 : data_.back().inset_; } @@ -139,5 +145,53 @@ InsetOld * LCursor::innerInset() const LyXText * LCursor::innerText() const { - return data_.empty() ? bv_->text : data_.back().text_; + if (!data_.empty()) { + // go up until first non-0 text is hit + // (innermost text is 0 e.g. for mathed and the outer tabular level) + for (int i = data_.size() - 1; i >= 0; --i) + if (data_[i].text()) + return data_[i].text(); + } + return bv_->text; +} + + +void LCursor::getPos(int & x, int & y) const +{ + if (data_.empty()) { + x = bv_->text->cursor.x(); + y = bv_->text->cursor.y(); + y -= bv_->top_y(); + } else { + // Would be nice to clean this up to make some understandable sense... + UpdatableInset * inset = innerInset(); + // Non-obvious. The reason we have to have these + // extra checks is that the ->getCursor() calls rely + // on the inset's own knowledge of its screen position. + // If we scroll up or down in a big enough increment, the + // inset->draw() is not called: this doesn't update + // inset.top_baseline, so getCursor() returns an old value. + // Ugly as you like. + //inset->getCursorPos(bv_, x, y); + //y = inset->insetInInsetY() + bv_->text->cursor.y(); + inset->getCursorPos(bv_, x, y); + x += inset->x(); + y += inset->y(); + } +} + + +UpdatableInset * LCursor::innerInsetOfType(int code) const +{ + for (int i = data_.size() - 1; i >= 0; --i) + if (data_[i].inset_->lyxCode() == code) + return data_[i].inset_; + return 0; +} + + +InsetTabular * LCursor::innerInsetTabular() const +{ + return static_cast + (innerInsetOfType(InsetOld::TABULAR_CODE)); } diff --git a/src/cursor.h b/src/cursor.h index 2494217206..9929c87a97 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -19,10 +19,11 @@ #include class BufferView; -class InsetOld; +class UpdatableInset; class DispatchResult; class FuncRequest; class LyXText; +class InsetTabular; /** @@ -32,20 +33,18 @@ class LyXText; class CursorItem { public: /// - CursorItem() : inset_(0), text_(0), idx_(0), par_(0), pos_(0) {} + CursorItem() : inset_(0), par_(0), pos_(0) {} /// - CursorItem(InsetOld * inset, LyXText * text) - : inset_(inset), text_(text), idx_(0), par_(0), pos_(0) + explicit CursorItem(UpdatableInset * inset) + : inset_(inset), par_(0), pos_(0) {} /// + LyXText * text() const; + /// friend std::ostream & operator<<(std::ostream &, CursorItem const &); public: /// - InsetOld * inset_; - /// - LyXText * text_; - /// - int idx_; + UpdatableInset * inset_; /// int par_; /// @@ -55,20 +54,26 @@ public: class LCursor { public: - /// - LCursor(BufferView * bv); + /// create 'empty' cursor + explicit LCursor(BufferView * bv); /// dispatch from innermost inset upwards DispatchResult dispatch(FuncRequest const & cmd); - /// adjust cursor acording to result - bool handleResult(DispatchResult const & res); - /// - void push(InsetOld *, LyXText *); /// + void push(UpdatableInset * inset); + /// restrict cursor nesting to given size + void pop(int depth); + /// pop one level off the cursor void pop(); /// - InsetOld * innerInset() const; + UpdatableInset * innerInset() const; + /// + UpdatableInset * innerInsetOfType(int code) const; + /// + InsetTabular * innerInsetTabular() const; /// LyXText * innerText() const; + /// returns x,y position + void getPos(int & x, int & y) const; /// friend std::ostream & operator<<(std::ostream &, LCursor const &); public: diff --git a/src/dispatchresult.h b/src/dispatchresult.h index 0cad88a85a..4b1e8c859c 100644 --- a/src/dispatchresult.h +++ b/src/dispatchresult.h @@ -25,6 +25,8 @@ the inset. FINISHED_DOWN = FINISHED, but move the cursor DOWN from the inset. + FINISHED_POP = FINISHED, but move the cursor DOWN from + the inset. UNDISPATCHED = the action was not catched, it should be dispatched by lower level insets */ diff --git a/src/factory.C b/src/factory.C index 587fdd2072..fcfb662f8b 100644 --- a/src/factory.C +++ b/src/factory.C @@ -176,18 +176,15 @@ InsetOld * createInset(FuncRequest const & cmd) bv->owner()->getDialogs().show("tabularcreate"); return 0; - case LFUN_INSET_CAPTION: - if (bv->theLockingInset()) { - lyxerr << "Locking inset code: " - << static_cast(bv->theLockingInset()->lyxCode()); - auto_ptr inset(new InsetCaption(params)); - inset->setOwner(bv->theLockingInset()); - inset->setAutoBreakRows(true); - inset->setDrawFrame(InsetText::LOCKED); - inset->setFrameColor(LColor::captionframe); - return inset.release(); - } - return 0; + case LFUN_INSET_CAPTION: + if (bv->innerInset()) { + auto_ptr inset(new InsetCaption(params)); + inset->setOwner(bv->innerInset()); + inset->setAutoBreakRows(true); + inset->setDrawFrame(InsetText::LOCKED); + inset->setFrameColor(LColor::captionframe); + return inset.release(); + } case LFUN_INDEX_PRINT: return new InsetPrintIndex(InsetCommandParams("printindex")); diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index fc2d2c30a9..4a52910086 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ + +2003-11-10 André Pönitz + + * screen.C: adjust to removed inset locking + 2003-10-14 Angus Leeming * LyXView.[Ch] (updateInset): invoke BufferView::updateInset, returning diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 10dab24a2c..6e8e43fd1e 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -21,6 +21,7 @@ #include "BufferView.h" #include "buffer.h" #include "bufferparams.h" +#include "cursor.h" #include "debug.h" #include "language.h" #include "LColor.h" @@ -171,34 +172,9 @@ void LyXScreen::showCursor(BufferView & bv) int h = ascent + descent; int x = 0; int y = 0; - int const top_y = bv.top_y(); - - if (bv.theLockingInset()) { - // Would be nice to clean this up to make some understandable sense... - UpdatableInset * inset = bv.theLockingInset(); - inset->getCursor(bv, x, y); - - // Non-obvious. The reason we have to have these - // extra checks is that the ->getCursor() calls rely - // on the inset's own knowledge of its screen position. - // If we scroll up or down in a big enough increment, the - // inset->draw() is not called: this doesn't update - // inset.top_baseline, so getCursor() returns an old value. - // Ugly as you like. - int bx, by; - inset->getCursorPos(&bv, bx, by); - by += inset->insetInInsetY() + bv.text->cursor.y(); - if (by < top_y) - return; - if (by > top_y + workarea().workHeight()) - return; - } else { - x = bv.text->cursor.x(); - y = bv.text->cursor.y(); - y -= top_y; - } - + bv.cursor().getPos(x, y); y -= ascent; + //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl; // if it doesn't fit entirely on the screen, don't try to show it if (y < 0 || y + h > workarea().workHeight()) @@ -229,13 +205,13 @@ void LyXScreen::toggleCursor(BufferView & bv) bool LyXScreen::fitManualCursor(BufferView * bv, LyXText *, - int /*x*/, int y, int asc, int desc) + int x, int y, int asc, int desc) { + lyxerr << "LyXScreen::fitManualCursor x: " << x << " y: " << y << std::endl; int const vheight = workarea().workHeight(); int const topy = bv->top_y(); int newtop = topy; - if (y + desc - topy >= vheight) newtop = y - 3 * vheight / 4; // the scroll region must be so big!! else if (y - asc < topy && topy > 0) diff --git a/src/funcrequest.C b/src/funcrequest.C index fd18c01bcb..108fe2a261 100644 --- a/src/funcrequest.C +++ b/src/funcrequest.C @@ -17,6 +17,8 @@ #include "debug.h" #include "support/std_sstream.h" +#include + using std::endl; using std::getline; @@ -134,3 +136,19 @@ string FuncRequest::getArg(unsigned int i) const split(args, argument); return i < args.size() ? args[i] : string(); } + + +bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) +{ + return lhs.action == rhs.action && lhs.argument == rhs.argument; +} + + +std::ostream & operator<<(std::ostream & os, FuncRequest const & cmd) +{ + return os + << " action: " << cmd.action + << " arg: '" << cmd.argument << "'" + << " x: " << cmd.x + << " y: " << cmd.y; +} diff --git a/src/funcrequest.h b/src/funcrequest.h index 2091ab0b46..9501ca9da1 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -16,6 +16,7 @@ #include "frontends/mouse_state.h" #include +#include class BufferView; @@ -77,10 +78,8 @@ public: // should be private, too... }; -inline -bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) -{ - return lhs.action == rhs.action && lhs.argument == rhs.argument; -} +bool operator==(FuncRequest const & lhs, FuncRequest const & rhs); + +std::ostream & operator<<(std::ostream &, FuncRequest const &); #endif // FUNCREQUEST_H diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index dbef4b3677..99b3931041 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,17 @@ + +2003-11-10 André Pönitz + + * inset.[Ch]: + * insetbox.[Ch]: + * insetcollapsable.[Ch]: + * insetert.C: + * insetfloat.C: + * insetminipage.C: + * insettabular.[Ch]: + * insettext.[Ch]: + * insetwrap.C: + * updatableinset.[Ch]: remove inset locking & adjust + 2003-11-07 Alfredo Braunstein * inset.h (allowSpellCheck): add (return true) diff --git a/src/insets/inset.C b/src/insets/inset.C index 26162984b8..ea46d9fd8e 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -74,15 +74,6 @@ string const InsetOld::editMessage() const } -LyXText * InsetOld::getLyXText(BufferView const * bv, bool /*recursive*/) const -{ - if (owner()) - return owner()->getLyXText(bv, false); - else - return bv->text; -} - - void InsetOld::setBackgroundColor(LColor_color color) { background_color_ = color; diff --git a/src/insets/inset.h b/src/insets/inset.h index 79dfac6f82..e8d28cd97d 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -214,12 +214,6 @@ public: int x() const { return top_x; } /// int y() const { return top_baseline; } - // - // because we could have fake text insets and have to call this - // inside them without cast!!! - /// - virtual LyXText * getLyXText(BufferView const *, - bool recursive = false) const; /// virtual void deleteLyXText(BufferView *, bool = true) const {} /// returns the actuall scroll-value @@ -237,10 +231,6 @@ public: /// virtual int numParagraphs() const { return 0; } - /// return the cursor if we own one otherwise giv'em just the - /// BufferView cursor to work with. - virtual LyXCursor const & cursor(BufferView * bview) const; - /// used to toggle insets // is the inset open? virtual bool isOpen() const { return false; } diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index 167ce31955..e626f12b3d 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -149,11 +149,13 @@ void InsetBox::setButtonLabel() } -void InsetBox::metrics(MetricsInfo & mi, Dimension & dim) const +void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const { + MetricsInfo mi = m; + mi.base.textwidth = params_.width.inPixels(m.base.textwidth); InsetCollapsable::metrics(mi, dim); - if (params_.inner_box && isOpen()) - dim.wid = mi.base.textwidth; + //if (params_.inner_box && isOpen()) + // dim.wid = mi.base.textwidth; dim_ = dim; } @@ -175,31 +177,30 @@ InsetBox::priv_dispatch(FuncRequest const & cmd, switch (cmd.action) { case LFUN_INSET_MODIFY: { + lyxerr << "InsetBox::dispatch MODIFY" << endl; InsetBoxMailer::string2params(cmd.argument, params_); setButtonLabel(); bv->updateInset(this); result.dispatched(true); result.update(true); - break; + return result; } + case LFUN_INSET_DIALOG_UPDATE: InsetBoxMailer(*this).updateDialog(bv); result.dispatched(true); - break; + return result; case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { InsetBoxMailer(*this).showDialog(bv); return DispatchResult(true); } - // fallthrough: + return InsetCollapsable::priv_dispatch(cmd, idx, pos); default: - result = InsetCollapsable::priv_dispatch(cmd, idx, pos); - break; + return InsetCollapsable::priv_dispatch(cmd, idx, pos); } - - return result; } @@ -349,49 +350,26 @@ int InsetBox::docbook(Buffer const & buf, std::ostream & os, int InsetBox::plaintext(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const { - int i = 0; - string const pt = params_.type; - BoxType btype = boxtranslator().find(params_.type); + BoxType const btype = boxtranslator().find(params_.type); + switch (btype) { - case Frameless: - break; - case Boxed: - os << "["; - break; - case ovalbox: - os << "("; - break; - case Ovalbox: - os << "(("; - break; - case Shadowbox: - os << "["; - break; - case Doublebox: - os << "[["; - break; + case Frameless: break; + case Boxed: os << "["; break; + case ovalbox: os << "("; break; + case Ovalbox: os << "(("; break; + case Shadowbox: os << "["; break; + case Doublebox: os << "[["; break; } - i = inset.plaintext(buf, os, runparams); + int i = inset.plaintext(buf, os, runparams); switch (btype) { - case Frameless: - break; - case Boxed: - os << "]"; - break; - case ovalbox: - os << ")"; - break; - case Ovalbox: - os << "))"; - break; - case Shadowbox: - os << "]/"; - break; - case Doublebox: - os << "]]"; - break; + case Frameless: break; + case Boxed: os << "]"; break; + case ovalbox: os << ")"; break; + case Ovalbox: os << "))"; break; + case Shadowbox: os << "]/"; break; + case Doublebox: os << "]]"; break; } return i; diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h index 70baad6188..7c684b8150 100644 --- a/src/insets/insetbox.h +++ b/src/insets/insetbox.h @@ -78,6 +78,8 @@ public: /// show the Box dialog bool showInsetDialog(BufferView * bv) const; /// + bool display() const { return false; } + /// int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index a525d20181..9194111ad7 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -39,12 +39,10 @@ using std::ostream; InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed) - : UpdatableInset(), inset(bp), collapsed_(collapsed), - button_dim(0, 0, 0, 0), label("Label"), + : UpdatableInset(), inset(bp), collapsed_(collapsed), label("Label") #if 0 - autocollapse(false), + ,autocollapse(false) #endif - in_update(false), first_after_edit(false) { inset.setOwner(this); inset.setAutoBreakRows(true); @@ -56,11 +54,10 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed) InsetCollapsable::InsetCollapsable(InsetCollapsable const & in) : UpdatableInset(in), inset(in.inset), collapsed_(in.collapsed_), - labelfont_(in.labelfont_), button_dim(0, 0, 0, 0), label(in.label), + labelfont_(in.labelfont_), label(in.label) #if 0 - autocollapse(in.autocollapse), + ,autocollapse(in.autocollapse) #endif - in_update(false), first_after_edit(false) { inset.setOwner(this); } @@ -128,6 +125,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = max(dim.wid, insetdim.wid); } dim_ = dim; + //lyxerr << "InsetCollapsable::metrics: dim.wid: " << dim.wid << endl; } @@ -161,11 +159,10 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const top_x = x; top_baseline = y; - int const bl = y - aa + dim_collapsed.ascent(); - if (inlined) { inset.draw(pi, x, y); } else { + int const bl = y - aa + dim_collapsed.ascent(); draw_collapsed(pi, old_x, bl); inset.draw(pi, x, bl + dim_collapsed.descent() + inset.ascent()); } @@ -185,59 +182,52 @@ InsetOld::EDITABLE InsetCollapsable::editable() const } -void InsetCollapsable::insetUnlock(BufferView * bv) -{ -#if 0 - if (autocollapse) { - if (change_label_with_text) { - draw_label = get_new_label(); - } else { - draw_label = label; - } - collapsed_ = true; - } -#endif - inset.insetUnlock(bv); - if (scroll()) - scroll(bv, 0.0F); - bv->updateInset(this); -} - - FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd) { FuncRequest cmd1 = cmd; - cmd1.y = ascent() + cmd.y - (height_collapsed() + inset.ascent()); + cmd1.y = ascent() + cmd.y - height_collapsed() - inset.ascent(); return cmd1; } -void InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) +DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) { - bool ret = false; + DispatchResult result(true, true); BufferView * bv = cmd.view(); - if (collapsed_ && cmd.button() != mouse_button::button3) { - collapsed_ = false; - bv->updateInset(this); - bv->buffer()->markDirty(); - return; - } - - if (cmd.button() != mouse_button::button3 && hitButton(cmd)) { + if (cmd.button() == mouse_button::button3) { + lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl; + if (hitButton(cmd)) + showInsetDialog(bv); + } else { if (collapsed_) { + lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; collapsed_ = false; - } else { - collapsed_ = true; - bv->unlockInset(this); + bv->updateInset(this); + bv->buffer()->markDirty(); + return result; + } + + if (hitButton(cmd)) { + if (collapsed_) { + lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; + collapsed_ = false; + } else { + collapsed_ = true; + result.update(true); + result.val(FINISHED_RIGHT); + return result; + } + result.update(true); + bv->updateInset(this); + bv->buffer()->markDirty(); + } else if (!collapsed_ && cmd.y > button_dim.y2) { + lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; + result = inset.dispatch(adjustCommand(cmd)); } - bv->updateInset(this); - bv->buffer()->markDirty(); - } else if (!collapsed_ && cmd.y > button_dim.y2) { - ret = inset.dispatch(adjustCommand(cmd)) == DispatchResult(true, true); } - if (cmd.button() == mouse_button::button3 && !ret) - showInsetDialog(bv); + lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl; + return result; } @@ -278,36 +268,11 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const void InsetCollapsable::edit(BufferView * bv, bool left) { lyxerr << "InsetCollapsable: edit left/right" << endl; - if (!bv->lockInset(this)) - lyxerr << "InsetCollapsable: can't lock" << endl; - bv->cursor().push(this, inset.getText(0)); + bv->cursor().push(this); inset.edit(bv, left); - first_after_edit = true; open(bv); } -/* - if (!cmd.argument.empty()) { - UpdatableInset::edit( - if (collapsed_) { - lyxerr << "branch collapsed_" << endl; - collapsed_ = false; - if (bv->lockInset(this)) { - bv->updateInset(this); - bv->buffer()->markDirty(); - inset.dispatch(cmd); - first_after_edit = true; - } - } else { - lyxerr << "branch not collapsed_" << endl; - if (bv->lockInset(this)) - inset.dispatch(cmd); - } - return; - } - UpdatableInset::edit(cmd, idx, pos); -*/ - void InsetCollapsable::edit(BufferView * bv, int x, int y) { @@ -316,30 +281,25 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) collapsed_ = false; // set this only here as it should be recollapsed only if // it was already collapsed! - first_after_edit = true; - if (!bv->lockInset(this)) - return; bv->updateInset(this); bv->buffer()->markDirty(); inset.edit(bv, x, y); } else { - if (!bv->lockInset(this)) - return; if (y <= button_dim.y2) inset.edit(bv, x, 0); else inset.edit(bv, x, - ascent() + y - (height_collapsed() + inset.ascent())); + ascent() + y - height_collapsed() + inset.ascent()); } - bv->cursor().push(this, inset.getText(0)); + bv->cursor().push(this); } DispatchResult InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) { - //lyxerr << "InsetCollapsable::localDispatch: " - // << cmd.action << " '" << cmd.argument << "'\n"; + lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd + << " button y: " << button_dim.y2 << endl; switch (cmd.action) { case LFUN_MOUSE_PRESS: if (!collapsed_ && cmd.y > button_dim.y2) @@ -352,39 +312,22 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - lfunMouseRelease(cmd); + if (!collapsed_ && cmd.y > button_dim.y2) + inset.dispatch(adjustCommand(cmd)); + else + return lfunMouseRelease(cmd); return DispatchResult(true, true); default: - DispatchResult const result = inset.dispatch(cmd); - first_after_edit = false; - return result; - } -} - - -bool InsetCollapsable::lockInsetInInset(BufferView * bv, UpdatableInset * in) -{ - if (&inset == in) - return true; - return inset.lockInsetInInset(bv, in); -} - - -bool InsetCollapsable::unlockInsetInInset(BufferView * bv, UpdatableInset * in, - bool lr) -{ - if (&inset == in) { - bv->unlockInset(this); - return true; + return inset.dispatch(cmd); } - return inset.unlockInsetInInset(bv, in, lr); + lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl; } int InsetCollapsable::insetInInsetY() const { - return inset.insetInInsetY() - (top_baseline - inset.y()); + return inset.y() - top_baseline + inset.insetInInsetY(); } @@ -394,32 +337,10 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const } -void InsetCollapsable::getCursor(BufferView & bv, int & x, int & y) const -{ - inset.getCursor(bv, x, y); -} - - void InsetCollapsable::getCursorPos(BufferView * bv, int & x, int & y) const { inset.getCursorPos(bv, x , y); -} - - -UpdatableInset * InsetCollapsable::getLockingInset() const -{ - UpdatableInset * in = inset.getLockingInset(); - if (&inset == in) - return const_cast(this); - return in; -} - - -UpdatableInset * InsetCollapsable::getFirstLockingInsetOfType(InsetOld::Code c) -{ - if (c == lyxCode()) - return this; - return inset.getFirstLockingInsetOfType(c); + y += - ascent() + height_collapsed() + inset.ascent(); } @@ -430,13 +351,6 @@ void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font, } -LyXText * InsetCollapsable::getLyXText(BufferView const * bv, - bool const recursive) const -{ - return inset.getLyXText(bv, recursive); -} - - void InsetCollapsable::deleteLyXText(BufferView * bv, bool recursive) const { inset.deleteLyXText(bv, recursive); @@ -479,12 +393,6 @@ LyXText * InsetCollapsable::getText(int i) const } -LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const -{ - return inset.cursor(bv); -} - - void InsetCollapsable::open(BufferView * bv) { if (!collapsed_) @@ -527,3 +435,52 @@ void InsetCollapsable::addPreview(PreviewLoader & loader) const { inset.addPreview(loader); } + + +bool InsetCollapsable::insetAllowed(InsetOld::Code code) const +{ + return inset.insetAllowed(code); +} + + +void InsetCollapsable::fitInsetCursor(BufferView * bv) const +{ + inset.fitInsetCursor(bv); +} + + +void InsetCollapsable::setLabelFont(LyXFont & f) +{ + labelfont_ = f; +} + +#if 0 +void InsetCollapsable::setAutoCollapse(bool f) +{ + autocollapse = f; +} +#endif + +void InsetCollapsable::scroll(BufferView *bv, float sx) const +{ + UpdatableInset::scroll(bv, sx); +} + + +void InsetCollapsable::scroll(BufferView *bv, int offset) const +{ + UpdatableInset::scroll(bv, offset); +} + + +bool InsetCollapsable::isOpen() const +{ + return !collapsed_; +} + + +Box const & InsetCollapsable::buttonDim() const +{ + return button_dim; +} + diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 689b562155..66e10b093f 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -55,16 +55,9 @@ public: /// bool insertInset(BufferView *, InsetOld * inset); /// - virtual bool insetAllowed(InsetOld::Code code) const; + bool insetAllowed(InsetOld::Code code) const; /// - bool isTextInset() const; - /// - void insetUnlock(BufferView *); - /// - bool lockInsetInInset(BufferView *, UpdatableInset *); - /// - bool unlockInsetInInset(BufferView *, UpdatableInset *, - bool lr = false); + bool isTextInset() const { return true; } /// int insetInInsetY() const; /// @@ -81,17 +74,11 @@ public: OutputParams const & runparams) const; /// void validate(LaTeXFeatures & features) const; - /// FIXME, document + /// get the screen x,y of the cursor void getCursorPos(BufferView *, int & x, int & y) const; - /// Get the absolute document x,y of the cursor - virtual void getCursor(BufferView &, int &, int &) const; /// void fitInsetCursor(BufferView * bv) const; /// - UpdatableInset * getLockingInset() const; - /// - UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code); - /// void setFont(BufferView *, LyXFont const &, bool toggleall = false, bool selectall = false); /// @@ -102,8 +89,6 @@ public: /// void setAutoCollapse(bool f); #endif - /// - LyXText * getLyXText(BufferView const *, bool const recursive) const; /// void deleteLyXText(BufferView *, bool recursive=true) const; /// Appends \c list with all labels found within this inset. @@ -121,18 +106,15 @@ public: /// LyXText * getText(int) const; /// - LyXCursor const & cursor(BufferView *) const; - /// - virtual bool display() const { return isOpen(); } + bool display() const { return isOpen(); } /// bool isOpen() const; /// void open(BufferView *); /// void close(BufferView *) const; - + /// void markErased(); - /// void addPreview(lyx::graphics::PreviewLoader &) const; @@ -157,12 +139,10 @@ protected: void edit(BufferView *, bool); /// void edit(BufferView *, int, int); - /// - UpdatableInset * lockingInset() const { return inset.lockingInset(); } private: /// - void lfunMouseRelease(FuncRequest const &); + DispatchResult lfunMouseRelease(FuncRequest const &); /// FuncRequest adjustCommand(FuncRequest const &); @@ -178,80 +158,14 @@ private: mutable Box button_dim; /// mutable int topx; + /// mutable int topbaseline; - /// mutable std::string label; #if 0 /// bool autocollapse; #endif - /// - bool in_update; - /// - mutable bool first_after_edit; }; - -inline -bool InsetCollapsable::insetAllowed(InsetOld::Code code) const -{ - return inset.insetAllowed(code); -} - - -inline -bool InsetCollapsable::isTextInset() const -{ - return true; -} - - -inline -void InsetCollapsable::fitInsetCursor(BufferView * bv) const -{ - inset.fitInsetCursor(bv); -} - -inline -void InsetCollapsable::setLabelFont(LyXFont & f) -{ - labelfont_ = f; -} - -#if 0 -inline -void InsetCollapsable::setAutoCollapse(bool f) -{ - autocollapse = f; -} -#endif - -inline -void InsetCollapsable::scroll(BufferView *bv, float sx) const -{ - UpdatableInset::scroll(bv, sx); -} - - -inline -void InsetCollapsable::scroll(BufferView *bv, int offset) const -{ - UpdatableInset::scroll(bv, offset); -} - - -inline -bool InsetCollapsable::isOpen() const -{ - return !collapsed_; -} - - -inline -Box const & InsetCollapsable::buttonDim() const -{ - return button_dim; -} - #endif diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 7d51c0a0ea..03cd6fee24 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -8,6 +8,7 @@ * * Full author contact details are available in file CREDITS. */ + #include #include "insetert.h" @@ -59,10 +60,7 @@ void InsetERT::init() InsetERT::InsetERT(BufferParams const & bp, bool collapsed) : InsetCollapsable(bp, collapsed) { - if (collapsed) - status_ = Collapsed; - else - status_ = Open; + status_ = collapsed ? Collapsed : Open; init(); } @@ -84,10 +82,7 @@ InsetERT::InsetERT(BufferParams const & bp, Language const * l, string const & contents, bool collapsed) : InsetCollapsable(bp, collapsed) { - if (collapsed) - status_ = Collapsed; - else - status_ = Open; + status_ = collapsed ? Collapsed : Open; LyXFont font(LyXFont::ALL_INHERIT, l); #ifdef SET_HARD_FONT @@ -140,21 +135,6 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex) lex.pushToken(token); } } -#if 0 -#warning this should be really short lived only for compatibility to -#warning files written 07/08/2001 so this has to go before 1.2.0! (Jug) - if (lex.isOK()) { - lex.next(); - string const token = lex.getString(); - if (token == "collapsed") { - lex.next(); - setCollapsed(lex.getBool()); - } else { - // Take countermeasures - lex.pushToken(token); - } - } -#endif inset.read(buf, lex); #ifdef SET_HARD_FONT @@ -198,8 +178,7 @@ void InsetERT::write(Buffer const & buf, ostream & os) const break; } - os << getInsetName() << "\n" - << "status "<< st << "\n"; + os << getInsetName() << "\n" << "status "<< st << "\n"; //inset.writeParagraphData(buf, os); string const layout(buf.params().getLyXTextClass().defaultLayoutName()); @@ -271,9 +250,7 @@ void InsetERT::updateStatus(BufferView * bv, bool swap) const InsetOld::EDITABLE InsetERT::editable() const { - if (status_ == Collapsed) - return IS_EDITABLE; - return HIGHLY_EDITABLE; + return (status_ == Collapsed) ? IS_EDITABLE : HIGHLY_EDITABLE; } @@ -308,7 +285,7 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd) // inlined is special - the text appears above if (status_ == Inlined) inset.dispatch(cmd1); - else if (isOpen() && (cmd.y > buttonDim().y2)) { + else if (isOpen() && cmd.y > buttonDim().y2) { cmd1.y -= height_collapsed(); inset.dispatch(cmd1); } @@ -427,8 +404,6 @@ int InsetERT::docbook(Buffer const &, ostream & os, void InsetERT::edit(BufferView * bv, bool left) { if (status_ == Inlined) { - if (!bv->lockInset(this)) - return; inset.edit(bv, left); } else { InsetCollapsable::edit(bv, left); @@ -439,8 +414,7 @@ void InsetERT::edit(BufferView * bv, bool left) DispatchResult -InsetERT::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { BufferView * bv = cmd.view(); @@ -452,16 +426,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, case LFUN_INSET_MODIFY: { InsetERT::ERTStatus status_; InsetERTMailer::string2params(cmd.argument, status_); - status(bv, status_); - - /* FIXME: I refuse to believe we have to live - * with ugliness like this ! Note that this - * rebreak *is* needed. Consider a change from - * Open (needfullrow) to Inlined (only the space - * taken by the text). - */ - inset.getLyXText(cmd.view())->fullRebreak(); bv->updateInset(this); return DispatchResult(true, true); } @@ -491,7 +456,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, case LFUN_DELETE_LINE_FORWARD: case LFUN_CUT: set_latex_font(bv); - return DispatchResult(false); + return InsetCollapsable::priv_dispatch(cmd, idx, pos); default: return InsetCollapsable::priv_dispatch(cmd, idx, pos); @@ -507,7 +472,7 @@ string const InsetERT::get_new_label() const pos_type const n = min(max_length, p_siz); pos_type i = 0; pos_type j = 0; - for(; i < n && j < p_siz; ++j) { + for( ; i < n && j < p_siz; ++j) { if (inset.paragraphs.begin()->isInset(j)) continue; la += inset.paragraphs.begin()->getChar(j); @@ -525,19 +490,14 @@ string const InsetERT::get_new_label() const void InsetERT::setButtonLabel() const { - if (status_ == Collapsed) { - setLabel(get_new_label()); - } else { - setLabel(_("ERT")); - } + setLabel(status_ == Collapsed ? get_new_label() : _("ERT")); } bool InsetERT::checkInsertChar(LyXFont & /* font */) { #ifdef SET_HARD_FONT - LyXFont f(LyXFont::ALL_INHERIT, latex_language); - font = f; + LyXFont font(LyXFont::ALL_INHERIT, latex_language); font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); #endif @@ -566,15 +526,13 @@ void InsetERT::draw(PainterInfo & pi, int x, int y) const } -void InsetERT::set_latex_font(BufferView * /* bv */) +void InsetERT::set_latex_font(BufferView * /*bv*/) { #ifdef SET_HARD_FONT LyXFont font(LyXFont::ALL_INHERIT, latex_language); - font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); - - inset.getLyXText(bv)->setFont(bv, font, false); + inset.text_.setFont(bv, font, false); #endif } @@ -582,26 +540,29 @@ void InsetERT::set_latex_font(BufferView * /* bv */) // attention this function can be called with bv == 0 void InsetERT::status(BufferView * bv, ERTStatus const st) const { - if (st != status_) { - status_ = st; - switch (st) { - case Inlined: - break; - case Open: - setCollapsed(false); - setButtonLabel(); - break; - case Collapsed: - setCollapsed(true); - setButtonLabel(); - if (bv) - bv->unlockInset(const_cast(this)); - break; - } - if (bv) { - bv->updateInset(this); - bv->buffer()->markDirty(); - } + if (st == status_) + return; + + status_ = st; + switch (st) { + case Inlined: + break; + case Open: + setCollapsed(false); + setButtonLabel(); + break; + case Collapsed: + setCollapsed(true); + setButtonLabel(); +#ifdef LOCK + if (bv) + bv->unlockInset(); +#endif + break; + } + if (bv) { + bv->updateInset(this); + bv->buffer()->markDirty(); } } @@ -615,9 +576,8 @@ bool InsetERT::showInsetDialog(BufferView * bv) const void InsetERT::open(BufferView * bv) { - if (isOpen()) - return; - status(bv, Open); + if (!isOpen()) + status(bv, Open); } @@ -632,8 +592,7 @@ void InsetERT::close(BufferView * bv) const void InsetERT::getDrawFont(LyXFont & font) const { - LyXFont f(LyXFont::ALL_INHERIT, latex_language); - font = f; + font = LyXFont(LyXFont::ALL_INHERIT, latex_language); font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); } @@ -667,8 +626,7 @@ void InsetERTMailer::string2params(string const & in, } -string const -InsetERTMailer::params2string(InsetERT::ERTStatus status) +string const InsetERTMailer::params2string(InsetERT::ERTStatus status) { return name_ + ' ' + tostr(status); } diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index b08be76012..e5510c4bdc 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -366,9 +366,7 @@ bool InsetFloat::insetAllowed(InsetOld::Code code) const { if (code == InsetOld::FLOAT_CODE) return false; - if (inset.getLockingInset() != const_cast(this)) - return inset.insetAllowed(code); - if ((code == InsetOld::FOOT_CODE) || (code == InsetOld::MARGIN_CODE)) + if (code == InsetOld::FOOT_CODE || code == InsetOld::MARGIN_CODE) return false; return true; } @@ -376,11 +374,8 @@ bool InsetFloat::insetAllowed(InsetOld::Code code) const bool InsetFloat::showInsetDialog(BufferView * bv) const { - if (!inset.showInsetDialog(bv)) { - InsetFloat * tmp = const_cast(this); - InsetFloatMailer mailer(*tmp); - mailer.showDialog(bv); - } + if (!inset.showInsetDialog(bv)) + InsetFloatMailer(const_cast(*this)).showDialog(bv); return true; } @@ -388,13 +383,9 @@ bool InsetFloat::showInsetDialog(BufferView * bv) const void InsetFloat::wide(bool w, BufferParams const & bp) { params_.wide = w; - - string lab(_("float: ")); - lab += floatname(params_.type, bp); - + string lab = _("float: ") + floatname(params_.type, bp); if (params_.wide) lab += '*'; - setLabel(lab); } diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 8de88ef3ab..bb9ca07133 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -104,13 +104,8 @@ InsetMinipage::priv_dispatch(FuncRequest const & cmd, case LFUN_INSET_MODIFY: { InsetMinipage::Params params; InsetMinipageMailer::string2params(cmd.argument, params); - params_.pos = params.pos; params_.width = params.width; - - /* FIXME: I refuse to believe we have to live - * with ugliness like this ... */ - inset.getLyXText(cmd.view())->fullRebreak(); cmd.view()->updateInset(this); return DispatchResult(true, true); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 72cfc70916..e140e3abcc 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -44,6 +44,7 @@ using lyx::graphics::PreviewLoader; using lyx::support::ltrim; using lyx::support::strToInt; +using lyx::support::strToDbl; using std::endl; using std::max; @@ -153,17 +154,11 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns) buffer_(&buf), cursorx_(0), cursory_(0) { tabular.setOwner(this); - // for now make it always display as display() inset - // just for test!!! the_locking_inset = 0; - old_locking_inset = 0; - locked = false; - oldcell = -1; - actrow = actcell = 0; + actrow = 0; + actcell = 0; clearSelection(); in_reset_pos = 0; - inset_x = 0; - inset_y = 0; } @@ -173,14 +168,10 @@ InsetTabular::InsetTabular(InsetTabular const & tab) { tabular.setOwner(this); the_locking_inset = 0; - old_locking_inset = 0; - locked = false; - oldcell = -1; - actrow = actcell = 0; + actrow = 0; + actcell = 0; clearSelection(); in_reset_pos = 0; - inset_x = 0; - inset_y = 0; } @@ -202,13 +193,6 @@ Buffer const & InsetTabular::buffer() const } -BufferView * InsetTabular::view() const -{ - BOOST_ASSERT(false); - return 0; -} - - void InsetTabular::buffer(Buffer * b) { buffer_ = b; @@ -268,12 +252,8 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const BufferView * bv = pi.base.bv; -#if 0 - UpdatableInset::draw(pi, x, y); -#else if (!owner()) x += scroll(); -#endif top_x = x; top_baseline = y; @@ -332,7 +312,7 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y, int row, int cell) const { int x2 = x + tabular.getWidthOfColumn(cell); - bool on_off; + bool on_off = false; if (!tabular.topAlreadyDrawn(cell)) { on_off = !tabular.topLine(cell); @@ -396,149 +376,24 @@ string const InsetTabular::editMessage() const } -void InsetTabular::insetUnlock(BufferView * bv) -{ - if (the_locking_inset) { - the_locking_inset->insetUnlock(bv); - updateLocal(bv); - the_locking_inset = 0; - } - actcell = 0; - oldcell = -1; - locked = false; - if (scroll(false) || hasSelection()) { - clearSelection(); - if (scroll(false)) - scroll(bv, 0.0F); - updateLocal(bv); - } -} - - void InsetTabular::updateLocal(BufferView * bv) const { bv->updateInset(this); - if (locked) - resetPos(bv); -} - - -bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset) -{ - lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset(" - << inset << "): "; - if (!inset) - return false; - - oldcell = -1; - - if (inset == &tabular.getCellInset(actcell)) { - lyxerr[Debug::INSETTEXT] << "OK" << endl; - the_locking_inset = &tabular.getCellInset(actcell); - resetPos(bv); - return true; - } - - if (!the_locking_inset) { - int const n = tabular.getNumberOfCells(); - for (int i = 0; i < n; ++i) { - InsetText * in = &tabular.getCellInset(i); - if (inset == in) { - actcell = i; - the_locking_inset = in; - locked = true; - resetPos(bv); - return true; - } - if (in->lockInsetInInset(bv, inset)) { - actcell = i; - the_locking_inset = in; - locked = true; - resetPos(bv); - in->edit(bv, true); - return true; - } - } - return false; - } - - if (the_locking_inset && (the_locking_inset == inset)) { - lyxerr[Debug::INSETTEXT] << "OK" << endl; - resetPos(bv); - return false; - } - - if (the_locking_inset) { - lyxerr[Debug::INSETTEXT] << "MAYBE" << endl; - return the_locking_inset->lockInsetInInset(bv, inset); - } - - lyxerr[Debug::INSETTEXT] << "NOT OK" << endl; - return false; -} - - -bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset, - bool lr) -{ - if (!the_locking_inset) - return false; - if (the_locking_inset == inset) { - the_locking_inset->insetUnlock(bv); -#ifdef WITH_WARNINGS -#warning fix scrolling when cellinset has requested a scroll (Jug)!!! -#endif -#if 0 - if (scroll(false)) - scroll(bv, 0.0F); -#endif - updateLocal(bv); - // this has to be here otherwise we don't redraw the cell! - the_locking_inset = 0; - return true; - } - if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) { - if (inset->lyxCode() == TABULAR_CODE && - !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) { - InsetTabularMailer(*this).updateDialog(bv); - oldcell = actcell; - } - return true; - } - return false; + resetPos(bv); } int InsetTabular::insetInInsetY() const { - if (!the_locking_inset) - return 0; - return inset_y + the_locking_inset->insetInInsetY(); -} - - -UpdatableInset * InsetTabular::getLockingInset() const -{ - return the_locking_inset ? the_locking_inset->getLockingInset() : - const_cast(this); -} - - -UpdatableInset * InsetTabular::getFirstLockingInsetOfType(InsetOld::Code c) -{ - if (c == lyxCode()) - return this; if (the_locking_inset) - return the_locking_inset->getFirstLockingInsetOfType(c); + return cursory_ + the_locking_inset->insetInInsetY(); return 0; } bool InsetTabular::insertInset(BufferView * bv, InsetOld * inset) { - if (the_locking_inset) - return the_locking_inset->insertInset(bv, inset); - return false; + return the_locking_inset && the_locking_inset->insertInset(bv, inset); } @@ -547,96 +402,38 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd) if (hasSelection() && cmd.button() == mouse_button::button3) return; - if (hasSelection()) { + if (hasSelection()) clearSelection(); - updateLocal(cmd.view()); - } - int const ocell = actcell; BufferView * bv = cmd.view(); - if (!locked) { - locked = true; - the_locking_inset = 0; - inset_x = 0; - inset_y = 0; - } + the_locking_inset = 0; setPos(bv, cmd.x, cmd.y); clearSelection(); + the_locking_inset = 0; - bool const inset_hit = insetHit(bv, cmd.x, cmd.y); - - if (ocell == actcell && the_locking_inset && inset_hit) { - resetPos(bv); - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - the_locking_inset->dispatch(cmd1); - return; - } - - if (the_locking_inset) { - the_locking_inset->insetUnlock(bv); - updateLocal(bv); - the_locking_inset = 0; - } - - if (cmd.button() == mouse_button::button2) { + if (cmd.button() == mouse_button::button2) dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph")); - return; - } - - if (inset_hit && bv->theLockingInset()) { - if (!bv->lockInset(&tabular.getCellInset(actcell))) { - lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; - return; - } - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - the_locking_inset->dispatch(cmd1); - } } -bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd) +void InsetTabular::lfunMouseRelease(FuncRequest const & cmd) { - DispatchResult ret(false); - if (the_locking_inset) { - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - ret = the_locking_inset->dispatch(cmd1); - } - if (cmd.button() == mouse_button::button3 && ret == DispatchResult(false)) { + if (cmd.button() == mouse_button::button3) InsetTabularMailer(*this).showDialog(cmd.view()); - return true; - } - return ret.dispatched() || ret.val() > FINISHED; } void InsetTabular::lfunMouseMotion(FuncRequest const & cmd) { - if (the_locking_inset) { - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - the_locking_inset->dispatch(cmd1); - return; - } - BufferView * bv = cmd.view(); int const old_cell = actcell; setPos(bv, cmd.x, cmd.y); - if (!hasSelection()) { + if (!hasSelection()) setSelection(actcell, actcell); - updateLocal(bv); - } else if (old_cell != actcell) { + else if (old_cell != actcell) setSelection(sel_cell_start, actcell); - updateLocal(bv); - } } @@ -646,16 +443,8 @@ void InsetTabular::edit(BufferView * bv, bool left) << " first text: " << tabular.cell_info[0][0].inset.getText(0) << " first cell: " << &tabular.cell_info[0][0].inset << endl; - if (!bv->lockInset(this)) { - lyxerr << "InsetTabular::Cannot lock inset" << endl; - return; - } - finishUndo(); - locked = true; the_locking_inset = 0; - inset_x = 0; - inset_y = 0; if (left) { if (isRightToLeft(bv)) @@ -671,7 +460,7 @@ void InsetTabular::edit(BufferView * bv, bool left) clearSelection(); resetPos(bv); bv->fitCursor(); - bv->cursor().push(this, 0); + bv->cursor().push(this); } @@ -680,122 +469,63 @@ void InsetTabular::edit(BufferView * bv, int x, int y) lyxerr << "InsetTabular::edit: " << this << " first cell " << &tabular.cell_info[0][0].inset << endl; - if (!bv->lockInset(this)) { - lyxerr << "InsetTabular::Cannot lock inset" << endl; - return; - } - finishUndo(); - locked = true; the_locking_inset = 0; - inset_x = 0; - inset_y = 0; - setPos(bv, x, y); clearSelection(); finishUndo(); - if (insetHit(bv, x, y)) { - inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); - inset_y = cursory_; - activateCellInset(bv, x - inset_x, y - inset_y); - } - bv->cursor().push(this, tabular.getCellInset(actcell).getText(0)); + int xx = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); + bv->cursor().push(this); + if (x > xx) + activateCellInset(bv, x - xx, y - cursory_); } DispatchResult -InsetTabular::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) { + lyxerr << "InsetTabular::dispatch: " << cmd << endl; // We need to save the value of the_locking_inset as the call to // the_locking_inset->localDispatch might unlock it. - old_locking_inset = the_locking_inset; - DispatchResult result = UpdatableInset::priv_dispatch(cmd, idx, pos); - BufferView * bv = cmd.view(); - - if (result.dispatched()) { - resetPos(bv); - return result; - } + DispatchResult result(true, true); + BufferView * bv = cmd.view(); + bool hs = hasSelection(); - if (cmd.action < 0 && cmd.argument.empty()) { - lyxerr << "InsetTabular: cursor pop 2" << endl; - bv->cursor().pop(); - return DispatchResult(false, FINISHED); - } + switch (cmd.action) { - bool hs = hasSelection(); + case LFUN_MOUSE_PRESS: + lfunMousePress(cmd); + return DispatchResult(true, true); - result = DispatchResult(true, true); - // this one have priority over the locked InsetText, if we're not already - // inside another tabular then that one get's priority! - if (getFirstLockingInsetOfType(InsetOld::TABULAR_CODE) == this) { - switch (cmd.action) { - case LFUN_MOUSE_PRESS: - lfunMousePress(cmd); - return DispatchResult(true, true); + case LFUN_MOUSE_MOTION: + lfunMouseMotion(cmd); + return DispatchResult(true, true); - case LFUN_MOUSE_MOTION: - lfunMouseMotion(cmd); - return DispatchResult(true, true); + case LFUN_MOUSE_RELEASE: + lfunMouseRelease(cmd); + return DispatchResult(true, true); - case LFUN_MOUSE_RELEASE: - return DispatchResult(lfunMouseRelease(cmd)); + case LFUN_CELL_BACKWARD: + case LFUN_CELL_FORWARD: + if (cmd.action == LFUN_CELL_FORWARD) + moveNextCell(bv, the_locking_inset != 0); + else + movePrevCell(bv, the_locking_inset != 0); + clearSelection(); + if (!the_locking_inset) + return DispatchResult(true); + return result; - case LFUN_CELL_BACKWARD: - case LFUN_CELL_FORWARD: - unlockInsetInInset(bv, the_locking_inset); - if (cmd.action == LFUN_CELL_FORWARD) - moveNextCell(bv, old_locking_inset != 0); + case LFUN_SCROLL_INSET: + if (!cmd.argument.empty()) { + if (cmd.argument.find('.') != cmd.argument.npos) + scroll(cmd.view(), static_cast(strToDbl(cmd.argument))); else - movePrevCell(bv, old_locking_inset != 0); - clearSelection(); - if (hs) - updateLocal(bv); - if (!the_locking_inset) - return DispatchResult(true); - return result; - // this to avoid compiler warnings. - default: - break; - } - } - - kb_action action = cmd.action; - string arg = cmd.argument; - if (the_locking_inset) { - result = the_locking_inset->dispatch(cmd); - if (result.dispatched()) { - if (result.update()) { - updateLocal(bv); - } else { - int const sc = scroll(); - resetPos(bv); - if (sc != scroll()) { - // inset has been scrolled - updateLocal(bv); - } - } - return result; - } else if (result.val() == FINISHED_UP) { - action = LFUN_UP; - // Make sure to reset status message after - // exiting, e.g. math inset - bv->owner()->clearMessage(); - } else if (result.val() == FINISHED_DOWN) { - action = LFUN_DOWN; - bv->owner()->clearMessage(); - } else if (result.val() == FINISHED_RIGHT) { - action = LFUN_RIGHT; - bv->owner()->clearMessage(); - } else if (result.val() == FINISHED) { - bv->owner()->clearMessage(); + scroll(cmd.view(), strToInt(cmd.argument)); + cmd.view()->updateInset(this); + return DispatchResult(true, true); } - } - result = DispatchResult(true, true); - switch (action) { - // --- Cursor Movements ---------------------------------- case LFUN_RIGHTSEL: { int const start = hasSelection() ? sel_cell_start : actcell; if (tabular.isLastCellInRow(actcell)) { @@ -811,15 +541,14 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, end = actcell; } setSelection(start, end); - updateLocal(bv); break; } + case LFUN_RIGHT: - result = moveRight(bv); + result = moveRight(bv, true); clearSelection(); - if (hs) - updateLocal(bv); break; + case LFUN_LEFTSEL: { int const start = hasSelection() ? sel_cell_start : actcell; if (tabular.isFirstCellInRow(actcell)) { @@ -835,15 +564,14 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, end = actcell; } setSelection(start, end); - updateLocal(bv); break; } + case LFUN_LEFT: - result = moveLeft(bv); + result = moveLeft(bv, true); clearSelection(); - if (hs) - updateLocal(bv); break; + case LFUN_DOWNSEL: { int const start = hasSelection() ? sel_cell_start : actcell; int const ocell = actcell; @@ -859,15 +587,14 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, } else { setSelection(start, start); } - updateLocal(bv); + break; } - break; + case LFUN_DOWN: - result = moveDown(bv, old_locking_inset != 0); + result = moveDown(bv, the_locking_inset != 0); clearSelection(); - if (hs) - updateLocal(bv); break; + case LFUN_UPSEL: { int const start = hasSelection() ? sel_cell_start : actcell; int const ocell = actcell; @@ -875,45 +602,42 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // the current cell at the beginning if (hasSelection()) { moveUp(bv, false); - if ((ocell == sel_cell_end) || - (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell))) + if (ocell == sel_cell_end || + tabular.column_of_cell(ocell) > tabular.column_of_cell(actcell)) setSelection(start, tabular.getCellAbove(sel_cell_end)); else setSelection(start, tabular.getLastCellAbove(sel_cell_end)); } else { setSelection(start, start); } - updateLocal(bv); + break; } - break; + case LFUN_UP: - result = moveUp(bv, old_locking_inset != 0); + result = moveUp(bv, the_locking_inset != 0); clearSelection(); - if (hs) - updateLocal(bv); break; + case LFUN_NEXT: { if (hs) clearSelection(); int column = actcol; - unlockInsetInInset(bv, the_locking_inset); - if (bv->top_y() + bv->painter().paperHeight() < - top_baseline + tabular.getHeightOfTabular()) - { - bv->scrollDocView(bv->top_y() + bv->painter().paperHeight()); - actcell = tabular.getCellBelow(first_visible_cell) + column; - } else { - actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column; - } + if (bv->top_y() + bv->painter().paperHeight() + < top_baseline + tabular.getHeightOfTabular()) + { + bv->scrollDocView(bv->top_y() + bv->painter().paperHeight()); + actcell = tabular.getCellBelow(first_visible_cell) + column; + } else { + actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column; + } resetPos(bv); - updateLocal(bv); break; } + case LFUN_PRIOR: { if (hs) clearSelection(); int column = actcol; - unlockInsetInInset(bv, the_locking_inset); if (top_baseline < 0) { bv->scrollDocView(bv->top_y() - bv->painter().paperHeight()); if (top_baseline > 0) @@ -924,9 +648,9 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, actcell = column; } resetPos(bv); - updateLocal(bv); break; } + // none of these make sense for insettabular, // but we must catch them to prevent any // selection from being confused @@ -951,47 +675,84 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_ENDBUF: case LFUN_ENDBUFSEL: break; + case LFUN_LAYOUT_TABULAR: InsetTabularMailer(*this).showDialog(bv); break; + case LFUN_INSET_DIALOG_UPDATE: InsetTabularMailer(*this).updateDialog(bv); break; + case LFUN_TABULAR_FEATURE: - if (!tabularFeatures(bv, arg)) + if (!tabularFeatures(bv, cmd.argument)) result = DispatchResult(false); break; - // insert file functions + + // insert file functions case LFUN_FILE_INSERT_ASCII_PARA: - case LFUN_FILE_INSERT_ASCII: - { - string tmpstr = getContentsOfAsciiFile(bv, arg, false); - if (tmpstr.empty()) - break; - if (insertAsciiString(bv, tmpstr, false)) - updateLocal(bv); - else + case LFUN_FILE_INSERT_ASCII: { + string tmpstr = getContentsOfAsciiFile(bv, cmd.argument, false); + if (!tmpstr.empty() && !insertAsciiString(bv, tmpstr, false)) result = DispatchResult(false); break; } - // cut and paste functions + + case LFUN_LANGUAGE: + case LFUN_EMPH: + case LFUN_BOLD: + case LFUN_NOUN: + case LFUN_CODE: + case LFUN_SANS: + case LFUN_ROMAN: + case LFUN_DEFAULT: + case LFUN_UNDERLINE: + case LFUN_FONT_SIZE: + lyxerr << "font changes not re-implemented for tables after LOCK" << endl; + break; + + case LFUN_FINISHED_LEFT: + lyxerr << "swallow LFUN_FINISHED_LEFT, act: " << actcell << endl; + if (!movePrevCell(bv, false)) + result = DispatchResult(FINISHED); + break; + + case LFUN_FINISHED_RIGHT: + lyxerr << "swallow LFUN_FINISHED_RIGHT, act: " << actcell << endl; + if (!moveNextCell(bv, false)) + result = DispatchResult(FINISHED_RIGHT); + break; + + case LFUN_FINISHED_UP: + lyxerr << "swallow LFUN_FINISHED_UP, act: " << actcell << endl; + result = moveUp(bv, true); + break; + + case LFUN_FINISHED_DOWN: + lyxerr << "swallow LFUN_FINISHED_DOWN, act: " << actcell << endl; + result = moveDown(bv, true); + break; + case LFUN_CUT: - if (!copySelection(bv)) - break; - // no break here! + if (copySelection(bv)) { + recordUndo(bv, Undo::DELETE); + cutSelection(bv->buffer()->params()); + } + break; + case LFUN_DELETE: recordUndo(bv, Undo::DELETE); cutSelection(bv->buffer()->params()); - updateLocal(bv); break; + case LFUN_COPY: if (!hasSelection()) break; finishUndo(); copySelection(bv); break; - case LFUN_PASTESELECTION: - { + + case LFUN_PASTESELECTION: { string const clip = bv->getClipboard(); if (clip.empty()) break; @@ -1062,64 +823,40 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // and executes LFUN_PASTESELECTION in insettext! paste_tabular.reset(); } + // fall through } + case LFUN_PASTE: if (hasPasteBuffer()) { recordUndo(bv, Undo::INSERT); pasteSelection(bv); - updateLocal(bv); break; } - // ATTENTION: the function above has to be PASTE and PASTESELECTION!!! + // fall through + + // ATTENTION: the function above has to be PASTE and PASTESELECTION!!! + default: // handle font changing stuff on selection before we lock the inset // in the default part! result = DispatchResult(false); - if (hs) { - switch(action) { - case LFUN_LANGUAGE: - case LFUN_EMPH: - case LFUN_BOLD: - case LFUN_NOUN: - case LFUN_CODE: - case LFUN_SANS: - case LFUN_ROMAN: - case LFUN_DEFAULT: - case LFUN_UNDERLINE: - case LFUN_FONT_SIZE: - if (bv->dispatch(FuncRequest(bv, action, arg))) - result = DispatchResult(true, true); - break; - default: - break; - } - } // we try to activate the actual inset and put this event down to // the insets dispatch function. - if (result.dispatched() || the_locking_inset) - break; - if (activateCellInset(bv)) { - result = the_locking_inset->dispatch(FuncRequest(bv, action, arg)); + if (!the_locking_inset && activateCellInset(bv)) { + result = the_locking_inset->dispatch(cmd); if (!result.dispatched()) { - unlockInsetInInset(bv, the_locking_inset); // we need to update if this was requested before - updateLocal(bv); - return DispatchResult(false); + result = DispatchResult(false); + break; } if (hs) clearSelection(); - updateLocal(bv); - return result; } break; } - if (result.val() >= FINISHED) { - bv->unlockInset(this); - } - else if (!the_locking_inset && bv->fitCursor()) - updateLocal(bv); - + updateLocal(bv); + InsetTabularMailer(*this).updateDialog(bv); return result; } @@ -1134,11 +871,8 @@ int InsetTabular::latex(Buffer const & buf, ostream & os, int InsetTabular::plaintext(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - if (runparams.linelen > 0) - return tabular.plaintext(buf, os, runparams, - ownerPar(buf, this).params().depth(), - false, 0); - return tabular.plaintext(buf, os, runparams, 0, false, 0); + int dp = runparams.linelen ? ownerPar(buf, this).params().depth() : 0; + return tabular.plaintext(buf, os, runparams, dp, false, 0); } @@ -1232,34 +966,10 @@ void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const } -void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const -{ - if (the_locking_inset) { - the_locking_inset->getCursor(bv, x, y); - return; - } - - x = cursorx_; - y = cursory_ + InsetTabular::y(); - - // Fun stuff - int desc = tabular.getDescentOfRow(actrow); - y += desc; - int ascdesc = tabular.getAscentOfRow(actrow) + desc; - y -= ascdesc / 2; - y += ADD_TO_HEIGHT * 2; - y += TEXT_TO_INSET_OFFSET; -} - - -void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const +void InsetTabular::getCursorPos(BufferView *, int & x, int & y) const { - if (the_locking_inset) { - the_locking_inset->getCursorPos(bv, x, y); - return; - } - x = cursorx_ - top_x; - y = cursory_; + x = TEXT_TO_INSET_OFFSET + cursorx_ - top_x; + y = TEXT_TO_INSET_OFFSET + cursory_; } @@ -1282,7 +992,9 @@ void InsetTabular::fitInsetCursor(BufferView * bv) const void InsetTabular::setPos(BufferView * bv, int x, int y) const { cursory_ = 0; - actcell = actrow = actcol = 0; + actcell = 0; + actrow = 0; + actcol = 0; int ly = tabular.getDescentOfRow(actrow); // first search the right row @@ -1318,7 +1030,7 @@ int InsetTabular::getCellXPos(int cell) const for (; c < cell; ++c) lx += tabular.getWidthOfColumn(c); - return (lx - tabular.getWidthOfColumn(cell) + top_x); + return lx - tabular.getWidthOfColumn(cell) + top_x; } @@ -1343,17 +1055,12 @@ void InsetTabular::resetPos(BufferView * bv) const ++actrow; } } - if (!locked) { - if (the_locking_inset) - inset_y = cursory_; - return; - } + // we need this only from here on!!! ++in_reset_pos; int const offset = ADD_TO_TABULAR_WIDTH + 2; - int new_x = getCellXPos(actcell); + int new_x = getCellXPos(actcell) + offset; int old_x = cursorx_; - new_x += offset; cursorx_ = new_x; // cursor.x(getCellXPos(actcell) + offset); if (actcol < tabular.columns() - 1 && scroll(false) && @@ -1364,9 +1071,9 @@ void InsetTabular::resetPos(BufferView * bv) const } else if (the_locking_inset && tabular.getWidthOfColumn(actcell) > bv->workWidth() - 20) { - int xx = cursorx_ - offset + bv->text->getRealCursorX(); + int xx = cursorx_ - offset; if (xx > bv->workWidth()-20) { - scroll(bv, -(xx - bv->workWidth() + 60)); + scroll(bv, - xx + bv->workWidth() - 60); updateLocal(bv); } else if (xx < 20) { if (xx < 0) @@ -1379,43 +1086,31 @@ void InsetTabular::resetPos(BufferView * bv) const } else if (cursorx_ - offset > 20 && cursorx_ - offset + tabular.getWidthOfColumn(actcell) > bv->workWidth() - 20) { - scroll(bv, -tabular.getWidthOfColumn(actcell) - 20); + scroll(bv, - tabular.getWidthOfColumn(actcell) - 20); updateLocal(bv); } else if (cursorx_ - offset < 20) { scroll(bv, 20 - cursorx_ + offset); updateLocal(bv); } else if (scroll() && top_x > 20 && - (top_x + tabular.getWidthOfTabular()) > bv->workWidth() - 20) { + top_x + tabular.getWidthOfTabular() > bv->workWidth() - 20) { scroll(bv, old_x - cursorx_); updateLocal(bv); } - if (the_locking_inset) { - inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); - inset_y = cursory_; - } - if ((!the_locking_inset || - !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) && - actcell != oldcell) { - InsetTabularMailer(*this).updateDialog(bv); - oldcell = actcell; - } + InsetTabularMailer(*this).updateDialog(bv); in_reset_pos = 0; } DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock) { - if (lock && !old_locking_inset) { + if (lock) { if (activateCellInset(bv)) return DispatchResult(true, true); } else { bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv); - if (!moved) { - lyxerr << "InsetTabular: cursor pop 3" << endl; - bv->cursor().pop(); + if (!moved) return DispatchResult(false, FINISHED_RIGHT); - } if (lock && activateCellInset(bv)) return DispatchResult(true, true); } @@ -1427,11 +1122,8 @@ DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock) DispatchResult InsetTabular::moveLeft(BufferView * bv, bool lock) { bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv); - if (!moved) { - lyxerr << "InsetTabular: cursor pop 4" << endl; - bv->cursor().pop(); + if (!moved) return DispatchResult(false, FINISHED); - } // behind the inset if (lock && activateCellInset(bv, 0, 0, true)) return DispatchResult(true, true); @@ -1445,22 +1137,12 @@ DispatchResult InsetTabular::moveUp(BufferView * bv, bool lock) int const ocell = actcell; actcell = tabular.getCellAbove(actcell); if (actcell == ocell) { // we moved out of the inset - lyxerr << "InsetTabular: cursor pop 5" << endl; - bv->cursor().pop(); return DispatchResult(false, FINISHED_UP); } resetPos(bv); - if (lock) { - int x = 0; - int y = 0; - if (old_locking_inset) { - old_locking_inset->getCursorPos(bv, x, y); - x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell); - } - if (activateCellInset(bv, x, 0)) - return DispatchResult(true, true); - } - return DispatchResult(true); + if (lock) + activateCellInset(bv, bv->x_target(), 0); + return DispatchResult(true, true); } @@ -1469,22 +1151,12 @@ DispatchResult InsetTabular::moveDown(BufferView * bv, bool lock) int const ocell = actcell; actcell = tabular.getCellBelow(actcell); if (actcell == ocell) { // we moved out of the inset - lyxerr << "InsetTabular: cursor pop 6" << endl; - bv->cursor().pop(); return DispatchResult(false, FINISHED_DOWN); } resetPos(bv); - if (lock) { - int x = 0; - int y = 0; - if (old_locking_inset) { - old_locking_inset->getCursorPos(bv, x, y); - x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell); - } - if (activateCellInset(bv, x, 0)) - return DispatchResult(true, true); - } - return DispatchResult(true); + if (lock) + activateCellInset(bv, bv->x_target(), 0); + return DispatchResult(true, true); } @@ -1519,7 +1191,9 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock) bool InsetTabular::movePrevCell(BufferView * bv, bool lock) { + lyxerr << "move prevcell 1" << endl; if (isRightToLeft(bv)) { + lyxerr << "move prevcell a" << endl; if (tabular.isLastCellInRow(actcell)) { int row = tabular.row_of_cell(actcell); if (row == 0) @@ -1532,16 +1206,20 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock) ++actcell; } } else { - if (!actcell) // first cell + lyxerr << "move prevcell b" << endl; + if (actcell == 0) // first cell return false; --actcell; } + lyxerr << "move prevcell 2" << endl; if (lock) { bool rtl = tabular.getCellInset(actcell).paragraphs.begin()-> isRightToLeftPar(bv->buffer()->params()); activateCellInset(bv, 0, 0, !rtl); } + lyxerr << "move prevcell 3" << endl; resetPos(bv); + lyxerr << "move prevcell 4" << endl; return true; } @@ -1693,17 +1371,7 @@ void InsetTabular::tabularFeatures(BufferView * bv, case LyXTabular::SET_PWIDTH: { LyXLength const len(value); - LyXLength const & oldlen = tabular.getColumnPWidth(actcell); - tabular.setColumnPWidth(actcell, len); - if (oldlen != len) { - // We need this otherwise we won't resize - // the insettext of the active cell (if any) - // until later (see InsetText::do_resize) - unlockInsetInInset(bv, the_locking_inset); - bv->update(); - } - if (len.zero() && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK) tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string()); @@ -1714,63 +1382,43 @@ void InsetTabular::tabularFeatures(BufferView * bv, } case LyXTabular::SET_MPWIDTH: - { - LyXLength const len(value); - LyXLength const & oldlen = tabular.getPWidth(actcell); - tabular.setMColumnPWidth(actcell, len); - if (oldlen != len) { - // We need this otherwise we won't resize - // the insettext of the active cell (if any) - // until later (see InsetText::do_resize) - unlockInsetInInset(bv, the_locking_inset); - updateLocal(bv); - } - } - break; + tabular.setMColumnPWidth(actcell, LyXLength(value)); + break; case LyXTabular::SET_SPECIAL_COLUMN: case LyXTabular::SET_SPECIAL_MULTI: tabular.setAlignSpecial(actcell,value,feature); - updateLocal(bv); break; case LyXTabular::APPEND_ROW: // append the row into the tabular - unlockInsetInInset(bv, the_locking_inset); tabular.appendRow(bv->buffer()->params(), actcell); tabular.setOwner(this); - updateLocal(bv); break; case LyXTabular::APPEND_COLUMN: // append the column into the tabular - unlockInsetInInset(bv, the_locking_inset); tabular.appendColumn(bv->buffer()->params(), actcell); tabular.setOwner(this); actcell = tabular.getCellNumber(row, column); - updateLocal(bv); break; case LyXTabular::DELETE_ROW: - unlockInsetInInset(bv, the_locking_inset); for (int i = sel_row_start; i <= sel_row_end; ++i) tabular.deleteRow(sel_row_start); if (sel_row_start >= tabular.rows()) --sel_row_start; actcell = tabular.getCellNumber(sel_row_start, column); clearSelection(); - updateLocal(bv); break; case LyXTabular::DELETE_COLUMN: - unlockInsetInInset(bv, the_locking_inset); for (int i = sel_col_start; i <= sel_col_end; ++i) tabular.deleteColumn(sel_col_start); if (sel_col_start >= tabular.columns()) --sel_col_start; actcell = tabular.getCellNumber(row, sel_col_start); clearSelection(); - updateLocal(bv); break; case LyXTabular::M_TOGGLE_LINE_TOP: @@ -1782,7 +1430,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.setTopLine( tabular.getCellNumber(i, j), lineSet, flag); - updateLocal(bv); break; } @@ -1796,7 +1443,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.getCellNumber(i, j), lineSet, flag); - updateLocal(bv); break; } @@ -1810,7 +1456,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.getCellNumber(i,j), lineSet, flag); - updateLocal(bv); break; } @@ -1824,7 +1469,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.getCellNumber(i,j), lineSet, flag); - updateLocal(bv); break; } @@ -1842,7 +1486,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.getCellNumber(i, j), setAlign, flag); - updateLocal(bv); break; case LyXTabular::M_VALIGN_TOP: @@ -1857,7 +1500,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.setVAlignment( tabular.getCellNumber(i, j), setVAlign, flag); - updateLocal(bv); break; case LyXTabular::MULTICOLUMN: { @@ -1876,7 +1518,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.unsetMultiColumn(actcell); else tabular.setMultiColumn(bv->buffer(), actcell, 1); - updateLocal(bv); break; } // we have a selection so this means we just add all this @@ -1894,7 +1535,6 @@ void InsetTabular::tabularFeatures(BufferView * bv, tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1); actcell = s_start; clearSelection(); - updateLocal(bv); break; } @@ -1905,17 +1545,14 @@ void InsetTabular::tabularFeatures(BufferView * bv, for (int j = sel_col_start; j <= sel_col_end; ++j) tabular.setAllLines( tabular.getCellNumber(i,j), setLines); - updateLocal(bv); break; case LyXTabular::SET_LONGTABULAR: tabular.setLongTabular(true); - updateLocal(bv); // because this toggles displayed break; case LyXTabular::UNSET_LONGTABULAR: tabular.setLongTabular(false); - updateLocal(bv); // because this toggles displayed break; case LyXTabular::SET_ROTATE_TABULAR: @@ -1991,6 +1628,7 @@ void InsetTabular::tabularFeatures(BufferView * bv, break; } + updateLocal(bv); InsetTabularMailer(*this).updateDialog(bv); } @@ -2003,10 +1641,8 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind) x = inset.x() + inset.width(); y = inset.descent(); } - //inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); - //inset_y = cursory_; inset.edit(bv, x, y); - bv->cursor().push(&inset, inset.getText(0)); + bv->cursor().push(&inset); if (!the_locking_inset) return false; updateLocal(bv); @@ -2014,27 +1650,12 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind) } -bool InsetTabular::insetHit(BufferView *, int x, int) const -{ - return x + top_x > cursorx_ + tabular.getBeginningOfTextInCell(actcell); -} - - void InsetTabular::deleteLyXText(BufferView * /*bv*/, bool /*recursive*/) const { //resizeLyXText(bv, recursive); } -LyXText * InsetTabular::getLyXText(BufferView const * bv, - bool const recursive) const -{ - if (the_locking_inset) - return the_locking_inset->getLyXText(bv, recursive); - return InsetOld::getLyXText(bv, recursive); -} - - bool InsetTabular::showInsetDialog(BufferView * bv) const { if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) @@ -2045,6 +1666,8 @@ bool InsetTabular::showInsetDialog(BufferView * bv) const void InsetTabular::openLayoutDialog(BufferView * bv) const { +#warning Look here +/* if (the_locking_inset) { InsetTabular * inset = static_cast (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)); @@ -2053,6 +1676,7 @@ void InsetTabular::openLayoutDialog(BufferView * bv) const return; } } +*/ InsetTabularMailer(*this).showDialog(bv); } @@ -2414,19 +2038,11 @@ int InsetTabular::numParagraphs() const LyXText * InsetTabular::getText(int i) const { return i < tabular.getNumberOfCells() - ? tabular.getCellInset(i).getText(0) + ? tabular.getCellInset(i).getText(0) : 0; } -LyXCursor const & InsetTabular::cursor(BufferView * bv) const -{ - if (the_locking_inset) - return the_locking_inset->cursor(bv); - return InsetOld::cursor(bv); -} - - void InsetTabular::markErased() { for (int cell = 0; cell < tabular.getNumberOfCells(); ++cell) @@ -2434,14 +2050,9 @@ void InsetTabular::markErased() } -bool InsetTabular::insetAllowed(InsetOld::Code code) const +bool InsetTabular::insetAllowed(InsetOld::Code) const { - if (the_locking_inset) - return the_locking_inset->insetAllowed(code); - // we return true here because if the inset is not locked someone - // wants to insert something in one of our insettexts and we generally - // allow to do so. - return true; + return false; } @@ -2526,7 +2137,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, // we can only set this if we are not too far right if (cols < columns) { InsetText & inset = loctab->getCellInset(cell); - LyXFont const font = inset.getLyXText(bv)-> + LyXFont const font = inset.text_. getFont(inset.paragraphs.begin(), 0); inset.setText(buf.substr(op, p - op), font); ++cols; @@ -2537,7 +2148,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, // we can only set this if we are not too far right if (cols < columns) { InsetText & inset = tabular.getCellInset(cell); - LyXFont const font = inset.getLyXText(bv)-> + LyXFont const font = inset.text_. getFont(inset.paragraphs.begin(), 0); inset.setText(buf.substr(op, p - op), font); } @@ -2553,8 +2164,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, // check for the last cell if there is no trailing '\n' if (cell < cells && op < len) { InsetText & inset = loctab->getCellInset(cell); - LyXFont const font = inset.getLyXText(bv)-> - getFont(inset.paragraphs.begin(), 0); + LyXFont const font = inset.text_.getFont(inset.paragraphs.begin(), 0); inset.setText(buf.substr(op, len - op), font); } @@ -2566,9 +2176,10 @@ void InsetTabular::addPreview(PreviewLoader & loader) const { int const rows = tabular.rows(); int const columns = tabular.columns(); - for (int i = 0; i < rows; ++i) + for (int i = 0; i < rows; ++i) { for (int j = 0; j < columns; ++j) tabular.getCellInset(i, j).addPreview(loader); + } } @@ -2635,11 +2246,9 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset) string const InsetTabularMailer::params2string(InsetTabular const & inset) { - Buffer const & buffer = inset.buffer(); - ostringstream data; data << name_ << " \\active_cell " << inset.getActCell() << '\n'; - inset.write(buffer, data); + inset.write(inset.buffer(), data); data << "\\end_inset\n"; return data.str(); } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index e846d153c9..74cfd6798f 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -77,22 +77,11 @@ public: void draw(PainterInfo & pi, int x, int y) const; /// std::string const editMessage() const; - // - void insetUnlock(BufferView *); /// void updateLocal(BufferView *) const; /// - bool lockInsetInInset(BufferView *, UpdatableInset *); - /// - bool unlockInsetInInset(BufferView *, UpdatableInset *, - bool lr = false); - /// int insetInInsetY() const; /// - UpdatableInset * getLockingInset() const; - /// - UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code); - /// bool insertInset(BufferView *, InsetOld *); /// bool insetAllowed(InsetOld::Code code) const; @@ -120,10 +109,8 @@ public: void validate(LaTeXFeatures & features) const; /// InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; } - /// FIXME, document + /// get the absolute screen x,y of the cursor void getCursorPos(BufferView *, int & x, int & y) const; - /// Get the absolute document x,y of the cursor - virtual void getCursor(BufferView &, int &, int &) const; /// bool tabularFeatures(BufferView * bv, std::string const & what); /// @@ -135,9 +122,6 @@ public: void setFont(BufferView *, LyXFont const &, bool toggleall = false, bool selectall = false); /// - LyXText * getLyXText(BufferView const *, - bool const recursive = false) const; - /// void deleteLyXText(BufferView *, bool recursive = true) const; /// void openLayoutDialog(BufferView *) const; @@ -163,8 +147,6 @@ public: int numParagraphs() const; /// LyXText * getText(int) const; - /// - LyXCursor const & cursor(BufferView *) const; /// void markErased(); @@ -182,12 +164,8 @@ public: mutable LyXTabular tabular; /// are some cells selected ? - bool hasSelection() const { - return has_selection; - } + bool hasSelection() const { return has_selection; } - /// - virtual BufferView * view() const; /// Buffer const & buffer() const; @@ -206,11 +184,7 @@ private: /// void lfunMousePress(FuncRequest const &); /// - // the bool return is used to see if we opened a dialog so that we can - // check this from an outer inset and open the dialog of the outer inset - // if that one has one! - /// - bool lfunMouseRelease(FuncRequest const &); + void lfunMouseRelease(FuncRequest const &); /// void lfunMouseMotion(FuncRequest const &); /// @@ -226,13 +200,13 @@ private: /// void setPos(BufferView *, int x, int y) const; /// - DispatchResult moveRight(BufferView *, bool lock = true); + DispatchResult moveRight(BufferView *, bool lock); /// - DispatchResult moveLeft(BufferView *, bool lock = true); + DispatchResult moveLeft(BufferView *, bool lock); /// - DispatchResult moveUp(BufferView *, bool lock = true); + DispatchResult moveUp(BufferView *, bool lock); /// - DispatchResult moveDown(BufferView *, bool lock = true); + DispatchResult moveDown(BufferView *, bool lock); /// bool moveNextCell(BufferView *, bool lock = false); /// @@ -257,8 +231,6 @@ private: bool activateCellInset(BufferView *, int x = 0, int y = 0, bool behind = false); /// - bool insetHit(BufferView * bv, int x, int y) const; - /// bool hasPasteBuffer() const; /// bool copySelection(BufferView *); @@ -269,29 +241,20 @@ private: /// bool isRightToLeft(BufferView *); /// - void getSelection(int & scol, int & ecol, - int & srow, int & erow) const; + void getSelection(int & scol, int & ecol, int & srow, int & erow) const; /// bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste); - /// - UpdatableInset * lockingInset() const { return the_locking_inset; } // // Private structures and variables /// InsetText * the_locking_inset; /// - InsetText * old_locking_inset; - /// Buffer const * buffer_; /// mutable int cursorx_; /// mutable int cursory_; - /// - mutable unsigned int inset_x; - /// - mutable unsigned int inset_y; /// true if a set of cells are selected mutable bool has_selection; /// the starting cell selection nr @@ -301,18 +264,12 @@ private: /// mutable int actcell; /// - mutable int oldcell; - /// mutable int actcol; /// mutable int actrow; /// mutable int first_visible_cell; /// - bool no_selection; - /// - mutable bool locked; - /// mutable int in_reset_pos; }; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index beaf1ab70a..68c7a4ce19 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -28,6 +28,7 @@ #include "lyxfind.h" #include "lyxlex.h" #include "lyxrc.h" +#include "lyxtext.h" #include "metricsinfo.h" #include "output_docbook.h" #include "output_latex.h" @@ -113,12 +114,7 @@ void InsetText::init() for (; pit != end; ++pit) pit->setInsetOwner(this); text_.paragraphs_ = ¶graphs; - - locked = false; - inset_x = 0; - inset_y = 0; no_selection = true; - the_locking_inset = 0; old_par = -1; in_insetAllowed = false; mouse_x = 0; @@ -224,14 +220,13 @@ void InsetText::read(Buffer const & buf, LyXLex & lex) void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const { //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl; - textwidth_ = mi.base.textwidth - 30; + textwidth_ = max(40, mi.base.textwidth - 30); BufferView * bv = mi.base.bv; setViewCache(bv); text_.metrics(mi, dim); dim.asc += TEXT_TO_INSET_OFFSET; dim.des += TEXT_TO_INSET_OFFSET; dim.wid += 2 * TEXT_TO_INSET_OFFSET; - dim.wid = max(dim.wid, 10); dim_ = dim; } @@ -247,6 +242,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const // update our idea of where we are. Clearly, we should // not have to know this information. top_x = x; + top_baseline = y; int const start_x = x; @@ -257,26 +253,16 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const if (backgroundColor() != LColor::background) clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, y); - // no draw is necessary !!! - if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) { - top_baseline = y; - return; - } - bv->hideCursor(); if (!owner()) x += scroll(); - top_baseline = y; - inset_x = cx() - x; - inset_y = cy(); - x += TEXT_TO_INSET_OFFSET; paintTextInset(*bv, text_, x, y); - if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked)) + if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED) drawFrame(pain, start_x); } @@ -321,45 +307,11 @@ string const InsetText::editMessage() const } -void InsetText::insetUnlock(BufferView * bv) -{ - if (the_locking_inset) { - the_locking_inset->insetUnlock(bv); - the_locking_inset = 0; - updateLocal(bv, false); - } - no_selection = true; - locked = false; - - if (text_.selection.set()) - text_.clearSelection(); - else if (owner()) - bv->owner()->setLayout(owner()->getLyXText(bv) - ->cursorPar()->layout()->name()); - else - bv->owner()->setLayout(bv->text->cursorPar()->layout()->name()); - // hack for deleteEmptyParMech - if (!paragraphs.begin()->empty()) - text_.setCursor(0, 0); - else if (paragraphs.size() > 1) - text_.setCursor(1, 0); -} - - -void InsetText::lockInset(BufferView * bv) +void InsetText::sanitizeEmptyText(BufferView * bv) { - locked = true; - the_locking_inset = 0; - inset_x = inset_y = 0; - inset_boundary = false; - old_par = -1; - text_.setCursorIntern(0, 0); - text_.clearSelection(); - finishUndo(); - // If the inset is empty set the language of the current font to the - // language to the surronding text (if different). - if (paragraphs.begin()->empty() && paragraphs.size() == 1 && - bv->getParentLanguage(this) != text_.current_font.language()) { + if (paragraphs.size() == 1 + && paragraphs.begin()->empty() + && bv->getParentLanguage(this) != text_.current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); setFont(bv, font, false); @@ -367,233 +319,57 @@ void InsetText::lockInset(BufferView * bv) } -void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset) -{ - the_locking_inset = inset; - inset_x = cx() - top_x; - inset_y = cy(); - inset_boundary = cboundary(); -} - - -bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset) -{ - lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" - << inset << "): " << endl; - if (!inset) - return false; - if (!the_locking_inset) { - ParagraphList::iterator pit = paragraphs.begin(); - ParagraphList::iterator pend = paragraphs.end(); - - for (; pit != pend; ++pit) { - InsetList::iterator it = pit->insetlist.begin(); - InsetList::iterator const end = pit->insetlist.end(); - for (; it != end; ++it) { - if (it->inset == inset) { - lyxerr << "InsetText::lockInsetInInset: 1 a" << endl; - text_.setCursorIntern( - std::distance(paragraphs.begin(), pit), it->pos); - lyxerr << "InsetText::lockInsetInInset: 1 b" << endl; - lyxerr << "bv: " << bv << " inset: " << inset << endl; - lockInset(bv, inset); - lyxerr << "InsetText::lockInsetInInset: 1 c" << endl; - return true; - } - } - } - lyxerr << "InsetText::lockInsetInInset: 3" << endl; - return false; - } - if (inset == cpar()->getInset(cpos())) { - lyxerr[Debug::INSETS] << "OK" << endl; - lockInset(bv, inset); - return true; - } - - if (the_locking_inset && the_locking_inset == inset) { - inset_x = cx() - top_x; - inset_y = cy(); - } else if (the_locking_inset) { - lyxerr[Debug::INSETS] << "MAYBE" << endl; - return the_locking_inset->lockInsetInInset(bv, inset); - } - lyxerr[Debug::INSETS] << "NOT OK" << endl; - return false; -} - - -bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset, - bool lr) -{ - if (!the_locking_inset) - return false; - if (the_locking_inset == inset) { - the_locking_inset->insetUnlock(bv); - the_locking_inset = 0; - if (lr) - moveRightIntern(bv, true, false); - old_par = -1; // force layout setting - if (scroll()) - scroll(bv, 0.0F); - else - updateLocal(bv, false); - return true; - } - return the_locking_inset->unlockInsetInInset(bv, inset, lr); -} - +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! + // use this to check mouse motion for selection mouse_x = cmd.x; mouse_y = cmd.y; BufferView * bv = cmd.view(); - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - if (!locked) - lockInset(bv); - - int tmp_x = cmd.x; - int tmp_y = cmd.y + dim_.asc - bv->top_y(); - InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y); - - if (the_locking_inset) { - if (the_locking_inset == inset) { - the_locking_inset->dispatch(cmd1); - return; - } - // otherwise only unlock the_locking_inset - the_locking_inset->insetUnlock(bv); - the_locking_inset = 0; - } - if (!inset) - no_selection = false; - - if (bv->theLockingInset()) { - if (isHighlyEditableInset(inset)) { - // We just have to lock the inset before calling a - // PressEvent on it! - UpdatableInset * uinset = static_cast(inset); - if (!bv->lockInset(uinset)) { - lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; - } - inset->dispatch(cmd1); - if (the_locking_inset) - updateLocal(bv, false); - return; - } - } - if (!inset) { - bool paste_internally = false; - if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) { - dispatch(FuncRequest(bv, LFUN_COPY)); - paste_internally = true; - } - int old_top_y = bv->top_y(); - - text_.setCursorFromCoordinates(cmd.x, cmd.y + dim_.asc); - // set the selection cursor! - text_.selection.cursor = text_.cursor; - bv->x_target(text_.cursor.x()); - - text_.clearSelection(); - updateLocal(bv, false); - - bv->owner()->setLayout(cpar()->layout()->name()); - - // we moved the view we cannot do mouse selection in this case! - if (bv->top_y() != old_top_y) - no_selection = true; - old_par = text_.cursor.par(); - // Insert primary selection with middle mouse - // if there is a local selection in the current buffer, - // insert this - if (cmd.button() == mouse_button::button2) { - if (paste_internally) - dispatch(FuncRequest(bv, LFUN_PASTE)); - else - dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph")); - } - } else { - getLyXText(bv)->clearSelection(); - } -} - - -bool InsetText::lfunMouseRelease(FuncRequest const & cmd) -{ - BufferView * bv = cmd.view(); - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - - no_selection = true; - if (the_locking_inset) { - DispatchResult const res = the_locking_inset->dispatch(cmd1); - return res.dispatched(); - } - - int tmp_x = cmd.x; - int tmp_y = cmd.y + dim_.asc - bv->top_y(); - InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y); - if (!inset) - return false; + no_selection = false; + text_.clearSelection(); - // We still need to deal properly with the whole relative vs. - // absolute mouse co-ords thing in a realiable, sensible way - DispatchResult const res = inset->dispatch(cmd1); - bool const ret = res.dispatched(); - updateLocal(bv, false); - return ret; + // 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) { - FuncRequest cmd1 = cmd; - cmd1.x -= inset_x; - cmd1.y -= inset_y; - - if (the_locking_inset) { - the_locking_inset->dispatch(cmd1); - return; - } - + 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); + text_.setCursorFromCoordinates(cmd.x, cmd.y + dim_.asc); bv->x_target(text_.cursor.x()); - if (cur == text_.cursor) - return; - text_.setSelection(); - updateLocal(bv, false); + 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) { - setViewCache(bv); - - if (!bv->lockInset(this)) { - lyxerr << "Cannot lock inset" << endl; - return; - } lyxerr << "InsetText: edit left/right" << endl; + setViewCache(bv); - locked = true; - the_locking_inset = 0; - inset_x = 0; - inset_y = 0; - inset_boundary = false; old_par = -1; if (left) @@ -601,153 +377,64 @@ void InsetText::edit(BufferView * bv, bool left) else text_.setCursor(paragraphs.size() - 1, paragraphs.back().size()); - // If the inset is empty set the language of the current font to the - // language to the surronding text (if different). - if (paragraphs.begin()->empty() && - paragraphs.size() == 1 && - bv->getParentLanguage(this) != text_.current_font.language()) - { - LyXFont font(LyXFont::ALL_IGNORE); - font.setLanguage(bv->getParentLanguage(this)); - setFont(bv, font, false); - } - + sanitizeEmptyText(bv); updateLocal(bv, false); - // Tell the paragraph dialog that we've entered an insettext. - bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); + bv->updateParagraphDialog(); } void InsetText::edit(BufferView * bv, int x, int y) { - if (!bv->lockInset(this)) { - lyxerr << "Cannot lock inset" << endl; - return; - } - lyxerr << "InsetText: edit xy" << endl; - - locked = true; - the_locking_inset = 0; - inset_x = 0; - inset_y = 0; - inset_boundary = false; + lyxerr << "InsetText::edit xy" << endl; old_par = -1; - - int tmp_y = (y < 0) ? 0 : y; - // we put here -1 and not button as now the button in the - // edit call should not be needed we will fix this in 1.3.x - // cycle hopefully (Jug 20020509) - // FIXME: GUII I've changed this to none: probably WRONG - if (!checkAndActivateInset(bv, x, tmp_y)) { - text_.setCursorFromCoordinates(x, y + dim_.asc); - text_.cursor.x(text_.cursor.x()); - bv->x_target(text_.cursor.x()); - } + sanitizeEmptyText(bv); + text_.setCursorFromCoordinates(x, y + dim_.asc); + text_.cursor.x(text_.cursor.x()); + bv->x_target(text_.cursor.x()); text_.clearSelection(); finishUndo(); - // If the inset is empty set the language of the current font to the - // language to the surronding text (if different). - if (paragraphs.begin()->empty() && - paragraphs.size() == 1 && - bv->getParentLanguage(this) != text_.current_font.language()) - { - LyXFont font(LyXFont::ALL_IGNORE); - font.setLanguage(bv->getParentLanguage(this)); - setFont(bv, font, false); - } - updateLocal(bv, false); - // Tell the paragraph dialog that we've entered an insettext. - bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); + bv->updateParagraphDialog(); } -DispatchResult -InsetText::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, + idx_type &, pos_type &) { + lyxerr << "InsetText::priv_dispatch (begin), act: " + << 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); - return DispatchResult(true, true); + result = DispatchResult(true, true); + break; case LFUN_MOUSE_MOTION: lfunMouseMotion(cmd); - return DispatchResult(true, true); + result = DispatchResult(true, true); + break; case LFUN_MOUSE_RELEASE: - return DispatchResult(lfunMouseRelease(cmd)); - - default: + lfunMouseRelease(cmd); + result = DispatchResult(true, true); break; - } - - bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1; - no_selection = false; - - DispatchResult result = UpdatableInset::priv_dispatch(cmd, idx, pos); - if (result.dispatched()) - return result; - -#if 0 - // This looks utterly strange. (Lgb) - if (cmd.action == LFUN_UNKNOWN_ACTION && cmd.argument.empty()) - return DispatchResult(false, FINISHED); -#endif - - if (the_locking_inset) { - DispatchResult result = the_locking_inset->dispatch(cmd); - if (result.dispatched()) { - if (result.update()) { - result.update(false); - updateLocal(bv, false); - } - return result; - } - - switch (result.val()) { - case FINISHED_RIGHT: - moveRightIntern(bv, false, false); - result.dispatched(true); - result.update(true); - break; - case FINISHED_UP: - result = moveUp(bv); - if (result.val() >= FINISHED) { - updateLocal(bv, false); - bv->unlockInset(this); - } - break; - case FINISHED_DOWN: - result = moveDown(bv); - if (result.val() >= FINISHED) { - updateLocal(bv, false); - bv->unlockInset(this); - } - break; - default: - result.dispatched(true); - result.update(true); - break; - } - the_locking_inset = 0; - updateLocal(bv, false); - // make sure status gets reset immediately - bv->owner()->clearMessage(); - return result; - } - - switch (cmd.action) { - // Normal chars case LFUN_SELFINSERT: if (bv->buffer()->isReadonly()) { -// setErrorMessage(N_("Document is read only")); + // setErrorMessage(N_("Document is read only")); break; } if (!cmd.argument.empty()) { @@ -775,20 +462,21 @@ InsetText::priv_dispatch(FuncRequest const & cmd, result.update(true); break; - // cursor movements that need special handling - case LFUN_RIGHT: result = moveRight(bv); finishUndo(); break; + case LFUN_LEFT: finishUndo(); result = moveLeft(bv); break; + case LFUN_DOWN: finishUndo(); result = moveDown(bv); break; + case LFUN_UP: finishUndo(); result = moveUp(bv); @@ -797,8 +485,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd, case LFUN_PRIOR: if (crow() == text_.firstRow()) { result.val(FINISHED_UP); - lyxerr << "InsetText: cursor pop 1" << endl; - bv->cursor().pop(); } else { text_.cursorPrevious(); text_.clearSelection(); @@ -809,8 +495,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd, case LFUN_NEXT: if (crow() == text_.lastRow()) { result.val(FINISHED_DOWN); - lyxerr << "InsetText: cursor pop 2" << endl; - bv->cursor().pop(); } else { text_.cursorNext(); text_.clearSelection(); @@ -842,7 +526,8 @@ InsetText::priv_dispatch(FuncRequest const & cmd, #ifdef WITH_WARNINGS #warning FIXME horrendously bad UI #endif - Alert::error(_("Paste failed"), _("Cannot include more than one paragraph.")); + Alert::error(_("Paste failed"), + _("Cannot include more than one paragraph.")); } } else { replaceSelection(bv->getLyXText()); @@ -938,14 +623,10 @@ InsetText::priv_dispatch(FuncRequest const & cmd, break; default: + result = text_.dispatch(cmd); break; } - if (result.update()) { - result.update(false); - updateLocal(bv, true); - } - /// 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() && @@ -955,11 +636,7 @@ InsetText::priv_dispatch(FuncRequest const & cmd, setFont(bv, font, false); } - if (result.val() >= FINISHED) { - result.val(NONE); - bv->unlockInset(this); - } - + lyxerr << "InsetText::priv_dispatch (end)" << endl; return result; } @@ -1010,49 +687,24 @@ void InsetText::validate(LaTeXFeatures & features) const } -void InsetText::getCursor(BufferView & bv, int & x, int & y) const +void InsetText::getCursorPos(BufferView *, int & x, int & y) const { - if (the_locking_inset) { - the_locking_inset->getCursor(bv, x, y); - return; - } - x = cx(); - y = cy() + InsetText::y(); -} - - -void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const -{ - if (the_locking_inset) { - the_locking_inset->getCursorPos(bv, x, y); - return; - } - x = cx() - top_x - TEXT_TO_INSET_OFFSET; - y = cy() - TEXT_TO_INSET_OFFSET; + x = cx() - top_x; + y = cy(); } int InsetText::insetInInsetY() const { - if (!the_locking_inset) - return 0; - - return inset_y + the_locking_inset->insetInInsetY(); + return 0; } void InsetText::fitInsetCursor(BufferView * bv) const { - if (the_locking_inset) { - the_locking_inset->fitInsetCursor(bv); - return; - } - LyXFont const font = text_.getFont(cpar(), cpos()); - int const asc = font_metrics::maxAscent(font); int const desc = font_metrics::maxDescent(font); - bv->fitLockedInsetCursor(cx(), cy(), asc, desc); } @@ -1075,17 +727,12 @@ DispatchResult InsetText::moveLeft(BufferView * bv) } -DispatchResult -InsetText::moveRightIntern(BufferView * bv, bool front, +DispatchResult InsetText::moveRightIntern(BufferView * bv, bool front, bool activate_inset, bool selecting) { ParagraphList::iterator c_par = cpar(); - - if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size()) { - lyxerr << "InsetText: cursor pop 3" << endl; - bv->cursor().pop(); + if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size()) return DispatchResult(false, FINISHED_RIGHT); - } if (activate_inset && checkAndActivateInset(bv, front)) return DispatchResult(true, true); text_.cursorRight(bv); @@ -1095,15 +742,11 @@ InsetText::moveRightIntern(BufferView * bv, bool front, } -DispatchResult -InsetText::moveLeftIntern(BufferView * bv, bool front, +DispatchResult InsetText::moveLeftIntern(BufferView * bv, bool front, bool activate_inset, bool selecting) { - if (cpar() == paragraphs.begin() && cpos() <= 0) { - lyxerr << "InsetText: cursor pop 4" << endl; - bv->cursor().pop(); + if (cpar() == paragraphs.begin() && cpos() <= 0) return DispatchResult(false, FINISHED); - } text_.cursorLeft(bv); if (!selecting) text_.clearSelection(); @@ -1115,11 +758,8 @@ InsetText::moveLeftIntern(BufferView * bv, bool front, DispatchResult InsetText::moveUp(BufferView * bv) { - if (crow() == text_.firstRow()) { - lyxerr << "InsetText: cursor pop 5" << endl; - bv->cursor().pop(); + if (crow() == text_.firstRow()) return DispatchResult(false, FINISHED_UP); - } text_.cursorUp(bv); text_.clearSelection(); return DispatchResult(true); @@ -1128,11 +768,8 @@ DispatchResult InsetText::moveUp(BufferView * bv) DispatchResult InsetText::moveDown(BufferView * bv) { - if (crow() == text_.lastRow()) { - lyxerr << "InsetText: cursor pop 6" << endl; - bv->cursor().pop(); + if (crow() == text_.lastRow()) return DispatchResult(false, FINISHED_DOWN); - } text_.cursorDown(bv); text_.clearSelection(); return DispatchResult(true); @@ -1141,11 +778,6 @@ DispatchResult InsetText::moveDown(BufferView * bv) bool InsetText::insertInset(BufferView * bv, InsetOld * inset) { - if (the_locking_inset) { - if (the_locking_inset->insetAllowed(inset)) - return the_locking_inset->insertInset(bv, inset); - return false; - } inset->setOwner(this); text_.insertInset(inset); bv->fitCursor(); @@ -1164,36 +796,15 @@ bool InsetText::insetAllowed(InsetOld::Code code) const if (in_insetAllowed) return ret; in_insetAllowed = true; - if (the_locking_inset) - ret = the_locking_inset->insetAllowed(code); - else if (owner()) + if (owner()) ret = owner()->insetAllowed(code); in_insetAllowed = false; return ret; } -UpdatableInset * InsetText::getLockingInset() const +bool InsetText::showInsetDialog(BufferView *) const { - return the_locking_inset ? the_locking_inset->getLockingInset() : - const_cast(this); -} - - -UpdatableInset * InsetText::getFirstLockingInsetOfType(InsetOld::Code c) -{ - if (c == lyxCode()) - return this; - if (the_locking_inset) - return the_locking_inset->getFirstLockingInsetOfType(c); - return 0; -} - - -bool InsetText::showInsetDialog(BufferView * bv) const -{ - if (the_locking_inset) - return the_locking_inset->showInsetDialog(bv); return false; } @@ -1215,11 +826,6 @@ void InsetText::getLabelList(Buffer const & buffer, void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, bool selectall) { - if (the_locking_inset) { - the_locking_inset->setFont(bv, font, toggleall, selectall); - return; - } - if ((paragraphs.size() == 1 && paragraphs.begin()->empty()) || cpar()->empty()) { text_.setFont(font, toggleall); @@ -1254,31 +860,6 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool front) if (!isHighlyEditableInset(inset)) return false; inset->edit(bv, front); - if (!the_locking_inset) - return false; - updateLocal(bv, false); - return true; -} - - -bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y) -{ - int dummyx = x; - int dummyy = y + dim_.asc; - InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy); - if (!inset) - return false; - if (!isHighlyEditableInset(inset)) - return false; - if (x < 0) - x = dim_.wid; - if (y < 0) - y = dim_.des; - inset_x = cx() - top_x; - inset_y = cy(); - inset->edit(bv, x - inset_x, y - inset_y); - if (!the_locking_inset) - return false; updateLocal(bv, false); return true; } @@ -1337,13 +918,7 @@ void InsetText::setFrameColor(LColor_color col) int InsetText::cx() const { - int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET; - if (the_locking_inset) { - LyXFont font = text_.getFont(text_.cursorPar(), text_.cursor.pos()); - if (font.isVisibleRightToLeft()) - x -= the_locking_inset->width(); - } - return x; + return text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET; } @@ -1365,28 +940,12 @@ ParagraphList::iterator InsetText::cpar() const } -bool InsetText::cboundary() const -{ - return text_.cursor.boundary(); -} - - RowList::iterator InsetText::crow() const { return cpar()->getRow(cpos()); } -LyXText * InsetText::getLyXText(BufferView const * bv, - bool const recursive) const -{ - setViewCache(bv); - if (recursive && the_locking_inset) - return the_locking_inset->getLyXText(bv, true); - return &text_; -} - - void InsetText::setViewCache(BufferView const * bv) const { if (bv) { @@ -1422,14 +981,9 @@ void InsetText::removeNewlines() } -int InsetText::scroll(bool recursive) const +int InsetText::scroll(bool /*recursive*/) const { - int sx = UpdatableInset::scroll(false); - - if (recursive && the_locking_inset) - sx += the_locking_inset->scroll(recursive); - - return sx; + return UpdatableInset::scroll(false); } @@ -1470,14 +1024,6 @@ LyXText * InsetText::getText(int i) const } -LyXCursor const & InsetText::cursor(BufferView * bv) const -{ - if (the_locking_inset) - return the_locking_inset->cursor(bv); - return getLyXText(bv)->cursor; -} - - bool InsetText::checkInsertChar(LyXFont & font) { return owner() ? owner()->checkInsertChar(font) : true; @@ -1489,7 +1035,7 @@ void InsetText::collapseParagraphs(BufferView * bv) while (paragraphs.size() > 1) { ParagraphList::iterator const first = paragraphs.begin(); ParagraphList::iterator second = first; - advance(second, 1); + ++second; size_t const first_par_size = first->size(); if (!first->empty() && @@ -1517,9 +1063,8 @@ void InsetText::collapseParagraphs(BufferView * bv) void InsetText::getDrawFont(LyXFont & font) const { - if (!owner()) - return; - owner()->getDrawFont(font); + if (owner()) + owner()->getDrawFont(font); } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index db8617cf9e..863288d56e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -73,13 +73,6 @@ public: /// bool isTextInset() const { return true; } /// - void insetUnlock(BufferView *); - /// - bool lockInsetInInset(BufferView *, UpdatableInset *); - /// - bool unlockInsetInInset(BufferView *, - UpdatableInset *, bool lr = false); - /// int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// @@ -97,8 +90,6 @@ public: InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; } /// FIXME, document void getCursorPos(BufferView *, int & x, int & y) const; - /// Get the absolute document x,y of the cursor - virtual void getCursor(BufferView &, int &, int &) const; /// int insetInInsetY() const; /// @@ -108,10 +99,6 @@ public: /// bool insetAllowed(InsetOld::Code) const; /// - UpdatableInset * getLockingInset() const; - /// - UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code); - /// void setFont(BufferView *, LyXFont const &, bool toggleall = false, bool selectall = false); @@ -127,10 +114,8 @@ public: void setDrawFrame(DrawFrame); /// LColor_color frameColor() const; - void setFrameColor(LColor_color); /// - LyXText * getLyXText(BufferView const *, - bool const recursive = false) const; + void setFrameColor(LColor_color); /// void setViewCache(BufferView const * bv) const; /// @@ -155,8 +140,6 @@ public: ParagraphList * getParagraphs(int) const; /// LyXText * getText(int) const; - /// - LyXCursor const & cursor(BufferView *) const; /// mark as erased for change tracking void markErased() { clear(true); }; @@ -183,8 +166,6 @@ public: void edit(BufferView *, bool); /// void edit(BufferView *, int, int); - /// - UpdatableInset * lockingInset() const { return the_locking_inset; } /// int numParagraphs() const { return 1; } @@ -192,15 +173,10 @@ public: mutable ParagraphList paragraphs; protected: /// - virtual DispatchResult priv_dispatch(FuncRequest const &, idx_type &, pos_type &); /// void updateLocal(BufferView *, bool mark_dirty); - /// set parameters for an initial lock of this inset - void lockInset(BufferView *); - /// lock an inset inside this one - void lockInset(BufferView *, UpdatableInset *); private: /// @@ -208,9 +184,12 @@ private: /// void lfunMousePress(FuncRequest const &); /// - bool lfunMouseRelease(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 *); /// DispatchResult moveRight(BufferView *); @@ -246,8 +225,6 @@ private: /// ParagraphList::iterator cpar() const; /// - bool cboundary() const; - /// RowList::iterator crow() const; /// void drawFrame(Painter &, int x) const; @@ -266,18 +243,8 @@ private: */ int frame_color_; /// - mutable bool locked; - /// - bool inset_boundary; - /// - mutable int inset_x; - /// - mutable int inset_y; - /// bool no_selection; /// - UpdatableInset * the_locking_inset; - /// mutable lyx::paroffset_type old_par; /// diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index 372dcf1f05..8a30af6f54 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -27,9 +27,8 @@ #include "outputparams.h" #include "paragraph.h" -#include "support/tostr.h" - #include "support/std_sstream.h" +#include "support/tostr.h" using std::string; @@ -50,10 +49,7 @@ string floatname(string const & type, BufferParams const & bp) { FloatList const & floats = bp.getLyXTextClass().floats(); FloatList::const_iterator it = floats[type]; - if (it == floats.end()) - return type; - - return _(it->second.name()); + return (it == floats.end()) ? type : _(it->second.name()); } } // namespace anon @@ -62,9 +58,7 @@ string floatname(string const & type, BufferParams const & bp) InsetWrap::InsetWrap(BufferParams const & bp, string const & type) : InsetCollapsable(bp) { - string lab(_("wrap: ")); - lab += floatname(type, bp); - setLabel(lab); + setLabel(_("wrap: ") + floatname(type, bp)); LyXFont font(LyXFont::ALL_SANE); font.decSize(); font.decSize(); @@ -272,8 +266,7 @@ string const InsetWrapMailer::inset2string(Buffer const &) const } -void InsetWrapMailer::string2params(string const & in, - InsetWrapParams & params) +void InsetWrapMailer::string2params(string const & in, InsetWrapParams & params) { params = InsetWrapParams(); diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index 4a5cb9a2e9..60c4bab900 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -27,16 +27,6 @@ using lyx::support::strToDbl; using lyx::support::strToInt; -using std::string; - - -// some stuff for inset locking - -void UpdatableInset::insetUnlock(BufferView *) -{ - lyxerr[Debug::INFO] << "Inset Unlock" << std::endl; -} - // An updatable inset is highly editable by definition InsetOld::EDITABLE UpdatableInset::editable() const @@ -49,18 +39,8 @@ void UpdatableInset::fitInsetCursor(BufferView *) const {} -void UpdatableInset::draw(PainterInfo &, int, int) const -{ - // ATTENTION: don't do the following here!!! - // top_x = x; - // top_baseline = y; -} - - void UpdatableInset::scroll(BufferView * bv, float s) const { - //LyXFont font; - if (!s) { scx = 0; return; @@ -75,23 +55,21 @@ void UpdatableInset::scroll(BufferView * bv, float s) const return; scx = int(s * workW / 2); - // if (!display()) - // scx += 20; #warning metrics? - if (tmp_top_x + scx + width() < workW / 2) { - scx += workW / 2 - (tmp_top_x + scx + width()); - } + if (tmp_top_x + scx + width() < workW / 2) + scx = workW / 2 - tmp_top_x - width(); } + void UpdatableInset::scroll(BufferView * bv, int offset) const { if (offset > 0) { if (!scx && top_x >= 20) return; - if ((top_x + offset) > 20) + if (top_x + offset > 20) scx = 0; - // scx += offset - (top_x - scx + offset - 20); + // scx = - top_x; else scx += offset; } else { @@ -109,30 +87,23 @@ void UpdatableInset::scroll(BufferView * bv, int offset) const /// An updatable inset could handle lyx editing commands DispatchResult -UpdatableInset::priv_dispatch(FuncRequest const & ev, idx_type &, pos_type &) +UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) { - if (ev.action == LFUN_MOUSE_RELEASE) + switch (cmd.action) { + case LFUN_MOUSE_RELEASE: return DispatchResult(editable() == IS_EDITABLE); - if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) { - if (ev.argument.find('.') != ev.argument.npos) { - float const xx = static_cast(strToDbl(ev.argument)); - scroll(ev.view(), xx); - } else { - int const xx = strToInt(ev.argument); - scroll(ev.view(), xx); + case LFUN_SCROLL_INSET: + if (!cmd.argument.empty()) { + if (cmd.argument.find('.') != cmd.argument.npos) + scroll(cmd.view(), static_cast(strToDbl(cmd.argument))); + else + scroll(cmd.view(), strToInt(cmd.argument)); + cmd.view()->updateInset(this); + return DispatchResult(true, true); } - ev.view()->updateInset(this); - return DispatchResult(true, true); + default: + return DispatchResult(false); } - return DispatchResult(false); -} - - -LyXCursor const & InsetOld::cursor(BufferView * bv) const -{ - if (owner()) - return owner()->getLyXText(bv, false)->cursor; - return bv->text->cursor; } diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 26ec8b9346..361c554716 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -15,37 +15,12 @@ #ifndef UPDATABLEINSET_H #define UPDATABLEINSET_H -// Updatable Insets. These insets can be locked and receive -// directly user interaction. Currently used only for mathed. +// Updatable Insets. These insets can receive directly user interaction. // Note that all pure methods from Inset class are pure here too. // [Alejandro 080596] #include "inset.h" -#include "support/types.h" - - -/** Extracted from Matthias notes: - * - * An inset can simple call LockInset in it's edit call and *ONLY* - * in it's edit call. - * - * Unlocking is either done by LyX or the inset itself with a - * UnlockInset-call - * - * During the lock, all button and keyboard events will be modified - * and send to the inset through the following inset-features. Note that - * InsetOld::insetUnlock will be called from inside UnlockInset. It is meant - * to contain the code for restoring the menus and things like this. - * - * If a inset wishes any redraw and/or update it just has to call - * updateInset(this). - * - * It's is completly irrelevant, where the inset is. UpdateInset will - * find it in any paragraph in any buffer. - * Of course the_locking_inset and the insets in the current paragraph/buffer - * are checked first, so no performance problem should occur. - */ class UpdatableInset : public InsetOld { public: /// check if the font of the char we want inserting is correct @@ -58,29 +33,10 @@ public: virtual void fitInsetCursor(BufferView *) const; /// FIXME virtual void getCursorPos(BufferView *, int &, int &) const {} - /// Get the absolute document x,y of the cursor - virtual void getCursor(BufferView &, int &, int &) const = 0; - /// - virtual void insetUnlock(BufferView *); - /// - virtual void draw(PainterInfo & pi, int x, int y) const; /// virtual bool insertInset(BufferView *, InsetOld *) { return false; } /// - virtual UpdatableInset * getLockingInset() const - { return const_cast(this); } - /// - virtual UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code c) - { return (c == lyxCode()) ? this : 0; } - /// virtual int insetInInsetY() const { return 0; } - /// - virtual bool lockInsetInInset(BufferView *, UpdatableInset *) - { return false; } - /// - virtual bool unlockInsetInInset(BufferView *, UpdatableInset *, - bool /*lr*/ = false) - { return false; } // We need this method to not clobber the real method in Inset int scroll(bool recursive = true) const { return InsetOld::scroll(recursive); } @@ -88,8 +44,6 @@ public: virtual bool showInsetDialog(BufferView *) const { return false; } /// virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {} - /// - virtual UpdatableInset * lockingInset() const { return 0; } protected: /// An updatable inset could handle lyx editing commands diff --git a/src/iterators.C b/src/iterators.C index d074ac1422..e0053a1d7e 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -354,10 +354,12 @@ PosIterator ParIterator::asPosIterator(lyx::pos_type pos) const int const last = size() - 1; for (int i = 0; i < last; ++i) { ParPosition & pp = pimpl_->positions[i]; - p.stack_.push_back(PosIteratorItem(const_cast(pp.plist), pp.pit, (*pp.it)->pos, *pp.index + 1)); + p.stack_.push_back( + PosIteratorItem(const_cast(pp.plist), pp.pit, (*pp.it)->pos, *pp.index + 1)); } ParPosition const & pp = pimpl_->positions[last]; - p.stack_.push_back(PosIteratorItem(const_cast(pp.plist), pp.pit, pos, 0)); + p.stack_.push_back( + PosIteratorItem(const_cast(pp.plist), pp.pit, pos, 0)); return p; } @@ -375,7 +377,8 @@ ParIterator::ParIterator(PosIterator const & pos) BOOST_ASSERT(inset); InsetList::iterator beg = it.pit->insetlist.begin(); InsetList::iterator end = it.pit->insetlist.end(); - for (; beg != end && beg->inset != inset; ++beg); + for ( ; beg != end && beg->inset != inset; ++beg) + ; pp.it.reset(beg); pp.index.reset(it.index - 1); } @@ -386,21 +389,9 @@ ParIterator::ParIterator(PosIterator const & pos) void ParIterator::lockPath(BufferView * bv) const { - bv->insetUnlock(); + bv->cursor() = LCursor(bv); int last = size() - 1; - for (int i = 0; i < last; ++i) { - UpdatableInset * outer = - dynamic_cast((*pimpl_->positions[i].it)->inset); - outer->edit(bv, true); - LyXText * txt = outer->getText(*pimpl_->positions[i].index); - InsetText * inner = txt->inset_owner; - // deep voodoo magic: on a table, the edit call locks the first - // cell and further lock calls get lost there. - // We have to unlock it to then lock the correct one. - if (outer != inner) { - outer->insetUnlock(bv); - outer->lockInsetInInset(bv, inner); - inner->edit(bv, true); - } - } +#warning this seems to create just one entry for InsetTabulars + for (int i = 0; i < last; ++i) + (*pimpl_->positions[i].it)->inset->edit(bv, true); } diff --git a/src/lfuns.h b/src/lfuns.h index daae7eb2b6..f1dfe36390 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -327,6 +327,10 @@ enum kb_action { LFUN_INSERT_PAGEBREAK, LFUN_REPEAT, // 250 + LFUN_FINISHED_LEFT, + LFUN_FINISHED_RIGHT, + LFUN_FINISHED_UP, + LFUN_FINISHED_DOWN, LFUN_LASTACTION // end of the table }; diff --git a/src/lyx_cb.C b/src/lyx_cb.C index f1843b0796..89f5f67e10 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -353,13 +353,12 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) return; // clear the selection - bool flag = (bv->text == bv->getLyXText()); - if (flag) - bv->beforeChange(bv->text); - if (!asParagraph) - bv->getLyXText()->insertStringAsLines(tmpstr); - else + if (bv->text == bv->getLyXText()) + bv->text->clearSelection(); + if (asParagraph) bv->getLyXText()->insertStringAsParagraphs(tmpstr); + else + bv->getLyXText()->insertStringAsLines(tmpstr); bv->update(); } @@ -459,9 +458,9 @@ string const getPossibleLabel(BufferView const & bv) break; string head; par_text = split(par_text, head, ' '); + // Is it legal to use spaces in labels ? if (i > 0) - text += '-'; // Is it legal to use spaces in - // labels ? + text += '-'; text += head; } diff --git a/src/lyxfind.C b/src/lyxfind.C index db23d30db9..9f474c5a36 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -37,10 +37,10 @@ using bv_funcs::put_selection_at; using std::string; + namespace lyx { namespace find { - namespace { class MatchString @@ -80,18 +80,6 @@ private: }; - -} //namespace anon - - - - - -namespace { - - - - bool findForward(PosIterator & cur, PosIterator const & end, MatchString & match) { @@ -135,15 +123,13 @@ bool searchAllowed(BufferView * bv, string const & str) Alert::error(_("Search error"), _("Search string is empty")); return false; } - if (!bv->available()) - return false; - return true; - + return bv->available(); } } // namespace anon + bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw) { @@ -170,13 +156,6 @@ bool find(BufferView * bv, string const & searchstr, return found; } -namespace { - - - - -} //namespace anon - int replaceAll(BufferView * bv, string const & searchstr, string const & replacestr, @@ -236,10 +215,11 @@ int replace(BufferView * bv, } } +#ifdef LOCK LyXText * text = bv->getLyXText(); // We have to do this check only because mathed insets don't // return their own LyXText but the LyXText of it's parent! - if (!bv->theLockingInset() || + if (!bv->innerInset() || ((text != bv->text) && (text->inset_owner == text->inset_owner->getLockingInset()))) { text->replaceSelectionWithString(replacestr); @@ -247,10 +227,9 @@ int replace(BufferView * bv, text->cursor = fw ? text->selection.end : text->selection.start; } +#endif - // FIXME: should be called via an LFUN bv->buffer()->markDirty(); - find(bv, searchstr, cs, mw, fw); bv->update(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 19cbed4590..53555cf02c 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -75,13 +75,11 @@ #include "support/std_sstream.h" #include "support/os.h" -using bv_funcs::apply_freefont; using bv_funcs::changeDepth; using bv_funcs::currentState; using bv_funcs::DEC_DEPTH; using bv_funcs::freefont2string; using bv_funcs::INC_DEPTH; -using bv_funcs::update_and_apply_freefont; using lyx::support::AddName; using lyx::support::AddPath; @@ -325,7 +323,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const } } - UpdatableInset * tli = view()->theLockingInset(); + UpdatableInset * tli = view()->cursor().innerInset(); + InsetTabular * tab = view()->cursor().innerInsetTabular(); // I would really like to avoid having this switch and rather try to // encode this in the function itself. @@ -343,29 +342,22 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_CUT: case LFUN_COPY: - if (tli) { - UpdatableInset * in = tli; - if (in->lyxCode() != InsetOld::TABULAR_CODE) { - in = tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE); - } - if (in && static_cast(in)->hasSelection()) { - disable = false; - break; - } - } - disable = !mathcursor && !view()->getLyXText()->selection.set(); + if (tab && tab->hasSelection()) + disable = false; + else + disable = !mathcursor && !view()->getLyXText()->selection.set(); break; + case LFUN_RUNCHKTEX: disable = !buf->isLatex() || lyxrc.chktex_command == "none"; break; + case LFUN_BUILDPROG: disable = !Exporter::IsExportable(*buf, "program"); break; case LFUN_LAYOUT_TABULAR: - disable = !tli - || (tli->lyxCode() != InsetOld::TABULAR_CODE - && !tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)); + disable = !view()->cursor().innerInsetTabular(); break; case LFUN_DEPTH_MIN: @@ -388,8 +380,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_TABULAR_FEATURE: - if (mathcursor) { #if 0 + if (mathcursor) { // FIXME: check temporarily disabled // valign code char align = mathcursor->valign(); @@ -423,7 +415,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; } flag.setOnOff(ev.argument[0] == align); -#endif disable = !mathcursor->halign(); break; @@ -432,15 +423,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const if (tli) { FuncStatus ret; //ret.disabled(true); - if (tli->lyxCode() == InsetOld::TABULAR_CODE) { - ret = static_cast(tli) - ->getStatus(ev.argument); - flag |= ret; - disable = false; - } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) { - ret = static_cast - (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) - ->getStatus(ev.argument); + InsetTabular * tab = view()->cursor().innerInsetTabular(); + if (tab) { + ret = tab->getStatus(ev.argument); flag |= ret; disable = false; } else { @@ -453,6 +438,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const if (ret.onoff(true) || ret.onoff(false)) flag.setOnOff(false); } +#endif break; case LFUN_VC_REGISTER: @@ -495,14 +481,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSET_SETTINGS: { disable = true; - UpdatableInset * inset = view()->theLockingInset(); + UpdatableInset * inset = view()->cursor().innerInset(); if (!inset) break; - // get the innermost inset - inset = inset->getLockingInset(); - // jump back to owner if an InsetText, so // we get back to the InsetTabular or whatever if (inset->lyxCode() == InsetOld::TEXT_CODE) @@ -573,7 +556,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = !Exporter::IsExportable(*buf, "dvi") || lyxrc.print_command == "none"; } else if (name == "character") { - UpdatableInset * tli = view()->theLockingInset(); + UpdatableInset * tli = view()->cursor().innerInset(); disable = tli && tli->lyxCode() == InsetOld::ERT_CODE; } else if (name == "vclog") { disable = !buf->lyxvc().inUse(); @@ -756,6 +739,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; } +#ifdef LOCK // the font related toggles if (!mathcursor) { LyXFont const & font = view()->getLyXText()->real_current_font; @@ -809,6 +793,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; } } +#endif // this one is difficult to get right. As a half-baked // solution, we consider only the first action of the sequence @@ -852,8 +837,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) string argument = func.argument; kb_action action = func.action; - lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << action - <<"] arg[" << argument << ']' << endl; + //lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << func << endl; + lyxerr << "LyXFunc::dispatch: cmd: " << func << endl; // we have not done anything wrong yet. errorstat = false; @@ -881,207 +866,14 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) if (view()->available()) view()->hideCursor(); -#if 1 - { - UpdatableInset * innerinset = view()->theLockingInset(); - for (UpdatableInset * tmp = innerinset; tmp; tmp = tmp->lockingInset()) - innerinset = tmp; - - if (view()->cursor().innerInset() != innerinset) { - lyxerr << "### CURSOR OUT OF SYNC: tli: " - << view()->theLockingInset() << " inner: " - << innerinset - << "\ncursor: " << view()->cursor() << endl; - } - } - - if (0) { - DispatchResult result = - view()->cursor().dispatch(FuncRequest(func, view())); - - if (result.dispatched()) { - if (result.update()) { - view()->update(); - } - lyxerr << "dispatched by Cursor::dispatch()\n"; - goto exit_with_message; - } - lyxerr << "### NOT DispatchResult(true, true) BY Cursor::dispatch() ###\n"; - } -#endif - - - if (view()->available() && view()->theLockingInset()) { - DispatchResult result; - if (action > 1 || (action == LFUN_UNKNOWN_ACTION && - !keyseq.deleted())) - { - UpdatableInset * inset = view()->theLockingInset(); -#if 1 - int inset_x; - int dummy_y; - inset->getCursorPos(view(), inset_x, dummy_y); -#endif - if (action == LFUN_UNKNOWN_ACTION && argument.empty()) - argument = encoded_last_key; - - // the insets can't try to handle this, - // a table cell in the dummy position will - // lock its insettext, the insettext will - // pass it the bufferview, and succeed, - // so it will stay not locked. Not good - // if we've just done LFUN_ESCAPE (which - // injects an LFUN_PARAGRAPH_UPDATE) - if (action == LFUN_PARAGRAPH_UPDATE) { - view()->dispatch(func); - goto exit_with_message; - } - - // Undo/Redo is a bit tricky for insets. - if (action == LFUN_UNDO) { - view()->undo(); - goto exit_with_message; - } - - if (action == LFUN_REDO) { - view()->redo(); - goto exit_with_message; - } - - // Hand-over to inset's own dispatch: - result = inset->dispatch(FuncRequest(view(), action, argument)); - if (result.dispatched()) { - if (result.update()) - view()->update(); - - goto exit_with_message; - } - - // If DispatchResult(false), just soldier on - if (result.val() == FINISHED) { - owner->clearMessage(); - goto exit_with_message; - // We do not need special RTL handling here: - // FINISHED means that the cursor should be - // one position after the inset. - } - - if (result.val() == FINISHED_RIGHT) { - view()->text->cursorRight(view()); - moveCursorUpdate(); - owner->clearMessage(); - goto exit_with_message; - } - - if (result.val() == FINISHED_UP) { - LyXText * text = view()->text; - ParagraphList::iterator pit = text->cursorPar(); - Row const & row = *pit->getRow(text->cursor.pos()); - if (text->isFirstRow(pit, row)) { -#if 1 - text->setCursorFromCoordinates( - text->cursor.x() + inset_x, - text->cursor.y() - - row.baseline() - 1); - view()->x_target(text->cursor.x()); -#else - text->cursorUp(view()); -#endif - moveCursorUpdate(); - } else { - view()->update(); - } - owner->clearMessage(); - goto exit_with_message; - } - - if (result.val() == FINISHED_DOWN) { - LyXText * text = view()->text; - ParagraphList::iterator pit = text->cursorPar(); - Row const & row = *pit->getRow(text->cursor.pos()); - if (text->isLastRow(pit, row)) { -#if 1 - text->setCursorFromCoordinates( - text->cursor.x() + inset_x, - text->cursor.y() - - row.baseline() + - row.height() + 1); - view()->x_target(text->cursor.x()); -#else - text->cursorDown(view()); -#endif - } else { - text->cursorRight(view()); - } - moveCursorUpdate(); - owner->clearMessage(); - goto exit_with_message; - } - -#warning I am not sure this is still right, please have a look! (Jug 20020417) - // result == DispatchResult() - //setMessage(N_("Text mode")); - switch (action) { - case LFUN_UNKNOWN_ACTION: - case LFUN_BREAKPARAGRAPH: - case LFUN_BREAKLINE: - view()->text->cursorRight(view()); - view()->switchKeyMap(); - owner->view_state_changed(); - break; - case LFUN_RIGHT: - if (!view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) { - view()->text->cursorRight(view()); - moveCursorUpdate(); - owner->view_state_changed(); - } - goto exit_with_message; - case LFUN_LEFT: - if (view()->text->cursorPar()->isRightToLeftPar(owner->buffer()->params())) { - view()->text->cursorRight(view()); - moveCursorUpdate(); - owner->view_state_changed(); - } - goto exit_with_message; - case LFUN_DOWN: { - LyXText * text = view()->text; - ParagraphList::iterator pit = text->cursorPar(); - if (text->isLastRow(pit, *pit->getRow(text->cursor.pos()))) - view()->text->cursorDown(view()); - else - view()->text->cursorRight(view()); - moveCursorUpdate(); - owner->view_state_changed(); - goto exit_with_message; - } - default: - break; - } - } - } - switch (action) { case LFUN_ESCAPE: { if (!view()->available()) break; - // this function should be used always [asierra060396] - UpdatableInset * tli = view()->theLockingInset(); - if (tli) { - UpdatableInset * lock = tli->getLockingInset(); - - if (tli == lock) { - view()->unlockInset(tli); - view()->text->cursorRight(view()); - moveCursorUpdate(); - owner->view_state_changed(); - } else { - tli->unlockInsetInInset(view(), lock, true); - } - finishUndo(); - // Tell the paragraph dialog that we changed paragraph - dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); - } + view()->cursor().pop(); + // Tell the paragraph dialog that we changed paragraph + dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); break; } @@ -1104,7 +896,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) } case LFUN_PREFIX: - if (view()->available() && !view()->theLockingInset()) + if (view()->available()) view()->update(); owner->message(keyseq.printOptions()); break; @@ -1140,7 +932,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) view()->center(); break; - // --- Menus ----------------------------------------------- + // --- Menus ----------------------------------------------- case LFUN_MENUNEW: menuNew(argument, false); break; @@ -1236,35 +1028,10 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) view()->redo(); break; - case LFUN_FREEFONT_APPLY: - apply_freefont(view()); - break; - - case LFUN_FREEFONT_UPDATE: - update_and_apply_freefont(view(), argument); - break; - case LFUN_RECONFIGURE: Reconfigure(view()); break; -#if 0 - case LFUN_FLOATSOPERATE: - if (argument == "openfoot") - view()->allFloats(1,0); - else if (argument == "closefoot") - view()->allFloats(0,0); - else if (argument == "openfig") - view()->allFloats(1,1); - else if (argument == "closefig") - view()->allFloats(0,1); - break; -#else -#ifdef WITH_WARNINGS -//#warning Find another implementation here (or another lyxfunc)! -#endif -#endif - case LFUN_HELP_OPEN: { string const arg = argument; if (arg.empty()) { @@ -1283,7 +1050,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) break; } - // --- version control ------------------------------- + // --- version control ------------------------------- case LFUN_VC_REGISTER: if (!ensureBufferClean(view())) break; @@ -1324,7 +1091,6 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) break; // --- buffers ---------------------------------------- - case LFUN_SWITCHBUFFER: view()->buffer(bufferlist.getBuffer(argument)); break; @@ -1337,19 +1103,10 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) open(argument); break; - case LFUN_LAYOUT_TABULAR: { - UpdatableInset * tli = view()->theLockingInset(); - if (tli) { - if (tli->lyxCode() == InsetOld::TABULAR_CODE) { - static_cast(tli)->openLayoutDialog(view()); - } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) { - static_cast( - tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) - ->openLayoutDialog(view()); - } - } + case LFUN_LAYOUT_TABULAR: + if (InsetTabular * tab = view()->cursor().innerInsetTabular()) + tab->openLayoutDialog(view()); break; - } case LFUN_DROP_LAYOUTS_CHOICE: owner->getToolbar().openLayoutList(); @@ -1357,11 +1114,9 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) case LFUN_MENU_OPEN_BY_NAME: owner->getMenubar().openByName(argument); - break; // RVDK_PATCH_5 + break; // --- lyxserver commands ---------------------------- - - case LFUN_GETNAME: setMessage(owner->buffer()->fileName()); lyxerr[Debug::INFO] << "FNAME[" @@ -1417,7 +1172,6 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) << " found." << endl; } - par.lockPath(view()); LyXText * lt = par.text(view()); @@ -1429,10 +1183,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) view()->center(); // see BufferView_pimpl::center() view()->updateScrollbar(); + break; } - break; - - // --- insert characters ---------------------------------------- // --- Mathed stuff. If we are here, there is no locked inset yet. case LFUN_MATH_EXTERN: @@ -1643,10 +1395,9 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) case LFUN_FORKS_KILL: if (isStrInt(argument)) { pid_t const pid = strToInt(argument); - ForkedcallsController & fcc = ForkedcallsController::get(); - fcc.kill(pid); + ForkedcallsController::get().kill(pid); + break; } - break; case LFUN_TOOLTIPS_TOGGLE: owner->getDialogs().toggleTooltips(); @@ -1656,15 +1407,19 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) InsetExternal().dispatch(FuncRequest(view(), action, argument)); break; - default: - // Then if it was none of the above - // Trying the BufferView::pimpl dispatch: - if (!view()->dispatch(func)) - lyxerr << "A truly unknown func [" - << lyxaction.getActionName(func.action) << "]!" - << endl; - break; - } // end of switch + default: { + DispatchResult result = + view()->cursor().dispatch(FuncRequest(func, view())); + if (result.dispatched()) { + if (result.update()) + view()->update(); + lyxerr << "dispatched by Cursor::dispatch()" << endl; + } else { + lyxerr << "### NOT DISPATCHED BY Cursor::dispatch() ###" << endl; + } + break; + } + } exit_with_message: diff --git a/src/lyxtext.h b/src/lyxtext.h index c19d8b440c..a860240359 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -51,8 +51,7 @@ class VSpace; class LyXText : public TextCursor { public: /// Constructor - LyXText(BufferView *, InsetText *, bool ininset, - ParagraphList & paragraphs); + LyXText(BufferView *, InsetText *, bool ininset, ParagraphList & plist); void init(BufferView *); /// @@ -67,14 +66,10 @@ public: LyXFont defaultfont_; /// InsetText * inset_owner; - /// - UpdatableInset * the_locking_inset; /// update all cached row positions void updateRowPositions(); /// - int getRealCursorX() const; - /// LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const; /// LyXFont getLayoutFont(ParagraphList::iterator pit) const; @@ -403,6 +398,10 @@ private: /// void charInserted(); + /// set 'number' font property + void number(); + /// is the cursor paragraph right-to-left? + bool rtl() const; public: /// diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index a535381b8f..dae1f38efd 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,9 @@ + +2003-11-10 André Pönitz + + * formula.C: + * formulabase.C: adjust to removed inset locking + 2003-11-05 José Matos * formula.[Ch] (ascii, linuxdoc, docbook): diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 63cffade24..b6d94ee065 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -196,9 +196,9 @@ bool editing_inset(InsetFormula const * inset) void InsetFormula::draw(PainterInfo & pi, int x, int y) const { // The previews are drawn only when we're not editing the inset. - bool const use_preview = (!editing_inset(this) && - RenderPreview::activated() && - preview_->previewReady()); + bool const use_preview = !editing_inset(this) + && RenderPreview::activated() + && preview_->previewReady(); int const w = dim_.wid; int const d = dim_.des; @@ -227,6 +227,10 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const xo_ = x; yo_ = y; + + top_x = x; + top_baseline = y; + } @@ -260,9 +264,9 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const { - bool const use_preview = (!editing_inset(this) && - RenderPreview::activated() && - preview_->previewReady()); + bool const use_preview = !editing_inset(this) + && RenderPreview::activated() + && preview_->previewReady(); if (use_preview) { preview_->metrics(m, dim); @@ -303,10 +307,10 @@ namespace { string const latex_string(InsetFormula const & inset, Buffer const &) { - ostringstream ls; - WriteStream wi(ls, false, false); + ostringstream os; + WriteStream wi(os, false, false); inset.par()->write(wi); - return ls.str(); + return os.str(); } } // namespace anon diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index b3ad9ca447..d9dd11a923 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -11,6 +11,7 @@ #include +#include "cursor.h" #include "formulabase.h" #include "formula.h" #include "formulamacro.h" @@ -61,13 +62,13 @@ namespace { int first_x; int first_y; -bool openNewInset(BufferView * bv, UpdatableInset * new_inset) +bool openNewInset(BufferView * bv, UpdatableInset * inset) { - if (!bv->insertInset(new_inset)) { - delete new_inset; + if (!bv->insertInset(inset)) { + delete inset; return false; } - new_inset->edit(bv, true); + inset->edit(bv, true); return true; } @@ -186,7 +187,7 @@ void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const x = mathcursor->targetX(); x -= xo_; y -= yo_; - //lyxerr << "getCursorPos: " << x << ' ' << y << endl; + lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl; } @@ -320,10 +321,9 @@ DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) void InsetFormulaBase::edit(BufferView * bv, bool left) { lyxerr << "Called FormulaBase::edit" << endl; - if (!bv->lockInset(this)) - lyxerr << "Cannot lock math inset in edit call!" << endl; releaseMathCursor(bv); mathcursor = new MathCursor(this, left); + bv->cursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time bv->updateInset(this); @@ -333,12 +333,11 @@ void InsetFormulaBase::edit(BufferView * bv, bool left) void InsetFormulaBase::edit(BufferView * bv, int x, int y) { lyxerr << "Called FormulaBase::EDIT with '" << x << ' ' << y << "'" << endl; - if (!bv->lockInset(this)) - lyxerr << "Cannot lock math inset in edit call!" << endl; releaseMathCursor(bv); mathcursor = new MathCursor(this, true); //metrics(bv); mathcursor->setPos(x + xo_, y + yo_); + bv->cursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time bv->updateInset(this); @@ -710,9 +709,8 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, if (data.empty()) result = DispatchResult(false); - else { + else bv->owner()->getDialogs().show(name, data, 0); - } } break; @@ -757,7 +755,6 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, cmd.view()->stuffClipboard(mathcursor->grabSelection()); } else { releaseMathCursor(bv); - bv->unlockInset(this); if (remove_inset) bv->owner()->dispatch(FuncRequest(LFUN_DELETE)); } @@ -859,11 +856,6 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, for (MathIterator it = current; it != iend(par().nucleus()); ++it) { if (it.cell().matchpart(ar, it.back().pos_)) { - bv->unlockInset(bv->theLockingInset()); - if (!bv->lockInset(this)) { - lyxerr << "Cannot lock inset" << endl; - return false; - } delete mathcursor; mathcursor = new MathCursor(this, true); //metrics(bv); @@ -917,7 +909,7 @@ void mathDispatchCreation(FuncRequest const & cmd, bool display) if (sel.empty()) { InsetFormula * f = new InsetFormula(bv); if (openNewInset(bv, f)) { - bv->theLockingInset()-> + bv->cursor().innerInset()-> dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); // don't do that also for LFUN_MATH_MODE unless you want end up with // always changing to mathrm when opening an inlined inset @@ -980,9 +972,9 @@ void mathDispatch(FuncRequest const & cmd) case LFUN_MATH_DELIM: { InsetFormula * f = new InsetFormula(bv); if (openNewInset(bv, f)) { - bv->theLockingInset()-> - dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); - bv->theLockingInset()->dispatch(cmd); + UpdatableInset * inset = bv->cursor().innerInset(); + inset->dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); + inset->dispatch(cmd); } break; } diff --git a/src/text.C b/src/text.C index 3c2bb6e871..3a736e0b0c 100644 --- a/src/text.C +++ b/src/text.C @@ -50,8 +50,6 @@ #include "support/lstrings.h" #include "support/textutils.h" -using bv_funcs::number; - using lyx::pos_type; using lyx::word_location; @@ -130,15 +128,6 @@ int LyXText::workWidth() const } -int LyXText::getRealCursorX() const -{ - int x = cursor.x(); - if (the_locking_inset && the_locking_inset->getLyXText(bv()) != this) - x = the_locking_inset->getLyXText(bv())->getRealCursorX(); - return x; -} - - // This is the comments that some of the warnings below refers to. // There are some issues in this file and I don't think they are // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that @@ -942,10 +931,10 @@ void LyXText::insertChar(char c) getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON && getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON) ) - number(bv()); // Set current_font.number to OFF + number(); // Set current_font.number to OFF } else if (IsDigit(c) && real_current_font.isVisibleRightToLeft()) { - number(bv()); // Set current_font.number to ON + number(); // Set current_font.number to ON if (cursor.pos() > 0) { char const c = cursorPar()->getChar(cursor.pos() - 1); diff --git a/src/text2.C b/src/text2.C index f958261c16..3319d4cb61 100644 --- a/src/text2.C +++ b/src/text2.C @@ -72,12 +72,10 @@ using std::string; LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset, ParagraphList & paragraphs) - : height(0), width(0), - inset_owner(inset), the_locking_inset(0), bv_owner(bv), + : height(0), width(0), inset_owner(inset), bv_owner(bv), in_inset_(ininset), paragraphs_(¶graphs), cache_pos_(-1) -{ -} +{} void LyXText::init(BufferView * bview) @@ -257,9 +255,10 @@ void LyXText::toggleInset() // No, try to see if we are inside a collapsable inset if (inset_owner && inset_owner->owner() && inset_owner->owner()->isOpen()) { - bv()->unlockInset(inset_owner->owner()); + finishUndo(); inset_owner->owner()->close(bv()); bv()->getLyXText()->cursorRight(bv()); + bv()->updateParagraphDialog(); } return; } @@ -278,7 +277,7 @@ void LyXText::toggleInset() } -/* used in setlayout */ +// used in setLayout // Asger is not sure we want to do this... void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params, Paragraph & par) @@ -439,6 +438,7 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only) prev_after_depth = pit->getMaxDepthAfter(); +#warning SERIOUS: Uahh... does this mean we access end->getMaxDepthAfter? if (pit == end) { break; } @@ -549,7 +549,6 @@ void LyXText::setSelection() } - void LyXText::clearSelection() { TextCursor::clearSelection(); @@ -571,8 +570,8 @@ void LyXText::cursorEnd() { ParagraphList::iterator cpit = cursorPar(); pos_type end = cpit->getRow(cursor.pos())->endpos(); - /* if not on the last row of the par, put the cursor before - the final space */ + // if not on the last row of the par, put the cursor before + // the final space setCursor(cpit, end == cpit->size() ? end : end - 1); } @@ -656,7 +655,7 @@ string LyXText::getStringToIndex() // the DTP switches for paragraphs. LyX will store them in the first // physical paragraph. When a paragraph is broken, the top settings rest, // the bottom settings are given to the new one. So I can make sure, -// they do not duplicate themself and you cannnot make dirty things with +// they do not duplicate themself and you cannot play dirty tricks with // them! void LyXText::setParagraph( @@ -690,7 +689,6 @@ void LyXText::setParagraph( recUndo(selection.start.par(), parOffset(undoendpit) - 1); - int tmppit = selection.end.par(); while (tmppit != selection.start.par() - 1) { @@ -1021,6 +1019,7 @@ void LyXText::insertInset(InsetOld * inset) { if (!cursorPar()->insetAllowed(inset->lyxCode())) return; + recUndo(cursor.par()); freezeUndo(); cursorPar()->insertInset(cursor.pos(), inset); diff --git a/src/text3.C b/src/text3.C index 7c761bfb40..d2d9acce3f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -46,8 +46,10 @@ #include "support/lstrings.h" #include "support/tostr.h" - #include "support/std_sstream.h" + +#include "mathed/formulabase.h" + #include using bv_funcs::replaceSelection; @@ -74,6 +76,144 @@ bool selection_possible = false; namespace { + // globals... + LyXFont freefont(LyXFont::ALL_IGNORE); + bool toggleall = false; + + + void toggleAndShow(BufferView * bv, LyXText * text, + LyXFont const & font, bool toggleall = true) + { + if (!bv->available()) + return; + + text->toggleFree(font, toggleall); + bv->update(); + + if (font.language() != ignore_language || + font.number() != LyXFont::IGNORE) { + LyXCursor & cursor = text->cursor; + Paragraph & par = *text->cursorPar(); + text->bidi.computeTables(par, *bv->buffer(), + *par.getRow(cursor.pos())); + if (cursor.boundary() != + text->bidi.isBoundary(*bv->buffer(), par, + cursor.pos(), + text->real_current_font)) + text->setCursor(cursor.par(), cursor.pos(), + false, !cursor.boundary()); + } + } + + + /// Apply the contents of freefont at the current cursor location. + void apply_freefont(BufferView * bv, LyXText * text) + { + toggleAndShow(bv, text, freefont, toggleall); + bv->owner()->view_state_changed(); + bv->owner()->message(_("Character set")); + } + + + /** Set the freefont using the contents of \param data dispatched from + * the frontends and apply it at the current cursor location. + */ + void update_and_apply_freefont(BufferView * bv, LyXText * text, + string const & data) + { + LyXFont font; + bool toggle; + if (bv_funcs::string2font(data, font, toggle)) { + freefont = font; + toggleall = toggle; + apply_freefont(bv, text); + } + } + + + void emph(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setEmph(LyXFont::TOGGLE); + toggleAndShow(bv, text, font); + } + + + void bold(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setSeries(LyXFont::BOLD_SERIES); + toggleAndShow(bv, text, font); + } + + + void noun(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setNoun(LyXFont::TOGGLE); + toggleAndShow(bv, text, font); + } + + + void lang(BufferView * bv, string const & l, LyXText * text) + { + Language const * lang = languages.getLanguage(l); + if (!lang) + return; + + LyXFont font(LyXFont::ALL_IGNORE); + font.setLanguage(lang); + toggleAndShow(bv, text, font); + } + + + void code(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good + toggleAndShow(bv, text, font); + } + + + void sans(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setFamily(LyXFont::SANS_FAMILY); + toggleAndShow(bv, text, font); + } + + + void roman(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setFamily(LyXFont::ROMAN_FAMILY); + toggleAndShow(bv, text, font); + } + + + void styleReset(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_INHERIT, ignore_language); + toggleAndShow(bv, text, font); + } + + + void underline(BufferView * bv, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setUnderbar(LyXFont::TOGGLE); + toggleAndShow(bv, text, font); + } + + + void fontSize(BufferView * bv, string const & size, LyXText * text) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setLyXSize(size); + toggleAndShow(bv, text, font); + } + + void moveCursorUpdate(BufferView * bv, bool selecting) { LyXText * lt = bv->getLyXText(); @@ -151,6 +291,20 @@ namespace { } // anon namespace +namespace bv_funcs { + +string const freefont2string() +{ + string data; + if (font2string(freefont, toggleall, data)) + return data; + return string(); +} + +} + + + InsetOld * LyXText::checkInsetHit(int & x, int & y) { int y_tmp = y + bv_owner->top_y(); @@ -213,7 +367,7 @@ bool LyXText::gotoNextInset(vector const & codes, void LyXText::gotoInset(vector const & codes, bool same_content) { - bv()->beforeChange(this); + clearSelection(); string contents; if (same_content && cursor.pos() < cursorPar()->size() @@ -275,7 +429,8 @@ void LyXText::cursorPrevious() if (inset_owner) { new_y += bv()->text->cursor.y() - + bv()->theLockingInset()->insetInInsetY() + y; + + bv()->cursor().innerInset()->insetInInsetY() + + y; } else { new_y += cursor.y() - crit->baseline(); } @@ -305,14 +460,14 @@ void LyXText::cursorNext() int y = topy + bv()->workHeight(); if (inset_owner && !topy) { - y -= (bv()->text->cursor.y() - - bv()->top_y() - + bv()->theLockingInset()->insetInInsetY()); + y += - bv()->text->cursor.y() + + bv()->top_y() + - bv()->cursor().innerInset()->insetInInsetY(); } ParagraphList::iterator dummypit; - Row const & rr = *getRowNearY(y, dummypit); - y = dummypit->y + rr.y_offset(); + Row const & row = *getRowNearY(y, dummypit); + y = dummypit->y + row.y_offset(); setCursorFromCoordinates(bv()->x_target(), y); // + bv->workHeight()); @@ -333,7 +488,7 @@ void LyXText::cursorNext() if (inset_owner) { new_y = bv()->text->cursor.y() - + bv()->theLockingInset()->insetInInsetY() + + bv()->cursor().innerInset()->insetInInsetY() + y - crit->baseline(); } else { new_y = cursor.y() - crit->baseline(); @@ -389,11 +544,24 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd, } // anon namespace +void LyXText::number() +{ + LyXFont font(LyXFont::ALL_IGNORE); + font.setNumber(LyXFont::TOGGLE); + toggleAndShow(bv(), this, font); +} + + +bool LyXText::rtl() const +{ + return cursorPar()->isRightToLeftPar(bv()->buffer()->params()); +} + + DispatchResult LyXText::dispatch(FuncRequest const & cmd) { - lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action - <<"] arg[" << cmd.argument << ']' << "xy[" << - cmd.x << ',' << cmd.y << ']' << endl; + //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl; + lyxerr << "LyXText::dispatch: cmd: " << cmd << endl; BufferView * bv = cmd.view(); @@ -428,27 +596,27 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } case LFUN_DELETE_WORD_FORWARD: - bv->beforeChange(this); + clearSelection(); deleteWordForward(); finishChange(bv); break; case LFUN_DELETE_WORD_BACKWARD: - bv->beforeChange(this); + clearSelection(); deleteWordBackward(); finishChange(bv); break; case LFUN_DELETE_LINE_FORWARD: - bv->beforeChange(this); + clearSelection(); deleteLineForward(); finishChange(bv); break; case LFUN_WORDRIGHT: if (!selection.mark()) - bv->beforeChange(this); - if (cursorPar()->isRightToLeftPar(bv->buffer()->params())) + clearSelection(); + if (rtl()) cursorLeftOneWord(); else cursorRightOneWord(); @@ -457,8 +625,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_WORDLEFT: if (!selection.mark()) - bv->beforeChange(this); - if (cursorPar()->isRightToLeftPar(bv->buffer()->params())) + clearSelection(); + if (rtl()) cursorRightOneWord(); else cursorLeftOneWord(); @@ -467,14 +635,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_BEGINNINGBUF: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorTop(); finishChange(bv); break; case LFUN_ENDBUF: if (selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorBottom(); finishChange(bv); break; @@ -482,7 +650,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_RIGHTSEL: if (!selection.set()) selection.cursor = cursor; - if (cursorPar()->isRightToLeftPar(bv->buffer()->params())) + if (rtl()) cursorLeft(bv); else cursorRight(bv); @@ -492,7 +660,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_LEFTSEL: if (!selection.set()) selection.cursor = cursor; - if (cursorPar()->isRightToLeftPar(bv->buffer()->params())) + if (rtl()) cursorRight(bv); else cursorLeft(bv); @@ -556,7 +724,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_WORDRIGHTSEL: - if (cursorPar()->isRightToLeftPar(bv->buffer()->params())) + if (rtl()) cursorLeftOneWord(); else cursorRightOneWord(); @@ -564,7 +732,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_WORDLEFTSEL: - if (cursorPar()->isRightToLeftPar(bv->buffer()->params())) + if (rtl()) cursorRightOneWord(); else cursorLeftOneWord(); @@ -576,16 +744,16 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) LyXCursor cur2; ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs()); setCursor(cur1.par(), cur1.pos()); - bv->beforeChange(this); + clearSelection(); setCursor(cur2.par(), cur2.pos()); finishChange(bv, true); break; } case LFUN_RIGHT: { - bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params()); + bool is_rtl = rtl(); if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); if (is_rtl) cursorLeft(false); if (cursor.pos() < cursorPar()->size() @@ -603,11 +771,11 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } case LFUN_LEFT: { - // This is soooo ugly. Isn`t it possible to make + // This is soooo ugly. Isn't it possible to make // it simpler? (Lgb) - bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params()); + bool const is_rtl = rtl(); if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); LyXCursor const cur = cursor; if (!is_rtl) cursorLeft(false); @@ -618,7 +786,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) InsetOld * tmpinset = cursorPar()->getInset(cursor.pos()); cmd.message(tmpinset->editMessage()); tmpinset->edit(bv, is_rtl); - bv->cursor().push(tmpinset, tmpinset->getText(0)); break; } if (is_rtl) @@ -629,56 +796,56 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_UP: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorUp(false); finishChange(bv); break; case LFUN_DOWN: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorDown(false); finishChange(bv); break; case LFUN_UP_PARAGRAPH: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorUpParagraph(); finishChange(bv); break; case LFUN_DOWN_PARAGRAPH: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorDownParagraph(); finishChange(bv, false); break; case LFUN_PRIOR: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorPrevious(); finishChange(bv, false); break; case LFUN_NEXT: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorNext(); finishChange(bv, false); break; case LFUN_HOME: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorHome(); finishChange(bv, false); break; case LFUN_END: if (!selection.mark()) - bv->beforeChange(this); + clearSelection(); cursorEnd(); finishChange(bv, false); break; @@ -866,12 +1033,11 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } case LFUN_INSET_SETTINGS: - BOOST_ASSERT(bv->theLockingInset()); - bv->theLockingInset()->getLockingInset()->showInsetDialog(bv); + bv->cursor().innerInset()->showInsetDialog(bv); break; case LFUN_INSET_TOGGLE: - bv->beforeChange(this); + clearSelection(); toggleInset(); bv->update(); bv->switchKeyMap(); @@ -906,14 +1072,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_MARK_OFF: - bv->beforeChange(this); + clearSelection(); bv->update(); selection.cursor = cursor; cmd.message(N_("Mark off")); break; case LFUN_MARK_ON: - bv->beforeChange(this); + clearSelection(); selection.mark(true); bv->update(); selection.cursor = cursor; @@ -921,7 +1087,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_SETMARK: - bv->beforeChange(this); + clearSelection(); if (selection.mark()) { cmd.message(N_("Mark removed")); } else { @@ -1082,16 +1248,15 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } case LFUN_PASTESELECTION: { - // this was originally a beforeChange(bv->text), i.e + // this was originally a bv->text->clearSelection(), i.e // the outermost LyXText! - bv->beforeChange(this); + clearSelection(); string const clip = bv->getClipboard(); if (!clip.empty()) { if (cmd.argument == "paragraph") insertStringAsParagraphs(clip); else insertStringAsLines(clip); - clearSelection(); bv->update(); } break; @@ -1161,8 +1326,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_MOUSE_TRIPLE: if (!bv->buffer()) break; - if (!isInInset() && bv->theLockingInset()) - break; if (cmd.button() == mouse_button::button1) { cursorHome(); selection.cursor = cursor; @@ -1176,8 +1339,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_MOUSE_DOUBLE: if (!bv->buffer()) break; - if (!isInInset() && bv->theLockingInset()) - break; if (cmd.button() == mouse_button::button1) { selectWord(lyx::WHOLE_WORD_STRICT); bv->update(); @@ -1185,8 +1346,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } break; - case LFUN_MOUSE_MOTION: - { + case LFUN_MOUSE_MOTION: { // Only use motion with button 1 //if (ev.button() != mouse_button::button1) // return false; @@ -1195,8 +1355,9 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; // Check for inset locking - if (bv->theLockingInset()) { - InsetOld * tli = bv->theLockingInset(); +#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(); @@ -1209,6 +1370,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) 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 @@ -1261,10 +1423,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; } - int x = cmd.x; - int y = cmd.y; - InsetOld * inset_hit = bv->text->checkInsetHit(x, y); - // Middle button press pastes if we have a selection // We do this here as if the selection was inside an inset // it could get cleared on the unlocking of the inset so @@ -1276,55 +1434,20 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } int const screen_first = bv->top_y(); - - if (bv->theLockingInset()) { - // We are in inset locking mode - - // Check whether the inset was hit. If not reset mode, - // otherwise give the event to the inset - if (inset_hit == bv->theLockingInset()) { - FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button()); - bv->theLockingInset()->dispatch(cmd1); - break; - } - bv->unlockInset(bv->theLockingInset()); - lyxerr << "Re-initializing cursor" << endl; - bv->cursor() = LCursor(bv); - } - - if (!inset_hit) - selection_possible = true; + selection_possible = true; // Clear the selection bv->text->clearSelection(); bv->update(); bv->updateScrollbar(); - // Single left click in math inset? - if (isHighlyEditableInset(inset_hit)) { - lyxerr << "click on highly editable inset, like math" << endl; - UpdatableInset * inset = static_cast(inset_hit); - selection_possible = false; - bv->owner()->message(inset->editMessage()); - // We just have to lock the inset before calling a PressEvent on it! - if (!bv->lockInset(inset)) - lyxerr << "Cannot lock inset" << endl; -#warning cell 0 is certainly not always good. - bv->cursor().push(inset, inset->getText(0)); - FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button()); - inset->dispatch(cmd1); - break; - } - // I'm not sure we should continue here if we hit an inset (Jug20020403) - // Right click on a footnote flag opens float menu if (cmd.button() == mouse_button::button3) { selection_possible = false; break; } - if (!inset_hit) // otherwise it was already set in checkInsetHit(...) - bv->text->setCursorFromCoordinates(x, y + screen_first); + bv->text->setCursorFromCoordinates(cmd.x, cmd.y + screen_first); finishUndo(); bv->text->selection.cursor = bv->text->cursor; bv->x_target(bv->text->cursor.x()); @@ -1345,8 +1468,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; } - case LFUN_MOUSE_RELEASE: - { + case LFUN_MOUSE_RELEASE: { // do nothing if we used the mouse wheel if (!bv->buffer()) break; @@ -1355,24 +1477,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) || cmd.button() == mouse_button::button5) break; - // If we hit an inset, we have the inset coordinates in these - // and inset_hit points to the inset. If we do not hit an - // inset, inset_hit is 0, and inset_x == x, inset_y == y. - int x = cmd.x; - int y = cmd.y; - InsetOld * inset_hit = bv->text->checkInsetHit(x, y); - - if (bv->theLockingInset()) { - // We are in inset locking mode. - - // LyX does a kind of work-area grabbing for insets. - // Only a ButtonPress FuncRequest outside the inset will - // force a insetUnlock. - FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button()); - bv->theLockingInset()->dispatch(cmd1); - break; - } - selection_possible = false; if (cmd.button() == mouse_button::button2) @@ -1386,49 +1490,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) bv->owner()->view_state_changed(); bv->owner()->updateMenubar(); bv->owner()->updateToolbar(); - - // Did we hit an editable inset? - if (inset_hit) { - selection_possible = false; - - // if we reach this point with a selection, it - // must mean we are currently selecting. - // But we don't want to open the inset - // because that is annoying for the user. - // So just pretend we didn't hit it. - // this is OK because a "kosher" ButtonRelease - // will follow a ButtonPress that clears - // the selection. - // Note this also fixes selection drawing - // problems if we end up opening an inset - if (selection.set()) - break; - - // CHECK fix this proper in 0.13 - // well, maybe 13.0 !!!!!!!!! - - // Following a ref shouldn't issue - // a push on the undo-stack - // anylonger, now that we have - // keybindings for following - // references and returning from - // references. IMHO though, it - // should be the inset's own business - // to push or not push on the undo - // stack. They don't *have* to - // alter the document... - // (Joacim) - // ...or maybe the recordUndo() - // below isn't necessary at all anylonger? - if (inset_hit->lyxCode() == InsetOld::REF_CODE) - recUndo(cursor.par()); - - bv->owner()->message(inset_hit->editMessage()); - - FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button()); - inset_hit->dispatch(cmd1); - } - break; } @@ -1448,7 +1509,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) bv->haveSelection(false); } - bv->beforeChange(this); + clearSelection(); LyXFont const old_font = real_current_font; string::const_iterator cit = cmd.argument.begin(); @@ -1522,18 +1583,113 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_DEPTH_MIN: - bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false); clearSelection(); + bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false); bv->update(); break; case LFUN_DEPTH_PLUS: clearSelection(); bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false); - clearSelection(); bv->update(); break; + case LFUN_MATH_DELIM: + case LFUN_MATH_DISPLAY: + case LFUN_INSERT_MATH: + case LFUN_MATH_LIMITS: + case LFUN_MATH_MACRO: + case LFUN_MATH_MUTATE: + case LFUN_MATH_SPACE: + case LFUN_MATH_IMPORT_SELECTION: + case LFUN_MATH_MODE: + case LFUN_MATH_NONUMBER: + case LFUN_MATH_NUMBER: + case LFUN_MATH_EXTERN: + case LFUN_MATH_SIZE: + mathDispatch(cmd); + break; + + case LFUN_EMPH: + emph(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_BOLD: + bold(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_NOUN: + noun(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_CODE: + code(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_SANS: + sans(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_ROMAN: + roman(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_DEFAULT: + styleReset(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_UNDERLINE: + underline(bv, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_FONT_SIZE: + fontSize(bv, cmd.argument, this); + bv->owner()->view_state_changed(); + break; + + case LFUN_LANGUAGE: + lang(bv, cmd.argument, this); + bv->switchKeyMap(); + bv->owner()->view_state_changed(); + break; + + case LFUN_FREEFONT_APPLY: + apply_freefont(bv, this); + break; + + case LFUN_FREEFONT_UPDATE: + update_and_apply_freefont(bv, this, cmd.argument); + break; + + case LFUN_FINISHED_LEFT: + lyxerr << "swallow LFUN_FINISHED_LEFT" << endl; + if (rtl()) + cursorRight(bv); + break; + + case LFUN_FINISHED_RIGHT: + lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl; + if (!rtl()) + cursorRight(bv); + break; + + case LFUN_FINISHED_UP: + lyxerr << "swallow LFUN_FINISHED_UP" << endl; + break; + + case LFUN_FINISHED_DOWN: + lyxerr << "swallow LFUN_FINISHED_DOWN" << endl; + cursorRight(bv); + break; + default: return DispatchResult(false); } diff --git a/src/undo.C b/src/undo.C index 44166bca4c..5dd0af2565 100644 --- a/src/undo.C +++ b/src/undo.C @@ -203,10 +203,7 @@ bool textUndoOrRedo(BufferView * bv, { if (stack.empty()) { // nothing to do - freezeUndo(); - bv->unlockInset(bv->theLockingInset()); finishUndo(); - unFreezeUndo(); return false; } @@ -232,12 +229,7 @@ bool textUndoOrRedo(BufferView * bv, lyxerr << " undo other: " << otherstack.top() << std::endl; } - // Now we can unlock the inset for safety because the inset - // pointer could be changed during the undo-function. Anyway - // if needed we have to lock the right inset/position if this - // is requested. freezeUndo(); - bv->unlockInset(bv->theLockingInset()); bool const ret = performUndoOrRedo(bv, undo); unFreezeUndo(); return ret; -- 2.39.2