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 "frontends/Alert.h"
32 #include "insets/insetbib.h"
33 #include "insets/insettext.h"
34 /// added for Dispatch functions
36 #include "frontends/FileDialog.h"
38 #include "FloatList.h"
39 #include "support/filetools.h"
40 #include "support/lyxfunctional.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetlatexaccent.h"
43 #include "insets/insettoc.h"
44 #include "insets/insetref.h"
45 #include "insets/insetparent.h"
46 #include "insets/insetindex.h"
47 #include "insets/insetnote.h"
48 #include "insets/insetinclude.h"
49 #include "insets/insetcite.h"
50 #include "insets/insetert.h"
51 #include "insets/insetexternal.h"
52 #include "insets/insetgraphics.h"
53 #include "insets/insetfoot.h"
54 #include "insets/insetmarginal.h"
55 #include "insets/insetminipage.h"
56 #include "insets/insetfloat.h"
57 #include "insets/insettabular.h"
59 #include "insets/insettheorem.h"
60 #include "insets/insetlist.h"
62 #include "insets/insetcaption.h"
63 #include "insets/insetfloatlist.h"
64 #include "insets/insetspecialchar.h"
66 #include "ParagraphParameters.h"
67 #include "undo_funcs.h"
68 #include "mathed/formulabase.h"
70 extern LyXTextClass::size_type current_layout;
81 /* the selection possible is needed, that only motion events are
82 * used, where the bottom press event was on the drawing area too */
83 bool selection_possible = false;
85 extern BufferList bufferlist;
86 extern char ascii_type;
88 extern void sigchldchecker(pid_t pid, int * status);
89 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
94 const unsigned int saved_positions_num = 20;
99 XSync(fl_get_display(), 0);
103 void SetXtermCursor(Window win)
105 static Cursor cursor;
106 static bool cursor_undefined = true;
107 if (cursor_undefined){
108 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
109 XFlush(fl_get_display());
110 cursor_undefined = false;
112 XDefineCursor(fl_get_display(), win, cursor);
113 XFlush(fl_get_display());
119 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
120 int xpos, int ypos, int width, int height)
121 : bv_(b), owner_(o), buffer_(0),
122 current_scrollbar_value(0), cursor_timeout(400),
123 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
127 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
128 workarea_.workAreaExpose
129 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
130 workarea_.workAreaEnter
131 .connect(slot(this, &BufferView::Pimpl::enterView));
132 workarea_.workAreaLeave
133 .connect(slot(this, &BufferView::Pimpl::leaveView));
134 workarea_.workAreaButtonPress
135 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
136 workarea_.workAreaButtonRelease
138 &BufferView::Pimpl::workAreaButtonRelease));
139 workarea_.workAreaMotionNotify
140 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
141 workarea_.workAreaDoubleClick
142 .connect(slot(this, &BufferView::Pimpl::doubleClick));
143 workarea_.workAreaTripleClick
144 .connect(slot(this, &BufferView::Pimpl::tripleClick));
145 workarea_.workAreaKeyPress
146 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
148 cursor_timeout.timeout.connect(slot(this,
149 &BufferView::Pimpl::cursorToggle));
150 cursor_timeout.start();
151 workarea_.setFocus();
152 saved_positions.resize(saved_positions_num);
156 Painter & BufferView::Pimpl::painter()
158 return workarea_.getPainter();
162 void BufferView::Pimpl::buffer(Buffer * b)
164 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
168 buffer_->delUser(bv_);
170 // Put the old text into the TextCache, but
171 // only if the buffer is still loaded.
172 // Also set the owner of the test to 0
173 // bv_->text->owner(0);
174 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
175 if (lyxerr.debugging())
176 textcache.show(lyxerr, "BufferView::buffer");
181 // Set current buffer
184 if (bufferlist.getState() == BufferList::CLOSING) return;
187 // screen is always deleted when the buffer is changed.
190 // If we are closing the buffer, use the first buffer as current
192 buffer_ = bufferlist.first();
196 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
197 buffer_->addUser(bv_);
198 // If we don't have a text object for this, we make one
199 if (bv_->text == 0) {
200 resizeCurrentBuffer();
205 bv_->text->first = screen_->topCursorVisible(bv_->text);
206 owner_->updateMenubar();
207 owner_->updateToolbar();
208 // Similarly, buffer-dependent dialogs should be updated or
209 // hidden. This should go here because some dialogs (eg ToC)
210 // require bv_->text.
211 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_,xpos, ypos,button);
596 bv_->unlockInset(bv_->theLockingInset());
601 selection_possible = true;
602 screen_->hideCursor();
604 int const screen_first = bv_->text->first;
606 // Middle button press pastes if we have a selection
607 bool paste_internally = false;
609 && bv_->text->selection.set()) {
610 owner_->getLyXFunc()->dispatch(LFUN_COPY);
611 paste_internally = true;
614 // Clear the selection
615 screen_->toggleSelection(bv_->text, bv_);
616 bv_->text->clearSelection();
617 bv_->text->fullRebreak(bv_);
619 screen_->update(bv_->text, bv_);
625 // Single left click in math inset?
626 if (isHighlyEditableInset(inset_hit)) {
627 // Highly editable inset, like math
628 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
629 selection_possible = false;
630 owner_->updateLayoutChoice();
631 owner_->message(inset->editMessage());
632 inset->insetButtonPress(bv_, xpos, ypos, button);
633 inset->edit(bv_, xpos, ypos, button);
637 // Right click on a footnote flag opens float menu
639 selection_possible = false;
643 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
644 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
646 bv_->text->selection.cursor = bv_->text->cursor;
647 bv_->text->cursor.x_fix(bv_->text->cursor.x());
649 owner_->updateLayoutChoice();
651 selection_possible = false;
654 // Insert primary selection with middle mouse
655 // if there is a local selection in the current buffer,
658 if (paste_internally)
659 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
661 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
663 selection_possible = false;
669 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
675 LyXText * text = bv_->getLyXText();
677 if (text->bv_owner && bv_->theLockingInset())
680 if (screen_.get() && button == 1) {
681 if (text->bv_owner) {
682 screen_->hideCursor();
683 screen_->toggleSelection(text, bv_);
684 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
685 screen_->toggleSelection(text, bv_, false);
687 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
689 /* This will fit the cursor on the screen
691 update(text, BufferView::SELECT|BufferView::FITCUR);
696 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
702 LyXText * text = bv_->getLyXText();
704 if (text->bv_owner && bv_->theLockingInset())
707 if (screen_.get() && (button == 1)) {
708 screen_->hideCursor();
709 screen_->toggleSelection(text, bv_);
710 text->cursorHome(bv_);
711 text->selection.cursor = text->cursor;
712 text->cursorEnd(bv_);
713 text->setSelection(bv_);
714 screen_->toggleSelection(text, bv_, false);
715 /* This will fit the cursor on the screen
717 update(text, BufferView::SELECT|BufferView::FITCUR);
722 void BufferView::Pimpl::enterView()
724 if (active() && available()) {
725 SetXtermCursor(workarea_.getWin());
726 using_xterm_cursor = true;
731 void BufferView::Pimpl::leaveView()
733 if (using_xterm_cursor) {
734 XUndefineCursor(fl_get_display(), workarea_.getWin());
735 using_xterm_cursor = false;
740 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
743 if (!buffer_ || !screen_.get()) return;
745 // If we hit an inset, we have the inset coordinates in these
746 // and inset_hit points to the inset. If we do not hit an
747 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
748 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
750 if (bv_->theLockingInset()) {
751 // We are in inset locking mode.
753 /* LyX does a kind of work-area grabbing for insets.
754 Only a ButtonPress Event outside the inset will
755 force a insetUnlock. */
756 bv_->theLockingInset()->
757 insetButtonRelease(bv_, x, y, button);
761 selection_possible = false;
769 // Did we hit an editable inset?
771 // Inset like error, notes and figures
772 selection_possible = false;
774 // CHECK fix this proper in 0.13
776 // Following a ref shouldn't issue
777 // a push on the undo-stack
778 // anylonger, now that we have
779 // keybindings for following
780 // references and returning from
781 // references. IMHO though, it
782 // should be the inset's own business
783 // to push or not push on the undo
784 // stack. They don't *have* to
785 // alter the document...
787 // ...or maybe the SetCursorParUndo()
788 // below isn't necessary at all anylonger?
789 if (inset_hit->lyxCode() == Inset::REF_CODE) {
790 setCursorParUndo(bv_);
793 owner_->message(inset_hit->editMessage());
795 if (isHighlyEditableInset(inset_hit)) {
796 // Highly editable inset, like math
797 UpdatableInset *inset = (UpdatableInset *)inset_hit;
798 inset->insetButtonRelease(bv_, x, y, button);
800 inset_hit->insetButtonRelease(bv_, x, y, button);
801 inset_hit->edit(bv_, x, y, button);
807 #warning variable c is set but never used. What is it good for?? (JMarc)
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()->isInset(cursor.pos())
860 && isEditableInset(cursor.par()->getInset(cursor.pos()))) {
862 // Check whether the inset really was hit
863 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
864 LyXFont font = text->getFont(buffer_,
865 cursor.par(), cursor.pos());
866 int const width = tmpinset->width(bv_, font);
867 int const inset_x = font.isVisibleRightToLeft()
868 ? cursor.x() - width : cursor.x();
869 int const start_x = inset_x + tmpinset->scroll();
870 int const end_x = inset_x + width;
872 if (x > start_x && x < end_x
873 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
874 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
875 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
877 // The origin of an inset is on the baseline
878 y = y_tmp - (text->cursor.y());
883 if ((cursor.pos() - 1 >= 0) &&
884 cursor.par()->isInset(cursor.pos() - 1) &&
885 isEditableInset(cursor.par()->getInset(cursor.pos() - 1))) {
886 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
887 LyXFont font = text->getFont(buffer_, cursor.par(),
889 int const width = tmpinset->width(bv_, font);
890 int const inset_x = font.isVisibleRightToLeft()
891 ? cursor.x() : cursor.x() - width;
892 int const start_x = inset_x + tmpinset->scroll();
893 int const end_x = inset_x + width;
895 if (x > start_x && x < end_x
896 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
897 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
899 if (move_cursor && (tmpinset != bv_->theLockingInset()))
901 text->setCursor(bv_, cursor.par(),
902 cursor.pos() - 1, true);
904 // The origin of an inset is on the baseline
905 y = y_tmp - (text->cursor.y());
913 void BufferView::Pimpl::workAreaExpose()
915 static int work_area_width;
916 static unsigned int work_area_height;
918 bool const widthChange = workarea_.workWidth() != work_area_width;
919 bool const heightChange = workarea_.height() != work_area_height;
921 // update from work area
922 work_area_width = workarea_.workWidth();
923 work_area_height = workarea_.height();
926 // The visible LyXView need a resize
929 // Remove all texts from the textcache
930 // This is not _really_ what we want to do. What
931 // we really want to do is to delete in textcache
932 // that does not have a BufferView with matching
933 // width, but as long as we have only one BufferView
934 // deleting all gives the same result.
935 if (lyxerr.debugging())
936 textcache.show(lyxerr, "Expose delete all");
938 } else if (heightChange) {
939 // Rebuild image of current screen
941 // fitCursor() ensures we don't jump back
942 // to the start of the document on vertical
946 // The main window size has changed, repaint most stuff
948 } else if (screen_.get())
949 screen_->redraw(bv_->text, bv_);
951 // Grey box when we don't have a buffer
955 // always make sure that the scrollbar is sane.
957 owner_->updateLayoutChoice();
962 void BufferView::Pimpl::update()
965 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
967 LyXText::text_status st = bv_->text->status();
968 screen_->update(bv_->text, bv_);
970 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
971 if (bv_->text->fullRebreak(bv_)) {
972 st = LyXText::NEED_MORE_REFRESH;
973 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
974 bv_->text->cursor.pos());
977 bv_->text->status(bv_, st);
978 screen_->update(bv_->text, bv_);
980 // do this here instead of in the screen::update because of
982 bv_->text->status(bv_, LyXText::UNCHANGED);
988 // Values used when calling update:
990 // -2 - update, move sel_cursor if selection, fitcursor
991 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
992 // 0 - update, move sel_cursor if selection, fitcursor
993 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
994 // 3 - update, move sel_cursor if selection
997 // a simple redraw of the parts that need refresh
999 // move sel_cursor if selection -
1000 // the text's sel_cursor is moved if there is selection is progress
1003 // fitCursor() is called and the scrollbar updated
1006 // the buffer is marked dirty.
1015 // UPDATE_ONLY = UPDATE;
1016 // UPDATE_SELECT = UPDATE | SELECT;
1017 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1018 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1020 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1021 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1022 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1023 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1024 // update(3) -> update(1) -> update(1) -> update(SELECT)
1026 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1028 owner_->updateLayoutChoice();
1030 if (!text->selection.set() && (f & SELECT)) {
1031 text->selection.cursor = text->cursor;
1034 text->fullRebreak(bv_);
1036 if (text->inset_owner) {
1037 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1038 updateInset(text->inset_owner, false);
1048 buffer_->markDirty();
1053 // Callback for cursor timer
1054 void BufferView::Pimpl::cursorToggle()
1056 // Quite a nice place for asyncron Inset updating, isn't it?
1057 // Actually no! This is run even if no buffer exist... so (Lgb)
1059 cursor_timeout.restart();
1064 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1065 if (pid == -1) // error find out what is wrong
1066 ; // ignore it for now.
1068 sigchldchecker(pid, &status);
1070 updatelist.update(bv_);
1072 if (!screen_.get()) {
1073 cursor_timeout.restart();
1077 if (!bv_->theLockingInset()) {
1078 screen_->cursorToggle(bv_);
1080 bv_->theLockingInset()->toggleInsetCursor(bv_);
1083 cursor_timeout.restart();
1087 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1089 if (!text->cursor.row()->previous())
1092 int y = text->first;
1093 if (text->inset_owner)
1094 y += bv_->text->first;
1095 Row * cursorrow = text->cursor.row();
1096 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1098 // This is to allow jumping over large insets
1099 if ((cursorrow == text->cursor.row()))
1100 text->cursorUp(bv_);
1102 if (text->inset_owner ||
1103 text->cursor.row()->height() < workarea_.height())
1104 screen_->draw(bv_->text, bv_,
1106 - text->cursor.row()->baseline()
1107 + text->cursor.row()->height()
1108 - workarea_.height() + 1 );
1113 void BufferView::Pimpl::cursorNext(LyXText * text)
1115 if (!text->cursor.row()->next())
1118 int y = text->first + workarea_.height();
1119 // if (text->inset_owner)
1120 // y += bv_->text->first;
1121 text->getRowNearY(y);
1123 Row * cursorrow = text->cursor.row();
1124 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1126 // This is to allow jumping over large insets
1127 if ((cursorrow == bv_->text->cursor.row()))
1128 text->cursorDown(bv_);
1130 if (text->inset_owner ||
1131 text->cursor.row()->height() < workarea_.height())
1132 screen_->draw(bv_->text, bv_, text->cursor.y() -
1133 text->cursor.row()->baseline());
1138 bool BufferView::Pimpl::available() const
1140 if (buffer_ && bv_->text) return true;
1145 void BufferView::Pimpl::beforeChange(LyXText * text)
1148 text->clearSelection();
1152 void BufferView::Pimpl::savePosition(unsigned int i)
1154 if (i >= saved_positions_num)
1156 saved_positions[i] = Position(buffer_->fileName(),
1157 bv_->text->cursor.par()->id(),
1158 bv_->text->cursor.pos());
1161 str << _("Saved bookmark") << ' ' << i;
1162 owner_->message(str.str().c_str());
1167 void BufferView::Pimpl::restorePosition(unsigned int i)
1169 if (i >= saved_positions_num)
1172 string const fname = saved_positions[i].filename;
1174 beforeChange(bv_->text);
1176 if (fname != buffer_->fileName()) {
1177 Buffer * b = bufferlist.exists(fname) ?
1178 bufferlist.getBuffer(fname) :
1179 bufferlist.loadLyXFile(fname); // don't ask, just load it
1180 if (b != 0 ) buffer(b);
1183 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1187 bv_->text->setCursor(bv_, par,
1188 min(par->size(), saved_positions[i].par_pos));
1190 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1193 str << _("Moved to bookmark") << ' ' << i;
1194 owner_->message(str.str().c_str());
1199 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1201 if (i >= saved_positions_num)
1204 return !saved_positions[i].filename.empty();
1208 void BufferView::Pimpl::setState()
1210 if (!lyxrc.rtl_support)
1213 LyXText * text = bv_->getLyXText();
1214 if (text->real_current_font.isRightToLeft()) {
1215 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1216 owner_->getIntl()->KeyMapSec();
1218 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1219 owner_->getIntl()->KeyMapPrim();
1224 void BufferView::Pimpl::insetSleep()
1226 if (bv_->theLockingInset() && !inset_slept) {
1227 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1228 bv_->theLockingInset()->insetUnlock(bv_);
1234 void BufferView::Pimpl::insetWakeup()
1236 if (bv_->theLockingInset() && inset_slept) {
1237 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1238 inset_slept = false;
1243 void BufferView::Pimpl::insetUnlock()
1245 if (bv_->theLockingInset()) {
1247 bv_->theLockingInset()->insetUnlock(bv_);
1248 bv_->theLockingInset(0);
1250 inset_slept = false;
1255 bool BufferView::Pimpl::focus() const
1257 return workarea_.hasFocus();
1261 void BufferView::Pimpl::focus(bool f)
1263 if (f) workarea_.setFocus();
1267 bool BufferView::Pimpl::active() const
1269 return workarea_.active();
1273 bool BufferView::Pimpl::belowMouse() const
1275 return workarea_.belowMouse();
1279 void BufferView::Pimpl::showCursor()
1281 if (screen_.get()) {
1282 if (bv_->theLockingInset())
1283 bv_->theLockingInset()->showInsetCursor(bv_);
1285 screen_->showCursor(bv_->text, bv_);
1290 void BufferView::Pimpl::hideCursor()
1292 if (screen_.get()) {
1293 if (!bv_->theLockingInset())
1294 // bv_->theLockingInset()->hideInsetCursor(bv_);
1296 screen_->hideCursor();
1301 void BufferView::Pimpl::toggleSelection(bool b)
1303 if (screen_.get()) {
1304 if (bv_->theLockingInset())
1305 bv_->theLockingInset()->toggleSelection(bv_, b);
1306 screen_->toggleSelection(bv_->text, bv_, b);
1311 void BufferView::Pimpl::toggleToggle()
1314 screen_->toggleToggle(bv_->text, bv_);
1318 void BufferView::Pimpl::center()
1320 beforeChange(bv_->text);
1321 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1322 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1324 screen_->draw(bv_->text, bv_, 0);
1326 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1331 void BufferView::Pimpl::pasteClipboard(bool asPara)
1333 if (!buffer_) return;
1335 screen_->hideCursor();
1336 beforeChange(bv_->text);
1338 string const clip(workarea_.getClipboard());
1340 if (clip.empty()) return;
1343 bv_->text->insertStringAsParagraphs(bv_, clip);
1345 bv_->text->insertStringAsLines(bv_, clip);
1347 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1351 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1353 workarea_.putClipboard(stuff);
1358 * Dispatch functions for actions which can be valid for BufferView->text
1359 * and/or InsetText->text!!!
1364 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1366 LyXText * lt = bv_->getLyXText();
1368 if (selecting || lt->selection.mark()) {
1369 lt->setSelection(bv_);
1373 update(lt, BufferView::SELECT|BufferView::FITCUR);
1376 /* ---> Everytime the cursor is moved, show the current font state. */
1377 // should this too me moved out of this func?
1378 //owner->showState();
1383 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1385 LyXCursor cursor = bv_->getLyXText()->cursor;
1386 Buffer::inset_iterator it =
1387 find_if(Buffer::inset_iterator(
1388 cursor.par(), cursor.pos()),
1389 buffer_->inset_iterator_end(),
1390 lyx::compare_memfun(&Inset::lyxCode, code));
1391 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1395 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1397 string filename = filen;
1399 if (filename.empty()) {
1400 // Launch a file browser
1401 string initpath = lyxrc.document_path;
1404 string const trypath = owner_->buffer()->filepath;
1405 // If directory is writeable, use this as default.
1406 if (IsDirWriteable(trypath))
1410 FileDialog fileDlg(bv_->owner(),
1411 _("Select LyX document to insert"),
1413 make_pair(string(_("Documents")),
1414 string(lyxrc.document_path)),
1415 make_pair(string(_("Examples")),
1416 string(AddPath(system_lyxdir, "examples"))));
1418 FileDialog::Result result =
1419 fileDlg.Select(initpath,
1420 _("*.lyx| LyX Documents (*.lyx)"));
1422 if (result.first == FileDialog::Later)
1425 filename = result.second;
1427 // check selected filename
1428 if (filename.empty()) {
1429 owner_->message(_("Canceled."));
1434 // get absolute path of file and add ".lyx" to the filename if
1436 filename = FileSearch(string(), filename, "lyx");
1438 string const disp_fn(MakeDisplayPath(filename));
1441 s1 << _("Inserting document") << ' '
1442 << disp_fn << " ...";
1443 owner_->message(s1.str().c_str());
1444 bool const res = bv_->insertLyXFile(filename);
1447 str << _("Document") << ' ' << disp_fn
1448 << ' ' << _("inserted.");
1449 owner_->message(str.str().c_str());
1452 str << _("Could not insert document") << ' '
1454 owner_->message(str.str().c_str());
1459 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1461 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1462 << action <<"] arg[" << argument << "]" << endl;
1465 // --- Misc -------------------------------------------
1469 LyXText * lt = bv_->getLyXText();
1470 lt->toggleAppendix(bv_);
1473 | BufferView::FITCUR
1474 | BufferView::CHANGE);
1479 case LFUN_TOC_INSERT:
1481 InsetCommandParams p;
1482 p.setCmdName("tableofcontents");
1483 Inset * inset = new InsetTOC(p);
1484 if (!insertInset(inset, "Standard"))
1489 case LFUN_TABULAR_FEATURE:
1490 case LFUN_SCROLL_INSET:
1491 // this is not handled here as this funktion is only aktive
1492 // if we have a locking_inset and that one is (or contains)
1496 case LFUN_INSET_GRAPHICS:
1498 Inset * new_inset = new InsetGraphics;
1499 if (!insertInset(new_inset)) {
1502 // this is need because you don't use a inset->Edit()
1503 updateInset(new_inset, true);
1504 new_inset->edit(bv_);
1514 case LFUN_PASTESELECTION:
1516 bool asPara = false;
1517 if (argument == "paragraph") asPara = true;
1518 pasteClipboard(asPara);
1530 case LFUN_LAYOUT_COPY:
1531 bv_->copyEnvironment();
1534 case LFUN_LAYOUT_PASTE:
1535 bv_->pasteEnvironment();
1539 case LFUN_GOTOERROR:
1540 gotoInset(Inset::ERROR_CODE, false);
1544 gotoInset(Inset::IGNORE_CODE, false);
1547 case LFUN_REFERENCE_GOTO:
1549 vector<Inset::Code> tmp;
1550 tmp.push_back(Inset::LABEL_CODE);
1551 tmp.push_back(Inset::REF_CODE);
1552 gotoInset(tmp, true);
1556 case LFUN_HYPHENATION:
1557 specialChar(InsetSpecialChar::HYPHENATION);
1560 case LFUN_LIGATURE_BREAK:
1561 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1565 specialChar(InsetSpecialChar::LDOTS);
1568 case LFUN_END_OF_SENTENCE:
1569 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1572 case LFUN_MENU_SEPARATOR:
1573 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1581 changeDepth(bv_, bv_->getLyXText(), 0);
1584 case LFUN_DEPTH_MIN:
1585 changeDepth(bv_, bv_->getLyXText(), -1);
1588 case LFUN_DEPTH_PLUS:
1589 changeDepth(bv_, bv_->getLyXText(), 1);
1593 owner_->getDialogs()->setUserFreeFont();
1596 case LFUN_FILE_INSERT:
1598 MenuInsertLyXFile(argument);
1602 case LFUN_FILE_INSERT_ASCII_PARA:
1603 InsertAsciiFile(bv_, argument, true);
1606 case LFUN_FILE_INSERT_ASCII:
1607 InsertAsciiFile(bv_, argument, false);
1612 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1613 << argument << endl;
1615 // Derive layout number from given argument (string)
1616 // and current buffer's textclass (number). */
1617 LyXTextClassList::ClassList::size_type tclass =
1618 buffer_->params.textclass;
1619 pair <bool, LyXTextClass::size_type> layout =
1620 textclasslist.NumberOfLayout(tclass, argument);
1622 // If the entry is obsolete, use the new one instead.
1624 string obs = textclasslist.Style(tclass,layout.second)
1628 textclasslist.NumberOfLayout(tclass, obs);
1631 // see if we found the layout number:
1632 if (!layout.first) {
1633 owner_->getLyXFunc()->setErrorMessage(
1634 string(N_("Layout ")) + argument +
1639 if (current_layout != layout.second) {
1640 LyXText * lt = bv_->getLyXText();
1642 current_layout = layout.second;
1645 | BufferView::FITCUR);
1646 lt->setLayout(bv_, layout.second);
1647 owner_->setLayout(layout.second);
1650 | BufferView::FITCUR
1651 | BufferView::CHANGE);
1658 lang(bv_, argument);
1660 owner_->showState();
1665 owner_->showState();
1670 owner_->showState();
1675 owner_->showState();
1680 owner_->showState();
1685 owner_->showState();
1690 owner_->showState();
1695 owner_->showState();
1698 case LFUN_UNDERLINE:
1700 owner_->showState();
1703 case LFUN_FONT_SIZE:
1704 fontSize(bv_, argument);
1705 owner_->showState();
1708 case LFUN_FONT_STATE:
1709 owner_->getLyXFunc()->setMessage(currentState(bv_));
1712 case LFUN_UPCASE_WORD:
1714 LyXText * lt = bv_->getLyXText();
1718 | BufferView::FITCUR);
1719 lt->changeCase(bv_, LyXText::text_uppercase);
1720 if (lt->inset_owner)
1721 updateInset(lt->inset_owner, true);
1724 | BufferView::FITCUR
1725 | BufferView::CHANGE);
1729 case LFUN_LOWCASE_WORD:
1731 LyXText * lt = bv_->getLyXText();
1733 update(lt, BufferView::SELECT|BufferView::FITCUR);
1734 lt->changeCase(bv_, LyXText::text_lowercase);
1735 if (lt->inset_owner)
1736 updateInset(lt->inset_owner, true);
1739 | BufferView::FITCUR
1740 | BufferView::CHANGE);
1744 case LFUN_CAPITALIZE_WORD:
1746 LyXText * lt = bv_->getLyXText();
1748 update(lt, BufferView::SELECT|BufferView::FITCUR);
1749 lt->changeCase(bv_, LyXText::text_capitalization);
1750 if (lt->inset_owner)
1751 updateInset(lt->inset_owner, true);
1754 | BufferView::FITCUR
1755 | BufferView::CHANGE);
1759 case LFUN_TRANSPOSE_CHARS:
1761 LyXText * lt = bv_->getLyXText();
1763 update(lt, BufferView::SELECT|BufferView::FITCUR);
1764 lt->transposeChars(*bv_);
1765 if (lt->inset_owner)
1766 updateInset(lt->inset_owner, true);
1769 | BufferView::FITCUR
1770 | BufferView::CHANGE);
1775 case LFUN_INSERT_LABEL:
1776 MenuInsertLabel(bv_, argument);
1779 case LFUN_REF_INSERT:
1780 if (argument.empty()) {
1781 InsetCommandParams p("ref");
1782 owner_->getDialogs()->createRef(p.getAsString());
1784 InsetCommandParams p;
1785 p.setFromString(argument);
1787 InsetRef * inset = new InsetRef(p, *buffer_);
1788 if (!insertInset(inset))
1791 updateInset(inset, true);
1795 case LFUN_BOOKMARK_SAVE:
1796 savePosition(strToUnsignedInt(argument));
1799 case LFUN_BOOKMARK_GOTO:
1800 restorePosition(strToUnsignedInt(argument));
1805 string label(argument);
1806 if (label.empty()) {
1808 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1810 label = inset->getContents();
1815 if (!label.empty()) {
1816 //bv_->savePosition(0);
1817 if (!bv_->gotoLabel(label))
1818 Alert::alert(_("Error"),
1819 _("Couldn't find this label"),
1820 _("in current document."));
1825 // --- Cursor Movements -----------------------------
1828 LyXText * lt = bv_->getLyXText();
1830 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1831 if (!lt->selection.mark())
1833 update(lt, BufferView::SELECT|BufferView::FITCUR);
1835 lt->cursorLeft(bv_, false);
1836 if (lt->cursor.pos() < lt->cursor.par()->size()
1837 && lt->cursor.par()->isInset(lt->cursor.pos())
1838 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1839 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1840 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1842 tmpinset->edit(bv_, false);
1844 tmpinset->edit(bv_);
1848 lt->cursorRight(bv_, false);
1850 moveCursorUpdate(false);
1851 owner_->showState();
1857 // This is soooo ugly. Isn`t it possible to make
1858 // it simpler? (Lgb)
1859 LyXText * lt = bv_->getLyXText();
1860 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1861 if (!lt->selection.mark())
1863 update(lt, BufferView::SELECT|BufferView::FITCUR);
1864 LyXCursor const cur = lt->cursor;
1866 lt->cursorLeft(bv_, false);
1867 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1868 lt->cursor.pos() < lt->cursor.par()->size() &&
1869 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1870 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1871 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1872 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1874 tmpinset->edit(bv_);
1876 tmpinset->edit(bv_, false);
1880 lt->cursorRight(bv_, false);
1883 moveCursorUpdate(false);
1884 owner_->showState();
1890 LyXText * lt = bv_->getLyXText();
1892 if (!lt->selection.mark())
1894 update(lt, BufferView::UPDATE);
1897 moveCursorUpdate(false);
1898 owner_->showState();
1904 LyXText * lt = bv_->getLyXText();
1906 if (!lt->selection.mark())
1908 update(lt, BufferView::UPDATE);
1909 lt->cursorDown(bv_);
1911 moveCursorUpdate(false);
1912 owner_->showState();
1916 case LFUN_UP_PARAGRAPH:
1918 LyXText * lt = bv_->getLyXText();
1920 if (!lt->selection.mark())
1922 update(lt, BufferView::UPDATE);
1923 lt->cursorUpParagraph(bv_);
1925 moveCursorUpdate(false);
1926 owner_->showState();
1930 case LFUN_DOWN_PARAGRAPH:
1932 LyXText * lt = bv_->getLyXText();
1934 if (!lt->selection.mark())
1936 update(lt, BufferView::UPDATE);
1937 lt->cursorDownParagraph(bv_);
1939 moveCursorUpdate(false);
1940 owner_->showState();
1946 LyXText * lt = bv_->getLyXText();
1948 if (!lt->selection.mark())
1950 update(lt, BufferView::UPDATE);
1953 moveCursorUpdate(false);
1954 owner_->showState();
1960 LyXText * lt = bv_->getLyXText();
1962 if (!lt->selection.mark())
1964 update(lt, BufferView::UPDATE);
1967 moveCursorUpdate(false);
1968 owner_->showState();
1974 LyXText * lt = bv_->getLyXText();
1976 if (!lt->selection.mark())
1978 update(lt, BufferView::SELECT|BufferView::FITCUR);
1979 lt->cursorHome(bv_);
1981 moveCursorUpdate(false);
1982 owner_->showState();
1988 LyXText * lt = bv_->getLyXText();
1990 if (!lt->selection.mark())
1993 BufferView::SELECT|BufferView::FITCUR);
1996 moveCursorUpdate(false);
1997 owner_->showState();
2001 case LFUN_SHIFT_TAB:
2004 LyXText * lt = bv_->getLyXText();
2006 if (!lt->selection.mark())
2009 BufferView::SELECT|BufferView::FITCUR);
2012 moveCursorUpdate(false);
2013 owner_->showState();
2017 case LFUN_WORDRIGHT:
2019 LyXText * lt = bv_->getLyXText();
2021 if (!lt->selection.mark())
2023 update(lt, BufferView::SELECT|BufferView::FITCUR);
2024 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2025 lt->cursorLeftOneWord(bv_);
2027 lt->cursorRightOneWord(bv_);
2029 moveCursorUpdate(false);
2030 owner_->showState();
2036 LyXText * lt = bv_->getLyXText();
2038 if (!lt->selection.mark())
2040 update(lt, BufferView::SELECT|BufferView::FITCUR);
2041 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2042 lt->cursorRightOneWord(bv_);
2044 lt->cursorLeftOneWord(bv_);
2046 moveCursorUpdate(false);
2047 owner_->showState();
2051 case LFUN_BEGINNINGBUF:
2053 LyXText * lt = bv_->getLyXText();
2055 if (!lt->selection.mark())
2058 BufferView::SELECT|BufferView::FITCUR);
2061 moveCursorUpdate(false);
2062 owner_->showState();
2068 LyXText * lt = bv_->getLyXText();
2070 if (!lt->selection.mark())
2073 BufferView::SELECT|BufferView::FITCUR);
2074 lt->cursorBottom(bv_);
2076 moveCursorUpdate(false);
2077 owner_->showState();
2081 /* cursor selection ---------------------------- */
2084 LyXText * lt = bv_->getLyXText();
2087 BufferView::SELECT|BufferView::FITCUR);
2088 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2089 lt->cursorLeft(bv_);
2091 lt->cursorRight(bv_);
2093 moveCursorUpdate(true);
2094 owner_->showState();
2100 LyXText * lt = bv_->getLyXText();
2103 BufferView::SELECT|BufferView::FITCUR);
2104 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2105 lt->cursorRight(bv_);
2107 lt->cursorLeft(bv_);
2109 moveCursorUpdate(true);
2110 owner_->showState();
2116 LyXText * lt = bv_->getLyXText();
2119 BufferView::SELECT|BufferView::FITCUR);
2122 moveCursorUpdate(true);
2123 owner_->showState();
2129 LyXText * lt = bv_->getLyXText();
2132 BufferView::SELECT|BufferView::FITCUR);
2133 lt->cursorDown(bv_);
2135 moveCursorUpdate(true);
2136 owner_->showState();
2140 case LFUN_UP_PARAGRAPHSEL:
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 lt->cursorUpParagraph(bv_);
2148 moveCursorUpdate(true);
2149 owner_->showState();
2153 case LFUN_DOWN_PARAGRAPHSEL:
2155 LyXText * lt = bv_->getLyXText();
2158 BufferView::SELECT|BufferView::FITCUR);
2159 lt->cursorDownParagraph(bv_);
2161 moveCursorUpdate(true);
2162 owner_->showState();
2168 LyXText * lt = bv_->getLyXText();
2170 update(lt, BufferView::SELECT|BufferView::FITCUR);
2173 moveCursorUpdate(true);
2174 owner_->showState();
2180 LyXText * lt = bv_->getLyXText();
2182 update(lt, BufferView::SELECT|BufferView::FITCUR);
2185 moveCursorUpdate(true);
2186 owner_->showState();
2192 LyXText * lt = bv_->getLyXText();
2194 update(lt, BufferView::SELECT|BufferView::FITCUR);
2195 lt->cursorHome(bv_);
2197 moveCursorUpdate(true);
2198 owner_->showState();
2204 LyXText * lt = bv_->getLyXText();
2206 update(lt, BufferView::SELECT|BufferView::FITCUR);
2209 moveCursorUpdate(true);
2210 owner_->showState();
2214 case LFUN_WORDRIGHTSEL:
2216 LyXText * lt = bv_->getLyXText();
2218 update(lt, BufferView::SELECT|BufferView::FITCUR);
2219 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2220 lt->cursorLeftOneWord(bv_);
2222 lt->cursorRightOneWord(bv_);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2229 case LFUN_WORDLEFTSEL:
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2235 lt->cursorRightOneWord(bv_);
2237 lt->cursorLeftOneWord(bv_);
2239 moveCursorUpdate(true);
2240 owner_->showState();
2244 case LFUN_BEGINNINGBUFSEL:
2246 LyXText * lt = bv_->getLyXText();
2248 if (lt->inset_owner)
2250 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 moveCursorUpdate(true);
2254 owner_->showState();
2258 case LFUN_ENDBUFSEL:
2260 LyXText * lt = bv_->getLyXText();
2262 if (lt->inset_owner)
2265 BufferView::SELECT|BufferView::FITCUR);
2266 lt->cursorBottom(bv_);
2268 moveCursorUpdate(true);
2269 owner_->showState();
2273 // --- text changing commands ------------------------
2274 case LFUN_BREAKLINE:
2276 LyXText * lt = bv_->getLyXText();
2279 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2282 | BufferView::FITCUR
2283 | BufferView::CHANGE);
2284 moveCursorUpdate(false);
2288 case LFUN_PROTECTEDSPACE:
2290 LyXText * lt = bv_->getLyXText();
2292 LyXLayout const & style = textclasslist
2293 .Style(buffer_->params.textclass,
2294 lt->cursor.par()->getLayout());
2296 if (style.free_spacing) {
2297 lt->insertChar(bv_, ' ');
2300 | BufferView::FITCUR
2301 | BufferView::CHANGE);
2305 moveCursorUpdate(false);
2311 LyXText * lt = bv_->getLyXText();
2313 if (lt->selection.mark()) {
2317 | BufferView::FITCUR);
2318 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2321 lt->selection.mark(true);
2324 | BufferView::FITCUR);
2325 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2327 lt->selection.cursor = lt->cursor;
2333 LyXText * lt = bv_->getLyXText();
2335 if (!lt->selection.set()) {
2337 lt->selection.cursor = lt->cursor;
2340 | BufferView::FITCUR
2341 | BufferView::CHANGE);
2342 // It is possible to make it a lot faster still
2343 // just comment out the line below...
2348 moveCursorUpdate(false);
2349 owner_->showState();
2354 case LFUN_DELETE_SKIP:
2356 LyXText * lt = bv_->getLyXText();
2358 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2360 LyXCursor cursor = lt->cursor;
2362 if (!lt->selection.set()) {
2363 if (cursor.pos() == cursor.par()->size()) {
2364 lt->cursorRight(bv_);
2365 cursor = lt->cursor;
2366 if (cursor.pos() == 0
2367 && !(cursor.par()->params().spaceTop()
2368 == VSpace (VSpace::NONE))) {
2371 cursor.par()->params().lineTop(),
2372 cursor.par()->params().lineBottom(),
2373 cursor.par()->params().pagebreakTop(),
2374 cursor.par()->params().pagebreakBottom(),
2375 VSpace(VSpace::NONE),
2376 cursor.par()->params().spaceBottom(),
2377 cursor.par()->params().spacing(),
2378 cursor.par()->params().align(),
2379 cursor.par()->params().labelWidthString(), 0);
2380 lt->cursorLeft(bv_);
2383 | BufferView::FITCUR
2384 | BufferView::CHANGE);
2386 lt->cursorLeft(bv_);
2388 lt->selection.cursor = lt->cursor;
2391 | BufferView::FITCUR
2392 | BufferView::CHANGE);
2396 lt->selection.cursor = lt->cursor;
2399 | BufferView::FITCUR
2400 | BufferView::CHANGE);
2408 /* -------> Delete word forward. */
2409 case LFUN_DELETE_WORD_FORWARD:
2410 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2411 bv_->getLyXText()->deleteWordForward(bv_);
2412 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2413 moveCursorUpdate(false);
2414 owner_->showState();
2417 /* -------> Delete word backward. */
2418 case LFUN_DELETE_WORD_BACKWARD:
2420 LyXText * lt = bv_->getLyXText();
2422 update(lt, BufferView::SELECT|BufferView::FITCUR);
2423 lt->deleteWordBackward(bv_);
2426 | BufferView::FITCUR
2427 | BufferView::CHANGE);
2428 moveCursorUpdate(false);
2429 owner_->showState();
2433 /* -------> Kill to end of line. */
2434 case LFUN_DELETE_LINE_FORWARD:
2436 LyXText * lt = bv_->getLyXText();
2438 update(lt, BufferView::SELECT|BufferView::FITCUR);
2439 lt->deleteLineForward(bv_);
2442 | BufferView::FITCUR
2443 | BufferView::CHANGE);
2444 moveCursorUpdate(false);
2448 /* -------> Set mark off. */
2451 LyXText * lt = bv_->getLyXText();
2454 update(lt, BufferView::SELECT|BufferView::FITCUR);
2455 lt->selection.cursor = lt->cursor;
2456 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2460 /* -------> Set mark on. */
2463 LyXText * lt = bv_->getLyXText();
2466 lt->selection.mark(true);
2467 update(lt, BufferView::SELECT|BufferView::FITCUR);
2468 lt->selection.cursor = lt->cursor;
2469 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2473 case LFUN_BACKSPACE:
2475 LyXText * lt = bv_->getLyXText();
2477 if (!lt->selection.set()) {
2478 if (owner_->getIntl()->getTrans().backspace()) {
2480 lt->selection.cursor = lt->cursor;
2483 | BufferView::FITCUR
2484 | BufferView::CHANGE);
2485 // It is possible to make it a lot faster still
2486 // just comment out the line below...
2492 owner_->showState();
2497 case LFUN_BACKSPACE_SKIP:
2499 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2500 LyXText * lt = bv_->getLyXText();
2502 LyXCursor cursor = lt->cursor;
2504 if (!lt->selection.set()) {
2505 if (cursor.pos() == 0
2506 && !(cursor.par()->params().spaceTop()
2507 == VSpace (VSpace::NONE))) {
2510 cursor.par()->params().lineTop(),
2511 cursor.par()->params().lineBottom(),
2512 cursor.par()->params().pagebreakTop(),
2513 cursor.par()->params().pagebreakBottom(),
2514 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2515 cursor.par()->params().spacing(),
2516 cursor.par()->params().align(),
2517 cursor.par()->params().labelWidthString(), 0);
2520 | BufferView::FITCUR
2521 | BufferView::CHANGE);
2524 lt->selection.cursor = cursor;
2527 | BufferView::FITCUR
2528 | BufferView::CHANGE);
2535 case LFUN_BREAKPARAGRAPH:
2537 LyXText * lt = bv_->getLyXText();
2540 lt->breakParagraph(bv_, 0);
2543 | BufferView::FITCUR
2544 | BufferView::CHANGE);
2545 lt->selection.cursor = lt->cursor;
2547 owner_->showState();
2551 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2553 LyXText * lt = bv_->getLyXText();
2556 lt->breakParagraph(bv_, 1);
2559 | BufferView::FITCUR
2560 | BufferView::CHANGE);
2561 lt->selection.cursor = lt->cursor;
2563 owner_->showState();
2567 case LFUN_BREAKPARAGRAPH_SKIP:
2569 // When at the beginning of a paragraph, remove
2570 // indentation and add a "defskip" at the top.
2571 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2572 LyXText * lt = bv_->getLyXText();
2574 LyXCursor cursor = lt->cursor;
2577 if (cursor.pos() == 0) {
2578 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2581 cursor.par()->params().lineTop(),
2582 cursor.par()->params().lineBottom(),
2583 cursor.par()->params().pagebreakTop(),
2584 cursor.par()->params().pagebreakBottom(),
2585 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2586 cursor.par()->params().spacing(),
2587 cursor.par()->params().align(),
2588 cursor.par()->params().labelWidthString(), 1);
2589 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2593 lt->breakParagraph(bv_, 0);
2594 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2599 | BufferView::FITCUR
2600 | BufferView::CHANGE);
2601 lt->selection.cursor = cursor;
2603 owner_->showState();
2607 case LFUN_PARAGRAPH_SPACING:
2609 LyXText * lt = bv_->getLyXText();
2611 Paragraph * par = lt->cursor.par();
2612 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2613 float cur_value = 1.0;
2614 if (cur_spacing == Spacing::Other) {
2615 cur_value = par->params().spacing().getValue();
2618 istringstream istr(argument.c_str());
2622 Spacing::Space new_spacing = cur_spacing;
2623 float new_value = cur_value;
2625 lyxerr << "Missing argument to `paragraph-spacing'"
2627 } else if (tmp == "single") {
2628 new_spacing = Spacing::Single;
2629 } else if (tmp == "onehalf") {
2630 new_spacing = Spacing::Onehalf;
2631 } else if (tmp == "double") {
2632 new_spacing = Spacing::Double;
2633 } else if (tmp == "other") {
2634 new_spacing = Spacing::Other;
2637 lyxerr << "new_value = " << tmpval << endl;
2640 } else if (tmp == "default") {
2641 new_spacing = Spacing::Default;
2643 lyxerr << _("Unknown spacing argument: ")
2644 << argument << endl;
2646 if (cur_spacing != new_spacing || cur_value != new_value) {
2647 par->params().spacing(Spacing(new_spacing, new_value));
2648 lt->redoParagraph(bv_);
2651 | BufferView::FITCUR
2652 | BufferView::CHANGE);
2657 case LFUN_INSET_TOGGLE:
2659 LyXText * lt = bv_->getLyXText();
2662 update(lt, BufferView::SELECT|BufferView::FITCUR);
2663 lt->toggleInset(bv_);
2664 update(lt, BufferView::SELECT|BufferView::FITCUR);
2676 InsetCommandParams p;
2677 if (action == LFUN_HTMLURL)
2678 p.setCmdName("htmlurl");
2680 p.setCmdName("url");
2681 owner_->getDialogs()->createUrl(p.getAsString());
2685 case LFUN_INSERT_URL:
2687 InsetCommandParams p;
2688 p.setFromString(argument);
2690 InsetUrl * inset = new InsetUrl(p);
2691 if (!insertInset(inset))
2694 updateInset(inset, true);
2698 case LFUN_INSET_TEXT:
2699 insertAndEditInset(new InsetText);
2702 case LFUN_INSET_ERT:
2703 insertAndEditInset(new InsetERT);
2706 case LFUN_INSET_EXTERNAL:
2707 insertAndEditInset(new InsetExternal);
2710 case LFUN_INSET_FOOTNOTE:
2711 insertAndEditInset(new InsetFoot);
2714 case LFUN_INSET_MARGINAL:
2715 insertAndEditInset(new InsetMarginal);
2718 case LFUN_INSET_MINIPAGE:
2719 insertAndEditInset(new InsetMinipage);
2722 case LFUN_INSERT_NOTE:
2723 insertAndEditInset(new InsetNote);
2726 case LFUN_INSET_FLOAT:
2727 // check if the float type exist
2728 if (floatList.typeExist(argument)) {
2729 insertAndEditInset(new InsetFloat(argument));
2731 lyxerr << "Non-existent float type: "
2732 << argument << endl;
2736 case LFUN_INSET_WIDE_FLOAT:
2738 // check if the float type exist
2739 if (floatList.typeExist(argument)) {
2740 InsetFloat * new_inset = new InsetFloat(argument);
2741 new_inset->wide(true);
2742 if (insertInset(new_inset))
2743 new_inset->edit(bv_);
2747 lyxerr << "Non-existent float type: "
2748 << argument << endl;
2755 case LFUN_INSET_LIST:
2756 insertAndEditInset(new InsetList);
2759 case LFUN_INSET_THEOREM:
2760 insertAndEditInset(new InsetTheorem);
2764 case LFUN_INSET_CAPTION:
2766 // Do we have a locking inset...
2767 if (bv_->theLockingInset()) {
2768 lyxerr << "Locking inset code: "
2769 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2770 InsetCaption * new_inset = new InsetCaption;
2771 new_inset->setOwner(bv_->theLockingInset());
2772 new_inset->setAutoBreakRows(true);
2773 new_inset->setDrawFrame(0, InsetText::LOCKED);
2774 new_inset->setFrameColor(0, LColor::captionframe);
2775 if (insertInset(new_inset))
2776 new_inset->edit(bv_);
2783 case LFUN_INSET_TABULAR:
2787 if (!argument.empty())
2788 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2789 InsetTabular * new_inset =
2790 new InsetTabular(*buffer_, r, c);
2792 bv_->getLyXText()->real_current_font.isRightToLeft();
2793 if (!open_new_inset(new_inset, rtl))
2798 // --- lyxserver commands ----------------------------
2800 case LFUN_CHARATCURSOR:
2802 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2803 if (pos < bv_->getLyXText()->cursor.par()->size())
2804 owner_->getLyXFunc()->setMessage(
2805 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2807 owner_->getLyXFunc()->setMessage("EOF");
2812 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2814 + tostr(bv_->getLyXText()->cursor.y()));
2821 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2822 lyxerr << "SETXY: Could not parse coordinates in '"
2823 << argument << std::endl;
2825 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2829 case LFUN_GETLAYOUT:
2830 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2835 LyXFont & font = bv_->getLyXText()->current_font;
2836 if (font.shape() == LyXFont::ITALIC_SHAPE)
2837 owner_->getLyXFunc()->setMessage("E");
2838 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2839 owner_->getLyXFunc()->setMessage("N");
2841 owner_->getLyXFunc()->setMessage("0");
2846 // --- accented characters ---------------------------
2849 case LFUN_CIRCUMFLEX:
2859 case LFUN_SPECIAL_CARON:
2862 case LFUN_HUNG_UMLAUT:
2865 if (argument.empty()) {
2867 owner_->getLyXFunc()->handleKeyFunc(action);
2869 owner_->getLyXFunc()->handleKeyFunc(action);
2870 owner_->getIntl()->getTrans()
2871 .TranslateAndInsert(argument[0], bv_->getLyXText());
2872 update(bv_->getLyXText(),
2874 | BufferView::FITCUR
2875 | BufferView::CHANGE);
2879 case LFUN_MATH_MACRO:
2880 mathDispatchMathMacro(bv_, argument);
2883 case LFUN_MATH_DELIM:
2884 mathDispatchMathDelim(bv_, argument);
2887 case LFUN_INSERT_MATRIX:
2888 mathDispatchInsertMatrix(bv_, argument);
2891 case LFUN_INSERT_MATH:
2892 mathDispatchInsertMath(bv_, argument);
2895 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2896 mathDispatchMathImportSelection(bv_, argument);
2899 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2900 mathDispatchMathDisplay(bv_, argument);
2903 case LFUN_MATH_MODE: // Open or create an inlined math inset
2904 mathDispatchMathMode(bv_, argument);
2907 case LFUN_GREEK: // Insert a single greek letter
2908 mathDispatchGreek(bv_, argument);
2911 case LFUN_CITATION_INSERT:
2913 InsetCommandParams p;
2914 p.setFromString( argument );
2916 InsetCitation * inset = new InsetCitation( p );
2917 if (!insertInset(inset))
2920 updateInset( inset, true );
2924 case LFUN_INSERT_BIBTEX:
2926 // ale970405+lasgoutt970425
2927 // The argument can be up to two tokens separated
2928 // by a space. The first one is the bibstyle.
2929 string const db = token(argument, ' ', 0);
2930 string const bibstyle = token(argument, ' ', 1);
2932 InsetCommandParams p( "BibTeX", db, bibstyle );
2933 InsetBibtex * inset = new InsetBibtex(p);
2935 if (insertInset(inset)) {
2936 if (argument.empty())
2943 // BibTeX data bases
2944 case LFUN_BIBDB_ADD:
2946 InsetBibtex * inset =
2947 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2949 inset->addDatabase(argument);
2954 case LFUN_BIBDB_DEL:
2956 InsetBibtex * inset =
2957 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2959 inset->delDatabase(argument);
2964 case LFUN_BIBTEX_STYLE:
2966 InsetBibtex * inset =
2967 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2969 inset->setOptions(argument);
2974 case LFUN_INDEX_CREATE:
2976 InsetCommandParams p("index");
2977 if (argument.empty()) {
2978 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2979 p.setContents(idxstring);
2981 p.setContents(argument);
2984 owner_->getDialogs()->createIndex(p.getAsString());
2988 case LFUN_INDEX_INSERT:
2990 InsetCommandParams p;
2991 p.setFromString(argument);
2992 InsetIndex * inset = new InsetIndex(p);
2994 if (!insertInset(inset))
2997 updateInset(inset, true);
3001 case LFUN_INDEX_INSERT_LAST:
3003 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3004 if (!idxstring.empty()) {
3005 owner_->message(_("Word `")
3006 + idxstring + _(("' indexed.")));
3007 InsetCommandParams p("index", idxstring);
3008 InsetIndex * inset = new InsetIndex(p);
3010 if (!insertInset(inset))
3013 updateInset(inset, true);
3018 case LFUN_INDEX_PRINT:
3020 InsetCommandParams p("printindex");
3021 Inset * inset = new InsetPrintIndex(p);
3022 if (!insertInset(inset, "Standard"))
3027 case LFUN_PARENTINSERT:
3029 lyxerr << "arg " << argument << endl;
3030 InsetCommandParams p( "lyxparent", argument );
3031 Inset * inset = new InsetParent(p, *buffer_);
3032 if (!insertInset(inset, "Standard"))
3038 case LFUN_CHILD_INSERT:
3040 InsetInclude::Params p;
3041 p.cparams.setFromString(argument);
3042 p.masterFilename_ = buffer_->fileName();
3044 InsetInclude * inset = new InsetInclude(p);
3045 if (!insertInset(inset))
3048 updateInset(inset, true);
3049 bv_->owner()->getDialogs()->showInclude(inset);
3054 case LFUN_FLOAT_LIST:
3056 // We should check the argument for validity. (Lgb)
3057 Inset * inset = new InsetFloatList(argument);
3058 if (!insertInset(inset, "Standard"))
3063 case LFUN_THESAURUS_ENTRY:
3065 string arg = argument;
3068 arg = bv_->getLyXText()->selectionAsString(buffer_,
3072 if (arg.size() > 100 || arg.empty()) {
3073 // Get word or selection
3074 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3075 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3076 // FIXME: where is getLyXText()->unselect(bv_) ?
3080 bv_->owner()->getDialogs()->showThesaurus(arg);
3084 case LFUN_SELFINSERT:
3086 if (argument.empty()) break;
3088 /* Automatically delete the currently selected
3089 * text and replace it with what is being
3090 * typed in now. Depends on lyxrc settings
3091 * "auto_region_delete", which defaults to
3094 LyXText * lt = bv_->getLyXText();
3096 if (lyxrc.auto_region_delete) {
3097 if (lt->selection.set()) {
3098 lt->cutSelection(bv_, false, false);
3101 | BufferView::FITCUR
3102 | BufferView::CHANGE);
3107 LyXFont const old_font(lt->real_current_font);
3109 string::const_iterator cit = argument.begin();
3110 string::const_iterator end = argument.end();
3111 for (; cit != end; ++cit) {
3112 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3117 | BufferView::FITCUR
3118 | BufferView::CHANGE);
3120 lt->selection.cursor = lt->cursor;
3121 moveCursorUpdate(false);
3123 // real_current_font.number can change so we need to
3124 // update the minibuffer
3125 if (old_font != lt->real_current_font)
3126 owner_->showState();
3131 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3133 time_t now_time_t = time(NULL);
3134 struct tm * now_tm = localtime(&now_time_t);
3135 setlocale(LC_TIME, "");
3137 if (!argument.empty())
3140 arg = lyxrc.date_insert_format;
3142 int const datetmp_len =
3143 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3145 LyXText * lt = bv_->getLyXText();
3147 for (int i = 0; i < datetmp_len; i++) {
3148 lt->insertChar(bv_, datetmp[i]);
3151 | BufferView::FITCUR
3152 | BufferView::CHANGE);
3155 lt->selection.cursor = lt->cursor;
3156 moveCursorUpdate(false);
3160 case LFUN_UNKNOWN_ACTION:
3161 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3172 void BufferView::Pimpl::newline()
3175 LyXText * lt = bv_->getLyXText();
3179 | BufferView::FITCUR);
3180 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3183 | BufferView::FITCUR
3184 | BufferView::CHANGE);
3189 void BufferView::Pimpl::hfill()
3192 LyXText * lt = bv_->getLyXText();
3196 | BufferView::FITCUR);
3197 lt->insertChar(bv_, Paragraph::META_HFILL);
3200 | BufferView::FITCUR
3201 | BufferView::CHANGE);
3206 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3210 update(lt, BufferView::SELECT|BufferView::FITCUR);
3211 InsetSpecialChar * new_inset =
3212 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3213 #ifdef WITH_WARNINGS
3214 #warning Why is this code different from specialChar() below? (JMarc)
3215 // the code in specialChar is a generic version of what used to exist
3216 // for other special chars. I did not merge this case because of the
3217 // call to updateInset(), but what does it do?
3219 if (!insertInset(new_inset))
3222 updateInset(new_inset, true);
3227 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3230 LyXText * lt = bv_->getLyXText();
3233 update(lt, BufferView::SELECT|BufferView::FITCUR);
3234 InsetSpecialChar * new_inset =
3235 new InsetSpecialChar(kind);
3236 insertInset(new_inset);
3237 // Ok, what happens here if we are unable to insert
3238 // the inset? Leak it?
3243 void BufferView::Pimpl::smartQuote()
3245 LyXText const * lt = bv_->getLyXText();
3246 Paragraph const * par = lt->cursor.par();
3247 Paragraph::size_type pos = lt->cursor.pos();
3251 || (par->isInset(pos - 1)
3252 && par->getInset(pos - 1)->isSpace()))
3255 c = par->getChar(pos - 1);
3260 LyXLayout const & style = textclasslist.Style(
3261 bv_->buffer()->params.textclass, 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);
3410 LyXCursor const & cursor = bv_->text->cursor;
3414 cursor.par()->isInset(cursor.pos())) {
3415 Inset const * inset = cursor.par()->getInset(cursor.pos());
3416 if (find(codes.begin(), codes.end(), inset->lyxCode())
3419 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);