From ce3b1fa997fd9451d627d0eae03f8a8336a1c696 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 11 Mar 2003 15:01:29 +0000 Subject: [PATCH] activate the new InsetHFill, small ws git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6448 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 13 ++++--------- src/insets/insetert.C | 1 - src/insets/insethfill.h | 2 ++ src/insets/insetquotes.C | 2 +- src/insets/insetspecialchar.C | 1 + src/insets/insetspecialchar.h | 10 ++-------- src/lyxlayout.C | 4 ++-- src/paragraph.C | 36 +++++++++++++---------------------- src/paragraph.h | 4 +--- src/paragraph_pimpl.C | 9 +++------ src/sgml.C | 2 -- src/support/textutils.h | 9 --------- src/text.C | 24 +++++++++++++---------- src/text3.C | 8 +------- 14 files changed, 44 insertions(+), 81 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 8b55fbecca..cc6ad28eaa 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -49,6 +49,7 @@ #include "insets/inset.h" #include "insets/inseterror.h" +#include "insets/insethfill.h" #include "insets/insetlabel.h" #include "insets/insetref.h" #include "insets/inseturl.h" @@ -966,7 +967,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, par->insertInset(pos, inset, font, current_change); ++pos; } else if (token == "\\hfill") { - par->insertChar(pos, Paragraph::META_HFILL, font, current_change); + par->insertInset(pos, new InsetHFill(), + LyXFont(LyXFont::ALL_INHERIT, params.language)); ++pos; } else if (token == "\\change_unchanged") { // Hack ! Needed for empty paragraphs :/ @@ -1617,19 +1619,12 @@ string const Buffer::asciiParagraph(Paragraph const & par, } break; - case Paragraph::META_HFILL: - buffer << word << "\t"; - currlinelen += word.length() + 1; - word.erase(); - break; - default: if (c == ' ') { if (linelen > 0 && currlinelen + word.length() > linelen - 10) { buffer << "\n"; - pair p = - addDepth(depth, ltype_depth); + pair p = addDepth(depth, ltype_depth); buffer << p.second; currlinelen = p.first; } diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 78783ecde0..c4107c93a6 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -208,7 +208,6 @@ void InsetERT::write(Buffer const * buf, ostream & os) const Paragraph::value_type c = par->getChar(i); switch (c) { case Paragraph::META_INSET: - case Paragraph::META_HFILL: lyxerr << "Element is not allowed in insertERT" << endl; case Paragraph::META_NEWLINE: diff --git a/src/insets/insethfill.h b/src/insets/insethfill.h index 27df19a004..071761c4fe 100644 --- a/src/insets/insethfill.h +++ b/src/insets/insethfill.h @@ -33,6 +33,8 @@ public: int ascii(Buffer const *, std::ostream &, int linelen) const; /// void write(Buffer const * buf, ostream & os) const; + /// We don't need \begin_inset and \end_inset + bool directWrite() const { return true; } }; #endif diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index fe90f3e563..dfb1051a75 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -86,7 +86,7 @@ InsetQuotes::InsetQuotes(char c, BufferParams const & params) // Decide whether left or right switch (c) { case ' ': case '(': - case Paragraph::META_HFILL: + //case Paragraph::META_HFILL: case Paragraph::META_NEWLINE: side_ = LeftQ; // left quote break; diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index dcf2f1a065..510dee9f44 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -35,6 +35,7 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const return kind_; } + int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const { return font_metrics::maxAscent(font); diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 9b9956775b..79ced1f07d 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -71,15 +71,9 @@ public: /// virtual Inset * clone(Buffer const &, bool same_id = false) const; /// - Inset::Code lyxCode() const - { - return Inset::SPECIALCHAR_CODE; - } + Inset::Code lyxCode() const { return Inset::SPECIALCHAR_CODE; } /// We don't need \begin_inset and \end_inset - bool directWrite() const - { - return true; - }; + bool directWrite() const { return true; } /// void validate(LaTeXFeatures &) const; diff --git a/src/lyxlayout.C b/src/lyxlayout.C index 80e280b157..2f815aa162 100644 --- a/src/lyxlayout.C +++ b/src/lyxlayout.C @@ -529,7 +529,7 @@ void LyXLayout::readLabelType(LyXLex & lexrc) keyword_item labelTypeTags[] = { { "bibliography", LA_BIBLIO }, { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT }, - { "counter_chapter", LA_COUNTER_CHAPTER }, + { "counter_chapter", LA_COUNTER_CHAPTER }, { "counter_enumi", LA_COUNTER_ENUMI }, { "counter_enumii", LA_COUNTER_ENUMII }, { "counter_enumiii", LA_COUNTER_ENUMIII }, @@ -544,7 +544,7 @@ void LyXLayout::readLabelType(LyXLex & lexrc) { "sensitive", LA_SENSITIVE }, { "static", LA_STATIC }, { "top_environment", LA_TOP_ENVIRONMENT } -}; + }; pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO); int le = lexrc.lex(); diff --git a/src/paragraph.C b/src/paragraph.C index 730c68be39..7e8470af8f 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -265,10 +265,6 @@ void Paragraph::write(Buffer const * buf, ostream & os, os << "\n\\newline \n"; column = 0; break; - case META_HFILL: - os << "\n\\hfill \n"; - column = 0; - break; case '\\': os << "\n\\backslash \n"; column = 0; @@ -433,7 +429,6 @@ void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, C bool Paragraph::insetAllowed(Inset::Code code) { //lyxerr << "Paragraph::InsertInsetAllowed" << endl; - if (pimpl_->inset_owner) return pimpl_->inset_owner->insetAllowed(code); return true; @@ -443,7 +438,6 @@ bool Paragraph::insetAllowed(Inset::Code code) Inset * Paragraph::getInset(pos_type pos) { lyx::Assert(pos < size()); - return insetlist.get(pos); } @@ -451,7 +445,6 @@ Inset * Paragraph::getInset(pos_type pos) Inset const * Paragraph::getInset(pos_type pos) const { lyx::Assert(pos < size()); - return insetlist.get(pos); } @@ -470,11 +463,11 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams, } LyXFont retfont; - if (cit != end) { + if (cit != end) retfont = cit->font(); - } else if (pos == size() && !empty()) { + else if (pos == size() && !empty()) retfont = getFontSettings(bparams, pos - 1); - } else + else retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams)); return retfont; @@ -1291,7 +1284,8 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf, bool Paragraph::isHfill(pos_type pos) const { - return IsHfillChar(getChar(pos)); + return IsInsetChar(getChar(pos)) + && getInset(pos)->lyxCode() == Inset::HFILL_CODE; } @@ -1424,25 +1418,22 @@ string const Paragraph::asString(Buffer const * buffer, bool label) const string const Paragraph::asString(Buffer const * buffer, pos_type beg, pos_type end, bool label) const { - ostringstream ost; + ostringstream os; if (beg == 0 && label && !params().labelString().empty()) - ost << params().labelString() << ' '; + os << params().labelString() << ' '; for (pos_type i = beg; i < end; ++i) { value_type const c = getUChar(buffer->params, i); if (IsPrintable(c)) - ost << c; + os << c; else if (c == META_NEWLINE) - ost << '\n'; - else if (c == META_HFILL) - ost << '\t'; - else if (c == META_INSET) { - getInset(i)->ascii(buffer, ost); - } + os << '\n'; + else if (c == META_INSET) + getInset(i)->ascii(buffer, os); } - return STRCONV(ost.str()); + return STRCONV(os.str()); } @@ -1451,10 +1442,9 @@ void Paragraph::setInsetOwner(Inset * i) pimpl_->inset_owner = i; InsetList::iterator it = insetlist.begin(); InsetList::iterator end = insetlist.end(); - for (; it != end; ++it) { + for (; it != end; ++it) if (it.getInset()) it.getInset()->setOwner(i); - } } diff --git a/src/paragraph.h b/src/paragraph.h index dfbc8d226b..7ffac04de6 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -40,9 +40,7 @@ public: /// enum META_KIND { /// - META_HFILL = 1, - /// - META_NEWLINE, + META_NEWLINE = 2, /// META_INSET }; diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 2e20984399..0db7762521 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -497,9 +497,11 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf, value_type const c) { if (style.pass_thru) { - if (c != '\0') os << c; + if (c != '\0') + os << c; return; } + // Two major modes: LaTeX or plain // Handle here those cases common to both modes // and then split to handle the two modes separately. @@ -574,11 +576,6 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf, running_font = basefont; break; - case Paragraph::META_HFILL: - os << "\\hfill{}"; - column += 7; - break; - default: // And now for the special cases within each mode diff --git a/src/sgml.C b/src/sgml.C index 435d71cc13..e8b6f825f0 100644 --- a/src/sgml.C +++ b/src/sgml.C @@ -26,8 +26,6 @@ pair escapeChar(char c) string str; switch (c) { - case Paragraph::META_HFILL: - break; case Paragraph::META_NEWLINE: str = '\n'; break; diff --git a/src/support/textutils.h b/src/support/textutils.h index 3a239da133..fe07ee7c2c 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -39,14 +39,6 @@ bool IsLineSeparatorChar(char c) } -/// return true if the char is a meta-character for hfill -inline -bool IsHfillChar(char c) -{ - return (c == Paragraph::META_HFILL); -} - - /// return true if the char is a meta-character for an inset inline bool IsInsetChar(char c) @@ -119,7 +111,6 @@ bool IsWordChar(unsigned char c) { return !(IsSeparatorChar(c) || IsKommaChar(c) - || IsHfillChar(c) || IsInsetChar(c)); } diff --git a/src/text.C b/src/text.C index f0e98d86fa..4515e9ff2c 100644 --- a/src/text.C +++ b/src/text.C @@ -221,23 +221,26 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par, if (font.language()->RightToLeft()) { if (font.language()->lang() == "arabic" && (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 || - lyxrc.font_norm_type == LyXRC::ISO_10646_1)) + lyxrc.font_norm_type == LyXRC::ISO_10646_1)) { if (Encodings::IsComposeChar_arabic(c)) return 0; else c = transformChar(c, par, pos); - else if (font.language()->lang() == "hebrew" && + } else if (font.language()->lang() == "hebrew" && Encodings::IsComposeChar_hebrew(c)) return 0; } return font_metrics::width(c, font); - } else if (IsHfillChar(c)) { - // Because of the representation as vertical lines - return 3; - } else if (c == Paragraph::META_INSET) { + } + + if (c == Paragraph::META_INSET) { Inset * tmpinset = par->getInset(pos); if (tmpinset) { + if (tmpinset->lyxCode() == Inset::HFILL_CODE) { + // Because of the representation as vertical lines + return 3; + } #if 1 // this IS needed otherwise on initialitation we don't get the fill // of the row right (ONLY on initialization if we read a file!) @@ -245,10 +248,11 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par, tmpinset->update(bview, font); #endif return tmpinset->width(bview, font); - } else - return 0; + } + return 0; + } - } else if (IsSeparatorChar(c)) + if (IsSeparatorChar(c)) c = ' '; else if (IsNewlineChar(c)) c = 'n'; @@ -2311,7 +2315,7 @@ void LyXText::changeCase(BufferView & bview, LyXText::TextCase action) continue; } unsigned char c = par->getChar(pos); - if (!IsInsetChar(c) && !IsHfillChar(c)) { + if (!IsInsetChar(c)) { switch (action) { case text_lowercase: c = lowercase(c); diff --git a/src/text3.C b/src/text3.C index 0ac114e8ba..e0a7256258 100644 --- a/src/text3.C +++ b/src/text3.C @@ -949,13 +949,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) specialChar(this, bv, InsetSpecialChar::LDOTS); break; - case LFUN_HFILL: - bv->hideCursor(); - update(bv, false); - insertChar(bv, Paragraph::META_HFILL); - update(bv); - break; - case LFUN_END_OF_SENTENCE: specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE); break; @@ -1617,6 +1610,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_INDEX_PRINT: case LFUN_PARENTINSERT: case LFUN_TOC_INSERT: + case LFUN_HFILL: // do nothing fancy doInsertInset(this, cmd, false, false); break; -- 2.39.5