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"
30 // FIXME: move this stuff out again
31 #include "bufferlist.h"
33 #include "lyxserver.h"
34 #include "BufferView.h"
36 // Dear Lord, deliver us from Evil,
38 #include <boost/shared_ptr.hpp>
39 #include <boost/function/function0.hpp>
40 #include <boost/signals/signal1.hpp>
41 #include <boost/bind.hpp>
45 #include "qfont_loader.h"
46 #include "io_callback.h"
48 #include <qapplication.h>
50 #include <qpaintdevicemetrics.h>
54 #ifndef CXX_GLOBAL_CSTD
62 extern BufferList bufferlist;
69 QPaintDeviceMetrics pdm(&w);
70 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
73 map<int, io_callback *> io_callbacks;
78 // FIXME: wrong place !
79 LyXServer * lyxserver;
82 extern bool lyxX11EventFilter(XEvent * xev);
85 class LQApplication : public QApplication
88 LQApplication(int &argc, char **argv);
91 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
95 LQApplication::LQApplication(int &argc, char **argv)
96 : QApplication( argc, argv )
99 LQApplication::~LQApplication()
102 void lyx_gui::parse_init(int & argc, char * argv[])
104 static LQApplication a(argc, argv);
106 using namespace grfx;
108 Image::newImage = boost::bind(&QLImage::newImage);
109 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
111 // needs to be done before reading lyxrc
112 lyxrc.dpi = getDPI();
116 void lyx_gui::parse_lyxrc()
121 void lyx_gui::start(string const & batch, vector<string> const & files)
126 unsigned int width = 690;
127 unsigned int height = 510;
129 QtView view(width, height);
130 view.show(xpos, ypos, "LyX");
135 // FIXME: some code below needs moving
137 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
139 vector<string>::const_iterator cit = files.begin();
140 vector<string>::const_iterator end = files.end();
141 for (; cit != end; ++cit) {
142 Buffer * b = bufferlist.loadLyXFile(*cit);
148 // switch to the last buffer successfully loaded
150 view.view()->buffer(last);
153 // handle the batch commands the user asked for
154 if (!batch.empty()) {
155 view.getLyXFunc().dispatch(batch);
171 string const lyx_gui::hexname(LColor::color col)
173 QColor color(lcolor.getX11Name(col).c_str());
174 return ltrim(color.name().latin1(), "#");
178 void lyx_gui::update_color(LColor::color)
184 void lyx_gui::update_fonts()
190 bool lyx_gui::font_available(LyXFont const & font)
192 return fontloader.available(font);
196 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
198 io_callbacks[fd] = new io_callback(fd, comm);
202 void lyx_gui::remove_read_callback(int fd)
204 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
205 if (it != io_callbacks.end()) {
207 io_callbacks.erase(it);