]> 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 6ad47a3afc2867c98c4431a06e3d78d37c394e70..a2e8ecba193fdf4a8d1d8e666f985a6e302e0861 100644 (file)
 #include "bufferlist.h"
 #include "BufferView.h"
 #include "debug.h"
+#include "funcrequest.h"
 #include "gettext.h"
 #include "LColor.h"
 #include "lyx_main.h"
+#include "LyXAction.h"
 #include "lyxfunc.h"
 #include "lyxrc.h"
 #include "lyxserver.h"
+#include "lyxsocket.h"
 
 #include "graphics/LoaderQueue.h"
 
+#include "support/filetools.h"
 #include "support/lyxlib.h"
 #include "support/os.h"
-#include "support/filetools.h"
 #include "support/path_defines.h"
 
 #include "lyx_forms.h"
@@ -60,12 +63,14 @@ 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 {
 
@@ -116,7 +121,7 @@ int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
        }
 
        // emergency cleanup
-       LyX::emergencyCleanup();
+       LyX::cref().emergencyCleanup();
 
        // Get the reason for the crash.
        char etxt[513];
@@ -174,7 +179,7 @@ void parse_init(int & argc, char * argv[])
 
        XSetErrorHandler(LyX_XErrHandler);
 
-       lyxColorHandler.reset(new LyXColorHandler());
+       lyxColorHandler.reset(new LyXColorHandler);
 
        using namespace lyx::graphics;
 
@@ -279,13 +284,18 @@ void 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();
 
        // 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();
@@ -294,7 +304,7 @@ void start(string const & batch, vector<string> const & files)
 
        // handle the batch commands the user asked for
        if (!batch.empty())
-               view.getLyXFunc().dispatch(batch);
+               view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
 
        // enter the event loop
        while (!finished) {
@@ -310,6 +320,7 @@ void start(string const & batch, vector<string> const & files)
        }
 
        // FIXME: breaks emergencyCleanup
+       delete lyxsocket;
        delete lyxserver;
 }
 
@@ -355,6 +366,7 @@ string const hexname(LColor_color col)
 
 void update_color(LColor_color col)
 {
+       lyxColorHandler->getGCForeground(col);
        lyxColorHandler->updateColor(col);
 }
 
@@ -379,6 +391,20 @@ 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);
+}
+
+extern "C"
+void C_serversocket_callback(int, void * data)
+{
+       LyXServerSocket * server = static_cast<LyXServerSocket *>(data);
+       server->serverCallback();
+}
+
 }
 
 void set_read_callback(int fd, LyXComm * comm)
@@ -386,12 +412,30 @@ 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()
 {