#include "Text.h"
+#include "Bidi.h"
#include "BranchList.h"
#include "FloatList.h"
#include "FuncStatus.h"
#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
-#include "bufferview_funcs.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "debug.h"
#include "gettext.h"
#include "Intl.h"
#include "Language.h"
+#include "Layout.h"
#include "LyXAction.h"
#include "LyXFunc.h"
#include "Lexer.h"
using support::isStrUnsignedInt;
using support::token;
-namespace frontend {
-extern docstring current_layout;
-}
-
-namespace {
-
- // globals...
- Font freefont(Font::ALL_IGNORE);
- bool toggleall = false;
+// globals...
+static Font freefont(Font::ALL_IGNORE);
+static bool toggleall = false;
- 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());
- }
+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);
}
-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);
}
-} // anon namespace
+string const freefont2string()
+{
+ return freefont.toString(toggleall);
+}
void Text::number(Cursor & cur)
needsUpdate |= cursorDownParagraph(cur);
break;
- case LFUN_SCREEN_UP:
case LFUN_SCREEN_UP_SELECT:
- needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
+ needsUpdate |= cur.selHandle(true);
if (cur.pit() == 0 && cur.textRow().pos() == 0)
cur.undispatched();
else {
}
break;
- case LFUN_SCREEN_DOWN:
case LFUN_SCREEN_DOWN_SELECT:
- needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
+ needsUpdate |= cur.selHandle(true);
if (cur.pit() == cur.lastpit()
&& cur.textRow().endpos() == cur.lastpos())
cur.undispatched();
case LFUN_BREAK_PARAGRAPH:
cap::replaceSelection(cur);
- breakParagraph(cur, 0);
+ breakParagraph(cur, false);
cur.resetAnchor();
break;
case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
cap::replaceSelection(cur);
- breakParagraph(cur, 1);
+ breakParagraph(cur, true);
cur.resetAnchor();
break;
if (cur.pos() == 0)
cur.paragraph().params().labelWidthString(docstring());
else
- breakParagraph(cur, 0);
+ breakParagraph(cur, false);
cur.resetAnchor();
break;
}
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();
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())
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;
}
}
}
- if (change_layout) {
+ if (change_layout)
setLayout(cur, layout);
- // inform the GUI that the layout has changed.
- bv->layoutChanged(layout);
- }
+
break;
}
break;
}
- case LFUN_FONT_CODE: {
+ case LFUN_FONT_TYPEWRITER: {
Font font(Font::ALL_IGNORE);
font.setFamily(Font::TYPEWRITER_FAMILY); // no good
toggleAndShow(cur, this, font);
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);
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: {
flag.setOnOff(font.family() == Font::ROMAN_FAMILY);
return true;
- case LFUN_FONT_CODE:
+ case LFUN_FONT_TYPEWRITER:
flag.setOnOff(font.family() == Font::TYPEWRITER_FAMILY);
return true;
case LFUN_WORD_SELECT:
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_DOWN:
- case LFUN_SCREEN_UP:
- case LFUN_SCREEN_DOWN:
case LFUN_LINE_BEGIN:
case LFUN_LINE_END:
case LFUN_BREAK_LINE: