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"
|
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/NoGuiFontLoader.h"
|
|
|
|
#include "frontends/NoGuiFontMetrics.h"
|
|
|
|
#include "frontends/FontLoader.h"
|
|
|
|
#include "frontends/FontMetrics.h"
|
2006-11-07 17:19:33 +00:00
|
|
|
|
2007-09-21 20:27:07 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2007-05-04 17:20:53 +00:00
|
|
|
#include "support/FileName.h"
|
2006-06-26 17:18:28 +00:00
|
|
|
#include "support/lstrings.h"
|
2006-09-22 09:47:39 +00:00
|
|
|
#include "support/os.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Package.h"
|
2006-09-22 09:47:39 +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-29 07:04:28 +00:00
|
|
|
#include "support/debug.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-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.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
|
|
|
|
|
|
|
#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-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
|
|
|
|
|
|
|
|
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)
|
2007-11-18 20:36:52 +00:00
|
|
|
: QApplication(argc, argv), Application(), current_view_(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
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
// Qt bug? setQuitOnLastWindowClosed(true); does not work
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
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
|
|
|
|
|
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());
|
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);
|
|
|
|
// ask the user for saving changes or cancel quit
|
2007-12-04 22:21:25 +00:00
|
|
|
if (!current_view_->quitWriteAll())
|
2007-11-24 07:58:12 +00:00
|
|
|
break;
|
|
|
|
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.")));
|
2007-12-04 22:21:25 +00:00
|
|
|
if (current_view_->quitWriteAll())
|
2007-11-24 07:58:12 +00:00
|
|
|
closeAllViews();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2007-11-18 20:36:52 +00:00
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
int id = 0;
|
|
|
|
while (views_.find(id) != views_.end())
|
|
|
|
id++;
|
|
|
|
views_[id] = new GuiView(id);
|
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
|
2007-11-17 20:47:50 +00:00
|
|
|
GuiView * view = views_[id];
|
|
|
|
theLyXFunc().setLyXView(view);
|
2007-11-13 15:29:15 +00:00
|
|
|
|
2007-11-17 20:47:50 +00:00
|
|
|
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();
|
2007-11-13 15:29:15 +00:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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.
|
|
|
|
LyX::ref().addFileToLoad(FileName(fromqstr(foe->file())));
|
|
|
|
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) {
|
|
|
|
if (e.type_ == ErrorException) {
|
2007-09-21 20:27:07 +00:00
|
|
|
Alert::error(e.title_, e.details_);
|
|
|
|
LyX::cref().emergencyCleanup();
|
2007-09-27 08:56:18 +00:00
|
|
|
QApplication::exit(1);
|
2007-12-12 19:57:42 +00:00
|
|
|
} else if (e.type_ == WarningException) {
|
2007-09-21 20:27:07 +00:00
|
|
|
Alert::warning(e.title_, e.details_);
|
2007-11-13 23:00:36 +00:00
|
|
|
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-04-02 10:18:12 +00:00
|
|
|
LyX::cref().emergencyCleanup();
|
2007-09-27 08:56:18 +00:00
|
|
|
QApplication::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-04-01 16:06:43 +00:00
|
|
|
LyX::cref().emergencyCleanup();
|
2007-09-27 08:56:18 +00:00
|
|
|
QApplication::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.
|
|
|
|
/// We are changing that to write all unsaved buffers...
|
2007-12-04 22:21:25 +00:00
|
|
|
if (sm.allowsInteraction() && !current_view_->quitWriteAll())
|
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_);
|
|
|
|
if (views_.empty()) {
|
|
|
|
// quit in CloseEvent will not be triggert
|
|
|
|
qApp->quit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
map<int, GuiView*> const cmap = views_;
|
|
|
|
map<int, GuiView*>::const_iterator it;
|
|
|
|
for (it = cmap.begin(); it != cmap.end(); ++it) {
|
|
|
|
// TODO: return false when close event was ignored
|
|
|
|
// e.g. quitWriteAll()->'Cancel'
|
|
|
|
// maybe we need something like 'bool closeView()'
|
|
|
|
it->second->close();
|
|
|
|
// unregisterd by the CloseEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
static frontend::NoGuiFontLoader no_gui_font_loader;
|
|
|
|
|
|
|
|
if (!use_gui)
|
|
|
|
return no_gui_font_loader;
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
static frontend::NoGuiFontMetrics no_gui_font_metrics;
|
|
|
|
|
|
|
|
if (!use_gui)
|
|
|
|
return no_gui_font_metrics;
|
|
|
|
|
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"
|