]> 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 3c7daf746b105ceba1b1cf5a18c99a0878269546..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>
@@ -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())
@@ -225,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;
@@ -233,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;
@@ -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
@@ -299,16 +313,23 @@ 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 << endl;
+                       lyxerr << "Type: " << ev.xany.type
+                              << " 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);
@@ -332,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());
 }
 
 
@@ -358,7 +379,7 @@ namespace {
 extern "C"
 void C_read_callback(int, void * data)
 {
-       LyXComm * comm = static_cast<LyXComm *>(data); 
+       LyXComm * comm = static_cast<LyXComm *>(data);
        comm->read_ready();
 }
 
@@ -368,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);
+}