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 unsigned 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.
930 owner_->updateLayoutChoice();
935 void BufferView::Pimpl::update()
937 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
938 LyXText::text_status st = bv_->text->status();
939 screen().update(bv_->text, bv_);
941 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
942 bv_->text->fullRebreak(bv_);
943 st = LyXText::NEED_MORE_REFRESH;
944 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
945 bv_->text->cursor.pos());
946 if (bv_->text->selection.set()) {
947 bv_->text->setCursor(bv_, bv_->text->selection.start,
948 bv_->text->selection.start.par(),
949 bv_->text->selection.start.pos());
950 bv_->text->setCursor(bv_, bv_->text->selection.end,
951 bv_->text->selection.end.par(),
952 bv_->text->selection.end.pos());
955 bv_->text->status(bv_, st);
956 screen().update(bv_->text, bv_);
958 // do this here instead of in the screen::update because of
960 bv_->text->status(bv_, LyXText::UNCHANGED);
966 // Values used when calling update:
968 // -2 - update, move sel_cursor if selection, fitcursor
969 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
970 // 0 - update, move sel_cursor if selection, fitcursor
971 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
972 // 3 - update, move sel_cursor if selection
975 // a simple redraw of the parts that need refresh
977 // move sel_cursor if selection -
978 // the text's sel_cursor is moved if there is selection is progress
981 // fitCursor() is called and the scrollbar updated
984 // the buffer is marked dirty.
993 // UPDATE_ONLY = UPDATE;
994 // UPDATE_SELECT = UPDATE | SELECT;
995 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
996 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
998 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
999 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1000 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1001 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1002 // update(3) -> update(1) -> update(1) -> update(SELECT)
1004 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1006 owner_->updateLayoutChoice();
1008 if (!text->selection.set() && (f & SELECT)) {
1009 text->selection.cursor = text->cursor;
1012 text->fullRebreak(bv_);
1014 if (text->inset_owner) {
1015 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1016 updateInset(text->inset_owner, false);
1026 buffer_->markDirty();
1031 // Callback for cursor timer
1032 void BufferView::Pimpl::cursorToggle()
1035 cursor_timeout.restart();
1040 extern void reapSpellchecker(void);
1043 if (!bv_->theLockingInset()) {
1044 screen().cursorToggle(bv_);
1046 bv_->theLockingInset()->toggleInsetCursor(bv_);
1049 cursor_timeout.restart();
1053 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1055 if (!text->cursor.row()->previous()) {
1056 if (text->first_y > 0) {
1057 int new_y = bv_->text->first_y - workarea().workHeight();
1058 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1064 int y = text->first_y;
1065 Row * cursorrow = text->cursor.row();
1067 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1071 if (cursorrow == bv_->text->cursor.row()) {
1072 // we have a row which is higher than the workarea so we leave the
1073 // cursor on the start of the row and move only the draw up as soon
1074 // as we move the cursor or do something while inside the row (it may
1075 // span several workarea-heights) we'll move to the top again, but this
1076 // is better than just jump down and only display part of the row.
1077 new_y = bv_->text->first_y - workarea().workHeight();
1079 if (text->inset_owner) {
1080 new_y = bv_->text->cursor.iy()
1081 + bv_->theLockingInset()->insetInInsetY() + y
1082 + text->cursor.row()->height()
1083 - workarea().workHeight() + 1;
1085 new_y = text->cursor.y()
1086 - text->cursor.row()->baseline()
1087 + text->cursor.row()->height()
1088 - workarea().workHeight() + 1;
1091 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1092 if (text->cursor.row()->previous()) {
1094 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1095 text->cursor.row()->previous()->pos(), false);
1096 if (cur.y() > text->first_y) {
1097 text->cursorUp(bv_, true);
1104 void BufferView::Pimpl::cursorNext(LyXText * text)
1106 if (!text->cursor.row()->next()) {
1107 int y = text->cursor.y() - text->cursor.row()->baseline() +
1108 text->cursor.row()->height();
1109 if (y > int(text->first_y + workarea().workHeight())) {
1110 screen().draw(bv_->text, bv_,
1111 bv_->text->first_y + workarea().workHeight());
1117 int y = text->first_y + workarea().workHeight();
1118 if (text->inset_owner && !text->first_y) {
1119 y -= (bv_->text->cursor.iy()
1120 - bv_->text->first_y
1121 + bv_->theLockingInset()->insetInInsetY());
1124 text->getRowNearY(y);
1126 Row * cursorrow = text->cursor.row();
1127 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1131 if (cursorrow == bv_->text->cursor.row()) {
1132 // we have a row which is higher than the workarea so we leave the
1133 // cursor on the start of the row and move only the draw down as soon
1134 // as we move the cursor or do something while inside the row (it may
1135 // span several workarea-heights) we'll move to the top again, but this
1136 // is better than just jump down and only display part of the row.
1137 new_y = bv_->text->first_y + workarea().workHeight();
1139 if (text->inset_owner) {
1140 new_y = bv_->text->cursor.iy()
1141 + bv_->theLockingInset()->insetInInsetY()
1142 + y - text->cursor.row()->baseline();
1144 new_y = text->cursor.y() - text->cursor.row()->baseline();
1147 screen().draw(bv_->text, bv_, new_y);
1148 if (text->cursor.row()->next()) {
1150 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1151 text->cursor.row()->next()->pos(), false);
1152 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1153 text->cursorDown(bv_, true);
1160 bool BufferView::Pimpl::available() const
1162 if (buffer_ && bv_->text)
1168 void BufferView::Pimpl::beforeChange(LyXText * text)
1171 text->clearSelection();
1175 void BufferView::Pimpl::savePosition(unsigned int i)
1177 if (i >= saved_positions_num)
1179 saved_positions[i] = Position(buffer_->fileName(),
1180 bv_->text->cursor.par()->id(),
1181 bv_->text->cursor.pos());
1184 str << _("Saved bookmark") << ' ' << i;
1185 owner_->message(str.str().c_str());
1190 void BufferView::Pimpl::restorePosition(unsigned int i)
1192 if (i >= saved_positions_num)
1195 string const fname = saved_positions[i].filename;
1197 beforeChange(bv_->text);
1199 if (fname != buffer_->fileName()) {
1200 Buffer * b = bufferlist.exists(fname) ?
1201 bufferlist.getBuffer(fname) :
1202 bufferlist.loadLyXFile(fname); // don't ask, just load it
1203 if (b != 0) buffer(b);
1206 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1210 bv_->text->setCursor(bv_, par,
1211 min(par->size(), saved_positions[i].par_pos));
1213 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1216 str << _("Moved to bookmark") << ' ' << i;
1217 owner_->message(str.str().c_str());
1222 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1224 if (i >= saved_positions_num)
1227 return !saved_positions[i].filename.empty();
1231 void BufferView::Pimpl::setState()
1233 if (!lyxrc.rtl_support)
1236 LyXText * text = bv_->getLyXText();
1237 if (text->real_current_font.isRightToLeft()
1238 && !(bv_->theLockingInset()
1239 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1241 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1242 owner_->getIntl()->KeyMapSec();
1244 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1245 owner_->getIntl()->KeyMapPrim();
1250 void BufferView::Pimpl::insetUnlock()
1252 if (bv_->theLockingInset()) {
1253 bv_->theLockingInset()->insetUnlock(bv_);
1254 bv_->theLockingInset(0);
1260 void BufferView::Pimpl::showCursor()
1262 if (bv_->theLockingInset())
1263 bv_->theLockingInset()->showInsetCursor(bv_);
1265 screen().showCursor(bv_->text, bv_);
1269 void BufferView::Pimpl::hideCursor()
1271 if (!bv_->theLockingInset())
1272 screen().hideCursor();
1276 void BufferView::Pimpl::toggleSelection(bool b)
1278 if (bv_->theLockingInset())
1279 bv_->theLockingInset()->toggleSelection(bv_, b);
1280 screen().toggleSelection(bv_->text, bv_, b);
1284 void BufferView::Pimpl::toggleToggle()
1286 screen().toggleToggle(bv_->text, bv_);
1290 void BufferView::Pimpl::center()
1292 beforeChange(bv_->text);
1293 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1294 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1296 screen().draw(bv_->text, bv_, 0);
1298 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1302 void BufferView::Pimpl::pasteClipboard(bool asPara)
1307 screen().hideCursor();
1308 beforeChange(bv_->text);
1310 string const clip(workarea().getClipboard());
1316 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1318 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1320 bv_->getLyXText()->clearSelection();
1321 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1325 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1327 workarea().putClipboard(stuff);
1332 * Dispatch functions for actions which can be valid for BufferView->text
1333 * and/or InsetText->text!!!
1338 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1340 LyXText * lt = bv_->getLyXText();
1342 if (selecting || lt->selection.mark()) {
1343 lt->setSelection(bv_);
1347 updateInset(lt->inset_owner, false);
1351 update(lt, BufferView::SELECT|BufferView::FITCUR);
1353 update(lt, BufferView::SELECT);
1355 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1356 bv_->theLockingInset()->hideInsetCursor(bv_);
1357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1361 if (!lt->selection.set())
1362 workarea().haveSelection(false);
1364 /* ---> Everytime the cursor is moved, show the current font state. */
1365 // should this too me moved out of this func?
1366 //owner->showState();
1371 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1373 LyXCursor cursor = bv_->getLyXText()->cursor;
1374 Buffer::inset_iterator it =
1375 find_if(Buffer::inset_iterator(
1376 cursor.par(), cursor.pos()),
1377 buffer_->inset_iterator_end(),
1378 lyx::compare_memfun(&Inset::lyxCode, code));
1379 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1383 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1385 string filename = filen;
1387 if (filename.empty()) {
1388 // Launch a file browser
1389 string initpath = lyxrc.document_path;
1392 string const trypath = owner_->buffer()->filePath();
1393 // If directory is writeable, use this as default.
1394 if (IsDirWriteable(trypath))
1398 FileDialog fileDlg(bv_->owner(),
1399 _("Select LyX document to insert"),
1401 make_pair(string(_("Documents|#o#O")),
1402 string(lyxrc.document_path)),
1403 make_pair(string(_("Examples|#E#e")),
1404 string(AddPath(system_lyxdir, "examples"))));
1406 FileDialog::Result result =
1407 fileDlg.Select(initpath,
1408 _("*.lyx| LyX Documents (*.lyx)"));
1410 if (result.first == FileDialog::Later)
1413 filename = result.second;
1415 // check selected filename
1416 if (filename.empty()) {
1417 owner_->message(_("Canceled."));
1422 // get absolute path of file and add ".lyx" to the filename if
1424 filename = FileSearch(string(), filename, "lyx");
1426 string const disp_fn(MakeDisplayPath(filename));
1429 s1 << _("Inserting document") << ' '
1430 << disp_fn << " ...";
1431 owner_->message(s1.str().c_str());
1432 bool const res = bv_->insertLyXFile(filename);
1435 str << _("Document") << ' ' << disp_fn
1436 << ' ' << _("inserted.");
1437 owner_->message(str.str().c_str());
1440 str << _("Could not insert document") << ' '
1442 owner_->message(str.str().c_str());
1447 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1449 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1450 << action <<"] arg[" << argument << "]" << endl;
1452 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1455 // --- Misc -------------------------------------------
1459 LyXText * lt = bv_->getLyXText();
1460 lt->toggleAppendix(bv_);
1463 | BufferView::FITCUR
1464 | BufferView::CHANGE);
1469 case LFUN_TOC_INSERT:
1471 InsetCommandParams p;
1472 p.setCmdName("tableofcontents");
1473 Inset * inset = new InsetTOC(p);
1474 if (!insertInset(inset, tclass.defaultLayoutName()))
1479 case LFUN_SCROLL_INSET:
1480 // this is not handled here as this funktion is only aktive
1481 // if we have a locking_inset and that one is (or contains)
1485 case LFUN_INSET_GRAPHICS:
1487 Inset * new_inset = new InsetGraphics;
1488 if (!insertInset(new_inset)) {
1491 // this is need because you don't use a inset->Edit()
1492 updateInset(new_inset, true);
1493 new_inset->edit(bv_);
1503 case LFUN_PASTESELECTION:
1505 bool asPara = false;
1506 if (argument == "paragraph")
1508 pasteClipboard(asPara);
1520 case LFUN_LAYOUT_COPY:
1521 bv_->copyEnvironment();
1524 case LFUN_LAYOUT_PASTE:
1525 bv_->pasteEnvironment();
1529 case LFUN_GOTOERROR:
1530 gotoInset(Inset::ERROR_CODE, false);
1534 gotoInset(Inset::IGNORE_CODE, false);
1537 case LFUN_REFERENCE_GOTO:
1539 vector<Inset::Code> tmp;
1540 tmp.push_back(Inset::LABEL_CODE);
1541 tmp.push_back(Inset::REF_CODE);
1542 gotoInset(tmp, true);
1546 case LFUN_HYPHENATION:
1547 specialChar(InsetSpecialChar::HYPHENATION);
1550 case LFUN_LIGATURE_BREAK:
1551 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1555 specialChar(InsetSpecialChar::LDOTS);
1558 case LFUN_END_OF_SENTENCE:
1559 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1562 case LFUN_MENU_SEPARATOR:
1563 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1570 case LFUN_DEPTH_MIN:
1571 changeDepth(bv_, bv_->getLyXText(), -1);
1574 case LFUN_DEPTH_PLUS:
1575 changeDepth(bv_, bv_->getLyXText(), 1);
1579 owner_->getDialogs()->setUserFreeFont();
1582 case LFUN_FILE_INSERT:
1583 MenuInsertLyXFile(argument);
1586 case LFUN_FILE_INSERT_ASCII_PARA:
1587 InsertAsciiFile(bv_, argument, true);
1590 case LFUN_FILE_INSERT_ASCII:
1591 InsertAsciiFile(bv_, argument, false);
1596 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1597 << argument << endl;
1599 // This is not the good solution to the empty argument
1600 // problem, but it will hopefully suffice for 1.2.0.
1601 // The correct solution would be to augument the
1602 // function list/array with information about what
1603 // functions needs arguments and their type.
1604 if (argument.empty()) {
1605 owner_->getLyXFunc()->setErrorMessage(
1606 _("LyX function 'layout' needs an argument."));
1610 // Derive layout number from given argument (string)
1611 // and current buffer's textclass (number). */
1612 bool hasLayout = tclass.hasLayout(argument);
1613 string layout = argument;
1615 // If the entry is obsolete, use the new one instead.
1617 string const & obs = tclass[layout]->obsoleted_by();
1623 owner_->getLyXFunc()->setErrorMessage(
1624 string(N_("Layout ")) + argument +
1629 bool change_layout = (current_layout != layout);
1630 LyXText * lt = bv_->getLyXText();
1631 if (!change_layout && lt->selection.set() &&
1632 lt->selection.start.par() != lt->selection.end.par())
1634 Paragraph * spar = lt->selection.start.par();
1635 Paragraph * epar = lt->selection.end.par()->next();
1636 while(spar != epar) {
1637 if (spar->layout()->name() != current_layout) {
1638 change_layout = true;
1643 if (change_layout) {
1645 current_layout = layout;
1648 | BufferView::FITCUR);
1649 lt->setLayout(bv_, layout);
1650 owner_->setLayout(layout);
1653 | BufferView::FITCUR
1654 | BufferView::CHANGE);
1661 lang(bv_, argument);
1663 owner_->showState();
1668 owner_->showState();
1673 owner_->showState();
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1698 owner_->showState();
1701 case LFUN_UNDERLINE:
1703 owner_->showState();
1706 case LFUN_FONT_SIZE:
1707 fontSize(bv_, argument);
1708 owner_->showState();
1711 case LFUN_FONT_STATE:
1712 owner_->getLyXFunc()->setMessage(currentState(bv_));
1715 case LFUN_UPCASE_WORD:
1717 LyXText * lt = bv_->getLyXText();
1721 | BufferView::FITCUR);
1722 lt->changeCase(bv_, LyXText::text_uppercase);
1723 if (lt->inset_owner)
1724 updateInset(lt->inset_owner, true);
1727 | BufferView::FITCUR
1728 | BufferView::CHANGE);
1732 case LFUN_LOWCASE_WORD:
1734 LyXText * lt = bv_->getLyXText();
1736 update(lt, BufferView::SELECT|BufferView::FITCUR);
1737 lt->changeCase(bv_, LyXText::text_lowercase);
1738 if (lt->inset_owner)
1739 updateInset(lt->inset_owner, true);
1742 | BufferView::FITCUR
1743 | BufferView::CHANGE);
1747 case LFUN_CAPITALIZE_WORD:
1749 LyXText * lt = bv_->getLyXText();
1751 update(lt, BufferView::SELECT|BufferView::FITCUR);
1752 lt->changeCase(bv_, LyXText::text_capitalization);
1753 if (lt->inset_owner)
1754 updateInset(lt->inset_owner, true);
1757 | BufferView::FITCUR
1758 | BufferView::CHANGE);
1762 case LFUN_TRANSPOSE_CHARS:
1764 LyXText * lt = bv_->getLyXText();
1766 update(lt, BufferView::SELECT|BufferView::FITCUR);
1767 lt->transposeChars(*bv_);
1768 if (lt->inset_owner)
1769 updateInset(lt->inset_owner, true);
1772 | BufferView::FITCUR
1773 | BufferView::CHANGE);
1778 case LFUN_INSERT_LABEL:
1779 MenuInsertLabel(bv_, argument);
1782 case LFUN_REF_INSERT:
1783 if (argument.empty()) {
1784 InsetCommandParams p("ref");
1785 owner_->getDialogs()->createRef(p.getAsString());
1787 InsetCommandParams p;
1788 p.setFromString(argument);
1790 InsetRef * inset = new InsetRef(p, *buffer_);
1791 if (!insertInset(inset))
1794 updateInset(inset, true);
1798 case LFUN_BOOKMARK_SAVE:
1799 savePosition(strToUnsignedInt(argument));
1802 case LFUN_BOOKMARK_GOTO:
1803 restorePosition(strToUnsignedInt(argument));
1808 string label(argument);
1809 if (label.empty()) {
1811 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1813 label = inset->getContents();
1818 if (!label.empty()) {
1819 //bv_->savePosition(0);
1820 if (!bv_->gotoLabel(label))
1821 Alert::alert(_("Error"),
1822 _("Couldn't find this label"),
1823 _("in current document."));
1828 // --- Cursor Movements -----------------------------
1831 LyXText * lt = bv_->getLyXText();
1833 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1834 if (!lt->selection.mark())
1836 update(lt, BufferView::SELECT|BufferView::FITCUR);
1838 lt->cursorLeft(bv_, false);
1839 if (lt->cursor.pos() < lt->cursor.par()->size()
1840 && lt->cursor.par()->isInset(lt->cursor.pos())
1841 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1842 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1843 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1845 tmpinset->edit(bv_, false);
1847 tmpinset->edit(bv_);
1851 lt->cursorRight(bv_, false);
1853 moveCursorUpdate(false);
1854 owner_->showState();
1860 // This is soooo ugly. Isn`t it possible to make
1861 // it simpler? (Lgb)
1862 LyXText * lt = bv_->getLyXText();
1863 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1864 if (!lt->selection.mark())
1866 update(lt, BufferView::SELECT|BufferView::FITCUR);
1867 LyXCursor const cur = lt->cursor;
1869 lt->cursorLeft(bv_, false);
1870 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1871 lt->cursor.pos() < lt->cursor.par()->size() &&
1872 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1873 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1874 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1875 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1877 tmpinset->edit(bv_);
1879 tmpinset->edit(bv_, false);
1883 lt->cursorRight(bv_, false);
1886 moveCursorUpdate(false);
1887 owner_->showState();
1893 LyXText * lt = bv_->getLyXText();
1895 if (!lt->selection.mark())
1897 update(lt, BufferView::UPDATE);
1900 moveCursorUpdate(false);
1901 owner_->showState();
1907 LyXText * lt = bv_->getLyXText();
1909 if (!lt->selection.mark())
1911 update(lt, BufferView::UPDATE);
1912 lt->cursorDown(bv_);
1914 moveCursorUpdate(false);
1915 owner_->showState();
1919 case LFUN_UP_PARAGRAPH:
1921 LyXText * lt = bv_->getLyXText();
1923 if (!lt->selection.mark())
1925 update(lt, BufferView::UPDATE);
1926 lt->cursorUpParagraph(bv_);
1928 moveCursorUpdate(false);
1929 owner_->showState();
1933 case LFUN_DOWN_PARAGRAPH:
1935 LyXText * lt = bv_->getLyXText();
1937 if (!lt->selection.mark())
1939 update(lt, BufferView::UPDATE);
1940 lt->cursorDownParagraph(bv_);
1942 moveCursorUpdate(false);
1943 owner_->showState();
1949 LyXText * lt = bv_->getLyXText();
1951 if (!lt->selection.mark())
1953 update(lt, BufferView::UPDATE);
1956 moveCursorUpdate(false, false);
1957 owner_->showState();
1963 LyXText * lt = bv_->getLyXText();
1965 if (!lt->selection.mark())
1967 update(lt, BufferView::UPDATE);
1970 moveCursorUpdate(false, false);
1971 owner_->showState();
1977 LyXText * lt = bv_->getLyXText();
1979 if (!lt->selection.mark())
1981 update(lt, BufferView::SELECT|BufferView::FITCUR);
1982 lt->cursorHome(bv_);
1984 moveCursorUpdate(false);
1985 owner_->showState();
1991 LyXText * lt = bv_->getLyXText();
1993 if (!lt->selection.mark())
1996 BufferView::SELECT|BufferView::FITCUR);
1999 moveCursorUpdate(false);
2000 owner_->showState();
2004 case LFUN_SHIFT_TAB:
2007 LyXText * lt = bv_->getLyXText();
2009 if (!lt->selection.mark())
2012 BufferView::SELECT|BufferView::FITCUR);
2015 moveCursorUpdate(false);
2016 owner_->showState();
2020 case LFUN_WORDRIGHT:
2022 LyXText * lt = bv_->getLyXText();
2024 if (!lt->selection.mark())
2026 update(lt, BufferView::SELECT|BufferView::FITCUR);
2027 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2028 lt->cursorLeftOneWord(bv_);
2030 lt->cursorRightOneWord(bv_);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2039 LyXText * lt = bv_->getLyXText();
2041 if (!lt->selection.mark())
2043 update(lt, BufferView::SELECT|BufferView::FITCUR);
2044 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2045 lt->cursorRightOneWord(bv_);
2047 lt->cursorLeftOneWord(bv_);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2054 case LFUN_BEGINNINGBUF:
2056 LyXText * lt = bv_->getLyXText();
2058 if (!lt->selection.mark())
2061 BufferView::SELECT|BufferView::FITCUR);
2064 moveCursorUpdate(false);
2065 owner_->showState();
2071 LyXText * lt = bv_->getLyXText();
2073 if (!lt->selection.mark())
2076 BufferView::SELECT|BufferView::FITCUR);
2077 lt->cursorBottom(bv_);
2079 moveCursorUpdate(false);
2080 owner_->showState();
2084 /* cursor selection ---------------------------- */
2087 LyXText * lt = bv_->getLyXText();
2090 BufferView::SELECT|BufferView::FITCUR);
2091 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2092 lt->cursorLeft(bv_);
2094 lt->cursorRight(bv_);
2096 moveCursorUpdate(true);
2097 owner_->showState();
2103 LyXText * lt = bv_->getLyXText();
2106 BufferView::SELECT|BufferView::FITCUR);
2107 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2108 lt->cursorRight(bv_);
2110 lt->cursorLeft(bv_);
2112 moveCursorUpdate(true);
2113 owner_->showState();
2119 LyXText * lt = bv_->getLyXText();
2122 BufferView::SELECT|BufferView::FITCUR);
2123 lt->cursorUp(bv_, true);
2125 moveCursorUpdate(true);
2126 owner_->showState();
2132 LyXText * lt = bv_->getLyXText();
2135 BufferView::SELECT|BufferView::FITCUR);
2136 lt->cursorDown(bv_, true);
2138 moveCursorUpdate(true);
2139 owner_->showState();
2143 case LFUN_UP_PARAGRAPHSEL:
2145 LyXText * lt = bv_->getLyXText();
2148 BufferView::SELECT|BufferView::FITCUR);
2149 lt->cursorUpParagraph(bv_);
2151 moveCursorUpdate(true);
2152 owner_->showState();
2156 case LFUN_DOWN_PARAGRAPHSEL:
2158 LyXText * lt = bv_->getLyXText();
2161 BufferView::SELECT|BufferView::FITCUR);
2162 lt->cursorDownParagraph(bv_);
2164 moveCursorUpdate(true);
2165 owner_->showState();
2171 LyXText * lt = bv_->getLyXText();
2173 update(lt, BufferView::SELECT|BufferView::FITCUR);
2176 moveCursorUpdate(true);
2177 owner_->showState();
2183 LyXText * lt = bv_->getLyXText();
2185 update(lt, BufferView::SELECT|BufferView::FITCUR);
2188 moveCursorUpdate(true);
2189 owner_->showState();
2195 LyXText * lt = bv_->getLyXText();
2197 update(lt, BufferView::SELECT|BufferView::FITCUR);
2198 lt->cursorHome(bv_);
2200 moveCursorUpdate(true);
2201 owner_->showState();
2207 LyXText * lt = bv_->getLyXText();
2209 update(lt, BufferView::SELECT|BufferView::FITCUR);
2212 moveCursorUpdate(true);
2213 owner_->showState();
2217 case LFUN_WORDRIGHTSEL:
2219 LyXText * lt = bv_->getLyXText();
2221 update(lt, BufferView::SELECT|BufferView::FITCUR);
2222 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2223 lt->cursorLeftOneWord(bv_);
2225 lt->cursorRightOneWord(bv_);
2227 moveCursorUpdate(true);
2228 owner_->showState();
2232 case LFUN_WORDLEFTSEL:
2234 LyXText * lt = bv_->getLyXText();
2236 update(lt, BufferView::SELECT|BufferView::FITCUR);
2237 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2238 lt->cursorRightOneWord(bv_);
2240 lt->cursorLeftOneWord(bv_);
2242 moveCursorUpdate(true);
2243 owner_->showState();
2247 case LFUN_BEGINNINGBUFSEL:
2249 LyXText * lt = bv_->getLyXText();
2251 if (lt->inset_owner)
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2256 moveCursorUpdate(true);
2257 owner_->showState();
2261 case LFUN_ENDBUFSEL:
2263 LyXText * lt = bv_->getLyXText();
2265 if (lt->inset_owner)
2268 BufferView::SELECT|BufferView::FITCUR);
2269 lt->cursorBottom(bv_);
2271 moveCursorUpdate(true);
2272 owner_->showState();
2276 // --- text changing commands ------------------------
2277 case LFUN_BREAKLINE:
2279 LyXText * lt = bv_->getLyXText();
2282 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2285 | BufferView::FITCUR
2286 | BufferView::CHANGE);
2287 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2288 moveCursorUpdate(false);
2292 case LFUN_PROTECTEDSPACE:
2294 LyXText * lt = bv_->getLyXText();
2295 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2297 if (style->free_spacing) {
2298 lt->insertChar(bv_, ' ');
2301 | BufferView::FITCUR
2302 | BufferView::CHANGE);
2304 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2306 moveCursorUpdate(false);
2312 LyXText * lt = bv_->getLyXText();
2314 if (lt->selection.mark()) {
2318 | BufferView::FITCUR);
2319 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2322 lt->selection.mark(true);
2325 | BufferView::FITCUR);
2326 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2328 lt->selection.cursor = lt->cursor;
2334 LyXText * lt = bv_->getLyXText();
2336 if (!lt->selection.set()) {
2338 lt->selection.cursor = lt->cursor;
2341 | BufferView::FITCUR
2342 | BufferView::CHANGE);
2343 // It is possible to make it a lot faster still
2344 // just comment out the line below...
2349 moveCursorUpdate(false);
2350 owner_->showState();
2355 case LFUN_DELETE_SKIP:
2357 LyXText * lt = bv_->getLyXText();
2359 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2361 LyXCursor cursor = lt->cursor;
2363 if (!lt->selection.set()) {
2364 if (cursor.pos() == cursor.par()->size()) {
2365 lt->cursorRight(bv_);
2366 cursor = lt->cursor;
2367 if (cursor.pos() == 0
2368 && !(cursor.par()->params().spaceTop()
2369 == VSpace (VSpace::NONE))) {
2372 cursor.par()->params().lineTop(),
2373 cursor.par()->params().lineBottom(),
2374 cursor.par()->params().pagebreakTop(),
2375 cursor.par()->params().pagebreakBottom(),
2376 VSpace(VSpace::NONE),
2377 cursor.par()->params().spaceBottom(),
2378 cursor.par()->params().spacing(),
2379 cursor.par()->params().align(),
2380 cursor.par()->params().labelWidthString(), 0);
2381 lt->cursorLeft(bv_);
2384 | BufferView::FITCUR
2385 | BufferView::CHANGE);
2387 lt->cursorLeft(bv_);
2389 lt->selection.cursor = lt->cursor;
2392 | BufferView::FITCUR
2393 | BufferView::CHANGE);
2397 lt->selection.cursor = lt->cursor;
2400 | BufferView::FITCUR
2401 | BufferView::CHANGE);
2409 /* -------> Delete word forward. */
2410 case LFUN_DELETE_WORD_FORWARD:
2411 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2412 bv_->getLyXText()->deleteWordForward(bv_);
2413 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2414 moveCursorUpdate(false);
2415 owner_->showState();
2418 /* -------> Delete word backward. */
2419 case LFUN_DELETE_WORD_BACKWARD:
2421 LyXText * lt = bv_->getLyXText();
2423 update(lt, BufferView::SELECT|BufferView::FITCUR);
2424 lt->deleteWordBackward(bv_);
2427 | BufferView::FITCUR
2428 | BufferView::CHANGE);
2429 moveCursorUpdate(false);
2430 owner_->showState();
2434 /* -------> Kill to end of line. */
2435 case LFUN_DELETE_LINE_FORWARD:
2437 LyXText * lt = bv_->getLyXText();
2439 update(lt, BufferView::SELECT|BufferView::FITCUR);
2440 lt->deleteLineForward(bv_);
2443 | BufferView::FITCUR
2444 | BufferView::CHANGE);
2445 moveCursorUpdate(false);
2449 /* -------> Set mark off. */
2452 LyXText * lt = bv_->getLyXText();
2455 update(lt, BufferView::SELECT|BufferView::FITCUR);
2456 lt->selection.cursor = lt->cursor;
2457 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2461 /* -------> Set mark on. */
2464 LyXText * lt = bv_->getLyXText();
2467 lt->selection.mark(true);
2468 update(lt, BufferView::SELECT|BufferView::FITCUR);
2469 lt->selection.cursor = lt->cursor;
2470 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2474 case LFUN_BACKSPACE:
2476 LyXText * lt = bv_->getLyXText();
2478 if (!lt->selection.set()) {
2479 if (owner_->getIntl()->getTransManager().backspace()) {
2481 lt->selection.cursor = lt->cursor;
2484 | BufferView::FITCUR
2485 | BufferView::CHANGE);
2486 // It is possible to make it a lot faster still
2487 // just comment out the line below...
2493 owner_->showState();
2498 case LFUN_BACKSPACE_SKIP:
2500 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2501 LyXText * lt = bv_->getLyXText();
2503 LyXCursor cursor = lt->cursor;
2505 if (!lt->selection.set()) {
2506 if (cursor.pos() == 0
2507 && !(cursor.par()->params().spaceTop()
2508 == VSpace (VSpace::NONE))) {
2511 cursor.par()->params().lineTop(),
2512 cursor.par()->params().lineBottom(),
2513 cursor.par()->params().pagebreakTop(),
2514 cursor.par()->params().pagebreakBottom(),
2515 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2516 cursor.par()->params().spacing(),
2517 cursor.par()->params().align(),
2518 cursor.par()->params().labelWidthString(), 0);
2521 | BufferView::FITCUR
2522 | BufferView::CHANGE);
2525 lt->selection.cursor = cursor;
2528 | BufferView::FITCUR
2529 | BufferView::CHANGE);
2536 case LFUN_BREAKPARAGRAPH:
2538 LyXText * lt = bv_->getLyXText();
2541 lt->breakParagraph(bv_, 0);
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2546 lt->selection.cursor = lt->cursor;
2548 owner_->showState();
2552 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2554 LyXText * lt = bv_->getLyXText();
2557 lt->breakParagraph(bv_, 1);
2560 | BufferView::FITCUR
2561 | BufferView::CHANGE);
2562 lt->selection.cursor = lt->cursor;
2564 owner_->showState();
2568 case LFUN_BREAKPARAGRAPH_SKIP:
2570 // When at the beginning of a paragraph, remove
2571 // indentation and add a "defskip" at the top.
2572 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2573 LyXText * lt = bv_->getLyXText();
2575 LyXCursor cursor = lt->cursor;
2578 if (cursor.pos() == 0) {
2579 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2582 cursor.par()->params().lineTop(),
2583 cursor.par()->params().lineBottom(),
2584 cursor.par()->params().pagebreakTop(),
2585 cursor.par()->params().pagebreakBottom(),
2586 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2587 cursor.par()->params().spacing(),
2588 cursor.par()->params().align(),
2589 cursor.par()->params().labelWidthString(), 1);
2590 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2594 lt->breakParagraph(bv_, 0);
2595 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2600 | BufferView::FITCUR
2601 | BufferView::CHANGE);
2602 lt->selection.cursor = cursor;
2604 owner_->showState();
2608 case LFUN_PARAGRAPH_SPACING:
2610 LyXText * lt = bv_->getLyXText();
2612 Paragraph * par = lt->cursor.par();
2613 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2614 float cur_value = 1.0;
2615 if (cur_spacing == Spacing::Other) {
2616 cur_value = par->params().spacing().getValue();
2619 istringstream istr(argument.c_str());
2623 Spacing::Space new_spacing = cur_spacing;
2624 float new_value = cur_value;
2626 lyxerr << "Missing argument to `paragraph-spacing'"
2628 } else if (tmp == "single") {
2629 new_spacing = Spacing::Single;
2630 } else if (tmp == "onehalf") {
2631 new_spacing = Spacing::Onehalf;
2632 } else if (tmp == "double") {
2633 new_spacing = Spacing::Double;
2634 } else if (tmp == "other") {
2635 new_spacing = Spacing::Other;
2638 lyxerr << "new_value = " << tmpval << endl;
2641 } else if (tmp == "default") {
2642 new_spacing = Spacing::Default;
2644 lyxerr << _("Unknown spacing argument: ")
2645 << argument << endl;
2647 if (cur_spacing != new_spacing || cur_value != new_value) {
2648 par->params().spacing(Spacing(new_spacing, new_value));
2649 lt->redoParagraph(bv_);
2652 | BufferView::FITCUR
2653 | BufferView::CHANGE);
2658 case LFUN_INSET_TOGGLE:
2660 LyXText * lt = bv_->getLyXText();
2663 update(lt, BufferView::SELECT|BufferView::FITCUR);
2664 lt->toggleInset(bv_);
2665 update(lt, BufferView::SELECT|BufferView::FITCUR);
2677 InsetCommandParams p;
2678 if (action == LFUN_HTMLURL)
2679 p.setCmdName("htmlurl");
2681 p.setCmdName("url");
2682 owner_->getDialogs()->createUrl(p.getAsString());
2686 case LFUN_INSERT_URL:
2688 InsetCommandParams p;
2689 p.setFromString(argument);
2691 InsetUrl * inset = new InsetUrl(p);
2692 if (!insertInset(inset))
2695 updateInset(inset, true);
2699 case LFUN_INSET_ERT:
2700 insertAndEditInset(new InsetERT(buffer_->params));
2703 case LFUN_INSET_EXTERNAL:
2704 insertAndEditInset(new InsetExternal);
2707 case LFUN_INSET_FOOTNOTE:
2708 insertAndEditInset(new InsetFoot(buffer_->params));
2711 case LFUN_INSET_MARGINAL:
2712 insertAndEditInset(new InsetMarginal(buffer_->params));
2715 case LFUN_INSET_MINIPAGE:
2716 insertAndEditInset(new InsetMinipage(buffer_->params));
2719 case LFUN_INSERT_NOTE:
2720 insertAndEditInset(new InsetNote(buffer_->params));
2723 case LFUN_INSET_FLOAT:
2724 // check if the float type exist
2725 if (floatList.typeExist(argument)) {
2726 insertAndEditInset(new InsetFloat(buffer_->params,
2729 lyxerr << "Non-existent float type: "
2730 << argument << endl;
2734 case LFUN_INSET_WIDE_FLOAT:
2735 // check if the float type exist
2736 if (floatList.typeExist(argument)) {
2737 InsetFloat * new_inset =
2738 new InsetFloat(buffer_->params, argument);
2739 new_inset->wide(true);
2740 insertAndEditInset(new_inset);
2742 lyxerr << "Non-existent float type: "
2743 << argument << endl;
2748 case LFUN_INSET_LIST:
2749 insertAndEditInset(new InsetList);
2752 case LFUN_INSET_THEOREM:
2753 insertAndEditInset(new InsetTheorem);
2757 case LFUN_INSET_CAPTION:
2759 // Do we have a locking inset...
2760 if (bv_->theLockingInset()) {
2761 lyxerr << "Locking inset code: "
2762 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2763 InsetCaption * new_inset =
2764 new InsetCaption(buffer_->params);
2765 new_inset->setOwner(bv_->theLockingInset());
2766 new_inset->setAutoBreakRows(true);
2767 new_inset->setDrawFrame(0, InsetText::LOCKED);
2768 new_inset->setFrameColor(0, LColor::captionframe);
2769 if (insertInset(new_inset))
2770 new_inset->edit(bv_);
2777 case LFUN_INSET_TABULAR:
2781 if (!argument.empty())
2782 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2783 InsetTabular * new_inset =
2784 new InsetTabular(*buffer_, r, c);
2786 bv_->getLyXText()->real_current_font.isRightToLeft();
2787 if (!open_new_inset(new_inset, rtl))
2792 // --- lyxserver commands ----------------------------
2794 case LFUN_CHARATCURSOR:
2796 pos_type pos = bv_->getLyXText()->cursor.pos();
2797 if (pos < bv_->getLyXText()->cursor.par()->size())
2798 owner_->getLyXFunc()->setMessage(
2799 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2801 owner_->getLyXFunc()->setMessage("EOF");
2806 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2808 + tostr(bv_->getLyXText()->cursor.y()));
2815 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2816 lyxerr << "SETXY: Could not parse coordinates in '"
2817 << argument << std::endl;
2819 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2823 case LFUN_GETLAYOUT:
2824 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2829 LyXFont & font = bv_->getLyXText()->current_font;
2830 if (font.shape() == LyXFont::ITALIC_SHAPE)
2831 owner_->getLyXFunc()->setMessage("E");
2832 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2833 owner_->getLyXFunc()->setMessage("N");
2835 owner_->getLyXFunc()->setMessage("0");
2840 // --- accented characters ---------------------------
2843 case LFUN_CIRCUMFLEX:
2853 case LFUN_SPECIAL_CARON:
2856 case LFUN_HUNG_UMLAUT:
2859 if (argument.empty()) {
2861 owner_->getLyXFunc()->handleKeyFunc(action);
2863 owner_->getLyXFunc()->handleKeyFunc(action);
2864 owner_->getIntl()->getTransManager()
2865 .TranslateAndInsert(argument[0], bv_->getLyXText());
2866 update(bv_->getLyXText(),
2868 | BufferView::FITCUR
2869 | BufferView::CHANGE);
2874 mathDispatch(bv_, argument);
2877 case LFUN_MATH_MACRO:
2878 mathDispatchMathMacro(bv_, argument);
2881 case LFUN_MATH_DELIM:
2882 mathDispatchMathDelim(bv_, argument);
2885 case LFUN_INSERT_MATRIX:
2886 mathDispatchInsertMatrix(bv_, argument);
2889 case LFUN_INSERT_MATH:
2890 mathDispatchInsertMath(bv_, argument);
2893 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2894 mathDispatchMathImportSelection(bv_, argument);
2897 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2898 mathDispatchMathDisplay(bv_, argument);
2901 case LFUN_MATH_MODE: // Open or create an inlined math inset
2902 mathDispatchMathMode(bv_, argument);
2905 case LFUN_GREEK: // Insert a single greek letter
2906 mathDispatchGreek(bv_, argument);
2909 case LFUN_CITATION_INSERT:
2911 InsetCommandParams p;
2912 p.setFromString(argument);
2914 InsetCitation * inset = new InsetCitation(p);
2915 if (!insertInset(inset))
2918 updateInset(inset, true);
2922 case LFUN_INSERT_BIBTEX:
2924 // ale970405+lasgoutt970425
2925 // The argument can be up to two tokens separated
2926 // by a space. The first one is the bibstyle.
2927 string const db = token(argument, ' ', 0);
2928 string const bibstyle = token(argument, ' ', 1);
2930 InsetCommandParams p("BibTeX", db, bibstyle);
2931 InsetBibtex * inset = new InsetBibtex(p);
2933 if (insertInset(inset)) {
2934 if (argument.empty())
2941 // BibTeX data bases
2942 case LFUN_BIBDB_ADD:
2944 InsetBibtex * inset =
2945 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2947 inset->addDatabase(argument);
2952 case LFUN_BIBDB_DEL:
2954 InsetBibtex * inset =
2955 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2957 inset->delDatabase(argument);
2962 case LFUN_BIBTEX_STYLE:
2964 InsetBibtex * inset =
2965 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2967 inset->setOptions(argument);
2972 case LFUN_INDEX_INSERT:
2974 string entry = argument;
2975 if (entry.empty()) {
2976 entry = bv_->getLyXText()->getStringToIndex(bv_);
2979 if (entry.empty()) {
2980 owner_->getDialogs()->createIndex();
2984 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
2986 if (!insertInset(inset)) {
2989 updateInset(inset, true);
2994 case LFUN_INDEX_PRINT:
2996 InsetCommandParams p("printindex");
2997 Inset * inset = new InsetPrintIndex(p);
2998 if (!insertInset(inset, tclass.defaultLayoutName()))
3003 case LFUN_PARENTINSERT:
3005 InsetCommandParams p("lyxparent", argument);
3006 Inset * inset = new InsetParent(p, *buffer_);
3007 if (!insertInset(inset, tclass.defaultLayoutName()))
3013 case LFUN_CHILD_INSERT:
3015 InsetInclude::Params p;
3016 p.cparams.setFromString(argument);
3017 p.masterFilename_ = buffer_->fileName();
3019 InsetInclude * inset = new InsetInclude(p);
3020 if (!insertInset(inset))
3023 updateInset(inset, true);
3024 bv_->owner()->getDialogs()->showInclude(inset);
3029 case LFUN_FLOAT_LIST:
3030 if (floatList.typeExist(argument)) {
3031 Inset * inset = new InsetFloatList(argument);
3032 if (!insertInset(inset, tclass.defaultLayoutName()))
3035 lyxerr << "Non-existent float type: "
3036 << argument << endl;
3040 case LFUN_THESAURUS_ENTRY:
3042 string arg = argument;
3045 arg = bv_->getLyXText()->selectionAsString(buffer_,
3049 if (arg.size() > 100 || arg.empty()) {
3050 // Get word or selection
3051 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3052 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3053 // FIXME: where is getLyXText()->unselect(bv_) ?
3057 bv_->owner()->getDialogs()->showThesaurus(arg);
3061 case LFUN_SELFINSERT:
3063 if (argument.empty()) break;
3065 /* Automatically delete the currently selected
3066 * text and replace it with what is being
3067 * typed in now. Depends on lyxrc settings
3068 * "auto_region_delete", which defaults to
3071 LyXText * lt = bv_->getLyXText();
3073 if (lyxrc.auto_region_delete) {
3074 if (lt->selection.set()) {
3075 lt->cutSelection(bv_, false, false);
3078 | BufferView::FITCUR
3079 | BufferView::CHANGE);
3081 workarea().haveSelection(false);
3085 LyXFont const old_font(lt->real_current_font);
3087 string::const_iterator cit = argument.begin();
3088 string::const_iterator end = argument.end();
3089 for (; cit != end; ++cit) {
3090 owner_->getIntl()->getTransManager().
3091 TranslateAndInsert(*cit, lt);
3096 | BufferView::FITCUR
3097 | BufferView::CHANGE);
3099 lt->selection.cursor = lt->cursor;
3100 moveCursorUpdate(false);
3102 // real_current_font.number can change so we need to
3103 // update the minibuffer
3104 if (old_font != lt->real_current_font)
3105 owner_->showState();
3110 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3112 time_t now_time_t = time(NULL);
3113 struct tm * now_tm = localtime(&now_time_t);
3114 setlocale(LC_TIME, "");
3116 if (!argument.empty())
3119 arg = lyxrc.date_insert_format;
3121 int const datetmp_len =
3122 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3124 LyXText * lt = bv_->getLyXText();
3126 for (int i = 0; i < datetmp_len; i++) {
3127 lt->insertChar(bv_, datetmp[i]);
3130 | BufferView::FITCUR
3131 | BufferView::CHANGE);
3134 lt->selection.cursor = lt->cursor;
3135 moveCursorUpdate(false);
3139 case LFUN_UNKNOWN_ACTION:
3140 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3151 void BufferView::Pimpl::newline()
3154 LyXText * lt = bv_->getLyXText();
3158 | BufferView::FITCUR);
3159 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3162 | BufferView::FITCUR
3163 | BufferView::CHANGE);
3168 void BufferView::Pimpl::hfill()
3171 LyXText * lt = bv_->getLyXText();
3175 | BufferView::FITCUR);
3176 lt->insertChar(bv_, Paragraph::META_HFILL);
3179 | BufferView::FITCUR
3180 | BufferView::CHANGE);
3185 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3188 LyXText * lt = bv_->getLyXText();
3191 update(lt, BufferView::SELECT|BufferView::FITCUR);
3192 InsetSpecialChar * new_inset =
3193 new InsetSpecialChar(kind);
3194 if (!insertInset(new_inset))
3197 updateInset(new_inset, true);
3202 void BufferView::Pimpl::smartQuote()
3204 LyXText const * lt = bv_->getLyXText();
3205 Paragraph const * par = lt->cursor.par();
3206 pos_type pos = lt->cursor.pos();
3210 || (par->isInset(pos - 1)
3211 && par->getInset(pos - 1)->isSpace()))
3214 c = par->getChar(pos - 1);
3219 LyXLayout_ptr const & style = par->layout();
3221 if (style->pass_thru ||
3222 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3223 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3227 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3229 if (insertInset(inset))
3236 // Open and lock an updatable inset
3237 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3239 LyXText * lt = bv_->getLyXText();
3243 if (!insertInset(new_inset)) {
3247 new_inset->edit(bv_, !behind);
3252 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3254 // if we are in a locking inset we should try to insert the
3255 // inset there otherwise this is a illegal function now
3256 if (bv_->theLockingInset()) {
3257 if (bv_->theLockingInset()->insetAllowed(inset))
3258 return bv_->theLockingInset()->insertInset(bv_, inset);
3262 // not quite sure if we want this...
3263 setCursorParUndo(bv_);
3266 beforeChange(bv_->text);
3267 if (!lout.empty()) {
3268 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3269 bv_->text->breakParagraph(bv_);
3270 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3272 if (bv_->text->cursor.par()->size()) {
3273 bv_->text->cursorLeft(bv_);
3275 bv_->text->breakParagraph(bv_);
3276 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3280 LyXTextClass const & tclass =
3281 textclasslist[buffer_->params.textclass];
3282 bool hasLayout = tclass.hasLayout(lres);
3283 string lay = tclass.defaultLayoutName();
3285 if (hasLayout != false) {
3289 // layout not fount using default
3290 lay = tclass.defaultLayoutName();
3293 bv_->text->setLayout(bv_, lay);
3295 bv_->text->setParagraph(bv_, 0, 0,
3297 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3302 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3305 bv_->text->insertInset(bv_, inset);
3306 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3313 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3315 if (!inset || !available())
3318 // first check for locking insets
3319 if (bv_->theLockingInset()) {
3320 if (bv_->theLockingInset() == inset) {
3321 if (bv_->text->updateInset(bv_, inset)) {
3324 buffer_->markDirty();
3329 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3330 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3333 buffer_->markDirty();
3341 // then check if the inset is a top_level inset (has no owner)
3342 // if yes do the update as always otherwise we have to update the
3343 // toplevel inset where this inset is inside
3344 Inset * tl_inset = inset;
3345 while(tl_inset->owner())
3346 tl_inset = tl_inset->owner();
3348 if (tl_inset == inset) {
3349 update(bv_->text, BufferView::UPDATE);
3350 if (bv_->text->updateInset(bv_, inset)) {
3354 | BufferView::FITCUR
3355 | BufferView::CHANGE);
3357 update(bv_->text, SELECT);
3361 } else if (static_cast<UpdatableInset *>(tl_inset)
3362 ->updateInsetInInset(bv_, inset))
3364 if (bv_->text->updateInset(bv_, tl_inset)) {
3372 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3375 if (!available()) return;
3378 beforeChange(bv_->text);
3379 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3381 LyXCursor const & cursor = bv_->text->cursor;
3385 cursor.par()->isInset(cursor.pos())) {
3386 Inset const * inset = cursor.par()->getInset(cursor.pos());
3387 if (find(codes.begin(), codes.end(), inset->lyxCode())
3390 static_cast<InsetCommand const *>(inset)->getContents();
3394 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3395 if (bv_->text->cursor.pos()
3396 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3397 LyXCursor tmp = bv_->text->cursor;
3398 bv_->text->cursor.par(bv_->text->ownerParagraph());
3399 bv_->text->cursor.pos(0);
3400 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3401 bv_->text->cursor = tmp;
3402 bv_->owner()->message(_("No more insets"));
3405 bv_->owner()->message(_("No more insets"));
3408 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3409 bv_->text->selection.cursor = bv_->text->cursor;
3413 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3415 gotoInset(vector<Inset::Code>(1, code), same_content);