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);
373 buffer_->resizeInsets(bv_);
375 // this will scroll the screen such that the cursor becomes visible
380 owner_->allowInput();
382 /// clear the "Formatting Document" message
389 void BufferView::Pimpl::updateScreen()
391 // Regenerate the screen.
392 screen_.reset(new LyXScreen(workarea_));
396 void BufferView::Pimpl::updateScrollbar()
398 /* If the text is smaller than the working area, the scrollbar
399 * maximum must be the working area height. No scrolling will
402 workarea_.setScrollbar(0, 1.0);
406 long const text_height = bv_->text->height;
407 long const work_height = workarea_.height();
409 if (text_height <= work_height) {
410 workarea_.setScrollbarBounds(0.0, 0.0);
411 current_scrollbar_value = bv_->text->first_y;
412 workarea_.setScrollbar(current_scrollbar_value, 1.0);
416 double const lineh = bv_->text->defaultHeight();
417 double const slider_size =
418 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
420 static long old_text_height;
421 static double old_lineh;
422 static double old_slider_size;
424 if (text_height != old_text_height) {
425 workarea_.setScrollbarBounds(0.0,
426 text_height - work_height);
427 old_text_height = text_height;
429 if (lineh != old_lineh) {
430 workarea_.setScrollbarIncrements(lineh);
433 if (current_scrollbar_value != bv_->text->first_y
434 || slider_size != old_slider_size) {
435 current_scrollbar_value = bv_->text->first_y;
436 workarea_.setScrollbar(current_scrollbar_value, slider_size);
437 old_slider_size = slider_size;
442 // Callback for scrollbar slider
443 void BufferView::Pimpl::scrollCB(double value)
445 if (!buffer_) return;
447 current_scrollbar_value = long(value);
449 if (current_scrollbar_value < 0)
450 current_scrollbar_value = 0;
455 screen_->draw(bv_->text, bv_, current_scrollbar_value);
457 if (!lyxrc.cursor_follows_scrollbar) {
462 LyXText * vbt = bv_->text;
464 int const height = vbt->defaultHeight();
465 int const first = static_cast<int>((bv_->text->first_y + height));
466 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
468 if (vbt->cursor.y() < first)
469 vbt->setCursorFromCoordinates(bv_, 0, first);
470 else if (vbt->cursor.y() > last)
471 vbt->setCursorFromCoordinates(bv_, 0, last);
477 int BufferView::Pimpl::scrollUp(long time)
479 if (!buffer_) return 0;
480 if (!screen_.get()) return 0;
482 double value = workarea_.getScrollbarValue();
484 if (value == 0) return 0;
486 float add_value = (bv_->text->defaultHeight()
487 + float(time) * float(time) * 0.125);
489 if (add_value > workarea_.height())
490 add_value = float(workarea_.height() -
491 bv_->text->defaultHeight());
498 workarea_.setScrollbarValue(value);
505 int BufferView::Pimpl::scrollDown(long time)
507 if (!buffer_) return 0;
508 if (!screen_.get()) return 0;
510 double value = workarea_.getScrollbarValue();
511 pair<float, float> p = workarea_.getScrollbarBounds();
512 double const max = p.second;
514 if (value == max) return 0;
516 float add_value = (bv_->text->defaultHeight()
517 + float(time) * float(time) * 0.125);
519 if (add_value > workarea_.height())
520 add_value = float(workarea_.height() -
521 bv_->text->defaultHeight());
528 workarea_.setScrollbarValue(value);
535 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
537 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
541 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
543 // Only use motion with button 1
544 if (!(state & Button1MotionMask))
547 if (!buffer_ || !screen_.get()) return;
549 // Check for inset locking
550 if (bv_->theLockingInset()) {
551 LyXCursor cursor = bv_->text->cursor;
552 LyXFont font = bv_->text->getFont(buffer_,
553 cursor.par(), cursor.pos());
554 int width = bv_->theLockingInset()->width(bv_, font);
555 int inset_x = font.isVisibleRightToLeft()
556 ? cursor.x() - width : cursor.x();
557 int start_x = inset_x + bv_->theLockingInset()->scroll();
558 bv_->theLockingInset()->
559 insetMotionNotify(bv_,
561 y - cursor.y() + bv_->text->first_y,
566 /* The test for not selection possible is needed, that only motion
567 events are used, where the bottom press event was on
568 the drawing area too */
569 if (!selection_possible)
572 screen_->hideCursor();
574 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
576 if (!bv_->text->selection.set())
577 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
579 bv_->text->setSelection(bv_);
580 screen_->toggleToggle(bv_->text, bv_);
586 // Single-click on work area
587 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
590 if (!buffer_ || !screen_.get()) return;
592 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
594 // ok ok, this is a hack.
595 if (button == 4 || button == 5) {
598 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
601 scrollDown(lyxrc.wheel_jump);
606 if (bv_->theLockingInset()) {
607 // We are in inset locking mode
609 /* Check whether the inset was hit. If not reset mode,
610 otherwise give the event to the inset */
611 if (inset_hit == bv_->theLockingInset()) {
612 bv_->theLockingInset()->
613 insetButtonPress(bv_,xpos, ypos,button);
616 bv_->unlockInset(bv_->theLockingInset());
621 selection_possible = true;
622 screen_->hideCursor();
624 int const screen_first = bv_->text->first_y;
626 // Middle button press pastes if we have a selection
627 bool paste_internally = false;
629 && bv_->text->selection.set()) {
630 owner_->getLyXFunc()->dispatch(LFUN_COPY);
631 paste_internally = true;
634 // Clear the selection
635 screen_->toggleSelection(bv_->text, bv_);
636 bv_->text->clearSelection();
637 bv_->text->fullRebreak(bv_);
641 // Single left click in math inset?
642 if (isHighlyEditableInset(inset_hit)) {
643 // Highly editable inset, like math
644 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
645 selection_possible = false;
646 owner_->updateLayoutChoice();
647 owner_->message(inset->editMessage());
648 // IMO the inset has to be first in edit-mode and then we send the
649 // button press. (Jug 20020222)
650 inset->edit(bv_); //, xpos, ypos, button);
651 inset->insetButtonPress(bv_, xpos, ypos, button);
655 // Right click on a footnote flag opens float menu
657 selection_possible = false;
661 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
662 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
664 bv_->text->selection.cursor = bv_->text->cursor;
665 bv_->text->cursor.x_fix(bv_->text->cursor.x());
667 owner_->updateLayoutChoice();
669 selection_possible = false;
672 // Insert primary selection with middle mouse
673 // if there is a local selection in the current buffer,
676 if (paste_internally)
677 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
679 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
681 selection_possible = false;
687 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
693 LyXText * text = bv_->getLyXText();
695 if (text->bv_owner && bv_->theLockingInset())
698 if (screen_.get() && button == 1) {
699 if (text->bv_owner) {
700 screen_->hideCursor();
701 screen_->toggleSelection(text, bv_);
702 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
703 screen_->toggleSelection(text, bv_, false);
705 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
707 /* This will fit the cursor on the screen
709 update(text, BufferView::SELECT|BufferView::FITCUR);
714 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
720 LyXText * text = bv_->getLyXText();
722 if (text->bv_owner && bv_->theLockingInset())
725 if (screen_.get() && (button == 1)) {
726 if (text->bv_owner) {
727 screen_->hideCursor();
728 screen_->toggleSelection(text, bv_);
730 text->cursorHome(bv_);
731 text->selection.cursor = text->cursor;
732 text->cursorEnd(bv_);
733 text->setSelection(bv_);
734 if (text->bv_owner) {
735 screen_->toggleSelection(text, bv_, false);
737 /* This will fit the cursor on the screen
739 update(text, BufferView::SELECT|BufferView::FITCUR);
744 void BufferView::Pimpl::selectionRequested()
749 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
752 workarea_.putClipboard(sel);
757 void BufferView::Pimpl::selectionLost()
759 if (active() && available()) {
762 bv_->getLyXText()->clearSelection();
768 void BufferView::Pimpl::enterView()
770 if (active() && available()) {
771 SetXtermCursor(workarea_.getWin());
772 using_xterm_cursor = true;
777 void BufferView::Pimpl::leaveView()
779 if (using_xterm_cursor) {
780 XUndefineCursor(fl_get_display(), workarea_.getWin());
781 using_xterm_cursor = false;
786 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
789 if (!buffer_ || !screen_.get()) return;
791 // If we hit an inset, we have the inset coordinates in these
792 // and inset_hit points to the inset. If we do not hit an
793 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
794 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
796 if (bv_->theLockingInset()) {
797 // We are in inset locking mode.
799 /* LyX does a kind of work-area grabbing for insets.
800 Only a ButtonPress Event outside the inset will
801 force a insetUnlock. */
802 bv_->theLockingInset()->
803 insetButtonRelease(bv_, x, y, button);
807 selection_possible = false;
814 workarea_.haveSelection(bv_->getLyXText()->selection.set());
819 owner_->updateMenubar();
820 owner_->updateToolbar();
822 // Did we hit an editable inset?
824 selection_possible = false;
826 // if we reach this point with a selection, it
827 // must mean we are currently selecting.
828 // But we don't want to open the inset
829 // because that is annoying for the user.
830 // So just pretend we didn't hit it.
831 // this is OK because a "kosher" ButtonRelease
832 // will follow a ButtonPress that clears
834 // Note this also fixes selection drawing
835 // problems if we end up opening an inset
836 if (bv_->getLyXText()->selection.set())
839 // CHECK fix this proper in 0.13
840 // well, maybe 13.0 !!!!!!!!!
842 // Following a ref shouldn't issue
843 // a push on the undo-stack
844 // anylonger, now that we have
845 // keybindings for following
846 // references and returning from
847 // references. IMHO though, it
848 // should be the inset's own business
849 // to push or not push on the undo
850 // stack. They don't *have* to
851 // alter the document...
853 // ...or maybe the SetCursorParUndo()
854 // below isn't necessary at all anylonger?
855 if (inset_hit->lyxCode() == Inset::REF_CODE) {
856 setCursorParUndo(bv_);
859 owner_->message(inset_hit->editMessage());
861 if (isHighlyEditableInset(inset_hit)) {
862 // Highly editable inset, like math
863 UpdatableInset *inset = (UpdatableInset *)inset_hit;
864 inset->insetButtonRelease(bv_, x, y, button);
866 inset_hit->insetButtonRelease(bv_, x, y, button);
867 inset_hit->edit(bv_, x, y, button);
872 // Maybe we want to edit a bibitem ale970302
873 if (bv_->text->cursor.par()->bibkey && x < 20 +
874 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
875 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
882 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
883 LyXCursor const & cursor) const
885 Paragraph /*const*/ & par = *cursor.par();
886 pos_type const pos = cursor.pos();
888 lyx::Assert(par.getInset(pos));
890 Inset const & inset(*par.getInset(pos));
892 LyXFont const & font = text.getFont(buffer_, &par, pos);
894 int const width = inset.width(bv_, font);
895 int const inset_x = font.isVisibleRightToLeft()
896 ? (cursor.x() - width) : cursor.x();
899 inset_x + inset.scroll(),
901 cursor.y() - inset.ascent(bv_, font),
902 cursor.y() + inset.descent(bv_, font));
906 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
907 LyXCursor const & cursor,
908 int & x, int & y) const
910 pos_type const pos(cursor.pos());
911 Paragraph /*const*/ & par(*cursor.par());
913 if (pos >= par.size() || !par.isInset(pos)) {
917 Inset /*const*/ * inset = par.getInset(pos);
919 if (!isEditableInset(inset)) {
923 Box b(insetDimensions(text, cursor));
925 if (!b.contained(x, y)) {
926 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
927 << " box " << b << endl;
931 text.setCursor(bv_, &par, pos, true);
934 // The origin of an inset is on the baseline
935 y -= (text.cursor.y());
941 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
946 int y_tmp = y + text->first_y;
949 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
951 Inset * inset(checkInset(*text, cursor, x, y_tmp));
958 // look at previous position
960 if (cursor.pos() == 0) {
965 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
967 inset = checkInset(*text, cursor, x, y_tmp);
975 void BufferView::Pimpl::workAreaExpose()
977 static int work_area_width;
978 static unsigned int work_area_height;
980 bool const widthChange = workarea_.workWidth() != work_area_width;
981 bool const heightChange = workarea_.height() != work_area_height;
983 // update from work area
984 work_area_width = workarea_.workWidth();
985 work_area_height = workarea_.height();
988 // The visible LyXView need a resize
991 // Remove all texts from the textcache
992 // This is not _really_ what we want to do. What
993 // we really want to do is to delete in textcache
994 // that does not have a BufferView with matching
995 // width, but as long as we have only one BufferView
996 // deleting all gives the same result.
997 if (lyxerr.debugging())
998 textcache.show(lyxerr, "Expose delete all");
1000 } else if (heightChange) {
1001 // Rebuild image of current screen
1003 // fitCursor() ensures we don't jump back
1004 // to the start of the document on vertical
1008 // The main window size has changed, repaint most stuff
1010 } else if (screen_.get())
1011 screen_->redraw(bv_->text, bv_);
1013 // Grey box when we don't have a buffer
1014 workarea_.greyOut();
1017 // always make sure that the scrollbar is sane.
1019 owner_->updateLayoutChoice();
1024 void BufferView::Pimpl::update()
1026 if (screen_.get() &&
1027 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1029 LyXText::text_status st = bv_->text->status();
1030 screen_->update(bv_->text, bv_);
1032 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1033 if (bv_->text->fullRebreak(bv_)) {
1034 st = LyXText::NEED_MORE_REFRESH;
1035 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1036 bv_->text->cursor.pos());
1039 bv_->text->status(bv_, st);
1040 screen_->update(bv_->text, bv_);
1042 // do this here instead of in the screen::update because of
1044 bv_->text->status(bv_, LyXText::UNCHANGED);
1050 // Values used when calling update:
1052 // -2 - update, move sel_cursor if selection, fitcursor
1053 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1054 // 0 - update, move sel_cursor if selection, fitcursor
1055 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1056 // 3 - update, move sel_cursor if selection
1059 // a simple redraw of the parts that need refresh
1061 // move sel_cursor if selection -
1062 // the text's sel_cursor is moved if there is selection is progress
1065 // fitCursor() is called and the scrollbar updated
1068 // the buffer is marked dirty.
1077 // UPDATE_ONLY = UPDATE;
1078 // UPDATE_SELECT = UPDATE | SELECT;
1079 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1080 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1082 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1083 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1084 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1085 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1086 // update(3) -> update(1) -> update(1) -> update(SELECT)
1088 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1090 owner_->updateLayoutChoice();
1092 if (!text->selection.set() && (f & SELECT)) {
1093 text->selection.cursor = text->cursor;
1096 text->fullRebreak(bv_);
1098 if (text->inset_owner) {
1099 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1100 updateInset(text->inset_owner, false);
1110 buffer_->markDirty();
1115 // Callback for cursor timer
1116 void BufferView::Pimpl::cursorToggle()
1119 cursor_timeout.restart();
1123 if (!screen_.get()) {
1124 cursor_timeout.restart();
1129 extern void reapSpellchecker(void);
1132 if (!bv_->theLockingInset()) {
1133 screen_->cursorToggle(bv_);
1135 bv_->theLockingInset()->toggleInsetCursor(bv_);
1138 cursor_timeout.restart();
1142 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1144 if (!text->cursor.row()->previous())
1147 int y = text->first_y;
1148 Row * cursorrow = text->cursor.row();
1150 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1152 // This is to allow jumping over large insets
1153 if ((cursorrow == text->cursor.row()))
1154 text->cursorUp(bv_);
1156 if (text->inset_owner ||
1157 text->cursor.row()->height() < workarea_.height())
1158 screen_->draw(bv_->text, bv_,
1160 - text->cursor.row()->baseline()
1161 + text->cursor.row()->height()
1162 - workarea_.height() + 1);
1167 void BufferView::Pimpl::cursorNext(LyXText * text)
1169 if (!text->cursor.row()->next())
1172 int y = text->first_y + workarea_.height();
1173 // if (text->inset_owner)
1174 // y += bv_->text->first;
1175 text->getRowNearY(y);
1177 Row * cursorrow = text->cursor.row();
1178 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1180 // This is to allow jumping over large insets
1181 if ((cursorrow == bv_->text->cursor.row()))
1182 text->cursorDown(bv_);
1184 if (text->inset_owner ||
1185 text->cursor.row()->height() < workarea_.height())
1186 screen_->draw(bv_->text, bv_, text->cursor.y() -
1187 text->cursor.row()->baseline());
1192 bool BufferView::Pimpl::available() const
1194 if (buffer_ && bv_->text)
1200 void BufferView::Pimpl::beforeChange(LyXText * text)
1203 text->clearSelection();
1207 void BufferView::Pimpl::savePosition(unsigned int i)
1209 if (i >= saved_positions_num)
1211 saved_positions[i] = Position(buffer_->fileName(),
1212 bv_->text->cursor.par()->id(),
1213 bv_->text->cursor.pos());
1216 str << _("Saved bookmark") << ' ' << i;
1217 owner_->message(str.str().c_str());
1222 void BufferView::Pimpl::restorePosition(unsigned int i)
1224 if (i >= saved_positions_num)
1227 string const fname = saved_positions[i].filename;
1229 beforeChange(bv_->text);
1231 if (fname != buffer_->fileName()) {
1232 Buffer * b = bufferlist.exists(fname) ?
1233 bufferlist.getBuffer(fname) :
1234 bufferlist.loadLyXFile(fname); // don't ask, just load it
1235 if (b != 0) buffer(b);
1238 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1242 bv_->text->setCursor(bv_, par,
1243 min(par->size(), saved_positions[i].par_pos));
1245 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1248 str << _("Moved to bookmark") << ' ' << i;
1249 owner_->message(str.str().c_str());
1254 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1256 if (i >= saved_positions_num)
1259 return !saved_positions[i].filename.empty();
1263 void BufferView::Pimpl::setState()
1265 if (!lyxrc.rtl_support)
1268 LyXText * text = bv_->getLyXText();
1269 if (text->real_current_font.isRightToLeft()) {
1270 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1271 owner_->getIntl()->KeyMapSec();
1273 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1274 owner_->getIntl()->KeyMapPrim();
1279 void BufferView::Pimpl::insetSleep()
1281 if (bv_->theLockingInset() && !inset_slept) {
1282 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1283 bv_->theLockingInset()->insetUnlock(bv_);
1289 void BufferView::Pimpl::insetWakeup()
1291 if (bv_->theLockingInset() && inset_slept) {
1292 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1293 inset_slept = false;
1298 void BufferView::Pimpl::insetUnlock()
1300 if (bv_->theLockingInset()) {
1302 bv_->theLockingInset()->insetUnlock(bv_);
1303 bv_->theLockingInset(0);
1305 inset_slept = false;
1310 bool BufferView::Pimpl::focus() const
1312 return workarea_.hasFocus();
1316 void BufferView::Pimpl::focus(bool f)
1318 if (f) workarea_.setFocus();
1322 bool BufferView::Pimpl::active() const
1324 return workarea_.active();
1328 bool BufferView::Pimpl::belowMouse() const
1330 return workarea_.belowMouse();
1334 void BufferView::Pimpl::showCursor()
1336 if (screen_.get()) {
1337 if (bv_->theLockingInset())
1338 bv_->theLockingInset()->showInsetCursor(bv_);
1340 screen_->showCursor(bv_->text, bv_);
1345 void BufferView::Pimpl::hideCursor()
1347 if (screen_.get()) {
1348 if (!bv_->theLockingInset())
1349 // bv_->theLockingInset()->hideInsetCursor(bv_);
1351 screen_->hideCursor();
1356 void BufferView::Pimpl::toggleSelection(bool b)
1358 if (screen_.get()) {
1359 if (bv_->theLockingInset())
1360 bv_->theLockingInset()->toggleSelection(bv_, b);
1361 screen_->toggleSelection(bv_->text, bv_, b);
1366 void BufferView::Pimpl::toggleToggle()
1369 screen_->toggleToggle(bv_->text, bv_);
1373 void BufferView::Pimpl::center()
1375 beforeChange(bv_->text);
1376 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1377 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1379 screen_->draw(bv_->text, bv_, 0);
1381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1386 void BufferView::Pimpl::pasteClipboard(bool asPara)
1388 if (!buffer_) return;
1390 screen_->hideCursor();
1391 beforeChange(bv_->text);
1393 string const clip(workarea_.getClipboard());
1395 if (clip.empty()) return;
1398 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1400 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1402 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1406 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1408 workarea_.putClipboard(stuff);
1413 * Dispatch functions for actions which can be valid for BufferView->text
1414 * and/or InsetText->text!!!
1419 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1421 LyXText * lt = bv_->getLyXText();
1423 if (selecting || lt->selection.mark()) {
1424 lt->setSelection(bv_);
1428 update(lt, BufferView::SELECT|BufferView::FITCUR);
1431 /* ---> Everytime the cursor is moved, show the current font state. */
1432 // should this too me moved out of this func?
1433 //owner->showState();
1438 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1440 LyXCursor cursor = bv_->getLyXText()->cursor;
1441 Buffer::inset_iterator it =
1442 find_if(Buffer::inset_iterator(
1443 cursor.par(), cursor.pos()),
1444 buffer_->inset_iterator_end(),
1445 lyx::compare_memfun(&Inset::lyxCode, code));
1446 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1450 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1452 string filename = filen;
1454 if (filename.empty()) {
1455 // Launch a file browser
1456 string initpath = lyxrc.document_path;
1459 string const trypath = owner_->buffer()->filePath();
1460 // If directory is writeable, use this as default.
1461 if (IsDirWriteable(trypath))
1465 FileDialog fileDlg(bv_->owner(),
1466 _("Select LyX document to insert"),
1468 make_pair(string(_("Documents|#o#O")),
1469 string(lyxrc.document_path)),
1470 make_pair(string(_("Examples|#E#e")),
1471 string(AddPath(system_lyxdir, "examples"))));
1473 FileDialog::Result result =
1474 fileDlg.Select(initpath,
1475 _("*.lyx| LyX Documents (*.lyx)"));
1477 if (result.first == FileDialog::Later)
1480 filename = result.second;
1482 // check selected filename
1483 if (filename.empty()) {
1484 owner_->message(_("Canceled."));
1489 // get absolute path of file and add ".lyx" to the filename if
1491 filename = FileSearch(string(), filename, "lyx");
1493 string const disp_fn(MakeDisplayPath(filename));
1496 s1 << _("Inserting document") << ' '
1497 << disp_fn << " ...";
1498 owner_->message(s1.str().c_str());
1499 bool const res = bv_->insertLyXFile(filename);
1502 str << _("Document") << ' ' << disp_fn
1503 << ' ' << _("inserted.");
1504 owner_->message(str.str().c_str());
1507 str << _("Could not insert document") << ' '
1509 owner_->message(str.str().c_str());
1514 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1516 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1517 << action <<"] arg[" << argument << "]" << endl;
1520 // --- Misc -------------------------------------------
1524 LyXText * lt = bv_->getLyXText();
1525 lt->toggleAppendix(bv_);
1528 | BufferView::FITCUR
1529 | BufferView::CHANGE);
1534 case LFUN_TOC_INSERT:
1536 InsetCommandParams p;
1537 p.setCmdName("tableofcontents");
1538 Inset * inset = new InsetTOC(p);
1539 if (!insertInset(inset, "Standard"))
1544 case LFUN_SCROLL_INSET:
1545 // this is not handled here as this funktion is only aktive
1546 // if we have a locking_inset and that one is (or contains)
1550 case LFUN_INSET_GRAPHICS:
1552 Inset * new_inset = new InsetGraphics;
1553 if (!insertInset(new_inset)) {
1556 // this is need because you don't use a inset->Edit()
1557 updateInset(new_inset, true);
1558 new_inset->edit(bv_);
1568 case LFUN_PASTESELECTION:
1570 bool asPara = false;
1571 if (argument == "paragraph")
1573 pasteClipboard(asPara);
1585 case LFUN_LAYOUT_COPY:
1586 bv_->copyEnvironment();
1589 case LFUN_LAYOUT_PASTE:
1590 bv_->pasteEnvironment();
1594 case LFUN_GOTOERROR:
1595 gotoInset(Inset::ERROR_CODE, false);
1599 gotoInset(Inset::IGNORE_CODE, false);
1602 case LFUN_REFERENCE_GOTO:
1604 vector<Inset::Code> tmp;
1605 tmp.push_back(Inset::LABEL_CODE);
1606 tmp.push_back(Inset::REF_CODE);
1607 gotoInset(tmp, true);
1611 case LFUN_HYPHENATION:
1612 specialChar(InsetSpecialChar::HYPHENATION);
1615 case LFUN_LIGATURE_BREAK:
1616 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1620 specialChar(InsetSpecialChar::LDOTS);
1623 case LFUN_END_OF_SENTENCE:
1624 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1627 case LFUN_MENU_SEPARATOR:
1628 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1636 changeDepth(bv_, bv_->getLyXText(), 0);
1639 case LFUN_DEPTH_MIN:
1640 changeDepth(bv_, bv_->getLyXText(), -1);
1643 case LFUN_DEPTH_PLUS:
1644 changeDepth(bv_, bv_->getLyXText(), 1);
1648 owner_->getDialogs()->setUserFreeFont();
1651 case LFUN_FILE_INSERT:
1652 MenuInsertLyXFile(argument);
1655 case LFUN_FILE_INSERT_ASCII_PARA:
1656 InsertAsciiFile(bv_, argument, true);
1659 case LFUN_FILE_INSERT_ASCII:
1660 InsertAsciiFile(bv_, argument, false);
1665 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1666 << argument << endl;
1668 // Derive layout number from given argument (string)
1669 // and current buffer's textclass (number). */
1670 textclass_type tclass = buffer_->params.textclass;
1672 textclasslist[tclass].hasLayout(argument);
1673 string layout = argument;
1675 // If the entry is obsolete, use the new one instead.
1677 string const & obs = textclasslist[tclass][layout]
1684 owner_->getLyXFunc()->setErrorMessage(
1685 string(N_("Layout ")) + argument +
1690 if (current_layout != layout) {
1691 LyXText * lt = bv_->getLyXText();
1693 current_layout = layout;
1696 | BufferView::FITCUR);
1697 lt->setLayout(bv_, layout);
1698 owner_->setLayout(layout);
1701 | BufferView::FITCUR
1702 | BufferView::CHANGE);
1709 lang(bv_, argument);
1711 owner_->showState();
1716 owner_->showState();
1721 owner_->showState();
1726 owner_->showState();
1731 owner_->showState();
1736 owner_->showState();
1741 owner_->showState();
1746 owner_->showState();
1749 case LFUN_UNDERLINE:
1751 owner_->showState();
1754 case LFUN_FONT_SIZE:
1755 fontSize(bv_, argument);
1756 owner_->showState();
1759 case LFUN_FONT_STATE:
1760 owner_->getLyXFunc()->setMessage(currentState(bv_));
1763 case LFUN_UPCASE_WORD:
1765 LyXText * lt = bv_->getLyXText();
1769 | BufferView::FITCUR);
1770 lt->changeCase(bv_, LyXText::text_uppercase);
1771 if (lt->inset_owner)
1772 updateInset(lt->inset_owner, true);
1775 | BufferView::FITCUR
1776 | BufferView::CHANGE);
1780 case LFUN_LOWCASE_WORD:
1782 LyXText * lt = bv_->getLyXText();
1784 update(lt, BufferView::SELECT|BufferView::FITCUR);
1785 lt->changeCase(bv_, LyXText::text_lowercase);
1786 if (lt->inset_owner)
1787 updateInset(lt->inset_owner, true);
1790 | BufferView::FITCUR
1791 | BufferView::CHANGE);
1795 case LFUN_CAPITALIZE_WORD:
1797 LyXText * lt = bv_->getLyXText();
1799 update(lt, BufferView::SELECT|BufferView::FITCUR);
1800 lt->changeCase(bv_, LyXText::text_capitalization);
1801 if (lt->inset_owner)
1802 updateInset(lt->inset_owner, true);
1805 | BufferView::FITCUR
1806 | BufferView::CHANGE);
1810 case LFUN_TRANSPOSE_CHARS:
1812 LyXText * lt = bv_->getLyXText();
1814 update(lt, BufferView::SELECT|BufferView::FITCUR);
1815 lt->transposeChars(*bv_);
1816 if (lt->inset_owner)
1817 updateInset(lt->inset_owner, true);
1820 | BufferView::FITCUR
1821 | BufferView::CHANGE);
1826 case LFUN_INSERT_LABEL:
1827 MenuInsertLabel(bv_, argument);
1830 case LFUN_REF_INSERT:
1831 if (argument.empty()) {
1832 InsetCommandParams p("ref");
1833 owner_->getDialogs()->createRef(p.getAsString());
1835 InsetCommandParams p;
1836 p.setFromString(argument);
1838 InsetRef * inset = new InsetRef(p, *buffer_);
1839 if (!insertInset(inset))
1842 updateInset(inset, true);
1846 case LFUN_BOOKMARK_SAVE:
1847 savePosition(strToUnsignedInt(argument));
1850 case LFUN_BOOKMARK_GOTO:
1851 restorePosition(strToUnsignedInt(argument));
1856 string label(argument);
1857 if (label.empty()) {
1859 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1861 label = inset->getContents();
1866 if (!label.empty()) {
1867 //bv_->savePosition(0);
1868 if (!bv_->gotoLabel(label))
1869 Alert::alert(_("Error"),
1870 _("Couldn't find this label"),
1871 _("in current document."));
1876 // --- Cursor Movements -----------------------------
1879 LyXText * lt = bv_->getLyXText();
1881 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1882 if (!lt->selection.mark())
1884 update(lt, BufferView::SELECT|BufferView::FITCUR);
1886 lt->cursorLeft(bv_, false);
1887 if (lt->cursor.pos() < lt->cursor.par()->size()
1888 && lt->cursor.par()->isInset(lt->cursor.pos())
1889 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1890 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1891 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1893 tmpinset->edit(bv_, false);
1895 tmpinset->edit(bv_);
1899 lt->cursorRight(bv_, false);
1901 moveCursorUpdate(false);
1902 owner_->showState();
1908 // This is soooo ugly. Isn`t it possible to make
1909 // it simpler? (Lgb)
1910 LyXText * lt = bv_->getLyXText();
1911 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1912 if (!lt->selection.mark())
1914 update(lt, BufferView::SELECT|BufferView::FITCUR);
1915 LyXCursor const cur = lt->cursor;
1917 lt->cursorLeft(bv_, false);
1918 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1919 lt->cursor.pos() < lt->cursor.par()->size() &&
1920 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1921 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1922 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1923 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1925 tmpinset->edit(bv_);
1927 tmpinset->edit(bv_, false);
1931 lt->cursorRight(bv_, false);
1934 moveCursorUpdate(false);
1935 owner_->showState();
1941 LyXText * lt = bv_->getLyXText();
1943 if (!lt->selection.mark())
1945 update(lt, BufferView::UPDATE);
1948 moveCursorUpdate(false);
1949 owner_->showState();
1955 LyXText * lt = bv_->getLyXText();
1957 if (!lt->selection.mark())
1959 update(lt, BufferView::UPDATE);
1960 lt->cursorDown(bv_);
1962 moveCursorUpdate(false);
1963 owner_->showState();
1967 case LFUN_UP_PARAGRAPH:
1969 LyXText * lt = bv_->getLyXText();
1971 if (!lt->selection.mark())
1973 update(lt, BufferView::UPDATE);
1974 lt->cursorUpParagraph(bv_);
1976 moveCursorUpdate(false);
1977 owner_->showState();
1981 case LFUN_DOWN_PARAGRAPH:
1983 LyXText * lt = bv_->getLyXText();
1985 if (!lt->selection.mark())
1987 update(lt, BufferView::UPDATE);
1988 lt->cursorDownParagraph(bv_);
1990 moveCursorUpdate(false);
1991 owner_->showState();
1997 LyXText * lt = bv_->getLyXText();
1999 if (!lt->selection.mark())
2001 update(lt, BufferView::UPDATE);
2004 moveCursorUpdate(false);
2005 owner_->showState();
2011 LyXText * lt = bv_->getLyXText();
2013 if (!lt->selection.mark())
2015 update(lt, BufferView::UPDATE);
2018 moveCursorUpdate(false);
2019 owner_->showState();
2025 LyXText * lt = bv_->getLyXText();
2027 if (!lt->selection.mark())
2029 update(lt, BufferView::SELECT|BufferView::FITCUR);
2030 lt->cursorHome(bv_);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2039 LyXText * lt = bv_->getLyXText();
2041 if (!lt->selection.mark())
2044 BufferView::SELECT|BufferView::FITCUR);
2047 moveCursorUpdate(false);
2048 owner_->showState();
2052 case LFUN_SHIFT_TAB:
2055 LyXText * lt = bv_->getLyXText();
2057 if (!lt->selection.mark())
2060 BufferView::SELECT|BufferView::FITCUR);
2063 moveCursorUpdate(false);
2064 owner_->showState();
2068 case LFUN_WORDRIGHT:
2070 LyXText * lt = bv_->getLyXText();
2072 if (!lt->selection.mark())
2074 update(lt, BufferView::SELECT|BufferView::FITCUR);
2075 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2076 lt->cursorLeftOneWord(bv_);
2078 lt->cursorRightOneWord(bv_);
2080 moveCursorUpdate(false);
2081 owner_->showState();
2087 LyXText * lt = bv_->getLyXText();
2089 if (!lt->selection.mark())
2091 update(lt, BufferView::SELECT|BufferView::FITCUR);
2092 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2093 lt->cursorRightOneWord(bv_);
2095 lt->cursorLeftOneWord(bv_);
2097 moveCursorUpdate(false);
2098 owner_->showState();
2102 case LFUN_BEGINNINGBUF:
2104 LyXText * lt = bv_->getLyXText();
2106 if (!lt->selection.mark())
2109 BufferView::SELECT|BufferView::FITCUR);
2112 moveCursorUpdate(false);
2113 owner_->showState();
2119 LyXText * lt = bv_->getLyXText();
2121 if (!lt->selection.mark())
2124 BufferView::SELECT|BufferView::FITCUR);
2125 lt->cursorBottom(bv_);
2127 moveCursorUpdate(false);
2128 owner_->showState();
2132 /* cursor selection ---------------------------- */
2135 LyXText * lt = bv_->getLyXText();
2138 BufferView::SELECT|BufferView::FITCUR);
2139 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2140 lt->cursorLeft(bv_);
2142 lt->cursorRight(bv_);
2144 moveCursorUpdate(true);
2145 owner_->showState();
2151 LyXText * lt = bv_->getLyXText();
2154 BufferView::SELECT|BufferView::FITCUR);
2155 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2156 lt->cursorRight(bv_);
2158 lt->cursorLeft(bv_);
2160 moveCursorUpdate(true);
2161 owner_->showState();
2167 LyXText * lt = bv_->getLyXText();
2170 BufferView::SELECT|BufferView::FITCUR);
2173 moveCursorUpdate(true);
2174 owner_->showState();
2180 LyXText * lt = bv_->getLyXText();
2183 BufferView::SELECT|BufferView::FITCUR);
2184 lt->cursorDown(bv_);
2186 moveCursorUpdate(true);
2187 owner_->showState();
2191 case LFUN_UP_PARAGRAPHSEL:
2193 LyXText * lt = bv_->getLyXText();
2196 BufferView::SELECT|BufferView::FITCUR);
2197 lt->cursorUpParagraph(bv_);
2199 moveCursorUpdate(true);
2200 owner_->showState();
2204 case LFUN_DOWN_PARAGRAPHSEL:
2206 LyXText * lt = bv_->getLyXText();
2209 BufferView::SELECT|BufferView::FITCUR);
2210 lt->cursorDownParagraph(bv_);
2212 moveCursorUpdate(true);
2213 owner_->showState();
2219 LyXText * lt = bv_->getLyXText();
2221 update(lt, BufferView::SELECT|BufferView::FITCUR);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 moveCursorUpdate(true);
2237 owner_->showState();
2243 LyXText * lt = bv_->getLyXText();
2245 update(lt, BufferView::SELECT|BufferView::FITCUR);
2246 lt->cursorHome(bv_);
2248 moveCursorUpdate(true);
2249 owner_->showState();
2255 LyXText * lt = bv_->getLyXText();
2257 update(lt, BufferView::SELECT|BufferView::FITCUR);
2260 moveCursorUpdate(true);
2261 owner_->showState();
2265 case LFUN_WORDRIGHTSEL:
2267 LyXText * lt = bv_->getLyXText();
2269 update(lt, BufferView::SELECT|BufferView::FITCUR);
2270 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2271 lt->cursorLeftOneWord(bv_);
2273 lt->cursorRightOneWord(bv_);
2275 moveCursorUpdate(true);
2276 owner_->showState();
2280 case LFUN_WORDLEFTSEL:
2282 LyXText * lt = bv_->getLyXText();
2284 update(lt, BufferView::SELECT|BufferView::FITCUR);
2285 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2286 lt->cursorRightOneWord(bv_);
2288 lt->cursorLeftOneWord(bv_);
2290 moveCursorUpdate(true);
2291 owner_->showState();
2295 case LFUN_BEGINNINGBUFSEL:
2297 LyXText * lt = bv_->getLyXText();
2299 if (lt->inset_owner)
2301 update(lt, BufferView::SELECT|BufferView::FITCUR);
2304 moveCursorUpdate(true);
2305 owner_->showState();
2309 case LFUN_ENDBUFSEL:
2311 LyXText * lt = bv_->getLyXText();
2313 if (lt->inset_owner)
2316 BufferView::SELECT|BufferView::FITCUR);
2317 lt->cursorBottom(bv_);
2319 moveCursorUpdate(true);
2320 owner_->showState();
2324 // --- text changing commands ------------------------
2325 case LFUN_BREAKLINE:
2327 LyXText * lt = bv_->getLyXText();
2330 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2333 | BufferView::FITCUR
2334 | BufferView::CHANGE);
2335 moveCursorUpdate(false);
2339 case LFUN_PROTECTEDSPACE:
2341 LyXText * lt = bv_->getLyXText();
2343 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2345 if (style.free_spacing) {
2346 lt->insertChar(bv_, ' ');
2349 | BufferView::FITCUR
2350 | BufferView::CHANGE);
2354 moveCursorUpdate(false);
2360 LyXText * lt = bv_->getLyXText();
2362 if (lt->selection.mark()) {
2366 | BufferView::FITCUR);
2367 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2370 lt->selection.mark(true);
2373 | BufferView::FITCUR);
2374 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2376 lt->selection.cursor = lt->cursor;
2382 LyXText * lt = bv_->getLyXText();
2384 if (!lt->selection.set()) {
2386 lt->selection.cursor = lt->cursor;
2389 | BufferView::FITCUR
2390 | BufferView::CHANGE);
2391 // It is possible to make it a lot faster still
2392 // just comment out the line below...
2397 moveCursorUpdate(false);
2398 owner_->showState();
2403 case LFUN_DELETE_SKIP:
2405 LyXText * lt = bv_->getLyXText();
2407 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2409 LyXCursor cursor = lt->cursor;
2411 if (!lt->selection.set()) {
2412 if (cursor.pos() == cursor.par()->size()) {
2413 lt->cursorRight(bv_);
2414 cursor = lt->cursor;
2415 if (cursor.pos() == 0
2416 && !(cursor.par()->params().spaceTop()
2417 == VSpace (VSpace::NONE))) {
2420 cursor.par()->params().lineTop(),
2421 cursor.par()->params().lineBottom(),
2422 cursor.par()->params().pagebreakTop(),
2423 cursor.par()->params().pagebreakBottom(),
2424 VSpace(VSpace::NONE),
2425 cursor.par()->params().spaceBottom(),
2426 cursor.par()->params().spacing(),
2427 cursor.par()->params().align(),
2428 cursor.par()->params().labelWidthString(), 0);
2429 lt->cursorLeft(bv_);
2432 | BufferView::FITCUR
2433 | BufferView::CHANGE);
2435 lt->cursorLeft(bv_);
2437 lt->selection.cursor = lt->cursor;
2440 | BufferView::FITCUR
2441 | BufferView::CHANGE);
2445 lt->selection.cursor = lt->cursor;
2448 | BufferView::FITCUR
2449 | BufferView::CHANGE);
2457 /* -------> Delete word forward. */
2458 case LFUN_DELETE_WORD_FORWARD:
2459 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2460 bv_->getLyXText()->deleteWordForward(bv_);
2461 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2462 moveCursorUpdate(false);
2463 owner_->showState();
2466 /* -------> Delete word backward. */
2467 case LFUN_DELETE_WORD_BACKWARD:
2469 LyXText * lt = bv_->getLyXText();
2471 update(lt, BufferView::SELECT|BufferView::FITCUR);
2472 lt->deleteWordBackward(bv_);
2475 | BufferView::FITCUR
2476 | BufferView::CHANGE);
2477 moveCursorUpdate(false);
2478 owner_->showState();
2482 /* -------> Kill to end of line. */
2483 case LFUN_DELETE_LINE_FORWARD:
2485 LyXText * lt = bv_->getLyXText();
2487 update(lt, BufferView::SELECT|BufferView::FITCUR);
2488 lt->deleteLineForward(bv_);
2491 | BufferView::FITCUR
2492 | BufferView::CHANGE);
2493 moveCursorUpdate(false);
2497 /* -------> Set mark off. */
2500 LyXText * lt = bv_->getLyXText();
2503 update(lt, BufferView::SELECT|BufferView::FITCUR);
2504 lt->selection.cursor = lt->cursor;
2505 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2509 /* -------> Set mark on. */
2512 LyXText * lt = bv_->getLyXText();
2515 lt->selection.mark(true);
2516 update(lt, BufferView::SELECT|BufferView::FITCUR);
2517 lt->selection.cursor = lt->cursor;
2518 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2522 case LFUN_BACKSPACE:
2524 LyXText * lt = bv_->getLyXText();
2526 if (!lt->selection.set()) {
2527 if (owner_->getIntl()->getTrans().backspace()) {
2529 lt->selection.cursor = lt->cursor;
2532 | BufferView::FITCUR
2533 | BufferView::CHANGE);
2534 // It is possible to make it a lot faster still
2535 // just comment out the line below...
2541 owner_->showState();
2546 case LFUN_BACKSPACE_SKIP:
2548 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2549 LyXText * lt = bv_->getLyXText();
2551 LyXCursor cursor = lt->cursor;
2553 if (!lt->selection.set()) {
2554 if (cursor.pos() == 0
2555 && !(cursor.par()->params().spaceTop()
2556 == VSpace (VSpace::NONE))) {
2559 cursor.par()->params().lineTop(),
2560 cursor.par()->params().lineBottom(),
2561 cursor.par()->params().pagebreakTop(),
2562 cursor.par()->params().pagebreakBottom(),
2563 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2564 cursor.par()->params().spacing(),
2565 cursor.par()->params().align(),
2566 cursor.par()->params().labelWidthString(), 0);
2569 | BufferView::FITCUR
2570 | BufferView::CHANGE);
2573 lt->selection.cursor = cursor;
2576 | BufferView::FITCUR
2577 | BufferView::CHANGE);
2584 case LFUN_BREAKPARAGRAPH:
2586 LyXText * lt = bv_->getLyXText();
2589 lt->breakParagraph(bv_, 0);
2592 | BufferView::FITCUR
2593 | BufferView::CHANGE);
2594 lt->selection.cursor = lt->cursor;
2596 owner_->showState();
2600 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2602 LyXText * lt = bv_->getLyXText();
2605 lt->breakParagraph(bv_, 1);
2608 | BufferView::FITCUR
2609 | BufferView::CHANGE);
2610 lt->selection.cursor = lt->cursor;
2612 owner_->showState();
2616 case LFUN_BREAKPARAGRAPH_SKIP:
2618 // When at the beginning of a paragraph, remove
2619 // indentation and add a "defskip" at the top.
2620 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2621 LyXText * lt = bv_->getLyXText();
2623 LyXCursor cursor = lt->cursor;
2626 if (cursor.pos() == 0) {
2627 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2630 cursor.par()->params().lineTop(),
2631 cursor.par()->params().lineBottom(),
2632 cursor.par()->params().pagebreakTop(),
2633 cursor.par()->params().pagebreakBottom(),
2634 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2635 cursor.par()->params().spacing(),
2636 cursor.par()->params().align(),
2637 cursor.par()->params().labelWidthString(), 1);
2638 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2642 lt->breakParagraph(bv_, 0);
2643 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2648 | BufferView::FITCUR
2649 | BufferView::CHANGE);
2650 lt->selection.cursor = cursor;
2652 owner_->showState();
2656 case LFUN_PARAGRAPH_SPACING:
2658 LyXText * lt = bv_->getLyXText();
2660 Paragraph * par = lt->cursor.par();
2661 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2662 float cur_value = 1.0;
2663 if (cur_spacing == Spacing::Other) {
2664 cur_value = par->params().spacing().getValue();
2667 istringstream istr(argument.c_str());
2671 Spacing::Space new_spacing = cur_spacing;
2672 float new_value = cur_value;
2674 lyxerr << "Missing argument to `paragraph-spacing'"
2676 } else if (tmp == "single") {
2677 new_spacing = Spacing::Single;
2678 } else if (tmp == "onehalf") {
2679 new_spacing = Spacing::Onehalf;
2680 } else if (tmp == "double") {
2681 new_spacing = Spacing::Double;
2682 } else if (tmp == "other") {
2683 new_spacing = Spacing::Other;
2686 lyxerr << "new_value = " << tmpval << endl;
2689 } else if (tmp == "default") {
2690 new_spacing = Spacing::Default;
2692 lyxerr << _("Unknown spacing argument: ")
2693 << argument << endl;
2695 if (cur_spacing != new_spacing || cur_value != new_value) {
2696 par->params().spacing(Spacing(new_spacing, new_value));
2697 lt->redoParagraph(bv_);
2700 | BufferView::FITCUR
2701 | BufferView::CHANGE);
2706 case LFUN_INSET_TOGGLE:
2708 LyXText * lt = bv_->getLyXText();
2711 update(lt, BufferView::SELECT|BufferView::FITCUR);
2712 lt->toggleInset(bv_);
2713 update(lt, BufferView::SELECT|BufferView::FITCUR);
2725 InsetCommandParams p;
2726 if (action == LFUN_HTMLURL)
2727 p.setCmdName("htmlurl");
2729 p.setCmdName("url");
2730 owner_->getDialogs()->createUrl(p.getAsString());
2734 case LFUN_INSERT_URL:
2736 InsetCommandParams p;
2737 p.setFromString(argument);
2739 InsetUrl * inset = new InsetUrl(p);
2740 if (!insertInset(inset))
2743 updateInset(inset, true);
2747 case LFUN_INSET_TEXT:
2748 insertAndEditInset(new InsetText(buffer_->params));
2751 case LFUN_INSET_ERT:
2752 insertAndEditInset(new InsetERT(buffer_->params));
2755 case LFUN_INSET_EXTERNAL:
2756 insertAndEditInset(new InsetExternal);
2759 case LFUN_INSET_FOOTNOTE:
2760 insertAndEditInset(new InsetFoot(buffer_->params));
2763 case LFUN_INSET_MARGINAL:
2764 insertAndEditInset(new InsetMarginal(buffer_->params));
2767 case LFUN_INSET_MINIPAGE:
2768 insertAndEditInset(new InsetMinipage(buffer_->params));
2771 case LFUN_INSERT_NOTE:
2772 insertAndEditInset(new InsetNote(buffer_->params));
2775 case LFUN_INSET_FLOAT:
2776 // check if the float type exist
2777 if (floatList.typeExist(argument)) {
2778 insertAndEditInset(new InsetFloat(buffer_->params,
2781 lyxerr << "Non-existent float type: "
2782 << argument << endl;
2786 case LFUN_INSET_WIDE_FLOAT:
2788 // check if the float type exist
2789 if (floatList.typeExist(argument)) {
2790 InsetFloat * new_inset =
2791 new InsetFloat(buffer_->params, argument);
2792 new_inset->wide(true);
2793 if (insertInset(new_inset))
2794 new_inset->edit(bv_);
2798 lyxerr << "Non-existent float type: "
2799 << argument << endl;
2806 case LFUN_INSET_LIST:
2807 insertAndEditInset(new InsetList);
2810 case LFUN_INSET_THEOREM:
2811 insertAndEditInset(new InsetTheorem);
2815 case LFUN_INSET_CAPTION:
2817 // Do we have a locking inset...
2818 if (bv_->theLockingInset()) {
2819 lyxerr << "Locking inset code: "
2820 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2821 InsetCaption * new_inset =
2822 new InsetCaption(buffer_->params);
2823 new_inset->setOwner(bv_->theLockingInset());
2824 new_inset->setAutoBreakRows(true);
2825 new_inset->setDrawFrame(0, InsetText::LOCKED);
2826 new_inset->setFrameColor(0, LColor::captionframe);
2827 if (insertInset(new_inset))
2828 new_inset->edit(bv_);
2835 case LFUN_INSET_TABULAR:
2839 if (!argument.empty())
2840 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2841 InsetTabular * new_inset =
2842 new InsetTabular(*buffer_, r, c);
2844 bv_->getLyXText()->real_current_font.isRightToLeft();
2845 if (!open_new_inset(new_inset, rtl))
2850 // --- lyxserver commands ----------------------------
2852 case LFUN_CHARATCURSOR:
2854 pos_type pos = bv_->getLyXText()->cursor.pos();
2855 if (pos < bv_->getLyXText()->cursor.par()->size())
2856 owner_->getLyXFunc()->setMessage(
2857 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2859 owner_->getLyXFunc()->setMessage("EOF");
2864 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2866 + tostr(bv_->getLyXText()->cursor.y()));
2873 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2874 lyxerr << "SETXY: Could not parse coordinates in '"
2875 << argument << std::endl;
2877 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2881 case LFUN_GETLAYOUT:
2882 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2887 LyXFont & font = bv_->getLyXText()->current_font;
2888 if (font.shape() == LyXFont::ITALIC_SHAPE)
2889 owner_->getLyXFunc()->setMessage("E");
2890 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2891 owner_->getLyXFunc()->setMessage("N");
2893 owner_->getLyXFunc()->setMessage("0");
2898 // --- accented characters ---------------------------
2901 case LFUN_CIRCUMFLEX:
2911 case LFUN_SPECIAL_CARON:
2914 case LFUN_HUNG_UMLAUT:
2917 if (argument.empty()) {
2919 owner_->getLyXFunc()->handleKeyFunc(action);
2921 owner_->getLyXFunc()->handleKeyFunc(action);
2922 owner_->getIntl()->getTrans()
2923 .TranslateAndInsert(argument[0], bv_->getLyXText());
2924 update(bv_->getLyXText(),
2926 | BufferView::FITCUR
2927 | BufferView::CHANGE);
2931 case LFUN_MATH_MACRO:
2932 mathDispatchMathMacro(bv_, argument);
2935 case LFUN_MATH_DELIM:
2936 mathDispatchMathDelim(bv_, argument);
2939 case LFUN_INSERT_MATRIX:
2940 mathDispatchInsertMatrix(bv_, argument);
2943 case LFUN_INSERT_MATH:
2944 mathDispatchInsertMath(bv_, argument);
2947 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2948 mathDispatchMathImportSelection(bv_, argument);
2951 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2952 mathDispatchMathDisplay(bv_, argument);
2955 case LFUN_MATH_MODE: // Open or create an inlined math inset
2956 mathDispatchMathMode(bv_, argument);
2959 case LFUN_GREEK: // Insert a single greek letter
2960 mathDispatchGreek(bv_, argument);
2963 case LFUN_CITATION_INSERT:
2965 InsetCommandParams p;
2966 p.setFromString(argument);
2968 InsetCitation * inset = new InsetCitation(p);
2969 if (!insertInset(inset))
2972 updateInset(inset, true);
2976 case LFUN_INSERT_BIBTEX:
2978 // ale970405+lasgoutt970425
2979 // The argument can be up to two tokens separated
2980 // by a space. The first one is the bibstyle.
2981 string const db = token(argument, ' ', 0);
2982 string const bibstyle = token(argument, ' ', 1);
2984 InsetCommandParams p("BibTeX", db, bibstyle);
2985 InsetBibtex * inset = new InsetBibtex(p);
2987 if (insertInset(inset)) {
2988 if (argument.empty())
2995 // BibTeX data bases
2996 case LFUN_BIBDB_ADD:
2998 InsetBibtex * inset =
2999 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3001 inset->addDatabase(argument);
3006 case LFUN_BIBDB_DEL:
3008 InsetBibtex * inset =
3009 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3011 inset->delDatabase(argument);
3016 case LFUN_BIBTEX_STYLE:
3018 InsetBibtex * inset =
3019 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3021 inset->setOptions(argument);
3026 case LFUN_INDEX_CREATE:
3028 InsetCommandParams p("index");
3029 if (argument.empty()) {
3030 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3031 p.setContents(idxstring);
3033 p.setContents(argument);
3036 owner_->getDialogs()->createIndex(p.getAsString());
3040 case LFUN_INDEX_INSERT:
3042 InsetCommandParams p;
3043 p.setFromString(argument);
3044 InsetIndex * inset = new InsetIndex(p);
3046 if (!insertInset(inset))
3049 updateInset(inset, true);
3053 case LFUN_INDEX_INSERT_LAST:
3055 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3056 if (!idxstring.empty()) {
3057 owner_->message(_("Word `")
3058 + idxstring + _(("' indexed.")));
3059 InsetCommandParams p("index", idxstring);
3060 InsetIndex * inset = new InsetIndex(p);
3062 if (!insertInset(inset))
3065 updateInset(inset, true);
3070 case LFUN_INDEX_PRINT:
3072 InsetCommandParams p("printindex");
3073 Inset * inset = new InsetPrintIndex(p);
3074 if (!insertInset(inset, "Standard"))
3079 case LFUN_PARENTINSERT:
3081 lyxerr << "arg " << argument << endl;
3082 InsetCommandParams p("lyxparent", argument);
3083 Inset * inset = new InsetParent(p, *buffer_);
3084 if (!insertInset(inset, "Standard"))
3090 case LFUN_CHILD_INSERT:
3092 InsetInclude::Params p;
3093 p.cparams.setFromString(argument);
3094 p.masterFilename_ = buffer_->fileName();
3096 InsetInclude * inset = new InsetInclude(p);
3097 if (!insertInset(inset))
3100 updateInset(inset, true);
3101 bv_->owner()->getDialogs()->showInclude(inset);
3106 case LFUN_FLOAT_LIST:
3108 // We should check the argument for validity. (Lgb)
3109 Inset * inset = new InsetFloatList(argument);
3110 if (!insertInset(inset, "Standard"))
3115 case LFUN_THESAURUS_ENTRY:
3117 string arg = argument;
3120 arg = bv_->getLyXText()->selectionAsString(buffer_,
3124 if (arg.size() > 100 || arg.empty()) {
3125 // Get word or selection
3126 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3127 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3128 // FIXME: where is getLyXText()->unselect(bv_) ?
3132 bv_->owner()->getDialogs()->showThesaurus(arg);
3136 case LFUN_SELFINSERT:
3138 if (argument.empty()) break;
3140 /* Automatically delete the currently selected
3141 * text and replace it with what is being
3142 * typed in now. Depends on lyxrc settings
3143 * "auto_region_delete", which defaults to
3146 LyXText * lt = bv_->getLyXText();
3148 if (lyxrc.auto_region_delete) {
3149 if (lt->selection.set()) {
3150 lt->cutSelection(bv_, false, false);
3153 | BufferView::FITCUR
3154 | BufferView::CHANGE);
3159 LyXFont const old_font(lt->real_current_font);
3161 string::const_iterator cit = argument.begin();
3162 string::const_iterator end = argument.end();
3163 for (; cit != end; ++cit) {
3164 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3169 | BufferView::FITCUR
3170 | BufferView::CHANGE);
3172 lt->selection.cursor = lt->cursor;
3173 moveCursorUpdate(false);
3175 // real_current_font.number can change so we need to
3176 // update the minibuffer
3177 if (old_font != lt->real_current_font)
3178 owner_->showState();
3183 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3185 time_t now_time_t = time(NULL);
3186 struct tm * now_tm = localtime(&now_time_t);
3187 setlocale(LC_TIME, "");
3189 if (!argument.empty())
3192 arg = lyxrc.date_insert_format;
3194 int const datetmp_len =
3195 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3197 LyXText * lt = bv_->getLyXText();
3199 for (int i = 0; i < datetmp_len; i++) {
3200 lt->insertChar(bv_, datetmp[i]);
3203 | BufferView::FITCUR
3204 | BufferView::CHANGE);
3207 lt->selection.cursor = lt->cursor;
3208 moveCursorUpdate(false);
3212 case LFUN_UNKNOWN_ACTION:
3213 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3224 void BufferView::Pimpl::newline()
3227 LyXText * lt = bv_->getLyXText();
3231 | BufferView::FITCUR);
3232 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3235 | BufferView::FITCUR
3236 | BufferView::CHANGE);
3241 void BufferView::Pimpl::hfill()
3244 LyXText * lt = bv_->getLyXText();
3248 | BufferView::FITCUR);
3249 lt->insertChar(bv_, Paragraph::META_HFILL);
3252 | BufferView::FITCUR
3253 | BufferView::CHANGE);
3258 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3262 update(lt, BufferView::SELECT|BufferView::FITCUR);
3263 InsetSpecialChar * new_inset =
3264 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3265 #ifdef WITH_WARNINGS
3266 #warning Why is this code different from specialChar() below? (JMarc)
3267 // the code in specialChar is a generic version of what used to exist
3268 // for other special chars. I did not merge this case because of the
3269 // call to updateInset(), but what does it do?
3271 if (!insertInset(new_inset))
3274 updateInset(new_inset, true);
3279 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3282 LyXText * lt = bv_->getLyXText();
3285 update(lt, BufferView::SELECT|BufferView::FITCUR);
3286 InsetSpecialChar * new_inset =
3287 new InsetSpecialChar(kind);
3288 if (!insertInset(new_inset))
3294 void BufferView::Pimpl::smartQuote()
3296 LyXText const * lt = bv_->getLyXText();
3297 Paragraph const * par = lt->cursor.par();
3298 pos_type pos = lt->cursor.pos();
3302 || (par->isInset(pos - 1)
3303 && par->getInset(pos - 1)->isSpace()))
3306 c = par->getChar(pos - 1);
3311 LyXLayout const & style =
3312 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3314 if (style.pass_thru ||
3315 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3316 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3320 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3322 if (insertInset(inset))
3329 // Open and lock an updatable inset
3330 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3332 LyXText * lt = bv_->getLyXText();
3336 if (!insertInset(new_inset)) {
3340 new_inset->edit(bv_, !behind);
3345 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3347 // if we are in a locking inset we should try to insert the
3348 // inset there otherwise this is a illegal function now
3349 if (bv_->theLockingInset()) {
3350 if (bv_->theLockingInset()->insetAllowed(inset))
3351 return bv_->theLockingInset()->insertInset(bv_, inset);
3355 // not quite sure if we want this...
3356 setCursorParUndo(bv_);
3359 beforeChange(bv_->text);
3360 if (!lout.empty()) {
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3362 bv_->text->breakParagraph(bv_);
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3365 if (bv_->text->cursor.par()->size()) {
3366 bv_->text->cursorLeft(bv_);
3368 bv_->text->breakParagraph(bv_);
3369 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3373 LyXTextClass const & tclass =
3374 textclasslist[buffer_->params.textclass];
3375 bool hasLayout = tclass.hasLayout(lres);
3376 string lay = tclass.defaultLayoutName();
3378 if (hasLayout != false) {
3382 // layout not fount using default
3383 lay = tclass.defaultLayoutName();
3386 bv_->text->setLayout(bv_, lay);
3388 bv_->text->setParagraph(bv_, 0, 0,
3390 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3395 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3398 bv_->text->insertInset(bv_, inset);
3399 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3406 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3408 if (!inset || !available())
3411 // first check for locking insets
3412 if (bv_->theLockingInset()) {
3413 if (bv_->theLockingInset() == inset) {
3414 if (bv_->text->updateInset(bv_, inset)) {
3417 buffer_->markDirty();
3422 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3423 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3426 buffer_->markDirty();
3434 // then check if the inset is a top_level inset (has no owner)
3435 // if yes do the update as always otherwise we have to update the
3436 // toplevel inset where this inset is inside
3437 Inset * tl_inset = inset;
3438 while(tl_inset->owner())
3439 tl_inset = tl_inset->owner();
3441 if (tl_inset == inset) {
3442 update(bv_->text, BufferView::UPDATE);
3443 if (bv_->text->updateInset(bv_, inset)) {
3447 | BufferView::FITCUR
3448 | BufferView::CHANGE);
3450 update(bv_->text, SELECT);
3454 } else if (static_cast<UpdatableInset *>(tl_inset)
3455 ->updateInsetInInset(bv_, inset))
3457 if (bv_->text->updateInset(bv_, tl_inset)) {
3465 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3468 if (!available()) return;
3471 beforeChange(bv_->text);
3472 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3474 LyXCursor const & cursor = bv_->text->cursor;
3478 cursor.par()->isInset(cursor.pos())) {
3479 Inset const * inset = cursor.par()->getInset(cursor.pos());
3480 if (find(codes.begin(), codes.end(), inset->lyxCode())
3483 static_cast<InsetCommand const *>(inset)->getContents();
3487 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3488 if (bv_->text->cursor.pos()
3489 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3490 LyXCursor tmp = bv_->text->cursor;
3491 bv_->text->cursor.par(bv_->text->ownerParagraph());
3492 bv_->text->cursor.pos(0);
3493 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3494 bv_->text->cursor = tmp;
3495 bv_->owner()->message(_("No more insets"));
3498 bv_->owner()->message(_("No more insets"));
3501 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3502 bv_->text->selection.cursor = bv_->text->cursor;
3506 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3508 gotoInset(vector<Inset::Code>(1, code), same_content);