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()) 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 buffer_->resizeInsets(bv_);
1003 } else if (heightChange) {
1004 // Rebuild image of current screen
1006 // fitCursor() ensures we don't jump back
1007 // to the start of the document on vertical
1011 // The main window size has changed, repaint most stuff
1013 } else if (screen_.get())
1014 screen_->redraw(bv_->text, bv_);
1016 // Grey box when we don't have a buffer
1017 workarea_.greyOut();
1020 // always make sure that the scrollbar is sane.
1022 owner_->updateLayoutChoice();
1027 void BufferView::Pimpl::update()
1029 if (screen_.get() &&
1030 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1032 LyXText::text_status st = bv_->text->status();
1033 screen_->update(bv_->text, bv_);
1035 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1036 if (bv_->text->fullRebreak(bv_)) {
1037 st = LyXText::NEED_MORE_REFRESH;
1038 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1039 bv_->text->cursor.pos());
1042 bv_->text->status(bv_, st);
1043 screen_->update(bv_->text, bv_);
1045 // do this here instead of in the screen::update because of
1047 bv_->text->status(bv_, LyXText::UNCHANGED);
1053 // Values used when calling update:
1055 // -2 - update, move sel_cursor if selection, fitcursor
1056 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1057 // 0 - update, move sel_cursor if selection, fitcursor
1058 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1059 // 3 - update, move sel_cursor if selection
1062 // a simple redraw of the parts that need refresh
1064 // move sel_cursor if selection -
1065 // the text's sel_cursor is moved if there is selection is progress
1068 // fitCursor() is called and the scrollbar updated
1071 // the buffer is marked dirty.
1080 // UPDATE_ONLY = UPDATE;
1081 // UPDATE_SELECT = UPDATE | SELECT;
1082 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1083 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1085 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1086 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1087 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1088 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1089 // update(3) -> update(1) -> update(1) -> update(SELECT)
1091 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1093 owner_->updateLayoutChoice();
1095 if (!text->selection.set() && (f & SELECT)) {
1096 text->selection.cursor = text->cursor;
1099 text->fullRebreak(bv_);
1101 if (text->inset_owner) {
1102 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1103 updateInset(text->inset_owner, false);
1113 buffer_->markDirty();
1118 // Callback for cursor timer
1119 void BufferView::Pimpl::cursorToggle()
1122 cursor_timeout.restart();
1126 if (!screen_.get()) {
1127 cursor_timeout.restart();
1132 extern void reapSpellchecker(void);
1135 if (!bv_->theLockingInset()) {
1136 screen_->cursorToggle(bv_);
1138 bv_->theLockingInset()->toggleInsetCursor(bv_);
1141 cursor_timeout.restart();
1145 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1147 if (!text->cursor.row()->previous())
1150 int y = text->first_y;
1151 Row * cursorrow = text->cursor.row();
1153 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1155 // This is to allow jumping over large insets
1156 if ((cursorrow == text->cursor.row()))
1157 text->cursorUp(bv_);
1159 if (text->inset_owner ||
1160 text->cursor.row()->height() < workarea_.height())
1161 screen_->draw(bv_->text, bv_,
1163 - text->cursor.row()->baseline()
1164 + text->cursor.row()->height()
1165 - workarea_.height() + 1);
1170 void BufferView::Pimpl::cursorNext(LyXText * text)
1172 if (!text->cursor.row()->next())
1175 int y = text->first_y + workarea_.height();
1176 // if (text->inset_owner)
1177 // y += bv_->text->first;
1178 text->getRowNearY(y);
1180 Row * cursorrow = text->cursor.row();
1181 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1183 // This is to allow jumping over large insets
1184 if ((cursorrow == bv_->text->cursor.row()))
1185 text->cursorDown(bv_);
1187 if (text->inset_owner ||
1188 text->cursor.row()->height() < workarea_.height())
1189 screen_->draw(bv_->text, bv_, text->cursor.y() -
1190 text->cursor.row()->baseline());
1195 bool BufferView::Pimpl::available() const
1197 if (buffer_ && bv_->text)
1203 void BufferView::Pimpl::beforeChange(LyXText * text)
1206 text->clearSelection();
1210 void BufferView::Pimpl::savePosition(unsigned int i)
1212 if (i >= saved_positions_num)
1214 saved_positions[i] = Position(buffer_->fileName(),
1215 bv_->text->cursor.par()->id(),
1216 bv_->text->cursor.pos());
1219 str << _("Saved bookmark") << ' ' << i;
1220 owner_->message(str.str().c_str());
1225 void BufferView::Pimpl::restorePosition(unsigned int i)
1227 if (i >= saved_positions_num)
1230 string const fname = saved_positions[i].filename;
1232 beforeChange(bv_->text);
1234 if (fname != buffer_->fileName()) {
1235 Buffer * b = bufferlist.exists(fname) ?
1236 bufferlist.getBuffer(fname) :
1237 bufferlist.loadLyXFile(fname); // don't ask, just load it
1238 if (b != 0) buffer(b);
1241 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1245 bv_->text->setCursor(bv_, par,
1246 min(par->size(), saved_positions[i].par_pos));
1248 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1251 str << _("Moved to bookmark") << ' ' << i;
1252 owner_->message(str.str().c_str());
1257 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1259 if (i >= saved_positions_num)
1262 return !saved_positions[i].filename.empty();
1266 void BufferView::Pimpl::setState()
1268 if (!lyxrc.rtl_support)
1271 LyXText * text = bv_->getLyXText();
1272 if (text->real_current_font.isRightToLeft()) {
1273 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1274 owner_->getIntl()->KeyMapSec();
1276 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1277 owner_->getIntl()->KeyMapPrim();
1282 void BufferView::Pimpl::insetSleep()
1284 if (bv_->theLockingInset() && !inset_slept) {
1285 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1286 bv_->theLockingInset()->insetUnlock(bv_);
1292 void BufferView::Pimpl::insetWakeup()
1294 if (bv_->theLockingInset() && inset_slept) {
1295 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1296 inset_slept = false;
1301 void BufferView::Pimpl::insetUnlock()
1303 if (bv_->theLockingInset()) {
1305 bv_->theLockingInset()->insetUnlock(bv_);
1306 bv_->theLockingInset(0);
1308 inset_slept = false;
1313 bool BufferView::Pimpl::focus() const
1315 return workarea_.hasFocus();
1319 void BufferView::Pimpl::focus(bool f)
1321 if (f) workarea_.setFocus();
1325 bool BufferView::Pimpl::active() const
1327 return workarea_.active();
1331 bool BufferView::Pimpl::belowMouse() const
1333 return workarea_.belowMouse();
1337 void BufferView::Pimpl::showCursor()
1339 if (screen_.get()) {
1340 if (bv_->theLockingInset())
1341 bv_->theLockingInset()->showInsetCursor(bv_);
1343 screen_->showCursor(bv_->text, bv_);
1348 void BufferView::Pimpl::hideCursor()
1350 if (screen_.get()) {
1351 if (!bv_->theLockingInset())
1352 // bv_->theLockingInset()->hideInsetCursor(bv_);
1354 screen_->hideCursor();
1359 void BufferView::Pimpl::toggleSelection(bool b)
1361 if (screen_.get()) {
1362 if (bv_->theLockingInset())
1363 bv_->theLockingInset()->toggleSelection(bv_, b);
1364 screen_->toggleSelection(bv_->text, bv_, b);
1369 void BufferView::Pimpl::toggleToggle()
1372 screen_->toggleToggle(bv_->text, bv_);
1376 void BufferView::Pimpl::center()
1378 beforeChange(bv_->text);
1379 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1380 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1382 screen_->draw(bv_->text, bv_, 0);
1384 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1389 void BufferView::Pimpl::pasteClipboard(bool asPara)
1391 if (!buffer_) return;
1393 screen_->hideCursor();
1394 beforeChange(bv_->text);
1396 string const clip(workarea_.getClipboard());
1398 if (clip.empty()) return;
1401 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1403 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1405 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1409 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1411 workarea_.putClipboard(stuff);
1416 * Dispatch functions for actions which can be valid for BufferView->text
1417 * and/or InsetText->text!!!
1422 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1424 LyXText * lt = bv_->getLyXText();
1426 if (selecting || lt->selection.mark()) {
1427 lt->setSelection(bv_);
1431 updateInset(lt->inset_owner, false);
1434 update(lt, BufferView::SELECT|BufferView::FITCUR);
1438 /* ---> Everytime the cursor is moved, show the current font state. */
1439 // should this too me moved out of this func?
1440 //owner->showState();
1445 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1447 LyXCursor cursor = bv_->getLyXText()->cursor;
1448 Buffer::inset_iterator it =
1449 find_if(Buffer::inset_iterator(
1450 cursor.par(), cursor.pos()),
1451 buffer_->inset_iterator_end(),
1452 lyx::compare_memfun(&Inset::lyxCode, code));
1453 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1457 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1459 string filename = filen;
1461 if (filename.empty()) {
1462 // Launch a file browser
1463 string initpath = lyxrc.document_path;
1466 string const trypath = owner_->buffer()->filePath();
1467 // If directory is writeable, use this as default.
1468 if (IsDirWriteable(trypath))
1472 FileDialog fileDlg(bv_->owner(),
1473 _("Select LyX document to insert"),
1475 make_pair(string(_("Documents|#o#O")),
1476 string(lyxrc.document_path)),
1477 make_pair(string(_("Examples|#E#e")),
1478 string(AddPath(system_lyxdir, "examples"))));
1480 FileDialog::Result result =
1481 fileDlg.Select(initpath,
1482 _("*.lyx| LyX Documents (*.lyx)"));
1484 if (result.first == FileDialog::Later)
1487 filename = result.second;
1489 // check selected filename
1490 if (filename.empty()) {
1491 owner_->message(_("Canceled."));
1496 // get absolute path of file and add ".lyx" to the filename if
1498 filename = FileSearch(string(), filename, "lyx");
1500 string const disp_fn(MakeDisplayPath(filename));
1503 s1 << _("Inserting document") << ' '
1504 << disp_fn << " ...";
1505 owner_->message(s1.str().c_str());
1506 bool const res = bv_->insertLyXFile(filename);
1509 str << _("Document") << ' ' << disp_fn
1510 << ' ' << _("inserted.");
1511 owner_->message(str.str().c_str());
1514 str << _("Could not insert document") << ' '
1516 owner_->message(str.str().c_str());
1521 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1523 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1524 << action <<"] arg[" << argument << "]" << endl;
1527 // --- Misc -------------------------------------------
1531 LyXText * lt = bv_->getLyXText();
1532 lt->toggleAppendix(bv_);
1535 | BufferView::FITCUR
1536 | BufferView::CHANGE);
1541 case LFUN_TOC_INSERT:
1543 InsetCommandParams p;
1544 p.setCmdName("tableofcontents");
1545 Inset * inset = new InsetTOC(p);
1546 if (!insertInset(inset, "Standard"))
1551 case LFUN_SCROLL_INSET:
1552 // this is not handled here as this funktion is only aktive
1553 // if we have a locking_inset and that one is (or contains)
1557 case LFUN_INSET_GRAPHICS:
1559 Inset * new_inset = new InsetGraphics;
1560 if (!insertInset(new_inset)) {
1563 // this is need because you don't use a inset->Edit()
1564 updateInset(new_inset, true);
1565 new_inset->edit(bv_);
1575 case LFUN_PASTESELECTION:
1577 bool asPara = false;
1578 if (argument == "paragraph")
1580 pasteClipboard(asPara);
1592 case LFUN_LAYOUT_COPY:
1593 bv_->copyEnvironment();
1596 case LFUN_LAYOUT_PASTE:
1597 bv_->pasteEnvironment();
1601 case LFUN_GOTOERROR:
1602 gotoInset(Inset::ERROR_CODE, false);
1606 gotoInset(Inset::IGNORE_CODE, false);
1609 case LFUN_REFERENCE_GOTO:
1611 vector<Inset::Code> tmp;
1612 tmp.push_back(Inset::LABEL_CODE);
1613 tmp.push_back(Inset::REF_CODE);
1614 gotoInset(tmp, true);
1618 case LFUN_HYPHENATION:
1619 specialChar(InsetSpecialChar::HYPHENATION);
1622 case LFUN_LIGATURE_BREAK:
1623 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1627 specialChar(InsetSpecialChar::LDOTS);
1630 case LFUN_END_OF_SENTENCE:
1631 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1634 case LFUN_MENU_SEPARATOR:
1635 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1643 changeDepth(bv_, bv_->getLyXText(), 0);
1646 case LFUN_DEPTH_MIN:
1647 changeDepth(bv_, bv_->getLyXText(), -1);
1650 case LFUN_DEPTH_PLUS:
1651 changeDepth(bv_, bv_->getLyXText(), 1);
1655 owner_->getDialogs()->setUserFreeFont();
1658 case LFUN_FILE_INSERT:
1659 MenuInsertLyXFile(argument);
1662 case LFUN_FILE_INSERT_ASCII_PARA:
1663 InsertAsciiFile(bv_, argument, true);
1666 case LFUN_FILE_INSERT_ASCII:
1667 InsertAsciiFile(bv_, argument, false);
1672 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1673 << argument << endl;
1675 // Derive layout number from given argument (string)
1676 // and current buffer's textclass (number). */
1677 textclass_type tclass = buffer_->params.textclass;
1679 textclasslist[tclass].hasLayout(argument);
1680 string layout = argument;
1682 // If the entry is obsolete, use the new one instead.
1684 string const & obs = textclasslist[tclass][layout]
1691 owner_->getLyXFunc()->setErrorMessage(
1692 string(N_("Layout ")) + argument +
1697 if (current_layout != layout) {
1698 LyXText * lt = bv_->getLyXText();
1700 current_layout = layout;
1703 | BufferView::FITCUR);
1704 lt->setLayout(bv_, layout);
1705 owner_->setLayout(layout);
1708 | BufferView::FITCUR
1709 | BufferView::CHANGE);
1716 lang(bv_, argument);
1718 owner_->showState();
1723 owner_->showState();
1728 owner_->showState();
1733 owner_->showState();
1738 owner_->showState();
1743 owner_->showState();
1748 owner_->showState();
1753 owner_->showState();
1756 case LFUN_UNDERLINE:
1758 owner_->showState();
1761 case LFUN_FONT_SIZE:
1762 fontSize(bv_, argument);
1763 owner_->showState();
1766 case LFUN_FONT_STATE:
1767 owner_->getLyXFunc()->setMessage(currentState(bv_));
1770 case LFUN_UPCASE_WORD:
1772 LyXText * lt = bv_->getLyXText();
1776 | BufferView::FITCUR);
1777 lt->changeCase(bv_, LyXText::text_uppercase);
1778 if (lt->inset_owner)
1779 updateInset(lt->inset_owner, true);
1782 | BufferView::FITCUR
1783 | BufferView::CHANGE);
1787 case LFUN_LOWCASE_WORD:
1789 LyXText * lt = bv_->getLyXText();
1791 update(lt, BufferView::SELECT|BufferView::FITCUR);
1792 lt->changeCase(bv_, LyXText::text_lowercase);
1793 if (lt->inset_owner)
1794 updateInset(lt->inset_owner, true);
1797 | BufferView::FITCUR
1798 | BufferView::CHANGE);
1802 case LFUN_CAPITALIZE_WORD:
1804 LyXText * lt = bv_->getLyXText();
1806 update(lt, BufferView::SELECT|BufferView::FITCUR);
1807 lt->changeCase(bv_, LyXText::text_capitalization);
1808 if (lt->inset_owner)
1809 updateInset(lt->inset_owner, true);
1812 | BufferView::FITCUR
1813 | BufferView::CHANGE);
1817 case LFUN_TRANSPOSE_CHARS:
1819 LyXText * lt = bv_->getLyXText();
1821 update(lt, BufferView::SELECT|BufferView::FITCUR);
1822 lt->transposeChars(*bv_);
1823 if (lt->inset_owner)
1824 updateInset(lt->inset_owner, true);
1827 | BufferView::FITCUR
1828 | BufferView::CHANGE);
1833 case LFUN_INSERT_LABEL:
1834 MenuInsertLabel(bv_, argument);
1837 case LFUN_REF_INSERT:
1838 if (argument.empty()) {
1839 InsetCommandParams p("ref");
1840 owner_->getDialogs()->createRef(p.getAsString());
1842 InsetCommandParams p;
1843 p.setFromString(argument);
1845 InsetRef * inset = new InsetRef(p, *buffer_);
1846 if (!insertInset(inset))
1849 updateInset(inset, true);
1853 case LFUN_BOOKMARK_SAVE:
1854 savePosition(strToUnsignedInt(argument));
1857 case LFUN_BOOKMARK_GOTO:
1858 restorePosition(strToUnsignedInt(argument));
1863 string label(argument);
1864 if (label.empty()) {
1866 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1868 label = inset->getContents();
1873 if (!label.empty()) {
1874 //bv_->savePosition(0);
1875 if (!bv_->gotoLabel(label))
1876 Alert::alert(_("Error"),
1877 _("Couldn't find this label"),
1878 _("in current document."));
1883 // --- Cursor Movements -----------------------------
1886 LyXText * lt = bv_->getLyXText();
1888 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1889 if (!lt->selection.mark())
1891 update(lt, BufferView::SELECT|BufferView::FITCUR);
1893 lt->cursorLeft(bv_, false);
1894 if (lt->cursor.pos() < lt->cursor.par()->size()
1895 && lt->cursor.par()->isInset(lt->cursor.pos())
1896 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1897 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1898 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1900 tmpinset->edit(bv_, false);
1902 tmpinset->edit(bv_);
1906 lt->cursorRight(bv_, false);
1908 moveCursorUpdate(false);
1909 owner_->showState();
1915 // This is soooo ugly. Isn`t it possible to make
1916 // it simpler? (Lgb)
1917 LyXText * lt = bv_->getLyXText();
1918 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1919 if (!lt->selection.mark())
1921 update(lt, BufferView::SELECT|BufferView::FITCUR);
1922 LyXCursor const cur = lt->cursor;
1924 lt->cursorLeft(bv_, false);
1925 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1926 lt->cursor.pos() < lt->cursor.par()->size() &&
1927 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1928 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1929 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1930 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1932 tmpinset->edit(bv_);
1934 tmpinset->edit(bv_, false);
1938 lt->cursorRight(bv_, false);
1941 moveCursorUpdate(false);
1942 owner_->showState();
1948 LyXText * lt = bv_->getLyXText();
1950 if (!lt->selection.mark())
1952 update(lt, BufferView::UPDATE);
1955 moveCursorUpdate(false);
1956 owner_->showState();
1962 LyXText * lt = bv_->getLyXText();
1964 if (!lt->selection.mark())
1966 update(lt, BufferView::UPDATE);
1967 lt->cursorDown(bv_);
1969 moveCursorUpdate(false);
1970 owner_->showState();
1974 case LFUN_UP_PARAGRAPH:
1976 LyXText * lt = bv_->getLyXText();
1978 if (!lt->selection.mark())
1980 update(lt, BufferView::UPDATE);
1981 lt->cursorUpParagraph(bv_);
1983 moveCursorUpdate(false);
1984 owner_->showState();
1988 case LFUN_DOWN_PARAGRAPH:
1990 LyXText * lt = bv_->getLyXText();
1992 if (!lt->selection.mark())
1994 update(lt, BufferView::UPDATE);
1995 lt->cursorDownParagraph(bv_);
1997 moveCursorUpdate(false);
1998 owner_->showState();
2004 LyXText * lt = bv_->getLyXText();
2006 if (!lt->selection.mark())
2008 update(lt, BufferView::UPDATE);
2011 moveCursorUpdate(false);
2012 owner_->showState();
2018 LyXText * lt = bv_->getLyXText();
2020 if (!lt->selection.mark())
2022 update(lt, BufferView::UPDATE);
2025 moveCursorUpdate(false);
2026 owner_->showState();
2032 LyXText * lt = bv_->getLyXText();
2034 if (!lt->selection.mark())
2036 update(lt, BufferView::SELECT|BufferView::FITCUR);
2037 lt->cursorHome(bv_);
2039 moveCursorUpdate(false);
2040 owner_->showState();
2046 LyXText * lt = bv_->getLyXText();
2048 if (!lt->selection.mark())
2051 BufferView::SELECT|BufferView::FITCUR);
2054 moveCursorUpdate(false);
2055 owner_->showState();
2059 case LFUN_SHIFT_TAB:
2062 LyXText * lt = bv_->getLyXText();
2064 if (!lt->selection.mark())
2067 BufferView::SELECT|BufferView::FITCUR);
2070 moveCursorUpdate(false);
2071 owner_->showState();
2075 case LFUN_WORDRIGHT:
2077 LyXText * lt = bv_->getLyXText();
2079 if (!lt->selection.mark())
2081 update(lt, BufferView::SELECT|BufferView::FITCUR);
2082 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2083 lt->cursorLeftOneWord(bv_);
2085 lt->cursorRightOneWord(bv_);
2087 moveCursorUpdate(false);
2088 owner_->showState();
2094 LyXText * lt = bv_->getLyXText();
2096 if (!lt->selection.mark())
2098 update(lt, BufferView::SELECT|BufferView::FITCUR);
2099 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2100 lt->cursorRightOneWord(bv_);
2102 lt->cursorLeftOneWord(bv_);
2104 moveCursorUpdate(false);
2105 owner_->showState();
2109 case LFUN_BEGINNINGBUF:
2111 LyXText * lt = bv_->getLyXText();
2113 if (!lt->selection.mark())
2116 BufferView::SELECT|BufferView::FITCUR);
2119 moveCursorUpdate(false);
2120 owner_->showState();
2126 LyXText * lt = bv_->getLyXText();
2128 if (!lt->selection.mark())
2131 BufferView::SELECT|BufferView::FITCUR);
2132 lt->cursorBottom(bv_);
2134 moveCursorUpdate(false);
2135 owner_->showState();
2139 /* cursor selection ---------------------------- */
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2147 lt->cursorLeft(bv_);
2149 lt->cursorRight(bv_);
2151 moveCursorUpdate(true);
2152 owner_->showState();
2158 LyXText * lt = bv_->getLyXText();
2161 BufferView::SELECT|BufferView::FITCUR);
2162 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2163 lt->cursorRight(bv_);
2165 lt->cursorLeft(bv_);
2167 moveCursorUpdate(true);
2168 owner_->showState();
2174 LyXText * lt = bv_->getLyXText();
2177 BufferView::SELECT|BufferView::FITCUR);
2180 moveCursorUpdate(true);
2181 owner_->showState();
2187 LyXText * lt = bv_->getLyXText();
2190 BufferView::SELECT|BufferView::FITCUR);
2191 lt->cursorDown(bv_);
2193 moveCursorUpdate(true);
2194 owner_->showState();
2198 case LFUN_UP_PARAGRAPHSEL:
2200 LyXText * lt = bv_->getLyXText();
2203 BufferView::SELECT|BufferView::FITCUR);
2204 lt->cursorUpParagraph(bv_);
2206 moveCursorUpdate(true);
2207 owner_->showState();
2211 case LFUN_DOWN_PARAGRAPHSEL:
2213 LyXText * lt = bv_->getLyXText();
2216 BufferView::SELECT|BufferView::FITCUR);
2217 lt->cursorDownParagraph(bv_);
2219 moveCursorUpdate(true);
2220 owner_->showState();
2226 LyXText * lt = bv_->getLyXText();
2228 update(lt, BufferView::SELECT|BufferView::FITCUR);
2231 moveCursorUpdate(true);
2232 owner_->showState();
2238 LyXText * lt = bv_->getLyXText();
2240 update(lt, BufferView::SELECT|BufferView::FITCUR);
2243 moveCursorUpdate(true);
2244 owner_->showState();
2250 LyXText * lt = bv_->getLyXText();
2252 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 lt->cursorHome(bv_);
2255 moveCursorUpdate(true);
2256 owner_->showState();
2262 LyXText * lt = bv_->getLyXText();
2264 update(lt, BufferView::SELECT|BufferView::FITCUR);
2267 moveCursorUpdate(true);
2268 owner_->showState();
2272 case LFUN_WORDRIGHTSEL:
2274 LyXText * lt = bv_->getLyXText();
2276 update(lt, BufferView::SELECT|BufferView::FITCUR);
2277 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2278 lt->cursorLeftOneWord(bv_);
2280 lt->cursorRightOneWord(bv_);
2282 moveCursorUpdate(true);
2283 owner_->showState();
2287 case LFUN_WORDLEFTSEL:
2289 LyXText * lt = bv_->getLyXText();
2291 update(lt, BufferView::SELECT|BufferView::FITCUR);
2292 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2293 lt->cursorRightOneWord(bv_);
2295 lt->cursorLeftOneWord(bv_);
2297 moveCursorUpdate(true);
2298 owner_->showState();
2302 case LFUN_BEGINNINGBUFSEL:
2304 LyXText * lt = bv_->getLyXText();
2306 if (lt->inset_owner)
2308 update(lt, BufferView::SELECT|BufferView::FITCUR);
2311 moveCursorUpdate(true);
2312 owner_->showState();
2316 case LFUN_ENDBUFSEL:
2318 LyXText * lt = bv_->getLyXText();
2320 if (lt->inset_owner)
2323 BufferView::SELECT|BufferView::FITCUR);
2324 lt->cursorBottom(bv_);
2326 moveCursorUpdate(true);
2327 owner_->showState();
2331 // --- text changing commands ------------------------
2332 case LFUN_BREAKLINE:
2334 LyXText * lt = bv_->getLyXText();
2337 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2340 | BufferView::FITCUR
2341 | BufferView::CHANGE);
2342 moveCursorUpdate(false);
2346 case LFUN_PROTECTEDSPACE:
2348 LyXText * lt = bv_->getLyXText();
2350 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2352 if (style.free_spacing) {
2353 lt->insertChar(bv_, ' ');
2356 | BufferView::FITCUR
2357 | BufferView::CHANGE);
2359 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2361 moveCursorUpdate(false);
2367 LyXText * lt = bv_->getLyXText();
2369 if (lt->selection.mark()) {
2373 | BufferView::FITCUR);
2374 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2377 lt->selection.mark(true);
2380 | BufferView::FITCUR);
2381 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2383 lt->selection.cursor = lt->cursor;
2389 LyXText * lt = bv_->getLyXText();
2391 if (!lt->selection.set()) {
2393 lt->selection.cursor = lt->cursor;
2396 | BufferView::FITCUR
2397 | BufferView::CHANGE);
2398 // It is possible to make it a lot faster still
2399 // just comment out the line below...
2404 moveCursorUpdate(false);
2405 owner_->showState();
2410 case LFUN_DELETE_SKIP:
2412 LyXText * lt = bv_->getLyXText();
2414 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2416 LyXCursor cursor = lt->cursor;
2418 if (!lt->selection.set()) {
2419 if (cursor.pos() == cursor.par()->size()) {
2420 lt->cursorRight(bv_);
2421 cursor = lt->cursor;
2422 if (cursor.pos() == 0
2423 && !(cursor.par()->params().spaceTop()
2424 == VSpace (VSpace::NONE))) {
2427 cursor.par()->params().lineTop(),
2428 cursor.par()->params().lineBottom(),
2429 cursor.par()->params().pagebreakTop(),
2430 cursor.par()->params().pagebreakBottom(),
2431 VSpace(VSpace::NONE),
2432 cursor.par()->params().spaceBottom(),
2433 cursor.par()->params().spacing(),
2434 cursor.par()->params().align(),
2435 cursor.par()->params().labelWidthString(), 0);
2436 lt->cursorLeft(bv_);
2439 | BufferView::FITCUR
2440 | BufferView::CHANGE);
2442 lt->cursorLeft(bv_);
2444 lt->selection.cursor = lt->cursor;
2447 | BufferView::FITCUR
2448 | BufferView::CHANGE);
2452 lt->selection.cursor = lt->cursor;
2455 | BufferView::FITCUR
2456 | BufferView::CHANGE);
2464 /* -------> Delete word forward. */
2465 case LFUN_DELETE_WORD_FORWARD:
2466 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2467 bv_->getLyXText()->deleteWordForward(bv_);
2468 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2469 moveCursorUpdate(false);
2470 owner_->showState();
2473 /* -------> Delete word backward. */
2474 case LFUN_DELETE_WORD_BACKWARD:
2476 LyXText * lt = bv_->getLyXText();
2478 update(lt, BufferView::SELECT|BufferView::FITCUR);
2479 lt->deleteWordBackward(bv_);
2482 | BufferView::FITCUR
2483 | BufferView::CHANGE);
2484 moveCursorUpdate(false);
2485 owner_->showState();
2489 /* -------> Kill to end of line. */
2490 case LFUN_DELETE_LINE_FORWARD:
2492 LyXText * lt = bv_->getLyXText();
2494 update(lt, BufferView::SELECT|BufferView::FITCUR);
2495 lt->deleteLineForward(bv_);
2498 | BufferView::FITCUR
2499 | BufferView::CHANGE);
2500 moveCursorUpdate(false);
2504 /* -------> Set mark off. */
2507 LyXText * lt = bv_->getLyXText();
2510 update(lt, BufferView::SELECT|BufferView::FITCUR);
2511 lt->selection.cursor = lt->cursor;
2512 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2516 /* -------> Set mark on. */
2519 LyXText * lt = bv_->getLyXText();
2522 lt->selection.mark(true);
2523 update(lt, BufferView::SELECT|BufferView::FITCUR);
2524 lt->selection.cursor = lt->cursor;
2525 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2529 case LFUN_BACKSPACE:
2531 LyXText * lt = bv_->getLyXText();
2533 if (!lt->selection.set()) {
2534 if (owner_->getIntl()->getTrans().backspace()) {
2536 lt->selection.cursor = lt->cursor;
2539 | BufferView::FITCUR
2540 | BufferView::CHANGE);
2541 // It is possible to make it a lot faster still
2542 // just comment out the line below...
2548 owner_->showState();
2553 case LFUN_BACKSPACE_SKIP:
2555 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2556 LyXText * lt = bv_->getLyXText();
2558 LyXCursor cursor = lt->cursor;
2560 if (!lt->selection.set()) {
2561 if (cursor.pos() == 0
2562 && !(cursor.par()->params().spaceTop()
2563 == VSpace (VSpace::NONE))) {
2566 cursor.par()->params().lineTop(),
2567 cursor.par()->params().lineBottom(),
2568 cursor.par()->params().pagebreakTop(),
2569 cursor.par()->params().pagebreakBottom(),
2570 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2571 cursor.par()->params().spacing(),
2572 cursor.par()->params().align(),
2573 cursor.par()->params().labelWidthString(), 0);
2576 | BufferView::FITCUR
2577 | BufferView::CHANGE);
2580 lt->selection.cursor = cursor;
2583 | BufferView::FITCUR
2584 | BufferView::CHANGE);
2591 case LFUN_BREAKPARAGRAPH:
2593 LyXText * lt = bv_->getLyXText();
2596 lt->breakParagraph(bv_, 0);
2599 | BufferView::FITCUR
2600 | BufferView::CHANGE);
2601 lt->selection.cursor = lt->cursor;
2603 owner_->showState();
2607 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2609 LyXText * lt = bv_->getLyXText();
2612 lt->breakParagraph(bv_, 1);
2615 | BufferView::FITCUR
2616 | BufferView::CHANGE);
2617 lt->selection.cursor = lt->cursor;
2619 owner_->showState();
2623 case LFUN_BREAKPARAGRAPH_SKIP:
2625 // When at the beginning of a paragraph, remove
2626 // indentation and add a "defskip" at the top.
2627 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2628 LyXText * lt = bv_->getLyXText();
2630 LyXCursor cursor = lt->cursor;
2633 if (cursor.pos() == 0) {
2634 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2637 cursor.par()->params().lineTop(),
2638 cursor.par()->params().lineBottom(),
2639 cursor.par()->params().pagebreakTop(),
2640 cursor.par()->params().pagebreakBottom(),
2641 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2642 cursor.par()->params().spacing(),
2643 cursor.par()->params().align(),
2644 cursor.par()->params().labelWidthString(), 1);
2645 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2649 lt->breakParagraph(bv_, 0);
2650 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2655 | BufferView::FITCUR
2656 | BufferView::CHANGE);
2657 lt->selection.cursor = cursor;
2659 owner_->showState();
2663 case LFUN_PARAGRAPH_SPACING:
2665 LyXText * lt = bv_->getLyXText();
2667 Paragraph * par = lt->cursor.par();
2668 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2669 float cur_value = 1.0;
2670 if (cur_spacing == Spacing::Other) {
2671 cur_value = par->params().spacing().getValue();
2674 istringstream istr(argument.c_str());
2678 Spacing::Space new_spacing = cur_spacing;
2679 float new_value = cur_value;
2681 lyxerr << "Missing argument to `paragraph-spacing'"
2683 } else if (tmp == "single") {
2684 new_spacing = Spacing::Single;
2685 } else if (tmp == "onehalf") {
2686 new_spacing = Spacing::Onehalf;
2687 } else if (tmp == "double") {
2688 new_spacing = Spacing::Double;
2689 } else if (tmp == "other") {
2690 new_spacing = Spacing::Other;
2693 lyxerr << "new_value = " << tmpval << endl;
2696 } else if (tmp == "default") {
2697 new_spacing = Spacing::Default;
2699 lyxerr << _("Unknown spacing argument: ")
2700 << argument << endl;
2702 if (cur_spacing != new_spacing || cur_value != new_value) {
2703 par->params().spacing(Spacing(new_spacing, new_value));
2704 lt->redoParagraph(bv_);
2707 | BufferView::FITCUR
2708 | BufferView::CHANGE);
2713 case LFUN_INSET_TOGGLE:
2715 LyXText * lt = bv_->getLyXText();
2718 update(lt, BufferView::SELECT|BufferView::FITCUR);
2719 lt->toggleInset(bv_);
2720 update(lt, BufferView::SELECT|BufferView::FITCUR);
2732 InsetCommandParams p;
2733 if (action == LFUN_HTMLURL)
2734 p.setCmdName("htmlurl");
2736 p.setCmdName("url");
2737 owner_->getDialogs()->createUrl(p.getAsString());
2741 case LFUN_INSERT_URL:
2743 InsetCommandParams p;
2744 p.setFromString(argument);
2746 InsetUrl * inset = new InsetUrl(p);
2747 if (!insertInset(inset))
2750 updateInset(inset, true);
2754 case LFUN_INSET_TEXT:
2755 insertAndEditInset(new InsetText(buffer_->params));
2758 case LFUN_INSET_ERT:
2759 insertAndEditInset(new InsetERT(buffer_->params));
2762 case LFUN_INSET_EXTERNAL:
2763 insertAndEditInset(new InsetExternal);
2766 case LFUN_INSET_FOOTNOTE:
2767 insertAndEditInset(new InsetFoot(buffer_->params));
2770 case LFUN_INSET_MARGINAL:
2771 insertAndEditInset(new InsetMarginal(buffer_->params));
2774 case LFUN_INSET_MINIPAGE:
2775 insertAndEditInset(new InsetMinipage(buffer_->params));
2778 case LFUN_INSERT_NOTE:
2779 insertAndEditInset(new InsetNote(buffer_->params));
2782 case LFUN_INSET_FLOAT:
2783 // check if the float type exist
2784 if (floatList.typeExist(argument)) {
2785 insertAndEditInset(new InsetFloat(buffer_->params,
2788 lyxerr << "Non-existent float type: "
2789 << argument << endl;
2793 case LFUN_INSET_WIDE_FLOAT:
2795 // check if the float type exist
2796 if (floatList.typeExist(argument)) {
2797 InsetFloat * new_inset =
2798 new InsetFloat(buffer_->params, argument);
2799 new_inset->wide(true);
2800 if (insertInset(new_inset))
2801 new_inset->edit(bv_);
2805 lyxerr << "Non-existent float type: "
2806 << argument << endl;
2813 case LFUN_INSET_LIST:
2814 insertAndEditInset(new InsetList);
2817 case LFUN_INSET_THEOREM:
2818 insertAndEditInset(new InsetTheorem);
2822 case LFUN_INSET_CAPTION:
2824 // Do we have a locking inset...
2825 if (bv_->theLockingInset()) {
2826 lyxerr << "Locking inset code: "
2827 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2828 InsetCaption * new_inset =
2829 new InsetCaption(buffer_->params);
2830 new_inset->setOwner(bv_->theLockingInset());
2831 new_inset->setAutoBreakRows(true);
2832 new_inset->setDrawFrame(0, InsetText::LOCKED);
2833 new_inset->setFrameColor(0, LColor::captionframe);
2834 if (insertInset(new_inset))
2835 new_inset->edit(bv_);
2842 case LFUN_INSET_TABULAR:
2846 if (!argument.empty())
2847 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2848 InsetTabular * new_inset =
2849 new InsetTabular(*buffer_, r, c);
2851 bv_->getLyXText()->real_current_font.isRightToLeft();
2852 if (!open_new_inset(new_inset, rtl))
2857 // --- lyxserver commands ----------------------------
2859 case LFUN_CHARATCURSOR:
2861 pos_type pos = bv_->getLyXText()->cursor.pos();
2862 if (pos < bv_->getLyXText()->cursor.par()->size())
2863 owner_->getLyXFunc()->setMessage(
2864 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2866 owner_->getLyXFunc()->setMessage("EOF");
2871 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2873 + tostr(bv_->getLyXText()->cursor.y()));
2880 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2881 lyxerr << "SETXY: Could not parse coordinates in '"
2882 << argument << std::endl;
2884 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2888 case LFUN_GETLAYOUT:
2889 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2894 LyXFont & font = bv_->getLyXText()->current_font;
2895 if (font.shape() == LyXFont::ITALIC_SHAPE)
2896 owner_->getLyXFunc()->setMessage("E");
2897 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2898 owner_->getLyXFunc()->setMessage("N");
2900 owner_->getLyXFunc()->setMessage("0");
2905 // --- accented characters ---------------------------
2908 case LFUN_CIRCUMFLEX:
2918 case LFUN_SPECIAL_CARON:
2921 case LFUN_HUNG_UMLAUT:
2924 if (argument.empty()) {
2926 owner_->getLyXFunc()->handleKeyFunc(action);
2928 owner_->getLyXFunc()->handleKeyFunc(action);
2929 owner_->getIntl()->getTrans()
2930 .TranslateAndInsert(argument[0], bv_->getLyXText());
2931 update(bv_->getLyXText(),
2933 | BufferView::FITCUR
2934 | BufferView::CHANGE);
2938 case LFUN_MATH_MACRO:
2939 mathDispatchMathMacro(bv_, argument);
2942 case LFUN_MATH_DELIM:
2943 mathDispatchMathDelim(bv_, argument);
2946 case LFUN_INSERT_MATRIX:
2947 mathDispatchInsertMatrix(bv_, argument);
2950 case LFUN_INSERT_MATH:
2951 mathDispatchInsertMath(bv_, argument);
2954 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2955 mathDispatchMathImportSelection(bv_, argument);
2958 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2959 mathDispatchMathDisplay(bv_, argument);
2962 case LFUN_MATH_MODE: // Open or create an inlined math inset
2963 mathDispatchMathMode(bv_, argument);
2966 case LFUN_GREEK: // Insert a single greek letter
2967 mathDispatchGreek(bv_, argument);
2970 case LFUN_CITATION_INSERT:
2972 InsetCommandParams p;
2973 p.setFromString(argument);
2975 InsetCitation * inset = new InsetCitation(p);
2976 if (!insertInset(inset))
2979 updateInset(inset, true);
2983 case LFUN_INSERT_BIBTEX:
2985 // ale970405+lasgoutt970425
2986 // The argument can be up to two tokens separated
2987 // by a space. The first one is the bibstyle.
2988 string const db = token(argument, ' ', 0);
2989 string const bibstyle = token(argument, ' ', 1);
2991 InsetCommandParams p("BibTeX", db, bibstyle);
2992 InsetBibtex * inset = new InsetBibtex(p);
2994 if (insertInset(inset)) {
2995 if (argument.empty())
3002 // BibTeX data bases
3003 case LFUN_BIBDB_ADD:
3005 InsetBibtex * inset =
3006 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3008 inset->addDatabase(argument);
3013 case LFUN_BIBDB_DEL:
3015 InsetBibtex * inset =
3016 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3018 inset->delDatabase(argument);
3023 case LFUN_BIBTEX_STYLE:
3025 InsetBibtex * inset =
3026 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3028 inset->setOptions(argument);
3033 case LFUN_INDEX_CREATE:
3035 InsetCommandParams p("index");
3036 if (argument.empty()) {
3037 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3038 p.setContents(idxstring);
3040 p.setContents(argument);
3043 owner_->getDialogs()->createIndex(p.getAsString());
3047 case LFUN_INDEX_INSERT:
3049 InsetCommandParams p;
3050 p.setFromString(argument);
3051 InsetIndex * inset = new InsetIndex(p);
3053 if (!insertInset(inset))
3056 updateInset(inset, true);
3060 case LFUN_INDEX_INSERT_LAST:
3062 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3063 if (!idxstring.empty()) {
3064 owner_->message(_("Word `")
3065 + idxstring + _(("' indexed.")));
3066 InsetCommandParams p("index", idxstring);
3067 InsetIndex * inset = new InsetIndex(p);
3069 if (!insertInset(inset))
3072 updateInset(inset, true);
3077 case LFUN_INDEX_PRINT:
3079 InsetCommandParams p("printindex");
3080 Inset * inset = new InsetPrintIndex(p);
3081 if (!insertInset(inset, "Standard"))
3086 case LFUN_PARENTINSERT:
3088 lyxerr << "arg " << argument << endl;
3089 InsetCommandParams p("lyxparent", argument);
3090 Inset * inset = new InsetParent(p, *buffer_);
3091 if (!insertInset(inset, "Standard"))
3097 case LFUN_CHILD_INSERT:
3099 InsetInclude::Params p;
3100 p.cparams.setFromString(argument);
3101 p.masterFilename_ = buffer_->fileName();
3103 InsetInclude * inset = new InsetInclude(p);
3104 if (!insertInset(inset))
3107 updateInset(inset, true);
3108 bv_->owner()->getDialogs()->showInclude(inset);
3113 case LFUN_FLOAT_LIST:
3115 // We should check the argument for validity. (Lgb)
3116 Inset * inset = new InsetFloatList(argument);
3117 if (!insertInset(inset, "Standard"))
3122 case LFUN_THESAURUS_ENTRY:
3124 string arg = argument;
3127 arg = bv_->getLyXText()->selectionAsString(buffer_,
3131 if (arg.size() > 100 || arg.empty()) {
3132 // Get word or selection
3133 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3134 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3135 // FIXME: where is getLyXText()->unselect(bv_) ?
3139 bv_->owner()->getDialogs()->showThesaurus(arg);
3143 case LFUN_SELFINSERT:
3145 if (argument.empty()) break;
3147 /* Automatically delete the currently selected
3148 * text and replace it with what is being
3149 * typed in now. Depends on lyxrc settings
3150 * "auto_region_delete", which defaults to
3153 LyXText * lt = bv_->getLyXText();
3155 if (lyxrc.auto_region_delete) {
3156 if (lt->selection.set()) {
3157 lt->cutSelection(bv_, false, false);
3160 | BufferView::FITCUR
3161 | BufferView::CHANGE);
3166 LyXFont const old_font(lt->real_current_font);
3168 string::const_iterator cit = argument.begin();
3169 string::const_iterator end = argument.end();
3170 for (; cit != end; ++cit) {
3171 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3176 | BufferView::FITCUR
3177 | BufferView::CHANGE);
3179 lt->selection.cursor = lt->cursor;
3180 moveCursorUpdate(false);
3182 // real_current_font.number can change so we need to
3183 // update the minibuffer
3184 if (old_font != lt->real_current_font)
3185 owner_->showState();
3190 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3192 time_t now_time_t = time(NULL);
3193 struct tm * now_tm = localtime(&now_time_t);
3194 setlocale(LC_TIME, "");
3196 if (!argument.empty())
3199 arg = lyxrc.date_insert_format;
3201 int const datetmp_len =
3202 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3204 LyXText * lt = bv_->getLyXText();
3206 for (int i = 0; i < datetmp_len; i++) {
3207 lt->insertChar(bv_, datetmp[i]);
3210 | BufferView::FITCUR
3211 | BufferView::CHANGE);
3214 lt->selection.cursor = lt->cursor;
3215 moveCursorUpdate(false);
3219 case LFUN_UNKNOWN_ACTION:
3220 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3231 void BufferView::Pimpl::newline()
3234 LyXText * lt = bv_->getLyXText();
3238 | BufferView::FITCUR);
3239 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3242 | BufferView::FITCUR
3243 | BufferView::CHANGE);
3248 void BufferView::Pimpl::hfill()
3251 LyXText * lt = bv_->getLyXText();
3255 | BufferView::FITCUR);
3256 lt->insertChar(bv_, Paragraph::META_HFILL);
3259 | BufferView::FITCUR
3260 | BufferView::CHANGE);
3265 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3268 LyXText * lt = bv_->getLyXText();
3271 update(lt, BufferView::SELECT|BufferView::FITCUR);
3272 InsetSpecialChar * new_inset =
3273 new InsetSpecialChar(kind);
3274 if (!insertInset(new_inset))
3277 updateInset(new_inset, true);
3282 void BufferView::Pimpl::smartQuote()
3284 LyXText const * lt = bv_->getLyXText();
3285 Paragraph const * par = lt->cursor.par();
3286 pos_type pos = lt->cursor.pos();
3290 || (par->isInset(pos - 1)
3291 && par->getInset(pos - 1)->isSpace()))
3294 c = par->getChar(pos - 1);
3299 LyXLayout const & style =
3300 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3302 if (style.pass_thru ||
3303 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3304 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3308 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3310 if (insertInset(inset))
3317 // Open and lock an updatable inset
3318 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3320 LyXText * lt = bv_->getLyXText();
3324 if (!insertInset(new_inset)) {
3328 new_inset->edit(bv_, !behind);
3333 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3335 // if we are in a locking inset we should try to insert the
3336 // inset there otherwise this is a illegal function now
3337 if (bv_->theLockingInset()) {
3338 if (bv_->theLockingInset()->insetAllowed(inset))
3339 return bv_->theLockingInset()->insertInset(bv_, inset);
3343 // not quite sure if we want this...
3344 setCursorParUndo(bv_);
3347 beforeChange(bv_->text);
3348 if (!lout.empty()) {
3349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3350 bv_->text->breakParagraph(bv_);
3351 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 if (bv_->text->cursor.par()->size()) {
3354 bv_->text->cursorLeft(bv_);
3356 bv_->text->breakParagraph(bv_);
3357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3361 LyXTextClass const & tclass =
3362 textclasslist[buffer_->params.textclass];
3363 bool hasLayout = tclass.hasLayout(lres);
3364 string lay = tclass.defaultLayoutName();
3366 if (hasLayout != false) {
3370 // layout not fount using default
3371 lay = tclass.defaultLayoutName();
3374 bv_->text->setLayout(bv_, lay);
3376 bv_->text->setParagraph(bv_, 0, 0,
3378 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3383 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3386 bv_->text->insertInset(bv_, inset);
3387 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3394 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3396 if (!inset || !available())
3399 // first check for locking insets
3400 if (bv_->theLockingInset()) {
3401 if (bv_->theLockingInset() == inset) {
3402 if (bv_->text->updateInset(bv_, inset)) {
3405 buffer_->markDirty();
3410 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3411 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3414 buffer_->markDirty();
3422 // then check if the inset is a top_level inset (has no owner)
3423 // if yes do the update as always otherwise we have to update the
3424 // toplevel inset where this inset is inside
3425 Inset * tl_inset = inset;
3426 while(tl_inset->owner())
3427 tl_inset = tl_inset->owner();
3429 if (tl_inset == inset) {
3430 update(bv_->text, BufferView::UPDATE);
3431 if (bv_->text->updateInset(bv_, inset)) {
3435 | BufferView::FITCUR
3436 | BufferView::CHANGE);
3438 update(bv_->text, SELECT);
3442 } else if (static_cast<UpdatableInset *>(tl_inset)
3443 ->updateInsetInInset(bv_, inset))
3445 if (bv_->text->updateInset(bv_, tl_inset)) {
3453 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3456 if (!available()) return;
3459 beforeChange(bv_->text);
3460 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3462 LyXCursor const & cursor = bv_->text->cursor;
3466 cursor.par()->isInset(cursor.pos())) {
3467 Inset const * inset = cursor.par()->getInset(cursor.pos());
3468 if (find(codes.begin(), codes.end(), inset->lyxCode())
3471 static_cast<InsetCommand const *>(inset)->getContents();
3475 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3476 if (bv_->text->cursor.pos()
3477 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3478 LyXCursor tmp = bv_->text->cursor;
3479 bv_->text->cursor.par(bv_->text->ownerParagraph());
3480 bv_->text->cursor.pos(0);
3481 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3482 bv_->text->cursor = tmp;
3483 bv_->owner()->message(_("No more insets"));
3486 bv_->owner()->message(_("No more insets"));
3489 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3490 bv_->text->selection.cursor = bv_->text->cursor;
3494 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3496 gotoInset(vector<Inset::Code>(1, code), same_content);