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 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
385 void BufferView::Pimpl::scrollDocView(int value)
387 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
389 if (!buffer_) return;
391 screen().draw(bv_->text, bv_, value);
393 if (!lyxrc.cursor_follows_scrollbar) {
397 LyXText * vbt = bv_->text;
399 int const height = vbt->defaultHeight();
400 int const first = static_cast<int>((bv_->text->first_y + height));
401 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
403 if (vbt->cursor.y() < first)
404 vbt->setCursorFromCoordinates(bv_, 0, first);
405 else if (vbt->cursor.y() > last)
406 vbt->setCursorFromCoordinates(bv_, 0, last);
410 int BufferView::Pimpl::scroll(long time)
415 LyXText const * t = bv_->text;
417 double const diff = t->defaultHeight()
418 + double(time) * double(time) * 0.125;
420 scrollDocView(int(diff));
421 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
426 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
427 key_modifier::state state)
429 bv_->owner()->getLyXFunc()->processKeySym(key, state);
433 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
435 // Only use motion with button 1
436 if (!(state & mouse_button::button1))
442 // Check for inset locking
443 if (bv_->theLockingInset()) {
444 LyXCursor cursor = bv_->text->cursor;
445 LyXFont font = bv_->text->getFont(buffer_,
446 cursor.par(), cursor.pos());
447 int width = bv_->theLockingInset()->width(bv_, font);
448 int inset_x = font.isVisibleRightToLeft()
449 ? cursor.ix() - width : cursor.ix();
450 int start_x = inset_x + bv_->theLockingInset()->scroll();
452 bv_->theLockingInset()->
453 insetMotionNotify(bv_,
455 y - cursor.iy() + bv_->text->first_y,
460 /* The test for not selection possible is needed, that only motion
461 events are used, where the bottom press event was on
462 the drawing area too */
463 if (!selection_possible)
466 screen().hideCursor();
468 Row * cursorrow = bv_->text->cursor.row();
469 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
471 // sorry for this but I have a strange error that the y value jumps at
472 // a certain point. This seems like an error in my xforms library or
473 // in some other local environment, but I would like to leave this here
474 // for the moment until I can remove this (Jug 20020418)
475 if (y_before < bv_->text->cursor.y())
476 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
478 // This is to allow jumping over large insets
479 if (cursorrow == bv_->text->cursor.row()) {
480 if (y >= int(workarea().workHeight())) {
481 bv_->text->cursorDown(bv_, false);
483 bv_->text->cursorUp(bv_, false);
487 if (!bv_->text->selection.set())
488 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
490 bv_->text->setSelection(bv_);
491 screen().toggleToggle(bv_->text, bv_);
497 // Single-click on work area
498 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
499 mouse_button::state button)
504 // ok ok, this is a hack (for xforms)
505 if (button == mouse_button::button4) {
506 scroll(-lyxrc.wheel_jump);
507 // We shouldn't go further down as we really should only do the
508 // scrolling and be done with this. Otherwise we may open some
509 // dialogs (Jug 20020424).
511 } else if (button == mouse_button::button5) {
512 scroll(lyxrc.wheel_jump);
513 // We shouldn't go further down as we really should only do the
514 // scrolling and be done with this. Otherwise we may open some
515 // dialogs (Jug 20020424).
519 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
521 // Middle button press pastes if we have a selection
522 // We do this here as if the selection was inside an inset
523 // it could get cleared on the unlocking of the inset so
524 // we have to check this first
525 bool paste_internally = false;
526 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
527 owner_->getLyXFunc()->dispatch(LFUN_COPY);
528 paste_internally = true;
531 int const screen_first = bv_->text->first_y;
533 if (bv_->theLockingInset()) {
534 // We are in inset locking mode
536 /* Check whether the inset was hit. If not reset mode,
537 otherwise give the event to the inset */
538 if (inset_hit == bv_->theLockingInset()) {
539 bv_->theLockingInset()->
540 insetButtonPress(bv_, xpos, ypos, button);
543 bv_->unlockInset(bv_->theLockingInset());
548 selection_possible = true;
549 screen().hideCursor();
551 // Clear the selection
552 screen().toggleSelection(bv_->text, bv_);
553 bv_->text->clearSelection();
554 bv_->text->fullRebreak(bv_);
558 // Single left click in math inset?
559 if (isHighlyEditableInset(inset_hit)) {
560 // Highly editable inset, like math
561 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
562 selection_possible = false;
563 owner_->updateLayoutChoice();
564 owner_->message(inset->editMessage());
565 //inset->edit(bv_, xpos, ypos, button);
566 // We just have to lock the inset before calling a PressEvent on it!
567 // we don't need the edit() call here! (Jug20020329)
568 if (!bv_->lockInset(inset)) {
569 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
571 inset->insetButtonPress(bv_, xpos, ypos, button);
574 // I'm not sure we should continue here if we hit an inset (Jug20020403)
576 // Right click on a footnote flag opens float menu
577 if (button == mouse_button::button3) {
578 selection_possible = false;
582 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
583 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
585 bv_->text->selection.cursor = bv_->text->cursor;
586 bv_->text->cursor.x_fix(bv_->text->cursor.x());
588 owner_->updateLayoutChoice();
590 selection_possible = false;
593 // Insert primary selection with middle mouse
594 // if there is a local selection in the current buffer,
596 if (button == mouse_button::button2) {
597 if (paste_internally)
598 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
600 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
602 selection_possible = false;
608 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
613 LyXText * text = bv_->getLyXText();
615 if (text->bv_owner && bv_->theLockingInset())
618 if (button == mouse_button::button1) {
619 if (text->bv_owner) {
620 screen().hideCursor();
621 screen().toggleSelection(text, bv_);
622 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
623 screen().toggleSelection(text, bv_, false);
625 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
627 /* This will fit the cursor on the screen
629 update(text, BufferView::SELECT|BufferView::FITCUR);
634 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
639 LyXText * text = bv_->getLyXText();
641 if (text->bv_owner && bv_->theLockingInset())
644 if (button == mouse_button::button1) {
645 if (text->bv_owner) {
646 screen().hideCursor();
647 screen().toggleSelection(text, bv_);
649 text->cursorHome(bv_);
650 text->selection.cursor = text->cursor;
651 text->cursorEnd(bv_);
652 text->setSelection(bv_);
653 if (text->bv_owner) {
654 screen().toggleSelection(text, bv_, false);
656 /* This will fit the cursor on the screen
658 update(text, BufferView::SELECT|BufferView::FITCUR);
663 void BufferView::Pimpl::selectionRequested()
670 LyXText * text = bv_->getLyXText();
672 if (text->selection.set() &&
673 (!bv_->text->xsel_cache.set() ||
674 text->selection.start != bv_->text->xsel_cache.start ||
675 text->selection.end != bv_->text->xsel_cache.end))
677 bv_->text->xsel_cache = text->selection;
678 sel = text->selectionAsString(bv_->buffer(), false);
679 } else if (!text->selection.set()) {
681 bv_->text->xsel_cache.set(false);
684 workarea().putClipboard(sel);
689 void BufferView::Pimpl::selectionLost()
694 bv_->getLyXText()->clearSelection();
696 bv_->text->xsel_cache.set(false);
701 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
702 mouse_button::state button)
704 // do nothing if we used the mouse wheel
705 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
708 // If we hit an inset, we have the inset coordinates in these
709 // and inset_hit points to the inset. If we do not hit an
710 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
711 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
713 if (bv_->theLockingInset()) {
714 // We are in inset locking mode.
716 /* LyX does a kind of work-area grabbing for insets.
717 Only a ButtonPress Event outside the inset will
718 force a insetUnlock. */
719 bv_->theLockingInset()->
720 insetButtonRelease(bv_, x, y, button);
724 selection_possible = false;
726 if (button == mouse_button::button2)
730 if (button == mouse_button::button1) {
731 workarea().haveSelection(bv_->getLyXText()->selection.set());
736 owner_->updateMenubar();
737 owner_->updateToolbar();
739 // Did we hit an editable inset?
741 selection_possible = false;
743 // if we reach this point with a selection, it
744 // must mean we are currently selecting.
745 // But we don't want to open the inset
746 // because that is annoying for the user.
747 // So just pretend we didn't hit it.
748 // this is OK because a "kosher" ButtonRelease
749 // will follow a ButtonPress that clears
751 // Note this also fixes selection drawing
752 // problems if we end up opening an inset
753 if (bv_->getLyXText()->selection.set())
756 // CHECK fix this proper in 0.13
757 // well, maybe 13.0 !!!!!!!!!
759 // Following a ref shouldn't issue
760 // a push on the undo-stack
761 // anylonger, now that we have
762 // keybindings for following
763 // references and returning from
764 // references. IMHO though, it
765 // should be the inset's own business
766 // to push or not push on the undo
767 // stack. They don't *have* to
768 // alter the document...
770 // ...or maybe the SetCursorParUndo()
771 // below isn't necessary at all anylonger?
772 if (inset_hit->lyxCode() == Inset::REF_CODE) {
773 setCursorParUndo(bv_);
776 owner_->message(inset_hit->editMessage());
778 if (isHighlyEditableInset(inset_hit)) {
779 // Highly editable inset, like math
780 UpdatableInset *inset = (UpdatableInset *)inset_hit;
781 inset->insetButtonRelease(bv_, x, y, button);
783 inset_hit->insetButtonRelease(bv_, x, y, button);
784 // IMO this is a grosshack! Inset's should be changed so that
785 // they call the actions they have to do with the insetButtonRel.
786 // function and not in the edit(). This should be changed
788 inset_hit->edit(bv_, x, y, button);
793 // Maybe we want to edit a bibitem ale970302
794 if (bv_->text->cursor.par()->bibkey && x < 20 +
795 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
796 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
803 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
804 LyXCursor const & cursor) const
806 Paragraph /*const*/ & par = *cursor.par();
807 pos_type const pos = cursor.pos();
809 lyx::Assert(par.getInset(pos));
811 Inset const & inset(*par.getInset(pos));
813 LyXFont const & font = text.getFont(buffer_, &par, pos);
815 int const width = inset.width(bv_, font);
816 int const inset_x = font.isVisibleRightToLeft()
817 ? (cursor.ix() - width) : cursor.ix();
820 inset_x + inset.scroll(),
822 cursor.iy() - inset.ascent(bv_, font),
823 cursor.iy() + inset.descent(bv_, font));
827 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
828 LyXCursor const & cursor,
829 int & x, int & y) const
831 pos_type const pos(cursor.pos());
832 Paragraph /*const*/ & par(*cursor.par());
834 if (pos >= par.size() || !par.isInset(pos)) {
838 Inset /*const*/ * inset = par.getInset(pos);
840 if (!isEditableInset(inset)) {
844 Box b(insetDimensions(text, cursor));
846 if (!b.contained(x, y)) {
847 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
848 << " box " << b << endl;
852 text.setCursor(bv_, &par, pos, true);
855 // The origin of an inset is on the baseline
856 y -= text.cursor.iy();
862 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
864 int y_tmp = y + text->first_y;
867 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
869 Inset * inset(checkInset(*text, cursor, x, y_tmp));
876 // look at previous position
878 if (cursor.pos() == 0) {
883 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
885 inset = checkInset(*text, cursor, x, y_tmp);
893 void BufferView::Pimpl::workAreaResize()
895 static int work_area_width;
896 static int work_area_height;
898 bool const widthChange = workarea().workWidth() != work_area_width;
899 bool const heightChange = workarea().workHeight() != work_area_height;
901 // update from work area
902 work_area_width = workarea().workWidth();
903 work_area_height = workarea().workHeight();
907 // The visible LyXView need a resize
908 resizeCurrentBuffer();
910 // Remove all texts from the textcache
911 // This is not _really_ what we want to do. What
912 // we really want to do is to delete in textcache
913 // that does not have a BufferView with matching
914 // width, but as long as we have only one BufferView
915 // deleting all gives the same result.
916 if (lyxerr.debugging())
917 textcache.show(lyxerr, "Expose delete all");
919 // FIXME: this is aalready done in resizeCurrentBuffer() ??
920 buffer_->resizeInsets(bv_);
921 } else if (heightChange) {
922 // fitCursor() ensures we don't jump back
923 // to the start of the document on vertical
929 if (widthChange || heightChange) {
933 // always make sure that the scrollbar is sane.
936 owner_->updateLayoutChoice();
941 void BufferView::Pimpl::update()
943 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
944 LyXText::text_status st = bv_->text->status();
945 screen().update(bv_->text, bv_);
947 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
948 bv_->text->fullRebreak(bv_);
949 st = LyXText::NEED_MORE_REFRESH;
950 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
951 bv_->text->cursor.pos());
952 if (bv_->text->selection.set()) {
953 bv_->text->setCursor(bv_, bv_->text->selection.start,
954 bv_->text->selection.start.par(),
955 bv_->text->selection.start.pos());
956 bv_->text->setCursor(bv_, bv_->text->selection.end,
957 bv_->text->selection.end.par(),
958 bv_->text->selection.end.pos());
961 bv_->text->status(bv_, st);
962 screen().update(bv_->text, bv_);
964 // do this here instead of in the screen::update because of
966 bv_->text->status(bv_, LyXText::UNCHANGED);
972 // Values used when calling update:
974 // -2 - update, move sel_cursor if selection, fitcursor
975 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
976 // 0 - update, move sel_cursor if selection, fitcursor
977 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
978 // 3 - update, move sel_cursor if selection
981 // a simple redraw of the parts that need refresh
983 // move sel_cursor if selection -
984 // the text's sel_cursor is moved if there is selection is progress
987 // fitCursor() is called and the scrollbar updated
990 // the buffer is marked dirty.
999 // UPDATE_ONLY = UPDATE;
1000 // UPDATE_SELECT = UPDATE | SELECT;
1001 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1002 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1004 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1005 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1006 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1007 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1008 // update(3) -> update(1) -> update(1) -> update(SELECT)
1010 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1012 owner_->updateLayoutChoice();
1014 if (!text->selection.set() && (f & SELECT)) {
1015 text->selection.cursor = text->cursor;
1018 text->fullRebreak(bv_);
1020 if (text->inset_owner) {
1021 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1022 updateInset(text->inset_owner, false);
1032 buffer_->markDirty();
1037 // Callback for cursor timer
1038 void BufferView::Pimpl::cursorToggle()
1041 cursor_timeout.restart();
1046 extern void reapSpellchecker(void);
1049 if (!bv_->theLockingInset()) {
1050 screen().cursorToggle(bv_);
1052 bv_->theLockingInset()->toggleInsetCursor(bv_);
1055 cursor_timeout.restart();
1059 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1061 if (!text->cursor.row()->previous()) {
1062 if (text->first_y > 0) {
1063 int new_y = bv_->text->first_y - workarea().workHeight();
1064 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1070 int y = text->first_y;
1071 Row * cursorrow = text->cursor.row();
1073 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1077 if (cursorrow == bv_->text->cursor.row()) {
1078 // we have a row which is higher than the workarea so we leave the
1079 // cursor on the start of the row and move only the draw up as soon
1080 // as we move the cursor or do something while inside the row (it may
1081 // span several workarea-heights) we'll move to the top again, but this
1082 // is better than just jump down and only display part of the row.
1083 new_y = bv_->text->first_y - workarea().workHeight();
1085 if (text->inset_owner) {
1086 new_y = bv_->text->cursor.iy()
1087 + bv_->theLockingInset()->insetInInsetY() + y
1088 + text->cursor.row()->height()
1089 - workarea().workHeight() + 1;
1091 new_y = text->cursor.y()
1092 - text->cursor.row()->baseline()
1093 + text->cursor.row()->height()
1094 - workarea().workHeight() + 1;
1097 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1098 if (text->cursor.row()->previous()) {
1100 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1101 text->cursor.row()->previous()->pos(), false);
1102 if (cur.y() > text->first_y) {
1103 text->cursorUp(bv_, true);
1110 void BufferView::Pimpl::cursorNext(LyXText * text)
1112 if (!text->cursor.row()->next()) {
1113 int y = text->cursor.y() - text->cursor.row()->baseline() +
1114 text->cursor.row()->height();
1115 if (y > int(text->first_y + workarea().workHeight())) {
1116 screen().draw(bv_->text, bv_,
1117 bv_->text->first_y + workarea().workHeight());
1123 int y = text->first_y + workarea().workHeight();
1124 if (text->inset_owner && !text->first_y) {
1125 y -= (bv_->text->cursor.iy()
1126 - bv_->text->first_y
1127 + bv_->theLockingInset()->insetInInsetY());
1130 text->getRowNearY(y);
1132 Row * cursorrow = text->cursor.row();
1133 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1137 if (cursorrow == bv_->text->cursor.row()) {
1138 // we have a row which is higher than the workarea so we leave the
1139 // cursor on the start of the row and move only the draw down as soon
1140 // as we move the cursor or do something while inside the row (it may
1141 // span several workarea-heights) we'll move to the top again, but this
1142 // is better than just jump down and only display part of the row.
1143 new_y = bv_->text->first_y + workarea().workHeight();
1145 if (text->inset_owner) {
1146 new_y = bv_->text->cursor.iy()
1147 + bv_->theLockingInset()->insetInInsetY()
1148 + y - text->cursor.row()->baseline();
1150 new_y = text->cursor.y() - text->cursor.row()->baseline();
1153 screen().draw(bv_->text, bv_, new_y);
1154 if (text->cursor.row()->next()) {
1156 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1157 text->cursor.row()->next()->pos(), false);
1158 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1159 text->cursorDown(bv_, true);
1166 bool BufferView::Pimpl::available() const
1168 if (buffer_ && bv_->text)
1174 void BufferView::Pimpl::beforeChange(LyXText * text)
1177 text->clearSelection();
1181 void BufferView::Pimpl::savePosition(unsigned int i)
1183 if (i >= saved_positions_num)
1185 saved_positions[i] = Position(buffer_->fileName(),
1186 bv_->text->cursor.par()->id(),
1187 bv_->text->cursor.pos());
1190 str << _("Saved bookmark") << ' ' << i;
1191 owner_->message(str.str().c_str());
1196 void BufferView::Pimpl::restorePosition(unsigned int i)
1198 if (i >= saved_positions_num)
1201 string const fname = saved_positions[i].filename;
1203 beforeChange(bv_->text);
1205 if (fname != buffer_->fileName()) {
1206 Buffer * b = bufferlist.exists(fname) ?
1207 bufferlist.getBuffer(fname) :
1208 bufferlist.loadLyXFile(fname); // don't ask, just load it
1209 if (b != 0) buffer(b);
1212 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1216 bv_->text->setCursor(bv_, par,
1217 min(par->size(), saved_positions[i].par_pos));
1219 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1222 str << _("Moved to bookmark") << ' ' << i;
1223 owner_->message(str.str().c_str());
1228 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1230 if (i >= saved_positions_num)
1233 return !saved_positions[i].filename.empty();
1237 void BufferView::Pimpl::setState()
1239 if (!lyxrc.rtl_support)
1242 LyXText * text = bv_->getLyXText();
1243 if (text->real_current_font.isRightToLeft()
1244 && !(bv_->theLockingInset()
1245 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1247 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1248 owner_->getIntl()->KeyMapSec();
1250 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1251 owner_->getIntl()->KeyMapPrim();
1256 void BufferView::Pimpl::insetUnlock()
1258 if (bv_->theLockingInset()) {
1259 bv_->theLockingInset()->insetUnlock(bv_);
1260 bv_->theLockingInset(0);
1266 void BufferView::Pimpl::showCursor()
1268 if (bv_->theLockingInset())
1269 bv_->theLockingInset()->showInsetCursor(bv_);
1271 screen().showCursor(bv_->text, bv_);
1275 void BufferView::Pimpl::hideCursor()
1277 if (!bv_->theLockingInset())
1278 screen().hideCursor();
1282 void BufferView::Pimpl::toggleSelection(bool b)
1284 if (bv_->theLockingInset())
1285 bv_->theLockingInset()->toggleSelection(bv_, b);
1286 screen().toggleSelection(bv_->text, bv_, b);
1290 void BufferView::Pimpl::toggleToggle()
1292 screen().toggleToggle(bv_->text, bv_);
1296 void BufferView::Pimpl::center()
1298 beforeChange(bv_->text);
1299 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1300 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1302 screen().draw(bv_->text, bv_, 0);
1304 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1308 void BufferView::Pimpl::pasteClipboard(bool asPara)
1313 screen().hideCursor();
1314 beforeChange(bv_->text);
1316 string const clip(workarea().getClipboard());
1322 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1324 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1326 bv_->getLyXText()->clearSelection();
1327 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1331 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1333 workarea().putClipboard(stuff);
1338 * Dispatch functions for actions which can be valid for BufferView->text
1339 * and/or InsetText->text!!!
1344 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1346 LyXText * lt = bv_->getLyXText();
1348 if (selecting || lt->selection.mark()) {
1349 lt->setSelection(bv_);
1353 updateInset(lt->inset_owner, false);
1357 update(lt, BufferView::SELECT|BufferView::FITCUR);
1359 update(lt, BufferView::SELECT);
1361 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1362 bv_->theLockingInset()->hideInsetCursor(bv_);
1363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1367 if (!lt->selection.set())
1368 workarea().haveSelection(false);
1370 /* ---> Everytime the cursor is moved, show the current font state. */
1371 // should this too me moved out of this func?
1372 //owner->showState();
1377 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1379 LyXCursor cursor = bv_->getLyXText()->cursor;
1380 Buffer::inset_iterator it =
1381 find_if(Buffer::inset_iterator(
1382 cursor.par(), cursor.pos()),
1383 buffer_->inset_iterator_end(),
1384 lyx::compare_memfun(&Inset::lyxCode, code));
1385 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1389 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1391 string filename = filen;
1393 if (filename.empty()) {
1394 // Launch a file browser
1395 string initpath = lyxrc.document_path;
1398 string const trypath = owner_->buffer()->filePath();
1399 // If directory is writeable, use this as default.
1400 if (IsDirWriteable(trypath))
1404 FileDialog fileDlg(bv_->owner(),
1405 _("Select LyX document to insert"),
1407 make_pair(string(_("Documents|#o#O")),
1408 string(lyxrc.document_path)),
1409 make_pair(string(_("Examples|#E#e")),
1410 string(AddPath(system_lyxdir, "examples"))));
1412 FileDialog::Result result =
1413 fileDlg.Select(initpath,
1414 _("*.lyx| LyX Documents (*.lyx)"));
1416 if (result.first == FileDialog::Later)
1419 filename = result.second;
1421 // check selected filename
1422 if (filename.empty()) {
1423 owner_->message(_("Canceled."));
1428 // get absolute path of file and add ".lyx" to the filename if
1430 filename = FileSearch(string(), filename, "lyx");
1432 string const disp_fn(MakeDisplayPath(filename));
1435 s1 << _("Inserting document") << ' '
1436 << disp_fn << " ...";
1437 owner_->message(s1.str().c_str());
1438 bool const res = bv_->insertLyXFile(filename);
1441 str << _("Document") << ' ' << disp_fn
1442 << ' ' << _("inserted.");
1443 owner_->message(str.str().c_str());
1446 str << _("Could not insert document") << ' '
1448 owner_->message(str.str().c_str());
1453 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1455 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1456 << action <<"] arg[" << argument << "]" << endl;
1458 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1461 // --- Misc -------------------------------------------
1465 LyXText * lt = bv_->getLyXText();
1466 lt->toggleAppendix(bv_);
1469 | BufferView::FITCUR
1470 | BufferView::CHANGE);
1475 case LFUN_TOC_INSERT:
1477 InsetCommandParams p;
1478 p.setCmdName("tableofcontents");
1479 Inset * inset = new InsetTOC(p);
1480 if (!insertInset(inset, tclass.defaultLayoutName()))
1485 case LFUN_SCROLL_INSET:
1486 // this is not handled here as this funktion is only aktive
1487 // if we have a locking_inset and that one is (or contains)
1491 case LFUN_INSET_GRAPHICS:
1493 Inset * new_inset = new InsetGraphics;
1494 if (!insertInset(new_inset)) {
1497 // this is need because you don't use a inset->Edit()
1498 updateInset(new_inset, true);
1499 new_inset->edit(bv_);
1509 case LFUN_PASTESELECTION:
1511 bool asPara = false;
1512 if (argument == "paragraph")
1514 pasteClipboard(asPara);
1526 case LFUN_LAYOUT_COPY:
1527 bv_->copyEnvironment();
1530 case LFUN_LAYOUT_PASTE:
1531 bv_->pasteEnvironment();
1535 case LFUN_GOTOERROR:
1536 gotoInset(Inset::ERROR_CODE, false);
1540 gotoInset(Inset::IGNORE_CODE, false);
1543 case LFUN_REFERENCE_GOTO:
1545 vector<Inset::Code> tmp;
1546 tmp.push_back(Inset::LABEL_CODE);
1547 tmp.push_back(Inset::REF_CODE);
1548 gotoInset(tmp, true);
1552 case LFUN_HYPHENATION:
1553 specialChar(InsetSpecialChar::HYPHENATION);
1556 case LFUN_LIGATURE_BREAK:
1557 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1561 specialChar(InsetSpecialChar::LDOTS);
1564 case LFUN_END_OF_SENTENCE:
1565 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1568 case LFUN_MENU_SEPARATOR:
1569 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1576 case LFUN_DEPTH_MIN:
1577 changeDepth(bv_, bv_->getLyXText(), -1);
1580 case LFUN_DEPTH_PLUS:
1581 changeDepth(bv_, bv_->getLyXText(), 1);
1585 owner_->getDialogs()->setUserFreeFont();
1588 case LFUN_FILE_INSERT:
1589 MenuInsertLyXFile(argument);
1592 case LFUN_FILE_INSERT_ASCII_PARA:
1593 InsertAsciiFile(bv_, argument, true);
1596 case LFUN_FILE_INSERT_ASCII:
1597 InsertAsciiFile(bv_, argument, false);
1602 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1603 << argument << endl;
1605 // This is not the good solution to the empty argument
1606 // problem, but it will hopefully suffice for 1.2.0.
1607 // The correct solution would be to augument the
1608 // function list/array with information about what
1609 // functions needs arguments and their type.
1610 if (argument.empty()) {
1611 owner_->getLyXFunc()->setErrorMessage(
1612 _("LyX function 'layout' needs an argument."));
1616 // Derive layout number from given argument (string)
1617 // and current buffer's textclass (number). */
1618 bool hasLayout = tclass.hasLayout(argument);
1619 string layout = argument;
1621 // If the entry is obsolete, use the new one instead.
1623 string const & obs = tclass[layout]->obsoleted_by();
1629 owner_->getLyXFunc()->setErrorMessage(
1630 string(N_("Layout ")) + argument +
1635 bool change_layout = (current_layout != layout);
1636 LyXText * lt = bv_->getLyXText();
1637 if (!change_layout && lt->selection.set() &&
1638 lt->selection.start.par() != lt->selection.end.par())
1640 Paragraph * spar = lt->selection.start.par();
1641 Paragraph * epar = lt->selection.end.par()->next();
1642 while(spar != epar) {
1643 if (spar->layout()->name() != current_layout) {
1644 change_layout = true;
1649 if (change_layout) {
1651 current_layout = layout;
1654 | BufferView::FITCUR);
1655 lt->setLayout(bv_, layout);
1656 owner_->setLayout(layout);
1659 | BufferView::FITCUR
1660 | BufferView::CHANGE);
1667 lang(bv_, argument);
1669 owner_->showState();
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1694 owner_->showState();
1699 owner_->showState();
1704 owner_->showState();
1707 case LFUN_UNDERLINE:
1709 owner_->showState();
1712 case LFUN_FONT_SIZE:
1713 fontSize(bv_, argument);
1714 owner_->showState();
1717 case LFUN_FONT_STATE:
1718 owner_->getLyXFunc()->setMessage(currentState(bv_));
1721 case LFUN_UPCASE_WORD:
1723 LyXText * lt = bv_->getLyXText();
1727 | BufferView::FITCUR);
1728 lt->changeCase(bv_, LyXText::text_uppercase);
1729 if (lt->inset_owner)
1730 updateInset(lt->inset_owner, true);
1733 | BufferView::FITCUR
1734 | BufferView::CHANGE);
1738 case LFUN_LOWCASE_WORD:
1740 LyXText * lt = bv_->getLyXText();
1742 update(lt, BufferView::SELECT|BufferView::FITCUR);
1743 lt->changeCase(bv_, LyXText::text_lowercase);
1744 if (lt->inset_owner)
1745 updateInset(lt->inset_owner, true);
1748 | BufferView::FITCUR
1749 | BufferView::CHANGE);
1753 case LFUN_CAPITALIZE_WORD:
1755 LyXText * lt = bv_->getLyXText();
1757 update(lt, BufferView::SELECT|BufferView::FITCUR);
1758 lt->changeCase(bv_, LyXText::text_capitalization);
1759 if (lt->inset_owner)
1760 updateInset(lt->inset_owner, true);
1763 | BufferView::FITCUR
1764 | BufferView::CHANGE);
1768 case LFUN_TRANSPOSE_CHARS:
1770 LyXText * lt = bv_->getLyXText();
1772 update(lt, BufferView::SELECT|BufferView::FITCUR);
1773 lt->transposeChars(*bv_);
1774 if (lt->inset_owner)
1775 updateInset(lt->inset_owner, true);
1778 | BufferView::FITCUR
1779 | BufferView::CHANGE);
1784 case LFUN_INSERT_LABEL:
1785 MenuInsertLabel(bv_, argument);
1788 case LFUN_REF_INSERT:
1789 if (argument.empty()) {
1790 InsetCommandParams p("ref");
1791 owner_->getDialogs()->createRef(p.getAsString());
1793 InsetCommandParams p;
1794 p.setFromString(argument);
1796 InsetRef * inset = new InsetRef(p, *buffer_);
1797 if (!insertInset(inset))
1800 updateInset(inset, true);
1804 case LFUN_BOOKMARK_SAVE:
1805 savePosition(strToUnsignedInt(argument));
1808 case LFUN_BOOKMARK_GOTO:
1809 restorePosition(strToUnsignedInt(argument));
1814 string label(argument);
1815 if (label.empty()) {
1817 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1819 label = inset->getContents();
1824 if (!label.empty()) {
1825 //bv_->savePosition(0);
1826 if (!bv_->gotoLabel(label))
1827 Alert::alert(_("Error"),
1828 _("Couldn't find this label"),
1829 _("in current document."));
1834 // --- Cursor Movements -----------------------------
1837 LyXText * lt = bv_->getLyXText();
1839 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1840 if (!lt->selection.mark())
1842 update(lt, BufferView::SELECT|BufferView::FITCUR);
1844 lt->cursorLeft(bv_, false);
1845 if (lt->cursor.pos() < lt->cursor.par()->size()
1846 && lt->cursor.par()->isInset(lt->cursor.pos())
1847 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1848 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1849 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1851 tmpinset->edit(bv_, false);
1853 tmpinset->edit(bv_);
1857 lt->cursorRight(bv_, false);
1859 moveCursorUpdate(false);
1860 owner_->showState();
1866 // This is soooo ugly. Isn`t it possible to make
1867 // it simpler? (Lgb)
1868 LyXText * lt = bv_->getLyXText();
1869 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1870 if (!lt->selection.mark())
1872 update(lt, BufferView::SELECT|BufferView::FITCUR);
1873 LyXCursor const cur = lt->cursor;
1875 lt->cursorLeft(bv_, false);
1876 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1877 lt->cursor.pos() < lt->cursor.par()->size() &&
1878 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1879 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1880 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1881 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1883 tmpinset->edit(bv_);
1885 tmpinset->edit(bv_, false);
1889 lt->cursorRight(bv_, false);
1892 moveCursorUpdate(false);
1893 owner_->showState();
1899 LyXText * lt = bv_->getLyXText();
1901 if (!lt->selection.mark())
1903 update(lt, BufferView::UPDATE);
1906 moveCursorUpdate(false);
1907 owner_->showState();
1913 LyXText * lt = bv_->getLyXText();
1915 if (!lt->selection.mark())
1917 update(lt, BufferView::UPDATE);
1918 lt->cursorDown(bv_);
1920 moveCursorUpdate(false);
1921 owner_->showState();
1925 case LFUN_UP_PARAGRAPH:
1927 LyXText * lt = bv_->getLyXText();
1929 if (!lt->selection.mark())
1931 update(lt, BufferView::UPDATE);
1932 lt->cursorUpParagraph(bv_);
1934 moveCursorUpdate(false);
1935 owner_->showState();
1939 case LFUN_DOWN_PARAGRAPH:
1941 LyXText * lt = bv_->getLyXText();
1943 if (!lt->selection.mark())
1945 update(lt, BufferView::UPDATE);
1946 lt->cursorDownParagraph(bv_);
1948 moveCursorUpdate(false);
1949 owner_->showState();
1955 LyXText * lt = bv_->getLyXText();
1957 if (!lt->selection.mark())
1959 update(lt, BufferView::UPDATE);
1962 moveCursorUpdate(false, false);
1963 owner_->showState();
1969 LyXText * lt = bv_->getLyXText();
1971 if (!lt->selection.mark())
1973 update(lt, BufferView::UPDATE);
1976 moveCursorUpdate(false, false);
1977 owner_->showState();
1983 LyXText * lt = bv_->getLyXText();
1985 if (!lt->selection.mark())
1987 update(lt, BufferView::SELECT|BufferView::FITCUR);
1988 lt->cursorHome(bv_);
1990 moveCursorUpdate(false);
1991 owner_->showState();
1997 LyXText * lt = bv_->getLyXText();
1999 if (!lt->selection.mark())
2002 BufferView::SELECT|BufferView::FITCUR);
2005 moveCursorUpdate(false);
2006 owner_->showState();
2010 case LFUN_SHIFT_TAB:
2013 LyXText * lt = bv_->getLyXText();
2015 if (!lt->selection.mark())
2018 BufferView::SELECT|BufferView::FITCUR);
2021 moveCursorUpdate(false);
2022 owner_->showState();
2026 case LFUN_WORDRIGHT:
2028 LyXText * lt = bv_->getLyXText();
2030 if (!lt->selection.mark())
2032 update(lt, BufferView::SELECT|BufferView::FITCUR);
2033 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2034 lt->cursorLeftOneWord(bv_);
2036 lt->cursorRightOneWord(bv_);
2038 moveCursorUpdate(false);
2039 owner_->showState();
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->cursorRightOneWord(bv_);
2053 lt->cursorLeftOneWord(bv_);
2055 moveCursorUpdate(false);
2056 owner_->showState();
2060 case LFUN_BEGINNINGBUF:
2062 LyXText * lt = bv_->getLyXText();
2064 if (!lt->selection.mark())
2067 BufferView::SELECT|BufferView::FITCUR);
2070 moveCursorUpdate(false);
2071 owner_->showState();
2077 LyXText * lt = bv_->getLyXText();
2079 if (!lt->selection.mark())
2082 BufferView::SELECT|BufferView::FITCUR);
2083 lt->cursorBottom(bv_);
2085 moveCursorUpdate(false);
2086 owner_->showState();
2090 /* cursor selection ---------------------------- */
2093 LyXText * lt = bv_->getLyXText();
2096 BufferView::SELECT|BufferView::FITCUR);
2097 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2098 lt->cursorLeft(bv_);
2100 lt->cursorRight(bv_);
2102 moveCursorUpdate(true);
2103 owner_->showState();
2109 LyXText * lt = bv_->getLyXText();
2112 BufferView::SELECT|BufferView::FITCUR);
2113 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2114 lt->cursorRight(bv_);
2116 lt->cursorLeft(bv_);
2118 moveCursorUpdate(true);
2119 owner_->showState();
2125 LyXText * lt = bv_->getLyXText();
2128 BufferView::SELECT|BufferView::FITCUR);
2129 lt->cursorUp(bv_, true);
2131 moveCursorUpdate(true);
2132 owner_->showState();
2138 LyXText * lt = bv_->getLyXText();
2141 BufferView::SELECT|BufferView::FITCUR);
2142 lt->cursorDown(bv_, true);
2144 moveCursorUpdate(true);
2145 owner_->showState();
2149 case LFUN_UP_PARAGRAPHSEL:
2151 LyXText * lt = bv_->getLyXText();
2154 BufferView::SELECT|BufferView::FITCUR);
2155 lt->cursorUpParagraph(bv_);
2157 moveCursorUpdate(true);
2158 owner_->showState();
2162 case LFUN_DOWN_PARAGRAPHSEL:
2164 LyXText * lt = bv_->getLyXText();
2167 BufferView::SELECT|BufferView::FITCUR);
2168 lt->cursorDownParagraph(bv_);
2170 moveCursorUpdate(true);
2171 owner_->showState();
2177 LyXText * lt = bv_->getLyXText();
2179 update(lt, BufferView::SELECT|BufferView::FITCUR);
2182 moveCursorUpdate(true);
2183 owner_->showState();
2189 LyXText * lt = bv_->getLyXText();
2191 update(lt, BufferView::SELECT|BufferView::FITCUR);
2194 moveCursorUpdate(true);
2195 owner_->showState();
2201 LyXText * lt = bv_->getLyXText();
2203 update(lt, BufferView::SELECT|BufferView::FITCUR);
2204 lt->cursorHome(bv_);
2206 moveCursorUpdate(true);
2207 owner_->showState();
2213 LyXText * lt = bv_->getLyXText();
2215 update(lt, BufferView::SELECT|BufferView::FITCUR);
2218 moveCursorUpdate(true);
2219 owner_->showState();
2223 case LFUN_WORDRIGHTSEL:
2225 LyXText * lt = bv_->getLyXText();
2227 update(lt, BufferView::SELECT|BufferView::FITCUR);
2228 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2229 lt->cursorLeftOneWord(bv_);
2231 lt->cursorRightOneWord(bv_);
2233 moveCursorUpdate(true);
2234 owner_->showState();
2238 case LFUN_WORDLEFTSEL:
2240 LyXText * lt = bv_->getLyXText();
2242 update(lt, BufferView::SELECT|BufferView::FITCUR);
2243 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2244 lt->cursorRightOneWord(bv_);
2246 lt->cursorLeftOneWord(bv_);
2248 moveCursorUpdate(true);
2249 owner_->showState();
2253 case LFUN_BEGINNINGBUFSEL:
2255 LyXText * lt = bv_->getLyXText();
2257 if (lt->inset_owner)
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2262 moveCursorUpdate(true);
2263 owner_->showState();
2267 case LFUN_ENDBUFSEL:
2269 LyXText * lt = bv_->getLyXText();
2271 if (lt->inset_owner)
2274 BufferView::SELECT|BufferView::FITCUR);
2275 lt->cursorBottom(bv_);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2282 // --- text changing commands ------------------------
2283 case LFUN_BREAKLINE:
2285 LyXText * lt = bv_->getLyXText();
2288 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2291 | BufferView::FITCUR
2292 | BufferView::CHANGE);
2293 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2294 moveCursorUpdate(false);
2298 case LFUN_PROTECTEDSPACE:
2300 LyXText * lt = bv_->getLyXText();
2301 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2303 if (style->free_spacing) {
2304 lt->insertChar(bv_, ' ');
2307 | BufferView::FITCUR
2308 | BufferView::CHANGE);
2310 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2312 moveCursorUpdate(false);
2318 LyXText * lt = bv_->getLyXText();
2320 if (lt->selection.mark()) {
2324 | BufferView::FITCUR);
2325 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2328 lt->selection.mark(true);
2331 | BufferView::FITCUR);
2332 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2334 lt->selection.cursor = lt->cursor;
2340 LyXText * lt = bv_->getLyXText();
2342 if (!lt->selection.set()) {
2344 lt->selection.cursor = lt->cursor;
2347 | BufferView::FITCUR
2348 | BufferView::CHANGE);
2349 // It is possible to make it a lot faster still
2350 // just comment out the line below...
2355 moveCursorUpdate(false);
2356 owner_->showState();
2361 case LFUN_DELETE_SKIP:
2363 LyXText * lt = bv_->getLyXText();
2365 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2367 LyXCursor cursor = lt->cursor;
2369 if (!lt->selection.set()) {
2370 if (cursor.pos() == cursor.par()->size()) {
2371 lt->cursorRight(bv_);
2372 cursor = lt->cursor;
2373 if (cursor.pos() == 0
2374 && !(cursor.par()->params().spaceTop()
2375 == VSpace (VSpace::NONE))) {
2378 cursor.par()->params().lineTop(),
2379 cursor.par()->params().lineBottom(),
2380 cursor.par()->params().pagebreakTop(),
2381 cursor.par()->params().pagebreakBottom(),
2382 VSpace(VSpace::NONE),
2383 cursor.par()->params().spaceBottom(),
2384 cursor.par()->params().spacing(),
2385 cursor.par()->params().align(),
2386 cursor.par()->params().labelWidthString(), 0);
2387 lt->cursorLeft(bv_);
2390 | BufferView::FITCUR
2391 | BufferView::CHANGE);
2393 lt->cursorLeft(bv_);
2395 lt->selection.cursor = lt->cursor;
2398 | BufferView::FITCUR
2399 | BufferView::CHANGE);
2403 lt->selection.cursor = lt->cursor;
2406 | BufferView::FITCUR
2407 | BufferView::CHANGE);
2415 /* -------> Delete word forward. */
2416 case LFUN_DELETE_WORD_FORWARD:
2417 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2418 bv_->getLyXText()->deleteWordForward(bv_);
2419 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2420 moveCursorUpdate(false);
2421 owner_->showState();
2424 /* -------> Delete word backward. */
2425 case LFUN_DELETE_WORD_BACKWARD:
2427 LyXText * lt = bv_->getLyXText();
2429 update(lt, BufferView::SELECT|BufferView::FITCUR);
2430 lt->deleteWordBackward(bv_);
2433 | BufferView::FITCUR
2434 | BufferView::CHANGE);
2435 moveCursorUpdate(false);
2436 owner_->showState();
2440 /* -------> Kill to end of line. */
2441 case LFUN_DELETE_LINE_FORWARD:
2443 LyXText * lt = bv_->getLyXText();
2445 update(lt, BufferView::SELECT|BufferView::FITCUR);
2446 lt->deleteLineForward(bv_);
2449 | BufferView::FITCUR
2450 | BufferView::CHANGE);
2451 moveCursorUpdate(false);
2455 /* -------> Set mark off. */
2458 LyXText * lt = bv_->getLyXText();
2461 update(lt, BufferView::SELECT|BufferView::FITCUR);
2462 lt->selection.cursor = lt->cursor;
2463 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2467 /* -------> Set mark on. */
2470 LyXText * lt = bv_->getLyXText();
2473 lt->selection.mark(true);
2474 update(lt, BufferView::SELECT|BufferView::FITCUR);
2475 lt->selection.cursor = lt->cursor;
2476 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2480 case LFUN_BACKSPACE:
2482 LyXText * lt = bv_->getLyXText();
2484 if (!lt->selection.set()) {
2485 if (owner_->getIntl()->getTransManager().backspace()) {
2487 lt->selection.cursor = lt->cursor;
2490 | BufferView::FITCUR
2491 | BufferView::CHANGE);
2492 // It is possible to make it a lot faster still
2493 // just comment out the line below...
2499 owner_->showState();
2504 case LFUN_BACKSPACE_SKIP:
2506 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2507 LyXText * lt = bv_->getLyXText();
2509 LyXCursor cursor = lt->cursor;
2511 if (!lt->selection.set()) {
2512 if (cursor.pos() == 0
2513 && !(cursor.par()->params().spaceTop()
2514 == VSpace (VSpace::NONE))) {
2517 cursor.par()->params().lineTop(),
2518 cursor.par()->params().lineBottom(),
2519 cursor.par()->params().pagebreakTop(),
2520 cursor.par()->params().pagebreakBottom(),
2521 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2522 cursor.par()->params().spacing(),
2523 cursor.par()->params().align(),
2524 cursor.par()->params().labelWidthString(), 0);
2527 | BufferView::FITCUR
2528 | BufferView::CHANGE);
2531 lt->selection.cursor = cursor;
2534 | BufferView::FITCUR
2535 | BufferView::CHANGE);
2542 case LFUN_BREAKPARAGRAPH:
2544 LyXText * lt = bv_->getLyXText();
2547 lt->breakParagraph(bv_, 0);
2550 | BufferView::FITCUR
2551 | BufferView::CHANGE);
2552 lt->selection.cursor = lt->cursor;
2554 owner_->showState();
2558 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2560 LyXText * lt = bv_->getLyXText();
2563 lt->breakParagraph(bv_, 1);
2566 | BufferView::FITCUR
2567 | BufferView::CHANGE);
2568 lt->selection.cursor = lt->cursor;
2570 owner_->showState();
2574 case LFUN_BREAKPARAGRAPH_SKIP:
2576 // When at the beginning of a paragraph, remove
2577 // indentation and add a "defskip" at the top.
2578 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2579 LyXText * lt = bv_->getLyXText();
2581 LyXCursor cursor = lt->cursor;
2584 if (cursor.pos() == 0) {
2585 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2588 cursor.par()->params().lineTop(),
2589 cursor.par()->params().lineBottom(),
2590 cursor.par()->params().pagebreakTop(),
2591 cursor.par()->params().pagebreakBottom(),
2592 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2593 cursor.par()->params().spacing(),
2594 cursor.par()->params().align(),
2595 cursor.par()->params().labelWidthString(), 1);
2596 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2600 lt->breakParagraph(bv_, 0);
2601 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2606 | BufferView::FITCUR
2607 | BufferView::CHANGE);
2608 lt->selection.cursor = cursor;
2610 owner_->showState();
2614 case LFUN_PARAGRAPH_SPACING:
2616 LyXText * lt = bv_->getLyXText();
2618 Paragraph * par = lt->cursor.par();
2619 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2620 float cur_value = 1.0;
2621 if (cur_spacing == Spacing::Other) {
2622 cur_value = par->params().spacing().getValue();
2625 istringstream istr(argument.c_str());
2629 Spacing::Space new_spacing = cur_spacing;
2630 float new_value = cur_value;
2632 lyxerr << "Missing argument to `paragraph-spacing'"
2634 } else if (tmp == "single") {
2635 new_spacing = Spacing::Single;
2636 } else if (tmp == "onehalf") {
2637 new_spacing = Spacing::Onehalf;
2638 } else if (tmp == "double") {
2639 new_spacing = Spacing::Double;
2640 } else if (tmp == "other") {
2641 new_spacing = Spacing::Other;
2644 lyxerr << "new_value = " << tmpval << endl;
2647 } else if (tmp == "default") {
2648 new_spacing = Spacing::Default;
2650 lyxerr << _("Unknown spacing argument: ")
2651 << argument << endl;
2653 if (cur_spacing != new_spacing || cur_value != new_value) {
2654 par->params().spacing(Spacing(new_spacing, new_value));
2655 lt->redoParagraph(bv_);
2658 | BufferView::FITCUR
2659 | BufferView::CHANGE);
2664 case LFUN_INSET_TOGGLE:
2666 LyXText * lt = bv_->getLyXText();
2669 update(lt, BufferView::SELECT|BufferView::FITCUR);
2670 lt->toggleInset(bv_);
2671 update(lt, BufferView::SELECT|BufferView::FITCUR);
2683 InsetCommandParams p;
2684 if (action == LFUN_HTMLURL)
2685 p.setCmdName("htmlurl");
2687 p.setCmdName("url");
2688 owner_->getDialogs()->createUrl(p.getAsString());
2692 case LFUN_INSERT_URL:
2694 InsetCommandParams p;
2695 p.setFromString(argument);
2697 InsetUrl * inset = new InsetUrl(p);
2698 if (!insertInset(inset))
2701 updateInset(inset, true);
2705 case LFUN_INSET_ERT:
2706 insertAndEditInset(new InsetERT(buffer_->params));
2709 case LFUN_INSET_EXTERNAL:
2710 insertAndEditInset(new InsetExternal);
2713 case LFUN_INSET_FOOTNOTE:
2714 insertAndEditInset(new InsetFoot(buffer_->params));
2717 case LFUN_INSET_MARGINAL:
2718 insertAndEditInset(new InsetMarginal(buffer_->params));
2721 case LFUN_INSET_MINIPAGE:
2722 insertAndEditInset(new InsetMinipage(buffer_->params));
2725 case LFUN_INSERT_NOTE:
2726 insertAndEditInset(new InsetNote(buffer_->params));
2729 case LFUN_INSET_FLOAT:
2730 // check if the float type exist
2731 if (floatList.typeExist(argument)) {
2732 insertAndEditInset(new InsetFloat(buffer_->params,
2735 lyxerr << "Non-existent float type: "
2736 << argument << endl;
2740 case LFUN_INSET_WIDE_FLOAT:
2741 // check if the float type exist
2742 if (floatList.typeExist(argument)) {
2743 InsetFloat * new_inset =
2744 new InsetFloat(buffer_->params, argument);
2745 new_inset->wide(true);
2746 insertAndEditInset(new_inset);
2748 lyxerr << "Non-existent float type: "
2749 << argument << endl;
2754 case LFUN_INSET_LIST:
2755 insertAndEditInset(new InsetList);
2758 case LFUN_INSET_THEOREM:
2759 insertAndEditInset(new InsetTheorem);
2763 case LFUN_INSET_CAPTION:
2765 // Do we have a locking inset...
2766 if (bv_->theLockingInset()) {
2767 lyxerr << "Locking inset code: "
2768 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2769 InsetCaption * new_inset =
2770 new InsetCaption(buffer_->params);
2771 new_inset->setOwner(bv_->theLockingInset());
2772 new_inset->setAutoBreakRows(true);
2773 new_inset->setDrawFrame(0, InsetText::LOCKED);
2774 new_inset->setFrameColor(0, LColor::captionframe);
2775 if (insertInset(new_inset))
2776 new_inset->edit(bv_);
2783 case LFUN_INSET_TABULAR:
2787 if (!argument.empty())
2788 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2789 InsetTabular * new_inset =
2790 new InsetTabular(*buffer_, r, c);
2792 bv_->getLyXText()->real_current_font.isRightToLeft();
2793 if (!open_new_inset(new_inset, rtl))
2798 // --- lyxserver commands ----------------------------
2800 case LFUN_CHARATCURSOR:
2802 pos_type pos = bv_->getLyXText()->cursor.pos();
2803 if (pos < bv_->getLyXText()->cursor.par()->size())
2804 owner_->getLyXFunc()->setMessage(
2805 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2807 owner_->getLyXFunc()->setMessage("EOF");
2812 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2814 + tostr(bv_->getLyXText()->cursor.y()));
2821 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2822 lyxerr << "SETXY: Could not parse coordinates in '"
2823 << argument << std::endl;
2825 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2829 case LFUN_GETLAYOUT:
2830 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2835 LyXFont & font = bv_->getLyXText()->current_font;
2836 if (font.shape() == LyXFont::ITALIC_SHAPE)
2837 owner_->getLyXFunc()->setMessage("E");
2838 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2839 owner_->getLyXFunc()->setMessage("N");
2841 owner_->getLyXFunc()->setMessage("0");
2846 // --- accented characters ---------------------------
2849 case LFUN_CIRCUMFLEX:
2859 case LFUN_SPECIAL_CARON:
2862 case LFUN_HUNG_UMLAUT:
2865 if (argument.empty()) {
2867 owner_->getLyXFunc()->handleKeyFunc(action);
2869 owner_->getLyXFunc()->handleKeyFunc(action);
2870 owner_->getIntl()->getTransManager()
2871 .TranslateAndInsert(argument[0], bv_->getLyXText());
2872 update(bv_->getLyXText(),
2874 | BufferView::FITCUR
2875 | BufferView::CHANGE);
2880 mathDispatch(bv_, argument);
2883 case LFUN_MATH_MACRO:
2884 mathDispatchMathMacro(bv_, argument);
2887 case LFUN_MATH_DELIM:
2888 mathDispatchMathDelim(bv_, argument);
2891 case LFUN_INSERT_MATRIX:
2892 mathDispatchInsertMatrix(bv_, argument);
2895 case LFUN_INSERT_MATH:
2896 mathDispatchInsertMath(bv_, argument);
2899 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2900 mathDispatchMathImportSelection(bv_, argument);
2903 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2904 mathDispatchMathDisplay(bv_, argument);
2907 case LFUN_MATH_MODE: // Open or create an inlined math inset
2908 mathDispatchMathMode(bv_, argument);
2911 case LFUN_GREEK: // Insert a single greek letter
2912 mathDispatchGreek(bv_, argument);
2915 case LFUN_CITATION_INSERT:
2917 InsetCommandParams p;
2918 p.setFromString(argument);
2920 InsetCitation * inset = new InsetCitation(p);
2921 if (!insertInset(inset))
2924 updateInset(inset, true);
2928 case LFUN_INSERT_BIBTEX:
2930 // ale970405+lasgoutt970425
2931 // The argument can be up to two tokens separated
2932 // by a space. The first one is the bibstyle.
2933 string const db = token(argument, ' ', 0);
2934 string const bibstyle = token(argument, ' ', 1);
2936 InsetCommandParams p("BibTeX", db, bibstyle);
2937 InsetBibtex * inset = new InsetBibtex(p);
2939 if (insertInset(inset)) {
2940 if (argument.empty())
2947 // BibTeX data bases
2948 case LFUN_BIBDB_ADD:
2950 InsetBibtex * inset =
2951 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2953 inset->addDatabase(argument);
2958 case LFUN_BIBDB_DEL:
2960 InsetBibtex * inset =
2961 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2963 inset->delDatabase(argument);
2968 case LFUN_BIBTEX_STYLE:
2970 InsetBibtex * inset =
2971 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2973 inset->setOptions(argument);
2978 case LFUN_INDEX_INSERT:
2980 string entry = argument;
2981 if (entry.empty()) {
2982 entry = bv_->getLyXText()->getStringToIndex(bv_);
2985 if (entry.empty()) {
2986 owner_->getDialogs()->createIndex();
2990 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
2992 if (!insertInset(inset)) {
2995 updateInset(inset, true);
3000 case LFUN_INDEX_PRINT:
3002 InsetCommandParams p("printindex");
3003 Inset * inset = new InsetPrintIndex(p);
3004 if (!insertInset(inset, tclass.defaultLayoutName()))
3009 case LFUN_PARENTINSERT:
3011 InsetCommandParams p("lyxparent", argument);
3012 Inset * inset = new InsetParent(p, *buffer_);
3013 if (!insertInset(inset, tclass.defaultLayoutName()))
3019 case LFUN_CHILD_INSERT:
3021 InsetInclude::Params p;
3022 p.cparams.setFromString(argument);
3023 p.masterFilename_ = buffer_->fileName();
3025 InsetInclude * inset = new InsetInclude(p);
3026 if (!insertInset(inset))
3029 updateInset(inset, true);
3030 bv_->owner()->getDialogs()->showInclude(inset);
3035 case LFUN_FLOAT_LIST:
3036 if (floatList.typeExist(argument)) {
3037 Inset * inset = new InsetFloatList(argument);
3038 if (!insertInset(inset, tclass.defaultLayoutName()))
3041 lyxerr << "Non-existent float type: "
3042 << argument << endl;
3046 case LFUN_THESAURUS_ENTRY:
3048 string arg = argument;
3051 arg = bv_->getLyXText()->selectionAsString(buffer_,
3055 if (arg.size() > 100 || arg.empty()) {
3056 // Get word or selection
3057 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3058 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3059 // FIXME: where is getLyXText()->unselect(bv_) ?
3063 bv_->owner()->getDialogs()->showThesaurus(arg);
3067 case LFUN_SELFINSERT:
3069 if (argument.empty()) break;
3071 /* Automatically delete the currently selected
3072 * text and replace it with what is being
3073 * typed in now. Depends on lyxrc settings
3074 * "auto_region_delete", which defaults to
3077 LyXText * lt = bv_->getLyXText();
3079 if (lyxrc.auto_region_delete) {
3080 if (lt->selection.set()) {
3081 lt->cutSelection(bv_, false, false);
3084 | BufferView::FITCUR
3085 | BufferView::CHANGE);
3087 workarea().haveSelection(false);
3091 LyXFont const old_font(lt->real_current_font);
3093 string::const_iterator cit = argument.begin();
3094 string::const_iterator end = argument.end();
3095 for (; cit != end; ++cit) {
3096 owner_->getIntl()->getTransManager().
3097 TranslateAndInsert(*cit, lt);
3102 | BufferView::FITCUR
3103 | BufferView::CHANGE);
3105 lt->selection.cursor = lt->cursor;
3106 moveCursorUpdate(false);
3108 // real_current_font.number can change so we need to
3109 // update the minibuffer
3110 if (old_font != lt->real_current_font)
3111 owner_->showState();
3116 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3118 time_t now_time_t = time(NULL);
3119 struct tm * now_tm = localtime(&now_time_t);
3120 setlocale(LC_TIME, "");
3122 if (!argument.empty())
3125 arg = lyxrc.date_insert_format;
3127 int const datetmp_len =
3128 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3130 LyXText * lt = bv_->getLyXText();
3132 for (int i = 0; i < datetmp_len; i++) {
3133 lt->insertChar(bv_, datetmp[i]);
3136 | BufferView::FITCUR
3137 | BufferView::CHANGE);
3140 lt->selection.cursor = lt->cursor;
3141 moveCursorUpdate(false);
3145 case LFUN_UNKNOWN_ACTION:
3146 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3157 void BufferView::Pimpl::newline()
3160 LyXText * lt = bv_->getLyXText();
3164 | BufferView::FITCUR);
3165 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3168 | BufferView::FITCUR
3169 | BufferView::CHANGE);
3174 void BufferView::Pimpl::hfill()
3177 LyXText * lt = bv_->getLyXText();
3181 | BufferView::FITCUR);
3182 lt->insertChar(bv_, Paragraph::META_HFILL);
3185 | BufferView::FITCUR
3186 | BufferView::CHANGE);
3191 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3194 LyXText * lt = bv_->getLyXText();
3197 update(lt, BufferView::SELECT|BufferView::FITCUR);
3198 InsetSpecialChar * new_inset =
3199 new InsetSpecialChar(kind);
3200 if (!insertInset(new_inset))
3203 updateInset(new_inset, true);
3208 void BufferView::Pimpl::smartQuote()
3210 LyXText const * lt = bv_->getLyXText();
3211 Paragraph const * par = lt->cursor.par();
3212 pos_type pos = lt->cursor.pos();
3216 || (par->isInset(pos - 1)
3217 && par->getInset(pos - 1)->isSpace()))
3220 c = par->getChar(pos - 1);
3225 LyXLayout_ptr const & style = par->layout();
3227 if (style->pass_thru ||
3228 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3229 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3233 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3235 if (insertInset(inset))
3242 // Open and lock an updatable inset
3243 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3245 LyXText * lt = bv_->getLyXText();
3249 if (!insertInset(new_inset)) {
3253 new_inset->edit(bv_, !behind);
3258 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3260 // if we are in a locking inset we should try to insert the
3261 // inset there otherwise this is a illegal function now
3262 if (bv_->theLockingInset()) {
3263 if (bv_->theLockingInset()->insetAllowed(inset))
3264 return bv_->theLockingInset()->insertInset(bv_, inset);
3268 // not quite sure if we want this...
3269 setCursorParUndo(bv_);
3272 beforeChange(bv_->text);
3273 if (!lout.empty()) {
3274 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3275 bv_->text->breakParagraph(bv_);
3276 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3278 if (bv_->text->cursor.par()->size()) {
3279 bv_->text->cursorLeft(bv_);
3281 bv_->text->breakParagraph(bv_);
3282 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3286 LyXTextClass const & tclass =
3287 textclasslist[buffer_->params.textclass];
3288 bool hasLayout = tclass.hasLayout(lres);
3289 string lay = tclass.defaultLayoutName();
3291 if (hasLayout != false) {
3295 // layout not fount using default
3296 lay = tclass.defaultLayoutName();
3299 bv_->text->setLayout(bv_, lay);
3301 bv_->text->setParagraph(bv_, 0, 0,
3303 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3308 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3311 bv_->text->insertInset(bv_, inset);
3312 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3319 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3321 if (!inset || !available())
3324 // first check for locking insets
3325 if (bv_->theLockingInset()) {
3326 if (bv_->theLockingInset() == inset) {
3327 if (bv_->text->updateInset(bv_, inset)) {
3330 buffer_->markDirty();
3335 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3336 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3339 buffer_->markDirty();
3347 // then check if the inset is a top_level inset (has no owner)
3348 // if yes do the update as always otherwise we have to update the
3349 // toplevel inset where this inset is inside
3350 Inset * tl_inset = inset;
3351 while(tl_inset->owner())
3352 tl_inset = tl_inset->owner();
3354 if (tl_inset == inset) {
3355 update(bv_->text, BufferView::UPDATE);
3356 if (bv_->text->updateInset(bv_, inset)) {
3360 | BufferView::FITCUR
3361 | BufferView::CHANGE);
3363 update(bv_->text, SELECT);
3367 } else if (static_cast<UpdatableInset *>(tl_inset)
3368 ->updateInsetInInset(bv_, inset))
3370 if (bv_->text->updateInset(bv_, tl_inset)) {
3378 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3381 if (!available()) return;
3384 beforeChange(bv_->text);
3385 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3387 LyXCursor const & cursor = bv_->text->cursor;
3391 cursor.par()->isInset(cursor.pos())) {
3392 Inset const * inset = cursor.par()->getInset(cursor.pos());
3393 if (find(codes.begin(), codes.end(), inset->lyxCode())
3396 static_cast<InsetCommand const *>(inset)->getContents();
3400 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3401 if (bv_->text->cursor.pos()
3402 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3403 LyXCursor tmp = bv_->text->cursor;
3404 bv_->text->cursor.par(bv_->text->ownerParagraph());
3405 bv_->text->cursor.pos(0);
3406 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3407 bv_->text->cursor = tmp;
3408 bv_->owner()->message(_("No more insets"));
3411 bv_->owner()->message(_("No more insets"));
3414 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3415 bv_->text->selection.cursor = bv_->text->cursor;
3419 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3421 gotoInset(vector<Inset::Code>(1, code), same_content);