From e1a5cb74a8685b4d2442d73ccec737577d931766 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 13 Jul 2006 16:37:55 +0000 Subject: [PATCH] GUI API Cleanup step 3: merge with "younes" branch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14448 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 4 +- src/BufferView.h | 8 ++-- src/BufferView_pimpl.C | 70 ++++++++++++++--------------- src/BufferView_pimpl.h | 15 +++---- src/frontends/LyXView.C | 34 +++++++++++++- src/frontends/LyXView.h | 19 +++++--- src/frontends/WorkArea.C | 75 ++++++++++++++++++------------- src/frontends/WorkArea.h | 42 ++++++++++------- src/frontends/gtk/GView.C | 3 +- src/frontends/gtk/GView.h | 3 +- src/frontends/gtk/lyx_gui.C | 2 +- src/frontends/qt3/QtView.C | 3 +- src/frontends/qt3/QtView.h | 5 +-- src/frontends/qt3/lyx_gui.C | 2 +- src/frontends/qt4/GuiView.C | 18 ++++---- src/frontends/qt4/GuiView.h | 6 +-- src/frontends/qt4/GuiWorkArea.C | 25 +++++------ src/frontends/qt4/lyx_gui.C | 7 +-- src/frontends/qt4/qfont_metrics.C | 2 +- src/importer.C | 5 ++- src/insets/insettabular.C | 4 +- src/lyx_cb.C | 3 +- src/lyxfunc.C | 30 +++++++------ src/rowpainter.h | 2 +- 24 files changed, 226 insertions(+), 161 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 8da4777884..b4b4cb1a1f 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -96,9 +96,9 @@ void BufferView::setBuffer(Buffer * b) } -void BufferView::newFile(string const & fn, string const & tn, bool named) +string BufferView::firstLayout() { - pimpl_->newFile(fn, tn, named); + return pimpl_->firstLayout(); } diff --git a/src/BufferView.h b/src/BufferView.h index a05c38e84c..3f8ff3eab0 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -15,6 +15,8 @@ #ifndef BUFFER_VIEW_H #define BUFFER_VIEW_H +#include "metricsinfo.h" + #include "frontends/LyXKeySym.h" #include "support/types.h" @@ -96,6 +98,8 @@ public: void setBuffer(Buffer * b); /// return the buffer being viewed Buffer * buffer() const; + /// return the first layout of the Buffer. + std::string firstLayout(); /// return the owning main view LyXView * owner() const; @@ -105,9 +109,6 @@ public: /// reload the contained buffer void reload(); - /// create a new buffer based on template - void newFile(std::string const & fname, std::string const & tname, - bool named = true); /// load a buffer into the view bool loadLyXFile(std::string const & name, bool tolastfiles = true); @@ -220,7 +221,6 @@ public: */ void putSelectionAt(DocIterator const & cur, int length, bool backwards); - /// ViewMetricsInfo const & viewMetricsInfo(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a0b3a00f39..7ba4368d13 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -108,6 +108,7 @@ namespace { unsigned int const saved_positions_num = 20; + /// Return an inset of this class if it exists at the current cursor position template T * getInsetByCode(LCursor & cur, InsetBase::Code code) @@ -187,7 +188,7 @@ void BufferView::Pimpl::connectBuffer(Buffer & buf) closingConnection_ = buf.closing.connect( - boost::bind(&BufferView::Pimpl::setBuffer, this, (Buffer *)0)); + boost::bind(&LyXView::setBuffer, owner_, (Buffer *)0)); } @@ -203,13 +204,6 @@ void BufferView::Pimpl::disconnectBuffer() } -void BufferView::Pimpl::newFile(string const & filename, string const & tname, - bool isNamed) -{ - setBuffer(::newFile(filename, tname, isNamed)); -} - - bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) { // Get absolute path of file and add ".lyx" @@ -257,7 +251,7 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) text, 0, 1, _("&Create"), _("Cancel")); if (ret == 0) - b = ::newFile(s, string(), true); + b = newFile(s, string(), true); else return false; } @@ -376,10 +370,14 @@ void BufferView::Pimpl::setBuffer(Buffer * b) } update(); - owner_->updateMenubar(); - owner_->updateToolbars(); - owner_->updateLayoutChoice(); - owner_->updateWindowTitle(); + + if (buffer_ && lyx::graphics::Previews::status() != LyXRC::PREVIEW_OFF) + lyx::graphics::Previews::get().generateBufferPreviews(*buffer_); +} + +string BufferView::Pimpl::firstLayout() +{ + string firstlayout; // This is done after the layout combox has been populated if (buffer_) { @@ -389,16 +387,14 @@ void BufferView::Pimpl::setBuffer(Buffer * b) CursorSlice const & slice = cursor_[i]; if (!slice.inset().inMathed()) { LyXLayout_ptr const layout = slice.paragraph().layout(); - owner_->setLayout(layout->name()); + firstlayout = layout->name(); break; } BOOST_ASSERT(i>0); --i; } } - - if (buffer_ && lyx::graphics::Previews::status() != LyXRC::PREVIEW_OFF) - lyx::graphics::Previews::get().generateBufferPreviews(*buffer_); + return firstlayout; } @@ -555,7 +551,7 @@ void BufferView::Pimpl::scroll(int /*lines*/) // scrollDocView(new_top_y); // // // Update the scrollbar. -// workArea_->setScrollbarParams(t->height(), top_y(), defaultRowHeight()); +// workArea_->setScrollbarParams(t->height(), top_y(), defaultRowHeight());} } @@ -669,30 +665,32 @@ void BufferView::Pimpl::update(Update::flags flags) } // Check needed to survive LyX startup - if (buffer_) { - // Update macro store - buffer_->buildMacros(); + if (!buffer_) + return; + + // Check if there is already a redraw waiting in the queue. + if (needs_redraw_) + return; - // First drawing step - bool singlePar = flags & Update::SinglePar; - needs_redraw_ = flags & (Update::Force | Update::SinglePar); + // Update macro store + buffer_->buildMacros(); - updateMetrics(singlePar); + // First drawing step + bool singlePar = flags & Update::SinglePar; + needs_redraw_ = (flags & (Update::Force | Update::SinglePar)); - if ((flags & (Update::FitCursor | Update::MultiParSel)) - && (fitCursor() || multiParSel())) { + updateMetrics(singlePar); + + if ((flags & (Update::FitCursor | Update::MultiParSel)) + && (fitCursor() || multiParSel())) { needs_redraw_ = true; singlePar = false; - } - - if (needs_redraw_) { - // Second drawing step - updateMetrics(singlePar); - } } - owner_->redrawWorkArea(); - owner_->view_state_changed(); + if (needs_redraw_) { + // Second drawing step + updateMetrics(singlePar); + } } @@ -825,7 +823,7 @@ void BufferView::Pimpl::menuInsertLyXFile(string const & filenm) string initpath = lyxrc.document_path; if (available()) { - string const trypath = owner_->buffer()->filePath(); + string const trypath = buffer_->filePath(); // If directory is writeable, use this as default. if (isDirWriteable(trypath)) initpath = trypath; diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 8b1e33fb85..ca9c78c215 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -34,7 +34,6 @@ class LyXView; class FuncRequest; class FuncStatus; -class ViewMetricsInfo; namespace lyx { namespace frontend { @@ -50,6 +49,8 @@ public: Pimpl(BufferView & bv, LyXView * owner); /// void setBuffer(Buffer * buf); + /// return the first layout of the Buffer. + std::string firstLayout(); /// void resizeCurrentBuffer(); // @@ -58,9 +59,7 @@ public: bool multiParSel(); /// void update(Update::flags flags = Update::Force); - /// - void newFile(std::string const &, std::string const &, bool); - /// + /// load a buffer into the view bool loadLyXFile(std::string const &, bool); /// void workAreaResize(int width, int height); @@ -163,15 +162,14 @@ private: /// notify readonly status void showReadonly(bool); - - /// - friend class BufferView; - /// ViewMetricsInfo metrics_info_; /// void updateMetrics(bool singlepar = false); + /// + friend class BufferView; + /// BufferView * bv_; /// @@ -215,5 +213,6 @@ private: lyx::pit_type anchor_ref_; /// int offset_ref_; + }; #endif // BUFFERVIEW_PIMPL_H diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 7cf2a05887..54dad90f3e 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -80,7 +80,6 @@ LyXView::LyXView(Gui & owner) lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl; } - LyXView::~LyXView() { } @@ -95,6 +94,13 @@ void LyXView::setWorkArea(WorkArea * work_area) void LyXView::redrawWorkArea() { work_area_->redraw(); + updateStatusBar(); +} + + +WorkArea * LyXView::workArea() +{ + return work_area_; } @@ -120,6 +126,32 @@ Buffer * LyXView::buffer() const } +void LyXView::setBuffer(Buffer * b) +{ + work_area_->bufferView().setBuffer(b); + updateMenubar(); + updateToolbars(); + updateLayoutChoice(); + updateWindowTitle(); + if (b) + setLayout(work_area_->bufferView().firstLayout()); + redrawWorkArea(); +} + + +bool LyXView::loadLyXFile(string const & filename, bool tolastfiles) +{ + bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles); + updateMenubar(); + updateToolbars(); + updateLayoutChoice(); + updateWindowTitle(); + if (loaded) + setLayout(work_area_->bufferView().firstLayout()); + redrawWorkArea(); + return loaded; +} + BufferView * LyXView::view() const { return &work_area_->bufferView(); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 36245d0f5b..7c9a2a98e2 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -62,6 +62,7 @@ public: virtual ~LyXView(); void setWorkArea(lyx::frontend::WorkArea * work_area); + /** * This is called after the concrete view has been created. * We have to have the toolbar and the other stuff created @@ -110,6 +111,12 @@ public: //@} + /// load a buffer into the current workarea + bool loadLyXFile(std::string const & name, bool tolastfiles = true); + + /// set a buffer to the current workarea + void setBuffer(Buffer * b); + /// sets the layout in the toolbar layout selection void setLayout(std::string const & layout); /// updates the possible layouts selectable @@ -119,13 +126,12 @@ public: void updateToolbars(); /// update the menubar void updateMenubar(); + /// update the status bar + virtual void updateStatusBar() = 0; /// focus the command buffer (minibuffer) boost::signal focus_command_buffer; - /// view state string changed - boost::signal view_state_changed; - /// display a message in the view virtual void message(std::string const &) = 0; @@ -152,10 +158,13 @@ public: /// virtual lyx::frontend::Gui & gui(); - lyx::frontend::WorkArea * workArea() const { return work_area_; } - /// Temporary method used by the kernel to redraw the work area. virtual void redrawWorkArea(); + + /// Temporary method to access the current workArea. + /// This is needed for the qt3 and gtk frontend. + lyx::frontend::WorkArea * workArea(); + protected: /// current work area (screen view of a BufferView). /** diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 21fa3fb9b0..0ff8fb4f82 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -44,6 +44,7 @@ #include #include +#include #include using lyx::support::libFileSearch; @@ -55,20 +56,12 @@ using std::max; using std::string; -namespace { - -// All the below connection objects are needed because of a bug in some -// versions of GCC (<=2.96 are on the suspects list.) By having and assigning -// to these connections we avoid a segfault upon startup, and also at exit. -// (Lgb) - -boost::signals::connection timecon; - -} // anon namespace - namespace lyx { namespace frontend { +// FIXME: The SplashScreen should be transfered to the +// LyXView and create a WorkArea only when a new buffer exists. This +// will allow to call WorkArea::redraw() in the constructor. class SplashScreen : boost::noncopyable, boost::signals::trackable { public: /// This is a singleton class. Get the instance. @@ -131,9 +124,20 @@ SplashScreen::SplashScreen() loader_.reset(file); } +namespace { + +// All the below connection objects are needed because of a bug in some +// versions of GCC (<=2.96 are on the suspects list.) By having and assigning +// to these connections we avoid a segfault upon startup, and also at exit. +// (Lgb) + +boost::signals::connection timecon; + +} // anon namespace + WorkArea::WorkArea(BufferView * buffer_view) - : buffer_view_(buffer_view), greyed_out_(true), - cursor_visible_(false), cursor_timeout_(400) + : buffer_view_(buffer_view), greyed_out_(true), + cursor_visible_(false), cursor_timeout_(400) { // Start loading the pixmap as soon as possible if (lyxrc.show_banner) { @@ -177,7 +181,8 @@ void WorkArea::checkAndGreyOut() void WorkArea::redraw() { - BOOST_ASSERT(buffer_view_); + if (!buffer_view_) + return; if (!buffer_view_->buffer()) { greyOut(); @@ -187,35 +192,30 @@ void WorkArea::redraw() if (!buffer_view_->needsRedraw()) return; - greyed_out_ = false; ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo(); - - Painter & pain = getPainter(); - - pain.start(); - paintText(*buffer_view_, vi, pain); + greyed_out_ = false; + getPainter().start(); + paintText(*buffer_view_, vi, getPainter()); lyxerr[Debug::DEBUG] << "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); - pain.end(); - //theCoords.doneUpdating(); + getPainter().end(); buffer_view_->needsRedraw(false); - if (lyxerr.debugging(Debug::DEBUG)) { - lyxerr[Debug::DEBUG] - << " ymin = " << ymin << " width() = " << width() - << " ymax-ymin = " << ymax-ymin << std::endl; - } + lyxerr[Debug::DEBUG] + << " ymin = " << ymin << " width() = " << width() + << " ymax-ymin = " << ymax-ymin << std::endl; } -void WorkArea::processKeySym(LyXKeySymPtr key, key_modifier::state state) +void WorkArea::processKeySym(LyXKeySymPtr key, + key_modifier::state state) { hideCursor(); - buffer_view_->workAreaKeyPress(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 @@ -223,9 +223,23 @@ void WorkArea::processKeySym(LyXKeySymPtr key, key_modifier::state state) * of the cursor. Note we cannot do this inside * dispatch() itself, because that's called recursively. */ - // if (buffer_view_->available()) +// if (buffer_view_->available()) toggleCursor(); + redraw(); +} + + +void WorkArea::dispatch(FuncRequest const & cmd0) +{ + buffer_view_->workAreaDispatch(cmd0); + redraw(); +} + +void WorkArea::resizeBufferView() +{ + buffer_view_->workAreaResize(width(), height()); + redraw(); } @@ -334,6 +348,5 @@ void WorkArea::toggleCursor() cursor_timeout_.restart(); } - } // namespace frontend } // namespace lyx diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index ffa8b2bc42..1405c8f2ea 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -34,7 +34,9 @@ int const CursorShape = CursorShape; #include "frontends/LyXKeySym.h" #include "frontends/Timeout.h" + class BufferView; +class FuncRequest; namespace lyx { namespace frontend { @@ -51,7 +53,6 @@ enum CursorShape { REVERSED_L_SHAPE }; - /** * The work area class represents the widget that provides the * view onto a document. It is owned by the BufferView, and @@ -72,6 +73,7 @@ public: /// BufferView const & bufferView() const; + /// return the painter object for this work area virtual Painter & getPainter() = 0; @@ -92,28 +94,38 @@ public: /// redraw the screen, without using existing pixmap virtual void redraw(); - /// - void processKeySym(LyXKeySymPtr key, key_modifier::state state); - /// grey out (no buffer) void greyOut(); - /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, CursorShape shape) = 0; + /// FIXME: should be protected, public until the qt3 and gtk frontends are + /// cleaned up. + void processKeySym(LyXKeySymPtr key, key_modifier::state state); - /// hide the cursor - virtual void removeCursor() = 0; +protected: + /// cause the display of the given area of the work area + virtual void expose(int x, int y, int w, int h) = 0; - /// Show the cursor - void showCursor(); - /// Hide the cursor + /// + void dispatch(FuncRequest const & cmd0); + + /// + void resizeBufferView(); + + + /// hide the visible cursor, if it is visible void hideCursor(); + + /// show the cursor if it is not visible + void showCursor(); + /// toggle the cursor's visibility void toggleCursor(); -protected: - /// cause the display of the given area of the work area - virtual void expose(int x, int y, int w, int h) = 0; + /// hide the cursor + virtual void removeCursor() = 0; + + /// paint the cursor and store the background + virtual void showCursor(int x, int y, int h, CursorShape shape) = 0; /// BufferView * buffer_view_; @@ -125,7 +137,7 @@ private: /// bool greyed_out_; - /// + /// is the cursor currently displayed bool cursor_visible_; /// diff --git a/src/frontends/gtk/GView.C b/src/frontends/gtk/GView.C index 6765f2197e..0603561b27 100644 --- a/src/frontends/gtk/GView.C +++ b/src/frontends/gtk/GView.C @@ -98,7 +98,6 @@ GView::GView(Gui & owner) : LyXView(owner) focus_command_buffer.connect( boost::bind(&GMiniBuffer::editMode, minibuffer_.get())); - view_state_changed.connect(boost::bind(&GView::showViewState, this)); signal_focus_in_event().connect(sigc::mem_fun(*this, &GView::onFocusIn)); // int width = 750; @@ -177,7 +176,7 @@ void GView::message(string const & msg) } -void GView::showViewState() +void GView::updateStatusBar() { message(getLyXFunc().viewStatusMessage()); } diff --git a/src/frontends/gtk/GView.h b/src/frontends/gtk/GView.h index ce0c3be837..ea05f84a1c 100644 --- a/src/frontends/gtk/GView.h +++ b/src/frontends/gtk/GView.h @@ -55,9 +55,10 @@ public: // returns true if this view has the focus. virtual bool hasFocus() const; + /// + void updateStatusBar(); private: - void showViewState(); bool onFocusIn(GdkEventFocus * event); virtual void setWindowTitle(std::string const & t, std::string const & it); diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index 40d6676156..ea07200152 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -160,7 +160,7 @@ int lyx_gui::start(string const & batch, std::vector const & files, os::internal_path(package().temp_dir() + "/lyxsocket")); for_each(files.begin(), files.end(), - bind(&BufferView::loadLyXFile, view.view(), _1, true)); + bind(&LyXView::loadLyXFile, &view, _1, true)); // handle the batch commands the user asked for if (!batch.empty()) { diff --git a/src/frontends/qt3/QtView.C b/src/frontends/qt3/QtView.C index 4b4847e98c..e6975dd63a 100644 --- a/src/frontends/qt3/QtView.C +++ b/src/frontends/qt3/QtView.C @@ -81,7 +81,6 @@ void QtView::init() statusBar()->setSizeGripEnabled(false); - view_state_changed.connect(boost::bind(&QtView::update_view_state, this)); connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt())); // make sure the buttons are disabled if needed @@ -137,7 +136,7 @@ void QtView::update_view_state_qt() } -void QtView::update_view_state() +void QtView::updateStatusBar() { // let the user see the explicit message if (statusbar_timer_.isActive()) diff --git a/src/frontends/qt3/QtView.h b/src/frontends/qt3/QtView.h index a87533b7c3..f79ee1ae4a 100644 --- a/src/frontends/qt3/QtView.h +++ b/src/frontends/qt3/QtView.h @@ -80,13 +80,12 @@ public slots: protected: /// make sure we quit cleanly virtual void closeEvent(QCloseEvent * e); + /// update status bar + void updateStatusBar(); private: /// focus the command buffer widget void focus_command_widget(); - /// update status bar - void update_view_state(); - /** * setWindowTitle - set title of window * @param t main window title diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index 70a2792e50..33cc8f9c13 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -265,7 +265,7 @@ int start(string const & batch, vector const & files, os::internal_path(package().temp_dir() + "/lyxsocket")); for_each(files.begin(), files.end(), - bind(&BufferView::loadLyXFile, view.view(), _1, true)); + bind(&LyXView::loadLyXFile, &view, _1, true)); // handle the batch commands the user asked for if (!batch.empty()) { diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index f80a56eca1..775460104c 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -27,14 +27,16 @@ #include "debug.h" #include "frontends/Toolbars.h" - +#include "frontends/WorkArea.h" #include "support/filetools.h" - #include "support/convert.h" -#include +#include "support/lstrings.h" -#include "GuiView.h" +// This include must be declared before everything else because +// of boost/Qt/LyX clash... #include "GuiImplementation.h" + +#include "GuiView.h" #include "QLMenubar.h" #include "FontLoader.h" #include "QCommandBuffer.h" @@ -46,10 +48,9 @@ #include #include #include -//#include -//#include -#include "support/lstrings.h" + +#include using std::string; @@ -103,7 +104,6 @@ void GuiView::init() statusBar()->setSizeGripEnabled(false); - view_state_changed.connect(boost::bind(&GuiView::update_view_state, this)); QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt())); // make sure the buttons are disabled if needed @@ -161,7 +161,7 @@ void GuiView::update_view_state_qt() } -void GuiView::update_view_state() +void GuiView::updateStatusBar() { // let the user see the explicit message if (statusbar_timer_.isActive()) diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 6918e4d51e..385fa22e41 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -66,6 +66,9 @@ public: /// clear status message virtual void clearMessage(); + /// update the status bar + virtual void updateStatusBar(); + /// add the command buffer void addCommandBuffer(QToolBar * toolbar); @@ -99,9 +102,6 @@ private: /// focus the command buffer widget void focus_command_widget(); - /// update status bar - void update_view_state(); - /** * setWindowTitle - set title of window * @param t main window title diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C index d17d6aefd6..4f0a8d21de 100644 --- a/src/frontends/qt4/GuiWorkArea.C +++ b/src/frontends/qt4/GuiWorkArea.C @@ -11,13 +11,9 @@ #include -#include - -// This include must be declared before everything else because -// of boost/Qt/LyX clash... -#include "GuiView.h" #include "GuiWorkArea.h" + #include "QLPainter.h" #include "QLyXKeySym.h" @@ -40,6 +36,7 @@ #include #include +#include // Abdel (26/06/2006): // On windows-XP the UserGuide PageDown scroll test is faster without event pruning (16 s) @@ -208,6 +205,7 @@ void GuiWorkArea::adjustViewWithScrollBar(int) << endl; */ buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition()); + redraw(); } @@ -231,7 +229,7 @@ void GuiWorkArea::dropEvent(QDropEvent* event) for (int i = 0; i!=files.size(); ++i) { string const file = os::internal_path(fromqstr(files.at(i).toString())); if (!file.empty()) - buffer_view_->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file)); + dispatch(FuncRequest(LFUN_FILE_OPEN, file)); } } @@ -243,13 +241,13 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e) FuncRequest cmd(LFUN_MOUSE_TRIPLE, dc_event_.x, dc_event_.y, q_button_state(dc_event_.state)); - buffer_view_->workAreaDispatch(cmd); + dispatch(cmd); return; } FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(), q_button_state(e->button())); - buffer_view_->workAreaDispatch(cmd); + dispatch(cmd); } @@ -260,7 +258,7 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e) FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(), q_button_state(e->button())); - buffer_view_->workAreaDispatch(cmd); + dispatch(cmd); } @@ -320,7 +318,7 @@ void GuiWorkArea::mouseMoveEvent(QMouseEvent * e) synthetic_mouse_event_.scrollbar_value_old = scrollbar_value; // ... and dispatch the event to the LyX core. - buffer_view_->workAreaDispatch(cmd); + dispatch(cmd); } } @@ -350,7 +348,7 @@ void GuiWorkArea::generateSyntheticMouseEvent() synthetic_mouse_event_.scrollbar_value_old = scrollbar_value; // ... and dispatch the event to the LyX core. - buffer_view_->workAreaDispatch(synthetic_mouse_event_.cmd); + dispatch(synthetic_mouse_event_.cmd); } } @@ -423,7 +421,7 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e) FuncRequest cmd(LFUN_MOUSE_DOUBLE, dc_event_.x, dc_event_.y, q_button_state(dc_event_.state)); - buffer_view_->workAreaDispatch(cmd); + dispatch(cmd); } @@ -438,7 +436,7 @@ void GuiWorkArea::resizeEvent(QResizeEvent *) // paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32); paint_device_ = QPixmap(viewport()->width(), viewport()->height()); - buffer_view_->workAreaResize(viewport()->width(), viewport()->height()); + resizeBufferView(); /* lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION @@ -479,6 +477,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * e) << "\n QPaintEvent h\t" << e->rect().height() << endl; */ + QPainter q(viewport()); q.drawPixmap(e->rect(), paint_device_, e->rect()); diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index 3051dbe9d6..cdf6e9a292 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -29,6 +29,7 @@ #include "lyxserver.h" #include "lyxsocket.h" + #include "graphics/LoaderQueue.h" #include "support/lstrings.h" @@ -36,8 +37,6 @@ #include "support/package.h" #include "debug.h" -#include -#include #include "GuiView.h" #include "ColorCache.h" @@ -54,6 +53,8 @@ #include #include +#include +#include using lyx::support::ltrim; @@ -239,7 +240,7 @@ int start(string const & batch, vector const & files, os::internal_path(package().temp_dir() + "/lyxsocket")); for_each(files.begin(), files.end(), - bind(&BufferView::loadLyXFile, view.view(), _1, true)); + bind(&LyXView::loadLyXFile, &view, _1, true)); // handle the batch commands the user asked for if (!batch.empty()) { diff --git a/src/frontends/qt4/qfont_metrics.C b/src/frontends/qt4/qfont_metrics.C index 04d0908315..c233a8d8f0 100644 --- a/src/frontends/qt4/qfont_metrics.C +++ b/src/frontends/qt4/qfont_metrics.C @@ -14,8 +14,8 @@ #include "frontends/font_metrics.h" #include "frontends/lyx_gui.h" -#include "FontLoader.h" #include "Application.h" +#include "FontLoader.h" #include "language.h" diff --git a/src/importer.C b/src/importer.C index 1c84d3d147..b2d6f12156 100644 --- a/src/importer.C +++ b/src/importer.C @@ -24,6 +24,7 @@ #include "frontends/Alert.h" #include "gettext.h" #include "BufferView.h" +#include "buffer_funcs.h" using lyx::support::bformat; using lyx::support::changeExtension; @@ -69,9 +70,9 @@ bool Importer::Import(LyXView * lv, string const & filename, if (loader_format == "lyx") { - lv->view()->loadLyXFile(lyxfile); + lv->loadLyXFile(lyxfile); } else { - lv->view()->newFile(lyxfile, string(), true); + lv->setBuffer(newFile(lyxfile, string(), true)); bool as_paragraphs = loader_format == "textparagraph"; string filename2 = (loader_format == format) ? filename : changeExtension(filename, diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 2288ac29c4..3f9fabe9ba 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -603,7 +603,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) // //if (hasSelection()) // // cur.selection() = false; // col_type const col = tabular.column_of_cell(cur.idx()); -// int const t = cur.bv().top_y() + cur.bv().painter().paperHeight(); +// int const t = cur.bv().top_y() + cur.bv().height(); // if (t < yo() + tabular.getHeightOfTabular()) { // cur.bv().scrollDocView(t); // cur.idx() = tabular.getCellBelow(first_visible_cell) + col; @@ -619,7 +619,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) // //if (hasSelection()) // // cur.selection() = false; // col_type const col = tabular.column_of_cell(cur.idx()); -// int const t = cur.bv().top_y() + cur.bv().painter().paperHeight(); +// int const t = cur.bv().top_y() + cur.bv().height(); // if (yo() < 0) { // cur.bv().scrollDocView(t); // if (yo() > 0) diff --git a/src/lyx_cb.C b/src/lyx_cb.C index fcd809bec7..c47d517869 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -19,6 +19,7 @@ #include "buffer.h" #include "bufferlist.h" #include "BufferView.h" +#include "buffer_funcs.h" #include "cursor.h" #include "debug.h" #include "gettext.h" @@ -342,7 +343,7 @@ void newFile(BufferView * bv, string const & filename) << "\nName is " << name << "\nTemplate is " << tmpname << endl; - bv->newFile(name, tmpname); + bv->setBuffer(newFile(name, tmpname)); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 355f5ff4e9..59f6c47fe9 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1042,7 +1042,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } owner->message(bformat(_("Opening help file %1$s..."), makeDisplayPath(fname))); - view()->loadLyXFile(fname, false); + owner->loadLyXFile(fname, false); break; } @@ -1088,15 +1088,15 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // --- buffers ---------------------------------------- case LFUN_BUFFER_SWITCH: - view()->setBuffer(bufferlist.getBuffer(argument)); + owner->setBuffer(bufferlist.getBuffer(argument)); break; case LFUN_BUFFER_NEXT: - view()->setBuffer(bufferlist.next(view()->buffer())); + owner->setBuffer(bufferlist.next(view()->buffer())); break; case LFUN_BUFFER_PREVIOUS: - view()->setBuffer(bufferlist.previous(view()->buffer())); + owner->setBuffer(bufferlist.previous(view()->buffer())); break; case LFUN_FILE_NEW: @@ -1136,16 +1136,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (prefixIs(file_name, package().temp_dir())) { // Needed by inverse dvi search. If it is a file // in tmpdir, call the apropriated function - view()->setBuffer(bufferlist.getBufferFromTmp(file_name)); + owner->setBuffer(bufferlist.getBufferFromTmp(file_name)); } else { // Must replace extension of the file to be .lyx // and get full path string const s = changeExtension(file_name, ".lyx"); // Either change buffer or load the file if (bufferlist.exists(s)) { - view()->setBuffer(bufferlist.getBuffer(s)); + owner->setBuffer(bufferlist.getBuffer(s)); } else { - view()->loadLyXFile(s); + owner->loadLyXFile(s); } } @@ -1296,9 +1296,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) view()->savePosition(0); string const parentfilename = owner->buffer()->fileName(); if (bufferlist.exists(filename)) - view()->setBuffer(bufferlist.getBuffer(filename)); + owner->setBuffer(bufferlist.getBuffer(filename)); else - view()->loadLyXFile(filename); + owner->loadLyXFile(filename); // Set the parent name of the child document. // This makes insertion of citations and references in the child work, // when the target is in the parent or another child document. @@ -1607,6 +1607,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) else if (update) view()->update(Update::FitCursor); + owner->redrawWorkArea(); + // if we executed a mutating lfun, mark the buffer as dirty if (flag.enabled() && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) @@ -1733,7 +1735,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) templname = result.second; } - view()->newFile(filename, templname, !name.empty()); + owner->setBuffer(newFile(filename, templname, !name.empty())); } @@ -1787,15 +1789,15 @@ void LyXFunc::open(string const & fname) // if the file doesn't exist, let the user create one if (!fs::exists(filename)) { - // the user specifically chose this name. Believe them. - view()->newFile(filename, "", true); + // the user specifically chose this name. Believe him. + owner->setBuffer(newFile(filename, "", true)); return; } owner->message(bformat(_("Opening document %1$s..."), disp_fn)); string str2; - if (view()->loadLyXFile(filename)) { + if (owner->loadLyXFile(filename)) { str2 = bformat(_("Document %1$s opened."), disp_fn); } else { str2 = bformat(_("Could not open document %1$s"), disp_fn); @@ -1899,7 +1901,7 @@ void LyXFunc::closeBuffer() // since there's no current buffer owner->getDialogs().hideBufferDependent(); } else { - view()->setBuffer(bufferlist.first()); + owner->setBuffer(bufferlist.first()); } } } diff --git a/src/rowpainter.h b/src/rowpainter.h index 2551fec92d..e15f2d6392 100644 --- a/src/rowpainter.h +++ b/src/rowpainter.h @@ -30,7 +30,7 @@ class Painter; /// paint visible paragraph of main text void paintText(BufferView const & bv, ViewMetricsInfo const & vi, - lyx::frontend::Painter & pain); + lyx::frontend::Painter & painter); /// paint the rows of a text inset void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y); -- 2.39.5