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;
70 extern int greek_kb_flag;
81 /* the selection possible is needed, that only motion events are
82 * used, where the bottom press event was on the drawing area too */
83 bool selection_possible = false;
85 extern BufferList bufferlist;
86 extern char ascii_type;
88 extern bool math_insert_greek(BufferView *, char);
89 extern void sigchldchecker(pid_t pid, int * status);
90 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
95 const unsigned int saved_positions_num = 20;
100 XSync(fl_get_display(), 0);
104 void SetXtermCursor(Window win)
106 static Cursor cursor;
107 static bool cursor_undefined = true;
108 if (cursor_undefined){
109 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
110 XFlush(fl_get_display());
111 cursor_undefined = false;
113 XDefineCursor(fl_get_display(), win, cursor);
114 XFlush(fl_get_display());
120 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
121 int xpos, int ypos, int width, int height)
122 : bv_(b), owner_(o), buffer_(0),
123 current_scrollbar_value(0), cursor_timeout(400),
124 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
128 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
129 workarea_.workAreaExpose
130 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
131 workarea_.workAreaEnter
132 .connect(slot(this, &BufferView::Pimpl::enterView));
133 workarea_.workAreaLeave
134 .connect(slot(this, &BufferView::Pimpl::leaveView));
135 workarea_.workAreaButtonPress
136 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
137 workarea_.workAreaButtonRelease
139 &BufferView::Pimpl::workAreaButtonRelease));
140 workarea_.workAreaMotionNotify
141 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
142 workarea_.workAreaDoubleClick
143 .connect(slot(this, &BufferView::Pimpl::doubleClick));
144 workarea_.workAreaTripleClick
145 .connect(slot(this, &BufferView::Pimpl::tripleClick));
146 workarea_.workAreaKeyPress
147 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
149 cursor_timeout.timeout.connect(slot(this,
150 &BufferView::Pimpl::cursorToggle));
151 cursor_timeout.start();
152 workarea_.setFocus();
153 saved_positions.resize(saved_positions_num);
157 Painter & BufferView::Pimpl::painter()
159 return workarea_.getPainter();
163 void BufferView::Pimpl::buffer(Buffer * b)
165 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
169 buffer_->delUser(bv_);
171 // Put the old text into the TextCache, but
172 // only if the buffer is still loaded.
173 // Also set the owner of the test to 0
174 // bv_->text->owner(0);
175 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
176 if (lyxerr.debugging())
177 textcache.show(lyxerr, "BufferView::buffer");
182 // Set current buffer
185 if (bufferlist.getState() == BufferList::CLOSING) return;
188 // screen is always deleted when the buffer is changed.
191 // If we are closing the buffer, use the first buffer as current
193 buffer_ = bufferlist.first();
197 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
198 buffer_->addUser(bv_);
199 // If we don't have a text object for this, we make one
200 if (bv_->text == 0) {
201 resizeCurrentBuffer();
206 bv_->text->first = screen_->topCursorVisible(bv_->text);
207 owner_->updateMenubar();
208 owner_->updateToolbar();
209 // Similarly, buffer-dependent dialogs should be updated or
210 // hidden. This should go here because some dialogs (eg ToC)
211 // require bv_->text.
212 owner_->getDialogs()->updateBufferDependent(true);
216 lyxerr[Debug::INFO] << " No Buffer!" << endl;
217 owner_->updateMenubar();
218 owner_->updateToolbar();
219 owner_->getDialogs()->hideBufferDependent();
223 // Also remove all remaining text's from the testcache.
224 // (there should not be any!) (if there is any it is a
226 if (lyxerr.debugging())
227 textcache.show(lyxerr, "buffer delete all");
230 // should update layoutchoice even if we don't have a buffer.
231 owner_->updateLayoutChoice();
233 owner_->updateWindowTitle();
237 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
239 workarea_.resize(xpos, ypos, width, height);
240 update(bv_->text, SELECT);
245 void BufferView::Pimpl::resize()
248 resizeCurrentBuffer();
252 void BufferView::Pimpl::redraw()
254 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
259 bool BufferView::Pimpl::fitCursor(LyXText * text)
261 lyx::Assert(screen_.get());
265 if (bv_->theLockingInset()) {
266 bv_->theLockingInset()->fitInsetCursor(bv_);
269 ret = screen_->fitCursor(text, bv_);
272 bv_->owner()->getDialogs()->updateParagraph();
279 void BufferView::Pimpl::redoCurrentBuffer()
281 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
282 if (buffer_ && bv_->text) {
284 owner_->updateLayoutChoice();
289 int BufferView::Pimpl::resizeCurrentBuffer()
291 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
294 Paragraph * selstartpar = 0;
295 Paragraph * selendpar = 0;
296 UpdatableInset * the_locking_inset = 0;
298 Paragraph::size_type pos = 0;
299 Paragraph::size_type selstartpos = 0;
300 Paragraph::size_type selendpos = 0;
301 bool selection = false;
302 bool mark_set = false;
304 owner_->prohibitInput();
306 owner_->message(_("Formatting document..."));
309 par = bv_->text->cursor.par();
310 pos = bv_->text->cursor.pos();
311 selstartpar = bv_->text->selection.start.par();
312 selstartpos = bv_->text->selection.start.pos();
313 selendpar = bv_->text->selection.end.par();
314 selendpos = bv_->text->selection.end.pos();
315 selection = bv_->text->selection.set();
316 mark_set = bv_->text->selection.mark();
317 the_locking_inset = bv_->theLockingInset();
319 bv_->text = new LyXText(bv_);
320 bv_->text->init(bv_);
322 // See if we have a text in TextCache that fits
323 // the new buffer_ with the correct width.
324 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
326 if (lyxerr.debugging()) {
327 lyxerr << "Found a LyXText that fits:\n";
328 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
330 // Set the owner of the newly found text
331 // bv_->text->owner(bv_);
332 if (lyxerr.debugging())
333 textcache.show(lyxerr, "resizeCurrentBuffer");
335 bv_->text = new LyXText(bv_);
336 bv_->text->init(bv_);
342 bv_->text->selection.set(true);
343 /* at this point just to avoid the Delete-Empty-Paragraph
344 * Mechanism when setting the cursor */
345 bv_->text->selection.mark(mark_set);
347 bv_->text->setCursor(bv_, selstartpar, selstartpos);
348 bv_->text->selection.cursor = bv_->text->cursor;
349 bv_->text->setCursor(bv_, selendpar, selendpos);
350 bv_->text->setSelection(bv_);
351 bv_->text->setCursor(bv_, par, pos);
353 bv_->text->setCursor(bv_, par, pos);
354 bv_->text->selection.cursor = bv_->text->cursor;
355 bv_->text->selection.set(false);
357 // remake the inset locking
358 bv_->theLockingInset(the_locking_inset);
360 bv_->text->first = screen_->topCursorVisible(bv_->text);
361 buffer_->resizeInsets(bv_);
362 // this will scroll the screen such that the cursor becomes visible
367 owner_->allowInput();
369 /// clear the "Formatting Document" message
372 /// get rid of the splash screen if it's not gone already
373 owner_->getDialogs()->destroySplash();
379 void BufferView::Pimpl::updateScreen()
381 // Regenerate the screen.
382 screen_.reset(new LyXScreen(workarea_));
386 void BufferView::Pimpl::updateScrollbar()
388 /* If the text is smaller than the working area, the scrollbar
389 * maximum must be the working area height. No scrolling will
392 workarea_.setScrollbar(0, 1.0);
396 long const text_height = bv_->text->height;
398 double const lineh = bv_->text->defaultHeight();
399 double const slider_size =
400 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
402 static long old_text_height = 0;
403 static double old_lineh = 0;
404 static double old_slider_size = 0;
406 if (text_height != old_text_height) {
407 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
408 old_text_height = text_height;
410 if (lineh != old_lineh) {
411 workarea_.setScrollbarIncrements(lineh);
414 if (current_scrollbar_value != bv_->text->first
415 || slider_size != old_slider_size) {
416 current_scrollbar_value = bv_->text->first;
417 workarea_.setScrollbar(current_scrollbar_value, slider_size);
418 old_slider_size = slider_size;
423 // Callback for scrollbar slider
424 void BufferView::Pimpl::scrollCB(double value)
426 if (!buffer_) return;
428 current_scrollbar_value = long(value);
429 if (current_scrollbar_value < 0)
430 current_scrollbar_value = 0;
435 screen_->draw(bv_->text, bv_, current_scrollbar_value);
437 if (!lyxrc.cursor_follows_scrollbar) {
442 LyXText * vbt = bv_->text;
444 int const height = vbt->defaultHeight();
445 int const first = static_cast<int>((bv_->text->first + height));
446 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
448 if (vbt->cursor.y() < first)
449 vbt->setCursorFromCoordinates(bv_, 0, first);
450 else if (vbt->cursor.y() > last)
451 vbt->setCursorFromCoordinates(bv_, 0, last);
457 int BufferView::Pimpl::scrollUp(long time)
459 if (!buffer_) return 0;
460 if (!screen_.get()) return 0;
462 double value = workarea_.getScrollbarValue();
464 if (value == 0) return 0;
466 float add_value = (bv_->text->defaultHeight()
467 + float(time) * float(time) * 0.125);
469 if (add_value > workarea_.height())
470 add_value = float(workarea_.height() -
471 bv_->text->defaultHeight());
478 workarea_.setScrollbarValue(value);
485 int BufferView::Pimpl::scrollDown(long time)
487 if (!buffer_) return 0;
488 if (!screen_.get()) return 0;
490 double value = workarea_.getScrollbarValue();
491 pair<float, float> p = workarea_.getScrollbarBounds();
492 double const max = p.second;
494 if (value == max) return 0;
496 float add_value = (bv_->text->defaultHeight()
497 + float(time) * float(time) * 0.125);
499 if (add_value > workarea_.height())
500 add_value = float(workarea_.height() -
501 bv_->text->defaultHeight());
508 workarea_.setScrollbarValue(value);
515 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
517 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
521 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
523 // Only use motion with button 1
524 if (!(state & Button1MotionMask))
527 if (!buffer_ || !screen_.get()) return;
529 // Check for inset locking
530 if (bv_->theLockingInset()) {
531 LyXCursor cursor = bv_->text->cursor;
532 LyXFont font = bv_->text->getFont(buffer_,
533 cursor.par(), cursor.pos());
534 int width = bv_->theLockingInset()->width(bv_, font);
535 int inset_x = font.isVisibleRightToLeft()
536 ? cursor.x() - width : cursor.x();
537 int start_x = inset_x + bv_->theLockingInset()->scroll();
538 bv_->theLockingInset()->
539 insetMotionNotify(bv_,
541 y - cursor.y() + bv_->text->first,
546 /* The test for not selection possible is needed, that only motion
547 events are used, where the bottom press event was on
548 the drawing area too */
549 if (!selection_possible)
552 screen_->hideCursor();
554 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
556 if (!bv_->text->selection.set())
557 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
559 bv_->text->setSelection(bv_);
560 screen_->toggleToggle(bv_->text, bv_);
561 fitCursor(bv_->text);
563 screen_->showCursor(bv_->text, bv_);
570 // Single-click on work area
571 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
574 if (!buffer_ || !screen_.get()) return;
576 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
578 // ok ok, this is a hack.
579 if (button == 4 || button == 5) {
582 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
585 scrollDown(lyxrc.wheel_jump);
590 if (bv_->theLockingInset()) {
591 // We are in inset locking mode
593 /* Check whether the inset was hit. If not reset mode,
594 otherwise give the event to the inset */
595 if (inset_hit == bv_->theLockingInset()) {
596 bv_->theLockingInset()->
597 insetButtonPress(bv_,
602 bv_->unlockInset(bv_->theLockingInset());
607 selection_possible = true;
608 screen_->hideCursor();
610 int const screen_first = bv_->text->first;
612 // Middle button press pastes if we have a selection
613 bool paste_internally = false;
615 && bv_->text->selection.set()) {
616 owner_->getLyXFunc()->dispatch(LFUN_COPY);
617 paste_internally = true;
620 // Clear the selection
621 screen_->toggleSelection(bv_->text, bv_);
622 bv_->text->clearSelection();
623 bv_->text->fullRebreak(bv_);
624 screen_->update(bv_->text, bv_);
627 // Single left click in math inset?
628 if ((inset_hit != 0) &&
629 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
630 // Highly editable inset, like math
631 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
632 selection_possible = false;
633 owner_->updateLayoutChoice();
634 owner_->message(inset->editMessage());
635 inset->insetButtonPress(bv_, xpos, ypos, button);
636 inset->edit(bv_, xpos, ypos, button);
640 // Right click on a footnote flag opens float menu
642 selection_possible = false;
646 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
647 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
649 bv_->text->selection.cursor = bv_->text->cursor;
650 bv_->text->cursor.x_fix(bv_->text->cursor.x());
652 owner_->updateLayoutChoice();
653 if (fitCursor(bv_->text)) {
654 selection_possible = false;
657 // Insert primary selection with middle mouse
658 // if there is a local selection in the current buffer,
661 if (paste_internally)
662 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
664 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
666 selection_possible = false;
672 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
678 LyXText * text = bv_->getLyXText();
680 if (text->bv_owner && bv_->theLockingInset())
683 if (screen_.get() && button == 1) {
684 if (text->bv_owner) {
685 screen_->hideCursor();
686 screen_->toggleSelection(text, bv_);
687 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
688 screen_->toggleSelection(text, bv_, false);
690 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
692 /* This will fit the cursor on the screen
694 update(text, BufferView::SELECT|BufferView::FITCUR);
699 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
705 LyXText * text = bv_->getLyXText();
707 if (text->bv_owner && bv_->theLockingInset())
710 if (screen_.get() && (button == 1)) {
711 screen_->hideCursor();
712 screen_->toggleSelection(text, bv_);
713 text->cursorHome(bv_);
714 text->selection.cursor = text->cursor;
715 text->cursorEnd(bv_);
716 text->setSelection(bv_);
717 screen_->toggleSelection(text, bv_, false);
718 /* This will fit the cursor on the screen
720 update(text, BufferView::SELECT|BufferView::FITCUR);
725 void BufferView::Pimpl::enterView()
727 if (active() && available()) {
728 SetXtermCursor(workarea_.getWin());
729 using_xterm_cursor = true;
734 void BufferView::Pimpl::leaveView()
736 if (using_xterm_cursor) {
737 XUndefineCursor(fl_get_display(), workarea_.getWin());
738 using_xterm_cursor = false;
743 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
746 if (!buffer_ || !screen_.get()) return;
748 // If we hit an inset, we have the inset coordinates in these
749 // and inset_hit points to the inset. If we do not hit an
750 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
751 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
753 if (bv_->theLockingInset()) {
754 // We are in inset locking mode.
756 /* LyX does a kind of work-area grabbing for insets.
757 Only a ButtonPress Event outside the inset will
758 force a insetUnlock. */
759 bv_->theLockingInset()->
760 insetButtonRelease(bv_, x, y, button);
764 selection_possible = false;
772 // Did we hit an editable inset?
774 // Inset like error, notes and figures
775 selection_possible = false;
777 // CHECK fix this proper in 0.13
779 // Following a ref shouldn't issue
780 // a push on the undo-stack
781 // anylonger, now that we have
782 // keybindings for following
783 // references and returning from
784 // references. IMHO though, it
785 // should be the inset's own business
786 // to push or not push on the undo
787 // stack. They don't *have* to
788 // alter the document...
790 // ...or maybe the SetCursorParUndo()
791 // below isn't necessary at all anylonger?
792 if (inset_hit->lyxCode() == Inset::REF_CODE) {
793 setCursorParUndo(bv_);
796 owner_->message(inset_hit->editMessage());
798 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
799 // Highly editable inset, like math
800 UpdatableInset *inset = (UpdatableInset *)inset_hit;
801 inset->insetButtonRelease(bv_, x, y, button);
803 inset_hit->insetButtonRelease(bv_, x, y, button);
804 inset_hit->edit(bv_, x, y, button);
809 // check whether we want to open a float
813 if (bv_->text->cursor.pos() <
814 bv_->text->cursor.par()->size()) {
815 c = bv_->text->cursor.par()->
816 getChar(bv_->text->cursor.pos());
818 if (bv_->text->cursor.pos() - 1 >= 0) {
819 c = bv_->text->cursor.par()->
820 getChar(bv_->text->cursor.pos() - 1);
823 selection_possible = false;
828 // Maybe we want to edit a bibitem ale970302
829 if (bv_->text->cursor.par()->bibkey && x < 20 +
830 bibitemMaxWidth(bv_, textclasslist.
832 params.textclass).defaultfont())) {
833 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
841 * Returns an inset if inset was hit. 0 otherwise.
842 * If hit, the coordinates are changed relative to the inset.
843 * Otherwise coordinates are not changed, and false is returned.
845 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
846 unsigned int /* button */)
851 int y_tmp = y + text->first;
854 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
855 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
858 if (cursor.pos() < cursor.par()->size()
859 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
860 && cursor.par()->getInset(cursor.pos())
861 && cursor.par()->getInset(cursor.pos())->editable()) {
863 // Check whether the inset really was hit
864 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
865 LyXFont font = text->getFont(buffer_,
866 cursor.par(), cursor.pos());
867 int const width = tmpinset->width(bv_, font);
868 int const inset_x = font.isVisibleRightToLeft()
869 ? cursor.x() - width : cursor.x();
870 int const start_x = inset_x + tmpinset->scroll();
871 int const end_x = inset_x + width;
873 if (x > start_x && x < end_x
874 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
875 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
876 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
878 // The origin of an inset is on the baseline
879 y = y_tmp - (text->cursor.y());
884 if ((cursor.pos() - 1 >= 0) &&
885 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
886 (cursor.par()->getInset(cursor.pos() - 1)) &&
887 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
888 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
889 LyXFont font = text->getFont(buffer_, cursor.par(),
891 int const width = tmpinset->width(bv_, font);
892 int const inset_x = font.isVisibleRightToLeft()
893 ? cursor.x() : cursor.x() - width;
894 int const start_x = inset_x + tmpinset->scroll();
895 int const end_x = inset_x + width;
897 if (x > start_x && x < end_x
898 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
899 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
901 if (move_cursor && (tmpinset != bv_->theLockingInset()))
903 text->setCursor(bv_, cursor.par(),
904 cursor.pos() - 1, true);
906 // The origin of an inset is on the baseline
907 y = y_tmp - (text->cursor.y());
915 void BufferView::Pimpl::workAreaExpose()
917 static int work_area_width;
918 static unsigned int work_area_height;
920 bool const widthChange = workarea_.workWidth() != work_area_width;
921 bool const heightChange = workarea_.height() != work_area_height;
923 // update from work area
924 work_area_width = workarea_.workWidth();
925 work_area_height = workarea_.height();
928 // The visible LyXView need a resize
931 // Remove all texts from the textcache
932 // This is not _really_ what we want to do. What
933 // we really want to do is to delete in textcache
934 // that does not have a BufferView with matching
935 // width, but as long as we have only one BufferView
936 // deleting all gives the same result.
937 if (lyxerr.debugging())
938 textcache.show(lyxerr, "Expose delete all");
940 } else if (heightChange) {
941 // Rebuild image of current screen
943 // fitCursor() ensures we don't jump back
944 // to the start of the document on vertical
946 fitCursor(bv_->text);
948 // The main window size has changed, repaint most stuff
950 } else if (screen_.get())
951 screen_->redraw(bv_->text, bv_);
953 // Grey box when we don't have a buffer
957 // always make sure that the scrollbar is sane.
959 owner_->updateLayoutChoice();
964 void BufferView::Pimpl::update()
967 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
969 screen_->update(bv_->text, bv_);
973 // Values used when calling update:
975 // -2 - update, move sel_cursor if selection, fitcursor
976 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
977 // 0 - update, move sel_cursor if selection, fitcursor
978 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
979 // 3 - update, move sel_cursor if selection
982 // a simple redraw of the parts that need refresh
984 // move sel_cursor if selection -
985 // the text's sel_cursor is moved if there is selection is progress
988 // fitCursor() is called and the scrollbar updated
991 // the buffer is marked dirty.
1000 // UPDATE_ONLY = UPDATE;
1001 // UPDATE_SELECT = UPDATE | SELECT;
1002 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1003 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1005 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1006 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1007 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1008 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1009 // update(3) -> update(1) -> update(1) -> update(SELECT)
1011 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1013 owner_->updateLayoutChoice();
1015 if (!text->selection.set() && (f & SELECT)) {
1016 text->selection.cursor = text->cursor;
1019 text->fullRebreak(bv_);
1021 if (text->inset_owner) {
1022 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1023 updateInset(text->inset_owner, true);
1033 buffer_->markDirty();
1038 // Callback for cursor timer
1039 void BufferView::Pimpl::cursorToggle()
1041 // Quite a nice place for asyncron Inset updating, isn't it?
1042 // Actually no! This is run even if no buffer exist... so (Lgb)
1044 cursor_timeout.restart();
1049 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1050 if (pid == -1) // error find out what is wrong
1051 ; // ignore it for now.
1053 sigchldchecker(pid, &status);
1055 updatelist.update(bv_);
1057 if (!screen_.get()) {
1058 cursor_timeout.restart();
1062 if (!bv_->theLockingInset()) {
1063 screen_->cursorToggle(bv_->text, bv_);
1065 bv_->theLockingInset()->toggleInsetCursor(bv_);
1068 cursor_timeout.restart();
1072 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1074 if (!text->cursor.row()->previous())
1077 int y = text->first;
1078 if (text->inset_owner)
1079 y += bv_->text->first;
1080 Row * cursorrow = text->cursor.row();
1081 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1083 // This is to allow jumping over large insets
1084 if ((cursorrow == text->cursor.row()))
1085 text->cursorUp(bv_);
1087 if (text->inset_owner ||
1088 text->cursor.row()->height() < workarea_.height())
1089 screen_->draw(bv_->text, bv_,
1091 - text->cursor.row()->baseline()
1092 + text->cursor.row()->height()
1093 - workarea_.height() + 1 );
1098 void BufferView::Pimpl::cursorNext(LyXText * text)
1100 if (!text->cursor.row()->next())
1103 int y = text->first + workarea_.height();
1104 // if (text->inset_owner)
1105 // y += bv_->text->first;
1106 text->getRowNearY(y);
1108 Row * cursorrow = text->cursor.row();
1109 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1111 // This is to allow jumping over large insets
1112 if ((cursorrow == bv_->text->cursor.row()))
1113 text->cursorDown(bv_);
1115 if (text->inset_owner ||
1116 text->cursor.row()->height() < workarea_.height())
1117 screen_->draw(bv_->text, bv_, text->cursor.y() -
1118 text->cursor.row()->baseline());
1123 bool BufferView::Pimpl::available() const
1125 if (buffer_ && bv_->text) return true;
1130 void BufferView::Pimpl::beforeChange(LyXText * text)
1133 text->clearSelection();
1137 void BufferView::Pimpl::savePosition(unsigned int i)
1139 if (i >= saved_positions_num)
1141 saved_positions[i] = Position(buffer_->fileName(),
1142 bv_->text->cursor.par()->id(),
1143 bv_->text->cursor.pos());
1146 str << _("Saved bookmark") << ' ' << i;
1147 owner_->message(str.str().c_str());
1152 void BufferView::Pimpl::restorePosition(unsigned int i)
1154 if (i >= saved_positions_num)
1157 string const fname = saved_positions[i].filename;
1159 beforeChange(bv_->text);
1161 if (fname != buffer_->fileName()) {
1162 Buffer * b = bufferlist.exists(fname) ?
1163 bufferlist.getBuffer(fname) :
1164 bufferlist.loadLyXFile(fname); // don't ask, just load it
1165 if (b != 0 ) buffer(b);
1168 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1172 bv_->text->setCursor(bv_, par,
1173 min(par->size(), saved_positions[i].par_pos));
1175 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1178 str << _("Moved to bookmark") << ' ' << i;
1179 owner_->message(str.str().c_str());
1184 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1186 if (i >= saved_positions_num)
1189 return !saved_positions[i].filename.empty();
1193 void BufferView::Pimpl::setState()
1195 if (!lyxrc.rtl_support)
1198 LyXText * text = bv_->getLyXText();
1199 if (text->real_current_font.isRightToLeft()
1202 text->real_current_font.latex() != LyXFont::ON
1205 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1206 owner_->getIntl()->KeyMapSec();
1208 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1209 owner_->getIntl()->KeyMapPrim();
1214 void BufferView::Pimpl::insetSleep()
1216 if (bv_->theLockingInset() && !inset_slept) {
1217 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1218 bv_->theLockingInset()->insetUnlock(bv_);
1224 void BufferView::Pimpl::insetWakeup()
1226 if (bv_->theLockingInset() && inset_slept) {
1227 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1228 inset_slept = false;
1233 void BufferView::Pimpl::insetUnlock()
1235 if (bv_->theLockingInset()) {
1237 bv_->theLockingInset()->insetUnlock(bv_);
1238 bv_->theLockingInset(0);
1240 inset_slept = false;
1245 bool BufferView::Pimpl::focus() const
1247 return workarea_.hasFocus();
1251 void BufferView::Pimpl::focus(bool f)
1253 if (f) workarea_.setFocus();
1257 bool BufferView::Pimpl::active() const
1259 return workarea_.active();
1263 bool BufferView::Pimpl::belowMouse() const
1265 return workarea_.belowMouse();
1269 void BufferView::Pimpl::showCursor()
1271 if (screen_.get()) {
1272 if (bv_->theLockingInset())
1273 bv_->theLockingInset()->showInsetCursor(bv_);
1275 screen_->showCursor(bv_->text, bv_);
1280 void BufferView::Pimpl::hideCursor()
1282 if (screen_.get()) {
1283 if (!bv_->theLockingInset())
1284 // bv_->theLockingInset()->hideInsetCursor(bv_);
1286 screen_->hideCursor();
1291 void BufferView::Pimpl::toggleSelection(bool b)
1293 if (screen_.get()) {
1294 if (bv_->theLockingInset())
1295 bv_->theLockingInset()->toggleSelection(bv_, b);
1296 screen_->toggleSelection(bv_->text, bv_, b);
1301 void BufferView::Pimpl::toggleToggle()
1304 screen_->toggleToggle(bv_->text, bv_);
1308 void BufferView::Pimpl::center()
1310 beforeChange(bv_->text);
1311 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1312 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1314 screen_->draw(bv_->text, bv_, 0);
1316 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1321 void BufferView::Pimpl::pasteClipboard(bool asPara)
1323 if (!buffer_) return;
1325 screen_->hideCursor();
1326 beforeChange(bv_->text);
1328 string const clip(workarea_.getClipboard());
1330 if (clip.empty()) return;
1333 bv_->text->insertStringAsParagraphs(bv_, clip);
1335 bv_->text->insertStringAsLines(bv_, clip);
1337 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1341 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1343 workarea_.putClipboard(stuff);
1348 * Dispatch functions for actions which can be valid for BufferView->text
1349 * and/or InsetText->text!!!
1354 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1356 LyXText * lt = bv_->getLyXText();
1358 if (selecting || lt->selection.mark()) {
1359 lt->setSelection(bv_);
1363 update(lt, BufferView::SELECT|BufferView::FITCUR);
1366 /* ---> Everytime the cursor is moved, show the current font state. */
1367 // should this too me moved out of this func?
1368 //owner->showState();
1373 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1375 LyXCursor cursor = bv_->getLyXText()->cursor;
1376 Buffer::inset_iterator it =
1377 find_if(Buffer::inset_iterator(
1378 cursor.par(), cursor.pos()),
1379 buffer_->inset_iterator_end(),
1380 lyx::compare_memfun(&Inset::lyxCode, code));
1381 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1385 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1387 string filename = filen;
1389 if (filename.empty()) {
1390 // Launch a file browser
1391 string initpath = lyxrc.document_path;
1394 string const trypath = owner_->buffer()->filepath;
1395 // If directory is writeable, use this as default.
1396 if (IsDirWriteable(trypath))
1400 FileDialog fileDlg(bv_->owner(),
1401 _("Select LyX document to insert"),
1403 make_pair(string(_("Documents")),
1404 string(lyxrc.document_path)),
1405 make_pair(string(_("Examples")),
1406 string(AddPath(system_lyxdir, "examples"))));
1408 FileDialog::Result result =
1409 fileDlg.Select(initpath,
1410 _("*.lyx| LyX Documents (*.lyx)"));
1412 if (result.first == FileDialog::Later)
1415 filename = result.second;
1417 // check selected filename
1418 if (filename.empty()) {
1419 owner_->message(_("Canceled."));
1424 // get absolute path of file and add ".lyx" to the filename if
1426 filename = FileSearch(string(), filename, "lyx");
1428 string const disp_fn(MakeDisplayPath(filename));
1431 s1 << _("Inserting document") << ' '
1432 << disp_fn << " ...";
1433 owner_->message(s1.str().c_str());
1434 bool const res = bv_->insertLyXFile(filename);
1437 str << _("Document") << ' ' << disp_fn
1438 << ' ' << _("inserted.");
1439 owner_->message(str.str().c_str());
1442 str << _("Could not insert document") << ' '
1444 owner_->message(str.str().c_str());
1449 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1451 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1452 << action <<"] arg[" << argument << "]" << endl;
1455 // --- Misc -------------------------------------------
1459 LyXText * lt = bv_->getLyXText();
1460 lt->toggleAppendix(bv_);
1463 | BufferView::FITCUR
1464 | BufferView::CHANGE);
1469 case LFUN_TOC_INSERT:
1471 InsetCommandParams p;
1472 p.setCmdName("tableofcontents");
1473 Inset * inset = new InsetTOC(p);
1474 if (!insertInset(inset, "Standard"))
1479 case LFUN_TABULAR_FEATURE:
1480 case LFUN_SCROLL_INSET:
1481 // this is not handled here as this funktion is only aktive
1482 // if we have a locking_inset and that one is (or contains)
1486 case LFUN_INSET_GRAPHICS:
1488 Inset * new_inset = new InsetGraphics;
1489 if (!insertInset(new_inset)) {
1492 // this is need because you don't use a inset->Edit()
1493 updateInset(new_inset, true);
1494 new_inset->edit(bv_);
1504 case LFUN_PASTESELECTION:
1506 bool asPara = false;
1507 if (argument == "paragraph") asPara = true;
1508 pasteClipboard(asPara);
1520 case LFUN_LAYOUT_COPY:
1521 bv_->copyEnvironment();
1524 case LFUN_LAYOUT_PASTE:
1525 bv_->pasteEnvironment();
1529 case LFUN_GOTOERROR:
1530 gotoInset(Inset::ERROR_CODE, false);
1534 gotoInset(Inset::IGNORE_CODE, false);
1537 case LFUN_REFERENCE_GOTO:
1539 vector<Inset::Code> tmp;
1540 tmp.push_back(Inset::LABEL_CODE);
1541 tmp.push_back(Inset::REF_CODE);
1542 gotoInset(tmp, true);
1546 case LFUN_HYPHENATION:
1547 specialChar(InsetSpecialChar::HYPHENATION);
1550 case LFUN_LIGATURE_BREAK:
1551 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1555 specialChar(InsetSpecialChar::LDOTS);
1558 case LFUN_END_OF_SENTENCE:
1559 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1562 case LFUN_MENU_SEPARATOR:
1563 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1571 changeDepth(bv_, bv_->getLyXText(), 0);
1574 case LFUN_DEPTH_MIN:
1575 changeDepth(bv_, bv_->getLyXText(), -1);
1578 case LFUN_DEPTH_PLUS:
1579 changeDepth(bv_, bv_->getLyXText(), 1);
1583 owner_->getDialogs()->setUserFreeFont();
1590 owner_->showState();
1594 case LFUN_FILE_INSERT:
1596 MenuInsertLyXFile(argument);
1600 case LFUN_FILE_INSERT_ASCII_PARA:
1601 InsertAsciiFile(bv_, argument, true);
1604 case LFUN_FILE_INSERT_ASCII:
1605 InsertAsciiFile(bv_, argument, false);
1610 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1611 << argument << endl;
1613 // Derive layout number from given argument (string)
1614 // and current buffer's textclass (number). */
1615 LyXTextClassList::ClassList::size_type tclass =
1616 buffer_->params.textclass;
1617 pair <bool, LyXTextClass::size_type> layout =
1618 textclasslist.NumberOfLayout(tclass, argument);
1620 // If the entry is obsolete, use the new one instead.
1622 string obs = textclasslist.Style(tclass,layout.second)
1626 textclasslist.NumberOfLayout(tclass, obs);
1629 // see if we found the layout number:
1630 if (!layout.first) {
1631 owner_->getLyXFunc()->setErrorMessage(
1632 string(N_("Layout ")) + argument +
1637 if (current_layout != layout.second) {
1638 LyXText * lt = bv_->getLyXText();
1640 current_layout = layout.second;
1643 | BufferView::FITCUR);
1644 lt->setLayout(bv_, layout.second);
1645 owner_->setLayout(layout.second);
1648 | BufferView::FITCUR
1649 | BufferView::CHANGE);
1656 Lang(bv_, argument);
1658 owner_->showState();
1663 owner_->showState();
1668 owner_->showState();
1673 owner_->showState();
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1696 case LFUN_UNDERLINE:
1698 owner_->showState();
1701 case LFUN_FONT_SIZE:
1702 FontSize(bv_, argument);
1703 owner_->showState();
1706 case LFUN_FONT_STATE:
1707 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1710 case LFUN_UPCASE_WORD:
1712 LyXText * lt = bv_->getLyXText();
1716 | BufferView::FITCUR);
1717 lt->changeCase(bv_, LyXText::text_uppercase);
1718 if (lt->inset_owner)
1719 updateInset(lt->inset_owner, true);
1722 | BufferView::FITCUR
1723 | BufferView::CHANGE);
1727 case LFUN_LOWCASE_WORD:
1729 LyXText * lt = bv_->getLyXText();
1731 update(lt, BufferView::SELECT|BufferView::FITCUR);
1732 lt->changeCase(bv_, LyXText::text_lowercase);
1733 if (lt->inset_owner)
1734 updateInset(lt->inset_owner, true);
1737 | BufferView::FITCUR
1738 | BufferView::CHANGE);
1742 case LFUN_CAPITALIZE_WORD:
1744 LyXText * lt = bv_->getLyXText();
1746 update(lt, BufferView::SELECT|BufferView::FITCUR);
1747 lt->changeCase(bv_, LyXText::text_capitalization);
1748 if (lt->inset_owner)
1749 updateInset(lt->inset_owner, true);
1752 | BufferView::FITCUR
1753 | BufferView::CHANGE);
1757 case LFUN_TRANSPOSE_CHARS:
1759 LyXText * lt = bv_->getLyXText();
1761 update(lt, BufferView::SELECT|BufferView::FITCUR);
1762 lt->transposeChars(*bv_);
1763 if (lt->inset_owner)
1764 updateInset(lt->inset_owner, true);
1767 | BufferView::FITCUR
1768 | BufferView::CHANGE);
1773 case LFUN_INSERT_LABEL:
1774 MenuInsertLabel(bv_, argument);
1777 case LFUN_REF_INSERT:
1778 if (argument.empty()) {
1779 InsetCommandParams p("ref");
1780 owner_->getDialogs()->createRef(p.getAsString());
1782 InsetCommandParams p;
1783 p.setFromString(argument);
1785 InsetRef * inset = new InsetRef(p, *buffer_);
1786 if (!insertInset(inset))
1789 updateInset(inset, true);
1793 case LFUN_BOOKMARK_SAVE:
1794 savePosition(strToUnsignedInt(argument));
1797 case LFUN_BOOKMARK_GOTO:
1798 restorePosition(strToUnsignedInt(argument));
1803 string label(argument);
1804 if (label.empty()) {
1806 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1808 label = inset->getContents();
1813 if (!label.empty()) {
1814 //bv_->savePosition(0);
1815 if (!bv_->gotoLabel(label))
1816 WriteAlert(_("Error"),
1817 _("Couldn't find this label"),
1818 _("in current document."));
1823 // --- Cursor Movements -----------------------------
1826 LyXText * lt = bv_->getLyXText();
1828 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1829 if (!lt->selection.mark())
1831 update(lt, BufferView::SELECT|BufferView::FITCUR);
1833 lt->cursorLeft(bv_, false);
1834 if (lt->cursor.pos() < lt->cursor.par()->size()
1835 && lt->cursor.par()->getChar(lt->cursor.pos())
1836 == Paragraph::META_INSET
1837 && lt->cursor.par()->getInset(lt->cursor.pos())
1838 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1839 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1840 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1842 tmpinset->edit(bv_, false);
1844 tmpinset->edit(bv_);
1848 lt->cursorRight(bv_, false);
1850 moveCursorUpdate(false);
1851 owner_->showState();
1857 // This is soooo ugly. Isn`t it possible to make
1858 // it simpler? (Lgb)
1859 LyXText * lt = bv_->getLyXText();
1860 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1861 if (!lt->selection.mark())
1863 update(lt, BufferView::SELECT|BufferView::FITCUR);
1864 LyXCursor const cur = lt->cursor;
1866 lt->cursorLeft(bv_, false);
1867 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1868 lt->cursor.pos() < lt->cursor.par()->size() &&
1869 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1870 Paragraph::META_INSET) &&
1871 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1872 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1873 == Inset::HIGHLY_EDITABLE))
1875 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1876 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1878 tmpinset->edit(bv_);
1880 tmpinset->edit(bv_, false);
1884 lt->cursorRight(bv_, false);
1887 moveCursorUpdate(false);
1888 owner_->showState();
1894 LyXText * lt = bv_->getLyXText();
1896 if (!lt->selection.mark())
1898 update(lt, BufferView::UPDATE);
1901 moveCursorUpdate(false);
1902 owner_->showState();
1908 LyXText * lt = bv_->getLyXText();
1910 if (!lt->selection.mark())
1912 update(lt, BufferView::UPDATE);
1913 lt->cursorDown(bv_);
1915 moveCursorUpdate(false);
1916 owner_->showState();
1920 case LFUN_UP_PARAGRAPH:
1922 LyXText * lt = bv_->getLyXText();
1924 if (!lt->selection.mark())
1926 update(lt, BufferView::UPDATE);
1927 lt->cursorUpParagraph(bv_);
1929 moveCursorUpdate(false);
1930 owner_->showState();
1934 case LFUN_DOWN_PARAGRAPH:
1936 LyXText * lt = bv_->getLyXText();
1938 if (!lt->selection.mark())
1940 update(lt, BufferView::UPDATE);
1941 lt->cursorDownParagraph(bv_);
1943 moveCursorUpdate(false);
1944 owner_->showState();
1950 LyXText * lt = bv_->getLyXText();
1952 if (!lt->selection.mark())
1954 update(lt, BufferView::UPDATE);
1957 moveCursorUpdate(false);
1958 owner_->showState();
1964 LyXText * lt = bv_->getLyXText();
1966 if (!lt->selection.mark())
1968 update(lt, BufferView::UPDATE);
1971 moveCursorUpdate(false);
1972 owner_->showState();
1978 LyXText * lt = bv_->getLyXText();
1980 if (!lt->selection.mark())
1982 update(lt, BufferView::SELECT|BufferView::FITCUR);
1983 lt->cursorHome(bv_);
1985 moveCursorUpdate(false);
1986 owner_->showState();
1992 LyXText * lt = bv_->getLyXText();
1994 if (!lt->selection.mark())
1997 BufferView::SELECT|BufferView::FITCUR);
2000 moveCursorUpdate(false);
2001 owner_->showState();
2005 case LFUN_SHIFT_TAB:
2008 LyXText * lt = bv_->getLyXText();
2010 if (!lt->selection.mark())
2013 BufferView::SELECT|BufferView::FITCUR);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2021 case LFUN_WORDRIGHT:
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2027 update(lt, BufferView::SELECT|BufferView::FITCUR);
2028 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2029 lt->cursorLeftOneWord(bv_);
2031 lt->cursorRightOneWord(bv_);
2033 moveCursorUpdate(false);
2034 owner_->showState();
2040 LyXText * lt = bv_->getLyXText();
2042 if (!lt->selection.mark())
2044 update(lt, BufferView::SELECT|BufferView::FITCUR);
2045 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2046 lt->cursorRightOneWord(bv_);
2048 lt->cursorLeftOneWord(bv_);
2050 moveCursorUpdate(false);
2051 owner_->showState();
2055 case LFUN_BEGINNINGBUF:
2057 LyXText * lt = bv_->getLyXText();
2059 if (!lt->selection.mark())
2062 BufferView::SELECT|BufferView::FITCUR);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2077 BufferView::SELECT|BufferView::FITCUR);
2078 lt->cursorBottom(bv_);
2080 moveCursorUpdate(false);
2081 owner_->showState();
2085 /* cursor selection ---------------------------- */
2088 LyXText * lt = bv_->getLyXText();
2091 BufferView::SELECT|BufferView::FITCUR);
2092 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2093 lt->cursorLeft(bv_);
2095 lt->cursorRight(bv_);
2097 moveCursorUpdate(true);
2098 owner_->showState();
2104 LyXText * lt = bv_->getLyXText();
2107 BufferView::SELECT|BufferView::FITCUR);
2108 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2109 lt->cursorRight(bv_);
2111 lt->cursorLeft(bv_);
2113 moveCursorUpdate(true);
2114 owner_->showState();
2120 LyXText * lt = bv_->getLyXText();
2123 BufferView::SELECT|BufferView::FITCUR);
2126 moveCursorUpdate(true);
2127 owner_->showState();
2133 LyXText * lt = bv_->getLyXText();
2136 BufferView::SELECT|BufferView::FITCUR);
2137 lt->cursorDown(bv_);
2139 moveCursorUpdate(true);
2140 owner_->showState();
2144 case LFUN_UP_PARAGRAPHSEL:
2146 LyXText * lt = bv_->getLyXText();
2149 BufferView::SELECT|BufferView::FITCUR);
2150 lt->cursorUpParagraph(bv_);
2152 moveCursorUpdate(true);
2153 owner_->showState();
2157 case LFUN_DOWN_PARAGRAPHSEL:
2159 LyXText * lt = bv_->getLyXText();
2162 BufferView::SELECT|BufferView::FITCUR);
2163 lt->cursorDownParagraph(bv_);
2165 moveCursorUpdate(true);
2166 owner_->showState();
2172 LyXText * lt = bv_->getLyXText();
2174 update(lt, BufferView::SELECT|BufferView::FITCUR);
2177 moveCursorUpdate(true);
2178 owner_->showState();
2184 LyXText * lt = bv_->getLyXText();
2186 update(lt, BufferView::SELECT|BufferView::FITCUR);
2189 moveCursorUpdate(true);
2190 owner_->showState();
2196 LyXText * lt = bv_->getLyXText();
2198 update(lt, BufferView::SELECT|BufferView::FITCUR);
2199 lt->cursorHome(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2208 LyXText * lt = bv_->getLyXText();
2210 update(lt, BufferView::SELECT|BufferView::FITCUR);
2213 moveCursorUpdate(true);
2214 owner_->showState();
2218 case LFUN_WORDRIGHTSEL:
2220 LyXText * lt = bv_->getLyXText();
2222 update(lt, BufferView::SELECT|BufferView::FITCUR);
2223 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2224 lt->cursorLeftOneWord(bv_);
2226 lt->cursorRightOneWord(bv_);
2228 moveCursorUpdate(true);
2229 owner_->showState();
2233 case LFUN_WORDLEFTSEL:
2235 LyXText * lt = bv_->getLyXText();
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2239 lt->cursorRightOneWord(bv_);
2241 lt->cursorLeftOneWord(bv_);
2243 moveCursorUpdate(true);
2244 owner_->showState();
2248 case LFUN_BEGINNINGBUFSEL:
2250 LyXText * lt = bv_->getLyXText();
2252 if (lt->inset_owner)
2254 update(lt, BufferView::SELECT|BufferView::FITCUR);
2257 moveCursorUpdate(true);
2258 owner_->showState();
2262 case LFUN_ENDBUFSEL:
2264 LyXText * lt = bv_->getLyXText();
2266 if (lt->inset_owner)
2269 BufferView::SELECT|BufferView::FITCUR);
2270 lt->cursorBottom(bv_);
2272 moveCursorUpdate(true);
2273 owner_->showState();
2277 // --- text changing commands ------------------------
2278 case LFUN_BREAKLINE:
2280 LyXText * lt = bv_->getLyXText();
2283 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2286 | BufferView::FITCUR
2287 | BufferView::CHANGE);
2288 moveCursorUpdate(false);
2292 case LFUN_PROTECTEDSPACE:
2294 LyXText * lt = bv_->getLyXText();
2296 LyXLayout const & style = textclasslist
2297 .Style(buffer_->params.textclass,
2298 lt->cursor.par()->getLayout());
2300 if (style.free_spacing) {
2301 lt->insertChar(bv_, ' ');
2304 | BufferView::FITCUR
2305 | BufferView::CHANGE);
2309 moveCursorUpdate(false);
2315 LyXText * lt = bv_->getLyXText();
2317 if (lt->selection.mark()) {
2321 | BufferView::FITCUR);
2322 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2325 lt->selection.mark(true);
2328 | BufferView::FITCUR);
2329 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2331 lt->selection.cursor = lt->cursor;
2337 LyXText * lt = bv_->getLyXText();
2339 if (!lt->selection.set()) {
2341 lt->selection.cursor = lt->cursor;
2344 | BufferView::FITCUR
2345 | BufferView::CHANGE);
2346 // It is possible to make it a lot faster still
2347 // just comment out the line below...
2352 moveCursorUpdate(false);
2353 owner_->showState();
2358 case LFUN_DELETE_SKIP:
2360 LyXText * lt = bv_->getLyXText();
2362 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2364 LyXCursor cursor = lt->cursor;
2366 if (!lt->selection.set()) {
2367 if (cursor.pos() == cursor.par()->size()) {
2368 lt->cursorRight(bv_);
2369 cursor = lt->cursor;
2370 if (cursor.pos() == 0
2371 && !(cursor.par()->params().spaceTop()
2372 == VSpace (VSpace::NONE))) {
2375 cursor.par()->params().lineTop(),
2376 cursor.par()->params().lineBottom(),
2377 cursor.par()->params().pagebreakTop(),
2378 cursor.par()->params().pagebreakBottom(),
2379 VSpace(VSpace::NONE),
2380 cursor.par()->params().spaceBottom(),
2381 cursor.par()->params().align(),
2382 cursor.par()->params().labelWidthString(), 0);
2383 lt->cursorLeft(bv_);
2386 | BufferView::FITCUR
2387 | BufferView::CHANGE);
2389 lt->cursorLeft(bv_);
2391 lt->selection.cursor = lt->cursor;
2394 | BufferView::FITCUR
2395 | BufferView::CHANGE);
2399 lt->selection.cursor = lt->cursor;
2402 | BufferView::FITCUR
2403 | BufferView::CHANGE);
2411 /* -------> Delete word forward. */
2412 case LFUN_DELETE_WORD_FORWARD:
2413 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2414 bv_->getLyXText()->deleteWordForward(bv_);
2415 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2416 moveCursorUpdate(false);
2417 owner_->showState();
2420 /* -------> Delete word backward. */
2421 case LFUN_DELETE_WORD_BACKWARD:
2423 LyXText * lt = bv_->getLyXText();
2425 update(lt, BufferView::SELECT|BufferView::FITCUR);
2426 lt->deleteWordBackward(bv_);
2429 | BufferView::FITCUR
2430 | BufferView::CHANGE);
2431 moveCursorUpdate(false);
2432 owner_->showState();
2436 /* -------> Kill to end of line. */
2437 case LFUN_DELETE_LINE_FORWARD:
2439 LyXText * lt = bv_->getLyXText();
2441 update(lt, BufferView::SELECT|BufferView::FITCUR);
2442 lt->deleteLineForward(bv_);
2445 | BufferView::FITCUR
2446 | BufferView::CHANGE);
2447 moveCursorUpdate(false);
2451 /* -------> Set mark off. */
2454 LyXText * lt = bv_->getLyXText();
2457 update(lt, BufferView::SELECT|BufferView::FITCUR);
2458 lt->selection.cursor = lt->cursor;
2459 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2463 /* -------> Set mark on. */
2466 LyXText * lt = bv_->getLyXText();
2469 lt->selection.mark(true);
2470 update(lt, BufferView::SELECT|BufferView::FITCUR);
2471 lt->selection.cursor = lt->cursor;
2472 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2476 case LFUN_BACKSPACE:
2478 LyXText * lt = bv_->getLyXText();
2480 if (!lt->selection.set()) {
2481 if (owner_->getIntl()->getTrans().backspace()) {
2483 lt->selection.cursor = lt->cursor;
2486 | BufferView::FITCUR
2487 | BufferView::CHANGE);
2488 // It is possible to make it a lot faster still
2489 // just comment out the line below...
2495 owner_->showState();
2500 case LFUN_BACKSPACE_SKIP:
2502 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2503 LyXText * lt = bv_->getLyXText();
2505 LyXCursor cursor = lt->cursor;
2507 if (!lt->selection.set()) {
2508 if (cursor.pos() == 0
2509 && !(cursor.par()->params().spaceTop()
2510 == VSpace (VSpace::NONE))) {
2513 cursor.par()->params().lineTop(),
2514 cursor.par()->params().lineBottom(),
2515 cursor.par()->params().pagebreakTop(),
2516 cursor.par()->params().pagebreakBottom(),
2517 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2518 cursor.par()->params().align(),
2519 cursor.par()->params().labelWidthString(), 0);
2522 | BufferView::FITCUR
2523 | BufferView::CHANGE);
2526 lt->selection.cursor = cursor;
2529 | BufferView::FITCUR
2530 | BufferView::CHANGE);
2537 case LFUN_BREAKPARAGRAPH:
2539 LyXText * lt = bv_->getLyXText();
2542 lt->breakParagraph(bv_, 0);
2545 | BufferView::FITCUR
2546 | BufferView::CHANGE);
2547 lt->selection.cursor = lt->cursor;
2549 owner_->showState();
2553 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2555 LyXText * lt = bv_->getLyXText();
2558 lt->breakParagraph(bv_, 1);
2561 | BufferView::FITCUR
2562 | BufferView::CHANGE);
2563 lt->selection.cursor = lt->cursor;
2565 owner_->showState();
2569 case LFUN_BREAKPARAGRAPH_SKIP:
2571 // When at the beginning of a paragraph, remove
2572 // indentation and add a "defskip" at the top.
2573 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2574 LyXText * lt = bv_->getLyXText();
2576 LyXCursor cursor = lt->cursor;
2579 if (cursor.pos() == 0) {
2580 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2583 cursor.par()->params().lineTop(),
2584 cursor.par()->params().lineBottom(),
2585 cursor.par()->params().pagebreakTop(),
2586 cursor.par()->params().pagebreakBottom(),
2587 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2588 cursor.par()->params().align(),
2589 cursor.par()->params().labelWidthString(), 1);
2590 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2594 lt->breakParagraph(bv_, 0);
2595 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2600 | BufferView::FITCUR
2601 | BufferView::CHANGE);
2602 lt->selection.cursor = cursor;
2604 owner_->showState();
2608 case LFUN_PARAGRAPH_SPACING:
2610 LyXText * lt = bv_->getLyXText();
2612 Paragraph * par = lt->cursor.par();
2613 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2614 float cur_value = 1.0;
2615 if (cur_spacing == Spacing::Other) {
2616 cur_value = par->params().spacing().getValue();
2619 istringstream istr(argument.c_str());
2623 Spacing::Space new_spacing = cur_spacing;
2624 float new_value = cur_value;
2626 lyxerr << "Missing argument to `paragraph-spacing'"
2628 } else if (tmp == "single") {
2629 new_spacing = Spacing::Single;
2630 } else if (tmp == "onehalf") {
2631 new_spacing = Spacing::Onehalf;
2632 } else if (tmp == "double") {
2633 new_spacing = Spacing::Double;
2634 } else if (tmp == "other") {
2635 new_spacing = Spacing::Other;
2638 lyxerr << "new_value = " << tmpval << endl;
2641 } else if (tmp == "default") {
2642 new_spacing = Spacing::Default;
2644 lyxerr << _("Unknown spacing argument: ")
2645 << argument << endl;
2647 if (cur_spacing != new_spacing || cur_value != new_value) {
2648 par->params().spacing(Spacing(new_spacing, new_value));
2649 lt->redoParagraph(bv_);
2652 | BufferView::FITCUR
2653 | BufferView::CHANGE);
2658 case LFUN_INSET_TOGGLE:
2660 LyXText * lt = bv_->getLyXText();
2663 update(lt, BufferView::SELECT|BufferView::FITCUR);
2664 lt->toggleInset(bv_);
2665 update(lt, BufferView::SELECT|BufferView::FITCUR);
2677 InsetCommandParams p;
2678 if (action == LFUN_HTMLURL)
2679 p.setCmdName("htmlurl");
2681 p.setCmdName("url");
2682 owner_->getDialogs()->createUrl(p.getAsString());
2686 case LFUN_INSERT_URL:
2688 InsetCommandParams p;
2689 p.setFromString(argument);
2691 InsetUrl * inset = new InsetUrl(p);
2692 if (!insertInset(inset))
2695 updateInset(inset, true);
2699 case LFUN_INSET_TEXT:
2700 insertAndEditInset(new InsetText);
2703 case LFUN_INSET_ERT:
2704 insertAndEditInset(new InsetERT);
2707 case LFUN_INSET_EXTERNAL:
2708 insertAndEditInset(new InsetExternal);
2711 case LFUN_INSET_FOOTNOTE:
2712 insertAndEditInset(new InsetFoot);
2715 case LFUN_INSET_MARGINAL:
2716 insertAndEditInset(new InsetMarginal);
2719 case LFUN_INSET_MINIPAGE:
2720 insertAndEditInset(new InsetMinipage);
2723 case LFUN_INSERT_NOTE:
2724 insertAndEditInset(new InsetNote);
2727 case LFUN_INSET_FLOAT:
2728 // check if the float type exist
2729 if (floatList.typeExist(argument)) {
2730 insertAndEditInset(new InsetFloat(argument));
2732 lyxerr << "Non-existant float type: "
2733 << argument << endl;
2737 case LFUN_INSET_WIDE_FLOAT:
2739 // check if the float type exist
2740 if (floatList.typeExist(argument)) {
2741 InsetFloat * new_inset = new InsetFloat(argument);
2742 new_inset->wide(true);
2743 if (insertInset(new_inset))
2744 new_inset->edit(bv_);
2748 lyxerr << "Non-existant float type: "
2749 << argument << endl;
2756 case LFUN_INSET_LIST:
2757 insertAndEditInset(new InsetList);
2760 case LFUN_INSET_THEOREM:
2761 insertAndEditInset(new InsetTheorem);
2765 case LFUN_INSET_CAPTION:
2767 // Do we have a locking inset...
2768 if (bv_->theLockingInset()) {
2769 lyxerr << "Locking inset code: "
2770 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2771 InsetCaption * new_inset = new InsetCaption;
2772 new_inset->setOwner(bv_->theLockingInset());
2773 new_inset->setAutoBreakRows(true);
2774 new_inset->setDrawFrame(0, InsetText::LOCKED);
2775 new_inset->setFrameColor(0, LColor::captionframe);
2776 if (insertInset(new_inset))
2777 new_inset->edit(bv_);
2784 case LFUN_INSET_TABULAR:
2788 if (!argument.empty())
2789 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2790 InsetTabular * new_inset =
2791 new InsetTabular(*buffer_, r, c);
2793 bv_->getLyXText()->real_current_font.isRightToLeft();
2794 if (!open_new_inset(new_inset, rtl))
2799 // --- lyxserver commands ----------------------------
2801 case LFUN_CHARATCURSOR:
2803 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2804 if (pos < bv_->getLyXText()->cursor.par()->size())
2805 owner_->getLyXFunc()->setMessage(
2806 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2808 owner_->getLyXFunc()->setMessage("EOF");
2813 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2815 + tostr(bv_->getLyXText()->cursor.y()));
2822 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2823 lyxerr << "SETXY: Could not parse coordinates in '"
2824 << argument << std::endl;
2826 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2830 case LFUN_GETLAYOUT:
2831 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2836 LyXFont & font = bv_->getLyXText()->current_font;
2837 if (font.shape() == LyXFont::ITALIC_SHAPE)
2838 owner_->getLyXFunc()->setMessage("E");
2839 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2840 owner_->getLyXFunc()->setMessage("N");
2842 owner_->getLyXFunc()->setMessage("0");
2850 LyXFont & font = bv_->getLyXText()->current_font;
2851 if (font.latex() == LyXFont::ON)
2852 owner_->getLyXFunc()->setMessage("L");
2855 owner_->getLyXFunc()->setMessage("0");
2859 // --- accented characters ---------------------------
2862 case LFUN_CIRCUMFLEX:
2872 case LFUN_SPECIAL_CARON:
2875 case LFUN_HUNG_UMLAUT:
2878 if (argument.empty()) {
2880 owner_->getLyXFunc()->handleKeyFunc(action);
2882 owner_->getLyXFunc()->handleKeyFunc(action);
2883 owner_->getIntl()->getTrans()
2884 .TranslateAndInsert(argument[0], bv_->getLyXText());
2885 update(bv_->getLyXText(),
2887 | BufferView::FITCUR
2888 | BufferView::CHANGE);
2892 case LFUN_MATH_MACRO:
2893 mathDispatchMathMacro(bv_, argument);
2896 case LFUN_MATH_DELIM:
2897 mathDispatchMathDelim(bv_, argument);
2900 case LFUN_INSERT_MATRIX:
2901 mathDispatchInsertMatrix(bv_, argument);
2904 case LFUN_INSERT_MATH:
2905 mathDispatchInsertMath(bv_, argument);
2908 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2909 mathDispatchMathImportSelection(bv_, argument);
2912 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2913 mathDispatchMathDisplay(bv_, argument);
2916 case LFUN_MATH_MODE: // Open or create an inlined math inset
2917 mathDispatchMathMode(bv_, argument);
2920 case LFUN_CITATION_INSERT:
2922 InsetCommandParams p;
2923 p.setFromString( argument );
2925 InsetCitation * inset = new InsetCitation( p );
2926 if (!insertInset(inset))
2929 updateInset( inset, true );
2933 case LFUN_INSERT_BIBTEX:
2935 // ale970405+lasgoutt970425
2936 // The argument can be up to two tokens separated
2937 // by a space. The first one is the bibstyle.
2938 string const db = token(argument, ' ', 0);
2939 string bibstyle = token(argument, ' ', 1);
2940 if (bibstyle.empty())
2943 InsetCommandParams p( "BibTeX", db, bibstyle );
2944 InsetBibtex * inset = new InsetBibtex(p);
2946 if (insertInset(inset)) {
2947 if (argument.empty())
2954 // BibTeX data bases
2955 case LFUN_BIBDB_ADD:
2957 InsetBibtex * inset =
2958 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2960 inset->addDatabase(argument);
2965 case LFUN_BIBDB_DEL:
2967 InsetBibtex * inset =
2968 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2970 inset->delDatabase(argument);
2975 case LFUN_BIBTEX_STYLE:
2977 InsetBibtex * inset =
2978 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2980 inset->setOptions(argument);
2985 case LFUN_INDEX_CREATE:
2987 InsetCommandParams p("index");
2988 LyXText * lt = bv_->getLyXText();
2990 if (argument.empty()) {
2991 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2992 if (!idxstring.empty())
2993 p.setContents(idxstring);
2997 p.setContents(argument);
3000 owner_->getDialogs()->createIndex(p.getAsString());
3004 case LFUN_INDEX_INSERT:
3006 InsetCommandParams p;
3007 p.setFromString(argument);
3008 InsetIndex * inset = new InsetIndex(p);
3010 if (!insertInset(inset))
3013 updateInset(inset, true);
3017 case LFUN_INDEX_INSERT_LAST:
3019 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3020 if (!idxstring.empty()) {
3021 owner_->message(_("Word `")
3022 + idxstring + _(("' indexed.")));
3023 InsetCommandParams p("index", idxstring);
3024 InsetIndex * inset = new InsetIndex(p);
3026 if (!insertInset(inset))
3029 updateInset(inset, true);
3034 case LFUN_INDEX_PRINT:
3036 InsetCommandParams p("printindex");
3037 Inset * inset = new InsetPrintIndex(p);
3038 if (!insertInset(inset, "Standard"))
3043 case LFUN_PARENTINSERT:
3045 lyxerr << "arg " << argument << endl;
3046 InsetCommandParams p( "lyxparent", argument );
3047 Inset * inset = new InsetParent(p, *buffer_);
3048 if (!insertInset(inset, "Standard"))
3054 case LFUN_CHILD_INSERT:
3056 InsetInclude::Params p;
3057 p.cparams.setFromString(argument);
3058 p.masterFilename_ = buffer_->fileName();
3060 InsetInclude * inset = new InsetInclude(p);
3061 if (!insertInset(inset))
3064 updateInset(inset, true);
3065 bv_->owner()->getDialogs()->showInclude(inset);
3070 case LFUN_FLOAT_LIST:
3072 // We should check the argument for validity. (Lgb)
3073 Inset * inset = new InsetFloatList(argument);
3074 if (!insertInset(inset, "Standard"))
3079 case LFUN_THESAURUS_ENTRY:
3081 string arg = argument;
3084 arg = bv_->getLyXText()->selectionAsString(buffer_);
3087 if (arg.size() > 100 || arg.empty()) {
3088 // Get word or selection
3089 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3090 arg = bv_->getLyXText()->selectionAsString(buffer_);
3091 // FIXME: where is getLyXText()->unselect(bv_) ?
3095 bv_->owner()->getDialogs()->showThesaurus(arg);
3099 case LFUN_SELFINSERT:
3101 if (argument.empty()) break;
3103 /* Automatically delete the currently selected
3104 * text and replace it with what is being
3105 * typed in now. Depends on lyxrc settings
3106 * "auto_region_delete", which defaults to
3109 LyXText * lt = bv_->getLyXText();
3111 if (lyxrc.auto_region_delete) {
3112 if (lt->selection.set()) {
3113 lt->cutSelection(bv_, false);
3116 | BufferView::FITCUR
3117 | BufferView::CHANGE);
3122 LyXFont const old_font(lt->real_current_font);
3124 string::const_iterator cit = argument.begin();
3125 string::const_iterator end = argument.end();
3126 for (; cit != end; ++cit) {
3127 if (greek_kb_flag) {
3128 if (!math_insert_greek(bv_, *cit))
3129 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3131 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3136 | BufferView::FITCUR
3137 | BufferView::CHANGE);
3139 lt->selection.cursor = lt->cursor;
3140 moveCursorUpdate(false);
3142 // real_current_font.number can change so we need to
3143 // update the minibuffer
3144 if (old_font != lt->real_current_font)
3145 owner_->showState();
3150 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3152 time_t now_time_t = time(NULL);
3153 struct tm * now_tm = localtime(&now_time_t);
3154 setlocale(LC_TIME, "");
3156 if (!argument.empty())
3159 arg = lyxrc.date_insert_format;
3161 int const datetmp_len =
3162 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3164 LyXText * lt = bv_->getLyXText();
3166 for (int i = 0; i < datetmp_len; i++) {
3167 lt->insertChar(bv_, datetmp[i]);
3170 | BufferView::FITCUR
3171 | BufferView::CHANGE);
3174 lt->selection.cursor = lt->cursor;
3175 moveCursorUpdate(false);
3179 case LFUN_UNKNOWN_ACTION:
3180 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3191 void BufferView::Pimpl::newline()
3194 LyXText * lt = bv_->getLyXText();
3198 | BufferView::FITCUR);
3199 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3202 | BufferView::FITCUR
3203 | BufferView::CHANGE);
3208 void BufferView::Pimpl::hfill()
3211 LyXText * lt = bv_->getLyXText();
3215 | BufferView::FITCUR);
3216 lt->insertChar(bv_, Paragraph::META_HFILL);
3219 | BufferView::FITCUR
3220 | BufferView::CHANGE);
3225 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3229 update(lt, BufferView::SELECT|BufferView::FITCUR);
3230 InsetSpecialChar * new_inset =
3231 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3232 #ifdef WITH_WARNINGS
3233 #warning Why is this code different from specialChar() below? (JMarc)
3234 // the code in specialChar is a generic version of what used to exist
3235 // for other special chars. I did not merge this case because of the
3236 // call to updateInset(), but what does it do?
3238 if (!insertInset(new_inset))
3241 updateInset(new_inset, true);
3246 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3249 LyXText * lt = bv_->getLyXText();
3252 update(lt, BufferView::SELECT|BufferView::FITCUR);
3253 InsetSpecialChar * new_inset =
3254 new InsetSpecialChar(kind);
3255 insertInset(new_inset);
3260 void BufferView::Pimpl::smartQuote()
3263 LyXText * lt = bv_->getLyXText();
3265 if (lt->cursor.pos())
3266 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3271 if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
3272 Dispatch(LFUN_SELFINSERT, "\"");
3276 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3278 if (insertInset(inset))
3285 // Open and lock an updatable inset
3286 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3288 LyXText * lt = bv_->getLyXText();
3292 if (!insertInset(new_inset)) {
3296 new_inset->edit(bv_, !behind);
3301 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3303 // if we are in a locking inset we should try to insert the
3304 // inset there otherwise this is a illegal function now
3305 if (bv_->theLockingInset()) {
3306 if (bv_->theLockingInset()->insetAllowed(inset))
3307 return bv_->theLockingInset()->insertInset(bv_, inset);
3311 // not quite sure if we want this...
3312 setCursorParUndo(bv_);
3315 beforeChange(bv_->text);
3316 if (!lout.empty()) {
3317 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3318 bv_->text->breakParagraph(bv_);
3319 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3321 if (bv_->text->cursor.par()->size()) {
3322 bv_->text->cursorLeft(bv_);
3324 bv_->text->breakParagraph(bv_);
3325 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3328 pair<bool, LyXTextClass::size_type> lres =
3329 textclasslist.NumberOfLayout(buffer_->params
3331 LyXTextClass::size_type lay;
3332 if (lres.first != false) {
3336 // layout not fount using default "Standard" (0)
3340 bv_->text->setLayout(bv_, lay);
3342 bv_->text->setParagraph(bv_, 0, 0,
3344 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3348 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3350 bv_->text->current_font.setLatex(LyXFont::OFF);
3354 bv_->text->insertInset(bv_, inset);
3355 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3362 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3367 // first check for locking insets
3368 if (bv_->theLockingInset()) {
3369 if (bv_->theLockingInset() == inset) {
3370 if (bv_->text->updateInset(bv_, inset)) {
3373 buffer_->markDirty();
3378 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3379 if (bv_->text->updateInset(bv_,
3380 bv_->theLockingInset())) {
3383 buffer_->markDirty();
3391 // then check the current buffer
3394 update(bv_->text, BufferView::UPDATE);
3395 if (bv_->text->updateInset(bv_, inset)) {
3399 | BufferView::FITCUR
3400 | BufferView::CHANGE);
3402 update(bv_->text, SELECT);
3410 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3413 if (!available()) return;
3416 beforeChange(bv_->text);
3417 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3421 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3422 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3423 if (find(codes.begin(), codes.end(), inset->lyxCode())
3426 static_cast<InsetCommand const *>(inset)->getContents();
3429 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3430 if (bv_->text->cursor.pos()
3431 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3432 LyXCursor tmp = bv_->text->cursor;
3433 bv_->text->cursor.par(bv_->text->firstParagraph());
3434 bv_->text->cursor.pos(0);
3435 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3436 bv_->text->cursor = tmp;
3437 bv_->owner()->message(_("No more insets"));
3440 bv_->owner()->message(_("No more insets"));
3443 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3444 bv_->text->selection.cursor = bv_->text->cursor;
3448 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3450 gotoInset(vector<Inset::Code>(1, code), same_content);