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 if (widthChange || heightChange) {
936 // always make sure that the scrollbar is sane.
938 owner_->updateLayoutChoice();
943 void BufferView::Pimpl::update()
945 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
946 LyXText::text_status st = bv_->text->status();
947 screen().update(bv_->text, bv_);
949 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
950 bv_->text->fullRebreak(bv_);
951 st = LyXText::NEED_MORE_REFRESH;
952 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
953 bv_->text->cursor.pos());
954 if (bv_->text->selection.set()) {
955 bv_->text->setCursor(bv_, bv_->text->selection.start,
956 bv_->text->selection.start.par(),
957 bv_->text->selection.start.pos());
958 bv_->text->setCursor(bv_, bv_->text->selection.end,
959 bv_->text->selection.end.par(),
960 bv_->text->selection.end.pos());
963 bv_->text->status(bv_, st);
964 screen().update(bv_->text, bv_);
966 // do this here instead of in the screen::update because of
968 bv_->text->status(bv_, LyXText::UNCHANGED);
974 // Values used when calling update:
976 // -2 - update, move sel_cursor if selection, fitcursor
977 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
978 // 0 - update, move sel_cursor if selection, fitcursor
979 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
980 // 3 - update, move sel_cursor if selection
983 // a simple redraw of the parts that need refresh
985 // move sel_cursor if selection -
986 // the text's sel_cursor is moved if there is selection is progress
989 // fitCursor() is called and the scrollbar updated
992 // the buffer is marked dirty.
1001 // UPDATE_ONLY = UPDATE;
1002 // UPDATE_SELECT = UPDATE | SELECT;
1003 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1004 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1006 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1007 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1008 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1009 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1010 // update(3) -> update(1) -> update(1) -> update(SELECT)
1012 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1014 owner_->updateLayoutChoice();
1016 if (!text->selection.set() && (f & SELECT)) {
1017 text->selection.cursor = text->cursor;
1020 text->fullRebreak(bv_);
1022 if (text->inset_owner) {
1023 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1024 updateInset(text->inset_owner, false);
1034 buffer_->markDirty();
1039 // Callback for cursor timer
1040 void BufferView::Pimpl::cursorToggle()
1043 cursor_timeout.restart();
1048 extern void reapSpellchecker(void);
1051 if (!bv_->theLockingInset()) {
1052 screen().cursorToggle(bv_);
1054 bv_->theLockingInset()->toggleInsetCursor(bv_);
1057 cursor_timeout.restart();
1061 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1063 if (!text->cursor.row()->previous()) {
1064 if (text->first_y > 0) {
1065 int new_y = bv_->text->first_y - workarea().workHeight();
1066 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1072 int y = text->first_y;
1073 Row * cursorrow = text->cursor.row();
1075 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1079 if (cursorrow == bv_->text->cursor.row()) {
1080 // we have a row which is higher than the workarea so we leave the
1081 // cursor on the start of the row and move only the draw up as soon
1082 // as we move the cursor or do something while inside the row (it may
1083 // span several workarea-heights) we'll move to the top again, but this
1084 // is better than just jump down and only display part of the row.
1085 new_y = bv_->text->first_y - workarea().workHeight();
1087 if (text->inset_owner) {
1088 new_y = bv_->text->cursor.iy()
1089 + bv_->theLockingInset()->insetInInsetY() + y
1090 + text->cursor.row()->height()
1091 - workarea().workHeight() + 1;
1093 new_y = text->cursor.y()
1094 - text->cursor.row()->baseline()
1095 + text->cursor.row()->height()
1096 - workarea().workHeight() + 1;
1099 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1100 if (text->cursor.row()->previous()) {
1102 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1103 text->cursor.row()->previous()->pos(), false);
1104 if (cur.y() > text->first_y) {
1105 text->cursorUp(bv_, true);
1112 void BufferView::Pimpl::cursorNext(LyXText * text)
1114 if (!text->cursor.row()->next()) {
1115 int y = text->cursor.y() - text->cursor.row()->baseline() +
1116 text->cursor.row()->height();
1117 if (y > int(text->first_y + workarea().workHeight())) {
1118 screen().draw(bv_->text, bv_,
1119 bv_->text->first_y + workarea().workHeight());
1125 int y = text->first_y + workarea().workHeight();
1126 if (text->inset_owner && !text->first_y) {
1127 y -= (bv_->text->cursor.iy()
1128 - bv_->text->first_y
1129 + bv_->theLockingInset()->insetInInsetY());
1132 text->getRowNearY(y);
1134 Row * cursorrow = text->cursor.row();
1135 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1139 if (cursorrow == bv_->text->cursor.row()) {
1140 // we have a row which is higher than the workarea so we leave the
1141 // cursor on the start of the row and move only the draw down as soon
1142 // as we move the cursor or do something while inside the row (it may
1143 // span several workarea-heights) we'll move to the top again, but this
1144 // is better than just jump down and only display part of the row.
1145 new_y = bv_->text->first_y + workarea().workHeight();
1147 if (text->inset_owner) {
1148 new_y = bv_->text->cursor.iy()
1149 + bv_->theLockingInset()->insetInInsetY()
1150 + y - text->cursor.row()->baseline();
1152 new_y = text->cursor.y() - text->cursor.row()->baseline();
1155 screen().draw(bv_->text, bv_, new_y);
1156 if (text->cursor.row()->next()) {
1158 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1159 text->cursor.row()->next()->pos(), false);
1160 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1161 text->cursorDown(bv_, true);
1168 bool BufferView::Pimpl::available() const
1170 if (buffer_ && bv_->text)
1176 void BufferView::Pimpl::beforeChange(LyXText * text)
1179 text->clearSelection();
1183 void BufferView::Pimpl::savePosition(unsigned int i)
1185 if (i >= saved_positions_num)
1187 saved_positions[i] = Position(buffer_->fileName(),
1188 bv_->text->cursor.par()->id(),
1189 bv_->text->cursor.pos());
1192 str << _("Saved bookmark") << ' ' << i;
1193 owner_->message(str.str().c_str());
1198 void BufferView::Pimpl::restorePosition(unsigned int i)
1200 if (i >= saved_positions_num)
1203 string const fname = saved_positions[i].filename;
1205 beforeChange(bv_->text);
1207 if (fname != buffer_->fileName()) {
1208 Buffer * b = bufferlist.exists(fname) ?
1209 bufferlist.getBuffer(fname) :
1210 bufferlist.loadLyXFile(fname); // don't ask, just load it
1211 if (b != 0) buffer(b);
1214 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1218 bv_->text->setCursor(bv_, par,
1219 min(par->size(), saved_positions[i].par_pos));
1221 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1224 str << _("Moved to bookmark") << ' ' << i;
1225 owner_->message(str.str().c_str());
1230 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1232 if (i >= saved_positions_num)
1235 return !saved_positions[i].filename.empty();
1239 void BufferView::Pimpl::setState()
1241 if (!lyxrc.rtl_support)
1244 LyXText * text = bv_->getLyXText();
1245 if (text->real_current_font.isRightToLeft()
1246 && !(bv_->theLockingInset()
1247 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1249 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1250 owner_->getIntl()->KeyMapSec();
1252 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1253 owner_->getIntl()->KeyMapPrim();
1258 void BufferView::Pimpl::insetUnlock()
1260 if (bv_->theLockingInset()) {
1261 bv_->theLockingInset()->insetUnlock(bv_);
1262 bv_->theLockingInset(0);
1268 void BufferView::Pimpl::showCursor()
1270 if (bv_->theLockingInset())
1271 bv_->theLockingInset()->showInsetCursor(bv_);
1273 screen().showCursor(bv_->text, bv_);
1277 void BufferView::Pimpl::hideCursor()
1279 if (!bv_->theLockingInset())
1280 screen().hideCursor();
1284 void BufferView::Pimpl::toggleSelection(bool b)
1286 if (bv_->theLockingInset())
1287 bv_->theLockingInset()->toggleSelection(bv_, b);
1288 screen().toggleSelection(bv_->text, bv_, b);
1292 void BufferView::Pimpl::toggleToggle()
1294 screen().toggleToggle(bv_->text, bv_);
1298 void BufferView::Pimpl::center()
1300 LyXText * t = bv_->text;
1303 int const half_height = workarea().workHeight() / 2;
1306 if (t->cursor.y() > half_height) {
1307 new_y = t->cursor.y() - half_height;
1310 // FIXME: can we do this w/o calling screen directly ?
1311 // This updates first_y but means the fitCursor() call
1312 // from the update(FITCUR) doesn't realise that we might
1313 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1314 // the scrollbar to be updated as it should, so we have
1315 // to do it manually. Any operation that does a center()
1316 // and also might have moved first_y must make sure to call
1317 // updateScrollbar() currently. Never mind that this is a
1318 // pretty obfuscated way of updating t->first_y
1319 screen().draw(t, bv_, new_y);
1321 update(t, BufferView::SELECT | BufferView::FITCUR);
1325 void BufferView::Pimpl::pasteClipboard(bool asPara)
1330 screen().hideCursor();
1331 beforeChange(bv_->text);
1333 string const clip(workarea().getClipboard());
1339 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1341 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1343 bv_->getLyXText()->clearSelection();
1344 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1348 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1350 workarea().putClipboard(stuff);
1355 * Dispatch functions for actions which can be valid for BufferView->text
1356 * and/or InsetText->text!!!
1361 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1363 LyXText * lt = bv_->getLyXText();
1365 if (selecting || lt->selection.mark()) {
1366 lt->setSelection(bv_);
1370 updateInset(lt->inset_owner, false);
1374 update(lt, BufferView::SELECT|BufferView::FITCUR);
1376 update(lt, BufferView::SELECT);
1378 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1379 bv_->theLockingInset()->hideInsetCursor(bv_);
1380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1384 if (!lt->selection.set())
1385 workarea().haveSelection(false);
1387 /* ---> Everytime the cursor is moved, show the current font state. */
1388 // should this too me moved out of this func?
1389 //owner->showState();
1394 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1396 LyXCursor cursor = bv_->getLyXText()->cursor;
1397 Buffer::inset_iterator it =
1398 find_if(Buffer::inset_iterator(
1399 cursor.par(), cursor.pos()),
1400 buffer_->inset_iterator_end(),
1401 lyx::compare_memfun(&Inset::lyxCode, code));
1402 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1406 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1408 string filename = filen;
1410 if (filename.empty()) {
1411 // Launch a file browser
1412 string initpath = lyxrc.document_path;
1415 string const trypath = owner_->buffer()->filePath();
1416 // If directory is writeable, use this as default.
1417 if (IsDirWriteable(trypath))
1421 FileDialog fileDlg(bv_->owner(),
1422 _("Select LyX document to insert"),
1424 make_pair(string(_("Documents|#o#O")),
1425 string(lyxrc.document_path)),
1426 make_pair(string(_("Examples|#E#e")),
1427 string(AddPath(system_lyxdir, "examples"))));
1429 FileDialog::Result result =
1430 fileDlg.Select(initpath,
1431 _("*.lyx| LyX Documents (*.lyx)"));
1433 if (result.first == FileDialog::Later)
1436 filename = result.second;
1438 // check selected filename
1439 if (filename.empty()) {
1440 owner_->message(_("Canceled."));
1445 // get absolute path of file and add ".lyx" to the filename if
1447 filename = FileSearch(string(), filename, "lyx");
1449 string const disp_fn(MakeDisplayPath(filename));
1452 s1 << _("Inserting document") << ' '
1453 << disp_fn << " ...";
1454 owner_->message(s1.str().c_str());
1455 bool const res = bv_->insertLyXFile(filename);
1458 str << _("Document") << ' ' << disp_fn
1459 << ' ' << _("inserted.");
1460 owner_->message(str.str().c_str());
1463 str << _("Could not insert document") << ' '
1465 owner_->message(str.str().c_str());
1470 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1472 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1473 << action <<"] arg[" << argument << "]" << endl;
1475 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1478 // --- Misc -------------------------------------------
1482 LyXText * lt = bv_->getLyXText();
1483 lt->toggleAppendix(bv_);
1486 | BufferView::FITCUR
1487 | BufferView::CHANGE);
1492 case LFUN_TOC_INSERT:
1494 InsetCommandParams p;
1495 p.setCmdName("tableofcontents");
1496 Inset * inset = new InsetTOC(p);
1497 if (!insertInset(inset, tclass.defaultLayoutName()))
1502 case LFUN_SCROLL_INSET:
1503 // this is not handled here as this funktion is only aktive
1504 // if we have a locking_inset and that one is (or contains)
1508 case LFUN_INSET_GRAPHICS:
1510 Inset * new_inset = new InsetGraphics;
1511 if (!insertInset(new_inset)) {
1514 // this is need because you don't use a inset->Edit()
1515 updateInset(new_inset, true);
1516 new_inset->edit(bv_);
1526 case LFUN_PASTESELECTION:
1528 bool asPara = false;
1529 if (argument == "paragraph")
1531 pasteClipboard(asPara);
1543 case LFUN_LAYOUT_COPY:
1544 bv_->copyEnvironment();
1547 case LFUN_LAYOUT_PASTE:
1548 bv_->pasteEnvironment();
1552 case LFUN_GOTOERROR:
1553 gotoInset(Inset::ERROR_CODE, false);
1557 gotoInset(Inset::IGNORE_CODE, false);
1560 case LFUN_REFERENCE_GOTO:
1562 vector<Inset::Code> tmp;
1563 tmp.push_back(Inset::LABEL_CODE);
1564 tmp.push_back(Inset::REF_CODE);
1565 gotoInset(tmp, true);
1569 case LFUN_HYPHENATION:
1570 specialChar(InsetSpecialChar::HYPHENATION);
1573 case LFUN_LIGATURE_BREAK:
1574 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1578 specialChar(InsetSpecialChar::LDOTS);
1581 case LFUN_END_OF_SENTENCE:
1582 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1585 case LFUN_MENU_SEPARATOR:
1586 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1593 case LFUN_DEPTH_MIN:
1594 changeDepth(bv_, bv_->getLyXText(), -1);
1597 case LFUN_DEPTH_PLUS:
1598 changeDepth(bv_, bv_->getLyXText(), 1);
1602 owner_->getDialogs()->setUserFreeFont();
1605 case LFUN_FILE_INSERT:
1606 MenuInsertLyXFile(argument);
1609 case LFUN_FILE_INSERT_ASCII_PARA:
1610 InsertAsciiFile(bv_, argument, true);
1613 case LFUN_FILE_INSERT_ASCII:
1614 InsertAsciiFile(bv_, argument, false);
1619 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1620 << argument << endl;
1622 // This is not the good solution to the empty argument
1623 // problem, but it will hopefully suffice for 1.2.0.
1624 // The correct solution would be to augument the
1625 // function list/array with information about what
1626 // functions needs arguments and their type.
1627 if (argument.empty()) {
1628 owner_->getLyXFunc()->setErrorMessage(
1629 _("LyX function 'layout' needs an argument."));
1633 // Derive layout number from given argument (string)
1634 // and current buffer's textclass (number). */
1635 bool hasLayout = tclass.hasLayout(argument);
1636 string layout = argument;
1638 // If the entry is obsolete, use the new one instead.
1640 string const & obs = tclass[layout]->obsoleted_by();
1646 owner_->getLyXFunc()->setErrorMessage(
1647 string(N_("Layout ")) + argument +
1652 bool change_layout = (current_layout != layout);
1653 LyXText * lt = bv_->getLyXText();
1654 if (!change_layout && lt->selection.set() &&
1655 lt->selection.start.par() != lt->selection.end.par())
1657 Paragraph * spar = lt->selection.start.par();
1658 Paragraph * epar = lt->selection.end.par()->next();
1659 while(spar != epar) {
1660 if (spar->layout()->name() != current_layout) {
1661 change_layout = true;
1666 if (change_layout) {
1668 current_layout = layout;
1671 | BufferView::FITCUR);
1672 lt->setLayout(bv_, layout);
1673 owner_->setLayout(layout);
1676 | BufferView::FITCUR
1677 | BufferView::CHANGE);
1684 lang(bv_, argument);
1686 owner_->showState();
1691 owner_->showState();
1696 owner_->showState();
1701 owner_->showState();
1706 owner_->showState();
1711 owner_->showState();
1716 owner_->showState();
1721 owner_->showState();
1724 case LFUN_UNDERLINE:
1726 owner_->showState();
1729 case LFUN_FONT_SIZE:
1730 fontSize(bv_, argument);
1731 owner_->showState();
1734 case LFUN_FONT_STATE:
1735 owner_->getLyXFunc()->setMessage(currentState(bv_));
1738 case LFUN_UPCASE_WORD:
1740 LyXText * lt = bv_->getLyXText();
1744 | BufferView::FITCUR);
1745 lt->changeCase(bv_, LyXText::text_uppercase);
1746 if (lt->inset_owner)
1747 updateInset(lt->inset_owner, true);
1750 | BufferView::FITCUR
1751 | BufferView::CHANGE);
1755 case LFUN_LOWCASE_WORD:
1757 LyXText * lt = bv_->getLyXText();
1759 update(lt, BufferView::SELECT|BufferView::FITCUR);
1760 lt->changeCase(bv_, LyXText::text_lowercase);
1761 if (lt->inset_owner)
1762 updateInset(lt->inset_owner, true);
1765 | BufferView::FITCUR
1766 | BufferView::CHANGE);
1770 case LFUN_CAPITALIZE_WORD:
1772 LyXText * lt = bv_->getLyXText();
1774 update(lt, BufferView::SELECT|BufferView::FITCUR);
1775 lt->changeCase(bv_, LyXText::text_capitalization);
1776 if (lt->inset_owner)
1777 updateInset(lt->inset_owner, true);
1780 | BufferView::FITCUR
1781 | BufferView::CHANGE);
1785 case LFUN_TRANSPOSE_CHARS:
1787 LyXText * lt = bv_->getLyXText();
1789 update(lt, BufferView::SELECT|BufferView::FITCUR);
1790 lt->transposeChars(*bv_);
1791 if (lt->inset_owner)
1792 updateInset(lt->inset_owner, true);
1795 | BufferView::FITCUR
1796 | BufferView::CHANGE);
1801 case LFUN_INSERT_LABEL:
1802 MenuInsertLabel(bv_, argument);
1805 case LFUN_REF_INSERT:
1806 if (argument.empty()) {
1807 InsetCommandParams p("ref");
1808 owner_->getDialogs()->createRef(p.getAsString());
1810 InsetCommandParams p;
1811 p.setFromString(argument);
1813 InsetRef * inset = new InsetRef(p, *buffer_);
1814 if (!insertInset(inset))
1817 updateInset(inset, true);
1821 case LFUN_BOOKMARK_SAVE:
1822 savePosition(strToUnsignedInt(argument));
1825 case LFUN_BOOKMARK_GOTO:
1826 restorePosition(strToUnsignedInt(argument));
1831 string label(argument);
1832 if (label.empty()) {
1834 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1836 label = inset->getContents();
1841 if (!label.empty()) {
1842 //bv_->savePosition(0);
1843 if (!bv_->gotoLabel(label))
1844 Alert::alert(_("Error"),
1845 _("Couldn't find this label"),
1846 _("in current document."));
1851 // --- Cursor Movements -----------------------------
1854 LyXText * lt = bv_->getLyXText();
1856 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1857 if (!lt->selection.mark())
1859 update(lt, BufferView::SELECT|BufferView::FITCUR);
1861 lt->cursorLeft(bv_, false);
1862 if (lt->cursor.pos() < lt->cursor.par()->size()
1863 && lt->cursor.par()->isInset(lt->cursor.pos())
1864 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1865 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1866 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1868 tmpinset->edit(bv_, false);
1870 tmpinset->edit(bv_);
1874 lt->cursorRight(bv_, false);
1876 moveCursorUpdate(false);
1877 owner_->showState();
1883 // This is soooo ugly. Isn`t it possible to make
1884 // it simpler? (Lgb)
1885 LyXText * lt = bv_->getLyXText();
1886 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1887 if (!lt->selection.mark())
1889 update(lt, BufferView::SELECT|BufferView::FITCUR);
1890 LyXCursor const cur = lt->cursor;
1892 lt->cursorLeft(bv_, false);
1893 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1894 lt->cursor.pos() < lt->cursor.par()->size() &&
1895 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1896 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1897 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1898 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1900 tmpinset->edit(bv_);
1902 tmpinset->edit(bv_, false);
1906 lt->cursorRight(bv_, false);
1909 moveCursorUpdate(false);
1910 owner_->showState();
1916 LyXText * lt = bv_->getLyXText();
1918 if (!lt->selection.mark())
1920 update(lt, BufferView::UPDATE);
1923 moveCursorUpdate(false);
1924 owner_->showState();
1930 LyXText * lt = bv_->getLyXText();
1932 if (!lt->selection.mark())
1934 update(lt, BufferView::UPDATE);
1935 lt->cursorDown(bv_);
1937 moveCursorUpdate(false);
1938 owner_->showState();
1942 case LFUN_UP_PARAGRAPH:
1944 LyXText * lt = bv_->getLyXText();
1946 if (!lt->selection.mark())
1948 update(lt, BufferView::UPDATE);
1949 lt->cursorUpParagraph(bv_);
1951 moveCursorUpdate(false);
1952 owner_->showState();
1956 case LFUN_DOWN_PARAGRAPH:
1958 LyXText * lt = bv_->getLyXText();
1960 if (!lt->selection.mark())
1962 update(lt, BufferView::UPDATE);
1963 lt->cursorDownParagraph(bv_);
1965 moveCursorUpdate(false);
1966 owner_->showState();
1972 LyXText * lt = bv_->getLyXText();
1974 if (!lt->selection.mark())
1976 update(lt, BufferView::UPDATE);
1979 moveCursorUpdate(false, false);
1980 owner_->showState();
1986 LyXText * lt = bv_->getLyXText();
1988 if (!lt->selection.mark())
1990 update(lt, BufferView::UPDATE);
1993 moveCursorUpdate(false, false);
1994 owner_->showState();
2000 LyXText * lt = bv_->getLyXText();
2002 if (!lt->selection.mark())
2004 update(lt, BufferView::SELECT|BufferView::FITCUR);
2005 lt->cursorHome(bv_);
2007 moveCursorUpdate(false);
2008 owner_->showState();
2014 LyXText * lt = bv_->getLyXText();
2016 if (!lt->selection.mark())
2019 BufferView::SELECT|BufferView::FITCUR);
2022 moveCursorUpdate(false);
2023 owner_->showState();
2027 case LFUN_SHIFT_TAB:
2030 LyXText * lt = bv_->getLyXText();
2032 if (!lt->selection.mark())
2035 BufferView::SELECT|BufferView::FITCUR);
2038 moveCursorUpdate(false);
2039 owner_->showState();
2043 case LFUN_WORDRIGHT:
2045 LyXText * lt = bv_->getLyXText();
2047 if (!lt->selection.mark())
2049 update(lt, BufferView::SELECT|BufferView::FITCUR);
2050 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2051 lt->cursorLeftOneWord(bv_);
2053 lt->cursorRightOneWord(bv_);
2055 moveCursorUpdate(false);
2056 owner_->showState();
2062 LyXText * lt = bv_->getLyXText();
2064 if (!lt->selection.mark())
2066 update(lt, BufferView::SELECT|BufferView::FITCUR);
2067 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2068 lt->cursorRightOneWord(bv_);
2070 lt->cursorLeftOneWord(bv_);
2072 moveCursorUpdate(false);
2073 owner_->showState();
2077 case LFUN_BEGINNINGBUF:
2079 LyXText * lt = bv_->getLyXText();
2081 if (!lt->selection.mark())
2084 BufferView::SELECT|BufferView::FITCUR);
2087 moveCursorUpdate(false);
2088 owner_->showState();
2094 LyXText * lt = bv_->getLyXText();
2096 if (!lt->selection.mark())
2099 BufferView::SELECT|BufferView::FITCUR);
2100 lt->cursorBottom(bv_);
2102 moveCursorUpdate(false);
2103 owner_->showState();
2107 /* cursor selection ---------------------------- */
2110 LyXText * lt = bv_->getLyXText();
2113 BufferView::SELECT|BufferView::FITCUR);
2114 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2115 lt->cursorLeft(bv_);
2117 lt->cursorRight(bv_);
2119 moveCursorUpdate(true);
2120 owner_->showState();
2126 LyXText * lt = bv_->getLyXText();
2129 BufferView::SELECT|BufferView::FITCUR);
2130 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2131 lt->cursorRight(bv_);
2133 lt->cursorLeft(bv_);
2135 moveCursorUpdate(true);
2136 owner_->showState();
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 lt->cursorUp(bv_, true);
2148 moveCursorUpdate(true);
2149 owner_->showState();
2155 LyXText * lt = bv_->getLyXText();
2158 BufferView::SELECT|BufferView::FITCUR);
2159 lt->cursorDown(bv_, true);
2161 moveCursorUpdate(true);
2162 owner_->showState();
2166 case LFUN_UP_PARAGRAPHSEL:
2168 LyXText * lt = bv_->getLyXText();
2171 BufferView::SELECT|BufferView::FITCUR);
2172 lt->cursorUpParagraph(bv_);
2174 moveCursorUpdate(true);
2175 owner_->showState();
2179 case LFUN_DOWN_PARAGRAPHSEL:
2181 LyXText * lt = bv_->getLyXText();
2184 BufferView::SELECT|BufferView::FITCUR);
2185 lt->cursorDownParagraph(bv_);
2187 moveCursorUpdate(true);
2188 owner_->showState();
2194 LyXText * lt = bv_->getLyXText();
2196 update(lt, BufferView::SELECT|BufferView::FITCUR);
2199 moveCursorUpdate(true);
2200 owner_->showState();
2206 LyXText * lt = bv_->getLyXText();
2208 update(lt, BufferView::SELECT|BufferView::FITCUR);
2211 moveCursorUpdate(true);
2212 owner_->showState();
2218 LyXText * lt = bv_->getLyXText();
2220 update(lt, BufferView::SELECT|BufferView::FITCUR);
2221 lt->cursorHome(bv_);
2223 moveCursorUpdate(true);
2224 owner_->showState();
2230 LyXText * lt = bv_->getLyXText();
2232 update(lt, BufferView::SELECT|BufferView::FITCUR);
2235 moveCursorUpdate(true);
2236 owner_->showState();
2240 case LFUN_WORDRIGHTSEL:
2242 LyXText * lt = bv_->getLyXText();
2244 update(lt, BufferView::SELECT|BufferView::FITCUR);
2245 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2246 lt->cursorLeftOneWord(bv_);
2248 lt->cursorRightOneWord(bv_);
2250 moveCursorUpdate(true);
2251 owner_->showState();
2255 case LFUN_WORDLEFTSEL:
2257 LyXText * lt = bv_->getLyXText();
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2260 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2261 lt->cursorRightOneWord(bv_);
2263 lt->cursorLeftOneWord(bv_);
2265 moveCursorUpdate(true);
2266 owner_->showState();
2270 case LFUN_BEGINNINGBUFSEL:
2272 LyXText * lt = bv_->getLyXText();
2274 if (lt->inset_owner)
2276 update(lt, BufferView::SELECT|BufferView::FITCUR);
2279 moveCursorUpdate(true);
2280 owner_->showState();
2284 case LFUN_ENDBUFSEL:
2286 LyXText * lt = bv_->getLyXText();
2288 if (lt->inset_owner)
2291 BufferView::SELECT|BufferView::FITCUR);
2292 lt->cursorBottom(bv_);
2294 moveCursorUpdate(true);
2295 owner_->showState();
2299 // --- text changing commands ------------------------
2300 case LFUN_BREAKLINE:
2302 LyXText * lt = bv_->getLyXText();
2305 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2308 | BufferView::FITCUR
2309 | BufferView::CHANGE);
2310 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2311 moveCursorUpdate(false);
2315 case LFUN_PROTECTEDSPACE:
2317 LyXText * lt = bv_->getLyXText();
2318 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2320 if (style->free_spacing) {
2321 lt->insertChar(bv_, ' ');
2324 | BufferView::FITCUR
2325 | BufferView::CHANGE);
2327 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2329 moveCursorUpdate(false);
2335 LyXText * lt = bv_->getLyXText();
2337 if (lt->selection.mark()) {
2341 | BufferView::FITCUR);
2342 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2345 lt->selection.mark(true);
2348 | BufferView::FITCUR);
2349 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2351 lt->selection.cursor = lt->cursor;
2357 LyXText * lt = bv_->getLyXText();
2359 if (!lt->selection.set()) {
2361 lt->selection.cursor = lt->cursor;
2364 | BufferView::FITCUR
2365 | BufferView::CHANGE);
2366 // It is possible to make it a lot faster still
2367 // just comment out the line below...
2372 moveCursorUpdate(false);
2373 owner_->showState();
2378 case LFUN_DELETE_SKIP:
2380 LyXText * lt = bv_->getLyXText();
2382 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2384 LyXCursor cursor = lt->cursor;
2386 if (!lt->selection.set()) {
2387 if (cursor.pos() == cursor.par()->size()) {
2388 lt->cursorRight(bv_);
2389 cursor = lt->cursor;
2390 if (cursor.pos() == 0
2391 && !(cursor.par()->params().spaceTop()
2392 == VSpace (VSpace::NONE))) {
2395 cursor.par()->params().lineTop(),
2396 cursor.par()->params().lineBottom(),
2397 cursor.par()->params().pagebreakTop(),
2398 cursor.par()->params().pagebreakBottom(),
2399 VSpace(VSpace::NONE),
2400 cursor.par()->params().spaceBottom(),
2401 cursor.par()->params().spacing(),
2402 cursor.par()->params().align(),
2403 cursor.par()->params().labelWidthString(), 0);
2404 lt->cursorLeft(bv_);
2407 | BufferView::FITCUR
2408 | BufferView::CHANGE);
2410 lt->cursorLeft(bv_);
2412 lt->selection.cursor = lt->cursor;
2415 | BufferView::FITCUR
2416 | BufferView::CHANGE);
2420 lt->selection.cursor = lt->cursor;
2423 | BufferView::FITCUR
2424 | BufferView::CHANGE);
2432 /* -------> Delete word forward. */
2433 case LFUN_DELETE_WORD_FORWARD:
2434 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2435 bv_->getLyXText()->deleteWordForward(bv_);
2436 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2437 moveCursorUpdate(false);
2438 owner_->showState();
2441 /* -------> Delete word backward. */
2442 case LFUN_DELETE_WORD_BACKWARD:
2444 LyXText * lt = bv_->getLyXText();
2446 update(lt, BufferView::SELECT|BufferView::FITCUR);
2447 lt->deleteWordBackward(bv_);
2450 | BufferView::FITCUR
2451 | BufferView::CHANGE);
2452 moveCursorUpdate(false);
2453 owner_->showState();
2457 /* -------> Kill to end of line. */
2458 case LFUN_DELETE_LINE_FORWARD:
2460 LyXText * lt = bv_->getLyXText();
2462 update(lt, BufferView::SELECT|BufferView::FITCUR);
2463 lt->deleteLineForward(bv_);
2466 | BufferView::FITCUR
2467 | BufferView::CHANGE);
2468 moveCursorUpdate(false);
2472 /* -------> Set mark off. */
2475 LyXText * lt = bv_->getLyXText();
2478 update(lt, BufferView::SELECT|BufferView::FITCUR);
2479 lt->selection.cursor = lt->cursor;
2480 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2484 /* -------> Set mark on. */
2487 LyXText * lt = bv_->getLyXText();
2490 lt->selection.mark(true);
2491 update(lt, BufferView::SELECT|BufferView::FITCUR);
2492 lt->selection.cursor = lt->cursor;
2493 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2497 case LFUN_BACKSPACE:
2499 LyXText * lt = bv_->getLyXText();
2501 if (!lt->selection.set()) {
2502 if (owner_->getIntl()->getTransManager().backspace()) {
2504 lt->selection.cursor = lt->cursor;
2507 | BufferView::FITCUR
2508 | BufferView::CHANGE);
2509 // It is possible to make it a lot faster still
2510 // just comment out the line below...
2516 owner_->showState();
2521 case LFUN_BACKSPACE_SKIP:
2523 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2524 LyXText * lt = bv_->getLyXText();
2526 LyXCursor cursor = lt->cursor;
2528 if (!lt->selection.set()) {
2529 if (cursor.pos() == 0
2530 && !(cursor.par()->params().spaceTop()
2531 == VSpace (VSpace::NONE))) {
2534 cursor.par()->params().lineTop(),
2535 cursor.par()->params().lineBottom(),
2536 cursor.par()->params().pagebreakTop(),
2537 cursor.par()->params().pagebreakBottom(),
2538 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2539 cursor.par()->params().spacing(),
2540 cursor.par()->params().align(),
2541 cursor.par()->params().labelWidthString(), 0);
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2548 lt->selection.cursor = cursor;
2551 | BufferView::FITCUR
2552 | BufferView::CHANGE);
2559 case LFUN_BREAKPARAGRAPH:
2561 LyXText * lt = bv_->getLyXText();
2564 lt->breakParagraph(bv_, 0);
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2569 lt->selection.cursor = lt->cursor;
2571 owner_->showState();
2575 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2577 LyXText * lt = bv_->getLyXText();
2580 lt->breakParagraph(bv_, 1);
2583 | BufferView::FITCUR
2584 | BufferView::CHANGE);
2585 lt->selection.cursor = lt->cursor;
2587 owner_->showState();
2591 case LFUN_BREAKPARAGRAPH_SKIP:
2593 // When at the beginning of a paragraph, remove
2594 // indentation and add a "defskip" at the top.
2595 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2596 LyXText * lt = bv_->getLyXText();
2598 LyXCursor cursor = lt->cursor;
2601 if (cursor.pos() == 0) {
2602 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2605 cursor.par()->params().lineTop(),
2606 cursor.par()->params().lineBottom(),
2607 cursor.par()->params().pagebreakTop(),
2608 cursor.par()->params().pagebreakBottom(),
2609 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2610 cursor.par()->params().spacing(),
2611 cursor.par()->params().align(),
2612 cursor.par()->params().labelWidthString(), 1);
2613 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2617 lt->breakParagraph(bv_, 0);
2618 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2623 | BufferView::FITCUR
2624 | BufferView::CHANGE);
2625 lt->selection.cursor = cursor;
2627 owner_->showState();
2631 case LFUN_PARAGRAPH_SPACING:
2633 LyXText * lt = bv_->getLyXText();
2635 Paragraph * par = lt->cursor.par();
2636 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2637 float cur_value = 1.0;
2638 if (cur_spacing == Spacing::Other) {
2639 cur_value = par->params().spacing().getValue();
2642 istringstream istr(argument.c_str());
2646 Spacing::Space new_spacing = cur_spacing;
2647 float new_value = cur_value;
2649 lyxerr << "Missing argument to `paragraph-spacing'"
2651 } else if (tmp == "single") {
2652 new_spacing = Spacing::Single;
2653 } else if (tmp == "onehalf") {
2654 new_spacing = Spacing::Onehalf;
2655 } else if (tmp == "double") {
2656 new_spacing = Spacing::Double;
2657 } else if (tmp == "other") {
2658 new_spacing = Spacing::Other;
2661 lyxerr << "new_value = " << tmpval << endl;
2664 } else if (tmp == "default") {
2665 new_spacing = Spacing::Default;
2667 lyxerr << _("Unknown spacing argument: ")
2668 << argument << endl;
2670 if (cur_spacing != new_spacing || cur_value != new_value) {
2671 par->params().spacing(Spacing(new_spacing, new_value));
2672 lt->redoParagraph(bv_);
2675 | BufferView::FITCUR
2676 | BufferView::CHANGE);
2681 case LFUN_INSET_TOGGLE:
2683 LyXText * lt = bv_->getLyXText();
2686 update(lt, BufferView::SELECT|BufferView::FITCUR);
2687 lt->toggleInset(bv_);
2688 update(lt, BufferView::SELECT|BufferView::FITCUR);
2700 InsetCommandParams p;
2701 if (action == LFUN_HTMLURL)
2702 p.setCmdName("htmlurl");
2704 p.setCmdName("url");
2705 owner_->getDialogs()->createUrl(p.getAsString());
2709 case LFUN_INSERT_URL:
2711 InsetCommandParams p;
2712 p.setFromString(argument);
2714 InsetUrl * inset = new InsetUrl(p);
2715 if (!insertInset(inset))
2718 updateInset(inset, true);
2722 case LFUN_INSET_ERT:
2723 insertAndEditInset(new InsetERT(buffer_->params));
2726 case LFUN_INSET_EXTERNAL:
2727 insertAndEditInset(new InsetExternal);
2730 case LFUN_INSET_FOOTNOTE:
2731 insertAndEditInset(new InsetFoot(buffer_->params));
2734 case LFUN_INSET_MARGINAL:
2735 insertAndEditInset(new InsetMarginal(buffer_->params));
2738 case LFUN_INSET_MINIPAGE:
2739 insertAndEditInset(new InsetMinipage(buffer_->params));
2742 case LFUN_INSERT_NOTE:
2743 insertAndEditInset(new InsetNote(buffer_->params));
2746 case LFUN_INSET_FLOAT:
2747 // check if the float type exist
2748 if (floatList.typeExist(argument)) {
2749 insertAndEditInset(new InsetFloat(buffer_->params,
2752 lyxerr << "Non-existent float type: "
2753 << argument << endl;
2757 case LFUN_INSET_WIDE_FLOAT:
2758 // check if the float type exist
2759 if (floatList.typeExist(argument)) {
2760 InsetFloat * new_inset =
2761 new InsetFloat(buffer_->params, argument);
2762 new_inset->wide(true);
2763 insertAndEditInset(new_inset);
2765 lyxerr << "Non-existent float type: "
2766 << argument << endl;
2771 case LFUN_INSET_LIST:
2772 insertAndEditInset(new InsetList);
2775 case LFUN_INSET_THEOREM:
2776 insertAndEditInset(new InsetTheorem);
2780 case LFUN_INSET_CAPTION:
2782 // Do we have a locking inset...
2783 if (bv_->theLockingInset()) {
2784 lyxerr << "Locking inset code: "
2785 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2786 InsetCaption * new_inset =
2787 new InsetCaption(buffer_->params);
2788 new_inset->setOwner(bv_->theLockingInset());
2789 new_inset->setAutoBreakRows(true);
2790 new_inset->setDrawFrame(0, InsetText::LOCKED);
2791 new_inset->setFrameColor(0, LColor::captionframe);
2792 if (insertInset(new_inset))
2793 new_inset->edit(bv_);
2800 case LFUN_INSET_TABULAR:
2804 if (!argument.empty())
2805 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2806 InsetTabular * new_inset =
2807 new InsetTabular(*buffer_, r, c);
2809 bv_->getLyXText()->real_current_font.isRightToLeft();
2810 if (!open_new_inset(new_inset, rtl))
2815 // --- lyxserver commands ----------------------------
2817 case LFUN_CHARATCURSOR:
2819 pos_type pos = bv_->getLyXText()->cursor.pos();
2820 if (pos < bv_->getLyXText()->cursor.par()->size())
2821 owner_->getLyXFunc()->setMessage(
2822 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2824 owner_->getLyXFunc()->setMessage("EOF");
2829 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2831 + tostr(bv_->getLyXText()->cursor.y()));
2838 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2839 lyxerr << "SETXY: Could not parse coordinates in '"
2840 << argument << std::endl;
2842 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2846 case LFUN_GETLAYOUT:
2847 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2852 LyXFont & font = bv_->getLyXText()->current_font;
2853 if (font.shape() == LyXFont::ITALIC_SHAPE)
2854 owner_->getLyXFunc()->setMessage("E");
2855 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2856 owner_->getLyXFunc()->setMessage("N");
2858 owner_->getLyXFunc()->setMessage("0");
2863 // --- accented characters ---------------------------
2866 case LFUN_CIRCUMFLEX:
2876 case LFUN_SPECIAL_CARON:
2879 case LFUN_HUNG_UMLAUT:
2882 if (argument.empty()) {
2884 owner_->getLyXFunc()->handleKeyFunc(action);
2886 owner_->getLyXFunc()->handleKeyFunc(action);
2887 owner_->getIntl()->getTransManager()
2888 .TranslateAndInsert(argument[0], bv_->getLyXText());
2889 update(bv_->getLyXText(),
2891 | BufferView::FITCUR
2892 | BufferView::CHANGE);
2897 mathDispatch(bv_, argument);
2900 case LFUN_MATH_MACRO:
2901 mathDispatchMathMacro(bv_, argument);
2904 case LFUN_MATH_DELIM:
2905 mathDispatchMathDelim(bv_, argument);
2908 case LFUN_INSERT_MATRIX:
2909 mathDispatchInsertMatrix(bv_, argument);
2912 case LFUN_INSERT_MATH:
2913 mathDispatchInsertMath(bv_, argument);
2916 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2917 mathDispatchMathImportSelection(bv_, argument);
2920 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2921 mathDispatchMathDisplay(bv_, argument);
2924 case LFUN_MATH_MODE: // Open or create an inlined math inset
2925 mathDispatchMathMode(bv_, argument);
2928 case LFUN_GREEK: // Insert a single greek letter
2929 mathDispatchGreek(bv_, argument);
2932 case LFUN_CITATION_INSERT:
2934 InsetCommandParams p;
2935 p.setFromString(argument);
2937 InsetCitation * inset = new InsetCitation(p);
2938 if (!insertInset(inset))
2941 updateInset(inset, true);
2945 case LFUN_INSERT_BIBTEX:
2947 // ale970405+lasgoutt970425
2948 // The argument can be up to two tokens separated
2949 // by a space. The first one is the bibstyle.
2950 string const db = token(argument, ' ', 0);
2951 string const bibstyle = token(argument, ' ', 1);
2953 InsetCommandParams p("BibTeX", db, bibstyle);
2954 InsetBibtex * inset = new InsetBibtex(p);
2956 if (insertInset(inset)) {
2957 if (argument.empty())
2964 // BibTeX data bases
2965 case LFUN_BIBDB_ADD:
2967 InsetBibtex * inset =
2968 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2970 inset->addDatabase(argument);
2975 case LFUN_BIBDB_DEL:
2977 InsetBibtex * inset =
2978 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2980 inset->delDatabase(argument);
2985 case LFUN_BIBTEX_STYLE:
2987 InsetBibtex * inset =
2988 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2990 inset->setOptions(argument);
2995 case LFUN_INDEX_INSERT:
2997 string entry = argument;
2998 if (entry.empty()) {
2999 entry = bv_->getLyXText()->getStringToIndex(bv_);
3002 if (entry.empty()) {
3003 owner_->getDialogs()->createIndex();
3007 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3009 if (!insertInset(inset)) {
3012 updateInset(inset, true);
3017 case LFUN_INDEX_PRINT:
3019 InsetCommandParams p("printindex");
3020 Inset * inset = new InsetPrintIndex(p);
3021 if (!insertInset(inset, tclass.defaultLayoutName()))
3026 case LFUN_PARENTINSERT:
3028 InsetCommandParams p("lyxparent", argument);
3029 Inset * inset = new InsetParent(p, *buffer_);
3030 if (!insertInset(inset, tclass.defaultLayoutName()))
3036 case LFUN_CHILD_INSERT:
3038 InsetInclude::Params p;
3039 p.cparams.setFromString(argument);
3040 p.masterFilename_ = buffer_->fileName();
3042 InsetInclude * inset = new InsetInclude(p);
3043 if (!insertInset(inset))
3046 updateInset(inset, true);
3047 bv_->owner()->getDialogs()->showInclude(inset);
3052 case LFUN_FLOAT_LIST:
3053 if (floatList.typeExist(argument)) {
3054 Inset * inset = new InsetFloatList(argument);
3055 if (!insertInset(inset, tclass.defaultLayoutName()))
3058 lyxerr << "Non-existent float type: "
3059 << argument << endl;
3063 case LFUN_THESAURUS_ENTRY:
3065 string arg = argument;
3068 arg = bv_->getLyXText()->selectionAsString(buffer_,
3072 if (arg.size() > 100 || arg.empty()) {
3073 // Get word or selection
3074 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3075 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3076 // FIXME: where is getLyXText()->unselect(bv_) ?
3080 bv_->owner()->getDialogs()->showThesaurus(arg);
3084 case LFUN_SELFINSERT:
3086 if (argument.empty()) break;
3088 /* Automatically delete the currently selected
3089 * text and replace it with what is being
3090 * typed in now. Depends on lyxrc settings
3091 * "auto_region_delete", which defaults to
3094 LyXText * lt = bv_->getLyXText();
3096 if (lyxrc.auto_region_delete) {
3097 if (lt->selection.set()) {
3098 lt->cutSelection(bv_, false, false);
3101 | BufferView::FITCUR
3102 | BufferView::CHANGE);
3104 workarea().haveSelection(false);
3108 LyXFont const old_font(lt->real_current_font);
3110 string::const_iterator cit = argument.begin();
3111 string::const_iterator end = argument.end();
3112 for (; cit != end; ++cit) {
3113 owner_->getIntl()->getTransManager().
3114 TranslateAndInsert(*cit, lt);
3119 | BufferView::FITCUR
3120 | BufferView::CHANGE);
3122 lt->selection.cursor = lt->cursor;
3123 moveCursorUpdate(false);
3125 // real_current_font.number can change so we need to
3126 // update the minibuffer
3127 if (old_font != lt->real_current_font)
3128 owner_->showState();
3133 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3135 time_t now_time_t = time(NULL);
3136 struct tm * now_tm = localtime(&now_time_t);
3137 setlocale(LC_TIME, "");
3139 if (!argument.empty())
3142 arg = lyxrc.date_insert_format;
3144 int const datetmp_len =
3145 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3147 LyXText * lt = bv_->getLyXText();
3149 for (int i = 0; i < datetmp_len; i++) {
3150 lt->insertChar(bv_, datetmp[i]);
3153 | BufferView::FITCUR
3154 | BufferView::CHANGE);
3157 lt->selection.cursor = lt->cursor;
3158 moveCursorUpdate(false);
3162 case LFUN_UNKNOWN_ACTION:
3163 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3174 void BufferView::Pimpl::newline()
3177 LyXText * lt = bv_->getLyXText();
3181 | BufferView::FITCUR);
3182 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3185 | BufferView::FITCUR
3186 | BufferView::CHANGE);
3191 void BufferView::Pimpl::hfill()
3194 LyXText * lt = bv_->getLyXText();
3198 | BufferView::FITCUR);
3199 lt->insertChar(bv_, Paragraph::META_HFILL);
3202 | BufferView::FITCUR
3203 | BufferView::CHANGE);
3208 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3211 LyXText * lt = bv_->getLyXText();
3214 update(lt, BufferView::SELECT|BufferView::FITCUR);
3215 InsetSpecialChar * new_inset =
3216 new InsetSpecialChar(kind);
3217 if (!insertInset(new_inset))
3220 updateInset(new_inset, true);
3225 void BufferView::Pimpl::smartQuote()
3227 LyXText const * lt = bv_->getLyXText();
3228 Paragraph const * par = lt->cursor.par();
3229 pos_type pos = lt->cursor.pos();
3233 || (par->isInset(pos - 1)
3234 && par->getInset(pos - 1)->isSpace()))
3237 c = par->getChar(pos - 1);
3242 LyXLayout_ptr const & style = par->layout();
3244 if (style->pass_thru ||
3245 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3246 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3250 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3253 if (insertInset(inset))
3258 bool gotsel = false;
3260 if (bv_->getLyXText()->selection.set()) {
3261 bv_->getLyXText()->cutSelection(bv_, true, false);
3265 if (insertInset(inset)) {
3268 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION);
3276 // Open and lock an updatable inset
3277 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3279 LyXText * lt = bv_->getLyXText();
3283 if (!insertInset(new_inset)) {
3287 new_inset->edit(bv_, !behind);
3292 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3294 // if we are in a locking inset we should try to insert the
3295 // inset there otherwise this is a illegal function now
3296 if (bv_->theLockingInset()) {
3297 if (bv_->theLockingInset()->insetAllowed(inset))
3298 return bv_->theLockingInset()->insertInset(bv_, inset);
3302 // not quite sure if we want this...
3303 setCursorParUndo(bv_);
3306 beforeChange(bv_->text);
3307 if (!lout.empty()) {
3308 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3309 bv_->text->breakParagraph(bv_);
3310 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3312 if (bv_->text->cursor.par()->size()) {
3313 bv_->text->cursorLeft(bv_);
3315 bv_->text->breakParagraph(bv_);
3316 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3320 LyXTextClass const & tclass =
3321 textclasslist[buffer_->params.textclass];
3322 bool hasLayout = tclass.hasLayout(lres);
3323 string lay = tclass.defaultLayoutName();
3325 if (hasLayout != false) {
3329 // layout not fount using default
3330 lay = tclass.defaultLayoutName();
3333 bv_->text->setLayout(bv_, lay);
3335 bv_->text->setParagraph(bv_, 0, 0,
3337 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3342 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 bv_->text->insertInset(bv_, inset);
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3355 if (!inset || !available())
3358 // first check for locking insets
3359 if (bv_->theLockingInset()) {
3360 if (bv_->theLockingInset() == inset) {
3361 if (bv_->text->updateInset(bv_, inset)) {
3364 buffer_->markDirty();
3369 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3370 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3373 buffer_->markDirty();
3381 // then check if the inset is a top_level inset (has no owner)
3382 // if yes do the update as always otherwise we have to update the
3383 // toplevel inset where this inset is inside
3384 Inset * tl_inset = inset;
3385 while(tl_inset->owner())
3386 tl_inset = tl_inset->owner();
3388 if (tl_inset == inset) {
3389 update(bv_->text, BufferView::UPDATE);
3390 if (bv_->text->updateInset(bv_, inset)) {
3394 | BufferView::FITCUR
3395 | BufferView::CHANGE);
3397 update(bv_->text, SELECT);
3401 } else if (static_cast<UpdatableInset *>(tl_inset)
3402 ->updateInsetInInset(bv_, inset))
3404 if (bv_->text->updateInset(bv_, tl_inset)) {
3412 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3415 if (!available()) return;
3418 beforeChange(bv_->text);
3419 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3421 LyXCursor const & cursor = bv_->text->cursor;
3425 cursor.par()->isInset(cursor.pos())) {
3426 Inset const * inset = cursor.par()->getInset(cursor.pos());
3427 if (find(codes.begin(), codes.end(), inset->lyxCode())
3430 static_cast<InsetCommand const *>(inset)->getContents();
3434 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3435 if (bv_->text->cursor.pos()
3436 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3437 LyXCursor tmp = bv_->text->cursor;
3438 bv_->text->cursor.par(bv_->text->ownerParagraph());
3439 bv_->text->cursor.pos(0);
3440 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3441 bv_->text->cursor = tmp;
3442 bv_->owner()->message(_("No more insets"));
3445 bv_->owner()->message(_("No more insets"));
3448 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3449 bv_->text->selection.cursor = bv_->text->cursor;
3453 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3455 gotoInset(vector<Inset::Code>(1, code), same_content);