2006-06-26 17:18:28 +00:00
|
|
|
/**
|
2007-09-05 20:33:29 +00:00
|
|
|
* \file GuiApplication.cpp
|
2006-06-26 17:18:28 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2006-07-01 18:14:58 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include "GuiApplication.h"
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
#include "ColorCache.h"
|
|
|
|
#include "GuiClipboard.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiImage.h"
|
2008-03-14 23:25:11 +00:00
|
|
|
#include "GuiKeySymbol.h"
|
2008-05-23 08:43:07 +00:00
|
|
|
#include "GuiSelection.h"
|
2007-11-17 20:47:50 +00:00
|
|
|
#include "GuiView.h"
|
2008-05-23 08:43:07 +00:00
|
|
|
#include "Menus.h"
|
|
|
|
#include "qt_helpers.h"
|
2006-08-17 08:37:46 +00:00
|
|
|
|
2007-09-21 20:27:07 +00:00
|
|
|
#include "frontends/alert.h"
|
2007-11-17 22:11:11 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
#include "frontends/FontLoader.h"
|
|
|
|
#include "frontends/FontMetrics.h"
|
2006-11-07 17:19:33 +00:00
|
|
|
|
2007-11-24 07:58:12 +00:00
|
|
|
#include "Buffer.h"
|
2007-08-27 06:35:24 +00:00
|
|
|
#include "BufferList.h"
|
2006-09-29 23:21:03 +00:00
|
|
|
#include "BufferView.h"
|
2008-05-23 09:53:27 +00:00
|
|
|
#include "Color.h"
|
2007-11-17 22:11:11 +00:00
|
|
|
#include "Font.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-11-24 07:58:12 +00:00
|
|
|
#include "FuncStatus.h"
|
2008-05-08 09:03:38 +00:00
|
|
|
#include "Language.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyX.h"
|
|
|
|
#include "LyXFunc.h"
|
|
|
|
#include "LyXRC.h"
|
2007-11-24 07:58:12 +00:00
|
|
|
#include "Session.h"
|
2007-11-16 22:10:35 +00:00
|
|
|
#include "version.h"
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/ExceptionMessage.h"
|
|
|
|
#include "support/FileName.h"
|
|
|
|
#include "support/ForkedCalls.h"
|
2008-03-06 21:50:27 +00:00
|
|
|
#include "support/gettext.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/os.h"
|
|
|
|
#include "support/Package.h"
|
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
#include "support/linkback/LinkBackProxy.h"
|
|
|
|
#endif
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include <QClipboard>
|
2006-06-26 17:18:28 +00:00
|
|
|
#include <QEventLoop>
|
2006-11-29 09:06:37 +00:00
|
|
|
#include <QFileOpenEvent>
|
2006-09-22 09:47:39 +00:00
|
|
|
#include <QLocale>
|
|
|
|
#include <QLibraryInfo>
|
2008-05-23 07:52:39 +00:00
|
|
|
#include <QMacPasteboardMime>
|
2007-12-26 09:54:48 +00:00
|
|
|
#include <QMenuBar>
|
2008-05-23 07:52:39 +00:00
|
|
|
#include <QMimeData>
|
2007-08-21 07:33:46 +00:00
|
|
|
#include <QPixmapCache>
|
2007-11-15 12:58:44 +00:00
|
|
|
#include <QRegExp>
|
2007-08-27 06:35:24 +00:00
|
|
|
#include <QSessionManager>
|
2007-09-15 20:31:50 +00:00
|
|
|
#include <QSocketNotifier>
|
2008-05-14 10:34:19 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2008-05-08 09:03:38 +00:00
|
|
|
#include <QStandardItemModel>
|
2006-06-26 17:18:28 +00:00
|
|
|
#include <QTextCodec>
|
2006-11-26 10:32:42 +00:00
|
|
|
#include <QTimer>
|
2006-09-22 09:47:39 +00:00
|
|
|
#include <QTranslator>
|
2006-09-29 23:10:17 +00:00
|
|
|
#include <QWidget>
|
2006-06-26 17:18:28 +00:00
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
2007-01-05 10:11:21 +00:00
|
|
|
#include <X11/Xatom.h>
|
2006-06-26 17:18:28 +00:00
|
|
|
#include <X11/Xlib.h>
|
2007-11-11 12:14:06 +00:00
|
|
|
#undef CursorShape
|
|
|
|
#undef None
|
2006-06-26 17:18:28 +00:00
|
|
|
#endif
|
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
#include <QVector>
|
|
|
|
#include <QWindowsMime>
|
|
|
|
#if defined(Q_CYGWIN_WIN) || defined(Q_CC_MINGW)
|
|
|
|
#include <wtypes.h>
|
|
|
|
#endif
|
|
|
|
#include <objidl.h>
|
|
|
|
#endif // Q_WS_WIN
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2007-04-02 10:18:12 +00:00
|
|
|
#include <exception>
|
2008-05-23 08:43:07 +00:00
|
|
|
#include <map>
|
2007-04-02 10:18:12 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
using namespace lyx::support;
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
// FIXME: These strings are also used in GuiClipboard.cpp.
|
|
|
|
static char const * const lyx_mime_type = "application/x-lyx";
|
|
|
|
static char const * const pdf_mime_type = "application/pdf";
|
|
|
|
static char const * const emf_mime_type = "image/x-emf";
|
|
|
|
static char const * const wmf_mime_type = "image/x-wmf";
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
namespace lyx {
|
2006-09-22 09:47:39 +00:00
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
frontend::Application * createApplication(int & argc, char * argv[])
|
2006-09-22 09:47:39 +00:00
|
|
|
{
|
2007-09-15 17:47:35 +00:00
|
|
|
return new frontend::GuiApplication(argc, argv);
|
2006-09-22 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
namespace frontend {
|
2006-09-22 09:47:39 +00:00
|
|
|
|
2007-09-15 20:31:50 +00:00
|
|
|
class SocketNotifier : public QSocketNotifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// connect a connection notification from the LyXServerSocket
|
|
|
|
SocketNotifier(QObject * parent, int fd, Application::SocketCallback func)
|
|
|
|
: QSocketNotifier(fd, QSocketNotifier::Read, parent), func_(func)
|
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// The callback function
|
|
|
|
Application::SocketCallback func_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Mac specific stuff goes here...
|
2007-05-04 17:20:53 +00:00
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
class MenuTranslator : public QTranslator
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2007-09-15 17:47:35 +00:00
|
|
|
public:
|
2007-09-15 20:31:50 +00:00
|
|
|
MenuTranslator(QObject * parent)
|
|
|
|
: QTranslator(parent)
|
|
|
|
{}
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
QString translate(const char * /*context*/,
|
|
|
|
const char * sourceText,
|
|
|
|
const char * /*comment*/ = 0)
|
|
|
|
{
|
|
|
|
string const s = sourceText;
|
|
|
|
if (s == N_("About %1") || s == N_("Preferences")
|
|
|
|
|| s == N_("Reconfigure") || s == N_("Quit %1"))
|
|
|
|
return qt_(s);
|
|
|
|
else
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
};
|
2006-10-12 14:10:13 +00:00
|
|
|
|
2008-03-14 23:25:11 +00:00
|
|
|
class GlobalMenuBar : public QMenuBar
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
GlobalMenuBar() : QMenuBar(0) {}
|
|
|
|
|
|
|
|
///
|
|
|
|
bool event(QEvent * e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::ShortcutOverride) {
|
|
|
|
// && activeWindow() == 0) {
|
|
|
|
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
|
|
|
|
KeySymbol sym;
|
|
|
|
setKeySymbol(&sym, ke);
|
|
|
|
theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
|
|
|
|
e->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2006-10-12 14:10:13 +00:00
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// QMacPasteboardMimeGraphics can only be compiled on Mac.
|
|
|
|
|
|
|
|
class QMacPasteboardMimeGraphics : public QMacPasteboardMime
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QMacPasteboardMimeGraphics()
|
|
|
|
: QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QString convertorName() { return "Graphics"; }
|
|
|
|
|
|
|
|
QString flavorFor(QString const & mime)
|
|
|
|
{
|
|
|
|
LYXERR(Debug::ACTION, "flavorFor " << mime);
|
|
|
|
if (mime == QLatin1String(pdf_mime_type))
|
|
|
|
return QLatin1String("com.adobe.pdf");
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString mimeFor(QString flav)
|
|
|
|
{
|
|
|
|
LYXERR(Debug::ACTION, "mimeFor " << flav);
|
|
|
|
if (flav == QLatin1String("com.adobe.pdf"))
|
|
|
|
return QLatin1String(pdf_mime_type);
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canConvert(QString const & mime, QString flav)
|
|
|
|
{ return mimeFor(flav) == mime; }
|
|
|
|
|
|
|
|
QVariant convertToMime(QString const & mime, QList<QByteArray> data, QString flav)
|
|
|
|
{
|
|
|
|
if(data.count() > 1)
|
|
|
|
qWarning("QMacPasteboardMimeGraphics: Cannot handle multiple member data");
|
|
|
|
return data.first();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QByteArray> convertFromMime(QString const & mime, QVariant data, QString flav)
|
|
|
|
{
|
|
|
|
QList<QByteArray> ret;
|
|
|
|
ret.append(data.toByteArray());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// You can find more platform specific stuff
|
|
|
|
// at the end of this file...
|
|
|
|
///////////////////////////////////////////////////////////////
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Windows specific stuff goes here...
|
|
|
|
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
// QWindowsMimeMetafile can only be compiled on Windows.
|
|
|
|
|
|
|
|
static FORMATETC cfFromMime(QString const & mimetype)
|
|
|
|
{
|
|
|
|
FORMATETC formatetc;
|
|
|
|
if (mimetype == emf_mime_type) {
|
|
|
|
formatetc.cfFormat = CF_ENHMETAFILE;
|
|
|
|
formatetc.tymed = TYMED_ENHMF;
|
|
|
|
} else if (mimetype == wmf_mime_type) {
|
|
|
|
formatetc.cfFormat = CF_METAFILEPICT;
|
|
|
|
formatetc.tymed = TYMED_MFPICT;
|
|
|
|
}
|
|
|
|
formatetc.ptd = 0;
|
|
|
|
formatetc.dwAspect = DVASPECT_CONTENT;
|
|
|
|
formatetc.lindex = -1;
|
|
|
|
return formatetc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class QWindowsMimeMetafile : public QWindowsMime {
|
|
|
|
public:
|
|
|
|
QWindowsMimeMetafile() {}
|
|
|
|
|
|
|
|
bool canConvertFromMime(FORMATETC const & formatetc,
|
|
|
|
QMimeData const * mimedata) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canConvertToMime(QString const & mimetype,
|
|
|
|
IDataObject * pDataObj) const
|
|
|
|
{
|
|
|
|
if (mimetype != emf_mime_type && mimetype != wmf_mime_type)
|
|
|
|
return false;
|
|
|
|
FORMATETC formatetc = cfFromMime(mimetype);
|
|
|
|
return pDataObj->QueryGetData(&formatetc) == S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool convertFromMime(FORMATETC const & formatetc,
|
|
|
|
const QMimeData * mimedata, STGMEDIUM * pmedium) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant convertToMime(QString const & mimetype, IDataObject * pDataObj,
|
|
|
|
QVariant::Type preferredType) const
|
|
|
|
{
|
|
|
|
QByteArray data;
|
|
|
|
if (!canConvertToMime(mimetype, pDataObj))
|
|
|
|
return data;
|
|
|
|
|
|
|
|
FORMATETC formatetc = cfFromMime(mimetype);
|
|
|
|
STGMEDIUM s;
|
|
|
|
if (pDataObj->GetData(&formatetc, &s) != S_OK)
|
|
|
|
return data;
|
|
|
|
|
|
|
|
int dataSize;
|
|
|
|
if (s.tymed == TYMED_ENHMF) {
|
|
|
|
dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, 0, 0);
|
|
|
|
data.resize(dataSize);
|
|
|
|
dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, dataSize,
|
|
|
|
(LPBYTE)data.data());
|
|
|
|
} else if (s.tymed == TYMED_MFPICT) {
|
|
|
|
dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, 0, 0);
|
|
|
|
data.resize(dataSize);
|
|
|
|
dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, dataSize,
|
|
|
|
(LPBYTE)data.data());
|
|
|
|
}
|
|
|
|
data.detach();
|
|
|
|
ReleaseStgMedium(&s);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVector<FORMATETC> formatsForMime(QString const & mimeType,
|
|
|
|
QMimeData const * mimeData) const
|
|
|
|
{
|
|
|
|
QVector<FORMATETC> formats;
|
|
|
|
formats += cfFromMime(mimeType);
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString mimeForFormat(FORMATETC const & formatetc) const
|
|
|
|
{
|
|
|
|
switch (formatetc.cfFormat) {
|
|
|
|
case CF_ENHMETAFILE:
|
|
|
|
return emf_mime_type;
|
|
|
|
case CF_METAFILEPICT:
|
|
|
|
return wmf_mime_type;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // Q_WS_WIN
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// GuiApplication::Private definition and implementation.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct GuiApplication::Private
|
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
Private(): language_model_(0), global_menubar_(0)
|
2008-05-23 07:52:39 +00:00
|
|
|
{
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// Create the global default menubar which is shown for the dialogs
|
|
|
|
// and if no GuiView is visible.
|
|
|
|
global_menubar_ = new GlobalMenuBar();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
///
|
|
|
|
QSortFilterProxyModel * language_model_;
|
|
|
|
///
|
|
|
|
GuiClipboard clipboard_;
|
|
|
|
///
|
|
|
|
GuiSelection selection_;
|
|
|
|
///
|
|
|
|
FontLoader font_loader_;
|
|
|
|
///
|
|
|
|
ColorCache color_cache_;
|
|
|
|
///
|
|
|
|
QTranslator qt_trans_;
|
|
|
|
///
|
|
|
|
std::map<int, SocketNotifier *> socket_notifiers_;
|
|
|
|
///
|
|
|
|
Menus menus_;
|
|
|
|
/// this timer is used for any regular events one wants to
|
|
|
|
/// perform. at present it is used to check if forked processes
|
|
|
|
/// are done.
|
|
|
|
QTimer general_timer_;
|
|
|
|
|
|
|
|
/// Multiple views container.
|
|
|
|
/**
|
|
|
|
* Warning: This must not be a smart pointer as the destruction of the
|
|
|
|
* object is handled by Qt when the view is closed
|
|
|
|
* \sa Qt::WA_DeleteOnClose attribute.
|
|
|
|
*/
|
2008-05-23 10:45:55 +00:00
|
|
|
map<int, GuiView *> views_;
|
2008-05-23 08:43:07 +00:00
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
/// Only used on mac.
|
|
|
|
GlobalMenuBar * global_menubar_;
|
|
|
|
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
/// Linkback mime handler for MacOSX.
|
|
|
|
QMacPasteboardMimeGraphics mac_pasteboard_mime_;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
/// WMF Mime handler for Windows clipboard.
|
|
|
|
// FIXME for Windows Vista and Qt4 (see http://bugzilla.lyx.org/show_bug.cgi?id=4846)
|
|
|
|
// But this makes LyX crash on exit when LyX is compiled in release mode and if there
|
|
|
|
// is something in the clipboard.
|
|
|
|
QWindowsMimeMetafile wmf_mime_;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
GuiApplication * guiApp;
|
2006-10-13 16:48:12 +00:00
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
GuiApplication::~GuiApplication()
|
|
|
|
{
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
closeAllLinkBackLinks();
|
|
|
|
#endif
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
GuiApplication::GuiApplication(int & argc, char ** argv)
|
2008-05-23 08:43:07 +00:00
|
|
|
: QApplication(argc, argv), current_view_(0), d(new GuiApplication::Private)
|
2006-06-26 17:18:28 +00:00
|
|
|
{
|
2007-11-16 22:10:35 +00:00
|
|
|
QString app_name = "LyX";
|
|
|
|
QCoreApplication::setOrganizationName(app_name);
|
2007-09-27 14:05:05 +00:00
|
|
|
QCoreApplication::setOrganizationDomain("lyx.org");
|
2007-11-16 22:21:40 +00:00
|
|
|
QCoreApplication::setApplicationName(app_name + "-" + lyx_version);
|
2007-09-27 14:05:05 +00:00
|
|
|
|
2008-03-14 23:26:47 +00:00
|
|
|
// FIXME: quitOnLastWindowClosed is true by default. We should have a
|
|
|
|
// lyxrc setting for this in order to let the application stay resident.
|
|
|
|
// But then we need some kind of dock icon, at least on Windows.
|
2008-02-27 11:44:37 +00:00
|
|
|
/*
|
|
|
|
if (lyxrc.quit_on_last_window_closed)
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
*/
|
2008-03-17 10:23:02 +00:00
|
|
|
#ifdef Q_WS_MACX
|
2008-03-14 23:30:28 +00:00
|
|
|
// FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
|
|
|
|
// seems to be the default case for applications like LyX.
|
2008-03-14 23:25:11 +00:00
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
#endif
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
#ifdef Q_WS_X11
|
2006-10-22 14:37:32 +00:00
|
|
|
// doubleClickInterval() is 400 ms on X11 which is just too long.
|
2006-06-26 17:18:28 +00:00
|
|
|
// 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
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
// install translation file for Qt built-in dialogs
|
|
|
|
QString language_name = QString("qt_") + QLocale::system().name();
|
2007-07-31 17:09:50 +00:00
|
|
|
|
|
|
|
// language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN).
|
|
|
|
// Short-named translator can be loaded from a long name, but not the
|
|
|
|
// opposite. Therefore, long name should be used without truncation.
|
|
|
|
// c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
|
2008-05-23 08:43:07 +00:00
|
|
|
if (d->qt_trans_.load(language_name,
|
2006-09-22 09:47:39 +00:00
|
|
|
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
installTranslator(&d->qt_trans_);
|
2006-09-22 09:47:39 +00:00
|
|
|
// even if the language calls for RtL, don't do that
|
2007-08-07 21:23:40 +00:00
|
|
|
setLayoutDirection(Qt::LeftToRight);
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "Successfully installed Qt translations for locale "
|
2008-04-20 21:05:35 +00:00
|
|
|
<< language_name);
|
2006-09-22 09:47:39 +00:00
|
|
|
} else
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "Could not find Qt translations for locale "
|
2008-04-20 21:05:35 +00:00
|
|
|
<< language_name);
|
2006-09-22 09:47:39 +00:00
|
|
|
|
2007-08-07 21:23:40 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// This allows to translate the strings that appear in the LyX menu.
|
2008-05-23 07:52:39 +00:00
|
|
|
/// A translator suitable for the entries in the LyX menu.
|
|
|
|
/// Only needed with Qt/Mac.
|
|
|
|
installTranslator(new MenuTranslator(this));
|
2007-08-07 21:23:40 +00:00
|
|
|
#endif
|
2008-03-14 23:25:11 +00:00
|
|
|
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
|
2007-08-07 21:23:40 +00:00
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
using namespace lyx::graphics;
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
Image::newImage = boost::bind(&GuiImage::newImage);
|
|
|
|
Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
|
2006-09-22 09:47:39 +00:00
|
|
|
|
|
|
|
// needs to be done before reading lyxrc
|
2007-09-15 17:47:35 +00:00
|
|
|
QWidget w;
|
|
|
|
lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2;
|
2006-09-22 09:47:39 +00:00
|
|
|
|
2006-10-12 14:10:13 +00:00
|
|
|
guiApp = this;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
// Set the cache to 5120 kilobytes which corresponds to screen size of
|
|
|
|
// 1280 by 1024 pixels with a color depth of 32 bits.
|
|
|
|
QPixmapCache::setCacheLimit(5120);
|
2007-11-18 20:36:52 +00:00
|
|
|
|
|
|
|
// Initialize RC Fonts
|
|
|
|
if (lyxrc.roman_font_name.empty())
|
|
|
|
lyxrc.roman_font_name = fromqstr(romanFontName());
|
|
|
|
|
|
|
|
if (lyxrc.sans_font_name.empty())
|
|
|
|
lyxrc.sans_font_name = fromqstr(sansFontName());
|
|
|
|
|
|
|
|
if (lyxrc.typewriter_font_name.empty())
|
|
|
|
lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
|
2008-02-05 13:10:42 +00:00
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
d->general_timer_.setInterval(500);
|
|
|
|
connect(&d->general_timer_, SIGNAL(timeout()),
|
2008-02-05 13:10:42 +00:00
|
|
|
this, SLOT(handleRegularEvents()));
|
2008-05-23 08:43:07 +00:00
|
|
|
d->general_timer_.start();
|
2006-06-26 17:18:28 +00:00
|
|
|
}
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
|
2008-05-23 09:53:27 +00:00
|
|
|
bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
|
2007-11-24 07:58:12 +00:00
|
|
|
{
|
|
|
|
bool enable = true;
|
|
|
|
|
|
|
|
switch(cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_WINDOW_CLOSE:
|
2008-05-23 10:45:55 +00:00
|
|
|
enable = d->views_.size() > 0;
|
2007-11-24 07:58:12 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-23 09:53:27 +00:00
|
|
|
case LFUN_BUFFER_NEW:
|
|
|
|
case LFUN_BUFFER_NEW_TEMPLATE:
|
|
|
|
case LFUN_FILE_OPEN:
|
|
|
|
case LFUN_SCREEN_FONT_UPDATE:
|
|
|
|
case LFUN_SET_COLOR:
|
|
|
|
case LFUN_WINDOW_NEW:
|
|
|
|
case LFUN_LYX_QUIT:
|
|
|
|
enable = true;
|
|
|
|
break;
|
|
|
|
|
2007-11-24 07:58:12 +00:00
|
|
|
default:
|
2008-05-23 09:53:27 +00:00
|
|
|
return false;
|
2007-11-24 07:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
flag.enabled(false);
|
|
|
|
|
2008-05-23 09:53:27 +00:00
|
|
|
return true;
|
2007-11-24 07:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 14:36:50 +00:00
|
|
|
bool GuiApplication::dispatch(FuncRequest const & cmd)
|
2007-11-24 07:58:12 +00:00
|
|
|
{
|
|
|
|
switch(cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_WINDOW_NEW:
|
2007-11-24 08:51:11 +00:00
|
|
|
createView(toqstr(cmd.argument()));
|
2007-11-24 07:58:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_WINDOW_CLOSE:
|
|
|
|
// update bookmark pit of the current buffer before window close
|
|
|
|
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
|
|
|
|
theLyXFunc().gotoBookmark(i+1, false, false);
|
|
|
|
current_view_->close();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_LYX_QUIT:
|
|
|
|
// quitting is triggered by the gui code
|
|
|
|
// (leaving the event loop).
|
2008-03-15 02:42:59 +00:00
|
|
|
if (current_view_)
|
|
|
|
current_view_->message(from_utf8(N_("Exiting.")));
|
2008-02-27 10:35:28 +00:00
|
|
|
if (closeAllViews())
|
|
|
|
quit();
|
2007-11-24 07:58:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_SCREEN_FONT_UPDATE: {
|
|
|
|
// handle the screen font changes.
|
2008-05-23 08:43:07 +00:00
|
|
|
d->font_loader_.update();
|
2007-11-24 07:58:12 +00:00
|
|
|
// Backup current_view_
|
|
|
|
GuiView * view = current_view_;
|
|
|
|
// Set current_view_ to zero to forbid GuiWorkArea::redraw()
|
|
|
|
// to skip the refresh.
|
|
|
|
current_view_ = 0;
|
|
|
|
BufferList::iterator it = theBufferList().begin();
|
|
|
|
BufferList::iterator const end = theBufferList().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
(*it)->changed();
|
|
|
|
// Restore current_view_
|
|
|
|
current_view_ = view;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-14 23:24:45 +00:00
|
|
|
case LFUN_BUFFER_NEW:
|
2008-05-23 11:08:12 +00:00
|
|
|
if (d->views_.empty()
|
2008-03-14 23:33:05 +00:00
|
|
|
|| (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
|
|
|
|
createView(QString(), false); // keep hidden
|
|
|
|
current_view_->newDocument(to_utf8(cmd.argument()), false);
|
|
|
|
current_view_->show();
|
|
|
|
setActiveWindow(current_view_);
|
|
|
|
} else
|
|
|
|
current_view_->newDocument(to_utf8(cmd.argument()), false);
|
2008-03-14 23:24:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_NEW_TEMPLATE:
|
2008-05-23 11:08:12 +00:00
|
|
|
if (d->views_.empty()
|
2008-03-14 23:27:31 +00:00
|
|
|
|| (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
|
2008-03-14 23:24:45 +00:00
|
|
|
createView();
|
|
|
|
current_view_->newDocument(to_utf8(cmd.argument()), true);
|
|
|
|
if (!current_view_->buffer())
|
|
|
|
current_view_->close();
|
|
|
|
} else
|
|
|
|
current_view_->newDocument(to_utf8(cmd.argument()), true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_FILE_OPEN:
|
2008-05-23 11:08:12 +00:00
|
|
|
if (d->views_.empty()
|
2008-03-14 23:27:31 +00:00
|
|
|
|| (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
|
2008-03-14 23:24:45 +00:00
|
|
|
createView();
|
|
|
|
current_view_->openDocument(to_utf8(cmd.argument()));
|
|
|
|
if (!current_view_->buffer())
|
|
|
|
current_view_->close();
|
|
|
|
} else
|
|
|
|
current_view_->openDocument(to_utf8(cmd.argument()));
|
|
|
|
break;
|
|
|
|
|
2008-05-23 09:53:27 +00:00
|
|
|
case LFUN_SET_COLOR: {
|
|
|
|
string lyx_name;
|
|
|
|
string const x11_name = split(to_utf8(cmd.argument()), lyx_name, ' ');
|
|
|
|
if (lyx_name.empty() || x11_name.empty()) {
|
|
|
|
current_view_->message(
|
|
|
|
_("Syntax: set-color <lyx_name> <x11_name>"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const graphicsbg = lcolor.getLyXName(Color_graphicsbg);
|
|
|
|
bool const graphicsbg_changed = lyx_name == graphicsbg
|
|
|
|
&& x11_name != graphicsbg;
|
|
|
|
if (graphicsbg_changed) {
|
|
|
|
// FIXME: The graphics cache no longer has a changeDisplay method.
|
|
|
|
#if 0
|
|
|
|
graphics::GCache::get().changeDisplay(true);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lcolor.setColor(lyx_name, x11_name)) {
|
|
|
|
current_view_->message(
|
|
|
|
bformat(_("Set-color \"%1$s\" failed "
|
|
|
|
"- color is undefined or "
|
|
|
|
"may not be redefined"),
|
|
|
|
from_utf8(lyx_name)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Make sure we don't keep old colors in cache.
|
|
|
|
d->color_cache_.clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-24 07:58:12 +00:00
|
|
|
default:
|
2007-11-26 14:36:50 +00:00
|
|
|
// Notify the caller that the action has not been dispatched.
|
|
|
|
return false;
|
2007-11-24 07:58:12 +00:00
|
|
|
}
|
2007-11-26 14:36:50 +00:00
|
|
|
|
|
|
|
// The action has been dispatched.
|
|
|
|
return true;
|
2007-11-24 07:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-21 15:12:47 +00:00
|
|
|
void GuiApplication::resetGui()
|
|
|
|
{
|
|
|
|
map<int, GuiView *>::iterator it;
|
2008-05-23 08:43:07 +00:00
|
|
|
for (it = d->views_.begin(); it != d->views_.end(); ++it)
|
2007-11-21 15:12:47 +00:00
|
|
|
it->second->resetDialogs();
|
2007-11-24 07:58:12 +00:00
|
|
|
|
|
|
|
dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
|
2007-11-21 15:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-14 23:33:05 +00:00
|
|
|
void GuiApplication::createView(QString const & geometry_arg, bool autoShow)
|
2007-11-13 15:29:15 +00:00
|
|
|
{
|
2008-03-14 23:31:44 +00:00
|
|
|
// release the keyboard which might have been grabed by the global
|
|
|
|
// menubar on Mac to catch shortcuts even without any GuiView.
|
2008-05-23 07:52:39 +00:00
|
|
|
if (d->global_menubar_)
|
|
|
|
d->global_menubar_->releaseKeyboard();
|
2008-03-14 23:25:24 +00:00
|
|
|
|
2008-03-14 16:39:34 +00:00
|
|
|
// create new view
|
2007-11-18 20:36:52 +00:00
|
|
|
int id = 0;
|
2008-05-23 08:43:07 +00:00
|
|
|
while (d->views_.find(id) != d->views_.end())
|
2007-11-18 20:36:52 +00:00
|
|
|
id++;
|
2008-03-14 16:39:34 +00:00
|
|
|
GuiView * view = new GuiView(id);
|
|
|
|
|
|
|
|
// copy the icon size from old view
|
2008-05-23 11:08:12 +00:00
|
|
|
if (current_view_)
|
2008-03-14 16:39:34 +00:00
|
|
|
view->setIconSize(current_view_->iconSize());
|
2007-11-18 20:36:52 +00:00
|
|
|
|
2008-03-14 16:39:34 +00:00
|
|
|
// register view
|
2008-05-23 08:43:07 +00:00
|
|
|
d->views_[id] = view;
|
2008-03-14 23:29:11 +00:00
|
|
|
|
2008-03-14 23:33:05 +00:00
|
|
|
if (autoShow) {
|
|
|
|
view->show();
|
|
|
|
setActiveWindow(view);
|
|
|
|
}
|
|
|
|
|
2007-11-24 08:51:11 +00:00
|
|
|
if (!geometry_arg.isEmpty()) {
|
2007-11-15 12:58:44 +00:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
int x, y;
|
|
|
|
int w, h;
|
|
|
|
QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
|
2007-11-24 08:51:11 +00:00
|
|
|
re.indexIn(geometry_arg);
|
2007-11-15 12:58:44 +00:00
|
|
|
w = re.cap(1).toInt();
|
|
|
|
h = re.cap(2).toInt();
|
|
|
|
x = re.cap(3).toInt();
|
|
|
|
y = re.cap(4).toInt();
|
2007-11-17 20:47:50 +00:00
|
|
|
view->setGeometry(x, y, w, h);
|
2007-11-15 12:58:44 +00:00
|
|
|
#endif
|
|
|
|
}
|
2007-11-17 20:47:50 +00:00
|
|
|
view->setFocus();
|
2008-03-15 02:42:59 +00:00
|
|
|
setCurrentView(view);
|
2007-11-13 15:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
Clipboard & GuiApplication::clipboard()
|
2006-09-22 15:02:41 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
return d->clipboard_;
|
2006-09-22 15:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
Selection & GuiApplication::selection()
|
2006-09-22 15:02:41 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
return d->selection_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FontLoader & GuiApplication::fontLoader()
|
|
|
|
{
|
|
|
|
return d->font_loader_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Menus const & GuiApplication::menus() const
|
|
|
|
{
|
|
|
|
return d->menus_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Menus & GuiApplication::menus()
|
|
|
|
{
|
|
|
|
return d->menus_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-23 10:45:55 +00:00
|
|
|
QVector<int> GuiApplication::viewIds()
|
2008-05-23 08:43:07 +00:00
|
|
|
{
|
2008-05-23 10:45:55 +00:00
|
|
|
QVector<int> ids;
|
|
|
|
map<int, GuiView *>::const_iterator end = d->views_.end();
|
|
|
|
map<int, GuiView *>::const_iterator it = d->views_.begin();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
ids.push_back(it->first);
|
|
|
|
return ids;
|
2008-05-23 08:43:07 +00:00
|
|
|
}
|
|
|
|
|
2008-05-23 10:45:55 +00:00
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
ColorCache & GuiApplication::colorCache()
|
|
|
|
{
|
|
|
|
return d->color_cache_;
|
2006-09-22 15:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
int GuiApplication::exec()
|
2006-06-26 17:18:28 +00:00
|
|
|
{
|
2006-11-26 02:18:32 +00:00
|
|
|
QTimer::singleShot(1, this, SLOT(execBatchCommands()));
|
2006-09-22 09:47:39 +00:00
|
|
|
return QApplication::exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiApplication::exit(int status)
|
|
|
|
{
|
|
|
|
QApplication::exit(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-26 02:18:32 +00:00
|
|
|
void GuiApplication::execBatchCommands()
|
|
|
|
{
|
2008-05-23 08:57:41 +00:00
|
|
|
// init the global menubar on Mac. This must be done after the session
|
|
|
|
// was recovered to know the "last files".
|
|
|
|
if (d->global_menubar_)
|
|
|
|
d->menus_.fillMenuBar(d->global_menubar_, 0, true);
|
|
|
|
|
2006-11-26 02:18:32 +00:00
|
|
|
LyX::ref().execBatchCommands();
|
2008-05-14 10:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractItemModel * GuiApplication::languageModel()
|
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
if (d->language_model_)
|
|
|
|
return d->language_model_;
|
2008-05-08 09:03:38 +00:00
|
|
|
|
2008-05-14 10:34:19 +00:00
|
|
|
QStandardItemModel * lang_model = new QStandardItemModel(this);
|
|
|
|
lang_model->insertColumns(0, 1);
|
2008-05-08 09:03:38 +00:00
|
|
|
int current_row;
|
|
|
|
Languages::const_iterator it = languages.begin();
|
|
|
|
Languages::const_iterator end = languages.end();
|
|
|
|
for (; it != end; ++it) {
|
2008-05-14 10:34:19 +00:00
|
|
|
current_row = lang_model->rowCount();
|
|
|
|
lang_model->insertRows(current_row, 1);
|
|
|
|
QModelIndex item = lang_model->index(current_row, 0);
|
|
|
|
lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
|
|
|
|
lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
|
2008-05-08 09:03:38 +00:00
|
|
|
}
|
2008-05-23 08:43:07 +00:00
|
|
|
d->language_model_ = new QSortFilterProxyModel(this);
|
|
|
|
d->language_model_->setSourceModel(lang_model);
|
2008-05-16 14:30:46 +00:00
|
|
|
#if QT_VERSION >= 0x040300
|
2008-05-23 08:43:07 +00:00
|
|
|
d->language_model_->setSortLocaleAware(true);
|
2008-05-16 14:30:46 +00:00
|
|
|
#endif
|
2008-05-23 08:43:07 +00:00
|
|
|
return d->language_model_;
|
2006-11-26 02:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 23:02:57 +00:00
|
|
|
void GuiApplication::restoreGuiSession()
|
|
|
|
{
|
|
|
|
if (!lyxrc.load_session)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Session & session = LyX::ref().session();
|
|
|
|
vector<FileName> const & lastopened = session.lastOpened().getfiles();
|
|
|
|
// do not add to the lastfile list since these files are restored from
|
|
|
|
// last session, and should be already there (regular files), or should
|
|
|
|
// not be added at all (help files).
|
|
|
|
for_each(lastopened.begin(), lastopened.end(),
|
|
|
|
bind(&GuiView::loadDocument, current_view_, _1, false));
|
|
|
|
|
|
|
|
// clear this list to save a few bytes of RAM
|
|
|
|
session.lastOpened().clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
QString const GuiApplication::romanFontName()
|
2006-10-03 10:34:10 +00:00
|
|
|
{
|
|
|
|
QFont font;
|
2006-10-22 13:10:12 +00:00
|
|
|
font.setKerning(false);
|
2006-10-03 10:34:10 +00:00
|
|
|
font.setStyleHint(QFont::Serif);
|
|
|
|
font.setFamily("serif");
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
return QFontInfo(font).family();
|
2006-10-03 10:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
QString const GuiApplication::sansFontName()
|
2006-10-03 10:34:10 +00:00
|
|
|
{
|
|
|
|
QFont font;
|
2006-10-22 13:10:12 +00:00
|
|
|
font.setKerning(false);
|
2006-10-03 10:34:10 +00:00
|
|
|
font.setStyleHint(QFont::SansSerif);
|
|
|
|
font.setFamily("sans");
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
return QFontInfo(font).family();
|
2006-10-03 10:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
QString const GuiApplication::typewriterFontName()
|
2006-10-03 10:34:10 +00:00
|
|
|
{
|
|
|
|
QFont font;
|
2006-10-22 13:10:12 +00:00
|
|
|
font.setKerning(false);
|
2006-10-03 10:34:10 +00:00
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
font.setFamily("monospace");
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
return QFontInfo(font).family();
|
2006-10-03 10:34:10 +00:00
|
|
|
}
|
2006-06-26 17:18:28 +00:00
|
|
|
|
|
|
|
|
2008-02-05 13:10:42 +00:00
|
|
|
void GuiApplication::handleRegularEvents()
|
|
|
|
{
|
|
|
|
ForkedCallsController::handleCompletedProcesses();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-29 09:06:37 +00:00
|
|
|
bool GuiApplication::event(QEvent * e)
|
|
|
|
{
|
|
|
|
switch(e->type()) {
|
|
|
|
case QEvent::FileOpen: {
|
|
|
|
// Open a file; this happens only on Mac OS X for now
|
|
|
|
QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
|
2007-05-04 17:20:53 +00:00
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
if (!current_view_ || !current_view_->view())
|
2007-05-04 17:20:53 +00:00
|
|
|
// The application is not properly initialized yet.
|
|
|
|
// So we acknowledge the event and delay the file opening
|
|
|
|
// until LyX is ready.
|
|
|
|
// FIXME UNICODE: FileName accept an utf8 encoded string.
|
2008-02-06 23:02:57 +00:00
|
|
|
LyX::ref().addFileToLoad(fromqstr(foe->file()));
|
2007-05-04 17:20:53 +00:00
|
|
|
else
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
|
|
|
|
qstring_to_ucs4(foe->file())));
|
|
|
|
|
|
|
|
e->accept();
|
2006-11-29 09:06:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
2007-01-31 16:07:37 +00:00
|
|
|
return QApplication::event(e);
|
2006-11-29 09:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-01 16:06:43 +00:00
|
|
|
bool GuiApplication::notify(QObject * receiver, QEvent * event)
|
|
|
|
{
|
|
|
|
try {
|
2007-11-13 23:00:36 +00:00
|
|
|
return QApplication::notify(receiver, event);
|
2007-04-01 16:06:43 +00:00
|
|
|
}
|
2007-12-12 19:57:42 +00:00
|
|
|
catch (ExceptionMessage const & e) {
|
2008-02-29 08:10:51 +00:00
|
|
|
switch(e.type_) {
|
|
|
|
case ErrorException:
|
2008-02-28 20:40:55 +00:00
|
|
|
LyX::cref().emergencyCleanup();
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
closeAllViews();
|
2007-09-21 20:27:07 +00:00
|
|
|
Alert::error(e.title_, e.details_);
|
2008-02-28 20:40:55 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Properly crash in debug mode in order to get a useful backtrace.
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
// In release mode, try to exit gracefully.
|
|
|
|
this->exit(1);
|
2008-02-29 08:10:51 +00:00
|
|
|
|
|
|
|
case BufferException: {
|
|
|
|
Buffer * buf = current_view_->buffer();
|
|
|
|
docstring details = e.details_ + '\n';
|
|
|
|
details += theBufferList().emergencyWrite(buf);
|
|
|
|
theBufferList().release(buf);
|
2008-03-17 02:49:47 +00:00
|
|
|
details += "\n" + _("The current document was closed.");
|
2008-02-29 08:10:51 +00:00
|
|
|
Alert::error(e.title_, details);
|
2007-11-13 23:00:36 +00:00
|
|
|
return false;
|
2007-09-21 20:27:07 +00:00
|
|
|
}
|
2008-02-29 08:10:51 +00:00
|
|
|
case WarningException:
|
|
|
|
Alert::warning(e.title_, e.details_);
|
|
|
|
return false;
|
2008-03-26 22:25:43 +00:00
|
|
|
}
|
2007-09-21 20:27:07 +00:00
|
|
|
}
|
2007-12-12 19:28:07 +00:00
|
|
|
catch (exception const & e) {
|
2007-09-27 09:49:14 +00:00
|
|
|
docstring s = _("LyX has caught an exception, it will now "
|
2007-12-02 23:55:38 +00:00
|
|
|
"attempt to save all unsaved documents and exit."
|
2007-09-27 09:49:14 +00:00
|
|
|
"\n\nException: ");
|
|
|
|
s += from_ascii(e.what());
|
|
|
|
Alert::error(_("Software exception Detected"), s);
|
2007-12-16 11:34:29 +00:00
|
|
|
LyX::cref().exit(1);
|
2007-04-02 10:18:12 +00:00
|
|
|
}
|
2007-04-01 16:06:43 +00:00
|
|
|
catch (...) {
|
2007-09-27 09:49:14 +00:00
|
|
|
docstring s = _("LyX has caught some really weird exception, it will "
|
2007-12-02 23:55:38 +00:00
|
|
|
"now attempt to save all unsaved documents and exit.");
|
2007-09-27 09:49:14 +00:00
|
|
|
Alert::error(_("Software exception Detected"), s);
|
2007-12-16 11:34:29 +00:00
|
|
|
LyX::cref().exit(1);
|
2007-04-01 16:06:43 +00:00
|
|
|
}
|
|
|
|
|
2007-11-13 23:00:36 +00:00
|
|
|
return false;
|
2007-04-01 16:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-13 23:00:36 +00:00
|
|
|
bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
QColor const & qcol = d->color_cache_.get(col);
|
2006-10-12 14:10:13 +00:00
|
|
|
if (!qcol.isValid()) {
|
|
|
|
rgbcol.r = 0;
|
|
|
|
rgbcol.g = 0;
|
|
|
|
rgbcol.b = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rgbcol.r = qcol.red();
|
|
|
|
rgbcol.g = qcol.green();
|
|
|
|
rgbcol.b = qcol.blue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
string const GuiApplication::hexName(ColorCode col)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
return ltrim(fromqstr(d->color_cache_.get(col).name()), "#");
|
2006-10-12 14:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 20:31:50 +00:00
|
|
|
void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
|
|
|
|
{
|
|
|
|
SocketNotifier * sn = new SocketNotifier(this, fd, func);
|
2008-05-23 08:43:07 +00:00
|
|
|
d->socket_notifiers_[fd] = sn;
|
2007-09-15 20:31:50 +00:00
|
|
|
connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiApplication::socketDataReceived(int fd)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
d->socket_notifiers_[fd]->func_();
|
2006-10-12 14:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
void GuiApplication::unregisterSocketCallback(int fd)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
d->socket_notifiers_[fd]->setEnabled(false);
|
|
|
|
d->socket_notifiers_.erase(fd);
|
2006-10-12 14:10:13 +00:00
|
|
|
}
|
|
|
|
|
2007-08-27 06:35:24 +00:00
|
|
|
|
|
|
|
void GuiApplication::commitData(QSessionManager & sm)
|
|
|
|
{
|
|
|
|
/// The implementation is required to avoid an application exit
|
|
|
|
/// when session state save is triggered by session manager.
|
|
|
|
/// The default implementation sends a close event to all
|
|
|
|
/// visible top level widgets when session managment allows
|
|
|
|
/// interaction.
|
2008-02-27 10:35:28 +00:00
|
|
|
/// We are changing that to close all wiew one by one.
|
|
|
|
/// FIXME: verify if the default implementation is enough now.
|
|
|
|
if (sm.allowsInteraction() && !closeAllViews())
|
2007-08-27 06:35:24 +00:00
|
|
|
sm.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-23 10:54:34 +00:00
|
|
|
void GuiApplication::unregisterView(GuiView * gv)
|
2007-11-17 20:47:50 +00:00
|
|
|
{
|
2008-05-23 10:54:34 +00:00
|
|
|
LASSERT(d->views_[gv->id()] == gv, /**/);
|
|
|
|
d->views_.erase(gv->id());
|
2008-05-23 11:16:23 +00:00
|
|
|
if (current_view_ == gv) {
|
2008-05-23 11:08:12 +00:00
|
|
|
current_view_ = 0;
|
2008-05-23 11:16:23 +00:00
|
|
|
theLyXFunc().setLyXView(0);
|
|
|
|
}
|
2007-11-17 20:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiApplication::closeAllViews()
|
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
if (d->views_.empty())
|
2007-11-17 20:47:50 +00:00
|
|
|
return true;
|
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
map<int, GuiView*> const cmap = d->views_;
|
2007-11-17 20:47:50 +00:00
|
|
|
map<int, GuiView*>::const_iterator it;
|
|
|
|
for (it = cmap.begin(); it != cmap.end(); ++it) {
|
2008-02-27 10:35:28 +00:00
|
|
|
if (!it->second->close())
|
|
|
|
return false;
|
2007-11-17 20:47:50 +00:00
|
|
|
}
|
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
d->views_.clear();
|
2007-11-17 20:47:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 20:56:05 +00:00
|
|
|
GuiView & GuiApplication::view(int id) const
|
2007-11-17 20:47:50 +00:00
|
|
|
{
|
2008-05-23 08:43:07 +00:00
|
|
|
LASSERT(d->views_.find(id) != d->views_.end(), /**/);
|
|
|
|
return *d->views_.find(id)->second;
|
2007-11-17 20:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiApplication::hideDialogs(string const & name, Inset * inset) const
|
|
|
|
{
|
2008-05-23 10:45:55 +00:00
|
|
|
map<int, GuiView *>::iterator end = d->views_.end();
|
|
|
|
for (map<int, GuiView *>::iterator it = d->views_.begin(); it != end; ++it)
|
|
|
|
it->second->hideDialog(name, inset);
|
2007-11-17 20:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Buffer const * GuiApplication::updateInset(Inset const * inset) const
|
|
|
|
{
|
|
|
|
Buffer const * buffer_ = 0;
|
2008-05-23 10:45:55 +00:00
|
|
|
map<int, GuiView *>::iterator end = d->views_.end();
|
|
|
|
for (map<int, GuiView *>::iterator it = d->views_.begin(); it != end; ++it) {
|
|
|
|
if (Buffer const * ptr = it->second->updateInset(inset))
|
2007-11-17 20:47:50 +00:00
|
|
|
buffer_ = ptr;
|
|
|
|
}
|
|
|
|
return buffer_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 21:50:27 +00:00
|
|
|
void GuiApplication::readMenus(Lexer & lex)
|
|
|
|
{
|
2008-03-07 00:21:23 +00:00
|
|
|
menus().read(lex);
|
2008-03-06 21:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiApplication::searchMenu(FuncRequest const & func,
|
|
|
|
vector<docstring> & names) const
|
|
|
|
{
|
2008-03-08 15:33:52 +00:00
|
|
|
return menus().searchMenu(func, names);
|
2008-03-06 21:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-14 23:25:11 +00:00
|
|
|
void GuiApplication::onLastWindowClosed()
|
|
|
|
{
|
2008-05-23 07:52:39 +00:00
|
|
|
if (d->global_menubar_)
|
|
|
|
d->global_menubar_->grabKeyboard();
|
2008-03-14 23:25:11 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 00:07:54 +00:00
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2008-03-27 00:07:54 +00:00
|
|
|
//
|
2006-06-26 17:18:28 +00:00
|
|
|
// X11 specific stuff goes here...
|
2008-03-27 00:07:54 +00:00
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
#ifdef Q_WS_X11
|
2006-09-22 09:47:39 +00:00
|
|
|
bool GuiApplication::x11EventFilter(XEvent * xev)
|
2006-06-26 17:18:28 +00:00
|
|
|
{
|
2007-11-18 20:36:52 +00:00
|
|
|
if (!current_view_)
|
2006-12-04 13:52:02 +00:00
|
|
|
return false;
|
|
|
|
|
2006-11-07 18:17:15 +00:00
|
|
|
switch (xev->type) {
|
2007-01-04 15:36:29 +00:00
|
|
|
case SelectionRequest: {
|
2007-01-05 10:11:21 +00:00
|
|
|
if (xev->xselectionrequest.selection != XA_PRIMARY)
|
|
|
|
break;
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "X requested selection.");
|
2007-11-18 20:36:52 +00:00
|
|
|
BufferView * bv = current_view_->view();
|
2006-11-07 17:19:33 +00:00
|
|
|
if (bv) {
|
2007-01-05 10:11:21 +00:00
|
|
|
docstring const sel = bv->requestSelection();
|
2006-09-17 08:35:12 +00:00
|
|
|
if (!sel.empty())
|
2008-05-23 09:32:49 +00:00
|
|
|
d->selection_.put(sel);
|
2006-09-17 08:35:12 +00:00
|
|
|
}
|
2006-06-26 17:18:28 +00:00
|
|
|
break;
|
2007-01-04 15:36:29 +00:00
|
|
|
}
|
|
|
|
case SelectionClear: {
|
2007-01-05 10:11:21 +00:00
|
|
|
if (xev->xselectionclear.selection != XA_PRIMARY)
|
|
|
|
break;
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "Lost selection.");
|
2007-11-18 20:36:52 +00:00
|
|
|
BufferView * bv = current_view_->view();
|
2006-11-07 17:19:33 +00:00
|
|
|
if (bv)
|
|
|
|
bv->clearSelection();
|
2006-06-26 17:18:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-04 15:36:29 +00:00
|
|
|
}
|
2006-06-26 17:18:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace frontend
|
2007-11-17 22:11:11 +00:00
|
|
|
|
|
|
|
|
2008-03-27 00:07:54 +00:00
|
|
|
void hideDialogs(std::string const & name, Inset * inset)
|
|
|
|
{
|
|
|
|
if (theApp())
|
|
|
|
theApp()->hideDialogs(name, inset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 22:11:11 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Font stuff
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
frontend::FontLoader & theFontLoader()
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(frontend::guiApp, /**/);
|
2007-11-18 20:36:52 +00:00
|
|
|
return frontend::guiApp->fontLoader();
|
2007-11-17 22:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frontend::FontMetrics const & theFontMetrics(Font const & f)
|
|
|
|
{
|
|
|
|
return theFontMetrics(f.fontInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(frontend::guiApp, /**/);
|
2007-11-18 20:36:52 +00:00
|
|
|
return frontend::guiApp->fontLoader().metrics(f);
|
2007-11-17 22:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 00:07:54 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Misc stuff
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-11-17 22:11:11 +00:00
|
|
|
frontend::Clipboard & theClipboard()
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(frontend::guiApp, /**/);
|
2007-11-17 22:11:11 +00:00
|
|
|
return frontend::guiApp->clipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frontend::Selection & theSelection()
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(frontend::guiApp, /**/);
|
2007-11-17 22:11:11 +00:00
|
|
|
return frontend::guiApp->selection();
|
|
|
|
}
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
} // namespace lyx
|
2006-10-23 16:29:24 +00:00
|
|
|
|
|
|
|
#include "GuiApplication_moc.cpp"
|