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 string current_layout;
88 using lyx::textclass_type;
90 /* the selection possible is needed, that only motion events are
91 * used, where the bottom press event was on the drawing area too */
92 bool selection_possible = false;
94 extern BufferList bufferlist;
95 extern char ascii_type;
97 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
102 const unsigned int saved_positions_num = 20;
107 XSync(fl_get_display(), 0);
111 void SetXtermCursor(Window win)
113 static Cursor cursor;
114 static bool cursor_undefined = true;
115 if (cursor_undefined) {
116 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
117 XFlush(fl_get_display());
118 cursor_undefined = false;
120 XDefineCursor(fl_get_display(), win, cursor);
121 XFlush(fl_get_display());
127 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
128 int xpos, int ypos, int width, int height)
129 : bv_(b), owner_(o), buffer_(0),
130 current_scrollbar_value(0), cursor_timeout(400),
131 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
135 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
136 workarea_.workAreaExpose
137 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
138 workarea_.workAreaEnter
139 .connect(slot(this, &BufferView::Pimpl::enterView));
140 workarea_.workAreaLeave
141 .connect(slot(this, &BufferView::Pimpl::leaveView));
142 workarea_.workAreaButtonPress
143 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
144 workarea_.workAreaButtonRelease
146 &BufferView::Pimpl::workAreaButtonRelease));
147 workarea_.workAreaMotionNotify
148 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
149 workarea_.workAreaDoubleClick
150 .connect(slot(this, &BufferView::Pimpl::doubleClick));
151 workarea_.workAreaTripleClick
152 .connect(slot(this, &BufferView::Pimpl::tripleClick));
153 workarea_.workAreaKeyPress
154 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
155 workarea_.selectionRequested
156 .connect(slot(this, &BufferView::Pimpl::selectionRequested));
157 workarea_.selectionLost
158 .connect(slot(this, &BufferView::Pimpl::selectionLost));
160 cursor_timeout.timeout.connect(slot(this,
161 &BufferView::Pimpl::cursorToggle));
162 cursor_timeout.start();
163 workarea_.setFocus();
164 saved_positions.resize(saved_positions_num);
168 Painter & BufferView::Pimpl::painter()
170 return workarea_.getPainter();
174 void BufferView::Pimpl::buffer(Buffer * b)
176 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
180 buffer_->delUser(bv_);
182 // Put the old text into the TextCache, but
183 // only if the buffer is still loaded.
184 // Also set the owner of the test to 0
185 // bv_->text->owner(0);
186 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
187 if (lyxerr.debugging())
188 textcache.show(lyxerr, "BufferView::buffer");
193 // Set current buffer
196 if (bufferlist.getState() == BufferList::CLOSING) return;
199 // screen is always deleted when the buffer is changed.
202 // If we are closing the buffer, use the first buffer as current
204 buffer_ = bufferlist.first();
208 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
209 buffer_->addUser(bv_);
210 // If we don't have a text object for this, we make one
211 if (bv_->text == 0) {
212 resizeCurrentBuffer();
217 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
218 owner_->updateMenubar();
219 owner_->updateToolbar();
220 // Similarly, buffer-dependent dialogs should be updated or
221 // hidden. This should go here because some dialogs (eg ToC)
222 // require bv_->text.
223 owner_->getDialogs()->updateBufferDependent(true);
227 lyxerr[Debug::INFO] << " No Buffer!" << endl;
228 owner_->updateMenubar();
229 owner_->updateToolbar();
230 owner_->getDialogs()->hideBufferDependent();
234 // Also remove all remaining text's from the testcache.
235 // (there should not be any!) (if there is any it is a
237 if (lyxerr.debugging())
238 textcache.show(lyxerr, "buffer delete all");
241 // should update layoutchoice even if we don't have a buffer.
242 owner_->updateLayoutChoice();
244 owner_->updateWindowTitle();
248 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
250 workarea_.resize(xpos, ypos, width, height);
251 update(bv_->text, SELECT);
256 void BufferView::Pimpl::resize()
259 resizeCurrentBuffer();
263 void BufferView::Pimpl::redraw()
265 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
270 bool BufferView::Pimpl::fitCursor()
272 lyx::Assert(screen_.get());
276 if (bv_->theLockingInset()) {
277 bv_->theLockingInset()->fitInsetCursor(bv_);
280 ret = screen_->fitCursor(bv_->text, bv_);
283 bv_->owner()->getDialogs()->updateParagraph();
290 void BufferView::Pimpl::redoCurrentBuffer()
292 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
293 if (buffer_ && bv_->text) {
295 owner_->updateLayoutChoice();
300 int BufferView::Pimpl::resizeCurrentBuffer()
302 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
305 Paragraph * selstartpar = 0;
306 Paragraph * selendpar = 0;
307 UpdatableInset * the_locking_inset = 0;
310 pos_type selstartpos = 0;
311 pos_type selendpos = 0;
312 bool selection = false;
313 bool mark_set = false;
315 owner_->prohibitInput();
317 owner_->message(_("Formatting document..."));
320 par = bv_->text->cursor.par();
321 pos = bv_->text->cursor.pos();
322 selstartpar = bv_->text->selection.start.par();
323 selstartpos = bv_->text->selection.start.pos();
324 selendpar = bv_->text->selection.end.par();
325 selendpos = bv_->text->selection.end.pos();
326 selection = bv_->text->selection.set();
327 mark_set = bv_->text->selection.mark();
328 the_locking_inset = bv_->theLockingInset();
330 bv_->text = new LyXText(bv_);
331 bv_->text->init(bv_);
332 buffer_->resizeInsets(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_);
349 //buffer_->resizeInsets(bv_);
356 bv_->text->selection.set(true);
357 // At this point just to avoid the Delete-Empty-Paragraph-
358 // Mechanism when setting the cursor.
359 bv_->text->selection.mark(mark_set);
361 bv_->text->setCursor(bv_, selstartpar, selstartpos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->setCursor(bv_, selendpar, selendpos);
364 bv_->text->setSelection(bv_);
365 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->setCursor(bv_, par, pos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->selection.set(false);
371 // remake the inset locking
372 bv_->theLockingInset(the_locking_inset);
375 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
377 // this will scroll the screen such that the cursor becomes visible
382 owner_->allowInput();
384 /// clear the "Formatting Document" message
391 void BufferView::Pimpl::updateScreen()
393 // Regenerate the screen.
394 screen_.reset(new LyXScreen(workarea_));
398 void BufferView::Pimpl::updateScrollbar()
400 /* If the text is smaller than the working area, the scrollbar
401 * maximum must be the working area height. No scrolling will
404 workarea_.setScrollbar(0, 1.0);
408 long const text_height = bv_->text->height;
409 long const work_height = workarea_.height();
411 if (text_height <= work_height) {
412 workarea_.setScrollbarBounds(0.0, 0.0);
413 current_scrollbar_value = bv_->text->first_y;
414 workarea_.setScrollbar(current_scrollbar_value, 1.0);
418 double const lineh = bv_->text->defaultHeight();
419 double const slider_size =
420 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
422 static long old_text_height;
423 static double old_lineh;
424 static double old_slider_size;
426 if (text_height != old_text_height) {
427 workarea_.setScrollbarBounds(0.0,
428 text_height - work_height);
429 old_text_height = text_height;
431 if (lineh != old_lineh) {
432 workarea_.setScrollbarIncrements(lineh);
435 if (current_scrollbar_value != bv_->text->first_y
436 || slider_size != old_slider_size) {
437 current_scrollbar_value = bv_->text->first_y;
438 workarea_.setScrollbar(current_scrollbar_value, slider_size);
439 old_slider_size = slider_size;
444 // Callback for scrollbar slider
445 void BufferView::Pimpl::scrollCB(double value)
447 if (!buffer_) return;
449 current_scrollbar_value = long(value);
451 if (current_scrollbar_value < 0)
452 current_scrollbar_value = 0;
457 screen_->draw(bv_->text, bv_, current_scrollbar_value);
459 if (!lyxrc.cursor_follows_scrollbar) {
464 LyXText * vbt = bv_->text;
466 int const height = vbt->defaultHeight();
467 int const first = static_cast<int>((bv_->text->first_y + height));
468 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
470 if (vbt->cursor.y() < first)
471 vbt->setCursorFromCoordinates(bv_, 0, first);
472 else if (vbt->cursor.y() > last)
473 vbt->setCursorFromCoordinates(bv_, 0, last);
479 int BufferView::Pimpl::scrollUp(long time)
481 if (!buffer_) return 0;
482 if (!screen_.get()) return 0;
484 double value = workarea_.getScrollbarValue();
486 if (value == 0) return 0;
488 float add_value = (bv_->text->defaultHeight()
489 + float(time) * float(time) * 0.125);
491 if (add_value > workarea_.height())
492 add_value = float(workarea_.height() -
493 bv_->text->defaultHeight());
500 workarea_.setScrollbarValue(value);
507 int BufferView::Pimpl::scrollDown(long time)
509 if (!buffer_) return 0;
510 if (!screen_.get()) return 0;
512 double value = workarea_.getScrollbarValue();
513 pair<float, float> p = workarea_.getScrollbarBounds();
514 double const max = p.second;
516 if (value == max) return 0;
518 float add_value = (bv_->text->defaultHeight()
519 + float(time) * float(time) * 0.125);
521 if (add_value > workarea_.height())
522 add_value = float(workarea_.height() -
523 bv_->text->defaultHeight());
530 workarea_.setScrollbarValue(value);
537 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
539 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
543 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
545 // Only use motion with button 1
546 if (!(state & Button1MotionMask))
549 if (!buffer_ || !screen_.get()) return;
551 // Check for inset locking
552 if (bv_->theLockingInset()) {
553 LyXCursor cursor = bv_->text->cursor;
554 LyXFont font = bv_->text->getFont(buffer_,
555 cursor.par(), cursor.pos());
556 int width = bv_->theLockingInset()->width(bv_, font);
557 int inset_x = font.isVisibleRightToLeft()
558 ? cursor.x() - width : cursor.x();
559 int start_x = inset_x + bv_->theLockingInset()->scroll();
560 bv_->theLockingInset()->
561 insetMotionNotify(bv_,
563 y - cursor.y() + bv_->text->first_y,
568 /* The test for not selection possible is needed, that only motion
569 events are used, where the bottom press event was on
570 the drawing area too */
571 if (!selection_possible)
574 screen_->hideCursor();
576 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
578 if (!bv_->text->selection.set())
579 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
581 bv_->text->setSelection(bv_);
582 screen_->toggleToggle(bv_->text, bv_);
588 // Single-click on work area
589 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
592 if (!buffer_ || !screen_.get())
595 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
597 // ok ok, this is a hack.
598 if (button == 4 || button == 5) {
601 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
604 scrollDown(lyxrc.wheel_jump);
609 // Middle button press pastes if we have a selection
610 // We do this here as if the selection was inside an inset
611 // it could get cleared on the unlocking of the inset so
612 // we have to check this first
613 bool paste_internally = false;
614 if (button == 2 && bv_->getLyXText()->selection.set()) {
615 owner_->getLyXFunc()->dispatch(LFUN_COPY);
616 paste_internally = true;
619 if (bv_->theLockingInset()) {
620 // We are in inset locking mode
622 /* Check whether the inset was hit. If not reset mode,
623 otherwise give the event to the inset */
624 if (inset_hit == bv_->theLockingInset()) {
625 bv_->theLockingInset()->
626 insetButtonPress(bv_,xpos, ypos,button);
629 bv_->unlockInset(bv_->theLockingInset());
634 selection_possible = true;
635 screen_->hideCursor();
637 int const screen_first = bv_->text->first_y;
639 // Clear the selection
640 screen_->toggleSelection(bv_->text, bv_);
641 bv_->text->clearSelection();
642 bv_->text->fullRebreak(bv_);
646 // Single left click in math inset?
647 if (isHighlyEditableInset(inset_hit)) {
648 // Highly editable inset, like math
649 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
650 selection_possible = false;
651 owner_->updateLayoutChoice();
652 owner_->message(inset->editMessage());
653 // IMO the inset has to be first in edit-mode and then we send the
654 // button press. (Jug 20020222)
655 inset->edit(bv_); //, xpos, ypos, button);
656 inset->insetButtonPress(bv_, xpos, ypos, button);
660 // Right click on a footnote flag opens float menu
662 selection_possible = false;
666 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
667 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
669 bv_->text->selection.cursor = bv_->text->cursor;
670 bv_->text->cursor.x_fix(bv_->text->cursor.x());
672 owner_->updateLayoutChoice();
674 selection_possible = false;
677 // Insert primary selection with middle mouse
678 // if there is a local selection in the current buffer,
681 if (paste_internally)
682 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
684 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
686 selection_possible = false;
692 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
698 LyXText * text = bv_->getLyXText();
700 if (text->bv_owner && bv_->theLockingInset())
703 if (screen_.get() && button == 1) {
704 if (text->bv_owner) {
705 screen_->hideCursor();
706 screen_->toggleSelection(text, bv_);
707 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
708 screen_->toggleSelection(text, bv_, false);
710 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
712 /* This will fit the cursor on the screen
714 update(text, BufferView::SELECT|BufferView::FITCUR);
719 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
725 LyXText * text = bv_->getLyXText();
727 if (text->bv_owner && bv_->theLockingInset())
730 if (screen_.get() && (button == 1)) {
731 if (text->bv_owner) {
732 screen_->hideCursor();
733 screen_->toggleSelection(text, bv_);
735 text->cursorHome(bv_);
736 text->selection.cursor = text->cursor;
737 text->cursorEnd(bv_);
738 text->setSelection(bv_);
739 if (text->bv_owner) {
740 screen_->toggleSelection(text, bv_, false);
742 /* This will fit the cursor on the screen
744 update(text, BufferView::SELECT|BufferView::FITCUR);
749 void BufferView::Pimpl::selectionRequested()
754 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
757 workarea_.putClipboard(sel);
762 void BufferView::Pimpl::selectionLost()
764 if (active() && available()) {
767 bv_->getLyXText()->clearSelection();
773 void BufferView::Pimpl::enterView()
775 if (active() && available()) {
776 SetXtermCursor(workarea_.getWin());
777 using_xterm_cursor = true;
782 void BufferView::Pimpl::leaveView()
784 if (using_xterm_cursor) {
785 XUndefineCursor(fl_get_display(), workarea_.getWin());
786 using_xterm_cursor = false;
791 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
794 if (!buffer_ || !screen_.get()) return;
796 // If we hit an inset, we have the inset coordinates in these
797 // and inset_hit points to the inset. If we do not hit an
798 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
799 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
801 if (bv_->theLockingInset()) {
802 // We are in inset locking mode.
804 /* LyX does a kind of work-area grabbing for insets.
805 Only a ButtonPress Event outside the inset will
806 force a insetUnlock. */
807 bv_->theLockingInset()->
808 insetButtonRelease(bv_, x, y, button);
812 selection_possible = false;
819 workarea_.haveSelection(bv_->getLyXText()->selection.set());
824 owner_->updateMenubar();
825 owner_->updateToolbar();
827 // Did we hit an editable inset?
829 selection_possible = false;
831 // if we reach this point with a selection, it
832 // must mean we are currently selecting.
833 // But we don't want to open the inset
834 // because that is annoying for the user.
835 // So just pretend we didn't hit it.
836 // this is OK because a "kosher" ButtonRelease
837 // will follow a ButtonPress that clears
839 // Note this also fixes selection drawing
840 // problems if we end up opening an inset
841 if (bv_->getLyXText()->selection.set())
844 // CHECK fix this proper in 0.13
845 // well, maybe 13.0 !!!!!!!!!
847 // Following a ref shouldn't issue
848 // a push on the undo-stack
849 // anylonger, now that we have
850 // keybindings for following
851 // references and returning from
852 // references. IMHO though, it
853 // should be the inset's own business
854 // to push or not push on the undo
855 // stack. They don't *have* to
856 // alter the document...
858 // ...or maybe the SetCursorParUndo()
859 // below isn't necessary at all anylonger?
860 if (inset_hit->lyxCode() == Inset::REF_CODE) {
861 setCursorParUndo(bv_);
864 owner_->message(inset_hit->editMessage());
866 if (isHighlyEditableInset(inset_hit)) {
867 // Highly editable inset, like math
868 UpdatableInset *inset = (UpdatableInset *)inset_hit;
869 inset->insetButtonRelease(bv_, x, y, button);
871 inset_hit->insetButtonRelease(bv_, x, y, button);
872 inset_hit->edit(bv_, x, y, button);
877 // Maybe we want to edit a bibitem ale970302
878 if (bv_->text->cursor.par()->bibkey && x < 20 +
879 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
880 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
887 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
888 LyXCursor const & cursor) const
890 Paragraph /*const*/ & par = *cursor.par();
891 pos_type const pos = cursor.pos();
893 lyx::Assert(par.getInset(pos));
895 Inset const & inset(*par.getInset(pos));
897 LyXFont const & font = text.getFont(buffer_, &par, pos);
899 int const width = inset.width(bv_, font);
900 int const inset_x = font.isVisibleRightToLeft()
901 ? (cursor.x() - width) : cursor.x();
904 inset_x + inset.scroll(),
906 cursor.y() - inset.ascent(bv_, font),
907 cursor.y() + inset.descent(bv_, font));
911 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
912 LyXCursor const & cursor,
913 int & x, int & y) const
915 pos_type const pos(cursor.pos());
916 Paragraph /*const*/ & par(*cursor.par());
918 if (pos >= par.size() || !par.isInset(pos)) {
922 Inset /*const*/ * inset = par.getInset(pos);
924 if (!isEditableInset(inset)) {
928 Box b(insetDimensions(text, cursor));
930 if (!b.contained(x, y)) {
931 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
932 << " box " << b << endl;
936 text.setCursor(bv_, &par, pos, true);
939 // The origin of an inset is on the baseline
940 y -= (text.cursor.y());
946 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
951 int y_tmp = y + text->first_y;
954 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
956 Inset * inset(checkInset(*text, cursor, x, y_tmp));
963 // look at previous position
965 if (cursor.pos() == 0) {
970 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
972 inset = checkInset(*text, cursor, x, y_tmp);
980 void BufferView::Pimpl::workAreaExpose()
982 static int work_area_width;
983 static unsigned int work_area_height;
985 bool const widthChange = workarea_.workWidth() != work_area_width;
986 bool const heightChange = workarea_.height() != work_area_height;
988 // update from work area
989 work_area_width = workarea_.workWidth();
990 work_area_height = workarea_.height();
993 // The visible LyXView need a resize
996 // Remove all texts from the textcache
997 // This is not _really_ what we want to do. What
998 // we really want to do is to delete in textcache
999 // that does not have a BufferView with matching
1000 // width, but as long as we have only one BufferView
1001 // deleting all gives the same result.
1002 if (lyxerr.debugging())
1003 textcache.show(lyxerr, "Expose delete all");
1005 buffer_->resizeInsets(bv_);
1006 } else if (heightChange) {
1007 // Rebuild image of current screen
1009 // fitCursor() ensures we don't jump back
1010 // to the start of the document on vertical
1014 // The main window size has changed, repaint most stuff
1016 } else if (screen_.get())
1017 screen_->redraw(bv_->text, bv_);
1019 // Grey box when we don't have a buffer
1020 workarea_.greyOut();
1023 // always make sure that the scrollbar is sane.
1025 owner_->updateLayoutChoice();
1030 void BufferView::Pimpl::update()
1032 if (screen_.get() &&
1033 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1035 LyXText::text_status st = bv_->text->status();
1036 screen_->update(bv_->text, bv_);
1038 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1039 if (bv_->text->fullRebreak(bv_)) {
1040 st = LyXText::NEED_MORE_REFRESH;
1041 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1042 bv_->text->cursor.pos());
1045 bv_->text->status(bv_, st);
1046 screen_->update(bv_->text, bv_);
1048 // do this here instead of in the screen::update because of
1050 bv_->text->status(bv_, LyXText::UNCHANGED);
1056 // Values used when calling update:
1058 // -2 - update, move sel_cursor if selection, fitcursor
1059 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1060 // 0 - update, move sel_cursor if selection, fitcursor
1061 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1062 // 3 - update, move sel_cursor if selection
1065 // a simple redraw of the parts that need refresh
1067 // move sel_cursor if selection -
1068 // the text's sel_cursor is moved if there is selection is progress
1071 // fitCursor() is called and the scrollbar updated
1074 // the buffer is marked dirty.
1083 // UPDATE_ONLY = UPDATE;
1084 // UPDATE_SELECT = UPDATE | SELECT;
1085 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1086 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1088 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1089 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1090 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1091 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1092 // update(3) -> update(1) -> update(1) -> update(SELECT)
1094 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1096 owner_->updateLayoutChoice();
1098 if (!text->selection.set() && (f & SELECT)) {
1099 text->selection.cursor = text->cursor;
1102 text->fullRebreak(bv_);
1104 if (text->inset_owner) {
1105 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1106 updateInset(text->inset_owner, false);
1116 buffer_->markDirty();
1121 // Callback for cursor timer
1122 void BufferView::Pimpl::cursorToggle()
1125 cursor_timeout.restart();
1129 if (!screen_.get()) {
1130 cursor_timeout.restart();
1135 extern void reapSpellchecker(void);
1138 if (!bv_->theLockingInset()) {
1139 screen_->cursorToggle(bv_);
1141 bv_->theLockingInset()->toggleInsetCursor(bv_);
1144 cursor_timeout.restart();
1148 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1150 if (!text->cursor.row()->previous())
1153 int y = text->first_y;
1154 Row * cursorrow = text->cursor.row();
1156 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1158 // This is to allow jumping over large insets
1159 if ((cursorrow == text->cursor.row()))
1160 text->cursorUp(bv_);
1162 if (text->inset_owner ||
1163 text->cursor.row()->height() < workarea_.height())
1164 screen_->draw(bv_->text, bv_,
1166 - text->cursor.row()->baseline()
1167 + text->cursor.row()->height()
1168 - workarea_.height() + 1);
1173 void BufferView::Pimpl::cursorNext(LyXText * text)
1175 if (!text->cursor.row()->next())
1178 int y = text->first_y + workarea_.height();
1179 // if (text->inset_owner)
1180 // y += bv_->text->first;
1181 text->getRowNearY(y);
1183 Row * cursorrow = text->cursor.row();
1184 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1186 // This is to allow jumping over large insets
1187 if ((cursorrow == bv_->text->cursor.row()))
1188 text->cursorDown(bv_);
1190 if (text->inset_owner ||
1191 text->cursor.row()->height() < workarea_.height())
1192 screen_->draw(bv_->text, bv_, text->cursor.y() -
1193 text->cursor.row()->baseline());
1198 bool BufferView::Pimpl::available() const
1200 if (buffer_ && bv_->text)
1206 void BufferView::Pimpl::beforeChange(LyXText * text)
1209 text->clearSelection();
1213 void BufferView::Pimpl::savePosition(unsigned int i)
1215 if (i >= saved_positions_num)
1217 saved_positions[i] = Position(buffer_->fileName(),
1218 bv_->text->cursor.par()->id(),
1219 bv_->text->cursor.pos());
1222 str << _("Saved bookmark") << ' ' << i;
1223 owner_->message(str.str().c_str());
1228 void BufferView::Pimpl::restorePosition(unsigned int i)
1230 if (i >= saved_positions_num)
1233 string const fname = saved_positions[i].filename;
1235 beforeChange(bv_->text);
1237 if (fname != buffer_->fileName()) {
1238 Buffer * b = bufferlist.exists(fname) ?
1239 bufferlist.getBuffer(fname) :
1240 bufferlist.loadLyXFile(fname); // don't ask, just load it
1241 if (b != 0) buffer(b);
1244 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1248 bv_->text->setCursor(bv_, par,
1249 min(par->size(), saved_positions[i].par_pos));
1251 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1254 str << _("Moved to bookmark") << ' ' << i;
1255 owner_->message(str.str().c_str());
1260 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1262 if (i >= saved_positions_num)
1265 return !saved_positions[i].filename.empty();
1269 void BufferView::Pimpl::setState()
1271 if (!lyxrc.rtl_support)
1274 LyXText * text = bv_->getLyXText();
1275 if (text->real_current_font.isRightToLeft()) {
1276 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1277 owner_->getIntl()->KeyMapSec();
1279 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1280 owner_->getIntl()->KeyMapPrim();
1285 void BufferView::Pimpl::insetSleep()
1287 if (bv_->theLockingInset() && !inset_slept) {
1288 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1289 bv_->theLockingInset()->insetUnlock(bv_);
1295 void BufferView::Pimpl::insetWakeup()
1297 if (bv_->theLockingInset() && inset_slept) {
1298 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1299 inset_slept = false;
1304 void BufferView::Pimpl::insetUnlock()
1306 if (bv_->theLockingInset()) {
1308 bv_->theLockingInset()->insetUnlock(bv_);
1309 bv_->theLockingInset(0);
1311 inset_slept = false;
1316 bool BufferView::Pimpl::focus() const
1318 return workarea_.hasFocus();
1322 void BufferView::Pimpl::focus(bool f)
1324 if (f) workarea_.setFocus();
1328 bool BufferView::Pimpl::active() const
1330 return workarea_.active();
1334 bool BufferView::Pimpl::belowMouse() const
1336 return workarea_.belowMouse();
1340 void BufferView::Pimpl::showCursor()
1342 if (screen_.get()) {
1343 if (bv_->theLockingInset())
1344 bv_->theLockingInset()->showInsetCursor(bv_);
1346 screen_->showCursor(bv_->text, bv_);
1351 void BufferView::Pimpl::hideCursor()
1353 if (screen_.get()) {
1354 if (!bv_->theLockingInset())
1355 // bv_->theLockingInset()->hideInsetCursor(bv_);
1357 screen_->hideCursor();
1362 void BufferView::Pimpl::toggleSelection(bool b)
1364 if (screen_.get()) {
1365 if (bv_->theLockingInset())
1366 bv_->theLockingInset()->toggleSelection(bv_, b);
1367 screen_->toggleSelection(bv_->text, bv_, b);
1372 void BufferView::Pimpl::toggleToggle()
1375 screen_->toggleToggle(bv_->text, bv_);
1379 void BufferView::Pimpl::center()
1381 beforeChange(bv_->text);
1382 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1383 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1385 screen_->draw(bv_->text, bv_, 0);
1387 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1392 void BufferView::Pimpl::pasteClipboard(bool asPara)
1397 screen_->hideCursor();
1398 beforeChange(bv_->text);
1400 string const clip(workarea_.getClipboard());
1406 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1408 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1410 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1414 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1416 workarea_.putClipboard(stuff);
1421 * Dispatch functions for actions which can be valid for BufferView->text
1422 * and/or InsetText->text!!!
1427 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1429 LyXText * lt = bv_->getLyXText();
1431 if (selecting || lt->selection.mark()) {
1432 lt->setSelection(bv_);
1436 updateInset(lt->inset_owner, false);
1439 update(lt, BufferView::SELECT|BufferView::FITCUR);
1443 /* ---> Everytime the cursor is moved, show the current font state. */
1444 // should this too me moved out of this func?
1445 //owner->showState();
1450 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1452 LyXCursor cursor = bv_->getLyXText()->cursor;
1453 Buffer::inset_iterator it =
1454 find_if(Buffer::inset_iterator(
1455 cursor.par(), cursor.pos()),
1456 buffer_->inset_iterator_end(),
1457 lyx::compare_memfun(&Inset::lyxCode, code));
1458 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1462 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1464 string filename = filen;
1466 if (filename.empty()) {
1467 // Launch a file browser
1468 string initpath = lyxrc.document_path;
1471 string const trypath = owner_->buffer()->filePath();
1472 // If directory is writeable, use this as default.
1473 if (IsDirWriteable(trypath))
1477 FileDialog fileDlg(bv_->owner(),
1478 _("Select LyX document to insert"),
1480 make_pair(string(_("Documents|#o#O")),
1481 string(lyxrc.document_path)),
1482 make_pair(string(_("Examples|#E#e")),
1483 string(AddPath(system_lyxdir, "examples"))));
1485 FileDialog::Result result =
1486 fileDlg.Select(initpath,
1487 _("*.lyx| LyX Documents (*.lyx)"));
1489 if (result.first == FileDialog::Later)
1492 filename = result.second;
1494 // check selected filename
1495 if (filename.empty()) {
1496 owner_->message(_("Canceled."));
1501 // get absolute path of file and add ".lyx" to the filename if
1503 filename = FileSearch(string(), filename, "lyx");
1505 string const disp_fn(MakeDisplayPath(filename));
1508 s1 << _("Inserting document") << ' '
1509 << disp_fn << " ...";
1510 owner_->message(s1.str().c_str());
1511 bool const res = bv_->insertLyXFile(filename);
1514 str << _("Document") << ' ' << disp_fn
1515 << ' ' << _("inserted.");
1516 owner_->message(str.str().c_str());
1519 str << _("Could not insert document") << ' '
1521 owner_->message(str.str().c_str());
1526 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1528 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1529 << action <<"] arg[" << argument << "]" << endl;
1532 // --- Misc -------------------------------------------
1536 LyXText * lt = bv_->getLyXText();
1537 lt->toggleAppendix(bv_);
1540 | BufferView::FITCUR
1541 | BufferView::CHANGE);
1546 case LFUN_TOC_INSERT:
1548 InsetCommandParams p;
1549 p.setCmdName("tableofcontents");
1550 Inset * inset = new InsetTOC(p);
1551 if (!insertInset(inset, "Standard"))
1556 case LFUN_SCROLL_INSET:
1557 // this is not handled here as this funktion is only aktive
1558 // if we have a locking_inset and that one is (or contains)
1562 case LFUN_INSET_GRAPHICS:
1564 Inset * new_inset = new InsetGraphics;
1565 if (!insertInset(new_inset)) {
1568 // this is need because you don't use a inset->Edit()
1569 updateInset(new_inset, true);
1570 new_inset->edit(bv_);
1580 case LFUN_PASTESELECTION:
1582 bool asPara = false;
1583 if (argument == "paragraph")
1585 pasteClipboard(asPara);
1597 case LFUN_LAYOUT_COPY:
1598 bv_->copyEnvironment();
1601 case LFUN_LAYOUT_PASTE:
1602 bv_->pasteEnvironment();
1606 case LFUN_GOTOERROR:
1607 gotoInset(Inset::ERROR_CODE, false);
1611 gotoInset(Inset::IGNORE_CODE, false);
1614 case LFUN_REFERENCE_GOTO:
1616 vector<Inset::Code> tmp;
1617 tmp.push_back(Inset::LABEL_CODE);
1618 tmp.push_back(Inset::REF_CODE);
1619 gotoInset(tmp, true);
1623 case LFUN_HYPHENATION:
1624 specialChar(InsetSpecialChar::HYPHENATION);
1627 case LFUN_LIGATURE_BREAK:
1628 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1632 specialChar(InsetSpecialChar::LDOTS);
1635 case LFUN_END_OF_SENTENCE:
1636 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1639 case LFUN_MENU_SEPARATOR:
1640 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1647 case LFUN_DEPTH_MIN:
1648 changeDepth(bv_, bv_->getLyXText(), -1);
1651 case LFUN_DEPTH_PLUS:
1652 changeDepth(bv_, bv_->getLyXText(), 1);
1656 owner_->getDialogs()->setUserFreeFont();
1659 case LFUN_FILE_INSERT:
1660 MenuInsertLyXFile(argument);
1663 case LFUN_FILE_INSERT_ASCII_PARA:
1664 InsertAsciiFile(bv_, argument, true);
1667 case LFUN_FILE_INSERT_ASCII:
1668 InsertAsciiFile(bv_, argument, false);
1673 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1674 << argument << endl;
1676 // Derive layout number from given argument (string)
1677 // and current buffer's textclass (number). */
1678 textclass_type tclass = buffer_->params.textclass;
1680 textclasslist[tclass].hasLayout(argument);
1681 string layout = argument;
1683 // If the entry is obsolete, use the new one instead.
1685 string const & obs = textclasslist[tclass][layout]
1692 owner_->getLyXFunc()->setErrorMessage(
1693 string(N_("Layout ")) + argument +
1698 if (current_layout != layout) {
1699 LyXText * lt = bv_->getLyXText();
1701 current_layout = layout;
1704 | BufferView::FITCUR);
1705 lt->setLayout(bv_, layout);
1706 owner_->setLayout(layout);
1709 | BufferView::FITCUR
1710 | BufferView::CHANGE);
1717 lang(bv_, argument);
1719 owner_->showState();
1724 owner_->showState();
1729 owner_->showState();
1734 owner_->showState();
1739 owner_->showState();
1744 owner_->showState();
1749 owner_->showState();
1754 owner_->showState();
1757 case LFUN_UNDERLINE:
1759 owner_->showState();
1762 case LFUN_FONT_SIZE:
1763 fontSize(bv_, argument);
1764 owner_->showState();
1767 case LFUN_FONT_STATE:
1768 owner_->getLyXFunc()->setMessage(currentState(bv_));
1771 case LFUN_UPCASE_WORD:
1773 LyXText * lt = bv_->getLyXText();
1777 | BufferView::FITCUR);
1778 lt->changeCase(bv_, LyXText::text_uppercase);
1779 if (lt->inset_owner)
1780 updateInset(lt->inset_owner, true);
1783 | BufferView::FITCUR
1784 | BufferView::CHANGE);
1788 case LFUN_LOWCASE_WORD:
1790 LyXText * lt = bv_->getLyXText();
1792 update(lt, BufferView::SELECT|BufferView::FITCUR);
1793 lt->changeCase(bv_, LyXText::text_lowercase);
1794 if (lt->inset_owner)
1795 updateInset(lt->inset_owner, true);
1798 | BufferView::FITCUR
1799 | BufferView::CHANGE);
1803 case LFUN_CAPITALIZE_WORD:
1805 LyXText * lt = bv_->getLyXText();
1807 update(lt, BufferView::SELECT|BufferView::FITCUR);
1808 lt->changeCase(bv_, LyXText::text_capitalization);
1809 if (lt->inset_owner)
1810 updateInset(lt->inset_owner, true);
1813 | BufferView::FITCUR
1814 | BufferView::CHANGE);
1818 case LFUN_TRANSPOSE_CHARS:
1820 LyXText * lt = bv_->getLyXText();
1822 update(lt, BufferView::SELECT|BufferView::FITCUR);
1823 lt->transposeChars(*bv_);
1824 if (lt->inset_owner)
1825 updateInset(lt->inset_owner, true);
1828 | BufferView::FITCUR
1829 | BufferView::CHANGE);
1834 case LFUN_INSERT_LABEL:
1835 MenuInsertLabel(bv_, argument);
1838 case LFUN_REF_INSERT:
1839 if (argument.empty()) {
1840 InsetCommandParams p("ref");
1841 owner_->getDialogs()->createRef(p.getAsString());
1843 InsetCommandParams p;
1844 p.setFromString(argument);
1846 InsetRef * inset = new InsetRef(p, *buffer_);
1847 if (!insertInset(inset))
1850 updateInset(inset, true);
1854 case LFUN_BOOKMARK_SAVE:
1855 savePosition(strToUnsignedInt(argument));
1858 case LFUN_BOOKMARK_GOTO:
1859 restorePosition(strToUnsignedInt(argument));
1864 string label(argument);
1865 if (label.empty()) {
1867 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1869 label = inset->getContents();
1874 if (!label.empty()) {
1875 //bv_->savePosition(0);
1876 if (!bv_->gotoLabel(label))
1877 Alert::alert(_("Error"),
1878 _("Couldn't find this label"),
1879 _("in current document."));
1884 // --- Cursor Movements -----------------------------
1887 LyXText * lt = bv_->getLyXText();
1889 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1890 if (!lt->selection.mark())
1892 update(lt, BufferView::SELECT|BufferView::FITCUR);
1894 lt->cursorLeft(bv_, false);
1895 if (lt->cursor.pos() < lt->cursor.par()->size()
1896 && lt->cursor.par()->isInset(lt->cursor.pos())
1897 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1898 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1899 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1901 tmpinset->edit(bv_, false);
1903 tmpinset->edit(bv_);
1907 lt->cursorRight(bv_, false);
1909 moveCursorUpdate(false);
1910 owner_->showState();
1916 // This is soooo ugly. Isn`t it possible to make
1917 // it simpler? (Lgb)
1918 LyXText * lt = bv_->getLyXText();
1919 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1920 if (!lt->selection.mark())
1922 update(lt, BufferView::SELECT|BufferView::FITCUR);
1923 LyXCursor const cur = lt->cursor;
1925 lt->cursorLeft(bv_, false);
1926 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1927 lt->cursor.pos() < lt->cursor.par()->size() &&
1928 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1929 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1930 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1931 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1933 tmpinset->edit(bv_);
1935 tmpinset->edit(bv_, false);
1939 lt->cursorRight(bv_, false);
1942 moveCursorUpdate(false);
1943 owner_->showState();
1949 LyXText * lt = bv_->getLyXText();
1951 if (!lt->selection.mark())
1953 update(lt, BufferView::UPDATE);
1956 moveCursorUpdate(false);
1957 owner_->showState();
1963 LyXText * lt = bv_->getLyXText();
1965 if (!lt->selection.mark())
1967 update(lt, BufferView::UPDATE);
1968 lt->cursorDown(bv_);
1970 moveCursorUpdate(false);
1971 owner_->showState();
1975 case LFUN_UP_PARAGRAPH:
1977 LyXText * lt = bv_->getLyXText();
1979 if (!lt->selection.mark())
1981 update(lt, BufferView::UPDATE);
1982 lt->cursorUpParagraph(bv_);
1984 moveCursorUpdate(false);
1985 owner_->showState();
1989 case LFUN_DOWN_PARAGRAPH:
1991 LyXText * lt = bv_->getLyXText();
1993 if (!lt->selection.mark())
1995 update(lt, BufferView::UPDATE);
1996 lt->cursorDownParagraph(bv_);
1998 moveCursorUpdate(false);
1999 owner_->showState();
2005 LyXText * lt = bv_->getLyXText();
2007 if (!lt->selection.mark())
2009 update(lt, BufferView::UPDATE);
2012 moveCursorUpdate(false);
2013 owner_->showState();
2019 LyXText * lt = bv_->getLyXText();
2021 if (!lt->selection.mark())
2023 update(lt, BufferView::UPDATE);
2026 moveCursorUpdate(false);
2027 owner_->showState();
2033 LyXText * lt = bv_->getLyXText();
2035 if (!lt->selection.mark())
2037 update(lt, BufferView::SELECT|BufferView::FITCUR);
2038 lt->cursorHome(bv_);
2040 moveCursorUpdate(false);
2041 owner_->showState();
2047 LyXText * lt = bv_->getLyXText();
2049 if (!lt->selection.mark())
2052 BufferView::SELECT|BufferView::FITCUR);
2055 moveCursorUpdate(false);
2056 owner_->showState();
2060 case LFUN_SHIFT_TAB:
2063 LyXText * lt = bv_->getLyXText();
2065 if (!lt->selection.mark())
2068 BufferView::SELECT|BufferView::FITCUR);
2071 moveCursorUpdate(false);
2072 owner_->showState();
2076 case LFUN_WORDRIGHT:
2078 LyXText * lt = bv_->getLyXText();
2080 if (!lt->selection.mark())
2082 update(lt, BufferView::SELECT|BufferView::FITCUR);
2083 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2084 lt->cursorLeftOneWord(bv_);
2086 lt->cursorRightOneWord(bv_);
2088 moveCursorUpdate(false);
2089 owner_->showState();
2095 LyXText * lt = bv_->getLyXText();
2097 if (!lt->selection.mark())
2099 update(lt, BufferView::SELECT|BufferView::FITCUR);
2100 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2101 lt->cursorRightOneWord(bv_);
2103 lt->cursorLeftOneWord(bv_);
2105 moveCursorUpdate(false);
2106 owner_->showState();
2110 case LFUN_BEGINNINGBUF:
2112 LyXText * lt = bv_->getLyXText();
2114 if (!lt->selection.mark())
2117 BufferView::SELECT|BufferView::FITCUR);
2120 moveCursorUpdate(false);
2121 owner_->showState();
2127 LyXText * lt = bv_->getLyXText();
2129 if (!lt->selection.mark())
2132 BufferView::SELECT|BufferView::FITCUR);
2133 lt->cursorBottom(bv_);
2135 moveCursorUpdate(false);
2136 owner_->showState();
2140 /* cursor selection ---------------------------- */
2143 LyXText * lt = bv_->getLyXText();
2146 BufferView::SELECT|BufferView::FITCUR);
2147 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2148 lt->cursorLeft(bv_);
2150 lt->cursorRight(bv_);
2152 moveCursorUpdate(true);
2153 owner_->showState();
2159 LyXText * lt = bv_->getLyXText();
2162 BufferView::SELECT|BufferView::FITCUR);
2163 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2164 lt->cursorRight(bv_);
2166 lt->cursorLeft(bv_);
2168 moveCursorUpdate(true);
2169 owner_->showState();
2175 LyXText * lt = bv_->getLyXText();
2178 BufferView::SELECT|BufferView::FITCUR);
2181 moveCursorUpdate(true);
2182 owner_->showState();
2188 LyXText * lt = bv_->getLyXText();
2191 BufferView::SELECT|BufferView::FITCUR);
2192 lt->cursorDown(bv_);
2194 moveCursorUpdate(true);
2195 owner_->showState();
2199 case LFUN_UP_PARAGRAPHSEL:
2201 LyXText * lt = bv_->getLyXText();
2204 BufferView::SELECT|BufferView::FITCUR);
2205 lt->cursorUpParagraph(bv_);
2207 moveCursorUpdate(true);
2208 owner_->showState();
2212 case LFUN_DOWN_PARAGRAPHSEL:
2214 LyXText * lt = bv_->getLyXText();
2217 BufferView::SELECT|BufferView::FITCUR);
2218 lt->cursorDownParagraph(bv_);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2244 moveCursorUpdate(true);
2245 owner_->showState();
2251 LyXText * lt = bv_->getLyXText();
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2254 lt->cursorHome(bv_);
2256 moveCursorUpdate(true);
2257 owner_->showState();
2263 LyXText * lt = bv_->getLyXText();
2265 update(lt, BufferView::SELECT|BufferView::FITCUR);
2268 moveCursorUpdate(true);
2269 owner_->showState();
2273 case LFUN_WORDRIGHTSEL:
2275 LyXText * lt = bv_->getLyXText();
2277 update(lt, BufferView::SELECT|BufferView::FITCUR);
2278 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2279 lt->cursorLeftOneWord(bv_);
2281 lt->cursorRightOneWord(bv_);
2283 moveCursorUpdate(true);
2284 owner_->showState();
2288 case LFUN_WORDLEFTSEL:
2290 LyXText * lt = bv_->getLyXText();
2292 update(lt, BufferView::SELECT|BufferView::FITCUR);
2293 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2294 lt->cursorRightOneWord(bv_);
2296 lt->cursorLeftOneWord(bv_);
2298 moveCursorUpdate(true);
2299 owner_->showState();
2303 case LFUN_BEGINNINGBUFSEL:
2305 LyXText * lt = bv_->getLyXText();
2307 if (lt->inset_owner)
2309 update(lt, BufferView::SELECT|BufferView::FITCUR);
2312 moveCursorUpdate(true);
2313 owner_->showState();
2317 case LFUN_ENDBUFSEL:
2319 LyXText * lt = bv_->getLyXText();
2321 if (lt->inset_owner)
2324 BufferView::SELECT|BufferView::FITCUR);
2325 lt->cursorBottom(bv_);
2327 moveCursorUpdate(true);
2328 owner_->showState();
2332 // --- text changing commands ------------------------
2333 case LFUN_BREAKLINE:
2335 LyXText * lt = bv_->getLyXText();
2338 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2341 | BufferView::FITCUR
2342 | BufferView::CHANGE);
2343 moveCursorUpdate(false);
2347 case LFUN_PROTECTEDSPACE:
2349 LyXText * lt = bv_->getLyXText();
2351 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2353 if (style.free_spacing) {
2354 lt->insertChar(bv_, ' ');
2357 | BufferView::FITCUR
2358 | BufferView::CHANGE);
2360 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2362 moveCursorUpdate(false);
2368 LyXText * lt = bv_->getLyXText();
2370 if (lt->selection.mark()) {
2374 | BufferView::FITCUR);
2375 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2378 lt->selection.mark(true);
2381 | BufferView::FITCUR);
2382 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2384 lt->selection.cursor = lt->cursor;
2390 LyXText * lt = bv_->getLyXText();
2392 if (!lt->selection.set()) {
2394 lt->selection.cursor = lt->cursor;
2397 | BufferView::FITCUR
2398 | BufferView::CHANGE);
2399 // It is possible to make it a lot faster still
2400 // just comment out the line below...
2405 moveCursorUpdate(false);
2406 owner_->showState();
2411 case LFUN_DELETE_SKIP:
2413 LyXText * lt = bv_->getLyXText();
2415 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2417 LyXCursor cursor = lt->cursor;
2419 if (!lt->selection.set()) {
2420 if (cursor.pos() == cursor.par()->size()) {
2421 lt->cursorRight(bv_);
2422 cursor = lt->cursor;
2423 if (cursor.pos() == 0
2424 && !(cursor.par()->params().spaceTop()
2425 == VSpace (VSpace::NONE))) {
2428 cursor.par()->params().lineTop(),
2429 cursor.par()->params().lineBottom(),
2430 cursor.par()->params().pagebreakTop(),
2431 cursor.par()->params().pagebreakBottom(),
2432 VSpace(VSpace::NONE),
2433 cursor.par()->params().spaceBottom(),
2434 cursor.par()->params().spacing(),
2435 cursor.par()->params().align(),
2436 cursor.par()->params().labelWidthString(), 0);
2437 lt->cursorLeft(bv_);
2440 | BufferView::FITCUR
2441 | BufferView::CHANGE);
2443 lt->cursorLeft(bv_);
2445 lt->selection.cursor = lt->cursor;
2448 | BufferView::FITCUR
2449 | BufferView::CHANGE);
2453 lt->selection.cursor = lt->cursor;
2456 | BufferView::FITCUR
2457 | BufferView::CHANGE);
2465 /* -------> Delete word forward. */
2466 case LFUN_DELETE_WORD_FORWARD:
2467 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2468 bv_->getLyXText()->deleteWordForward(bv_);
2469 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2470 moveCursorUpdate(false);
2471 owner_->showState();
2474 /* -------> Delete word backward. */
2475 case LFUN_DELETE_WORD_BACKWARD:
2477 LyXText * lt = bv_->getLyXText();
2479 update(lt, BufferView::SELECT|BufferView::FITCUR);
2480 lt->deleteWordBackward(bv_);
2483 | BufferView::FITCUR
2484 | BufferView::CHANGE);
2485 moveCursorUpdate(false);
2486 owner_->showState();
2490 /* -------> Kill to end of line. */
2491 case LFUN_DELETE_LINE_FORWARD:
2493 LyXText * lt = bv_->getLyXText();
2495 update(lt, BufferView::SELECT|BufferView::FITCUR);
2496 lt->deleteLineForward(bv_);
2499 | BufferView::FITCUR
2500 | BufferView::CHANGE);
2501 moveCursorUpdate(false);
2505 /* -------> Set mark off. */
2508 LyXText * lt = bv_->getLyXText();
2511 update(lt, BufferView::SELECT|BufferView::FITCUR);
2512 lt->selection.cursor = lt->cursor;
2513 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2517 /* -------> Set mark on. */
2520 LyXText * lt = bv_->getLyXText();
2523 lt->selection.mark(true);
2524 update(lt, BufferView::SELECT|BufferView::FITCUR);
2525 lt->selection.cursor = lt->cursor;
2526 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2530 case LFUN_BACKSPACE:
2532 LyXText * lt = bv_->getLyXText();
2534 if (!lt->selection.set()) {
2535 if (owner_->getIntl()->getTrans().backspace()) {
2537 lt->selection.cursor = lt->cursor;
2540 | BufferView::FITCUR
2541 | BufferView::CHANGE);
2542 // It is possible to make it a lot faster still
2543 // just comment out the line below...
2549 owner_->showState();
2554 case LFUN_BACKSPACE_SKIP:
2556 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2557 LyXText * lt = bv_->getLyXText();
2559 LyXCursor cursor = lt->cursor;
2561 if (!lt->selection.set()) {
2562 if (cursor.pos() == 0
2563 && !(cursor.par()->params().spaceTop()
2564 == VSpace (VSpace::NONE))) {
2567 cursor.par()->params().lineTop(),
2568 cursor.par()->params().lineBottom(),
2569 cursor.par()->params().pagebreakTop(),
2570 cursor.par()->params().pagebreakBottom(),
2571 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2572 cursor.par()->params().spacing(),
2573 cursor.par()->params().align(),
2574 cursor.par()->params().labelWidthString(), 0);
2577 | BufferView::FITCUR
2578 | BufferView::CHANGE);
2581 lt->selection.cursor = cursor;
2584 | BufferView::FITCUR
2585 | BufferView::CHANGE);
2592 case LFUN_BREAKPARAGRAPH:
2594 LyXText * lt = bv_->getLyXText();
2597 lt->breakParagraph(bv_, 0);
2600 | BufferView::FITCUR
2601 | BufferView::CHANGE);
2602 lt->selection.cursor = lt->cursor;
2604 owner_->showState();
2608 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2610 LyXText * lt = bv_->getLyXText();
2613 lt->breakParagraph(bv_, 1);
2616 | BufferView::FITCUR
2617 | BufferView::CHANGE);
2618 lt->selection.cursor = lt->cursor;
2620 owner_->showState();
2624 case LFUN_BREAKPARAGRAPH_SKIP:
2626 // When at the beginning of a paragraph, remove
2627 // indentation and add a "defskip" at the top.
2628 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2629 LyXText * lt = bv_->getLyXText();
2631 LyXCursor cursor = lt->cursor;
2634 if (cursor.pos() == 0) {
2635 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2638 cursor.par()->params().lineTop(),
2639 cursor.par()->params().lineBottom(),
2640 cursor.par()->params().pagebreakTop(),
2641 cursor.par()->params().pagebreakBottom(),
2642 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2643 cursor.par()->params().spacing(),
2644 cursor.par()->params().align(),
2645 cursor.par()->params().labelWidthString(), 1);
2646 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2650 lt->breakParagraph(bv_, 0);
2651 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2656 | BufferView::FITCUR
2657 | BufferView::CHANGE);
2658 lt->selection.cursor = cursor;
2660 owner_->showState();
2664 case LFUN_PARAGRAPH_SPACING:
2666 LyXText * lt = bv_->getLyXText();
2668 Paragraph * par = lt->cursor.par();
2669 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2670 float cur_value = 1.0;
2671 if (cur_spacing == Spacing::Other) {
2672 cur_value = par->params().spacing().getValue();
2675 istringstream istr(argument.c_str());
2679 Spacing::Space new_spacing = cur_spacing;
2680 float new_value = cur_value;
2682 lyxerr << "Missing argument to `paragraph-spacing'"
2684 } else if (tmp == "single") {
2685 new_spacing = Spacing::Single;
2686 } else if (tmp == "onehalf") {
2687 new_spacing = Spacing::Onehalf;
2688 } else if (tmp == "double") {
2689 new_spacing = Spacing::Double;
2690 } else if (tmp == "other") {
2691 new_spacing = Spacing::Other;
2694 lyxerr << "new_value = " << tmpval << endl;
2697 } else if (tmp == "default") {
2698 new_spacing = Spacing::Default;
2700 lyxerr << _("Unknown spacing argument: ")
2701 << argument << endl;
2703 if (cur_spacing != new_spacing || cur_value != new_value) {
2704 par->params().spacing(Spacing(new_spacing, new_value));
2705 lt->redoParagraph(bv_);
2708 | BufferView::FITCUR
2709 | BufferView::CHANGE);
2714 case LFUN_INSET_TOGGLE:
2716 LyXText * lt = bv_->getLyXText();
2719 update(lt, BufferView::SELECT|BufferView::FITCUR);
2720 lt->toggleInset(bv_);
2721 update(lt, BufferView::SELECT|BufferView::FITCUR);
2733 InsetCommandParams p;
2734 if (action == LFUN_HTMLURL)
2735 p.setCmdName("htmlurl");
2737 p.setCmdName("url");
2738 owner_->getDialogs()->createUrl(p.getAsString());
2742 case LFUN_INSERT_URL:
2744 InsetCommandParams p;
2745 p.setFromString(argument);
2747 InsetUrl * inset = new InsetUrl(p);
2748 if (!insertInset(inset))
2751 updateInset(inset, true);
2755 case LFUN_INSET_ERT:
2756 insertAndEditInset(new InsetERT(buffer_->params));
2759 case LFUN_INSET_EXTERNAL:
2760 insertAndEditInset(new InsetExternal);
2763 case LFUN_INSET_FOOTNOTE:
2764 insertAndEditInset(new InsetFoot(buffer_->params));
2767 case LFUN_INSET_MARGINAL:
2768 insertAndEditInset(new InsetMarginal(buffer_->params));
2771 case LFUN_INSET_MINIPAGE:
2772 insertAndEditInset(new InsetMinipage(buffer_->params));
2775 case LFUN_INSERT_NOTE:
2776 insertAndEditInset(new InsetNote(buffer_->params));
2779 case LFUN_INSET_FLOAT:
2780 // check if the float type exist
2781 if (floatList.typeExist(argument)) {
2782 insertAndEditInset(new InsetFloat(buffer_->params,
2785 lyxerr << "Non-existent float type: "
2786 << argument << endl;
2790 case LFUN_INSET_WIDE_FLOAT:
2792 // check if the float type exist
2793 if (floatList.typeExist(argument)) {
2794 InsetFloat * new_inset =
2795 new InsetFloat(buffer_->params, argument);
2796 new_inset->wide(true);
2797 if (insertInset(new_inset))
2798 new_inset->edit(bv_);
2802 lyxerr << "Non-existent float type: "
2803 << argument << endl;
2810 case LFUN_INSET_LIST:
2811 insertAndEditInset(new InsetList);
2814 case LFUN_INSET_THEOREM:
2815 insertAndEditInset(new InsetTheorem);
2819 case LFUN_INSET_CAPTION:
2821 // Do we have a locking inset...
2822 if (bv_->theLockingInset()) {
2823 lyxerr << "Locking inset code: "
2824 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2825 InsetCaption * new_inset =
2826 new InsetCaption(buffer_->params);
2827 new_inset->setOwner(bv_->theLockingInset());
2828 new_inset->setAutoBreakRows(true);
2829 new_inset->setDrawFrame(0, InsetText::LOCKED);
2830 new_inset->setFrameColor(0, LColor::captionframe);
2831 if (insertInset(new_inset))
2832 new_inset->edit(bv_);
2839 case LFUN_INSET_TABULAR:
2843 if (!argument.empty())
2844 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2845 InsetTabular * new_inset =
2846 new InsetTabular(*buffer_, r, c);
2848 bv_->getLyXText()->real_current_font.isRightToLeft();
2849 if (!open_new_inset(new_inset, rtl))
2854 // --- lyxserver commands ----------------------------
2856 case LFUN_CHARATCURSOR:
2858 pos_type pos = bv_->getLyXText()->cursor.pos();
2859 if (pos < bv_->getLyXText()->cursor.par()->size())
2860 owner_->getLyXFunc()->setMessage(
2861 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2863 owner_->getLyXFunc()->setMessage("EOF");
2868 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2870 + tostr(bv_->getLyXText()->cursor.y()));
2877 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2878 lyxerr << "SETXY: Could not parse coordinates in '"
2879 << argument << std::endl;
2881 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2885 case LFUN_GETLAYOUT:
2886 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2891 LyXFont & font = bv_->getLyXText()->current_font;
2892 if (font.shape() == LyXFont::ITALIC_SHAPE)
2893 owner_->getLyXFunc()->setMessage("E");
2894 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2895 owner_->getLyXFunc()->setMessage("N");
2897 owner_->getLyXFunc()->setMessage("0");
2902 // --- accented characters ---------------------------
2905 case LFUN_CIRCUMFLEX:
2915 case LFUN_SPECIAL_CARON:
2918 case LFUN_HUNG_UMLAUT:
2921 if (argument.empty()) {
2923 owner_->getLyXFunc()->handleKeyFunc(action);
2925 owner_->getLyXFunc()->handleKeyFunc(action);
2926 owner_->getIntl()->getTrans()
2927 .TranslateAndInsert(argument[0], bv_->getLyXText());
2928 update(bv_->getLyXText(),
2930 | BufferView::FITCUR
2931 | BufferView::CHANGE);
2935 case LFUN_MATH_MACRO:
2936 mathDispatchMathMacro(bv_, argument);
2939 case LFUN_MATH_DELIM:
2940 mathDispatchMathDelim(bv_, argument);
2943 case LFUN_INSERT_MATRIX:
2944 mathDispatchInsertMatrix(bv_, argument);
2947 case LFUN_INSERT_MATH:
2948 mathDispatchInsertMath(bv_, argument);
2951 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2952 mathDispatchMathImportSelection(bv_, argument);
2955 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2956 mathDispatchMathDisplay(bv_, argument);
2959 case LFUN_MATH_MODE: // Open or create an inlined math inset
2960 mathDispatchMathMode(bv_, argument);
2963 case LFUN_GREEK: // Insert a single greek letter
2964 mathDispatchGreek(bv_, argument);
2967 case LFUN_CITATION_INSERT:
2969 InsetCommandParams p;
2970 p.setFromString(argument);
2972 InsetCitation * inset = new InsetCitation(p);
2973 if (!insertInset(inset))
2976 updateInset(inset, true);
2980 case LFUN_INSERT_BIBTEX:
2982 // ale970405+lasgoutt970425
2983 // The argument can be up to two tokens separated
2984 // by a space. The first one is the bibstyle.
2985 string const db = token(argument, ' ', 0);
2986 string const bibstyle = token(argument, ' ', 1);
2988 InsetCommandParams p("BibTeX", db, bibstyle);
2989 InsetBibtex * inset = new InsetBibtex(p);
2991 if (insertInset(inset)) {
2992 if (argument.empty())
2999 // BibTeX data bases
3000 case LFUN_BIBDB_ADD:
3002 InsetBibtex * inset =
3003 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3005 inset->addDatabase(argument);
3010 case LFUN_BIBDB_DEL:
3012 InsetBibtex * inset =
3013 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3015 inset->delDatabase(argument);
3020 case LFUN_BIBTEX_STYLE:
3022 InsetBibtex * inset =
3023 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3025 inset->setOptions(argument);
3030 case LFUN_INDEX_CREATE:
3032 InsetCommandParams p("index");
3033 if (argument.empty()) {
3034 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3035 p.setContents(idxstring);
3037 p.setContents(argument);
3040 owner_->getDialogs()->createIndex(p.getAsString());
3044 case LFUN_INDEX_INSERT:
3046 InsetCommandParams p;
3047 p.setFromString(argument);
3048 InsetIndex * inset = new InsetIndex(p);
3050 if (!insertInset(inset))
3053 updateInset(inset, true);
3057 case LFUN_INDEX_INSERT_LAST:
3059 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3060 if (!idxstring.empty()) {
3061 owner_->message(_("Word `")
3062 + idxstring + _(("' indexed.")));
3063 InsetCommandParams p("index", idxstring);
3064 InsetIndex * inset = new InsetIndex(p);
3066 if (!insertInset(inset))
3069 updateInset(inset, true);
3074 case LFUN_INDEX_PRINT:
3076 InsetCommandParams p("printindex");
3077 Inset * inset = new InsetPrintIndex(p);
3078 if (!insertInset(inset, "Standard"))
3083 case LFUN_PARENTINSERT:
3085 lyxerr << "arg " << argument << endl;
3086 InsetCommandParams p("lyxparent", argument);
3087 Inset * inset = new InsetParent(p, *buffer_);
3088 if (!insertInset(inset, "Standard"))
3094 case LFUN_CHILD_INSERT:
3096 InsetInclude::Params p;
3097 p.cparams.setFromString(argument);
3098 p.masterFilename_ = buffer_->fileName();
3100 InsetInclude * inset = new InsetInclude(p);
3101 if (!insertInset(inset))
3104 updateInset(inset, true);
3105 bv_->owner()->getDialogs()->showInclude(inset);
3110 case LFUN_FLOAT_LIST:
3112 // We should check the argument for validity. (Lgb)
3113 Inset * inset = new InsetFloatList(argument);
3114 if (!insertInset(inset, "Standard"))
3119 case LFUN_THESAURUS_ENTRY:
3121 string arg = argument;
3124 arg = bv_->getLyXText()->selectionAsString(buffer_,
3128 if (arg.size() > 100 || arg.empty()) {
3129 // Get word or selection
3130 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3131 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3132 // FIXME: where is getLyXText()->unselect(bv_) ?
3136 bv_->owner()->getDialogs()->showThesaurus(arg);
3140 case LFUN_SELFINSERT:
3142 if (argument.empty()) break;
3144 /* Automatically delete the currently selected
3145 * text and replace it with what is being
3146 * typed in now. Depends on lyxrc settings
3147 * "auto_region_delete", which defaults to
3150 LyXText * lt = bv_->getLyXText();
3152 if (lyxrc.auto_region_delete) {
3153 if (lt->selection.set()) {
3154 lt->cutSelection(bv_, false, false);
3157 | BufferView::FITCUR
3158 | BufferView::CHANGE);
3163 LyXFont const old_font(lt->real_current_font);
3165 string::const_iterator cit = argument.begin();
3166 string::const_iterator end = argument.end();
3167 for (; cit != end; ++cit) {
3168 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3173 | BufferView::FITCUR
3174 | BufferView::CHANGE);
3176 lt->selection.cursor = lt->cursor;
3177 moveCursorUpdate(false);
3179 // real_current_font.number can change so we need to
3180 // update the minibuffer
3181 if (old_font != lt->real_current_font)
3182 owner_->showState();
3187 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3189 time_t now_time_t = time(NULL);
3190 struct tm * now_tm = localtime(&now_time_t);
3191 setlocale(LC_TIME, "");
3193 if (!argument.empty())
3196 arg = lyxrc.date_insert_format;
3198 int const datetmp_len =
3199 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3201 LyXText * lt = bv_->getLyXText();
3203 for (int i = 0; i < datetmp_len; i++) {
3204 lt->insertChar(bv_, datetmp[i]);
3207 | BufferView::FITCUR
3208 | BufferView::CHANGE);
3211 lt->selection.cursor = lt->cursor;
3212 moveCursorUpdate(false);
3216 case LFUN_UNKNOWN_ACTION:
3217 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3228 void BufferView::Pimpl::newline()
3231 LyXText * lt = bv_->getLyXText();
3235 | BufferView::FITCUR);
3236 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3239 | BufferView::FITCUR
3240 | BufferView::CHANGE);
3245 void BufferView::Pimpl::hfill()
3248 LyXText * lt = bv_->getLyXText();
3252 | BufferView::FITCUR);
3253 lt->insertChar(bv_, Paragraph::META_HFILL);
3256 | BufferView::FITCUR
3257 | BufferView::CHANGE);
3262 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3265 LyXText * lt = bv_->getLyXText();
3268 update(lt, BufferView::SELECT|BufferView::FITCUR);
3269 InsetSpecialChar * new_inset =
3270 new InsetSpecialChar(kind);
3271 if (!insertInset(new_inset))
3274 updateInset(new_inset, true);
3279 void BufferView::Pimpl::smartQuote()
3281 LyXText const * lt = bv_->getLyXText();
3282 Paragraph const * par = lt->cursor.par();
3283 pos_type pos = lt->cursor.pos();
3287 || (par->isInset(pos - 1)
3288 && par->getInset(pos - 1)->isSpace()))
3291 c = par->getChar(pos - 1);
3296 LyXLayout const & style =
3297 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3299 if (style.pass_thru ||
3300 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3301 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3305 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3307 if (insertInset(inset))
3314 // Open and lock an updatable inset
3315 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3317 LyXText * lt = bv_->getLyXText();
3321 if (!insertInset(new_inset)) {
3325 new_inset->edit(bv_, !behind);
3330 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3332 // if we are in a locking inset we should try to insert the
3333 // inset there otherwise this is a illegal function now
3334 if (bv_->theLockingInset()) {
3335 if (bv_->theLockingInset()->insetAllowed(inset))
3336 return bv_->theLockingInset()->insertInset(bv_, inset);
3340 // not quite sure if we want this...
3341 setCursorParUndo(bv_);
3344 beforeChange(bv_->text);
3345 if (!lout.empty()) {
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3347 bv_->text->breakParagraph(bv_);
3348 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3350 if (bv_->text->cursor.par()->size()) {
3351 bv_->text->cursorLeft(bv_);
3353 bv_->text->breakParagraph(bv_);
3354 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3358 LyXTextClass const & tclass =
3359 textclasslist[buffer_->params.textclass];
3360 bool hasLayout = tclass.hasLayout(lres);
3361 string lay = tclass.defaultLayoutName();
3363 if (hasLayout != false) {
3367 // layout not fount using default
3368 lay = tclass.defaultLayoutName();
3371 bv_->text->setLayout(bv_, lay);
3373 bv_->text->setParagraph(bv_, 0, 0,
3375 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3383 bv_->text->insertInset(bv_, inset);
3384 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3391 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3393 if (!inset || !available())
3396 // first check for locking insets
3397 if (bv_->theLockingInset()) {
3398 if (bv_->theLockingInset() == inset) {
3399 if (bv_->text->updateInset(bv_, inset)) {
3402 buffer_->markDirty();
3407 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3408 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3411 buffer_->markDirty();
3419 // then check if the inset is a top_level inset (has no owner)
3420 // if yes do the update as always otherwise we have to update the
3421 // toplevel inset where this inset is inside
3422 Inset * tl_inset = inset;
3423 while(tl_inset->owner())
3424 tl_inset = tl_inset->owner();
3426 if (tl_inset == inset) {
3427 update(bv_->text, BufferView::UPDATE);
3428 if (bv_->text->updateInset(bv_, inset)) {
3432 | BufferView::FITCUR
3433 | BufferView::CHANGE);
3435 update(bv_->text, SELECT);
3439 } else if (static_cast<UpdatableInset *>(tl_inset)
3440 ->updateInsetInInset(bv_, inset))
3442 if (bv_->text->updateInset(bv_, tl_inset)) {
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);