]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/lyx_gui.C
transfer lyx_gui::exit() to frontends/lyx_gui.C
[lyx.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 using std::map;
73 using std::vector;
74 using std::string;
75
76
77 namespace {
78
79 map<int, shared_ptr<socket_callback> > socket_callbacks;
80
81 } // namespace anon
82
83
84 GuiApplication * guiApp;
85
86 namespace lyx_gui {
87
88 int exec(int & argc, char * argv[])
89 {
90         GuiApplication app(argc, argv);
91
92         guiApp = &app;
93         theApp = guiApp;
94
95         return LyX::ref().exec2(argc, argv);
96 }
97
98
99 void sync_events()
100 {
101         // This is the ONLY place where processEvents may be called.
102         // During screen update/ redraw, this method is disabled to
103         // prevent keyboard events being handed to the LyX core, where
104         // they could cause re-entrant calls to screen update.
105 #if QT_VERSION >= 0x030100
106         qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
107 #endif
108 }
109
110
111 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
112 {
113         QColor const & qcol = lcolorcache.get(col);
114         if (!qcol.isValid()) {
115                 rgbcol.r = 0;
116                 rgbcol.g = 0;
117                 rgbcol.b = 0;
118                 return false;
119         }
120         rgbcol.r = qcol.red();
121         rgbcol.g = qcol.green();
122         rgbcol.b = qcol.blue();
123         return true;
124 }
125
126
127 string const hexname(LColor_color col)
128 {
129         return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
130 }
131
132
133 void update_color(LColor_color)
134 {
135         // FIXME: Bleh, can't we just clear them all at once ?
136         lcolorcache.clear();
137 }
138
139
140 void update_fonts()
141 {
142         fontloader.update();
143 }
144
145
146 bool font_available(LyXFont const & font)
147 {
148         return fontloader.available(font);
149 }
150
151
152 void register_socket_callback(int fd, boost::function<void()> func)
153 {
154         socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
155 }
156
157
158 void unregister_socket_callback(int fd)
159 {
160         socket_callbacks.erase(fd);
161 }
162
163 }; // namespace lyx_gui