#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
-
-#include "FuncRequest.h"
-#include "LyXFunc.h"
-#include "Painter.h"
+#include "frontends/LyXView.h"
+#include "frontends/WorkAreaManager.h"
#include "BufferView.h"
#include "Buffer.h"
#include "CoordCache.h"
#include "Cursor.h"
#include "debug.h"
+#include "Font.h"
+#include "FuncRequest.h"
+#include "KeySymbol.h"
#include "Language.h"
-#include "Color.h"
-#include "LyXFont.h"
+#include "LyXFunc.h"
#include "LyXRC.h"
-#include "Row.h"
-#include "LyXText.h"
-#include "LyXView.h"
#include "MetricsInfo.h"
-#include "Paragraph.h"
-#include "rowpainter.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>
namespace lyx {
namespace frontend {
-WorkArea::WorkArea(int id, LyXView & lyx_view)
- : buffer_view_(0), lyx_view_(lyx_view), greyed_out_(true),
- id_(id), cursor_visible_(false), cursor_timeout_(400)
+WorkArea::WorkArea(Buffer & buffer, LyXView & lv)
+ : buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
+ cursor_visible_(false), cursor_timeout_(400)
{
- // Start loading the pixmap as soon as possible
- //if (lyxrc.show_banner) {
- // showBanner();
- //}
-
+ buffer.workAreaManager().add(this);
// Setup the signals
timecon = cursor_timeout_.timeout
.connect(boost::bind(&WorkArea::toggleCursor, this));
}
-void WorkArea::setBufferView(BufferView * buffer_view)
+WorkArea::~WorkArea()
{
- if (buffer_view_) {
- message_connection_.disconnect();
- lyx_view_.disconnectBufferView();
- }
-
- hideCursor();
- buffer_view_ = buffer_view;
- toggleCursor();
+ buffer_view_->buffer().workAreaManager().remove(this);
+ delete buffer_view_;
+}
- message_connection_ = buffer_view_->message.connect(
- boost::bind(&WorkArea::displayMessage, this, _1));
- lyx_view_.connectBufferView(*buffer_view);
+void WorkArea::close()
+{
+ lyx_view_->removeWorkArea(this);
}
+//void WorkArea::setLyXView(LyXView * lyx_view)
+//{
+// lyx_view_ = lyx_view;
+//}
+
BufferView & WorkArea::bufferView()
{
void WorkArea::redraw()
{
- if (!buffer_view_ || !buffer_view_->buffer()) {
- greyed_out_ = true;
- // The argument here are meaningless.
- expose(1,1,1,1);
+ if (!isVisible())
+ // No need to redraw in this case.
return;
- }
- // No need to do anything if this is the current view. The BufferView
+ // No need to do anything if this is the current view. The BufferView
// metrics are already up to date.
- if (&lyx_view_ != theApp()->currentView())
+ if (lyx_view_ != theApp()->currentView()) {
// FIXME: it would be nice to optimize for the off-screen case.
buffer_view_->updateMetrics(false);
+ buffer_view_->cursor().fixIfBroken();
+ }
updateScrollbar();
+ // update cursor position, because otherwise it has to wait until
+ // the blinking interval is over
+ if (cursor_visible_) {
+ hideCursor();
+ showCursor();
+ }
+
ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
- greyed_out_ = false;
LYXERR(Debug::WORKAREA) << "WorkArea::redraw screen" << endl;
}
-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);
-
- /* When we move around, or type, it's nice to be able to see
- * the cursor immediately after the keypress.
- */
- startBlinkingCursor();
+ theLyXFunc().setLyXView(lyx_view_);
+ 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) {
- lyx_view_.dispatch(cmd0);
+ lyx_view_->dispatch(cmd0);
return;
}
- theLyXFunc().setLyXView(&lyx_view_);
+ theLyXFunc().setLyXView(lyx_view_);
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;
// In order to avoid bad surprise in the middle of an operation, we better stop
// the blinking cursor.
- if (!(cmd.action == LFUN_MOUSE_MOTION
+ if (!(cmd.action == LFUN_MOUSE_MOTION
&& cmd.button() == mouse_button::none))
stopBlinkingCursor();
- bool const needRedraw = buffer_view_->workAreaDispatch(cmd);
+ buffer_view_->mouseEventDispatch(cmd);
- if (needRedraw)
- redraw();
-
// Skip these when selecting
if (cmd.action != LFUN_MOUSE_MOTION) {
- lyx_view_.updateLayoutChoice();
- lyx_view_.updateMenubar();
- lyx_view_.updateToolbars();
+ lyx_view_->updateLayoutChoice();
+ lyx_view_->updateToolbars();
}
// GUI tweaks except with mouse motion with no button pressed.
- if (!(cmd.action == LFUN_MOUSE_MOTION
+ 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();
+ lyx_view_->clearMessage();
// Show the cursor immediately after any operation.
startBlinkingCursor();
void WorkArea::resizeBufferView()
{
- lyx_view_.busy(true);
- lyx_view_.message(_("Formatting document..."));
- buffer_view_->workAreaResize(width(), height());
- lyx_view_.updateLayoutChoice();
- lyx_view_.clearMessage();
- lyx_view_.busy(false);
+ // 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_->setBusy(false);
}
void WorkArea::updateScrollbar()
{
- buffer_view_->updateScrollbar();
+ buffer_view_->updateScrollbar();
ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
setScrollbarParams(scroll_.height, scroll_.position,
scroll_.lineScrollHeight);
}
-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_)
return;
- if (!buffer_view_->buffer())
- return;
-
CursorShape shape = BAR_SHAPE;
- LyXText const & text = *buffer_view_->cursor().innerText();
- LyXFont 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();
if (realfont.language() == latex_language)
shape = BAR_SHAPE;
- LyXFont const font = buffer_view_->cursor().getFont();
+ Font const font = buffer_view_->cursor().getFont();
FontMetrics const & fm = theFontMetrics(font);
int const asc = fm.maxAscent();
int const des = fm.maxDescent();
void WorkArea::toggleCursor()
{
- if (buffer_view_->buffer()) {
-
- if (cursor_visible_)
- hideCursor();
- else
- showCursor();
+ if (cursor_visible_)
+ hideCursor();
+ else
+ showCursor();
- // Use this opportunity to deal with any child processes that
- // have finished but are waiting to communicate this fact
- // to the rest of LyX.
- ForkedcallsController & fcc = ForkedcallsController::get();
- fcc.handleCompletedProcesses();
- }
+ // Use this opportunity to deal with any child processes that
+ // have finished but are waiting to communicate this fact
+ // to the rest of LyX.
+ ForkedcallsController & fcc = ForkedcallsController::get();
+ fcc.handleCompletedProcesses();
cursor_timeout_.restart();
}
-
-void WorkArea::displayMessage(lyx::docstring const & message)
-{
- lyx_view_.message(message);
-}
-
} // namespace frontend
} // namespace lyx