2 * \file BufferView_pimpl.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
12 #pragma implementation
15 #include "BufferView_pimpl.h"
16 #include "frontends/WorkArea.h"
17 #include "frontends/screen.h"
18 #include "frontends/LyXScreenFactory.h"
19 #include "frontends/WorkAreaFactory.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/Alert.h"
22 #include "frontends/FileDialog.h"
25 #include "paragraph.h"
26 #include "frontends/LyXView.h"
27 #include "commandtags.h"
30 #include "bufferview_funcs.h"
31 #include "TextCache.h"
32 #include "bufferlist.h"
35 // added for Dispatch functions
38 #include "FloatList.h"
40 #include "ParagraphParameters.h"
41 #include "undo_funcs.h"
42 #include "lyxtextclasslist.h"
44 #include "insets/insetbib.h"
45 #include "insets/insettext.h"
46 #include "insets/inseturl.h"
47 #include "insets/insetlatexaccent.h"
48 #include "insets/insettoc.h"
49 #include "insets/insetref.h"
50 #include "insets/insetparent.h"
51 #include "insets/insetindex.h"
52 #include "insets/insetnote.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetert.h"
56 #include "insets/insetexternal.h"
57 #include "insets/insetgraphics.h"
58 #include "insets/insetfoot.h"
59 #include "insets/insetmarginal.h"
60 #include "insets/insetminipage.h"
61 #include "insets/insetfloat.h"
62 #include "insets/insettabular.h"
64 #include "insets/insettheorem.h"
65 #include "insets/insetlist.h"
67 #include "insets/insetcaption.h"
68 #include "insets/insetfloatlist.h"
69 #include "insets/insetspecialchar.h"
71 #include "mathed/formulabase.h"
73 #include "graphics/Previews.h"
75 #include "support/LAssert.h"
76 #include "support/lstrings.h"
77 #include "support/filetools.h"
78 #include "support/lyxfunctional.h"
80 #include <boost/bind.hpp>
89 extern string current_layout;
91 #ifndef CXX_GLOBAL_CSTD
104 using std::make_pair;
108 using lyx::textclass_type;
110 /* the selection possible is needed, that only motion events are
111 * used, where the bottom press event was on the drawing area too */
112 bool selection_possible = false;
114 extern BufferList bufferlist;
115 extern char ascii_type;
117 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
122 const unsigned int saved_positions_num = 20;
128 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
129 int xpos, int ypos, int width, int height)
130 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
131 using_xterm_cursor(false)
133 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
134 screen_.reset(LyXScreenFactory::create(workarea()));
137 workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
138 workarea().workAreaResize
139 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
140 workarea().workAreaButtonPress
141 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
142 workarea().workAreaButtonRelease
143 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
144 workarea().workAreaMotionNotify
145 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
146 workarea().workAreaDoubleClick
147 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
148 workarea().workAreaTripleClick
149 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
150 workarea().workAreaKeyPress
151 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
152 workarea().selectionRequested
153 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
154 workarea().selectionLost
155 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
157 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
158 cursor_timeout.start();
159 saved_positions.resize(saved_positions_num);
163 WorkArea & BufferView::Pimpl::workarea() const
165 return *workarea_.get();
169 LyXScreen & BufferView::Pimpl::screen() const
171 return *screen_.get();
175 Painter & BufferView::Pimpl::painter() const
177 return workarea().getPainter();
181 void BufferView::Pimpl::buffer(Buffer * b)
183 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
186 buffer_->delUser(bv_);
188 // Put the old text into the TextCache, but
189 // only if the buffer is still loaded.
190 // Also set the owner of the test to 0
191 // bv_->text->owner(0);
192 textcache.add(buffer_, workarea().workWidth(), bv_->text);
193 if (lyxerr.debugging())
194 textcache.show(lyxerr, "BufferView::buffer");
199 // Set current buffer
202 if (bufferlist.getState() == BufferList::CLOSING) return;
204 // If we are closing the buffer, use the first buffer as current
206 buffer_ = bufferlist.first();
210 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
211 buffer_->addUser(bv_);
213 // If we don't have a text object for this, we make one
214 if (bv_->text == 0) {
215 resizeCurrentBuffer();
218 // FIXME: needed when ?
219 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
221 // Similarly, buffer-dependent dialogs should be updated or
222 // hidden. This should go here because some dialogs (eg ToC)
223 // require bv_->text.
224 owner_->getDialogs()->updateBufferDependent(true);
226 lyxerr[Debug::INFO] << " No Buffer!" << endl;
227 owner_->getDialogs()->hideBufferDependent();
229 // Also remove all remaining text's from the testcache.
230 // (there should not be any!) (if there is any it is a
232 if (lyxerr.debugging())
233 textcache.show(lyxerr, "buffer delete all");
239 owner_->updateMenubar();
240 owner_->updateToolbar();
241 owner_->updateLayoutChoice();
242 owner_->updateWindowTitle();
244 if (grfx::Previews::activated() && buffer_)
245 grfx::Previews::get().generateBufferPreviews(*buffer_);
249 bool BufferView::Pimpl::fitCursor()
253 if (bv_->theLockingInset()) {
254 bv_->theLockingInset()->fitInsetCursor(bv_);
257 ret = screen().fitCursor(bv_->text, bv_);
260 bv_->owner()->getDialogs()->updateParagraph();
267 void BufferView::Pimpl::redoCurrentBuffer()
269 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
270 if (buffer_ && bv_->text) {
271 resizeCurrentBuffer();
272 owner_->updateLayoutChoice();
277 int BufferView::Pimpl::resizeCurrentBuffer()
279 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
282 Paragraph * selstartpar = 0;
283 Paragraph * selendpar = 0;
284 UpdatableInset * the_locking_inset = 0;
287 pos_type selstartpos = 0;
288 pos_type selendpos = 0;
289 bool selection = false;
290 bool mark_set = false;
292 owner_->prohibitInput();
294 owner_->message(_("Formatting document..."));
297 par = bv_->text->cursor.par();
298 pos = bv_->text->cursor.pos();
299 selstartpar = bv_->text->selection.start.par();
300 selstartpos = bv_->text->selection.start.pos();
301 selendpar = bv_->text->selection.end.par();
302 selendpos = bv_->text->selection.end.pos();
303 selection = bv_->text->selection.set();
304 mark_set = bv_->text->selection.mark();
305 the_locking_inset = bv_->theLockingInset();
306 buffer_->resizeInsets(bv_);
307 // I don't think the delete and new are necessary here we just could
308 // call only init! (Jug 20020419)
310 bv_->text = new LyXText(bv_);
311 bv_->text->init(bv_);
313 // See if we have a text in TextCache that fits
314 // the new buffer_ with the correct width.
315 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
317 if (lyxerr.debugging()) {
318 lyxerr << "Found a LyXText that fits:\n";
319 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
321 // Set the owner of the newly found text
322 // bv_->text->owner(bv_);
323 if (lyxerr.debugging())
324 textcache.show(lyxerr, "resizeCurrentBuffer");
326 bv_->text = new LyXText(bv_);
327 bv_->text->init(bv_);
328 //buffer_->resizeInsets(bv_);
333 bv_->text->selection.set(true);
334 // At this point just to avoid the Delete-Empty-Paragraph-
335 // Mechanism when setting the cursor.
336 bv_->text->selection.mark(mark_set);
338 bv_->text->setCursor(bv_, selstartpar, selstartpos);
339 bv_->text->selection.cursor = bv_->text->cursor;
340 bv_->text->setCursor(bv_, selendpar, selendpos);
341 bv_->text->setSelection(bv_);
342 bv_->text->setCursor(bv_, par, pos);
344 bv_->text->setCursor(bv_, par, pos);
345 bv_->text->selection.cursor = bv_->text->cursor;
346 bv_->text->selection.set(false);
348 // remake the inset locking
349 bv_->theLockingInset(the_locking_inset);
352 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
355 owner_->allowInput();
357 /// clear the "Formatting Document" message
364 void BufferView::Pimpl::repaint()
366 // Regenerate the screen.
367 screen().redraw(bv_->text, bv_);
371 void BufferView::Pimpl::updateScrollbar()
374 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
375 workarea().setScrollbarParams(0, 0, 0);
379 LyXText const & t = *bv_->text;
381 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
382 << t.first_y << ", default height " << t.defaultHeight() << endl;
384 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
388 void BufferView::Pimpl::scrollDocView(int value)
390 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
392 if (!buffer_) return;
394 screen().draw(bv_->text, bv_, value);
396 if (!lyxrc.cursor_follows_scrollbar) {
400 LyXText * vbt = bv_->text;
402 int const height = vbt->defaultHeight();
403 int const first = static_cast<int>((bv_->text->first_y + height));
404 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
406 if (vbt->cursor.y() < first)
407 vbt->setCursorFromCoordinates(bv_, 0, first);
408 else if (vbt->cursor.y() > last)
409 vbt->setCursorFromCoordinates(bv_, 0, last);
413 int BufferView::Pimpl::scroll(long time)
418 LyXText const * t = bv_->text;
420 double const diff = t->defaultHeight()
421 + double(time) * double(time) * 0.125;
423 scrollDocView(int(diff));
424 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
429 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
430 key_modifier::state state)
432 bv_->owner()->getLyXFunc()->processKeySym(key, state);
436 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
438 // Only use motion with button 1
439 if (!(state & mouse_button::button1))
445 // Check for inset locking
446 if (bv_->theLockingInset()) {
447 LyXCursor cursor = bv_->text->cursor;
448 LyXFont font = bv_->text->getFont(buffer_,
449 cursor.par(), cursor.pos());
450 int width = bv_->theLockingInset()->width(bv_, font);
451 int inset_x = font.isVisibleRightToLeft()
452 ? cursor.ix() - width : cursor.ix();
453 int start_x = inset_x + bv_->theLockingInset()->scroll();
455 bv_->theLockingInset()->
456 insetMotionNotify(bv_,
458 y - cursor.iy() + bv_->text->first_y,
463 /* The test for not selection possible is needed, that only motion
464 events are used, where the bottom press event was on
465 the drawing area too */
466 if (!selection_possible)
469 screen().hideCursor();
471 Row * cursorrow = bv_->text->cursor.row();
472 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
474 // sorry for this but I have a strange error that the y value jumps at
475 // a certain point. This seems like an error in my xforms library or
476 // in some other local environment, but I would like to leave this here
477 // for the moment until I can remove this (Jug 20020418)
478 if (y_before < bv_->text->cursor.y())
479 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
481 // This is to allow jumping over large insets
482 if (cursorrow == bv_->text->cursor.row()) {
483 if (y >= int(workarea().workHeight())) {
484 bv_->text->cursorDown(bv_, false);
486 bv_->text->cursorUp(bv_, false);
490 if (!bv_->text->selection.set())
491 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
493 bv_->text->setSelection(bv_);
494 screen().toggleToggle(bv_->text, bv_);
500 // Single-click on work area
501 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
502 mouse_button::state button)
507 // ok ok, this is a hack (for xforms)
508 if (button == mouse_button::button4) {
509 scroll(-lyxrc.wheel_jump);
510 // We shouldn't go further down as we really should only do the
511 // scrolling and be done with this. Otherwise we may open some
512 // dialogs (Jug 20020424).
514 } else if (button == mouse_button::button5) {
515 scroll(lyxrc.wheel_jump);
516 // We shouldn't go further down as we really should only do the
517 // scrolling and be done with this. Otherwise we may open some
518 // dialogs (Jug 20020424).
522 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
524 // Middle button press pastes if we have a selection
525 // We do this here as if the selection was inside an inset
526 // it could get cleared on the unlocking of the inset so
527 // we have to check this first
528 bool paste_internally = false;
529 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
530 owner_->getLyXFunc()->dispatch(LFUN_COPY);
531 paste_internally = true;
534 int const screen_first = bv_->text->first_y;
536 if (bv_->theLockingInset()) {
537 // We are in inset locking mode
539 /* Check whether the inset was hit. If not reset mode,
540 otherwise give the event to the inset */
541 if (inset_hit == bv_->theLockingInset()) {
542 bv_->theLockingInset()->
543 insetButtonPress(bv_, xpos, ypos, button);
546 bv_->unlockInset(bv_->theLockingInset());
551 selection_possible = true;
552 screen().hideCursor();
554 // Clear the selection
555 screen().toggleSelection(bv_->text, bv_);
556 bv_->text->clearSelection();
557 bv_->text->fullRebreak(bv_);
561 // Single left click in math inset?
562 if (isHighlyEditableInset(inset_hit)) {
563 // Highly editable inset, like math
564 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
565 selection_possible = false;
566 owner_->updateLayoutChoice();
567 owner_->message(inset->editMessage());
568 //inset->edit(bv_, xpos, ypos, button);
569 // We just have to lock the inset before calling a PressEvent on it!
570 // we don't need the edit() call here! (Jug20020329)
571 if (!bv_->lockInset(inset)) {
572 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
574 inset->insetButtonPress(bv_, xpos, ypos, button);
577 // I'm not sure we should continue here if we hit an inset (Jug20020403)
579 // Right click on a footnote flag opens float menu
580 if (button == mouse_button::button3) {
581 selection_possible = false;
585 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
586 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
588 bv_->text->selection.cursor = bv_->text->cursor;
589 bv_->text->cursor.x_fix(bv_->text->cursor.x());
591 owner_->updateLayoutChoice();
593 selection_possible = false;
596 // Insert primary selection with middle mouse
597 // if there is a local selection in the current buffer,
599 if (button == mouse_button::button2) {
600 if (paste_internally)
601 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
603 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
604 string("paragraph"));
605 selection_possible = false;
611 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
616 LyXText * text = bv_->getLyXText();
618 if (text->bv_owner && bv_->theLockingInset())
621 if (button == mouse_button::button1) {
622 if (text->bv_owner) {
623 screen().hideCursor();
624 screen().toggleSelection(text, bv_);
625 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
626 screen().toggleSelection(text, bv_, false);
628 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
630 /* This will fit the cursor on the screen
632 update(text, BufferView::SELECT|BufferView::FITCUR);
637 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
642 LyXText * text = bv_->getLyXText();
644 if (text->bv_owner && bv_->theLockingInset())
647 if (button == mouse_button::button1) {
648 if (text->bv_owner) {
649 screen().hideCursor();
650 screen().toggleSelection(text, bv_);
652 text->cursorHome(bv_);
653 text->selection.cursor = text->cursor;
654 text->cursorEnd(bv_);
655 text->setSelection(bv_);
656 if (text->bv_owner) {
657 screen().toggleSelection(text, bv_, false);
659 /* This will fit the cursor on the screen
661 update(text, BufferView::SELECT|BufferView::FITCUR);
666 void BufferView::Pimpl::selectionRequested()
673 LyXText * text = bv_->getLyXText();
675 if (text->selection.set() &&
676 (!bv_->text->xsel_cache.set() ||
677 text->selection.start != bv_->text->xsel_cache.start ||
678 text->selection.end != bv_->text->xsel_cache.end))
680 bv_->text->xsel_cache = text->selection;
681 sel = text->selectionAsString(bv_->buffer(), false);
682 } else if (!text->selection.set()) {
684 bv_->text->xsel_cache.set(false);
687 workarea().putClipboard(sel);
692 void BufferView::Pimpl::selectionLost()
697 bv_->getLyXText()->clearSelection();
699 bv_->text->xsel_cache.set(false);
704 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
705 mouse_button::state button)
707 // do nothing if we used the mouse wheel
708 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
711 // If we hit an inset, we have the inset coordinates in these
712 // and inset_hit points to the inset. If we do not hit an
713 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
714 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
716 if (bv_->theLockingInset()) {
717 // We are in inset locking mode.
719 /* LyX does a kind of work-area grabbing for insets.
720 Only a ButtonPress Event outside the inset will
721 force a insetUnlock. */
722 bv_->theLockingInset()->
723 insetButtonRelease(bv_, x, y, button);
727 selection_possible = false;
729 if (button == mouse_button::button2)
733 if (button == mouse_button::button1) {
734 workarea().haveSelection(bv_->getLyXText()->selection.set());
738 owner_->view_state_changed();
739 owner_->updateMenubar();
740 owner_->updateToolbar();
742 // Did we hit an editable inset?
744 selection_possible = false;
746 // if we reach this point with a selection, it
747 // must mean we are currently selecting.
748 // But we don't want to open the inset
749 // because that is annoying for the user.
750 // So just pretend we didn't hit it.
751 // this is OK because a "kosher" ButtonRelease
752 // will follow a ButtonPress that clears
754 // Note this also fixes selection drawing
755 // problems if we end up opening an inset
756 if (bv_->getLyXText()->selection.set())
759 // CHECK fix this proper in 0.13
760 // well, maybe 13.0 !!!!!!!!!
762 // Following a ref shouldn't issue
763 // a push on the undo-stack
764 // anylonger, now that we have
765 // keybindings for following
766 // references and returning from
767 // references. IMHO though, it
768 // should be the inset's own business
769 // to push or not push on the undo
770 // stack. They don't *have* to
771 // alter the document...
773 // ...or maybe the SetCursorParUndo()
774 // below isn't necessary at all anylonger?
775 if (inset_hit->lyxCode() == Inset::REF_CODE) {
776 setCursorParUndo(bv_);
779 owner_->message(inset_hit->editMessage());
781 if (isHighlyEditableInset(inset_hit)) {
782 // Highly editable inset, like math
783 UpdatableInset *inset = (UpdatableInset *)inset_hit;
784 inset->insetButtonRelease(bv_, x, y, button);
786 inset_hit->insetButtonRelease(bv_, x, y, button);
787 // IMO this is a grosshack! Inset's should be changed so that
788 // they call the actions they have to do with the insetButtonRel.
789 // function and not in the edit(). This should be changed
791 inset_hit->edit(bv_, x, y, button);
796 // Maybe we want to edit a bibitem ale970302
797 if (bv_->text->cursor.par()->bibkey && x < 20 +
798 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
799 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
806 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
807 LyXCursor const & cursor) const
809 Paragraph /*const*/ & par = *cursor.par();
810 pos_type const pos = cursor.pos();
812 lyx::Assert(par.getInset(pos));
814 Inset const & inset(*par.getInset(pos));
816 LyXFont const & font = text.getFont(buffer_, &par, pos);
818 int const width = inset.width(bv_, font);
819 int const inset_x = font.isVisibleRightToLeft()
820 ? (cursor.ix() - width) : cursor.ix();
823 inset_x + inset.scroll(),
825 cursor.iy() - inset.ascent(bv_, font),
826 cursor.iy() + inset.descent(bv_, font));
830 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
831 LyXCursor const & cursor,
832 int & x, int & y) const
834 pos_type const pos(cursor.pos());
835 Paragraph /*const*/ & par(*cursor.par());
837 if (pos >= par.size() || !par.isInset(pos)) {
841 Inset /*const*/ * inset = par.getInset(pos);
843 if (!isEditableInset(inset)) {
847 Box b(insetDimensions(text, cursor));
849 if (!b.contained(x, y)) {
850 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
851 << " box " << b << endl;
855 text.setCursor(bv_, &par, pos, true);
858 // The origin of an inset is on the baseline
859 y -= text.cursor.iy();
865 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
867 int y_tmp = y + text->first_y;
870 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
872 Inset * inset(checkInset(*text, cursor, x, y_tmp));
879 // look at previous position
881 if (cursor.pos() == 0) {
886 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
888 inset = checkInset(*text, cursor, x, y_tmp);
896 void BufferView::Pimpl::workAreaResize()
898 static int work_area_width;
899 static int work_area_height;
901 bool const widthChange = workarea().workWidth() != work_area_width;
902 bool const heightChange = workarea().workHeight() != work_area_height;
904 // update from work area
905 work_area_width = workarea().workWidth();
906 work_area_height = workarea().workHeight();
910 // The visible LyXView need a resize
911 resizeCurrentBuffer();
913 // Remove all texts from the textcache
914 // This is not _really_ what we want to do. What
915 // we really want to do is to delete in textcache
916 // that does not have a BufferView with matching
917 // width, but as long as we have only one BufferView
918 // deleting all gives the same result.
919 if (lyxerr.debugging())
920 textcache.show(lyxerr, "Expose delete all");
922 // FIXME: this is aalready done in resizeCurrentBuffer() ??
923 buffer_->resizeInsets(bv_);
924 } else if (heightChange) {
925 // fitCursor() ensures we don't jump back
926 // to the start of the document on vertical
932 if (widthChange || heightChange) {
936 // always make sure that the scrollbar is sane.
938 owner_->updateLayoutChoice();
943 void BufferView::Pimpl::update()
945 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
946 LyXText::text_status st = bv_->text->status();
947 screen().update(bv_->text, bv_);
949 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
950 bv_->text->fullRebreak(bv_);
951 st = LyXText::NEED_MORE_REFRESH;
952 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
953 bv_->text->cursor.pos());
954 if (bv_->text->selection.set()) {
955 bv_->text->setCursor(bv_, bv_->text->selection.start,
956 bv_->text->selection.start.par(),
957 bv_->text->selection.start.pos());
958 bv_->text->setCursor(bv_, bv_->text->selection.end,
959 bv_->text->selection.end.par(),
960 bv_->text->selection.end.pos());
963 bv_->text->status(bv_, st);
964 screen().update(bv_->text, bv_);
966 // do this here instead of in the screen::update because of
968 bv_->text->status(bv_, LyXText::UNCHANGED);
974 // Values used when calling update:
976 // -2 - update, move sel_cursor if selection, fitcursor
977 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
978 // 0 - update, move sel_cursor if selection, fitcursor
979 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
980 // 3 - update, move sel_cursor if selection
983 // a simple redraw of the parts that need refresh
985 // move sel_cursor if selection -
986 // the text's sel_cursor is moved if there is selection is progress
989 // fitCursor() is called and the scrollbar updated
992 // the buffer is marked dirty.
1001 // UPDATE_ONLY = UPDATE;
1002 // UPDATE_SELECT = UPDATE | SELECT;
1003 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1004 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1006 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1007 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1008 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1009 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1010 // update(3) -> update(1) -> update(1) -> update(SELECT)
1012 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1014 owner_->updateLayoutChoice();
1016 if (!text->selection.set() && (f & SELECT)) {
1017 text->selection.cursor = text->cursor;
1020 text->fullRebreak(bv_);
1022 if (text->inset_owner) {
1023 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1024 updateInset(text->inset_owner, false);
1034 buffer_->markDirty();
1039 // Callback for cursor timer
1040 void BufferView::Pimpl::cursorToggle()
1043 cursor_timeout.restart();
1048 extern void reapSpellchecker(void);
1051 if (!bv_->theLockingInset()) {
1052 screen().cursorToggle(bv_);
1054 bv_->theLockingInset()->toggleInsetCursor(bv_);
1057 cursor_timeout.restart();
1061 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1063 if (!text->cursor.row()->previous()) {
1064 if (text->first_y > 0) {
1065 int new_y = bv_->text->first_y - workarea().workHeight();
1066 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1072 int y = text->first_y;
1073 Row * cursorrow = text->cursor.row();
1075 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1079 if (cursorrow == bv_->text->cursor.row()) {
1080 // we have a row which is higher than the workarea so we leave the
1081 // cursor on the start of the row and move only the draw up as soon
1082 // as we move the cursor or do something while inside the row (it may
1083 // span several workarea-heights) we'll move to the top again, but this
1084 // is better than just jump down and only display part of the row.
1085 new_y = bv_->text->first_y - workarea().workHeight();
1087 if (text->inset_owner) {
1088 new_y = bv_->text->cursor.iy()
1089 + bv_->theLockingInset()->insetInInsetY() + y
1090 + text->cursor.row()->height()
1091 - workarea().workHeight() + 1;
1093 new_y = text->cursor.y()
1094 - text->cursor.row()->baseline()
1095 + text->cursor.row()->height()
1096 - workarea().workHeight() + 1;
1099 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1100 if (text->cursor.row()->previous()) {
1102 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1103 text->cursor.row()->previous()->pos(), false);
1104 if (cur.y() > text->first_y) {
1105 text->cursorUp(bv_, true);
1112 void BufferView::Pimpl::cursorNext(LyXText * text)
1114 if (!text->cursor.row()->next()) {
1115 int y = text->cursor.y() - text->cursor.row()->baseline() +
1116 text->cursor.row()->height();
1117 if (y > int(text->first_y + workarea().workHeight())) {
1118 screen().draw(bv_->text, bv_,
1119 bv_->text->first_y + workarea().workHeight());
1125 int y = text->first_y + workarea().workHeight();
1126 if (text->inset_owner && !text->first_y) {
1127 y -= (bv_->text->cursor.iy()
1128 - bv_->text->first_y
1129 + bv_->theLockingInset()->insetInInsetY());
1132 text->getRowNearY(y);
1134 Row * cursorrow = text->cursor.row();
1135 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1139 if (cursorrow == bv_->text->cursor.row()) {
1140 // we have a row which is higher than the workarea so we leave the
1141 // cursor on the start of the row and move only the draw down as soon
1142 // as we move the cursor or do something while inside the row (it may
1143 // span several workarea-heights) we'll move to the top again, but this
1144 // is better than just jump down and only display part of the row.
1145 new_y = bv_->text->first_y + workarea().workHeight();
1147 if (text->inset_owner) {
1148 new_y = bv_->text->cursor.iy()
1149 + bv_->theLockingInset()->insetInInsetY()
1150 + y - text->cursor.row()->baseline();
1152 new_y = text->cursor.y() - text->cursor.row()->baseline();
1155 screen().draw(bv_->text, bv_, new_y);
1156 if (text->cursor.row()->next()) {
1158 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1159 text->cursor.row()->next()->pos(), false);
1160 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1161 text->cursorDown(bv_, true);
1168 bool BufferView::Pimpl::available() const
1170 if (buffer_ && bv_->text)
1176 void BufferView::Pimpl::beforeChange(LyXText * text)
1179 text->clearSelection();
1183 void BufferView::Pimpl::savePosition(unsigned int i)
1185 if (i >= saved_positions_num)
1187 saved_positions[i] = Position(buffer_->fileName(),
1188 bv_->text->cursor.par()->id(),
1189 bv_->text->cursor.pos());
1192 str << _("Saved bookmark") << ' ' << i;
1193 owner_->message(str.str().c_str());
1198 void BufferView::Pimpl::restorePosition(unsigned int i)
1200 if (i >= saved_positions_num)
1203 string const fname = saved_positions[i].filename;
1205 beforeChange(bv_->text);
1207 if (fname != buffer_->fileName()) {
1208 Buffer * b = bufferlist.exists(fname) ?
1209 bufferlist.getBuffer(fname) :
1210 bufferlist.loadLyXFile(fname); // don't ask, just load it
1211 if (b != 0) buffer(b);
1214 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1218 bv_->text->setCursor(bv_, par,
1219 min(par->size(), saved_positions[i].par_pos));
1221 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1224 str << _("Moved to bookmark") << ' ' << i;
1225 owner_->message(str.str().c_str());
1230 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1232 if (i >= saved_positions_num)
1235 return !saved_positions[i].filename.empty();
1239 void BufferView::Pimpl::switchKeyMap()
1241 if (!lyxrc.rtl_support)
1244 LyXText * text = bv_->getLyXText();
1245 if (text->real_current_font.isRightToLeft()
1246 && !(bv_->theLockingInset()
1247 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1249 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1250 owner_->getIntl()->KeyMapSec();
1252 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1253 owner_->getIntl()->KeyMapPrim();
1258 void BufferView::Pimpl::insetUnlock()
1260 if (bv_->theLockingInset()) {
1261 bv_->theLockingInset()->insetUnlock(bv_);
1262 bv_->theLockingInset(0);
1268 void BufferView::Pimpl::showCursor()
1270 if (bv_->theLockingInset())
1271 bv_->theLockingInset()->showInsetCursor(bv_);
1273 screen().showCursor(bv_->text, bv_);
1277 void BufferView::Pimpl::hideCursor()
1279 if (!bv_->theLockingInset())
1280 screen().hideCursor();
1284 void BufferView::Pimpl::toggleSelection(bool b)
1286 if (bv_->theLockingInset())
1287 bv_->theLockingInset()->toggleSelection(bv_, b);
1288 screen().toggleSelection(bv_->text, bv_, b);
1292 void BufferView::Pimpl::toggleToggle()
1294 screen().toggleToggle(bv_->text, bv_);
1298 void BufferView::Pimpl::center()
1300 LyXText * t = bv_->text;
1303 int const half_height = workarea().workHeight() / 2;
1306 if (t->cursor.y() > half_height) {
1307 new_y = t->cursor.y() - half_height;
1310 // FIXME: can we do this w/o calling screen directly ?
1311 // This updates first_y but means the fitCursor() call
1312 // from the update(FITCUR) doesn't realise that we might
1313 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1314 // the scrollbar to be updated as it should, so we have
1315 // to do it manually. Any operation that does a center()
1316 // and also might have moved first_y must make sure to call
1317 // updateScrollbar() currently. Never mind that this is a
1318 // pretty obfuscated way of updating t->first_y
1319 screen().draw(t, bv_, new_y);
1321 update(t, BufferView::SELECT | BufferView::FITCUR);
1325 void BufferView::Pimpl::pasteClipboard(bool asPara)
1330 screen().hideCursor();
1331 beforeChange(bv_->text);
1333 string const clip(workarea().getClipboard());
1339 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1341 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1343 bv_->getLyXText()->clearSelection();
1344 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1348 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1350 workarea().putClipboard(stuff);
1355 * Dispatch functions for actions which can be valid for BufferView->text
1356 * and/or InsetText->text!!!
1361 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1363 LyXText * lt = bv_->getLyXText();
1365 if (selecting || lt->selection.mark()) {
1366 lt->setSelection(bv_);
1370 updateInset(lt->inset_owner, false);
1374 update(lt, BufferView::SELECT|BufferView::FITCUR);
1376 update(lt, BufferView::SELECT);
1378 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1379 bv_->theLockingInset()->hideInsetCursor(bv_);
1380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1384 if (!lt->selection.set())
1385 workarea().haveSelection(false);
1391 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1393 LyXCursor cursor = bv_->getLyXText()->cursor;
1394 Buffer::inset_iterator it =
1395 find_if(Buffer::inset_iterator(
1396 cursor.par(), cursor.pos()),
1397 buffer_->inset_iterator_end(),
1398 lyx::compare_memfun(&Inset::lyxCode, code));
1399 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1403 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1405 string filename = filen;
1407 if (filename.empty()) {
1408 // Launch a file browser
1409 string initpath = lyxrc.document_path;
1412 string const trypath = owner_->buffer()->filePath();
1413 // If directory is writeable, use this as default.
1414 if (IsDirWriteable(trypath))
1418 FileDialog fileDlg(bv_->owner(),
1419 _("Select LyX document to insert"),
1421 make_pair(string(_("Documents|#o#O")),
1422 string(lyxrc.document_path)),
1423 make_pair(string(_("Examples|#E#e")),
1424 string(AddPath(system_lyxdir, "examples"))));
1426 FileDialog::Result result =
1427 fileDlg.Select(initpath,
1428 _("*.lyx| LyX Documents (*.lyx)"));
1430 if (result.first == FileDialog::Later)
1433 filename = result.second;
1435 // check selected filename
1436 if (filename.empty()) {
1437 owner_->message(_("Canceled."));
1442 // get absolute path of file and add ".lyx" to the filename if
1444 filename = FileSearch(string(), filename, "lyx");
1446 string const disp_fn(MakeDisplayPath(filename));
1449 s1 << _("Inserting document") << ' '
1450 << disp_fn << " ...";
1451 owner_->message(s1.str().c_str());
1452 bool const res = bv_->insertLyXFile(filename);
1455 str << _("Document") << ' ' << disp_fn
1456 << ' ' << _("inserted.");
1457 owner_->message(str.str().c_str());
1460 str << _("Could not insert document") << ' '
1462 owner_->message(str.str().c_str());
1467 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1469 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1470 << action <<"] arg[" << argument << "]" << endl;
1472 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1475 // --- Misc -------------------------------------------
1479 LyXText * lt = bv_->getLyXText();
1480 lt->toggleAppendix(bv_);
1483 | BufferView::FITCUR
1484 | BufferView::CHANGE);
1489 case LFUN_TOC_INSERT:
1491 InsetCommandParams p;
1492 p.setCmdName("tableofcontents");
1493 Inset * inset = new InsetTOC(p);
1494 if (!insertInset(inset, tclass.defaultLayoutName()))
1499 case LFUN_SCROLL_INSET:
1500 // this is not handled here as this funktion is only aktive
1501 // if we have a locking_inset and that one is (or contains)
1505 case LFUN_INSET_GRAPHICS:
1507 Inset * new_inset = new InsetGraphics;
1508 if (!insertInset(new_inset)) {
1511 // this is need because you don't use a inset->Edit()
1512 updateInset(new_inset, true);
1513 new_inset->edit(bv_);
1523 case LFUN_PASTESELECTION:
1525 bool asPara = false;
1526 if (argument == "paragraph")
1528 pasteClipboard(asPara);
1540 case LFUN_LAYOUT_COPY:
1541 bv_->copyEnvironment();
1544 case LFUN_LAYOUT_PASTE:
1545 bv_->pasteEnvironment();
1549 case LFUN_GOTOERROR:
1550 gotoInset(Inset::ERROR_CODE, false);
1554 gotoInset(Inset::IGNORE_CODE, false);
1557 case LFUN_REFERENCE_GOTO:
1559 vector<Inset::Code> tmp;
1560 tmp.push_back(Inset::LABEL_CODE);
1561 tmp.push_back(Inset::REF_CODE);
1562 gotoInset(tmp, true);
1566 case LFUN_HYPHENATION:
1567 specialChar(InsetSpecialChar::HYPHENATION);
1570 case LFUN_LIGATURE_BREAK:
1571 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1575 specialChar(InsetSpecialChar::LDOTS);
1578 case LFUN_END_OF_SENTENCE:
1579 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1582 case LFUN_MENU_SEPARATOR:
1583 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1590 case LFUN_DEPTH_MIN:
1591 changeDepth(bv_, bv_->getLyXText(), -1);
1594 case LFUN_DEPTH_PLUS:
1595 changeDepth(bv_, bv_->getLyXText(), 1);
1599 owner_->getDialogs()->setUserFreeFont();
1602 case LFUN_FILE_INSERT:
1603 MenuInsertLyXFile(argument);
1606 case LFUN_FILE_INSERT_ASCII_PARA:
1607 InsertAsciiFile(bv_, argument, true);
1610 case LFUN_FILE_INSERT_ASCII:
1611 InsertAsciiFile(bv_, argument, false);
1616 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1617 << argument << endl;
1619 // This is not the good solution to the empty argument
1620 // problem, but it will hopefully suffice for 1.2.0.
1621 // The correct solution would be to augument the
1622 // function list/array with information about what
1623 // functions needs arguments and their type.
1624 if (argument.empty()) {
1625 owner_->getLyXFunc()->setErrorMessage(
1626 _("LyX function 'layout' needs an argument."));
1630 // Derive layout number from given argument (string)
1631 // and current buffer's textclass (number). */
1632 bool hasLayout = tclass.hasLayout(argument);
1633 string layout = argument;
1635 // If the entry is obsolete, use the new one instead.
1637 string const & obs = tclass[layout]->obsoleted_by();
1643 owner_->getLyXFunc()->setErrorMessage(
1644 string(N_("Layout ")) + argument +
1649 bool change_layout = (current_layout != layout);
1650 LyXText * lt = bv_->getLyXText();
1651 if (!change_layout && lt->selection.set() &&
1652 lt->selection.start.par() != lt->selection.end.par())
1654 Paragraph * spar = lt->selection.start.par();
1655 Paragraph * epar = lt->selection.end.par()->next();
1656 while(spar != epar) {
1657 if (spar->layout()->name() != current_layout) {
1658 change_layout = true;
1663 if (change_layout) {
1665 current_layout = layout;
1668 | BufferView::FITCUR);
1669 lt->setLayout(bv_, layout);
1670 owner_->setLayout(layout);
1673 | BufferView::FITCUR
1674 | BufferView::CHANGE);
1681 lang(bv_, argument);
1683 owner_->view_state_changed();
1688 owner_->view_state_changed();
1693 owner_->view_state_changed();
1698 owner_->view_state_changed();
1703 owner_->view_state_changed();
1708 owner_->view_state_changed();
1713 owner_->view_state_changed();
1718 owner_->view_state_changed();
1721 case LFUN_UNDERLINE:
1723 owner_->view_state_changed();
1726 case LFUN_FONT_SIZE:
1727 fontSize(bv_, argument);
1728 owner_->view_state_changed();
1731 case LFUN_FONT_STATE:
1732 owner_->getLyXFunc()->setMessage(currentState(bv_));
1735 case LFUN_UPCASE_WORD:
1737 LyXText * lt = bv_->getLyXText();
1741 | BufferView::FITCUR);
1742 lt->changeCase(bv_, LyXText::text_uppercase);
1743 if (lt->inset_owner)
1744 updateInset(lt->inset_owner, true);
1747 | BufferView::FITCUR
1748 | BufferView::CHANGE);
1752 case LFUN_LOWCASE_WORD:
1754 LyXText * lt = bv_->getLyXText();
1756 update(lt, BufferView::SELECT|BufferView::FITCUR);
1757 lt->changeCase(bv_, LyXText::text_lowercase);
1758 if (lt->inset_owner)
1759 updateInset(lt->inset_owner, true);
1762 | BufferView::FITCUR
1763 | BufferView::CHANGE);
1767 case LFUN_CAPITALIZE_WORD:
1769 LyXText * lt = bv_->getLyXText();
1771 update(lt, BufferView::SELECT|BufferView::FITCUR);
1772 lt->changeCase(bv_, LyXText::text_capitalization);
1773 if (lt->inset_owner)
1774 updateInset(lt->inset_owner, true);
1777 | BufferView::FITCUR
1778 | BufferView::CHANGE);
1782 case LFUN_TRANSPOSE_CHARS:
1784 LyXText * lt = bv_->getLyXText();
1786 update(lt, BufferView::SELECT|BufferView::FITCUR);
1787 lt->transposeChars(*bv_);
1788 if (lt->inset_owner)
1789 updateInset(lt->inset_owner, true);
1792 | BufferView::FITCUR
1793 | BufferView::CHANGE);
1798 case LFUN_INSERT_LABEL:
1799 MenuInsertLabel(bv_, argument);
1802 case LFUN_REF_INSERT:
1803 if (argument.empty()) {
1804 InsetCommandParams p("ref");
1805 owner_->getDialogs()->createRef(p.getAsString());
1807 InsetCommandParams p;
1808 p.setFromString(argument);
1810 InsetRef * inset = new InsetRef(p, *buffer_);
1811 if (!insertInset(inset))
1814 updateInset(inset, true);
1818 case LFUN_BOOKMARK_SAVE:
1819 savePosition(strToUnsignedInt(argument));
1822 case LFUN_BOOKMARK_GOTO:
1823 restorePosition(strToUnsignedInt(argument));
1828 string label(argument);
1829 if (label.empty()) {
1831 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1833 label = inset->getContents();
1838 if (!label.empty()) {
1839 //bv_->savePosition(0);
1840 if (!bv_->gotoLabel(label))
1841 Alert::alert(_("Error"),
1842 _("Couldn't find this label"),
1843 _("in current document."));
1848 // --- Cursor Movements -----------------------------
1851 LyXText * lt = bv_->getLyXText();
1853 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1854 if (!lt->selection.mark())
1856 update(lt, BufferView::SELECT|BufferView::FITCUR);
1858 lt->cursorLeft(bv_, false);
1859 if (lt->cursor.pos() < lt->cursor.par()->size()
1860 && lt->cursor.par()->isInset(lt->cursor.pos())
1861 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1862 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1863 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1865 tmpinset->edit(bv_, false);
1867 tmpinset->edit(bv_);
1871 lt->cursorRight(bv_, false);
1873 moveCursorUpdate(false);
1874 owner_->view_state_changed();
1880 // This is soooo ugly. Isn`t it possible to make
1881 // it simpler? (Lgb)
1882 LyXText * lt = bv_->getLyXText();
1883 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1884 if (!lt->selection.mark())
1886 update(lt, BufferView::SELECT|BufferView::FITCUR);
1887 LyXCursor const cur = lt->cursor;
1889 lt->cursorLeft(bv_, false);
1890 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1891 lt->cursor.pos() < lt->cursor.par()->size() &&
1892 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1893 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1894 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1895 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1897 tmpinset->edit(bv_);
1899 tmpinset->edit(bv_, false);
1903 lt->cursorRight(bv_, false);
1906 moveCursorUpdate(false);
1907 owner_->view_state_changed();
1913 LyXText * lt = bv_->getLyXText();
1915 if (!lt->selection.mark())
1917 update(lt, BufferView::UPDATE);
1920 moveCursorUpdate(false);
1921 owner_->view_state_changed();
1927 LyXText * lt = bv_->getLyXText();
1929 if (!lt->selection.mark())
1931 update(lt, BufferView::UPDATE);
1932 lt->cursorDown(bv_);
1934 moveCursorUpdate(false);
1935 owner_->view_state_changed();
1939 case LFUN_UP_PARAGRAPH:
1941 LyXText * lt = bv_->getLyXText();
1943 if (!lt->selection.mark())
1945 update(lt, BufferView::UPDATE);
1946 lt->cursorUpParagraph(bv_);
1948 moveCursorUpdate(false);
1949 owner_->view_state_changed();
1953 case LFUN_DOWN_PARAGRAPH:
1955 LyXText * lt = bv_->getLyXText();
1957 if (!lt->selection.mark())
1959 update(lt, BufferView::UPDATE);
1960 lt->cursorDownParagraph(bv_);
1962 moveCursorUpdate(false);
1963 owner_->view_state_changed();
1969 LyXText * lt = bv_->getLyXText();
1971 if (!lt->selection.mark())
1973 update(lt, BufferView::UPDATE);
1976 moveCursorUpdate(false, false);
1977 owner_->view_state_changed();
1983 LyXText * lt = bv_->getLyXText();
1985 if (!lt->selection.mark())
1987 update(lt, BufferView::UPDATE);
1990 moveCursorUpdate(false, false);
1991 owner_->view_state_changed();
1997 LyXText * lt = bv_->getLyXText();
1999 if (!lt->selection.mark())
2001 update(lt, BufferView::SELECT|BufferView::FITCUR);
2002 lt->cursorHome(bv_);
2004 moveCursorUpdate(false);
2005 owner_->view_state_changed();
2011 LyXText * lt = bv_->getLyXText();
2013 if (!lt->selection.mark())
2016 BufferView::SELECT|BufferView::FITCUR);
2019 moveCursorUpdate(false);
2020 owner_->view_state_changed();
2024 case LFUN_SHIFT_TAB:
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2032 BufferView::SELECT|BufferView::FITCUR);
2035 moveCursorUpdate(false);
2036 owner_->view_state_changed();
2040 case LFUN_WORDRIGHT:
2042 LyXText * lt = bv_->getLyXText();
2044 if (!lt->selection.mark())
2046 update(lt, BufferView::SELECT|BufferView::FITCUR);
2047 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2048 lt->cursorLeftOneWord(bv_);
2050 lt->cursorRightOneWord(bv_);
2052 moveCursorUpdate(false);
2053 owner_->view_state_changed();
2059 LyXText * lt = bv_->getLyXText();
2061 if (!lt->selection.mark())
2063 update(lt, BufferView::SELECT|BufferView::FITCUR);
2064 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2065 lt->cursorRightOneWord(bv_);
2067 lt->cursorLeftOneWord(bv_);
2069 moveCursorUpdate(false);
2070 owner_->view_state_changed();
2074 case LFUN_BEGINNINGBUF:
2076 LyXText * lt = bv_->getLyXText();
2078 if (!lt->selection.mark())
2081 BufferView::SELECT|BufferView::FITCUR);
2084 moveCursorUpdate(false);
2085 owner_->view_state_changed();
2091 LyXText * lt = bv_->getLyXText();
2093 if (!lt->selection.mark())
2096 BufferView::SELECT|BufferView::FITCUR);
2097 lt->cursorBottom(bv_);
2099 moveCursorUpdate(false);
2100 owner_->view_state_changed();
2104 /* cursor selection ---------------------------- */
2107 LyXText * lt = bv_->getLyXText();
2110 BufferView::SELECT|BufferView::FITCUR);
2111 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2112 lt->cursorLeft(bv_);
2114 lt->cursorRight(bv_);
2116 moveCursorUpdate(true);
2117 owner_->view_state_changed();
2123 LyXText * lt = bv_->getLyXText();
2126 BufferView::SELECT|BufferView::FITCUR);
2127 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2128 lt->cursorRight(bv_);
2130 lt->cursorLeft(bv_);
2132 moveCursorUpdate(true);
2133 owner_->view_state_changed();
2139 LyXText * lt = bv_->getLyXText();
2142 BufferView::SELECT|BufferView::FITCUR);
2143 lt->cursorUp(bv_, true);
2145 moveCursorUpdate(true);
2146 owner_->view_state_changed();
2152 LyXText * lt = bv_->getLyXText();
2155 BufferView::SELECT|BufferView::FITCUR);
2156 lt->cursorDown(bv_, true);
2158 moveCursorUpdate(true);
2159 owner_->view_state_changed();
2163 case LFUN_UP_PARAGRAPHSEL:
2165 LyXText * lt = bv_->getLyXText();
2168 BufferView::SELECT|BufferView::FITCUR);
2169 lt->cursorUpParagraph(bv_);
2171 moveCursorUpdate(true);
2172 owner_->view_state_changed();
2176 case LFUN_DOWN_PARAGRAPHSEL:
2178 LyXText * lt = bv_->getLyXText();
2181 BufferView::SELECT|BufferView::FITCUR);
2182 lt->cursorDownParagraph(bv_);
2184 moveCursorUpdate(true);
2185 owner_->view_state_changed();
2191 LyXText * lt = bv_->getLyXText();
2193 update(lt, BufferView::SELECT|BufferView::FITCUR);
2196 moveCursorUpdate(true);
2197 owner_->view_state_changed();
2203 LyXText * lt = bv_->getLyXText();
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2208 moveCursorUpdate(true);
2209 owner_->view_state_changed();
2215 LyXText * lt = bv_->getLyXText();
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2218 lt->cursorHome(bv_);
2220 moveCursorUpdate(true);
2221 owner_->view_state_changed();
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2232 moveCursorUpdate(true);
2233 owner_->view_state_changed();
2237 case LFUN_WORDRIGHTSEL:
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2242 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2243 lt->cursorLeftOneWord(bv_);
2245 lt->cursorRightOneWord(bv_);
2247 moveCursorUpdate(true);
2248 owner_->view_state_changed();
2252 case LFUN_WORDLEFTSEL:
2254 LyXText * lt = bv_->getLyXText();
2256 update(lt, BufferView::SELECT|BufferView::FITCUR);
2257 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2258 lt->cursorRightOneWord(bv_);
2260 lt->cursorLeftOneWord(bv_);
2262 moveCursorUpdate(true);
2263 owner_->view_state_changed();
2267 case LFUN_BEGINNINGBUFSEL:
2269 LyXText * lt = bv_->getLyXText();
2271 if (lt->inset_owner)
2273 update(lt, BufferView::SELECT|BufferView::FITCUR);
2276 moveCursorUpdate(true);
2277 owner_->view_state_changed();
2281 case LFUN_ENDBUFSEL:
2283 LyXText * lt = bv_->getLyXText();
2285 if (lt->inset_owner)
2288 BufferView::SELECT|BufferView::FITCUR);
2289 lt->cursorBottom(bv_);
2291 moveCursorUpdate(true);
2292 owner_->view_state_changed();
2296 // --- text changing commands ------------------------
2297 case LFUN_BREAKLINE:
2299 LyXText * lt = bv_->getLyXText();
2302 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2305 | BufferView::FITCUR
2306 | BufferView::CHANGE);
2307 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2308 moveCursorUpdate(false);
2312 case LFUN_PROTECTEDSPACE:
2314 LyXText * lt = bv_->getLyXText();
2315 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2317 if (style->free_spacing) {
2318 lt->insertChar(bv_, ' ');
2321 | BufferView::FITCUR
2322 | BufferView::CHANGE);
2324 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2326 moveCursorUpdate(false);
2332 LyXText * lt = bv_->getLyXText();
2334 if (lt->selection.mark()) {
2338 | BufferView::FITCUR);
2339 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2342 lt->selection.mark(true);
2345 | BufferView::FITCUR);
2346 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2348 lt->selection.cursor = lt->cursor;
2354 LyXText * lt = bv_->getLyXText();
2356 if (!lt->selection.set()) {
2358 lt->selection.cursor = lt->cursor;
2361 | BufferView::FITCUR
2362 | BufferView::CHANGE);
2363 // It is possible to make it a lot faster still
2364 // just comment out the line below...
2369 moveCursorUpdate(false);
2370 owner_->view_state_changed();
2375 case LFUN_DELETE_SKIP:
2377 LyXText * lt = bv_->getLyXText();
2379 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2381 LyXCursor cursor = lt->cursor;
2383 if (!lt->selection.set()) {
2384 if (cursor.pos() == cursor.par()->size()) {
2385 lt->cursorRight(bv_);
2386 cursor = lt->cursor;
2387 if (cursor.pos() == 0
2388 && !(cursor.par()->params().spaceTop()
2389 == VSpace (VSpace::NONE))) {
2392 cursor.par()->params().lineTop(),
2393 cursor.par()->params().lineBottom(),
2394 cursor.par()->params().pagebreakTop(),
2395 cursor.par()->params().pagebreakBottom(),
2396 VSpace(VSpace::NONE),
2397 cursor.par()->params().spaceBottom(),
2398 cursor.par()->params().spacing(),
2399 cursor.par()->params().align(),
2400 cursor.par()->params().labelWidthString(), 0);
2401 lt->cursorLeft(bv_);
2404 | BufferView::FITCUR
2405 | BufferView::CHANGE);
2407 lt->cursorLeft(bv_);
2409 lt->selection.cursor = lt->cursor;
2412 | BufferView::FITCUR
2413 | BufferView::CHANGE);
2417 lt->selection.cursor = lt->cursor;
2420 | BufferView::FITCUR
2421 | BufferView::CHANGE);
2429 /* -------> Delete word forward. */
2430 case LFUN_DELETE_WORD_FORWARD:
2431 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2432 bv_->getLyXText()->deleteWordForward(bv_);
2433 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2434 moveCursorUpdate(false);
2435 owner_->view_state_changed();
2438 /* -------> Delete word backward. */
2439 case LFUN_DELETE_WORD_BACKWARD:
2441 LyXText * lt = bv_->getLyXText();
2443 update(lt, BufferView::SELECT|BufferView::FITCUR);
2444 lt->deleteWordBackward(bv_);
2447 | BufferView::FITCUR
2448 | BufferView::CHANGE);
2449 moveCursorUpdate(false);
2450 owner_->view_state_changed();
2454 /* -------> Kill to end of line. */
2455 case LFUN_DELETE_LINE_FORWARD:
2457 LyXText * lt = bv_->getLyXText();
2459 update(lt, BufferView::SELECT|BufferView::FITCUR);
2460 lt->deleteLineForward(bv_);
2463 | BufferView::FITCUR
2464 | BufferView::CHANGE);
2465 moveCursorUpdate(false);
2469 /* -------> Set mark off. */
2472 LyXText * lt = bv_->getLyXText();
2475 update(lt, BufferView::SELECT|BufferView::FITCUR);
2476 lt->selection.cursor = lt->cursor;
2477 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2481 /* -------> Set mark on. */
2484 LyXText * lt = bv_->getLyXText();
2487 lt->selection.mark(true);
2488 update(lt, BufferView::SELECT|BufferView::FITCUR);
2489 lt->selection.cursor = lt->cursor;
2490 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2494 case LFUN_BACKSPACE:
2496 LyXText * lt = bv_->getLyXText();
2498 if (!lt->selection.set()) {
2499 if (owner_->getIntl()->getTransManager().backspace()) {
2501 lt->selection.cursor = lt->cursor;
2504 | BufferView::FITCUR
2505 | BufferView::CHANGE);
2506 // It is possible to make it a lot faster still
2507 // just comment out the line below...
2513 owner_->view_state_changed();
2518 case LFUN_BACKSPACE_SKIP:
2520 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2521 LyXText * lt = bv_->getLyXText();
2523 LyXCursor cursor = lt->cursor;
2525 if (!lt->selection.set()) {
2526 if (cursor.pos() == 0
2527 && !(cursor.par()->params().spaceTop()
2528 == VSpace (VSpace::NONE))) {
2531 cursor.par()->params().lineTop(),
2532 cursor.par()->params().lineBottom(),
2533 cursor.par()->params().pagebreakTop(),
2534 cursor.par()->params().pagebreakBottom(),
2535 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2536 cursor.par()->params().spacing(),
2537 cursor.par()->params().align(),
2538 cursor.par()->params().labelWidthString(), 0);
2541 | BufferView::FITCUR
2542 | BufferView::CHANGE);
2545 lt->selection.cursor = cursor;
2548 | BufferView::FITCUR
2549 | BufferView::CHANGE);
2556 case LFUN_BREAKPARAGRAPH:
2558 LyXText * lt = bv_->getLyXText();
2561 lt->breakParagraph(bv_, 0);
2564 | BufferView::FITCUR
2565 | BufferView::CHANGE);
2566 lt->selection.cursor = lt->cursor;
2568 owner_->view_state_changed();
2572 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2574 LyXText * lt = bv_->getLyXText();
2577 lt->breakParagraph(bv_, 1);
2580 | BufferView::FITCUR
2581 | BufferView::CHANGE);
2582 lt->selection.cursor = lt->cursor;
2584 owner_->view_state_changed();
2588 case LFUN_BREAKPARAGRAPH_SKIP:
2590 // When at the beginning of a paragraph, remove
2591 // indentation and add a "defskip" at the top.
2592 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2593 LyXText * lt = bv_->getLyXText();
2595 LyXCursor cursor = lt->cursor;
2598 if (cursor.pos() == 0) {
2599 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2602 cursor.par()->params().lineTop(),
2603 cursor.par()->params().lineBottom(),
2604 cursor.par()->params().pagebreakTop(),
2605 cursor.par()->params().pagebreakBottom(),
2606 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2607 cursor.par()->params().spacing(),
2608 cursor.par()->params().align(),
2609 cursor.par()->params().labelWidthString(), 1);
2610 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2614 lt->breakParagraph(bv_, 0);
2615 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2620 | BufferView::FITCUR
2621 | BufferView::CHANGE);
2622 lt->selection.cursor = cursor;
2624 owner_->view_state_changed();
2628 case LFUN_PARAGRAPH_SPACING:
2630 LyXText * lt = bv_->getLyXText();
2632 Paragraph * par = lt->cursor.par();
2633 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2634 float cur_value = 1.0;
2635 if (cur_spacing == Spacing::Other) {
2636 cur_value = par->params().spacing().getValue();
2639 istringstream istr(argument.c_str());
2643 Spacing::Space new_spacing = cur_spacing;
2644 float new_value = cur_value;
2646 lyxerr << "Missing argument to `paragraph-spacing'"
2648 } else if (tmp == "single") {
2649 new_spacing = Spacing::Single;
2650 } else if (tmp == "onehalf") {
2651 new_spacing = Spacing::Onehalf;
2652 } else if (tmp == "double") {
2653 new_spacing = Spacing::Double;
2654 } else if (tmp == "other") {
2655 new_spacing = Spacing::Other;
2658 lyxerr << "new_value = " << tmpval << endl;
2661 } else if (tmp == "default") {
2662 new_spacing = Spacing::Default;
2664 lyxerr << _("Unknown spacing argument: ")
2665 << argument << endl;
2667 if (cur_spacing != new_spacing || cur_value != new_value) {
2668 par->params().spacing(Spacing(new_spacing, new_value));
2669 lt->redoParagraph(bv_);
2672 | BufferView::FITCUR
2673 | BufferView::CHANGE);
2678 case LFUN_INSET_TOGGLE:
2680 LyXText * lt = bv_->getLyXText();
2683 update(lt, BufferView::SELECT|BufferView::FITCUR);
2684 lt->toggleInset(bv_);
2685 update(lt, BufferView::SELECT|BufferView::FITCUR);
2697 InsetCommandParams p;
2698 if (action == LFUN_HTMLURL)
2699 p.setCmdName("htmlurl");
2701 p.setCmdName("url");
2702 owner_->getDialogs()->createUrl(p.getAsString());
2706 case LFUN_INSERT_URL:
2708 InsetCommandParams p;
2709 p.setFromString(argument);
2711 InsetUrl * inset = new InsetUrl(p);
2712 if (!insertInset(inset))
2715 updateInset(inset, true);
2719 case LFUN_INSET_ERT:
2720 insertAndEditInset(new InsetERT(buffer_->params));
2723 case LFUN_INSET_EXTERNAL:
2724 insertAndEditInset(new InsetExternal);
2727 case LFUN_INSET_FOOTNOTE:
2728 insertAndEditInset(new InsetFoot(buffer_->params));
2731 case LFUN_INSET_MARGINAL:
2732 insertAndEditInset(new InsetMarginal(buffer_->params));
2735 case LFUN_INSET_MINIPAGE:
2736 insertAndEditInset(new InsetMinipage(buffer_->params));
2739 case LFUN_INSERT_NOTE:
2740 insertAndEditInset(new InsetNote(buffer_->params));
2743 case LFUN_INSET_FLOAT:
2744 // check if the float type exist
2745 if (floatList.typeExist(argument)) {
2746 insertAndEditInset(new InsetFloat(buffer_->params,
2749 lyxerr << "Non-existent float type: "
2750 << argument << endl;
2754 case LFUN_INSET_WIDE_FLOAT:
2755 // check if the float type exist
2756 if (floatList.typeExist(argument)) {
2757 InsetFloat * new_inset =
2758 new InsetFloat(buffer_->params, argument);
2759 new_inset->wide(true);
2760 insertAndEditInset(new_inset);
2762 lyxerr << "Non-existent float type: "
2763 << argument << endl;
2768 case LFUN_INSET_LIST:
2769 insertAndEditInset(new InsetList);
2772 case LFUN_INSET_THEOREM:
2773 insertAndEditInset(new InsetTheorem);
2777 case LFUN_INSET_CAPTION:
2779 // Do we have a locking inset...
2780 if (bv_->theLockingInset()) {
2781 lyxerr << "Locking inset code: "
2782 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2783 InsetCaption * new_inset =
2784 new InsetCaption(buffer_->params);
2785 new_inset->setOwner(bv_->theLockingInset());
2786 new_inset->setAutoBreakRows(true);
2787 new_inset->setDrawFrame(0, InsetText::LOCKED);
2788 new_inset->setFrameColor(0, LColor::captionframe);
2789 if (insertInset(new_inset))
2790 new_inset->edit(bv_);
2797 case LFUN_INSET_TABULAR:
2801 if (!argument.empty())
2802 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2803 InsetTabular * new_inset =
2804 new InsetTabular(*buffer_, r, c);
2806 bv_->getLyXText()->real_current_font.isRightToLeft();
2807 if (!open_new_inset(new_inset, rtl))
2812 // --- lyxserver commands ----------------------------
2814 case LFUN_CHARATCURSOR:
2816 pos_type pos = bv_->getLyXText()->cursor.pos();
2817 if (pos < bv_->getLyXText()->cursor.par()->size())
2818 owner_->getLyXFunc()->setMessage(
2819 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2821 owner_->getLyXFunc()->setMessage("EOF");
2826 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2828 + tostr(bv_->getLyXText()->cursor.y()));
2835 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2836 lyxerr << "SETXY: Could not parse coordinates in '"
2837 << argument << std::endl;
2839 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2843 case LFUN_GETLAYOUT:
2844 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2849 LyXFont & font = bv_->getLyXText()->current_font;
2850 if (font.shape() == LyXFont::ITALIC_SHAPE)
2851 owner_->getLyXFunc()->setMessage("E");
2852 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2853 owner_->getLyXFunc()->setMessage("N");
2855 owner_->getLyXFunc()->setMessage("0");
2860 // --- accented characters ---------------------------
2863 case LFUN_CIRCUMFLEX:
2873 case LFUN_SPECIAL_CARON:
2876 case LFUN_HUNG_UMLAUT:
2879 if (argument.empty()) {
2881 owner_->getLyXFunc()->handleKeyFunc(action);
2883 owner_->getLyXFunc()->handleKeyFunc(action);
2884 owner_->getIntl()->getTransManager()
2885 .TranslateAndInsert(argument[0], bv_->getLyXText());
2886 update(bv_->getLyXText(),
2888 | BufferView::FITCUR
2889 | BufferView::CHANGE);
2894 mathDispatch(bv_, argument);
2897 case LFUN_MATH_MACRO:
2898 mathDispatchMathMacro(bv_, argument);
2901 case LFUN_MATH_DELIM:
2902 mathDispatchMathDelim(bv_, argument);
2905 case LFUN_INSERT_MATRIX:
2906 mathDispatchInsertMatrix(bv_, argument);
2909 case LFUN_INSERT_MATH:
2910 mathDispatchInsertMath(bv_, argument);
2913 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2914 mathDispatchMathImportSelection(bv_, argument);
2917 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2918 mathDispatchMathDisplay(bv_, argument);
2921 case LFUN_MATH_MODE: // Open or create an inlined math inset
2922 mathDispatchMathMode(bv_, argument);
2925 case LFUN_GREEK: // Insert a single greek letter
2926 mathDispatchGreek(bv_, argument);
2929 case LFUN_CITATION_INSERT:
2931 InsetCommandParams p;
2932 p.setFromString(argument);
2934 InsetCitation * inset = new InsetCitation(p);
2935 if (!insertInset(inset))
2938 updateInset(inset, true);
2942 case LFUN_INSERT_BIBTEX:
2944 // ale970405+lasgoutt970425
2945 // The argument can be up to two tokens separated
2946 // by a space. The first one is the bibstyle.
2947 string const db = token(argument, ' ', 0);
2948 string const bibstyle = token(argument, ' ', 1);
2950 InsetCommandParams p("BibTeX", db, bibstyle);
2951 InsetBibtex * inset = new InsetBibtex(p);
2953 if (insertInset(inset)) {
2954 if (argument.empty())
2961 // BibTeX data bases
2962 case LFUN_BIBDB_ADD:
2964 InsetBibtex * inset =
2965 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2967 inset->addDatabase(argument);
2972 case LFUN_BIBDB_DEL:
2974 InsetBibtex * inset =
2975 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2977 inset->delDatabase(argument);
2982 case LFUN_BIBTEX_STYLE:
2984 InsetBibtex * inset =
2985 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2987 inset->setOptions(argument);
2992 case LFUN_INDEX_INSERT:
2994 string entry = argument;
2995 if (entry.empty()) {
2996 entry = bv_->getLyXText()->getStringToIndex(bv_);
2999 if (entry.empty()) {
3000 owner_->getDialogs()->createIndex();
3004 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3006 if (!insertInset(inset)) {
3009 updateInset(inset, true);
3014 case LFUN_INDEX_PRINT:
3016 InsetCommandParams p("printindex");
3017 Inset * inset = new InsetPrintIndex(p);
3018 if (!insertInset(inset, tclass.defaultLayoutName()))
3023 case LFUN_PARENTINSERT:
3025 InsetCommandParams p("lyxparent", argument);
3026 Inset * inset = new InsetParent(p, *buffer_);
3027 if (!insertInset(inset, tclass.defaultLayoutName()))
3033 case LFUN_CHILD_INSERT:
3035 InsetInclude::Params p;
3036 p.cparams.setFromString(argument);
3037 p.masterFilename_ = buffer_->fileName();
3039 InsetInclude * inset = new InsetInclude(p);
3040 if (!insertInset(inset))
3043 updateInset(inset, true);
3044 bv_->owner()->getDialogs()->showInclude(inset);
3049 case LFUN_FLOAT_LIST:
3050 if (floatList.typeExist(argument)) {
3051 Inset * inset = new InsetFloatList(argument);
3052 if (!insertInset(inset, tclass.defaultLayoutName()))
3055 lyxerr << "Non-existent float type: "
3056 << argument << endl;
3060 case LFUN_THESAURUS_ENTRY:
3062 string arg = argument;
3065 arg = bv_->getLyXText()->selectionAsString(buffer_,
3069 if (arg.size() > 100 || arg.empty()) {
3070 // Get word or selection
3071 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3072 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3073 // FIXME: where is getLyXText()->unselect(bv_) ?
3077 bv_->owner()->getDialogs()->showThesaurus(arg);
3081 case LFUN_SELFINSERT:
3083 if (argument.empty()) break;
3085 /* Automatically delete the currently selected
3086 * text and replace it with what is being
3087 * typed in now. Depends on lyxrc settings
3088 * "auto_region_delete", which defaults to
3091 LyXText * lt = bv_->getLyXText();
3093 if (lyxrc.auto_region_delete) {
3094 if (lt->selection.set()) {
3095 lt->cutSelection(bv_, false, false);
3098 | BufferView::FITCUR
3099 | BufferView::CHANGE);
3101 workarea().haveSelection(false);
3105 LyXFont const old_font(lt->real_current_font);
3107 string::const_iterator cit = argument.begin();
3108 string::const_iterator end = argument.end();
3109 for (; cit != end; ++cit) {
3110 owner_->getIntl()->getTransManager().
3111 TranslateAndInsert(*cit, lt);
3116 | BufferView::FITCUR
3117 | BufferView::CHANGE);
3119 lt->selection.cursor = lt->cursor;
3120 moveCursorUpdate(false);
3122 // real_current_font.number can change so we need to
3123 // update the minibuffer
3124 if (old_font != lt->real_current_font)
3125 owner_->view_state_changed();
3130 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3132 time_t now_time_t = time(NULL);
3133 struct tm * now_tm = localtime(&now_time_t);
3134 setlocale(LC_TIME, "");
3136 if (!argument.empty())
3139 arg = lyxrc.date_insert_format;
3141 int const datetmp_len =
3142 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3144 LyXText * lt = bv_->getLyXText();
3146 for (int i = 0; i < datetmp_len; i++) {
3147 lt->insertChar(bv_, datetmp[i]);
3150 | BufferView::FITCUR
3151 | BufferView::CHANGE);
3154 lt->selection.cursor = lt->cursor;
3155 moveCursorUpdate(false);
3159 case LFUN_UNKNOWN_ACTION:
3160 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3171 void BufferView::Pimpl::newline()
3174 LyXText * lt = bv_->getLyXText();
3178 | BufferView::FITCUR);
3179 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3182 | BufferView::FITCUR
3183 | BufferView::CHANGE);
3188 void BufferView::Pimpl::hfill()
3191 LyXText * lt = bv_->getLyXText();
3195 | BufferView::FITCUR);
3196 lt->insertChar(bv_, Paragraph::META_HFILL);
3199 | BufferView::FITCUR
3200 | BufferView::CHANGE);
3205 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3208 LyXText * lt = bv_->getLyXText();
3211 update(lt, BufferView::SELECT|BufferView::FITCUR);
3212 InsetSpecialChar * new_inset =
3213 new InsetSpecialChar(kind);
3214 if (!insertInset(new_inset))
3217 updateInset(new_inset, true);
3222 void BufferView::Pimpl::smartQuote()
3224 LyXText const * lt = bv_->getLyXText();
3225 Paragraph const * par = lt->cursor.par();
3226 pos_type pos = lt->cursor.pos();
3230 || (par->isInset(pos - 1)
3231 && par->getInset(pos - 1)->isSpace()))
3234 c = par->getChar(pos - 1);
3239 LyXLayout_ptr const & style = par->layout();
3241 if (style->pass_thru ||
3242 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3243 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, string("\""));
3247 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3250 if (insertInset(inset))
3255 bool gotsel = false;
3257 if (bv_->getLyXText()->selection.set()) {
3258 bv_->getLyXText()->cutSelection(bv_, true, false);
3262 if (insertInset(inset)) {
3265 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3273 // Open and lock an updatable inset
3274 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3276 LyXText * lt = bv_->getLyXText();
3280 if (!insertInset(new_inset)) {
3284 new_inset->edit(bv_, !behind);
3289 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3291 // if we are in a locking inset we should try to insert the
3292 // inset there otherwise this is a illegal function now
3293 if (bv_->theLockingInset()) {
3294 if (bv_->theLockingInset()->insetAllowed(inset))
3295 return bv_->theLockingInset()->insertInset(bv_, inset);
3299 // not quite sure if we want this...
3300 setCursorParUndo(bv_);
3303 beforeChange(bv_->text);
3304 if (!lout.empty()) {
3305 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3306 bv_->text->breakParagraph(bv_);
3307 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3309 if (bv_->text->cursor.par()->size()) {
3310 bv_->text->cursorLeft(bv_);
3312 bv_->text->breakParagraph(bv_);
3313 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3317 LyXTextClass const & tclass =
3318 textclasslist[buffer_->params.textclass];
3319 bool hasLayout = tclass.hasLayout(lres);
3320 string lay = tclass.defaultLayoutName();
3322 if (hasLayout != false) {
3326 // layout not fount using default
3327 lay = tclass.defaultLayoutName();
3330 bv_->text->setLayout(bv_, lay);
3332 bv_->text->setParagraph(bv_, 0, 0,
3334 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3339 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3342 bv_->text->insertInset(bv_, inset);
3343 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3350 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3352 if (!inset || !available())
3355 // first check for locking insets
3356 if (bv_->theLockingInset()) {
3357 if (bv_->theLockingInset() == inset) {
3358 if (bv_->text->updateInset(bv_, inset)) {
3361 buffer_->markDirty();
3366 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3367 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3370 buffer_->markDirty();
3378 // then check if the inset is a top_level inset (has no owner)
3379 // if yes do the update as always otherwise we have to update the
3380 // toplevel inset where this inset is inside
3381 Inset * tl_inset = inset;
3382 while(tl_inset->owner())
3383 tl_inset = tl_inset->owner();
3385 if (tl_inset == inset) {
3386 update(bv_->text, BufferView::UPDATE);
3387 if (bv_->text->updateInset(bv_, inset)) {
3391 | BufferView::FITCUR
3392 | BufferView::CHANGE);
3394 update(bv_->text, SELECT);
3398 } else if (static_cast<UpdatableInset *>(tl_inset)
3399 ->updateInsetInInset(bv_, inset))
3401 if (bv_->text->updateInset(bv_, tl_inset)) {
3409 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3412 if (!available()) return;
3415 beforeChange(bv_->text);
3416 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3418 LyXCursor const & cursor = bv_->text->cursor;
3422 cursor.par()->isInset(cursor.pos())) {
3423 Inset const * inset = cursor.par()->getInset(cursor.pos());
3424 if (find(codes.begin(), codes.end(), inset->lyxCode())
3427 static_cast<InsetCommand const *>(inset)->getContents();
3431 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3432 if (bv_->text->cursor.pos()
3433 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3434 LyXCursor tmp = bv_->text->cursor;
3435 bv_->text->cursor.par(bv_->text->ownerParagraph());
3436 bv_->text->cursor.pos(0);
3437 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3438 bv_->text->cursor = tmp;
3439 bv_->owner()->message(_("No more insets"));
3442 bv_->owner()->message(_("No more insets"));
3445 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3446 bv_->text->selection.cursor = bv_->text->cursor;
3450 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3452 gotoInset(vector<Inset::Code>(1, code), same_content);