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
|
|
|
|
*
|
|
|
|
* 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-09-24 13:57:09 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/os.h"
|
|
|
|
#include "support/filetools.h"
|
2002-08-15 19:52:59 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-06-19 05:20:29 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "gettext.h"
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-12 01:48:53 +00:00
|
|
|
#include "lyx_gui.h"
|
2002-06-19 05:20:29 +00:00
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "lyxrc.h"
|
2002-07-12 03:05:13 +00:00
|
|
|
#include "lyxfont.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"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include "lyxserver.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
2002-07-12 01:48:53 +00:00
|
|
|
// Dear Lord, deliver us from Evil,
|
|
|
|
// aka the Qt headers
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/function/function0.hpp>
|
|
|
|
#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"
|
|
|
|
#include "QLImage.h"
|
2002-07-12 03:05:13 +00:00
|
|
|
#include "qfont_loader.h"
|
2002-07-28 18:13:51 +00:00
|
|
|
#include "io_callback.h"
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
#include <qapplication.h>
|
2002-10-20 01:48:28 +00:00
|
|
|
#include <qwidget.h>
|
|
|
|
#include <qpaintdevicemetrics.h>
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-11-04 00:15:56 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
using std::exit;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using std::vector;
|
2002-07-31 04:33:03 +00:00
|
|
|
using std::map;
|
2002-06-19 05:20:29 +00:00
|
|
|
using std::endl;
|
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;
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
// FIXME: wrong place !
|
|
|
|
LyXServer * lyxserver;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-11-07 22:46:30 +00:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
extern bool lyxX11EventFilter(XEvent * xev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class LQApplication : public QApplication
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LQApplication(int &argc, char **argv);
|
|
|
|
~LQApplication();
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
LQApplication::LQApplication(int &argc, char **argv)
|
|
|
|
: QApplication( argc, argv )
|
|
|
|
{}
|
|
|
|
|
|
|
|
LQApplication::~LQApplication()
|
|
|
|
{}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
void lyx_gui::parse_init(int & argc, char * argv[])
|
|
|
|
{
|
2002-11-07 22:46:30 +00:00
|
|
|
static LQApplication a(argc, argv);
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-12 16:26:25 +00:00
|
|
|
using namespace grfx;
|
|
|
|
|
|
|
|
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();
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
|
|
|
|
void lyx_gui::parse_lyxrc()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-11-04 00:15:56 +00:00
|
|
|
void lyx_gui::start(string const & batch, vector<string> const & files)
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
|
|
|
// initial geometry
|
|
|
|
int xpos = -1;
|
|
|
|
int ypos = -1;
|
|
|
|
unsigned int width = 690;
|
|
|
|
unsigned int height = 510;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
QtView view(width, height);
|
|
|
|
view.show(xpos, ypos, "LyX");
|
|
|
|
view.init();
|
|
|
|
|
|
|
|
Buffer * last = 0;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
// FIXME: some code below needs moving
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
|
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();
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
Buffer * b = bufferlist.loadLyXFile(*cit);
|
|
|
|
if (b) {
|
|
|
|
last = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// switch to the last buffer successfully loaded
|
|
|
|
if (last) {
|
|
|
|
view.view()->buffer(last);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle the batch commands the user asked for
|
|
|
|
if (!batch.empty()) {
|
2002-08-13 14:40:38 +00:00
|
|
|
view.getLyXFunc().dispatch(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
|
2002-06-19 05:20:29 +00:00
|
|
|
delete lyxserver;
|
|
|
|
}
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
|
|
|
2002-07-22 18:56:04 +00:00
|
|
|
void lyx_gui::exit()
|
|
|
|
{
|
|
|
|
qApp->exit(0);
|
|
|
|
}
|
|
|
|
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2002-07-11 01:01:38 +00:00
|
|
|
string const lyx_gui::hexname(LColor::color col)
|
|
|
|
{
|
2002-07-13 01:42:15 +00:00
|
|
|
QColor color(lcolor.getX11Name(col).c_str());
|
2002-08-15 19:52:59 +00:00
|
|
|
return ltrim(color.name().latin1(), "#");
|
2002-07-11 01:01:38 +00:00
|
|
|
}
|
2002-07-12 02:27:42 +00:00
|
|
|
|
|
|
|
|
2002-07-12 03:05:13 +00:00
|
|
|
void lyx_gui::update_color(LColor::color)
|
2002-07-12 02:27:42 +00:00
|
|
|
{
|
|
|
|
// no need
|
|
|
|
}
|
2002-07-12 03:05:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
void lyx_gui::update_fonts()
|
|
|
|
{
|
|
|
|
fontloader.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool lyx_gui::font_available(LyXFont const & font)
|
|
|
|
{
|
|
|
|
return fontloader.available(font);
|
|
|
|
}
|
2002-07-14 01:44:15 +00:00
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-07-14 01:44:15 +00:00
|
|
|
void lyx_gui::set_read_callback(int fd, LyXComm * comm)
|
|
|
|
{
|
2002-07-31 04:33:03 +00:00
|
|
|
io_callbacks[fd] = new io_callback(fd, comm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lyx_gui::remove_read_callback(int fd)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|