From: Georg Baum Date: Fri, 22 Sep 2006 20:48:42 +0000 (+0000) Subject: make it compile again X-Git-Tag: 1.6.10~12517 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ebaaff58fad6299f19bfd65157b5deabf6925fcf;p=features.git make it compile again git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15131 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 5a9559c23c..8bc2869f99 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -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 index 0000000000..894db2adb4 --- /dev/null +++ b/src/frontends/qt3/GuiApplication.C @@ -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 + +#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 +#include +#include +#include +#include +#include +#include + +#ifdef Q_WS_X11 +#include +#endif + +#include + +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 (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 index 0000000000..6b8d938785 --- /dev/null +++ b/src/frontends/qt3/GuiApplication.h @@ -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 + +/////////////////////////////////////////////////////////////// +// Specific stuff + +#ifdef Q_WS_MACX +#include +#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 diff --git a/src/frontends/qt3/GuiImplementation.h b/src/frontends/qt3/GuiImplementation.h index d74def1331..30b4725bea 100644 --- a/src/frontends/qt3/GuiImplementation.h +++ b/src/frontends/qt3/GuiImplementation.h @@ -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 selection_; /// boost::shared_ptr work_area_; /// diff --git a/src/frontends/qt3/GuiSelection.C b/src/frontends/qt3/GuiSelection.C index e6cd9552ba..f4a97ac408 100644 --- a/src/frontends/qt3/GuiSelection.C +++ b/src/frontends/qt3/GuiSelection.C @@ -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 diff --git a/src/frontends/qt3/GuiSelection.h b/src/frontends/qt3/GuiSelection.h index 919c741e83..8096be121a 100644 --- a/src/frontends/qt3/GuiSelection.h +++ b/src/frontends/qt3/GuiSelection.h @@ -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 diff --git a/src/frontends/qt3/Makefile.am b/src/frontends/qt3/Makefile.am index 79e5257379..18997b26b1 100644 --- a/src/frontends/qt3/Makefile.am +++ b/src/frontends/qt3/Makefile.am @@ -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 \ diff --git a/src/frontends/qt3/QWorkArea.C b/src/frontends/qt3/QWorkArea.C index 5a6198f1a0..2d9dd3d12d 100644 --- a/src/frontends/qt3/QWorkArea.C +++ b/src/frontends/qt3/QWorkArea.C @@ -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(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) { diff --git a/src/frontends/qt3/QWorkArea.h b/src/frontends/qt3/QWorkArea.h index f558d4817c..96032bd9f9 100644 --- a/src/frontends/qt3/QWorkArea.h +++ b/src/frontends/qt3/QWorkArea.h @@ -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); /// diff --git a/src/frontends/qt3/QtView.C b/src/frontends/qt3/QtView.C index ba6e975304..1f7b3eacd0 100644 --- a/src/frontends/qt3/QtView.C +++ b/src/frontends/qt3/QtView.C @@ -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); diff --git a/src/frontends/qt3/QtView.h b/src/frontends/qt3/QtView.h index 6ab6423385..89668fdab1 100644 --- a/src/frontends/qt3/QtView.h +++ b/src/frontends/qt3/QtView.h @@ -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(); diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index 4a95a40739..812129397a 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -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" @@ -39,9 +36,10 @@ #include // FIXME: Is this needed? (Lgb) #include #include +#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 > 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 (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); }