]> git.lyx.org Git - features.git/blob - src/frontends/qt3/lyx_gui.C
This commit creates a new "frontends/lyx_gui.C" that contains all functions that...
[features.git] / src / frontends / qt3 / lyx_gui.C
1 /**
2  * \file qt3/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 unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "lyx_gui.h"
15
16 // FIXME: move this stuff out again
17 #include "BufferView.h"
18 #include "Color.h"
19 #include "funcrequest.h"
20 #include "LColor.h"
21 #include "lyx_main.h"
22 #include "LyXAction.h"
23 #include "lyxfunc.h"
24 #include "lyxrc.h"
25 #include "lyxserver.h"
26 #include "lyxsocket.h"
27
28 #include "support/lstrings.h"
29 #include "support/os.h"
30 #include "support/package.h"
31 #include "debug.h"
32
33 // Dear Lord, deliver us from Evil, aka the Qt headers
34 // Qt defines a macro 'signals' that clashes with a boost namespace.
35 // All is well if the namespace is visible first.
36 #include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
37 #include <boost/bind.hpp>
38 #include <boost/shared_ptr.hpp>
39 #include "frontends/LyXView.h"
40 #include "frontends/WorkArea.h"
41
42 #include "GuiApplication.h"
43 #include "QtView.h"
44 #include "lcolorcache.h"
45 #include "qfont_loader.h"
46 #include "QLImage.h"
47 #include "qt_helpers.h"
48 #include "socket_callback.h"
49
50 #ifdef Q_WS_MACX
51 #include <Carbon/Carbon.h>
52 #endif
53
54 #include <qapplication.h>
55 #if QT_VERSION >= 0x030100
56 #include <qeventloop.h>
57 #endif
58 #include <qpaintdevicemetrics.h>
59 #include <qtranslator.h>
60 #include <qtextcodec.h>
61
62 using lyx::support::ltrim;
63 using lyx::support::package;
64
65 using lyx::frontend::GuiApplication;
66 using lyx::frontend::QtView;
67
68 namespace os = lyx::support::os;
69
70 using boost::shared_ptr;
71
72 #ifndef CXX_GLOBAL_CSTD
73 using std::exit;
74 #endif
75
76 using std::map;
77 using std::vector;
78 using std::string;
79
80
81 namespace {
82
83 map<int, shared_ptr<socket_callback> > socket_callbacks;
84
85 } // namespace anon
86
87
88 GuiApplication * guiApp;
89
90 namespace lyx_gui {
91
92 int exec(int & argc, char * argv[])
93 {
94         GuiApplication app(argc, argv);
95
96         guiApp = &app;
97         theApp = guiApp;
98
99         return LyX::ref().exec2(argc, argv);
100 }
101
102
103 void sync_events()
104 {
105         // This is the ONLY place where processEvents may be called.
106         // During screen update/ redraw, this method is disabled to
107         // prevent keyboard events being handed to the LyX core, where
108         // they could cause re-entrant calls to screen update.
109 #if QT_VERSION >= 0x030100
110         qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
111 #endif
112 }
113
114
115 void exit(int status)
116 {
117         guiApp->exit(status);
118 }
119
120
121 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
122 {
123         QColor const & qcol = lcolorcache.get(col);
124         if (!qcol.isValid()) {
125                 rgbcol.r = 0;
126                 rgbcol.g = 0;
127                 rgbcol.b = 0;
128                 return false;
129         }
130         rgbcol.r = qcol.red();
131         rgbcol.g = qcol.green();
132         rgbcol.b = qcol.blue();
133         return true;
134 }
135
136
137 string const hexname(LColor_color col)
138 {
139         return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
140 }
141
142
143 void update_color(LColor_color)
144 {
145         // FIXME: Bleh, can't we just clear them all at once ?
146         lcolorcache.clear();
147 }
148
149
150 void update_fonts()
151 {
152         fontloader.update();
153 }
154
155
156 bool font_available(LyXFont const & font)
157 {
158         return fontloader.available(font);
159 }
160
161
162 void register_socket_callback(int fd, boost::function<void()> func)
163 {
164         socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
165 }
166
167
168 void unregister_socket_callback(int fd)
169 {
170         socket_callbacks.erase(fd);
171 }
172
173 }; // namespace lyx_gui