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 "funcrequest.h"
45 #include "insets/insetbib.h"
46 #include "insets/insettext.h"
47 #include "insets/inseturl.h"
48 #include "insets/insetlatexaccent.h"
49 #include "insets/insettoc.h"
50 #include "insets/insetref.h"
51 #include "insets/insetparent.h"
52 #include "insets/insetindex.h"
53 #include "insets/insetnote.h"
54 #include "insets/insetinclude.h"
55 #include "insets/insetcite.h"
56 #include "insets/insetert.h"
57 #include "insets/insetexternal.h"
58 #include "insets/insetgraphics.h"
59 #include "insets/insetfoot.h"
60 #include "insets/insetmarginal.h"
61 #include "insets/insetminipage.h"
62 #include "insets/insetfloat.h"
63 #include "insets/insettabular.h"
65 #include "insets/insettheorem.h"
66 #include "insets/insetlist.h"
68 #include "insets/insetcaption.h"
69 #include "insets/insetfloatlist.h"
70 #include "insets/insetspecialchar.h"
72 #include "mathed/formulabase.h"
74 #include "graphics/Previews.h"
76 #include "support/LAssert.h"
77 #include "support/lstrings.h"
78 #include "support/filetools.h"
79 #include "support/lyxfunctional.h"
81 #include <boost/bind.hpp>
82 #include <boost/signals/connection.hpp>
91 extern string current_layout;
93 #ifndef CXX_GLOBAL_CSTD
106 using std::make_pair;
110 using lyx::textclass_type;
112 /* the selection possible is needed, that only motion events are
113 * used, where the bottom press event was on the drawing area too */
114 bool selection_possible = false;
116 extern BufferList bufferlist;
117 extern char ascii_type;
119 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
124 unsigned int const saved_positions_num = 20;
126 // All the below connection objects are needed because of a bug in some
127 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
128 // to these connections we avoid a segfault upon startup, and also at exit.
131 boost::signals::connection timecon;
132 boost::signals::connection doccon;
133 boost::signals::connection resizecon;
134 boost::signals::connection bpresscon;
135 boost::signals::connection breleasecon;
136 boost::signals::connection motioncon;
137 boost::signals::connection doublecon;
138 boost::signals::connection triplecon;
139 boost::signals::connection kpresscon;
140 boost::signals::connection selectioncon;
141 boost::signals::connection lostcon;
146 BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
147 int xpos, int ypos, int width, int height)
148 : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
149 using_xterm_cursor(false)
151 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
152 screen_.reset(LyXScreenFactory::create(workarea()));
155 doccon = workarea().scrollDocView
156 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
157 resizecon = workarea().workAreaResize
158 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
159 bpresscon = workarea().workAreaButtonPress
160 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
161 breleasecon = workarea().workAreaButtonRelease
162 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
163 motioncon = workarea().workAreaMotionNotify
164 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
165 doublecon = workarea().workAreaDoubleClick
166 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
167 triplecon = workarea().workAreaTripleClick
168 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
169 kpresscon = workarea().workAreaKeyPress
170 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
171 selectioncon = workarea().selectionRequested
172 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
173 lostcon = workarea().selectionLost
174 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
176 timecon = cursor_timeout.timeout
177 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
178 cursor_timeout.start();
179 saved_positions.resize(saved_positions_num);
183 WorkArea & BufferView::Pimpl::workarea() const
185 return *workarea_.get();
189 LyXScreen & BufferView::Pimpl::screen() const
191 return *screen_.get();
195 Painter & BufferView::Pimpl::painter() const
197 return workarea().getPainter();
201 void BufferView::Pimpl::buffer(Buffer * b)
203 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
206 buffer_->delUser(bv_);
208 // Put the old text into the TextCache, but
209 // only if the buffer is still loaded.
210 // Also set the owner of the test to 0
211 // bv_->text->owner(0);
212 textcache.add(buffer_, workarea().workWidth(), bv_->text);
213 if (lyxerr.debugging())
214 textcache.show(lyxerr, "BufferView::buffer");
219 // set current buffer
222 if (bufferlist.getState() == BufferList::CLOSING) return;
224 // if we are closing the buffer, use the first buffer as current
226 buffer_ = bufferlist.first();
230 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
231 buffer_->addUser(bv_);
233 // If we don't have a text object for this, we make one
234 if (bv_->text == 0) {
235 resizeCurrentBuffer();
238 // FIXME: needed when ?
240 screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
242 // Similarly, buffer-dependent dialogs should be updated or
243 // hidden. This should go here because some dialogs (eg ToC)
244 // require bv_->text.
245 owner_->getDialogs().updateBufferDependent(true);
247 lyxerr[Debug::INFO] << " No Buffer!" << endl;
248 owner_->getDialogs().hideBufferDependent();
250 // Also remove all remaining text's from the testcache.
251 // (there should not be any!) (if there is any it is a
253 if (lyxerr.debugging())
254 textcache.show(lyxerr, "buffer delete all");
260 owner_->updateMenubar();
261 owner_->updateToolbar();
262 owner_->updateLayoutChoice();
263 owner_->updateWindowTitle();
265 if (grfx::Previews::activated() && buffer_)
266 grfx::Previews::get().generateBufferPreviews(*buffer_);
270 bool BufferView::Pimpl::fitCursor()
274 if (bv_->theLockingInset()) {
275 bv_->theLockingInset()->fitInsetCursor(bv_);
278 ret = screen().fitCursor(bv_->text, bv_);
281 bv_->owner()->getDialogs().updateParagraph();
288 void BufferView::Pimpl::redoCurrentBuffer()
290 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
291 if (buffer_ && bv_->text) {
292 resizeCurrentBuffer();
294 owner_->updateLayoutChoice();
300 int BufferView::Pimpl::resizeCurrentBuffer()
302 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
305 Paragraph * selstartpar = 0;
306 Paragraph * selendpar = 0;
307 UpdatableInset * the_locking_inset = 0;
310 pos_type selstartpos = 0;
311 pos_type selendpos = 0;
312 bool selection = false;
313 bool mark_set = false;
315 owner_->prohibitInput();
317 owner_->message(_("Formatting document..."));
320 par = bv_->text->cursor.par();
321 pos = bv_->text->cursor.pos();
322 selstartpar = bv_->text->selection.start.par();
323 selstartpos = bv_->text->selection.start.pos();
324 selendpar = bv_->text->selection.end.par();
325 selendpos = bv_->text->selection.end.pos();
326 selection = bv_->text->selection.set();
327 mark_set = bv_->text->selection.mark();
328 the_locking_inset = bv_->theLockingInset();
329 buffer_->resizeInsets(bv_);
330 // I don't think the delete and new are necessary here we just could
331 // call only init! (Jug 20020419)
333 bv_->text = new LyXText(bv_);
334 bv_->text->init(bv_);
336 // See if we have a text in TextCache that fits
337 // the new buffer_ with the correct width.
338 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
340 if (lyxerr.debugging()) {
341 lyxerr << "Found a LyXText that fits:\n";
342 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
344 // Set the owner of the newly found text
345 // bv_->text->owner(bv_);
346 if (lyxerr.debugging())
347 textcache.show(lyxerr, "resizeCurrentBuffer");
349 bv_->text = new LyXText(bv_);
350 bv_->text->init(bv_);
351 //buffer_->resizeInsets(bv_);
356 bv_->text->selection.set(true);
357 // At this point just to avoid the Delete-Empty-Paragraph-
358 // Mechanism when setting the cursor.
359 bv_->text->selection.mark(mark_set);
361 bv_->text->setCursor(bv_, selstartpar, selstartpos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->setCursor(bv_, selendpar, selendpos);
364 bv_->text->setSelection(bv_);
365 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->setCursor(bv_, par, pos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->selection.set(false);
371 // remake the inset locking
372 bv_->theLockingInset(the_locking_inset);
375 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
378 owner_->allowInput();
386 void BufferView::Pimpl::repaint()
388 // Regenerate the screen.
389 screen().redraw(bv_->text, bv_);
393 void BufferView::Pimpl::updateScrollbar()
396 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
397 workarea().setScrollbarParams(0, 0, 0);
401 LyXText const & t = *bv_->text;
403 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
404 << t.first_y << ", default height " << t.defaultHeight() << endl;
406 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
410 void BufferView::Pimpl::scrollDocView(int value)
412 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
414 if (!buffer_) return;
416 screen().draw(bv_->text, bv_, value);
418 if (!lyxrc.cursor_follows_scrollbar) {
422 LyXText * vbt = bv_->text;
424 int const height = vbt->defaultHeight();
425 int const first = static_cast<int>((bv_->text->first_y + height));
426 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
428 if (vbt->cursor.y() < first)
429 vbt->setCursorFromCoordinates(bv_, 0, first);
430 else if (vbt->cursor.y() > last)
431 vbt->setCursorFromCoordinates(bv_, 0, last);
435 int BufferView::Pimpl::scroll(long time)
440 LyXText const * t = bv_->text;
442 double const diff = t->defaultHeight()
443 + double(time) * double(time) * 0.125;
445 scrollDocView(int(diff));
446 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
451 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
452 key_modifier::state state)
454 bv_->owner()->getLyXFunc().processKeySym(key, state);
458 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
460 // Only use motion with button 1
461 if (!(state & mouse_button::button1))
467 // Check for inset locking
468 if (bv_->theLockingInset()) {
469 LyXCursor cursor = bv_->text->cursor;
470 LyXFont font = bv_->text->getFont(buffer_,
471 cursor.par(), cursor.pos());
472 int width = bv_->theLockingInset()->width(bv_, font);
473 int inset_x = font.isVisibleRightToLeft()
474 ? cursor.ix() - width : cursor.ix();
475 int start_x = inset_x + bv_->theLockingInset()->scroll();
477 FuncRequest cmd(bv_, LFUN_MOUSE_MOTION,
478 x - start_x, y - cursor.iy() + bv_->text->first_y, state);
479 bv_->theLockingInset()->localDispatch(cmd);
483 // The test for not selection possible is needed, that only motion
484 // events are used, where the bottom press event was on
485 // the drawing area too
486 if (!selection_possible)
489 screen().hideCursor();
491 Row * cursorrow = bv_->text->cursor.row();
492 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
494 // sorry for this but I have a strange error that the y value jumps at
495 // a certain point. This seems like an error in my xforms library or
496 // in some other local environment, but I would like to leave this here
497 // for the moment until I can remove this (Jug 20020418)
498 if (y_before < bv_->text->cursor.y())
499 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
501 // This is to allow jumping over large insets
502 if (cursorrow == bv_->text->cursor.row()) {
503 if (y >= int(workarea().workHeight())) {
504 bv_->text->cursorDown(bv_, false);
506 bv_->text->cursorUp(bv_, false);
510 if (!bv_->text->selection.set())
511 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
513 bv_->text->setSelection(bv_);
514 screen().toggleToggle(bv_->text, bv_);
520 // Single-click on work area
521 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
522 mouse_button::state button)
527 // ok ok, this is a hack (for xforms)
528 if (button == mouse_button::button4) {
529 scroll(-lyxrc.wheel_jump);
530 // We shouldn't go further down as we really should only do the
531 // scrolling and be done with this. Otherwise we may open some
532 // dialogs (Jug 20020424).
534 } else if (button == mouse_button::button5) {
535 scroll(lyxrc.wheel_jump);
536 // We shouldn't go further down as we really should only do the
537 // scrolling and be done with this. Otherwise we may open some
538 // dialogs (Jug 20020424).
542 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
544 // Middle button press pastes if we have a selection
545 // We do this here as if the selection was inside an inset
546 // it could get cleared on the unlocking of the inset so
547 // we have to check this first
548 bool paste_internally = false;
549 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
550 owner_->dispatch(FuncRequest(LFUN_COPY));
551 paste_internally = true;
554 int const screen_first = bv_->text->first_y;
556 if (bv_->theLockingInset()) {
557 // We are in inset locking mode
559 // Check whether the inset was hit. If not reset mode,
560 // otherwise give the event to the inset
561 if (inset_hit == bv_->theLockingInset()) {
562 FuncRequest cmd(bv_, LFUN_MOUSE_PRESS, xpos, ypos, button);
563 bv_->theLockingInset()->localDispatch(cmd);
566 bv_->unlockInset(bv_->theLockingInset());
570 selection_possible = true;
571 screen().hideCursor();
573 // Clear the selection
574 screen().toggleSelection(bv_->text, bv_);
575 bv_->text->clearSelection();
576 bv_->text->fullRebreak(bv_);
580 // Single left click in math inset?
581 if (isHighlyEditableInset(inset_hit)) {
582 // Highly editable inset, like math
583 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
584 selection_possible = false;
585 owner_->updateLayoutChoice();
586 owner_->message(inset->editMessage());
587 //inset->edit(bv_, xpos, ypos, button);
588 // We just have to lock the inset before calling a PressEvent on it!
589 // we don't need the edit() call here! (Jug20020329)
590 if (!bv_->lockInset(inset)) {
591 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
593 FuncRequest cmd(bv_, LFUN_MOUSE_PRESS, xpos, ypos, button);
594 inset->localDispatch(cmd);
597 // I'm not sure we should continue here if we hit an inset (Jug20020403)
599 // Right click on a footnote flag opens float menu
600 if (button == mouse_button::button3) {
601 selection_possible = false;
605 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
606 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
608 bv_->text->selection.cursor = bv_->text->cursor;
609 bv_->text->cursor.x_fix(bv_->text->cursor.x());
611 owner_->updateLayoutChoice();
613 selection_possible = false;
616 // Insert primary selection with middle mouse
617 // if there is a local selection in the current buffer,
619 if (button == mouse_button::button2) {
620 if (paste_internally)
621 owner_->dispatch(FuncRequest(LFUN_PASTE));
623 owner_->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
624 selection_possible = false;
630 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
635 LyXText * text = bv_->getLyXText();
637 if (text->bv_owner && bv_->theLockingInset())
640 if (button == mouse_button::button1) {
641 if (text->bv_owner) {
642 screen().hideCursor();
643 screen().toggleSelection(text, bv_);
644 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
645 screen().toggleSelection(text, bv_, false);
647 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
649 /* This will fit the cursor on the screen
651 update(text, BufferView::SELECT|BufferView::FITCUR);
652 workarea().haveSelection(bv_->getLyXText()->selection.set());
657 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
662 LyXText * text = bv_->getLyXText();
664 if (text->bv_owner && bv_->theLockingInset())
667 if (button == mouse_button::button1) {
668 if (text->bv_owner) {
669 screen().hideCursor();
670 screen().toggleSelection(text, bv_);
672 text->cursorHome(bv_);
673 text->selection.cursor = text->cursor;
674 text->cursorEnd(bv_);
675 text->setSelection(bv_);
676 if (text->bv_owner) {
677 screen().toggleSelection(text, bv_, false);
679 /* This will fit the cursor on the screen
681 update(text, BufferView::SELECT|BufferView::FITCUR);
682 workarea().haveSelection(bv_->getLyXText()->selection.set());
687 void BufferView::Pimpl::selectionRequested()
694 LyXText * text = bv_->getLyXText();
696 if (text->selection.set() &&
697 (!bv_->text->xsel_cache.set() ||
698 text->selection.start != bv_->text->xsel_cache.start ||
699 text->selection.end != bv_->text->xsel_cache.end))
701 bv_->text->xsel_cache = text->selection;
702 sel = text->selectionAsString(bv_->buffer(), false);
703 } else if (!text->selection.set()) {
705 bv_->text->xsel_cache.set(false);
708 workarea().putClipboard(sel);
713 void BufferView::Pimpl::selectionLost()
718 bv_->getLyXText()->clearSelection();
720 bv_->text->xsel_cache.set(false);
725 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
726 mouse_button::state button)
728 // do nothing if we used the mouse wheel
729 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
732 // If we hit an inset, we have the inset coordinates in these
733 // and inset_hit points to the inset. If we do not hit an
734 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
735 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
737 if (bv_->theLockingInset()) {
738 // We are in inset locking mode.
740 // LyX does a kind of work-area grabbing for insets.
741 // Only a ButtonPress FuncRequest outside the inset will
742 // force a insetUnlock.
743 FuncRequest cmd(bv_, LFUN_MOUSE_RELEASE, x, y, button);
744 bv_->theLockingInset()->localDispatch(cmd);
748 selection_possible = false;
750 if (button == mouse_button::button2)
754 if (button == mouse_button::button1) {
755 workarea().haveSelection(bv_->getLyXText()->selection.set());
759 owner_->view_state_changed();
760 owner_->updateMenubar();
761 owner_->updateToolbar();
763 // Did we hit an editable inset?
765 selection_possible = false;
767 // if we reach this point with a selection, it
768 // must mean we are currently selecting.
769 // But we don't want to open the inset
770 // because that is annoying for the user.
771 // So just pretend we didn't hit it.
772 // this is OK because a "kosher" ButtonRelease
773 // will follow a ButtonPress that clears
775 // Note this also fixes selection drawing
776 // problems if we end up opening an inset
777 if (bv_->getLyXText()->selection.set())
780 // CHECK fix this proper in 0.13
781 // well, maybe 13.0 !!!!!!!!!
783 // Following a ref shouldn't issue
784 // a push on the undo-stack
785 // anylonger, now that we have
786 // keybindings for following
787 // references and returning from
788 // references. IMHO though, it
789 // should be the inset's own business
790 // to push or not push on the undo
791 // stack. They don't *have* to
792 // alter the document...
794 // ...or maybe the SetCursorParUndo()
795 // below isn't necessary at all anylonger?
796 if (inset_hit->lyxCode() == Inset::REF_CODE) {
797 setCursorParUndo(bv_);
800 owner_->message(inset_hit->editMessage());
802 if (isHighlyEditableInset(inset_hit)) {
803 // Highly editable inset, like math
804 UpdatableInset *inset = (UpdatableInset *)inset_hit;
805 FuncRequest cmd(bv_, LFUN_MOUSE_RELEASE, x, y, button);
806 inset->localDispatch(cmd);
808 FuncRequest cmd(bv_, LFUN_MOUSE_RELEASE, x, y, button);
809 inset_hit->localDispatch(cmd);
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
815 #warning Please remove donot call inset->edit() here (Jug 20020812)
817 inset_hit->edit(bv_, x, y, button);
822 // Maybe we want to edit a bibitem ale970302
823 if (bv_->text->cursor.par()->bibkey) {
824 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
825 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
826 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
827 (!is_rtl && x < 20+width)) {
828 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
836 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
837 LyXCursor const & cursor) const
839 Paragraph /*const*/ & par = *cursor.par();
840 pos_type const pos = cursor.pos();
842 lyx::Assert(par.getInset(pos));
844 Inset const & inset(*par.getInset(pos));
846 LyXFont const & font = text.getFont(buffer_, &par, pos);
848 int const width = inset.width(bv_, font);
849 int const inset_x = font.isVisibleRightToLeft()
850 ? (cursor.ix() - width) : cursor.ix();
853 inset_x + inset.scroll(),
855 cursor.iy() - inset.ascent(bv_, font),
856 cursor.iy() + inset.descent(bv_, font));
860 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
861 LyXCursor const & cursor,
862 int & x, int & y) const
864 pos_type const pos(cursor.pos());
865 Paragraph /*const*/ & par(*cursor.par());
867 if (pos >= par.size() || !par.isInset(pos)) {
871 Inset /*const*/ * inset = par.getInset(pos);
873 if (!isEditableInset(inset)) {
877 Box b(insetDimensions(text, cursor));
879 if (!b.contained(x, y)) {
880 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
881 << " box " << b << endl;
885 text.setCursor(bv_, &par, pos, true);
888 // The origin of an inset is on the baseline
889 y -= text.cursor.iy();
895 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
897 int y_tmp = y + text->first_y;
900 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
902 Inset * inset(checkInset(*text, cursor, x, y_tmp));
909 // look at previous position
911 if (cursor.pos() == 0) {
916 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
918 inset = checkInset(*text, cursor, x, y_tmp);
926 void BufferView::Pimpl::workAreaResize()
928 static int work_area_width;
929 static int work_area_height;
931 bool const widthChange = workarea().workWidth() != work_area_width;
932 bool const heightChange = workarea().workHeight() != work_area_height;
934 // update from work area
935 work_area_width = workarea().workWidth();
936 work_area_height = workarea().workHeight();
940 // The visible LyXView need a resize
941 resizeCurrentBuffer();
943 // Remove all texts from the textcache
944 // This is not _really_ what we want to do. What
945 // we really want to do is to delete in textcache
946 // that does not have a BufferView with matching
947 // width, but as long as we have only one BufferView
948 // deleting all gives the same result.
949 if (lyxerr.debugging())
950 textcache.show(lyxerr, "Expose delete all");
952 // FIXME: this is aalready done in resizeCurrentBuffer() ??
953 buffer_->resizeInsets(bv_);
954 } else if (heightChange) {
955 // fitCursor() ensures we don't jump back
956 // to the start of the document on vertical
962 if (widthChange || heightChange) {
966 // always make sure that the scrollbar is sane.
968 owner_->updateLayoutChoice();
973 void BufferView::Pimpl::update()
975 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
976 LyXText::text_status st = bv_->text->status();
977 screen().update(bv_->text, bv_);
979 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
980 bv_->text->fullRebreak(bv_);
981 st = LyXText::NEED_MORE_REFRESH;
982 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
983 bv_->text->cursor.pos());
984 if (bv_->text->selection.set()) {
985 bv_->text->setCursor(bv_, bv_->text->selection.start,
986 bv_->text->selection.start.par(),
987 bv_->text->selection.start.pos());
988 bv_->text->setCursor(bv_, bv_->text->selection.end,
989 bv_->text->selection.end.par(),
990 bv_->text->selection.end.pos());
993 bv_->text->status(bv_, st);
994 screen().update(bv_->text, bv_);
996 // do this here instead of in the screen::update because of
998 bv_->text->status(bv_, LyXText::UNCHANGED);
1004 // Values used when calling update:
1006 // -2 - update, move sel_cursor if selection, fitcursor
1007 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1008 // 0 - update, move sel_cursor if selection, fitcursor
1009 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1010 // 3 - update, move sel_cursor if selection
1013 // a simple redraw of the parts that need refresh
1015 // move sel_cursor if selection -
1016 // the text's sel_cursor is moved if there is selection is progress
1019 // fitCursor() is called and the scrollbar updated
1022 // the buffer is marked dirty.
1031 // UPDATE_ONLY = UPDATE;
1032 // UPDATE_SELECT = UPDATE | SELECT;
1033 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1034 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1036 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1037 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1038 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1039 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1040 // update(3) -> update(1) -> update(1) -> update(SELECT)
1042 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1044 owner_->updateLayoutChoice();
1046 if (!text->selection.set() && (f & SELECT)) {
1047 text->selection.cursor = text->cursor;
1050 text->fullRebreak(bv_);
1052 if (text->inset_owner) {
1053 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1054 updateInset(text->inset_owner, false);
1064 buffer_->markDirty();
1069 // Callback for cursor timer
1070 void BufferView::Pimpl::cursorToggle()
1073 cursor_timeout.restart();
1078 extern void reapSpellchecker(void);
1081 if (!bv_->theLockingInset()) {
1082 screen().cursorToggle(bv_);
1084 bv_->theLockingInset()->toggleInsetCursor(bv_);
1087 cursor_timeout.restart();
1091 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1093 if (!text->cursor.row()->previous()) {
1094 if (text->first_y > 0) {
1095 int new_y = bv_->text->first_y - workarea().workHeight();
1096 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1102 int y = text->first_y;
1103 Row * cursorrow = text->cursor.row();
1105 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1109 if (cursorrow == bv_->text->cursor.row()) {
1110 // we have a row which is higher than the workarea so we leave the
1111 // cursor on the start of the row and move only the draw up as soon
1112 // as we move the cursor or do something while inside the row (it may
1113 // span several workarea-heights) we'll move to the top again, but this
1114 // is better than just jump down and only display part of the row.
1115 new_y = bv_->text->first_y - workarea().workHeight();
1117 if (text->inset_owner) {
1118 new_y = bv_->text->cursor.iy()
1119 + bv_->theLockingInset()->insetInInsetY() + y
1120 + text->cursor.row()->height()
1121 - workarea().workHeight() + 1;
1123 new_y = text->cursor.y()
1124 - text->cursor.row()->baseline()
1125 + text->cursor.row()->height()
1126 - workarea().workHeight() + 1;
1129 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1130 if (text->cursor.row()->previous()) {
1132 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1133 text->cursor.row()->previous()->pos(), false);
1134 if (cur.y() > text->first_y) {
1135 text->cursorUp(bv_, true);
1142 void BufferView::Pimpl::cursorNext(LyXText * text)
1144 if (!text->cursor.row()->next()) {
1145 int y = text->cursor.y() - text->cursor.row()->baseline() +
1146 text->cursor.row()->height();
1147 if (y > int(text->first_y + workarea().workHeight())) {
1148 screen().draw(bv_->text, bv_,
1149 bv_->text->first_y + workarea().workHeight());
1155 int y = text->first_y + workarea().workHeight();
1156 if (text->inset_owner && !text->first_y) {
1157 y -= (bv_->text->cursor.iy()
1158 - bv_->text->first_y
1159 + bv_->theLockingInset()->insetInInsetY());
1162 text->getRowNearY(y);
1164 Row * cursorrow = text->cursor.row();
1165 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1169 if (cursorrow == bv_->text->cursor.row()) {
1170 // we have a row which is higher than the workarea so we leave the
1171 // cursor on the start of the row and move only the draw down as soon
1172 // as we move the cursor or do something while inside the row (it may
1173 // span several workarea-heights) we'll move to the top again, but this
1174 // is better than just jump down and only display part of the row.
1175 new_y = bv_->text->first_y + workarea().workHeight();
1177 if (text->inset_owner) {
1178 new_y = bv_->text->cursor.iy()
1179 + bv_->theLockingInset()->insetInInsetY()
1180 + y - text->cursor.row()->baseline();
1182 new_y = text->cursor.y() - text->cursor.row()->baseline();
1185 screen().draw(bv_->text, bv_, new_y);
1186 if (text->cursor.row()->next()) {
1188 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1189 text->cursor.row()->next()->pos(), false);
1190 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1191 text->cursorDown(bv_, true);
1198 bool BufferView::Pimpl::available() const
1200 if (buffer_ && bv_->text)
1206 void BufferView::Pimpl::beforeChange(LyXText * text)
1209 text->clearSelection();
1213 void BufferView::Pimpl::savePosition(unsigned int i)
1215 if (i >= saved_positions_num)
1217 saved_positions[i] = Position(buffer_->fileName(),
1218 bv_->text->cursor.par()->id(),
1219 bv_->text->cursor.pos());
1222 str << _("Saved bookmark") << ' ' << i;
1223 owner_->message(str.str().c_str());
1228 void BufferView::Pimpl::restorePosition(unsigned int i)
1230 if (i >= saved_positions_num)
1233 string const fname = saved_positions[i].filename;
1235 beforeChange(bv_->text);
1237 if (fname != buffer_->fileName()) {
1238 Buffer * b = bufferlist.exists(fname) ?
1239 bufferlist.getBuffer(fname) :
1240 bufferlist.loadLyXFile(fname); // don't ask, just load it
1241 if (b != 0) buffer(b);
1244 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1248 bv_->text->setCursor(bv_, par,
1249 min(par->size(), saved_positions[i].par_pos));
1251 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1254 str << _("Moved to bookmark") << ' ' << i;
1255 owner_->message(str.str().c_str());
1260 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1262 if (i >= saved_positions_num)
1265 return !saved_positions[i].filename.empty();
1269 void BufferView::Pimpl::switchKeyMap()
1271 if (!lyxrc.rtl_support)
1274 LyXText * text = bv_->getLyXText();
1275 if (text->real_current_font.isRightToLeft()
1276 && !(bv_->theLockingInset()
1277 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1279 if (owner_->getIntl().keymap == Intl::PRIMARY)
1280 owner_->getIntl().KeyMapSec();
1282 if (owner_->getIntl().keymap == Intl::SECONDARY)
1283 owner_->getIntl().KeyMapPrim();
1288 void BufferView::Pimpl::insetUnlock()
1290 if (bv_->theLockingInset()) {
1291 bv_->theLockingInset()->insetUnlock(bv_);
1292 bv_->theLockingInset(0);
1298 void BufferView::Pimpl::showCursor()
1300 if (bv_->theLockingInset())
1301 bv_->theLockingInset()->showInsetCursor(bv_);
1303 screen().showCursor(bv_->text, bv_);
1307 void BufferView::Pimpl::hideCursor()
1309 if (!bv_->theLockingInset())
1310 screen().hideCursor();
1314 void BufferView::Pimpl::toggleSelection(bool b)
1316 if (bv_->theLockingInset())
1317 bv_->theLockingInset()->toggleSelection(bv_, b);
1318 screen().toggleSelection(bv_->text, bv_, b);
1322 void BufferView::Pimpl::toggleToggle()
1324 screen().toggleToggle(bv_->text, bv_);
1328 void BufferView::Pimpl::center()
1330 LyXText * t = bv_->text;
1333 int const half_height = workarea().workHeight() / 2;
1336 if (t->cursor.y() > half_height) {
1337 new_y = t->cursor.y() - half_height;
1340 // FIXME: can we do this w/o calling screen directly ?
1341 // This updates first_y but means the fitCursor() call
1342 // from the update(FITCUR) doesn't realise that we might
1343 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1344 // the scrollbar to be updated as it should, so we have
1345 // to do it manually. Any operation that does a center()
1346 // and also might have moved first_y must make sure to call
1347 // updateScrollbar() currently. Never mind that this is a
1348 // pretty obfuscated way of updating t->first_y
1349 screen().draw(t, bv_, new_y);
1351 update(t, BufferView::SELECT | BufferView::FITCUR);
1355 void BufferView::Pimpl::pasteClipboard(bool asPara)
1360 screen().hideCursor();
1361 beforeChange(bv_->text);
1363 string const clip(workarea().getClipboard());
1369 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1371 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1373 bv_->getLyXText()->clearSelection();
1374 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1378 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1380 workarea().putClipboard(stuff);
1385 * Dispatch functions for actions which can be valid for BufferView->text
1386 * and/or InsetText->text!!!
1391 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1393 LyXText * lt = bv_->getLyXText();
1395 if (selecting || lt->selection.mark()) {
1396 lt->setSelection(bv_);
1400 updateInset(lt->inset_owner, false);
1404 update(lt, BufferView::SELECT|BufferView::FITCUR);
1406 update(lt, BufferView::SELECT);
1408 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1409 bv_->theLockingInset()->hideInsetCursor(bv_);
1410 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1414 if (!lt->selection.set())
1415 workarea().haveSelection(false);
1421 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1423 LyXCursor cursor = bv_->getLyXText()->cursor;
1424 Buffer::inset_iterator it =
1425 find_if(Buffer::inset_iterator(
1426 cursor.par(), cursor.pos()),
1427 buffer_->inset_iterator_end(),
1428 lyx::compare_memfun(&Inset::lyxCode, code));
1429 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1433 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1435 string filename = filen;
1437 if (filename.empty()) {
1438 // Launch a file browser
1439 string initpath = lyxrc.document_path;
1442 string const trypath = owner_->buffer()->filePath();
1443 // If directory is writeable, use this as default.
1444 if (IsDirWriteable(trypath))
1448 FileDialog fileDlg(bv_->owner(),
1449 _("Select LyX document to insert"),
1451 make_pair(string(_("Documents|#o#O")),
1452 string(lyxrc.document_path)),
1453 make_pair(string(_("Examples|#E#e")),
1454 string(AddPath(system_lyxdir, "examples"))));
1456 FileDialog::Result result =
1457 fileDlg.Select(initpath,
1458 _("*.lyx| LyX Documents (*.lyx)"));
1460 if (result.first == FileDialog::Later)
1463 filename = result.second;
1465 // check selected filename
1466 if (filename.empty()) {
1467 owner_->message(_("Canceled."));
1472 // get absolute path of file and add ".lyx" to the filename if
1474 filename = FileSearch(string(), filename, "lyx");
1476 string const disp_fn(MakeDisplayPath(filename));
1479 s1 << _("Inserting document") << ' '
1480 << disp_fn << " ...";
1481 owner_->message(s1.str().c_str());
1482 bool const res = bv_->insertLyXFile(filename);
1485 str << _("Document") << ' ' << disp_fn
1486 << ' ' << _("inserted.");
1487 owner_->message(str.str().c_str());
1490 str << _("Could not insert document") << ' '
1492 owner_->message(str.str().c_str());
1497 bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
1499 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1500 << ev.action <<"] arg[" << ev.argument << "]" << endl;
1502 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1504 switch (ev.action) {
1506 case LFUN_TOC_INSERT:
1508 InsetCommandParams p;
1509 p.setCmdName("tableofcontents");
1510 Inset * inset = new InsetTOC(p);
1511 if (!insertInset(inset, tclass.defaultLayoutName()))
1516 case LFUN_SCROLL_INSET:
1517 // this is not handled here as this function is only active
1518 // if we have a locking_inset and that one is (or contains)
1522 case LFUN_INSET_GRAPHICS:
1524 Inset * new_inset = new InsetGraphics;
1525 if (!insertInset(new_inset)) {
1528 // this is need because you don't use a inset->Edit()
1529 updateInset(new_inset, true);
1530 new_inset->edit(bv_);
1540 case LFUN_PASTESELECTION:
1541 pasteClipboard(ev.argument == "paragraph");
1552 case LFUN_LAYOUT_COPY:
1553 bv_->copyEnvironment();
1556 case LFUN_LAYOUT_PASTE:
1557 bv_->pasteEnvironment();
1561 case LFUN_GOTOERROR:
1562 gotoInset(Inset::ERROR_CODE, false);
1566 gotoInset(Inset::NOTE_CODE, false);
1569 case LFUN_REFERENCE_GOTO:
1571 vector<Inset::Code> tmp;
1572 tmp.push_back(Inset::LABEL_CODE);
1573 tmp.push_back(Inset::REF_CODE);
1574 gotoInset(tmp, true);
1578 case LFUN_HYPHENATION:
1579 specialChar(InsetSpecialChar::HYPHENATION);
1582 case LFUN_LIGATURE_BREAK:
1583 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1587 specialChar(InsetSpecialChar::LDOTS);
1590 case LFUN_END_OF_SENTENCE:
1591 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1594 case LFUN_MENU_SEPARATOR:
1595 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1602 case LFUN_DEPTH_MIN:
1603 changeDepth(bv_, bv_->getLyXText(), -1);
1606 case LFUN_DEPTH_PLUS:
1607 changeDepth(bv_, bv_->getLyXText(), 1);
1611 owner_->getDialogs().setUserFreeFont();
1614 case LFUN_FILE_INSERT:
1615 MenuInsertLyXFile(ev.argument);
1618 case LFUN_FILE_INSERT_ASCII_PARA:
1619 InsertAsciiFile(bv_, ev.argument, true);
1622 case LFUN_FILE_INSERT_ASCII:
1623 InsertAsciiFile(bv_, ev.argument, false);
1628 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1629 << ev.argument << endl;
1631 // This is not the good solution to the empty argument
1632 // problem, but it will hopefully suffice for 1.2.0.
1633 // The correct solution would be to augument the
1634 // function list/array with information about what
1635 // functions needs arguments and their type.
1636 if (ev.argument.empty()) {
1637 owner_->getLyXFunc().setErrorMessage(
1638 _("LyX function 'layout' needs an argument."));
1642 // Derive layout number from given argument (string)
1643 // and current buffer's textclass (number). */
1644 bool hasLayout = tclass.hasLayout(ev.argument);
1645 string layout = ev.argument;
1647 // If the entry is obsolete, use the new one instead.
1649 string const & obs = tclass[layout]->obsoleted_by();
1655 owner_->getLyXFunc().setErrorMessage(
1656 string(N_("Layout ")) + ev.argument +
1661 bool change_layout = (current_layout != layout);
1662 LyXText * lt = bv_->getLyXText();
1663 if (!change_layout && lt->selection.set() &&
1664 lt->selection.start.par() != lt->selection.end.par())
1666 Paragraph * spar = lt->selection.start.par();
1667 Paragraph * epar = lt->selection.end.par()->next();
1668 while(spar != epar) {
1669 if (spar->layout()->name() != current_layout) {
1670 change_layout = true;
1675 if (change_layout) {
1677 current_layout = layout;
1680 | BufferView::FITCUR);
1681 lt->setLayout(bv_, layout);
1682 owner_->setLayout(layout);
1685 | BufferView::FITCUR
1686 | BufferView::CHANGE);
1693 lang(bv_, ev.argument);
1695 owner_->view_state_changed();
1700 owner_->view_state_changed();
1705 owner_->view_state_changed();
1710 owner_->view_state_changed();
1715 owner_->view_state_changed();
1720 owner_->view_state_changed();
1725 owner_->view_state_changed();
1730 owner_->view_state_changed();
1733 case LFUN_UNDERLINE:
1735 owner_->view_state_changed();
1738 case LFUN_FONT_SIZE:
1739 fontSize(bv_, ev.argument);
1740 owner_->view_state_changed();
1743 case LFUN_FONT_STATE:
1744 owner_->getLyXFunc().setMessage(currentState(bv_));
1747 case LFUN_UPCASE_WORD:
1749 LyXText * lt = bv_->getLyXText();
1753 | BufferView::FITCUR);
1754 lt->changeCase(bv_, LyXText::text_uppercase);
1755 if (lt->inset_owner)
1756 updateInset(lt->inset_owner, true);
1759 | BufferView::FITCUR
1760 | BufferView::CHANGE);
1764 case LFUN_LOWCASE_WORD:
1766 LyXText * lt = bv_->getLyXText();
1768 update(lt, BufferView::SELECT|BufferView::FITCUR);
1769 lt->changeCase(bv_, LyXText::text_lowercase);
1770 if (lt->inset_owner)
1771 updateInset(lt->inset_owner, true);
1774 | BufferView::FITCUR
1775 | BufferView::CHANGE);
1779 case LFUN_CAPITALIZE_WORD:
1781 LyXText * lt = bv_->getLyXText();
1783 update(lt, BufferView::SELECT|BufferView::FITCUR);
1784 lt->changeCase(bv_, LyXText::text_capitalization);
1785 if (lt->inset_owner)
1786 updateInset(lt->inset_owner, true);
1789 | BufferView::FITCUR
1790 | BufferView::CHANGE);
1794 case LFUN_TRANSPOSE_CHARS:
1796 LyXText * lt = bv_->getLyXText();
1798 update(lt, BufferView::SELECT|BufferView::FITCUR);
1799 lt->transposeChars(*bv_);
1800 if (lt->inset_owner)
1801 updateInset(lt->inset_owner, true);
1804 | BufferView::FITCUR
1805 | BufferView::CHANGE);
1810 case LFUN_INSERT_LABEL:
1811 MenuInsertLabel(bv_, ev.argument);
1814 case LFUN_REF_INSERT:
1815 if (ev.argument.empty()) {
1816 InsetCommandParams p("ref");
1817 owner_->getDialogs().createRef(p.getAsString());
1819 InsetCommandParams p;
1820 p.setFromString(ev.argument);
1822 InsetRef * inset = new InsetRef(p, *buffer_);
1823 if (!insertInset(inset))
1826 updateInset(inset, true);
1830 case LFUN_BOOKMARK_SAVE:
1831 savePosition(strToUnsignedInt(ev.argument));
1834 case LFUN_BOOKMARK_GOTO:
1835 restorePosition(strToUnsignedInt(ev.argument));
1840 string label = ev.argument;
1841 if (label.empty()) {
1843 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1845 label = inset->getContents();
1850 if (!label.empty()) {
1851 //bv_->savePosition(0);
1852 if (!bv_->gotoLabel(label))
1853 Alert::alert(_("Error"),
1854 _("Couldn't find this label"),
1855 _("in current document."));
1860 // --- Cursor Movements -----------------------------
1863 LyXText * lt = bv_->getLyXText();
1865 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1866 if (!lt->selection.mark())
1868 update(lt, BufferView::SELECT|BufferView::FITCUR);
1870 lt->cursorLeft(bv_, false);
1871 if (lt->cursor.pos() < lt->cursor.par()->size()
1872 && lt->cursor.par()->isInset(lt->cursor.pos())
1873 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1874 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1875 owner_->getLyXFunc().setMessage(tmpinset->editMessage());
1877 tmpinset->edit(bv_, false);
1879 tmpinset->edit(bv_);
1883 lt->cursorRight(bv_, false);
1885 moveCursorUpdate(false);
1886 owner_->view_state_changed();
1892 // This is soooo ugly. Isn`t it possible to make
1893 // it simpler? (Lgb)
1894 LyXText * lt = bv_->getLyXText();
1895 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1896 if (!lt->selection.mark())
1898 update(lt, BufferView::SELECT|BufferView::FITCUR);
1899 LyXCursor const cur = lt->cursor;
1901 lt->cursorLeft(bv_, false);
1902 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1903 lt->cursor.pos() < lt->cursor.par()->size() &&
1904 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1905 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1906 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1907 owner_->getLyXFunc().setMessage(tmpinset->editMessage());
1909 tmpinset->edit(bv_);
1911 tmpinset->edit(bv_, false);
1915 lt->cursorRight(bv_, false);
1918 moveCursorUpdate(false);
1919 owner_->view_state_changed();
1925 LyXText * lt = bv_->getLyXText();
1927 if (!lt->selection.mark())
1929 update(lt, BufferView::UPDATE);
1932 moveCursorUpdate(false);
1933 owner_->view_state_changed();
1939 LyXText * lt = bv_->getLyXText();
1941 if (!lt->selection.mark())
1943 update(lt, BufferView::UPDATE);
1944 lt->cursorDown(bv_);
1946 moveCursorUpdate(false);
1947 owner_->view_state_changed();
1951 case LFUN_UP_PARAGRAPH:
1953 LyXText * lt = bv_->getLyXText();
1955 if (!lt->selection.mark())
1957 update(lt, BufferView::UPDATE);
1958 lt->cursorUpParagraph(bv_);
1960 moveCursorUpdate(false);
1961 owner_->view_state_changed();
1965 case LFUN_DOWN_PARAGRAPH:
1967 LyXText * lt = bv_->getLyXText();
1969 if (!lt->selection.mark())
1971 update(lt, BufferView::UPDATE);
1972 lt->cursorDownParagraph(bv_);
1974 moveCursorUpdate(false);
1975 owner_->view_state_changed();
1981 LyXText * lt = bv_->getLyXText();
1983 if (!lt->selection.mark())
1985 update(lt, BufferView::UPDATE);
1988 moveCursorUpdate(false, false);
1989 owner_->view_state_changed();
1995 LyXText * lt = bv_->getLyXText();
1997 if (!lt->selection.mark())
1999 update(lt, BufferView::UPDATE);
2002 moveCursorUpdate(false, false);
2003 owner_->view_state_changed();
2009 LyXText * lt = bv_->getLyXText();
2011 if (!lt->selection.mark())
2013 update(lt, BufferView::SELECT|BufferView::FITCUR);
2014 lt->cursorHome(bv_);
2016 moveCursorUpdate(false);
2017 owner_->view_state_changed();
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2028 BufferView::SELECT|BufferView::FITCUR);
2031 moveCursorUpdate(false);
2032 owner_->view_state_changed();
2036 case LFUN_SHIFT_TAB:
2039 LyXText * lt = bv_->getLyXText();
2041 if (!lt->selection.mark())
2044 BufferView::SELECT|BufferView::FITCUR);
2047 moveCursorUpdate(false);
2048 owner_->view_state_changed();
2052 case LFUN_WORDRIGHT:
2054 LyXText * lt = bv_->getLyXText();
2056 if (!lt->selection.mark())
2058 update(lt, BufferView::SELECT|BufferView::FITCUR);
2059 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2060 lt->cursorLeftOneWord(bv_);
2062 lt->cursorRightOneWord(bv_);
2064 moveCursorUpdate(false);
2065 owner_->view_state_changed();
2071 LyXText * lt = bv_->getLyXText();
2073 if (!lt->selection.mark())
2075 update(lt, BufferView::SELECT|BufferView::FITCUR);
2076 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2077 lt->cursorRightOneWord(bv_);
2079 lt->cursorLeftOneWord(bv_);
2081 moveCursorUpdate(false);
2082 owner_->view_state_changed();
2086 case LFUN_BEGINNINGBUF:
2088 LyXText * lt = bv_->getLyXText();
2090 if (!lt->selection.mark())
2093 BufferView::SELECT|BufferView::FITCUR);
2096 moveCursorUpdate(false);
2097 owner_->view_state_changed();
2103 LyXText * lt = bv_->getLyXText();
2105 if (!lt->selection.mark())
2108 BufferView::SELECT|BufferView::FITCUR);
2109 lt->cursorBottom(bv_);
2111 moveCursorUpdate(false);
2112 owner_->view_state_changed();
2116 /* cursor selection ---------------------------- */
2119 LyXText * lt = bv_->getLyXText();
2122 BufferView::SELECT|BufferView::FITCUR);
2123 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2124 lt->cursorLeft(bv_);
2126 lt->cursorRight(bv_);
2128 moveCursorUpdate(true);
2129 owner_->view_state_changed();
2135 LyXText * lt = bv_->getLyXText();
2138 BufferView::SELECT|BufferView::FITCUR);
2139 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2140 lt->cursorRight(bv_);
2142 lt->cursorLeft(bv_);
2144 moveCursorUpdate(true);
2145 owner_->view_state_changed();
2151 LyXText * lt = bv_->getLyXText();
2154 BufferView::SELECT|BufferView::FITCUR);
2155 lt->cursorUp(bv_, true);
2157 moveCursorUpdate(true);
2158 owner_->view_state_changed();
2164 LyXText * lt = bv_->getLyXText();
2167 BufferView::SELECT|BufferView::FITCUR);
2168 lt->cursorDown(bv_, true);
2170 moveCursorUpdate(true);
2171 owner_->view_state_changed();
2175 case LFUN_UP_PARAGRAPHSEL:
2177 LyXText * lt = bv_->getLyXText();
2180 BufferView::SELECT|BufferView::FITCUR);
2181 lt->cursorUpParagraph(bv_);
2183 moveCursorUpdate(true);
2184 owner_->view_state_changed();
2188 case LFUN_DOWN_PARAGRAPHSEL:
2190 LyXText * lt = bv_->getLyXText();
2193 BufferView::SELECT|BufferView::FITCUR);
2194 lt->cursorDownParagraph(bv_);
2196 moveCursorUpdate(true);
2197 owner_->view_state_changed();
2203 LyXText * lt = bv_->getLyXText();
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2208 moveCursorUpdate(true);
2209 owner_->view_state_changed();
2215 LyXText * lt = bv_->getLyXText();
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2220 moveCursorUpdate(true);
2221 owner_->view_state_changed();
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2230 lt->cursorHome(bv_);
2232 moveCursorUpdate(true);
2233 owner_->view_state_changed();
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2244 moveCursorUpdate(true);
2245 owner_->view_state_changed();
2249 case LFUN_WORDRIGHTSEL:
2251 LyXText * lt = bv_->getLyXText();
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2254 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2255 lt->cursorLeftOneWord(bv_);
2257 lt->cursorRightOneWord(bv_);
2259 moveCursorUpdate(true);
2260 owner_->view_state_changed();
2264 case LFUN_WORDLEFTSEL:
2266 LyXText * lt = bv_->getLyXText();
2268 update(lt, BufferView::SELECT|BufferView::FITCUR);
2269 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2270 lt->cursorRightOneWord(bv_);
2272 lt->cursorLeftOneWord(bv_);
2274 moveCursorUpdate(true);
2275 owner_->view_state_changed();
2279 case LFUN_BEGINNINGBUFSEL:
2281 LyXText * lt = bv_->getLyXText();
2283 if (lt->inset_owner)
2285 update(lt, BufferView::SELECT|BufferView::FITCUR);
2288 moveCursorUpdate(true);
2289 owner_->view_state_changed();
2293 case LFUN_ENDBUFSEL:
2295 LyXText * lt = bv_->getLyXText();
2297 if (lt->inset_owner)
2300 BufferView::SELECT|BufferView::FITCUR);
2301 lt->cursorBottom(bv_);
2303 moveCursorUpdate(true);
2304 owner_->view_state_changed();
2308 // --- text changing commands ------------------------
2309 case LFUN_BREAKLINE:
2311 LyXText * lt = bv_->getLyXText();
2314 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2317 | BufferView::FITCUR
2318 | BufferView::CHANGE);
2319 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2320 moveCursorUpdate(false);
2324 case LFUN_PROTECTEDSPACE:
2326 LyXText * lt = bv_->getLyXText();
2327 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2329 if (style->free_spacing) {
2330 lt->insertChar(bv_, ' ');
2333 | BufferView::FITCUR
2334 | BufferView::CHANGE);
2336 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2338 moveCursorUpdate(false);
2344 LyXText * lt = bv_->getLyXText();
2346 if (lt->selection.mark()) {
2350 | BufferView::FITCUR);
2351 owner_->getLyXFunc().setMessage(N_("Mark removed"));
2354 lt->selection.mark(true);
2357 | BufferView::FITCUR);
2358 owner_->getLyXFunc().setMessage(N_("Mark set"));
2360 lt->selection.cursor = lt->cursor;
2366 LyXText * lt = bv_->getLyXText();
2368 if (!lt->selection.set()) {
2370 lt->selection.cursor = lt->cursor;
2373 | BufferView::FITCUR
2374 | BufferView::CHANGE);
2375 // It is possible to make it a lot faster still
2376 // just comment out the line below...
2381 moveCursorUpdate(false);
2382 owner_->view_state_changed();
2387 case LFUN_DELETE_SKIP:
2389 LyXText * lt = bv_->getLyXText();
2391 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2393 LyXCursor cursor = lt->cursor;
2395 if (!lt->selection.set()) {
2396 if (cursor.pos() == cursor.par()->size()) {
2397 lt->cursorRight(bv_);
2398 cursor = lt->cursor;
2399 if (cursor.pos() == 0
2400 && !(cursor.par()->params().spaceTop()
2401 == VSpace (VSpace::NONE))) {
2404 cursor.par()->params().lineTop(),
2405 cursor.par()->params().lineBottom(),
2406 cursor.par()->params().pagebreakTop(),
2407 cursor.par()->params().pagebreakBottom(),
2408 VSpace(VSpace::NONE),
2409 cursor.par()->params().spaceBottom(),
2410 cursor.par()->params().spacing(),
2411 cursor.par()->params().align(),
2412 cursor.par()->params().labelWidthString(), 0);
2413 lt->cursorLeft(bv_);
2416 | BufferView::FITCUR
2417 | BufferView::CHANGE);
2419 lt->cursorLeft(bv_);
2421 lt->selection.cursor = lt->cursor;
2424 | BufferView::FITCUR
2425 | BufferView::CHANGE);
2429 lt->selection.cursor = lt->cursor;
2432 | BufferView::FITCUR
2433 | BufferView::CHANGE);
2441 /* -------> Delete word forward. */
2442 case LFUN_DELETE_WORD_FORWARD:
2443 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2444 bv_->getLyXText()->deleteWordForward(bv_);
2445 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2446 moveCursorUpdate(false);
2447 owner_->view_state_changed();
2450 /* -------> Delete word backward. */
2451 case LFUN_DELETE_WORD_BACKWARD:
2453 LyXText * lt = bv_->getLyXText();
2455 update(lt, BufferView::SELECT|BufferView::FITCUR);
2456 lt->deleteWordBackward(bv_);
2459 | BufferView::FITCUR
2460 | BufferView::CHANGE);
2461 moveCursorUpdate(false);
2462 owner_->view_state_changed();
2466 /* -------> Kill to end of line. */
2467 case LFUN_DELETE_LINE_FORWARD:
2469 LyXText * lt = bv_->getLyXText();
2471 update(lt, BufferView::SELECT|BufferView::FITCUR);
2472 lt->deleteLineForward(bv_);
2475 | BufferView::FITCUR
2476 | BufferView::CHANGE);
2477 moveCursorUpdate(false);
2481 /* -------> Set mark off. */
2484 LyXText * lt = bv_->getLyXText();
2487 update(lt, BufferView::SELECT|BufferView::FITCUR);
2488 lt->selection.cursor = lt->cursor;
2489 owner_->getLyXFunc().setMessage(N_("Mark off"));
2493 /* -------> Set mark on. */
2496 LyXText * lt = bv_->getLyXText();
2499 lt->selection.mark(true);
2500 update(lt, BufferView::SELECT|BufferView::FITCUR);
2501 lt->selection.cursor = lt->cursor;
2502 owner_->getLyXFunc().setMessage(N_("Mark on"));
2506 case LFUN_BACKSPACE:
2508 LyXText * lt = bv_->getLyXText();
2510 if (!lt->selection.set()) {
2511 if (owner_->getIntl().getTransManager().backspace()) {
2513 lt->selection.cursor = lt->cursor;
2516 | BufferView::FITCUR
2517 | BufferView::CHANGE);
2518 // It is possible to make it a lot faster still
2519 // just comment out the line below...
2525 owner_->view_state_changed();
2530 case LFUN_BACKSPACE_SKIP:
2532 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2533 LyXText * lt = bv_->getLyXText();
2535 LyXCursor cursor = lt->cursor;
2537 if (!lt->selection.set()) {
2538 if (cursor.pos() == 0
2539 && !(cursor.par()->params().spaceTop()
2540 == VSpace (VSpace::NONE))) {
2543 cursor.par()->params().lineTop(),
2544 cursor.par()->params().lineBottom(),
2545 cursor.par()->params().pagebreakTop(),
2546 cursor.par()->params().pagebreakBottom(),
2547 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2548 cursor.par()->params().spacing(),
2549 cursor.par()->params().align(),
2550 cursor.par()->params().labelWidthString(), 0);
2553 | BufferView::FITCUR
2554 | BufferView::CHANGE);
2557 lt->selection.cursor = cursor;
2560 | BufferView::FITCUR
2561 | BufferView::CHANGE);
2568 case LFUN_BREAKPARAGRAPH:
2570 LyXText * lt = bv_->getLyXText();
2573 lt->breakParagraph(bv_, 0);
2576 | BufferView::FITCUR
2577 | BufferView::CHANGE);
2578 lt->selection.cursor = lt->cursor;
2580 owner_->view_state_changed();
2584 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2586 LyXText * lt = bv_->getLyXText();
2589 lt->breakParagraph(bv_, 1);
2592 | BufferView::FITCUR
2593 | BufferView::CHANGE);
2594 lt->selection.cursor = lt->cursor;
2596 owner_->view_state_changed();
2600 case LFUN_BREAKPARAGRAPH_SKIP:
2602 // When at the beginning of a paragraph, remove
2603 // indentation and add a "defskip" at the top.
2604 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2605 LyXText * lt = bv_->getLyXText();
2607 LyXCursor cursor = lt->cursor;
2610 if (cursor.pos() == 0) {
2611 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2614 cursor.par()->params().lineTop(),
2615 cursor.par()->params().lineBottom(),
2616 cursor.par()->params().pagebreakTop(),
2617 cursor.par()->params().pagebreakBottom(),
2618 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2619 cursor.par()->params().spacing(),
2620 cursor.par()->params().align(),
2621 cursor.par()->params().labelWidthString(), 1);
2622 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2626 lt->breakParagraph(bv_, 0);
2627 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2632 | BufferView::FITCUR
2633 | BufferView::CHANGE);
2634 lt->selection.cursor = cursor;
2636 owner_->view_state_changed();
2640 case LFUN_PARAGRAPH_SPACING:
2642 LyXText * lt = bv_->getLyXText();
2644 Paragraph * par = lt->cursor.par();
2645 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2646 float cur_value = 1.0;
2647 if (cur_spacing == Spacing::Other) {
2648 cur_value = par->params().spacing().getValue();
2651 istringstream istr(ev.argument.c_str());
2655 Spacing::Space new_spacing = cur_spacing;
2656 float new_value = cur_value;
2658 lyxerr << "Missing argument to `paragraph-spacing'"
2660 } else if (tmp == "single") {
2661 new_spacing = Spacing::Single;
2662 } else if (tmp == "onehalf") {
2663 new_spacing = Spacing::Onehalf;
2664 } else if (tmp == "double") {
2665 new_spacing = Spacing::Double;
2666 } else if (tmp == "other") {
2667 new_spacing = Spacing::Other;
2670 lyxerr << "new_value = " << tmpval << endl;
2673 } else if (tmp == "default") {
2674 new_spacing = Spacing::Default;
2676 lyxerr << _("Unknown spacing argument: ")
2677 << ev.argument << endl;
2679 if (cur_spacing != new_spacing || cur_value != new_value) {
2680 par->params().spacing(Spacing(new_spacing, new_value));
2681 lt->redoParagraph(bv_);
2684 | BufferView::FITCUR
2685 | BufferView::CHANGE);
2690 case LFUN_INSET_TOGGLE:
2692 LyXText * lt = bv_->getLyXText();
2695 update(lt, BufferView::SELECT|BufferView::FITCUR);
2696 lt->toggleInset(bv_);
2697 update(lt, BufferView::SELECT|BufferView::FITCUR);
2709 InsetCommandParams p;
2710 if (ev.action == LFUN_HTMLURL)
2711 p.setCmdName("htmlurl");
2713 p.setCmdName("url");
2714 owner_->getDialogs().createUrl(p.getAsString());
2718 case LFUN_INSERT_URL:
2720 InsetCommandParams p;
2721 p.setFromString(ev.argument);
2723 InsetUrl * inset = new InsetUrl(p);
2724 if (!insertInset(inset))
2727 updateInset(inset, true);
2731 case LFUN_INSET_ERT:
2732 insertAndEditInset(new InsetERT(buffer_->params));
2735 case LFUN_INSET_EXTERNAL:
2736 insertAndEditInset(new InsetExternal);
2739 case LFUN_INSET_FOOTNOTE:
2740 insertAndEditInset(new InsetFoot(buffer_->params));
2743 case LFUN_INSET_MARGINAL:
2744 insertAndEditInset(new InsetMarginal(buffer_->params));
2747 case LFUN_INSET_MINIPAGE:
2748 insertAndEditInset(new InsetMinipage(buffer_->params));
2751 case LFUN_INSERT_NOTE:
2752 insertAndEditInset(new InsetNote(buffer_->params));
2755 case LFUN_INSET_FLOAT:
2756 // check if the float type exist
2757 if (floatList.typeExist(ev.argument)) {
2758 insertAndEditInset(new InsetFloat(buffer_->params,
2761 lyxerr << "Non-existent float type: "
2762 << ev.argument << endl;
2766 case LFUN_INSET_WIDE_FLOAT:
2767 // check if the float type exist
2768 if (floatList.typeExist(ev.argument)) {
2769 InsetFloat * new_inset =
2770 new InsetFloat(buffer_->params, ev.argument);
2771 new_inset->wide(true);
2772 insertAndEditInset(new_inset);
2774 lyxerr << "Non-existent float type: "
2775 << ev.argument << endl;
2780 case LFUN_INSET_LIST:
2781 insertAndEditInset(new InsetList);
2784 case LFUN_INSET_THEOREM:
2785 insertAndEditInset(new InsetTheorem);
2789 case LFUN_INSET_CAPTION:
2791 // Do we have a locking inset...
2792 if (bv_->theLockingInset()) {
2793 lyxerr << "Locking inset code: "
2794 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2795 InsetCaption * new_inset =
2796 new InsetCaption(buffer_->params);
2797 new_inset->setOwner(bv_->theLockingInset());
2798 new_inset->setAutoBreakRows(true);
2799 new_inset->setDrawFrame(0, InsetText::LOCKED);
2800 new_inset->setFrameColor(0, LColor::captionframe);
2801 if (insertInset(new_inset))
2802 new_inset->edit(bv_);
2809 case LFUN_TABULAR_INSERT:
2811 if (ev.argument.empty()) {
2812 owner_->getDialogs().showTabularCreate();
2818 ::sscanf(ev.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(ev.argument.c_str(), " %d %d", &x, &y) != 2) {
2852 lyxerr << "SETXY: Could not parse coordinates in '"
2853 << ev.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 (ev.argument.empty()) {
2897 owner_->getLyXFunc().handleKeyFunc(ev.action);
2899 owner_->getLyXFunc().handleKeyFunc(ev.action);
2900 owner_->getIntl().getTransManager()
2901 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
2902 update(bv_->getLyXText(),
2904 | BufferView::FITCUR
2905 | BufferView::CHANGE);
2909 case LFUN_MATH_MACRO:
2910 case LFUN_MATH_DELIM:
2911 case LFUN_INSERT_MATRIX:
2912 case LFUN_INSERT_MATH:
2913 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2914 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2915 case LFUN_MATH_MODE: // Open or create an inlined math inset
2916 case LFUN_GREEK: // Insert a single greek letter
2917 mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
2920 case LFUN_CITATION_INSERT:
2922 InsetCommandParams p;
2923 p.setFromString(ev.argument);
2925 InsetCitation * inset = new InsetCitation(p);
2926 if (!insertInset(inset))
2929 updateInset(inset, true);
2933 case LFUN_INSERT_BIBTEX:
2935 // ale970405+lasgoutt970425
2936 // The argument can be up to two tokens separated
2937 // by a space. The first one is the bibstyle.
2938 string const db = token(ev.argument, ' ', 0);
2939 string const bibstyle = token(ev.argument, ' ', 1);
2941 InsetCommandParams p("BibTeX", db, bibstyle);
2942 InsetBibtex * inset = new InsetBibtex(p);
2944 if (insertInset(inset)) {
2945 if (ev.argument.empty())
2952 // BibTeX data bases
2953 case LFUN_BIBDB_ADD:
2955 InsetBibtex * inset =
2956 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2958 inset->addDatabase(ev.argument);
2963 case LFUN_BIBDB_DEL:
2965 InsetBibtex * inset =
2966 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2968 inset->delDatabase(ev.argument);
2973 case LFUN_BIBTEX_STYLE:
2975 InsetBibtex * inset =
2976 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2978 inset->setOptions(ev.argument);
2983 case LFUN_INDEX_INSERT:
2985 string entry = ev.argument;
2986 if (entry.empty()) {
2987 entry = bv_->getLyXText()->getStringToIndex(bv_);
2990 if (entry.empty()) {
2991 owner_->getDialogs().createIndex();
2995 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
2997 if (!insertInset(inset)) {
3000 updateInset(inset, true);
3005 case LFUN_INDEX_PRINT:
3007 InsetCommandParams p("printindex");
3008 Inset * inset = new InsetPrintIndex(p);
3009 if (!insertInset(inset, tclass.defaultLayoutName()))
3014 case LFUN_PARENTINSERT:
3016 InsetCommandParams p("lyxparent", ev.argument);
3017 Inset * inset = new InsetParent(p, *buffer_);
3018 if (!insertInset(inset, tclass.defaultLayoutName()))
3024 case LFUN_CHILD_INSERT:
3026 InsetInclude::Params p;
3027 p.cparams.setFromString(ev.argument);
3028 p.masterFilename_ = buffer_->fileName();
3030 InsetInclude * inset = new InsetInclude(p);
3031 if (!insertInset(inset))
3034 updateInset(inset, true);
3035 bv_->owner()->getDialogs().showInclude(inset);
3040 case LFUN_FLOAT_LIST:
3041 if (floatList.typeExist(ev.argument)) {
3042 Inset * inset = new InsetFloatList(ev.argument);
3043 if (!insertInset(inset, tclass.defaultLayoutName()))
3046 lyxerr << "Non-existent float type: "
3047 << ev.argument << endl;
3051 case LFUN_THESAURUS_ENTRY:
3053 string arg = ev.argument;
3056 arg = bv_->getLyXText()->selectionAsString(buffer_,
3060 if (arg.size() > 100 || arg.empty()) {
3061 // Get word or selection
3062 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3063 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3064 // FIXME: where is getLyXText()->unselect(bv_) ?
3068 bv_->owner()->getDialogs().showThesaurus(arg);
3072 case LFUN_SELFINSERT:
3074 if (ev.argument.empty()) break;
3076 /* Automatically delete the currently selected
3077 * text and replace it with what is being
3078 * typed in now. Depends on lyxrc settings
3079 * "auto_region_delete", which defaults to
3082 LyXText * lt = bv_->getLyXText();
3084 if (lyxrc.auto_region_delete) {
3085 if (lt->selection.set()) {
3086 lt->cutSelection(bv_, false, false);
3089 | BufferView::FITCUR
3090 | BufferView::CHANGE);
3092 workarea().haveSelection(false);
3096 LyXFont const old_font(lt->real_current_font);
3098 string::const_iterator cit = ev.argument.begin();
3099 string::const_iterator end = ev.argument.end();
3100 for (; cit != end; ++cit) {
3101 owner_->getIntl().getTransManager().
3102 TranslateAndInsert(*cit, lt);
3107 | BufferView::FITCUR
3108 | BufferView::CHANGE);
3110 lt->selection.cursor = lt->cursor;
3111 moveCursorUpdate(false);
3113 // real_current_font.number can change so we need to
3114 // update the minibuffer
3115 if (old_font != lt->real_current_font)
3116 owner_->view_state_changed();
3121 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3123 time_t now_time_t = time(NULL);
3124 struct tm * now_tm = localtime(&now_time_t);
3125 setlocale(LC_TIME, "");
3127 if (!ev.argument.empty())
3130 arg = lyxrc.date_insert_format;
3132 int const datetmp_len =
3133 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3135 LyXText * lt = bv_->getLyXText();
3137 for (int i = 0; i < datetmp_len; i++) {
3138 lt->insertChar(bv_, datetmp[i]);
3141 | BufferView::FITCUR
3142 | BufferView::CHANGE);
3145 lt->selection.cursor = lt->cursor;
3146 moveCursorUpdate(false);
3150 case LFUN_UNKNOWN_ACTION:
3151 owner_->getLyXFunc().setErrorMessage(N_("Unknown function!"));
3155 FuncRequest cmd = ev;
3157 return bv_->getLyXText()->dispatch(cmd);
3164 void BufferView::Pimpl::newline()
3167 LyXText * lt = bv_->getLyXText();
3171 | BufferView::FITCUR);
3172 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3175 | BufferView::FITCUR
3176 | BufferView::CHANGE);
3181 void BufferView::Pimpl::hfill()
3184 LyXText * lt = bv_->getLyXText();
3188 | BufferView::FITCUR);
3189 lt->insertChar(bv_, Paragraph::META_HFILL);
3192 | BufferView::FITCUR
3193 | BufferView::CHANGE);
3198 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3201 LyXText * lt = bv_->getLyXText();
3204 update(lt, BufferView::SELECT|BufferView::FITCUR);
3205 InsetSpecialChar * new_inset =
3206 new InsetSpecialChar(kind);
3207 if (!insertInset(new_inset))
3210 updateInset(new_inset, true);
3215 void BufferView::Pimpl::smartQuote()
3217 LyXText const * lt = bv_->getLyXText();
3218 Paragraph const * par = lt->cursor.par();
3219 pos_type pos = lt->cursor.pos();
3223 || (par->isInset(pos - 1)
3224 && par->getInset(pos - 1)->isSpace()))
3227 c = par->getChar(pos - 1);
3232 LyXLayout_ptr const & style = par->layout();
3234 if (style->pass_thru ||
3235 par->getFontSettings(buffer_->params,
3236 pos).language()->lang() == "hebrew" ||
3237 (!insertInset(new InsetQuotes(c, buffer_->params))))
3238 bv_->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
3242 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3245 if (insertInset(inset))
3250 bool gotsel = false;
3252 if (bv_->getLyXText()->selection.set()) {
3253 bv_->getLyXText()->cutSelection(bv_, true, false);
3257 if (insertInset(inset)) {
3260 owner_->dispatch(FuncRequest(LFUN_PASTESELECTION));
3268 // Open and lock an updatable inset
3269 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3271 LyXText * lt = bv_->getLyXText();
3275 if (!insertInset(new_inset)) {
3279 new_inset->edit(bv_, !behind);
3284 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3286 // if we are in a locking inset we should try to insert the
3287 // inset there otherwise this is a illegal function now
3288 if (bv_->theLockingInset()) {
3289 if (bv_->theLockingInset()->insetAllowed(inset))
3290 return bv_->theLockingInset()->insertInset(bv_, inset);
3294 // not quite sure if we want this...
3295 setCursorParUndo(bv_);
3298 beforeChange(bv_->text);
3299 if (!lout.empty()) {
3300 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3301 bv_->text->breakParagraph(bv_);
3302 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3304 if (!bv_->text->cursor.par()->empty()) {
3305 bv_->text->cursorLeft(bv_);
3307 bv_->text->breakParagraph(bv_);
3308 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3312 LyXTextClass const & tclass =
3313 buffer_->params.getLyXTextClass();
3314 bool hasLayout = tclass.hasLayout(lres);
3315 string lay = tclass.defaultLayoutName();
3317 if (hasLayout != false) {
3321 // layout not fount using default
3322 lay = tclass.defaultLayoutName();
3325 bv_->text->setLayout(bv_, lay);
3327 bv_->text->setParagraph(bv_, 0, 0,
3329 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3334 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3337 bv_->text->insertInset(bv_, inset);
3338 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3347 if (!inset || !available())
3350 // first check for locking insets
3351 if (bv_->theLockingInset()) {
3352 if (bv_->theLockingInset() == inset) {
3353 if (bv_->text->updateInset(bv_, inset)) {
3356 buffer_->markDirty();
3361 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3362 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3365 buffer_->markDirty();
3373 // then check if the inset is a top_level inset (has no owner)
3374 // if yes do the update as always otherwise we have to update the
3375 // toplevel inset where this inset is inside
3376 Inset * tl_inset = inset;
3377 while(tl_inset->owner())
3378 tl_inset = tl_inset->owner();
3380 if (tl_inset == inset) {
3381 update(bv_->text, BufferView::UPDATE);
3382 if (bv_->text->updateInset(bv_, inset)) {
3386 | BufferView::FITCUR
3387 | BufferView::CHANGE);
3389 update(bv_->text, SELECT);
3393 } else if (static_cast<UpdatableInset *>(tl_inset)
3394 ->updateInsetInInset(bv_, inset))
3396 if (bv_->text->updateInset(bv_, tl_inset)) {
3404 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3407 if (!available()) return;
3410 beforeChange(bv_->text);
3411 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3413 LyXCursor const & cursor = bv_->text->cursor;
3417 cursor.par()->isInset(cursor.pos())) {
3418 Inset const * inset = cursor.par()->getInset(cursor.pos());
3419 if (find(codes.begin(), codes.end(), inset->lyxCode())
3422 static_cast<InsetCommand const *>(inset)->getContents();
3426 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3427 if (bv_->text->cursor.pos()
3428 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3429 LyXCursor tmp = bv_->text->cursor;
3430 bv_->text->cursor.par(bv_->text->ownerParagraph());
3431 bv_->text->cursor.pos(0);
3432 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3433 bv_->text->cursor = tmp;
3434 bv_->owner()->message(_("No more insets"));
3437 bv_->owner()->message(_("No more insets"));
3440 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3441 bv_->text->selection.cursor = bv_->text->cursor;
3445 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3447 gotoInset(vector<Inset::Code>(1, code), same_content);