]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/lyx_gui.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / lyx_gui.C
index b424142506bfe265b34320c20d54ee34885787b5..7713c528225e2613f92bb6836ebecece61a31729 100644 (file)
@@ -1,10 +1,12 @@
 /**
- * \file lyx_gui.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * \file xforms/lyx_gui.C
+ * 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>
@@ -66,6 +68,15 @@ 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()
 {
@@ -167,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())
@@ -228,7 +239,7 @@ void lyx_gui::parse_lyxrc()
 }
 
 
-void lyx_gui::start(string const & batch, vector<string> files)
+void lyx_gui::start(string const & batch, vector<string> const & files)
 {
        // initial geometry
        int xpos = -1;
@@ -236,19 +247,19 @@ void lyx_gui::start(string const & batch, vector<string> files)
        unsigned int width = 690;
        unsigned int height = 510;
 
-       static const int geometryBitmask =
+       int const geometryBitmask =
                XParseGeometry(geometry,
-                               &xpos, &ypos, &width, &height);
+                              &xpos, &ypos, &width, &height);
 
        // if width is not set by geometry, check it against monitor width
-       if (!(geometryBitmask & 4)) {
+       if (!(geometryBitmask & WidthValue)) {
                Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
                if (WidthOfScreen(scr) - 8 < int(width))
                        width = WidthOfScreen(scr) - 8;
        }
 
        // if height is not set by geometry, check it against monitor height
-       if (!(geometryBitmask & 8)) {
+       if (!(geometryBitmask & HeightValue)) {
                Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
                if (HeightOfScreen(scr) - 24 < int(height))
                        height = HeightOfScreen(scr) - 24;
@@ -275,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();
@@ -293,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()->dispatch(batch);
+               view.getLyXFunc().dispatch(batch);
        }
 
        // enter the event loop
@@ -302,8 +313,9 @@ void lyx_gui::start(string const & batch, vector<string> files)
                        XEvent ev;
                        fl_XNextEvent(&ev);
                        lyxerr << "Received unhandled X11 event" << endl;
-                       lyxerr << "Type: 0x" << hex << ev.xany.type <<
-                               " Target: 0x" << hex << ev.xany.window << dec << endl;
+                       lyxerr << "Type: " << ev.xany.type
+                              << " Target: 0x" << hex << ev.xany.window
+                              << dec << endl;
                }
        }
 
@@ -341,7 +353,7 @@ string const lyx_gui::hexname(LColor::color col)
           << setw(2) << (xcol.green / 256)
           << setw(2) << (xcol.blue  / 256);
 
-       return os.str().c_str();
+       return STRCONV(os.str());
 }
 
 
@@ -377,3 +389,9 @@ 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);
+}