]> git.lyx.org Git - features.git/blobdiff - src/frontends/xforms/lyx_gui.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / frontends / xforms / lyx_gui.C
index ccf772656dad5a67ddff495607940ee9ee2a53b9..14ff26790e3380ee43e7732efb45541873f8b56d 100644 (file)
@@ -6,60 +6,79 @@
  * \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 "LyXAction.h"
+#include "lyxfunc.h"
 #include "lyxrc.h"
-#include "lyxfont.h"
+#include "lyxserver.h"
+#include "lyxsocket.h"
+
 #include "graphics/LoaderQueue.h"
 
-// FIXME: move this stuff out again
-#include "bufferlist.h"
-#include "buffer_funcs.h"
-#include "lyxfunc.h"
-#include "lyxserver.h"
-#include "BufferView.h"
-#include "XFormsView.h"
+#include "support/filetools.h"
+#include "support/lyxlib.h"
+#include "support/os.h"
+#include "support/path_defines.h"
 
 #include "lyx_forms.h"
-#include "ColorHandler.h"
-#include "xforms_helpers.h"
-#include "xfont_loader.h"
-#include "xformsImage.h"
 
-#include "Lsstream.h"
-#include <iomanip>
-#include <fcntl.h>
 #include <boost/bind.hpp>
 
+#include <fcntl.h>
+
+#include <sstream>
+#include <iomanip>
+
+using lyx::support::AddName;
+using lyx::support::user_lyxdir;
+
+using lyx::frontend::fontloader;
+using lyx::frontend::getRGBColor;
+using lyx::frontend::lyxColorHandler;
+using lyx::frontend::LyXColorHandler;
+using lyx::frontend::XformsColor;
+using lyx::frontend::XFormsView;
+
+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 {
 
@@ -110,14 +129,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;
 }
 
@@ -168,9 +187,9 @@ void 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);
@@ -185,7 +204,7 @@ void parse_init(int & argc, char * argv[])
 
 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;
@@ -273,33 +292,26 @@ void start(string const & batch, vector<string> const & files)
        lyxerr[Debug::GUI] << "Creating view: " << width << 'x' << height
                           << '+' << xpos << '+' << ypos << endl;
 
-       XFormsView view(width, height);
-       view.show(xpos, ypos, "LyX");
-       view.init();
+       boost::shared_ptr<XFormsView> view(new XFormsView(width, height));
+       LyX::ref().addLyXView(view);
 
-       Buffer * last = 0;
+       view->show(xpos, ypos, "LyX");
+       view->init();
 
        // FIXME: some code below needs moving
 
-       lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
+       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.newBuffer(*cit);
-               if (loadLyXFile(b, *cit))
-                       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) {
@@ -315,6 +327,7 @@ void start(string const & batch, vector<string> const & files)
        }
 
        // FIXME: breaks emergencyCleanup
+       delete lyxsocket;
        delete lyxserver;
 }
 
@@ -337,7 +350,7 @@ FuncStatus getStatus(FuncRequest const & /*ev*/)
        return FuncStatus();
 }
 
-string const hexname(LColor::color col)
+string const hexname(LColor_color col)
 {
        unsigned int r, g, b;
        bool const success = getRGBColor(col, r, g, b);
@@ -354,12 +367,13 @@ string const hexname(LColor::color col)
           << setw(2) << g
           << setw(2) << b;
 
-       return STRCONV(os.str());
+       return os.str();
 }
 
 
-void update_color(LColor::color col)
+void update_color(LColor_color col)
 {
+       lyxColorHandler->getGCForeground(col);
        lyxColorHandler->updateColor(col);
 }
 
@@ -375,26 +389,32 @@ bool font_available(LyXFont const & font)
        return fontloader.available(font);
 }
 
+
 namespace {
 
+std::map<int, boost::function<void()> > socket_callbacks;
+
 extern "C"
-void C_read_callback(int, void * data)
+void C_socket_callback(int fd, void *)
 {
-       LyXComm * comm = static_cast<LyXComm *>(data);
-       comm->read_ready();
+       socket_callbacks[fd]();
 }
 
-}
 
-void set_read_callback(int fd, LyXComm * comm)
+} // NS anon
+
+
+void register_socket_callback(int fd, boost::function<void()> func)
 {
-       fl_add_io_callback(fd, FL_READ, C_read_callback, comm);
+       socket_callbacks[fd] = func;
+       fl_add_io_callback(fd, FL_READ, C_socket_callback, 0);
 }
 
 
-void remove_read_callback(int fd)
+void unregister_socket_callback(int fd)
 {
-       fl_remove_io_callback(fd, FL_READ, C_read_callback);
+       fl_remove_io_callback(fd, FL_READ, C_socket_callback);
+       socket_callbacks.erase(fd);
 }