7 #include "BufferView_pimpl.h"
12 #include "paragraph.h"
14 #include "commandtags.h"
18 #include "bufferview_funcs.h"
19 #include "TextCache.h"
20 #include "bufferlist.h"
21 #include "lyx_gui_misc.h"
24 // added for Dispatch functions
27 #include "FloatList.h"
29 #include "ParagraphParameters.h"
30 #include "undo_funcs.h"
31 #include "lyxtextclasslist.h"
33 #include "frontends/Dialogs.h"
34 #include "frontends/Alert.h"
35 #include "frontends/FileDialog.h"
37 #include "insets/insetbib.h"
38 #include "insets/insettext.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetlatexaccent.h"
41 #include "insets/insettoc.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetnote.h"
46 #include "insets/insetinclude.h"
47 #include "insets/insetcite.h"
48 #include "insets/insetert.h"
49 #include "insets/insetexternal.h"
50 #include "insets/insetgraphics.h"
51 #include "insets/insetfoot.h"
52 #include "insets/insetmarginal.h"
53 #include "insets/insetminipage.h"
54 #include "insets/insetfloat.h"
55 #include "insets/insettabular.h"
57 #include "insets/insettheorem.h"
58 #include "insets/insetlist.h"
60 #include "insets/insetcaption.h"
61 #include "insets/insetfloatlist.h"
62 #include "insets/insetspecialchar.h"
64 #include "mathed/formulabase.h"
66 #include "support/LAssert.h"
67 #include "support/lstrings.h"
68 #include "support/filetools.h"
69 #include "support/lyxfunctional.h"
77 extern lyx::layout_type current_layout;
89 using lyx::layout_type;
90 using lyx::textclass_type;
92 /* the selection possible is needed, that only motion events are
93 * used, where the bottom press event was on the drawing area too */
94 bool selection_possible = false;
96 extern BufferList bufferlist;
97 extern char ascii_type;
99 extern void sigchldchecker(pid_t pid, int * status);
100 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
105 const unsigned int saved_positions_num = 20;
110 XSync(fl_get_display(), 0);
114 void SetXtermCursor(Window win)
116 static Cursor cursor;
117 static bool cursor_undefined = true;
118 if (cursor_undefined){
119 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
120 XFlush(fl_get_display());
121 cursor_undefined = false;
123 XDefineCursor(fl_get_display(), win, cursor);
124 XFlush(fl_get_display());
130 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
131 int xpos, int ypos, int width, int height)
132 : bv_(b), owner_(o), buffer_(0),
133 current_scrollbar_value(0), cursor_timeout(400),
134 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
138 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
139 workarea_.workAreaExpose
140 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
141 workarea_.workAreaEnter
142 .connect(slot(this, &BufferView::Pimpl::enterView));
143 workarea_.workAreaLeave
144 .connect(slot(this, &BufferView::Pimpl::leaveView));
145 workarea_.workAreaButtonPress
146 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
147 workarea_.workAreaButtonRelease
149 &BufferView::Pimpl::workAreaButtonRelease));
150 workarea_.workAreaMotionNotify
151 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
152 workarea_.workAreaDoubleClick
153 .connect(slot(this, &BufferView::Pimpl::doubleClick));
154 workarea_.workAreaTripleClick
155 .connect(slot(this, &BufferView::Pimpl::tripleClick));
156 workarea_.workAreaKeyPress
157 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
159 cursor_timeout.timeout.connect(slot(this,
160 &BufferView::Pimpl::cursorToggle));
161 cursor_timeout.start();
162 workarea_.setFocus();
163 saved_positions.resize(saved_positions_num);
167 Painter & BufferView::Pimpl::painter()
169 return workarea_.getPainter();
173 void BufferView::Pimpl::buffer(Buffer * b)
175 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
179 buffer_->delUser(bv_);
181 // Put the old text into the TextCache, but
182 // only if the buffer is still loaded.
183 // Also set the owner of the test to 0
184 // bv_->text->owner(0);
185 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
186 if (lyxerr.debugging())
187 textcache.show(lyxerr, "BufferView::buffer");
192 // Set current buffer
195 if (bufferlist.getState() == BufferList::CLOSING) return;
198 // screen is always deleted when the buffer is changed.
201 // If we are closing the buffer, use the first buffer as current
203 buffer_ = bufferlist.first();
207 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
208 buffer_->addUser(bv_);
209 // If we don't have a text object for this, we make one
210 if (bv_->text == 0) {
211 resizeCurrentBuffer();
216 bv_->text->first = screen_->topCursorVisible(bv_->text);
217 owner_->updateMenubar();
218 owner_->updateToolbar();
219 // Similarly, buffer-dependent dialogs should be updated or
220 // hidden. This should go here because some dialogs (eg ToC)
221 // require bv_->text.
222 owner_->getDialogs()->updateBufferDependent(true);
226 lyxerr[Debug::INFO] << " No Buffer!" << endl;
227 owner_->updateMenubar();
228 owner_->updateToolbar();
229 owner_->getDialogs()->hideBufferDependent();
233 // Also remove all remaining text's from the testcache.
234 // (there should not be any!) (if there is any it is a
236 if (lyxerr.debugging())
237 textcache.show(lyxerr, "buffer delete all");
240 // should update layoutchoice even if we don't have a buffer.
241 owner_->updateLayoutChoice();
243 owner_->updateWindowTitle();
247 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
249 workarea_.resize(xpos, ypos, width, height);
250 update(bv_->text, SELECT);
255 void BufferView::Pimpl::resize()
258 resizeCurrentBuffer();
262 void BufferView::Pimpl::redraw()
264 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
269 bool BufferView::Pimpl::fitCursor()
271 lyx::Assert(screen_.get());
275 if (bv_->theLockingInset()) {
276 bv_->theLockingInset()->fitInsetCursor(bv_);
279 ret = screen_->fitCursor(bv_->text, bv_);
282 bv_->owner()->getDialogs()->updateParagraph();
289 void BufferView::Pimpl::redoCurrentBuffer()
291 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
292 if (buffer_ && bv_->text) {
294 owner_->updateLayoutChoice();
299 int BufferView::Pimpl::resizeCurrentBuffer()
301 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
304 Paragraph * selstartpar = 0;
305 Paragraph * selendpar = 0;
306 UpdatableInset * the_locking_inset = 0;
309 pos_type selstartpos = 0;
310 pos_type selendpos = 0;
311 bool selection = false;
312 bool mark_set = false;
314 owner_->prohibitInput();
316 owner_->message(_("Formatting document..."));
319 par = bv_->text->cursor.par();
320 pos = bv_->text->cursor.pos();
321 selstartpar = bv_->text->selection.start.par();
322 selstartpos = bv_->text->selection.start.pos();
323 selendpar = bv_->text->selection.end.par();
324 selendpos = bv_->text->selection.end.pos();
325 selection = bv_->text->selection.set();
326 mark_set = bv_->text->selection.mark();
327 the_locking_inset = bv_->theLockingInset();
329 bv_->text = new LyXText(bv_);
330 bv_->text->init(bv_);
332 // See if we have a text in TextCache that fits
333 // the new buffer_ with the correct width.
334 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
336 if (lyxerr.debugging()) {
337 lyxerr << "Found a LyXText that fits:\n";
338 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
340 // Set the owner of the newly found text
341 // bv_->text->owner(bv_);
342 if (lyxerr.debugging())
343 textcache.show(lyxerr, "resizeCurrentBuffer");
345 bv_->text = new LyXText(bv_);
346 bv_->text->init(bv_);
352 bv_->text->selection.set(true);
353 /* at this point just to avoid the Delete-Empty-Paragraph
354 * Mechanism when setting the cursor */
355 bv_->text->selection.mark(mark_set);
357 bv_->text->setCursor(bv_, selstartpar, selstartpos);
358 bv_->text->selection.cursor = bv_->text->cursor;
359 bv_->text->setCursor(bv_, selendpar, selendpos);
360 bv_->text->setSelection(bv_);
361 bv_->text->setCursor(bv_, par, pos);
363 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->selection.cursor = bv_->text->cursor;
365 bv_->text->selection.set(false);
367 // remake the inset locking
368 bv_->theLockingInset(the_locking_inset);
370 bv_->text->first = screen_->topCursorVisible(bv_->text);
372 buffer_->resizeInsets(bv_);
374 // this will scroll the screen such that the cursor becomes visible
379 owner_->allowInput();
381 /// clear the "Formatting Document" message
388 void BufferView::Pimpl::updateScreen()
390 // Regenerate the screen.
391 screen_.reset(new LyXScreen(workarea_));
395 void BufferView::Pimpl::updateScrollbar()
397 /* If the text is smaller than the working area, the scrollbar
398 * maximum must be the working area height. No scrolling will
401 workarea_.setScrollbar(0, 1.0);
405 long const text_height = bv_->text->height;
407 double const lineh = bv_->text->defaultHeight();
408 double const slider_size =
409 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
411 static long old_text_height = 0;
412 static double old_lineh = 0;
413 static double old_slider_size = 0;
415 if (text_height != old_text_height) {
416 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
417 old_text_height = text_height;
419 if (lineh != old_lineh) {
420 workarea_.setScrollbarIncrements(lineh);
423 if (current_scrollbar_value != bv_->text->first
424 || slider_size != old_slider_size) {
425 current_scrollbar_value = bv_->text->first;
426 workarea_.setScrollbar(current_scrollbar_value, slider_size);
427 old_slider_size = slider_size;
432 // Callback for scrollbar slider
433 void BufferView::Pimpl::scrollCB(double value)
435 if (!buffer_) return;
437 current_scrollbar_value = long(value);
438 if (current_scrollbar_value < 0)
439 current_scrollbar_value = 0;
444 screen_->draw(bv_->text, bv_, current_scrollbar_value);
446 if (!lyxrc.cursor_follows_scrollbar) {
451 LyXText * vbt = bv_->text;
453 int const height = vbt->defaultHeight();
454 int const first = static_cast<int>((bv_->text->first + height));
455 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
457 if (vbt->cursor.y() < first)
458 vbt->setCursorFromCoordinates(bv_, 0, first);
459 else if (vbt->cursor.y() > last)
460 vbt->setCursorFromCoordinates(bv_, 0, last);
466 int BufferView::Pimpl::scrollUp(long time)
468 if (!buffer_) return 0;
469 if (!screen_.get()) return 0;
471 double value = workarea_.getScrollbarValue();
473 if (value == 0) return 0;
475 float add_value = (bv_->text->defaultHeight()
476 + float(time) * float(time) * 0.125);
478 if (add_value > workarea_.height())
479 add_value = float(workarea_.height() -
480 bv_->text->defaultHeight());
487 workarea_.setScrollbarValue(value);
494 int BufferView::Pimpl::scrollDown(long time)
496 if (!buffer_) return 0;
497 if (!screen_.get()) return 0;
499 double value = workarea_.getScrollbarValue();
500 pair<float, float> p = workarea_.getScrollbarBounds();
501 double const max = p.second;
503 if (value == max) return 0;
505 float add_value = (bv_->text->defaultHeight()
506 + float(time) * float(time) * 0.125);
508 if (add_value > workarea_.height())
509 add_value = float(workarea_.height() -
510 bv_->text->defaultHeight());
517 workarea_.setScrollbarValue(value);
524 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
526 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
530 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
532 // Only use motion with button 1
533 if (!(state & Button1MotionMask))
536 if (!buffer_ || !screen_.get()) return;
538 // Check for inset locking
539 if (bv_->theLockingInset()) {
540 LyXCursor cursor = bv_->text->cursor;
541 LyXFont font = bv_->text->getFont(buffer_,
542 cursor.par(), cursor.pos());
543 int width = bv_->theLockingInset()->width(bv_, font);
544 int inset_x = font.isVisibleRightToLeft()
545 ? cursor.x() - width : cursor.x();
546 int start_x = inset_x + bv_->theLockingInset()->scroll();
547 bv_->theLockingInset()->
548 insetMotionNotify(bv_,
550 y - cursor.y() + bv_->text->first,
555 /* The test for not selection possible is needed, that only motion
556 events are used, where the bottom press event was on
557 the drawing area too */
558 if (!selection_possible)
561 screen_->hideCursor();
563 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
565 if (!bv_->text->selection.set())
566 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
568 bv_->text->setSelection(bv_);
569 screen_->toggleToggle(bv_->text, bv_);
572 screen_->showCursor(bv_->text, bv_);
579 // Single-click on work area
580 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
583 if (!buffer_ || !screen_.get()) return;
585 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
587 // ok ok, this is a hack.
588 if (button == 4 || button == 5) {
591 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
594 scrollDown(lyxrc.wheel_jump);
599 if (bv_->theLockingInset()) {
600 // We are in inset locking mode
602 /* Check whether the inset was hit. If not reset mode,
603 otherwise give the event to the inset */
604 if (inset_hit == bv_->theLockingInset()) {
605 bv_->theLockingInset()->
606 insetButtonPress(bv_,xpos, ypos,button);
609 bv_->unlockInset(bv_->theLockingInset());
614 selection_possible = true;
615 screen_->hideCursor();
617 int const screen_first = bv_->text->first;
619 // Middle button press pastes if we have a selection
620 bool paste_internally = false;
622 && bv_->text->selection.set()) {
623 owner_->getLyXFunc()->dispatch(LFUN_COPY);
624 paste_internally = true;
627 // Clear the selection
628 screen_->toggleSelection(bv_->text, bv_);
629 bv_->text->clearSelection();
630 bv_->text->fullRebreak(bv_);
632 screen_->update(bv_->text, bv_);
638 // Single left click in math inset?
639 if (isHighlyEditableInset(inset_hit)) {
640 // Highly editable inset, like math
641 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
642 selection_possible = false;
643 owner_->updateLayoutChoice();
644 owner_->message(inset->editMessage());
645 inset->insetButtonPress(bv_, xpos, ypos, button);
646 inset->edit(bv_, xpos, ypos, button);
650 // Right click on a footnote flag opens float menu
652 selection_possible = false;
656 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
657 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
659 bv_->text->selection.cursor = bv_->text->cursor;
660 bv_->text->cursor.x_fix(bv_->text->cursor.x());
662 owner_->updateLayoutChoice();
664 selection_possible = false;
667 // Insert primary selection with middle mouse
668 // if there is a local selection in the current buffer,
671 if (paste_internally)
672 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
674 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
676 selection_possible = false;
682 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
688 LyXText * text = bv_->getLyXText();
690 if (text->bv_owner && bv_->theLockingInset())
693 if (screen_.get() && button == 1) {
694 if (text->bv_owner) {
695 screen_->hideCursor();
696 screen_->toggleSelection(text, bv_);
697 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
698 screen_->toggleSelection(text, bv_, false);
700 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
702 /* This will fit the cursor on the screen
704 update(text, BufferView::SELECT|BufferView::FITCUR);
709 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
715 LyXText * text = bv_->getLyXText();
717 if (text->bv_owner && bv_->theLockingInset())
720 if (screen_.get() && (button == 1)) {
721 if (text->bv_owner) {
722 screen_->hideCursor();
723 screen_->toggleSelection(text, bv_);
725 text->cursorHome(bv_);
726 text->selection.cursor = text->cursor;
727 text->cursorEnd(bv_);
728 text->setSelection(bv_);
729 if (text->bv_owner) {
730 screen_->toggleSelection(text, bv_, false);
732 /* This will fit the cursor on the screen
734 update(text, BufferView::SELECT|BufferView::FITCUR);
739 void BufferView::Pimpl::enterView()
741 if (active() && available()) {
742 SetXtermCursor(workarea_.getWin());
743 using_xterm_cursor = true;
748 void BufferView::Pimpl::leaveView()
750 if (using_xterm_cursor) {
751 XUndefineCursor(fl_get_display(), workarea_.getWin());
752 using_xterm_cursor = false;
757 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
760 if (!buffer_ || !screen_.get()) return;
762 // If we hit an inset, we have the inset coordinates in these
763 // and inset_hit points to the inset. If we do not hit an
764 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
765 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
767 if (bv_->theLockingInset()) {
768 // We are in inset locking mode.
770 /* LyX does a kind of work-area grabbing for insets.
771 Only a ButtonPress Event outside the inset will
772 force a insetUnlock. */
773 bv_->theLockingInset()->
774 insetButtonRelease(bv_, x, y, button);
778 selection_possible = false;
786 // Did we hit an editable inset?
788 // Inset like error, notes and figures
789 selection_possible = false;
791 // if we reach this point with a selection, it
792 // must mean we are currently selecting.
793 // But we don't want to open the inset
794 // because that is annoying for the user.
795 // So just pretend we didn't hit it.
796 // this is OK because a "kosher" ButtonRelease
797 // will follow a ButtonPress that clears
799 // Note this also fixes selection drawing
800 // problems if we end up opening an inset
801 if (bv_->getLyXText()->selection.set())
804 // CHECK fix this proper in 0.13
805 // well, maybe 13.0 !!!!!!!!!
807 // Following a ref shouldn't issue
808 // a push on the undo-stack
809 // anylonger, now that we have
810 // keybindings for following
811 // references and returning from
812 // references. IMHO though, it
813 // should be the inset's own business
814 // to push or not push on the undo
815 // stack. They don't *have* to
816 // alter the document...
818 // ...or maybe the SetCursorParUndo()
819 // below isn't necessary at all anylonger?
820 if (inset_hit->lyxCode() == Inset::REF_CODE) {
821 setCursorParUndo(bv_);
824 owner_->message(inset_hit->editMessage());
826 if (isHighlyEditableInset(inset_hit)) {
827 // Highly editable inset, like math
828 UpdatableInset *inset = (UpdatableInset *)inset_hit;
829 inset->insetButtonRelease(bv_, x, y, button);
831 inset_hit->insetButtonRelease(bv_, x, y, button);
832 inset_hit->edit(bv_, x, y, button);
838 #warning variable c is set but never used. What is it good for?? (JMarc)
839 #warning isnt this code dead ?? "open a float" ??? (jbl)
841 // check whether we want to open a float
845 if (bv_->text->cursor.pos() <
846 bv_->text->cursor.par()->size()) {
847 c = bv_->text->cursor.par()->
848 getChar(bv_->text->cursor.pos());
850 if (bv_->text->cursor.pos() - 1 >= 0) {
851 c = bv_->text->cursor.par()->
852 getChar(bv_->text->cursor.pos() - 1);
855 selection_possible = false;
860 // Maybe we want to edit a bibitem ale970302
861 if (bv_->text->cursor.par()->bibkey && x < 20 +
862 bibitemMaxWidth(bv_, textclasslist.
864 params.textclass).defaultfont())) {
865 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
872 Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
874 Paragraph /*const*/ & par = *cursor.par();
875 pos_type const pos = cursor.pos();
877 lyx::Assert(par.getInset(pos));
879 Inset const & inset(*par.getInset(pos));
881 LyXFont const & font = text.getFont(buffer_, &par, pos);
883 int const width = inset.width(bv_, font);
884 int const inset_x = font.isVisibleRightToLeft()
885 ? (cursor.x() - width) : cursor.x();
888 inset_x + inset.scroll(),
890 cursor.y() - inset.ascent(bv_, font),
891 cursor.y() + inset.descent(bv_, font));
895 Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
897 pos_type const pos(cursor.pos());
898 Paragraph /*const*/ & par(*cursor.par());
900 if (pos >= par.size() || !par.isInset(pos)) {
904 Inset /*const*/ * inset = par.getInset(pos);
906 if (!isEditableInset(inset)) {
910 Box b(insetDimensions(text, cursor));
912 if (!b.contained(x, y)) {
916 text.setCursor(bv_, &par, pos, true);
919 // The origin of an inset is on the baseline
920 y -= (text.cursor.y());
926 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
931 int y_tmp = y + text->first;
934 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
936 Inset * inset(checkInset(*text, cursor, x, y_tmp));
943 // look at previous position
945 if (cursor.pos() == 0) {
950 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
952 inset = checkInset(*text, cursor, x, y_tmp);
960 void BufferView::Pimpl::workAreaExpose()
962 static int work_area_width;
963 static unsigned int work_area_height;
965 bool const widthChange = workarea_.workWidth() != work_area_width;
966 bool const heightChange = workarea_.height() != work_area_height;
968 // update from work area
969 work_area_width = workarea_.workWidth();
970 work_area_height = workarea_.height();
973 // The visible LyXView need a resize
976 // Remove all texts from the textcache
977 // This is not _really_ what we want to do. What
978 // we really want to do is to delete in textcache
979 // that does not have a BufferView with matching
980 // width, but as long as we have only one BufferView
981 // deleting all gives the same result.
982 if (lyxerr.debugging())
983 textcache.show(lyxerr, "Expose delete all");
985 } else if (heightChange) {
986 // Rebuild image of current screen
988 // fitCursor() ensures we don't jump back
989 // to the start of the document on vertical
993 // The main window size has changed, repaint most stuff
995 } else if (screen_.get())
996 screen_->redraw(bv_->text, bv_);
998 // Grey box when we don't have a buffer
1002 // always make sure that the scrollbar is sane.
1004 owner_->updateLayoutChoice();
1009 void BufferView::Pimpl::update()
1011 if (screen_.get() &&
1012 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1014 LyXText::text_status st = bv_->text->status();
1015 screen_->update(bv_->text, bv_);
1017 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1018 if (bv_->text->fullRebreak(bv_)) {
1019 st = LyXText::NEED_MORE_REFRESH;
1020 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1021 bv_->text->cursor.pos());
1024 bv_->text->status(bv_, st);
1025 screen_->update(bv_->text, bv_);
1027 // do this here instead of in the screen::update because of
1029 bv_->text->status(bv_, LyXText::UNCHANGED);
1035 // Values used when calling update:
1037 // -2 - update, move sel_cursor if selection, fitcursor
1038 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1039 // 0 - update, move sel_cursor if selection, fitcursor
1040 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1041 // 3 - update, move sel_cursor if selection
1044 // a simple redraw of the parts that need refresh
1046 // move sel_cursor if selection -
1047 // the text's sel_cursor is moved if there is selection is progress
1050 // fitCursor() is called and the scrollbar updated
1053 // the buffer is marked dirty.
1062 // UPDATE_ONLY = UPDATE;
1063 // UPDATE_SELECT = UPDATE | SELECT;
1064 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1065 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1067 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1068 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1069 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1070 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1071 // update(3) -> update(1) -> update(1) -> update(SELECT)
1073 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1075 owner_->updateLayoutChoice();
1077 if (!text->selection.set() && (f & SELECT)) {
1078 text->selection.cursor = text->cursor;
1081 text->fullRebreak(bv_);
1083 if (text->inset_owner) {
1084 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1085 updateInset(text->inset_owner, false);
1095 buffer_->markDirty();
1100 // Callback for cursor timer
1101 void BufferView::Pimpl::cursorToggle()
1103 // Quite a nice place for asyncron Inset updating, isn't it?
1104 // Actually no! This is run even if no buffer exist... so (Lgb)
1106 cursor_timeout.restart();
1111 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1112 if (pid == -1) // error find out what is wrong
1113 ; // ignore it for now.
1115 sigchldchecker(pid, &status);
1117 updatelist.update(bv_);
1119 if (!screen_.get()) {
1120 cursor_timeout.restart();
1124 if (!bv_->theLockingInset()) {
1125 screen_->cursorToggle(bv_);
1127 bv_->theLockingInset()->toggleInsetCursor(bv_);
1130 cursor_timeout.restart();
1134 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1136 if (!text->cursor.row()->previous())
1139 int y = text->first;
1140 if (text->inset_owner)
1141 y += bv_->text->first;
1142 Row * cursorrow = text->cursor.row();
1143 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1145 // This is to allow jumping over large insets
1146 if ((cursorrow == text->cursor.row()))
1147 text->cursorUp(bv_);
1149 if (text->inset_owner ||
1150 text->cursor.row()->height() < workarea_.height())
1151 screen_->draw(bv_->text, bv_,
1153 - text->cursor.row()->baseline()
1154 + text->cursor.row()->height()
1155 - workarea_.height() + 1 );
1160 void BufferView::Pimpl::cursorNext(LyXText * text)
1162 if (!text->cursor.row()->next())
1165 int y = text->first + workarea_.height();
1166 // if (text->inset_owner)
1167 // y += bv_->text->first;
1168 text->getRowNearY(y);
1170 Row * cursorrow = text->cursor.row();
1171 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1173 // This is to allow jumping over large insets
1174 if ((cursorrow == bv_->text->cursor.row()))
1175 text->cursorDown(bv_);
1177 if (text->inset_owner ||
1178 text->cursor.row()->height() < workarea_.height())
1179 screen_->draw(bv_->text, bv_, text->cursor.y() -
1180 text->cursor.row()->baseline());
1185 bool BufferView::Pimpl::available() const
1187 if (buffer_ && bv_->text) return true;
1192 void BufferView::Pimpl::beforeChange(LyXText * text)
1195 text->clearSelection();
1199 void BufferView::Pimpl::savePosition(unsigned int i)
1201 if (i >= saved_positions_num)
1203 saved_positions[i] = Position(buffer_->fileName(),
1204 bv_->text->cursor.par()->id(),
1205 bv_->text->cursor.pos());
1208 str << _("Saved bookmark") << ' ' << i;
1209 owner_->message(str.str().c_str());
1214 void BufferView::Pimpl::restorePosition(unsigned int i)
1216 if (i >= saved_positions_num)
1219 string const fname = saved_positions[i].filename;
1221 beforeChange(bv_->text);
1223 if (fname != buffer_->fileName()) {
1224 Buffer * b = bufferlist.exists(fname) ?
1225 bufferlist.getBuffer(fname) :
1226 bufferlist.loadLyXFile(fname); // don't ask, just load it
1227 if (b != 0 ) buffer(b);
1230 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1234 bv_->text->setCursor(bv_, par,
1235 min(par->size(), saved_positions[i].par_pos));
1237 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1240 str << _("Moved to bookmark") << ' ' << i;
1241 owner_->message(str.str().c_str());
1246 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1248 if (i >= saved_positions_num)
1251 return !saved_positions[i].filename.empty();
1255 void BufferView::Pimpl::setState()
1257 if (!lyxrc.rtl_support)
1260 LyXText * text = bv_->getLyXText();
1261 if (text->real_current_font.isRightToLeft()) {
1262 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1263 owner_->getIntl()->KeyMapSec();
1265 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1266 owner_->getIntl()->KeyMapPrim();
1271 void BufferView::Pimpl::insetSleep()
1273 if (bv_->theLockingInset() && !inset_slept) {
1274 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1275 bv_->theLockingInset()->insetUnlock(bv_);
1281 void BufferView::Pimpl::insetWakeup()
1283 if (bv_->theLockingInset() && inset_slept) {
1284 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1285 inset_slept = false;
1290 void BufferView::Pimpl::insetUnlock()
1292 if (bv_->theLockingInset()) {
1294 bv_->theLockingInset()->insetUnlock(bv_);
1295 bv_->theLockingInset(0);
1297 inset_slept = false;
1302 bool BufferView::Pimpl::focus() const
1304 return workarea_.hasFocus();
1308 void BufferView::Pimpl::focus(bool f)
1310 if (f) workarea_.setFocus();
1314 bool BufferView::Pimpl::active() const
1316 return workarea_.active();
1320 bool BufferView::Pimpl::belowMouse() const
1322 return workarea_.belowMouse();
1326 void BufferView::Pimpl::showCursor()
1328 if (screen_.get()) {
1329 if (bv_->theLockingInset())
1330 bv_->theLockingInset()->showInsetCursor(bv_);
1332 screen_->showCursor(bv_->text, bv_);
1337 void BufferView::Pimpl::hideCursor()
1339 if (screen_.get()) {
1340 if (!bv_->theLockingInset())
1341 // bv_->theLockingInset()->hideInsetCursor(bv_);
1343 screen_->hideCursor();
1348 void BufferView::Pimpl::toggleSelection(bool b)
1350 if (screen_.get()) {
1351 if (bv_->theLockingInset())
1352 bv_->theLockingInset()->toggleSelection(bv_, b);
1353 screen_->toggleSelection(bv_->text, bv_, b);
1358 void BufferView::Pimpl::toggleToggle()
1361 screen_->toggleToggle(bv_->text, bv_);
1365 void BufferView::Pimpl::center()
1367 beforeChange(bv_->text);
1368 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1369 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1371 screen_->draw(bv_->text, bv_, 0);
1373 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1378 void BufferView::Pimpl::pasteClipboard(bool asPara)
1380 if (!buffer_) return;
1382 screen_->hideCursor();
1383 beforeChange(bv_->text);
1385 string const clip(workarea_.getClipboard());
1387 if (clip.empty()) return;
1390 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1392 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1394 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1398 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1400 workarea_.putClipboard(stuff);
1405 * Dispatch functions for actions which can be valid for BufferView->text
1406 * and/or InsetText->text!!!
1411 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1413 LyXText * lt = bv_->getLyXText();
1415 if (selecting || lt->selection.mark()) {
1416 lt->setSelection(bv_);
1420 update(lt, BufferView::SELECT|BufferView::FITCUR);
1423 /* ---> Everytime the cursor is moved, show the current font state. */
1424 // should this too me moved out of this func?
1425 //owner->showState();
1430 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1432 LyXCursor cursor = bv_->getLyXText()->cursor;
1433 Buffer::inset_iterator it =
1434 find_if(Buffer::inset_iterator(
1435 cursor.par(), cursor.pos()),
1436 buffer_->inset_iterator_end(),
1437 lyx::compare_memfun(&Inset::lyxCode, code));
1438 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1442 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1444 string filename = filen;
1446 if (filename.empty()) {
1447 // Launch a file browser
1448 string initpath = lyxrc.document_path;
1451 string const trypath = owner_->buffer()->filepath;
1452 // If directory is writeable, use this as default.
1453 if (IsDirWriteable(trypath))
1457 FileDialog fileDlg(bv_->owner(),
1458 _("Select LyX document to insert"),
1460 make_pair(string(_("Documents")),
1461 string(lyxrc.document_path)),
1462 make_pair(string(_("Examples")),
1463 string(AddPath(system_lyxdir, "examples"))));
1465 FileDialog::Result result =
1466 fileDlg.Select(initpath,
1467 _("*.lyx| LyX Documents (*.lyx)"));
1469 if (result.first == FileDialog::Later)
1472 filename = result.second;
1474 // check selected filename
1475 if (filename.empty()) {
1476 owner_->message(_("Canceled."));
1481 // get absolute path of file and add ".lyx" to the filename if
1483 filename = FileSearch(string(), filename, "lyx");
1485 string const disp_fn(MakeDisplayPath(filename));
1488 s1 << _("Inserting document") << ' '
1489 << disp_fn << " ...";
1490 owner_->message(s1.str().c_str());
1491 bool const res = bv_->insertLyXFile(filename);
1494 str << _("Document") << ' ' << disp_fn
1495 << ' ' << _("inserted.");
1496 owner_->message(str.str().c_str());
1499 str << _("Could not insert document") << ' '
1501 owner_->message(str.str().c_str());
1506 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1508 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1509 << action <<"] arg[" << argument << "]" << endl;
1512 // --- Misc -------------------------------------------
1516 LyXText * lt = bv_->getLyXText();
1517 lt->toggleAppendix(bv_);
1520 | BufferView::FITCUR
1521 | BufferView::CHANGE);
1526 case LFUN_TOC_INSERT:
1528 InsetCommandParams p;
1529 p.setCmdName("tableofcontents");
1530 Inset * inset = new InsetTOC(p);
1531 if (!insertInset(inset, "Standard"))
1536 case LFUN_TABULAR_FEATURE:
1537 case LFUN_SCROLL_INSET:
1538 // this is not handled here as this funktion is only aktive
1539 // if we have a locking_inset and that one is (or contains)
1543 case LFUN_INSET_GRAPHICS:
1545 Inset * new_inset = new InsetGraphics;
1546 if (!insertInset(new_inset)) {
1549 // this is need because you don't use a inset->Edit()
1550 updateInset(new_inset, true);
1551 new_inset->edit(bv_);
1561 case LFUN_PASTESELECTION:
1563 bool asPara = false;
1564 if (argument == "paragraph")
1566 pasteClipboard(asPara);
1578 case LFUN_LAYOUT_COPY:
1579 bv_->copyEnvironment();
1582 case LFUN_LAYOUT_PASTE:
1583 bv_->pasteEnvironment();
1587 case LFUN_GOTOERROR:
1588 gotoInset(Inset::ERROR_CODE, false);
1592 gotoInset(Inset::IGNORE_CODE, false);
1595 case LFUN_REFERENCE_GOTO:
1597 vector<Inset::Code> tmp;
1598 tmp.push_back(Inset::LABEL_CODE);
1599 tmp.push_back(Inset::REF_CODE);
1600 gotoInset(tmp, true);
1604 case LFUN_HYPHENATION:
1605 specialChar(InsetSpecialChar::HYPHENATION);
1608 case LFUN_LIGATURE_BREAK:
1609 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1613 specialChar(InsetSpecialChar::LDOTS);
1616 case LFUN_END_OF_SENTENCE:
1617 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1620 case LFUN_MENU_SEPARATOR:
1621 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1629 changeDepth(bv_, bv_->getLyXText(), 0);
1632 case LFUN_DEPTH_MIN:
1633 changeDepth(bv_, bv_->getLyXText(), -1);
1636 case LFUN_DEPTH_PLUS:
1637 changeDepth(bv_, bv_->getLyXText(), 1);
1641 owner_->getDialogs()->setUserFreeFont();
1644 case LFUN_FILE_INSERT:
1645 MenuInsertLyXFile(argument);
1648 case LFUN_FILE_INSERT_ASCII_PARA:
1649 InsertAsciiFile(bv_, argument, true);
1652 case LFUN_FILE_INSERT_ASCII:
1653 InsertAsciiFile(bv_, argument, false);
1658 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1659 << argument << endl;
1661 // Derive layout number from given argument (string)
1662 // and current buffer's textclass (number). */
1663 textclass_type tclass = buffer_->params.textclass;
1664 pair <bool, layout_type> layout =
1665 textclasslist.NumberOfLayout(tclass, argument);
1667 // If the entry is obsolete, use the new one instead.
1669 string obs = textclasslist.Style(tclass, layout.second)
1672 layout = textclasslist.NumberOfLayout(tclass, obs);
1675 // see if we found the layout number:
1676 if (!layout.first) {
1677 owner_->getLyXFunc()->setErrorMessage(
1678 string(N_("Layout ")) + argument +
1683 if (current_layout != layout.second) {
1684 LyXText * lt = bv_->getLyXText();
1686 current_layout = layout.second;
1689 | BufferView::FITCUR);
1690 lt->setLayout(bv_, layout.second);
1691 owner_->setLayout(layout.second);
1694 | BufferView::FITCUR
1695 | BufferView::CHANGE);
1702 lang(bv_, argument);
1704 owner_->showState();
1709 owner_->showState();
1714 owner_->showState();
1719 owner_->showState();
1724 owner_->showState();
1729 owner_->showState();
1734 owner_->showState();
1739 owner_->showState();
1742 case LFUN_UNDERLINE:
1744 owner_->showState();
1747 case LFUN_FONT_SIZE:
1748 fontSize(bv_, argument);
1749 owner_->showState();
1752 case LFUN_FONT_STATE:
1753 owner_->getLyXFunc()->setMessage(currentState(bv_));
1756 case LFUN_UPCASE_WORD:
1758 LyXText * lt = bv_->getLyXText();
1762 | BufferView::FITCUR);
1763 lt->changeCase(bv_, LyXText::text_uppercase);
1764 if (lt->inset_owner)
1765 updateInset(lt->inset_owner, true);
1768 | BufferView::FITCUR
1769 | BufferView::CHANGE);
1773 case LFUN_LOWCASE_WORD:
1775 LyXText * lt = bv_->getLyXText();
1777 update(lt, BufferView::SELECT|BufferView::FITCUR);
1778 lt->changeCase(bv_, LyXText::text_lowercase);
1779 if (lt->inset_owner)
1780 updateInset(lt->inset_owner, true);
1783 | BufferView::FITCUR
1784 | BufferView::CHANGE);
1788 case LFUN_CAPITALIZE_WORD:
1790 LyXText * lt = bv_->getLyXText();
1792 update(lt, BufferView::SELECT|BufferView::FITCUR);
1793 lt->changeCase(bv_, LyXText::text_capitalization);
1794 if (lt->inset_owner)
1795 updateInset(lt->inset_owner, true);
1798 | BufferView::FITCUR
1799 | BufferView::CHANGE);
1803 case LFUN_TRANSPOSE_CHARS:
1805 LyXText * lt = bv_->getLyXText();
1807 update(lt, BufferView::SELECT|BufferView::FITCUR);
1808 lt->transposeChars(*bv_);
1809 if (lt->inset_owner)
1810 updateInset(lt->inset_owner, true);
1813 | BufferView::FITCUR
1814 | BufferView::CHANGE);
1819 case LFUN_INSERT_LABEL:
1820 MenuInsertLabel(bv_, argument);
1823 case LFUN_REF_INSERT:
1824 if (argument.empty()) {
1825 InsetCommandParams p("ref");
1826 owner_->getDialogs()->createRef(p.getAsString());
1828 InsetCommandParams p;
1829 p.setFromString(argument);
1831 InsetRef * inset = new InsetRef(p, *buffer_);
1832 if (!insertInset(inset))
1835 updateInset(inset, true);
1839 case LFUN_BOOKMARK_SAVE:
1840 savePosition(strToUnsignedInt(argument));
1843 case LFUN_BOOKMARK_GOTO:
1844 restorePosition(strToUnsignedInt(argument));
1849 string label(argument);
1850 if (label.empty()) {
1852 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1854 label = inset->getContents();
1859 if (!label.empty()) {
1860 //bv_->savePosition(0);
1861 if (!bv_->gotoLabel(label))
1862 Alert::alert(_("Error"),
1863 _("Couldn't find this label"),
1864 _("in current document."));
1869 // --- Cursor Movements -----------------------------
1872 LyXText * lt = bv_->getLyXText();
1874 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1875 if (!lt->selection.mark())
1877 update(lt, BufferView::SELECT|BufferView::FITCUR);
1879 lt->cursorLeft(bv_, false);
1880 if (lt->cursor.pos() < lt->cursor.par()->size()
1881 && lt->cursor.par()->isInset(lt->cursor.pos())
1882 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1883 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1884 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1886 tmpinset->edit(bv_, false);
1888 tmpinset->edit(bv_);
1892 lt->cursorRight(bv_, false);
1894 moveCursorUpdate(false);
1895 owner_->showState();
1901 // This is soooo ugly. Isn`t it possible to make
1902 // it simpler? (Lgb)
1903 LyXText * lt = bv_->getLyXText();
1904 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1905 if (!lt->selection.mark())
1907 update(lt, BufferView::SELECT|BufferView::FITCUR);
1908 LyXCursor const cur = lt->cursor;
1910 lt->cursorLeft(bv_, false);
1911 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1912 lt->cursor.pos() < lt->cursor.par()->size() &&
1913 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1914 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1915 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1916 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1918 tmpinset->edit(bv_);
1920 tmpinset->edit(bv_, false);
1924 lt->cursorRight(bv_, false);
1927 moveCursorUpdate(false);
1928 owner_->showState();
1934 LyXText * lt = bv_->getLyXText();
1936 if (!lt->selection.mark())
1938 update(lt, BufferView::UPDATE);
1941 moveCursorUpdate(false);
1942 owner_->showState();
1948 LyXText * lt = bv_->getLyXText();
1950 if (!lt->selection.mark())
1952 update(lt, BufferView::UPDATE);
1953 lt->cursorDown(bv_);
1955 moveCursorUpdate(false);
1956 owner_->showState();
1960 case LFUN_UP_PARAGRAPH:
1962 LyXText * lt = bv_->getLyXText();
1964 if (!lt->selection.mark())
1966 update(lt, BufferView::UPDATE);
1967 lt->cursorUpParagraph(bv_);
1969 moveCursorUpdate(false);
1970 owner_->showState();
1974 case LFUN_DOWN_PARAGRAPH:
1976 LyXText * lt = bv_->getLyXText();
1978 if (!lt->selection.mark())
1980 update(lt, BufferView::UPDATE);
1981 lt->cursorDownParagraph(bv_);
1983 moveCursorUpdate(false);
1984 owner_->showState();
1990 LyXText * lt = bv_->getLyXText();
1992 if (!lt->selection.mark())
1994 update(lt, BufferView::UPDATE);
1997 moveCursorUpdate(false);
1998 owner_->showState();
2004 LyXText * lt = bv_->getLyXText();
2006 if (!lt->selection.mark())
2008 update(lt, BufferView::UPDATE);
2011 moveCursorUpdate(false);
2012 owner_->showState();
2018 LyXText * lt = bv_->getLyXText();
2020 if (!lt->selection.mark())
2022 update(lt, BufferView::SELECT|BufferView::FITCUR);
2023 lt->cursorHome(bv_);
2025 moveCursorUpdate(false);
2026 owner_->showState();
2032 LyXText * lt = bv_->getLyXText();
2034 if (!lt->selection.mark())
2037 BufferView::SELECT|BufferView::FITCUR);
2040 moveCursorUpdate(false);
2041 owner_->showState();
2045 case LFUN_SHIFT_TAB:
2048 LyXText * lt = bv_->getLyXText();
2050 if (!lt->selection.mark())
2053 BufferView::SELECT|BufferView::FITCUR);
2056 moveCursorUpdate(false);
2057 owner_->showState();
2061 case LFUN_WORDRIGHT:
2063 LyXText * lt = bv_->getLyXText();
2065 if (!lt->selection.mark())
2067 update(lt, BufferView::SELECT|BufferView::FITCUR);
2068 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2069 lt->cursorLeftOneWord(bv_);
2071 lt->cursorRightOneWord(bv_);
2073 moveCursorUpdate(false);
2074 owner_->showState();
2080 LyXText * lt = bv_->getLyXText();
2082 if (!lt->selection.mark())
2084 update(lt, BufferView::SELECT|BufferView::FITCUR);
2085 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2086 lt->cursorRightOneWord(bv_);
2088 lt->cursorLeftOneWord(bv_);
2090 moveCursorUpdate(false);
2091 owner_->showState();
2095 case LFUN_BEGINNINGBUF:
2097 LyXText * lt = bv_->getLyXText();
2099 if (!lt->selection.mark())
2102 BufferView::SELECT|BufferView::FITCUR);
2105 moveCursorUpdate(false);
2106 owner_->showState();
2112 LyXText * lt = bv_->getLyXText();
2114 if (!lt->selection.mark())
2117 BufferView::SELECT|BufferView::FITCUR);
2118 lt->cursorBottom(bv_);
2120 moveCursorUpdate(false);
2121 owner_->showState();
2125 /* cursor selection ---------------------------- */
2128 LyXText * lt = bv_->getLyXText();
2131 BufferView::SELECT|BufferView::FITCUR);
2132 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2133 lt->cursorLeft(bv_);
2135 lt->cursorRight(bv_);
2137 moveCursorUpdate(true);
2138 owner_->showState();
2144 LyXText * lt = bv_->getLyXText();
2147 BufferView::SELECT|BufferView::FITCUR);
2148 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2149 lt->cursorRight(bv_);
2151 lt->cursorLeft(bv_);
2153 moveCursorUpdate(true);
2154 owner_->showState();
2160 LyXText * lt = bv_->getLyXText();
2163 BufferView::SELECT|BufferView::FITCUR);
2166 moveCursorUpdate(true);
2167 owner_->showState();
2173 LyXText * lt = bv_->getLyXText();
2176 BufferView::SELECT|BufferView::FITCUR);
2177 lt->cursorDown(bv_);
2179 moveCursorUpdate(true);
2180 owner_->showState();
2184 case LFUN_UP_PARAGRAPHSEL:
2186 LyXText * lt = bv_->getLyXText();
2189 BufferView::SELECT|BufferView::FITCUR);
2190 lt->cursorUpParagraph(bv_);
2192 moveCursorUpdate(true);
2193 owner_->showState();
2197 case LFUN_DOWN_PARAGRAPHSEL:
2199 LyXText * lt = bv_->getLyXText();
2202 BufferView::SELECT|BufferView::FITCUR);
2203 lt->cursorDownParagraph(bv_);
2205 moveCursorUpdate(true);
2206 owner_->showState();
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 moveCursorUpdate(true);
2218 owner_->showState();
2224 LyXText * lt = bv_->getLyXText();
2226 update(lt, BufferView::SELECT|BufferView::FITCUR);
2229 moveCursorUpdate(true);
2230 owner_->showState();
2236 LyXText * lt = bv_->getLyXText();
2238 update(lt, BufferView::SELECT|BufferView::FITCUR);
2239 lt->cursorHome(bv_);
2241 moveCursorUpdate(true);
2242 owner_->showState();
2248 LyXText * lt = bv_->getLyXText();
2250 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 moveCursorUpdate(true);
2254 owner_->showState();
2258 case LFUN_WORDRIGHTSEL:
2260 LyXText * lt = bv_->getLyXText();
2262 update(lt, BufferView::SELECT|BufferView::FITCUR);
2263 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2264 lt->cursorLeftOneWord(bv_);
2266 lt->cursorRightOneWord(bv_);
2268 moveCursorUpdate(true);
2269 owner_->showState();
2273 case LFUN_WORDLEFTSEL:
2275 LyXText * lt = bv_->getLyXText();
2277 update(lt, BufferView::SELECT|BufferView::FITCUR);
2278 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2279 lt->cursorRightOneWord(bv_);
2281 lt->cursorLeftOneWord(bv_);
2283 moveCursorUpdate(true);
2284 owner_->showState();
2288 case LFUN_BEGINNINGBUFSEL:
2290 LyXText * lt = bv_->getLyXText();
2292 if (lt->inset_owner)
2294 update(lt, BufferView::SELECT|BufferView::FITCUR);
2297 moveCursorUpdate(true);
2298 owner_->showState();
2302 case LFUN_ENDBUFSEL:
2304 LyXText * lt = bv_->getLyXText();
2306 if (lt->inset_owner)
2309 BufferView::SELECT|BufferView::FITCUR);
2310 lt->cursorBottom(bv_);
2312 moveCursorUpdate(true);
2313 owner_->showState();
2317 // --- text changing commands ------------------------
2318 case LFUN_BREAKLINE:
2320 LyXText * lt = bv_->getLyXText();
2323 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2326 | BufferView::FITCUR
2327 | BufferView::CHANGE);
2328 moveCursorUpdate(false);
2332 case LFUN_PROTECTEDSPACE:
2334 LyXText * lt = bv_->getLyXText();
2336 LyXLayout const & style = textclasslist
2337 .Style(buffer_->params.textclass,
2338 lt->cursor.par()->getLayout());
2340 if (style.free_spacing) {
2341 lt->insertChar(bv_, ' ');
2344 | BufferView::FITCUR
2345 | BufferView::CHANGE);
2349 moveCursorUpdate(false);
2355 LyXText * lt = bv_->getLyXText();
2357 if (lt->selection.mark()) {
2361 | BufferView::FITCUR);
2362 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2365 lt->selection.mark(true);
2368 | BufferView::FITCUR);
2369 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2371 lt->selection.cursor = lt->cursor;
2377 LyXText * lt = bv_->getLyXText();
2379 if (!lt->selection.set()) {
2381 lt->selection.cursor = lt->cursor;
2384 | BufferView::FITCUR
2385 | BufferView::CHANGE);
2386 // It is possible to make it a lot faster still
2387 // just comment out the line below...
2392 moveCursorUpdate(false);
2393 owner_->showState();
2398 case LFUN_DELETE_SKIP:
2400 LyXText * lt = bv_->getLyXText();
2402 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2404 LyXCursor cursor = lt->cursor;
2406 if (!lt->selection.set()) {
2407 if (cursor.pos() == cursor.par()->size()) {
2408 lt->cursorRight(bv_);
2409 cursor = lt->cursor;
2410 if (cursor.pos() == 0
2411 && !(cursor.par()->params().spaceTop()
2412 == VSpace (VSpace::NONE))) {
2415 cursor.par()->params().lineTop(),
2416 cursor.par()->params().lineBottom(),
2417 cursor.par()->params().pagebreakTop(),
2418 cursor.par()->params().pagebreakBottom(),
2419 VSpace(VSpace::NONE),
2420 cursor.par()->params().spaceBottom(),
2421 cursor.par()->params().spacing(),
2422 cursor.par()->params().align(),
2423 cursor.par()->params().labelWidthString(), 0);
2424 lt->cursorLeft(bv_);
2427 | BufferView::FITCUR
2428 | BufferView::CHANGE);
2430 lt->cursorLeft(bv_);
2432 lt->selection.cursor = lt->cursor;
2435 | BufferView::FITCUR
2436 | BufferView::CHANGE);
2440 lt->selection.cursor = lt->cursor;
2443 | BufferView::FITCUR
2444 | BufferView::CHANGE);
2452 /* -------> Delete word forward. */
2453 case LFUN_DELETE_WORD_FORWARD:
2454 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2455 bv_->getLyXText()->deleteWordForward(bv_);
2456 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2457 moveCursorUpdate(false);
2458 owner_->showState();
2461 /* -------> Delete word backward. */
2462 case LFUN_DELETE_WORD_BACKWARD:
2464 LyXText * lt = bv_->getLyXText();
2466 update(lt, BufferView::SELECT|BufferView::FITCUR);
2467 lt->deleteWordBackward(bv_);
2470 | BufferView::FITCUR
2471 | BufferView::CHANGE);
2472 moveCursorUpdate(false);
2473 owner_->showState();
2477 /* -------> Kill to end of line. */
2478 case LFUN_DELETE_LINE_FORWARD:
2480 LyXText * lt = bv_->getLyXText();
2482 update(lt, BufferView::SELECT|BufferView::FITCUR);
2483 lt->deleteLineForward(bv_);
2486 | BufferView::FITCUR
2487 | BufferView::CHANGE);
2488 moveCursorUpdate(false);
2492 /* -------> Set mark off. */
2495 LyXText * lt = bv_->getLyXText();
2498 update(lt, BufferView::SELECT|BufferView::FITCUR);
2499 lt->selection.cursor = lt->cursor;
2500 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2504 /* -------> Set mark on. */
2507 LyXText * lt = bv_->getLyXText();
2510 lt->selection.mark(true);
2511 update(lt, BufferView::SELECT|BufferView::FITCUR);
2512 lt->selection.cursor = lt->cursor;
2513 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2517 case LFUN_BACKSPACE:
2519 LyXText * lt = bv_->getLyXText();
2521 if (!lt->selection.set()) {
2522 if (owner_->getIntl()->getTrans().backspace()) {
2524 lt->selection.cursor = lt->cursor;
2527 | BufferView::FITCUR
2528 | BufferView::CHANGE);
2529 // It is possible to make it a lot faster still
2530 // just comment out the line below...
2536 owner_->showState();
2541 case LFUN_BACKSPACE_SKIP:
2543 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2544 LyXText * lt = bv_->getLyXText();
2546 LyXCursor cursor = lt->cursor;
2548 if (!lt->selection.set()) {
2549 if (cursor.pos() == 0
2550 && !(cursor.par()->params().spaceTop()
2551 == VSpace (VSpace::NONE))) {
2554 cursor.par()->params().lineTop(),
2555 cursor.par()->params().lineBottom(),
2556 cursor.par()->params().pagebreakTop(),
2557 cursor.par()->params().pagebreakBottom(),
2558 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2559 cursor.par()->params().spacing(),
2560 cursor.par()->params().align(),
2561 cursor.par()->params().labelWidthString(), 0);
2564 | BufferView::FITCUR
2565 | BufferView::CHANGE);
2568 lt->selection.cursor = cursor;
2571 | BufferView::FITCUR
2572 | BufferView::CHANGE);
2579 case LFUN_BREAKPARAGRAPH:
2581 LyXText * lt = bv_->getLyXText();
2584 lt->breakParagraph(bv_, 0);
2587 | BufferView::FITCUR
2588 | BufferView::CHANGE);
2589 lt->selection.cursor = lt->cursor;
2591 owner_->showState();
2595 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2597 LyXText * lt = bv_->getLyXText();
2600 lt->breakParagraph(bv_, 1);
2603 | BufferView::FITCUR
2604 | BufferView::CHANGE);
2605 lt->selection.cursor = lt->cursor;
2607 owner_->showState();
2611 case LFUN_BREAKPARAGRAPH_SKIP:
2613 // When at the beginning of a paragraph, remove
2614 // indentation and add a "defskip" at the top.
2615 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2616 LyXText * lt = bv_->getLyXText();
2618 LyXCursor cursor = lt->cursor;
2621 if (cursor.pos() == 0) {
2622 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2625 cursor.par()->params().lineTop(),
2626 cursor.par()->params().lineBottom(),
2627 cursor.par()->params().pagebreakTop(),
2628 cursor.par()->params().pagebreakBottom(),
2629 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2630 cursor.par()->params().spacing(),
2631 cursor.par()->params().align(),
2632 cursor.par()->params().labelWidthString(), 1);
2633 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2637 lt->breakParagraph(bv_, 0);
2638 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2643 | BufferView::FITCUR
2644 | BufferView::CHANGE);
2645 lt->selection.cursor = cursor;
2647 owner_->showState();
2651 case LFUN_PARAGRAPH_SPACING:
2653 LyXText * lt = bv_->getLyXText();
2655 Paragraph * par = lt->cursor.par();
2656 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2657 float cur_value = 1.0;
2658 if (cur_spacing == Spacing::Other) {
2659 cur_value = par->params().spacing().getValue();
2662 istringstream istr(argument.c_str());
2666 Spacing::Space new_spacing = cur_spacing;
2667 float new_value = cur_value;
2669 lyxerr << "Missing argument to `paragraph-spacing'"
2671 } else if (tmp == "single") {
2672 new_spacing = Spacing::Single;
2673 } else if (tmp == "onehalf") {
2674 new_spacing = Spacing::Onehalf;
2675 } else if (tmp == "double") {
2676 new_spacing = Spacing::Double;
2677 } else if (tmp == "other") {
2678 new_spacing = Spacing::Other;
2681 lyxerr << "new_value = " << tmpval << endl;
2684 } else if (tmp == "default") {
2685 new_spacing = Spacing::Default;
2687 lyxerr << _("Unknown spacing argument: ")
2688 << argument << endl;
2690 if (cur_spacing != new_spacing || cur_value != new_value) {
2691 par->params().spacing(Spacing(new_spacing, new_value));
2692 lt->redoParagraph(bv_);
2695 | BufferView::FITCUR
2696 | BufferView::CHANGE);
2701 case LFUN_INSET_TOGGLE:
2703 LyXText * lt = bv_->getLyXText();
2706 update(lt, BufferView::SELECT|BufferView::FITCUR);
2707 lt->toggleInset(bv_);
2708 update(lt, BufferView::SELECT|BufferView::FITCUR);
2720 InsetCommandParams p;
2721 if (action == LFUN_HTMLURL)
2722 p.setCmdName("htmlurl");
2724 p.setCmdName("url");
2725 owner_->getDialogs()->createUrl(p.getAsString());
2729 case LFUN_INSERT_URL:
2731 InsetCommandParams p;
2732 p.setFromString(argument);
2734 InsetUrl * inset = new InsetUrl(p);
2735 if (!insertInset(inset))
2738 updateInset(inset, true);
2742 case LFUN_INSET_TEXT:
2743 insertAndEditInset(new InsetText);
2746 case LFUN_INSET_ERT:
2747 insertAndEditInset(new InsetERT);
2750 case LFUN_INSET_EXTERNAL:
2751 insertAndEditInset(new InsetExternal);
2754 case LFUN_INSET_FOOTNOTE:
2755 insertAndEditInset(new InsetFoot);
2758 case LFUN_INSET_MARGINAL:
2759 insertAndEditInset(new InsetMarginal);
2762 case LFUN_INSET_MINIPAGE:
2763 insertAndEditInset(new InsetMinipage);
2766 case LFUN_INSERT_NOTE:
2767 insertAndEditInset(new InsetNote);
2770 case LFUN_INSET_FLOAT:
2771 // check if the float type exist
2772 if (floatList.typeExist(argument)) {
2773 insertAndEditInset(new InsetFloat(argument));
2775 lyxerr << "Non-existent float type: "
2776 << argument << endl;
2780 case LFUN_INSET_WIDE_FLOAT:
2782 // check if the float type exist
2783 if (floatList.typeExist(argument)) {
2784 InsetFloat * new_inset = new InsetFloat(argument);
2785 new_inset->wide(true);
2786 if (insertInset(new_inset))
2787 new_inset->edit(bv_);
2791 lyxerr << "Non-existent float type: "
2792 << argument << endl;
2799 case LFUN_INSET_LIST:
2800 insertAndEditInset(new InsetList);
2803 case LFUN_INSET_THEOREM:
2804 insertAndEditInset(new InsetTheorem);
2808 case LFUN_INSET_CAPTION:
2810 // Do we have a locking inset...
2811 if (bv_->theLockingInset()) {
2812 lyxerr << "Locking inset code: "
2813 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2814 InsetCaption * new_inset = new InsetCaption;
2815 new_inset->setOwner(bv_->theLockingInset());
2816 new_inset->setAutoBreakRows(true);
2817 new_inset->setDrawFrame(0, InsetText::LOCKED);
2818 new_inset->setFrameColor(0, LColor::captionframe);
2819 if (insertInset(new_inset))
2820 new_inset->edit(bv_);
2827 case LFUN_INSET_TABULAR:
2831 if (!argument.empty())
2832 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2833 InsetTabular * new_inset =
2834 new InsetTabular(*buffer_, r, c);
2836 bv_->getLyXText()->real_current_font.isRightToLeft();
2837 if (!open_new_inset(new_inset, rtl))
2842 // --- lyxserver commands ----------------------------
2844 case LFUN_CHARATCURSOR:
2846 pos_type pos = bv_->getLyXText()->cursor.pos();
2847 if (pos < bv_->getLyXText()->cursor.par()->size())
2848 owner_->getLyXFunc()->setMessage(
2849 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2851 owner_->getLyXFunc()->setMessage("EOF");
2856 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2858 + tostr(bv_->getLyXText()->cursor.y()));
2865 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2866 lyxerr << "SETXY: Could not parse coordinates in '"
2867 << argument << std::endl;
2869 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2873 case LFUN_GETLAYOUT:
2874 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2879 LyXFont & font = bv_->getLyXText()->current_font;
2880 if (font.shape() == LyXFont::ITALIC_SHAPE)
2881 owner_->getLyXFunc()->setMessage("E");
2882 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2883 owner_->getLyXFunc()->setMessage("N");
2885 owner_->getLyXFunc()->setMessage("0");
2890 // --- accented characters ---------------------------
2893 case LFUN_CIRCUMFLEX:
2903 case LFUN_SPECIAL_CARON:
2906 case LFUN_HUNG_UMLAUT:
2909 if (argument.empty()) {
2911 owner_->getLyXFunc()->handleKeyFunc(action);
2913 owner_->getLyXFunc()->handleKeyFunc(action);
2914 owner_->getIntl()->getTrans()
2915 .TranslateAndInsert(argument[0], bv_->getLyXText());
2916 update(bv_->getLyXText(),
2918 | BufferView::FITCUR
2919 | BufferView::CHANGE);
2923 case LFUN_MATH_MACRO:
2924 mathDispatchMathMacro(bv_, argument);
2927 case LFUN_MATH_DELIM:
2928 mathDispatchMathDelim(bv_, argument);
2931 case LFUN_INSERT_MATRIX:
2932 mathDispatchInsertMatrix(bv_, argument);
2935 case LFUN_INSERT_MATH:
2936 mathDispatchInsertMath(bv_, argument);
2939 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2940 mathDispatchMathImportSelection(bv_, argument);
2943 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2944 mathDispatchMathDisplay(bv_, argument);
2947 case LFUN_MATH_MODE: // Open or create an inlined math inset
2948 mathDispatchMathMode(bv_, argument);
2951 case LFUN_GREEK: // Insert a single greek letter
2952 mathDispatchGreek(bv_, argument);
2955 case LFUN_CITATION_INSERT:
2957 InsetCommandParams p;
2958 p.setFromString( argument );
2960 InsetCitation * inset = new InsetCitation( p );
2961 if (!insertInset(inset))
2964 updateInset( inset, true );
2968 case LFUN_INSERT_BIBTEX:
2970 // ale970405+lasgoutt970425
2971 // The argument can be up to two tokens separated
2972 // by a space. The first one is the bibstyle.
2973 string const db = token(argument, ' ', 0);
2974 string const bibstyle = token(argument, ' ', 1);
2976 InsetCommandParams p( "BibTeX", db, bibstyle );
2977 InsetBibtex * inset = new InsetBibtex(p);
2979 if (insertInset(inset)) {
2980 if (argument.empty())
2987 // BibTeX data bases
2988 case LFUN_BIBDB_ADD:
2990 InsetBibtex * inset =
2991 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2993 inset->addDatabase(argument);
2998 case LFUN_BIBDB_DEL:
3000 InsetBibtex * inset =
3001 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3003 inset->delDatabase(argument);
3008 case LFUN_BIBTEX_STYLE:
3010 InsetBibtex * inset =
3011 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3013 inset->setOptions(argument);
3018 case LFUN_INDEX_CREATE:
3020 InsetCommandParams p("index");
3021 if (argument.empty()) {
3022 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3023 p.setContents(idxstring);
3025 p.setContents(argument);
3028 owner_->getDialogs()->createIndex(p.getAsString());
3032 case LFUN_INDEX_INSERT:
3034 InsetCommandParams p;
3035 p.setFromString(argument);
3036 InsetIndex * inset = new InsetIndex(p);
3038 if (!insertInset(inset))
3041 updateInset(inset, true);
3045 case LFUN_INDEX_INSERT_LAST:
3047 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3048 if (!idxstring.empty()) {
3049 owner_->message(_("Word `")
3050 + idxstring + _(("' indexed.")));
3051 InsetCommandParams p("index", idxstring);
3052 InsetIndex * inset = new InsetIndex(p);
3054 if (!insertInset(inset))
3057 updateInset(inset, true);
3062 case LFUN_INDEX_PRINT:
3064 InsetCommandParams p("printindex");
3065 Inset * inset = new InsetPrintIndex(p);
3066 if (!insertInset(inset, "Standard"))
3071 case LFUN_PARENTINSERT:
3073 lyxerr << "arg " << argument << endl;
3074 InsetCommandParams p( "lyxparent", argument );
3075 Inset * inset = new InsetParent(p, *buffer_);
3076 if (!insertInset(inset, "Standard"))
3082 case LFUN_CHILD_INSERT:
3084 InsetInclude::Params p;
3085 p.cparams.setFromString(argument);
3086 p.masterFilename_ = buffer_->fileName();
3088 InsetInclude * inset = new InsetInclude(p);
3089 if (!insertInset(inset))
3092 updateInset(inset, true);
3093 bv_->owner()->getDialogs()->showInclude(inset);
3098 case LFUN_FLOAT_LIST:
3100 // We should check the argument for validity. (Lgb)
3101 Inset * inset = new InsetFloatList(argument);
3102 if (!insertInset(inset, "Standard"))
3107 case LFUN_THESAURUS_ENTRY:
3109 string arg = argument;
3112 arg = bv_->getLyXText()->selectionAsString(buffer_,
3116 if (arg.size() > 100 || arg.empty()) {
3117 // Get word or selection
3118 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3119 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3120 // FIXME: where is getLyXText()->unselect(bv_) ?
3124 bv_->owner()->getDialogs()->showThesaurus(arg);
3128 case LFUN_SELFINSERT:
3130 if (argument.empty()) break;
3132 /* Automatically delete the currently selected
3133 * text and replace it with what is being
3134 * typed in now. Depends on lyxrc settings
3135 * "auto_region_delete", which defaults to
3138 LyXText * lt = bv_->getLyXText();
3140 if (lyxrc.auto_region_delete) {
3141 if (lt->selection.set()) {
3142 lt->cutSelection(bv_, false, false);
3145 | BufferView::FITCUR
3146 | BufferView::CHANGE);
3151 LyXFont const old_font(lt->real_current_font);
3153 string::const_iterator cit = argument.begin();
3154 string::const_iterator end = argument.end();
3155 for (; cit != end; ++cit) {
3156 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3161 | BufferView::FITCUR
3162 | BufferView::CHANGE);
3164 lt->selection.cursor = lt->cursor;
3165 moveCursorUpdate(false);
3167 // real_current_font.number can change so we need to
3168 // update the minibuffer
3169 if (old_font != lt->real_current_font)
3170 owner_->showState();
3175 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3177 time_t now_time_t = time(NULL);
3178 struct tm * now_tm = localtime(&now_time_t);
3179 setlocale(LC_TIME, "");
3181 if (!argument.empty())
3184 arg = lyxrc.date_insert_format;
3186 int const datetmp_len =
3187 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3189 LyXText * lt = bv_->getLyXText();
3191 for (int i = 0; i < datetmp_len; i++) {
3192 lt->insertChar(bv_, datetmp[i]);
3195 | BufferView::FITCUR
3196 | BufferView::CHANGE);
3199 lt->selection.cursor = lt->cursor;
3200 moveCursorUpdate(false);
3204 case LFUN_UNKNOWN_ACTION:
3205 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3216 void BufferView::Pimpl::newline()
3219 LyXText * lt = bv_->getLyXText();
3223 | BufferView::FITCUR);
3224 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3227 | BufferView::FITCUR
3228 | BufferView::CHANGE);
3233 void BufferView::Pimpl::hfill()
3236 LyXText * lt = bv_->getLyXText();
3240 | BufferView::FITCUR);
3241 lt->insertChar(bv_, Paragraph::META_HFILL);
3244 | BufferView::FITCUR
3245 | BufferView::CHANGE);
3250 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3254 update(lt, BufferView::SELECT|BufferView::FITCUR);
3255 InsetSpecialChar * new_inset =
3256 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3257 #ifdef WITH_WARNINGS
3258 #warning Why is this code different from specialChar() below? (JMarc)
3259 // the code in specialChar is a generic version of what used to exist
3260 // for other special chars. I did not merge this case because of the
3261 // call to updateInset(), but what does it do?
3263 if (!insertInset(new_inset))
3266 updateInset(new_inset, true);
3271 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3274 LyXText * lt = bv_->getLyXText();
3277 update(lt, BufferView::SELECT|BufferView::FITCUR);
3278 InsetSpecialChar * new_inset =
3279 new InsetSpecialChar(kind);
3280 insertInset(new_inset);
3281 // Ok, what happens here if we are unable to insert
3282 // the inset? Leak it?
3287 void BufferView::Pimpl::smartQuote()
3289 LyXText const * lt = bv_->getLyXText();
3290 Paragraph const * par = lt->cursor.par();
3291 pos_type pos = lt->cursor.pos();
3295 || (par->isInset(pos - 1)
3296 && par->getInset(pos - 1)->isSpace()))
3299 c = par->getChar(pos - 1);
3304 LyXLayout const & style = textclasslist.Style(
3305 bv_->buffer()->params.textclass, par->getLayout());
3307 if (style.pass_thru ||
3308 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3309 Dispatch(LFUN_SELFINSERT, "\"");
3313 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3315 if (insertInset(inset))
3322 // Open and lock an updatable inset
3323 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3325 LyXText * lt = bv_->getLyXText();
3329 if (!insertInset(new_inset)) {
3333 new_inset->edit(bv_, !behind);
3338 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3340 // if we are in a locking inset we should try to insert the
3341 // inset there otherwise this is a illegal function now
3342 if (bv_->theLockingInset()) {
3343 if (bv_->theLockingInset()->insetAllowed(inset))
3344 return bv_->theLockingInset()->insertInset(bv_, inset);
3348 // not quite sure if we want this...
3349 setCursorParUndo(bv_);
3352 beforeChange(bv_->text);
3353 if (!lout.empty()) {
3354 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3355 bv_->text->breakParagraph(bv_);
3356 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3358 if (bv_->text->cursor.par()->size()) {
3359 bv_->text->cursorLeft(bv_);
3361 bv_->text->breakParagraph(bv_);
3362 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3365 pair<bool, layout_type> lres =
3366 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3367 layout_type lay = 0;
3368 if (lres.first != false) {
3372 // layout not fount using default "Standard" (0)
3376 bv_->text->setLayout(bv_, lay);
3378 bv_->text->setParagraph(bv_, 0, 0,
3380 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3385 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3388 bv_->text->insertInset(bv_, inset);
3389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3396 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3401 // first check for locking insets
3402 if (bv_->theLockingInset()) {
3403 if (bv_->theLockingInset() == inset) {
3404 if (bv_->text->updateInset(bv_, inset)) {
3407 buffer_->markDirty();
3412 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3413 if (bv_->text->updateInset(bv_,
3414 bv_->theLockingInset())) {
3417 buffer_->markDirty();
3425 // then check the current buffer
3428 update(bv_->text, BufferView::UPDATE);
3429 if (bv_->text->updateInset(bv_, inset)) {
3433 | BufferView::FITCUR
3434 | BufferView::CHANGE);
3436 update(bv_->text, SELECT);
3444 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3447 if (!available()) return;
3450 beforeChange(bv_->text);
3451 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3453 LyXCursor const & cursor = bv_->text->cursor;
3457 cursor.par()->isInset(cursor.pos())) {
3458 Inset const * inset = cursor.par()->getInset(cursor.pos());
3459 if (find(codes.begin(), codes.end(), inset->lyxCode())
3462 static_cast<InsetCommand const *>(inset)->getContents();
3466 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3467 if (bv_->text->cursor.pos()
3468 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3469 LyXCursor tmp = bv_->text->cursor;
3470 bv_->text->cursor.par(bv_->text->firstParagraph());
3471 bv_->text->cursor.pos(0);
3472 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3473 bv_->text->cursor = tmp;
3474 bv_->owner()->message(_("No more insets"));
3477 bv_->owner()->message(_("No more insets"));
3480 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3481 bv_->text->selection.cursor = bv_->text->cursor;
3485 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3487 gotoInset(vector<Inset::Code>(1, code), same_content);