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()
1221 text->real_current_font.latex() != LyXFont::ON
1224 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1225 owner_->getIntl()->KeyMapSec();
1227 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1228 owner_->getIntl()->KeyMapPrim();
1233 void BufferView::Pimpl::insetSleep()
1235 if (bv_->theLockingInset() && !inset_slept) {
1236 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1237 bv_->theLockingInset()->insetUnlock(bv_);
1243 void BufferView::Pimpl::insetWakeup()
1245 if (bv_->theLockingInset() && inset_slept) {
1246 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1247 inset_slept = false;
1252 void BufferView::Pimpl::insetUnlock()
1254 if (bv_->theLockingInset()) {
1256 bv_->theLockingInset()->insetUnlock(bv_);
1257 bv_->theLockingInset(0);
1259 inset_slept = false;
1264 bool BufferView::Pimpl::focus() const
1266 return workarea_.hasFocus();
1270 void BufferView::Pimpl::focus(bool f)
1272 if (f) workarea_.setFocus();
1276 bool BufferView::Pimpl::active() const
1278 return workarea_.active();
1282 bool BufferView::Pimpl::belowMouse() const
1284 return workarea_.belowMouse();
1288 void BufferView::Pimpl::showCursor()
1290 if (screen_.get()) {
1291 if (bv_->theLockingInset())
1292 bv_->theLockingInset()->showInsetCursor(bv_);
1294 screen_->showCursor(bv_->text, bv_);
1299 void BufferView::Pimpl::hideCursor()
1301 if (screen_.get()) {
1302 if (!bv_->theLockingInset())
1303 // bv_->theLockingInset()->hideInsetCursor(bv_);
1305 screen_->hideCursor();
1310 void BufferView::Pimpl::toggleSelection(bool b)
1312 if (screen_.get()) {
1313 if (bv_->theLockingInset())
1314 bv_->theLockingInset()->toggleSelection(bv_, b);
1315 screen_->toggleSelection(bv_->text, bv_, b);
1320 void BufferView::Pimpl::toggleToggle()
1323 screen_->toggleToggle(bv_->text, bv_);
1327 void BufferView::Pimpl::center()
1329 beforeChange(bv_->text);
1330 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1331 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1333 screen_->draw(bv_->text, bv_, 0);
1335 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1340 void BufferView::Pimpl::pasteClipboard(bool asPara)
1342 if (!buffer_) return;
1344 screen_->hideCursor();
1345 beforeChange(bv_->text);
1347 string const clip(workarea_.getClipboard());
1349 if (clip.empty()) return;
1352 bv_->text->insertStringAsParagraphs(bv_, clip);
1354 bv_->text->insertStringAsLines(bv_, clip);
1356 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1360 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1362 workarea_.putClipboard(stuff);
1367 * Dispatch functions for actions which can be valid for BufferView->text
1368 * and/or InsetText->text!!!
1373 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1375 LyXText * lt = bv_->getLyXText();
1377 if (selecting || lt->selection.mark()) {
1378 lt->setSelection(bv_);
1382 update(lt, BufferView::SELECT|BufferView::FITCUR);
1385 /* ---> Everytime the cursor is moved, show the current font state. */
1386 // should this too me moved out of this func?
1387 //owner->showState();
1392 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1394 LyXCursor cursor = bv_->getLyXText()->cursor;
1395 Buffer::inset_iterator it =
1396 find_if(Buffer::inset_iterator(
1397 cursor.par(), cursor.pos()),
1398 buffer_->inset_iterator_end(),
1399 lyx::compare_memfun(&Inset::lyxCode, code));
1400 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1404 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1406 string filename = filen;
1408 if (filename.empty()) {
1409 // Launch a file browser
1410 string initpath = lyxrc.document_path;
1413 string const trypath = owner_->buffer()->filepath;
1414 // If directory is writeable, use this as default.
1415 if (IsDirWriteable(trypath))
1419 FileDialog fileDlg(bv_->owner(),
1420 _("Select LyX document to insert"),
1422 make_pair(string(_("Documents")),
1423 string(lyxrc.document_path)),
1424 make_pair(string(_("Examples")),
1425 string(AddPath(system_lyxdir, "examples"))));
1427 FileDialog::Result result =
1428 fileDlg.Select(initpath,
1429 _("*.lyx| LyX Documents (*.lyx)"));
1431 if (result.first == FileDialog::Later)
1434 filename = result.second;
1436 // check selected filename
1437 if (filename.empty()) {
1438 owner_->message(_("Canceled."));
1443 // get absolute path of file and add ".lyx" to the filename if
1445 filename = FileSearch(string(), filename, "lyx");
1447 string const disp_fn(MakeDisplayPath(filename));
1450 s1 << _("Inserting document") << ' '
1451 << disp_fn << " ...";
1452 owner_->message(s1.str().c_str());
1453 bool const res = bv_->insertLyXFile(filename);
1456 str << _("Document") << ' ' << disp_fn
1457 << ' ' << _("inserted.");
1458 owner_->message(str.str().c_str());
1461 str << _("Could not insert document") << ' '
1463 owner_->message(str.str().c_str());
1468 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1470 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1471 << action <<"] arg[" << argument << "]" << endl;
1474 // --- Misc -------------------------------------------
1478 LyXText * lt = bv_->getLyXText();
1479 lt->toggleAppendix(bv_);
1482 | BufferView::FITCUR
1483 | BufferView::CHANGE);
1488 case LFUN_TOC_INSERT:
1490 InsetCommandParams p;
1491 p.setCmdName("tableofcontents");
1492 Inset * inset = new InsetTOC(p);
1493 if (!insertInset(inset, "Standard"))
1498 case LFUN_TABULAR_FEATURE:
1499 case LFUN_SCROLL_INSET:
1500 // this is not handled here as this funktion is only aktive
1501 // if we have a locking_inset and that one is (or contains)
1505 case LFUN_INSET_GRAPHICS:
1507 Inset * new_inset = new InsetGraphics;
1508 if (!insertInset(new_inset)) {
1511 // this is need because you don't use a inset->Edit()
1512 updateInset(new_inset, true);
1513 new_inset->edit(bv_);
1523 case LFUN_PASTESELECTION:
1525 bool asPara = false;
1526 if (argument == "paragraph") asPara = true;
1527 pasteClipboard(asPara);
1539 case LFUN_LAYOUT_COPY:
1540 bv_->copyEnvironment();
1543 case LFUN_LAYOUT_PASTE:
1544 bv_->pasteEnvironment();
1548 case LFUN_GOTOERROR:
1549 gotoInset(Inset::ERROR_CODE, false);
1553 gotoInset(Inset::IGNORE_CODE, false);
1556 case LFUN_REFERENCE_GOTO:
1558 vector<Inset::Code> tmp;
1559 tmp.push_back(Inset::LABEL_CODE);
1560 tmp.push_back(Inset::REF_CODE);
1561 gotoInset(tmp, true);
1565 case LFUN_HYPHENATION:
1566 specialChar(InsetSpecialChar::HYPHENATION);
1569 case LFUN_LIGATURE_BREAK:
1570 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1574 specialChar(InsetSpecialChar::LDOTS);
1577 case LFUN_END_OF_SENTENCE:
1578 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1581 case LFUN_MENU_SEPARATOR:
1582 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1590 changeDepth(bv_, bv_->getLyXText(), 0);
1593 case LFUN_DEPTH_MIN:
1594 changeDepth(bv_, bv_->getLyXText(), -1);
1597 case LFUN_DEPTH_PLUS:
1598 changeDepth(bv_, bv_->getLyXText(), 1);
1602 owner_->getDialogs()->setUserFreeFont();
1609 owner_->showState();
1613 case LFUN_FILE_INSERT:
1615 MenuInsertLyXFile(argument);
1619 case LFUN_FILE_INSERT_ASCII_PARA:
1620 InsertAsciiFile(bv_, argument, true);
1623 case LFUN_FILE_INSERT_ASCII:
1624 InsertAsciiFile(bv_, argument, false);
1629 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1630 << argument << endl;
1632 // Derive layout number from given argument (string)
1633 // and current buffer's textclass (number). */
1634 LyXTextClassList::ClassList::size_type tclass =
1635 buffer_->params.textclass;
1636 pair <bool, LyXTextClass::size_type> layout =
1637 textclasslist.NumberOfLayout(tclass, argument);
1639 // If the entry is obsolete, use the new one instead.
1641 string obs = textclasslist.Style(tclass,layout.second)
1645 textclasslist.NumberOfLayout(tclass, obs);
1648 // see if we found the layout number:
1649 if (!layout.first) {
1650 owner_->getLyXFunc()->setErrorMessage(
1651 string(N_("Layout ")) + argument +
1656 if (current_layout != layout.second) {
1657 LyXText * lt = bv_->getLyXText();
1659 current_layout = layout.second;
1662 | BufferView::FITCUR);
1663 lt->setLayout(bv_, layout.second);
1664 owner_->setLayout(layout.second);
1667 | BufferView::FITCUR
1668 | BufferView::CHANGE);
1675 lang(bv_, argument);
1677 owner_->showState();
1682 owner_->showState();
1687 owner_->showState();
1692 owner_->showState();
1697 owner_->showState();
1702 owner_->showState();
1707 owner_->showState();
1712 owner_->showState();
1715 case LFUN_UNDERLINE:
1717 owner_->showState();
1720 case LFUN_FONT_SIZE:
1721 fontSize(bv_, argument);
1722 owner_->showState();
1725 case LFUN_FONT_STATE:
1726 owner_->getLyXFunc()->setMessage(currentState(bv_));
1729 case LFUN_UPCASE_WORD:
1731 LyXText * lt = bv_->getLyXText();
1735 | BufferView::FITCUR);
1736 lt->changeCase(bv_, LyXText::text_uppercase);
1737 if (lt->inset_owner)
1738 updateInset(lt->inset_owner, true);
1741 | BufferView::FITCUR
1742 | BufferView::CHANGE);
1746 case LFUN_LOWCASE_WORD:
1748 LyXText * lt = bv_->getLyXText();
1750 update(lt, BufferView::SELECT|BufferView::FITCUR);
1751 lt->changeCase(bv_, LyXText::text_lowercase);
1752 if (lt->inset_owner)
1753 updateInset(lt->inset_owner, true);
1756 | BufferView::FITCUR
1757 | BufferView::CHANGE);
1761 case LFUN_CAPITALIZE_WORD:
1763 LyXText * lt = bv_->getLyXText();
1765 update(lt, BufferView::SELECT|BufferView::FITCUR);
1766 lt->changeCase(bv_, LyXText::text_capitalization);
1767 if (lt->inset_owner)
1768 updateInset(lt->inset_owner, true);
1771 | BufferView::FITCUR
1772 | BufferView::CHANGE);
1776 case LFUN_TRANSPOSE_CHARS:
1778 LyXText * lt = bv_->getLyXText();
1780 update(lt, BufferView::SELECT|BufferView::FITCUR);
1781 lt->transposeChars(*bv_);
1782 if (lt->inset_owner)
1783 updateInset(lt->inset_owner, true);
1786 | BufferView::FITCUR
1787 | BufferView::CHANGE);
1792 case LFUN_INSERT_LABEL:
1793 MenuInsertLabel(bv_, argument);
1796 case LFUN_REF_INSERT:
1797 if (argument.empty()) {
1798 InsetCommandParams p("ref");
1799 owner_->getDialogs()->createRef(p.getAsString());
1801 InsetCommandParams p;
1802 p.setFromString(argument);
1804 InsetRef * inset = new InsetRef(p, *buffer_);
1805 if (!insertInset(inset))
1808 updateInset(inset, true);
1812 case LFUN_BOOKMARK_SAVE:
1813 savePosition(strToUnsignedInt(argument));
1816 case LFUN_BOOKMARK_GOTO:
1817 restorePosition(strToUnsignedInt(argument));
1822 string label(argument);
1823 if (label.empty()) {
1825 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1827 label = inset->getContents();
1832 if (!label.empty()) {
1833 //bv_->savePosition(0);
1834 if (!bv_->gotoLabel(label))
1835 WriteAlert(_("Error"),
1836 _("Couldn't find this label"),
1837 _("in current document."));
1842 // --- Cursor Movements -----------------------------
1845 LyXText * lt = bv_->getLyXText();
1847 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1848 if (!lt->selection.mark())
1850 update(lt, BufferView::SELECT|BufferView::FITCUR);
1852 lt->cursorLeft(bv_, false);
1853 if (lt->cursor.pos() < lt->cursor.par()->size()
1854 && lt->cursor.par()->getChar(lt->cursor.pos())
1855 == Paragraph::META_INSET
1856 && lt->cursor.par()->getInset(lt->cursor.pos())
1857 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1858 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1859 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1861 tmpinset->edit(bv_, false);
1863 tmpinset->edit(bv_);
1867 lt->cursorRight(bv_, false);
1869 moveCursorUpdate(false);
1870 owner_->showState();
1876 // This is soooo ugly. Isn`t it possible to make
1877 // it simpler? (Lgb)
1878 LyXText * lt = bv_->getLyXText();
1879 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1880 if (!lt->selection.mark())
1882 update(lt, BufferView::SELECT|BufferView::FITCUR);
1883 LyXCursor const cur = lt->cursor;
1885 lt->cursorLeft(bv_, false);
1886 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1887 lt->cursor.pos() < lt->cursor.par()->size() &&
1888 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1889 Paragraph::META_INSET) &&
1890 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1891 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1892 == Inset::HIGHLY_EDITABLE))
1894 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1895 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1897 tmpinset->edit(bv_);
1899 tmpinset->edit(bv_, false);
1903 lt->cursorRight(bv_, false);
1906 moveCursorUpdate(false);
1907 owner_->showState();
1913 LyXText * lt = bv_->getLyXText();
1915 if (!lt->selection.mark())
1917 update(lt, BufferView::UPDATE);
1920 moveCursorUpdate(false);
1921 owner_->showState();
1927 LyXText * lt = bv_->getLyXText();
1929 if (!lt->selection.mark())
1931 update(lt, BufferView::UPDATE);
1932 lt->cursorDown(bv_);
1934 moveCursorUpdate(false);
1935 owner_->showState();
1939 case LFUN_UP_PARAGRAPH:
1941 LyXText * lt = bv_->getLyXText();
1943 if (!lt->selection.mark())
1945 update(lt, BufferView::UPDATE);
1946 lt->cursorUpParagraph(bv_);
1948 moveCursorUpdate(false);
1949 owner_->showState();
1953 case LFUN_DOWN_PARAGRAPH:
1955 LyXText * lt = bv_->getLyXText();
1957 if (!lt->selection.mark())
1959 update(lt, BufferView::UPDATE);
1960 lt->cursorDownParagraph(bv_);
1962 moveCursorUpdate(false);
1963 owner_->showState();
1969 LyXText * lt = bv_->getLyXText();
1971 if (!lt->selection.mark())
1973 update(lt, BufferView::UPDATE);
1976 moveCursorUpdate(false);
1977 owner_->showState();
1983 LyXText * lt = bv_->getLyXText();
1985 if (!lt->selection.mark())
1987 update(lt, BufferView::UPDATE);
1990 moveCursorUpdate(false);
1991 owner_->showState();
1997 LyXText * lt = bv_->getLyXText();
1999 if (!lt->selection.mark())
2001 update(lt, BufferView::SELECT|BufferView::FITCUR);
2002 lt->cursorHome(bv_);
2004 moveCursorUpdate(false);
2005 owner_->showState();
2011 LyXText * lt = bv_->getLyXText();
2013 if (!lt->selection.mark())
2016 BufferView::SELECT|BufferView::FITCUR);
2019 moveCursorUpdate(false);
2020 owner_->showState();
2024 case LFUN_SHIFT_TAB:
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2032 BufferView::SELECT|BufferView::FITCUR);
2035 moveCursorUpdate(false);
2036 owner_->showState();
2040 case LFUN_WORDRIGHT:
2042 LyXText * lt = bv_->getLyXText();
2044 if (!lt->selection.mark())
2046 update(lt, BufferView::SELECT|BufferView::FITCUR);
2047 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2048 lt->cursorLeftOneWord(bv_);
2050 lt->cursorRightOneWord(bv_);
2052 moveCursorUpdate(false);
2053 owner_->showState();
2059 LyXText * lt = bv_->getLyXText();
2061 if (!lt->selection.mark())
2063 update(lt, BufferView::SELECT|BufferView::FITCUR);
2064 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2065 lt->cursorRightOneWord(bv_);
2067 lt->cursorLeftOneWord(bv_);
2069 moveCursorUpdate(false);
2070 owner_->showState();
2074 case LFUN_BEGINNINGBUF:
2076 LyXText * lt = bv_->getLyXText();
2078 if (!lt->selection.mark())
2081 BufferView::SELECT|BufferView::FITCUR);
2084 moveCursorUpdate(false);
2085 owner_->showState();
2091 LyXText * lt = bv_->getLyXText();
2093 if (!lt->selection.mark())
2096 BufferView::SELECT|BufferView::FITCUR);
2097 lt->cursorBottom(bv_);
2099 moveCursorUpdate(false);
2100 owner_->showState();
2104 /* cursor selection ---------------------------- */
2107 LyXText * lt = bv_->getLyXText();
2110 BufferView::SELECT|BufferView::FITCUR);
2111 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2112 lt->cursorLeft(bv_);
2114 lt->cursorRight(bv_);
2116 moveCursorUpdate(true);
2117 owner_->showState();
2123 LyXText * lt = bv_->getLyXText();
2126 BufferView::SELECT|BufferView::FITCUR);
2127 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2128 lt->cursorRight(bv_);
2130 lt->cursorLeft(bv_);
2132 moveCursorUpdate(true);
2133 owner_->showState();
2139 LyXText * lt = bv_->getLyXText();
2142 BufferView::SELECT|BufferView::FITCUR);
2145 moveCursorUpdate(true);
2146 owner_->showState();
2152 LyXText * lt = bv_->getLyXText();
2155 BufferView::SELECT|BufferView::FITCUR);
2156 lt->cursorDown(bv_);
2158 moveCursorUpdate(true);
2159 owner_->showState();
2163 case LFUN_UP_PARAGRAPHSEL:
2165 LyXText * lt = bv_->getLyXText();
2168 BufferView::SELECT|BufferView::FITCUR);
2169 lt->cursorUpParagraph(bv_);
2171 moveCursorUpdate(true);
2172 owner_->showState();
2176 case LFUN_DOWN_PARAGRAPHSEL:
2178 LyXText * lt = bv_->getLyXText();
2181 BufferView::SELECT|BufferView::FITCUR);
2182 lt->cursorDownParagraph(bv_);
2184 moveCursorUpdate(true);
2185 owner_->showState();
2191 LyXText * lt = bv_->getLyXText();
2193 update(lt, BufferView::SELECT|BufferView::FITCUR);
2196 moveCursorUpdate(true);
2197 owner_->showState();
2203 LyXText * lt = bv_->getLyXText();
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2208 moveCursorUpdate(true);
2209 owner_->showState();
2215 LyXText * lt = bv_->getLyXText();
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2218 lt->cursorHome(bv_);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2237 case LFUN_WORDRIGHTSEL:
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2242 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2243 lt->cursorLeftOneWord(bv_);
2245 lt->cursorRightOneWord(bv_);
2247 moveCursorUpdate(true);
2248 owner_->showState();
2252 case LFUN_WORDLEFTSEL:
2254 LyXText * lt = bv_->getLyXText();
2256 update(lt, BufferView::SELECT|BufferView::FITCUR);
2257 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2258 lt->cursorRightOneWord(bv_);
2260 lt->cursorLeftOneWord(bv_);
2262 moveCursorUpdate(true);
2263 owner_->showState();
2267 case LFUN_BEGINNINGBUFSEL:
2269 LyXText * lt = bv_->getLyXText();
2271 if (lt->inset_owner)
2273 update(lt, BufferView::SELECT|BufferView::FITCUR);
2276 moveCursorUpdate(true);
2277 owner_->showState();
2281 case LFUN_ENDBUFSEL:
2283 LyXText * lt = bv_->getLyXText();
2285 if (lt->inset_owner)
2288 BufferView::SELECT|BufferView::FITCUR);
2289 lt->cursorBottom(bv_);
2291 moveCursorUpdate(true);
2292 owner_->showState();
2296 // --- text changing commands ------------------------
2297 case LFUN_BREAKLINE:
2299 LyXText * lt = bv_->getLyXText();
2302 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2305 | BufferView::FITCUR
2306 | BufferView::CHANGE);
2307 moveCursorUpdate(false);
2311 case LFUN_PROTECTEDSPACE:
2313 LyXText * lt = bv_->getLyXText();
2315 LyXLayout const & style = textclasslist
2316 .Style(buffer_->params.textclass,
2317 lt->cursor.par()->getLayout());
2319 if (style.free_spacing) {
2320 lt->insertChar(bv_, ' ');
2323 | BufferView::FITCUR
2324 | BufferView::CHANGE);
2328 moveCursorUpdate(false);
2334 LyXText * lt = bv_->getLyXText();
2336 if (lt->selection.mark()) {
2340 | BufferView::FITCUR);
2341 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2344 lt->selection.mark(true);
2347 | BufferView::FITCUR);
2348 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2350 lt->selection.cursor = lt->cursor;
2356 LyXText * lt = bv_->getLyXText();
2358 if (!lt->selection.set()) {
2360 lt->selection.cursor = lt->cursor;
2363 | BufferView::FITCUR
2364 | BufferView::CHANGE);
2365 // It is possible to make it a lot faster still
2366 // just comment out the line below...
2371 moveCursorUpdate(false);
2372 owner_->showState();
2377 case LFUN_DELETE_SKIP:
2379 LyXText * lt = bv_->getLyXText();
2381 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2383 LyXCursor cursor = lt->cursor;
2385 if (!lt->selection.set()) {
2386 if (cursor.pos() == cursor.par()->size()) {
2387 lt->cursorRight(bv_);
2388 cursor = lt->cursor;
2389 if (cursor.pos() == 0
2390 && !(cursor.par()->params().spaceTop()
2391 == VSpace (VSpace::NONE))) {
2394 cursor.par()->params().lineTop(),
2395 cursor.par()->params().lineBottom(),
2396 cursor.par()->params().pagebreakTop(),
2397 cursor.par()->params().pagebreakBottom(),
2398 VSpace(VSpace::NONE),
2399 cursor.par()->params().spaceBottom(),
2400 cursor.par()->params().align(),
2401 cursor.par()->params().labelWidthString(), 0);
2402 lt->cursorLeft(bv_);
2405 | BufferView::FITCUR
2406 | BufferView::CHANGE);
2408 lt->cursorLeft(bv_);
2410 lt->selection.cursor = lt->cursor;
2413 | BufferView::FITCUR
2414 | BufferView::CHANGE);
2418 lt->selection.cursor = lt->cursor;
2421 | BufferView::FITCUR
2422 | BufferView::CHANGE);
2430 /* -------> Delete word forward. */
2431 case LFUN_DELETE_WORD_FORWARD:
2432 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2433 bv_->getLyXText()->deleteWordForward(bv_);
2434 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2435 moveCursorUpdate(false);
2436 owner_->showState();
2439 /* -------> Delete word backward. */
2440 case LFUN_DELETE_WORD_BACKWARD:
2442 LyXText * lt = bv_->getLyXText();
2444 update(lt, BufferView::SELECT|BufferView::FITCUR);
2445 lt->deleteWordBackward(bv_);
2448 | BufferView::FITCUR
2449 | BufferView::CHANGE);
2450 moveCursorUpdate(false);
2451 owner_->showState();
2455 /* -------> Kill to end of line. */
2456 case LFUN_DELETE_LINE_FORWARD:
2458 LyXText * lt = bv_->getLyXText();
2460 update(lt, BufferView::SELECT|BufferView::FITCUR);
2461 lt->deleteLineForward(bv_);
2464 | BufferView::FITCUR
2465 | BufferView::CHANGE);
2466 moveCursorUpdate(false);
2470 /* -------> Set mark off. */
2473 LyXText * lt = bv_->getLyXText();
2476 update(lt, BufferView::SELECT|BufferView::FITCUR);
2477 lt->selection.cursor = lt->cursor;
2478 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2482 /* -------> Set mark on. */
2485 LyXText * lt = bv_->getLyXText();
2488 lt->selection.mark(true);
2489 update(lt, BufferView::SELECT|BufferView::FITCUR);
2490 lt->selection.cursor = lt->cursor;
2491 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2495 case LFUN_BACKSPACE:
2497 LyXText * lt = bv_->getLyXText();
2499 if (!lt->selection.set()) {
2500 if (owner_->getIntl()->getTrans().backspace()) {
2502 lt->selection.cursor = lt->cursor;
2505 | BufferView::FITCUR
2506 | BufferView::CHANGE);
2507 // It is possible to make it a lot faster still
2508 // just comment out the line below...
2514 owner_->showState();
2519 case LFUN_BACKSPACE_SKIP:
2521 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2522 LyXText * lt = bv_->getLyXText();
2524 LyXCursor cursor = lt->cursor;
2526 if (!lt->selection.set()) {
2527 if (cursor.pos() == 0
2528 && !(cursor.par()->params().spaceTop()
2529 == VSpace (VSpace::NONE))) {
2532 cursor.par()->params().lineTop(),
2533 cursor.par()->params().lineBottom(),
2534 cursor.par()->params().pagebreakTop(),
2535 cursor.par()->params().pagebreakBottom(),
2536 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2537 cursor.par()->params().align(),
2538 cursor.par()->params().labelWidthString(), 0);
2541 | BufferView::FITCUR
2542 | BufferView::CHANGE);
2545 lt->selection.cursor = cursor;
2548 | BufferView::FITCUR
2549 | BufferView::CHANGE);
2556 case LFUN_BREAKPARAGRAPH:
2558 LyXText * lt = bv_->getLyXText();
2561 lt->breakParagraph(bv_, 0);
2564 | BufferView::FITCUR
2565 | BufferView::CHANGE);
2566 lt->selection.cursor = lt->cursor;
2568 owner_->showState();
2572 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2574 LyXText * lt = bv_->getLyXText();
2577 lt->breakParagraph(bv_, 1);
2580 | BufferView::FITCUR
2581 | BufferView::CHANGE);
2582 lt->selection.cursor = lt->cursor;
2584 owner_->showState();
2588 case LFUN_BREAKPARAGRAPH_SKIP:
2590 // When at the beginning of a paragraph, remove
2591 // indentation and add a "defskip" at the top.
2592 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2593 LyXText * lt = bv_->getLyXText();
2595 LyXCursor cursor = lt->cursor;
2598 if (cursor.pos() == 0) {
2599 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2602 cursor.par()->params().lineTop(),
2603 cursor.par()->params().lineBottom(),
2604 cursor.par()->params().pagebreakTop(),
2605 cursor.par()->params().pagebreakBottom(),
2606 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2607 cursor.par()->params().align(),
2608 cursor.par()->params().labelWidthString(), 1);
2609 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2613 lt->breakParagraph(bv_, 0);
2614 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2619 | BufferView::FITCUR
2620 | BufferView::CHANGE);
2621 lt->selection.cursor = cursor;
2623 owner_->showState();
2627 case LFUN_PARAGRAPH_SPACING:
2629 LyXText * lt = bv_->getLyXText();
2631 Paragraph * par = lt->cursor.par();
2632 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2633 float cur_value = 1.0;
2634 if (cur_spacing == Spacing::Other) {
2635 cur_value = par->params().spacing().getValue();
2638 istringstream istr(argument.c_str());
2642 Spacing::Space new_spacing = cur_spacing;
2643 float new_value = cur_value;
2645 lyxerr << "Missing argument to `paragraph-spacing'"
2647 } else if (tmp == "single") {
2648 new_spacing = Spacing::Single;
2649 } else if (tmp == "onehalf") {
2650 new_spacing = Spacing::Onehalf;
2651 } else if (tmp == "double") {
2652 new_spacing = Spacing::Double;
2653 } else if (tmp == "other") {
2654 new_spacing = Spacing::Other;
2657 lyxerr << "new_value = " << tmpval << endl;
2660 } else if (tmp == "default") {
2661 new_spacing = Spacing::Default;
2663 lyxerr << _("Unknown spacing argument: ")
2664 << argument << endl;
2666 if (cur_spacing != new_spacing || cur_value != new_value) {
2667 par->params().spacing(Spacing(new_spacing, new_value));
2668 lt->redoParagraph(bv_);
2671 | BufferView::FITCUR
2672 | BufferView::CHANGE);
2677 case LFUN_INSET_TOGGLE:
2679 LyXText * lt = bv_->getLyXText();
2682 update(lt, BufferView::SELECT|BufferView::FITCUR);
2683 lt->toggleInset(bv_);
2684 update(lt, BufferView::SELECT|BufferView::FITCUR);
2696 InsetCommandParams p;
2697 if (action == LFUN_HTMLURL)
2698 p.setCmdName("htmlurl");
2700 p.setCmdName("url");
2701 owner_->getDialogs()->createUrl(p.getAsString());
2705 case LFUN_INSERT_URL:
2707 InsetCommandParams p;
2708 p.setFromString(argument);
2710 InsetUrl * inset = new InsetUrl(p);
2711 if (!insertInset(inset))
2714 updateInset(inset, true);
2718 case LFUN_INSET_TEXT:
2719 insertAndEditInset(new InsetText);
2722 case LFUN_INSET_ERT:
2723 insertAndEditInset(new InsetERT);
2726 case LFUN_INSET_EXTERNAL:
2727 insertAndEditInset(new InsetExternal);
2730 case LFUN_INSET_FOOTNOTE:
2731 insertAndEditInset(new InsetFoot);
2734 case LFUN_INSET_MARGINAL:
2735 insertAndEditInset(new InsetMarginal);
2738 case LFUN_INSET_MINIPAGE:
2739 insertAndEditInset(new InsetMinipage);
2742 case LFUN_INSERT_NOTE:
2743 insertAndEditInset(new InsetNote);
2746 case LFUN_INSET_FLOAT:
2747 // check if the float type exist
2748 if (floatList.typeExist(argument)) {
2749 insertAndEditInset(new InsetFloat(argument));
2751 lyxerr << "Non-existant float type: "
2752 << argument << endl;
2756 case LFUN_INSET_WIDE_FLOAT:
2758 // check if the float type exist
2759 if (floatList.typeExist(argument)) {
2760 InsetFloat * new_inset = new InsetFloat(argument);
2761 new_inset->wide(true);
2762 if (insertInset(new_inset))
2763 new_inset->edit(bv_);
2767 lyxerr << "Non-existant float type: "
2768 << argument << endl;
2775 case LFUN_INSET_LIST:
2776 insertAndEditInset(new InsetList);
2779 case LFUN_INSET_THEOREM:
2780 insertAndEditInset(new InsetTheorem);
2784 case LFUN_INSET_CAPTION:
2786 // Do we have a locking inset...
2787 if (bv_->theLockingInset()) {
2788 lyxerr << "Locking inset code: "
2789 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2790 InsetCaption * new_inset = new InsetCaption;
2791 new_inset->setOwner(bv_->theLockingInset());
2792 new_inset->setAutoBreakRows(true);
2793 new_inset->setDrawFrame(0, InsetText::LOCKED);
2794 new_inset->setFrameColor(0, LColor::captionframe);
2795 if (insertInset(new_inset))
2796 new_inset->edit(bv_);
2803 case LFUN_INSET_TABULAR:
2807 if (!argument.empty())
2808 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2809 InsetTabular * new_inset =
2810 new InsetTabular(*buffer_, r, c);
2812 bv_->getLyXText()->real_current_font.isRightToLeft();
2813 if (!open_new_inset(new_inset, rtl))
2818 // --- lyxserver commands ----------------------------
2820 case LFUN_CHARATCURSOR:
2822 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2823 if (pos < bv_->getLyXText()->cursor.par()->size())
2824 owner_->getLyXFunc()->setMessage(
2825 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2827 owner_->getLyXFunc()->setMessage("EOF");
2832 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2834 + tostr(bv_->getLyXText()->cursor.y()));
2841 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2842 lyxerr << "SETXY: Could not parse coordinates in '"
2843 << argument << std::endl;
2845 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2849 case LFUN_GETLAYOUT:
2850 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2855 LyXFont & font = bv_->getLyXText()->current_font;
2856 if (font.shape() == LyXFont::ITALIC_SHAPE)
2857 owner_->getLyXFunc()->setMessage("E");
2858 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2859 owner_->getLyXFunc()->setMessage("N");
2861 owner_->getLyXFunc()->setMessage("0");
2869 LyXFont & font = bv_->getLyXText()->current_font;
2870 if (font.latex() == LyXFont::ON)
2871 owner_->getLyXFunc()->setMessage("L");
2874 owner_->getLyXFunc()->setMessage("0");
2878 // --- accented characters ---------------------------
2881 case LFUN_CIRCUMFLEX:
2891 case LFUN_SPECIAL_CARON:
2894 case LFUN_HUNG_UMLAUT:
2897 if (argument.empty()) {
2899 owner_->getLyXFunc()->handleKeyFunc(action);
2901 owner_->getLyXFunc()->handleKeyFunc(action);
2902 owner_->getIntl()->getTrans()
2903 .TranslateAndInsert(argument[0], bv_->getLyXText());
2904 update(bv_->getLyXText(),
2906 | BufferView::FITCUR
2907 | BufferView::CHANGE);
2911 case LFUN_MATH_MACRO:
2912 mathDispatchMathMacro(bv_, argument);
2915 case LFUN_MATH_DELIM:
2916 mathDispatchMathDelim(bv_, argument);
2919 case LFUN_INSERT_MATRIX:
2920 mathDispatchInsertMatrix(bv_, argument);
2923 case LFUN_INSERT_MATH:
2924 mathDispatchInsertMath(bv_, argument);
2927 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2928 mathDispatchMathImportSelection(bv_, argument);
2931 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2932 mathDispatchMathDisplay(bv_, argument);
2935 case LFUN_MATH_MODE: // Open or create an inlined math inset
2936 mathDispatchMathMode(bv_, argument);
2939 case LFUN_CITATION_INSERT:
2941 InsetCommandParams p;
2942 p.setFromString( argument );
2944 InsetCitation * inset = new InsetCitation( p );
2945 if (!insertInset(inset))
2948 updateInset( inset, true );
2952 case LFUN_INSERT_BIBTEX:
2954 // ale970405+lasgoutt970425
2955 // The argument can be up to two tokens separated
2956 // by a space. The first one is the bibstyle.
2957 string const db = token(argument, ' ', 0);
2958 string bibstyle = token(argument, ' ', 1);
2959 if (bibstyle.empty())
2962 InsetCommandParams p( "BibTeX", db, bibstyle );
2963 InsetBibtex * inset = new InsetBibtex(p);
2965 if (insertInset(inset)) {
2966 if (argument.empty())
2973 // BibTeX data bases
2974 case LFUN_BIBDB_ADD:
2976 InsetBibtex * inset =
2977 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2979 inset->addDatabase(argument);
2984 case LFUN_BIBDB_DEL:
2986 InsetBibtex * inset =
2987 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2989 inset->delDatabase(argument);
2994 case LFUN_BIBTEX_STYLE:
2996 InsetBibtex * inset =
2997 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2999 inset->setOptions(argument);
3004 case LFUN_INDEX_CREATE:
3006 InsetCommandParams p("index");
3007 if (argument.empty()) {
3008 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3009 if (!idxstring.empty()) {
3010 p.setContents(idxstring);
3015 p.setContents(argument);
3018 owner_->getDialogs()->createIndex(p.getAsString());
3022 case LFUN_INDEX_INSERT:
3024 InsetCommandParams p;
3025 p.setFromString(argument);
3026 InsetIndex * inset = new InsetIndex(p);
3028 if (!insertInset(inset))
3031 updateInset(inset, true);
3035 case LFUN_INDEX_INSERT_LAST:
3037 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3038 if (!idxstring.empty()) {
3039 owner_->message(_("Word `")
3040 + idxstring + _(("' indexed.")));
3041 InsetCommandParams p("index", idxstring);
3042 InsetIndex * inset = new InsetIndex(p);
3044 if (!insertInset(inset))
3047 updateInset(inset, true);
3052 case LFUN_INDEX_PRINT:
3054 InsetCommandParams p("printindex");
3055 Inset * inset = new InsetPrintIndex(p);
3056 if (!insertInset(inset, "Standard"))
3061 case LFUN_PARENTINSERT:
3063 lyxerr << "arg " << argument << endl;
3064 InsetCommandParams p( "lyxparent", argument );
3065 Inset * inset = new InsetParent(p, *buffer_);
3066 if (!insertInset(inset, "Standard"))
3072 case LFUN_CHILD_INSERT:
3074 InsetInclude::Params p;
3075 p.cparams.setFromString(argument);
3076 p.masterFilename_ = buffer_->fileName();
3078 InsetInclude * inset = new InsetInclude(p);
3079 if (!insertInset(inset))
3082 updateInset(inset, true);
3083 bv_->owner()->getDialogs()->showInclude(inset);
3088 case LFUN_FLOAT_LIST:
3090 // We should check the argument for validity. (Lgb)
3091 Inset * inset = new InsetFloatList(argument);
3092 if (!insertInset(inset, "Standard"))
3097 case LFUN_THESAURUS_ENTRY:
3099 string arg = argument;
3102 arg = bv_->getLyXText()->selectionAsString(buffer_);
3105 if (arg.size() > 100 || arg.empty()) {
3106 // Get word or selection
3107 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3108 arg = bv_->getLyXText()->selectionAsString(buffer_);
3109 // FIXME: where is getLyXText()->unselect(bv_) ?
3113 bv_->owner()->getDialogs()->showThesaurus(arg);
3117 case LFUN_SELFINSERT:
3119 if (argument.empty()) break;
3121 /* Automatically delete the currently selected
3122 * text and replace it with what is being
3123 * typed in now. Depends on lyxrc settings
3124 * "auto_region_delete", which defaults to
3127 LyXText * lt = bv_->getLyXText();
3129 if (lyxrc.auto_region_delete) {
3130 if (lt->selection.set()) {
3131 lt->cutSelection(bv_, false);
3134 | BufferView::FITCUR
3135 | BufferView::CHANGE);
3140 LyXFont const old_font(lt->real_current_font);
3142 string::const_iterator cit = argument.begin();
3143 string::const_iterator end = argument.end();
3144 for (; cit != end; ++cit) {
3145 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3150 | BufferView::FITCUR
3151 | BufferView::CHANGE);
3153 lt->selection.cursor = lt->cursor;
3154 moveCursorUpdate(false);
3156 // real_current_font.number can change so we need to
3157 // update the minibuffer
3158 if (old_font != lt->real_current_font)
3159 owner_->showState();
3164 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3166 time_t now_time_t = time(NULL);
3167 struct tm * now_tm = localtime(&now_time_t);
3168 setlocale(LC_TIME, "");
3170 if (!argument.empty())
3173 arg = lyxrc.date_insert_format;
3175 int const datetmp_len =
3176 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3178 LyXText * lt = bv_->getLyXText();
3180 for (int i = 0; i < datetmp_len; i++) {
3181 lt->insertChar(bv_, datetmp[i]);
3184 | BufferView::FITCUR
3185 | BufferView::CHANGE);
3188 lt->selection.cursor = lt->cursor;
3189 moveCursorUpdate(false);
3193 case LFUN_UNKNOWN_ACTION:
3194 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3205 void BufferView::Pimpl::newline()
3208 LyXText * lt = bv_->getLyXText();
3212 | BufferView::FITCUR);
3213 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3216 | BufferView::FITCUR
3217 | BufferView::CHANGE);
3222 void BufferView::Pimpl::hfill()
3225 LyXText * lt = bv_->getLyXText();
3229 | BufferView::FITCUR);
3230 lt->insertChar(bv_, Paragraph::META_HFILL);
3233 | BufferView::FITCUR
3234 | BufferView::CHANGE);
3239 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3243 update(lt, BufferView::SELECT|BufferView::FITCUR);
3244 InsetSpecialChar * new_inset =
3245 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3246 #ifdef WITH_WARNINGS
3247 #warning Why is this code different from specialChar() below? (JMarc)
3248 // the code in specialChar is a generic version of what used to exist
3249 // for other special chars. I did not merge this case because of the
3250 // call to updateInset(), but what does it do?
3252 if (!insertInset(new_inset))
3255 updateInset(new_inset, true);
3260 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3263 LyXText * lt = bv_->getLyXText();
3266 update(lt, BufferView::SELECT|BufferView::FITCUR);
3267 InsetSpecialChar * new_inset =
3268 new InsetSpecialChar(kind);
3269 insertInset(new_inset);
3274 void BufferView::Pimpl::smartQuote()
3277 LyXText * lt = bv_->getLyXText();
3279 if (lt->cursor.pos())
3280 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3286 LyXLayout const & style = textclasslist.Style(
3287 bv_->buffer()->params.textclass,
3288 lt->cursor.par()->getLayout());
3290 if (style.pass_thru ||
3291 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3292 Dispatch(LFUN_SELFINSERT, "\"");
3296 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3298 if (insertInset(inset))
3305 // Open and lock an updatable inset
3306 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3308 LyXText * lt = bv_->getLyXText();
3312 if (!insertInset(new_inset)) {
3316 new_inset->edit(bv_, !behind);
3321 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3323 // if we are in a locking inset we should try to insert the
3324 // inset there otherwise this is a illegal function now
3325 if (bv_->theLockingInset()) {
3326 if (bv_->theLockingInset()->insetAllowed(inset))
3327 return bv_->theLockingInset()->insertInset(bv_, inset);
3331 // not quite sure if we want this...
3332 setCursorParUndo(bv_);
3335 beforeChange(bv_->text);
3336 if (!lout.empty()) {
3337 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3338 bv_->text->breakParagraph(bv_);
3339 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3341 if (bv_->text->cursor.par()->size()) {
3342 bv_->text->cursorLeft(bv_);
3344 bv_->text->breakParagraph(bv_);
3345 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3348 pair<bool, LyXTextClass::size_type> lres =
3349 textclasslist.NumberOfLayout(buffer_->params
3351 LyXTextClass::size_type lay;
3352 if (lres.first != false) {
3356 // layout not fount using default "Standard" (0)
3360 bv_->text->setLayout(bv_, lay);
3362 bv_->text->setParagraph(bv_, 0, 0,
3364 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3368 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3370 bv_->text->current_font.setLatex(LyXFont::OFF);
3374 bv_->text->insertInset(bv_, inset);
3375 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3382 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3387 // first check for locking insets
3388 if (bv_->theLockingInset()) {
3389 if (bv_->theLockingInset() == inset) {
3390 if (bv_->text->updateInset(bv_, inset)) {
3393 buffer_->markDirty();
3398 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3399 if (bv_->text->updateInset(bv_,
3400 bv_->theLockingInset())) {
3403 buffer_->markDirty();
3411 // then check the current buffer
3414 update(bv_->text, BufferView::UPDATE);
3415 if (bv_->text->updateInset(bv_, inset)) {
3419 | BufferView::FITCUR
3420 | BufferView::CHANGE);
3422 update(bv_->text, SELECT);
3430 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3433 if (!available()) return;
3436 beforeChange(bv_->text);
3437 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3441 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3442 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3443 if (find(codes.begin(), codes.end(), inset->lyxCode())
3446 static_cast<InsetCommand const *>(inset)->getContents();
3449 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3450 if (bv_->text->cursor.pos()
3451 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3452 LyXCursor tmp = bv_->text->cursor;
3453 bv_->text->cursor.par(bv_->text->firstParagraph());
3454 bv_->text->cursor.pos(0);
3455 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3456 bv_->text->cursor = tmp;
3457 bv_->owner()->message(_("No more insets"));
3460 bv_->owner()->message(_("No more insets"));
3463 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3464 bv_->text->selection.cursor = bv_->text->cursor;
3468 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3470 gotoInset(vector<Inset::Code>(1, code), same_content);