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 int lyx_gui::start(string const & batch, std::vector<string> const & files,
144 unsigned int width, unsigned int height,
145 int /*posx*/, int /*posy*/, bool)
147 int view_id = theApp->gui().newView(width, height);
148 GView & view = static_cast<GView &> (theApp->gui().view(view_id));
149 theApp->gui().newWorkArea(width, height, 0);
151 LyX::ref().addLyXView(&view);
156 // FIXME: server code below needs moving
158 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
159 lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
160 os::internal_path(package().temp_dir() + "/lyxsocket"));
162 for_each(files.begin(), files.end(),
163 bind(&BufferView::loadLyXFile, view.view(), _1, true));
165 // handle the batch commands the user asked for
166 if (!batch.empty()) {
167 view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
172 // FIXME: breaks emergencyCleanup
179 void lyx_gui::exit(int /*status*/)
181 // FIXME: Don't ignore status
186 FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
190 case LFUN_TOOLTIPS_TOGGLE:
201 bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
204 Gdk::Color * gclr = colorCache.getColor(col);
207 if(!gclr->parse(lcolor.getX11Name(col))) {
215 // Note that X stores the RGB values in the range 0 - 65535
216 // whilst we require them in the range 0 - 255.
217 rgbcol.r = gclr->get_red() / 256;
218 rgbcol.g = gclr->get_green() / 256;
219 rgbcol.b = gclr->get_blue() / 256;
224 string const lyx_gui::hexname(LColor_color col)
226 lyx::RGBColor rgbcol;
227 if (!getRGBColor(col, rgbcol)) {
228 lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
233 std::ostringstream os;
235 os << std::setbase(16) << std::setfill('0')
236 << std::setw(2) << rgbcol.r
237 << std::setw(2) << rgbcol.g
238 << std::setw(2) << rgbcol.b;
244 void lyx_gui::update_color(LColor_color /*col*/)
250 void lyx_gui::update_fonts()
256 bool lyx_gui::font_available(LyXFont const & font)
258 return fontLoader.available(font);
264 std::map<int, boost::shared_ptr<io_callback> > callbacks;
269 void lyx_gui::register_socket_callback(int fd,
270 boost::function<void()> func)
272 callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
276 void lyx_gui::unregister_socket_callback(int fd)
282 string const lyx_gui::roman_font_name()
288 string const lyx_gui::sans_font_name()
294 string const lyx_gui::typewriter_font_name()
300 void lyx_gui::sync_events()