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>
55 #ifndef CXX_GLOBAL_CSTD
63 extern BufferList bufferlist;
70 QPaintDeviceMetrics pdm(&w);
71 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
74 map<int, io_callback *> io_callbacks;
79 // FIXME: wrong place !
80 LyXServer * lyxserver;
83 extern bool lyxX11EventFilter(XEvent * xev);
86 class LQApplication : public QApplication
89 LQApplication(int &argc, char **argv);
92 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
96 LQApplication::LQApplication(int &argc, char **argv)
97 : QApplication( argc, argv )
100 LQApplication::~LQApplication()
103 void lyx_gui::parse_init(int & argc, char * argv[])
105 static LQApplication a(argc, argv);
107 using namespace grfx;
109 Image::newImage = boost::bind(&QLImage::newImage);
110 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
112 // needs to be done before reading lyxrc
113 lyxrc.dpi = getDPI();
117 void lyx_gui::parse_lyxrc()
122 void lyx_gui::start(string const & batch, vector<string> const & files)
127 unsigned int width = 690;
128 unsigned int height = 510;
130 QtView view(width, height);
131 view.show(xpos, ypos, "LyX");
136 // FIXME: some code below needs moving
138 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
140 vector<string>::const_iterator cit = files.begin();
141 vector<string>::const_iterator end = files.end();
142 for (; cit != end; ++cit) {
143 Buffer * b = bufferlist.loadLyXFile(*cit);
149 // switch to the last buffer successfully loaded
151 view.view()->buffer(last);
154 // handle the batch commands the user asked for
155 if (!batch.empty()) {
156 view.getLyXFunc().dispatch(batch);
172 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
176 case LFUN_LAYOUT_PREAMBLE:
177 case LFUN_TOOLTIPS_TOGGLE:
178 case LFUN_FORKS_SHOW:
188 string const lyx_gui::hexname(LColor::color col)
190 QColor color(toqstr(lcolor.getX11Name(col)));
191 return ltrim(fromqstr(color.name()), "#");
195 void lyx_gui::update_color(LColor::color)
201 void lyx_gui::update_fonts()
207 bool lyx_gui::font_available(LyXFont const & font)
209 return fontloader.available(font);
213 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
215 io_callbacks[fd] = new io_callback(fd, comm);
219 void lyx_gui::remove_read_callback(int fd)
221 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
222 if (it != io_callbacks.end()) {
224 io_callbacks.erase(it);