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());
1080 bv_->text->status(bv_, st);
1081 screen_->update(bv_->text, bv_);
1083 // do this here instead of in the screen::update because of
1085 bv_->text->status(bv_, LyXText::UNCHANGED);
1091 // Values used when calling update:
1093 // -2 - update, move sel_cursor if selection, fitcursor
1094 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1095 // 0 - update, move sel_cursor if selection, fitcursor
1096 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1097 // 3 - update, move sel_cursor if selection
1100 // a simple redraw of the parts that need refresh
1102 // move sel_cursor if selection -
1103 // the text's sel_cursor is moved if there is selection is progress
1106 // fitCursor() is called and the scrollbar updated
1109 // the buffer is marked dirty.
1118 // UPDATE_ONLY = UPDATE;
1119 // UPDATE_SELECT = UPDATE | SELECT;
1120 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1121 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1123 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1124 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1125 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1126 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1127 // update(3) -> update(1) -> update(1) -> update(SELECT)
1129 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1131 owner_->updateLayoutChoice();
1133 if (!text->selection.set() && (f & SELECT)) {
1134 text->selection.cursor = text->cursor;
1137 text->fullRebreak(bv_);
1139 if (text->inset_owner) {
1140 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1141 updateInset(text->inset_owner, false);
1151 buffer_->markDirty();
1156 // Callback for cursor timer
1157 void BufferView::Pimpl::cursorToggle()
1160 cursor_timeout.restart();
1164 if (!screen_.get()) {
1165 cursor_timeout.restart();
1170 extern void reapSpellchecker(void);
1173 if (!bv_->theLockingInset()) {
1174 screen_->cursorToggle(bv_);
1176 bv_->theLockingInset()->toggleInsetCursor(bv_);
1179 cursor_timeout.restart();
1183 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1185 if (!text->cursor.row()->previous()) {
1186 if (text->first_y > 0) {
1187 int new_y = bv_->text->first_y - workarea_.height();
1188 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1194 int y = text->first_y;
1195 Row * cursorrow = text->cursor.row();
1197 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1201 if (cursorrow == bv_->text->cursor.row()) {
1202 // we have a row which is higher than the workarea so we leave the
1203 // cursor on the start of the row and move only the draw up as soon
1204 // as we move the cursor or do something while inside the row (it may
1205 // span several workarea-heights) we'll move to the top again, but this
1206 // is better than just jump down and only display part of the row.
1207 new_y = bv_->text->first_y - workarea_.height();
1209 if (text->inset_owner) {
1210 new_y = bv_->text->cursor.iy()
1211 + bv_->theLockingInset()->insetInInsetY() + y
1212 + text->cursor.row()->height()
1213 - workarea_.height() + 1;
1215 new_y = text->cursor.y()
1216 - text->cursor.row()->baseline()
1217 + text->cursor.row()->height()
1218 - workarea_.height() + 1;
1221 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1222 if (text->cursor.row()->previous()) {
1224 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1225 text->cursor.row()->previous()->pos(), false);
1226 if (cur.y() > text->first_y) {
1227 text->cursorUp(bv_, true);
1234 void BufferView::Pimpl::cursorNext(LyXText * text)
1236 if (!text->cursor.row()->next()) {
1237 int y = text->cursor.y() - text->cursor.row()->baseline() +
1238 text->cursor.row()->height();
1239 if (y > int(text->first_y + workarea_.height())) {
1240 screen_->draw(bv_->text, bv_,
1241 bv_->text->first_y + workarea_.height());
1247 int y = text->first_y + workarea_.height();
1248 if (text->inset_owner && !text->first_y) {
1249 y -= (bv_->text->cursor.iy()
1250 - bv_->text->first_y
1251 + bv_->theLockingInset()->insetInInsetY());
1253 text->getRowNearY(y);
1255 Row * cursorrow = text->cursor.row();
1256 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1259 if (cursorrow == bv_->text->cursor.row()) {
1260 // we have a row which is higher than the workarea so we leave the
1261 // cursor on the start of the row and move only the draw down as soon
1262 // as we move the cursor or do something while inside the row (it may
1263 // span several workarea-heights) we'll move to the top again, but this
1264 // is better than just jump down and only display part of the row.
1265 new_y = bv_->text->first_y + workarea_.height();
1267 if (text->inset_owner) {
1268 new_y = bv_->text->cursor.iy()
1269 + bv_->theLockingInset()->insetInInsetY()
1270 + y - text->cursor.row()->baseline();
1272 new_y = text->cursor.y() - text->cursor.row()->baseline();
1275 screen_->draw(bv_->text, bv_, new_y);
1276 if (text->cursor.row()->next()) {
1278 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1279 text->cursor.row()->next()->pos(), false);
1280 if (cur.y() < int(text->first_y + workarea_.height())) {
1281 text->cursorDown(bv_, true);
1288 bool BufferView::Pimpl::available() const
1290 if (buffer_ && bv_->text)
1296 void BufferView::Pimpl::beforeChange(LyXText * text)
1299 text->clearSelection();
1303 void BufferView::Pimpl::savePosition(unsigned int i)
1305 if (i >= saved_positions_num)
1307 saved_positions[i] = Position(buffer_->fileName(),
1308 bv_->text->cursor.par()->id(),
1309 bv_->text->cursor.pos());
1312 str << _("Saved bookmark") << ' ' << i;
1313 owner_->message(str.str().c_str());
1318 void BufferView::Pimpl::restorePosition(unsigned int i)
1320 if (i >= saved_positions_num)
1323 string const fname = saved_positions[i].filename;
1325 beforeChange(bv_->text);
1327 if (fname != buffer_->fileName()) {
1328 Buffer * b = bufferlist.exists(fname) ?
1329 bufferlist.getBuffer(fname) :
1330 bufferlist.loadLyXFile(fname); // don't ask, just load it
1331 if (b != 0) buffer(b);
1334 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1338 bv_->text->setCursor(bv_, par,
1339 min(par->size(), saved_positions[i].par_pos));
1341 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1344 str << _("Moved to bookmark") << ' ' << i;
1345 owner_->message(str.str().c_str());
1350 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1352 if (i >= saved_positions_num)
1355 return !saved_positions[i].filename.empty();
1359 void BufferView::Pimpl::setState()
1361 if (!lyxrc.rtl_support)
1364 LyXText * text = bv_->getLyXText();
1365 if (text->real_current_font.isRightToLeft()) {
1366 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1367 owner_->getIntl()->KeyMapSec();
1369 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1370 owner_->getIntl()->KeyMapPrim();
1375 void BufferView::Pimpl::insetSleep()
1377 if (bv_->theLockingInset() && !inset_slept) {
1378 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1379 bv_->theLockingInset()->insetUnlock(bv_);
1385 void BufferView::Pimpl::insetWakeup()
1387 if (bv_->theLockingInset() && inset_slept) {
1388 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1389 inset_slept = false;
1394 void BufferView::Pimpl::insetUnlock()
1396 if (bv_->theLockingInset()) {
1398 bv_->theLockingInset()->insetUnlock(bv_);
1399 bv_->theLockingInset(0);
1401 inset_slept = false;
1406 bool BufferView::Pimpl::focus() const
1408 return workarea_.hasFocus();
1412 void BufferView::Pimpl::focus(bool f)
1414 if (f) workarea_.setFocus();
1418 bool BufferView::Pimpl::active() const
1420 return workarea_.active();
1424 bool BufferView::Pimpl::belowMouse() const
1426 return workarea_.belowMouse();
1430 void BufferView::Pimpl::showCursor()
1432 if (screen_.get()) {
1433 if (bv_->theLockingInset())
1434 bv_->theLockingInset()->showInsetCursor(bv_);
1436 screen_->showCursor(bv_->text, bv_);
1441 void BufferView::Pimpl::hideCursor()
1443 if (screen_.get()) {
1444 if (!bv_->theLockingInset())
1445 // bv_->theLockingInset()->hideInsetCursor(bv_);
1447 screen_->hideCursor();
1452 void BufferView::Pimpl::toggleSelection(bool b)
1454 if (screen_.get()) {
1455 if (bv_->theLockingInset())
1456 bv_->theLockingInset()->toggleSelection(bv_, b);
1457 screen_->toggleSelection(bv_->text, bv_, b);
1462 void BufferView::Pimpl::toggleToggle()
1465 screen_->toggleToggle(bv_->text, bv_);
1469 void BufferView::Pimpl::center()
1471 beforeChange(bv_->text);
1472 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1473 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1475 screen_->draw(bv_->text, bv_, 0);
1477 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1482 void BufferView::Pimpl::pasteClipboard(bool asPara)
1487 screen_->hideCursor();
1488 beforeChange(bv_->text);
1490 string const clip(workarea_.getClipboard());
1496 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1498 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1500 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1504 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1506 workarea_.putClipboard(stuff);
1511 * Dispatch functions for actions which can be valid for BufferView->text
1512 * and/or InsetText->text!!!
1517 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1519 LyXText * lt = bv_->getLyXText();
1521 if (selecting || lt->selection.mark()) {
1522 lt->setSelection(bv_);
1526 updateInset(lt->inset_owner, false);
1530 update(lt, BufferView::SELECT|BufferView::FITCUR);
1532 update(lt, BufferView::SELECT);
1536 if (!lt->selection.set())
1537 workarea_.haveSelection(false);
1539 /* ---> Everytime the cursor is moved, show the current font state. */
1540 // should this too me moved out of this func?
1541 //owner->showState();
1546 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1548 LyXCursor cursor = bv_->getLyXText()->cursor;
1549 Buffer::inset_iterator it =
1550 find_if(Buffer::inset_iterator(
1551 cursor.par(), cursor.pos()),
1552 buffer_->inset_iterator_end(),
1553 lyx::compare_memfun(&Inset::lyxCode, code));
1554 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1558 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1560 string filename = filen;
1562 if (filename.empty()) {
1563 // Launch a file browser
1564 string initpath = lyxrc.document_path;
1567 string const trypath = owner_->buffer()->filePath();
1568 // If directory is writeable, use this as default.
1569 if (IsDirWriteable(trypath))
1573 FileDialog fileDlg(bv_->owner(),
1574 _("Select LyX document to insert"),
1576 make_pair(string(_("Documents|#o#O")),
1577 string(lyxrc.document_path)),
1578 make_pair(string(_("Examples|#E#e")),
1579 string(AddPath(system_lyxdir, "examples"))));
1581 FileDialog::Result result =
1582 fileDlg.Select(initpath,
1583 _("*.lyx| LyX Documents (*.lyx)"));
1585 if (result.first == FileDialog::Later)
1588 filename = result.second;
1590 // check selected filename
1591 if (filename.empty()) {
1592 owner_->message(_("Canceled."));
1597 // get absolute path of file and add ".lyx" to the filename if
1599 filename = FileSearch(string(), filename, "lyx");
1601 string const disp_fn(MakeDisplayPath(filename));
1604 s1 << _("Inserting document") << ' '
1605 << disp_fn << " ...";
1606 owner_->message(s1.str().c_str());
1607 bool const res = bv_->insertLyXFile(filename);
1610 str << _("Document") << ' ' << disp_fn
1611 << ' ' << _("inserted.");
1612 owner_->message(str.str().c_str());
1615 str << _("Could not insert document") << ' '
1617 owner_->message(str.str().c_str());
1622 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1624 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1625 << action <<"] arg[" << argument << "]" << endl;
1628 // --- Misc -------------------------------------------
1632 LyXText * lt = bv_->getLyXText();
1633 lt->toggleAppendix(bv_);
1636 | BufferView::FITCUR
1637 | BufferView::CHANGE);
1642 case LFUN_TOC_INSERT:
1644 InsetCommandParams p;
1645 p.setCmdName("tableofcontents");
1646 Inset * inset = new InsetTOC(p);
1647 if (!insertInset(inset, "Standard"))
1652 case LFUN_SCROLL_INSET:
1653 // this is not handled here as this funktion is only aktive
1654 // if we have a locking_inset and that one is (or contains)
1658 case LFUN_INSET_GRAPHICS:
1660 Inset * new_inset = new InsetGraphics;
1661 if (!insertInset(new_inset)) {
1664 // this is need because you don't use a inset->Edit()
1665 updateInset(new_inset, true);
1666 new_inset->edit(bv_);
1676 case LFUN_PASTESELECTION:
1678 bool asPara = false;
1679 if (argument == "paragraph")
1681 pasteClipboard(asPara);
1693 case LFUN_LAYOUT_COPY:
1694 bv_->copyEnvironment();
1697 case LFUN_LAYOUT_PASTE:
1698 bv_->pasteEnvironment();
1702 case LFUN_GOTOERROR:
1703 gotoInset(Inset::ERROR_CODE, false);
1707 gotoInset(Inset::IGNORE_CODE, false);
1710 case LFUN_REFERENCE_GOTO:
1712 vector<Inset::Code> tmp;
1713 tmp.push_back(Inset::LABEL_CODE);
1714 tmp.push_back(Inset::REF_CODE);
1715 gotoInset(tmp, true);
1719 case LFUN_HYPHENATION:
1720 specialChar(InsetSpecialChar::HYPHENATION);
1723 case LFUN_LIGATURE_BREAK:
1724 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1728 specialChar(InsetSpecialChar::LDOTS);
1731 case LFUN_END_OF_SENTENCE:
1732 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1735 case LFUN_MENU_SEPARATOR:
1736 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1743 case LFUN_DEPTH_MIN:
1744 changeDepth(bv_, bv_->getLyXText(), -1);
1747 case LFUN_DEPTH_PLUS:
1748 changeDepth(bv_, bv_->getLyXText(), 1);
1752 owner_->getDialogs()->setUserFreeFont();
1755 case LFUN_FILE_INSERT:
1756 MenuInsertLyXFile(argument);
1759 case LFUN_FILE_INSERT_ASCII_PARA:
1760 InsertAsciiFile(bv_, argument, true);
1763 case LFUN_FILE_INSERT_ASCII:
1764 InsertAsciiFile(bv_, argument, false);
1769 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1770 << argument << endl;
1772 // Derive layout number from given argument (string)
1773 // and current buffer's textclass (number). */
1774 textclass_type tclass = buffer_->params.textclass;
1776 textclasslist[tclass].hasLayout(argument);
1777 string layout = argument;
1779 // If the entry is obsolete, use the new one instead.
1781 string const & obs = textclasslist[tclass][layout]
1788 owner_->getLyXFunc()->setErrorMessage(
1789 string(N_("Layout ")) + argument +
1794 bool change_layout = (current_layout != layout);
1795 LyXText * lt = bv_->getLyXText();
1796 if (!change_layout && lt->selection.set() &&
1797 lt->selection.start.par() != lt->selection.end.par())
1799 Paragraph * spar = lt->selection.start.par();
1800 Paragraph * epar = lt->selection.end.par()->next();
1801 while(spar != epar) {
1802 if (spar->layout() != current_layout) {
1803 change_layout = true;
1808 if (change_layout) {
1810 current_layout = layout;
1813 | BufferView::FITCUR);
1814 lt->setLayout(bv_, layout);
1815 owner_->setLayout(layout);
1818 | BufferView::FITCUR
1819 | BufferView::CHANGE);
1826 lang(bv_, argument);
1828 owner_->showState();
1833 owner_->showState();
1838 owner_->showState();
1843 owner_->showState();
1848 owner_->showState();
1853 owner_->showState();
1858 owner_->showState();
1863 owner_->showState();
1866 case LFUN_UNDERLINE:
1868 owner_->showState();
1871 case LFUN_FONT_SIZE:
1872 fontSize(bv_, argument);
1873 owner_->showState();
1876 case LFUN_FONT_STATE:
1877 owner_->getLyXFunc()->setMessage(currentState(bv_));
1880 case LFUN_UPCASE_WORD:
1882 LyXText * lt = bv_->getLyXText();
1886 | BufferView::FITCUR);
1887 lt->changeCase(bv_, LyXText::text_uppercase);
1888 if (lt->inset_owner)
1889 updateInset(lt->inset_owner, true);
1892 | BufferView::FITCUR
1893 | BufferView::CHANGE);
1897 case LFUN_LOWCASE_WORD:
1899 LyXText * lt = bv_->getLyXText();
1901 update(lt, BufferView::SELECT|BufferView::FITCUR);
1902 lt->changeCase(bv_, LyXText::text_lowercase);
1903 if (lt->inset_owner)
1904 updateInset(lt->inset_owner, true);
1907 | BufferView::FITCUR
1908 | BufferView::CHANGE);
1912 case LFUN_CAPITALIZE_WORD:
1914 LyXText * lt = bv_->getLyXText();
1916 update(lt, BufferView::SELECT|BufferView::FITCUR);
1917 lt->changeCase(bv_, LyXText::text_capitalization);
1918 if (lt->inset_owner)
1919 updateInset(lt->inset_owner, true);
1922 | BufferView::FITCUR
1923 | BufferView::CHANGE);
1927 case LFUN_TRANSPOSE_CHARS:
1929 LyXText * lt = bv_->getLyXText();
1931 update(lt, BufferView::SELECT|BufferView::FITCUR);
1932 lt->transposeChars(*bv_);
1933 if (lt->inset_owner)
1934 updateInset(lt->inset_owner, true);
1937 | BufferView::FITCUR
1938 | BufferView::CHANGE);
1943 case LFUN_INSERT_LABEL:
1944 MenuInsertLabel(bv_, argument);
1947 case LFUN_REF_INSERT:
1948 if (argument.empty()) {
1949 InsetCommandParams p("ref");
1950 owner_->getDialogs()->createRef(p.getAsString());
1952 InsetCommandParams p;
1953 p.setFromString(argument);
1955 InsetRef * inset = new InsetRef(p, *buffer_);
1956 if (!insertInset(inset))
1959 updateInset(inset, true);
1963 case LFUN_BOOKMARK_SAVE:
1964 savePosition(strToUnsignedInt(argument));
1967 case LFUN_BOOKMARK_GOTO:
1968 restorePosition(strToUnsignedInt(argument));
1973 string label(argument);
1974 if (label.empty()) {
1976 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1978 label = inset->getContents();
1983 if (!label.empty()) {
1984 //bv_->savePosition(0);
1985 if (!bv_->gotoLabel(label))
1986 Alert::alert(_("Error"),
1987 _("Couldn't find this label"),
1988 _("in current document."));
1993 // --- Cursor Movements -----------------------------
1996 LyXText * lt = bv_->getLyXText();
1998 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1999 if (!lt->selection.mark())
2001 update(lt, BufferView::SELECT|BufferView::FITCUR);
2003 lt->cursorLeft(bv_, false);
2004 if (lt->cursor.pos() < lt->cursor.par()->size()
2005 && lt->cursor.par()->isInset(lt->cursor.pos())
2006 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2007 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2008 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2010 tmpinset->edit(bv_, false);
2012 tmpinset->edit(bv_);
2016 lt->cursorRight(bv_, false);
2018 moveCursorUpdate(false);
2019 owner_->showState();
2025 // This is soooo ugly. Isn`t it possible to make
2026 // it simpler? (Lgb)
2027 LyXText * lt = bv_->getLyXText();
2028 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2029 if (!lt->selection.mark())
2031 update(lt, BufferView::SELECT|BufferView::FITCUR);
2032 LyXCursor const cur = lt->cursor;
2034 lt->cursorLeft(bv_, false);
2035 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2036 lt->cursor.pos() < lt->cursor.par()->size() &&
2037 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2038 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2039 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2040 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2042 tmpinset->edit(bv_);
2044 tmpinset->edit(bv_, false);
2048 lt->cursorRight(bv_, false);
2051 moveCursorUpdate(false);
2052 owner_->showState();
2058 LyXText * lt = bv_->getLyXText();
2060 if (!lt->selection.mark())
2062 update(lt, BufferView::UPDATE);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2076 update(lt, BufferView::UPDATE);
2077 lt->cursorDown(bv_);
2079 moveCursorUpdate(false);
2080 owner_->showState();
2084 case LFUN_UP_PARAGRAPH:
2086 LyXText * lt = bv_->getLyXText();
2088 if (!lt->selection.mark())
2090 update(lt, BufferView::UPDATE);
2091 lt->cursorUpParagraph(bv_);
2093 moveCursorUpdate(false);
2094 owner_->showState();
2098 case LFUN_DOWN_PARAGRAPH:
2100 LyXText * lt = bv_->getLyXText();
2102 if (!lt->selection.mark())
2104 update(lt, BufferView::UPDATE);
2105 lt->cursorDownParagraph(bv_);
2107 moveCursorUpdate(false);
2108 owner_->showState();
2114 LyXText * lt = bv_->getLyXText();
2116 if (!lt->selection.mark())
2118 update(lt, BufferView::UPDATE);
2121 moveCursorUpdate(false, false);
2122 owner_->showState();
2128 LyXText * lt = bv_->getLyXText();
2130 if (!lt->selection.mark())
2132 update(lt, BufferView::UPDATE);
2135 moveCursorUpdate(false, false);
2136 owner_->showState();
2142 LyXText * lt = bv_->getLyXText();
2144 if (!lt->selection.mark())
2146 update(lt, BufferView::SELECT|BufferView::FITCUR);
2147 lt->cursorHome(bv_);
2149 moveCursorUpdate(false);
2150 owner_->showState();
2156 LyXText * lt = bv_->getLyXText();
2158 if (!lt->selection.mark())
2161 BufferView::SELECT|BufferView::FITCUR);
2164 moveCursorUpdate(false);
2165 owner_->showState();
2169 case LFUN_SHIFT_TAB:
2172 LyXText * lt = bv_->getLyXText();
2174 if (!lt->selection.mark())
2177 BufferView::SELECT|BufferView::FITCUR);
2180 moveCursorUpdate(false);
2181 owner_->showState();
2185 case LFUN_WORDRIGHT:
2187 LyXText * lt = bv_->getLyXText();
2189 if (!lt->selection.mark())
2191 update(lt, BufferView::SELECT|BufferView::FITCUR);
2192 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2193 lt->cursorLeftOneWord(bv_);
2195 lt->cursorRightOneWord(bv_);
2197 moveCursorUpdate(false);
2198 owner_->showState();
2204 LyXText * lt = bv_->getLyXText();
2206 if (!lt->selection.mark())
2208 update(lt, BufferView::SELECT|BufferView::FITCUR);
2209 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2210 lt->cursorRightOneWord(bv_);
2212 lt->cursorLeftOneWord(bv_);
2214 moveCursorUpdate(false);
2215 owner_->showState();
2219 case LFUN_BEGINNINGBUF:
2221 LyXText * lt = bv_->getLyXText();
2223 if (!lt->selection.mark())
2226 BufferView::SELECT|BufferView::FITCUR);
2229 moveCursorUpdate(false);
2230 owner_->showState();
2236 LyXText * lt = bv_->getLyXText();
2238 if (!lt->selection.mark())
2241 BufferView::SELECT|BufferView::FITCUR);
2242 lt->cursorBottom(bv_);
2244 moveCursorUpdate(false);
2245 owner_->showState();
2249 /* cursor selection ---------------------------- */
2252 LyXText * lt = bv_->getLyXText();
2255 BufferView::SELECT|BufferView::FITCUR);
2256 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2257 lt->cursorLeft(bv_);
2259 lt->cursorRight(bv_);
2261 moveCursorUpdate(true);
2262 owner_->showState();
2268 LyXText * lt = bv_->getLyXText();
2271 BufferView::SELECT|BufferView::FITCUR);
2272 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2273 lt->cursorRight(bv_);
2275 lt->cursorLeft(bv_);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2284 LyXText * lt = bv_->getLyXText();
2287 BufferView::SELECT|BufferView::FITCUR);
2288 lt->cursorUp(bv_, true);
2290 moveCursorUpdate(true);
2291 owner_->showState();
2297 LyXText * lt = bv_->getLyXText();
2300 BufferView::SELECT|BufferView::FITCUR);
2301 lt->cursorDown(bv_, true);
2303 moveCursorUpdate(true);
2304 owner_->showState();
2308 case LFUN_UP_PARAGRAPHSEL:
2310 LyXText * lt = bv_->getLyXText();
2313 BufferView::SELECT|BufferView::FITCUR);
2314 lt->cursorUpParagraph(bv_);
2316 moveCursorUpdate(true);
2317 owner_->showState();
2321 case LFUN_DOWN_PARAGRAPHSEL:
2323 LyXText * lt = bv_->getLyXText();
2326 BufferView::SELECT|BufferView::FITCUR);
2327 lt->cursorDownParagraph(bv_);
2329 moveCursorUpdate(true);
2330 owner_->showState();
2336 LyXText * lt = bv_->getLyXText();
2338 update(lt, BufferView::SELECT|BufferView::FITCUR);
2341 moveCursorUpdate(true);
2342 owner_->showState();
2348 LyXText * lt = bv_->getLyXText();
2350 update(lt, BufferView::SELECT|BufferView::FITCUR);
2353 moveCursorUpdate(true);
2354 owner_->showState();
2360 LyXText * lt = bv_->getLyXText();
2362 update(lt, BufferView::SELECT|BufferView::FITCUR);
2363 lt->cursorHome(bv_);
2365 moveCursorUpdate(true);
2366 owner_->showState();
2372 LyXText * lt = bv_->getLyXText();
2374 update(lt, BufferView::SELECT|BufferView::FITCUR);
2377 moveCursorUpdate(true);
2378 owner_->showState();
2382 case LFUN_WORDRIGHTSEL:
2384 LyXText * lt = bv_->getLyXText();
2386 update(lt, BufferView::SELECT|BufferView::FITCUR);
2387 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2388 lt->cursorLeftOneWord(bv_);
2390 lt->cursorRightOneWord(bv_);
2392 moveCursorUpdate(true);
2393 owner_->showState();
2397 case LFUN_WORDLEFTSEL:
2399 LyXText * lt = bv_->getLyXText();
2401 update(lt, BufferView::SELECT|BufferView::FITCUR);
2402 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2403 lt->cursorRightOneWord(bv_);
2405 lt->cursorLeftOneWord(bv_);
2407 moveCursorUpdate(true);
2408 owner_->showState();
2412 case LFUN_BEGINNINGBUFSEL:
2414 LyXText * lt = bv_->getLyXText();
2416 if (lt->inset_owner)
2418 update(lt, BufferView::SELECT|BufferView::FITCUR);
2421 moveCursorUpdate(true);
2422 owner_->showState();
2426 case LFUN_ENDBUFSEL:
2428 LyXText * lt = bv_->getLyXText();
2430 if (lt->inset_owner)
2433 BufferView::SELECT|BufferView::FITCUR);
2434 lt->cursorBottom(bv_);
2436 moveCursorUpdate(true);
2437 owner_->showState();
2441 // --- text changing commands ------------------------
2442 case LFUN_BREAKLINE:
2444 LyXText * lt = bv_->getLyXText();
2447 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2450 | BufferView::FITCUR
2451 | BufferView::CHANGE);
2452 moveCursorUpdate(false);
2456 case LFUN_PROTECTEDSPACE:
2458 LyXText * lt = bv_->getLyXText();
2460 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2462 if (style.free_spacing) {
2463 lt->insertChar(bv_, ' ');
2466 | BufferView::FITCUR
2467 | BufferView::CHANGE);
2469 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2471 moveCursorUpdate(false);
2477 LyXText * lt = bv_->getLyXText();
2479 if (lt->selection.mark()) {
2483 | BufferView::FITCUR);
2484 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2487 lt->selection.mark(true);
2490 | BufferView::FITCUR);
2491 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2493 lt->selection.cursor = lt->cursor;
2499 LyXText * lt = bv_->getLyXText();
2501 if (!lt->selection.set()) {
2503 lt->selection.cursor = lt->cursor;
2506 | BufferView::FITCUR
2507 | BufferView::CHANGE);
2508 // It is possible to make it a lot faster still
2509 // just comment out the line below...
2514 moveCursorUpdate(false);
2515 owner_->showState();
2520 case LFUN_DELETE_SKIP:
2522 LyXText * lt = bv_->getLyXText();
2524 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2526 LyXCursor cursor = lt->cursor;
2528 if (!lt->selection.set()) {
2529 if (cursor.pos() == cursor.par()->size()) {
2530 lt->cursorRight(bv_);
2531 cursor = lt->cursor;
2532 if (cursor.pos() == 0
2533 && !(cursor.par()->params().spaceTop()
2534 == VSpace (VSpace::NONE))) {
2537 cursor.par()->params().lineTop(),
2538 cursor.par()->params().lineBottom(),
2539 cursor.par()->params().pagebreakTop(),
2540 cursor.par()->params().pagebreakBottom(),
2541 VSpace(VSpace::NONE),
2542 cursor.par()->params().spaceBottom(),
2543 cursor.par()->params().spacing(),
2544 cursor.par()->params().align(),
2545 cursor.par()->params().labelWidthString(), 0);
2546 lt->cursorLeft(bv_);
2549 | BufferView::FITCUR
2550 | BufferView::CHANGE);
2552 lt->cursorLeft(bv_);
2554 lt->selection.cursor = lt->cursor;
2557 | BufferView::FITCUR
2558 | BufferView::CHANGE);
2562 lt->selection.cursor = lt->cursor;
2565 | BufferView::FITCUR
2566 | BufferView::CHANGE);
2574 /* -------> Delete word forward. */
2575 case LFUN_DELETE_WORD_FORWARD:
2576 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2577 bv_->getLyXText()->deleteWordForward(bv_);
2578 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2579 moveCursorUpdate(false);
2580 owner_->showState();
2583 /* -------> Delete word backward. */
2584 case LFUN_DELETE_WORD_BACKWARD:
2586 LyXText * lt = bv_->getLyXText();
2588 update(lt, BufferView::SELECT|BufferView::FITCUR);
2589 lt->deleteWordBackward(bv_);
2592 | BufferView::FITCUR
2593 | BufferView::CHANGE);
2594 moveCursorUpdate(false);
2595 owner_->showState();
2599 /* -------> Kill to end of line. */
2600 case LFUN_DELETE_LINE_FORWARD:
2602 LyXText * lt = bv_->getLyXText();
2604 update(lt, BufferView::SELECT|BufferView::FITCUR);
2605 lt->deleteLineForward(bv_);
2608 | BufferView::FITCUR
2609 | BufferView::CHANGE);
2610 moveCursorUpdate(false);
2614 /* -------> Set mark off. */
2617 LyXText * lt = bv_->getLyXText();
2620 update(lt, BufferView::SELECT|BufferView::FITCUR);
2621 lt->selection.cursor = lt->cursor;
2622 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2626 /* -------> Set mark on. */
2629 LyXText * lt = bv_->getLyXText();
2632 lt->selection.mark(true);
2633 update(lt, BufferView::SELECT|BufferView::FITCUR);
2634 lt->selection.cursor = lt->cursor;
2635 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2639 case LFUN_BACKSPACE:
2641 LyXText * lt = bv_->getLyXText();
2643 if (!lt->selection.set()) {
2644 if (owner_->getIntl()->getTrans().backspace()) {
2646 lt->selection.cursor = lt->cursor;
2649 | BufferView::FITCUR
2650 | BufferView::CHANGE);
2651 // It is possible to make it a lot faster still
2652 // just comment out the line below...
2658 owner_->showState();
2663 case LFUN_BACKSPACE_SKIP:
2665 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2666 LyXText * lt = bv_->getLyXText();
2668 LyXCursor cursor = lt->cursor;
2670 if (!lt->selection.set()) {
2671 if (cursor.pos() == 0
2672 && !(cursor.par()->params().spaceTop()
2673 == VSpace (VSpace::NONE))) {
2676 cursor.par()->params().lineTop(),
2677 cursor.par()->params().lineBottom(),
2678 cursor.par()->params().pagebreakTop(),
2679 cursor.par()->params().pagebreakBottom(),
2680 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2681 cursor.par()->params().spacing(),
2682 cursor.par()->params().align(),
2683 cursor.par()->params().labelWidthString(), 0);
2686 | BufferView::FITCUR
2687 | BufferView::CHANGE);
2690 lt->selection.cursor = cursor;
2693 | BufferView::FITCUR
2694 | BufferView::CHANGE);
2701 case LFUN_BREAKPARAGRAPH:
2703 LyXText * lt = bv_->getLyXText();
2706 lt->breakParagraph(bv_, 0);
2709 | BufferView::FITCUR
2710 | BufferView::CHANGE);
2711 lt->selection.cursor = lt->cursor;
2713 owner_->showState();
2717 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2719 LyXText * lt = bv_->getLyXText();
2722 lt->breakParagraph(bv_, 1);
2725 | BufferView::FITCUR
2726 | BufferView::CHANGE);
2727 lt->selection.cursor = lt->cursor;
2729 owner_->showState();
2733 case LFUN_BREAKPARAGRAPH_SKIP:
2735 // When at the beginning of a paragraph, remove
2736 // indentation and add a "defskip" at the top.
2737 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2738 LyXText * lt = bv_->getLyXText();
2740 LyXCursor cursor = lt->cursor;
2743 if (cursor.pos() == 0) {
2744 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2747 cursor.par()->params().lineTop(),
2748 cursor.par()->params().lineBottom(),
2749 cursor.par()->params().pagebreakTop(),
2750 cursor.par()->params().pagebreakBottom(),
2751 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2752 cursor.par()->params().spacing(),
2753 cursor.par()->params().align(),
2754 cursor.par()->params().labelWidthString(), 1);
2755 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2759 lt->breakParagraph(bv_, 0);
2760 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2765 | BufferView::FITCUR
2766 | BufferView::CHANGE);
2767 lt->selection.cursor = cursor;
2769 owner_->showState();
2773 case LFUN_PARAGRAPH_SPACING:
2775 LyXText * lt = bv_->getLyXText();
2777 Paragraph * par = lt->cursor.par();
2778 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2779 float cur_value = 1.0;
2780 if (cur_spacing == Spacing::Other) {
2781 cur_value = par->params().spacing().getValue();
2784 istringstream istr(argument.c_str());
2788 Spacing::Space new_spacing = cur_spacing;
2789 float new_value = cur_value;
2791 lyxerr << "Missing argument to `paragraph-spacing'"
2793 } else if (tmp == "single") {
2794 new_spacing = Spacing::Single;
2795 } else if (tmp == "onehalf") {
2796 new_spacing = Spacing::Onehalf;
2797 } else if (tmp == "double") {
2798 new_spacing = Spacing::Double;
2799 } else if (tmp == "other") {
2800 new_spacing = Spacing::Other;
2803 lyxerr << "new_value = " << tmpval << endl;
2806 } else if (tmp == "default") {
2807 new_spacing = Spacing::Default;
2809 lyxerr << _("Unknown spacing argument: ")
2810 << argument << endl;
2812 if (cur_spacing != new_spacing || cur_value != new_value) {
2813 par->params().spacing(Spacing(new_spacing, new_value));
2814 lt->redoParagraph(bv_);
2817 | BufferView::FITCUR
2818 | BufferView::CHANGE);
2823 case LFUN_INSET_TOGGLE:
2825 LyXText * lt = bv_->getLyXText();
2828 update(lt, BufferView::SELECT|BufferView::FITCUR);
2829 lt->toggleInset(bv_);
2830 update(lt, BufferView::SELECT|BufferView::FITCUR);
2842 InsetCommandParams p;
2843 if (action == LFUN_HTMLURL)
2844 p.setCmdName("htmlurl");
2846 p.setCmdName("url");
2847 owner_->getDialogs()->createUrl(p.getAsString());
2851 case LFUN_INSERT_URL:
2853 InsetCommandParams p;
2854 p.setFromString(argument);
2856 InsetUrl * inset = new InsetUrl(p);
2857 if (!insertInset(inset))
2860 updateInset(inset, true);
2864 case LFUN_INSET_ERT:
2865 insertAndEditInset(new InsetERT(buffer_->params));
2868 case LFUN_INSET_EXTERNAL:
2869 insertAndEditInset(new InsetExternal);
2872 case LFUN_INSET_FOOTNOTE:
2873 insertAndEditInset(new InsetFoot(buffer_->params));
2876 case LFUN_INSET_MARGINAL:
2877 insertAndEditInset(new InsetMarginal(buffer_->params));
2880 case LFUN_INSET_MINIPAGE:
2881 insertAndEditInset(new InsetMinipage(buffer_->params));
2884 case LFUN_INSERT_NOTE:
2885 insertAndEditInset(new InsetNote(buffer_->params));
2888 case LFUN_INSET_FLOAT:
2889 // check if the float type exist
2890 if (floatList.typeExist(argument)) {
2891 insertAndEditInset(new InsetFloat(buffer_->params,
2894 lyxerr << "Non-existent float type: "
2895 << argument << endl;
2899 case LFUN_INSET_WIDE_FLOAT:
2901 // check if the float type exist
2902 if (floatList.typeExist(argument)) {
2903 InsetFloat * new_inset =
2904 new InsetFloat(buffer_->params, argument);
2905 new_inset->wide(true);
2906 if (insertInset(new_inset))
2907 new_inset->edit(bv_);
2911 lyxerr << "Non-existent float type: "
2912 << argument << endl;
2919 case LFUN_INSET_LIST:
2920 insertAndEditInset(new InsetList);
2923 case LFUN_INSET_THEOREM:
2924 insertAndEditInset(new InsetTheorem);
2928 case LFUN_INSET_CAPTION:
2930 // Do we have a locking inset...
2931 if (bv_->theLockingInset()) {
2932 lyxerr << "Locking inset code: "
2933 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2934 InsetCaption * new_inset =
2935 new InsetCaption(buffer_->params);
2936 new_inset->setOwner(bv_->theLockingInset());
2937 new_inset->setAutoBreakRows(true);
2938 new_inset->setDrawFrame(0, InsetText::LOCKED);
2939 new_inset->setFrameColor(0, LColor::captionframe);
2940 if (insertInset(new_inset))
2941 new_inset->edit(bv_);
2948 case LFUN_INSET_TABULAR:
2952 if (!argument.empty())
2953 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2954 InsetTabular * new_inset =
2955 new InsetTabular(*buffer_, r, c);
2957 bv_->getLyXText()->real_current_font.isRightToLeft();
2958 if (!open_new_inset(new_inset, rtl))
2963 // --- lyxserver commands ----------------------------
2965 case LFUN_CHARATCURSOR:
2967 pos_type pos = bv_->getLyXText()->cursor.pos();
2968 if (pos < bv_->getLyXText()->cursor.par()->size())
2969 owner_->getLyXFunc()->setMessage(
2970 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2972 owner_->getLyXFunc()->setMessage("EOF");
2977 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2979 + tostr(bv_->getLyXText()->cursor.y()));
2986 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2987 lyxerr << "SETXY: Could not parse coordinates in '"
2988 << argument << std::endl;
2990 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2994 case LFUN_GETLAYOUT:
2995 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3000 LyXFont & font = bv_->getLyXText()->current_font;
3001 if (font.shape() == LyXFont::ITALIC_SHAPE)
3002 owner_->getLyXFunc()->setMessage("E");
3003 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3004 owner_->getLyXFunc()->setMessage("N");
3006 owner_->getLyXFunc()->setMessage("0");
3011 // --- accented characters ---------------------------
3014 case LFUN_CIRCUMFLEX:
3024 case LFUN_SPECIAL_CARON:
3027 case LFUN_HUNG_UMLAUT:
3030 if (argument.empty()) {
3032 owner_->getLyXFunc()->handleKeyFunc(action);
3034 owner_->getLyXFunc()->handleKeyFunc(action);
3035 owner_->getIntl()->getTrans()
3036 .TranslateAndInsert(argument[0], bv_->getLyXText());
3037 update(bv_->getLyXText(),
3039 | BufferView::FITCUR
3040 | BufferView::CHANGE);
3044 case LFUN_MATH_MACRO:
3045 mathDispatchMathMacro(bv_, argument);
3048 case LFUN_MATH_DELIM:
3049 mathDispatchMathDelim(bv_, argument);
3052 case LFUN_INSERT_MATRIX:
3053 mathDispatchInsertMatrix(bv_, argument);
3056 case LFUN_INSERT_MATH:
3057 mathDispatchInsertMath(bv_, argument);
3060 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3061 mathDispatchMathImportSelection(bv_, argument);
3064 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3065 mathDispatchMathDisplay(bv_, argument);
3068 case LFUN_MATH_MODE: // Open or create an inlined math inset
3069 mathDispatchMathMode(bv_, argument);
3072 case LFUN_GREEK: // Insert a single greek letter
3073 mathDispatchGreek(bv_, argument);
3076 case LFUN_CITATION_INSERT:
3078 InsetCommandParams p;
3079 p.setFromString(argument);
3081 InsetCitation * inset = new InsetCitation(p);
3082 if (!insertInset(inset))
3085 updateInset(inset, true);
3089 case LFUN_INSERT_BIBTEX:
3091 // ale970405+lasgoutt970425
3092 // The argument can be up to two tokens separated
3093 // by a space. The first one is the bibstyle.
3094 string const db = token(argument, ' ', 0);
3095 string const bibstyle = token(argument, ' ', 1);
3097 InsetCommandParams p("BibTeX", db, bibstyle);
3098 InsetBibtex * inset = new InsetBibtex(p);
3100 if (insertInset(inset)) {
3101 if (argument.empty())
3108 // BibTeX data bases
3109 case LFUN_BIBDB_ADD:
3111 InsetBibtex * inset =
3112 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3114 inset->addDatabase(argument);
3119 case LFUN_BIBDB_DEL:
3121 InsetBibtex * inset =
3122 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3124 inset->delDatabase(argument);
3129 case LFUN_BIBTEX_STYLE:
3131 InsetBibtex * inset =
3132 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3134 inset->setOptions(argument);
3139 case LFUN_INDEX_CREATE:
3141 InsetCommandParams p("index");
3142 if (argument.empty()) {
3143 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3144 p.setContents(idxstring);
3146 p.setContents(argument);
3149 owner_->getDialogs()->createIndex(p.getAsString());
3153 case LFUN_INDEX_INSERT:
3155 InsetCommandParams p;
3156 p.setFromString(argument);
3157 InsetIndex * inset = new InsetIndex(p);
3159 if (!insertInset(inset))
3162 updateInset(inset, true);
3166 case LFUN_INDEX_INSERT_LAST:
3168 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3169 if (!idxstring.empty()) {
3170 owner_->message(_("Word `")
3171 + idxstring + _(("' indexed.")));
3172 InsetCommandParams p("index", idxstring);
3173 InsetIndex * inset = new InsetIndex(p);
3175 if (!insertInset(inset))
3178 updateInset(inset, true);
3183 case LFUN_INDEX_PRINT:
3185 InsetCommandParams p("printindex");
3186 Inset * inset = new InsetPrintIndex(p);
3187 if (!insertInset(inset, "Standard"))
3192 case LFUN_PARENTINSERT:
3194 InsetCommandParams p("lyxparent", argument);
3195 Inset * inset = new InsetParent(p, *buffer_);
3196 if (!insertInset(inset, "Standard"))
3202 case LFUN_CHILD_INSERT:
3204 InsetInclude::Params p;
3205 p.cparams.setFromString(argument);
3206 p.masterFilename_ = buffer_->fileName();
3208 InsetInclude * inset = new InsetInclude(p);
3209 if (!insertInset(inset))
3212 updateInset(inset, true);
3213 bv_->owner()->getDialogs()->showInclude(inset);
3218 case LFUN_FLOAT_LIST:
3220 // We should check the argument for validity. (Lgb)
3221 Inset * inset = new InsetFloatList(argument);
3222 if (!insertInset(inset, "Standard"))
3227 case LFUN_THESAURUS_ENTRY:
3229 string arg = argument;
3232 arg = bv_->getLyXText()->selectionAsString(buffer_,
3236 if (arg.size() > 100 || arg.empty()) {
3237 // Get word or selection
3238 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3239 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3240 // FIXME: where is getLyXText()->unselect(bv_) ?
3244 bv_->owner()->getDialogs()->showThesaurus(arg);
3248 case LFUN_SELFINSERT:
3250 if (argument.empty()) break;
3252 /* Automatically delete the currently selected
3253 * text and replace it with what is being
3254 * typed in now. Depends on lyxrc settings
3255 * "auto_region_delete", which defaults to
3258 LyXText * lt = bv_->getLyXText();
3260 if (lyxrc.auto_region_delete) {
3261 if (lt->selection.set()) {
3262 lt->cutSelection(bv_, false, false);
3265 | BufferView::FITCUR
3266 | BufferView::CHANGE);
3268 workarea_.haveSelection(false);
3272 LyXFont const old_font(lt->real_current_font);
3274 string::const_iterator cit = argument.begin();
3275 string::const_iterator end = argument.end();
3276 for (; cit != end; ++cit) {
3277 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3282 | BufferView::FITCUR
3283 | BufferView::CHANGE);
3285 lt->selection.cursor = lt->cursor;
3286 moveCursorUpdate(false);
3288 // real_current_font.number can change so we need to
3289 // update the minibuffer
3290 if (old_font != lt->real_current_font)
3291 owner_->showState();
3296 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3298 time_t now_time_t = time(NULL);
3299 struct tm * now_tm = localtime(&now_time_t);
3300 setlocale(LC_TIME, "");
3302 if (!argument.empty())
3305 arg = lyxrc.date_insert_format;
3307 int const datetmp_len =
3308 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3310 LyXText * lt = bv_->getLyXText();
3312 for (int i = 0; i < datetmp_len; i++) {
3313 lt->insertChar(bv_, datetmp[i]);
3316 | BufferView::FITCUR
3317 | BufferView::CHANGE);
3320 lt->selection.cursor = lt->cursor;
3321 moveCursorUpdate(false);
3325 case LFUN_UNKNOWN_ACTION:
3326 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3337 void BufferView::Pimpl::newline()
3340 LyXText * lt = bv_->getLyXText();
3344 | BufferView::FITCUR);
3345 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3348 | BufferView::FITCUR
3349 | BufferView::CHANGE);
3354 void BufferView::Pimpl::hfill()
3357 LyXText * lt = bv_->getLyXText();
3361 | BufferView::FITCUR);
3362 lt->insertChar(bv_, Paragraph::META_HFILL);
3365 | BufferView::FITCUR
3366 | BufferView::CHANGE);
3371 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3374 LyXText * lt = bv_->getLyXText();
3377 update(lt, BufferView::SELECT|BufferView::FITCUR);
3378 InsetSpecialChar * new_inset =
3379 new InsetSpecialChar(kind);
3380 if (!insertInset(new_inset))
3383 updateInset(new_inset, true);
3388 void BufferView::Pimpl::smartQuote()
3390 LyXText const * lt = bv_->getLyXText();
3391 Paragraph const * par = lt->cursor.par();
3392 pos_type pos = lt->cursor.pos();
3396 || (par->isInset(pos - 1)
3397 && par->getInset(pos - 1)->isSpace()))
3400 c = par->getChar(pos - 1);
3405 LyXLayout const & style =
3406 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3408 if (style.pass_thru ||
3409 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3410 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3414 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3416 if (insertInset(inset))
3423 // Open and lock an updatable inset
3424 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3426 LyXText * lt = bv_->getLyXText();
3430 if (!insertInset(new_inset)) {
3434 new_inset->edit(bv_, !behind);
3439 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3441 // if we are in a locking inset we should try to insert the
3442 // inset there otherwise this is a illegal function now
3443 if (bv_->theLockingInset()) {
3444 if (bv_->theLockingInset()->insetAllowed(inset))
3445 return bv_->theLockingInset()->insertInset(bv_, inset);
3449 // not quite sure if we want this...
3450 setCursorParUndo(bv_);
3453 beforeChange(bv_->text);
3454 if (!lout.empty()) {
3455 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3456 bv_->text->breakParagraph(bv_);
3457 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3459 if (bv_->text->cursor.par()->size()) {
3460 bv_->text->cursorLeft(bv_);
3462 bv_->text->breakParagraph(bv_);
3463 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3467 LyXTextClass const & tclass =
3468 textclasslist[buffer_->params.textclass];
3469 bool hasLayout = tclass.hasLayout(lres);
3470 string lay = tclass.defaultLayoutName();
3472 if (hasLayout != false) {
3476 // layout not fount using default
3477 lay = tclass.defaultLayoutName();
3480 bv_->text->setLayout(bv_, lay);
3482 bv_->text->setParagraph(bv_, 0, 0,
3484 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3489 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3492 bv_->text->insertInset(bv_, inset);
3493 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3500 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3502 if (!inset || !available())
3505 // first check for locking insets
3506 if (bv_->theLockingInset()) {
3507 if (bv_->theLockingInset() == inset) {
3508 if (bv_->text->updateInset(bv_, inset)) {
3511 buffer_->markDirty();
3516 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3517 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3520 buffer_->markDirty();
3528 // then check if the inset is a top_level inset (has no owner)
3529 // if yes do the update as always otherwise we have to update the
3530 // toplevel inset where this inset is inside
3531 Inset * tl_inset = inset;
3532 while(tl_inset->owner())
3533 tl_inset = tl_inset->owner();
3535 if (tl_inset == inset) {
3536 update(bv_->text, BufferView::UPDATE);
3537 if (bv_->text->updateInset(bv_, inset)) {
3541 | BufferView::FITCUR
3542 | BufferView::CHANGE);
3544 update(bv_->text, SELECT);
3548 } else if (static_cast<UpdatableInset *>(tl_inset)
3549 ->updateInsetInInset(bv_, inset))
3551 if (bv_->text->updateInset(bv_, tl_inset)) {
3559 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3562 if (!available()) return;
3565 beforeChange(bv_->text);
3566 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3568 LyXCursor const & cursor = bv_->text->cursor;
3572 cursor.par()->isInset(cursor.pos())) {
3573 Inset const * inset = cursor.par()->getInset(cursor.pos());
3574 if (find(codes.begin(), codes.end(), inset->lyxCode())
3577 static_cast<InsetCommand const *>(inset)->getContents();
3581 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3582 if (bv_->text->cursor.pos()
3583 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3584 LyXCursor tmp = bv_->text->cursor;
3585 bv_->text->cursor.par(bv_->text->ownerParagraph());
3586 bv_->text->cursor.pos(0);
3587 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3588 bv_->text->cursor = tmp;
3589 bv_->owner()->message(_("No more insets"));
3592 bv_->owner()->message(_("No more insets"));
3595 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3596 bv_->text->selection.cursor = bv_->text->cursor;
3600 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3602 gotoInset(vector<Inset::Code>(1, code), same_content);