From: Abdelrazak Younes Date: Fri, 22 Sep 2006 09:47:39 +0000 (+0000) Subject: This commit introduces frontends/Application.[Ch] and makes qt4/GuiApplication (renam... X-Git-Tag: 1.6.10~12529 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3f0fadc48ad6fb14594787e1ecd747bf6e79b2f3;p=features.git This commit introduces frontends/Application.[Ch] and makes qt4/GuiApplication (renamed from qt4/Application) derive from it. Most of the code in qt4/lyx_gui.C has been transferred either to Application or to qt4/GuiApplication. Application handles unique instances of LyXFunc, LyXServer and LyXServerSocket. 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 --- diff --git a/src/frontends/Application.C b/src/frontends/Application.C new file mode 100644 index 0000000000..d590e9d678 --- /dev/null +++ b/src/frontends/Application.C @@ -0,0 +1,104 @@ +/** + * \file frontend/Application.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "Application.h" + +#include "funcrequest.h" +#include "LyXAction.h" +#include "lyxrc.h" +#include "LyXView.h" + +#include "support/lstrings.h" +#include "support/os.h" +#include "support/package.h" + +#include + +using lyx::support::package; + +// FIXME: replace all occurence of lyxserver with theApp->server(). +LyXServer * lyxserver; +// FIXME: replace all occurence of lyxsocket with theApp->socket(). +LyXServerSocket * lyxsocket; + +namespace lyx { +namespace frontend { + + +Application::Application(int & argc, char ** argv) +{ +} + + +LyXFunc & Application::lyxFunc() +{ + return *lyxfunc_.get(); +} + + +LyXFunc const & Application::lyxFunc() const +{ + return *lyxfunc_.get(); +} + + +LyXServer & Application::server() +{ + return *lyx_server_.get(); +} + + +LyXServer const & Application::server() const +{ + return *lyx_server_.get(); +} + + +LyXServerSocket & Application::socket() +{ + return *lyx_socket_.get(); +} + + +LyXServerSocket const & Application::socket() const +{ + return *lyx_socket_.get(); +} + + +void Application::setBufferView(BufferView * buffer_view) +{ + buffer_view_ = buffer_view; +} + + +int Application::start(std::string const & batch) +{ + lyx_server_.reset(new LyXServer(lyxfunc_.get(), lyxrc.lyxpipes)); + lyx_socket_.reset(new LyXServerSocket(lyxfunc_.get(), + lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket"))); + + // FIXME: these two lines should disappear soon (Abdel 20/09/71) + lyxserver = lyx_server_.get(); + lyxsocket = lyx_socket_.get(); + + // handle the batch commands the user asked for + if (!batch.empty()) { + lyxfunc_->dispatch(lyxaction.lookupFunc(batch)); + } + + return exec(); +} + + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/Application.h b/src/frontends/Application.h new file mode 100644 index 0000000000..a7efd78342 --- /dev/null +++ b/src/frontends/Application.h @@ -0,0 +1,89 @@ +/** + * \file frontend/Application.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYX_APPLICATION_H +#define LYX_APPLICATION_H + +#include "lyxfunc.h" +#include "lyxserver.h" +#include "lyxsocket.h" + +#include + +#include + +class BufferView; +class LyXView; + +namespace lyx { +namespace frontend { + +//class GuiWorkArea; +class Gui; + + +/// The 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: + Application(int & argc, char ** argv); + + int start(std::string const & batch); + /// + virtual Gui & gui() = 0; + /// + virtual int const exec() = 0; + /// + virtual void exit(int status) = 0; + + /// + LyXFunc & lyxFunc(); + LyXFunc const & lyxFunc() const; + /// + LyXServer & server(); + LyXServer const & server() const; + /// + LyXServerSocket & socket(); + LyXServerSocket const & socket() const; + /// + void setBufferView(BufferView * buffer_view); + +protected: + /// + BufferView * buffer_view_; + + // FIXME: lyxfunc_ should be private. But the actual construction is done in + // GuiApplication for now. + + /// our function handler + boost::scoped_ptr lyxfunc_; + +private: + /// + boost::scoped_ptr lyx_server_; + /// + boost::scoped_ptr lyx_socket_; + +}; // Application + +} // namespace frontend +} // namespace lyx + +extern lyx::frontend::Application * theApp; + + +#endif // LYX_APPLICATION_H diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 13776f2529..932e98602e 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -13,6 +13,7 @@ #ifndef LYXVIEW_H #define LYXVIEW_H +#include "frontends/Application.h" #include "frontends/Toolbars.h" #include @@ -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(); } diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 21005c4f50..996f7b2042 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -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 index 24d97a72da..0000000000 --- a/src/frontends/qt4/Application.C +++ /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 - -#include "Application.h" - -#include "GuiWorkArea.h" - -#include "qt_helpers.h" - -#include "BufferView.h" -#include "debug.h" - -#include "support/lstrings.h" - -#include -#include -#include -#include -#include - -#ifdef Q_WS_X11 -#include -#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 index a176342766..0000000000 --- a/src/frontends/qt4/Application.h +++ /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 - -/////////////////////////////////////////////////////////////// -// 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 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 index 0000000000..764251bede --- /dev/null +++ b/src/frontends/qt4/GuiApplication.C @@ -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 + +#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 +#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; + 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 (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 index 0000000000..efd54a45f0 --- /dev/null +++ b/src/frontends/qt4/GuiApplication.h @@ -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 + +/////////////////////////////////////////////////////////////// +// 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 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 diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C index eee68e344a..da8a331081 100644 --- a/src/frontends/qt4/GuiWorkArea.C +++ b/src/frontends/qt4/GuiWorkArea.C @@ -13,7 +13,7 @@ #include "GuiWorkArea.h" -#include "Application.h" +#include "GuiApplication.h" #include "ColorCache.h" #include "QLPainter.h" #include "QLyXKeySym.h" diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C index 4fdbd7f28b..a3c2383ac9 100644 --- a/src/frontends/qt4/QLPainter.C +++ b/src/frontends/qt4/QLPainter.C @@ -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); diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index 1aa7d1c21f..8cf90e0001 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -28,12 +28,7 @@ #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 #include @@ -56,13 +51,10 @@ 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 > 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 (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); } diff --git a/src/frontends/qt4/qfont_metrics.C b/src/frontends/qt4/qfont_metrics.C index 6abda06299..915c2934ab 100644 --- a/src/frontends/qt4/qfont_metrics.C +++ b/src/frontends/qt4/qfont_metrics.C @@ -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;