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"
49 #include "xftFontLoader.h"
50 #include "GWorkArea.h"
52 #include "support/lyxlib.h"
53 #include "support/os.h"
54 #include "support/filetools.h"
55 #include "support/package.h"
59 #include "LyXGdkImage.h"
61 #include <boost/bind.hpp>
62 #include <boost/function.hpp>
63 #include <boost/shared_ptr.hpp>
70 namespace os = lyx::support::os;
72 using std::ostringstream;
75 using lyx::support::package;
77 using lyx::frontend::colorCache;
78 using lyx::frontend::GView;
81 extern BufferList bufferlist;
83 // FIXME: wrong place !
84 LyXServer * lyxserver;
85 LyXServerSocket * lyxsocket;
87 bool lyx_gui::use_gui = true;
91 /// estimate DPI from X server
94 //TODO use GDK instead
95 Screen * scr = ScreenOfDisplay(getDisplay(), getScreen());
96 return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
97 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2);
103 void lyx_gui::parse_init(int & argc, char * argv[])
105 new Gtk::Main(argc, argv);
107 using namespace lyx::graphics;
108 Image::newImage = boost::bind(&LyXGdkImage::newImage);
109 Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats);
113 // must do this /before/ lyxrc gets read
114 lyxrc.dpi = getDPI();
118 void lyx_gui::parse_lyxrc()
123 void lyx_gui::start(string const & batch, std::vector<string> const & files)
125 boost::shared_ptr<GView> view_ptr(new GView);
126 LyX::ref().addLyXView(view_ptr);
128 GView & view = *view_ptr.get();
132 // FIXME: server code below needs moving
134 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
135 lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
136 os::internal_path(package().temp_dir() + "/lyxsocket"));
138 for_each(files.begin(), files.end(),
139 bind(&BufferView::loadLyXFile, view.view(), _1, true));
141 // handle the batch commands the user asked for
142 if (!batch.empty()) {
143 view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
148 // FIXME: breaks emergencyCleanup
160 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
164 case LFUN_DIALOG_SHOW:
165 if (ev.argument == "preamble")
168 case LFUN_TOOLTIPS_TOGGLE:
179 bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
182 Gdk::Color * gclr = colorCache.getColor(col);
185 if(!gclr->parse(lcolor.getX11Name(col))) {
193 // Note that X stores the RGB values in the range 0 - 65535
194 // whilst we require them in the range 0 - 255.
195 rgbcol.r = gclr->get_red() / 256;
196 rgbcol.g = gclr->get_green() / 256;
197 rgbcol.b = gclr->get_blue() / 256;
202 string const lyx_gui::hexname(LColor_color col)
204 lyx::RGBColor rgbcol;
205 if (!getRGBColor(col, rgbcol)) {
206 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
211 std::ostringstream os;
213 os << std::setbase(16) << std::setfill('0')
214 << std::setw(2) << rgbcol.r
215 << std::setw(2) << rgbcol.g
216 << std::setw(2) << rgbcol.b;
222 void lyx_gui::update_color(LColor_color /*col*/)
228 void lyx_gui::update_fonts()
234 bool lyx_gui::font_available(LyXFont const & font)
236 return fontLoader.available(font);
242 std::map<int, boost::shared_ptr<io_callback> > callbacks;
247 void lyx_gui::register_socket_callback(int fd,
248 boost::function<void()> func)
250 callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
254 void lyx_gui::unregister_socket_callback(int fd)
260 string const lyx_gui::roman_font_name()
266 string const lyx_gui::sans_font_name()
272 string const lyx_gui::typewriter_font_name()
278 void lyx_gui::sync_events()