- }
-
- case LFUN_INSERT_MATRIX:
- {
- bv->lockedInsetStoreUndo(Undo::INSERT);
- int k, m, n;
- char s[80], arg2[80];
- // This is just so that too long args won't ooze out of s.
- strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
- k = sscanf(arg2, "%d %d %s", &m, &n, s);
- s[79] = '\0';
-
- if (k < 1) {
- m = n = 1;
- } else if (k == 1) {
- n = 1;
- }
-
- MathMatrixInset * p = new MathMatrixInset(m, n);
- if (mathcursor && p) {
- if (k > 2 && int(strlen(s)) > m)
- p->SetAlign(s[0], &s[1]);
- mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
- UpdateLocal(bv);
- }
- break;
- }
-
- case LFUN_MATH_DELIM:
- {
- bv->lockedInsetStoreUndo(Undo::INSERT);
- char lf[40], rg[40], arg2[40];
- int ilf = '(', irg = '.';
- latexkeys * l;
- string vdelim("(){}[]./|");
-
- if (arg.empty())
- break;
- strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
- int n = sscanf(arg2, "%s %s", lf, rg);
- lf[39] = '\0'; rg[39] = '\0';
-
- if (n > 0) {
- if (isdigit(lf[0]))
- ilf = atoi(lf);
- else
- if (lf[1]) {
- l = in_word_set(lf, strlen(lf));
- // Long words will cause l == 0; so check.
- if(l) ilf = l->id;
- } else
- if (vdelim.find(lf[0]) != string::npos)
- ilf = lf[0];
-
- if (n > 1) {
- if (isdigit(rg[0]))
- irg = atoi(rg);
- else
- if (rg[1]) {
- l = in_word_set(rg, strlen(rg));
- if(l) irg = l->id;
- } else
- if (vdelim.find(rg[0]) != string::npos)
- irg = rg[0];
- }
- }
-
- MathDelimInset * p = new MathDelimInset(ilf, irg);
- mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
- UpdateLocal(bv);
- break;
- }
-
- case LFUN_PROTECTEDSPACE:
- {
- bv->lockedInsetStoreUndo(Undo::INSERT);
- sp = new MathSpaceInset(1);
- mathcursor->Insert(sp);
- space_on = true;
- UpdateLocal(bv);
- break;
- }
-
- case LFUN_INSERT_LABEL:
- {
- bv->lockedInsetStoreUndo(Undo::INSERT);
- if (par->GetType() < LM_OT_PAR) break;
- string lb = arg;
- if (lb.empty()) {
- pair<bool, string>
- res = askForText(_("Enter new label to insert:"));
- if (res.first) {
- lb = res.second;
- }
- }
- if (!lb.empty() && lb[0] > ' ') {
- SetNumber(true);
- if (par->GetType() == LM_OT_MPARN) {
- mathcursor->setLabel(lb.c_str());
-// MathMatrixInset *mt = (MathMatrixInset*)par;
-// mt->SetLabel(lb);
- } else {
- //if (label.notEmpty()) delete label;
- label = lb;
- }
- UpdateLocal(bv);
- } else
- label.erase();
- break;
- }
-
- case LFUN_MATH_DISPLAY:
- //current_view->lockedInsetStoreUndo(Undo::INSERT);
- bv->lockedInsetStoreUndo(Undo::EDIT);
- display(!disp_flag);
- 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"));
- varcode = LM_TC_TEXTRM;
- } else {
- varcode = LM_TC_VAR;
+
+ /* cursor selection ---------------------------- */
+
+ case LFUN_PASTE:
+ if (was_macro)
+ mathcursor->MacroModeClose();
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+ mathcursor->SelPaste();
+ UpdateLocal(bv);
+ break;
+
+ case LFUN_CUT:
+ bv->lockedInsetStoreUndo(Undo::DELETE);
+ mathcursor->SelCut();
+ UpdateLocal(bv);
+ break;
+
+ case LFUN_COPY:
+ mathcursor->SelCopy();
+ break;
+
+ case LFUN_HOMESEL:
+ case LFUN_ENDSEL:
+ case LFUN_WORDRIGHTSEL:
+ case LFUN_WORDLEFTSEL:
+ break;
+
+ // --- accented characters ------------------------------
+
+ case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
+ case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
+ case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
+ case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
+ case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
+ case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
+ case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
+ case LFUN_CARON: mathcursor->setAccent(LM_check); break;
+ case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
+ case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
+
+ // Greek mode
+ case LFUN_GREEK:
+ if (!greek_kb_flag) {
+ greek_kb_flag = 1;
+ bv->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
+ } else
+ greek_kb_flag = 0;
+ break;
+
+ // Greek keyboard
+ case LFUN_GREEK_TOGGLE:
+ greek_kb_flag = (greek_kb_flag) ? 0 : 2;
+ if (greek_kb_flag)
+ bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
+ else
+ bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
+ break;
+
+ // Math fonts
+ case LFUN_BOLD: mathcursor->toggleLastCode(LM_TC_BF); break;
+ case LFUN_SANS: mathcursor->toggleLastCode(LM_TC_SF); break;
+ case LFUN_EMPH: mathcursor->toggleLastCode(LM_TC_CAL); break;
+ case LFUN_ROMAN: mathcursor->toggleLastCode(LM_TC_RM); break;
+ case LFUN_CODE: mathcursor->toggleLastCode(LM_TC_TT); break;
+ case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR); break;
+
+ case LFUN_TEX:
+ // varcode = LM_TC_TEX;
+ mathcursor->setLastCode(LM_TC_TEX);
+ bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
+ break;
+
+ case LFUN_MATH_NUMBER:
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+ if (disp_flag) {
+ short type = par->GetType();
+ if (is_numbered(type)) {
+ --type;
+ if (!label.empty()) {
+ label.erase();
+ }
+ bv->owner()->getMiniBuffer()->Set(_("No number"));
+ } else {
+ ++type;
+ bv->owner()->getMiniBuffer()->Set(_("Number"));
+ }
+ par->SetType(type);
+ UpdateLocal(bv);
+ }
+ break;
+
+ case LFUN_MATH_NONUMBER:
+ if (is_multi_numbered(par->GetType())) {
+ // MathMatrixInset *mt = (MathMatrixInset*)par;
+ //BUG
+ // mt->SetNumbered(!mt->IsNumbered());
+
+#warning This is a terrible hack! We should find a better solution.
+ while (mathcursor->getLabel() == MathedXIter::error_label) {
+ if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
+ return DISPATCHED;
+ }
+ mathcursor->setNumbered();
+ UpdateLocal(bv);
+ }
+ break;
+
+ case LFUN_MATH_LIMITS:
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+ if (mathcursor->Limits())
+ UpdateLocal(bv);
+ // fall through!
+
+ case LFUN_MATH_SIZE:
+ if (!arg.empty()) {
+ latexkeys const * l = in_word_set(arg);
+ int sz = (l) ? l->id: -1;
+ mathcursor->SetSize(sz);
+ UpdateLocal(bv);
+ break;
+ }
+ // possible fall through?
+
+ case LFUN_INSERT_MATH:
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+ InsertSymbol(bv, arg);
+ break;
+
+
+ case LFUN_INSERT_MATRIX:
+ {
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+ int k, m, n;
+ char s[80], arg2[80];
+ // This is just so that too long args won't ooze out of s.
+ strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
+ k = sscanf(arg2, "%d %d %s", &m, &n, s);
+ s[79] = '\0';
+
+ if (k < 1) {
+ m = n = 1;
+ } else if (k == 1) {
+ n = 1;
+ }
+
+ MathMatrixInset * p = new MathMatrixInset(m, n);
+ if (mathcursor && p) {
+ if (k > 2 && int(strlen(s)) > m)
+ p->SetAlign(s[0], &s[1]);
+ mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
+ UpdateLocal(bv);
+ }
+ break;
+ }
+
+ case LFUN_MATH_DELIM:
+ {
+ bv->lockedInsetStoreUndo(Undo::INSERT);
+ char lf[40], rg[40], arg2[40];
+ int ilf = '(', irg = '.';
+ latexkeys const * l;
+ string vdelim("(){}[]./|");
+
+ if (arg.empty())
+ break;
+ ::strncpy(arg2, arg.c_str(), 40);
+ arg2[39]= '\0';
+ int n = sscanf(arg2, "%s %s", lf, rg);
+ lf[39] = '\0';
+ rg[39] = '\0';
+
+ if (n > 0) {
+ if (isdigit(lf[0]))
+ ilf = lyx::atoi(lf);
+ else
+ if (lf[1]) {
+ l = in_word_set(lf, strlen(lf));
+ // Long words will cause l == 0; so check.
+ if (l)
+ ilf = l->id;
+ } else if (vdelim.find(lf[0]) != string::npos)
+ ilf = lf[0];
+
+ if (n > 1) {
+ if (isdigit(rg[0]))
+ irg = lyx::atoi(rg);
+ else
+ if (rg[1]) {
+ l = in_word_set(rg, strlen(rg));
+ if (l)
+ irg = l->id;
+ } else if (vdelim.find(rg[0]) != string::npos)
+ irg = rg[0];
+ }
+ }
+
+ MathDelimInset * p = new MathDelimInset(ilf, irg);
+ mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
+ UpdateLocal(bv);
+ break;