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 #pragma implementation
18 #include "support/lyxlib.h"
19 #include "support/os.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
23 #include "qt_helpers.h"
29 #include "funcrequest.h"
31 // FIXME: move this stuff out again
32 #include "bufferlist.h"
34 #include "lyxserver.h"
35 #include "BufferView.h"
37 // Dear Lord, deliver us from Evil,
39 #include <boost/shared_ptr.hpp>
40 #include <boost/function/function0.hpp>
41 #include <boost/signals/signal1.hpp>
42 #include <boost/bind.hpp>
46 #include "qfont_loader.h"
47 #include "io_callback.h"
49 #include <qapplication.h>
51 #include <qpaintdevicemetrics.h>
56 #ifndef CXX_GLOBAL_CSTD
64 extern BufferList bufferlist;
71 QPaintDeviceMetrics pdm(&w);
72 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
75 map<int, io_callback *> io_callbacks;
80 // FIXME: wrong place !
81 LyXServer * lyxserver;
84 extern void initEncodings();
87 extern bool lyxX11EventFilter(XEvent * xev);
91 class LQApplication : public QApplication
94 LQApplication(int &argc, char **argv);
97 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
102 LQApplication::LQApplication(int &argc, char **argv)
103 : QApplication( argc, argv )
107 LQApplication::~LQApplication()
111 void lyx_gui::parse_init(int & argc, char * argv[])
113 static LQApplication a(argc, argv);
115 using namespace grfx;
117 Image::newImage = boost::bind(&QLImage::newImage);
118 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
120 // needs to be done before reading lyxrc
121 lyxrc.dpi = getDPI();
127 void lyx_gui::parse_lyxrc()
132 void lyx_gui::start(string const & batch, vector<string> const & files)
137 unsigned int width = 690;
138 unsigned int height = 510;
140 QtView view(width, height);
146 // FIXME: some code below needs moving
148 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
150 vector<string>::const_iterator cit = files.begin();
151 vector<string>::const_iterator end = files.end();
152 for (; cit != end; ++cit) {
153 Buffer * b = bufferlist.loadLyXFile(*cit);
159 // switch to the last buffer successfully loaded
161 view.view()->buffer(last);
164 // handle the batch commands the user asked for
165 if (!batch.empty()) {
166 view.getLyXFunc().dispatch(batch);
178 // we cannot call qApp->exit(0) - that could return us
179 // into a static dialog return in the lyx code (for example,
180 // load autosave file QMessageBox. We have to just get the hell
187 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
191 case LFUN_LAYOUT_PREAMBLE:
192 case LFUN_TOOLTIPS_TOGGLE:
193 case LFUN_FORKS_SHOW:
203 string const lyx_gui::hexname(LColor::color col)
205 QColor color(toqstr(lcolor.getX11Name(col)));
206 return ltrim(fromqstr(color.name()), "#");
210 void lyx_gui::update_color(LColor::color)
216 void lyx_gui::update_fonts()
222 bool lyx_gui::font_available(LyXFont const & font)
224 return fontloader.available(font);
228 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
230 io_callbacks[fd] = new io_callback(fd, comm);
234 void lyx_gui::remove_read_callback(int fd)
236 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
237 if (it != io_callbacks.end()) {
239 io_callbacks.erase(it);