]> 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 207a33bcc807358aefbb90c9a411b394bd1a543c..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>
@@ -20,6 +22,7 @@
 
 #include "lyx_main.h"
 #include "lyxrc.h"
+#include "lyxfont.h"
 
 // FIXME: move this stuff out again
 #include "bufferlist.h"
 #include FORMS_H_LOCATION
 #include "ColorHandler.h"
 #include "xforms_helpers.h"
+#include "xfont_loader.h"
 #ifdef USE_XFORMS_IMAGE_LOADER
 #include "xformsImage.h"
 #else
 #include "graphics/GraphicsImageXPM.h"
 #endif
 
-
+#include "Lsstream.h"
+#include <iomanip>
 #include <fcntl.h>
-
 #include <boost/bind.hpp>
 
 #ifndef CXX_GLOBAL_CSTD
@@ -48,9 +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 !
@@ -58,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()
 {
@@ -147,14 +166,26 @@ void lyx_gui::parse_init(int & argc, char * argv[])
        XSetErrorHandler(LyX_XErrHandler);
 
        lyxColorHandler.reset(new LyXColorHandler());
+
+       using namespace grfx;
+
+#ifdef USE_XFORMS_IMAGE_LOADER
+       // connect the image loader based on the xforms library
+       Image::newImage = boost::bind(&xformsImage::newImage);
+       Image::loadableFormats = boost::bind(&xformsImage::loadableFormats);
+#else
+       // connect the image loader based on the XPM library
+       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())
@@ -255,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();
@@ -273,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
@@ -283,28 +314,83 @@ 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;
 }
 
 
-// Called by the graphics cache to connect the appropriate frontend
-// image loading routines to the LyX kernel.
-void lyx_gui::init_graphics()
+void lyx_gui::exit()
 {
-       using namespace grfx;
+       finished = true;
+}
 
-#ifdef USE_XFORMS_IMAGE_LOADER
-       // connect the image loader based on the xforms library
-       Image::newImage = boost::bind(&xformsImage::newImage);
-       Image::loadableFormats = boost::bind(&xformsImage::loadableFormats);
-#else
-       // connect the image loader based on the XPM library
-       Image::newImage = boost::bind(&ImageXPM::newImage);
-       Image::loadableFormats = boost::bind(&ImageXPM::loadableFormats);
-#endif
+
+string const lyx_gui::hexname(LColor::color col)
+{
+       string const name = lcolor.getX11Name(col);
+       Display * const display = fl_get_display();
+       Colormap const cmap = fl_state[fl_get_vclass()].colormap;
+       XColor xcol, ccol;
+
+       if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
+                       lyxerr << "X can't find color \""
+                              << lcolor.getLyXName(col)
+                              << "\"" << endl;
+                       return string();
+       }
+
+       ostringstream os;
+
+       // Note that X stores the RGB values in the range 0 - 65535
+       // whilst we require them in the range 0 - 255.
+       os << setbase(16) << setfill('0')
+          << setw(2) << (xcol.red   / 256)
+          << setw(2) << (xcol.green / 256)
+          << setw(2) << (xcol.blue  / 256);
+
+       return os.str().c_str();
+}
+
+
+void lyx_gui::update_color(LColor::color col)
+{
+       lyxColorHandler->updateColor(col);
+}
+
+
+void lyx_gui::update_fonts()
+{
+       fontloader.update();
+}
+
+
+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);
 }