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 "support/LAssert.h"
74 #include "support/lstrings.h"
75 #include "support/filetools.h"
76 #include "support/lyxfunctional.h"
78 #include <boost/bind.hpp>
87 extern string current_layout;
89 #ifndef CXX_GLOBAL_CSTD
102 using std::make_pair;
106 using lyx::textclass_type;
108 /* the selection possible is needed, that only motion events are
109 * used, where the bottom press event was on the drawing area too */
110 bool selection_possible = false;
112 extern BufferList bufferlist;
113 extern char ascii_type;
115 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
120 const unsigned int saved_positions_num = 20;
126 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
127 int xpos, int ypos, int width, int height)
128 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
129 using_xterm_cursor(false)
131 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
132 screen_.reset(LyXScreenFactory::create(workarea()));
135 workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
136 workarea().workAreaResize
137 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
138 workarea().workAreaButtonPress
139 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
140 workarea().workAreaButtonRelease
141 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
142 workarea().workAreaMotionNotify
143 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
144 workarea().workAreaDoubleClick
145 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
146 workarea().workAreaTripleClick
147 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
148 workarea().workAreaKeyPress
149 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
150 workarea().selectionRequested
151 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
152 workarea().selectionLost
153 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
155 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
156 cursor_timeout.start();
157 saved_positions.resize(saved_positions_num);
161 WorkArea & BufferView::Pimpl::workarea() const
163 return *workarea_.get();
167 LyXScreen & BufferView::Pimpl::screen() const
169 return *screen_.get();
173 Painter & BufferView::Pimpl::painter() const
175 return workarea().getPainter();
179 void BufferView::Pimpl::buffer(Buffer * b)
181 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
184 buffer_->delUser(bv_);
186 // Put the old text into the TextCache, but
187 // only if the buffer is still loaded.
188 // Also set the owner of the test to 0
189 // bv_->text->owner(0);
190 textcache.add(buffer_, workarea().workWidth(), bv_->text);
191 if (lyxerr.debugging())
192 textcache.show(lyxerr, "BufferView::buffer");
197 // Set current buffer
200 if (bufferlist.getState() == BufferList::CLOSING) return;
202 // If we are closing the buffer, use the first buffer as current
204 buffer_ = bufferlist.first();
208 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
209 buffer_->addUser(bv_);
211 // If we don't have a text object for this, we make one
212 if (bv_->text == 0) {
213 resizeCurrentBuffer();
216 // FIXME: needed when ?
217 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
219 // Similarly, buffer-dependent dialogs should be updated or
220 // hidden. This should go here because some dialogs (eg ToC)
221 // require bv_->text.
222 owner_->getDialogs()->updateBufferDependent(true);
224 lyxerr[Debug::INFO] << " No Buffer!" << endl;
225 owner_->getDialogs()->hideBufferDependent();
227 // Also remove all remaining text's from the testcache.
228 // (there should not be any!) (if there is any it is a
230 if (lyxerr.debugging())
231 textcache.show(lyxerr, "buffer delete all");
237 owner_->updateMenubar();
238 owner_->updateToolbar();
239 owner_->updateLayoutChoice();
240 owner_->updateWindowTitle();
244 bool BufferView::Pimpl::fitCursor()
248 if (bv_->theLockingInset()) {
249 bv_->theLockingInset()->fitInsetCursor(bv_);
252 ret = screen().fitCursor(bv_->text, bv_);
255 bv_->owner()->getDialogs()->updateParagraph();
262 void BufferView::Pimpl::redoCurrentBuffer()
264 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
265 if (buffer_ && bv_->text) {
266 resizeCurrentBuffer();
267 owner_->updateLayoutChoice();
272 int BufferView::Pimpl::resizeCurrentBuffer()
274 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
277 Paragraph * selstartpar = 0;
278 Paragraph * selendpar = 0;
279 UpdatableInset * the_locking_inset = 0;
282 pos_type selstartpos = 0;
283 pos_type selendpos = 0;
284 bool selection = false;
285 bool mark_set = false;
287 owner_->prohibitInput();
289 owner_->message(_("Formatting document..."));
292 par = bv_->text->cursor.par();
293 pos = bv_->text->cursor.pos();
294 selstartpar = bv_->text->selection.start.par();
295 selstartpos = bv_->text->selection.start.pos();
296 selendpar = bv_->text->selection.end.par();
297 selendpos = bv_->text->selection.end.pos();
298 selection = bv_->text->selection.set();
299 mark_set = bv_->text->selection.mark();
300 the_locking_inset = bv_->theLockingInset();
301 buffer_->resizeInsets(bv_);
302 // I don't think the delete and new are necessary here we just could
303 // call only init! (Jug 20020419)
305 bv_->text = new LyXText(bv_);
306 bv_->text->init(bv_);
308 // See if we have a text in TextCache that fits
309 // the new buffer_ with the correct width.
310 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
312 if (lyxerr.debugging()) {
313 lyxerr << "Found a LyXText that fits:\n";
314 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
316 // Set the owner of the newly found text
317 // bv_->text->owner(bv_);
318 if (lyxerr.debugging())
319 textcache.show(lyxerr, "resizeCurrentBuffer");
321 bv_->text = new LyXText(bv_);
322 bv_->text->init(bv_);
323 //buffer_->resizeInsets(bv_);
328 bv_->text->selection.set(true);
329 // At this point just to avoid the Delete-Empty-Paragraph-
330 // Mechanism when setting the cursor.
331 bv_->text->selection.mark(mark_set);
333 bv_->text->setCursor(bv_, selstartpar, selstartpos);
334 bv_->text->selection.cursor = bv_->text->cursor;
335 bv_->text->setCursor(bv_, selendpar, selendpos);
336 bv_->text->setSelection(bv_);
337 bv_->text->setCursor(bv_, par, pos);
339 bv_->text->setCursor(bv_, par, pos);
340 bv_->text->selection.cursor = bv_->text->cursor;
341 bv_->text->selection.set(false);
343 // remake the inset locking
344 bv_->theLockingInset(the_locking_inset);
347 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
350 owner_->allowInput();
352 /// clear the "Formatting Document" message
359 void BufferView::Pimpl::repaint()
361 // Regenerate the screen.
362 screen().redraw(bv_->text, bv_);
366 void BufferView::Pimpl::updateScrollbar()
369 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
370 workarea().setScrollbarParams(0, 0, 0);
374 LyXText const & t = *bv_->text;
376 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
380 void BufferView::Pimpl::scrollDocView(int value)
382 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
384 if (!buffer_) return;
386 screen().draw(bv_->text, bv_, value);
388 if (!lyxrc.cursor_follows_scrollbar) {
392 LyXText * vbt = bv_->text;
394 int const height = vbt->defaultHeight();
395 int const first = static_cast<int>((bv_->text->first_y + height));
396 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
398 if (vbt->cursor.y() < first)
399 vbt->setCursorFromCoordinates(bv_, 0, first);
400 else if (vbt->cursor.y() > last)
401 vbt->setCursorFromCoordinates(bv_, 0, last);
405 int BufferView::Pimpl::scroll(long time)
410 LyXText const * t = bv_->text;
412 double const diff = t->defaultHeight()
413 + double(time) * double(time) * 0.125;
415 scrollDocView(int(diff));
416 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
421 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
422 key_modifier::state state)
424 bv_->owner()->getLyXFunc()->processKeySym(key, state);
428 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
430 // Only use motion with button 1
431 if (!(state & mouse_button::button1))
437 // Check for inset locking
438 if (bv_->theLockingInset()) {
439 LyXCursor cursor = bv_->text->cursor;
440 LyXFont font = bv_->text->getFont(buffer_,
441 cursor.par(), cursor.pos());
442 int width = bv_->theLockingInset()->width(bv_, font);
443 int inset_x = font.isVisibleRightToLeft()
444 ? cursor.ix() - width : cursor.ix();
445 int start_x = inset_x + bv_->theLockingInset()->scroll();
447 bv_->theLockingInset()->
448 insetMotionNotify(bv_,
450 y - cursor.iy() + bv_->text->first_y,
455 /* The test for not selection possible is needed, that only motion
456 events are used, where the bottom press event was on
457 the drawing area too */
458 if (!selection_possible)
461 screen().hideCursor();
463 Row * cursorrow = bv_->text->cursor.row();
464 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
466 // sorry for this but I have a strange error that the y value jumps at
467 // a certain point. This seems like an error in my xforms library or
468 // in some other local environment, but I would like to leave this here
469 // for the moment until I can remove this (Jug 20020418)
470 if (y_before < bv_->text->cursor.y())
471 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
473 // This is to allow jumping over large insets
474 if (cursorrow == bv_->text->cursor.row()) {
475 if (y >= int(workarea().workHeight())) {
476 bv_->text->cursorDown(bv_, false);
478 bv_->text->cursorUp(bv_, false);
482 if (!bv_->text->selection.set())
483 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
485 bv_->text->setSelection(bv_);
486 screen().toggleToggle(bv_->text, bv_);
492 // Single-click on work area
493 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
494 mouse_button::state button)
499 // ok ok, this is a hack (for xforms)
500 if (button == mouse_button::button4) {
501 scroll(-lyxrc.wheel_jump);
502 // We shouldn't go further down as we really should only do the
503 // scrolling and be done with this. Otherwise we may open some
504 // dialogs (Jug 20020424).
506 } else if (button == mouse_button::button5) {
507 scroll(lyxrc.wheel_jump);
508 // We shouldn't go further down as we really should only do the
509 // scrolling and be done with this. Otherwise we may open some
510 // dialogs (Jug 20020424).
514 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
516 // Middle button press pastes if we have a selection
517 // We do this here as if the selection was inside an inset
518 // it could get cleared on the unlocking of the inset so
519 // we have to check this first
520 bool paste_internally = false;
521 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
522 owner_->getLyXFunc()->dispatch(LFUN_COPY);
523 paste_internally = true;
526 int const screen_first = bv_->text->first_y;
528 if (bv_->theLockingInset()) {
529 // We are in inset locking mode
531 /* Check whether the inset was hit. If not reset mode,
532 otherwise give the event to the inset */
533 if (inset_hit == bv_->theLockingInset()) {
534 bv_->theLockingInset()->
535 insetButtonPress(bv_, xpos, ypos, button);
538 bv_->unlockInset(bv_->theLockingInset());
543 selection_possible = true;
544 screen().hideCursor();
546 // Clear the selection
547 screen().toggleSelection(bv_->text, bv_);
548 bv_->text->clearSelection();
549 bv_->text->fullRebreak(bv_);
553 // Single left click in math inset?
554 if (isHighlyEditableInset(inset_hit)) {
555 // Highly editable inset, like math
556 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
557 selection_possible = false;
558 owner_->updateLayoutChoice();
559 owner_->message(inset->editMessage());
560 //inset->edit(bv_, xpos, ypos, button);
561 // We just have to lock the inset before calling a PressEvent on it!
562 // we don't need the edit() call here! (Jug20020329)
563 if (!bv_->lockInset(inset)) {
564 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
566 inset->insetButtonPress(bv_, xpos, ypos, button);
569 // I'm not sure we should continue here if we hit an inset (Jug20020403)
571 // Right click on a footnote flag opens float menu
572 if (button == mouse_button::button3) {
573 selection_possible = false;
577 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
578 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
580 bv_->text->selection.cursor = bv_->text->cursor;
581 bv_->text->cursor.x_fix(bv_->text->cursor.x());
583 owner_->updateLayoutChoice();
585 selection_possible = false;
588 // Insert primary selection with middle mouse
589 // if there is a local selection in the current buffer,
591 if (button == mouse_button::button2) {
592 if (paste_internally)
593 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
595 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
597 selection_possible = false;
603 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
608 LyXText * text = bv_->getLyXText();
610 if (text->bv_owner && bv_->theLockingInset())
613 if (button == mouse_button::button1) {
614 if (text->bv_owner) {
615 screen().hideCursor();
616 screen().toggleSelection(text, bv_);
617 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
618 screen().toggleSelection(text, bv_, false);
620 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
622 /* This will fit the cursor on the screen
624 update(text, BufferView::SELECT|BufferView::FITCUR);
629 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
634 LyXText * text = bv_->getLyXText();
636 if (text->bv_owner && bv_->theLockingInset())
639 if (button == mouse_button::button1) {
640 if (text->bv_owner) {
641 screen().hideCursor();
642 screen().toggleSelection(text, bv_);
644 text->cursorHome(bv_);
645 text->selection.cursor = text->cursor;
646 text->cursorEnd(bv_);
647 text->setSelection(bv_);
648 if (text->bv_owner) {
649 screen().toggleSelection(text, bv_, false);
651 /* This will fit the cursor on the screen
653 update(text, BufferView::SELECT|BufferView::FITCUR);
658 void BufferView::Pimpl::selectionRequested()
665 LyXText * text = bv_->getLyXText();
667 if (text->selection.set() &&
668 (!bv_->text->xsel_cache.set() ||
669 text->selection.start != bv_->text->xsel_cache.start ||
670 text->selection.end != bv_->text->xsel_cache.end))
672 bv_->text->xsel_cache = text->selection;
673 sel = text->selectionAsString(bv_->buffer(), false);
674 } else if (!text->selection.set()) {
676 bv_->text->xsel_cache.set(false);
679 workarea().putClipboard(sel);
684 void BufferView::Pimpl::selectionLost()
689 bv_->getLyXText()->clearSelection();
691 bv_->text->xsel_cache.set(false);
696 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
697 mouse_button::state button)
699 // do nothing if we used the mouse wheel
700 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
703 // If we hit an inset, we have the inset coordinates in these
704 // and inset_hit points to the inset. If we do not hit an
705 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
706 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
708 if (bv_->theLockingInset()) {
709 // We are in inset locking mode.
711 /* LyX does a kind of work-area grabbing for insets.
712 Only a ButtonPress Event outside the inset will
713 force a insetUnlock. */
714 bv_->theLockingInset()->
715 insetButtonRelease(bv_, x, y, button);
719 selection_possible = false;
721 if (button == mouse_button::button2)
725 if (button == mouse_button::button1) {
726 workarea().haveSelection(bv_->getLyXText()->selection.set());
731 owner_->updateMenubar();
732 owner_->updateToolbar();
734 // Did we hit an editable inset?
736 selection_possible = false;
738 // if we reach this point with a selection, it
739 // must mean we are currently selecting.
740 // But we don't want to open the inset
741 // because that is annoying for the user.
742 // So just pretend we didn't hit it.
743 // this is OK because a "kosher" ButtonRelease
744 // will follow a ButtonPress that clears
746 // Note this also fixes selection drawing
747 // problems if we end up opening an inset
748 if (bv_->getLyXText()->selection.set())
751 // CHECK fix this proper in 0.13
752 // well, maybe 13.0 !!!!!!!!!
754 // Following a ref shouldn't issue
755 // a push on the undo-stack
756 // anylonger, now that we have
757 // keybindings for following
758 // references and returning from
759 // references. IMHO though, it
760 // should be the inset's own business
761 // to push or not push on the undo
762 // stack. They don't *have* to
763 // alter the document...
765 // ...or maybe the SetCursorParUndo()
766 // below isn't necessary at all anylonger?
767 if (inset_hit->lyxCode() == Inset::REF_CODE) {
768 setCursorParUndo(bv_);
771 owner_->message(inset_hit->editMessage());
773 if (isHighlyEditableInset(inset_hit)) {
774 // Highly editable inset, like math
775 UpdatableInset *inset = (UpdatableInset *)inset_hit;
776 inset->insetButtonRelease(bv_, x, y, button);
778 inset_hit->insetButtonRelease(bv_, x, y, button);
779 // IMO this is a grosshack! Inset's should be changed so that
780 // they call the actions they have to do with the insetButtonRel.
781 // function and not in the edit(). This should be changed
783 inset_hit->edit(bv_, x, y, button);
788 // Maybe we want to edit a bibitem ale970302
789 if (bv_->text->cursor.par()->bibkey && x < 20 +
790 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
791 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
798 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
799 LyXCursor const & cursor) const
801 Paragraph /*const*/ & par = *cursor.par();
802 pos_type const pos = cursor.pos();
804 lyx::Assert(par.getInset(pos));
806 Inset const & inset(*par.getInset(pos));
808 LyXFont const & font = text.getFont(buffer_, &par, pos);
810 int const width = inset.width(bv_, font);
811 int const inset_x = font.isVisibleRightToLeft()
812 ? (cursor.ix() - width) : cursor.ix();
815 inset_x + inset.scroll(),
817 cursor.iy() - inset.ascent(bv_, font),
818 cursor.iy() + inset.descent(bv_, font));
822 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
823 LyXCursor const & cursor,
824 int & x, int & y) const
826 pos_type const pos(cursor.pos());
827 Paragraph /*const*/ & par(*cursor.par());
829 if (pos >= par.size() || !par.isInset(pos)) {
833 Inset /*const*/ * inset = par.getInset(pos);
835 if (!isEditableInset(inset)) {
839 Box b(insetDimensions(text, cursor));
841 if (!b.contained(x, y)) {
842 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
843 << " box " << b << endl;
847 text.setCursor(bv_, &par, pos, true);
850 // The origin of an inset is on the baseline
851 y -= text.cursor.iy();
857 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
859 int y_tmp = y + text->first_y;
862 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
864 Inset * inset(checkInset(*text, cursor, x, y_tmp));
871 // look at previous position
873 if (cursor.pos() == 0) {
878 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
880 inset = checkInset(*text, cursor, x, y_tmp);
888 void BufferView::Pimpl::workAreaResize()
890 static int work_area_width;
891 static int work_area_height;
893 bool const widthChange = workarea().workWidth() != work_area_width;
894 bool const heightChange = workarea().workHeight() != work_area_height;
896 // update from work area
897 work_area_width = workarea().workWidth();
898 work_area_height = workarea().workHeight();
902 // The visible LyXView need a resize
903 resizeCurrentBuffer();
905 // Remove all texts from the textcache
906 // This is not _really_ what we want to do. What
907 // we really want to do is to delete in textcache
908 // that does not have a BufferView with matching
909 // width, but as long as we have only one BufferView
910 // deleting all gives the same result.
911 if (lyxerr.debugging())
912 textcache.show(lyxerr, "Expose delete all");
914 // FIXME: this is aalready done in resizeCurrentBuffer() ??
915 buffer_->resizeInsets(bv_);
916 } else if (heightChange) {
917 // fitCursor() ensures we don't jump back
918 // to the start of the document on vertical
924 if (widthChange || heightChange) {
928 // always make sure that the scrollbar is sane.
931 owner_->updateLayoutChoice();
936 void BufferView::Pimpl::update()
938 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
939 LyXText::text_status st = bv_->text->status();
940 screen().update(bv_->text, bv_);
942 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
943 bv_->text->fullRebreak(bv_);
944 st = LyXText::NEED_MORE_REFRESH;
945 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
946 bv_->text->cursor.pos());
947 if (bv_->text->selection.set()) {
948 bv_->text->setCursor(bv_, bv_->text->selection.start,
949 bv_->text->selection.start.par(),
950 bv_->text->selection.start.pos());
951 bv_->text->setCursor(bv_, bv_->text->selection.end,
952 bv_->text->selection.end.par(),
953 bv_->text->selection.end.pos());
956 bv_->text->status(bv_, st);
957 screen().update(bv_->text, bv_);
959 // do this here instead of in the screen::update because of
961 bv_->text->status(bv_, LyXText::UNCHANGED);
967 // Values used when calling update:
969 // -2 - update, move sel_cursor if selection, fitcursor
970 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
971 // 0 - update, move sel_cursor if selection, fitcursor
972 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
973 // 3 - update, move sel_cursor if selection
976 // a simple redraw of the parts that need refresh
978 // move sel_cursor if selection -
979 // the text's sel_cursor is moved if there is selection is progress
982 // fitCursor() is called and the scrollbar updated
985 // the buffer is marked dirty.
994 // UPDATE_ONLY = UPDATE;
995 // UPDATE_SELECT = UPDATE | SELECT;
996 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
997 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
999 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1000 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1001 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1002 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1003 // update(3) -> update(1) -> update(1) -> update(SELECT)
1005 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1007 owner_->updateLayoutChoice();
1009 if (!text->selection.set() && (f & SELECT)) {
1010 text->selection.cursor = text->cursor;
1013 text->fullRebreak(bv_);
1015 if (text->inset_owner) {
1016 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1017 updateInset(text->inset_owner, false);
1027 buffer_->markDirty();
1032 // Callback for cursor timer
1033 void BufferView::Pimpl::cursorToggle()
1036 cursor_timeout.restart();
1041 extern void reapSpellchecker(void);
1044 if (!bv_->theLockingInset()) {
1045 screen().cursorToggle(bv_);
1047 bv_->theLockingInset()->toggleInsetCursor(bv_);
1050 cursor_timeout.restart();
1054 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1056 if (!text->cursor.row()->previous()) {
1057 if (text->first_y > 0) {
1058 int new_y = bv_->text->first_y - workarea().workHeight();
1059 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1065 int y = text->first_y;
1066 Row * cursorrow = text->cursor.row();
1068 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1072 if (cursorrow == bv_->text->cursor.row()) {
1073 // we have a row which is higher than the workarea so we leave the
1074 // cursor on the start of the row and move only the draw up as soon
1075 // as we move the cursor or do something while inside the row (it may
1076 // span several workarea-heights) we'll move to the top again, but this
1077 // is better than just jump down and only display part of the row.
1078 new_y = bv_->text->first_y - workarea().workHeight();
1080 if (text->inset_owner) {
1081 new_y = bv_->text->cursor.iy()
1082 + bv_->theLockingInset()->insetInInsetY() + y
1083 + text->cursor.row()->height()
1084 - workarea().workHeight() + 1;
1086 new_y = text->cursor.y()
1087 - text->cursor.row()->baseline()
1088 + text->cursor.row()->height()
1089 - workarea().workHeight() + 1;
1092 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1093 if (text->cursor.row()->previous()) {
1095 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1096 text->cursor.row()->previous()->pos(), false);
1097 if (cur.y() > text->first_y) {
1098 text->cursorUp(bv_, true);
1105 void BufferView::Pimpl::cursorNext(LyXText * text)
1107 if (!text->cursor.row()->next()) {
1108 int y = text->cursor.y() - text->cursor.row()->baseline() +
1109 text->cursor.row()->height();
1110 if (y > int(text->first_y + workarea().workHeight())) {
1111 screen().draw(bv_->text, bv_,
1112 bv_->text->first_y + workarea().workHeight());
1118 int y = text->first_y + workarea().workHeight();
1119 if (text->inset_owner && !text->first_y) {
1120 y -= (bv_->text->cursor.iy()
1121 - bv_->text->first_y
1122 + bv_->theLockingInset()->insetInInsetY());
1125 text->getRowNearY(y);
1127 Row * cursorrow = text->cursor.row();
1128 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1132 if (cursorrow == bv_->text->cursor.row()) {
1133 // we have a row which is higher than the workarea so we leave the
1134 // cursor on the start of the row and move only the draw down as soon
1135 // as we move the cursor or do something while inside the row (it may
1136 // span several workarea-heights) we'll move to the top again, but this
1137 // is better than just jump down and only display part of the row.
1138 new_y = bv_->text->first_y + workarea().workHeight();
1140 if (text->inset_owner) {
1141 new_y = bv_->text->cursor.iy()
1142 + bv_->theLockingInset()->insetInInsetY()
1143 + y - text->cursor.row()->baseline();
1145 new_y = text->cursor.y() - text->cursor.row()->baseline();
1148 screen().draw(bv_->text, bv_, new_y);
1149 if (text->cursor.row()->next()) {
1151 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1152 text->cursor.row()->next()->pos(), false);
1153 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1154 text->cursorDown(bv_, true);
1161 bool BufferView::Pimpl::available() const
1163 if (buffer_ && bv_->text)
1169 void BufferView::Pimpl::beforeChange(LyXText * text)
1172 text->clearSelection();
1176 void BufferView::Pimpl::savePosition(unsigned int i)
1178 if (i >= saved_positions_num)
1180 saved_positions[i] = Position(buffer_->fileName(),
1181 bv_->text->cursor.par()->id(),
1182 bv_->text->cursor.pos());
1185 str << _("Saved bookmark") << ' ' << i;
1186 owner_->message(str.str().c_str());
1191 void BufferView::Pimpl::restorePosition(unsigned int i)
1193 if (i >= saved_positions_num)
1196 string const fname = saved_positions[i].filename;
1198 beforeChange(bv_->text);
1200 if (fname != buffer_->fileName()) {
1201 Buffer * b = bufferlist.exists(fname) ?
1202 bufferlist.getBuffer(fname) :
1203 bufferlist.loadLyXFile(fname); // don't ask, just load it
1204 if (b != 0) buffer(b);
1207 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1211 bv_->text->setCursor(bv_, par,
1212 min(par->size(), saved_positions[i].par_pos));
1214 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1217 str << _("Moved to bookmark") << ' ' << i;
1218 owner_->message(str.str().c_str());
1223 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1225 if (i >= saved_positions_num)
1228 return !saved_positions[i].filename.empty();
1232 void BufferView::Pimpl::setState()
1234 if (!lyxrc.rtl_support)
1237 LyXText * text = bv_->getLyXText();
1238 if (text->real_current_font.isRightToLeft()
1239 && !(bv_->theLockingInset()
1240 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1242 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1243 owner_->getIntl()->KeyMapSec();
1245 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1246 owner_->getIntl()->KeyMapPrim();
1251 void BufferView::Pimpl::insetUnlock()
1253 if (bv_->theLockingInset()) {
1254 bv_->theLockingInset()->insetUnlock(bv_);
1255 bv_->theLockingInset(0);
1261 void BufferView::Pimpl::showCursor()
1263 if (bv_->theLockingInset())
1264 bv_->theLockingInset()->showInsetCursor(bv_);
1266 screen().showCursor(bv_->text, bv_);
1270 void BufferView::Pimpl::hideCursor()
1272 if (!bv_->theLockingInset())
1273 screen().hideCursor();
1277 void BufferView::Pimpl::toggleSelection(bool b)
1279 if (bv_->theLockingInset())
1280 bv_->theLockingInset()->toggleSelection(bv_, b);
1281 screen().toggleSelection(bv_->text, bv_, b);
1285 void BufferView::Pimpl::toggleToggle()
1287 screen().toggleToggle(bv_->text, bv_);
1291 void BufferView::Pimpl::center()
1293 beforeChange(bv_->text);
1294 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1295 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1297 screen().draw(bv_->text, bv_, 0);
1299 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1303 void BufferView::Pimpl::pasteClipboard(bool asPara)
1308 screen().hideCursor();
1309 beforeChange(bv_->text);
1311 string const clip(workarea().getClipboard());
1317 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1319 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1321 bv_->getLyXText()->clearSelection();
1322 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1326 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1328 workarea().putClipboard(stuff);
1333 * Dispatch functions for actions which can be valid for BufferView->text
1334 * and/or InsetText->text!!!
1339 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1341 LyXText * lt = bv_->getLyXText();
1343 if (selecting || lt->selection.mark()) {
1344 lt->setSelection(bv_);
1348 updateInset(lt->inset_owner, false);
1352 update(lt, BufferView::SELECT|BufferView::FITCUR);
1354 update(lt, BufferView::SELECT);
1356 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1357 bv_->theLockingInset()->hideInsetCursor(bv_);
1358 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1362 if (!lt->selection.set())
1363 workarea().haveSelection(false);
1365 /* ---> Everytime the cursor is moved, show the current font state. */
1366 // should this too me moved out of this func?
1367 //owner->showState();
1372 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1374 LyXCursor cursor = bv_->getLyXText()->cursor;
1375 Buffer::inset_iterator it =
1376 find_if(Buffer::inset_iterator(
1377 cursor.par(), cursor.pos()),
1378 buffer_->inset_iterator_end(),
1379 lyx::compare_memfun(&Inset::lyxCode, code));
1380 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1384 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1386 string filename = filen;
1388 if (filename.empty()) {
1389 // Launch a file browser
1390 string initpath = lyxrc.document_path;
1393 string const trypath = owner_->buffer()->filePath();
1394 // If directory is writeable, use this as default.
1395 if (IsDirWriteable(trypath))
1399 FileDialog fileDlg(bv_->owner(),
1400 _("Select LyX document to insert"),
1402 make_pair(string(_("Documents|#o#O")),
1403 string(lyxrc.document_path)),
1404 make_pair(string(_("Examples|#E#e")),
1405 string(AddPath(system_lyxdir, "examples"))));
1407 FileDialog::Result result =
1408 fileDlg.Select(initpath,
1409 _("*.lyx| LyX Documents (*.lyx)"));
1411 if (result.first == FileDialog::Later)
1414 filename = result.second;
1416 // check selected filename
1417 if (filename.empty()) {
1418 owner_->message(_("Canceled."));
1423 // get absolute path of file and add ".lyx" to the filename if
1425 filename = FileSearch(string(), filename, "lyx");
1427 string const disp_fn(MakeDisplayPath(filename));
1430 s1 << _("Inserting document") << ' '
1431 << disp_fn << " ...";
1432 owner_->message(s1.str().c_str());
1433 bool const res = bv_->insertLyXFile(filename);
1436 str << _("Document") << ' ' << disp_fn
1437 << ' ' << _("inserted.");
1438 owner_->message(str.str().c_str());
1441 str << _("Could not insert document") << ' '
1443 owner_->message(str.str().c_str());
1448 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1450 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1451 << action <<"] arg[" << argument << "]" << endl;
1453 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1456 // --- Misc -------------------------------------------
1460 LyXText * lt = bv_->getLyXText();
1461 lt->toggleAppendix(bv_);
1464 | BufferView::FITCUR
1465 | BufferView::CHANGE);
1470 case LFUN_TOC_INSERT:
1472 InsetCommandParams p;
1473 p.setCmdName("tableofcontents");
1474 Inset * inset = new InsetTOC(p);
1475 if (!insertInset(inset, tclass.defaultLayoutName()))
1480 case LFUN_SCROLL_INSET:
1481 // this is not handled here as this funktion is only aktive
1482 // if we have a locking_inset and that one is (or contains)
1486 case LFUN_INSET_GRAPHICS:
1488 Inset * new_inset = new InsetGraphics;
1489 if (!insertInset(new_inset)) {
1492 // this is need because you don't use a inset->Edit()
1493 updateInset(new_inset, true);
1494 new_inset->edit(bv_);
1504 case LFUN_PASTESELECTION:
1506 bool asPara = false;
1507 if (argument == "paragraph")
1509 pasteClipboard(asPara);
1521 case LFUN_LAYOUT_COPY:
1522 bv_->copyEnvironment();
1525 case LFUN_LAYOUT_PASTE:
1526 bv_->pasteEnvironment();
1530 case LFUN_GOTOERROR:
1531 gotoInset(Inset::ERROR_CODE, false);
1535 gotoInset(Inset::IGNORE_CODE, false);
1538 case LFUN_REFERENCE_GOTO:
1540 vector<Inset::Code> tmp;
1541 tmp.push_back(Inset::LABEL_CODE);
1542 tmp.push_back(Inset::REF_CODE);
1543 gotoInset(tmp, true);
1547 case LFUN_HYPHENATION:
1548 specialChar(InsetSpecialChar::HYPHENATION);
1551 case LFUN_LIGATURE_BREAK:
1552 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1556 specialChar(InsetSpecialChar::LDOTS);
1559 case LFUN_END_OF_SENTENCE:
1560 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1563 case LFUN_MENU_SEPARATOR:
1564 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1571 case LFUN_DEPTH_MIN:
1572 changeDepth(bv_, bv_->getLyXText(), -1);
1575 case LFUN_DEPTH_PLUS:
1576 changeDepth(bv_, bv_->getLyXText(), 1);
1580 owner_->getDialogs()->setUserFreeFont();
1583 case LFUN_FILE_INSERT:
1584 MenuInsertLyXFile(argument);
1587 case LFUN_FILE_INSERT_ASCII_PARA:
1588 InsertAsciiFile(bv_, argument, true);
1591 case LFUN_FILE_INSERT_ASCII:
1592 InsertAsciiFile(bv_, argument, false);
1597 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1598 << argument << endl;
1600 // This is not the good solution to the empty argument
1601 // problem, but it will hopefully suffice for 1.2.0.
1602 // The correct solution would be to augument the
1603 // function list/array with information about what
1604 // functions needs arguments and their type.
1605 if (argument.empty()) {
1606 owner_->getLyXFunc()->setErrorMessage(
1607 _("LyX function 'layout' needs an argument."));
1611 // Derive layout number from given argument (string)
1612 // and current buffer's textclass (number). */
1613 bool hasLayout = tclass.hasLayout(argument);
1614 string layout = argument;
1616 // If the entry is obsolete, use the new one instead.
1618 string const & obs = tclass[layout]->obsoleted_by();
1624 owner_->getLyXFunc()->setErrorMessage(
1625 string(N_("Layout ")) + argument +
1630 bool change_layout = (current_layout != layout);
1631 LyXText * lt = bv_->getLyXText();
1632 if (!change_layout && lt->selection.set() &&
1633 lt->selection.start.par() != lt->selection.end.par())
1635 Paragraph * spar = lt->selection.start.par();
1636 Paragraph * epar = lt->selection.end.par()->next();
1637 while(spar != epar) {
1638 if (spar->layout()->name() != current_layout) {
1639 change_layout = true;
1644 if (change_layout) {
1646 current_layout = layout;
1649 | BufferView::FITCUR);
1650 lt->setLayout(bv_, layout);
1651 owner_->setLayout(layout);
1654 | BufferView::FITCUR
1655 | BufferView::CHANGE);
1662 lang(bv_, argument);
1664 owner_->showState();
1669 owner_->showState();
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1694 owner_->showState();
1699 owner_->showState();
1702 case LFUN_UNDERLINE:
1704 owner_->showState();
1707 case LFUN_FONT_SIZE:
1708 fontSize(bv_, argument);
1709 owner_->showState();
1712 case LFUN_FONT_STATE:
1713 owner_->getLyXFunc()->setMessage(currentState(bv_));
1716 case LFUN_UPCASE_WORD:
1718 LyXText * lt = bv_->getLyXText();
1722 | BufferView::FITCUR);
1723 lt->changeCase(bv_, LyXText::text_uppercase);
1724 if (lt->inset_owner)
1725 updateInset(lt->inset_owner, true);
1728 | BufferView::FITCUR
1729 | BufferView::CHANGE);
1733 case LFUN_LOWCASE_WORD:
1735 LyXText * lt = bv_->getLyXText();
1737 update(lt, BufferView::SELECT|BufferView::FITCUR);
1738 lt->changeCase(bv_, LyXText::text_lowercase);
1739 if (lt->inset_owner)
1740 updateInset(lt->inset_owner, true);
1743 | BufferView::FITCUR
1744 | BufferView::CHANGE);
1748 case LFUN_CAPITALIZE_WORD:
1750 LyXText * lt = bv_->getLyXText();
1752 update(lt, BufferView::SELECT|BufferView::FITCUR);
1753 lt->changeCase(bv_, LyXText::text_capitalization);
1754 if (lt->inset_owner)
1755 updateInset(lt->inset_owner, true);
1758 | BufferView::FITCUR
1759 | BufferView::CHANGE);
1763 case LFUN_TRANSPOSE_CHARS:
1765 LyXText * lt = bv_->getLyXText();
1767 update(lt, BufferView::SELECT|BufferView::FITCUR);
1768 lt->transposeChars(*bv_);
1769 if (lt->inset_owner)
1770 updateInset(lt->inset_owner, true);
1773 | BufferView::FITCUR
1774 | BufferView::CHANGE);
1779 case LFUN_INSERT_LABEL:
1780 MenuInsertLabel(bv_, argument);
1783 case LFUN_REF_INSERT:
1784 if (argument.empty()) {
1785 InsetCommandParams p("ref");
1786 owner_->getDialogs()->createRef(p.getAsString());
1788 InsetCommandParams p;
1789 p.setFromString(argument);
1791 InsetRef * inset = new InsetRef(p, *buffer_);
1792 if (!insertInset(inset))
1795 updateInset(inset, true);
1799 case LFUN_BOOKMARK_SAVE:
1800 savePosition(strToUnsignedInt(argument));
1803 case LFUN_BOOKMARK_GOTO:
1804 restorePosition(strToUnsignedInt(argument));
1809 string label(argument);
1810 if (label.empty()) {
1812 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1814 label = inset->getContents();
1819 if (!label.empty()) {
1820 //bv_->savePosition(0);
1821 if (!bv_->gotoLabel(label))
1822 Alert::alert(_("Error"),
1823 _("Couldn't find this label"),
1824 _("in current document."));
1829 // --- Cursor Movements -----------------------------
1832 LyXText * lt = bv_->getLyXText();
1834 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1835 if (!lt->selection.mark())
1837 update(lt, BufferView::SELECT|BufferView::FITCUR);
1839 lt->cursorLeft(bv_, false);
1840 if (lt->cursor.pos() < lt->cursor.par()->size()
1841 && lt->cursor.par()->isInset(lt->cursor.pos())
1842 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1843 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1844 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1846 tmpinset->edit(bv_, false);
1848 tmpinset->edit(bv_);
1852 lt->cursorRight(bv_, false);
1854 moveCursorUpdate(false);
1855 owner_->showState();
1861 // This is soooo ugly. Isn`t it possible to make
1862 // it simpler? (Lgb)
1863 LyXText * lt = bv_->getLyXText();
1864 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1865 if (!lt->selection.mark())
1867 update(lt, BufferView::SELECT|BufferView::FITCUR);
1868 LyXCursor const cur = lt->cursor;
1870 lt->cursorLeft(bv_, false);
1871 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1872 lt->cursor.pos() < lt->cursor.par()->size() &&
1873 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1874 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1875 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1876 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1878 tmpinset->edit(bv_);
1880 tmpinset->edit(bv_, false);
1884 lt->cursorRight(bv_, false);
1887 moveCursorUpdate(false);
1888 owner_->showState();
1894 LyXText * lt = bv_->getLyXText();
1896 if (!lt->selection.mark())
1898 update(lt, BufferView::UPDATE);
1901 moveCursorUpdate(false);
1902 owner_->showState();
1908 LyXText * lt = bv_->getLyXText();
1910 if (!lt->selection.mark())
1912 update(lt, BufferView::UPDATE);
1913 lt->cursorDown(bv_);
1915 moveCursorUpdate(false);
1916 owner_->showState();
1920 case LFUN_UP_PARAGRAPH:
1922 LyXText * lt = bv_->getLyXText();
1924 if (!lt->selection.mark())
1926 update(lt, BufferView::UPDATE);
1927 lt->cursorUpParagraph(bv_);
1929 moveCursorUpdate(false);
1930 owner_->showState();
1934 case LFUN_DOWN_PARAGRAPH:
1936 LyXText * lt = bv_->getLyXText();
1938 if (!lt->selection.mark())
1940 update(lt, BufferView::UPDATE);
1941 lt->cursorDownParagraph(bv_);
1943 moveCursorUpdate(false);
1944 owner_->showState();
1950 LyXText * lt = bv_->getLyXText();
1952 if (!lt->selection.mark())
1954 update(lt, BufferView::UPDATE);
1957 moveCursorUpdate(false, false);
1958 owner_->showState();
1964 LyXText * lt = bv_->getLyXText();
1966 if (!lt->selection.mark())
1968 update(lt, BufferView::UPDATE);
1971 moveCursorUpdate(false, false);
1972 owner_->showState();
1978 LyXText * lt = bv_->getLyXText();
1980 if (!lt->selection.mark())
1982 update(lt, BufferView::SELECT|BufferView::FITCUR);
1983 lt->cursorHome(bv_);
1985 moveCursorUpdate(false);
1986 owner_->showState();
1992 LyXText * lt = bv_->getLyXText();
1994 if (!lt->selection.mark())
1997 BufferView::SELECT|BufferView::FITCUR);
2000 moveCursorUpdate(false);
2001 owner_->showState();
2005 case LFUN_SHIFT_TAB:
2008 LyXText * lt = bv_->getLyXText();
2010 if (!lt->selection.mark())
2013 BufferView::SELECT|BufferView::FITCUR);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2021 case LFUN_WORDRIGHT:
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2027 update(lt, BufferView::SELECT|BufferView::FITCUR);
2028 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2029 lt->cursorLeftOneWord(bv_);
2031 lt->cursorRightOneWord(bv_);
2033 moveCursorUpdate(false);
2034 owner_->showState();
2040 LyXText * lt = bv_->getLyXText();
2042 if (!lt->selection.mark())
2044 update(lt, BufferView::SELECT|BufferView::FITCUR);
2045 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2046 lt->cursorRightOneWord(bv_);
2048 lt->cursorLeftOneWord(bv_);
2050 moveCursorUpdate(false);
2051 owner_->showState();
2055 case LFUN_BEGINNINGBUF:
2057 LyXText * lt = bv_->getLyXText();
2059 if (!lt->selection.mark())
2062 BufferView::SELECT|BufferView::FITCUR);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2077 BufferView::SELECT|BufferView::FITCUR);
2078 lt->cursorBottom(bv_);
2080 moveCursorUpdate(false);
2081 owner_->showState();
2085 /* cursor selection ---------------------------- */
2088 LyXText * lt = bv_->getLyXText();
2091 BufferView::SELECT|BufferView::FITCUR);
2092 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2093 lt->cursorLeft(bv_);
2095 lt->cursorRight(bv_);
2097 moveCursorUpdate(true);
2098 owner_->showState();
2104 LyXText * lt = bv_->getLyXText();
2107 BufferView::SELECT|BufferView::FITCUR);
2108 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2109 lt->cursorRight(bv_);
2111 lt->cursorLeft(bv_);
2113 moveCursorUpdate(true);
2114 owner_->showState();
2120 LyXText * lt = bv_->getLyXText();
2123 BufferView::SELECT|BufferView::FITCUR);
2124 lt->cursorUp(bv_, true);
2126 moveCursorUpdate(true);
2127 owner_->showState();
2133 LyXText * lt = bv_->getLyXText();
2136 BufferView::SELECT|BufferView::FITCUR);
2137 lt->cursorDown(bv_, true);
2139 moveCursorUpdate(true);
2140 owner_->showState();
2144 case LFUN_UP_PARAGRAPHSEL:
2146 LyXText * lt = bv_->getLyXText();
2149 BufferView::SELECT|BufferView::FITCUR);
2150 lt->cursorUpParagraph(bv_);
2152 moveCursorUpdate(true);
2153 owner_->showState();
2157 case LFUN_DOWN_PARAGRAPHSEL:
2159 LyXText * lt = bv_->getLyXText();
2162 BufferView::SELECT|BufferView::FITCUR);
2163 lt->cursorDownParagraph(bv_);
2165 moveCursorUpdate(true);
2166 owner_->showState();
2172 LyXText * lt = bv_->getLyXText();
2174 update(lt, BufferView::SELECT|BufferView::FITCUR);
2177 moveCursorUpdate(true);
2178 owner_->showState();
2184 LyXText * lt = bv_->getLyXText();
2186 update(lt, BufferView::SELECT|BufferView::FITCUR);
2189 moveCursorUpdate(true);
2190 owner_->showState();
2196 LyXText * lt = bv_->getLyXText();
2198 update(lt, BufferView::SELECT|BufferView::FITCUR);
2199 lt->cursorHome(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2208 LyXText * lt = bv_->getLyXText();
2210 update(lt, BufferView::SELECT|BufferView::FITCUR);
2213 moveCursorUpdate(true);
2214 owner_->showState();
2218 case LFUN_WORDRIGHTSEL:
2220 LyXText * lt = bv_->getLyXText();
2222 update(lt, BufferView::SELECT|BufferView::FITCUR);
2223 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2224 lt->cursorLeftOneWord(bv_);
2226 lt->cursorRightOneWord(bv_);
2228 moveCursorUpdate(true);
2229 owner_->showState();
2233 case LFUN_WORDLEFTSEL:
2235 LyXText * lt = bv_->getLyXText();
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2239 lt->cursorRightOneWord(bv_);
2241 lt->cursorLeftOneWord(bv_);
2243 moveCursorUpdate(true);
2244 owner_->showState();
2248 case LFUN_BEGINNINGBUFSEL:
2250 LyXText * lt = bv_->getLyXText();
2252 if (lt->inset_owner)
2254 update(lt, BufferView::SELECT|BufferView::FITCUR);
2257 moveCursorUpdate(true);
2258 owner_->showState();
2262 case LFUN_ENDBUFSEL:
2264 LyXText * lt = bv_->getLyXText();
2266 if (lt->inset_owner)
2269 BufferView::SELECT|BufferView::FITCUR);
2270 lt->cursorBottom(bv_);
2272 moveCursorUpdate(true);
2273 owner_->showState();
2277 // --- text changing commands ------------------------
2278 case LFUN_BREAKLINE:
2280 LyXText * lt = bv_->getLyXText();
2283 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2286 | BufferView::FITCUR
2287 | BufferView::CHANGE);
2288 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2289 moveCursorUpdate(false);
2293 case LFUN_PROTECTEDSPACE:
2295 LyXText * lt = bv_->getLyXText();
2296 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2298 if (style->free_spacing) {
2299 lt->insertChar(bv_, ' ');
2302 | BufferView::FITCUR
2303 | BufferView::CHANGE);
2305 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2307 moveCursorUpdate(false);
2313 LyXText * lt = bv_->getLyXText();
2315 if (lt->selection.mark()) {
2319 | BufferView::FITCUR);
2320 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2323 lt->selection.mark(true);
2326 | BufferView::FITCUR);
2327 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2329 lt->selection.cursor = lt->cursor;
2335 LyXText * lt = bv_->getLyXText();
2337 if (!lt->selection.set()) {
2339 lt->selection.cursor = lt->cursor;
2342 | BufferView::FITCUR
2343 | BufferView::CHANGE);
2344 // It is possible to make it a lot faster still
2345 // just comment out the line below...
2350 moveCursorUpdate(false);
2351 owner_->showState();
2356 case LFUN_DELETE_SKIP:
2358 LyXText * lt = bv_->getLyXText();
2360 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2362 LyXCursor cursor = lt->cursor;
2364 if (!lt->selection.set()) {
2365 if (cursor.pos() == cursor.par()->size()) {
2366 lt->cursorRight(bv_);
2367 cursor = lt->cursor;
2368 if (cursor.pos() == 0
2369 && !(cursor.par()->params().spaceTop()
2370 == VSpace (VSpace::NONE))) {
2373 cursor.par()->params().lineTop(),
2374 cursor.par()->params().lineBottom(),
2375 cursor.par()->params().pagebreakTop(),
2376 cursor.par()->params().pagebreakBottom(),
2377 VSpace(VSpace::NONE),
2378 cursor.par()->params().spaceBottom(),
2379 cursor.par()->params().spacing(),
2380 cursor.par()->params().align(),
2381 cursor.par()->params().labelWidthString(), 0);
2382 lt->cursorLeft(bv_);
2385 | BufferView::FITCUR
2386 | BufferView::CHANGE);
2388 lt->cursorLeft(bv_);
2390 lt->selection.cursor = lt->cursor;
2393 | BufferView::FITCUR
2394 | BufferView::CHANGE);
2398 lt->selection.cursor = lt->cursor;
2401 | BufferView::FITCUR
2402 | BufferView::CHANGE);
2410 /* -------> Delete word forward. */
2411 case LFUN_DELETE_WORD_FORWARD:
2412 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2413 bv_->getLyXText()->deleteWordForward(bv_);
2414 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2415 moveCursorUpdate(false);
2416 owner_->showState();
2419 /* -------> Delete word backward. */
2420 case LFUN_DELETE_WORD_BACKWARD:
2422 LyXText * lt = bv_->getLyXText();
2424 update(lt, BufferView::SELECT|BufferView::FITCUR);
2425 lt->deleteWordBackward(bv_);
2428 | BufferView::FITCUR
2429 | BufferView::CHANGE);
2430 moveCursorUpdate(false);
2431 owner_->showState();
2435 /* -------> Kill to end of line. */
2436 case LFUN_DELETE_LINE_FORWARD:
2438 LyXText * lt = bv_->getLyXText();
2440 update(lt, BufferView::SELECT|BufferView::FITCUR);
2441 lt->deleteLineForward(bv_);
2444 | BufferView::FITCUR
2445 | BufferView::CHANGE);
2446 moveCursorUpdate(false);
2450 /* -------> Set mark off. */
2453 LyXText * lt = bv_->getLyXText();
2456 update(lt, BufferView::SELECT|BufferView::FITCUR);
2457 lt->selection.cursor = lt->cursor;
2458 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2462 /* -------> Set mark on. */
2465 LyXText * lt = bv_->getLyXText();
2468 lt->selection.mark(true);
2469 update(lt, BufferView::SELECT|BufferView::FITCUR);
2470 lt->selection.cursor = lt->cursor;
2471 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2475 case LFUN_BACKSPACE:
2477 LyXText * lt = bv_->getLyXText();
2479 if (!lt->selection.set()) {
2480 if (owner_->getIntl()->getTransManager().backspace()) {
2482 lt->selection.cursor = lt->cursor;
2485 | BufferView::FITCUR
2486 | BufferView::CHANGE);
2487 // It is possible to make it a lot faster still
2488 // just comment out the line below...
2494 owner_->showState();
2499 case LFUN_BACKSPACE_SKIP:
2501 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2502 LyXText * lt = bv_->getLyXText();
2504 LyXCursor cursor = lt->cursor;
2506 if (!lt->selection.set()) {
2507 if (cursor.pos() == 0
2508 && !(cursor.par()->params().spaceTop()
2509 == VSpace (VSpace::NONE))) {
2512 cursor.par()->params().lineTop(),
2513 cursor.par()->params().lineBottom(),
2514 cursor.par()->params().pagebreakTop(),
2515 cursor.par()->params().pagebreakBottom(),
2516 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2517 cursor.par()->params().spacing(),
2518 cursor.par()->params().align(),
2519 cursor.par()->params().labelWidthString(), 0);
2522 | BufferView::FITCUR
2523 | BufferView::CHANGE);
2526 lt->selection.cursor = cursor;
2529 | BufferView::FITCUR
2530 | BufferView::CHANGE);
2537 case LFUN_BREAKPARAGRAPH:
2539 LyXText * lt = bv_->getLyXText();
2542 lt->breakParagraph(bv_, 0);
2545 | BufferView::FITCUR
2546 | BufferView::CHANGE);
2547 lt->selection.cursor = lt->cursor;
2549 owner_->showState();
2553 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2555 LyXText * lt = bv_->getLyXText();
2558 lt->breakParagraph(bv_, 1);
2561 | BufferView::FITCUR
2562 | BufferView::CHANGE);
2563 lt->selection.cursor = lt->cursor;
2565 owner_->showState();
2569 case LFUN_BREAKPARAGRAPH_SKIP:
2571 // When at the beginning of a paragraph, remove
2572 // indentation and add a "defskip" at the top.
2573 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2574 LyXText * lt = bv_->getLyXText();
2576 LyXCursor cursor = lt->cursor;
2579 if (cursor.pos() == 0) {
2580 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2583 cursor.par()->params().lineTop(),
2584 cursor.par()->params().lineBottom(),
2585 cursor.par()->params().pagebreakTop(),
2586 cursor.par()->params().pagebreakBottom(),
2587 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2588 cursor.par()->params().spacing(),
2589 cursor.par()->params().align(),
2590 cursor.par()->params().labelWidthString(), 1);
2591 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2595 lt->breakParagraph(bv_, 0);
2596 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2601 | BufferView::FITCUR
2602 | BufferView::CHANGE);
2603 lt->selection.cursor = cursor;
2605 owner_->showState();
2609 case LFUN_PARAGRAPH_SPACING:
2611 LyXText * lt = bv_->getLyXText();
2613 Paragraph * par = lt->cursor.par();
2614 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2615 float cur_value = 1.0;
2616 if (cur_spacing == Spacing::Other) {
2617 cur_value = par->params().spacing().getValue();
2620 istringstream istr(argument.c_str());
2624 Spacing::Space new_spacing = cur_spacing;
2625 float new_value = cur_value;
2627 lyxerr << "Missing argument to `paragraph-spacing'"
2629 } else if (tmp == "single") {
2630 new_spacing = Spacing::Single;
2631 } else if (tmp == "onehalf") {
2632 new_spacing = Spacing::Onehalf;
2633 } else if (tmp == "double") {
2634 new_spacing = Spacing::Double;
2635 } else if (tmp == "other") {
2636 new_spacing = Spacing::Other;
2639 lyxerr << "new_value = " << tmpval << endl;
2642 } else if (tmp == "default") {
2643 new_spacing = Spacing::Default;
2645 lyxerr << _("Unknown spacing argument: ")
2646 << argument << endl;
2648 if (cur_spacing != new_spacing || cur_value != new_value) {
2649 par->params().spacing(Spacing(new_spacing, new_value));
2650 lt->redoParagraph(bv_);
2653 | BufferView::FITCUR
2654 | BufferView::CHANGE);
2659 case LFUN_INSET_TOGGLE:
2661 LyXText * lt = bv_->getLyXText();
2664 update(lt, BufferView::SELECT|BufferView::FITCUR);
2665 lt->toggleInset(bv_);
2666 update(lt, BufferView::SELECT|BufferView::FITCUR);
2678 InsetCommandParams p;
2679 if (action == LFUN_HTMLURL)
2680 p.setCmdName("htmlurl");
2682 p.setCmdName("url");
2683 owner_->getDialogs()->createUrl(p.getAsString());
2687 case LFUN_INSERT_URL:
2689 InsetCommandParams p;
2690 p.setFromString(argument);
2692 InsetUrl * inset = new InsetUrl(p);
2693 if (!insertInset(inset))
2696 updateInset(inset, true);
2700 case LFUN_INSET_ERT:
2701 insertAndEditInset(new InsetERT(buffer_->params));
2704 case LFUN_INSET_EXTERNAL:
2705 insertAndEditInset(new InsetExternal);
2708 case LFUN_INSET_FOOTNOTE:
2709 insertAndEditInset(new InsetFoot(buffer_->params));
2712 case LFUN_INSET_MARGINAL:
2713 insertAndEditInset(new InsetMarginal(buffer_->params));
2716 case LFUN_INSET_MINIPAGE:
2717 insertAndEditInset(new InsetMinipage(buffer_->params));
2720 case LFUN_INSERT_NOTE:
2721 insertAndEditInset(new InsetNote(buffer_->params));
2724 case LFUN_INSET_FLOAT:
2725 // check if the float type exist
2726 if (floatList.typeExist(argument)) {
2727 insertAndEditInset(new InsetFloat(buffer_->params,
2730 lyxerr << "Non-existent float type: "
2731 << argument << endl;
2735 case LFUN_INSET_WIDE_FLOAT:
2736 // check if the float type exist
2737 if (floatList.typeExist(argument)) {
2738 InsetFloat * new_inset =
2739 new InsetFloat(buffer_->params, argument);
2740 new_inset->wide(true);
2741 insertAndEditInset(new_inset);
2743 lyxerr << "Non-existent float type: "
2744 << argument << endl;
2749 case LFUN_INSET_LIST:
2750 insertAndEditInset(new InsetList);
2753 case LFUN_INSET_THEOREM:
2754 insertAndEditInset(new InsetTheorem);
2758 case LFUN_INSET_CAPTION:
2760 // Do we have a locking inset...
2761 if (bv_->theLockingInset()) {
2762 lyxerr << "Locking inset code: "
2763 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2764 InsetCaption * new_inset =
2765 new InsetCaption(buffer_->params);
2766 new_inset->setOwner(bv_->theLockingInset());
2767 new_inset->setAutoBreakRows(true);
2768 new_inset->setDrawFrame(0, InsetText::LOCKED);
2769 new_inset->setFrameColor(0, LColor::captionframe);
2770 if (insertInset(new_inset))
2771 new_inset->edit(bv_);
2778 case LFUN_INSET_TABULAR:
2782 if (!argument.empty())
2783 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2784 InsetTabular * new_inset =
2785 new InsetTabular(*buffer_, r, c);
2787 bv_->getLyXText()->real_current_font.isRightToLeft();
2788 if (!open_new_inset(new_inset, rtl))
2793 // --- lyxserver commands ----------------------------
2795 case LFUN_CHARATCURSOR:
2797 pos_type pos = bv_->getLyXText()->cursor.pos();
2798 if (pos < bv_->getLyXText()->cursor.par()->size())
2799 owner_->getLyXFunc()->setMessage(
2800 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2802 owner_->getLyXFunc()->setMessage("EOF");
2807 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2809 + tostr(bv_->getLyXText()->cursor.y()));
2816 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2817 lyxerr << "SETXY: Could not parse coordinates in '"
2818 << argument << std::endl;
2820 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2824 case LFUN_GETLAYOUT:
2825 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2830 LyXFont & font = bv_->getLyXText()->current_font;
2831 if (font.shape() == LyXFont::ITALIC_SHAPE)
2832 owner_->getLyXFunc()->setMessage("E");
2833 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2834 owner_->getLyXFunc()->setMessage("N");
2836 owner_->getLyXFunc()->setMessage("0");
2841 // --- accented characters ---------------------------
2844 case LFUN_CIRCUMFLEX:
2854 case LFUN_SPECIAL_CARON:
2857 case LFUN_HUNG_UMLAUT:
2860 if (argument.empty()) {
2862 owner_->getLyXFunc()->handleKeyFunc(action);
2864 owner_->getLyXFunc()->handleKeyFunc(action);
2865 owner_->getIntl()->getTransManager()
2866 .TranslateAndInsert(argument[0], bv_->getLyXText());
2867 update(bv_->getLyXText(),
2869 | BufferView::FITCUR
2870 | BufferView::CHANGE);
2875 mathDispatch(bv_, argument);
2878 case LFUN_MATH_MACRO:
2879 mathDispatchMathMacro(bv_, argument);
2882 case LFUN_MATH_DELIM:
2883 mathDispatchMathDelim(bv_, argument);
2886 case LFUN_INSERT_MATRIX:
2887 mathDispatchInsertMatrix(bv_, argument);
2890 case LFUN_INSERT_MATH:
2891 mathDispatchInsertMath(bv_, argument);
2894 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2895 mathDispatchMathImportSelection(bv_, argument);
2898 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2899 mathDispatchMathDisplay(bv_, argument);
2902 case LFUN_MATH_MODE: // Open or create an inlined math inset
2903 mathDispatchMathMode(bv_, argument);
2906 case LFUN_GREEK: // Insert a single greek letter
2907 mathDispatchGreek(bv_, argument);
2910 case LFUN_CITATION_INSERT:
2912 InsetCommandParams p;
2913 p.setFromString(argument);
2915 InsetCitation * inset = new InsetCitation(p);
2916 if (!insertInset(inset))
2919 updateInset(inset, true);
2923 case LFUN_INSERT_BIBTEX:
2925 // ale970405+lasgoutt970425
2926 // The argument can be up to two tokens separated
2927 // by a space. The first one is the bibstyle.
2928 string const db = token(argument, ' ', 0);
2929 string const bibstyle = token(argument, ' ', 1);
2931 InsetCommandParams p("BibTeX", db, bibstyle);
2932 InsetBibtex * inset = new InsetBibtex(p);
2934 if (insertInset(inset)) {
2935 if (argument.empty())
2942 // BibTeX data bases
2943 case LFUN_BIBDB_ADD:
2945 InsetBibtex * inset =
2946 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2948 inset->addDatabase(argument);
2953 case LFUN_BIBDB_DEL:
2955 InsetBibtex * inset =
2956 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2958 inset->delDatabase(argument);
2963 case LFUN_BIBTEX_STYLE:
2965 InsetBibtex * inset =
2966 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2968 inset->setOptions(argument);
2973 case LFUN_INDEX_INSERT:
2975 string entry = argument;
2976 if (entry.empty()) {
2977 entry = bv_->getLyXText()->getStringToIndex(bv_);
2980 if (entry.empty()) {
2981 owner_->getDialogs()->createIndex();
2985 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
2987 if (!insertInset(inset)) {
2990 updateInset(inset, true);
2995 case LFUN_INDEX_PRINT:
2997 InsetCommandParams p("printindex");
2998 Inset * inset = new InsetPrintIndex(p);
2999 if (!insertInset(inset, tclass.defaultLayoutName()))
3004 case LFUN_PARENTINSERT:
3006 InsetCommandParams p("lyxparent", argument);
3007 Inset * inset = new InsetParent(p, *buffer_);
3008 if (!insertInset(inset, tclass.defaultLayoutName()))
3014 case LFUN_CHILD_INSERT:
3016 InsetInclude::Params p;
3017 p.cparams.setFromString(argument);
3018 p.masterFilename_ = buffer_->fileName();
3020 InsetInclude * inset = new InsetInclude(p);
3021 if (!insertInset(inset))
3024 updateInset(inset, true);
3025 bv_->owner()->getDialogs()->showInclude(inset);
3030 case LFUN_FLOAT_LIST:
3031 if (floatList.typeExist(argument)) {
3032 Inset * inset = new InsetFloatList(argument);
3033 if (!insertInset(inset, tclass.defaultLayoutName()))
3036 lyxerr << "Non-existent float type: "
3037 << argument << endl;
3041 case LFUN_THESAURUS_ENTRY:
3043 string arg = argument;
3046 arg = bv_->getLyXText()->selectionAsString(buffer_,
3050 if (arg.size() > 100 || arg.empty()) {
3051 // Get word or selection
3052 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3053 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3054 // FIXME: where is getLyXText()->unselect(bv_) ?
3058 bv_->owner()->getDialogs()->showThesaurus(arg);
3062 case LFUN_SELFINSERT:
3064 if (argument.empty()) break;
3066 /* Automatically delete the currently selected
3067 * text and replace it with what is being
3068 * typed in now. Depends on lyxrc settings
3069 * "auto_region_delete", which defaults to
3072 LyXText * lt = bv_->getLyXText();
3074 if (lyxrc.auto_region_delete) {
3075 if (lt->selection.set()) {
3076 lt->cutSelection(bv_, false, false);
3079 | BufferView::FITCUR
3080 | BufferView::CHANGE);
3082 workarea().haveSelection(false);
3086 LyXFont const old_font(lt->real_current_font);
3088 string::const_iterator cit = argument.begin();
3089 string::const_iterator end = argument.end();
3090 for (; cit != end; ++cit) {
3091 owner_->getIntl()->getTransManager().
3092 TranslateAndInsert(*cit, lt);
3097 | BufferView::FITCUR
3098 | BufferView::CHANGE);
3100 lt->selection.cursor = lt->cursor;
3101 moveCursorUpdate(false);
3103 // real_current_font.number can change so we need to
3104 // update the minibuffer
3105 if (old_font != lt->real_current_font)
3106 owner_->showState();
3111 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3113 time_t now_time_t = time(NULL);
3114 struct tm * now_tm = localtime(&now_time_t);
3115 setlocale(LC_TIME, "");
3117 if (!argument.empty())
3120 arg = lyxrc.date_insert_format;
3122 int const datetmp_len =
3123 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3125 LyXText * lt = bv_->getLyXText();
3127 for (int i = 0; i < datetmp_len; i++) {
3128 lt->insertChar(bv_, datetmp[i]);
3131 | BufferView::FITCUR
3132 | BufferView::CHANGE);
3135 lt->selection.cursor = lt->cursor;
3136 moveCursorUpdate(false);
3140 case LFUN_UNKNOWN_ACTION:
3141 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3152 void BufferView::Pimpl::newline()
3155 LyXText * lt = bv_->getLyXText();
3159 | BufferView::FITCUR);
3160 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3163 | BufferView::FITCUR
3164 | BufferView::CHANGE);
3169 void BufferView::Pimpl::hfill()
3172 LyXText * lt = bv_->getLyXText();
3176 | BufferView::FITCUR);
3177 lt->insertChar(bv_, Paragraph::META_HFILL);
3180 | BufferView::FITCUR
3181 | BufferView::CHANGE);
3186 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3189 LyXText * lt = bv_->getLyXText();
3192 update(lt, BufferView::SELECT|BufferView::FITCUR);
3193 InsetSpecialChar * new_inset =
3194 new InsetSpecialChar(kind);
3195 if (!insertInset(new_inset))
3198 updateInset(new_inset, true);
3203 void BufferView::Pimpl::smartQuote()
3205 LyXText const * lt = bv_->getLyXText();
3206 Paragraph const * par = lt->cursor.par();
3207 pos_type pos = lt->cursor.pos();
3211 || (par->isInset(pos - 1)
3212 && par->getInset(pos - 1)->isSpace()))
3215 c = par->getChar(pos - 1);
3220 LyXLayout_ptr const & style = par->layout();
3222 if (style->pass_thru ||
3223 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3224 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3228 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3230 if (insertInset(inset))
3237 // Open and lock an updatable inset
3238 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3240 LyXText * lt = bv_->getLyXText();
3244 if (!insertInset(new_inset)) {
3248 new_inset->edit(bv_, !behind);
3253 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3255 // if we are in a locking inset we should try to insert the
3256 // inset there otherwise this is a illegal function now
3257 if (bv_->theLockingInset()) {
3258 if (bv_->theLockingInset()->insetAllowed(inset))
3259 return bv_->theLockingInset()->insertInset(bv_, inset);
3263 // not quite sure if we want this...
3264 setCursorParUndo(bv_);
3267 beforeChange(bv_->text);
3268 if (!lout.empty()) {
3269 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3270 bv_->text->breakParagraph(bv_);
3271 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3273 if (bv_->text->cursor.par()->size()) {
3274 bv_->text->cursorLeft(bv_);
3276 bv_->text->breakParagraph(bv_);
3277 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3281 LyXTextClass const & tclass =
3282 textclasslist[buffer_->params.textclass];
3283 bool hasLayout = tclass.hasLayout(lres);
3284 string lay = tclass.defaultLayoutName();
3286 if (hasLayout != false) {
3290 // layout not fount using default
3291 lay = tclass.defaultLayoutName();
3294 bv_->text->setLayout(bv_, lay);
3296 bv_->text->setParagraph(bv_, 0, 0,
3298 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3303 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3306 bv_->text->insertInset(bv_, inset);
3307 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3314 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3316 if (!inset || !available())
3319 // first check for locking insets
3320 if (bv_->theLockingInset()) {
3321 if (bv_->theLockingInset() == inset) {
3322 if (bv_->text->updateInset(bv_, inset)) {
3325 buffer_->markDirty();
3330 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3331 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3334 buffer_->markDirty();
3342 // then check if the inset is a top_level inset (has no owner)
3343 // if yes do the update as always otherwise we have to update the
3344 // toplevel inset where this inset is inside
3345 Inset * tl_inset = inset;
3346 while(tl_inset->owner())
3347 tl_inset = tl_inset->owner();
3349 if (tl_inset == inset) {
3350 update(bv_->text, BufferView::UPDATE);
3351 if (bv_->text->updateInset(bv_, inset)) {
3355 | BufferView::FITCUR
3356 | BufferView::CHANGE);
3358 update(bv_->text, SELECT);
3362 } else if (static_cast<UpdatableInset *>(tl_inset)
3363 ->updateInsetInInset(bv_, inset))
3365 if (bv_->text->updateInset(bv_, tl_inset)) {
3373 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3376 if (!available()) return;
3379 beforeChange(bv_->text);
3380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3382 LyXCursor const & cursor = bv_->text->cursor;
3386 cursor.par()->isInset(cursor.pos())) {
3387 Inset const * inset = cursor.par()->getInset(cursor.pos());
3388 if (find(codes.begin(), codes.end(), inset->lyxCode())
3391 static_cast<InsetCommand const *>(inset)->getContents();
3395 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3396 if (bv_->text->cursor.pos()
3397 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3398 LyXCursor tmp = bv_->text->cursor;
3399 bv_->text->cursor.par(bv_->text->ownerParagraph());
3400 bv_->text->cursor.pos(0);
3401 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3402 bv_->text->cursor = tmp;
3403 bv_->owner()->message(_("No more insets"));
3406 bv_->owner()->message(_("No more insets"));
3409 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3410 bv_->text->selection.cursor = bv_->text->cursor;
3414 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3416 gotoInset(vector<Inset::Code>(1, code), same_content);