]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/lyx_gui.C
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / lyx_gui.C
index 67c55eede8d6fec5571650438a77afecd48a7f1d..919ec7063233a16c27d85441762f21e1ef63b402 100644 (file)
@@ -1,10 +1,12 @@
 /**
  * \file lyx_gui.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
  * \author unknown
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon 
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
@@ -50,12 +52,12 @@ using std::exit;
 
 using std::vector;
 using std::hex;
+using std::dec;
 using std::endl;
 using std::setbase;
 using std::setfill;
 using std::setw;
 
-extern bool finished;
 extern BufferList bufferlist;
 
 // FIXME: wrong place !
@@ -63,6 +65,18 @@ LyXServer * lyxserver;
 
 namespace {
 
+/// quit lyx
+bool finished = false;
+
+/// estimate DPI from X server
+float getDPI()
+{
+       Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
+       return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
+               (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2; 
+}
+
 /// set default GUI configuration
 void setDefaults()
 {
@@ -152,7 +166,7 @@ void lyx_gui::parse_init(int & argc, char * argv[])
        XSetErrorHandler(LyX_XErrHandler);
 
        lyxColorHandler.reset(new LyXColorHandler());
+
        using namespace grfx;
 
 #ifdef USE_XFORMS_IMAGE_LOADER
@@ -164,14 +178,14 @@ void lyx_gui::parse_init(int & argc, char * argv[])
        Image::newImage = boost::bind(&ImageXPM::newImage);
        Image::loadableFormats = boost::bind(&ImageXPM::loadableFormats);
 #endif
+
+       // must do this /before/ lyxrc gets read 
+       lyxrc.dpi = getDPI();
 }
 
 
 void lyx_gui::parse_lyxrc()
 {
-       // FIXME !!!!
-       lyxrc.dpi = 95;
-
        XformsColor::read(AddName(user_lyxdir, "preferences.xform"));
 
        if (lyxrc.popup_font_encoding.empty())
@@ -272,7 +286,7 @@ void lyx_gui::start(string const & batch, vector<string> files)
 
        // FIXME: some code below needs moving
 
-       lyxserver = new LyXServer(view.getLyXFunc(), lyxrc.lyxpipes);
+       lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
 
        vector<string>::const_iterator cit = files.begin();
        vector<string>::const_iterator end = files.end();
@@ -290,7 +304,7 @@ void lyx_gui::start(string const & batch, vector<string> files)
 
        // handle the batch commands the user asked for
        if (!batch.empty()) {
-               view.getLyXFunc()->verboseDispatch(batch, false);
+               view.getLyXFunc().dispatch(batch);
        }
 
        // enter the event loop
@@ -300,15 +314,21 @@ void lyx_gui::start(string const & batch, vector<string> files)
                        fl_XNextEvent(&ev);
                        lyxerr << "Received unhandled X11 event" << endl;
                        lyxerr << "Type: 0x" << hex << ev.xany.type <<
-                               " Target: 0x" << hex << ev.xany.window << endl;
+                               " Target: 0x" << hex << ev.xany.window << dec << endl;
                }
        }
 
-       // FIXME
+       // FIXME: breaks emergencyCleanup
        delete lyxserver;
 }
 
 
+void lyx_gui::exit()
+{
+       finished = true;
+}
+
+
 string const lyx_gui::hexname(LColor::color col)
 {
        string const name = lcolor.getX11Name(col);
@@ -352,3 +372,25 @@ bool lyx_gui::font_available(LyXFont const & font)
 {
        return fontloader.available(font);
 }
+
+namespace {
+
+extern "C"
+void C_read_callback(int, void * data)
+{
+       LyXComm * comm = static_cast<LyXComm *>(data);
+       comm->read_ready();
+}
+
+}
+
+void lyx_gui::set_read_callback(int fd, LyXComm * comm)
+{
+       fl_add_io_callback(fd, FL_READ, C_read_callback, comm);
+}
+
+
+void lyx_gui::remove_read_callback(int fd)
+{
+       fl_remove_io_callback(fd, FL_READ, C_read_callback);
+}