]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/WorkArea.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[lyx.git] / src / frontends / WorkArea.C
index 0d65d628cc83f476bd9b2893ffc40d3bfb8da62d..c1a89e18a9cb699702f9658e28e9a52ac646befc 100644 (file)
 #include "rowpainter.h"
 
 #include "gettext.h"
-#include "support/filetools.h" // LibFileSearch
 #include "support/forkedcontr.h"
 
 #include <boost/utility.hpp>
 #include <boost/bind.hpp>
 #include <boost/current_function.hpp>
 
-using lyx::support::libFileSearch;
 using lyx::support::ForkedcallsController;
 
 using std::endl;
@@ -94,8 +92,6 @@ void WorkArea::setBufferView(BufferView * buffer_view)
                lyx_view_.disconnectBufferView();
        }
 
-       theApp->setBufferView(buffer_view);
-
        hideCursor();
        buffer_view_ = buffer_view;
        toggleCursor();
@@ -122,46 +118,45 @@ BufferView const & WorkArea::bufferView() const
 void WorkArea::stopBlinkingCursor()
 {
        cursor_timeout_.stop();
+       hideCursor();
 }
 
 
 void WorkArea::startBlinkingCursor()
 {
+       showCursor();
        cursor_timeout_.restart();
 }
 
 
-void WorkArea::checkAndGreyOut()
+void WorkArea::redraw()
 {
-       if (greyed_out_)
-               greyOut();
-}
-
-
-void WorkArea::redraw(bool singlePar)
-{
-       if (!buffer_view_)
-               return;
-
-       if (!buffer_view_->buffer()) {
-               checkAndGreyOut();
+       if (!buffer_view_ || !buffer_view_->buffer()) {
+               greyed_out_ = true;
+               // The argument here are meaningless.
+               expose(1,1,1,1);
                return;
        }
 
-       buffer_view_->updateMetrics(singlePar && hasFocus());
+       // No need to do anything if this is the current view. The BufferView 
+       // metrics are already up to date.
+       if (&lyx_view_ != theApp()->currentView())
+               // FIXME: it would be nice to optimize for the off-screen case.
+               buffer_view_->updateMetrics(false);
 
        updateScrollbar();
 
        ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
        greyed_out_ = false;
 
-       lyxerr[Debug::WORKAREA] << "WorkArea::redraw screen" << endl;
+       LYXERR(Debug::WORKAREA) << "WorkArea::redraw screen" << endl;
+
        int const ymin = std::max(vi.y1, 0);
        int const ymax = vi.p2 < vi.size - 1 ? vi.y2 : height();
 
        expose(0, ymin, width(), ymax - ymin);
 
-       //lyxerr[Debug::WORKAREA]
+       //LYXERR(Debug::WORKAREA)
        //<< "  ymin = " << ymin << "  width() = " << width()
 //             << "  ymax-ymin = " << ymax-ymin << std::endl;
 
@@ -170,27 +165,23 @@ void WorkArea::redraw(bool singlePar)
 }
 
 
-void WorkArea::processKeySym(LyXKeySymPtr key,
-                                                        key_modifier::state state)
+void WorkArea::processKeySym(LyXKeySymPtr key, key_modifier::state state)
 {
-       hideCursor();
+       // In order to avoid bad surprise in the middle of an operation, we better stop
+       // the blinking cursor.
+       stopBlinkingCursor();
 
        theLyXFunc().setLyXView(&lyx_view_);
        theLyXFunc().processKeySym(key, state);
 
-       /* This is perhaps a bit of a hack. When we move
-        * around, or type, it's nice to be able to see
-        * the cursor immediately after the keypress. So
-        * we reset the toggle timeout and force the visibility
-        * of the cursor. Note we cannot do this inside
-        * dispatch() itself, because that's called recursively.
+       /* When we move around, or type, it's nice to be able to see
+        * the cursor immediately after the keypress.
         */
-//     if (buffer_view_->buffer())
-       toggleCursor();
+       startBlinkingCursor();
 }
 
 
-void WorkArea::dispatch(FuncRequest const & cmd0)
+void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k)
 {
        // Handle drag&drop
        if (cmd0.action == LFUN_FILE_OPEN) {
@@ -200,21 +191,48 @@ void WorkArea::dispatch(FuncRequest const & cmd0)
 
        theLyXFunc().setLyXView(&lyx_view_);
 
-       buffer_view_->workAreaDispatch(cmd0);
+       FuncRequest cmd;
+
+       if (cmd0.action == LFUN_MOUSE_PRESS) {
+               if (k == key_modifier::shift)
+                       cmd = FuncRequest(cmd0, "region-select");
+               else if (k == key_modifier::ctrl)
+                       cmd = FuncRequest(cmd0, "paragraph-select");
+               else
+                       cmd = cmd0;
+       }
+       else
+               cmd = cmd0;
+
+       // In order to avoid bad surprise in the middle of an operation, we better stop
+       // the blinking cursor.
+       if (!(cmd.action == LFUN_MOUSE_MOTION 
+               && cmd.button() == mouse_button::none))
+               stopBlinkingCursor();
+
+       bool const needRedraw = buffer_view_->workAreaDispatch(cmd);
 
+       if (needRedraw)
+               redraw();
+       
        // Skip these when selecting
-       if (cmd0.action != LFUN_MOUSE_MOTION) {
+       if (cmd.action != LFUN_MOUSE_MOTION) {
                lyx_view_.updateLayoutChoice();
                lyx_view_.updateMenubar();
                lyx_view_.updateToolbars();
        }
 
-       // Slight hack: this is only called currently when we
-       // clicked somewhere, so we force through the display
-       // of the new status here.
-       lyx_view_.clearMessage();
+       // GUI tweaks except with mouse motion with no button pressed.
+       if (!(cmd.action == LFUN_MOUSE_MOTION 
+               && cmd.button() == mouse_button::none)) {
+               // Slight hack: this is only called currently when we
+               // clicked somewhere, so we force through the display
+               // of the new status here.
+               lyx_view_.clearMessage();
 
-       redraw();
+               // Show the cursor immediately after any operation.
+               startBlinkingCursor();
+       }
 }
 
 
@@ -224,9 +242,8 @@ void WorkArea::resizeBufferView()
        lyx_view_.message(_("Formatting document..."));
        buffer_view_->workAreaResize(width(), height());
        lyx_view_.updateLayoutChoice();
-       redraw();
-       lyx_view_.busy(false);
        lyx_view_.clearMessage();
+       lyx_view_.busy(false);
 }
 
 
@@ -241,21 +258,15 @@ void WorkArea::updateScrollbar()
 
 void WorkArea::scrollBufferView(int position)
 {
+       stopBlinkingCursor();
        buffer_view_->scrollDocView(position);
        redraw();
-       hideCursor();
        if (lyxrc.cursor_follows_scrollbar) {
                buffer_view_->setCursorFromScrollbar();
                lyx_view_.updateLayoutChoice();
        }
-       toggleCursor();
-}
-
-
-void WorkArea::greyOut()
-{
-       greyed_out_ = true;
-       expose(4, 5, 3, 3);
+       // Show the cursor immediately after any operation.
+       startBlinkingCursor();
 }
 
 
@@ -269,7 +280,7 @@ void WorkArea::showCursor()
 
        CursorShape shape = BAR_SHAPE;
 
-       LyXText const & text = *buffer_view_->getLyXText();
+       LyXText const & text = *buffer_view_->cursor().innerText();
        LyXFont const & realfont = text.real_current_font;
        BufferParams const & bp = buffer_view_->buffer()->params();
        bool const samelang = realfont.language() == bp.language;