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_);
333 // See if we have a text in TextCache that fits
334 // the new buffer_ with the correct width.
335 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
337 if (lyxerr.debugging()) {
338 lyxerr << "Found a LyXText that fits:\n";
339 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
341 // Set the owner of the newly found text
342 // bv_->text->owner(bv_);
343 if (lyxerr.debugging())
344 textcache.show(lyxerr, "resizeCurrentBuffer");
346 bv_->text = new LyXText(bv_);
347 bv_->text->init(bv_);
353 bv_->text->selection.set(true);
354 /* at this point just to avoid the Delete-Empty-Paragraph
355 * Mechanism when setting the cursor */
356 bv_->text->selection.mark(mark_set);
358 bv_->text->setCursor(bv_, selstartpar, selstartpos);
359 bv_->text->selection.cursor = bv_->text->cursor;
360 bv_->text->setCursor(bv_, selendpar, selendpos);
361 bv_->text->setSelection(bv_);
362 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->setCursor(bv_, par, pos);
365 bv_->text->selection.cursor = bv_->text->cursor;
366 bv_->text->selection.set(false);
368 // remake the inset locking
369 bv_->theLockingInset(the_locking_inset);
371 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
372 // please tell me WHY the heck you deactivated this code, whoever
373 // 'you' are (Jug 20020311)
375 buffer_->resizeInsets(bv_);
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()) return;
594 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
596 // ok ok, this is a hack.
597 if (button == 4 || button == 5) {
600 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
603 scrollDown(lyxrc.wheel_jump);
608 if (bv_->theLockingInset()) {
609 // We are in inset locking mode
611 /* Check whether the inset was hit. If not reset mode,
612 otherwise give the event to the inset */
613 if (inset_hit == bv_->theLockingInset()) {
614 bv_->theLockingInset()->
615 insetButtonPress(bv_,xpos, ypos,button);
618 bv_->unlockInset(bv_->theLockingInset());
623 selection_possible = true;
624 screen_->hideCursor();
626 int const screen_first = bv_->text->first_y;
628 // Middle button press pastes if we have a selection
629 bool paste_internally = false;
631 && bv_->text->selection.set()) {
632 owner_->getLyXFunc()->dispatch(LFUN_COPY);
633 paste_internally = true;
636 // Clear the selection
637 screen_->toggleSelection(bv_->text, bv_);
638 bv_->text->clearSelection();
639 bv_->text->fullRebreak(bv_);
643 // Single left click in math inset?
644 if (isHighlyEditableInset(inset_hit)) {
645 // Highly editable inset, like math
646 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
647 selection_possible = false;
648 owner_->updateLayoutChoice();
649 owner_->message(inset->editMessage());
650 // IMO the inset has to be first in edit-mode and then we send the
651 // button press. (Jug 20020222)
652 inset->edit(bv_); //, xpos, ypos, button);
653 inset->insetButtonPress(bv_, xpos, ypos, button);
657 // Right click on a footnote flag opens float menu
659 selection_possible = false;
663 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
664 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
666 bv_->text->selection.cursor = bv_->text->cursor;
667 bv_->text->cursor.x_fix(bv_->text->cursor.x());
669 owner_->updateLayoutChoice();
671 selection_possible = false;
674 // Insert primary selection with middle mouse
675 // if there is a local selection in the current buffer,
678 if (paste_internally)
679 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
681 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
683 selection_possible = false;
689 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
695 LyXText * text = bv_->getLyXText();
697 if (text->bv_owner && bv_->theLockingInset())
700 if (screen_.get() && button == 1) {
701 if (text->bv_owner) {
702 screen_->hideCursor();
703 screen_->toggleSelection(text, bv_);
704 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
705 screen_->toggleSelection(text, bv_, false);
707 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
709 /* This will fit the cursor on the screen
711 update(text, BufferView::SELECT|BufferView::FITCUR);
716 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
722 LyXText * text = bv_->getLyXText();
724 if (text->bv_owner && bv_->theLockingInset())
727 if (screen_.get() && (button == 1)) {
728 if (text->bv_owner) {
729 screen_->hideCursor();
730 screen_->toggleSelection(text, bv_);
732 text->cursorHome(bv_);
733 text->selection.cursor = text->cursor;
734 text->cursorEnd(bv_);
735 text->setSelection(bv_);
736 if (text->bv_owner) {
737 screen_->toggleSelection(text, bv_, false);
739 /* This will fit the cursor on the screen
741 update(text, BufferView::SELECT|BufferView::FITCUR);
746 void BufferView::Pimpl::selectionRequested()
751 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
754 workarea_.putClipboard(sel);
759 void BufferView::Pimpl::selectionLost()
761 if (active() && available()) {
764 bv_->getLyXText()->clearSelection();
770 void BufferView::Pimpl::enterView()
772 if (active() && available()) {
773 SetXtermCursor(workarea_.getWin());
774 using_xterm_cursor = true;
779 void BufferView::Pimpl::leaveView()
781 if (using_xterm_cursor) {
782 XUndefineCursor(fl_get_display(), workarea_.getWin());
783 using_xterm_cursor = false;
788 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
791 if (!buffer_ || !screen_.get()) return;
793 // If we hit an inset, we have the inset coordinates in these
794 // and inset_hit points to the inset. If we do not hit an
795 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
796 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
798 if (bv_->theLockingInset()) {
799 // We are in inset locking mode.
801 /* LyX does a kind of work-area grabbing for insets.
802 Only a ButtonPress Event outside the inset will
803 force a insetUnlock. */
804 bv_->theLockingInset()->
805 insetButtonRelease(bv_, x, y, button);
809 selection_possible = false;
816 workarea_.haveSelection(bv_->getLyXText()->selection.set());
821 owner_->updateMenubar();
822 owner_->updateToolbar();
824 // Did we hit an editable inset?
826 selection_possible = false;
828 // if we reach this point with a selection, it
829 // must mean we are currently selecting.
830 // But we don't want to open the inset
831 // because that is annoying for the user.
832 // So just pretend we didn't hit it.
833 // this is OK because a "kosher" ButtonRelease
834 // will follow a ButtonPress that clears
836 // Note this also fixes selection drawing
837 // problems if we end up opening an inset
838 if (bv_->getLyXText()->selection.set())
841 // CHECK fix this proper in 0.13
842 // well, maybe 13.0 !!!!!!!!!
844 // Following a ref shouldn't issue
845 // a push on the undo-stack
846 // anylonger, now that we have
847 // keybindings for following
848 // references and returning from
849 // references. IMHO though, it
850 // should be the inset's own business
851 // to push or not push on the undo
852 // stack. They don't *have* to
853 // alter the document...
855 // ...or maybe the SetCursorParUndo()
856 // below isn't necessary at all anylonger?
857 if (inset_hit->lyxCode() == Inset::REF_CODE) {
858 setCursorParUndo(bv_);
861 owner_->message(inset_hit->editMessage());
863 if (isHighlyEditableInset(inset_hit)) {
864 // Highly editable inset, like math
865 UpdatableInset *inset = (UpdatableInset *)inset_hit;
866 inset->insetButtonRelease(bv_, x, y, button);
868 inset_hit->insetButtonRelease(bv_, x, y, button);
869 inset_hit->edit(bv_, x, y, button);
874 // Maybe we want to edit a bibitem ale970302
875 if (bv_->text->cursor.par()->bibkey && x < 20 +
876 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
877 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
884 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
885 LyXCursor const & cursor) const
887 Paragraph /*const*/ & par = *cursor.par();
888 pos_type const pos = cursor.pos();
890 lyx::Assert(par.getInset(pos));
892 Inset const & inset(*par.getInset(pos));
894 LyXFont const & font = text.getFont(buffer_, &par, pos);
896 int const width = inset.width(bv_, font);
897 int const inset_x = font.isVisibleRightToLeft()
898 ? (cursor.x() - width) : cursor.x();
901 inset_x + inset.scroll(),
903 cursor.y() - inset.ascent(bv_, font),
904 cursor.y() + inset.descent(bv_, font));
908 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
909 LyXCursor const & cursor,
910 int & x, int & y) const
912 pos_type const pos(cursor.pos());
913 Paragraph /*const*/ & par(*cursor.par());
915 if (pos >= par.size() || !par.isInset(pos)) {
919 Inset /*const*/ * inset = par.getInset(pos);
921 if (!isEditableInset(inset)) {
925 Box b(insetDimensions(text, cursor));
927 if (!b.contained(x, y)) {
928 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
929 << " box " << b << endl;
933 text.setCursor(bv_, &par, pos, true);
936 // The origin of an inset is on the baseline
937 y -= (text.cursor.y());
943 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
948 int y_tmp = y + text->first_y;
951 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
953 Inset * inset(checkInset(*text, cursor, x, y_tmp));
960 // look at previous position
962 if (cursor.pos() == 0) {
967 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
969 inset = checkInset(*text, cursor, x, y_tmp);
977 void BufferView::Pimpl::workAreaExpose()
979 static int work_area_width;
980 static unsigned int work_area_height;
982 bool const widthChange = workarea_.workWidth() != work_area_width;
983 bool const heightChange = workarea_.height() != work_area_height;
985 // update from work area
986 work_area_width = workarea_.workWidth();
987 work_area_height = workarea_.height();
990 // The visible LyXView need a resize
993 // Remove all texts from the textcache
994 // This is not _really_ what we want to do. What
995 // we really want to do is to delete in textcache
996 // that does not have a BufferView with matching
997 // width, but as long as we have only one BufferView
998 // deleting all gives the same result.
999 if (lyxerr.debugging())
1000 textcache.show(lyxerr, "Expose delete all");
1002 } else if (heightChange) {
1003 // Rebuild image of current screen
1005 // fitCursor() ensures we don't jump back
1006 // to the start of the document on vertical
1010 // The main window size has changed, repaint most stuff
1012 } else if (screen_.get())
1013 screen_->redraw(bv_->text, bv_);
1015 // Grey box when we don't have a buffer
1016 workarea_.greyOut();
1019 // always make sure that the scrollbar is sane.
1021 owner_->updateLayoutChoice();
1026 void BufferView::Pimpl::update()
1028 if (screen_.get() &&
1029 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1031 LyXText::text_status st = bv_->text->status();
1032 screen_->update(bv_->text, bv_);
1034 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1035 if (bv_->text->fullRebreak(bv_)) {
1036 st = LyXText::NEED_MORE_REFRESH;
1037 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1038 bv_->text->cursor.pos());
1041 bv_->text->status(bv_, st);
1042 screen_->update(bv_->text, bv_);
1044 // do this here instead of in the screen::update because of
1046 bv_->text->status(bv_, LyXText::UNCHANGED);
1052 // Values used when calling update:
1054 // -2 - update, move sel_cursor if selection, fitcursor
1055 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1056 // 0 - update, move sel_cursor if selection, fitcursor
1057 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1058 // 3 - update, move sel_cursor if selection
1061 // a simple redraw of the parts that need refresh
1063 // move sel_cursor if selection -
1064 // the text's sel_cursor is moved if there is selection is progress
1067 // fitCursor() is called and the scrollbar updated
1070 // the buffer is marked dirty.
1079 // UPDATE_ONLY = UPDATE;
1080 // UPDATE_SELECT = UPDATE | SELECT;
1081 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1082 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1084 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1085 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1086 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1087 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1088 // update(3) -> update(1) -> update(1) -> update(SELECT)
1090 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1092 owner_->updateLayoutChoice();
1094 if (!text->selection.set() && (f & SELECT)) {
1095 text->selection.cursor = text->cursor;
1098 text->fullRebreak(bv_);
1100 if (text->inset_owner) {
1101 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1102 updateInset(text->inset_owner, false);
1112 buffer_->markDirty();
1117 // Callback for cursor timer
1118 void BufferView::Pimpl::cursorToggle()
1121 cursor_timeout.restart();
1125 if (!screen_.get()) {
1126 cursor_timeout.restart();
1131 extern void reapSpellchecker(void);
1134 if (!bv_->theLockingInset()) {
1135 screen_->cursorToggle(bv_);
1137 bv_->theLockingInset()->toggleInsetCursor(bv_);
1140 cursor_timeout.restart();
1144 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1146 if (!text->cursor.row()->previous())
1149 int y = text->first_y;
1150 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_y + 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)
1202 void BufferView::Pimpl::beforeChange(LyXText * text)
1205 text->clearSelection();
1209 void BufferView::Pimpl::savePosition(unsigned int i)
1211 if (i >= saved_positions_num)
1213 saved_positions[i] = Position(buffer_->fileName(),
1214 bv_->text->cursor.par()->id(),
1215 bv_->text->cursor.pos());
1218 str << _("Saved bookmark") << ' ' << i;
1219 owner_->message(str.str().c_str());
1224 void BufferView::Pimpl::restorePosition(unsigned int i)
1226 if (i >= saved_positions_num)
1229 string const fname = saved_positions[i].filename;
1231 beforeChange(bv_->text);
1233 if (fname != buffer_->fileName()) {
1234 Buffer * b = bufferlist.exists(fname) ?
1235 bufferlist.getBuffer(fname) :
1236 bufferlist.loadLyXFile(fname); // don't ask, just load it
1237 if (b != 0) buffer(b);
1240 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1244 bv_->text->setCursor(bv_, par,
1245 min(par->size(), saved_positions[i].par_pos));
1247 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1250 str << _("Moved to bookmark") << ' ' << i;
1251 owner_->message(str.str().c_str());
1256 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1258 if (i >= saved_positions_num)
1261 return !saved_positions[i].filename.empty();
1265 void BufferView::Pimpl::setState()
1267 if (!lyxrc.rtl_support)
1270 LyXText * text = bv_->getLyXText();
1271 if (text->real_current_font.isRightToLeft()) {
1272 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1273 owner_->getIntl()->KeyMapSec();
1275 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1276 owner_->getIntl()->KeyMapPrim();
1281 void BufferView::Pimpl::insetSleep()
1283 if (bv_->theLockingInset() && !inset_slept) {
1284 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1285 bv_->theLockingInset()->insetUnlock(bv_);
1291 void BufferView::Pimpl::insetWakeup()
1293 if (bv_->theLockingInset() && inset_slept) {
1294 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1295 inset_slept = false;
1300 void BufferView::Pimpl::insetUnlock()
1302 if (bv_->theLockingInset()) {
1304 bv_->theLockingInset()->insetUnlock(bv_);
1305 bv_->theLockingInset(0);
1307 inset_slept = false;
1312 bool BufferView::Pimpl::focus() const
1314 return workarea_.hasFocus();
1318 void BufferView::Pimpl::focus(bool f)
1320 if (f) workarea_.setFocus();
1324 bool BufferView::Pimpl::active() const
1326 return workarea_.active();
1330 bool BufferView::Pimpl::belowMouse() const
1332 return workarea_.belowMouse();
1336 void BufferView::Pimpl::showCursor()
1338 if (screen_.get()) {
1339 if (bv_->theLockingInset())
1340 bv_->theLockingInset()->showInsetCursor(bv_);
1342 screen_->showCursor(bv_->text, bv_);
1347 void BufferView::Pimpl::hideCursor()
1349 if (screen_.get()) {
1350 if (!bv_->theLockingInset())
1351 // bv_->theLockingInset()->hideInsetCursor(bv_);
1353 screen_->hideCursor();
1358 void BufferView::Pimpl::toggleSelection(bool b)
1360 if (screen_.get()) {
1361 if (bv_->theLockingInset())
1362 bv_->theLockingInset()->toggleSelection(bv_, b);
1363 screen_->toggleSelection(bv_->text, bv_, b);
1368 void BufferView::Pimpl::toggleToggle()
1371 screen_->toggleToggle(bv_->text, bv_);
1375 void BufferView::Pimpl::center()
1377 beforeChange(bv_->text);
1378 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1379 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1381 screen_->draw(bv_->text, bv_, 0);
1383 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1388 void BufferView::Pimpl::pasteClipboard(bool asPara)
1390 if (!buffer_) return;
1392 screen_->hideCursor();
1393 beforeChange(bv_->text);
1395 string const clip(workarea_.getClipboard());
1397 if (clip.empty()) return;
1400 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1402 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1404 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1408 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1410 workarea_.putClipboard(stuff);
1415 * Dispatch functions for actions which can be valid for BufferView->text
1416 * and/or InsetText->text!!!
1421 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1423 LyXText * lt = bv_->getLyXText();
1425 if (selecting || lt->selection.mark()) {
1426 lt->setSelection(bv_);
1430 update(lt, BufferView::SELECT|BufferView::FITCUR);
1433 /* ---> Everytime the cursor is moved, show the current font state. */
1434 // should this too me moved out of this func?
1435 //owner->showState();
1440 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1442 LyXCursor cursor = bv_->getLyXText()->cursor;
1443 Buffer::inset_iterator it =
1444 find_if(Buffer::inset_iterator(
1445 cursor.par(), cursor.pos()),
1446 buffer_->inset_iterator_end(),
1447 lyx::compare_memfun(&Inset::lyxCode, code));
1448 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1452 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1454 string filename = filen;
1456 if (filename.empty()) {
1457 // Launch a file browser
1458 string initpath = lyxrc.document_path;
1461 string const trypath = owner_->buffer()->filePath();
1462 // If directory is writeable, use this as default.
1463 if (IsDirWriteable(trypath))
1467 FileDialog fileDlg(bv_->owner(),
1468 _("Select LyX document to insert"),
1470 make_pair(string(_("Documents|#o#O")),
1471 string(lyxrc.document_path)),
1472 make_pair(string(_("Examples|#E#e")),
1473 string(AddPath(system_lyxdir, "examples"))));
1475 FileDialog::Result result =
1476 fileDlg.Select(initpath,
1477 _("*.lyx| LyX Documents (*.lyx)"));
1479 if (result.first == FileDialog::Later)
1482 filename = result.second;
1484 // check selected filename
1485 if (filename.empty()) {
1486 owner_->message(_("Canceled."));
1491 // get absolute path of file and add ".lyx" to the filename if
1493 filename = FileSearch(string(), filename, "lyx");
1495 string const disp_fn(MakeDisplayPath(filename));
1498 s1 << _("Inserting document") << ' '
1499 << disp_fn << " ...";
1500 owner_->message(s1.str().c_str());
1501 bool const res = bv_->insertLyXFile(filename);
1504 str << _("Document") << ' ' << disp_fn
1505 << ' ' << _("inserted.");
1506 owner_->message(str.str().c_str());
1509 str << _("Could not insert document") << ' '
1511 owner_->message(str.str().c_str());
1516 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1518 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1519 << action <<"] arg[" << argument << "]" << endl;
1522 // --- Misc -------------------------------------------
1526 LyXText * lt = bv_->getLyXText();
1527 lt->toggleAppendix(bv_);
1530 | BufferView::FITCUR
1531 | BufferView::CHANGE);
1536 case LFUN_TOC_INSERT:
1538 InsetCommandParams p;
1539 p.setCmdName("tableofcontents");
1540 Inset * inset = new InsetTOC(p);
1541 if (!insertInset(inset, "Standard"))
1546 case LFUN_SCROLL_INSET:
1547 // this is not handled here as this funktion is only aktive
1548 // if we have a locking_inset and that one is (or contains)
1552 case LFUN_INSET_GRAPHICS:
1554 Inset * new_inset = new InsetGraphics;
1555 if (!insertInset(new_inset)) {
1558 // this is need because you don't use a inset->Edit()
1559 updateInset(new_inset, true);
1560 new_inset->edit(bv_);
1570 case LFUN_PASTESELECTION:
1572 bool asPara = false;
1573 if (argument == "paragraph")
1575 pasteClipboard(asPara);
1587 case LFUN_LAYOUT_COPY:
1588 bv_->copyEnvironment();
1591 case LFUN_LAYOUT_PASTE:
1592 bv_->pasteEnvironment();
1596 case LFUN_GOTOERROR:
1597 gotoInset(Inset::ERROR_CODE, false);
1601 gotoInset(Inset::IGNORE_CODE, false);
1604 case LFUN_REFERENCE_GOTO:
1606 vector<Inset::Code> tmp;
1607 tmp.push_back(Inset::LABEL_CODE);
1608 tmp.push_back(Inset::REF_CODE);
1609 gotoInset(tmp, true);
1613 case LFUN_HYPHENATION:
1614 specialChar(InsetSpecialChar::HYPHENATION);
1617 case LFUN_LIGATURE_BREAK:
1618 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1622 specialChar(InsetSpecialChar::LDOTS);
1625 case LFUN_END_OF_SENTENCE:
1626 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1629 case LFUN_MENU_SEPARATOR:
1630 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1638 changeDepth(bv_, bv_->getLyXText(), 0);
1641 case LFUN_DEPTH_MIN:
1642 changeDepth(bv_, bv_->getLyXText(), -1);
1645 case LFUN_DEPTH_PLUS:
1646 changeDepth(bv_, bv_->getLyXText(), 1);
1650 owner_->getDialogs()->setUserFreeFont();
1653 case LFUN_FILE_INSERT:
1654 MenuInsertLyXFile(argument);
1657 case LFUN_FILE_INSERT_ASCII_PARA:
1658 InsertAsciiFile(bv_, argument, true);
1661 case LFUN_FILE_INSERT_ASCII:
1662 InsertAsciiFile(bv_, argument, false);
1667 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1668 << argument << endl;
1670 // Derive layout number from given argument (string)
1671 // and current buffer's textclass (number). */
1672 textclass_type tclass = buffer_->params.textclass;
1674 textclasslist[tclass].hasLayout(argument);
1675 string layout = argument;
1677 // If the entry is obsolete, use the new one instead.
1679 string const & obs = textclasslist[tclass][layout]
1686 owner_->getLyXFunc()->setErrorMessage(
1687 string(N_("Layout ")) + argument +
1692 if (current_layout != layout) {
1693 LyXText * lt = bv_->getLyXText();
1695 current_layout = layout;
1698 | BufferView::FITCUR);
1699 lt->setLayout(bv_, layout);
1700 owner_->setLayout(layout);
1703 | BufferView::FITCUR
1704 | BufferView::CHANGE);
1711 lang(bv_, argument);
1713 owner_->showState();
1718 owner_->showState();
1723 owner_->showState();
1728 owner_->showState();
1733 owner_->showState();
1738 owner_->showState();
1743 owner_->showState();
1748 owner_->showState();
1751 case LFUN_UNDERLINE:
1753 owner_->showState();
1756 case LFUN_FONT_SIZE:
1757 fontSize(bv_, argument);
1758 owner_->showState();
1761 case LFUN_FONT_STATE:
1762 owner_->getLyXFunc()->setMessage(currentState(bv_));
1765 case LFUN_UPCASE_WORD:
1767 LyXText * lt = bv_->getLyXText();
1771 | BufferView::FITCUR);
1772 lt->changeCase(bv_, LyXText::text_uppercase);
1773 if (lt->inset_owner)
1774 updateInset(lt->inset_owner, true);
1777 | BufferView::FITCUR
1778 | BufferView::CHANGE);
1782 case LFUN_LOWCASE_WORD:
1784 LyXText * lt = bv_->getLyXText();
1786 update(lt, BufferView::SELECT|BufferView::FITCUR);
1787 lt->changeCase(bv_, LyXText::text_lowercase);
1788 if (lt->inset_owner)
1789 updateInset(lt->inset_owner, true);
1792 | BufferView::FITCUR
1793 | BufferView::CHANGE);
1797 case LFUN_CAPITALIZE_WORD:
1799 LyXText * lt = bv_->getLyXText();
1801 update(lt, BufferView::SELECT|BufferView::FITCUR);
1802 lt->changeCase(bv_, LyXText::text_capitalization);
1803 if (lt->inset_owner)
1804 updateInset(lt->inset_owner, true);
1807 | BufferView::FITCUR
1808 | BufferView::CHANGE);
1812 case LFUN_TRANSPOSE_CHARS:
1814 LyXText * lt = bv_->getLyXText();
1816 update(lt, BufferView::SELECT|BufferView::FITCUR);
1817 lt->transposeChars(*bv_);
1818 if (lt->inset_owner)
1819 updateInset(lt->inset_owner, true);
1822 | BufferView::FITCUR
1823 | BufferView::CHANGE);
1828 case LFUN_INSERT_LABEL:
1829 MenuInsertLabel(bv_, argument);
1832 case LFUN_REF_INSERT:
1833 if (argument.empty()) {
1834 InsetCommandParams p("ref");
1835 owner_->getDialogs()->createRef(p.getAsString());
1837 InsetCommandParams p;
1838 p.setFromString(argument);
1840 InsetRef * inset = new InsetRef(p, *buffer_);
1841 if (!insertInset(inset))
1844 updateInset(inset, true);
1848 case LFUN_BOOKMARK_SAVE:
1849 savePosition(strToUnsignedInt(argument));
1852 case LFUN_BOOKMARK_GOTO:
1853 restorePosition(strToUnsignedInt(argument));
1858 string label(argument);
1859 if (label.empty()) {
1861 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1863 label = inset->getContents();
1868 if (!label.empty()) {
1869 //bv_->savePosition(0);
1870 if (!bv_->gotoLabel(label))
1871 Alert::alert(_("Error"),
1872 _("Couldn't find this label"),
1873 _("in current document."));
1878 // --- Cursor Movements -----------------------------
1881 LyXText * lt = bv_->getLyXText();
1883 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1884 if (!lt->selection.mark())
1886 update(lt, BufferView::SELECT|BufferView::FITCUR);
1888 lt->cursorLeft(bv_, false);
1889 if (lt->cursor.pos() < lt->cursor.par()->size()
1890 && lt->cursor.par()->isInset(lt->cursor.pos())
1891 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1892 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1893 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1895 tmpinset->edit(bv_, false);
1897 tmpinset->edit(bv_);
1901 lt->cursorRight(bv_, false);
1903 moveCursorUpdate(false);
1904 owner_->showState();
1910 // This is soooo ugly. Isn`t it possible to make
1911 // it simpler? (Lgb)
1912 LyXText * lt = bv_->getLyXText();
1913 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1914 if (!lt->selection.mark())
1916 update(lt, BufferView::SELECT|BufferView::FITCUR);
1917 LyXCursor const cur = lt->cursor;
1919 lt->cursorLeft(bv_, false);
1920 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1921 lt->cursor.pos() < lt->cursor.par()->size() &&
1922 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1923 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1924 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1925 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1927 tmpinset->edit(bv_);
1929 tmpinset->edit(bv_, false);
1933 lt->cursorRight(bv_, false);
1936 moveCursorUpdate(false);
1937 owner_->showState();
1943 LyXText * lt = bv_->getLyXText();
1945 if (!lt->selection.mark())
1947 update(lt, BufferView::UPDATE);
1950 moveCursorUpdate(false);
1951 owner_->showState();
1957 LyXText * lt = bv_->getLyXText();
1959 if (!lt->selection.mark())
1961 update(lt, BufferView::UPDATE);
1962 lt->cursorDown(bv_);
1964 moveCursorUpdate(false);
1965 owner_->showState();
1969 case LFUN_UP_PARAGRAPH:
1971 LyXText * lt = bv_->getLyXText();
1973 if (!lt->selection.mark())
1975 update(lt, BufferView::UPDATE);
1976 lt->cursorUpParagraph(bv_);
1978 moveCursorUpdate(false);
1979 owner_->showState();
1983 case LFUN_DOWN_PARAGRAPH:
1985 LyXText * lt = bv_->getLyXText();
1987 if (!lt->selection.mark())
1989 update(lt, BufferView::UPDATE);
1990 lt->cursorDownParagraph(bv_);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1999 LyXText * lt = bv_->getLyXText();
2001 if (!lt->selection.mark())
2003 update(lt, BufferView::UPDATE);
2006 moveCursorUpdate(false);
2007 owner_->showState();
2013 LyXText * lt = bv_->getLyXText();
2015 if (!lt->selection.mark())
2017 update(lt, BufferView::UPDATE);
2020 moveCursorUpdate(false);
2021 owner_->showState();
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2031 update(lt, BufferView::SELECT|BufferView::FITCUR);
2032 lt->cursorHome(bv_);
2034 moveCursorUpdate(false);
2035 owner_->showState();
2041 LyXText * lt = bv_->getLyXText();
2043 if (!lt->selection.mark())
2046 BufferView::SELECT|BufferView::FITCUR);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2054 case LFUN_SHIFT_TAB:
2057 LyXText * lt = bv_->getLyXText();
2059 if (!lt->selection.mark())
2062 BufferView::SELECT|BufferView::FITCUR);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2070 case LFUN_WORDRIGHT:
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2076 update(lt, BufferView::SELECT|BufferView::FITCUR);
2077 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2078 lt->cursorLeftOneWord(bv_);
2080 lt->cursorRightOneWord(bv_);
2082 moveCursorUpdate(false);
2083 owner_->showState();
2089 LyXText * lt = bv_->getLyXText();
2091 if (!lt->selection.mark())
2093 update(lt, BufferView::SELECT|BufferView::FITCUR);
2094 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2095 lt->cursorRightOneWord(bv_);
2097 lt->cursorLeftOneWord(bv_);
2099 moveCursorUpdate(false);
2100 owner_->showState();
2104 case LFUN_BEGINNINGBUF:
2106 LyXText * lt = bv_->getLyXText();
2108 if (!lt->selection.mark())
2111 BufferView::SELECT|BufferView::FITCUR);
2114 moveCursorUpdate(false);
2115 owner_->showState();
2121 LyXText * lt = bv_->getLyXText();
2123 if (!lt->selection.mark())
2126 BufferView::SELECT|BufferView::FITCUR);
2127 lt->cursorBottom(bv_);
2129 moveCursorUpdate(false);
2130 owner_->showState();
2134 /* cursor selection ---------------------------- */
2137 LyXText * lt = bv_->getLyXText();
2140 BufferView::SELECT|BufferView::FITCUR);
2141 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2142 lt->cursorLeft(bv_);
2144 lt->cursorRight(bv_);
2146 moveCursorUpdate(true);
2147 owner_->showState();
2153 LyXText * lt = bv_->getLyXText();
2156 BufferView::SELECT|BufferView::FITCUR);
2157 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2158 lt->cursorRight(bv_);
2160 lt->cursorLeft(bv_);
2162 moveCursorUpdate(true);
2163 owner_->showState();
2169 LyXText * lt = bv_->getLyXText();
2172 BufferView::SELECT|BufferView::FITCUR);
2175 moveCursorUpdate(true);
2176 owner_->showState();
2182 LyXText * lt = bv_->getLyXText();
2185 BufferView::SELECT|BufferView::FITCUR);
2186 lt->cursorDown(bv_);
2188 moveCursorUpdate(true);
2189 owner_->showState();
2193 case LFUN_UP_PARAGRAPHSEL:
2195 LyXText * lt = bv_->getLyXText();
2198 BufferView::SELECT|BufferView::FITCUR);
2199 lt->cursorUpParagraph(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2206 case LFUN_DOWN_PARAGRAPHSEL:
2208 LyXText * lt = bv_->getLyXText();
2211 BufferView::SELECT|BufferView::FITCUR);
2212 lt->cursorDownParagraph(bv_);
2214 moveCursorUpdate(true);
2215 owner_->showState();
2221 LyXText * lt = bv_->getLyXText();
2223 update(lt, BufferView::SELECT|BufferView::FITCUR);
2226 moveCursorUpdate(true);
2227 owner_->showState();
2233 LyXText * lt = bv_->getLyXText();
2235 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 moveCursorUpdate(true);
2239 owner_->showState();
2245 LyXText * lt = bv_->getLyXText();
2247 update(lt, BufferView::SELECT|BufferView::FITCUR);
2248 lt->cursorHome(bv_);
2250 moveCursorUpdate(true);
2251 owner_->showState();
2257 LyXText * lt = bv_->getLyXText();
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2262 moveCursorUpdate(true);
2263 owner_->showState();
2267 case LFUN_WORDRIGHTSEL:
2269 LyXText * lt = bv_->getLyXText();
2271 update(lt, BufferView::SELECT|BufferView::FITCUR);
2272 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2273 lt->cursorLeftOneWord(bv_);
2275 lt->cursorRightOneWord(bv_);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2282 case LFUN_WORDLEFTSEL:
2284 LyXText * lt = bv_->getLyXText();
2286 update(lt, BufferView::SELECT|BufferView::FITCUR);
2287 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2288 lt->cursorRightOneWord(bv_);
2290 lt->cursorLeftOneWord(bv_);
2292 moveCursorUpdate(true);
2293 owner_->showState();
2297 case LFUN_BEGINNINGBUFSEL:
2299 LyXText * lt = bv_->getLyXText();
2301 if (lt->inset_owner)
2303 update(lt, BufferView::SELECT|BufferView::FITCUR);
2306 moveCursorUpdate(true);
2307 owner_->showState();
2311 case LFUN_ENDBUFSEL:
2313 LyXText * lt = bv_->getLyXText();
2315 if (lt->inset_owner)
2318 BufferView::SELECT|BufferView::FITCUR);
2319 lt->cursorBottom(bv_);
2321 moveCursorUpdate(true);
2322 owner_->showState();
2326 // --- text changing commands ------------------------
2327 case LFUN_BREAKLINE:
2329 LyXText * lt = bv_->getLyXText();
2332 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2335 | BufferView::FITCUR
2336 | BufferView::CHANGE);
2337 moveCursorUpdate(false);
2341 case LFUN_PROTECTEDSPACE:
2343 LyXText * lt = bv_->getLyXText();
2345 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2347 if (style.free_spacing) {
2348 lt->insertChar(bv_, ' ');
2351 | BufferView::FITCUR
2352 | BufferView::CHANGE);
2356 moveCursorUpdate(false);
2362 LyXText * lt = bv_->getLyXText();
2364 if (lt->selection.mark()) {
2368 | BufferView::FITCUR);
2369 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2372 lt->selection.mark(true);
2375 | BufferView::FITCUR);
2376 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2378 lt->selection.cursor = lt->cursor;
2384 LyXText * lt = bv_->getLyXText();
2386 if (!lt->selection.set()) {
2388 lt->selection.cursor = lt->cursor;
2391 | BufferView::FITCUR
2392 | BufferView::CHANGE);
2393 // It is possible to make it a lot faster still
2394 // just comment out the line below...
2399 moveCursorUpdate(false);
2400 owner_->showState();
2405 case LFUN_DELETE_SKIP:
2407 LyXText * lt = bv_->getLyXText();
2409 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2411 LyXCursor cursor = lt->cursor;
2413 if (!lt->selection.set()) {
2414 if (cursor.pos() == cursor.par()->size()) {
2415 lt->cursorRight(bv_);
2416 cursor = lt->cursor;
2417 if (cursor.pos() == 0
2418 && !(cursor.par()->params().spaceTop()
2419 == VSpace (VSpace::NONE))) {
2422 cursor.par()->params().lineTop(),
2423 cursor.par()->params().lineBottom(),
2424 cursor.par()->params().pagebreakTop(),
2425 cursor.par()->params().pagebreakBottom(),
2426 VSpace(VSpace::NONE),
2427 cursor.par()->params().spaceBottom(),
2428 cursor.par()->params().spacing(),
2429 cursor.par()->params().align(),
2430 cursor.par()->params().labelWidthString(), 0);
2431 lt->cursorLeft(bv_);
2434 | BufferView::FITCUR
2435 | BufferView::CHANGE);
2437 lt->cursorLeft(bv_);
2439 lt->selection.cursor = lt->cursor;
2442 | BufferView::FITCUR
2443 | BufferView::CHANGE);
2447 lt->selection.cursor = lt->cursor;
2450 | BufferView::FITCUR
2451 | BufferView::CHANGE);
2459 /* -------> Delete word forward. */
2460 case LFUN_DELETE_WORD_FORWARD:
2461 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2462 bv_->getLyXText()->deleteWordForward(bv_);
2463 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2464 moveCursorUpdate(false);
2465 owner_->showState();
2468 /* -------> Delete word backward. */
2469 case LFUN_DELETE_WORD_BACKWARD:
2471 LyXText * lt = bv_->getLyXText();
2473 update(lt, BufferView::SELECT|BufferView::FITCUR);
2474 lt->deleteWordBackward(bv_);
2477 | BufferView::FITCUR
2478 | BufferView::CHANGE);
2479 moveCursorUpdate(false);
2480 owner_->showState();
2484 /* -------> Kill to end of line. */
2485 case LFUN_DELETE_LINE_FORWARD:
2487 LyXText * lt = bv_->getLyXText();
2489 update(lt, BufferView::SELECT|BufferView::FITCUR);
2490 lt->deleteLineForward(bv_);
2493 | BufferView::FITCUR
2494 | BufferView::CHANGE);
2495 moveCursorUpdate(false);
2499 /* -------> Set mark off. */
2502 LyXText * lt = bv_->getLyXText();
2505 update(lt, BufferView::SELECT|BufferView::FITCUR);
2506 lt->selection.cursor = lt->cursor;
2507 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2511 /* -------> Set mark on. */
2514 LyXText * lt = bv_->getLyXText();
2517 lt->selection.mark(true);
2518 update(lt, BufferView::SELECT|BufferView::FITCUR);
2519 lt->selection.cursor = lt->cursor;
2520 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2524 case LFUN_BACKSPACE:
2526 LyXText * lt = bv_->getLyXText();
2528 if (!lt->selection.set()) {
2529 if (owner_->getIntl()->getTrans().backspace()) {
2531 lt->selection.cursor = lt->cursor;
2534 | BufferView::FITCUR
2535 | BufferView::CHANGE);
2536 // It is possible to make it a lot faster still
2537 // just comment out the line below...
2543 owner_->showState();
2548 case LFUN_BACKSPACE_SKIP:
2550 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2551 LyXText * lt = bv_->getLyXText();
2553 LyXCursor cursor = lt->cursor;
2555 if (!lt->selection.set()) {
2556 if (cursor.pos() == 0
2557 && !(cursor.par()->params().spaceTop()
2558 == VSpace (VSpace::NONE))) {
2561 cursor.par()->params().lineTop(),
2562 cursor.par()->params().lineBottom(),
2563 cursor.par()->params().pagebreakTop(),
2564 cursor.par()->params().pagebreakBottom(),
2565 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2566 cursor.par()->params().spacing(),
2567 cursor.par()->params().align(),
2568 cursor.par()->params().labelWidthString(), 0);
2571 | BufferView::FITCUR
2572 | BufferView::CHANGE);
2575 lt->selection.cursor = cursor;
2578 | BufferView::FITCUR
2579 | BufferView::CHANGE);
2586 case LFUN_BREAKPARAGRAPH:
2588 LyXText * lt = bv_->getLyXText();
2591 lt->breakParagraph(bv_, 0);
2594 | BufferView::FITCUR
2595 | BufferView::CHANGE);
2596 lt->selection.cursor = lt->cursor;
2598 owner_->showState();
2602 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2604 LyXText * lt = bv_->getLyXText();
2607 lt->breakParagraph(bv_, 1);
2610 | BufferView::FITCUR
2611 | BufferView::CHANGE);
2612 lt->selection.cursor = lt->cursor;
2614 owner_->showState();
2618 case LFUN_BREAKPARAGRAPH_SKIP:
2620 // When at the beginning of a paragraph, remove
2621 // indentation and add a "defskip" at the top.
2622 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2623 LyXText * lt = bv_->getLyXText();
2625 LyXCursor cursor = lt->cursor;
2628 if (cursor.pos() == 0) {
2629 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2632 cursor.par()->params().lineTop(),
2633 cursor.par()->params().lineBottom(),
2634 cursor.par()->params().pagebreakTop(),
2635 cursor.par()->params().pagebreakBottom(),
2636 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2637 cursor.par()->params().spacing(),
2638 cursor.par()->params().align(),
2639 cursor.par()->params().labelWidthString(), 1);
2640 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2644 lt->breakParagraph(bv_, 0);
2645 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2650 | BufferView::FITCUR
2651 | BufferView::CHANGE);
2652 lt->selection.cursor = cursor;
2654 owner_->showState();
2658 case LFUN_PARAGRAPH_SPACING:
2660 LyXText * lt = bv_->getLyXText();
2662 Paragraph * par = lt->cursor.par();
2663 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2664 float cur_value = 1.0;
2665 if (cur_spacing == Spacing::Other) {
2666 cur_value = par->params().spacing().getValue();
2669 istringstream istr(argument.c_str());
2673 Spacing::Space new_spacing = cur_spacing;
2674 float new_value = cur_value;
2676 lyxerr << "Missing argument to `paragraph-spacing'"
2678 } else if (tmp == "single") {
2679 new_spacing = Spacing::Single;
2680 } else if (tmp == "onehalf") {
2681 new_spacing = Spacing::Onehalf;
2682 } else if (tmp == "double") {
2683 new_spacing = Spacing::Double;
2684 } else if (tmp == "other") {
2685 new_spacing = Spacing::Other;
2688 lyxerr << "new_value = " << tmpval << endl;
2691 } else if (tmp == "default") {
2692 new_spacing = Spacing::Default;
2694 lyxerr << _("Unknown spacing argument: ")
2695 << argument << endl;
2697 if (cur_spacing != new_spacing || cur_value != new_value) {
2698 par->params().spacing(Spacing(new_spacing, new_value));
2699 lt->redoParagraph(bv_);
2702 | BufferView::FITCUR
2703 | BufferView::CHANGE);
2708 case LFUN_INSET_TOGGLE:
2710 LyXText * lt = bv_->getLyXText();
2713 update(lt, BufferView::SELECT|BufferView::FITCUR);
2714 lt->toggleInset(bv_);
2715 update(lt, BufferView::SELECT|BufferView::FITCUR);
2727 InsetCommandParams p;
2728 if (action == LFUN_HTMLURL)
2729 p.setCmdName("htmlurl");
2731 p.setCmdName("url");
2732 owner_->getDialogs()->createUrl(p.getAsString());
2736 case LFUN_INSERT_URL:
2738 InsetCommandParams p;
2739 p.setFromString(argument);
2741 InsetUrl * inset = new InsetUrl(p);
2742 if (!insertInset(inset))
2745 updateInset(inset, true);
2749 case LFUN_INSET_TEXT:
2750 insertAndEditInset(new InsetText(buffer_->params));
2753 case LFUN_INSET_ERT:
2754 insertAndEditInset(new InsetERT(buffer_->params));
2757 case LFUN_INSET_EXTERNAL:
2758 insertAndEditInset(new InsetExternal);
2761 case LFUN_INSET_FOOTNOTE:
2762 insertAndEditInset(new InsetFoot(buffer_->params));
2765 case LFUN_INSET_MARGINAL:
2766 insertAndEditInset(new InsetMarginal(buffer_->params));
2769 case LFUN_INSET_MINIPAGE:
2770 insertAndEditInset(new InsetMinipage(buffer_->params));
2773 case LFUN_INSERT_NOTE:
2774 insertAndEditInset(new InsetNote(buffer_->params));
2777 case LFUN_INSET_FLOAT:
2778 // check if the float type exist
2779 if (floatList.typeExist(argument)) {
2780 insertAndEditInset(new InsetFloat(buffer_->params,
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 =
2793 new InsetFloat(buffer_->params, argument);
2794 new_inset->wide(true);
2795 if (insertInset(new_inset))
2796 new_inset->edit(bv_);
2800 lyxerr << "Non-existent float type: "
2801 << argument << endl;
2808 case LFUN_INSET_LIST:
2809 insertAndEditInset(new InsetList);
2812 case LFUN_INSET_THEOREM:
2813 insertAndEditInset(new InsetTheorem);
2817 case LFUN_INSET_CAPTION:
2819 // Do we have a locking inset...
2820 if (bv_->theLockingInset()) {
2821 lyxerr << "Locking inset code: "
2822 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2823 InsetCaption * new_inset =
2824 new InsetCaption(buffer_->params);
2825 new_inset->setOwner(bv_->theLockingInset());
2826 new_inset->setAutoBreakRows(true);
2827 new_inset->setDrawFrame(0, InsetText::LOCKED);
2828 new_inset->setFrameColor(0, LColor::captionframe);
2829 if (insertInset(new_inset))
2830 new_inset->edit(bv_);
2837 case LFUN_INSET_TABULAR:
2841 if (!argument.empty())
2842 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2843 InsetTabular * new_inset =
2844 new InsetTabular(*buffer_, r, c);
2846 bv_->getLyXText()->real_current_font.isRightToLeft();
2847 if (!open_new_inset(new_inset, rtl))
2852 // --- lyxserver commands ----------------------------
2854 case LFUN_CHARATCURSOR:
2856 pos_type pos = bv_->getLyXText()->cursor.pos();
2857 if (pos < bv_->getLyXText()->cursor.par()->size())
2858 owner_->getLyXFunc()->setMessage(
2859 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2861 owner_->getLyXFunc()->setMessage("EOF");
2866 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2868 + tostr(bv_->getLyXText()->cursor.y()));
2875 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2876 lyxerr << "SETXY: Could not parse coordinates in '"
2877 << argument << std::endl;
2879 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2883 case LFUN_GETLAYOUT:
2884 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2889 LyXFont & font = bv_->getLyXText()->current_font;
2890 if (font.shape() == LyXFont::ITALIC_SHAPE)
2891 owner_->getLyXFunc()->setMessage("E");
2892 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2893 owner_->getLyXFunc()->setMessage("N");
2895 owner_->getLyXFunc()->setMessage("0");
2900 // --- accented characters ---------------------------
2903 case LFUN_CIRCUMFLEX:
2913 case LFUN_SPECIAL_CARON:
2916 case LFUN_HUNG_UMLAUT:
2919 if (argument.empty()) {
2921 owner_->getLyXFunc()->handleKeyFunc(action);
2923 owner_->getLyXFunc()->handleKeyFunc(action);
2924 owner_->getIntl()->getTrans()
2925 .TranslateAndInsert(argument[0], bv_->getLyXText());
2926 update(bv_->getLyXText(),
2928 | BufferView::FITCUR
2929 | BufferView::CHANGE);
2933 case LFUN_MATH_MACRO:
2934 mathDispatchMathMacro(bv_, argument);
2937 case LFUN_MATH_DELIM:
2938 mathDispatchMathDelim(bv_, argument);
2941 case LFUN_INSERT_MATRIX:
2942 mathDispatchInsertMatrix(bv_, argument);
2945 case LFUN_INSERT_MATH:
2946 mathDispatchInsertMath(bv_, argument);
2949 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2950 mathDispatchMathImportSelection(bv_, argument);
2953 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2954 mathDispatchMathDisplay(bv_, argument);
2957 case LFUN_MATH_MODE: // Open or create an inlined math inset
2958 mathDispatchMathMode(bv_, argument);
2961 case LFUN_GREEK: // Insert a single greek letter
2962 mathDispatchGreek(bv_, argument);
2965 case LFUN_CITATION_INSERT:
2967 InsetCommandParams p;
2968 p.setFromString(argument);
2970 InsetCitation * inset = new InsetCitation(p);
2971 if (!insertInset(inset))
2974 updateInset(inset, true);
2978 case LFUN_INSERT_BIBTEX:
2980 // ale970405+lasgoutt970425
2981 // The argument can be up to two tokens separated
2982 // by a space. The first one is the bibstyle.
2983 string const db = token(argument, ' ', 0);
2984 string const bibstyle = token(argument, ' ', 1);
2986 InsetCommandParams p("BibTeX", db, bibstyle);
2987 InsetBibtex * inset = new InsetBibtex(p);
2989 if (insertInset(inset)) {
2990 if (argument.empty())
2997 // BibTeX data bases
2998 case LFUN_BIBDB_ADD:
3000 InsetBibtex * inset =
3001 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3003 inset->addDatabase(argument);
3008 case LFUN_BIBDB_DEL:
3010 InsetBibtex * inset =
3011 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3013 inset->delDatabase(argument);
3018 case LFUN_BIBTEX_STYLE:
3020 InsetBibtex * inset =
3021 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3023 inset->setOptions(argument);
3028 case LFUN_INDEX_CREATE:
3030 InsetCommandParams p("index");
3031 if (argument.empty()) {
3032 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3033 p.setContents(idxstring);
3035 p.setContents(argument);
3038 owner_->getDialogs()->createIndex(p.getAsString());
3042 case LFUN_INDEX_INSERT:
3044 InsetCommandParams p;
3045 p.setFromString(argument);
3046 InsetIndex * inset = new InsetIndex(p);
3048 if (!insertInset(inset))
3051 updateInset(inset, true);
3055 case LFUN_INDEX_INSERT_LAST:
3057 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3058 if (!idxstring.empty()) {
3059 owner_->message(_("Word `")
3060 + idxstring + _(("' indexed.")));
3061 InsetCommandParams p("index", idxstring);
3062 InsetIndex * inset = new InsetIndex(p);
3064 if (!insertInset(inset))
3067 updateInset(inset, true);
3072 case LFUN_INDEX_PRINT:
3074 InsetCommandParams p("printindex");
3075 Inset * inset = new InsetPrintIndex(p);
3076 if (!insertInset(inset, "Standard"))
3081 case LFUN_PARENTINSERT:
3083 lyxerr << "arg " << argument << endl;
3084 InsetCommandParams p("lyxparent", argument);
3085 Inset * inset = new InsetParent(p, *buffer_);
3086 if (!insertInset(inset, "Standard"))
3092 case LFUN_CHILD_INSERT:
3094 InsetInclude::Params p;
3095 p.cparams.setFromString(argument);
3096 p.masterFilename_ = buffer_->fileName();
3098 InsetInclude * inset = new InsetInclude(p);
3099 if (!insertInset(inset))
3102 updateInset(inset, true);
3103 bv_->owner()->getDialogs()->showInclude(inset);
3108 case LFUN_FLOAT_LIST:
3110 // We should check the argument for validity. (Lgb)
3111 Inset * inset = new InsetFloatList(argument);
3112 if (!insertInset(inset, "Standard"))
3117 case LFUN_THESAURUS_ENTRY:
3119 string arg = argument;
3122 arg = bv_->getLyXText()->selectionAsString(buffer_,
3126 if (arg.size() > 100 || arg.empty()) {
3127 // Get word or selection
3128 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3129 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3130 // FIXME: where is getLyXText()->unselect(bv_) ?
3134 bv_->owner()->getDialogs()->showThesaurus(arg);
3138 case LFUN_SELFINSERT:
3140 if (argument.empty()) break;
3142 /* Automatically delete the currently selected
3143 * text and replace it with what is being
3144 * typed in now. Depends on lyxrc settings
3145 * "auto_region_delete", which defaults to
3148 LyXText * lt = bv_->getLyXText();
3150 if (lyxrc.auto_region_delete) {
3151 if (lt->selection.set()) {
3152 lt->cutSelection(bv_, false, false);
3155 | BufferView::FITCUR
3156 | BufferView::CHANGE);
3161 LyXFont const old_font(lt->real_current_font);
3163 string::const_iterator cit = argument.begin();
3164 string::const_iterator end = argument.end();
3165 for (; cit != end; ++cit) {
3166 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3171 | BufferView::FITCUR
3172 | BufferView::CHANGE);
3174 lt->selection.cursor = lt->cursor;
3175 moveCursorUpdate(false);
3177 // real_current_font.number can change so we need to
3178 // update the minibuffer
3179 if (old_font != lt->real_current_font)
3180 owner_->showState();
3185 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3187 time_t now_time_t = time(NULL);
3188 struct tm * now_tm = localtime(&now_time_t);
3189 setlocale(LC_TIME, "");
3191 if (!argument.empty())
3194 arg = lyxrc.date_insert_format;
3196 int const datetmp_len =
3197 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3199 LyXText * lt = bv_->getLyXText();
3201 for (int i = 0; i < datetmp_len; i++) {
3202 lt->insertChar(bv_, datetmp[i]);
3205 | BufferView::FITCUR
3206 | BufferView::CHANGE);
3209 lt->selection.cursor = lt->cursor;
3210 moveCursorUpdate(false);
3214 case LFUN_UNKNOWN_ACTION:
3215 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3226 void BufferView::Pimpl::newline()
3229 LyXText * lt = bv_->getLyXText();
3233 | BufferView::FITCUR);
3234 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3237 | BufferView::FITCUR
3238 | BufferView::CHANGE);
3243 void BufferView::Pimpl::hfill()
3246 LyXText * lt = bv_->getLyXText();
3250 | BufferView::FITCUR);
3251 lt->insertChar(bv_, Paragraph::META_HFILL);
3254 | BufferView::FITCUR
3255 | BufferView::CHANGE);
3260 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3264 update(lt, BufferView::SELECT|BufferView::FITCUR);
3265 InsetSpecialChar * new_inset =
3266 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3267 #ifdef WITH_WARNINGS
3268 #warning Why is this code different from specialChar() below? (JMarc)
3269 // the code in specialChar is a generic version of what used to exist
3270 // for other special chars. I did not merge this case because of the
3271 // call to updateInset(), but what does it do?
3273 if (!insertInset(new_inset))
3276 updateInset(new_inset, true);
3281 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3284 LyXText * lt = bv_->getLyXText();
3287 update(lt, BufferView::SELECT|BufferView::FITCUR);
3288 InsetSpecialChar * new_inset =
3289 new InsetSpecialChar(kind);
3290 if (!insertInset(new_inset))
3296 void BufferView::Pimpl::smartQuote()
3298 LyXText const * lt = bv_->getLyXText();
3299 Paragraph const * par = lt->cursor.par();
3300 pos_type pos = lt->cursor.pos();
3304 || (par->isInset(pos - 1)
3305 && par->getInset(pos - 1)->isSpace()))
3308 c = par->getChar(pos - 1);
3313 LyXLayout const & style =
3314 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3316 if (style.pass_thru ||
3317 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3318 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3322 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3324 if (insertInset(inset))
3331 // Open and lock an updatable inset
3332 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3334 LyXText * lt = bv_->getLyXText();
3338 if (!insertInset(new_inset)) {
3342 new_inset->edit(bv_, !behind);
3347 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3349 // if we are in a locking inset we should try to insert the
3350 // inset there otherwise this is a illegal function now
3351 if (bv_->theLockingInset()) {
3352 if (bv_->theLockingInset()->insetAllowed(inset))
3353 return bv_->theLockingInset()->insertInset(bv_, inset);
3357 // not quite sure if we want this...
3358 setCursorParUndo(bv_);
3361 beforeChange(bv_->text);
3362 if (!lout.empty()) {
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3364 bv_->text->breakParagraph(bv_);
3365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 if (bv_->text->cursor.par()->size()) {
3368 bv_->text->cursorLeft(bv_);
3370 bv_->text->breakParagraph(bv_);
3371 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3375 LyXTextClass const & tclass =
3376 textclasslist[buffer_->params.textclass];
3377 bool hasLayout = tclass.hasLayout(lres);
3378 string lay = tclass.defaultLayoutName();
3380 if (hasLayout != false) {
3384 // layout not fount using default
3385 lay = tclass.defaultLayoutName();
3388 bv_->text->setLayout(bv_, lay);
3390 bv_->text->setParagraph(bv_, 0, 0,
3392 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3397 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3400 bv_->text->insertInset(bv_, inset);
3401 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3408 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3410 if (!inset || !available())
3413 // first check for locking insets
3414 if (bv_->theLockingInset()) {
3415 if (bv_->theLockingInset() == inset) {
3416 if (bv_->text->updateInset(bv_, inset)) {
3419 buffer_->markDirty();
3424 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3425 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3428 buffer_->markDirty();
3436 // then check if the inset is a top_level inset (has no owner)
3437 // if yes do the update as always otherwise we have to update the
3438 // toplevel inset where this inset is inside
3439 Inset * tl_inset = inset;
3440 while(tl_inset->owner())
3441 tl_inset = tl_inset->owner();
3443 if (tl_inset == inset) {
3444 update(bv_->text, BufferView::UPDATE);
3445 if (bv_->text->updateInset(bv_, inset)) {
3449 | BufferView::FITCUR
3450 | BufferView::CHANGE);
3452 update(bv_->text, SELECT);
3456 } else if (static_cast<UpdatableInset *>(tl_inset)
3457 ->updateInsetInInset(bv_, inset))
3459 if (bv_->text->updateInset(bv_, tl_inset)) {
3467 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3470 if (!available()) return;
3473 beforeChange(bv_->text);
3474 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3476 LyXCursor const & cursor = bv_->text->cursor;
3480 cursor.par()->isInset(cursor.pos())) {
3481 Inset const * inset = cursor.par()->getInset(cursor.pos());
3482 if (find(codes.begin(), codes.end(), inset->lyxCode())
3485 static_cast<InsetCommand const *>(inset)->getContents();
3489 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3490 if (bv_->text->cursor.pos()
3491 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3492 LyXCursor tmp = bv_->text->cursor;
3493 bv_->text->cursor.par(bv_->text->ownerParagraph());
3494 bv_->text->cursor.pos(0);
3495 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3496 bv_->text->cursor = tmp;
3497 bv_->owner()->message(_("No more insets"));
3500 bv_->owner()->message(_("No more insets"));
3503 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3504 bv_->text->selection.cursor = bv_->text->cursor;
3508 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3510 gotoInset(vector<Inset::Code>(1, code), same_content);