--- /dev/null
+/**\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
--- /dev/null
+/**\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
#ifndef LYXVIEW_H
#define LYXVIEW_H
+#include "frontends/Application.h"
#include "frontends/Toolbars.h"
#include <boost/scoped_ptr.hpp>
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(); }
lyx_view_.disconnectBufferView();
}
+ theApp->setBufferView(buffer_view);
+
hideCursor();
buffer_view_ = buffer_view;
toggleCursor();
+++ /dev/null
-/**
- * \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
+++ /dev/null
-/**
- * \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
--- /dev/null
+/**
+ * \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
--- /dev/null
+/**
+ * \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
#include "GuiWorkArea.h"
-#include "Application.h"
+#include "GuiApplication.h"
#include "ColorCache.h"
#include "QLPainter.h"
#include "QLyXKeySym.h"
#include "ColorCache.h"
#include "FontLoader.h"
-#include "Application.h"
+#include "GuiApplication.h"
#include "qt_helpers.h"
#include "debug.h"
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);
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);
#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"
#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;
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;
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);
}
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);
}
// 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);
}
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);
}
#include "frontends/font_metrics.h"
#include "frontends/lyx_gui.h"
-#include "Application.h"
+#include "GuiApplication.h"
#include "FontLoader.h"
#include "qt_helpers.h"
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;
{
if (!lyx_gui::use_gui)
return 1;
- return theApp->fontLoader().metrics(f).ascent();
+ return guiApp->fontLoader().metrics(f).ascent();
}
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;
}
{
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)
{
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)
{
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));
}
{
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);
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());
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;
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;