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 void lyx_gui::parse_init(int & argc, char * argv[])
84 static QApplication a(argc, argv);
88 Image::newImage = boost::bind(&QLImage::newImage);
89 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
91 // needs to be done before reading lyxrc
96 void lyx_gui::parse_lyxrc()
101 void lyx_gui::start(string const & batch, vector<string> const & files)
106 unsigned int width = 690;
107 unsigned int height = 510;
109 QtView view(width, height);
110 view.show(xpos, ypos, "LyX");
115 // FIXME: some code below needs moving
117 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
119 vector<string>::const_iterator cit = files.begin();
120 vector<string>::const_iterator end = files.end();
121 for (; cit != end; ++cit) {
122 Buffer * b = bufferlist.loadLyXFile(*cit);
128 // switch to the last buffer successfully loaded
130 view.view()->buffer(last);
133 // handle the batch commands the user asked for
134 if (!batch.empty()) {
135 view.getLyXFunc().dispatch(batch);
151 string const lyx_gui::hexname(LColor::color col)
153 QColor color(lcolor.getX11Name(col).c_str());
154 return ltrim(color.name().latin1(), "#");
158 void lyx_gui::update_color(LColor::color)
164 void lyx_gui::update_fonts()
170 bool lyx_gui::font_available(LyXFont const & font)
172 return fontloader.available(font);
176 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
178 io_callbacks[fd] = new io_callback(fd, comm);
182 void lyx_gui::remove_read_callback(int fd)
184 map<int, io_callback *>::iterator it = io_callbacks.find(fd);
185 if (it != io_callbacks.end()) {
187 io_callbacks.erase(it);