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"
42 #include "funcrequest.h"
44 #include "insets/insetbib.h"
45 #include "insets/insettext.h"
46 #include "insets/inseturl.h"
47 #include "insets/insetlatexaccent.h"
48 #include "insets/insettoc.h"
49 #include "insets/insetref.h"
50 #include "insets/insetparent.h"
51 #include "insets/insetindex.h"
52 #include "insets/insetnote.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetert.h"
56 #include "insets/insetexternal.h"
57 #include "insets/insetgraphics.h"
58 #include "insets/insetfoot.h"
59 #include "insets/insetmarginal.h"
60 #include "insets/insetminipage.h"
61 #include "insets/insetfloat.h"
62 #include "insets/insettabular.h"
64 #include "insets/insettheorem.h"
65 #include "insets/insetlist.h"
67 #include "insets/insetcaption.h"
68 #include "insets/insetfloatlist.h"
69 #include "insets/insetspecialchar.h"
71 #include "mathed/formulabase.h"
73 #include "graphics/Previews.h"
75 #include "support/LAssert.h"
76 #include "support/lstrings.h"
77 #include "support/filetools.h"
78 #include "support/lyxfunctional.h"
80 #include <boost/bind.hpp>
81 #include <boost/signals/connection.hpp>
90 extern string current_layout;
92 #ifndef CXX_GLOBAL_CSTD
105 using std::make_pair;
109 using lyx::textclass_type;
111 /* the selection possible is needed, that only motion events are
112 * used, where the bottom press event was on the drawing area too */
113 bool selection_possible = false;
115 extern BufferList bufferlist;
116 extern char ascii_type;
118 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
123 unsigned int const saved_positions_num = 20;
125 // All the below connection objects are needed because of a bug in some
126 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
127 // to these connections we avoid a segfault upon startup, and also at exit.
130 boost::signals::connection timecon;
131 boost::signals::connection doccon;
132 boost::signals::connection resizecon;
133 boost::signals::connection bpresscon;
134 boost::signals::connection breleasecon;
135 boost::signals::connection motioncon;
136 boost::signals::connection doublecon;
137 boost::signals::connection triplecon;
138 boost::signals::connection kpresscon;
139 boost::signals::connection selectioncon;
140 boost::signals::connection lostcon;
145 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
146 int xpos, int ypos, int width, int height)
147 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
148 using_xterm_cursor(false)
150 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
151 screen_.reset(LyXScreenFactory::create(workarea()));
154 doccon = workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
155 resizecon = workarea().workAreaResize
156 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
157 bpresscon = workarea().workAreaButtonPress
158 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
159 breleasecon = workarea().workAreaButtonRelease
160 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
161 motioncon = workarea().workAreaMotionNotify
162 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
163 doublecon = workarea().workAreaDoubleClick
164 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
165 triplecon = workarea().workAreaTripleClick
166 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
167 kpresscon = workarea().workAreaKeyPress
168 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
169 selectioncon = workarea().selectionRequested
170 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
171 lostcon = workarea().selectionLost
172 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
174 timecon = cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
175 cursor_timeout.start();
176 saved_positions.resize(saved_positions_num);
180 WorkArea & BufferView::Pimpl::workarea() const
182 return *workarea_.get();
186 LyXScreen & BufferView::Pimpl::screen() const
188 return *screen_.get();
192 Painter & BufferView::Pimpl::painter() const
194 return workarea().getPainter();
198 void BufferView::Pimpl::buffer(Buffer * b)
200 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
203 buffer_->delUser(bv_);
205 // Put the old text into the TextCache, but
206 // only if the buffer is still loaded.
207 // Also set the owner of the test to 0
208 // bv_->text->owner(0);
209 textcache.add(buffer_, workarea().workWidth(), bv_->text);
210 if (lyxerr.debugging())
211 textcache.show(lyxerr, "BufferView::buffer");
216 // Set current buffer
219 if (bufferlist.getState() == BufferList::CLOSING) return;
221 // If we are closing the buffer, use the first buffer as current
223 buffer_ = bufferlist.first();
227 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
228 buffer_->addUser(bv_);
230 // If we don't have a text object for this, we make one
231 if (bv_->text == 0) {
232 resizeCurrentBuffer();
235 // FIXME: needed when ?
236 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
238 // Similarly, buffer-dependent dialogs should be updated or
239 // hidden. This should go here because some dialogs (eg ToC)
240 // require bv_->text.
241 owner_->getDialogs()->updateBufferDependent(true);
243 lyxerr[Debug::INFO] << " No Buffer!" << endl;
244 owner_->getDialogs()->hideBufferDependent();
246 // Also remove all remaining text's from the testcache.
247 // (there should not be any!) (if there is any it is a
249 if (lyxerr.debugging())
250 textcache.show(lyxerr, "buffer delete all");
256 owner_->updateMenubar();
257 owner_->updateToolbar();
258 owner_->updateLayoutChoice();
259 owner_->updateWindowTitle();
261 if (grfx::Previews::activated() && buffer_)
262 grfx::Previews::get().generateBufferPreviews(*buffer_);
266 bool BufferView::Pimpl::fitCursor()
270 if (bv_->theLockingInset()) {
271 bv_->theLockingInset()->fitInsetCursor(bv_);
274 ret = screen().fitCursor(bv_->text, bv_);
277 bv_->owner()->getDialogs()->updateParagraph();
284 void BufferView::Pimpl::redoCurrentBuffer()
286 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
287 if (buffer_ && bv_->text) {
288 resizeCurrentBuffer();
290 owner_->updateLayoutChoice();
296 int BufferView::Pimpl::resizeCurrentBuffer()
298 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
301 Paragraph * selstartpar = 0;
302 Paragraph * selendpar = 0;
303 UpdatableInset * the_locking_inset = 0;
306 pos_type selstartpos = 0;
307 pos_type selendpos = 0;
308 bool selection = false;
309 bool mark_set = false;
311 owner_->prohibitInput();
313 owner_->message(_("Formatting document..."));
316 par = bv_->text->cursor.par();
317 pos = bv_->text->cursor.pos();
318 selstartpar = bv_->text->selection.start.par();
319 selstartpos = bv_->text->selection.start.pos();
320 selendpar = bv_->text->selection.end.par();
321 selendpos = bv_->text->selection.end.pos();
322 selection = bv_->text->selection.set();
323 mark_set = bv_->text->selection.mark();
324 the_locking_inset = bv_->theLockingInset();
325 buffer_->resizeInsets(bv_);
326 // I don't think the delete and new are necessary here we just could
327 // call only init! (Jug 20020419)
329 bv_->text = new LyXText(bv_);
330 bv_->text->init(bv_);
332 // See if we have a text in TextCache that fits
333 // the new buffer_ with the correct width.
334 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
336 if (lyxerr.debugging()) {
337 lyxerr << "Found a LyXText that fits:\n";
338 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
340 // Set the owner of the newly found text
341 // bv_->text->owner(bv_);
342 if (lyxerr.debugging())
343 textcache.show(lyxerr, "resizeCurrentBuffer");
345 bv_->text = new LyXText(bv_);
346 bv_->text->init(bv_);
347 //buffer_->resizeInsets(bv_);
352 bv_->text->selection.set(true);
353 // At this point just to avoid the Delete-Empty-Paragraph-
354 // Mechanism when setting the cursor.
355 bv_->text->selection.mark(mark_set);
357 bv_->text->setCursor(bv_, selstartpar, selstartpos);
358 bv_->text->selection.cursor = bv_->text->cursor;
359 bv_->text->setCursor(bv_, selendpar, selendpos);
360 bv_->text->setSelection(bv_);
361 bv_->text->setCursor(bv_, par, pos);
363 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->selection.cursor = bv_->text->cursor;
365 bv_->text->selection.set(false);
367 // remake the inset locking
368 bv_->theLockingInset(the_locking_inset);
371 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
374 owner_->allowInput();
382 void BufferView::Pimpl::repaint()
384 // Regenerate the screen.
385 screen().redraw(bv_->text, bv_);
389 void BufferView::Pimpl::updateScrollbar()
392 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
393 workarea().setScrollbarParams(0, 0, 0);
397 LyXText const & t = *bv_->text;
399 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
400 << t.first_y << ", default height " << t.defaultHeight() << endl;
402 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
406 void BufferView::Pimpl::scrollDocView(int value)
408 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
410 if (!buffer_) return;
412 screen().draw(bv_->text, bv_, value);
414 if (!lyxrc.cursor_follows_scrollbar) {
418 LyXText * vbt = bv_->text;
420 int const height = vbt->defaultHeight();
421 int const first = static_cast<int>((bv_->text->first_y + height));
422 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
424 if (vbt->cursor.y() < first)
425 vbt->setCursorFromCoordinates(bv_, 0, first);
426 else if (vbt->cursor.y() > last)
427 vbt->setCursorFromCoordinates(bv_, 0, last);
431 int BufferView::Pimpl::scroll(long time)
436 LyXText const * t = bv_->text;
438 double const diff = t->defaultHeight()
439 + double(time) * double(time) * 0.125;
441 scrollDocView(int(diff));
442 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
447 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
448 key_modifier::state state)
450 bv_->owner()->getLyXFunc()->processKeySym(key, state);
454 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
456 // Only use motion with button 1
457 if (!(state & mouse_button::button1))
463 // Check for inset locking
464 if (bv_->theLockingInset()) {
465 LyXCursor cursor = bv_->text->cursor;
466 LyXFont font = bv_->text->getFont(buffer_,
467 cursor.par(), cursor.pos());
468 int width = bv_->theLockingInset()->width(bv_, font);
469 int inset_x = font.isVisibleRightToLeft()
470 ? cursor.ix() - width : cursor.ix();
471 int start_x = inset_x + bv_->theLockingInset()->scroll();
473 bv_->theLockingInset()->
474 insetMotionNotify(bv_,
476 y - cursor.iy() + bv_->text->first_y,
481 /* The test for not selection possible is needed, that only motion
482 events are used, where the bottom press event was on
483 the drawing area too */
484 if (!selection_possible)
487 screen().hideCursor();
489 Row * cursorrow = bv_->text->cursor.row();
490 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
492 // sorry for this but I have a strange error that the y value jumps at
493 // a certain point. This seems like an error in my xforms library or
494 // in some other local environment, but I would like to leave this here
495 // for the moment until I can remove this (Jug 20020418)
496 if (y_before < bv_->text->cursor.y())
497 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
499 // This is to allow jumping over large insets
500 if (cursorrow == bv_->text->cursor.row()) {
501 if (y >= int(workarea().workHeight())) {
502 bv_->text->cursorDown(bv_, false);
504 bv_->text->cursorUp(bv_, false);
508 if (!bv_->text->selection.set())
509 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
511 bv_->text->setSelection(bv_);
512 screen().toggleToggle(bv_->text, bv_);
518 // Single-click on work area
519 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
520 mouse_button::state button)
525 // ok ok, this is a hack (for xforms)
526 if (button == mouse_button::button4) {
527 scroll(-lyxrc.wheel_jump);
528 // We shouldn't go further down as we really should only do the
529 // scrolling and be done with this. Otherwise we may open some
530 // dialogs (Jug 20020424).
532 } else if (button == mouse_button::button5) {
533 scroll(lyxrc.wheel_jump);
534 // We shouldn't go further down as we really should only do the
535 // scrolling and be done with this. Otherwise we may open some
536 // dialogs (Jug 20020424).
540 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
542 // Middle button press pastes if we have a selection
543 // We do this here as if the selection was inside an inset
544 // it could get cleared on the unlocking of the inset so
545 // we have to check this first
546 bool paste_internally = false;
547 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
548 owner_->getLyXFunc()->dispatch(LFUN_COPY);
549 paste_internally = true;
552 int const screen_first = bv_->text->first_y;
554 if (bv_->theLockingInset()) {
555 // We are in inset locking mode
557 /* Check whether the inset was hit. If not reset mode,
558 otherwise give the event to the inset */
559 if (inset_hit == bv_->theLockingInset()) {
560 bv_->theLockingInset()->
561 insetButtonPress(bv_, xpos, ypos, button);
564 bv_->unlockInset(bv_->theLockingInset());
569 selection_possible = true;
570 screen().hideCursor();
572 // Clear the selection
573 screen().toggleSelection(bv_->text, bv_);
574 bv_->text->clearSelection();
575 bv_->text->fullRebreak(bv_);
579 // Single left click in math inset?
580 if (isHighlyEditableInset(inset_hit)) {
581 // Highly editable inset, like math
582 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
583 selection_possible = false;
584 owner_->updateLayoutChoice();
585 owner_->message(inset->editMessage());
586 //inset->edit(bv_, xpos, ypos, button);
587 // We just have to lock the inset before calling a PressEvent on it!
588 // we don't need the edit() call here! (Jug20020329)
589 if (!bv_->lockInset(inset)) {
590 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
592 inset->insetButtonPress(bv_, xpos, ypos, button);
595 // I'm not sure we should continue here if we hit an inset (Jug20020403)
597 // Right click on a footnote flag opens float menu
598 if (button == mouse_button::button3) {
599 selection_possible = false;
603 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
604 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
606 bv_->text->selection.cursor = bv_->text->cursor;
607 bv_->text->cursor.x_fix(bv_->text->cursor.x());
609 owner_->updateLayoutChoice();
611 selection_possible = false;
614 // Insert primary selection with middle mouse
615 // if there is a local selection in the current buffer,
617 if (button == mouse_button::button2) {
618 if (paste_internally)
619 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
621 owner_->getLyXFunc()->dispatch(FuncRequest(LFUN_PASTESELECTION, "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);
650 workarea().haveSelection(bv_->getLyXText()->selection.set());
655 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
660 LyXText * text = bv_->getLyXText();
662 if (text->bv_owner && bv_->theLockingInset())
665 if (button == mouse_button::button1) {
666 if (text->bv_owner) {
667 screen().hideCursor();
668 screen().toggleSelection(text, bv_);
670 text->cursorHome(bv_);
671 text->selection.cursor = text->cursor;
672 text->cursorEnd(bv_);
673 text->setSelection(bv_);
674 if (text->bv_owner) {
675 screen().toggleSelection(text, bv_, false);
677 /* This will fit the cursor on the screen
679 update(text, BufferView::SELECT|BufferView::FITCUR);
680 workarea().haveSelection(bv_->getLyXText()->selection.set());
685 void BufferView::Pimpl::selectionRequested()
692 LyXText * text = bv_->getLyXText();
694 if (text->selection.set() &&
695 (!bv_->text->xsel_cache.set() ||
696 text->selection.start != bv_->text->xsel_cache.start ||
697 text->selection.end != bv_->text->xsel_cache.end))
699 bv_->text->xsel_cache = text->selection;
700 sel = text->selectionAsString(bv_->buffer(), false);
701 } else if (!text->selection.set()) {
703 bv_->text->xsel_cache.set(false);
706 workarea().putClipboard(sel);
711 void BufferView::Pimpl::selectionLost()
716 bv_->getLyXText()->clearSelection();
718 bv_->text->xsel_cache.set(false);
723 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
724 mouse_button::state button)
726 // do nothing if we used the mouse wheel
727 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
730 // If we hit an inset, we have the inset coordinates in these
731 // and inset_hit points to the inset. If we do not hit an
732 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
733 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
735 if (bv_->theLockingInset()) {
736 // We are in inset locking mode.
738 /* LyX does a kind of work-area grabbing for insets.
739 Only a ButtonPress FuncRequest outside the inset will
740 force a insetUnlock. */
741 bv_->theLockingInset()->
742 insetButtonRelease(bv_, x, y, button);
746 selection_possible = false;
748 if (button == mouse_button::button2)
752 if (button == mouse_button::button1) {
753 workarea().haveSelection(bv_->getLyXText()->selection.set());
757 owner_->view_state_changed();
758 owner_->updateMenubar();
759 owner_->updateToolbar();
761 // Did we hit an editable inset?
763 selection_possible = false;
765 // if we reach this point with a selection, it
766 // must mean we are currently selecting.
767 // But we don't want to open the inset
768 // because that is annoying for the user.
769 // So just pretend we didn't hit it.
770 // this is OK because a "kosher" ButtonRelease
771 // will follow a ButtonPress that clears
773 // Note this also fixes selection drawing
774 // problems if we end up opening an inset
775 if (bv_->getLyXText()->selection.set())
778 // CHECK fix this proper in 0.13
779 // well, maybe 13.0 !!!!!!!!!
781 // Following a ref shouldn't issue
782 // a push on the undo-stack
783 // anylonger, now that we have
784 // keybindings for following
785 // references and returning from
786 // references. IMHO though, it
787 // should be the inset's own business
788 // to push or not push on the undo
789 // stack. They don't *have* to
790 // alter the document...
792 // ...or maybe the SetCursorParUndo()
793 // below isn't necessary at all anylonger?
794 if (inset_hit->lyxCode() == Inset::REF_CODE) {
795 setCursorParUndo(bv_);
798 owner_->message(inset_hit->editMessage());
800 if (isHighlyEditableInset(inset_hit)) {
801 // Highly editable inset, like math
802 UpdatableInset *inset = (UpdatableInset *)inset_hit;
803 inset->insetButtonRelease(bv_, x, y, button);
805 inset_hit->insetButtonRelease(bv_, x, y, button);
806 // IMO this is a grosshack! Inset's should be changed so that
807 // they call the actions they have to do with the insetButtonRel.
808 // function and not in the edit(). This should be changed
810 inset_hit->edit(bv_, x, y, button);
815 // Maybe we want to edit a bibitem ale970302
816 if (bv_->text->cursor.par()->bibkey) {
817 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
818 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
819 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
820 (!is_rtl && x < 20+width)) {
821 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
829 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
830 LyXCursor const & cursor) const
832 Paragraph /*const*/ & par = *cursor.par();
833 pos_type const pos = cursor.pos();
835 lyx::Assert(par.getInset(pos));
837 Inset const & inset(*par.getInset(pos));
839 LyXFont const & font = text.getFont(buffer_, &par, pos);
841 int const width = inset.width(bv_, font);
842 int const inset_x = font.isVisibleRightToLeft()
843 ? (cursor.ix() - width) : cursor.ix();
846 inset_x + inset.scroll(),
848 cursor.iy() - inset.ascent(bv_, font),
849 cursor.iy() + inset.descent(bv_, font));
853 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
854 LyXCursor const & cursor,
855 int & x, int & y) const
857 pos_type const pos(cursor.pos());
858 Paragraph /*const*/ & par(*cursor.par());
860 if (pos >= par.size() || !par.isInset(pos)) {
864 Inset /*const*/ * inset = par.getInset(pos);
866 if (!isEditableInset(inset)) {
870 Box b(insetDimensions(text, cursor));
872 if (!b.contained(x, y)) {
873 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
874 << " box " << b << endl;
878 text.setCursor(bv_, &par, pos, true);
881 // The origin of an inset is on the baseline
882 y -= text.cursor.iy();
888 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
890 int y_tmp = y + text->first_y;
893 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
895 Inset * inset(checkInset(*text, cursor, x, y_tmp));
902 // look at previous position
904 if (cursor.pos() == 0) {
909 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
911 inset = checkInset(*text, cursor, x, y_tmp);
919 void BufferView::Pimpl::workAreaResize()
921 static int work_area_width;
922 static int work_area_height;
924 bool const widthChange = workarea().workWidth() != work_area_width;
925 bool const heightChange = workarea().workHeight() != work_area_height;
927 // update from work area
928 work_area_width = workarea().workWidth();
929 work_area_height = workarea().workHeight();
933 // The visible LyXView need a resize
934 resizeCurrentBuffer();
936 // Remove all texts from the textcache
937 // This is not _really_ what we want to do. What
938 // we really want to do is to delete in textcache
939 // that does not have a BufferView with matching
940 // width, but as long as we have only one BufferView
941 // deleting all gives the same result.
942 if (lyxerr.debugging())
943 textcache.show(lyxerr, "Expose delete all");
945 // FIXME: this is aalready done in resizeCurrentBuffer() ??
946 buffer_->resizeInsets(bv_);
947 } else if (heightChange) {
948 // fitCursor() ensures we don't jump back
949 // to the start of the document on vertical
955 if (widthChange || heightChange) {
959 // always make sure that the scrollbar is sane.
961 owner_->updateLayoutChoice();
966 void BufferView::Pimpl::update()
968 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
969 LyXText::text_status st = bv_->text->status();
970 screen().update(bv_->text, bv_);
972 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
973 bv_->text->fullRebreak(bv_);
974 st = LyXText::NEED_MORE_REFRESH;
975 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
976 bv_->text->cursor.pos());
977 if (bv_->text->selection.set()) {
978 bv_->text->setCursor(bv_, bv_->text->selection.start,
979 bv_->text->selection.start.par(),
980 bv_->text->selection.start.pos());
981 bv_->text->setCursor(bv_, bv_->text->selection.end,
982 bv_->text->selection.end.par(),
983 bv_->text->selection.end.pos());
986 bv_->text->status(bv_, st);
987 screen().update(bv_->text, bv_);
989 // do this here instead of in the screen::update because of
991 bv_->text->status(bv_, LyXText::UNCHANGED);
997 // Values used when calling update:
999 // -2 - update, move sel_cursor if selection, fitcursor
1000 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1001 // 0 - update, move sel_cursor if selection, fitcursor
1002 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1003 // 3 - update, move sel_cursor if selection
1006 // a simple redraw of the parts that need refresh
1008 // move sel_cursor if selection -
1009 // the text's sel_cursor is moved if there is selection is progress
1012 // fitCursor() is called and the scrollbar updated
1015 // the buffer is marked dirty.
1024 // UPDATE_ONLY = UPDATE;
1025 // UPDATE_SELECT = UPDATE | SELECT;
1026 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1027 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1029 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1030 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1031 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1032 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1033 // update(3) -> update(1) -> update(1) -> update(SELECT)
1035 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1037 owner_->updateLayoutChoice();
1039 if (!text->selection.set() && (f & SELECT)) {
1040 text->selection.cursor = text->cursor;
1043 text->fullRebreak(bv_);
1045 if (text->inset_owner) {
1046 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1047 updateInset(text->inset_owner, false);
1057 buffer_->markDirty();
1062 // Callback for cursor timer
1063 void BufferView::Pimpl::cursorToggle()
1066 cursor_timeout.restart();
1071 extern void reapSpellchecker(void);
1074 if (!bv_->theLockingInset()) {
1075 screen().cursorToggle(bv_);
1077 bv_->theLockingInset()->toggleInsetCursor(bv_);
1080 cursor_timeout.restart();
1084 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1086 if (!text->cursor.row()->previous()) {
1087 if (text->first_y > 0) {
1088 int new_y = bv_->text->first_y - workarea().workHeight();
1089 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1095 int y = text->first_y;
1096 Row * cursorrow = text->cursor.row();
1098 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1102 if (cursorrow == bv_->text->cursor.row()) {
1103 // we have a row which is higher than the workarea so we leave the
1104 // cursor on the start of the row and move only the draw up as soon
1105 // as we move the cursor or do something while inside the row (it may
1106 // span several workarea-heights) we'll move to the top again, but this
1107 // is better than just jump down and only display part of the row.
1108 new_y = bv_->text->first_y - workarea().workHeight();
1110 if (text->inset_owner) {
1111 new_y = bv_->text->cursor.iy()
1112 + bv_->theLockingInset()->insetInInsetY() + y
1113 + text->cursor.row()->height()
1114 - workarea().workHeight() + 1;
1116 new_y = text->cursor.y()
1117 - text->cursor.row()->baseline()
1118 + text->cursor.row()->height()
1119 - workarea().workHeight() + 1;
1122 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1123 if (text->cursor.row()->previous()) {
1125 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1126 text->cursor.row()->previous()->pos(), false);
1127 if (cur.y() > text->first_y) {
1128 text->cursorUp(bv_, true);
1135 void BufferView::Pimpl::cursorNext(LyXText * text)
1137 if (!text->cursor.row()->next()) {
1138 int y = text->cursor.y() - text->cursor.row()->baseline() +
1139 text->cursor.row()->height();
1140 if (y > int(text->first_y + workarea().workHeight())) {
1141 screen().draw(bv_->text, bv_,
1142 bv_->text->first_y + workarea().workHeight());
1148 int y = text->first_y + workarea().workHeight();
1149 if (text->inset_owner && !text->first_y) {
1150 y -= (bv_->text->cursor.iy()
1151 - bv_->text->first_y
1152 + bv_->theLockingInset()->insetInInsetY());
1155 text->getRowNearY(y);
1157 Row * cursorrow = text->cursor.row();
1158 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1162 if (cursorrow == bv_->text->cursor.row()) {
1163 // we have a row which is higher than the workarea so we leave the
1164 // cursor on the start of the row and move only the draw down as soon
1165 // as we move the cursor or do something while inside the row (it may
1166 // span several workarea-heights) we'll move to the top again, but this
1167 // is better than just jump down and only display part of the row.
1168 new_y = bv_->text->first_y + workarea().workHeight();
1170 if (text->inset_owner) {
1171 new_y = bv_->text->cursor.iy()
1172 + bv_->theLockingInset()->insetInInsetY()
1173 + y - text->cursor.row()->baseline();
1175 new_y = text->cursor.y() - text->cursor.row()->baseline();
1178 screen().draw(bv_->text, bv_, new_y);
1179 if (text->cursor.row()->next()) {
1181 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1182 text->cursor.row()->next()->pos(), false);
1183 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1184 text->cursorDown(bv_, true);
1191 bool BufferView::Pimpl::available() const
1193 if (buffer_ && bv_->text)
1199 void BufferView::Pimpl::beforeChange(LyXText * text)
1202 text->clearSelection();
1206 void BufferView::Pimpl::savePosition(unsigned int i)
1208 if (i >= saved_positions_num)
1210 saved_positions[i] = Position(buffer_->fileName(),
1211 bv_->text->cursor.par()->id(),
1212 bv_->text->cursor.pos());
1215 str << _("Saved bookmark") << ' ' << i;
1216 owner_->message(str.str().c_str());
1221 void BufferView::Pimpl::restorePosition(unsigned int i)
1223 if (i >= saved_positions_num)
1226 string const fname = saved_positions[i].filename;
1228 beforeChange(bv_->text);
1230 if (fname != buffer_->fileName()) {
1231 Buffer * b = bufferlist.exists(fname) ?
1232 bufferlist.getBuffer(fname) :
1233 bufferlist.loadLyXFile(fname); // don't ask, just load it
1234 if (b != 0) buffer(b);
1237 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1241 bv_->text->setCursor(bv_, par,
1242 min(par->size(), saved_positions[i].par_pos));
1244 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1247 str << _("Moved to bookmark") << ' ' << i;
1248 owner_->message(str.str().c_str());
1253 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1255 if (i >= saved_positions_num)
1258 return !saved_positions[i].filename.empty();
1262 void BufferView::Pimpl::switchKeyMap()
1264 if (!lyxrc.rtl_support)
1267 LyXText * text = bv_->getLyXText();
1268 if (text->real_current_font.isRightToLeft()
1269 && !(bv_->theLockingInset()
1270 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1272 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1273 owner_->getIntl()->KeyMapSec();
1275 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1276 owner_->getIntl()->KeyMapPrim();
1281 void BufferView::Pimpl::insetUnlock()
1283 if (bv_->theLockingInset()) {
1284 bv_->theLockingInset()->insetUnlock(bv_);
1285 bv_->theLockingInset(0);
1291 void BufferView::Pimpl::showCursor()
1293 if (bv_->theLockingInset())
1294 bv_->theLockingInset()->showInsetCursor(bv_);
1296 screen().showCursor(bv_->text, bv_);
1300 void BufferView::Pimpl::hideCursor()
1302 if (!bv_->theLockingInset())
1303 screen().hideCursor();
1307 void BufferView::Pimpl::toggleSelection(bool b)
1309 if (bv_->theLockingInset())
1310 bv_->theLockingInset()->toggleSelection(bv_, b);
1311 screen().toggleSelection(bv_->text, bv_, b);
1315 void BufferView::Pimpl::toggleToggle()
1317 screen().toggleToggle(bv_->text, bv_);
1321 void BufferView::Pimpl::center()
1323 LyXText * t = bv_->text;
1326 int const half_height = workarea().workHeight() / 2;
1329 if (t->cursor.y() > half_height) {
1330 new_y = t->cursor.y() - half_height;
1333 // FIXME: can we do this w/o calling screen directly ?
1334 // This updates first_y but means the fitCursor() call
1335 // from the update(FITCUR) doesn't realise that we might
1336 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1337 // the scrollbar to be updated as it should, so we have
1338 // to do it manually. Any operation that does a center()
1339 // and also might have moved first_y must make sure to call
1340 // updateScrollbar() currently. Never mind that this is a
1341 // pretty obfuscated way of updating t->first_y
1342 screen().draw(t, bv_, new_y);
1344 update(t, BufferView::SELECT | BufferView::FITCUR);
1348 void BufferView::Pimpl::pasteClipboard(bool asPara)
1353 screen().hideCursor();
1354 beforeChange(bv_->text);
1356 string const clip(workarea().getClipboard());
1362 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1364 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1366 bv_->getLyXText()->clearSelection();
1367 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1371 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1373 workarea().putClipboard(stuff);
1378 * Dispatch functions for actions which can be valid for BufferView->text
1379 * and/or InsetText->text!!!
1384 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1386 LyXText * lt = bv_->getLyXText();
1388 if (selecting || lt->selection.mark()) {
1389 lt->setSelection(bv_);
1393 updateInset(lt->inset_owner, false);
1397 update(lt, BufferView::SELECT|BufferView::FITCUR);
1399 update(lt, BufferView::SELECT);
1401 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1402 bv_->theLockingInset()->hideInsetCursor(bv_);
1403 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1407 if (!lt->selection.set())
1408 workarea().haveSelection(false);
1414 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1416 LyXCursor cursor = bv_->getLyXText()->cursor;
1417 Buffer::inset_iterator it =
1418 find_if(Buffer::inset_iterator(
1419 cursor.par(), cursor.pos()),
1420 buffer_->inset_iterator_end(),
1421 lyx::compare_memfun(&Inset::lyxCode, code));
1422 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1426 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1428 string filename = filen;
1430 if (filename.empty()) {
1431 // Launch a file browser
1432 string initpath = lyxrc.document_path;
1435 string const trypath = owner_->buffer()->filePath();
1436 // If directory is writeable, use this as default.
1437 if (IsDirWriteable(trypath))
1441 FileDialog fileDlg(bv_->owner(),
1442 _("Select LyX document to insert"),
1444 make_pair(string(_("Documents|#o#O")),
1445 string(lyxrc.document_path)),
1446 make_pair(string(_("Examples|#E#e")),
1447 string(AddPath(system_lyxdir, "examples"))));
1449 FileDialog::Result result =
1450 fileDlg.Select(initpath,
1451 _("*.lyx| LyX Documents (*.lyx)"));
1453 if (result.first == FileDialog::Later)
1456 filename = result.second;
1458 // check selected filename
1459 if (filename.empty()) {
1460 owner_->message(_("Canceled."));
1465 // get absolute path of file and add ".lyx" to the filename if
1467 filename = FileSearch(string(), filename, "lyx");
1469 string const disp_fn(MakeDisplayPath(filename));
1472 s1 << _("Inserting document") << ' '
1473 << disp_fn << " ...";
1474 owner_->message(s1.str().c_str());
1475 bool const res = bv_->insertLyXFile(filename);
1478 str << _("Document") << ' ' << disp_fn
1479 << ' ' << _("inserted.");
1480 owner_->message(str.str().c_str());
1483 str << _("Could not insert document") << ' '
1485 owner_->message(str.str().c_str());
1490 bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
1492 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1493 << ev.action <<"] arg[" << ev.argument << "]" << endl;
1495 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1497 switch (ev.action) {
1498 // --- Misc -------------------------------------------
1502 LyXText * lt = bv_->getLyXText();
1503 lt->toggleAppendix(bv_);
1506 | BufferView::FITCUR
1507 | BufferView::CHANGE);
1512 case LFUN_TOC_INSERT:
1514 InsetCommandParams p;
1515 p.setCmdName("tableofcontents");
1516 Inset * inset = new InsetTOC(p);
1517 if (!insertInset(inset, tclass.defaultLayoutName()))
1522 case LFUN_SCROLL_INSET:
1523 // this is not handled here as this funktion is only aktive
1524 // if we have a locking_inset and that one is (or contains)
1528 case LFUN_INSET_GRAPHICS:
1530 Inset * new_inset = new InsetGraphics;
1531 if (!insertInset(new_inset)) {
1534 // this is need because you don't use a inset->Edit()
1535 updateInset(new_inset, true);
1536 new_inset->edit(bv_);
1546 case LFUN_PASTESELECTION:
1547 pasteClipboard(ev.argument == "paragraph");
1558 case LFUN_LAYOUT_COPY:
1559 bv_->copyEnvironment();
1562 case LFUN_LAYOUT_PASTE:
1563 bv_->pasteEnvironment();
1567 case LFUN_GOTOERROR:
1568 gotoInset(Inset::ERROR_CODE, false);
1572 gotoInset(Inset::NOTE_CODE, false);
1575 case LFUN_REFERENCE_GOTO:
1577 vector<Inset::Code> tmp;
1578 tmp.push_back(Inset::LABEL_CODE);
1579 tmp.push_back(Inset::REF_CODE);
1580 gotoInset(tmp, true);
1584 case LFUN_HYPHENATION:
1585 specialChar(InsetSpecialChar::HYPHENATION);
1588 case LFUN_LIGATURE_BREAK:
1589 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1593 specialChar(InsetSpecialChar::LDOTS);
1596 case LFUN_END_OF_SENTENCE:
1597 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1600 case LFUN_MENU_SEPARATOR:
1601 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1608 case LFUN_DEPTH_MIN:
1609 changeDepth(bv_, bv_->getLyXText(), -1);
1612 case LFUN_DEPTH_PLUS:
1613 changeDepth(bv_, bv_->getLyXText(), 1);
1617 owner_->getDialogs()->setUserFreeFont();
1620 case LFUN_FILE_INSERT:
1621 MenuInsertLyXFile(ev.argument);
1624 case LFUN_FILE_INSERT_ASCII_PARA:
1625 InsertAsciiFile(bv_, ev.argument, true);
1628 case LFUN_FILE_INSERT_ASCII:
1629 InsertAsciiFile(bv_, ev.argument, false);
1634 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1635 << ev.argument << endl;
1637 // This is not the good solution to the empty argument
1638 // problem, but it will hopefully suffice for 1.2.0.
1639 // The correct solution would be to augument the
1640 // function list/array with information about what
1641 // functions needs arguments and their type.
1642 if (ev.argument.empty()) {
1643 owner_->getLyXFunc()->setErrorMessage(
1644 _("LyX function 'layout' needs an argument."));
1648 // Derive layout number from given argument (string)
1649 // and current buffer's textclass (number). */
1650 bool hasLayout = tclass.hasLayout(ev.argument);
1651 string layout = ev.argument;
1653 // If the entry is obsolete, use the new one instead.
1655 string const & obs = tclass[layout]->obsoleted_by();
1661 owner_->getLyXFunc()->setErrorMessage(
1662 string(N_("Layout ")) + ev.argument +
1667 bool change_layout = (current_layout != layout);
1668 LyXText * lt = bv_->getLyXText();
1669 if (!change_layout && lt->selection.set() &&
1670 lt->selection.start.par() != lt->selection.end.par())
1672 Paragraph * spar = lt->selection.start.par();
1673 Paragraph * epar = lt->selection.end.par()->next();
1674 while(spar != epar) {
1675 if (spar->layout()->name() != current_layout) {
1676 change_layout = true;
1681 if (change_layout) {
1683 current_layout = layout;
1686 | BufferView::FITCUR);
1687 lt->setLayout(bv_, layout);
1688 owner_->setLayout(layout);
1691 | BufferView::FITCUR
1692 | BufferView::CHANGE);
1699 lang(bv_, ev.argument);
1701 owner_->view_state_changed();
1706 owner_->view_state_changed();
1711 owner_->view_state_changed();
1716 owner_->view_state_changed();
1721 owner_->view_state_changed();
1726 owner_->view_state_changed();
1731 owner_->view_state_changed();
1736 owner_->view_state_changed();
1739 case LFUN_UNDERLINE:
1741 owner_->view_state_changed();
1744 case LFUN_FONT_SIZE:
1745 fontSize(bv_, ev.argument);
1746 owner_->view_state_changed();
1749 case LFUN_FONT_STATE:
1750 owner_->getLyXFunc()->setMessage(currentState(bv_));
1753 case LFUN_UPCASE_WORD:
1755 LyXText * lt = bv_->getLyXText();
1759 | BufferView::FITCUR);
1760 lt->changeCase(bv_, LyXText::text_uppercase);
1761 if (lt->inset_owner)
1762 updateInset(lt->inset_owner, true);
1765 | BufferView::FITCUR
1766 | BufferView::CHANGE);
1770 case LFUN_LOWCASE_WORD:
1772 LyXText * lt = bv_->getLyXText();
1774 update(lt, BufferView::SELECT|BufferView::FITCUR);
1775 lt->changeCase(bv_, LyXText::text_lowercase);
1776 if (lt->inset_owner)
1777 updateInset(lt->inset_owner, true);
1780 | BufferView::FITCUR
1781 | BufferView::CHANGE);
1785 case LFUN_CAPITALIZE_WORD:
1787 LyXText * lt = bv_->getLyXText();
1789 update(lt, BufferView::SELECT|BufferView::FITCUR);
1790 lt->changeCase(bv_, LyXText::text_capitalization);
1791 if (lt->inset_owner)
1792 updateInset(lt->inset_owner, true);
1795 | BufferView::FITCUR
1796 | BufferView::CHANGE);
1800 case LFUN_TRANSPOSE_CHARS:
1802 LyXText * lt = bv_->getLyXText();
1804 update(lt, BufferView::SELECT|BufferView::FITCUR);
1805 lt->transposeChars(*bv_);
1806 if (lt->inset_owner)
1807 updateInset(lt->inset_owner, true);
1810 | BufferView::FITCUR
1811 | BufferView::CHANGE);
1816 case LFUN_INSERT_LABEL:
1817 MenuInsertLabel(bv_, ev.argument);
1820 case LFUN_REF_INSERT:
1821 if (ev.argument.empty()) {
1822 InsetCommandParams p("ref");
1823 owner_->getDialogs()->createRef(p.getAsString());
1825 InsetCommandParams p;
1826 p.setFromString(ev.argument);
1828 InsetRef * inset = new InsetRef(p, *buffer_);
1829 if (!insertInset(inset))
1832 updateInset(inset, true);
1836 case LFUN_BOOKMARK_SAVE:
1837 savePosition(strToUnsignedInt(ev.argument));
1840 case LFUN_BOOKMARK_GOTO:
1841 restorePosition(strToUnsignedInt(ev.argument));
1846 string label = ev.argument;
1847 if (label.empty()) {
1849 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1851 label = inset->getContents();
1856 if (!label.empty()) {
1857 //bv_->savePosition(0);
1858 if (!bv_->gotoLabel(label))
1859 Alert::alert(_("Error"),
1860 _("Couldn't find this label"),
1861 _("in current document."));
1866 // --- Cursor Movements -----------------------------
1869 LyXText * lt = bv_->getLyXText();
1871 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1872 if (!lt->selection.mark())
1874 update(lt, BufferView::SELECT|BufferView::FITCUR);
1876 lt->cursorLeft(bv_, false);
1877 if (lt->cursor.pos() < lt->cursor.par()->size()
1878 && lt->cursor.par()->isInset(lt->cursor.pos())
1879 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1880 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1881 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1883 tmpinset->edit(bv_, false);
1885 tmpinset->edit(bv_);
1889 lt->cursorRight(bv_, false);
1891 moveCursorUpdate(false);
1892 owner_->view_state_changed();
1898 // This is soooo ugly. Isn`t it possible to make
1899 // it simpler? (Lgb)
1900 LyXText * lt = bv_->getLyXText();
1901 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1902 if (!lt->selection.mark())
1904 update(lt, BufferView::SELECT|BufferView::FITCUR);
1905 LyXCursor const cur = lt->cursor;
1907 lt->cursorLeft(bv_, false);
1908 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1909 lt->cursor.pos() < lt->cursor.par()->size() &&
1910 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1911 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1912 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1913 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1915 tmpinset->edit(bv_);
1917 tmpinset->edit(bv_, false);
1921 lt->cursorRight(bv_, false);
1924 moveCursorUpdate(false);
1925 owner_->view_state_changed();
1931 LyXText * lt = bv_->getLyXText();
1933 if (!lt->selection.mark())
1935 update(lt, BufferView::UPDATE);
1938 moveCursorUpdate(false);
1939 owner_->view_state_changed();
1945 LyXText * lt = bv_->getLyXText();
1947 if (!lt->selection.mark())
1949 update(lt, BufferView::UPDATE);
1950 lt->cursorDown(bv_);
1952 moveCursorUpdate(false);
1953 owner_->view_state_changed();
1957 case LFUN_UP_PARAGRAPH:
1959 LyXText * lt = bv_->getLyXText();
1961 if (!lt->selection.mark())
1963 update(lt, BufferView::UPDATE);
1964 lt->cursorUpParagraph(bv_);
1966 moveCursorUpdate(false);
1967 owner_->view_state_changed();
1971 case LFUN_DOWN_PARAGRAPH:
1973 LyXText * lt = bv_->getLyXText();
1975 if (!lt->selection.mark())
1977 update(lt, BufferView::UPDATE);
1978 lt->cursorDownParagraph(bv_);
1980 moveCursorUpdate(false);
1981 owner_->view_state_changed();
1987 LyXText * lt = bv_->getLyXText();
1989 if (!lt->selection.mark())
1991 update(lt, BufferView::UPDATE);
1994 moveCursorUpdate(false, false);
1995 owner_->view_state_changed();
2001 LyXText * lt = bv_->getLyXText();
2003 if (!lt->selection.mark())
2005 update(lt, BufferView::UPDATE);
2008 moveCursorUpdate(false, false);
2009 owner_->view_state_changed();
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2019 update(lt, BufferView::SELECT|BufferView::FITCUR);
2020 lt->cursorHome(bv_);
2022 moveCursorUpdate(false);
2023 owner_->view_state_changed();
2029 LyXText * lt = bv_->getLyXText();
2031 if (!lt->selection.mark())
2034 BufferView::SELECT|BufferView::FITCUR);
2037 moveCursorUpdate(false);
2038 owner_->view_state_changed();
2042 case LFUN_SHIFT_TAB:
2045 LyXText * lt = bv_->getLyXText();
2047 if (!lt->selection.mark())
2050 BufferView::SELECT|BufferView::FITCUR);
2053 moveCursorUpdate(false);
2054 owner_->view_state_changed();
2058 case LFUN_WORDRIGHT:
2060 LyXText * lt = bv_->getLyXText();
2062 if (!lt->selection.mark())
2064 update(lt, BufferView::SELECT|BufferView::FITCUR);
2065 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2066 lt->cursorLeftOneWord(bv_);
2068 lt->cursorRightOneWord(bv_);
2070 moveCursorUpdate(false);
2071 owner_->view_state_changed();
2077 LyXText * lt = bv_->getLyXText();
2079 if (!lt->selection.mark())
2081 update(lt, BufferView::SELECT|BufferView::FITCUR);
2082 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2083 lt->cursorRightOneWord(bv_);
2085 lt->cursorLeftOneWord(bv_);
2087 moveCursorUpdate(false);
2088 owner_->view_state_changed();
2092 case LFUN_BEGINNINGBUF:
2094 LyXText * lt = bv_->getLyXText();
2096 if (!lt->selection.mark())
2099 BufferView::SELECT|BufferView::FITCUR);
2102 moveCursorUpdate(false);
2103 owner_->view_state_changed();
2109 LyXText * lt = bv_->getLyXText();
2111 if (!lt->selection.mark())
2114 BufferView::SELECT|BufferView::FITCUR);
2115 lt->cursorBottom(bv_);
2117 moveCursorUpdate(false);
2118 owner_->view_state_changed();
2122 /* cursor selection ---------------------------- */
2125 LyXText * lt = bv_->getLyXText();
2128 BufferView::SELECT|BufferView::FITCUR);
2129 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2130 lt->cursorLeft(bv_);
2132 lt->cursorRight(bv_);
2134 moveCursorUpdate(true);
2135 owner_->view_state_changed();
2141 LyXText * lt = bv_->getLyXText();
2144 BufferView::SELECT|BufferView::FITCUR);
2145 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2146 lt->cursorRight(bv_);
2148 lt->cursorLeft(bv_);
2150 moveCursorUpdate(true);
2151 owner_->view_state_changed();
2157 LyXText * lt = bv_->getLyXText();
2160 BufferView::SELECT|BufferView::FITCUR);
2161 lt->cursorUp(bv_, true);
2163 moveCursorUpdate(true);
2164 owner_->view_state_changed();
2170 LyXText * lt = bv_->getLyXText();
2173 BufferView::SELECT|BufferView::FITCUR);
2174 lt->cursorDown(bv_, true);
2176 moveCursorUpdate(true);
2177 owner_->view_state_changed();
2181 case LFUN_UP_PARAGRAPHSEL:
2183 LyXText * lt = bv_->getLyXText();
2186 BufferView::SELECT|BufferView::FITCUR);
2187 lt->cursorUpParagraph(bv_);
2189 moveCursorUpdate(true);
2190 owner_->view_state_changed();
2194 case LFUN_DOWN_PARAGRAPHSEL:
2196 LyXText * lt = bv_->getLyXText();
2199 BufferView::SELECT|BufferView::FITCUR);
2200 lt->cursorDownParagraph(bv_);
2202 moveCursorUpdate(true);
2203 owner_->view_state_changed();
2209 LyXText * lt = bv_->getLyXText();
2211 update(lt, BufferView::SELECT|BufferView::FITCUR);
2214 moveCursorUpdate(true);
2215 owner_->view_state_changed();
2221 LyXText * lt = bv_->getLyXText();
2223 update(lt, BufferView::SELECT|BufferView::FITCUR);
2226 moveCursorUpdate(true);
2227 owner_->view_state_changed();
2233 LyXText * lt = bv_->getLyXText();
2235 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 lt->cursorHome(bv_);
2238 moveCursorUpdate(true);
2239 owner_->view_state_changed();
2245 LyXText * lt = bv_->getLyXText();
2247 update(lt, BufferView::SELECT|BufferView::FITCUR);
2250 moveCursorUpdate(true);
2251 owner_->view_state_changed();
2255 case LFUN_WORDRIGHTSEL:
2257 LyXText * lt = bv_->getLyXText();
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2260 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2261 lt->cursorLeftOneWord(bv_);
2263 lt->cursorRightOneWord(bv_);
2265 moveCursorUpdate(true);
2266 owner_->view_state_changed();
2270 case LFUN_WORDLEFTSEL:
2272 LyXText * lt = bv_->getLyXText();
2274 update(lt, BufferView::SELECT|BufferView::FITCUR);
2275 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2276 lt->cursorRightOneWord(bv_);
2278 lt->cursorLeftOneWord(bv_);
2280 moveCursorUpdate(true);
2281 owner_->view_state_changed();
2285 case LFUN_BEGINNINGBUFSEL:
2287 LyXText * lt = bv_->getLyXText();
2289 if (lt->inset_owner)
2291 update(lt, BufferView::SELECT|BufferView::FITCUR);
2294 moveCursorUpdate(true);
2295 owner_->view_state_changed();
2299 case LFUN_ENDBUFSEL:
2301 LyXText * lt = bv_->getLyXText();
2303 if (lt->inset_owner)
2306 BufferView::SELECT|BufferView::FITCUR);
2307 lt->cursorBottom(bv_);
2309 moveCursorUpdate(true);
2310 owner_->view_state_changed();
2314 // --- text changing commands ------------------------
2315 case LFUN_BREAKLINE:
2317 LyXText * lt = bv_->getLyXText();
2320 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2323 | BufferView::FITCUR
2324 | BufferView::CHANGE);
2325 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2326 moveCursorUpdate(false);
2330 case LFUN_PROTECTEDSPACE:
2332 LyXText * lt = bv_->getLyXText();
2333 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2335 if (style->free_spacing) {
2336 lt->insertChar(bv_, ' ');
2339 | BufferView::FITCUR
2340 | BufferView::CHANGE);
2342 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2344 moveCursorUpdate(false);
2350 LyXText * lt = bv_->getLyXText();
2352 if (lt->selection.mark()) {
2356 | BufferView::FITCUR);
2357 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2360 lt->selection.mark(true);
2363 | BufferView::FITCUR);
2364 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2366 lt->selection.cursor = lt->cursor;
2372 LyXText * lt = bv_->getLyXText();
2374 if (!lt->selection.set()) {
2376 lt->selection.cursor = lt->cursor;
2379 | BufferView::FITCUR
2380 | BufferView::CHANGE);
2381 // It is possible to make it a lot faster still
2382 // just comment out the line below...
2387 moveCursorUpdate(false);
2388 owner_->view_state_changed();
2393 case LFUN_DELETE_SKIP:
2395 LyXText * lt = bv_->getLyXText();
2397 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2399 LyXCursor cursor = lt->cursor;
2401 if (!lt->selection.set()) {
2402 if (cursor.pos() == cursor.par()->size()) {
2403 lt->cursorRight(bv_);
2404 cursor = lt->cursor;
2405 if (cursor.pos() == 0
2406 && !(cursor.par()->params().spaceTop()
2407 == VSpace (VSpace::NONE))) {
2410 cursor.par()->params().lineTop(),
2411 cursor.par()->params().lineBottom(),
2412 cursor.par()->params().pagebreakTop(),
2413 cursor.par()->params().pagebreakBottom(),
2414 VSpace(VSpace::NONE),
2415 cursor.par()->params().spaceBottom(),
2416 cursor.par()->params().spacing(),
2417 cursor.par()->params().align(),
2418 cursor.par()->params().labelWidthString(), 0);
2419 lt->cursorLeft(bv_);
2422 | BufferView::FITCUR
2423 | BufferView::CHANGE);
2425 lt->cursorLeft(bv_);
2427 lt->selection.cursor = lt->cursor;
2430 | BufferView::FITCUR
2431 | BufferView::CHANGE);
2435 lt->selection.cursor = lt->cursor;
2438 | BufferView::FITCUR
2439 | BufferView::CHANGE);
2447 /* -------> Delete word forward. */
2448 case LFUN_DELETE_WORD_FORWARD:
2449 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2450 bv_->getLyXText()->deleteWordForward(bv_);
2451 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2452 moveCursorUpdate(false);
2453 owner_->view_state_changed();
2456 /* -------> Delete word backward. */
2457 case LFUN_DELETE_WORD_BACKWARD:
2459 LyXText * lt = bv_->getLyXText();
2461 update(lt, BufferView::SELECT|BufferView::FITCUR);
2462 lt->deleteWordBackward(bv_);
2465 | BufferView::FITCUR
2466 | BufferView::CHANGE);
2467 moveCursorUpdate(false);
2468 owner_->view_state_changed();
2472 /* -------> Kill to end of line. */
2473 case LFUN_DELETE_LINE_FORWARD:
2475 LyXText * lt = bv_->getLyXText();
2477 update(lt, BufferView::SELECT|BufferView::FITCUR);
2478 lt->deleteLineForward(bv_);
2481 | BufferView::FITCUR
2482 | BufferView::CHANGE);
2483 moveCursorUpdate(false);
2487 /* -------> Set mark off. */
2490 LyXText * lt = bv_->getLyXText();
2493 update(lt, BufferView::SELECT|BufferView::FITCUR);
2494 lt->selection.cursor = lt->cursor;
2495 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2499 /* -------> Set mark on. */
2502 LyXText * lt = bv_->getLyXText();
2505 lt->selection.mark(true);
2506 update(lt, BufferView::SELECT|BufferView::FITCUR);
2507 lt->selection.cursor = lt->cursor;
2508 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2512 case LFUN_BACKSPACE:
2514 LyXText * lt = bv_->getLyXText();
2516 if (!lt->selection.set()) {
2517 if (owner_->getIntl()->getTransManager().backspace()) {
2519 lt->selection.cursor = lt->cursor;
2522 | BufferView::FITCUR
2523 | BufferView::CHANGE);
2524 // It is possible to make it a lot faster still
2525 // just comment out the line below...
2531 owner_->view_state_changed();
2536 case LFUN_BACKSPACE_SKIP:
2538 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2539 LyXText * lt = bv_->getLyXText();
2541 LyXCursor cursor = lt->cursor;
2543 if (!lt->selection.set()) {
2544 if (cursor.pos() == 0
2545 && !(cursor.par()->params().spaceTop()
2546 == VSpace (VSpace::NONE))) {
2549 cursor.par()->params().lineTop(),
2550 cursor.par()->params().lineBottom(),
2551 cursor.par()->params().pagebreakTop(),
2552 cursor.par()->params().pagebreakBottom(),
2553 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2554 cursor.par()->params().spacing(),
2555 cursor.par()->params().align(),
2556 cursor.par()->params().labelWidthString(), 0);
2559 | BufferView::FITCUR
2560 | BufferView::CHANGE);
2563 lt->selection.cursor = cursor;
2566 | BufferView::FITCUR
2567 | BufferView::CHANGE);
2574 case LFUN_BREAKPARAGRAPH:
2576 LyXText * lt = bv_->getLyXText();
2579 lt->breakParagraph(bv_, 0);
2582 | BufferView::FITCUR
2583 | BufferView::CHANGE);
2584 lt->selection.cursor = lt->cursor;
2586 owner_->view_state_changed();
2590 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2592 LyXText * lt = bv_->getLyXText();
2595 lt->breakParagraph(bv_, 1);
2598 | BufferView::FITCUR
2599 | BufferView::CHANGE);
2600 lt->selection.cursor = lt->cursor;
2602 owner_->view_state_changed();
2606 case LFUN_BREAKPARAGRAPH_SKIP:
2608 // When at the beginning of a paragraph, remove
2609 // indentation and add a "defskip" at the top.
2610 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2611 LyXText * lt = bv_->getLyXText();
2613 LyXCursor cursor = lt->cursor;
2616 if (cursor.pos() == 0) {
2617 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2620 cursor.par()->params().lineTop(),
2621 cursor.par()->params().lineBottom(),
2622 cursor.par()->params().pagebreakTop(),
2623 cursor.par()->params().pagebreakBottom(),
2624 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2625 cursor.par()->params().spacing(),
2626 cursor.par()->params().align(),
2627 cursor.par()->params().labelWidthString(), 1);
2628 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2632 lt->breakParagraph(bv_, 0);
2633 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2638 | BufferView::FITCUR
2639 | BufferView::CHANGE);
2640 lt->selection.cursor = cursor;
2642 owner_->view_state_changed();
2646 case LFUN_PARAGRAPH_SPACING:
2648 LyXText * lt = bv_->getLyXText();
2650 Paragraph * par = lt->cursor.par();
2651 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2652 float cur_value = 1.0;
2653 if (cur_spacing == Spacing::Other) {
2654 cur_value = par->params().spacing().getValue();
2657 istringstream istr(ev.argument.c_str());
2661 Spacing::Space new_spacing = cur_spacing;
2662 float new_value = cur_value;
2664 lyxerr << "Missing argument to `paragraph-spacing'"
2666 } else if (tmp == "single") {
2667 new_spacing = Spacing::Single;
2668 } else if (tmp == "onehalf") {
2669 new_spacing = Spacing::Onehalf;
2670 } else if (tmp == "double") {
2671 new_spacing = Spacing::Double;
2672 } else if (tmp == "other") {
2673 new_spacing = Spacing::Other;
2676 lyxerr << "new_value = " << tmpval << endl;
2679 } else if (tmp == "default") {
2680 new_spacing = Spacing::Default;
2682 lyxerr << _("Unknown spacing argument: ")
2683 << ev.argument << endl;
2685 if (cur_spacing != new_spacing || cur_value != new_value) {
2686 par->params().spacing(Spacing(new_spacing, new_value));
2687 lt->redoParagraph(bv_);
2690 | BufferView::FITCUR
2691 | BufferView::CHANGE);
2696 case LFUN_INSET_TOGGLE:
2698 LyXText * lt = bv_->getLyXText();
2701 update(lt, BufferView::SELECT|BufferView::FITCUR);
2702 lt->toggleInset(bv_);
2703 update(lt, BufferView::SELECT|BufferView::FITCUR);
2715 InsetCommandParams p;
2716 if (ev.action == LFUN_HTMLURL)
2717 p.setCmdName("htmlurl");
2719 p.setCmdName("url");
2720 owner_->getDialogs()->createUrl(p.getAsString());
2724 case LFUN_INSERT_URL:
2726 InsetCommandParams p;
2727 p.setFromString(ev.argument);
2729 InsetUrl * inset = new InsetUrl(p);
2730 if (!insertInset(inset))
2733 updateInset(inset, true);
2737 case LFUN_INSET_ERT:
2738 insertAndEditInset(new InsetERT(buffer_->params));
2741 case LFUN_INSET_EXTERNAL:
2742 insertAndEditInset(new InsetExternal);
2745 case LFUN_INSET_FOOTNOTE:
2746 insertAndEditInset(new InsetFoot(buffer_->params));
2749 case LFUN_INSET_MARGINAL:
2750 insertAndEditInset(new InsetMarginal(buffer_->params));
2753 case LFUN_INSET_MINIPAGE:
2754 insertAndEditInset(new InsetMinipage(buffer_->params));
2757 case LFUN_INSERT_NOTE:
2758 insertAndEditInset(new InsetNote(buffer_->params));
2761 case LFUN_INSET_FLOAT:
2762 // check if the float type exist
2763 if (floatList.typeExist(ev.argument)) {
2764 insertAndEditInset(new InsetFloat(buffer_->params,
2767 lyxerr << "Non-existent float type: "
2768 << ev.argument << endl;
2772 case LFUN_INSET_WIDE_FLOAT:
2773 // check if the float type exist
2774 if (floatList.typeExist(ev.argument)) {
2775 InsetFloat * new_inset =
2776 new InsetFloat(buffer_->params, ev.argument);
2777 new_inset->wide(true);
2778 insertAndEditInset(new_inset);
2780 lyxerr << "Non-existent float type: "
2781 << ev.argument << endl;
2786 case LFUN_INSET_LIST:
2787 insertAndEditInset(new InsetList);
2790 case LFUN_INSET_THEOREM:
2791 insertAndEditInset(new InsetTheorem);
2795 case LFUN_INSET_CAPTION:
2797 // Do we have a locking inset...
2798 if (bv_->theLockingInset()) {
2799 lyxerr << "Locking inset code: "
2800 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2801 InsetCaption * new_inset =
2802 new InsetCaption(buffer_->params);
2803 new_inset->setOwner(bv_->theLockingInset());
2804 new_inset->setAutoBreakRows(true);
2805 new_inset->setDrawFrame(0, InsetText::LOCKED);
2806 new_inset->setFrameColor(0, LColor::captionframe);
2807 if (insertInset(new_inset))
2808 new_inset->edit(bv_);
2815 case LFUN_TABULAR_INSERT:
2817 if (ev.argument.empty()) {
2818 owner_->getDialogs()->showTabularCreate();
2824 ::sscanf(ev.argument.c_str(),"%d%d", &r, &c);
2825 InsetTabular * new_inset =
2826 new InsetTabular(*buffer_, r, c);
2828 bv_->getLyXText()->real_current_font.isRightToLeft();
2829 if (!open_new_inset(new_inset, rtl))
2834 // --- lyxserver commands ----------------------------
2836 case LFUN_CHARATCURSOR:
2838 pos_type pos = bv_->getLyXText()->cursor.pos();
2839 if (pos < bv_->getLyXText()->cursor.par()->size())
2840 owner_->getLyXFunc()->setMessage(
2841 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2843 owner_->getLyXFunc()->setMessage("EOF");
2848 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2850 + tostr(bv_->getLyXText()->cursor.y()));
2857 if (::sscanf(ev.argument.c_str(), " %d %d", &x, &y) != 2) {
2858 lyxerr << "SETXY: Could not parse coordinates in '"
2859 << ev.argument << std::endl;
2861 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2865 case LFUN_GETLAYOUT:
2866 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2871 LyXFont & font = bv_->getLyXText()->current_font;
2872 if (font.shape() == LyXFont::ITALIC_SHAPE)
2873 owner_->getLyXFunc()->setMessage("E");
2874 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2875 owner_->getLyXFunc()->setMessage("N");
2877 owner_->getLyXFunc()->setMessage("0");
2882 // --- accented characters ---------------------------
2885 case LFUN_CIRCUMFLEX:
2895 case LFUN_SPECIAL_CARON:
2898 case LFUN_HUNG_UMLAUT:
2901 if (ev.argument.empty()) {
2903 owner_->getLyXFunc()->handleKeyFunc(ev.action);
2905 owner_->getLyXFunc()->handleKeyFunc(ev.action);
2906 owner_->getIntl()->getTransManager()
2907 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
2908 update(bv_->getLyXText(),
2910 | BufferView::FITCUR
2911 | BufferView::CHANGE);
2916 mathDispatch(bv_, ev.argument);
2919 case LFUN_MATH_MACRO:
2920 mathDispatchMathMacro(bv_, ev.argument);
2923 case LFUN_MATH_DELIM:
2924 mathDispatchMathDelim(bv_, ev.argument);
2927 case LFUN_INSERT_MATRIX:
2928 mathDispatchInsertMatrix(bv_, ev.argument);
2931 case LFUN_INSERT_MATH:
2932 mathDispatchInsertMath(bv_, ev.argument);
2935 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2936 mathDispatchMathImportSelection(bv_, ev.argument);
2939 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2940 mathDispatchMathDisplay(bv_, ev.argument);
2943 case LFUN_MATH_MODE: // Open or create an inlined math inset
2944 mathDispatchMathMode(bv_, ev.argument);
2947 case LFUN_GREEK: // Insert a single greek letter
2948 mathDispatchGreek(bv_, ev.argument);
2951 case LFUN_CITATION_INSERT:
2953 InsetCommandParams p;
2954 p.setFromString(ev.argument);
2956 InsetCitation * inset = new InsetCitation(p);
2957 if (!insertInset(inset))
2960 updateInset(inset, true);
2964 case LFUN_INSERT_BIBTEX:
2966 // ale970405+lasgoutt970425
2967 // The argument can be up to two tokens separated
2968 // by a space. The first one is the bibstyle.
2969 string const db = token(ev.argument, ' ', 0);
2970 string const bibstyle = token(ev.argument, ' ', 1);
2972 InsetCommandParams p("BibTeX", db, bibstyle);
2973 InsetBibtex * inset = new InsetBibtex(p);
2975 if (insertInset(inset)) {
2976 if (ev.argument.empty())
2983 // BibTeX data bases
2984 case LFUN_BIBDB_ADD:
2986 InsetBibtex * inset =
2987 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2989 inset->addDatabase(ev.argument);
2994 case LFUN_BIBDB_DEL:
2996 InsetBibtex * inset =
2997 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2999 inset->delDatabase(ev.argument);
3004 case LFUN_BIBTEX_STYLE:
3006 InsetBibtex * inset =
3007 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3009 inset->setOptions(ev.argument);
3014 case LFUN_INDEX_INSERT:
3016 string entry = ev.argument;
3017 if (entry.empty()) {
3018 entry = bv_->getLyXText()->getStringToIndex(bv_);
3021 if (entry.empty()) {
3022 owner_->getDialogs()->createIndex();
3026 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3028 if (!insertInset(inset)) {
3031 updateInset(inset, true);
3036 case LFUN_INDEX_PRINT:
3038 InsetCommandParams p("printindex");
3039 Inset * inset = new InsetPrintIndex(p);
3040 if (!insertInset(inset, tclass.defaultLayoutName()))
3045 case LFUN_PARENTINSERT:
3047 InsetCommandParams p("lyxparent", ev.argument);
3048 Inset * inset = new InsetParent(p, *buffer_);
3049 if (!insertInset(inset, tclass.defaultLayoutName()))
3055 case LFUN_CHILD_INSERT:
3057 InsetInclude::Params p;
3058 p.cparams.setFromString(ev.argument);
3059 p.masterFilename_ = buffer_->fileName();
3061 InsetInclude * inset = new InsetInclude(p);
3062 if (!insertInset(inset))
3065 updateInset(inset, true);
3066 bv_->owner()->getDialogs()->showInclude(inset);
3071 case LFUN_FLOAT_LIST:
3072 if (floatList.typeExist(ev.argument)) {
3073 Inset * inset = new InsetFloatList(ev.argument);
3074 if (!insertInset(inset, tclass.defaultLayoutName()))
3077 lyxerr << "Non-existent float type: "
3078 << ev.argument << endl;
3082 case LFUN_THESAURUS_ENTRY:
3084 string arg = ev.argument;
3087 arg = bv_->getLyXText()->selectionAsString(buffer_,
3091 if (arg.size() > 100 || arg.empty()) {
3092 // Get word or selection
3093 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3094 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3095 // FIXME: where is getLyXText()->unselect(bv_) ?
3099 bv_->owner()->getDialogs()->showThesaurus(arg);
3103 case LFUN_SELFINSERT:
3105 if (ev.argument.empty()) break;
3107 /* Automatically delete the currently selected
3108 * text and replace it with what is being
3109 * typed in now. Depends on lyxrc settings
3110 * "auto_region_delete", which defaults to
3113 LyXText * lt = bv_->getLyXText();
3115 if (lyxrc.auto_region_delete) {
3116 if (lt->selection.set()) {
3117 lt->cutSelection(bv_, false, false);
3120 | BufferView::FITCUR
3121 | BufferView::CHANGE);
3123 workarea().haveSelection(false);
3127 LyXFont const old_font(lt->real_current_font);
3129 string::const_iterator cit = ev.argument.begin();
3130 string::const_iterator end = ev.argument.end();
3131 for (; cit != end; ++cit) {
3132 owner_->getIntl()->getTransManager().
3133 TranslateAndInsert(*cit, lt);
3138 | BufferView::FITCUR
3139 | BufferView::CHANGE);
3141 lt->selection.cursor = lt->cursor;
3142 moveCursorUpdate(false);
3144 // real_current_font.number can change so we need to
3145 // update the minibuffer
3146 if (old_font != lt->real_current_font)
3147 owner_->view_state_changed();
3152 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3154 time_t now_time_t = time(NULL);
3155 struct tm * now_tm = localtime(&now_time_t);
3156 setlocale(LC_TIME, "");
3158 if (!ev.argument.empty())
3161 arg = lyxrc.date_insert_format;
3163 int const datetmp_len =
3164 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3166 LyXText * lt = bv_->getLyXText();
3168 for (int i = 0; i < datetmp_len; i++) {
3169 lt->insertChar(bv_, datetmp[i]);
3172 | BufferView::FITCUR
3173 | BufferView::CHANGE);
3176 lt->selection.cursor = lt->cursor;
3177 moveCursorUpdate(false);
3181 case LFUN_UNKNOWN_ACTION:
3182 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3193 void BufferView::Pimpl::newline()
3196 LyXText * lt = bv_->getLyXText();
3200 | BufferView::FITCUR);
3201 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3204 | BufferView::FITCUR
3205 | BufferView::CHANGE);
3210 void BufferView::Pimpl::hfill()
3213 LyXText * lt = bv_->getLyXText();
3217 | BufferView::FITCUR);
3218 lt->insertChar(bv_, Paragraph::META_HFILL);
3221 | BufferView::FITCUR
3222 | BufferView::CHANGE);
3227 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3230 LyXText * lt = bv_->getLyXText();
3233 update(lt, BufferView::SELECT|BufferView::FITCUR);
3234 InsetSpecialChar * new_inset =
3235 new InsetSpecialChar(kind);
3236 if (!insertInset(new_inset))
3239 updateInset(new_inset, true);
3244 void BufferView::Pimpl::smartQuote()
3246 LyXText const * lt = bv_->getLyXText();
3247 Paragraph const * par = lt->cursor.par();
3248 pos_type pos = lt->cursor.pos();
3252 || (par->isInset(pos - 1)
3253 && par->getInset(pos - 1)->isSpace()))
3256 c = par->getChar(pos - 1);
3261 LyXLayout_ptr const & style = par->layout();
3263 if (style->pass_thru ||
3264 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3265 bv_->owner()->getLyXFunc()
3266 ->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
3270 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3273 if (insertInset(inset))
3278 bool gotsel = false;
3280 if (bv_->getLyXText()->selection.set()) {
3281 bv_->getLyXText()->cutSelection(bv_, true, false);
3285 if (insertInset(inset)) {
3288 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3296 // Open and lock an updatable inset
3297 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3299 LyXText * lt = bv_->getLyXText();
3303 if (!insertInset(new_inset)) {
3307 new_inset->edit(bv_, !behind);
3312 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3314 // if we are in a locking inset we should try to insert the
3315 // inset there otherwise this is a illegal function now
3316 if (bv_->theLockingInset()) {
3317 if (bv_->theLockingInset()->insetAllowed(inset))
3318 return bv_->theLockingInset()->insertInset(bv_, inset);
3322 // not quite sure if we want this...
3323 setCursorParUndo(bv_);
3326 beforeChange(bv_->text);
3327 if (!lout.empty()) {
3328 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3329 bv_->text->breakParagraph(bv_);
3330 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3332 if (!bv_->text->cursor.par()->empty()) {
3333 bv_->text->cursorLeft(bv_);
3335 bv_->text->breakParagraph(bv_);
3336 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3340 LyXTextClass const & tclass =
3341 buffer_->params.getLyXTextClass();
3342 bool hasLayout = tclass.hasLayout(lres);
3343 string lay = tclass.defaultLayoutName();
3345 if (hasLayout != false) {
3349 // layout not fount using default
3350 lay = tclass.defaultLayoutName();
3353 bv_->text->setLayout(bv_, lay);
3355 bv_->text->setParagraph(bv_, 0, 0,
3357 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3362 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3365 bv_->text->insertInset(bv_, inset);
3366 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3373 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3375 if (!inset || !available())
3378 // first check for locking insets
3379 if (bv_->theLockingInset()) {
3380 if (bv_->theLockingInset() == inset) {
3381 if (bv_->text->updateInset(bv_, inset)) {
3384 buffer_->markDirty();
3389 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3390 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3393 buffer_->markDirty();
3401 // then check if the inset is a top_level inset (has no owner)
3402 // if yes do the update as always otherwise we have to update the
3403 // toplevel inset where this inset is inside
3404 Inset * tl_inset = inset;
3405 while(tl_inset->owner())
3406 tl_inset = tl_inset->owner();
3408 if (tl_inset == inset) {
3409 update(bv_->text, BufferView::UPDATE);
3410 if (bv_->text->updateInset(bv_, inset)) {
3414 | BufferView::FITCUR
3415 | BufferView::CHANGE);
3417 update(bv_->text, SELECT);
3421 } else if (static_cast<UpdatableInset *>(tl_inset)
3422 ->updateInsetInInset(bv_, inset))
3424 if (bv_->text->updateInset(bv_, tl_inset)) {
3432 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3435 if (!available()) return;
3438 beforeChange(bv_->text);
3439 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3441 LyXCursor const & cursor = bv_->text->cursor;
3445 cursor.par()->isInset(cursor.pos())) {
3446 Inset const * inset = cursor.par()->getInset(cursor.pos());
3447 if (find(codes.begin(), codes.end(), inset->lyxCode())
3450 static_cast<InsetCommand const *>(inset)->getContents();
3454 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3455 if (bv_->text->cursor.pos()
3456 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3457 LyXCursor tmp = bv_->text->cursor;
3458 bv_->text->cursor.par(bv_->text->ownerParagraph());
3459 bv_->text->cursor.pos(0);
3460 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3461 bv_->text->cursor = tmp;
3462 bv_->owner()->message(_("No more insets"));
3465 bv_->owner()->message(_("No more insets"));
3468 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3469 bv_->text->selection.cursor = bv_->text->cursor;
3473 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3475 gotoInset(vector<Inset::Code>(1, code), same_content);