2 * \file BufferView_pimpl.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
12 #pragma implementation
15 #include "BufferView_pimpl.h"
16 #include "frontends/WorkArea.h"
17 #include "frontends/screen.h"
18 #include "frontends/LyXScreenFactory.h"
19 #include "frontends/WorkAreaFactory.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/Alert.h"
22 #include "frontends/FileDialog.h"
25 #include "paragraph.h"
26 #include "frontends/LyXView.h"
27 #include "commandtags.h"
30 #include "bufferview_funcs.h"
31 #include "TextCache.h"
32 #include "bufferlist.h"
35 // added for Dispatch functions
38 #include "FloatList.h"
40 #include "ParagraphParameters.h"
41 #include "undo_funcs.h"
42 #include "lyxtextclasslist.h"
44 #include "insets/insetbib.h"
45 #include "insets/insettext.h"
46 #include "insets/inseturl.h"
47 #include "insets/insetlatexaccent.h"
48 #include "insets/insettoc.h"
49 #include "insets/insetref.h"
50 #include "insets/insetparent.h"
51 #include "insets/insetindex.h"
52 #include "insets/insetnote.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetert.h"
56 #include "insets/insetexternal.h"
57 #include "insets/insetgraphics.h"
58 #include "insets/insetfoot.h"
59 #include "insets/insetmarginal.h"
60 #include "insets/insetminipage.h"
61 #include "insets/insetfloat.h"
62 #include "insets/insettabular.h"
64 #include "insets/insettheorem.h"
65 #include "insets/insetlist.h"
67 #include "insets/insetcaption.h"
68 #include "insets/insetfloatlist.h"
69 #include "insets/insetspecialchar.h"
71 #include "mathed/formulabase.h"
73 #include "graphics/Previews.h"
75 #include "support/LAssert.h"
76 #include "support/lstrings.h"
77 #include "support/filetools.h"
78 #include "support/lyxfunctional.h"
80 #include <boost/bind.hpp>
89 extern string current_layout;
91 #ifndef CXX_GLOBAL_CSTD
104 using std::make_pair;
108 using lyx::textclass_type;
110 /* the selection possible is needed, that only motion events are
111 * used, where the bottom press event was on the drawing area too */
112 bool selection_possible = false;
114 extern BufferList bufferlist;
115 extern char ascii_type;
117 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
122 const unsigned int saved_positions_num = 20;
128 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
129 int xpos, int ypos, int width, int height)
130 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
131 using_xterm_cursor(false)
133 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
134 screen_.reset(LyXScreenFactory::create(workarea()));
137 workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
138 workarea().workAreaResize
139 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
140 workarea().workAreaButtonPress
141 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
142 workarea().workAreaButtonRelease
143 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
144 workarea().workAreaMotionNotify
145 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
146 workarea().workAreaDoubleClick
147 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
148 workarea().workAreaTripleClick
149 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
150 workarea().workAreaKeyPress
151 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
152 workarea().selectionRequested
153 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
154 workarea().selectionLost
155 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
157 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
158 cursor_timeout.start();
159 saved_positions.resize(saved_positions_num);
163 WorkArea & BufferView::Pimpl::workarea() const
165 return *workarea_.get();
169 LyXScreen & BufferView::Pimpl::screen() const
171 return *screen_.get();
175 Painter & BufferView::Pimpl::painter() const
177 return workarea().getPainter();
181 void BufferView::Pimpl::buffer(Buffer * b)
183 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
186 buffer_->delUser(bv_);
188 // Put the old text into the TextCache, but
189 // only if the buffer is still loaded.
190 // Also set the owner of the test to 0
191 // bv_->text->owner(0);
192 textcache.add(buffer_, workarea().workWidth(), bv_->text);
193 if (lyxerr.debugging())
194 textcache.show(lyxerr, "BufferView::buffer");
199 // Set current buffer
202 if (bufferlist.getState() == BufferList::CLOSING) return;
204 // If we are closing the buffer, use the first buffer as current
206 buffer_ = bufferlist.first();
210 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
211 buffer_->addUser(bv_);
213 // If we don't have a text object for this, we make one
214 if (bv_->text == 0) {
215 resizeCurrentBuffer();
218 // FIXME: needed when ?
219 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
221 // Similarly, buffer-dependent dialogs should be updated or
222 // hidden. This should go here because some dialogs (eg ToC)
223 // require bv_->text.
224 owner_->getDialogs()->updateBufferDependent(true);
226 lyxerr[Debug::INFO] << " No Buffer!" << endl;
227 owner_->getDialogs()->hideBufferDependent();
229 // Also remove all remaining text's from the testcache.
230 // (there should not be any!) (if there is any it is a
232 if (lyxerr.debugging())
233 textcache.show(lyxerr, "buffer delete all");
239 owner_->updateMenubar();
240 owner_->updateToolbar();
241 owner_->updateLayoutChoice();
242 owner_->updateWindowTitle();
244 if (grfx::Previews::activated() && buffer_)
245 grfx::Previews::get().generateBufferPreviews(buffer_);
249 bool BufferView::Pimpl::fitCursor()
253 if (bv_->theLockingInset()) {
254 bv_->theLockingInset()->fitInsetCursor(bv_);
257 ret = screen().fitCursor(bv_->text, bv_);
260 bv_->owner()->getDialogs()->updateParagraph();
267 void BufferView::Pimpl::redoCurrentBuffer()
269 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
270 if (buffer_ && bv_->text) {
271 resizeCurrentBuffer();
272 owner_->updateLayoutChoice();
277 int BufferView::Pimpl::resizeCurrentBuffer()
279 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
282 Paragraph * selstartpar = 0;
283 Paragraph * selendpar = 0;
284 UpdatableInset * the_locking_inset = 0;
287 pos_type selstartpos = 0;
288 pos_type selendpos = 0;
289 bool selection = false;
290 bool mark_set = false;
292 owner_->prohibitInput();
294 owner_->message(_("Formatting document..."));
297 par = bv_->text->cursor.par();
298 pos = bv_->text->cursor.pos();
299 selstartpar = bv_->text->selection.start.par();
300 selstartpos = bv_->text->selection.start.pos();
301 selendpar = bv_->text->selection.end.par();
302 selendpos = bv_->text->selection.end.pos();
303 selection = bv_->text->selection.set();
304 mark_set = bv_->text->selection.mark();
305 the_locking_inset = bv_->theLockingInset();
306 buffer_->resizeInsets(bv_);
307 // I don't think the delete and new are necessary here we just could
308 // call only init! (Jug 20020419)
310 bv_->text = new LyXText(bv_);
311 bv_->text->init(bv_);
313 // See if we have a text in TextCache that fits
314 // the new buffer_ with the correct width.
315 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
317 if (lyxerr.debugging()) {
318 lyxerr << "Found a LyXText that fits:\n";
319 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
321 // Set the owner of the newly found text
322 // bv_->text->owner(bv_);
323 if (lyxerr.debugging())
324 textcache.show(lyxerr, "resizeCurrentBuffer");
326 bv_->text = new LyXText(bv_);
327 bv_->text->init(bv_);
328 //buffer_->resizeInsets(bv_);
333 bv_->text->selection.set(true);
334 // At this point just to avoid the Delete-Empty-Paragraph-
335 // Mechanism when setting the cursor.
336 bv_->text->selection.mark(mark_set);
338 bv_->text->setCursor(bv_, selstartpar, selstartpos);
339 bv_->text->selection.cursor = bv_->text->cursor;
340 bv_->text->setCursor(bv_, selendpar, selendpos);
341 bv_->text->setSelection(bv_);
342 bv_->text->setCursor(bv_, par, pos);
344 bv_->text->setCursor(bv_, par, pos);
345 bv_->text->selection.cursor = bv_->text->cursor;
346 bv_->text->selection.set(false);
348 // remake the inset locking
349 bv_->theLockingInset(the_locking_inset);
352 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
355 owner_->allowInput();
357 /// clear the "Formatting Document" message
364 void BufferView::Pimpl::repaint()
366 // Regenerate the screen.
367 screen().redraw(bv_->text, bv_);
371 void BufferView::Pimpl::updateScrollbar()
374 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
375 workarea().setScrollbarParams(0, 0, 0);
379 LyXText const & t = *bv_->text;
381 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
382 << t.first_y << ", default height " << t.defaultHeight() << endl;
384 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
388 void BufferView::Pimpl::scrollDocView(int value)
390 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
392 if (!buffer_) return;
394 screen().draw(bv_->text, bv_, value);
396 if (!lyxrc.cursor_follows_scrollbar) {
400 LyXText * vbt = bv_->text;
402 int const height = vbt->defaultHeight();
403 int const first = static_cast<int>((bv_->text->first_y + height));
404 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
406 if (vbt->cursor.y() < first)
407 vbt->setCursorFromCoordinates(bv_, 0, first);
408 else if (vbt->cursor.y() > last)
409 vbt->setCursorFromCoordinates(bv_, 0, last);
413 int BufferView::Pimpl::scroll(long time)
418 LyXText const * t = bv_->text;
420 double const diff = t->defaultHeight()
421 + double(time) * double(time) * 0.125;
423 scrollDocView(int(diff));
424 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
429 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
430 key_modifier::state state)
432 bv_->owner()->getLyXFunc()->processKeySym(key, state);
436 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
438 // Only use motion with button 1
439 if (!(state & mouse_button::button1))
445 // Check for inset locking
446 if (bv_->theLockingInset()) {
447 LyXCursor cursor = bv_->text->cursor;
448 LyXFont font = bv_->text->getFont(buffer_,
449 cursor.par(), cursor.pos());
450 int width = bv_->theLockingInset()->width(bv_, font);
451 int inset_x = font.isVisibleRightToLeft()
452 ? cursor.ix() - width : cursor.ix();
453 int start_x = inset_x + bv_->theLockingInset()->scroll();
455 bv_->theLockingInset()->
456 insetMotionNotify(bv_,
458 y - cursor.iy() + bv_->text->first_y,
463 /* The test for not selection possible is needed, that only motion
464 events are used, where the bottom press event was on
465 the drawing area too */
466 if (!selection_possible)
469 screen().hideCursor();
471 Row * cursorrow = bv_->text->cursor.row();
472 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
474 // sorry for this but I have a strange error that the y value jumps at
475 // a certain point. This seems like an error in my xforms library or
476 // in some other local environment, but I would like to leave this here
477 // for the moment until I can remove this (Jug 20020418)
478 if (y_before < bv_->text->cursor.y())
479 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
481 // This is to allow jumping over large insets
482 if (cursorrow == bv_->text->cursor.row()) {
483 if (y >= int(workarea().workHeight())) {
484 bv_->text->cursorDown(bv_, false);
486 bv_->text->cursorUp(bv_, false);
490 if (!bv_->text->selection.set())
491 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
493 bv_->text->setSelection(bv_);
494 screen().toggleToggle(bv_->text, bv_);
500 // Single-click on work area
501 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
502 mouse_button::state button)
507 // ok ok, this is a hack (for xforms)
508 if (button == mouse_button::button4) {
509 scroll(-lyxrc.wheel_jump);
510 // We shouldn't go further down as we really should only do the
511 // scrolling and be done with this. Otherwise we may open some
512 // dialogs (Jug 20020424).
514 } else if (button == mouse_button::button5) {
515 scroll(lyxrc.wheel_jump);
516 // We shouldn't go further down as we really should only do the
517 // scrolling and be done with this. Otherwise we may open some
518 // dialogs (Jug 20020424).
522 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
524 // Middle button press pastes if we have a selection
525 // We do this here as if the selection was inside an inset
526 // it could get cleared on the unlocking of the inset so
527 // we have to check this first
528 bool paste_internally = false;
529 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
530 owner_->getLyXFunc()->dispatch(LFUN_COPY);
531 paste_internally = true;
534 int const screen_first = bv_->text->first_y;
536 if (bv_->theLockingInset()) {
537 // We are in inset locking mode
539 /* Check whether the inset was hit. If not reset mode,
540 otherwise give the event to the inset */
541 if (inset_hit == bv_->theLockingInset()) {
542 bv_->theLockingInset()->
543 insetButtonPress(bv_, xpos, ypos, button);
546 bv_->unlockInset(bv_->theLockingInset());
551 selection_possible = true;
552 screen().hideCursor();
554 // Clear the selection
555 screen().toggleSelection(bv_->text, bv_);
556 bv_->text->clearSelection();
557 bv_->text->fullRebreak(bv_);
561 // Single left click in math inset?
562 if (isHighlyEditableInset(inset_hit)) {
563 // Highly editable inset, like math
564 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
565 selection_possible = false;
566 owner_->updateLayoutChoice();
567 owner_->message(inset->editMessage());
568 //inset->edit(bv_, xpos, ypos, button);
569 // We just have to lock the inset before calling a PressEvent on it!
570 // we don't need the edit() call here! (Jug20020329)
571 if (!bv_->lockInset(inset)) {
572 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
574 inset->insetButtonPress(bv_, xpos, ypos, button);
577 // I'm not sure we should continue here if we hit an inset (Jug20020403)
579 // Right click on a footnote flag opens float menu
580 if (button == mouse_button::button3) {
581 selection_possible = false;
585 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
586 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
588 bv_->text->selection.cursor = bv_->text->cursor;
589 bv_->text->cursor.x_fix(bv_->text->cursor.x());
591 owner_->updateLayoutChoice();
593 selection_possible = false;
596 // Insert primary selection with middle mouse
597 // if there is a local selection in the current buffer,
599 if (button == mouse_button::button2) {
600 if (paste_internally)
601 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
603 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
605 selection_possible = false;
611 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
616 LyXText * text = bv_->getLyXText();
618 if (text->bv_owner && bv_->theLockingInset())
621 if (button == mouse_button::button1) {
622 if (text->bv_owner) {
623 screen().hideCursor();
624 screen().toggleSelection(text, bv_);
625 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
626 screen().toggleSelection(text, bv_, false);
628 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
630 /* This will fit the cursor on the screen
632 update(text, BufferView::SELECT|BufferView::FITCUR);
637 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
642 LyXText * text = bv_->getLyXText();
644 if (text->bv_owner && bv_->theLockingInset())
647 if (button == mouse_button::button1) {
648 if (text->bv_owner) {
649 screen().hideCursor();
650 screen().toggleSelection(text, bv_);
652 text->cursorHome(bv_);
653 text->selection.cursor = text->cursor;
654 text->cursorEnd(bv_);
655 text->setSelection(bv_);
656 if (text->bv_owner) {
657 screen().toggleSelection(text, bv_, false);
659 /* This will fit the cursor on the screen
661 update(text, BufferView::SELECT|BufferView::FITCUR);
666 void BufferView::Pimpl::selectionRequested()
673 LyXText * text = bv_->getLyXText();
675 if (text->selection.set() &&
676 (!bv_->text->xsel_cache.set() ||
677 text->selection.start != bv_->text->xsel_cache.start ||
678 text->selection.end != bv_->text->xsel_cache.end))
680 bv_->text->xsel_cache = text->selection;
681 sel = text->selectionAsString(bv_->buffer(), false);
682 } else if (!text->selection.set()) {
684 bv_->text->xsel_cache.set(false);
687 workarea().putClipboard(sel);
692 void BufferView::Pimpl::selectionLost()
697 bv_->getLyXText()->clearSelection();
699 bv_->text->xsel_cache.set(false);
704 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
705 mouse_button::state button)
707 // do nothing if we used the mouse wheel
708 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
711 // If we hit an inset, we have the inset coordinates in these
712 // and inset_hit points to the inset. If we do not hit an
713 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
714 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
716 if (bv_->theLockingInset()) {
717 // We are in inset locking mode.
719 /* LyX does a kind of work-area grabbing for insets.
720 Only a ButtonPress Event outside the inset will
721 force a insetUnlock. */
722 bv_->theLockingInset()->
723 insetButtonRelease(bv_, x, y, button);
727 selection_possible = false;
729 if (button == mouse_button::button2)
733 if (button == mouse_button::button1) {
734 workarea().haveSelection(bv_->getLyXText()->selection.set());
739 owner_->updateMenubar();
740 owner_->updateToolbar();
742 // Did we hit an editable inset?
744 selection_possible = false;
746 // if we reach this point with a selection, it
747 // must mean we are currently selecting.
748 // But we don't want to open the inset
749 // because that is annoying for the user.
750 // So just pretend we didn't hit it.
751 // this is OK because a "kosher" ButtonRelease
752 // will follow a ButtonPress that clears
754 // Note this also fixes selection drawing
755 // problems if we end up opening an inset
756 if (bv_->getLyXText()->selection.set())
759 // CHECK fix this proper in 0.13
760 // well, maybe 13.0 !!!!!!!!!
762 // Following a ref shouldn't issue
763 // a push on the undo-stack
764 // anylonger, now that we have
765 // keybindings for following
766 // references and returning from
767 // references. IMHO though, it
768 // should be the inset's own business
769 // to push or not push on the undo
770 // stack. They don't *have* to
771 // alter the document...
773 // ...or maybe the SetCursorParUndo()
774 // below isn't necessary at all anylonger?
775 if (inset_hit->lyxCode() == Inset::REF_CODE) {
776 setCursorParUndo(bv_);
779 owner_->message(inset_hit->editMessage());
781 if (isHighlyEditableInset(inset_hit)) {
782 // Highly editable inset, like math
783 UpdatableInset *inset = (UpdatableInset *)inset_hit;
784 inset->insetButtonRelease(bv_, x, y, button);
786 inset_hit->insetButtonRelease(bv_, x, y, button);
787 // IMO this is a grosshack! Inset's should be changed so that
788 // they call the actions they have to do with the insetButtonRel.
789 // function and not in the edit(). This should be changed
791 inset_hit->edit(bv_, x, y, button);
796 // Maybe we want to edit a bibitem ale970302
797 if (bv_->text->cursor.par()->bibkey && x < 20 +
798 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
799 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
806 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
807 LyXCursor const & cursor) const
809 Paragraph /*const*/ & par = *cursor.par();
810 pos_type const pos = cursor.pos();
812 lyx::Assert(par.getInset(pos));
814 Inset const & inset(*par.getInset(pos));
816 LyXFont const & font = text.getFont(buffer_, &par, pos);
818 int const width = inset.width(bv_, font);
819 int const inset_x = font.isVisibleRightToLeft()
820 ? (cursor.ix() - width) : cursor.ix();
823 inset_x + inset.scroll(),
825 cursor.iy() - inset.ascent(bv_, font),
826 cursor.iy() + inset.descent(bv_, font));
830 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
831 LyXCursor const & cursor,
832 int & x, int & y) const
834 pos_type const pos(cursor.pos());
835 Paragraph /*const*/ & par(*cursor.par());
837 if (pos >= par.size() || !par.isInset(pos)) {
841 Inset /*const*/ * inset = par.getInset(pos);
843 if (!isEditableInset(inset)) {
847 Box b(insetDimensions(text, cursor));
849 if (!b.contained(x, y)) {
850 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
851 << " box " << b << endl;
855 text.setCursor(bv_, &par, pos, true);
858 // The origin of an inset is on the baseline
859 y -= text.cursor.iy();
865 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
867 int y_tmp = y + text->first_y;
870 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
872 Inset * inset(checkInset(*text, cursor, x, y_tmp));
879 // look at previous position
881 if (cursor.pos() == 0) {
886 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
888 inset = checkInset(*text, cursor, x, y_tmp);
896 void BufferView::Pimpl::workAreaResize()
898 static int work_area_width;
899 static int work_area_height;
901 bool const widthChange = workarea().workWidth() != work_area_width;
902 bool const heightChange = workarea().workHeight() != work_area_height;
904 // update from work area
905 work_area_width = workarea().workWidth();
906 work_area_height = workarea().workHeight();
910 // The visible LyXView need a resize
911 resizeCurrentBuffer();
913 // Remove all texts from the textcache
914 // This is not _really_ what we want to do. What
915 // we really want to do is to delete in textcache
916 // that does not have a BufferView with matching
917 // width, but as long as we have only one BufferView
918 // deleting all gives the same result.
919 if (lyxerr.debugging())
920 textcache.show(lyxerr, "Expose delete all");
922 // FIXME: this is aalready done in resizeCurrentBuffer() ??
923 buffer_->resizeInsets(bv_);
924 } else if (heightChange) {
925 // fitCursor() ensures we don't jump back
926 // to the start of the document on vertical
932 // FIXME: GUII temporarily we always repaint for xforms' benefit
933 if (1 || widthChange || heightChange) {
937 // always make sure that the scrollbar is sane.
939 owner_->updateLayoutChoice();
944 void BufferView::Pimpl::update()
946 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
947 LyXText::text_status st = bv_->text->status();
948 screen().update(bv_->text, bv_);
950 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
951 bv_->text->fullRebreak(bv_);
952 st = LyXText::NEED_MORE_REFRESH;
953 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
954 bv_->text->cursor.pos());
955 if (bv_->text->selection.set()) {
956 bv_->text->setCursor(bv_, bv_->text->selection.start,
957 bv_->text->selection.start.par(),
958 bv_->text->selection.start.pos());
959 bv_->text->setCursor(bv_, bv_->text->selection.end,
960 bv_->text->selection.end.par(),
961 bv_->text->selection.end.pos());
964 bv_->text->status(bv_, st);
965 screen().update(bv_->text, bv_);
967 // do this here instead of in the screen::update because of
969 bv_->text->status(bv_, LyXText::UNCHANGED);
975 // Values used when calling update:
977 // -2 - update, move sel_cursor if selection, fitcursor
978 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
979 // 0 - update, move sel_cursor if selection, fitcursor
980 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
981 // 3 - update, move sel_cursor if selection
984 // a simple redraw of the parts that need refresh
986 // move sel_cursor if selection -
987 // the text's sel_cursor is moved if there is selection is progress
990 // fitCursor() is called and the scrollbar updated
993 // the buffer is marked dirty.
1002 // UPDATE_ONLY = UPDATE;
1003 // UPDATE_SELECT = UPDATE | SELECT;
1004 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1005 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1007 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1008 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1009 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1010 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1011 // update(3) -> update(1) -> update(1) -> update(SELECT)
1013 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1015 owner_->updateLayoutChoice();
1017 if (!text->selection.set() && (f & SELECT)) {
1018 text->selection.cursor = text->cursor;
1021 text->fullRebreak(bv_);
1023 if (text->inset_owner) {
1024 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1025 updateInset(text->inset_owner, false);
1035 buffer_->markDirty();
1040 // Callback for cursor timer
1041 void BufferView::Pimpl::cursorToggle()
1044 cursor_timeout.restart();
1049 extern void reapSpellchecker(void);
1052 if (!bv_->theLockingInset()) {
1053 screen().cursorToggle(bv_);
1055 bv_->theLockingInset()->toggleInsetCursor(bv_);
1058 cursor_timeout.restart();
1062 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1064 if (!text->cursor.row()->previous()) {
1065 if (text->first_y > 0) {
1066 int new_y = bv_->text->first_y - workarea().workHeight();
1067 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1073 int y = text->first_y;
1074 Row * cursorrow = text->cursor.row();
1076 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1080 if (cursorrow == bv_->text->cursor.row()) {
1081 // we have a row which is higher than the workarea so we leave the
1082 // cursor on the start of the row and move only the draw up as soon
1083 // as we move the cursor or do something while inside the row (it may
1084 // span several workarea-heights) we'll move to the top again, but this
1085 // is better than just jump down and only display part of the row.
1086 new_y = bv_->text->first_y - workarea().workHeight();
1088 if (text->inset_owner) {
1089 new_y = bv_->text->cursor.iy()
1090 + bv_->theLockingInset()->insetInInsetY() + y
1091 + text->cursor.row()->height()
1092 - workarea().workHeight() + 1;
1094 new_y = text->cursor.y()
1095 - text->cursor.row()->baseline()
1096 + text->cursor.row()->height()
1097 - workarea().workHeight() + 1;
1100 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1101 if (text->cursor.row()->previous()) {
1103 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1104 text->cursor.row()->previous()->pos(), false);
1105 if (cur.y() > text->first_y) {
1106 text->cursorUp(bv_, true);
1113 void BufferView::Pimpl::cursorNext(LyXText * text)
1115 if (!text->cursor.row()->next()) {
1116 int y = text->cursor.y() - text->cursor.row()->baseline() +
1117 text->cursor.row()->height();
1118 if (y > int(text->first_y + workarea().workHeight())) {
1119 screen().draw(bv_->text, bv_,
1120 bv_->text->first_y + workarea().workHeight());
1126 int y = text->first_y + workarea().workHeight();
1127 if (text->inset_owner && !text->first_y) {
1128 y -= (bv_->text->cursor.iy()
1129 - bv_->text->first_y
1130 + bv_->theLockingInset()->insetInInsetY());
1133 text->getRowNearY(y);
1135 Row * cursorrow = text->cursor.row();
1136 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1140 if (cursorrow == bv_->text->cursor.row()) {
1141 // we have a row which is higher than the workarea so we leave the
1142 // cursor on the start of the row and move only the draw down as soon
1143 // as we move the cursor or do something while inside the row (it may
1144 // span several workarea-heights) we'll move to the top again, but this
1145 // is better than just jump down and only display part of the row.
1146 new_y = bv_->text->first_y + workarea().workHeight();
1148 if (text->inset_owner) {
1149 new_y = bv_->text->cursor.iy()
1150 + bv_->theLockingInset()->insetInInsetY()
1151 + y - text->cursor.row()->baseline();
1153 new_y = text->cursor.y() - text->cursor.row()->baseline();
1156 screen().draw(bv_->text, bv_, new_y);
1157 if (text->cursor.row()->next()) {
1159 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1160 text->cursor.row()->next()->pos(), false);
1161 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1162 text->cursorDown(bv_, true);
1169 bool BufferView::Pimpl::available() const
1171 if (buffer_ && bv_->text)
1177 void BufferView::Pimpl::beforeChange(LyXText * text)
1180 text->clearSelection();
1184 void BufferView::Pimpl::savePosition(unsigned int i)
1186 if (i >= saved_positions_num)
1188 saved_positions[i] = Position(buffer_->fileName(),
1189 bv_->text->cursor.par()->id(),
1190 bv_->text->cursor.pos());
1193 str << _("Saved bookmark") << ' ' << i;
1194 owner_->message(str.str().c_str());
1199 void BufferView::Pimpl::restorePosition(unsigned int i)
1201 if (i >= saved_positions_num)
1204 string const fname = saved_positions[i].filename;
1206 beforeChange(bv_->text);
1208 if (fname != buffer_->fileName()) {
1209 Buffer * b = bufferlist.exists(fname) ?
1210 bufferlist.getBuffer(fname) :
1211 bufferlist.loadLyXFile(fname); // don't ask, just load it
1212 if (b != 0) buffer(b);
1215 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1219 bv_->text->setCursor(bv_, par,
1220 min(par->size(), saved_positions[i].par_pos));
1222 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1225 str << _("Moved to bookmark") << ' ' << i;
1226 owner_->message(str.str().c_str());
1231 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1233 if (i >= saved_positions_num)
1236 return !saved_positions[i].filename.empty();
1240 void BufferView::Pimpl::setState()
1242 if (!lyxrc.rtl_support)
1245 LyXText * text = bv_->getLyXText();
1246 if (text->real_current_font.isRightToLeft()
1247 && !(bv_->theLockingInset()
1248 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1250 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1251 owner_->getIntl()->KeyMapSec();
1253 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1254 owner_->getIntl()->KeyMapPrim();
1259 void BufferView::Pimpl::insetUnlock()
1261 if (bv_->theLockingInset()) {
1262 bv_->theLockingInset()->insetUnlock(bv_);
1263 bv_->theLockingInset(0);
1269 void BufferView::Pimpl::showCursor()
1271 if (bv_->theLockingInset())
1272 bv_->theLockingInset()->showInsetCursor(bv_);
1274 screen().showCursor(bv_->text, bv_);
1278 void BufferView::Pimpl::hideCursor()
1280 if (!bv_->theLockingInset())
1281 screen().hideCursor();
1285 void BufferView::Pimpl::toggleSelection(bool b)
1287 if (bv_->theLockingInset())
1288 bv_->theLockingInset()->toggleSelection(bv_, b);
1289 screen().toggleSelection(bv_->text, bv_, b);
1293 void BufferView::Pimpl::toggleToggle()
1295 screen().toggleToggle(bv_->text, bv_);
1299 void BufferView::Pimpl::center()
1301 LyXText * t = bv_->text;
1304 int const half_height = workarea().workHeight() / 2;
1307 if (t->cursor.y() > half_height) {
1308 new_y = t->cursor.y() - half_height;
1311 // FIXME: can we do this w/o calling screen directly ?
1312 // This updates first_y but means the fitCursor() call
1313 // from the update(FITCUR) doesn't realise that we might
1314 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1315 // the scrollbar to be updated as it should, so we have
1316 // to do it manually. Any operation that does a center()
1317 // and also might have moved first_y must make sure to call
1318 // updateScrollbar() currently. Never mind that this is a
1319 // pretty obfuscated way of updating t->first_y
1320 screen().draw(t, bv_, new_y);
1322 update(t, BufferView::SELECT | BufferView::FITCUR);
1326 void BufferView::Pimpl::pasteClipboard(bool asPara)
1331 screen().hideCursor();
1332 beforeChange(bv_->text);
1334 string const clip(workarea().getClipboard());
1340 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1342 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1344 bv_->getLyXText()->clearSelection();
1345 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1349 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1351 workarea().putClipboard(stuff);
1356 * Dispatch functions for actions which can be valid for BufferView->text
1357 * and/or InsetText->text!!!
1362 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1364 LyXText * lt = bv_->getLyXText();
1366 if (selecting || lt->selection.mark()) {
1367 lt->setSelection(bv_);
1371 updateInset(lt->inset_owner, false);
1375 update(lt, BufferView::SELECT|BufferView::FITCUR);
1377 update(lt, BufferView::SELECT);
1379 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1380 bv_->theLockingInset()->hideInsetCursor(bv_);
1381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1385 if (!lt->selection.set())
1386 workarea().haveSelection(false);
1388 /* ---> Everytime the cursor is moved, show the current font state. */
1389 // should this too me moved out of this func?
1390 //owner->showState();
1395 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1397 LyXCursor cursor = bv_->getLyXText()->cursor;
1398 Buffer::inset_iterator it =
1399 find_if(Buffer::inset_iterator(
1400 cursor.par(), cursor.pos()),
1401 buffer_->inset_iterator_end(),
1402 lyx::compare_memfun(&Inset::lyxCode, code));
1403 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1407 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1409 string filename = filen;
1411 if (filename.empty()) {
1412 // Launch a file browser
1413 string initpath = lyxrc.document_path;
1416 string const trypath = owner_->buffer()->filePath();
1417 // If directory is writeable, use this as default.
1418 if (IsDirWriteable(trypath))
1422 FileDialog fileDlg(bv_->owner(),
1423 _("Select LyX document to insert"),
1425 make_pair(string(_("Documents|#o#O")),
1426 string(lyxrc.document_path)),
1427 make_pair(string(_("Examples|#E#e")),
1428 string(AddPath(system_lyxdir, "examples"))));
1430 FileDialog::Result result =
1431 fileDlg.Select(initpath,
1432 _("*.lyx| LyX Documents (*.lyx)"));
1434 if (result.first == FileDialog::Later)
1437 filename = result.second;
1439 // check selected filename
1440 if (filename.empty()) {
1441 owner_->message(_("Canceled."));
1446 // get absolute path of file and add ".lyx" to the filename if
1448 filename = FileSearch(string(), filename, "lyx");
1450 string const disp_fn(MakeDisplayPath(filename));
1453 s1 << _("Inserting document") << ' '
1454 << disp_fn << " ...";
1455 owner_->message(s1.str().c_str());
1456 bool const res = bv_->insertLyXFile(filename);
1459 str << _("Document") << ' ' << disp_fn
1460 << ' ' << _("inserted.");
1461 owner_->message(str.str().c_str());
1464 str << _("Could not insert document") << ' '
1466 owner_->message(str.str().c_str());
1471 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1473 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1474 << action <<"] arg[" << argument << "]" << endl;
1476 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1479 // --- Misc -------------------------------------------
1483 LyXText * lt = bv_->getLyXText();
1484 lt->toggleAppendix(bv_);
1487 | BufferView::FITCUR
1488 | BufferView::CHANGE);
1493 case LFUN_TOC_INSERT:
1495 InsetCommandParams p;
1496 p.setCmdName("tableofcontents");
1497 Inset * inset = new InsetTOC(p);
1498 if (!insertInset(inset, tclass.defaultLayoutName()))
1503 case LFUN_SCROLL_INSET:
1504 // this is not handled here as this funktion is only aktive
1505 // if we have a locking_inset and that one is (or contains)
1509 case LFUN_INSET_GRAPHICS:
1511 Inset * new_inset = new InsetGraphics;
1512 if (!insertInset(new_inset)) {
1515 // this is need because you don't use a inset->Edit()
1516 updateInset(new_inset, true);
1517 new_inset->edit(bv_);
1527 case LFUN_PASTESELECTION:
1529 bool asPara = false;
1530 if (argument == "paragraph")
1532 pasteClipboard(asPara);
1544 case LFUN_LAYOUT_COPY:
1545 bv_->copyEnvironment();
1548 case LFUN_LAYOUT_PASTE:
1549 bv_->pasteEnvironment();
1553 case LFUN_GOTOERROR:
1554 gotoInset(Inset::ERROR_CODE, false);
1558 gotoInset(Inset::IGNORE_CODE, false);
1561 case LFUN_REFERENCE_GOTO:
1563 vector<Inset::Code> tmp;
1564 tmp.push_back(Inset::LABEL_CODE);
1565 tmp.push_back(Inset::REF_CODE);
1566 gotoInset(tmp, true);
1570 case LFUN_HYPHENATION:
1571 specialChar(InsetSpecialChar::HYPHENATION);
1574 case LFUN_LIGATURE_BREAK:
1575 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1579 specialChar(InsetSpecialChar::LDOTS);
1582 case LFUN_END_OF_SENTENCE:
1583 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1586 case LFUN_MENU_SEPARATOR:
1587 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1594 case LFUN_DEPTH_MIN:
1595 changeDepth(bv_, bv_->getLyXText(), -1);
1598 case LFUN_DEPTH_PLUS:
1599 changeDepth(bv_, bv_->getLyXText(), 1);
1603 owner_->getDialogs()->setUserFreeFont();
1606 case LFUN_FILE_INSERT:
1607 MenuInsertLyXFile(argument);
1610 case LFUN_FILE_INSERT_ASCII_PARA:
1611 InsertAsciiFile(bv_, argument, true);
1614 case LFUN_FILE_INSERT_ASCII:
1615 InsertAsciiFile(bv_, argument, false);
1620 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1621 << argument << endl;
1623 // This is not the good solution to the empty argument
1624 // problem, but it will hopefully suffice for 1.2.0.
1625 // The correct solution would be to augument the
1626 // function list/array with information about what
1627 // functions needs arguments and their type.
1628 if (argument.empty()) {
1629 owner_->getLyXFunc()->setErrorMessage(
1630 _("LyX function 'layout' needs an argument."));
1634 // Derive layout number from given argument (string)
1635 // and current buffer's textclass (number). */
1636 bool hasLayout = tclass.hasLayout(argument);
1637 string layout = argument;
1639 // If the entry is obsolete, use the new one instead.
1641 string const & obs = tclass[layout]->obsoleted_by();
1647 owner_->getLyXFunc()->setErrorMessage(
1648 string(N_("Layout ")) + argument +
1653 bool change_layout = (current_layout != layout);
1654 LyXText * lt = bv_->getLyXText();
1655 if (!change_layout && lt->selection.set() &&
1656 lt->selection.start.par() != lt->selection.end.par())
1658 Paragraph * spar = lt->selection.start.par();
1659 Paragraph * epar = lt->selection.end.par()->next();
1660 while(spar != epar) {
1661 if (spar->layout()->name() != current_layout) {
1662 change_layout = true;
1667 if (change_layout) {
1669 current_layout = layout;
1672 | BufferView::FITCUR);
1673 lt->setLayout(bv_, layout);
1674 owner_->setLayout(layout);
1677 | BufferView::FITCUR
1678 | BufferView::CHANGE);
1685 lang(bv_, argument);
1687 owner_->showState();
1692 owner_->showState();
1697 owner_->showState();
1702 owner_->showState();
1707 owner_->showState();
1712 owner_->showState();
1717 owner_->showState();
1722 owner_->showState();
1725 case LFUN_UNDERLINE:
1727 owner_->showState();
1730 case LFUN_FONT_SIZE:
1731 fontSize(bv_, argument);
1732 owner_->showState();
1735 case LFUN_FONT_STATE:
1736 owner_->getLyXFunc()->setMessage(currentState(bv_));
1739 case LFUN_UPCASE_WORD:
1741 LyXText * lt = bv_->getLyXText();
1745 | BufferView::FITCUR);
1746 lt->changeCase(bv_, LyXText::text_uppercase);
1747 if (lt->inset_owner)
1748 updateInset(lt->inset_owner, true);
1751 | BufferView::FITCUR
1752 | BufferView::CHANGE);
1756 case LFUN_LOWCASE_WORD:
1758 LyXText * lt = bv_->getLyXText();
1760 update(lt, BufferView::SELECT|BufferView::FITCUR);
1761 lt->changeCase(bv_, LyXText::text_lowercase);
1762 if (lt->inset_owner)
1763 updateInset(lt->inset_owner, true);
1766 | BufferView::FITCUR
1767 | BufferView::CHANGE);
1771 case LFUN_CAPITALIZE_WORD:
1773 LyXText * lt = bv_->getLyXText();
1775 update(lt, BufferView::SELECT|BufferView::FITCUR);
1776 lt->changeCase(bv_, LyXText::text_capitalization);
1777 if (lt->inset_owner)
1778 updateInset(lt->inset_owner, true);
1781 | BufferView::FITCUR
1782 | BufferView::CHANGE);
1786 case LFUN_TRANSPOSE_CHARS:
1788 LyXText * lt = bv_->getLyXText();
1790 update(lt, BufferView::SELECT|BufferView::FITCUR);
1791 lt->transposeChars(*bv_);
1792 if (lt->inset_owner)
1793 updateInset(lt->inset_owner, true);
1796 | BufferView::FITCUR
1797 | BufferView::CHANGE);
1802 case LFUN_INSERT_LABEL:
1803 MenuInsertLabel(bv_, argument);
1806 case LFUN_REF_INSERT:
1807 if (argument.empty()) {
1808 InsetCommandParams p("ref");
1809 owner_->getDialogs()->createRef(p.getAsString());
1811 InsetCommandParams p;
1812 p.setFromString(argument);
1814 InsetRef * inset = new InsetRef(p, *buffer_);
1815 if (!insertInset(inset))
1818 updateInset(inset, true);
1822 case LFUN_BOOKMARK_SAVE:
1823 savePosition(strToUnsignedInt(argument));
1826 case LFUN_BOOKMARK_GOTO:
1827 restorePosition(strToUnsignedInt(argument));
1832 string label(argument);
1833 if (label.empty()) {
1835 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1837 label = inset->getContents();
1842 if (!label.empty()) {
1843 //bv_->savePosition(0);
1844 if (!bv_->gotoLabel(label))
1845 Alert::alert(_("Error"),
1846 _("Couldn't find this label"),
1847 _("in current document."));
1852 // --- Cursor Movements -----------------------------
1855 LyXText * lt = bv_->getLyXText();
1857 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1858 if (!lt->selection.mark())
1860 update(lt, BufferView::SELECT|BufferView::FITCUR);
1862 lt->cursorLeft(bv_, false);
1863 if (lt->cursor.pos() < lt->cursor.par()->size()
1864 && lt->cursor.par()->isInset(lt->cursor.pos())
1865 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1866 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1867 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1869 tmpinset->edit(bv_, false);
1871 tmpinset->edit(bv_);
1875 lt->cursorRight(bv_, false);
1877 moveCursorUpdate(false);
1878 owner_->showState();
1884 // This is soooo ugly. Isn`t it possible to make
1885 // it simpler? (Lgb)
1886 LyXText * lt = bv_->getLyXText();
1887 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1888 if (!lt->selection.mark())
1890 update(lt, BufferView::SELECT|BufferView::FITCUR);
1891 LyXCursor const cur = lt->cursor;
1893 lt->cursorLeft(bv_, false);
1894 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1895 lt->cursor.pos() < lt->cursor.par()->size() &&
1896 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1897 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1898 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1899 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1901 tmpinset->edit(bv_);
1903 tmpinset->edit(bv_, false);
1907 lt->cursorRight(bv_, false);
1910 moveCursorUpdate(false);
1911 owner_->showState();
1917 LyXText * lt = bv_->getLyXText();
1919 if (!lt->selection.mark())
1921 update(lt, BufferView::UPDATE);
1924 moveCursorUpdate(false);
1925 owner_->showState();
1931 LyXText * lt = bv_->getLyXText();
1933 if (!lt->selection.mark())
1935 update(lt, BufferView::UPDATE);
1936 lt->cursorDown(bv_);
1938 moveCursorUpdate(false);
1939 owner_->showState();
1943 case LFUN_UP_PARAGRAPH:
1945 LyXText * lt = bv_->getLyXText();
1947 if (!lt->selection.mark())
1949 update(lt, BufferView::UPDATE);
1950 lt->cursorUpParagraph(bv_);
1952 moveCursorUpdate(false);
1953 owner_->showState();
1957 case LFUN_DOWN_PARAGRAPH:
1959 LyXText * lt = bv_->getLyXText();
1961 if (!lt->selection.mark())
1963 update(lt, BufferView::UPDATE);
1964 lt->cursorDownParagraph(bv_);
1966 moveCursorUpdate(false);
1967 owner_->showState();
1973 LyXText * lt = bv_->getLyXText();
1975 if (!lt->selection.mark())
1977 update(lt, BufferView::UPDATE);
1980 moveCursorUpdate(false, false);
1981 owner_->showState();
1987 LyXText * lt = bv_->getLyXText();
1989 if (!lt->selection.mark())
1991 update(lt, BufferView::UPDATE);
1994 moveCursorUpdate(false, false);
1995 owner_->showState();
2001 LyXText * lt = bv_->getLyXText();
2003 if (!lt->selection.mark())
2005 update(lt, BufferView::SELECT|BufferView::FITCUR);
2006 lt->cursorHome(bv_);
2008 moveCursorUpdate(false);
2009 owner_->showState();
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2020 BufferView::SELECT|BufferView::FITCUR);
2023 moveCursorUpdate(false);
2024 owner_->showState();
2028 case LFUN_SHIFT_TAB:
2031 LyXText * lt = bv_->getLyXText();
2033 if (!lt->selection.mark())
2036 BufferView::SELECT|BufferView::FITCUR);
2039 moveCursorUpdate(false);
2040 owner_->showState();
2044 case LFUN_WORDRIGHT:
2046 LyXText * lt = bv_->getLyXText();
2048 if (!lt->selection.mark())
2050 update(lt, BufferView::SELECT|BufferView::FITCUR);
2051 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2052 lt->cursorLeftOneWord(bv_);
2054 lt->cursorRightOneWord(bv_);
2056 moveCursorUpdate(false);
2057 owner_->showState();
2063 LyXText * lt = bv_->getLyXText();
2065 if (!lt->selection.mark())
2067 update(lt, BufferView::SELECT|BufferView::FITCUR);
2068 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2069 lt->cursorRightOneWord(bv_);
2071 lt->cursorLeftOneWord(bv_);
2073 moveCursorUpdate(false);
2074 owner_->showState();
2078 case LFUN_BEGINNINGBUF:
2080 LyXText * lt = bv_->getLyXText();
2082 if (!lt->selection.mark())
2085 BufferView::SELECT|BufferView::FITCUR);
2088 moveCursorUpdate(false);
2089 owner_->showState();
2095 LyXText * lt = bv_->getLyXText();
2097 if (!lt->selection.mark())
2100 BufferView::SELECT|BufferView::FITCUR);
2101 lt->cursorBottom(bv_);
2103 moveCursorUpdate(false);
2104 owner_->showState();
2108 /* cursor selection ---------------------------- */
2111 LyXText * lt = bv_->getLyXText();
2114 BufferView::SELECT|BufferView::FITCUR);
2115 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2116 lt->cursorLeft(bv_);
2118 lt->cursorRight(bv_);
2120 moveCursorUpdate(true);
2121 owner_->showState();
2127 LyXText * lt = bv_->getLyXText();
2130 BufferView::SELECT|BufferView::FITCUR);
2131 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2132 lt->cursorRight(bv_);
2134 lt->cursorLeft(bv_);
2136 moveCursorUpdate(true);
2137 owner_->showState();
2143 LyXText * lt = bv_->getLyXText();
2146 BufferView::SELECT|BufferView::FITCUR);
2147 lt->cursorUp(bv_, true);
2149 moveCursorUpdate(true);
2150 owner_->showState();
2156 LyXText * lt = bv_->getLyXText();
2159 BufferView::SELECT|BufferView::FITCUR);
2160 lt->cursorDown(bv_, true);
2162 moveCursorUpdate(true);
2163 owner_->showState();
2167 case LFUN_UP_PARAGRAPHSEL:
2169 LyXText * lt = bv_->getLyXText();
2172 BufferView::SELECT|BufferView::FITCUR);
2173 lt->cursorUpParagraph(bv_);
2175 moveCursorUpdate(true);
2176 owner_->showState();
2180 case LFUN_DOWN_PARAGRAPHSEL:
2182 LyXText * lt = bv_->getLyXText();
2185 BufferView::SELECT|BufferView::FITCUR);
2186 lt->cursorDownParagraph(bv_);
2188 moveCursorUpdate(true);
2189 owner_->showState();
2195 LyXText * lt = bv_->getLyXText();
2197 update(lt, BufferView::SELECT|BufferView::FITCUR);
2200 moveCursorUpdate(true);
2201 owner_->showState();
2207 LyXText * lt = bv_->getLyXText();
2209 update(lt, BufferView::SELECT|BufferView::FITCUR);
2212 moveCursorUpdate(true);
2213 owner_->showState();
2219 LyXText * lt = bv_->getLyXText();
2221 update(lt, BufferView::SELECT|BufferView::FITCUR);
2222 lt->cursorHome(bv_);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 moveCursorUpdate(true);
2237 owner_->showState();
2241 case LFUN_WORDRIGHTSEL:
2243 LyXText * lt = bv_->getLyXText();
2245 update(lt, BufferView::SELECT|BufferView::FITCUR);
2246 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2247 lt->cursorLeftOneWord(bv_);
2249 lt->cursorRightOneWord(bv_);
2251 moveCursorUpdate(true);
2252 owner_->showState();
2256 case LFUN_WORDLEFTSEL:
2258 LyXText * lt = bv_->getLyXText();
2260 update(lt, BufferView::SELECT|BufferView::FITCUR);
2261 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2262 lt->cursorRightOneWord(bv_);
2264 lt->cursorLeftOneWord(bv_);
2266 moveCursorUpdate(true);
2267 owner_->showState();
2271 case LFUN_BEGINNINGBUFSEL:
2273 LyXText * lt = bv_->getLyXText();
2275 if (lt->inset_owner)
2277 update(lt, BufferView::SELECT|BufferView::FITCUR);
2280 moveCursorUpdate(true);
2281 owner_->showState();
2285 case LFUN_ENDBUFSEL:
2287 LyXText * lt = bv_->getLyXText();
2289 if (lt->inset_owner)
2292 BufferView::SELECT|BufferView::FITCUR);
2293 lt->cursorBottom(bv_);
2295 moveCursorUpdate(true);
2296 owner_->showState();
2300 // --- text changing commands ------------------------
2301 case LFUN_BREAKLINE:
2303 LyXText * lt = bv_->getLyXText();
2306 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2309 | BufferView::FITCUR
2310 | BufferView::CHANGE);
2311 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2312 moveCursorUpdate(false);
2316 case LFUN_PROTECTEDSPACE:
2318 LyXText * lt = bv_->getLyXText();
2319 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2321 if (style->free_spacing) {
2322 lt->insertChar(bv_, ' ');
2325 | BufferView::FITCUR
2326 | BufferView::CHANGE);
2328 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2330 moveCursorUpdate(false);
2336 LyXText * lt = bv_->getLyXText();
2338 if (lt->selection.mark()) {
2342 | BufferView::FITCUR);
2343 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2346 lt->selection.mark(true);
2349 | BufferView::FITCUR);
2350 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2352 lt->selection.cursor = lt->cursor;
2358 LyXText * lt = bv_->getLyXText();
2360 if (!lt->selection.set()) {
2362 lt->selection.cursor = lt->cursor;
2365 | BufferView::FITCUR
2366 | BufferView::CHANGE);
2367 // It is possible to make it a lot faster still
2368 // just comment out the line below...
2373 moveCursorUpdate(false);
2374 owner_->showState();
2379 case LFUN_DELETE_SKIP:
2381 LyXText * lt = bv_->getLyXText();
2383 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2385 LyXCursor cursor = lt->cursor;
2387 if (!lt->selection.set()) {
2388 if (cursor.pos() == cursor.par()->size()) {
2389 lt->cursorRight(bv_);
2390 cursor = lt->cursor;
2391 if (cursor.pos() == 0
2392 && !(cursor.par()->params().spaceTop()
2393 == VSpace (VSpace::NONE))) {
2396 cursor.par()->params().lineTop(),
2397 cursor.par()->params().lineBottom(),
2398 cursor.par()->params().pagebreakTop(),
2399 cursor.par()->params().pagebreakBottom(),
2400 VSpace(VSpace::NONE),
2401 cursor.par()->params().spaceBottom(),
2402 cursor.par()->params().spacing(),
2403 cursor.par()->params().align(),
2404 cursor.par()->params().labelWidthString(), 0);
2405 lt->cursorLeft(bv_);
2408 | BufferView::FITCUR
2409 | BufferView::CHANGE);
2411 lt->cursorLeft(bv_);
2413 lt->selection.cursor = lt->cursor;
2416 | BufferView::FITCUR
2417 | BufferView::CHANGE);
2421 lt->selection.cursor = lt->cursor;
2424 | BufferView::FITCUR
2425 | BufferView::CHANGE);
2433 /* -------> Delete word forward. */
2434 case LFUN_DELETE_WORD_FORWARD:
2435 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2436 bv_->getLyXText()->deleteWordForward(bv_);
2437 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2438 moveCursorUpdate(false);
2439 owner_->showState();
2442 /* -------> Delete word backward. */
2443 case LFUN_DELETE_WORD_BACKWARD:
2445 LyXText * lt = bv_->getLyXText();
2447 update(lt, BufferView::SELECT|BufferView::FITCUR);
2448 lt->deleteWordBackward(bv_);
2451 | BufferView::FITCUR
2452 | BufferView::CHANGE);
2453 moveCursorUpdate(false);
2454 owner_->showState();
2458 /* -------> Kill to end of line. */
2459 case LFUN_DELETE_LINE_FORWARD:
2461 LyXText * lt = bv_->getLyXText();
2463 update(lt, BufferView::SELECT|BufferView::FITCUR);
2464 lt->deleteLineForward(bv_);
2467 | BufferView::FITCUR
2468 | BufferView::CHANGE);
2469 moveCursorUpdate(false);
2473 /* -------> Set mark off. */
2476 LyXText * lt = bv_->getLyXText();
2479 update(lt, BufferView::SELECT|BufferView::FITCUR);
2480 lt->selection.cursor = lt->cursor;
2481 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2485 /* -------> Set mark on. */
2488 LyXText * lt = bv_->getLyXText();
2491 lt->selection.mark(true);
2492 update(lt, BufferView::SELECT|BufferView::FITCUR);
2493 lt->selection.cursor = lt->cursor;
2494 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2498 case LFUN_BACKSPACE:
2500 LyXText * lt = bv_->getLyXText();
2502 if (!lt->selection.set()) {
2503 if (owner_->getIntl()->getTransManager().backspace()) {
2505 lt->selection.cursor = lt->cursor;
2508 | BufferView::FITCUR
2509 | BufferView::CHANGE);
2510 // It is possible to make it a lot faster still
2511 // just comment out the line below...
2517 owner_->showState();
2522 case LFUN_BACKSPACE_SKIP:
2524 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2525 LyXText * lt = bv_->getLyXText();
2527 LyXCursor cursor = lt->cursor;
2529 if (!lt->selection.set()) {
2530 if (cursor.pos() == 0
2531 && !(cursor.par()->params().spaceTop()
2532 == VSpace (VSpace::NONE))) {
2535 cursor.par()->params().lineTop(),
2536 cursor.par()->params().lineBottom(),
2537 cursor.par()->params().pagebreakTop(),
2538 cursor.par()->params().pagebreakBottom(),
2539 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2540 cursor.par()->params().spacing(),
2541 cursor.par()->params().align(),
2542 cursor.par()->params().labelWidthString(), 0);
2545 | BufferView::FITCUR
2546 | BufferView::CHANGE);
2549 lt->selection.cursor = cursor;
2552 | BufferView::FITCUR
2553 | BufferView::CHANGE);
2560 case LFUN_BREAKPARAGRAPH:
2562 LyXText * lt = bv_->getLyXText();
2565 lt->breakParagraph(bv_, 0);
2568 | BufferView::FITCUR
2569 | BufferView::CHANGE);
2570 lt->selection.cursor = lt->cursor;
2572 owner_->showState();
2576 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2578 LyXText * lt = bv_->getLyXText();
2581 lt->breakParagraph(bv_, 1);
2584 | BufferView::FITCUR
2585 | BufferView::CHANGE);
2586 lt->selection.cursor = lt->cursor;
2588 owner_->showState();
2592 case LFUN_BREAKPARAGRAPH_SKIP:
2594 // When at the beginning of a paragraph, remove
2595 // indentation and add a "defskip" at the top.
2596 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2597 LyXText * lt = bv_->getLyXText();
2599 LyXCursor cursor = lt->cursor;
2602 if (cursor.pos() == 0) {
2603 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2606 cursor.par()->params().lineTop(),
2607 cursor.par()->params().lineBottom(),
2608 cursor.par()->params().pagebreakTop(),
2609 cursor.par()->params().pagebreakBottom(),
2610 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2611 cursor.par()->params().spacing(),
2612 cursor.par()->params().align(),
2613 cursor.par()->params().labelWidthString(), 1);
2614 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2618 lt->breakParagraph(bv_, 0);
2619 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2624 | BufferView::FITCUR
2625 | BufferView::CHANGE);
2626 lt->selection.cursor = cursor;
2628 owner_->showState();
2632 case LFUN_PARAGRAPH_SPACING:
2634 LyXText * lt = bv_->getLyXText();
2636 Paragraph * par = lt->cursor.par();
2637 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2638 float cur_value = 1.0;
2639 if (cur_spacing == Spacing::Other) {
2640 cur_value = par->params().spacing().getValue();
2643 istringstream istr(argument.c_str());
2647 Spacing::Space new_spacing = cur_spacing;
2648 float new_value = cur_value;
2650 lyxerr << "Missing argument to `paragraph-spacing'"
2652 } else if (tmp == "single") {
2653 new_spacing = Spacing::Single;
2654 } else if (tmp == "onehalf") {
2655 new_spacing = Spacing::Onehalf;
2656 } else if (tmp == "double") {
2657 new_spacing = Spacing::Double;
2658 } else if (tmp == "other") {
2659 new_spacing = Spacing::Other;
2662 lyxerr << "new_value = " << tmpval << endl;
2665 } else if (tmp == "default") {
2666 new_spacing = Spacing::Default;
2668 lyxerr << _("Unknown spacing argument: ")
2669 << argument << endl;
2671 if (cur_spacing != new_spacing || cur_value != new_value) {
2672 par->params().spacing(Spacing(new_spacing, new_value));
2673 lt->redoParagraph(bv_);
2676 | BufferView::FITCUR
2677 | BufferView::CHANGE);
2682 case LFUN_INSET_TOGGLE:
2684 LyXText * lt = bv_->getLyXText();
2687 update(lt, BufferView::SELECT|BufferView::FITCUR);
2688 lt->toggleInset(bv_);
2689 update(lt, BufferView::SELECT|BufferView::FITCUR);
2701 InsetCommandParams p;
2702 if (action == LFUN_HTMLURL)
2703 p.setCmdName("htmlurl");
2705 p.setCmdName("url");
2706 owner_->getDialogs()->createUrl(p.getAsString());
2710 case LFUN_INSERT_URL:
2712 InsetCommandParams p;
2713 p.setFromString(argument);
2715 InsetUrl * inset = new InsetUrl(p);
2716 if (!insertInset(inset))
2719 updateInset(inset, true);
2723 case LFUN_INSET_ERT:
2724 insertAndEditInset(new InsetERT(buffer_->params));
2727 case LFUN_INSET_EXTERNAL:
2728 insertAndEditInset(new InsetExternal);
2731 case LFUN_INSET_FOOTNOTE:
2732 insertAndEditInset(new InsetFoot(buffer_->params));
2735 case LFUN_INSET_MARGINAL:
2736 insertAndEditInset(new InsetMarginal(buffer_->params));
2739 case LFUN_INSET_MINIPAGE:
2740 insertAndEditInset(new InsetMinipage(buffer_->params));
2743 case LFUN_INSERT_NOTE:
2744 insertAndEditInset(new InsetNote(buffer_->params));
2747 case LFUN_INSET_FLOAT:
2748 // check if the float type exist
2749 if (floatList.typeExist(argument)) {
2750 insertAndEditInset(new InsetFloat(buffer_->params,
2753 lyxerr << "Non-existent float type: "
2754 << argument << endl;
2758 case LFUN_INSET_WIDE_FLOAT:
2759 // check if the float type exist
2760 if (floatList.typeExist(argument)) {
2761 InsetFloat * new_inset =
2762 new InsetFloat(buffer_->params, argument);
2763 new_inset->wide(true);
2764 insertAndEditInset(new_inset);
2766 lyxerr << "Non-existent float type: "
2767 << argument << endl;
2772 case LFUN_INSET_LIST:
2773 insertAndEditInset(new InsetList);
2776 case LFUN_INSET_THEOREM:
2777 insertAndEditInset(new InsetTheorem);
2781 case LFUN_INSET_CAPTION:
2783 // Do we have a locking inset...
2784 if (bv_->theLockingInset()) {
2785 lyxerr << "Locking inset code: "
2786 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2787 InsetCaption * new_inset =
2788 new InsetCaption(buffer_->params);
2789 new_inset->setOwner(bv_->theLockingInset());
2790 new_inset->setAutoBreakRows(true);
2791 new_inset->setDrawFrame(0, InsetText::LOCKED);
2792 new_inset->setFrameColor(0, LColor::captionframe);
2793 if (insertInset(new_inset))
2794 new_inset->edit(bv_);
2801 case LFUN_INSET_TABULAR:
2805 if (!argument.empty())
2806 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2807 InsetTabular * new_inset =
2808 new InsetTabular(*buffer_, r, c);
2810 bv_->getLyXText()->real_current_font.isRightToLeft();
2811 if (!open_new_inset(new_inset, rtl))
2816 // --- lyxserver commands ----------------------------
2818 case LFUN_CHARATCURSOR:
2820 pos_type pos = bv_->getLyXText()->cursor.pos();
2821 if (pos < bv_->getLyXText()->cursor.par()->size())
2822 owner_->getLyXFunc()->setMessage(
2823 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2825 owner_->getLyXFunc()->setMessage("EOF");
2830 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2832 + tostr(bv_->getLyXText()->cursor.y()));
2839 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2840 lyxerr << "SETXY: Could not parse coordinates in '"
2841 << argument << std::endl;
2843 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2847 case LFUN_GETLAYOUT:
2848 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2853 LyXFont & font = bv_->getLyXText()->current_font;
2854 if (font.shape() == LyXFont::ITALIC_SHAPE)
2855 owner_->getLyXFunc()->setMessage("E");
2856 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2857 owner_->getLyXFunc()->setMessage("N");
2859 owner_->getLyXFunc()->setMessage("0");
2864 // --- accented characters ---------------------------
2867 case LFUN_CIRCUMFLEX:
2877 case LFUN_SPECIAL_CARON:
2880 case LFUN_HUNG_UMLAUT:
2883 if (argument.empty()) {
2885 owner_->getLyXFunc()->handleKeyFunc(action);
2887 owner_->getLyXFunc()->handleKeyFunc(action);
2888 owner_->getIntl()->getTransManager()
2889 .TranslateAndInsert(argument[0], bv_->getLyXText());
2890 update(bv_->getLyXText(),
2892 | BufferView::FITCUR
2893 | BufferView::CHANGE);
2898 mathDispatch(bv_, argument);
2901 case LFUN_MATH_MACRO:
2902 mathDispatchMathMacro(bv_, argument);
2905 case LFUN_MATH_DELIM:
2906 mathDispatchMathDelim(bv_, argument);
2909 case LFUN_INSERT_MATRIX:
2910 mathDispatchInsertMatrix(bv_, argument);
2913 case LFUN_INSERT_MATH:
2914 mathDispatchInsertMath(bv_, argument);
2917 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2918 mathDispatchMathImportSelection(bv_, argument);
2921 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2922 mathDispatchMathDisplay(bv_, argument);
2925 case LFUN_MATH_MODE: // Open or create an inlined math inset
2926 mathDispatchMathMode(bv_, argument);
2929 case LFUN_GREEK: // Insert a single greek letter
2930 mathDispatchGreek(bv_, argument);
2933 case LFUN_CITATION_INSERT:
2935 InsetCommandParams p;
2936 p.setFromString(argument);
2938 InsetCitation * inset = new InsetCitation(p);
2939 if (!insertInset(inset))
2942 updateInset(inset, true);
2946 case LFUN_INSERT_BIBTEX:
2948 // ale970405+lasgoutt970425
2949 // The argument can be up to two tokens separated
2950 // by a space. The first one is the bibstyle.
2951 string const db = token(argument, ' ', 0);
2952 string const bibstyle = token(argument, ' ', 1);
2954 InsetCommandParams p("BibTeX", db, bibstyle);
2955 InsetBibtex * inset = new InsetBibtex(p);
2957 if (insertInset(inset)) {
2958 if (argument.empty())
2965 // BibTeX data bases
2966 case LFUN_BIBDB_ADD:
2968 InsetBibtex * inset =
2969 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2971 inset->addDatabase(argument);
2976 case LFUN_BIBDB_DEL:
2978 InsetBibtex * inset =
2979 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2981 inset->delDatabase(argument);
2986 case LFUN_BIBTEX_STYLE:
2988 InsetBibtex * inset =
2989 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2991 inset->setOptions(argument);
2996 case LFUN_INDEX_INSERT:
2998 string entry = argument;
2999 if (entry.empty()) {
3000 entry = bv_->getLyXText()->getStringToIndex(bv_);
3003 if (entry.empty()) {
3004 owner_->getDialogs()->createIndex();
3008 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3010 if (!insertInset(inset)) {
3013 updateInset(inset, true);
3018 case LFUN_INDEX_PRINT:
3020 InsetCommandParams p("printindex");
3021 Inset * inset = new InsetPrintIndex(p);
3022 if (!insertInset(inset, tclass.defaultLayoutName()))
3027 case LFUN_PARENTINSERT:
3029 InsetCommandParams p("lyxparent", argument);
3030 Inset * inset = new InsetParent(p, *buffer_);
3031 if (!insertInset(inset, tclass.defaultLayoutName()))
3037 case LFUN_CHILD_INSERT:
3039 InsetInclude::Params p;
3040 p.cparams.setFromString(argument);
3041 p.masterFilename_ = buffer_->fileName();
3043 InsetInclude * inset = new InsetInclude(p);
3044 if (!insertInset(inset))
3047 updateInset(inset, true);
3048 bv_->owner()->getDialogs()->showInclude(inset);
3053 case LFUN_FLOAT_LIST:
3054 if (floatList.typeExist(argument)) {
3055 Inset * inset = new InsetFloatList(argument);
3056 if (!insertInset(inset, tclass.defaultLayoutName()))
3059 lyxerr << "Non-existent float type: "
3060 << argument << endl;
3064 case LFUN_THESAURUS_ENTRY:
3066 string arg = argument;
3069 arg = bv_->getLyXText()->selectionAsString(buffer_,
3073 if (arg.size() > 100 || arg.empty()) {
3074 // Get word or selection
3075 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3076 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3077 // FIXME: where is getLyXText()->unselect(bv_) ?
3081 bv_->owner()->getDialogs()->showThesaurus(arg);
3085 case LFUN_SELFINSERT:
3087 if (argument.empty()) break;
3089 /* Automatically delete the currently selected
3090 * text and replace it with what is being
3091 * typed in now. Depends on lyxrc settings
3092 * "auto_region_delete", which defaults to
3095 LyXText * lt = bv_->getLyXText();
3097 if (lyxrc.auto_region_delete) {
3098 if (lt->selection.set()) {
3099 lt->cutSelection(bv_, false, false);
3102 | BufferView::FITCUR
3103 | BufferView::CHANGE);
3105 workarea().haveSelection(false);
3109 LyXFont const old_font(lt->real_current_font);
3111 string::const_iterator cit = argument.begin();
3112 string::const_iterator end = argument.end();
3113 for (; cit != end; ++cit) {
3114 owner_->getIntl()->getTransManager().
3115 TranslateAndInsert(*cit, lt);
3120 | BufferView::FITCUR
3121 | BufferView::CHANGE);
3123 lt->selection.cursor = lt->cursor;
3124 moveCursorUpdate(false);
3126 // real_current_font.number can change so we need to
3127 // update the minibuffer
3128 if (old_font != lt->real_current_font)
3129 owner_->showState();
3134 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3136 time_t now_time_t = time(NULL);
3137 struct tm * now_tm = localtime(&now_time_t);
3138 setlocale(LC_TIME, "");
3140 if (!argument.empty())
3143 arg = lyxrc.date_insert_format;
3145 int const datetmp_len =
3146 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3148 LyXText * lt = bv_->getLyXText();
3150 for (int i = 0; i < datetmp_len; i++) {
3151 lt->insertChar(bv_, datetmp[i]);
3154 | BufferView::FITCUR
3155 | BufferView::CHANGE);
3158 lt->selection.cursor = lt->cursor;
3159 moveCursorUpdate(false);
3163 case LFUN_UNKNOWN_ACTION:
3164 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3175 void BufferView::Pimpl::newline()
3178 LyXText * lt = bv_->getLyXText();
3182 | BufferView::FITCUR);
3183 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3186 | BufferView::FITCUR
3187 | BufferView::CHANGE);
3192 void BufferView::Pimpl::hfill()
3195 LyXText * lt = bv_->getLyXText();
3199 | BufferView::FITCUR);
3200 lt->insertChar(bv_, Paragraph::META_HFILL);
3203 | BufferView::FITCUR
3204 | BufferView::CHANGE);
3209 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3212 LyXText * lt = bv_->getLyXText();
3215 update(lt, BufferView::SELECT|BufferView::FITCUR);
3216 InsetSpecialChar * new_inset =
3217 new InsetSpecialChar(kind);
3218 if (!insertInset(new_inset))
3221 updateInset(new_inset, true);
3226 void BufferView::Pimpl::smartQuote()
3228 LyXText const * lt = bv_->getLyXText();
3229 Paragraph const * par = lt->cursor.par();
3230 pos_type pos = lt->cursor.pos();
3234 || (par->isInset(pos - 1)
3235 && par->getInset(pos - 1)->isSpace()))
3238 c = par->getChar(pos - 1);
3243 LyXLayout_ptr const & style = par->layout();
3245 if (style->pass_thru ||
3246 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3247 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3251 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3254 if (insertInset(inset))
3259 bool gotsel = false;
3261 if (bv_->getLyXText()->selection.set()) {
3262 bv_->getLyXText()->cutSelection(bv_, true, false);
3266 if (insertInset(inset)) {
3269 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3277 // Open and lock an updatable inset
3278 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3280 LyXText * lt = bv_->getLyXText();
3284 if (!insertInset(new_inset)) {
3288 new_inset->edit(bv_, !behind);
3293 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3295 // if we are in a locking inset we should try to insert the
3296 // inset there otherwise this is a illegal function now
3297 if (bv_->theLockingInset()) {
3298 if (bv_->theLockingInset()->insetAllowed(inset))
3299 return bv_->theLockingInset()->insertInset(bv_, inset);
3303 // not quite sure if we want this...
3304 setCursorParUndo(bv_);
3307 beforeChange(bv_->text);
3308 if (!lout.empty()) {
3309 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3310 bv_->text->breakParagraph(bv_);
3311 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3313 if (bv_->text->cursor.par()->size()) {
3314 bv_->text->cursorLeft(bv_);
3316 bv_->text->breakParagraph(bv_);
3317 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3321 LyXTextClass const & tclass =
3322 textclasslist[buffer_->params.textclass];
3323 bool hasLayout = tclass.hasLayout(lres);
3324 string lay = tclass.defaultLayoutName();
3326 if (hasLayout != false) {
3330 // layout not fount using default
3331 lay = tclass.defaultLayoutName();
3334 bv_->text->setLayout(bv_, lay);
3336 bv_->text->setParagraph(bv_, 0, 0,
3338 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3343 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3346 bv_->text->insertInset(bv_, inset);
3347 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3354 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3356 if (!inset || !available())
3359 // first check for locking insets
3360 if (bv_->theLockingInset()) {
3361 if (bv_->theLockingInset() == inset) {
3362 if (bv_->text->updateInset(bv_, inset)) {
3365 buffer_->markDirty();
3370 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3371 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3374 buffer_->markDirty();
3382 // then check if the inset is a top_level inset (has no owner)
3383 // if yes do the update as always otherwise we have to update the
3384 // toplevel inset where this inset is inside
3385 Inset * tl_inset = inset;
3386 while(tl_inset->owner())
3387 tl_inset = tl_inset->owner();
3389 if (tl_inset == inset) {
3390 update(bv_->text, BufferView::UPDATE);
3391 if (bv_->text->updateInset(bv_, inset)) {
3395 | BufferView::FITCUR
3396 | BufferView::CHANGE);
3398 update(bv_->text, SELECT);
3402 } else if (static_cast<UpdatableInset *>(tl_inset)
3403 ->updateInsetInInset(bv_, inset))
3405 if (bv_->text->updateInset(bv_, tl_inset)) {
3413 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3416 if (!available()) return;
3419 beforeChange(bv_->text);
3420 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3422 LyXCursor const & cursor = bv_->text->cursor;
3426 cursor.par()->isInset(cursor.pos())) {
3427 Inset const * inset = cursor.par()->getInset(cursor.pos());
3428 if (find(codes.begin(), codes.end(), inset->lyxCode())
3431 static_cast<InsetCommand const *>(inset)->getContents();
3435 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3436 if (bv_->text->cursor.pos()
3437 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3438 LyXCursor tmp = bv_->text->cursor;
3439 bv_->text->cursor.par(bv_->text->ownerParagraph());
3440 bv_->text->cursor.pos(0);
3441 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3442 bv_->text->cursor = tmp;
3443 bv_->owner()->message(_("No more insets"));
3446 bv_->owner()->message(_("No more insets"));
3449 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3450 bv_->text->selection.cursor = bv_->text->cursor;
3454 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3456 gotoInset(vector<Inset::Code>(1, code), same_content);