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_SCROLL_INSET:
1546 // this is not handled here as this funktion is only aktive
1547 // if we have a locking_inset and that one is (or contains)
1551 case LFUN_INSET_GRAPHICS:
1553 Inset * new_inset = new InsetGraphics;
1554 if (!insertInset(new_inset)) {
1557 // this is need because you don't use a inset->Edit()
1558 updateInset(new_inset, true);
1559 new_inset->edit(bv_);
1569 case LFUN_PASTESELECTION:
1571 bool asPara = false;
1572 if (argument == "paragraph")
1574 pasteClipboard(asPara);
1586 case LFUN_LAYOUT_COPY:
1587 bv_->copyEnvironment();
1590 case LFUN_LAYOUT_PASTE:
1591 bv_->pasteEnvironment();
1595 case LFUN_GOTOERROR:
1596 gotoInset(Inset::ERROR_CODE, false);
1600 gotoInset(Inset::IGNORE_CODE, false);
1603 case LFUN_REFERENCE_GOTO:
1605 vector<Inset::Code> tmp;
1606 tmp.push_back(Inset::LABEL_CODE);
1607 tmp.push_back(Inset::REF_CODE);
1608 gotoInset(tmp, true);
1612 case LFUN_HYPHENATION:
1613 specialChar(InsetSpecialChar::HYPHENATION);
1616 case LFUN_LIGATURE_BREAK:
1617 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1621 specialChar(InsetSpecialChar::LDOTS);
1624 case LFUN_END_OF_SENTENCE:
1625 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1628 case LFUN_MENU_SEPARATOR:
1629 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1637 changeDepth(bv_, bv_->getLyXText(), 0);
1640 case LFUN_DEPTH_MIN:
1641 changeDepth(bv_, bv_->getLyXText(), -1);
1644 case LFUN_DEPTH_PLUS:
1645 changeDepth(bv_, bv_->getLyXText(), 1);
1649 owner_->getDialogs()->setUserFreeFont();
1652 case LFUN_FILE_INSERT:
1653 MenuInsertLyXFile(argument);
1656 case LFUN_FILE_INSERT_ASCII_PARA:
1657 InsertAsciiFile(bv_, argument, true);
1660 case LFUN_FILE_INSERT_ASCII:
1661 InsertAsciiFile(bv_, argument, false);
1666 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1667 << argument << endl;
1669 // Derive layout number from given argument (string)
1670 // and current buffer's textclass (number). */
1671 textclass_type tclass = buffer_->params.textclass;
1672 pair <bool, layout_type> layout =
1673 textclasslist.NumberOfLayout(tclass, argument);
1675 // If the entry is obsolete, use the new one instead.
1677 string obs = textclasslist.Style(tclass, layout.second)
1680 layout = textclasslist.NumberOfLayout(tclass, obs);
1683 // see if we found the layout number:
1684 if (!layout.first) {
1685 owner_->getLyXFunc()->setErrorMessage(
1686 string(N_("Layout ")) + argument +
1691 if (current_layout != layout.second) {
1692 LyXText * lt = bv_->getLyXText();
1694 current_layout = layout.second;
1697 | BufferView::FITCUR);
1698 lt->setLayout(bv_, layout.second);
1699 owner_->setLayout(layout.second);
1702 | BufferView::FITCUR
1703 | BufferView::CHANGE);
1710 lang(bv_, argument);
1712 owner_->showState();
1717 owner_->showState();
1722 owner_->showState();
1727 owner_->showState();
1732 owner_->showState();
1737 owner_->showState();
1742 owner_->showState();
1747 owner_->showState();
1750 case LFUN_UNDERLINE:
1752 owner_->showState();
1755 case LFUN_FONT_SIZE:
1756 fontSize(bv_, argument);
1757 owner_->showState();
1760 case LFUN_FONT_STATE:
1761 owner_->getLyXFunc()->setMessage(currentState(bv_));
1764 case LFUN_UPCASE_WORD:
1766 LyXText * lt = bv_->getLyXText();
1770 | BufferView::FITCUR);
1771 lt->changeCase(bv_, LyXText::text_uppercase);
1772 if (lt->inset_owner)
1773 updateInset(lt->inset_owner, true);
1776 | BufferView::FITCUR
1777 | BufferView::CHANGE);
1781 case LFUN_LOWCASE_WORD:
1783 LyXText * lt = bv_->getLyXText();
1785 update(lt, BufferView::SELECT|BufferView::FITCUR);
1786 lt->changeCase(bv_, LyXText::text_lowercase);
1787 if (lt->inset_owner)
1788 updateInset(lt->inset_owner, true);
1791 | BufferView::FITCUR
1792 | BufferView::CHANGE);
1796 case LFUN_CAPITALIZE_WORD:
1798 LyXText * lt = bv_->getLyXText();
1800 update(lt, BufferView::SELECT|BufferView::FITCUR);
1801 lt->changeCase(bv_, LyXText::text_capitalization);
1802 if (lt->inset_owner)
1803 updateInset(lt->inset_owner, true);
1806 | BufferView::FITCUR
1807 | BufferView::CHANGE);
1811 case LFUN_TRANSPOSE_CHARS:
1813 LyXText * lt = bv_->getLyXText();
1815 update(lt, BufferView::SELECT|BufferView::FITCUR);
1816 lt->transposeChars(*bv_);
1817 if (lt->inset_owner)
1818 updateInset(lt->inset_owner, true);
1821 | BufferView::FITCUR
1822 | BufferView::CHANGE);
1827 case LFUN_INSERT_LABEL:
1828 MenuInsertLabel(bv_, argument);
1831 case LFUN_REF_INSERT:
1832 if (argument.empty()) {
1833 InsetCommandParams p("ref");
1834 owner_->getDialogs()->createRef(p.getAsString());
1836 InsetCommandParams p;
1837 p.setFromString(argument);
1839 InsetRef * inset = new InsetRef(p, *buffer_);
1840 if (!insertInset(inset))
1843 updateInset(inset, true);
1847 case LFUN_BOOKMARK_SAVE:
1848 savePosition(strToUnsignedInt(argument));
1851 case LFUN_BOOKMARK_GOTO:
1852 restorePosition(strToUnsignedInt(argument));
1857 string label(argument);
1858 if (label.empty()) {
1860 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1862 label = inset->getContents();
1867 if (!label.empty()) {
1868 //bv_->savePosition(0);
1869 if (!bv_->gotoLabel(label))
1870 Alert::alert(_("Error"),
1871 _("Couldn't find this label"),
1872 _("in current document."));
1877 // --- Cursor Movements -----------------------------
1880 LyXText * lt = bv_->getLyXText();
1882 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1883 if (!lt->selection.mark())
1885 update(lt, BufferView::SELECT|BufferView::FITCUR);
1887 lt->cursorLeft(bv_, false);
1888 if (lt->cursor.pos() < lt->cursor.par()->size()
1889 && lt->cursor.par()->isInset(lt->cursor.pos())
1890 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1891 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1892 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1894 tmpinset->edit(bv_, false);
1896 tmpinset->edit(bv_);
1900 lt->cursorRight(bv_, false);
1902 moveCursorUpdate(false);
1903 owner_->showState();
1909 // This is soooo ugly. Isn`t it possible to make
1910 // it simpler? (Lgb)
1911 LyXText * lt = bv_->getLyXText();
1912 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1913 if (!lt->selection.mark())
1915 update(lt, BufferView::SELECT|BufferView::FITCUR);
1916 LyXCursor const cur = lt->cursor;
1918 lt->cursorLeft(bv_, false);
1919 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1920 lt->cursor.pos() < lt->cursor.par()->size() &&
1921 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1922 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1923 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1924 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1926 tmpinset->edit(bv_);
1928 tmpinset->edit(bv_, false);
1932 lt->cursorRight(bv_, false);
1935 moveCursorUpdate(false);
1936 owner_->showState();
1942 LyXText * lt = bv_->getLyXText();
1944 if (!lt->selection.mark())
1946 update(lt, BufferView::UPDATE);
1949 moveCursorUpdate(false);
1950 owner_->showState();
1956 LyXText * lt = bv_->getLyXText();
1958 if (!lt->selection.mark())
1960 update(lt, BufferView::UPDATE);
1961 lt->cursorDown(bv_);
1963 moveCursorUpdate(false);
1964 owner_->showState();
1968 case LFUN_UP_PARAGRAPH:
1970 LyXText * lt = bv_->getLyXText();
1972 if (!lt->selection.mark())
1974 update(lt, BufferView::UPDATE);
1975 lt->cursorUpParagraph(bv_);
1977 moveCursorUpdate(false);
1978 owner_->showState();
1982 case LFUN_DOWN_PARAGRAPH:
1984 LyXText * lt = bv_->getLyXText();
1986 if (!lt->selection.mark())
1988 update(lt, BufferView::UPDATE);
1989 lt->cursorDownParagraph(bv_);
1991 moveCursorUpdate(false);
1992 owner_->showState();
1998 LyXText * lt = bv_->getLyXText();
2000 if (!lt->selection.mark())
2002 update(lt, BufferView::UPDATE);
2005 moveCursorUpdate(false);
2006 owner_->showState();
2012 LyXText * lt = bv_->getLyXText();
2014 if (!lt->selection.mark())
2016 update(lt, BufferView::UPDATE);
2019 moveCursorUpdate(false);
2020 owner_->showState();
2026 LyXText * lt = bv_->getLyXText();
2028 if (!lt->selection.mark())
2030 update(lt, BufferView::SELECT|BufferView::FITCUR);
2031 lt->cursorHome(bv_);
2033 moveCursorUpdate(false);
2034 owner_->showState();
2040 LyXText * lt = bv_->getLyXText();
2042 if (!lt->selection.mark())
2045 BufferView::SELECT|BufferView::FITCUR);
2048 moveCursorUpdate(false);
2049 owner_->showState();
2053 case LFUN_SHIFT_TAB:
2056 LyXText * lt = bv_->getLyXText();
2058 if (!lt->selection.mark())
2061 BufferView::SELECT|BufferView::FITCUR);
2064 moveCursorUpdate(false);
2065 owner_->showState();
2069 case LFUN_WORDRIGHT:
2071 LyXText * lt = bv_->getLyXText();
2073 if (!lt->selection.mark())
2075 update(lt, BufferView::SELECT|BufferView::FITCUR);
2076 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2077 lt->cursorLeftOneWord(bv_);
2079 lt->cursorRightOneWord(bv_);
2081 moveCursorUpdate(false);
2082 owner_->showState();
2088 LyXText * lt = bv_->getLyXText();
2090 if (!lt->selection.mark())
2092 update(lt, BufferView::SELECT|BufferView::FITCUR);
2093 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2094 lt->cursorRightOneWord(bv_);
2096 lt->cursorLeftOneWord(bv_);
2098 moveCursorUpdate(false);
2099 owner_->showState();
2103 case LFUN_BEGINNINGBUF:
2105 LyXText * lt = bv_->getLyXText();
2107 if (!lt->selection.mark())
2110 BufferView::SELECT|BufferView::FITCUR);
2113 moveCursorUpdate(false);
2114 owner_->showState();
2120 LyXText * lt = bv_->getLyXText();
2122 if (!lt->selection.mark())
2125 BufferView::SELECT|BufferView::FITCUR);
2126 lt->cursorBottom(bv_);
2128 moveCursorUpdate(false);
2129 owner_->showState();
2133 /* cursor selection ---------------------------- */
2136 LyXText * lt = bv_->getLyXText();
2139 BufferView::SELECT|BufferView::FITCUR);
2140 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2141 lt->cursorLeft(bv_);
2143 lt->cursorRight(bv_);
2145 moveCursorUpdate(true);
2146 owner_->showState();
2152 LyXText * lt = bv_->getLyXText();
2155 BufferView::SELECT|BufferView::FITCUR);
2156 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2157 lt->cursorRight(bv_);
2159 lt->cursorLeft(bv_);
2161 moveCursorUpdate(true);
2162 owner_->showState();
2168 LyXText * lt = bv_->getLyXText();
2171 BufferView::SELECT|BufferView::FITCUR);
2174 moveCursorUpdate(true);
2175 owner_->showState();
2181 LyXText * lt = bv_->getLyXText();
2184 BufferView::SELECT|BufferView::FITCUR);
2185 lt->cursorDown(bv_);
2187 moveCursorUpdate(true);
2188 owner_->showState();
2192 case LFUN_UP_PARAGRAPHSEL:
2194 LyXText * lt = bv_->getLyXText();
2197 BufferView::SELECT|BufferView::FITCUR);
2198 lt->cursorUpParagraph(bv_);
2200 moveCursorUpdate(true);
2201 owner_->showState();
2205 case LFUN_DOWN_PARAGRAPHSEL:
2207 LyXText * lt = bv_->getLyXText();
2210 BufferView::SELECT|BufferView::FITCUR);
2211 lt->cursorDownParagraph(bv_);
2213 moveCursorUpdate(true);
2214 owner_->showState();
2220 LyXText * lt = bv_->getLyXText();
2222 update(lt, BufferView::SELECT|BufferView::FITCUR);
2225 moveCursorUpdate(true);
2226 owner_->showState();
2232 LyXText * lt = bv_->getLyXText();
2234 update(lt, BufferView::SELECT|BufferView::FITCUR);
2237 moveCursorUpdate(true);
2238 owner_->showState();
2244 LyXText * lt = bv_->getLyXText();
2246 update(lt, BufferView::SELECT|BufferView::FITCUR);
2247 lt->cursorHome(bv_);
2249 moveCursorUpdate(true);
2250 owner_->showState();
2256 LyXText * lt = bv_->getLyXText();
2258 update(lt, BufferView::SELECT|BufferView::FITCUR);
2261 moveCursorUpdate(true);
2262 owner_->showState();
2266 case LFUN_WORDRIGHTSEL:
2268 LyXText * lt = bv_->getLyXText();
2270 update(lt, BufferView::SELECT|BufferView::FITCUR);
2271 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2272 lt->cursorLeftOneWord(bv_);
2274 lt->cursorRightOneWord(bv_);
2276 moveCursorUpdate(true);
2277 owner_->showState();
2281 case LFUN_WORDLEFTSEL:
2283 LyXText * lt = bv_->getLyXText();
2285 update(lt, BufferView::SELECT|BufferView::FITCUR);
2286 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2287 lt->cursorRightOneWord(bv_);
2289 lt->cursorLeftOneWord(bv_);
2291 moveCursorUpdate(true);
2292 owner_->showState();
2296 case LFUN_BEGINNINGBUFSEL:
2298 LyXText * lt = bv_->getLyXText();
2300 if (lt->inset_owner)
2302 update(lt, BufferView::SELECT|BufferView::FITCUR);
2305 moveCursorUpdate(true);
2306 owner_->showState();
2310 case LFUN_ENDBUFSEL:
2312 LyXText * lt = bv_->getLyXText();
2314 if (lt->inset_owner)
2317 BufferView::SELECT|BufferView::FITCUR);
2318 lt->cursorBottom(bv_);
2320 moveCursorUpdate(true);
2321 owner_->showState();
2325 // --- text changing commands ------------------------
2326 case LFUN_BREAKLINE:
2328 LyXText * lt = bv_->getLyXText();
2331 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2334 | BufferView::FITCUR
2335 | BufferView::CHANGE);
2336 moveCursorUpdate(false);
2340 case LFUN_PROTECTEDSPACE:
2342 LyXText * lt = bv_->getLyXText();
2344 LyXLayout const & style = textclasslist
2345 .Style(buffer_->params.textclass,
2346 lt->cursor.par()->getLayout());
2348 if (style.free_spacing) {
2349 lt->insertChar(bv_, ' ');
2352 | BufferView::FITCUR
2353 | BufferView::CHANGE);
2357 moveCursorUpdate(false);
2363 LyXText * lt = bv_->getLyXText();
2365 if (lt->selection.mark()) {
2369 | BufferView::FITCUR);
2370 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2373 lt->selection.mark(true);
2376 | BufferView::FITCUR);
2377 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2379 lt->selection.cursor = lt->cursor;
2385 LyXText * lt = bv_->getLyXText();
2387 if (!lt->selection.set()) {
2389 lt->selection.cursor = lt->cursor;
2392 | BufferView::FITCUR
2393 | BufferView::CHANGE);
2394 // It is possible to make it a lot faster still
2395 // just comment out the line below...
2400 moveCursorUpdate(false);
2401 owner_->showState();
2406 case LFUN_DELETE_SKIP:
2408 LyXText * lt = bv_->getLyXText();
2410 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2412 LyXCursor cursor = lt->cursor;
2414 if (!lt->selection.set()) {
2415 if (cursor.pos() == cursor.par()->size()) {
2416 lt->cursorRight(bv_);
2417 cursor = lt->cursor;
2418 if (cursor.pos() == 0
2419 && !(cursor.par()->params().spaceTop()
2420 == VSpace (VSpace::NONE))) {
2423 cursor.par()->params().lineTop(),
2424 cursor.par()->params().lineBottom(),
2425 cursor.par()->params().pagebreakTop(),
2426 cursor.par()->params().pagebreakBottom(),
2427 VSpace(VSpace::NONE),
2428 cursor.par()->params().spaceBottom(),
2429 cursor.par()->params().spacing(),
2430 cursor.par()->params().align(),
2431 cursor.par()->params().labelWidthString(), 0);
2432 lt->cursorLeft(bv_);
2435 | BufferView::FITCUR
2436 | BufferView::CHANGE);
2438 lt->cursorLeft(bv_);
2440 lt->selection.cursor = lt->cursor;
2443 | BufferView::FITCUR
2444 | BufferView::CHANGE);
2448 lt->selection.cursor = lt->cursor;
2451 | BufferView::FITCUR
2452 | BufferView::CHANGE);
2460 /* -------> Delete word forward. */
2461 case LFUN_DELETE_WORD_FORWARD:
2462 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2463 bv_->getLyXText()->deleteWordForward(bv_);
2464 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2465 moveCursorUpdate(false);
2466 owner_->showState();
2469 /* -------> Delete word backward. */
2470 case LFUN_DELETE_WORD_BACKWARD:
2472 LyXText * lt = bv_->getLyXText();
2474 update(lt, BufferView::SELECT|BufferView::FITCUR);
2475 lt->deleteWordBackward(bv_);
2478 | BufferView::FITCUR
2479 | BufferView::CHANGE);
2480 moveCursorUpdate(false);
2481 owner_->showState();
2485 /* -------> Kill to end of line. */
2486 case LFUN_DELETE_LINE_FORWARD:
2488 LyXText * lt = bv_->getLyXText();
2490 update(lt, BufferView::SELECT|BufferView::FITCUR);
2491 lt->deleteLineForward(bv_);
2494 | BufferView::FITCUR
2495 | BufferView::CHANGE);
2496 moveCursorUpdate(false);
2500 /* -------> Set mark off. */
2503 LyXText * lt = bv_->getLyXText();
2506 update(lt, BufferView::SELECT|BufferView::FITCUR);
2507 lt->selection.cursor = lt->cursor;
2508 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2512 /* -------> Set mark on. */
2515 LyXText * lt = bv_->getLyXText();
2518 lt->selection.mark(true);
2519 update(lt, BufferView::SELECT|BufferView::FITCUR);
2520 lt->selection.cursor = lt->cursor;
2521 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2525 case LFUN_BACKSPACE:
2527 LyXText * lt = bv_->getLyXText();
2529 if (!lt->selection.set()) {
2530 if (owner_->getIntl()->getTrans().backspace()) {
2532 lt->selection.cursor = lt->cursor;
2535 | BufferView::FITCUR
2536 | BufferView::CHANGE);
2537 // It is possible to make it a lot faster still
2538 // just comment out the line below...
2544 owner_->showState();
2549 case LFUN_BACKSPACE_SKIP:
2551 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2552 LyXText * lt = bv_->getLyXText();
2554 LyXCursor cursor = lt->cursor;
2556 if (!lt->selection.set()) {
2557 if (cursor.pos() == 0
2558 && !(cursor.par()->params().spaceTop()
2559 == VSpace (VSpace::NONE))) {
2562 cursor.par()->params().lineTop(),
2563 cursor.par()->params().lineBottom(),
2564 cursor.par()->params().pagebreakTop(),
2565 cursor.par()->params().pagebreakBottom(),
2566 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2567 cursor.par()->params().spacing(),
2568 cursor.par()->params().align(),
2569 cursor.par()->params().labelWidthString(), 0);
2572 | BufferView::FITCUR
2573 | BufferView::CHANGE);
2576 lt->selection.cursor = cursor;
2579 | BufferView::FITCUR
2580 | BufferView::CHANGE);
2587 case LFUN_BREAKPARAGRAPH:
2589 LyXText * lt = bv_->getLyXText();
2592 lt->breakParagraph(bv_, 0);
2595 | BufferView::FITCUR
2596 | BufferView::CHANGE);
2597 lt->selection.cursor = lt->cursor;
2599 owner_->showState();
2603 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2605 LyXText * lt = bv_->getLyXText();
2608 lt->breakParagraph(bv_, 1);
2611 | BufferView::FITCUR
2612 | BufferView::CHANGE);
2613 lt->selection.cursor = lt->cursor;
2615 owner_->showState();
2619 case LFUN_BREAKPARAGRAPH_SKIP:
2621 // When at the beginning of a paragraph, remove
2622 // indentation and add a "defskip" at the top.
2623 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2624 LyXText * lt = bv_->getLyXText();
2626 LyXCursor cursor = lt->cursor;
2629 if (cursor.pos() == 0) {
2630 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2633 cursor.par()->params().lineTop(),
2634 cursor.par()->params().lineBottom(),
2635 cursor.par()->params().pagebreakTop(),
2636 cursor.par()->params().pagebreakBottom(),
2637 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2638 cursor.par()->params().spacing(),
2639 cursor.par()->params().align(),
2640 cursor.par()->params().labelWidthString(), 1);
2641 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2645 lt->breakParagraph(bv_, 0);
2646 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2651 | BufferView::FITCUR
2652 | BufferView::CHANGE);
2653 lt->selection.cursor = cursor;
2655 owner_->showState();
2659 case LFUN_PARAGRAPH_SPACING:
2661 LyXText * lt = bv_->getLyXText();
2663 Paragraph * par = lt->cursor.par();
2664 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2665 float cur_value = 1.0;
2666 if (cur_spacing == Spacing::Other) {
2667 cur_value = par->params().spacing().getValue();
2670 istringstream istr(argument.c_str());
2674 Spacing::Space new_spacing = cur_spacing;
2675 float new_value = cur_value;
2677 lyxerr << "Missing argument to `paragraph-spacing'"
2679 } else if (tmp == "single") {
2680 new_spacing = Spacing::Single;
2681 } else if (tmp == "onehalf") {
2682 new_spacing = Spacing::Onehalf;
2683 } else if (tmp == "double") {
2684 new_spacing = Spacing::Double;
2685 } else if (tmp == "other") {
2686 new_spacing = Spacing::Other;
2689 lyxerr << "new_value = " << tmpval << endl;
2692 } else if (tmp == "default") {
2693 new_spacing = Spacing::Default;
2695 lyxerr << _("Unknown spacing argument: ")
2696 << argument << endl;
2698 if (cur_spacing != new_spacing || cur_value != new_value) {
2699 par->params().spacing(Spacing(new_spacing, new_value));
2700 lt->redoParagraph(bv_);
2703 | BufferView::FITCUR
2704 | BufferView::CHANGE);
2709 case LFUN_INSET_TOGGLE:
2711 LyXText * lt = bv_->getLyXText();
2714 update(lt, BufferView::SELECT|BufferView::FITCUR);
2715 lt->toggleInset(bv_);
2716 update(lt, BufferView::SELECT|BufferView::FITCUR);
2728 InsetCommandParams p;
2729 if (action == LFUN_HTMLURL)
2730 p.setCmdName("htmlurl");
2732 p.setCmdName("url");
2733 owner_->getDialogs()->createUrl(p.getAsString());
2737 case LFUN_INSERT_URL:
2739 InsetCommandParams p;
2740 p.setFromString(argument);
2742 InsetUrl * inset = new InsetUrl(p);
2743 if (!insertInset(inset))
2746 updateInset(inset, true);
2750 case LFUN_INSET_TEXT:
2751 insertAndEditInset(new InsetText);
2754 case LFUN_INSET_ERT:
2755 insertAndEditInset(new InsetERT);
2758 case LFUN_INSET_EXTERNAL:
2759 insertAndEditInset(new InsetExternal);
2762 case LFUN_INSET_FOOTNOTE:
2763 insertAndEditInset(new InsetFoot);
2766 case LFUN_INSET_MARGINAL:
2767 insertAndEditInset(new InsetMarginal);
2770 case LFUN_INSET_MINIPAGE:
2771 insertAndEditInset(new InsetMinipage);
2774 case LFUN_INSERT_NOTE:
2775 insertAndEditInset(new InsetNote);
2778 case LFUN_INSET_FLOAT:
2779 // check if the float type exist
2780 if (floatList.typeExist(argument)) {
2781 insertAndEditInset(new InsetFloat(argument));
2783 lyxerr << "Non-existent float type: "
2784 << argument << endl;
2788 case LFUN_INSET_WIDE_FLOAT:
2790 // check if the float type exist
2791 if (floatList.typeExist(argument)) {
2792 InsetFloat * new_inset = new InsetFloat(argument);
2793 new_inset->wide(true);
2794 if (insertInset(new_inset))
2795 new_inset->edit(bv_);
2799 lyxerr << "Non-existent float type: "
2800 << argument << endl;
2807 case LFUN_INSET_LIST:
2808 insertAndEditInset(new InsetList);
2811 case LFUN_INSET_THEOREM:
2812 insertAndEditInset(new InsetTheorem);
2816 case LFUN_INSET_CAPTION:
2818 // Do we have a locking inset...
2819 if (bv_->theLockingInset()) {
2820 lyxerr << "Locking inset code: "
2821 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2822 InsetCaption * new_inset = new InsetCaption;
2823 new_inset->setOwner(bv_->theLockingInset());
2824 new_inset->setAutoBreakRows(true);
2825 new_inset->setDrawFrame(0, InsetText::LOCKED);
2826 new_inset->setFrameColor(0, LColor::captionframe);
2827 if (insertInset(new_inset))
2828 new_inset->edit(bv_);
2835 case LFUN_INSET_TABULAR:
2839 if (!argument.empty())
2840 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2841 InsetTabular * new_inset =
2842 new InsetTabular(*buffer_, r, c);
2844 bv_->getLyXText()->real_current_font.isRightToLeft();
2845 if (!open_new_inset(new_inset, rtl))
2850 // --- lyxserver commands ----------------------------
2852 case LFUN_CHARATCURSOR:
2854 pos_type pos = bv_->getLyXText()->cursor.pos();
2855 if (pos < bv_->getLyXText()->cursor.par()->size())
2856 owner_->getLyXFunc()->setMessage(
2857 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2859 owner_->getLyXFunc()->setMessage("EOF");
2864 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2866 + tostr(bv_->getLyXText()->cursor.y()));
2873 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2874 lyxerr << "SETXY: Could not parse coordinates in '"
2875 << argument << std::endl;
2877 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2881 case LFUN_GETLAYOUT:
2882 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2887 LyXFont & font = bv_->getLyXText()->current_font;
2888 if (font.shape() == LyXFont::ITALIC_SHAPE)
2889 owner_->getLyXFunc()->setMessage("E");
2890 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2891 owner_->getLyXFunc()->setMessage("N");
2893 owner_->getLyXFunc()->setMessage("0");
2898 // --- accented characters ---------------------------
2901 case LFUN_CIRCUMFLEX:
2911 case LFUN_SPECIAL_CARON:
2914 case LFUN_HUNG_UMLAUT:
2917 if (argument.empty()) {
2919 owner_->getLyXFunc()->handleKeyFunc(action);
2921 owner_->getLyXFunc()->handleKeyFunc(action);
2922 owner_->getIntl()->getTrans()
2923 .TranslateAndInsert(argument[0], bv_->getLyXText());
2924 update(bv_->getLyXText(),
2926 | BufferView::FITCUR
2927 | BufferView::CHANGE);
2931 case LFUN_MATH_MACRO:
2932 mathDispatchMathMacro(bv_, argument);
2935 case LFUN_MATH_DELIM:
2936 mathDispatchMathDelim(bv_, argument);
2939 case LFUN_INSERT_MATRIX:
2940 mathDispatchInsertMatrix(bv_, argument);
2943 case LFUN_INSERT_MATH:
2944 mathDispatchInsertMath(bv_, argument);
2947 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2948 mathDispatchMathImportSelection(bv_, argument);
2951 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2952 mathDispatchMathDisplay(bv_, argument);
2955 case LFUN_MATH_MODE: // Open or create an inlined math inset
2956 mathDispatchMathMode(bv_, argument);
2959 case LFUN_GREEK: // Insert a single greek letter
2960 mathDispatchGreek(bv_, argument);
2963 case LFUN_CITATION_INSERT:
2965 InsetCommandParams p;
2966 p.setFromString(argument);
2968 InsetCitation * inset = new InsetCitation(p);
2969 if (!insertInset(inset))
2972 updateInset(inset, true);
2976 case LFUN_INSERT_BIBTEX:
2978 // ale970405+lasgoutt970425
2979 // The argument can be up to two tokens separated
2980 // by a space. The first one is the bibstyle.
2981 string const db = token(argument, ' ', 0);
2982 string const bibstyle = token(argument, ' ', 1);
2984 InsetCommandParams p("BibTeX", db, bibstyle);
2985 InsetBibtex * inset = new InsetBibtex(p);
2987 if (insertInset(inset)) {
2988 if (argument.empty())
2995 // BibTeX data bases
2996 case LFUN_BIBDB_ADD:
2998 InsetBibtex * inset =
2999 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3001 inset->addDatabase(argument);
3006 case LFUN_BIBDB_DEL:
3008 InsetBibtex * inset =
3009 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3011 inset->delDatabase(argument);
3016 case LFUN_BIBTEX_STYLE:
3018 InsetBibtex * inset =
3019 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3021 inset->setOptions(argument);
3026 case LFUN_INDEX_CREATE:
3028 InsetCommandParams p("index");
3029 if (argument.empty()) {
3030 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3031 p.setContents(idxstring);
3033 p.setContents(argument);
3036 owner_->getDialogs()->createIndex(p.getAsString());
3040 case LFUN_INDEX_INSERT:
3042 InsetCommandParams p;
3043 p.setFromString(argument);
3044 InsetIndex * inset = new InsetIndex(p);
3046 if (!insertInset(inset))
3049 updateInset(inset, true);
3053 case LFUN_INDEX_INSERT_LAST:
3055 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3056 if (!idxstring.empty()) {
3057 owner_->message(_("Word `")
3058 + idxstring + _(("' indexed.")));
3059 InsetCommandParams p("index", idxstring);
3060 InsetIndex * inset = new InsetIndex(p);
3062 if (!insertInset(inset))
3065 updateInset(inset, true);
3070 case LFUN_INDEX_PRINT:
3072 InsetCommandParams p("printindex");
3073 Inset * inset = new InsetPrintIndex(p);
3074 if (!insertInset(inset, "Standard"))
3079 case LFUN_PARENTINSERT:
3081 lyxerr << "arg " << argument << endl;
3082 InsetCommandParams p("lyxparent", argument);
3083 Inset * inset = new InsetParent(p, *buffer_);
3084 if (!insertInset(inset, "Standard"))
3090 case LFUN_CHILD_INSERT:
3092 InsetInclude::Params p;
3093 p.cparams.setFromString(argument);
3094 p.masterFilename_ = buffer_->fileName();
3096 InsetInclude * inset = new InsetInclude(p);
3097 if (!insertInset(inset))
3100 updateInset(inset, true);
3101 bv_->owner()->getDialogs()->showInclude(inset);
3106 case LFUN_FLOAT_LIST:
3108 // We should check the argument for validity. (Lgb)
3109 Inset * inset = new InsetFloatList(argument);
3110 if (!insertInset(inset, "Standard"))
3115 case LFUN_THESAURUS_ENTRY:
3117 string arg = argument;
3120 arg = bv_->getLyXText()->selectionAsString(buffer_,
3124 if (arg.size() > 100 || arg.empty()) {
3125 // Get word or selection
3126 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3127 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3128 // FIXME: where is getLyXText()->unselect(bv_) ?
3132 bv_->owner()->getDialogs()->showThesaurus(arg);
3136 case LFUN_SELFINSERT:
3138 if (argument.empty()) break;
3140 /* Automatically delete the currently selected
3141 * text and replace it with what is being
3142 * typed in now. Depends on lyxrc settings
3143 * "auto_region_delete", which defaults to
3146 LyXText * lt = bv_->getLyXText();
3148 if (lyxrc.auto_region_delete) {
3149 if (lt->selection.set()) {
3150 lt->cutSelection(bv_, false, false);
3153 | BufferView::FITCUR
3154 | BufferView::CHANGE);
3159 LyXFont const old_font(lt->real_current_font);
3161 string::const_iterator cit = argument.begin();
3162 string::const_iterator end = argument.end();
3163 for (; cit != end; ++cit) {
3164 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3169 | BufferView::FITCUR
3170 | BufferView::CHANGE);
3172 lt->selection.cursor = lt->cursor;
3173 moveCursorUpdate(false);
3175 // real_current_font.number can change so we need to
3176 // update the minibuffer
3177 if (old_font != lt->real_current_font)
3178 owner_->showState();
3183 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3185 time_t now_time_t = time(NULL);
3186 struct tm * now_tm = localtime(&now_time_t);
3187 setlocale(LC_TIME, "");
3189 if (!argument.empty())
3192 arg = lyxrc.date_insert_format;
3194 int const datetmp_len =
3195 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3197 LyXText * lt = bv_->getLyXText();
3199 for (int i = 0; i < datetmp_len; i++) {
3200 lt->insertChar(bv_, datetmp[i]);
3203 | BufferView::FITCUR
3204 | BufferView::CHANGE);
3207 lt->selection.cursor = lt->cursor;
3208 moveCursorUpdate(false);
3212 case LFUN_UNKNOWN_ACTION:
3213 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3224 void BufferView::Pimpl::newline()
3227 LyXText * lt = bv_->getLyXText();
3231 | BufferView::FITCUR);
3232 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3235 | BufferView::FITCUR
3236 | BufferView::CHANGE);
3241 void BufferView::Pimpl::hfill()
3244 LyXText * lt = bv_->getLyXText();
3248 | BufferView::FITCUR);
3249 lt->insertChar(bv_, Paragraph::META_HFILL);
3252 | BufferView::FITCUR
3253 | BufferView::CHANGE);
3258 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3262 update(lt, BufferView::SELECT|BufferView::FITCUR);
3263 InsetSpecialChar * new_inset =
3264 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3265 #ifdef WITH_WARNINGS
3266 #warning Why is this code different from specialChar() below? (JMarc)
3267 // the code in specialChar is a generic version of what used to exist
3268 // for other special chars. I did not merge this case because of the
3269 // call to updateInset(), but what does it do?
3271 if (!insertInset(new_inset))
3274 updateInset(new_inset, true);
3279 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3282 LyXText * lt = bv_->getLyXText();
3285 update(lt, BufferView::SELECT|BufferView::FITCUR);
3286 InsetSpecialChar * new_inset =
3287 new InsetSpecialChar(kind);
3288 if (!insertInset(new_inset))
3294 void BufferView::Pimpl::smartQuote()
3296 LyXText const * lt = bv_->getLyXText();
3297 Paragraph const * par = lt->cursor.par();
3298 pos_type pos = lt->cursor.pos();
3302 || (par->isInset(pos - 1)
3303 && par->getInset(pos - 1)->isSpace()))
3306 c = par->getChar(pos - 1);
3311 LyXLayout const & style = textclasslist.Style(
3312 bv_->buffer()->params.textclass, par->getLayout());
3314 if (style.pass_thru ||
3315 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3316 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3320 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3322 if (insertInset(inset))
3329 // Open and lock an updatable inset
3330 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3332 LyXText * lt = bv_->getLyXText();
3336 if (!insertInset(new_inset)) {
3340 new_inset->edit(bv_, !behind);
3345 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3347 // if we are in a locking inset we should try to insert the
3348 // inset there otherwise this is a illegal function now
3349 if (bv_->theLockingInset()) {
3350 if (bv_->theLockingInset()->insetAllowed(inset))
3351 return bv_->theLockingInset()->insertInset(bv_, inset);
3355 // not quite sure if we want this...
3356 setCursorParUndo(bv_);
3359 beforeChange(bv_->text);
3360 if (!lout.empty()) {
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3362 bv_->text->breakParagraph(bv_);
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3365 if (bv_->text->cursor.par()->size()) {
3366 bv_->text->cursorLeft(bv_);
3368 bv_->text->breakParagraph(bv_);
3369 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3372 pair<bool, layout_type> lres =
3373 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3374 layout_type lay = 0;
3375 if (lres.first != false) {
3379 // layout not fount using default "Standard" (0)
3383 bv_->text->setLayout(bv_, lay);
3385 bv_->text->setParagraph(bv_, 0, 0,
3387 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3392 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3395 bv_->text->insertInset(bv_, inset);
3396 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3403 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3408 // first check for locking insets
3409 if (bv_->theLockingInset()) {
3410 if (bv_->theLockingInset() == inset) {
3411 if (bv_->text->updateInset(bv_, inset)) {
3414 buffer_->markDirty();
3419 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3420 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3423 buffer_->markDirty();
3431 // then check the current buffer
3434 update(bv_->text, BufferView::UPDATE);
3435 if (bv_->text->updateInset(bv_, inset)) {
3439 | BufferView::FITCUR
3440 | BufferView::CHANGE);
3442 update(bv_->text, SELECT);
3450 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3453 if (!available()) return;
3456 beforeChange(bv_->text);
3457 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3459 LyXCursor const & cursor = bv_->text->cursor;
3463 cursor.par()->isInset(cursor.pos())) {
3464 Inset const * inset = cursor.par()->getInset(cursor.pos());
3465 if (find(codes.begin(), codes.end(), inset->lyxCode())
3468 static_cast<InsetCommand const *>(inset)->getContents();
3472 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3473 if (bv_->text->cursor.pos()
3474 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3475 LyXCursor tmp = bv_->text->cursor;
3476 bv_->text->cursor.par(bv_->text->ownerParagraph());
3477 bv_->text->cursor.pos(0);
3478 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3479 bv_->text->cursor = tmp;
3480 bv_->owner()->message(_("No more insets"));
3483 bv_->owner()->message(_("No more insets"));
3486 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3487 bv_->text->selection.cursor = bv_->text->cursor;
3491 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3493 gotoInset(vector<Inset::Code>(1, code), same_content);