3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
15 #include "support/lyxlib.h"
16 #include "support/os.h"
17 #include "support/filetools.h"
18 #include "support/lstrings.h"
20 #include "qt_helpers.h"
26 #include "funcrequest.h"
28 // FIXME: move this stuff out again
29 #include "bufferlist.h"
31 #include "lyxserver.h"
32 #include "BufferView.h"
34 // Dear Lord, deliver us from Evil,
36 #include <boost/shared_ptr.hpp>
37 #include <boost/function/function0.hpp>
38 #include <boost/signals/signal1.hpp>
39 #include <boost/bind.hpp>
43 #include "qfont_loader.h"
44 #include "io_callback.h"
46 #include <qapplication.h>
48 #include <qpaintdevicemetrics.h>
53 #ifndef CXX_GLOBAL_CSTD
61 extern BufferList bufferlist;
68 QPaintDeviceMetrics pdm(&w);
69 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
72 map<int, io_callback *> io_callbacks;
77 // FIXME: wrong place !
78 LyXServer * lyxserver;
81 extern void initEncodings();
84 extern bool lyxX11EventFilter(XEvent * xev);
88 class LQApplication : public QApplication
91 LQApplication(int & argc, char ** argv);
94 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
99 LQApplication::LQApplication(int & argc, char ** argv)
100 : QApplication(argc, argv)
104 LQApplication::~LQApplication()
108 void lyx_gui::parse_init(int & argc, char * argv[])
110 static LQApplication a(argc, argv);
112 using namespace grfx;
114 Image::newImage = boost::bind(&QLImage::newImage);
115 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
117 // needs to be done before reading lyxrc
118 lyxrc.dpi = getDPI();
124 void lyx_gui::parse_lyxrc()
129 void lyx_gui::start(string const & batch, vector<string> const & files)
134 unsigned int width = 690;
135 unsigned int height = 510;
137 QtView view(width, height);
143 // FIXME: some code below needs moving
145 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
147 vector<string>::const_iterator cit = files.begin();
148 vector<string>::const_iterator end = files.end();
149 for (; cit != end; ++cit) {
150 Buffer * b = bufferlist.loadLyXFile(*cit);
156 // switch to the last buffer successfully loaded
158 view.view()->buffer(last);
161 // handle the batch commands the user asked for
162 if (!batch.empty()) {
163 view.getLyXFunc().dispatch(batch);
179 // we cannot call qApp->exit(0) - that could return us
180 // into a static dialog return in the lyx code (for example,
181 // load autosave file QMessageBox. We have to just get the hell
188 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
192 case LFUN_LAYOUT_PREAMBLE:
193 case LFUN_TOOLTIPS_TOGGLE:
194 case LFUN_FORKS_SHOW:
204 string const lyx_gui::hexname(LColor::color col)
206 QColor color(toqstr(lcolor.getX11Name(col)));
207 return ltrim(fromqstr(color.name()), "#");
211 void lyx_gui::update_color(LColor::color)
217 void lyx_gui::update_fonts()
223 bool lyx_gui::font_available(LyXFont const & font)
225 return fontloader.available(font);
229 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
231 io_callbacks[fd] = new io_callback(fd, comm);
235 void lyx_gui::remove_read_callback(int fd)
237 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
238 if (it != io_callbacks.end()) {
240 io_callbacks.erase(it);