From 802d3221e0dae22037262d4185f5e671b86064ba Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 26 Jun 2000 15:33:13 +0000 Subject: [PATCH] Lior's color patch; other small things git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@837 a592a061-630c-0410-9148-cb99ea01b6c8 --- ANNOUNCE | 1 + ChangeLog | 22 ++++++++++++++++++++++ configure.in | 6 ++++++ images/redo_bw.xpm | 25 +++++++++++++++++++++++++ images/undo_bw.xpm | 25 +++++++++++++++++++++++++ lib/lyxrc.example | 6 ++++++ lib/reLyX/configure.in | 6 ++++++ src/ColorHandler.C | 28 ++++++++++++++++++++++++++++ src/ColorHandler.h | 3 +++ src/LColor.C | 17 +++++++++++++++++ src/LColor.h | 2 ++ src/LyXAction.C | 1 + src/commandtags.h | 1 + src/lyxfunc.C | 25 +++++++++++++++++++++++++ src/lyxrc.C | 29 +++++++++++++++++++++++++++++ 15 files changed, 197 insertions(+) create mode 100644 images/redo_bw.xpm create mode 100644 images/undo_bw.xpm diff --git a/ANNOUNCE b/ANNOUNCE index bcd4d48a8b..ba1153e4a5 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -60,6 +60,7 @@ with mirrors at ftp://alpha.tat.physik.uni-tuebingen.de/pub/lyx ftp://ftp.lip6.fr/pub/lyx/ + ftp://ftp.chg.ru/packages/lyx/ ftp://ftp.sdsc.edu/pub/other/lyx/ ftp://ftp.fciencias.unam.mx/pub/Lyx/ ftp://mirror.aarnet.edu.au/pub/LyX/ diff --git a/ChangeLog b/ChangeLog index 49ef11e540..74e3a757a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-06-26 Lior Silberman + + * src/lyxrc.C: + * lib/lyxrc.example: new lyxrc tag \set_color. + + * src/lyxfunc.C (Dispatch): + * src/commandtags.h: + * src/LyXAction.C: new lyxfunc "set-color". + + * src/LColor.[Ch] (setColor): new method to set colors from a lyxname + and an x11name given as strings. + + * src/ColorHandler.[Ch] (updateColor): new method. Updates the GC + cache when a color is changed. + 2000-06-26 Juergen Vigna * src/lyxrow.C (width): added this functions and variable. @@ -9,6 +24,13 @@ 2000-06-26 Jean-Marc Lasgouttes + * images/undo_bw.xpm: new icon. + * images/redo_bw.xpm: ditto. + + * configure.in (INSTALL_SCRIPT): change value to + ${INSTALL} to avoid failures of install-script target. + * lib/reLyX/configure.in (INSTALL_SCRIPT): ditto + * src/BufferView.h: add a magic "friend" declaration to please compaq cxx. diff --git a/configure.in b/configure.in index 84029dc4bd..4a0dfa76c0 100644 --- a/configure.in +++ b/configure.in @@ -42,6 +42,12 @@ if test "x$KPSEWHICH" = xkpsewhich ; then [Define this if you have the kpsewhich program working on your system.]) fi +# Work around a problem in automake 1.4: when invoking install-strip, +# INSTALL_PROGRAM is changed to 'install -s', and since +# INSTALL_SCRIPT==INSTALL_PROGRAM, we get errors with fileutils-4.0 +# which returns an error condition when stripping fails. +INSTALL_SCRIPT='${INSTALL}' + ### we will also need a C compiler to compile GNU gettext AC_PROG_CC diff --git a/images/redo_bw.xpm b/images/redo_bw.xpm new file mode 100644 index 0000000000..bebc8e7f7c --- /dev/null +++ b/images/redo_bw.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char const * redo_bw_xpm[] = { +"20 20 2 1", +" c #BFBFBFBFBFBF", +". c black", +" ", +" ", +" ", +" ", +" ", +" ", +" ...... ", +" .. .. ", +" .. .. . ", +" .. .. .. ", +" .. .... ", +" . .... ", +" ..... ", +" ...... ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/images/undo_bw.xpm b/images/undo_bw.xpm new file mode 100644 index 0000000000..1d68d8553c --- /dev/null +++ b/images/undo_bw.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char const * undo_bw_xpm[] = { +"20 20 2 1", +" c #BFBFBFBFBFBF", +". c black", +" ", +" ", +" ", +" ", +" ", +" ", +" ...... ", +" .. .. ", +" . .. .. ", +" .. .. .. ", +" .... .. ", +" .... . ", +" ..... ", +" ...... ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/lib/lyxrc.example b/lib/lyxrc.example index e41ac1bd09..6066417547 100644 --- a/lib/lyxrc.example +++ b/lib/lyxrc.example @@ -255,6 +255,12 @@ # This is the default in LyX (exactly what LaTeX does): #\screen_font_sizes 5.0 7.0 8.0 9.0 10.0 12.0 14.4 17.28 20.74 24.88 +# To change the colors for footnotes: +#\set_color footnote green +# for mathed you may also want to change the coloring of lines and brackets: +#\set_color math yellow +#\set_color mathlines yellow + # # TOOLBAR SECTION ######################################################## # diff --git a/lib/reLyX/configure.in b/lib/reLyX/configure.in index b1ffdf0d7d..f59fec50ad 100644 --- a/lib/reLyX/configure.in +++ b/lib/reLyX/configure.in @@ -26,6 +26,12 @@ test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' LYX_DIR=`eval "echo \`eval \"echo ${datadir}/${PACKAGE}\"\`"` AC_SUBST(LYX_DIR) +# Work around a problem in automake 1.4: when invoking install-strip, +# INSTALL_PROGRAM is changed to 'install -s', and since +# INSTALL_SCRIPT==INSTALL_PROGRAM, we get errors with fileutils-4.0 +# which returns an error condition when stripping fails. +INSTALL_SCRIPT='${INSTALL}' + dnl Checks for programs. AC_PROG_INSTALL RELYX_CHECK_PERL diff --git a/src/ColorHandler.C b/src/ColorHandler.C index 5b2571fbdd..48aea3a9ca 100644 --- a/src/ColorHandler.C +++ b/src/ColorHandler.C @@ -195,5 +195,33 @@ GC LyXColorHandler::getGCLinepars(PainterBase::line_style ls, GCCapStyle | GCJoinStyle | GCFunction, &val); } +// update GC cache after color redefinition +void LyXColorHandler::updateColor (LColor::color c) +{ + // color GC cache + GC gc = colorGCcache[c]; + if (gc != NULL) { + XFreeGC(display, gc); + colorGCcache[c] = NULL; + getGCForeground(c); + } + + // line GC cache + + int index, ls, lw; + for (ls=0; ls<3; ++ls) + for (lw=0; lw<2; ++lw) { + index = lw + (ls << 1) + (c << 3); + if (lineGCcache.find(index) != lineGCcache.end()) { + gc = lineGCcache[index]; + XFreeGC(display,gc); + lineGCcache.erase(index); + getGCLinepars(PainterBase::line_style(ls), + PainterBase::line_width(lw), c); + } + } + +} + // LyXColorHandler * lyxColorHandler; diff --git a/src/ColorHandler.h b/src/ColorHandler.h index f868fbfb34..b9e2640839 100644 --- a/src/ColorHandler.h +++ b/src/ColorHandler.h @@ -42,6 +42,9 @@ public: /// GC getGCLinepars(PainterBase::line_style, PainterBase::line_width, LColor::color c); + /// update the cache after a color definition change + void updateColor(LColor::color c); + private: /// Display * display; diff --git a/src/LColor.C b/src/LColor.C index c4763d8f72..1677790393 100644 --- a/src/LColor.C +++ b/src/LColor.C @@ -22,6 +22,7 @@ #include "gettext.h" #include "support/lstrings.h" +using std::endl; void LColor::fill(LColor::color col, string const & gui, string const & latex, string const & x11, @@ -171,6 +172,22 @@ void LColor::setColor(LColor::color col, string const & x11name) } +bool LColor::setColor(string const & lyxname, string const & x11name) +{ + color col = getFromLyXName (lyxname); + + // "inherit" is returned for colors not in the database + // (and anyway should not be redefined) + if (col == inherit || col == ignore) { + lyxerr << "Color " << lyxname << " is undefined or may not be" + " redefined" << endl; + return false; + } + setColor (col, x11name); + return true; +} + + LColor::color LColor::getFromGUIName(string const & guiname) const { InfoTab::const_iterator ici = infotab.begin(); diff --git a/src/LColor.h b/src/LColor.h index 4fc25de94d..1875816b78 100644 --- a/src/LColor.h +++ b/src/LColor.h @@ -173,6 +173,8 @@ public: LColor(); /// void setColor(LColor::color col, string const & x11name); + /// + bool setColor(string const & lyxname, string const & x11name); /// Get GUI name of color string getGUIName(LColor::color c) const; diff --git a/src/LyXAction.C b/src/LyXAction.C index 701c520d96..3cc0237afd 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -393,6 +393,7 @@ void LyXAction::init() { LFUN_UPCASE_WORD, "word-upcase", "", Noop }, { LFUN_DATE_INSERT, "date-insert", "", Noop }, { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", "", Noop }, + { LFUN_SET_COLOR, "set-color", "", Noop }, { LFUN_NOACTION, "", "", Noop } }; diff --git a/src/commandtags.h b/src/commandtags.h index 06c95a909b..91fca71d90 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -253,6 +253,7 @@ enum kb_action { LFUN_LOFVIEW, // Dekel 20000519 LFUN_LOTVIEW, // Dekel 20000519 LFUN_LOAVIEW, // Dekel 20000519 + LFUN_SET_COLOR, // SLior 20000611 LFUN_INSET_EXTERNAL, // Alstrup 20000609 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index f23bd3f3c8..02c3c25452 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -32,6 +32,7 @@ using std::istringstream; #include "kbmap.h" #include "lyxfunc.h" #include "bufferlist.h" +#include "ColorHandler.h" #include "lyxserver.h" #include "lyx.h" #include "intl.h" @@ -2601,6 +2602,30 @@ string LyXFunc::Dispatch(int ac, } break; + case LFUN_SET_COLOR: + { + string lyx_name, x11_name; + x11_name = split(argument, lyx_name, ' '); + if (lyx_name.empty() || x11_name.empty()) { + LyXBell(); + setErrorMessage(N_("Syntax: set-color " + " ")); + break; + } + + if (!lcolor.setColor(lyx_name, x11_name)) { + static string err1 (N_("Set-color \"")); + static string err2 (N_("\" failed - color is undefined " + "or may not be redefined")); + LyXBell(); + setErrorMessage(err1 + lyx_name + err2); + break; + } + lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name)); + owner->view()->redraw(); + break; + } + case LFUN_UNKNOWN_ACTION: { if(!owner->buffer()) { diff --git a/src/lyxrc.C b/src/lyxrc.C index f7359f6e5a..4533ac0875 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -85,6 +85,7 @@ enum LyXRCTags { RC_SCREEN_FONT_POPUP, RC_SCREEN_FONT_ENCODING, RC_SCREEN_FONT_ENCODING_MENU, + RC_SET_COLOR, RC_AUTOSAVE, RC_DOCUMENTPATH, RC_TEMPLATEPATH, @@ -250,6 +251,7 @@ keyword_item lyxrcTags[] = { { "\\screen_font_typewriter", RC_SCREEN_FONT_TYPEWRITER }, { "\\screen_zoom", RC_SCREEN_ZOOM }, { "\\serverpipe", RC_SERVERPIPE }, + { "\\set_color", RC_SET_COLOR }, { "\\show_banner", RC_SHOW_BANNER }, { "\\spell_command", RC_SPELL_COMMAND }, { "\\tempdir_path", RC_TEMPDIRPATH }, @@ -837,6 +839,30 @@ int LyXRC::read(string const & filename) font_norm_menu = lexrc.GetString(); break; + case RC_SET_COLOR: + { + string lyx_name, x11_name; + + if (lexrc.lex() == LyXLex::LEX_DATA) { + lyx_name = lexrc.GetString(); + } else { + lexrc.printError("Bad color tag: `$$Token'"); + break; + } + + if (lexrc.lex() == LyXLex::LEX_DATA) { + x11_name = lexrc.GetString(); + } else { + lexrc.printError("Bad color name: `$$Token'"); + break; + } + + if (!lcolor.setColor(lyx_name, x11_name)) + lyxerr << "Bad lyxrc set_color for " + << lyx_name << endl; + + break; + } case RC_AUTOREGIONDELETE: // Auto region delete defaults to true if (lexrc.next()) @@ -1043,6 +1069,7 @@ int LyXRC::read(string const & filename) if ( lexrc.next()) docbook_to_pdf_command = lexrc.GetString(); break; + case RC_LAST: break; // this is just a dummy } } @@ -1101,6 +1128,8 @@ void LyXRC::output(ostream & os) const // bind files are not done here. case RC_BEGINTOOLBAR: // Toolbar is not written here (yet). + case RC_SET_COLOR: + // color bindings not written to preference file. case RC_FONT_ENCODING: os << "\\font_encoding \"" << fontenc << "\"\n"; case RC_PRINTER: -- 2.39.5