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();
329 buffer_->resizeInsets(bv_);
330 // I don't think the delete and new are necessary here we just could
331 // call only init! (Jug 20020419)
333 bv_->text = new LyXText(bv_);
334 bv_->text->init(bv_);
336 // See if we have a text in TextCache that fits
337 // the new buffer_ with the correct width.
338 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
340 if (lyxerr.debugging()) {
341 lyxerr << "Found a LyXText that fits:\n";
342 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
344 // Set the owner of the newly found text
345 // bv_->text->owner(bv_);
346 if (lyxerr.debugging())
347 textcache.show(lyxerr, "resizeCurrentBuffer");
349 bv_->text = new LyXText(bv_);
350 bv_->text->init(bv_);
351 //buffer_->resizeInsets(bv_);
358 bv_->text->selection.set(true);
359 // At this point just to avoid the Delete-Empty-Paragraph-
360 // Mechanism when setting the cursor.
361 bv_->text->selection.mark(mark_set);
363 bv_->text->setCursor(bv_, selstartpar, selstartpos);
364 bv_->text->selection.cursor = bv_->text->cursor;
365 bv_->text->setCursor(bv_, selendpar, selendpos);
366 bv_->text->setSelection(bv_);
367 bv_->text->setCursor(bv_, par, pos);
369 bv_->text->setCursor(bv_, par, pos);
370 bv_->text->selection.cursor = bv_->text->cursor;
371 bv_->text->selection.set(false);
373 // remake the inset locking
374 bv_->theLockingInset(the_locking_inset);
377 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
379 // this will scroll the screen such that the cursor becomes visible
384 owner_->allowInput();
386 /// clear the "Formatting Document" message
393 void BufferView::Pimpl::updateScreen()
395 // Regenerate the screen.
396 screen_.reset(new LyXScreen(workarea_));
400 void BufferView::Pimpl::updateScrollbar()
403 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
404 workarea_.setScrollbar(0, 1.0);
408 long const text_height = bv_->text->height;
409 long const work_height = workarea_.height();
411 double const lineh = bv_->text->defaultHeight();
412 double const slider_size =
413 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
415 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
416 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
418 /* If the text is smaller than the working area, the scrollbar
419 * maximum must be the working area height. No scrolling will
421 if (text_height <= work_height) {
422 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
423 workarea_.setScrollbarBounds(0.0, 0.0);
424 current_scrollbar_value = bv_->text->first_y;
425 workarea_.setScrollbar(current_scrollbar_value, 1.0);
429 workarea_.setScrollbarBounds(0.0, text_height - work_height);
430 workarea_.setScrollbarIncrements(lineh);
431 current_scrollbar_value = bv_->text->first_y;
432 workarea_.setScrollbar(current_scrollbar_value, slider_size);
436 // Callback for scrollbar slider
437 void BufferView::Pimpl::scrollCB(double value)
439 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
441 if (!buffer_) return;
443 current_scrollbar_value = long(value);
445 if (current_scrollbar_value < 0)
446 current_scrollbar_value = 0;
451 screen_->draw(bv_->text, bv_, current_scrollbar_value);
453 if (!lyxrc.cursor_follows_scrollbar) {
458 LyXText * vbt = bv_->text;
460 int const height = vbt->defaultHeight();
461 int const first = static_cast<int>((bv_->text->first_y + height));
462 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
464 if (vbt->cursor.y() < first)
465 vbt->setCursorFromCoordinates(bv_, 0, first);
466 else if (vbt->cursor.y() > last)
467 vbt->setCursorFromCoordinates(bv_, 0, last);
473 int BufferView::Pimpl::scrollUp(long time)
475 if (!buffer_) return 0;
476 if (!screen_.get()) return 0;
478 double value = workarea_.getScrollbarValue();
480 if (value == 0) return 0;
482 float add_value = (bv_->text->defaultHeight()
483 + float(time) * float(time) * 0.125);
485 if (add_value > workarea_.height())
486 add_value = float(workarea_.height() -
487 bv_->text->defaultHeight());
494 workarea_.setScrollbarValue(value);
501 int BufferView::Pimpl::scrollDown(long time)
503 if (!buffer_) return 0;
504 if (!screen_.get()) return 0;
506 double value = workarea_.getScrollbarValue();
507 pair<float, float> p = workarea_.getScrollbarBounds();
508 double const max = p.second;
510 if (value == max) return 0;
512 float add_value = (bv_->text->defaultHeight()
513 + float(time) * float(time) * 0.125);
515 if (add_value > workarea_.height())
516 add_value = float(workarea_.height() -
517 bv_->text->defaultHeight());
524 workarea_.setScrollbarValue(value);
531 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
533 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
537 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
539 // Only use motion with button 1
540 if (!(state & Button1MotionMask))
543 if (!buffer_ || !screen_.get()) return;
545 // Check for inset locking
546 if (bv_->theLockingInset()) {
547 LyXCursor cursor = bv_->text->cursor;
548 LyXFont font = bv_->text->getFont(buffer_,
549 cursor.par(), cursor.pos());
550 int width = bv_->theLockingInset()->width(bv_, font);
551 int inset_x = font.isVisibleRightToLeft()
552 ? cursor.ix() - width : cursor.ix();
553 int start_x = inset_x + bv_->theLockingInset()->scroll();
554 bv_->theLockingInset()->
555 insetMotionNotify(bv_,
557 y - cursor.iy() + bv_->text->first_y,
562 /* The test for not selection possible is needed, that only motion
563 events are used, where the bottom press event was on
564 the drawing area too */
565 if (!selection_possible)
568 screen_->hideCursor();
570 int y_before = bv_->text->cursor.y();
572 Row * cursorrow = bv_->text->cursor.row();
573 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
575 // sorry for this but I have a strange error that the y value jumps at
576 // a certain point. This seems like an error in my xforms library or
577 // in some other local environment, but I would like to leave this here
578 // for the moment until I can remove this (Jug 20020418)
579 if (y_before < bv_->text->cursor.y())
580 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
582 // This is to allow jumping over large insets
583 if (cursorrow == bv_->text->cursor.row()) {
584 if (y >= int(workarea_.height())) {
585 bv_->text->cursorDown(bv_, false);
587 bv_->text->cursorUp(bv_, false);
591 if (!bv_->text->selection.set())
592 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
594 bv_->text->setSelection(bv_);
595 screen_->toggleToggle(bv_->text, bv_);
601 // Single-click on work area
602 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
605 if (!buffer_ || !screen_.get())
608 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
610 // ok ok, this is a hack.
611 if (button == 4 || button == 5) {
614 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
617 scrollDown(lyxrc.wheel_jump);
622 // Middle button press pastes if we have a selection
623 // We do this here as if the selection was inside an inset
624 // it could get cleared on the unlocking of the inset so
625 // we have to check this first
626 bool paste_internally = false;
627 if (button == 2 && bv_->getLyXText()->selection.set()) {
628 owner_->getLyXFunc()->dispatch(LFUN_COPY);
629 paste_internally = true;
632 int const screen_first = bv_->text->first_y;
634 if (bv_->theLockingInset()) {
635 // We are in inset locking mode
637 /* Check whether the inset was hit. If not reset mode,
638 otherwise give the event to the inset */
639 if (inset_hit == bv_->theLockingInset()) {
640 bv_->theLockingInset()->
641 insetButtonPress(bv_,xpos, ypos,button);
644 bv_->unlockInset(bv_->theLockingInset());
649 selection_possible = true;
650 screen_->hideCursor();
652 // Clear the selection
653 screen_->toggleSelection(bv_->text, bv_);
654 bv_->text->clearSelection();
655 bv_->text->fullRebreak(bv_);
659 // Single left click in math inset?
660 if (isHighlyEditableInset(inset_hit)) {
661 // Highly editable inset, like math
662 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
663 selection_possible = false;
664 owner_->updateLayoutChoice();
665 owner_->message(inset->editMessage());
666 //inset->edit(bv_, xpos, ypos, button);
667 // We just have to lock the inset before calling a PressEvent on it!
668 // we don't need the edit() call here! (Jug20020329)
669 if (!bv_->lockInset(inset)) {
670 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
672 inset->insetButtonPress(bv_, xpos, ypos, button);
675 // I'm not sure we should continue here if we hit an inset (Jug20020403)
677 // Right click on a footnote flag opens float menu
679 selection_possible = false;
683 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
684 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
686 bv_->text->selection.cursor = bv_->text->cursor;
687 bv_->text->cursor.x_fix(bv_->text->cursor.x());
689 owner_->updateLayoutChoice();
691 selection_possible = false;
694 // Insert primary selection with middle mouse
695 // if there is a local selection in the current buffer,
698 if (paste_internally)
699 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
701 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
703 selection_possible = false;
709 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
715 LyXText * text = bv_->getLyXText();
717 if (text->bv_owner && bv_->theLockingInset())
720 if (screen_.get() && button == 1) {
721 if (text->bv_owner) {
722 screen_->hideCursor();
723 screen_->toggleSelection(text, bv_);
724 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
725 screen_->toggleSelection(text, bv_, false);
727 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
729 /* This will fit the cursor on the screen
731 update(text, BufferView::SELECT|BufferView::FITCUR);
736 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
742 LyXText * text = bv_->getLyXText();
744 if (text->bv_owner && bv_->theLockingInset())
747 if (screen_.get() && (button == 1)) {
748 if (text->bv_owner) {
749 screen_->hideCursor();
750 screen_->toggleSelection(text, bv_);
752 text->cursorHome(bv_);
753 text->selection.cursor = text->cursor;
754 text->cursorEnd(bv_);
755 text->setSelection(bv_);
756 if (text->bv_owner) {
757 screen_->toggleSelection(text, bv_, false);
759 /* This will fit the cursor on the screen
761 update(text, BufferView::SELECT|BufferView::FITCUR);
766 void BufferView::Pimpl::selectionRequested()
773 LyXText * text = bv_->getLyXText();
775 if (text->selection.set() &&
776 (!bv_->text->xsel_cache.set() ||
777 text->selection.start != bv_->text->xsel_cache.start ||
778 text->selection.end != bv_->text->xsel_cache.end))
780 bv_->text->xsel_cache = text->selection;
781 sel = text->selectionAsString(bv_->buffer(), false);
782 } else if (!text->selection.set()) {
784 bv_->text->xsel_cache.set(false);
787 workarea_.putClipboard(sel);
792 void BufferView::Pimpl::selectionLost()
794 if (active() && available()) {
797 bv_->getLyXText()->clearSelection();
799 bv_->text->xsel_cache.set(false);
804 void BufferView::Pimpl::enterView()
806 if (active() && available()) {
807 SetXtermCursor(workarea_.getWin());
808 using_xterm_cursor = true;
813 void BufferView::Pimpl::leaveView()
815 if (using_xterm_cursor) {
816 XUndefineCursor(fl_get_display(), workarea_.getWin());
817 using_xterm_cursor = false;
822 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
825 if (!buffer_ || !screen_.get()) return;
827 // If we hit an inset, we have the inset coordinates in these
828 // and inset_hit points to the inset. If we do not hit an
829 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
830 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
832 if (bv_->theLockingInset()) {
833 // We are in inset locking mode.
835 /* LyX does a kind of work-area grabbing for insets.
836 Only a ButtonPress Event outside the inset will
837 force a insetUnlock. */
838 bv_->theLockingInset()->
839 insetButtonRelease(bv_, x, y, button);
843 selection_possible = false;
850 workarea_.haveSelection(bv_->getLyXText()->selection.set());
855 owner_->updateMenubar();
856 owner_->updateToolbar();
858 // Did we hit an editable inset?
860 selection_possible = false;
862 // if we reach this point with a selection, it
863 // must mean we are currently selecting.
864 // But we don't want to open the inset
865 // because that is annoying for the user.
866 // So just pretend we didn't hit it.
867 // this is OK because a "kosher" ButtonRelease
868 // will follow a ButtonPress that clears
870 // Note this also fixes selection drawing
871 // problems if we end up opening an inset
872 if (bv_->getLyXText()->selection.set())
875 // CHECK fix this proper in 0.13
876 // well, maybe 13.0 !!!!!!!!!
878 // Following a ref shouldn't issue
879 // a push on the undo-stack
880 // anylonger, now that we have
881 // keybindings for following
882 // references and returning from
883 // references. IMHO though, it
884 // should be the inset's own business
885 // to push or not push on the undo
886 // stack. They don't *have* to
887 // alter the document...
889 // ...or maybe the SetCursorParUndo()
890 // below isn't necessary at all anylonger?
891 if (inset_hit->lyxCode() == Inset::REF_CODE) {
892 setCursorParUndo(bv_);
895 owner_->message(inset_hit->editMessage());
897 if (isHighlyEditableInset(inset_hit)) {
898 // Highly editable inset, like math
899 UpdatableInset *inset = (UpdatableInset *)inset_hit;
900 inset->insetButtonRelease(bv_, x, y, button);
902 inset_hit->insetButtonRelease(bv_, x, y, button);
903 // IMO this is a grosshack! Inset's should be changed so that
904 // they call the actions they have to do with the insetButtonRel.
905 // function and not in the edit(). This should be changed
907 inset_hit->edit(bv_, x, y, button);
912 // Maybe we want to edit a bibitem ale970302
913 if (bv_->text->cursor.par()->bibkey && x < 20 +
914 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
915 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
922 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
923 LyXCursor const & cursor) const
925 Paragraph /*const*/ & par = *cursor.par();
926 pos_type const pos = cursor.pos();
928 lyx::Assert(par.getInset(pos));
930 Inset const & inset(*par.getInset(pos));
932 LyXFont const & font = text.getFont(buffer_, &par, pos);
934 int const width = inset.width(bv_, font);
935 int const inset_x = font.isVisibleRightToLeft()
936 ? (cursor.ix() - width) : cursor.ix();
939 inset_x + inset.scroll(),
941 cursor.iy() - inset.ascent(bv_, font),
942 cursor.iy() + inset.descent(bv_, font));
946 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
947 LyXCursor const & cursor,
948 int & x, int & y) const
950 pos_type const pos(cursor.pos());
951 Paragraph /*const*/ & par(*cursor.par());
953 if (pos >= par.size() || !par.isInset(pos)) {
957 Inset /*const*/ * inset = par.getInset(pos);
959 if (!isEditableInset(inset)) {
963 Box b(insetDimensions(text, cursor));
965 if (!b.contained(x, y)) {
966 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
967 << " box " << b << endl;
971 text.setCursor(bv_, &par, pos, true);
974 // The origin of an inset is on the baseline
975 y -= text.cursor.iy();
981 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
986 int y_tmp = y + text->first_y;
989 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
991 Inset * inset(checkInset(*text, cursor, x, y_tmp));
998 // look at previous position
1000 if (cursor.pos() == 0) {
1005 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1007 inset = checkInset(*text, cursor, x, y_tmp);
1015 void BufferView::Pimpl::workAreaExpose()
1017 static int work_area_width;
1018 static unsigned int work_area_height;
1020 bool const widthChange = workarea_.workWidth() != work_area_width;
1021 bool const heightChange = workarea_.height() != work_area_height;
1023 // update from work area
1024 work_area_width = workarea_.workWidth();
1025 work_area_height = workarea_.height();
1028 // The visible LyXView need a resize
1031 // Remove all texts from the textcache
1032 // This is not _really_ what we want to do. What
1033 // we really want to do is to delete in textcache
1034 // that does not have a BufferView with matching
1035 // width, but as long as we have only one BufferView
1036 // deleting all gives the same result.
1037 if (lyxerr.debugging())
1038 textcache.show(lyxerr, "Expose delete all");
1040 buffer_->resizeInsets(bv_);
1041 } else if (heightChange) {
1042 // Rebuild image of current screen
1044 // fitCursor() ensures we don't jump back
1045 // to the start of the document on vertical
1049 // The main window size has changed, repaint most stuff
1051 } else if (screen_.get())
1052 screen_->redraw(bv_->text, bv_);
1054 // Grey box when we don't have a buffer
1055 workarea_.greyOut();
1058 // always make sure that the scrollbar is sane.
1060 owner_->updateLayoutChoice();
1065 void BufferView::Pimpl::update()
1067 if (screen_.get() &&
1068 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1070 LyXText::text_status st = bv_->text->status();
1071 screen_->update(bv_->text, bv_);
1073 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1074 if (bv_->text->fullRebreak(bv_)) {
1075 st = LyXText::NEED_MORE_REFRESH;
1076 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1077 bv_->text->cursor.pos());
1078 if (bv_->text->selection.set()) {
1079 bv_->text->setCursor(bv_, bv_->text->selection.start,
1080 bv_->text->selection.start.par(),
1081 bv_->text->selection.start.pos());
1082 bv_->text->setCursor(bv_, bv_->text->selection.end,
1083 bv_->text->selection.end.par(),
1084 bv_->text->selection.end.pos());
1088 bv_->text->status(bv_, st);
1089 screen_->update(bv_->text, bv_);
1091 // do this here instead of in the screen::update because of
1093 bv_->text->status(bv_, LyXText::UNCHANGED);
1099 // Values used when calling update:
1101 // -2 - update, move sel_cursor if selection, fitcursor
1102 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1103 // 0 - update, move sel_cursor if selection, fitcursor
1104 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1105 // 3 - update, move sel_cursor if selection
1108 // a simple redraw of the parts that need refresh
1110 // move sel_cursor if selection -
1111 // the text's sel_cursor is moved if there is selection is progress
1114 // fitCursor() is called and the scrollbar updated
1117 // the buffer is marked dirty.
1126 // UPDATE_ONLY = UPDATE;
1127 // UPDATE_SELECT = UPDATE | SELECT;
1128 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1129 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1131 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1132 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1133 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1134 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1135 // update(3) -> update(1) -> update(1) -> update(SELECT)
1137 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1139 owner_->updateLayoutChoice();
1141 if (!text->selection.set() && (f & SELECT)) {
1142 text->selection.cursor = text->cursor;
1145 text->fullRebreak(bv_);
1147 if (text->inset_owner) {
1148 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1149 updateInset(text->inset_owner, false);
1159 buffer_->markDirty();
1164 // Callback for cursor timer
1165 void BufferView::Pimpl::cursorToggle()
1168 cursor_timeout.restart();
1172 if (!screen_.get()) {
1173 cursor_timeout.restart();
1178 extern void reapSpellchecker(void);
1181 if (!bv_->theLockingInset()) {
1182 screen_->cursorToggle(bv_);
1184 bv_->theLockingInset()->toggleInsetCursor(bv_);
1187 cursor_timeout.restart();
1191 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1193 if (!text->cursor.row()->previous()) {
1194 if (text->first_y > 0) {
1195 int new_y = bv_->text->first_y - workarea_.height();
1196 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1202 int y = text->first_y;
1203 Row * cursorrow = text->cursor.row();
1205 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1209 if (cursorrow == bv_->text->cursor.row()) {
1210 // we have a row which is higher than the workarea so we leave the
1211 // cursor on the start of the row and move only the draw up as soon
1212 // as we move the cursor or do something while inside the row (it may
1213 // span several workarea-heights) we'll move to the top again, but this
1214 // is better than just jump down and only display part of the row.
1215 new_y = bv_->text->first_y - workarea_.height();
1217 if (text->inset_owner) {
1218 new_y = bv_->text->cursor.iy()
1219 + bv_->theLockingInset()->insetInInsetY() + y
1220 + text->cursor.row()->height()
1221 - workarea_.height() + 1;
1223 new_y = text->cursor.y()
1224 - text->cursor.row()->baseline()
1225 + text->cursor.row()->height()
1226 - workarea_.height() + 1;
1229 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1230 if (text->cursor.row()->previous()) {
1232 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1233 text->cursor.row()->previous()->pos(), false);
1234 if (cur.y() > text->first_y) {
1235 text->cursorUp(bv_, true);
1242 void BufferView::Pimpl::cursorNext(LyXText * text)
1244 if (!text->cursor.row()->next()) {
1245 int y = text->cursor.y() - text->cursor.row()->baseline() +
1246 text->cursor.row()->height();
1247 if (y > int(text->first_y + workarea_.height())) {
1248 screen_->draw(bv_->text, bv_,
1249 bv_->text->first_y + workarea_.height());
1255 int y = text->first_y + workarea_.height();
1256 if (text->inset_owner && !text->first_y) {
1257 y -= (bv_->text->cursor.iy()
1258 - bv_->text->first_y
1259 + bv_->theLockingInset()->insetInInsetY());
1261 text->getRowNearY(y);
1263 Row * cursorrow = text->cursor.row();
1264 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1267 if (cursorrow == bv_->text->cursor.row()) {
1268 // we have a row which is higher than the workarea so we leave the
1269 // cursor on the start of the row and move only the draw down as soon
1270 // as we move the cursor or do something while inside the row (it may
1271 // span several workarea-heights) we'll move to the top again, but this
1272 // is better than just jump down and only display part of the row.
1273 new_y = bv_->text->first_y + workarea_.height();
1275 if (text->inset_owner) {
1276 new_y = bv_->text->cursor.iy()
1277 + bv_->theLockingInset()->insetInInsetY()
1278 + y - text->cursor.row()->baseline();
1280 new_y = text->cursor.y() - text->cursor.row()->baseline();
1283 screen_->draw(bv_->text, bv_, new_y);
1284 if (text->cursor.row()->next()) {
1286 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1287 text->cursor.row()->next()->pos(), false);
1288 if (cur.y() < int(text->first_y + workarea_.height())) {
1289 text->cursorDown(bv_, true);
1296 bool BufferView::Pimpl::available() const
1298 if (buffer_ && bv_->text)
1304 void BufferView::Pimpl::beforeChange(LyXText * text)
1307 text->clearSelection();
1311 void BufferView::Pimpl::savePosition(unsigned int i)
1313 if (i >= saved_positions_num)
1315 saved_positions[i] = Position(buffer_->fileName(),
1316 bv_->text->cursor.par()->id(),
1317 bv_->text->cursor.pos());
1320 str << _("Saved bookmark") << ' ' << i;
1321 owner_->message(str.str().c_str());
1326 void BufferView::Pimpl::restorePosition(unsigned int i)
1328 if (i >= saved_positions_num)
1331 string const fname = saved_positions[i].filename;
1333 beforeChange(bv_->text);
1335 if (fname != buffer_->fileName()) {
1336 Buffer * b = bufferlist.exists(fname) ?
1337 bufferlist.getBuffer(fname) :
1338 bufferlist.loadLyXFile(fname); // don't ask, just load it
1339 if (b != 0) buffer(b);
1342 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1346 bv_->text->setCursor(bv_, par,
1347 min(par->size(), saved_positions[i].par_pos));
1349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1352 str << _("Moved to bookmark") << ' ' << i;
1353 owner_->message(str.str().c_str());
1358 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1360 if (i >= saved_positions_num)
1363 return !saved_positions[i].filename.empty();
1367 void BufferView::Pimpl::setState()
1369 if (!lyxrc.rtl_support)
1372 LyXText * text = bv_->getLyXText();
1373 if (text->real_current_font.isRightToLeft()) {
1374 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1375 owner_->getIntl()->KeyMapSec();
1377 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1378 owner_->getIntl()->KeyMapPrim();
1383 void BufferView::Pimpl::insetSleep()
1385 if (bv_->theLockingInset() && !inset_slept) {
1386 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1387 bv_->theLockingInset()->insetUnlock(bv_);
1393 void BufferView::Pimpl::insetWakeup()
1395 if (bv_->theLockingInset() && inset_slept) {
1396 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1397 inset_slept = false;
1402 void BufferView::Pimpl::insetUnlock()
1404 if (bv_->theLockingInset()) {
1406 bv_->theLockingInset()->insetUnlock(bv_);
1407 bv_->theLockingInset(0);
1409 inset_slept = false;
1414 bool BufferView::Pimpl::focus() const
1416 return workarea_.hasFocus();
1420 void BufferView::Pimpl::focus(bool f)
1422 if (f) workarea_.setFocus();
1426 bool BufferView::Pimpl::active() const
1428 return workarea_.active();
1432 bool BufferView::Pimpl::belowMouse() const
1434 return workarea_.belowMouse();
1438 void BufferView::Pimpl::showCursor()
1440 if (screen_.get()) {
1441 if (bv_->theLockingInset())
1442 bv_->theLockingInset()->showInsetCursor(bv_);
1444 screen_->showCursor(bv_->text, bv_);
1449 void BufferView::Pimpl::hideCursor()
1451 if (screen_.get()) {
1452 if (!bv_->theLockingInset())
1453 // bv_->theLockingInset()->hideInsetCursor(bv_);
1455 screen_->hideCursor();
1460 void BufferView::Pimpl::toggleSelection(bool b)
1462 if (screen_.get()) {
1463 if (bv_->theLockingInset())
1464 bv_->theLockingInset()->toggleSelection(bv_, b);
1465 screen_->toggleSelection(bv_->text, bv_, b);
1470 void BufferView::Pimpl::toggleToggle()
1473 screen_->toggleToggle(bv_->text, bv_);
1477 void BufferView::Pimpl::center()
1479 beforeChange(bv_->text);
1480 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1481 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1483 screen_->draw(bv_->text, bv_, 0);
1485 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1490 void BufferView::Pimpl::pasteClipboard(bool asPara)
1495 screen_->hideCursor();
1496 beforeChange(bv_->text);
1498 string const clip(workarea_.getClipboard());
1504 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1506 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1508 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1512 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1514 workarea_.putClipboard(stuff);
1519 * Dispatch functions for actions which can be valid for BufferView->text
1520 * and/or InsetText->text!!!
1525 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1527 LyXText * lt = bv_->getLyXText();
1529 if (selecting || lt->selection.mark()) {
1530 lt->setSelection(bv_);
1534 updateInset(lt->inset_owner, false);
1538 update(lt, BufferView::SELECT|BufferView::FITCUR);
1540 update(lt, BufferView::SELECT);
1544 if (!lt->selection.set())
1545 workarea_.haveSelection(false);
1547 /* ---> Everytime the cursor is moved, show the current font state. */
1548 // should this too me moved out of this func?
1549 //owner->showState();
1554 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1556 LyXCursor cursor = bv_->getLyXText()->cursor;
1557 Buffer::inset_iterator it =
1558 find_if(Buffer::inset_iterator(
1559 cursor.par(), cursor.pos()),
1560 buffer_->inset_iterator_end(),
1561 lyx::compare_memfun(&Inset::lyxCode, code));
1562 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1566 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1568 string filename = filen;
1570 if (filename.empty()) {
1571 // Launch a file browser
1572 string initpath = lyxrc.document_path;
1575 string const trypath = owner_->buffer()->filePath();
1576 // If directory is writeable, use this as default.
1577 if (IsDirWriteable(trypath))
1581 FileDialog fileDlg(bv_->owner(),
1582 _("Select LyX document to insert"),
1584 make_pair(string(_("Documents|#o#O")),
1585 string(lyxrc.document_path)),
1586 make_pair(string(_("Examples|#E#e")),
1587 string(AddPath(system_lyxdir, "examples"))));
1589 FileDialog::Result result =
1590 fileDlg.Select(initpath,
1591 _("*.lyx| LyX Documents (*.lyx)"));
1593 if (result.first == FileDialog::Later)
1596 filename = result.second;
1598 // check selected filename
1599 if (filename.empty()) {
1600 owner_->message(_("Canceled."));
1605 // get absolute path of file and add ".lyx" to the filename if
1607 filename = FileSearch(string(), filename, "lyx");
1609 string const disp_fn(MakeDisplayPath(filename));
1612 s1 << _("Inserting document") << ' '
1613 << disp_fn << " ...";
1614 owner_->message(s1.str().c_str());
1615 bool const res = bv_->insertLyXFile(filename);
1618 str << _("Document") << ' ' << disp_fn
1619 << ' ' << _("inserted.");
1620 owner_->message(str.str().c_str());
1623 str << _("Could not insert document") << ' '
1625 owner_->message(str.str().c_str());
1630 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1632 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1633 << action <<"] arg[" << argument << "]" << endl;
1636 // --- Misc -------------------------------------------
1640 LyXText * lt = bv_->getLyXText();
1641 lt->toggleAppendix(bv_);
1644 | BufferView::FITCUR
1645 | BufferView::CHANGE);
1650 case LFUN_TOC_INSERT:
1652 InsetCommandParams p;
1653 p.setCmdName("tableofcontents");
1654 Inset * inset = new InsetTOC(p);
1655 if (!insertInset(inset, "Standard"))
1660 case LFUN_SCROLL_INSET:
1661 // this is not handled here as this funktion is only aktive
1662 // if we have a locking_inset and that one is (or contains)
1666 case LFUN_INSET_GRAPHICS:
1668 Inset * new_inset = new InsetGraphics;
1669 if (!insertInset(new_inset)) {
1672 // this is need because you don't use a inset->Edit()
1673 updateInset(new_inset, true);
1674 new_inset->edit(bv_);
1684 case LFUN_PASTESELECTION:
1686 bool asPara = false;
1687 if (argument == "paragraph")
1689 pasteClipboard(asPara);
1701 case LFUN_LAYOUT_COPY:
1702 bv_->copyEnvironment();
1705 case LFUN_LAYOUT_PASTE:
1706 bv_->pasteEnvironment();
1710 case LFUN_GOTOERROR:
1711 gotoInset(Inset::ERROR_CODE, false);
1715 gotoInset(Inset::IGNORE_CODE, false);
1718 case LFUN_REFERENCE_GOTO:
1720 vector<Inset::Code> tmp;
1721 tmp.push_back(Inset::LABEL_CODE);
1722 tmp.push_back(Inset::REF_CODE);
1723 gotoInset(tmp, true);
1727 case LFUN_HYPHENATION:
1728 specialChar(InsetSpecialChar::HYPHENATION);
1731 case LFUN_LIGATURE_BREAK:
1732 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1736 specialChar(InsetSpecialChar::LDOTS);
1739 case LFUN_END_OF_SENTENCE:
1740 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1743 case LFUN_MENU_SEPARATOR:
1744 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1751 case LFUN_DEPTH_MIN:
1752 changeDepth(bv_, bv_->getLyXText(), -1);
1755 case LFUN_DEPTH_PLUS:
1756 changeDepth(bv_, bv_->getLyXText(), 1);
1760 owner_->getDialogs()->setUserFreeFont();
1763 case LFUN_FILE_INSERT:
1764 MenuInsertLyXFile(argument);
1767 case LFUN_FILE_INSERT_ASCII_PARA:
1768 InsertAsciiFile(bv_, argument, true);
1771 case LFUN_FILE_INSERT_ASCII:
1772 InsertAsciiFile(bv_, argument, false);
1777 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1778 << argument << endl;
1780 // Derive layout number from given argument (string)
1781 // and current buffer's textclass (number). */
1782 textclass_type tclass = buffer_->params.textclass;
1784 textclasslist[tclass].hasLayout(argument);
1785 string layout = argument;
1787 // If the entry is obsolete, use the new one instead.
1789 string const & obs = textclasslist[tclass][layout]
1796 owner_->getLyXFunc()->setErrorMessage(
1797 string(N_("Layout ")) + argument +
1802 bool change_layout = (current_layout != layout);
1803 LyXText * lt = bv_->getLyXText();
1804 if (!change_layout && lt->selection.set() &&
1805 lt->selection.start.par() != lt->selection.end.par())
1807 Paragraph * spar = lt->selection.start.par();
1808 Paragraph * epar = lt->selection.end.par()->next();
1809 while(spar != epar) {
1810 if (spar->layout() != current_layout) {
1811 change_layout = true;
1816 if (change_layout) {
1818 current_layout = layout;
1821 | BufferView::FITCUR);
1822 lt->setLayout(bv_, layout);
1823 owner_->setLayout(layout);
1826 | BufferView::FITCUR
1827 | BufferView::CHANGE);
1834 lang(bv_, argument);
1836 owner_->showState();
1841 owner_->showState();
1846 owner_->showState();
1851 owner_->showState();
1856 owner_->showState();
1861 owner_->showState();
1866 owner_->showState();
1871 owner_->showState();
1874 case LFUN_UNDERLINE:
1876 owner_->showState();
1879 case LFUN_FONT_SIZE:
1880 fontSize(bv_, argument);
1881 owner_->showState();
1884 case LFUN_FONT_STATE:
1885 owner_->getLyXFunc()->setMessage(currentState(bv_));
1888 case LFUN_UPCASE_WORD:
1890 LyXText * lt = bv_->getLyXText();
1894 | BufferView::FITCUR);
1895 lt->changeCase(bv_, LyXText::text_uppercase);
1896 if (lt->inset_owner)
1897 updateInset(lt->inset_owner, true);
1900 | BufferView::FITCUR
1901 | BufferView::CHANGE);
1905 case LFUN_LOWCASE_WORD:
1907 LyXText * lt = bv_->getLyXText();
1909 update(lt, BufferView::SELECT|BufferView::FITCUR);
1910 lt->changeCase(bv_, LyXText::text_lowercase);
1911 if (lt->inset_owner)
1912 updateInset(lt->inset_owner, true);
1915 | BufferView::FITCUR
1916 | BufferView::CHANGE);
1920 case LFUN_CAPITALIZE_WORD:
1922 LyXText * lt = bv_->getLyXText();
1924 update(lt, BufferView::SELECT|BufferView::FITCUR);
1925 lt->changeCase(bv_, LyXText::text_capitalization);
1926 if (lt->inset_owner)
1927 updateInset(lt->inset_owner, true);
1930 | BufferView::FITCUR
1931 | BufferView::CHANGE);
1935 case LFUN_TRANSPOSE_CHARS:
1937 LyXText * lt = bv_->getLyXText();
1939 update(lt, BufferView::SELECT|BufferView::FITCUR);
1940 lt->transposeChars(*bv_);
1941 if (lt->inset_owner)
1942 updateInset(lt->inset_owner, true);
1945 | BufferView::FITCUR
1946 | BufferView::CHANGE);
1951 case LFUN_INSERT_LABEL:
1952 MenuInsertLabel(bv_, argument);
1955 case LFUN_REF_INSERT:
1956 if (argument.empty()) {
1957 InsetCommandParams p("ref");
1958 owner_->getDialogs()->createRef(p.getAsString());
1960 InsetCommandParams p;
1961 p.setFromString(argument);
1963 InsetRef * inset = new InsetRef(p, *buffer_);
1964 if (!insertInset(inset))
1967 updateInset(inset, true);
1971 case LFUN_BOOKMARK_SAVE:
1972 savePosition(strToUnsignedInt(argument));
1975 case LFUN_BOOKMARK_GOTO:
1976 restorePosition(strToUnsignedInt(argument));
1981 string label(argument);
1982 if (label.empty()) {
1984 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1986 label = inset->getContents();
1991 if (!label.empty()) {
1992 //bv_->savePosition(0);
1993 if (!bv_->gotoLabel(label))
1994 Alert::alert(_("Error"),
1995 _("Couldn't find this label"),
1996 _("in current document."));
2001 // --- Cursor Movements -----------------------------
2004 LyXText * lt = bv_->getLyXText();
2006 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2007 if (!lt->selection.mark())
2009 update(lt, BufferView::SELECT|BufferView::FITCUR);
2011 lt->cursorLeft(bv_, false);
2012 if (lt->cursor.pos() < lt->cursor.par()->size()
2013 && lt->cursor.par()->isInset(lt->cursor.pos())
2014 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2015 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2016 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2018 tmpinset->edit(bv_, false);
2020 tmpinset->edit(bv_);
2024 lt->cursorRight(bv_, false);
2026 moveCursorUpdate(false);
2027 owner_->showState();
2033 // This is soooo ugly. Isn`t it possible to make
2034 // it simpler? (Lgb)
2035 LyXText * lt = bv_->getLyXText();
2036 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2037 if (!lt->selection.mark())
2039 update(lt, BufferView::SELECT|BufferView::FITCUR);
2040 LyXCursor const cur = lt->cursor;
2042 lt->cursorLeft(bv_, false);
2043 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2044 lt->cursor.pos() < lt->cursor.par()->size() &&
2045 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2046 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2047 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2048 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2050 tmpinset->edit(bv_);
2052 tmpinset->edit(bv_, false);
2056 lt->cursorRight(bv_, false);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2066 LyXText * lt = bv_->getLyXText();
2068 if (!lt->selection.mark())
2070 update(lt, BufferView::UPDATE);
2073 moveCursorUpdate(false);
2074 owner_->showState();
2080 LyXText * lt = bv_->getLyXText();
2082 if (!lt->selection.mark())
2084 update(lt, BufferView::UPDATE);
2085 lt->cursorDown(bv_);
2087 moveCursorUpdate(false);
2088 owner_->showState();
2092 case LFUN_UP_PARAGRAPH:
2094 LyXText * lt = bv_->getLyXText();
2096 if (!lt->selection.mark())
2098 update(lt, BufferView::UPDATE);
2099 lt->cursorUpParagraph(bv_);
2101 moveCursorUpdate(false);
2102 owner_->showState();
2106 case LFUN_DOWN_PARAGRAPH:
2108 LyXText * lt = bv_->getLyXText();
2110 if (!lt->selection.mark())
2112 update(lt, BufferView::UPDATE);
2113 lt->cursorDownParagraph(bv_);
2115 moveCursorUpdate(false);
2116 owner_->showState();
2122 LyXText * lt = bv_->getLyXText();
2124 if (!lt->selection.mark())
2126 update(lt, BufferView::UPDATE);
2129 moveCursorUpdate(false, false);
2130 owner_->showState();
2136 LyXText * lt = bv_->getLyXText();
2138 if (!lt->selection.mark())
2140 update(lt, BufferView::UPDATE);
2143 moveCursorUpdate(false, false);
2144 owner_->showState();
2150 LyXText * lt = bv_->getLyXText();
2152 if (!lt->selection.mark())
2154 update(lt, BufferView::SELECT|BufferView::FITCUR);
2155 lt->cursorHome(bv_);
2157 moveCursorUpdate(false);
2158 owner_->showState();
2164 LyXText * lt = bv_->getLyXText();
2166 if (!lt->selection.mark())
2169 BufferView::SELECT|BufferView::FITCUR);
2172 moveCursorUpdate(false);
2173 owner_->showState();
2177 case LFUN_SHIFT_TAB:
2180 LyXText * lt = bv_->getLyXText();
2182 if (!lt->selection.mark())
2185 BufferView::SELECT|BufferView::FITCUR);
2188 moveCursorUpdate(false);
2189 owner_->showState();
2193 case LFUN_WORDRIGHT:
2195 LyXText * lt = bv_->getLyXText();
2197 if (!lt->selection.mark())
2199 update(lt, BufferView::SELECT|BufferView::FITCUR);
2200 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2201 lt->cursorLeftOneWord(bv_);
2203 lt->cursorRightOneWord(bv_);
2205 moveCursorUpdate(false);
2206 owner_->showState();
2212 LyXText * lt = bv_->getLyXText();
2214 if (!lt->selection.mark())
2216 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2218 lt->cursorRightOneWord(bv_);
2220 lt->cursorLeftOneWord(bv_);
2222 moveCursorUpdate(false);
2223 owner_->showState();
2227 case LFUN_BEGINNINGBUF:
2229 LyXText * lt = bv_->getLyXText();
2231 if (!lt->selection.mark())
2234 BufferView::SELECT|BufferView::FITCUR);
2237 moveCursorUpdate(false);
2238 owner_->showState();
2244 LyXText * lt = bv_->getLyXText();
2246 if (!lt->selection.mark())
2249 BufferView::SELECT|BufferView::FITCUR);
2250 lt->cursorBottom(bv_);
2252 moveCursorUpdate(false);
2253 owner_->showState();
2257 /* cursor selection ---------------------------- */
2260 LyXText * lt = bv_->getLyXText();
2263 BufferView::SELECT|BufferView::FITCUR);
2264 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2265 lt->cursorLeft(bv_);
2267 lt->cursorRight(bv_);
2269 moveCursorUpdate(true);
2270 owner_->showState();
2276 LyXText * lt = bv_->getLyXText();
2279 BufferView::SELECT|BufferView::FITCUR);
2280 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2281 lt->cursorRight(bv_);
2283 lt->cursorLeft(bv_);
2285 moveCursorUpdate(true);
2286 owner_->showState();
2292 LyXText * lt = bv_->getLyXText();
2295 BufferView::SELECT|BufferView::FITCUR);
2296 lt->cursorUp(bv_, true);
2298 moveCursorUpdate(true);
2299 owner_->showState();
2305 LyXText * lt = bv_->getLyXText();
2308 BufferView::SELECT|BufferView::FITCUR);
2309 lt->cursorDown(bv_, true);
2311 moveCursorUpdate(true);
2312 owner_->showState();
2316 case LFUN_UP_PARAGRAPHSEL:
2318 LyXText * lt = bv_->getLyXText();
2321 BufferView::SELECT|BufferView::FITCUR);
2322 lt->cursorUpParagraph(bv_);
2324 moveCursorUpdate(true);
2325 owner_->showState();
2329 case LFUN_DOWN_PARAGRAPHSEL:
2331 LyXText * lt = bv_->getLyXText();
2334 BufferView::SELECT|BufferView::FITCUR);
2335 lt->cursorDownParagraph(bv_);
2337 moveCursorUpdate(true);
2338 owner_->showState();
2344 LyXText * lt = bv_->getLyXText();
2346 update(lt, BufferView::SELECT|BufferView::FITCUR);
2349 moveCursorUpdate(true);
2350 owner_->showState();
2356 LyXText * lt = bv_->getLyXText();
2358 update(lt, BufferView::SELECT|BufferView::FITCUR);
2361 moveCursorUpdate(true);
2362 owner_->showState();
2368 LyXText * lt = bv_->getLyXText();
2370 update(lt, BufferView::SELECT|BufferView::FITCUR);
2371 lt->cursorHome(bv_);
2373 moveCursorUpdate(true);
2374 owner_->showState();
2380 LyXText * lt = bv_->getLyXText();
2382 update(lt, BufferView::SELECT|BufferView::FITCUR);
2385 moveCursorUpdate(true);
2386 owner_->showState();
2390 case LFUN_WORDRIGHTSEL:
2392 LyXText * lt = bv_->getLyXText();
2394 update(lt, BufferView::SELECT|BufferView::FITCUR);
2395 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2396 lt->cursorLeftOneWord(bv_);
2398 lt->cursorRightOneWord(bv_);
2400 moveCursorUpdate(true);
2401 owner_->showState();
2405 case LFUN_WORDLEFTSEL:
2407 LyXText * lt = bv_->getLyXText();
2409 update(lt, BufferView::SELECT|BufferView::FITCUR);
2410 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2411 lt->cursorRightOneWord(bv_);
2413 lt->cursorLeftOneWord(bv_);
2415 moveCursorUpdate(true);
2416 owner_->showState();
2420 case LFUN_BEGINNINGBUFSEL:
2422 LyXText * lt = bv_->getLyXText();
2424 if (lt->inset_owner)
2426 update(lt, BufferView::SELECT|BufferView::FITCUR);
2429 moveCursorUpdate(true);
2430 owner_->showState();
2434 case LFUN_ENDBUFSEL:
2436 LyXText * lt = bv_->getLyXText();
2438 if (lt->inset_owner)
2441 BufferView::SELECT|BufferView::FITCUR);
2442 lt->cursorBottom(bv_);
2444 moveCursorUpdate(true);
2445 owner_->showState();
2449 // --- text changing commands ------------------------
2450 case LFUN_BREAKLINE:
2452 LyXText * lt = bv_->getLyXText();
2455 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2458 | BufferView::FITCUR
2459 | BufferView::CHANGE);
2460 moveCursorUpdate(false);
2464 case LFUN_PROTECTEDSPACE:
2466 LyXText * lt = bv_->getLyXText();
2468 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2470 if (style.free_spacing) {
2471 lt->insertChar(bv_, ' ');
2474 | BufferView::FITCUR
2475 | BufferView::CHANGE);
2477 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2479 moveCursorUpdate(false);
2485 LyXText * lt = bv_->getLyXText();
2487 if (lt->selection.mark()) {
2491 | BufferView::FITCUR);
2492 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2495 lt->selection.mark(true);
2498 | BufferView::FITCUR);
2499 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2501 lt->selection.cursor = lt->cursor;
2507 LyXText * lt = bv_->getLyXText();
2509 if (!lt->selection.set()) {
2511 lt->selection.cursor = lt->cursor;
2514 | BufferView::FITCUR
2515 | BufferView::CHANGE);
2516 // It is possible to make it a lot faster still
2517 // just comment out the line below...
2522 moveCursorUpdate(false);
2523 owner_->showState();
2528 case LFUN_DELETE_SKIP:
2530 LyXText * lt = bv_->getLyXText();
2532 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2534 LyXCursor cursor = lt->cursor;
2536 if (!lt->selection.set()) {
2537 if (cursor.pos() == cursor.par()->size()) {
2538 lt->cursorRight(bv_);
2539 cursor = lt->cursor;
2540 if (cursor.pos() == 0
2541 && !(cursor.par()->params().spaceTop()
2542 == VSpace (VSpace::NONE))) {
2545 cursor.par()->params().lineTop(),
2546 cursor.par()->params().lineBottom(),
2547 cursor.par()->params().pagebreakTop(),
2548 cursor.par()->params().pagebreakBottom(),
2549 VSpace(VSpace::NONE),
2550 cursor.par()->params().spaceBottom(),
2551 cursor.par()->params().spacing(),
2552 cursor.par()->params().align(),
2553 cursor.par()->params().labelWidthString(), 0);
2554 lt->cursorLeft(bv_);
2557 | BufferView::FITCUR
2558 | BufferView::CHANGE);
2560 lt->cursorLeft(bv_);
2562 lt->selection.cursor = lt->cursor;
2565 | BufferView::FITCUR
2566 | BufferView::CHANGE);
2570 lt->selection.cursor = lt->cursor;
2573 | BufferView::FITCUR
2574 | BufferView::CHANGE);
2582 /* -------> Delete word forward. */
2583 case LFUN_DELETE_WORD_FORWARD:
2584 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2585 bv_->getLyXText()->deleteWordForward(bv_);
2586 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2587 moveCursorUpdate(false);
2588 owner_->showState();
2591 /* -------> Delete word backward. */
2592 case LFUN_DELETE_WORD_BACKWARD:
2594 LyXText * lt = bv_->getLyXText();
2596 update(lt, BufferView::SELECT|BufferView::FITCUR);
2597 lt->deleteWordBackward(bv_);
2600 | BufferView::FITCUR
2601 | BufferView::CHANGE);
2602 moveCursorUpdate(false);
2603 owner_->showState();
2607 /* -------> Kill to end of line. */
2608 case LFUN_DELETE_LINE_FORWARD:
2610 LyXText * lt = bv_->getLyXText();
2612 update(lt, BufferView::SELECT|BufferView::FITCUR);
2613 lt->deleteLineForward(bv_);
2616 | BufferView::FITCUR
2617 | BufferView::CHANGE);
2618 moveCursorUpdate(false);
2622 /* -------> Set mark off. */
2625 LyXText * lt = bv_->getLyXText();
2628 update(lt, BufferView::SELECT|BufferView::FITCUR);
2629 lt->selection.cursor = lt->cursor;
2630 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2634 /* -------> Set mark on. */
2637 LyXText * lt = bv_->getLyXText();
2640 lt->selection.mark(true);
2641 update(lt, BufferView::SELECT|BufferView::FITCUR);
2642 lt->selection.cursor = lt->cursor;
2643 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2647 case LFUN_BACKSPACE:
2649 LyXText * lt = bv_->getLyXText();
2651 if (!lt->selection.set()) {
2652 if (owner_->getIntl()->getTrans().backspace()) {
2654 lt->selection.cursor = lt->cursor;
2657 | BufferView::FITCUR
2658 | BufferView::CHANGE);
2659 // It is possible to make it a lot faster still
2660 // just comment out the line below...
2666 owner_->showState();
2671 case LFUN_BACKSPACE_SKIP:
2673 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2674 LyXText * lt = bv_->getLyXText();
2676 LyXCursor cursor = lt->cursor;
2678 if (!lt->selection.set()) {
2679 if (cursor.pos() == 0
2680 && !(cursor.par()->params().spaceTop()
2681 == VSpace (VSpace::NONE))) {
2684 cursor.par()->params().lineTop(),
2685 cursor.par()->params().lineBottom(),
2686 cursor.par()->params().pagebreakTop(),
2687 cursor.par()->params().pagebreakBottom(),
2688 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2689 cursor.par()->params().spacing(),
2690 cursor.par()->params().align(),
2691 cursor.par()->params().labelWidthString(), 0);
2694 | BufferView::FITCUR
2695 | BufferView::CHANGE);
2698 lt->selection.cursor = cursor;
2701 | BufferView::FITCUR
2702 | BufferView::CHANGE);
2709 case LFUN_BREAKPARAGRAPH:
2711 LyXText * lt = bv_->getLyXText();
2714 lt->breakParagraph(bv_, 0);
2717 | BufferView::FITCUR
2718 | BufferView::CHANGE);
2719 lt->selection.cursor = lt->cursor;
2721 owner_->showState();
2725 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2727 LyXText * lt = bv_->getLyXText();
2730 lt->breakParagraph(bv_, 1);
2733 | BufferView::FITCUR
2734 | BufferView::CHANGE);
2735 lt->selection.cursor = lt->cursor;
2737 owner_->showState();
2741 case LFUN_BREAKPARAGRAPH_SKIP:
2743 // When at the beginning of a paragraph, remove
2744 // indentation and add a "defskip" at the top.
2745 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2746 LyXText * lt = bv_->getLyXText();
2748 LyXCursor cursor = lt->cursor;
2751 if (cursor.pos() == 0) {
2752 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2755 cursor.par()->params().lineTop(),
2756 cursor.par()->params().lineBottom(),
2757 cursor.par()->params().pagebreakTop(),
2758 cursor.par()->params().pagebreakBottom(),
2759 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2760 cursor.par()->params().spacing(),
2761 cursor.par()->params().align(),
2762 cursor.par()->params().labelWidthString(), 1);
2763 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2767 lt->breakParagraph(bv_, 0);
2768 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2773 | BufferView::FITCUR
2774 | BufferView::CHANGE);
2775 lt->selection.cursor = cursor;
2777 owner_->showState();
2781 case LFUN_PARAGRAPH_SPACING:
2783 LyXText * lt = bv_->getLyXText();
2785 Paragraph * par = lt->cursor.par();
2786 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2787 float cur_value = 1.0;
2788 if (cur_spacing == Spacing::Other) {
2789 cur_value = par->params().spacing().getValue();
2792 istringstream istr(argument.c_str());
2796 Spacing::Space new_spacing = cur_spacing;
2797 float new_value = cur_value;
2799 lyxerr << "Missing argument to `paragraph-spacing'"
2801 } else if (tmp == "single") {
2802 new_spacing = Spacing::Single;
2803 } else if (tmp == "onehalf") {
2804 new_spacing = Spacing::Onehalf;
2805 } else if (tmp == "double") {
2806 new_spacing = Spacing::Double;
2807 } else if (tmp == "other") {
2808 new_spacing = Spacing::Other;
2811 lyxerr << "new_value = " << tmpval << endl;
2814 } else if (tmp == "default") {
2815 new_spacing = Spacing::Default;
2817 lyxerr << _("Unknown spacing argument: ")
2818 << argument << endl;
2820 if (cur_spacing != new_spacing || cur_value != new_value) {
2821 par->params().spacing(Spacing(new_spacing, new_value));
2822 lt->redoParagraph(bv_);
2825 | BufferView::FITCUR
2826 | BufferView::CHANGE);
2831 case LFUN_INSET_TOGGLE:
2833 LyXText * lt = bv_->getLyXText();
2836 update(lt, BufferView::SELECT|BufferView::FITCUR);
2837 lt->toggleInset(bv_);
2838 update(lt, BufferView::SELECT|BufferView::FITCUR);
2850 InsetCommandParams p;
2851 if (action == LFUN_HTMLURL)
2852 p.setCmdName("htmlurl");
2854 p.setCmdName("url");
2855 owner_->getDialogs()->createUrl(p.getAsString());
2859 case LFUN_INSERT_URL:
2861 InsetCommandParams p;
2862 p.setFromString(argument);
2864 InsetUrl * inset = new InsetUrl(p);
2865 if (!insertInset(inset))
2868 updateInset(inset, true);
2872 case LFUN_INSET_ERT:
2873 insertAndEditInset(new InsetERT(buffer_->params));
2876 case LFUN_INSET_EXTERNAL:
2877 insertAndEditInset(new InsetExternal);
2880 case LFUN_INSET_FOOTNOTE:
2881 insertAndEditInset(new InsetFoot(buffer_->params));
2884 case LFUN_INSET_MARGINAL:
2885 insertAndEditInset(new InsetMarginal(buffer_->params));
2888 case LFUN_INSET_MINIPAGE:
2889 insertAndEditInset(new InsetMinipage(buffer_->params));
2892 case LFUN_INSERT_NOTE:
2893 insertAndEditInset(new InsetNote(buffer_->params));
2896 case LFUN_INSET_FLOAT:
2897 // check if the float type exist
2898 if (floatList.typeExist(argument)) {
2899 insertAndEditInset(new InsetFloat(buffer_->params,
2902 lyxerr << "Non-existent float type: "
2903 << argument << endl;
2907 case LFUN_INSET_WIDE_FLOAT:
2909 // check if the float type exist
2910 if (floatList.typeExist(argument)) {
2911 InsetFloat * new_inset =
2912 new InsetFloat(buffer_->params, argument);
2913 new_inset->wide(true);
2914 if (insertInset(new_inset))
2915 new_inset->edit(bv_);
2919 lyxerr << "Non-existent float type: "
2920 << argument << endl;
2927 case LFUN_INSET_LIST:
2928 insertAndEditInset(new InsetList);
2931 case LFUN_INSET_THEOREM:
2932 insertAndEditInset(new InsetTheorem);
2936 case LFUN_INSET_CAPTION:
2938 // Do we have a locking inset...
2939 if (bv_->theLockingInset()) {
2940 lyxerr << "Locking inset code: "
2941 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2942 InsetCaption * new_inset =
2943 new InsetCaption(buffer_->params);
2944 new_inset->setOwner(bv_->theLockingInset());
2945 new_inset->setAutoBreakRows(true);
2946 new_inset->setDrawFrame(0, InsetText::LOCKED);
2947 new_inset->setFrameColor(0, LColor::captionframe);
2948 if (insertInset(new_inset))
2949 new_inset->edit(bv_);
2956 case LFUN_INSET_TABULAR:
2960 if (!argument.empty())
2961 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2962 InsetTabular * new_inset =
2963 new InsetTabular(*buffer_, r, c);
2965 bv_->getLyXText()->real_current_font.isRightToLeft();
2966 if (!open_new_inset(new_inset, rtl))
2971 // --- lyxserver commands ----------------------------
2973 case LFUN_CHARATCURSOR:
2975 pos_type pos = bv_->getLyXText()->cursor.pos();
2976 if (pos < bv_->getLyXText()->cursor.par()->size())
2977 owner_->getLyXFunc()->setMessage(
2978 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2980 owner_->getLyXFunc()->setMessage("EOF");
2985 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2987 + tostr(bv_->getLyXText()->cursor.y()));
2994 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2995 lyxerr << "SETXY: Could not parse coordinates in '"
2996 << argument << std::endl;
2998 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
3002 case LFUN_GETLAYOUT:
3003 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3008 LyXFont & font = bv_->getLyXText()->current_font;
3009 if (font.shape() == LyXFont::ITALIC_SHAPE)
3010 owner_->getLyXFunc()->setMessage("E");
3011 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3012 owner_->getLyXFunc()->setMessage("N");
3014 owner_->getLyXFunc()->setMessage("0");
3019 // --- accented characters ---------------------------
3022 case LFUN_CIRCUMFLEX:
3032 case LFUN_SPECIAL_CARON:
3035 case LFUN_HUNG_UMLAUT:
3038 if (argument.empty()) {
3040 owner_->getLyXFunc()->handleKeyFunc(action);
3042 owner_->getLyXFunc()->handleKeyFunc(action);
3043 owner_->getIntl()->getTrans()
3044 .TranslateAndInsert(argument[0], bv_->getLyXText());
3045 update(bv_->getLyXText(),
3047 | BufferView::FITCUR
3048 | BufferView::CHANGE);
3052 case LFUN_MATH_MACRO:
3053 mathDispatchMathMacro(bv_, argument);
3056 case LFUN_MATH_DELIM:
3057 mathDispatchMathDelim(bv_, argument);
3060 case LFUN_INSERT_MATRIX:
3061 mathDispatchInsertMatrix(bv_, argument);
3064 case LFUN_INSERT_MATH:
3065 mathDispatchInsertMath(bv_, argument);
3068 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3069 mathDispatchMathImportSelection(bv_, argument);
3072 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3073 mathDispatchMathDisplay(bv_, argument);
3076 case LFUN_MATH_MODE: // Open or create an inlined math inset
3077 mathDispatchMathMode(bv_, argument);
3080 case LFUN_GREEK: // Insert a single greek letter
3081 mathDispatchGreek(bv_, argument);
3084 case LFUN_CITATION_INSERT:
3086 InsetCommandParams p;
3087 p.setFromString(argument);
3089 InsetCitation * inset = new InsetCitation(p);
3090 if (!insertInset(inset))
3093 updateInset(inset, true);
3097 case LFUN_INSERT_BIBTEX:
3099 // ale970405+lasgoutt970425
3100 // The argument can be up to two tokens separated
3101 // by a space. The first one is the bibstyle.
3102 string const db = token(argument, ' ', 0);
3103 string const bibstyle = token(argument, ' ', 1);
3105 InsetCommandParams p("BibTeX", db, bibstyle);
3106 InsetBibtex * inset = new InsetBibtex(p);
3108 if (insertInset(inset)) {
3109 if (argument.empty())
3116 // BibTeX data bases
3117 case LFUN_BIBDB_ADD:
3119 InsetBibtex * inset =
3120 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3122 inset->addDatabase(argument);
3127 case LFUN_BIBDB_DEL:
3129 InsetBibtex * inset =
3130 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3132 inset->delDatabase(argument);
3137 case LFUN_BIBTEX_STYLE:
3139 InsetBibtex * inset =
3140 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3142 inset->setOptions(argument);
3147 case LFUN_INDEX_CREATE:
3149 InsetCommandParams p("index");
3150 if (argument.empty()) {
3151 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3152 p.setContents(idxstring);
3154 p.setContents(argument);
3157 owner_->getDialogs()->createIndex(p.getAsString());
3161 case LFUN_INDEX_INSERT:
3163 InsetCommandParams p;
3164 p.setFromString(argument);
3165 InsetIndex * inset = new InsetIndex(p);
3167 if (!insertInset(inset))
3170 updateInset(inset, true);
3174 case LFUN_INDEX_INSERT_LAST:
3176 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3177 if (!idxstring.empty()) {
3178 owner_->message(_("Word `")
3179 + idxstring + _(("' indexed.")));
3180 InsetCommandParams p("index", idxstring);
3181 InsetIndex * inset = new InsetIndex(p);
3183 if (!insertInset(inset))
3186 updateInset(inset, true);
3191 case LFUN_INDEX_PRINT:
3193 InsetCommandParams p("printindex");
3194 Inset * inset = new InsetPrintIndex(p);
3195 if (!insertInset(inset, "Standard"))
3200 case LFUN_PARENTINSERT:
3202 InsetCommandParams p("lyxparent", argument);
3203 Inset * inset = new InsetParent(p, *buffer_);
3204 if (!insertInset(inset, "Standard"))
3210 case LFUN_CHILD_INSERT:
3212 InsetInclude::Params p;
3213 p.cparams.setFromString(argument);
3214 p.masterFilename_ = buffer_->fileName();
3216 InsetInclude * inset = new InsetInclude(p);
3217 if (!insertInset(inset))
3220 updateInset(inset, true);
3221 bv_->owner()->getDialogs()->showInclude(inset);
3226 case LFUN_FLOAT_LIST:
3228 // We should check the argument for validity. (Lgb)
3229 Inset * inset = new InsetFloatList(argument);
3230 if (!insertInset(inset, "Standard"))
3235 case LFUN_THESAURUS_ENTRY:
3237 string arg = argument;
3240 arg = bv_->getLyXText()->selectionAsString(buffer_,
3244 if (arg.size() > 100 || arg.empty()) {
3245 // Get word or selection
3246 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3247 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3248 // FIXME: where is getLyXText()->unselect(bv_) ?
3252 bv_->owner()->getDialogs()->showThesaurus(arg);
3256 case LFUN_SELFINSERT:
3258 if (argument.empty()) break;
3260 /* Automatically delete the currently selected
3261 * text and replace it with what is being
3262 * typed in now. Depends on lyxrc settings
3263 * "auto_region_delete", which defaults to
3266 LyXText * lt = bv_->getLyXText();
3268 if (lyxrc.auto_region_delete) {
3269 if (lt->selection.set()) {
3270 lt->cutSelection(bv_, false, false);
3273 | BufferView::FITCUR
3274 | BufferView::CHANGE);
3276 workarea_.haveSelection(false);
3280 LyXFont const old_font(lt->real_current_font);
3282 string::const_iterator cit = argument.begin();
3283 string::const_iterator end = argument.end();
3284 for (; cit != end; ++cit) {
3285 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3290 | BufferView::FITCUR
3291 | BufferView::CHANGE);
3293 lt->selection.cursor = lt->cursor;
3294 moveCursorUpdate(false);
3296 // real_current_font.number can change so we need to
3297 // update the minibuffer
3298 if (old_font != lt->real_current_font)
3299 owner_->showState();
3304 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3306 time_t now_time_t = time(NULL);
3307 struct tm * now_tm = localtime(&now_time_t);
3308 setlocale(LC_TIME, "");
3310 if (!argument.empty())
3313 arg = lyxrc.date_insert_format;
3315 int const datetmp_len =
3316 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3318 LyXText * lt = bv_->getLyXText();
3320 for (int i = 0; i < datetmp_len; i++) {
3321 lt->insertChar(bv_, datetmp[i]);
3324 | BufferView::FITCUR
3325 | BufferView::CHANGE);
3328 lt->selection.cursor = lt->cursor;
3329 moveCursorUpdate(false);
3333 case LFUN_UNKNOWN_ACTION:
3334 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3345 void BufferView::Pimpl::newline()
3348 LyXText * lt = bv_->getLyXText();
3352 | BufferView::FITCUR);
3353 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3356 | BufferView::FITCUR
3357 | BufferView::CHANGE);
3362 void BufferView::Pimpl::hfill()
3365 LyXText * lt = bv_->getLyXText();
3369 | BufferView::FITCUR);
3370 lt->insertChar(bv_, Paragraph::META_HFILL);
3373 | BufferView::FITCUR
3374 | BufferView::CHANGE);
3379 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3382 LyXText * lt = bv_->getLyXText();
3385 update(lt, BufferView::SELECT|BufferView::FITCUR);
3386 InsetSpecialChar * new_inset =
3387 new InsetSpecialChar(kind);
3388 if (!insertInset(new_inset))
3391 updateInset(new_inset, true);
3396 void BufferView::Pimpl::smartQuote()
3398 LyXText const * lt = bv_->getLyXText();
3399 Paragraph const * par = lt->cursor.par();
3400 pos_type pos = lt->cursor.pos();
3404 || (par->isInset(pos - 1)
3405 && par->getInset(pos - 1)->isSpace()))
3408 c = par->getChar(pos - 1);
3413 LyXLayout const & style =
3414 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3416 if (style.pass_thru ||
3417 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3418 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3422 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3424 if (insertInset(inset))
3431 // Open and lock an updatable inset
3432 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3434 LyXText * lt = bv_->getLyXText();
3438 if (!insertInset(new_inset)) {
3442 new_inset->edit(bv_, !behind);
3447 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3449 // if we are in a locking inset we should try to insert the
3450 // inset there otherwise this is a illegal function now
3451 if (bv_->theLockingInset()) {
3452 if (bv_->theLockingInset()->insetAllowed(inset))
3453 return bv_->theLockingInset()->insertInset(bv_, inset);
3457 // not quite sure if we want this...
3458 setCursorParUndo(bv_);
3461 beforeChange(bv_->text);
3462 if (!lout.empty()) {
3463 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3464 bv_->text->breakParagraph(bv_);
3465 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3467 if (bv_->text->cursor.par()->size()) {
3468 bv_->text->cursorLeft(bv_);
3470 bv_->text->breakParagraph(bv_);
3471 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3475 LyXTextClass const & tclass =
3476 textclasslist[buffer_->params.textclass];
3477 bool hasLayout = tclass.hasLayout(lres);
3478 string lay = tclass.defaultLayoutName();
3480 if (hasLayout != false) {
3484 // layout not fount using default
3485 lay = tclass.defaultLayoutName();
3488 bv_->text->setLayout(bv_, lay);
3490 bv_->text->setParagraph(bv_, 0, 0,
3492 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3497 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3500 bv_->text->insertInset(bv_, inset);
3501 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3508 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3510 if (!inset || !available())
3513 // first check for locking insets
3514 if (bv_->theLockingInset()) {
3515 if (bv_->theLockingInset() == inset) {
3516 if (bv_->text->updateInset(bv_, inset)) {
3519 buffer_->markDirty();
3524 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3525 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3528 buffer_->markDirty();
3536 // then check if the inset is a top_level inset (has no owner)
3537 // if yes do the update as always otherwise we have to update the
3538 // toplevel inset where this inset is inside
3539 Inset * tl_inset = inset;
3540 while(tl_inset->owner())
3541 tl_inset = tl_inset->owner();
3543 if (tl_inset == inset) {
3544 update(bv_->text, BufferView::UPDATE);
3545 if (bv_->text->updateInset(bv_, inset)) {
3549 | BufferView::FITCUR
3550 | BufferView::CHANGE);
3552 update(bv_->text, SELECT);
3556 } else if (static_cast<UpdatableInset *>(tl_inset)
3557 ->updateInsetInInset(bv_, inset))
3559 if (bv_->text->updateInset(bv_, tl_inset)) {
3567 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3570 if (!available()) return;
3573 beforeChange(bv_->text);
3574 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3576 LyXCursor const & cursor = bv_->text->cursor;
3580 cursor.par()->isInset(cursor.pos())) {
3581 Inset const * inset = cursor.par()->getInset(cursor.pos());
3582 if (find(codes.begin(), codes.end(), inset->lyxCode())
3585 static_cast<InsetCommand const *>(inset)->getContents();
3589 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3590 if (bv_->text->cursor.pos()
3591 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3592 LyXCursor tmp = bv_->text->cursor;
3593 bv_->text->cursor.par(bv_->text->ownerParagraph());
3594 bv_->text->cursor.pos(0);
3595 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3596 bv_->text->cursor = tmp;
3597 bv_->owner()->message(_("No more insets"));
3600 bv_->owner()->message(_("No more insets"));
3603 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3604 bv_->text->selection.cursor = bv_->text->cursor;
3608 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3610 gotoInset(vector<Inset::Code>(1, code), same_content);