#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 "LyX.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>
: 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();
-
- // current buffer is going to be switched-off, save cursor pos
- // Ideally, the whole cursor stack should be saved, but session
- // currently can only handle bottom (whole document) level pit and pos.
- // That is to say, if a cursor is in a nested inset, it will be
- // restore to the left of the top level inset.
- Cursor & cur = buffer_view_->cursor();
- LyX::ref().session().lastFilePos().save(
- support::FileName(buffer_view_->buffer()->fileName()),
- boost::tie(cur.bottom().pit(), cur.bottom().pos()) );
-
+ buffer_view_->buffer().workAreaManager().remove(this);
delete buffer_view_;
}
}
-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) {
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;
&& 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) {
lyx_view_->updateLayoutChoice();
- lyx_view_->updateMenubar();
lyx_view_->updateToolbars();
}
void WorkArea::resizeBufferView()
{
- lyx_view_->busy(true);
- lyx_view_->message(_("Formatting document..."));
- buffer_view_->workAreaResize(width(), height());
+ // WARNING: Please don't put any code that will trigger a repaint here!
+ // We are already inside a paint event.
+ lyx_view_->setBusy(true);
+ buffer_view_->resize(width(), height());
lyx_view_->updateLayoutChoice();
- lyx_view_->clearMessage();
- lyx_view_->busy(false);
+ lyx_view_->setBusy(false);
}
}
-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_)
CursorShape shape = BAR_SHAPE;
- Text const & text = *buffer_view_->cursor().innerText();
- Font const & realfont = text.real_current_font;
- BufferParams const & bp = buffer_view_->buffer()->params();
+ 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();