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
KeepEmpty 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
InsetLayout Branch

View File

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

View File

@ -23,10 +23,12 @@
#include "FloatList.h"
#include "FuncStatus.h"
#include "gettext.h"
#include "Language.h"
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "FuncRequest.h"
#include "MetricsInfo.h"
#include "ParagraphParameters.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
@ -157,6 +159,15 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
status_ = isOpen() ? Open : Collapsed;
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);
FontInfo tmpfont = mi.base.font;
getDrawFont(mi.base.font);
mi.base.font.realize(tmpfont);
switch (geometry()) {
case NoButton:
InsetText::metrics(mi, dim);
@ -218,6 +233,8 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
}
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;
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
Dimension dimc = dimensionCollapsed();
@ -339,6 +360,8 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
break;
}
pi.background_color = old_color;
pi.base.font = tmpfont;
}
@ -538,7 +561,29 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.dispatched();
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:
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);
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,
FuncStatus & flag) const
{
switch (cmd.action) {
// suppress these
case LFUN_ACCENT_ACUTE:
case LFUN_ACCENT_BREVE:
case LFUN_ACCENT_CARON:
case LFUN_ACCENT_CEDILLA:
case LFUN_ACCENT_CIRCLE:
case LFUN_ACCENT_CIRCUMFLEX:
case LFUN_ACCENT_DOT:
case LFUN_ACCENT_GRAVE:
case LFUN_ACCENT_HUNGARIAN_UMLAUT:
case LFUN_ACCENT_MACRON:
case LFUN_ACCENT_OGONEK:
case LFUN_ACCENT_SPECIAL_CARON:
case LFUN_ACCENT_TIE:
case LFUN_ACCENT_TILDE:
case LFUN_ACCENT_UMLAUT:
case LFUN_ACCENT_UNDERBAR:
case LFUN_ACCENT_UNDERDOT:
case LFUN_APPENDIX:
case LFUN_BIBITEM_INSERT:
case LFUN_BOX_INSERT:
case LFUN_BRANCH_INSERT:
case LFUN_BREAK_LINE:
case LFUN_CAPTION_INSERT:
case LFUN_CLEARPAGE_INSERT:
case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_DEPTH_DECREMENT:
case LFUN_DEPTH_INCREMENT:
case LFUN_DOTS_INSERT:
case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
case LFUN_ENVIRONMENT_INSERT:
case LFUN_ERT_INSERT:
case LFUN_FILE_INSERT:
case LFUN_FLEX_INSERT:
case LFUN_FLOAT_INSERT:
case LFUN_FLOAT_LIST:
case LFUN_FLOAT_WIDE_INSERT:
case LFUN_FONT_BOLD:
case LFUN_FONT_TYPEWRITER:
case LFUN_FONT_DEFAULT:
case LFUN_FONT_EMPH:
case LFUN_FONT_FREE_APPLY:
case LFUN_FONT_FREE_UPDATE:
case LFUN_FONT_NOUN:
case LFUN_FONT_ROMAN:
case LFUN_FONT_SANS:
case LFUN_FONT_FRAK:
case LFUN_FONT_ITAL:
case LFUN_FONT_SIZE:
case LFUN_FONT_STATE:
case LFUN_FONT_UNDERLINE:
case LFUN_FOOTNOTE_INSERT:
case LFUN_HFILL_INSERT:
case LFUN_HYPERLINK_INSERT:
case LFUN_HYPHENATION_POINT_INSERT:
case LFUN_INDEX_INSERT:
case LFUN_INDEX_PRINT:
case LFUN_INSET_INSERT:
case LFUN_LABEL_GOTO:
case LFUN_LABEL_INSERT:
case LFUN_LIGATURE_BREAK_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
case LFUN_LANGUAGE:
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH:
case LFUN_LAYOUT_TABULAR:
case LFUN_MARGINALNOTE_INSERT:
case LFUN_MATH_DISPLAY:
case LFUN_MATH_INSERT:
case LFUN_MATH_MATRIX:
case LFUN_MATH_MODE:
case LFUN_MENU_OPEN:
case LFUN_MENU_SEPARATOR_INSERT:
case LFUN_NOACTION:
case LFUN_NOMENCL_INSERT:
case LFUN_NOMENCL_PRINT:
case LFUN_NOTE_INSERT:
case LFUN_NOTE_NEXT:
case LFUN_OPTIONAL_INSERT:
case LFUN_PARAGRAPH_PARAMS:
case LFUN_PARAGRAPH_PARAMS_APPLY:
case LFUN_PARAGRAPH_SPACING:
case LFUN_PARAGRAPH_UPDATE:
case LFUN_REFERENCE_NEXT:
case LFUN_SERVER_GOTO_FILE_ROW:
case LFUN_SERVER_NOTIFY:
case LFUN_SERVER_SET_XY:
case LFUN_SPACE_INSERT:
case LFUN_TABULAR_INSERT:
case LFUN_TOC_INSERT:
case LFUN_WRAP_INSERT:
if (layout_.passthru) {
flag.enabled(false);
return true;
} else
return InsetText::getStatus(cur, cmd, flag);
// suppress these
case LFUN_ACCENT_ACUTE:
case LFUN_ACCENT_BREVE:
case LFUN_ACCENT_CARON:
case LFUN_ACCENT_CEDILLA:
case LFUN_ACCENT_CIRCLE:
case LFUN_ACCENT_CIRCUMFLEX:
case LFUN_ACCENT_DOT:
case LFUN_ACCENT_GRAVE:
case LFUN_ACCENT_HUNGARIAN_UMLAUT:
case LFUN_ACCENT_MACRON:
case LFUN_ACCENT_OGONEK:
case LFUN_ACCENT_SPECIAL_CARON:
case LFUN_ACCENT_TIE:
case LFUN_ACCENT_TILDE:
case LFUN_ACCENT_UMLAUT:
case LFUN_ACCENT_UNDERBAR:
case LFUN_ACCENT_UNDERDOT:
case LFUN_APPENDIX:
case LFUN_BIBITEM_INSERT:
case LFUN_BOX_INSERT:
case LFUN_BRANCH_INSERT:
case LFUN_BREAK_LINE:
case LFUN_CAPTION_INSERT:
case LFUN_CLEARPAGE_INSERT:
case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_DEPTH_DECREMENT:
case LFUN_DEPTH_INCREMENT:
case LFUN_DOTS_INSERT:
case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
case LFUN_ENVIRONMENT_INSERT:
case LFUN_ERT_INSERT:
case LFUN_FILE_INSERT:
case LFUN_FLEX_INSERT:
case LFUN_FLOAT_INSERT:
case LFUN_FLOAT_LIST:
case LFUN_FLOAT_WIDE_INSERT:
case LFUN_FONT_BOLD:
case LFUN_FONT_TYPEWRITER:
case LFUN_FONT_DEFAULT:
case LFUN_FONT_EMPH:
case LFUN_FONT_FREE_APPLY:
case LFUN_FONT_FREE_UPDATE:
case LFUN_FONT_NOUN:
case LFUN_FONT_ROMAN:
case LFUN_FONT_SANS:
case LFUN_FONT_FRAK:
case LFUN_FONT_ITAL:
case LFUN_FONT_SIZE:
case LFUN_FONT_STATE:
case LFUN_FONT_UNDERLINE:
case LFUN_FOOTNOTE_INSERT:
case LFUN_HFILL_INSERT:
case LFUN_HYPERLINK_INSERT:
case LFUN_HYPHENATION_POINT_INSERT:
case LFUN_INDEX_INSERT:
case LFUN_INDEX_PRINT:
case LFUN_INSET_INSERT:
case LFUN_LABEL_GOTO:
case LFUN_LABEL_INSERT:
case LFUN_LIGATURE_BREAK_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH:
case LFUN_LAYOUT_TABULAR:
case LFUN_MARGINALNOTE_INSERT:
case LFUN_MATH_DISPLAY:
case LFUN_MATH_INSERT:
case LFUN_MATH_MATRIX:
case LFUN_MATH_MODE:
case LFUN_MENU_OPEN:
case LFUN_MENU_SEPARATOR_INSERT:
case LFUN_NOACTION:
case LFUN_NOMENCL_INSERT:
case LFUN_NOMENCL_PRINT:
case LFUN_NOTE_INSERT:
case LFUN_NOTE_NEXT:
case LFUN_OPTIONAL_INSERT:
case LFUN_PARAGRAPH_PARAMS:
case LFUN_PARAGRAPH_PARAMS_APPLY:
case LFUN_PARAGRAPH_SPACING:
case LFUN_PARAGRAPH_UPDATE:
case LFUN_REFERENCE_NEXT:
case LFUN_SERVER_GOTO_FILE_ROW:
case LFUN_SERVER_NOTIFY:
case LFUN_SERVER_SET_XY:
case LFUN_SPACE_INSERT:
case LFUN_TABULAR_INSERT:
case LFUN_TOC_INSERT:
case LFUN_WRAP_INSERT:
if (layout_.passthru) {
flag.enabled(false);
return true;
} else
return InsetText::getStatus(cur, cmd, flag);
case LFUN_INSET_TOGGLE:
if (cmd.argument() == "open" || cmd.argument() == "close" ||
@ -661,6 +729,15 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.enabled(false);
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:
return InsetText::getStatus(cur, cmd, flag);
}

View File

@ -157,6 +157,10 @@ protected:
Inset * editXY(Cursor & cur, int x, int y);
///
docstring floatName(std::string const & type, BufferParams const &) const;
///
virtual void resetParagraphsFont();
///
virtual void getDrawFont(FontInfo &) const;
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
{
return _("Opened ERT Inset");
@ -208,19 +193,6 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
setStatus(cur, st);
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:
// Force any new text to latex_language
// FIXME: This should only be necessary in init(), but
@ -230,8 +202,6 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
// approach.
cur.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);
break;
}

View File

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

View File

@ -56,12 +56,6 @@ public:
///
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; }
///
@ -81,9 +75,6 @@ public:
protected:
InsetFlex(InsetFlex const &);
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
private:
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)
: InsetCommand(p, string())
{}

View File

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

View File

@ -59,14 +59,15 @@ void InsetListings::init()
InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par)
: InsetERT(bp, par.status())
: InsetCollapsable(bp, par.status())
{
setLayout(bp);
init();
}
InsetListings::InsetListings(InsetListings const & in)
: InsetERT(in), params_(in.params_)
: InsetCollapsable(in), params_(in.params_)
{
init();
}
@ -139,7 +140,7 @@ void InsetListings::read(Buffer const & buf, Lexer & lex)
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());
break;
}
InsetERT::doDispatch(cur, cmd);
InsetCollapsable::doDispatch(cur, cmd);
break;
}
default:
InsetERT::doDispatch(cur, cmd);
InsetCollapsable::doDispatch(cur, cmd);
break;
}
}
@ -265,7 +266,7 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
status.enabled(!params().isInline());
return true;
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()
{
// FIXME UNICODE
setLabel(isOpen() ? _("Listing") : 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;
if (decoration() == Classic)
setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing")));
else
setLabel(getNewLabel(_("Listing")));
}
void InsetListings::validate(LaTeXFeatures & features) const
{
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,
OutputParams const & runparams) const
{

View File

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