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);
809 // check whether we want to open a float
813 if (bv_->text->cursor.pos() <
814 bv_->text->cursor.par()->size()) {
815 c = bv_->text->cursor.par()->
816 getChar(bv_->text->cursor.pos());
818 if (bv_->text->cursor.pos() - 1 >= 0) {
819 c = bv_->text->cursor.par()->
820 getChar(bv_->text->cursor.pos() - 1);
823 selection_possible = false;
828 // Maybe we want to edit a bibitem ale970302
829 if (bv_->text->cursor.par()->bibkey && x < 20 +
830 bibitemMaxWidth(bv_, textclasslist.
832 params.textclass).defaultfont())) {
833 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
841 * Returns an inset if inset was hit. 0 otherwise.
842 * If hit, the coordinates are changed relative to the inset.
843 * Otherwise coordinates are not changed, and false is returned.
845 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
846 unsigned int /* button */)
851 int y_tmp = y + text->first;
854 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
855 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
858 if (cursor.pos() < cursor.par()->size()
859 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
860 && cursor.par()->getInset(cursor.pos())
861 && cursor.par()->getInset(cursor.pos())->editable()) {
863 // Check whether the inset really was hit
864 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
865 LyXFont font = text->getFont(buffer_,
866 cursor.par(), cursor.pos());
867 int const width = tmpinset->width(bv_, font);
868 int const inset_x = font.isVisibleRightToLeft()
869 ? cursor.x() - width : cursor.x();
870 int const start_x = inset_x + tmpinset->scroll();
871 int const end_x = inset_x + width;
873 if (x > start_x && x < end_x
874 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
875 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
876 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
878 // The origin of an inset is on the baseline
879 y = y_tmp - (text->cursor.y());
884 if ((cursor.pos() - 1 >= 0) &&
885 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
886 (cursor.par()->getInset(cursor.pos() - 1)) &&
887 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
888 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
889 LyXFont font = text->getFont(buffer_, cursor.par(),
891 int const width = tmpinset->width(bv_, font);
892 int const inset_x = font.isVisibleRightToLeft()
893 ? cursor.x() : cursor.x() - width;
894 int const start_x = inset_x + tmpinset->scroll();
895 int const end_x = inset_x + width;
897 if (x > start_x && x < end_x
898 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
899 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
901 if (move_cursor && (tmpinset != bv_->theLockingInset()))
903 text->setCursor(bv_, cursor.par(),
904 cursor.pos() - 1, true);
906 // The origin of an inset is on the baseline
907 y = y_tmp - (text->cursor.y());
915 void BufferView::Pimpl::workAreaExpose()
917 static int work_area_width;
918 static unsigned int work_area_height;
920 bool const widthChange = workarea_.workWidth() != work_area_width;
921 bool const heightChange = workarea_.height() != work_area_height;
923 // update from work area
924 work_area_width = workarea_.workWidth();
925 work_area_height = workarea_.height();
928 // The visible LyXView need a resize
931 // Remove all texts from the textcache
932 // This is not _really_ what we want to do. What
933 // we really want to do is to delete in textcache
934 // that does not have a BufferView with matching
935 // width, but as long as we have only one BufferView
936 // deleting all gives the same result.
937 if (lyxerr.debugging())
938 textcache.show(lyxerr, "Expose delete all");
940 } else if (heightChange) {
941 // Rebuild image of current screen
943 // fitCursor() ensures we don't jump back
944 // to the start of the document on vertical
948 // The main window size has changed, repaint most stuff
950 } else if (screen_.get())
951 screen_->redraw(bv_->text, bv_);
953 // Grey box when we don't have a buffer
957 // always make sure that the scrollbar is sane.
959 owner_->updateLayoutChoice();
964 void BufferView::Pimpl::update()
967 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
969 LyXText::text_status st = bv_->text->status();
970 screen_->update(bv_->text, bv_);
972 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
973 if (bv_->text->fullRebreak(bv_)) {
974 st = LyXText::NEED_MORE_REFRESH;
975 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
976 bv_->text->cursor.pos());
979 bv_->text->status(bv_, st);
980 screen_->update(bv_->text, bv_);
982 // do this here instead of in the screen::update because of
984 bv_->text->status(bv_, LyXText::UNCHANGED);
990 // Values used when calling update:
992 // -2 - update, move sel_cursor if selection, fitcursor
993 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
994 // 0 - update, move sel_cursor if selection, fitcursor
995 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
996 // 3 - update, move sel_cursor if selection
999 // a simple redraw of the parts that need refresh
1001 // move sel_cursor if selection -
1002 // the text's sel_cursor is moved if there is selection is progress
1005 // fitCursor() is called and the scrollbar updated
1008 // the buffer is marked dirty.
1017 // UPDATE_ONLY = UPDATE;
1018 // UPDATE_SELECT = UPDATE | SELECT;
1019 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1020 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1022 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1023 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1024 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1025 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1026 // update(3) -> update(1) -> update(1) -> update(SELECT)
1028 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1030 owner_->updateLayoutChoice();
1032 if (!text->selection.set() && (f & SELECT)) {
1033 text->selection.cursor = text->cursor;
1036 text->fullRebreak(bv_);
1038 if (text->inset_owner) {
1039 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1040 updateInset(text->inset_owner, true);
1050 buffer_->markDirty();
1055 // Callback for cursor timer
1056 void BufferView::Pimpl::cursorToggle()
1058 // Quite a nice place for asyncron Inset updating, isn't it?
1059 // Actually no! This is run even if no buffer exist... so (Lgb)
1061 cursor_timeout.restart();
1066 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1067 if (pid == -1) // error find out what is wrong
1068 ; // ignore it for now.
1070 sigchldchecker(pid, &status);
1072 updatelist.update(bv_);
1074 if (!screen_.get()) {
1075 cursor_timeout.restart();
1079 if (!bv_->theLockingInset()) {
1080 screen_->cursorToggle(bv_);
1082 bv_->theLockingInset()->toggleInsetCursor(bv_);
1085 cursor_timeout.restart();
1089 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1091 if (!text->cursor.row()->previous())
1094 int y = text->first;
1095 if (text->inset_owner)
1096 y += bv_->text->first;
1097 Row * cursorrow = text->cursor.row();
1098 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1100 // This is to allow jumping over large insets
1101 if ((cursorrow == text->cursor.row()))
1102 text->cursorUp(bv_);
1104 if (text->inset_owner ||
1105 text->cursor.row()->height() < workarea_.height())
1106 screen_->draw(bv_->text, bv_,
1108 - text->cursor.row()->baseline()
1109 + text->cursor.row()->height()
1110 - workarea_.height() + 1 );
1115 void BufferView::Pimpl::cursorNext(LyXText * text)
1117 if (!text->cursor.row()->next())
1120 int y = text->first + workarea_.height();
1121 // if (text->inset_owner)
1122 // y += bv_->text->first;
1123 text->getRowNearY(y);
1125 Row * cursorrow = text->cursor.row();
1126 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1128 // This is to allow jumping over large insets
1129 if ((cursorrow == bv_->text->cursor.row()))
1130 text->cursorDown(bv_);
1132 if (text->inset_owner ||
1133 text->cursor.row()->height() < workarea_.height())
1134 screen_->draw(bv_->text, bv_, text->cursor.y() -
1135 text->cursor.row()->baseline());
1140 bool BufferView::Pimpl::available() const
1142 if (buffer_ && bv_->text) return true;
1147 void BufferView::Pimpl::beforeChange(LyXText * text)
1150 text->clearSelection();
1154 void BufferView::Pimpl::savePosition(unsigned int i)
1156 if (i >= saved_positions_num)
1158 saved_positions[i] = Position(buffer_->fileName(),
1159 bv_->text->cursor.par()->id(),
1160 bv_->text->cursor.pos());
1163 str << _("Saved bookmark") << ' ' << i;
1164 owner_->message(str.str().c_str());
1169 void BufferView::Pimpl::restorePosition(unsigned int i)
1171 if (i >= saved_positions_num)
1174 string const fname = saved_positions[i].filename;
1176 beforeChange(bv_->text);
1178 if (fname != buffer_->fileName()) {
1179 Buffer * b = bufferlist.exists(fname) ?
1180 bufferlist.getBuffer(fname) :
1181 bufferlist.loadLyXFile(fname); // don't ask, just load it
1182 if (b != 0 ) buffer(b);
1185 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1189 bv_->text->setCursor(bv_, par,
1190 min(par->size(), saved_positions[i].par_pos));
1192 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1195 str << _("Moved to bookmark") << ' ' << i;
1196 owner_->message(str.str().c_str());
1201 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1203 if (i >= saved_positions_num)
1206 return !saved_positions[i].filename.empty();
1210 void BufferView::Pimpl::setState()
1212 if (!lyxrc.rtl_support)
1215 LyXText * text = bv_->getLyXText();
1216 if (text->real_current_font.isRightToLeft()) {
1217 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1218 owner_->getIntl()->KeyMapSec();
1220 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1221 owner_->getIntl()->KeyMapPrim();
1226 void BufferView::Pimpl::insetSleep()
1228 if (bv_->theLockingInset() && !inset_slept) {
1229 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1230 bv_->theLockingInset()->insetUnlock(bv_);
1236 void BufferView::Pimpl::insetWakeup()
1238 if (bv_->theLockingInset() && inset_slept) {
1239 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1240 inset_slept = false;
1245 void BufferView::Pimpl::insetUnlock()
1247 if (bv_->theLockingInset()) {
1249 bv_->theLockingInset()->insetUnlock(bv_);
1250 bv_->theLockingInset(0);
1252 inset_slept = false;
1257 bool BufferView::Pimpl::focus() const
1259 return workarea_.hasFocus();
1263 void BufferView::Pimpl::focus(bool f)
1265 if (f) workarea_.setFocus();
1269 bool BufferView::Pimpl::active() const
1271 return workarea_.active();
1275 bool BufferView::Pimpl::belowMouse() const
1277 return workarea_.belowMouse();
1281 void BufferView::Pimpl::showCursor()
1283 if (screen_.get()) {
1284 if (bv_->theLockingInset())
1285 bv_->theLockingInset()->showInsetCursor(bv_);
1287 screen_->showCursor(bv_->text, bv_);
1292 void BufferView::Pimpl::hideCursor()
1294 if (screen_.get()) {
1295 if (!bv_->theLockingInset())
1296 // bv_->theLockingInset()->hideInsetCursor(bv_);
1298 screen_->hideCursor();
1303 void BufferView::Pimpl::toggleSelection(bool b)
1305 if (screen_.get()) {
1306 if (bv_->theLockingInset())
1307 bv_->theLockingInset()->toggleSelection(bv_, b);
1308 screen_->toggleSelection(bv_->text, bv_, b);
1313 void BufferView::Pimpl::toggleToggle()
1316 screen_->toggleToggle(bv_->text, bv_);
1320 void BufferView::Pimpl::center()
1322 beforeChange(bv_->text);
1323 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1324 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1326 screen_->draw(bv_->text, bv_, 0);
1328 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1333 void BufferView::Pimpl::pasteClipboard(bool asPara)
1335 if (!buffer_) return;
1337 screen_->hideCursor();
1338 beforeChange(bv_->text);
1340 string const clip(workarea_.getClipboard());
1342 if (clip.empty()) return;
1345 bv_->text->insertStringAsParagraphs(bv_, clip);
1347 bv_->text->insertStringAsLines(bv_, clip);
1349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1353 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1355 workarea_.putClipboard(stuff);
1360 * Dispatch functions for actions which can be valid for BufferView->text
1361 * and/or InsetText->text!!!
1366 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1368 LyXText * lt = bv_->getLyXText();
1370 if (selecting || lt->selection.mark()) {
1371 lt->setSelection(bv_);
1375 update(lt, BufferView::SELECT|BufferView::FITCUR);
1378 /* ---> Everytime the cursor is moved, show the current font state. */
1379 // should this too me moved out of this func?
1380 //owner->showState();
1385 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1387 LyXCursor cursor = bv_->getLyXText()->cursor;
1388 Buffer::inset_iterator it =
1389 find_if(Buffer::inset_iterator(
1390 cursor.par(), cursor.pos()),
1391 buffer_->inset_iterator_end(),
1392 lyx::compare_memfun(&Inset::lyxCode, code));
1393 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1397 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1399 string filename = filen;
1401 if (filename.empty()) {
1402 // Launch a file browser
1403 string initpath = lyxrc.document_path;
1406 string const trypath = owner_->buffer()->filepath;
1407 // If directory is writeable, use this as default.
1408 if (IsDirWriteable(trypath))
1412 FileDialog fileDlg(bv_->owner(),
1413 _("Select LyX document to insert"),
1415 make_pair(string(_("Documents")),
1416 string(lyxrc.document_path)),
1417 make_pair(string(_("Examples")),
1418 string(AddPath(system_lyxdir, "examples"))));
1420 FileDialog::Result result =
1421 fileDlg.Select(initpath,
1422 _("*.lyx| LyX Documents (*.lyx)"));
1424 if (result.first == FileDialog::Later)
1427 filename = result.second;
1429 // check selected filename
1430 if (filename.empty()) {
1431 owner_->message(_("Canceled."));
1436 // get absolute path of file and add ".lyx" to the filename if
1438 filename = FileSearch(string(), filename, "lyx");
1440 string const disp_fn(MakeDisplayPath(filename));
1443 s1 << _("Inserting document") << ' '
1444 << disp_fn << " ...";
1445 owner_->message(s1.str().c_str());
1446 bool const res = bv_->insertLyXFile(filename);
1449 str << _("Document") << ' ' << disp_fn
1450 << ' ' << _("inserted.");
1451 owner_->message(str.str().c_str());
1454 str << _("Could not insert document") << ' '
1456 owner_->message(str.str().c_str());
1461 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1463 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1464 << action <<"] arg[" << argument << "]" << endl;
1467 // --- Misc -------------------------------------------
1471 LyXText * lt = bv_->getLyXText();
1472 lt->toggleAppendix(bv_);
1475 | BufferView::FITCUR
1476 | BufferView::CHANGE);
1481 case LFUN_TOC_INSERT:
1483 InsetCommandParams p;
1484 p.setCmdName("tableofcontents");
1485 Inset * inset = new InsetTOC(p);
1486 if (!insertInset(inset, "Standard"))
1491 case LFUN_TABULAR_FEATURE:
1492 case LFUN_SCROLL_INSET:
1493 // this is not handled here as this funktion is only aktive
1494 // if we have a locking_inset and that one is (or contains)
1498 case LFUN_INSET_GRAPHICS:
1500 Inset * new_inset = new InsetGraphics;
1501 if (!insertInset(new_inset)) {
1504 // this is need because you don't use a inset->Edit()
1505 updateInset(new_inset, true);
1506 new_inset->edit(bv_);
1516 case LFUN_PASTESELECTION:
1518 bool asPara = false;
1519 if (argument == "paragraph") asPara = true;
1520 pasteClipboard(asPara);
1532 case LFUN_LAYOUT_COPY:
1533 bv_->copyEnvironment();
1536 case LFUN_LAYOUT_PASTE:
1537 bv_->pasteEnvironment();
1541 case LFUN_GOTOERROR:
1542 gotoInset(Inset::ERROR_CODE, false);
1546 gotoInset(Inset::IGNORE_CODE, false);
1549 case LFUN_REFERENCE_GOTO:
1551 vector<Inset::Code> tmp;
1552 tmp.push_back(Inset::LABEL_CODE);
1553 tmp.push_back(Inset::REF_CODE);
1554 gotoInset(tmp, true);
1558 case LFUN_HYPHENATION:
1559 specialChar(InsetSpecialChar::HYPHENATION);
1562 case LFUN_LIGATURE_BREAK:
1563 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1567 specialChar(InsetSpecialChar::LDOTS);
1570 case LFUN_END_OF_SENTENCE:
1571 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1574 case LFUN_MENU_SEPARATOR:
1575 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1583 changeDepth(bv_, bv_->getLyXText(), 0);
1586 case LFUN_DEPTH_MIN:
1587 changeDepth(bv_, bv_->getLyXText(), -1);
1590 case LFUN_DEPTH_PLUS:
1591 changeDepth(bv_, bv_->getLyXText(), 1);
1595 owner_->getDialogs()->setUserFreeFont();
1598 case LFUN_FILE_INSERT:
1600 MenuInsertLyXFile(argument);
1604 case LFUN_FILE_INSERT_ASCII_PARA:
1605 InsertAsciiFile(bv_, argument, true);
1608 case LFUN_FILE_INSERT_ASCII:
1609 InsertAsciiFile(bv_, argument, false);
1614 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1615 << argument << endl;
1617 // Derive layout number from given argument (string)
1618 // and current buffer's textclass (number). */
1619 LyXTextClassList::ClassList::size_type tclass =
1620 buffer_->params.textclass;
1621 pair <bool, LyXTextClass::size_type> layout =
1622 textclasslist.NumberOfLayout(tclass, argument);
1624 // If the entry is obsolete, use the new one instead.
1626 string obs = textclasslist.Style(tclass,layout.second)
1630 textclasslist.NumberOfLayout(tclass, obs);
1633 // see if we found the layout number:
1634 if (!layout.first) {
1635 owner_->getLyXFunc()->setErrorMessage(
1636 string(N_("Layout ")) + argument +
1641 if (current_layout != layout.second) {
1642 LyXText * lt = bv_->getLyXText();
1644 current_layout = layout.second;
1647 | BufferView::FITCUR);
1648 lt->setLayout(bv_, layout.second);
1649 owner_->setLayout(layout.second);
1652 | BufferView::FITCUR
1653 | BufferView::CHANGE);
1660 lang(bv_, argument);
1662 owner_->showState();
1667 owner_->showState();
1672 owner_->showState();
1677 owner_->showState();
1682 owner_->showState();
1687 owner_->showState();
1692 owner_->showState();
1697 owner_->showState();
1700 case LFUN_UNDERLINE:
1702 owner_->showState();
1705 case LFUN_FONT_SIZE:
1706 fontSize(bv_, argument);
1707 owner_->showState();
1710 case LFUN_FONT_STATE:
1711 owner_->getLyXFunc()->setMessage(currentState(bv_));
1714 case LFUN_UPCASE_WORD:
1716 LyXText * lt = bv_->getLyXText();
1720 | BufferView::FITCUR);
1721 lt->changeCase(bv_, LyXText::text_uppercase);
1722 if (lt->inset_owner)
1723 updateInset(lt->inset_owner, true);
1726 | BufferView::FITCUR
1727 | BufferView::CHANGE);
1731 case LFUN_LOWCASE_WORD:
1733 LyXText * lt = bv_->getLyXText();
1735 update(lt, BufferView::SELECT|BufferView::FITCUR);
1736 lt->changeCase(bv_, LyXText::text_lowercase);
1737 if (lt->inset_owner)
1738 updateInset(lt->inset_owner, true);
1741 | BufferView::FITCUR
1742 | BufferView::CHANGE);
1746 case LFUN_CAPITALIZE_WORD:
1748 LyXText * lt = bv_->getLyXText();
1750 update(lt, BufferView::SELECT|BufferView::FITCUR);
1751 lt->changeCase(bv_, LyXText::text_capitalization);
1752 if (lt->inset_owner)
1753 updateInset(lt->inset_owner, true);
1756 | BufferView::FITCUR
1757 | BufferView::CHANGE);
1761 case LFUN_TRANSPOSE_CHARS:
1763 LyXText * lt = bv_->getLyXText();
1765 update(lt, BufferView::SELECT|BufferView::FITCUR);
1766 lt->transposeChars(*bv_);
1767 if (lt->inset_owner)
1768 updateInset(lt->inset_owner, true);
1771 | BufferView::FITCUR
1772 | BufferView::CHANGE);
1777 case LFUN_INSERT_LABEL:
1778 MenuInsertLabel(bv_, argument);
1781 case LFUN_REF_INSERT:
1782 if (argument.empty()) {
1783 InsetCommandParams p("ref");
1784 owner_->getDialogs()->createRef(p.getAsString());
1786 InsetCommandParams p;
1787 p.setFromString(argument);
1789 InsetRef * inset = new InsetRef(p, *buffer_);
1790 if (!insertInset(inset))
1793 updateInset(inset, true);
1797 case LFUN_BOOKMARK_SAVE:
1798 savePosition(strToUnsignedInt(argument));
1801 case LFUN_BOOKMARK_GOTO:
1802 restorePosition(strToUnsignedInt(argument));
1807 string label(argument);
1808 if (label.empty()) {
1810 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1812 label = inset->getContents();
1817 if (!label.empty()) {
1818 //bv_->savePosition(0);
1819 if (!bv_->gotoLabel(label))
1820 WriteAlert(_("Error"),
1821 _("Couldn't find this label"),
1822 _("in current document."));
1827 // --- Cursor Movements -----------------------------
1830 LyXText * lt = bv_->getLyXText();
1832 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1833 if (!lt->selection.mark())
1835 update(lt, BufferView::SELECT|BufferView::FITCUR);
1837 lt->cursorLeft(bv_, false);
1838 if (lt->cursor.pos() < lt->cursor.par()->size()
1839 && lt->cursor.par()->getChar(lt->cursor.pos())
1840 == Paragraph::META_INSET
1841 && lt->cursor.par()->getInset(lt->cursor.pos())
1842 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1843 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1844 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1846 tmpinset->edit(bv_, false);
1848 tmpinset->edit(bv_);
1852 lt->cursorRight(bv_, false);
1854 moveCursorUpdate(false);
1855 owner_->showState();
1861 // This is soooo ugly. Isn`t it possible to make
1862 // it simpler? (Lgb)
1863 LyXText * lt = bv_->getLyXText();
1864 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1865 if (!lt->selection.mark())
1867 update(lt, BufferView::SELECT|BufferView::FITCUR);
1868 LyXCursor const cur = lt->cursor;
1870 lt->cursorLeft(bv_, false);
1871 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1872 lt->cursor.pos() < lt->cursor.par()->size() &&
1873 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1874 Paragraph::META_INSET) &&
1875 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1876 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1877 == Inset::HIGHLY_EDITABLE))
1879 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1880 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1882 tmpinset->edit(bv_);
1884 tmpinset->edit(bv_, false);
1888 lt->cursorRight(bv_, false);
1891 moveCursorUpdate(false);
1892 owner_->showState();
1898 LyXText * lt = bv_->getLyXText();
1900 if (!lt->selection.mark())
1902 update(lt, BufferView::UPDATE);
1905 moveCursorUpdate(false);
1906 owner_->showState();
1912 LyXText * lt = bv_->getLyXText();
1914 if (!lt->selection.mark())
1916 update(lt, BufferView::UPDATE);
1917 lt->cursorDown(bv_);
1919 moveCursorUpdate(false);
1920 owner_->showState();
1924 case LFUN_UP_PARAGRAPH:
1926 LyXText * lt = bv_->getLyXText();
1928 if (!lt->selection.mark())
1930 update(lt, BufferView::UPDATE);
1931 lt->cursorUpParagraph(bv_);
1933 moveCursorUpdate(false);
1934 owner_->showState();
1938 case LFUN_DOWN_PARAGRAPH:
1940 LyXText * lt = bv_->getLyXText();
1942 if (!lt->selection.mark())
1944 update(lt, BufferView::UPDATE);
1945 lt->cursorDownParagraph(bv_);
1947 moveCursorUpdate(false);
1948 owner_->showState();
1954 LyXText * lt = bv_->getLyXText();
1956 if (!lt->selection.mark())
1958 update(lt, BufferView::UPDATE);
1961 moveCursorUpdate(false);
1962 owner_->showState();
1968 LyXText * lt = bv_->getLyXText();
1970 if (!lt->selection.mark())
1972 update(lt, BufferView::UPDATE);
1975 moveCursorUpdate(false);
1976 owner_->showState();
1982 LyXText * lt = bv_->getLyXText();
1984 if (!lt->selection.mark())
1986 update(lt, BufferView::SELECT|BufferView::FITCUR);
1987 lt->cursorHome(bv_);
1989 moveCursorUpdate(false);
1990 owner_->showState();
1996 LyXText * lt = bv_->getLyXText();
1998 if (!lt->selection.mark())
2001 BufferView::SELECT|BufferView::FITCUR);
2004 moveCursorUpdate(false);
2005 owner_->showState();
2009 case LFUN_SHIFT_TAB:
2012 LyXText * lt = bv_->getLyXText();
2014 if (!lt->selection.mark())
2017 BufferView::SELECT|BufferView::FITCUR);
2020 moveCursorUpdate(false);
2021 owner_->showState();
2025 case LFUN_WORDRIGHT:
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2031 update(lt, BufferView::SELECT|BufferView::FITCUR);
2032 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2033 lt->cursorLeftOneWord(bv_);
2035 lt->cursorRightOneWord(bv_);
2037 moveCursorUpdate(false);
2038 owner_->showState();
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->cursorRightOneWord(bv_);
2052 lt->cursorLeftOneWord(bv_);
2054 moveCursorUpdate(false);
2055 owner_->showState();
2059 case LFUN_BEGINNINGBUF:
2061 LyXText * lt = bv_->getLyXText();
2063 if (!lt->selection.mark())
2066 BufferView::SELECT|BufferView::FITCUR);
2069 moveCursorUpdate(false);
2070 owner_->showState();
2076 LyXText * lt = bv_->getLyXText();
2078 if (!lt->selection.mark())
2081 BufferView::SELECT|BufferView::FITCUR);
2082 lt->cursorBottom(bv_);
2084 moveCursorUpdate(false);
2085 owner_->showState();
2089 /* cursor selection ---------------------------- */
2092 LyXText * lt = bv_->getLyXText();
2095 BufferView::SELECT|BufferView::FITCUR);
2096 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2097 lt->cursorLeft(bv_);
2099 lt->cursorRight(bv_);
2101 moveCursorUpdate(true);
2102 owner_->showState();
2108 LyXText * lt = bv_->getLyXText();
2111 BufferView::SELECT|BufferView::FITCUR);
2112 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2113 lt->cursorRight(bv_);
2115 lt->cursorLeft(bv_);
2117 moveCursorUpdate(true);
2118 owner_->showState();
2124 LyXText * lt = bv_->getLyXText();
2127 BufferView::SELECT|BufferView::FITCUR);
2130 moveCursorUpdate(true);
2131 owner_->showState();
2137 LyXText * lt = bv_->getLyXText();
2140 BufferView::SELECT|BufferView::FITCUR);
2141 lt->cursorDown(bv_);
2143 moveCursorUpdate(true);
2144 owner_->showState();
2148 case LFUN_UP_PARAGRAPHSEL:
2150 LyXText * lt = bv_->getLyXText();
2153 BufferView::SELECT|BufferView::FITCUR);
2154 lt->cursorUpParagraph(bv_);
2156 moveCursorUpdate(true);
2157 owner_->showState();
2161 case LFUN_DOWN_PARAGRAPHSEL:
2163 LyXText * lt = bv_->getLyXText();
2166 BufferView::SELECT|BufferView::FITCUR);
2167 lt->cursorDownParagraph(bv_);
2169 moveCursorUpdate(true);
2170 owner_->showState();
2176 LyXText * lt = bv_->getLyXText();
2178 update(lt, BufferView::SELECT|BufferView::FITCUR);
2181 moveCursorUpdate(true);
2182 owner_->showState();
2188 LyXText * lt = bv_->getLyXText();
2190 update(lt, BufferView::SELECT|BufferView::FITCUR);
2193 moveCursorUpdate(true);
2194 owner_->showState();
2200 LyXText * lt = bv_->getLyXText();
2202 update(lt, BufferView::SELECT|BufferView::FITCUR);
2203 lt->cursorHome(bv_);
2205 moveCursorUpdate(true);
2206 owner_->showState();
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 moveCursorUpdate(true);
2218 owner_->showState();
2222 case LFUN_WORDRIGHTSEL:
2224 LyXText * lt = bv_->getLyXText();
2226 update(lt, BufferView::SELECT|BufferView::FITCUR);
2227 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2228 lt->cursorLeftOneWord(bv_);
2230 lt->cursorRightOneWord(bv_);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2237 case LFUN_WORDLEFTSEL:
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2242 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2243 lt->cursorRightOneWord(bv_);
2245 lt->cursorLeftOneWord(bv_);
2247 moveCursorUpdate(true);
2248 owner_->showState();
2252 case LFUN_BEGINNINGBUFSEL:
2254 LyXText * lt = bv_->getLyXText();
2256 if (lt->inset_owner)
2258 update(lt, BufferView::SELECT|BufferView::FITCUR);
2261 moveCursorUpdate(true);
2262 owner_->showState();
2266 case LFUN_ENDBUFSEL:
2268 LyXText * lt = bv_->getLyXText();
2270 if (lt->inset_owner)
2273 BufferView::SELECT|BufferView::FITCUR);
2274 lt->cursorBottom(bv_);
2276 moveCursorUpdate(true);
2277 owner_->showState();
2281 // --- text changing commands ------------------------
2282 case LFUN_BREAKLINE:
2284 LyXText * lt = bv_->getLyXText();
2287 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2290 | BufferView::FITCUR
2291 | BufferView::CHANGE);
2292 moveCursorUpdate(false);
2296 case LFUN_PROTECTEDSPACE:
2298 LyXText * lt = bv_->getLyXText();
2300 LyXLayout const & style = textclasslist
2301 .Style(buffer_->params.textclass,
2302 lt->cursor.par()->getLayout());
2304 if (style.free_spacing) {
2305 lt->insertChar(bv_, ' ');
2308 | BufferView::FITCUR
2309 | BufferView::CHANGE);
2313 moveCursorUpdate(false);
2319 LyXText * lt = bv_->getLyXText();
2321 if (lt->selection.mark()) {
2325 | BufferView::FITCUR);
2326 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2329 lt->selection.mark(true);
2332 | BufferView::FITCUR);
2333 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2335 lt->selection.cursor = lt->cursor;
2341 LyXText * lt = bv_->getLyXText();
2343 if (!lt->selection.set()) {
2345 lt->selection.cursor = lt->cursor;
2348 | BufferView::FITCUR
2349 | BufferView::CHANGE);
2350 // It is possible to make it a lot faster still
2351 // just comment out the line below...
2356 moveCursorUpdate(false);
2357 owner_->showState();
2362 case LFUN_DELETE_SKIP:
2364 LyXText * lt = bv_->getLyXText();
2366 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2368 LyXCursor cursor = lt->cursor;
2370 if (!lt->selection.set()) {
2371 if (cursor.pos() == cursor.par()->size()) {
2372 lt->cursorRight(bv_);
2373 cursor = lt->cursor;
2374 if (cursor.pos() == 0
2375 && !(cursor.par()->params().spaceTop()
2376 == VSpace (VSpace::NONE))) {
2379 cursor.par()->params().lineTop(),
2380 cursor.par()->params().lineBottom(),
2381 cursor.par()->params().pagebreakTop(),
2382 cursor.par()->params().pagebreakBottom(),
2383 VSpace(VSpace::NONE),
2384 cursor.par()->params().spaceBottom(),
2385 cursor.par()->params().spacing(),
2386 cursor.par()->params().align(),
2387 cursor.par()->params().labelWidthString(), 0);
2388 lt->cursorLeft(bv_);
2391 | BufferView::FITCUR
2392 | BufferView::CHANGE);
2394 lt->cursorLeft(bv_);
2396 lt->selection.cursor = lt->cursor;
2399 | BufferView::FITCUR
2400 | BufferView::CHANGE);
2404 lt->selection.cursor = lt->cursor;
2407 | BufferView::FITCUR
2408 | BufferView::CHANGE);
2416 /* -------> Delete word forward. */
2417 case LFUN_DELETE_WORD_FORWARD:
2418 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2419 bv_->getLyXText()->deleteWordForward(bv_);
2420 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2421 moveCursorUpdate(false);
2422 owner_->showState();
2425 /* -------> Delete word backward. */
2426 case LFUN_DELETE_WORD_BACKWARD:
2428 LyXText * lt = bv_->getLyXText();
2430 update(lt, BufferView::SELECT|BufferView::FITCUR);
2431 lt->deleteWordBackward(bv_);
2434 | BufferView::FITCUR
2435 | BufferView::CHANGE);
2436 moveCursorUpdate(false);
2437 owner_->showState();
2441 /* -------> Kill to end of line. */
2442 case LFUN_DELETE_LINE_FORWARD:
2444 LyXText * lt = bv_->getLyXText();
2446 update(lt, BufferView::SELECT|BufferView::FITCUR);
2447 lt->deleteLineForward(bv_);
2450 | BufferView::FITCUR
2451 | BufferView::CHANGE);
2452 moveCursorUpdate(false);
2456 /* -------> Set mark off. */
2459 LyXText * lt = bv_->getLyXText();
2462 update(lt, BufferView::SELECT|BufferView::FITCUR);
2463 lt->selection.cursor = lt->cursor;
2464 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2468 /* -------> Set mark on. */
2471 LyXText * lt = bv_->getLyXText();
2474 lt->selection.mark(true);
2475 update(lt, BufferView::SELECT|BufferView::FITCUR);
2476 lt->selection.cursor = lt->cursor;
2477 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2481 case LFUN_BACKSPACE:
2483 LyXText * lt = bv_->getLyXText();
2485 if (!lt->selection.set()) {
2486 if (owner_->getIntl()->getTrans().backspace()) {
2488 lt->selection.cursor = lt->cursor;
2491 | BufferView::FITCUR
2492 | BufferView::CHANGE);
2493 // It is possible to make it a lot faster still
2494 // just comment out the line below...
2500 owner_->showState();
2505 case LFUN_BACKSPACE_SKIP:
2507 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2508 LyXText * lt = bv_->getLyXText();
2510 LyXCursor cursor = lt->cursor;
2512 if (!lt->selection.set()) {
2513 if (cursor.pos() == 0
2514 && !(cursor.par()->params().spaceTop()
2515 == VSpace (VSpace::NONE))) {
2518 cursor.par()->params().lineTop(),
2519 cursor.par()->params().lineBottom(),
2520 cursor.par()->params().pagebreakTop(),
2521 cursor.par()->params().pagebreakBottom(),
2522 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2523 cursor.par()->params().spacing(),
2524 cursor.par()->params().align(),
2525 cursor.par()->params().labelWidthString(), 0);
2528 | BufferView::FITCUR
2529 | BufferView::CHANGE);
2532 lt->selection.cursor = cursor;
2535 | BufferView::FITCUR
2536 | BufferView::CHANGE);
2543 case LFUN_BREAKPARAGRAPH:
2545 LyXText * lt = bv_->getLyXText();
2548 lt->breakParagraph(bv_, 0);
2551 | BufferView::FITCUR
2552 | BufferView::CHANGE);
2553 lt->selection.cursor = lt->cursor;
2555 owner_->showState();
2559 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2561 LyXText * lt = bv_->getLyXText();
2564 lt->breakParagraph(bv_, 1);
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2569 lt->selection.cursor = lt->cursor;
2571 owner_->showState();
2575 case LFUN_BREAKPARAGRAPH_SKIP:
2577 // When at the beginning of a paragraph, remove
2578 // indentation and add a "defskip" at the top.
2579 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2580 LyXText * lt = bv_->getLyXText();
2582 LyXCursor cursor = lt->cursor;
2585 if (cursor.pos() == 0) {
2586 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2589 cursor.par()->params().lineTop(),
2590 cursor.par()->params().lineBottom(),
2591 cursor.par()->params().pagebreakTop(),
2592 cursor.par()->params().pagebreakBottom(),
2593 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2594 cursor.par()->params().spacing(),
2595 cursor.par()->params().align(),
2596 cursor.par()->params().labelWidthString(), 1);
2597 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2601 lt->breakParagraph(bv_, 0);
2602 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2607 | BufferView::FITCUR
2608 | BufferView::CHANGE);
2609 lt->selection.cursor = cursor;
2611 owner_->showState();
2615 case LFUN_PARAGRAPH_SPACING:
2617 LyXText * lt = bv_->getLyXText();
2619 Paragraph * par = lt->cursor.par();
2620 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2621 float cur_value = 1.0;
2622 if (cur_spacing == Spacing::Other) {
2623 cur_value = par->params().spacing().getValue();
2626 istringstream istr(argument.c_str());
2630 Spacing::Space new_spacing = cur_spacing;
2631 float new_value = cur_value;
2633 lyxerr << "Missing argument to `paragraph-spacing'"
2635 } else if (tmp == "single") {
2636 new_spacing = Spacing::Single;
2637 } else if (tmp == "onehalf") {
2638 new_spacing = Spacing::Onehalf;
2639 } else if (tmp == "double") {
2640 new_spacing = Spacing::Double;
2641 } else if (tmp == "other") {
2642 new_spacing = Spacing::Other;
2645 lyxerr << "new_value = " << tmpval << endl;
2648 } else if (tmp == "default") {
2649 new_spacing = Spacing::Default;
2651 lyxerr << _("Unknown spacing argument: ")
2652 << argument << endl;
2654 if (cur_spacing != new_spacing || cur_value != new_value) {
2655 par->params().spacing(Spacing(new_spacing, new_value));
2656 lt->redoParagraph(bv_);
2659 | BufferView::FITCUR
2660 | BufferView::CHANGE);
2665 case LFUN_INSET_TOGGLE:
2667 LyXText * lt = bv_->getLyXText();
2670 update(lt, BufferView::SELECT|BufferView::FITCUR);
2671 lt->toggleInset(bv_);
2672 update(lt, BufferView::SELECT|BufferView::FITCUR);
2684 InsetCommandParams p;
2685 if (action == LFUN_HTMLURL)
2686 p.setCmdName("htmlurl");
2688 p.setCmdName("url");
2689 owner_->getDialogs()->createUrl(p.getAsString());
2693 case LFUN_INSERT_URL:
2695 InsetCommandParams p;
2696 p.setFromString(argument);
2698 InsetUrl * inset = new InsetUrl(p);
2699 if (!insertInset(inset))
2702 updateInset(inset, true);
2706 case LFUN_INSET_TEXT:
2707 insertAndEditInset(new InsetText);
2710 case LFUN_INSET_ERT:
2711 insertAndEditInset(new InsetERT);
2714 case LFUN_INSET_EXTERNAL:
2715 insertAndEditInset(new InsetExternal);
2718 case LFUN_INSET_FOOTNOTE:
2719 insertAndEditInset(new InsetFoot);
2722 case LFUN_INSET_MARGINAL:
2723 insertAndEditInset(new InsetMarginal);
2726 case LFUN_INSET_MINIPAGE:
2727 insertAndEditInset(new InsetMinipage);
2730 case LFUN_INSERT_NOTE:
2731 insertAndEditInset(new InsetNote);
2734 case LFUN_INSET_FLOAT:
2735 // check if the float type exist
2736 if (floatList.typeExist(argument)) {
2737 insertAndEditInset(new InsetFloat(argument));
2739 lyxerr << "Non-existent float type: "
2740 << argument << endl;
2744 case LFUN_INSET_WIDE_FLOAT:
2746 // check if the float type exist
2747 if (floatList.typeExist(argument)) {
2748 InsetFloat * new_inset = new InsetFloat(argument);
2749 new_inset->wide(true);
2750 if (insertInset(new_inset))
2751 new_inset->edit(bv_);
2755 lyxerr << "Non-existent float type: "
2756 << argument << endl;
2763 case LFUN_INSET_LIST:
2764 insertAndEditInset(new InsetList);
2767 case LFUN_INSET_THEOREM:
2768 insertAndEditInset(new InsetTheorem);
2772 case LFUN_INSET_CAPTION:
2774 // Do we have a locking inset...
2775 if (bv_->theLockingInset()) {
2776 lyxerr << "Locking inset code: "
2777 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2778 InsetCaption * new_inset = new InsetCaption;
2779 new_inset->setOwner(bv_->theLockingInset());
2780 new_inset->setAutoBreakRows(true);
2781 new_inset->setDrawFrame(0, InsetText::LOCKED);
2782 new_inset->setFrameColor(0, LColor::captionframe);
2783 if (insertInset(new_inset))
2784 new_inset->edit(bv_);
2791 case LFUN_INSET_TABULAR:
2795 if (!argument.empty())
2796 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2797 InsetTabular * new_inset =
2798 new InsetTabular(*buffer_, r, c);
2800 bv_->getLyXText()->real_current_font.isRightToLeft();
2801 if (!open_new_inset(new_inset, rtl))
2806 // --- lyxserver commands ----------------------------
2808 case LFUN_CHARATCURSOR:
2810 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2811 if (pos < bv_->getLyXText()->cursor.par()->size())
2812 owner_->getLyXFunc()->setMessage(
2813 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2815 owner_->getLyXFunc()->setMessage("EOF");
2820 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2822 + tostr(bv_->getLyXText()->cursor.y()));
2829 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2830 lyxerr << "SETXY: Could not parse coordinates in '"
2831 << argument << std::endl;
2833 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2837 case LFUN_GETLAYOUT:
2838 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2843 LyXFont & font = bv_->getLyXText()->current_font;
2844 if (font.shape() == LyXFont::ITALIC_SHAPE)
2845 owner_->getLyXFunc()->setMessage("E");
2846 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2847 owner_->getLyXFunc()->setMessage("N");
2849 owner_->getLyXFunc()->setMessage("0");
2854 // --- accented characters ---------------------------
2857 case LFUN_CIRCUMFLEX:
2867 case LFUN_SPECIAL_CARON:
2870 case LFUN_HUNG_UMLAUT:
2873 if (argument.empty()) {
2875 owner_->getLyXFunc()->handleKeyFunc(action);
2877 owner_->getLyXFunc()->handleKeyFunc(action);
2878 owner_->getIntl()->getTrans()
2879 .TranslateAndInsert(argument[0], bv_->getLyXText());
2880 update(bv_->getLyXText(),
2882 | BufferView::FITCUR
2883 | BufferView::CHANGE);
2887 case LFUN_MATH_MACRO:
2888 mathDispatchMathMacro(bv_, argument);
2891 case LFUN_MATH_DELIM:
2892 mathDispatchMathDelim(bv_, argument);
2895 case LFUN_INSERT_MATRIX:
2896 mathDispatchInsertMatrix(bv_, argument);
2899 case LFUN_INSERT_MATH:
2900 mathDispatchInsertMath(bv_, argument);
2903 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2904 mathDispatchMathImportSelection(bv_, argument);
2907 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2908 mathDispatchMathDisplay(bv_, argument);
2911 case LFUN_MATH_MODE: // Open or create an inlined math inset
2912 mathDispatchMathMode(bv_, argument);
2915 case LFUN_CITATION_INSERT:
2917 InsetCommandParams p;
2918 p.setFromString( argument );
2920 InsetCitation * inset = new InsetCitation( p );
2921 if (!insertInset(inset))
2924 updateInset( inset, true );
2928 case LFUN_INSERT_BIBTEX:
2930 // ale970405+lasgoutt970425
2931 // The argument can be up to two tokens separated
2932 // by a space. The first one is the bibstyle.
2933 string const db = token(argument, ' ', 0);
2934 string const bibstyle = token(argument, ' ', 1);
2936 InsetCommandParams p( "BibTeX", db, bibstyle );
2937 InsetBibtex * inset = new InsetBibtex(p);
2939 if (insertInset(inset)) {
2940 if (argument.empty())
2947 // BibTeX data bases
2948 case LFUN_BIBDB_ADD:
2950 InsetBibtex * inset =
2951 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2953 inset->addDatabase(argument);
2958 case LFUN_BIBDB_DEL:
2960 InsetBibtex * inset =
2961 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2963 inset->delDatabase(argument);
2968 case LFUN_BIBTEX_STYLE:
2970 InsetBibtex * inset =
2971 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2973 inset->setOptions(argument);
2978 case LFUN_INDEX_CREATE:
2980 InsetCommandParams p("index");
2981 if (argument.empty()) {
2982 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2983 p.setContents(idxstring);
2985 p.setContents(argument);
2988 owner_->getDialogs()->createIndex(p.getAsString());
2992 case LFUN_INDEX_INSERT:
2994 InsetCommandParams p;
2995 p.setFromString(argument);
2996 InsetIndex * inset = new InsetIndex(p);
2998 if (!insertInset(inset))
3001 updateInset(inset, true);
3005 case LFUN_INDEX_INSERT_LAST:
3007 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3008 if (!idxstring.empty()) {
3009 owner_->message(_("Word `")
3010 + idxstring + _(("' indexed.")));
3011 InsetCommandParams p("index", idxstring);
3012 InsetIndex * inset = new InsetIndex(p);
3014 if (!insertInset(inset))
3017 updateInset(inset, true);
3022 case LFUN_INDEX_PRINT:
3024 InsetCommandParams p("printindex");
3025 Inset * inset = new InsetPrintIndex(p);
3026 if (!insertInset(inset, "Standard"))
3031 case LFUN_PARENTINSERT:
3033 lyxerr << "arg " << argument << endl;
3034 InsetCommandParams p( "lyxparent", argument );
3035 Inset * inset = new InsetParent(p, *buffer_);
3036 if (!insertInset(inset, "Standard"))
3042 case LFUN_CHILD_INSERT:
3044 InsetInclude::Params p;
3045 p.cparams.setFromString(argument);
3046 p.masterFilename_ = buffer_->fileName();
3048 InsetInclude * inset = new InsetInclude(p);
3049 if (!insertInset(inset))
3052 updateInset(inset, true);
3053 bv_->owner()->getDialogs()->showInclude(inset);
3058 case LFUN_FLOAT_LIST:
3060 // We should check the argument for validity. (Lgb)
3061 Inset * inset = new InsetFloatList(argument);
3062 if (!insertInset(inset, "Standard"))
3067 case LFUN_THESAURUS_ENTRY:
3069 string arg = argument;
3072 arg = bv_->getLyXText()->selectionAsString(buffer_,
3076 if (arg.size() > 100 || arg.empty()) {
3077 // Get word or selection
3078 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3079 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3080 // FIXME: where is getLyXText()->unselect(bv_) ?
3084 bv_->owner()->getDialogs()->showThesaurus(arg);
3088 case LFUN_SELFINSERT:
3090 if (argument.empty()) break;
3092 /* Automatically delete the currently selected
3093 * text and replace it with what is being
3094 * typed in now. Depends on lyxrc settings
3095 * "auto_region_delete", which defaults to
3098 LyXText * lt = bv_->getLyXText();
3100 if (lyxrc.auto_region_delete) {
3101 if (lt->selection.set()) {
3102 lt->cutSelection(bv_, false, false);
3105 | BufferView::FITCUR
3106 | BufferView::CHANGE);
3111 LyXFont const old_font(lt->real_current_font);
3113 string::const_iterator cit = argument.begin();
3114 string::const_iterator end = argument.end();
3115 for (; cit != end; ++cit) {
3116 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3121 | BufferView::FITCUR
3122 | BufferView::CHANGE);
3124 lt->selection.cursor = lt->cursor;
3125 moveCursorUpdate(false);
3127 // real_current_font.number can change so we need to
3128 // update the minibuffer
3129 if (old_font != lt->real_current_font)
3130 owner_->showState();
3135 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3137 time_t now_time_t = time(NULL);
3138 struct tm * now_tm = localtime(&now_time_t);
3139 setlocale(LC_TIME, "");
3141 if (!argument.empty())
3144 arg = lyxrc.date_insert_format;
3146 int const datetmp_len =
3147 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3149 LyXText * lt = bv_->getLyXText();
3151 for (int i = 0; i < datetmp_len; i++) {
3152 lt->insertChar(bv_, datetmp[i]);
3155 | BufferView::FITCUR
3156 | BufferView::CHANGE);
3159 lt->selection.cursor = lt->cursor;
3160 moveCursorUpdate(false);
3164 case LFUN_UNKNOWN_ACTION:
3165 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3176 void BufferView::Pimpl::newline()
3179 LyXText * lt = bv_->getLyXText();
3183 | BufferView::FITCUR);
3184 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3187 | BufferView::FITCUR
3188 | BufferView::CHANGE);
3193 void BufferView::Pimpl::hfill()
3196 LyXText * lt = bv_->getLyXText();
3200 | BufferView::FITCUR);
3201 lt->insertChar(bv_, Paragraph::META_HFILL);
3204 | BufferView::FITCUR
3205 | BufferView::CHANGE);
3210 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3214 update(lt, BufferView::SELECT|BufferView::FITCUR);
3215 InsetSpecialChar * new_inset =
3216 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3217 #ifdef WITH_WARNINGS
3218 #warning Why is this code different from specialChar() below? (JMarc)
3219 // the code in specialChar is a generic version of what used to exist
3220 // for other special chars. I did not merge this case because of the
3221 // call to updateInset(), but what does it do?
3223 if (!insertInset(new_inset))
3226 updateInset(new_inset, true);
3231 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3234 LyXText * lt = bv_->getLyXText();
3237 update(lt, BufferView::SELECT|BufferView::FITCUR);
3238 InsetSpecialChar * new_inset =
3239 new InsetSpecialChar(kind);
3240 insertInset(new_inset);
3241 // Ok, what happens here if we are unable to insert
3242 // the inset? Leak it?
3247 void BufferView::Pimpl::smartQuote()
3250 LyXText * lt = bv_->getLyXText();
3252 if (lt->cursor.pos())
3253 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3259 LyXLayout const & style = textclasslist.Style(
3260 bv_->buffer()->params.textclass,
3261 lt->cursor.par()->getLayout());
3263 if (style.pass_thru ||
3264 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3265 Dispatch(LFUN_SELFINSERT, "\"");
3269 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3271 if (insertInset(inset))
3278 // Open and lock an updatable inset
3279 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3281 LyXText * lt = bv_->getLyXText();
3285 if (!insertInset(new_inset)) {
3289 new_inset->edit(bv_, !behind);
3294 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3296 // if we are in a locking inset we should try to insert the
3297 // inset there otherwise this is a illegal function now
3298 if (bv_->theLockingInset()) {
3299 if (bv_->theLockingInset()->insetAllowed(inset))
3300 return bv_->theLockingInset()->insertInset(bv_, inset);
3304 // not quite sure if we want this...
3305 setCursorParUndo(bv_);
3308 beforeChange(bv_->text);
3309 if (!lout.empty()) {
3310 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3311 bv_->text->breakParagraph(bv_);
3312 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3314 if (bv_->text->cursor.par()->size()) {
3315 bv_->text->cursorLeft(bv_);
3317 bv_->text->breakParagraph(bv_);
3318 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3321 pair<bool, LyXTextClass::size_type> lres =
3322 textclasslist.NumberOfLayout(buffer_->params
3324 LyXTextClass::size_type lay;
3325 if (lres.first != false) {
3329 // layout not fount using default "Standard" (0)
3333 bv_->text->setLayout(bv_, lay);
3335 bv_->text->setParagraph(bv_, 0, 0,
3337 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3342 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 bv_->text->insertInset(bv_, inset);
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3358 // first check for locking insets
3359 if (bv_->theLockingInset()) {
3360 if (bv_->theLockingInset() == inset) {
3361 if (bv_->text->updateInset(bv_, inset)) {
3364 buffer_->markDirty();
3369 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3370 if (bv_->text->updateInset(bv_,
3371 bv_->theLockingInset())) {
3374 buffer_->markDirty();
3382 // then check the current buffer
3385 update(bv_->text, BufferView::UPDATE);
3386 if (bv_->text->updateInset(bv_, inset)) {
3390 | BufferView::FITCUR
3391 | BufferView::CHANGE);
3393 update(bv_->text, SELECT);
3401 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3404 if (!available()) return;
3407 beforeChange(bv_->text);
3408 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3412 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3413 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3414 if (find(codes.begin(), codes.end(), inset->lyxCode())
3417 static_cast<InsetCommand const *>(inset)->getContents();
3420 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3421 if (bv_->text->cursor.pos()
3422 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3423 LyXCursor tmp = bv_->text->cursor;
3424 bv_->text->cursor.par(bv_->text->firstParagraph());
3425 bv_->text->cursor.pos(0);
3426 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3427 bv_->text->cursor = tmp;
3428 bv_->owner()->message(_("No more insets"));
3431 bv_->owner()->message(_("No more insets"));
3434 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3435 bv_->text->selection.cursor = bv_->text->cursor;
3439 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3441 gotoInset(vector<Inset::Code>(1, code), same_content);