Hello,

This patch works fine under windows. Georg, Bennett could you please check that it works fine on your respective platform.

The patch is not finished as it needs some doxygen cleanup/comments) but the C++ code is finished

Thanks in advance,
Abdel.
Index: src/frontends/qt4/Application.C
===================================================================
--- src/frontends/qt4/Application.C     (revision 0)
+++ src/frontends/qt4/Application.C     (revision 0)
@@ -0,0 +1,187 @@
+/**
+ * \file qt4/lyx_gui.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 "Application.h"
+#include "qt_helpers.h"
+#include "debug.h"
+#include "support/lstrings.h"
+
+#include <QApplication>
+#include <QEventLoop>
+#include <QTranslator>
+#include <QTextCodec>
+
+using lyx::support::subst;
+
+using std::map;
+using std::vector;
+using std::string;
+using std::endl;
+
+namespace {
+
+} // namespace anon
+
+///////////////////////////////////////////////////////////////
+// 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)
+{
+#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
+}
+
+
+Application::~Application()
+{
+       size_t end = work_areas_.size();
+       for (size_t i = 0; i < end; ++i)
+               delete work_areas_[i];
+}
+
+
+QWorkArea * Application::newWorkArea(LyXView & owner, int w, int h)
+{
+       current_work_area_ = new QWorkArea(owner, w, h);
+       work_areas_.push_back(current_work_area_);
+       lyxerr[Debug::GUI] 
+       << "current_work_area_  " << current_work_area_
+       << "    work_areas_.size() " << work_areas_.size()
+               << endl;
+
+       return current_work_area_;
+}
+
+////////////////////////////////////////////////////////////////////////
+// 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 (current_work_area_)
+                       current_work_area_->view().view()->selectionRequested();
+               break;
+       case SelectionClear:
+               lyxerr[Debug::GUI] << "Lost selection." << endl;
+               if (current_work_area_)
+                       current_work_area_->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;
+       }
+ }
+} // 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);
+                                       
current_work_area_->view().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

Property changes on: src\frontends\qt4\Application.C
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/frontends/qt4/Application.h
===================================================================
--- src/frontends/qt4/Application.h     (revision 0)
+++ src/frontends/qt4/Application.h     (revision 0)
@@ -0,0 +1,64 @@
+/**
+ * \file qt4/lyx_gui.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.
+ */
+
+#ifndef LYX_APPLICATION_H
+#define LYX_APPLICATION_H
+
+#include "QWorkArea.h"
+
+#include <QApplication>
+
+///////////////////////////////////////////////////////////////
+// Specific stuff
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#endif
+
+#ifdef Q_WS_MACX
+#include <Carbon/Carbon.h>
+#endif
+
+
+namespace lyx {
+namespace frontend {
+
+class Application : public QApplication
+{
+public:
+       Application(int & argc, char ** argv);
+       ~Application();
+
+       QWorkArea * newWorkArea(LyXView & owner, int w, int h);
+
+private:
+       std::vector<QWorkArea *> work_areas_;
+       QWorkArea * current_work_area_;
+
+#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
+
+#endif // LYX_APPLICATION_H

Property changes on: src\frontends\qt4\Application.h
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/frontends/qt4/lyx_gui.C
===================================================================
--- src/frontends/qt4/lyx_gui.C (revision 13992)
+++ src/frontends/qt4/lyx_gui.C (working copy)
@@ -46,11 +46,8 @@
 #include "QLImage.h"
 #include "qt_helpers.h"
 #include "socket_callback.h"
+#include "Application.h"
 
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#endif
-
 #include <QApplication>
 #include <QEventLoop>
 #include <QTranslator>
@@ -60,6 +57,7 @@
 using lyx::support::package;
 
 using lyx::frontend::QtView;
+using lyx::frontend::Application;
 
 namespace os = lyx::support::os;
 
@@ -73,9 +71,6 @@
 using std::vector;
 using std::string;
 
-
-extern BufferList bufferlist;
-
 namespace {
 
 int getDPI()
@@ -95,59 +90,9 @@
 // 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 {
 
-LQApplication * app = 0;
+Application * app = 0;
 
 }
 
@@ -181,9 +126,9 @@
        FontLoader::initFontPath();
 
 #ifdef Q_WS_WIN
-       static QApplication win_app(argc, argv);
+       static Application win_app(argc, argv);
 #else
-       app = new LQApplication(argc, argv);
+       app = new Application(argc, argv);
 #endif
 
        // install translation file for Qt built-in dialogs
Index: src/frontends/qt4/Makefile.am
===================================================================
--- src/frontends/qt4/Makefile.am       (revision 13992)
+++ src/frontends/qt4/Makefile.am       (working copy)
@@ -85,6 +85,7 @@
        QtLyXView.h \
        WorkAreaFactory.C \
        checkedwidgets.C checkedwidgets.h \
+       Application.C Application.h \
        lyx_gui.C \
        lcolorcache.h lcolorcache.C \
        panelstack.h panelstack.C \
Index: src/frontends/qt4/QWorkArea.C
===================================================================
--- src/frontends/qt4/QWorkArea.C       (revision 13992)
+++ src/frontends/qt4/QWorkArea.C       (working copy)
@@ -38,22 +38,6 @@
 
 #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;
 
@@ -61,8 +45,6 @@
 
 namespace {
 
-QWorkArea * wa_ptr = 0;
-
 /// return the LyX key state from Qt's
 key_modifier::state q_key_state(Qt::ButtonState state)
 {
@@ -186,17 +168,6 @@
        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()
@@ -232,9 +203,6 @@
 
 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;
 
@@ -674,96 +642,4 @@
 #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"
Index: src/frontends/qt4/WorkAreaFactory.C
===================================================================
--- src/frontends/qt4/WorkAreaFactory.C (revision 13992)
+++ src/frontends/qt4/WorkAreaFactory.C (working copy)
@@ -11,13 +11,17 @@
 #include <config.h>
 
 #include "frontends/WorkAreaFactory.h"
-#include "QWorkArea.h"
+#include "Application.h"
 
+using lyx::frontend::Application;
+
 namespace WorkAreaFactory {
 
 WorkArea * create(LyXView & owner, int w, int h)
 {
-       return new QWorkArea(owner, w, h);
+       Application * theApp = static_cast<Application *> qApp;
+
+       return theApp->newWorkArea(owner, w, h);
 }
 
 } // namespace WorkAreaFactory

Reply via email to