]> git.lyx.org Git - features.git/blobdiff - src/frontends/xforms/Color.C
Converter patch from Dekel, Preference patch from Angus, menu patch from Rob
[features.git] / src / frontends / xforms / Color.C
index e69f91fe000f276e0aca596d6c41bf5cad6e1e04..ba09d4d833da983631766f85de37cc65d39e605c 100644 (file)
@@ -10,6 +10,7 @@
  *======================================================*/
 
 #include <config.h>
+#include FORMS_H_LOCATION
 
 #ifdef __GNUG_
 #pragma implementation
 
 #include <algorithm> // max
 #include <cmath> // floor
+#include <fstream> // ofstream
 #include "Color.h"
+#include "lyxlex.h"
 
 using std::max;
 using std::min;
+using std::ofstream;
 
 static int const nohue = -1;
 
-RGB::RGB( HSV const & hsv )
+RGBColor::RGBColor( HSVColor const & hsv )
 {
        double h = hsv.h;
        double s = hsv.s;
@@ -91,7 +95,7 @@ RGB::RGB( HSV const & hsv )
 }
 
 
-HSV::HSV( RGB const & rgb )
+HSVColor::HSVColor( RGBColor const & rgb )
 {
        // r, g, b lie in the range 0-1, not 0-255.
        double r = rgb.r / 255.0;
@@ -128,3 +132,91 @@ HSV::HSV( RGB const & rgb )
        }
 }
 
+
+// sorted by hand to prevent LyXLex from complaining on read().
+static
+keyword_item xformTags[] = {
+//     { "\\gui_active_tab", FL_LIGHTER_COL1 },
+       { "\\gui_background", FL_COL1 },
+       { "\\gui_buttonbottom", FL_BOTTOM_BCOL },
+       { "\\gui_buttonleft", FL_LEFT_BCOL },
+       { "\\gui_buttonright", FL_RIGHT_BCOL },
+       { "\\gui_buttontop", FL_TOP_BCOL },
+       { "\\gui_inactive", FL_INACTIVE },
+       { "\\gui_push_button", FL_YELLOW },
+       { "\\gui_selected", FL_MCOL },  
+       { "\\gui_text", FL_BLACK }
+};
+
+
+static const int xformCount = sizeof(xformTags) / sizeof(keyword_item);
+
+
+bool XformColor::read(string const & filename)
+{
+       LyXLex lexrc( xformTags, xformCount );
+       if( !lexrc.setFile( filename ) )
+               return false;
+
+       while( lexrc.IsOK() ) {
+               int le = lexrc.lex();
+
+               switch( le ) {
+               case LyXLex::LEX_UNDEF:
+                       lexrc.printError("Unknown tag `$$Token'");
+                       continue; 
+               case LyXLex::LEX_FEOF:
+                       continue;
+               default: break;
+               }
+
+               RGBColor col;
+
+               if( !lexrc.next() ) break;
+               col.r = lexrc.GetInteger();
+
+               if( !lexrc.next() ) break;
+               col.g = lexrc.GetInteger();
+
+               if( !lexrc.next() ) break;
+               col.b = lexrc.GetInteger();
+
+               fl_mapcolor(le, col.r, col.g, col.b);
+       }
+       
+       return true;
+}
+
+
+bool XformColor::write(string const & filename)
+{
+       ofstream os(filename.c_str());
+       if (!os)
+               return false;
+
+       os << "### This file is part of\n"
+          << "### ========================================================\n"
+          << "###          LyX, The Document Processor\n"
+          << "###\n"
+          << "###          Copyright 1995 Matthias Ettrich\n"
+          << "###          Copyright 1995-2000 The LyX Team.\n"
+          << "###\n"
+          << "### ========================================================\n"
+          << "\n"
+          << "# This file is written by LyX, if you want to make your own\n"
+          << "# modifications you should do them from inside LyX and save\n"
+          << "\n";
+
+       for( int i = 0; i < xformCount; ++i ) {
+               string tag  = xformTags[i].tag;
+               int colorID = xformTags[i].code;
+               RGBColor color;
+
+               fl_getmcolor(colorID, &color.r, &color.g, &color.b);
+
+               os << tag + " "
+                  << color.r << " " << color.g << " " << color.b << "\n";
+       }
+
+       return true;
+}