From cb8bb668e768b6e13863a0988779070297e33e6d Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 24 Jul 2001 10:13:19 +0000 Subject: [PATCH] playing around with insets git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2315 a592a061-630c-0410-9148-cb99ea01b6c8 --- NEWS | 4 ++-- lib/examples/fr_splash.lyx | 22 ++++++++++----------- src/ChangeLog | 13 +++++++++++++ src/Painter.h | 2 +- src/PainterBase.h | 2 +- src/insets/ChangeLog | 31 ++++++++++++++++++++++++++++++ src/insets/inset.C | 18 ++++++++++++++++++ src/insets/inset.h | 9 ++++++++- src/insets/insetcollapsable.C | 5 ++++- src/insets/insetert.C | 28 ++++++++++++--------------- src/insets/insetert.h | 3 +++ src/insets/insetlatexaccent.C | 5 +++-- src/insets/insetminipage.C | 2 ++ src/insets/insetnote.C | 9 ++++++++- src/insets/insettabular.C | 8 +++++--- src/insets/insettext.C | 11 ++++++++--- src/insets/insettext.h | 3 +++ src/lyxtext.h | 11 +++-------- src/text.C | 36 +++++++++++++++++++++++------------ 19 files changed, 159 insertions(+), 63 deletions(-) diff --git a/NEWS b/NEWS index d5f065f6eb..701326eb66 100644 --- a/NEWS +++ b/NEWS @@ -18,8 +18,8 @@ Switch to the so-called 'new' insets: - TeX mode has been superseded by the 666 (aka ERT) inset, which is foldable -- new graphics inset superseding the older figure inset [will that be - OK in 1.2.0?] +- new graphics inset with support for hassle-free inclusion of various + image formats (GIF, JPEG, PNG and EPS by default). - new minipage inset diff --git a/lib/examples/fr_splash.lyx b/lib/examples/fr_splash.lyx index 8edd821d67..f8d1919135 100644 --- a/lib/examples/fr_splash.lyx +++ b/lib/examples/fr_splash.lyx @@ -27,7 +27,7 @@ Bienvenue dans l'univers de LyX ! \begin_inset Info Informations de révision : -Traduction : Mise à jour, Date: 2001/02/16 +Traduction : Mise à jour, Date: 2001/06/10 Original : Révision: 1.5, Date: 2000/12/28 \end_inset @@ -37,8 +37,8 @@ Original : R Le Top N des choses à connaître pour utiliser LyX \layout Enumerate -LyX est fourni avec une excellente documentation -- servez-vous-en s'il - vous plaît ! Vous pouvez commencer par +LyX est fourni avec une excellente documentation -- servez-vous-en donc + ! Vous pouvez commencer par \family sans \bar under A @@ -58,10 +58,9 @@ A \bar default ide\SpecialChar \menuseparator Manuel\SpecialChar ~ -d'Apprentissage. - +d'Apprentissage \family default -Seul le titre des autres documents est traduit en français pour le moment. +. \layout Enumerate LyX est ce qu'on appelle un @@ -76,7 +75,7 @@ LyX est ce qu'on appelle un Par sa conception, il se distingue des traitements de texte ordinaires -- en ce sens qu'il facilite l'écriture des documents. Mais la distinction est minime, ne vous inquiétez pas. - La documentation est là pour faire toute la lumière la-dessus + La documentation est là pour faire toute la lumière là-dessus \begin_float footnote \layout Standard @@ -85,8 +84,7 @@ Avons-nous d . \layout Enumerate -Les résultats de mise en page de LyX sont très esthétiques ! Sélectionnez - +Les résultats de mise en page de LyX sont très esthétiques ! Faites \family sans \bar under V @@ -122,15 +120,15 @@ d'Apprentissage \layout Enumerate LyX possède de nombreuses fonctionnalités pour ceux qui lisent ou écrivent - d'autres langages que l'anglais. - De plus, le clavier, la barre d'outils et beaucoup d'autres caractéristiques + dans d'autres langues que l'anglais. + En outre, le clavier, la barre d'outils et beaucoup d'autres caractéristiques sont pleinement configurables (pour la plupart en éditant votre fichier \family typewriter lyxrc \family default ). - Voir le fichier + Voir \family sans \bar under A diff --git a/src/ChangeLog b/src/ChangeLog index 12b51084e6..047e57ebd0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2001-07-24 Jean-Marc Lasgouttes + + * lyxtext.h: remove unused (and unimplemented) methods + +2001-07-23 Jean-Marc Lasgouttes + + * text.C (getVisibleRow): honor background color + + * PainterBase.h: + * Painter.h: remove default color argument for fillRectangle + + * text.C (backgroundColor): new method + 2001-07-24 Lars Gullik Bjønnes * text.C (getVisibleRow): adjust diff --git a/src/Painter.h b/src/Painter.h index ba001988a4..f6dad96bbc 100644 --- a/src/Painter.h +++ b/src/Painter.h @@ -74,7 +74,7 @@ public: /// Fill a rectangle PainterBase & fillRectangle(int x, int y, int w, int h, - LColor::color = LColor::background); + LColor::color); /// For the graphics inset. PainterBase & image(int x, int y, int w, int h, LyXImage const * image); diff --git a/src/PainterBase.h b/src/PainterBase.h index 71a39f987f..237f7f13d1 100644 --- a/src/PainterBase.h +++ b/src/PainterBase.h @@ -137,7 +137,7 @@ public: /// Fill a rectangle virtual PainterBase & fillRectangle( int x, int y, int w, int h, - LColor::color = LColor::background) = 0; + LColor::color) = 0; /// A filled rectangle with the shape of a 3D button virtual PainterBase & button(int x, int y, int w, int h); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 3ea458ea18..c3750d95d5 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,34 @@ +2001-07-24 Jean-Marc Lasgouttes + + * insetminipage.C (InsetMinipage): set background color to red :) + +2001-07-23 Jean-Marc Lasgouttes + + * insettext.C (insetUnlock): only set update to CLEAR_FRAME if + draw frame mode is LOCKED. + + * insetcollapsable.C (edit): + (insetButtonRelease): set update status to full when + opening inset. + + * insettext.C (clearInset): + * insettabular.C (draw): + * insetlatexaccent.C (draw): honor background color. + + * inset.h: new member background_color_, initialized to + LColor::inherit. + + * inset.C (backgroundColor): new method. + (setBackgroundColor): new method. + + * insetert.C (init): new method, called by the ctors. + (InsetERT): when inserting contents, make sure the font is + ALL_INHERIT. + + * insetnote.C (InsetNote): when inserting content, remove trailing + newline + (init): set background color to LColor::note + 2001-07-24 Lars Gullik Bjønnes * insetcollapsable.C: adjust diff --git a/src/insets/inset.C b/src/insets/inset.C index 315cf2444c..581006f0cb 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -90,6 +90,24 @@ LyXText * Inset::getLyXText(BufferView const * bv, bool const) const } +void Inset::setBackgroundColor(LColor::color color) +{ + background_color_ = color; +} + + +LColor::color Inset::backgroundColor() const +{ + if (background_color_ == LColor::inherit) { + if (owner()) + return owner()->backgroundColor(); + else + return LColor::background; + } else + return background_color_; +} + + int Inset::id() const { return id_; diff --git a/src/insets/inset.h b/src/insets/inset.h index c309e60a53..550c6cee31 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -19,6 +19,7 @@ #include "LString.h" #include #include "commandtags.h" +#include "LColor.h" class LyXFont; class BufferView; @@ -128,7 +129,7 @@ public: }; /// - Inset() : top_x(0), top_baseline(0), scx(0), id_(inset_id++), owner_(0) {} + Inset() : top_x(0), top_baseline(0), scx(0), id_(inset_id++), owner_(0), background_color_(LColor::inherit) {} /// Virtual base destructor virtual ~Inset() {} /// @@ -225,6 +226,10 @@ public: /// Inset * owner() const { return owner_; } /// + void setBackgroundColor(LColor::color); + /// + LColor::color backgroundColor() const; + /// int x() const { return top_x; } /// int y() const { return top_baseline; } @@ -288,6 +293,8 @@ private: Inset * owner_; /// string name; + /// + LColor::color background_color_; }; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index a5149e020f..5739b50801 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -289,6 +289,7 @@ void InsetCollapsable::edit(BufferView * bv, bool front) collapsed_ = false; if (!bv->lockInset(this)) return; + inset.setUpdateStatus(bv, InsetText::FULL); bv->updateInset(this, false); inset.edit(bv, front); } else { @@ -347,6 +348,7 @@ void InsetCollapsable::insetButtonRelease(BufferView * bv, draw_label = label; collapsed_ = false; inset.insetButtonRelease(bv, 0, 0, button); + inset.setUpdateStatus(bv, InsetText::FULL); bv->updateInset(this, false); } else { if (change_label_with_text) { @@ -620,8 +622,9 @@ void InsetCollapsable::setLabel(string const & l, bool flag) string InsetCollapsable::get_new_label() const { string la; + Paragraph::size_type const max_length = 10; - int n = std::min(10, inset.paragraph()->size()); + int n = std::min(max_length, inset.paragraph()->size()); int i,j; for(i=0,j=0; i < n && j < inset.paragraph()->size(); ++j) { if (inset.paragraph()->isInset(j)) diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 4c76ca4c5f..acd54a0653 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -23,37 +23,33 @@ using std::ostream; -InsetERT::InsetERT() : InsetCollapsable() +void InsetERT::init() { setLabel(_("666"), true); - //LyXFont font(LyXFont::ALL_SANE); - //font.setLatex (LyXFont::ON); labelfont = LyXFont(LyXFont::ALL_SANE); labelfont.decSize(); labelfont.decSize(); +#ifndef NO_LATEX + labelfont.setLatex(LyXFont::ON); +#else labelfont.setColor(LColor::latex); +#endif setAutoCollapse(false); setInsetName("ERT"); } +InsetERT::InsetERT() : InsetCollapsable() +{ + init(); +} + InsetERT::InsetERT(string const & contents, bool collapsed) : InsetCollapsable(collapsed) { - setLabel(_("666")); - LyXFont font(LyXFont::ALL_SANE); -#ifndef NO_LATEX - font.setLatex(LyXFont::ON); -#else - font.setColor(LColor::latex); -#endif - labelfont = LyXFont(LyXFont::ALL_SANE); - labelfont.decSize(); - labelfont.decSize(); - labelfont.setColor(LColor::latex); - setAutoCollapse(false); - setInsetName("ERT"); + init(); + LyXFont const font(LyXFont::ALL_INHERIT); string::const_iterator cit = contents.begin(); string::const_iterator end = contents.end(); Paragraph::size_type pos = 0; diff --git a/src/insets/insetert.h b/src/insets/insetert.h index f6a0ebde9d..116c2e9075 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -58,6 +58,9 @@ public: virtual int linuxdoc(Buffer const *, std::ostream &) const; /// virtual int docBook(Buffer const *, std::ostream &) const; +private: + /// + void init(); }; #endif diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index ccd8401ebf..3709a847bd 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -409,7 +409,7 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, pain.fillRectangle(int(x + tmpx), tmpvar, wid, lyxfont::ascent('i', font) - lyxfont::ascent('x', font) - 1, - LColor::background); + backgroundColor()); // the five lines below is a simple hack to // make the display of accent 'i' and 'j' // better. It makes the accent be written @@ -602,7 +602,8 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, baseline - ascent(bv, font) + 1, width(bv, font) - 2, ascent(bv, font) - + descent(bv, font) - 2); + + descent(bv, font) - 2, + backgroundColor()); pain.rectangle(int(x + 1), baseline - ascent(bv, font) + 1, width(bv, font) - 2, ascent(bv, font) + descent(bv, font) - 2); diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 1f3ee2e054..3c357d1afe 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -69,6 +69,8 @@ InsetMinipage::InsetMinipage() font.setColor(LColor::collapsable); setLabelFont(font); setAutoCollapse(false); + // just for experimentation :) + setBackgroundColor(LColor::red); setInsetName("Minipage"); width_ = "100%"; // set default to 100% of column_width } diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 89ac827f58..c8945ee3c8 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -22,6 +22,7 @@ #include "lyxtext.h" #include "insets/insettext.h" #include "support/LOstream.h" +#include "support/lstrings.h" #include "debug.h" using std::ostream; @@ -32,18 +33,22 @@ void InsetNote::init() font.decSize(); font.setColor(LColor::note); setLabelFont(font); + setAutoCollapse(false); + setBackgroundColor(LColor::note); setLabel(_("note")); setInsetName("Note"); } + InsetNote::InsetNote() : InsetCollapsable() { init(); } + InsetNote::InsetNote(Buffer const * buf, string const & contents, bool collapsed) : InsetCollapsable(collapsed) @@ -52,9 +57,11 @@ InsetNote::InsetNote(Buffer const * buf, string const & contents, Paragraph * par = inset.paragraph(); Paragraph::size_type pos = 0; - buf->insertStringAsLines(par, pos, labelfont, contents); + buf->insertStringAsLines(par, pos, LyXFont(LyXFont::ALL_INHERIT), + strip(contents, '\n')); } + Inset * InsetNote::clone(Buffer const &, bool same_id) const { InsetNote * result = new InsetNote; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index ecd4b885de..26607fed2a 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -259,7 +259,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, h = pain.paperHeight(); if ((top_x + w) > pain.paperWidth()) w = pain.paperWidth(); - pain.fillRectangle(tx, ty, w, h); + pain.fillRectangle(tx, ty, w, h, backgroundColor()); need_update = FULL; cleared = true; } @@ -366,7 +366,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, baseline - tabular->GetAscentOfRow(i) + 1, int(cx - nx - 1), tabular->GetAscentOfRow(i) + - tabular->GetDescentOfRow(i) - 1); + tabular->GetDescentOfRow(i) - 1, + backgroundColor()); // clear behind the inset pain.fillRectangle( int(cx + the_locking_inset->width(bv,font) + 1), @@ -376,7 +377,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, the_locking_inset->width(bv,font) - tabular->GetAdditionalWidth(cell) - 1, tabular->GetAscentOfRow(i) + - tabular->GetDescentOfRow(i) - 1); + tabular->GetDescentOfRow(i) - 1, + backgroundColor()); } } x -= ADD_TO_TABULAR_WIDTH; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 17f6610888..29c8cba48d 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -472,7 +472,7 @@ void InsetText::clearFrame(Painter & pain, bool cleared) const if (!cleared) { pain.rectangle(top_x + 1, top_baseline - insetAscent + 1, insetWidth - 1, insetAscent + insetDescent - 1, - LColor::background); + backgroundColor()); } frame_is_visible = false; } @@ -667,7 +667,11 @@ void InsetText::insetUnlock(BufferView * bv) hideInsetCursor(bv); no_selection = false; locked = false; - int code = CURSOR|CLEAR_FRAME; + int code; + if (drawFrame_ == LOCKED) + code = CURSOR|CLEAR_FRAME; + else + code = CURSOR; bool clear = false; if (!lt) { lt = getLyXText(bv); @@ -1941,7 +1945,8 @@ void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const h = pain.paperHeight(); if ((top_x + drawTextXOffset + w) > pain.paperWidth()) w = pain.paperWidth(); - pain.fillRectangle(top_x+drawTextXOffset, ty, w, h); + pain.fillRectangle(top_x+drawTextXOffset, ty, w, h, + backgroundColor()); cleared = true; need_update = FULL; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 7bb3355b02..1b0388a341 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -289,8 +289,11 @@ private: UpdatableInset::RESULT moveDown(BufferView *); /// void setCharFont(Buffer const *, int pos, LyXFont const & font); +#if 0 + ///What's that ??? Not used, not implemented! /// string const getText(int); +#endif /// bool checkAndActivateInset(BufferView * bv, bool behind); /// diff --git a/src/lyxtext.h b/src/lyxtext.h index 87d6b78c4b..0cb33eac0d 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -22,6 +22,7 @@ #include "layout.h" #include "lyxrow.h" #include "vspace.h" +#include "LColor.h" class Buffer; class BufferParams; @@ -392,14 +393,6 @@ public: void copyEnvironmentType(); /// void pasteEnvironmentType(BufferView *); - /// - void insertFootnote(); - /// - void insertMarginpar(); - /// - void insertFigure(); - /// - void insertTabular(); /** the DTP switches for paragraphs. LyX will store the top settings always in the first physical paragraph, the bottom settings in the @@ -606,6 +599,8 @@ private: */ bool hfillExpansion(Buffer const *, Row const * row_ptr, Paragraph::size_type pos) const; + /// + LColor::color backgroundColor(); /// diff --git a/src/text.C b/src/text.C index 8d49945013..c6b00c4e65 100644 --- a/src/text.C +++ b/src/text.C @@ -1159,6 +1159,14 @@ bool LyXText::hfillExpansion(Buffer const * buf, Row const * row_ptr, } +LColor::color LyXText::backgroundColor() +{ + if (inset_owner) + return inset_owner->backgroundColor(); + else + return LColor::background; +} + void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const { /* get the maximum ascent and the maximum descent */ @@ -2938,25 +2946,29 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset, int const w = inset_owner ? inset_owner->width(bview, font) - 2 : ww; int const x = x_offset; - pain.fillRectangle(x, y, w, h); + pain.fillRectangle(x, y, w, h, backgroundColor()); } else if (inset != 0) { int h = row_ptr->baseline() - inset->ascent(bview, font); if (h > 0) { int const w = (inset_owner ? inset_owner->width(bview, font) : ww); - pain.fillRectangle(x_offset, y_offset, w, h); + pain.fillRectangle(x_offset, y_offset, w, h, + backgroundColor()); } h += inset->ascent(bview, font) + inset->descent(bview, font); if ((row_ptr->height() - h) > 0) { int const w = (inset_owner ? inset_owner->width(bview, font) : ww); pain.fillRectangle(x_offset, y_offset + h, - w, row_ptr->height() - h); + w, row_ptr->height() - h, + backgroundColor()); } if (!inset_owner && !inset->display() && !inset->needFullRow()) { int const w = inset->width(bview, font) + int(x); - pain.fillRectangle(w, y_offset, ww - w, row_ptr->height()); + pain.fillRectangle(w, y_offset, + ww - w, row_ptr->height(), + backgroundColor()); } } @@ -3158,8 +3170,8 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset, 0, _("Page Break (top)"), pb_font, - LColor::background, - LColor::background, false, w, a, d); + backgroundColor(), + backgroundColor(), false, w, a, d); #else ; lyxfont::rectText(_("Page Break (top)"), pb_font, @@ -3169,8 +3181,8 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset, y_offset + y_top + 2 * defaultHeight() + d, _("Page Break (top)"), pb_font, - LColor::background, - LColor::background); + backgroundColor(), + backgroundColor()); y_top += 3 * defaultHeight(); } @@ -3354,8 +3366,8 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset, .rectText(0, 0, _("Page Break (bottom)"), pb_font, - LColor::background, - LColor::background, false, w, a, d); + backgroundColor(), + backgroundColor(), false, w, a, d); #else ; lyxfont::rectText(_("Page Break (bottom)"), pb_font, @@ -3364,8 +3376,8 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset, pain.rectText((ww - w) / 2, y_place + d, _("Page Break (bottom)"), pb_font, - LColor::background, - LColor::background); + backgroundColor(), + backgroundColor()); y_bottom -= 3 * defaultHeight(); }