]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/lyx_gui.C
fontloader for gtk, probably not efficient
[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 bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
107 {
108         Gdk::Color gdkColor;
109         Gdk::Color * gclr = colorCache.getColor(col);
110         if (!gclr) {
111                 gclr = &gdkColor;
112                 if(!gclr->parse(lcolor.getX11Name(col))) {
113                         rgbcol.r = 0;
114                         rgbcol.g = 0;
115                         rgbcol.b = 0;
116                         return false;
117                 }
118         }
119
120         // Note that X stores the RGB values in the range 0 - 65535
121         // whilst we require them in the range 0 - 255.
122         rgbcol.r = gclr->get_red() / 256;
123         rgbcol.g = gclr->get_green() / 256;
124         rgbcol.b = gclr->get_blue() / 256;
125         return true;
126 }
127
128
129 string const lyx_gui::hexname(LColor_color col)
130 {
131         lyx::RGBColor rgbcol;
132         if (!getRGBColor(col, rgbcol)) {
133                 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
134                        << '"' << std::endl;
135                 return string();
136         }
137
138         std::ostringstream os;
139
140         os << std::setbase(16) << std::setfill('0')
141            << std::setw(2) << rgbcol.r
142            << std::setw(2) << rgbcol.g
143            << std::setw(2) << rgbcol.b;
144
145         return os.str();
146 }
147
148
149 void lyx_gui::update_color(LColor_color /*col*/)
150 {
151         colorCache.clear();
152 }
153
154
155 namespace {
156
157 std::map<int, boost::shared_ptr<io_callback> > callbacks;
158
159 } // NS anon
160
161
162 void lyx_gui::register_socket_callback(int fd,
163                                        boost::function<void()> func)
164 {
165         callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
166 }
167
168
169 void lyx_gui::unregister_socket_callback(int fd)
170 {
171         callbacks.erase(fd);
172 }
173
174
175 void lyx_gui::sync_events()
176 {
177         // FIXME
178 }