Abdelrazak Younes wrote:
Hello,

As the title says...

If I don't get any objection, I'll do the merge tomorrow.

Please find attached the updated patch that I will commit now. I have corrected Lars merge issues and updated to latest trunk.

Abdel.

Index: BufferView.C
===================================================================
--- BufferView.C        (revision 14447)
+++ BufferView.C        (working copy)
@@ -96,9 +96,9 @@
 }
 
 
-void BufferView::newFile(string const & fn, string const & tn, bool named)
+string BufferView::firstLayout()
 {
-       pimpl_->newFile(fn, tn, named);
+       return pimpl_->firstLayout();
 }
 
 
Index: BufferView.h
===================================================================
--- BufferView.h        (revision 14447)
+++ BufferView.h        (working copy)
@@ -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 @@
        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 @@
 
        /// 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 @@
         */
        void putSelectionAt(DocIterator const & cur,
                int length, bool backwards);
-
        ///
        ViewMetricsInfo const & viewMetricsInfo();
 
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 14447)
+++ BufferView_pimpl.C  (working copy)
@@ -108,6 +108,7 @@
 
 unsigned int const saved_positions_num = 20;
 
+
 /// Return an inset of this class if it exists at the current cursor position
 template <class T>
 T * getInsetByCode(LCursor & cur, InsetBase::Code code)
@@ -187,7 +188,7 @@
 
        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::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 @@
                         text, 0, 1, _("&Create"), _("Cancel"));
 
                if (ret == 0)
-                       b = ::newFile(s, string(), true);
+                       b = newFile(s, string(), true);
                else
                        return false;
        }
@@ -376,11 +370,15 @@
        }
 
        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_) {
                size_t i = cursor_.depth() - 1;
@@ -389,16 +387,14 @@
                        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 @@
 //     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 @@
        }
 
        // 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 @@
                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;
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h  (revision 14447)
+++ BufferView_pimpl.h  (working copy)
@@ -34,7 +34,6 @@
 
 class FuncRequest;
 class FuncStatus;
-class ViewMetricsInfo;
 
 namespace lyx {
 namespace frontend {
@@ -50,6 +49,8 @@
        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 @@
        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,16 +162,15 @@
        /// notify readonly status
        void showReadonly(bool);
 
-
        ///
-       friend class BufferView;
-
-       ///
        ViewMetricsInfo metrics_info_;
        ///
        void updateMetrics(bool singlepar = false);
 
        ///
+       friend class BufferView;
+
+       ///
        BufferView * bv_;
        ///
        LyXView * owner_;
@@ -215,5 +213,6 @@
        lyx::pit_type anchor_ref_;
        ///
        int offset_ref_;
+
 };
 #endif // BUFFERVIEW_PIMPL_H
Index: frontends/gtk/GView.C
===================================================================
--- frontends/gtk/GView.C       (revision 14447)
+++ frontends/gtk/GView.C       (working copy)
@@ -98,7 +98,6 @@
 
        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::showViewState()
+void GView::updateStatusBar()
 {
        message(getLyXFunc().viewStatusMessage());
 }
Index: frontends/gtk/GView.h
===================================================================
--- frontends/gtk/GView.h       (revision 14447)
+++ frontends/gtk/GView.h       (working copy)
@@ -55,9 +55,10 @@
 
        // 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);
 
Index: frontends/gtk/lyx_gui.C
===================================================================
--- frontends/gtk/lyx_gui.C     (revision 14447)
+++ frontends/gtk/lyx_gui.C     (working copy)
@@ -160,7 +160,7 @@
                          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()) {
Index: frontends/LyXView.C
===================================================================
--- frontends/LyXView.C (revision 14447)
+++ frontends/LyXView.C (working copy)
@@ -80,7 +80,6 @@
        lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
 }
 
-
 LyXView::~LyXView()
 {
 }
@@ -95,9 +94,16 @@
 void LyXView::redrawWorkArea()
 {
        work_area_->redraw();
+       updateStatusBar();
 }
 
 
+WorkArea * LyXView::workArea()
+{
+       return work_area_;
+}
+
+
 void LyXView::init()
 {
        updateLayoutChoice();
@@ -120,6 +126,32 @@
 }
 
 
+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();
Index: frontends/LyXView.h
===================================================================
--- frontends/LyXView.h (revision 14447)
+++ frontends/LyXView.h (working copy)
@@ -62,6 +62,7 @@
        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 @@
 
        //@}
 
+       /// 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 @@
        void updateToolbars();
        /// update the menubar
        void updateMenubar();
+       /// update the status bar
+       virtual void updateStatusBar() = 0;
 
        /// focus the command buffer (minibuffer)
        boost::signal<void()> focus_command_buffer;
 
-       /// view state string changed
-       boost::signal<void()> view_state_changed;
-
        /// display a message in the view
        virtual void message(std::string const &) = 0;
 
@@ -152,10 +158,13 @@
        ///
        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).
        /**
Index: frontends/qt3/lyx_gui.C
===================================================================
--- frontends/qt3/lyx_gui.C     (revision 14447)
+++ frontends/qt3/lyx_gui.C     (working copy)
@@ -265,7 +265,7 @@
                          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()) {
Index: frontends/qt3/QtView.C
===================================================================
--- frontends/qt3/QtView.C      (revision 14447)
+++ frontends/qt3/QtView.C      (working copy)
@@ -81,7 +81,6 @@
 
        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()
+void QtView::updateStatusBar()
 {
        // let the user see the explicit message
        if (statusbar_timer_.isActive())
Index: frontends/qt3/QtView.h
===================================================================
--- frontends/qt3/QtView.h      (revision 14447)
+++ frontends/qt3/QtView.h      (working copy)
@@ -80,13 +80,12 @@
 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
Index: frontends/qt4/GuiView.C
===================================================================
--- frontends/qt4/GuiView.C     (revision 14447)
+++ frontends/qt4/GuiView.C     (working copy)
@@ -27,14 +27,16 @@
 #include "debug.h"
 
 #include "frontends/Toolbars.h"
-
+#include "frontends/WorkArea.h"
 #include "support/filetools.h"
-
 #include "support/convert.h"
-#include <boost/bind.hpp>
+#include "support/lstrings.h"
 
+// This include must be declared before everything else because
+// of boost/Qt/LyX clash...
+#include "GuiImplementation.h"
+
 #include "GuiView.h"
-#include "GuiImplementation.h"
 #include "QLMenubar.h"
 #include "FontLoader.h"
 #include "QCommandBuffer.h"
@@ -46,12 +48,11 @@
 #include <QToolBar>
 #include <QCloseEvent>
 #include <QAction>
-//#include <QMenu>
-//#include <QMenuBar>
 
-#include "support/lstrings.h"
 
+#include <boost/bind.hpp>
 
+
 using std::string;
 using std::endl;
 
@@ -103,7 +104,6 @@
 
        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()
+void GuiView::updateStatusBar()
 {
        // let the user see the explicit message
        if (statusbar_timer_.isActive())
Index: frontends/qt4/GuiView.h
===================================================================
--- frontends/qt4/GuiView.h     (revision 14447)
+++ frontends/qt4/GuiView.h     (working copy)
@@ -66,6 +66,9 @@
        /// 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 @@
        /// 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
Index: frontends/qt4/GuiWorkArea.C
===================================================================
--- frontends/qt4/GuiWorkArea.C (revision 14447)
+++ frontends/qt4/GuiWorkArea.C (working copy)
@@ -11,13 +11,9 @@
 
 #include <config.h>
 
-#include <boost/current_function.hpp>
 
-// 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 <QScrollBar>
 
 #include <boost/bind.hpp>
+#include <boost/current_function.hpp>
 
 // Abdel (26/06/2006):
 // On windows-XP the UserGuide PageDown scroll test is faster without event 
pruning (16 s)
@@ -208,6 +205,7 @@
                << endl;
        */
        buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition());
+       redraw();
 }
 
 
@@ -231,7 +229,7 @@
        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 @@
                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 @@
 
        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 @@
                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 @@
                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 @@
        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 @@
 //     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 @@
                << "\n QPaintEvent h\t" << e->rect().height()
                << endl;
        */
+
        QPainter q(viewport());
        q.drawPixmap(e->rect(), paint_device_, e->rect());
 
Index: frontends/qt4/lyx_gui.C
===================================================================
--- frontends/qt4/lyx_gui.C     (revision 14447)
+++ frontends/qt4/lyx_gui.C     (working copy)
@@ -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 <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
 
 #include "GuiView.h"
 #include "ColorCache.h"
@@ -54,6 +53,8 @@
 #include <QLocale>
 #include <QLibraryInfo>
 
+#include <boost/bind.hpp>
+#include <boost/shared_ptr.hpp>
 
 
 using lyx::support::ltrim;
@@ -239,7 +240,7 @@
                          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()) {
Index: frontends/qt4/qfont_metrics.C
===================================================================
--- frontends/qt4/qfont_metrics.C       (revision 14447)
+++ frontends/qt4/qfont_metrics.C       (working copy)
@@ -14,8 +14,8 @@
 #include "frontends/font_metrics.h"
 #include "frontends/lyx_gui.h"
 
+#include "Application.h"
 #include "FontLoader.h"
-#include "Application.h"
 
 #include "language.h"
 
Index: frontends/WorkArea.C
===================================================================
--- frontends/WorkArea.C        (revision 14447)
+++ frontends/WorkArea.C        (working copy)
@@ -44,6 +44,7 @@
 
 #include <boost/utility.hpp>
 #include <boost/bind.hpp>
+#include <boost/current_function.hpp>
 #include <boost/signals/trackable.hpp>
 
 using lyx::support::libFileSearch;
@@ -55,20 +56,12 @@
 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 @@
        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::redraw()
 {
-       BOOST_ASSERT(buffer_view_);
+       if (!buffer_view_)
+               return;
 
        if (!buffer_view_->buffer()) {
                greyOut();
@@ -187,35 +192,30 @@
        if (!buffer_view_->needsRedraw())
                return;
 
+       ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
        greyed_out_ = false;
-       ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
-
-       Painter & pain = getPainter();
-
-       pain.start();
-       paintText(*buffer_view_, vi, pain);
+       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);
 
-       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,12 +223,26 @@
         * 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();
+}
+
+
 void WorkArea::greyOut()
 {
        greyed_out_ = true;
@@ -334,6 +348,5 @@
        cursor_timeout_.restart();
 }
 
-
 } // namespace frontend
 } // namespace lyx
Index: frontends/WorkArea.h
===================================================================
--- frontends/WorkArea.h        (revision 14447)
+++ frontends/WorkArea.h        (working copy)
@@ -11,6 +11,14 @@
  * Full author contact details are available in file CREDITS.
  */
 
+#ifndef BASE_WORKAREA_H
+#define BASE_WORKAREA_H
+
+#include "frontends/key_state.h"
+#include "frontends/LyXKeySym.h"
+#include "frontends/Timeout.h"
+
+
 // X11 use a define called CursorShape, and we really want to use
 // that name our selves. Therefore we do something similar to what is done
 // in kde/fixx11h.h:
@@ -27,14 +35,8 @@
 } // namespace X
 
 
-#ifndef BASE_WORKAREA_H
-#define BASE_WORKAREA_H
-
-#include "frontends/key_state.h"
-#include "frontends/LyXKeySym.h"
-#include "frontends/Timeout.h"
-
 class BufferView;
+class FuncRequest;
 
 namespace lyx {
 namespace frontend {
@@ -51,7 +53,6 @@
        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 @@
        ///
        BufferView const & bufferView() const;
 
+
        /// return the painter object for this work area
        virtual Painter & getPainter() = 0;
 
@@ -92,29 +94,39 @@
        /// 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 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();
-       /// Hide the cursor
-       void hideCursor();
+
        /// 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 @@
        ///
        bool greyed_out_;
 
-       ///
+       /// is the cursor currently displayed
        bool cursor_visible_;
 
        ///
Index: importer.C
===================================================================
--- importer.C  (revision 14447)
+++ importer.C  (working copy)
@@ -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 @@
 
 
        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,
Index: insets/insettabular.C
===================================================================
--- insets/insettabular.C       (revision 14447)
+++ insets/insettabular.C       (working copy)
@@ -603,7 +603,7 @@
 //             //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 @@
 //             //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)
Index: lyx_cb.C
===================================================================
--- lyx_cb.C    (revision 14447)
+++ lyx_cb.C    (working copy)
@@ -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 @@
                            << "\nName is " << name
                            << "\nTemplate is " << tmpname << endl;
 
-       bv->newFile(name, tmpname);
+       bv->setBuffer(newFile(name, tmpname));
 }
 
 
Index: lyxfunc.C
===================================================================
--- lyxfunc.C   (revision 14447)
+++ lyxfunc.C   (working copy)
@@ -1042,7 +1042,7 @@
                        }
                        owner->message(bformat(_("Opening help file %1$s..."),
                                makeDisplayPath(fname)));
-                       view()->loadLyXFile(fname, false);
+                       owner->loadLyXFile(fname, false);
                        break;
                }
 
@@ -1088,15 +1088,15 @@
 
                // --- 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 @@
                        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 @@
                        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 @@
                        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 @@
                templname = result.second;
        }
 
-       view()->newFile(filename, templname, !name.empty());
+       owner->setBuffer(newFile(filename, templname, !name.empty()));
 }
 
 
@@ -1787,15 +1789,15 @@
 
        // 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 @@
                        // since there's no current buffer
                        owner->getDialogs().hideBufferDependent();
                } else {
-                       view()->setBuffer(bufferlist.first());
+                       owner->setBuffer(bufferlist.first());
                }
        }
 }
Index: rowpainter.h
===================================================================
--- rowpainter.h        (revision 14447)
+++ rowpainter.h        (working copy)
@@ -30,7 +30,7 @@
 
 /// 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);

Reply via email to