12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
22 #include "bufferview_funcs.h"
23 #include "TextCache.h"
24 #include "bufferlist.h"
25 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "support/lstrings.h"
30 #include "frontends/Dialogs.h"
31 #include "insets/insetbib.h"
32 #include "insets/insettext.h"
33 /// added for Dispatch functions
35 #include "frontends/FileDialog.h"
37 #include "FloatList.h"
38 #include "support/filetools.h"
39 #include "support/lyxfunctional.h"
40 #include "insets/inseturl.h"
41 #include "insets/insetlatexaccent.h"
42 #include "insets/insettoc.h"
43 #include "insets/insetref.h"
44 #include "insets/insetparent.h"
45 #include "insets/insetindex.h"
46 #include "insets/insetnote.h"
47 #include "insets/insetinclude.h"
48 #include "insets/insetcite.h"
49 #include "insets/insetert.h"
50 #include "insets/insetexternal.h"
51 #include "insets/insetgraphics.h"
52 #include "insets/insetfoot.h"
53 #include "insets/insetmarginal.h"
54 #include "insets/insetminipage.h"
55 #include "insets/insetfloat.h"
56 #include "insets/insettabular.h"
58 #include "insets/insettheorem.h"
59 #include "insets/insetlist.h"
61 #include "insets/insetcaption.h"
62 #include "insets/insetfloatlist.h"
63 #include "insets/insetspecialchar.h"
65 #include "ParagraphParameters.h"
66 #include "undo_funcs.h"
67 #include "mathed/formulabase.h"
69 extern LyXTextClass::size_type current_layout;
80 /* the selection possible is needed, that only motion events are
81 * used, where the bottom press event was on the drawing area too */
82 bool selection_possible = false;
84 extern BufferList bufferlist;
85 extern char ascii_type;
87 extern void sigchldchecker(pid_t pid, int * status);
88 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
93 const unsigned int saved_positions_num = 20;
98 XSync(fl_get_display(), 0);
102 void SetXtermCursor(Window win)
104 static Cursor cursor;
105 static bool cursor_undefined = true;
106 if (cursor_undefined){
107 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
108 XFlush(fl_get_display());
109 cursor_undefined = false;
111 XDefineCursor(fl_get_display(), win, cursor);
112 XFlush(fl_get_display());
118 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
119 int xpos, int ypos, int width, int height)
120 : bv_(b), owner_(o), buffer_(0),
121 current_scrollbar_value(0), cursor_timeout(400),
122 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
126 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
127 workarea_.workAreaExpose
128 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
129 workarea_.workAreaEnter
130 .connect(slot(this, &BufferView::Pimpl::enterView));
131 workarea_.workAreaLeave
132 .connect(slot(this, &BufferView::Pimpl::leaveView));
133 workarea_.workAreaButtonPress
134 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
135 workarea_.workAreaButtonRelease
137 &BufferView::Pimpl::workAreaButtonRelease));
138 workarea_.workAreaMotionNotify
139 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
140 workarea_.workAreaDoubleClick
141 .connect(slot(this, &BufferView::Pimpl::doubleClick));
142 workarea_.workAreaTripleClick
143 .connect(slot(this, &BufferView::Pimpl::tripleClick));
144 workarea_.workAreaKeyPress
145 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
147 cursor_timeout.timeout.connect(slot(this,
148 &BufferView::Pimpl::cursorToggle));
149 cursor_timeout.start();
150 workarea_.setFocus();
151 saved_positions.resize(saved_positions_num);
155 Painter & BufferView::Pimpl::painter()
157 return workarea_.getPainter();
161 void BufferView::Pimpl::buffer(Buffer * b)
163 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
167 buffer_->delUser(bv_);
169 // Put the old text into the TextCache, but
170 // only if the buffer is still loaded.
171 // Also set the owner of the test to 0
172 // bv_->text->owner(0);
173 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
174 if (lyxerr.debugging())
175 textcache.show(lyxerr, "BufferView::buffer");
180 // Set current buffer
183 if (bufferlist.getState() == BufferList::CLOSING) return;
186 // screen is always deleted when the buffer is changed.
189 // If we are closing the buffer, use the first buffer as current
191 buffer_ = bufferlist.first();
195 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
196 buffer_->addUser(bv_);
197 // If we don't have a text object for this, we make one
198 if (bv_->text == 0) {
199 resizeCurrentBuffer();
204 bv_->text->first = screen_->topCursorVisible(bv_->text);
205 owner_->updateMenubar();
206 owner_->updateToolbar();
207 // Similarly, buffer-dependent dialogs should be updated or
208 // hidden. This should go here because some dialogs (eg ToC)
209 // require bv_->text.
210 owner_->getDialogs()->updateBufferDependent(true);
215 lyxerr[Debug::INFO] << " No Buffer!" << endl;
216 owner_->updateMenubar();
217 owner_->updateToolbar();
218 owner_->getDialogs()->hideBufferDependent();
222 // Also remove all remaining text's from the testcache.
223 // (there should not be any!) (if there is any it is a
225 if (lyxerr.debugging())
226 textcache.show(lyxerr, "buffer delete all");
229 // should update layoutchoice even if we don't have a buffer.
230 owner_->updateLayoutChoice();
232 owner_->updateWindowTitle();
236 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
238 workarea_.resize(xpos, ypos, width, height);
239 update(bv_->text, SELECT);
244 void BufferView::Pimpl::resize()
247 resizeCurrentBuffer();
251 void BufferView::Pimpl::redraw()
253 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
258 bool BufferView::Pimpl::fitCursor()
260 lyx::Assert(screen_.get());
264 if (bv_->theLockingInset()) {
265 bv_->theLockingInset()->fitInsetCursor(bv_);
268 ret = screen_->fitCursor(bv_->text, bv_);
271 bv_->owner()->getDialogs()->updateParagraph();
278 void BufferView::Pimpl::redoCurrentBuffer()
280 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
281 if (buffer_ && bv_->text) {
283 owner_->updateLayoutChoice();
288 int BufferView::Pimpl::resizeCurrentBuffer()
290 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
293 Paragraph * selstartpar = 0;
294 Paragraph * selendpar = 0;
295 UpdatableInset * the_locking_inset = 0;
297 Paragraph::size_type pos = 0;
298 Paragraph::size_type selstartpos = 0;
299 Paragraph::size_type selendpos = 0;
300 bool selection = false;
301 bool mark_set = false;
303 owner_->prohibitInput();
305 owner_->message(_("Formatting document..."));
308 par = bv_->text->cursor.par();
309 pos = bv_->text->cursor.pos();
310 selstartpar = bv_->text->selection.start.par();
311 selstartpos = bv_->text->selection.start.pos();
312 selendpar = bv_->text->selection.end.par();
313 selendpos = bv_->text->selection.end.pos();
314 selection = bv_->text->selection.set();
315 mark_set = bv_->text->selection.mark();
316 the_locking_inset = bv_->theLockingInset();
318 bv_->text = new LyXText(bv_);
319 bv_->text->init(bv_);
321 // See if we have a text in TextCache that fits
322 // the new buffer_ with the correct width.
323 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
325 if (lyxerr.debugging()) {
326 lyxerr << "Found a LyXText that fits:\n";
327 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
329 // Set the owner of the newly found text
330 // bv_->text->owner(bv_);
331 if (lyxerr.debugging())
332 textcache.show(lyxerr, "resizeCurrentBuffer");
334 bv_->text = new LyXText(bv_);
335 bv_->text->init(bv_);
341 bv_->text->selection.set(true);
342 /* at this point just to avoid the Delete-Empty-Paragraph
343 * Mechanism when setting the cursor */
344 bv_->text->selection.mark(mark_set);
346 bv_->text->setCursor(bv_, selstartpar, selstartpos);
347 bv_->text->selection.cursor = bv_->text->cursor;
348 bv_->text->setCursor(bv_, selendpar, selendpos);
349 bv_->text->setSelection(bv_);
350 bv_->text->setCursor(bv_, par, pos);
352 bv_->text->setCursor(bv_, par, pos);
353 bv_->text->selection.cursor = bv_->text->cursor;
354 bv_->text->selection.set(false);
356 // remake the inset locking
357 bv_->theLockingInset(the_locking_inset);
359 bv_->text->first = screen_->topCursorVisible(bv_->text);
360 buffer_->resizeInsets(bv_);
361 // this will scroll the screen such that the cursor becomes visible
366 owner_->allowInput();
368 /// clear the "Formatting Document" message
375 void BufferView::Pimpl::updateScreen()
377 // Regenerate the screen.
378 screen_.reset(new LyXScreen(workarea_));
382 void BufferView::Pimpl::updateScrollbar()
384 /* If the text is smaller than the working area, the scrollbar
385 * maximum must be the working area height. No scrolling will
388 workarea_.setScrollbar(0, 1.0);
392 long const text_height = bv_->text->height;
394 double const lineh = bv_->text->defaultHeight();
395 double const slider_size =
396 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
398 static long old_text_height = 0;
399 static double old_lineh = 0;
400 static double old_slider_size = 0;
402 if (text_height != old_text_height) {
403 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
404 old_text_height = text_height;
406 if (lineh != old_lineh) {
407 workarea_.setScrollbarIncrements(lineh);
410 if (current_scrollbar_value != bv_->text->first
411 || slider_size != old_slider_size) {
412 current_scrollbar_value = bv_->text->first;
413 workarea_.setScrollbar(current_scrollbar_value, slider_size);
414 old_slider_size = slider_size;
419 // Callback for scrollbar slider
420 void BufferView::Pimpl::scrollCB(double value)
422 if (!buffer_) return;
424 current_scrollbar_value = long(value);
425 if (current_scrollbar_value < 0)
426 current_scrollbar_value = 0;
431 screen_->draw(bv_->text, bv_, current_scrollbar_value);
433 if (!lyxrc.cursor_follows_scrollbar) {
438 LyXText * vbt = bv_->text;
440 int const height = vbt->defaultHeight();
441 int const first = static_cast<int>((bv_->text->first + height));
442 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
444 if (vbt->cursor.y() < first)
445 vbt->setCursorFromCoordinates(bv_, 0, first);
446 else if (vbt->cursor.y() > last)
447 vbt->setCursorFromCoordinates(bv_, 0, last);
453 int BufferView::Pimpl::scrollUp(long time)
455 if (!buffer_) return 0;
456 if (!screen_.get()) return 0;
458 double value = workarea_.getScrollbarValue();
460 if (value == 0) return 0;
462 float add_value = (bv_->text->defaultHeight()
463 + float(time) * float(time) * 0.125);
465 if (add_value > workarea_.height())
466 add_value = float(workarea_.height() -
467 bv_->text->defaultHeight());
474 workarea_.setScrollbarValue(value);
481 int BufferView::Pimpl::scrollDown(long time)
483 if (!buffer_) return 0;
484 if (!screen_.get()) return 0;
486 double value = workarea_.getScrollbarValue();
487 pair<float, float> p = workarea_.getScrollbarBounds();
488 double const max = p.second;
490 if (value == max) return 0;
492 float add_value = (bv_->text->defaultHeight()
493 + float(time) * float(time) * 0.125);
495 if (add_value > workarea_.height())
496 add_value = float(workarea_.height() -
497 bv_->text->defaultHeight());
504 workarea_.setScrollbarValue(value);
511 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
513 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
517 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
519 // Only use motion with button 1
520 if (!(state & Button1MotionMask))
523 if (!buffer_ || !screen_.get()) return;
525 // Check for inset locking
526 if (bv_->theLockingInset()) {
527 LyXCursor cursor = bv_->text->cursor;
528 LyXFont font = bv_->text->getFont(buffer_,
529 cursor.par(), cursor.pos());
530 int width = bv_->theLockingInset()->width(bv_, font);
531 int inset_x = font.isVisibleRightToLeft()
532 ? cursor.x() - width : cursor.x();
533 int start_x = inset_x + bv_->theLockingInset()->scroll();
534 bv_->theLockingInset()->
535 insetMotionNotify(bv_,
537 y - cursor.y() + bv_->text->first,
542 /* The test for not selection possible is needed, that only motion
543 events are used, where the bottom press event was on
544 the drawing area too */
545 if (!selection_possible)
548 screen_->hideCursor();
550 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
552 if (!bv_->text->selection.set())
553 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
555 bv_->text->setSelection(bv_);
556 screen_->toggleToggle(bv_->text, bv_);
559 screen_->showCursor(bv_->text, bv_);
566 // Single-click on work area
567 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
570 if (!buffer_ || !screen_.get()) return;
572 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
574 // ok ok, this is a hack.
575 if (button == 4 || button == 5) {
578 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
581 scrollDown(lyxrc.wheel_jump);
586 if (bv_->theLockingInset()) {
587 // We are in inset locking mode
589 /* Check whether the inset was hit. If not reset mode,
590 otherwise give the event to the inset */
591 if (inset_hit == bv_->theLockingInset()) {
592 bv_->theLockingInset()->
593 insetButtonPress(bv_,
598 bv_->unlockInset(bv_->theLockingInset());
603 selection_possible = true;
604 screen_->hideCursor();
606 int const screen_first = bv_->text->first;
608 // Middle button press pastes if we have a selection
609 bool paste_internally = false;
611 && bv_->text->selection.set()) {
612 owner_->getLyXFunc()->dispatch(LFUN_COPY);
613 paste_internally = true;
616 // Clear the selection
617 screen_->toggleSelection(bv_->text, bv_);
618 bv_->text->clearSelection();
619 bv_->text->fullRebreak(bv_);
621 screen_->update(bv_->text, bv_);
627 // Single left click in math inset?
628 if ((inset_hit != 0) &&
629 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
630 // Highly editable inset, like math
631 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
632 selection_possible = false;
633 owner_->updateLayoutChoice();
634 owner_->message(inset->editMessage());
635 inset->insetButtonPress(bv_, xpos, ypos, button);
636 inset->edit(bv_, xpos, ypos, button);
640 // Right click on a footnote flag opens float menu
642 selection_possible = false;
646 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
647 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
649 bv_->text->selection.cursor = bv_->text->cursor;
650 bv_->text->cursor.x_fix(bv_->text->cursor.x());
652 owner_->updateLayoutChoice();
654 selection_possible = false;
657 // Insert primary selection with middle mouse
658 // if there is a local selection in the current buffer,
661 if (paste_internally)
662 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
664 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
666 selection_possible = false;
672 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
678 LyXText * text = bv_->getLyXText();
680 if (text->bv_owner && bv_->theLockingInset())
683 if (screen_.get() && button == 1) {
684 if (text->bv_owner) {
685 screen_->hideCursor();
686 screen_->toggleSelection(text, bv_);
687 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
688 screen_->toggleSelection(text, bv_, false);
690 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
692 /* This will fit the cursor on the screen
694 update(text, BufferView::SELECT|BufferView::FITCUR);
699 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
705 LyXText * text = bv_->getLyXText();
707 if (text->bv_owner && bv_->theLockingInset())
710 if (screen_.get() && (button == 1)) {
711 screen_->hideCursor();
712 screen_->toggleSelection(text, bv_);
713 text->cursorHome(bv_);
714 text->selection.cursor = text->cursor;
715 text->cursorEnd(bv_);
716 text->setSelection(bv_);
717 screen_->toggleSelection(text, bv_, false);
718 /* This will fit the cursor on the screen
720 update(text, BufferView::SELECT|BufferView::FITCUR);
725 void BufferView::Pimpl::enterView()
727 if (active() && available()) {
728 SetXtermCursor(workarea_.getWin());
729 using_xterm_cursor = true;
734 void BufferView::Pimpl::leaveView()
736 if (using_xterm_cursor) {
737 XUndefineCursor(fl_get_display(), workarea_.getWin());
738 using_xterm_cursor = false;
743 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
746 if (!buffer_ || !screen_.get()) return;
748 // If we hit an inset, we have the inset coordinates in these
749 // and inset_hit points to the inset. If we do not hit an
750 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
751 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
753 if (bv_->theLockingInset()) {
754 // We are in inset locking mode.
756 /* LyX does a kind of work-area grabbing for insets.
757 Only a ButtonPress Event outside the inset will
758 force a insetUnlock. */
759 bv_->theLockingInset()->
760 insetButtonRelease(bv_, x, y, button);
764 selection_possible = false;
772 // Did we hit an editable inset?
774 // Inset like error, notes and figures
775 selection_possible = false;
777 // CHECK fix this proper in 0.13
779 // Following a ref shouldn't issue
780 // a push on the undo-stack
781 // anylonger, now that we have
782 // keybindings for following
783 // references and returning from
784 // references. IMHO though, it
785 // should be the inset's own business
786 // to push or not push on the undo
787 // stack. They don't *have* to
788 // alter the document...
790 // ...or maybe the SetCursorParUndo()
791 // below isn't necessary at all anylonger?
792 if (inset_hit->lyxCode() == Inset::REF_CODE) {
793 setCursorParUndo(bv_);
796 owner_->message(inset_hit->editMessage());
798 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
799 // Highly editable inset, like math
800 UpdatableInset *inset = (UpdatableInset *)inset_hit;
801 inset->insetButtonRelease(bv_, x, y, button);
803 inset_hit->insetButtonRelease(bv_, x, y, button);
804 inset_hit->edit(bv_, x, y, button);
810 #warning variable c is set but never used. What is it good for?? (JMarc)
812 // check whether we want to open a float
816 if (bv_->text->cursor.pos() <
817 bv_->text->cursor.par()->size()) {
818 c = bv_->text->cursor.par()->
819 getChar(bv_->text->cursor.pos());
821 if (bv_->text->cursor.pos() - 1 >= 0) {
822 c = bv_->text->cursor.par()->
823 getChar(bv_->text->cursor.pos() - 1);
826 selection_possible = false;
831 // Maybe we want to edit a bibitem ale970302
832 if (bv_->text->cursor.par()->bibkey && x < 20 +
833 bibitemMaxWidth(bv_, textclasslist.
835 params.textclass).defaultfont())) {
836 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
844 * Returns an inset if inset was hit. 0 otherwise.
845 * If hit, the coordinates are changed relative to the inset.
846 * Otherwise coordinates are not changed, and false is returned.
848 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
849 unsigned int /* button */)
854 int y_tmp = y + text->first;
857 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
858 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
861 if (cursor.pos() < cursor.par()->size()
862 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
863 && cursor.par()->getInset(cursor.pos())
864 && cursor.par()->getInset(cursor.pos())->editable()) {
866 // Check whether the inset really was hit
867 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
868 LyXFont font = text->getFont(buffer_,
869 cursor.par(), cursor.pos());
870 int const width = tmpinset->width(bv_, font);
871 int const inset_x = font.isVisibleRightToLeft()
872 ? cursor.x() - width : cursor.x();
873 int const start_x = inset_x + tmpinset->scroll();
874 int const end_x = inset_x + width;
876 if (x > start_x && x < end_x
877 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
878 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
879 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
881 // The origin of an inset is on the baseline
882 y = y_tmp - (text->cursor.y());
887 if ((cursor.pos() - 1 >= 0) &&
888 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
889 (cursor.par()->getInset(cursor.pos() - 1)) &&
890 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
891 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
892 LyXFont font = text->getFont(buffer_, cursor.par(),
894 int const width = tmpinset->width(bv_, font);
895 int const inset_x = font.isVisibleRightToLeft()
896 ? cursor.x() : cursor.x() - width;
897 int const start_x = inset_x + tmpinset->scroll();
898 int const end_x = inset_x + width;
900 if (x > start_x && x < end_x
901 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
902 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
904 if (move_cursor && (tmpinset != bv_->theLockingInset()))
906 text->setCursor(bv_, cursor.par(),
907 cursor.pos() - 1, true);
909 // The origin of an inset is on the baseline
910 y = y_tmp - (text->cursor.y());
918 void BufferView::Pimpl::workAreaExpose()
920 static int work_area_width;
921 static unsigned int work_area_height;
923 bool const widthChange = workarea_.workWidth() != work_area_width;
924 bool const heightChange = workarea_.height() != work_area_height;
926 // update from work area
927 work_area_width = workarea_.workWidth();
928 work_area_height = workarea_.height();
931 // The visible LyXView need a resize
934 // Remove all texts from the textcache
935 // This is not _really_ what we want to do. What
936 // we really want to do is to delete in textcache
937 // that does not have a BufferView with matching
938 // width, but as long as we have only one BufferView
939 // deleting all gives the same result.
940 if (lyxerr.debugging())
941 textcache.show(lyxerr, "Expose delete all");
943 } else if (heightChange) {
944 // Rebuild image of current screen
946 // fitCursor() ensures we don't jump back
947 // to the start of the document on vertical
951 // The main window size has changed, repaint most stuff
953 } else if (screen_.get())
954 screen_->redraw(bv_->text, bv_);
956 // Grey box when we don't have a buffer
960 // always make sure that the scrollbar is sane.
962 owner_->updateLayoutChoice();
967 void BufferView::Pimpl::update()
970 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
972 LyXText::text_status st = bv_->text->status();
973 screen_->update(bv_->text, bv_);
975 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
976 if (bv_->text->fullRebreak(bv_)) {
977 st = LyXText::NEED_MORE_REFRESH;
978 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
979 bv_->text->cursor.pos());
982 bv_->text->status(bv_, st);
983 screen_->update(bv_->text, bv_);
985 // do this here instead of in the screen::update because of
987 bv_->text->status(bv_, LyXText::UNCHANGED);
993 // Values used when calling update:
995 // -2 - update, move sel_cursor if selection, fitcursor
996 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
997 // 0 - update, move sel_cursor if selection, fitcursor
998 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
999 // 3 - update, move sel_cursor if selection
1002 // a simple redraw of the parts that need refresh
1004 // move sel_cursor if selection -
1005 // the text's sel_cursor is moved if there is selection is progress
1008 // fitCursor() is called and the scrollbar updated
1011 // the buffer is marked dirty.
1020 // UPDATE_ONLY = UPDATE;
1021 // UPDATE_SELECT = UPDATE | SELECT;
1022 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1023 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1025 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1026 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1027 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1028 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1029 // update(3) -> update(1) -> update(1) -> update(SELECT)
1031 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1033 owner_->updateLayoutChoice();
1035 if (!text->selection.set() && (f & SELECT)) {
1036 text->selection.cursor = text->cursor;
1039 text->fullRebreak(bv_);
1041 if (text->inset_owner) {
1042 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1043 updateInset(text->inset_owner, true);
1053 buffer_->markDirty();
1058 // Callback for cursor timer
1059 void BufferView::Pimpl::cursorToggle()
1061 // Quite a nice place for asyncron Inset updating, isn't it?
1062 // Actually no! This is run even if no buffer exist... so (Lgb)
1064 cursor_timeout.restart();
1069 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1070 if (pid == -1) // error find out what is wrong
1071 ; // ignore it for now.
1073 sigchldchecker(pid, &status);
1075 updatelist.update(bv_);
1077 if (!screen_.get()) {
1078 cursor_timeout.restart();
1082 if (!bv_->theLockingInset()) {
1083 screen_->cursorToggle(bv_);
1085 bv_->theLockingInset()->toggleInsetCursor(bv_);
1088 cursor_timeout.restart();
1092 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1094 if (!text->cursor.row()->previous())
1097 int y = text->first;
1098 if (text->inset_owner)
1099 y += bv_->text->first;
1100 Row * cursorrow = text->cursor.row();
1101 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1103 // This is to allow jumping over large insets
1104 if ((cursorrow == text->cursor.row()))
1105 text->cursorUp(bv_);
1107 if (text->inset_owner ||
1108 text->cursor.row()->height() < workarea_.height())
1109 screen_->draw(bv_->text, bv_,
1111 - text->cursor.row()->baseline()
1112 + text->cursor.row()->height()
1113 - workarea_.height() + 1 );
1118 void BufferView::Pimpl::cursorNext(LyXText * text)
1120 if (!text->cursor.row()->next())
1123 int y = text->first + workarea_.height();
1124 // if (text->inset_owner)
1125 // y += bv_->text->first;
1126 text->getRowNearY(y);
1128 Row * cursorrow = text->cursor.row();
1129 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1131 // This is to allow jumping over large insets
1132 if ((cursorrow == bv_->text->cursor.row()))
1133 text->cursorDown(bv_);
1135 if (text->inset_owner ||
1136 text->cursor.row()->height() < workarea_.height())
1137 screen_->draw(bv_->text, bv_, text->cursor.y() -
1138 text->cursor.row()->baseline());
1143 bool BufferView::Pimpl::available() const
1145 if (buffer_ && bv_->text) return true;
1150 void BufferView::Pimpl::beforeChange(LyXText * text)
1153 text->clearSelection();
1157 void BufferView::Pimpl::savePosition(unsigned int i)
1159 if (i >= saved_positions_num)
1161 saved_positions[i] = Position(buffer_->fileName(),
1162 bv_->text->cursor.par()->id(),
1163 bv_->text->cursor.pos());
1166 str << _("Saved bookmark") << ' ' << i;
1167 owner_->message(str.str().c_str());
1172 void BufferView::Pimpl::restorePosition(unsigned int i)
1174 if (i >= saved_positions_num)
1177 string const fname = saved_positions[i].filename;
1179 beforeChange(bv_->text);
1181 if (fname != buffer_->fileName()) {
1182 Buffer * b = bufferlist.exists(fname) ?
1183 bufferlist.getBuffer(fname) :
1184 bufferlist.loadLyXFile(fname); // don't ask, just load it
1185 if (b != 0 ) buffer(b);
1188 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1192 bv_->text->setCursor(bv_, par,
1193 min(par->size(), saved_positions[i].par_pos));
1195 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1198 str << _("Moved to bookmark") << ' ' << i;
1199 owner_->message(str.str().c_str());
1204 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1206 if (i >= saved_positions_num)
1209 return !saved_positions[i].filename.empty();
1213 void BufferView::Pimpl::setState()
1215 if (!lyxrc.rtl_support)
1218 LyXText * text = bv_->getLyXText();
1219 if (text->real_current_font.isRightToLeft()) {
1220 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1221 owner_->getIntl()->KeyMapSec();
1223 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1224 owner_->getIntl()->KeyMapPrim();
1229 void BufferView::Pimpl::insetSleep()
1231 if (bv_->theLockingInset() && !inset_slept) {
1232 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1233 bv_->theLockingInset()->insetUnlock(bv_);
1239 void BufferView::Pimpl::insetWakeup()
1241 if (bv_->theLockingInset() && inset_slept) {
1242 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1243 inset_slept = false;
1248 void BufferView::Pimpl::insetUnlock()
1250 if (bv_->theLockingInset()) {
1252 bv_->theLockingInset()->insetUnlock(bv_);
1253 bv_->theLockingInset(0);
1255 inset_slept = false;
1260 bool BufferView::Pimpl::focus() const
1262 return workarea_.hasFocus();
1266 void BufferView::Pimpl::focus(bool f)
1268 if (f) workarea_.setFocus();
1272 bool BufferView::Pimpl::active() const
1274 return workarea_.active();
1278 bool BufferView::Pimpl::belowMouse() const
1280 return workarea_.belowMouse();
1284 void BufferView::Pimpl::showCursor()
1286 if (screen_.get()) {
1287 if (bv_->theLockingInset())
1288 bv_->theLockingInset()->showInsetCursor(bv_);
1290 screen_->showCursor(bv_->text, bv_);
1295 void BufferView::Pimpl::hideCursor()
1297 if (screen_.get()) {
1298 if (!bv_->theLockingInset())
1299 // bv_->theLockingInset()->hideInsetCursor(bv_);
1301 screen_->hideCursor();
1306 void BufferView::Pimpl::toggleSelection(bool b)
1308 if (screen_.get()) {
1309 if (bv_->theLockingInset())
1310 bv_->theLockingInset()->toggleSelection(bv_, b);
1311 screen_->toggleSelection(bv_->text, bv_, b);
1316 void BufferView::Pimpl::toggleToggle()
1319 screen_->toggleToggle(bv_->text, bv_);
1323 void BufferView::Pimpl::center()
1325 beforeChange(bv_->text);
1326 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1327 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1329 screen_->draw(bv_->text, bv_, 0);
1331 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1336 void BufferView::Pimpl::pasteClipboard(bool asPara)
1338 if (!buffer_) return;
1340 screen_->hideCursor();
1341 beforeChange(bv_->text);
1343 string const clip(workarea_.getClipboard());
1345 if (clip.empty()) return;
1348 bv_->text->insertStringAsParagraphs(bv_, clip);
1350 bv_->text->insertStringAsLines(bv_, clip);
1352 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1356 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1358 workarea_.putClipboard(stuff);
1363 * Dispatch functions for actions which can be valid for BufferView->text
1364 * and/or InsetText->text!!!
1369 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1371 LyXText * lt = bv_->getLyXText();
1373 if (selecting || lt->selection.mark()) {
1374 lt->setSelection(bv_);
1378 update(lt, BufferView::SELECT|BufferView::FITCUR);
1381 /* ---> Everytime the cursor is moved, show the current font state. */
1382 // should this too me moved out of this func?
1383 //owner->showState();
1388 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1390 LyXCursor cursor = bv_->getLyXText()->cursor;
1391 Buffer::inset_iterator it =
1392 find_if(Buffer::inset_iterator(
1393 cursor.par(), cursor.pos()),
1394 buffer_->inset_iterator_end(),
1395 lyx::compare_memfun(&Inset::lyxCode, code));
1396 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1400 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1402 string filename = filen;
1404 if (filename.empty()) {
1405 // Launch a file browser
1406 string initpath = lyxrc.document_path;
1409 string const trypath = owner_->buffer()->filepath;
1410 // If directory is writeable, use this as default.
1411 if (IsDirWriteable(trypath))
1415 FileDialog fileDlg(bv_->owner(),
1416 _("Select LyX document to insert"),
1418 make_pair(string(_("Documents")),
1419 string(lyxrc.document_path)),
1420 make_pair(string(_("Examples")),
1421 string(AddPath(system_lyxdir, "examples"))));
1423 FileDialog::Result result =
1424 fileDlg.Select(initpath,
1425 _("*.lyx| LyX Documents (*.lyx)"));
1427 if (result.first == FileDialog::Later)
1430 filename = result.second;
1432 // check selected filename
1433 if (filename.empty()) {
1434 owner_->message(_("Canceled."));
1439 // get absolute path of file and add ".lyx" to the filename if
1441 filename = FileSearch(string(), filename, "lyx");
1443 string const disp_fn(MakeDisplayPath(filename));
1446 s1 << _("Inserting document") << ' '
1447 << disp_fn << " ...";
1448 owner_->message(s1.str().c_str());
1449 bool const res = bv_->insertLyXFile(filename);
1452 str << _("Document") << ' ' << disp_fn
1453 << ' ' << _("inserted.");
1454 owner_->message(str.str().c_str());
1457 str << _("Could not insert document") << ' '
1459 owner_->message(str.str().c_str());
1464 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1466 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1467 << action <<"] arg[" << argument << "]" << endl;
1470 // --- Misc -------------------------------------------
1474 LyXText * lt = bv_->getLyXText();
1475 lt->toggleAppendix(bv_);
1478 | BufferView::FITCUR
1479 | BufferView::CHANGE);
1484 case LFUN_TOC_INSERT:
1486 InsetCommandParams p;
1487 p.setCmdName("tableofcontents");
1488 Inset * inset = new InsetTOC(p);
1489 if (!insertInset(inset, "Standard"))
1494 case LFUN_TABULAR_FEATURE:
1495 case LFUN_SCROLL_INSET:
1496 // this is not handled here as this funktion is only aktive
1497 // if we have a locking_inset and that one is (or contains)
1501 case LFUN_INSET_GRAPHICS:
1503 Inset * new_inset = new InsetGraphics;
1504 if (!insertInset(new_inset)) {
1507 // this is need because you don't use a inset->Edit()
1508 updateInset(new_inset, true);
1509 new_inset->edit(bv_);
1519 case LFUN_PASTESELECTION:
1521 bool asPara = false;
1522 if (argument == "paragraph") asPara = true;
1523 pasteClipboard(asPara);
1535 case LFUN_LAYOUT_COPY:
1536 bv_->copyEnvironment();
1539 case LFUN_LAYOUT_PASTE:
1540 bv_->pasteEnvironment();
1544 case LFUN_GOTOERROR:
1545 gotoInset(Inset::ERROR_CODE, false);
1549 gotoInset(Inset::IGNORE_CODE, false);
1552 case LFUN_REFERENCE_GOTO:
1554 vector<Inset::Code> tmp;
1555 tmp.push_back(Inset::LABEL_CODE);
1556 tmp.push_back(Inset::REF_CODE);
1557 gotoInset(tmp, true);
1561 case LFUN_HYPHENATION:
1562 specialChar(InsetSpecialChar::HYPHENATION);
1565 case LFUN_LIGATURE_BREAK:
1566 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1570 specialChar(InsetSpecialChar::LDOTS);
1573 case LFUN_END_OF_SENTENCE:
1574 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1577 case LFUN_MENU_SEPARATOR:
1578 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1586 changeDepth(bv_, bv_->getLyXText(), 0);
1589 case LFUN_DEPTH_MIN:
1590 changeDepth(bv_, bv_->getLyXText(), -1);
1593 case LFUN_DEPTH_PLUS:
1594 changeDepth(bv_, bv_->getLyXText(), 1);
1598 owner_->getDialogs()->setUserFreeFont();
1601 case LFUN_FILE_INSERT:
1603 MenuInsertLyXFile(argument);
1607 case LFUN_FILE_INSERT_ASCII_PARA:
1608 InsertAsciiFile(bv_, argument, true);
1611 case LFUN_FILE_INSERT_ASCII:
1612 InsertAsciiFile(bv_, argument, false);
1617 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1618 << argument << endl;
1620 // Derive layout number from given argument (string)
1621 // and current buffer's textclass (number). */
1622 LyXTextClassList::ClassList::size_type tclass =
1623 buffer_->params.textclass;
1624 pair <bool, LyXTextClass::size_type> layout =
1625 textclasslist.NumberOfLayout(tclass, argument);
1627 // If the entry is obsolete, use the new one instead.
1629 string obs = textclasslist.Style(tclass,layout.second)
1633 textclasslist.NumberOfLayout(tclass, obs);
1636 // see if we found the layout number:
1637 if (!layout.first) {
1638 owner_->getLyXFunc()->setErrorMessage(
1639 string(N_("Layout ")) + argument +
1644 if (current_layout != layout.second) {
1645 LyXText * lt = bv_->getLyXText();
1647 current_layout = layout.second;
1650 | BufferView::FITCUR);
1651 lt->setLayout(bv_, layout.second);
1652 owner_->setLayout(layout.second);
1655 | BufferView::FITCUR
1656 | BufferView::CHANGE);
1663 lang(bv_, argument);
1665 owner_->showState();
1670 owner_->showState();
1675 owner_->showState();
1680 owner_->showState();
1685 owner_->showState();
1690 owner_->showState();
1695 owner_->showState();
1700 owner_->showState();
1703 case LFUN_UNDERLINE:
1705 owner_->showState();
1708 case LFUN_FONT_SIZE:
1709 fontSize(bv_, argument);
1710 owner_->showState();
1713 case LFUN_FONT_STATE:
1714 owner_->getLyXFunc()->setMessage(currentState(bv_));
1717 case LFUN_UPCASE_WORD:
1719 LyXText * lt = bv_->getLyXText();
1723 | BufferView::FITCUR);
1724 lt->changeCase(bv_, LyXText::text_uppercase);
1725 if (lt->inset_owner)
1726 updateInset(lt->inset_owner, true);
1729 | BufferView::FITCUR
1730 | BufferView::CHANGE);
1734 case LFUN_LOWCASE_WORD:
1736 LyXText * lt = bv_->getLyXText();
1738 update(lt, BufferView::SELECT|BufferView::FITCUR);
1739 lt->changeCase(bv_, LyXText::text_lowercase);
1740 if (lt->inset_owner)
1741 updateInset(lt->inset_owner, true);
1744 | BufferView::FITCUR
1745 | BufferView::CHANGE);
1749 case LFUN_CAPITALIZE_WORD:
1751 LyXText * lt = bv_->getLyXText();
1753 update(lt, BufferView::SELECT|BufferView::FITCUR);
1754 lt->changeCase(bv_, LyXText::text_capitalization);
1755 if (lt->inset_owner)
1756 updateInset(lt->inset_owner, true);
1759 | BufferView::FITCUR
1760 | BufferView::CHANGE);
1764 case LFUN_TRANSPOSE_CHARS:
1766 LyXText * lt = bv_->getLyXText();
1768 update(lt, BufferView::SELECT|BufferView::FITCUR);
1769 lt->transposeChars(*bv_);
1770 if (lt->inset_owner)
1771 updateInset(lt->inset_owner, true);
1774 | BufferView::FITCUR
1775 | BufferView::CHANGE);
1780 case LFUN_INSERT_LABEL:
1781 MenuInsertLabel(bv_, argument);
1784 case LFUN_REF_INSERT:
1785 if (argument.empty()) {
1786 InsetCommandParams p("ref");
1787 owner_->getDialogs()->createRef(p.getAsString());
1789 InsetCommandParams p;
1790 p.setFromString(argument);
1792 InsetRef * inset = new InsetRef(p, *buffer_);
1793 if (!insertInset(inset))
1796 updateInset(inset, true);
1800 case LFUN_BOOKMARK_SAVE:
1801 savePosition(strToUnsignedInt(argument));
1804 case LFUN_BOOKMARK_GOTO:
1805 restorePosition(strToUnsignedInt(argument));
1810 string label(argument);
1811 if (label.empty()) {
1813 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1815 label = inset->getContents();
1820 if (!label.empty()) {
1821 //bv_->savePosition(0);
1822 if (!bv_->gotoLabel(label))
1823 WriteAlert(_("Error"),
1824 _("Couldn't find this label"),
1825 _("in current document."));
1830 // --- Cursor Movements -----------------------------
1833 LyXText * lt = bv_->getLyXText();
1835 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1836 if (!lt->selection.mark())
1838 update(lt, BufferView::SELECT|BufferView::FITCUR);
1840 lt->cursorLeft(bv_, false);
1841 if (lt->cursor.pos() < lt->cursor.par()->size()
1842 && lt->cursor.par()->getChar(lt->cursor.pos())
1843 == Paragraph::META_INSET
1844 && lt->cursor.par()->getInset(lt->cursor.pos())
1845 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1846 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1847 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1849 tmpinset->edit(bv_, false);
1851 tmpinset->edit(bv_);
1855 lt->cursorRight(bv_, false);
1857 moveCursorUpdate(false);
1858 owner_->showState();
1864 // This is soooo ugly. Isn`t it possible to make
1865 // it simpler? (Lgb)
1866 LyXText * lt = bv_->getLyXText();
1867 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1868 if (!lt->selection.mark())
1870 update(lt, BufferView::SELECT|BufferView::FITCUR);
1871 LyXCursor const cur = lt->cursor;
1873 lt->cursorLeft(bv_, false);
1874 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1875 lt->cursor.pos() < lt->cursor.par()->size() &&
1876 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1877 Paragraph::META_INSET) &&
1878 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1879 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1880 == Inset::HIGHLY_EDITABLE))
1882 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1883 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1885 tmpinset->edit(bv_);
1887 tmpinset->edit(bv_, false);
1891 lt->cursorRight(bv_, false);
1894 moveCursorUpdate(false);
1895 owner_->showState();
1901 LyXText * lt = bv_->getLyXText();
1903 if (!lt->selection.mark())
1905 update(lt, BufferView::UPDATE);
1908 moveCursorUpdate(false);
1909 owner_->showState();
1915 LyXText * lt = bv_->getLyXText();
1917 if (!lt->selection.mark())
1919 update(lt, BufferView::UPDATE);
1920 lt->cursorDown(bv_);
1922 moveCursorUpdate(false);
1923 owner_->showState();
1927 case LFUN_UP_PARAGRAPH:
1929 LyXText * lt = bv_->getLyXText();
1931 if (!lt->selection.mark())
1933 update(lt, BufferView::UPDATE);
1934 lt->cursorUpParagraph(bv_);
1936 moveCursorUpdate(false);
1937 owner_->showState();
1941 case LFUN_DOWN_PARAGRAPH:
1943 LyXText * lt = bv_->getLyXText();
1945 if (!lt->selection.mark())
1947 update(lt, BufferView::UPDATE);
1948 lt->cursorDownParagraph(bv_);
1950 moveCursorUpdate(false);
1951 owner_->showState();
1957 LyXText * lt = bv_->getLyXText();
1959 if (!lt->selection.mark())
1961 update(lt, BufferView::UPDATE);
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::SELECT|BufferView::FITCUR);
1990 lt->cursorHome(bv_);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1999 LyXText * lt = bv_->getLyXText();
2001 if (!lt->selection.mark())
2004 BufferView::SELECT|BufferView::FITCUR);
2007 moveCursorUpdate(false);
2008 owner_->showState();
2012 case LFUN_SHIFT_TAB:
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2020 BufferView::SELECT|BufferView::FITCUR);
2023 moveCursorUpdate(false);
2024 owner_->showState();
2028 case LFUN_WORDRIGHT:
2030 LyXText * lt = bv_->getLyXText();
2032 if (!lt->selection.mark())
2034 update(lt, BufferView::SELECT|BufferView::FITCUR);
2035 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2036 lt->cursorLeftOneWord(bv_);
2038 lt->cursorRightOneWord(bv_);
2040 moveCursorUpdate(false);
2041 owner_->showState();
2047 LyXText * lt = bv_->getLyXText();
2049 if (!lt->selection.mark())
2051 update(lt, BufferView::SELECT|BufferView::FITCUR);
2052 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2053 lt->cursorRightOneWord(bv_);
2055 lt->cursorLeftOneWord(bv_);
2057 moveCursorUpdate(false);
2058 owner_->showState();
2062 case LFUN_BEGINNINGBUF:
2064 LyXText * lt = bv_->getLyXText();
2066 if (!lt->selection.mark())
2069 BufferView::SELECT|BufferView::FITCUR);
2072 moveCursorUpdate(false);
2073 owner_->showState();
2079 LyXText * lt = bv_->getLyXText();
2081 if (!lt->selection.mark())
2084 BufferView::SELECT|BufferView::FITCUR);
2085 lt->cursorBottom(bv_);
2087 moveCursorUpdate(false);
2088 owner_->showState();
2092 /* cursor selection ---------------------------- */
2095 LyXText * lt = bv_->getLyXText();
2098 BufferView::SELECT|BufferView::FITCUR);
2099 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2100 lt->cursorLeft(bv_);
2102 lt->cursorRight(bv_);
2104 moveCursorUpdate(true);
2105 owner_->showState();
2111 LyXText * lt = bv_->getLyXText();
2114 BufferView::SELECT|BufferView::FITCUR);
2115 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2116 lt->cursorRight(bv_);
2118 lt->cursorLeft(bv_);
2120 moveCursorUpdate(true);
2121 owner_->showState();
2127 LyXText * lt = bv_->getLyXText();
2130 BufferView::SELECT|BufferView::FITCUR);
2133 moveCursorUpdate(true);
2134 owner_->showState();
2140 LyXText * lt = bv_->getLyXText();
2143 BufferView::SELECT|BufferView::FITCUR);
2144 lt->cursorDown(bv_);
2146 moveCursorUpdate(true);
2147 owner_->showState();
2151 case LFUN_UP_PARAGRAPHSEL:
2153 LyXText * lt = bv_->getLyXText();
2156 BufferView::SELECT|BufferView::FITCUR);
2157 lt->cursorUpParagraph(bv_);
2159 moveCursorUpdate(true);
2160 owner_->showState();
2164 case LFUN_DOWN_PARAGRAPHSEL:
2166 LyXText * lt = bv_->getLyXText();
2169 BufferView::SELECT|BufferView::FITCUR);
2170 lt->cursorDownParagraph(bv_);
2172 moveCursorUpdate(true);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2181 update(lt, BufferView::SELECT|BufferView::FITCUR);
2184 moveCursorUpdate(true);
2185 owner_->showState();
2191 LyXText * lt = bv_->getLyXText();
2193 update(lt, BufferView::SELECT|BufferView::FITCUR);
2196 moveCursorUpdate(true);
2197 owner_->showState();
2203 LyXText * lt = bv_->getLyXText();
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2206 lt->cursorHome(bv_);
2208 moveCursorUpdate(true);
2209 owner_->showState();
2215 LyXText * lt = bv_->getLyXText();
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2225 case LFUN_WORDRIGHTSEL:
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2230 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2231 lt->cursorLeftOneWord(bv_);
2233 lt->cursorRightOneWord(bv_);
2235 moveCursorUpdate(true);
2236 owner_->showState();
2240 case LFUN_WORDLEFTSEL:
2242 LyXText * lt = bv_->getLyXText();
2244 update(lt, BufferView::SELECT|BufferView::FITCUR);
2245 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2246 lt->cursorRightOneWord(bv_);
2248 lt->cursorLeftOneWord(bv_);
2250 moveCursorUpdate(true);
2251 owner_->showState();
2255 case LFUN_BEGINNINGBUFSEL:
2257 LyXText * lt = bv_->getLyXText();
2259 if (lt->inset_owner)
2261 update(lt, BufferView::SELECT|BufferView::FITCUR);
2264 moveCursorUpdate(true);
2265 owner_->showState();
2269 case LFUN_ENDBUFSEL:
2271 LyXText * lt = bv_->getLyXText();
2273 if (lt->inset_owner)
2276 BufferView::SELECT|BufferView::FITCUR);
2277 lt->cursorBottom(bv_);
2279 moveCursorUpdate(true);
2280 owner_->showState();
2284 // --- text changing commands ------------------------
2285 case LFUN_BREAKLINE:
2287 LyXText * lt = bv_->getLyXText();
2290 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2293 | BufferView::FITCUR
2294 | BufferView::CHANGE);
2295 moveCursorUpdate(false);
2299 case LFUN_PROTECTEDSPACE:
2301 LyXText * lt = bv_->getLyXText();
2303 LyXLayout const & style = textclasslist
2304 .Style(buffer_->params.textclass,
2305 lt->cursor.par()->getLayout());
2307 if (style.free_spacing) {
2308 lt->insertChar(bv_, ' ');
2311 | BufferView::FITCUR
2312 | BufferView::CHANGE);
2316 moveCursorUpdate(false);
2322 LyXText * lt = bv_->getLyXText();
2324 if (lt->selection.mark()) {
2328 | BufferView::FITCUR);
2329 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2332 lt->selection.mark(true);
2335 | BufferView::FITCUR);
2336 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2338 lt->selection.cursor = lt->cursor;
2344 LyXText * lt = bv_->getLyXText();
2346 if (!lt->selection.set()) {
2348 lt->selection.cursor = lt->cursor;
2351 | BufferView::FITCUR
2352 | BufferView::CHANGE);
2353 // It is possible to make it a lot faster still
2354 // just comment out the line below...
2359 moveCursorUpdate(false);
2360 owner_->showState();
2365 case LFUN_DELETE_SKIP:
2367 LyXText * lt = bv_->getLyXText();
2369 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2371 LyXCursor cursor = lt->cursor;
2373 if (!lt->selection.set()) {
2374 if (cursor.pos() == cursor.par()->size()) {
2375 lt->cursorRight(bv_);
2376 cursor = lt->cursor;
2377 if (cursor.pos() == 0
2378 && !(cursor.par()->params().spaceTop()
2379 == VSpace (VSpace::NONE))) {
2382 cursor.par()->params().lineTop(),
2383 cursor.par()->params().lineBottom(),
2384 cursor.par()->params().pagebreakTop(),
2385 cursor.par()->params().pagebreakBottom(),
2386 VSpace(VSpace::NONE),
2387 cursor.par()->params().spaceBottom(),
2388 cursor.par()->params().spacing(),
2389 cursor.par()->params().align(),
2390 cursor.par()->params().labelWidthString(), 0);
2391 lt->cursorLeft(bv_);
2394 | BufferView::FITCUR
2395 | BufferView::CHANGE);
2397 lt->cursorLeft(bv_);
2399 lt->selection.cursor = lt->cursor;
2402 | BufferView::FITCUR
2403 | BufferView::CHANGE);
2407 lt->selection.cursor = lt->cursor;
2410 | BufferView::FITCUR
2411 | BufferView::CHANGE);
2419 /* -------> Delete word forward. */
2420 case LFUN_DELETE_WORD_FORWARD:
2421 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2422 bv_->getLyXText()->deleteWordForward(bv_);
2423 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2424 moveCursorUpdate(false);
2425 owner_->showState();
2428 /* -------> Delete word backward. */
2429 case LFUN_DELETE_WORD_BACKWARD:
2431 LyXText * lt = bv_->getLyXText();
2433 update(lt, BufferView::SELECT|BufferView::FITCUR);
2434 lt->deleteWordBackward(bv_);
2437 | BufferView::FITCUR
2438 | BufferView::CHANGE);
2439 moveCursorUpdate(false);
2440 owner_->showState();
2444 /* -------> Kill to end of line. */
2445 case LFUN_DELETE_LINE_FORWARD:
2447 LyXText * lt = bv_->getLyXText();
2449 update(lt, BufferView::SELECT|BufferView::FITCUR);
2450 lt->deleteLineForward(bv_);
2453 | BufferView::FITCUR
2454 | BufferView::CHANGE);
2455 moveCursorUpdate(false);
2459 /* -------> Set mark off. */
2462 LyXText * lt = bv_->getLyXText();
2465 update(lt, BufferView::SELECT|BufferView::FITCUR);
2466 lt->selection.cursor = lt->cursor;
2467 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2471 /* -------> Set mark on. */
2474 LyXText * lt = bv_->getLyXText();
2477 lt->selection.mark(true);
2478 update(lt, BufferView::SELECT|BufferView::FITCUR);
2479 lt->selection.cursor = lt->cursor;
2480 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2484 case LFUN_BACKSPACE:
2486 LyXText * lt = bv_->getLyXText();
2488 if (!lt->selection.set()) {
2489 if (owner_->getIntl()->getTrans().backspace()) {
2491 lt->selection.cursor = lt->cursor;
2494 | BufferView::FITCUR
2495 | BufferView::CHANGE);
2496 // It is possible to make it a lot faster still
2497 // just comment out the line below...
2503 owner_->showState();
2508 case LFUN_BACKSPACE_SKIP:
2510 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2511 LyXText * lt = bv_->getLyXText();
2513 LyXCursor cursor = lt->cursor;
2515 if (!lt->selection.set()) {
2516 if (cursor.pos() == 0
2517 && !(cursor.par()->params().spaceTop()
2518 == VSpace (VSpace::NONE))) {
2521 cursor.par()->params().lineTop(),
2522 cursor.par()->params().lineBottom(),
2523 cursor.par()->params().pagebreakTop(),
2524 cursor.par()->params().pagebreakBottom(),
2525 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2526 cursor.par()->params().spacing(),
2527 cursor.par()->params().align(),
2528 cursor.par()->params().labelWidthString(), 0);
2531 | BufferView::FITCUR
2532 | BufferView::CHANGE);
2535 lt->selection.cursor = cursor;
2538 | BufferView::FITCUR
2539 | BufferView::CHANGE);
2546 case LFUN_BREAKPARAGRAPH:
2548 LyXText * lt = bv_->getLyXText();
2551 lt->breakParagraph(bv_, 0);
2554 | BufferView::FITCUR
2555 | BufferView::CHANGE);
2556 lt->selection.cursor = lt->cursor;
2558 owner_->showState();
2562 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2564 LyXText * lt = bv_->getLyXText();
2567 lt->breakParagraph(bv_, 1);
2570 | BufferView::FITCUR
2571 | BufferView::CHANGE);
2572 lt->selection.cursor = lt->cursor;
2574 owner_->showState();
2578 case LFUN_BREAKPARAGRAPH_SKIP:
2580 // When at the beginning of a paragraph, remove
2581 // indentation and add a "defskip" at the top.
2582 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2583 LyXText * lt = bv_->getLyXText();
2585 LyXCursor cursor = lt->cursor;
2588 if (cursor.pos() == 0) {
2589 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2592 cursor.par()->params().lineTop(),
2593 cursor.par()->params().lineBottom(),
2594 cursor.par()->params().pagebreakTop(),
2595 cursor.par()->params().pagebreakBottom(),
2596 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2597 cursor.par()->params().spacing(),
2598 cursor.par()->params().align(),
2599 cursor.par()->params().labelWidthString(), 1);
2600 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2604 lt->breakParagraph(bv_, 0);
2605 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2610 | BufferView::FITCUR
2611 | BufferView::CHANGE);
2612 lt->selection.cursor = cursor;
2614 owner_->showState();
2618 case LFUN_PARAGRAPH_SPACING:
2620 LyXText * lt = bv_->getLyXText();
2622 Paragraph * par = lt->cursor.par();
2623 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2624 float cur_value = 1.0;
2625 if (cur_spacing == Spacing::Other) {
2626 cur_value = par->params().spacing().getValue();
2629 istringstream istr(argument.c_str());
2633 Spacing::Space new_spacing = cur_spacing;
2634 float new_value = cur_value;
2636 lyxerr << "Missing argument to `paragraph-spacing'"
2638 } else if (tmp == "single") {
2639 new_spacing = Spacing::Single;
2640 } else if (tmp == "onehalf") {
2641 new_spacing = Spacing::Onehalf;
2642 } else if (tmp == "double") {
2643 new_spacing = Spacing::Double;
2644 } else if (tmp == "other") {
2645 new_spacing = Spacing::Other;
2648 lyxerr << "new_value = " << tmpval << endl;
2651 } else if (tmp == "default") {
2652 new_spacing = Spacing::Default;
2654 lyxerr << _("Unknown spacing argument: ")
2655 << argument << endl;
2657 if (cur_spacing != new_spacing || cur_value != new_value) {
2658 par->params().spacing(Spacing(new_spacing, new_value));
2659 lt->redoParagraph(bv_);
2662 | BufferView::FITCUR
2663 | BufferView::CHANGE);
2668 case LFUN_INSET_TOGGLE:
2670 LyXText * lt = bv_->getLyXText();
2673 update(lt, BufferView::SELECT|BufferView::FITCUR);
2674 lt->toggleInset(bv_);
2675 update(lt, BufferView::SELECT|BufferView::FITCUR);
2687 InsetCommandParams p;
2688 if (action == LFUN_HTMLURL)
2689 p.setCmdName("htmlurl");
2691 p.setCmdName("url");
2692 owner_->getDialogs()->createUrl(p.getAsString());
2696 case LFUN_INSERT_URL:
2698 InsetCommandParams p;
2699 p.setFromString(argument);
2701 InsetUrl * inset = new InsetUrl(p);
2702 if (!insertInset(inset))
2705 updateInset(inset, true);
2709 case LFUN_INSET_TEXT:
2710 insertAndEditInset(new InsetText);
2713 case LFUN_INSET_ERT:
2714 insertAndEditInset(new InsetERT);
2717 case LFUN_INSET_EXTERNAL:
2718 insertAndEditInset(new InsetExternal);
2721 case LFUN_INSET_FOOTNOTE:
2722 insertAndEditInset(new InsetFoot);
2725 case LFUN_INSET_MARGINAL:
2726 insertAndEditInset(new InsetMarginal);
2729 case LFUN_INSET_MINIPAGE:
2730 insertAndEditInset(new InsetMinipage);
2733 case LFUN_INSERT_NOTE:
2734 insertAndEditInset(new InsetNote);
2737 case LFUN_INSET_FLOAT:
2738 // check if the float type exist
2739 if (floatList.typeExist(argument)) {
2740 insertAndEditInset(new InsetFloat(argument));
2742 lyxerr << "Non-existent float type: "
2743 << argument << endl;
2747 case LFUN_INSET_WIDE_FLOAT:
2749 // check if the float type exist
2750 if (floatList.typeExist(argument)) {
2751 InsetFloat * new_inset = new InsetFloat(argument);
2752 new_inset->wide(true);
2753 if (insertInset(new_inset))
2754 new_inset->edit(bv_);
2758 lyxerr << "Non-existent float type: "
2759 << argument << endl;
2766 case LFUN_INSET_LIST:
2767 insertAndEditInset(new InsetList);
2770 case LFUN_INSET_THEOREM:
2771 insertAndEditInset(new InsetTheorem);
2775 case LFUN_INSET_CAPTION:
2777 // Do we have a locking inset...
2778 if (bv_->theLockingInset()) {
2779 lyxerr << "Locking inset code: "
2780 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2781 InsetCaption * new_inset = new InsetCaption;
2782 new_inset->setOwner(bv_->theLockingInset());
2783 new_inset->setAutoBreakRows(true);
2784 new_inset->setDrawFrame(0, InsetText::LOCKED);
2785 new_inset->setFrameColor(0, LColor::captionframe);
2786 if (insertInset(new_inset))
2787 new_inset->edit(bv_);
2794 case LFUN_INSET_TABULAR:
2798 if (!argument.empty())
2799 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2800 InsetTabular * new_inset =
2801 new InsetTabular(*buffer_, r, c);
2803 bv_->getLyXText()->real_current_font.isRightToLeft();
2804 if (!open_new_inset(new_inset, rtl))
2809 // --- lyxserver commands ----------------------------
2811 case LFUN_CHARATCURSOR:
2813 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2814 if (pos < bv_->getLyXText()->cursor.par()->size())
2815 owner_->getLyXFunc()->setMessage(
2816 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2818 owner_->getLyXFunc()->setMessage("EOF");
2823 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2825 + tostr(bv_->getLyXText()->cursor.y()));
2832 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2833 lyxerr << "SETXY: Could not parse coordinates in '"
2834 << argument << std::endl;
2836 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2840 case LFUN_GETLAYOUT:
2841 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2846 LyXFont & font = bv_->getLyXText()->current_font;
2847 if (font.shape() == LyXFont::ITALIC_SHAPE)
2848 owner_->getLyXFunc()->setMessage("E");
2849 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2850 owner_->getLyXFunc()->setMessage("N");
2852 owner_->getLyXFunc()->setMessage("0");
2857 // --- accented characters ---------------------------
2860 case LFUN_CIRCUMFLEX:
2870 case LFUN_SPECIAL_CARON:
2873 case LFUN_HUNG_UMLAUT:
2876 if (argument.empty()) {
2878 owner_->getLyXFunc()->handleKeyFunc(action);
2880 owner_->getLyXFunc()->handleKeyFunc(action);
2881 owner_->getIntl()->getTrans()
2882 .TranslateAndInsert(argument[0], bv_->getLyXText());
2883 update(bv_->getLyXText(),
2885 | BufferView::FITCUR
2886 | BufferView::CHANGE);
2890 case LFUN_MATH_MACRO:
2891 mathDispatchMathMacro(bv_, argument);
2894 case LFUN_MATH_DELIM:
2895 mathDispatchMathDelim(bv_, argument);
2898 case LFUN_INSERT_MATRIX:
2899 mathDispatchInsertMatrix(bv_, argument);
2902 case LFUN_INSERT_MATH:
2903 mathDispatchInsertMath(bv_, argument);
2906 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2907 mathDispatchMathImportSelection(bv_, argument);
2910 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2911 mathDispatchMathDisplay(bv_, argument);
2914 case LFUN_MATH_MODE: // Open or create an inlined math inset
2915 mathDispatchMathMode(bv_, argument);
2918 case LFUN_CITATION_INSERT:
2920 InsetCommandParams p;
2921 p.setFromString( argument );
2923 InsetCitation * inset = new InsetCitation( p );
2924 if (!insertInset(inset))
2927 updateInset( inset, true );
2931 case LFUN_INSERT_BIBTEX:
2933 // ale970405+lasgoutt970425
2934 // The argument can be up to two tokens separated
2935 // by a space. The first one is the bibstyle.
2936 string const db = token(argument, ' ', 0);
2937 string const bibstyle = token(argument, ' ', 1);
2939 InsetCommandParams p( "BibTeX", db, bibstyle );
2940 InsetBibtex * inset = new InsetBibtex(p);
2942 if (insertInset(inset)) {
2943 if (argument.empty())
2950 // BibTeX data bases
2951 case LFUN_BIBDB_ADD:
2953 InsetBibtex * inset =
2954 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2956 inset->addDatabase(argument);
2961 case LFUN_BIBDB_DEL:
2963 InsetBibtex * inset =
2964 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2966 inset->delDatabase(argument);
2971 case LFUN_BIBTEX_STYLE:
2973 InsetBibtex * inset =
2974 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2976 inset->setOptions(argument);
2981 case LFUN_INDEX_CREATE:
2983 InsetCommandParams p("index");
2984 if (argument.empty()) {
2985 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2986 p.setContents(idxstring);
2988 p.setContents(argument);
2991 owner_->getDialogs()->createIndex(p.getAsString());
2995 case LFUN_INDEX_INSERT:
2997 InsetCommandParams p;
2998 p.setFromString(argument);
2999 InsetIndex * inset = new InsetIndex(p);
3001 if (!insertInset(inset))
3004 updateInset(inset, true);
3008 case LFUN_INDEX_INSERT_LAST:
3010 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3011 if (!idxstring.empty()) {
3012 owner_->message(_("Word `")
3013 + idxstring + _(("' indexed.")));
3014 InsetCommandParams p("index", idxstring);
3015 InsetIndex * inset = new InsetIndex(p);
3017 if (!insertInset(inset))
3020 updateInset(inset, true);
3025 case LFUN_INDEX_PRINT:
3027 InsetCommandParams p("printindex");
3028 Inset * inset = new InsetPrintIndex(p);
3029 if (!insertInset(inset, "Standard"))
3034 case LFUN_PARENTINSERT:
3036 lyxerr << "arg " << argument << endl;
3037 InsetCommandParams p( "lyxparent", argument );
3038 Inset * inset = new InsetParent(p, *buffer_);
3039 if (!insertInset(inset, "Standard"))
3045 case LFUN_CHILD_INSERT:
3047 InsetInclude::Params p;
3048 p.cparams.setFromString(argument);
3049 p.masterFilename_ = buffer_->fileName();
3051 InsetInclude * inset = new InsetInclude(p);
3052 if (!insertInset(inset))
3055 updateInset(inset, true);
3056 bv_->owner()->getDialogs()->showInclude(inset);
3061 case LFUN_FLOAT_LIST:
3063 // We should check the argument for validity. (Lgb)
3064 Inset * inset = new InsetFloatList(argument);
3065 if (!insertInset(inset, "Standard"))
3070 case LFUN_THESAURUS_ENTRY:
3072 string arg = argument;
3075 arg = bv_->getLyXText()->selectionAsString(buffer_,
3079 if (arg.size() > 100 || arg.empty()) {
3080 // Get word or selection
3081 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3082 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3083 // FIXME: where is getLyXText()->unselect(bv_) ?
3087 bv_->owner()->getDialogs()->showThesaurus(arg);
3091 case LFUN_SELFINSERT:
3093 if (argument.empty()) break;
3095 /* Automatically delete the currently selected
3096 * text and replace it with what is being
3097 * typed in now. Depends on lyxrc settings
3098 * "auto_region_delete", which defaults to
3101 LyXText * lt = bv_->getLyXText();
3103 if (lyxrc.auto_region_delete) {
3104 if (lt->selection.set()) {
3105 lt->cutSelection(bv_, false, false);
3108 | BufferView::FITCUR
3109 | BufferView::CHANGE);
3114 LyXFont const old_font(lt->real_current_font);
3116 string::const_iterator cit = argument.begin();
3117 string::const_iterator end = argument.end();
3118 for (; cit != end; ++cit) {
3119 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3124 | BufferView::FITCUR
3125 | BufferView::CHANGE);
3127 lt->selection.cursor = lt->cursor;
3128 moveCursorUpdate(false);
3130 // real_current_font.number can change so we need to
3131 // update the minibuffer
3132 if (old_font != lt->real_current_font)
3133 owner_->showState();
3138 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3140 time_t now_time_t = time(NULL);
3141 struct tm * now_tm = localtime(&now_time_t);
3142 setlocale(LC_TIME, "");
3144 if (!argument.empty())
3147 arg = lyxrc.date_insert_format;
3149 int const datetmp_len =
3150 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3152 LyXText * lt = bv_->getLyXText();
3154 for (int i = 0; i < datetmp_len; i++) {
3155 lt->insertChar(bv_, datetmp[i]);
3158 | BufferView::FITCUR
3159 | BufferView::CHANGE);
3162 lt->selection.cursor = lt->cursor;
3163 moveCursorUpdate(false);
3167 case LFUN_UNKNOWN_ACTION:
3168 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3179 void BufferView::Pimpl::newline()
3182 LyXText * lt = bv_->getLyXText();
3186 | BufferView::FITCUR);
3187 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3190 | BufferView::FITCUR
3191 | BufferView::CHANGE);
3196 void BufferView::Pimpl::hfill()
3199 LyXText * lt = bv_->getLyXText();
3203 | BufferView::FITCUR);
3204 lt->insertChar(bv_, Paragraph::META_HFILL);
3207 | BufferView::FITCUR
3208 | BufferView::CHANGE);
3213 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3217 update(lt, BufferView::SELECT|BufferView::FITCUR);
3218 InsetSpecialChar * new_inset =
3219 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3220 #ifdef WITH_WARNINGS
3221 #warning Why is this code different from specialChar() below? (JMarc)
3222 // the code in specialChar is a generic version of what used to exist
3223 // for other special chars. I did not merge this case because of the
3224 // call to updateInset(), but what does it do?
3226 if (!insertInset(new_inset))
3229 updateInset(new_inset, true);
3234 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3237 LyXText * lt = bv_->getLyXText();
3240 update(lt, BufferView::SELECT|BufferView::FITCUR);
3241 InsetSpecialChar * new_inset =
3242 new InsetSpecialChar(kind);
3243 insertInset(new_inset);
3244 // Ok, what happens here if we are unable to insert
3245 // the inset? Leak it?
3250 void BufferView::Pimpl::smartQuote()
3253 LyXText * lt = bv_->getLyXText();
3255 if (lt->cursor.pos())
3256 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3262 LyXLayout const & style = textclasslist.Style(
3263 bv_->buffer()->params.textclass,
3264 lt->cursor.par()->getLayout());
3266 if (style.pass_thru ||
3267 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3268 Dispatch(LFUN_SELFINSERT, "\"");
3272 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3274 if (insertInset(inset))
3281 // Open and lock an updatable inset
3282 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3284 LyXText * lt = bv_->getLyXText();
3288 if (!insertInset(new_inset)) {
3292 new_inset->edit(bv_, !behind);
3297 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3299 // if we are in a locking inset we should try to insert the
3300 // inset there otherwise this is a illegal function now
3301 if (bv_->theLockingInset()) {
3302 if (bv_->theLockingInset()->insetAllowed(inset))
3303 return bv_->theLockingInset()->insertInset(bv_, inset);
3307 // not quite sure if we want this...
3308 setCursorParUndo(bv_);
3311 beforeChange(bv_->text);
3312 if (!lout.empty()) {
3313 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3314 bv_->text->breakParagraph(bv_);
3315 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3317 if (bv_->text->cursor.par()->size()) {
3318 bv_->text->cursorLeft(bv_);
3320 bv_->text->breakParagraph(bv_);
3321 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3324 pair<bool, LyXTextClass::size_type> lres =
3325 textclasslist.NumberOfLayout(buffer_->params
3327 LyXTextClass::size_type lay;
3328 if (lres.first != false) {
3332 // layout not fount using default "Standard" (0)
3336 bv_->text->setLayout(bv_, lay);
3338 bv_->text->setParagraph(bv_, 0, 0,
3340 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3345 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3348 bv_->text->insertInset(bv_, inset);
3349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3356 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3361 // first check for locking insets
3362 if (bv_->theLockingInset()) {
3363 if (bv_->theLockingInset() == inset) {
3364 if (bv_->text->updateInset(bv_, inset)) {
3367 buffer_->markDirty();
3372 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3373 if (bv_->text->updateInset(bv_,
3374 bv_->theLockingInset())) {
3377 buffer_->markDirty();
3385 // then check the current buffer
3388 update(bv_->text, BufferView::UPDATE);
3389 if (bv_->text->updateInset(bv_, inset)) {
3393 | BufferView::FITCUR
3394 | BufferView::CHANGE);
3396 update(bv_->text, SELECT);
3404 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3407 if (!available()) return;
3410 beforeChange(bv_->text);
3411 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3415 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3416 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3417 if (find(codes.begin(), codes.end(), inset->lyxCode())
3420 static_cast<InsetCommand const *>(inset)->getContents();
3423 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3424 if (bv_->text->cursor.pos()
3425 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3426 LyXCursor tmp = bv_->text->cursor;
3427 bv_->text->cursor.par(bv_->text->firstParagraph());
3428 bv_->text->cursor.pos(0);
3429 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3430 bv_->text->cursor = tmp;
3431 bv_->owner()->message(_("No more insets"));
3434 bv_->owner()->message(_("No more insets"));
3437 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3438 bv_->text->selection.cursor = bv_->text->cursor;
3442 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3444 gotoInset(vector<Inset::Code>(1, code), same_content);