]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/lyx_gui.C
3de8d1872a4ca0e7567c51da4d9d6adfe2fcdcae
[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 namespace {
83
84 /// estimate DPI from X server
85 int getDPI()
86 {
87         //TODO use GDK instead
88         Screen * scr = ScreenOfDisplay(getDisplay(), getScreen());
89         return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
90                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2);
91 }
92
93 } // namespace anon
94
95 GuiApplication * guiApp;
96
97 int lyx_gui::exec(int & argc, char * argv[])
98 {
99         guiApp = new GuiApplication(argc, argv);
100         theApp = guiApp;
101
102         return LyX::ref().exec2(argc, argv);
103 }
104
105
106 void lyx_gui::exit(int status)
107 {
108         guiApp->exit(status);
109 }
110
111
112 bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
113 {
114         Gdk::Color gdkColor;
115         Gdk::Color * gclr = colorCache.getColor(col);
116         if (!gclr) {
117                 gclr = &gdkColor;
118                 if(!gclr->parse(lcolor.getX11Name(col))) {
119                         rgbcol.r = 0;
120                         rgbcol.g = 0;
121                         rgbcol.b = 0;
122                         return false;
123                 }
124         }
125
126         // Note that X stores the RGB values in the range 0 - 65535
127         // whilst we require them in the range 0 - 255.
128         rgbcol.r = gclr->get_red() / 256;
129         rgbcol.g = gclr->get_green() / 256;
130         rgbcol.b = gclr->get_blue() / 256;
131         return true;
132 }
133
134
135 string const lyx_gui::hexname(LColor_color col)
136 {
137         lyx::RGBColor rgbcol;
138         if (!getRGBColor(col, rgbcol)) {
139                 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
140                        << '"' << std::endl;
141                 return string();
142         }
143
144         std::ostringstream os;
145
146         os << std::setbase(16) << std::setfill('0')
147            << std::setw(2) << rgbcol.r
148            << std::setw(2) << rgbcol.g
149            << std::setw(2) << rgbcol.b;
150
151         return os.str();
152 }
153
154
155 void lyx_gui::update_color(LColor_color /*col*/)
156 {
157         colorCache.clear();
158 }
159
160
161 void lyx_gui::update_fonts()
162 {
163         fontLoader.update();
164 }
165
166
167 bool lyx_gui::font_available(LyXFont const & font)
168 {
169         return fontLoader.available(font);
170 }
171
172
173 namespace {
174
175 std::map<int, boost::shared_ptr<io_callback> > callbacks;
176
177 } // NS anon
178
179
180 void lyx_gui::register_socket_callback(int fd,
181                                        boost::function<void()> func)
182 {
183         callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
184 }
185
186
187 void lyx_gui::unregister_socket_callback(int fd)
188 {
189         callbacks.erase(fd);
190 }
191
192
193 void lyx_gui::sync_events()
194 {
195         // FIXME
196 }