]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Compile fix.
[lyx.git] / src / BufferView.cpp
index 1eae3b3a3ff9a4094e74762edb751359d039195c..338a55aa5c3f9a1ce7e7fdeba159fec447ab9e83 100644 (file)
@@ -58,9 +58,9 @@
 #include "insets/InsetCommand.h" // ChangeRefs
 #include "insets/InsetExternal.h"
 #include "insets/InsetGraphics.h"
+#include "insets/InsetNote.h"
 #include "insets/InsetRef.h"
 #include "insets/InsetText.h"
-#include "insets/InsetNote.h"
 
 #include "frontends/alert.h"
 #include "frontends/Application.h"
@@ -220,7 +220,8 @@ struct BufferView::Private
        Private(BufferView & bv): wh_(0), cursor_(bv),
                anchor_pit_(0), anchor_ypos_(0),
                inlineCompletionUniqueChars_(0),
-               last_inset_(0), mouse_position_cache_(),
+               last_inset_(0), clickable_inset_(false), 
+               mouse_position_cache_(),
                bookmark_edit_position_(-1), gui_(0)
        {}
 
@@ -263,6 +264,8 @@ struct BufferView::Private
          * Not owned, so don't delete.
          */
        Inset * last_inset_;
+       /// are we hovering something that we can click
+       bool clickable_inset_;
 
        /// position of the mouse at the time of the last mouse move
        /// This is used to update the hovering status of inset in
@@ -1027,7 +1030,6 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_FONT_STATE:
        case LFUN_LABEL_INSERT:
-       case LFUN_LINE_INSERT:
        case LFUN_INFO_INSERT:
        case LFUN_PARAGRAPH_GOTO:
        case LFUN_NOTE_NEXT:
@@ -1208,7 +1210,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                // We are most certainly here because of a change in the document
                // It is then better to make sure that all dialogs are in sync with
                // current document settings.
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force | Update::FitCursor);
                dr.forceBufferUpdate();
                break;
        }
@@ -1220,7 +1222,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().clearLayoutModules();
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
                break;
        }
@@ -1238,7 +1240,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().addLayoutModule(argument);
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
                break;
        }
@@ -1270,7 +1272,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().setBaseClass(argument);
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldDocClass);
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
                break;
        }
@@ -1296,7 +1298,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().setBaseClass(bc);
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
                break;
        }
@@ -1307,7 +1309,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                if (!cur.textUndo())
                        dr.setMessage(_("No further undo information"));
                else
-                       dr.update(Update::Force | Update::FitCursor);
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                dr.forceBufferUpdate();
                break;
 
@@ -1317,7 +1319,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                if (!cur.textRedo())
                        dr.setMessage(_("No further redo information"));
                else
-                       dr.update(Update::Force | Update::FitCursor);
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                dr.forceBufferUpdate();
                break;
 
@@ -1340,8 +1342,13 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                saveBookmark(0);
                        }
                }
-               if (!label.empty())
+               if (!label.empty()) {
                        gotoLabel(label);
+                       // at the moment, this is redundant, since gotoLabel will
+                       // eventually call LFUN_PARAGRAPH_GOTO, but it seems best
+                       // to have it here.
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
+               }
                break;
        }
        
@@ -1366,7 +1373,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                // Set the cursor
                                dit.pos() = pos;
                                setCursor(dit);
-                               dr.update(Update::Force | Update::FitCursor);
+                               dr.screenUpdate(Update::Force | Update::FitCursor);
                        } else {
                                // Switch to other buffer view and resend cmd
                                lyx::dispatch(FuncRequest(
@@ -1420,18 +1427,18 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        case LFUN_CHANGE_NEXT:
                findNextChange(this);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force | Update::FitCursor);
                break;
        
        case LFUN_CHANGE_PREVIOUS:
                findPreviousChange(this);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_CHANGES_MERGE:
                if (findNextChange(this) || findPreviousChange(this)) {
-                       dr.update(Update::Force | Update::FitCursor);
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                        dr.forceBufferUpdate();
                        showDialog("changes");
                }
@@ -1445,7 +1452,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                // accept everything in a single step to support atomic undo
                buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force | Update::FitCursor);
                dr.forceBufferUpdate();
                break;
 
@@ -1458,7 +1465,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                // Note: reject does not work recursively; the user may have to repeat the operation
                buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force | Update::FitCursor);
                dr.forceBufferUpdate();
                break;
 
@@ -1480,7 +1487,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                bool const fw = act == LFUN_WORD_FIND_FORWARD;
                docstring const data =
                        find2string(searched_string, true, false, fw);
-               find(this, FuncRequest(LFUN_WORD_FIND, data));
+               bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
+               if (found)
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1492,8 +1501,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
                        break;
                }
-               if (find(this, req))
-                       showCursor();
+               if (lyxfind(this, req))
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                else
                        message(_("String not found!"));
                d->search_request_cache_ = req;
@@ -1507,14 +1516,17 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        DocIterator end = cur.selectionEnd();
                        if (beg.pit() == end.pit()) {
                                for (pos_type p = beg.pos() ; p < end.pos() ; ++p) {
-                                       if (!cur.inMathed()
-                                           && cur.paragraph().isDeleted(p))
+                                       if (!cur.inMathed() && cur.paragraph().isDeleted(p)) {
                                                has_deleted = true;
+                                               break;
+                                       }
                                }
                        }
                }
-               replace(this, cmd, has_deleted);
-               dr.forceBufferUpdate();
+               if (lyxreplace(this, cmd, has_deleted)) {
+                       dr.forceBufferUpdate();
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
+               }
                break;
        }
 
@@ -1523,9 +1535,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                istringstream iss(to_utf8(cmd.argument()));
                iss >> opt;
                if (findAdv(this, opt))
-                       cur.dispatched();
-               else
-                       cur.undispatched();
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1664,7 +1674,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                bool update = in_texted && cur.bv().checkDepm(cur, old);
                cur.finishUndo();
                if (update) {
-                       dr.update(Update::Force | Update::FitCursor);
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                        dr.forceBufferUpdate();
                }
                break;
@@ -1688,7 +1698,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        y = getPos(cur).y_;
 
                cur.finishUndo();
-               dr.update(Update::SinglePar | Update::FitCursor);
+               dr.screenUpdate(Update::SinglePar | Update::FitCursor);
                break;
        }
 
@@ -1705,7 +1715,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        y = getPos(cur).y_;
 
                cur.finishUndo();
-               dr.update(Update::SinglePar | Update::FitCursor);
+               dr.screenUpdate(Update::SinglePar | Update::FitCursor);
                break;
        }
 
@@ -1748,7 +1758,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                cur.endUndoGroup();
                cur = savecur;
                cur.fixIfBroken();
-               dr.update(Update::Force);
+               dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
 
                if (iterations >= max_iter) {
@@ -1851,8 +1861,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                cur.recordUndo();
                FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
                inset->dispatch(cur, fr);
-               dr.update(Update::SinglePar | Update::FitCursor);
-               dr.forceBufferUpdate();
+               dr.screenUpdate(cur.result().screenUpdate());
+               if (cur.result().needBufferUpdate())
+                       dr.forceBufferUpdate();
                break;
        }
 
@@ -1951,8 +1962,12 @@ Inset const * BufferView::getCoveringInset(Text const & text,
 void BufferView::updateHoveredInset() const
 {
        // Get inset under mouse, if there is one.
-       Inset const * covering_inset = getCoveringInset(buffer_.text(),
-                       d->mouse_position_cache_.x_, d->mouse_position_cache_.y_);
+       int const x = d->mouse_position_cache_.x_;
+       int const y = d->mouse_position_cache_.y_;
+       Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+
+       d->clickable_inset_ = covering_inset && covering_inset->clickable(x, y);
+
        if (covering_inset == d->last_inset_)
                // Same inset, no need to do anything...
                return;
@@ -2059,8 +2074,8 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
        theSelection().haveSelection(cursor().selection());
 
        // If the command has been dispatched,
-       if (cur.result().dispatched() || cur.result().update())
-               processUpdateFlags(cur.result().update());
+       if (cur.result().dispatched() || cur.result().screenUpdate())
+               processUpdateFlags(cur.result().screenUpdate());
 }
 
 
@@ -2191,8 +2206,8 @@ bool BufferView::setCursorFromInset(Inset const * inset)
 
 void BufferView::gotoLabel(docstring const & label)
 {
-       std::vector<Buffer const *> bufs = buffer().allRelatives();
-       std::vector<Buffer const *>::iterator it = bufs.begin();
+       ListOfBuffers bufs = buffer().allRelatives();
+       ListOfBuffers::iterator it = bufs.begin();
        for (; it != bufs.end(); ++it) {
                Buffer const * buf = *it;
 
@@ -2334,9 +2349,6 @@ void BufferView::putSelectionAt(DocIterator const & cur,
                } else
                        d->cursor_.setSelection(d->cursor_, length);
        }
-       // Ensure a redraw happens in any case because the new selection could 
-       // possibly be on the same screen as the previous selection.
-       processUpdateFlags(Update::Force | Update::FitCursor);
 }
 
 
@@ -2495,7 +2507,7 @@ void BufferView::insertLyXFile(FileName const & fname)
 
        docstring res;
        Buffer buf("", false);
-       if (buf.loadLyXFile(filename)) {
+       if (buf.loadLyXFile(filename) == Buffer::ReadSuccess) {
                ErrorList & el = buffer_.errorList("Parse");
                // Copy the inserted document error list into the current buffer one.
                el = buf.errorList("Parse");
@@ -2876,11 +2888,17 @@ void BufferView::setInlineCompletion(Cursor & cur, DocIterator const & pos,
        
        // set update flags
        if (changed) {
-               if (singlePar && !(cur.result().update() & Update::Force))
-                       cur.screenUpdateFlags(cur.result().update() | Update::SinglePar);
+               if (singlePar && !(cur.result().screenUpdate() & Update::Force))
+                       cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
                else
-                       cur.screenUpdateFlags(cur.result().update() | Update::Force);
+                       cur.screenUpdateFlags(cur.result().screenUpdate() | Update::Force);
        }
 }
 
+
+bool BufferView::clickableInset() const
+{ 
+       return d->clickable_inset_; 
+}
+
 } // namespace lyx