]> git.lyx.org Git - features.git/commitdiff
make it compile again
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 22 Sep 2006 20:48:42 +0000 (20:48 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 22 Sep 2006 20:48:42 +0000 (20:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15131 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
development/scons/scons_manifest.py
src/frontends/qt3/GuiApplication.C [new file with mode: 0644]
src/frontends/qt3/GuiApplication.h [new file with mode: 0644]
src/frontends/qt3/GuiImplementation.h
src/frontends/qt3/GuiSelection.C
src/frontends/qt3/GuiSelection.h
src/frontends/qt3/Makefile.am
src/frontends/qt3/QWorkArea.C
src/frontends/qt3/QWorkArea.h
src/frontends/qt3/QtView.C
src/frontends/qt3/QtView.h
src/frontends/qt3/lyx_gui.C

index 5a9559c23c448badd817ee9b5af0552e10ab049c..8bc2869f9910d31c418a08d7dab0862bdf7ddd41 100644 (file)
@@ -732,6 +732,7 @@ src_frontends_qt3_moc_files = Split('''
 src_frontends_qt3_header_files = Split('''
     BulletsModule.h
     FileDialog_private.h
+    GuiApplication.h
     GuiClipboard.h
     GuiImplementation.h
     GuiSelection.h
@@ -852,6 +853,7 @@ src_frontends_qt3_files = Split('''
     Dialogs.C
     FileDialog.C
     FileDialog_private.C
+    GuiApplication.C
     GuiClipboard.C
     GuiSelection.C
     LyXKeySymFactory.C
diff --git a/src/frontends/qt3/GuiApplication.C b/src/frontends/qt3/GuiApplication.C
new file mode 100644 (file)
index 0000000..894db2a
--- /dev/null
@@ -0,0 +1,319 @@
+/**
+ * \file qt3/GuiApplication.C
+ * 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.
+ */
+
+#include <config.h>
+
+#include "frontends/LyXView.h"
+#include "frontends/WorkArea.h"
+
+#include "GuiApplication.h"
+
+#include "QtView.h"
+#include "GuiWorkArea.h"
+#include "qt_helpers.h"
+#include "QLImage.h"
+
+#include "BufferView.h"
+
+#include "graphics/LoaderQueue.h"
+
+#include "support/lstrings.h"
+#include "support/os.h"
+#include "support/package.h"
+
+#include "lyx_main.h"
+#include "lyxrc.h"
+#include "debug.h"
+
+#include <qapplication.h>
+#include <qclipboard.h>
+#include <qeventloop.h>
+#include <qlocale.h>
+#include <qpaintdevicemetrics.h>
+#include <qtextcodec.h>
+#include <qtranslator.h>
+
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#endif
+
+#include <boost/bind.hpp>
+
+using lyx::support::subst;
+
+using std::string;
+using std::endl;
+
+// in QLyXKeySym.C
+extern void initEncodings();
+
+///////////////////////////////////////////////////////////////
+// You can find other X11 and MACX specific stuff
+// at the end of this file...
+///////////////////////////////////////////////////////////////
+
+namespace {
+
+int getDPI()
+{
+       QWidget w;
+       QPaintDeviceMetrics pdm(&w);
+       return int(0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY()));
+}
+
+} // namespace anon
+
+
+namespace lyx {
+namespace frontend {
+
+GuiApplication::GuiApplication(int & argc, char ** argv)
+       : QApplication(argc, argv), Application(argc, argv)
+{
+#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
+       AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
+                             NewAEEventHandlerUPP(handleOpenDocuments),
+                             0, false);
+#endif
+
+#if QT_VERSION >= 0x030200
+       // install translation file for Qt built-in dialogs
+       // These are only installed since Qt 3.2.x
+       QTranslator qt_trans(0);
+       if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
+                               qInstallPathTranslations())) {
+               qApp->installTranslator(&qt_trans);
+               // even if the language calls for RtL, don't do that
+               qApp->setReverseLayout(false);
+               lyxerr[Debug::GUI]
+                       << "Successfully installed Qt translations for locale "
+                       << QTextCodec::locale() << std::endl;
+       } else
+               lyxerr[Debug::GUI]
+                       << "Could not find  Qt translations for locale "
+                       << QTextCodec::locale() << std::endl;
+#endif
+
+#ifdef Q_WS_MACX
+       // These translations are meant to break Qt/Mac menu merging
+       // algorithm on some entries. It lists the menu names that
+       // should not be moved to the LyX menu
+       QTranslator aqua_trans(0);
+       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
+                                            "do_not_merge_me"));
+       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
+                                            "do_not_merge_me"));
+       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
+                                            "do_not_merge_me"));
+       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
+                                            "do_not_merge_me"));
+
+       qApp->installTranslator(&aqua_trans);
+#endif
+
+       using namespace lyx::graphics;
+
+       Image::newImage = boost::bind(&QLImage::newImage);
+       Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
+
+       // needs to be done before reading lyxrc
+       lyxrc.dpi = getDPI();
+
+       LoaderQueue::setPriority(10,100);
+}
+
+
+Clipboard& GuiApplication::clipboard()
+{
+       return clipboard_;
+}
+
+
+Selection& GuiApplication::selection()
+{
+       return selection_;
+}
+
+
+int const GuiApplication::exec()
+{
+       return QApplication::exec();
+}
+
+
+void GuiApplication::exit(int status)
+{
+       QApplication::exit(status);
+}
+
+
+// FIXME: this whole method needs to be moved to Application.
+LyXView & GuiApplication::createView(unsigned int width,
+                                                                         unsigned int height,
+                                                                         int posx, int posy,
+                                                                         bool maximize)
+{
+       // this can't be done before because it needs the Languages object
+       initEncodings();
+
+       int view_id = gui().newView(width, height);
+       QtView & view = static_cast<QtView &> (gui().view(view_id));
+
+       lyxfunc_.reset(new LyXFunc(&view));
+
+       // FIXME: for now we assume that there is only one LyXView with id = 0.
+       /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
+       //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
+
+       LyX::ref().addLyXView(&view);
+
+       view.init();
+
+       // FIXME: put this initialisation code in GuiView accessible via
+       // a pure virtual method in LyXView.
+
+       // only true when the -geometry option was NOT used
+       if (width != 0 && height != 0) {
+               view.initFloatingGeometry(QRect(posx, posy, width, height));
+               view.resize(width, height);
+               if (posx != -1 && posy != -1)
+                       view.move(posx, posy);
+               view.show();
+               if (maximize)
+                       view.setWindowState(Qt::WindowMaximized);
+       } else
+               view.show();
+
+       return view;
+}
+
+
+////////////////////////////////////////////////////////////////////////
+// X11 specific stuff goes here...
+#ifdef Q_WS_X11
+bool GuiApplication::x11EventFilter(XEvent * xev)
+{
+       switch (xev->type) {
+       case SelectionRequest:
+               lyxerr[Debug::GUI] << "X requested selection." << endl;
+               if (buffer_view_) {
+                       lyx::docstring const sel = buffer_view_->requestSelection();
+                       if (!sel.empty())
+                               selection_.put(sel);
+               }
+               break;
+       case SelectionClear:
+               lyxerr[Debug::GUI] << "Lost selection." << endl;
+               if (buffer_view_)
+                       buffer_view_->clearSelection();
+               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;
+       }
+ }
+
+} // namespace
+
+OSErr GuiApplication::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);
+//                                     buffer_view_->workAreaDispatch(
+//                                             FuncRequest(LFUN_FILE_OPEN,
+//                                                         fromqstr(s_arg)));
+                                       break;
+                               }
+                       }
+               } // for ...
+       }
+       AEDisposeDesc(&documentList);
+
+       return err;
+}
+
+bool GuiApplication::macEventFilter(EventRef event)
+{
+       if (GetEventClass(event) == kEventClassAppleEvent) {
+               EventRecord eventrec;
+               ConvertEventRefToEventRecord(event, &eventrec);
+               AEProcessAppleEvent(&eventrec);
+
+               return false;
+       }
+       return false;
+}
+
+#endif  // Q_WS_MACX
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt3/GuiApplication.h b/src/frontends/qt3/GuiApplication.h
new file mode 100644 (file)
index 0000000..6b8d938
--- /dev/null
@@ -0,0 +1,100 @@
+/**
+ * \file qt3/GuiApplication.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 QT3_APPLICATION_H
+#define QT3_APPLICATION_H
+
+#include "frontends/Application.h"
+
+#include "qfont_loader.h"
+#include "GuiClipboard.h"
+#include "GuiImplementation.h"
+#include "GuiSelection.h"
+
+#include <qapplication.h>
+
+///////////////////////////////////////////////////////////////
+// Specific stuff
+
+#ifdef Q_WS_MACX
+#include <Carbon/Carbon.h>
+#endif
+///////////////////////////////////////////////////////////////
+
+class BufferView;
+
+namespace lyx {
+namespace frontend {
+
+class GuiWorkArea;
+
+/// The Qt main application class
+/**
+There should be only one instance of this class. No Qt object
+initialisation should be done before the instanciation of this class.
+
+\todo The work areas handling could be moved to a base virtual class
+comon to all frontends.
+*/
+class GuiApplication : public QApplication, public Application
+{
+public:
+       GuiApplication(int & argc, char ** argv);
+
+       /// Method inherited from \c Application class
+       //@{
+       virtual Clipboard& clipboard();
+       virtual Selection& selection();
+       virtual int const exec();
+       virtual Gui & gui() { return gui_; }
+       virtual void exit(int status);
+       //@}
+
+       ///
+       FontLoader & fontLoader() { return font_loader_; }
+
+       ///
+       LyXView & createView(unsigned int width, unsigned int height,
+               int posx, int posy, bool maximize);
+
+private:
+       ///
+       GuiImplementation gui_;
+       ///
+       GuiClipboard clipboard_;
+       ///
+       GuiSelection selection_;
+       ///
+       FontLoader font_loader_;
+
+#ifdef Q_WS_X11
+public:
+       bool x11EventFilter (XEvent * ev);
+#endif
+
+#ifdef Q_WS_MACX
+public:
+       bool macEventFilter(EventRef event);
+private:
+//     static OSStatus handleOpenDocuments(
+       static pascal OSErr     handleOpenDocuments(
+               const AppleEvent* inEvent, AppleEvent*, long);
+#endif
+}; // GuiApplication
+
+} // namespace frontend
+} // namespace lyx
+
+extern lyx::frontend::GuiApplication * guiApp;
+
+
+#endif // QT3_APPLICATION_H
index d74def1331b19f0a38704ba41f166098f85f519d..30b4725bea47f6a68ac2955e24d43c5b69efe71e 100644 (file)
@@ -18,8 +18,6 @@
 #include "qscreen.h"
 #include "QWorkArea.h"
 
-#include "GuiClipboard.h"
-#include "GuiSelection.h"
 #include "GuiWorkArea.h"
 
 #include "BufferView.h"
@@ -47,19 +45,9 @@ public:
        {
        }
 
-       lyx::frontend::Clipboard& clipboard()
-       {
-               return clipboard_;
-       }
-
-       lyx::frontend::Selection& selection()
-       {
-               return *selection_;
-       }
-
        int newView(unsigned int /*w*/, unsigned int /*h*/)
        {
-               view_.reset(new FView(*this));
+               view_.reset(new FView);
                return 0;
        }
 
@@ -80,7 +68,6 @@ public:
                old_work_area_.reset(new FWorkArea(*view_.get(), w, h));
                old_screen_.reset(new FScreen(*old_work_area_.get()));
                work_area_.reset(new GuiWorkArea(old_screen_.get(), old_work_area_.get()));
-               selection_.reset(new GuiSelection(old_work_area_.get()));
 
                // FIXME BufferView creation should be independant of WorkArea creation
                buffer_views_[0].reset(new BufferView(view_.get()));
@@ -96,17 +83,12 @@ public:
 
        void destroyWorkArea(int /*id*/)
        {
-               selection_.reset();
                work_area_.reset();
                old_work_area_.reset();
                old_screen_.reset();
        }
 
 private:
-       ///
-       GuiClipboard clipboard_;
-       ///
-       boost::shared_ptr<GuiSelection> selection_;
        ///
        boost::shared_ptr<GuiWorkArea> work_area_;
        ///
index e6cd9552ba96d16ad1b908a260eef6b12575621c..f4a97ac40800bcad4cf19a6af5a11671af5f52d4 100644 (file)
@@ -50,5 +50,17 @@ void GuiSelection::put(docstring const & str)
                                   QClipboard::Selection);
 }
 
+
+void GuiSelection::haveSelection(bool own)
+{
+       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.
+}
+
 } // namespace frontend
 } // namespace lyx
index 919c741e83b28aed5d187fd8e6b78ff62377691f..8096be121a024fda3d0ced0240b406ddd773bc25 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "frontends/Selection.h"
 
-#include "QWorkArea.h"
-
 namespace lyx {
 namespace frontend {
 
@@ -25,28 +23,19 @@ namespace frontend {
 class GuiSelection: public lyx::frontend::Selection
 {
 public:
-       GuiSelection(QWorkArea * work_area)
-               : old_work_area_(work_area)
-       {
-       }
+       GuiSelection() {}
 
        virtual ~GuiSelection() {}
 
        /** Selection overloaded methods
         */
        //@{
-       void haveSelection(bool own)
-       {
-               old_work_area_->haveSelection(own);
-       }
+       void haveSelection(bool);
 
        docstring const get() const;
 
        void put(docstring const & str);
        //@}
-
-private:
-       QWorkArea * old_work_area_;
 };
 
 } // namespace frontend
index 79e525737922f6f7e124d58a49d2bf26013ad06a..18997b26b1957806a058604f52a49b69eb2d5dee 100644 (file)
@@ -34,6 +34,7 @@ libqt3_la_SOURCES = \
        Alert_pimpl.C \
        Dialogs.C \
        FileDialog.C \
+       GuiApplication.C GuiApplication.h \
        GuiClipboard.C GuiClipboard.h \
        GuiImplementation.h \
        GuiSelection.C GuiSelection.h \
index 5a6198f1a06ac6af9987028fa7059aba32f65bc5..2d9dd3d12de82b30ccd3f85638f1cf85b140d316 100644 (file)
@@ -45,10 +45,6 @@ using std::string;
 
 namespace os = lyx::support::os;
 
-namespace {
-lyx::frontend::QWorkArea * wa_ptr = 0;
-}
-
 namespace lyx {
 namespace frontend {
 
@@ -72,9 +68,6 @@ QWorkArea::QWorkArea(LyXView & owner, int, int)
        vl->addWidget(content_, 5);
        vl->addWidget(scrollbar_, 0);
 
-#ifdef Q_WS_MACX
-       wa_ptr = this;
-#endif
        show();
 }
 
@@ -102,117 +95,6 @@ void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
        scrollbar_->setTracking(true);
 }
 
-} // namespace frontend
-} // namespace lyx
-
-
-#ifdef Q_WS_X11
-bool lyxX11EventFilter(XEvent * xev)
-{
-       switch (xev->type) {
-       case SelectionRequest:
-               lyxerr[Debug::GUI] << "X requested selection." << endl;
-               if (wa_ptr) {
-                       lyx::docstring const sel = wa_ptr->view().view()->requestSelection();
-                       if (!sel.empty())
-                               wa_ptr->view().gui().selection().put(sel);
-               }
-               break;
-       case SelectionClear:
-               lyxerr[Debug::GUI] << "Lost selection." << endl;
-               if (wa_ptr)
-                       wa_ptr->view().view()->clearSelection();
-               break;
-       }
-       return false;
-}
-#endif
-
-#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
-
-
-namespace lyx {
-namespace frontend {
-
-void QWorkArea::haveSelection(bool own)
-{
-       wa_ptr = const_cast<QWorkArea*>(this);
-
-       if (!QApplication::clipboard()->supportsSelection())
-               return;
-
-       if (own) {
-               QApplication::clipboard()->setSelectionMode(true);
-               QApplication::clipboard()->setText(QString());
-       }
-       // We don't need to do anything if own = false, as this case is
-       // handled by QT.
-}
-
 
 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
 {
index f558d4817c5d52d030eb58e81a20cdd45330c376..96032bd9f96f8991af7bf096474c6f793100c1bf 100644 (file)
@@ -49,8 +49,6 @@ public:
        ///
        virtual void setScrollbarParams(int height, int pos, int line_height);
 
-       /// a selection exists
-       virtual void haveSelection(bool);
        ///
        virtual void dragEnterEvent(QDragEnterEvent * event);
        ///
index ba6e975304644076fc1a09801b43127144de2809..1f7b3eacd0f9fefa549d22ae8f86803d03070566 100644 (file)
@@ -55,8 +55,8 @@ int const statusbar_timer_value = 3000;
 } // namespace anon
 
 
-QtView::QtView(Gui & owner)
-       : QMainWindow(), LyXView(owner), commandbuffer_(0)
+QtView::QtView()
+       : QMainWindow(), LyXView(), commandbuffer_(0)
 {
        qApp->setMainWidget(this);
 
index 6ab64233850d1e3c08533c38c8d28fd24137b701..89668fdab10bf305e8075e9920c9d036703e23c3 100644 (file)
@@ -36,7 +36,7 @@ class QtView : public QMainWindow, public LyXView {
        Q_OBJECT
 public:
        /// create a main window of the given dimensions
-       QtView(Gui & owner);
+       QtView();
 
        ~QtView();
 
index 4a95a40739bb25992cfee732af56c37e030203af..812129397ae81ae7b140257b28311b976af5b139 100644 (file)
@@ -14,7 +14,6 @@
 #include "lyx_gui.h"
 
 // FIXME: move this stuff out again
-#include "bufferlist.h"
 #include "BufferView.h"
 #include "Color.h"
 #include "funcrequest.h"
@@ -26,8 +25,6 @@
 #include "lyxserver.h"
 #include "lyxsocket.h"
 
-#include "graphics/LoaderQueue.h"
-
 #include "support/lstrings.h"
 #include "support/os.h"
 #include "support/package.h"
 #include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
+#include "frontends/LyXView.h"
 #include "frontends/WorkArea.h"
 
-#include "GuiImplementation.h"
+#include "GuiApplication.h"
 #include "QtView.h"
 #include "lcolorcache.h"
 #include "qfont_loader.h"
@@ -64,8 +62,7 @@
 using lyx::support::ltrim;
 using lyx::support::package;
 
-using lyx::frontend::Gui;
-using lyx::frontend::GuiImplementation;
+using lyx::frontend::GuiApplication;
 using lyx::frontend::QtView;
 
 namespace os = lyx::support::os;
@@ -81,92 +78,15 @@ using std::vector;
 using std::string;
 
 
-extern BufferList bufferlist;
-
-// FIXME: wrong place !
-LyXServer * lyxserver;
-LyXServerSocket * lyxsocket;
-
 namespace {
 
-int getDPI()
-{
-       QWidget w;
-       QPaintDeviceMetrics pdm(&w);
-       return int(0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY()));
-}
-
 map<int, shared_ptr<socket_callback> > socket_callbacks;
 
-void cleanup()
-{
-       delete lyxsocket;
-       lyxsocket = 0;
-       delete lyxserver;
-       lyxserver = 0;
-}
-
 } // namespace anon
 
-// in QLyXKeySym.C
-extern void initEncodings();
-
-#ifdef Q_WS_X11
-extern bool lyxX11EventFilter(XEvent * xev);
-#endif
-
-#ifdef Q_WS_MACX
-extern pascal OSErr
-handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
-                   long /*refCon*/);
-#endif
-
-class LQApplication : public QApplication
-{
-public:
-       LQApplication(int & argc, char ** argv);
-       //
-       Gui & gui() { return gui_; }
-
-#ifdef Q_WS_X11
-       bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
-#endif
-#ifdef Q_WS_MACX
-       bool macEventFilter(EventRef event);
-#endif
-
-private:
-       ///
-       GuiImplementation gui_;
-};
-
-
-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
-
-LQApplication * theApp;
+lyx::frontend::Application * theApp;
+GuiApplication * guiApp;
 
 namespace lyx_gui {
 
@@ -178,53 +98,10 @@ int exec(int & argc, char * argv[])
        // Force adding of font path _before_ QApplication is initialized
        FontLoader::initFontPath();
 
-       LQApplication app(argc, argv);
-       theApp = &app;
-
-#if QT_VERSION >= 0x030200
-       // install translation file for Qt built-in dialogs
-       // These are only installed since Qt 3.2.x
-       QTranslator qt_trans(0);
-       if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
-                         qInstallPathTranslations())) {
-               qApp->installTranslator(&qt_trans);
-               // even if the language calls for RtL, don't do that
-               qApp->setReverseLayout(false);
-               lyxerr[Debug::GUI]
-                       << "Successfully installed Qt translations for locale "
-                       << QTextCodec::locale() << std::endl;
-       } else
-               lyxerr[Debug::GUI]
-                       << "Could not find  Qt translations for locale "
-                       << QTextCodec::locale() << std::endl;
-#endif
-
-#ifdef Q_WS_MACX
-       // These translations are meant to break Qt/Mac menu merging
-       // algorithm on some entries. It lists the menu names that
-       // should not be moved to the LyX menu
-       QTranslator aqua_trans(0);
-       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
-                                            "do_not_merge_me"));
-       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
-                                            "do_not_merge_me"));
-       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
-                                            "do_not_merge_me"));
-       aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
-                                            "do_not_merge_me"));
-
-       qApp->installTranslator(&aqua_trans);
-#endif
-
-       using namespace lyx::graphics;
-
-       Image::newImage = boost::bind(&QLImage::newImage);
-       Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
+       GuiApplication app(argc, argv);
 
-       // needs to be done before reading lyxrc
-       lyxrc.dpi = getDPI();
-
-       LoaderQueue::setPriority(10,100);
+       guiApp = &app;
+       theApp = guiApp;
 
        return LyX::ref().exec2(argc, argv);
 }
@@ -237,50 +114,13 @@ void parse_lyxrc()
 LyXView* create_view(unsigned int width, unsigned int height, int posx, int posy,
              bool maximize)
 {
-       // this can't be done before because it needs the Languages object
-       initEncodings();
-
-       int view_id = theApp->gui().newView(width, height);
-       QtView & view = static_cast<QtView &> (theApp->gui().view(view_id));
-       theApp->gui().newWorkArea(width, height, 0);
-
-       LyX::ref().addLyXView(&view);
-
-       view.init();
-
-       if (width != 0 && height != 0) {
-               view.initFloatingGeometry(QRect(posx, posy, width, height));
-               view.resize(width, height);
-               if (posx != -1 && posy != -1)
-                       view.move(posx, posy);
-               view.show();
-               if (maximize)
-                       view.setWindowState(Qt::WindowMaximized);
-       } else
-               view.show();
-
-       return &view;
+       return &guiApp->createView(width, height, posx, posy, maximize);
 }
 
 
-int start(LyXView * view, string const & batch)
+int start(LyXView *, string const & batch)
 {
-       // FIXME: some code below needs moving
-
-       lyxserver = new LyXServer(&view->getLyXFunc(), lyxrc.lyxpipes);
-       lyxsocket = new LyXServerSocket(&view->getLyXFunc(),
-                         os::internal_path(package().temp_dir() + "/lyxsocket"));
-
-       // handle the batch commands the user asked for
-       if (!batch.empty()) {
-               view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
-       }
-
-       int const status = qApp->exec();
-
-       // FIXME
-       cleanup();
-       return status;
+       return theApp->start(batch);
 }
 
 
@@ -298,8 +138,7 @@ void sync_events()
 
 void exit(int status)
 {
-       cleanup();
-       QApplication::exit(status);
+       guiApp->exit(status);
 }