]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lyx_gui.C
Lots and lots of little trivial bits.
[lyx.git] / src / frontends / qt2 / lyx_gui.C
1 /**
2  * \file lyx_gui.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "support/lyxlib.h"
19 #include "support/os.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "debug.h"
23 #include "gettext.h"
24
25 #include <fcntl.h>
26 #include <boost/bind.hpp>
27
28 #include "lyx_gui.h"
29 #include "lyx_main.h"
30 #include "lyxrc.h"
31 #include "lyxfont.h"
32
33 // FIXME: move this stuff out again
34 #include "bufferlist.h"
35 #include "lyxfunc.h"
36 #include "lyxserver.h"
37 #include "BufferView.h"
38
39 // Dear Lord, deliver us from Evil,
40 // aka the Qt headers
41 #include <boost/shared_ptr.hpp>
42 #include <boost/function/function0.hpp>
43 #include <boost/signals/signal1.hpp>
44
45 #include "QtView.h"
46 #include "QLImage.h"
47 #include "qfont_loader.h"
48 #include "io_callback.h"
49
50 #include <qapplication.h>
51
52 #ifndef CXX_GLOBAL_CSTD
53 using std::exit;
54 #endif
55
56 using std::vector;
57 using std::map;
58 using std::endl;
59
60 extern BufferList bufferlist;
61
62 namespace {
63         /// good ol' "easy to use" Qt again
64         float getDPI() { return 95; }
65 }
66
67 // FIXME: wrong place !
68 LyXServer * lyxserver;
69
70 void lyx_gui::parse_init(int & argc, char * argv[])
71 {
72         static QApplication a(argc, argv);
73
74         using namespace grfx;
75
76         Image::newImage = boost::bind(&QLImage::newImage);
77         Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
78
79         // needs to be done before reading lyxrc
80         lyxrc.dpi = getDPI();
81 }
82
83
84 void lyx_gui::parse_lyxrc()
85 {
86 }
87
88
89 void lyx_gui::start(string const & batch, vector<string> files)
90 {
91         // initial geometry
92         int xpos = -1;
93         int ypos = -1;
94         unsigned int width = 690;
95         unsigned int height = 510;
96
97         QtView view(width, height);
98         view.show(xpos, ypos, "LyX");
99         view.init();
100
101         Buffer * last = 0;
102
103         // FIXME: some code below needs moving
104
105         lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
106
107         vector<string>::const_iterator cit = files.begin();
108         vector<string>::const_iterator end = files.end();
109         for (; cit != end; ++cit) {
110                 Buffer * b = bufferlist.loadLyXFile(*cit);
111                 if (b) {
112                         last = b;
113                 }
114         }
115
116         // switch to the last buffer successfully loaded
117         if (last) {
118                 view.view()->buffer(last);
119         }
120
121         // handle the batch commands the user asked for
122         if (!batch.empty()) {
123                 view.getLyXFunc().dispatch(batch);
124         }
125
126         qApp->exec();
127
128         // FIXME
129         delete lyxserver;
130 }
131
132
133 void lyx_gui::exit()
134 {
135         qApp->exit(0);
136 }
137
138
139 string const lyx_gui::hexname(LColor::color col)
140 {
141         QColor color(lcolor.getX11Name(col).c_str());
142         return ltrim(color.name().latin1(), "#");
143 }
144
145
146 void lyx_gui::update_color(LColor::color)
147 {
148         // no need
149 }
150
151
152 void lyx_gui::update_fonts()
153 {
154         fontloader.update();
155 }
156
157
158 bool lyx_gui::font_available(LyXFont const & font)
159 {
160         return fontloader.available(font);
161 }
162
163
164 namespace {
165         map<int, io_callback *> io_callbacks;
166 }
167
168
169 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
170 {
171         io_callbacks[fd] = new io_callback(fd, comm);
172 }
173
174
175 void lyx_gui::remove_read_callback(int fd)
176 {
177         map<int, io_callback *>::iterator it = io_callbacks.find(fd);
178         if (it != io_callbacks.end()) {
179                 delete it->second;
180                 io_callbacks.erase(it);
181         }
182 }