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 const unsigned int saved_positions_num = 20;
127 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
128 int xpos, int ypos, int width, int height)
129 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
130 using_xterm_cursor(false)
132 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
133 screen_.reset(LyXScreenFactory::create(workarea()));
136 workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
137 workarea().workAreaResize
138 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
139 workarea().workAreaButtonPress
140 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
141 workarea().workAreaButtonRelease
142 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
143 workarea().workAreaMotionNotify
144 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
145 workarea().workAreaDoubleClick
146 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
147 workarea().workAreaTripleClick
148 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
149 workarea().workAreaKeyPress
150 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
151 workarea().selectionRequested
152 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
153 workarea().selectionLost
154 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
156 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
157 cursor_timeout.start();
158 saved_positions.resize(saved_positions_num);
162 WorkArea & BufferView::Pimpl::workarea() const
164 return *workarea_.get();
168 LyXScreen & BufferView::Pimpl::screen() const
170 return *screen_.get();
174 Painter & BufferView::Pimpl::painter() const
176 return workarea().getPainter();
180 void BufferView::Pimpl::buffer(Buffer * b)
182 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
185 buffer_->delUser(bv_);
187 // Put the old text into the TextCache, but
188 // only if the buffer is still loaded.
189 // Also set the owner of the test to 0
190 // bv_->text->owner(0);
191 textcache.add(buffer_, workarea().workWidth(), bv_->text);
192 if (lyxerr.debugging())
193 textcache.show(lyxerr, "BufferView::buffer");
198 // Set current buffer
201 if (bufferlist.getState() == BufferList::CLOSING) return;
203 // If we are closing the buffer, use the first buffer as current
205 buffer_ = bufferlist.first();
209 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
210 buffer_->addUser(bv_);
212 // If we don't have a text object for this, we make one
213 if (bv_->text == 0) {
214 resizeCurrentBuffer();
217 // FIXME: needed when ?
218 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
220 // Similarly, buffer-dependent dialogs should be updated or
221 // hidden. This should go here because some dialogs (eg ToC)
222 // require bv_->text.
223 owner_->getDialogs()->updateBufferDependent(true);
225 lyxerr[Debug::INFO] << " No Buffer!" << endl;
226 owner_->getDialogs()->hideBufferDependent();
228 // Also remove all remaining text's from the testcache.
229 // (there should not be any!) (if there is any it is a
231 if (lyxerr.debugging())
232 textcache.show(lyxerr, "buffer delete all");
238 owner_->updateMenubar();
239 owner_->updateToolbar();
240 owner_->updateLayoutChoice();
241 owner_->updateWindowTitle();
243 if (grfx::Previews::activated() && buffer_)
244 grfx::Previews::get().generateBufferPreviews(*buffer_);
248 bool BufferView::Pimpl::fitCursor()
252 if (bv_->theLockingInset()) {
253 bv_->theLockingInset()->fitInsetCursor(bv_);
256 ret = screen().fitCursor(bv_->text, bv_);
259 bv_->owner()->getDialogs()->updateParagraph();
266 void BufferView::Pimpl::redoCurrentBuffer()
268 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
269 if (buffer_ && bv_->text) {
270 resizeCurrentBuffer();
271 owner_->updateLayoutChoice();
276 int BufferView::Pimpl::resizeCurrentBuffer()
278 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
281 Paragraph * selstartpar = 0;
282 Paragraph * selendpar = 0;
283 UpdatableInset * the_locking_inset = 0;
286 pos_type selstartpos = 0;
287 pos_type selendpos = 0;
288 bool selection = false;
289 bool mark_set = false;
291 owner_->prohibitInput();
293 owner_->message(_("Formatting document..."));
296 par = bv_->text->cursor.par();
297 pos = bv_->text->cursor.pos();
298 selstartpar = bv_->text->selection.start.par();
299 selstartpos = bv_->text->selection.start.pos();
300 selendpar = bv_->text->selection.end.par();
301 selendpos = bv_->text->selection.end.pos();
302 selection = bv_->text->selection.set();
303 mark_set = bv_->text->selection.mark();
304 the_locking_inset = bv_->theLockingInset();
305 buffer_->resizeInsets(bv_);
306 // I don't think the delete and new are necessary here we just could
307 // call only init! (Jug 20020419)
309 bv_->text = new LyXText(bv_);
310 bv_->text->init(bv_);
312 // See if we have a text in TextCache that fits
313 // the new buffer_ with the correct width.
314 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
316 if (lyxerr.debugging()) {
317 lyxerr << "Found a LyXText that fits:\n";
318 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
320 // Set the owner of the newly found text
321 // bv_->text->owner(bv_);
322 if (lyxerr.debugging())
323 textcache.show(lyxerr, "resizeCurrentBuffer");
325 bv_->text = new LyXText(bv_);
326 bv_->text->init(bv_);
327 //buffer_->resizeInsets(bv_);
332 bv_->text->selection.set(true);
333 // At this point just to avoid the Delete-Empty-Paragraph-
334 // Mechanism when setting the cursor.
335 bv_->text->selection.mark(mark_set);
337 bv_->text->setCursor(bv_, selstartpar, selstartpos);
338 bv_->text->selection.cursor = bv_->text->cursor;
339 bv_->text->setCursor(bv_, selendpar, selendpos);
340 bv_->text->setSelection(bv_);
341 bv_->text->setCursor(bv_, par, pos);
343 bv_->text->setCursor(bv_, par, pos);
344 bv_->text->selection.cursor = bv_->text->cursor;
345 bv_->text->selection.set(false);
347 // remake the inset locking
348 bv_->theLockingInset(the_locking_inset);
351 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
354 owner_->allowInput();
356 /// clear the "Formatting Document" message
363 void BufferView::Pimpl::repaint()
365 // Regenerate the screen.
366 screen().redraw(bv_->text, bv_);
370 void BufferView::Pimpl::updateScrollbar()
373 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
374 workarea().setScrollbarParams(0, 0, 0);
378 LyXText const & t = *bv_->text;
380 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
381 << t.first_y << ", default height " << t.defaultHeight() << endl;
383 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
387 void BufferView::Pimpl::scrollDocView(int value)
389 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
391 if (!buffer_) return;
393 screen().draw(bv_->text, bv_, value);
395 if (!lyxrc.cursor_follows_scrollbar) {
399 LyXText * vbt = bv_->text;
401 int const height = vbt->defaultHeight();
402 int const first = static_cast<int>((bv_->text->first_y + height));
403 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
405 if (vbt->cursor.y() < first)
406 vbt->setCursorFromCoordinates(bv_, 0, first);
407 else if (vbt->cursor.y() > last)
408 vbt->setCursorFromCoordinates(bv_, 0, last);
412 int BufferView::Pimpl::scroll(long time)
417 LyXText const * t = bv_->text;
419 double const diff = t->defaultHeight()
420 + double(time) * double(time) * 0.125;
422 scrollDocView(int(diff));
423 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
428 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
429 key_modifier::state state)
431 bv_->owner()->getLyXFunc()->processKeySym(key, state);
435 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
437 // Only use motion with button 1
438 if (!(state & mouse_button::button1))
444 // Check for inset locking
445 if (bv_->theLockingInset()) {
446 LyXCursor cursor = bv_->text->cursor;
447 LyXFont font = bv_->text->getFont(buffer_,
448 cursor.par(), cursor.pos());
449 int width = bv_->theLockingInset()->width(bv_, font);
450 int inset_x = font.isVisibleRightToLeft()
451 ? cursor.ix() - width : cursor.ix();
452 int start_x = inset_x + bv_->theLockingInset()->scroll();
454 bv_->theLockingInset()->
455 insetMotionNotify(bv_,
457 y - cursor.iy() + bv_->text->first_y,
462 /* The test for not selection possible is needed, that only motion
463 events are used, where the bottom press event was on
464 the drawing area too */
465 if (!selection_possible)
468 screen().hideCursor();
470 Row * cursorrow = bv_->text->cursor.row();
471 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
473 // sorry for this but I have a strange error that the y value jumps at
474 // a certain point. This seems like an error in my xforms library or
475 // in some other local environment, but I would like to leave this here
476 // for the moment until I can remove this (Jug 20020418)
477 if (y_before < bv_->text->cursor.y())
478 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
480 // This is to allow jumping over large insets
481 if (cursorrow == bv_->text->cursor.row()) {
482 if (y >= int(workarea().workHeight())) {
483 bv_->text->cursorDown(bv_, false);
485 bv_->text->cursorUp(bv_, false);
489 if (!bv_->text->selection.set())
490 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
492 bv_->text->setSelection(bv_);
493 screen().toggleToggle(bv_->text, bv_);
499 // Single-click on work area
500 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
501 mouse_button::state button)
506 // ok ok, this is a hack (for xforms)
507 if (button == mouse_button::button4) {
508 scroll(-lyxrc.wheel_jump);
509 // We shouldn't go further down as we really should only do the
510 // scrolling and be done with this. Otherwise we may open some
511 // dialogs (Jug 20020424).
513 } else if (button == mouse_button::button5) {
514 scroll(lyxrc.wheel_jump);
515 // We shouldn't go further down as we really should only do the
516 // scrolling and be done with this. Otherwise we may open some
517 // dialogs (Jug 20020424).
521 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
523 // Middle button press pastes if we have a selection
524 // We do this here as if the selection was inside an inset
525 // it could get cleared on the unlocking of the inset so
526 // we have to check this first
527 bool paste_internally = false;
528 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
529 owner_->getLyXFunc()->dispatch(LFUN_COPY);
530 paste_internally = true;
533 int const screen_first = bv_->text->first_y;
535 if (bv_->theLockingInset()) {
536 // We are in inset locking mode
538 /* Check whether the inset was hit. If not reset mode,
539 otherwise give the event to the inset */
540 if (inset_hit == bv_->theLockingInset()) {
541 bv_->theLockingInset()->
542 insetButtonPress(bv_, xpos, ypos, button);
545 bv_->unlockInset(bv_->theLockingInset());
550 selection_possible = true;
551 screen().hideCursor();
553 // Clear the selection
554 screen().toggleSelection(bv_->text, bv_);
555 bv_->text->clearSelection();
556 bv_->text->fullRebreak(bv_);
560 // Single left click in math inset?
561 if (isHighlyEditableInset(inset_hit)) {
562 // Highly editable inset, like math
563 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
564 selection_possible = false;
565 owner_->updateLayoutChoice();
566 owner_->message(inset->editMessage());
567 //inset->edit(bv_, xpos, ypos, button);
568 // We just have to lock the inset before calling a PressEvent on it!
569 // we don't need the edit() call here! (Jug20020329)
570 if (!bv_->lockInset(inset)) {
571 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
573 inset->insetButtonPress(bv_, xpos, ypos, button);
576 // I'm not sure we should continue here if we hit an inset (Jug20020403)
578 // Right click on a footnote flag opens float menu
579 if (button == mouse_button::button3) {
580 selection_possible = false;
584 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
585 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
587 bv_->text->selection.cursor = bv_->text->cursor;
588 bv_->text->cursor.x_fix(bv_->text->cursor.x());
590 owner_->updateLayoutChoice();
592 selection_possible = false;
595 // Insert primary selection with middle mouse
596 // if there is a local selection in the current buffer,
598 if (button == mouse_button::button2) {
599 if (paste_internally)
600 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
602 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
603 string("paragraph"));
604 selection_possible = false;
610 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
615 LyXText * text = bv_->getLyXText();
617 if (text->bv_owner && bv_->theLockingInset())
620 if (button == mouse_button::button1) {
621 if (text->bv_owner) {
622 screen().hideCursor();
623 screen().toggleSelection(text, bv_);
624 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
625 screen().toggleSelection(text, bv_, false);
627 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
629 /* This will fit the cursor on the screen
631 update(text, BufferView::SELECT|BufferView::FITCUR);
636 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
641 LyXText * text = bv_->getLyXText();
643 if (text->bv_owner && bv_->theLockingInset())
646 if (button == mouse_button::button1) {
647 if (text->bv_owner) {
648 screen().hideCursor();
649 screen().toggleSelection(text, bv_);
651 text->cursorHome(bv_);
652 text->selection.cursor = text->cursor;
653 text->cursorEnd(bv_);
654 text->setSelection(bv_);
655 if (text->bv_owner) {
656 screen().toggleSelection(text, bv_, false);
658 /* This will fit the cursor on the screen
660 update(text, BufferView::SELECT|BufferView::FITCUR);
665 void BufferView::Pimpl::selectionRequested()
672 LyXText * text = bv_->getLyXText();
674 if (text->selection.set() &&
675 (!bv_->text->xsel_cache.set() ||
676 text->selection.start != bv_->text->xsel_cache.start ||
677 text->selection.end != bv_->text->xsel_cache.end))
679 bv_->text->xsel_cache = text->selection;
680 sel = text->selectionAsString(bv_->buffer(), false);
681 } else if (!text->selection.set()) {
683 bv_->text->xsel_cache.set(false);
686 workarea().putClipboard(sel);
691 void BufferView::Pimpl::selectionLost()
696 bv_->getLyXText()->clearSelection();
698 bv_->text->xsel_cache.set(false);
703 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
704 mouse_button::state button)
706 // do nothing if we used the mouse wheel
707 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
710 // If we hit an inset, we have the inset coordinates in these
711 // and inset_hit points to the inset. If we do not hit an
712 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
713 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
715 if (bv_->theLockingInset()) {
716 // We are in inset locking mode.
718 /* LyX does a kind of work-area grabbing for insets.
719 Only a ButtonPress Event outside the inset will
720 force a insetUnlock. */
721 bv_->theLockingInset()->
722 insetButtonRelease(bv_, x, y, button);
726 selection_possible = false;
728 if (button == mouse_button::button2)
732 if (button == mouse_button::button1) {
733 workarea().haveSelection(bv_->getLyXText()->selection.set());
737 owner_->view_state_changed();
738 owner_->updateMenubar();
739 owner_->updateToolbar();
741 // Did we hit an editable inset?
743 selection_possible = false;
745 // if we reach this point with a selection, it
746 // must mean we are currently selecting.
747 // But we don't want to open the inset
748 // because that is annoying for the user.
749 // So just pretend we didn't hit it.
750 // this is OK because a "kosher" ButtonRelease
751 // will follow a ButtonPress that clears
753 // Note this also fixes selection drawing
754 // problems if we end up opening an inset
755 if (bv_->getLyXText()->selection.set())
758 // CHECK fix this proper in 0.13
759 // well, maybe 13.0 !!!!!!!!!
761 // Following a ref shouldn't issue
762 // a push on the undo-stack
763 // anylonger, now that we have
764 // keybindings for following
765 // references and returning from
766 // references. IMHO though, it
767 // should be the inset's own business
768 // to push or not push on the undo
769 // stack. They don't *have* to
770 // alter the document...
772 // ...or maybe the SetCursorParUndo()
773 // below isn't necessary at all anylonger?
774 if (inset_hit->lyxCode() == Inset::REF_CODE) {
775 setCursorParUndo(bv_);
778 owner_->message(inset_hit->editMessage());
780 if (isHighlyEditableInset(inset_hit)) {
781 // Highly editable inset, like math
782 UpdatableInset *inset = (UpdatableInset *)inset_hit;
783 inset->insetButtonRelease(bv_, x, y, button);
785 inset_hit->insetButtonRelease(bv_, x, y, button);
786 // IMO this is a grosshack! Inset's should be changed so that
787 // they call the actions they have to do with the insetButtonRel.
788 // function and not in the edit(). This should be changed
790 inset_hit->edit(bv_, x, y, button);
795 // Maybe we want to edit a bibitem ale970302
796 if (bv_->text->cursor.par()->bibkey) {
797 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
798 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
799 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
800 (!is_rtl && x < 20+width)) {
801 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
809 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
810 LyXCursor const & cursor) const
812 Paragraph /*const*/ & par = *cursor.par();
813 pos_type const pos = cursor.pos();
815 lyx::Assert(par.getInset(pos));
817 Inset const & inset(*par.getInset(pos));
819 LyXFont const & font = text.getFont(buffer_, &par, pos);
821 int const width = inset.width(bv_, font);
822 int const inset_x = font.isVisibleRightToLeft()
823 ? (cursor.ix() - width) : cursor.ix();
826 inset_x + inset.scroll(),
828 cursor.iy() - inset.ascent(bv_, font),
829 cursor.iy() + inset.descent(bv_, font));
833 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
834 LyXCursor const & cursor,
835 int & x, int & y) const
837 pos_type const pos(cursor.pos());
838 Paragraph /*const*/ & par(*cursor.par());
840 if (pos >= par.size() || !par.isInset(pos)) {
844 Inset /*const*/ * inset = par.getInset(pos);
846 if (!isEditableInset(inset)) {
850 Box b(insetDimensions(text, cursor));
852 if (!b.contained(x, y)) {
853 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
854 << " box " << b << endl;
858 text.setCursor(bv_, &par, pos, true);
861 // The origin of an inset is on the baseline
862 y -= text.cursor.iy();
868 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
870 int y_tmp = y + text->first_y;
873 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
875 Inset * inset(checkInset(*text, cursor, x, y_tmp));
882 // look at previous position
884 if (cursor.pos() == 0) {
889 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
891 inset = checkInset(*text, cursor, x, y_tmp);
899 void BufferView::Pimpl::workAreaResize()
901 static int work_area_width;
902 static int work_area_height;
904 bool const widthChange = workarea().workWidth() != work_area_width;
905 bool const heightChange = workarea().workHeight() != work_area_height;
907 // update from work area
908 work_area_width = workarea().workWidth();
909 work_area_height = workarea().workHeight();
913 // The visible LyXView need a resize
914 resizeCurrentBuffer();
916 // Remove all texts from the textcache
917 // This is not _really_ what we want to do. What
918 // we really want to do is to delete in textcache
919 // that does not have a BufferView with matching
920 // width, but as long as we have only one BufferView
921 // deleting all gives the same result.
922 if (lyxerr.debugging())
923 textcache.show(lyxerr, "Expose delete all");
925 // FIXME: this is aalready done in resizeCurrentBuffer() ??
926 buffer_->resizeInsets(bv_);
927 } else if (heightChange) {
928 // fitCursor() ensures we don't jump back
929 // to the start of the document on vertical
935 if (widthChange || heightChange) {
939 // always make sure that the scrollbar is sane.
941 owner_->updateLayoutChoice();
946 void BufferView::Pimpl::update()
948 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
949 LyXText::text_status st = bv_->text->status();
950 screen().update(bv_->text, bv_);
952 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
953 bv_->text->fullRebreak(bv_);
954 st = LyXText::NEED_MORE_REFRESH;
955 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
956 bv_->text->cursor.pos());
957 if (bv_->text->selection.set()) {
958 bv_->text->setCursor(bv_, bv_->text->selection.start,
959 bv_->text->selection.start.par(),
960 bv_->text->selection.start.pos());
961 bv_->text->setCursor(bv_, bv_->text->selection.end,
962 bv_->text->selection.end.par(),
963 bv_->text->selection.end.pos());
966 bv_->text->status(bv_, st);
967 screen().update(bv_->text, bv_);
969 // do this here instead of in the screen::update because of
971 bv_->text->status(bv_, LyXText::UNCHANGED);
977 // Values used when calling update:
979 // -2 - update, move sel_cursor if selection, fitcursor
980 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
981 // 0 - update, move sel_cursor if selection, fitcursor
982 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
983 // 3 - update, move sel_cursor if selection
986 // a simple redraw of the parts that need refresh
988 // move sel_cursor if selection -
989 // the text's sel_cursor is moved if there is selection is progress
992 // fitCursor() is called and the scrollbar updated
995 // the buffer is marked dirty.
1004 // UPDATE_ONLY = UPDATE;
1005 // UPDATE_SELECT = UPDATE | SELECT;
1006 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1007 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1009 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1010 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1011 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1012 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1013 // update(3) -> update(1) -> update(1) -> update(SELECT)
1015 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1017 owner_->updateLayoutChoice();
1019 if (!text->selection.set() && (f & SELECT)) {
1020 text->selection.cursor = text->cursor;
1023 text->fullRebreak(bv_);
1025 if (text->inset_owner) {
1026 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1027 updateInset(text->inset_owner, false);
1037 buffer_->markDirty();
1042 // Callback for cursor timer
1043 void BufferView::Pimpl::cursorToggle()
1046 cursor_timeout.restart();
1051 extern void reapSpellchecker(void);
1054 if (!bv_->theLockingInset()) {
1055 screen().cursorToggle(bv_);
1057 bv_->theLockingInset()->toggleInsetCursor(bv_);
1060 cursor_timeout.restart();
1064 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1066 if (!text->cursor.row()->previous()) {
1067 if (text->first_y > 0) {
1068 int new_y = bv_->text->first_y - workarea().workHeight();
1069 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1075 int y = text->first_y;
1076 Row * cursorrow = text->cursor.row();
1078 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1082 if (cursorrow == bv_->text->cursor.row()) {
1083 // we have a row which is higher than the workarea so we leave the
1084 // cursor on the start of the row and move only the draw up as soon
1085 // as we move the cursor or do something while inside the row (it may
1086 // span several workarea-heights) we'll move to the top again, but this
1087 // is better than just jump down and only display part of the row.
1088 new_y = bv_->text->first_y - workarea().workHeight();
1090 if (text->inset_owner) {
1091 new_y = bv_->text->cursor.iy()
1092 + bv_->theLockingInset()->insetInInsetY() + y
1093 + text->cursor.row()->height()
1094 - workarea().workHeight() + 1;
1096 new_y = text->cursor.y()
1097 - text->cursor.row()->baseline()
1098 + text->cursor.row()->height()
1099 - workarea().workHeight() + 1;
1102 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1103 if (text->cursor.row()->previous()) {
1105 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1106 text->cursor.row()->previous()->pos(), false);
1107 if (cur.y() > text->first_y) {
1108 text->cursorUp(bv_, true);
1115 void BufferView::Pimpl::cursorNext(LyXText * text)
1117 if (!text->cursor.row()->next()) {
1118 int y = text->cursor.y() - text->cursor.row()->baseline() +
1119 text->cursor.row()->height();
1120 if (y > int(text->first_y + workarea().workHeight())) {
1121 screen().draw(bv_->text, bv_,
1122 bv_->text->first_y + workarea().workHeight());
1128 int y = text->first_y + workarea().workHeight();
1129 if (text->inset_owner && !text->first_y) {
1130 y -= (bv_->text->cursor.iy()
1131 - bv_->text->first_y
1132 + bv_->theLockingInset()->insetInInsetY());
1135 text->getRowNearY(y);
1137 Row * cursorrow = text->cursor.row();
1138 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1142 if (cursorrow == bv_->text->cursor.row()) {
1143 // we have a row which is higher than the workarea so we leave the
1144 // cursor on the start of the row and move only the draw down as soon
1145 // as we move the cursor or do something while inside the row (it may
1146 // span several workarea-heights) we'll move to the top again, but this
1147 // is better than just jump down and only display part of the row.
1148 new_y = bv_->text->first_y + workarea().workHeight();
1150 if (text->inset_owner) {
1151 new_y = bv_->text->cursor.iy()
1152 + bv_->theLockingInset()->insetInInsetY()
1153 + y - text->cursor.row()->baseline();
1155 new_y = text->cursor.y() - text->cursor.row()->baseline();
1158 screen().draw(bv_->text, bv_, new_y);
1159 if (text->cursor.row()->next()) {
1161 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1162 text->cursor.row()->next()->pos(), false);
1163 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1164 text->cursorDown(bv_, true);
1171 bool BufferView::Pimpl::available() const
1173 if (buffer_ && bv_->text)
1179 void BufferView::Pimpl::beforeChange(LyXText * text)
1182 text->clearSelection();
1186 void BufferView::Pimpl::savePosition(unsigned int i)
1188 if (i >= saved_positions_num)
1190 saved_positions[i] = Position(buffer_->fileName(),
1191 bv_->text->cursor.par()->id(),
1192 bv_->text->cursor.pos());
1195 str << _("Saved bookmark") << ' ' << i;
1196 owner_->message(str.str().c_str());
1201 void BufferView::Pimpl::restorePosition(unsigned int i)
1203 if (i >= saved_positions_num)
1206 string const fname = saved_positions[i].filename;
1208 beforeChange(bv_->text);
1210 if (fname != buffer_->fileName()) {
1211 Buffer * b = bufferlist.exists(fname) ?
1212 bufferlist.getBuffer(fname) :
1213 bufferlist.loadLyXFile(fname); // don't ask, just load it
1214 if (b != 0) buffer(b);
1217 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1221 bv_->text->setCursor(bv_, par,
1222 min(par->size(), saved_positions[i].par_pos));
1224 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1227 str << _("Moved to bookmark") << ' ' << i;
1228 owner_->message(str.str().c_str());
1233 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1235 if (i >= saved_positions_num)
1238 return !saved_positions[i].filename.empty();
1242 void BufferView::Pimpl::switchKeyMap()
1244 if (!lyxrc.rtl_support)
1247 LyXText * text = bv_->getLyXText();
1248 if (text->real_current_font.isRightToLeft()
1249 && !(bv_->theLockingInset()
1250 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1252 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1253 owner_->getIntl()->KeyMapSec();
1255 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1256 owner_->getIntl()->KeyMapPrim();
1261 void BufferView::Pimpl::insetUnlock()
1263 if (bv_->theLockingInset()) {
1264 bv_->theLockingInset()->insetUnlock(bv_);
1265 bv_->theLockingInset(0);
1271 void BufferView::Pimpl::showCursor()
1273 if (bv_->theLockingInset())
1274 bv_->theLockingInset()->showInsetCursor(bv_);
1276 screen().showCursor(bv_->text, bv_);
1280 void BufferView::Pimpl::hideCursor()
1282 if (!bv_->theLockingInset())
1283 screen().hideCursor();
1287 void BufferView::Pimpl::toggleSelection(bool b)
1289 if (bv_->theLockingInset())
1290 bv_->theLockingInset()->toggleSelection(bv_, b);
1291 screen().toggleSelection(bv_->text, bv_, b);
1295 void BufferView::Pimpl::toggleToggle()
1297 screen().toggleToggle(bv_->text, bv_);
1301 void BufferView::Pimpl::center()
1303 LyXText * t = bv_->text;
1306 int const half_height = workarea().workHeight() / 2;
1309 if (t->cursor.y() > half_height) {
1310 new_y = t->cursor.y() - half_height;
1313 // FIXME: can we do this w/o calling screen directly ?
1314 // This updates first_y but means the fitCursor() call
1315 // from the update(FITCUR) doesn't realise that we might
1316 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1317 // the scrollbar to be updated as it should, so we have
1318 // to do it manually. Any operation that does a center()
1319 // and also might have moved first_y must make sure to call
1320 // updateScrollbar() currently. Never mind that this is a
1321 // pretty obfuscated way of updating t->first_y
1322 screen().draw(t, bv_, new_y);
1324 update(t, BufferView::SELECT | BufferView::FITCUR);
1328 void BufferView::Pimpl::pasteClipboard(bool asPara)
1333 screen().hideCursor();
1334 beforeChange(bv_->text);
1336 string const clip(workarea().getClipboard());
1342 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1344 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1346 bv_->getLyXText()->clearSelection();
1347 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1351 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1353 workarea().putClipboard(stuff);
1358 * Dispatch functions for actions which can be valid for BufferView->text
1359 * and/or InsetText->text!!!
1364 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1366 LyXText * lt = bv_->getLyXText();
1368 if (selecting || lt->selection.mark()) {
1369 lt->setSelection(bv_);
1373 updateInset(lt->inset_owner, false);
1377 update(lt, BufferView::SELECT|BufferView::FITCUR);
1379 update(lt, BufferView::SELECT);
1381 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1382 bv_->theLockingInset()->hideInsetCursor(bv_);
1383 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1387 if (!lt->selection.set())
1388 workarea().haveSelection(false);
1394 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1396 LyXCursor cursor = bv_->getLyXText()->cursor;
1397 Buffer::inset_iterator it =
1398 find_if(Buffer::inset_iterator(
1399 cursor.par(), cursor.pos()),
1400 buffer_->inset_iterator_end(),
1401 lyx::compare_memfun(&Inset::lyxCode, code));
1402 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1406 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1408 string filename = filen;
1410 if (filename.empty()) {
1411 // Launch a file browser
1412 string initpath = lyxrc.document_path;
1415 string const trypath = owner_->buffer()->filePath();
1416 // If directory is writeable, use this as default.
1417 if (IsDirWriteable(trypath))
1421 FileDialog fileDlg(bv_->owner(),
1422 _("Select LyX document to insert"),
1424 make_pair(string(_("Documents|#o#O")),
1425 string(lyxrc.document_path)),
1426 make_pair(string(_("Examples|#E#e")),
1427 string(AddPath(system_lyxdir, "examples"))));
1429 FileDialog::Result result =
1430 fileDlg.Select(initpath,
1431 _("*.lyx| LyX Documents (*.lyx)"));
1433 if (result.first == FileDialog::Later)
1436 filename = result.second;
1438 // check selected filename
1439 if (filename.empty()) {
1440 owner_->message(_("Canceled."));
1445 // get absolute path of file and add ".lyx" to the filename if
1447 filename = FileSearch(string(), filename, "lyx");
1449 string const disp_fn(MakeDisplayPath(filename));
1452 s1 << _("Inserting document") << ' '
1453 << disp_fn << " ...";
1454 owner_->message(s1.str().c_str());
1455 bool const res = bv_->insertLyXFile(filename);
1458 str << _("Document") << ' ' << disp_fn
1459 << ' ' << _("inserted.");
1460 owner_->message(str.str().c_str());
1463 str << _("Could not insert document") << ' '
1465 owner_->message(str.str().c_str());
1470 bool BufferView::Pimpl::dispatch(kb_action action, string const & argument)
1472 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1473 << action <<"] arg[" << argument << "]" << endl;
1475 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1478 // --- Misc -------------------------------------------
1482 LyXText * lt = bv_->getLyXText();
1483 lt->toggleAppendix(bv_);
1486 | BufferView::FITCUR
1487 | BufferView::CHANGE);
1492 case LFUN_TOC_INSERT:
1494 InsetCommandParams p;
1495 p.setCmdName("tableofcontents");
1496 Inset * inset = new InsetTOC(p);
1497 if (!insertInset(inset, tclass.defaultLayoutName()))
1502 case LFUN_SCROLL_INSET:
1503 // this is not handled here as this funktion is only aktive
1504 // if we have a locking_inset and that one is (or contains)
1508 case LFUN_INSET_GRAPHICS:
1510 Inset * new_inset = new InsetGraphics;
1511 if (!insertInset(new_inset)) {
1514 // this is need because you don't use a inset->Edit()
1515 updateInset(new_inset, true);
1516 new_inset->edit(bv_);
1526 case LFUN_PASTESELECTION:
1528 bool asPara = false;
1529 if (argument == "paragraph")
1531 pasteClipboard(asPara);
1543 case LFUN_LAYOUT_COPY:
1544 bv_->copyEnvironment();
1547 case LFUN_LAYOUT_PASTE:
1548 bv_->pasteEnvironment();
1552 case LFUN_GOTOERROR:
1553 gotoInset(Inset::ERROR_CODE, false);
1557 gotoInset(Inset::IGNORE_CODE, false);
1560 case LFUN_REFERENCE_GOTO:
1562 vector<Inset::Code> tmp;
1563 tmp.push_back(Inset::LABEL_CODE);
1564 tmp.push_back(Inset::REF_CODE);
1565 gotoInset(tmp, true);
1569 case LFUN_HYPHENATION:
1570 specialChar(InsetSpecialChar::HYPHENATION);
1573 case LFUN_LIGATURE_BREAK:
1574 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1578 specialChar(InsetSpecialChar::LDOTS);
1581 case LFUN_END_OF_SENTENCE:
1582 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1585 case LFUN_MENU_SEPARATOR:
1586 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1593 case LFUN_DEPTH_MIN:
1594 changeDepth(bv_, bv_->getLyXText(), -1);
1597 case LFUN_DEPTH_PLUS:
1598 changeDepth(bv_, bv_->getLyXText(), 1);
1602 owner_->getDialogs()->setUserFreeFont();
1605 case LFUN_FILE_INSERT:
1606 MenuInsertLyXFile(argument);
1609 case LFUN_FILE_INSERT_ASCII_PARA:
1610 InsertAsciiFile(bv_, argument, true);
1613 case LFUN_FILE_INSERT_ASCII:
1614 InsertAsciiFile(bv_, argument, false);
1619 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1620 << argument << endl;
1622 // This is not the good solution to the empty argument
1623 // problem, but it will hopefully suffice for 1.2.0.
1624 // The correct solution would be to augument the
1625 // function list/array with information about what
1626 // functions needs arguments and their type.
1627 if (argument.empty()) {
1628 owner_->getLyXFunc()->setErrorMessage(
1629 _("LyX function 'layout' needs an argument."));
1633 // Derive layout number from given argument (string)
1634 // and current buffer's textclass (number). */
1635 bool hasLayout = tclass.hasLayout(argument);
1636 string layout = argument;
1638 // If the entry is obsolete, use the new one instead.
1640 string const & obs = tclass[layout]->obsoleted_by();
1646 owner_->getLyXFunc()->setErrorMessage(
1647 string(N_("Layout ")) + argument +
1652 bool change_layout = (current_layout != layout);
1653 LyXText * lt = bv_->getLyXText();
1654 if (!change_layout && lt->selection.set() &&
1655 lt->selection.start.par() != lt->selection.end.par())
1657 Paragraph * spar = lt->selection.start.par();
1658 Paragraph * epar = lt->selection.end.par()->next();
1659 while(spar != epar) {
1660 if (spar->layout()->name() != current_layout) {
1661 change_layout = true;
1666 if (change_layout) {
1668 current_layout = layout;
1671 | BufferView::FITCUR);
1672 lt->setLayout(bv_, layout);
1673 owner_->setLayout(layout);
1676 | BufferView::FITCUR
1677 | BufferView::CHANGE);
1684 lang(bv_, argument);
1686 owner_->view_state_changed();
1691 owner_->view_state_changed();
1696 owner_->view_state_changed();
1701 owner_->view_state_changed();
1706 owner_->view_state_changed();
1711 owner_->view_state_changed();
1716 owner_->view_state_changed();
1721 owner_->view_state_changed();
1724 case LFUN_UNDERLINE:
1726 owner_->view_state_changed();
1729 case LFUN_FONT_SIZE:
1730 fontSize(bv_, argument);
1731 owner_->view_state_changed();
1734 case LFUN_FONT_STATE:
1735 owner_->getLyXFunc()->setMessage(currentState(bv_));
1738 case LFUN_UPCASE_WORD:
1740 LyXText * lt = bv_->getLyXText();
1744 | BufferView::FITCUR);
1745 lt->changeCase(bv_, LyXText::text_uppercase);
1746 if (lt->inset_owner)
1747 updateInset(lt->inset_owner, true);
1750 | BufferView::FITCUR
1751 | BufferView::CHANGE);
1755 case LFUN_LOWCASE_WORD:
1757 LyXText * lt = bv_->getLyXText();
1759 update(lt, BufferView::SELECT|BufferView::FITCUR);
1760 lt->changeCase(bv_, LyXText::text_lowercase);
1761 if (lt->inset_owner)
1762 updateInset(lt->inset_owner, true);
1765 | BufferView::FITCUR
1766 | BufferView::CHANGE);
1770 case LFUN_CAPITALIZE_WORD:
1772 LyXText * lt = bv_->getLyXText();
1774 update(lt, BufferView::SELECT|BufferView::FITCUR);
1775 lt->changeCase(bv_, LyXText::text_capitalization);
1776 if (lt->inset_owner)
1777 updateInset(lt->inset_owner, true);
1780 | BufferView::FITCUR
1781 | BufferView::CHANGE);
1785 case LFUN_TRANSPOSE_CHARS:
1787 LyXText * lt = bv_->getLyXText();
1789 update(lt, BufferView::SELECT|BufferView::FITCUR);
1790 lt->transposeChars(*bv_);
1791 if (lt->inset_owner)
1792 updateInset(lt->inset_owner, true);
1795 | BufferView::FITCUR
1796 | BufferView::CHANGE);
1801 case LFUN_INSERT_LABEL:
1802 MenuInsertLabel(bv_, argument);
1805 case LFUN_REF_INSERT:
1806 if (argument.empty()) {
1807 InsetCommandParams p("ref");
1808 owner_->getDialogs()->createRef(p.getAsString());
1810 InsetCommandParams p;
1811 p.setFromString(argument);
1813 InsetRef * inset = new InsetRef(p, *buffer_);
1814 if (!insertInset(inset))
1817 updateInset(inset, true);
1821 case LFUN_BOOKMARK_SAVE:
1822 savePosition(strToUnsignedInt(argument));
1825 case LFUN_BOOKMARK_GOTO:
1826 restorePosition(strToUnsignedInt(argument));
1831 string label(argument);
1832 if (label.empty()) {
1834 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1836 label = inset->getContents();
1841 if (!label.empty()) {
1842 //bv_->savePosition(0);
1843 if (!bv_->gotoLabel(label))
1844 Alert::alert(_("Error"),
1845 _("Couldn't find this label"),
1846 _("in current document."));
1851 // --- Cursor Movements -----------------------------
1854 LyXText * lt = bv_->getLyXText();
1856 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1857 if (!lt->selection.mark())
1859 update(lt, BufferView::SELECT|BufferView::FITCUR);
1861 lt->cursorLeft(bv_, false);
1862 if (lt->cursor.pos() < lt->cursor.par()->size()
1863 && lt->cursor.par()->isInset(lt->cursor.pos())
1864 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1865 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1866 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1868 tmpinset->edit(bv_, false);
1870 tmpinset->edit(bv_);
1874 lt->cursorRight(bv_, false);
1876 moveCursorUpdate(false);
1877 owner_->view_state_changed();
1883 // This is soooo ugly. Isn`t it possible to make
1884 // it simpler? (Lgb)
1885 LyXText * lt = bv_->getLyXText();
1886 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1887 if (!lt->selection.mark())
1889 update(lt, BufferView::SELECT|BufferView::FITCUR);
1890 LyXCursor const cur = lt->cursor;
1892 lt->cursorLeft(bv_, false);
1893 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1894 lt->cursor.pos() < lt->cursor.par()->size() &&
1895 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1896 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1897 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1898 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1900 tmpinset->edit(bv_);
1902 tmpinset->edit(bv_, false);
1906 lt->cursorRight(bv_, false);
1909 moveCursorUpdate(false);
1910 owner_->view_state_changed();
1916 LyXText * lt = bv_->getLyXText();
1918 if (!lt->selection.mark())
1920 update(lt, BufferView::UPDATE);
1923 moveCursorUpdate(false);
1924 owner_->view_state_changed();
1930 LyXText * lt = bv_->getLyXText();
1932 if (!lt->selection.mark())
1934 update(lt, BufferView::UPDATE);
1935 lt->cursorDown(bv_);
1937 moveCursorUpdate(false);
1938 owner_->view_state_changed();
1942 case LFUN_UP_PARAGRAPH:
1944 LyXText * lt = bv_->getLyXText();
1946 if (!lt->selection.mark())
1948 update(lt, BufferView::UPDATE);
1949 lt->cursorUpParagraph(bv_);
1951 moveCursorUpdate(false);
1952 owner_->view_state_changed();
1956 case LFUN_DOWN_PARAGRAPH:
1958 LyXText * lt = bv_->getLyXText();
1960 if (!lt->selection.mark())
1962 update(lt, BufferView::UPDATE);
1963 lt->cursorDownParagraph(bv_);
1965 moveCursorUpdate(false);
1966 owner_->view_state_changed();
1972 LyXText * lt = bv_->getLyXText();
1974 if (!lt->selection.mark())
1976 update(lt, BufferView::UPDATE);
1979 moveCursorUpdate(false, false);
1980 owner_->view_state_changed();
1986 LyXText * lt = bv_->getLyXText();
1988 if (!lt->selection.mark())
1990 update(lt, BufferView::UPDATE);
1993 moveCursorUpdate(false, false);
1994 owner_->view_state_changed();
2000 LyXText * lt = bv_->getLyXText();
2002 if (!lt->selection.mark())
2004 update(lt, BufferView::SELECT|BufferView::FITCUR);
2005 lt->cursorHome(bv_);
2007 moveCursorUpdate(false);
2008 owner_->view_state_changed();
2014 LyXText * lt = bv_->getLyXText();
2016 if (!lt->selection.mark())
2019 BufferView::SELECT|BufferView::FITCUR);
2022 moveCursorUpdate(false);
2023 owner_->view_state_changed();
2027 case LFUN_SHIFT_TAB:
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_WORDRIGHT:
2045 LyXText * lt = bv_->getLyXText();
2047 if (!lt->selection.mark())
2049 update(lt, BufferView::SELECT|BufferView::FITCUR);
2050 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2051 lt->cursorLeftOneWord(bv_);
2053 lt->cursorRightOneWord(bv_);
2055 moveCursorUpdate(false);
2056 owner_->view_state_changed();
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->cursorRightOneWord(bv_);
2070 lt->cursorLeftOneWord(bv_);
2072 moveCursorUpdate(false);
2073 owner_->view_state_changed();
2077 case LFUN_BEGINNINGBUF:
2079 LyXText * lt = bv_->getLyXText();
2081 if (!lt->selection.mark())
2084 BufferView::SELECT|BufferView::FITCUR);
2087 moveCursorUpdate(false);
2088 owner_->view_state_changed();
2094 LyXText * lt = bv_->getLyXText();
2096 if (!lt->selection.mark())
2099 BufferView::SELECT|BufferView::FITCUR);
2100 lt->cursorBottom(bv_);
2102 moveCursorUpdate(false);
2103 owner_->view_state_changed();
2107 /* cursor selection ---------------------------- */
2110 LyXText * lt = bv_->getLyXText();
2113 BufferView::SELECT|BufferView::FITCUR);
2114 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2115 lt->cursorLeft(bv_);
2117 lt->cursorRight(bv_);
2119 moveCursorUpdate(true);
2120 owner_->view_state_changed();
2126 LyXText * lt = bv_->getLyXText();
2129 BufferView::SELECT|BufferView::FITCUR);
2130 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2131 lt->cursorRight(bv_);
2133 lt->cursorLeft(bv_);
2135 moveCursorUpdate(true);
2136 owner_->view_state_changed();
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 lt->cursorUp(bv_, true);
2148 moveCursorUpdate(true);
2149 owner_->view_state_changed();
2155 LyXText * lt = bv_->getLyXText();
2158 BufferView::SELECT|BufferView::FITCUR);
2159 lt->cursorDown(bv_, true);
2161 moveCursorUpdate(true);
2162 owner_->view_state_changed();
2166 case LFUN_UP_PARAGRAPHSEL:
2168 LyXText * lt = bv_->getLyXText();
2171 BufferView::SELECT|BufferView::FITCUR);
2172 lt->cursorUpParagraph(bv_);
2174 moveCursorUpdate(true);
2175 owner_->view_state_changed();
2179 case LFUN_DOWN_PARAGRAPHSEL:
2181 LyXText * lt = bv_->getLyXText();
2184 BufferView::SELECT|BufferView::FITCUR);
2185 lt->cursorDownParagraph(bv_);
2187 moveCursorUpdate(true);
2188 owner_->view_state_changed();
2194 LyXText * lt = bv_->getLyXText();
2196 update(lt, BufferView::SELECT|BufferView::FITCUR);
2199 moveCursorUpdate(true);
2200 owner_->view_state_changed();
2206 LyXText * lt = bv_->getLyXText();
2208 update(lt, BufferView::SELECT|BufferView::FITCUR);
2211 moveCursorUpdate(true);
2212 owner_->view_state_changed();
2218 LyXText * lt = bv_->getLyXText();
2220 update(lt, BufferView::SELECT|BufferView::FITCUR);
2221 lt->cursorHome(bv_);
2223 moveCursorUpdate(true);
2224 owner_->view_state_changed();
2230 LyXText * lt = bv_->getLyXText();
2232 update(lt, BufferView::SELECT|BufferView::FITCUR);
2235 moveCursorUpdate(true);
2236 owner_->view_state_changed();
2240 case LFUN_WORDRIGHTSEL:
2242 LyXText * lt = bv_->getLyXText();
2244 update(lt, BufferView::SELECT|BufferView::FITCUR);
2245 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2246 lt->cursorLeftOneWord(bv_);
2248 lt->cursorRightOneWord(bv_);
2250 moveCursorUpdate(true);
2251 owner_->view_state_changed();
2255 case LFUN_WORDLEFTSEL:
2257 LyXText * lt = bv_->getLyXText();
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2260 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2261 lt->cursorRightOneWord(bv_);
2263 lt->cursorLeftOneWord(bv_);
2265 moveCursorUpdate(true);
2266 owner_->view_state_changed();
2270 case LFUN_BEGINNINGBUFSEL:
2272 LyXText * lt = bv_->getLyXText();
2274 if (lt->inset_owner)
2276 update(lt, BufferView::SELECT|BufferView::FITCUR);
2279 moveCursorUpdate(true);
2280 owner_->view_state_changed();
2284 case LFUN_ENDBUFSEL:
2286 LyXText * lt = bv_->getLyXText();
2288 if (lt->inset_owner)
2291 BufferView::SELECT|BufferView::FITCUR);
2292 lt->cursorBottom(bv_);
2294 moveCursorUpdate(true);
2295 owner_->view_state_changed();
2299 // --- text changing commands ------------------------
2300 case LFUN_BREAKLINE:
2302 LyXText * lt = bv_->getLyXText();
2305 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2308 | BufferView::FITCUR
2309 | BufferView::CHANGE);
2310 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2311 moveCursorUpdate(false);
2315 case LFUN_PROTECTEDSPACE:
2317 LyXText * lt = bv_->getLyXText();
2318 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2320 if (style->free_spacing) {
2321 lt->insertChar(bv_, ' ');
2324 | BufferView::FITCUR
2325 | BufferView::CHANGE);
2327 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2329 moveCursorUpdate(false);
2335 LyXText * lt = bv_->getLyXText();
2337 if (lt->selection.mark()) {
2341 | BufferView::FITCUR);
2342 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2345 lt->selection.mark(true);
2348 | BufferView::FITCUR);
2349 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2351 lt->selection.cursor = lt->cursor;
2357 LyXText * lt = bv_->getLyXText();
2359 if (!lt->selection.set()) {
2361 lt->selection.cursor = lt->cursor;
2364 | BufferView::FITCUR
2365 | BufferView::CHANGE);
2366 // It is possible to make it a lot faster still
2367 // just comment out the line below...
2372 moveCursorUpdate(false);
2373 owner_->view_state_changed();
2378 case LFUN_DELETE_SKIP:
2380 LyXText * lt = bv_->getLyXText();
2382 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2384 LyXCursor cursor = lt->cursor;
2386 if (!lt->selection.set()) {
2387 if (cursor.pos() == cursor.par()->size()) {
2388 lt->cursorRight(bv_);
2389 cursor = lt->cursor;
2390 if (cursor.pos() == 0
2391 && !(cursor.par()->params().spaceTop()
2392 == VSpace (VSpace::NONE))) {
2395 cursor.par()->params().lineTop(),
2396 cursor.par()->params().lineBottom(),
2397 cursor.par()->params().pagebreakTop(),
2398 cursor.par()->params().pagebreakBottom(),
2399 VSpace(VSpace::NONE),
2400 cursor.par()->params().spaceBottom(),
2401 cursor.par()->params().spacing(),
2402 cursor.par()->params().align(),
2403 cursor.par()->params().labelWidthString(), 0);
2404 lt->cursorLeft(bv_);
2407 | BufferView::FITCUR
2408 | BufferView::CHANGE);
2410 lt->cursorLeft(bv_);
2412 lt->selection.cursor = lt->cursor;
2415 | BufferView::FITCUR
2416 | BufferView::CHANGE);
2420 lt->selection.cursor = lt->cursor;
2423 | BufferView::FITCUR
2424 | BufferView::CHANGE);
2432 /* -------> Delete word forward. */
2433 case LFUN_DELETE_WORD_FORWARD:
2434 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2435 bv_->getLyXText()->deleteWordForward(bv_);
2436 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2437 moveCursorUpdate(false);
2438 owner_->view_state_changed();
2441 /* -------> Delete word backward. */
2442 case LFUN_DELETE_WORD_BACKWARD:
2444 LyXText * lt = bv_->getLyXText();
2446 update(lt, BufferView::SELECT|BufferView::FITCUR);
2447 lt->deleteWordBackward(bv_);
2450 | BufferView::FITCUR
2451 | BufferView::CHANGE);
2452 moveCursorUpdate(false);
2453 owner_->view_state_changed();
2457 /* -------> Kill to end of line. */
2458 case LFUN_DELETE_LINE_FORWARD:
2460 LyXText * lt = bv_->getLyXText();
2462 update(lt, BufferView::SELECT|BufferView::FITCUR);
2463 lt->deleteLineForward(bv_);
2466 | BufferView::FITCUR
2467 | BufferView::CHANGE);
2468 moveCursorUpdate(false);
2472 /* -------> Set mark off. */
2475 LyXText * lt = bv_->getLyXText();
2478 update(lt, BufferView::SELECT|BufferView::FITCUR);
2479 lt->selection.cursor = lt->cursor;
2480 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2484 /* -------> Set mark on. */
2487 LyXText * lt = bv_->getLyXText();
2490 lt->selection.mark(true);
2491 update(lt, BufferView::SELECT|BufferView::FITCUR);
2492 lt->selection.cursor = lt->cursor;
2493 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2497 case LFUN_BACKSPACE:
2499 LyXText * lt = bv_->getLyXText();
2501 if (!lt->selection.set()) {
2502 if (owner_->getIntl()->getTransManager().backspace()) {
2504 lt->selection.cursor = lt->cursor;
2507 | BufferView::FITCUR
2508 | BufferView::CHANGE);
2509 // It is possible to make it a lot faster still
2510 // just comment out the line below...
2516 owner_->view_state_changed();
2521 case LFUN_BACKSPACE_SKIP:
2523 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2524 LyXText * lt = bv_->getLyXText();
2526 LyXCursor cursor = lt->cursor;
2528 if (!lt->selection.set()) {
2529 if (cursor.pos() == 0
2530 && !(cursor.par()->params().spaceTop()
2531 == VSpace (VSpace::NONE))) {
2534 cursor.par()->params().lineTop(),
2535 cursor.par()->params().lineBottom(),
2536 cursor.par()->params().pagebreakTop(),
2537 cursor.par()->params().pagebreakBottom(),
2538 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2539 cursor.par()->params().spacing(),
2540 cursor.par()->params().align(),
2541 cursor.par()->params().labelWidthString(), 0);
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2548 lt->selection.cursor = cursor;
2551 | BufferView::FITCUR
2552 | BufferView::CHANGE);
2559 case LFUN_BREAKPARAGRAPH:
2561 LyXText * lt = bv_->getLyXText();
2564 lt->breakParagraph(bv_, 0);
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2569 lt->selection.cursor = lt->cursor;
2571 owner_->view_state_changed();
2575 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2577 LyXText * lt = bv_->getLyXText();
2580 lt->breakParagraph(bv_, 1);
2583 | BufferView::FITCUR
2584 | BufferView::CHANGE);
2585 lt->selection.cursor = lt->cursor;
2587 owner_->view_state_changed();
2591 case LFUN_BREAKPARAGRAPH_SKIP:
2593 // When at the beginning of a paragraph, remove
2594 // indentation and add a "defskip" at the top.
2595 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2596 LyXText * lt = bv_->getLyXText();
2598 LyXCursor cursor = lt->cursor;
2601 if (cursor.pos() == 0) {
2602 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2605 cursor.par()->params().lineTop(),
2606 cursor.par()->params().lineBottom(),
2607 cursor.par()->params().pagebreakTop(),
2608 cursor.par()->params().pagebreakBottom(),
2609 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2610 cursor.par()->params().spacing(),
2611 cursor.par()->params().align(),
2612 cursor.par()->params().labelWidthString(), 1);
2613 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2617 lt->breakParagraph(bv_, 0);
2618 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2623 | BufferView::FITCUR
2624 | BufferView::CHANGE);
2625 lt->selection.cursor = cursor;
2627 owner_->view_state_changed();
2631 case LFUN_PARAGRAPH_SPACING:
2633 LyXText * lt = bv_->getLyXText();
2635 Paragraph * par = lt->cursor.par();
2636 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2637 float cur_value = 1.0;
2638 if (cur_spacing == Spacing::Other) {
2639 cur_value = par->params().spacing().getValue();
2642 istringstream istr(argument.c_str());
2646 Spacing::Space new_spacing = cur_spacing;
2647 float new_value = cur_value;
2649 lyxerr << "Missing argument to `paragraph-spacing'"
2651 } else if (tmp == "single") {
2652 new_spacing = Spacing::Single;
2653 } else if (tmp == "onehalf") {
2654 new_spacing = Spacing::Onehalf;
2655 } else if (tmp == "double") {
2656 new_spacing = Spacing::Double;
2657 } else if (tmp == "other") {
2658 new_spacing = Spacing::Other;
2661 lyxerr << "new_value = " << tmpval << endl;
2664 } else if (tmp == "default") {
2665 new_spacing = Spacing::Default;
2667 lyxerr << _("Unknown spacing argument: ")
2668 << argument << endl;
2670 if (cur_spacing != new_spacing || cur_value != new_value) {
2671 par->params().spacing(Spacing(new_spacing, new_value));
2672 lt->redoParagraph(bv_);
2675 | BufferView::FITCUR
2676 | BufferView::CHANGE);
2681 case LFUN_INSET_TOGGLE:
2683 LyXText * lt = bv_->getLyXText();
2686 update(lt, BufferView::SELECT|BufferView::FITCUR);
2687 lt->toggleInset(bv_);
2688 update(lt, BufferView::SELECT|BufferView::FITCUR);
2700 InsetCommandParams p;
2701 if (action == LFUN_HTMLURL)
2702 p.setCmdName("htmlurl");
2704 p.setCmdName("url");
2705 owner_->getDialogs()->createUrl(p.getAsString());
2709 case LFUN_INSERT_URL:
2711 InsetCommandParams p;
2712 p.setFromString(argument);
2714 InsetUrl * inset = new InsetUrl(p);
2715 if (!insertInset(inset))
2718 updateInset(inset, true);
2722 case LFUN_INSET_ERT:
2723 insertAndEditInset(new InsetERT(buffer_->params));
2726 case LFUN_INSET_EXTERNAL:
2727 insertAndEditInset(new InsetExternal);
2730 case LFUN_INSET_FOOTNOTE:
2731 insertAndEditInset(new InsetFoot(buffer_->params));
2734 case LFUN_INSET_MARGINAL:
2735 insertAndEditInset(new InsetMarginal(buffer_->params));
2738 case LFUN_INSET_MINIPAGE:
2739 insertAndEditInset(new InsetMinipage(buffer_->params));
2742 case LFUN_INSERT_NOTE:
2743 insertAndEditInset(new InsetNote(buffer_->params));
2746 case LFUN_INSET_FLOAT:
2747 // check if the float type exist
2748 if (floatList.typeExist(argument)) {
2749 insertAndEditInset(new InsetFloat(buffer_->params,
2752 lyxerr << "Non-existent float type: "
2753 << argument << endl;
2757 case LFUN_INSET_WIDE_FLOAT:
2758 // check if the float type exist
2759 if (floatList.typeExist(argument)) {
2760 InsetFloat * new_inset =
2761 new InsetFloat(buffer_->params, argument);
2762 new_inset->wide(true);
2763 insertAndEditInset(new_inset);
2765 lyxerr << "Non-existent float type: "
2766 << argument << endl;
2771 case LFUN_INSET_LIST:
2772 insertAndEditInset(new InsetList);
2775 case LFUN_INSET_THEOREM:
2776 insertAndEditInset(new InsetTheorem);
2780 case LFUN_INSET_CAPTION:
2782 // Do we have a locking inset...
2783 if (bv_->theLockingInset()) {
2784 lyxerr << "Locking inset code: "
2785 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2786 InsetCaption * new_inset =
2787 new InsetCaption(buffer_->params);
2788 new_inset->setOwner(bv_->theLockingInset());
2789 new_inset->setAutoBreakRows(true);
2790 new_inset->setDrawFrame(0, InsetText::LOCKED);
2791 new_inset->setFrameColor(0, LColor::captionframe);
2792 if (insertInset(new_inset))
2793 new_inset->edit(bv_);
2800 case LFUN_INSET_TABULAR:
2804 if (!argument.empty())
2805 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2806 InsetTabular * new_inset =
2807 new InsetTabular(*buffer_, r, c);
2809 bv_->getLyXText()->real_current_font.isRightToLeft();
2810 if (!open_new_inset(new_inset, rtl))
2815 // --- lyxserver commands ----------------------------
2817 case LFUN_CHARATCURSOR:
2819 pos_type pos = bv_->getLyXText()->cursor.pos();
2820 if (pos < bv_->getLyXText()->cursor.par()->size())
2821 owner_->getLyXFunc()->setMessage(
2822 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2824 owner_->getLyXFunc()->setMessage("EOF");
2829 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2831 + tostr(bv_->getLyXText()->cursor.y()));
2838 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2839 lyxerr << "SETXY: Could not parse coordinates in '"
2840 << argument << std::endl;
2842 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2846 case LFUN_GETLAYOUT:
2847 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2852 LyXFont & font = bv_->getLyXText()->current_font;
2853 if (font.shape() == LyXFont::ITALIC_SHAPE)
2854 owner_->getLyXFunc()->setMessage("E");
2855 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2856 owner_->getLyXFunc()->setMessage("N");
2858 owner_->getLyXFunc()->setMessage("0");
2863 // --- accented characters ---------------------------
2866 case LFUN_CIRCUMFLEX:
2876 case LFUN_SPECIAL_CARON:
2879 case LFUN_HUNG_UMLAUT:
2882 if (argument.empty()) {
2884 owner_->getLyXFunc()->handleKeyFunc(action);
2886 owner_->getLyXFunc()->handleKeyFunc(action);
2887 owner_->getIntl()->getTransManager()
2888 .TranslateAndInsert(argument[0], bv_->getLyXText());
2889 update(bv_->getLyXText(),
2891 | BufferView::FITCUR
2892 | BufferView::CHANGE);
2897 mathDispatch(bv_, argument);
2900 case LFUN_MATH_MACRO:
2901 mathDispatchMathMacro(bv_, argument);
2904 case LFUN_MATH_DELIM:
2905 mathDispatchMathDelim(bv_, argument);
2908 case LFUN_INSERT_MATRIX:
2909 mathDispatchInsertMatrix(bv_, argument);
2912 case LFUN_INSERT_MATH:
2913 mathDispatchInsertMath(bv_, argument);
2916 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2917 mathDispatchMathImportSelection(bv_, argument);
2920 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2921 mathDispatchMathDisplay(bv_, argument);
2924 case LFUN_MATH_MODE: // Open or create an inlined math inset
2925 mathDispatchMathMode(bv_, argument);
2928 case LFUN_GREEK: // Insert a single greek letter
2929 mathDispatchGreek(bv_, argument);
2932 case LFUN_CITATION_INSERT:
2934 InsetCommandParams p;
2935 p.setFromString(argument);
2937 InsetCitation * inset = new InsetCitation(p);
2938 if (!insertInset(inset))
2941 updateInset(inset, true);
2945 case LFUN_INSERT_BIBTEX:
2947 // ale970405+lasgoutt970425
2948 // The argument can be up to two tokens separated
2949 // by a space. The first one is the bibstyle.
2950 string const db = token(argument, ' ', 0);
2951 string const bibstyle = token(argument, ' ', 1);
2953 InsetCommandParams p("BibTeX", db, bibstyle);
2954 InsetBibtex * inset = new InsetBibtex(p);
2956 if (insertInset(inset)) {
2957 if (argument.empty())
2964 // BibTeX data bases
2965 case LFUN_BIBDB_ADD:
2967 InsetBibtex * inset =
2968 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2970 inset->addDatabase(argument);
2975 case LFUN_BIBDB_DEL:
2977 InsetBibtex * inset =
2978 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2980 inset->delDatabase(argument);
2985 case LFUN_BIBTEX_STYLE:
2987 InsetBibtex * inset =
2988 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2990 inset->setOptions(argument);
2995 case LFUN_INDEX_INSERT:
2997 string entry = argument;
2998 if (entry.empty()) {
2999 entry = bv_->getLyXText()->getStringToIndex(bv_);
3002 if (entry.empty()) {
3003 owner_->getDialogs()->createIndex();
3007 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3009 if (!insertInset(inset)) {
3012 updateInset(inset, true);
3017 case LFUN_INDEX_PRINT:
3019 InsetCommandParams p("printindex");
3020 Inset * inset = new InsetPrintIndex(p);
3021 if (!insertInset(inset, tclass.defaultLayoutName()))
3026 case LFUN_PARENTINSERT:
3028 InsetCommandParams p("lyxparent", argument);
3029 Inset * inset = new InsetParent(p, *buffer_);
3030 if (!insertInset(inset, tclass.defaultLayoutName()))
3036 case LFUN_CHILD_INSERT:
3038 InsetInclude::Params p;
3039 p.cparams.setFromString(argument);
3040 p.masterFilename_ = buffer_->fileName();
3042 InsetInclude * inset = new InsetInclude(p);
3043 if (!insertInset(inset))
3046 updateInset(inset, true);
3047 bv_->owner()->getDialogs()->showInclude(inset);
3052 case LFUN_FLOAT_LIST:
3053 if (floatList.typeExist(argument)) {
3054 Inset * inset = new InsetFloatList(argument);
3055 if (!insertInset(inset, tclass.defaultLayoutName()))
3058 lyxerr << "Non-existent float type: "
3059 << argument << endl;
3063 case LFUN_THESAURUS_ENTRY:
3065 string arg = argument;
3068 arg = bv_->getLyXText()->selectionAsString(buffer_,
3072 if (arg.size() > 100 || arg.empty()) {
3073 // Get word or selection
3074 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3075 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3076 // FIXME: where is getLyXText()->unselect(bv_) ?
3080 bv_->owner()->getDialogs()->showThesaurus(arg);
3084 case LFUN_SELFINSERT:
3086 if (argument.empty()) break;
3088 /* Automatically delete the currently selected
3089 * text and replace it with what is being
3090 * typed in now. Depends on lyxrc settings
3091 * "auto_region_delete", which defaults to
3094 LyXText * lt = bv_->getLyXText();
3096 if (lyxrc.auto_region_delete) {
3097 if (lt->selection.set()) {
3098 lt->cutSelection(bv_, false, false);
3101 | BufferView::FITCUR
3102 | BufferView::CHANGE);
3104 workarea().haveSelection(false);
3108 LyXFont const old_font(lt->real_current_font);
3110 string::const_iterator cit = argument.begin();
3111 string::const_iterator end = argument.end();
3112 for (; cit != end; ++cit) {
3113 owner_->getIntl()->getTransManager().
3114 TranslateAndInsert(*cit, lt);
3119 | BufferView::FITCUR
3120 | BufferView::CHANGE);
3122 lt->selection.cursor = lt->cursor;
3123 moveCursorUpdate(false);
3125 // real_current_font.number can change so we need to
3126 // update the minibuffer
3127 if (old_font != lt->real_current_font)
3128 owner_->view_state_changed();
3133 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3135 time_t now_time_t = time(NULL);
3136 struct tm * now_tm = localtime(&now_time_t);
3137 setlocale(LC_TIME, "");
3139 if (!argument.empty())
3142 arg = lyxrc.date_insert_format;
3144 int const datetmp_len =
3145 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3147 LyXText * lt = bv_->getLyXText();
3149 for (int i = 0; i < datetmp_len; i++) {
3150 lt->insertChar(bv_, datetmp[i]);
3153 | BufferView::FITCUR
3154 | BufferView::CHANGE);
3157 lt->selection.cursor = lt->cursor;
3158 moveCursorUpdate(false);
3162 case LFUN_UNKNOWN_ACTION:
3163 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3174 void BufferView::Pimpl::newline()
3177 LyXText * lt = bv_->getLyXText();
3181 | BufferView::FITCUR);
3182 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3185 | BufferView::FITCUR
3186 | BufferView::CHANGE);
3191 void BufferView::Pimpl::hfill()
3194 LyXText * lt = bv_->getLyXText();
3198 | BufferView::FITCUR);
3199 lt->insertChar(bv_, Paragraph::META_HFILL);
3202 | BufferView::FITCUR
3203 | BufferView::CHANGE);
3208 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3211 LyXText * lt = bv_->getLyXText();
3214 update(lt, BufferView::SELECT|BufferView::FITCUR);
3215 InsetSpecialChar * new_inset =
3216 new InsetSpecialChar(kind);
3217 if (!insertInset(new_inset))
3220 updateInset(new_inset, true);
3225 void BufferView::Pimpl::smartQuote()
3227 LyXText const * lt = bv_->getLyXText();
3228 Paragraph const * par = lt->cursor.par();
3229 pos_type pos = lt->cursor.pos();
3233 || (par->isInset(pos - 1)
3234 && par->getInset(pos - 1)->isSpace()))
3237 c = par->getChar(pos - 1);
3242 LyXLayout_ptr const & style = par->layout();
3244 if (style->pass_thru ||
3245 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3246 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, string("\""));
3250 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3253 if (insertInset(inset))
3258 bool gotsel = false;
3260 if (bv_->getLyXText()->selection.set()) {
3261 bv_->getLyXText()->cutSelection(bv_, true, false);
3265 if (insertInset(inset)) {
3268 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3276 // Open and lock an updatable inset
3277 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3279 LyXText * lt = bv_->getLyXText();
3283 if (!insertInset(new_inset)) {
3287 new_inset->edit(bv_, !behind);
3292 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3294 // if we are in a locking inset we should try to insert the
3295 // inset there otherwise this is a illegal function now
3296 if (bv_->theLockingInset()) {
3297 if (bv_->theLockingInset()->insetAllowed(inset))
3298 return bv_->theLockingInset()->insertInset(bv_, inset);
3302 // not quite sure if we want this...
3303 setCursorParUndo(bv_);
3306 beforeChange(bv_->text);
3307 if (!lout.empty()) {
3308 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3309 bv_->text->breakParagraph(bv_);
3310 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3312 if (bv_->text->cursor.par()->size()) {
3313 bv_->text->cursorLeft(bv_);
3315 bv_->text->breakParagraph(bv_);
3316 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3320 LyXTextClass const & tclass =
3321 buffer_->params.getLyXTextClass();
3322 bool hasLayout = tclass.hasLayout(lres);
3323 string lay = tclass.defaultLayoutName();
3325 if (hasLayout != false) {
3329 // layout not fount using default
3330 lay = tclass.defaultLayoutName();
3333 bv_->text->setLayout(bv_, lay);
3335 bv_->text->setParagraph(bv_, 0, 0,
3337 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3342 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 bv_->text->insertInset(bv_, inset);
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3355 if (!inset || !available())
3358 // first check for locking insets
3359 if (bv_->theLockingInset()) {
3360 if (bv_->theLockingInset() == inset) {
3361 if (bv_->text->updateInset(bv_, inset)) {
3364 buffer_->markDirty();
3369 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3370 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3373 buffer_->markDirty();
3381 // then check if the inset is a top_level inset (has no owner)
3382 // if yes do the update as always otherwise we have to update the
3383 // toplevel inset where this inset is inside
3384 Inset * tl_inset = inset;
3385 while(tl_inset->owner())
3386 tl_inset = tl_inset->owner();
3388 if (tl_inset == inset) {
3389 update(bv_->text, BufferView::UPDATE);
3390 if (bv_->text->updateInset(bv_, inset)) {
3394 | BufferView::FITCUR
3395 | BufferView::CHANGE);
3397 update(bv_->text, SELECT);
3401 } else if (static_cast<UpdatableInset *>(tl_inset)
3402 ->updateInsetInInset(bv_, inset))
3404 if (bv_->text->updateInset(bv_, tl_inset)) {
3412 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3415 if (!available()) return;
3418 beforeChange(bv_->text);
3419 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3421 LyXCursor const & cursor = bv_->text->cursor;
3425 cursor.par()->isInset(cursor.pos())) {
3426 Inset const * inset = cursor.par()->getInset(cursor.pos());
3427 if (find(codes.begin(), codes.end(), inset->lyxCode())
3430 static_cast<InsetCommand const *>(inset)->getContents();
3434 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3435 if (bv_->text->cursor.pos()
3436 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3437 LyXCursor tmp = bv_->text->cursor;
3438 bv_->text->cursor.par(bv_->text->ownerParagraph());
3439 bv_->text->cursor.pos(0);
3440 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3441 bv_->text->cursor = tmp;
3442 bv_->owner()->message(_("No more insets"));
3445 bv_->owner()->message(_("No more insets"));
3448 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3449 bv_->text->selection.cursor = bv_->text->cursor;
3453 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3455 gotoInset(vector<Inset::Code>(1, code), same_content);