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"
30 #include "LyXAction.h"
34 #include "graphics/LoaderQueue.h"
36 #include "io_callback.h"
38 // FIXME: move this stuff out again
39 #include "bufferlist.h"
41 #include "lyxserver.h"
42 #include "lyxsocket.h"
43 #include "BufferView.h"
48 #include "xftFontLoader.h"
49 #include "GWorkArea.h"
51 #include "support/lyxlib.h"
52 #include "support/os.h"
53 #include "support/filetools.h"
54 #include "support/package.h"
58 #include "LyXGdkImage.h"
60 #include <boost/bind.hpp>
61 #include <boost/function.hpp>
62 #include <boost/shared_ptr.hpp>
69 namespace os = lyx::support::os;
71 using std::ostringstream;
74 using lyx::support::package;
76 using lyx::frontend::colorCache;
77 using lyx::frontend::GView;
80 extern BufferList bufferlist;
82 // FIXME: wrong place !
83 LyXServer * lyxserver;
84 LyXServerSocket * lyxsocket;
86 bool lyx_gui::use_gui = true;
91 bool finished = false;
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);
106 void lyx_gui::parse_init(int & argc, char * argv[])
108 new Gtk::Main(argc, argv);
110 using namespace lyx::graphics;
111 Image::newImage = boost::bind(&LyXGdkImage::newImage);
112 Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats);
116 // must do this /before/ lyxrc gets read
117 lyxrc.dpi = getDPI();
121 void lyx_gui::parse_lyxrc()
126 void lyx_gui::start(string const & batch, std::vector<string> const & files)
128 boost::shared_ptr<GView> view_ptr(new GView);
129 LyX::ref().addLyXView(view_ptr);
131 GView & view = *view_ptr.get();
135 // FIXME: server code below needs moving
137 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
138 lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
139 os::internal_path(package().temp_dir() + "/lyxsocket"));
141 for_each(files.begin(), files.end(),
142 bind(&BufferView::loadLyXFile, view.view(), _1, true));
144 // handle the batch commands the user asked for
145 if (!batch.empty()) {
146 view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
149 // enter the event loop
151 while (Gtk::Main::events_pending())
152 Gtk::Main::iteration(false);
155 // FIXME: breaks emergencyCleanup
167 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
171 case LFUN_DIALOG_SHOW:
172 if (ev.argument == "preamble")
175 case LFUN_TOOLTIPS_TOGGLE:
186 string const lyx_gui::hexname(LColor_color col)
189 Gdk::Color * gclr = colorCache.getColor(col);
192 gclr->parse(lcolor.getX11Name(col));
195 std::ostringstream os;
197 // Note that X stores the RGB values in the range 0 - 65535
198 // whilst we require them in the range 0 - 255.
199 os << std::setbase(16) << std::setfill('0')
200 << std::setw(2) << (gclr->get_red() / 256)
201 << std::setw(2) << (gclr->get_green() / 256)
202 << std::setw(2) << (gclr->get_blue() / 256);
208 void lyx_gui::update_color(LColor_color /*col*/)
214 void lyx_gui::update_fonts()
220 bool lyx_gui::font_available(LyXFont const & font)
222 return fontLoader.available(font);
228 std::map<int, boost::shared_ptr<io_callback> > callbacks;
233 void lyx_gui::register_socket_callback(int fd,
234 boost::function<void()> func)
236 callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
240 void lyx_gui::unregister_socket_callback(int fd)
246 string const lyx_gui::roman_font_name()
252 string const lyx_gui::sans_font_name()
258 string const lyx_gui::typewriter_font_name()
264 void lyx_gui::sync_events()