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"
|
2006-08-17 08:37:46 +00:00
|
|
|
|
2007-09-21 20:27:07 +00:00
|
|
|
#include "frontends/alert.h"
|
2006-11-07 17:19:33 +00:00
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include "graphics/LoaderQueue.h"
|
2006-08-17 08:37:46 +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-08-27 06:35:24 +00:00
|
|
|
#include "BufferList.h"
|
2006-09-29 23:21:03 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-26 19:21:38 +00:00
|
|
|
#include "Color.h"
|
2006-10-12 14:10:13 +00:00
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-08-07 21:23:40 +00:00
|
|
|
#include "gettext.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyX.h"
|
|
|
|
#include "LyXFunc.h"
|
|
|
|
#include "LyXRC.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-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>
|
|
|
|
#endif
|
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2007-04-02 10:18:12 +00:00
|
|
|
#include <exception>
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
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
|
|
|
using support::FileName;
|
2006-10-13 16:48:12 +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-09-15 20:31:50 +00:00
|
|
|
: QApplication(argc, argv), Application(argc, argv)
|
2006-06-26 17:18:28 +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-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2006-09-22 09:47:39 +00:00
|
|
|
<< "Successfully installed Qt translations for locale "
|
|
|
|
<< fromqstr(language_name) << std::endl;
|
|
|
|
} else
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2006-09-22 09:47:39 +00:00
|
|
|
<< "Could not find Qt translations for locale "
|
|
|
|
<< fromqstr(language_name) << std::endl;
|
|
|
|
|
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
|
|
|
|
|
|
|
LoaderQueue::setPriority(10,100);
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-03 10:34:10 +00:00
|
|
|
string const GuiApplication::romanFontName()
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
|
|
|
|
return fromqstr(QFontInfo(font).family());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const GuiApplication::sansFontName()
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
|
|
|
|
return fromqstr(QFontInfo(font).family());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const GuiApplication::typewriterFontName()
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
|
|
|
|
return fromqstr(QFontInfo(font).family());
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (!currentView() || !currentView()->view())
|
|
|
|
// 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)
|
|
|
|
{
|
2007-09-22 15:56:26 +00:00
|
|
|
bool return_value = false;
|
2007-04-01 16:06:43 +00:00
|
|
|
try {
|
|
|
|
return_value = QApplication::notify(receiver, event);
|
|
|
|
}
|
2007-09-21 20:27:07 +00:00
|
|
|
catch (support::ExceptionMessage const & e) {
|
|
|
|
if (e.type_ == support::ErrorException) {
|
|
|
|
Alert::error(e.title_, e.details_);
|
|
|
|
LyX::cref().emergencyCleanup();
|
2007-09-27 08:56:18 +00:00
|
|
|
QApplication::exit(1);
|
2007-09-21 20:27:07 +00:00
|
|
|
} else if (e.type_ == support::WarningException) {
|
|
|
|
Alert::warning(e.title_, e.details_);
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
}
|
2007-04-02 10:18:12 +00:00
|
|
|
catch (std::exception const & e) {
|
|
|
|
lyxerr << "Caught \"normal\" exception: " << e.what() << endl;
|
|
|
|
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-04-02 10:18:12 +00:00
|
|
|
lyxerr << "Caught some really weird exception..." << endl;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-12 14:10:13 +00:00
|
|
|
void GuiApplication::syncEvents()
|
|
|
|
{
|
|
|
|
// This is the ONLY place where processEvents may be called.
|
|
|
|
// During screen update/ redraw, this method is disabled to
|
|
|
|
// prevent keyboard events being handed to the LyX core, where
|
|
|
|
// they could cause re-entrant calls to screen update.
|
|
|
|
processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 17:34:20 +00:00
|
|
|
bool GuiApplication::getRgbColor(Color_color col,
|
2007-04-25 16:39:21 +00:00
|
|
|
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-04-26 17:34:20 +00:00
|
|
|
string const GuiApplication::hexName(Color_color col)
|
2006-10-12 14:10:13 +00:00
|
|
|
{
|
2007-09-15 17:47:35 +00:00
|
|
|
return support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
|
2006-10-12 14:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 17:34:20 +00:00
|
|
|
void GuiApplication::updateColor(Color_color)
|
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...
|
|
|
|
if (sm.allowsInteraction() && !theBufferList().quitWriteAll())
|
|
|
|
sm.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2006-12-04 13:52:02 +00:00
|
|
|
if (!currentView())
|
|
|
|
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-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "X requested selection." << endl;
|
2007-01-04 15:36:29 +00:00
|
|
|
BufferView * bv = currentView()->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-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "Lost selection." << endl;
|
2007-01-04 15:36:29 +00:00
|
|
|
BufferView * bv = currentView()->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
|
|
|
|
|
2007-08-07 21:23:40 +00:00
|
|
|
void GuiApplication::addMenuTranslator()
|
|
|
|
{
|
2007-09-15 20:31:50 +00:00
|
|
|
installTranslator(new MenuTranslator(this));
|
2007-08-07 21:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-10-23 16:29:24 +00:00
|
|
|
|
|
|
|
#include "GuiApplication_moc.cpp"
|