]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/WorkArea.cpp
Move Color::color enum to ColorCode.h
[lyx.git] / src / frontends / WorkArea.cpp
index 8ae29add12deca170e2210c6fa11fc6a6597dc7e..c3abe443b29ae6c145b40c42b85d71c30769936a 100644 (file)
 #include "frontends/Application.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/LyXView.h"
+#include "frontends/WorkAreaManager.h"
 
 #include "BufferView.h"
 #include "Buffer.h"
 #include "BufferParams.h"
-#include "Color.h"
 #include "CoordCache.h"
 #include "Cursor.h"
 #include "debug.h"
 #include "Font.h"
 #include "FuncRequest.h"
+#include "KeySymbol.h"
 #include "Language.h"
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "MetricsInfo.h"
-#include "Text.h"
 
 #include "gettext.h"
 #include "support/ForkedcallsController.h"
 #include "support/FileName.h"
 
-#include <boost/utility.hpp>
+#include <boost/noncopyable.hpp>
 #include <boost/bind.hpp>
 #include <boost/current_function.hpp>
 
@@ -68,27 +68,18 @@ WorkArea::WorkArea(Buffer & buffer, LyXView & lv)
        : buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
        cursor_visible_(false), cursor_timeout_(400)
 {
+       buffer.workAreaManager().add(this);
        // Setup the signals
        timecon = cursor_timeout_.timeout
                .connect(boost::bind(&WorkArea::toggleCursor, this));
 
-       bufferChangedConnection_ =
-               buffer.changed.connect(
-                       boost::bind(&WorkArea::redraw, this));
-
-       bufferClosingConnection_ =
-               buffer.closing.connect(
-               boost::bind(&WorkArea::close, this));
-
        cursor_timeout_.start();
 }
 
 
 WorkArea::~WorkArea()
 {
-       bufferChangedConnection_.disconnect();
-       bufferClosingConnection_.disconnect();
-
+       buffer_view_->buffer().workAreaManager().remove(this);
        delete buffer_view_;
 }
 
@@ -171,18 +162,18 @@ void WorkArea::redraw()
 }
 
 
-void WorkArea::processKeySym(KeySymbolPtr key, key_modifier::state state)
+void WorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
 {
        // 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);
+       theLyXFunc().processKeySym(key, mod);
 }
 
 
-void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k)
+void WorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
 {
        // Handle drag&drop
        if (cmd0.action == LFUN_FILE_OPEN) {
@@ -195,9 +186,9 @@ void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k)
        FuncRequest cmd;
 
        if (cmd0.action == LFUN_MOUSE_PRESS) {
-               if (k == key_modifier::shift)
+               if (mod == ShiftModifier)
                        cmd = FuncRequest(cmd0, "region-select");
-               else if (k == key_modifier::ctrl)
+               else if (mod == ControlModifier)
                        cmd = FuncRequest(cmd0, "paragraph-select");
                else
                        cmd = cmd0;
@@ -211,10 +202,7 @@ void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k)
                && cmd.button() == mouse_button::none))
                stopBlinkingCursor();
 
-       bool const needRedraw = buffer_view_->workAreaDispatch(cmd);
-
-       if (needRedraw)
-               redraw();
+       buffer_view_->mouseEventDispatch(cmd);
 
        // Skip these when selecting
        if (cmd.action != LFUN_MOUSE_MOTION) {
@@ -240,10 +228,10 @@ void WorkArea::resizeBufferView()
 {
        // WARNING: Please don't put any code that will trigger a repaint here!
        // We are already inside a paint event.
-       lyx_view_->busy(true);
+       lyx_view_->setBusy(true);
        buffer_view_->resize(width(), height());
        lyx_view_->updateLayoutChoice();
-       lyx_view_->busy(false);
+       lyx_view_->setBusy(false);
 }
 
 
@@ -256,20 +244,6 @@ void WorkArea::updateScrollbar()
 }
 
 
-void WorkArea::scrollBufferView(int position)
-{
-       stopBlinkingCursor();
-       buffer_view_->scrollDocView(position);
-       redraw();
-       if (lyxrc.cursor_follows_scrollbar) {
-               buffer_view_->setCursorFromScrollbar();
-               lyx_view_->updateLayoutChoice();
-       }
-       // Show the cursor immediately after any operation.
-       startBlinkingCursor();
-}
-
-
 void WorkArea::showCursor()
 {
        if (cursor_visible_)
@@ -277,8 +251,7 @@ void WorkArea::showCursor()
 
        CursorShape shape = BAR_SHAPE;
 
-       Text const & text = *buffer_view_->cursor().innerText();
-       Font const & realfont = text.real_current_font;
+       Font const & realfont = buffer_view_->cursor().real_current_font;
        BufferParams const & bp = buffer_view_->buffer().params();
        bool const samelang = realfont.language() == bp.language;
        bool const isrtl = realfont.isVisibleRightToLeft();