]> git.lyx.org Git - features.git/commitdiff
changeCase fix
authorLars Gullik Bjønnes <larsbj@gullik.org>
Wed, 27 Jun 2001 18:29:18 +0000 (18:29 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Wed, 27 Jun 2001 18:29:18 +0000 (18:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2149 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/lyxcursor.C
src/lyxcursor.h
src/mathed/math_macro.C
src/text.C

index ce555ac05e5d754d3b8aab796453cb9ba7a15c31..96f2b35dcde66c5551e66871f691cb887d74074f 100644 (file)
@@ -1,5 +1,14 @@
 2001-06-27  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
+       * lyxcursor.h (operator<): new func
+       (operator>): new func
+       (operator>=): new func
+       (operator<=): new func
+
+       * text.C (changeCase): use selection.start and selection.end
+       (changeRegionCase): require from to be <= to. Require par to be a
+       valid paragraph.
+
        * LaTeXFeatures.C (getFloatDefinitions): std:: qualify ostream
 
 2001-06-27  Juergen Vigna  <jug@sad.it>
index 94b31e8d13d59693b7c95d1f9842c0e8ba14b6dc..2bd2e5f9a2a94a5afd39eed0dbae0a49062f2dae 100644 (file)
@@ -29,10 +29,10 @@ void LyXCursor::par(Paragraph * p)
 }
 
 
-Paragraph * LyXCursor::par()
-{
-       return par_;
-}
+//Paragraph * LyXCursor::par()
+//{
+//     return par_;
+//}
 
 
 Paragraph * LyXCursor::par() const
@@ -106,10 +106,10 @@ void LyXCursor::row(Row * r)
 }
 
 
-Row * LyXCursor::row()
-{
-       return row_;
-}
+//Row * LyXCursor::row()
+//{
+//     return row_;
+//}
 
 
 Row * LyXCursor::row() const
index 0fdf06a2961d30637f34f768f4fea6e619932d55..a3025e4073fe594bd6beffa275fb32bbd1d0318f 100644 (file)
@@ -28,7 +28,7 @@ public:
        ///
        void par(Paragraph * p);
        ///
-       Paragraph * par();
+       //Paragraph * par();
        ///
        Paragraph * par() const;
        ///
@@ -54,7 +54,7 @@ public:
        ///
        void row(Row * r);
        ///
-       Row * row();
+       //Row * row();
        ///
        Row * row() const;
 private:
@@ -90,4 +90,42 @@ bool operator!=(LyXCursor const & a, LyXCursor const & b)
        return !(a == b);
 }
 
+///
+inline
+bool operator<(LyXCursor const & a, LyXCursor const & b) 
+{
+       // Can this be done in a nother way?
+       return (a.y() < b.y() && a.pos() < b.pos());
+}
+
+///
+inline
+bool operator>(LyXCursor const & a, LyXCursor const & b) 
+{
+       return b < a;
+}
+
+///
+inline
+bool operator>=(LyXCursor const & a, LyXCursor const & b)
+{
+#if 0
+       return (a > b || a == b);
+#else
+       return !(a < b);
+#endif
+}
+
+
+///
+inline
+bool operator<=(LyXCursor const & a, LyXCursor const & b)
+{
+#if 0
+       return (a < b || a == b);
+#else
+       return !(a > b);
+#endif
+}
+
 #endif
index d91fd3deb93b2927cdf213631937c95d7b234685..aaaf5a328db1ede15ec8e8b2ca1ffd08a08a8fd1 100644 (file)
@@ -31,7 +31,6 @@
 #include "math_macrotemplate.h"
 #include "Painter.h"
 
-using std::ostream;
 using std::endl;
 
 MathMacro::MathMacro(MathMacroTemplate const & t)
@@ -110,7 +109,7 @@ void MathMacro::draw(Painter & pain, int x, int y)
 }
 
 
-void MathMacro::dump(ostream & os) const
+void MathMacro::dump(std::ostream & os) const
 {
        MathMacroTable::dump();
        os << "\n macro: '" << this << "'\n";
@@ -120,7 +119,7 @@ void MathMacro::dump(ostream & os) const
        os << endl;
 }
 
-void MathMacro::Write(ostream & os, bool fragile) const
+void MathMacro::Write(std::ostream & os, bool fragile) const
 {
        os << '\\' << name_;
        for (int i = 0; i < nargs(); ++i) {
@@ -133,7 +132,7 @@ void MathMacro::Write(ostream & os, bool fragile) const
 }
 
 
-void MathMacro::WriteNormal(ostream & os) const
+void MathMacro::WriteNormal(std::ostream & os) const
 {
        os << "[macro " << name_ << " ";
        for (int i = 0; i < nargs(); ++i) {
index 06d534a349fc6755416cedc01cba1d864a57007d..2a30f1acf124fe3aef702594ba541570c872920b 100644 (file)
@@ -2396,49 +2396,14 @@ void LyXText::changeCase(BufferView * bview, LyXText::TextCase action)
        LyXCursor to;
 
        if (selection.set()) {
-               from = selection.cursor;
-               to = cursor;
+               from = selection.start;
+               to = selection.end;
        } else {
                getWord(from, to, PARTIAL_WORD);
-               setCursor(bview, to.par(), to.pos()+1);
+               setCursor(bview, to.par(), to.pos() + 1);
        }
 
-       setUndo(bview->buffer(), Undo::FINISH,
-               from.par()->previous(), to.par()->next()); 
-
-#if 1
-       changeRegionCase(bview, to, from, action);
-#else
-       while(from != to) {
-               unsigned char c = from.par()->getChar(from.pos());
-               if (!IsInsetChar(c) && !IsHfillChar(c)) {
-                       switch (action) {
-                       case text_lowercase:
-                               c = tolower(c);
-                               break;
-                       case text_capitalization:
-                               c = toupper(c);
-                               action = text_lowercase;
-                               break;
-                       case text_uppercase:
-                               c = toupper(c);
-                               break;
-                       }
-               }
-               from.par()->setChar(from.pos(), c);
-               checkParagraph(bview, from.par(), from.pos());
-               from.pos(from.pos() + 1);
-               if (from.pos() >= from.par()->size()) {
-                       from.par(from.par()->next());
-                       from.pos(0);
-               }
-       }
-       if (to.row() != from.row()) {
-               refresh_y = from.y() - from.row()->baseline();
-               refresh_row = from.row();
-               status = LyXText::NEED_MORE_REFRESH;
-       }
-#endif
+       changeRegionCase(bview, from, to, action);
 }
 
 
@@ -2447,13 +2412,16 @@ void LyXText::changeRegionCase(BufferView * bview,
                               LyXCursor const & to,
                               LyXText::TextCase action)
 {
+       lyx::Assert(from <= to);
+       
        setUndo(bview->buffer(), Undo::FINISH,
                from.par()->previous(), to.par()->next());
 
-       LyXCursor tmp(from);
-       
-       while(tmp != to) {
-               unsigned char c = tmp.par()->getChar(tmp.pos());
+       Paragraph::size_type pos = from.pos();
+       Paragraph * par = from.par();
+
+       while (par && (pos != to.pos() || par != to.par())) {
+               unsigned char c = par->getChar(pos);
                if (!IsInsetChar(c) && !IsHfillChar(c)) {
                        switch (action) {
                        case text_lowercase:
@@ -2468,17 +2436,18 @@ void LyXText::changeRegionCase(BufferView * bview,
                                break;
                        }
                }
-               tmp.par()->setChar(tmp.pos(), c);
-               checkParagraph(bview, tmp.par(), tmp.pos());
-               tmp.pos(tmp.pos() + 1);
-               if (tmp.pos() >= tmp.par()->size()) {
-                       tmp.par(tmp.par()->next());
-                       tmp.pos(0);
+               par->setChar(pos, c);
+               checkParagraph(bview, par, pos);
+
+               ++pos;
+               if (pos == par->size()) {
+                       par = par->next();
+                       pos = 0;
                }
        }
-       if (to.row() != tmp.row()) {
-               refresh_y = tmp.y() - tmp.row()->baseline();
-               refresh_row = tmp.row();
+       if (to.row() != from.row()) {
+               refresh_y = from.y() - from.row()->baseline();
+               refresh_row = from.row();
                status = LyXText::NEED_MORE_REFRESH;
        }
 }