]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/lyx_gui.C
make it compile again
[lyx.git] / src / frontends / gtk / lyx_gui.C
1 /**
2  * \file gtk/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 Lars Gullik Bjnes
7  * \author John Levon
8  * \author Huang Ying
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 // Too hard to make concept checks work with this file
16 #ifdef _GLIBCXX_CONCEPT_CHECKS
17 #undef _GLIBCXX_CONCEPT_CHECKS
18 #endif
19 #ifdef _GLIBCPP_CONCEPT_CHECKS
20 #undef _GLIBCPP_CONCEPT_CHECKS
21 #endif
22
23 #include "lyx_gui.h"
24
25 #include "debug.h"
26 #include "funcrequest.h"
27 #include "gettext.h"
28
29 #include "Color.h"
30 #include "LColor.h"
31 #include "LyXAction.h"
32 #include "lyx_main.h"
33 #include "lyxrc.h"
34 #include "lyxfont.h"
35 #include "graphics/LoaderQueue.h"
36
37 #include "io_callback.h"
38
39 // FIXME: move this stuff out again
40 #include "lyxfunc.h"
41 #include "lyxserver.h"
42 #include "lyxsocket.h"
43 #include "BufferView.h"
44
45 #include "GuiApplication.h"
46 #include "GuiImplementation.h"
47 #include "GView.h"
48 #include "GtkmmX.h"
49
50 #include "GWorkArea.h"
51
52 #include "support/lyxlib.h"
53 #include "support/os.h"
54 #include "support/filetools.h"
55 #include "support/package.h"
56
57 #include <gtkmm.h>
58
59 #include <boost/bind.hpp>
60 #include <boost/function.hpp>
61 #include <boost/shared_ptr.hpp>
62
63 #include <fcntl.h>
64
65 #include <sstream>
66 #include <iomanip>
67
68 namespace os = lyx::support::os;
69
70 using std::ostringstream;
71 using std::string;
72
73 using lyx::support::package;
74
75 using lyx::frontend::colorCache;
76 using lyx::frontend::Gui;
77 using lyx::frontend::GuiApplication;
78 using lyx::frontend::GuiImplementation;
79 using lyx::frontend::GView;
80
81
82 bool lyx_gui::use_gui = true;
83
84 namespace {
85
86 /// estimate DPI from X server
87 int getDPI()
88 {
89         //TODO use GDK instead
90         Screen * scr = ScreenOfDisplay(getDisplay(), getScreen());
91         return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
92                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2);
93 }
94
95 } // namespace anon
96
97 lyx::frontend::Application * theApp;
98 GuiApplication * guiApp;
99
100 int lyx_gui::exec(int & argc, char * argv[])
101 {
102         guiApp = new GuiApplication(argc, argv);
103         theApp = guiApp;
104
105         return LyX::ref().exec2(argc, argv);
106 }
107
108
109 void lyx_gui::parse_lyxrc()
110 {
111 }
112
113
114 LyXView * lyx_gui::create_view(unsigned int width, unsigned int height,
115                 int posx, int posy, bool maximize)
116 {
117         return &guiApp->createView(width, height, posx, posy, maximize);
118 }
119
120
121 int lyx_gui::start(LyXView *, string const & batch)
122 {
123         return guiApp->start(batch);
124 }
125
126
127 void lyx_gui::exit(int status)
128 {
129         guiApp->exit(status);
130 }
131
132
133 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
134 {
135         FuncStatus flag;
136         switch (ev.action) {
137         case LFUN_TOOLTIPS_TOGGLE:
138                 flag.unknown(true);
139                 break;
140         default:
141                 break;
142         }
143
144         return flag;
145 }
146
147
148 bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
149 {
150         Gdk::Color gdkColor;
151         Gdk::Color * gclr = colorCache.getColor(col);
152         if (!gclr) {
153                 gclr = &gdkColor;
154                 if(!gclr->parse(lcolor.getX11Name(col))) {
155                         rgbcol.r = 0;
156                         rgbcol.g = 0;
157                         rgbcol.b = 0;
158                         return false;
159                 }
160         }
161
162         // Note that X stores the RGB values in the range 0 - 65535
163         // whilst we require them in the range 0 - 255.
164         rgbcol.r = gclr->get_red() / 256;
165         rgbcol.g = gclr->get_green() / 256;
166         rgbcol.b = gclr->get_blue() / 256;
167         return true;
168 }
169
170
171 string const lyx_gui::hexname(LColor_color col)
172 {
173         lyx::RGBColor rgbcol;
174         if (!getRGBColor(col, rgbcol)) {
175                 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
176                        << '"' << std::endl;
177                 return string();
178         }
179
180         std::ostringstream os;
181
182         os << std::setbase(16) << std::setfill('0')
183            << std::setw(2) << rgbcol.r
184            << std::setw(2) << rgbcol.g
185            << std::setw(2) << rgbcol.b;
186
187         return os.str();
188 }
189
190
191 void lyx_gui::update_color(LColor_color /*col*/)
192 {
193         colorCache.clear();
194 }
195
196
197 void lyx_gui::update_fonts()
198 {
199         fontLoader.update();
200 }
201
202
203 bool lyx_gui::font_available(LyXFont const & font)
204 {
205         return fontLoader.available(font);
206 }
207
208
209 namespace {
210
211 std::map<int, boost::shared_ptr<io_callback> > callbacks;
212
213 } // NS anon
214
215
216 void lyx_gui::register_socket_callback(int fd,
217                                        boost::function<void()> func)
218 {
219         callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
220 }
221
222
223 void lyx_gui::unregister_socket_callback(int fd)
224 {
225         callbacks.erase(fd);
226 }
227
228
229 string const lyx_gui::roman_font_name()
230 {
231         return "times";
232 }
233
234
235 string const lyx_gui::sans_font_name()
236 {
237         return "helvetica";
238 }
239
240
241 string const lyx_gui::typewriter_font_name()
242 {
243         return "courier";
244 }
245
246
247 void lyx_gui::sync_events()
248 {
249         // FIXME
250 }