/** * \file lyx_gui.C * Copyright 2002 the LyX Team * Read the file COPYING * * \author unknown * \author John Levon */ #include #include "support/lyxlib.h" #include "support/os.h" #include "support/filetools.h" #include "support/lstrings.h" #include "debug.h" #include "gettext.h" #include #include #include "lyx_gui.h" #include "lyx_main.h" #include "lyxrc.h" #include "lyxfont.h" // FIXME: move this stuff out again #include "bufferlist.h" #include "lyxfunc.h" #include "lyxserver.h" #include "BufferView.h" // Dear Lord, deliver us from Evil, // aka the Qt headers #include #include #include #include "QtView.h" #include "QLImage.h" #include "qfont_loader.h" #include "io_callback.h" #include #ifndef CXX_GLOBAL_CSTD using std::exit; #endif using std::vector; using std::map; using std::endl; extern BufferList bufferlist; // FIXME: wrong place ! LyXServer * lyxserver; void lyx_gui::parse_init(int & argc, char * argv[]) { static QApplication a(argc, argv); using namespace grfx; Image::newImage = boost::bind(&QLImage::newImage); Image::loadableFormats = boost::bind(&QLImage::loadableFormats); } void lyx_gui::parse_lyxrc() { // FIXME !!!! lyxrc.dpi = 95; } void lyx_gui::start(string const & batch, vector files) { // initial geometry int xpos = -1; int ypos = -1; unsigned int width = 690; unsigned int height = 510; QtView view(width, height); view.show(xpos, ypos, "LyX"); view.init(); Buffer * last = 0; // FIXME: some code below needs moving lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); vector::const_iterator cit = files.begin(); vector::const_iterator end = files.end(); for (; cit != end; ++cit) { Buffer * b = bufferlist.loadLyXFile(*cit); if (b) { last = b; } } // switch to the last buffer successfully loaded if (last) { view.view()->buffer(last); } // handle the batch commands the user asked for if (!batch.empty()) { view.getLyXFunc().dispatch(batch); } qApp->exec(); // FIXME delete lyxserver; } void lyx_gui::exit() { qApp->exit(0); } string const lyx_gui::hexname(LColor::color col) { QColor color(lcolor.getX11Name(col).c_str()); return ltrim(color.name().latin1(), "#"); } void lyx_gui::update_color(LColor::color) { // no need } void lyx_gui::update_fonts() { fontloader.update(); } bool lyx_gui::font_available(LyXFont const & font) { return fontloader.available(font); } namespace { map io_callbacks; } void lyx_gui::set_read_callback(int fd, LyXComm * comm) { io_callbacks[fd] = new io_callback(fd, comm); } void lyx_gui::remove_read_callback(int fd) { map::iterator it = io_callbacks.find(fd); if (it != io_callbacks.end()) { delete it->second; io_callbacks.erase(it); } }