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();
293 int BufferView::Pimpl::resizeCurrentBuffer()
295 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
298 Paragraph * selstartpar = 0;
299 Paragraph * selendpar = 0;
300 UpdatableInset * the_locking_inset = 0;
303 pos_type selstartpos = 0;
304 pos_type selendpos = 0;
305 bool selection = false;
306 bool mark_set = false;
308 owner_->prohibitInput();
310 owner_->message(_("Formatting document..."));
313 par = bv_->text->cursor.par();
314 pos = bv_->text->cursor.pos();
315 selstartpar = bv_->text->selection.start.par();
316 selstartpos = bv_->text->selection.start.pos();
317 selendpar = bv_->text->selection.end.par();
318 selendpos = bv_->text->selection.end.pos();
319 selection = bv_->text->selection.set();
320 mark_set = bv_->text->selection.mark();
321 the_locking_inset = bv_->theLockingInset();
322 buffer_->resizeInsets(bv_);
323 // I don't think the delete and new are necessary here we just could
324 // call only init! (Jug 20020419)
326 bv_->text = new LyXText(bv_);
327 bv_->text->init(bv_);
329 // See if we have a text in TextCache that fits
330 // the new buffer_ with the correct width.
331 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
333 if (lyxerr.debugging()) {
334 lyxerr << "Found a LyXText that fits:\n";
335 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
337 // Set the owner of the newly found text
338 // bv_->text->owner(bv_);
339 if (lyxerr.debugging())
340 textcache.show(lyxerr, "resizeCurrentBuffer");
342 bv_->text = new LyXText(bv_);
343 bv_->text->init(bv_);
344 //buffer_->resizeInsets(bv_);
349 bv_->text->selection.set(true);
350 // At this point just to avoid the Delete-Empty-Paragraph-
351 // Mechanism when setting the cursor.
352 bv_->text->selection.mark(mark_set);
354 bv_->text->setCursor(bv_, selstartpar, selstartpos);
355 bv_->text->selection.cursor = bv_->text->cursor;
356 bv_->text->setCursor(bv_, selendpar, selendpos);
357 bv_->text->setSelection(bv_);
358 bv_->text->setCursor(bv_, par, pos);
360 bv_->text->setCursor(bv_, par, pos);
361 bv_->text->selection.cursor = bv_->text->cursor;
362 bv_->text->selection.set(false);
364 // remake the inset locking
365 bv_->theLockingInset(the_locking_inset);
368 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
371 owner_->allowInput();
373 /// clear the "Formatting Document" message
380 void BufferView::Pimpl::repaint()
382 // Regenerate the screen.
383 screen().redraw(bv_->text, bv_);
387 void BufferView::Pimpl::updateScrollbar()
390 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
391 workarea().setScrollbarParams(0, 0, 0);
395 LyXText const & t = *bv_->text;
397 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
398 << t.first_y << ", default height " << t.defaultHeight() << endl;
400 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
404 void BufferView::Pimpl::scrollDocView(int value)
406 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
408 if (!buffer_) return;
410 screen().draw(bv_->text, bv_, value);
412 if (!lyxrc.cursor_follows_scrollbar) {
416 LyXText * vbt = bv_->text;
418 int const height = vbt->defaultHeight();
419 int const first = static_cast<int>((bv_->text->first_y + height));
420 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
422 if (vbt->cursor.y() < first)
423 vbt->setCursorFromCoordinates(bv_, 0, first);
424 else if (vbt->cursor.y() > last)
425 vbt->setCursorFromCoordinates(bv_, 0, last);
429 int BufferView::Pimpl::scroll(long time)
434 LyXText const * t = bv_->text;
436 double const diff = t->defaultHeight()
437 + double(time) * double(time) * 0.125;
439 scrollDocView(int(diff));
440 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
445 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
446 key_modifier::state state)
448 bv_->owner()->getLyXFunc()->processKeySym(key, state);
452 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
454 // Only use motion with button 1
455 if (!(state & mouse_button::button1))
461 // Check for inset locking
462 if (bv_->theLockingInset()) {
463 LyXCursor cursor = bv_->text->cursor;
464 LyXFont font = bv_->text->getFont(buffer_,
465 cursor.par(), cursor.pos());
466 int width = bv_->theLockingInset()->width(bv_, font);
467 int inset_x = font.isVisibleRightToLeft()
468 ? cursor.ix() - width : cursor.ix();
469 int start_x = inset_x + bv_->theLockingInset()->scroll();
471 bv_->theLockingInset()->
472 insetMotionNotify(bv_,
474 y - cursor.iy() + bv_->text->first_y,
479 /* The test for not selection possible is needed, that only motion
480 events are used, where the bottom press event was on
481 the drawing area too */
482 if (!selection_possible)
485 screen().hideCursor();
487 Row * cursorrow = bv_->text->cursor.row();
488 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
490 // sorry for this but I have a strange error that the y value jumps at
491 // a certain point. This seems like an error in my xforms library or
492 // in some other local environment, but I would like to leave this here
493 // for the moment until I can remove this (Jug 20020418)
494 if (y_before < bv_->text->cursor.y())
495 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
497 // This is to allow jumping over large insets
498 if (cursorrow == bv_->text->cursor.row()) {
499 if (y >= int(workarea().workHeight())) {
500 bv_->text->cursorDown(bv_, false);
502 bv_->text->cursorUp(bv_, false);
506 if (!bv_->text->selection.set())
507 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
509 bv_->text->setSelection(bv_);
510 screen().toggleToggle(bv_->text, bv_);
516 // Single-click on work area
517 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
518 mouse_button::state button)
523 // ok ok, this is a hack (for xforms)
524 if (button == mouse_button::button4) {
525 scroll(-lyxrc.wheel_jump);
526 // We shouldn't go further down as we really should only do the
527 // scrolling and be done with this. Otherwise we may open some
528 // dialogs (Jug 20020424).
530 } else if (button == mouse_button::button5) {
531 scroll(lyxrc.wheel_jump);
532 // We shouldn't go further down as we really should only do the
533 // scrolling and be done with this. Otherwise we may open some
534 // dialogs (Jug 20020424).
538 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
540 // Middle button press pastes if we have a selection
541 // We do this here as if the selection was inside an inset
542 // it could get cleared on the unlocking of the inset so
543 // we have to check this first
544 bool paste_internally = false;
545 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
546 owner_->getLyXFunc()->dispatch(LFUN_COPY);
547 paste_internally = true;
550 int const screen_first = bv_->text->first_y;
552 if (bv_->theLockingInset()) {
553 // We are in inset locking mode
555 /* Check whether the inset was hit. If not reset mode,
556 otherwise give the event to the inset */
557 if (inset_hit == bv_->theLockingInset()) {
558 bv_->theLockingInset()->
559 insetButtonPress(bv_, xpos, ypos, button);
562 bv_->unlockInset(bv_->theLockingInset());
567 selection_possible = true;
568 screen().hideCursor();
570 // Clear the selection
571 screen().toggleSelection(bv_->text, bv_);
572 bv_->text->clearSelection();
573 bv_->text->fullRebreak(bv_);
577 // Single left click in math inset?
578 if (isHighlyEditableInset(inset_hit)) {
579 // Highly editable inset, like math
580 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
581 selection_possible = false;
582 owner_->updateLayoutChoice();
583 owner_->message(inset->editMessage());
584 //inset->edit(bv_, xpos, ypos, button);
585 // We just have to lock the inset before calling a PressEvent on it!
586 // we don't need the edit() call here! (Jug20020329)
587 if (!bv_->lockInset(inset)) {
588 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
590 inset->insetButtonPress(bv_, xpos, ypos, button);
593 // I'm not sure we should continue here if we hit an inset (Jug20020403)
595 // Right click on a footnote flag opens float menu
596 if (button == mouse_button::button3) {
597 selection_possible = false;
601 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
602 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
604 bv_->text->selection.cursor = bv_->text->cursor;
605 bv_->text->cursor.x_fix(bv_->text->cursor.x());
607 owner_->updateLayoutChoice();
609 selection_possible = false;
612 // Insert primary selection with middle mouse
613 // if there is a local selection in the current buffer,
615 if (button == mouse_button::button2) {
616 if (paste_internally)
617 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
619 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
620 string("paragraph"));
621 selection_possible = false;
627 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
632 LyXText * text = bv_->getLyXText();
634 if (text->bv_owner && bv_->theLockingInset())
637 if (button == mouse_button::button1) {
638 if (text->bv_owner) {
639 screen().hideCursor();
640 screen().toggleSelection(text, bv_);
641 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
642 screen().toggleSelection(text, bv_, false);
644 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
646 /* This will fit the cursor on the screen
648 update(text, BufferView::SELECT|BufferView::FITCUR);
653 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
658 LyXText * text = bv_->getLyXText();
660 if (text->bv_owner && bv_->theLockingInset())
663 if (button == mouse_button::button1) {
664 if (text->bv_owner) {
665 screen().hideCursor();
666 screen().toggleSelection(text, bv_);
668 text->cursorHome(bv_);
669 text->selection.cursor = text->cursor;
670 text->cursorEnd(bv_);
671 text->setSelection(bv_);
672 if (text->bv_owner) {
673 screen().toggleSelection(text, bv_, false);
675 /* This will fit the cursor on the screen
677 update(text, BufferView::SELECT|BufferView::FITCUR);
682 void BufferView::Pimpl::selectionRequested()
689 LyXText * text = bv_->getLyXText();
691 if (text->selection.set() &&
692 (!bv_->text->xsel_cache.set() ||
693 text->selection.start != bv_->text->xsel_cache.start ||
694 text->selection.end != bv_->text->xsel_cache.end))
696 bv_->text->xsel_cache = text->selection;
697 sel = text->selectionAsString(bv_->buffer(), false);
698 } else if (!text->selection.set()) {
700 bv_->text->xsel_cache.set(false);
703 workarea().putClipboard(sel);
708 void BufferView::Pimpl::selectionLost()
713 bv_->getLyXText()->clearSelection();
715 bv_->text->xsel_cache.set(false);
720 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
721 mouse_button::state button)
723 // do nothing if we used the mouse wheel
724 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
727 // If we hit an inset, we have the inset coordinates in these
728 // and inset_hit points to the inset. If we do not hit an
729 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
730 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
732 if (bv_->theLockingInset()) {
733 // We are in inset locking mode.
735 /* LyX does a kind of work-area grabbing for insets.
736 Only a ButtonPress Event outside the inset will
737 force a insetUnlock. */
738 bv_->theLockingInset()->
739 insetButtonRelease(bv_, x, y, button);
743 selection_possible = false;
745 if (button == mouse_button::button2)
749 if (button == mouse_button::button1) {
750 workarea().haveSelection(bv_->getLyXText()->selection.set());
754 owner_->view_state_changed();
755 owner_->updateMenubar();
756 owner_->updateToolbar();
758 // Did we hit an editable inset?
760 selection_possible = false;
762 // if we reach this point with a selection, it
763 // must mean we are currently selecting.
764 // But we don't want to open the inset
765 // because that is annoying for the user.
766 // So just pretend we didn't hit it.
767 // this is OK because a "kosher" ButtonRelease
768 // will follow a ButtonPress that clears
770 // Note this also fixes selection drawing
771 // problems if we end up opening an inset
772 if (bv_->getLyXText()->selection.set())
775 // CHECK fix this proper in 0.13
776 // well, maybe 13.0 !!!!!!!!!
778 // Following a ref shouldn't issue
779 // a push on the undo-stack
780 // anylonger, now that we have
781 // keybindings for following
782 // references and returning from
783 // references. IMHO though, it
784 // should be the inset's own business
785 // to push or not push on the undo
786 // stack. They don't *have* to
787 // alter the document...
789 // ...or maybe the SetCursorParUndo()
790 // below isn't necessary at all anylonger?
791 if (inset_hit->lyxCode() == Inset::REF_CODE) {
792 setCursorParUndo(bv_);
795 owner_->message(inset_hit->editMessage());
797 if (isHighlyEditableInset(inset_hit)) {
798 // Highly editable inset, like math
799 UpdatableInset *inset = (UpdatableInset *)inset_hit;
800 inset->insetButtonRelease(bv_, x, y, button);
802 inset_hit->insetButtonRelease(bv_, x, y, button);
803 // IMO this is a grosshack! Inset's should be changed so that
804 // they call the actions they have to do with the insetButtonRel.
805 // function and not in the edit(). This should be changed
807 inset_hit->edit(bv_, x, y, button);
812 // Maybe we want to edit a bibitem ale970302
813 if (bv_->text->cursor.par()->bibkey) {
814 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
815 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
816 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
817 (!is_rtl && x < 20+width)) {
818 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
826 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
827 LyXCursor const & cursor) const
829 Paragraph /*const*/ & par = *cursor.par();
830 pos_type const pos = cursor.pos();
832 lyx::Assert(par.getInset(pos));
834 Inset const & inset(*par.getInset(pos));
836 LyXFont const & font = text.getFont(buffer_, &par, pos);
838 int const width = inset.width(bv_, font);
839 int const inset_x = font.isVisibleRightToLeft()
840 ? (cursor.ix() - width) : cursor.ix();
843 inset_x + inset.scroll(),
845 cursor.iy() - inset.ascent(bv_, font),
846 cursor.iy() + inset.descent(bv_, font));
850 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
851 LyXCursor const & cursor,
852 int & x, int & y) const
854 pos_type const pos(cursor.pos());
855 Paragraph /*const*/ & par(*cursor.par());
857 if (pos >= par.size() || !par.isInset(pos)) {
861 Inset /*const*/ * inset = par.getInset(pos);
863 if (!isEditableInset(inset)) {
867 Box b(insetDimensions(text, cursor));
869 if (!b.contained(x, y)) {
870 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
871 << " box " << b << endl;
875 text.setCursor(bv_, &par, pos, true);
878 // The origin of an inset is on the baseline
879 y -= text.cursor.iy();
885 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
887 int y_tmp = y + text->first_y;
890 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
892 Inset * inset(checkInset(*text, cursor, x, y_tmp));
899 // look at previous position
901 if (cursor.pos() == 0) {
906 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
908 inset = checkInset(*text, cursor, x, y_tmp);
916 void BufferView::Pimpl::workAreaResize()
918 static int work_area_width;
919 static int work_area_height;
921 bool const widthChange = workarea().workWidth() != work_area_width;
922 bool const heightChange = workarea().workHeight() != work_area_height;
924 // update from work area
925 work_area_width = workarea().workWidth();
926 work_area_height = workarea().workHeight();
930 // The visible LyXView need a resize
931 resizeCurrentBuffer();
933 // Remove all texts from the textcache
934 // This is not _really_ what we want to do. What
935 // we really want to do is to delete in textcache
936 // that does not have a BufferView with matching
937 // width, but as long as we have only one BufferView
938 // deleting all gives the same result.
939 if (lyxerr.debugging())
940 textcache.show(lyxerr, "Expose delete all");
942 // FIXME: this is aalready done in resizeCurrentBuffer() ??
943 buffer_->resizeInsets(bv_);
944 } else if (heightChange) {
945 // fitCursor() ensures we don't jump back
946 // to the start of the document on vertical
952 if (widthChange || heightChange) {
956 // always make sure that the scrollbar is sane.
958 owner_->updateLayoutChoice();
963 void BufferView::Pimpl::update()
965 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
966 LyXText::text_status st = bv_->text->status();
967 screen().update(bv_->text, bv_);
969 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
970 bv_->text->fullRebreak(bv_);
971 st = LyXText::NEED_MORE_REFRESH;
972 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
973 bv_->text->cursor.pos());
974 if (bv_->text->selection.set()) {
975 bv_->text->setCursor(bv_, bv_->text->selection.start,
976 bv_->text->selection.start.par(),
977 bv_->text->selection.start.pos());
978 bv_->text->setCursor(bv_, bv_->text->selection.end,
979 bv_->text->selection.end.par(),
980 bv_->text->selection.end.pos());
983 bv_->text->status(bv_, st);
984 screen().update(bv_->text, bv_);
986 // do this here instead of in the screen::update because of
988 bv_->text->status(bv_, LyXText::UNCHANGED);
994 // Values used when calling update:
996 // -2 - update, move sel_cursor if selection, fitcursor
997 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
998 // 0 - update, move sel_cursor if selection, fitcursor
999 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1000 // 3 - update, move sel_cursor if selection
1003 // a simple redraw of the parts that need refresh
1005 // move sel_cursor if selection -
1006 // the text's sel_cursor is moved if there is selection is progress
1009 // fitCursor() is called and the scrollbar updated
1012 // the buffer is marked dirty.
1021 // UPDATE_ONLY = UPDATE;
1022 // UPDATE_SELECT = UPDATE | SELECT;
1023 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1024 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1026 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1027 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1028 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1029 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1030 // update(3) -> update(1) -> update(1) -> update(SELECT)
1032 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1034 owner_->updateLayoutChoice();
1036 if (!text->selection.set() && (f & SELECT)) {
1037 text->selection.cursor = text->cursor;
1040 text->fullRebreak(bv_);
1042 if (text->inset_owner) {
1043 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1044 updateInset(text->inset_owner, false);
1054 buffer_->markDirty();
1059 // Callback for cursor timer
1060 void BufferView::Pimpl::cursorToggle()
1063 cursor_timeout.restart();
1068 extern void reapSpellchecker(void);
1071 if (!bv_->theLockingInset()) {
1072 screen().cursorToggle(bv_);
1074 bv_->theLockingInset()->toggleInsetCursor(bv_);
1077 cursor_timeout.restart();
1081 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1083 if (!text->cursor.row()->previous()) {
1084 if (text->first_y > 0) {
1085 int new_y = bv_->text->first_y - workarea().workHeight();
1086 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1092 int y = text->first_y;
1093 Row * cursorrow = text->cursor.row();
1095 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1099 if (cursorrow == bv_->text->cursor.row()) {
1100 // we have a row which is higher than the workarea so we leave the
1101 // cursor on the start of the row and move only the draw up as soon
1102 // as we move the cursor or do something while inside the row (it may
1103 // span several workarea-heights) we'll move to the top again, but this
1104 // is better than just jump down and only display part of the row.
1105 new_y = bv_->text->first_y - workarea().workHeight();
1107 if (text->inset_owner) {
1108 new_y = bv_->text->cursor.iy()
1109 + bv_->theLockingInset()->insetInInsetY() + y
1110 + text->cursor.row()->height()
1111 - workarea().workHeight() + 1;
1113 new_y = text->cursor.y()
1114 - text->cursor.row()->baseline()
1115 + text->cursor.row()->height()
1116 - workarea().workHeight() + 1;
1119 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1120 if (text->cursor.row()->previous()) {
1122 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1123 text->cursor.row()->previous()->pos(), false);
1124 if (cur.y() > text->first_y) {
1125 text->cursorUp(bv_, true);
1132 void BufferView::Pimpl::cursorNext(LyXText * text)
1134 if (!text->cursor.row()->next()) {
1135 int y = text->cursor.y() - text->cursor.row()->baseline() +
1136 text->cursor.row()->height();
1137 if (y > int(text->first_y + workarea().workHeight())) {
1138 screen().draw(bv_->text, bv_,
1139 bv_->text->first_y + workarea().workHeight());
1145 int y = text->first_y + workarea().workHeight();
1146 if (text->inset_owner && !text->first_y) {
1147 y -= (bv_->text->cursor.iy()
1148 - bv_->text->first_y
1149 + bv_->theLockingInset()->insetInInsetY());
1152 text->getRowNearY(y);
1154 Row * cursorrow = text->cursor.row();
1155 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1159 if (cursorrow == bv_->text->cursor.row()) {
1160 // we have a row which is higher than the workarea so we leave the
1161 // cursor on the start of the row and move only the draw down as soon
1162 // as we move the cursor or do something while inside the row (it may
1163 // span several workarea-heights) we'll move to the top again, but this
1164 // is better than just jump down and only display part of the row.
1165 new_y = bv_->text->first_y + workarea().workHeight();
1167 if (text->inset_owner) {
1168 new_y = bv_->text->cursor.iy()
1169 + bv_->theLockingInset()->insetInInsetY()
1170 + y - text->cursor.row()->baseline();
1172 new_y = text->cursor.y() - text->cursor.row()->baseline();
1175 screen().draw(bv_->text, bv_, new_y);
1176 if (text->cursor.row()->next()) {
1178 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1179 text->cursor.row()->next()->pos(), false);
1180 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1181 text->cursorDown(bv_, true);
1188 bool BufferView::Pimpl::available() const
1190 if (buffer_ && bv_->text)
1196 void BufferView::Pimpl::beforeChange(LyXText * text)
1199 text->clearSelection();
1203 void BufferView::Pimpl::savePosition(unsigned int i)
1205 if (i >= saved_positions_num)
1207 saved_positions[i] = Position(buffer_->fileName(),
1208 bv_->text->cursor.par()->id(),
1209 bv_->text->cursor.pos());
1212 str << _("Saved bookmark") << ' ' << i;
1213 owner_->message(str.str().c_str());
1218 void BufferView::Pimpl::restorePosition(unsigned int i)
1220 if (i >= saved_positions_num)
1223 string const fname = saved_positions[i].filename;
1225 beforeChange(bv_->text);
1227 if (fname != buffer_->fileName()) {
1228 Buffer * b = bufferlist.exists(fname) ?
1229 bufferlist.getBuffer(fname) :
1230 bufferlist.loadLyXFile(fname); // don't ask, just load it
1231 if (b != 0) buffer(b);
1234 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1238 bv_->text->setCursor(bv_, par,
1239 min(par->size(), saved_positions[i].par_pos));
1241 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1244 str << _("Moved to bookmark") << ' ' << i;
1245 owner_->message(str.str().c_str());
1250 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1252 if (i >= saved_positions_num)
1255 return !saved_positions[i].filename.empty();
1259 void BufferView::Pimpl::switchKeyMap()
1261 if (!lyxrc.rtl_support)
1264 LyXText * text = bv_->getLyXText();
1265 if (text->real_current_font.isRightToLeft()
1266 && !(bv_->theLockingInset()
1267 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1269 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1270 owner_->getIntl()->KeyMapSec();
1272 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1273 owner_->getIntl()->KeyMapPrim();
1278 void BufferView::Pimpl::insetUnlock()
1280 if (bv_->theLockingInset()) {
1281 bv_->theLockingInset()->insetUnlock(bv_);
1282 bv_->theLockingInset(0);
1288 void BufferView::Pimpl::showCursor()
1290 if (bv_->theLockingInset())
1291 bv_->theLockingInset()->showInsetCursor(bv_);
1293 screen().showCursor(bv_->text, bv_);
1297 void BufferView::Pimpl::hideCursor()
1299 if (!bv_->theLockingInset())
1300 screen().hideCursor();
1304 void BufferView::Pimpl::toggleSelection(bool b)
1306 if (bv_->theLockingInset())
1307 bv_->theLockingInset()->toggleSelection(bv_, b);
1308 screen().toggleSelection(bv_->text, bv_, b);
1312 void BufferView::Pimpl::toggleToggle()
1314 screen().toggleToggle(bv_->text, bv_);
1318 void BufferView::Pimpl::center()
1320 LyXText * t = bv_->text;
1323 int const half_height = workarea().workHeight() / 2;
1326 if (t->cursor.y() > half_height) {
1327 new_y = t->cursor.y() - half_height;
1330 // FIXME: can we do this w/o calling screen directly ?
1331 // This updates first_y but means the fitCursor() call
1332 // from the update(FITCUR) doesn't realise that we might
1333 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1334 // the scrollbar to be updated as it should, so we have
1335 // to do it manually. Any operation that does a center()
1336 // and also might have moved first_y must make sure to call
1337 // updateScrollbar() currently. Never mind that this is a
1338 // pretty obfuscated way of updating t->first_y
1339 screen().draw(t, bv_, new_y);
1341 update(t, BufferView::SELECT | BufferView::FITCUR);
1345 void BufferView::Pimpl::pasteClipboard(bool asPara)
1350 screen().hideCursor();
1351 beforeChange(bv_->text);
1353 string const clip(workarea().getClipboard());
1359 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1361 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1363 bv_->getLyXText()->clearSelection();
1364 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1368 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1370 workarea().putClipboard(stuff);
1375 * Dispatch functions for actions which can be valid for BufferView->text
1376 * and/or InsetText->text!!!
1381 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1383 LyXText * lt = bv_->getLyXText();
1385 if (selecting || lt->selection.mark()) {
1386 lt->setSelection(bv_);
1390 updateInset(lt->inset_owner, false);
1394 update(lt, BufferView::SELECT|BufferView::FITCUR);
1396 update(lt, BufferView::SELECT);
1398 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1399 bv_->theLockingInset()->hideInsetCursor(bv_);
1400 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1404 if (!lt->selection.set())
1405 workarea().haveSelection(false);
1411 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1413 LyXCursor cursor = bv_->getLyXText()->cursor;
1414 Buffer::inset_iterator it =
1415 find_if(Buffer::inset_iterator(
1416 cursor.par(), cursor.pos()),
1417 buffer_->inset_iterator_end(),
1418 lyx::compare_memfun(&Inset::lyxCode, code));
1419 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1423 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1425 string filename = filen;
1427 if (filename.empty()) {
1428 // Launch a file browser
1429 string initpath = lyxrc.document_path;
1432 string const trypath = owner_->buffer()->filePath();
1433 // If directory is writeable, use this as default.
1434 if (IsDirWriteable(trypath))
1438 FileDialog fileDlg(bv_->owner(),
1439 _("Select LyX document to insert"),
1441 make_pair(string(_("Documents|#o#O")),
1442 string(lyxrc.document_path)),
1443 make_pair(string(_("Examples|#E#e")),
1444 string(AddPath(system_lyxdir, "examples"))));
1446 FileDialog::Result result =
1447 fileDlg.Select(initpath,
1448 _("*.lyx| LyX Documents (*.lyx)"));
1450 if (result.first == FileDialog::Later)
1453 filename = result.second;
1455 // check selected filename
1456 if (filename.empty()) {
1457 owner_->message(_("Canceled."));
1462 // get absolute path of file and add ".lyx" to the filename if
1464 filename = FileSearch(string(), filename, "lyx");
1466 string const disp_fn(MakeDisplayPath(filename));
1469 s1 << _("Inserting document") << ' '
1470 << disp_fn << " ...";
1471 owner_->message(s1.str().c_str());
1472 bool const res = bv_->insertLyXFile(filename);
1475 str << _("Document") << ' ' << disp_fn
1476 << ' ' << _("inserted.");
1477 owner_->message(str.str().c_str());
1480 str << _("Could not insert document") << ' '
1482 owner_->message(str.str().c_str());
1487 bool BufferView::Pimpl::dispatch(kb_action action, string const & argument)
1489 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1490 << action <<"] arg[" << argument << "]" << endl;
1492 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1495 // --- Misc -------------------------------------------
1499 LyXText * lt = bv_->getLyXText();
1500 lt->toggleAppendix(bv_);
1503 | BufferView::FITCUR
1504 | BufferView::CHANGE);
1509 case LFUN_TOC_INSERT:
1511 InsetCommandParams p;
1512 p.setCmdName("tableofcontents");
1513 Inset * inset = new InsetTOC(p);
1514 if (!insertInset(inset, tclass.defaultLayoutName()))
1519 case LFUN_SCROLL_INSET:
1520 // this is not handled here as this funktion is only aktive
1521 // if we have a locking_inset and that one is (or contains)
1525 case LFUN_INSET_GRAPHICS:
1527 Inset * new_inset = new InsetGraphics;
1528 if (!insertInset(new_inset)) {
1531 // this is need because you don't use a inset->Edit()
1532 updateInset(new_inset, true);
1533 new_inset->edit(bv_);
1543 case LFUN_PASTESELECTION:
1545 bool asPara = false;
1546 if (argument == "paragraph")
1548 pasteClipboard(asPara);
1560 case LFUN_LAYOUT_COPY:
1561 bv_->copyEnvironment();
1564 case LFUN_LAYOUT_PASTE:
1565 bv_->pasteEnvironment();
1569 case LFUN_GOTOERROR:
1570 gotoInset(Inset::ERROR_CODE, false);
1574 gotoInset(Inset::IGNORE_CODE, false);
1577 case LFUN_REFERENCE_GOTO:
1579 vector<Inset::Code> tmp;
1580 tmp.push_back(Inset::LABEL_CODE);
1581 tmp.push_back(Inset::REF_CODE);
1582 gotoInset(tmp, true);
1586 case LFUN_HYPHENATION:
1587 specialChar(InsetSpecialChar::HYPHENATION);
1590 case LFUN_LIGATURE_BREAK:
1591 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1595 specialChar(InsetSpecialChar::LDOTS);
1598 case LFUN_END_OF_SENTENCE:
1599 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1602 case LFUN_MENU_SEPARATOR:
1603 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1610 case LFUN_DEPTH_MIN:
1611 changeDepth(bv_, bv_->getLyXText(), -1);
1614 case LFUN_DEPTH_PLUS:
1615 changeDepth(bv_, bv_->getLyXText(), 1);
1619 owner_->getDialogs()->setUserFreeFont();
1622 case LFUN_FILE_INSERT:
1623 MenuInsertLyXFile(argument);
1626 case LFUN_FILE_INSERT_ASCII_PARA:
1627 InsertAsciiFile(bv_, argument, true);
1630 case LFUN_FILE_INSERT_ASCII:
1631 InsertAsciiFile(bv_, argument, false);
1636 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1637 << argument << endl;
1639 // This is not the good solution to the empty argument
1640 // problem, but it will hopefully suffice for 1.2.0.
1641 // The correct solution would be to augument the
1642 // function list/array with information about what
1643 // functions needs arguments and their type.
1644 if (argument.empty()) {
1645 owner_->getLyXFunc()->setErrorMessage(
1646 _("LyX function 'layout' needs an argument."));
1650 // Derive layout number from given argument (string)
1651 // and current buffer's textclass (number). */
1652 bool hasLayout = tclass.hasLayout(argument);
1653 string layout = argument;
1655 // If the entry is obsolete, use the new one instead.
1657 string const & obs = tclass[layout]->obsoleted_by();
1663 owner_->getLyXFunc()->setErrorMessage(
1664 string(N_("Layout ")) + argument +
1669 bool change_layout = (current_layout != layout);
1670 LyXText * lt = bv_->getLyXText();
1671 if (!change_layout && lt->selection.set() &&
1672 lt->selection.start.par() != lt->selection.end.par())
1674 Paragraph * spar = lt->selection.start.par();
1675 Paragraph * epar = lt->selection.end.par()->next();
1676 while(spar != epar) {
1677 if (spar->layout()->name() != current_layout) {
1678 change_layout = true;
1683 if (change_layout) {
1685 current_layout = layout;
1688 | BufferView::FITCUR);
1689 lt->setLayout(bv_, layout);
1690 owner_->setLayout(layout);
1693 | BufferView::FITCUR
1694 | BufferView::CHANGE);
1701 lang(bv_, argument);
1703 owner_->view_state_changed();
1708 owner_->view_state_changed();
1713 owner_->view_state_changed();
1718 owner_->view_state_changed();
1723 owner_->view_state_changed();
1728 owner_->view_state_changed();
1733 owner_->view_state_changed();
1738 owner_->view_state_changed();
1741 case LFUN_UNDERLINE:
1743 owner_->view_state_changed();
1746 case LFUN_FONT_SIZE:
1747 fontSize(bv_, argument);
1748 owner_->view_state_changed();
1751 case LFUN_FONT_STATE:
1752 owner_->getLyXFunc()->setMessage(currentState(bv_));
1755 case LFUN_UPCASE_WORD:
1757 LyXText * lt = bv_->getLyXText();
1761 | BufferView::FITCUR);
1762 lt->changeCase(bv_, LyXText::text_uppercase);
1763 if (lt->inset_owner)
1764 updateInset(lt->inset_owner, true);
1767 | BufferView::FITCUR
1768 | BufferView::CHANGE);
1772 case LFUN_LOWCASE_WORD:
1774 LyXText * lt = bv_->getLyXText();
1776 update(lt, BufferView::SELECT|BufferView::FITCUR);
1777 lt->changeCase(bv_, LyXText::text_lowercase);
1778 if (lt->inset_owner)
1779 updateInset(lt->inset_owner, true);
1782 | BufferView::FITCUR
1783 | BufferView::CHANGE);
1787 case LFUN_CAPITALIZE_WORD:
1789 LyXText * lt = bv_->getLyXText();
1791 update(lt, BufferView::SELECT|BufferView::FITCUR);
1792 lt->changeCase(bv_, LyXText::text_capitalization);
1793 if (lt->inset_owner)
1794 updateInset(lt->inset_owner, true);
1797 | BufferView::FITCUR
1798 | BufferView::CHANGE);
1802 case LFUN_TRANSPOSE_CHARS:
1804 LyXText * lt = bv_->getLyXText();
1806 update(lt, BufferView::SELECT|BufferView::FITCUR);
1807 lt->transposeChars(*bv_);
1808 if (lt->inset_owner)
1809 updateInset(lt->inset_owner, true);
1812 | BufferView::FITCUR
1813 | BufferView::CHANGE);
1818 case LFUN_INSERT_LABEL:
1819 MenuInsertLabel(bv_, argument);
1822 case LFUN_REF_INSERT:
1823 if (argument.empty()) {
1824 InsetCommandParams p("ref");
1825 owner_->getDialogs()->createRef(p.getAsString());
1827 InsetCommandParams p;
1828 p.setFromString(argument);
1830 InsetRef * inset = new InsetRef(p, *buffer_);
1831 if (!insertInset(inset))
1834 updateInset(inset, true);
1838 case LFUN_BOOKMARK_SAVE:
1839 savePosition(strToUnsignedInt(argument));
1842 case LFUN_BOOKMARK_GOTO:
1843 restorePosition(strToUnsignedInt(argument));
1848 string label(argument);
1849 if (label.empty()) {
1851 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1853 label = inset->getContents();
1858 if (!label.empty()) {
1859 //bv_->savePosition(0);
1860 if (!bv_->gotoLabel(label))
1861 Alert::alert(_("Error"),
1862 _("Couldn't find this label"),
1863 _("in current document."));
1868 // --- Cursor Movements -----------------------------
1871 LyXText * lt = bv_->getLyXText();
1873 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1874 if (!lt->selection.mark())
1876 update(lt, BufferView::SELECT|BufferView::FITCUR);
1878 lt->cursorLeft(bv_, false);
1879 if (lt->cursor.pos() < lt->cursor.par()->size()
1880 && lt->cursor.par()->isInset(lt->cursor.pos())
1881 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1882 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1883 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1885 tmpinset->edit(bv_, false);
1887 tmpinset->edit(bv_);
1891 lt->cursorRight(bv_, false);
1893 moveCursorUpdate(false);
1894 owner_->view_state_changed();
1900 // This is soooo ugly. Isn`t it possible to make
1901 // it simpler? (Lgb)
1902 LyXText * lt = bv_->getLyXText();
1903 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1904 if (!lt->selection.mark())
1906 update(lt, BufferView::SELECT|BufferView::FITCUR);
1907 LyXCursor const cur = lt->cursor;
1909 lt->cursorLeft(bv_, false);
1910 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1911 lt->cursor.pos() < lt->cursor.par()->size() &&
1912 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1913 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1914 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1915 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1917 tmpinset->edit(bv_);
1919 tmpinset->edit(bv_, false);
1923 lt->cursorRight(bv_, false);
1926 moveCursorUpdate(false);
1927 owner_->view_state_changed();
1933 LyXText * lt = bv_->getLyXText();
1935 if (!lt->selection.mark())
1937 update(lt, BufferView::UPDATE);
1940 moveCursorUpdate(false);
1941 owner_->view_state_changed();
1947 LyXText * lt = bv_->getLyXText();
1949 if (!lt->selection.mark())
1951 update(lt, BufferView::UPDATE);
1952 lt->cursorDown(bv_);
1954 moveCursorUpdate(false);
1955 owner_->view_state_changed();
1959 case LFUN_UP_PARAGRAPH:
1961 LyXText * lt = bv_->getLyXText();
1963 if (!lt->selection.mark())
1965 update(lt, BufferView::UPDATE);
1966 lt->cursorUpParagraph(bv_);
1968 moveCursorUpdate(false);
1969 owner_->view_state_changed();
1973 case LFUN_DOWN_PARAGRAPH:
1975 LyXText * lt = bv_->getLyXText();
1977 if (!lt->selection.mark())
1979 update(lt, BufferView::UPDATE);
1980 lt->cursorDownParagraph(bv_);
1982 moveCursorUpdate(false);
1983 owner_->view_state_changed();
1989 LyXText * lt = bv_->getLyXText();
1991 if (!lt->selection.mark())
1993 update(lt, BufferView::UPDATE);
1996 moveCursorUpdate(false, false);
1997 owner_->view_state_changed();
2003 LyXText * lt = bv_->getLyXText();
2005 if (!lt->selection.mark())
2007 update(lt, BufferView::UPDATE);
2010 moveCursorUpdate(false, false);
2011 owner_->view_state_changed();
2017 LyXText * lt = bv_->getLyXText();
2019 if (!lt->selection.mark())
2021 update(lt, BufferView::SELECT|BufferView::FITCUR);
2022 lt->cursorHome(bv_);
2024 moveCursorUpdate(false);
2025 owner_->view_state_changed();
2031 LyXText * lt = bv_->getLyXText();
2033 if (!lt->selection.mark())
2036 BufferView::SELECT|BufferView::FITCUR);
2039 moveCursorUpdate(false);
2040 owner_->view_state_changed();
2044 case LFUN_SHIFT_TAB:
2047 LyXText * lt = bv_->getLyXText();
2049 if (!lt->selection.mark())
2052 BufferView::SELECT|BufferView::FITCUR);
2055 moveCursorUpdate(false);
2056 owner_->view_state_changed();
2060 case LFUN_WORDRIGHT:
2062 LyXText * lt = bv_->getLyXText();
2064 if (!lt->selection.mark())
2066 update(lt, BufferView::SELECT|BufferView::FITCUR);
2067 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2068 lt->cursorLeftOneWord(bv_);
2070 lt->cursorRightOneWord(bv_);
2072 moveCursorUpdate(false);
2073 owner_->view_state_changed();
2079 LyXText * lt = bv_->getLyXText();
2081 if (!lt->selection.mark())
2083 update(lt, BufferView::SELECT|BufferView::FITCUR);
2084 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2085 lt->cursorRightOneWord(bv_);
2087 lt->cursorLeftOneWord(bv_);
2089 moveCursorUpdate(false);
2090 owner_->view_state_changed();
2094 case LFUN_BEGINNINGBUF:
2096 LyXText * lt = bv_->getLyXText();
2098 if (!lt->selection.mark())
2101 BufferView::SELECT|BufferView::FITCUR);
2104 moveCursorUpdate(false);
2105 owner_->view_state_changed();
2111 LyXText * lt = bv_->getLyXText();
2113 if (!lt->selection.mark())
2116 BufferView::SELECT|BufferView::FITCUR);
2117 lt->cursorBottom(bv_);
2119 moveCursorUpdate(false);
2120 owner_->view_state_changed();
2124 /* cursor selection ---------------------------- */
2127 LyXText * lt = bv_->getLyXText();
2130 BufferView::SELECT|BufferView::FITCUR);
2131 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2132 lt->cursorLeft(bv_);
2134 lt->cursorRight(bv_);
2136 moveCursorUpdate(true);
2137 owner_->view_state_changed();
2143 LyXText * lt = bv_->getLyXText();
2146 BufferView::SELECT|BufferView::FITCUR);
2147 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2148 lt->cursorRight(bv_);
2150 lt->cursorLeft(bv_);
2152 moveCursorUpdate(true);
2153 owner_->view_state_changed();
2159 LyXText * lt = bv_->getLyXText();
2162 BufferView::SELECT|BufferView::FITCUR);
2163 lt->cursorUp(bv_, true);
2165 moveCursorUpdate(true);
2166 owner_->view_state_changed();
2172 LyXText * lt = bv_->getLyXText();
2175 BufferView::SELECT|BufferView::FITCUR);
2176 lt->cursorDown(bv_, true);
2178 moveCursorUpdate(true);
2179 owner_->view_state_changed();
2183 case LFUN_UP_PARAGRAPHSEL:
2185 LyXText * lt = bv_->getLyXText();
2188 BufferView::SELECT|BufferView::FITCUR);
2189 lt->cursorUpParagraph(bv_);
2191 moveCursorUpdate(true);
2192 owner_->view_state_changed();
2196 case LFUN_DOWN_PARAGRAPHSEL:
2198 LyXText * lt = bv_->getLyXText();
2201 BufferView::SELECT|BufferView::FITCUR);
2202 lt->cursorDownParagraph(bv_);
2204 moveCursorUpdate(true);
2205 owner_->view_state_changed();
2211 LyXText * lt = bv_->getLyXText();
2213 update(lt, BufferView::SELECT|BufferView::FITCUR);
2216 moveCursorUpdate(true);
2217 owner_->view_state_changed();
2223 LyXText * lt = bv_->getLyXText();
2225 update(lt, BufferView::SELECT|BufferView::FITCUR);
2228 moveCursorUpdate(true);
2229 owner_->view_state_changed();
2235 LyXText * lt = bv_->getLyXText();
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 lt->cursorHome(bv_);
2240 moveCursorUpdate(true);
2241 owner_->view_state_changed();
2247 LyXText * lt = bv_->getLyXText();
2249 update(lt, BufferView::SELECT|BufferView::FITCUR);
2252 moveCursorUpdate(true);
2253 owner_->view_state_changed();
2257 case LFUN_WORDRIGHTSEL:
2259 LyXText * lt = bv_->getLyXText();
2261 update(lt, BufferView::SELECT|BufferView::FITCUR);
2262 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2263 lt->cursorLeftOneWord(bv_);
2265 lt->cursorRightOneWord(bv_);
2267 moveCursorUpdate(true);
2268 owner_->view_state_changed();
2272 case LFUN_WORDLEFTSEL:
2274 LyXText * lt = bv_->getLyXText();
2276 update(lt, BufferView::SELECT|BufferView::FITCUR);
2277 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2278 lt->cursorRightOneWord(bv_);
2280 lt->cursorLeftOneWord(bv_);
2282 moveCursorUpdate(true);
2283 owner_->view_state_changed();
2287 case LFUN_BEGINNINGBUFSEL:
2289 LyXText * lt = bv_->getLyXText();
2291 if (lt->inset_owner)
2293 update(lt, BufferView::SELECT|BufferView::FITCUR);
2296 moveCursorUpdate(true);
2297 owner_->view_state_changed();
2301 case LFUN_ENDBUFSEL:
2303 LyXText * lt = bv_->getLyXText();
2305 if (lt->inset_owner)
2308 BufferView::SELECT|BufferView::FITCUR);
2309 lt->cursorBottom(bv_);
2311 moveCursorUpdate(true);
2312 owner_->view_state_changed();
2316 // --- text changing commands ------------------------
2317 case LFUN_BREAKLINE:
2319 LyXText * lt = bv_->getLyXText();
2322 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2325 | BufferView::FITCUR
2326 | BufferView::CHANGE);
2327 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2328 moveCursorUpdate(false);
2332 case LFUN_PROTECTEDSPACE:
2334 LyXText * lt = bv_->getLyXText();
2335 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2337 if (style->free_spacing) {
2338 lt->insertChar(bv_, ' ');
2341 | BufferView::FITCUR
2342 | BufferView::CHANGE);
2344 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2346 moveCursorUpdate(false);
2352 LyXText * lt = bv_->getLyXText();
2354 if (lt->selection.mark()) {
2358 | BufferView::FITCUR);
2359 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2362 lt->selection.mark(true);
2365 | BufferView::FITCUR);
2366 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2368 lt->selection.cursor = lt->cursor;
2374 LyXText * lt = bv_->getLyXText();
2376 if (!lt->selection.set()) {
2378 lt->selection.cursor = lt->cursor;
2381 | BufferView::FITCUR
2382 | BufferView::CHANGE);
2383 // It is possible to make it a lot faster still
2384 // just comment out the line below...
2389 moveCursorUpdate(false);
2390 owner_->view_state_changed();
2395 case LFUN_DELETE_SKIP:
2397 LyXText * lt = bv_->getLyXText();
2399 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2401 LyXCursor cursor = lt->cursor;
2403 if (!lt->selection.set()) {
2404 if (cursor.pos() == cursor.par()->size()) {
2405 lt->cursorRight(bv_);
2406 cursor = lt->cursor;
2407 if (cursor.pos() == 0
2408 && !(cursor.par()->params().spaceTop()
2409 == VSpace (VSpace::NONE))) {
2412 cursor.par()->params().lineTop(),
2413 cursor.par()->params().lineBottom(),
2414 cursor.par()->params().pagebreakTop(),
2415 cursor.par()->params().pagebreakBottom(),
2416 VSpace(VSpace::NONE),
2417 cursor.par()->params().spaceBottom(),
2418 cursor.par()->params().spacing(),
2419 cursor.par()->params().align(),
2420 cursor.par()->params().labelWidthString(), 0);
2421 lt->cursorLeft(bv_);
2424 | BufferView::FITCUR
2425 | BufferView::CHANGE);
2427 lt->cursorLeft(bv_);
2429 lt->selection.cursor = lt->cursor;
2432 | BufferView::FITCUR
2433 | BufferView::CHANGE);
2437 lt->selection.cursor = lt->cursor;
2440 | BufferView::FITCUR
2441 | BufferView::CHANGE);
2449 /* -------> Delete word forward. */
2450 case LFUN_DELETE_WORD_FORWARD:
2451 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2452 bv_->getLyXText()->deleteWordForward(bv_);
2453 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2454 moveCursorUpdate(false);
2455 owner_->view_state_changed();
2458 /* -------> Delete word backward. */
2459 case LFUN_DELETE_WORD_BACKWARD:
2461 LyXText * lt = bv_->getLyXText();
2463 update(lt, BufferView::SELECT|BufferView::FITCUR);
2464 lt->deleteWordBackward(bv_);
2467 | BufferView::FITCUR
2468 | BufferView::CHANGE);
2469 moveCursorUpdate(false);
2470 owner_->view_state_changed();
2474 /* -------> Kill to end of line. */
2475 case LFUN_DELETE_LINE_FORWARD:
2477 LyXText * lt = bv_->getLyXText();
2479 update(lt, BufferView::SELECT|BufferView::FITCUR);
2480 lt->deleteLineForward(bv_);
2483 | BufferView::FITCUR
2484 | BufferView::CHANGE);
2485 moveCursorUpdate(false);
2489 /* -------> Set mark off. */
2492 LyXText * lt = bv_->getLyXText();
2495 update(lt, BufferView::SELECT|BufferView::FITCUR);
2496 lt->selection.cursor = lt->cursor;
2497 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2501 /* -------> Set mark on. */
2504 LyXText * lt = bv_->getLyXText();
2507 lt->selection.mark(true);
2508 update(lt, BufferView::SELECT|BufferView::FITCUR);
2509 lt->selection.cursor = lt->cursor;
2510 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2514 case LFUN_BACKSPACE:
2516 LyXText * lt = bv_->getLyXText();
2518 if (!lt->selection.set()) {
2519 if (owner_->getIntl()->getTransManager().backspace()) {
2521 lt->selection.cursor = lt->cursor;
2524 | BufferView::FITCUR
2525 | BufferView::CHANGE);
2526 // It is possible to make it a lot faster still
2527 // just comment out the line below...
2533 owner_->view_state_changed();
2538 case LFUN_BACKSPACE_SKIP:
2540 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2541 LyXText * lt = bv_->getLyXText();
2543 LyXCursor cursor = lt->cursor;
2545 if (!lt->selection.set()) {
2546 if (cursor.pos() == 0
2547 && !(cursor.par()->params().spaceTop()
2548 == VSpace (VSpace::NONE))) {
2551 cursor.par()->params().lineTop(),
2552 cursor.par()->params().lineBottom(),
2553 cursor.par()->params().pagebreakTop(),
2554 cursor.par()->params().pagebreakBottom(),
2555 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2556 cursor.par()->params().spacing(),
2557 cursor.par()->params().align(),
2558 cursor.par()->params().labelWidthString(), 0);
2561 | BufferView::FITCUR
2562 | BufferView::CHANGE);
2565 lt->selection.cursor = cursor;
2568 | BufferView::FITCUR
2569 | BufferView::CHANGE);
2576 case LFUN_BREAKPARAGRAPH:
2578 LyXText * lt = bv_->getLyXText();
2581 lt->breakParagraph(bv_, 0);
2584 | BufferView::FITCUR
2585 | BufferView::CHANGE);
2586 lt->selection.cursor = lt->cursor;
2588 owner_->view_state_changed();
2592 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2594 LyXText * lt = bv_->getLyXText();
2597 lt->breakParagraph(bv_, 1);
2600 | BufferView::FITCUR
2601 | BufferView::CHANGE);
2602 lt->selection.cursor = lt->cursor;
2604 owner_->view_state_changed();
2608 case LFUN_BREAKPARAGRAPH_SKIP:
2610 // When at the beginning of a paragraph, remove
2611 // indentation and add a "defskip" at the top.
2612 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2613 LyXText * lt = bv_->getLyXText();
2615 LyXCursor cursor = lt->cursor;
2618 if (cursor.pos() == 0) {
2619 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2622 cursor.par()->params().lineTop(),
2623 cursor.par()->params().lineBottom(),
2624 cursor.par()->params().pagebreakTop(),
2625 cursor.par()->params().pagebreakBottom(),
2626 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2627 cursor.par()->params().spacing(),
2628 cursor.par()->params().align(),
2629 cursor.par()->params().labelWidthString(), 1);
2630 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2634 lt->breakParagraph(bv_, 0);
2635 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2640 | BufferView::FITCUR
2641 | BufferView::CHANGE);
2642 lt->selection.cursor = cursor;
2644 owner_->view_state_changed();
2648 case LFUN_PARAGRAPH_SPACING:
2650 LyXText * lt = bv_->getLyXText();
2652 Paragraph * par = lt->cursor.par();
2653 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2654 float cur_value = 1.0;
2655 if (cur_spacing == Spacing::Other) {
2656 cur_value = par->params().spacing().getValue();
2659 istringstream istr(argument.c_str());
2663 Spacing::Space new_spacing = cur_spacing;
2664 float new_value = cur_value;
2666 lyxerr << "Missing argument to `paragraph-spacing'"
2668 } else if (tmp == "single") {
2669 new_spacing = Spacing::Single;
2670 } else if (tmp == "onehalf") {
2671 new_spacing = Spacing::Onehalf;
2672 } else if (tmp == "double") {
2673 new_spacing = Spacing::Double;
2674 } else if (tmp == "other") {
2675 new_spacing = Spacing::Other;
2678 lyxerr << "new_value = " << tmpval << endl;
2681 } else if (tmp == "default") {
2682 new_spacing = Spacing::Default;
2684 lyxerr << _("Unknown spacing argument: ")
2685 << argument << endl;
2687 if (cur_spacing != new_spacing || cur_value != new_value) {
2688 par->params().spacing(Spacing(new_spacing, new_value));
2689 lt->redoParagraph(bv_);
2692 | BufferView::FITCUR
2693 | BufferView::CHANGE);
2698 case LFUN_INSET_TOGGLE:
2700 LyXText * lt = bv_->getLyXText();
2703 update(lt, BufferView::SELECT|BufferView::FITCUR);
2704 lt->toggleInset(bv_);
2705 update(lt, BufferView::SELECT|BufferView::FITCUR);
2717 InsetCommandParams p;
2718 if (action == LFUN_HTMLURL)
2719 p.setCmdName("htmlurl");
2721 p.setCmdName("url");
2722 owner_->getDialogs()->createUrl(p.getAsString());
2726 case LFUN_INSERT_URL:
2728 InsetCommandParams p;
2729 p.setFromString(argument);
2731 InsetUrl * inset = new InsetUrl(p);
2732 if (!insertInset(inset))
2735 updateInset(inset, true);
2739 case LFUN_INSET_ERT:
2740 insertAndEditInset(new InsetERT(buffer_->params));
2743 case LFUN_INSET_EXTERNAL:
2744 insertAndEditInset(new InsetExternal);
2747 case LFUN_INSET_FOOTNOTE:
2748 insertAndEditInset(new InsetFoot(buffer_->params));
2751 case LFUN_INSET_MARGINAL:
2752 insertAndEditInset(new InsetMarginal(buffer_->params));
2755 case LFUN_INSET_MINIPAGE:
2756 insertAndEditInset(new InsetMinipage(buffer_->params));
2759 case LFUN_INSERT_NOTE:
2760 insertAndEditInset(new InsetNote(buffer_->params));
2763 case LFUN_INSET_FLOAT:
2764 // check if the float type exist
2765 if (floatList.typeExist(argument)) {
2766 insertAndEditInset(new InsetFloat(buffer_->params,
2769 lyxerr << "Non-existent float type: "
2770 << argument << endl;
2774 case LFUN_INSET_WIDE_FLOAT:
2775 // check if the float type exist
2776 if (floatList.typeExist(argument)) {
2777 InsetFloat * new_inset =
2778 new InsetFloat(buffer_->params, argument);
2779 new_inset->wide(true);
2780 insertAndEditInset(new_inset);
2782 lyxerr << "Non-existent float type: "
2783 << argument << endl;
2788 case LFUN_INSET_LIST:
2789 insertAndEditInset(new InsetList);
2792 case LFUN_INSET_THEOREM:
2793 insertAndEditInset(new InsetTheorem);
2797 case LFUN_INSET_CAPTION:
2799 // Do we have a locking inset...
2800 if (bv_->theLockingInset()) {
2801 lyxerr << "Locking inset code: "
2802 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2803 InsetCaption * new_inset =
2804 new InsetCaption(buffer_->params);
2805 new_inset->setOwner(bv_->theLockingInset());
2806 new_inset->setAutoBreakRows(true);
2807 new_inset->setDrawFrame(0, InsetText::LOCKED);
2808 new_inset->setFrameColor(0, LColor::captionframe);
2809 if (insertInset(new_inset))
2810 new_inset->edit(bv_);
2817 case LFUN_INSET_TABULAR:
2821 if (!argument.empty())
2822 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2823 InsetTabular * new_inset =
2824 new InsetTabular(*buffer_, r, c);
2826 bv_->getLyXText()->real_current_font.isRightToLeft();
2827 if (!open_new_inset(new_inset, rtl))
2832 // --- lyxserver commands ----------------------------
2834 case LFUN_CHARATCURSOR:
2836 pos_type pos = bv_->getLyXText()->cursor.pos();
2837 if (pos < bv_->getLyXText()->cursor.par()->size())
2838 owner_->getLyXFunc()->setMessage(
2839 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2841 owner_->getLyXFunc()->setMessage("EOF");
2846 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2848 + tostr(bv_->getLyXText()->cursor.y()));
2855 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2856 lyxerr << "SETXY: Could not parse coordinates in '"
2857 << argument << std::endl;
2859 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2863 case LFUN_GETLAYOUT:
2864 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2869 LyXFont & font = bv_->getLyXText()->current_font;
2870 if (font.shape() == LyXFont::ITALIC_SHAPE)
2871 owner_->getLyXFunc()->setMessage("E");
2872 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2873 owner_->getLyXFunc()->setMessage("N");
2875 owner_->getLyXFunc()->setMessage("0");
2880 // --- accented characters ---------------------------
2883 case LFUN_CIRCUMFLEX:
2893 case LFUN_SPECIAL_CARON:
2896 case LFUN_HUNG_UMLAUT:
2899 if (argument.empty()) {
2901 owner_->getLyXFunc()->handleKeyFunc(action);
2903 owner_->getLyXFunc()->handleKeyFunc(action);
2904 owner_->getIntl()->getTransManager()
2905 .TranslateAndInsert(argument[0], bv_->getLyXText());
2906 update(bv_->getLyXText(),
2908 | BufferView::FITCUR
2909 | BufferView::CHANGE);
2914 mathDispatch(bv_, argument);
2917 case LFUN_MATH_MACRO:
2918 mathDispatchMathMacro(bv_, argument);
2921 case LFUN_MATH_DELIM:
2922 mathDispatchMathDelim(bv_, argument);
2925 case LFUN_INSERT_MATRIX:
2926 mathDispatchInsertMatrix(bv_, argument);
2929 case LFUN_INSERT_MATH:
2930 mathDispatchInsertMath(bv_, argument);
2933 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2934 mathDispatchMathImportSelection(bv_, argument);
2937 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2938 mathDispatchMathDisplay(bv_, argument);
2941 case LFUN_MATH_MODE: // Open or create an inlined math inset
2942 mathDispatchMathMode(bv_, argument);
2945 case LFUN_GREEK: // Insert a single greek letter
2946 mathDispatchGreek(bv_, argument);
2949 case LFUN_CITATION_INSERT:
2951 InsetCommandParams p;
2952 p.setFromString(argument);
2954 InsetCitation * inset = new InsetCitation(p);
2955 if (!insertInset(inset))
2958 updateInset(inset, true);
2962 case LFUN_INSERT_BIBTEX:
2964 // ale970405+lasgoutt970425
2965 // The argument can be up to two tokens separated
2966 // by a space. The first one is the bibstyle.
2967 string const db = token(argument, ' ', 0);
2968 string const bibstyle = token(argument, ' ', 1);
2970 InsetCommandParams p("BibTeX", db, bibstyle);
2971 InsetBibtex * inset = new InsetBibtex(p);
2973 if (insertInset(inset)) {
2974 if (argument.empty())
2981 // BibTeX data bases
2982 case LFUN_BIBDB_ADD:
2984 InsetBibtex * inset =
2985 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2987 inset->addDatabase(argument);
2992 case LFUN_BIBDB_DEL:
2994 InsetBibtex * inset =
2995 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2997 inset->delDatabase(argument);
3002 case LFUN_BIBTEX_STYLE:
3004 InsetBibtex * inset =
3005 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3007 inset->setOptions(argument);
3012 case LFUN_INDEX_INSERT:
3014 string entry = argument;
3015 if (entry.empty()) {
3016 entry = bv_->getLyXText()->getStringToIndex(bv_);
3019 if (entry.empty()) {
3020 owner_->getDialogs()->createIndex();
3024 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3026 if (!insertInset(inset)) {
3029 updateInset(inset, true);
3034 case LFUN_INDEX_PRINT:
3036 InsetCommandParams p("printindex");
3037 Inset * inset = new InsetPrintIndex(p);
3038 if (!insertInset(inset, tclass.defaultLayoutName()))
3043 case LFUN_PARENTINSERT:
3045 InsetCommandParams p("lyxparent", argument);
3046 Inset * inset = new InsetParent(p, *buffer_);
3047 if (!insertInset(inset, tclass.defaultLayoutName()))
3053 case LFUN_CHILD_INSERT:
3055 InsetInclude::Params p;
3056 p.cparams.setFromString(argument);
3057 p.masterFilename_ = buffer_->fileName();
3059 InsetInclude * inset = new InsetInclude(p);
3060 if (!insertInset(inset))
3063 updateInset(inset, true);
3064 bv_->owner()->getDialogs()->showInclude(inset);
3069 case LFUN_FLOAT_LIST:
3070 if (floatList.typeExist(argument)) {
3071 Inset * inset = new InsetFloatList(argument);
3072 if (!insertInset(inset, tclass.defaultLayoutName()))
3075 lyxerr << "Non-existent float type: "
3076 << argument << endl;
3080 case LFUN_THESAURUS_ENTRY:
3082 string arg = argument;
3085 arg = bv_->getLyXText()->selectionAsString(buffer_,
3089 if (arg.size() > 100 || arg.empty()) {
3090 // Get word or selection
3091 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3092 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3093 // FIXME: where is getLyXText()->unselect(bv_) ?
3097 bv_->owner()->getDialogs()->showThesaurus(arg);
3101 case LFUN_SELFINSERT:
3103 if (argument.empty()) break;
3105 /* Automatically delete the currently selected
3106 * text and replace it with what is being
3107 * typed in now. Depends on lyxrc settings
3108 * "auto_region_delete", which defaults to
3111 LyXText * lt = bv_->getLyXText();
3113 if (lyxrc.auto_region_delete) {
3114 if (lt->selection.set()) {
3115 lt->cutSelection(bv_, false, false);
3118 | BufferView::FITCUR
3119 | BufferView::CHANGE);
3121 workarea().haveSelection(false);
3125 LyXFont const old_font(lt->real_current_font);
3127 string::const_iterator cit = argument.begin();
3128 string::const_iterator end = argument.end();
3129 for (; cit != end; ++cit) {
3130 owner_->getIntl()->getTransManager().
3131 TranslateAndInsert(*cit, lt);
3136 | BufferView::FITCUR
3137 | BufferView::CHANGE);
3139 lt->selection.cursor = lt->cursor;
3140 moveCursorUpdate(false);
3142 // real_current_font.number can change so we need to
3143 // update the minibuffer
3144 if (old_font != lt->real_current_font)
3145 owner_->view_state_changed();
3150 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3152 time_t now_time_t = time(NULL);
3153 struct tm * now_tm = localtime(&now_time_t);
3154 setlocale(LC_TIME, "");
3156 if (!argument.empty())
3159 arg = lyxrc.date_insert_format;
3161 int const datetmp_len =
3162 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3164 LyXText * lt = bv_->getLyXText();
3166 for (int i = 0; i < datetmp_len; i++) {
3167 lt->insertChar(bv_, datetmp[i]);
3170 | BufferView::FITCUR
3171 | BufferView::CHANGE);
3174 lt->selection.cursor = lt->cursor;
3175 moveCursorUpdate(false);
3179 case LFUN_UNKNOWN_ACTION:
3180 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3191 void BufferView::Pimpl::newline()
3194 LyXText * lt = bv_->getLyXText();
3198 | BufferView::FITCUR);
3199 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3202 | BufferView::FITCUR
3203 | BufferView::CHANGE);
3208 void BufferView::Pimpl::hfill()
3211 LyXText * lt = bv_->getLyXText();
3215 | BufferView::FITCUR);
3216 lt->insertChar(bv_, Paragraph::META_HFILL);
3219 | BufferView::FITCUR
3220 | BufferView::CHANGE);
3225 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3228 LyXText * lt = bv_->getLyXText();
3231 update(lt, BufferView::SELECT|BufferView::FITCUR);
3232 InsetSpecialChar * new_inset =
3233 new InsetSpecialChar(kind);
3234 if (!insertInset(new_inset))
3237 updateInset(new_inset, true);
3242 void BufferView::Pimpl::smartQuote()
3244 LyXText const * lt = bv_->getLyXText();
3245 Paragraph const * par = lt->cursor.par();
3246 pos_type pos = lt->cursor.pos();
3250 || (par->isInset(pos - 1)
3251 && par->getInset(pos - 1)->isSpace()))
3254 c = par->getChar(pos - 1);
3259 LyXLayout_ptr const & style = par->layout();
3261 if (style->pass_thru ||
3262 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3263 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, string("\""));
3267 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3270 if (insertInset(inset))
3275 bool gotsel = false;
3277 if (bv_->getLyXText()->selection.set()) {
3278 bv_->getLyXText()->cutSelection(bv_, true, false);
3282 if (insertInset(inset)) {
3285 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3293 // Open and lock an updatable inset
3294 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3296 LyXText * lt = bv_->getLyXText();
3300 if (!insertInset(new_inset)) {
3304 new_inset->edit(bv_, !behind);
3309 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3311 // if we are in a locking inset we should try to insert the
3312 // inset there otherwise this is a illegal function now
3313 if (bv_->theLockingInset()) {
3314 if (bv_->theLockingInset()->insetAllowed(inset))
3315 return bv_->theLockingInset()->insertInset(bv_, inset);
3319 // not quite sure if we want this...
3320 setCursorParUndo(bv_);
3323 beforeChange(bv_->text);
3324 if (!lout.empty()) {
3325 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3326 bv_->text->breakParagraph(bv_);
3327 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3329 if (bv_->text->cursor.par()->size()) {
3330 bv_->text->cursorLeft(bv_);
3332 bv_->text->breakParagraph(bv_);
3333 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3337 LyXTextClass const & tclass =
3338 buffer_->params.getLyXTextClass();
3339 bool hasLayout = tclass.hasLayout(lres);
3340 string lay = tclass.defaultLayoutName();
3342 if (hasLayout != false) {
3346 // layout not fount using default
3347 lay = tclass.defaultLayoutName();
3350 bv_->text->setLayout(bv_, lay);
3352 bv_->text->setParagraph(bv_, 0, 0,
3354 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3359 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3362 bv_->text->insertInset(bv_, inset);
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3370 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3372 if (!inset || !available())
3375 // first check for locking insets
3376 if (bv_->theLockingInset()) {
3377 if (bv_->theLockingInset() == inset) {
3378 if (bv_->text->updateInset(bv_, inset)) {
3381 buffer_->markDirty();
3386 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3387 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3390 buffer_->markDirty();
3398 // then check if the inset is a top_level inset (has no owner)
3399 // if yes do the update as always otherwise we have to update the
3400 // toplevel inset where this inset is inside
3401 Inset * tl_inset = inset;
3402 while(tl_inset->owner())
3403 tl_inset = tl_inset->owner();
3405 if (tl_inset == inset) {
3406 update(bv_->text, BufferView::UPDATE);
3407 if (bv_->text->updateInset(bv_, inset)) {
3411 | BufferView::FITCUR
3412 | BufferView::CHANGE);
3414 update(bv_->text, SELECT);
3418 } else if (static_cast<UpdatableInset *>(tl_inset)
3419 ->updateInsetInInset(bv_, inset))
3421 if (bv_->text->updateInset(bv_, tl_inset)) {
3429 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3432 if (!available()) return;
3435 beforeChange(bv_->text);
3436 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3438 LyXCursor const & cursor = bv_->text->cursor;
3442 cursor.par()->isInset(cursor.pos())) {
3443 Inset const * inset = cursor.par()->getInset(cursor.pos());
3444 if (find(codes.begin(), codes.end(), inset->lyxCode())
3447 static_cast<InsetCommand const *>(inset)->getContents();
3451 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3452 if (bv_->text->cursor.pos()
3453 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3454 LyXCursor tmp = bv_->text->cursor;
3455 bv_->text->cursor.par(bv_->text->ownerParagraph());
3456 bv_->text->cursor.pos(0);
3457 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3458 bv_->text->cursor = tmp;
3459 bv_->owner()->message(_("No more insets"));
3462 bv_->owner()->message(_("No more insets"));
3465 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3466 bv_->text->selection.cursor = bv_->text->cursor;
3470 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3472 gotoInset(vector<Inset::Code>(1, code), same_content);