]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GuiApplication.C
It compiles again. I must be crazy. At least it does not run but segfaults
[lyx.git] / src / frontends / gtk / GuiApplication.C
1 /**
2  * \file qt4/GuiApplication.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  * \author Abdelrazak Younes
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 "GuiApplication.h"
24 #include "io_callback.h"
25
26 #include "GtkmmX.h"
27
28 #include "BufferView.h"
29 #include "Color.h"
30
31 #include "graphics/LoaderQueue.h"
32
33 #include "support/lstrings.h"
34 #include "support/os.h"
35 #include "support/package.h"
36
37 #include "lyx_main.h"
38 #include "lyxrc.h"
39 #include "debug.h"
40
41 #include <gtkmm.h>
42
43 #include "LyXGdkImage.h"
44
45 #include <iomanip>
46
47
48 using lyx::support::subst;
49
50 using std::string;
51 using std::endl;
52
53
54 namespace {
55
56 std::map<int, boost::shared_ptr<io_callback> > callbacks;
57
58 /// estimate DPI from X server
59 int getDPI()
60 {
61         //TODO use GDK instead
62         Screen * scr = ScreenOfDisplay(getDisplay(), getScreen());
63         return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
64                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2);
65 }
66
67 } // namespace anon
68
69
70 namespace lyx {
71
72 frontend::Application * createApplication(int & argc, char * argv[])
73 {
74         return new frontend::GuiApplication(argc, argv);
75 }
76
77 namespace frontend {
78
79 GuiApplication::GuiApplication(int & argc, char ** argv)
80         : Gtk::Main(argc, argv), Application(argc, argv)
81 {
82         using namespace lyx::graphics;
83         Image::newImage = boost::bind(&LyXGdkImage::newImage);
84         Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats);
85
86         // needs to be done before reading lyxrc
87         lyxrc.dpi = getDPI();
88
89         LoaderQueue::setPriority(10,100);
90 }
91
92
93 Clipboard& GuiApplication::clipboard()
94 {
95         return clipboard_;
96 }
97
98
99 Selection& GuiApplication::selection()
100 {
101         return selection_;
102 }
103
104
105 int const GuiApplication::exec()
106 {
107         run();
108         return EXIT_SUCCESS;
109 }
110
111
112 void GuiApplication::exit(int /*status*/)
113 {
114         // FIXME: Don't ignore status
115         guiApp->quit();
116 }
117
118
119 string const GuiApplication::romanFontName()
120 {
121         return "times";
122 }
123
124
125 string const GuiApplication::sansFontName()
126 {
127         return "helvetica";
128 }
129
130
131 string const GuiApplication::typewriterFontName()
132 {
133         return "courier";
134 }
135
136
137 void GuiApplication::syncEvents()
138 {
139         // FIXME
140 }
141
142
143 bool GuiApplication::getRgbColor(LColor_color col,
144         lyx::RGBColor & rgbcol)
145 {
146         Gdk::Color gdkColor;
147         Gdk::Color * gclr = colorCache.getColor(col);
148         if (!gclr) {
149                 gclr = &gdkColor;
150                 if(!gclr->parse(lcolor.getX11Name(col))) {
151                         rgbcol.r = 0;
152                         rgbcol.g = 0;
153                         rgbcol.b = 0;
154                         return false;
155                 }
156         }
157
158         // Note that X stores the RGB values in the range 0 - 65535
159         // whilst we require them in the range 0 - 255.
160         rgbcol.r = gclr->get_red() / 256;
161         rgbcol.g = gclr->get_green() / 256;
162         rgbcol.b = gclr->get_blue() / 256;
163         return true;
164 }
165
166
167 string const GuiApplication::hexName(LColor_color col)
168 {
169         lyx::RGBColor rgbcol;
170         if (!getRgbColor(col, rgbcol)) {
171                 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
172                        << '"' << std::endl;
173                 return string();
174         }
175
176         std::ostringstream os;
177
178         os << std::setbase(16) << std::setfill('0')
179            << std::setw(2) << rgbcol.r
180            << std::setw(2) << rgbcol.g
181            << std::setw(2) << rgbcol.b;
182
183         return os.str();
184 }
185
186
187 void GuiApplication::updateColor(LColor_color)
188 {
189         colorCache.clear();
190 }
191
192
193 void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
194 {
195         callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
196 }
197
198
199 void GuiApplication::unregisterSocketCallback(int fd)
200 {
201         callbacks.erase(fd);
202 }
203
204 } // namespace frontend
205 } // namespace lyx