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
This commit is contained in:
Abdelrazak Younes 2006-09-22 09:47:39 +00:00
parent de161c40b1
commit 3f0fadc48a
10 changed files with 397 additions and 185 deletions

104
src/frontends/Application.C Normal file
View File

@ -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 <config.h>
#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 <boost/scoped_ptr.hpp>
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

View File

@ -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 <boost/scoped_ptr.hpp>
#include <string>
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> lyxfunc_;
private:
///
boost::scoped_ptr<LyXServer> lyx_server_;
///
boost::scoped_ptr<LyXServerSocket> lyx_socket_;
}; // Application
} // namespace frontend
} // namespace lyx
extern lyx::frontend::Application * theApp;
#endif // LYX_APPLICATION_H

View File

@ -13,6 +13,7 @@
#ifndef LYXVIEW_H #ifndef LYXVIEW_H
#define LYXVIEW_H #define LYXVIEW_H
#include "frontends/Application.h"
#include "frontends/Toolbars.h" #include "frontends/Toolbars.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
@ -87,9 +88,9 @@ public:
Buffer * buffer() const; Buffer * buffer() const;
/// return the LyX function handler for this view /// 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 /// return the toolbar for this view
Toolbars & getToolbars() { return *toolbars_.get(); } Toolbars & getToolbars() { return *toolbars_.get(); }

View File

@ -164,6 +164,8 @@ void WorkArea::setBufferView(BufferView * buffer_view)
lyx_view_.disconnectBufferView(); lyx_view_.disconnectBufferView();
} }
theApp->setBufferView(buffer_view);
hideCursor(); hideCursor();
buffer_view_ = buffer_view; buffer_view_ = buffer_view;
toggleCursor(); toggleCursor();

View File

@ -1,5 +1,5 @@
/** /**
* \file qt4/Application.C * \file qt4/GuiApplication.C
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
@ -12,42 +12,68 @@
#include <config.h> #include <config.h>
#include "Application.h" #include "GuiApplication.h"
#include "GuiView.h"
#include "GuiWorkArea.h" #include "GuiWorkArea.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "QLImage.h"
#include "BufferView.h" #include "BufferView.h"
#include "debug.h"
#include "graphics/LoaderQueue.h"
#include "support/lstrings.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 <QApplication>
#include <QEventLoop>
#include <QTranslator>
#include <QTextCodec>
#include <QClipboard> #include <QClipboard>
#include <QEventLoop>
#include <QLocale>
#include <QLibraryInfo>
#include <QTextCodec>
#include <QTranslator>
#ifdef Q_WS_X11 #ifdef Q_WS_X11
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif #endif
#include <boost/bind.hpp>
using lyx::support::subst; using lyx::support::subst;
using std::string; using std::string;
using std::endl; using std::endl;
// in QLyXKeySym.C
extern void initEncodings();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// You can find other X11 and MACX specific stuff // You can find other X11 and MACX specific stuff
// at the end of this file... // at the end of this file...
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
namespace {
int getDPI()
{
QWidget w;
return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
}
} // namespace anon
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
Application::Application(int & argc, char ** argv) GuiApplication::GuiApplication(int & argc, char ** argv)
: QApplication(argc, argv), buffer_view_(0) : QApplication(argc, argv), Application(argc, argv)
{ {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
// doubleClickInterval() is 400 ms on X11 witch is just too long. // doubleClickInterval() is 400 ms on X11 witch is just too long.
@ -62,19 +88,121 @@ Application::Application(int & argc, char ** argv)
NewAEEventHandlerUPP(handleOpenDocuments), NewAEEventHandlerUPP(handleOpenDocuments),
0, false); 0, false);
#endif #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);
} }
void Application::setBufferView(BufferView * buffer_view) int const GuiApplication::exec()
{ {
buffer_view_ = buffer_view; 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... // X11 specific stuff goes here...
#ifdef Q_WS_X11 #ifdef Q_WS_X11
bool Application::x11EventFilter(XEvent * xev) bool GuiApplication::x11EventFilter(XEvent * xev)
{ {
switch (xev->type) { switch (xev->type) {
case SelectionRequest: case SelectionRequest:
@ -101,6 +229,7 @@ bool Application::x11EventFilter(XEvent * xev)
#ifdef Q_WS_MACX #ifdef Q_WS_MACX
namespace{ namespace{
OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent) OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
{ {
DescType returnedType; DescType returnedType;
@ -117,9 +246,10 @@ OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
return err; return err;
} }
} }
} // namespace } // namespace
OSErr Application::handleOpenDocuments(const AppleEvent* inEvent, OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent,
AppleEvent* /*reply*/, long /*refCon*/) AppleEvent* /*reply*/, long /*refCon*/)
{ {
QString s_arg; QString s_arg;
@ -165,7 +295,7 @@ OSErr Application::handleOpenDocuments(const AppleEvent* inEvent,
return err; return err;
} }
bool Application::macEventFilter(EventRef event) bool GuiApplication::macEventFilter(EventRef event)
{ {
if (GetEventClass(event) == kEventClassAppleEvent) { if (GetEventClass(event) == kEventClassAppleEvent) {
EventRecord eventrec; EventRecord eventrec;

View File

@ -1,5 +1,5 @@
/** /**
* \file qt4/Application.h * \file qt4/GuiApplication.h
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
@ -10,12 +10,14 @@
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
#ifndef LYX_APPLICATION_H #ifndef QT4_APPLICATION_H
#define LYX_APPLICATION_H #define QT4_APPLICATION_H
#include "GuiImplementation.h" #include "GuiImplementation.h"
#include "FontLoader.h" #include "FontLoader.h"
#include "frontends/Application.h"
#include <QApplication> #include <QApplication>
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@ -41,22 +43,26 @@ initialisation should be done before the instanciation of this class.
\todo The work areas handling could be moved to a base virtual class \todo The work areas handling could be moved to a base virtual class
comon to all frontends. comon to all frontends.
*/ */
class Application : public QApplication class GuiApplication : public QApplication, public Application
{ {
public: public:
Application(int & argc, char ** argv); 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);
//@}
//
Gui & gui() { return gui_; }
/// ///
FontLoader & fontLoader() { return font_loader_; } FontLoader & fontLoader() { return font_loader_; }
/// ///
void setBufferView(BufferView * buffer_view); LyXView & createView(unsigned int width, unsigned int height,
int posx, int posy, bool maximize);
private: private:
///
BufferView * buffer_view_;
/// ///
GuiImplementation gui_; GuiImplementation gui_;
@ -76,12 +82,12 @@ private:
static pascal OSErr handleOpenDocuments( static pascal OSErr handleOpenDocuments(
const AppleEvent* inEvent, AppleEvent*, long); const AppleEvent* inEvent, AppleEvent*, long);
#endif #endif
}; // Application }; // GuiApplication
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx
extern lyx::frontend::Application * theApp; extern lyx::frontend::GuiApplication * guiApp;
#endif // LYX_APPLICATION_H #endif // QT4_APPLICATION_H

View File

@ -13,7 +13,7 @@
#include "GuiWorkArea.h" #include "GuiWorkArea.h"
#include "Application.h" #include "GuiApplication.h"
#include "ColorCache.h" #include "ColorCache.h"
#include "QLPainter.h" #include "QLPainter.h"
#include "QLyXKeySym.h" #include "QLyXKeySym.h"

View File

@ -18,7 +18,7 @@
#include "ColorCache.h" #include "ColorCache.h"
#include "FontLoader.h" #include "FontLoader.h"
#include "Application.h" #include "GuiApplication.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "debug.h" #include "debug.h"
@ -202,8 +202,8 @@ void QLPainter::smallCapsText(int x, int y,
LyXFont smallfont(f); LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
QFont const & qfont = theApp->fontLoader().get(f); QFont const & qfont = guiApp->fontLoader().get(f);
QFont const & qsmallfont = theApp->fontLoader().get(smallfont); QFont const & qsmallfont = guiApp->fontLoader().get(smallfont);
QFontMetrics const & qfontm = QFontMetrics(qfont); QFontMetrics const & qfontm = QFontMetrics(qfont);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont); 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) { if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
setQPainterPen(f.realColor()); 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. // We need to draw the text as LTR as we use our own bidi code.
qp_->setLayoutDirection(Qt::LeftToRight); qp_->setLayoutDirection(Qt::LeftToRight);
qp_->drawText(x, y, str); qp_->drawText(x, y, str);

View File

@ -28,12 +28,7 @@
#include "lyxsocket.h" #include "lyxsocket.h"
#include "graphics/LoaderQueue.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/os.h"
#include "support/package.h"
#include "debug.h"
#include "GuiView.h" #include "GuiView.h"
@ -42,7 +37,7 @@
#include "QLImage.h" #include "QLImage.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "socket_callback.h" #include "socket_callback.h"
#include "Application.h" #include "GuiApplication.h"
#include <QApplication> #include <QApplication>
#include <QEventLoop> #include <QEventLoop>
@ -56,13 +51,10 @@
using lyx::support::ltrim; using lyx::support::ltrim;
using lyx::support::package;
using lyx::frontend::GuiImplementation; using lyx::frontend::GuiImplementation;
using lyx::frontend::GuiView; using lyx::frontend::GuiView;
using lyx::frontend::Application; using lyx::frontend::GuiApplication;
namespace os = lyx::support::os;
using boost::shared_ptr; using boost::shared_ptr;
@ -74,35 +66,16 @@ using std::map;
using std::vector; using std::vector;
using std::string; using std::string;
// FIXME: wrong place ! lyx::frontend::GuiApplication * guiApp;
LyXServer * lyxserver;
LyXServerSocket * lyxsocket;
lyx::frontend::Application * theApp; lyx::frontend::Application * theApp;
namespace { namespace {
int getDPI()
{
QWidget w;
return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
}
map<int, shared_ptr<socket_callback> > socket_callbacks; map<int, shared_ptr<socket_callback> > socket_callbacks;
void cleanup()
{
delete lyxsocket;
lyxsocket = 0;
delete lyxserver;
lyxserver = 0;
}
} // namespace anon } // namespace anon
// in QLyXKeySym.C
extern void initEncodings();
namespace lyx_gui { namespace lyx_gui {
bool use_gui = true; bool use_gui = true;
@ -124,65 +97,23 @@ int exec(int & argc, char * argv[])
that caused the hanging: that caused the hanging:
QObject::killTimer: timers cannot be stopped from another thread 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 // Force adding of font path _before_ QApplication is initialized
FontLoader::initFontPath(); FontLoader::initFontPath();
#if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN) #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
static Application app(argc, argv); static GuiApplication app(argc, argv);
#else #else
Application app(argc, argv); GuiApplication app(argc, argv);
#endif #endif
theApp = &app; guiApp = &app;
theApp = guiApp;
// 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);
return LyX::ref().exec2(argc, argv); 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, LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
bool maximize) bool maximize)
{ {
// this can't be done before because it needs the Languages object return &guiApp->createView(width, height, posx, posy, maximize);
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;
} }
int start(LyXView * view, string const & batch) int start(LyXView * view, string const & batch)
{ {
// FIXME: some code below needs moving return theApp->start(batch);
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;
} }
@ -261,14 +142,13 @@ void sync_events()
// During screen update/ redraw, this method is disabled to // During screen update/ redraw, this method is disabled to
// prevent keyboard events being handed to the LyX core, where // prevent keyboard events being handed to the LyX core, where
// they could cause re-entrant calls to screen update. // they could cause re-entrant calls to screen update.
qApp->processEvents(QEventLoop::ExcludeUserInputEvents); guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
} }
void exit(int status) void exit(int status)
{ {
cleanup(); guiApp->exit(status);
QApplication::exit(status);
} }
@ -318,13 +198,13 @@ void update_color(LColor_color)
void update_fonts() void update_fonts()
{ {
theApp->fontLoader().update(); guiApp->fontLoader().update();
} }
bool font_available(LyXFont const & font) bool font_available(LyXFont const & font)
{ {
return theApp->fontLoader().available(font); return guiApp->fontLoader().available(font);
} }

View File

@ -14,7 +14,7 @@
#include "frontends/font_metrics.h" #include "frontends/font_metrics.h"
#include "frontends/lyx_gui.h" #include "frontends/lyx_gui.h"
#include "Application.h" #include "GuiApplication.h"
#include "FontLoader.h" #include "FontLoader.h"
#include "qt_helpers.h" #include "qt_helpers.h"
@ -39,8 +39,8 @@ int smallcapswidth(QString const & s, LyXFont const & f)
LyXFont smallfont = f; LyXFont smallfont = f;
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
QFontMetrics const & qm = theApp->fontLoader().metrics(f); QFontMetrics const & qm = guiApp->fontLoader().metrics(f);
QFontMetrics const & qsmallm = theApp->fontLoader().metrics(smallfont); QFontMetrics const & qsmallm = guiApp->fontLoader().metrics(smallfont);
int w = 0; int w = 0;
@ -65,7 +65,7 @@ int font_metrics::maxAscent(LyXFont const & f)
{ {
if (!lyx_gui::use_gui) if (!lyx_gui::use_gui)
return 1; 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; return 1;
// We add 1 as the value returned by QT is different than X // We add 1 as the value returned by QT is different than X
// See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74 // 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) if (!lyx_gui::use_gui)
return 1; 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 // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height). // value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, 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) if (!lyx_gui::use_gui)
return 1; 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 // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height). // value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, 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) if (!lyx_gui::use_gui)
return 1; 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) if (!lyx_gui::use_gui)
return 1; 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(). // Qt rbearing is from the right edge of the char's width().
QChar sc = ucs4_to_qchar(c); 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) if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
return smallcapswidth(ucs2, f); return smallcapswidth(ucs2, f);
QLFontInfo & fi = theApp->fontLoader().fontinfo(f); QLFontInfo & fi = guiApp->fontLoader().fontinfo(f);
if (ls == 1) if (ls == 1)
return fi.width(ucs2[0].unicode()); 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, void font_metrics::rectText(docstring const & str, LyXFont const & f,
int & w, int & ascent, int & descent) 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; static int const d = 2;
w = width(str, f) + d * 2 + 2; w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d; 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, void font_metrics::buttonText(docstring const & str, LyXFont const & f,
int & w, int & ascent, int & descent) 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; static int const d = 3;
w = width(str, f) + d * 2 + 2; w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d; ascent = m.ascent() + d;