]> git.lyx.org Git - features.git/commitdiff
* inset.h:
authorAndré Pönitz <poenitz@gmx.net>
Wed, 10 Dec 2003 09:45:32 +0000 (09:45 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 10 Dec 2003 09:45:32 +0000 (09:45 +0000)
* 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

21 files changed:
src/BufferView_pimpl.C
src/CutAndPaste.C
src/bufferview_funcs.C
src/cursor.C
src/insets/ChangeLog
src/insets/inset.C
src/insets/inset.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetert.C
src/insets/insetert.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/insettoc.C
src/insets/insettoc.h
src/insets/updatableinset.h
src/lyxtext.h
src/text.C
src/text3.C

index 58b34419be4cde081331b8c7411dc15447744950..c73217116de8443abecd51ef4b78a3601b083225 100644 (file)
@@ -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<UpdatableInset*>(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();
index c3aab6fe7fb67851491ed3a51920f0a5f7390a77..23d0765ae55298102842f85482571ce057d1b233 100644 (file)
@@ -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);
-                               }
                        }
                }
        }
index b7b19a533a320bc5db131f341e75dea8453d842b..88d8405f803854e5e77f98e7d044828ce787942f 100644 (file)
@@ -309,4 +309,4 @@ void put_selection_at(BufferView * bv, PosIterator const & cur,
 }
 
 
-}; // namespace bv_funcs
+} // namespace bv_funcs
index b5a35e2cf4d9df096263f1d3dc266d19c36b327d..0ff4ae9508e56a2393b3cec8ae43ff793ef53bd5 100644 (file)
@@ -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 f1cf93657f54136fc5502640e29132d0abfd1dda..5db03efc2c0d69eee61676f4d24a594c45550fab 100644 (file)
@@ -1,3 +1,15 @@
+
+2003-12-10  André Pönitz  <poenitz@gmx.net>
+
+       * 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  <martin.vermee@hut.fi>
 
        * insetcharstyle.[Ch]: Conglomerate-style CharStyles
index 88affad0752447fc792d724c56d67e7ef6344e1c..9d56a9713bb1d89fef593532d76192ea90ec50f1 100644 (file)
@@ -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;
 }
+
+
index 0539f91dc990b35f3c9491843e6b3fde901829a5..f2817241117812cbb421d99bff48d52e8c6a3bed 100644 (file)
@@ -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 918f1c2c723d9c84ee448a597c9b2a6d2c609372..49d4ff405261dfa7665b5ddcbcee80061ac0275d 100644 (file)
@@ -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";
index 8cb7df7ae804ba55c9d7047a7bf8614d5bb844e0..9d4ebbc1d0e86ad709daf08913dc6b7f2d456a8c 100644 (file)
@@ -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 3fef4e1a640df843cd531777abeea63f610637b5..eb5a7fd22c6869ee1e4ba4be45ebc8a3dea4ed2f 100644 (file)
@@ -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:
index e2c295565bdfbd33ca9d4511f5246c3c22471479..3fb04dd44f3191b6aa49466fc3db869d4f17268a 100644 (file)
@@ -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 528f769378efd0ca3318c20d2e558092c96fb0d2..0830576152de1cb7bef2780f58635c5bea1dfc0d 100644 (file)
@@ -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;
 }
 
 
index cf3875ea054ec4c029dff9511f3cd581e2267719..82cb9530c06ee08965493b9e285a0179bcd7d90d 100644 (file)
@@ -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 d5c548784bab620e9a909fa77175e178dc53d539..9b599802c9ede8e1aaad77b15093e052b7f600ba 100644 (file)
@@ -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,
index 4dd4f5dd573d5479759044608f65555b51195c38..c4f2c9beaa535fa0f0f95642d929b0940461749e 100644 (file)
@@ -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 7277322f000d7f215e90ab40a6562a3f9e01cd2e..5b5f3ec4367b67c0710e700d15c9af3b8d4bb36b 100644 (file)
@@ -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 45c2f76663e54744ffd1f6d6da634d48cd50eb5a..15796551288046850bc6772240ffdea665e5c5dd 100644 (file)
 #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<InsetBase> 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; }
index 8ea216607f58d28ff363da2d02bb14652dfe0fda..af9ec80b524dd3a446fadf4f8bf980ae006f7190 100644 (file)
@@ -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); }
index 799d02ed23e1f49f4f151391096bce7e35c87c26..9b5290cbd530cc4060f1901fa349b72c25a0ebfd 100644 (file)
@@ -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;
index 2b952bc4f69ec4b03cd5f1daa6cb7c6bcf96c2da..0d074bd03fa03640b4fbccab896089bd2837b313 100644 (file)
@@ -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();
+}
+
index 8bc6b3d05300bcb2763f3c6dab8786247782ad76..b42ee51d0be1b7e572d2febf60b51022358b8402 100644 (file)
@@ -252,7 +252,6 @@ string const freefont2string()
 }
 
 
-
 InsetOld * LyXText::checkInsetHit(int x, int y)
 {
        ParagraphList::iterator pit;