]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/lyx_gui.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / lyx_gui.C
index 7c80857880adbdadcea83f5e9755eb32b66d9c13..a2e8ecba193fdf4a8d1d8e666f985a6e302e0861 100644 (file)
@@ -3,61 +3,74 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author unknown
+ * \author Lars Gullik Bjønnes
  * \author John Levon
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "lyx_gui.h"
+#include "ColorHandler.h"
+#include "xfont_loader.h"
+#include "xforms_helpers.h"
+#include "xformsImage.h"
+#include "XFormsView.h"
 
-#include "support/lyxlib.h"
-#include "support/os.h"
-#include "support/filetools.h"
-
+#include "bufferlist.h"
+#include "BufferView.h"
 #include "debug.h"
+#include "funcrequest.h"
 #include "gettext.h"
-
+#include "LColor.h"
 #include "lyx_main.h"
-#include "lyxrc.h"
-#include "lyxfont.h"
-
-// FIXME: move this stuff out again
-#include "bufferlist.h"
+#include "LyXAction.h"
 #include "lyxfunc.h"
+#include "lyxrc.h"
 #include "lyxserver.h"
-#include "BufferView.h"
-#include "XFormsView.h"
+#include "lyxsocket.h"
 
-#include FORMS_H_LOCATION
-#include "ColorHandler.h"
-#include "xforms_helpers.h"
-#include "xfont_loader.h"
-#include "xformsImage.h"
+#include "graphics/LoaderQueue.h"
 
-#include "Lsstream.h"
+#include "support/filetools.h"
+#include "support/lyxlib.h"
+#include "support/os.h"
+#include "support/path_defines.h"
+
+#include "lyx_forms.h"
+
+#include <boost/bind.hpp>
+
+#include "support/std_sstream.h"
 #include <iomanip>
 #include <fcntl.h>
-#include <boost/bind.hpp>
+
+using lyx::support::AddName;
+using lyx::support::user_lyxdir;
+
+namespace os = lyx::support::os;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::exit;
 #endif
 
-using std::vector;
-using std::hex;
 using std::dec;
 using std::endl;
+using std::hex;
 using std::setbase;
 using std::setfill;
 using std::setw;
+using std::ostringstream;
+using std::vector;
+using std::string;
+
 
 extern BufferList bufferlist;
 
 // FIXME: wrong place !
 LyXServer * lyxserver;
+LyXServerSocket * lyxsocket;
 
 namespace {
 
@@ -108,14 +121,14 @@ int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
        }
 
        // emergency cleanup
-       LyX::emergencyCleanup();
+       LyX::cref().emergencyCleanup();
 
        // Get the reason for the crash.
        char etxt[513];
        XGetErrorText(display, xeev->error_code, etxt, 512);
        lyxerr << etxt << " id: " << xeev->resourceid << endl;
        // By doing an abort we get a nice backtrace. (hopefully)
-       lyx::abort();
+       lyx::support::abort();
        return 0;
 }
 
@@ -127,7 +140,12 @@ char geometry[40];
 } // namespace anon
 
 
-void lyx_gui::parse_init(int & argc, char * argv[])
+namespace lyx_gui {
+
+bool use_gui = true;
+
+
+void parse_init(int & argc, char * argv[])
 {
        setDefaults();
 
@@ -161,9 +179,9 @@ void lyx_gui::parse_init(int & argc, char * argv[])
 
        XSetErrorHandler(LyX_XErrHandler);
 
-       lyxColorHandler.reset(new LyXColorHandler());
+       lyxColorHandler.reset(new LyXColorHandler);
 
-       using namespace grfx;
+       using namespace lyx::graphics;
 
        // connect the image loader based on the xforms library
        Image::newImage = boost::bind(&xformsImage::newImage);
@@ -171,12 +189,14 @@ void lyx_gui::parse_init(int & argc, char * argv[])
 
        // must do this /before/ lyxrc gets read
        lyxrc.dpi = getDPI();
+
+       LoaderQueue::setPriority(10,100);
 }
 
 
-void lyx_gui::parse_lyxrc()
+void parse_lyxrc()
 {
-       XformsColor::read(AddName(user_lyxdir, "preferences.xform"));
+       XformsColor::read(AddName(user_lyxdir(), "preferences.xform"));
 
        if (lyxrc.popup_font_encoding.empty())
                lyxrc.popup_font_encoding = lyxrc.font_norm;
@@ -225,7 +245,7 @@ void lyx_gui::parse_lyxrc()
 }
 
 
-void lyx_gui::start(string const & batch, vector<string> const & files)
+void start(string const & batch, vector<string> const & files)
 {
        // initial geometry
        int xpos = -1;
@@ -264,34 +284,27 @@ void lyx_gui::start(string const & batch, vector<string> const & files)
        lyxerr[Debug::GUI] << "Creating view: " << width << 'x' << height
                           << '+' << xpos << '+' << ypos << endl;
 
-       XFormsView view(width, height);
+       boost::shared_ptr<XFormsView> view_ptr(new XFormsView(width, height));
+       LyX::ref().addLyXView(view_ptr);
+
+       XFormsView & view = *view_ptr.get();
        view.show(xpos, ypos, "LyX");
        view.init();
 
-       Buffer * last = 0;
-
        // FIXME: some code below needs moving
 
        lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
+       lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
+                         os::slashify_path(os::getTmpDir() + "/lyxsocket"));
 
        vector<string>::const_iterator cit = files.begin();
        vector<string>::const_iterator end = files.end();
-       for (; cit != end; ++cit) {
-               Buffer * b = bufferlist.loadLyXFile(*cit);
-               if (b) {
-                       last = b;
-               }
-       }
-
-       // switch to the last buffer successfully loaded
-       if (last) {
-               view.view()->buffer(last);
-       }
+       for (; cit != end; ++cit)
+               view.view()->loadLyXFile(*cit, true);
 
        // handle the batch commands the user asked for
-       if (!batch.empty()) {
-               view.getLyXFunc().dispatch(batch);
-       }
+       if (!batch.empty())
+               view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
 
        // enter the event loop
        while (!finished) {
@@ -307,56 +320,64 @@ void lyx_gui::start(string const & batch, vector<string> const & files)
        }
 
        // FIXME: breaks emergencyCleanup
+       delete lyxsocket;
        delete lyxserver;
 }
 
 
-void lyx_gui::exit()
+void exit()
 {
        finished = true;
 }
 
 
-string const lyx_gui::hexname(LColor::color col)
+void sync_events()
 {
-       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();
-       }
+       // FIXME
+}
+
+
+FuncStatus getStatus(FuncRequest const & /*ev*/)
+{
+       // Nothing interesting to do here
+       return FuncStatus();
+}
+
+string const hexname(LColor_color col)
+{
+       unsigned int r, g, b;
+       bool const success = getRGBColor(col, r, g, b);
+       if (!success) {
+               lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
+                      << '"' << endl;
+               return string();
+        }
 
-       ostringstream os;
+        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);
+          << setw(2) << r
+          << setw(2) << g
+          << setw(2) << b;
 
-       return STRCONV(os.str());
+       return os.str();
 }
 
 
-void lyx_gui::update_color(LColor::color col)
+void update_color(LColor_color col)
 {
+       lyxColorHandler->getGCForeground(col);
        lyxColorHandler->updateColor(col);
 }
 
 
-void lyx_gui::update_fonts()
+void update_fonts()
 {
        fontloader.update();
 }
 
 
-bool lyx_gui::font_available(LyXFont const & font)
+bool font_available(LyXFont const & font)
 {
        return fontloader.available(font);
 }
@@ -370,15 +391,67 @@ void C_read_callback(int, void * data)
        comm->read_ready();
 }
 
+extern "C"
+void C_datasocket_callback(int, void * data)
+{
+       LyXDataSocket * client = static_cast<LyXDataSocket *>(data);
+       client->server()->dataCallback(client);
 }
 
-void lyx_gui::set_read_callback(int fd, LyXComm * comm)
+extern "C"
+void C_serversocket_callback(int, void * data)
 {
-       fl_add_io_callback(fd, FL_READ, C_read_callback, comm);
+       LyXServerSocket * server = static_cast<LyXServerSocket *>(data);
+       server->serverCallback();
 }
 
+}
 
-void lyx_gui::remove_read_callback(int fd)
+void set_read_callback(int fd, LyXComm * comm)
+{
+       fl_add_io_callback(fd, FL_READ, C_read_callback, comm);
+}
+
+void remove_read_callback(int fd)
 {
        fl_remove_io_callback(fd, FL_READ, C_read_callback);
 }
+
+void set_datasocket_callback(LyXDataSocket * p)
+{
+       fl_add_io_callback(p->fd(), FL_READ, C_datasocket_callback, p);
+}
+
+void remove_datasocket_callback(LyXDataSocket * p)
+{
+       fl_remove_io_callback(p->fd(), FL_READ, C_datasocket_callback);
+}
+
+void set_serversocket_callback(LyXServerSocket * p)
+{
+       fl_add_io_callback(p->fd(), FL_READ, C_serversocket_callback, p);
+}
+
+void remove_serversocket_callback(LyXServerSocket * p)
+{
+       fl_remove_io_callback(p->fd(), FL_READ, C_serversocket_callback);
+}
+
+string const roman_font_name()
+{
+       return "times";
+}
+
+
+string const sans_font_name()
+{
+       return "helvetica";
+}
+
+
+string const typewriter_font_name()
+{
+       return "courier";
+}
+
+}; // namespace lyx_gui