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