]> git.lyx.org Git - features.git/commitdiff
various cleanups
authorJohn Levon <levon@movementarian.org>
Fri, 9 Aug 2002 00:42:12 +0000 (00:42 +0000)
committerJohn Levon <levon@movementarian.org>
Fri, 9 Aug 2002 00:42:12 +0000 (00:42 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4912 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/ChangeLog
src/Makefile.am
src/buffer.C
src/bufferview_funcs.C
src/frontends/Liason.C
src/lyxfunc.C
src/lyxgluelength.C
src/lyxtext.h
src/paragraph.C
src/paragraph.h
src/paragraph_pimpl.C
src/sgml.C [new file with mode: 0644]
src/sgml.h [new file with mode: 0644]

index 58005e0504f538c4923f88fc73c27a237c7583f4..8244f229e866f8255136e77d7272c045d99135ff 100644 (file)
@@ -1,3 +1,27 @@
+2002-08-09  John Levon  <levon@movementarian.org>
+
+       * Makefile.am:
+       * sgml.h:
+       * sgml.C:
+       * buffer.C:
+       * paragraph.h:
+       * paragraph.C: move sgml char escaping out of paragraph
+       * paragraph.h:
+       * paragraph.C: remove id setter
+       * buffer.C:
+       * paragraph.C: 
+       * paragraph_pimpl.C: remove dead tex_code_break_column
+       * bufferview_funcs.C: small cleanup
+       * lyxfunc.C: remove dead proto 
+
+       * lyxtext.h: make some stuff private. Remove some dead stuff.
+
+       * lyxgluelength.C: make as[LyX]String() readable
 2002-08-08  John Levon  <levon@movementarian.org>
 
        * LyXAction.h:
index cd8cab4bdffeb2c3a18c57f95bb9c985169915fe..cdfa4be849678697fd2d86a01556e64aa01c9397 100644 (file)
@@ -178,10 +178,12 @@ lyx_SOURCES = \
        paragraph_pimpl.C \
        paragraph_pimpl.h \
        SpellBase.h \
-       ispell.h \
        ispell.C \
-       pspell.h \
+       ispell.h \
        pspell.C \
+       pspell.h \
+       sgml.C \
+       sgml.h \
        tabular.C \
        tabular.h \
        tabular-old.C \
index b9aee3eee8a83662687c4c2cdf48a6ee3eb7d084..828debef9bd8013492c4d9f22b08d4010e19c72d 100644 (file)
@@ -44,6 +44,7 @@
 #include "ParagraphParameters.h"
 #include "iterators.h"
 #include "lyxtextclasslist.h"
+#include "sgml.h"
 
 #include "mathed/formulamacro.h"
 #include "mathed/formula.h"
 #include <sys/types.h>
 #include <utime.h>
 
+#include <boost/tuple/tuple.hpp>
 
 #ifdef HAVE_LOCALE
 #include <locale>
@@ -137,17 +139,12 @@ using lyx::textclass_type;
 // all these externs should eventually be removed.
 extern BufferList bufferlist;
 
-extern LyXAction lyxaction;
-
 namespace {
 
 const int LYX_FORMAT = 220;
 
 } // namespace anon
 
-extern int tex_code_break_column;
-
-
 Buffer::Buffer(string const & file, bool ronly)
        : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
          unnamed(false), dep_clean(0), read_only(ronly),
@@ -2165,8 +2162,6 @@ void Buffer::makeLaTeXFile(ostream & os,
 {
        niceFile = nice; // this will be used by Insetincludes.
 
-       tex_code_break_column = lyxrc.ascii_linelen;
-
        // validate the buffer.
        lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
        LaTeXFeatures features(params);
@@ -2191,9 +2186,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        // usual is \batchmode and has a
        // special input@path to allow the including of figures
        // with either \input or \includegraphics (what figinsets do).
-       // batchmode is not set if there is a tex_code_break_column.
-       // In this case somebody is interested in the generated LaTeX,
-       // so this is OK. input@path is set when the actual parameter
+       // input@path is set when the actual parameter
        // original_path is set. This is done for usual tex-file, but not
        // for nice-latex-file. (Matthias 250696)
        if (!only_body) {
@@ -2631,12 +2624,6 @@ void Buffer::makeLaTeXFile(ostream & os,
        // Just to be sure. (Asger)
        texrow.newline();
 
-       // tex_code_break_column's value is used to decide
-       // if we are in batchmode or not (within mathed_write()
-       // in math_write.C) so we must set it to a non-zero
-       // value when we leave otherwise we save incorrect .lyx files.
-       tex_code_break_column = lyxrc.ascii_linelen;
-
        lyxerr[Debug::INFO] << "Finished making latex file." << endl;
        lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
 
@@ -3161,10 +3148,10 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
                                os << c;
                        ++char_line_count;
                } else {
-                       string sgml_string;
-                       if (par->sgmlConvertChar(c, sgml_string)
-                           && !style->free_spacing && !par->isFreeSpacing())
-                       {
+                       bool ws;
+                       string str;
+                       boost::tie(ws, str) = sgml::escapeChar(c);
+                       if (ws && !style->free_spacing && !par->isFreeSpacing()) {
                                // in freespacing mode, spaces are
                                // non-breaking characters
                                if (desc_on) {// if char is ' ' then...
@@ -3178,8 +3165,8 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
                                        os << c;
                                }
                        } else {
-                               os << sgml_string;
-                               char_line_count += sgml_string.length();
+                               os << str;
+                               char_line_count += str.length();
                        }
                }
                font_old = font;
@@ -3551,13 +3538,14 @@ void Buffer::simpleDocBookOnePar(ostream & os,
                        }
                } else {
                        char c = par->getChar(i);
-                       string sgml_string;
-                       par->sgmlConvertChar(c, sgml_string);
+                       bool ws;
+                       string str;
+                       boost::tie(ws, str) = sgml::escapeChar(c);
 
                        if (style->pass_thru) {
                                os << c;
                        } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
-                                       os << sgml_string;
+                                       os << str;
                        } else if (desc_on ==1) {
                                ++char_line_count;
                                os << "\n</term><listitem><para>";
index ee43bd9e11f6a9569c3bef3fc1130882e906a5f2..61f6a226dfe34bcd5377e0de99aa8afebddbc839 100644 (file)
@@ -210,29 +210,32 @@ string const currentState(BufferView * bv)
  */
 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
 {
-       if (bv->available()) {
-               if (bv->theLockingInset()) {
-                       bv->theLockingInset()->setFont(bv, font, toggleall);
-                       return;
-               }
-               LyXText * text = bv->getLyXText();
-               if (!text)
-                       return;
-
-               bv->hideCursor();
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->toggleFree(bv, font, toggleall);
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-
-               if (font.language() != ignore_language ||
-                   font.number() != LyXFont::IGNORE) {
-                       LyXCursor & cursor = text->cursor;
-                       text->computeBidiTables(bv->buffer(), cursor.row());
-                       if (cursor.boundary() !=
-                           text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
-                                            text->real_current_font))
-                               text->setCursor(bv, cursor.par(), cursor.pos(),
-                                               false, !cursor.boundary());
-               }
+       if (!bv->available())
+               return;
+       if (bv->theLockingInset()) {
+               bv->theLockingInset()->setFont(bv, font, toggleall);
+               return;
+       }
+       LyXText * text = bv->getLyXText();
+       // FIXME: can this happen ?? 
+       if (!text)
+               return;
+
+       bv->hideCursor();
+       bv->update(text, BufferView::SELECT | BufferView::FITCUR);
+       text->toggleFree(bv, font, toggleall);
+       bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+
+       if (font.language() != ignore_language ||
+           font.number() != LyXFont::IGNORE) {
+               LyXCursor & cursor = text->cursor;
+               text->computeBidiTables(bv->buffer(), cursor.row());
+               if (cursor.boundary() !=
+                   text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
+                                    text->real_current_font))
+                       text->setCursor(bv, cursor.par(), cursor.pos(),
+                                       false, !cursor.boundary());
        }
 }
index cda33f196f638423811066325b715734046df652..5ea5c4c2d1cea167970fdce851f0812161344251 100644 (file)
@@ -32,8 +32,6 @@
 
 using std::endl;
 
-extern LyXRC lyxrc;
-
 namespace Liason {
 
 PrinterParams getPrinterParams(Buffer * buffer)
index 53b30fbb43a85186fdfe778fd9c63a7cd2079a88..5e85afd224583413adf46e1738db4be037103388 100644 (file)
@@ -114,8 +114,6 @@ extern bool selection_possible;
 
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
-extern void show_symbols_form(LyXFunc *);
-
 // (alkis)
 extern tex_accent_struct get_accent(kb_action action);
 
index 0469b8e7357448e6b84f8d634bf25c7e0859dbb7..fd1cf48565f725efdeec5451932037970a615681 100644 (file)
@@ -41,52 +41,48 @@ string const LyXGlueLength::asString() const
 {
        ostringstream buffer;
 
-       if (!plus_.zero())
-               if (!minus_.zero())
-                       if (len_.unit() == plus_.unit() && len_.unit() == minus_.unit())
-                               if (plus_.value() == minus_.value())
-                                       buffer << len_.value() << "+-"
-                                              << plus_.value() << unit_name[len_.unit()];
-                               else
-                                       buffer << len_.value()
-                                              << '+' << plus_.value()
-                                              << '-' << minus_.value()
-                                              << unit_name[len_.unit()];
-                       else
-                               if (plus_.unit() == minus_.unit()
-                                   && plus_.value() == minus_.value())
-                                       buffer << len_.value() << unit_name[len_.unit()]
-                                              << "+-" << plus_.value()
-                                              << unit_name[plus_.unit()];
-
-                               else
-                                       buffer << len_.value() << unit_name[len_.unit()]
-                                              << '+' << plus_.value()
-                                              << unit_name[plus_.unit()]
-                                              << '-' << minus_.value()
-                                              << unit_name[minus_.unit()];
-               else
-                       if (len_.unit() == plus_.unit())
-                               buffer << len_.value() << '+' << plus_.value()
-                                      << unit_name[len_.unit()];
-                       else
-                               buffer << len_.value() << unit_name[len_.unit()]
-                                      << '+' << plus_.value()
-                                      << unit_name[plus_.unit()];
-
-       else
-               if (!minus_.zero())
-                       if (len_.unit() == minus_.unit())
-                               buffer << len_.value() << '-' << minus_.value()
-                                      << unit_name[len_.unit()];
-
-                       else
-                               buffer << len_.value() << unit_name[len_.unit()]
-                                      << '-' << minus_.value()
-                                      << unit_name[minus_.unit()];
-               else
-                       buffer << len_.value() << unit_name[len_.unit()];
-
+       buffer << len_.value();
+
+       if (plus_.zero() && minus_.zero()) {
+               buffer << unit_name[len_.unit()];
+               return buffer.str().c_str();
+       }
+       // just len and plus
+       if (minus_.zero()) {
+               if (len_.unit() != plus_.unit())
+                       buffer << unit_name[len_.unit()];
+               buffer << "+" << plus_.value();
+               buffer << unit_name[plus_.unit()];
+               return buffer.str().c_str();
+       }
+       // just len and minus
+       if (plus_.zero()) {
+               if (len_.unit() != minus_.unit())
+                       buffer << unit_name[len_.unit()];
+               buffer << "-" << minus_.value();
+               buffer << unit_name[minus_.unit()];
+               return buffer.str().c_str();
+       }
+
+       // ok, len, plus AND minus
+       // len+-
+       if (minus_ == plus_) {
+               if (len_.unit() != minus_.unit())
+                       buffer << unit_name[len_.unit()];
+               buffer << "+-" << minus_.value();
+               buffer << unit_name[minus_.unit()];
+               return buffer.str().c_str();
+       }
+       // this is so rare a case, why bother minimising units ?
+
+       buffer << unit_name[len_.unit()];
+       buffer << "+" << plus_.value() << unit_name[plus_.unit()];
+       buffer << "-" << minus_.value() << unit_name[minus_.unit()];
        return buffer.str().c_str();
 }
 
@@ -95,25 +91,12 @@ string const LyXGlueLength::asLatexString() const
 {
        ostringstream buffer;
 
+       buffer << len_.value() << unit_name[len_.unit()];
        if (!plus_.zero())
-               if (!minus_.zero())
-                       buffer << len_.value() << unit_name[len_.unit()]
-                              << " plus "
-                              << plus_.value() << unit_name[plus_.unit()]
-                              << " minus "
-                              << minus_.value() << unit_name[minus_.unit()];
-               else
-                       buffer << len_.value() << unit_name[len_.unit()]
-                              << " plus "
-                              << plus_.value() << unit_name[plus_.unit()];
-       else
-               if (!minus_.zero())
-                       buffer << len_.value() << unit_name[len_.unit()]
-                              << " minus "
-                              << minus_.value() << unit_name[minus_.unit()];
-               else
-                       buffer << len_.value() << unit_name[len_.unit()];
-
+               buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
+       if (!minus_.zero())
+               buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
        return buffer.str().c_str();
 }
 
index 076562856b2b062e4a91080fa590bec730e57fbc..6b89751d3359206e668560b8f10e536fb6cc4529 100644 (file)
@@ -122,9 +122,6 @@ public:
        ///
        void setLayout(BufferView *, string const & layout);
 
-       /// used in setlayout
-       void makeFontEntriesLayoutSpecific(Buffer const *, Paragraph * par);
-
        /** increment depth over selection and make a total rebreak of those
          paragraphs
          */
@@ -166,11 +163,6 @@ public:
            */
        void redoHeightOfParagraph(BufferView *, LyXCursor const & cursor);
 
-       /** forces the redrawing of a paragraph. Needed when manipulating a
-           right address box
-           */
-       void redoDrawingOfParagraph(BufferView *, LyXCursor const & cursor);
-
        /** insert a character, moves all the following breaks in the
          same Paragraph one to the right and make a little rebreak
          */
@@ -321,9 +313,6 @@ public:
                             bool setfont = true,
                             bool boundary = false) const;
        ///
-       float getCursorX(BufferView *, Row *, lyx::pos_type pos,
-                                        lyx::pos_type last, bool boundary) const;
-       ///
        void setCurrentFont(BufferView *) const;
 
        ///
@@ -392,11 +381,6 @@ public:
        /// Change the case of the word at cursor position.
        void changeCase(BufferView *, TextCase action);
        ///
-       void changeRegionCase(BufferView * bview,
-                                      LyXCursor const & from,
-                                      LyXCursor const & to,
-                                      LyXText::TextCase action);
-       ///
        void transposeChars(BufferView &);
 
        /** returns a printed row in a pixmap. The y value is needed to
@@ -464,12 +448,6 @@ public:
        ///
        void checkParagraph(BufferView *, Paragraph * par, lyx::pos_type pos);
        ///
-       int numberOfCell(Paragraph * par, lyx::pos_type pos) const;
-       ///
-       void removeTableRow(LyXCursor & cursor) const;
-       ///
-       bool isEmptyTableCell() const;
-       ///
        void toggleAppendix(BufferView *);
        ///
        int workWidth(BufferView *) const;
@@ -516,6 +494,22 @@ private:
        ///
        mutable Row * lastrow;
 
+       ///
+       float getCursorX(BufferView *, Row *, lyx::pos_type pos,
+                                        lyx::pos_type last, bool boundary) const;
+       ///
+       void changeRegionCase(BufferView * bview,
+                                      LyXCursor const & from,
+                                      LyXCursor const & to,
+                                      LyXText::TextCase action);
+       /// used in setlayout
+       void makeFontEntriesLayoutSpecific(Buffer const *, Paragraph * par);
+
+       /** forces the redrawing of a paragraph. Needed when manipulating a
+           right address box
+           */
+       void redoDrawingOfParagraph(BufferView *, LyXCursor const & cursor);
+
        /** Copybuffer for copy environment type.
          Asger has learned that this should be a buffer-property instead
          Lgb has learned that 'char' is a lousy type for non-characters
index cc63b355636fac0aac11db0c7b52412fd55e2191..958687f0bfa6c559536e8beef9fea9e750dfab68 100644 (file)
@@ -54,7 +54,6 @@ using std::reverse;
 
 using lyx::pos_type;
 
-int tex_code_break_column = 72;  // needs non-zero initialization. set later.
 // this is a bad idea, but how can Paragraph find its buffer to get
 // parameters? (JMarc)
 
@@ -1188,7 +1187,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
                        texrow.newline();
                }
 
-               if (tex_code_break_column && style->isCommand()) {
+               if (style->isCommand()) {
                        os << '\n';
                        texrow.newline();
                }
@@ -1703,70 +1702,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
 }
 
 
-bool Paragraph::sgmlConvertChar(char c, string & sgml_string)
-{
-       bool retval = false;
-       switch (c) {
-       case Paragraph::META_HFILL:
-               sgml_string.erase();
-               break;
-       case Paragraph::META_NEWLINE:
-               sgml_string = '\n';
-               break;
-       case '&':
-               sgml_string = "&amp;";
-               break;
-       case '<':
-               sgml_string = "&lt;";
-               break;
-       case '>':
-               sgml_string = "&gt;";
-               break;
-       case '$':
-               sgml_string = "&dollar;";
-               break;
-       case '#':
-               sgml_string = "&num;";
-               break;
-       case '%':
-               sgml_string = "&percnt;";
-               break;
-       case '[':
-               sgml_string = "&lsqb;";
-               break;
-       case ']':
-               sgml_string = "&rsqb;";
-               break;
-       case '{':
-               sgml_string = "&lcub;";
-               break;
-       case '}':
-               sgml_string = "&rcub;";
-               break;
-       case '~':
-               sgml_string = "&tilde;";
-               break;
-       case '"':
-               sgml_string = "&quot;";
-               break;
-       case '\\':
-               sgml_string = "&bsol;";
-               break;
-       case ' ':
-               retval = true;
-               sgml_string = ' ';
-               break;
-       case '\0': // Ignore :-)
-               sgml_string.erase();
-               break;
-       default:
-               sgml_string = c;
-               break;
-       }
-       return retval;
-}
-
-
 Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
                                            BufferParams const & bparams,
                                            ostream & os, TexRow & texrow)
@@ -2110,12 +2045,6 @@ int Paragraph::id() const
 }
 
 
-void  Paragraph::id(int id_arg)
-{
-       pimpl_->id_ = id_arg;
-}
-
-
 LyXLayout_ptr const & Paragraph::layout() const
 {
        return layout_;
index d44cd40fdd3195ba72f088c0e3f07b6c3c741f50..99f86cd5f5234104c19a4b07acbac9a88d18b67b 100644 (file)
@@ -113,11 +113,9 @@ public:
        ///
        void validate(LaTeXFeatures &) const;
 
-       ///
+       /// return the unique ID of this paragraph
        int id() const;
        ///
-       void id(int id_arg);
-       ///
        void read();
 
        ///
@@ -326,8 +324,6 @@ public:
        ///
        void unsetPExtraType(BufferParams const &);
 #endif
-       ///
-       bool sgmlConvertChar(char c, string & sgml_string);
        ///
        bool isFreeSpacing() const;
 
index 60aebb7831e47e5523e1baece9e1be3008990d3c..0e4578fb0bf7c3b6f81cb3f9dac5db5b925fa84f 100644 (file)
@@ -31,9 +31,6 @@ using std::ostream;
 using std::upper_bound;
 using std::lower_bound;
 
-extern int tex_code_break_column;
-
-
 // Initialize static member.
 ShareContainer<LyXFont> Paragraph::Pimpl::FontTable::container;
 // Initialization of the counter for the paragraph id's,
@@ -249,7 +246,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow,
                                       LyXLayout const & style)
 {
        if (style.pass_thru) return;
-       if (column > tex_code_break_column
+       if (column > lyxrc.ascii_linelen
            && i
            && getChar(i - 1) != ' '
            && (i < size() - 1)
@@ -263,13 +260,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow,
                     || getChar(i - 1) == '?'
                     || getChar(i - 1) == ':'
                     || getChar(i - 1) == '!'))) {
-               if (tex_code_break_column == 0) {
-                       // in batchmode we need LaTeX to still
-                       // see it as a space not as an extra '\n'
-                       os << " %\n";
-               } else {
-                       os << '\n';
-               }
+               os << '\n';
                texrow.newline();
                texrow.start(owner_, i + 1);
                column = 0;
diff --git a/src/sgml.C b/src/sgml.C
new file mode 100644 (file)
index 0000000..b170d7b
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * \file sgml.C
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author José Matos
+ * \author John Levon <levon@movementarian.org>
+ */
+
+#include "sgml.h"
+#include "paragraph.h"
+using std::pair;
+using std::make_pair;
+namespace sgml {
+
+pair<bool, string> escapeChar(char c)
+{
+       string str;
+       switch (c) {
+       case Paragraph::META_HFILL:
+               break;
+       case Paragraph::META_NEWLINE:
+               str = '\n';
+               break;
+       case ' ':
+               return make_pair(true, string(" "));
+               break;
+       case '\0': // Ignore :-)
+               str.erase();
+               break;
+       case '&':
+               str = "&amp;";
+               break;
+       case '<':
+               str = "&lt;";
+               break;
+       case '>':
+               str = "&gt;";
+               break;
+       case '$':
+               str = "&dollar;";
+               break;
+       case '#':
+               str = "&num;";
+               break;
+       case '%':
+               str = "&percnt;";
+               break;
+       case '[':
+               str = "&lsqb;";
+               break;
+       case ']':
+               str = "&rsqb;";
+               break;
+       case '{':
+               str = "&lcub;";
+               break;
+       case '}':
+               str = "&rcub;";
+               break;
+       case '~':
+               str = "&tilde;";
+               break;
+       case '"':
+               str = "&quot;";
+               break;
+       case '\\':
+               str = "&bsol;";
+               break;
+       default:
+               str = c;
+               break;
+       }
+       return make_pair(false, str);
+}
+
+} // namespace sgml
diff --git a/src/sgml.h b/src/sgml.h
new file mode 100644 (file)
index 0000000..e3040e5
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * \file sgml.h
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author José Matos
+ * \author John Levon <levon@movementarian.org>
+ */
+
+#ifndef SGML_H
+#define SGML_H
+#include <config.h>
+
+#include "LString.h"
+#include <algorithm>
+namespace sgml {
+
+/**
+ * Escape the given character if necessary
+ * to an SGML entity. The bool return is true
+ * if it was a whitespace character.
+ */
+std::pair<bool, string> escapeChar(char c);
+
+}
+
+#endif // SGML_H