From 153ac7500c4626a4e0ed38bf2bf88163f953c910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 10 Dec 2003 09:45:32 +0000 Subject: [PATCH] * inset.h: * insetert.[Ch]: * insettabular.[Ch]: * insettext.[Ch]: remove unused insetInset() * insetert.C: disable some LFUNs * insettoc.[Ch]: metrics() and draw() of InsetButton is enough. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8221 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 26 +++++++---------- src/CutAndPaste.C | 13 ++------- src/bufferview_funcs.C | 2 +- src/cursor.C | 1 + src/insets/ChangeLog | 12 ++++++++ src/insets/inset.C | 28 ++++++++++++++++++ src/insets/inset.h | 2 ++ src/insets/insetcollapsable.C | 11 ------- src/insets/insetcollapsable.h | 2 -- src/insets/insetert.C | 55 ++++++++++++----------------------- src/insets/insetert.h | 2 -- src/insets/insettabular.C | 32 ++++++++++---------- src/insets/insettabular.h | 14 ++++----- src/insets/insettext.C | 12 +------- src/insets/insettext.h | 2 -- src/insets/insettoc.C | 16 ---------- src/insets/insettoc.h | 10 +------ src/insets/updatableinset.h | 5 ---- src/lyxtext.h | 5 ++++ src/text.C | 13 +++++++++ src/text3.C | 1 - 21 files changed, 116 insertions(+), 148 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 58b34419be..c73217116d 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -750,13 +750,13 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code) 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(inset)); @@ -1255,16 +1259,6 @@ 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()) { - if (bv_->theLockingInset()->insetAllowed(inset)) - return bv_->theLockingInset()->insertInset(bv_, inset); - return false; - } -#endif - // not quite sure if we want this... bv_->text()->recUndo(bv_->text()->cursor.par()); freezeUndo(); diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index c3aab6fe7f..23d0765ae5 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -248,7 +248,7 @@ CutAndPaste::pasteSelection(Buffer const & buffer, // 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. @@ -265,17 +265,8 @@ CutAndPaste::pasteSelection(Buffer const & buffer, tmpbuf->setInsetOwner(pit->inInset()); for (pos_type i = 0; i < tmpbuf->size(); ++i) { if (tmpbuf->getChar(i) == Paragraph::META_INSET) { - if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) { + if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) tmpbuf->erase(i--); - } - } else { - LyXFont f1 = tmpbuf->getFont(buffer.params(), i, outerFont(pit, pars)); - LyXFont f2 = f1; - if (!pit->checkInsertChar(f1)) { - tmpbuf->erase(i--); - } else if (f1 != f2) { - tmpbuf->setFont(i, f1); - } } } } diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index b7b19a533a..88d8405f80 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -309,4 +309,4 @@ void put_selection_at(BufferView * bv, PosIterator const & cur, } -}; // namespace bv_funcs +} // namespace bv_funcs diff --git a/src/cursor.C b/src/cursor.C index b5a35e2cf4..0ff4ae9508 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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_ diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index f1cf93657f..5db03efc2c 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,15 @@ + +2003-12-10 André Pönitz + + * inset.h: + * insetert.[Ch]: + * insettabular.[Ch]: + * insettext.[Ch]: remove unused insetInset() + + * insetert.C: disable some LFUNs + + * insettoc.[Ch]: metrics() and draw() of InsetButton is enough. + 2003-12-04 Martin Vermeer * insetcharstyle.[Ch]: Conglomerate-style CharStyles diff --git a/src/insets/inset.C b/src/insets/inset.C index 88affad075..9d56a9713b 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -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) const 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 const * i) { return i && i->editable() == InsetOld::HIGHLY_EDITABLE; } + + diff --git a/src/insets/inset.h b/src/insets/inset.h index 0539f91dc9..f281724111 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -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? diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 918f1c2c72..49d4ff4052 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -65,17 +65,6 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & in) } -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"; diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 8cb7df7ae8..9d4ebbc1d0 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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; } diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 3fef4e1a64..eb5a7fd22c 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -85,11 +85,6 @@ InsetERT::InsetERT(BufferParams const & bp, 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, LyXLex & lex) } 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() const } -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, bool left) 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 const & cmd, idx_type & idx, pos_type & pos) 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: diff --git a/src/insets/insetert.h b/src/insets/insetert.h index e2c295565b..3fb04dd44f 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -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 &, diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 528f769378..0830576152 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -388,12 +388,6 @@ void InsetTabular::updateLocal(BufferView * bv) const } -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(FuncRequest const & cmd) 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, int x, int y) 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 const & cmd, idx_type &, pos_type &) 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 const & cmd, idx_type &, pos_type &) } case LFUN_PRIOR: { - if (hs) + if (hasSelection()) clearSelection(); int column = actcol; if (yo_ < 0) { @@ -845,7 +843,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) result = DispatchResult(false); break; } - if (hs) + if (hasSelection()) clearSelection(); } break; @@ -1594,7 +1592,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind) if (!the_locking_inset) return false; updateLocal(bv); - return the_locking_inset; + return true; } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index cf3875ea05..82cb9530c0 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -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 diff --git a/src/insets/insettext.C b/src/insets/insettext.C index d5c548784b..9b599802c9 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -207,7 +207,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const if (!owner()) x += scroll(); - y += bv->top_y() - text_.firstRow()->ascent_of_text(); + y += bv->top_y() - text_.ascent(); text_.draw(pi, x, y); @@ -393,16 +393,6 @@ void InsetText::getCursorPos(int & x, int & y) const } -bool InsetText::insertInset(BufferView * bv, InsetOld * inset) -{ - inset->setOwner(this); - text_.insertInset(inset); - updateLocal(bv); -#warning should we mark the buffer dirty? - return true; -} - - bool InsetText::insetAllowed(InsetOld::Code code) const { // in_insetAllowed is a really gross hack, diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 4dd4f5dd57..c4f2c9beaa 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -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 &, diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index 7277322f00..5b5f3ec436 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -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) diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 45c2f76663..1579655128 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -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: /// @@ -29,10 +25,6 @@ public: /// std::auto_ptr clone() const; /// - void metrics(MetricsInfo &, Dimension &) const; - /// - void draw(PainterInfo & pi, int x, int y) const; - /// std::string const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 8ea216607f..af9ec80b52 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -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); } diff --git a/src/lyxtext.h b/src/lyxtext.h index 799d02ed23..9b5290cbd5 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -395,6 +395,11 @@ public: /// returns whether we've seen our usual 'end' marker bool read(Buffer const & buf, LyXLex & lex); + /// + int ascent() const; + /// + int descent() const; + public: /// int height; diff --git a/src/text.C b/src/text.C index 2b952bc4f6..0d074bd03f 100644 --- a/src/text.C +++ b/src/text.C @@ -1844,3 +1844,16 @@ bool LyXText::read(Buffer const & buf, LyXLex & lex) } return the_end_read; } + + +int LyXText::ascent() const +{ + return firstRow()->ascent_of_text(); +} + + +int LyXText::descent() const +{ + return height - firstRow()->ascent_of_text(); +} + diff --git a/src/text3.C b/src/text3.C index 8bc6b3d053..b42ee51d0b 100644 --- a/src/text3.C +++ b/src/text3.C @@ -252,7 +252,6 @@ string const freefont2string() } - InsetOld * LyXText::checkInsetHit(int x, int y) { ParagraphList::iterator pit;