Implement ForceLtR; cleanup of collapsable insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21285 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2007-10-30 12:30:46 +00:00
parent eabe6081c9
commit 3d443b4c9d
12 changed files with 213 additions and 287 deletions

View File

@ -103,6 +103,25 @@ InsetLayout ERT
PassThru true PassThru true
KeepEmpty true KeepEmpty true
FreeSpacing true FreeSpacing true
ForceLTR true
End
InsetLayout Listings
LabelString Listings
LatexType none
Decoration minimalistic
Font
Color black
Family typewriter
EndFont
LabelFont
Color black
Size Small
EndFont
MultiPar true
PassThru true
KeepEmpty true
FreeSpacing true
End End
InsetLayout Branch InsetLayout Branch

View File

@ -9,6 +9,7 @@ InsetLayout URL
Decoration minimalistic Decoration minimalistic
LabelString URL LabelString URL
PassThru true PassThru true
ForceLTR true
Font Font
Family Typewriter Family Typewriter
Color Blue Color Blue

View File

@ -23,10 +23,12 @@
#include "FloatList.h" #include "FloatList.h"
#include "FuncStatus.h" #include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "Language.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "Lexer.h" #include "Lexer.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "MetricsInfo.h" #include "MetricsInfo.h"
#include "ParagraphParameters.h"
#include "frontends/FontMetrics.h" #include "frontends/FontMetrics.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
@ -157,6 +159,15 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
status_ = isOpen() ? Open : Collapsed; status_ = isOpen() ? Open : Collapsed;
setButtonLabel(); setButtonLabel();
// Force default font, if so requested
// This avoids paragraphs in buffer language that would have a
// foreign language after a document language change, and it ensures
// that all new text in ERT and similar gets the "latex" language,
// since new text inherits the language from the last position of the
// existing text. As a side effect this makes us also robust against
// bugs in LyX that might lead to font changes in ERT in .lyx files.
resetParagraphsFont();
} }
@ -173,6 +184,10 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
autoOpen_ = mi.base.bv->cursor().isInside(this); autoOpen_ = mi.base.bv->cursor().isInside(this);
FontInfo tmpfont = mi.base.font;
getDrawFont(mi.base.font);
mi.base.font.realize(tmpfont);
switch (geometry()) { switch (geometry()) {
case NoButton: case NoButton:
InsetText::metrics(mi, dim); InsetText::metrics(mi, dim);
@ -218,6 +233,8 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
} }
break; break;
} }
mi.base.font = tmpfont;
} }
@ -234,6 +251,10 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
ColorCode const old_color = pi.background_color; ColorCode const old_color = pi.background_color;
pi.background_color = backgroundColor(); pi.background_color = backgroundColor();
FontInfo tmpfont = pi.base.font;
getDrawFont(pi.base.font);
pi.base.font.realize(tmpfont);
// Draw button first -- top, left or only // Draw button first -- top, left or only
Dimension dimc = dimensionCollapsed(); Dimension dimc = dimensionCollapsed();
@ -339,6 +360,8 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
break; break;
} }
pi.background_color = old_color; pi.background_color = old_color;
pi.base.font = tmpfont;
} }
@ -538,7 +561,29 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.dispatched(); cur.dispatched();
break; break;
case LFUN_PASTE:
case LFUN_CLIPBOARD_PASTE:
case LFUN_PRIMARY_SELECTION_PASTE: {
InsetText::doDispatch(cur, cmd);
// Since we can only store plain text, we must reset all
// attributes.
// FIXME: Change only the pasted paragraphs
resetParagraphsFont();
break;
}
default: default:
if (layout_.forceltr) {
// Force any new text to latex_language
// FIXME: This should only be necessary in constructor, but
// new paragraphs that are created by pressing enter at the
// start of an existing paragraph get the buffer language
// and not latex_language, so we take this brute force
// approach.
cur.current_font.setLanguage(latex_language);
cur.real_current_font.setLanguage(latex_language);
}
InsetText::doDispatch(cur, cmd); InsetText::doDispatch(cur, cmd);
break; break;
} }
@ -551,107 +596,130 @@ bool InsetCollapsable::allowMultiPar() const
} }
void InsetCollapsable::resetParagraphsFont()
{
Font font;
font.fontInfo() = layout_.font;
if (layout_.forceltr)
font.setLanguage(latex_language);
if (layout_.passthru) {
ParagraphList::iterator par = paragraphs().begin();
ParagraphList::iterator const end = paragraphs().end();
while (par != end) {
par->resetFonts(font);
par->params().clear();
++par;
}
}
}
void InsetCollapsable::getDrawFont(FontInfo & font) const
{
font = layout_.font;
}
bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd, bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const FuncStatus & flag) const
{ {
switch (cmd.action) { switch (cmd.action) {
// suppress these // suppress these
case LFUN_ACCENT_ACUTE: case LFUN_ACCENT_ACUTE:
case LFUN_ACCENT_BREVE: case LFUN_ACCENT_BREVE:
case LFUN_ACCENT_CARON: case LFUN_ACCENT_CARON:
case LFUN_ACCENT_CEDILLA: case LFUN_ACCENT_CEDILLA:
case LFUN_ACCENT_CIRCLE: case LFUN_ACCENT_CIRCLE:
case LFUN_ACCENT_CIRCUMFLEX: case LFUN_ACCENT_CIRCUMFLEX:
case LFUN_ACCENT_DOT: case LFUN_ACCENT_DOT:
case LFUN_ACCENT_GRAVE: case LFUN_ACCENT_GRAVE:
case LFUN_ACCENT_HUNGARIAN_UMLAUT: case LFUN_ACCENT_HUNGARIAN_UMLAUT:
case LFUN_ACCENT_MACRON: case LFUN_ACCENT_MACRON:
case LFUN_ACCENT_OGONEK: case LFUN_ACCENT_OGONEK:
case LFUN_ACCENT_SPECIAL_CARON: case LFUN_ACCENT_SPECIAL_CARON:
case LFUN_ACCENT_TIE: case LFUN_ACCENT_TIE:
case LFUN_ACCENT_TILDE: case LFUN_ACCENT_TILDE:
case LFUN_ACCENT_UMLAUT: case LFUN_ACCENT_UMLAUT:
case LFUN_ACCENT_UNDERBAR: case LFUN_ACCENT_UNDERBAR:
case LFUN_ACCENT_UNDERDOT: case LFUN_ACCENT_UNDERDOT:
case LFUN_APPENDIX: case LFUN_APPENDIX:
case LFUN_BIBITEM_INSERT: case LFUN_BIBITEM_INSERT:
case LFUN_BOX_INSERT: case LFUN_BOX_INSERT:
case LFUN_BRANCH_INSERT: case LFUN_BRANCH_INSERT:
case LFUN_BREAK_LINE: case LFUN_BREAK_LINE:
case LFUN_CAPTION_INSERT: case LFUN_CAPTION_INSERT:
case LFUN_CLEARPAGE_INSERT: case LFUN_CLEARPAGE_INSERT:
case LFUN_CLEARDOUBLEPAGE_INSERT: case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_DEPTH_DECREMENT: case LFUN_DEPTH_DECREMENT:
case LFUN_DEPTH_INCREMENT: case LFUN_DEPTH_INCREMENT:
case LFUN_DOTS_INSERT: case LFUN_DOTS_INSERT:
case LFUN_END_OF_SENTENCE_PERIOD_INSERT: case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
case LFUN_ENVIRONMENT_INSERT: case LFUN_ENVIRONMENT_INSERT:
case LFUN_ERT_INSERT: case LFUN_ERT_INSERT:
case LFUN_FILE_INSERT: case LFUN_FILE_INSERT:
case LFUN_FLEX_INSERT: case LFUN_FLEX_INSERT:
case LFUN_FLOAT_INSERT: case LFUN_FLOAT_INSERT:
case LFUN_FLOAT_LIST: case LFUN_FLOAT_LIST:
case LFUN_FLOAT_WIDE_INSERT: case LFUN_FLOAT_WIDE_INSERT:
case LFUN_FONT_BOLD: case LFUN_FONT_BOLD:
case LFUN_FONT_TYPEWRITER: case LFUN_FONT_TYPEWRITER:
case LFUN_FONT_DEFAULT: case LFUN_FONT_DEFAULT:
case LFUN_FONT_EMPH: case LFUN_FONT_EMPH:
case LFUN_FONT_FREE_APPLY: case LFUN_FONT_FREE_APPLY:
case LFUN_FONT_FREE_UPDATE: case LFUN_FONT_FREE_UPDATE:
case LFUN_FONT_NOUN: case LFUN_FONT_NOUN:
case LFUN_FONT_ROMAN: case LFUN_FONT_ROMAN:
case LFUN_FONT_SANS: case LFUN_FONT_SANS:
case LFUN_FONT_FRAK: case LFUN_FONT_FRAK:
case LFUN_FONT_ITAL: case LFUN_FONT_ITAL:
case LFUN_FONT_SIZE: case LFUN_FONT_SIZE:
case LFUN_FONT_STATE: case LFUN_FONT_STATE:
case LFUN_FONT_UNDERLINE: case LFUN_FONT_UNDERLINE:
case LFUN_FOOTNOTE_INSERT: case LFUN_FOOTNOTE_INSERT:
case LFUN_HFILL_INSERT: case LFUN_HFILL_INSERT:
case LFUN_HYPERLINK_INSERT: case LFUN_HYPERLINK_INSERT:
case LFUN_HYPHENATION_POINT_INSERT: case LFUN_HYPHENATION_POINT_INSERT:
case LFUN_INDEX_INSERT: case LFUN_INDEX_INSERT:
case LFUN_INDEX_PRINT: case LFUN_INDEX_PRINT:
case LFUN_INSET_INSERT: case LFUN_INSET_INSERT:
case LFUN_LABEL_GOTO: case LFUN_LABEL_GOTO:
case LFUN_LABEL_INSERT: case LFUN_LABEL_INSERT:
case LFUN_LIGATURE_BREAK_INSERT: case LFUN_LIGATURE_BREAK_INSERT:
case LFUN_LINE_INSERT: case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT: case LFUN_PAGEBREAK_INSERT:
case LFUN_LANGUAGE: case LFUN_LAYOUT:
case LFUN_LAYOUT: case LFUN_LAYOUT_PARAGRAPH:
case LFUN_LAYOUT_PARAGRAPH: case LFUN_LAYOUT_TABULAR:
case LFUN_LAYOUT_TABULAR: case LFUN_MARGINALNOTE_INSERT:
case LFUN_MARGINALNOTE_INSERT: case LFUN_MATH_DISPLAY:
case LFUN_MATH_DISPLAY: case LFUN_MATH_INSERT:
case LFUN_MATH_INSERT: case LFUN_MATH_MATRIX:
case LFUN_MATH_MATRIX: case LFUN_MATH_MODE:
case LFUN_MATH_MODE: case LFUN_MENU_OPEN:
case LFUN_MENU_OPEN: case LFUN_MENU_SEPARATOR_INSERT:
case LFUN_MENU_SEPARATOR_INSERT: case LFUN_NOACTION:
case LFUN_NOACTION: case LFUN_NOMENCL_INSERT:
case LFUN_NOMENCL_INSERT: case LFUN_NOMENCL_PRINT:
case LFUN_NOMENCL_PRINT: case LFUN_NOTE_INSERT:
case LFUN_NOTE_INSERT: case LFUN_NOTE_NEXT:
case LFUN_NOTE_NEXT: case LFUN_OPTIONAL_INSERT:
case LFUN_OPTIONAL_INSERT: case LFUN_PARAGRAPH_PARAMS:
case LFUN_PARAGRAPH_PARAMS: case LFUN_PARAGRAPH_PARAMS_APPLY:
case LFUN_PARAGRAPH_PARAMS_APPLY: case LFUN_PARAGRAPH_SPACING:
case LFUN_PARAGRAPH_SPACING: case LFUN_PARAGRAPH_UPDATE:
case LFUN_PARAGRAPH_UPDATE: case LFUN_REFERENCE_NEXT:
case LFUN_REFERENCE_NEXT: case LFUN_SERVER_GOTO_FILE_ROW:
case LFUN_SERVER_GOTO_FILE_ROW: case LFUN_SERVER_NOTIFY:
case LFUN_SERVER_NOTIFY: case LFUN_SERVER_SET_XY:
case LFUN_SERVER_SET_XY: case LFUN_SPACE_INSERT:
case LFUN_SPACE_INSERT: case LFUN_TABULAR_INSERT:
case LFUN_TABULAR_INSERT: case LFUN_TOC_INSERT:
case LFUN_TOC_INSERT: case LFUN_WRAP_INSERT:
case LFUN_WRAP_INSERT: if (layout_.passthru) {
if (layout_.passthru) { flag.enabled(false);
flag.enabled(false); return true;
return true; } else
} else return InsetText::getStatus(cur, cmd, flag);
return InsetText::getStatus(cur, cmd, flag);
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (cmd.argument() == "open" || cmd.argument() == "close" || if (cmd.argument() == "open" || cmd.argument() == "close" ||
@ -661,6 +729,15 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.enabled(false); flag.enabled(false);
return true; return true;
case LFUN_LANGUAGE:
flag.enabled(layout_.forceltr);
return InsetText::getStatus(cur, cmd, flag);
case LFUN_BREAK_PARAGRAPH:
case LFUN_BREAK_PARAGRAPH_SKIP:
flag.enabled(layout_.multipar);
return true;
default: default:
return InsetText::getStatus(cur, cmd, flag); return InsetText::getStatus(cur, cmd, flag);
} }

View File

@ -157,6 +157,10 @@ protected:
Inset * editXY(Cursor & cur, int x, int y); Inset * editXY(Cursor & cur, int x, int y);
/// ///
docstring floatName(std::string const & type, BufferParams const &) const; docstring floatName(std::string const & type, BufferParams const &) const;
///
virtual void resetParagraphsFont();
///
virtual void getDrawFont(FontInfo &) const;
protected: protected:
/// ///

View File

@ -121,21 +121,6 @@ void InsetERT::write(Buffer const & buf, ostream & os) const
} }
void InsetERT::read(Buffer const & buf, Lexer & lex)
{
InsetCollapsable::read(buf, lex);
// Force default font
// This avoids paragraphs in buffer language that would have a
// foreign language after a document langauge change, and it ensures
// that all new text in ERT gets the "latex" language, since new text
// inherits the language from the last position of the existing text.
// As a side effect this makes us also robust against bugs in LyX
// that might lead to font changes in ERT in .lyx files.
resetParagraphsFont();
}
docstring const InsetERT::editMessage() const docstring const InsetERT::editMessage() const
{ {
return _("Opened ERT Inset"); return _("Opened ERT Inset");
@ -208,19 +193,6 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
setStatus(cur, st); setStatus(cur, st);
break; break;
} }
case LFUN_PASTE:
case LFUN_CLIPBOARD_PASTE:
case LFUN_PRIMARY_SELECTION_PASTE: {
InsetCollapsable::doDispatch(cur, cmd);
// Since we can only store plain text, we must reset all
// attributes.
// FIXME: Change only the pasted paragraphs
// ERT contents has always latex_language
resetParagraphsFont();
break;
}
default: default:
// Force any new text to latex_language // Force any new text to latex_language
// FIXME: This should only be necessary in init(), but // FIXME: This should only be necessary in init(), but
@ -230,8 +202,6 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
// approach. // approach.
cur.current_font.fontInfo() = layout->font; cur.current_font.fontInfo() = layout->font;
cur.real_current_font.fontInfo() = layout->font; cur.real_current_font.fontInfo() = layout->font;
cur.current_font.setLanguage(latex_language);
cur.real_current_font.setLanguage(latex_language);
InsetCollapsable::doDispatch(cur, cmd); InsetCollapsable::doDispatch(cur, cmd);
break; break;
} }

View File

@ -48,8 +48,6 @@ public:
/// ///
void write(Buffer const & buf, std::ostream & os) const; void write(Buffer const & buf, std::ostream & os) const;
/// ///
void read(Buffer const & buf, Lexer & lex);
///
virtual docstring const editMessage() const; virtual docstring const editMessage() const;
/// ///
bool insetAllowed(InsetCode code) const; bool insetAllowed(InsetCode code) const;
@ -71,8 +69,6 @@ public:
/// ///
bool showInsetDialog(BufferView *) const; bool showInsetDialog(BufferView *) const;
/// ///
void getDrawFont(FontInfo &) const;
///
bool forceDefaultParagraphs(idx_type) const { return true; } bool forceDefaultParagraphs(idx_type) const { return true; }
/// should paragraph indendation be ommitted in any case? /// should paragraph indendation be ommitted in any case?
bool neverIndent(Buffer const &) const { return true; } bool neverIndent(Buffer const &) const { return true; }
@ -84,6 +80,8 @@ protected:
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
/// ///
void resetParagraphsFont(); void resetParagraphsFont();
///
void getDrawFont(FontInfo &) const;
private: private:
virtual Inset * clone() const; virtual Inset * clone() const;

View File

@ -95,56 +95,6 @@ void InsetFlex::read(Buffer const & buf, Lexer & lex)
} }
void InsetFlex::metrics(MetricsInfo & mi, Dimension & dim) const
{
FontInfo tmpfont = mi.base.font;
getDrawFont(mi.base.font);
mi.base.font.reduce(sane_font);
mi.base.font.realize(tmpfont);
InsetCollapsable::metrics(mi, dim);
mi.base.font = tmpfont;
}
void InsetFlex::draw(PainterInfo & pi, int x, int y) const
{
FontInfo tmpfont = pi.base.font;
getDrawFont(pi.base.font);
// I don't understand why the above .reduce and .realize aren't
//needed, or even wanted, here. It just works. -- MV 10.04.2005
InsetCollapsable::draw(pi, x, y);
pi.base.font = tmpfont;
}
void InsetFlex::getDrawFont(FontInfo & font) const
{
font = layout_.font;
}
void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
{
InsetCollapsable::doDispatch(cur, cmd);
}
bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
switch (cmd.action) {
// paragraph breaks not allowed in flex insets
case LFUN_BREAK_PARAGRAPH:
case LFUN_BREAK_PARAGRAPH_SKIP:
status.enabled(layout_.multipar);
return true;
default:
return InsetCollapsable::getStatus(cur, cmd, status);
}
}
int InsetFlex::plaintext(Buffer const & buf, odocstream & os, int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {

View File

@ -56,12 +56,6 @@ public:
/// ///
void read(Buffer const & buf, Lexer & lex); void read(Buffer const & buf, Lexer & lex);
/// ///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo &, int, int) const;
///
void getDrawFont(FontInfo &) const;
///
bool forceDefaultParagraphs(idx_type) const { return true; } bool forceDefaultParagraphs(idx_type) const { return true; }
/// ///
@ -81,9 +75,6 @@ public:
protected: protected:
InsetFlex(InsetFlex const &); InsetFlex(InsetFlex const &);
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
private: private:
friend class InsetFlexParams; friend class InsetFlexParams;

View File

@ -63,50 +63,6 @@ void InsetIndex::write(Buffer const & buf, std::ostream & os) const
} }
void InsetIndex::metrics(MetricsInfo & mi, Dimension & dim) const
{
FontInfo tmpfont = mi.base.font;
getDrawFont(mi.base.font);
mi.base.font.realize(tmpfont);
InsetCollapsable::metrics(mi, dim);
mi.base.font = tmpfont;
}
void InsetIndex::draw(PainterInfo & pi, int x, int y) const
{
FontInfo tmpfont = pi.base.font;
getDrawFont(pi.base.font);
pi.base.font.realize(tmpfont);
InsetCollapsable::draw(pi, x, y);
pi.base.font = tmpfont;
}
void InsetIndex::getDrawFont(FontInfo & font) const
{
font = inherit_font;
font.realize(layout_.font);
}
bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
switch (cmd.action) {
// paragraph breaks not allowed
case LFUN_BREAK_PARAGRAPH:
case LFUN_BREAK_PARAGRAPH_SKIP:
status.enabled(false);
return true;
default:
return InsetCollapsable::getStatus(cur, cmd, status);
}
}
InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p) InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
: InsetCommand(p, string()) : InsetCommand(p, string())
{} {}

View File

@ -34,15 +34,8 @@ public:
/// ///
InsetCode lyxCode() const { return INDEX_CODE; } InsetCode lyxCode() const { return INDEX_CODE; }
/// ///
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo &, int, int) const;
///
docstring name() const { return from_ascii("Index"); } docstring name() const { return from_ascii("Index"); }
/// ///
void getDrawFont(FontInfo &) const;
///
void write(Buffer const & buf, std::ostream & os) const; void write(Buffer const & buf, std::ostream & os) const;
/// ///
int docbook(Buffer const &, odocstream &, int docbook(Buffer const &, odocstream &,
@ -50,8 +43,6 @@ public:
/// should paragraph indendation be omitted in any case? /// should paragraph indendation be omitted in any case?
bool neverIndent(Buffer const &) const { return true; } bool neverIndent(Buffer const &) const { return true; }
private: private:
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
/// ///
virtual Inset * clone() const; virtual Inset * clone() const;
}; };

View File

@ -59,14 +59,15 @@ void InsetListings::init()
InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par) InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par)
: InsetERT(bp, par.status()) : InsetCollapsable(bp, par.status())
{ {
setLayout(bp);
init(); init();
} }
InsetListings::InsetListings(InsetListings const & in) InsetListings::InsetListings(InsetListings const & in)
: InsetERT(in), params_(in.params_) : InsetCollapsable(in), params_(in.params_)
{ {
init(); init();
} }
@ -139,7 +140,7 @@ void InsetListings::read(Buffer const & buf, Lexer & lex)
break; break;
} }
} }
InsetERT::read(buf, lex); InsetCollapsable::read(buf, lex);
} }
@ -244,11 +245,11 @@ void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
InsetListingsMailer(*this).showDialog(&cur.bv()); InsetListingsMailer(*this).showDialog(&cur.bv());
break; break;
} }
InsetERT::doDispatch(cur, cmd); InsetCollapsable::doDispatch(cur, cmd);
break; break;
} }
default: default:
InsetERT::doDispatch(cur, cmd); InsetCollapsable::doDispatch(cur, cmd);
break; break;
} }
} }
@ -265,7 +266,7 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
status.enabled(!params().isInline()); status.enabled(!params().isInline());
return true; return true;
default: default:
return InsetERT::getStatus(cur, cmd, status); return InsetCollapsable::getStatus(cur, cmd, status);
} }
} }
@ -273,34 +274,17 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
void InsetListings::setButtonLabel() void InsetListings::setButtonLabel()
{ {
// FIXME UNICODE // FIXME UNICODE
setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing"))); if (decoration() == Classic)
} setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing")));
else
setLabel(getNewLabel(_("Listing")));
void InsetListings::metrics(MetricsInfo & mi, Dimension & dim) const
{
FontInfo tmpfont = mi.base.font;
getDrawFont(mi.base.font);
mi.base.font.realize(tmpfont);
InsetCollapsable::metrics(mi, dim);
mi.base.font = tmpfont;
}
void InsetListings::draw(PainterInfo & pi, int x, int y) const
{
FontInfo tmpfont = pi.base.font;
getDrawFont(pi.base.font);
pi.base.font.realize(tmpfont);
InsetCollapsable::draw(pi, x, y);
pi.base.font = tmpfont;
} }
void InsetListings::validate(LaTeXFeatures & features) const void InsetListings::validate(LaTeXFeatures & features) const
{ {
features.require("listings"); features.require("listings");
InsetERT::validate(features); InsetCollapsable::validate(features);
} }
@ -311,15 +295,6 @@ bool InsetListings::showInsetDialog(BufferView * bv) const
} }
void InsetListings::getDrawFont(FontInfo & font) const
{
font = inherit_font;
font.setFamily(TYPEWRITER_FAMILY);
// FIXME: define Color_listing?
font.setColor(Color_foreground);
}
docstring InsetListings::getCaption(Buffer const & buf, docstring InsetListings::getCaption(Buffer const & buf,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {

View File

@ -24,7 +24,7 @@ namespace lyx {
*/ */
class InsetListings : public InsetERT { class InsetListings : public InsetCollapsable {
public: public:
/// ///
InsetListings(BufferParams const &, InsetListingsParams const & par = InsetListingsParams()); InsetListings(BufferParams const &, InsetListingsParams const & par = InsetListingsParams());
@ -49,14 +49,8 @@ public:
/// ///
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
bool showInsetDialog(BufferView *) const; bool showInsetDialog(BufferView *) const;
/// ///
void getDrawFont(FontInfo &) const;
///
InsetListingsParams const & params() const { return params_; } InsetListingsParams const & params() const { return params_; }
/// ///
InsetListingsParams & params() { return params_; } InsetListingsParams & params() { return params_; }