]> git.lyx.org Git - features.git/commitdiff
This commit introduces frontends/Application.[Ch] and makes qt4/GuiApplication (renam...
authorAbdelrazak Younes <younes@lyx.org>
Fri, 22 Sep 2006 09:47:39 +0000 (09:47 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 22 Sep 2006 09:47:39 +0000 (09:47 +0000)
Most of qt3 and gtk should stay compilable except for LyXView.h because the LyXFunc instance has been transferred to Application.

* frontends/Application: new class aimed to be the one unique interface between the frontend and the kernel. Contains one global pointer to the unique instanciation theApp.

* frontends/qt4/GuiApplication: renamed from qt4/Application, the qt4 specialisation of the Application class.  Contains one global pointer to the unique instanciation guiApp (equal to theApp but pointing to a GuiApplication instead).

* frontends/qt4/lyx_gui.C: most of the code has been moved to Application and GuiApplication

All other file: adapted to new API.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15114 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/frontends/Application.C [new file with mode: 0644]
src/frontends/Application.h [new file with mode: 0644]
src/frontends/LyXView.h
src/frontends/WorkArea.C
src/frontends/qt4/Application.C [deleted file]
src/frontends/qt4/Application.h [deleted file]
src/frontends/qt4/GuiApplication.C [new file with mode: 0644]
src/frontends/qt4/GuiApplication.h [new file with mode: 0644]
src/frontends/qt4/GuiWorkArea.C
src/frontends/qt4/QLPainter.C
src/frontends/qt4/lyx_gui.C
src/frontends/qt4/qfont_metrics.C

diff --git a/src/frontends/Application.C b/src/frontends/Application.C
new file mode 100644 (file)
index 0000000..d590e9d
--- /dev/null
@@ -0,0 +1,104 @@
+/**\r
+ * \file frontend/Application.C\r
+ * This file is part of LyX, the document processor.\r
+ * Licence details can be found in the file COPYING.\r
+ *\r
+ * \author Abdelrazak Younes\r
+ *\r
+ * Full author contact details are available in file CREDITS.\r
+ */\r
+\r
+#include <config.h>\r
+\r
+#include "Application.h"\r
+\r
+#include "funcrequest.h"\r
+#include "LyXAction.h"\r
+#include "lyxrc.h"\r
+#include "LyXView.h"\r
+\r
+#include "support/lstrings.h"\r
+#include "support/os.h"\r
+#include "support/package.h"\r
+\r
+#include <boost/scoped_ptr.hpp>\r
+\r
+using lyx::support::package;\r
+\r
+// FIXME: replace all occurence of lyxserver with theApp->server().\r
+LyXServer * lyxserver;\r
+// FIXME: replace all occurence of lyxsocket with theApp->socket().\r
+LyXServerSocket * lyxsocket;\r
+\r
+namespace lyx {\r
+namespace frontend {\r
+\r
+\r
+Application::Application(int & argc, char ** argv)\r
+{\r
+}\r
+\r
+\r
+LyXFunc & Application::lyxFunc()\r
+{\r
+       return *lyxfunc_.get(); \r
+}\r
+\r
+\r
+LyXFunc const & Application::lyxFunc() const\r
+{\r
+       return *lyxfunc_.get(); \r
+}\r
+\r
+\r
+LyXServer & Application::server()\r
+{\r
+       return *lyx_server_.get(); \r
+}\r
+\r
+\r
+LyXServer const & Application::server() const \r
+{\r
+       return *lyx_server_.get(); \r
+}\r
+\r
+\r
+LyXServerSocket & Application::socket()\r
+{\r
+       return *lyx_socket_.get();\r
+}\r
+\r
+\r
+LyXServerSocket const & Application::socket() const\r
+{\r
+       return *lyx_socket_.get();\r
+}\r
+\r
+\r
+void Application::setBufferView(BufferView * buffer_view)\r
+{\r
+       buffer_view_ = buffer_view;\r
+}\r
+\r
+\r
+int Application::start(std::string const & batch)\r
+{\r
+       lyx_server_.reset(new LyXServer(lyxfunc_.get(), lyxrc.lyxpipes));\r
+       lyx_socket_.reset(new LyXServerSocket(lyxfunc_.get(), \r
+               lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));\r
+\r
+       // FIXME: these two lines should disappear soon (Abdel 20/09/71)\r
+       lyxserver = lyx_server_.get();\r
+       lyxsocket = lyx_socket_.get();\r
+\r
+       // handle the batch commands the user asked for\r
+       if (!batch.empty()) {\r
+               lyxfunc_->dispatch(lyxaction.lookupFunc(batch));\r
+       }\r
+\r
+       return exec();\r
+}\r
+\r
+\r
+} // namespace frontend\r
+} // namespace lyx\r
diff --git a/src/frontends/Application.h b/src/frontends/Application.h
new file mode 100644 (file)
index 0000000..a7efd78
--- /dev/null
@@ -0,0 +1,89 @@
+/**\r
+ * \file frontend/Application.h\r
+ * This file is part of LyX, the document processor.\r
+ * Licence details can be found in the file COPYING.\r
+ *\r
+ * \author Abdelrazak Younes\r
+ *\r
+ * Full author contact details are available in file CREDITS.\r
+ */\r
+\r
+#ifndef LYX_APPLICATION_H\r
+#define LYX_APPLICATION_H\r
+\r
+#include "lyxfunc.h"\r
+#include "lyxserver.h"\r
+#include "lyxsocket.h"\r
+\r
+#include <boost/scoped_ptr.hpp>\r
+\r
+#include <string>\r
+\r
+class BufferView;\r
+class LyXView;\r
+\r
+namespace lyx {\r
+namespace frontend {\r
+\r
+//class GuiWorkArea;\r
+class Gui;\r
+\r
+\r
+/// The main application class\r
+/**\r
+There should be only one instance of this class. No Qt object\r
+initialisation should be done before the instanciation of this class.\r
+\r
+\todo The work areas handling could be moved to a base virtual class\r
+comon to all frontends.\r
+*/\r
+class Application\r
+{\r
+public:\r
+       Application(int & argc, char ** argv);\r
+\r
+       int start(std::string const & batch);\r
+       ///\r
+       virtual Gui & gui() = 0;\r
+       ///\r
+       virtual int const exec() = 0;\r
+       ///\r
+       virtual void exit(int status) = 0;\r
+\r
+       ///\r
+       LyXFunc & lyxFunc();\r
+       LyXFunc const & lyxFunc() const;\r
+       ///\r
+       LyXServer & server();\r
+       LyXServer const & server() const;\r
+       ///\r
+       LyXServerSocket & socket();\r
+       LyXServerSocket const & socket() const;\r
+       ///\r
+       void setBufferView(BufferView * buffer_view);\r
+\r
+protected:\r
+       ///\r
+       BufferView * buffer_view_;\r
+\r
+       // FIXME: lyxfunc_ should be private. But the actual construction is done in\r
+       // GuiApplication for now.\r
+\r
+       /// our function handler\r
+       boost::scoped_ptr<LyXFunc> lyxfunc_;\r
+\r
+private:\r
+       ///\r
+       boost::scoped_ptr<LyXServer> lyx_server_;\r
+       ///\r
+       boost::scoped_ptr<LyXServerSocket> lyx_socket_;\r
+\r
+}; // Application\r
+\r
+} // namespace frontend\r
+} // namespace lyx\r
+\r
+extern lyx::frontend::Application * theApp;\r
+\r
+\r
+#endif // LYX_APPLICATION_H\r
index 13776f252978dd2def4d0ecbebb9a4f799be995d..932e98602e2035cfa6ca2fb2ab38b6ae71bb2293 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef LYXVIEW_H
 #define LYXVIEW_H
 
+#include "frontends/Application.h"
 #include "frontends/Toolbars.h"
 
 #include <boost/scoped_ptr.hpp>
@@ -87,9 +88,9 @@ public:
        Buffer * buffer() const;
 
        /// return the LyX function handler for this view
-       LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
+       LyXFunc & getLyXFunc() { return theApp->lyxFunc(); }
        ///
-       LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
+       LyXFunc const & getLyXFunc() const { return theApp->lyxFunc(); }
 
        /// return the toolbar for this view
        Toolbars & getToolbars() { return *toolbars_.get(); }
index 21005c4f504ef5fe7984384b67cdb399d2527b4d..996f7b204283544a6644b0cb68bf6b573aac0ff6 100644 (file)
@@ -164,6 +164,8 @@ void WorkArea::setBufferView(BufferView * buffer_view)
                lyx_view_.disconnectBufferView();
        }
 
+       theApp->setBufferView(buffer_view);
+
        hideCursor();
        buffer_view_ = buffer_view;
        toggleCursor();
diff --git a/src/frontends/qt4/Application.C b/src/frontends/qt4/Application.C
deleted file mode 100644 (file)
index 24d97a7..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/**
- * \file qt4/Application.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 "Application.h"
-
-#include "GuiWorkArea.h"
-
-#include "qt_helpers.h"
-
-#include "BufferView.h"
-#include "debug.h"
-
-#include "support/lstrings.h"
-
-#include <QApplication>
-#include <QEventLoop>
-#include <QTranslator>
-#include <QTextCodec>
-#include <QClipboard>
-
-#ifdef Q_WS_X11
-#include <X11/Xlib.h>
-#endif
-
-using lyx::support::subst;
-
-using std::string;
-using std::endl;
-
-///////////////////////////////////////////////////////////////
-// You can find other X11 and MACX specific stuff
-// at the end of this file...
-///////////////////////////////////////////////////////////////
-
-namespace lyx {
-namespace frontend {
-
-Application::Application(int & argc, char ** argv)
-       : QApplication(argc, argv), buffer_view_(0)
-{
-#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
-}
-
-
-void Application::setBufferView(BufferView * buffer_view)
-{
-       buffer_view_ = buffer_view;
-}
-
-
-////////////////////////////////////////////////////////////////////////
-// X11 specific stuff goes here...
-#ifdef Q_WS_X11
-bool Application::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())
-                               gui_.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 Application::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 Application::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/qt4/Application.h b/src/frontends/qt4/Application.h
deleted file mode 100644 (file)
index a176342..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * \file qt4/Application.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 LYX_APPLICATION_H
-#define LYX_APPLICATION_H
-
-#include "GuiImplementation.h"
-#include "FontLoader.h"
-
-#include <QApplication>
-
-///////////////////////////////////////////////////////////////
-// 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 Application : public QApplication
-{
-public:
-       Application(int & argc, char ** argv);
-
-       //
-       Gui & gui() { return gui_; }
-       ///
-       FontLoader & fontLoader() { return font_loader_; }
-       ///
-       void setBufferView(BufferView * buffer_view);
-
-private:
-       ///
-       BufferView * buffer_view_;
-
-       ///
-       GuiImplementation gui_;
-
-       ///
-       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
-}; // Application
-
-} // namespace frontend
-} // namespace lyx
-
-extern lyx::frontend::Application * theApp;
-
-
-#endif // LYX_APPLICATION_H
diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C
new file mode 100644 (file)
index 0000000..764251b
--- /dev/null
@@ -0,0 +1,313 @@
+/**
+ * \file qt4/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 "GuiApplication.h"
+
+#include "GuiView.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>
+#include <QClipboard>
+#include <QEventLoop>
+#include <QLocale>
+#include <QLibraryInfo>
+#include <QTextCodec>
+#include <QTranslator>
+
+#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;
+       return int(0.5 * (w.logicalDpiX() + w.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
+
+       // 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,
+               QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+       {
+               qApp->installTranslator(&qt_trans);
+               // even if the language calls for RtL, don't do that
+               qApp->setLayoutDirection(Qt::LeftToRight);
+               lyxerr[Debug::GUI]
+                       << "Successfully installed Qt translations for locale "
+                       << fromqstr(language_name) << std::endl;
+       } else
+               lyxerr[Debug::GUI]
+                       << "Could not find  Qt translations for locale "
+                       << fromqstr(language_name) << std::endl;
+
+/*#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);
+}
+
+
+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);
+       GuiView & view = static_cast<GuiView &> (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) {
+               if (posx != -1 && posy != -1) {
+#ifdef Q_OS_WIN32
+                       // FIXME: use only setGeoemtry when Trolltech has
+                       // fixed the qt4/X11 bug
+                       view.setGeometry(posx, posy,width, height);
+#else
+                       view.resize(width, height);
+                       view.move(posx, posy);
+#endif
+               } else {
+                       view.resize(width, height);
+               }
+
+               if (maximize)
+                       view.setWindowState(Qt::WindowMaximized);
+       }
+
+       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())
+                               gui_.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/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h
new file mode 100644 (file)
index 0000000..efd54a4
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * \file qt4/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 QT4_APPLICATION_H
+#define QT4_APPLICATION_H
+
+#include "GuiImplementation.h"
+#include "FontLoader.h"
+
+#include "frontends/Application.h"
+
+#include <QApplication>
+
+///////////////////////////////////////////////////////////////
+// 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 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_;
+
+       ///
+       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 // QT4_APPLICATION_H
index eee68e344a03982af727c5a681bf26d25ca38552..da8a331081c9fbdf378d064cfa9e10cf6f8e700b 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "GuiWorkArea.h"
 
-#include "Application.h"
+#include "GuiApplication.h"
 #include "ColorCache.h"
 #include "QLPainter.h"
 #include "QLyXKeySym.h"
index 4fdbd7f28bea087c1f8ec55f858c4987841c354f..a3c2383ac9f7635de28a5c82187e9fea9d6de33b 100644 (file)
@@ -18,7 +18,7 @@
 #include "ColorCache.h"
 #include "FontLoader.h"
 
-#include "Application.h"
+#include "GuiApplication.h"
 #include "qt_helpers.h"
 
 #include "debug.h"
@@ -202,8 +202,8 @@ void QLPainter::smallCapsText(int x, int y,
        LyXFont smallfont(f);
        smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
 
-       QFont const & qfont = theApp->fontLoader().get(f);
-       QFont const & qsmallfont = theApp->fontLoader().get(smallfont);
+       QFont const & qfont = guiApp->fontLoader().get(f);
+       QFont const & qsmallfont = guiApp->fontLoader().get(smallfont);
        QFontMetrics const & qfontm = QFontMetrics(qfont);
        QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
 
@@ -252,7 +252,7 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls,
 
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
                setQPainterPen(f.realColor());
-               qp_->setFont(theApp->fontLoader().get(f));
+               qp_->setFont(guiApp->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);
index 1aa7d1c21f63ef05935ccf1efa45199c827873bf..8cf90e00019e3789901f0817e9f961e580654756 100644 (file)
 #include "lyxsocket.h"
 
 
-#include "graphics/LoaderQueue.h"
-
 #include "support/lstrings.h"
-#include "support/os.h"
-#include "support/package.h"
-#include "debug.h"
 
 
 #include "GuiView.h"
@@ -42,7 +37,7 @@
 #include "QLImage.h"
 #include "qt_helpers.h"
 #include "socket_callback.h"
-#include "Application.h"
+#include "GuiApplication.h"
 
 #include <QApplication>
 #include <QEventLoop>
 
 
 using lyx::support::ltrim;
-using lyx::support::package;
 
 using lyx::frontend::GuiImplementation;
 using lyx::frontend::GuiView;
-using lyx::frontend::Application;
-
-namespace os = lyx::support::os;
+using lyx::frontend::GuiApplication;
 
 using boost::shared_ptr;
 
@@ -74,35 +66,16 @@ using std::map;
 using std::vector;
 using std::string;
 
-// FIXME: wrong place !
-LyXServer * lyxserver;
-LyXServerSocket * lyxsocket;
-
+lyx::frontend::GuiApplication * guiApp;
 lyx::frontend::Application * theApp;
 
-namespace {
 
-int getDPI()
-{
-       QWidget w;
-       return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
-}
+namespace {
 
 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();
-
 namespace lyx_gui {
 
 bool use_gui = true;
@@ -124,65 +97,23 @@ int exec(int & argc, char * argv[])
        that caused the hanging:
 
        QObject::killTimer: timers cannot be stopped from another thread
+
+       I hope that the problem will disappear automagically when we get rid of
+       lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
+       Clipboard and Selection access.
        */
 
        // Force adding of font path _before_ QApplication is initialized
        FontLoader::initFontPath();
 
 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
-       static Application app(argc, argv);
+       static GuiApplication app(argc, argv);
 #else
-       Application app(argc, argv);
+       GuiApplication app(argc, argv);
 #endif
 
-       theApp = &app;
-
-
-       // 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,
-               QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
-       {
-               qApp->installTranslator(&qt_trans);
-               // even if the language calls for RtL, don't do that
-               qApp->setLayoutDirection(Qt::LeftToRight);
-               lyxerr[Debug::GUI]
-                       << "Successfully installed Qt translations for locale "
-                       << fromqstr(language_name) << std::endl;
-       } else
-               lyxerr[Debug::GUI]
-                       << "Could not find  Qt translations for locale "
-                       << fromqstr(language_name) << std::endl;
-
-/*#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);
+       guiApp = &app;
+       theApp = guiApp;
 
        return LyX::ref().exec2(argc, argv);
 }
@@ -195,63 +126,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);
-       GuiView & view = static_cast<GuiView &> (theApp->gui().view(view_id));
-
-       // FIXME: for now we assume that there is only one LyXView with id = 0.
-       /*int workArea_id_ =*/ theApp->gui().newWorkArea(width, height, 0);
-       //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
-
-       LyX::ref().addLyXView(&view);
-
-       view.init();
-
-       // only true when the -geometry option was NOT used
-       if (width != 0 && height != 0) {
-               if (posx != -1 && posy != -1) {
-#ifdef Q_OS_WIN32
-                       // FIXME: use only setGeoemtry when Trolltech has
-                       // fixed the qt4/X11 bug
-                       view.setGeometry(posx, posy,width, height);
-#else
-                       view.resize(width, height);
-                       view.move(posx, posy);
-#endif
-               } else {
-                       view.resize(width, height);
-               }
-
-               if (maximize)
-                       view.setWindowState(Qt::WindowMaximized);
-       }
-
-       view.show();
-
-       return &view;
+       return &guiApp->createView(width, height, posx, posy, maximize);
 }
 
 
 int start(LyXView * view, 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);
 }
 
 
@@ -261,14 +142,13 @@ void sync_events()
        // During screen update/ redraw, this method is disabled to
        // prevent keyboard events being handed to the LyX core, where
        // they could cause re-entrant calls to screen update.
-       qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+       guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
 }
 
 
 void exit(int status)
 {
-       cleanup();
-       QApplication::exit(status);
+       guiApp->exit(status);
 }
 
 
@@ -318,13 +198,13 @@ void update_color(LColor_color)
 
 void update_fonts()
 {
-       theApp->fontLoader().update();
+       guiApp->fontLoader().update();
 }
 
 
 bool font_available(LyXFont const & font)
 {
-       return theApp->fontLoader().available(font);
+       return guiApp->fontLoader().available(font);
 }
 
 
index 6abda06299e0bac456d22104e45e53a4990bd3d1..915c2934abe5f14b227b9519cec50e923df4cf4d 100644 (file)
@@ -14,7 +14,7 @@
 #include "frontends/font_metrics.h"
 #include "frontends/lyx_gui.h"
 
-#include "Application.h"
+#include "GuiApplication.h"
 #include "FontLoader.h"
 #include "qt_helpers.h"
 
@@ -39,8 +39,8 @@ int smallcapswidth(QString const & s, LyXFont const & f)
        LyXFont smallfont = f;
        smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
 
-       QFontMetrics const & qm = theApp->fontLoader().metrics(f);
-       QFontMetrics const & qsmallm = theApp->fontLoader().metrics(smallfont);
+       QFontMetrics const & qm = guiApp->fontLoader().metrics(f);
+       QFontMetrics const & qsmallm = guiApp->fontLoader().metrics(smallfont);
 
        int w = 0;
 
@@ -65,7 +65,7 @@ int font_metrics::maxAscent(LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
-       return theApp->fontLoader().metrics(f).ascent();
+       return guiApp->fontLoader().metrics(f).ascent();
 }
 
 
@@ -75,7 +75,7 @@ int font_metrics::maxDescent(LyXFont const & f)
                return 1;
        // We add 1 as the value returned by QT is different than X
        // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
-       return theApp->fontLoader().metrics(f).descent() + 1;
+       return guiApp->fontLoader().metrics(f).descent() + 1;
 }
 
 
@@ -83,7 +83,7 @@ int font_metrics::ascent(char_type c, LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
-       QRect const & r = theApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
+       QRect const & r = guiApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
        // value by the height: (x, -y-height, width, height).
        // Other versions return: (x, -y, width, height)
@@ -99,7 +99,7 @@ int font_metrics::descent(char_type c, LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
-       QRect const & r = theApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
+       QRect const & r = guiApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
        // value by the height: (x, -y-height, width, height).
        // Other versions return: (x, -y, width, height)
@@ -115,7 +115,7 @@ int font_metrics::lbearing(char_type c, LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
-       return theApp->fontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
+       return guiApp->fontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
 }
 
 
@@ -123,7 +123,7 @@ int font_metrics::rbearing(char_type c, LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
-       QFontMetrics const & m = theApp->fontLoader().metrics(f);
+       QFontMetrics const & m = guiApp->fontLoader().metrics(f);
 
        // Qt rbearing is from the right edge of the char's width().
        QChar sc = ucs4_to_qchar(c);
@@ -141,7 +141,7 @@ int font_metrics::width(char_type const * s, size_t ls, LyXFont const & f)
        if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
                return smallcapswidth(ucs2, f);
 
-       QLFontInfo & fi = theApp->fontLoader().fontinfo(f);
+       QLFontInfo & fi = guiApp->fontLoader().fontinfo(f);
 
        if (ls == 1)
                return fi.width(ucs2[0].unicode());
@@ -166,7 +166,7 @@ int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
 void font_metrics::rectText(docstring const & str, LyXFont const & f,
        int & w, int & ascent, int & descent)
 {
-       QFontMetrics const & m = theApp->fontLoader().metrics(f);
+       QFontMetrics const & m = guiApp->fontLoader().metrics(f);
        static int const d = 2;
        w = width(str, f) + d * 2 + 2;
        ascent = m.ascent() + d;
@@ -178,7 +178,7 @@ void font_metrics::rectText(docstring const & str, LyXFont const & f,
 void font_metrics::buttonText(docstring const & str, LyXFont const & f,
        int & w, int & ascent, int & descent)
 {
-       QFontMetrics const & m = theApp->fontLoader().metrics(f);
+       QFontMetrics const & m = guiApp->fontLoader().metrics(f);
        static int const d = 3;
        w = width(str, f) + d * 2 + 2;
        ascent = m.ascent() + d;