]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Cosmetics.
[lyx.git] / src / Text3.cpp
index 75ff5a018d52e6656cc3941d0f47be2fb97e7fe9..3b9ea74184e125577b580447b8ed048750baeb98 100644 (file)
@@ -25,7 +25,6 @@
 #include "buffer_funcs.h"
 #include "BufferParams.h"
 #include "BufferView.h"
-#include "bufferview_funcs.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
 #include "debug.h"
@@ -36,6 +35,7 @@
 #include "gettext.h"
 #include "Intl.h"
 #include "Language.h"
+#include "Layout.h"
 #include "LyXAction.h"
 #include "LyXFunc.h"
 #include "Lexer.h"
@@ -86,116 +86,92 @@ using cap::replaceSelection;
 using support::isStrUnsignedInt;
 using support::token;
 
-namespace frontend {
-extern docstring current_layout;
-}
-
-namespace {
-
-       // globals...
-       Font freefont(Font::ALL_IGNORE);
-       bool toggleall = false;
-
-       void toggleAndShow(Cursor & cur, Text * text,
-               Font const & font, bool toggleall = true)
-       {
-               text->toggleFree(cur, font, toggleall);
+// globals...
+static Font freefont(Font::ALL_IGNORE);
+static bool toggleall = false;
 
-               if (font.language() != ignore_language ||
-                               font.number() != Font::IGNORE) {
-                       TextMetrics const & tm = cur.bv().textMetrics(text);
-                       if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
-                                               cur.pos(), cur.real_current_font))
-                               text->setCursor(cur, cur.pit(), cur.pos(),
-                                               false, !cur.boundary());
-               }
+static void toggleAndShow(Cursor & cur, Text * text,
+       Font const & font, bool toggleall = true)
+{
+       text->toggleFree(cur, font, toggleall);
+
+       if (font.language() != ignore_language ||
+                       font.number() != Font::IGNORE) {
+               TextMetrics const & tm = cur.bv().textMetrics(text);
+               if (cur.boundary() != tm.isRTLBoundary(cur.pit(),
+                                                                                                               cur.pos(), cur.real_current_font))
+                       text->setCursor(cur, cur.pit(), cur.pos(),
+                                                                                       false, !cur.boundary());
        }
+}
 
 
-       void moveCursor(Cursor & cur, bool selecting)
-       {
-               if (selecting || cur.mark())
-                       cur.setSelection();
-       }
+static void moveCursor(Cursor & cur, bool selecting)
+{
+       if (selecting || cur.mark())
+               cur.setSelection();
+}
 
 
-       void finishChange(Cursor & cur, bool selecting)
-       {
-               finishUndo();
-               moveCursor(cur, selecting);
-       }
+static void finishChange(Cursor & cur, bool selecting)
+{
+       finishUndo();
+       moveCursor(cur, selecting);
+}
 
 
-       void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
-       {
-               recordUndo(cur);
-               docstring sel = cur.selectionAsString(false);
+static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
+{
+       recordUndo(cur);
+       docstring sel = cur.selectionAsString(false);
 
-               // It may happen that sel is empty but there is a selection
-               replaceSelection(cur);
+       // It may happen that sel is empty but there is a selection
+       replaceSelection(cur);
 
-               if (sel.empty()) {
+       if (sel.empty()) {
 #ifdef ENABLE_ASSERTIONS
-                       const int old_pos = cur.pos();
+               const int old_pos = cur.pos();
 #endif
-                       cur.insert(new InsetMathHull(hullSimple));
-                       BOOST_ASSERT(old_pos == cur.pos());
-                       cur.nextInset()->edit(cur, true);
-                       // don't do that also for LFUN_MATH_MODE
-                       // unless you want end up with always changing
-                       // to mathrm when opening an inlined inset --
-                       // I really hate "LyXfunc overloading"...
-                       if (display)
-                               cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
-                       // Avoid an unnecessary undo step if cmd.argument
-                       // is empty
-                       if (!cmd.argument().empty())
-                               cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
-                                                        cmd.argument()));
+               cur.insert(new InsetMathHull(hullSimple));
+               BOOST_ASSERT(old_pos == cur.pos());
+               cur.nextInset()->edit(cur, true);
+               // don't do that also for LFUN_MATH_MODE
+               // unless you want end up with always changing
+               // to mathrm when opening an inlined inset --
+               // I really hate "LyXfunc overloading"...
+               if (display)
+                       cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
+               // Avoid an unnecessary undo step if cmd.argument
+               // is empty
+               if (!cmd.argument().empty())
+                       cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
+                                                cmd.argument()));
+       } else {
+               // create a macro if we see "\\newcommand"
+               // somewhere, and an ordinary formula
+               // otherwise
+               if (sel.find(from_ascii("\\newcommand")) == string::npos
+                               && sel.find(from_ascii("\\def")) == string::npos)
+               {
+                       InsetMathHull * formula = new InsetMathHull;
+                       istringstream is(to_utf8(sel));
+                       Lexer lex(0, 0);
+                       lex.setStream(is);
+                       formula->read(cur.buffer(), lex);
+                       if (formula->getType() == hullNone)
+                               // Don't create pseudo formulas if
+                               // delimiters are left out
+                               formula->mutate(hullSimple);
+                       cur.insert(formula);
                } else {
-                       // create a macro if we see "\\newcommand"
-                       // somewhere, and an ordinary formula
-                       // otherwise
-                       if (sel.find(from_ascii("\\newcommand")) == string::npos
-                           && sel.find(from_ascii("\\def")) == string::npos)
-                       {
-                               InsetMathHull * formula = new InsetMathHull;
-                               istringstream is(to_utf8(sel));
-                               Lexer lex(0, 0);
-                               lex.setStream(is);
-                               formula->read(cur.buffer(), lex);
-                               if (formula->getType() == hullNone)
-                                       // Don't create pseudo formulas if
-                                       // delimiters are left out
-                                       formula->mutate(hullSimple);
-                               cur.insert(formula);
-                       } else {
-                               cur.insert(new MathMacroTemplate(sel));
-                       }
+                       cur.insert(new MathMacroTemplate(sel));
                }
-               cur.message(from_utf8(N_("Math editor mode")));
        }
-
-} // namespace anon
-
-
-
-namespace bv_funcs {
-
-string const freefont2string()
-{
-       string data;
-       if (font2string(freefont, toggleall, data))
-               return data;
-       return string();
-}
-
+       cur.message(from_utf8(N_("Math editor mode")));
 }
 
 
-namespace {
-
-void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
+static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
 {
        recordUndo(cur);
        cap::replaceSelection(cur);
@@ -204,7 +180,7 @@ void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
 }
 
 
-bool doInsertInset(Cursor & cur, Text * text,
+static bool doInsertInset(Cursor & cur, Text * text,
        FuncRequest const & cmd, bool edit, bool pastesel)
 {
        Inset * inset = createInset(&cur.bv(), cmd);
@@ -235,7 +211,10 @@ bool doInsertInset(Cursor & cur, Text * text,
 }
 
 
-} // anon namespace
+string const freefont2string()
+{
+       return freefont.toString(toggleall);
+}
 
 
 void Text::number(Cursor & cur)
@@ -385,8 +364,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
-               } else
-                       cur.setCurrentFont();
+               }
                break;
 
        case LFUN_CHAR_BACKWARD:
@@ -402,8 +380,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
-               } else
-                       cur.setCurrentFont();
+               }
                break;
 
        case LFUN_UP_SELECT:
@@ -791,6 +768,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                docstring layout = cmd.argument();
                LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
 
+               docstring const old_layout = cur.paragraph().layout()->name();
+
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number)
                TextClass const & tclass = bv->buffer().params().getTextClass();
@@ -811,7 +790,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        break;
                }
 
-               bool change_layout = (frontend::current_layout != layout);
+               bool change_layout = (old_layout != layout);
 
                if (!change_layout && cur.selection() &&
                        cur.selBegin().pit() != cur.selEnd().pit())
@@ -819,7 +798,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        pit_type spit = cur.selBegin().pit();
                        pit_type epit = cur.selEnd().pit() + 1;
                        while (spit != epit) {
-                               if (pars_[spit].layout()->name() != frontend::current_layout) {
+                               if (pars_[spit].layout()->name() != old_layout) {
                                        change_layout = true;
                                        break;
                                }
@@ -827,11 +806,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        }
                }
 
-               if (change_layout) {
+               if (change_layout)
                        setLayout(cur, layout);
-                       // inform the GUI that the layout has changed.
-                       bv->layoutChanged(layout);
-               }
+
                break;
        }
 
@@ -1366,7 +1343,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FONT_FREE_UPDATE: {
                Font font;
                bool toggle;
-               if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
+               if (font.fromString(to_utf8(cmd.argument()), toggle)) {
                        freefont = font;
                        toggleall = toggle;
                        toggleAndShow(cur, this, freefont, toggleall);
@@ -1377,14 +1354,18 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_FINISHED_LEFT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
-               if (reverseDirectionNeeded(cur))
+               if (reverseDirectionNeeded(cur)) {
                        ++cur.pos();
+                       cur.setCurrentFont();
+               }
                break;
 
        case LFUN_FINISHED_RIGHT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
-               if (!reverseDirectionNeeded(cur))
+               if (!reverseDirectionNeeded(cur)) {
                        ++cur.pos();
+                       cur.setCurrentFont();
+               }
                break;
 
        case LFUN_LAYOUT_PARAGRAPH: {