Hello,

This patch continue my tedious cleanup work. Basically it transfer most of the LyXView use from BufferView to WorkArea, most notably:

LyXView::updateLayoutChoice();
LyXView::updateToolbars();
LyXView::getLyXFunc().processKeySym(key, state);
LyXView::dispatch(cmd);

This patch has been tested for qt4 but not for qt3 and gtk (not even compiled). I'd be grateful if someone help me with that task.

I would like to commit it and wait for some kind soul to verify that it also compile and work for qt3 and gtk.

As a side (but important) note I want to express that I am really fad up to update also qt3 and gtk. This is just doubling the time for each of my cleanup patches. Besides, they are very far behind of qt4 WRT my cleanups now. I really, _really_, think it's not worth it.

IIRC the main gtk maintainer explicitly said that he will update it when unicode is in. Besides I think that doing the full cleanup will need less work than the accumulated work trying to maintain the frontend in a compilable and working state. This is not fun really.

The same argument applies to qt3. Furthermore, qt4 is feature complete now thanks to Edwin latest Bullet patch. So please, let's just drop it.

As for the honesty argument about multiple frontend support, I think I have shown that I was very honest ;-)

Abdel.


Index: BufferView.C
===================================================================
--- BufferView.C        (revision 14681)
+++ BufferView.C        (working copy)
@@ -235,12 +235,6 @@
 }
 
 
-void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
-{
-       pimpl_->workAreaKeyPress(key, state);
-}
-
-
 bool BufferView::workAreaDispatch(FuncRequest const & ev)
 {
        return pimpl_->workAreaDispatch(ev);
Index: BufferView.h
===================================================================
--- BufferView.h        (revision 14681)
+++ BufferView.h        (working copy)
@@ -185,9 +185,6 @@
        ///
        void workAreaResize(int width, int height);
 
-       /// Receive a keypress
-       void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
-
        /// a function should be executed from the workarea
        bool workAreaDispatch(FuncRequest const & ev);
 
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 14681)
+++ BufferView_pimpl.C  (working copy)
@@ -231,12 +231,6 @@
 }
 
 
-lyx::frontend::Gui & BufferView::Pimpl::gui() const
-{
-       return owner_->gui();
-}
-
-
 int BufferView::Pimpl::width() const
 {
        return width_;
@@ -470,7 +464,6 @@
                        t.setCursorFromCoordinates(cur, 0, newy);
                }
        }
-       owner_->updateLayoutChoice();
 }
 
 
@@ -496,13 +489,6 @@
 }
 
 
-void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
-                                        key_modifier::state state)
-{
-       owner_->getLyXFunc().processKeySym(key, state);
-}
-
-
 void BufferView::Pimpl::selectionRequested()
 {
        static string sel;
@@ -556,8 +542,6 @@
 
        if (widthChange || heightChange)
                update();
-
-       owner_->updateLayoutChoice();
 }
 
 
@@ -845,12 +829,6 @@
        // LFUN_FILE_OPEN generated by drag-and-drop.
        FuncRequest cmd = cmd0;
 
-       // Handle drag&drop
-       if (cmd.action == LFUN_FILE_OPEN) {
-               owner_->dispatch(cmd);
-               return true;
-       }
-
        if (!buffer_)
                return false;
 
@@ -899,16 +877,6 @@
                        update(Update::FitCursor | Update::MultiParSel);
        }
 
-       // Skip these when selecting
-       if (cmd.action != LFUN_MOUSE_MOTION) {
-               owner_->updateLayoutChoice();
-               owner_->updateToolbars();
-       }
-
-       // Slight hack: this is only called currently when we
-       // clicked somewhere, so we force through the display
-       // of the new status here.
-       owner_->clearMessage();
        return true;
 }
 
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h  (revision 14681)
+++ BufferView_pimpl.h  (working copy)
@@ -69,8 +69,6 @@
        /// Wheel mouse scroll, move by multiples of text->defaultRowHeight().
        void scroll(int lines);
        ///
-       void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
-       ///
        void selectionRequested();
        ///
        void selectionLost();
@@ -97,9 +95,6 @@
        /// a function should be executed
        bool dispatch(FuncRequest const & ev);
 
-       /// the frontend
-       lyx::frontend::Gui & gui() const;
-
        /// Width and height of the BufferView in Pixels
        /**
        This is set externally by the workAreaResize method.
Index: frontends/gtk/GuiWorkArea.h
===================================================================
--- frontends/gtk/GuiWorkArea.h (revision 14681)
+++ frontends/gtk/GuiWorkArea.h (working copy)
@@ -27,7 +27,7 @@
 class GuiWorkArea: public lyx::frontend::WorkArea {
 public:
        GuiWorkArea(GScreen * screen, GWorkArea * work_area)
-               : old_screen_(screen), old_work_area_(work_area)
+               : WorkArea(work_area->view()), old_screen_(screen), 
old_work_area_(work_area)
        {
        }
 
Index: frontends/gtk/GWorkArea.C
===================================================================
--- frontends/gtk/GWorkArea.C   (revision 14681)
+++ frontends/gtk/GWorkArea.C   (working copy)
@@ -376,8 +376,7 @@
        adjusting_ = true;
 
        double val = vscrollbar_.get_adjustment()->get_value();
-       view_.view()->scrollDocView(static_cast<int>(val));
-       view_.workArea()->redraw();
+       view_.workArea()->scrollBufferView(static_cast<int>(val));
        adjusting_ = false;
 }
 
Index: frontends/gtk/GWorkArea.h
===================================================================
--- frontends/gtk/GWorkArea.h   (revision 14681)
+++ frontends/gtk/GWorkArea.h   (working copy)
@@ -82,6 +82,12 @@
        /// a selection exists
        virtual void haveSelection(bool);
        void inputCommit(gchar * str);
+
+       LyXView & view()
+       {
+               return view_;
+       }
+
 private:
        bool onExpose(GdkEventExpose * event);
        bool onConfigure(GdkEventConfigure * event);
Index: frontends/qt3/GuiWorkArea.h
===================================================================
--- frontends/qt3/GuiWorkArea.h (revision 14681)
+++ frontends/qt3/GuiWorkArea.h (working copy)
@@ -30,7 +30,7 @@
 class GuiWorkArea: public lyx::frontend::WorkArea {
 public:
        GuiWorkArea(FScreen * screen, FWorkArea * work_area)
-               : old_screen_(screen), old_work_area_(work_area)
+               : WorkArea(work_area->view()), old_screen_(screen), 
old_work_area_(work_area)
        {
        }
 
Index: frontends/qt3/QContentPane.C
===================================================================
--- frontends/qt3/QContentPane.C        (revision 14681)
+++ frontends/qt3/QContentPane.C        (working copy)
@@ -169,10 +169,8 @@
 
 void QContentPane::scrollBarChanged(int val)
 {
-       if (track_scrollbar_) {
-               wa_->view().view()->scrollDocView(val);
-               wa_->view().workArea()->redraw();
-       }
+       if (track_scrollbar_)
+               wa_->view().workArea()->scrollBufferView(val);
 }
 
 
@@ -340,7 +338,7 @@
        }
 
        pixmap_->resize(width(), height());
-       wa_->view().view()->workAreaResize(width(), height());
+       wa_->view().workArea()->resizeBufferView();
 }
 
 
@@ -350,7 +348,7 @@
 
        if (!pixmap_.get()) {
                pixmap_.reset(new QPixmap(width(), height()));
-               buffer_view_->workAreaResize(width(), height());
+               wa_->view().workArea()->resizeBufferView();
                return;
        }
 
Index: frontends/qt4/GuiImplementation.C
===================================================================
--- frontends/qt4/GuiImplementation.C   (revision 14681)
+++ frontends/qt4/GuiImplementation.C   (working copy)
@@ -75,7 +75,7 @@
 
        GuiView * view = views_[view_id].get();
 
-       work_areas_[id].reset(new GuiWorkArea(w, h, view));
+       work_areas_[id].reset(new GuiWorkArea(w, h, *view));
 
        // FIXME BufferView creation should be independant of WorkArea creation
        buffer_views_[id].reset(new BufferView(view));
Index: frontends/qt4/GuiWorkArea.C
===================================================================
--- frontends/qt4/GuiWorkArea.C (revision 14681)
+++ frontends/qt4/GuiWorkArea.C (working copy)
@@ -117,8 +117,8 @@
 {}
 
 
-GuiWorkArea::GuiWorkArea(int w, int h, QWidget * parent, BufferView * 
buffer_view)
-: QAbstractScrollArea(parent), WorkArea(buffer_view), painter_(this)
+GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
+: WorkArea(lyx_view), painter_(this)
 {
        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -137,7 +137,6 @@
        viewport()->setCursor(Qt::IBeamCursor);
 
        resize(w, h);
-       show();
        workWidth_ = w;
        workHeight_ = h;
 
@@ -197,18 +196,7 @@
 
 void GuiWorkArea::adjustViewWithScrollBar(int)
 {
-       /*
-       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-               << " verticalScrollBar val=" << verticalScrollBar()->value()
-               << " verticalScrollBar pos=" << 
verticalScrollBar()->sliderPosition()
-               << " min=" << verticalScrollBar()->minimum()
-               << " max=" << verticalScrollBar()->maximum()
-               << " pagestep=" << verticalScrollBar()->pageStep()
-               << " linestep=" << verticalScrollBar()->lineStep()
-               << endl;
-       */
-       buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition());
-       redraw();
+       scrollBufferView(verticalScrollBar()->sliderPosition());
 }
 
 
Index: frontends/qt4/GuiWorkArea.h
===================================================================
--- frontends/qt4/GuiWorkArea.h (revision 14681)
+++ frontends/qt4/GuiWorkArea.h (working copy)
@@ -101,7 +101,7 @@
 
 public:
 
-       GuiWorkArea(int width, int height, QWidget * parent, BufferView * 
buffer_view = 0);
+       GuiWorkArea(int width, int height, LyXView & lyx_view);
 
        virtual ~GuiWorkArea();
        /// return the width of the content pane
Index: frontends/WorkArea.C
===================================================================
--- frontends/WorkArea.C        (revision 14681)
+++ frontends/WorkArea.C        (working copy)
@@ -16,7 +16,9 @@
 #include "WorkArea.h"
 
 #include "font_metrics.h"
+#include "funcrequest.h"
 #include "lyx_gui.h"
+#include "lyxfunc.h"
 #include "Painter.h"
 
 #include "BufferView.h"
@@ -31,6 +33,7 @@
 #include "lyxrc.h"
 #include "lyxrow.h"
 #include "lyxtext.h"
+#include "LyXView.h"
 #include "metricsinfo.h"
 #include "paragraph.h"
 #include "rowpainter.h"
@@ -135,8 +138,8 @@
 
 } // anon namespace
 
-WorkArea::WorkArea(BufferView * buffer_view)
-       :  buffer_view_(buffer_view), greyed_out_(true),
+WorkArea::WorkArea(LyXView & lyx_view)
+       :  buffer_view_(0), lyx_view_(lyx_view), greyed_out_(true),
        cursor_visible_(false), cursor_timeout_(400)
 {
        // Start loading the pixmap as soon as possible
@@ -211,7 +214,7 @@
                                                         key_modifier::state 
state)
 {
        hideCursor();
-       buffer_view_->workAreaKeyPress(key, state);
+       lyx_view_.getLyXFunc().processKeySym(key, state);
 
        /* This is perhaps a bit of a hack. When we move
         * around, or type, it's nice to be able to see
@@ -222,7 +225,7 @@
         */
 //     if (buffer_view_->available())
        toggleCursor();
-
+       
        // uneeded "redraw()" call commented out for now.
        // When/if the call to LyXView::redrawWorkArea() in "lyxfunc.C:1610"
        // is not needed anymore, this line should be uncommented out
@@ -232,7 +235,25 @@
 
 void WorkArea::dispatch(FuncRequest const & cmd0)
 {
+       // Handle drag&drop
+       if (cmd0.action == LFUN_FILE_OPEN) {
+               lyx_view_.dispatch(cmd0);
+               return;
+       }
+
        buffer_view_->workAreaDispatch(cmd0);
+
+       // Skip these when selecting
+       if (cmd0.action != LFUN_MOUSE_MOTION) {
+               lyx_view_.updateLayoutChoice();
+               lyx_view_.updateToolbars();
+       }
+
+       // 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();
+
        redraw();
 }
 
@@ -240,10 +261,19 @@
 void WorkArea::resizeBufferView()
 {
        buffer_view_->workAreaResize(width(), height());
+       lyx_view_.updateLayoutChoice();
        redraw();
 }
 
 
+void WorkArea::scrollBufferView(int position)
+{
+       buffer_view_->scrollDocView(position);
+       lyx_view_.updateLayoutChoice();
+       redraw();
+}
+
+
 void WorkArea::greyOut()
 {
        greyed_out_ = true;
Index: frontends/WorkArea.h
===================================================================
--- frontends/WorkArea.h        (revision 14681)
+++ frontends/WorkArea.h        (working copy)
@@ -37,6 +37,7 @@
 
 class BufferView;
 class FuncRequest;
+class LyXView;
 
 namespace lyx {
 namespace frontend {
@@ -62,7 +63,7 @@
  */
 class WorkArea {
 public:
-       WorkArea(BufferView * buffer_view = 0);
+       WorkArea(LyXView & lyx_view);
 
        virtual ~WorkArea() {}
 
@@ -109,11 +110,13 @@
        /// FIXME: This is public because of qt3 and gtk, should be protected
        void dispatch(FuncRequest const & cmd0);
 
-protected:
-       ///
+       /// FIXME: This is public because of qt3 and gtk, should be protected
        void resizeBufferView();
 
+       /// FIXME: This is public because of qt3 and gtk, should be protected
+       void scrollBufferView(int position);
 
+protected:
        /// hide the visible cursor, if it is visible
        void hideCursor();
 
@@ -132,6 +135,9 @@
        ///
        BufferView * buffer_view_;
 
+       ///
+       LyXView & lyx_view_;
+
 private:
        ///
        void checkAndGreyOut();

Reply via email to