]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gtk/lyx_gui.C
fix LFUN enum values (some of them were broken by r13801)
[lyx.git] / src / frontends / gtk / lyx_gui.C
index 5053f92aee5de89bc3bfc124a1ebe8ea13a013a8..fef13b1af14eba2e3278b660c60121182f08828c 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"
@@ -87,10 +88,6 @@ bool lyx_gui::use_gui = true;
 
 namespace {
 
-/// quit lyx
-bool finished = false;
-
-
 /// estimate DPI from X server
 int getDPI()
 {
@@ -146,11 +143,7 @@ void lyx_gui::start(string const & batch, std::vector<string> const & files)
                view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
        }
 
-       // enter the event loop
-       while (!finished) {
-               while (Gtk::Main::events_pending())
-                       Gtk::Main::iteration(false);
-       }
+       Gtk::Main::run();
 
        // FIXME: breaks emergencyCleanup
        delete lyxsocket;
@@ -160,7 +153,7 @@ void lyx_gui::start(string const & batch, std::vector<string> const & files)
 
 void lyx_gui::exit()
 {
-       finished = true;
+       Gtk::Main::quit();
 }
 
 
@@ -183,23 +176,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();
 }