]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
fix compilation bug
[lyx.git] / src / BufferView_pimpl.C
index 5b20865439a6eaa348142c15a0248a0407b5de01..34b5a478e357034a93c92d4a0ff62c214eb557a7 100644 (file)
@@ -8,10 +8,6 @@
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "BufferView_pimpl.h"
 #include "frontends/WorkArea.h"
 #include "frontends/screen.h"
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
 #include "funcrequest.h"
+#include "iterators.h"
+#include "lyxfind.h"
 
 #include "insets/insetbib.h"
 #include "insets/insettext.h"
-#include "insets/inseturl.h"
 #include "insets/insetlatexaccent.h"
 #include "insets/insettoc.h"
 #include "insets/insetindex.h"
@@ -65,6 +62,7 @@
 
 #include <boost/bind.hpp>
 #include <boost/signals/connection.hpp>
+#include "BoostFormat.h"
 
 #include <unistd.h>
 #include <sys/wait.h>
@@ -154,7 +152,7 @@ Painter & BufferView::Pimpl::painter() const
 void BufferView::Pimpl::buffer(Buffer * b)
 {
        lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
-                           << b << ")" << endl;
+                           << b << ')' << endl;
        if (buffer_) {
                buffer_->delUser(bv_);
 
@@ -172,7 +170,9 @@ void BufferView::Pimpl::buffer(Buffer * b)
        // set current buffer
        buffer_ = b;
 
-       if (bufferlist.getState() == BufferList::CLOSING) return;
+       // if we're quitting lyx, don't bother updating stuff 
+       if (quitting)
+               return; 
 
        // if we are closing the buffer, use the first buffer as current
        if (!buffer_) {
@@ -265,8 +265,8 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        bool selection = false;
        bool mark_set  = false;
 
-       owner_->prohibitInput();
-
+       owner_->busy(true);
        owner_->message(_("Formatting document..."));
 
        if (bv_->text) {
@@ -298,6 +298,8 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                        //      bv_->text->owner(bv_);
                        if (lyxerr.debugging())
                                textcache.show(lyxerr, "resizeCurrentBuffer");
+
+                       buffer_->resizeInsets(bv_);
                } else {
                        bv_->text = new LyXText(bv_);
                        bv_->text->init(bv_);
@@ -328,7 +330,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
 
        switchKeyMap();
-       owner_->allowInput();
+       owner_->busy(false);
 
        updateScrollbar();
 
@@ -354,9 +356,9 @@ void BufferView::Pimpl::updateScrollbar()
        LyXText const & t = *bv_->text;
 
        lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
-               << t.first_y << ", default height " << t.defaultHeight() << endl;
+               << t.first_y << ", default height " << defaultRowHeight() << endl;
 
-       workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
+       workarea().setScrollbarParams(t.height, t.first_y, defaultRowHeight());
 }
 
 
@@ -364,17 +366,17 @@ void BufferView::Pimpl::scrollDocView(int value)
 {
        lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
 
-       if (!buffer_) return;
+       if (!buffer_)
+               return;
 
        screen().draw(bv_->text, bv_, value);
 
-       if (!lyxrc.cursor_follows_scrollbar) {
+       if (!lyxrc.cursor_follows_scrollbar)
                return;
-       }
 
        LyXText * vbt = bv_->text;
 
-       int const height = vbt->defaultHeight();
+       int const height = defaultRowHeight();
        int const first = static_cast<int>((bv_->text->first_y + height));
        int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
 
@@ -385,19 +387,26 @@ void BufferView::Pimpl::scrollDocView(int value)
 }
 
 
-int BufferView::Pimpl::scroll(long time)
+void BufferView::Pimpl::scroll(int lines)
 {
-       if (!buffer_)
-               return 0;
+       if (!buffer_) {
+               return;
+       }
 
        LyXText const * t = bv_->text;
+       int const line_height = defaultRowHeight();
 
-       double const diff = t->defaultHeight()
-               + double(time) * double(time) * 0.125;
+       // The new absolute coordinate
+       int new_first_y = t->first_y + lines * line_height;
 
-       scrollDocView(int(diff));
-       workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
-       return 0;
+       // Restrict to a valid value
+       new_first_y = std::min(t->height - 4 * line_height, new_first_y);
+       new_first_y = std::max(0, new_first_y);
+
+       scrollDocView(new_first_y);
+
+       // Update the scrollbar.
+       workarea().setScrollbarParams(t->height, t->first_y, defaultRowHeight());
 }
 
 
@@ -597,10 +606,6 @@ void BufferView::Pimpl::cursorToggle()
                return;
        }
 
-       /* FIXME */
-       extern void reapSpellchecker(void);
-       reapSpellchecker();
-
        if (!bv_->theLockingInset()) {
                screen().cursorToggle(bv_);
        } else {
@@ -619,6 +624,21 @@ bool BufferView::Pimpl::available() const
 }
 
 
+Change const BufferView::Pimpl::getCurrentChange()
+{
+       if (!bv_->buffer()->params.tracking_changes) 
+               return Change(Change::UNCHANGED);
+
+       LyXText * t(bv_->getLyXText());
+       if (!t->selection.set())
+               return Change(Change::UNCHANGED);
+       LyXCursor const & cur(t->selection.start);
+       return cur.par()->lookupChangeFull(cur.pos());
+}
+
+
 void BufferView::Pimpl::beforeChange(LyXText * text)
 {
        toggleSelection();
@@ -635,8 +655,12 @@ void BufferView::Pimpl::savePosition(unsigned int i)
                                      bv_->text->cursor.pos());
        if (i > 0) {
                ostringstream str;
-               str << _("Saved bookmark") << ' ' << i;
-               owner_->message(str.str().c_str());
+#if USE_BOOST_FORMAT
+               str << boost::format(_("Saved bookmark %1$d")) % i;
+#else
+               str << _("Saved bookmark ") << i;
+#endif
+               owner_->message(STRCONV(str.str()));
        }
 }
 
@@ -667,8 +691,12 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
        if (i > 0) {
                ostringstream str;
-               str << _("Moved to bookmark") << ' ' << i;
-               owner_->message(str.str().c_str());
+#if USE_BOOST_FORMAT
+               str << boost::format(_("Moved to bookmark %1$d")) % i;
+#else
+               str << _("Moved to bookmark ") << i;
+#endif
+               owner_->message(STRCONV(str.str()));
        }
 }
 
@@ -853,7 +881,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
                                  string(AddPath(system_lyxdir, "examples"))));
 
                FileDialog::Result result =
-                       fileDlg.Select(initpath,
+                       fileDlg.open(initpath,
                                       _("*.lyx| LyX Documents (*.lyx)"));
 
                if (result.first == FileDialog::Later)
@@ -875,34 +903,84 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
        string const disp_fn(MakeDisplayPath(filename));
 
        ostringstream s1;
-       s1 << _("Inserting document") << ' '
-          << disp_fn << " ...";
-       owner_->message(s1.str().c_str());
+#if USE_BOOST_FORMAT
+       s1 << boost::format(_("Inserting document %1$s...")) % disp_fn;
+#else
+       s1 << _("Inserting document ") << disp_fn << _("...");
+#endif
+       owner_->message(STRCONV(s1.str()));
        bool const res = bv_->insertLyXFile(filename);
        if (res) {
                ostringstream str;
-               str << _("Document") << ' ' << disp_fn
-                   << ' ' << _("inserted.");
-               owner_->message(str.str().c_str());
+#if USE_BOOST_FORMAT
+               str << boost::format(_("Document %1$s inserted.")) % disp_fn;
+#else
+               str << _("Document ") << disp_fn << _(" inserted.");
+#endif
+               owner_->message(STRCONV(str.str()));
        } else {
                ostringstream str;
-               str << _("Could not insert document") << ' '
-                   << disp_fn;
-               owner_->message(str.str().c_str());
+#if USE_BOOST_FORMAT
+               str << boost::format(_("Could not insert document %1$s")) % disp_fn;
+#else
+               str << _("Could not insert document ") << disp_fn;
+#endif
+               owner_->message(STRCONV(str.str()));
        }
 }
 
 
+void BufferView::Pimpl::trackChanges()
+{
+       Buffer * buf(bv_->buffer());
+       bool const tracking(buf->params.tracking_changes);
+
+       if (!tracking) {
+               ParIterator const end = buf->par_iterator_end();
+               for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
+                       (*it)->trackChanges();
+               }
+               buf->params.tracking_changes = true;
+
+               // we cannot allow undos beyond the freeze point
+               buf->undostack.clear();
+       } else {
+               bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
+               bv_->text->setCursor(bv_, &(*buf->paragraphs.begin()), 0);
+#warning changes FIXME 
+               //moveCursorUpdate(false);
+
+               bool found = lyxfind::findNextChange(bv_);
+               if (found) {
+                       owner_->getDialogs().showMergeChanges();
+                       return;
+               }
+
+               ParIterator const end = buf->par_iterator_end();
+               for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
+                       (*it)->untrackChanges();
+               }
+               buf->params.tracking_changes = false;
+       }
+       buf->redostack.clear();
+}
+
+
 bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
 {
        lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
-               << " action[" << ev.action <<"]"
-               << " arg[" << ev.argument << "]"
-               << " x[" << ev.x << "]"
-               << " y[" << ev.y << "]"
-               << " button[" << ev.button() << "]"
+               << " action[" << ev.action << ']'
+               << " arg[" << ev.argument << ']'
+               << " x[" << ev.x << ']'
+               << " y[" << ev.y << ']'
+               << " button[" << ev.button() << ']'
                << endl;
 
+       // e.g. Qt mouse press when no buffer
+       if (!buffer_)
+               return false;
+
        LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
 
        switch (ev.action) {
@@ -1064,32 +1142,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        }
        break;
 
-       case LFUN_HTMLURL:
-       case LFUN_URL:
-       {
-               InsetCommandParams p;
-               if (ev.action == LFUN_HTMLURL)
-                       p.setCmdName("htmlurl");
-               else
-                       p.setCmdName("url");
-               owner_->getDialogs().createUrl(p.getAsString());
-       }
-       break;
-
-       case LFUN_INSERT_URL:
-       {
-               InsetCommandParams p;
-               p.setFromString(ev.argument);
-
-               InsetUrl * inset = new InsetUrl(p);
-               if (!insertInset(inset))
-                       delete inset;
-               else
-                       updateInset(inset, true);
-       }
-       break;
-
-
        // --- accented characters ---------------------------
 
        case LFUN_UMLAUT:
@@ -1142,8 +1194,11 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                InsetCitation * inset = new InsetCitation(p);
                if (!insertInset(inset))
                        delete inset;
-               else
+               else {
+                       inset->setLoadingBuffer(bv_->buffer(), false);
                        updateInset(inset, true);
+               }
+
        }
        break;
 
@@ -1192,7 +1247,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        {
                InsetBibtex * inset =
                        static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
-               if (inset) 
+               if (inset)
                        inset->setOptions(ev.argument);
        }
        break;
@@ -1200,7 +1255,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        case LFUN_CHILD_INSERT:
        {
                InsetInclude::Params p;
-               p.cparams.setFromString(ev.argument);
+               if (!ev.argument.empty())
+                       p.cparams.setFromString(ev.argument);
                p.masterFilename_ = buffer_->fileName();
 
                InsetInclude * inset = new InsetInclude(p);
@@ -1245,6 +1301,56 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        }
                break;
 
+       case LFUN_TRACK_CHANGES:
+               trackChanges();
+               break;
+       case LFUN_MERGE_CHANGES:
+               owner_->getDialogs().showMergeChanges();
+               break;
+       case LFUN_ACCEPT_ALL_CHANGES: {
+               bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
+               bv_->text->setCursor(bv_, &(*bv_->buffer()->paragraphs.begin()), 0);
+#warning FIXME changes 
+               //moveCursorUpdate(false);
+
+               while (lyxfind::findNextChange(bv_)) {
+                       bv_->getLyXText()->acceptChange(bv_);
+               }
+               update(bv_->text,
+                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+               break;
+       }
+       case LFUN_REJECT_ALL_CHANGES: {
+               bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
+               bv_->text->setCursor(bv_, &(*bv_->buffer()->paragraphs.begin()), 0);
+#warning FIXME changes 
+               //moveCursorUpdate(false);
+
+               while (lyxfind::findNextChange(bv_)) {
+                       bv_->getLyXText()->rejectChange(bv_);
+               }
+               update(bv_->text,
+                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+               break;
+       }
+       case LFUN_ACCEPT_CHANGE: {
+               bv_->getLyXText()->acceptChange(bv_);
+               update(bv_->text,
+                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+               break;
+       }
+
+       case LFUN_REJECT_CHANGE: {
+               bv_->getLyXText()->rejectChange(bv_);
+               update(bv_->text,
+                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+               break;
+       }
        case LFUN_UNKNOWN_ACTION:
                ev.errorMessage(N_("Unknown function!"));
                break;
@@ -1263,7 +1369,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
        // inset there otherwise this is a illegal function now
        if (bv_->theLockingInset()) {
                if (bv_->theLockingInset()->insetAllowed(inset))
-                   return bv_->theLockingInset()->insertInset(bv_, inset);
+                       return bv_->theLockingInset()->insertInset(bv_, inset);
                return false;
        }