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);
214 lyxerr[Debug::INFO] << " No Buffer!" << endl;
215 owner_->updateMenubar();
216 owner_->updateToolbar();
217 owner_->getDialogs()->hideBufferDependent();
221 // Also remove all remaining text's from the testcache.
222 // (there should not be any!) (if there is any it is a
224 if (lyxerr.debugging())
225 textcache.show(lyxerr, "buffer delete all");
228 // should update layoutchoice even if we don't have a buffer.
229 owner_->updateLayoutChoice();
231 owner_->updateWindowTitle();
235 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
237 workarea_.resize(xpos, ypos, width, height);
238 update(bv_->text, SELECT);
243 void BufferView::Pimpl::resize()
246 resizeCurrentBuffer();
250 void BufferView::Pimpl::redraw()
252 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
257 bool BufferView::Pimpl::fitCursor()
259 lyx::Assert(screen_.get());
263 if (bv_->theLockingInset()) {
264 bv_->theLockingInset()->fitInsetCursor(bv_);
267 ret = screen_->fitCursor(bv_->text, bv_);
270 bv_->owner()->getDialogs()->updateParagraph();
277 void BufferView::Pimpl::redoCurrentBuffer()
279 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
280 if (buffer_ && bv_->text) {
282 owner_->updateLayoutChoice();
287 int BufferView::Pimpl::resizeCurrentBuffer()
289 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
292 Paragraph * selstartpar = 0;
293 Paragraph * selendpar = 0;
294 UpdatableInset * the_locking_inset = 0;
296 Paragraph::size_type pos = 0;
297 Paragraph::size_type selstartpos = 0;
298 Paragraph::size_type selendpos = 0;
299 bool selection = false;
300 bool mark_set = false;
302 owner_->prohibitInput();
304 owner_->message(_("Formatting document..."));
307 par = bv_->text->cursor.par();
308 pos = bv_->text->cursor.pos();
309 selstartpar = bv_->text->selection.start.par();
310 selstartpos = bv_->text->selection.start.pos();
311 selendpar = bv_->text->selection.end.par();
312 selendpos = bv_->text->selection.end.pos();
313 selection = bv_->text->selection.set();
314 mark_set = bv_->text->selection.mark();
315 the_locking_inset = bv_->theLockingInset();
317 bv_->text = new LyXText(bv_);
318 bv_->text->init(bv_);
320 // See if we have a text in TextCache that fits
321 // the new buffer_ with the correct width.
322 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
324 if (lyxerr.debugging()) {
325 lyxerr << "Found a LyXText that fits:\n";
326 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
328 // Set the owner of the newly found text
329 // bv_->text->owner(bv_);
330 if (lyxerr.debugging())
331 textcache.show(lyxerr, "resizeCurrentBuffer");
333 bv_->text = new LyXText(bv_);
334 bv_->text->init(bv_);
340 bv_->text->selection.set(true);
341 /* at this point just to avoid the Delete-Empty-Paragraph
342 * Mechanism when setting the cursor */
343 bv_->text->selection.mark(mark_set);
345 bv_->text->setCursor(bv_, selstartpar, selstartpos);
346 bv_->text->selection.cursor = bv_->text->cursor;
347 bv_->text->setCursor(bv_, selendpar, selendpos);
348 bv_->text->setSelection(bv_);
349 bv_->text->setCursor(bv_, par, pos);
351 bv_->text->setCursor(bv_, par, pos);
352 bv_->text->selection.cursor = bv_->text->cursor;
353 bv_->text->selection.set(false);
355 // remake the inset locking
356 bv_->theLockingInset(the_locking_inset);
358 bv_->text->first = screen_->topCursorVisible(bv_->text);
359 buffer_->resizeInsets(bv_);
360 // this will scroll the screen such that the cursor becomes visible
365 owner_->allowInput();
367 /// clear the "Formatting Document" message
370 /// get rid of the splash screen if it's not gone already
371 owner_->getDialogs()->destroySplash();
377 void BufferView::Pimpl::updateScreen()
379 // Regenerate the screen.
380 screen_.reset(new LyXScreen(workarea_));
384 void BufferView::Pimpl::updateScrollbar()
386 /* If the text is smaller than the working area, the scrollbar
387 * maximum must be the working area height. No scrolling will
390 workarea_.setScrollbar(0, 1.0);
394 long const text_height = bv_->text->height;
396 double const lineh = bv_->text->defaultHeight();
397 double const slider_size =
398 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
400 static long old_text_height = 0;
401 static double old_lineh = 0;
402 static double old_slider_size = 0;
404 if (text_height != old_text_height) {
405 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
406 old_text_height = text_height;
408 if (lineh != old_lineh) {
409 workarea_.setScrollbarIncrements(lineh);
412 if (current_scrollbar_value != bv_->text->first
413 || slider_size != old_slider_size) {
414 current_scrollbar_value = bv_->text->first;
415 workarea_.setScrollbar(current_scrollbar_value, slider_size);
416 old_slider_size = slider_size;
421 // Callback for scrollbar slider
422 void BufferView::Pimpl::scrollCB(double value)
424 if (!buffer_) return;
426 current_scrollbar_value = long(value);
427 if (current_scrollbar_value < 0)
428 current_scrollbar_value = 0;
433 screen_->draw(bv_->text, bv_, current_scrollbar_value);
435 if (!lyxrc.cursor_follows_scrollbar) {
440 LyXText * vbt = bv_->text;
442 int const height = vbt->defaultHeight();
443 int const first = static_cast<int>((bv_->text->first + height));
444 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
446 if (vbt->cursor.y() < first)
447 vbt->setCursorFromCoordinates(bv_, 0, first);
448 else if (vbt->cursor.y() > last)
449 vbt->setCursorFromCoordinates(bv_, 0, last);
455 int BufferView::Pimpl::scrollUp(long time)
457 if (!buffer_) return 0;
458 if (!screen_.get()) return 0;
460 double value = workarea_.getScrollbarValue();
462 if (value == 0) return 0;
464 float add_value = (bv_->text->defaultHeight()
465 + float(time) * float(time) * 0.125);
467 if (add_value > workarea_.height())
468 add_value = float(workarea_.height() -
469 bv_->text->defaultHeight());
476 workarea_.setScrollbarValue(value);
483 int BufferView::Pimpl::scrollDown(long time)
485 if (!buffer_) return 0;
486 if (!screen_.get()) return 0;
488 double value = workarea_.getScrollbarValue();
489 pair<float, float> p = workarea_.getScrollbarBounds();
490 double const max = p.second;
492 if (value == max) return 0;
494 float add_value = (bv_->text->defaultHeight()
495 + float(time) * float(time) * 0.125);
497 if (add_value > workarea_.height())
498 add_value = float(workarea_.height() -
499 bv_->text->defaultHeight());
506 workarea_.setScrollbarValue(value);
513 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
515 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
519 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
521 // Only use motion with button 1
522 if (!(state & Button1MotionMask))
525 if (!buffer_ || !screen_.get()) return;
527 // Check for inset locking
528 if (bv_->theLockingInset()) {
529 LyXCursor cursor = bv_->text->cursor;
530 LyXFont font = bv_->text->getFont(buffer_,
531 cursor.par(), cursor.pos());
532 int width = bv_->theLockingInset()->width(bv_, font);
533 int inset_x = font.isVisibleRightToLeft()
534 ? cursor.x() - width : cursor.x();
535 int start_x = inset_x + bv_->theLockingInset()->scroll();
536 bv_->theLockingInset()->
537 insetMotionNotify(bv_,
539 y - cursor.y() + bv_->text->first,
544 /* The test for not selection possible is needed, that only motion
545 events are used, where the bottom press event was on
546 the drawing area too */
547 if (!selection_possible)
550 screen_->hideCursor();
552 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
554 if (!bv_->text->selection.set())
555 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
557 bv_->text->setSelection(bv_);
558 screen_->toggleToggle(bv_->text, bv_);
561 screen_->showCursor(bv_->text, bv_);
568 // Single-click on work area
569 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
572 if (!buffer_ || !screen_.get()) return;
574 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
576 // ok ok, this is a hack.
577 if (button == 4 || button == 5) {
580 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
583 scrollDown(lyxrc.wheel_jump);
588 if (bv_->theLockingInset()) {
589 // We are in inset locking mode
591 /* Check whether the inset was hit. If not reset mode,
592 otherwise give the event to the inset */
593 if (inset_hit == bv_->theLockingInset()) {
594 bv_->theLockingInset()->
595 insetButtonPress(bv_,
600 bv_->unlockInset(bv_->theLockingInset());
605 selection_possible = true;
606 screen_->hideCursor();
608 int const screen_first = bv_->text->first;
610 // Middle button press pastes if we have a selection
611 bool paste_internally = false;
613 && bv_->text->selection.set()) {
614 owner_->getLyXFunc()->dispatch(LFUN_COPY);
615 paste_internally = true;
618 // Clear the selection
619 screen_->toggleSelection(bv_->text, bv_);
620 bv_->text->clearSelection();
621 bv_->text->fullRebreak(bv_);
623 screen_->update(bv_->text, bv_);
629 // Single left click in math inset?
630 if ((inset_hit != 0) &&
631 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
632 // Highly editable inset, like math
633 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
634 selection_possible = false;
635 owner_->updateLayoutChoice();
636 owner_->message(inset->editMessage());
637 inset->insetButtonPress(bv_, xpos, ypos, button);
638 inset->edit(bv_, xpos, ypos, button);
642 // Right click on a footnote flag opens float menu
644 selection_possible = false;
648 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
649 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
651 bv_->text->selection.cursor = bv_->text->cursor;
652 bv_->text->cursor.x_fix(bv_->text->cursor.x());
654 owner_->updateLayoutChoice();
656 selection_possible = false;
659 // Insert primary selection with middle mouse
660 // if there is a local selection in the current buffer,
663 if (paste_internally)
664 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
666 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
668 selection_possible = false;
674 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
680 LyXText * text = bv_->getLyXText();
682 if (text->bv_owner && bv_->theLockingInset())
685 if (screen_.get() && button == 1) {
686 if (text->bv_owner) {
687 screen_->hideCursor();
688 screen_->toggleSelection(text, bv_);
689 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
690 screen_->toggleSelection(text, bv_, false);
692 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
694 /* This will fit the cursor on the screen
696 update(text, BufferView::SELECT|BufferView::FITCUR);
701 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
707 LyXText * text = bv_->getLyXText();
709 if (text->bv_owner && bv_->theLockingInset())
712 if (screen_.get() && (button == 1)) {
713 screen_->hideCursor();
714 screen_->toggleSelection(text, bv_);
715 text->cursorHome(bv_);
716 text->selection.cursor = text->cursor;
717 text->cursorEnd(bv_);
718 text->setSelection(bv_);
719 screen_->toggleSelection(text, bv_, false);
720 /* This will fit the cursor on the screen
722 update(text, BufferView::SELECT|BufferView::FITCUR);
727 void BufferView::Pimpl::enterView()
729 if (active() && available()) {
730 SetXtermCursor(workarea_.getWin());
731 using_xterm_cursor = true;
736 void BufferView::Pimpl::leaveView()
738 if (using_xterm_cursor) {
739 XUndefineCursor(fl_get_display(), workarea_.getWin());
740 using_xterm_cursor = false;
745 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
748 if (!buffer_ || !screen_.get()) return;
750 // If we hit an inset, we have the inset coordinates in these
751 // and inset_hit points to the inset. If we do not hit an
752 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
753 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
755 if (bv_->theLockingInset()) {
756 // We are in inset locking mode.
758 /* LyX does a kind of work-area grabbing for insets.
759 Only a ButtonPress Event outside the inset will
760 force a insetUnlock. */
761 bv_->theLockingInset()->
762 insetButtonRelease(bv_, x, y, button);
766 selection_possible = false;
774 // Did we hit an editable inset?
776 // Inset like error, notes and figures
777 selection_possible = false;
779 // CHECK fix this proper in 0.13
781 // Following a ref shouldn't issue
782 // a push on the undo-stack
783 // anylonger, now that we have
784 // keybindings for following
785 // references and returning from
786 // references. IMHO though, it
787 // should be the inset's own business
788 // to push or not push on the undo
789 // stack. They don't *have* to
790 // alter the document...
792 // ...or maybe the SetCursorParUndo()
793 // below isn't necessary at all anylonger?
794 if (inset_hit->lyxCode() == Inset::REF_CODE) {
795 setCursorParUndo(bv_);
798 owner_->message(inset_hit->editMessage());
800 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
801 // Highly editable inset, like math
802 UpdatableInset *inset = (UpdatableInset *)inset_hit;
803 inset->insetButtonRelease(bv_, x, y, button);
805 inset_hit->insetButtonRelease(bv_, x, y, button);
806 inset_hit->edit(bv_, x, y, button);
811 // check whether we want to open a float
815 if (bv_->text->cursor.pos() <
816 bv_->text->cursor.par()->size()) {
817 c = bv_->text->cursor.par()->
818 getChar(bv_->text->cursor.pos());
820 if (bv_->text->cursor.pos() - 1 >= 0) {
821 c = bv_->text->cursor.par()->
822 getChar(bv_->text->cursor.pos() - 1);
825 selection_possible = false;
830 // Maybe we want to edit a bibitem ale970302
831 if (bv_->text->cursor.par()->bibkey && x < 20 +
832 bibitemMaxWidth(bv_, textclasslist.
834 params.textclass).defaultfont())) {
835 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
843 * Returns an inset if inset was hit. 0 otherwise.
844 * If hit, the coordinates are changed relative to the inset.
845 * Otherwise coordinates are not changed, and false is returned.
847 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
848 unsigned int /* button */)
853 int y_tmp = y + text->first;
856 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
857 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
860 if (cursor.pos() < cursor.par()->size()
861 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
862 && cursor.par()->getInset(cursor.pos())
863 && cursor.par()->getInset(cursor.pos())->editable()) {
865 // Check whether the inset really was hit
866 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
867 LyXFont font = text->getFont(buffer_,
868 cursor.par(), cursor.pos());
869 int const width = tmpinset->width(bv_, font);
870 int const inset_x = font.isVisibleRightToLeft()
871 ? cursor.x() - width : cursor.x();
872 int const start_x = inset_x + tmpinset->scroll();
873 int const end_x = inset_x + width;
875 if (x > start_x && x < end_x
876 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
877 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
878 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
880 // The origin of an inset is on the baseline
881 y = y_tmp - (text->cursor.y());
886 if ((cursor.pos() - 1 >= 0) &&
887 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
888 (cursor.par()->getInset(cursor.pos() - 1)) &&
889 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
890 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
891 LyXFont font = text->getFont(buffer_, cursor.par(),
893 int const width = tmpinset->width(bv_, font);
894 int const inset_x = font.isVisibleRightToLeft()
895 ? cursor.x() : cursor.x() - width;
896 int const start_x = inset_x + tmpinset->scroll();
897 int const end_x = inset_x + width;
899 if (x > start_x && x < end_x
900 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
901 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
903 if (move_cursor && (tmpinset != bv_->theLockingInset()))
905 text->setCursor(bv_, cursor.par(),
906 cursor.pos() - 1, true);
908 // The origin of an inset is on the baseline
909 y = y_tmp - (text->cursor.y());
917 void BufferView::Pimpl::workAreaExpose()
919 static int work_area_width;
920 static unsigned int work_area_height;
922 bool const widthChange = workarea_.workWidth() != work_area_width;
923 bool const heightChange = workarea_.height() != work_area_height;
925 // update from work area
926 work_area_width = workarea_.workWidth();
927 work_area_height = workarea_.height();
930 // The visible LyXView need a resize
933 // Remove all texts from the textcache
934 // This is not _really_ what we want to do. What
935 // we really want to do is to delete in textcache
936 // that does not have a BufferView with matching
937 // width, but as long as we have only one BufferView
938 // deleting all gives the same result.
939 if (lyxerr.debugging())
940 textcache.show(lyxerr, "Expose delete all");
942 } else if (heightChange) {
943 // Rebuild image of current screen
945 // fitCursor() ensures we don't jump back
946 // to the start of the document on vertical
950 // The main window size has changed, repaint most stuff
952 } else if (screen_.get())
953 screen_->redraw(bv_->text, bv_);
955 // Grey box when we don't have a buffer
959 // always make sure that the scrollbar is sane.
961 owner_->updateLayoutChoice();
966 void BufferView::Pimpl::update()
969 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
971 LyXText::text_status st = bv_->text->status();
972 screen_->update(bv_->text, bv_);
974 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
975 if (bv_->text->fullRebreak(bv_)) {
976 st = LyXText::NEED_MORE_REFRESH;
977 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
978 bv_->text->cursor.pos());
981 bv_->text->status(bv_, st);
982 screen_->update(bv_->text, bv_);
984 // do this here instead of in the screen::update because of
986 bv_->text->status(bv_, LyXText::UNCHANGED);
992 // Values used when calling update:
994 // -2 - update, move sel_cursor if selection, fitcursor
995 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
996 // 0 - update, move sel_cursor if selection, fitcursor
997 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
998 // 3 - update, move sel_cursor if selection
1001 // a simple redraw of the parts that need refresh
1003 // move sel_cursor if selection -
1004 // the text's sel_cursor is moved if there is selection is progress
1007 // fitCursor() is called and the scrollbar updated
1010 // the buffer is marked dirty.
1019 // UPDATE_ONLY = UPDATE;
1020 // UPDATE_SELECT = UPDATE | SELECT;
1021 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1022 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1024 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1025 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1026 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1027 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1028 // update(3) -> update(1) -> update(1) -> update(SELECT)
1030 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1032 owner_->updateLayoutChoice();
1034 if (!text->selection.set() && (f & SELECT)) {
1035 text->selection.cursor = text->cursor;
1038 text->fullRebreak(bv_);
1040 if (text->inset_owner) {
1041 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1042 updateInset(text->inset_owner, true);
1052 buffer_->markDirty();
1057 // Callback for cursor timer
1058 void BufferView::Pimpl::cursorToggle()
1060 // Quite a nice place for asyncron Inset updating, isn't it?
1061 // Actually no! This is run even if no buffer exist... so (Lgb)
1063 cursor_timeout.restart();
1068 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1069 if (pid == -1) // error find out what is wrong
1070 ; // ignore it for now.
1072 sigchldchecker(pid, &status);
1074 updatelist.update(bv_);
1076 if (!screen_.get()) {
1077 cursor_timeout.restart();
1081 if (!bv_->theLockingInset()) {
1082 screen_->cursorToggle(bv_);
1084 bv_->theLockingInset()->toggleInsetCursor(bv_);
1087 cursor_timeout.restart();
1091 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1093 if (!text->cursor.row()->previous())
1096 int y = text->first;
1097 if (text->inset_owner)
1098 y += bv_->text->first;
1099 Row * cursorrow = text->cursor.row();
1100 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1102 // This is to allow jumping over large insets
1103 if ((cursorrow == text->cursor.row()))
1104 text->cursorUp(bv_);
1106 if (text->inset_owner ||
1107 text->cursor.row()->height() < workarea_.height())
1108 screen_->draw(bv_->text, bv_,
1110 - text->cursor.row()->baseline()
1111 + text->cursor.row()->height()
1112 - workarea_.height() + 1 );
1117 void BufferView::Pimpl::cursorNext(LyXText * text)
1119 if (!text->cursor.row()->next())
1122 int y = text->first + workarea_.height();
1123 // if (text->inset_owner)
1124 // y += bv_->text->first;
1125 text->getRowNearY(y);
1127 Row * cursorrow = text->cursor.row();
1128 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1130 // This is to allow jumping over large insets
1131 if ((cursorrow == bv_->text->cursor.row()))
1132 text->cursorDown(bv_);
1134 if (text->inset_owner ||
1135 text->cursor.row()->height() < workarea_.height())
1136 screen_->draw(bv_->text, bv_, text->cursor.y() -
1137 text->cursor.row()->baseline());
1142 bool BufferView::Pimpl::available() const
1144 if (buffer_ && bv_->text) return true;
1149 void BufferView::Pimpl::beforeChange(LyXText * text)
1152 text->clearSelection();
1156 void BufferView::Pimpl::savePosition(unsigned int i)
1158 if (i >= saved_positions_num)
1160 saved_positions[i] = Position(buffer_->fileName(),
1161 bv_->text->cursor.par()->id(),
1162 bv_->text->cursor.pos());
1165 str << _("Saved bookmark") << ' ' << i;
1166 owner_->message(str.str().c_str());
1171 void BufferView::Pimpl::restorePosition(unsigned int i)
1173 if (i >= saved_positions_num)
1176 string const fname = saved_positions[i].filename;
1178 beforeChange(bv_->text);
1180 if (fname != buffer_->fileName()) {
1181 Buffer * b = bufferlist.exists(fname) ?
1182 bufferlist.getBuffer(fname) :
1183 bufferlist.loadLyXFile(fname); // don't ask, just load it
1184 if (b != 0 ) buffer(b);
1187 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1191 bv_->text->setCursor(bv_, par,
1192 min(par->size(), saved_positions[i].par_pos));
1194 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1197 str << _("Moved to bookmark") << ' ' << i;
1198 owner_->message(str.str().c_str());
1203 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1205 if (i >= saved_positions_num)
1208 return !saved_positions[i].filename.empty();
1212 void BufferView::Pimpl::setState()
1214 if (!lyxrc.rtl_support)
1217 LyXText * text = bv_->getLyXText();
1218 if (text->real_current_font.isRightToLeft()) {
1219 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1220 owner_->getIntl()->KeyMapSec();
1222 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1223 owner_->getIntl()->KeyMapPrim();
1228 void BufferView::Pimpl::insetSleep()
1230 if (bv_->theLockingInset() && !inset_slept) {
1231 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1232 bv_->theLockingInset()->insetUnlock(bv_);
1238 void BufferView::Pimpl::insetWakeup()
1240 if (bv_->theLockingInset() && inset_slept) {
1241 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1242 inset_slept = false;
1247 void BufferView::Pimpl::insetUnlock()
1249 if (bv_->theLockingInset()) {
1251 bv_->theLockingInset()->insetUnlock(bv_);
1252 bv_->theLockingInset(0);
1254 inset_slept = false;
1259 bool BufferView::Pimpl::focus() const
1261 return workarea_.hasFocus();
1265 void BufferView::Pimpl::focus(bool f)
1267 if (f) workarea_.setFocus();
1271 bool BufferView::Pimpl::active() const
1273 return workarea_.active();
1277 bool BufferView::Pimpl::belowMouse() const
1279 return workarea_.belowMouse();
1283 void BufferView::Pimpl::showCursor()
1285 if (screen_.get()) {
1286 if (bv_->theLockingInset())
1287 bv_->theLockingInset()->showInsetCursor(bv_);
1289 screen_->showCursor(bv_->text, bv_);
1294 void BufferView::Pimpl::hideCursor()
1296 if (screen_.get()) {
1297 if (!bv_->theLockingInset())
1298 // bv_->theLockingInset()->hideInsetCursor(bv_);
1300 screen_->hideCursor();
1305 void BufferView::Pimpl::toggleSelection(bool b)
1307 if (screen_.get()) {
1308 if (bv_->theLockingInset())
1309 bv_->theLockingInset()->toggleSelection(bv_, b);
1310 screen_->toggleSelection(bv_->text, bv_, b);
1315 void BufferView::Pimpl::toggleToggle()
1318 screen_->toggleToggle(bv_->text, bv_);
1322 void BufferView::Pimpl::center()
1324 beforeChange(bv_->text);
1325 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1326 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1328 screen_->draw(bv_->text, bv_, 0);
1330 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1335 void BufferView::Pimpl::pasteClipboard(bool asPara)
1337 if (!buffer_) return;
1339 screen_->hideCursor();
1340 beforeChange(bv_->text);
1342 string const clip(workarea_.getClipboard());
1344 if (clip.empty()) return;
1347 bv_->text->insertStringAsParagraphs(bv_, clip);
1349 bv_->text->insertStringAsLines(bv_, clip);
1351 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1355 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1357 workarea_.putClipboard(stuff);
1362 * Dispatch functions for actions which can be valid for BufferView->text
1363 * and/or InsetText->text!!!
1368 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1370 LyXText * lt = bv_->getLyXText();
1372 if (selecting || lt->selection.mark()) {
1373 lt->setSelection(bv_);
1377 update(lt, BufferView::SELECT|BufferView::FITCUR);
1380 /* ---> Everytime the cursor is moved, show the current font state. */
1381 // should this too me moved out of this func?
1382 //owner->showState();
1387 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1389 LyXCursor cursor = bv_->getLyXText()->cursor;
1390 Buffer::inset_iterator it =
1391 find_if(Buffer::inset_iterator(
1392 cursor.par(), cursor.pos()),
1393 buffer_->inset_iterator_end(),
1394 lyx::compare_memfun(&Inset::lyxCode, code));
1395 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1399 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1401 string filename = filen;
1403 if (filename.empty()) {
1404 // Launch a file browser
1405 string initpath = lyxrc.document_path;
1408 string const trypath = owner_->buffer()->filepath;
1409 // If directory is writeable, use this as default.
1410 if (IsDirWriteable(trypath))
1414 FileDialog fileDlg(bv_->owner(),
1415 _("Select LyX document to insert"),
1417 make_pair(string(_("Documents")),
1418 string(lyxrc.document_path)),
1419 make_pair(string(_("Examples")),
1420 string(AddPath(system_lyxdir, "examples"))));
1422 FileDialog::Result result =
1423 fileDlg.Select(initpath,
1424 _("*.lyx| LyX Documents (*.lyx)"));
1426 if (result.first == FileDialog::Later)
1429 filename = result.second;
1431 // check selected filename
1432 if (filename.empty()) {
1433 owner_->message(_("Canceled."));
1438 // get absolute path of file and add ".lyx" to the filename if
1440 filename = FileSearch(string(), filename, "lyx");
1442 string const disp_fn(MakeDisplayPath(filename));
1445 s1 << _("Inserting document") << ' '
1446 << disp_fn << " ...";
1447 owner_->message(s1.str().c_str());
1448 bool const res = bv_->insertLyXFile(filename);
1451 str << _("Document") << ' ' << disp_fn
1452 << ' ' << _("inserted.");
1453 owner_->message(str.str().c_str());
1456 str << _("Could not insert document") << ' '
1458 owner_->message(str.str().c_str());
1463 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1465 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1466 << action <<"] arg[" << argument << "]" << endl;
1469 // --- Misc -------------------------------------------
1473 LyXText * lt = bv_->getLyXText();
1474 lt->toggleAppendix(bv_);
1477 | BufferView::FITCUR
1478 | BufferView::CHANGE);
1483 case LFUN_TOC_INSERT:
1485 InsetCommandParams p;
1486 p.setCmdName("tableofcontents");
1487 Inset * inset = new InsetTOC(p);
1488 if (!insertInset(inset, "Standard"))
1493 case LFUN_TABULAR_FEATURE:
1494 case LFUN_SCROLL_INSET:
1495 // this is not handled here as this funktion is only aktive
1496 // if we have a locking_inset and that one is (or contains)
1500 case LFUN_INSET_GRAPHICS:
1502 Inset * new_inset = new InsetGraphics;
1503 if (!insertInset(new_inset)) {
1506 // this is need because you don't use a inset->Edit()
1507 updateInset(new_inset, true);
1508 new_inset->edit(bv_);
1518 case LFUN_PASTESELECTION:
1520 bool asPara = false;
1521 if (argument == "paragraph") asPara = true;
1522 pasteClipboard(asPara);
1534 case LFUN_LAYOUT_COPY:
1535 bv_->copyEnvironment();
1538 case LFUN_LAYOUT_PASTE:
1539 bv_->pasteEnvironment();
1543 case LFUN_GOTOERROR:
1544 gotoInset(Inset::ERROR_CODE, false);
1548 gotoInset(Inset::IGNORE_CODE, false);
1551 case LFUN_REFERENCE_GOTO:
1553 vector<Inset::Code> tmp;
1554 tmp.push_back(Inset::LABEL_CODE);
1555 tmp.push_back(Inset::REF_CODE);
1556 gotoInset(tmp, true);
1560 case LFUN_HYPHENATION:
1561 specialChar(InsetSpecialChar::HYPHENATION);
1564 case LFUN_LIGATURE_BREAK:
1565 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1569 specialChar(InsetSpecialChar::LDOTS);
1572 case LFUN_END_OF_SENTENCE:
1573 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1576 case LFUN_MENU_SEPARATOR:
1577 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1585 changeDepth(bv_, bv_->getLyXText(), 0);
1588 case LFUN_DEPTH_MIN:
1589 changeDepth(bv_, bv_->getLyXText(), -1);
1592 case LFUN_DEPTH_PLUS:
1593 changeDepth(bv_, bv_->getLyXText(), 1);
1597 owner_->getDialogs()->setUserFreeFont();
1600 case LFUN_FILE_INSERT:
1602 MenuInsertLyXFile(argument);
1606 case LFUN_FILE_INSERT_ASCII_PARA:
1607 InsertAsciiFile(bv_, argument, true);
1610 case LFUN_FILE_INSERT_ASCII:
1611 InsertAsciiFile(bv_, argument, false);
1616 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1617 << argument << endl;
1619 // Derive layout number from given argument (string)
1620 // and current buffer's textclass (number). */
1621 LyXTextClassList::ClassList::size_type tclass =
1622 buffer_->params.textclass;
1623 pair <bool, LyXTextClass::size_type> layout =
1624 textclasslist.NumberOfLayout(tclass, argument);
1626 // If the entry is obsolete, use the new one instead.
1628 string obs = textclasslist.Style(tclass,layout.second)
1632 textclasslist.NumberOfLayout(tclass, obs);
1635 // see if we found the layout number:
1636 if (!layout.first) {
1637 owner_->getLyXFunc()->setErrorMessage(
1638 string(N_("Layout ")) + argument +
1643 if (current_layout != layout.second) {
1644 LyXText * lt = bv_->getLyXText();
1646 current_layout = layout.second;
1649 | BufferView::FITCUR);
1650 lt->setLayout(bv_, layout.second);
1651 owner_->setLayout(layout.second);
1654 | BufferView::FITCUR
1655 | BufferView::CHANGE);
1662 lang(bv_, argument);
1664 owner_->showState();
1669 owner_->showState();
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1694 owner_->showState();
1699 owner_->showState();
1702 case LFUN_UNDERLINE:
1704 owner_->showState();
1707 case LFUN_FONT_SIZE:
1708 fontSize(bv_, argument);
1709 owner_->showState();
1712 case LFUN_FONT_STATE:
1713 owner_->getLyXFunc()->setMessage(currentState(bv_));
1716 case LFUN_UPCASE_WORD:
1718 LyXText * lt = bv_->getLyXText();
1722 | BufferView::FITCUR);
1723 lt->changeCase(bv_, LyXText::text_uppercase);
1724 if (lt->inset_owner)
1725 updateInset(lt->inset_owner, true);
1728 | BufferView::FITCUR
1729 | BufferView::CHANGE);
1733 case LFUN_LOWCASE_WORD:
1735 LyXText * lt = bv_->getLyXText();
1737 update(lt, BufferView::SELECT|BufferView::FITCUR);
1738 lt->changeCase(bv_, LyXText::text_lowercase);
1739 if (lt->inset_owner)
1740 updateInset(lt->inset_owner, true);
1743 | BufferView::FITCUR
1744 | BufferView::CHANGE);
1748 case LFUN_CAPITALIZE_WORD:
1750 LyXText * lt = bv_->getLyXText();
1752 update(lt, BufferView::SELECT|BufferView::FITCUR);
1753 lt->changeCase(bv_, LyXText::text_capitalization);
1754 if (lt->inset_owner)
1755 updateInset(lt->inset_owner, true);
1758 | BufferView::FITCUR
1759 | BufferView::CHANGE);
1763 case LFUN_TRANSPOSE_CHARS:
1765 LyXText * lt = bv_->getLyXText();
1767 update(lt, BufferView::SELECT|BufferView::FITCUR);
1768 lt->transposeChars(*bv_);
1769 if (lt->inset_owner)
1770 updateInset(lt->inset_owner, true);
1773 | BufferView::FITCUR
1774 | BufferView::CHANGE);
1779 case LFUN_INSERT_LABEL:
1780 MenuInsertLabel(bv_, argument);
1783 case LFUN_REF_INSERT:
1784 if (argument.empty()) {
1785 InsetCommandParams p("ref");
1786 owner_->getDialogs()->createRef(p.getAsString());
1788 InsetCommandParams p;
1789 p.setFromString(argument);
1791 InsetRef * inset = new InsetRef(p, *buffer_);
1792 if (!insertInset(inset))
1795 updateInset(inset, true);
1799 case LFUN_BOOKMARK_SAVE:
1800 savePosition(strToUnsignedInt(argument));
1803 case LFUN_BOOKMARK_GOTO:
1804 restorePosition(strToUnsignedInt(argument));
1809 string label(argument);
1810 if (label.empty()) {
1812 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1814 label = inset->getContents();
1819 if (!label.empty()) {
1820 //bv_->savePosition(0);
1821 if (!bv_->gotoLabel(label))
1822 WriteAlert(_("Error"),
1823 _("Couldn't find this label"),
1824 _("in current document."));
1829 // --- Cursor Movements -----------------------------
1832 LyXText * lt = bv_->getLyXText();
1834 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1835 if (!lt->selection.mark())
1837 update(lt, BufferView::SELECT|BufferView::FITCUR);
1839 lt->cursorLeft(bv_, false);
1840 if (lt->cursor.pos() < lt->cursor.par()->size()
1841 && lt->cursor.par()->getChar(lt->cursor.pos())
1842 == Paragraph::META_INSET
1843 && lt->cursor.par()->getInset(lt->cursor.pos())
1844 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1845 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1846 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1848 tmpinset->edit(bv_, false);
1850 tmpinset->edit(bv_);
1854 lt->cursorRight(bv_, false);
1856 moveCursorUpdate(false);
1857 owner_->showState();
1863 // This is soooo ugly. Isn`t it possible to make
1864 // it simpler? (Lgb)
1865 LyXText * lt = bv_->getLyXText();
1866 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1867 if (!lt->selection.mark())
1869 update(lt, BufferView::SELECT|BufferView::FITCUR);
1870 LyXCursor const cur = lt->cursor;
1872 lt->cursorLeft(bv_, false);
1873 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1874 lt->cursor.pos() < lt->cursor.par()->size() &&
1875 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1876 Paragraph::META_INSET) &&
1877 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1878 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1879 == Inset::HIGHLY_EDITABLE))
1881 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1882 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1884 tmpinset->edit(bv_);
1886 tmpinset->edit(bv_, false);
1890 lt->cursorRight(bv_, false);
1893 moveCursorUpdate(false);
1894 owner_->showState();
1900 LyXText * lt = bv_->getLyXText();
1902 if (!lt->selection.mark())
1904 update(lt, BufferView::UPDATE);
1907 moveCursorUpdate(false);
1908 owner_->showState();
1914 LyXText * lt = bv_->getLyXText();
1916 if (!lt->selection.mark())
1918 update(lt, BufferView::UPDATE);
1919 lt->cursorDown(bv_);
1921 moveCursorUpdate(false);
1922 owner_->showState();
1926 case LFUN_UP_PARAGRAPH:
1928 LyXText * lt = bv_->getLyXText();
1930 if (!lt->selection.mark())
1932 update(lt, BufferView::UPDATE);
1933 lt->cursorUpParagraph(bv_);
1935 moveCursorUpdate(false);
1936 owner_->showState();
1940 case LFUN_DOWN_PARAGRAPH:
1942 LyXText * lt = bv_->getLyXText();
1944 if (!lt->selection.mark())
1946 update(lt, BufferView::UPDATE);
1947 lt->cursorDownParagraph(bv_);
1949 moveCursorUpdate(false);
1950 owner_->showState();
1956 LyXText * lt = bv_->getLyXText();
1958 if (!lt->selection.mark())
1960 update(lt, BufferView::UPDATE);
1963 moveCursorUpdate(false);
1964 owner_->showState();
1970 LyXText * lt = bv_->getLyXText();
1972 if (!lt->selection.mark())
1974 update(lt, BufferView::UPDATE);
1977 moveCursorUpdate(false);
1978 owner_->showState();
1984 LyXText * lt = bv_->getLyXText();
1986 if (!lt->selection.mark())
1988 update(lt, BufferView::SELECT|BufferView::FITCUR);
1989 lt->cursorHome(bv_);
1991 moveCursorUpdate(false);
1992 owner_->showState();
1998 LyXText * lt = bv_->getLyXText();
2000 if (!lt->selection.mark())
2003 BufferView::SELECT|BufferView::FITCUR);
2006 moveCursorUpdate(false);
2007 owner_->showState();
2011 case LFUN_SHIFT_TAB:
2014 LyXText * lt = bv_->getLyXText();
2016 if (!lt->selection.mark())
2019 BufferView::SELECT|BufferView::FITCUR);
2022 moveCursorUpdate(false);
2023 owner_->showState();
2027 case LFUN_WORDRIGHT:
2029 LyXText * lt = bv_->getLyXText();
2031 if (!lt->selection.mark())
2033 update(lt, BufferView::SELECT|BufferView::FITCUR);
2034 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2035 lt->cursorLeftOneWord(bv_);
2037 lt->cursorRightOneWord(bv_);
2039 moveCursorUpdate(false);
2040 owner_->showState();
2046 LyXText * lt = bv_->getLyXText();
2048 if (!lt->selection.mark())
2050 update(lt, BufferView::SELECT|BufferView::FITCUR);
2051 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2052 lt->cursorRightOneWord(bv_);
2054 lt->cursorLeftOneWord(bv_);
2056 moveCursorUpdate(false);
2057 owner_->showState();
2061 case LFUN_BEGINNINGBUF:
2063 LyXText * lt = bv_->getLyXText();
2065 if (!lt->selection.mark())
2068 BufferView::SELECT|BufferView::FITCUR);
2071 moveCursorUpdate(false);
2072 owner_->showState();
2078 LyXText * lt = bv_->getLyXText();
2080 if (!lt->selection.mark())
2083 BufferView::SELECT|BufferView::FITCUR);
2084 lt->cursorBottom(bv_);
2086 moveCursorUpdate(false);
2087 owner_->showState();
2091 /* cursor selection ---------------------------- */
2094 LyXText * lt = bv_->getLyXText();
2097 BufferView::SELECT|BufferView::FITCUR);
2098 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2099 lt->cursorLeft(bv_);
2101 lt->cursorRight(bv_);
2103 moveCursorUpdate(true);
2104 owner_->showState();
2110 LyXText * lt = bv_->getLyXText();
2113 BufferView::SELECT|BufferView::FITCUR);
2114 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2115 lt->cursorRight(bv_);
2117 lt->cursorLeft(bv_);
2119 moveCursorUpdate(true);
2120 owner_->showState();
2126 LyXText * lt = bv_->getLyXText();
2129 BufferView::SELECT|BufferView::FITCUR);
2132 moveCursorUpdate(true);
2133 owner_->showState();
2139 LyXText * lt = bv_->getLyXText();
2142 BufferView::SELECT|BufferView::FITCUR);
2143 lt->cursorDown(bv_);
2145 moveCursorUpdate(true);
2146 owner_->showState();
2150 case LFUN_UP_PARAGRAPHSEL:
2152 LyXText * lt = bv_->getLyXText();
2155 BufferView::SELECT|BufferView::FITCUR);
2156 lt->cursorUpParagraph(bv_);
2158 moveCursorUpdate(true);
2159 owner_->showState();
2163 case LFUN_DOWN_PARAGRAPHSEL:
2165 LyXText * lt = bv_->getLyXText();
2168 BufferView::SELECT|BufferView::FITCUR);
2169 lt->cursorDownParagraph(bv_);
2171 moveCursorUpdate(true);
2172 owner_->showState();
2178 LyXText * lt = bv_->getLyXText();
2180 update(lt, BufferView::SELECT|BufferView::FITCUR);
2183 moveCursorUpdate(true);
2184 owner_->showState();
2190 LyXText * lt = bv_->getLyXText();
2192 update(lt, BufferView::SELECT|BufferView::FITCUR);
2195 moveCursorUpdate(true);
2196 owner_->showState();
2202 LyXText * lt = bv_->getLyXText();
2204 update(lt, BufferView::SELECT|BufferView::FITCUR);
2205 lt->cursorHome(bv_);
2207 moveCursorUpdate(true);
2208 owner_->showState();
2214 LyXText * lt = bv_->getLyXText();
2216 update(lt, BufferView::SELECT|BufferView::FITCUR);
2219 moveCursorUpdate(true);
2220 owner_->showState();
2224 case LFUN_WORDRIGHTSEL:
2226 LyXText * lt = bv_->getLyXText();
2228 update(lt, BufferView::SELECT|BufferView::FITCUR);
2229 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2230 lt->cursorLeftOneWord(bv_);
2232 lt->cursorRightOneWord(bv_);
2234 moveCursorUpdate(true);
2235 owner_->showState();
2239 case LFUN_WORDLEFTSEL:
2241 LyXText * lt = bv_->getLyXText();
2243 update(lt, BufferView::SELECT|BufferView::FITCUR);
2244 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2245 lt->cursorRightOneWord(bv_);
2247 lt->cursorLeftOneWord(bv_);
2249 moveCursorUpdate(true);
2250 owner_->showState();
2254 case LFUN_BEGINNINGBUFSEL:
2256 LyXText * lt = bv_->getLyXText();
2258 if (lt->inset_owner)
2260 update(lt, BufferView::SELECT|BufferView::FITCUR);
2263 moveCursorUpdate(true);
2264 owner_->showState();
2268 case LFUN_ENDBUFSEL:
2270 LyXText * lt = bv_->getLyXText();
2272 if (lt->inset_owner)
2275 BufferView::SELECT|BufferView::FITCUR);
2276 lt->cursorBottom(bv_);
2278 moveCursorUpdate(true);
2279 owner_->showState();
2283 // --- text changing commands ------------------------
2284 case LFUN_BREAKLINE:
2286 LyXText * lt = bv_->getLyXText();
2289 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2292 | BufferView::FITCUR
2293 | BufferView::CHANGE);
2294 moveCursorUpdate(false);
2298 case LFUN_PROTECTEDSPACE:
2300 LyXText * lt = bv_->getLyXText();
2302 LyXLayout const & style = textclasslist
2303 .Style(buffer_->params.textclass,
2304 lt->cursor.par()->getLayout());
2306 if (style.free_spacing) {
2307 lt->insertChar(bv_, ' ');
2310 | BufferView::FITCUR
2311 | BufferView::CHANGE);
2315 moveCursorUpdate(false);
2321 LyXText * lt = bv_->getLyXText();
2323 if (lt->selection.mark()) {
2327 | BufferView::FITCUR);
2328 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2331 lt->selection.mark(true);
2334 | BufferView::FITCUR);
2335 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2337 lt->selection.cursor = lt->cursor;
2343 LyXText * lt = bv_->getLyXText();
2345 if (!lt->selection.set()) {
2347 lt->selection.cursor = lt->cursor;
2350 | BufferView::FITCUR
2351 | BufferView::CHANGE);
2352 // It is possible to make it a lot faster still
2353 // just comment out the line below...
2358 moveCursorUpdate(false);
2359 owner_->showState();
2364 case LFUN_DELETE_SKIP:
2366 LyXText * lt = bv_->getLyXText();
2368 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2370 LyXCursor cursor = lt->cursor;
2372 if (!lt->selection.set()) {
2373 if (cursor.pos() == cursor.par()->size()) {
2374 lt->cursorRight(bv_);
2375 cursor = lt->cursor;
2376 if (cursor.pos() == 0
2377 && !(cursor.par()->params().spaceTop()
2378 == VSpace (VSpace::NONE))) {
2381 cursor.par()->params().lineTop(),
2382 cursor.par()->params().lineBottom(),
2383 cursor.par()->params().pagebreakTop(),
2384 cursor.par()->params().pagebreakBottom(),
2385 VSpace(VSpace::NONE),
2386 cursor.par()->params().spaceBottom(),
2387 cursor.par()->params().spacing(),
2388 cursor.par()->params().align(),
2389 cursor.par()->params().labelWidthString(), 0);
2390 lt->cursorLeft(bv_);
2393 | BufferView::FITCUR
2394 | BufferView::CHANGE);
2396 lt->cursorLeft(bv_);
2398 lt->selection.cursor = lt->cursor;
2401 | BufferView::FITCUR
2402 | BufferView::CHANGE);
2406 lt->selection.cursor = lt->cursor;
2409 | BufferView::FITCUR
2410 | BufferView::CHANGE);
2418 /* -------> Delete word forward. */
2419 case LFUN_DELETE_WORD_FORWARD:
2420 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2421 bv_->getLyXText()->deleteWordForward(bv_);
2422 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2423 moveCursorUpdate(false);
2424 owner_->showState();
2427 /* -------> Delete word backward. */
2428 case LFUN_DELETE_WORD_BACKWARD:
2430 LyXText * lt = bv_->getLyXText();
2432 update(lt, BufferView::SELECT|BufferView::FITCUR);
2433 lt->deleteWordBackward(bv_);
2436 | BufferView::FITCUR
2437 | BufferView::CHANGE);
2438 moveCursorUpdate(false);
2439 owner_->showState();
2443 /* -------> Kill to end of line. */
2444 case LFUN_DELETE_LINE_FORWARD:
2446 LyXText * lt = bv_->getLyXText();
2448 update(lt, BufferView::SELECT|BufferView::FITCUR);
2449 lt->deleteLineForward(bv_);
2452 | BufferView::FITCUR
2453 | BufferView::CHANGE);
2454 moveCursorUpdate(false);
2458 /* -------> Set mark off. */
2461 LyXText * lt = bv_->getLyXText();
2464 update(lt, BufferView::SELECT|BufferView::FITCUR);
2465 lt->selection.cursor = lt->cursor;
2466 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2470 /* -------> Set mark on. */
2473 LyXText * lt = bv_->getLyXText();
2476 lt->selection.mark(true);
2477 update(lt, BufferView::SELECT|BufferView::FITCUR);
2478 lt->selection.cursor = lt->cursor;
2479 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2483 case LFUN_BACKSPACE:
2485 LyXText * lt = bv_->getLyXText();
2487 if (!lt->selection.set()) {
2488 if (owner_->getIntl()->getTrans().backspace()) {
2490 lt->selection.cursor = lt->cursor;
2493 | BufferView::FITCUR
2494 | BufferView::CHANGE);
2495 // It is possible to make it a lot faster still
2496 // just comment out the line below...
2502 owner_->showState();
2507 case LFUN_BACKSPACE_SKIP:
2509 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2510 LyXText * lt = bv_->getLyXText();
2512 LyXCursor cursor = lt->cursor;
2514 if (!lt->selection.set()) {
2515 if (cursor.pos() == 0
2516 && !(cursor.par()->params().spaceTop()
2517 == VSpace (VSpace::NONE))) {
2520 cursor.par()->params().lineTop(),
2521 cursor.par()->params().lineBottom(),
2522 cursor.par()->params().pagebreakTop(),
2523 cursor.par()->params().pagebreakBottom(),
2524 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2525 cursor.par()->params().spacing(),
2526 cursor.par()->params().align(),
2527 cursor.par()->params().labelWidthString(), 0);
2530 | BufferView::FITCUR
2531 | BufferView::CHANGE);
2534 lt->selection.cursor = cursor;
2537 | BufferView::FITCUR
2538 | BufferView::CHANGE);
2545 case LFUN_BREAKPARAGRAPH:
2547 LyXText * lt = bv_->getLyXText();
2550 lt->breakParagraph(bv_, 0);
2553 | BufferView::FITCUR
2554 | BufferView::CHANGE);
2555 lt->selection.cursor = lt->cursor;
2557 owner_->showState();
2561 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2563 LyXText * lt = bv_->getLyXText();
2566 lt->breakParagraph(bv_, 1);
2569 | BufferView::FITCUR
2570 | BufferView::CHANGE);
2571 lt->selection.cursor = lt->cursor;
2573 owner_->showState();
2577 case LFUN_BREAKPARAGRAPH_SKIP:
2579 // When at the beginning of a paragraph, remove
2580 // indentation and add a "defskip" at the top.
2581 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2582 LyXText * lt = bv_->getLyXText();
2584 LyXCursor cursor = lt->cursor;
2587 if (cursor.pos() == 0) {
2588 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2591 cursor.par()->params().lineTop(),
2592 cursor.par()->params().lineBottom(),
2593 cursor.par()->params().pagebreakTop(),
2594 cursor.par()->params().pagebreakBottom(),
2595 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2596 cursor.par()->params().spacing(),
2597 cursor.par()->params().align(),
2598 cursor.par()->params().labelWidthString(), 1);
2599 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2603 lt->breakParagraph(bv_, 0);
2604 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2609 | BufferView::FITCUR
2610 | BufferView::CHANGE);
2611 lt->selection.cursor = cursor;
2613 owner_->showState();
2617 case LFUN_PARAGRAPH_SPACING:
2619 LyXText * lt = bv_->getLyXText();
2621 Paragraph * par = lt->cursor.par();
2622 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2623 float cur_value = 1.0;
2624 if (cur_spacing == Spacing::Other) {
2625 cur_value = par->params().spacing().getValue();
2628 istringstream istr(argument.c_str());
2632 Spacing::Space new_spacing = cur_spacing;
2633 float new_value = cur_value;
2635 lyxerr << "Missing argument to `paragraph-spacing'"
2637 } else if (tmp == "single") {
2638 new_spacing = Spacing::Single;
2639 } else if (tmp == "onehalf") {
2640 new_spacing = Spacing::Onehalf;
2641 } else if (tmp == "double") {
2642 new_spacing = Spacing::Double;
2643 } else if (tmp == "other") {
2644 new_spacing = Spacing::Other;
2647 lyxerr << "new_value = " << tmpval << endl;
2650 } else if (tmp == "default") {
2651 new_spacing = Spacing::Default;
2653 lyxerr << _("Unknown spacing argument: ")
2654 << argument << endl;
2656 if (cur_spacing != new_spacing || cur_value != new_value) {
2657 par->params().spacing(Spacing(new_spacing, new_value));
2658 lt->redoParagraph(bv_);
2661 | BufferView::FITCUR
2662 | BufferView::CHANGE);
2667 case LFUN_INSET_TOGGLE:
2669 LyXText * lt = bv_->getLyXText();
2672 update(lt, BufferView::SELECT|BufferView::FITCUR);
2673 lt->toggleInset(bv_);
2674 update(lt, BufferView::SELECT|BufferView::FITCUR);
2686 InsetCommandParams p;
2687 if (action == LFUN_HTMLURL)
2688 p.setCmdName("htmlurl");
2690 p.setCmdName("url");
2691 owner_->getDialogs()->createUrl(p.getAsString());
2695 case LFUN_INSERT_URL:
2697 InsetCommandParams p;
2698 p.setFromString(argument);
2700 InsetUrl * inset = new InsetUrl(p);
2701 if (!insertInset(inset))
2704 updateInset(inset, true);
2708 case LFUN_INSET_TEXT:
2709 insertAndEditInset(new InsetText);
2712 case LFUN_INSET_ERT:
2713 insertAndEditInset(new InsetERT);
2716 case LFUN_INSET_EXTERNAL:
2717 insertAndEditInset(new InsetExternal);
2720 case LFUN_INSET_FOOTNOTE:
2721 insertAndEditInset(new InsetFoot);
2724 case LFUN_INSET_MARGINAL:
2725 insertAndEditInset(new InsetMarginal);
2728 case LFUN_INSET_MINIPAGE:
2729 insertAndEditInset(new InsetMinipage);
2732 case LFUN_INSERT_NOTE:
2733 insertAndEditInset(new InsetNote);
2736 case LFUN_INSET_FLOAT:
2737 // check if the float type exist
2738 if (floatList.typeExist(argument)) {
2739 insertAndEditInset(new InsetFloat(argument));
2741 lyxerr << "Non-existant float type: "
2742 << argument << endl;
2746 case LFUN_INSET_WIDE_FLOAT:
2748 // check if the float type exist
2749 if (floatList.typeExist(argument)) {
2750 InsetFloat * new_inset = new InsetFloat(argument);
2751 new_inset->wide(true);
2752 if (insertInset(new_inset))
2753 new_inset->edit(bv_);
2757 lyxerr << "Non-existant float type: "
2758 << argument << endl;
2765 case LFUN_INSET_LIST:
2766 insertAndEditInset(new InsetList);
2769 case LFUN_INSET_THEOREM:
2770 insertAndEditInset(new InsetTheorem);
2774 case LFUN_INSET_CAPTION:
2776 // Do we have a locking inset...
2777 if (bv_->theLockingInset()) {
2778 lyxerr << "Locking inset code: "
2779 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2780 InsetCaption * new_inset = new InsetCaption;
2781 new_inset->setOwner(bv_->theLockingInset());
2782 new_inset->setAutoBreakRows(true);
2783 new_inset->setDrawFrame(0, InsetText::LOCKED);
2784 new_inset->setFrameColor(0, LColor::captionframe);
2785 if (insertInset(new_inset))
2786 new_inset->edit(bv_);
2793 case LFUN_INSET_TABULAR:
2797 if (!argument.empty())
2798 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2799 InsetTabular * new_inset =
2800 new InsetTabular(*buffer_, r, c);
2802 bv_->getLyXText()->real_current_font.isRightToLeft();
2803 if (!open_new_inset(new_inset, rtl))
2808 // --- lyxserver commands ----------------------------
2810 case LFUN_CHARATCURSOR:
2812 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2813 if (pos < bv_->getLyXText()->cursor.par()->size())
2814 owner_->getLyXFunc()->setMessage(
2815 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2817 owner_->getLyXFunc()->setMessage("EOF");
2822 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2824 + tostr(bv_->getLyXText()->cursor.y()));
2831 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2832 lyxerr << "SETXY: Could not parse coordinates in '"
2833 << argument << std::endl;
2835 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2839 case LFUN_GETLAYOUT:
2840 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2845 LyXFont & font = bv_->getLyXText()->current_font;
2846 if (font.shape() == LyXFont::ITALIC_SHAPE)
2847 owner_->getLyXFunc()->setMessage("E");
2848 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2849 owner_->getLyXFunc()->setMessage("N");
2851 owner_->getLyXFunc()->setMessage("0");
2856 // --- accented characters ---------------------------
2859 case LFUN_CIRCUMFLEX:
2869 case LFUN_SPECIAL_CARON:
2872 case LFUN_HUNG_UMLAUT:
2875 if (argument.empty()) {
2877 owner_->getLyXFunc()->handleKeyFunc(action);
2879 owner_->getLyXFunc()->handleKeyFunc(action);
2880 owner_->getIntl()->getTrans()
2881 .TranslateAndInsert(argument[0], bv_->getLyXText());
2882 update(bv_->getLyXText(),
2884 | BufferView::FITCUR
2885 | BufferView::CHANGE);
2889 case LFUN_MATH_MACRO:
2890 mathDispatchMathMacro(bv_, argument);
2893 case LFUN_MATH_DELIM:
2894 mathDispatchMathDelim(bv_, argument);
2897 case LFUN_INSERT_MATRIX:
2898 mathDispatchInsertMatrix(bv_, argument);
2901 case LFUN_INSERT_MATH:
2902 mathDispatchInsertMath(bv_, argument);
2905 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2906 mathDispatchMathImportSelection(bv_, argument);
2909 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2910 mathDispatchMathDisplay(bv_, argument);
2913 case LFUN_MATH_MODE: // Open or create an inlined math inset
2914 mathDispatchMathMode(bv_, argument);
2917 case LFUN_CITATION_INSERT:
2919 InsetCommandParams p;
2920 p.setFromString( argument );
2922 InsetCitation * inset = new InsetCitation( p );
2923 if (!insertInset(inset))
2926 updateInset( inset, true );
2930 case LFUN_INSERT_BIBTEX:
2932 // ale970405+lasgoutt970425
2933 // The argument can be up to two tokens separated
2934 // by a space. The first one is the bibstyle.
2935 string const db = token(argument, ' ', 0);
2936 string const bibstyle = token(argument, ' ', 1);
2938 InsetCommandParams p( "BibTeX", db, bibstyle );
2939 InsetBibtex * inset = new InsetBibtex(p);
2941 if (insertInset(inset)) {
2942 if (argument.empty())
2949 // BibTeX data bases
2950 case LFUN_BIBDB_ADD:
2952 InsetBibtex * inset =
2953 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2955 inset->addDatabase(argument);
2960 case LFUN_BIBDB_DEL:
2962 InsetBibtex * inset =
2963 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2965 inset->delDatabase(argument);
2970 case LFUN_BIBTEX_STYLE:
2972 InsetBibtex * inset =
2973 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2975 inset->setOptions(argument);
2980 case LFUN_INDEX_CREATE:
2982 InsetCommandParams p("index");
2983 if (argument.empty()) {
2984 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2985 p.setContents(idxstring);
2987 p.setContents(argument);
2990 owner_->getDialogs()->createIndex(p.getAsString());
2994 case LFUN_INDEX_INSERT:
2996 InsetCommandParams p;
2997 p.setFromString(argument);
2998 InsetIndex * inset = new InsetIndex(p);
3000 if (!insertInset(inset))
3003 updateInset(inset, true);
3007 case LFUN_INDEX_INSERT_LAST:
3009 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3010 if (!idxstring.empty()) {
3011 owner_->message(_("Word `")
3012 + idxstring + _(("' indexed.")));
3013 InsetCommandParams p("index", idxstring);
3014 InsetIndex * inset = new InsetIndex(p);
3016 if (!insertInset(inset))
3019 updateInset(inset, true);
3024 case LFUN_INDEX_PRINT:
3026 InsetCommandParams p("printindex");
3027 Inset * inset = new InsetPrintIndex(p);
3028 if (!insertInset(inset, "Standard"))
3033 case LFUN_PARENTINSERT:
3035 lyxerr << "arg " << argument << endl;
3036 InsetCommandParams p( "lyxparent", argument );
3037 Inset * inset = new InsetParent(p, *buffer_);
3038 if (!insertInset(inset, "Standard"))
3044 case LFUN_CHILD_INSERT:
3046 InsetInclude::Params p;
3047 p.cparams.setFromString(argument);
3048 p.masterFilename_ = buffer_->fileName();
3050 InsetInclude * inset = new InsetInclude(p);
3051 if (!insertInset(inset))
3054 updateInset(inset, true);
3055 bv_->owner()->getDialogs()->showInclude(inset);
3060 case LFUN_FLOAT_LIST:
3062 // We should check the argument for validity. (Lgb)
3063 Inset * inset = new InsetFloatList(argument);
3064 if (!insertInset(inset, "Standard"))
3069 case LFUN_THESAURUS_ENTRY:
3071 string arg = argument;
3074 arg = bv_->getLyXText()->selectionAsString(buffer_);
3077 if (arg.size() > 100 || arg.empty()) {
3078 // Get word or selection
3079 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3080 arg = bv_->getLyXText()->selectionAsString(buffer_);
3081 // FIXME: where is getLyXText()->unselect(bv_) ?
3085 bv_->owner()->getDialogs()->showThesaurus(arg);
3089 case LFUN_SELFINSERT:
3091 if (argument.empty()) break;
3093 /* Automatically delete the currently selected
3094 * text and replace it with what is being
3095 * typed in now. Depends on lyxrc settings
3096 * "auto_region_delete", which defaults to
3099 LyXText * lt = bv_->getLyXText();
3101 if (lyxrc.auto_region_delete) {
3102 if (lt->selection.set()) {
3103 lt->cutSelection(bv_, false, false);
3106 | BufferView::FITCUR
3107 | BufferView::CHANGE);
3112 LyXFont const old_font(lt->real_current_font);
3114 string::const_iterator cit = argument.begin();
3115 string::const_iterator end = argument.end();
3116 for (; cit != end; ++cit) {
3117 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3122 | BufferView::FITCUR
3123 | BufferView::CHANGE);
3125 lt->selection.cursor = lt->cursor;
3126 moveCursorUpdate(false);
3128 // real_current_font.number can change so we need to
3129 // update the minibuffer
3130 if (old_font != lt->real_current_font)
3131 owner_->showState();
3136 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3138 time_t now_time_t = time(NULL);
3139 struct tm * now_tm = localtime(&now_time_t);
3140 setlocale(LC_TIME, "");
3142 if (!argument.empty())
3145 arg = lyxrc.date_insert_format;
3147 int const datetmp_len =
3148 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3150 LyXText * lt = bv_->getLyXText();
3152 for (int i = 0; i < datetmp_len; i++) {
3153 lt->insertChar(bv_, datetmp[i]);
3156 | BufferView::FITCUR
3157 | BufferView::CHANGE);
3160 lt->selection.cursor = lt->cursor;
3161 moveCursorUpdate(false);
3165 case LFUN_UNKNOWN_ACTION:
3166 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3177 void BufferView::Pimpl::newline()
3180 LyXText * lt = bv_->getLyXText();
3184 | BufferView::FITCUR);
3185 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3188 | BufferView::FITCUR
3189 | BufferView::CHANGE);
3194 void BufferView::Pimpl::hfill()
3197 LyXText * lt = bv_->getLyXText();
3201 | BufferView::FITCUR);
3202 lt->insertChar(bv_, Paragraph::META_HFILL);
3205 | BufferView::FITCUR
3206 | BufferView::CHANGE);
3211 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3215 update(lt, BufferView::SELECT|BufferView::FITCUR);
3216 InsetSpecialChar * new_inset =
3217 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3218 #ifdef WITH_WARNINGS
3219 #warning Why is this code different from specialChar() below? (JMarc)
3220 // the code in specialChar is a generic version of what used to exist
3221 // for other special chars. I did not merge this case because of the
3222 // call to updateInset(), but what does it do?
3224 if (!insertInset(new_inset))
3227 updateInset(new_inset, true);
3232 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3235 LyXText * lt = bv_->getLyXText();
3238 update(lt, BufferView::SELECT|BufferView::FITCUR);
3239 InsetSpecialChar * new_inset =
3240 new InsetSpecialChar(kind);
3241 insertInset(new_inset);
3246 void BufferView::Pimpl::smartQuote()
3249 LyXText * lt = bv_->getLyXText();
3251 if (lt->cursor.pos())
3252 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3258 LyXLayout const & style = textclasslist.Style(
3259 bv_->buffer()->params.textclass,
3260 lt->cursor.par()->getLayout());
3262 if (style.pass_thru ||
3263 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3264 Dispatch(LFUN_SELFINSERT, "\"");
3268 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3270 if (insertInset(inset))
3277 // Open and lock an updatable inset
3278 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3280 LyXText * lt = bv_->getLyXText();
3284 if (!insertInset(new_inset)) {
3288 new_inset->edit(bv_, !behind);
3293 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3295 // if we are in a locking inset we should try to insert the
3296 // inset there otherwise this is a illegal function now
3297 if (bv_->theLockingInset()) {
3298 if (bv_->theLockingInset()->insetAllowed(inset))
3299 return bv_->theLockingInset()->insertInset(bv_, inset);
3303 // not quite sure if we want this...
3304 setCursorParUndo(bv_);
3307 beforeChange(bv_->text);
3308 if (!lout.empty()) {
3309 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3310 bv_->text->breakParagraph(bv_);
3311 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3313 if (bv_->text->cursor.par()->size()) {
3314 bv_->text->cursorLeft(bv_);
3316 bv_->text->breakParagraph(bv_);
3317 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3320 pair<bool, LyXTextClass::size_type> lres =
3321 textclasslist.NumberOfLayout(buffer_->params
3323 LyXTextClass::size_type lay;
3324 if (lres.first != false) {
3328 // layout not fount using default "Standard" (0)
3332 bv_->text->setLayout(bv_, lay);
3334 bv_->text->setParagraph(bv_, 0, 0,
3336 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3341 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3344 bv_->text->insertInset(bv_, inset);
3345 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3352 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3357 // first check for locking insets
3358 if (bv_->theLockingInset()) {
3359 if (bv_->theLockingInset() == inset) {
3360 if (bv_->text->updateInset(bv_, inset)) {
3363 buffer_->markDirty();
3368 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3369 if (bv_->text->updateInset(bv_,
3370 bv_->theLockingInset())) {
3373 buffer_->markDirty();
3381 // then check the current buffer
3384 update(bv_->text, BufferView::UPDATE);
3385 if (bv_->text->updateInset(bv_, inset)) {
3389 | BufferView::FITCUR
3390 | BufferView::CHANGE);
3392 update(bv_->text, SELECT);
3400 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3403 if (!available()) return;
3406 beforeChange(bv_->text);
3407 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3411 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3412 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3413 if (find(codes.begin(), codes.end(), inset->lyxCode())
3416 static_cast<InsetCommand const *>(inset)->getContents();
3419 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3420 if (bv_->text->cursor.pos()
3421 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3422 LyXCursor tmp = bv_->text->cursor;
3423 bv_->text->cursor.par(bv_->text->firstParagraph());
3424 bv_->text->cursor.pos(0);
3425 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3426 bv_->text->cursor = tmp;
3427 bv_->owner()->message(_("No more insets"));
3430 bv_->owner()->message(_("No more insets"));
3433 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3434 bv_->text->selection.cursor = bv_->text->cursor;
3438 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3440 gotoInset(vector<Inset::Code>(1, code), same_content);