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"
|
|
|
|
|
|
|
|
// 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.
|
2002-07-12 01:48:53 +00:00
|
|
|
#include <boost/signals/signal1.hpp>
|
2002-11-04 00:15:56 +00:00
|
|
|
#include <boost/bind.hpp>
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-12 01:48:53 +00:00
|
|
|
#include "QtView.h"
|
2002-07-28 18:13:51 +00:00
|
|
|
#include "io_callback.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>
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::ltrim;
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
float getDPI()
|
2002-10-20 01:48:28 +00:00
|
|
|
{
|
2002-10-14 20:20:34 +00:00
|
|
|
QWidget w;
|
|
|
|
QPaintDeviceMetrics pdm(&w);
|
2002-10-17 13:31:04 +00:00
|
|
|
return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
|
2002-10-14 20:20:34 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
map<int, io_callback *> io_callbacks;
|
2003-11-05 10:49:07 +00:00
|
|
|
map<int, 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;
|
|
|
|
|
2002-12-20 01:32:51 +00:00
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void parse_init(int & argc, char * argv[])
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
2002-11-07 22:46:30 +00:00
|
|
|
static LQApplication a(argc, argv);
|
2002-07-28 18:13:51 +00:00
|
|
|
|
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(),
|
|
|
|
os::slashify_path(os::getTmpDir() + "/lyxsocket"));
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
vector<string>::const_iterator cit = files.begin();
|
|
|
|
vector<string>::const_iterator end = files.end();
|
2003-06-27 07:11:31 +00:00
|
|
|
for (; cit != end; ++cit)
|
|
|
|
view.view()->loadLyXFile(*cit, 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;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void set_read_callback(int fd, LyXComm * comm)
|
2002-07-14 01:44:15 +00:00
|
|
|
{
|
2002-07-31 04:33:03 +00:00
|
|
|
io_callbacks[fd] = new io_callback(fd, comm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-31 02:59:34 +00:00
|
|
|
void remove_read_callback(int fd)
|
2002-07-31 04:33:03 +00:00
|
|
|
{
|
|
|
|
map<int, io_callback *>::iterator it = io_callbacks.find(fd);
|
|
|
|
if (it != io_callbacks.end()) {
|
|
|
|
delete it->second;
|
|
|
|
io_callbacks.erase(it);
|
|
|
|
}
|
2002-07-14 01:44:15 +00:00
|
|
|
}
|
2003-03-31 02:59:34 +00:00
|
|
|
|
|
|
|
|
2003-11-05 10:49:07 +00:00
|
|
|
void set_datasocket_callback(LyXDataSocket * p)
|
|
|
|
{
|
|
|
|
socket_callbacks[p->fd()] = new socket_callback(p);
|
|
|
|
}
|
2003-10-13 12:25:11 +00:00
|
|
|
|
2003-11-05 10:49:07 +00:00
|
|
|
void set_serversocket_callback(LyXServerSocket * p)
|
|
|
|
{
|
|
|
|
socket_callbacks[p->fd()] = new socket_callback(p);
|
|
|
|
}
|
2003-10-13 12:25:11 +00:00
|
|
|
|
2003-11-05 10:49:07 +00:00
|
|
|
void remove_socket_callback(int fd)
|
|
|
|
{
|
|
|
|
map<int, socket_callback *>::iterator it = socket_callbacks.find(fd);
|
|
|
|
if (it != socket_callbacks.end()) {
|
|
|
|
delete it->second;
|
|
|
|
socket_callbacks.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2003-10-13 12:25:11 +00:00
|
|
|
|
2003-11-05 10:49:07 +00:00
|
|
|
void remove_datasocket_callback(LyXDataSocket * p)
|
|
|
|
{
|
|
|
|
remove_socket_callback(p->fd());
|
|
|
|
}
|
2003-10-13 12:25:11 +00:00
|
|
|
|
2003-11-05 10:49:07 +00:00
|
|
|
void remove_serversocket_callback(LyXServerSocket * p)
|
|
|
|
{
|
|
|
|
remove_socket_callback(p->fd());
|
|
|
|
}
|
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");
|
|
|
|
return QFontInfo(font).family().latin1();
|
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");
|
|
|
|
return QFontInfo(font).family().latin1();
|
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");
|
|
|
|
return QFontInfo(font).family().latin1();
|
2003-03-31 02:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace lyx_gui
|