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
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiImage.h"
|
2008-03-14 23:25:11 +00:00
|
|
|
#include "GuiKeySymbol.h"
|
2007-11-17 20:47:50 +00:00
|
|
|
#include "GuiView.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"
|
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"
|
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-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"
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
#include <QApplication>
|
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>
|
2007-12-26 09:54:48 +00:00
|
|
|
#include <QMenuBar>
|
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>
|
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
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2007-04-02 10:18:12 +00:00
|
|
|
#include <exception>
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
GuiApplication::GuiApplication(int & argc, char ** argv)
|
2008-03-14 23:25:11 +00:00
|
|
|
: QApplication(argc, argv), Application(), current_view_(0), global_menubar_(0)
|
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-14 23:25:11 +00:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
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
|
2007-01-04 11:05:57 +00:00
|
|
|
if (qt_trans_.load(language_name,
|
2006-09-22 09:47:39 +00:00
|
|
|
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
|
|
|
{
|
2007-08-07 21:23:40 +00:00
|
|
|
installTranslator(&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 "
|
|
|
|
<< fromqstr(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 "
|
|
|
|
<< fromqstr(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.
|
|
|
|
addMenuTranslator();
|
|
|
|
#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
|
|
|
|
|
|
|
general_timer_.setInterval(500);
|
|
|
|
connect(&general_timer_, SIGNAL(timeout()),
|
|
|
|
this, SLOT(handleRegularEvents()));
|
|
|
|
general_timer_.start();
|
2008-03-14 23:25:11 +00:00
|
|
|
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
if (global_menubar_ == 0) {
|
|
|
|
// Create the global default menubar which is shown for the dialogs
|
|
|
|
// and if no GuiView is visible.
|
|
|
|
global_menubar_ = new GlobalMenuBar();
|
|
|
|
}
|
|
|
|
#endif
|
2006-06-26 17:18:28 +00:00
|
|
|
}
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
GuiApplication::~GuiApplication()
|
|
|
|
{
|
2007-09-15 20:31:50 +00:00
|
|
|
socket_notifiers_.clear();
|
2007-09-15 17:47:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-24 07:58:12 +00:00
|
|
|
FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
|
|
|
|
{
|
|
|
|
FuncStatus flag;
|
|
|
|
bool enable = true;
|
|
|
|
|
|
|
|
switch(cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_WINDOW_CLOSE:
|
|
|
|
enable = view_ids_.size() > 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!current_view_) {
|
|
|
|
enable = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
flag.enabled(false);
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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).
|
|
|
|
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.
|
|
|
|
font_loader_.update();
|
|
|
|
// 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:
|
|
|
|
if (viewCount() == 0
|
|
|
|
|| (!lyxrc.single_window && current_view_->buffer() != 0))
|
|
|
|
createView();
|
|
|
|
current_view_->newDocument(to_utf8(cmd.argument()), false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_NEW_TEMPLATE:
|
|
|
|
if (viewCount() == 0
|
|
|
|
|| (!lyxrc.single_window && current_view_->buffer() != 0)) {
|
|
|
|
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:
|
|
|
|
if (viewCount() == 0
|
|
|
|
|| (!lyxrc.single_window && current_view_->buffer() != 0)) {
|
|
|
|
createView();
|
|
|
|
current_view_->openDocument(to_utf8(cmd.argument()));
|
|
|
|
if (!current_view_->buffer())
|
|
|
|
current_view_->close();
|
|
|
|
} else
|
|
|
|
current_view_->openDocument(to_utf8(cmd.argument()));
|
|
|
|
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;
|
|
|
|
for (it = views_.begin(); it != views_.end(); ++it)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
|
|
|
|
{
|
|
|
|
ids.clear();
|
|
|
|
map<int, GuiView *>::const_iterator it;
|
|
|
|
for (it = stdmap.begin(); it != stdmap.end(); ++it)
|
|
|
|
ids.push_back(it->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-24 08:51:11 +00:00
|
|
|
void GuiApplication::createView(QString const & geometry_arg)
|
2007-11-13 15:29:15 +00:00
|
|
|
{
|
2008-03-14 23:25:24 +00:00
|
|
|
if (global_menubar_)
|
|
|
|
global_menubar_->releaseKeyboard();
|
|
|
|
|
2008-03-14 16:39:34 +00:00
|
|
|
// create new view
|
2007-11-18 20:36:52 +00:00
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
int id = 0;
|
|
|
|
while (views_.find(id) != views_.end())
|
|
|
|
id++;
|
2008-03-14 16:39:34 +00:00
|
|
|
GuiView * view = new GuiView(id);
|
|
|
|
|
|
|
|
// copy the icon size from old view
|
|
|
|
if (viewCount() > 0)
|
|
|
|
view->setIconSize(current_view_->iconSize());
|
2007-11-18 20:36:52 +00:00
|
|
|
|
2008-03-14 16:39:34 +00:00
|
|
|
// register view
|
|
|
|
views_[id] = view;
|
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
|
2007-11-17 20:47:50 +00:00
|
|
|
theLyXFunc().setLyXView(view);
|
|
|
|
view->show();
|
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-14 23:24:45 +00:00
|
|
|
setActiveWindow(view);
|
2007-11-17 20:47:50 +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
|
|
|
{
|
|
|
|
return clipboard_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 17:47:35 +00:00
|
|
|
Selection & GuiApplication::selection()
|
2006-09-22 15:02:41 +00:00
|
|
|
{
|
|
|
|
return selection_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
LyX::ref().execBatchCommands();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
details += _("\nThe current document was closed.");
|
|
|
|
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;
|
|
|
|
};
|
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
|
|
|
{
|
|
|
|
QColor const & qcol = color_cache_.get(col);
|
|
|
|
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
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
return ltrim(fromqstr(color_cache_.get(col).name()), "#");
|
2006-10-12 14:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
void GuiApplication::updateColor(ColorCode)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
|
|
|
// FIXME: Bleh, can't we just clear them all at once ?
|
|
|
|
color_cache_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 20:31:50 +00:00
|
|
|
void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
|
|
|
|
{
|
|
|
|
SocketNotifier * sn = new SocketNotifier(this, fd, func);
|
|
|
|
socket_notifiers_[fd] = sn;
|
|
|
|
connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiApplication::socketDataReceived(int fd)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2007-09-15 20:31:50 +00:00
|
|
|
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
|
|
|
{
|
2007-09-15 20:31:50 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 20:47:50 +00:00
|
|
|
void GuiApplication::addMenuTranslator()
|
|
|
|
{
|
|
|
|
installTranslator(new MenuTranslator(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiApplication::unregisterView(int id)
|
|
|
|
{
|
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
BOOST_ASSERT(views_.find(id) != views_.end());
|
|
|
|
BOOST_ASSERT(views_[id]);
|
|
|
|
|
|
|
|
map<int, GuiView *>::iterator it;
|
|
|
|
for (it = views_.begin(); it != views_.end(); ++it) {
|
|
|
|
if (it->first == id) {
|
|
|
|
views_.erase(id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiApplication::closeAllViews()
|
|
|
|
{
|
|
|
|
updateIds(views_, view_ids_);
|
2008-02-27 10:35:28 +00:00
|
|
|
if (views_.empty())
|
2007-11-17 20:47:50 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
map<int, GuiView*> const cmap = views_;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
views_.clear();
|
|
|
|
view_ids_.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 20:56:05 +00:00
|
|
|
GuiView & GuiApplication::view(int id) const
|
2007-11-17 20:47:50 +00:00
|
|
|
{
|
|
|
|
BOOST_ASSERT(views_.find(id) != views_.end());
|
|
|
|
return *views_.find(id)->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiApplication::hideDialogs(string const & name, Inset * inset) const
|
|
|
|
{
|
|
|
|
vector<int>::const_iterator it = view_ids_.begin();
|
|
|
|
vector<int>::const_iterator const end = view_ids_.end();
|
|
|
|
for (; it != end; ++it)
|
2007-11-18 00:01:14 +00:00
|
|
|
view(*it).hideDialog(name, inset);
|
2007-11-17 20:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Buffer const * GuiApplication::updateInset(Inset const * inset) const
|
|
|
|
{
|
|
|
|
Buffer const * buffer_ = 0;
|
|
|
|
vector<int>::const_iterator it = view_ids_.begin();
|
|
|
|
vector<int>::const_iterator const end = view_ids_.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
Buffer const * ptr = view(*it).updateInset(inset);
|
|
|
|
if (ptr)
|
|
|
|
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::initGlobalMenu()
|
|
|
|
{
|
|
|
|
if (global_menubar_)
|
|
|
|
menus().fillMenuBar(global_menubar_, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiApplication::onLastWindowClosed()
|
|
|
|
{
|
|
|
|
if (global_menubar_)
|
|
|
|
global_menubar_->grabKeyboard();
|
|
|
|
}
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// X11 specific stuff goes here...
|
|
|
|
#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())
|
2006-09-22 18:45:22 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Font stuff
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
frontend::FontLoader & theFontLoader()
|
|
|
|
{
|
2007-11-18 20:36:52 +00:00
|
|
|
BOOST_ASSERT(frontend::guiApp);
|
|
|
|
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)
|
|
|
|
{
|
2007-11-18 20:36:52 +00:00
|
|
|
BOOST_ASSERT(frontend::guiApp);
|
|
|
|
return frontend::guiApp->fontLoader().metrics(f);
|
2007-11-17 22:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frontend::Clipboard & theClipboard()
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(frontend::guiApp);
|
|
|
|
return frontend::guiApp->clipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frontend::Selection & theSelection()
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(frontend::guiApp);
|
|
|
|
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"
|