Inset::insertInset and the toc's metrics/draw is unneeded. This furthermore creates just one cursor slice for clicks on tabulars. Official plan in one cursor slice for tabular. Better solution in the long run (in the light of IU) and according to a few experiements not much harder to implement.
Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
? .iterators.C.swp ? .lyxlayout.C.swp ? 1.diff ? bugs.diff ? insets/2 Index: BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.473 diff -u -p -r1.473 BufferView_pimpl.C --- BufferView_pimpl.C 2 Dec 2003 10:51:57 -0000 1.473 +++ BufferView_pimpl.C 10 Dec 2003 09:06:35 -0000 @@ -750,13 +750,13 @@ InsetOld * BufferView::Pimpl::getInsetBy Buffer::inset_iterator beg = b->inset_iterator_begin(); Buffer::inset_iterator end = b->inset_iterator_end(); - bool cursorPar_seen = false; + bool cursor_par_seen = false; for (; beg != end; ++beg) { if (beg.getPar() == text->cursorPar()) { - cursorPar_seen = true; + cursor_par_seen = true; } - if (cursorPar_seen) { + if (cursor_par_seen) { if (beg.getPar() == text->cursorPar() && beg.getPos() >= text->cursor.pos()) { break; @@ -871,21 +871,25 @@ namespace { InsetOld * insetFromCoords(BufferView * bv, int x, int y) { + lyxerr << "insetFromCoords" << endl; LyXText * text = bv->text(); InsetOld * inset = 0; theTempCursor = LCursor(bv); while (true) { - InsetOld * inset_hit = text->checkInsetHit(x, y); + InsetOld * const inset_hit = text->checkInsetHit(x, y); if (!inset_hit) { lyxerr << "no further inset hit" << endl; break; } inset = inset_hit; - if (!inset_hit->descendable()) { + if (!inset->descendable()) { lyxerr << "not descendable" << endl; break; } - text = inset_hit->getText(0); + int const cell = inset->getCell(x, y); + if (cell == -1) + break; + text = inset_hit->getText(cell); lyxerr << "Hit inset: " << inset << " at x: " << x << " text: " << text << " y: " << y << endl; theTempCursor.push(static_cast<UpdatableInset*>(inset)); Index: CutAndPaste.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.C,v retrieving revision 1.125 diff -u -p -r1.125 CutAndPaste.C --- CutAndPaste.C 1 Dec 2003 13:35:37 -0000 1.125 +++ CutAndPaste.C 10 Dec 2003 09:06:35 -0000 @@ -248,7 +248,7 @@ CutAndPaste::pasteSelection(Buffer const // this new max depth level so that subsequent // paragraphs are aligned correctly to this paragraph // at level 0. - if ((int(tmpbuf->params().depth()) + depth_delta) < 0) + if (int(tmpbuf->params().depth()) + depth_delta < 0) depth_delta = 0; // Set the right depth so that we are not too deep or shallow. Index: bufferview_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferview_funcs.C,v retrieving revision 1.127 diff -u -p -r1.127 bufferview_funcs.C --- bufferview_funcs.C 1 Dec 2003 13:35:38 -0000 1.127 +++ bufferview_funcs.C 10 Dec 2003 09:06:35 -0000 @@ -309,4 +309,4 @@ void put_selection_at(BufferView * bv, P } -}; // namespace bv_funcs +} // namespace bv_funcs Index: cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v retrieving revision 1.26 diff -u -p -r1.26 cursor.C --- cursor.C 28 Nov 2003 08:55:06 -0000 1.26 +++ cursor.C 10 Dec 2003 09:06:35 -0000 @@ -35,6 +35,7 @@ using std::endl; std::ostream & operator<<(std::ostream & os, CursorItem const & item) { os << " inset: " << item.inset_ + << " code: " << item.inset_->lyxCode() << " text: " << item.text() // << " par: " << item.par_ // << " pos: " << item.pos_ Index: lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.269 diff -u -p -r1.269 lyxtext.h --- lyxtext.h 8 Dec 2003 12:47:18 -0000 1.269 +++ lyxtext.h 10 Dec 2003 09:06:35 -0000 @@ -394,6 +394,11 @@ public: void write(Buffer const & buf, std::ostream & os) const; /// returns whether we've seen our usual 'end' marker bool read(Buffer const & buf, LyXLex & lex); + + /// + int ascent() const; + /// + int descent() const; public: /// Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.508 diff -u -p -r1.508 text.C --- text.C 3 Dec 2003 18:17:15 -0000 1.508 +++ text.C 10 Dec 2003 09:06:35 -0000 @@ -1844,3 +1844,16 @@ bool LyXText::read(Buffer const & buf, L } return the_end_read; } + + +int LyXText::ascent() const +{ + return firstRow()->ascent_of_text(); +} + + +int LyXText::descent() const +{ + return height - firstRow()->ascent_of_text(); +} + Index: text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.192 diff -u -p -r1.192 text3.C --- text3.C 1 Dec 2003 13:35:44 -0000 1.192 +++ text3.C 10 Dec 2003 09:06:35 -0000 @@ -252,7 +252,6 @@ string const freefont2string() } - InsetOld * LyXText::checkInsetHit(int x, int y) { ParagraphList::iterator pit; Index: insets/inset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.C,v retrieving revision 1.120 diff -u -p -r1.120 inset.C --- insets/inset.C 1 Dec 2003 13:35:45 -0000 1.120 +++ insets/inset.C 10 Dec 2003 09:06:35 -0000 @@ -17,7 +17,9 @@ #include "updatableinset.h" #include "BufferView.h" +#include "debug.h" #include "gettext.h" +#include "lyxtext.h" #include "LColor.h" @@ -114,6 +116,30 @@ int InsetOld::scroll(bool recursive) con return 0; } + +int InsetOld::getCell(int x, int y) const +{ + for (int i = 0, n = numParagraphs(); i < n; ++i) { + LyXText * text = getText(i); + //lyxerr << "### text: " << text << " i: " << i + // << " xo: " << text->xo_ << "..." << text->xo_ + text->width + // << " yo: " << text->yo_ + // << " yo: " << text->yo_ - text->ascent() << "..." + // << text->yo_ + text->descent() + // << std::endl; + if (x >= text->xo_ + && x <= text->xo_ + text->width + && y >= text->yo_ + && y <= text->yo_ + text->height) + { + lyxerr << "### found text # " << i << std::endl; + return i; + } + } + return -1; +} + + bool isEditableInset(InsetOld const * i) { return i && i->editable(); @@ -124,3 +150,5 @@ bool isHighlyEditableInset(InsetOld cons { return i && i->editable() == InsetOld::HIGHLY_EDITABLE; } + + Index: insets/inset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v retrieving revision 1.149 diff -u -p -r1.149 inset.h --- insets/inset.h 3 Dec 2003 18:17:17 -0000 1.149 +++ insets/inset.h 10 Dec 2003 09:06:35 -0000 @@ -226,6 +226,8 @@ public: virtual LyXText * getText(int /*num*/) const { return 0; } /// virtual int numParagraphs() const { return 0; } + /// returns cell covering position (x,y), -1 if none exists + virtual int getCell(int x, int y) const; /// used to toggle insets // is the inset open? Index: insets/insetcollapsable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v retrieving revision 1.221 diff -u -p -r1.221 insetcollapsable.C --- insets/insetcollapsable.C 3 Dec 2003 18:17:17 -0000 1.221 +++ insets/insetcollapsable.C 10 Dec 2003 09:06:35 -0000 @@ -65,17 +65,6 @@ InsetCollapsable::InsetCollapsable(Inset } -bool InsetCollapsable::insertInset(BufferView * bv, InsetOld * in) -{ - if (!insetAllowed(in->lyxCode())) { - lyxerr << "InsetCollapsable::InsertInset: " - "Unable to insert inset." << endl; - return false; - } - return inset.insertInset(bv, in); -} - - void InsetCollapsable::write(Buffer const & buf, ostream & os) const { os << "collapsed " << (status_ == Collapsed ? "true" : "false") << "\n"; Index: insets/insetcollapsable.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v retrieving revision 1.156 diff -u -p -r1.156 insetcollapsable.h --- insets/insetcollapsable.h 3 Dec 2003 18:17:17 -0000 1.156 +++ insets/insetcollapsable.h 10 Dec 2003 09:06:35 -0000 @@ -61,8 +61,6 @@ public: /// can we go further down on mouse click? bool descendable() const; /// - bool insertInset(BufferView *, InsetOld * inset); - /// bool insetAllowed(InsetOld::Code code) const; /// bool isTextInset() const { return true; } Index: insets/insetert.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v retrieving revision 1.181 diff -u -p -r1.181 insetert.C --- insets/insetert.C 3 Dec 2003 18:17:17 -0000 1.181 +++ insets/insetert.C 10 Dec 2003 09:06:35 -0000 @@ -85,11 +85,6 @@ InsetERT::InsetERT(BufferParams const & status_ = collapsed ? Collapsed : Open; LyXFont font(LyXFont::ALL_INHERIT, l); -#ifdef SET_HARD_FONT - font.setFamily(LyXFont::TYPEWRITER_FAMILY); - font.setColor(LColor::latex); -#endif - string::const_iterator cit = contents.begin(); string::const_iterator end = contents.end(); pos_type pos = 0; @@ -137,21 +132,6 @@ void InsetERT::read(Buffer const & buf, } inset.read(buf, lex); -#ifdef SET_HARD_FONT - LyXFont font(LyXFont::ALL_INHERIT, latex_language); - font.setFamily(LyXFont::TYPEWRITER_FAMILY); - font.setColor(LColor::latex); - - ParagraphList::iterator pit = inset.paragraphs().begin(); - ParagraphList::iterator pend = inset.paragraphs().end(); - for (; pit != pend; ++pit) { - pos_type siz = pit->size(); - for (pos_type i = 0; i < siz; ++i) { - pit->setFont(i, font); - } - } -#endif - if (!token_found) { if (isOpen()) status_ = Open; @@ -218,12 +198,6 @@ string const InsetERT::editMessage() con } -bool InsetERT::insertInset(BufferView *, InsetOld *) -{ - return false; -} - - void InsetERT::updateStatus(bool swap) const { if (status_ != Inlined) { @@ -396,17 +370,8 @@ void InsetERT::edit(BufferView * bv, boo DispatchResult InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { - BufferView * bv = cmd.view(); - switch (cmd.action) { - case LFUN_INSET_MODIFY: { - InsetERTMailer::string2params(cmd.argument, status_); - setButtonLabel(); - bv->update(); - return DispatchResult(true, true); - } - case LFUN_MOUSE_PRESS: lfunMousePress(cmd); return DispatchResult(true, true); @@ -419,8 +384,26 @@ InsetERT::priv_dispatch(FuncRequest cons lfunMouseRelease(cmd); return DispatchResult(true, true); + case LFUN_INSET_MODIFY: + InsetERTMailer::string2params(cmd.argument, status_); + setButtonLabel(); + return DispatchResult(true, true); + case LFUN_LAYOUT: - bv->owner()->setLayout(inset.paragraphs().begin()->layout()->name()); + case LFUN_BOLD: + case LFUN_CODE: + case LFUN_DEFAULT: + case LFUN_EMPH: + case LFUN_FREEFONT_APPLY: + case LFUN_FREEFONT_UPDATE: + case LFUN_NOUN: + case LFUN_ROMAN: + case LFUN_SANS: + case LFUN_FRAK: + case LFUN_ITAL: + case LFUN_FONT_SIZE: + case LFUN_FONT_STATE: + case LFUN_UNDERLINE: return DispatchResult(true); default: Index: insets/insetert.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.h,v retrieving revision 1.100 diff -u -p -r1.100 insetert.h --- insets/insetert.h 3 Dec 2003 18:17:17 -0000 1.100 +++ insets/insetert.h 10 Dec 2003 09:06:35 -0000 @@ -49,8 +49,6 @@ public: /// std::string const editMessage() const; /// - bool insertInset(BufferView *, InsetOld *); - /// bool insetAllowed(InsetOld::Code code) const; /// int latex(Buffer const &, std::ostream &, Index: insets/insettabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v retrieving revision 1.384 diff -u -p -r1.384 insettabular.C --- insets/insettabular.C 3 Dec 2003 18:17:17 -0000 1.384 +++ insets/insettabular.C 10 Dec 2003 09:06:35 -0000 @@ -388,12 +388,6 @@ void InsetTabular::updateLocal(BufferVie } -bool InsetTabular::insertInset(BufferView * bv, InsetOld * inset) -{ - return the_locking_inset && the_locking_inset->insertInset(bv, inset); -} - - void InsetTabular::lfunMousePress(FuncRequest const & cmd) { if (hasSelection() && cmd.button() == mouse_button::button3) @@ -404,10 +398,15 @@ void InsetTabular::lfunMousePress(FuncRe BufferView * bv = cmd.view(); - the_locking_inset = 0; - setPos(bv, cmd.x, cmd.y); - clearSelection(); - the_locking_inset = 0; + int cell = getCell(cmd.x + xo_, cmd.y + yo_); + lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl; + if (cell == -1) { + } else { + the_locking_inset = 0; + setPos(bv, cmd.x, cmd.y); + clearSelection(); + the_locking_inset = 0; + } if (cmd.button() == mouse_button::button2) dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph")); @@ -481,12 +480,11 @@ void InsetTabular::edit(BufferView * bv, DispatchResult InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) { - lyxerr << "InsetTabular::dispatch: " << cmd << endl; + 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. DispatchResult result(true, true); - BufferView * bv = cmd.view(); - bool hs = hasSelection(); + BufferView * bv = cmd.view(); switch (cmd.action) { @@ -616,7 +614,7 @@ InsetTabular::priv_dispatch(FuncRequest break; case LFUN_NEXT: { - if (hs) + if (hasSelection()) clearSelection(); int column = actcol; if (bv->top_y() + bv->painter().paperHeight() @@ -632,7 +630,7 @@ InsetTabular::priv_dispatch(FuncRequest } case LFUN_PRIOR: { - if (hs) + if (hasSelection()) clearSelection(); int column = actcol; if (yo_ < 0) { @@ -845,7 +843,7 @@ InsetTabular::priv_dispatch(FuncRequest result = DispatchResult(false); break; } - if (hs) + if (hasSelection()) clearSelection(); } break; @@ -1594,7 +1592,7 @@ bool InsetTabular::activateCellInset(Buf if (!the_locking_inset) return false; updateLocal(bv); - return the_locking_inset; + return true; } Index: insets/insettabular.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v retrieving revision 1.172 diff -u -p -r1.172 insettabular.h --- insets/insettabular.h 3 Dec 2003 18:17:19 -0000 1.172 +++ insets/insettabular.h 10 Dec 2003 09:06:35 -0000 @@ -80,8 +80,6 @@ public: /// void updateLocal(BufferView *) const; /// - bool insertInset(BufferView *, InsetOld *); - /// bool insetAllowed(InsetOld::Code code) const; /// bool isTextInset() const { return true; } @@ -149,14 +147,8 @@ public: /// void addPreview(lyx::graphics::PreviewLoader &) const; - // - // Public structures and variables - /// - mutable LyXTabular tabular; - /// are some cells selected ? bool hasSelection() const { return has_selection; } - /// Buffer const & buffer() const; @@ -168,6 +160,12 @@ public: void edit(BufferView * bv, int, int); /// can we go further down on mouse click? bool descendable() const { return true; } + + // + // Public structures and variables + /// + mutable LyXTabular tabular; + protected: /// virtual Index: insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.560 diff -u -p -r1.560 insettext.C --- insets/insettext.C 3 Dec 2003 18:17:19 -0000 1.560 +++ insets/insettext.C 10 Dec 2003 09:06:35 -0000 @@ -207,7 +207,7 @@ void InsetText::draw(PainterInfo & pi, i if (!owner()) x += scroll(); - y += bv->top_y() - text_.firstRow()->ascent_of_text(); + y += bv->top_y() - text_.ascent(); text_.draw(pi, x, y); @@ -390,16 +390,6 @@ void InsetText::getCursorPos(int & x, in { x = text_.cursor.x() + TEXT_TO_INSET_OFFSET; y = text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET; -} - - -bool InsetText::insertInset(BufferView * bv, InsetOld * inset) -{ - inset->setOwner(this); - text_.insertInset(inset); - updateLocal(bv); -#warning should we mark the buffer dirty? - return true; } Index: insets/insettext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v retrieving revision 1.238 diff -u -p -r1.238 insettext.h --- insets/insettext.h 3 Dec 2003 18:17:20 -0000 1.238 +++ insets/insettext.h 10 Dec 2003 09:06:35 -0000 @@ -90,8 +90,6 @@ public: /// FIXME, document void getCursorPos(int & x, int & y) const; /// - bool insertInset(BufferView *, InsetOld *); - /// bool insetAllowed(InsetOld::Code) const; /// void setFont(BufferView *, LyXFont const &, Index: insets/insettoc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettoc.C,v retrieving revision 1.66 diff -u -p -r1.66 insettoc.C --- insets/insettoc.C 20 Nov 2003 01:22:50 -0000 1.66 +++ insets/insettoc.C 10 Dec 2003 09:06:35 -0000 @@ -58,22 +58,6 @@ InsetOld::Code InsetTOC::lyxCode() const } -void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const -{ - InsetCommand::metrics(mi, dim); - int const x1 = (mi.base.textwidth - dim.wid) / 2; - button().setBox(Box(x1, x1 + dim.wid, -dim.asc, dim.des)); - dim.wid = mi.base.textwidth; - dim_ = dim; -} - - -void InsetTOC::draw(PainterInfo & pi, int, int y) const -{ - InsetCommand::draw(pi, button().box().x1, y); -} - - DispatchResult InsetTOC::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) Index: insets/insettoc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettoc.h,v retrieving revision 1.56 diff -u -p -r1.56 insettoc.h --- insets/insettoc.h 5 Nov 2003 12:06:18 -0000 1.56 +++ insets/insettoc.h 10 Dec 2003 09:06:35 -0000 @@ -12,14 +12,10 @@ #ifndef INSET_TOC_H #define INSET_TOC_H - #include "insetcommand.h" -class MetricsInfo; - -/** Used to insert table of contents - */ +/// Used to insert table of contents and similar lists class InsetTOC : public InsetCommand { public: /// @@ -28,10 +24,6 @@ public: ~InsetTOC(); /// std::auto_ptr<InsetBase> clone() const; - /// - void metrics(MetricsInfo &, Dimension &) const; - /// - void draw(PainterInfo & pi, int x, int y) const; /// std::string const getScreenLabel(Buffer const &) const; /// Index: insets/updatableinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.h,v retrieving revision 1.27 diff -u -p -r1.27 updatableinset.h --- insets/updatableinset.h 28 Nov 2003 08:55:12 -0000 1.27 +++ insets/updatableinset.h 10 Dec 2003 09:06:35 -0000 @@ -23,9 +23,6 @@ class UpdatableInset : public InsetOld { public: - /// check if the font of the char we want inserting is correct - /// and modify it if it is not. - virtual bool checkInsertChar(LyXFont &) { return true; } /// virtual EDITABLE editable() const; @@ -33,8 +30,6 @@ public: virtual void getCursorPos(int &, int &) const {} /// return the cursor dim virtual void getCursorDim(int &, int &) const; - /// - virtual bool insertInset(BufferView *, InsetOld *) { return false; } // We need this method to not clobber the real method in Inset int scroll(bool recursive = true) const { return InsetOld::scroll(recursive); }