2 * \file BufferView_pimpl.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
12 #pragma implementation
15 #include "BufferView_pimpl.h"
16 #include "frontends/WorkArea.h"
17 #include "frontends/screen.h"
18 #include "frontends/LyXScreenFactory.h"
19 #include "frontends/WorkAreaFactory.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/Alert.h"
22 #include "frontends/FileDialog.h"
25 #include "paragraph.h"
26 #include "frontends/LyXView.h"
27 #include "commandtags.h"
30 #include "bufferview_funcs.h"
31 #include "TextCache.h"
32 #include "bufferlist.h"
35 // added for Dispatch functions
38 #include "FloatList.h"
40 #include "ParagraphParameters.h"
41 #include "undo_funcs.h"
42 #include "lyxtextclasslist.h"
44 #include "insets/insetbib.h"
45 #include "insets/insettext.h"
46 #include "insets/inseturl.h"
47 #include "insets/insetlatexaccent.h"
48 #include "insets/insettoc.h"
49 #include "insets/insetref.h"
50 #include "insets/insetparent.h"
51 #include "insets/insetindex.h"
52 #include "insets/insetnote.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetert.h"
56 #include "insets/insetexternal.h"
57 #include "insets/insetgraphics.h"
58 #include "insets/insetfoot.h"
59 #include "insets/insetmarginal.h"
60 #include "insets/insetminipage.h"
61 #include "insets/insetfloat.h"
62 #include "insets/insettabular.h"
64 #include "insets/insettheorem.h"
65 #include "insets/insetlist.h"
67 #include "insets/insetcaption.h"
68 #include "insets/insetfloatlist.h"
69 #include "insets/insetspecialchar.h"
71 #include "mathed/formulabase.h"
73 #include "support/LAssert.h"
74 #include "support/lstrings.h"
75 #include "support/filetools.h"
76 #include "support/lyxfunctional.h"
78 #include <boost/bind.hpp>
87 extern string current_layout;
89 #ifndef CXX_GLOBAL_CSTD
102 using std::make_pair;
106 using lyx::textclass_type;
108 /* the selection possible is needed, that only motion events are
109 * used, where the bottom press event was on the drawing area too */
110 bool selection_possible = false;
112 extern BufferList bufferlist;
113 extern char ascii_type;
115 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
120 const unsigned int saved_positions_num = 20;
126 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
127 int xpos, int ypos, int width, int height)
128 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
129 using_xterm_cursor(false)
131 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
132 screen_.reset(LyXScreenFactory::create(workarea()));
135 workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
136 workarea().workAreaExpose
137 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
138 workarea().workAreaButtonPress
139 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
140 workarea().workAreaButtonRelease
141 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
142 workarea().workAreaMotionNotify
143 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
144 workarea().workAreaDoubleClick
145 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
146 workarea().workAreaTripleClick
147 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
148 workarea().workAreaKeyPress
149 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
150 workarea().selectionRequested
151 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
152 workarea().selectionLost
153 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
155 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
156 cursor_timeout.start();
157 saved_positions.resize(saved_positions_num);
161 WorkArea & BufferView::Pimpl::workarea() const
163 return *workarea_.get();
167 LyXScreen & BufferView::Pimpl::screen() const
169 return *screen_.get();
173 Painter & BufferView::Pimpl::painter() const
175 return workarea().getPainter();
179 void BufferView::Pimpl::buffer(Buffer * b)
181 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
184 buffer_->delUser(bv_);
186 // Put the old text into the TextCache, but
187 // only if the buffer is still loaded.
188 // Also set the owner of the test to 0
189 // bv_->text->owner(0);
190 textcache.add(buffer_, workarea().workWidth(), bv_->text);
191 if (lyxerr.debugging())
192 textcache.show(lyxerr, "BufferView::buffer");
197 // Set current buffer
200 if (bufferlist.getState() == BufferList::CLOSING) return;
202 // If we are closing the buffer, use the first buffer as current
204 buffer_ = bufferlist.first();
208 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
209 buffer_->addUser(bv_);
210 // If we don't have a text object for this, we make one
211 if (bv_->text == 0) {
212 resizeCurrentBuffer();
217 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
218 owner_->updateMenubar();
219 owner_->updateToolbar();
220 // Similarly, buffer-dependent dialogs should be updated or
221 // hidden. This should go here because some dialogs (eg ToC)
222 // require bv_->text.
223 owner_->getDialogs()->updateBufferDependent(true);
226 lyxerr[Debug::INFO] << " No Buffer!" << endl;
227 owner_->updateMenubar();
228 owner_->updateToolbar();
229 owner_->getDialogs()->hideBufferDependent();
233 // Also remove all remaining text's from the testcache.
234 // (there should not be any!) (if there is any it is a
236 if (lyxerr.debugging())
237 textcache.show(lyxerr, "buffer delete all");
240 // should update layoutchoice even if we don't have a buffer.
241 owner_->updateLayoutChoice();
243 owner_->updateWindowTitle();
247 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
249 workarea().resize(xpos, ypos, width, height);
250 update(bv_->text, SELECT);
255 void BufferView::Pimpl::resize()
258 resizeCurrentBuffer();
262 void BufferView::Pimpl::redraw()
264 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
269 bool BufferView::Pimpl::fitCursor()
273 if (bv_->theLockingInset()) {
274 bv_->theLockingInset()->fitInsetCursor(bv_);
277 ret = screen().fitCursor(bv_->text, bv_);
280 bv_->owner()->getDialogs()->updateParagraph();
287 void BufferView::Pimpl::redoCurrentBuffer()
289 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
290 if (buffer_ && bv_->text) {
292 owner_->updateLayoutChoice();
297 int BufferView::Pimpl::resizeCurrentBuffer()
299 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
302 Paragraph * selstartpar = 0;
303 Paragraph * selendpar = 0;
304 UpdatableInset * the_locking_inset = 0;
307 pos_type selstartpos = 0;
308 pos_type selendpos = 0;
309 bool selection = false;
310 bool mark_set = false;
312 owner_->prohibitInput();
314 owner_->message(_("Formatting document..."));
317 par = bv_->text->cursor.par();
318 pos = bv_->text->cursor.pos();
319 selstartpar = bv_->text->selection.start.par();
320 selstartpos = bv_->text->selection.start.pos();
321 selendpar = bv_->text->selection.end.par();
322 selendpos = bv_->text->selection.end.pos();
323 selection = bv_->text->selection.set();
324 mark_set = bv_->text->selection.mark();
325 the_locking_inset = bv_->theLockingInset();
326 buffer_->resizeInsets(bv_);
327 // I don't think the delete and new are necessary here we just could
328 // call only init! (Jug 20020419)
330 bv_->text = new LyXText(bv_);
331 bv_->text->init(bv_);
333 // See if we have a text in TextCache that fits
334 // the new buffer_ with the correct width.
335 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
337 if (lyxerr.debugging()) {
338 lyxerr << "Found a LyXText that fits:\n";
339 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
341 // Set the owner of the newly found text
342 // bv_->text->owner(bv_);
343 if (lyxerr.debugging())
344 textcache.show(lyxerr, "resizeCurrentBuffer");
346 bv_->text = new LyXText(bv_);
347 bv_->text->init(bv_);
348 //buffer_->resizeInsets(bv_);
355 bv_->text->selection.set(true);
356 // At this point just to avoid the Delete-Empty-Paragraph-
357 // Mechanism when setting the cursor.
358 bv_->text->selection.mark(mark_set);
360 bv_->text->setCursor(bv_, selstartpar, selstartpos);
361 bv_->text->selection.cursor = bv_->text->cursor;
362 bv_->text->setCursor(bv_, selendpar, selendpos);
363 bv_->text->setSelection(bv_);
364 bv_->text->setCursor(bv_, par, pos);
366 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->selection.cursor = bv_->text->cursor;
368 bv_->text->selection.set(false);
370 // remake the inset locking
371 bv_->theLockingInset(the_locking_inset);
374 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
376 // this will scroll the screen such that the cursor becomes visible
381 owner_->allowInput();
383 /// clear the "Formatting Document" message
390 void BufferView::Pimpl::updateScreen()
392 // Regenerate the screen.
393 screen().redraw(bv_->text, bv_);
397 void BufferView::Pimpl::updateScrollbar()
400 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
401 workarea().setScrollbarParams(0, 0, 0);
405 LyXText const & t = *bv_->text;
407 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
411 void BufferView::Pimpl::scrollDocView(int value)
413 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
415 if (!buffer_) return;
417 screen().draw(bv_->text, bv_, value);
419 if (!lyxrc.cursor_follows_scrollbar) {
423 LyXText * vbt = bv_->text;
425 int const height = vbt->defaultHeight();
426 int const first = static_cast<int>((bv_->text->first_y + height));
427 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
429 if (vbt->cursor.y() < first)
430 vbt->setCursorFromCoordinates(bv_, 0, first);
431 else if (vbt->cursor.y() > last)
432 vbt->setCursorFromCoordinates(bv_, 0, last);
436 int BufferView::Pimpl::scroll(long time)
441 LyXText const * t = bv_->text;
443 double const diff = t->defaultHeight()
444 + double(time) * double(time) * 0.125;
446 scrollDocView(int(diff));
447 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
452 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
453 key_modifier::state state)
455 bv_->owner()->getLyXFunc()->processKeySym(key, state);
459 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
461 // Only use motion with button 1
462 if (!(state & mouse_button::button1))
468 // Check for inset locking
469 if (bv_->theLockingInset()) {
470 LyXCursor cursor = bv_->text->cursor;
471 LyXFont font = bv_->text->getFont(buffer_,
472 cursor.par(), cursor.pos());
473 int width = bv_->theLockingInset()->width(bv_, font);
474 int inset_x = font.isVisibleRightToLeft()
475 ? cursor.ix() - width : cursor.ix();
476 int start_x = inset_x + bv_->theLockingInset()->scroll();
478 bv_->theLockingInset()->
479 insetMotionNotify(bv_,
481 y - cursor.iy() + bv_->text->first_y,
486 /* The test for not selection possible is needed, that only motion
487 events are used, where the bottom press event was on
488 the drawing area too */
489 if (!selection_possible)
492 screen().hideCursor();
494 Row * cursorrow = bv_->text->cursor.row();
495 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
497 // sorry for this but I have a strange error that the y value jumps at
498 // a certain point. This seems like an error in my xforms library or
499 // in some other local environment, but I would like to leave this here
500 // for the moment until I can remove this (Jug 20020418)
501 if (y_before < bv_->text->cursor.y())
502 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
504 // This is to allow jumping over large insets
505 if (cursorrow == bv_->text->cursor.row()) {
506 if (y >= int(workarea().workHeight())) {
507 bv_->text->cursorDown(bv_, false);
509 bv_->text->cursorUp(bv_, false);
513 if (!bv_->text->selection.set())
514 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
516 bv_->text->setSelection(bv_);
517 screen().toggleToggle(bv_->text, bv_);
523 // Single-click on work area
524 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
525 mouse_button::state button)
530 // ok ok, this is a hack (for xforms)
531 if (button == mouse_button::button4) {
532 scroll(-lyxrc.wheel_jump);
533 // We shouldn't go further down as we really should only do the
534 // scrolling and be done with this. Otherwise we may open some
535 // dialogs (Jug 20020424).
537 } else if (button == mouse_button::button5) {
538 scroll(lyxrc.wheel_jump);
539 // We shouldn't go further down as we really should only do the
540 // scrolling and be done with this. Otherwise we may open some
541 // dialogs (Jug 20020424).
545 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
547 // Middle button press pastes if we have a selection
548 // We do this here as if the selection was inside an inset
549 // it could get cleared on the unlocking of the inset so
550 // we have to check this first
551 bool paste_internally = false;
552 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
553 owner_->getLyXFunc()->dispatch(LFUN_COPY);
554 paste_internally = true;
557 int const screen_first = bv_->text->first_y;
559 if (bv_->theLockingInset()) {
560 // We are in inset locking mode
562 /* Check whether the inset was hit. If not reset mode,
563 otherwise give the event to the inset */
564 if (inset_hit == bv_->theLockingInset()) {
565 bv_->theLockingInset()->
566 insetButtonPress(bv_, xpos, ypos, button);
569 bv_->unlockInset(bv_->theLockingInset());
574 selection_possible = true;
575 screen().hideCursor();
577 // Clear the selection
578 screen().toggleSelection(bv_->text, bv_);
579 bv_->text->clearSelection();
580 bv_->text->fullRebreak(bv_);
584 // Single left click in math inset?
585 if (isHighlyEditableInset(inset_hit)) {
586 // Highly editable inset, like math
587 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
588 selection_possible = false;
589 owner_->updateLayoutChoice();
590 owner_->message(inset->editMessage());
591 //inset->edit(bv_, xpos, ypos, button);
592 // We just have to lock the inset before calling a PressEvent on it!
593 // we don't need the edit() call here! (Jug20020329)
594 if (!bv_->lockInset(inset)) {
595 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
597 inset->insetButtonPress(bv_, xpos, ypos, button);
600 // I'm not sure we should continue here if we hit an inset (Jug20020403)
602 // Right click on a footnote flag opens float menu
603 if (button == mouse_button::button3) {
604 selection_possible = false;
608 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
609 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
611 bv_->text->selection.cursor = bv_->text->cursor;
612 bv_->text->cursor.x_fix(bv_->text->cursor.x());
614 owner_->updateLayoutChoice();
616 selection_possible = false;
619 // Insert primary selection with middle mouse
620 // if there is a local selection in the current buffer,
622 if (button == mouse_button::button2) {
623 if (paste_internally)
624 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
626 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
628 selection_possible = false;
634 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
639 LyXText * text = bv_->getLyXText();
641 if (text->bv_owner && bv_->theLockingInset())
644 if (button == mouse_button::button1) {
645 if (text->bv_owner) {
646 screen().hideCursor();
647 screen().toggleSelection(text, bv_);
648 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
649 screen().toggleSelection(text, bv_, false);
651 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
653 /* This will fit the cursor on the screen
655 update(text, BufferView::SELECT|BufferView::FITCUR);
660 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
665 LyXText * text = bv_->getLyXText();
667 if (text->bv_owner && bv_->theLockingInset())
670 if (button == mouse_button::button1) {
671 if (text->bv_owner) {
672 screen().hideCursor();
673 screen().toggleSelection(text, bv_);
675 text->cursorHome(bv_);
676 text->selection.cursor = text->cursor;
677 text->cursorEnd(bv_);
678 text->setSelection(bv_);
679 if (text->bv_owner) {
680 screen().toggleSelection(text, bv_, false);
682 /* This will fit the cursor on the screen
684 update(text, BufferView::SELECT|BufferView::FITCUR);
689 void BufferView::Pimpl::selectionRequested()
696 LyXText * text = bv_->getLyXText();
698 if (text->selection.set() &&
699 (!bv_->text->xsel_cache.set() ||
700 text->selection.start != bv_->text->xsel_cache.start ||
701 text->selection.end != bv_->text->xsel_cache.end))
703 bv_->text->xsel_cache = text->selection;
704 sel = text->selectionAsString(bv_->buffer(), false);
705 } else if (!text->selection.set()) {
707 bv_->text->xsel_cache.set(false);
710 workarea().putClipboard(sel);
715 void BufferView::Pimpl::selectionLost()
720 bv_->getLyXText()->clearSelection();
722 bv_->text->xsel_cache.set(false);
727 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
728 mouse_button::state button)
730 // do nothing if we used the mouse wheel
731 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
734 // If we hit an inset, we have the inset coordinates in these
735 // and inset_hit points to the inset. If we do not hit an
736 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
737 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
739 if (bv_->theLockingInset()) {
740 // We are in inset locking mode.
742 /* LyX does a kind of work-area grabbing for insets.
743 Only a ButtonPress Event outside the inset will
744 force a insetUnlock. */
745 bv_->theLockingInset()->
746 insetButtonRelease(bv_, x, y, button);
750 selection_possible = false;
752 if (button == mouse_button::button2)
756 if (button == mouse_button::button1) {
757 workarea().haveSelection(bv_->getLyXText()->selection.set());
762 owner_->updateMenubar();
763 owner_->updateToolbar();
765 // Did we hit an editable inset?
767 selection_possible = false;
769 // if we reach this point with a selection, it
770 // must mean we are currently selecting.
771 // But we don't want to open the inset
772 // because that is annoying for the user.
773 // So just pretend we didn't hit it.
774 // this is OK because a "kosher" ButtonRelease
775 // will follow a ButtonPress that clears
777 // Note this also fixes selection drawing
778 // problems if we end up opening an inset
779 if (bv_->getLyXText()->selection.set())
782 // CHECK fix this proper in 0.13
783 // well, maybe 13.0 !!!!!!!!!
785 // Following a ref shouldn't issue
786 // a push on the undo-stack
787 // anylonger, now that we have
788 // keybindings for following
789 // references and returning from
790 // references. IMHO though, it
791 // should be the inset's own business
792 // to push or not push on the undo
793 // stack. They don't *have* to
794 // alter the document...
796 // ...or maybe the SetCursorParUndo()
797 // below isn't necessary at all anylonger?
798 if (inset_hit->lyxCode() == Inset::REF_CODE) {
799 setCursorParUndo(bv_);
802 owner_->message(inset_hit->editMessage());
804 if (isHighlyEditableInset(inset_hit)) {
805 // Highly editable inset, like math
806 UpdatableInset *inset = (UpdatableInset *)inset_hit;
807 inset->insetButtonRelease(bv_, x, y, button);
809 inset_hit->insetButtonRelease(bv_, x, y, button);
810 // IMO this is a grosshack! Inset's should be changed so that
811 // they call the actions they have to do with the insetButtonRel.
812 // function and not in the edit(). This should be changed
814 inset_hit->edit(bv_, x, y, button);
819 // Maybe we want to edit a bibitem ale970302
820 if (bv_->text->cursor.par()->bibkey && x < 20 +
821 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
822 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
829 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
830 LyXCursor const & cursor) const
832 Paragraph /*const*/ & par = *cursor.par();
833 pos_type const pos = cursor.pos();
835 lyx::Assert(par.getInset(pos));
837 Inset const & inset(*par.getInset(pos));
839 LyXFont const & font = text.getFont(buffer_, &par, pos);
841 int const width = inset.width(bv_, font);
842 int const inset_x = font.isVisibleRightToLeft()
843 ? (cursor.ix() - width) : cursor.ix();
846 inset_x + inset.scroll(),
848 cursor.iy() - inset.ascent(bv_, font),
849 cursor.iy() + inset.descent(bv_, font));
853 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
854 LyXCursor const & cursor,
855 int & x, int & y) const
857 pos_type const pos(cursor.pos());
858 Paragraph /*const*/ & par(*cursor.par());
860 if (pos >= par.size() || !par.isInset(pos)) {
864 Inset /*const*/ * inset = par.getInset(pos);
866 if (!isEditableInset(inset)) {
870 Box b(insetDimensions(text, cursor));
872 if (!b.contained(x, y)) {
873 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
874 << " box " << b << endl;
878 text.setCursor(bv_, &par, pos, true);
881 // The origin of an inset is on the baseline
882 y -= text.cursor.iy();
888 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
890 int y_tmp = y + text->first_y;
893 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
895 Inset * inset(checkInset(*text, cursor, x, y_tmp));
902 // look at previous position
904 if (cursor.pos() == 0) {
909 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
911 inset = checkInset(*text, cursor, x, y_tmp);
919 void BufferView::Pimpl::workAreaExpose()
921 static int work_area_width;
922 static unsigned int work_area_height;
924 bool const widthChange = workarea().workWidth() != work_area_width;
925 bool const heightChange = workarea().workHeight() != work_area_height;
927 // update from work area
928 work_area_width = workarea().workWidth();
929 work_area_height = workarea().workHeight();
932 // The visible LyXView need a resize
933 owner_->view()->resize();
935 // Remove all texts from the textcache
936 // This is not _really_ what we want to do. What
937 // we really want to do is to delete in textcache
938 // that does not have a BufferView with matching
939 // width, but as long as we have only one BufferView
940 // deleting all gives the same result.
941 if (lyxerr.debugging())
942 textcache.show(lyxerr, "Expose delete all");
944 buffer_->resizeInsets(bv_);
945 } else if (heightChange) {
946 // Rebuild image of current screen
948 // fitCursor() ensures we don't jump back
949 // to the start of the document on vertical
953 // The main window size has changed, repaint most stuff
956 screen().redraw(bv_->text, bv_);
959 screen().redraw(bv_->text, bv_);
962 // always make sure that the scrollbar is sane.
964 owner_->updateLayoutChoice();
969 void BufferView::Pimpl::update()
971 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
972 LyXText::text_status st = bv_->text->status();
973 screen().update(bv_->text, bv_);
975 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
976 bv_->text->fullRebreak(bv_);
977 st = LyXText::NEED_MORE_REFRESH;
978 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
979 bv_->text->cursor.pos());
980 if (bv_->text->selection.set()) {
981 bv_->text->setCursor(bv_, bv_->text->selection.start,
982 bv_->text->selection.start.par(),
983 bv_->text->selection.start.pos());
984 bv_->text->setCursor(bv_, bv_->text->selection.end,
985 bv_->text->selection.end.par(),
986 bv_->text->selection.end.pos());
989 bv_->text->status(bv_, st);
990 screen().update(bv_->text, bv_);
992 // do this here instead of in the screen::update because of
994 bv_->text->status(bv_, LyXText::UNCHANGED);
1000 // Values used when calling update:
1002 // -2 - update, move sel_cursor if selection, fitcursor
1003 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1004 // 0 - update, move sel_cursor if selection, fitcursor
1005 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1006 // 3 - update, move sel_cursor if selection
1009 // a simple redraw of the parts that need refresh
1011 // move sel_cursor if selection -
1012 // the text's sel_cursor is moved if there is selection is progress
1015 // fitCursor() is called and the scrollbar updated
1018 // the buffer is marked dirty.
1027 // UPDATE_ONLY = UPDATE;
1028 // UPDATE_SELECT = UPDATE | SELECT;
1029 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1030 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1032 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1033 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1034 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1035 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1036 // update(3) -> update(1) -> update(1) -> update(SELECT)
1038 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1040 owner_->updateLayoutChoice();
1042 if (!text->selection.set() && (f & SELECT)) {
1043 text->selection.cursor = text->cursor;
1046 text->fullRebreak(bv_);
1048 if (text->inset_owner) {
1049 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1050 updateInset(text->inset_owner, false);
1060 buffer_->markDirty();
1065 // Callback for cursor timer
1066 void BufferView::Pimpl::cursorToggle()
1069 cursor_timeout.restart();
1074 extern void reapSpellchecker(void);
1077 if (!bv_->theLockingInset()) {
1078 screen().cursorToggle(bv_);
1080 bv_->theLockingInset()->toggleInsetCursor(bv_);
1083 cursor_timeout.restart();
1087 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1089 if (!text->cursor.row()->previous()) {
1090 if (text->first_y > 0) {
1091 int new_y = bv_->text->first_y - workarea().workHeight();
1092 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1098 int y = text->first_y;
1099 Row * cursorrow = text->cursor.row();
1101 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1105 if (cursorrow == bv_->text->cursor.row()) {
1106 // we have a row which is higher than the workarea so we leave the
1107 // cursor on the start of the row and move only the draw up as soon
1108 // as we move the cursor or do something while inside the row (it may
1109 // span several workarea-heights) we'll move to the top again, but this
1110 // is better than just jump down and only display part of the row.
1111 new_y = bv_->text->first_y - workarea().workHeight();
1113 if (text->inset_owner) {
1114 new_y = bv_->text->cursor.iy()
1115 + bv_->theLockingInset()->insetInInsetY() + y
1116 + text->cursor.row()->height()
1117 - workarea().workHeight() + 1;
1119 new_y = text->cursor.y()
1120 - text->cursor.row()->baseline()
1121 + text->cursor.row()->height()
1122 - workarea().workHeight() + 1;
1125 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1126 if (text->cursor.row()->previous()) {
1128 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1129 text->cursor.row()->previous()->pos(), false);
1130 if (cur.y() > text->first_y) {
1131 text->cursorUp(bv_, true);
1138 void BufferView::Pimpl::cursorNext(LyXText * text)
1140 if (!text->cursor.row()->next()) {
1141 int y = text->cursor.y() - text->cursor.row()->baseline() +
1142 text->cursor.row()->height();
1143 if (y > int(text->first_y + workarea().workHeight())) {
1144 screen().draw(bv_->text, bv_,
1145 bv_->text->first_y + workarea().workHeight());
1151 int y = text->first_y + workarea().workHeight();
1152 if (text->inset_owner && !text->first_y) {
1153 y -= (bv_->text->cursor.iy()
1154 - bv_->text->first_y
1155 + bv_->theLockingInset()->insetInInsetY());
1158 text->getRowNearY(y);
1160 Row * cursorrow = text->cursor.row();
1161 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1165 if (cursorrow == bv_->text->cursor.row()) {
1166 // we have a row which is higher than the workarea so we leave the
1167 // cursor on the start of the row and move only the draw down as soon
1168 // as we move the cursor or do something while inside the row (it may
1169 // span several workarea-heights) we'll move to the top again, but this
1170 // is better than just jump down and only display part of the row.
1171 new_y = bv_->text->first_y + workarea().workHeight();
1173 if (text->inset_owner) {
1174 new_y = bv_->text->cursor.iy()
1175 + bv_->theLockingInset()->insetInInsetY()
1176 + y - text->cursor.row()->baseline();
1178 new_y = text->cursor.y() - text->cursor.row()->baseline();
1181 screen().draw(bv_->text, bv_, new_y);
1182 if (text->cursor.row()->next()) {
1184 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1185 text->cursor.row()->next()->pos(), false);
1186 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1187 text->cursorDown(bv_, true);
1194 bool BufferView::Pimpl::available() const
1196 if (buffer_ && bv_->text)
1202 void BufferView::Pimpl::beforeChange(LyXText * text)
1205 text->clearSelection();
1209 void BufferView::Pimpl::savePosition(unsigned int i)
1211 if (i >= saved_positions_num)
1213 saved_positions[i] = Position(buffer_->fileName(),
1214 bv_->text->cursor.par()->id(),
1215 bv_->text->cursor.pos());
1218 str << _("Saved bookmark") << ' ' << i;
1219 owner_->message(str.str().c_str());
1224 void BufferView::Pimpl::restorePosition(unsigned int i)
1226 if (i >= saved_positions_num)
1229 string const fname = saved_positions[i].filename;
1231 beforeChange(bv_->text);
1233 if (fname != buffer_->fileName()) {
1234 Buffer * b = bufferlist.exists(fname) ?
1235 bufferlist.getBuffer(fname) :
1236 bufferlist.loadLyXFile(fname); // don't ask, just load it
1237 if (b != 0) buffer(b);
1240 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1244 bv_->text->setCursor(bv_, par,
1245 min(par->size(), saved_positions[i].par_pos));
1247 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1250 str << _("Moved to bookmark") << ' ' << i;
1251 owner_->message(str.str().c_str());
1256 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1258 if (i >= saved_positions_num)
1261 return !saved_positions[i].filename.empty();
1265 void BufferView::Pimpl::setState()
1267 if (!lyxrc.rtl_support)
1270 LyXText * text = bv_->getLyXText();
1271 if (text->real_current_font.isRightToLeft()
1272 && !(bv_->theLockingInset()
1273 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1275 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1276 owner_->getIntl()->KeyMapSec();
1278 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1279 owner_->getIntl()->KeyMapPrim();
1284 void BufferView::Pimpl::insetUnlock()
1286 if (bv_->theLockingInset()) {
1287 bv_->theLockingInset()->insetUnlock(bv_);
1288 bv_->theLockingInset(0);
1294 void BufferView::Pimpl::showCursor()
1296 if (bv_->theLockingInset())
1297 bv_->theLockingInset()->showInsetCursor(bv_);
1299 screen().showCursor(bv_->text, bv_);
1303 void BufferView::Pimpl::hideCursor()
1305 if (!bv_->theLockingInset())
1306 screen().hideCursor();
1310 void BufferView::Pimpl::toggleSelection(bool b)
1312 if (bv_->theLockingInset())
1313 bv_->theLockingInset()->toggleSelection(bv_, b);
1314 screen().toggleSelection(bv_->text, bv_, b);
1318 void BufferView::Pimpl::toggleToggle()
1320 screen().toggleToggle(bv_->text, bv_);
1324 void BufferView::Pimpl::center()
1326 beforeChange(bv_->text);
1327 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1328 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1330 screen().draw(bv_->text, bv_, 0);
1332 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1337 void BufferView::Pimpl::pasteClipboard(bool asPara)
1342 screen().hideCursor();
1343 beforeChange(bv_->text);
1345 string const clip(workarea().getClipboard());
1351 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1353 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1355 bv_->getLyXText()->clearSelection();
1356 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1360 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1362 workarea().putClipboard(stuff);
1367 * Dispatch functions for actions which can be valid for BufferView->text
1368 * and/or InsetText->text!!!
1373 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1375 LyXText * lt = bv_->getLyXText();
1377 if (selecting || lt->selection.mark()) {
1378 lt->setSelection(bv_);
1382 updateInset(lt->inset_owner, false);
1386 update(lt, BufferView::SELECT|BufferView::FITCUR);
1388 update(lt, BufferView::SELECT);
1390 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1391 bv_->theLockingInset()->hideInsetCursor(bv_);
1392 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1396 if (!lt->selection.set())
1397 workarea().haveSelection(false);
1399 /* ---> Everytime the cursor is moved, show the current font state. */
1400 // should this too me moved out of this func?
1401 //owner->showState();
1406 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1408 LyXCursor cursor = bv_->getLyXText()->cursor;
1409 Buffer::inset_iterator it =
1410 find_if(Buffer::inset_iterator(
1411 cursor.par(), cursor.pos()),
1412 buffer_->inset_iterator_end(),
1413 lyx::compare_memfun(&Inset::lyxCode, code));
1414 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1418 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1420 string filename = filen;
1422 if (filename.empty()) {
1423 // Launch a file browser
1424 string initpath = lyxrc.document_path;
1427 string const trypath = owner_->buffer()->filePath();
1428 // If directory is writeable, use this as default.
1429 if (IsDirWriteable(trypath))
1433 FileDialog fileDlg(bv_->owner(),
1434 _("Select LyX document to insert"),
1436 make_pair(string(_("Documents|#o#O")),
1437 string(lyxrc.document_path)),
1438 make_pair(string(_("Examples|#E#e")),
1439 string(AddPath(system_lyxdir, "examples"))));
1441 FileDialog::Result result =
1442 fileDlg.Select(initpath,
1443 _("*.lyx| LyX Documents (*.lyx)"));
1445 if (result.first == FileDialog::Later)
1448 filename = result.second;
1450 // check selected filename
1451 if (filename.empty()) {
1452 owner_->message(_("Canceled."));
1457 // get absolute path of file and add ".lyx" to the filename if
1459 filename = FileSearch(string(), filename, "lyx");
1461 string const disp_fn(MakeDisplayPath(filename));
1464 s1 << _("Inserting document") << ' '
1465 << disp_fn << " ...";
1466 owner_->message(s1.str().c_str());
1467 bool const res = bv_->insertLyXFile(filename);
1470 str << _("Document") << ' ' << disp_fn
1471 << ' ' << _("inserted.");
1472 owner_->message(str.str().c_str());
1475 str << _("Could not insert document") << ' '
1477 owner_->message(str.str().c_str());
1482 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1484 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1485 << action <<"] arg[" << argument << "]" << endl;
1487 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1490 // --- Misc -------------------------------------------
1494 LyXText * lt = bv_->getLyXText();
1495 lt->toggleAppendix(bv_);
1498 | BufferView::FITCUR
1499 | BufferView::CHANGE);
1504 case LFUN_TOC_INSERT:
1506 InsetCommandParams p;
1507 p.setCmdName("tableofcontents");
1508 Inset * inset = new InsetTOC(p);
1509 if (!insertInset(inset, tclass.defaultLayoutName()))
1514 case LFUN_SCROLL_INSET:
1515 // this is not handled here as this funktion is only aktive
1516 // if we have a locking_inset and that one is (or contains)
1520 case LFUN_INSET_GRAPHICS:
1522 Inset * new_inset = new InsetGraphics;
1523 if (!insertInset(new_inset)) {
1526 // this is need because you don't use a inset->Edit()
1527 updateInset(new_inset, true);
1528 new_inset->edit(bv_);
1538 case LFUN_PASTESELECTION:
1540 bool asPara = false;
1541 if (argument == "paragraph")
1543 pasteClipboard(asPara);
1555 case LFUN_LAYOUT_COPY:
1556 bv_->copyEnvironment();
1559 case LFUN_LAYOUT_PASTE:
1560 bv_->pasteEnvironment();
1564 case LFUN_GOTOERROR:
1565 gotoInset(Inset::ERROR_CODE, false);
1569 gotoInset(Inset::IGNORE_CODE, false);
1572 case LFUN_REFERENCE_GOTO:
1574 vector<Inset::Code> tmp;
1575 tmp.push_back(Inset::LABEL_CODE);
1576 tmp.push_back(Inset::REF_CODE);
1577 gotoInset(tmp, true);
1581 case LFUN_HYPHENATION:
1582 specialChar(InsetSpecialChar::HYPHENATION);
1585 case LFUN_LIGATURE_BREAK:
1586 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1590 specialChar(InsetSpecialChar::LDOTS);
1593 case LFUN_END_OF_SENTENCE:
1594 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1597 case LFUN_MENU_SEPARATOR:
1598 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1605 case LFUN_DEPTH_MIN:
1606 changeDepth(bv_, bv_->getLyXText(), -1);
1609 case LFUN_DEPTH_PLUS:
1610 changeDepth(bv_, bv_->getLyXText(), 1);
1614 owner_->getDialogs()->setUserFreeFont();
1617 case LFUN_FILE_INSERT:
1618 MenuInsertLyXFile(argument);
1621 case LFUN_FILE_INSERT_ASCII_PARA:
1622 InsertAsciiFile(bv_, argument, true);
1625 case LFUN_FILE_INSERT_ASCII:
1626 InsertAsciiFile(bv_, argument, false);
1631 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1632 << argument << endl;
1634 // This is not the good solution to the empty argument
1635 // problem, but it will hopefully suffice for 1.2.0.
1636 // The correct solution would be to augument the
1637 // function list/array with information about what
1638 // functions needs arguments and their type.
1639 if (argument.empty()) {
1640 owner_->getLyXFunc()->setErrorMessage(
1641 _("LyX function 'layout' needs an argument."));
1645 // Derive layout number from given argument (string)
1646 // and current buffer's textclass (number). */
1647 bool hasLayout = tclass.hasLayout(argument);
1648 string layout = argument;
1650 // If the entry is obsolete, use the new one instead.
1652 string const & obs = tclass[layout].obsoleted_by();
1658 owner_->getLyXFunc()->setErrorMessage(
1659 string(N_("Layout ")) + argument +
1664 bool change_layout = (current_layout != layout);
1665 LyXText * lt = bv_->getLyXText();
1666 if (!change_layout && lt->selection.set() &&
1667 lt->selection.start.par() != lt->selection.end.par())
1669 Paragraph * spar = lt->selection.start.par();
1670 Paragraph * epar = lt->selection.end.par()->next();
1671 while(spar != epar) {
1672 if (spar->layout() != current_layout) {
1673 change_layout = true;
1678 if (change_layout) {
1680 current_layout = layout;
1683 | BufferView::FITCUR);
1684 lt->setLayout(bv_, layout);
1685 owner_->setLayout(layout);
1688 | BufferView::FITCUR
1689 | BufferView::CHANGE);
1696 lang(bv_, argument);
1698 owner_->showState();
1703 owner_->showState();
1708 owner_->showState();
1713 owner_->showState();
1718 owner_->showState();
1723 owner_->showState();
1728 owner_->showState();
1733 owner_->showState();
1736 case LFUN_UNDERLINE:
1738 owner_->showState();
1741 case LFUN_FONT_SIZE:
1742 fontSize(bv_, argument);
1743 owner_->showState();
1746 case LFUN_FONT_STATE:
1747 owner_->getLyXFunc()->setMessage(currentState(bv_));
1750 case LFUN_UPCASE_WORD:
1752 LyXText * lt = bv_->getLyXText();
1756 | BufferView::FITCUR);
1757 lt->changeCase(bv_, LyXText::text_uppercase);
1758 if (lt->inset_owner)
1759 updateInset(lt->inset_owner, true);
1762 | BufferView::FITCUR
1763 | BufferView::CHANGE);
1767 case LFUN_LOWCASE_WORD:
1769 LyXText * lt = bv_->getLyXText();
1771 update(lt, BufferView::SELECT|BufferView::FITCUR);
1772 lt->changeCase(bv_, LyXText::text_lowercase);
1773 if (lt->inset_owner)
1774 updateInset(lt->inset_owner, true);
1777 | BufferView::FITCUR
1778 | BufferView::CHANGE);
1782 case LFUN_CAPITALIZE_WORD:
1784 LyXText * lt = bv_->getLyXText();
1786 update(lt, BufferView::SELECT|BufferView::FITCUR);
1787 lt->changeCase(bv_, LyXText::text_capitalization);
1788 if (lt->inset_owner)
1789 updateInset(lt->inset_owner, true);
1792 | BufferView::FITCUR
1793 | BufferView::CHANGE);
1797 case LFUN_TRANSPOSE_CHARS:
1799 LyXText * lt = bv_->getLyXText();
1801 update(lt, BufferView::SELECT|BufferView::FITCUR);
1802 lt->transposeChars(*bv_);
1803 if (lt->inset_owner)
1804 updateInset(lt->inset_owner, true);
1807 | BufferView::FITCUR
1808 | BufferView::CHANGE);
1813 case LFUN_INSERT_LABEL:
1814 MenuInsertLabel(bv_, argument);
1817 case LFUN_REF_INSERT:
1818 if (argument.empty()) {
1819 InsetCommandParams p("ref");
1820 owner_->getDialogs()->createRef(p.getAsString());
1822 InsetCommandParams p;
1823 p.setFromString(argument);
1825 InsetRef * inset = new InsetRef(p, *buffer_);
1826 if (!insertInset(inset))
1829 updateInset(inset, true);
1833 case LFUN_BOOKMARK_SAVE:
1834 savePosition(strToUnsignedInt(argument));
1837 case LFUN_BOOKMARK_GOTO:
1838 restorePosition(strToUnsignedInt(argument));
1843 string label(argument);
1844 if (label.empty()) {
1846 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1848 label = inset->getContents();
1853 if (!label.empty()) {
1854 //bv_->savePosition(0);
1855 if (!bv_->gotoLabel(label))
1856 Alert::alert(_("Error"),
1857 _("Couldn't find this label"),
1858 _("in current document."));
1863 // --- Cursor Movements -----------------------------
1866 LyXText * lt = bv_->getLyXText();
1868 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1869 if (!lt->selection.mark())
1871 update(lt, BufferView::SELECT|BufferView::FITCUR);
1873 lt->cursorLeft(bv_, false);
1874 if (lt->cursor.pos() < lt->cursor.par()->size()
1875 && lt->cursor.par()->isInset(lt->cursor.pos())
1876 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1877 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1878 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1880 tmpinset->edit(bv_, false);
1882 tmpinset->edit(bv_);
1886 lt->cursorRight(bv_, false);
1888 moveCursorUpdate(false);
1889 owner_->showState();
1895 // This is soooo ugly. Isn`t it possible to make
1896 // it simpler? (Lgb)
1897 LyXText * lt = bv_->getLyXText();
1898 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1899 if (!lt->selection.mark())
1901 update(lt, BufferView::SELECT|BufferView::FITCUR);
1902 LyXCursor const cur = lt->cursor;
1904 lt->cursorLeft(bv_, false);
1905 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1906 lt->cursor.pos() < lt->cursor.par()->size() &&
1907 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1908 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1909 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1910 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1912 tmpinset->edit(bv_);
1914 tmpinset->edit(bv_, false);
1918 lt->cursorRight(bv_, false);
1921 moveCursorUpdate(false);
1922 owner_->showState();
1928 LyXText * lt = bv_->getLyXText();
1930 if (!lt->selection.mark())
1932 update(lt, BufferView::UPDATE);
1935 moveCursorUpdate(false);
1936 owner_->showState();
1942 LyXText * lt = bv_->getLyXText();
1944 if (!lt->selection.mark())
1946 update(lt, BufferView::UPDATE);
1947 lt->cursorDown(bv_);
1949 moveCursorUpdate(false);
1950 owner_->showState();
1954 case LFUN_UP_PARAGRAPH:
1956 LyXText * lt = bv_->getLyXText();
1958 if (!lt->selection.mark())
1960 update(lt, BufferView::UPDATE);
1961 lt->cursorUpParagraph(bv_);
1963 moveCursorUpdate(false);
1964 owner_->showState();
1968 case LFUN_DOWN_PARAGRAPH:
1970 LyXText * lt = bv_->getLyXText();
1972 if (!lt->selection.mark())
1974 update(lt, BufferView::UPDATE);
1975 lt->cursorDownParagraph(bv_);
1977 moveCursorUpdate(false);
1978 owner_->showState();
1984 LyXText * lt = bv_->getLyXText();
1986 if (!lt->selection.mark())
1988 update(lt, BufferView::UPDATE);
1991 moveCursorUpdate(false, false);
1992 owner_->showState();
1998 LyXText * lt = bv_->getLyXText();
2000 if (!lt->selection.mark())
2002 update(lt, BufferView::UPDATE);
2005 moveCursorUpdate(false, false);
2006 owner_->showState();
2012 LyXText * lt = bv_->getLyXText();
2014 if (!lt->selection.mark())
2016 update(lt, BufferView::SELECT|BufferView::FITCUR);
2017 lt->cursorHome(bv_);
2019 moveCursorUpdate(false);
2020 owner_->showState();
2026 LyXText * lt = bv_->getLyXText();
2028 if (!lt->selection.mark())
2031 BufferView::SELECT|BufferView::FITCUR);
2034 moveCursorUpdate(false);
2035 owner_->showState();
2039 case LFUN_SHIFT_TAB:
2042 LyXText * lt = bv_->getLyXText();
2044 if (!lt->selection.mark())
2047 BufferView::SELECT|BufferView::FITCUR);
2050 moveCursorUpdate(false);
2051 owner_->showState();
2055 case LFUN_WORDRIGHT:
2057 LyXText * lt = bv_->getLyXText();
2059 if (!lt->selection.mark())
2061 update(lt, BufferView::SELECT|BufferView::FITCUR);
2062 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2063 lt->cursorLeftOneWord(bv_);
2065 lt->cursorRightOneWord(bv_);
2067 moveCursorUpdate(false);
2068 owner_->showState();
2074 LyXText * lt = bv_->getLyXText();
2076 if (!lt->selection.mark())
2078 update(lt, BufferView::SELECT|BufferView::FITCUR);
2079 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2080 lt->cursorRightOneWord(bv_);
2082 lt->cursorLeftOneWord(bv_);
2084 moveCursorUpdate(false);
2085 owner_->showState();
2089 case LFUN_BEGINNINGBUF:
2091 LyXText * lt = bv_->getLyXText();
2093 if (!lt->selection.mark())
2096 BufferView::SELECT|BufferView::FITCUR);
2099 moveCursorUpdate(false);
2100 owner_->showState();
2106 LyXText * lt = bv_->getLyXText();
2108 if (!lt->selection.mark())
2111 BufferView::SELECT|BufferView::FITCUR);
2112 lt->cursorBottom(bv_);
2114 moveCursorUpdate(false);
2115 owner_->showState();
2119 /* cursor selection ---------------------------- */
2122 LyXText * lt = bv_->getLyXText();
2125 BufferView::SELECT|BufferView::FITCUR);
2126 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2127 lt->cursorLeft(bv_);
2129 lt->cursorRight(bv_);
2131 moveCursorUpdate(true);
2132 owner_->showState();
2138 LyXText * lt = bv_->getLyXText();
2141 BufferView::SELECT|BufferView::FITCUR);
2142 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2143 lt->cursorRight(bv_);
2145 lt->cursorLeft(bv_);
2147 moveCursorUpdate(true);
2148 owner_->showState();
2154 LyXText * lt = bv_->getLyXText();
2157 BufferView::SELECT|BufferView::FITCUR);
2158 lt->cursorUp(bv_, true);
2160 moveCursorUpdate(true);
2161 owner_->showState();
2167 LyXText * lt = bv_->getLyXText();
2170 BufferView::SELECT|BufferView::FITCUR);
2171 lt->cursorDown(bv_, true);
2173 moveCursorUpdate(true);
2174 owner_->showState();
2178 case LFUN_UP_PARAGRAPHSEL:
2180 LyXText * lt = bv_->getLyXText();
2183 BufferView::SELECT|BufferView::FITCUR);
2184 lt->cursorUpParagraph(bv_);
2186 moveCursorUpdate(true);
2187 owner_->showState();
2191 case LFUN_DOWN_PARAGRAPHSEL:
2193 LyXText * lt = bv_->getLyXText();
2196 BufferView::SELECT|BufferView::FITCUR);
2197 lt->cursorDownParagraph(bv_);
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);
2223 moveCursorUpdate(true);
2224 owner_->showState();
2230 LyXText * lt = bv_->getLyXText();
2232 update(lt, BufferView::SELECT|BufferView::FITCUR);
2233 lt->cursorHome(bv_);
2235 moveCursorUpdate(true);
2236 owner_->showState();
2242 LyXText * lt = bv_->getLyXText();
2244 update(lt, BufferView::SELECT|BufferView::FITCUR);
2247 moveCursorUpdate(true);
2248 owner_->showState();
2252 case LFUN_WORDRIGHTSEL:
2254 LyXText * lt = bv_->getLyXText();
2256 update(lt, BufferView::SELECT|BufferView::FITCUR);
2257 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2258 lt->cursorLeftOneWord(bv_);
2260 lt->cursorRightOneWord(bv_);
2262 moveCursorUpdate(true);
2263 owner_->showState();
2267 case LFUN_WORDLEFTSEL:
2269 LyXText * lt = bv_->getLyXText();
2271 update(lt, BufferView::SELECT|BufferView::FITCUR);
2272 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2273 lt->cursorRightOneWord(bv_);
2275 lt->cursorLeftOneWord(bv_);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2282 case LFUN_BEGINNINGBUFSEL:
2284 LyXText * lt = bv_->getLyXText();
2286 if (lt->inset_owner)
2288 update(lt, BufferView::SELECT|BufferView::FITCUR);
2291 moveCursorUpdate(true);
2292 owner_->showState();
2296 case LFUN_ENDBUFSEL:
2298 LyXText * lt = bv_->getLyXText();
2300 if (lt->inset_owner)
2303 BufferView::SELECT|BufferView::FITCUR);
2304 lt->cursorBottom(bv_);
2306 moveCursorUpdate(true);
2307 owner_->showState();
2311 // --- text changing commands ------------------------
2312 case LFUN_BREAKLINE:
2314 LyXText * lt = bv_->getLyXText();
2317 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2320 | BufferView::FITCUR
2321 | BufferView::CHANGE);
2322 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2323 moveCursorUpdate(false);
2327 case LFUN_PROTECTEDSPACE:
2329 LyXText * lt = bv_->getLyXText();
2331 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2333 if (style.free_spacing) {
2334 lt->insertChar(bv_, ' ');
2337 | BufferView::FITCUR
2338 | BufferView::CHANGE);
2340 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2342 moveCursorUpdate(false);
2348 LyXText * lt = bv_->getLyXText();
2350 if (lt->selection.mark()) {
2354 | BufferView::FITCUR);
2355 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2358 lt->selection.mark(true);
2361 | BufferView::FITCUR);
2362 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2364 lt->selection.cursor = lt->cursor;
2370 LyXText * lt = bv_->getLyXText();
2372 if (!lt->selection.set()) {
2374 lt->selection.cursor = lt->cursor;
2377 | BufferView::FITCUR
2378 | BufferView::CHANGE);
2379 // It is possible to make it a lot faster still
2380 // just comment out the line below...
2385 moveCursorUpdate(false);
2386 owner_->showState();
2391 case LFUN_DELETE_SKIP:
2393 LyXText * lt = bv_->getLyXText();
2395 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2397 LyXCursor cursor = lt->cursor;
2399 if (!lt->selection.set()) {
2400 if (cursor.pos() == cursor.par()->size()) {
2401 lt->cursorRight(bv_);
2402 cursor = lt->cursor;
2403 if (cursor.pos() == 0
2404 && !(cursor.par()->params().spaceTop()
2405 == VSpace (VSpace::NONE))) {
2408 cursor.par()->params().lineTop(),
2409 cursor.par()->params().lineBottom(),
2410 cursor.par()->params().pagebreakTop(),
2411 cursor.par()->params().pagebreakBottom(),
2412 VSpace(VSpace::NONE),
2413 cursor.par()->params().spaceBottom(),
2414 cursor.par()->params().spacing(),
2415 cursor.par()->params().align(),
2416 cursor.par()->params().labelWidthString(), 0);
2417 lt->cursorLeft(bv_);
2420 | BufferView::FITCUR
2421 | BufferView::CHANGE);
2423 lt->cursorLeft(bv_);
2425 lt->selection.cursor = lt->cursor;
2428 | BufferView::FITCUR
2429 | BufferView::CHANGE);
2433 lt->selection.cursor = lt->cursor;
2436 | BufferView::FITCUR
2437 | BufferView::CHANGE);
2445 /* -------> Delete word forward. */
2446 case LFUN_DELETE_WORD_FORWARD:
2447 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2448 bv_->getLyXText()->deleteWordForward(bv_);
2449 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2450 moveCursorUpdate(false);
2451 owner_->showState();
2454 /* -------> Delete word backward. */
2455 case LFUN_DELETE_WORD_BACKWARD:
2457 LyXText * lt = bv_->getLyXText();
2459 update(lt, BufferView::SELECT|BufferView::FITCUR);
2460 lt->deleteWordBackward(bv_);
2463 | BufferView::FITCUR
2464 | BufferView::CHANGE);
2465 moveCursorUpdate(false);
2466 owner_->showState();
2470 /* -------> Kill to end of line. */
2471 case LFUN_DELETE_LINE_FORWARD:
2473 LyXText * lt = bv_->getLyXText();
2475 update(lt, BufferView::SELECT|BufferView::FITCUR);
2476 lt->deleteLineForward(bv_);
2479 | BufferView::FITCUR
2480 | BufferView::CHANGE);
2481 moveCursorUpdate(false);
2485 /* -------> Set mark off. */
2488 LyXText * lt = bv_->getLyXText();
2491 update(lt, BufferView::SELECT|BufferView::FITCUR);
2492 lt->selection.cursor = lt->cursor;
2493 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2497 /* -------> Set mark on. */
2500 LyXText * lt = bv_->getLyXText();
2503 lt->selection.mark(true);
2504 update(lt, BufferView::SELECT|BufferView::FITCUR);
2505 lt->selection.cursor = lt->cursor;
2506 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2510 case LFUN_BACKSPACE:
2512 LyXText * lt = bv_->getLyXText();
2514 if (!lt->selection.set()) {
2515 if (owner_->getIntl()->getTransManager().backspace()) {
2517 lt->selection.cursor = lt->cursor;
2520 | BufferView::FITCUR
2521 | BufferView::CHANGE);
2522 // It is possible to make it a lot faster still
2523 // just comment out the line below...
2529 owner_->showState();
2534 case LFUN_BACKSPACE_SKIP:
2536 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2537 LyXText * lt = bv_->getLyXText();
2539 LyXCursor cursor = lt->cursor;
2541 if (!lt->selection.set()) {
2542 if (cursor.pos() == 0
2543 && !(cursor.par()->params().spaceTop()
2544 == VSpace (VSpace::NONE))) {
2547 cursor.par()->params().lineTop(),
2548 cursor.par()->params().lineBottom(),
2549 cursor.par()->params().pagebreakTop(),
2550 cursor.par()->params().pagebreakBottom(),
2551 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2552 cursor.par()->params().spacing(),
2553 cursor.par()->params().align(),
2554 cursor.par()->params().labelWidthString(), 0);
2557 | BufferView::FITCUR
2558 | BufferView::CHANGE);
2561 lt->selection.cursor = cursor;
2564 | BufferView::FITCUR
2565 | BufferView::CHANGE);
2572 case LFUN_BREAKPARAGRAPH:
2574 LyXText * lt = bv_->getLyXText();
2577 lt->breakParagraph(bv_, 0);
2580 | BufferView::FITCUR
2581 | BufferView::CHANGE);
2582 lt->selection.cursor = lt->cursor;
2584 owner_->showState();
2588 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2590 LyXText * lt = bv_->getLyXText();
2593 lt->breakParagraph(bv_, 1);
2596 | BufferView::FITCUR
2597 | BufferView::CHANGE);
2598 lt->selection.cursor = lt->cursor;
2600 owner_->showState();
2604 case LFUN_BREAKPARAGRAPH_SKIP:
2606 // When at the beginning of a paragraph, remove
2607 // indentation and add a "defskip" at the top.
2608 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2609 LyXText * lt = bv_->getLyXText();
2611 LyXCursor cursor = lt->cursor;
2614 if (cursor.pos() == 0) {
2615 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2618 cursor.par()->params().lineTop(),
2619 cursor.par()->params().lineBottom(),
2620 cursor.par()->params().pagebreakTop(),
2621 cursor.par()->params().pagebreakBottom(),
2622 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2623 cursor.par()->params().spacing(),
2624 cursor.par()->params().align(),
2625 cursor.par()->params().labelWidthString(), 1);
2626 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2630 lt->breakParagraph(bv_, 0);
2631 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2636 | BufferView::FITCUR
2637 | BufferView::CHANGE);
2638 lt->selection.cursor = cursor;
2640 owner_->showState();
2644 case LFUN_PARAGRAPH_SPACING:
2646 LyXText * lt = bv_->getLyXText();
2648 Paragraph * par = lt->cursor.par();
2649 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2650 float cur_value = 1.0;
2651 if (cur_spacing == Spacing::Other) {
2652 cur_value = par->params().spacing().getValue();
2655 istringstream istr(argument.c_str());
2659 Spacing::Space new_spacing = cur_spacing;
2660 float new_value = cur_value;
2662 lyxerr << "Missing argument to `paragraph-spacing'"
2664 } else if (tmp == "single") {
2665 new_spacing = Spacing::Single;
2666 } else if (tmp == "onehalf") {
2667 new_spacing = Spacing::Onehalf;
2668 } else if (tmp == "double") {
2669 new_spacing = Spacing::Double;
2670 } else if (tmp == "other") {
2671 new_spacing = Spacing::Other;
2674 lyxerr << "new_value = " << tmpval << endl;
2677 } else if (tmp == "default") {
2678 new_spacing = Spacing::Default;
2680 lyxerr << _("Unknown spacing argument: ")
2681 << argument << endl;
2683 if (cur_spacing != new_spacing || cur_value != new_value) {
2684 par->params().spacing(Spacing(new_spacing, new_value));
2685 lt->redoParagraph(bv_);
2688 | BufferView::FITCUR
2689 | BufferView::CHANGE);
2694 case LFUN_INSET_TOGGLE:
2696 LyXText * lt = bv_->getLyXText();
2699 update(lt, BufferView::SELECT|BufferView::FITCUR);
2700 lt->toggleInset(bv_);
2701 update(lt, BufferView::SELECT|BufferView::FITCUR);
2713 InsetCommandParams p;
2714 if (action == LFUN_HTMLURL)
2715 p.setCmdName("htmlurl");
2717 p.setCmdName("url");
2718 owner_->getDialogs()->createUrl(p.getAsString());
2722 case LFUN_INSERT_URL:
2724 InsetCommandParams p;
2725 p.setFromString(argument);
2727 InsetUrl * inset = new InsetUrl(p);
2728 if (!insertInset(inset))
2731 updateInset(inset, true);
2735 case LFUN_INSET_ERT:
2736 insertAndEditInset(new InsetERT(buffer_->params));
2739 case LFUN_INSET_EXTERNAL:
2740 insertAndEditInset(new InsetExternal);
2743 case LFUN_INSET_FOOTNOTE:
2744 insertAndEditInset(new InsetFoot(buffer_->params));
2747 case LFUN_INSET_MARGINAL:
2748 insertAndEditInset(new InsetMarginal(buffer_->params));
2751 case LFUN_INSET_MINIPAGE:
2752 insertAndEditInset(new InsetMinipage(buffer_->params));
2755 case LFUN_INSERT_NOTE:
2756 insertAndEditInset(new InsetNote(buffer_->params));
2759 case LFUN_INSET_FLOAT:
2760 // check if the float type exist
2761 if (floatList.typeExist(argument)) {
2762 insertAndEditInset(new InsetFloat(buffer_->params,
2765 lyxerr << "Non-existent float type: "
2766 << argument << endl;
2770 case LFUN_INSET_WIDE_FLOAT:
2771 // check if the float type exist
2772 if (floatList.typeExist(argument)) {
2773 InsetFloat * new_inset =
2774 new InsetFloat(buffer_->params, argument);
2775 new_inset->wide(true);
2776 insertAndEditInset(new_inset);
2778 lyxerr << "Non-existent float type: "
2779 << argument << endl;
2784 case LFUN_INSET_LIST:
2785 insertAndEditInset(new InsetList);
2788 case LFUN_INSET_THEOREM:
2789 insertAndEditInset(new InsetTheorem);
2793 case LFUN_INSET_CAPTION:
2795 // Do we have a locking inset...
2796 if (bv_->theLockingInset()) {
2797 lyxerr << "Locking inset code: "
2798 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2799 InsetCaption * new_inset =
2800 new InsetCaption(buffer_->params);
2801 new_inset->setOwner(bv_->theLockingInset());
2802 new_inset->setAutoBreakRows(true);
2803 new_inset->setDrawFrame(0, InsetText::LOCKED);
2804 new_inset->setFrameColor(0, LColor::captionframe);
2805 if (insertInset(new_inset))
2806 new_inset->edit(bv_);
2813 case LFUN_INSET_TABULAR:
2817 if (!argument.empty())
2818 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2819 InsetTabular * new_inset =
2820 new InsetTabular(*buffer_, r, c);
2822 bv_->getLyXText()->real_current_font.isRightToLeft();
2823 if (!open_new_inset(new_inset, rtl))
2828 // --- lyxserver commands ----------------------------
2830 case LFUN_CHARATCURSOR:
2832 pos_type pos = bv_->getLyXText()->cursor.pos();
2833 if (pos < bv_->getLyXText()->cursor.par()->size())
2834 owner_->getLyXFunc()->setMessage(
2835 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2837 owner_->getLyXFunc()->setMessage("EOF");
2842 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2844 + tostr(bv_->getLyXText()->cursor.y()));
2851 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2852 lyxerr << "SETXY: Could not parse coordinates in '"
2853 << argument << std::endl;
2855 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2859 case LFUN_GETLAYOUT:
2860 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2865 LyXFont & font = bv_->getLyXText()->current_font;
2866 if (font.shape() == LyXFont::ITALIC_SHAPE)
2867 owner_->getLyXFunc()->setMessage("E");
2868 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2869 owner_->getLyXFunc()->setMessage("N");
2871 owner_->getLyXFunc()->setMessage("0");
2876 // --- accented characters ---------------------------
2879 case LFUN_CIRCUMFLEX:
2889 case LFUN_SPECIAL_CARON:
2892 case LFUN_HUNG_UMLAUT:
2895 if (argument.empty()) {
2897 owner_->getLyXFunc()->handleKeyFunc(action);
2899 owner_->getLyXFunc()->handleKeyFunc(action);
2900 owner_->getIntl()->getTransManager()
2901 .TranslateAndInsert(argument[0], bv_->getLyXText());
2902 update(bv_->getLyXText(),
2904 | BufferView::FITCUR
2905 | BufferView::CHANGE);
2910 mathDispatch(bv_, argument);
2913 case LFUN_MATH_MACRO:
2914 mathDispatchMathMacro(bv_, argument);
2917 case LFUN_MATH_DELIM:
2918 mathDispatchMathDelim(bv_, argument);
2921 case LFUN_INSERT_MATRIX:
2922 mathDispatchInsertMatrix(bv_, argument);
2925 case LFUN_INSERT_MATH:
2926 mathDispatchInsertMath(bv_, argument);
2929 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2930 mathDispatchMathImportSelection(bv_, argument);
2933 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2934 mathDispatchMathDisplay(bv_, argument);
2937 case LFUN_MATH_MODE: // Open or create an inlined math inset
2938 mathDispatchMathMode(bv_, argument);
2941 case LFUN_GREEK: // Insert a single greek letter
2942 mathDispatchGreek(bv_, argument);
2945 case LFUN_CITATION_INSERT:
2947 InsetCommandParams p;
2948 p.setFromString(argument);
2950 InsetCitation * inset = new InsetCitation(p);
2951 if (!insertInset(inset))
2954 updateInset(inset, true);
2958 case LFUN_INSERT_BIBTEX:
2960 // ale970405+lasgoutt970425
2961 // The argument can be up to two tokens separated
2962 // by a space. The first one is the bibstyle.
2963 string const db = token(argument, ' ', 0);
2964 string const bibstyle = token(argument, ' ', 1);
2966 InsetCommandParams p("BibTeX", db, bibstyle);
2967 InsetBibtex * inset = new InsetBibtex(p);
2969 if (insertInset(inset)) {
2970 if (argument.empty())
2977 // BibTeX data bases
2978 case LFUN_BIBDB_ADD:
2980 InsetBibtex * inset =
2981 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2983 inset->addDatabase(argument);
2988 case LFUN_BIBDB_DEL:
2990 InsetBibtex * inset =
2991 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2993 inset->delDatabase(argument);
2998 case LFUN_BIBTEX_STYLE:
3000 InsetBibtex * inset =
3001 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3003 inset->setOptions(argument);
3008 case LFUN_INDEX_CREATE:
3010 InsetCommandParams p("index");
3011 if (argument.empty()) {
3012 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3013 p.setContents(idxstring);
3015 p.setContents(argument);
3018 owner_->getDialogs()->createIndex(p.getAsString());
3022 case LFUN_INDEX_INSERT:
3024 InsetCommandParams p;
3025 p.setFromString(argument);
3026 InsetIndex * inset = new InsetIndex(p);
3028 if (!insertInset(inset))
3031 updateInset(inset, true);
3035 case LFUN_INDEX_INSERT_LAST:
3037 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3038 if (!idxstring.empty()) {
3039 owner_->message(_("Word `")
3040 + idxstring + _(("' indexed.")));
3041 InsetCommandParams p("index", idxstring);
3042 InsetIndex * inset = new InsetIndex(p);
3044 if (!insertInset(inset))
3047 updateInset(inset, true);
3052 case LFUN_INDEX_PRINT:
3054 InsetCommandParams p("printindex");
3055 Inset * inset = new InsetPrintIndex(p);
3056 if (!insertInset(inset, tclass.defaultLayoutName()))
3061 case LFUN_PARENTINSERT:
3063 InsetCommandParams p("lyxparent", argument);
3064 Inset * inset = new InsetParent(p, *buffer_);
3065 if (!insertInset(inset, tclass.defaultLayoutName()))
3071 case LFUN_CHILD_INSERT:
3073 InsetInclude::Params p;
3074 p.cparams.setFromString(argument);
3075 p.masterFilename_ = buffer_->fileName();
3077 InsetInclude * inset = new InsetInclude(p);
3078 if (!insertInset(inset))
3081 updateInset(inset, true);
3082 bv_->owner()->getDialogs()->showInclude(inset);
3087 case LFUN_FLOAT_LIST:
3088 if (floatList.typeExist(argument)) {
3089 Inset * inset = new InsetFloatList(argument);
3090 if (!insertInset(inset, tclass.defaultLayoutName()))
3093 lyxerr << "Non-existent float type: "
3094 << argument << endl;
3098 case LFUN_THESAURUS_ENTRY:
3100 string arg = argument;
3103 arg = bv_->getLyXText()->selectionAsString(buffer_,
3107 if (arg.size() > 100 || arg.empty()) {
3108 // Get word or selection
3109 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3110 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3111 // FIXME: where is getLyXText()->unselect(bv_) ?
3115 bv_->owner()->getDialogs()->showThesaurus(arg);
3119 case LFUN_SELFINSERT:
3121 if (argument.empty()) break;
3123 /* Automatically delete the currently selected
3124 * text and replace it with what is being
3125 * typed in now. Depends on lyxrc settings
3126 * "auto_region_delete", which defaults to
3129 LyXText * lt = bv_->getLyXText();
3131 if (lyxrc.auto_region_delete) {
3132 if (lt->selection.set()) {
3133 lt->cutSelection(bv_, false, false);
3136 | BufferView::FITCUR
3137 | BufferView::CHANGE);
3139 workarea().haveSelection(false);
3143 LyXFont const old_font(lt->real_current_font);
3145 string::const_iterator cit = argument.begin();
3146 string::const_iterator end = argument.end();
3147 for (; cit != end; ++cit) {
3148 owner_->getIntl()->getTransManager().
3149 TranslateAndInsert(*cit, lt);
3154 | BufferView::FITCUR
3155 | BufferView::CHANGE);
3157 lt->selection.cursor = lt->cursor;
3158 moveCursorUpdate(false);
3160 // real_current_font.number can change so we need to
3161 // update the minibuffer
3162 if (old_font != lt->real_current_font)
3163 owner_->showState();
3168 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3170 time_t now_time_t = time(NULL);
3171 struct tm * now_tm = localtime(&now_time_t);
3172 setlocale(LC_TIME, "");
3174 if (!argument.empty())
3177 arg = lyxrc.date_insert_format;
3179 int const datetmp_len =
3180 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3182 LyXText * lt = bv_->getLyXText();
3184 for (int i = 0; i < datetmp_len; i++) {
3185 lt->insertChar(bv_, datetmp[i]);
3188 | BufferView::FITCUR
3189 | BufferView::CHANGE);
3192 lt->selection.cursor = lt->cursor;
3193 moveCursorUpdate(false);
3197 case LFUN_UNKNOWN_ACTION:
3198 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3209 void BufferView::Pimpl::newline()
3212 LyXText * lt = bv_->getLyXText();
3216 | BufferView::FITCUR);
3217 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3220 | BufferView::FITCUR
3221 | BufferView::CHANGE);
3226 void BufferView::Pimpl::hfill()
3229 LyXText * lt = bv_->getLyXText();
3233 | BufferView::FITCUR);
3234 lt->insertChar(bv_, Paragraph::META_HFILL);
3237 | BufferView::FITCUR
3238 | BufferView::CHANGE);
3243 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3246 LyXText * lt = bv_->getLyXText();
3249 update(lt, BufferView::SELECT|BufferView::FITCUR);
3250 InsetSpecialChar * new_inset =
3251 new InsetSpecialChar(kind);
3252 if (!insertInset(new_inset))
3255 updateInset(new_inset, true);
3260 void BufferView::Pimpl::smartQuote()
3262 LyXText const * lt = bv_->getLyXText();
3263 Paragraph const * par = lt->cursor.par();
3264 pos_type pos = lt->cursor.pos();
3268 || (par->isInset(pos - 1)
3269 && par->getInset(pos - 1)->isSpace()))
3272 c = par->getChar(pos - 1);
3277 LyXLayout const & style =
3278 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3280 if (style.pass_thru ||
3281 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3282 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3286 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3288 if (insertInset(inset))
3295 // Open and lock an updatable inset
3296 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3298 LyXText * lt = bv_->getLyXText();
3302 if (!insertInset(new_inset)) {
3306 new_inset->edit(bv_, !behind);
3311 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3313 // if we are in a locking inset we should try to insert the
3314 // inset there otherwise this is a illegal function now
3315 if (bv_->theLockingInset()) {
3316 if (bv_->theLockingInset()->insetAllowed(inset))
3317 return bv_->theLockingInset()->insertInset(bv_, inset);
3321 // not quite sure if we want this...
3322 setCursorParUndo(bv_);
3325 beforeChange(bv_->text);
3326 if (!lout.empty()) {
3327 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3328 bv_->text->breakParagraph(bv_);
3329 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3331 if (bv_->text->cursor.par()->size()) {
3332 bv_->text->cursorLeft(bv_);
3334 bv_->text->breakParagraph(bv_);
3335 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3339 LyXTextClass const & tclass =
3340 textclasslist[buffer_->params.textclass];
3341 bool hasLayout = tclass.hasLayout(lres);
3342 string lay = tclass.defaultLayoutName();
3344 if (hasLayout != false) {
3348 // layout not fount using default
3349 lay = tclass.defaultLayoutName();
3352 bv_->text->setLayout(bv_, lay);
3354 bv_->text->setParagraph(bv_, 0, 0,
3356 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3364 bv_->text->insertInset(bv_, inset);
3365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3372 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3374 if (!inset || !available())
3377 // first check for locking insets
3378 if (bv_->theLockingInset()) {
3379 if (bv_->theLockingInset() == inset) {
3380 if (bv_->text->updateInset(bv_, inset)) {
3383 buffer_->markDirty();
3388 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3389 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3392 buffer_->markDirty();
3400 // then check if the inset is a top_level inset (has no owner)
3401 // if yes do the update as always otherwise we have to update the
3402 // toplevel inset where this inset is inside
3403 Inset * tl_inset = inset;
3404 while(tl_inset->owner())
3405 tl_inset = tl_inset->owner();
3407 if (tl_inset == inset) {
3408 update(bv_->text, BufferView::UPDATE);
3409 if (bv_->text->updateInset(bv_, inset)) {
3413 | BufferView::FITCUR
3414 | BufferView::CHANGE);
3416 update(bv_->text, SELECT);
3420 } else if (static_cast<UpdatableInset *>(tl_inset)
3421 ->updateInsetInInset(bv_, inset))
3423 if (bv_->text->updateInset(bv_, tl_inset)) {
3431 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3434 if (!available()) return;
3437 beforeChange(bv_->text);
3438 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3440 LyXCursor const & cursor = bv_->text->cursor;
3444 cursor.par()->isInset(cursor.pos())) {
3445 Inset const * inset = cursor.par()->getInset(cursor.pos());
3446 if (find(codes.begin(), codes.end(), inset->lyxCode())
3449 static_cast<InsetCommand const *>(inset)->getContents();
3453 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3454 if (bv_->text->cursor.pos()
3455 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3456 LyXCursor tmp = bv_->text->cursor;
3457 bv_->text->cursor.par(bv_->text->ownerParagraph());
3458 bv_->text->cursor.pos(0);
3459 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3460 bv_->text->cursor = tmp;
3461 bv_->owner()->message(_("No more insets"));
3464 bv_->owner()->message(_("No more insets"));
3467 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3468 bv_->text->selection.cursor = bv_->text->cursor;
3472 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3474 gotoInset(vector<Inset::Code>(1, code), same_content);