1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2002 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
16 #include "BufferView.h"
17 #include "funcrequest.h"
20 #include "bufferparams.h"
22 #include "ParagraphParameters.h"
27 #include "support/lstrings.h"
28 #include "frontends/LyXView.h"
29 #include "frontends/screen.h"
30 #include "frontends/WorkArea.h"
31 #include "frontends/Dialogs.h"
32 #include "insets/insetspecialchar.h"
33 #include "insets/insettext.h"
34 #include "insets/insetquotes.h"
35 #include "insets/insetcommand.h"
36 #include "insets/insettabular.h"
37 #include "undo_funcs.h"
45 extern string current_layout;
49 void moveCursorUpdate(BufferView * bv, bool selecting)
51 LyXText * lt = bv->getLyXText();
53 if (selecting || lt->selection.mark()) {
58 bv->updateInset(lt->inset_owner, false);
62 // bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
64 bv->update(lt, BufferView::SELECT);
66 } else if (bv->text->status() != LyXText::UNCHANGED) {
67 bv->theLockingInset()->hideInsetCursor(bv);
68 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
72 if (!lt->selection.set())
73 bv->workarea().haveSelection(false);
79 void finishChange(BufferView * bv, bool selecting = false)
82 moveCursorUpdate(bv, selecting);
83 bv->owner()->view_state_changed();
89 bool LyXText::gotoNextInset(BufferView * bv,
90 vector<Inset::Code> const & codes, string const & contents) const
92 LyXCursor res = cursor;
95 if (res.pos() < res.par()->size() - 1) {
96 res.pos(res.pos() + 1);
98 res.par(res.par()->next());
102 } while (res.par() &&
103 !(res.par()->isInset(res.pos())
104 && (inset = res.par()->getInset(res.pos())) != 0
105 && find(codes.begin(), codes.end(), inset->lyxCode())
107 && (contents.empty() ||
108 static_cast<InsetCommand *>(
109 res.par()->getInset(res.pos()))->getContents()
113 setCursor(bv, res.par(), res.pos(), false);
120 void LyXText::gotoInset(BufferView * bv, vector<Inset::Code> const & codes,
124 bv->beforeChange(this);
128 if (same_content && cursor.par()->isInset(cursor.pos())) {
129 Inset const * inset = cursor.par()->getInset(cursor.pos());
130 if (find(codes.begin(), codes.end(), inset->lyxCode())
132 contents = static_cast<InsetCommand const *>(inset)->getContents();
135 if (!gotoNextInset(bv, codes, contents)) {
136 if (cursor.pos() || cursor.par() != ownerParagraph()) {
137 LyXCursor tmp = cursor;
138 cursor.par(ownerParagraph());
140 if (!gotoNextInset(bv, codes, contents)) {
142 bv->owner()->message(_("No more insets"));
145 bv->owner()->message(_("No more insets"));
149 selection.cursor = cursor;
153 void LyXText::gotoInset(BufferView * bv, Inset::Code code, bool same_content)
155 gotoInset(bv, vector<Inset::Code>(1, code), same_content);
159 void LyXText::cursorPrevious(BufferView * bv)
161 if (!cursor.row()->previous()) {
163 int new_y = bv->text->first_y - bv->workarea().workHeight();
164 bv->screen().draw(bv->text, bv, new_y < 0 ? 0 : new_y);
165 bv->updateScrollbar();
171 Row * cursorrow = cursor.row();
173 setCursorFromCoordinates(bv, cursor.x_fix(), y);
177 if (cursorrow == bv->text->cursor.row()) {
178 // we have a row which is higher than the workarea so we leave the
179 // cursor on the start of the row and move only the draw up as soon
180 // as we move the cursor or do something while inside the row (it may
181 // span several workarea-heights) we'll move to the top again, but this
182 // is better than just jump down and only display part of the row.
183 new_y = bv->text->first_y - bv->workarea().workHeight();
186 new_y = bv->text->cursor.iy()
187 + bv->theLockingInset()->insetInInsetY() + y
188 + cursor.row()->height()
189 - bv->workarea().workHeight() + 1;
192 - cursor.row()->baseline()
193 + cursor.row()->height()
194 - bv->workarea().workHeight() + 1;
197 bv->screen().draw(bv->text, bv, new_y < 0 ? 0 : new_y);
198 if (cursor.row()->previous()) {
200 setCursor(bv, cur, cursor.row()->previous()->par(),
201 cursor.row()->previous()->pos(), false);
202 if (cur.y() > first_y) {
206 bv->updateScrollbar();
210 void LyXText::cursorNext(BufferView * bv)
212 if (!cursor.row()->next()) {
213 int y = cursor.y() - cursor.row()->baseline() +
214 cursor.row()->height();
215 if (y > int(first_y + bv->workarea().workHeight())) {
216 bv->screen().draw(bv->text, bv,
217 bv->text->first_y + bv->workarea().workHeight());
218 bv->updateScrollbar();
223 int y = first_y + bv->workarea().workHeight();
224 if (inset_owner && !first_y) {
225 y -= (bv->text->cursor.iy()
227 + bv->theLockingInset()->insetInInsetY());
232 Row * cursorrow = cursor.row();
233 setCursorFromCoordinates(bv, cursor.x_fix(), y);
234 // + workarea().workHeight());
238 if (cursorrow == bv->text->cursor.row()) {
239 // we have a row which is higher than the workarea so we leave the
240 // cursor on the start of the row and move only the draw down as soon
241 // as we move the cursor or do something while inside the row (it may
242 // span several workarea-heights) we'll move to the top again, but this
243 // is better than just jump down and only display part of the row.
244 new_y = bv->text->first_y + bv->workarea().workHeight();
247 new_y = bv->text->cursor.iy()
248 + bv->theLockingInset()->insetInInsetY()
249 + y - cursor.row()->baseline();
251 new_y = cursor.y() - cursor.row()->baseline();
254 bv->screen().draw(bv->text, bv, new_y);
255 if (cursor.row()->next()) {
257 setCursor(bv, cur, cursor.row()->next()->par(),
258 cursor.row()->next()->pos(), false);
259 if (cur.y() < int(first_y + bv->workarea().workHeight())) {
260 cursorDown(bv, true);
263 bv->updateScrollbar();
267 void LyXText::update(BufferView * bv, bool changed)
269 BufferView::UpdateCodes c = BufferView::SELECT | BufferView::FITCUR;
271 bv->update(this, c | BufferView::CHANGE);
277 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
281 InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
282 if (!bv->insertInset(new_inset))
285 bv->updateInset(new_inset, true);
289 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
291 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
292 <<"] arg[" << cmd.argument << "]" << endl;
294 BufferView * bv = cmd.view();
296 switch (cmd.action) {
298 case LFUN_APPENDIX: {
299 Paragraph * par = cursor.par();
300 bool start = !par->params().startOfAppendix();
302 // ensure that we have only one start_of_appendix in this document
303 Paragraph * tmp = ownerParagraph();
304 for (; tmp; tmp = tmp->next())
305 tmp->params().startOfAppendix(false);
307 par->params().startOfAppendix(start);
309 // we can set the refreshing parameters now
310 status(cmd.view(), LyXText::NEED_MORE_REFRESH);
312 refresh_row = 0; // not needed for full update
313 updateCounters(cmd.view());
314 setCursor(cmd.view(), cursor.par(), cursor.pos());
319 case LFUN_DELETE_WORD_FORWARD:
320 bv->beforeChange(this);
322 deleteWordForward(bv);
327 case LFUN_DELETE_WORD_BACKWARD:
328 bv->beforeChange(this);
330 deleteWordBackward(bv);
335 case LFUN_DELETE_LINE_FORWARD:
336 bv->beforeChange(this);
338 deleteLineForward(bv);
345 if (!selection.mark())
346 bv->beforeChange(this);
353 if (!selection.mark())
354 bv->beforeChange(this);
356 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
357 cursorLeftOneWord(bv);
359 cursorRightOneWord(bv);
364 if (!selection.mark())
365 bv->beforeChange(this);
367 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
368 cursorRightOneWord(bv);
370 cursorLeftOneWord(bv);
374 case LFUN_BEGINNINGBUF:
375 if (!selection.mark())
376 bv->beforeChange(this);
383 if (selection.mark())
384 bv->beforeChange(this);
392 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
396 finishChange(bv, true);
401 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
405 finishChange(bv, true);
411 finishChange(bv, true);
416 cursorDown(bv, true);
417 finishChange(bv, true);
420 case LFUN_UP_PARAGRAPHSEL:
422 cursorUpParagraph(bv);
423 finishChange(bv, true);
426 case LFUN_DOWN_PARAGRAPHSEL:
428 cursorDownParagraph(bv);
429 finishChange(bv, true);
435 finishChange(bv, true);
441 finishChange(bv, true);
447 finishChange(bv, true);
453 finishChange(bv, true);
456 case LFUN_WORDRIGHTSEL:
458 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
459 cursorLeftOneWord(bv);
461 cursorRightOneWord(bv);
462 finishChange(bv, true);
465 case LFUN_WORDLEFTSEL:
467 if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
468 cursorRightOneWord(bv);
470 cursorLeftOneWord(bv);
471 finishChange(bv, true);
475 bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
476 if (!selection.mark())
477 bv->beforeChange(this);
480 cursorLeft(bv, false);
481 if (cursor.pos() < cursor.par()->size()
482 && cursor.par()->isInset(cursor.pos())
483 && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
484 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
485 cmd.message(tmpinset->editMessage());
486 tmpinset->edit(bv, !is_rtl);
490 cursorRight(bv, false);
496 // This is soooo ugly. Isn`t it possible to make
498 bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
499 if (!selection.mark())
500 bv->beforeChange(this);
502 LyXCursor const cur = cursor;
504 cursorLeft(bv, false);
505 if ((is_rtl || cur != cursor) && // only if really moved!
506 cursor.pos() < cursor.par()->size() &&
507 cursor.par()->isInset(cursor.pos()) &&
508 isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
509 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
510 cmd.message(tmpinset->editMessage());
511 tmpinset->edit(bv, is_rtl);
515 cursorRight(bv, false);
521 if (!selection.mark())
522 bv->beforeChange(this);
523 bv->update(this, BufferView::UPDATE);
529 if (!selection.mark())
530 bv->beforeChange(this);
531 bv->update(this, BufferView::UPDATE);
536 case LFUN_UP_PARAGRAPH:
537 if (!selection.mark())
538 bv->beforeChange(this);
539 bv->update(this, BufferView::UPDATE);
540 cursorUpParagraph(bv);
544 case LFUN_DOWN_PARAGRAPH:
545 if (!selection.mark())
546 bv->beforeChange(this);
547 bv->update(this, BufferView::UPDATE);
548 cursorDownParagraph(bv);
549 finishChange(bv, false);
553 if (!selection.mark())
554 bv->beforeChange(this);
555 bv->update(this, BufferView::UPDATE);
557 finishChange(bv, false);
560 // moveCursorUpdate(bv, false, false);
561 // owner_->view_state_changed();
565 if (!selection.mark())
566 bv->beforeChange(this);
567 bv->update(this, BufferView::UPDATE);
569 finishChange(bv, false);
573 if (!selection.mark())
574 bv->beforeChange(this);
577 finishChange(bv, false);
581 if (!selection.mark())
582 bv->beforeChange(this);
585 finishChange(bv, false);
589 bv->beforeChange(this);
590 insertChar(bv, Paragraph::META_NEWLINE);
592 setCursor(bv, cursor.par(), cursor.pos());
593 moveCursorUpdate(bv, false);
597 if (!selection.set()) {
599 selection.cursor = cursor;
601 // It is possible to make it a lot faster still
602 // just comment out the line below...
606 cutSelection(bv, true);
609 moveCursorUpdate(bv, false);
610 bv->owner()->view_state_changed();
614 case LFUN_DELETE_SKIP:
615 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
616 if (!selection.set()) {
617 LyXCursor cur = cursor;
618 if (cur.pos() == cur.par()->size()) {
622 && !(cur.par()->params().spaceTop()
623 == VSpace (VSpace::NONE))) {
625 cur.par()->params().lineTop(),
626 cur.par()->params().lineBottom(),
627 cur.par()->params().pagebreakTop(),
628 cur.par()->params().pagebreakBottom(),
629 VSpace(VSpace::NONE),
630 cur.par()->params().spaceBottom(),
631 cur.par()->params().spacing(),
632 cur.par()->params().align(),
633 cur.par()->params().labelWidthString(), 0);
639 selection.cursor = cursor;
643 selection.cursor = cursor;
647 cutSelection(bv, true);
654 if (!selection.set()) {
655 if (bv->owner()->getIntl().getTransManager().backspace()) {
657 selection.cursor = cursor;
659 // It is possible to make it a lot faster still
660 // just comment out the line below...
665 cutSelection(bv, true);
668 bv->owner()->view_state_changed();
672 case LFUN_BACKSPACE_SKIP:
673 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
674 if (!selection.set()) {
675 LyXCursor cur = cursor;
677 && !(cur.par()->params().spaceTop()
678 == VSpace (VSpace::NONE))) {
680 cur.par()->params().lineTop(),
681 cur.par()->params().lineBottom(),
682 cur.par()->params().pagebreakTop(),
683 cur.par()->params().pagebreakBottom(),
684 VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
685 cur.par()->params().spacing(),
686 cur.par()->params().align(),
687 cur.par()->params().labelWidthString(), 0);
690 selection.cursor = cur;
694 cutSelection(bv, true);
699 case LFUN_BREAKPARAGRAPH:
700 bv->beforeChange(this);
701 breakParagraph(bv, 0);
703 selection.cursor = cursor;
705 bv->owner()->view_state_changed();
708 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
709 bv->beforeChange(this);
710 breakParagraph(bv, 1);
712 selection.cursor = cursor;
714 bv->owner()->view_state_changed();
717 case LFUN_BREAKPARAGRAPH_SKIP: {
718 // When at the beginning of a paragraph, remove
719 // indentation and add a "defskip" at the top.
720 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
721 LyXCursor cur = cursor;
722 bv->beforeChange(this);
723 if (cur.pos() == 0) {
724 if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
726 cur.par()->params().lineTop(),
727 cur.par()->params().lineBottom(),
728 cur.par()->params().pagebreakTop(),
729 cur.par()->params().pagebreakBottom(),
730 VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
731 cur.par()->params().spacing(),
732 cur.par()->params().align(),
733 cur.par()->params().labelWidthString(), 1);
738 breakParagraph(bv, 0);
742 selection.cursor = cur;
744 bv->owner()->view_state_changed();
748 case LFUN_PARAGRAPH_SPACING: {
749 Paragraph * par = cursor.par();
750 Spacing::Space cur_spacing = par->params().spacing().getSpace();
751 float cur_value = 1.0;
752 if (cur_spacing == Spacing::Other)
753 cur_value = par->params().spacing().getValue();
755 istringstream is(cmd.argument.c_str());
758 Spacing::Space new_spacing = cur_spacing;
759 float new_value = cur_value;
761 lyxerr << "Missing argument to `paragraph-spacing'"
763 } else if (tmp == "single") {
764 new_spacing = Spacing::Single;
765 } else if (tmp == "onehalf") {
766 new_spacing = Spacing::Onehalf;
767 } else if (tmp == "double") {
768 new_spacing = Spacing::Double;
769 } else if (tmp == "other") {
770 new_spacing = Spacing::Other;
773 lyxerr << "new_value = " << tmpval << endl;
776 } else if (tmp == "default") {
777 new_spacing = Spacing::Default;
779 lyxerr << _("Unknown spacing argument: ")
780 << cmd.argument << endl;
782 if (cur_spacing != new_spacing || cur_value != new_value) {
783 par->params().spacing(Spacing(new_spacing, new_value));
790 case LFUN_INSET_TOGGLE:
792 bv->beforeChange(this);
799 case LFUN_PROTECTEDSPACE:
800 if (cursor.par()->layout()->free_spacing) {
804 specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
806 moveCursorUpdate(bv, false);
809 case LFUN_HYPHENATION:
810 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
813 case LFUN_LIGATURE_BREAK:
814 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
818 specialChar(this, bv, InsetSpecialChar::LDOTS);
824 insertChar(bv, Paragraph::META_HFILL);
828 case LFUN_END_OF_SENTENCE:
829 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
832 case LFUN_MENU_SEPARATOR:
833 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
837 bv->beforeChange(this);
839 selection.cursor = cursor;
840 cmd.message(N_("Mark off"));
844 bv->beforeChange(this);
845 selection.mark(true);
847 selection.cursor = cursor;
848 cmd.message(N_("Mark on"));
852 bv->beforeChange(this);
853 if (selection.mark()) {
855 cmd.message(N_("Mark removed"));
857 selection.mark(true);
859 cmd.message(N_("Mark set"));
861 selection.cursor = cursor;
864 case LFUN_UPCASE_WORD:
866 changeCase(bv, LyXText::text_uppercase);
868 bv->updateInset(inset_owner, true);
872 case LFUN_LOWCASE_WORD:
874 changeCase(bv, LyXText::text_lowercase);
876 bv->updateInset(inset_owner, true);
880 case LFUN_CAPITALIZE_WORD:
882 changeCase(bv, LyXText::text_capitalization);
884 bv->updateInset(inset_owner, true);
888 case LFUN_TRANSPOSE_CHARS:
892 bv->updateInset(inset_owner, true);
897 cmd.message(_("Paste"));
899 // clear the selection
900 bv->toggleSelection();
904 clearSelection(); // bug 393
913 cutSelection(bv, true);
915 cmd.message(_("Cut"));
920 cmd.message(_("Copy"));
923 case LFUN_BEGINNINGBUFSEL:
925 return Inset::UNDISPATCHED;
928 finishChange(bv, true);
933 return Inset::UNDISPATCHED;
936 finishChange(bv, true);
940 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
946 istringstream is(cmd.argument.c_str());
949 lyxerr << "SETXY: Could not parse coordinates in '"
950 << cmd.argument << std::endl;
952 setCursorFromCoordinates(bv, x, y);
957 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
959 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
966 cmd.message(tostr(cursor.par()->layout()));
970 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
971 << cmd.argument << endl;
973 // This is not the good solution to the empty argument
974 // problem, but it will hopefully suffice for 1.2.0.
975 // The correct solution would be to augument the
976 // function list/array with information about what
977 // functions needs arguments and their type.
978 if (cmd.argument.empty()) {
979 cmd.errorMessage(_("LyX function 'layout' needs an argument."));
983 // Derive layout number from given argument (string)
984 // and current buffer's textclass (number)
985 LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
986 bool hasLayout = tclass.hasLayout(cmd.argument);
987 string layout = cmd.argument;
989 // If the entry is obsolete, use the new one instead.
991 string const & obs = tclass[layout]->obsoleted_by();
997 cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1002 bool change_layout = (current_layout != layout);
1003 if (!change_layout && selection.set() &&
1004 selection.start.par() != selection.end.par())
1006 Paragraph * spar = selection.start.par();
1007 Paragraph * epar = selection.end.par()->next();
1008 while (spar != epar) {
1009 if (spar->layout()->name() != current_layout) {
1010 change_layout = true;
1015 if (change_layout) {
1017 current_layout = layout;
1019 setLayout(bv, layout);
1020 bv->owner()->setLayout(layout);
1027 case LFUN_PASTESELECTION: {
1031 // this was originally a beforeChange(bv->text), i.e
1032 // the outermost LyXText!
1033 bv->beforeChange(this);
1034 string const clip = bv->workarea().getClipboard();
1035 if (!clip.empty()) {
1036 if (cmd.argument == "paragraph")
1037 insertStringAsParagraphs(bv, clip);
1039 insertStringAsLines(bv, clip);
1046 case LFUN_GOTOERROR:
1047 gotoInset(bv, Inset::ERROR_CODE, false);
1051 gotoInset(bv, Inset::NOTE_CODE, false);
1054 case LFUN_REFERENCE_GOTO:
1056 vector<Inset::Code> tmp;
1057 tmp.push_back(Inset::LABEL_CODE);
1058 tmp.push_back(Inset::REF_CODE);
1059 gotoInset(bv, tmp, true);
1064 case LFUN_INSET_LIST:
1065 case LFUN_INSET_THEOREM:
1067 case LFUN_INSERT_NOTE:
1068 case LFUN_INSET_ERT:
1069 case LFUN_INSET_EXTERNAL:
1070 case LFUN_INSET_FLOAT:
1071 case LFUN_INSET_FOOTNOTE:
1072 case LFUN_INSET_MARGINAL:
1073 case LFUN_INSET_MINIPAGE:
1074 case LFUN_INSET_OPTARG:
1075 case LFUN_INSET_WIDE_FLOAT: {
1076 Inset * inset = createInset(cmd);
1078 bool gotsel = false;
1079 if (selection.set()) {
1080 cutSelection(bv, true, false);
1083 if (bv->insertInset(inset)) {
1086 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
1094 case LFUN_TABULAR_INSERT:
1095 if (cmd.argument.empty())
1096 bv->owner()->getDialogs().showTabularCreate();
1100 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
1101 InsetTabular * inset = new InsetTabular(*bv->buffer(), r, c);
1102 bv->beforeChange(this);
1104 if (!bv->insertInset(inset))
1107 inset->edit(bv, !real_current_font.isRightToLeft());
1112 Paragraph const * par = cursor.par();
1113 lyx::pos_type pos = cursor.pos();
1117 else if (par->isInset(pos - 1) && par->getInset(pos - 1)->isSpace())
1120 c = par->getChar(pos - 1);
1123 LyXLayout_ptr const & style = par->layout();
1125 if (style->pass_thru ||
1126 par->getFontSettings(bv->buffer()->params,
1127 pos).language()->lang() == "hebrew" ||
1128 (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
1129 bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1133 case LFUN_DATE_INSERT: { // jdblair: date-insert cmd
1134 time_t now_time_t = time(NULL);
1135 struct tm * now_tm = localtime(&now_time_t);
1136 setlocale(LC_TIME, "");
1138 if (!cmd.argument.empty())
1141 arg = lyxrc.date_insert_format;
1143 int const datetmp_len =
1144 ::strftime(datetmp, 32, arg.c_str(), now_tm);
1146 for (int i = 0; i < datetmp_len; i++) {
1147 insertChar(bv, datetmp[i]);
1150 selection.cursor = cursor;
1151 moveCursorUpdate(bv, false);
1155 case LFUN_SELFINSERT: {
1156 if (cmd.argument.empty())
1159 // Automatically delete the currently selected
1160 // text and replace it with what is being
1161 // typed in now. Depends on lyxrc settings
1162 // "auto_region_delete", which defaults to
1165 if (lyxrc.auto_region_delete) {
1166 if (selection.set()) {
1167 cutSelection(bv, false, false);
1170 bv->workarea().haveSelection(false);
1173 bv->beforeChange(this);
1174 LyXFont const old_font(real_current_font);
1176 string::const_iterator cit = cmd.argument.begin();
1177 string::const_iterator end = cmd.argument.end();
1178 for (; cit != end; ++cit)
1179 bv->owner()->getIntl().getTransManager().
1180 TranslateAndInsert(*cit, this);
1183 selection.cursor = cursor;
1184 moveCursorUpdate(bv, false);
1186 // real_current_font.number can change so we need to
1187 // update the minibuffer
1188 if (old_font != real_current_font)
1189 bv->owner()->view_state_changed();
1194 return Inset::UNDISPATCHED;
1197 return Inset::DISPATCHED;