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_);
989 // Values used when calling update:
991 // -2 - update, move sel_cursor if selection, fitcursor
992 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
993 // 0 - update, move sel_cursor if selection, fitcursor
994 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
995 // 3 - update, move sel_cursor if selection
998 // a simple redraw of the parts that need refresh
1000 // move sel_cursor if selection -
1001 // the text's sel_cursor is moved if there is selection is progress
1004 // fitCursor() is called and the scrollbar updated
1007 // the buffer is marked dirty.
1016 // UPDATE_ONLY = UPDATE;
1017 // UPDATE_SELECT = UPDATE | SELECT;
1018 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1019 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1021 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1022 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1023 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1024 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1025 // update(3) -> update(1) -> update(1) -> update(SELECT)
1027 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1029 owner_->updateLayoutChoice();
1031 if (!text->selection.set() && (f & SELECT)) {
1032 text->selection.cursor = text->cursor;
1035 text->fullRebreak(bv_);
1037 if (text->inset_owner) {
1038 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1039 updateInset(text->inset_owner, true);
1049 buffer_->markDirty();
1054 // Callback for cursor timer
1055 void BufferView::Pimpl::cursorToggle()
1057 // Quite a nice place for asyncron Inset updating, isn't it?
1058 // Actually no! This is run even if no buffer exist... so (Lgb)
1060 cursor_timeout.restart();
1065 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1066 if (pid == -1) // error find out what is wrong
1067 ; // ignore it for now.
1069 sigchldchecker(pid, &status);
1071 updatelist.update(bv_);
1073 if (!screen_.get()) {
1074 cursor_timeout.restart();
1078 if (!bv_->theLockingInset()) {
1079 screen_->cursorToggle(bv_);
1081 bv_->theLockingInset()->toggleInsetCursor(bv_);
1084 cursor_timeout.restart();
1088 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1090 if (!text->cursor.row()->previous())
1093 int y = text->first;
1094 if (text->inset_owner)
1095 y += bv_->text->first;
1096 Row * cursorrow = text->cursor.row();
1097 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1099 // This is to allow jumping over large insets
1100 if ((cursorrow == text->cursor.row()))
1101 text->cursorUp(bv_);
1103 if (text->inset_owner ||
1104 text->cursor.row()->height() < workarea_.height())
1105 screen_->draw(bv_->text, bv_,
1107 - text->cursor.row()->baseline()
1108 + text->cursor.row()->height()
1109 - workarea_.height() + 1 );
1114 void BufferView::Pimpl::cursorNext(LyXText * text)
1116 if (!text->cursor.row()->next())
1119 int y = text->first + workarea_.height();
1120 // if (text->inset_owner)
1121 // y += bv_->text->first;
1122 text->getRowNearY(y);
1124 Row * cursorrow = text->cursor.row();
1125 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1127 // This is to allow jumping over large insets
1128 if ((cursorrow == bv_->text->cursor.row()))
1129 text->cursorDown(bv_);
1131 if (text->inset_owner ||
1132 text->cursor.row()->height() < workarea_.height())
1133 screen_->draw(bv_->text, bv_, text->cursor.y() -
1134 text->cursor.row()->baseline());
1139 bool BufferView::Pimpl::available() const
1141 if (buffer_ && bv_->text) return true;
1146 void BufferView::Pimpl::beforeChange(LyXText * text)
1149 text->clearSelection();
1153 void BufferView::Pimpl::savePosition(unsigned int i)
1155 if (i >= saved_positions_num)
1157 saved_positions[i] = Position(buffer_->fileName(),
1158 bv_->text->cursor.par()->id(),
1159 bv_->text->cursor.pos());
1162 str << _("Saved bookmark") << ' ' << i;
1163 owner_->message(str.str().c_str());
1168 void BufferView::Pimpl::restorePosition(unsigned int i)
1170 if (i >= saved_positions_num)
1173 string const fname = saved_positions[i].filename;
1175 beforeChange(bv_->text);
1177 if (fname != buffer_->fileName()) {
1178 Buffer * b = bufferlist.exists(fname) ?
1179 bufferlist.getBuffer(fname) :
1180 bufferlist.loadLyXFile(fname); // don't ask, just load it
1181 if (b != 0 ) buffer(b);
1184 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1188 bv_->text->setCursor(bv_, par,
1189 min(par->size(), saved_positions[i].par_pos));
1191 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1194 str << _("Moved to bookmark") << ' ' << i;
1195 owner_->message(str.str().c_str());
1200 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1202 if (i >= saved_positions_num)
1205 return !saved_positions[i].filename.empty();
1209 void BufferView::Pimpl::setState()
1211 if (!lyxrc.rtl_support)
1214 LyXText * text = bv_->getLyXText();
1215 if (text->real_current_font.isRightToLeft()
1218 text->real_current_font.latex() != LyXFont::ON
1221 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1222 owner_->getIntl()->KeyMapSec();
1224 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1225 owner_->getIntl()->KeyMapPrim();
1230 void BufferView::Pimpl::insetSleep()
1232 if (bv_->theLockingInset() && !inset_slept) {
1233 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1234 bv_->theLockingInset()->insetUnlock(bv_);
1240 void BufferView::Pimpl::insetWakeup()
1242 if (bv_->theLockingInset() && inset_slept) {
1243 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1244 inset_slept = false;
1249 void BufferView::Pimpl::insetUnlock()
1251 if (bv_->theLockingInset()) {
1253 bv_->theLockingInset()->insetUnlock(bv_);
1254 bv_->theLockingInset(0);
1256 inset_slept = false;
1261 bool BufferView::Pimpl::focus() const
1263 return workarea_.hasFocus();
1267 void BufferView::Pimpl::focus(bool f)
1269 if (f) workarea_.setFocus();
1273 bool BufferView::Pimpl::active() const
1275 return workarea_.active();
1279 bool BufferView::Pimpl::belowMouse() const
1281 return workarea_.belowMouse();
1285 void BufferView::Pimpl::showCursor()
1287 if (screen_.get()) {
1288 if (bv_->theLockingInset())
1289 bv_->theLockingInset()->showInsetCursor(bv_);
1291 screen_->showCursor(bv_->text, bv_);
1296 void BufferView::Pimpl::hideCursor()
1298 if (screen_.get()) {
1299 if (!bv_->theLockingInset())
1300 // bv_->theLockingInset()->hideInsetCursor(bv_);
1302 screen_->hideCursor();
1307 void BufferView::Pimpl::toggleSelection(bool b)
1309 if (screen_.get()) {
1310 if (bv_->theLockingInset())
1311 bv_->theLockingInset()->toggleSelection(bv_, b);
1312 screen_->toggleSelection(bv_->text, bv_, b);
1317 void BufferView::Pimpl::toggleToggle()
1320 screen_->toggleToggle(bv_->text, bv_);
1324 void BufferView::Pimpl::center()
1326 beforeChange(bv_->text);
1327 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1328 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1330 screen_->draw(bv_->text, bv_, 0);
1332 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1337 void BufferView::Pimpl::pasteClipboard(bool asPara)
1339 if (!buffer_) return;
1341 screen_->hideCursor();
1342 beforeChange(bv_->text);
1344 string const clip(workarea_.getClipboard());
1346 if (clip.empty()) return;
1349 bv_->text->insertStringAsParagraphs(bv_, clip);
1351 bv_->text->insertStringAsLines(bv_, clip);
1353 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1357 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1359 workarea_.putClipboard(stuff);
1364 * Dispatch functions for actions which can be valid for BufferView->text
1365 * and/or InsetText->text!!!
1370 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1372 LyXText * lt = bv_->getLyXText();
1374 if (selecting || lt->selection.mark()) {
1375 lt->setSelection(bv_);
1379 update(lt, BufferView::SELECT|BufferView::FITCUR);
1382 /* ---> Everytime the cursor is moved, show the current font state. */
1383 // should this too me moved out of this func?
1384 //owner->showState();
1389 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1391 LyXCursor cursor = bv_->getLyXText()->cursor;
1392 Buffer::inset_iterator it =
1393 find_if(Buffer::inset_iterator(
1394 cursor.par(), cursor.pos()),
1395 buffer_->inset_iterator_end(),
1396 lyx::compare_memfun(&Inset::lyxCode, code));
1397 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1401 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1403 string filename = filen;
1405 if (filename.empty()) {
1406 // Launch a file browser
1407 string initpath = lyxrc.document_path;
1410 string const trypath = owner_->buffer()->filepath;
1411 // If directory is writeable, use this as default.
1412 if (IsDirWriteable(trypath))
1416 FileDialog fileDlg(bv_->owner(),
1417 _("Select LyX document to insert"),
1419 make_pair(string(_("Documents")),
1420 string(lyxrc.document_path)),
1421 make_pair(string(_("Examples")),
1422 string(AddPath(system_lyxdir, "examples"))));
1424 FileDialog::Result result =
1425 fileDlg.Select(initpath,
1426 _("*.lyx| LyX Documents (*.lyx)"));
1428 if (result.first == FileDialog::Later)
1431 filename = result.second;
1433 // check selected filename
1434 if (filename.empty()) {
1435 owner_->message(_("Canceled."));
1440 // get absolute path of file and add ".lyx" to the filename if
1442 filename = FileSearch(string(), filename, "lyx");
1444 string const disp_fn(MakeDisplayPath(filename));
1447 s1 << _("Inserting document") << ' '
1448 << disp_fn << " ...";
1449 owner_->message(s1.str().c_str());
1450 bool const res = bv_->insertLyXFile(filename);
1453 str << _("Document") << ' ' << disp_fn
1454 << ' ' << _("inserted.");
1455 owner_->message(str.str().c_str());
1458 str << _("Could not insert document") << ' '
1460 owner_->message(str.str().c_str());
1465 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1467 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1468 << action <<"] arg[" << argument << "]" << endl;
1471 // --- Misc -------------------------------------------
1475 LyXText * lt = bv_->getLyXText();
1476 lt->toggleAppendix(bv_);
1479 | BufferView::FITCUR
1480 | BufferView::CHANGE);
1485 case LFUN_TOC_INSERT:
1487 InsetCommandParams p;
1488 p.setCmdName("tableofcontents");
1489 Inset * inset = new InsetTOC(p);
1490 if (!insertInset(inset, "Standard"))
1495 case LFUN_TABULAR_FEATURE:
1496 case LFUN_SCROLL_INSET:
1497 // this is not handled here as this funktion is only aktive
1498 // if we have a locking_inset and that one is (or contains)
1502 case LFUN_INSET_GRAPHICS:
1504 Inset * new_inset = new InsetGraphics;
1505 if (!insertInset(new_inset)) {
1508 // this is need because you don't use a inset->Edit()
1509 updateInset(new_inset, true);
1510 new_inset->edit(bv_);
1520 case LFUN_PASTESELECTION:
1522 bool asPara = false;
1523 if (argument == "paragraph") asPara = true;
1524 pasteClipboard(asPara);
1536 case LFUN_LAYOUT_COPY:
1537 bv_->copyEnvironment();
1540 case LFUN_LAYOUT_PASTE:
1541 bv_->pasteEnvironment();
1545 case LFUN_GOTOERROR:
1546 gotoInset(Inset::ERROR_CODE, false);
1550 gotoInset(Inset::IGNORE_CODE, false);
1553 case LFUN_REFERENCE_GOTO:
1555 vector<Inset::Code> tmp;
1556 tmp.push_back(Inset::LABEL_CODE);
1557 tmp.push_back(Inset::REF_CODE);
1558 gotoInset(tmp, true);
1562 case LFUN_HYPHENATION:
1563 specialChar(InsetSpecialChar::HYPHENATION);
1566 case LFUN_LIGATURE_BREAK:
1567 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1571 specialChar(InsetSpecialChar::LDOTS);
1574 case LFUN_END_OF_SENTENCE:
1575 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1578 case LFUN_MENU_SEPARATOR:
1579 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1587 changeDepth(bv_, bv_->getLyXText(), 0);
1590 case LFUN_DEPTH_MIN:
1591 changeDepth(bv_, bv_->getLyXText(), -1);
1594 case LFUN_DEPTH_PLUS:
1595 changeDepth(bv_, bv_->getLyXText(), 1);
1599 owner_->getDialogs()->setUserFreeFont();
1606 owner_->showState();
1610 case LFUN_FILE_INSERT:
1612 MenuInsertLyXFile(argument);
1616 case LFUN_FILE_INSERT_ASCII_PARA:
1617 InsertAsciiFile(bv_, argument, true);
1620 case LFUN_FILE_INSERT_ASCII:
1621 InsertAsciiFile(bv_, argument, false);
1626 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1627 << argument << endl;
1629 // Derive layout number from given argument (string)
1630 // and current buffer's textclass (number). */
1631 LyXTextClassList::ClassList::size_type tclass =
1632 buffer_->params.textclass;
1633 pair <bool, LyXTextClass::size_type> layout =
1634 textclasslist.NumberOfLayout(tclass, argument);
1636 // If the entry is obsolete, use the new one instead.
1638 string obs = textclasslist.Style(tclass,layout.second)
1642 textclasslist.NumberOfLayout(tclass, obs);
1645 // see if we found the layout number:
1646 if (!layout.first) {
1647 owner_->getLyXFunc()->setErrorMessage(
1648 string(N_("Layout ")) + argument +
1653 if (current_layout != layout.second) {
1654 LyXText * lt = bv_->getLyXText();
1656 current_layout = layout.second;
1659 | BufferView::FITCUR);
1660 lt->setLayout(bv_, layout.second);
1661 owner_->setLayout(layout.second);
1664 | BufferView::FITCUR
1665 | BufferView::CHANGE);
1672 lang(bv_, argument);
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1694 owner_->showState();
1699 owner_->showState();
1704 owner_->showState();
1709 owner_->showState();
1712 case LFUN_UNDERLINE:
1714 owner_->showState();
1717 case LFUN_FONT_SIZE:
1718 fontSize(bv_, argument);
1719 owner_->showState();
1722 case LFUN_FONT_STATE:
1723 owner_->getLyXFunc()->setMessage(currentState(bv_));
1726 case LFUN_UPCASE_WORD:
1728 LyXText * lt = bv_->getLyXText();
1732 | BufferView::FITCUR);
1733 lt->changeCase(bv_, LyXText::text_uppercase);
1734 if (lt->inset_owner)
1735 updateInset(lt->inset_owner, true);
1738 | BufferView::FITCUR
1739 | BufferView::CHANGE);
1743 case LFUN_LOWCASE_WORD:
1745 LyXText * lt = bv_->getLyXText();
1747 update(lt, BufferView::SELECT|BufferView::FITCUR);
1748 lt->changeCase(bv_, LyXText::text_lowercase);
1749 if (lt->inset_owner)
1750 updateInset(lt->inset_owner, true);
1753 | BufferView::FITCUR
1754 | BufferView::CHANGE);
1758 case LFUN_CAPITALIZE_WORD:
1760 LyXText * lt = bv_->getLyXText();
1762 update(lt, BufferView::SELECT|BufferView::FITCUR);
1763 lt->changeCase(bv_, LyXText::text_capitalization);
1764 if (lt->inset_owner)
1765 updateInset(lt->inset_owner, true);
1768 | BufferView::FITCUR
1769 | BufferView::CHANGE);
1773 case LFUN_TRANSPOSE_CHARS:
1775 LyXText * lt = bv_->getLyXText();
1777 update(lt, BufferView::SELECT|BufferView::FITCUR);
1778 lt->transposeChars(*bv_);
1779 if (lt->inset_owner)
1780 updateInset(lt->inset_owner, true);
1783 | BufferView::FITCUR
1784 | BufferView::CHANGE);
1789 case LFUN_INSERT_LABEL:
1790 MenuInsertLabel(bv_, argument);
1793 case LFUN_REF_INSERT:
1794 if (argument.empty()) {
1795 InsetCommandParams p("ref");
1796 owner_->getDialogs()->createRef(p.getAsString());
1798 InsetCommandParams p;
1799 p.setFromString(argument);
1801 InsetRef * inset = new InsetRef(p, *buffer_);
1802 if (!insertInset(inset))
1805 updateInset(inset, true);
1809 case LFUN_BOOKMARK_SAVE:
1810 savePosition(strToUnsignedInt(argument));
1813 case LFUN_BOOKMARK_GOTO:
1814 restorePosition(strToUnsignedInt(argument));
1819 string label(argument);
1820 if (label.empty()) {
1822 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1824 label = inset->getContents();
1829 if (!label.empty()) {
1830 //bv_->savePosition(0);
1831 if (!bv_->gotoLabel(label))
1832 WriteAlert(_("Error"),
1833 _("Couldn't find this label"),
1834 _("in current document."));
1839 // --- Cursor Movements -----------------------------
1842 LyXText * lt = bv_->getLyXText();
1844 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1845 if (!lt->selection.mark())
1847 update(lt, BufferView::SELECT|BufferView::FITCUR);
1849 lt->cursorLeft(bv_, false);
1850 if (lt->cursor.pos() < lt->cursor.par()->size()
1851 && lt->cursor.par()->getChar(lt->cursor.pos())
1852 == Paragraph::META_INSET
1853 && lt->cursor.par()->getInset(lt->cursor.pos())
1854 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1855 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1856 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1858 tmpinset->edit(bv_, false);
1860 tmpinset->edit(bv_);
1864 lt->cursorRight(bv_, false);
1866 moveCursorUpdate(false);
1867 owner_->showState();
1873 // This is soooo ugly. Isn`t it possible to make
1874 // it simpler? (Lgb)
1875 LyXText * lt = bv_->getLyXText();
1876 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1877 if (!lt->selection.mark())
1879 update(lt, BufferView::SELECT|BufferView::FITCUR);
1880 LyXCursor const cur = lt->cursor;
1882 lt->cursorLeft(bv_, false);
1883 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1884 lt->cursor.pos() < lt->cursor.par()->size() &&
1885 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1886 Paragraph::META_INSET) &&
1887 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1888 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1889 == Inset::HIGHLY_EDITABLE))
1891 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1892 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1894 tmpinset->edit(bv_);
1896 tmpinset->edit(bv_, false);
1900 lt->cursorRight(bv_, false);
1903 moveCursorUpdate(false);
1904 owner_->showState();
1910 LyXText * lt = bv_->getLyXText();
1912 if (!lt->selection.mark())
1914 update(lt, BufferView::UPDATE);
1917 moveCursorUpdate(false);
1918 owner_->showState();
1924 LyXText * lt = bv_->getLyXText();
1926 if (!lt->selection.mark())
1928 update(lt, BufferView::UPDATE);
1929 lt->cursorDown(bv_);
1931 moveCursorUpdate(false);
1932 owner_->showState();
1936 case LFUN_UP_PARAGRAPH:
1938 LyXText * lt = bv_->getLyXText();
1940 if (!lt->selection.mark())
1942 update(lt, BufferView::UPDATE);
1943 lt->cursorUpParagraph(bv_);
1945 moveCursorUpdate(false);
1946 owner_->showState();
1950 case LFUN_DOWN_PARAGRAPH:
1952 LyXText * lt = bv_->getLyXText();
1954 if (!lt->selection.mark())
1956 update(lt, BufferView::UPDATE);
1957 lt->cursorDownParagraph(bv_);
1959 moveCursorUpdate(false);
1960 owner_->showState();
1966 LyXText * lt = bv_->getLyXText();
1968 if (!lt->selection.mark())
1970 update(lt, BufferView::UPDATE);
1973 moveCursorUpdate(false);
1974 owner_->showState();
1980 LyXText * lt = bv_->getLyXText();
1982 if (!lt->selection.mark())
1984 update(lt, BufferView::UPDATE);
1987 moveCursorUpdate(false);
1988 owner_->showState();
1994 LyXText * lt = bv_->getLyXText();
1996 if (!lt->selection.mark())
1998 update(lt, BufferView::SELECT|BufferView::FITCUR);
1999 lt->cursorHome(bv_);
2001 moveCursorUpdate(false);
2002 owner_->showState();
2008 LyXText * lt = bv_->getLyXText();
2010 if (!lt->selection.mark())
2013 BufferView::SELECT|BufferView::FITCUR);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2021 case LFUN_SHIFT_TAB:
2024 LyXText * lt = bv_->getLyXText();
2026 if (!lt->selection.mark())
2029 BufferView::SELECT|BufferView::FITCUR);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2037 case LFUN_WORDRIGHT:
2039 LyXText * lt = bv_->getLyXText();
2041 if (!lt->selection.mark())
2043 update(lt, BufferView::SELECT|BufferView::FITCUR);
2044 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2045 lt->cursorLeftOneWord(bv_);
2047 lt->cursorRightOneWord(bv_);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2056 LyXText * lt = bv_->getLyXText();
2058 if (!lt->selection.mark())
2060 update(lt, BufferView::SELECT|BufferView::FITCUR);
2061 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2062 lt->cursorRightOneWord(bv_);
2064 lt->cursorLeftOneWord(bv_);
2066 moveCursorUpdate(false);
2067 owner_->showState();
2071 case LFUN_BEGINNINGBUF:
2073 LyXText * lt = bv_->getLyXText();
2075 if (!lt->selection.mark())
2078 BufferView::SELECT|BufferView::FITCUR);
2081 moveCursorUpdate(false);
2082 owner_->showState();
2088 LyXText * lt = bv_->getLyXText();
2090 if (!lt->selection.mark())
2093 BufferView::SELECT|BufferView::FITCUR);
2094 lt->cursorBottom(bv_);
2096 moveCursorUpdate(false);
2097 owner_->showState();
2101 /* cursor selection ---------------------------- */
2104 LyXText * lt = bv_->getLyXText();
2107 BufferView::SELECT|BufferView::FITCUR);
2108 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2109 lt->cursorLeft(bv_);
2111 lt->cursorRight(bv_);
2113 moveCursorUpdate(true);
2114 owner_->showState();
2120 LyXText * lt = bv_->getLyXText();
2123 BufferView::SELECT|BufferView::FITCUR);
2124 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2125 lt->cursorRight(bv_);
2127 lt->cursorLeft(bv_);
2129 moveCursorUpdate(true);
2130 owner_->showState();
2136 LyXText * lt = bv_->getLyXText();
2139 BufferView::SELECT|BufferView::FITCUR);
2142 moveCursorUpdate(true);
2143 owner_->showState();
2149 LyXText * lt = bv_->getLyXText();
2152 BufferView::SELECT|BufferView::FITCUR);
2153 lt->cursorDown(bv_);
2155 moveCursorUpdate(true);
2156 owner_->showState();
2160 case LFUN_UP_PARAGRAPHSEL:
2162 LyXText * lt = bv_->getLyXText();
2165 BufferView::SELECT|BufferView::FITCUR);
2166 lt->cursorUpParagraph(bv_);
2168 moveCursorUpdate(true);
2169 owner_->showState();
2173 case LFUN_DOWN_PARAGRAPHSEL:
2175 LyXText * lt = bv_->getLyXText();
2178 BufferView::SELECT|BufferView::FITCUR);
2179 lt->cursorDownParagraph(bv_);
2181 moveCursorUpdate(true);
2182 owner_->showState();
2188 LyXText * lt = bv_->getLyXText();
2190 update(lt, BufferView::SELECT|BufferView::FITCUR);
2193 moveCursorUpdate(true);
2194 owner_->showState();
2200 LyXText * lt = bv_->getLyXText();
2202 update(lt, BufferView::SELECT|BufferView::FITCUR);
2205 moveCursorUpdate(true);
2206 owner_->showState();
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2215 lt->cursorHome(bv_);
2217 moveCursorUpdate(true);
2218 owner_->showState();
2224 LyXText * lt = bv_->getLyXText();
2226 update(lt, BufferView::SELECT|BufferView::FITCUR);
2229 moveCursorUpdate(true);
2230 owner_->showState();
2234 case LFUN_WORDRIGHTSEL:
2236 LyXText * lt = bv_->getLyXText();
2238 update(lt, BufferView::SELECT|BufferView::FITCUR);
2239 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2240 lt->cursorLeftOneWord(bv_);
2242 lt->cursorRightOneWord(bv_);
2244 moveCursorUpdate(true);
2245 owner_->showState();
2249 case LFUN_WORDLEFTSEL:
2251 LyXText * lt = bv_->getLyXText();
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2254 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2255 lt->cursorRightOneWord(bv_);
2257 lt->cursorLeftOneWord(bv_);
2259 moveCursorUpdate(true);
2260 owner_->showState();
2264 case LFUN_BEGINNINGBUFSEL:
2266 LyXText * lt = bv_->getLyXText();
2268 if (lt->inset_owner)
2270 update(lt, BufferView::SELECT|BufferView::FITCUR);
2273 moveCursorUpdate(true);
2274 owner_->showState();
2278 case LFUN_ENDBUFSEL:
2280 LyXText * lt = bv_->getLyXText();
2282 if (lt->inset_owner)
2285 BufferView::SELECT|BufferView::FITCUR);
2286 lt->cursorBottom(bv_);
2288 moveCursorUpdate(true);
2289 owner_->showState();
2293 // --- text changing commands ------------------------
2294 case LFUN_BREAKLINE:
2296 LyXText * lt = bv_->getLyXText();
2299 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2302 | BufferView::FITCUR
2303 | BufferView::CHANGE);
2304 moveCursorUpdate(false);
2308 case LFUN_PROTECTEDSPACE:
2310 LyXText * lt = bv_->getLyXText();
2312 LyXLayout const & style = textclasslist
2313 .Style(buffer_->params.textclass,
2314 lt->cursor.par()->getLayout());
2316 if (style.free_spacing) {
2317 lt->insertChar(bv_, ' ');
2320 | BufferView::FITCUR
2321 | BufferView::CHANGE);
2325 moveCursorUpdate(false);
2331 LyXText * lt = bv_->getLyXText();
2333 if (lt->selection.mark()) {
2337 | BufferView::FITCUR);
2338 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2341 lt->selection.mark(true);
2344 | BufferView::FITCUR);
2345 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2347 lt->selection.cursor = lt->cursor;
2353 LyXText * lt = bv_->getLyXText();
2355 if (!lt->selection.set()) {
2357 lt->selection.cursor = lt->cursor;
2360 | BufferView::FITCUR
2361 | BufferView::CHANGE);
2362 // It is possible to make it a lot faster still
2363 // just comment out the line below...
2368 moveCursorUpdate(false);
2369 owner_->showState();
2374 case LFUN_DELETE_SKIP:
2376 LyXText * lt = bv_->getLyXText();
2378 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2380 LyXCursor cursor = lt->cursor;
2382 if (!lt->selection.set()) {
2383 if (cursor.pos() == cursor.par()->size()) {
2384 lt->cursorRight(bv_);
2385 cursor = lt->cursor;
2386 if (cursor.pos() == 0
2387 && !(cursor.par()->params().spaceTop()
2388 == VSpace (VSpace::NONE))) {
2391 cursor.par()->params().lineTop(),
2392 cursor.par()->params().lineBottom(),
2393 cursor.par()->params().pagebreakTop(),
2394 cursor.par()->params().pagebreakBottom(),
2395 VSpace(VSpace::NONE),
2396 cursor.par()->params().spaceBottom(),
2397 cursor.par()->params().align(),
2398 cursor.par()->params().labelWidthString(), 0);
2399 lt->cursorLeft(bv_);
2402 | BufferView::FITCUR
2403 | BufferView::CHANGE);
2405 lt->cursorLeft(bv_);
2407 lt->selection.cursor = lt->cursor;
2410 | BufferView::FITCUR
2411 | BufferView::CHANGE);
2415 lt->selection.cursor = lt->cursor;
2418 | BufferView::FITCUR
2419 | BufferView::CHANGE);
2427 /* -------> Delete word forward. */
2428 case LFUN_DELETE_WORD_FORWARD:
2429 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2430 bv_->getLyXText()->deleteWordForward(bv_);
2431 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2432 moveCursorUpdate(false);
2433 owner_->showState();
2436 /* -------> Delete word backward. */
2437 case LFUN_DELETE_WORD_BACKWARD:
2439 LyXText * lt = bv_->getLyXText();
2441 update(lt, BufferView::SELECT|BufferView::FITCUR);
2442 lt->deleteWordBackward(bv_);
2445 | BufferView::FITCUR
2446 | BufferView::CHANGE);
2447 moveCursorUpdate(false);
2448 owner_->showState();
2452 /* -------> Kill to end of line. */
2453 case LFUN_DELETE_LINE_FORWARD:
2455 LyXText * lt = bv_->getLyXText();
2457 update(lt, BufferView::SELECT|BufferView::FITCUR);
2458 lt->deleteLineForward(bv_);
2461 | BufferView::FITCUR
2462 | BufferView::CHANGE);
2463 moveCursorUpdate(false);
2467 /* -------> Set mark off. */
2470 LyXText * lt = bv_->getLyXText();
2473 update(lt, BufferView::SELECT|BufferView::FITCUR);
2474 lt->selection.cursor = lt->cursor;
2475 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2479 /* -------> Set mark on. */
2482 LyXText * lt = bv_->getLyXText();
2485 lt->selection.mark(true);
2486 update(lt, BufferView::SELECT|BufferView::FITCUR);
2487 lt->selection.cursor = lt->cursor;
2488 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2492 case LFUN_BACKSPACE:
2494 LyXText * lt = bv_->getLyXText();
2496 if (!lt->selection.set()) {
2497 if (owner_->getIntl()->getTrans().backspace()) {
2499 lt->selection.cursor = lt->cursor;
2502 | BufferView::FITCUR
2503 | BufferView::CHANGE);
2504 // It is possible to make it a lot faster still
2505 // just comment out the line below...
2511 owner_->showState();
2516 case LFUN_BACKSPACE_SKIP:
2518 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2519 LyXText * lt = bv_->getLyXText();
2521 LyXCursor cursor = lt->cursor;
2523 if (!lt->selection.set()) {
2524 if (cursor.pos() == 0
2525 && !(cursor.par()->params().spaceTop()
2526 == VSpace (VSpace::NONE))) {
2529 cursor.par()->params().lineTop(),
2530 cursor.par()->params().lineBottom(),
2531 cursor.par()->params().pagebreakTop(),
2532 cursor.par()->params().pagebreakBottom(),
2533 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2534 cursor.par()->params().align(),
2535 cursor.par()->params().labelWidthString(), 0);
2538 | BufferView::FITCUR
2539 | BufferView::CHANGE);
2542 lt->selection.cursor = cursor;
2545 | BufferView::FITCUR
2546 | BufferView::CHANGE);
2553 case LFUN_BREAKPARAGRAPH:
2555 LyXText * lt = bv_->getLyXText();
2558 lt->breakParagraph(bv_, 0);
2561 | BufferView::FITCUR
2562 | BufferView::CHANGE);
2563 lt->selection.cursor = lt->cursor;
2565 owner_->showState();
2569 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2571 LyXText * lt = bv_->getLyXText();
2574 lt->breakParagraph(bv_, 1);
2577 | BufferView::FITCUR
2578 | BufferView::CHANGE);
2579 lt->selection.cursor = lt->cursor;
2581 owner_->showState();
2585 case LFUN_BREAKPARAGRAPH_SKIP:
2587 // When at the beginning of a paragraph, remove
2588 // indentation and add a "defskip" at the top.
2589 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2590 LyXText * lt = bv_->getLyXText();
2592 LyXCursor cursor = lt->cursor;
2595 if (cursor.pos() == 0) {
2596 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2599 cursor.par()->params().lineTop(),
2600 cursor.par()->params().lineBottom(),
2601 cursor.par()->params().pagebreakTop(),
2602 cursor.par()->params().pagebreakBottom(),
2603 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2604 cursor.par()->params().align(),
2605 cursor.par()->params().labelWidthString(), 1);
2606 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2610 lt->breakParagraph(bv_, 0);
2611 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2616 | BufferView::FITCUR
2617 | BufferView::CHANGE);
2618 lt->selection.cursor = cursor;
2620 owner_->showState();
2624 case LFUN_PARAGRAPH_SPACING:
2626 LyXText * lt = bv_->getLyXText();
2628 Paragraph * par = lt->cursor.par();
2629 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2630 float cur_value = 1.0;
2631 if (cur_spacing == Spacing::Other) {
2632 cur_value = par->params().spacing().getValue();
2635 istringstream istr(argument.c_str());
2639 Spacing::Space new_spacing = cur_spacing;
2640 float new_value = cur_value;
2642 lyxerr << "Missing argument to `paragraph-spacing'"
2644 } else if (tmp == "single") {
2645 new_spacing = Spacing::Single;
2646 } else if (tmp == "onehalf") {
2647 new_spacing = Spacing::Onehalf;
2648 } else if (tmp == "double") {
2649 new_spacing = Spacing::Double;
2650 } else if (tmp == "other") {
2651 new_spacing = Spacing::Other;
2654 lyxerr << "new_value = " << tmpval << endl;
2657 } else if (tmp == "default") {
2658 new_spacing = Spacing::Default;
2660 lyxerr << _("Unknown spacing argument: ")
2661 << argument << endl;
2663 if (cur_spacing != new_spacing || cur_value != new_value) {
2664 par->params().spacing(Spacing(new_spacing, new_value));
2665 lt->redoParagraph(bv_);
2668 | BufferView::FITCUR
2669 | BufferView::CHANGE);
2674 case LFUN_INSET_TOGGLE:
2676 LyXText * lt = bv_->getLyXText();
2679 update(lt, BufferView::SELECT|BufferView::FITCUR);
2680 lt->toggleInset(bv_);
2681 update(lt, BufferView::SELECT|BufferView::FITCUR);
2693 InsetCommandParams p;
2694 if (action == LFUN_HTMLURL)
2695 p.setCmdName("htmlurl");
2697 p.setCmdName("url");
2698 owner_->getDialogs()->createUrl(p.getAsString());
2702 case LFUN_INSERT_URL:
2704 InsetCommandParams p;
2705 p.setFromString(argument);
2707 InsetUrl * inset = new InsetUrl(p);
2708 if (!insertInset(inset))
2711 updateInset(inset, true);
2715 case LFUN_INSET_TEXT:
2716 insertAndEditInset(new InsetText);
2719 case LFUN_INSET_ERT:
2720 insertAndEditInset(new InsetERT);
2723 case LFUN_INSET_EXTERNAL:
2724 insertAndEditInset(new InsetExternal);
2727 case LFUN_INSET_FOOTNOTE:
2728 insertAndEditInset(new InsetFoot);
2731 case LFUN_INSET_MARGINAL:
2732 insertAndEditInset(new InsetMarginal);
2735 case LFUN_INSET_MINIPAGE:
2736 insertAndEditInset(new InsetMinipage);
2739 case LFUN_INSERT_NOTE:
2740 insertAndEditInset(new InsetNote);
2743 case LFUN_INSET_FLOAT:
2744 // check if the float type exist
2745 if (floatList.typeExist(argument)) {
2746 insertAndEditInset(new InsetFloat(argument));
2748 lyxerr << "Non-existant float type: "
2749 << argument << endl;
2753 case LFUN_INSET_WIDE_FLOAT:
2755 // check if the float type exist
2756 if (floatList.typeExist(argument)) {
2757 InsetFloat * new_inset = new InsetFloat(argument);
2758 new_inset->wide(true);
2759 if (insertInset(new_inset))
2760 new_inset->edit(bv_);
2764 lyxerr << "Non-existant float type: "
2765 << argument << endl;
2772 case LFUN_INSET_LIST:
2773 insertAndEditInset(new InsetList);
2776 case LFUN_INSET_THEOREM:
2777 insertAndEditInset(new InsetTheorem);
2781 case LFUN_INSET_CAPTION:
2783 // Do we have a locking inset...
2784 if (bv_->theLockingInset()) {
2785 lyxerr << "Locking inset code: "
2786 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2787 InsetCaption * new_inset = new InsetCaption;
2788 new_inset->setOwner(bv_->theLockingInset());
2789 new_inset->setAutoBreakRows(true);
2790 new_inset->setDrawFrame(0, InsetText::LOCKED);
2791 new_inset->setFrameColor(0, LColor::captionframe);
2792 if (insertInset(new_inset))
2793 new_inset->edit(bv_);
2800 case LFUN_INSET_TABULAR:
2804 if (!argument.empty())
2805 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2806 InsetTabular * new_inset =
2807 new InsetTabular(*buffer_, r, c);
2809 bv_->getLyXText()->real_current_font.isRightToLeft();
2810 if (!open_new_inset(new_inset, rtl))
2815 // --- lyxserver commands ----------------------------
2817 case LFUN_CHARATCURSOR:
2819 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2820 if (pos < bv_->getLyXText()->cursor.par()->size())
2821 owner_->getLyXFunc()->setMessage(
2822 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2824 owner_->getLyXFunc()->setMessage("EOF");
2829 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2831 + tostr(bv_->getLyXText()->cursor.y()));
2838 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2839 lyxerr << "SETXY: Could not parse coordinates in '"
2840 << argument << std::endl;
2842 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2846 case LFUN_GETLAYOUT:
2847 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2852 LyXFont & font = bv_->getLyXText()->current_font;
2853 if (font.shape() == LyXFont::ITALIC_SHAPE)
2854 owner_->getLyXFunc()->setMessage("E");
2855 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2856 owner_->getLyXFunc()->setMessage("N");
2858 owner_->getLyXFunc()->setMessage("0");
2866 LyXFont & font = bv_->getLyXText()->current_font;
2867 if (font.latex() == LyXFont::ON)
2868 owner_->getLyXFunc()->setMessage("L");
2871 owner_->getLyXFunc()->setMessage("0");
2875 // --- accented characters ---------------------------
2878 case LFUN_CIRCUMFLEX:
2888 case LFUN_SPECIAL_CARON:
2891 case LFUN_HUNG_UMLAUT:
2894 if (argument.empty()) {
2896 owner_->getLyXFunc()->handleKeyFunc(action);
2898 owner_->getLyXFunc()->handleKeyFunc(action);
2899 owner_->getIntl()->getTrans()
2900 .TranslateAndInsert(argument[0], bv_->getLyXText());
2901 update(bv_->getLyXText(),
2903 | BufferView::FITCUR
2904 | BufferView::CHANGE);
2908 case LFUN_MATH_MACRO:
2909 mathDispatchMathMacro(bv_, argument);
2912 case LFUN_MATH_DELIM:
2913 mathDispatchMathDelim(bv_, argument);
2916 case LFUN_INSERT_MATRIX:
2917 mathDispatchInsertMatrix(bv_, argument);
2920 case LFUN_INSERT_MATH:
2921 mathDispatchInsertMath(bv_, argument);
2924 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2925 mathDispatchMathImportSelection(bv_, argument);
2928 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2929 mathDispatchMathDisplay(bv_, argument);
2932 case LFUN_MATH_MODE: // Open or create an inlined math inset
2933 mathDispatchMathMode(bv_, argument);
2936 case LFUN_CITATION_INSERT:
2938 InsetCommandParams p;
2939 p.setFromString( argument );
2941 InsetCitation * inset = new InsetCitation( p );
2942 if (!insertInset(inset))
2945 updateInset( inset, true );
2949 case LFUN_INSERT_BIBTEX:
2951 // ale970405+lasgoutt970425
2952 // The argument can be up to two tokens separated
2953 // by a space. The first one is the bibstyle.
2954 string const db = token(argument, ' ', 0);
2955 string bibstyle = token(argument, ' ', 1);
2956 if (bibstyle.empty())
2959 InsetCommandParams p( "BibTeX", db, bibstyle );
2960 InsetBibtex * inset = new InsetBibtex(p);
2962 if (insertInset(inset)) {
2963 if (argument.empty())
2970 // BibTeX data bases
2971 case LFUN_BIBDB_ADD:
2973 InsetBibtex * inset =
2974 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2976 inset->addDatabase(argument);
2981 case LFUN_BIBDB_DEL:
2983 InsetBibtex * inset =
2984 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2986 inset->delDatabase(argument);
2991 case LFUN_BIBTEX_STYLE:
2993 InsetBibtex * inset =
2994 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2996 inset->setOptions(argument);
3001 case LFUN_INDEX_CREATE:
3003 InsetCommandParams p("index");
3004 if (argument.empty()) {
3005 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3006 if (!idxstring.empty()) {
3007 p.setContents(idxstring);
3012 p.setContents(argument);
3015 owner_->getDialogs()->createIndex(p.getAsString());
3019 case LFUN_INDEX_INSERT:
3021 InsetCommandParams p;
3022 p.setFromString(argument);
3023 InsetIndex * inset = new InsetIndex(p);
3025 if (!insertInset(inset))
3028 updateInset(inset, true);
3032 case LFUN_INDEX_INSERT_LAST:
3034 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3035 if (!idxstring.empty()) {
3036 owner_->message(_("Word `")
3037 + idxstring + _(("' indexed.")));
3038 InsetCommandParams p("index", idxstring);
3039 InsetIndex * inset = new InsetIndex(p);
3041 if (!insertInset(inset))
3044 updateInset(inset, true);
3049 case LFUN_INDEX_PRINT:
3051 InsetCommandParams p("printindex");
3052 Inset * inset = new InsetPrintIndex(p);
3053 if (!insertInset(inset, "Standard"))
3058 case LFUN_PARENTINSERT:
3060 lyxerr << "arg " << argument << endl;
3061 InsetCommandParams p( "lyxparent", argument );
3062 Inset * inset = new InsetParent(p, *buffer_);
3063 if (!insertInset(inset, "Standard"))
3069 case LFUN_CHILD_INSERT:
3071 InsetInclude::Params p;
3072 p.cparams.setFromString(argument);
3073 p.masterFilename_ = buffer_->fileName();
3075 InsetInclude * inset = new InsetInclude(p);
3076 if (!insertInset(inset))
3079 updateInset(inset, true);
3080 bv_->owner()->getDialogs()->showInclude(inset);
3085 case LFUN_FLOAT_LIST:
3087 // We should check the argument for validity. (Lgb)
3088 Inset * inset = new InsetFloatList(argument);
3089 if (!insertInset(inset, "Standard"))
3094 case LFUN_THESAURUS_ENTRY:
3096 string arg = argument;
3099 arg = bv_->getLyXText()->selectionAsString(buffer_);
3102 if (arg.size() > 100 || arg.empty()) {
3103 // Get word or selection
3104 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3105 arg = bv_->getLyXText()->selectionAsString(buffer_);
3106 // FIXME: where is getLyXText()->unselect(bv_) ?
3110 bv_->owner()->getDialogs()->showThesaurus(arg);
3114 case LFUN_SELFINSERT:
3116 if (argument.empty()) break;
3118 /* Automatically delete the currently selected
3119 * text and replace it with what is being
3120 * typed in now. Depends on lyxrc settings
3121 * "auto_region_delete", which defaults to
3124 LyXText * lt = bv_->getLyXText();
3126 if (lyxrc.auto_region_delete) {
3127 if (lt->selection.set()) {
3128 lt->cutSelection(bv_, false);
3131 | BufferView::FITCUR
3132 | BufferView::CHANGE);
3137 LyXFont const old_font(lt->real_current_font);
3139 string::const_iterator cit = argument.begin();
3140 string::const_iterator end = argument.end();
3141 for (; cit != end; ++cit) {
3142 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3147 | BufferView::FITCUR
3148 | BufferView::CHANGE);
3150 lt->selection.cursor = lt->cursor;
3151 moveCursorUpdate(false);
3153 // real_current_font.number can change so we need to
3154 // update the minibuffer
3155 if (old_font != lt->real_current_font)
3156 owner_->showState();
3161 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3163 time_t now_time_t = time(NULL);
3164 struct tm * now_tm = localtime(&now_time_t);
3165 setlocale(LC_TIME, "");
3167 if (!argument.empty())
3170 arg = lyxrc.date_insert_format;
3172 int const datetmp_len =
3173 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3175 LyXText * lt = bv_->getLyXText();
3177 for (int i = 0; i < datetmp_len; i++) {
3178 lt->insertChar(bv_, datetmp[i]);
3181 | BufferView::FITCUR
3182 | BufferView::CHANGE);
3185 lt->selection.cursor = lt->cursor;
3186 moveCursorUpdate(false);
3190 case LFUN_UNKNOWN_ACTION:
3191 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3202 void BufferView::Pimpl::newline()
3205 LyXText * lt = bv_->getLyXText();
3209 | BufferView::FITCUR);
3210 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3213 | BufferView::FITCUR
3214 | BufferView::CHANGE);
3219 void BufferView::Pimpl::hfill()
3222 LyXText * lt = bv_->getLyXText();
3226 | BufferView::FITCUR);
3227 lt->insertChar(bv_, Paragraph::META_HFILL);
3230 | BufferView::FITCUR
3231 | BufferView::CHANGE);
3236 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3240 update(lt, BufferView::SELECT|BufferView::FITCUR);
3241 InsetSpecialChar * new_inset =
3242 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3243 #ifdef WITH_WARNINGS
3244 #warning Why is this code different from specialChar() below? (JMarc)
3245 // the code in specialChar is a generic version of what used to exist
3246 // for other special chars. I did not merge this case because of the
3247 // call to updateInset(), but what does it do?
3249 if (!insertInset(new_inset))
3252 updateInset(new_inset, true);
3257 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3260 LyXText * lt = bv_->getLyXText();
3263 update(lt, BufferView::SELECT|BufferView::FITCUR);
3264 InsetSpecialChar * new_inset =
3265 new InsetSpecialChar(kind);
3266 insertInset(new_inset);
3271 void BufferView::Pimpl::smartQuote()
3274 LyXText * lt = bv_->getLyXText();
3276 if (lt->cursor.pos())
3277 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3283 LyXLayout const & style = textclasslist.Style(
3284 bv_->buffer()->params.textclass,
3285 lt->cursor.par()->getLayout());
3287 if (style.pass_thru ||
3288 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3289 Dispatch(LFUN_SELFINSERT, "\"");
3293 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3295 if (insertInset(inset))
3302 // Open and lock an updatable inset
3303 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3305 LyXText * lt = bv_->getLyXText();
3309 if (!insertInset(new_inset)) {
3313 new_inset->edit(bv_, !behind);
3318 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3320 // if we are in a locking inset we should try to insert the
3321 // inset there otherwise this is a illegal function now
3322 if (bv_->theLockingInset()) {
3323 if (bv_->theLockingInset()->insetAllowed(inset))
3324 return bv_->theLockingInset()->insertInset(bv_, inset);
3328 // not quite sure if we want this...
3329 setCursorParUndo(bv_);
3332 beforeChange(bv_->text);
3333 if (!lout.empty()) {
3334 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3335 bv_->text->breakParagraph(bv_);
3336 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3338 if (bv_->text->cursor.par()->size()) {
3339 bv_->text->cursorLeft(bv_);
3341 bv_->text->breakParagraph(bv_);
3342 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 pair<bool, LyXTextClass::size_type> lres =
3346 textclasslist.NumberOfLayout(buffer_->params
3348 LyXTextClass::size_type lay;
3349 if (lres.first != false) {
3353 // layout not fount using default "Standard" (0)
3357 bv_->text->setLayout(bv_, lay);
3359 bv_->text->setParagraph(bv_, 0, 0,
3361 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 bv_->text->current_font.setLatex(LyXFont::OFF);
3371 bv_->text->insertInset(bv_, inset);
3372 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3379 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3384 // first check for locking insets
3385 if (bv_->theLockingInset()) {
3386 if (bv_->theLockingInset() == inset) {
3387 if (bv_->text->updateInset(bv_, inset)) {
3390 buffer_->markDirty();
3395 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3396 if (bv_->text->updateInset(bv_,
3397 bv_->theLockingInset())) {
3400 buffer_->markDirty();
3408 // then check the current buffer
3411 update(bv_->text, BufferView::UPDATE);
3412 if (bv_->text->updateInset(bv_, inset)) {
3416 | BufferView::FITCUR
3417 | BufferView::CHANGE);
3419 update(bv_->text, SELECT);
3427 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3430 if (!available()) return;
3433 beforeChange(bv_->text);
3434 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3438 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3439 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3440 if (find(codes.begin(), codes.end(), inset->lyxCode())
3443 static_cast<InsetCommand const *>(inset)->getContents();
3446 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3447 if (bv_->text->cursor.pos()
3448 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3449 LyXCursor tmp = bv_->text->cursor;
3450 bv_->text->cursor.par(bv_->text->firstParagraph());
3451 bv_->text->cursor.pos(0);
3452 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3453 bv_->text->cursor = tmp;
3454 bv_->owner()->message(_("No more insets"));
3457 bv_->owner()->message(_("No more insets"));
3460 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3461 bv_->text->selection.cursor = bv_->text->cursor;
3465 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3467 gotoInset(vector<Inset::Code>(1, code), same_content);