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 * b, LyXView * o,
147 int xpos, int ypos, int width, int height)
148 : bv_(b), owner_(o), 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.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
156 resizecon = workarea().workAreaResize
157 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
158 bpresscon = workarea().workAreaButtonPress
159 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
160 breleasecon = workarea().workAreaButtonRelease
161 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
162 motioncon = workarea().workAreaMotionNotify
163 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
164 doublecon = workarea().workAreaDoubleClick
165 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
166 triplecon = workarea().workAreaTripleClick
167 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
168 kpresscon = workarea().workAreaKeyPress
169 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
170 selectioncon = workarea().selectionRequested
171 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
172 lostcon = workarea().selectionLost
173 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
175 timecon = cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
176 cursor_timeout.start();
177 saved_positions.resize(saved_positions_num);
181 WorkArea & BufferView::Pimpl::workarea() const
183 return *workarea_.get();
187 LyXScreen & BufferView::Pimpl::screen() const
189 return *screen_.get();
193 Painter & BufferView::Pimpl::painter() const
195 return workarea().getPainter();
199 void BufferView::Pimpl::buffer(Buffer * b)
201 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
204 buffer_->delUser(bv_);
206 // Put the old text into the TextCache, but
207 // only if the buffer is still loaded.
208 // Also set the owner of the test to 0
209 // bv_->text->owner(0);
210 textcache.add(buffer_, workarea().workWidth(), bv_->text);
211 if (lyxerr.debugging())
212 textcache.show(lyxerr, "BufferView::buffer");
217 // Set current buffer
220 if (bufferlist.getState() == BufferList::CLOSING) return;
222 // If we are closing the buffer, use the first buffer as current
224 buffer_ = bufferlist.first();
228 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
229 buffer_->addUser(bv_);
231 // If we don't have a text object for this, we make one
232 if (bv_->text == 0) {
233 resizeCurrentBuffer();
236 // FIXME: needed when ?
237 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
239 // Similarly, buffer-dependent dialogs should be updated or
240 // hidden. This should go here because some dialogs (eg ToC)
241 // require bv_->text.
242 owner_->getDialogs().updateBufferDependent(true);
244 lyxerr[Debug::INFO] << " No Buffer!" << endl;
245 owner_->getDialogs().hideBufferDependent();
247 // Also remove all remaining text's from the testcache.
248 // (there should not be any!) (if there is any it is a
250 if (lyxerr.debugging())
251 textcache.show(lyxerr, "buffer delete all");
257 owner_->updateMenubar();
258 owner_->updateToolbar();
259 owner_->updateLayoutChoice();
260 owner_->updateWindowTitle();
262 if (grfx::Previews::activated() && buffer_)
263 grfx::Previews::get().generateBufferPreviews(*buffer_);
267 bool BufferView::Pimpl::fitCursor()
271 if (bv_->theLockingInset()) {
272 bv_->theLockingInset()->fitInsetCursor(bv_);
275 ret = screen().fitCursor(bv_->text, bv_);
278 bv_->owner()->getDialogs().updateParagraph();
285 void BufferView::Pimpl::redoCurrentBuffer()
287 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
288 if (buffer_ && bv_->text) {
289 resizeCurrentBuffer();
291 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_);
353 bv_->text->selection.set(true);
354 // At this point just to avoid the Delete-Empty-Paragraph-
355 // Mechanism when setting the cursor.
356 bv_->text->selection.mark(mark_set);
358 bv_->text->setCursor(bv_, selstartpar, selstartpos);
359 bv_->text->selection.cursor = bv_->text->cursor;
360 bv_->text->setCursor(bv_, selendpar, selendpos);
361 bv_->text->setSelection(bv_);
362 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->setCursor(bv_, par, pos);
365 bv_->text->selection.cursor = bv_->text->cursor;
366 bv_->text->selection.set(false);
368 // remake the inset locking
369 bv_->theLockingInset(the_locking_inset);
372 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
375 owner_->allowInput();
383 void BufferView::Pimpl::repaint()
385 // Regenerate the screen.
386 screen().redraw(bv_->text, bv_);
390 void BufferView::Pimpl::updateScrollbar()
393 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
394 workarea().setScrollbarParams(0, 0, 0);
398 LyXText const & t = *bv_->text;
400 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
401 << t.first_y << ", default height " << t.defaultHeight() << endl;
403 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
407 void BufferView::Pimpl::scrollDocView(int value)
409 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
411 if (!buffer_) return;
413 screen().draw(bv_->text, bv_, value);
415 if (!lyxrc.cursor_follows_scrollbar) {
419 LyXText * vbt = bv_->text;
421 int const height = vbt->defaultHeight();
422 int const first = static_cast<int>((bv_->text->first_y + height));
423 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
425 if (vbt->cursor.y() < first)
426 vbt->setCursorFromCoordinates(bv_, 0, first);
427 else if (vbt->cursor.y() > last)
428 vbt->setCursorFromCoordinates(bv_, 0, last);
432 int BufferView::Pimpl::scroll(long time)
437 LyXText const * t = bv_->text;
439 double const diff = t->defaultHeight()
440 + double(time) * double(time) * 0.125;
442 scrollDocView(int(diff));
443 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
448 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
449 key_modifier::state state)
451 bv_->owner()->getLyXFunc().processKeySym(key, state);
455 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
457 // Only use motion with button 1
458 if (!(state & mouse_button::button1))
464 // Check for inset locking
465 if (bv_->theLockingInset()) {
466 LyXCursor cursor = bv_->text->cursor;
467 LyXFont font = bv_->text->getFont(buffer_,
468 cursor.par(), cursor.pos());
469 int width = bv_->theLockingInset()->width(bv_, font);
470 int inset_x = font.isVisibleRightToLeft()
471 ? cursor.ix() - width : cursor.ix();
472 int start_x = inset_x + bv_->theLockingInset()->scroll();
474 bv_->theLockingInset()->
475 insetMotionNotify(bv_,
477 y - cursor.iy() + bv_->text->first_y,
482 /* The test for not selection possible is needed, that only motion
483 events are used, where the bottom press event was on
484 the drawing area too */
485 if (!selection_possible)
488 screen().hideCursor();
490 Row * cursorrow = bv_->text->cursor.row();
491 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
493 // sorry for this but I have a strange error that the y value jumps at
494 // a certain point. This seems like an error in my xforms library or
495 // in some other local environment, but I would like to leave this here
496 // for the moment until I can remove this (Jug 20020418)
497 if (y_before < bv_->text->cursor.y())
498 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
500 // This is to allow jumping over large insets
501 if (cursorrow == bv_->text->cursor.row()) {
502 if (y >= int(workarea().workHeight())) {
503 bv_->text->cursorDown(bv_, false);
505 bv_->text->cursorUp(bv_, false);
509 if (!bv_->text->selection.set())
510 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
512 bv_->text->setSelection(bv_);
513 screen().toggleToggle(bv_->text, bv_);
519 // Single-click on work area
520 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
521 mouse_button::state button)
526 // ok ok, this is a hack (for xforms)
527 if (button == mouse_button::button4) {
528 scroll(-lyxrc.wheel_jump);
529 // We shouldn't go further down as we really should only do the
530 // scrolling and be done with this. Otherwise we may open some
531 // dialogs (Jug 20020424).
533 } else if (button == mouse_button::button5) {
534 scroll(lyxrc.wheel_jump);
535 // We shouldn't go further down as we really should only do the
536 // scrolling and be done with this. Otherwise we may open some
537 // dialogs (Jug 20020424).
541 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
543 // Middle button press pastes if we have a selection
544 // We do this here as if the selection was inside an inset
545 // it could get cleared on the unlocking of the inset so
546 // we have to check this first
547 bool paste_internally = false;
548 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
549 owner_->dispatch(FuncRequest(LFUN_COPY));
550 paste_internally = true;
553 int const screen_first = bv_->text->first_y;
555 if (bv_->theLockingInset()) {
556 // We are in inset locking mode
558 /* Check whether the inset was hit. If not reset mode,
559 otherwise give the event to the inset */
560 if (inset_hit == bv_->theLockingInset()) {
561 bv_->theLockingInset()->
562 insetButtonPress(bv_, xpos, ypos, button);
565 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 inset->insetButtonPress(bv_, xpos, ypos, button);
596 // I'm not sure we should continue here if we hit an inset (Jug20020403)
598 // Right click on a footnote flag opens float menu
599 if (button == mouse_button::button3) {
600 selection_possible = false;
604 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
605 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
607 bv_->text->selection.cursor = bv_->text->cursor;
608 bv_->text->cursor.x_fix(bv_->text->cursor.x());
610 owner_->updateLayoutChoice();
612 selection_possible = false;
615 // Insert primary selection with middle mouse
616 // if there is a local selection in the current buffer,
618 if (button == mouse_button::button2) {
619 if (paste_internally)
620 owner_->dispatch(FuncRequest(LFUN_PASTE));
622 owner_->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
623 selection_possible = false;
629 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
634 LyXText * text = bv_->getLyXText();
636 if (text->bv_owner && bv_->theLockingInset())
639 if (button == mouse_button::button1) {
640 if (text->bv_owner) {
641 screen().hideCursor();
642 screen().toggleSelection(text, bv_);
643 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
644 screen().toggleSelection(text, bv_, false);
646 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
648 /* This will fit the cursor on the screen
650 update(text, BufferView::SELECT|BufferView::FITCUR);
651 workarea().haveSelection(bv_->getLyXText()->selection.set());
656 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
661 LyXText * text = bv_->getLyXText();
663 if (text->bv_owner && bv_->theLockingInset())
666 if (button == mouse_button::button1) {
667 if (text->bv_owner) {
668 screen().hideCursor();
669 screen().toggleSelection(text, bv_);
671 text->cursorHome(bv_);
672 text->selection.cursor = text->cursor;
673 text->cursorEnd(bv_);
674 text->setSelection(bv_);
675 if (text->bv_owner) {
676 screen().toggleSelection(text, bv_, false);
678 /* This will fit the cursor on the screen
680 update(text, BufferView::SELECT|BufferView::FITCUR);
681 workarea().haveSelection(bv_->getLyXText()->selection.set());
686 void BufferView::Pimpl::selectionRequested()
693 LyXText * text = bv_->getLyXText();
695 if (text->selection.set() &&
696 (!bv_->text->xsel_cache.set() ||
697 text->selection.start != bv_->text->xsel_cache.start ||
698 text->selection.end != bv_->text->xsel_cache.end))
700 bv_->text->xsel_cache = text->selection;
701 sel = text->selectionAsString(bv_->buffer(), false);
702 } else if (!text->selection.set()) {
704 bv_->text->xsel_cache.set(false);
707 workarea().putClipboard(sel);
712 void BufferView::Pimpl::selectionLost()
717 bv_->getLyXText()->clearSelection();
719 bv_->text->xsel_cache.set(false);
724 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
725 mouse_button::state button)
727 // do nothing if we used the mouse wheel
728 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
731 // If we hit an inset, we have the inset coordinates in these
732 // and inset_hit points to the inset. If we do not hit an
733 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
734 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
736 if (bv_->theLockingInset()) {
737 // We are in inset locking mode.
739 /* LyX does a kind of work-area grabbing for insets.
740 Only a ButtonPress FuncRequest outside the inset will
741 force a insetUnlock. */
742 bv_->theLockingInset()->
743 insetButtonRelease(bv_, x, y, button);
747 selection_possible = false;
749 if (button == mouse_button::button2)
753 if (button == mouse_button::button1) {
754 workarea().haveSelection(bv_->getLyXText()->selection.set());
758 owner_->view_state_changed();
759 owner_->updateMenubar();
760 owner_->updateToolbar();
762 // Did we hit an editable inset?
764 selection_possible = false;
766 // if we reach this point with a selection, it
767 // must mean we are currently selecting.
768 // But we don't want to open the inset
769 // because that is annoying for the user.
770 // So just pretend we didn't hit it.
771 // this is OK because a "kosher" ButtonRelease
772 // will follow a ButtonPress that clears
774 // Note this also fixes selection drawing
775 // problems if we end up opening an inset
776 if (bv_->getLyXText()->selection.set())
779 // CHECK fix this proper in 0.13
780 // well, maybe 13.0 !!!!!!!!!
782 // Following a ref shouldn't issue
783 // a push on the undo-stack
784 // anylonger, now that we have
785 // keybindings for following
786 // references and returning from
787 // references. IMHO though, it
788 // should be the inset's own business
789 // to push or not push on the undo
790 // stack. They don't *have* to
791 // alter the document...
793 // ...or maybe the SetCursorParUndo()
794 // below isn't necessary at all anylonger?
795 if (inset_hit->lyxCode() == Inset::REF_CODE) {
796 setCursorParUndo(bv_);
799 owner_->message(inset_hit->editMessage());
801 if (isHighlyEditableInset(inset_hit)) {
802 // Highly editable inset, like math
803 UpdatableInset *inset = (UpdatableInset *)inset_hit;
804 inset->insetButtonRelease(bv_, x, y, button);
806 inset_hit->insetButtonRelease(bv_, x, y, button);
807 // IMO this is a grosshack! Inset's should be changed so that
808 // they call the actions they have to do with the insetButtonRel.
809 // function and not in the edit(). This should be changed
812 #warning Please remove donot call inset->edit() here (Jug 20020812)
814 inset_hit->edit(bv_, x, y, button);
819 // Maybe we want to edit a bibitem ale970302
820 if (bv_->text->cursor.par()->bibkey) {
821 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
822 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
823 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
824 (!is_rtl && x < 20+width)) {
825 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
833 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
834 LyXCursor const & cursor) const
836 Paragraph /*const*/ & par = *cursor.par();
837 pos_type const pos = cursor.pos();
839 lyx::Assert(par.getInset(pos));
841 Inset const & inset(*par.getInset(pos));
843 LyXFont const & font = text.getFont(buffer_, &par, pos);
845 int const width = inset.width(bv_, font);
846 int const inset_x = font.isVisibleRightToLeft()
847 ? (cursor.ix() - width) : cursor.ix();
850 inset_x + inset.scroll(),
852 cursor.iy() - inset.ascent(bv_, font),
853 cursor.iy() + inset.descent(bv_, font));
857 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
858 LyXCursor const & cursor,
859 int & x, int & y) const
861 pos_type const pos(cursor.pos());
862 Paragraph /*const*/ & par(*cursor.par());
864 if (pos >= par.size() || !par.isInset(pos)) {
868 Inset /*const*/ * inset = par.getInset(pos);
870 if (!isEditableInset(inset)) {
874 Box b(insetDimensions(text, cursor));
876 if (!b.contained(x, y)) {
877 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
878 << " box " << b << endl;
882 text.setCursor(bv_, &par, pos, true);
885 // The origin of an inset is on the baseline
886 y -= text.cursor.iy();
892 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
894 int y_tmp = y + text->first_y;
897 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
899 Inset * inset(checkInset(*text, cursor, x, y_tmp));
906 // look at previous position
908 if (cursor.pos() == 0) {
913 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
915 inset = checkInset(*text, cursor, x, y_tmp);
923 void BufferView::Pimpl::workAreaResize()
925 static int work_area_width;
926 static int work_area_height;
928 bool const widthChange = workarea().workWidth() != work_area_width;
929 bool const heightChange = workarea().workHeight() != work_area_height;
931 // update from work area
932 work_area_width = workarea().workWidth();
933 work_area_height = workarea().workHeight();
937 // The visible LyXView need a resize
938 resizeCurrentBuffer();
940 // Remove all texts from the textcache
941 // This is not _really_ what we want to do. What
942 // we really want to do is to delete in textcache
943 // that does not have a BufferView with matching
944 // width, but as long as we have only one BufferView
945 // deleting all gives the same result.
946 if (lyxerr.debugging())
947 textcache.show(lyxerr, "Expose delete all");
949 // FIXME: this is aalready done in resizeCurrentBuffer() ??
950 buffer_->resizeInsets(bv_);
951 } else if (heightChange) {
952 // fitCursor() ensures we don't jump back
953 // to the start of the document on vertical
959 if (widthChange || heightChange) {
963 // always make sure that the scrollbar is sane.
965 owner_->updateLayoutChoice();
970 void BufferView::Pimpl::update()
972 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
973 LyXText::text_status st = bv_->text->status();
974 screen().update(bv_->text, bv_);
976 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
977 bv_->text->fullRebreak(bv_);
978 st = LyXText::NEED_MORE_REFRESH;
979 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
980 bv_->text->cursor.pos());
981 if (bv_->text->selection.set()) {
982 bv_->text->setCursor(bv_, bv_->text->selection.start,
983 bv_->text->selection.start.par(),
984 bv_->text->selection.start.pos());
985 bv_->text->setCursor(bv_, bv_->text->selection.end,
986 bv_->text->selection.end.par(),
987 bv_->text->selection.end.pos());
990 bv_->text->status(bv_, st);
991 screen().update(bv_->text, bv_);
993 // do this here instead of in the screen::update because of
995 bv_->text->status(bv_, LyXText::UNCHANGED);
1001 // Values used when calling update:
1003 // -2 - update, move sel_cursor if selection, fitcursor
1004 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1005 // 0 - update, move sel_cursor if selection, fitcursor
1006 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1007 // 3 - update, move sel_cursor if selection
1010 // a simple redraw of the parts that need refresh
1012 // move sel_cursor if selection -
1013 // the text's sel_cursor is moved if there is selection is progress
1016 // fitCursor() is called and the scrollbar updated
1019 // the buffer is marked dirty.
1028 // UPDATE_ONLY = UPDATE;
1029 // UPDATE_SELECT = UPDATE | SELECT;
1030 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1031 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1033 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1034 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1035 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1036 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1037 // update(3) -> update(1) -> update(1) -> update(SELECT)
1039 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1041 owner_->updateLayoutChoice();
1043 if (!text->selection.set() && (f & SELECT)) {
1044 text->selection.cursor = text->cursor;
1047 text->fullRebreak(bv_);
1049 if (text->inset_owner) {
1050 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1051 updateInset(text->inset_owner, false);
1061 buffer_->markDirty();
1066 // Callback for cursor timer
1067 void BufferView::Pimpl::cursorToggle()
1070 cursor_timeout.restart();
1075 extern void reapSpellchecker(void);
1078 if (!bv_->theLockingInset()) {
1079 screen().cursorToggle(bv_);
1081 bv_->theLockingInset()->toggleInsetCursor(bv_);
1084 cursor_timeout.restart();
1088 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1090 if (!text->cursor.row()->previous()) {
1091 if (text->first_y > 0) {
1092 int new_y = bv_->text->first_y - workarea().workHeight();
1093 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1099 int y = text->first_y;
1100 Row * cursorrow = text->cursor.row();
1102 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1106 if (cursorrow == bv_->text->cursor.row()) {
1107 // we have a row which is higher than the workarea so we leave the
1108 // cursor on the start of the row and move only the draw up as soon
1109 // as we move the cursor or do something while inside the row (it may
1110 // span several workarea-heights) we'll move to the top again, but this
1111 // is better than just jump down and only display part of the row.
1112 new_y = bv_->text->first_y - workarea().workHeight();
1114 if (text->inset_owner) {
1115 new_y = bv_->text->cursor.iy()
1116 + bv_->theLockingInset()->insetInInsetY() + y
1117 + text->cursor.row()->height()
1118 - workarea().workHeight() + 1;
1120 new_y = text->cursor.y()
1121 - text->cursor.row()->baseline()
1122 + text->cursor.row()->height()
1123 - workarea().workHeight() + 1;
1126 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1127 if (text->cursor.row()->previous()) {
1129 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1130 text->cursor.row()->previous()->pos(), false);
1131 if (cur.y() > text->first_y) {
1132 text->cursorUp(bv_, true);
1139 void BufferView::Pimpl::cursorNext(LyXText * text)
1141 if (!text->cursor.row()->next()) {
1142 int y = text->cursor.y() - text->cursor.row()->baseline() +
1143 text->cursor.row()->height();
1144 if (y > int(text->first_y + workarea().workHeight())) {
1145 screen().draw(bv_->text, bv_,
1146 bv_->text->first_y + workarea().workHeight());
1152 int y = text->first_y + workarea().workHeight();
1153 if (text->inset_owner && !text->first_y) {
1154 y -= (bv_->text->cursor.iy()
1155 - bv_->text->first_y
1156 + bv_->theLockingInset()->insetInInsetY());
1159 text->getRowNearY(y);
1161 Row * cursorrow = text->cursor.row();
1162 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1166 if (cursorrow == bv_->text->cursor.row()) {
1167 // we have a row which is higher than the workarea so we leave the
1168 // cursor on the start of the row and move only the draw down as soon
1169 // as we move the cursor or do something while inside the row (it may
1170 // span several workarea-heights) we'll move to the top again, but this
1171 // is better than just jump down and only display part of the row.
1172 new_y = bv_->text->first_y + workarea().workHeight();
1174 if (text->inset_owner) {
1175 new_y = bv_->text->cursor.iy()
1176 + bv_->theLockingInset()->insetInInsetY()
1177 + y - text->cursor.row()->baseline();
1179 new_y = text->cursor.y() - text->cursor.row()->baseline();
1182 screen().draw(bv_->text, bv_, new_y);
1183 if (text->cursor.row()->next()) {
1185 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1186 text->cursor.row()->next()->pos(), false);
1187 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1188 text->cursorDown(bv_, true);
1195 bool BufferView::Pimpl::available() const
1197 if (buffer_ && bv_->text)
1203 void BufferView::Pimpl::beforeChange(LyXText * text)
1206 text->clearSelection();
1210 void BufferView::Pimpl::savePosition(unsigned int i)
1212 if (i >= saved_positions_num)
1214 saved_positions[i] = Position(buffer_->fileName(),
1215 bv_->text->cursor.par()->id(),
1216 bv_->text->cursor.pos());
1219 str << _("Saved bookmark") << ' ' << i;
1220 owner_->message(str.str().c_str());
1225 void BufferView::Pimpl::restorePosition(unsigned int i)
1227 if (i >= saved_positions_num)
1230 string const fname = saved_positions[i].filename;
1232 beforeChange(bv_->text);
1234 if (fname != buffer_->fileName()) {
1235 Buffer * b = bufferlist.exists(fname) ?
1236 bufferlist.getBuffer(fname) :
1237 bufferlist.loadLyXFile(fname); // don't ask, just load it
1238 if (b != 0) buffer(b);
1241 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1245 bv_->text->setCursor(bv_, par,
1246 min(par->size(), saved_positions[i].par_pos));
1248 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1251 str << _("Moved to bookmark") << ' ' << i;
1252 owner_->message(str.str().c_str());
1257 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1259 if (i >= saved_positions_num)
1262 return !saved_positions[i].filename.empty();
1266 void BufferView::Pimpl::switchKeyMap()
1268 if (!lyxrc.rtl_support)
1271 LyXText * text = bv_->getLyXText();
1272 if (text->real_current_font.isRightToLeft()
1273 && !(bv_->theLockingInset()
1274 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1276 if (owner_->getIntl().keymap == Intl::PRIMARY)
1277 owner_->getIntl().KeyMapSec();
1279 if (owner_->getIntl().keymap == Intl::SECONDARY)
1280 owner_->getIntl().KeyMapPrim();
1285 void BufferView::Pimpl::insetUnlock()
1287 if (bv_->theLockingInset()) {
1288 bv_->theLockingInset()->insetUnlock(bv_);
1289 bv_->theLockingInset(0);
1295 void BufferView::Pimpl::showCursor()
1297 if (bv_->theLockingInset())
1298 bv_->theLockingInset()->showInsetCursor(bv_);
1300 screen().showCursor(bv_->text, bv_);
1304 void BufferView::Pimpl::hideCursor()
1306 if (!bv_->theLockingInset())
1307 screen().hideCursor();
1311 void BufferView::Pimpl::toggleSelection(bool b)
1313 if (bv_->theLockingInset())
1314 bv_->theLockingInset()->toggleSelection(bv_, b);
1315 screen().toggleSelection(bv_->text, bv_, b);
1319 void BufferView::Pimpl::toggleToggle()
1321 screen().toggleToggle(bv_->text, bv_);
1325 void BufferView::Pimpl::center()
1327 LyXText * t = bv_->text;
1330 int const half_height = workarea().workHeight() / 2;
1333 if (t->cursor.y() > half_height) {
1334 new_y = t->cursor.y() - half_height;
1337 // FIXME: can we do this w/o calling screen directly ?
1338 // This updates first_y but means the fitCursor() call
1339 // from the update(FITCUR) doesn't realise that we might
1340 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1341 // the scrollbar to be updated as it should, so we have
1342 // to do it manually. Any operation that does a center()
1343 // and also might have moved first_y must make sure to call
1344 // updateScrollbar() currently. Never mind that this is a
1345 // pretty obfuscated way of updating t->first_y
1346 screen().draw(t, bv_, new_y);
1348 update(t, BufferView::SELECT | BufferView::FITCUR);
1352 void BufferView::Pimpl::pasteClipboard(bool asPara)
1357 screen().hideCursor();
1358 beforeChange(bv_->text);
1360 string const clip(workarea().getClipboard());
1366 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1368 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1370 bv_->getLyXText()->clearSelection();
1371 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1375 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1377 workarea().putClipboard(stuff);
1382 * Dispatch functions for actions which can be valid for BufferView->text
1383 * and/or InsetText->text!!!
1388 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1390 LyXText * lt = bv_->getLyXText();
1392 if (selecting || lt->selection.mark()) {
1393 lt->setSelection(bv_);
1397 updateInset(lt->inset_owner, false);
1401 update(lt, BufferView::SELECT|BufferView::FITCUR);
1403 update(lt, BufferView::SELECT);
1405 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1406 bv_->theLockingInset()->hideInsetCursor(bv_);
1407 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1411 if (!lt->selection.set())
1412 workarea().haveSelection(false);
1418 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1420 LyXCursor cursor = bv_->getLyXText()->cursor;
1421 Buffer::inset_iterator it =
1422 find_if(Buffer::inset_iterator(
1423 cursor.par(), cursor.pos()),
1424 buffer_->inset_iterator_end(),
1425 lyx::compare_memfun(&Inset::lyxCode, code));
1426 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1430 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1432 string filename = filen;
1434 if (filename.empty()) {
1435 // Launch a file browser
1436 string initpath = lyxrc.document_path;
1439 string const trypath = owner_->buffer()->filePath();
1440 // If directory is writeable, use this as default.
1441 if (IsDirWriteable(trypath))
1445 FileDialog fileDlg(bv_->owner(),
1446 _("Select LyX document to insert"),
1448 make_pair(string(_("Documents|#o#O")),
1449 string(lyxrc.document_path)),
1450 make_pair(string(_("Examples|#E#e")),
1451 string(AddPath(system_lyxdir, "examples"))));
1453 FileDialog::Result result =
1454 fileDlg.Select(initpath,
1455 _("*.lyx| LyX Documents (*.lyx)"));
1457 if (result.first == FileDialog::Later)
1460 filename = result.second;
1462 // check selected filename
1463 if (filename.empty()) {
1464 owner_->message(_("Canceled."));
1469 // get absolute path of file and add ".lyx" to the filename if
1471 filename = FileSearch(string(), filename, "lyx");
1473 string const disp_fn(MakeDisplayPath(filename));
1476 s1 << _("Inserting document") << ' '
1477 << disp_fn << " ...";
1478 owner_->message(s1.str().c_str());
1479 bool const res = bv_->insertLyXFile(filename);
1482 str << _("Document") << ' ' << disp_fn
1483 << ' ' << _("inserted.");
1484 owner_->message(str.str().c_str());
1487 str << _("Could not insert document") << ' '
1489 owner_->message(str.str().c_str());
1494 bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
1496 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1497 << ev.action <<"] arg[" << ev.argument << "]" << endl;
1499 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1501 switch (ev.action) {
1502 // --- Misc -------------------------------------------
1506 LyXText * lt = bv_->getLyXText();
1507 lt->toggleAppendix(bv_);
1510 | BufferView::FITCUR
1511 | BufferView::CHANGE);
1516 case LFUN_TOC_INSERT:
1518 InsetCommandParams p;
1519 p.setCmdName("tableofcontents");
1520 Inset * inset = new InsetTOC(p);
1521 if (!insertInset(inset, tclass.defaultLayoutName()))
1526 case LFUN_SCROLL_INSET:
1527 // this is not handled here as this funktion is only aktive
1528 // if we have a locking_inset and that one is (or contains)
1532 case LFUN_INSET_GRAPHICS:
1534 Inset * new_inset = new InsetGraphics;
1535 if (!insertInset(new_inset)) {
1538 // this is need because you don't use a inset->Edit()
1539 updateInset(new_inset, true);
1540 new_inset->edit(bv_);
1550 case LFUN_PASTESELECTION:
1551 pasteClipboard(ev.argument == "paragraph");
1562 case LFUN_LAYOUT_COPY:
1563 bv_->copyEnvironment();
1566 case LFUN_LAYOUT_PASTE:
1567 bv_->pasteEnvironment();
1571 case LFUN_GOTOERROR:
1572 gotoInset(Inset::ERROR_CODE, false);
1576 gotoInset(Inset::NOTE_CODE, false);
1579 case LFUN_REFERENCE_GOTO:
1581 vector<Inset::Code> tmp;
1582 tmp.push_back(Inset::LABEL_CODE);
1583 tmp.push_back(Inset::REF_CODE);
1584 gotoInset(tmp, true);
1588 case LFUN_HYPHENATION:
1589 specialChar(InsetSpecialChar::HYPHENATION);
1592 case LFUN_LIGATURE_BREAK:
1593 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1597 specialChar(InsetSpecialChar::LDOTS);
1600 case LFUN_END_OF_SENTENCE:
1601 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1604 case LFUN_MENU_SEPARATOR:
1605 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1612 case LFUN_DEPTH_MIN:
1613 changeDepth(bv_, bv_->getLyXText(), -1);
1616 case LFUN_DEPTH_PLUS:
1617 changeDepth(bv_, bv_->getLyXText(), 1);
1621 owner_->getDialogs().setUserFreeFont();
1624 case LFUN_FILE_INSERT:
1625 MenuInsertLyXFile(ev.argument);
1628 case LFUN_FILE_INSERT_ASCII_PARA:
1629 InsertAsciiFile(bv_, ev.argument, true);
1632 case LFUN_FILE_INSERT_ASCII:
1633 InsertAsciiFile(bv_, ev.argument, false);
1638 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1639 << ev.argument << endl;
1641 // This is not the good solution to the empty argument
1642 // problem, but it will hopefully suffice for 1.2.0.
1643 // The correct solution would be to augument the
1644 // function list/array with information about what
1645 // functions needs arguments and their type.
1646 if (ev.argument.empty()) {
1647 owner_->getLyXFunc().setErrorMessage(
1648 _("LyX function 'layout' needs an argument."));
1652 // Derive layout number from given argument (string)
1653 // and current buffer's textclass (number). */
1654 bool hasLayout = tclass.hasLayout(ev.argument);
1655 string layout = ev.argument;
1657 // If the entry is obsolete, use the new one instead.
1659 string const & obs = tclass[layout]->obsoleted_by();
1665 owner_->getLyXFunc().setErrorMessage(
1666 string(N_("Layout ")) + ev.argument +
1671 bool change_layout = (current_layout != layout);
1672 LyXText * lt = bv_->getLyXText();
1673 if (!change_layout && lt->selection.set() &&
1674 lt->selection.start.par() != lt->selection.end.par())
1676 Paragraph * spar = lt->selection.start.par();
1677 Paragraph * epar = lt->selection.end.par()->next();
1678 while(spar != epar) {
1679 if (spar->layout()->name() != current_layout) {
1680 change_layout = true;
1685 if (change_layout) {
1687 current_layout = layout;
1690 | BufferView::FITCUR);
1691 lt->setLayout(bv_, layout);
1692 owner_->setLayout(layout);
1695 | BufferView::FITCUR
1696 | BufferView::CHANGE);
1703 lang(bv_, ev.argument);
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();
1735 owner_->view_state_changed();
1740 owner_->view_state_changed();
1743 case LFUN_UNDERLINE:
1745 owner_->view_state_changed();
1748 case LFUN_FONT_SIZE:
1749 fontSize(bv_, ev.argument);
1750 owner_->view_state_changed();
1753 case LFUN_FONT_STATE:
1754 owner_->getLyXFunc().setMessage(currentState(bv_));
1757 case LFUN_UPCASE_WORD:
1759 LyXText * lt = bv_->getLyXText();
1763 | BufferView::FITCUR);
1764 lt->changeCase(bv_, LyXText::text_uppercase);
1765 if (lt->inset_owner)
1766 updateInset(lt->inset_owner, true);
1769 | BufferView::FITCUR
1770 | BufferView::CHANGE);
1774 case LFUN_LOWCASE_WORD:
1776 LyXText * lt = bv_->getLyXText();
1778 update(lt, BufferView::SELECT|BufferView::FITCUR);
1779 lt->changeCase(bv_, LyXText::text_lowercase);
1780 if (lt->inset_owner)
1781 updateInset(lt->inset_owner, true);
1784 | BufferView::FITCUR
1785 | BufferView::CHANGE);
1789 case LFUN_CAPITALIZE_WORD:
1791 LyXText * lt = bv_->getLyXText();
1793 update(lt, BufferView::SELECT|BufferView::FITCUR);
1794 lt->changeCase(bv_, LyXText::text_capitalization);
1795 if (lt->inset_owner)
1796 updateInset(lt->inset_owner, true);
1799 | BufferView::FITCUR
1800 | BufferView::CHANGE);
1804 case LFUN_TRANSPOSE_CHARS:
1806 LyXText * lt = bv_->getLyXText();
1808 update(lt, BufferView::SELECT|BufferView::FITCUR);
1809 lt->transposeChars(*bv_);
1810 if (lt->inset_owner)
1811 updateInset(lt->inset_owner, true);
1814 | BufferView::FITCUR
1815 | BufferView::CHANGE);
1820 case LFUN_INSERT_LABEL:
1821 MenuInsertLabel(bv_, ev.argument);
1824 case LFUN_REF_INSERT:
1825 if (ev.argument.empty()) {
1826 InsetCommandParams p("ref");
1827 owner_->getDialogs().createRef(p.getAsString());
1829 InsetCommandParams p;
1830 p.setFromString(ev.argument);
1832 InsetRef * inset = new InsetRef(p, *buffer_);
1833 if (!insertInset(inset))
1836 updateInset(inset, true);
1840 case LFUN_BOOKMARK_SAVE:
1841 savePosition(strToUnsignedInt(ev.argument));
1844 case LFUN_BOOKMARK_GOTO:
1845 restorePosition(strToUnsignedInt(ev.argument));
1850 string label = ev.argument;
1851 if (label.empty()) {
1853 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1855 label = inset->getContents();
1860 if (!label.empty()) {
1861 //bv_->savePosition(0);
1862 if (!bv_->gotoLabel(label))
1863 Alert::alert(_("Error"),
1864 _("Couldn't find this label"),
1865 _("in current document."));
1870 // --- Cursor Movements -----------------------------
1873 LyXText * lt = bv_->getLyXText();
1875 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1876 if (!lt->selection.mark())
1878 update(lt, BufferView::SELECT|BufferView::FITCUR);
1880 lt->cursorLeft(bv_, false);
1881 if (lt->cursor.pos() < lt->cursor.par()->size()
1882 && lt->cursor.par()->isInset(lt->cursor.pos())
1883 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1884 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1885 owner_->getLyXFunc().setMessage(tmpinset->editMessage());
1887 tmpinset->edit(bv_, false);
1889 tmpinset->edit(bv_);
1893 lt->cursorRight(bv_, false);
1895 moveCursorUpdate(false);
1896 owner_->view_state_changed();
1902 // This is soooo ugly. Isn`t it possible to make
1903 // it simpler? (Lgb)
1904 LyXText * lt = bv_->getLyXText();
1905 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1906 if (!lt->selection.mark())
1908 update(lt, BufferView::SELECT|BufferView::FITCUR);
1909 LyXCursor const cur = lt->cursor;
1911 lt->cursorLeft(bv_, false);
1912 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1913 lt->cursor.pos() < lt->cursor.par()->size() &&
1914 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1915 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1916 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1917 owner_->getLyXFunc().setMessage(tmpinset->editMessage());
1919 tmpinset->edit(bv_);
1921 tmpinset->edit(bv_, false);
1925 lt->cursorRight(bv_, false);
1928 moveCursorUpdate(false);
1929 owner_->view_state_changed();
1935 LyXText * lt = bv_->getLyXText();
1937 if (!lt->selection.mark())
1939 update(lt, BufferView::UPDATE);
1942 moveCursorUpdate(false);
1943 owner_->view_state_changed();
1949 LyXText * lt = bv_->getLyXText();
1951 if (!lt->selection.mark())
1953 update(lt, BufferView::UPDATE);
1954 lt->cursorDown(bv_);
1956 moveCursorUpdate(false);
1957 owner_->view_state_changed();
1961 case LFUN_UP_PARAGRAPH:
1963 LyXText * lt = bv_->getLyXText();
1965 if (!lt->selection.mark())
1967 update(lt, BufferView::UPDATE);
1968 lt->cursorUpParagraph(bv_);
1970 moveCursorUpdate(false);
1971 owner_->view_state_changed();
1975 case LFUN_DOWN_PARAGRAPH:
1977 LyXText * lt = bv_->getLyXText();
1979 if (!lt->selection.mark())
1981 update(lt, BufferView::UPDATE);
1982 lt->cursorDownParagraph(bv_);
1984 moveCursorUpdate(false);
1985 owner_->view_state_changed();
1991 LyXText * lt = bv_->getLyXText();
1993 if (!lt->selection.mark())
1995 update(lt, BufferView::UPDATE);
1998 moveCursorUpdate(false, false);
1999 owner_->view_state_changed();
2005 LyXText * lt = bv_->getLyXText();
2007 if (!lt->selection.mark())
2009 update(lt, BufferView::UPDATE);
2012 moveCursorUpdate(false, false);
2013 owner_->view_state_changed();
2019 LyXText * lt = bv_->getLyXText();
2021 if (!lt->selection.mark())
2023 update(lt, BufferView::SELECT|BufferView::FITCUR);
2024 lt->cursorHome(bv_);
2026 moveCursorUpdate(false);
2027 owner_->view_state_changed();
2033 LyXText * lt = bv_->getLyXText();
2035 if (!lt->selection.mark())
2038 BufferView::SELECT|BufferView::FITCUR);
2041 moveCursorUpdate(false);
2042 owner_->view_state_changed();
2046 case LFUN_SHIFT_TAB:
2049 LyXText * lt = bv_->getLyXText();
2051 if (!lt->selection.mark())
2054 BufferView::SELECT|BufferView::FITCUR);
2057 moveCursorUpdate(false);
2058 owner_->view_state_changed();
2062 case LFUN_WORDRIGHT:
2064 LyXText * lt = bv_->getLyXText();
2066 if (!lt->selection.mark())
2068 update(lt, BufferView::SELECT|BufferView::FITCUR);
2069 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2070 lt->cursorLeftOneWord(bv_);
2072 lt->cursorRightOneWord(bv_);
2074 moveCursorUpdate(false);
2075 owner_->view_state_changed();
2081 LyXText * lt = bv_->getLyXText();
2083 if (!lt->selection.mark())
2085 update(lt, BufferView::SELECT|BufferView::FITCUR);
2086 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2087 lt->cursorRightOneWord(bv_);
2089 lt->cursorLeftOneWord(bv_);
2091 moveCursorUpdate(false);
2092 owner_->view_state_changed();
2096 case LFUN_BEGINNINGBUF:
2098 LyXText * lt = bv_->getLyXText();
2100 if (!lt->selection.mark())
2103 BufferView::SELECT|BufferView::FITCUR);
2106 moveCursorUpdate(false);
2107 owner_->view_state_changed();
2113 LyXText * lt = bv_->getLyXText();
2115 if (!lt->selection.mark())
2118 BufferView::SELECT|BufferView::FITCUR);
2119 lt->cursorBottom(bv_);
2121 moveCursorUpdate(false);
2122 owner_->view_state_changed();
2126 /* cursor selection ---------------------------- */
2129 LyXText * lt = bv_->getLyXText();
2132 BufferView::SELECT|BufferView::FITCUR);
2133 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2134 lt->cursorLeft(bv_);
2136 lt->cursorRight(bv_);
2138 moveCursorUpdate(true);
2139 owner_->view_state_changed();
2145 LyXText * lt = bv_->getLyXText();
2148 BufferView::SELECT|BufferView::FITCUR);
2149 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2150 lt->cursorRight(bv_);
2152 lt->cursorLeft(bv_);
2154 moveCursorUpdate(true);
2155 owner_->view_state_changed();
2161 LyXText * lt = bv_->getLyXText();
2164 BufferView::SELECT|BufferView::FITCUR);
2165 lt->cursorUp(bv_, true);
2167 moveCursorUpdate(true);
2168 owner_->view_state_changed();
2174 LyXText * lt = bv_->getLyXText();
2177 BufferView::SELECT|BufferView::FITCUR);
2178 lt->cursorDown(bv_, true);
2180 moveCursorUpdate(true);
2181 owner_->view_state_changed();
2185 case LFUN_UP_PARAGRAPHSEL:
2187 LyXText * lt = bv_->getLyXText();
2190 BufferView::SELECT|BufferView::FITCUR);
2191 lt->cursorUpParagraph(bv_);
2193 moveCursorUpdate(true);
2194 owner_->view_state_changed();
2198 case LFUN_DOWN_PARAGRAPHSEL:
2200 LyXText * lt = bv_->getLyXText();
2203 BufferView::SELECT|BufferView::FITCUR);
2204 lt->cursorDownParagraph(bv_);
2206 moveCursorUpdate(true);
2207 owner_->view_state_changed();
2213 LyXText * lt = bv_->getLyXText();
2215 update(lt, BufferView::SELECT|BufferView::FITCUR);
2218 moveCursorUpdate(true);
2219 owner_->view_state_changed();
2225 LyXText * lt = bv_->getLyXText();
2227 update(lt, BufferView::SELECT|BufferView::FITCUR);
2230 moveCursorUpdate(true);
2231 owner_->view_state_changed();
2237 LyXText * lt = bv_->getLyXText();
2239 update(lt, BufferView::SELECT|BufferView::FITCUR);
2240 lt->cursorHome(bv_);
2242 moveCursorUpdate(true);
2243 owner_->view_state_changed();
2249 LyXText * lt = bv_->getLyXText();
2251 update(lt, BufferView::SELECT|BufferView::FITCUR);
2254 moveCursorUpdate(true);
2255 owner_->view_state_changed();
2259 case LFUN_WORDRIGHTSEL:
2261 LyXText * lt = bv_->getLyXText();
2263 update(lt, BufferView::SELECT|BufferView::FITCUR);
2264 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2265 lt->cursorLeftOneWord(bv_);
2267 lt->cursorRightOneWord(bv_);
2269 moveCursorUpdate(true);
2270 owner_->view_state_changed();
2274 case LFUN_WORDLEFTSEL:
2276 LyXText * lt = bv_->getLyXText();
2278 update(lt, BufferView::SELECT|BufferView::FITCUR);
2279 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2280 lt->cursorRightOneWord(bv_);
2282 lt->cursorLeftOneWord(bv_);
2284 moveCursorUpdate(true);
2285 owner_->view_state_changed();
2289 case LFUN_BEGINNINGBUFSEL:
2291 LyXText * lt = bv_->getLyXText();
2293 if (lt->inset_owner)
2295 update(lt, BufferView::SELECT|BufferView::FITCUR);
2298 moveCursorUpdate(true);
2299 owner_->view_state_changed();
2303 case LFUN_ENDBUFSEL:
2305 LyXText * lt = bv_->getLyXText();
2307 if (lt->inset_owner)
2310 BufferView::SELECT|BufferView::FITCUR);
2311 lt->cursorBottom(bv_);
2313 moveCursorUpdate(true);
2314 owner_->view_state_changed();
2318 // --- text changing commands ------------------------
2319 case LFUN_BREAKLINE:
2321 LyXText * lt = bv_->getLyXText();
2324 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2327 | BufferView::FITCUR
2328 | BufferView::CHANGE);
2329 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2330 moveCursorUpdate(false);
2334 case LFUN_PROTECTEDSPACE:
2336 LyXText * lt = bv_->getLyXText();
2337 LyXLayout_ptr const & style = lt->cursor.par()->layout();
2339 if (style->free_spacing) {
2340 lt->insertChar(bv_, ' ');
2343 | BufferView::FITCUR
2344 | BufferView::CHANGE);
2346 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2348 moveCursorUpdate(false);
2354 LyXText * lt = bv_->getLyXText();
2356 if (lt->selection.mark()) {
2360 | BufferView::FITCUR);
2361 owner_->getLyXFunc().setMessage(N_("Mark removed"));
2364 lt->selection.mark(true);
2367 | BufferView::FITCUR);
2368 owner_->getLyXFunc().setMessage(N_("Mark set"));
2370 lt->selection.cursor = lt->cursor;
2376 LyXText * lt = bv_->getLyXText();
2378 if (!lt->selection.set()) {
2380 lt->selection.cursor = lt->cursor;
2383 | BufferView::FITCUR
2384 | BufferView::CHANGE);
2385 // It is possible to make it a lot faster still
2386 // just comment out the line below...
2391 moveCursorUpdate(false);
2392 owner_->view_state_changed();
2397 case LFUN_DELETE_SKIP:
2399 LyXText * lt = bv_->getLyXText();
2401 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2403 LyXCursor cursor = lt->cursor;
2405 if (!lt->selection.set()) {
2406 if (cursor.pos() == cursor.par()->size()) {
2407 lt->cursorRight(bv_);
2408 cursor = lt->cursor;
2409 if (cursor.pos() == 0
2410 && !(cursor.par()->params().spaceTop()
2411 == VSpace (VSpace::NONE))) {
2414 cursor.par()->params().lineTop(),
2415 cursor.par()->params().lineBottom(),
2416 cursor.par()->params().pagebreakTop(),
2417 cursor.par()->params().pagebreakBottom(),
2418 VSpace(VSpace::NONE),
2419 cursor.par()->params().spaceBottom(),
2420 cursor.par()->params().spacing(),
2421 cursor.par()->params().align(),
2422 cursor.par()->params().labelWidthString(), 0);
2423 lt->cursorLeft(bv_);
2426 | BufferView::FITCUR
2427 | BufferView::CHANGE);
2429 lt->cursorLeft(bv_);
2431 lt->selection.cursor = lt->cursor;
2434 | BufferView::FITCUR
2435 | BufferView::CHANGE);
2439 lt->selection.cursor = lt->cursor;
2442 | BufferView::FITCUR
2443 | BufferView::CHANGE);
2451 /* -------> Delete word forward. */
2452 case LFUN_DELETE_WORD_FORWARD:
2453 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2454 bv_->getLyXText()->deleteWordForward(bv_);
2455 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2456 moveCursorUpdate(false);
2457 owner_->view_state_changed();
2460 /* -------> Delete word backward. */
2461 case LFUN_DELETE_WORD_BACKWARD:
2463 LyXText * lt = bv_->getLyXText();
2465 update(lt, BufferView::SELECT|BufferView::FITCUR);
2466 lt->deleteWordBackward(bv_);
2469 | BufferView::FITCUR
2470 | BufferView::CHANGE);
2471 moveCursorUpdate(false);
2472 owner_->view_state_changed();
2476 /* -------> Kill to end of line. */
2477 case LFUN_DELETE_LINE_FORWARD:
2479 LyXText * lt = bv_->getLyXText();
2481 update(lt, BufferView::SELECT|BufferView::FITCUR);
2482 lt->deleteLineForward(bv_);
2485 | BufferView::FITCUR
2486 | BufferView::CHANGE);
2487 moveCursorUpdate(false);
2491 /* -------> Set mark off. */
2494 LyXText * lt = bv_->getLyXText();
2497 update(lt, BufferView::SELECT|BufferView::FITCUR);
2498 lt->selection.cursor = lt->cursor;
2499 owner_->getLyXFunc().setMessage(N_("Mark off"));
2503 /* -------> Set mark on. */
2506 LyXText * lt = bv_->getLyXText();
2509 lt->selection.mark(true);
2510 update(lt, BufferView::SELECT|BufferView::FITCUR);
2511 lt->selection.cursor = lt->cursor;
2512 owner_->getLyXFunc().setMessage(N_("Mark on"));
2516 case LFUN_BACKSPACE:
2518 LyXText * lt = bv_->getLyXText();
2520 if (!lt->selection.set()) {
2521 if (owner_->getIntl().getTransManager().backspace()) {
2523 lt->selection.cursor = lt->cursor;
2526 | BufferView::FITCUR
2527 | BufferView::CHANGE);
2528 // It is possible to make it a lot faster still
2529 // just comment out the line below...
2535 owner_->view_state_changed();
2540 case LFUN_BACKSPACE_SKIP:
2542 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2543 LyXText * lt = bv_->getLyXText();
2545 LyXCursor cursor = lt->cursor;
2547 if (!lt->selection.set()) {
2548 if (cursor.pos() == 0
2549 && !(cursor.par()->params().spaceTop()
2550 == VSpace (VSpace::NONE))) {
2553 cursor.par()->params().lineTop(),
2554 cursor.par()->params().lineBottom(),
2555 cursor.par()->params().pagebreakTop(),
2556 cursor.par()->params().pagebreakBottom(),
2557 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2558 cursor.par()->params().spacing(),
2559 cursor.par()->params().align(),
2560 cursor.par()->params().labelWidthString(), 0);
2563 | BufferView::FITCUR
2564 | BufferView::CHANGE);
2567 lt->selection.cursor = cursor;
2570 | BufferView::FITCUR
2571 | BufferView::CHANGE);
2578 case LFUN_BREAKPARAGRAPH:
2580 LyXText * lt = bv_->getLyXText();
2583 lt->breakParagraph(bv_, 0);
2586 | BufferView::FITCUR
2587 | BufferView::CHANGE);
2588 lt->selection.cursor = lt->cursor;
2590 owner_->view_state_changed();
2594 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2596 LyXText * lt = bv_->getLyXText();
2599 lt->breakParagraph(bv_, 1);
2602 | BufferView::FITCUR
2603 | BufferView::CHANGE);
2604 lt->selection.cursor = lt->cursor;
2606 owner_->view_state_changed();
2610 case LFUN_BREAKPARAGRAPH_SKIP:
2612 // When at the beginning of a paragraph, remove
2613 // indentation and add a "defskip" at the top.
2614 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2615 LyXText * lt = bv_->getLyXText();
2617 LyXCursor cursor = lt->cursor;
2620 if (cursor.pos() == 0) {
2621 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2624 cursor.par()->params().lineTop(),
2625 cursor.par()->params().lineBottom(),
2626 cursor.par()->params().pagebreakTop(),
2627 cursor.par()->params().pagebreakBottom(),
2628 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2629 cursor.par()->params().spacing(),
2630 cursor.par()->params().align(),
2631 cursor.par()->params().labelWidthString(), 1);
2632 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2636 lt->breakParagraph(bv_, 0);
2637 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2642 | BufferView::FITCUR
2643 | BufferView::CHANGE);
2644 lt->selection.cursor = cursor;
2646 owner_->view_state_changed();
2650 case LFUN_PARAGRAPH_SPACING:
2652 LyXText * lt = bv_->getLyXText();
2654 Paragraph * par = lt->cursor.par();
2655 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2656 float cur_value = 1.0;
2657 if (cur_spacing == Spacing::Other) {
2658 cur_value = par->params().spacing().getValue();
2661 istringstream istr(ev.argument.c_str());
2665 Spacing::Space new_spacing = cur_spacing;
2666 float new_value = cur_value;
2668 lyxerr << "Missing argument to `paragraph-spacing'"
2670 } else if (tmp == "single") {
2671 new_spacing = Spacing::Single;
2672 } else if (tmp == "onehalf") {
2673 new_spacing = Spacing::Onehalf;
2674 } else if (tmp == "double") {
2675 new_spacing = Spacing::Double;
2676 } else if (tmp == "other") {
2677 new_spacing = Spacing::Other;
2680 lyxerr << "new_value = " << tmpval << endl;
2683 } else if (tmp == "default") {
2684 new_spacing = Spacing::Default;
2686 lyxerr << _("Unknown spacing argument: ")
2687 << ev.argument << endl;
2689 if (cur_spacing != new_spacing || cur_value != new_value) {
2690 par->params().spacing(Spacing(new_spacing, new_value));
2691 lt->redoParagraph(bv_);
2694 | BufferView::FITCUR
2695 | BufferView::CHANGE);
2700 case LFUN_INSET_TOGGLE:
2702 LyXText * lt = bv_->getLyXText();
2705 update(lt, BufferView::SELECT|BufferView::FITCUR);
2706 lt->toggleInset(bv_);
2707 update(lt, BufferView::SELECT|BufferView::FITCUR);
2719 InsetCommandParams p;
2720 if (ev.action == LFUN_HTMLURL)
2721 p.setCmdName("htmlurl");
2723 p.setCmdName("url");
2724 owner_->getDialogs().createUrl(p.getAsString());
2728 case LFUN_INSERT_URL:
2730 InsetCommandParams p;
2731 p.setFromString(ev.argument);
2733 InsetUrl * inset = new InsetUrl(p);
2734 if (!insertInset(inset))
2737 updateInset(inset, true);
2741 case LFUN_INSET_ERT:
2742 insertAndEditInset(new InsetERT(buffer_->params));
2745 case LFUN_INSET_EXTERNAL:
2746 insertAndEditInset(new InsetExternal);
2749 case LFUN_INSET_FOOTNOTE:
2750 insertAndEditInset(new InsetFoot(buffer_->params));
2753 case LFUN_INSET_MARGINAL:
2754 insertAndEditInset(new InsetMarginal(buffer_->params));
2757 case LFUN_INSET_MINIPAGE:
2758 insertAndEditInset(new InsetMinipage(buffer_->params));
2761 case LFUN_INSERT_NOTE:
2762 insertAndEditInset(new InsetNote(buffer_->params));
2765 case LFUN_INSET_FLOAT:
2766 // check if the float type exist
2767 if (floatList.typeExist(ev.argument)) {
2768 insertAndEditInset(new InsetFloat(buffer_->params,
2771 lyxerr << "Non-existent float type: "
2772 << ev.argument << endl;
2776 case LFUN_INSET_WIDE_FLOAT:
2777 // check if the float type exist
2778 if (floatList.typeExist(ev.argument)) {
2779 InsetFloat * new_inset =
2780 new InsetFloat(buffer_->params, ev.argument);
2781 new_inset->wide(true);
2782 insertAndEditInset(new_inset);
2784 lyxerr << "Non-existent float type: "
2785 << ev.argument << endl;
2790 case LFUN_INSET_LIST:
2791 insertAndEditInset(new InsetList);
2794 case LFUN_INSET_THEOREM:
2795 insertAndEditInset(new InsetTheorem);
2799 case LFUN_INSET_CAPTION:
2801 // Do we have a locking inset...
2802 if (bv_->theLockingInset()) {
2803 lyxerr << "Locking inset code: "
2804 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2805 InsetCaption * new_inset =
2806 new InsetCaption(buffer_->params);
2807 new_inset->setOwner(bv_->theLockingInset());
2808 new_inset->setAutoBreakRows(true);
2809 new_inset->setDrawFrame(0, InsetText::LOCKED);
2810 new_inset->setFrameColor(0, LColor::captionframe);
2811 if (insertInset(new_inset))
2812 new_inset->edit(bv_);
2819 case LFUN_TABULAR_INSERT:
2821 if (ev.argument.empty()) {
2822 owner_->getDialogs().showTabularCreate();
2828 ::sscanf(ev.argument.c_str(),"%d%d", &r, &c);
2829 InsetTabular * new_inset =
2830 new InsetTabular(*buffer_, r, c);
2832 bv_->getLyXText()->real_current_font.isRightToLeft();
2833 if (!open_new_inset(new_inset, rtl))
2838 // --- lyxserver commands ----------------------------
2840 case LFUN_CHARATCURSOR:
2842 pos_type pos = bv_->getLyXText()->cursor.pos();
2843 if (pos < bv_->getLyXText()->cursor.par()->size())
2844 owner_->getLyXFunc().setMessage(
2845 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2847 owner_->getLyXFunc().setMessage("EOF");
2852 owner_->getLyXFunc().setMessage(tostr(bv_->getLyXText()->cursor.x())
2854 + tostr(bv_->getLyXText()->cursor.y()));
2861 if (::sscanf(ev.argument.c_str(), " %d %d", &x, &y) != 2) {
2862 lyxerr << "SETXY: Could not parse coordinates in '"
2863 << ev.argument << std::endl;
2865 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2869 case LFUN_GETLAYOUT:
2870 owner_->getLyXFunc().setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2875 LyXFont & font = bv_->getLyXText()->current_font;
2876 if (font.shape() == LyXFont::ITALIC_SHAPE)
2877 owner_->getLyXFunc().setMessage("E");
2878 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2879 owner_->getLyXFunc().setMessage("N");
2881 owner_->getLyXFunc().setMessage("0");
2886 // --- accented characters ---------------------------
2889 case LFUN_CIRCUMFLEX:
2899 case LFUN_SPECIAL_CARON:
2902 case LFUN_HUNG_UMLAUT:
2905 if (ev.argument.empty()) {
2907 owner_->getLyXFunc().handleKeyFunc(ev.action);
2909 owner_->getLyXFunc().handleKeyFunc(ev.action);
2910 owner_->getIntl().getTransManager()
2911 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
2912 update(bv_->getLyXText(),
2914 | BufferView::FITCUR
2915 | BufferView::CHANGE);
2919 case LFUN_MATH_MACRO:
2920 case LFUN_MATH_DELIM:
2921 case LFUN_INSERT_MATRIX:
2922 case LFUN_INSERT_MATH:
2923 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2924 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2925 case LFUN_MATH_MODE: // Open or create an inlined math inset
2926 case LFUN_GREEK: // Insert a single greek letter
2927 mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
2930 case LFUN_CITATION_INSERT:
2932 InsetCommandParams p;
2933 p.setFromString(ev.argument);
2935 InsetCitation * inset = new InsetCitation(p);
2936 if (!insertInset(inset))
2939 updateInset(inset, true);
2943 case LFUN_INSERT_BIBTEX:
2945 // ale970405+lasgoutt970425
2946 // The argument can be up to two tokens separated
2947 // by a space. The first one is the bibstyle.
2948 string const db = token(ev.argument, ' ', 0);
2949 string const bibstyle = token(ev.argument, ' ', 1);
2951 InsetCommandParams p("BibTeX", db, bibstyle);
2952 InsetBibtex * inset = new InsetBibtex(p);
2954 if (insertInset(inset)) {
2955 if (ev.argument.empty())
2962 // BibTeX data bases
2963 case LFUN_BIBDB_ADD:
2965 InsetBibtex * inset =
2966 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2968 inset->addDatabase(ev.argument);
2973 case LFUN_BIBDB_DEL:
2975 InsetBibtex * inset =
2976 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2978 inset->delDatabase(ev.argument);
2983 case LFUN_BIBTEX_STYLE:
2985 InsetBibtex * inset =
2986 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2988 inset->setOptions(ev.argument);
2993 case LFUN_INDEX_INSERT:
2995 string entry = ev.argument;
2996 if (entry.empty()) {
2997 entry = bv_->getLyXText()->getStringToIndex(bv_);
3000 if (entry.empty()) {
3001 owner_->getDialogs().createIndex();
3005 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
3007 if (!insertInset(inset)) {
3010 updateInset(inset, true);
3015 case LFUN_INDEX_PRINT:
3017 InsetCommandParams p("printindex");
3018 Inset * inset = new InsetPrintIndex(p);
3019 if (!insertInset(inset, tclass.defaultLayoutName()))
3024 case LFUN_PARENTINSERT:
3026 InsetCommandParams p("lyxparent", ev.argument);
3027 Inset * inset = new InsetParent(p, *buffer_);
3028 if (!insertInset(inset, tclass.defaultLayoutName()))
3034 case LFUN_CHILD_INSERT:
3036 InsetInclude::Params p;
3037 p.cparams.setFromString(ev.argument);
3038 p.masterFilename_ = buffer_->fileName();
3040 InsetInclude * inset = new InsetInclude(p);
3041 if (!insertInset(inset))
3044 updateInset(inset, true);
3045 bv_->owner()->getDialogs().showInclude(inset);
3050 case LFUN_FLOAT_LIST:
3051 if (floatList.typeExist(ev.argument)) {
3052 Inset * inset = new InsetFloatList(ev.argument);
3053 if (!insertInset(inset, tclass.defaultLayoutName()))
3056 lyxerr << "Non-existent float type: "
3057 << ev.argument << endl;
3061 case LFUN_THESAURUS_ENTRY:
3063 string arg = ev.argument;
3066 arg = bv_->getLyXText()->selectionAsString(buffer_,
3070 if (arg.size() > 100 || arg.empty()) {
3071 // Get word or selection
3072 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3073 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3074 // FIXME: where is getLyXText()->unselect(bv_) ?
3078 bv_->owner()->getDialogs().showThesaurus(arg);
3082 case LFUN_SELFINSERT:
3084 if (ev.argument.empty()) break;
3086 /* Automatically delete the currently selected
3087 * text and replace it with what is being
3088 * typed in now. Depends on lyxrc settings
3089 * "auto_region_delete", which defaults to
3092 LyXText * lt = bv_->getLyXText();
3094 if (lyxrc.auto_region_delete) {
3095 if (lt->selection.set()) {
3096 lt->cutSelection(bv_, false, false);
3099 | BufferView::FITCUR
3100 | BufferView::CHANGE);
3102 workarea().haveSelection(false);
3106 LyXFont const old_font(lt->real_current_font);
3108 string::const_iterator cit = ev.argument.begin();
3109 string::const_iterator end = ev.argument.end();
3110 for (; cit != end; ++cit) {
3111 owner_->getIntl().getTransManager().
3112 TranslateAndInsert(*cit, lt);
3117 | BufferView::FITCUR
3118 | BufferView::CHANGE);
3120 lt->selection.cursor = lt->cursor;
3121 moveCursorUpdate(false);
3123 // real_current_font.number can change so we need to
3124 // update the minibuffer
3125 if (old_font != lt->real_current_font)
3126 owner_->view_state_changed();
3131 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3133 time_t now_time_t = time(NULL);
3134 struct tm * now_tm = localtime(&now_time_t);
3135 setlocale(LC_TIME, "");
3137 if (!ev.argument.empty())
3140 arg = lyxrc.date_insert_format;
3142 int const datetmp_len =
3143 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3145 LyXText * lt = bv_->getLyXText();
3147 for (int i = 0; i < datetmp_len; i++) {
3148 lt->insertChar(bv_, datetmp[i]);
3151 | BufferView::FITCUR
3152 | BufferView::CHANGE);
3155 lt->selection.cursor = lt->cursor;
3156 moveCursorUpdate(false);
3160 case LFUN_UNKNOWN_ACTION:
3161 owner_->getLyXFunc().setErrorMessage(N_("Unknown function!"));
3172 void BufferView::Pimpl::newline()
3175 LyXText * lt = bv_->getLyXText();
3179 | BufferView::FITCUR);
3180 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3183 | BufferView::FITCUR
3184 | BufferView::CHANGE);
3189 void BufferView::Pimpl::hfill()
3192 LyXText * lt = bv_->getLyXText();
3196 | BufferView::FITCUR);
3197 lt->insertChar(bv_, Paragraph::META_HFILL);
3200 | BufferView::FITCUR
3201 | BufferView::CHANGE);
3206 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3209 LyXText * lt = bv_->getLyXText();
3212 update(lt, BufferView::SELECT|BufferView::FITCUR);
3213 InsetSpecialChar * new_inset =
3214 new InsetSpecialChar(kind);
3215 if (!insertInset(new_inset))
3218 updateInset(new_inset, true);
3223 void BufferView::Pimpl::smartQuote()
3225 LyXText const * lt = bv_->getLyXText();
3226 Paragraph const * par = lt->cursor.par();
3227 pos_type pos = lt->cursor.pos();
3231 || (par->isInset(pos - 1)
3232 && par->getInset(pos - 1)->isSpace()))
3235 c = par->getChar(pos - 1);
3240 LyXLayout_ptr const & style = par->layout();
3242 if (style->pass_thru ||
3243 par->getFontSettings(buffer_->params,
3244 pos).language()->lang() == "hebrew" ||
3245 (!insertInset(new InsetQuotes(c, buffer_->params))))
3246 bv_->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
3250 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3253 if (insertInset(inset))
3258 bool gotsel = false;
3260 if (bv_->getLyXText()->selection.set()) {
3261 bv_->getLyXText()->cutSelection(bv_, true, false);
3265 if (insertInset(inset)) {
3268 owner_->dispatch(FuncRequest(LFUN_PASTESELECTION));
3276 // Open and lock an updatable inset
3277 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3279 LyXText * lt = bv_->getLyXText();
3283 if (!insertInset(new_inset)) {
3287 new_inset->edit(bv_, !behind);
3292 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3294 // if we are in a locking inset we should try to insert the
3295 // inset there otherwise this is a illegal function now
3296 if (bv_->theLockingInset()) {
3297 if (bv_->theLockingInset()->insetAllowed(inset))
3298 return bv_->theLockingInset()->insertInset(bv_, inset);
3302 // not quite sure if we want this...
3303 setCursorParUndo(bv_);
3306 beforeChange(bv_->text);
3307 if (!lout.empty()) {
3308 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3309 bv_->text->breakParagraph(bv_);
3310 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3312 if (!bv_->text->cursor.par()->empty()) {
3313 bv_->text->cursorLeft(bv_);
3315 bv_->text->breakParagraph(bv_);
3316 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3320 LyXTextClass const & tclass =
3321 buffer_->params.getLyXTextClass();
3322 bool hasLayout = tclass.hasLayout(lres);
3323 string lay = tclass.defaultLayoutName();
3325 if (hasLayout != false) {
3329 // layout not fount using default
3330 lay = tclass.defaultLayoutName();
3333 bv_->text->setLayout(bv_, lay);
3335 bv_->text->setParagraph(bv_, 0, 0,
3337 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3342 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3345 bv_->text->insertInset(bv_, inset);
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3355 if (!inset || !available())
3358 // first check for locking insets
3359 if (bv_->theLockingInset()) {
3360 if (bv_->theLockingInset() == inset) {
3361 if (bv_->text->updateInset(bv_, inset)) {
3364 buffer_->markDirty();
3369 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3370 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3373 buffer_->markDirty();
3381 // then check if the inset is a top_level inset (has no owner)
3382 // if yes do the update as always otherwise we have to update the
3383 // toplevel inset where this inset is inside
3384 Inset * tl_inset = inset;
3385 while(tl_inset->owner())
3386 tl_inset = tl_inset->owner();
3388 if (tl_inset == inset) {
3389 update(bv_->text, BufferView::UPDATE);
3390 if (bv_->text->updateInset(bv_, inset)) {
3394 | BufferView::FITCUR
3395 | BufferView::CHANGE);
3397 update(bv_->text, SELECT);
3401 } else if (static_cast<UpdatableInset *>(tl_inset)
3402 ->updateInsetInInset(bv_, inset))
3404 if (bv_->text->updateInset(bv_, tl_inset)) {
3412 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3415 if (!available()) return;
3418 beforeChange(bv_->text);
3419 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3421 LyXCursor const & cursor = bv_->text->cursor;
3425 cursor.par()->isInset(cursor.pos())) {
3426 Inset const * inset = cursor.par()->getInset(cursor.pos());
3427 if (find(codes.begin(), codes.end(), inset->lyxCode())
3430 static_cast<InsetCommand const *>(inset)->getContents();
3434 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3435 if (bv_->text->cursor.pos()
3436 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3437 LyXCursor tmp = bv_->text->cursor;
3438 bv_->text->cursor.par(bv_->text->ownerParagraph());
3439 bv_->text->cursor.pos(0);
3440 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3441 bv_->text->cursor = tmp;
3442 bv_->owner()->message(_("No more insets"));
3445 bv_->owner()->message(_("No more insets"));
3448 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3449 bv_->text->selection.cursor = bv_->text->cursor;
3453 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3455 gotoInset(vector<Inset::Code>(1, code), same_content);