7 #include "BufferView_pimpl.h"
12 #include "paragraph.h"
14 #include "commandtags.h"
18 #include "bufferview_funcs.h"
19 #include "TextCache.h"
20 #include "bufferlist.h"
21 #include "lyx_gui_misc.h"
24 // added for Dispatch functions
27 #include "FloatList.h"
29 #include "ParagraphParameters.h"
30 #include "undo_funcs.h"
31 #include "lyxtextclasslist.h"
33 #include "frontends/Dialogs.h"
34 #include "frontends/Alert.h"
35 #include "frontends/FileDialog.h"
37 #include "insets/insetbib.h"
38 #include "insets/insettext.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetlatexaccent.h"
41 #include "insets/insettoc.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetnote.h"
46 #include "insets/insetinclude.h"
47 #include "insets/insetcite.h"
48 #include "insets/insetert.h"
49 #include "insets/insetexternal.h"
50 #include "insets/insetgraphics.h"
51 #include "insets/insetfoot.h"
52 #include "insets/insetmarginal.h"
53 #include "insets/insetminipage.h"
54 #include "insets/insetfloat.h"
55 #include "insets/insettabular.h"
57 #include "insets/insettheorem.h"
58 #include "insets/insetlist.h"
60 #include "insets/insetcaption.h"
61 #include "insets/insetfloatlist.h"
62 #include "insets/insetspecialchar.h"
64 #include "mathed/formulabase.h"
66 #include "support/LAssert.h"
67 #include "support/lstrings.h"
68 #include "support/filetools.h"
69 #include "support/lyxfunctional.h"
77 extern lyx::layout_type current_layout;
89 using lyx::layout_type;
90 using lyx::textclass_type;
92 /* the selection possible is needed, that only motion events are
93 * used, where the bottom press event was on the drawing area too */
94 bool selection_possible = false;
96 extern BufferList bufferlist;
97 extern char ascii_type;
99 extern void sigchldchecker(pid_t pid, int * status);
100 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
105 const unsigned int saved_positions_num = 20;
110 XSync(fl_get_display(), 0);
114 void SetXtermCursor(Window win)
116 static Cursor cursor;
117 static bool cursor_undefined = true;
118 if (cursor_undefined){
119 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
120 XFlush(fl_get_display());
121 cursor_undefined = false;
123 XDefineCursor(fl_get_display(), win, cursor);
124 XFlush(fl_get_display());
130 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
131 int xpos, int ypos, int width, int height)
132 : bv_(b), owner_(o), buffer_(0),
133 current_scrollbar_value(0), cursor_timeout(400),
134 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
138 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
139 workarea_.workAreaExpose
140 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
141 workarea_.workAreaEnter
142 .connect(slot(this, &BufferView::Pimpl::enterView));
143 workarea_.workAreaLeave
144 .connect(slot(this, &BufferView::Pimpl::leaveView));
145 workarea_.workAreaButtonPress
146 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
147 workarea_.workAreaButtonRelease
149 &BufferView::Pimpl::workAreaButtonRelease));
150 workarea_.workAreaMotionNotify
151 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
152 workarea_.workAreaDoubleClick
153 .connect(slot(this, &BufferView::Pimpl::doubleClick));
154 workarea_.workAreaTripleClick
155 .connect(slot(this, &BufferView::Pimpl::tripleClick));
156 workarea_.workAreaKeyPress
157 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
159 cursor_timeout.timeout.connect(slot(this,
160 &BufferView::Pimpl::cursorToggle));
161 cursor_timeout.start();
162 workarea_.setFocus();
163 saved_positions.resize(saved_positions_num);
167 Painter & BufferView::Pimpl::painter()
169 return workarea_.getPainter();
173 void BufferView::Pimpl::buffer(Buffer * b)
175 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
179 buffer_->delUser(bv_);
181 // Put the old text into the TextCache, but
182 // only if the buffer is still loaded.
183 // Also set the owner of the test to 0
184 // bv_->text->owner(0);
185 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
186 if (lyxerr.debugging())
187 textcache.show(lyxerr, "BufferView::buffer");
192 // Set current buffer
195 if (bufferlist.getState() == BufferList::CLOSING) return;
198 // screen is always deleted when the buffer is changed.
201 // If we are closing the buffer, use the first buffer as current
203 buffer_ = bufferlist.first();
207 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
208 buffer_->addUser(bv_);
209 // If we don't have a text object for this, we make one
210 if (bv_->text == 0) {
211 resizeCurrentBuffer();
216 bv_->text->first = screen_->topCursorVisible(bv_->text);
217 owner_->updateMenubar();
218 owner_->updateToolbar();
219 // Similarly, buffer-dependent dialogs should be updated or
220 // hidden. This should go here because some dialogs (eg ToC)
221 // require bv_->text.
222 owner_->getDialogs()->updateBufferDependent(true);
226 lyxerr[Debug::INFO] << " No Buffer!" << endl;
227 owner_->updateMenubar();
228 owner_->updateToolbar();
229 owner_->getDialogs()->hideBufferDependent();
233 // Also remove all remaining text's from the testcache.
234 // (there should not be any!) (if there is any it is a
236 if (lyxerr.debugging())
237 textcache.show(lyxerr, "buffer delete all");
240 // should update layoutchoice even if we don't have a buffer.
241 owner_->updateLayoutChoice();
243 owner_->updateWindowTitle();
247 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
249 workarea_.resize(xpos, ypos, width, height);
250 update(bv_->text, SELECT);
255 void BufferView::Pimpl::resize()
258 resizeCurrentBuffer();
262 void BufferView::Pimpl::redraw()
264 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
269 bool BufferView::Pimpl::fitCursor()
271 lyx::Assert(screen_.get());
275 if (bv_->theLockingInset()) {
276 bv_->theLockingInset()->fitInsetCursor(bv_);
279 ret = screen_->fitCursor(bv_->text, bv_);
282 bv_->owner()->getDialogs()->updateParagraph();
289 void BufferView::Pimpl::redoCurrentBuffer()
291 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
292 if (buffer_ && bv_->text) {
294 owner_->updateLayoutChoice();
299 int BufferView::Pimpl::resizeCurrentBuffer()
301 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
304 Paragraph * selstartpar = 0;
305 Paragraph * selendpar = 0;
306 UpdatableInset * the_locking_inset = 0;
309 pos_type selstartpos = 0;
310 pos_type selendpos = 0;
311 bool selection = false;
312 bool mark_set = false;
314 owner_->prohibitInput();
316 owner_->message(_("Formatting document..."));
319 par = bv_->text->cursor.par();
320 pos = bv_->text->cursor.pos();
321 selstartpar = bv_->text->selection.start.par();
322 selstartpos = bv_->text->selection.start.pos();
323 selendpar = bv_->text->selection.end.par();
324 selendpos = bv_->text->selection.end.pos();
325 selection = bv_->text->selection.set();
326 mark_set = bv_->text->selection.mark();
327 the_locking_inset = bv_->theLockingInset();
329 bv_->text = new LyXText(bv_);
330 bv_->text->init(bv_);
332 // See if we have a text in TextCache that fits
333 // the new buffer_ with the correct width.
334 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
336 if (lyxerr.debugging()) {
337 lyxerr << "Found a LyXText that fits:\n";
338 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
340 // Set the owner of the newly found text
341 // bv_->text->owner(bv_);
342 if (lyxerr.debugging())
343 textcache.show(lyxerr, "resizeCurrentBuffer");
345 bv_->text = new LyXText(bv_);
346 bv_->text->init(bv_);
352 bv_->text->selection.set(true);
353 /* at this point just to avoid the Delete-Empty-Paragraph
354 * Mechanism when setting the cursor */
355 bv_->text->selection.mark(mark_set);
357 bv_->text->setCursor(bv_, selstartpar, selstartpos);
358 bv_->text->selection.cursor = bv_->text->cursor;
359 bv_->text->setCursor(bv_, selendpar, selendpos);
360 bv_->text->setSelection(bv_);
361 bv_->text->setCursor(bv_, par, pos);
363 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->selection.cursor = bv_->text->cursor;
365 bv_->text->selection.set(false);
367 // remake the inset locking
368 bv_->theLockingInset(the_locking_inset);
370 bv_->text->first = screen_->topCursorVisible(bv_->text);
372 buffer_->resizeInsets(bv_);
374 // this will scroll the screen such that the cursor becomes visible
379 owner_->allowInput();
381 /// clear the "Formatting Document" message
388 void BufferView::Pimpl::updateScreen()
390 // Regenerate the screen.
391 screen_.reset(new LyXScreen(workarea_));
395 void BufferView::Pimpl::updateScrollbar()
397 /* If the text is smaller than the working area, the scrollbar
398 * maximum must be the working area height. No scrolling will
401 workarea_.setScrollbar(0, 1.0);
405 long const text_height = bv_->text->height;
407 double const lineh = bv_->text->defaultHeight();
408 double const slider_size =
409 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
411 static long old_text_height = 0;
412 static double old_lineh = 0;
413 static double old_slider_size = 0;
415 if (text_height != old_text_height) {
416 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
417 old_text_height = text_height;
419 if (lineh != old_lineh) {
420 workarea_.setScrollbarIncrements(lineh);
423 if (current_scrollbar_value != bv_->text->first
424 || slider_size != old_slider_size) {
425 current_scrollbar_value = bv_->text->first;
426 workarea_.setScrollbar(current_scrollbar_value, slider_size);
427 old_slider_size = slider_size;
432 // Callback for scrollbar slider
433 void BufferView::Pimpl::scrollCB(double value)
435 if (!buffer_) return;
437 current_scrollbar_value = long(value);
438 if (current_scrollbar_value < 0)
439 current_scrollbar_value = 0;
444 screen_->draw(bv_->text, bv_, current_scrollbar_value);
446 if (!lyxrc.cursor_follows_scrollbar) {
451 LyXText * vbt = bv_->text;
453 int const height = vbt->defaultHeight();
454 int const first = static_cast<int>((bv_->text->first + height));
455 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
457 if (vbt->cursor.y() < first)
458 vbt->setCursorFromCoordinates(bv_, 0, first);
459 else if (vbt->cursor.y() > last)
460 vbt->setCursorFromCoordinates(bv_, 0, last);
466 int BufferView::Pimpl::scrollUp(long time)
468 if (!buffer_) return 0;
469 if (!screen_.get()) return 0;
471 double value = workarea_.getScrollbarValue();
473 if (value == 0) return 0;
475 float add_value = (bv_->text->defaultHeight()
476 + float(time) * float(time) * 0.125);
478 if (add_value > workarea_.height())
479 add_value = float(workarea_.height() -
480 bv_->text->defaultHeight());
487 workarea_.setScrollbarValue(value);
494 int BufferView::Pimpl::scrollDown(long time)
496 if (!buffer_) return 0;
497 if (!screen_.get()) return 0;
499 double value = workarea_.getScrollbarValue();
500 pair<float, float> p = workarea_.getScrollbarBounds();
501 double const max = p.second;
503 if (value == max) return 0;
505 float add_value = (bv_->text->defaultHeight()
506 + float(time) * float(time) * 0.125);
508 if (add_value > workarea_.height())
509 add_value = float(workarea_.height() -
510 bv_->text->defaultHeight());
517 workarea_.setScrollbarValue(value);
524 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
526 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
530 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
532 // Only use motion with button 1
533 if (!(state & Button1MotionMask))
536 if (!buffer_ || !screen_.get()) return;
538 // Check for inset locking
539 if (bv_->theLockingInset()) {
540 LyXCursor cursor = bv_->text->cursor;
541 LyXFont font = bv_->text->getFont(buffer_,
542 cursor.par(), cursor.pos());
543 int width = bv_->theLockingInset()->width(bv_, font);
544 int inset_x = font.isVisibleRightToLeft()
545 ? cursor.x() - width : cursor.x();
546 int start_x = inset_x + bv_->theLockingInset()->scroll();
547 bv_->theLockingInset()->
548 insetMotionNotify(bv_,
550 y - cursor.y() + bv_->text->first,
555 /* The test for not selection possible is needed, that only motion
556 events are used, where the bottom press event was on
557 the drawing area too */
558 if (!selection_possible)
561 screen_->hideCursor();
563 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
565 if (!bv_->text->selection.set())
566 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
568 bv_->text->setSelection(bv_);
569 screen_->toggleToggle(bv_->text, bv_);
572 screen_->showCursor(bv_->text, bv_);
579 // Single-click on work area
580 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
583 if (!buffer_ || !screen_.get()) return;
585 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
587 // ok ok, this is a hack.
588 if (button == 4 || button == 5) {
591 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
594 scrollDown(lyxrc.wheel_jump);
599 if (bv_->theLockingInset()) {
600 // We are in inset locking mode
602 /* Check whether the inset was hit. If not reset mode,
603 otherwise give the event to the inset */
604 if (inset_hit == bv_->theLockingInset()) {
605 bv_->theLockingInset()->
606 insetButtonPress(bv_,xpos, ypos,button);
609 bv_->unlockInset(bv_->theLockingInset());
614 selection_possible = true;
615 screen_->hideCursor();
617 int const screen_first = bv_->text->first;
619 // Middle button press pastes if we have a selection
620 bool paste_internally = false;
622 && bv_->text->selection.set()) {
623 owner_->getLyXFunc()->dispatch(LFUN_COPY);
624 paste_internally = true;
627 // Clear the selection
628 screen_->toggleSelection(bv_->text, bv_);
629 bv_->text->clearSelection();
630 bv_->text->fullRebreak(bv_);
632 screen_->update(bv_->text, bv_);
638 // Single left click in math inset?
639 if (isHighlyEditableInset(inset_hit)) {
640 // Highly editable inset, like math
641 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
642 selection_possible = false;
643 owner_->updateLayoutChoice();
644 owner_->message(inset->editMessage());
645 inset->insetButtonPress(bv_, xpos, ypos, button);
646 inset->edit(bv_, xpos, ypos, button);
650 // Right click on a footnote flag opens float menu
652 selection_possible = false;
656 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
657 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
659 bv_->text->selection.cursor = bv_->text->cursor;
660 bv_->text->cursor.x_fix(bv_->text->cursor.x());
662 owner_->updateLayoutChoice();
664 selection_possible = false;
667 // Insert primary selection with middle mouse
668 // if there is a local selection in the current buffer,
671 if (paste_internally)
672 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
674 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
676 selection_possible = false;
682 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
688 LyXText * text = bv_->getLyXText();
690 if (text->bv_owner && bv_->theLockingInset())
693 if (screen_.get() && button == 1) {
694 if (text->bv_owner) {
695 screen_->hideCursor();
696 screen_->toggleSelection(text, bv_);
697 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
698 screen_->toggleSelection(text, bv_, false);
700 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
702 /* This will fit the cursor on the screen
704 update(text, BufferView::SELECT|BufferView::FITCUR);
709 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
715 LyXText * text = bv_->getLyXText();
717 if (text->bv_owner && bv_->theLockingInset())
720 if (screen_.get() && (button == 1)) {
721 if (text->bv_owner) {
722 screen_->hideCursor();
723 screen_->toggleSelection(text, bv_);
725 text->cursorHome(bv_);
726 text->selection.cursor = text->cursor;
727 text->cursorEnd(bv_);
728 text->setSelection(bv_);
729 if (text->bv_owner) {
730 screen_->toggleSelection(text, bv_, false);
732 /* This will fit the cursor on the screen
734 update(text, BufferView::SELECT|BufferView::FITCUR);
739 void BufferView::Pimpl::enterView()
741 if (active() && available()) {
742 SetXtermCursor(workarea_.getWin());
743 using_xterm_cursor = true;
748 void BufferView::Pimpl::leaveView()
750 if (using_xterm_cursor) {
751 XUndefineCursor(fl_get_display(), workarea_.getWin());
752 using_xterm_cursor = false;
757 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
760 if (!buffer_ || !screen_.get()) return;
762 // If we hit an inset, we have the inset coordinates in these
763 // and inset_hit points to the inset. If we do not hit an
764 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
765 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
767 if (bv_->theLockingInset()) {
768 // We are in inset locking mode.
770 /* LyX does a kind of work-area grabbing for insets.
771 Only a ButtonPress Event outside the inset will
772 force a insetUnlock. */
773 bv_->theLockingInset()->
774 insetButtonRelease(bv_, x, y, button);
778 selection_possible = false;
785 owner_->updateMenubar();
786 owner_->updateToolbar();
788 // Did we hit an editable inset?
790 // Inset like error, notes and figures
791 selection_possible = false;
793 // if we reach this point with a selection, it
794 // must mean we are currently selecting.
795 // But we don't want to open the inset
796 // because that is annoying for the user.
797 // So just pretend we didn't hit it.
798 // this is OK because a "kosher" ButtonRelease
799 // will follow a ButtonPress that clears
801 // Note this also fixes selection drawing
802 // problems if we end up opening an inset
803 if (bv_->getLyXText()->selection.set())
806 // CHECK fix this proper in 0.13
807 // well, maybe 13.0 !!!!!!!!!
809 // Following a ref shouldn't issue
810 // a push on the undo-stack
811 // anylonger, now that we have
812 // keybindings for following
813 // references and returning from
814 // references. IMHO though, it
815 // should be the inset's own business
816 // to push or not push on the undo
817 // stack. They don't *have* to
818 // alter the document...
820 // ...or maybe the SetCursorParUndo()
821 // below isn't necessary at all anylonger?
822 if (inset_hit->lyxCode() == Inset::REF_CODE) {
823 setCursorParUndo(bv_);
826 owner_->message(inset_hit->editMessage());
828 if (isHighlyEditableInset(inset_hit)) {
829 // Highly editable inset, like math
830 UpdatableInset *inset = (UpdatableInset *)inset_hit;
831 inset->insetButtonRelease(bv_, x, y, button);
833 inset_hit->insetButtonRelease(bv_, x, y, button);
834 inset_hit->edit(bv_, x, y, button);
839 // Maybe we want to edit a bibitem ale970302
840 if (bv_->text->cursor.par()->bibkey && x < 20 +
841 bibitemMaxWidth(bv_, textclasslist.
843 params.textclass).defaultfont())) {
844 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
851 Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
853 Paragraph /*const*/ & par = *cursor.par();
854 pos_type const pos = cursor.pos();
856 lyx::Assert(par.getInset(pos));
858 Inset const & inset(*par.getInset(pos));
860 LyXFont const & font = text.getFont(buffer_, &par, pos);
862 int const width = inset.width(bv_, font);
863 int const inset_x = font.isVisibleRightToLeft()
864 ? (cursor.x() - width) : cursor.x();
867 inset_x + inset.scroll(),
869 cursor.y() - inset.ascent(bv_, font),
870 cursor.y() + inset.descent(bv_, font));
874 Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
876 pos_type const pos(cursor.pos());
877 Paragraph /*const*/ & par(*cursor.par());
879 if (pos >= par.size() || !par.isInset(pos)) {
883 Inset /*const*/ * inset = par.getInset(pos);
885 if (!isEditableInset(inset)) {
889 Box b(insetDimensions(text, cursor));
891 if (!b.contained(x, y)) {
892 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
893 << " box " << b << endl;
897 text.setCursor(bv_, &par, pos, true);
900 // The origin of an inset is on the baseline
901 y -= (text.cursor.y());
907 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
912 int y_tmp = y + text->first;
915 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
917 Inset * inset(checkInset(*text, cursor, x, y_tmp));
924 // look at previous position
926 if (cursor.pos() == 0) {
931 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
933 inset = checkInset(*text, cursor, x, y_tmp);
941 void BufferView::Pimpl::workAreaExpose()
943 static int work_area_width;
944 static unsigned int work_area_height;
946 bool const widthChange = workarea_.workWidth() != work_area_width;
947 bool const heightChange = workarea_.height() != work_area_height;
949 // update from work area
950 work_area_width = workarea_.workWidth();
951 work_area_height = workarea_.height();
954 // The visible LyXView need a resize
957 // Remove all texts from the textcache
958 // This is not _really_ what we want to do. What
959 // we really want to do is to delete in textcache
960 // that does not have a BufferView with matching
961 // width, but as long as we have only one BufferView
962 // deleting all gives the same result.
963 if (lyxerr.debugging())
964 textcache.show(lyxerr, "Expose delete all");
966 } else if (heightChange) {
967 // Rebuild image of current screen
969 // fitCursor() ensures we don't jump back
970 // to the start of the document on vertical
974 // The main window size has changed, repaint most stuff
976 } else if (screen_.get())
977 screen_->redraw(bv_->text, bv_);
979 // Grey box when we don't have a buffer
983 // always make sure that the scrollbar is sane.
985 owner_->updateLayoutChoice();
990 void BufferView::Pimpl::update()
993 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
995 LyXText::text_status st = bv_->text->status();
996 screen_->update(bv_->text, bv_);
998 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
999 if (bv_->text->fullRebreak(bv_)) {
1000 st = LyXText::NEED_MORE_REFRESH;
1001 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1002 bv_->text->cursor.pos());
1005 bv_->text->status(bv_, st);
1006 screen_->update(bv_->text, bv_);
1008 // do this here instead of in the screen::update because of
1010 bv_->text->status(bv_, LyXText::UNCHANGED);
1016 // Values used when calling update:
1018 // -2 - update, move sel_cursor if selection, fitcursor
1019 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1020 // 0 - update, move sel_cursor if selection, fitcursor
1021 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1022 // 3 - update, move sel_cursor if selection
1025 // a simple redraw of the parts that need refresh
1027 // move sel_cursor if selection -
1028 // the text's sel_cursor is moved if there is selection is progress
1031 // fitCursor() is called and the scrollbar updated
1034 // the buffer is marked dirty.
1043 // UPDATE_ONLY = UPDATE;
1044 // UPDATE_SELECT = UPDATE | SELECT;
1045 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1046 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1048 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1049 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1050 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1051 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1052 // update(3) -> update(1) -> update(1) -> update(SELECT)
1054 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1056 owner_->updateLayoutChoice();
1058 if (!text->selection.set() && (f & SELECT)) {
1059 text->selection.cursor = text->cursor;
1062 text->fullRebreak(bv_);
1064 if (text->inset_owner) {
1065 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1066 updateInset(text->inset_owner, false);
1076 buffer_->markDirty();
1081 // Callback for cursor timer
1082 void BufferView::Pimpl::cursorToggle()
1084 // Quite a nice place for asyncron Inset updating, isn't it?
1085 // Actually no! This is run even if no buffer exist... so (Lgb)
1087 cursor_timeout.restart();
1092 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1093 if (pid == -1) // error find out what is wrong
1094 ; // ignore it for now.
1096 sigchldchecker(pid, &status);
1098 updatelist.update(bv_);
1100 if (!screen_.get()) {
1101 cursor_timeout.restart();
1105 if (!bv_->theLockingInset()) {
1106 screen_->cursorToggle(bv_);
1108 bv_->theLockingInset()->toggleInsetCursor(bv_);
1111 cursor_timeout.restart();
1115 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1117 if (!text->cursor.row()->previous())
1120 int y = text->first;
1121 if (text->inset_owner)
1122 y += bv_->text->first;
1123 Row * cursorrow = text->cursor.row();
1124 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1126 // This is to allow jumping over large insets
1127 if ((cursorrow == text->cursor.row()))
1128 text->cursorUp(bv_);
1130 if (text->inset_owner ||
1131 text->cursor.row()->height() < workarea_.height())
1132 screen_->draw(bv_->text, bv_,
1134 - text->cursor.row()->baseline()
1135 + text->cursor.row()->height()
1136 - workarea_.height() + 1 );
1141 void BufferView::Pimpl::cursorNext(LyXText * text)
1143 if (!text->cursor.row()->next())
1146 int y = text->first + workarea_.height();
1147 // if (text->inset_owner)
1148 // y += bv_->text->first;
1149 text->getRowNearY(y);
1151 Row * cursorrow = text->cursor.row();
1152 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1154 // This is to allow jumping over large insets
1155 if ((cursorrow == bv_->text->cursor.row()))
1156 text->cursorDown(bv_);
1158 if (text->inset_owner ||
1159 text->cursor.row()->height() < workarea_.height())
1160 screen_->draw(bv_->text, bv_, text->cursor.y() -
1161 text->cursor.row()->baseline());
1166 bool BufferView::Pimpl::available() const
1168 if (buffer_ && bv_->text) return true;
1173 void BufferView::Pimpl::beforeChange(LyXText * text)
1176 text->clearSelection();
1180 void BufferView::Pimpl::savePosition(unsigned int i)
1182 if (i >= saved_positions_num)
1184 saved_positions[i] = Position(buffer_->fileName(),
1185 bv_->text->cursor.par()->id(),
1186 bv_->text->cursor.pos());
1189 str << _("Saved bookmark") << ' ' << i;
1190 owner_->message(str.str().c_str());
1195 void BufferView::Pimpl::restorePosition(unsigned int i)
1197 if (i >= saved_positions_num)
1200 string const fname = saved_positions[i].filename;
1202 beforeChange(bv_->text);
1204 if (fname != buffer_->fileName()) {
1205 Buffer * b = bufferlist.exists(fname) ?
1206 bufferlist.getBuffer(fname) :
1207 bufferlist.loadLyXFile(fname); // don't ask, just load it
1208 if (b != 0 ) buffer(b);
1211 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1215 bv_->text->setCursor(bv_, par,
1216 min(par->size(), saved_positions[i].par_pos));
1218 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1221 str << _("Moved to bookmark") << ' ' << i;
1222 owner_->message(str.str().c_str());
1227 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1229 if (i >= saved_positions_num)
1232 return !saved_positions[i].filename.empty();
1236 void BufferView::Pimpl::setState()
1238 if (!lyxrc.rtl_support)
1241 LyXText * text = bv_->getLyXText();
1242 if (text->real_current_font.isRightToLeft()) {
1243 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1244 owner_->getIntl()->KeyMapSec();
1246 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1247 owner_->getIntl()->KeyMapPrim();
1252 void BufferView::Pimpl::insetSleep()
1254 if (bv_->theLockingInset() && !inset_slept) {
1255 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1256 bv_->theLockingInset()->insetUnlock(bv_);
1262 void BufferView::Pimpl::insetWakeup()
1264 if (bv_->theLockingInset() && inset_slept) {
1265 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1266 inset_slept = false;
1271 void BufferView::Pimpl::insetUnlock()
1273 if (bv_->theLockingInset()) {
1275 bv_->theLockingInset()->insetUnlock(bv_);
1276 bv_->theLockingInset(0);
1278 inset_slept = false;
1283 bool BufferView::Pimpl::focus() const
1285 return workarea_.hasFocus();
1289 void BufferView::Pimpl::focus(bool f)
1291 if (f) workarea_.setFocus();
1295 bool BufferView::Pimpl::active() const
1297 return workarea_.active();
1301 bool BufferView::Pimpl::belowMouse() const
1303 return workarea_.belowMouse();
1307 void BufferView::Pimpl::showCursor()
1309 if (screen_.get()) {
1310 if (bv_->theLockingInset())
1311 bv_->theLockingInset()->showInsetCursor(bv_);
1313 screen_->showCursor(bv_->text, bv_);
1318 void BufferView::Pimpl::hideCursor()
1320 if (screen_.get()) {
1321 if (!bv_->theLockingInset())
1322 // bv_->theLockingInset()->hideInsetCursor(bv_);
1324 screen_->hideCursor();
1329 void BufferView::Pimpl::toggleSelection(bool b)
1331 if (screen_.get()) {
1332 if (bv_->theLockingInset())
1333 bv_->theLockingInset()->toggleSelection(bv_, b);
1334 screen_->toggleSelection(bv_->text, bv_, b);
1339 void BufferView::Pimpl::toggleToggle()
1342 screen_->toggleToggle(bv_->text, bv_);
1346 void BufferView::Pimpl::center()
1348 beforeChange(bv_->text);
1349 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1350 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1352 screen_->draw(bv_->text, bv_, 0);
1354 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1359 void BufferView::Pimpl::pasteClipboard(bool asPara)
1361 if (!buffer_) return;
1363 screen_->hideCursor();
1364 beforeChange(bv_->text);
1366 string const clip(workarea_.getClipboard());
1368 if (clip.empty()) return;
1371 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1373 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1375 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1379 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1381 workarea_.putClipboard(stuff);
1386 * Dispatch functions for actions which can be valid for BufferView->text
1387 * and/or InsetText->text!!!
1392 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1394 LyXText * lt = bv_->getLyXText();
1396 if (selecting || lt->selection.mark()) {
1397 lt->setSelection(bv_);
1401 update(lt, BufferView::SELECT|BufferView::FITCUR);
1404 /* ---> Everytime the cursor is moved, show the current font state. */
1405 // should this too me moved out of this func?
1406 //owner->showState();
1411 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1413 LyXCursor cursor = bv_->getLyXText()->cursor;
1414 Buffer::inset_iterator it =
1415 find_if(Buffer::inset_iterator(
1416 cursor.par(), cursor.pos()),
1417 buffer_->inset_iterator_end(),
1418 lyx::compare_memfun(&Inset::lyxCode, code));
1419 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1423 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1425 string filename = filen;
1427 if (filename.empty()) {
1428 // Launch a file browser
1429 string initpath = lyxrc.document_path;
1432 string const trypath = owner_->buffer()->filepath;
1433 // If directory is writeable, use this as default.
1434 if (IsDirWriteable(trypath))
1438 FileDialog fileDlg(bv_->owner(),
1439 _("Select LyX document to insert"),
1441 make_pair(string(_("Documents|#o#O")),
1442 string(lyxrc.document_path)),
1443 make_pair(string(_("Examples|#E#e")),
1444 string(AddPath(system_lyxdir, "examples"))));
1446 FileDialog::Result result =
1447 fileDlg.Select(initpath,
1448 _("*.lyx| LyX Documents (*.lyx)"));
1450 if (result.first == FileDialog::Later)
1453 filename = result.second;
1455 // check selected filename
1456 if (filename.empty()) {
1457 owner_->message(_("Canceled."));
1462 // get absolute path of file and add ".lyx" to the filename if
1464 filename = FileSearch(string(), filename, "lyx");
1466 string const disp_fn(MakeDisplayPath(filename));
1469 s1 << _("Inserting document") << ' '
1470 << disp_fn << " ...";
1471 owner_->message(s1.str().c_str());
1472 bool const res = bv_->insertLyXFile(filename);
1475 str << _("Document") << ' ' << disp_fn
1476 << ' ' << _("inserted.");
1477 owner_->message(str.str().c_str());
1480 str << _("Could not insert document") << ' '
1482 owner_->message(str.str().c_str());
1487 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1489 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1490 << action <<"] arg[" << argument << "]" << endl;
1493 // --- Misc -------------------------------------------
1497 LyXText * lt = bv_->getLyXText();
1498 lt->toggleAppendix(bv_);
1501 | BufferView::FITCUR
1502 | BufferView::CHANGE);
1507 case LFUN_TOC_INSERT:
1509 InsetCommandParams p;
1510 p.setCmdName("tableofcontents");
1511 Inset * inset = new InsetTOC(p);
1512 if (!insertInset(inset, "Standard"))
1517 case LFUN_TABULAR_FEATURE:
1518 case LFUN_SCROLL_INSET:
1519 // this is not handled here as this funktion is only aktive
1520 // if we have a locking_inset and that one is (or contains)
1524 case LFUN_INSET_GRAPHICS:
1526 Inset * new_inset = new InsetGraphics;
1527 if (!insertInset(new_inset)) {
1530 // this is need because you don't use a inset->Edit()
1531 updateInset(new_inset, true);
1532 new_inset->edit(bv_);
1542 case LFUN_PASTESELECTION:
1544 bool asPara = false;
1545 if (argument == "paragraph")
1547 pasteClipboard(asPara);
1559 case LFUN_LAYOUT_COPY:
1560 bv_->copyEnvironment();
1563 case LFUN_LAYOUT_PASTE:
1564 bv_->pasteEnvironment();
1568 case LFUN_GOTOERROR:
1569 gotoInset(Inset::ERROR_CODE, false);
1573 gotoInset(Inset::IGNORE_CODE, false);
1576 case LFUN_REFERENCE_GOTO:
1578 vector<Inset::Code> tmp;
1579 tmp.push_back(Inset::LABEL_CODE);
1580 tmp.push_back(Inset::REF_CODE);
1581 gotoInset(tmp, true);
1585 case LFUN_HYPHENATION:
1586 specialChar(InsetSpecialChar::HYPHENATION);
1589 case LFUN_LIGATURE_BREAK:
1590 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1594 specialChar(InsetSpecialChar::LDOTS);
1597 case LFUN_END_OF_SENTENCE:
1598 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1601 case LFUN_MENU_SEPARATOR:
1602 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1610 changeDepth(bv_, bv_->getLyXText(), 0);
1613 case LFUN_DEPTH_MIN:
1614 changeDepth(bv_, bv_->getLyXText(), -1);
1617 case LFUN_DEPTH_PLUS:
1618 changeDepth(bv_, bv_->getLyXText(), 1);
1622 owner_->getDialogs()->setUserFreeFont();
1625 case LFUN_FILE_INSERT:
1626 MenuInsertLyXFile(argument);
1629 case LFUN_FILE_INSERT_ASCII_PARA:
1630 InsertAsciiFile(bv_, argument, true);
1633 case LFUN_FILE_INSERT_ASCII:
1634 InsertAsciiFile(bv_, argument, false);
1639 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1640 << argument << endl;
1642 // Derive layout number from given argument (string)
1643 // and current buffer's textclass (number). */
1644 textclass_type tclass = buffer_->params.textclass;
1645 pair <bool, layout_type> layout =
1646 textclasslist.NumberOfLayout(tclass, argument);
1648 // If the entry is obsolete, use the new one instead.
1650 string obs = textclasslist.Style(tclass, layout.second)
1653 layout = textclasslist.NumberOfLayout(tclass, obs);
1656 // see if we found the layout number:
1657 if (!layout.first) {
1658 owner_->getLyXFunc()->setErrorMessage(
1659 string(N_("Layout ")) + argument +
1664 if (current_layout != layout.second) {
1665 LyXText * lt = bv_->getLyXText();
1667 current_layout = layout.second;
1670 | BufferView::FITCUR);
1671 lt->setLayout(bv_, layout.second);
1672 owner_->setLayout(layout.second);
1675 | BufferView::FITCUR
1676 | BufferView::CHANGE);
1683 lang(bv_, argument);
1685 owner_->showState();
1690 owner_->showState();
1695 owner_->showState();
1700 owner_->showState();
1705 owner_->showState();
1710 owner_->showState();
1715 owner_->showState();
1720 owner_->showState();
1723 case LFUN_UNDERLINE:
1725 owner_->showState();
1728 case LFUN_FONT_SIZE:
1729 fontSize(bv_, argument);
1730 owner_->showState();
1733 case LFUN_FONT_STATE:
1734 owner_->getLyXFunc()->setMessage(currentState(bv_));
1737 case LFUN_UPCASE_WORD:
1739 LyXText * lt = bv_->getLyXText();
1743 | BufferView::FITCUR);
1744 lt->changeCase(bv_, LyXText::text_uppercase);
1745 if (lt->inset_owner)
1746 updateInset(lt->inset_owner, true);
1749 | BufferView::FITCUR
1750 | BufferView::CHANGE);
1754 case LFUN_LOWCASE_WORD:
1756 LyXText * lt = bv_->getLyXText();
1758 update(lt, BufferView::SELECT|BufferView::FITCUR);
1759 lt->changeCase(bv_, LyXText::text_lowercase);
1760 if (lt->inset_owner)
1761 updateInset(lt->inset_owner, true);
1764 | BufferView::FITCUR
1765 | BufferView::CHANGE);
1769 case LFUN_CAPITALIZE_WORD:
1771 LyXText * lt = bv_->getLyXText();
1773 update(lt, BufferView::SELECT|BufferView::FITCUR);
1774 lt->changeCase(bv_, LyXText::text_capitalization);
1775 if (lt->inset_owner)
1776 updateInset(lt->inset_owner, true);
1779 | BufferView::FITCUR
1780 | BufferView::CHANGE);
1784 case LFUN_TRANSPOSE_CHARS:
1786 LyXText * lt = bv_->getLyXText();
1788 update(lt, BufferView::SELECT|BufferView::FITCUR);
1789 lt->transposeChars(*bv_);
1790 if (lt->inset_owner)
1791 updateInset(lt->inset_owner, true);
1794 | BufferView::FITCUR
1795 | BufferView::CHANGE);
1800 case LFUN_INSERT_LABEL:
1801 MenuInsertLabel(bv_, argument);
1804 case LFUN_REF_INSERT:
1805 if (argument.empty()) {
1806 InsetCommandParams p("ref");
1807 owner_->getDialogs()->createRef(p.getAsString());
1809 InsetCommandParams p;
1810 p.setFromString(argument);
1812 InsetRef * inset = new InsetRef(p, *buffer_);
1813 if (!insertInset(inset))
1816 updateInset(inset, true);
1820 case LFUN_BOOKMARK_SAVE:
1821 savePosition(strToUnsignedInt(argument));
1824 case LFUN_BOOKMARK_GOTO:
1825 restorePosition(strToUnsignedInt(argument));
1830 string label(argument);
1831 if (label.empty()) {
1833 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1835 label = inset->getContents();
1840 if (!label.empty()) {
1841 //bv_->savePosition(0);
1842 if (!bv_->gotoLabel(label))
1843 Alert::alert(_("Error"),
1844 _("Couldn't find this label"),
1845 _("in current document."));
1850 // --- Cursor Movements -----------------------------
1853 LyXText * lt = bv_->getLyXText();
1855 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1856 if (!lt->selection.mark())
1858 update(lt, BufferView::SELECT|BufferView::FITCUR);
1860 lt->cursorLeft(bv_, false);
1861 if (lt->cursor.pos() < lt->cursor.par()->size()
1862 && lt->cursor.par()->isInset(lt->cursor.pos())
1863 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1864 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1865 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1867 tmpinset->edit(bv_, false);
1869 tmpinset->edit(bv_);
1873 lt->cursorRight(bv_, false);
1875 moveCursorUpdate(false);
1876 owner_->showState();
1882 // This is soooo ugly. Isn`t it possible to make
1883 // it simpler? (Lgb)
1884 LyXText * lt = bv_->getLyXText();
1885 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1886 if (!lt->selection.mark())
1888 update(lt, BufferView::SELECT|BufferView::FITCUR);
1889 LyXCursor const cur = lt->cursor;
1891 lt->cursorLeft(bv_, false);
1892 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1893 lt->cursor.pos() < lt->cursor.par()->size() &&
1894 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1895 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1896 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1897 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1899 tmpinset->edit(bv_);
1901 tmpinset->edit(bv_, false);
1905 lt->cursorRight(bv_, false);
1908 moveCursorUpdate(false);
1909 owner_->showState();
1915 LyXText * lt = bv_->getLyXText();
1917 if (!lt->selection.mark())
1919 update(lt, BufferView::UPDATE);
1922 moveCursorUpdate(false);
1923 owner_->showState();
1929 LyXText * lt = bv_->getLyXText();
1931 if (!lt->selection.mark())
1933 update(lt, BufferView::UPDATE);
1934 lt->cursorDown(bv_);
1936 moveCursorUpdate(false);
1937 owner_->showState();
1941 case LFUN_UP_PARAGRAPH:
1943 LyXText * lt = bv_->getLyXText();
1945 if (!lt->selection.mark())
1947 update(lt, BufferView::UPDATE);
1948 lt->cursorUpParagraph(bv_);
1950 moveCursorUpdate(false);
1951 owner_->showState();
1955 case LFUN_DOWN_PARAGRAPH:
1957 LyXText * lt = bv_->getLyXText();
1959 if (!lt->selection.mark())
1961 update(lt, BufferView::UPDATE);
1962 lt->cursorDownParagraph(bv_);
1964 moveCursorUpdate(false);
1965 owner_->showState();
1971 LyXText * lt = bv_->getLyXText();
1973 if (!lt->selection.mark())
1975 update(lt, BufferView::UPDATE);
1978 moveCursorUpdate(false);
1979 owner_->showState();
1985 LyXText * lt = bv_->getLyXText();
1987 if (!lt->selection.mark())
1989 update(lt, BufferView::UPDATE);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1999 LyXText * lt = bv_->getLyXText();
2001 if (!lt->selection.mark())
2003 update(lt, BufferView::SELECT|BufferView::FITCUR);
2004 lt->cursorHome(bv_);
2006 moveCursorUpdate(false);
2007 owner_->showState();
2013 LyXText * lt = bv_->getLyXText();
2015 if (!lt->selection.mark())
2018 BufferView::SELECT|BufferView::FITCUR);
2021 moveCursorUpdate(false);
2022 owner_->showState();
2026 case LFUN_SHIFT_TAB:
2029 LyXText * lt = bv_->getLyXText();
2031 if (!lt->selection.mark())
2034 BufferView::SELECT|BufferView::FITCUR);
2037 moveCursorUpdate(false);
2038 owner_->showState();
2042 case LFUN_WORDRIGHT:
2044 LyXText * lt = bv_->getLyXText();
2046 if (!lt->selection.mark())
2048 update(lt, BufferView::SELECT|BufferView::FITCUR);
2049 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2050 lt->cursorLeftOneWord(bv_);
2052 lt->cursorRightOneWord(bv_);
2054 moveCursorUpdate(false);
2055 owner_->showState();
2061 LyXText * lt = bv_->getLyXText();
2063 if (!lt->selection.mark())
2065 update(lt, BufferView::SELECT|BufferView::FITCUR);
2066 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2067 lt->cursorRightOneWord(bv_);
2069 lt->cursorLeftOneWord(bv_);
2071 moveCursorUpdate(false);
2072 owner_->showState();
2076 case LFUN_BEGINNINGBUF:
2078 LyXText * lt = bv_->getLyXText();
2080 if (!lt->selection.mark())
2083 BufferView::SELECT|BufferView::FITCUR);
2086 moveCursorUpdate(false);
2087 owner_->showState();
2093 LyXText * lt = bv_->getLyXText();
2095 if (!lt->selection.mark())
2098 BufferView::SELECT|BufferView::FITCUR);
2099 lt->cursorBottom(bv_);
2101 moveCursorUpdate(false);
2102 owner_->showState();
2106 /* cursor selection ---------------------------- */
2109 LyXText * lt = bv_->getLyXText();
2112 BufferView::SELECT|BufferView::FITCUR);
2113 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2114 lt->cursorLeft(bv_);
2116 lt->cursorRight(bv_);
2118 moveCursorUpdate(true);
2119 owner_->showState();
2125 LyXText * lt = bv_->getLyXText();
2128 BufferView::SELECT|BufferView::FITCUR);
2129 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2130 lt->cursorRight(bv_);
2132 lt->cursorLeft(bv_);
2134 moveCursorUpdate(true);
2135 owner_->showState();
2141 LyXText * lt = bv_->getLyXText();
2144 BufferView::SELECT|BufferView::FITCUR);
2147 moveCursorUpdate(true);
2148 owner_->showState();
2154 LyXText * lt = bv_->getLyXText();
2157 BufferView::SELECT|BufferView::FITCUR);
2158 lt->cursorDown(bv_);
2160 moveCursorUpdate(true);
2161 owner_->showState();
2165 case LFUN_UP_PARAGRAPHSEL:
2167 LyXText * lt = bv_->getLyXText();
2170 BufferView::SELECT|BufferView::FITCUR);
2171 lt->cursorUpParagraph(bv_);
2173 moveCursorUpdate(true);
2174 owner_->showState();
2178 case LFUN_DOWN_PARAGRAPHSEL:
2180 LyXText * lt = bv_->getLyXText();
2183 BufferView::SELECT|BufferView::FITCUR);
2184 lt->cursorDownParagraph(bv_);
2186 moveCursorUpdate(true);
2187 owner_->showState();
2193 LyXText * lt = bv_->getLyXText();
2195 update(lt, BufferView::SELECT|BufferView::FITCUR);
2198 moveCursorUpdate(true);
2199 owner_->showState();
2205 LyXText * lt = bv_->getLyXText();
2207 update(lt, BufferView::SELECT|BufferView::FITCUR);
2210 moveCursorUpdate(true);
2211 owner_->showState();
2217 LyXText * lt = bv_->getLyXText();
2219 update(lt, BufferView::SELECT|BufferView::FITCUR);
2220 lt->cursorHome(bv_);
2222 moveCursorUpdate(true);
2223 owner_->showState();
2229 LyXText * lt = bv_->getLyXText();
2231 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 moveCursorUpdate(true);
2235 owner_->showState();
2239 case LFUN_WORDRIGHTSEL:
2241 LyXText * lt = bv_->getLyXText();
2243 update(lt, BufferView::SELECT|BufferView::FITCUR);
2244 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2245 lt->cursorLeftOneWord(bv_);
2247 lt->cursorRightOneWord(bv_);
2249 moveCursorUpdate(true);
2250 owner_->showState();
2254 case LFUN_WORDLEFTSEL:
2256 LyXText * lt = bv_->getLyXText();
2258 update(lt, BufferView::SELECT|BufferView::FITCUR);
2259 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2260 lt->cursorRightOneWord(bv_);
2262 lt->cursorLeftOneWord(bv_);
2264 moveCursorUpdate(true);
2265 owner_->showState();
2269 case LFUN_BEGINNINGBUFSEL:
2271 LyXText * lt = bv_->getLyXText();
2273 if (lt->inset_owner)
2275 update(lt, BufferView::SELECT|BufferView::FITCUR);
2278 moveCursorUpdate(true);
2279 owner_->showState();
2283 case LFUN_ENDBUFSEL:
2285 LyXText * lt = bv_->getLyXText();
2287 if (lt->inset_owner)
2290 BufferView::SELECT|BufferView::FITCUR);
2291 lt->cursorBottom(bv_);
2293 moveCursorUpdate(true);
2294 owner_->showState();
2298 // --- text changing commands ------------------------
2299 case LFUN_BREAKLINE:
2301 LyXText * lt = bv_->getLyXText();
2304 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2307 | BufferView::FITCUR
2308 | BufferView::CHANGE);
2309 moveCursorUpdate(false);
2313 case LFUN_PROTECTEDSPACE:
2315 LyXText * lt = bv_->getLyXText();
2317 LyXLayout const & style = textclasslist
2318 .Style(buffer_->params.textclass,
2319 lt->cursor.par()->getLayout());
2321 if (style.free_spacing) {
2322 lt->insertChar(bv_, ' ');
2325 | BufferView::FITCUR
2326 | BufferView::CHANGE);
2330 moveCursorUpdate(false);
2336 LyXText * lt = bv_->getLyXText();
2338 if (lt->selection.mark()) {
2342 | BufferView::FITCUR);
2343 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2346 lt->selection.mark(true);
2349 | BufferView::FITCUR);
2350 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2352 lt->selection.cursor = lt->cursor;
2358 LyXText * lt = bv_->getLyXText();
2360 if (!lt->selection.set()) {
2362 lt->selection.cursor = lt->cursor;
2365 | BufferView::FITCUR
2366 | BufferView::CHANGE);
2367 // It is possible to make it a lot faster still
2368 // just comment out the line below...
2373 moveCursorUpdate(false);
2374 owner_->showState();
2379 case LFUN_DELETE_SKIP:
2381 LyXText * lt = bv_->getLyXText();
2383 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2385 LyXCursor cursor = lt->cursor;
2387 if (!lt->selection.set()) {
2388 if (cursor.pos() == cursor.par()->size()) {
2389 lt->cursorRight(bv_);
2390 cursor = lt->cursor;
2391 if (cursor.pos() == 0
2392 && !(cursor.par()->params().spaceTop()
2393 == VSpace (VSpace::NONE))) {
2396 cursor.par()->params().lineTop(),
2397 cursor.par()->params().lineBottom(),
2398 cursor.par()->params().pagebreakTop(),
2399 cursor.par()->params().pagebreakBottom(),
2400 VSpace(VSpace::NONE),
2401 cursor.par()->params().spaceBottom(),
2402 cursor.par()->params().spacing(),
2403 cursor.par()->params().align(),
2404 cursor.par()->params().labelWidthString(), 0);
2405 lt->cursorLeft(bv_);
2408 | BufferView::FITCUR
2409 | BufferView::CHANGE);
2411 lt->cursorLeft(bv_);
2413 lt->selection.cursor = lt->cursor;
2416 | BufferView::FITCUR
2417 | BufferView::CHANGE);
2421 lt->selection.cursor = lt->cursor;
2424 | BufferView::FITCUR
2425 | BufferView::CHANGE);
2433 /* -------> Delete word forward. */
2434 case LFUN_DELETE_WORD_FORWARD:
2435 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2436 bv_->getLyXText()->deleteWordForward(bv_);
2437 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2438 moveCursorUpdate(false);
2439 owner_->showState();
2442 /* -------> Delete word backward. */
2443 case LFUN_DELETE_WORD_BACKWARD:
2445 LyXText * lt = bv_->getLyXText();
2447 update(lt, BufferView::SELECT|BufferView::FITCUR);
2448 lt->deleteWordBackward(bv_);
2451 | BufferView::FITCUR
2452 | BufferView::CHANGE);
2453 moveCursorUpdate(false);
2454 owner_->showState();
2458 /* -------> Kill to end of line. */
2459 case LFUN_DELETE_LINE_FORWARD:
2461 LyXText * lt = bv_->getLyXText();
2463 update(lt, BufferView::SELECT|BufferView::FITCUR);
2464 lt->deleteLineForward(bv_);
2467 | BufferView::FITCUR
2468 | BufferView::CHANGE);
2469 moveCursorUpdate(false);
2473 /* -------> Set mark off. */
2476 LyXText * lt = bv_->getLyXText();
2479 update(lt, BufferView::SELECT|BufferView::FITCUR);
2480 lt->selection.cursor = lt->cursor;
2481 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2485 /* -------> Set mark on. */
2488 LyXText * lt = bv_->getLyXText();
2491 lt->selection.mark(true);
2492 update(lt, BufferView::SELECT|BufferView::FITCUR);
2493 lt->selection.cursor = lt->cursor;
2494 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2498 case LFUN_BACKSPACE:
2500 LyXText * lt = bv_->getLyXText();
2502 if (!lt->selection.set()) {
2503 if (owner_->getIntl()->getTrans().backspace()) {
2505 lt->selection.cursor = lt->cursor;
2508 | BufferView::FITCUR
2509 | BufferView::CHANGE);
2510 // It is possible to make it a lot faster still
2511 // just comment out the line below...
2517 owner_->showState();
2522 case LFUN_BACKSPACE_SKIP:
2524 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2525 LyXText * lt = bv_->getLyXText();
2527 LyXCursor cursor = lt->cursor;
2529 if (!lt->selection.set()) {
2530 if (cursor.pos() == 0
2531 && !(cursor.par()->params().spaceTop()
2532 == VSpace (VSpace::NONE))) {
2535 cursor.par()->params().lineTop(),
2536 cursor.par()->params().lineBottom(),
2537 cursor.par()->params().pagebreakTop(),
2538 cursor.par()->params().pagebreakBottom(),
2539 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2540 cursor.par()->params().spacing(),
2541 cursor.par()->params().align(),
2542 cursor.par()->params().labelWidthString(), 0);
2545 | BufferView::FITCUR
2546 | BufferView::CHANGE);
2549 lt->selection.cursor = cursor;
2552 | BufferView::FITCUR
2553 | BufferView::CHANGE);
2560 case LFUN_BREAKPARAGRAPH:
2562 LyXText * lt = bv_->getLyXText();
2565 lt->breakParagraph(bv_, 0);
2568 | BufferView::FITCUR
2569 | BufferView::CHANGE);
2570 lt->selection.cursor = lt->cursor;
2572 owner_->showState();
2576 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2578 LyXText * lt = bv_->getLyXText();
2581 lt->breakParagraph(bv_, 1);
2584 | BufferView::FITCUR
2585 | BufferView::CHANGE);
2586 lt->selection.cursor = lt->cursor;
2588 owner_->showState();
2592 case LFUN_BREAKPARAGRAPH_SKIP:
2594 // When at the beginning of a paragraph, remove
2595 // indentation and add a "defskip" at the top.
2596 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2597 LyXText * lt = bv_->getLyXText();
2599 LyXCursor cursor = lt->cursor;
2602 if (cursor.pos() == 0) {
2603 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2606 cursor.par()->params().lineTop(),
2607 cursor.par()->params().lineBottom(),
2608 cursor.par()->params().pagebreakTop(),
2609 cursor.par()->params().pagebreakBottom(),
2610 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2611 cursor.par()->params().spacing(),
2612 cursor.par()->params().align(),
2613 cursor.par()->params().labelWidthString(), 1);
2614 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2618 lt->breakParagraph(bv_, 0);
2619 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2624 | BufferView::FITCUR
2625 | BufferView::CHANGE);
2626 lt->selection.cursor = cursor;
2628 owner_->showState();
2632 case LFUN_PARAGRAPH_SPACING:
2634 LyXText * lt = bv_->getLyXText();
2636 Paragraph * par = lt->cursor.par();
2637 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2638 float cur_value = 1.0;
2639 if (cur_spacing == Spacing::Other) {
2640 cur_value = par->params().spacing().getValue();
2643 istringstream istr(argument.c_str());
2647 Spacing::Space new_spacing = cur_spacing;
2648 float new_value = cur_value;
2650 lyxerr << "Missing argument to `paragraph-spacing'"
2652 } else if (tmp == "single") {
2653 new_spacing = Spacing::Single;
2654 } else if (tmp == "onehalf") {
2655 new_spacing = Spacing::Onehalf;
2656 } else if (tmp == "double") {
2657 new_spacing = Spacing::Double;
2658 } else if (tmp == "other") {
2659 new_spacing = Spacing::Other;
2662 lyxerr << "new_value = " << tmpval << endl;
2665 } else if (tmp == "default") {
2666 new_spacing = Spacing::Default;
2668 lyxerr << _("Unknown spacing argument: ")
2669 << argument << endl;
2671 if (cur_spacing != new_spacing || cur_value != new_value) {
2672 par->params().spacing(Spacing(new_spacing, new_value));
2673 lt->redoParagraph(bv_);
2676 | BufferView::FITCUR
2677 | BufferView::CHANGE);
2682 case LFUN_INSET_TOGGLE:
2684 LyXText * lt = bv_->getLyXText();
2687 update(lt, BufferView::SELECT|BufferView::FITCUR);
2688 lt->toggleInset(bv_);
2689 update(lt, BufferView::SELECT|BufferView::FITCUR);
2701 InsetCommandParams p;
2702 if (action == LFUN_HTMLURL)
2703 p.setCmdName("htmlurl");
2705 p.setCmdName("url");
2706 owner_->getDialogs()->createUrl(p.getAsString());
2710 case LFUN_INSERT_URL:
2712 InsetCommandParams p;
2713 p.setFromString(argument);
2715 InsetUrl * inset = new InsetUrl(p);
2716 if (!insertInset(inset))
2719 updateInset(inset, true);
2723 case LFUN_INSET_TEXT:
2724 insertAndEditInset(new InsetText);
2727 case LFUN_INSET_ERT:
2728 insertAndEditInset(new InsetERT);
2731 case LFUN_INSET_EXTERNAL:
2732 insertAndEditInset(new InsetExternal);
2735 case LFUN_INSET_FOOTNOTE:
2736 insertAndEditInset(new InsetFoot);
2739 case LFUN_INSET_MARGINAL:
2740 insertAndEditInset(new InsetMarginal);
2743 case LFUN_INSET_MINIPAGE:
2744 insertAndEditInset(new InsetMinipage);
2747 case LFUN_INSERT_NOTE:
2748 insertAndEditInset(new InsetNote);
2751 case LFUN_INSET_FLOAT:
2752 // check if the float type exist
2753 if (floatList.typeExist(argument)) {
2754 insertAndEditInset(new InsetFloat(argument));
2756 lyxerr << "Non-existent float type: "
2757 << argument << endl;
2761 case LFUN_INSET_WIDE_FLOAT:
2763 // check if the float type exist
2764 if (floatList.typeExist(argument)) {
2765 InsetFloat * new_inset = new InsetFloat(argument);
2766 new_inset->wide(true);
2767 if (insertInset(new_inset))
2768 new_inset->edit(bv_);
2772 lyxerr << "Non-existent float type: "
2773 << argument << endl;
2780 case LFUN_INSET_LIST:
2781 insertAndEditInset(new InsetList);
2784 case LFUN_INSET_THEOREM:
2785 insertAndEditInset(new InsetTheorem);
2789 case LFUN_INSET_CAPTION:
2791 // Do we have a locking inset...
2792 if (bv_->theLockingInset()) {
2793 lyxerr << "Locking inset code: "
2794 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2795 InsetCaption * new_inset = new InsetCaption;
2796 new_inset->setOwner(bv_->theLockingInset());
2797 new_inset->setAutoBreakRows(true);
2798 new_inset->setDrawFrame(0, InsetText::LOCKED);
2799 new_inset->setFrameColor(0, LColor::captionframe);
2800 if (insertInset(new_inset))
2801 new_inset->edit(bv_);
2808 case LFUN_INSET_TABULAR:
2812 if (!argument.empty())
2813 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2814 InsetTabular * new_inset =
2815 new InsetTabular(*buffer_, r, c);
2817 bv_->getLyXText()->real_current_font.isRightToLeft();
2818 if (!open_new_inset(new_inset, rtl))
2823 // --- lyxserver commands ----------------------------
2825 case LFUN_CHARATCURSOR:
2827 pos_type pos = bv_->getLyXText()->cursor.pos();
2828 if (pos < bv_->getLyXText()->cursor.par()->size())
2829 owner_->getLyXFunc()->setMessage(
2830 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2832 owner_->getLyXFunc()->setMessage("EOF");
2837 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2839 + tostr(bv_->getLyXText()->cursor.y()));
2846 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2847 lyxerr << "SETXY: Could not parse coordinates in '"
2848 << argument << std::endl;
2850 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2854 case LFUN_GETLAYOUT:
2855 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2860 LyXFont & font = bv_->getLyXText()->current_font;
2861 if (font.shape() == LyXFont::ITALIC_SHAPE)
2862 owner_->getLyXFunc()->setMessage("E");
2863 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2864 owner_->getLyXFunc()->setMessage("N");
2866 owner_->getLyXFunc()->setMessage("0");
2871 // --- accented characters ---------------------------
2874 case LFUN_CIRCUMFLEX:
2884 case LFUN_SPECIAL_CARON:
2887 case LFUN_HUNG_UMLAUT:
2890 if (argument.empty()) {
2892 owner_->getLyXFunc()->handleKeyFunc(action);
2894 owner_->getLyXFunc()->handleKeyFunc(action);
2895 owner_->getIntl()->getTrans()
2896 .TranslateAndInsert(argument[0], bv_->getLyXText());
2897 update(bv_->getLyXText(),
2899 | BufferView::FITCUR
2900 | BufferView::CHANGE);
2904 case LFUN_MATH_MACRO:
2905 mathDispatchMathMacro(bv_, argument);
2908 case LFUN_MATH_DELIM:
2909 mathDispatchMathDelim(bv_, argument);
2912 case LFUN_INSERT_MATRIX:
2913 mathDispatchInsertMatrix(bv_, argument);
2916 case LFUN_INSERT_MATH:
2917 mathDispatchInsertMath(bv_, argument);
2920 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2921 mathDispatchMathImportSelection(bv_, argument);
2924 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2925 mathDispatchMathDisplay(bv_, argument);
2928 case LFUN_MATH_MODE: // Open or create an inlined math inset
2929 mathDispatchMathMode(bv_, argument);
2932 case LFUN_GREEK: // Insert a single greek letter
2933 mathDispatchGreek(bv_, argument);
2936 case LFUN_CITATION_INSERT:
2938 InsetCommandParams p;
2939 p.setFromString( argument );
2941 InsetCitation * inset = new InsetCitation( p );
2942 if (!insertInset(inset))
2945 updateInset( inset, true );
2949 case LFUN_INSERT_BIBTEX:
2951 // ale970405+lasgoutt970425
2952 // The argument can be up to two tokens separated
2953 // by a space. The first one is the bibstyle.
2954 string const db = token(argument, ' ', 0);
2955 string const bibstyle = token(argument, ' ', 1);
2957 InsetCommandParams p( "BibTeX", db, bibstyle );
2958 InsetBibtex * inset = new InsetBibtex(p);
2960 if (insertInset(inset)) {
2961 if (argument.empty())
2968 // BibTeX data bases
2969 case LFUN_BIBDB_ADD:
2971 InsetBibtex * inset =
2972 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2974 inset->addDatabase(argument);
2979 case LFUN_BIBDB_DEL:
2981 InsetBibtex * inset =
2982 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2984 inset->delDatabase(argument);
2989 case LFUN_BIBTEX_STYLE:
2991 InsetBibtex * inset =
2992 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2994 inset->setOptions(argument);
2999 case LFUN_INDEX_CREATE:
3001 InsetCommandParams p("index");
3002 if (argument.empty()) {
3003 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3004 p.setContents(idxstring);
3006 p.setContents(argument);
3009 owner_->getDialogs()->createIndex(p.getAsString());
3013 case LFUN_INDEX_INSERT:
3015 InsetCommandParams p;
3016 p.setFromString(argument);
3017 InsetIndex * inset = new InsetIndex(p);
3019 if (!insertInset(inset))
3022 updateInset(inset, true);
3026 case LFUN_INDEX_INSERT_LAST:
3028 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3029 if (!idxstring.empty()) {
3030 owner_->message(_("Word `")
3031 + idxstring + _(("' indexed.")));
3032 InsetCommandParams p("index", idxstring);
3033 InsetIndex * inset = new InsetIndex(p);
3035 if (!insertInset(inset))
3038 updateInset(inset, true);
3043 case LFUN_INDEX_PRINT:
3045 InsetCommandParams p("printindex");
3046 Inset * inset = new InsetPrintIndex(p);
3047 if (!insertInset(inset, "Standard"))
3052 case LFUN_PARENTINSERT:
3054 lyxerr << "arg " << argument << endl;
3055 InsetCommandParams p( "lyxparent", argument );
3056 Inset * inset = new InsetParent(p, *buffer_);
3057 if (!insertInset(inset, "Standard"))
3063 case LFUN_CHILD_INSERT:
3065 InsetInclude::Params p;
3066 p.cparams.setFromString(argument);
3067 p.masterFilename_ = buffer_->fileName();
3069 InsetInclude * inset = new InsetInclude(p);
3070 if (!insertInset(inset))
3073 updateInset(inset, true);
3074 bv_->owner()->getDialogs()->showInclude(inset);
3079 case LFUN_FLOAT_LIST:
3081 // We should check the argument for validity. (Lgb)
3082 Inset * inset = new InsetFloatList(argument);
3083 if (!insertInset(inset, "Standard"))
3088 case LFUN_THESAURUS_ENTRY:
3090 string arg = argument;
3093 arg = bv_->getLyXText()->selectionAsString(buffer_,
3097 if (arg.size() > 100 || arg.empty()) {
3098 // Get word or selection
3099 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3100 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3101 // FIXME: where is getLyXText()->unselect(bv_) ?
3105 bv_->owner()->getDialogs()->showThesaurus(arg);
3109 case LFUN_SELFINSERT:
3111 if (argument.empty()) break;
3113 /* Automatically delete the currently selected
3114 * text and replace it with what is being
3115 * typed in now. Depends on lyxrc settings
3116 * "auto_region_delete", which defaults to
3119 LyXText * lt = bv_->getLyXText();
3121 if (lyxrc.auto_region_delete) {
3122 if (lt->selection.set()) {
3123 lt->cutSelection(bv_, false, false);
3126 | BufferView::FITCUR
3127 | BufferView::CHANGE);
3132 LyXFont const old_font(lt->real_current_font);
3134 string::const_iterator cit = argument.begin();
3135 string::const_iterator end = argument.end();
3136 for (; cit != end; ++cit) {
3137 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3142 | BufferView::FITCUR
3143 | BufferView::CHANGE);
3145 lt->selection.cursor = lt->cursor;
3146 moveCursorUpdate(false);
3148 // real_current_font.number can change so we need to
3149 // update the minibuffer
3150 if (old_font != lt->real_current_font)
3151 owner_->showState();
3156 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3158 time_t now_time_t = time(NULL);
3159 struct tm * now_tm = localtime(&now_time_t);
3160 setlocale(LC_TIME, "");
3162 if (!argument.empty())
3165 arg = lyxrc.date_insert_format;
3167 int const datetmp_len =
3168 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3170 LyXText * lt = bv_->getLyXText();
3172 for (int i = 0; i < datetmp_len; i++) {
3173 lt->insertChar(bv_, datetmp[i]);
3176 | BufferView::FITCUR
3177 | BufferView::CHANGE);
3180 lt->selection.cursor = lt->cursor;
3181 moveCursorUpdate(false);
3185 case LFUN_UNKNOWN_ACTION:
3186 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3197 void BufferView::Pimpl::newline()
3200 LyXText * lt = bv_->getLyXText();
3204 | BufferView::FITCUR);
3205 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3208 | BufferView::FITCUR
3209 | BufferView::CHANGE);
3214 void BufferView::Pimpl::hfill()
3217 LyXText * lt = bv_->getLyXText();
3221 | BufferView::FITCUR);
3222 lt->insertChar(bv_, Paragraph::META_HFILL);
3225 | BufferView::FITCUR
3226 | BufferView::CHANGE);
3231 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3235 update(lt, BufferView::SELECT|BufferView::FITCUR);
3236 InsetSpecialChar * new_inset =
3237 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3238 #ifdef WITH_WARNINGS
3239 #warning Why is this code different from specialChar() below? (JMarc)
3240 // the code in specialChar is a generic version of what used to exist
3241 // for other special chars. I did not merge this case because of the
3242 // call to updateInset(), but what does it do?
3244 if (!insertInset(new_inset))
3247 updateInset(new_inset, true);
3252 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3255 LyXText * lt = bv_->getLyXText();
3258 update(lt, BufferView::SELECT|BufferView::FITCUR);
3259 InsetSpecialChar * new_inset =
3260 new InsetSpecialChar(kind);
3261 if (!insertInset(new_inset))
3267 void BufferView::Pimpl::smartQuote()
3269 LyXText const * lt = bv_->getLyXText();
3270 Paragraph const * par = lt->cursor.par();
3271 pos_type pos = lt->cursor.pos();
3275 || (par->isInset(pos - 1)
3276 && par->getInset(pos - 1)->isSpace()))
3279 c = par->getChar(pos - 1);
3284 LyXLayout const & style = textclasslist.Style(
3285 bv_->buffer()->params.textclass, par->getLayout());
3287 if (style.pass_thru ||
3288 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3289 Dispatch(LFUN_SELFINSERT, "\"");
3293 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3295 if (insertInset(inset))
3302 // Open and lock an updatable inset
3303 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3305 LyXText * lt = bv_->getLyXText();
3309 if (!insertInset(new_inset)) {
3313 new_inset->edit(bv_, !behind);
3318 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3320 // if we are in a locking inset we should try to insert the
3321 // inset there otherwise this is a illegal function now
3322 if (bv_->theLockingInset()) {
3323 if (bv_->theLockingInset()->insetAllowed(inset))
3324 return bv_->theLockingInset()->insertInset(bv_, inset);
3328 // not quite sure if we want this...
3329 setCursorParUndo(bv_);
3332 beforeChange(bv_->text);
3333 if (!lout.empty()) {
3334 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3335 bv_->text->breakParagraph(bv_);
3336 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3338 if (bv_->text->cursor.par()->size()) {
3339 bv_->text->cursorLeft(bv_);
3341 bv_->text->breakParagraph(bv_);
3342 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 pair<bool, layout_type> lres =
3346 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3347 layout_type lay = 0;
3348 if (lres.first != false) {
3352 // layout not fount using default "Standard" (0)
3356 bv_->text->setLayout(bv_, lay);
3358 bv_->text->setParagraph(bv_, 0, 0,
3360 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3368 bv_->text->insertInset(bv_, inset);
3369 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3376 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3381 // first check for locking insets
3382 if (bv_->theLockingInset()) {
3383 if (bv_->theLockingInset() == inset) {
3384 if (bv_->text->updateInset(bv_, inset)) {
3387 buffer_->markDirty();
3392 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3393 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3396 buffer_->markDirty();
3404 // then check the current buffer
3407 update(bv_->text, BufferView::UPDATE);
3408 if (bv_->text->updateInset(bv_, inset)) {
3412 | BufferView::FITCUR
3413 | BufferView::CHANGE);
3415 update(bv_->text, SELECT);
3423 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3426 if (!available()) return;
3429 beforeChange(bv_->text);
3430 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3432 LyXCursor const & cursor = bv_->text->cursor;
3436 cursor.par()->isInset(cursor.pos())) {
3437 Inset const * inset = cursor.par()->getInset(cursor.pos());
3438 if (find(codes.begin(), codes.end(), inset->lyxCode())
3441 static_cast<InsetCommand const *>(inset)->getContents();
3445 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3446 if (bv_->text->cursor.pos()
3447 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3448 LyXCursor tmp = bv_->text->cursor;
3449 bv_->text->cursor.par(bv_->text->ownerParagraph());
3450 bv_->text->cursor.pos(0);
3451 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3452 bv_->text->cursor = tmp;
3453 bv_->owner()->message(_("No more insets"));
3456 bv_->owner()->message(_("No more insets"));
3459 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3460 bv_->text->selection.cursor = bv_->text->cursor;
3464 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3466 gotoInset(vector<Inset::Code>(1, code), same_content);