2002-06-19 05:20:29 +00:00
|
|
|
/**
|
2002-09-26 08:57:43 +00:00
|
|
|
* \file qt2/lyx_gui.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 05:20:29 +00:00
|
|
|
*
|
|
|
|
* \author unknown
|
2002-09-24 13:57:09 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-19 05:20:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-12 01:48:53 +00:00
|
|
|
#include "lyx_gui.h"
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
// FIXME: move this stuff out again
|
|
|
|
#include "bufferlist.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "LColor.h"
|
2003-10-14 21:30:23 +00:00
|
|
|
#include "lyx_main.h"
|
2003-10-13 00:38:09 +00:00
|
|
|
#include "LyXAction.h"
|
2002-06-19 05:20:29 +00:00
|
|
|
#include "lyxfunc.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "lyxrc.h"
|
2002-06-19 05:20:29 +00:00
|
|
|
#include "lyxserver.h"
|
2003-10-14 11:35:50 +00:00
|
|
|
#include "lyxsocket.h"
|
2002-06-19 05:20:29 +00:00
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
#include "graphics/LoaderQueue.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/os.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
#include "support/package.h"
|
2004-08-08 22:37:39 +00:00
|
|
|
#include "debug.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
|
|
|
// Dear Lord, deliver us from Evil, aka the Qt headers
|
|
|
|
// Qt defines a macro 'signals' that clashes with a boost namespace.
|
|
|
|
// All is well if the namespace is visible first.
|
2004-09-26 14:19:47 +00:00
|
|
|
#include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
|
2002-11-04 00:15:56 +00:00
|
|
|
#include <boost/bind.hpp>
|
2004-07-21 19:03:21 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-12 01:48:53 +00:00
|
|
|
#include "QtView.h"
|
2003-05-24 15:19:05 +00:00
|
|
|
#include "lcolorcache.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
#include "qfont_loader.h"
|
|
|
|
#include "QLImage.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "socket_callback.h"
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2004-01-07 16:40:30 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
#include <qapplication.h>
|
2002-10-20 01:48:28 +00:00
|
|
|
#include <qpaintdevicemetrics.h>
|
2004-08-08 22:37:39 +00:00
|
|
|
#include <qtranslator.h>
|
|
|
|
#include <qtextcodec.h>
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::ltrim;
|
2005-01-10 19:17:43 +00:00
|
|
|
using lyx::support::package;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
using lyx::frontend::QtView;
|
|
|
|
|
2003-10-14 11:35:50 +00:00
|
|
|
namespace os = lyx::support::os;
|
|
|
|
|
2004-07-21 19:03:21 +00:00
|
|
|
using boost::shared_ptr;
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
using std::exit;
|
|
|
|
#endif
|
|
|
|
|
2002-07-31 04:33:03 +00:00
|
|
|
using std::map;
|
2003-09-08 00:33:41 +00:00
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
extern BufferList bufferlist;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-08-25 05:41:42 +00:00
|
|
|
namespace {
|
2002-10-14 20:20:34 +00:00
|
|
|
|
2005-01-05 10:54:31 +00:00
|
|
|
int getDPI()
|
2002-10-20 01:48:28 +00:00
|
|
|
{
|
2002-10-14 20:20:34 +00:00
|
|
|
QWidget w;
|
|
|
|
QPaintDeviceMetrics pdm(&w);
|
2005-01-05 10:54:31 +00:00
|
|
|
return int(0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY()));
|
2002-10-14 20:20:34 +00:00
|
|
|
}
|
|
|
|
|
2004-07-21 19:03:21 +00:00
|
|
|
map<int, shared_ptr<socket_callback> > socket_callbacks;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
// FIXME: wrong place !
|
|
|
|
LyXServer * lyxserver;
|
2003-10-14 11:35:50 +00:00
|
|
|
LyXServerSocket * lyxsocket;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2003-01-05 22:38:42 +00:00
|
|
|
// in QLyXKeySym.C
|
|
|
|
extern void initEncodings();
|
|
|
|
|
2002-11-07 22:46:30 +00:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
extern bool lyxX11EventFilter(XEvent * xev);
|
|
|
|
#endif
|
|
|
|
|
2004-01-07 16:40:30 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
extern bool macEventFilter(EventRef event);
|
|
|
|
extern pascal OSErr
|
2004-04-03 08:37:12 +00:00
|
|
|
handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
|
2004-01-07 16:40:30 +00:00
|
|
|
long /*refCon*/);
|
|
|
|
#endif
|
2003-01-05 22:38:42 +00:00
|
|
|
|
2002-11-07 22:46:30 +00:00
|
|
|
class LQApplication : public QApplication
|
|
|
|
{
|
|
|
|
public:
|
2003-01-23 16:23:43 +00:00
|
|
|
LQApplication(int & argc, char ** argv);
|
2002-11-07 22:46:30 +00:00
|
|
|
~LQApplication();
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
|
|
|
|
#endif
|
2004-01-07 16:40:30 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
bool macEventFilter(EventRef event);
|
|
|
|
#endif
|
2002-11-07 22:46:30 +00:00
|
|
|
};
|
|
|
|
|
2002-12-20 01:32:51 +00:00
|
|
|
|
2003-01-23 16:23:43 +00:00
|
|
|
LQApplication::LQApplication(int & argc, char ** argv)
|
|
|
|
: QApplication(argc, argv)
|
2004-01-07 16:40:30 +00:00
|
|
|
{
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
|
|
|
|
NewAEEventHandlerUPP(handleOpenDocuments),
|
|
|
|
0, false);
|
|
|
|
#endif
|
|
|
|
}
|
2002-11-07 22:46:30 +00:00
|
|
|
|
2002-12-20 01:32:51 +00:00
|
|
|
|
2002-11-07 22:46:30 +00:00
|
|
|
LQApplication::~LQApplication()
|
|
|
|
{}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2004-01-07 16:40:30 +00:00
|
|
|
|
|
|
|
#ifdef Q_WS_MACX
|
2004-04-03 08:37:12 +00:00
|
|
|
bool LQApplication::macEventFilter(EventRef event)
|
2004-01-07 16:40:30 +00:00
|
|
|
{
|
|
|
|
if (GetEventClass(event) == kEventClassAppleEvent) {
|
|
|
|
EventRecord eventrec;
|
|
|
|
ConvertEventRefToEventRecord(event, &eventrec);
|
|
|
|
AEProcessAppleEvent(&eventrec);
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2004-01-07 16:40:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
namespace lyx_gui {
|
|
|
|
|
|
|
|
bool use_gui = true;
|
|
|
|
|
|
|
|
void parse_init(int & argc, char * argv[])
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
2004-10-13 16:14:57 +00:00
|
|
|
// Force adding of font path _before_ QApplication is initialized
|
|
|
|
qfont_loader::initFontPath();
|
2004-10-26 21:16:44 +00:00
|
|
|
|
2004-08-08 22:37:39 +00:00
|
|
|
static LQApplication app(argc, argv);
|
|
|
|
|
|
|
|
#if QT_VERSION >= 0x030200
|
2004-10-05 10:11:42 +00:00
|
|
|
// install translation file for Qt built-in dialogs
|
2004-08-08 22:37:39 +00:00
|
|
|
// These are only installed since Qt 3.2.x
|
2004-10-05 10:11:42 +00:00
|
|
|
static QTranslator qt_trans(0);
|
|
|
|
if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
|
2004-08-08 22:37:39 +00:00
|
|
|
qInstallPathTranslations())) {
|
|
|
|
app.installTranslator(&qt_trans);
|
|
|
|
// even if the language calls for RtL, don't do that
|
|
|
|
app.setReverseLayout(false);
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "Successfully installed Qt translations for locale "
|
|
|
|
<< QTextCodec::locale() << std::endl;
|
|
|
|
} else
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "Could not find Qt translations for locale "
|
|
|
|
<< QTextCodec::locale() << std::endl;
|
|
|
|
#endif
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2004-08-14 18:06:10 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// These translations are meant to break Qt/Mac menu merging
|
|
|
|
// algorithm on some entries. It lists the menu names that
|
|
|
|
// should not be moved to the LyX menu
|
|
|
|
static QTranslator aqua_trans(0);
|
2004-09-26 14:19:47 +00:00
|
|
|
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
|
2004-08-14 18:06:10 +00:00
|
|
|
"do_not_merge_me"));
|
2004-09-26 14:19:47 +00:00
|
|
|
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
|
2004-08-14 18:06:10 +00:00
|
|
|
"do_not_merge_me"));
|
2004-09-26 14:19:47 +00:00
|
|
|
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
|
2004-08-14 18:06:10 +00:00
|
|
|
"do_not_merge_me"));
|
2004-09-26 14:19:47 +00:00
|
|
|
aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
|
2004-08-14 18:06:10 +00:00
|
|
|
"do_not_merge_me"));
|
|
|
|
|
|
|
|
app.installTranslator(&aqua_trans);
|
|
|
|
#endif
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
using namespace lyx::graphics;
|
2002-07-12 16:26:25 +00:00
|
|
|
|
|
|
|
Image::newImage = boost::bind(&QLImage::newImage);
|
|
|
|
Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
|
2002-08-25 05:41:42 +00:00
|
|
|
|
|
|
|
// needs to be done before reading lyxrc
|
|
|
|
lyxrc.dpi = getDPI();
|
2003-01-05 22:38:42 +00:00
|
|
|
|
|
|
|
initEncodings();
|
2003-02-25 11:20:59 +00:00
|
|
|
|
|
|
|
LoaderQueue::setPriority(10,100);
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void parse_lyxrc()
|
2003-02-28 09:49:49 +00:00
|
|
|
{}
|
2002-06-19 05:20:29 +00:00
|
|
|
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void start(string const & batch, vector<string> const & files)
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
|
|
|
// initial geometry
|
|
|
|
unsigned int width = 690;
|
|
|
|
unsigned int height = 510;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2003-10-14 21:30:23 +00:00
|
|
|
boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
|
|
|
|
LyX::ref().addLyXView(view_ptr);
|
|
|
|
|
|
|
|
QtView & view = *view_ptr.get();
|
2003-01-05 22:38:42 +00:00
|
|
|
view.show();
|
2002-06-19 05:20:29 +00:00
|
|
|
view.init();
|
|
|
|
|
|
|
|
// FIXME: some code below needs moving
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
|
2003-10-14 11:35:50 +00:00
|
|
|
lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
|
2005-01-10 19:17:43 +00:00
|
|
|
os::internal_path(package().temp_dir() + "/lyxsocket"));
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2004-11-06 15:23:12 +00:00
|
|
|
for_each(files.begin(), files.end(),
|
|
|
|
bind(&BufferView::loadLyXFile, view.view(), _1, true));
|
2002-06-19 05:20:29 +00:00
|
|
|
|
|
|
|
// handle the batch commands the user asked for
|
|
|
|
if (!batch.empty()) {
|
2003-10-13 00:38:09 +00:00
|
|
|
view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
2002-07-22 18:56:04 +00:00
|
|
|
qApp->exec();
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-22 18:56:04 +00:00
|
|
|
// FIXME
|
2003-10-14 11:35:50 +00:00
|
|
|
delete lyxsocket;
|
2002-06-19 05:20:29 +00:00
|
|
|
delete lyxserver;
|
2003-02-07 16:46:40 +00:00
|
|
|
lyxserver = 0;
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
|
|
|
2003-06-03 19:32:08 +00:00
|
|
|
void sync_events()
|
|
|
|
{
|
|
|
|
qApp->processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void exit()
|
2002-07-22 18:56:04 +00:00
|
|
|
{
|
2003-11-05 10:49:07 +00:00
|
|
|
delete lyxsocket;
|
2003-02-07 16:46:40 +00:00
|
|
|
delete lyxserver;
|
|
|
|
lyxserver = 0;
|
|
|
|
|
2002-12-20 01:32:51 +00:00
|
|
|
// we cannot call qApp->exit(0) - that could return us
|
|
|
|
// into a static dialog return in the lyx code (for example,
|
|
|
|
// load autosave file QMessageBox. We have to just get the hell
|
|
|
|
// out.
|
2003-02-25 13:35:26 +00:00
|
|
|
|
2002-12-20 01:32:51 +00:00
|
|
|
::exit(0);
|
2002-07-22 18:56:04 +00:00
|
|
|
}
|
|
|
|
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
FuncStatus getStatus(FuncRequest const & ev)
|
2002-12-18 14:24:32 +00:00
|
|
|
{
|
|
|
|
FuncStatus flag;
|
|
|
|
switch (ev.action) {
|
2003-06-19 16:49:45 +00:00
|
|
|
case LFUN_DIALOG_SHOW:
|
2004-03-17 21:21:47 +00:00
|
|
|
if (ev.argument == "preamble")
|
2003-06-19 16:49:45 +00:00
|
|
|
flag.unknown(true);
|
|
|
|
break;
|
2002-12-18 14:24:32 +00:00
|
|
|
case LFUN_TOOLTIPS_TOGGLE:
|
|
|
|
flag.unknown(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-06-23 14:04:09 +00:00
|
|
|
|
2002-12-18 14:24:32 +00:00
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
string const hexname(LColor_color col)
|
2002-07-11 01:01:38 +00:00
|
|
|
{
|
2003-05-24 15:19:05 +00:00
|
|
|
return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
|
2002-07-11 01:01:38 +00:00
|
|
|
}
|
2002-07-12 02:27:42 +00:00
|
|
|
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
void update_color(LColor_color)
|
2002-07-12 02:27:42 +00:00
|
|
|
{
|
2003-05-24 15:19:05 +00:00
|
|
|
// FIXME: Bleh, can't we just clear them all at once ?
|
|
|
|
lcolorcache.clear();
|
2002-07-12 02:27:42 +00:00
|
|
|
}
|
2002-07-12 03:05:13 +00:00
|
|
|
|
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void update_fonts()
|
2002-07-12 03:05:13 +00:00
|
|
|
{
|
|
|
|
fontloader.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
bool font_available(LyXFont const & font)
|
2002-07-12 03:05:13 +00:00
|
|
|
{
|
|
|
|
return fontloader.available(font);
|
|
|
|
}
|
2002-07-14 01:44:15 +00:00
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2004-07-21 19:03:21 +00:00
|
|
|
void register_socket_callback(int fd, boost::function<void()> func)
|
2003-11-05 10:49:07 +00:00
|
|
|
{
|
2004-07-21 19:03:21 +00:00
|
|
|
socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
|
2003-11-05 10:49:07 +00:00
|
|
|
}
|
2003-10-13 12:25:11 +00:00
|
|
|
|
|
|
|
|
2004-07-21 19:03:21 +00:00
|
|
|
void unregister_socket_callback(int fd)
|
2003-11-05 10:49:07 +00:00
|
|
|
{
|
2004-07-21 19:03:21 +00:00
|
|
|
socket_callbacks.erase(fd);
|
2003-11-05 10:49:07 +00:00
|
|
|
}
|
2003-10-13 12:25:11 +00:00
|
|
|
|
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
string const roman_font_name()
|
|
|
|
{
|
|
|
|
if (!use_gui)
|
|
|
|
return "serif";
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
font.setStyleHint(QFont::Serif);
|
2003-04-22 23:25:27 +00:00
|
|
|
font.setFamily("serif");
|
2004-06-18 13:31:55 +00:00
|
|
|
|
2004-08-12 07:24:03 +00:00
|
|
|
return fromqstr(QFontInfo(font).family());
|
2003-03-31 02:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const sans_font_name()
|
|
|
|
{
|
|
|
|
if (!use_gui)
|
|
|
|
return "sans";
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
font.setStyleHint(QFont::SansSerif);
|
2003-04-22 23:25:27 +00:00
|
|
|
font.setFamily("sans");
|
2004-06-18 13:31:55 +00:00
|
|
|
|
2004-08-12 07:24:03 +00:00
|
|
|
return fromqstr(QFontInfo(font).family());
|
2003-03-31 02:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const typewriter_font_name()
|
|
|
|
{
|
|
|
|
if (!use_gui)
|
|
|
|
return "monospace";
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
2003-04-22 23:25:27 +00:00
|
|
|
font.setFamily("monospace");
|
2004-06-18 13:31:55 +00:00
|
|
|
|
2004-08-12 07:24:03 +00:00
|
|
|
return fromqstr(QFontInfo(font).family());
|
2003-03-31 02:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace lyx_gui
|