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