Added support for changing label on collapsed InsetERT.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2305 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2001-07-23 12:47:25 +00:00
parent ce36c9bd16
commit 3ea708f4b6
5 changed files with 128 additions and 44 deletions

View File

@ -10,8 +10,8 @@ src/CutAndPaste.C
src/debug.C src/debug.C
src/exporter.C src/exporter.C
src/ext_l10n.h src/ext_l10n.h
src/figureForm.C
src/figure_form.C src/figure_form.C
src/figureForm.C
src/FontLoader.C src/FontLoader.C
src/frontends/controllers/biblio.C src/frontends/controllers/biblio.C
src/frontends/controllers/ButtonController.h src/frontends/controllers/ButtonController.h
@ -90,67 +90,67 @@ src/frontends/qt2/paragraphdlgimpl.C
src/frontends/qt2/tabularcreatedlgimpl.C src/frontends/qt2/tabularcreatedlgimpl.C
src/frontends/xforms/combox.C src/frontends/xforms/combox.C
src/frontends/xforms/FileDialog.C src/frontends/xforms/FileDialog.C
src/frontends/xforms/FormAboutlyx.C
src/frontends/xforms/form_aboutlyx.C src/frontends/xforms/form_aboutlyx.C
src/frontends/xforms/FormBibitem.C src/frontends/xforms/FormAboutlyx.C
src/frontends/xforms/form_bibitem.C src/frontends/xforms/form_bibitem.C
src/frontends/xforms/FormBibtex.C src/frontends/xforms/FormBibitem.C
src/frontends/xforms/form_bibtex.C src/frontends/xforms/form_bibtex.C
src/frontends/xforms/FormBibtex.C
src/frontends/xforms/form_browser.C src/frontends/xforms/form_browser.C
src/frontends/xforms/FormCharacter.C
src/frontends/xforms/form_character.C src/frontends/xforms/form_character.C
src/frontends/xforms/FormCitation.C src/frontends/xforms/FormCharacter.C
src/frontends/xforms/form_citation.C src/frontends/xforms/form_citation.C
src/frontends/xforms/FormDocument.C src/frontends/xforms/FormCitation.C
src/frontends/xforms/form_document.C src/frontends/xforms/form_document.C
src/frontends/xforms/FormError.C src/frontends/xforms/FormDocument.C
src/frontends/xforms/form_error.C src/frontends/xforms/form_error.C
src/frontends/xforms/FormExternal.C src/frontends/xforms/FormError.C
src/frontends/xforms/form_external.C src/frontends/xforms/form_external.C
src/frontends/xforms/FormFiledialog.C src/frontends/xforms/FormExternal.C
src/frontends/xforms/form_filedialog.C src/frontends/xforms/form_filedialog.C
src/frontends/xforms/FormGraphics.C src/frontends/xforms/FormFiledialog.C
src/frontends/xforms/form_graphics.C src/frontends/xforms/form_graphics.C
src/frontends/xforms/FormInclude.C src/frontends/xforms/FormGraphics.C
src/frontends/xforms/form_include.C src/frontends/xforms/form_include.C
src/frontends/xforms/FormIndex.C src/frontends/xforms/FormInclude.C
src/frontends/xforms/form_index.C src/frontends/xforms/form_index.C
src/frontends/xforms/FormIndex.C
src/frontends/xforms/FormLog.C src/frontends/xforms/FormLog.C
src/frontends/xforms/FormMathsBitmap.C src/frontends/xforms/FormMathsBitmap.C
src/frontends/xforms/FormMathsDeco.C
src/frontends/xforms/form_maths_deco.C src/frontends/xforms/form_maths_deco.C
src/frontends/xforms/FormMathsDelim.C src/frontends/xforms/FormMathsDeco.C
src/frontends/xforms/form_maths_delim.C src/frontends/xforms/form_maths_delim.C
src/frontends/xforms/FormMathsMatrix.C src/frontends/xforms/FormMathsDelim.C
src/frontends/xforms/form_maths_matrix.C src/frontends/xforms/form_maths_matrix.C
src/frontends/xforms/FormMathsPanel.C src/frontends/xforms/FormMathsMatrix.C
src/frontends/xforms/form_maths_panel.C src/frontends/xforms/form_maths_panel.C
src/frontends/xforms/FormMathsSpace.C src/frontends/xforms/FormMathsPanel.C
src/frontends/xforms/form_maths_space.C src/frontends/xforms/form_maths_space.C
src/frontends/xforms/FormMinipage.C src/frontends/xforms/FormMathsSpace.C
src/frontends/xforms/form_minipage.C src/frontends/xforms/form_minipage.C
src/frontends/xforms/FormParagraph.C src/frontends/xforms/FormMinipage.C
src/frontends/xforms/form_paragraph.C src/frontends/xforms/form_paragraph.C
src/frontends/xforms/FormPreamble.C src/frontends/xforms/FormParagraph.C
src/frontends/xforms/form_preamble.C src/frontends/xforms/form_preamble.C
src/frontends/xforms/FormPreferences.C src/frontends/xforms/FormPreamble.C
src/frontends/xforms/form_preferences.C src/frontends/xforms/form_preferences.C
src/frontends/xforms/FormPrint.C src/frontends/xforms/FormPreferences.C
src/frontends/xforms/form_print.C src/frontends/xforms/form_print.C
src/frontends/xforms/FormRef.C src/frontends/xforms/FormPrint.C
src/frontends/xforms/form_ref.C src/frontends/xforms/form_ref.C
src/frontends/xforms/FormSearch.C src/frontends/xforms/FormRef.C
src/frontends/xforms/form_search.C src/frontends/xforms/form_search.C
src/frontends/xforms/FormSpellchecker.C src/frontends/xforms/FormSearch.C
src/frontends/xforms/form_spellchecker.C src/frontends/xforms/form_spellchecker.C
src/frontends/xforms/FormTabular.C src/frontends/xforms/FormSpellchecker.C
src/frontends/xforms/form_tabular.C src/frontends/xforms/form_tabular.C
src/frontends/xforms/FormTabularCreate.C src/frontends/xforms/FormTabular.C
src/frontends/xforms/form_tabular_create.C src/frontends/xforms/form_tabular_create.C
src/frontends/xforms/FormToc.C src/frontends/xforms/FormTabularCreate.C
src/frontends/xforms/form_toc.C src/frontends/xforms/form_toc.C
src/frontends/xforms/FormUrl.C src/frontends/xforms/FormToc.C
src/frontends/xforms/form_url.C src/frontends/xforms/form_url.C
src/frontends/xforms/FormUrl.C
src/frontends/xforms/FormVCLog.C src/frontends/xforms/FormVCLog.C
src/frontends/xforms/input_validators.C src/frontends/xforms/input_validators.C
src/frontends/xforms/Menubar_pimpl.C src/frontends/xforms/Menubar_pimpl.C
@ -171,6 +171,7 @@ src/insets/insetfoot.C
src/insets/insetgraphics.C src/insets/insetgraphics.C
src/insets/insetinclude.C src/insets/insetinclude.C
src/insets/insetindex.C src/insets/insetindex.C
src/insets/insetinfo.C
src/insets/insetlabel.C src/insets/insetlabel.C
src/insets/insetlist.C src/insets/insetlist.C
src/insets/insetmarginal.C src/insets/insetmarginal.C
@ -206,7 +207,6 @@ src/MenuBackend.C
src/minibuffer.C src/minibuffer.C
src/paragraph.C src/paragraph.C
src/print_form.C src/print_form.C
src/sp_form.C
src/support/filetools.C src/support/filetools.C
src/support/getUserName.C src/support/getUserName.C
src/support/path.C src/support/path.C

View File

@ -1,3 +1,22 @@
2001-07-23 Juergen Vigna <jug@sad.it>
* insetert.C (InsetERT): use setLabel with "true" flag.
* insetcollapsable.C: modified various functions to set the draw_label
string right in any condition.
(setLabel): added a bool parameter to set change_label_with_text.
* insetcollapsable.h: added draw_label string which is set to the
actual drawn label-string, while label is the original static label
of this collapsable inset. Added bool change_label_with_text to set
if we want that the label changes to the start of the InsetText's
text when collabpsed. You can set this flag with the setLabel funciton.
Added bool inlined for inlined collapsable insets, but not handled
yet.
* insetcollapsable.C (get_new_label): added should get a new label
from the InsetText beginning (for now 10 chars).
2001-07-21 Yves Bastide <stid@libd-pc11.univ-bpclermont.fr> 2001-07-21 Yves Bastide <stid@libd-pc11.univ-bpclermont.fr>
* insetquotes.C (latex): fix the handling of french double quotes * insetquotes.C (latex): fix the handling of french double quotes

View File

@ -34,9 +34,11 @@ using std::max;
InsetCollapsable::InsetCollapsable(bool collapsed) InsetCollapsable::InsetCollapsable(bool collapsed)
: UpdatableInset(), collapsed_(collapsed), : UpdatableInset(), collapsed_(collapsed),
button_length(0), button_top_y(0), button_bottom_y(0), button_length(0), button_top_y(0), button_bottom_y(0),
label("Label"), autocollapse(true), label("Label"), draw_label(label), autocollapse(true),
widthCollapsed(0), oldWidth(0), need_update(FULL) widthCollapsed(0), oldWidth(0), need_update(FULL),
inlined(false), change_label_with_text(false)
{ {
inset.setOwner(this); inset.setOwner(this);
@ -80,6 +82,11 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
} }
} }
inset.read(buf, lex); inset.read(buf, lex);
if (collapsed_ && change_label_with_text) {
draw_label = get_new_label();
} else {
draw_label = label;
}
} }
@ -88,7 +95,7 @@ int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
int width = 0; int width = 0;
int ascent = 0; int ascent = 0;
int descent = 0; int descent = 0;
pain.buttonText(0, 0, label, labelfont, false, pain.buttonText(0, 0, draw_label, labelfont, false,
width, ascent, descent); width, ascent, descent);
return ascent; return ascent;
} }
@ -99,7 +106,7 @@ int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
int width = 0; int width = 0;
int ascent = 0; int ascent = 0;
int descent = 0; int descent = 0;
pain.buttonText(0, 0, label, labelfont, false, pain.buttonText(0, 0, draw_label, labelfont, false,
width, ascent, descent); width, ascent, descent);
return descent; return descent;
} }
@ -110,7 +117,7 @@ int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
int width; int width;
int ascent; int ascent;
int descent; int descent;
pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label, labelfont, false, pain.buttonText(TEXT_TO_INSET_OFFSET, 0, draw_label, labelfont, false,
width, ascent, descent); width, ascent, descent);
return width + (2*TEXT_TO_INSET_OFFSET); return width + (2*TEXT_TO_INSET_OFFSET);
} }
@ -136,8 +143,7 @@ int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const
int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
{ {
if (!widthCollapsed) widthCollapsed = width_collapsed(bv->painter(), font);
widthCollapsed = width_collapsed(bv->painter(), font);
if (collapsed_) if (collapsed_)
return widthCollapsed; return widthCollapsed;
@ -148,17 +154,17 @@ int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &, void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
int baseline, float & x) const int baseline, float & x) const
{ {
int width = 0; int width = 0;
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
baseline, label, labelfont, true, width); baseline, draw_label, labelfont, true, width);
x += width + TEXT_TO_INSET_OFFSET; x += width + TEXT_TO_INSET_OFFSET;
} }
void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
int baseline, float & x, bool cleared) const int baseline, float & x, bool cleared) const
{ {
if (nodraw()) if (nodraw())
return; return;
@ -234,6 +240,7 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
UpdatableInset::edit(bv, xp, yp, button); UpdatableInset::edit(bv, xp, yp, button);
if (collapsed_) { if (collapsed_) {
draw_label = label;
collapsed_ = false; collapsed_ = false;
if (!bv->lockInset(this)) if (!bv->lockInset(this))
return; return;
@ -257,6 +264,7 @@ void InsetCollapsable::edit(BufferView * bv, bool front)
UpdatableInset::edit(bv, front); UpdatableInset::edit(bv, front);
if (collapsed_) { if (collapsed_) {
draw_label = label;
collapsed_ = false; collapsed_ = false;
if (!bv->lockInset(this)) if (!bv->lockInset(this))
return; return;
@ -281,6 +289,11 @@ Inset::EDITABLE InsetCollapsable::editable() const
void InsetCollapsable::insetUnlock(BufferView * bv) void InsetCollapsable::insetUnlock(BufferView * bv)
{ {
if (autocollapse) { if (autocollapse) {
if (change_label_with_text) {
draw_label = get_new_label();
} else {
draw_label = label;
}
collapsed_ = true; collapsed_ = true;
} }
inset.insetUnlock(bv); inset.insetUnlock(bv);
@ -310,10 +323,16 @@ void InsetCollapsable::insetButtonRelease(BufferView * bv,
if ((x >= 0) && (x < button_length) && if ((x >= 0) && (x < button_length) &&
(y >= button_top_y) && (y <= button_bottom_y)) { (y >= button_top_y) && (y <= button_bottom_y)) {
if (collapsed_) { if (collapsed_) {
draw_label = label;
collapsed_ = false; collapsed_ = false;
inset.insetButtonRelease(bv, 0, 0, button); inset.insetButtonRelease(bv, 0, 0, button);
bv->updateInset(this, false); bv->updateInset(this, false);
} else { } else {
if (change_label_with_text) {
draw_label = get_new_label();
} else {
draw_label = label;
}
collapsed_ = true; collapsed_ = true;
bv->unlockInset(this); bv->unlockInset(this);
bv->updateInset(this, false); bv->updateInset(this, false);
@ -585,5 +604,42 @@ void InsetCollapsable::open(BufferView * bv, bool flag)
if (flag == !collapsed_) if (flag == !collapsed_)
return; return;
collapsed_ = !flag; collapsed_ = !flag;
if (collapsed_ && change_label_with_text) {
draw_label = get_new_label();
} else {
draw_label = label;
}
bv->updateInset(this, false); bv->updateInset(this, false);
} }
void InsetCollapsable::setLabel(string const & l, bool flag)
{
label = l;
change_label_with_text = flag;
if (collapsed_ && change_label_with_text) {
draw_label = get_new_label();
} else {
draw_label = label;
}
}
string InsetCollapsable::get_new_label() const
{
string la;
int n = std::min(10, inset.paragraph()->size());
int i,j;
for(i=0,j=0; i < n && j < inset.paragraph()->size(); ++j) {
if (inset.paragraph()->isInset(j))
continue;
la += inset.paragraph()->getChar(j);
++i;
}
if ((i > 0) && (j < inset.paragraph()->size()))
la += "...";
if (la.empty())
la = label;
return la;
}

View File

@ -127,7 +127,7 @@ public:
void setFont(BufferView *, LyXFont const &, bool toggleall = false, void setFont(BufferView *, LyXFont const &, bool toggleall = false,
bool selectall = false); bool selectall = false);
/// ///
void setLabel(string const & l) { label = l; } void setLabel(string const & l, bool flag = false);
/// ///
void setLabelFont(LyXFont & f) { labelfont = f; } void setLabelFont(LyXFont & f) { labelfont = f; }
/// ///
@ -207,6 +207,9 @@ public:
/// ///
InsetText inset; InsetText inset;
protected: protected:
///
string get_new_label() const;
/// ///
mutable int button_length; mutable int button_length;
/// ///
@ -217,6 +220,8 @@ private:
/// ///
string label; string label;
/// ///
mutable string draw_label;
///
bool autocollapse; bool autocollapse;
/// ///
mutable int widthCollapsed; mutable int widthCollapsed;
@ -226,6 +231,10 @@ private:
mutable int topx; mutable int topx;
mutable int topbaseline; mutable int topbaseline;
mutable UpdateCodes need_update; mutable UpdateCodes need_update;
///
bool inlined;
///
bool change_label_with_text;
}; };
#endif #endif

View File

@ -25,7 +25,7 @@ using std::ostream;
InsetERT::InsetERT() : InsetCollapsable() InsetERT::InsetERT() : InsetCollapsable()
{ {
setLabel(_("666")); setLabel(_("666"), true);
//LyXFont font(LyXFont::ALL_SANE); //LyXFont font(LyXFont::ALL_SANE);
//font.setLatex (LyXFont::ON); //font.setLatex (LyXFont::ON);
labelfont = LyXFont(LyXFont::ALL_SANE); labelfont = LyXFont(LyXFont::ALL_SANE);