]> git.lyx.org Git - features.git/commitdiff
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 20 Jun 2006 08:39:16 +0000 (08:39 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 20 Jun 2006 08:39:16 +0000 (08:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14152 a592a061-630c-0410-9148-cb99ea01b6c8

92 files changed:
development/scons/SConstruct
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/frontends/Clipboard.h [new file with mode: 0644]
src/frontends/Gui.h [new file with mode: 0644]
src/frontends/GuiCursor.C [new file with mode: 0644]
src/frontends/GuiCursor.h [new file with mode: 0644]
src/frontends/LyXScreenFactory.h [deleted file]
src/frontends/LyXView.h
src/frontends/Makefile.am
src/frontends/Painter.C
src/frontends/Painter.h
src/frontends/WorkArea.C [new file with mode: 0644]
src/frontends/WorkArea.h
src/frontends/WorkAreaFactory.h [deleted file]
src/frontends/gtk/GScreen.C
src/frontends/gtk/GScreen.h
src/frontends/gtk/GView.C
src/frontends/gtk/GView.h
src/frontends/gtk/GWorkArea.C
src/frontends/gtk/GWorkArea.h
src/frontends/gtk/GuiClipboard.h [new file with mode: 0644]
src/frontends/gtk/GuiImplementation.h [new file with mode: 0644]
src/frontends/gtk/GuiWorkArea.h [new file with mode: 0644]
src/frontends/gtk/LyXScreenFactory.C [deleted file]
src/frontends/gtk/Makefile.am
src/frontends/gtk/WorkAreaFactory.C [deleted file]
src/frontends/nullpainter.C
src/frontends/nullpainter.h
src/frontends/qt3/GuiClipboard.h [new file with mode: 0644]
src/frontends/qt3/GuiImplementation.h [new file with mode: 0644]
src/frontends/qt3/GuiWorkArea.h [new file with mode: 0644]
src/frontends/qt3/LyXScreenFactory.C [deleted file]
src/frontends/qt3/Makefile.am
src/frontends/qt3/QContentPane.C
src/frontends/qt3/QContentPane.h
src/frontends/qt3/QLPainter.C
src/frontends/qt3/QLPainter.h
src/frontends/qt3/QWorkArea.C
src/frontends/qt3/QWorkArea.h
src/frontends/qt3/QtView.C
src/frontends/qt3/QtView.h
src/frontends/qt3/WorkAreaFactory.C [deleted file]
src/frontends/qt3/qscreen.C
src/frontends/qt3/qscreen.h
src/frontends/qt3/qtTimeout.C
src/frontends/qt3/qtTimeout.h
src/frontends/qt4/GuiClipboard.h [new file with mode: 0644]
src/frontends/qt4/GuiImplementation.C [new file with mode: 0644]
src/frontends/qt4/GuiImplementation.h [new file with mode: 0644]
src/frontends/qt4/GuiWorkArea.C [new file with mode: 0644]
src/frontends/qt4/GuiWorkArea.h [new file with mode: 0644]
src/frontends/qt4/LyXScreenFactory.C [deleted file]
src/frontends/qt4/Makefile.am
src/frontends/qt4/Makefile.dialogs
src/frontends/qt4/QLPainter.C
src/frontends/qt4/QLPainter.h
src/frontends/qt4/QWorkArea.C [deleted file]
src/frontends/qt4/QWorkArea.h [deleted file]
src/frontends/qt4/QtView.C
src/frontends/qt4/QtView.h
src/frontends/qt4/WorkAreaFactory.C [deleted file]
src/frontends/qt4/lyx_gui.C
src/frontends/screen.C [deleted file]
src/frontends/screen.h [deleted file]
src/frontends/xforms/GuiClipboard.h [new file with mode: 0644]
src/frontends/xforms/GuiImplementation.h [new file with mode: 0644]
src/frontends/xforms/GuiWorkArea.h [new file with mode: 0644]
src/frontends/xforms/LyXScreenFactory.C [deleted file]
src/frontends/xforms/Makefile.am
src/frontends/xforms/WorkAreaFactory.C [deleted file]
src/frontends/xforms/XFormsView.C
src/frontends/xforms/XFormsView.h
src/frontends/xforms/XWorkArea.C
src/frontends/xforms/XWorkArea.h
src/frontends/xforms/xscreen.C
src/frontends/xforms/xscreen.h
src/insets/insetcollapsable.h
src/insets/insetline.C
src/insets/insetpagebreak.C
src/insets/insettabular.C
src/insets/insettabular.h
src/lyxtext.h
src/mathed/math_nestinset.C
src/mathed/math_support.C
src/metricsinfo.C
src/metricsinfo.h
src/rowpainter.C
src/support/lstrings.C
src/support/lstrings.h

index 6b19d5b4f934e8cdcd4a141fa566af298e8d7375..d496f40a4a5e43ec380988e8e22c3ce717aa9354 100644 (file)
@@ -1983,7 +1983,7 @@ if build_qt4:
     QtView.C
     QURLDialog.C
     QVSpaceDialog.C
-    QWorkArea.C
+    GuiWorkArea.C
     QWrapDialog.C
     QLToolbar.C
     socket_callback.C
index cbe6a33ef94acb1eb22a09c23d2499694a77b7cd..d52233651d9ef724f31f30ba5b828a06051c37c8 100644 (file)
 #include "WordLangTuple.h"
 
 #include "frontends/Alert.h"
+#include "frontends/Clipboard.h"
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
-#include "frontends/screen.h"
+#include "frontends/Gui.h"
 #include "frontends/WorkArea.h"
 
 #include "insets/insetcommand.h" // ChangeRefs
@@ -83,19 +84,13 @@ Buffer * BufferView::buffer() const
 }
 
 
-LyXScreen & BufferView::screen() const
-{
-       return pimpl_->screen();
-}
-
-
 LyXView * BufferView::owner() const
 {
        return pimpl_->owner_;
 }
 
 
-Painter & BufferView::painter() const
+lyx::frontend::Painter & BufferView::painter() const
 {
        return pimpl_->painter();
 }
@@ -200,7 +195,7 @@ void BufferView::switchKeyMap()
 
 int BufferView::workWidth() const
 {
-       return pimpl_->workarea().workWidth();
+       return pimpl_->workarea().width();
 }
 
 
@@ -212,7 +207,7 @@ void BufferView::center()
 
 string const BufferView::getClipboard() const
 {
-       return pimpl_->workarea().getClipboard();
+       return pimpl_->clipboard().get();
 }
 
 
@@ -317,7 +312,7 @@ void BufferView::gotoLabel(string const & label)
 
 void BufferView::hideCursor()
 {
-       screen().hideCursor();
+       pimpl_->gui().guiCursor().hide();
 }
 
 LyXText * BufferView::getLyXText()
@@ -338,13 +333,13 @@ LyXText const * BufferView::getLyXText() const
 
 void BufferView::haveSelection(bool sel)
 {
-       pimpl_->workarea().haveSelection(sel);
+       pimpl_->clipboard().haveSelection(sel);
 }
 
 
 int BufferView::workHeight() const
 {
-       return pimpl_->workarea().workHeight();
+       return pimpl_->workarea().height();
 }
 
 
index 1c79d7cfadcb0d6237ca15311bf137312ab1c0b0..5723cb72cd811925b704a2d8b75c755a5b02f1c7 100644 (file)
@@ -32,11 +32,14 @@ class FuncStatus;
 class Language;
 class LCursor;
 class LyXText;
-class LyXScreen;
 class LyXView;
-class Painter;
 class ParIterator;
 
+namespace lyx {
+namespace frontend {
+class Painter;
+}
+}
 
 namespace Update {
        enum flags {
@@ -83,9 +86,8 @@ public:
        Buffer * buffer() const;
 
        /// return the painter object for drawing onto the view
-       Painter & painter() const;
-       /// return the screen object for handling re-drawing
-       LyXScreen & screen() const;
+       lyx::frontend::Painter & painter() const;
+
        /// return the owning main view
        LyXView * owner() const;
 
index de0508b19d2e6c3bafc0dcd4b04d0289d8f05705..0976075911e280142a4bf151d61567d60bd7dee4 100644 (file)
 #include "insets/insettext.h"
 
 #include "frontends/Alert.h"
+#include "frontends/Clipboard.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
 #include "frontends/font_metrics.h"
+#include "frontends/Gui.h"
 #include "frontends/LyXView.h"
-#include "frontends/LyXScreenFactory.h"
-#include "frontends/screen.h"
+#include "frontends/Painter.h"
 #include "frontends/WorkArea.h"
-#include "frontends/WorkAreaFactory.h"
 
 #include "graphics/Previews.h"
 
 #include <functional>
 #include <vector>
 
+using lyx::frontend::WorkArea;
+using lyx::frontend::Clipboard;
+using lyx::frontend::Gui;
+
 using lyx::pos_type;
 
 using lyx::support::addPath;
@@ -103,7 +107,6 @@ using std::string;
 using std::mem_fun_ref;
 using std::vector;
 
-
 extern BufferList bufferlist;
 
 
@@ -142,13 +145,13 @@ BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
 {
        xsel_cache_.set = false;
 
-       workarea_.reset(WorkAreaFactory::create(*owner_, width, height));
-       screen_.reset(LyXScreenFactory::create(workarea()));
+       workAreaId_ = owner_->gui().newWorkArea(width, height);
+       workArea_ = & owner_->gui().workArea(workAreaId_);
 
        // Setup the signals
        timecon = cursor_timeout.timeout
                .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
-        
+       
        cursor_timeout.start();
         
        saved_positions.resize(saved_positions_num);
@@ -314,21 +317,27 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
 }
 
 
-WorkArea & BufferView::Pimpl::workarea() const
+lyx::frontend::Gui & BufferView::Pimpl::gui() const
+{
+       return owner_->gui();
+}
+
+
+lyx::frontend::WorkArea & BufferView::Pimpl::workarea() const
 {
-       return *workarea_.get();
+       return *workArea_;
 }
 
 
-LyXScreen & BufferView::Pimpl::screen() const
+lyx::frontend::Clipboard & BufferView::Pimpl::clipboard() const
 {
-       return *screen_.get();
+       return owner_->gui().clipboard();
 }
 
 
-Painter & BufferView::Pimpl::painter() const
+lyx::frontend::Painter & BufferView::Pimpl::painter() const
 {
-       return workarea().getPainter();
+       return workArea_->getPainter();
 }
 
 
@@ -451,7 +460,7 @@ void BufferView::Pimpl::updateScrollbar()
        if (!bv_->text()) {
                lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
                                     << " no text in updateScrollbar" << endl;
-               workarea().setScrollbarParams(0, 0, 0);
+               workArea_->setScrollbarParams(0, 0, 0);
                return;
        }
 
@@ -473,7 +482,7 @@ void BufferView::Pimpl::updateScrollbar()
 
        // estimated average paragraph height:
        if (wh_ == 0)
-               wh_ = workarea().workHeight() / 4;
+               wh_ = workArea_->height() / 4;
        int h = t.getPar(anchor_ref_).height();
 
        // Normalize anchor/offset (MV):
@@ -486,7 +495,7 @@ void BufferView::Pimpl::updateScrollbar()
        int sumh = 0;
        int nh = 0;
        for (lyx::pit_type pit = anchor_ref_; pit <= parsize; ++pit) {
-               if (sumh > workarea().workHeight())
+               if (sumh > workArea_->height())
                        break;
                int const h2 = t.getPar(pit).height();
                sumh += h2;
@@ -497,7 +506,7 @@ void BufferView::Pimpl::updateScrollbar()
        if (hav > wh_)
                wh_ = hav;
 
-       workarea().setScrollbarParams((parsize + 1) * wh_,
+       workArea_->setScrollbarParams((parsize + 1) * wh_,
                anchor_ref_ * wh_ + int(offset_ref_ * wh_ / float(h)),
                int(wh_ * defaultRowHeight() / float(h)));
 }
@@ -511,7 +520,7 @@ void BufferView::Pimpl::scrollDocView(int value)
        if (!buffer_)
                return;
 
-       screen().hideCursor();
+       owner_->gui().guiCursor().hide();
 
        LyXText & t = *bv_->text();
 
@@ -530,7 +539,7 @@ void BufferView::Pimpl::scrollDocView(int value)
 
        int const height = 2 * defaultRowHeight();
        int const first = height;
-       int const last = workarea().workHeight() - height;
+       int const last = workArea_->height() - height;
        LCursor & cur = cursor_;
 
        bv_funcs::CurStatus st = bv_funcs::status(bv_, cur);
@@ -574,7 +583,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());
 }
 
 
@@ -591,7 +600,7 @@ void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
         * dispatch() itself, because that's called recursively.
         */
        if (available())
-               screen().showCursor(*bv_);
+               owner_->gui().guiCursor().show(*bv_);
 }
 
 
@@ -618,7 +627,7 @@ void BufferView::Pimpl::selectionRequested()
                xsel_cache_.set = cur.selection();
                sel = cur.selectionAsString(false);
                if (!sel.empty())
-                       workarea().putClipboard(sel);
+                       clipboard().put(sel);
        }
 }
 
@@ -626,7 +635,7 @@ void BufferView::Pimpl::selectionRequested()
 void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
-               screen().hideCursor();
+               owner_->gui().guiCursor().hide();
                cursor_.clearSelection();
                xsel_cache_.set = false;
        }
@@ -635,15 +644,15 @@ void BufferView::Pimpl::selectionLost()
 
 void BufferView::Pimpl::workAreaResize()
 {
-       static int work_area_width;
-       static int work_area_height;
+       static int workArea_width;
+       static int workArea_height;
 
-       bool const widthChange = workarea().workWidth() != work_area_width;
-       bool const heightChange = workarea().workHeight() != work_area_height;
+       bool const widthChange = workArea_->width() != workArea_width;
+       bool const heightChange = workArea_->height() != workArea_height;
 
        // Update from work area
-       work_area_width = workarea().workWidth();
-       work_area_height = workarea().workHeight();
+       workArea_width = workArea_->width();
+       workArea_height = workArea_->height();
 
        if (buffer_ && widthChange) {
                // The visible LyXView need a resize
@@ -666,7 +675,7 @@ bool BufferView::Pimpl::fitCursor()
                int const asc = font_metrics::maxAscent(font);
                int const des = font_metrics::maxDescent(font);
                Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
-               if (p.y_ - asc >= 0 && p.y_ + des < workarea().workHeight())
+               if (p.y_ - asc >= 0 && p.y_ + des < workArea_->height())
                        return false;
        }
        center();
@@ -721,14 +730,14 @@ void BufferView::Pimpl::update(Update::flags flags)
                }
                if (forceupdate) {
                        // Second drawing step
-                       screen().redraw(*bv_, vi);
+                       workArea_->redraw(*bv_, vi);
                } else {
                        // Abort updating of the coord
                        // cache - just restore the old one
                        std::swap(theCoords, backup);
                }
        } else
-               screen().greyOut();
+               workArea_->greyOut();
 
        // And the scrollbar
        updateScrollbar();
@@ -740,7 +749,7 @@ void BufferView::Pimpl::update(Update::flags flags)
 void BufferView::Pimpl::cursorToggle()
 {
        if (buffer_) {
-               screen().toggleCursor(*bv_);
+               owner_->gui().guiCursor().toggle(*bv_);
 
                // Use this opportunity to deal with any child processes that
                // have finished but are waiting to communicate this fact
@@ -867,13 +876,13 @@ void BufferView::Pimpl::center()
        Paragraph const & par = bot.text()->paragraphs()[pit];
        anchor_ref_ = pit;
        offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
-               + par.ascent() - workarea().workHeight() / 2;
+               + par.ascent() - workArea_->height() / 2;
 }
 
 
 void BufferView::Pimpl::stuffClipboard(string const & content) const
 {
-       workarea().putClipboard(content);
+       clipboard().put(content);
 }
 
 
@@ -998,13 +1007,13 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
        if (!available())
                return false;
 
-       screen().hideCursor();
+       owner_->gui().guiCursor().hide();
 
        // Either the inset under the cursor or the
        // surrounding LyXText will handle this event.
 
        // Build temporary cursor.
-       cmd.y = min(max(cmd.y,-1), workarea().workHeight());
+       cmd.y = min(max(cmd.y, -1), workArea_->height());
        InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
        //lyxerr << BOOST_CURRENT_FUNCTION
        //       << " * hit inset at tip: " << inset << endl;
@@ -1036,7 +1045,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
 
        // See workAreaKeyPress
        cursor_timeout.restart();
-       screen().showCursor(*bv_);
+       owner_->gui().guiCursor().show(*bv_);
 
        // Skip these when selecting
        if (cmd.action != LFUN_MOUSE_MOTION) {
index 20f131c7898119848dd9becfc4bed4e29769dc00..bf66462773640890e5176e84f1d133932728db86 100644 (file)
 #include <boost/shared_ptr.hpp>
 #include <boost/signals/trackable.hpp>
 
-
 class Change;
 class LyXKeySym;
 class LyXView;
-class WorkArea;
-class LyXScreen;
+
 class FuncRequest;
 class FuncStatus;
 class ViewMetricsInfo;
 
+namespace lyx {
+namespace frontend {
+class Gui;
+class WorkArea;
+class Clipboard;
+class Painter;
+class GuiCursor;
+}
+}
+
 
 ///
 class BufferView::Pimpl : public boost::signals::trackable {
@@ -51,9 +59,7 @@ public:
        ///
        Pimpl(BufferView & bv, LyXView * owner, int width, int height);
        ///
-       Painter & painter() const;
-       /// return the screen for this bview
-       LyXScreen & screen() const;
+       lyx::frontend::Painter & painter() const;
        ///
        void setBuffer(Buffer * buf);
        ///
@@ -110,6 +116,14 @@ public:
        bool repaintAll() { return refresh_inside_; }
        ///
        void repaintAll(bool r) {refresh_inside_ = r; }
+
+       /// the frontend
+       lyx::frontend::Gui & gui() const;
+       /// our workarea
+       lyx::frontend::WorkArea & workarea() const;
+       /// the clipboard
+       lyx::frontend::Clipboard & clipboard() const;
+
 private:
        /// An error list (replaces the error insets)
        ErrorList errorlist_;
@@ -148,10 +162,7 @@ private:
        LyXView * owner_;
        ///
        Buffer * buffer_;
-       ///
-       boost::scoped_ptr<LyXScreen> screen_;
-       ///
-       boost::scoped_ptr<WorkArea> workarea_;
+
        /// Estimated average par height for scrollbar
        int wh_;
        ///
@@ -179,8 +190,10 @@ private:
        std::vector<Position> saved_positions;
        ///
        void menuInsertLyXFile(std::string const & filen);
-       /// our workarea
-       WorkArea & workarea() const;
+
+       lyx::frontend::WorkArea * workArea_;
+       int workAreaId_;
+
        /// this is used to handle XSelection events in the right manner
        struct {
                CursorSlice cursor;
diff --git a/src/frontends/Clipboard.h b/src/frontends/Clipboard.h
new file mode 100644 (file)
index 0000000..ca04642
--- /dev/null
@@ -0,0 +1,41 @@
+// -*- C++ -*-
+/**
+ * \file Clipboard.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef BASE_CLIPBOARD_H
+#define BASE_CLIPBOARD_H
+
+#include <string>
+
+namespace lyx {
+namespace frontend {
+
+/**
+ * A Clipboard class manages the clipboard.
+ */
+class Clipboard
+{
+public:
+       virtual ~Clipboard() {}
+
+       /// a selection exists
+       virtual void haveSelection(bool) = 0;
+       /// get the X clipboard contents
+       virtual std::string const get() const = 0;
+       /// fill the clipboard
+       virtual void put(std::string const &) = 0;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // BASE_CLIPBOARD_H
diff --git a/src/frontends/Gui.h b/src/frontends/Gui.h
new file mode 100644 (file)
index 0000000..2d1c9ee
--- /dev/null
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+/**
+ * \file Gui.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef BASE_GUI_H
+#define BASE_GUI_H
+
+#include "frontends/GuiCursor.h"
+
+namespace lyx {
+namespace frontend {
+
+class Clipboard;
+class WorkArea;
+
+
+/**
+ * A Gui class manages the different frontend elements.
+ */
+class Gui
+{
+public:
+       virtual ~Gui() {}
+
+       ///
+       virtual Clipboard& clipboard() = 0;
+       ///
+       virtual int newWorkArea(int w, int h) = 0;
+       ///
+       virtual WorkArea& workArea(int id) = 0;
+       ///
+       virtual void destroyWorkArea(int id) = 0;
+
+       ///
+       GuiCursor & guiCursor() {return cursor_;}
+
+private:
+       GuiCursor cursor_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // BASE_GUI_H
diff --git a/src/frontends/GuiCursor.C b/src/frontends/GuiCursor.C
new file mode 100644 (file)
index 0000000..7187c49
--- /dev/null
@@ -0,0 +1,149 @@
+/**
+ * \file GuiCursor.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Splash screen code added by Angus Leeming
+ */
+
+#include <config.h>
+
+#include "frontends/GuiCursor.h"
+
+#include "font_metrics.h"
+#include "lyx_gui.h"
+#include "frontends/Painter.h"
+#include "frontends/WorkArea.h"
+
+#include "BufferView.h"
+#include "buffer.h"
+#include "bufferparams.h"
+#include "coordcache.h"
+#include "cursor.h"
+#include "debug.h"
+#include "language.h"
+#include "LColor.h"
+#include "lyxfont.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "lyxtext.h"
+#include "metricsinfo.h"
+#include "paragraph.h"
+#include "rowpainter.h"
+#include "version.h"
+
+#include "graphics/GraphicsImage.h"
+#include "graphics/GraphicsLoader.h"
+
+#include "support/filetools.h" // LibFileSearch
+
+#include <boost/utility.hpp>
+#include <boost/bind.hpp>
+#include <boost/signals/trackable.hpp>
+
+using lyx::support::libFileSearch;
+
+using std::endl;
+using std::min;
+using std::max;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+GuiCursor::GuiCursor()
+       : cursor_visible_(false), work_area_(NULL)
+{
+}
+
+
+GuiCursor::~GuiCursor()
+{
+}
+
+void GuiCursor::connect(WorkArea * work_area)
+{
+       work_area_ = work_area;
+}
+
+
+void GuiCursor::show(BufferView & bv)
+{
+       if (cursor_visible_)
+               return;
+
+       if (!bv.available())
+               return;
+
+       Cursor_Shape shape = BAR_SHAPE;
+
+       LyXText const & text = *bv.getLyXText();
+       LyXFont const & realfont = text.real_current_font;
+       BufferParams const & bp = bv.buffer()->params();
+       bool const samelang = realfont.language() == bp.language;
+       bool const isrtl = realfont.isVisibleRightToLeft();
+
+       if (!samelang || isrtl != bp.language->rightToLeft()) {
+               shape = L_SHAPE;
+               if (isrtl)
+                       shape = REVERSED_L_SHAPE;
+       }
+
+       // The ERT language hack needs fixing up
+       if (realfont.language() == latex_language)
+               shape = BAR_SHAPE;
+
+       LyXFont const font = bv.cursor().getFont();
+       int const asc = font_metrics::maxAscent(font);
+       int const des = font_metrics::maxDescent(font);
+       int h = asc + des;
+       int x = 0;
+       int y = 0;
+       bv.cursor().getPos(x, y);
+       y -= asc;
+       //lyxerr << "Cursor::show x: " << x << " y: " << y << endl;
+
+       BOOST_ASSERT(work_area_);
+
+       // if it doesn't touch the screen, don't try to show it
+       if (y + h < 0 || y >= work_area_->height())
+               return;
+
+       cursor_visible_ = true;
+       work_area_->showCursor(x, y, h, shape);
+}
+
+
+void GuiCursor::hide()
+{
+       if (!cursor_visible_)
+               return;
+
+       cursor_visible_ = false;
+       BOOST_ASSERT(work_area_);
+       work_area_->removeCursor();
+}
+
+
+void GuiCursor::toggle(BufferView & bv)
+{
+       if (cursor_visible_)
+               hide();
+       else
+               show(bv);
+}
+
+
+void GuiCursor::prepare()
+{
+       cursor_visible_ = false;
+}
+
+} // namespace frontend
+} // namespace lyx
+
diff --git a/src/frontends/GuiCursor.h b/src/frontends/GuiCursor.h
new file mode 100644 (file)
index 0000000..cc45d8c
--- /dev/null
@@ -0,0 +1,73 @@
+// -*- C++ -*-
+/**
+ * \file GuiCursor.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUI_CURSOR_H
+#define GUI_CURSOR_H
+
+
+class LyXText;
+class CursorSlice;
+class BufferView;
+class ViewMetricsInfo;
+
+namespace lyx {
+namespace frontend {
+
+class WorkArea;
+
+/// types of cursor in work area
+enum Cursor_Shape {
+       /// normal I-beam
+       BAR_SHAPE,
+       /// L-shape for locked insets of a different language
+       L_SHAPE,
+       /// reverse L-shape for RTL text
+       REVERSED_L_SHAPE
+};
+
+/**
+ * GuiCursor - document rendering management
+ *
+ * The blinking cursor is handled here.
+ */
+class GuiCursor {
+public:
+       GuiCursor();
+
+       virtual ~GuiCursor();
+
+       void connect(WorkArea * work_area);
+
+       /// hide the visible cursor, if it is visible
+       void hide();
+
+       /// show the cursor if it is not visible
+       void show(BufferView & bv);
+
+       /// toggle the cursor's visibility
+       void toggle(BufferView & bv);
+
+       /// set cursor_visible_ to false in prep for re-display
+       void prepare();
+
+private:
+       /// is the cursor currently displayed
+       bool cursor_visible_;
+
+       WorkArea * work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUI_CURSOR_H
diff --git a/src/frontends/LyXScreenFactory.h b/src/frontends/LyXScreenFactory.h
deleted file mode 100644 (file)
index 70057d3..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// -*- C++ -*-
-/**
- * \file LyXScreenFactory.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LYXSCREENFACTORY_H
-#define LYXSCREENFACTORY_H
-
-class WorkArea;
-class LyXScreen;
-
-namespace LyXScreenFactory {
-       /**
-        * Make a screen renderer. Used because we want to
-        * generate a toolkit-specific instance.
-        */
-       LyXScreen * create(WorkArea & owner);
-}
-
-#endif // LYXSCREEN_FACTORY_H
index c43dc7118638b69930cad6f8c0a786a2dfa73ef7..29e51c1dbf103d7381b9f6460ef184192491686f 100644 (file)
@@ -33,9 +33,15 @@ class Timeout;
 class FuncRequest;
 
 namespace lyx {
+
+namespace frontend {
+class Gui;
+} // namespace frontend
+
 namespace frontend {
 class ControlCommandBuffer;
 } // namespace frontend
+
 } // namespace lyx
 
 /**
@@ -145,6 +151,8 @@ public:
        // returns true if this view has the focus.
        virtual bool hasFocus() const = 0;
 
+       virtual lyx::frontend::Gui & gui() = 0;
+
 protected:
        /// view of a buffer. Eventually there will be several.
        boost::shared_ptr<BufferView> bufferview_;
index aba90612304bf4d506d3c0117ca4c64e6ae4c1ba..eda5f688e2d3ced44ba8f333355ba84f030d4af7 100644 (file)
@@ -21,7 +21,6 @@ libfrontends_la_SOURCES = \
        FileDialog.h \
        LyXKeySym.h \
        LyXKeySymFactory.h \
-       LyXScreenFactory.h \
        LyXView.C \
        LyXView.h \
        Menubar.h \
@@ -31,8 +30,12 @@ libfrontends_la_SOURCES = \
        Timeout.h \
        Toolbars.C \
        Toolbars.h \
+       Clipboard.h \
+       Gui.h \
+       GuiCursor.C \
+       GuiCursor.h \
+       WorkArea.C \
        WorkArea.h \
-       WorkAreaFactory.h \
        font_metrics.h \
        guiapi.h \
        guiapi.C \
@@ -40,6 +43,4 @@ libfrontends_la_SOURCES = \
        lyx_gui.h \
        mouse_state.h \
        nullpainter.C \
-       nullpainter.h \
-       screen.C \
-       screen.h
+       nullpainter.h
index 9a1eab791214ebc18602cf56a66ccf2372f6c18b..a3b14ff624b0bb1606492a9809e4820f6b4e9ceb 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "Painter.h"
 #include "font_metrics.h"
-#include "WorkArea.h"
 
 #include "LColor.h"
 #include "lyxfont.h"
@@ -21,6 +20,8 @@
 using std::max;
 using std::string;
 
+namespace lyx {
+namespace frontend {
 
 void Painter::button(int x, int y, int w, int h)
 {
@@ -92,3 +93,6 @@ void Painter::underline(LyXFont const & f, int x, int y, int width)
        else
                fillRectangle(x, y + below, width, below + height, f.color());
 }
+
+} // namespace frontend
+} // namespace lyx
index 668ec4b9b89ab508dc822d0fec7eb26cf3fa6223..9680acb2e2d10205f227767029b88e9e6a0904f5 100644 (file)
@@ -26,8 +26,8 @@ namespace lyx {
 namespace graphics {
        class Image;
 }
-}
 
+namespace frontend {
 
 /**
  * Painter - A painter class to encapsulate all graphics parameters and operations
@@ -182,4 +182,7 @@ protected:
        virtual void buttonFrame(int x, int y, int w, int h);
 };
 
+} // namespace frontend
+} // namespace lyx
+
 #endif // PAINTER_H
diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C
new file mode 100644 (file)
index 0000000..9f20119
--- /dev/null
@@ -0,0 +1,187 @@
+/**
+ * \file WorkArea.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Splash screen code added by Angus Leeming
+ */
+
+#include <config.h>
+
+#include "WorkArea.h"
+
+#include "font_metrics.h"
+#include "lyx_gui.h"
+#include "Painter.h"
+
+#include "BufferView.h"
+#include "buffer.h"
+#include "bufferparams.h"
+#include "coordcache.h"
+#include "cursor.h"
+#include "debug.h"
+#include "language.h"
+#include "LColor.h"
+#include "lyxfont.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "lyxtext.h"
+#include "metricsinfo.h"
+#include "paragraph.h"
+#include "rowpainter.h"
+#include "version.h"
+
+#include "graphics/GraphicsImage.h"
+#include "graphics/GraphicsLoader.h"
+
+#include "support/filetools.h" // LibFileSearch
+
+#include <boost/utility.hpp>
+#include <boost/bind.hpp>
+#include <boost/signals/trackable.hpp>
+
+using lyx::support::libFileSearch;
+
+using std::endl;
+using std::min;
+using std::max;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+class SplashScreen : boost::noncopyable, boost::signals::trackable {
+public:
+       /// This is a singleton class. Get the instance.
+       static SplashScreen const & get();
+       ///
+       lyx::graphics::Image const * image() const { return loader_.image(); }
+       ///
+       string const & text() const { return text_; }
+       ///
+       LyXFont const & font() const { return font_; }
+       ///
+       void connect(lyx::graphics::Loader::slot_type const & slot) const {
+               loader_.connect(slot);
+       }
+       ///
+       void startLoading() const {
+               if (loader_.status() == lyx::graphics::WaitingToLoad)
+                       loader_.startLoading();
+       }
+
+private:
+       /** Make the c-tor private so we can control how many objects
+        *  are instantiated.
+        */
+       SplashScreen();
+
+       ///
+       lyx::graphics::Loader loader_;
+       /// The text to be written on top of the pixmap
+       string const text_;
+       /// in this font...
+       LyXFont font_;
+};
+
+
+SplashScreen const & SplashScreen::get()
+{
+       static SplashScreen singleton;
+       return singleton;
+}
+
+
+SplashScreen::SplashScreen()
+       : text_(lyx_version ? lyx_version : "unknown")
+{
+       if (!lyxrc.show_banner)
+               return;
+
+       string const file = libFileSearch("images", "banner", "ppm");
+       if (file.empty())
+               return;
+
+       // The font used to display the version info
+       font_.setFamily(LyXFont::SANS_FAMILY);
+       font_.setSeries(LyXFont::BOLD_SERIES);
+       font_.setSize(LyXFont::SIZE_NORMAL);
+       font_.setColor(LColor::yellow);
+
+       // Load up the graphics file
+       loader_.reset(file);
+}
+
+WorkArea::WorkArea(LyXView & owner, int w, int h)
+       : greyed_out_(true)
+{
+       // Start loading the pixmap as soon as possible
+       if (lyxrc.show_banner) {
+               SplashScreen const & splash = SplashScreen::get();
+               splash.connect(boost::bind(&WorkArea::checkAndGreyOut, this));
+               splash.startLoading();
+       }
+}
+
+
+void WorkArea::checkAndGreyOut()
+{
+       if (greyed_out_)
+               greyOut();
+}
+
+
+void WorkArea::redraw(BufferView & bv, ViewMetricsInfo const & vi)
+{
+       greyed_out_ = false;
+       getPainter().start();
+       paintText(bv, vi);
+       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);
+       getPainter().end();
+       theCoords.doneUpdating();
+}
+
+
+void WorkArea::greyOut()
+{
+       greyed_out_ = true;
+       getPainter().start();
+
+       getPainter().fillRectangle(0, 0,
+               width(),
+               height(),
+               LColor::bottomarea);
+
+       // Add a splash screen to the centre of the work area
+       SplashScreen const & splash = SplashScreen::get();
+       lyx::graphics::Image const * const splash_image = splash.image();
+       if (splash_image) {
+               int const w = splash_image->getWidth();
+               int const h = splash_image->getHeight();
+
+               int x = (width() - w) / 2;
+               int y = (height() - h) / 2;
+
+               getPainter().image(x, y, w, h, *splash_image);
+
+               x += 260;
+               y += 265;
+
+               getPainter().text(x, y, splash.text(), splash.font());
+       }
+       expose(0, 0, width(), height());
+       getPainter().end();
+}
+
+} // namespace frontend
+} // namespace lyx
index f48dbd0403102f3d8b23ca14e9d4229ebc5d1840..b3ee602e57ff0982cc114d2d1ea47330effecf1a 100644 (file)
@@ -6,32 +6,39 @@
  *
  * \author unknown
  * \author John Levon
+ * \author Abdelrazak Younes
  *
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef WORKAREA_H
-#define WORKAREA_H
+#ifndef BASE_WORKAREA_H
+#define BASE_WORKAREA_H
+
+#include "frontends/GuiCursor.h"
 
 #include "frontends/key_state.h"
 #include "frontends/LyXKeySym.h"
 
-#include <boost/signal.hpp>
+class LyXView;
+class FuncRequest;
+class BufferView;
+class ViewMetricsInfo;
 
+namespace lyx {
+namespace frontend {
 
 class Painter;
-class FuncRequest;
 
 /**
  * The work area class represents the widget that provides the
  * view onto a document. It is owned by the BufferView, and
  * is responsible for handing events back to its owning BufferView.
- * It works in concert with the LyXScreen class to update the
+ * It works in concert with the BaseScreen class to update the
  * widget view of a document.
  */
 class WorkArea {
 public:
-       WorkArea() {}
+       WorkArea(LyXView & owner, int w, int h);
 
        virtual ~WorkArea() {}
 
@@ -39,9 +46,10 @@ public:
        virtual Painter & getPainter() = 0;
 
        /// return the width of the work area in pixels
-       virtual int workWidth() const = 0;
+       virtual int width() const = 0;
+
        /// return the height of the work area in pixels
-       virtual int workHeight() const = 0;
+       virtual int height() const = 0;
 
        /**
         * Update the scrollbar.
@@ -51,13 +59,31 @@ public:
         */
        virtual void setScrollbarParams(int height, int pos, int line_height) = 0;
 
-       // FIXME: this is an odd place to have it, but xforms needs it here ...
-       /// a selection exists
-       virtual void haveSelection(bool) const = 0;
-       /// get the X clipboard contents
-       virtual std::string const getClipboard() const = 0;
-       /// fill the clipboard
-       virtual void putClipboard(std::string const &) const = 0;
+       /// redraw the screen, without using existing pixmap
+       virtual void redraw(BufferView & bv, ViewMetricsInfo const & vi);
+
+       /// grey out (no buffer)
+       void greyOut();
+
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape) = 0;
+
+       /// 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;
+
+private:
+       ///
+       void checkAndGreyOut();
+
+       ///
+       bool greyed_out_;
 };
 
-#endif // WORKAREA_H
+} // namespace frontend
+} // namespace lyx
+
+#endif // BASE_WORKAREA_H
diff --git a/src/frontends/WorkAreaFactory.h b/src/frontends/WorkAreaFactory.h
deleted file mode 100644 (file)
index ca679bf..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// -*- C++ -*-
-/**
- * \file WorkAreaFactory.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef WORKAREAFACTORY_H
-#define WORKAREAFACTORY_H
-
-class WorkArea;
-class LyXView;
-
-namespace WorkAreaFactory {
-       /**
-        * Make a work area. Used because we want to generate
-        * a toolkit-specific instance.
-        */
-       WorkArea * create(LyXView & owner, int w, int h);
-}
-
-#endif // WORKAREA_FACTORY_H
index ee711bba9ccf6e6247cdf3822c2d126f053ee765..2014e734630c9571317ebdd10d80e20e540132a9 100644 (file)
 #include "lyxtext.h"
 #include "lyxrow.h"
 
-#include "frontends/screen.h"
 #include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
-#include "frontends/WorkArea.h"
 
 #include "insets/insettext.h"
 
@@ -43,7 +41,7 @@ namespace lyx {
 namespace frontend {
 
 GScreen::GScreen(GWorkArea & o)
-       : LyXScreen(), owner_(o)
+       : owner_(o)
 {
        // the cursor isnt yet visible
        cursorX_ = 0;
@@ -58,12 +56,6 @@ GScreen::~GScreen()
 }
 
 
-WorkArea & GScreen::workarea()
-{
-       return owner_;
-}
-
-
 void GScreen::setCursorColor(Glib::RefPtr<Gdk::GC> gc)
 {
        Gdk::Color * clr = owner_.getColorHandler().
index baaea7e3f5d85334c17c15d1b4ba9a49ce6b0c7c..8e9a1694548b5036fa61b25235530292059d77c9 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef GSCREEN_H
 #define GSCREEN_H
 
-#include "screen.h"
+#include "frontends/GuiCursor.h"
 
 #include <gtkmm.h>
 
@@ -26,7 +26,7 @@ class GWorkArea;
     date and used to optimize drawing on the screen.
     This class also handles the drawing of the cursor and partly the selection.
  */
-class GScreen : public LyXScreen {
+class GScreen {
 public:
        ///
        GScreen(GWorkArea &);
@@ -40,9 +40,6 @@ public:
        virtual void removeCursor();
        ///
        virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
-protected:
-       /// get the work area
-       virtual WorkArea & workarea();
 
        /// Copies specified area of pixmap to screen
        virtual void expose(int x, int y, int w, int h);
index d3a29ec16ec601bbf02708a7990d6a17307d6373..f07b198315b58011386f471551b00c4237f03364 100644 (file)
@@ -57,7 +57,7 @@ void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink)
 } // namespace anon
 
 
-GView::GView()
+GView::GView() : frontend_(*this)
 {
        // The physical store for the boxes making up the layout.
        box_store_.push_back(BoxPtr(new Gtk::VBox));
index 2b74894cb1b9a512a7116918c87a427673017dd7..cc796a66f3772cbc1f44b3abfe179635df88549a 100644 (file)
 #ifndef GVIEW_H
 #define GVIEW_H
 
-#include "frontends/LyXView.h"
 #include "bufferview_funcs.h"
 
+#include "frontends/LyXView.h"
+
+#include "GuiImplementation.h"
+
 #include <gtkmm.h>
 
 #include <map>
@@ -55,6 +58,9 @@ public:
        // returns true if this view has the focus.
        virtual bool hasFocus() const;
 
+       ///
+       Gui & gui() { return frontend_; }
+
 private:
        void showViewState();
        bool onFocusIn(GdkEventFocus * event);
@@ -73,6 +79,8 @@ private:
 
        boost::scoped_ptr<GMiniBuffer> minibuffer_;
        Gtk::Widget * workArea_;
+       ///
+       GuiImplementation frontend_;
 };
 
 } // namespace frontend
index 5cdae14731132761e5502e9bc753a2e103fa315c..0b39199cb56b5a98dadcb223ee9fbb2c5afc6bdc 100644 (file)
@@ -504,7 +504,7 @@ void GWorkArea::onClipboardClear()
 }
 
 
-void GWorkArea::haveSelection(bool toHave) const
+void GWorkArea::haveSelection(bool toHave)
 {
        if (toHave) {
                Glib::RefPtr<Gtk::Clipboard> clipboard =
@@ -533,7 +533,7 @@ string const GWorkArea::getClipboard() const
 
 // ENCODING: we assume that the backend passes us ISO-8859-1 and
 // convert from that to UTF-8 before passing to GTK
-void GWorkArea::putClipboard(string const & str) const
+void GWorkArea::putClipboard(string const & str)
 {
        Glib::RefPtr<Gtk::Clipboard> clipboard =
                Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
index b7f447f11b43f463ba545c7009b2e1a9b5e60bf5..eea296c85d6877e40766f921f6ab983664267103 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "GPainter.h"
 
-#include "frontends/WorkArea.h"
+#include <boost/shared_ptr.hpp>
 
 #include <gtkmm.h>
 #include <gtk/gtk.h>
@@ -55,7 +55,7 @@ private:
 };
 
 
-class GWorkArea : public WorkArea, public sigc::trackable {
+class GWorkArea : public sigc::trackable {
 public:
        GWorkArea(LyXView & owner, int width, int height);
        ~GWorkArea();
@@ -80,11 +80,11 @@ public:
 
        virtual void setScrollbarParams(int height, int pos, int line_height);
        /// a selection exists
-       virtual void haveSelection(bool) const;
+       virtual void haveSelection(bool);
        ///
        virtual std::string const getClipboard() const;
        ///
-       virtual void putClipboard(std::string const &) const;
+       virtual void putClipboard(std::string const &);
        void inputCommit(gchar * str);
 private:
        bool onExpose(GdkEventExpose * event);
diff --git a/src/frontends/gtk/GuiClipboard.h b/src/frontends/gtk/GuiClipboard.h
new file mode 100644 (file)
index 0000000..f8bff11
--- /dev/null
@@ -0,0 +1,63 @@
+// -*- C++ -*-
+/**
+ * \file gtk/Clipboard.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CLIPBOARD_H
+#define CLIPBOARD_H
+
+#include "frontends/Clipboard.h"
+
+#include "GWorkArea.h"
+
+namespace lyx {
+namespace frontend {
+
+typedef GWorkArea FWorkArea;
+
+/**
+ * The GTK version of the Clipboard.
+ */
+class GuiClipboard: public lyx::frontend::Clipboard
+{
+public:
+       GuiClipboard(FWorkArea * work_area)
+               : old_work_area_(work_area)
+       {
+       }
+
+       virtual ~GuiClipboard() {}
+
+       /** ClipBoard overloaded methods
+        */
+       //@{
+       void haveSelection(bool own)
+       {
+               old_work_area_->haveSelection(own);
+       }
+
+       std::string const get() const
+       {
+               return old_work_area_->getClipboard();
+       }
+
+       void put(std::string const & str)
+       {
+               old_work_area_->putClipboard(str);
+       }
+       //@}
+
+private:
+       FWorkArea * old_work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // CLIPBOARD_H
diff --git a/src/frontends/gtk/GuiImplementation.h b/src/frontends/gtk/GuiImplementation.h
new file mode 100644 (file)
index 0000000..6f603a6
--- /dev/null
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+/**
+ * \file gtk/GuiImplementation.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUI_IMPLEMENTATION_H
+#define GUI_IMPLEMENTATION_H
+
+#include "frontends/Gui.h"
+#include "frontends/LyXView.h"
+
+#include "GScreen.h"
+#include "GWorkArea.h"
+
+#include "GuiClipboard.h"
+#include "GuiWorkArea.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include <map>
+
+namespace lyx {
+namespace frontend {
+
+typedef GScreen FScreen;
+typedef GWorkArea FWorkArea;
+
+/**
+ * The Gui class is the interface to all GTK components.
+ */
+class GuiImplementation: public lyx::frontend::Gui
+{
+public:
+       GuiImplementation(LyXView & owner): owner_(owner)
+       {
+       }
+
+       virtual ~GuiImplementation()
+       {
+       }
+
+       lyx::frontend::Clipboard& clipboard()
+       {
+               return *clipboard_;
+       }
+
+       int newWorkArea(int w, int h)
+       {
+               old_work_area_.reset(new FWorkArea(owner_, w, h));
+               old_screen_.reset(new FScreen(*old_work_area_.get()));
+               work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get()));
+               clipboard_.reset(new GuiClipboard(old_work_area_.get()));
+               guiCursor().connect(work_area_.get());
+       }
+
+       lyx::frontend::WorkArea& workArea(int id)
+       {
+               return *work_area_;
+       }
+
+       void destroyWorkArea(int id)
+       {
+               clipboard_.reset();
+               work_area_.reset();
+               old_work_area_.reset();
+               old_screen_.reset();
+       }
+
+private:
+       ///
+       boost::shared_ptr<GuiClipboard> clipboard_;
+       ///
+       boost::shared_ptr<GuiWorkArea> work_area_;
+       ///
+       boost::shared_ptr<FWorkArea> old_work_area_;
+       ///
+       boost::shared_ptr<FScreen> old_screen_;
+       ///
+       LyXView & owner_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUI_IMPLEMENTATION_H
diff --git a/src/frontends/gtk/GuiWorkArea.h b/src/frontends/gtk/GuiWorkArea.h
new file mode 100644 (file)
index 0000000..8e6ca04
--- /dev/null
@@ -0,0 +1,98 @@
+// -*- C++ -*-
+/**
+ * \file gtk/WorkArea.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef WORKAREA_H
+#define WORKAREA_H
+
+#include "frontends/WorkArea.h"
+
+#include "GScreen.h"
+#include "GWorkArea.h"
+
+namespace lyx {
+namespace frontend {
+
+typedef GScreen FScreen;
+typedef GWorkArea FWorkArea;
+
+/**
+ * Temporary wrapper around GWorkArea and GScreen.
+ * Please refer to the Qt4 implementation for a proper cleanup of the API.
+ */
+class GuiWorkArea: public lyx::frontend::WorkArea {
+public:
+       GuiWorkArea(LyXView & owner, int w, int h,
+               FScreen * screen, FWorkArea * work_area)
+               : lyx::frontend::WorkArea(owner, w, h),
+               old_screen_(screen), old_work_area_(work_area)
+       {
+       }
+
+       ~GuiWorkArea() {}
+
+       /// return the painter object for this work area
+       virtual lyx::frontend::Painter & getPainter()
+       {
+               return old_work_area_->getPainter();
+       }
+
+       /// return the width of the work area in pixels
+       virtual int width() const
+       {
+               return old_work_area_->workWidth();
+       }
+
+       /// return the height of the work area in pixels
+       virtual int height() const
+       {
+               return old_work_area_->workHeight();
+       }
+
+       /**
+        * Update the scrollbar.
+        * @param height the total document height in pixels
+        * @param pos the current position in the document, in pixels
+        * @param line_height the line-scroll amount, in pixels
+        */
+       virtual void setScrollbarParams(int height, int pos, int line_height)
+       {
+               old_work_area_->setScrollbarParams(height, pos, line_height);
+       }
+
+
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape)
+       {
+               old_screen_->showCursor(x, y, h, shape);
+       }
+
+       /// hide the cursor
+       virtual void removeCursor()
+       {
+               old_screen_->removeCursor();
+       }
+
+protected:
+       /// cause the display of the given area of the work area
+       virtual void expose(int x, int y, int w, int h)
+       {
+               old_screen_->expose(x, y, w, h);
+       }
+
+private:
+       FScreen * old_screen_;
+       FWorkArea * old_work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // WORKAREA_H
diff --git a/src/frontends/gtk/LyXScreenFactory.C b/src/frontends/gtk/LyXScreenFactory.C
deleted file mode 100644 (file)
index 61eb1d9..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * \file gtk/LyXScreenFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Huang Ying
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-// Too hard to make concept checks work with this file
-#ifdef _GLIBCXX_CONCEPT_CHECKS
-#undef _GLIBCXX_CONCEPT_CHECKS
-#endif
-#ifdef _GLIBCPP_CONCEPT_CHECKS
-#undef _GLIBCPP_CONCEPT_CHECKS
-#endif
-
-#include "GWorkArea.h"
-#include "GScreen.h"
-
-#include "frontends/LyXScreenFactory.h"
-
-namespace LyXScreenFactory {
-
-
-LyXScreen * create(WorkArea & owner)
-{
-       using lyx::frontend::GScreen;
-       using lyx::frontend::GWorkArea;
-
-       return new GScreen(static_cast<GWorkArea &>(owner));
-}
-
-
-}
index b1a708df6ea0d785c7a2384bdecee7ab94ff8304..2ad37f86c50e81c203b7efe08eb60ee4a894436b 100644 (file)
@@ -111,6 +111,8 @@ libgtk_la_SOURCES = \
        GToolbar.h \
        GUrl.C \
        GUrl.h \
+       GuiClipboard.h \
+       GuiWorkArea.h \
        GView.C \
        GView.h \
        GViewBase.C \
@@ -133,10 +135,9 @@ libgtk_la_SOURCES = \
        LyXGdkImage.C \
        LyXGdkImage.h \
        LyXKeySymFactory.C \
-       LyXScreenFactory.C \
-       WorkAreaFactory.C \
        ghelpers.C \
        ghelpers.h \
+       GuiImplementation.h \
        io_callback.C \
        io_callback.h \
        lyx_gui.C \
diff --git a/src/frontends/gtk/WorkAreaFactory.C b/src/frontends/gtk/WorkAreaFactory.C
deleted file mode 100644 (file)
index 18c8207..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * \file gtk/WorkAreaFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Huang Ying
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-// Too hard to make concept checks work with this file
-#ifdef _GLIBCXX_CONCEPT_CHECKS
-#undef _GLIBCXX_CONCEPT_CHECKS
-#endif
-#ifdef _GLIBCPP_CONCEPT_CHECKS
-#undef _GLIBCPP_CONCEPT_CHECKS
-#endif
-
-#include "GWorkArea.h"
-
-#include "frontends/WorkAreaFactory.h"
-
-#include <gtkmm.h>
-
-
-namespace WorkAreaFactory {
-
-
-WorkArea * create(LyXView & owner, int w, int h)
-{
-       return new lyx::frontend::GWorkArea(owner, w, h);
-}
-
-
-}
index 19b2bd286d161fc4717c8c65d02978f077fa21dc..085cd821170622facf5f13ac66339b4853653e38 100644 (file)
 #include <limits>
 
 
+namespace lyx {
+namespace frontend {
+
 int NullPainter::paperHeight() const
 {
        return std::numeric_limits<int>::max();
 }
+
+} // namespace frontend
+} // namespace lyx
index 24c33cf6e3400182f4aee2e3d5e112ad4af64f5e..6dc5629d89e8530ee60afa498fbc58d5d426313d 100644 (file)
 #include "LColor.h"
 #include "Painter.h"
 
+
+namespace lyx {
+namespace frontend {
+
 class NullPainter : public Painter {
 public:
        ///
@@ -71,4 +75,7 @@ public:
        void buttonFrame(int, int, int, int) {}
 };
 
+} // namespace frontend
+} // namespace lyx
+
 #endif // NULLPAINTER_H
diff --git a/src/frontends/qt3/GuiClipboard.h b/src/frontends/qt3/GuiClipboard.h
new file mode 100644 (file)
index 0000000..2323f83
--- /dev/null
@@ -0,0 +1,63 @@
+// -*- C++ -*-
+/**
+ * \file qt3/GuiClipboard.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CLIPBOARD_H
+#define CLIPBOARD_H
+
+#include "frontends/Clipboard.h"
+
+#include "QWorkArea.h"
+
+namespace lyx {
+namespace frontend {
+
+typedef QWorkArea FWorkArea;
+
+/**
+ * The Qt3 version of the Clipboard.
+ */
+class GuiClipboard: public lyx::frontend::Clipboard
+{
+public:
+       GuiClipboard(FWorkArea * work_area)
+               : old_work_area_(work_area)
+       {
+       }
+
+       virtual ~GuiClipboard() {}
+
+       /** ClipBoard overloaded methods
+        */
+       //@{
+       void haveSelection(bool own)
+       {
+               old_work_area_->haveSelection(own);
+       }
+
+       std::string const get() const
+       {
+               return old_work_area_->getClipboard();
+       }
+
+       void put(std::string const & str)
+       {
+               old_work_area_->putClipboard(str);
+       }
+       //@}
+
+private:
+       FWorkArea * old_work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // CLIPBOARD_H
diff --git a/src/frontends/qt3/GuiImplementation.h b/src/frontends/qt3/GuiImplementation.h
new file mode 100644 (file)
index 0000000..199df59
--- /dev/null
@@ -0,0 +1,89 @@
+// -*- C++ -*-
+/**
+ * \file qt3/Gui.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUI_IMPLEMENTATION_H
+#define GUI_IMPLEMENTATION_H
+
+#include "frontends/Gui.h"
+#include "frontends/LyXView.h"
+
+#include "qscreen.h"
+#include "QWorkArea.h"
+
+#include "GuiClipboard.h"
+#include "GuiWorkArea.h"
+
+#include <boost/shared_ptr.hpp>
+
+namespace lyx {
+namespace frontend {
+
+typedef QScreen FScreen;
+typedef QWorkArea FWorkArea;
+
+/**
+ * The Gui class is the interface to all Qt3 components.
+ */
+class GuiImplementation: public lyx::frontend::Gui
+{
+public:
+       GuiImplementation(LyXView & owner): owner_(owner)
+       {
+       }
+
+       virtual ~GuiImplementation()
+       {
+       }
+
+       lyx::frontend::Clipboard& clipboard()
+       {
+               return *clipboard_;
+       }
+
+       int newWorkArea(int w, int h)
+       {
+               old_work_area_.reset(new FWorkArea(owner_, w, h));
+               old_screen_.reset(new FScreen(*old_work_area_.get()));
+               work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get()));
+               clipboard_.reset(new GuiClipboard(old_work_area_.get()));
+               guiCursor().connect(work_area_.get());
+       }
+
+       lyx::frontend::WorkArea& workArea(int id)
+       {
+               return *work_area_;
+       }
+
+       void destroyWorkArea(int id)
+       {
+               clipboard_.reset();
+               work_area_.reset();
+               old_work_area_.reset();
+               old_screen_.reset();
+       }
+
+private:
+       ///
+       boost::shared_ptr<GuiClipboard> clipboard_;
+       ///
+       boost::shared_ptr<GuiWorkArea> work_area_;
+       ///
+       boost::shared_ptr<FWorkArea> old_work_area_;
+       ///
+       boost::shared_ptr<FScreen> old_screen_;
+       ///
+       LyXView & owner_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUI_IMPLEMENTATION_H
diff --git a/src/frontends/qt3/GuiWorkArea.h b/src/frontends/qt3/GuiWorkArea.h
new file mode 100644 (file)
index 0000000..bdf3fc8
--- /dev/null
@@ -0,0 +1,98 @@
+// -*- C++ -*-
+/**
+ * \file qt3/WorkArea.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef WORKAREA_H
+#define WORKAREA_H
+
+#include "frontends/WorkArea.h"
+
+#include "qscreen.h"
+#include "QWorkArea.h"
+
+namespace lyx {
+namespace frontend {
+
+typedef QScreen FScreen;
+typedef QWorkArea FWorkArea;
+
+/**
+ * Temporary wrapper around QWorkArea and QScreen.
+ * Please refer to the Qt4 implementation for a proper cleanup of the API.
+ */
+class GuiWorkArea: public lyx::frontend::WorkArea {
+public:
+       GuiWorkArea(LyXView & owner, int w, int h,
+               FScreen * screen, FWorkArea * work_area)
+               : lyx::frontend::WorkArea(owner, w, h),
+               old_screen_(screen), old_work_area_(work_area)
+       {
+       }
+
+       ~GuiWorkArea() {}
+
+       /// return the painter object for this work area
+       virtual lyx::frontend::Painter & getPainter()
+       {
+               return old_work_area_->getPainter();
+       }
+
+       /// return the width of the work area in pixels
+       virtual int width() const
+       {
+               return old_work_area_->workWidth();
+       }
+
+       /// return the height of the work area in pixels
+       virtual int height() const
+       {
+               return old_work_area_->workHeight();
+       }
+
+       /**
+        * Update the scrollbar.
+        * @param height the total document height in pixels
+        * @param pos the current position in the document, in pixels
+        * @param line_height the line-scroll amount, in pixels
+        */
+       virtual void setScrollbarParams(int height, int pos, int line_height)
+       {
+               old_work_area_->setScrollbarParams(height, pos, line_height);
+       }
+
+
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape)
+       {
+               old_screen_->showCursor(x, y, h, shape);
+       }
+
+       /// hide the cursor
+       virtual void removeCursor()
+       {
+               old_screen_->removeCursor();
+       }
+
+protected:
+       /// cause the display of the given area of the work area
+       virtual void expose(int x, int y, int w, int h)
+       {
+               old_screen_->expose(x, y, w, h);
+       }
+
+private:
+       FScreen * old_screen_;
+       FWorkArea * old_work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // WORKAREA_H
diff --git a/src/frontends/qt3/LyXScreenFactory.C b/src/frontends/qt3/LyXScreenFactory.C
deleted file mode 100644 (file)
index be794cc..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * \file qt3/LyXScreenFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/LyXScreenFactory.h"
-
-#include "QWorkArea.h"
-#include "qscreen.h"
-
-namespace LyXScreenFactory {
-
-LyXScreen * create(WorkArea & owner)
-{
-       return new QScreen(static_cast<QWorkArea &>(owner));
-}
-
-} // namespace LyXScreenFactory
index adf2c281ece0c13cfc51bff917b018a34f3b0e9e..abaf567d01df2e49ec278046df6e8ab4c6f8a2b6 100644 (file)
@@ -27,8 +27,10 @@ libqt3_la_SOURCES = \
        Alert_pimpl.C \
        Dialogs.C \
        FileDialog.C \
+       GuiClipboard.h \
+       GuiImplementation.h \
+       GuiWorkArea.h \
        LyXKeySymFactory.C \
-       LyXScreenFactory.C \
        QLMenubar.C QLMenubar.h \
        qtTimeout.C qtTimeout.h \
        QAbout.C QAbout.h \
@@ -73,7 +75,6 @@ libqt3_la_SOURCES = \
        QWrap.C QWrap.h \
        Qt2BC.C Qt2BC.h \
        QtLyXView.h \
-       WorkAreaFactory.C \
        checkedwidgets.C checkedwidgets.h \
        lyx_gui.C \
        lcolorcache.h lcolorcache.C \
index fbd9362c946d280dd60d3859b71f40063a508a61..a9b16162edf2297b512a3105c12ca8a3ee4cc31b 100644 (file)
@@ -78,6 +78,9 @@ mouse_button::state q_motion_state(Qt::ButtonState state)
 } // namespace anon
 
 
+namespace lyx {
+namespace frontend {
+
 // This is a 'heartbeat' generating synthetic mouse move events when the
 // cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
 SyntheticMouseEvent::SyntheticMouseEvent()
@@ -358,3 +361,6 @@ void QContentPane::trackScrollbar(bool track_on)
 {
        track_scrollbar_ = track_on;
 }
+
+} // namespace frontend
+} // namespace lyx
index 65a02b7bbe8bf0dd4c8d69c4a23c700d56316b00..89a872138b5f3b116f69fb7bb79162687d42d84b 100644 (file)
 #ifndef QCONTENTPANE_H
 #define QCONTENTPANE_H
 
+#include "funcrequest.h"
 #ifdef emit
 #undef emit
-#endif
-
-#include "funcrequest.h"
 #include "frontends/Timeout.h"
+#define emit
+#else
+#include "frontends/Timeout.h"
+#endif
 
 #include <qwidget.h>
 #include <qpixmap.h>
@@ -31,7 +33,6 @@
 #define USE_INPUT_METHODS 1
 #endif
 
-class QWorkArea;
 
 /// for emulating triple click
 class double_click {
@@ -55,6 +56,11 @@ public:
 };
 
 
+namespace lyx {
+namespace frontend {
+
+class QWorkArea;
+
 /** Qt only emits mouse events when the mouse is being moved, but
  *  we want to generate 'pseudo' mouse events when the mouse button is
  *  pressed and the mouse cursor is below the bottom, or above the top
@@ -139,4 +145,7 @@ private:
        double_click dc_event_;
 };
 
+} // namespace frontend
+} // namespace lyx
+
 #endif // QCONTENTPANE_H
index 2b9f73dbea36f26391ac10c46cb7b59405b80c5e..4b15ad53d21839a84e7ed012fa285d6795f82251 100644 (file)
@@ -28,6 +28,8 @@
 using std::endl;
 using std::string;
 
+namespace lyx {
+namespace frontend {
 
 QLPainter::QLPainter(QWorkArea & qwa)
        : Painter(), owner_(qwa), paint_check_(0)
@@ -248,3 +250,7 @@ void QLPainter::text(int x, int y, char const * s, size_t ls,
                underline(f, x, y, font_metrics::width(s, ls, f));
        }
 }
+
+} // namespace frontend
+} // namespace lyx
+
index fbe710fe8eef809272203b6c1c6beb739fcd268e..fad5060cd9bc3093da3127aae4daeaac45f554a8 100644 (file)
 #ifndef QLPAINTER_H
 #define QLPAINTER_H
 
-#include "Painter.h"
+#include "frontends/Painter.h"
 
 #include <boost/scoped_ptr.hpp>
 
+
 class LyXFont;
-class QWorkArea;
 class QPainter;
 class QString;
 
+namespace lyx {
+namespace frontend {
+
+class QWorkArea;
+
 /**
  * QLPainter - a painter implementation for Xlib
  */
-class QLPainter : public Painter {
+class QLPainter : public lyx::frontend::Painter {
 public:
        QLPainter(QWorkArea &);
 
@@ -133,4 +138,7 @@ private:
        int paint_check_;
 };
 
+} // namespace frontend
+} // namespace lyx
+
 #endif // QLPAINTER_H
index 3a00893a178a3d7e1da609539728a199cdd7fd58..b16075f7e2e9d567100babbb0b80746433cc5842 100644 (file)
 #include <Carbon/Carbon.h>
 #endif
 
-#ifdef Q_OS_MAC
 #include <support/lstrings.h>
 
-using lyx::support::subst;
-#endif
+using lyx::support::internalLineEnding;
+using lyx::support::externalLineEnding;
 using std::endl;
 using std::string;
 
 namespace os = lyx::support::os;
 
 namespace {
-QWorkArea * wa_ptr = 0;
+lyx::frontend::QWorkArea * wa_ptr = 0;
 }
 
+namespace lyx {
+namespace frontend {
+
 QWorkArea::QWorkArea(LyXView & owner, int, int)
-        : WorkArea(), QWidget(qApp->mainWidget()), owner_(owner), painter_(*this)
+        : QWidget(qApp->mainWidget()), owner_(owner), painter_(*this)
 {
        scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
        content_ = new QContentPane(this);
@@ -99,6 +101,10 @@ void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
        scrollbar_->setPageStep(height());
 }
 
+} // namespace frontend
+} // namespace lyx
+
+
 #ifdef Q_WS_X11
 bool lyxX11EventFilter(XEvent * xev)
 {
@@ -184,7 +190,11 @@ pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
 }
 #endif  // Q_WS_MACX
 
-void QWorkArea::haveSelection(bool own) const
+
+namespace lyx {
+namespace frontend {
+
+void QWorkArea::haveSelection(bool own)
 {
        wa_ptr = const_cast<QWorkArea*>(this);
 
@@ -206,24 +216,14 @@ string const QWorkArea::getClipboard() const
        QString str = QApplication::clipboard()->text();
        if (str.isNull())
                return string();
-#ifdef Q_OS_MAC
-       // The MAC clipboard uses \r for lineendings, and we use \n
-       return subst(fromqstr(str), '\r', '\n');
-#else
-       return fromqstr(str);
-#endif
+       return internalLineEnding(fromqstr(str));
 }
 
 
-void QWorkArea::putClipboard(string const & str) const
+void QWorkArea::putClipboard(string const & str)
 {
        QApplication::clipboard()->setSelectionMode(true);
-#ifdef Q_OS_MAC
-       // The MAC clipboard uses \r for lineendings, and we use \n
-       QApplication::clipboard()->setText(toqstr(subst(str, '\n', '\r')));
-#else
-       QApplication::clipboard()->setText(toqstr(str));
-#endif
+       QApplication::clipboard()->setText(toqstr(externalLineEnding(str)));
 }
 
 
@@ -247,3 +247,6 @@ void QWorkArea::dropEvent(QDropEvent * event)
                }
        }
 }
+
+} // namespace frontend
+} // namespace lyx
index caaada90c28b5ee30eaa71190a027c152bc109fb..84affb94295e5c1178e690aef1f3e0219d3a0065 100644 (file)
@@ -13,7 +13,6 @@
 #ifndef QWORKAREA_H
 #define QWORKAREA_H
 
-#include "WorkArea.h"
 #include "QLPainter.h"
 #include "QContentPane.h"
 
@@ -23,6 +22,9 @@ class LyXView;
 class QPixmap;
 class QWidget;
 
+namespace lyx {
+namespace frontend {
+
 
 /**
  * Qt-specific implementation of the work area
@@ -31,7 +33,7 @@ class QWidget;
  * It consists of a content pane widget, and a scrollbar.
  * Hopefully soon we can just use QScrollView ...
  */
-class QWorkArea : public WorkArea, public QWidget {
+class QWorkArea : public QWidget {
 public:
        friend class QContentPane;
 
@@ -39,7 +41,7 @@ public:
 
        virtual ~QWorkArea();
        /// return this widget's painter
-       virtual Painter & getPainter() { return painter_; }
+       virtual lyx::frontend::Painter & getPainter() { return painter_; }
        /// return the width of the content pane
        virtual int workWidth() const { return content_->width(); }
        /// return the height of the content pane
@@ -48,11 +50,11 @@ public:
        virtual void setScrollbarParams(int height, int pos, int line_height);
 
        /// a selection exists
-       virtual void haveSelection(bool) const;
+       virtual void haveSelection(bool);
        ///
        virtual std::string const getClipboard() const;
        ///
-       virtual void putClipboard(std::string const &) const;
+       virtual void putClipboard(std::string const &);
        ///
        virtual void dragEnterEvent(QDragEnterEvent * event);
        ///
@@ -81,4 +83,8 @@ private:
        QLPainter painter_;
 };
 
+
+} // namespace frontend
+} // namespace lyx
+
 #endif // QWORKAREA_H
index 503cfb440c85c99897388a7b54ccbb69e96765cf..1e1bab55405fcf7cae79cf32ab98d36a577edb6d 100644 (file)
@@ -56,7 +56,7 @@ int const statusbar_timer_value = 3000;
 
 
 QtView::QtView(unsigned int width, unsigned int height)
-       : QMainWindow(), LyXView(), commandbuffer_(0)
+       : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
 {
        resize(width, height);
 
index 35737fa4752ea9807272d7c05769d44d32418328..29cf568f5d796c51400d30e9e28598240b318290 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "frontends/LyXView.h"
 
+#include "GuiImplementation.h"
+
 #include <qmainwindow.h>
 #include <qtimer.h>
 
@@ -62,6 +64,9 @@ public:
        // returns true if this view has the focus.
        virtual bool hasFocus() const;
 
+       //
+       lyx::frontend::Gui & gui() { return frontend_; }
+
 public slots:
        /// idle timeout
        void update_view_state_qt();
@@ -86,6 +91,9 @@ private:
 
        /// command buffer
        QCommandBuffer * commandbuffer_;
+       
+       ///
+       GuiImplementation frontend_;
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt3/WorkAreaFactory.C b/src/frontends/qt3/WorkAreaFactory.C
deleted file mode 100644 (file)
index 054fee2..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * \file qt3/WorkAreaFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/WorkAreaFactory.h"
-#include "QWorkArea.h"
-
-namespace WorkAreaFactory {
-
-WorkArea * create(LyXView & owner, int w, int h)
-{
-       return new QWorkArea(owner, w, h);
-}
-
-} // namespace WorkAreaFactory
index 5b5ab545dceae84869dc4fa0df948bb2a2c52b2b..ba4cf89deaaf22cb9632e0a28ae1c6e5a1f7b9d9 100644 (file)
@@ -30,9 +30,11 @@ void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
 
 } // namespace anon
 
+namespace lyx {
+namespace frontend {
 
 QScreen::QScreen(QWorkArea & o)
-       : LyXScreen(), owner_(o)
+       : owner_(o)
 {
 }
 
@@ -42,12 +44,6 @@ QScreen::~QScreen()
 }
 
 
-WorkArea & QScreen::workarea()
-{
-       return owner_;
-}
-
-
 void QScreen::repaint()
 {
        QWidget * content = owner_.getContent();
@@ -162,3 +158,7 @@ void QScreen::removeCursor()
        owner_.getContent()
                ->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
 }
+
+
+} // namespace frontend
+} // namespace lyx
index 7d595f5e45a675ea3e91fd484cd2ebe7450e11e0..fed647d2e85f1cd83356c5cdd025c838f80e6e58 100644 (file)
 #ifndef QSCREEN_H
 #define QSCREEN_H
 
-#include "screen.h"
+#include "frontends/GuiCursor.h"
+
 #include <qcolor.h>
 #include <qpixmap.h>
 
+namespace lyx {
+namespace frontend {
+
 class QWorkArea;
-class WorkArea;
 
 
 /**
  * Qt implementation of toolkit-specific parts of LyXScreen.
  */
-class QScreen : public LyXScreen {
+class QScreen {
 public:
        QScreen(QWorkArea &);
 
        virtual ~QScreen();
 
-protected:
-       /// get the work area
-       virtual WorkArea & workarea();
-
+public:
        /// repaint the whole content immediately
        void repaint();
 
@@ -40,7 +40,7 @@ protected:
        virtual void expose(int x, int y, int exp_width, int exp_height);
 
        /// paint the cursor and store the background
-       virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
+       virtual void showCursor(int x, int y, int h, lyx::frontend::Cursor_Shape shape);
 
        /// hide the cursor
        virtual void removeCursor();
@@ -63,4 +63,7 @@ private:
        QColor cursor_color_;
 };
 
+} // namespace frontend
+} // namespace lyx
+
 #endif // QSCREEN_H
index 241932b4a0e88d19574fea9d7cd33e7ee953bba3..61f8e70beb8ebcee0d482adaf4aea35c33094724 100644 (file)
@@ -14,6 +14,9 @@
 
 #include "debug.h"
 
+// stupid Qt
+#undef emit
+
 
 Timeout::Timeout(unsigned int msec, Type t)
        : pimpl_(new qtTimeout(*this)), type(t), timeout_ms(msec)
index 6fa3ad2a8cabf5b8a2b320eca0fcb5d053282e2f..51ea8ff44f9f455f5006fa64f71b376c7118a1d1 100644 (file)
 #ifndef QTTIMEOUT_H
 #define QTTIMEOUT_H
 
+#ifdef emit
+#undef emit
+#include "frontends/Timeout.h"
+#define emit
+#else
 #include "frontends/Timeout.h"
+#endif
 #include <qobject.h>
 
-// stupid Qt
-#undef emit
 
 /**
  * This class executes the callback when the timeout expires
diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h
new file mode 100644 (file)
index 0000000..cce918c
--- /dev/null
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+/**
+ * \file GuiClipboard.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CLIPBOARD_H
+#define CLIPBOARD_H
+
+#include "frontends/Clipboard.h"
+
+namespace lyx {
+namespace frontend {
+
+/**
+ * The Qt4 version of the Clipboard.
+ */
+class GuiClipboard: public Clipboard
+{
+public:
+       GuiClipboard() {}
+
+       virtual ~GuiClipboard() {}
+
+       /** ClipBoard overloaded methods
+        */
+       //@{
+       void haveSelection(bool own);
+       std::string const get() const;
+       void put(std::string const & str);
+       //@}
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // CLIPBOARD_H
diff --git a/src/frontends/qt4/GuiImplementation.C b/src/frontends/qt4/GuiImplementation.C
new file mode 100644 (file)
index 0000000..18c13b5
--- /dev/null
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+/**
+ * \file GuiImplementation.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include "GuiImplementation.h"
+#include "GuiWorkArea.h"
+#include "QtView.h"
+
+using boost::shared_ptr;
+
+namespace lyx {
+namespace frontend {
+
+GuiImplementation::GuiImplementation(QtView & owner): owner_(owner), max_id_(0)
+{
+}
+
+
+Clipboard& GuiImplementation::clipboard()
+{
+       return clipboard_;
+}
+
+
+int GuiImplementation::newWorkArea(int w, int h)
+{
+       size_t const id = max_id_;
+       ++max_id_;
+       work_areas_[id].reset(new GuiWorkArea(owner_, w, h));
+       return id;
+}
+
+WorkArea& GuiImplementation::workArea(int id)
+{
+       BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
+
+       guiCursor().connect(work_areas_[id].get());
+
+       return *work_areas_[id].get();
+}
+
+
+void GuiImplementation::destroyWorkArea(int id)
+{
+       work_areas_.erase(id);
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/GuiImplementation.h b/src/frontends/qt4/GuiImplementation.h
new file mode 100644 (file)
index 0000000..31f23ad
--- /dev/null
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+/**
+ * \file GuiImplementation.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUI_IMPLEMENTATION_H
+#define GUI_IMPLEMENTATION_H
+
+#include "frontends/Gui.h"
+#include "GuiClipboard.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include <map>
+
+namespace lyx {
+namespace frontend {
+
+class GuiWorkArea;
+class QtView;
+
+/**
+ * The GuiImplementation class is the interface to all Qt4 components.
+ */
+class GuiImplementation: public Gui
+{
+public:
+       GuiImplementation(QtView & owner);
+       virtual ~GuiImplementation() {}
+
+       Clipboard& clipboard();
+
+       int newWorkArea(int w, int h);
+       WorkArea& workArea(int id);
+       void destroyWorkArea(int id);
+
+private:
+       ///
+       GuiClipboard clipboard_;
+       ///
+       std::map<int, boost::shared_ptr<GuiWorkArea> > work_areas_;
+       ///
+       QtView & owner_;
+       ///
+       size_t max_id_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUI_IMPLEMENTATION_H
diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C
new file mode 100644 (file)
index 0000000..76c8c3b
--- /dev/null
@@ -0,0 +1,610 @@
+/**
+ * \file GuiWorkArea.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include <boost/current_function.hpp>
+
+#include "GuiWorkArea.h"
+#include "QLPainter.h"
+#include "QLyXKeySym.h"
+#include "QtView.h"
+
+#include "ColorCache.h"
+#include "qt_helpers.h"
+#include "Application.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "LColor.h"
+#include "support/os.h"
+
+#include <QLayout>
+#include <QMainWindow>
+#include <QMimeData>
+#include <QUrl>
+#include <QDragEnterEvent>
+#include <QPixmap>
+#include <QPainter>
+#include <QScrollBar>
+
+#include <boost/bind.hpp>
+
+// Abdel (09/06/2006):
+// I want the drawing to be fast without Keyboard buffering so when working
+// on optimization, please set the following macro to 0:
+#define USE_KEY_BUFFERING 0
+
+using std::endl;
+using std::string;
+
+namespace os = lyx::support::os;
+
+namespace {
+
+/// return the LyX key state from Qt's
+key_modifier::state q_key_state(Qt::ButtonState state)
+{
+       key_modifier::state k = key_modifier::none;
+       if (state & Qt::ControlModifier)
+               k |= key_modifier::ctrl;
+       if (state & Qt::ShiftModifier)
+               k |= key_modifier::shift;
+       if (state & Qt::AltModifier)
+               k |= key_modifier::alt;
+       return k;
+}
+
+
+/// return the LyX mouse button state from Qt's
+mouse_button::state q_button_state(Qt::ButtonState button)
+{
+       mouse_button::state b = mouse_button::none;
+       switch (button) {
+               case Qt::LeftButton:
+                       b = mouse_button::button1;
+                       break;
+               case Qt::MidButton:
+                       b = mouse_button::button2;
+                       break;
+               case Qt::RightButton:
+                       b = mouse_button::button3;
+                       break;
+               default:
+                       break;
+       }
+       return b;
+}
+
+
+/// return the LyX mouse button state from Qt's
+mouse_button::state q_motion_state(Qt::ButtonState state)
+{
+       mouse_button::state b = mouse_button::none;
+       if (state & Qt::LeftButton)
+               b |= mouse_button::button1;
+       if (state & Qt::MidButton)
+               b |= mouse_button::button2;
+       if (state & Qt::RightButton)
+               b |= mouse_button::button3;
+       return b;
+}
+
+} // namespace anon
+
+namespace lyx {
+namespace frontend {
+
+// This is a 'heartbeat' generating synthetic mouse move events when the
+// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
+SyntheticMouseEvent::SyntheticMouseEvent()
+       : timeout(200), restart_timeout(true),
+         x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
+{}
+
+
+GuiWorkArea::GuiWorkArea(LyXView & owner, int w, int h)
+: QAbstractScrollArea(QtView::mainWidget()), WorkArea(owner, w, h), view_(owner), painter_(this)
+{
+       setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+       setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+       QtView::mainWidget()->setCentralWidget(this);
+
+       setAcceptDrops(true);
+
+       setMinimumSize(100, 70);
+
+       viewport()->setAutoFillBackground(false);
+       viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
+
+       viewport()->setFocusPolicy(Qt::WheelFocus);
+       viewport()->setFocus();
+       setFocusPolicy(Qt::WheelFocus);
+
+       viewport()->setCursor(Qt::IBeamCursor);
+
+       resize(w, h);
+       show();
+       workWidth_ = w;
+       workHeight_ = h;
+
+       synthetic_mouse_event_.timeout.timeout.connect(
+               boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
+                           this));
+
+       // Initialize the vertical Scroll Bar
+       QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
+               this, SLOT(adjustViewWithScrollBar(int)));
+
+       // PageStep only depends on the viewport height.
+       verticalScrollBar()->setPageStep(workHeight_);
+
+       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
+               << "\n Area width\t" << width()
+               << "\n Area height\t" << height()
+               << "\n viewport width\t" << viewport()->width()
+               << "\n viewport height\t" << viewport()->height()
+               << endl;
+
+       if (USE_KEY_BUFFERING) {
+               // This is the keyboard buffering stuff...
+               // I don't see any need for this under windows. The keyboard is reactive
+               // enough...
+
+               if ( !QObject::connect(&step_timer_, SIGNAL(timeout()),
+                       this, SLOT(keyeventTimeout())) )
+                       lyxerr[Debug::GUI] << "ERROR: keyeventTimeout cannot connect!" << endl;
+
+               // Start the timer, one-shot.
+               step_timer_.start(50, true);
+       }
+
+       ///////////////////////////////////////////////////////////////////////
+       // Specific stuff goes here...
+
+#if USE_INPUT_METHODS
+       // to make qt-immodule work
+       setInputMethodEnabled(true);
+#endif
+
+}
+
+GuiWorkArea::~GuiWorkArea()
+{
+}
+
+void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
+{
+       // do what cursor movement does (some grey)
+       h += height() / 4;
+       int scroll_max_ = std::max(0, h - height());
+
+       verticalScrollBar()->setRange(0, scroll_max_);
+       verticalScrollBar()->setSliderPosition(scroll_pos);
+       verticalScrollBar()->setLineStep(scroll_line_step);
+}
+
+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;
+       */
+       view_.view()->scrollDocView(verticalScrollBar()->sliderPosition());
+}
+
+
+void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
+{
+       if (event->mimeData()->hasUrls())
+               event->accept();
+       /// \todo Ask lyx-devel is this is enough:
+       /// if (event->mimeData()->hasFormat("text/plain"))
+       ///     event->acceptProposedAction();
+}
+
+
+void GuiWorkArea::dropEvent(QDropEvent* event)
+{
+       QList<QUrl> files = event->mimeData()->urls();
+       if (files.isEmpty())
+               return;
+
+       lyxerr[Debug::GUI] << "GuiWorkArea::dropEvent: got URIs!" << endl;
+       for (int i = 0; i!=files.size(); ++i) {
+               string const file = os::internal_path(fromqstr(files.at(i).toString()));
+               if (!file.empty())
+                       view_.view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
+       }
+}
+
+
+void GuiWorkArea::mousePressEvent(QMouseEvent * e)
+{
+       if (dc_event_.active && dc_event_ == *e) {
+               dc_event_.active = false;
+               FuncRequest cmd(LFUN_MOUSE_TRIPLE,
+                       dc_event_.x, dc_event_.y,
+                       q_button_state(dc_event_.state));
+               view_.view()->workAreaDispatch(cmd);
+               return;
+       }
+
+       FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
+                             q_button_state(e->button()));
+       view_.view()->workAreaDispatch(cmd);
+}
+
+
+void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
+{
+       if (synthetic_mouse_event_.timeout.running())
+               synthetic_mouse_event_.timeout.stop();
+
+       FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
+                             q_button_state(e->button()));
+       view_.view()->workAreaDispatch(cmd);
+}
+
+
+void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
+{
+       FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
+                             q_motion_state(e->state()));
+
+       // If we're above or below the work area...
+       if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
+               // Make sure only a synthetic event can cause a page scroll,
+               // so they come at a steady rate:
+               if (e->y() <= 20)
+                       // _Force_ a scroll up:
+                       cmd.y = -40;
+               else
+                       cmd.y = viewport()->height();
+               // Store the event, to be handled when the timeout expires.
+               synthetic_mouse_event_.cmd = cmd;
+
+               if (synthetic_mouse_event_.timeout.running())
+                       // Discard the event. Note that it _may_ be handled
+                       // when the timeout expires if
+                       // synthetic_mouse_event_.cmd has not been overwritten.
+                       // Ie, when the timeout expires, we handle the
+                       // most recent event but discard all others that
+                       // occurred after the one used to start the timeout
+                       // in the first place.
+                       return;
+               else {
+                       synthetic_mouse_event_.restart_timeout = true;
+                       synthetic_mouse_event_.timeout.start();
+                       // Fall through to handle this event...
+               }
+
+       } else if (synthetic_mouse_event_.timeout.running()) {
+               // Store the event, to be possibly handled when the timeout
+               // expires.
+               // Once the timeout has expired, normal control is returned
+               // to mouseMoveEvent (restart_timeout = false).
+               // This results in a much smoother 'feel' when moving the
+               // mouse back into the work area.
+               synthetic_mouse_event_.cmd = cmd;
+               synthetic_mouse_event_.restart_timeout = false;
+               return;
+       }
+
+       // Has anything changed on-screen since the last QMouseEvent
+       // was received?
+       double const scrollbar_value = verticalScrollBar()->value();
+       if (e->x() != synthetic_mouse_event_.x_old ||
+           e->y() != synthetic_mouse_event_.y_old ||
+           scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
+               // Yes it has. Store the params used to check this.
+               synthetic_mouse_event_.x_old = e->x();
+               synthetic_mouse_event_.y_old = e->y();
+               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
+
+               // ... and dispatch the event to the LyX core.
+               view_.view()->workAreaDispatch(cmd);
+       }
+}
+
+
+void GuiWorkArea::wheelEvent(QWheelEvent * e)
+{
+       // Wheel rotation by one notch results in a delta() of 120 (see
+       // documentation of QWheelEvent)
+       int const lines = qApp->wheelScrollLines() * e->delta() / 120;
+       verticalScrollBar()->setValue(verticalScrollBar()->value() -
+                       lines *  verticalScrollBar()->lineStep());
+       adjustViewWithScrollBar();
+}
+
+
+void GuiWorkArea::generateSyntheticMouseEvent()
+{
+       // Set things off to generate the _next_ 'pseudo' event.
+       if (synthetic_mouse_event_.restart_timeout)
+               synthetic_mouse_event_.timeout.start();
+
+       // Has anything changed on-screen since the last timeout signal
+       // was received?
+       double const scrollbar_value = verticalScrollBar()->value();
+       if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
+               // Yes it has. Store the params used to check this.
+               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
+
+               // ... and dispatch the event to the LyX core.
+               view_.view()->workAreaDispatch(synthetic_mouse_event_.cmd);
+       }
+}
+
+
+void GuiWorkArea::keyPressEvent(QKeyEvent * e)
+{
+       lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
+               << " count=" << e->count()
+               << " text=" << (const char *) e->text()
+               << " isAutoRepeat=" << e->isAutoRepeat()
+               << " key=" << e->key()
+               << endl;
+
+       if (USE_KEY_BUFFERING) {
+               keyeventQueue_.push(boost::shared_ptr<QKeyEvent>(new QKeyEvent(*e)));
+       }
+       else {
+               boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
+               sym->set(e);
+               view_.view()->workAreaKeyPress(sym, q_key_state(e->state()));
+       }
+}
+
+// This is used only if USE_KEY_BUFFERING is defined...
+void GuiWorkArea::keyeventTimeout()
+{
+       bool handle_autos = true;
+
+       while (!keyeventQueue_.empty()) {
+               boost::shared_ptr<QKeyEvent> ev = keyeventQueue_.front();
+
+               // We never handle more than one auto repeated
+               // char in a list of queued up events.
+               if (!handle_autos && ev->isAutoRepeat()) {
+                       keyeventQueue_.pop();
+                       continue;
+               }
+
+                boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
+               sym->set(ev.get());
+
+                lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
+                                   << " count=" << ev->count()
+                                   << " text=" << (const char *) ev->text()
+                                   << " isAutoRepeat=" << ev->isAutoRepeat()
+                                   << " key=" << ev->key()
+                                   << endl;
+
+                view_.view()->workAreaKeyPress(sym, q_key_state(ev->state()));
+               keyeventQueue_.pop();
+
+               handle_autos = false;
+       }
+
+       // Restart the timer.
+       step_timer_.start(25, true);
+}
+
+
+void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
+{
+       dc_event_ = double_click(e);
+
+       if (!dc_event_.active)
+               return;
+
+       dc_event_.active = false;
+
+       FuncRequest cmd(LFUN_MOUSE_DOUBLE,
+               dc_event_.x, dc_event_.y,
+               q_button_state(dc_event_.state));
+       view_.view()->workAreaDispatch(cmd);
+}
+
+
+void GuiWorkArea::resizeEvent(QResizeEvent *)
+{
+       workWidth_ = viewport()->width();
+       workHeight_ = viewport()->height();
+
+       verticalScrollBar()->setPageStep(viewport()->height());
+
+//     screen_device_ = QPixmap(viewport()->width(), viewport()->height());
+//     paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32);
+       paint_device_ = QPixmap(viewport()->width(), viewport()->height());
+
+       view_.view()->workAreaResize();
+
+       /*
+       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
+               << "\n QWidget width\t" << this->QWidget::width()
+               << "\n QWidget height\t" << this->QWidget::height()
+               << "\n viewport width\t" << viewport()->width()
+               << "\n viewport height\t" << viewport()->height()
+               << "\n QResizeEvent rect left\t" << rect().left()
+               << "\n QResizeEvent rect right\t" << rect().right()
+               << endl;
+               */
+}
+
+
+void GuiWorkArea::update(int x, int y, int w, int h)
+{
+       //screen_device_.fromImage(paint_device_);
+       //QPainter q(&screen_device_);
+       //q.drawImage(x, y, paint_device_.copy(x, y, w, h));
+
+       viewport()->update(x, y, w, h);
+}
+
+
+void GuiWorkArea::paintEvent(QPaintEvent * e)
+{
+       /*
+       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
+               << "\n QWidget width\t" << this->width()
+               << "\n QWidget height\t" << this->height()
+               << "\n viewport width\t" << viewport()->width()
+               << "\n viewport height\t" << viewport()->height()
+               << "\n pixmap width\t" << pixmap_->width()
+               << "\n pixmap height\t" << pixmap_->height()
+               << "\n QPaintEvent x\t" << e->rect().x()
+               << "\n QPaintEvent y\t" << e->rect().y()
+               << "\n QPaintEvent w\t" << e->rect().width()
+               << "\n QPaintEvent h\t" << e->rect().height()
+               << endl;
+       */
+       QPainter q(viewport());
+       q.drawPixmap(e->rect(), paint_device_, e->rect());
+
+       if (show_vcursor_)
+               q.drawPixmap(cursor_x_, cursor_y_, vcursor_);
+
+       if (show_hcursor_)
+               q.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_);
+}
+
+
+QPixmap GuiWorkArea::copyScreen(int x, int y, int w, int h) const
+{
+       return paint_device_.copy(x, y, w, h);
+}
+
+
+void GuiWorkArea::drawScreen(int x, int y, QPixmap pixmap)
+{
+       QPainter q(&paint_device_);
+       q.drawPixmap(x, y, pixmap);
+       viewport()->update(x, y, pixmap.width(), pixmap.height());
+}
+
+
+void GuiWorkArea::expose(int x, int y, int w, int h)
+{
+//     lyxerr[Debug::GUI] << "expose " << w << 'x' << h
+//             << '+' << x << '+' << y << std::endl;
+
+       update(x, y, w, h);
+}
+
+
+void GuiWorkArea::showCursor(int x, int y, int h, Cursor_Shape shape)
+{
+       if (!qApp->focusWidget())
+               return;
+
+       show_vcursor_ = true;
+
+       QColor const & required_color = lcolorcache.get(LColor::cursor);
+
+       if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_
+               && cursor_color_ == required_color
+               && cursor_shape_ == shape) {
+               show_hcursor_ = lshape_cursor_;
+               viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+               return;
+       }
+
+       // Cache the dimensions of the cursor.
+       cursor_x_ = x;
+       cursor_y_ = y;
+       cursor_h_ = h;
+       cursor_color_ = required_color;
+       cursor_shape_ = shape;
+
+       switch (cursor_shape_) {
+       case BAR_SHAPE:
+               // FIXME the cursor width shouldn't be hard-coded!
+               cursor_w_ = 2;
+               lshape_cursor_ = false;
+               break;
+       case L_SHAPE:
+               cursor_w_ = cursor_h_ / 3;
+               lshape_cursor_ = true;
+               break;
+       case REVERSED_L_SHAPE:
+               cursor_w_ = cursor_h_ / 3;
+               cursor_x_ -= cursor_w_ - 1;
+               lshape_cursor_ = true;
+               break;
+       }
+
+       // We cache two pixmaps:
+       // 1 the vertical line of the cursor.
+       // 2 the horizontal line of the L-shaped cursor (if necessary).
+       
+       // Draw the new (vertical) cursor.
+       vcursor_ = QPixmap(cursor_w_, cursor_h_);
+       vcursor_.fill(cursor_color_);
+
+       // Draw the new (horizontal) cursor if necessary.
+       if (lshape_cursor_) {
+               hcursor_ = QPixmap(cursor_w_, 1);
+               hcursor_.fill(cursor_color_);
+               show_hcursor_ = true;
+       }
+
+       viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+}
+
+
+void GuiWorkArea::removeCursor()
+{
+       show_vcursor_ = false;
+       show_hcursor_ = false;
+
+       viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+}
+
+///////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////
+// Specific stuff
+
+////////////////////////////////////////////////////////////////////////
+// qt-immodule specific stuff goes here...
+
+#if USE_INPUT_METHODS
+// to make qt-immodule work
+
+void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
+{
+       QString const text = e->text();
+       if (!text.isEmpty()) {
+               int key = 0;
+               // needed to make math superscript work on some systems
+               // ideally, such special coding should not be necessary
+               if (text == "^")
+                       key = Qt::Key_AsciiCircum;
+               QKeyEvent ev(QEvent::KeyPress, key, *text.ascii(), 0, text);
+               keyPressEvent(&ev);
+       }
+       e->accept();
+}
+#endif
+
+} // namespace frontend
+} // namespace lyx
+
+#include "GuiWorkArea_moc.cpp"
diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h
new file mode 100644 (file)
index 0000000..9a041c0
--- /dev/null
@@ -0,0 +1,253 @@
+// -*- C++ -*-
+/**
+ * \file GuiWorkArea.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef WORKAREA_H
+#define WORKAREA_H
+
+#if (defined(Q_WS_X11) && QT_VERSION >= 0x030200)
+#define USE_INPUT_METHODS 1
+#endif
+
+#ifdef emit
+#undef emit
+#endif
+
+#include "frontends/LyXView.h"
+#include "frontends/WorkArea.h"
+
+#include "QLPainter.h"
+
+#include "funcrequest.h"
+#include "frontends/Timeout.h"
+
+#include <QAbstractScrollArea>
+#include <QMouseEvent>
+#include <QWheelEvent>
+#include <QResizeEvent>
+#include <QKeyEvent>
+#include <QPaintEvent>
+#include <QTimer>
+#include <QImage>
+#include <QPixmap>
+
+#include <queue>
+
+class Painter;
+
+class QWidget;
+class QDragEnterEvent;
+class QDropEvent;
+class QMouseEvent;
+
+namespace lyx {
+namespace frontend {
+
+/// for emulating triple click
+class double_click {
+public:
+       int x;
+       int y;
+       Qt::ButtonState state;
+       bool active;
+
+       bool operator==(QMouseEvent const & e) {
+               return x == e.x() && y == e.y()
+                       && state == e.button();
+       }
+
+       double_click()
+               : x(0), y(0), state(Qt::NoButton), active(false) {}
+
+       double_click(QMouseEvent * e)
+               : x(e->x()), y(e->y()),
+               state(e->button()), active(true) {}
+};
+
+/** Qt only emits mouse events when the mouse is being moved, but
+ *  we want to generate 'pseudo' mouse events when the mouse button is
+ *  pressed and the mouse cursor is below the bottom, or above the top
+ *  of the work area. In this way, we'll be able to continue scrolling
+ *  (and selecting) the text.
+ *
+ *  This class stores all the parameters needed to make this happen.
+ */
+class SyntheticMouseEvent
+{
+public:
+       SyntheticMouseEvent();
+
+       FuncRequest cmd;
+       Timeout timeout;
+       bool restart_timeout;
+       int x_old;
+       int y_old;
+       double scrollbar_value_old;
+};
+
+/**
+ * Qt-specific implementation of the work area
+ * (buffer view GUI)
+*/
+class GuiWorkArea: public QAbstractScrollArea, public WorkArea {
+
+       Q_OBJECT
+
+public:
+
+       GuiWorkArea(LyXView & owner, int w, int h);
+
+       virtual ~GuiWorkArea();
+       /// return the width of the content pane
+       virtual int width() const { return workWidth_; }
+
+       /// return the height of the content pane
+       virtual int height() const { return workHeight_; }
+       ///
+       virtual void setScrollbarParams(int height, int pos, int line_height);
+
+       ///
+       virtual void dragEnterEvent(QDragEnterEvent * event);
+
+       ///
+       virtual void dropEvent(QDropEvent* event);
+
+       /// return the widget's painter
+       virtual Painter & getPainter() { return (Painter &) painter_; }
+
+       /// return the backing pixmap
+       QPaintDevice * paintDevice() { return &paint_device_; }
+
+       /// update the passed area.
+       void update(int x, int y, int w, int h);
+
+       /// return a screen copy of the defined area.
+       QPixmap copyScreen(int x, int y, int w, int h) const;
+
+       /// Draw a pixmap onto the backing pixmap.
+       /**
+       QPixmap is implicitely shared so no need to pass by reference.
+       */
+       void drawScreen(int x, int y, QPixmap pixmap);
+       
+       LyXView & view() { return view_; }
+
+       /// copies specified area of pixmap to screen
+       virtual void expose(int x, int y, int exp_width, int exp_height);
+
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
+
+       /// hide the cursor
+       virtual void removeCursor();
+
+protected:
+
+       /// repaint part of the widget
+       void paintEvent(QPaintEvent * e);
+       /// widget has been resized
+       void resizeEvent(QResizeEvent * e);
+       /// mouse button press
+       void mousePressEvent(QMouseEvent * e);
+       /// mouse button release
+       void mouseReleaseEvent(QMouseEvent * e);
+       /// mouse double click of button
+       void mouseDoubleClickEvent(QMouseEvent * e);
+       /// mouse motion
+       void mouseMoveEvent(QMouseEvent * e);
+       /// wheel event
+       void wheelEvent(QWheelEvent * e);
+       /// key press
+       void keyPressEvent(QKeyEvent * e);
+
+#if USE_INPUT_METHODS
+protected:
+       /// IM events
+       void inputMethodEvent(QInputMethodEvent * e);
+#endif
+
+public slots:
+
+       /// Timeout event Slot for keyboard bufferring.
+       /// \todo This is not used currently in the code, remove?
+       void keyeventTimeout();
+
+       /// Adjust the LyX buffer view with the position of the scrollbar.
+       /**
+       * The action argument is not used in the the code, it is there
+       * only for the connection to the vertical srollbar signal which
+       * emits an 'int' action.
+       */
+       void adjustViewWithScrollBar(int action = 0);
+
+private:
+        ///
+        LyXView & view_;
+        
+       /// Buffer view width.
+       int workWidth_;
+
+       /// Buffer view height.
+       int workHeight_;
+
+       /// Our painter.
+       QLPainter painter_;
+
+       /// The slot connected to SyntheticMouseEvent::timeout.
+       void generateSyntheticMouseEvent();
+
+       ///
+       SyntheticMouseEvent synthetic_mouse_event_;
+
+       /// Our client side painting device.
+       //QImage paint_device_;
+       QPixmap paint_device_;
+
+       /// Our server side painting device.
+       //QPixmap screen_device_;
+
+       /// \todo remove
+       QTimer step_timer_;
+
+       /// \todo remove
+       std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
+
+       double_click dc_event_;
+
+       ///
+       int cursor_x_;
+       ///
+       int cursor_y_;
+       ///
+       int cursor_w_;
+       ///
+       int cursor_h_;
+       ///
+       QPixmap hcursor_;
+       ///
+       QPixmap vcursor_;
+       ///
+       bool show_hcursor_;
+       ///
+       bool show_vcursor_;
+       ///
+       bool lshape_cursor_;
+       ///
+       QColor cursor_color_;
+       ///
+       Cursor_Shape cursor_shape_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // WORKAREA_H
diff --git a/src/frontends/qt4/LyXScreenFactory.C b/src/frontends/qt4/LyXScreenFactory.C
deleted file mode 100644 (file)
index e1a4c3d..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * \file qt4/LyXScreenFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/LyXScreenFactory.h"
-
-#include "QWorkArea.h"
-
-namespace LyXScreenFactory {
-
-LyXScreen * create(WorkArea & owner)
-{
-       return &(static_cast<QWorkArea &>(owner));
-}
-
-} // namespace LyXScreenFactory
index 851f0ebe802228606477d5141f179956973250bc..bbe92e62c514bb1b37256cb3ec0cf554b1721c53 100644 (file)
@@ -30,17 +30,16 @@ AM_CPPFLAGS += \
        -I$(top_srcdir)/src/frontends/controllers
 
 libqt4_la_SOURCES = \
-       QDialogView.C \
-       QDialogView.h \
-       Action.C Action.h \
        Alert_pimpl.C \
+       Application.C Application.h \
        ColorCache.h ColorCache.C \
        Dialogs.C \
        FileDialog.C \
+       FontLoader.h FontLoader.C \
+       GuiClipboard.h GuiClipboard.C \
+       GuiImplementation.h GuiImplementation.C \
        LyXKeySymFactory.C \
-       LyXScreenFactory.C \
        QLMenubar.C QLMenubar.h \
-       qtTimeout.C qtTimeout.h \
        QAbout.C QAbout.h \
        QBibitem.C QBibitem.h \
        QBibtex.C QBibtex.h \
@@ -51,6 +50,7 @@ libqt4_la_SOURCES = \
        QCharacter.C QCharacter.h \
        QCitation.C QCitation.h \
        QDocument.C QDocument.h \
+       QDialogView.C QDialogView.h \
        QErrorList.C QErrorList.h \
        QERT.C QERT.h \
        QExternal.C QExternal.h \
@@ -80,16 +80,14 @@ libqt4_la_SOURCES = \
        QToc.C QToc.h \
        QURL.C QURL.h \
        QVSpace.C QVSpace.h \
-       QWorkArea.C QWorkArea.h \
        QWrap.C QWrap.h \
        Qt2BC.C Qt2BC.h \
-       WorkAreaFactory.C \
        checkedwidgets.C checkedwidgets.h \
        lyx_gui.C \
        panelstack.h panelstack.C \
        qfontexample.h qfontexample.C \
-       FontLoader.h FontLoader.C \
        qfont_metrics.C \
        qlkey.h \
        qt_helpers.h qt_helpers.C \
+       qtTimeout.C qtTimeout.h \
        $(MOCFILES)
index 558351c2d5d3fd608c6dd454b8146e9e4c5bbaf3..4a4d85dc73d09e5317e3827291ebbd4ac98187ef 100644 (file)
@@ -78,6 +78,7 @@ MOCFILES = \
        emptytable.C emptytable.h \
        FileDialog_private.C FileDialog_private.h \
        floatplacement.C floatplacement.h \
+       GuiWorkArea.C GuiWorkArea.h \
        iconpalette.C iconpalette.h \
        InsertTableWidget.C InsertTableWidget.h \
        lengthcombo.C lengthcombo.h \
@@ -129,7 +130,6 @@ MOCFILES = \
        QtView.C QtView.h \
        QURLDialog.C QURLDialog.h \
        QVSpaceDialog.C QVSpaceDialog.h \
-       QWorkArea.C QWorkArea.h \
        QWrapDialog.C QWrapDialog.h \
        QLToolbar.C QLToolbar.h \
        socket_callback.C socket_callback.h \
index ad0f4d66d446d53a4ad51c4c39f9c23bf30e3274..f54a74537b775637525759f306ebf0595c389a28 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "QLPainter.h"
 
-#include "QWorkArea.h"
+#include "GuiWorkArea.h"
 #include "QLImage.h"
 
 #include "ColorCache.h"
 using std::endl;
 using std::string;
 
+namespace lyx {
+namespace frontend {
 
 QLPainter::~QLPainter()
 {
 }
 
-QLPainter::QLPainter(QWorkArea * qwa)
+QLPainter::QLPainter(GuiWorkArea * qwa)
        : Painter(), qwa_(qwa)
 {
 }
@@ -234,7 +236,7 @@ void QLPainter::text(int x, int y, char const * s, size_t ls,
 
        QString str;
        str.setLength(ls);
-       for (int i = 0; i < ls; ++i)
+       for (size_t i = 0; i < ls; ++i)
                str[i] = QChar(encoding->ucs(s[i]));
 
        // HACK: QT3 refuses to show single compose characters
@@ -248,7 +250,7 @@ void QLPainter::text(int x, int y, char const * s, size_t ls,
                qp.setFont(fontloader.get(f));
                // We need to draw the text as LTR as we use our own bidi code.
                qp.setLayoutDirection(Qt::LeftToRight);
-               qp.drawText(x, y, str, -1);
+               qp.drawText(x, y, str);
        } else {
                smallCapsText(x, y, str, f);
        }
@@ -270,3 +272,7 @@ void QLPainter::drawImage(int x, int y, QImage const & image)
        QPainter qp(qwa_->paintDevice());
        qp.drawImage(x, y, image);
 }
+
+} // namespace frontend
+} // namespace lyx
+
index 93e048f64425d87b408bb39fbbaac31c4835733e..88e8c4096f17afe5b4e53bfbf43ba8f751345875 100644 (file)
@@ -23,14 +23,18 @@ class QPainter;
 class QString;
 class QPixmap;
 class QImage;
-class QWorkArea;
+
+namespace lyx {
+namespace frontend {
+
+class GuiWorkArea;
 
 /**
  * QLPainter - a painter implementation for Qt4
  */
 class QLPainter : public Painter {
 public:
-       QLPainter(QWorkArea *);
+       QLPainter(GuiWorkArea *);
 
        ~QLPainter();
 
@@ -146,11 +150,14 @@ private:
        boost::scoped_ptr<QPainter> qp_;
 
        /// the working area
-       QWorkArea * qwa_;
+       GuiWorkArea * qwa_;
 
        LColor::color current_color_;
        Painter::line_style current_ls_;
        Painter::line_width current_lw_;
 };
 
+} // namespace frontend
+} // namespace lyx
+
 #endif // QLPAINTER_H
diff --git a/src/frontends/qt4/QWorkArea.C b/src/frontends/qt4/QWorkArea.C
deleted file mode 100644 (file)
index 6de2dd4..0000000
+++ /dev/null
@@ -1,770 +0,0 @@
-/**
- * \file QWorkArea.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include <boost/current_function.hpp>
-
-#include "QWorkArea.h"
-#include "QLPainter.h"
-#include "QLyXKeySym.h"
-#include "QtView.h"
-
-#include "ColorCache.h"
-#include "qt_helpers.h"
-#include "BufferView.h"
-#include "debug.h"
-#include "funcrequest.h"
-#include "LColor.h"
-#include "support/os.h"
-
-#include <QApplication>
-#include <QClipboard>
-#include <QLayout>
-#include <QMainWindow>
-#include <QMimeData>
-#include <QUrl>
-#include <QDragEnterEvent>
-#include <QPixmap>
-#include <QPainter>
-#include <QScrollBar>
-
-#include <boost/bind.hpp>
-
-///////////////////////////////////////////////////////////////
-// Specific stuff
-#ifdef Q_WS_X11
-#include <X11/Xlib.h>
-#endif
-
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#include <support/lstrings.h>
-using lyx::support::subst;
-#endif
-
-// You can find other qt-immodule, X11 and MACX specific stuff
-// at the end of this file...
-///////////////////////////////////////////////////////////////
-
-using std::endl;
-using std::string;
-
-namespace os = lyx::support::os;
-
-namespace {
-
-QWorkArea * wa_ptr = 0;
-
-/// return the LyX key state from Qt's
-key_modifier::state q_key_state(Qt::ButtonState state)
-{
-       key_modifier::state k = key_modifier::none;
-       if (state & Qt::ControlModifier)
-               k |= key_modifier::ctrl;
-       if (state & Qt::ShiftModifier)
-               k |= key_modifier::shift;
-       if (state & Qt::AltModifier)
-               k |= key_modifier::alt;
-       return k;
-}
-
-
-/// return the LyX mouse button state from Qt's
-mouse_button::state q_button_state(Qt::ButtonState button)
-{
-       mouse_button::state b = mouse_button::none;
-       switch (button) {
-               case Qt::LeftButton:
-                       b = mouse_button::button1;
-                       break;
-               case Qt::MidButton:
-                       b = mouse_button::button2;
-                       break;
-               case Qt::RightButton:
-                       b = mouse_button::button3;
-                       break;
-               default:
-                       break;
-       }
-       return b;
-}
-
-
-/// return the LyX mouse button state from Qt's
-mouse_button::state q_motion_state(Qt::ButtonState state)
-{
-       mouse_button::state b = mouse_button::none;
-       if (state & Qt::LeftButton)
-               b |= mouse_button::button1;
-       if (state & Qt::MidButton)
-               b |= mouse_button::button2;
-       if (state & Qt::RightButton)
-               b |= mouse_button::button3;
-       return b;
-}
-
-} // namespace anon
-
-// This is a 'heartbeat' generating synthetic mouse move events when the
-// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
-SyntheticMouseEvent::SyntheticMouseEvent()
-       : timeout(200), restart_timeout(true),
-         x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
-{}
-
-
-QWorkArea::QWorkArea(LyXView & owner, int w, int h)
-    : QAbstractScrollArea(lyx::frontend::QtView::mainWidget()), WorkArea(), view_(owner), painter_(this)
-{
-       setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-       setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
-       lyx::frontend::QtView::mainWidget()->setCentralWidget(this);
-
-       setAcceptDrops(true);
-
-       setMinimumSize(100, 70);
-
-       viewport()->setAutoFillBackground(false);
-       viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
-
-       viewport()->setFocusPolicy(Qt::WheelFocus);
-       viewport()->setFocus();
-       setFocusPolicy(Qt::WheelFocus);
-
-       viewport()->setCursor(Qt::IBeamCursor);
-
-       resize(w, h);
-       show();
-       workWidth_ = w;
-       workHeight_ = h;
-
-       synthetic_mouse_event_.timeout.timeout.connect(
-               boost::bind(&QWorkArea::generateSyntheticMouseEvent,
-                           this));
-
-       // Initialize the vertical Scroll Bar
-       QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
-               this, SLOT(adjustViewWithScrollBar(int)));
-
-       // PageStep only depends on the viewport height.
-       verticalScrollBar()->setPageStep(workHeight_);
-
-       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-               << "\n Area width\t" << width()
-               << "\n Area height\t" << height()
-               << "\n viewport width\t" << viewport()->width()
-               << "\n viewport height\t" << viewport()->height()
-               << endl;
-
-/*
-       // This is the keyboard buffering stuff...
-       // I don't see any need for this under windows. The keyboard is reactive
-    // enough...
-
-       if ( !QObject::connect(&step_timer_, SIGNAL(timeout()),
-               this, SLOT(keyeventTimeout())) )
-                       lyxerr[Debug::GUI] << "ERROR: keyeventTimeout cannot connect!" << endl;
-
-       // Start the timer, one-shot.
-       step_timer_.start(50, true);
-*/
-
-       ///////////////////////////////////////////////////////////////////////
-       // Specific stuff goes here...
-
-#if USE_INPUT_METHODS
-       // to make qt-immodule work
-       setInputMethodEnabled(true);
-#endif
-
-#ifdef Q_WS_X11
-       // doubleClickInterval() is 400 ms on X11 witch is just too long.
-       // On Windows and Mac OS X, the operating system's value is used.
-       // On Microsoft Windows, calling this function sets the double
-       // click interval for all applications. So we don't!
-       QApplication::setDoubleClickInterval(300);
-#endif
-
-#ifdef Q_WS_MACX
-       wa_ptr = this;
-#endif
-}
-
-QWorkArea::~QWorkArea()
-{
-}
-
-void QWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
-{
-       // do what cursor movement does (some grey)
-       h += height() / 4;
-       int scroll_max_ = std::max(0, h - height());
-
-       verticalScrollBar()->setRange(0, scroll_max_);
-       verticalScrollBar()->setSliderPosition(scroll_pos);
-       verticalScrollBar()->setLineStep(scroll_line_step);
-}
-
-void QWorkArea::adjustViewWithScrollBar(int action)
-{
-       /*
-       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;
-       */
-       view_.view()->scrollDocView(verticalScrollBar()->sliderPosition());
-}
-
-
-void QWorkArea::haveSelection(bool own) const
-{
-       /// \todo ask X11 and MAC devels why this wa_ptr is useful.
-       wa_ptr = const_cast<QWorkArea*>(this);
-
-       if (!QApplication::clipboard()->supportsSelection())
-               return;
-
-       if (own) {
-               QApplication::clipboard()->setText(QString(), QClipboard::Selection);
-       }
-       // We don't need to do anything if own = false, as this case is
-       // handled by QT.
-}
-
-
-string const QWorkArea::getClipboard() const
-{
-       QString str = QApplication::clipboard()->text(QClipboard::Selection);
-       lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
-       if (str.isNull())
-               return string();
-#ifdef Q_WS_MACX
-       // The MAC clipboard uses \r for lineendings, and we use \n
-       return subst(fromqstr(str), '\r', '\n');
-#else
-       return fromqstr(str);
-#endif
-}
-
-
-void QWorkArea::putClipboard(string const & str) const
-{
-#ifdef Q_WS_MACX
-       // The MAC clipboard uses \r for lineendings, and we use \n
-       QApplication::clipboard()->setText(toqstr(subst(str, '\n', '\r')),
-                                          QClipboard::Selection);
-#else
-       QApplication::clipboard()->setText(toqstr(str), QClipboard::Selection);
-#endif
-       lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
-}
-
-
-void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
-{
-       if (event->mimeData()->hasUrls())
-               event->accept();
-       /// \todo Ask lyx-devel is this is enough:
-       /// if (event->mimeData()->hasFormat("text/plain"))
-       ///     event->acceptProposedAction();
-
-}
-
-
-void QWorkArea::dropEvent(QDropEvent* event)
-{
-       QList<QUrl> files = event->mimeData()->urls();
-       if (files.isEmpty())
-               return;
-
-       lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!" << endl;
-       for (int i = 0; i!=files.size(); ++i) {
-               string const file = os::internal_path(fromqstr(files.at(i).toString()));
-               if (!file.empty())
-                       view_.view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
-       }
-}
-
-
-void QWorkArea::mousePressEvent(QMouseEvent * e)
-{
-       if (dc_event_.active && dc_event_ == *e) {
-               dc_event_.active = false;
-               FuncRequest cmd(LFUN_MOUSE_TRIPLE,
-                       dc_event_.x, dc_event_.y,
-                       q_button_state(dc_event_.state));
-               view_.view()->workAreaDispatch(cmd);
-               return;
-       }
-
-       FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
-                             q_button_state(e->button()));
-       view_.view()->workAreaDispatch(cmd);
-}
-
-
-void QWorkArea::mouseReleaseEvent(QMouseEvent * e)
-{
-       if (synthetic_mouse_event_.timeout.running())
-               synthetic_mouse_event_.timeout.stop();
-
-       FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
-                             q_button_state(e->button()));
-       view_.view()->workAreaDispatch(cmd);
-}
-
-
-void QWorkArea::mouseMoveEvent(QMouseEvent * e)
-{
-       FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
-                             q_motion_state(e->state()));
-
-       // If we're above or below the work area...
-       if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
-               // Make sure only a synthetic event can cause a page scroll,
-               // so they come at a steady rate:
-               if (e->y() <= 20)
-                       // _Force_ a scroll up:
-                       cmd.y = -40;
-               else
-                       cmd.y = viewport()->height();
-               // Store the event, to be handled when the timeout expires.
-               synthetic_mouse_event_.cmd = cmd;
-
-               if (synthetic_mouse_event_.timeout.running())
-                       // Discard the event. Note that it _may_ be handled
-                       // when the timeout expires if
-                       // synthetic_mouse_event_.cmd has not been overwritten.
-                       // Ie, when the timeout expires, we handle the
-                       // most recent event but discard all others that
-                       // occurred after the one used to start the timeout
-                       // in the first place.
-                       return;
-               else {
-                       synthetic_mouse_event_.restart_timeout = true;
-                       synthetic_mouse_event_.timeout.start();
-                       // Fall through to handle this event...
-               }
-
-       } else if (synthetic_mouse_event_.timeout.running()) {
-               // Store the event, to be possibly handled when the timeout
-               // expires.
-               // Once the timeout has expired, normal control is returned
-               // to mouseMoveEvent (restart_timeout = false).
-               // This results in a much smoother 'feel' when moving the
-               // mouse back into the work area.
-               synthetic_mouse_event_.cmd = cmd;
-               synthetic_mouse_event_.restart_timeout = false;
-               return;
-       }
-
-       // Has anything changed on-screen since the last QMouseEvent
-       // was received?
-       double const scrollbar_value = verticalScrollBar()->value();
-       if (e->x() != synthetic_mouse_event_.x_old ||
-           e->y() != synthetic_mouse_event_.y_old ||
-           scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
-               // Yes it has. Store the params used to check this.
-               synthetic_mouse_event_.x_old = e->x();
-               synthetic_mouse_event_.y_old = e->y();
-               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
-
-               // ... and dispatch the event to the LyX core.
-               view_.view()->workAreaDispatch(cmd);
-       }
-}
-
-
-void QWorkArea::wheelEvent(QWheelEvent * e)
-{
-       // Wheel rotation by one notch results in a delta() of 120 (see
-       // documentation of QWheelEvent)
-       int const lines = QApplication::wheelScrollLines() * e->delta() / 120;
-       verticalScrollBar()->setValue(verticalScrollBar()->value() -
-                       lines *  verticalScrollBar()->lineStep());
-       adjustViewWithScrollBar();
-}
-
-
-void QWorkArea::generateSyntheticMouseEvent()
-{
-       // Set things off to generate the _next_ 'pseudo' event.
-       if (synthetic_mouse_event_.restart_timeout)
-               synthetic_mouse_event_.timeout.start();
-
-       // Has anything changed on-screen since the last timeout signal
-       // was received?
-       double const scrollbar_value = verticalScrollBar()->value();
-       if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
-               // Yes it has. Store the params used to check this.
-               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
-
-               // ... and dispatch the event to the LyX core.
-               view_.view()->workAreaDispatch(synthetic_mouse_event_.cmd);
-       }
-}
-
-void QWorkArea::keyPressEvent(QKeyEvent * e)
-{
-       lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
-               << " count=" << e->count()
-               << " text=" << (const char *) e->text()
-               << " isAutoRepeat=" << e->isAutoRepeat()
-               << " key=" << e->key()
-               << endl;
-
-//     keyeventQueue_.push(boost::shared_ptr<QKeyEvent>(new QKeyEvent(*e)));
-
-    boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
-    sym->set(e);
-    view_.view()->workAreaKeyPress(sym, q_key_state(e->state()));
-
-}
-
-// This is not used for now...
-void QWorkArea::keyeventTimeout()
-{
-       bool handle_autos = true;
-
-       while (!keyeventQueue_.empty()) {
-               boost::shared_ptr<QKeyEvent> ev = keyeventQueue_.front();
-
-               // We never handle more than one auto repeated
-               // char in a list of queued up events.
-               if (!handle_autos && ev->isAutoRepeat()) {
-                       keyeventQueue_.pop();
-                       continue;
-               }
-
-                boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
-               sym->set(ev.get());
-
-                lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-                                   << " count=" << ev->count()
-                                   << " text=" << (const char *) ev->text()
-                                   << " isAutoRepeat=" << ev->isAutoRepeat()
-                                   << " key=" << ev->key()
-                                   << endl;
-
-                view_.view()->workAreaKeyPress(sym, q_key_state(ev->state()));
-               keyeventQueue_.pop();
-
-               handle_autos = false;
-       }
-
-       // Restart the timer.
-       step_timer_.start(25, true);
-}
-
-
-void QWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
-{
-       dc_event_ = double_click(e);
-
-       if (!dc_event_.active)
-               return;
-
-       dc_event_.active = false;
-
-       FuncRequest cmd(LFUN_MOUSE_DOUBLE,
-               dc_event_.x, dc_event_.y,
-               q_button_state(dc_event_.state));
-       view_.view()->workAreaDispatch(cmd);
-}
-
-
-void QWorkArea::resizeEvent(QResizeEvent * resizeEvent)
-{
-       workWidth_ = viewport()->width();
-       workHeight_ = viewport()->height();
-
-       verticalScrollBar()->setPageStep(viewport()->height());
-
-//     screen_device_ = QPixmap(viewport()->width(), viewport()->height());
-//     paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32);
-       paint_device_ = QPixmap(viewport()->width(), viewport()->height());
-
-       view_.view()->workAreaResize();
-
-       /*
-       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-               << "\n QWidget width\t" << this->QWidget::width()
-               << "\n QWidget height\t" << this->QWidget::height()
-               << "\n viewport width\t" << viewport()->width()
-               << "\n viewport height\t" << viewport()->height()
-               << "\n QResizeEvent rect left\t" << rect().left()
-               << "\n QResizeEvent rect right\t" << rect().right()
-               << endl;
-               */
-}
-
-void QWorkArea::update(int x, int y, int w, int h)
-{
-       //screen_device_.fromImage(paint_device_);
-       //QPainter q(&screen_device_);
-       //q.drawImage(x, y, paint_device_.copy(x, y, w, h));
-
-       viewport()->update(x, y, w, h);
-}
-
-void QWorkArea::paintEvent(QPaintEvent * e)
-{
-       /*
-       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-               << "\n QWidget width\t" << this->width()
-               << "\n QWidget height\t" << this->height()
-               << "\n viewport width\t" << viewport()->width()
-               << "\n viewport height\t" << viewport()->height()
-               << "\n pixmap width\t" << pixmap_->width()
-               << "\n pixmap height\t" << pixmap_->height()
-               << "\n QPaintEvent x\t" << e->rect().x()
-               << "\n QPaintEvent y\t" << e->rect().y()
-               << "\n QPaintEvent w\t" << e->rect().width()
-               << "\n QPaintEvent h\t" << e->rect().height()
-               << endl;
-       */
-       QPainter q(viewport());
-       q.drawPixmap(e->rect(), paint_device_, e->rect());
-
-       if (show_vcursor_)
-               q.drawPixmap(cursor_x_, cursor_y_, vcursor_);
-
-       if (show_hcursor_)
-               q.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_);
-}
-
-
-QPixmap QWorkArea::copyScreen(int x, int y, int w, int h) const
-{
-       return paint_device_.copy(x, y, w, h);
-}
-
-void QWorkArea::drawScreen(int x, int y, QPixmap pixmap)
-{
-       QPainter q(&paint_device_);
-       q.drawPixmap(x, y, pixmap);
-       viewport()->update(x, y, pixmap.width(), pixmap.height());
-}
-
-///////////////////////////////////////////////////////////////
-// LyXSreen overloaded methods:
-
-WorkArea & QWorkArea::workarea()
-{
-//     return static_cast<QWorkArea &> (*this);
-       return *this;
-}
-
-
-void QWorkArea::expose(int x, int y, int w, int h)
-{
-//     lyxerr[Debug::GUI] << "expose " << w << 'x' << h
-//             << '+' << x << '+' << y << std::endl;
-
-       update(x, y, w, h);
-}
-
-
-void QWorkArea::showCursor(int x, int y, int h, Cursor_Shape shape)
-{
-       if (!qApp->focusWidget())
-               return;
-
-       show_vcursor_ = true;
-
-       QColor const & required_color = lcolorcache.get(LColor::cursor);
-
-       if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_
-               && cursor_color_ == required_color
-               && cursor_shape_ == shape) {
-               show_hcursor_ = lshape_cursor_;
-               viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
-               return;
-       }
-
-       // Cache the dimensions of the cursor.
-       cursor_x_ = x;
-       cursor_y_ = y;
-       cursor_h_ = h;
-       cursor_color_ = required_color;
-       cursor_shape_ = shape;
-
-       switch (cursor_shape_) {
-       case BAR_SHAPE:
-               // FIXME the cursor width shouldn't be hard-coded!
-               cursor_w_ = 2;
-               lshape_cursor_ = false;
-               break;
-       case L_SHAPE:
-               cursor_w_ = cursor_h_ / 3;
-               lshape_cursor_ = true;
-               break;
-       case REVERSED_L_SHAPE:
-               cursor_w_ = cursor_h_ / 3;
-               cursor_x_ -= cursor_w_ - 1;
-               lshape_cursor_ = true;
-               break;
-       }
-
-       // We cache two pixmaps:
-       // 1 the vertical line of the cursor.
-       // 2 the horizontal line of the L-shaped cursor (if necessary).
-       
-       // Draw the new (vertical) cursor.
-       vcursor_ = QPixmap(cursor_w_, cursor_h_);
-       vcursor_.fill(cursor_color_);
-
-       // Draw the new (horizontal) cursor if necessary.
-       if (lshape_cursor_) {
-               hcursor_ = QPixmap(cursor_w_, 1);
-               hcursor_.fill(cursor_color_);
-               show_hcursor_ = true;
-       }
-
-       viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
-}
-
-
-void QWorkArea::removeCursor()
-{
-       show_vcursor_ = false;
-       show_hcursor_ = false;
-
-       viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
-}
-
-///////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////
-// Specific stuff
-
-////////////////////////////////////////////////////////////////////////
-// qt-immodule specific stuff goes here...
-
-#if USE_INPUT_METHODS
-// to make qt-immodule work
-
-void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
-{
-       QString const text = e->text();
-       if (!text.isEmpty()) {
-               int key = 0;
-               // needed to make math superscript work on some systems
-               // ideally, such special coding should not be necessary
-               if (text == "^")
-                       key = Qt::Key_AsciiCircum;
-               QKeyEvent ev(QEvent::KeyPress, key, *text.ascii(), 0, text);
-               keyPressEvent(&ev);
-       }
-       e->accept();
-}
-#endif
-
-
-////////////////////////////////////////////////////////////////////////
-// X11 specific stuff goes here...
-
-#ifdef Q_WS_X11
-bool lyxX11EventFilter(XEvent * xev)
-{
-       switch (xev->type) {
-       case SelectionRequest:
-               lyxerr[Debug::GUI] << "X requested selection." << endl;
-               if (wa_ptr)
-                       wa_ptr->view().view()->selectionRequested();
-               break;
-       case SelectionClear:
-               lyxerr[Debug::GUI] << "Lost selection." << endl;
-               if (wa_ptr)
-                       wa_ptr->view().view()->selectionLost();
-               break;
-       }
-       return false;
-}
-#endif
-
-
-////////////////////////////////////////////////////////////////////////
-// Mac OSX specific stuff goes here...
-
-#ifdef Q_WS_MACX
-namespace{
-OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
- {
-       DescType returnedType;
-       Size actualSize;
-       OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
-                                     typeWildCard, &returnedType, nil, 0,
-                                     &actualSize);
-       switch (err) {
-       case errAEDescNotFound:
-               return noErr;
-       case noErr:
-               return errAEEventNotHandled;
-       default:
-               return err;
-       }
- }
-}
-
-pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
-                                AppleEvent* /*reply*/, long /*refCon*/)
-{
-       QString s_arg;
-       AEDescList documentList;
-       OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
-                                  &documentList);
-       if (err != noErr)
-               return err;
-
-       err = checkAppleEventForMissingParams(*inEvent);
-       if (err == noErr) {
-               long documentCount;
-               err = AECountItems(&documentList, &documentCount);
-               for (long documentIndex = 1;
-                    err == noErr && documentIndex <= documentCount;
-                    documentIndex++) {
-                       DescType returnedType;
-                       Size actualSize;
-                       AEKeyword keyword;
-                       FSRef ref;
-                       char qstr_buf[1024];
-                       err = AESizeOfNthItem(&documentList, documentIndex,
-                                             &returnedType, &actualSize);
-                       if (err == noErr) {
-                               err = AEGetNthPtr(&documentList, documentIndex,
-                                                 typeFSRef, &keyword,
-                                                 &returnedType, (Ptr)&ref,
-                                                 sizeof(FSRef), &actualSize);
-                               if (err == noErr) {
-                                       FSRefMakePath(&ref, (UInt8*)qstr_buf,
-                                                     1024);
-                                       s_arg=QString::fromUtf8(qstr_buf);
-                                       wa_ptr->view().view()->workAreaDispatch(
-                                               FuncRequest(LFUN_FILE_OPEN,
-                                                           fromqstr(s_arg)));
-                                       break;
-                               }
-                       }
-               } // for ...
-       }
-       AEDisposeDesc(&documentList);
-       return err;
-}
-#endif  // Q_WS_MACX
-
-#include "QWorkArea_moc.cpp"
diff --git a/src/frontends/qt4/QWorkArea.h b/src/frontends/qt4/QWorkArea.h
deleted file mode 100644 (file)
index 1f5147e..0000000
+++ /dev/null
@@ -1,262 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QWorkArea.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef QWORKAREA_H
-#define QWORKAREA_H
-
-#if (defined(Q_WS_X11) && QT_VERSION >= 0x030200)
-#define USE_INPUT_METHODS 1
-#endif
-
-#ifdef emit
-#undef emit
-#endif
-
-#include "WorkArea.h"
-#include "QLPainter.h"
-#include "LyXView.h"
-#include "screen.h"
-
-#include "funcrequest.h"
-#include "frontends/Timeout.h"
-
-#include <QAbstractScrollArea>
-#include <QMouseEvent>
-#include <QWheelEvent>
-#include <QResizeEvent>
-#include <QKeyEvent>
-#include <QPaintEvent>
-#include <QTimer>
-#include <QImage>
-#include <QPixmap>
-
-#include <queue>
-
-class Painter;
-
-class QWidget;
-class QDragEnterEvent;
-class QDropEvent;
-class QMouseEvent;
-
-/// for emulating triple click
-class double_click {
-public:
-       int x;
-       int y;
-       Qt::ButtonState state;
-       bool active;
-
-       bool operator==(QMouseEvent const & e) {
-               return x == e.x() && y == e.y()
-                       && state == e.button();
-       }
-
-       double_click()
-               : x(0), y(0), state(Qt::NoButton), active(false) {}
-
-       double_click(QMouseEvent * e)
-               : x(e->x()), y(e->y()),
-               state(e->button()), active(true) {}
-};
-
-
-/** Qt only emits mouse events when the mouse is being moved, but
- *  we want to generate 'pseudo' mouse events when the mouse button is
- *  pressed and the mouse cursor is below the bottom, or above the top
- *  of the work area. In this way, we'll be able to continue scrolling
- *  (and selecting) the text.
- *
- *  This class stores all the parameters needed to make this happen.
- */
-class SyntheticMouseEvent
-{
-public:
-       SyntheticMouseEvent();
-
-       FuncRequest cmd;
-       Timeout timeout;
-       bool restart_timeout;
-       int x_old;
-       int y_old;
-       double scrollbar_value_old;
-};
-
-/**
- * Qt-specific implementation of the work area
- * (buffer view GUI)
-*/
-class QWorkArea : public QAbstractScrollArea, public WorkArea, public LyXScreen {
-
-       Q_OBJECT
-
-public:
-
-       QWorkArea(LyXView & owner, int w, int h);
-
-       virtual ~QWorkArea();
-       /// return the width of the content pane
-       virtual int workWidth() const { return workWidth_; }
-
-       /// return the height of the content pane
-       virtual int workHeight() const { return workHeight_; }
-       ///
-       virtual void setScrollbarParams(int height, int pos, int line_height);
-
-       /// a selection exists
-       virtual void haveSelection(bool) const;
-
-       ///
-       virtual std::string const getClipboard() const;
-
-       ///
-       virtual void putClipboard(std::string const &) const;
-
-       ///
-       virtual void dragEnterEvent(QDragEnterEvent * event);
-
-       ///
-       virtual void dropEvent(QDropEvent* event);
-
-       /// return the widget's painter
-       virtual Painter & getPainter() { return (Painter &) painter_; }
-
-       /// return the backing pixmap
-       QPaintDevice * paintDevice() { return &paint_device_; }
-
-       /// update the passed area.
-       void update(int x, int y, int w, int h);
-
-       /// return a screen copy of the defined area.
-       QPixmap copyScreen(int x, int y, int w, int h) const;
-
-       /// Draw a pixmap onto the backing pixmap.
-       /**
-       QPixmap is implicitely shared so no need to pass by reference.
-       */
-       void drawScreen(int x, int y, QPixmap pixmap);
-       
-       LyXView & view() { return view_; }
-
-       // LyXScreen overloaded methods:
-
-       /// get the work area
-       virtual WorkArea & workarea();
-
-       /// copies specified area of pixmap to screen
-       virtual void expose(int x, int y, int exp_width, int exp_height);
-
-       /// paint the cursor and store the background
-       virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
-
-       /// hide the cursor
-       virtual void removeCursor();
-
-protected:
-
-       /// repaint part of the widget
-       void paintEvent(QPaintEvent * e);
-       /// widget has been resized
-       void resizeEvent(QResizeEvent * e);
-       /// mouse button press
-       void mousePressEvent(QMouseEvent * e);
-       /// mouse button release
-       void mouseReleaseEvent(QMouseEvent * e);
-       /// mouse double click of button
-       void mouseDoubleClickEvent(QMouseEvent * e);
-       /// mouse motion
-       void mouseMoveEvent(QMouseEvent * e);
-       /// wheel event
-       void wheelEvent(QWheelEvent * e);
-       /// key press
-       void keyPressEvent(QKeyEvent * e);
-
-#if USE_INPUT_METHODS
-protected:
-       /// IM events
-       void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
-#endif
-
-public slots:
-
-       /// Timeout event Slot for keyboard bufferring.
-       /// \todo This is not used currently in the code, remove?
-       void keyeventTimeout();
-
-       /// Adjust the LyX buffer view with the position of the scrollbar.
-       /**
-       * The action argument is not used in the the code, it is there
-       * only for the connection to the vertical srollbar signal which
-       * emits an 'int' action.
-       */
-       void adjustViewWithScrollBar(int action = 0);
-
-private:
-        ///
-        LyXView & view_;
-        
-       /// Buffer view width.
-       int workWidth_;
-
-       /// Buffer view height.
-       int workHeight_;
-
-       /// Our painter.
-       QLPainter painter_;
-
-       /// The slot connected to SyntheticMouseEvent::timeout.
-       void generateSyntheticMouseEvent();
-
-       ///
-       SyntheticMouseEvent synthetic_mouse_event_;
-
-       /// Our client side painting device.
-       //QImage paint_device_;
-       QPixmap paint_device_;
-
-       /// Our server side painting device.
-       //QPixmap screen_device_;
-
-       /// \todo remove
-       QTimer step_timer_;
-
-       /// \todo remove
-       std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
-
-       double_click dc_event_;
-
-       ///
-       int cursor_x_;
-       ///
-       int cursor_y_;
-       ///
-       int cursor_w_;
-       ///
-       int cursor_h_;
-       ///
-       QPixmap hcursor_;
-       ///
-       QPixmap vcursor_;
-       ///
-       bool show_hcursor_;
-       ///
-       bool show_vcursor_;
-       ///
-       bool lshape_cursor_;
-       ///
-       QColor cursor_color_;
-       ///
-       Cursor_Shape cursor_shape_;
-};
-
-#endif // QWORKAREA_H
index afcb82cee9d492ee66d667b9e96e14534bac1822..db07c73f227eca78cb36c936c890b3179d73731c 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author John Levon
  * \author Abdelrazak Younes
  *
@@ -71,7 +71,7 @@ int const statusbar_timer_value = 3000;
 
 
 QtView::QtView(unsigned int width, unsigned int height)
-       : QMainWindow(), LyXView(), commandbuffer_(0)
+       : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
 {
        mainWidget_ = this;
 
index 937629dd7e77122031b73dbc0ea28c81af13486a..ab18f8cf664d8f7fda535efa88556f5156a0bbfe 100644 (file)
@@ -17,6 +17,8 @@
 // Must be here because of moc.
 #include <config.h>
 
+#include "GuiImplementation.h"
+
 #include "frontends/LyXView.h"
 #include "funcrequest.h"
 
@@ -72,6 +74,9 @@ public:
        // returns true if this view has the focus.
        virtual bool hasFocus() const;
 
+       //
+       Gui & gui() { return frontend_; }
+
        static QMainWindow* mainWidget();
 
 public slots:
@@ -105,6 +110,8 @@ private:
 
        ///
        static QMainWindow* mainWidget_;
+
+       GuiImplementation frontend_;
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt4/WorkAreaFactory.C b/src/frontends/qt4/WorkAreaFactory.C
deleted file mode 100644 (file)
index 39748da..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * \file qt4/WorkAreaFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/WorkAreaFactory.h"
-#include "QWorkArea.h"
-
-namespace WorkAreaFactory {
-
-WorkArea * create(LyXView & owner, int w, int h)
-{
-       return new QWorkArea(owner, w, h);
-}
-
-} // namespace WorkAreaFactory
index ef49d88317aa5f251cae3af24ec2216c0d7c8931..84d674575b6f889520a914094a45c94d82bb0c34 100644 (file)
@@ -5,6 +5,7 @@
  *
  * \author unknown
  * \author John Levon
+ * \author Abdelrazak Younes
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "support/package.h"
 #include "debug.h"
 
-// Dear Lord, deliver us from Evil, aka the Qt headers
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
 
 #include "QLImage.h"
 #include "qt_helpers.h"
 #include "socket_callback.h"
-
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#endif
+#include "Application.h"
 
 #include <QApplication>
 #include <QEventLoop>
 #include <QLocale>
 #include <QLibraryInfo>
 
+
+
 using lyx::support::ltrim;
 using lyx::support::package;
 
 using lyx::frontend::QtView;
+using lyx::frontend::Application;
 
 namespace os = lyx::support::os;
 
@@ -77,9 +74,6 @@ using std::map;
 using std::vector;
 using std::string;
 
-
-extern BufferList bufferlist;
-
 // FIXME: wrong place !
 LyXServer * lyxserver;
 LyXServerSocket * lyxsocket;
@@ -107,78 +101,45 @@ void cleanup()
 // in QLyXKeySym.C
 extern void initEncodings();
 
-#ifdef Q_WS_X11
-extern bool lyxX11EventFilter(XEvent * xev);
-#endif
-
-#ifdef Q_WS_MACX
-extern bool macEventFilter(EventRef event);
-extern pascal OSErr
-handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
-                   long /*refCon*/);
-#endif
-
-class LQApplication : public QApplication
-{
-public:
-       LQApplication(int & argc, char ** argv);
-#ifdef Q_WS_X11
-       bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
-#endif
-#ifdef Q_WS_MACX
-       bool macEventFilter(EventRef event);
-#endif
-};
-
-
-LQApplication::LQApplication(int & argc, char ** argv)
-       : QApplication(argc, argv)
-{
-#ifdef Q_WS_MACX
-       AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
-                             NewAEEventHandlerUPP(handleOpenDocuments),
-                             0, false);
-#endif
-}
-
-
-#ifdef Q_WS_MACX
-bool LQApplication::macEventFilter(EventRef event)
-{
-       if (GetEventClass(event) == kEventClassAppleEvent) {
-               EventRecord eventrec;
-               ConvertEventRefToEventRecord(event, &eventrec);
-               AEProcessAppleEvent(&eventrec);
-
-               return false;
-       }
-       return false;
-}
-#endif
-
-
 namespace lyx_gui {
 
 bool use_gui = true;
 
-
 void exec(int & argc, char * argv[])
 {      
+       /*
+       FIXME : Abdel 29/05/2006 (younes.a@free.fr)
+       reorganize this code. In particular make sure that this
+       advice from Qt documentation is respected:
+       
+               Since the QApplication object does so much initialization, it
+               must be created before any other objects related to the user
+               interface are created.
+       
+       Right now this is not the case, I suspect that a number of global variables
+       contains Qt object that are initialized before the passage through
+       parse_init(). This might also explain the message displayed by Qt
+       that caused the hanging:
+
+       QObject::killTimer: timers cannot be stopped from another thread
+       */
+
        // Force adding of font path _before_ QApplication is initialized
        FontLoader::initFontPath();
 
 #ifdef Q_WS_WIN
-       static LQApplication app(argc, argv);
+       static Application app(argc, argv);
 #else
-       LQApplication app(argc, argv);
+       Application app(argc, argv);
 #endif
 
+
        // install translation file for Qt built-in dialogs
        // These are only installed since Qt 3.2.x
        QTranslator qt_trans;
        QString language_name = QString("qt_") + QLocale::system().name();
        language_name.truncate(5);
-       if (qt_trans.load(language_name, 
+       if (qt_trans.load(language_name,
                QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
        {
                qApp->installTranslator(&qt_trans);
diff --git a/src/frontends/screen.C b/src/frontends/screen.C
deleted file mode 100644 (file)
index dcd0221..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-/**
- * \file screen.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- *
- * Splash screen code added by Angus Leeming
- */
-
-#include <config.h>
-
-#include "screen.h"
-#include "font_metrics.h"
-#include "lyx_gui.h"
-#include "Painter.h"
-#include "WorkArea.h"
-
-#include "BufferView.h"
-#include "buffer.h"
-#include "bufferparams.h"
-#include "coordcache.h"
-#include "cursor.h"
-#include "debug.h"
-#include "language.h"
-#include "LColor.h"
-#include "lyxfont.h"
-#include "lyxrc.h"
-#include "lyxrow.h"
-#include "lyxtext.h"
-#include "metricsinfo.h"
-#include "paragraph.h"
-#include "rowpainter.h"
-#include "version.h"
-
-#include "graphics/GraphicsImage.h"
-#include "graphics/GraphicsLoader.h"
-
-#include "support/filetools.h" // LibFileSearch
-
-#include <boost/utility.hpp>
-#include <boost/bind.hpp>
-#include <boost/signals/trackable.hpp>
-
-using lyx::support::libFileSearch;
-
-using std::endl;
-using std::min;
-using std::max;
-using std::string;
-
-
-namespace {
-
-class SplashScreen : boost::noncopyable, boost::signals::trackable {
-public:
-       /// This is a singleton class. Get the instance.
-       static SplashScreen const & get();
-       ///
-       lyx::graphics::Image const * image() const { return loader_.image(); }
-       ///
-       string const & text() const { return text_; }
-       ///
-       LyXFont const & font() const { return font_; }
-       ///
-       void connect(lyx::graphics::Loader::slot_type const & slot) const {
-               loader_.connect(slot);
-       }
-       ///
-       void startLoading() const {
-               if (loader_.status() == lyx::graphics::WaitingToLoad)
-                       loader_.startLoading();
-       }
-
-private:
-       /** Make the c-tor private so we can control how many objects
-        *  are instantiated.
-        */
-       SplashScreen();
-
-       ///
-       lyx::graphics::Loader loader_;
-       /// The text to be written on top of the pixmap
-       string const text_;
-       /// in this font...
-       LyXFont font_;
-};
-
-
-SplashScreen const & SplashScreen::get()
-{
-       static SplashScreen singleton;
-       return singleton;
-}
-
-
-SplashScreen::SplashScreen()
-       : text_(lyx_version ? lyx_version : "unknown")
-{
-       if (!lyxrc.show_banner)
-               return;
-
-       string const file = libFileSearch("images", "banner", "ppm");
-       if (file.empty())
-               return;
-
-       // The font used to display the version info
-       font_.setFamily(LyXFont::SANS_FAMILY);
-       font_.setSeries(LyXFont::BOLD_SERIES);
-       font_.setSize(LyXFont::SIZE_NORMAL);
-       font_.setColor(LColor::yellow);
-
-       // Load up the graphics file
-       loader_.reset(file);
-}
-
-} // namespace anon
-
-
-LyXScreen::LyXScreen()
-       : greyed_out_(true), cursor_visible_(false)
-{
-       // Start loading the pixmap as soon as possible
-       if (lyxrc.show_banner) {
-               SplashScreen const & splash = SplashScreen::get();
-               splash.connect(boost::bind(&LyXScreen::checkAndGreyOut, this));
-               splash.startLoading();
-       }
-}
-
-
-LyXScreen::~LyXScreen()
-{
-}
-
-
-void LyXScreen::checkAndGreyOut()
-{
-       if (greyed_out_)
-               greyOut();
-}
-
-
-void LyXScreen::showCursor(BufferView & bv)
-{
-       if (cursor_visible_)
-               return;
-
-       if (!bv.available())
-               return;
-
-       Cursor_Shape shape = BAR_SHAPE;
-
-       LyXText const & text = *bv.getLyXText();
-       LyXFont const & realfont = text.real_current_font;
-       BufferParams const & bp = bv.buffer()->params();
-       bool const samelang = realfont.language() == bp.language;
-       bool const isrtl = realfont.isVisibleRightToLeft();
-
-       if (!samelang || isrtl != bp.language->rightToLeft()) {
-               shape = L_SHAPE;
-               if (isrtl)
-                       shape = REVERSED_L_SHAPE;
-       }
-
-       // The ERT language hack needs fixing up
-       if (realfont.language() == latex_language)
-               shape = BAR_SHAPE;
-
-       LyXFont const font = bv.cursor().getFont();
-       int const asc = font_metrics::maxAscent(font);
-       int const des = font_metrics::maxDescent(font);
-       int h = asc + des;
-       int x = 0;
-       int y = 0;
-       bv.cursor().getPos(x, y);
-       y -= asc;
-       //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
-
-       // if it doesn't touch the screen, don't try to show it
-       if (y + h < 0 || y >= workarea().workHeight())
-               return;
-
-       cursor_visible_ = true;
-       showCursor(x, y, h, shape);
-}
-
-
-void LyXScreen::hideCursor()
-{
-       if (!cursor_visible_)
-               return;
-
-       cursor_visible_ = false;
-       removeCursor();
-}
-
-
-void LyXScreen::toggleCursor(BufferView & bv)
-{
-       if (cursor_visible_)
-               hideCursor();
-       else
-               showCursor(bv);
-}
-
-
-void LyXScreen::prepareCursor()
-{
-       cursor_visible_ = false;
-}
-
-
-void LyXScreen::redraw(BufferView & bv, ViewMetricsInfo const & vi)
-{
-       greyed_out_ = false;
-       workarea().getPainter().start();
-       paintText(bv, vi);
-       lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
-       int const ymin = std::max(vi.y1, 0);
-       int const ymax =
-               ( vi.p2 < vi.size - 1 ?  vi.y2 : workarea().workHeight() );
-       expose(0, ymin, workarea().workWidth(), ymax - ymin);
-       workarea().getPainter().end();
-       theCoords.doneUpdating();
-}
-
-
-void LyXScreen::greyOut()
-{
-       greyed_out_ = true;
-       workarea().getPainter().start();
-
-       workarea().getPainter().fillRectangle(0, 0,
-               workarea().workWidth(),
-               workarea().workHeight(),
-               LColor::bottomarea);
-
-       // Add a splash screen to the centre of the work area
-       SplashScreen const & splash = SplashScreen::get();
-       lyx::graphics::Image const * const splash_image = splash.image();
-       if (splash_image) {
-               int const w = splash_image->getWidth();
-               int const h = splash_image->getHeight();
-
-               int x = (workarea().workWidth() - w) / 2;
-               int y = (workarea().workHeight() - h) / 2;
-
-               workarea().getPainter().image(x, y, w, h, *splash_image);
-
-               x += 260;
-               y += 265;
-
-               workarea().getPainter().text(x, y, splash.text(), splash.font());
-       }
-       expose(0, 0, workarea().workWidth(), workarea().workHeight());
-       workarea().getPainter().end();
-}
diff --git a/src/frontends/screen.h b/src/frontends/screen.h
deleted file mode 100644 (file)
index 1c2825f..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-// -*- C++ -*-
-/**
- * \file screen.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef SCREEN_H
-#define SCREEN_H
-
-
-class LyXText;
-class CursorSlice;
-class WorkArea;
-class BufferView;
-class ViewMetricsInfo;
-
-
-/**
- * LyXScreen - document rendering management
- *
- * This class is used to manage the on-screen rendering inside the
- * work area; it is responsible for deciding which LyXText rows
- * need re-drawing.
- *
- * This class will arrange for LyXText to paint onto a pixmap
- * provided by the WorkArea widget.
- *
- * The blinking cursor is also handled here.
- */
-class LyXScreen {
-public:
-       LyXScreen();
-
-       virtual ~LyXScreen();
-
-       /// redraw the screen, without using existing pixmap
-       virtual void redraw(BufferView & bv, ViewMetricsInfo const & vi);
-
-       /// grey out (no buffer)
-       void greyOut();
-
-       /// hide the visible cursor, if it is visible
-       void hideCursor();
-
-       /// show the cursor if it is not visible
-       void showCursor(BufferView & bv);
-
-       /// toggle the cursor's visibility
-       void toggleCursor(BufferView & bv);
-
-       /// set cursor_visible_ to false in prep for re-display
-       void prepareCursor();
-
-
-protected:
-       /// cause the display of the given area of the work area
-       virtual void expose(int x, int y, int w, int h) = 0;
-
-       /// get the work area
-       virtual WorkArea & workarea() = 0;
-
-       /// types of cursor in work area
-       enum Cursor_Shape {
-               /// normal I-beam
-               BAR_SHAPE,
-               /// L-shape for locked insets of a different language
-               L_SHAPE,
-               /// reverse L-shape for RTL text
-               REVERSED_L_SHAPE
-       };
-
-       /// paint the cursor and store the background
-       virtual void showCursor(int x, int y, int h, Cursor_Shape shape) = 0;
-
-       /// hide the cursor
-       virtual void removeCursor() = 0;
-
-private:
-       ///
-       void checkAndGreyOut();
-
-       ///
-       bool greyed_out_;
-
-       /// is the cursor currently displayed
-       bool cursor_visible_;
-
-};
-
-#endif // SCREEN_H
diff --git a/src/frontends/xforms/GuiClipboard.h b/src/frontends/xforms/GuiClipboard.h
new file mode 100644 (file)
index 0000000..04ab2f2
--- /dev/null
@@ -0,0 +1,63 @@
+// -*- C++ -*-
+/**
+ * \file xforms/GuiClipboard.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CLIPBOARD_H
+#define CLIPBOARD_H
+
+#include "frontends/Clipboard.h"
+
+#include "XWorkArea.h"
+
+namespace lyx {
+namespace frontend {
+
+typedef XWorkArea FWorkArea;
+
+/**
+ * The XForms version of the Clipboard.
+ */
+class GuiClipboard: public lyx::frontend::Clipboard
+{
+public:
+       GuiClipboard(FWorkArea * work_area)
+               : old_work_area_(work_area)
+       {
+       }
+
+       virtual ~GuiClipboard() {}
+
+       /** ClipBoard overloaded methods
+        */
+       //@{
+       void haveSelection(bool own)
+       {
+               old_work_area_->haveSelection(own);
+       }
+
+       std::string const get() const
+       {
+               return old_work_area_->getClipboard();
+       }
+
+       void put(std::string const & str)
+       {
+               old_work_area_->putClipboard(str);
+       }
+       //@}
+
+private:
+       FWorkArea * old_work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // CLIPBOARD_H
diff --git a/src/frontends/xforms/GuiImplementation.h b/src/frontends/xforms/GuiImplementation.h
new file mode 100644 (file)
index 0000000..124b708
--- /dev/null
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+/**
+ * \file xforms/GuiImplementation.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUI_IMPLEMENTATION_H
+#define GUI_IMPLEMENTATION_H
+
+#include "frontends/Gui.h"
+#include "frontends/LyXView.h"
+
+#include "xscreen.h"
+#include "XWorkArea.h"
+
+#include "GuiClipboard.h"
+#include "GuiWorkArea.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include <map>
+
+namespace lyx {
+namespace frontend {
+
+typedef XScreen FScreen;
+typedef XWorkArea FWorkArea;
+
+/**
+ * The Gui class is the interface to all XForms components.
+ */
+class GuiImplementation: public lyx::frontend::Gui
+{
+public:
+       GuiImplementation(LyXView & owner): owner_(owner)
+       {
+       }
+
+       virtual ~GuiImplementation()
+       {
+       }
+
+       lyx::frontend::Clipboard& clipboard()
+       {
+               return *clipboard_;
+       }
+
+       int newWorkArea(int w, int h)
+       {
+               old_work_area_.reset(new FWorkArea(owner_, w, h));
+               old_screen_.reset(new FScreen(*old_work_area_.get()));
+               work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get()));
+               clipboard_.reset(new GuiClipboard(old_work_area_.get()));
+               guiCursor().connect(work_area_.get());
+       }
+
+       lyx::frontend::WorkArea& workArea(int id)
+       {
+               return *work_area_;
+       }
+
+       void destroyWorkArea(int id)
+       {
+               clipboard_.reset();
+               work_area_.reset();
+               old_work_area_.reset();
+               old_screen_.reset();
+       }
+
+private:
+       ///
+       boost::shared_ptr<GuiClipboard> clipboard_;
+       ///
+       boost::shared_ptr<GuiWorkArea> work_area_;
+       ///
+       boost::shared_ptr<FWorkArea> old_work_area_;
+       ///
+       boost::shared_ptr<FScreen> old_screen_;
+       ///
+       LyXView & owner_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUI_IMPLEMENTATION_H
diff --git a/src/frontends/xforms/GuiWorkArea.h b/src/frontends/xforms/GuiWorkArea.h
new file mode 100644 (file)
index 0000000..a595e6f
--- /dev/null
@@ -0,0 +1,98 @@
+// -*- C++ -*-
+/**
+ * \file xforms/WorkArea.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef WORKAREA_H
+#define WORKAREA_H
+
+#include "frontends/WorkArea.h"
+
+#include "xscreen.h"
+#include "XWorkArea.h"
+
+namespace lyx {
+namespace frontend {
+
+typedef XScreen FScreen;
+typedef XWorkArea FWorkArea;
+
+/**
+ * Temporary wrapper around XWorkArea and XScreen.
+ * Please refer to the Qt4 implementation for a proper cleanup of the API.
+ */
+class GuiWorkArea: public lyx::frontend::WorkArea {
+public:
+       GuiWorkArea(LyXView & owner, int w, int h,
+               FScreen * screen, FWorkArea * work_area)
+               : lyx::frontend::WorkArea(owner, w, h),
+               old_screen_(screen), old_work_area_(work_area)
+       {
+       }
+
+       ~GuiWorkArea() {}
+
+       /// return the painter object for this work area
+       virtual lyx::frontend::Painter & getPainter()
+       {
+               return old_work_area_->getPainter();
+       }
+
+       /// return the width of the work area in pixels
+       virtual int width() const
+       {
+               return old_work_area_->workWidth();
+       }
+
+       /// return the height of the work area in pixels
+       virtual int height() const
+       {
+               return old_work_area_->workHeight();
+       }
+
+       /**
+        * Update the scrollbar.
+        * @param height the total document height in pixels
+        * @param pos the current position in the document, in pixels
+        * @param line_height the line-scroll amount, in pixels
+        */
+       virtual void setScrollbarParams(int height, int pos, int line_height)
+       {
+               old_work_area_->setScrollbarParams(height, pos, line_height);
+       }
+
+
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape)
+       {
+               old_screen_->showCursor(x, y, h, shape);
+       }
+
+       /// hide the cursor
+       virtual void removeCursor()
+       {
+               old_screen_->removeCursor();
+       }
+
+protected:
+       /// cause the display of the given area of the work area
+       virtual void expose(int x, int y, int w, int h)
+       {
+               old_screen_->expose(x, y, w, h);
+       }
+
+private:
+       FScreen * old_screen_;
+       FWorkArea * old_work_area_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // WORKAREA_H
diff --git a/src/frontends/xforms/LyXScreenFactory.C b/src/frontends/xforms/LyXScreenFactory.C
deleted file mode 100644 (file)
index 6e007f0..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * \file xforms/LyXScreenFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/LyXScreenFactory.h"
-
-#include "xscreen.h"
-#include "XWorkArea.h"
-
-
-namespace LyXScreenFactory {
-
-LyXScreen * create(WorkArea & owner)
-{
-       using lyx::frontend::XScreen;
-       using lyx::frontend::XWorkArea;
-
-       return new XScreen(static_cast<XWorkArea &>(owner));
-}
-
-}
index ed4d9a1635082125308df6dc201ad5232ca1daf0..a7afd7cd64a2a5c96e25222796bf9ec375b61cdc 100644 (file)
@@ -156,10 +156,12 @@ libxforms_la_SOURCES = \
        FormVSpace.h \
        FormWrap.C \
        FormWrap.h \
+       GuiClipboard.h \
+       GuiImplementation.h \
+       GuiWorkArea.h \
        LayoutEngine.C \
        LayoutEngine.h \
        LyXKeySymFactory.C \
-       LyXScreenFactory.C \
        XFormsMenubar.C \
        XFormsMenubar.h \
        RadioButtonGroup.C \
@@ -168,7 +170,6 @@ libxforms_la_SOURCES = \
        XFormsToolbar.h \
        Tooltips.C \
        Tooltips.h \
-       WorkAreaFactory.C \
        XFormsView.C \
        XFormsView.h \
        XLyXKeySym.C \
diff --git a/src/frontends/xforms/WorkAreaFactory.C b/src/frontends/xforms/WorkAreaFactory.C
deleted file mode 100644 (file)
index 3b186a1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * \file xforms/WorkAreaFactory.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/WorkAreaFactory.h"
-#include "XWorkArea.h"
-
-
-namespace WorkAreaFactory {
-
-WorkArea * create(LyXView & owner, int w, int h)
-{
-       return new lyx::frontend::XWorkArea(owner, w, h);
-}
-
-}
index 86dfcbc5445740c34365e58de2c41cff71ba8a01..62410a03e42536c324420f97a7aa65d768b8d18c 100644 (file)
@@ -74,7 +74,7 @@ void print_metrics(std::ostream & os, std::string const & name, Box const & box)
 XFormsView::XFormsView(int width, int height)
        : LyXView(),
          window_(Box(width, height)),
-         icon_pixmap_(0), icon_mask_(0)
+         icon_pixmap_(0), icon_mask_(0), frontend_(*this)
 {
        int const air = 2;
 
index 45e58ff870d738c9bfbc83f22508aeaa5068b01d..91099b00dbe05fbd4f47db3eb04495adb77351c1 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef LyXView_H
 #define LyXView_H
 
+#include "GuiImplementation.h"
 #include "LayoutEngine.h"
 #include "forms_fwd.h"
 
@@ -82,6 +83,9 @@ public:
        // returns true if this view has the focus.
        virtual bool hasFocus() const;
 
+       ///
+       Gui & gui() { return frontend_; }
+
 private:
        /**
         * setWindowTitle - set title of window
@@ -116,6 +120,8 @@ private:
        Pixmap icon_pixmap_;
        ///
        Pixmap icon_mask_;
+       ///
+       GuiImplementation frontend_;
 };
 
 } // namespace frontend
index df5d2632646510db12a80f3bbbf25bdb24d04225..b4e131ef75f6f6d6ef89a085e5fe0dc0b78b1b2e 100644 (file)
@@ -613,7 +613,7 @@ int XWorkArea::event_cb(XEvent * xev)
 }
 
 
-void XWorkArea::haveSelection(bool yes) const
+void XWorkArea::haveSelection(bool yes)
 {
        Window const owner = yes ? FL_ObjWin(work_area) : None;
        XSetSelectionOwner(fl_get_display(), XA_PRIMARY, owner, CurrentTime);
@@ -642,7 +642,7 @@ string const XWorkArea::getClipboard() const
 }
 
 
-void XWorkArea::putClipboard(string const & s) const
+void XWorkArea::putClipboard(string const & s)
 {
        static string hold;
        hold = s;
index 9138fdd50ad62ad51b2744ddc348c51427b1b1cc..2f83c933a69aeb5bda2bf0a1290888492baab49d 100644 (file)
@@ -14,6 +14,7 @@
 #define XWORKAREA_H
 
 #include "frontends/WorkArea.h"
+#include "frontends/Clipboard.h"
 #include "XPainter.h"
 
 #include "LayoutEngine.h"
@@ -25,7 +26,7 @@ class LyXView;
 namespace lyx {
 namespace frontend {
 
-class XWorkArea : public WorkArea {
+class XWorkArea {
 public:
        ///
        XWorkArea(LyXView & owner, int width, int height);
@@ -56,11 +57,11 @@ public:
        /// xforms callback from scrollbar
        void scroll_cb();
        /// a selection exists
-       virtual void haveSelection(bool) const;
+       virtual void haveSelection(bool);
        ///
        virtual std::string const getClipboard() const;
        ///
-       virtual void putClipboard(std::string const &) const;
+       virtual void putClipboard(std::string const &);
 
        /// handles SelectionRequest X Event, to fill the clipboard
        int event_cb(XEvent * xev);
index 1c903ba878373c8c95a3f0616499f12cd64b2177..640b881f6364d5dbab61b141eb5456ebee971134 100644 (file)
@@ -45,7 +45,7 @@ GC createGC()
 
 
 XScreen::XScreen(XWorkArea & o)
-       : LyXScreen(), owner_(o), nocursor_pixmap_(0),
+       : owner_(o), nocursor_pixmap_(0),
        cursor_x_(0), cursor_y_(0), cursor_w_(0), cursor_h_(0)
 {
        // We need this GC
@@ -59,12 +59,6 @@ XScreen::~XScreen()
 }
 
 
-WorkArea & XScreen::workarea()
-{
-       return owner_;
-}
-
-
 void XScreen::setCursorColor()
 {
        if (!lyxColorHandler.get())
index 829ac96230bf28a18f91155b706d6c27efd1fa57..27f1d2c3f4c92cef6af0359e1c243c898c6ff1ce 100644 (file)
@@ -13,7 +13,8 @@
 #ifndef XSCREEN_H
 #define XSCREEN_H
 
-#include "screen.h"
+#include "frontends/GuiCursor.h"
+
 #include <X11/Xlib.h> // for Pixmap, GC
 
 class WorkArea;
@@ -28,7 +29,7 @@ class XWorkArea;
     date and used to optimize drawing on the screen.
     This class also handles the drawing of the cursor and partly the selection.
  */
-class XScreen : public LyXScreen {
+class XScreen {
 public:
        ///
        XScreen(XWorkArea &);
@@ -39,10 +40,6 @@ public:
        /// Sets the cursor color to LColor::cursor.
        virtual void setCursorColor();
 
-protected:
-       /// get the work area
-       virtual WorkArea & workarea();
-
        /// Copies specified area of pixmap to screen
        virtual void expose(int x, int y, int w, int h);
 
index 9455eabbb2c58ef959c18b426de36d32904029fd..61493dac2363892c5a908e2dd49afe7659f4045b 100644 (file)
 #include "box.h"
 #include "lyxfont.h"
 
-class Painter;
 class LyXText;
 class Paragraph;
 class CursorSlice;
 
+namespace lyx {
+namespace frontend {
+class Painter;
+}
+}
+
+
 /** A collapsable text inset
 
 */
index 3a256920eacd48a4f644dca4a46d881b8a8c1ffb..62d724214272064657674f99e6ad33170734af6c 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "frontends/Painter.h"
 
+using lyx::frontend::Painter;
+
 using std::endl;
 using std::ostream;
 
index d86a826be59a97c10767a61a616c3f40cd30a650..cb417630c7ce8fc3ea22ae0698e25dd7d5386db7 100644 (file)
@@ -21,6 +21,8 @@
 #include "frontends/Painter.h"
 #include "frontends/font_metrics.h"
 
+using lyx::frontend::Painter;
+
 using std::endl;
 using std::ostream;
 
index 5b1bc8b8141a8cbc1c31364d9d49dbb44220a238..95e27e5f0cf74e637094b6d0a492a0cc12ffed61 100644 (file)
@@ -53,6 +53,8 @@ using lyx::graphics::PreviewLoader;
 
 using lyx::support::ltrim;
 
+using lyx::frontend::Painter;
+
 using boost::shared_ptr;
 
 using std::auto_ptr;
@@ -284,7 +286,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
        //lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
        BufferView * bv = pi.base.bv;
 
-       static NullPainter nop;
+       static lyx::frontend::NullPainter nop;
        static PainterInfo nullpi(bv, nop);
 
        //resetPos(bv->cursor());
index 5f14aeef73a43ec9953704bbc97d34063ab793ad..145f8548124445b7d9dec363c036960118951d20 100644 (file)
 
 class FuncStatus;
 class LyXLex;
-class Painter;
 class BufferView;
 class Buffer;
 class BufferParams;
 class Paragraph;
 class CursorSlice;
 
+namespace lyx {
+namespace frontend {
+class Painter;
+}
+}
+
 
 class InsetTabular : public InsetOld {
 public:
@@ -154,7 +159,7 @@ private:
        virtual std::auto_ptr<InsetBase> doClone() const;
 
        ///
-       void drawCellLines(Painter &, int x, int y, row_type row,
+       void drawCellLines(lyx::frontend::Painter &, int x, int y, row_type row,
                           idx_type cell, bool erased) const;
        ///
        void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
index dbb957d7746445cfa41a572dd948fe70f14ce799..8eb3931562fb88622b3d429c3ebdf7cd4e7f792f 100644 (file)
@@ -334,9 +334,6 @@ public:
        /// delete double space or empty paragraphs around old cursor
        bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
 
-       ///
-       friend class LyXScreen;
-
 public:
        ///
        Dimension dim_;
index 05af75303894277ed1c2a6a740b4804bc51a7816..d4967a70488691c23050c32df63d42e33d19b1fc 100644 (file)
@@ -229,7 +229,7 @@ void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
                return;
 
        // FIXME: hack to get position cache warm
-       static NullPainter nop;
+       static lyx::frontend::NullPainter nop;
        PainterInfo pinop(pi);
        pinop.pain = nop;
        draw(pinop, x, y);
index 0b8c139ddb9039e6858aa2c2fd8b350474f84cb3..7832135bc7a1abcb1f7c0a08991fa9490186a589 100644 (file)
@@ -27,6 +27,7 @@
 #include <map>
 #include <sstream>
 
+using lyx::frontend::Painter;
 
 using std::string;
 using std::max;
index 9d6568640c1a1cea9dca85f3aa48e2a0a741b219..63d6f2eae3f133006697bcbf2b86fb26c472bb92 100644 (file)
@@ -46,7 +46,7 @@ MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
 
 
 
-PainterInfo::PainterInfo(BufferView * bv, Painter & painter)
+PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
        : pain(painter), ltr_pos(false), erased_(false)
 {
        base.bv = bv;
index e7d3eeb36073a33b9c90c6e44703b3b1c4da13c9..84163116955aed6655a96635074848916987a527 100644 (file)
 
 #include <string>
 
-class Painter;
 class BufferView;
 
+namespace lyx {
+namespace frontend {
+class Painter;
+}
+}
+
 
 /// Standard Sizes (mode styles)
 enum Styles {
@@ -80,7 +85,7 @@ public:
 class PainterInfo {
 public:
        ///
-       PainterInfo(BufferView * bv, Painter & pain);
+       PainterInfo(BufferView * bv, lyx::frontend::Painter & pain);
        ///
        void draw(int x, int y, char c);
        ///
@@ -89,7 +94,7 @@ public:
        ///
        MetricsBase base;
        ///
-       Painter & pain;
+       lyx::frontend::Painter & pain;
        /// Whether the text at this point is right-to-left (for InsetNewline)
        bool ltr_pos;
        /// Whether the parent is deleted (change tracking)
index 3945d80ae71b42819191a44b62cae84c6b53a796..a82f7fa3bc1bd01befe830fb445217e23737eda5 100644 (file)
@@ -42,6 +42,8 @@
 
 #include <boost/crc.hpp>
 
+using lyx::frontend::Painter;
+using lyx::frontend::NullPainter;
 using lyx::char_type;
 using lyx::pos_type;
 using lyx::pit_type;
index b4b70f0f0c5f7488abf2e40ad23ada02bca8143a..fe8a86c5a164b6ac86d0d162d1af9d42066b9b58 100644 (file)
@@ -546,6 +546,27 @@ int findToken(char const * const str[], string const & search_token)
 }
 
 
+string const externalLineEnding(string const & str)
+{
+#if defined(__APPLE__)
+       // The MAC clipboard uses \r for lineendings, and we use \n
+       return subst(str, '\n', '\r');
+#elif defined (_WIN32) || (defined (__CYGWIN__) && defined (X_DISPLAY_MISSING))
+       // Windows clipboard uses \r\n for lineendings, and we use \n
+       return subst(str, "\n", "\r\n");
+#else
+       return str;
+#endif
+}
+
+
+string const internalLineEnding(string const & str)
+{
+       string s = subst(str, "\r\n", "\n");
+       return subst(s, '\r', '\n');
+}
+
+
 #ifndef I_AM_NOT_AFRAID_OF_HEADER_LIBRARIES
 #if USE_BOOST_FORMAT
 
index 0ef0806edd97c22c2d0289457d6425b24864b1c9..2b03e42b784173f1d0e14365a8ec42fbf0396ec6 100644 (file)
@@ -180,6 +180,12 @@ std::string const getStringFromVector(std::vector<std::string> const & vec,
 /// found, else -1. The last item in \p str must be "".
 int findToken(char const * const str[], std::string const & search_token);
 
+/// Convert internal line endings to line endings as expected by the OS
+std::string const externalLineEnding(std::string const & str);
+
+/// Convert line endings in any formnat to internal line endings
+std::string const internalLineEnding(std::string const & str);
+
 
 #ifdef I_AM_NOT_AFRAID_OF_HEADER_LIBRARIES