3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjnes
10 * Full author contact details are available in file CREDITS.
15 // Too hard to make concept checks work with this file
16 #ifdef _GLIBCXX_CONCEPT_CHECKS
17 #undef _GLIBCXX_CONCEPT_CHECKS
19 #ifdef _GLIBCPP_CONCEPT_CHECKS
20 #undef _GLIBCPP_CONCEPT_CHECKS
26 #include "funcrequest.h"
31 #include "LyXAction.h"
35 #include "graphics/LoaderQueue.h"
37 #include "io_callback.h"
39 // FIXME: move this stuff out again
40 #include "bufferlist.h"
42 #include "lyxserver.h"
43 #include "lyxsocket.h"
44 #include "BufferView.h"
46 #include "GuiImplementation.h"
50 #include "xftFontLoader.h"
51 #include "GWorkArea.h"
53 #include "support/lyxlib.h"
54 #include "support/os.h"
55 #include "support/filetools.h"
56 #include "support/package.h"
60 #include "LyXGdkImage.h"
62 #include <boost/bind.hpp>
63 #include <boost/function.hpp>
64 #include <boost/shared_ptr.hpp>
71 namespace os = lyx::support::os;
73 using std::ostringstream;
76 using lyx::support::package;
78 using lyx::frontend::colorCache;
79 using lyx::frontend::Gui;
80 using lyx::frontend::GuiImplementation;
81 using lyx::frontend::GView;
84 extern BufferList bufferlist;
86 // FIXME: wrong place !
87 LyXServer * lyxserver;
88 LyXServerSocket * lyxsocket;
90 bool lyx_gui::use_gui = true;
94 /// estimate DPI from X server
97 //TODO use GDK instead
98 Screen * scr = ScreenOfDisplay(getDisplay(), getScreen());
99 return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
100 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2);
105 class Application: public Gtk::Main
109 Application(int & argc, char * argv[]): Gtk::Main(argc, argv)
112 Gui & gui() { return gui_; }
116 GuiImplementation gui_;
119 Application * theApp;
121 int lyx_gui::exec(int & argc, char * argv[])
123 theApp = new Application(argc, argv);
125 using namespace lyx::graphics;
126 Image::newImage = boost::bind(&LyXGdkImage::newImage);
127 Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats);
131 // must do this /before/ lyxrc gets read
132 lyxrc.dpi = getDPI();
134 return LyX::ref().exec2(argc, argv);
138 void lyx_gui::parse_lyxrc()
143 LyXView * lyx_gui::create_view(unsigned int width, unsigned int height,
144 int /*posx*/, int /*posy*/, bool)
146 int view_id = theApp->gui().newView(width, height);
147 GView & view = static_cast<GView &> (theApp->gui().view(view_id));
148 theApp->gui().newWorkArea(width, height, 0);
150 LyX::ref().addLyXView(&view);
159 int lyx_gui::start(LyXView * view, string const & batch)
161 // FIXME: server code below needs moving
163 lyxserver = new LyXServer(&view->getLyXFunc(), lyxrc.lyxpipes);
164 lyxsocket = new LyXServerSocket(&view->getLyXFunc(),
165 os::internal_path(package().temp_dir() + "/lyxsocket"));
167 // handle the batch commands the user asked for
168 if (!batch.empty()) {
169 view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
174 // FIXME: breaks emergencyCleanup
181 void lyx_gui::exit(int /*status*/)
183 // FIXME: Don't ignore status
188 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
192 case LFUN_TOOLTIPS_TOGGLE:
203 bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
206 Gdk::Color * gclr = colorCache.getColor(col);
209 if(!gclr->parse(lcolor.getX11Name(col))) {
217 // Note that X stores the RGB values in the range 0 - 65535
218 // whilst we require them in the range 0 - 255.
219 rgbcol.r = gclr->get_red() / 256;
220 rgbcol.g = gclr->get_green() / 256;
221 rgbcol.b = gclr->get_blue() / 256;
226 string const lyx_gui::hexname(LColor_color col)
228 lyx::RGBColor rgbcol;
229 if (!getRGBColor(col, rgbcol)) {
230 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
235 std::ostringstream os;
237 os << std::setbase(16) << std::setfill('0')
238 << std::setw(2) << rgbcol.r
239 << std::setw(2) << rgbcol.g
240 << std::setw(2) << rgbcol.b;
246 void lyx_gui::update_color(LColor_color /*col*/)
252 void lyx_gui::update_fonts()
258 bool lyx_gui::font_available(LyXFont const & font)
260 return fontLoader.available(font);
266 std::map<int, boost::shared_ptr<io_callback> > callbacks;
271 void lyx_gui::register_socket_callback(int fd,
272 boost::function<void()> func)
274 callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
278 void lyx_gui::unregister_socket_callback(int fd)
284 string const lyx_gui::roman_font_name()
290 string const lyx_gui::sans_font_name()
296 string const lyx_gui::typewriter_font_name()
302 void lyx_gui::sync_events()