]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView2.C
Look for mathed xpms. Doesn't do anything yet due to lack of workable XPMs
[lyx.git] / src / BufferView2.C
index fa9456ea50788a105b496d7242557021762e5155..c467f4922ff0060c13b1cf01a5a450235da02a25 100644 (file)
@@ -14,9 +14,9 @@
 #include "buffer.h"
 #include "lyxcursor.h"
 #include "lyxtext.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
 #include "bufferlist.h"
-#include "lyxscreen.h"
+#include "frontends/screen.h"
 #include "LaTeX.h"
 #include "BufferView_pimpl.h"
 #include "language.h"
 #include "undo_funcs.h"
 #include "debug.h"
 #include "iterators.h"
+#include "lyxlex.h"
+#include "WordLangTuple.h"
 
 #include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
 
 #include "insets/insetcommand.h" //ChangeRefs
 #include "insets/inseterror.h"
@@ -56,11 +59,12 @@ bool BufferView::insertLyXFile(string const & filen)
        // Copyright CHT Software Service GmbH
        // Uwe C. Schroeder
        //
-       // Insert a Lyxformat - file into current buffer
+       // Insert a LyXformat - file into current buffer
        //
        // Moved from lyx_cb.C (Lgb)
 {
-       if (filen.empty()) return false;
+       if (filen.empty())
+               return false;
 
        string const fname = MakeAbsPath(filen);
 
@@ -189,19 +193,20 @@ bool BufferView::removeAutoInsets()
                        }
                }
 
-               Paragraph::inset_iterator pit = par->inset_iterator_begin();
-               Paragraph::inset_iterator pend = par->inset_iterator_end();
+               InsetList::iterator pit = par->insetlist.begin();
+               InsetList::iterator pend = par->insetlist.end();
+
                while (pit != pend) {
-                       if (pit->autoDelete()) {
+                       if (pit.getInset()->autoDelete()) {
                                removed = true;
                                pos_type const pos = pit.getPos();
 
                                par->erase(pos);
                                // We just invalidated par's inset iterators so
                                // we get the next valid iterator position
-                               pit = par->InsetIterator(pos);
+                               pit = par->insetlist.insetIterator(pos);
                                // and ensure we have a valid end iterator.
-                               pend = par->inset_iterator_end();
+                               pend = par->insetlist.end();
 
                                if (cursor_par == par) {
                                        // update the saved cursor position
@@ -273,10 +278,12 @@ void BufferView::insertErrors(TeXErrors & terr)
                if (texrowpar == 0)
                        continue;
 
+               freezeUndo();
                InsetError * new_inset = new InsetError(msgtxt);
                text->setCursorIntern(this, texrowpar, tmppos);
                text->insertInset(this, new_inset);
                text->fullRebreak(this);
+               unFreezeUndo();
        }
        // Restore the cursor position
        text->setCursorIntern(this, cursor.par(), cursor.pos());
@@ -308,17 +315,16 @@ bool BufferView::insertInset(Inset * inset, string const & lout)
 }
 
 
-/* This is also a buffer property (ale) */
+// This is also a buffer property (ale)
 // Not so sure about that. a goto Label function can not be buffer local, just
-// think how this will work in a multiwindo/buffer environment, all the
+// think how this will work in a multiwindow/buffer environment, all the
 // cursors in all the views showing this buffer will move. (Lgb)
 // OK, then no cursor action should be allowed in buffer. (ale)
 bool BufferView::gotoLabel(string const & label)
-
 {
        for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
             it != buffer()->inset_iterator_end(); ++it) {
-               vector<string> labels = (*it)->getLabelList();
+               vector<string> labels = it->getLabelList();
                if (find(labels.begin(),labels.end(),label)
                     != labels.end()) {
                        beforeChange(text);
@@ -334,40 +340,35 @@ bool BufferView::gotoLabel(string const & label)
 
 void BufferView::menuUndo()
 {
-       if (available()) {
-               owner()->message(_("Undo"));
-               hideCursor();
-               beforeChange(text);
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               if (!textUndo(this))
-                       owner()->message(_("No further undo information"));
-               else
-                       update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               setState();
-       }
+       if (!available())
+               return;
+
+       owner()->message(_("Undo"));
+       hideCursor();
+       beforeChange(text);
+       update(text, BufferView::SELECT|BufferView::FITCUR);
+       if (!textUndo(this))
+               owner()->message(_("No further undo information"));
+       else
+               update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+       switchKeyMap();
 }
 
 
 void BufferView::menuRedo()
 {
-#if 0 // this should not be here (Jug 20011206)
-       if (theLockingInset()) {
-               owner()->message(_("Redo not yet supported in math mode"));
+       if (!available())
                return;
-       }
-#endif
 
-       if (available()) {
-               owner()->message(_("Redo"));
-               hideCursor();
-               beforeChange(text);
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               if (!textRedo(this))
-                       owner()->message(_("No further redo information"));
-               else
-                       update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               setState();
-       }
+       owner()->message(_("Redo"));
+       hideCursor();
+       beforeChange(text);
+       update(text, BufferView::SELECT|BufferView::FITCUR);
+       if (!textRedo(this))
+               owner()->message(_("No further redo information"));
+       else
+               update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+       switchKeyMap();
 }
 
 
@@ -390,60 +391,12 @@ void BufferView::pasteEnvironment()
 }
 
 
-void BufferView::copy()
-{
-       if (available()) {
-               getLyXText()->copySelection(this);
-               owner()->message(_("Copy"));
-       }
-}
-
-
-void BufferView::cut(bool realcut)
-{
-       if (available()) {
-               hideCursor();
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->cutSelection(this, true, realcut);
-               update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               owner()->message(_("Cut"));
-       }
-}
-
-
-void BufferView::paste()
-{
-       if (!available())
-               return;
-
-       owner()->message(_("Paste"));
-
-       hideCursor();
-       // clear the selection
-       toggleSelection();
-       text->clearSelection();
-       update(text, BufferView::SELECT|BufferView::FITCUR);
-
-       // paste
-       text->pasteSelection(this);
-       update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-// why fake a selection only I think it should be a real one and not only
-// a painted one (Jug 20020318).
-#if 0
-       // clear the selection
-       toggleSelection();
-       text->clearSelection();
-       update(text, BufferView::SELECT|BufferView::FITCUR);
-#endif
-}
-
-
-/* these functions are for the spellchecker */
-string const BufferView::nextWord(float & value)
+// these functions are for the spellchecker
+WordLangTuple const BufferView::nextWord(float & value)
 {
        if (!available()) {
                value = 1;
-               return string();
+               return WordLangTuple();
        }
 
        return text->selectNextWordToSpellcheck(this, value);
@@ -452,7 +405,8 @@ string const BufferView::nextWord(float & value)
 
 void BufferView::selectLastWord()
 {
-       if (!available()) return;
+       if (!available())
+               return;
 
        LyXCursor cur = text->selection.cursor;
        hideCursor();
@@ -478,17 +432,18 @@ void BufferView::endOfSpellCheck()
 
 void BufferView::replaceWord(string const & replacestring)
 {
-       if (!available()) return;
+       if (!available())
+               return;
 
        LyXText * tt = getLyXText();
        hideCursor();
        update(tt, BufferView::SELECT|BufferView::FITCUR);
 
-       /* clear the selection (if there is any) */
+       // clear the selection (if there is any)
        toggleSelection(false);
        update(tt, BufferView::SELECT|BufferView::FITCUR);
 
-       /* clear the selection (if there is any) */
+       // clear the selection (if there is any)
        toggleSelection(false);
        tt->replaceSelectionWithString(this, replacestring);
 
@@ -522,26 +477,24 @@ bool BufferView::lockInset(UpdatableInset * inset)
                        }
                }
                // Then do a deep look of the inset and lock the right one
-               Paragraph * par = buffer()->paragraph;
                int const id = inset->id();
-               while(par) {
-                       Paragraph::inset_iterator it =
-                               par->inset_iterator_begin();
-                       Paragraph::inset_iterator const end =
-                               par->inset_iterator_end();
+               ParagraphList::iterator pit = buffer()->paragraphs.begin();
+               ParagraphList::iterator pend = buffer()->paragraphs.end();
+               for (; pit != pend; ++pit) {
+                       InsetList::iterator it = pit->insetlist.begin();
+                       InsetList::iterator end = pit->insetlist.end();
                        for (; it != end; ++it) {
-                               if ((*it) == inset) {
-                                       text->setCursorIntern(this, par, it.getPos());
+                               if (it.getInset() == inset) {
+                                       text->setCursorIntern(this, &*pit, it.getPos());
                                        theLockingInset(inset);
                                        return true;
                                }
-                               if ((*it)->getInsetFromID(id)) {
-                                       text->setCursorIntern(this, par, it.getPos());
-                                       (*it)->edit(this);
+                               if (it.getInset()->getInsetFromID(id)) {
+                                       text->setCursorIntern(this, &*pit, it.getPos());
+                                       it.getInset()->edit(this);
                                        return theLockingInset()->lockInsetInInset(this, inset);
                                }
                        }
-                       par = par->next();
                }
                return false;
        }
@@ -572,8 +525,8 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
                        shape = (txt->real_current_font.isVisibleRightToLeft())
                                ? LyXScreen::REVERSED_L_SHAPE
                                : LyXScreen::L_SHAPE;
-               y += cursor.y() + theLockingInset()->insetInInsetY();
-               pimpl_->screen_->showManualCursor(text, x, y, asc, desc,
+               y += cursor.iy() + theLockingInset()->insetInInsetY();
+               screen().showManualCursor(text, x, y, asc, desc,
                                                  shape);
        }
 }
@@ -582,7 +535,7 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
 void BufferView::hideLockedInsetCursor()
 {
        if (theLockingInset() && available()) {
-               pimpl_->screen_->hideCursor();
+               screen().hideCursor();
        }
 }
 
@@ -590,8 +543,8 @@ void BufferView::hideLockedInsetCursor()
 bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 {
        if (theLockingInset() && available()) {
-               y += text->cursor.y() + theLockingInset()->insetInInsetY();
-               if (pimpl_->screen_->fitManualCursor(text, this, x, y, asc, desc)) {
+               y += text->cursor.iy() + theLockingInset()->insetInInsetY();
+               if (screen().fitManualCursor(this, text, x, y, asc, desc)) {
                        updateScrollbar();
                        return true;
                }
@@ -608,11 +561,15 @@ int BufferView::unlockInset(UpdatableInset * inset)
                inset->insetUnlock(this);
                theLockingInset(0);
                // make sure we update the combo !
-               owner()->setLayout(getLyXText()->cursor.par()->layout());
+               owner()->setLayout(getLyXText()->cursor.par()->layout()->name());
+               // Tell the paragraph dialog that we changed paragraph
+               owner()->getDialogs().updateParagraph();
                finishUndo();
                return 0;
        } else if (inset && theLockingInset() &&
                   theLockingInset()->unlockInsetInInset(this, inset)) {
+               // Tell the paragraph dialog that we changed paragraph
+               owner()->getDialogs().updateParagraph();
                // owner inset has updated the layout combo
                finishUndo();
                return 0;
@@ -653,10 +610,10 @@ bool BufferView::ChangeInsets(Inset::Code code,
             it != end; ++it) {
                Paragraph * par = *it;
                bool changed_inset = false;
-               for (Paragraph::inset_iterator it2 = par->inset_iterator_begin();
-                    it2 != par->inset_iterator_end(); ++it2) {
-                       if ((*it2)->lyxCode() == code) {
-                               InsetCommand * inset = static_cast<InsetCommand *>(*it2);
+               for (InsetList::iterator it2 = par->insetlist.begin();
+                    it2 != par->insetlist.end(); ++it2) {
+                       if (it2.getInset()->lyxCode() == code) {
+                               InsetCommand * inset = static_cast<InsetCommand *>(it2.getInset());
                                if (inset->getContents() == from) {
                                        inset->setContents(to);
                                        changed_inset = true;