]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gtk/lyx_gui.C
make it compile again
[lyx.git] / src / frontends / gtk / lyx_gui.C
index 4a856671a61f375d9c68ad58892222ac93133c5a..23d3de2c878fbbf317217222d57df5192350571b 100644 (file)
@@ -26,6 +26,7 @@
 #include "funcrequest.h"
 #include "gettext.h"
 
+#include "Color.h"
 #include "LColor.h"
 #include "LyXAction.h"
 #include "lyx_main.h"
 #include "io_callback.h"
 
 // FIXME: move this stuff out again
-#include "bufferlist.h"
 #include "lyxfunc.h"
 #include "lyxserver.h"
 #include "lyxsocket.h"
 #include "BufferView.h"
 
+#include "GuiApplication.h"
+#include "GuiImplementation.h"
 #include "GView.h"
 #include "GtkmmX.h"
 
-#include "xftFontLoader.h"
 #include "GWorkArea.h"
 
 #include "support/lyxlib.h"
@@ -55,8 +56,6 @@
 
 #include <gtkmm.h>
 
-#include "LyXGdkImage.h"
-
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
 #include <boost/shared_ptr.hpp>
@@ -74,15 +73,12 @@ using std::string;
 using lyx::support::package;
 
 using lyx::frontend::colorCache;
+using lyx::frontend::Gui;
+using lyx::frontend::GuiApplication;
+using lyx::frontend::GuiImplementation;
 using lyx::frontend::GView;
 
 
-extern BufferList bufferlist;
-
-// FIXME: wrong place !
-LyXServer * lyxserver;
-LyXServerSocket * lyxsocket;
-
 bool lyx_gui::use_gui = true;
 
 namespace {
@@ -98,19 +94,15 @@ int getDPI()
 
 } // namespace anon
 
+lyx::frontend::Application * theApp;
+GuiApplication * guiApp;
 
-void lyx_gui::parse_init(int & argc, char * argv[])
+int lyx_gui::exec(int & argc, char * argv[])
 {
-       new Gtk::Main(argc, argv);
-
-       using namespace lyx::graphics;
-       Image::newImage = boost::bind(&LyXGdkImage::newImage);
-       Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats);
+       guiApp = new GuiApplication(argc, argv);
+       theApp = guiApp;
 
-       locale_init();
-
-       // must do this /before/ lyxrc gets read
-       lyxrc.dpi = getDPI();
+       return LyX::ref().exec2(argc, argv);
 }
 
 
@@ -119,40 +111,22 @@ void lyx_gui::parse_lyxrc()
 }
 
 
-void lyx_gui::start(string const & batch, std::vector<string> const & files)
+LyXView * lyx_gui::create_view(unsigned int width, unsigned int height,
+               int posx, int posy, bool maximize)
 {
-       boost::shared_ptr<GView> view_ptr(new GView);
-       LyX::ref().addLyXView(view_ptr);
-
-       GView & view = *view_ptr.get();
-       view.show();
-       view.init();
-
-       // FIXME: server code below needs moving
-
-       lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
-       lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
-                         os::internal_path(package().temp_dir() + "/lyxsocket"));
-
-       for_each(files.begin(), files.end(),
-                bind(&BufferView::loadLyXFile, view.view(), _1, true));
-
-       // handle the batch commands the user asked for
-       if (!batch.empty()) {
-               view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
-       }
+       return &guiApp->createView(width, height, posx, posy, maximize);
+}
 
-       Gtk::Main::run();
 
-       // FIXME: breaks emergencyCleanup
-       delete lyxsocket;
-       delete lyxserver;
+int lyx_gui::start(LyXView *, string const & batch)
+{
+       return guiApp->start(batch);
 }
 
 
-void lyx_gui::exit()
+void lyx_gui::exit(int status)
 {
-       Gtk::Main::quit();
+       guiApp->exit(status);
 }
 
 
@@ -160,10 +134,6 @@ FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
 {
        FuncStatus flag;
        switch (ev.action) {
-       case LFUN_DIALOG_SHOW:
-               if (ev.argument == "preamble")
-                       flag.unknown(true);
-               break;
        case LFUN_TOOLTIPS_TOGGLE:
                flag.unknown(true);
                break;
@@ -175,23 +145,44 @@ FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
 }
 
 
-string const lyx_gui::hexname(LColor_color col)
+bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
 {
        Gdk::Color gdkColor;
        Gdk::Color * gclr = colorCache.getColor(col);
        if (!gclr) {
                gclr = &gdkColor;
-               gclr->parse(lcolor.getX11Name(col));
+               if(!gclr->parse(lcolor.getX11Name(col))) {
+                       rgbcol.r = 0;
+                       rgbcol.g = 0;
+                       rgbcol.b = 0;
+                       return false;
+               }
        }
 
-       std::ostringstream os;
-
        // Note that X stores the RGB values in the range 0 - 65535
        // whilst we require them in the range 0 - 255.
+       rgbcol.r = gclr->get_red() / 256;
+       rgbcol.g = gclr->get_green() / 256;
+       rgbcol.b = gclr->get_blue() / 256;
+       return true;
+}
+
+
+string const lyx_gui::hexname(LColor_color col)
+{
+       lyx::RGBColor rgbcol;
+       if (!getRGBColor(col, rgbcol)) {
+               lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
+                      << '"' << std::endl;
+               return string();
+       }
+
+       std::ostringstream os;
+
        os << std::setbase(16) << std::setfill('0')
-          << std::setw(2) << (gclr->get_red() / 256)
-          << std::setw(2) << (gclr->get_green() / 256)
-          << std::setw(2) << (gclr->get_blue() / 256);
+          << std::setw(2) << rgbcol.r
+          << std::setw(2) << rgbcol.g
+          << std::setw(2) << rgbcol.b;
 
        return os.str();
 }