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"
23 // added for Dispatch functions
26 #include "FloatList.h"
28 #include "ParagraphParameters.h"
29 #include "undo_funcs.h"
30 #include "lyxtextclasslist.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Alert.h"
34 #include "frontends/FileDialog.h"
36 #include "insets/insetbib.h"
37 #include "insets/insettext.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetnote.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetlist.h"
59 #include "insets/insetcaption.h"
60 #include "insets/insetfloatlist.h"
61 #include "insets/insetspecialchar.h"
63 #include "mathed/formulabase.h"
65 #include "support/LAssert.h"
66 #include "support/lstrings.h"
67 #include "support/filetools.h"
68 #include "support/lyxfunctional.h"
76 extern lyx::layout_type current_layout;
88 using lyx::layout_type;
89 using lyx::textclass_type;
91 /* the selection possible is needed, that only motion events are
92 * used, where the bottom press event was on the drawing area too */
93 bool selection_possible = false;
95 extern BufferList bufferlist;
96 extern char ascii_type;
98 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
103 const unsigned int saved_positions_num = 20;
108 XSync(fl_get_display(), 0);
112 void SetXtermCursor(Window win)
114 static Cursor cursor;
115 static bool cursor_undefined = true;
116 if (cursor_undefined) {
117 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
118 XFlush(fl_get_display());
119 cursor_undefined = false;
121 XDefineCursor(fl_get_display(), win, cursor);
122 XFlush(fl_get_display());
128 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
129 int xpos, int ypos, int width, int height)
130 : bv_(b), owner_(o), buffer_(0),
131 current_scrollbar_value(0), cursor_timeout(400),
132 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
136 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
137 workarea_.workAreaExpose
138 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
139 workarea_.workAreaEnter
140 .connect(slot(this, &BufferView::Pimpl::enterView));
141 workarea_.workAreaLeave
142 .connect(slot(this, &BufferView::Pimpl::leaveView));
143 workarea_.workAreaButtonPress
144 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
145 workarea_.workAreaButtonRelease
147 &BufferView::Pimpl::workAreaButtonRelease));
148 workarea_.workAreaMotionNotify
149 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
150 workarea_.workAreaDoubleClick
151 .connect(slot(this, &BufferView::Pimpl::doubleClick));
152 workarea_.workAreaTripleClick
153 .connect(slot(this, &BufferView::Pimpl::tripleClick));
154 workarea_.workAreaKeyPress
155 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
156 workarea_.selectionRequested
157 .connect(slot(this, &BufferView::Pimpl::selectionRequested));
158 workarea_.selectionLost
159 .connect(slot(this, &BufferView::Pimpl::selectionLost));
161 cursor_timeout.timeout.connect(slot(this,
162 &BufferView::Pimpl::cursorToggle));
163 cursor_timeout.start();
164 workarea_.setFocus();
165 saved_positions.resize(saved_positions_num);
169 Painter & BufferView::Pimpl::painter()
171 return workarea_.getPainter();
175 void BufferView::Pimpl::buffer(Buffer * b)
177 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
181 buffer_->delUser(bv_);
183 // Put the old text into the TextCache, but
184 // only if the buffer is still loaded.
185 // Also set the owner of the test to 0
186 // bv_->text->owner(0);
187 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
188 if (lyxerr.debugging())
189 textcache.show(lyxerr, "BufferView::buffer");
194 // Set current buffer
197 if (bufferlist.getState() == BufferList::CLOSING) return;
200 // screen is always deleted when the buffer is changed.
203 // If we are closing the buffer, use the first buffer as current
205 buffer_ = bufferlist.first();
209 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
210 buffer_->addUser(bv_);
211 // If we don't have a text object for this, we make one
212 if (bv_->text == 0) {
213 resizeCurrentBuffer();
218 bv_->text->first = screen_->topCursorVisible(bv_->text);
219 owner_->updateMenubar();
220 owner_->updateToolbar();
221 // Similarly, buffer-dependent dialogs should be updated or
222 // hidden. This should go here because some dialogs (eg ToC)
223 // require bv_->text.
224 owner_->getDialogs()->updateBufferDependent(true);
228 lyxerr[Debug::INFO] << " No Buffer!" << endl;
229 owner_->updateMenubar();
230 owner_->updateToolbar();
231 owner_->getDialogs()->hideBufferDependent();
235 // Also remove all remaining text's from the testcache.
236 // (there should not be any!) (if there is any it is a
238 if (lyxerr.debugging())
239 textcache.show(lyxerr, "buffer delete all");
242 // should update layoutchoice even if we don't have a buffer.
243 owner_->updateLayoutChoice();
245 owner_->updateWindowTitle();
249 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
251 workarea_.resize(xpos, ypos, width, height);
252 update(bv_->text, SELECT);
257 void BufferView::Pimpl::resize()
260 resizeCurrentBuffer();
264 void BufferView::Pimpl::redraw()
266 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
271 bool BufferView::Pimpl::fitCursor()
273 lyx::Assert(screen_.get());
277 if (bv_->theLockingInset()) {
278 bv_->theLockingInset()->fitInsetCursor(bv_);
281 ret = screen_->fitCursor(bv_->text, bv_);
284 bv_->owner()->getDialogs()->updateParagraph();
291 void BufferView::Pimpl::redoCurrentBuffer()
293 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
294 if (buffer_ && bv_->text) {
296 owner_->updateLayoutChoice();
301 int BufferView::Pimpl::resizeCurrentBuffer()
303 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
306 Paragraph * selstartpar = 0;
307 Paragraph * selendpar = 0;
308 UpdatableInset * the_locking_inset = 0;
311 pos_type selstartpos = 0;
312 pos_type selendpos = 0;
313 bool selection = false;
314 bool mark_set = false;
316 owner_->prohibitInput();
318 owner_->message(_("Formatting document..."));
321 par = bv_->text->cursor.par();
322 pos = bv_->text->cursor.pos();
323 selstartpar = bv_->text->selection.start.par();
324 selstartpos = bv_->text->selection.start.pos();
325 selendpar = bv_->text->selection.end.par();
326 selendpos = bv_->text->selection.end.pos();
327 selection = bv_->text->selection.set();
328 mark_set = bv_->text->selection.mark();
329 the_locking_inset = bv_->theLockingInset();
331 bv_->text = new LyXText(bv_);
332 bv_->text->init(bv_);
334 // See if we have a text in TextCache that fits
335 // the new buffer_ with the correct width.
336 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
338 if (lyxerr.debugging()) {
339 lyxerr << "Found a LyXText that fits:\n";
340 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
342 // Set the owner of the newly found text
343 // bv_->text->owner(bv_);
344 if (lyxerr.debugging())
345 textcache.show(lyxerr, "resizeCurrentBuffer");
347 bv_->text = new LyXText(bv_);
348 bv_->text->init(bv_);
354 bv_->text->selection.set(true);
355 /* at this point just to avoid the Delete-Empty-Paragraph
356 * Mechanism when setting the cursor */
357 bv_->text->selection.mark(mark_set);
359 bv_->text->setCursor(bv_, selstartpar, selstartpos);
360 bv_->text->selection.cursor = bv_->text->cursor;
361 bv_->text->setCursor(bv_, selendpar, selendpos);
362 bv_->text->setSelection(bv_);
363 bv_->text->setCursor(bv_, par, pos);
365 bv_->text->setCursor(bv_, par, pos);
366 bv_->text->selection.cursor = bv_->text->cursor;
367 bv_->text->selection.set(false);
369 // remake the inset locking
370 bv_->theLockingInset(the_locking_inset);
372 bv_->text->first = screen_->topCursorVisible(bv_->text);
374 buffer_->resizeInsets(bv_);
376 // this will scroll the screen such that the cursor becomes visible
381 owner_->allowInput();
383 /// clear the "Formatting Document" message
390 void BufferView::Pimpl::updateScreen()
392 // Regenerate the screen.
393 screen_.reset(new LyXScreen(workarea_));
397 void BufferView::Pimpl::updateScrollbar()
399 /* If the text is smaller than the working area, the scrollbar
400 * maximum must be the working area height. No scrolling will
403 workarea_.setScrollbar(0, 1.0);
407 long const text_height = bv_->text->height;
408 long const work_height = workarea_.height();
410 if (text_height <= work_height) {
411 workarea_.setScrollbarBounds(0.0, 0.0);
412 current_scrollbar_value = bv_->text->first;
413 workarea_.setScrollbar(current_scrollbar_value, 1.0);
417 double const lineh = bv_->text->defaultHeight();
418 double const slider_size =
419 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
421 static long old_text_height;
422 static double old_lineh;
423 static double old_slider_size;
425 if (text_height != old_text_height) {
426 workarea_.setScrollbarBounds(0.0,
427 text_height - work_height);
428 old_text_height = text_height;
430 if (lineh != old_lineh) {
431 workarea_.setScrollbarIncrements(lineh);
434 if (current_scrollbar_value != bv_->text->first
435 || slider_size != old_slider_size) {
436 current_scrollbar_value = bv_->text->first;
437 workarea_.setScrollbar(current_scrollbar_value, slider_size);
438 old_slider_size = slider_size;
443 // Callback for scrollbar slider
444 void BufferView::Pimpl::scrollCB(double value)
446 if (!buffer_) return;
448 current_scrollbar_value = long(value);
450 if (current_scrollbar_value < 0)
451 current_scrollbar_value = 0;
456 screen_->draw(bv_->text, bv_, current_scrollbar_value);
458 if (!lyxrc.cursor_follows_scrollbar) {
463 LyXText * vbt = bv_->text;
465 int const height = vbt->defaultHeight();
466 int const first = static_cast<int>((bv_->text->first + height));
467 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
469 if (vbt->cursor.y() < first)
470 vbt->setCursorFromCoordinates(bv_, 0, first);
471 else if (vbt->cursor.y() > last)
472 vbt->setCursorFromCoordinates(bv_, 0, last);
478 int BufferView::Pimpl::scrollUp(long time)
480 if (!buffer_) return 0;
481 if (!screen_.get()) return 0;
483 double value = workarea_.getScrollbarValue();
485 if (value == 0) return 0;
487 float add_value = (bv_->text->defaultHeight()
488 + float(time) * float(time) * 0.125);
490 if (add_value > workarea_.height())
491 add_value = float(workarea_.height() -
492 bv_->text->defaultHeight());
499 workarea_.setScrollbarValue(value);
506 int BufferView::Pimpl::scrollDown(long time)
508 if (!buffer_) return 0;
509 if (!screen_.get()) return 0;
511 double value = workarea_.getScrollbarValue();
512 pair<float, float> p = workarea_.getScrollbarBounds();
513 double const max = p.second;
515 if (value == max) return 0;
517 float add_value = (bv_->text->defaultHeight()
518 + float(time) * float(time) * 0.125);
520 if (add_value > workarea_.height())
521 add_value = float(workarea_.height() -
522 bv_->text->defaultHeight());
529 workarea_.setScrollbarValue(value);
536 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
538 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
542 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
544 // Only use motion with button 1
545 if (!(state & Button1MotionMask))
548 if (!buffer_ || !screen_.get()) return;
550 // Check for inset locking
551 if (bv_->theLockingInset()) {
552 LyXCursor cursor = bv_->text->cursor;
553 LyXFont font = bv_->text->getFont(buffer_,
554 cursor.par(), cursor.pos());
555 int width = bv_->theLockingInset()->width(bv_, font);
556 int inset_x = font.isVisibleRightToLeft()
557 ? cursor.x() - width : cursor.x();
558 int start_x = inset_x + bv_->theLockingInset()->scroll();
559 bv_->theLockingInset()->
560 insetMotionNotify(bv_,
562 y - cursor.y() + bv_->text->first,
567 /* The test for not selection possible is needed, that only motion
568 events are used, where the bottom press event was on
569 the drawing area too */
570 if (!selection_possible)
573 screen_->hideCursor();
575 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
577 if (!bv_->text->selection.set())
578 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
580 bv_->text->setSelection(bv_);
581 screen_->toggleToggle(bv_->text, bv_);
587 // Single-click on work area
588 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
591 if (!buffer_ || !screen_.get()) return;
593 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
595 // ok ok, this is a hack.
596 if (button == 4 || button == 5) {
599 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
602 scrollDown(lyxrc.wheel_jump);
607 if (bv_->theLockingInset()) {
608 // We are in inset locking mode
610 /* Check whether the inset was hit. If not reset mode,
611 otherwise give the event to the inset */
612 if (inset_hit == bv_->theLockingInset()) {
613 bv_->theLockingInset()->
614 insetButtonPress(bv_,xpos, ypos,button);
617 bv_->unlockInset(bv_->theLockingInset());
622 selection_possible = true;
623 screen_->hideCursor();
625 int const screen_first = bv_->text->first;
627 // Middle button press pastes if we have a selection
628 bool paste_internally = false;
630 && bv_->text->selection.set()) {
631 owner_->getLyXFunc()->dispatch(LFUN_COPY);
632 paste_internally = true;
635 // Clear the selection
636 screen_->toggleSelection(bv_->text, bv_);
637 bv_->text->clearSelection();
638 bv_->text->fullRebreak(bv_);
642 // Single left click in math inset?
643 if (isHighlyEditableInset(inset_hit)) {
644 // Highly editable inset, like math
645 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
646 selection_possible = false;
647 owner_->updateLayoutChoice();
648 owner_->message(inset->editMessage());
649 // IMO the inset has to be first in edit-mode and then we send the
650 // button press. (Jug 20020222)
651 inset->edit(bv_); //, xpos, ypos, button);
652 inset->insetButtonPress(bv_, xpos, ypos, button);
656 // Right click on a footnote flag opens float menu
658 selection_possible = false;
662 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
663 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
665 bv_->text->selection.cursor = bv_->text->cursor;
666 bv_->text->cursor.x_fix(bv_->text->cursor.x());
668 owner_->updateLayoutChoice();
670 selection_possible = false;
673 // Insert primary selection with middle mouse
674 // if there is a local selection in the current buffer,
677 if (paste_internally)
678 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
680 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
682 selection_possible = false;
688 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
694 LyXText * text = bv_->getLyXText();
696 if (text->bv_owner && bv_->theLockingInset())
699 if (screen_.get() && button == 1) {
700 if (text->bv_owner) {
701 screen_->hideCursor();
702 screen_->toggleSelection(text, bv_);
703 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
704 screen_->toggleSelection(text, bv_, false);
706 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
708 /* This will fit the cursor on the screen
710 update(text, BufferView::SELECT|BufferView::FITCUR);
715 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
721 LyXText * text = bv_->getLyXText();
723 if (text->bv_owner && bv_->theLockingInset())
726 if (screen_.get() && (button == 1)) {
727 if (text->bv_owner) {
728 screen_->hideCursor();
729 screen_->toggleSelection(text, bv_);
731 text->cursorHome(bv_);
732 text->selection.cursor = text->cursor;
733 text->cursorEnd(bv_);
734 text->setSelection(bv_);
735 if (text->bv_owner) {
736 screen_->toggleSelection(text, bv_, false);
738 /* This will fit the cursor on the screen
740 update(text, BufferView::SELECT|BufferView::FITCUR);
745 void BufferView::Pimpl::selectionRequested()
750 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
753 workarea_.putClipboard(sel);
758 void BufferView::Pimpl::selectionLost()
762 bv_->getLyXText()->clearSelection();
767 void BufferView::Pimpl::enterView()
769 if (active() && available()) {
770 SetXtermCursor(workarea_.getWin());
771 using_xterm_cursor = true;
776 void BufferView::Pimpl::leaveView()
778 if (using_xterm_cursor) {
779 XUndefineCursor(fl_get_display(), workarea_.getWin());
780 using_xterm_cursor = false;
785 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
788 if (!buffer_ || !screen_.get()) return;
790 // If we hit an inset, we have the inset coordinates in these
791 // and inset_hit points to the inset. If we do not hit an
792 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
793 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
795 if (bv_->theLockingInset()) {
796 // We are in inset locking mode.
798 /* LyX does a kind of work-area grabbing for insets.
799 Only a ButtonPress Event outside the inset will
800 force a insetUnlock. */
801 bv_->theLockingInset()->
802 insetButtonRelease(bv_, x, y, button);
806 selection_possible = false;
813 workarea_.haveSelection(bv_->getLyXText()->selection.set());
818 owner_->updateMenubar();
819 owner_->updateToolbar();
821 // Did we hit an editable inset?
823 selection_possible = false;
825 // if we reach this point with a selection, it
826 // must mean we are currently selecting.
827 // But we don't want to open the inset
828 // because that is annoying for the user.
829 // So just pretend we didn't hit it.
830 // this is OK because a "kosher" ButtonRelease
831 // will follow a ButtonPress that clears
833 // Note this also fixes selection drawing
834 // problems if we end up opening an inset
835 if (bv_->getLyXText()->selection.set())
838 // CHECK fix this proper in 0.13
839 // well, maybe 13.0 !!!!!!!!!
841 // Following a ref shouldn't issue
842 // a push on the undo-stack
843 // anylonger, now that we have
844 // keybindings for following
845 // references and returning from
846 // references. IMHO though, it
847 // should be the inset's own business
848 // to push or not push on the undo
849 // stack. They don't *have* to
850 // alter the document...
852 // ...or maybe the SetCursorParUndo()
853 // below isn't necessary at all anylonger?
854 if (inset_hit->lyxCode() == Inset::REF_CODE) {
855 setCursorParUndo(bv_);
858 owner_->message(inset_hit->editMessage());
860 if (isHighlyEditableInset(inset_hit)) {
861 // Highly editable inset, like math
862 UpdatableInset *inset = (UpdatableInset *)inset_hit;
863 inset->insetButtonRelease(bv_, x, y, button);
865 inset_hit->insetButtonRelease(bv_, x, y, button);
866 inset_hit->edit(bv_, x, y, button);
871 // Maybe we want to edit a bibitem ale970302
872 if (bv_->text->cursor.par()->bibkey && x < 20 +
873 bibitemMaxWidth(bv_, textclasslist.
875 params.textclass).defaultfont())) {
876 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
883 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
884 LyXCursor const & cursor) const
886 Paragraph /*const*/ & par = *cursor.par();
887 pos_type const pos = cursor.pos();
889 lyx::Assert(par.getInset(pos));
891 Inset const & inset(*par.getInset(pos));
893 LyXFont const & font = text.getFont(buffer_, &par, pos);
895 int const width = inset.width(bv_, font);
896 int const inset_x = font.isVisibleRightToLeft()
897 ? (cursor.x() - width) : cursor.x();
900 inset_x + inset.scroll(),
902 cursor.y() - inset.ascent(bv_, font),
903 cursor.y() + inset.descent(bv_, font));
907 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
908 LyXCursor const & cursor,
909 int & x, int & y) const
911 pos_type const pos(cursor.pos());
912 Paragraph /*const*/ & par(*cursor.par());
914 if (pos >= par.size() || !par.isInset(pos)) {
918 Inset /*const*/ * inset = par.getInset(pos);
920 if (!isEditableInset(inset)) {
924 Box b(insetDimensions(text, cursor));
926 if (!b.contained(x, y)) {
927 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
928 << " box " << b << endl;
932 text.setCursor(bv_, &par, pos, true);
935 // The origin of an inset is on the baseline
936 y -= (text.cursor.y());
942 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
947 int y_tmp = y + text->first;
950 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
952 Inset * inset(checkInset(*text, cursor, x, y_tmp));
959 // look at previous position
961 if (cursor.pos() == 0) {
966 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
968 inset = checkInset(*text, cursor, x, y_tmp);
976 void BufferView::Pimpl::workAreaExpose()
978 static int work_area_width;
979 static unsigned int work_area_height;
981 bool const widthChange = workarea_.workWidth() != work_area_width;
982 bool const heightChange = workarea_.height() != work_area_height;
984 // update from work area
985 work_area_width = workarea_.workWidth();
986 work_area_height = workarea_.height();
989 // The visible LyXView need a resize
992 // Remove all texts from the textcache
993 // This is not _really_ what we want to do. What
994 // we really want to do is to delete in textcache
995 // that does not have a BufferView with matching
996 // width, but as long as we have only one BufferView
997 // deleting all gives the same result.
998 if (lyxerr.debugging())
999 textcache.show(lyxerr, "Expose delete all");
1001 } else if (heightChange) {
1002 // Rebuild image of current screen
1004 // fitCursor() ensures we don't jump back
1005 // to the start of the document on vertical
1009 // The main window size has changed, repaint most stuff
1011 } else if (screen_.get())
1012 screen_->redraw(bv_->text, bv_);
1014 // Grey box when we don't have a buffer
1015 workarea_.greyOut();
1018 // always make sure that the scrollbar is sane.
1020 owner_->updateLayoutChoice();
1025 void BufferView::Pimpl::update()
1027 if (screen_.get() &&
1028 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1030 LyXText::text_status st = bv_->text->status();
1031 screen_->update(bv_->text, bv_);
1033 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1034 if (bv_->text->fullRebreak(bv_)) {
1035 st = LyXText::NEED_MORE_REFRESH;
1036 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1037 bv_->text->cursor.pos());
1040 bv_->text->status(bv_, st);
1041 screen_->update(bv_->text, bv_);
1043 // do this here instead of in the screen::update because of
1045 bv_->text->status(bv_, LyXText::UNCHANGED);
1051 // Values used when calling update:
1053 // -2 - update, move sel_cursor if selection, fitcursor
1054 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1055 // 0 - update, move sel_cursor if selection, fitcursor
1056 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1057 // 3 - update, move sel_cursor if selection
1060 // a simple redraw of the parts that need refresh
1062 // move sel_cursor if selection -
1063 // the text's sel_cursor is moved if there is selection is progress
1066 // fitCursor() is called and the scrollbar updated
1069 // the buffer is marked dirty.
1078 // UPDATE_ONLY = UPDATE;
1079 // UPDATE_SELECT = UPDATE | SELECT;
1080 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1081 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1083 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1084 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1085 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1086 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1087 // update(3) -> update(1) -> update(1) -> update(SELECT)
1089 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1091 owner_->updateLayoutChoice();
1093 if (!text->selection.set() && (f & SELECT)) {
1094 text->selection.cursor = text->cursor;
1097 text->fullRebreak(bv_);
1099 if (text->inset_owner) {
1100 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1101 updateInset(text->inset_owner, false);
1111 buffer_->markDirty();
1116 // Callback for cursor timer
1117 void BufferView::Pimpl::cursorToggle()
1120 cursor_timeout.restart();
1124 if (!screen_.get()) {
1125 cursor_timeout.restart();
1130 extern void reapSpellchecker(void);
1133 if (!bv_->theLockingInset()) {
1134 screen_->cursorToggle(bv_);
1136 bv_->theLockingInset()->toggleInsetCursor(bv_);
1139 cursor_timeout.restart();
1143 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1145 if (!text->cursor.row()->previous())
1148 int y = text->first;
1149 if (text->inset_owner)
1150 y += bv_->text->first;
1151 Row * cursorrow = text->cursor.row();
1152 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1154 // This is to allow jumping over large insets
1155 if ((cursorrow == text->cursor.row()))
1156 text->cursorUp(bv_);
1158 if (text->inset_owner ||
1159 text->cursor.row()->height() < workarea_.height())
1160 screen_->draw(bv_->text, bv_,
1162 - text->cursor.row()->baseline()
1163 + text->cursor.row()->height()
1164 - workarea_.height() + 1);
1169 void BufferView::Pimpl::cursorNext(LyXText * text)
1171 if (!text->cursor.row()->next())
1174 int y = text->first + workarea_.height();
1175 // if (text->inset_owner)
1176 // y += bv_->text->first;
1177 text->getRowNearY(y);
1179 Row * cursorrow = text->cursor.row();
1180 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1182 // This is to allow jumping over large insets
1183 if ((cursorrow == bv_->text->cursor.row()))
1184 text->cursorDown(bv_);
1186 if (text->inset_owner ||
1187 text->cursor.row()->height() < workarea_.height())
1188 screen_->draw(bv_->text, bv_, text->cursor.y() -
1189 text->cursor.row()->baseline());
1194 bool BufferView::Pimpl::available() const
1196 if (buffer_ && bv_->text) return true;
1201 void BufferView::Pimpl::beforeChange(LyXText * text)
1204 text->clearSelection();
1208 void BufferView::Pimpl::savePosition(unsigned int i)
1210 if (i >= saved_positions_num)
1212 saved_positions[i] = Position(buffer_->fileName(),
1213 bv_->text->cursor.par()->id(),
1214 bv_->text->cursor.pos());
1217 str << _("Saved bookmark") << ' ' << i;
1218 owner_->message(str.str().c_str());
1223 void BufferView::Pimpl::restorePosition(unsigned int i)
1225 if (i >= saved_positions_num)
1228 string const fname = saved_positions[i].filename;
1230 beforeChange(bv_->text);
1232 if (fname != buffer_->fileName()) {
1233 Buffer * b = bufferlist.exists(fname) ?
1234 bufferlist.getBuffer(fname) :
1235 bufferlist.loadLyXFile(fname); // don't ask, just load it
1236 if (b != 0) buffer(b);
1239 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1243 bv_->text->setCursor(bv_, par,
1244 min(par->size(), saved_positions[i].par_pos));
1246 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1249 str << _("Moved to bookmark") << ' ' << i;
1250 owner_->message(str.str().c_str());
1255 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1257 if (i >= saved_positions_num)
1260 return !saved_positions[i].filename.empty();
1264 void BufferView::Pimpl::setState()
1266 if (!lyxrc.rtl_support)
1269 LyXText * text = bv_->getLyXText();
1270 if (text->real_current_font.isRightToLeft()) {
1271 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1272 owner_->getIntl()->KeyMapSec();
1274 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1275 owner_->getIntl()->KeyMapPrim();
1280 void BufferView::Pimpl::insetSleep()
1282 if (bv_->theLockingInset() && !inset_slept) {
1283 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1284 bv_->theLockingInset()->insetUnlock(bv_);
1290 void BufferView::Pimpl::insetWakeup()
1292 if (bv_->theLockingInset() && inset_slept) {
1293 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1294 inset_slept = false;
1299 void BufferView::Pimpl::insetUnlock()
1301 if (bv_->theLockingInset()) {
1303 bv_->theLockingInset()->insetUnlock(bv_);
1304 bv_->theLockingInset(0);
1306 inset_slept = false;
1311 bool BufferView::Pimpl::focus() const
1313 return workarea_.hasFocus();
1317 void BufferView::Pimpl::focus(bool f)
1319 if (f) workarea_.setFocus();
1323 bool BufferView::Pimpl::active() const
1325 return workarea_.active();
1329 bool BufferView::Pimpl::belowMouse() const
1331 return workarea_.belowMouse();
1335 void BufferView::Pimpl::showCursor()
1337 if (screen_.get()) {
1338 if (bv_->theLockingInset())
1339 bv_->theLockingInset()->showInsetCursor(bv_);
1341 screen_->showCursor(bv_->text, bv_);
1346 void BufferView::Pimpl::hideCursor()
1348 if (screen_.get()) {
1349 if (!bv_->theLockingInset())
1350 // bv_->theLockingInset()->hideInsetCursor(bv_);
1352 screen_->hideCursor();
1357 void BufferView::Pimpl::toggleSelection(bool b)
1359 if (screen_.get()) {
1360 if (bv_->theLockingInset())
1361 bv_->theLockingInset()->toggleSelection(bv_, b);
1362 screen_->toggleSelection(bv_->text, bv_, b);
1367 void BufferView::Pimpl::toggleToggle()
1370 screen_->toggleToggle(bv_->text, bv_);
1374 void BufferView::Pimpl::center()
1376 beforeChange(bv_->text);
1377 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1378 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1380 screen_->draw(bv_->text, bv_, 0);
1382 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1387 void BufferView::Pimpl::pasteClipboard(bool asPara)
1389 if (!buffer_) return;
1391 screen_->hideCursor();
1392 beforeChange(bv_->text);
1394 string const clip(workarea_.getClipboard());
1396 if (clip.empty()) return;
1399 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1401 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1403 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1407 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1409 workarea_.putClipboard(stuff);
1414 * Dispatch functions for actions which can be valid for BufferView->text
1415 * and/or InsetText->text!!!
1420 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1422 LyXText * lt = bv_->getLyXText();
1424 if (selecting || lt->selection.mark()) {
1425 lt->setSelection(bv_);
1429 update(lt, BufferView::SELECT|BufferView::FITCUR);
1432 /* ---> Everytime the cursor is moved, show the current font state. */
1433 // should this too me moved out of this func?
1434 //owner->showState();
1439 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1441 LyXCursor cursor = bv_->getLyXText()->cursor;
1442 Buffer::inset_iterator it =
1443 find_if(Buffer::inset_iterator(
1444 cursor.par(), cursor.pos()),
1445 buffer_->inset_iterator_end(),
1446 lyx::compare_memfun(&Inset::lyxCode, code));
1447 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1451 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1453 string filename = filen;
1455 if (filename.empty()) {
1456 // Launch a file browser
1457 string initpath = lyxrc.document_path;
1460 string const trypath = owner_->buffer()->filePath();
1461 // If directory is writeable, use this as default.
1462 if (IsDirWriteable(trypath))
1466 FileDialog fileDlg(bv_->owner(),
1467 _("Select LyX document to insert"),
1469 make_pair(string(_("Documents|#o#O")),
1470 string(lyxrc.document_path)),
1471 make_pair(string(_("Examples|#E#e")),
1472 string(AddPath(system_lyxdir, "examples"))));
1474 FileDialog::Result result =
1475 fileDlg.Select(initpath,
1476 _("*.lyx| LyX Documents (*.lyx)"));
1478 if (result.first == FileDialog::Later)
1481 filename = result.second;
1483 // check selected filename
1484 if (filename.empty()) {
1485 owner_->message(_("Canceled."));
1490 // get absolute path of file and add ".lyx" to the filename if
1492 filename = FileSearch(string(), filename, "lyx");
1494 string const disp_fn(MakeDisplayPath(filename));
1497 s1 << _("Inserting document") << ' '
1498 << disp_fn << " ...";
1499 owner_->message(s1.str().c_str());
1500 bool const res = bv_->insertLyXFile(filename);
1503 str << _("Document") << ' ' << disp_fn
1504 << ' ' << _("inserted.");
1505 owner_->message(str.str().c_str());
1508 str << _("Could not insert document") << ' '
1510 owner_->message(str.str().c_str());
1515 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1517 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1518 << action <<"] arg[" << argument << "]" << endl;
1521 // --- Misc -------------------------------------------
1525 LyXText * lt = bv_->getLyXText();
1526 lt->toggleAppendix(bv_);
1529 | BufferView::FITCUR
1530 | BufferView::CHANGE);
1535 case LFUN_TOC_INSERT:
1537 InsetCommandParams p;
1538 p.setCmdName("tableofcontents");
1539 Inset * inset = new InsetTOC(p);
1540 if (!insertInset(inset, "Standard"))
1545 case LFUN_TABULAR_FEATURE:
1546 case LFUN_SCROLL_INSET:
1547 // this is not handled here as this funktion is only aktive
1548 // if we have a locking_inset and that one is (or contains)
1552 case LFUN_INSET_GRAPHICS:
1554 Inset * new_inset = new InsetGraphics;
1555 if (!insertInset(new_inset)) {
1558 // this is need because you don't use a inset->Edit()
1559 updateInset(new_inset, true);
1560 new_inset->edit(bv_);
1570 case LFUN_PASTESELECTION:
1572 bool asPara = false;
1573 if (argument == "paragraph")
1575 pasteClipboard(asPara);
1587 case LFUN_LAYOUT_COPY:
1588 bv_->copyEnvironment();
1591 case LFUN_LAYOUT_PASTE:
1592 bv_->pasteEnvironment();
1596 case LFUN_GOTOERROR:
1597 gotoInset(Inset::ERROR_CODE, false);
1601 gotoInset(Inset::IGNORE_CODE, false);
1604 case LFUN_REFERENCE_GOTO:
1606 vector<Inset::Code> tmp;
1607 tmp.push_back(Inset::LABEL_CODE);
1608 tmp.push_back(Inset::REF_CODE);
1609 gotoInset(tmp, true);
1613 case LFUN_HYPHENATION:
1614 specialChar(InsetSpecialChar::HYPHENATION);
1617 case LFUN_LIGATURE_BREAK:
1618 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1622 specialChar(InsetSpecialChar::LDOTS);
1625 case LFUN_END_OF_SENTENCE:
1626 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1629 case LFUN_MENU_SEPARATOR:
1630 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1638 changeDepth(bv_, bv_->getLyXText(), 0);
1641 case LFUN_DEPTH_MIN:
1642 changeDepth(bv_, bv_->getLyXText(), -1);
1645 case LFUN_DEPTH_PLUS:
1646 changeDepth(bv_, bv_->getLyXText(), 1);
1650 owner_->getDialogs()->setUserFreeFont();
1653 case LFUN_FILE_INSERT:
1654 MenuInsertLyXFile(argument);
1657 case LFUN_FILE_INSERT_ASCII_PARA:
1658 InsertAsciiFile(bv_, argument, true);
1661 case LFUN_FILE_INSERT_ASCII:
1662 InsertAsciiFile(bv_, argument, false);
1667 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1668 << argument << endl;
1670 // Derive layout number from given argument (string)
1671 // and current buffer's textclass (number). */
1672 textclass_type tclass = buffer_->params.textclass;
1673 pair <bool, layout_type> layout =
1674 textclasslist.NumberOfLayout(tclass, argument);
1676 // If the entry is obsolete, use the new one instead.
1678 string obs = textclasslist.Style(tclass, layout.second)
1681 layout = textclasslist.NumberOfLayout(tclass, obs);
1684 // see if we found the layout number:
1685 if (!layout.first) {
1686 owner_->getLyXFunc()->setErrorMessage(
1687 string(N_("Layout ")) + argument +
1692 if (current_layout != layout.second) {
1693 LyXText * lt = bv_->getLyXText();
1695 current_layout = layout.second;
1698 | BufferView::FITCUR);
1699 lt->setLayout(bv_, layout.second);
1700 owner_->setLayout(layout.second);
1703 | BufferView::FITCUR
1704 | BufferView::CHANGE);
1711 lang(bv_, argument);
1713 owner_->showState();
1718 owner_->showState();
1723 owner_->showState();
1728 owner_->showState();
1733 owner_->showState();
1738 owner_->showState();
1743 owner_->showState();
1748 owner_->showState();
1751 case LFUN_UNDERLINE:
1753 owner_->showState();
1756 case LFUN_FONT_SIZE:
1757 fontSize(bv_, argument);
1758 owner_->showState();
1761 case LFUN_FONT_STATE:
1762 owner_->getLyXFunc()->setMessage(currentState(bv_));
1765 case LFUN_UPCASE_WORD:
1767 LyXText * lt = bv_->getLyXText();
1771 | BufferView::FITCUR);
1772 lt->changeCase(bv_, LyXText::text_uppercase);
1773 if (lt->inset_owner)
1774 updateInset(lt->inset_owner, true);
1777 | BufferView::FITCUR
1778 | BufferView::CHANGE);
1782 case LFUN_LOWCASE_WORD:
1784 LyXText * lt = bv_->getLyXText();
1786 update(lt, BufferView::SELECT|BufferView::FITCUR);
1787 lt->changeCase(bv_, LyXText::text_lowercase);
1788 if (lt->inset_owner)
1789 updateInset(lt->inset_owner, true);
1792 | BufferView::FITCUR
1793 | BufferView::CHANGE);
1797 case LFUN_CAPITALIZE_WORD:
1799 LyXText * lt = bv_->getLyXText();
1801 update(lt, BufferView::SELECT|BufferView::FITCUR);
1802 lt->changeCase(bv_, LyXText::text_capitalization);
1803 if (lt->inset_owner)
1804 updateInset(lt->inset_owner, true);
1807 | BufferView::FITCUR
1808 | BufferView::CHANGE);
1812 case LFUN_TRANSPOSE_CHARS:
1814 LyXText * lt = bv_->getLyXText();
1816 update(lt, BufferView::SELECT|BufferView::FITCUR);
1817 lt->transposeChars(*bv_);
1818 if (lt->inset_owner)
1819 updateInset(lt->inset_owner, true);
1822 | BufferView::FITCUR
1823 | BufferView::CHANGE);
1828 case LFUN_INSERT_LABEL:
1829 MenuInsertLabel(bv_, argument);
1832 case LFUN_REF_INSERT:
1833 if (argument.empty()) {
1834 InsetCommandParams p("ref");
1835 owner_->getDialogs()->createRef(p.getAsString());
1837 InsetCommandParams p;
1838 p.setFromString(argument);
1840 InsetRef * inset = new InsetRef(p, *buffer_);
1841 if (!insertInset(inset))
1844 updateInset(inset, true);
1848 case LFUN_BOOKMARK_SAVE:
1849 savePosition(strToUnsignedInt(argument));
1852 case LFUN_BOOKMARK_GOTO:
1853 restorePosition(strToUnsignedInt(argument));
1858 string label(argument);
1859 if (label.empty()) {
1861 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1863 label = inset->getContents();
1868 if (!label.empty()) {
1869 //bv_->savePosition(0);
1870 if (!bv_->gotoLabel(label))
1871 Alert::alert(_("Error"),
1872 _("Couldn't find this label"),
1873 _("in current document."));
1878 // --- Cursor Movements -----------------------------
1881 LyXText * lt = bv_->getLyXText();
1883 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1884 if (!lt->selection.mark())
1886 update(lt, BufferView::SELECT|BufferView::FITCUR);
1888 lt->cursorLeft(bv_, false);
1889 if (lt->cursor.pos() < lt->cursor.par()->size()
1890 && lt->cursor.par()->isInset(lt->cursor.pos())
1891 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1892 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1893 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1895 tmpinset->edit(bv_, false);
1897 tmpinset->edit(bv_);
1901 lt->cursorRight(bv_, false);
1903 moveCursorUpdate(false);
1904 owner_->showState();
1910 // This is soooo ugly. Isn`t it possible to make
1911 // it simpler? (Lgb)
1912 LyXText * lt = bv_->getLyXText();
1913 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1914 if (!lt->selection.mark())
1916 update(lt, BufferView::SELECT|BufferView::FITCUR);
1917 LyXCursor const cur = lt->cursor;
1919 lt->cursorLeft(bv_, false);
1920 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1921 lt->cursor.pos() < lt->cursor.par()->size() &&
1922 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1923 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1924 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1925 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1927 tmpinset->edit(bv_);
1929 tmpinset->edit(bv_, false);
1933 lt->cursorRight(bv_, false);
1936 moveCursorUpdate(false);
1937 owner_->showState();
1943 LyXText * lt = bv_->getLyXText();
1945 if (!lt->selection.mark())
1947 update(lt, BufferView::UPDATE);
1950 moveCursorUpdate(false);
1951 owner_->showState();
1957 LyXText * lt = bv_->getLyXText();
1959 if (!lt->selection.mark())
1961 update(lt, BufferView::UPDATE);
1962 lt->cursorDown(bv_);
1964 moveCursorUpdate(false);
1965 owner_->showState();
1969 case LFUN_UP_PARAGRAPH:
1971 LyXText * lt = bv_->getLyXText();
1973 if (!lt->selection.mark())
1975 update(lt, BufferView::UPDATE);
1976 lt->cursorUpParagraph(bv_);
1978 moveCursorUpdate(false);
1979 owner_->showState();
1983 case LFUN_DOWN_PARAGRAPH:
1985 LyXText * lt = bv_->getLyXText();
1987 if (!lt->selection.mark())
1989 update(lt, BufferView::UPDATE);
1990 lt->cursorDownParagraph(bv_);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1999 LyXText * lt = bv_->getLyXText();
2001 if (!lt->selection.mark())
2003 update(lt, BufferView::UPDATE);
2006 moveCursorUpdate(false);
2007 owner_->showState();
2013 LyXText * lt = bv_->getLyXText();
2015 if (!lt->selection.mark())
2017 update(lt, BufferView::UPDATE);
2020 moveCursorUpdate(false);
2021 owner_->showState();
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2031 update(lt, BufferView::SELECT|BufferView::FITCUR);
2032 lt->cursorHome(bv_);
2034 moveCursorUpdate(false);
2035 owner_->showState();
2041 LyXText * lt = bv_->getLyXText();
2043 if (!lt->selection.mark())
2046 BufferView::SELECT|BufferView::FITCUR);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2054 case LFUN_SHIFT_TAB:
2057 LyXText * lt = bv_->getLyXText();
2059 if (!lt->selection.mark())
2062 BufferView::SELECT|BufferView::FITCUR);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2070 case LFUN_WORDRIGHT:
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2076 update(lt, BufferView::SELECT|BufferView::FITCUR);
2077 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2078 lt->cursorLeftOneWord(bv_);
2080 lt->cursorRightOneWord(bv_);
2082 moveCursorUpdate(false);
2083 owner_->showState();
2089 LyXText * lt = bv_->getLyXText();
2091 if (!lt->selection.mark())
2093 update(lt, BufferView::SELECT|BufferView::FITCUR);
2094 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2095 lt->cursorRightOneWord(bv_);
2097 lt->cursorLeftOneWord(bv_);
2099 moveCursorUpdate(false);
2100 owner_->showState();
2104 case LFUN_BEGINNINGBUF:
2106 LyXText * lt = bv_->getLyXText();
2108 if (!lt->selection.mark())
2111 BufferView::SELECT|BufferView::FITCUR);
2114 moveCursorUpdate(false);
2115 owner_->showState();
2121 LyXText * lt = bv_->getLyXText();
2123 if (!lt->selection.mark())
2126 BufferView::SELECT|BufferView::FITCUR);
2127 lt->cursorBottom(bv_);
2129 moveCursorUpdate(false);
2130 owner_->showState();
2134 /* cursor selection ---------------------------- */
2137 LyXText * lt = bv_->getLyXText();
2140 BufferView::SELECT|BufferView::FITCUR);
2141 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2142 lt->cursorLeft(bv_);
2144 lt->cursorRight(bv_);
2146 moveCursorUpdate(true);
2147 owner_->showState();
2153 LyXText * lt = bv_->getLyXText();
2156 BufferView::SELECT|BufferView::FITCUR);
2157 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2158 lt->cursorRight(bv_);
2160 lt->cursorLeft(bv_);
2162 moveCursorUpdate(true);
2163 owner_->showState();
2169 LyXText * lt = bv_->getLyXText();
2172 BufferView::SELECT|BufferView::FITCUR);
2175 moveCursorUpdate(true);
2176 owner_->showState();
2182 LyXText * lt = bv_->getLyXText();
2185 BufferView::SELECT|BufferView::FITCUR);
2186 lt->cursorDown(bv_);
2188 moveCursorUpdate(true);
2189 owner_->showState();
2193 case LFUN_UP_PARAGRAPHSEL:
2195 LyXText * lt = bv_->getLyXText();
2198 BufferView::SELECT|BufferView::FITCUR);
2199 lt->cursorUpParagraph(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2206 case LFUN_DOWN_PARAGRAPHSEL:
2208 LyXText * lt = bv_->getLyXText();
2211 BufferView::SELECT|BufferView::FITCUR);
2212 lt->cursorDownParagraph(bv_);
2214 moveCursorUpdate(true);
2215 owner_->showState();
2221 LyXText * lt = bv_->getLyXText();
2223 update(lt, BufferView::SELECT|BufferView::FITCUR);
2226 moveCursorUpdate(true);
2227 owner_->showState();
2233 LyXText * lt = bv_->getLyXText();
2235 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 moveCursorUpdate(true);
2239 owner_->showState();
2245 LyXText * lt = bv_->getLyXText();
2247 update(lt, BufferView::SELECT|BufferView::FITCUR);
2248 lt->cursorHome(bv_);
2250 moveCursorUpdate(true);
2251 owner_->showState();
2257 LyXText * lt = bv_->getLyXText();
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2262 moveCursorUpdate(true);
2263 owner_->showState();
2267 case LFUN_WORDRIGHTSEL:
2269 LyXText * lt = bv_->getLyXText();
2271 update(lt, BufferView::SELECT|BufferView::FITCUR);
2272 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2273 lt->cursorLeftOneWord(bv_);
2275 lt->cursorRightOneWord(bv_);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2282 case LFUN_WORDLEFTSEL:
2284 LyXText * lt = bv_->getLyXText();
2286 update(lt, BufferView::SELECT|BufferView::FITCUR);
2287 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2288 lt->cursorRightOneWord(bv_);
2290 lt->cursorLeftOneWord(bv_);
2292 moveCursorUpdate(true);
2293 owner_->showState();
2297 case LFUN_BEGINNINGBUFSEL:
2299 LyXText * lt = bv_->getLyXText();
2301 if (lt->inset_owner)
2303 update(lt, BufferView::SELECT|BufferView::FITCUR);
2306 moveCursorUpdate(true);
2307 owner_->showState();
2311 case LFUN_ENDBUFSEL:
2313 LyXText * lt = bv_->getLyXText();
2315 if (lt->inset_owner)
2318 BufferView::SELECT|BufferView::FITCUR);
2319 lt->cursorBottom(bv_);
2321 moveCursorUpdate(true);
2322 owner_->showState();
2326 // --- text changing commands ------------------------
2327 case LFUN_BREAKLINE:
2329 LyXText * lt = bv_->getLyXText();
2332 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2335 | BufferView::FITCUR
2336 | BufferView::CHANGE);
2337 moveCursorUpdate(false);
2341 case LFUN_PROTECTEDSPACE:
2343 LyXText * lt = bv_->getLyXText();
2345 LyXLayout const & style = textclasslist
2346 .Style(buffer_->params.textclass,
2347 lt->cursor.par()->getLayout());
2349 if (style.free_spacing) {
2350 lt->insertChar(bv_, ' ');
2353 | BufferView::FITCUR
2354 | BufferView::CHANGE);
2358 moveCursorUpdate(false);
2364 LyXText * lt = bv_->getLyXText();
2366 if (lt->selection.mark()) {
2370 | BufferView::FITCUR);
2371 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2374 lt->selection.mark(true);
2377 | BufferView::FITCUR);
2378 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2380 lt->selection.cursor = lt->cursor;
2386 LyXText * lt = bv_->getLyXText();
2388 if (!lt->selection.set()) {
2390 lt->selection.cursor = lt->cursor;
2393 | BufferView::FITCUR
2394 | BufferView::CHANGE);
2395 // It is possible to make it a lot faster still
2396 // just comment out the line below...
2401 moveCursorUpdate(false);
2402 owner_->showState();
2407 case LFUN_DELETE_SKIP:
2409 LyXText * lt = bv_->getLyXText();
2411 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2413 LyXCursor cursor = lt->cursor;
2415 if (!lt->selection.set()) {
2416 if (cursor.pos() == cursor.par()->size()) {
2417 lt->cursorRight(bv_);
2418 cursor = lt->cursor;
2419 if (cursor.pos() == 0
2420 && !(cursor.par()->params().spaceTop()
2421 == VSpace (VSpace::NONE))) {
2424 cursor.par()->params().lineTop(),
2425 cursor.par()->params().lineBottom(),
2426 cursor.par()->params().pagebreakTop(),
2427 cursor.par()->params().pagebreakBottom(),
2428 VSpace(VSpace::NONE),
2429 cursor.par()->params().spaceBottom(),
2430 cursor.par()->params().spacing(),
2431 cursor.par()->params().align(),
2432 cursor.par()->params().labelWidthString(), 0);
2433 lt->cursorLeft(bv_);
2436 | BufferView::FITCUR
2437 | BufferView::CHANGE);
2439 lt->cursorLeft(bv_);
2441 lt->selection.cursor = lt->cursor;
2444 | BufferView::FITCUR
2445 | BufferView::CHANGE);
2449 lt->selection.cursor = lt->cursor;
2452 | BufferView::FITCUR
2453 | BufferView::CHANGE);
2461 /* -------> Delete word forward. */
2462 case LFUN_DELETE_WORD_FORWARD:
2463 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2464 bv_->getLyXText()->deleteWordForward(bv_);
2465 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2466 moveCursorUpdate(false);
2467 owner_->showState();
2470 /* -------> Delete word backward. */
2471 case LFUN_DELETE_WORD_BACKWARD:
2473 LyXText * lt = bv_->getLyXText();
2475 update(lt, BufferView::SELECT|BufferView::FITCUR);
2476 lt->deleteWordBackward(bv_);
2479 | BufferView::FITCUR
2480 | BufferView::CHANGE);
2481 moveCursorUpdate(false);
2482 owner_->showState();
2486 /* -------> Kill to end of line. */
2487 case LFUN_DELETE_LINE_FORWARD:
2489 LyXText * lt = bv_->getLyXText();
2491 update(lt, BufferView::SELECT|BufferView::FITCUR);
2492 lt->deleteLineForward(bv_);
2495 | BufferView::FITCUR
2496 | BufferView::CHANGE);
2497 moveCursorUpdate(false);
2501 /* -------> Set mark off. */
2504 LyXText * lt = bv_->getLyXText();
2507 update(lt, BufferView::SELECT|BufferView::FITCUR);
2508 lt->selection.cursor = lt->cursor;
2509 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2513 /* -------> Set mark on. */
2516 LyXText * lt = bv_->getLyXText();
2519 lt->selection.mark(true);
2520 update(lt, BufferView::SELECT|BufferView::FITCUR);
2521 lt->selection.cursor = lt->cursor;
2522 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2526 case LFUN_BACKSPACE:
2528 LyXText * lt = bv_->getLyXText();
2530 if (!lt->selection.set()) {
2531 if (owner_->getIntl()->getTrans().backspace()) {
2533 lt->selection.cursor = lt->cursor;
2536 | BufferView::FITCUR
2537 | BufferView::CHANGE);
2538 // It is possible to make it a lot faster still
2539 // just comment out the line below...
2545 owner_->showState();
2550 case LFUN_BACKSPACE_SKIP:
2552 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2553 LyXText * lt = bv_->getLyXText();
2555 LyXCursor cursor = lt->cursor;
2557 if (!lt->selection.set()) {
2558 if (cursor.pos() == 0
2559 && !(cursor.par()->params().spaceTop()
2560 == VSpace (VSpace::NONE))) {
2563 cursor.par()->params().lineTop(),
2564 cursor.par()->params().lineBottom(),
2565 cursor.par()->params().pagebreakTop(),
2566 cursor.par()->params().pagebreakBottom(),
2567 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2568 cursor.par()->params().spacing(),
2569 cursor.par()->params().align(),
2570 cursor.par()->params().labelWidthString(), 0);
2573 | BufferView::FITCUR
2574 | BufferView::CHANGE);
2577 lt->selection.cursor = cursor;
2580 | BufferView::FITCUR
2581 | BufferView::CHANGE);
2588 case LFUN_BREAKPARAGRAPH:
2590 LyXText * lt = bv_->getLyXText();
2593 lt->breakParagraph(bv_, 0);
2596 | BufferView::FITCUR
2597 | BufferView::CHANGE);
2598 lt->selection.cursor = lt->cursor;
2600 owner_->showState();
2604 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2606 LyXText * lt = bv_->getLyXText();
2609 lt->breakParagraph(bv_, 1);
2612 | BufferView::FITCUR
2613 | BufferView::CHANGE);
2614 lt->selection.cursor = lt->cursor;
2616 owner_->showState();
2620 case LFUN_BREAKPARAGRAPH_SKIP:
2622 // When at the beginning of a paragraph, remove
2623 // indentation and add a "defskip" at the top.
2624 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2625 LyXText * lt = bv_->getLyXText();
2627 LyXCursor cursor = lt->cursor;
2630 if (cursor.pos() == 0) {
2631 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2634 cursor.par()->params().lineTop(),
2635 cursor.par()->params().lineBottom(),
2636 cursor.par()->params().pagebreakTop(),
2637 cursor.par()->params().pagebreakBottom(),
2638 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2639 cursor.par()->params().spacing(),
2640 cursor.par()->params().align(),
2641 cursor.par()->params().labelWidthString(), 1);
2642 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2646 lt->breakParagraph(bv_, 0);
2647 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2652 | BufferView::FITCUR
2653 | BufferView::CHANGE);
2654 lt->selection.cursor = cursor;
2656 owner_->showState();
2660 case LFUN_PARAGRAPH_SPACING:
2662 LyXText * lt = bv_->getLyXText();
2664 Paragraph * par = lt->cursor.par();
2665 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2666 float cur_value = 1.0;
2667 if (cur_spacing == Spacing::Other) {
2668 cur_value = par->params().spacing().getValue();
2671 istringstream istr(argument.c_str());
2675 Spacing::Space new_spacing = cur_spacing;
2676 float new_value = cur_value;
2678 lyxerr << "Missing argument to `paragraph-spacing'"
2680 } else if (tmp == "single") {
2681 new_spacing = Spacing::Single;
2682 } else if (tmp == "onehalf") {
2683 new_spacing = Spacing::Onehalf;
2684 } else if (tmp == "double") {
2685 new_spacing = Spacing::Double;
2686 } else if (tmp == "other") {
2687 new_spacing = Spacing::Other;
2690 lyxerr << "new_value = " << tmpval << endl;
2693 } else if (tmp == "default") {
2694 new_spacing = Spacing::Default;
2696 lyxerr << _("Unknown spacing argument: ")
2697 << argument << endl;
2699 if (cur_spacing != new_spacing || cur_value != new_value) {
2700 par->params().spacing(Spacing(new_spacing, new_value));
2701 lt->redoParagraph(bv_);
2704 | BufferView::FITCUR
2705 | BufferView::CHANGE);
2710 case LFUN_INSET_TOGGLE:
2712 LyXText * lt = bv_->getLyXText();
2715 update(lt, BufferView::SELECT|BufferView::FITCUR);
2716 lt->toggleInset(bv_);
2717 update(lt, BufferView::SELECT|BufferView::FITCUR);
2729 InsetCommandParams p;
2730 if (action == LFUN_HTMLURL)
2731 p.setCmdName("htmlurl");
2733 p.setCmdName("url");
2734 owner_->getDialogs()->createUrl(p.getAsString());
2738 case LFUN_INSERT_URL:
2740 InsetCommandParams p;
2741 p.setFromString(argument);
2743 InsetUrl * inset = new InsetUrl(p);
2744 if (!insertInset(inset))
2747 updateInset(inset, true);
2751 case LFUN_INSET_TEXT:
2752 insertAndEditInset(new InsetText);
2755 case LFUN_INSET_ERT:
2756 insertAndEditInset(new InsetERT);
2759 case LFUN_INSET_EXTERNAL:
2760 insertAndEditInset(new InsetExternal);
2763 case LFUN_INSET_FOOTNOTE:
2764 insertAndEditInset(new InsetFoot);
2767 case LFUN_INSET_MARGINAL:
2768 insertAndEditInset(new InsetMarginal);
2771 case LFUN_INSET_MINIPAGE:
2772 insertAndEditInset(new InsetMinipage);
2775 case LFUN_INSERT_NOTE:
2776 insertAndEditInset(new InsetNote);
2779 case LFUN_INSET_FLOAT:
2780 // check if the float type exist
2781 if (floatList.typeExist(argument)) {
2782 insertAndEditInset(new InsetFloat(argument));
2784 lyxerr << "Non-existent float type: "
2785 << argument << endl;
2789 case LFUN_INSET_WIDE_FLOAT:
2791 // check if the float type exist
2792 if (floatList.typeExist(argument)) {
2793 InsetFloat * new_inset = new InsetFloat(argument);
2794 new_inset->wide(true);
2795 if (insertInset(new_inset))
2796 new_inset->edit(bv_);
2800 lyxerr << "Non-existent float type: "
2801 << argument << endl;
2808 case LFUN_INSET_LIST:
2809 insertAndEditInset(new InsetList);
2812 case LFUN_INSET_THEOREM:
2813 insertAndEditInset(new InsetTheorem);
2817 case LFUN_INSET_CAPTION:
2819 // Do we have a locking inset...
2820 if (bv_->theLockingInset()) {
2821 lyxerr << "Locking inset code: "
2822 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2823 InsetCaption * new_inset = new InsetCaption;
2824 new_inset->setOwner(bv_->theLockingInset());
2825 new_inset->setAutoBreakRows(true);
2826 new_inset->setDrawFrame(0, InsetText::LOCKED);
2827 new_inset->setFrameColor(0, LColor::captionframe);
2828 if (insertInset(new_inset))
2829 new_inset->edit(bv_);
2836 case LFUN_INSET_TABULAR:
2840 if (!argument.empty())
2841 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2842 InsetTabular * new_inset =
2843 new InsetTabular(*buffer_, r, c);
2845 bv_->getLyXText()->real_current_font.isRightToLeft();
2846 if (!open_new_inset(new_inset, rtl))
2851 // --- lyxserver commands ----------------------------
2853 case LFUN_CHARATCURSOR:
2855 pos_type pos = bv_->getLyXText()->cursor.pos();
2856 if (pos < bv_->getLyXText()->cursor.par()->size())
2857 owner_->getLyXFunc()->setMessage(
2858 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2860 owner_->getLyXFunc()->setMessage("EOF");
2865 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2867 + tostr(bv_->getLyXText()->cursor.y()));
2874 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2875 lyxerr << "SETXY: Could not parse coordinates in '"
2876 << argument << std::endl;
2878 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2882 case LFUN_GETLAYOUT:
2883 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2888 LyXFont & font = bv_->getLyXText()->current_font;
2889 if (font.shape() == LyXFont::ITALIC_SHAPE)
2890 owner_->getLyXFunc()->setMessage("E");
2891 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2892 owner_->getLyXFunc()->setMessage("N");
2894 owner_->getLyXFunc()->setMessage("0");
2899 // --- accented characters ---------------------------
2902 case LFUN_CIRCUMFLEX:
2912 case LFUN_SPECIAL_CARON:
2915 case LFUN_HUNG_UMLAUT:
2918 if (argument.empty()) {
2920 owner_->getLyXFunc()->handleKeyFunc(action);
2922 owner_->getLyXFunc()->handleKeyFunc(action);
2923 owner_->getIntl()->getTrans()
2924 .TranslateAndInsert(argument[0], bv_->getLyXText());
2925 update(bv_->getLyXText(),
2927 | BufferView::FITCUR
2928 | BufferView::CHANGE);
2932 case LFUN_MATH_MACRO:
2933 mathDispatchMathMacro(bv_, argument);
2936 case LFUN_MATH_DELIM:
2937 mathDispatchMathDelim(bv_, argument);
2940 case LFUN_INSERT_MATRIX:
2941 mathDispatchInsertMatrix(bv_, argument);
2944 case LFUN_INSERT_MATH:
2945 mathDispatchInsertMath(bv_, argument);
2948 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2949 mathDispatchMathImportSelection(bv_, argument);
2952 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2953 mathDispatchMathDisplay(bv_, argument);
2956 case LFUN_MATH_MODE: // Open or create an inlined math inset
2957 mathDispatchMathMode(bv_, argument);
2960 case LFUN_GREEK: // Insert a single greek letter
2961 mathDispatchGreek(bv_, argument);
2964 case LFUN_CITATION_INSERT:
2966 InsetCommandParams p;
2967 p.setFromString(argument);
2969 InsetCitation * inset = new InsetCitation(p);
2970 if (!insertInset(inset))
2973 updateInset(inset, true);
2977 case LFUN_INSERT_BIBTEX:
2979 // ale970405+lasgoutt970425
2980 // The argument can be up to two tokens separated
2981 // by a space. The first one is the bibstyle.
2982 string const db = token(argument, ' ', 0);
2983 string const bibstyle = token(argument, ' ', 1);
2985 InsetCommandParams p("BibTeX", db, bibstyle);
2986 InsetBibtex * inset = new InsetBibtex(p);
2988 if (insertInset(inset)) {
2989 if (argument.empty())
2996 // BibTeX data bases
2997 case LFUN_BIBDB_ADD:
2999 InsetBibtex * inset =
3000 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3002 inset->addDatabase(argument);
3007 case LFUN_BIBDB_DEL:
3009 InsetBibtex * inset =
3010 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3012 inset->delDatabase(argument);
3017 case LFUN_BIBTEX_STYLE:
3019 InsetBibtex * inset =
3020 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3022 inset->setOptions(argument);
3027 case LFUN_INDEX_CREATE:
3029 InsetCommandParams p("index");
3030 if (argument.empty()) {
3031 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3032 p.setContents(idxstring);
3034 p.setContents(argument);
3037 owner_->getDialogs()->createIndex(p.getAsString());
3041 case LFUN_INDEX_INSERT:
3043 InsetCommandParams p;
3044 p.setFromString(argument);
3045 InsetIndex * inset = new InsetIndex(p);
3047 if (!insertInset(inset))
3050 updateInset(inset, true);
3054 case LFUN_INDEX_INSERT_LAST:
3056 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3057 if (!idxstring.empty()) {
3058 owner_->message(_("Word `")
3059 + idxstring + _(("' indexed.")));
3060 InsetCommandParams p("index", idxstring);
3061 InsetIndex * inset = new InsetIndex(p);
3063 if (!insertInset(inset))
3066 updateInset(inset, true);
3071 case LFUN_INDEX_PRINT:
3073 InsetCommandParams p("printindex");
3074 Inset * inset = new InsetPrintIndex(p);
3075 if (!insertInset(inset, "Standard"))
3080 case LFUN_PARENTINSERT:
3082 lyxerr << "arg " << argument << endl;
3083 InsetCommandParams p("lyxparent", argument);
3084 Inset * inset = new InsetParent(p, *buffer_);
3085 if (!insertInset(inset, "Standard"))
3091 case LFUN_CHILD_INSERT:
3093 InsetInclude::Params p;
3094 p.cparams.setFromString(argument);
3095 p.masterFilename_ = buffer_->fileName();
3097 InsetInclude * inset = new InsetInclude(p);
3098 if (!insertInset(inset))
3101 updateInset(inset, true);
3102 bv_->owner()->getDialogs()->showInclude(inset);
3107 case LFUN_FLOAT_LIST:
3109 // We should check the argument for validity. (Lgb)
3110 Inset * inset = new InsetFloatList(argument);
3111 if (!insertInset(inset, "Standard"))
3116 case LFUN_THESAURUS_ENTRY:
3118 string arg = argument;
3121 arg = bv_->getLyXText()->selectionAsString(buffer_,
3125 if (arg.size() > 100 || arg.empty()) {
3126 // Get word or selection
3127 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3128 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3129 // FIXME: where is getLyXText()->unselect(bv_) ?
3133 bv_->owner()->getDialogs()->showThesaurus(arg);
3137 case LFUN_SELFINSERT:
3139 if (argument.empty()) break;
3141 /* Automatically delete the currently selected
3142 * text and replace it with what is being
3143 * typed in now. Depends on lyxrc settings
3144 * "auto_region_delete", which defaults to
3147 LyXText * lt = bv_->getLyXText();
3149 if (lyxrc.auto_region_delete) {
3150 if (lt->selection.set()) {
3151 lt->cutSelection(bv_, false, false);
3154 | BufferView::FITCUR
3155 | BufferView::CHANGE);
3160 LyXFont const old_font(lt->real_current_font);
3162 string::const_iterator cit = argument.begin();
3163 string::const_iterator end = argument.end();
3164 for (; cit != end; ++cit) {
3165 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3170 | BufferView::FITCUR
3171 | BufferView::CHANGE);
3173 lt->selection.cursor = lt->cursor;
3174 moveCursorUpdate(false);
3176 // real_current_font.number can change so we need to
3177 // update the minibuffer
3178 if (old_font != lt->real_current_font)
3179 owner_->showState();
3184 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3186 time_t now_time_t = time(NULL);
3187 struct tm * now_tm = localtime(&now_time_t);
3188 setlocale(LC_TIME, "");
3190 if (!argument.empty())
3193 arg = lyxrc.date_insert_format;
3195 int const datetmp_len =
3196 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3198 LyXText * lt = bv_->getLyXText();
3200 for (int i = 0; i < datetmp_len; i++) {
3201 lt->insertChar(bv_, datetmp[i]);
3204 | BufferView::FITCUR
3205 | BufferView::CHANGE);
3208 lt->selection.cursor = lt->cursor;
3209 moveCursorUpdate(false);
3213 case LFUN_UNKNOWN_ACTION:
3214 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3225 void BufferView::Pimpl::newline()
3228 LyXText * lt = bv_->getLyXText();
3232 | BufferView::FITCUR);
3233 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3236 | BufferView::FITCUR
3237 | BufferView::CHANGE);
3242 void BufferView::Pimpl::hfill()
3245 LyXText * lt = bv_->getLyXText();
3249 | BufferView::FITCUR);
3250 lt->insertChar(bv_, Paragraph::META_HFILL);
3253 | BufferView::FITCUR
3254 | BufferView::CHANGE);
3259 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3263 update(lt, BufferView::SELECT|BufferView::FITCUR);
3264 InsetSpecialChar * new_inset =
3265 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3266 #ifdef WITH_WARNINGS
3267 #warning Why is this code different from specialChar() below? (JMarc)
3268 // the code in specialChar is a generic version of what used to exist
3269 // for other special chars. I did not merge this case because of the
3270 // call to updateInset(), but what does it do?
3272 if (!insertInset(new_inset))
3275 updateInset(new_inset, true);
3280 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3283 LyXText * lt = bv_->getLyXText();
3286 update(lt, BufferView::SELECT|BufferView::FITCUR);
3287 InsetSpecialChar * new_inset =
3288 new InsetSpecialChar(kind);
3289 if (!insertInset(new_inset))
3295 void BufferView::Pimpl::smartQuote()
3297 LyXText const * lt = bv_->getLyXText();
3298 Paragraph const * par = lt->cursor.par();
3299 pos_type pos = lt->cursor.pos();
3303 || (par->isInset(pos - 1)
3304 && par->getInset(pos - 1)->isSpace()))
3307 c = par->getChar(pos - 1);
3312 LyXLayout const & style = textclasslist.Style(
3313 bv_->buffer()->params.textclass, par->getLayout());
3315 if (style.pass_thru ||
3316 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3317 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3321 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3323 if (insertInset(inset))
3330 // Open and lock an updatable inset
3331 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3333 LyXText * lt = bv_->getLyXText();
3337 if (!insertInset(new_inset)) {
3341 new_inset->edit(bv_, !behind);
3346 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3348 // if we are in a locking inset we should try to insert the
3349 // inset there otherwise this is a illegal function now
3350 if (bv_->theLockingInset()) {
3351 if (bv_->theLockingInset()->insetAllowed(inset))
3352 return bv_->theLockingInset()->insertInset(bv_, inset);
3356 // not quite sure if we want this...
3357 setCursorParUndo(bv_);
3360 beforeChange(bv_->text);
3361 if (!lout.empty()) {
3362 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3363 bv_->text->breakParagraph(bv_);
3364 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3366 if (bv_->text->cursor.par()->size()) {
3367 bv_->text->cursorLeft(bv_);
3369 bv_->text->breakParagraph(bv_);
3370 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3373 pair<bool, layout_type> lres =
3374 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3375 layout_type lay = 0;
3376 if (lres.first != false) {
3380 // layout not fount using default "Standard" (0)
3384 bv_->text->setLayout(bv_, lay);
3386 bv_->text->setParagraph(bv_, 0, 0,
3388 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3393 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3396 bv_->text->insertInset(bv_, inset);
3397 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3404 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3409 // first check for locking insets
3410 if (bv_->theLockingInset()) {
3411 if (bv_->theLockingInset() == inset) {
3412 if (bv_->text->updateInset(bv_, inset)) {
3415 buffer_->markDirty();
3420 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3421 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3424 buffer_->markDirty();
3432 // then check the current buffer
3435 update(bv_->text, BufferView::UPDATE);
3436 if (bv_->text->updateInset(bv_, inset)) {
3440 | BufferView::FITCUR
3441 | BufferView::CHANGE);
3443 update(bv_->text, SELECT);
3451 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3454 if (!available()) return;
3457 beforeChange(bv_->text);
3458 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3460 LyXCursor const & cursor = bv_->text->cursor;
3464 cursor.par()->isInset(cursor.pos())) {
3465 Inset const * inset = cursor.par()->getInset(cursor.pos());
3466 if (find(codes.begin(), codes.end(), inset->lyxCode())
3469 static_cast<InsetCommand const *>(inset)->getContents();
3473 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3474 if (bv_->text->cursor.pos()
3475 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3476 LyXCursor tmp = bv_->text->cursor;
3477 bv_->text->cursor.par(bv_->text->ownerParagraph());
3478 bv_->text->cursor.pos(0);
3479 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3480 bv_->text->cursor = tmp;
3481 bv_->owner()->message(_("No more insets"));
3484 bv_->owner()->message(_("No more insets"));
3487 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3488 bv_->text->selection.cursor = bv_->text->cursor;
3492 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3494 gotoInset(vector<Inset::Code>(1, code), same_content);