*/
#include <config.h>
+#include <fstream>
#include "Lsstream.h"
#include "math_cursor.h"
#include "math_parser.h"
#include "lyx_main.h"
-#include "minibuffer.h"
#include "BufferView.h"
#include "lyxtext.h"
#include "gettext.h"
#include "debug.h"
#include "lyx_gui_misc.h"
#include "support/LOstream.h"
+#include "support/lyxlib.h"
+#include "support/syscall.h"
#include "LyXView.h"
#include "Painter.h"
#include "font.h"
-#include "support/lyxlib.h"
#include "lyxrc.h"
#include "math_inset.h"
#include "math_parinset.h"
#include "math_deliminset.h"
#include "mathed/support.h"
+using std::ostringstream;
using std::ostream;
+using std::ifstream;
using std::istream;
using std::pair;
using std::endl;
// this is only used by Whichfont and mathed_init_fonts (Lgb)
LyXFont * Math_Fonts = 0;
-static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
-// local global
-static int sel_x;
-static int sel_y;
-static bool sel_flag;
+MathedCursor * mathcursor = 0;
-// quite a hack i know. Should be done with return values...
-int number_of_newlines = 0;
-static
+namespace {
+
+LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
+
+// local global
+int sel_x;
+int sel_y;
+bool sel_flag;
+
int mathed_write(MathParInset *, std::ostream &, bool fragile,
string const & label = string());
void mathed_init_fonts();
-static
void mathedValidate(LaTeXFeatures & features, MathParInset * par);
+} // namespaces
-MathedCursor * InsetFormula::mathcursor = 0;
LyXFont WhichFont(short type, int size)
}
+namespace {
+
void mathed_init_fonts() //removed 'static' because DEC cxx does not
//like it (JMarc)
// Probably because this func is declared as a friend in math_defs.h
MathedInset::defaultWidth(lyxfont::width('I', f));
}
+} // namespace anon
+
+
+// quite a hack i know. Should be done with return values...
+int number_of_newlines = 0;
InsetFormula::InsetFormula(bool display)
new MathParInset(*p);
// mathcursor = 0;
- disp_flag_ = (par->GetType()>0);
+ disp_flag_ = par->GetType() > 0;
}
InsetFormula::~InsetFormula()
{
- delete par;
+#ifdef WITH_WARNINGS
+#warning leak this for a while...
+#endif
+ //delete par;
}
Inset * InsetFormula::Clone(Buffer const &) const
{
- InsetFormula * f = new InsetFormula(par);
- f->label_ = label_;
- return f;
+ return new InsetFormula(par);
}
int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
{
- //#warning Alejandro, the number of lines is not returned in this case
- // This problem will disapear at 0.13.
- return mathed_write(par, os, fragile, label_);
+ return mathed_write(par, os, fragile, par->label());
}
mathed_parser_file(is, lex.GetLineNo());
- // Silly hack to read labels.
- mathed_label.erase();
-
MathedArray ar;
- mathed_parse(ar, 0, &par);
+ mathed_parse(ar, par, 0);
+ if (par->isMatrix()) {
+ //lyxerr << "################## InsetFormula::Read: IsMatrix\n";
+ static_cast<MathMatrixInset*>(par)->setData(ar);
+ }
+ else {
+ par->setData(ar);
+ //lyxerr << "################## InsetFormula::Read: keine Matrix\n";
+ }
+
+ //lyxerr << "InsetFormula::Read: par: " << par << " " << par->GetData() << endl;
+
par->Metrics();
disp_flag_ = (par->GetType() > 0);
// Update line number
lex.setLineNo(mathed_parser_lineno());
- if (!mathed_label.empty()) {
- label_ = mathed_label;
- mathed_label.erase();
- }
-
// reading of end_inset in the inset!!!
while (lex.IsOK()) {
lex.nextToken();
if (is_singlely_numbered(par->GetType())) {
string str;
- if (!label_.empty())
- str = string("(") + label_ + ")";
+ if (!par->label().empty())
+ str = string("(") + par->label() + ")";
else
str = string("(#)");
pain.text(int(x + 20), baseline, str, wfont);
} else {
- MathMatrixInset * mt =
- static_cast<MathMatrixInset*>(par);
- MathedRowSt const * crow = mt->getRowSt();
+ MathedRowContainer::iterator crow = par->getRowSt().begin();
while (crow) {
int const y = baseline + crow->getBaseline();
if (crow->isNumbered()) {
str = "(#)";
pain.text(int(x + 20), y, str, wfont);
}
- crow = crow->getNext();
+ ++crow;
}
}
}
- cursor_visible = false;
+ setCursorVisible(false);
}
// Now a symbol can be inserted only if the inset is locked
-void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
+void InsetFormula::InsertSymbol(BufferView *, string const & s)
{
if (s.empty() || !mathcursor)
return;
mathcursor->Interpret(s);
- UpdateLocal(bv);
+ // Andre: UpdateLocal(bv);
}
// x -= par->xo;
y -= par->yo();
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
- int asc = lyxfont::maxAscent(font);
- int desc = lyxfont::maxDescent(font);
+ int const asc = lyxfont::maxAscent(font);
+ int const desc = lyxfont::maxDescent(font);
- if (cursor_visible)
+ if (isCursorVisible())
bv->hideLockedInsetCursor();
else
bv->showLockedInsetCursor(x, y, asc, desc);
- cursor_visible = !cursor_visible;
+ toggleCursorVisible();
}
void InsetFormula::ShowInsetCursor(BufferView * bv, bool)
{
- if (!cursor_visible) {
+ if (!isCursorVisible()) {
if (mathcursor) {
int x;
int y;
// x -= par->xo;
y -= par->yo();
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
- int asc = lyxfont::maxAscent(font);
- int desc = lyxfont::maxDescent(font);
+ int const asc = lyxfont::maxAscent(font);
+ int const desc = lyxfont::maxDescent(font);
bv->fitLockedInsetCursor(x, y, asc, desc);
}
ToggleInsetCursor(bv);
void InsetFormula::HideInsetCursor(BufferView * bv)
{
- if (cursor_visible)
+ if (isCursorVisible())
ToggleInsetCursor(bv);
}
}
par->SetType(LM_OT_MIN);
par->SetStyle(LM_ST_TEXT);
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
if (!label_.empty()) {
label_.erase();
}
+*/
}
disp_flag_ = dspf;
}
vector<string> const InsetFormula::getLabelList() const
{
- //#warning This is dirty, I know. Ill clean it at 0.11
- // Correction, the only way to clean this is with a new kernel: 0.13.
-
vector<string> label_list;
-
- if (is_multi_numbered(par->GetType())) {
- MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
- MathedRowSt const * crow = mt->getRowSt();
- while (crow) {
- if (!crow->getLabel().empty())
- label_list.push_back(crow->getLabel());
- crow = crow->getNext();
- }
- } else if (!label_.empty())
- label_list.push_back(label_);
+ MathedRowContainer::iterator crow = par->getRowSt().begin();
+ for ( ; crow; ++crow)
+ label_list.push_back(crow->getLabel());
return label_list;
}
InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
string const & arg)
{
+ //lyxerr << "InsetFormula::LocalDispatch: act: " << action
+ // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
// extern char *dispatch_result;
+
+ if (!mathcursor) {
+ return UNDISPATCHED;
+ }
+
MathedTextCodes varcode = LM_TC_MIN;
bool was_macro = mathcursor->InMacroMode();
bool sel = false;
result = DISPATCH_RESULT(mathcursor->Right(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
result = DISPATCH_RESULT(mathcursor->Left(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
result = DISPATCH_RESULT(mathcursor->Up(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
result = DISPATCH_RESULT(mathcursor->Down(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->DelLine();
+ // Andre:
UpdateLocal(bv);
break;
bv->lockedInsetStoreUndo(Undo::INSERT);
byte c = arg.empty() ? '1' : arg[0];
mathcursor->Insert(c, LM_TC_CR);
- if (!label_.empty()) {
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
+ if (!par->label().empty()) {
mathcursor->setLabel(label_);
label_.erase();
}
+*/
par = mathcursor->GetPar();
+ // Andre:
UpdateLocal(bv);
}
break;
case LFUN_TABINSERT:
bv->lockedInsetStoreUndo(Undo::INSERT);
mathcursor->Insert('T', LM_TC_TAB);
+ // Andre:
UpdateLocal(bv);
break;
mathcursor->MacroModeClose();
bv->lockedInsetStoreUndo(Undo::INSERT);
mathcursor->SelPaste();
+ // Andre:
UpdateLocal(bv);
break;
case LFUN_CUT:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->SelCut();
+ // Andre:
UpdateLocal(bv);
break;
case LFUN_GREEK:
if (!greek_kb_flag) {
greek_kb_flag = 1;
- bv->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
+ bv->owner()->message(_("Math greek mode on"));
} else
greek_kb_flag = 0;
break;
case LFUN_GREEK_TOGGLE:
greek_kb_flag = (greek_kb_flag) ? 0 : 2;
if (greek_kb_flag)
- bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
+ bv->owner()->message(_("Math greek keyboard on"));
else
- bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
+ bv->owner()->message(_("Math greek keyboard off"));
break;
// Math fonts
case LFUN_TEX:
// varcode = LM_TC_TEX;
mathcursor->setLastCode(LM_TC_TEX);
- bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
+ bv->owner()->message(_("TeX mode"));
break;
case LFUN_MATH_NUMBER:
short type = par->GetType();
if (is_numbered(type)) {
--type;
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
if (!label_.empty()) {
label_.erase();
}
- bv->owner()->getMiniBuffer()->Set(_("No number"));
+*/
+ bv->owner()->message(_("No number"));
} else {
++type;
- bv->owner()->getMiniBuffer()->Set(_("Number"));
+ bv->owner()->message(_("Number"));
}
par->SetType(type);
+ // Andre:
UpdateLocal(bv);
}
break;
case LFUN_MATH_NONUMBER:
if (is_multi_numbered(par->GetType())) {
- // MathMatrixInset *mt = (MathMatrixInset*)par;
//BUG
- // mt->SetNumbered(!mt->IsNumbered());
+ // par->SetNumbered(!par->IsNumbered());
+#ifdef WITH_WARNINGS
#warning This is a terrible hack! We should find a better solution.
+#endif
while (mathcursor->getLabel() == MathedXIter::error_label) {
if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
return DISPATCHED;
}
mathcursor->setNumbered();
+ // Andre:
UpdateLocal(bv);
}
break;
case LFUN_MATH_LIMITS:
bv->lockedInsetStoreUndo(Undo::INSERT);
if (mathcursor->Limits())
+ // Andre:
UpdateLocal(bv);
// fall through!
case LFUN_MATH_SIZE:
if (!arg.empty()) {
latexkeys const * l = in_word_set(arg);
- int const sz = (l) ? l->id: -1;
+ int const sz = l ? l->id : -1;
mathcursor->SetSize(sz);
+ // Andre:
UpdateLocal(bv);
break;
}
case LFUN_INSERT_MATH:
bv->lockedInsetStoreUndo(Undo::INSERT);
InsertSymbol(bv, arg);
+ UpdateLocal(bv);
break;
n = 1;
}
- MathMatrixInset * p = new MathMatrixInset(m, n);
- if (mathcursor && p) {
+ if (mathcursor) {
+ MathMatrixInset * p = new MathMatrixInset(m, n);
if (k > 2 && int(strlen(s)) > m)
p->SetAlign(s[0], &s[1]);
mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
+ // Andre:
UpdateLocal(bv);
}
break;
ilf = lyx::atoi(lf);
else
if (lf[1]) {
- l = in_word_set(lf, strlen(lf));
+ l = in_word_set(lf);
// Long words will cause l == 0; so check.
if (l)
ilf = l->id;
irg = lyx::atoi(rg);
else
if (rg[1]) {
- l = in_word_set(rg, strlen(rg));
+ l = in_word_set(rg);
if (l)
irg = l->id;
} else if (vdelim.find(rg[0]) != string::npos)
MathDelimInset * p = new MathDelimInset(ilf, irg);
mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
+ // Andre:
UpdateLocal(bv);
break;
}
sp = new MathSpaceInset(1);
mathcursor->insertInset(sp, LM_TC_INSET);
space_on = true;
+ // Andre:
UpdateLocal(bv);
break;
break;
string old_label = is_multiline(par->GetType())
- ? mathcursor->getLabel() : label_;
+ ? mathcursor->getLabel() : par->label();
+#ifdef WITH_WARNINGS
#warning This is a terrible hack! We should find a better solution.
+#endif
// This is needed because in some positions
// mathcursor->cursor->crow is equal to 0, and therefore
// the label cannot be inserted.
string new_label = arg;
if (new_label.empty()) {
- string default_label = (lyxrc.label_init_length >= 0) ? "eq:" : "";
- pair<bool, string> res = old_label.empty()
- ? askForText(_("Enter new label to insert:"), default_label)
+ string const default_label =
+ (lyxrc.label_init_length >= 0) ? "eq:" : "";
+ pair<bool, string> const res = old_label.empty()
+ ? askForText(_("Enter new label to insert:"),
+ default_label)
: askForText(_("Enter label:"), old_label);
if (!res.first)
break;
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw();
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
if (is_multi_numbered(par->GetType())) {
mathcursor->setLabel(new_label);
- // MathMatrixInset *mt = (MathMatrixInset*)par;
- // mt->SetLabel(new_label);
+ // par->SetLabel(new_label);
} else
label_ = new_label;
+*/
+ // Andre:
UpdateLocal(bv);
break;
}
case LFUN_MATH_DISPLAY:
bv->lockedInsetStoreUndo(Undo::EDIT);
display(!disp_flag_);
+ // Andre:
UpdateLocal(bv);
break;
// Invalid actions under math mode
case LFUN_MATH_MODE:
if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
- bv->owner()->getMiniBuffer()->Set(_("math text mode"));
+ bv->owner()->message(_("math text mode"));
varcode = LM_TC_TEXTRM;
} else {
varcode = LM_TC_VAR;
break;
case LFUN_UNDO:
- bv->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
+ bv->owner()->message(_("Invalid action in math mode!"));
break;
- //------- dummy actions
- case LFUN_EXEC_COMMAND:
- bv->owner()->getMiniBuffer()->PrepareForCommand();
+ case LFUN_MATH_EXTERN:
+ HandleExtern(arg, bv);
break;
+ //------- dummy actions
+#ifdef WITH_WARNINGS
+#warning Is this needed here? Shouldnt the main dispatch handle this? (Lgb)
+#endif
+ //case LFUN_EXEC_COMMAND:
+ //bv->owner()->getMiniBuffer()->PrepareForCommand();
+ //break;
+
default:
- if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
+ if ((action == -1 || action == LFUN_SELFINSERT)
+ && !arg.empty()) {
unsigned char c = arg[0];
bv->lockedInsetStoreUndo(Undo::INSERT);
} else if (c == '\\') {
if (was_macro)
mathcursor->MacroModeClose();
- bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
+ // This line nukes the mathcursor. Why?
+#ifdef WITH_WARNINGS
+#warning Still? (Lgb)
+#endif
+ bv->owner()->message(_("TeX mode"));
mathcursor->setLastCode(LM_TC_TEX);
}
+ // Andre:
UpdateLocal(bv);
} else if (action == LFUN_MATH_PANEL) {
result = UNDISPATCHED;
}
}
- if (was_macro != mathcursor->InMacroMode()
+ //UpdateLocal(bv);
+
+ // Andre:
+ if ((mathcursor && was_macro != mathcursor->InMacroMode())
&& action >= 0
&& action != LFUN_BACKSPACE)
- UpdateLocal(bv);
+ UpdateLocal(bv);
if (sp && !space_on)
sp = 0;
- if (mathcursor->Selection() || was_selection)
+ if (mathcursor && (mathcursor->Selection() || was_selection))
ToggleInsetSelection(bv);
- if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE) ||
- (result == UNDISPATCHED))
+ if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
+ result == UNDISPATCHED)
ShowInsetCursor(bv);
else
bv->unlockInset(this);
- return result;
+ return result; // original version
}
+namespace {
-static
void mathedValidate(LaTeXFeatures & features, MathParInset * par)
{
MathedIter it(&par->GetData());
}
-static
int mathed_write(MathParInset * p, ostream & os,
bool fragile, string const & label)
{
}
return number_of_newlines;
}
+
+} // namespace anon
+
+
+/* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
+ * on greek mode */
+bool math_insert_greek(BufferView * bv, char c)
+{
+ if (bv->available() &&
+ (('A' <= c && c <= 'Z') ||
+ ('a'<= c && c<= 'z'))) {
+ string tmp;
+ tmp = c;
+ if (!bv->theLockingInset() || bv->theLockingInset()->IsTextInset()) {
+ int greek_kb_flag_save = greek_kb_flag;
+ InsetFormula * new_inset = new InsetFormula();
+ bv->beforeChange(bv->text);
+ if (!bv->insertInset(new_inset)) {
+ delete new_inset;
+ return false;
+ }
+// Update(1);//BUG
+ new_inset->Edit(bv, 0, 0, 0);
+ new_inset->LocalDispatch(bv, LFUN_SELFINSERT, tmp);
+ if (greek_kb_flag_save < 2) {
+ bv->unlockInset(new_inset); // bv->theLockingInset());
+ bv->text->CursorRight(bv, true);
+ }
+ } else
+ if (bv->theLockingInset()->LyxCode() == Inset::MATH_CODE ||
+ bv->theLockingInset()->LyxCode() == Inset::MATHMACRO_CODE)
+ static_cast<InsetFormula*>(bv->theLockingInset())->LocalDispatch(bv, LFUN_SELFINSERT, tmp);
+ else
+ lyxerr << "Math error: attempt to write on a wrong "
+ "class of inset." << endl;
+ return true;
+ }
+ return false;
+}
+
+void InsetFormula::HandleExtern(const string & arg, BufferView * bv)
+{
+ //string outfile = lyx::tempName("maple.out");
+ string outfile = "/tmp/lyx2" + arg + ".out";
+ ostringstream os;
+ par->WriteNormal(os);
+ string code = os.str().c_str();
+ string script = "lyx2" + arg + " '" + code + "' " + outfile;
+ lyxerr << "calling: " << script << endl;
+ Systemcalls cmd(Systemcalls::System, script, 0);
+
+ ifstream is(outfile.c_str());
+ MathedArray ar;
+ mathed_parser_file(is, 0);
+ mathed_parse(ar, par, 0);
+ par->array = ar;
+
+ UpdateLocal(bv);
+}
+
+