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>
88 extern string current_layout;
90 #ifndef CXX_GLOBAL_CSTD
103 using std::make_pair;
107 using lyx::textclass_type;
109 /* the selection possible is needed, that only motion events are
110 * used, where the bottom press event was on the drawing area too */
111 bool selection_possible = false;
113 extern BufferList bufferlist;
114 extern char ascii_type;
116 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
121 unsigned int const saved_positions_num = 20;
123 // All the below connection objects are needed because of a bug in some
124 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
125 // to these connections we avoid a segfault upon startup, and also at exit.
128 boost::signals::connection timecon;
129 boost::signals::connection doccon;
130 boost::signals::connection resizecon;
131 boost::signals::connection bpresscon;
132 boost::signals::connection breleasecon;
133 boost::signals::connection motioncon;
134 boost::signals::connection doublecon;
135 boost::signals::connection triplecon;
136 boost::signals::connection kpresscon;
137 boost::signals::connection selectioncon;
138 boost::signals::connection lostcon;
143 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
144 int xpos, int ypos, int width, int height)
145 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
146 using_xterm_cursor(false)
148 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
149 screen_.reset(LyXScreenFactory::create(workarea()));
152 doccon = workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
153 resizecon = workarea().workAreaResize
154 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
155 bpresscon = workarea().workAreaButtonPress
156 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
157 breleasecon = workarea().workAreaButtonRelease
158 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
159 motioncon = workarea().workAreaMotionNotify
160 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
161 doublecon = workarea().workAreaDoubleClick
162 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
163 triplecon = workarea().workAreaTripleClick
164 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
165 kpresscon = workarea().workAreaKeyPress
166 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
167 selectioncon = workarea().selectionRequested
168 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
169 lostcon = workarea().selectionLost
170 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
172 timecon = cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
173 cursor_timeout.start();
174 saved_positions.resize(saved_positions_num);
178 WorkArea & BufferView::Pimpl::workarea() const
180 return *workarea_.get();
184 LyXScreen & BufferView::Pimpl::screen() const
186 return *screen_.get();
190 Painter & BufferView::Pimpl::painter() const
192 return workarea().getPainter();
196 void BufferView::Pimpl::buffer(Buffer * b)
198 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
201 buffer_->delUser(bv_);
203 // Put the old text into the TextCache, but
204 // only if the buffer is still loaded.
205 // Also set the owner of the test to 0
206 // bv_->text->owner(0);
207 textcache.add(buffer_, workarea().workWidth(), bv_->text);
208 if (lyxerr.debugging())
209 textcache.show(lyxerr, "BufferView::buffer");
214 // Set current buffer
217 if (bufferlist.getState() == BufferList::CLOSING) return;
219 // If we are closing the buffer, use the first buffer as current
221 buffer_ = bufferlist.first();
225 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
226 buffer_->addUser(bv_);
228 // If we don't have a text object for this, we make one
229 if (bv_->text == 0) {
230 resizeCurrentBuffer();
233 // FIXME: needed when ?
234 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
236 // Similarly, buffer-dependent dialogs should be updated or
237 // hidden. This should go here because some dialogs (eg ToC)
238 // require bv_->text.
239 owner_->getDialogs()->updateBufferDependent(true);
241 lyxerr[Debug::INFO] << " No Buffer!" << endl;
242 owner_->getDialogs()->hideBufferDependent();
244 // Also remove all remaining text's from the testcache.
245 // (there should not be any!) (if there is any it is a
247 if (lyxerr.debugging())
248 textcache.show(lyxerr, "buffer delete all");
254 owner_->updateMenubar();
255 owner_->updateToolbar();
256 owner_->updateLayoutChoice();
257 owner_->updateWindowTitle();
259 if (grfx::Previews::activated() && buffer_)
260 grfx::Previews::get().generateBufferPreviews(*buffer_);
264 bool BufferView::Pimpl::fitCursor()
268 if (bv_->theLockingInset()) {
269 bv_->theLockingInset()->fitInsetCursor(bv_);
272 ret = screen().fitCursor(bv_->text, bv_);
275 bv_->owner()->getDialogs()->updateParagraph();
282 void BufferView::Pimpl::redoCurrentBuffer()
284 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
285 if (buffer_ && bv_->text) {
286 resizeCurrentBuffer();
287 owner_->updateLayoutChoice();
292 int BufferView::Pimpl::resizeCurrentBuffer()
294 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
297 Paragraph * selstartpar = 0;
298 Paragraph * selendpar = 0;
299 UpdatableInset * the_locking_inset = 0;
302 pos_type selstartpos = 0;
303 pos_type selendpos = 0;
304 bool selection = false;
305 bool mark_set = false;
307 owner_->prohibitInput();
309 owner_->message(_("Formatting document..."));
312 par = bv_->text->cursor.par();
313 pos = bv_->text->cursor.pos();
314 selstartpar = bv_->text->selection.start.par();
315 selstartpos = bv_->text->selection.start.pos();
316 selendpar = bv_->text->selection.end.par();
317 selendpos = bv_->text->selection.end.pos();
318 selection = bv_->text->selection.set();
319 mark_set = bv_->text->selection.mark();
320 the_locking_inset = bv_->theLockingInset();
321 buffer_->resizeInsets(bv_);
322 // I don't think the delete and new are necessary here we just could
323 // call only init! (Jug 20020419)
325 bv_->text = new LyXText(bv_);
326 bv_->text->init(bv_);
328 // See if we have a text in TextCache that fits
329 // the new buffer_ with the correct width.
330 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
332 if (lyxerr.debugging()) {
333 lyxerr << "Found a LyXText that fits:\n";
334 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
336 // Set the owner of the newly found text
337 // bv_->text->owner(bv_);
338 if (lyxerr.debugging())
339 textcache.show(lyxerr, "resizeCurrentBuffer");
341 bv_->text = new LyXText(bv_);
342 bv_->text->init(bv_);
343 //buffer_->resizeInsets(bv_);
348 bv_->text->selection.set(true);
349 // At this point just to avoid the Delete-Empty-Paragraph-
350 // Mechanism when setting the cursor.
351 bv_->text->selection.mark(mark_set);
353 bv_->text->setCursor(bv_, selstartpar, selstartpos);
354 bv_->text->selection.cursor = bv_->text->cursor;
355 bv_->text->setCursor(bv_, selendpar, selendpos);
356 bv_->text->setSelection(bv_);
357 bv_->text->setCursor(bv_, par, pos);
359 bv_->text->setCursor(bv_, par, pos);
360 bv_->text->selection.cursor = bv_->text->cursor;
361 bv_->text->selection.set(false);
363 // remake the inset locking
364 bv_->theLockingInset(the_locking_inset);
367 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
370 owner_->allowInput();
372 /// clear the "Formatting Document" message
379 void BufferView::Pimpl::repaint()
381 // Regenerate the screen.
382 screen().redraw(bv_->text, bv_);
386 void BufferView::Pimpl::updateScrollbar()
389 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
390 workarea().setScrollbarParams(0, 0, 0);
394 LyXText const & t = *bv_->text;
396 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
397 << t.first_y << ", default height " << t.defaultHeight() << endl;
399 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
403 void BufferView::Pimpl::scrollDocView(int value)
405 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
407 if (!buffer_) return;
409 screen().draw(bv_->text, bv_, value);
411 if (!lyxrc.cursor_follows_scrollbar) {
415 LyXText * vbt = bv_->text;
417 int const height = vbt->defaultHeight();
418 int const first = static_cast<int>((bv_->text->first_y + height));
419 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
421 if (vbt->cursor.y() < first)
422 vbt->setCursorFromCoordinates(bv_, 0, first);
423 else if (vbt->cursor.y() > last)
424 vbt->setCursorFromCoordinates(bv_, 0, last);
428 int BufferView::Pimpl::scroll(long time)
433 LyXText const * t = bv_->text;
435 double const diff = t->defaultHeight()
436 + double(time) * double(time) * 0.125;
438 scrollDocView(int(diff));
439 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
444 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
445 key_modifier::state state)
447 bv_->owner()->getLyXFunc()->processKeySym(key, state);
451 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
453 // Only use motion with button 1
454 if (!(state & mouse_button::button1))
460 // Check for inset locking
461 if (bv_->theLockingInset()) {
462 LyXCursor cursor = bv_->text->cursor;
463 LyXFont font = bv_->text->getFont(buffer_,
464 cursor.par(), cursor.pos());
465 int width = bv_->theLockingInset()->width(bv_, font);
466 int inset_x = font.isVisibleRightToLeft()
467 ? cursor.ix() - width : cursor.ix();
468 int start_x = inset_x + bv_->theLockingInset()->scroll();
470 bv_->theLockingInset()->
471 insetMotionNotify(bv_,
473 y - cursor.iy() + bv_->text->first_y,
478 /* The test for not selection possible is needed, that only motion
479 events are used, where the bottom press event was on
480 the drawing area too */
481 if (!selection_possible)
484 screen().hideCursor();
486 Row * cursorrow = bv_->text->cursor.row();
487 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
489 // sorry for this but I have a strange error that the y value jumps at
490 // a certain point. This seems like an error in my xforms library or
491 // in some other local environment, but I would like to leave this here
492 // for the moment until I can remove this (Jug 20020418)
493 if (y_before < bv_->text->cursor.y())
494 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
496 // This is to allow jumping over large insets
497 if (cursorrow == bv_->text->cursor.row()) {
498 if (y >= int(workarea().workHeight())) {
499 bv_->text->cursorDown(bv_, false);
501 bv_->text->cursorUp(bv_, false);
505 if (!bv_->text->selection.set())
506 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
508 bv_->text->setSelection(bv_);
509 screen().toggleToggle(bv_->text, bv_);
515 // Single-click on work area
516 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
517 mouse_button::state button)
522 // ok ok, this is a hack (for xforms)
523 if (button == mouse_button::button4) {
524 scroll(-lyxrc.wheel_jump);
525 // We shouldn't go further down as we really should only do the
526 // scrolling and be done with this. Otherwise we may open some
527 // dialogs (Jug 20020424).
529 } else if (button == mouse_button::button5) {
530 scroll(lyxrc.wheel_jump);
531 // We shouldn't go further down as we really should only do the
532 // scrolling and be done with this. Otherwise we may open some
533 // dialogs (Jug 20020424).
537 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
539 // Middle button press pastes if we have a selection
540 // We do this here as if the selection was inside an inset
541 // it could get cleared on the unlocking of the inset so
542 // we have to check this first
543 bool paste_internally = false;
544 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
545 owner_->getLyXFunc()->dispatch(LFUN_COPY);
546 paste_internally = true;
549 int const screen_first = bv_->text->first_y;
551 if (bv_->theLockingInset()) {
552 // We are in inset locking mode
554 /* Check whether the inset was hit. If not reset mode,
555 otherwise give the event to the inset */
556 if (inset_hit == bv_->theLockingInset()) {
557 bv_->theLockingInset()->
558 insetButtonPress(bv_, xpos, ypos, button);
561 bv_->unlockInset(bv_->theLockingInset());
566 selection_possible = true;
567 screen().hideCursor();
569 // Clear the selection
570 screen().toggleSelection(bv_->text, bv_);
571 bv_->text->clearSelection();
572 bv_->text->fullRebreak(bv_);
576 // Single left click in math inset?
577 if (isHighlyEditableInset(inset_hit)) {
578 // Highly editable inset, like math
579 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
580 selection_possible = false;
581 owner_->updateLayoutChoice();
582 owner_->message(inset->editMessage());
583 //inset->edit(bv_, xpos, ypos, button);
584 // We just have to lock the inset before calling a PressEvent on it!
585 // we don't need the edit() call here! (Jug20020329)
586 if (!bv_->lockInset(inset)) {
587 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
589 inset->insetButtonPress(bv_, xpos, ypos, button);
592 // I'm not sure we should continue here if we hit an inset (Jug20020403)
594 // Right click on a footnote flag opens float menu
595 if (button == mouse_button::button3) {
596 selection_possible = false;
600 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
601 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
603 bv_->text->selection.cursor = bv_->text->cursor;
604 bv_->text->cursor.x_fix(bv_->text->cursor.x());
606 owner_->updateLayoutChoice();
608 selection_possible = false;
611 // Insert primary selection with middle mouse
612 // if there is a local selection in the current buffer,
614 if (button == mouse_button::button2) {
615 if (paste_internally)
616 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
618 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
619 string("paragraph"));
620 selection_possible = false;
626 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
631 LyXText * text = bv_->getLyXText();
633 if (text->bv_owner && bv_->theLockingInset())
636 if (button == mouse_button::button1) {
637 if (text->bv_owner) {
638 screen().hideCursor();
639 screen().toggleSelection(text, bv_);
640 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
641 screen().toggleSelection(text, bv_, false);
643 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
645 /* This will fit the cursor on the screen
647 update(text, BufferView::SELECT|BufferView::FITCUR);
652 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
657 LyXText * text = bv_->getLyXText();
659 if (text->bv_owner && bv_->theLockingInset())
662 if (button == mouse_button::button1) {
663 if (text->bv_owner) {
664 screen().hideCursor();
665 screen().toggleSelection(text, bv_);
667 text->cursorHome(bv_);
668 text->selection.cursor = text->cursor;
669 text->cursorEnd(bv_);
670 text->setSelection(bv_);
671 if (text->bv_owner) {
672 screen().toggleSelection(text, bv_, false);
674 /* This will fit the cursor on the screen
676 update(text, BufferView::SELECT|BufferView::FITCUR);
681 void BufferView::Pimpl::selectionRequested()
688 LyXText * text = bv_->getLyXText();
690 if (text->selection.set() &&
691 (!bv_->text->xsel_cache.set() ||
692 text->selection.start != bv_->text->xsel_cache.start ||
693 text->selection.end != bv_->text->xsel_cache.end))
695 bv_->text->xsel_cache = text->selection;
696 sel = text->selectionAsString(bv_->buffer(), false);
697 } else if (!text->selection.set()) {
699 bv_->text->xsel_cache.set(false);
702 workarea().putClipboard(sel);
707 void BufferView::Pimpl::selectionLost()
712 bv_->getLyXText()->clearSelection();
714 bv_->text->xsel_cache.set(false);
719 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
720 mouse_button::state button)
722 // do nothing if we used the mouse wheel
723 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
726 // If we hit an inset, we have the inset coordinates in these
727 // and inset_hit points to the inset. If we do not hit an
728 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
729 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
731 if (bv_->theLockingInset()) {
732 // We are in inset locking mode.
734 /* LyX does a kind of work-area grabbing for insets.
735 Only a ButtonPress Event outside the inset will
736 force a insetUnlock. */
737 bv_->theLockingInset()->
738 insetButtonRelease(bv_, x, y, button);
742 selection_possible = false;
744 if (button == mouse_button::button2)
748 if (button == mouse_button::button1) {
749 workarea().haveSelection(bv_->getLyXText()->selection.set());
753 owner_->view_state_changed();
754 owner_->updateMenubar();
755 owner_->updateToolbar();
757 // Did we hit an editable inset?
759 selection_possible = false;
761 // if we reach this point with a selection, it
762 // must mean we are currently selecting.
763 // But we don't want to open the inset
764 // because that is annoying for the user.
765 // So just pretend we didn't hit it.
766 // this is OK because a "kosher" ButtonRelease
767 // will follow a ButtonPress that clears
769 // Note this also fixes selection drawing
770 // problems if we end up opening an inset
771 if (bv_->getLyXText()->selection.set())
774 // CHECK fix this proper in 0.13
775 // well, maybe 13.0 !!!!!!!!!
777 // Following a ref shouldn't issue
778 // a push on the undo-stack
779 // anylonger, now that we have
780 // keybindings for following
781 // references and returning from
782 // references. IMHO though, it
783 // should be the inset's own business
784 // to push or not push on the undo
785 // stack. They don't *have* to
786 // alter the document...
788 // ...or maybe the SetCursorParUndo()
789 // below isn't necessary at all anylonger?
790 if (inset_hit->lyxCode() == Inset::REF_CODE) {
791 setCursorParUndo(bv_);
794 owner_->message(inset_hit->editMessage());
796 if (isHighlyEditableInset(inset_hit)) {
797 // Highly editable inset, like math
798 UpdatableInset *inset = (UpdatableInset *)inset_hit;
799 inset->insetButtonRelease(bv_, x, y, button);
801 inset_hit->insetButtonRelease(bv_, x, y, button);
802 // IMO this is a grosshack! Inset's should be changed so that
803 // they call the actions they have to do with the insetButtonRel.
804 // function and not in the edit(). This should be changed
806 inset_hit->edit(bv_, x, y, button);
811 // Maybe we want to edit a bibitem ale970302
812 if (bv_->text->cursor.par()->bibkey) {
813 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
814 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
815 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
816 (!is_rtl && x < 20+width)) {
817 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
825 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
826 LyXCursor const & cursor) const
828 Paragraph /*const*/ & par = *cursor.par();
829 pos_type const pos = cursor.pos();
831 lyx::Assert(par.getInset(pos));
833 Inset const & inset(*par.getInset(pos));
835 LyXFont const & font = text.getFont(buffer_, &par, pos);
837 int const width = inset.width(bv_, font);
838 int const inset_x = font.isVisibleRightToLeft()
839 ? (cursor.ix() - width) : cursor.ix();
842 inset_x + inset.scroll(),
844 cursor.iy() - inset.ascent(bv_, font),
845 cursor.iy() + inset.descent(bv_, font));
849 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
850 LyXCursor const & cursor,
851 int & x, int & y) const
853 pos_type const pos(cursor.pos());
854 Paragraph /*const*/ & par(*cursor.par());
856 if (pos >= par.size() || !par.isInset(pos)) {
860 Inset /*const*/ * inset = par.getInset(pos);
862 if (!isEditableInset(inset)) {
866 Box b(insetDimensions(text, cursor));
868 if (!b.contained(x, y)) {
869 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
870 << " box " << b << endl;
874 text.setCursor(bv_, &par, pos, true);
877 // The origin of an inset is on the baseline
878 y -= text.cursor.iy();
884 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
886 int y_tmp = y + text->first_y;
889 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
891 Inset * inset(checkInset(*text, cursor, x, y_tmp));
898 // look at previous position
900 if (cursor.pos() == 0) {
905 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
907 inset = checkInset(*text, cursor, x, y_tmp);
915 void BufferView::Pimpl::workAreaResize()
917 static int work_area_width;
918 static int work_area_height;
920 bool const widthChange = workarea().workWidth() != work_area_width;
921 bool const heightChange = workarea().workHeight() != work_area_height;
923 // update from work area
924 work_area_width = workarea().workWidth();
925 work_area_height = workarea().workHeight();
929 // The visible LyXView need a resize
930 resizeCurrentBuffer();
932 // Remove all texts from the textcache
933 // This is not _really_ what we want to do. What
934 // we really want to do is to delete in textcache
935 // that does not have a BufferView with matching
936 // width, but as long as we have only one BufferView
937 // deleting all gives the same result.
938 if (lyxerr.debugging())
939 textcache.show(lyxerr, "Expose delete all");
941 // FIXME: this is aalready done in resizeCurrentBuffer() ??
942 buffer_->resizeInsets(bv_);
943 } else if (heightChange) {
944 // fitCursor() ensures we don't jump back
945 // to the start of the document on vertical
951 if (widthChange || heightChange) {
955 // always make sure that the scrollbar is sane.
957 owner_->updateLayoutChoice();
962 void BufferView::Pimpl::update()
964 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
965 LyXText::text_status st = bv_->text->status();
966 screen().update(bv_->text, bv_);
968 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
969 bv_->text->fullRebreak(bv_);
970 st = LyXText::NEED_MORE_REFRESH;
971 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
972 bv_->text->cursor.pos());
973 if (bv_->text->selection.set()) {
974 bv_->text->setCursor(bv_, bv_->text->selection.start,
975 bv_->text->selection.start.par(),
976 bv_->text->selection.start.pos());
977 bv_->text->setCursor(bv_, bv_->text->selection.end,
978 bv_->text->selection.end.par(),
979 bv_->text->selection.end.pos());
982 bv_->text->status(bv_, st);
983 screen().update(bv_->text, bv_);
985 // do this here instead of in the screen::update because of
987 bv_->text->status(bv_, LyXText::UNCHANGED);
993 // Values used when calling update:
995 // -2 - update, move sel_cursor if selection, fitcursor
996 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
997 // 0 - update, move sel_cursor if selection, fitcursor
998 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
999 // 3 - update, move sel_cursor if selection
1002 // a simple redraw of the parts that need refresh
1004 // move sel_cursor if selection -
1005 // the text's sel_cursor is moved if there is selection is progress
1008 // fitCursor() is called and the scrollbar updated
1011 // the buffer is marked dirty.
1020 // UPDATE_ONLY = UPDATE;
1021 // UPDATE_SELECT = UPDATE | SELECT;
1022 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1023 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1025 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1026 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1027 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1028 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1029 // update(3) -> update(1) -> update(1) -> update(SELECT)
1031 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1033 owner_->updateLayoutChoice();
1035 if (!text->selection.set() && (f & SELECT)) {
1036 text->selection.cursor = text->cursor;
1039 text->fullRebreak(bv_);
1041 if (text->inset_owner) {
1042 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1043 updateInset(text->inset_owner, false);
1053 buffer_->markDirty();
1058 // Callback for cursor timer
1059 void BufferView::Pimpl::cursorToggle()
1062 cursor_timeout.restart();
1067 extern void reapSpellchecker(void);
1070 if (!bv_->theLockingInset()) {
1071 screen().cursorToggle(bv_);
1073 bv_->theLockingInset()->toggleInsetCursor(bv_);
1076 cursor_timeout.restart();
1080 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1082 if (!text->cursor.row()->previous()) {
1083 if (text->first_y > 0) {
1084 int new_y = bv_->text->first_y - workarea().workHeight();
1085 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1091 int y = text->first_y;
1092 Row * cursorrow = text->cursor.row();
1094 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1098 if (cursorrow == bv_->text->cursor.row()) {
1099 // we have a row which is higher than the workarea so we leave the
1100 // cursor on the start of the row and move only the draw up as soon
1101 // as we move the cursor or do something while inside the row (it may
1102 // span several workarea-heights) we'll move to the top again, but this
1103 // is better than just jump down and only display part of the row.
1104 new_y = bv_->text->first_y - workarea().workHeight();
1106 if (text->inset_owner) {
1107 new_y = bv_->text->cursor.iy()
1108 + bv_->theLockingInset()->insetInInsetY() + y
1109 + text->cursor.row()->height()
1110 - workarea().workHeight() + 1;
1112 new_y = text->cursor.y()
1113 - text->cursor.row()->baseline()
1114 + text->cursor.row()->height()
1115 - workarea().workHeight() + 1;
1118 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1119 if (text->cursor.row()->previous()) {
1121 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1122 text->cursor.row()->previous()->pos(), false);
1123 if (cur.y() > text->first_y) {
1124 text->cursorUp(bv_, true);
1131 void BufferView::Pimpl::cursorNext(LyXText * text)
1133 if (!text->cursor.row()->next()) {
1134 int y = text->cursor.y() - text->cursor.row()->baseline() +
1135 text->cursor.row()->height();
1136 if (y > int(text->first_y + workarea().workHeight())) {
1137 screen().draw(bv_->text, bv_,
1138 bv_->text->first_y + workarea().workHeight());
1144 int y = text->first_y + workarea().workHeight();
1145 if (text->inset_owner && !text->first_y) {
1146 y -= (bv_->text->cursor.iy()
1147 - bv_->text->first_y
1148 + bv_->theLockingInset()->insetInInsetY());
1151 text->getRowNearY(y);
1153 Row * cursorrow = text->cursor.row();
1154 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1158 if (cursorrow == bv_->text->cursor.row()) {
1159 // we have a row which is higher than the workarea so we leave the
1160 // cursor on the start of the row and move only the draw down as soon
1161 // as we move the cursor or do something while inside the row (it may
1162 // span several workarea-heights) we'll move to the top again, but this
1163 // is better than just jump down and only display part of the row.
1164 new_y = bv_->text->first_y + workarea().workHeight();
1166 if (text->inset_owner) {
1167 new_y = bv_->text->cursor.iy()
1168 + bv_->theLockingInset()->insetInInsetY()
1169 + y - text->cursor.row()->baseline();
1171 new_y = text->cursor.y() - text->cursor.row()->baseline();
1174 screen().draw(bv_->text, bv_, new_y);
1175 if (text->cursor.row()->next()) {
1177 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1178 text->cursor.row()->next()->pos(), false);
1179 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1180 text->cursorDown(bv_, true);
1187 bool BufferView::Pimpl::available() const
1189 if (buffer_ && bv_->text)
1195 void BufferView::Pimpl::beforeChange(LyXText * text)
1198 text->clearSelection();
1202 void BufferView::Pimpl::savePosition(unsigned int i)
1204 if (i >= saved_positions_num)
1206 saved_positions[i] = Position(buffer_->fileName(),
1207 bv_->text->cursor.par()->id(),
1208 bv_->text->cursor.pos());
1211 str << _("Saved bookmark") << ' ' << i;
1212 owner_->message(str.str().c_str());
1217 void BufferView::Pimpl::restorePosition(unsigned int i)
1219 if (i >= saved_positions_num)
1222 string const fname = saved_positions[i].filename;
1224 beforeChange(bv_->text);
1226 if (fname != buffer_->fileName()) {
1227 Buffer * b = bufferlist.exists(fname) ?
1228 bufferlist.getBuffer(fname) :
1229 bufferlist.loadLyXFile(fname); // don't ask, just load it
1230 if (b != 0) buffer(b);
1233 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1237 bv_->text->setCursor(bv_, par,
1238 min(par->size(), saved_positions[i].par_pos));
1240 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1243 str << _("Moved to bookmark") << ' ' << i;
1244 owner_->message(str.str().c_str());
1249 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1251 if (i >= saved_positions_num)
1254 return !saved_positions[i].filename.empty();
1258 void BufferView::Pimpl::switchKeyMap()
1260 if (!lyxrc.rtl_support)
1263 LyXText * text = bv_->getLyXText();
1264 if (text->real_current_font.isRightToLeft()
1265 && !(bv_->theLockingInset()
1266 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1268 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1269 owner_->getIntl()->KeyMapSec();
1271 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1272 owner_->getIntl()->KeyMapPrim();
1277 void BufferView::Pimpl::insetUnlock()
1279 if (bv_->theLockingInset()) {
1280 bv_->theLockingInset()->insetUnlock(bv_);
1281 bv_->theLockingInset(0);
1287 void BufferView::Pimpl::showCursor()
1289 if (bv_->theLockingInset())
1290 bv_->theLockingInset()->showInsetCursor(bv_);
1292 screen().showCursor(bv_->text, bv_);
1296 void BufferView::Pimpl::hideCursor()
1298 if (!bv_->theLockingInset())
1299 screen().hideCursor();
1303 void BufferView::Pimpl::toggleSelection(bool b)
1305 if (bv_->theLockingInset())
1306 bv_->theLockingInset()->toggleSelection(bv_, b);
1307 screen().toggleSelection(bv_->text, bv_, b);
1311 void BufferView::Pimpl::toggleToggle()
1313 screen().toggleToggle(bv_->text, bv_);
1317 void BufferView::Pimpl::center()
1319 LyXText * t = bv_->text;
1322 int const half_height = workarea().workHeight() / 2;
1325 if (t->cursor.y() > half_height) {
1326 new_y = t->cursor.y() - half_height;
1329 // FIXME: can we do this w/o calling screen directly ?
1330 // This updates first_y but means the fitCursor() call
1331 // from the update(FITCUR) doesn't realise that we might
1332 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1333 // the scrollbar to be updated as it should, so we have
1334 // to do it manually. Any operation that does a center()
1335 // and also might have moved first_y must make sure to call
1336 // updateScrollbar() currently. Never mind that this is a
1337 // pretty obfuscated way of updating t->first_y
1338 screen().draw(t, bv_, new_y);
1340 update(t, BufferView::SELECT | BufferView::FITCUR);
1344 void BufferView::Pimpl::pasteClipboard(bool asPara)
1349 screen().hideCursor();
1350 beforeChange(bv_->text);
1352 string const clip(workarea().getClipboard());
1358 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1360 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1362 bv_->getLyXText()->clearSelection();
1363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1367 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1369 workarea().putClipboard(stuff);
1374 * Dispatch functions for actions which can be valid for BufferView->text
1375 * and/or InsetText->text!!!
1380 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1382 LyXText * lt = bv_->getLyXText();
1384 if (selecting || lt->selection.mark()) {
1385 lt->setSelection(bv_);
1389 updateInset(lt->inset_owner, false);
1393 update(lt, BufferView::SELECT|BufferView::FITCUR);
1395 update(lt, BufferView::SELECT);
1397 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1398 bv_->theLockingInset()->hideInsetCursor(bv_);
1399 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1403 if (!lt->selection.set())
1404 workarea().haveSelection(false);
1410 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1412 LyXCursor cursor = bv_->getLyXText()->cursor;
1413 Buffer::inset_iterator it =
1414 find_if(Buffer::inset_iterator(
1415 cursor.par(), cursor.pos()),
1416 buffer_->inset_iterator_end(),
1417 lyx::compare_memfun(&Inset::lyxCode, code));
1418 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1422 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1424 string filename = filen;
1426 if (filename.empty()) {
1427 // Launch a file browser
1428 string initpath = lyxrc.document_path;
1431 string const trypath = owner_->buffer()->filePath();
1432 // If directory is writeable, use this as default.
1433 if (IsDirWriteable(trypath))
1437 FileDialog fileDlg(bv_->owner(),
1438 _("Select LyX document to insert"),
1440 make_pair(string(_("Documents|#o#O")),
1441 string(lyxrc.document_path)),
1442 make_pair(string(_("Examples|#E#e")),
1443 string(AddPath(system_lyxdir, "examples"))));
1445 FileDialog::Result result =
1446 fileDlg.Select(initpath,
1447 _("*.lyx| LyX Documents (*.lyx)"));
1449 if (result.first == FileDialog::Later)
1452 filename = result.second;
1454 // check selected filename
1455 if (filename.empty()) {
1456 owner_->message(_("Canceled."));
1461 // get absolute path of file and add ".lyx" to the filename if
1463 filename = FileSearch(string(), filename, "lyx");
1465 string const disp_fn(MakeDisplayPath(filename));
1468 s1 << _("Inserting document") << ' '
1469 << disp_fn << " ...";
1470 owner_->message(s1.str().c_str());
1471 bool const res = bv_->insertLyXFile(filename);
1474 str << _("Document") << ' ' << disp_fn
1475 << ' ' << _("inserted.");
1476 owner_->message(str.str().c_str());
1479 str << _("Could not insert document") << ' '
1481 owner_->message(str.str().c_str());
1486 bool BufferView::Pimpl::dispatch(kb_action action, string const & argument)
1488 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1489 << action <<"] arg[" << argument << "]" << endl;
1491 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1494 // --- Misc -------------------------------------------
1498 LyXText * lt = bv_->getLyXText();
1499 lt->toggleAppendix(bv_);
1502 | BufferView::FITCUR
1503 | BufferView::CHANGE);
1508 case LFUN_TOC_INSERT:
1510 InsetCommandParams p;
1511 p.setCmdName("tableofcontents");
1512 Inset * inset = new InsetTOC(p);
1513 if (!insertInset(inset, tclass.defaultLayoutName()))
1518 case LFUN_SCROLL_INSET:
1519 // this is not handled here as this funktion is only aktive
1520 // if we have a locking_inset and that one is (or contains)
1524 case LFUN_INSET_GRAPHICS:
1526 Inset * new_inset = new InsetGraphics;
1527 if (!insertInset(new_inset)) {
1530 // this is need because you don't use a inset->Edit()
1531 updateInset(new_inset, true);
1532 new_inset->edit(bv_);
1542 case LFUN_PASTESELECTION:
1544 bool asPara = false;
1545 if (argument == "paragraph")
1547 pasteClipboard(asPara);
1559 case LFUN_LAYOUT_COPY:
1560 bv_->copyEnvironment();
1563 case LFUN_LAYOUT_PASTE:
1564 bv_->pasteEnvironment();
1568 case LFUN_GOTOERROR:
1569 gotoInset(Inset::ERROR_CODE, false);
1573 gotoInset(Inset::IGNORE_CODE, false);
1576 case LFUN_REFERENCE_GOTO:
1578 vector<Inset::Code> tmp;
1579 tmp.push_back(Inset::LABEL_CODE);
1580 tmp.push_back(Inset::REF_CODE);
1581 gotoInset(tmp, true);
1585 case LFUN_HYPHENATION:
1586 specialChar(InsetSpecialChar::HYPHENATION);
1589 case LFUN_LIGATURE_BREAK:
1590 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1594 specialChar(InsetSpecialChar::LDOTS);
1597 case LFUN_END_OF_SENTENCE:
1598 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1601 case LFUN_MENU_SEPARATOR:
1602 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1609 case LFUN_DEPTH_MIN:
1610 changeDepth(bv_, bv_->getLyXText(), -1);
1613 case LFUN_DEPTH_PLUS:
1614 changeDepth(bv_, bv_->getLyXText(), 1);
1618 owner_->getDialogs()->setUserFreeFont();
1621 case LFUN_FILE_INSERT:
1622 MenuInsertLyXFile(argument);
1625 case LFUN_FILE_INSERT_ASCII_PARA:
1626 InsertAsciiFile(bv_, argument, true);
1629 case LFUN_FILE_INSERT_ASCII:
1630 InsertAsciiFile(bv_, argument, false);
1635 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1636 << argument << endl;
1638 // This is not the good solution to the empty argument
1639 // problem, but it will hopefully suffice for 1.2.0.
1640 // The correct solution would be to augument the
1641 // function list/array with information about what
1642 // functions needs arguments and their type.
1643 if (argument.empty()) {
1644 owner_->getLyXFunc()->setErrorMessage(
1645 _("LyX function 'layout' needs an argument."));
1649 // Derive layout number from given argument (string)
1650 // and current buffer's textclass (number). */
1651 bool hasLayout = tclass.hasLayout(argument);
1652 string layout = argument;
1654 // If the entry is obsolete, use the new one instead.
1656 string const & obs = tclass[layout]->obsoleted_by();
1662 owner_->getLyXFunc()->setErrorMessage(
1663 string(N_("Layout ")) + argument +
1668 bool change_layout = (current_layout != layout);
1669 LyXText * lt = bv_->getLyXText();
1670 if (!change_layout && lt->selection.set() &&
1671 lt->selection.start.par() != lt->selection.end.par())
1673 Paragraph * spar = lt->selection.start.par();
1674 Paragraph * epar = lt->selection.end.par()->next();
1675 while(spar != epar) {
1676 if (spar->layout()->name() != current_layout) {
1677 change_layout = true;
1682 if (change_layout) {
1684 current_layout = layout;
1687 | BufferView::FITCUR);
1688 lt->setLayout(bv_, layout);
1689 owner_->setLayout(layout);
1692 | BufferView::FITCUR
1693 | BufferView::CHANGE);
1700 lang(bv_, argument);
1702 owner_->view_state_changed();
1707 owner_->view_state_changed();
1712 owner_->view_state_changed();
1717 owner_->view_state_changed();
1722 owner_->view_state_changed();
1727 owner_->view_state_changed();
1732 owner_->view_state_changed();
1737 owner_->view_state_changed();
1740 case LFUN_UNDERLINE:
1742 owner_->view_state_changed();
1745 case LFUN_FONT_SIZE:
1746 fontSize(bv_, argument);
1747 owner_->view_state_changed();
1750 case LFUN_FONT_STATE:
1751 owner_->getLyXFunc()->setMessage(currentState(bv_));
1754 case LFUN_UPCASE_WORD:
1756 LyXText * lt = bv_->getLyXText();
1760 | BufferView::FITCUR);
1761 lt->changeCase(bv_, LyXText::text_uppercase);
1762 if (lt->inset_owner)
1763 updateInset(lt->inset_owner, true);
1766 | BufferView::FITCUR
1767 | BufferView::CHANGE);
1771 case LFUN_LOWCASE_WORD:
1773 LyXText * lt = bv_->getLyXText();
1775 update(lt, BufferView::SELECT|BufferView::FITCUR);
1776 lt->changeCase(bv_, LyXText::text_lowercase);
1777 if (lt->inset_owner)
1778 updateInset(lt->inset_owner, true);
1781 | BufferView::FITCUR
1782 | BufferView::CHANGE);
1786 case LFUN_CAPITALIZE_WORD:
1788 LyXText * lt = bv_->getLyXText();
1790 update(lt, BufferView::SELECT|BufferView::FITCUR);
1791 lt->changeCase(bv_, LyXText::text_capitalization);
1792 if (lt->inset_owner)
1793 updateInset(lt->inset_owner, true);
1796 | BufferView::FITCUR
1797 | BufferView::CHANGE);
1801 case LFUN_TRANSPOSE_CHARS:
1803 LyXText * lt = bv_->getLyXText();
1805 update(lt, BufferView::SELECT|BufferView::FITCUR);
1806 lt->transposeChars(*bv_);
1807 if (lt->inset_owner)
1808 updateInset(lt->inset_owner, true);
1811 | BufferView::FITCUR
1812 | BufferView::CHANGE);
1817 case LFUN_INSERT_LABEL:
1818 MenuInsertLabel(bv_, argument);
1821 case LFUN_REF_INSERT:
1822 if (argument.empty()) {
1823 InsetCommandParams p("ref");
1824 owner_->getDialogs()->createRef(p.getAsString());
1826 InsetCommandParams p;
1827 p.setFromString(argument);
1829 InsetRef * inset = new InsetRef(p, *buffer_);
1830 if (!insertInset(inset))
1833 updateInset(inset, true);
1837 case LFUN_BOOKMARK_SAVE:
1838 savePosition(strToUnsignedInt(argument));
1841 case LFUN_BOOKMARK_GOTO:
1842 restorePosition(strToUnsignedInt(argument));
1847 string label(argument);
1848 if (label.empty()) {
1850 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1852 label = inset->getContents();
1857 if (!label.empty()) {
1858 //bv_->savePosition(0);
1859 if (!bv_->gotoLabel(label))
1860 Alert::alert(_("Error"),
1861 _("Couldn't find this label"),
1862 _("in current document."));
1867 // --- Cursor Movements -----------------------------
1870 LyXText * lt = bv_->getLyXText();
1872 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1873 if (!lt->selection.mark())
1875 update(lt, BufferView::SELECT|BufferView::FITCUR);
1877 lt->cursorLeft(bv_, false);
1878 if (lt->cursor.pos() < lt->cursor.par()->size()
1879 && lt->cursor.par()->isInset(lt->cursor.pos())
1880 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1881 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1882 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1884 tmpinset->edit(bv_, false);
1886 tmpinset->edit(bv_);
1890 lt->cursorRight(bv_, false);
1892 moveCursorUpdate(false);
1893 owner_->view_state_changed();
1899 // This is soooo ugly. Isn`t it possible to make
1900 // it simpler? (Lgb)
1901 LyXText * lt = bv_->getLyXText();
1902 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1903 if (!lt->selection.mark())
1905 update(lt, BufferView::SELECT|BufferView::FITCUR);
1906 LyXCursor const cur = lt->cursor;
1908 lt->cursorLeft(bv_, false);
1909 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1910 lt->cursor.pos() < lt->cursor.par()->size() &&
1911 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1912 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1913 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1914 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1916 tmpinset->edit(bv_);
1918 tmpinset->edit(bv_, false);
1922 lt->cursorRight(bv_, false);
1925 moveCursorUpdate(false);
1926 owner_->view_state_changed();
1932 LyXText * lt = bv_->getLyXText();
1934 if (!lt->selection.mark())
1936 update(lt, BufferView::UPDATE);
1939 moveCursorUpdate(false);
1940 owner_->view_state_changed();
1946 LyXText * lt = bv_->getLyXText();
1948 if (!lt->selection.mark())
1950 update(lt, BufferView::UPDATE);
1951 lt->cursorDown(bv_);
1953 moveCursorUpdate(false);
1954 owner_->view_state_changed();
1958 case LFUN_UP_PARAGRAPH:
1960 LyXText * lt = bv_->getLyXText();
1962 if (!lt->selection.mark())
1964 update(lt, BufferView::UPDATE);
1965 lt->cursorUpParagraph(bv_);
1967 moveCursorUpdate(false);
1968 owner_->view_state_changed();
1972 case LFUN_DOWN_PARAGRAPH:
1974 LyXText * lt = bv_->getLyXText();
1976 if (!lt->selection.mark())
1978 update(lt, BufferView::UPDATE);
1979 lt->cursorDownParagraph(bv_);
1981 moveCursorUpdate(false);
1982 owner_->view_state_changed();
1988 LyXText * lt = bv_->getLyXText();
1990 if (!lt->selection.mark())
1992 update(lt, BufferView::UPDATE);
1995 moveCursorUpdate(false, false);
1996 owner_->view_state_changed();
2002 LyXText * lt = bv_->getLyXText();
2004 if (!lt->selection.mark())
2006 update(lt, BufferView::UPDATE);
2009 moveCursorUpdate(false, false);
2010 owner_->view_state_changed();
2016 LyXText * lt = bv_->getLyXText();
2018 if (!lt->selection.mark())
2020 update(lt, BufferView::SELECT|BufferView::FITCUR);
2021 lt->cursorHome(bv_);
2023 moveCursorUpdate(false);
2024 owner_->view_state_changed();
2030 LyXText * lt = bv_->getLyXText();
2032 if (!lt->selection.mark())
2035 BufferView::SELECT|BufferView::FITCUR);
2038 moveCursorUpdate(false);
2039 owner_->view_state_changed();
2043 case LFUN_SHIFT_TAB:
2046 LyXText * lt = bv_->getLyXText();
2048 if (!lt->selection.mark())
2051 BufferView::SELECT|BufferView::FITCUR);
2054 moveCursorUpdate(false);
2055 owner_->view_state_changed();
2059 case LFUN_WORDRIGHT:
2061 LyXText * lt = bv_->getLyXText();
2063 if (!lt->selection.mark())
2065 update(lt, BufferView::SELECT|BufferView::FITCUR);
2066 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2067 lt->cursorLeftOneWord(bv_);
2069 lt->cursorRightOneWord(bv_);
2071 moveCursorUpdate(false);
2072 owner_->view_state_changed();
2078 LyXText * lt = bv_->getLyXText();
2080 if (!lt->selection.mark())
2082 update(lt, BufferView::SELECT|BufferView::FITCUR);
2083 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2084 lt->cursorRightOneWord(bv_);
2086 lt->cursorLeftOneWord(bv_);
2088 moveCursorUpdate(false);
2089 owner_->view_state_changed();
2093 case LFUN_BEGINNINGBUF:
2095 LyXText * lt = bv_->getLyXText();
2097 if (!lt->selection.mark())
2100 BufferView::SELECT|BufferView::FITCUR);
2103 moveCursorUpdate(false);
2104 owner_->view_state_changed();
2110 LyXText * lt = bv_->getLyXText();
2112 if (!lt->selection.mark())
2115 BufferView::SELECT|BufferView::FITCUR);
2116 lt->cursorBottom(bv_);
2118 moveCursorUpdate(false);
2119 owner_->view_state_changed();
2123 /* cursor selection ---------------------------- */
2126 LyXText * lt = bv_->getLyXText();
2129 BufferView::SELECT|BufferView::FITCUR);
2130 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2131 lt->cursorLeft(bv_);
2133 lt->cursorRight(bv_);
2135 moveCursorUpdate(true);
2136 owner_->view_state_changed();
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2147 lt->cursorRight(bv_);
2149 lt->cursorLeft(bv_);
2151 moveCursorUpdate(true);
2152 owner_->view_state_changed();
2158 LyXText * lt = bv_->getLyXText();
2161 BufferView::SELECT|BufferView::FITCUR);
2162 lt->cursorUp(bv_, true);
2164 moveCursorUpdate(true);
2165 owner_->view_state_changed();
2171 LyXText * lt = bv_->getLyXText();
2174 BufferView::SELECT|BufferView::FITCUR);
2175 lt->cursorDown(bv_, true);
2177 moveCursorUpdate(true);
2178 owner_->view_state_changed();
2182 case LFUN_UP_PARAGRAPHSEL:
2184 LyXText * lt = bv_->getLyXText();
2187 BufferView::SELECT|BufferView::FITCUR);
2188 lt->cursorUpParagraph(bv_);
2190 moveCursorUpdate(true);
2191 owner_->view_state_changed();
2195 case LFUN_DOWN_PARAGRAPHSEL:
2197 LyXText * lt = bv_->getLyXText();
2200 BufferView::SELECT|BufferView::FITCUR);
2201 lt->cursorDownParagraph(bv_);
2203 moveCursorUpdate(true);
2204 owner_->view_state_changed();
2210 LyXText * lt = bv_->getLyXText();
2212 update(lt, BufferView::SELECT|BufferView::FITCUR);
2215 moveCursorUpdate(true);
2216 owner_->view_state_changed();
2222 LyXText * lt = bv_->getLyXText();
2224 update(lt, BufferView::SELECT|BufferView::FITCUR);
2227 moveCursorUpdate(true);
2228 owner_->view_state_changed();
2234 LyXText * lt = bv_->getLyXText();
2236 update(lt, BufferView::SELECT|BufferView::FITCUR);
2237 lt->cursorHome(bv_);
2239 moveCursorUpdate(true);
2240 owner_->view_state_changed();
2246 LyXText * lt = bv_->getLyXText();
2248 update(lt, BufferView::SELECT|BufferView::FITCUR);
2251 moveCursorUpdate(true);
2252 owner_->view_state_changed();
2256 case LFUN_WORDRIGHTSEL:
2258 LyXText * lt = bv_->getLyXText();
2260 update(lt, BufferView::SELECT|BufferView::FITCUR);
2261 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2262 lt->cursorLeftOneWord(bv_);
2264 lt->cursorRightOneWord(bv_);
2266 moveCursorUpdate(true);
2267 owner_->view_state_changed();
2271 case LFUN_WORDLEFTSEL:
2273 LyXText * lt = bv_->getLyXText();
2275 update(lt, BufferView::SELECT|BufferView::FITCUR);
2276 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2277 lt->cursorRightOneWord(bv_);
2279 lt->cursorLeftOneWord(bv_);
2281 moveCursorUpdate(true);
2282 owner_->view_state_changed();
2286 case LFUN_BEGINNINGBUFSEL:
2288 LyXText * lt = bv_->getLyXText();
2290 if (lt->inset_owner)
2292 update(lt, BufferView::SELECT|BufferView::FITCUR);
2295 moveCursorUpdate(true);
2296 owner_->view_state_changed();
2300 case LFUN_ENDBUFSEL:
2302 LyXText * lt = bv_->getLyXText();
2304 if (lt->inset_owner)
2307 BufferView::SELECT|BufferView::FITCUR);
2308 lt->cursorBottom(bv_);
2310 moveCursorUpdate(true);
2311 owner_->view_state_changed();
2315 // --- text changing commands ------------------------
2316 case LFUN_BREAKLINE:
2318 LyXText * lt = bv_->getLyXText();
2321 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2324 | BufferView::FITCUR
2325 | BufferView::CHANGE);
2326 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2327 moveCursorUpdate(false);
2331 case LFUN_PROTECTEDSPACE:
2333 LyXText * lt = bv_->getLyXText();
2334 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2336 if (style->free_spacing) {
2337 lt->insertChar(bv_, ' ');
2340 | BufferView::FITCUR
2341 | BufferView::CHANGE);
2343 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2345 moveCursorUpdate(false);
2351 LyXText * lt = bv_->getLyXText();
2353 if (lt->selection.mark()) {
2357 | BufferView::FITCUR);
2358 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2361 lt->selection.mark(true);
2364 | BufferView::FITCUR);
2365 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2367 lt->selection.cursor = lt->cursor;
2373 LyXText * lt = bv_->getLyXText();
2375 if (!lt->selection.set()) {
2377 lt->selection.cursor = lt->cursor;
2380 | BufferView::FITCUR
2381 | BufferView::CHANGE);
2382 // It is possible to make it a lot faster still
2383 // just comment out the line below...
2388 moveCursorUpdate(false);
2389 owner_->view_state_changed();
2394 case LFUN_DELETE_SKIP:
2396 LyXText * lt = bv_->getLyXText();
2398 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2400 LyXCursor cursor = lt->cursor;
2402 if (!lt->selection.set()) {
2403 if (cursor.pos() == cursor.par()->size()) {
2404 lt->cursorRight(bv_);
2405 cursor = lt->cursor;
2406 if (cursor.pos() == 0
2407 && !(cursor.par()->params().spaceTop()
2408 == VSpace (VSpace::NONE))) {
2411 cursor.par()->params().lineTop(),
2412 cursor.par()->params().lineBottom(),
2413 cursor.par()->params().pagebreakTop(),
2414 cursor.par()->params().pagebreakBottom(),
2415 VSpace(VSpace::NONE),
2416 cursor.par()->params().spaceBottom(),
2417 cursor.par()->params().spacing(),
2418 cursor.par()->params().align(),
2419 cursor.par()->params().labelWidthString(), 0);
2420 lt->cursorLeft(bv_);
2423 | BufferView::FITCUR
2424 | BufferView::CHANGE);
2426 lt->cursorLeft(bv_);
2428 lt->selection.cursor = lt->cursor;
2431 | BufferView::FITCUR
2432 | BufferView::CHANGE);
2436 lt->selection.cursor = lt->cursor;
2439 | BufferView::FITCUR
2440 | BufferView::CHANGE);
2448 /* -------> Delete word forward. */
2449 case LFUN_DELETE_WORD_FORWARD:
2450 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2451 bv_->getLyXText()->deleteWordForward(bv_);
2452 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2453 moveCursorUpdate(false);
2454 owner_->view_state_changed();
2457 /* -------> Delete word backward. */
2458 case LFUN_DELETE_WORD_BACKWARD:
2460 LyXText * lt = bv_->getLyXText();
2462 update(lt, BufferView::SELECT|BufferView::FITCUR);
2463 lt->deleteWordBackward(bv_);
2466 | BufferView::FITCUR
2467 | BufferView::CHANGE);
2468 moveCursorUpdate(false);
2469 owner_->view_state_changed();
2473 /* -------> Kill to end of line. */
2474 case LFUN_DELETE_LINE_FORWARD:
2476 LyXText * lt = bv_->getLyXText();
2478 update(lt, BufferView::SELECT|BufferView::FITCUR);
2479 lt->deleteLineForward(bv_);
2482 | BufferView::FITCUR
2483 | BufferView::CHANGE);
2484 moveCursorUpdate(false);
2488 /* -------> Set mark off. */
2491 LyXText * lt = bv_->getLyXText();
2494 update(lt, BufferView::SELECT|BufferView::FITCUR);
2495 lt->selection.cursor = lt->cursor;
2496 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2500 /* -------> Set mark on. */
2503 LyXText * lt = bv_->getLyXText();
2506 lt->selection.mark(true);
2507 update(lt, BufferView::SELECT|BufferView::FITCUR);
2508 lt->selection.cursor = lt->cursor;
2509 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2513 case LFUN_BACKSPACE:
2515 LyXText * lt = bv_->getLyXText();
2517 if (!lt->selection.set()) {
2518 if (owner_->getIntl()->getTransManager().backspace()) {
2520 lt->selection.cursor = lt->cursor;
2523 | BufferView::FITCUR
2524 | BufferView::CHANGE);
2525 // It is possible to make it a lot faster still
2526 // just comment out the line below...
2532 owner_->view_state_changed();
2537 case LFUN_BACKSPACE_SKIP:
2539 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2540 LyXText * lt = bv_->getLyXText();
2542 LyXCursor cursor = lt->cursor;
2544 if (!lt->selection.set()) {
2545 if (cursor.pos() == 0
2546 && !(cursor.par()->params().spaceTop()
2547 == VSpace (VSpace::NONE))) {
2550 cursor.par()->params().lineTop(),
2551 cursor.par()->params().lineBottom(),
2552 cursor.par()->params().pagebreakTop(),
2553 cursor.par()->params().pagebreakBottom(),
2554 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2555 cursor.par()->params().spacing(),
2556 cursor.par()->params().align(),
2557 cursor.par()->params().labelWidthString(), 0);
2560 | BufferView::FITCUR
2561 | BufferView::CHANGE);
2564 lt->selection.cursor = cursor;
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2575 case LFUN_BREAKPARAGRAPH:
2577 LyXText * lt = bv_->getLyXText();
2580 lt->breakParagraph(bv_, 0);
2583 | BufferView::FITCUR
2584 | BufferView::CHANGE);
2585 lt->selection.cursor = lt->cursor;
2587 owner_->view_state_changed();
2591 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2593 LyXText * lt = bv_->getLyXText();
2596 lt->breakParagraph(bv_, 1);
2599 | BufferView::FITCUR
2600 | BufferView::CHANGE);
2601 lt->selection.cursor = lt->cursor;
2603 owner_->view_state_changed();
2607 case LFUN_BREAKPARAGRAPH_SKIP:
2609 // When at the beginning of a paragraph, remove
2610 // indentation and add a "defskip" at the top.
2611 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2612 LyXText * lt = bv_->getLyXText();
2614 LyXCursor cursor = lt->cursor;
2617 if (cursor.pos() == 0) {
2618 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2621 cursor.par()->params().lineTop(),
2622 cursor.par()->params().lineBottom(),
2623 cursor.par()->params().pagebreakTop(),
2624 cursor.par()->params().pagebreakBottom(),
2625 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2626 cursor.par()->params().spacing(),
2627 cursor.par()->params().align(),
2628 cursor.par()->params().labelWidthString(), 1);
2629 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2633 lt->breakParagraph(bv_, 0);
2634 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2639 | BufferView::FITCUR
2640 | BufferView::CHANGE);
2641 lt->selection.cursor = cursor;
2643 owner_->view_state_changed();
2647 case LFUN_PARAGRAPH_SPACING:
2649 LyXText * lt = bv_->getLyXText();
2651 Paragraph * par = lt->cursor.par();
2652 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2653 float cur_value = 1.0;
2654 if (cur_spacing == Spacing::Other) {
2655 cur_value = par->params().spacing().getValue();
2658 istringstream istr(argument.c_str());
2662 Spacing::Space new_spacing = cur_spacing;
2663 float new_value = cur_value;
2665 lyxerr << "Missing argument to `paragraph-spacing'"
2667 } else if (tmp == "single") {
2668 new_spacing = Spacing::Single;
2669 } else if (tmp == "onehalf") {
2670 new_spacing = Spacing::Onehalf;
2671 } else if (tmp == "double") {
2672 new_spacing = Spacing::Double;
2673 } else if (tmp == "other") {
2674 new_spacing = Spacing::Other;
2677 lyxerr << "new_value = " << tmpval << endl;
2680 } else if (tmp == "default") {
2681 new_spacing = Spacing::Default;
2683 lyxerr << _("Unknown spacing argument: ")
2684 << argument << endl;
2686 if (cur_spacing != new_spacing || cur_value != new_value) {
2687 par->params().spacing(Spacing(new_spacing, new_value));
2688 lt->redoParagraph(bv_);
2691 | BufferView::FITCUR
2692 | BufferView::CHANGE);
2697 case LFUN_INSET_TOGGLE:
2699 LyXText * lt = bv_->getLyXText();
2702 update(lt, BufferView::SELECT|BufferView::FITCUR);
2703 lt->toggleInset(bv_);
2704 update(lt, BufferView::SELECT|BufferView::FITCUR);
2716 InsetCommandParams p;
2717 if (action == LFUN_HTMLURL)
2718 p.setCmdName("htmlurl");
2720 p.setCmdName("url");
2721 owner_->getDialogs()->createUrl(p.getAsString());
2725 case LFUN_INSERT_URL:
2727 InsetCommandParams p;
2728 p.setFromString(argument);
2730 InsetUrl * inset = new InsetUrl(p);
2731 if (!insertInset(inset))
2734 updateInset(inset, true);
2738 case LFUN_INSET_ERT:
2739 insertAndEditInset(new InsetERT(buffer_->params));
2742 case LFUN_INSET_EXTERNAL:
2743 insertAndEditInset(new InsetExternal);
2746 case LFUN_INSET_FOOTNOTE:
2747 insertAndEditInset(new InsetFoot(buffer_->params));
2750 case LFUN_INSET_MARGINAL:
2751 insertAndEditInset(new InsetMarginal(buffer_->params));
2754 case LFUN_INSET_MINIPAGE:
2755 insertAndEditInset(new InsetMinipage(buffer_->params));
2758 case LFUN_INSERT_NOTE:
2759 insertAndEditInset(new InsetNote(buffer_->params));
2762 case LFUN_INSET_FLOAT:
2763 // check if the float type exist
2764 if (floatList.typeExist(argument)) {
2765 insertAndEditInset(new InsetFloat(buffer_->params,
2768 lyxerr << "Non-existent float type: "
2769 << argument << endl;
2773 case LFUN_INSET_WIDE_FLOAT:
2774 // check if the float type exist
2775 if (floatList.typeExist(argument)) {
2776 InsetFloat * new_inset =
2777 new InsetFloat(buffer_->params, argument);
2778 new_inset->wide(true);
2779 insertAndEditInset(new_inset);
2781 lyxerr << "Non-existent float type: "
2782 << argument << endl;
2787 case LFUN_INSET_LIST:
2788 insertAndEditInset(new InsetList);
2791 case LFUN_INSET_THEOREM:
2792 insertAndEditInset(new InsetTheorem);
2796 case LFUN_INSET_CAPTION:
2798 // Do we have a locking inset...
2799 if (bv_->theLockingInset()) {
2800 lyxerr << "Locking inset code: "
2801 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2802 InsetCaption * new_inset =
2803 new InsetCaption(buffer_->params);
2804 new_inset->setOwner(bv_->theLockingInset());
2805 new_inset->setAutoBreakRows(true);
2806 new_inset->setDrawFrame(0, InsetText::LOCKED);
2807 new_inset->setFrameColor(0, LColor::captionframe);
2808 if (insertInset(new_inset))
2809 new_inset->edit(bv_);
2816 case LFUN_INSET_TABULAR:
2820 if (!argument.empty())
2821 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2822 InsetTabular * new_inset =
2823 new InsetTabular(*buffer_, r, c);
2825 bv_->getLyXText()->real_current_font.isRightToLeft();
2826 if (!open_new_inset(new_inset, rtl))
2831 // --- lyxserver commands ----------------------------
2833 case LFUN_CHARATCURSOR:
2835 pos_type pos = bv_->getLyXText()->cursor.pos();
2836 if (pos < bv_->getLyXText()->cursor.par()->size())
2837 owner_->getLyXFunc()->setMessage(
2838 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2840 owner_->getLyXFunc()->setMessage("EOF");
2845 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2847 + tostr(bv_->getLyXText()->cursor.y()));
2854 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2855 lyxerr << "SETXY: Could not parse coordinates in '"
2856 << argument << std::endl;
2858 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2862 case LFUN_GETLAYOUT:
2863 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2868 LyXFont & font = bv_->getLyXText()->current_font;
2869 if (font.shape() == LyXFont::ITALIC_SHAPE)
2870 owner_->getLyXFunc()->setMessage("E");
2871 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2872 owner_->getLyXFunc()->setMessage("N");
2874 owner_->getLyXFunc()->setMessage("0");
2879 // --- accented characters ---------------------------
2882 case LFUN_CIRCUMFLEX:
2892 case LFUN_SPECIAL_CARON:
2895 case LFUN_HUNG_UMLAUT:
2898 if (argument.empty()) {
2900 owner_->getLyXFunc()->handleKeyFunc(action);
2902 owner_->getLyXFunc()->handleKeyFunc(action);
2903 owner_->getIntl()->getTransManager()
2904 .TranslateAndInsert(argument[0], bv_->getLyXText());
2905 update(bv_->getLyXText(),
2907 | BufferView::FITCUR
2908 | BufferView::CHANGE);
2913 mathDispatch(bv_, argument);
2916 case LFUN_MATH_MACRO:
2917 mathDispatchMathMacro(bv_, argument);
2920 case LFUN_MATH_DELIM:
2921 mathDispatchMathDelim(bv_, argument);
2924 case LFUN_INSERT_MATRIX:
2925 mathDispatchInsertMatrix(bv_, argument);
2928 case LFUN_INSERT_MATH:
2929 mathDispatchInsertMath(bv_, argument);
2932 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2933 mathDispatchMathImportSelection(bv_, argument);
2936 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2937 mathDispatchMathDisplay(bv_, argument);
2940 case LFUN_MATH_MODE: // Open or create an inlined math inset
2941 mathDispatchMathMode(bv_, argument);
2944 case LFUN_GREEK: // Insert a single greek letter
2945 mathDispatchGreek(bv_, argument);
2948 case LFUN_CITATION_INSERT:
2950 InsetCommandParams p;
2951 p.setFromString(argument);
2953 InsetCitation * inset = new InsetCitation(p);
2954 if (!insertInset(inset))
2957 updateInset(inset, true);
2961 case LFUN_INSERT_BIBTEX:
2963 // ale970405+lasgoutt970425
2964 // The argument can be up to two tokens separated
2965 // by a space. The first one is the bibstyle.
2966 string const db = token(argument, ' ', 0);
2967 string const bibstyle = token(argument, ' ', 1);
2969 InsetCommandParams p("BibTeX", db, bibstyle);
2970 InsetBibtex * inset = new InsetBibtex(p);
2972 if (insertInset(inset)) {
2973 if (argument.empty())
2980 // BibTeX data bases
2981 case LFUN_BIBDB_ADD:
2983 InsetBibtex * inset =
2984 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2986 inset->addDatabase(argument);
2991 case LFUN_BIBDB_DEL:
2993 InsetBibtex * inset =
2994 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2996 inset->delDatabase(argument);
3001 case LFUN_BIBTEX_STYLE:
3003 InsetBibtex * inset =
3004 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3006 inset->setOptions(argument);
3011 case LFUN_INDEX_INSERT:
3013 string entry = argument;
3014 if (entry.empty()) {
3015 entry = bv_->getLyXText()->getStringToIndex(bv_);
3018 if (entry.empty()) {
3019 owner_->getDialogs()->createIndex();
3023 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3025 if (!insertInset(inset)) {
3028 updateInset(inset, true);
3033 case LFUN_INDEX_PRINT:
3035 InsetCommandParams p("printindex");
3036 Inset * inset = new InsetPrintIndex(p);
3037 if (!insertInset(inset, tclass.defaultLayoutName()))
3042 case LFUN_PARENTINSERT:
3044 InsetCommandParams p("lyxparent", argument);
3045 Inset * inset = new InsetParent(p, *buffer_);
3046 if (!insertInset(inset, tclass.defaultLayoutName()))
3052 case LFUN_CHILD_INSERT:
3054 InsetInclude::Params p;
3055 p.cparams.setFromString(argument);
3056 p.masterFilename_ = buffer_->fileName();
3058 InsetInclude * inset = new InsetInclude(p);
3059 if (!insertInset(inset))
3062 updateInset(inset, true);
3063 bv_->owner()->getDialogs()->showInclude(inset);
3068 case LFUN_FLOAT_LIST:
3069 if (floatList.typeExist(argument)) {
3070 Inset * inset = new InsetFloatList(argument);
3071 if (!insertInset(inset, tclass.defaultLayoutName()))
3074 lyxerr << "Non-existent float type: "
3075 << argument << endl;
3079 case LFUN_THESAURUS_ENTRY:
3081 string arg = argument;
3084 arg = bv_->getLyXText()->selectionAsString(buffer_,
3088 if (arg.size() > 100 || arg.empty()) {
3089 // Get word or selection
3090 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3091 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3092 // FIXME: where is getLyXText()->unselect(bv_) ?
3096 bv_->owner()->getDialogs()->showThesaurus(arg);
3100 case LFUN_SELFINSERT:
3102 if (argument.empty()) break;
3104 /* Automatically delete the currently selected
3105 * text and replace it with what is being
3106 * typed in now. Depends on lyxrc settings
3107 * "auto_region_delete", which defaults to
3110 LyXText * lt = bv_->getLyXText();
3112 if (lyxrc.auto_region_delete) {
3113 if (lt->selection.set()) {
3114 lt->cutSelection(bv_, false, false);
3117 | BufferView::FITCUR
3118 | BufferView::CHANGE);
3120 workarea().haveSelection(false);
3124 LyXFont const old_font(lt->real_current_font);
3126 string::const_iterator cit = argument.begin();
3127 string::const_iterator end = argument.end();
3128 for (; cit != end; ++cit) {
3129 owner_->getIntl()->getTransManager().
3130 TranslateAndInsert(*cit, lt);
3135 | BufferView::FITCUR
3136 | BufferView::CHANGE);
3138 lt->selection.cursor = lt->cursor;
3139 moveCursorUpdate(false);
3141 // real_current_font.number can change so we need to
3142 // update the minibuffer
3143 if (old_font != lt->real_current_font)
3144 owner_->view_state_changed();
3149 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3151 time_t now_time_t = time(NULL);
3152 struct tm * now_tm = localtime(&now_time_t);
3153 setlocale(LC_TIME, "");
3155 if (!argument.empty())
3158 arg = lyxrc.date_insert_format;
3160 int const datetmp_len =
3161 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3163 LyXText * lt = bv_->getLyXText();
3165 for (int i = 0; i < datetmp_len; i++) {
3166 lt->insertChar(bv_, datetmp[i]);
3169 | BufferView::FITCUR
3170 | BufferView::CHANGE);
3173 lt->selection.cursor = lt->cursor;
3174 moveCursorUpdate(false);
3178 case LFUN_UNKNOWN_ACTION:
3179 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3190 void BufferView::Pimpl::newline()
3193 LyXText * lt = bv_->getLyXText();
3197 | BufferView::FITCUR);
3198 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3201 | BufferView::FITCUR
3202 | BufferView::CHANGE);
3207 void BufferView::Pimpl::hfill()
3210 LyXText * lt = bv_->getLyXText();
3214 | BufferView::FITCUR);
3215 lt->insertChar(bv_, Paragraph::META_HFILL);
3218 | BufferView::FITCUR
3219 | BufferView::CHANGE);
3224 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3227 LyXText * lt = bv_->getLyXText();
3230 update(lt, BufferView::SELECT|BufferView::FITCUR);
3231 InsetSpecialChar * new_inset =
3232 new InsetSpecialChar(kind);
3233 if (!insertInset(new_inset))
3236 updateInset(new_inset, true);
3241 void BufferView::Pimpl::smartQuote()
3243 LyXText const * lt = bv_->getLyXText();
3244 Paragraph const * par = lt->cursor.par();
3245 pos_type pos = lt->cursor.pos();
3249 || (par->isInset(pos - 1)
3250 && par->getInset(pos - 1)->isSpace()))
3253 c = par->getChar(pos - 1);
3258 LyXLayout_ptr const & style = par->layout();
3260 if (style->pass_thru ||
3261 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3262 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, string("\""));
3266 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3269 if (insertInset(inset))
3274 bool gotsel = false;
3276 if (bv_->getLyXText()->selection.set()) {
3277 bv_->getLyXText()->cutSelection(bv_, true, false);
3281 if (insertInset(inset)) {
3284 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3292 // Open and lock an updatable inset
3293 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3295 LyXText * lt = bv_->getLyXText();
3299 if (!insertInset(new_inset)) {
3303 new_inset->edit(bv_, !behind);
3308 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3310 // if we are in a locking inset we should try to insert the
3311 // inset there otherwise this is a illegal function now
3312 if (bv_->theLockingInset()) {
3313 if (bv_->theLockingInset()->insetAllowed(inset))
3314 return bv_->theLockingInset()->insertInset(bv_, inset);
3318 // not quite sure if we want this...
3319 setCursorParUndo(bv_);
3322 beforeChange(bv_->text);
3323 if (!lout.empty()) {
3324 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3325 bv_->text->breakParagraph(bv_);
3326 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3328 if (bv_->text->cursor.par()->size()) {
3329 bv_->text->cursorLeft(bv_);
3331 bv_->text->breakParagraph(bv_);
3332 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3336 LyXTextClass const & tclass =
3337 buffer_->params.getLyXTextClass();
3338 bool hasLayout = tclass.hasLayout(lres);
3339 string lay = tclass.defaultLayoutName();
3341 if (hasLayout != false) {
3345 // layout not fount using default
3346 lay = tclass.defaultLayoutName();
3349 bv_->text->setLayout(bv_, lay);
3351 bv_->text->setParagraph(bv_, 0, 0,
3353 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3358 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3361 bv_->text->insertInset(bv_, inset);
3362 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3369 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3371 if (!inset || !available())
3374 // first check for locking insets
3375 if (bv_->theLockingInset()) {
3376 if (bv_->theLockingInset() == inset) {
3377 if (bv_->text->updateInset(bv_, inset)) {
3380 buffer_->markDirty();
3385 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3386 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3389 buffer_->markDirty();
3397 // then check if the inset is a top_level inset (has no owner)
3398 // if yes do the update as always otherwise we have to update the
3399 // toplevel inset where this inset is inside
3400 Inset * tl_inset = inset;
3401 while(tl_inset->owner())
3402 tl_inset = tl_inset->owner();
3404 if (tl_inset == inset) {
3405 update(bv_->text, BufferView::UPDATE);
3406 if (bv_->text->updateInset(bv_, inset)) {
3410 | BufferView::FITCUR
3411 | BufferView::CHANGE);
3413 update(bv_->text, SELECT);
3417 } else if (static_cast<UpdatableInset *>(tl_inset)
3418 ->updateInsetInInset(bv_, inset))
3420 if (bv_->text->updateInset(bv_, tl_inset)) {
3428 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3431 if (!available()) return;
3434 beforeChange(bv_->text);
3435 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3437 LyXCursor const & cursor = bv_->text->cursor;
3441 cursor.par()->isInset(cursor.pos())) {
3442 Inset const * inset = cursor.par()->getInset(cursor.pos());
3443 if (find(codes.begin(), codes.end(), inset->lyxCode())
3446 static_cast<InsetCommand const *>(inset)->getContents();
3450 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3451 if (bv_->text->cursor.pos()
3452 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3453 LyXCursor tmp = bv_->text->cursor;
3454 bv_->text->cursor.par(bv_->text->ownerParagraph());
3455 bv_->text->cursor.pos(0);
3456 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3457 bv_->text->cursor = tmp;
3458 bv_->owner()->message(_("No more insets"));
3461 bv_->owner()->message(_("No more insets"));
3464 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3465 bv_->text->selection.cursor = bv_->text->cursor;
3469 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3471 gotoInset(vector<Inset::Code>(1, code), same_content);