]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/lyx_gui.C
Compilation fix: give C_read_callback extern "C" linkage.
[lyx.git] / src / frontends / xforms / lyx_gui.C
index 66fd9c84d37ac6be17e0d86ce4970555407b5b34..3c7daf746b105ceba1b1cf5a18c99a0878269546 100644 (file)
@@ -8,18 +8,19 @@
  */
 
 #include <config.h>
+
 #include "lyx_gui.h"
+
 #include "support/lyxlib.h"
 #include "support/os.h"
 #include "support/filetools.h"
+
 #include "debug.h"
 #include "gettext.h"
+
 #include "lyx_main.h"
 #include "lyxrc.h"
+#include "lyxfont.h"
 
 // FIXME: move this stuff out again
 #include "bufferlist.h"
 #include "lyxserver.h"
 #include "BufferView.h"
 #include "XFormsView.h"
+
 #include FORMS_H_LOCATION
 #include "ColorHandler.h"
 #include "xforms_helpers.h"
+#include "xfont_loader.h"
 #ifdef USE_XFORMS_IMAGE_LOADER
-#include "xformsGImage.h"
+#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
+using std::exit;
+#endif
+
 using std::vector;
 using std::hex;
 using std::endl;
+using std::setbase;
+using std::setfill;
+using std::setw;
+
 extern bool finished;
 extern BufferList bufferlist;
+
 // FIXME: wrong place !
 LyXServer * lyxserver;
+
 namespace {
+
 /// set default GUI configuration
 void setDefaults()
 {
@@ -76,7 +85,7 @@ void setDefaults()
                        | FL_PDBorderWidth, &cntl);
 }
 
+
 extern "C" {
 
 int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
@@ -99,19 +108,19 @@ int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
        lyx::abort();
        return 0;
 }
+
 }
+
 /// read in geometry specification
 char geometry[40];
+
 } // namespace anon
 
+
 void lyx_gui::parse_init(int & argc, char * argv[])
 {
        setDefaults();
+
        FL_CMD_OPT cmdopt[] = {
                {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
        };
@@ -121,36 +130,48 @@ void lyx_gui::parse_init(int & argc, char * argv[])
        };
 
        const int num_res = sizeof(res)/sizeof(FL_resource);
+
        fl_initialize(&argc, argv, "LyX", cmdopt, num_res);
+
        // It appears that, in xforms >=0.89.5, fl_initialize()
        // calls setlocale() and ruins our LC_NUMERIC setting.
        locale_init();
+
        fl_get_app_resources(res, num_res);
+
        Display * display = fl_get_display();
+
        if (!display) {
                lyxerr << "LyX: unable to access X display, exiting" << endl;
                os::warn("Unable to access X display, exiting");
-               exit(1);
+               ::exit(1);
        }
+
        fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
+
        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
+}
+
 
 void lyx_gui::parse_lyxrc()
 {
-       // FIXME !!!! 
+       // FIXME !!!!
        lyxrc.dpi = 95;
+
        XformsColor::read(AddName(user_lyxdir, "preferences.xform"));
 
        if (lyxrc.popup_font_encoding.empty())
@@ -203,7 +224,7 @@ void lyx_gui::parse_lyxrc()
 #endif
 }
 
+
 void lyx_gui::start(string const & batch, vector<string> files)
 {
        // initial geometry
@@ -211,7 +232,7 @@ void lyx_gui::start(string const & batch, vector<string> files)
        int ypos = -1;
        unsigned int width = 690;
        unsigned int height = 510;
+
        static const int geometryBitmask =
                XParseGeometry(geometry,
                                &xpos, &ypos, &width, &height);
@@ -231,7 +252,7 @@ void lyx_gui::start(string const & batch, vector<string> files)
        }
 
        Screen * s = ScreenOfDisplay(fl_get_display(), fl_screen);
+
        // recalculate xpos if it's not set
        if (xpos == -1)
                xpos = (WidthOfScreen(s) - width) / 2;
@@ -242,17 +263,17 @@ void lyx_gui::start(string const & batch, vector<string> files)
 
        lyxerr[Debug::GUI] << "Creating view: " << width << "x" << height
                << "+" << xpos << "+" << ypos << endl;
+
        XFormsView 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<string>::const_iterator cit = files.begin();
        vector<string>::const_iterator end = files.end();
        for (; cit != end; ++cit) {
@@ -272,7 +293,7 @@ void lyx_gui::start(string const & batch, vector<string> files)
                view.getLyXFunc()->verboseDispatch(batch, false);
        }
 
-       // enter the event loop 
+       // enter the event loop
        while (!finished) {
                if (fl_check_forms() == FL_EVENT) {
                        XEvent ev;
@@ -283,24 +304,67 @@ void lyx_gui::start(string const & batch, vector<string> files)
                }
        }
 
-       // FIXME 
+       // FIXME
        delete lyxserver;
 }
-// Called by the graphics cache to connect the appropriate frontend
-// image loading routines to the LyX kernel.
-void lyx_gui::init_graphics()
+
+
+string const lyx_gui::hexname(LColor::color col)
 {
-       using namespace grfx;
+       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();
+       }
 
-#ifdef USE_XFORMS_IMAGE_LOADER
-       // connect the image loader based on the xforms library
-       GImage::newImage.connect(boost::bind(&xformsGImage::newImage));
-       GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
-#else
-       // connect the image loader based on the XPM library
-       GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
-       GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats));
-#endif
+       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);
 }