From a8e9fe82d0461fa821b3ec70c83fe76f02eafcb0 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Fri, 11 May 2007 02:28:14 +0000 Subject: [PATCH] lib/lyx2lyx/lyx_1_5.py: fix revert of listings insets git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18262 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx_1_5.py | 30 +++++++++++++++++++++++------- src/Color.cpp | 1 + src/Color.h | 4 +++- src/insets/Inset.cpp | 8 ++++---- src/insets/Inset.h | 5 +++++ src/mathed/InsetMathGrid.h | 2 +- src/mathed/InsetMathHull.cpp | 13 +++++++++++-- src/mathed/InsetMathHull.h | 4 +++- src/mathed/MathData.cpp | 5 +++++ 9 files changed, 56 insertions(+), 16 deletions(-) diff --git a/lib/lyx2lyx/lyx_1_5.py b/lib/lyx2lyx/lyx_1_5.py index 97ce96b74d..ae85cf33c6 100644 --- a/lib/lyx2lyx/lyx_1_5.py +++ b/lib/lyx2lyx/lyx_1_5.py @@ -1391,6 +1391,9 @@ lstinline[language=Delphi]{var i = 10;} i = find_token(document.body, '\\begin_inset listings', i) if i == -1: break + else: + if not '\\usepackage{listings}' in document.preamble: + document.preamble.append('\\usepackage{listings}') j = find_end_of_inset(document.body, i + 1) if j == -1: # this should not happen @@ -1410,31 +1413,41 @@ lstinline[language=Delphi]{var i = 10;} k = line + 1 # looking for the oneline code for lstinline for line in range(i + 2, j + 1): - if document.body[line].startswith(r'\begin_layout'): - inlinecode = document.body[line+1] + if document.body[line].startswith(r'\end_layout'): + inlinecode = document.body[line - 1] break + if len(params) > 0: + params = '[%s]' % params if inline == 'true': - document.body[i:(j+1)] = [r'\begin_inset ERT' + document.body[i:(j+1)] = [r'\begin_inset ERT', 'status %s' % status, r'\begin_layout Standard', '', '', r'\backslash', - 'lstinline[%s]{%s}' % (params, inlinecode), + 'lstinline%s{%s}' % (params, inlinecode), r'\end_layout', '', r'\end_inset'] else: - document.body[i: k] = [r'\begin_inset ERT', + document.body[i: j+1] = [r'\begin_inset ERT', 'status %s' % status, '', r'\begin_layout Standard', '', '', r'\backslash', - r'lstlisting[%s]{' % params, + r'begin{lstlisting}%s' % params, r'\end_layout' - ] + ] + document.body[k : j - 1] + \ + ['', + r'\begin_layout Standard', + '', + r'\backslash', + 'end{lstlisting}', + r'\end_layout', + '', + r'\end_inset'] def revert_include_listings(document): @@ -1464,6 +1477,9 @@ lstinputlisting{file}[opt] i = find_token(document.body, r'\begin_inset Include \lstinputlisting', i) if i == -1: break + else: + if not '\\usepackage{listings}' in document.preamble: + document.preamble.append('\\usepackage{listings}') j = find_end_of_inset(document.body, i + 1) if j == -1: # this should not happen diff --git a/src/Color.cpp b/src/Color.cpp index 3474850fbc..9080907550 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -298,6 +298,7 @@ Color::Color() { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" }, { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" }, { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" }, + { mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" }, { mathline, N_("math line"), "mathline", "Blue", "mathline" }, { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" }, { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" }, diff --git a/src/Color.h b/src/Color.h index b2a43b7784..372c1a5025 100644 --- a/src/Color.h +++ b/src/Color.h @@ -123,8 +123,10 @@ public: mathbg, /// Macro math inset background color mathmacrobg, - /// Math inset frame color + /// Math inset frame color under focus mathframe, + /// Math inset frame color not under focus + mathcorners, /// Math line color mathline, diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 93b749e5d8..aa9778c0e1 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -117,12 +117,12 @@ static TranslatorMap const build_translator() /// pretty arbitrary dimensions Inset::Inset() - : dim_(10, 10, 10), background_color_(Color::background) + : dim_(10, 10, 10), background_color_(Color::background), redraw_background_(true) {} Inset::Inset(Inset const & inset) - : dim_(inset.dim_), background_color_(inset.background_color_) + : dim_(inset.dim_), background_color_(inset.background_color_), redraw_background_(true) {} @@ -288,7 +288,7 @@ void Inset::metricsMarkers2(Dimension & dim, int framesize) const void Inset::drawMarkers(PainterInfo & pi, int x, int y) const { Color::color pen_color = editing(pi.base.bv)? - Color::mathframe : Color::background; + Color::mathframe : Color::mathcorners; int const t = x + width() - 1; int const d = y + descent(); @@ -303,7 +303,7 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const { Color::color pen_color = editing(pi.base.bv)? - Color::mathframe : Color::background; + Color::mathframe : Color::mathcorners; drawMarkers(pi, x, y); int const t = x + width() - 1; diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 3eb44fedaa..1601ddb42e 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -192,6 +192,9 @@ public: /// is called when the mouse enter or leave this inset /// return true if this inset needs repaint virtual bool setMouseHover(bool) { return false; } + /// tells an inset to redraw background + virtual void setRedrawBackground(bool rd) const { redraw_background_ = rd; } + bool redrawBackground() const { return redraw_background_; } /// request "external features" virtual void validate(LaTeXFeatures &) const {} @@ -489,6 +492,8 @@ private: * of the header file. */ int background_color_; + + mutable bool redraw_background_; }; diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 3faa33f4ea..5735600fcc 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -214,7 +214,7 @@ public: void mathmlize(MathStream &) const; /// //void octave(OctaveStream &) const; - + /// tells an inset to redraw background protected: virtual void doDispatch(Cursor & cur, FuncRequest & cmd); /// diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 6b9d8d3cce..53cb61de95 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -48,6 +48,7 @@ #include "insets/RenderPreview.h" #include "insets/InsetLabel.h" +#include "frontends/Painter.h" #include "graphics/PreviewImage.h" #include "graphics/PreviewLoader.h" @@ -169,7 +170,7 @@ InsetMathHull::InsetMathHull() InsetMathHull::InsetMathHull(HullType type) - : InsetMathGrid(getCols(type), 1), type_(type), nonum_(1), label_(1), + : InsetMathGrid(getCols(type), 1), type_(type), nonum_(1), label_(1), preview_(new RenderPreview(this)) { initMath(); @@ -179,7 +180,7 @@ InsetMathHull::InsetMathHull(HullType type) InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid(other), - type_(other.type_), nonum_(other.nonum_), label_(other.label_), + type_(other.type_), nonum_(other.nonum_), label_(other.label_), preview_(new RenderPreview(this)) {} @@ -333,7 +334,15 @@ bool InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathHull::draw(PainterInfo & pi, int x, int y) const { + // setRedrawBackground(false); use_preview_ = previewState(pi.base.bv); + /*Cursor & cur = pi.base.bv->cursor(); + if (!editing(pi.base.bv) || !cur.selection() || &cur.inset() != this) + */ + lyxerr << "redraw " << x << " " << y << " " << width() << " " << redrawBackground() << std::endl; + if (redrawBackground()) + pi.pain.fillRectangle(x + 1, y - ascent() + 1, width() - 2, + ascent() + descent() - 1, Color::mathbg); if (use_preview_) { // one pixel gap in front diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index f858e76f9c..ccac7575d9 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -15,6 +15,7 @@ #include "InsetMathGrid.h" #include +#include "debug.h" namespace lyx { @@ -120,7 +121,6 @@ public: /// static int displayMargin() { return 12; } - protected: InsetMathHull(InsetMathHull const &); @@ -183,6 +183,8 @@ private: boost::scoped_ptr preview_; /// mutable bool use_preview_; + /// + /// mutable bool redraw_background_; // // Incorporate me // diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index a911cc839a..8e1deaba17 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -310,6 +310,8 @@ void MathData::draw(PainterInfo & pi, int x, int y) const || x >= bv. workWidth()) return; + + for (size_t i = 0, n = size(); i != n; ++i) { MathAtom const & at = operator[](i); #if 0 @@ -331,7 +333,10 @@ void MathData::draw(PainterInfo & pi, int x, int y) const #endif bv.coordCache().insets().add(at.nucleus(), x, y); at->drawSelection(pi, x, y); + at->setRedrawBackground(false); + lyxerr << "selection draw " << x << " " << y << " " << at->redrawBackground() << std::endl; at->draw(pi, x, y); + //at->setRedrawBackground(true); x += at->width(); } }