2 * \file BufferView_pimpl.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
12 #pragma implementation
15 #include "BufferView_pimpl.h"
16 #include "frontends/WorkArea.h"
17 #include "frontends/screen.h"
18 #include "frontends/LyXScreenFactory.h"
19 #include "frontends/WorkAreaFactory.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/Alert.h"
22 #include "frontends/FileDialog.h"
25 #include "paragraph.h"
26 #include "frontends/LyXView.h"
27 #include "commandtags.h"
30 #include "bufferview_funcs.h"
31 #include "TextCache.h"
32 #include "bufferlist.h"
35 // added for Dispatch functions
38 #include "FloatList.h"
40 #include "ParagraphParameters.h"
41 #include "undo_funcs.h"
43 #include "insets/insetbib.h"
44 #include "insets/insettext.h"
45 #include "insets/inseturl.h"
46 #include "insets/insetlatexaccent.h"
47 #include "insets/insettoc.h"
48 #include "insets/insetref.h"
49 #include "insets/insetparent.h"
50 #include "insets/insetindex.h"
51 #include "insets/insetnote.h"
52 #include "insets/insetinclude.h"
53 #include "insets/insetcite.h"
54 #include "insets/insetert.h"
55 #include "insets/insetexternal.h"
56 #include "insets/insetgraphics.h"
57 #include "insets/insetfoot.h"
58 #include "insets/insetmarginal.h"
59 #include "insets/insetminipage.h"
60 #include "insets/insetfloat.h"
61 #include "insets/insettabular.h"
63 #include "insets/insettheorem.h"
64 #include "insets/insetlist.h"
66 #include "insets/insetcaption.h"
67 #include "insets/insetfloatlist.h"
68 #include "insets/insetspecialchar.h"
70 #include "mathed/formulabase.h"
72 #include "graphics/Previews.h"
74 #include "support/LAssert.h"
75 #include "support/lstrings.h"
76 #include "support/filetools.h"
77 #include "support/lyxfunctional.h"
79 #include <boost/bind.hpp>
80 #include <boost/signals/connection.hpp>
89 extern string current_layout;
91 #ifndef CXX_GLOBAL_CSTD
104 using std::make_pair;
108 using lyx::textclass_type;
110 /* the selection possible is needed, that only motion events are
111 * used, where the bottom press event was on the drawing area too */
112 bool selection_possible = false;
114 extern BufferList bufferlist;
115 extern char ascii_type;
117 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
122 unsigned int const saved_positions_num = 20;
124 // All the below connection objects are needed because of a bug in some
125 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
126 // to these connections we avoid a segfault upon startup, and also at exit.
129 boost::signals::connection timecon;
130 boost::signals::connection doccon;
131 boost::signals::connection resizecon;
132 boost::signals::connection bpresscon;
133 boost::signals::connection breleasecon;
134 boost::signals::connection motioncon;
135 boost::signals::connection doublecon;
136 boost::signals::connection triplecon;
137 boost::signals::connection kpresscon;
138 boost::signals::connection selectioncon;
139 boost::signals::connection lostcon;
144 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
145 int xpos, int ypos, int width, int height)
146 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
147 using_xterm_cursor(false)
149 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
150 screen_.reset(LyXScreenFactory::create(workarea()));
153 doccon = workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
154 resizecon = workarea().workAreaResize
155 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
156 bpresscon = workarea().workAreaButtonPress
157 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
158 breleasecon = workarea().workAreaButtonRelease
159 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
160 motioncon = workarea().workAreaMotionNotify
161 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
162 doublecon = workarea().workAreaDoubleClick
163 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
164 triplecon = workarea().workAreaTripleClick
165 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
166 kpresscon = workarea().workAreaKeyPress
167 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
168 selectioncon = workarea().selectionRequested
169 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
170 lostcon = workarea().selectionLost
171 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
173 timecon = cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
174 cursor_timeout.start();
175 saved_positions.resize(saved_positions_num);
179 WorkArea & BufferView::Pimpl::workarea() const
181 return *workarea_.get();
185 LyXScreen & BufferView::Pimpl::screen() const
187 return *screen_.get();
191 Painter & BufferView::Pimpl::painter() const
193 return workarea().getPainter();
197 void BufferView::Pimpl::buffer(Buffer * b)
199 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
202 buffer_->delUser(bv_);
204 // Put the old text into the TextCache, but
205 // only if the buffer is still loaded.
206 // Also set the owner of the test to 0
207 // bv_->text->owner(0);
208 textcache.add(buffer_, workarea().workWidth(), bv_->text);
209 if (lyxerr.debugging())
210 textcache.show(lyxerr, "BufferView::buffer");
215 // Set current buffer
218 if (bufferlist.getState() == BufferList::CLOSING) return;
220 // If we are closing the buffer, use the first buffer as current
222 buffer_ = bufferlist.first();
226 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
227 buffer_->addUser(bv_);
229 // If we don't have a text object for this, we make one
230 if (bv_->text == 0) {
231 resizeCurrentBuffer();
234 // FIXME: needed when ?
235 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
237 // Similarly, buffer-dependent dialogs should be updated or
238 // hidden. This should go here because some dialogs (eg ToC)
239 // require bv_->text.
240 owner_->getDialogs()->updateBufferDependent(true);
242 lyxerr[Debug::INFO] << " No Buffer!" << endl;
243 owner_->getDialogs()->hideBufferDependent();
245 // Also remove all remaining text's from the testcache.
246 // (there should not be any!) (if there is any it is a
248 if (lyxerr.debugging())
249 textcache.show(lyxerr, "buffer delete all");
255 owner_->updateMenubar();
256 owner_->updateToolbar();
257 owner_->updateLayoutChoice();
258 owner_->updateWindowTitle();
260 if (grfx::Previews::activated() && buffer_)
261 grfx::Previews::get().generateBufferPreviews(*buffer_);
265 bool BufferView::Pimpl::fitCursor()
269 if (bv_->theLockingInset()) {
270 bv_->theLockingInset()->fitInsetCursor(bv_);
273 ret = screen().fitCursor(bv_->text, bv_);
276 bv_->owner()->getDialogs()->updateParagraph();
283 void BufferView::Pimpl::redoCurrentBuffer()
285 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
286 if (buffer_ && bv_->text) {
287 resizeCurrentBuffer();
288 owner_->updateLayoutChoice();
294 int BufferView::Pimpl::resizeCurrentBuffer()
296 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
299 Paragraph * selstartpar = 0;
300 Paragraph * selendpar = 0;
301 UpdatableInset * the_locking_inset = 0;
304 pos_type selstartpos = 0;
305 pos_type selendpos = 0;
306 bool selection = false;
307 bool mark_set = false;
309 owner_->prohibitInput();
311 owner_->message(_("Formatting document..."));
314 par = bv_->text->cursor.par();
315 pos = bv_->text->cursor.pos();
316 selstartpar = bv_->text->selection.start.par();
317 selstartpos = bv_->text->selection.start.pos();
318 selendpar = bv_->text->selection.end.par();
319 selendpos = bv_->text->selection.end.pos();
320 selection = bv_->text->selection.set();
321 mark_set = bv_->text->selection.mark();
322 the_locking_inset = bv_->theLockingInset();
323 buffer_->resizeInsets(bv_);
324 // I don't think the delete and new are necessary here we just could
325 // call only init! (Jug 20020419)
327 bv_->text = new LyXText(bv_);
328 bv_->text->init(bv_);
330 // See if we have a text in TextCache that fits
331 // the new buffer_ with the correct width.
332 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
334 if (lyxerr.debugging()) {
335 lyxerr << "Found a LyXText that fits:\n";
336 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
338 // Set the owner of the newly found text
339 // bv_->text->owner(bv_);
340 if (lyxerr.debugging())
341 textcache.show(lyxerr, "resizeCurrentBuffer");
343 bv_->text = new LyXText(bv_);
344 bv_->text->init(bv_);
345 //buffer_->resizeInsets(bv_);
350 bv_->text->selection.set(true);
351 // At this point just to avoid the Delete-Empty-Paragraph-
352 // Mechanism when setting the cursor.
353 bv_->text->selection.mark(mark_set);
355 bv_->text->setCursor(bv_, selstartpar, selstartpos);
356 bv_->text->selection.cursor = bv_->text->cursor;
357 bv_->text->setCursor(bv_, selendpar, selendpos);
358 bv_->text->setSelection(bv_);
359 bv_->text->setCursor(bv_, par, pos);
361 bv_->text->setCursor(bv_, par, pos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->selection.set(false);
365 // remake the inset locking
366 bv_->theLockingInset(the_locking_inset);
369 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
372 owner_->allowInput();
374 /// clear the "Formatting Document" message
381 void BufferView::Pimpl::repaint()
383 // Regenerate the screen.
384 screen().redraw(bv_->text, bv_);
388 void BufferView::Pimpl::updateScrollbar()
391 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
392 workarea().setScrollbarParams(0, 0, 0);
396 LyXText const & t = *bv_->text;
398 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
399 << t.first_y << ", default height " << t.defaultHeight() << endl;
401 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
405 void BufferView::Pimpl::scrollDocView(int value)
407 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
409 if (!buffer_) return;
411 screen().draw(bv_->text, bv_, value);
413 if (!lyxrc.cursor_follows_scrollbar) {
417 LyXText * vbt = bv_->text;
419 int const height = vbt->defaultHeight();
420 int const first = static_cast<int>((bv_->text->first_y + height));
421 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
423 if (vbt->cursor.y() < first)
424 vbt->setCursorFromCoordinates(bv_, 0, first);
425 else if (vbt->cursor.y() > last)
426 vbt->setCursorFromCoordinates(bv_, 0, last);
430 int BufferView::Pimpl::scroll(long time)
435 LyXText const * t = bv_->text;
437 double const diff = t->defaultHeight()
438 + double(time) * double(time) * 0.125;
440 scrollDocView(int(diff));
441 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
446 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
447 key_modifier::state state)
449 bv_->owner()->getLyXFunc()->processKeySym(key, state);
453 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
455 // Only use motion with button 1
456 if (!(state & mouse_button::button1))
462 // Check for inset locking
463 if (bv_->theLockingInset()) {
464 LyXCursor cursor = bv_->text->cursor;
465 LyXFont font = bv_->text->getFont(buffer_,
466 cursor.par(), cursor.pos());
467 int width = bv_->theLockingInset()->width(bv_, font);
468 int inset_x = font.isVisibleRightToLeft()
469 ? cursor.ix() - width : cursor.ix();
470 int start_x = inset_x + bv_->theLockingInset()->scroll();
472 bv_->theLockingInset()->
473 insetMotionNotify(bv_,
475 y - cursor.iy() + bv_->text->first_y,
480 /* The test for not selection possible is needed, that only motion
481 events are used, where the bottom press event was on
482 the drawing area too */
483 if (!selection_possible)
486 screen().hideCursor();
488 Row * cursorrow = bv_->text->cursor.row();
489 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
491 // sorry for this but I have a strange error that the y value jumps at
492 // a certain point. This seems like an error in my xforms library or
493 // in some other local environment, but I would like to leave this here
494 // for the moment until I can remove this (Jug 20020418)
495 if (y_before < bv_->text->cursor.y())
496 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
498 // This is to allow jumping over large insets
499 if (cursorrow == bv_->text->cursor.row()) {
500 if (y >= int(workarea().workHeight())) {
501 bv_->text->cursorDown(bv_, false);
503 bv_->text->cursorUp(bv_, false);
507 if (!bv_->text->selection.set())
508 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
510 bv_->text->setSelection(bv_);
511 screen().toggleToggle(bv_->text, bv_);
517 // Single-click on work area
518 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
519 mouse_button::state button)
524 // ok ok, this is a hack (for xforms)
525 if (button == mouse_button::button4) {
526 scroll(-lyxrc.wheel_jump);
527 // We shouldn't go further down as we really should only do the
528 // scrolling and be done with this. Otherwise we may open some
529 // dialogs (Jug 20020424).
531 } else if (button == mouse_button::button5) {
532 scroll(lyxrc.wheel_jump);
533 // We shouldn't go further down as we really should only do the
534 // scrolling and be done with this. Otherwise we may open some
535 // dialogs (Jug 20020424).
539 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
541 // Middle button press pastes if we have a selection
542 // We do this here as if the selection was inside an inset
543 // it could get cleared on the unlocking of the inset so
544 // we have to check this first
545 bool paste_internally = false;
546 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
547 owner_->getLyXFunc()->dispatch(LFUN_COPY);
548 paste_internally = true;
551 int const screen_first = bv_->text->first_y;
553 if (bv_->theLockingInset()) {
554 // We are in inset locking mode
556 /* Check whether the inset was hit. If not reset mode,
557 otherwise give the event to the inset */
558 if (inset_hit == bv_->theLockingInset()) {
559 bv_->theLockingInset()->
560 insetButtonPress(bv_, xpos, ypos, button);
563 bv_->unlockInset(bv_->theLockingInset());
568 selection_possible = true;
569 screen().hideCursor();
571 // Clear the selection
572 screen().toggleSelection(bv_->text, bv_);
573 bv_->text->clearSelection();
574 bv_->text->fullRebreak(bv_);
578 // Single left click in math inset?
579 if (isHighlyEditableInset(inset_hit)) {
580 // Highly editable inset, like math
581 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
582 selection_possible = false;
583 owner_->updateLayoutChoice();
584 owner_->message(inset->editMessage());
585 //inset->edit(bv_, xpos, ypos, button);
586 // We just have to lock the inset before calling a PressEvent on it!
587 // we don't need the edit() call here! (Jug20020329)
588 if (!bv_->lockInset(inset)) {
589 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
591 inset->insetButtonPress(bv_, xpos, ypos, button);
594 // I'm not sure we should continue here if we hit an inset (Jug20020403)
596 // Right click on a footnote flag opens float menu
597 if (button == mouse_button::button3) {
598 selection_possible = false;
602 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
603 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
605 bv_->text->selection.cursor = bv_->text->cursor;
606 bv_->text->cursor.x_fix(bv_->text->cursor.x());
608 owner_->updateLayoutChoice();
610 selection_possible = false;
613 // Insert primary selection with middle mouse
614 // if there is a local selection in the current buffer,
616 if (button == mouse_button::button2) {
617 if (paste_internally)
618 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
620 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
621 string("paragraph"));
622 selection_possible = false;
628 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
633 LyXText * text = bv_->getLyXText();
635 if (text->bv_owner && bv_->theLockingInset())
638 if (button == mouse_button::button1) {
639 if (text->bv_owner) {
640 screen().hideCursor();
641 screen().toggleSelection(text, bv_);
642 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
643 screen().toggleSelection(text, bv_, false);
645 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
647 /* This will fit the cursor on the screen
649 update(text, BufferView::SELECT|BufferView::FITCUR);
654 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
659 LyXText * text = bv_->getLyXText();
661 if (text->bv_owner && bv_->theLockingInset())
664 if (button == mouse_button::button1) {
665 if (text->bv_owner) {
666 screen().hideCursor();
667 screen().toggleSelection(text, bv_);
669 text->cursorHome(bv_);
670 text->selection.cursor = text->cursor;
671 text->cursorEnd(bv_);
672 text->setSelection(bv_);
673 if (text->bv_owner) {
674 screen().toggleSelection(text, bv_, false);
676 /* This will fit the cursor on the screen
678 update(text, BufferView::SELECT|BufferView::FITCUR);
683 void BufferView::Pimpl::selectionRequested()
690 LyXText * text = bv_->getLyXText();
692 if (text->selection.set() &&
693 (!bv_->text->xsel_cache.set() ||
694 text->selection.start != bv_->text->xsel_cache.start ||
695 text->selection.end != bv_->text->xsel_cache.end))
697 bv_->text->xsel_cache = text->selection;
698 sel = text->selectionAsString(bv_->buffer(), false);
699 } else if (!text->selection.set()) {
701 bv_->text->xsel_cache.set(false);
704 workarea().putClipboard(sel);
709 void BufferView::Pimpl::selectionLost()
714 bv_->getLyXText()->clearSelection();
716 bv_->text->xsel_cache.set(false);
721 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
722 mouse_button::state button)
724 // do nothing if we used the mouse wheel
725 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
728 // If we hit an inset, we have the inset coordinates in these
729 // and inset_hit points to the inset. If we do not hit an
730 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
731 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
733 if (bv_->theLockingInset()) {
734 // We are in inset locking mode.
736 /* LyX does a kind of work-area grabbing for insets.
737 Only a ButtonPress Event outside the inset will
738 force a insetUnlock. */
739 bv_->theLockingInset()->
740 insetButtonRelease(bv_, x, y, button);
744 selection_possible = false;
746 if (button == mouse_button::button2)
750 if (button == mouse_button::button1) {
751 workarea().haveSelection(bv_->getLyXText()->selection.set());
755 owner_->view_state_changed();
756 owner_->updateMenubar();
757 owner_->updateToolbar();
759 // Did we hit an editable inset?
761 selection_possible = false;
763 // if we reach this point with a selection, it
764 // must mean we are currently selecting.
765 // But we don't want to open the inset
766 // because that is annoying for the user.
767 // So just pretend we didn't hit it.
768 // this is OK because a "kosher" ButtonRelease
769 // will follow a ButtonPress that clears
771 // Note this also fixes selection drawing
772 // problems if we end up opening an inset
773 if (bv_->getLyXText()->selection.set())
776 // CHECK fix this proper in 0.13
777 // well, maybe 13.0 !!!!!!!!!
779 // Following a ref shouldn't issue
780 // a push on the undo-stack
781 // anylonger, now that we have
782 // keybindings for following
783 // references and returning from
784 // references. IMHO though, it
785 // should be the inset's own business
786 // to push or not push on the undo
787 // stack. They don't *have* to
788 // alter the document...
790 // ...or maybe the SetCursorParUndo()
791 // below isn't necessary at all anylonger?
792 if (inset_hit->lyxCode() == Inset::REF_CODE) {
793 setCursorParUndo(bv_);
796 owner_->message(inset_hit->editMessage());
798 if (isHighlyEditableInset(inset_hit)) {
799 // Highly editable inset, like math
800 UpdatableInset *inset = (UpdatableInset *)inset_hit;
801 inset->insetButtonRelease(bv_, x, y, button);
803 inset_hit->insetButtonRelease(bv_, x, y, button);
804 // IMO this is a grosshack! Inset's should be changed so that
805 // they call the actions they have to do with the insetButtonRel.
806 // function and not in the edit(). This should be changed
808 inset_hit->edit(bv_, x, y, button);
813 // Maybe we want to edit a bibitem ale970302
814 if (bv_->text->cursor.par()->bibkey) {
815 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
816 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
817 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
818 (!is_rtl && x < 20+width)) {
819 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
827 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
828 LyXCursor const & cursor) const
830 Paragraph /*const*/ & par = *cursor.par();
831 pos_type const pos = cursor.pos();
833 lyx::Assert(par.getInset(pos));
835 Inset const & inset(*par.getInset(pos));
837 LyXFont const & font = text.getFont(buffer_, &par, pos);
839 int const width = inset.width(bv_, font);
840 int const inset_x = font.isVisibleRightToLeft()
841 ? (cursor.ix() - width) : cursor.ix();
844 inset_x + inset.scroll(),
846 cursor.iy() - inset.ascent(bv_, font),
847 cursor.iy() + inset.descent(bv_, font));
851 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
852 LyXCursor const & cursor,
853 int & x, int & y) const
855 pos_type const pos(cursor.pos());
856 Paragraph /*const*/ & par(*cursor.par());
858 if (pos >= par.size() || !par.isInset(pos)) {
862 Inset /*const*/ * inset = par.getInset(pos);
864 if (!isEditableInset(inset)) {
868 Box b(insetDimensions(text, cursor));
870 if (!b.contained(x, y)) {
871 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
872 << " box " << b << endl;
876 text.setCursor(bv_, &par, pos, true);
879 // The origin of an inset is on the baseline
880 y -= text.cursor.iy();
886 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
888 int y_tmp = y + text->first_y;
891 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
893 Inset * inset(checkInset(*text, cursor, x, y_tmp));
900 // look at previous position
902 if (cursor.pos() == 0) {
907 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
909 inset = checkInset(*text, cursor, x, y_tmp);
917 void BufferView::Pimpl::workAreaResize()
919 static int work_area_width;
920 static int work_area_height;
922 bool const widthChange = workarea().workWidth() != work_area_width;
923 bool const heightChange = workarea().workHeight() != work_area_height;
925 // update from work area
926 work_area_width = workarea().workWidth();
927 work_area_height = workarea().workHeight();
931 // The visible LyXView need a resize
932 resizeCurrentBuffer();
934 // Remove all texts from the textcache
935 // This is not _really_ what we want to do. What
936 // we really want to do is to delete in textcache
937 // that does not have a BufferView with matching
938 // width, but as long as we have only one BufferView
939 // deleting all gives the same result.
940 if (lyxerr.debugging())
941 textcache.show(lyxerr, "Expose delete all");
943 // FIXME: this is aalready done in resizeCurrentBuffer() ??
944 buffer_->resizeInsets(bv_);
945 } else if (heightChange) {
946 // fitCursor() ensures we don't jump back
947 // to the start of the document on vertical
953 if (widthChange || heightChange) {
957 // always make sure that the scrollbar is sane.
959 owner_->updateLayoutChoice();
964 void BufferView::Pimpl::update()
966 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
967 LyXText::text_status st = bv_->text->status();
968 screen().update(bv_->text, bv_);
970 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
971 bv_->text->fullRebreak(bv_);
972 st = LyXText::NEED_MORE_REFRESH;
973 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
974 bv_->text->cursor.pos());
975 if (bv_->text->selection.set()) {
976 bv_->text->setCursor(bv_, bv_->text->selection.start,
977 bv_->text->selection.start.par(),
978 bv_->text->selection.start.pos());
979 bv_->text->setCursor(bv_, bv_->text->selection.end,
980 bv_->text->selection.end.par(),
981 bv_->text->selection.end.pos());
984 bv_->text->status(bv_, st);
985 screen().update(bv_->text, bv_);
987 // do this here instead of in the screen::update because of
989 bv_->text->status(bv_, LyXText::UNCHANGED);
995 // Values used when calling update:
997 // -2 - update, move sel_cursor if selection, fitcursor
998 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
999 // 0 - update, move sel_cursor if selection, fitcursor
1000 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1001 // 3 - update, move sel_cursor if selection
1004 // a simple redraw of the parts that need refresh
1006 // move sel_cursor if selection -
1007 // the text's sel_cursor is moved if there is selection is progress
1010 // fitCursor() is called and the scrollbar updated
1013 // the buffer is marked dirty.
1022 // UPDATE_ONLY = UPDATE;
1023 // UPDATE_SELECT = UPDATE | SELECT;
1024 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1025 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1027 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1028 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1029 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1030 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1031 // update(3) -> update(1) -> update(1) -> update(SELECT)
1033 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1035 owner_->updateLayoutChoice();
1037 if (!text->selection.set() && (f & SELECT)) {
1038 text->selection.cursor = text->cursor;
1041 text->fullRebreak(bv_);
1043 if (text->inset_owner) {
1044 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1045 updateInset(text->inset_owner, false);
1055 buffer_->markDirty();
1060 // Callback for cursor timer
1061 void BufferView::Pimpl::cursorToggle()
1064 cursor_timeout.restart();
1069 extern void reapSpellchecker(void);
1072 if (!bv_->theLockingInset()) {
1073 screen().cursorToggle(bv_);
1075 bv_->theLockingInset()->toggleInsetCursor(bv_);
1078 cursor_timeout.restart();
1082 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1084 if (!text->cursor.row()->previous()) {
1085 if (text->first_y > 0) {
1086 int new_y = bv_->text->first_y - workarea().workHeight();
1087 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1093 int y = text->first_y;
1094 Row * cursorrow = text->cursor.row();
1096 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1100 if (cursorrow == bv_->text->cursor.row()) {
1101 // we have a row which is higher than the workarea so we leave the
1102 // cursor on the start of the row and move only the draw up as soon
1103 // as we move the cursor or do something while inside the row (it may
1104 // span several workarea-heights) we'll move to the top again, but this
1105 // is better than just jump down and only display part of the row.
1106 new_y = bv_->text->first_y - workarea().workHeight();
1108 if (text->inset_owner) {
1109 new_y = bv_->text->cursor.iy()
1110 + bv_->theLockingInset()->insetInInsetY() + y
1111 + text->cursor.row()->height()
1112 - workarea().workHeight() + 1;
1114 new_y = text->cursor.y()
1115 - text->cursor.row()->baseline()
1116 + text->cursor.row()->height()
1117 - workarea().workHeight() + 1;
1120 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1121 if (text->cursor.row()->previous()) {
1123 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1124 text->cursor.row()->previous()->pos(), false);
1125 if (cur.y() > text->first_y) {
1126 text->cursorUp(bv_, true);
1133 void BufferView::Pimpl::cursorNext(LyXText * text)
1135 if (!text->cursor.row()->next()) {
1136 int y = text->cursor.y() - text->cursor.row()->baseline() +
1137 text->cursor.row()->height();
1138 if (y > int(text->first_y + workarea().workHeight())) {
1139 screen().draw(bv_->text, bv_,
1140 bv_->text->first_y + workarea().workHeight());
1146 int y = text->first_y + workarea().workHeight();
1147 if (text->inset_owner && !text->first_y) {
1148 y -= (bv_->text->cursor.iy()
1149 - bv_->text->first_y
1150 + bv_->theLockingInset()->insetInInsetY());
1153 text->getRowNearY(y);
1155 Row * cursorrow = text->cursor.row();
1156 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1160 if (cursorrow == bv_->text->cursor.row()) {
1161 // we have a row which is higher than the workarea so we leave the
1162 // cursor on the start of the row and move only the draw down as soon
1163 // as we move the cursor or do something while inside the row (it may
1164 // span several workarea-heights) we'll move to the top again, but this
1165 // is better than just jump down and only display part of the row.
1166 new_y = bv_->text->first_y + workarea().workHeight();
1168 if (text->inset_owner) {
1169 new_y = bv_->text->cursor.iy()
1170 + bv_->theLockingInset()->insetInInsetY()
1171 + y - text->cursor.row()->baseline();
1173 new_y = text->cursor.y() - text->cursor.row()->baseline();
1176 screen().draw(bv_->text, bv_, new_y);
1177 if (text->cursor.row()->next()) {
1179 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1180 text->cursor.row()->next()->pos(), false);
1181 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1182 text->cursorDown(bv_, true);
1189 bool BufferView::Pimpl::available() const
1191 if (buffer_ && bv_->text)
1197 void BufferView::Pimpl::beforeChange(LyXText * text)
1200 text->clearSelection();
1204 void BufferView::Pimpl::savePosition(unsigned int i)
1206 if (i >= saved_positions_num)
1208 saved_positions[i] = Position(buffer_->fileName(),
1209 bv_->text->cursor.par()->id(),
1210 bv_->text->cursor.pos());
1213 str << _("Saved bookmark") << ' ' << i;
1214 owner_->message(str.str().c_str());
1219 void BufferView::Pimpl::restorePosition(unsigned int i)
1221 if (i >= saved_positions_num)
1224 string const fname = saved_positions[i].filename;
1226 beforeChange(bv_->text);
1228 if (fname != buffer_->fileName()) {
1229 Buffer * b = bufferlist.exists(fname) ?
1230 bufferlist.getBuffer(fname) :
1231 bufferlist.loadLyXFile(fname); // don't ask, just load it
1232 if (b != 0) buffer(b);
1235 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1239 bv_->text->setCursor(bv_, par,
1240 min(par->size(), saved_positions[i].par_pos));
1242 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1245 str << _("Moved to bookmark") << ' ' << i;
1246 owner_->message(str.str().c_str());
1251 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1253 if (i >= saved_positions_num)
1256 return !saved_positions[i].filename.empty();
1260 void BufferView::Pimpl::switchKeyMap()
1262 if (!lyxrc.rtl_support)
1265 LyXText * text = bv_->getLyXText();
1266 if (text->real_current_font.isRightToLeft()
1267 && !(bv_->theLockingInset()
1268 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1270 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1271 owner_->getIntl()->KeyMapSec();
1273 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1274 owner_->getIntl()->KeyMapPrim();
1279 void BufferView::Pimpl::insetUnlock()
1281 if (bv_->theLockingInset()) {
1282 bv_->theLockingInset()->insetUnlock(bv_);
1283 bv_->theLockingInset(0);
1289 void BufferView::Pimpl::showCursor()
1291 if (bv_->theLockingInset())
1292 bv_->theLockingInset()->showInsetCursor(bv_);
1294 screen().showCursor(bv_->text, bv_);
1298 void BufferView::Pimpl::hideCursor()
1300 if (!bv_->theLockingInset())
1301 screen().hideCursor();
1305 void BufferView::Pimpl::toggleSelection(bool b)
1307 if (bv_->theLockingInset())
1308 bv_->theLockingInset()->toggleSelection(bv_, b);
1309 screen().toggleSelection(bv_->text, bv_, b);
1313 void BufferView::Pimpl::toggleToggle()
1315 screen().toggleToggle(bv_->text, bv_);
1319 void BufferView::Pimpl::center()
1321 LyXText * t = bv_->text;
1324 int const half_height = workarea().workHeight() / 2;
1327 if (t->cursor.y() > half_height) {
1328 new_y = t->cursor.y() - half_height;
1331 // FIXME: can we do this w/o calling screen directly ?
1332 // This updates first_y but means the fitCursor() call
1333 // from the update(FITCUR) doesn't realise that we might
1334 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1335 // the scrollbar to be updated as it should, so we have
1336 // to do it manually. Any operation that does a center()
1337 // and also might have moved first_y must make sure to call
1338 // updateScrollbar() currently. Never mind that this is a
1339 // pretty obfuscated way of updating t->first_y
1340 screen().draw(t, bv_, new_y);
1342 update(t, BufferView::SELECT | BufferView::FITCUR);
1346 void BufferView::Pimpl::pasteClipboard(bool asPara)
1351 screen().hideCursor();
1352 beforeChange(bv_->text);
1354 string const clip(workarea().getClipboard());
1360 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1362 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1364 bv_->getLyXText()->clearSelection();
1365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1369 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1371 workarea().putClipboard(stuff);
1376 * Dispatch functions for actions which can be valid for BufferView->text
1377 * and/or InsetText->text!!!
1382 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1384 LyXText * lt = bv_->getLyXText();
1386 if (selecting || lt->selection.mark()) {
1387 lt->setSelection(bv_);
1391 updateInset(lt->inset_owner, false);
1395 update(lt, BufferView::SELECT|BufferView::FITCUR);
1397 update(lt, BufferView::SELECT);
1399 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1400 bv_->theLockingInset()->hideInsetCursor(bv_);
1401 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1405 if (!lt->selection.set())
1406 workarea().haveSelection(false);
1412 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1414 LyXCursor cursor = bv_->getLyXText()->cursor;
1415 Buffer::inset_iterator it =
1416 find_if(Buffer::inset_iterator(
1417 cursor.par(), cursor.pos()),
1418 buffer_->inset_iterator_end(),
1419 lyx::compare_memfun(&Inset::lyxCode, code));
1420 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1424 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1426 string filename = filen;
1428 if (filename.empty()) {
1429 // Launch a file browser
1430 string initpath = lyxrc.document_path;
1433 string const trypath = owner_->buffer()->filePath();
1434 // If directory is writeable, use this as default.
1435 if (IsDirWriteable(trypath))
1439 FileDialog fileDlg(bv_->owner(),
1440 _("Select LyX document to insert"),
1442 make_pair(string(_("Documents|#o#O")),
1443 string(lyxrc.document_path)),
1444 make_pair(string(_("Examples|#E#e")),
1445 string(AddPath(system_lyxdir, "examples"))));
1447 FileDialog::Result result =
1448 fileDlg.Select(initpath,
1449 _("*.lyx| LyX Documents (*.lyx)"));
1451 if (result.first == FileDialog::Later)
1454 filename = result.second;
1456 // check selected filename
1457 if (filename.empty()) {
1458 owner_->message(_("Canceled."));
1463 // get absolute path of file and add ".lyx" to the filename if
1465 filename = FileSearch(string(), filename, "lyx");
1467 string const disp_fn(MakeDisplayPath(filename));
1470 s1 << _("Inserting document") << ' '
1471 << disp_fn << " ...";
1472 owner_->message(s1.str().c_str());
1473 bool const res = bv_->insertLyXFile(filename);
1476 str << _("Document") << ' ' << disp_fn
1477 << ' ' << _("inserted.");
1478 owner_->message(str.str().c_str());
1481 str << _("Could not insert document") << ' '
1483 owner_->message(str.str().c_str());
1488 bool BufferView::Pimpl::dispatch(kb_action action, string const & argument)
1490 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1491 << action <<"] arg[" << argument << "]" << endl;
1493 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1496 // --- Misc -------------------------------------------
1500 LyXText * lt = bv_->getLyXText();
1501 lt->toggleAppendix(bv_);
1504 | BufferView::FITCUR
1505 | BufferView::CHANGE);
1510 case LFUN_TOC_INSERT:
1512 InsetCommandParams p;
1513 p.setCmdName("tableofcontents");
1514 Inset * inset = new InsetTOC(p);
1515 if (!insertInset(inset, tclass.defaultLayoutName()))
1520 case LFUN_SCROLL_INSET:
1521 // this is not handled here as this funktion is only aktive
1522 // if we have a locking_inset and that one is (or contains)
1526 case LFUN_INSET_GRAPHICS:
1528 Inset * new_inset = new InsetGraphics;
1529 if (!insertInset(new_inset)) {
1532 // this is need because you don't use a inset->Edit()
1533 updateInset(new_inset, true);
1534 new_inset->edit(bv_);
1544 case LFUN_PASTESELECTION:
1546 bool asPara = false;
1547 if (argument == "paragraph")
1549 pasteClipboard(asPara);
1561 case LFUN_LAYOUT_COPY:
1562 bv_->copyEnvironment();
1565 case LFUN_LAYOUT_PASTE:
1566 bv_->pasteEnvironment();
1570 case LFUN_GOTOERROR:
1571 gotoInset(Inset::ERROR_CODE, false);
1575 gotoInset(Inset::NOTE_CODE, false);
1578 case LFUN_REFERENCE_GOTO:
1580 vector<Inset::Code> tmp;
1581 tmp.push_back(Inset::LABEL_CODE);
1582 tmp.push_back(Inset::REF_CODE);
1583 gotoInset(tmp, true);
1587 case LFUN_HYPHENATION:
1588 specialChar(InsetSpecialChar::HYPHENATION);
1591 case LFUN_LIGATURE_BREAK:
1592 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1596 specialChar(InsetSpecialChar::LDOTS);
1599 case LFUN_END_OF_SENTENCE:
1600 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1603 case LFUN_MENU_SEPARATOR:
1604 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1611 case LFUN_DEPTH_MIN:
1612 changeDepth(bv_, bv_->getLyXText(), -1);
1615 case LFUN_DEPTH_PLUS:
1616 changeDepth(bv_, bv_->getLyXText(), 1);
1620 owner_->getDialogs()->setUserFreeFont();
1623 case LFUN_FILE_INSERT:
1624 MenuInsertLyXFile(argument);
1627 case LFUN_FILE_INSERT_ASCII_PARA:
1628 InsertAsciiFile(bv_, argument, true);
1631 case LFUN_FILE_INSERT_ASCII:
1632 InsertAsciiFile(bv_, argument, false);
1637 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1638 << argument << endl;
1640 // This is not the good solution to the empty argument
1641 // problem, but it will hopefully suffice for 1.2.0.
1642 // The correct solution would be to augument the
1643 // function list/array with information about what
1644 // functions needs arguments and their type.
1645 if (argument.empty()) {
1646 owner_->getLyXFunc()->setErrorMessage(
1647 _("LyX function 'layout' needs an argument."));
1651 // Derive layout number from given argument (string)
1652 // and current buffer's textclass (number). */
1653 bool hasLayout = tclass.hasLayout(argument);
1654 string layout = argument;
1656 // If the entry is obsolete, use the new one instead.
1658 string const & obs = tclass[layout]->obsoleted_by();
1664 owner_->getLyXFunc()->setErrorMessage(
1665 string(N_("Layout ")) + argument +
1670 bool change_layout = (current_layout != layout);
1671 LyXText * lt = bv_->getLyXText();
1672 if (!change_layout && lt->selection.set() &&
1673 lt->selection.start.par() != lt->selection.end.par())
1675 Paragraph * spar = lt->selection.start.par();
1676 Paragraph * epar = lt->selection.end.par()->next();
1677 while(spar != epar) {
1678 if (spar->layout()->name() != current_layout) {
1679 change_layout = true;
1684 if (change_layout) {
1686 current_layout = layout;
1689 | BufferView::FITCUR);
1690 lt->setLayout(bv_, layout);
1691 owner_->setLayout(layout);
1694 | BufferView::FITCUR
1695 | BufferView::CHANGE);
1702 lang(bv_, argument);
1704 owner_->view_state_changed();
1709 owner_->view_state_changed();
1714 owner_->view_state_changed();
1719 owner_->view_state_changed();
1724 owner_->view_state_changed();
1729 owner_->view_state_changed();
1734 owner_->view_state_changed();
1739 owner_->view_state_changed();
1742 case LFUN_UNDERLINE:
1744 owner_->view_state_changed();
1747 case LFUN_FONT_SIZE:
1748 fontSize(bv_, argument);
1749 owner_->view_state_changed();
1752 case LFUN_FONT_STATE:
1753 owner_->getLyXFunc()->setMessage(currentState(bv_));
1756 case LFUN_UPCASE_WORD:
1758 LyXText * lt = bv_->getLyXText();
1762 | BufferView::FITCUR);
1763 lt->changeCase(bv_, LyXText::text_uppercase);
1764 if (lt->inset_owner)
1765 updateInset(lt->inset_owner, true);
1768 | BufferView::FITCUR
1769 | BufferView::CHANGE);
1773 case LFUN_LOWCASE_WORD:
1775 LyXText * lt = bv_->getLyXText();
1777 update(lt, BufferView::SELECT|BufferView::FITCUR);
1778 lt->changeCase(bv_, LyXText::text_lowercase);
1779 if (lt->inset_owner)
1780 updateInset(lt->inset_owner, true);
1783 | BufferView::FITCUR
1784 | BufferView::CHANGE);
1788 case LFUN_CAPITALIZE_WORD:
1790 LyXText * lt = bv_->getLyXText();
1792 update(lt, BufferView::SELECT|BufferView::FITCUR);
1793 lt->changeCase(bv_, LyXText::text_capitalization);
1794 if (lt->inset_owner)
1795 updateInset(lt->inset_owner, true);
1798 | BufferView::FITCUR
1799 | BufferView::CHANGE);
1803 case LFUN_TRANSPOSE_CHARS:
1805 LyXText * lt = bv_->getLyXText();
1807 update(lt, BufferView::SELECT|BufferView::FITCUR);
1808 lt->transposeChars(*bv_);
1809 if (lt->inset_owner)
1810 updateInset(lt->inset_owner, true);
1813 | BufferView::FITCUR
1814 | BufferView::CHANGE);
1819 case LFUN_INSERT_LABEL:
1820 MenuInsertLabel(bv_, argument);
1823 case LFUN_REF_INSERT:
1824 if (argument.empty()) {
1825 InsetCommandParams p("ref");
1826 owner_->getDialogs()->createRef(p.getAsString());
1828 InsetCommandParams p;
1829 p.setFromString(argument);
1831 InsetRef * inset = new InsetRef(p, *buffer_);
1832 if (!insertInset(inset))
1835 updateInset(inset, true);
1839 case LFUN_BOOKMARK_SAVE:
1840 savePosition(strToUnsignedInt(argument));
1843 case LFUN_BOOKMARK_GOTO:
1844 restorePosition(strToUnsignedInt(argument));
1849 string label(argument);
1850 if (label.empty()) {
1852 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1854 label = inset->getContents();
1859 if (!label.empty()) {
1860 //bv_->savePosition(0);
1861 if (!bv_->gotoLabel(label))
1862 Alert::alert(_("Error"),
1863 _("Couldn't find this label"),
1864 _("in current document."));
1869 // --- Cursor Movements -----------------------------
1872 LyXText * lt = bv_->getLyXText();
1874 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1875 if (!lt->selection.mark())
1877 update(lt, BufferView::SELECT|BufferView::FITCUR);
1879 lt->cursorLeft(bv_, false);
1880 if (lt->cursor.pos() < lt->cursor.par()->size()
1881 && lt->cursor.par()->isInset(lt->cursor.pos())
1882 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1883 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1884 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1886 tmpinset->edit(bv_, false);
1888 tmpinset->edit(bv_);
1892 lt->cursorRight(bv_, false);
1894 moveCursorUpdate(false);
1895 owner_->view_state_changed();
1901 // This is soooo ugly. Isn`t it possible to make
1902 // it simpler? (Lgb)
1903 LyXText * lt = bv_->getLyXText();
1904 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1905 if (!lt->selection.mark())
1907 update(lt, BufferView::SELECT|BufferView::FITCUR);
1908 LyXCursor const cur = lt->cursor;
1910 lt->cursorLeft(bv_, false);
1911 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1912 lt->cursor.pos() < lt->cursor.par()->size() &&
1913 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1914 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1915 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1916 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1918 tmpinset->edit(bv_);
1920 tmpinset->edit(bv_, false);
1924 lt->cursorRight(bv_, false);
1927 moveCursorUpdate(false);
1928 owner_->view_state_changed();
1934 LyXText * lt = bv_->getLyXText();
1936 if (!lt->selection.mark())
1938 update(lt, BufferView::UPDATE);
1941 moveCursorUpdate(false);
1942 owner_->view_state_changed();
1948 LyXText * lt = bv_->getLyXText();
1950 if (!lt->selection.mark())
1952 update(lt, BufferView::UPDATE);
1953 lt->cursorDown(bv_);
1955 moveCursorUpdate(false);
1956 owner_->view_state_changed();
1960 case LFUN_UP_PARAGRAPH:
1962 LyXText * lt = bv_->getLyXText();
1964 if (!lt->selection.mark())
1966 update(lt, BufferView::UPDATE);
1967 lt->cursorUpParagraph(bv_);
1969 moveCursorUpdate(false);
1970 owner_->view_state_changed();
1974 case LFUN_DOWN_PARAGRAPH:
1976 LyXText * lt = bv_->getLyXText();
1978 if (!lt->selection.mark())
1980 update(lt, BufferView::UPDATE);
1981 lt->cursorDownParagraph(bv_);
1983 moveCursorUpdate(false);
1984 owner_->view_state_changed();
1990 LyXText * lt = bv_->getLyXText();
1992 if (!lt->selection.mark())
1994 update(lt, BufferView::UPDATE);
1997 moveCursorUpdate(false, false);
1998 owner_->view_state_changed();
2004 LyXText * lt = bv_->getLyXText();
2006 if (!lt->selection.mark())
2008 update(lt, BufferView::UPDATE);
2011 moveCursorUpdate(false, false);
2012 owner_->view_state_changed();
2018 LyXText * lt = bv_->getLyXText();
2020 if (!lt->selection.mark())
2022 update(lt, BufferView::SELECT|BufferView::FITCUR);
2023 lt->cursorHome(bv_);
2025 moveCursorUpdate(false);
2026 owner_->view_state_changed();
2032 LyXText * lt = bv_->getLyXText();
2034 if (!lt->selection.mark())
2037 BufferView::SELECT|BufferView::FITCUR);
2040 moveCursorUpdate(false);
2041 owner_->view_state_changed();
2045 case LFUN_SHIFT_TAB:
2048 LyXText * lt = bv_->getLyXText();
2050 if (!lt->selection.mark())
2053 BufferView::SELECT|BufferView::FITCUR);
2056 moveCursorUpdate(false);
2057 owner_->view_state_changed();
2061 case LFUN_WORDRIGHT:
2063 LyXText * lt = bv_->getLyXText();
2065 if (!lt->selection.mark())
2067 update(lt, BufferView::SELECT|BufferView::FITCUR);
2068 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2069 lt->cursorLeftOneWord(bv_);
2071 lt->cursorRightOneWord(bv_);
2073 moveCursorUpdate(false);
2074 owner_->view_state_changed();
2080 LyXText * lt = bv_->getLyXText();
2082 if (!lt->selection.mark())
2084 update(lt, BufferView::SELECT|BufferView::FITCUR);
2085 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2086 lt->cursorRightOneWord(bv_);
2088 lt->cursorLeftOneWord(bv_);
2090 moveCursorUpdate(false);
2091 owner_->view_state_changed();
2095 case LFUN_BEGINNINGBUF:
2097 LyXText * lt = bv_->getLyXText();
2099 if (!lt->selection.mark())
2102 BufferView::SELECT|BufferView::FITCUR);
2105 moveCursorUpdate(false);
2106 owner_->view_state_changed();
2112 LyXText * lt = bv_->getLyXText();
2114 if (!lt->selection.mark())
2117 BufferView::SELECT|BufferView::FITCUR);
2118 lt->cursorBottom(bv_);
2120 moveCursorUpdate(false);
2121 owner_->view_state_changed();
2125 /* cursor selection ---------------------------- */
2128 LyXText * lt = bv_->getLyXText();
2131 BufferView::SELECT|BufferView::FITCUR);
2132 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2133 lt->cursorLeft(bv_);
2135 lt->cursorRight(bv_);
2137 moveCursorUpdate(true);
2138 owner_->view_state_changed();
2144 LyXText * lt = bv_->getLyXText();
2147 BufferView::SELECT|BufferView::FITCUR);
2148 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2149 lt->cursorRight(bv_);
2151 lt->cursorLeft(bv_);
2153 moveCursorUpdate(true);
2154 owner_->view_state_changed();
2160 LyXText * lt = bv_->getLyXText();
2163 BufferView::SELECT|BufferView::FITCUR);
2164 lt->cursorUp(bv_, true);
2166 moveCursorUpdate(true);
2167 owner_->view_state_changed();
2173 LyXText * lt = bv_->getLyXText();
2176 BufferView::SELECT|BufferView::FITCUR);
2177 lt->cursorDown(bv_, true);
2179 moveCursorUpdate(true);
2180 owner_->view_state_changed();
2184 case LFUN_UP_PARAGRAPHSEL:
2186 LyXText * lt = bv_->getLyXText();
2189 BufferView::SELECT|BufferView::FITCUR);
2190 lt->cursorUpParagraph(bv_);
2192 moveCursorUpdate(true);
2193 owner_->view_state_changed();
2197 case LFUN_DOWN_PARAGRAPHSEL:
2199 LyXText * lt = bv_->getLyXText();
2202 BufferView::SELECT|BufferView::FITCUR);
2203 lt->cursorDownParagraph(bv_);
2205 moveCursorUpdate(true);
2206 owner_->view_state_changed();
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 moveCursorUpdate(true);
2218 owner_->view_state_changed();
2224 LyXText * lt = bv_->getLyXText();
2226 update(lt, BufferView::SELECT|BufferView::FITCUR);
2229 moveCursorUpdate(true);
2230 owner_->view_state_changed();
2236 LyXText * lt = bv_->getLyXText();
2238 update(lt, BufferView::SELECT|BufferView::FITCUR);
2239 lt->cursorHome(bv_);
2241 moveCursorUpdate(true);
2242 owner_->view_state_changed();
2248 LyXText * lt = bv_->getLyXText();
2250 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 moveCursorUpdate(true);
2254 owner_->view_state_changed();
2258 case LFUN_WORDRIGHTSEL:
2260 LyXText * lt = bv_->getLyXText();
2262 update(lt, BufferView::SELECT|BufferView::FITCUR);
2263 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2264 lt->cursorLeftOneWord(bv_);
2266 lt->cursorRightOneWord(bv_);
2268 moveCursorUpdate(true);
2269 owner_->view_state_changed();
2273 case LFUN_WORDLEFTSEL:
2275 LyXText * lt = bv_->getLyXText();
2277 update(lt, BufferView::SELECT|BufferView::FITCUR);
2278 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2279 lt->cursorRightOneWord(bv_);
2281 lt->cursorLeftOneWord(bv_);
2283 moveCursorUpdate(true);
2284 owner_->view_state_changed();
2288 case LFUN_BEGINNINGBUFSEL:
2290 LyXText * lt = bv_->getLyXText();
2292 if (lt->inset_owner)
2294 update(lt, BufferView::SELECT|BufferView::FITCUR);
2297 moveCursorUpdate(true);
2298 owner_->view_state_changed();
2302 case LFUN_ENDBUFSEL:
2304 LyXText * lt = bv_->getLyXText();
2306 if (lt->inset_owner)
2309 BufferView::SELECT|BufferView::FITCUR);
2310 lt->cursorBottom(bv_);
2312 moveCursorUpdate(true);
2313 owner_->view_state_changed();
2317 // --- text changing commands ------------------------
2318 case LFUN_BREAKLINE:
2320 LyXText * lt = bv_->getLyXText();
2323 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2326 | BufferView::FITCUR
2327 | BufferView::CHANGE);
2328 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2329 moveCursorUpdate(false);
2333 case LFUN_PROTECTEDSPACE:
2335 LyXText * lt = bv_->getLyXText();
2336 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2338 if (style->free_spacing) {
2339 lt->insertChar(bv_, ' ');
2342 | BufferView::FITCUR
2343 | BufferView::CHANGE);
2345 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2347 moveCursorUpdate(false);
2353 LyXText * lt = bv_->getLyXText();
2355 if (lt->selection.mark()) {
2359 | BufferView::FITCUR);
2360 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2363 lt->selection.mark(true);
2366 | BufferView::FITCUR);
2367 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2369 lt->selection.cursor = lt->cursor;
2375 LyXText * lt = bv_->getLyXText();
2377 if (!lt->selection.set()) {
2379 lt->selection.cursor = lt->cursor;
2382 | BufferView::FITCUR
2383 | BufferView::CHANGE);
2384 // It is possible to make it a lot faster still
2385 // just comment out the line below...
2390 moveCursorUpdate(false);
2391 owner_->view_state_changed();
2396 case LFUN_DELETE_SKIP:
2398 LyXText * lt = bv_->getLyXText();
2400 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2402 LyXCursor cursor = lt->cursor;
2404 if (!lt->selection.set()) {
2405 if (cursor.pos() == cursor.par()->size()) {
2406 lt->cursorRight(bv_);
2407 cursor = lt->cursor;
2408 if (cursor.pos() == 0
2409 && !(cursor.par()->params().spaceTop()
2410 == VSpace (VSpace::NONE))) {
2413 cursor.par()->params().lineTop(),
2414 cursor.par()->params().lineBottom(),
2415 cursor.par()->params().pagebreakTop(),
2416 cursor.par()->params().pagebreakBottom(),
2417 VSpace(VSpace::NONE),
2418 cursor.par()->params().spaceBottom(),
2419 cursor.par()->params().spacing(),
2420 cursor.par()->params().align(),
2421 cursor.par()->params().labelWidthString(), 0);
2422 lt->cursorLeft(bv_);
2425 | BufferView::FITCUR
2426 | BufferView::CHANGE);
2428 lt->cursorLeft(bv_);
2430 lt->selection.cursor = lt->cursor;
2433 | BufferView::FITCUR
2434 | BufferView::CHANGE);
2438 lt->selection.cursor = lt->cursor;
2441 | BufferView::FITCUR
2442 | BufferView::CHANGE);
2450 /* -------> Delete word forward. */
2451 case LFUN_DELETE_WORD_FORWARD:
2452 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2453 bv_->getLyXText()->deleteWordForward(bv_);
2454 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2455 moveCursorUpdate(false);
2456 owner_->view_state_changed();
2459 /* -------> Delete word backward. */
2460 case LFUN_DELETE_WORD_BACKWARD:
2462 LyXText * lt = bv_->getLyXText();
2464 update(lt, BufferView::SELECT|BufferView::FITCUR);
2465 lt->deleteWordBackward(bv_);
2468 | BufferView::FITCUR
2469 | BufferView::CHANGE);
2470 moveCursorUpdate(false);
2471 owner_->view_state_changed();
2475 /* -------> Kill to end of line. */
2476 case LFUN_DELETE_LINE_FORWARD:
2478 LyXText * lt = bv_->getLyXText();
2480 update(lt, BufferView::SELECT|BufferView::FITCUR);
2481 lt->deleteLineForward(bv_);
2484 | BufferView::FITCUR
2485 | BufferView::CHANGE);
2486 moveCursorUpdate(false);
2490 /* -------> Set mark off. */
2493 LyXText * lt = bv_->getLyXText();
2496 update(lt, BufferView::SELECT|BufferView::FITCUR);
2497 lt->selection.cursor = lt->cursor;
2498 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2502 /* -------> Set mark on. */
2505 LyXText * lt = bv_->getLyXText();
2508 lt->selection.mark(true);
2509 update(lt, BufferView::SELECT|BufferView::FITCUR);
2510 lt->selection.cursor = lt->cursor;
2511 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2515 case LFUN_BACKSPACE:
2517 LyXText * lt = bv_->getLyXText();
2519 if (!lt->selection.set()) {
2520 if (owner_->getIntl()->getTransManager().backspace()) {
2522 lt->selection.cursor = lt->cursor;
2525 | BufferView::FITCUR
2526 | BufferView::CHANGE);
2527 // It is possible to make it a lot faster still
2528 // just comment out the line below...
2534 owner_->view_state_changed();
2539 case LFUN_BACKSPACE_SKIP:
2541 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2542 LyXText * lt = bv_->getLyXText();
2544 LyXCursor cursor = lt->cursor;
2546 if (!lt->selection.set()) {
2547 if (cursor.pos() == 0
2548 && !(cursor.par()->params().spaceTop()
2549 == VSpace (VSpace::NONE))) {
2552 cursor.par()->params().lineTop(),
2553 cursor.par()->params().lineBottom(),
2554 cursor.par()->params().pagebreakTop(),
2555 cursor.par()->params().pagebreakBottom(),
2556 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2557 cursor.par()->params().spacing(),
2558 cursor.par()->params().align(),
2559 cursor.par()->params().labelWidthString(), 0);
2562 | BufferView::FITCUR
2563 | BufferView::CHANGE);
2566 lt->selection.cursor = cursor;
2569 | BufferView::FITCUR
2570 | BufferView::CHANGE);
2577 case LFUN_BREAKPARAGRAPH:
2579 LyXText * lt = bv_->getLyXText();
2582 lt->breakParagraph(bv_, 0);
2585 | BufferView::FITCUR
2586 | BufferView::CHANGE);
2587 lt->selection.cursor = lt->cursor;
2589 owner_->view_state_changed();
2593 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2595 LyXText * lt = bv_->getLyXText();
2598 lt->breakParagraph(bv_, 1);
2601 | BufferView::FITCUR
2602 | BufferView::CHANGE);
2603 lt->selection.cursor = lt->cursor;
2605 owner_->view_state_changed();
2609 case LFUN_BREAKPARAGRAPH_SKIP:
2611 // When at the beginning of a paragraph, remove
2612 // indentation and add a "defskip" at the top.
2613 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2614 LyXText * lt = bv_->getLyXText();
2616 LyXCursor cursor = lt->cursor;
2619 if (cursor.pos() == 0) {
2620 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2623 cursor.par()->params().lineTop(),
2624 cursor.par()->params().lineBottom(),
2625 cursor.par()->params().pagebreakTop(),
2626 cursor.par()->params().pagebreakBottom(),
2627 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2628 cursor.par()->params().spacing(),
2629 cursor.par()->params().align(),
2630 cursor.par()->params().labelWidthString(), 1);
2631 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2635 lt->breakParagraph(bv_, 0);
2636 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2641 | BufferView::FITCUR
2642 | BufferView::CHANGE);
2643 lt->selection.cursor = cursor;
2645 owner_->view_state_changed();
2649 case LFUN_PARAGRAPH_SPACING:
2651 LyXText * lt = bv_->getLyXText();
2653 Paragraph * par = lt->cursor.par();
2654 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2655 float cur_value = 1.0;
2656 if (cur_spacing == Spacing::Other) {
2657 cur_value = par->params().spacing().getValue();
2660 istringstream istr(argument.c_str());
2664 Spacing::Space new_spacing = cur_spacing;
2665 float new_value = cur_value;
2667 lyxerr << "Missing argument to `paragraph-spacing'"
2669 } else if (tmp == "single") {
2670 new_spacing = Spacing::Single;
2671 } else if (tmp == "onehalf") {
2672 new_spacing = Spacing::Onehalf;
2673 } else if (tmp == "double") {
2674 new_spacing = Spacing::Double;
2675 } else if (tmp == "other") {
2676 new_spacing = Spacing::Other;
2679 lyxerr << "new_value = " << tmpval << endl;
2682 } else if (tmp == "default") {
2683 new_spacing = Spacing::Default;
2685 lyxerr << _("Unknown spacing argument: ")
2686 << argument << endl;
2688 if (cur_spacing != new_spacing || cur_value != new_value) {
2689 par->params().spacing(Spacing(new_spacing, new_value));
2690 lt->redoParagraph(bv_);
2693 | BufferView::FITCUR
2694 | BufferView::CHANGE);
2699 case LFUN_INSET_TOGGLE:
2701 LyXText * lt = bv_->getLyXText();
2704 update(lt, BufferView::SELECT|BufferView::FITCUR);
2705 lt->toggleInset(bv_);
2706 update(lt, BufferView::SELECT|BufferView::FITCUR);
2718 InsetCommandParams p;
2719 if (action == LFUN_HTMLURL)
2720 p.setCmdName("htmlurl");
2722 p.setCmdName("url");
2723 owner_->getDialogs()->createUrl(p.getAsString());
2727 case LFUN_INSERT_URL:
2729 InsetCommandParams p;
2730 p.setFromString(argument);
2732 InsetUrl * inset = new InsetUrl(p);
2733 if (!insertInset(inset))
2736 updateInset(inset, true);
2740 case LFUN_INSET_ERT:
2741 insertAndEditInset(new InsetERT(buffer_->params));
2744 case LFUN_INSET_EXTERNAL:
2745 insertAndEditInset(new InsetExternal);
2748 case LFUN_INSET_FOOTNOTE:
2749 insertAndEditInset(new InsetFoot(buffer_->params));
2752 case LFUN_INSET_MARGINAL:
2753 insertAndEditInset(new InsetMarginal(buffer_->params));
2756 case LFUN_INSET_MINIPAGE:
2757 insertAndEditInset(new InsetMinipage(buffer_->params));
2760 case LFUN_INSERT_NOTE:
2761 insertAndEditInset(new InsetNote(buffer_->params));
2764 case LFUN_INSET_FLOAT:
2765 // check if the float type exist
2766 if (floatList.typeExist(argument)) {
2767 insertAndEditInset(new InsetFloat(buffer_->params,
2770 lyxerr << "Non-existent float type: "
2771 << argument << endl;
2775 case LFUN_INSET_WIDE_FLOAT:
2776 // check if the float type exist
2777 if (floatList.typeExist(argument)) {
2778 InsetFloat * new_inset =
2779 new InsetFloat(buffer_->params, argument);
2780 new_inset->wide(true);
2781 insertAndEditInset(new_inset);
2783 lyxerr << "Non-existent float type: "
2784 << argument << endl;
2789 case LFUN_INSET_LIST:
2790 insertAndEditInset(new InsetList);
2793 case LFUN_INSET_THEOREM:
2794 insertAndEditInset(new InsetTheorem);
2798 case LFUN_INSET_CAPTION:
2800 // Do we have a locking inset...
2801 if (bv_->theLockingInset()) {
2802 lyxerr << "Locking inset code: "
2803 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2804 InsetCaption * new_inset =
2805 new InsetCaption(buffer_->params);
2806 new_inset->setOwner(bv_->theLockingInset());
2807 new_inset->setAutoBreakRows(true);
2808 new_inset->setDrawFrame(0, InsetText::LOCKED);
2809 new_inset->setFrameColor(0, LColor::captionframe);
2810 if (insertInset(new_inset))
2811 new_inset->edit(bv_);
2818 case LFUN_TABULAR_INSERT:
2820 if (argument.empty()) {
2821 owner_->getDialogs()->showTabularCreate();
2827 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2828 InsetTabular * new_inset =
2829 new InsetTabular(*buffer_, r, c);
2831 bv_->getLyXText()->real_current_font.isRightToLeft();
2832 if (!open_new_inset(new_inset, rtl))
2837 // --- lyxserver commands ----------------------------
2839 case LFUN_CHARATCURSOR:
2841 pos_type pos = bv_->getLyXText()->cursor.pos();
2842 if (pos < bv_->getLyXText()->cursor.par()->size())
2843 owner_->getLyXFunc()->setMessage(
2844 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2846 owner_->getLyXFunc()->setMessage("EOF");
2851 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2853 + tostr(bv_->getLyXText()->cursor.y()));
2860 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2861 lyxerr << "SETXY: Could not parse coordinates in '"
2862 << argument << std::endl;
2864 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2868 case LFUN_GETLAYOUT:
2869 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2874 LyXFont & font = bv_->getLyXText()->current_font;
2875 if (font.shape() == LyXFont::ITALIC_SHAPE)
2876 owner_->getLyXFunc()->setMessage("E");
2877 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2878 owner_->getLyXFunc()->setMessage("N");
2880 owner_->getLyXFunc()->setMessage("0");
2885 // --- accented characters ---------------------------
2888 case LFUN_CIRCUMFLEX:
2898 case LFUN_SPECIAL_CARON:
2901 case LFUN_HUNG_UMLAUT:
2904 if (argument.empty()) {
2906 owner_->getLyXFunc()->handleKeyFunc(action);
2908 owner_->getLyXFunc()->handleKeyFunc(action);
2909 owner_->getIntl()->getTransManager()
2910 .TranslateAndInsert(argument[0], bv_->getLyXText());
2911 update(bv_->getLyXText(),
2913 | BufferView::FITCUR
2914 | BufferView::CHANGE);
2919 mathDispatch(bv_, argument);
2922 case LFUN_MATH_MACRO:
2923 mathDispatchMathMacro(bv_, argument);
2926 case LFUN_MATH_DELIM:
2927 mathDispatchMathDelim(bv_, argument);
2930 case LFUN_INSERT_MATRIX:
2931 mathDispatchInsertMatrix(bv_, argument);
2934 case LFUN_INSERT_MATH:
2935 mathDispatchInsertMath(bv_, argument);
2938 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2939 mathDispatchMathImportSelection(bv_, argument);
2942 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2943 mathDispatchMathDisplay(bv_, argument);
2946 case LFUN_MATH_MODE: // Open or create an inlined math inset
2947 mathDispatchMathMode(bv_, argument);
2950 case LFUN_GREEK: // Insert a single greek letter
2951 mathDispatchGreek(bv_, argument);
2954 case LFUN_CITATION_INSERT:
2956 InsetCommandParams p;
2957 p.setFromString(argument);
2959 InsetCitation * inset = new InsetCitation(p);
2960 if (!insertInset(inset))
2963 updateInset(inset, true);
2967 case LFUN_INSERT_BIBTEX:
2969 // ale970405+lasgoutt970425
2970 // The argument can be up to two tokens separated
2971 // by a space. The first one is the bibstyle.
2972 string const db = token(argument, ' ', 0);
2973 string const bibstyle = token(argument, ' ', 1);
2975 InsetCommandParams p("BibTeX", db, bibstyle);
2976 InsetBibtex * inset = new InsetBibtex(p);
2978 if (insertInset(inset)) {
2979 if (argument.empty())
2986 // BibTeX data bases
2987 case LFUN_BIBDB_ADD:
2989 InsetBibtex * inset =
2990 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2992 inset->addDatabase(argument);
2997 case LFUN_BIBDB_DEL:
2999 InsetBibtex * inset =
3000 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3002 inset->delDatabase(argument);
3007 case LFUN_BIBTEX_STYLE:
3009 InsetBibtex * inset =
3010 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3012 inset->setOptions(argument);
3017 case LFUN_INDEX_INSERT:
3019 string entry = argument;
3020 if (entry.empty()) {
3021 entry = bv_->getLyXText()->getStringToIndex(bv_);
3024 if (entry.empty()) {
3025 owner_->getDialogs()->createIndex();
3029 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3031 if (!insertInset(inset)) {
3034 updateInset(inset, true);
3039 case LFUN_INDEX_PRINT:
3041 InsetCommandParams p("printindex");
3042 Inset * inset = new InsetPrintIndex(p);
3043 if (!insertInset(inset, tclass.defaultLayoutName()))
3048 case LFUN_PARENTINSERT:
3050 InsetCommandParams p("lyxparent", argument);
3051 Inset * inset = new InsetParent(p, *buffer_);
3052 if (!insertInset(inset, tclass.defaultLayoutName()))
3058 case LFUN_CHILD_INSERT:
3060 InsetInclude::Params p;
3061 p.cparams.setFromString(argument);
3062 p.masterFilename_ = buffer_->fileName();
3064 InsetInclude * inset = new InsetInclude(p);
3065 if (!insertInset(inset))
3068 updateInset(inset, true);
3069 bv_->owner()->getDialogs()->showInclude(inset);
3074 case LFUN_FLOAT_LIST:
3075 if (floatList.typeExist(argument)) {
3076 Inset * inset = new InsetFloatList(argument);
3077 if (!insertInset(inset, tclass.defaultLayoutName()))
3080 lyxerr << "Non-existent float type: "
3081 << argument << endl;
3085 case LFUN_THESAURUS_ENTRY:
3087 string arg = argument;
3090 arg = bv_->getLyXText()->selectionAsString(buffer_,
3094 if (arg.size() > 100 || arg.empty()) {
3095 // Get word or selection
3096 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3097 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3098 // FIXME: where is getLyXText()->unselect(bv_) ?
3102 bv_->owner()->getDialogs()->showThesaurus(arg);
3106 case LFUN_SELFINSERT:
3108 if (argument.empty()) break;
3110 /* Automatically delete the currently selected
3111 * text and replace it with what is being
3112 * typed in now. Depends on lyxrc settings
3113 * "auto_region_delete", which defaults to
3116 LyXText * lt = bv_->getLyXText();
3118 if (lyxrc.auto_region_delete) {
3119 if (lt->selection.set()) {
3120 lt->cutSelection(bv_, false, false);
3123 | BufferView::FITCUR
3124 | BufferView::CHANGE);
3126 workarea().haveSelection(false);
3130 LyXFont const old_font(lt->real_current_font);
3132 string::const_iterator cit = argument.begin();
3133 string::const_iterator end = argument.end();
3134 for (; cit != end; ++cit) {
3135 owner_->getIntl()->getTransManager().
3136 TranslateAndInsert(*cit, lt);
3141 | BufferView::FITCUR
3142 | BufferView::CHANGE);
3144 lt->selection.cursor = lt->cursor;
3145 moveCursorUpdate(false);
3147 // real_current_font.number can change so we need to
3148 // update the minibuffer
3149 if (old_font != lt->real_current_font)
3150 owner_->view_state_changed();
3155 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3157 time_t now_time_t = time(NULL);
3158 struct tm * now_tm = localtime(&now_time_t);
3159 setlocale(LC_TIME, "");
3161 if (!argument.empty())
3164 arg = lyxrc.date_insert_format;
3166 int const datetmp_len =
3167 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3169 LyXText * lt = bv_->getLyXText();
3171 for (int i = 0; i < datetmp_len; i++) {
3172 lt->insertChar(bv_, datetmp[i]);
3175 | BufferView::FITCUR
3176 | BufferView::CHANGE);
3179 lt->selection.cursor = lt->cursor;
3180 moveCursorUpdate(false);
3184 case LFUN_UNKNOWN_ACTION:
3185 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3196 void BufferView::Pimpl::newline()
3199 LyXText * lt = bv_->getLyXText();
3203 | BufferView::FITCUR);
3204 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3207 | BufferView::FITCUR
3208 | BufferView::CHANGE);
3213 void BufferView::Pimpl::hfill()
3216 LyXText * lt = bv_->getLyXText();
3220 | BufferView::FITCUR);
3221 lt->insertChar(bv_, Paragraph::META_HFILL);
3224 | BufferView::FITCUR
3225 | BufferView::CHANGE);
3230 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3233 LyXText * lt = bv_->getLyXText();
3236 update(lt, BufferView::SELECT|BufferView::FITCUR);
3237 InsetSpecialChar * new_inset =
3238 new InsetSpecialChar(kind);
3239 if (!insertInset(new_inset))
3242 updateInset(new_inset, true);
3247 void BufferView::Pimpl::smartQuote()
3249 LyXText const * lt = bv_->getLyXText();
3250 Paragraph const * par = lt->cursor.par();
3251 pos_type pos = lt->cursor.pos();
3255 || (par->isInset(pos - 1)
3256 && par->getInset(pos - 1)->isSpace()))
3259 c = par->getChar(pos - 1);
3264 LyXLayout_ptr const & style = par->layout();
3266 if (style->pass_thru ||
3267 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3268 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, string("\""));
3272 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3275 if (insertInset(inset))
3280 bool gotsel = false;
3282 if (bv_->getLyXText()->selection.set()) {
3283 bv_->getLyXText()->cutSelection(bv_, true, false);
3287 if (insertInset(inset)) {
3290 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3298 // Open and lock an updatable inset
3299 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3301 LyXText * lt = bv_->getLyXText();
3305 if (!insertInset(new_inset)) {
3309 new_inset->edit(bv_, !behind);
3314 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3316 // if we are in a locking inset we should try to insert the
3317 // inset there otherwise this is a illegal function now
3318 if (bv_->theLockingInset()) {
3319 if (bv_->theLockingInset()->insetAllowed(inset))
3320 return bv_->theLockingInset()->insertInset(bv_, inset);
3324 // not quite sure if we want this...
3325 setCursorParUndo(bv_);
3328 beforeChange(bv_->text);
3329 if (!lout.empty()) {
3330 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3331 bv_->text->breakParagraph(bv_);
3332 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3334 if (bv_->text->cursor.par()->size()) {
3335 bv_->text->cursorLeft(bv_);
3337 bv_->text->breakParagraph(bv_);
3338 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3342 LyXTextClass const & tclass =
3343 buffer_->params.getLyXTextClass();
3344 bool hasLayout = tclass.hasLayout(lres);
3345 string lay = tclass.defaultLayoutName();
3347 if (hasLayout != false) {
3351 // layout not fount using default
3352 lay = tclass.defaultLayoutName();
3355 bv_->text->setLayout(bv_, lay);
3357 bv_->text->setParagraph(bv_, 0, 0,
3359 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3364 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 bv_->text->insertInset(bv_, inset);
3368 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3375 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3377 if (!inset || !available())
3380 // first check for locking insets
3381 if (bv_->theLockingInset()) {
3382 if (bv_->theLockingInset() == inset) {
3383 if (bv_->text->updateInset(bv_, inset)) {
3386 buffer_->markDirty();
3391 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3392 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3395 buffer_->markDirty();
3403 // then check if the inset is a top_level inset (has no owner)
3404 // if yes do the update as always otherwise we have to update the
3405 // toplevel inset where this inset is inside
3406 Inset * tl_inset = inset;
3407 while(tl_inset->owner())
3408 tl_inset = tl_inset->owner();
3410 if (tl_inset == inset) {
3411 update(bv_->text, BufferView::UPDATE);
3412 if (bv_->text->updateInset(bv_, inset)) {
3416 | BufferView::FITCUR
3417 | BufferView::CHANGE);
3419 update(bv_->text, SELECT);
3423 } else if (static_cast<UpdatableInset *>(tl_inset)
3424 ->updateInsetInInset(bv_, inset))
3426 if (bv_->text->updateInset(bv_, tl_inset)) {
3434 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3437 if (!available()) return;
3440 beforeChange(bv_->text);
3441 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3443 LyXCursor const & cursor = bv_->text->cursor;
3447 cursor.par()->isInset(cursor.pos())) {
3448 Inset const * inset = cursor.par()->getInset(cursor.pos());
3449 if (find(codes.begin(), codes.end(), inset->lyxCode())
3452 static_cast<InsetCommand const *>(inset)->getContents();
3456 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3457 if (bv_->text->cursor.pos()
3458 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3459 LyXCursor tmp = bv_->text->cursor;
3460 bv_->text->cursor.par(bv_->text->ownerParagraph());
3461 bv_->text->cursor.pos(0);
3462 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3463 bv_->text->cursor = tmp;
3464 bv_->owner()->message(_("No more insets"));
3467 bv_->owner()->message(_("No more insets"));
3470 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3471 bv_->text->selection.cursor = bv_->text->cursor;
3475 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3477 gotoInset(vector<Inset::Code>(1, code), same_content);