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/Dialogs.h"
19 #include "frontends/Alert.h"
20 #include "frontends/FileDialog.h"
23 #include "paragraph.h"
24 #include "frontends/LyXView.h"
25 #include "commandtags.h"
28 #include "bufferview_funcs.h"
29 #include "TextCache.h"
30 #include "bufferlist.h"
33 // added for Dispatch functions
36 #include "FloatList.h"
38 #include "ParagraphParameters.h"
39 #include "undo_funcs.h"
40 #include "lyxtextclasslist.h"
42 #include "insets/insetbib.h"
43 #include "insets/insettext.h"
44 #include "insets/inseturl.h"
45 #include "insets/insetlatexaccent.h"
46 #include "insets/insettoc.h"
47 #include "insets/insetref.h"
48 #include "insets/insetparent.h"
49 #include "insets/insetindex.h"
50 #include "insets/insetnote.h"
51 #include "insets/insetinclude.h"
52 #include "insets/insetcite.h"
53 #include "insets/insetert.h"
54 #include "insets/insetexternal.h"
55 #include "insets/insetgraphics.h"
56 #include "insets/insetfoot.h"
57 #include "insets/insetmarginal.h"
58 #include "insets/insetminipage.h"
59 #include "insets/insetfloat.h"
60 #include "insets/insettabular.h"
62 #include "insets/insettheorem.h"
63 #include "insets/insetlist.h"
65 #include "insets/insetcaption.h"
66 #include "insets/insetfloatlist.h"
67 #include "insets/insetspecialchar.h"
69 #include "mathed/formulabase.h"
71 #include "support/LAssert.h"
72 #include "support/lstrings.h"
73 #include "support/filetools.h"
74 #include "support/lyxfunctional.h"
76 #include <boost/bind.hpp>
85 extern string current_layout;
87 #ifndef CXX_GLOBAL_CSTD
100 using std::make_pair;
104 using lyx::textclass_type;
106 /* the selection possible is needed, that only motion events are
107 * used, where the bottom press event was on the drawing area too */
108 bool selection_possible = false;
110 extern BufferList bufferlist;
111 extern char ascii_type;
113 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
118 const unsigned int saved_positions_num = 20;
123 XSync(fl_get_display(), 0);
127 void SetXtermCursor(Window win)
129 static Cursor cursor;
130 static bool cursor_undefined = true;
131 if (cursor_undefined) {
132 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
133 XFlush(fl_get_display());
134 cursor_undefined = false;
136 XDefineCursor(fl_get_display(), win, cursor);
137 XFlush(fl_get_display());
143 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
144 int xpos, int ypos, int width, int height)
145 : bv_(b), owner_(o), buffer_(0), cursor_timeout(400),
146 using_xterm_cursor(false)
148 workarea_.reset(new WorkArea(xpos, ypos, width, height));
149 screen_.reset(new LScreen(workarea()));
152 workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
153 workarea().workAreaExpose
154 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
155 workarea().workAreaButtonPress
156 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
157 workarea().workAreaButtonRelease
158 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
159 workarea().workAreaMotionNotify
160 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
161 workarea().workAreaDoubleClick
162 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
163 workarea().workAreaTripleClick
164 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
165 workarea().workAreaKeyPress
166 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
167 workarea().selectionRequested
168 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
169 workarea().selectionLost
170 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
172 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
173 cursor_timeout.start();
174 workarea().setFocus();
175 saved_positions.resize(saved_positions_num);
179 WorkArea & BufferView::Pimpl::workarea() const
181 return *workarea_.get();
185 LScreen & BufferView::Pimpl::screen() const
187 return *screen_.get();
191 Painter & BufferView::Pimpl::painter() const
193 return workarea().getPainter();
197 void BufferView::Pimpl::buffer(Buffer * b)
199 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
202 buffer_->delUser(bv_);
204 // Put the old text into the TextCache, but
205 // only if the buffer is still loaded.
206 // Also set the owner of the test to 0
207 // bv_->text->owner(0);
208 textcache.add(buffer_, workarea().workWidth(), bv_->text);
209 if (lyxerr.debugging())
210 textcache.show(lyxerr, "BufferView::buffer");
215 // Set current buffer
218 if (bufferlist.getState() == BufferList::CLOSING) return;
220 // If we are closing the buffer, use the first buffer as current
222 buffer_ = bufferlist.first();
226 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
227 buffer_->addUser(bv_);
228 // If we don't have a text object for this, we make one
229 if (bv_->text == 0) {
230 resizeCurrentBuffer();
235 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
236 owner_->updateMenubar();
237 owner_->updateToolbar();
238 // Similarly, buffer-dependent dialogs should be updated or
239 // hidden. This should go here because some dialogs (eg ToC)
240 // require bv_->text.
241 owner_->getDialogs()->updateBufferDependent(true);
244 lyxerr[Debug::INFO] << " No Buffer!" << endl;
245 owner_->updateMenubar();
246 owner_->updateToolbar();
247 owner_->getDialogs()->hideBufferDependent();
251 // Also remove all remaining text's from the testcache.
252 // (there should not be any!) (if there is any it is a
254 if (lyxerr.debugging())
255 textcache.show(lyxerr, "buffer delete all");
258 // should update layoutchoice even if we don't have a buffer.
259 owner_->updateLayoutChoice();
261 owner_->updateWindowTitle();
265 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
267 workarea().resize(xpos, ypos, width, height);
268 update(bv_->text, SELECT);
273 void BufferView::Pimpl::resize()
276 resizeCurrentBuffer();
280 void BufferView::Pimpl::redraw()
282 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
287 bool BufferView::Pimpl::fitCursor()
291 if (bv_->theLockingInset()) {
292 bv_->theLockingInset()->fitInsetCursor(bv_);
295 ret = screen().fitCursor(bv_->text, bv_);
298 bv_->owner()->getDialogs()->updateParagraph();
305 void BufferView::Pimpl::redoCurrentBuffer()
307 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
308 if (buffer_ && bv_->text) {
310 owner_->updateLayoutChoice();
315 int BufferView::Pimpl::resizeCurrentBuffer()
317 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
320 Paragraph * selstartpar = 0;
321 Paragraph * selendpar = 0;
322 UpdatableInset * the_locking_inset = 0;
325 pos_type selstartpos = 0;
326 pos_type selendpos = 0;
327 bool selection = false;
328 bool mark_set = false;
330 owner_->prohibitInput();
332 owner_->message(_("Formatting document..."));
335 par = bv_->text->cursor.par();
336 pos = bv_->text->cursor.pos();
337 selstartpar = bv_->text->selection.start.par();
338 selstartpos = bv_->text->selection.start.pos();
339 selendpar = bv_->text->selection.end.par();
340 selendpos = bv_->text->selection.end.pos();
341 selection = bv_->text->selection.set();
342 mark_set = bv_->text->selection.mark();
343 the_locking_inset = bv_->theLockingInset();
344 buffer_->resizeInsets(bv_);
345 // I don't think the delete and new are necessary here we just could
346 // call only init! (Jug 20020419)
348 bv_->text = new LyXText(bv_);
349 bv_->text->init(bv_);
351 // See if we have a text in TextCache that fits
352 // the new buffer_ with the correct width.
353 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
355 if (lyxerr.debugging()) {
356 lyxerr << "Found a LyXText that fits:\n";
357 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
359 // Set the owner of the newly found text
360 // bv_->text->owner(bv_);
361 if (lyxerr.debugging())
362 textcache.show(lyxerr, "resizeCurrentBuffer");
364 bv_->text = new LyXText(bv_);
365 bv_->text->init(bv_);
366 //buffer_->resizeInsets(bv_);
373 bv_->text->selection.set(true);
374 // At this point just to avoid the Delete-Empty-Paragraph-
375 // Mechanism when setting the cursor.
376 bv_->text->selection.mark(mark_set);
378 bv_->text->setCursor(bv_, selstartpar, selstartpos);
379 bv_->text->selection.cursor = bv_->text->cursor;
380 bv_->text->setCursor(bv_, selendpar, selendpos);
381 bv_->text->setSelection(bv_);
382 bv_->text->setCursor(bv_, par, pos);
384 bv_->text->setCursor(bv_, par, pos);
385 bv_->text->selection.cursor = bv_->text->cursor;
386 bv_->text->selection.set(false);
388 // remake the inset locking
389 bv_->theLockingInset(the_locking_inset);
392 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
394 // this will scroll the screen such that the cursor becomes visible
399 owner_->allowInput();
401 /// clear the "Formatting Document" message
408 void BufferView::Pimpl::updateScreen()
410 // Regenerate the screen.
415 void BufferView::Pimpl::updateScrollbar()
418 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
419 workarea().setScrollbarParams(0, 0, 0);
423 LyXText const & t = *bv_->text;
425 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
429 void BufferView::Pimpl::scrollDocView(int value)
431 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
433 if (!buffer_) return;
435 screen().draw(bv_->text, bv_, value);
437 if (!lyxrc.cursor_follows_scrollbar) {
442 LyXText * vbt = bv_->text;
444 int const height = vbt->defaultHeight();
445 int const first = static_cast<int>((bv_->text->first_y + height));
446 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
448 if (vbt->cursor.y() < first)
449 vbt->setCursorFromCoordinates(bv_, 0, first);
450 else if (vbt->cursor.y() > last)
451 vbt->setCursorFromCoordinates(bv_, 0, last);
457 int BufferView::Pimpl::scroll(long time)
462 LyXText const * t = bv_->text;
464 double const diff = t->defaultHeight()
465 + double(time) * double(time) * 0.125;
467 scrollDocView(int(diff));
468 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
473 void BufferView::Pimpl::workAreaKeyPress(KeySym key, key_modifier::state state)
475 bv_->owner()->getLyXFunc()->processKeySym(key, state);
479 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
481 // Only use motion with button 1
482 if (!(state & mouse_button::button1))
488 // Check for inset locking
489 if (bv_->theLockingInset()) {
490 LyXCursor cursor = bv_->text->cursor;
491 LyXFont font = bv_->text->getFont(buffer_,
492 cursor.par(), cursor.pos());
493 int width = bv_->theLockingInset()->width(bv_, font);
494 int inset_x = font.isVisibleRightToLeft()
495 ? cursor.ix() - width : cursor.ix();
496 int start_x = inset_x + bv_->theLockingInset()->scroll();
498 bv_->theLockingInset()->
499 insetMotionNotify(bv_,
501 y - cursor.iy() + bv_->text->first_y,
506 /* The test for not selection possible is needed, that only motion
507 events are used, where the bottom press event was on
508 the drawing area too */
509 if (!selection_possible)
512 screen().hideCursor();
514 Row * cursorrow = bv_->text->cursor.row();
515 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
517 // sorry for this but I have a strange error that the y value jumps at
518 // a certain point. This seems like an error in my xforms library or
519 // in some other local environment, but I would like to leave this here
520 // for the moment until I can remove this (Jug 20020418)
521 if (y_before < bv_->text->cursor.y())
522 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
524 // This is to allow jumping over large insets
525 if (cursorrow == bv_->text->cursor.row()) {
526 if (y >= int(workarea().workHeight())) {
527 bv_->text->cursorDown(bv_, false);
529 bv_->text->cursorUp(bv_, false);
533 if (!bv_->text->selection.set())
534 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
536 bv_->text->setSelection(bv_);
537 screen().toggleToggle(bv_->text, bv_);
543 // Single-click on work area
544 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
545 mouse_button::state button)
550 // ok ok, this is a hack (for xforms)
551 if (button == mouse_button::button4) {
552 scroll(-lyxrc.wheel_jump);
553 // We shouldn't go further down as we really should only do the
554 // scrolling and be done with this. Otherwise we may open some
555 // dialogs (Jug 20020424).
557 } else if (button == mouse_button::button5) {
558 scroll(lyxrc.wheel_jump);
559 // We shouldn't go further down as we really should only do the
560 // scrolling and be done with this. Otherwise we may open some
561 // dialogs (Jug 20020424).
565 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
567 // Middle button press pastes if we have a selection
568 // We do this here as if the selection was inside an inset
569 // it could get cleared on the unlocking of the inset so
570 // we have to check this first
571 bool paste_internally = false;
572 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
573 owner_->getLyXFunc()->dispatch(LFUN_COPY);
574 paste_internally = true;
577 int const screen_first = bv_->text->first_y;
579 if (bv_->theLockingInset()) {
580 // We are in inset locking mode
582 /* Check whether the inset was hit. If not reset mode,
583 otherwise give the event to the inset */
584 if (inset_hit == bv_->theLockingInset()) {
585 bv_->theLockingInset()->
586 insetButtonPress(bv_, xpos, ypos, button);
589 bv_->unlockInset(bv_->theLockingInset());
594 selection_possible = true;
595 screen().hideCursor();
597 // Clear the selection
598 screen().toggleSelection(bv_->text, bv_);
599 bv_->text->clearSelection();
600 bv_->text->fullRebreak(bv_);
604 // Single left click in math inset?
605 if (isHighlyEditableInset(inset_hit)) {
606 // Highly editable inset, like math
607 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
608 selection_possible = false;
609 owner_->updateLayoutChoice();
610 owner_->message(inset->editMessage());
611 //inset->edit(bv_, xpos, ypos, button);
612 // We just have to lock the inset before calling a PressEvent on it!
613 // we don't need the edit() call here! (Jug20020329)
614 if (!bv_->lockInset(inset)) {
615 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
617 inset->insetButtonPress(bv_, xpos, ypos, button);
620 // I'm not sure we should continue here if we hit an inset (Jug20020403)
622 // Right click on a footnote flag opens float menu
623 if (button == mouse_button::button3) {
624 selection_possible = false;
628 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
629 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
631 bv_->text->selection.cursor = bv_->text->cursor;
632 bv_->text->cursor.x_fix(bv_->text->cursor.x());
634 owner_->updateLayoutChoice();
636 selection_possible = false;
639 // Insert primary selection with middle mouse
640 // if there is a local selection in the current buffer,
642 if (button == mouse_button::button2) {
643 if (paste_internally)
644 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
646 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
648 selection_possible = false;
654 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
659 LyXText * text = bv_->getLyXText();
661 if (text->bv_owner && bv_->theLockingInset())
664 if (button == mouse_button::button1) {
665 if (text->bv_owner) {
666 screen().hideCursor();
667 screen().toggleSelection(text, bv_);
668 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
669 screen().toggleSelection(text, bv_, false);
671 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
673 /* This will fit the cursor on the screen
675 update(text, BufferView::SELECT|BufferView::FITCUR);
680 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
685 LyXText * text = bv_->getLyXText();
687 if (text->bv_owner && bv_->theLockingInset())
690 if (button == mouse_button::button1) {
691 if (text->bv_owner) {
692 screen().hideCursor();
693 screen().toggleSelection(text, bv_);
695 text->cursorHome(bv_);
696 text->selection.cursor = text->cursor;
697 text->cursorEnd(bv_);
698 text->setSelection(bv_);
699 if (text->bv_owner) {
700 screen().toggleSelection(text, bv_, false);
702 /* This will fit the cursor on the screen
704 update(text, BufferView::SELECT|BufferView::FITCUR);
709 void BufferView::Pimpl::selectionRequested()
716 LyXText * text = bv_->getLyXText();
718 if (text->selection.set() &&
719 (!bv_->text->xsel_cache.set() ||
720 text->selection.start != bv_->text->xsel_cache.start ||
721 text->selection.end != bv_->text->xsel_cache.end))
723 bv_->text->xsel_cache = text->selection;
724 sel = text->selectionAsString(bv_->buffer(), false);
725 } else if (!text->selection.set()) {
727 bv_->text->xsel_cache.set(false);
730 workarea().putClipboard(sel);
735 void BufferView::Pimpl::selectionLost()
740 bv_->getLyXText()->clearSelection();
742 bv_->text->xsel_cache.set(false);
747 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
748 mouse_button::state button)
750 // do nothing if we used the mouse wheel
751 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
754 // If we hit an inset, we have the inset coordinates in these
755 // and inset_hit points to the inset. If we do not hit an
756 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
757 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
759 if (bv_->theLockingInset()) {
760 // We are in inset locking mode.
762 /* LyX does a kind of work-area grabbing for insets.
763 Only a ButtonPress Event outside the inset will
764 force a insetUnlock. */
765 bv_->theLockingInset()->
766 insetButtonRelease(bv_, x, y, button);
770 selection_possible = false;
772 if (button == mouse_button::button2)
776 if (button == mouse_button::button1) {
777 workarea().haveSelection(bv_->getLyXText()->selection.set());
782 owner_->updateMenubar();
783 owner_->updateToolbar();
785 // Did we hit an editable inset?
787 selection_possible = false;
789 // if we reach this point with a selection, it
790 // must mean we are currently selecting.
791 // But we don't want to open the inset
792 // because that is annoying for the user.
793 // So just pretend we didn't hit it.
794 // this is OK because a "kosher" ButtonRelease
795 // will follow a ButtonPress that clears
797 // Note this also fixes selection drawing
798 // problems if we end up opening an inset
799 if (bv_->getLyXText()->selection.set())
802 // CHECK fix this proper in 0.13
803 // well, maybe 13.0 !!!!!!!!!
805 // Following a ref shouldn't issue
806 // a push on the undo-stack
807 // anylonger, now that we have
808 // keybindings for following
809 // references and returning from
810 // references. IMHO though, it
811 // should be the inset's own business
812 // to push or not push on the undo
813 // stack. They don't *have* to
814 // alter the document...
816 // ...or maybe the SetCursorParUndo()
817 // below isn't necessary at all anylonger?
818 if (inset_hit->lyxCode() == Inset::REF_CODE) {
819 setCursorParUndo(bv_);
822 owner_->message(inset_hit->editMessage());
824 if (isHighlyEditableInset(inset_hit)) {
825 // Highly editable inset, like math
826 UpdatableInset *inset = (UpdatableInset *)inset_hit;
827 inset->insetButtonRelease(bv_, x, y, button);
829 inset_hit->insetButtonRelease(bv_, x, y, button);
830 // IMO this is a grosshack! Inset's should be changed so that
831 // they call the actions they have to do with the insetButtonRel.
832 // function and not in the edit(). This should be changed
834 inset_hit->edit(bv_, x, y, button);
839 // Maybe we want to edit a bibitem ale970302
840 if (bv_->text->cursor.par()->bibkey && x < 20 +
841 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
842 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
849 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
850 LyXCursor const & cursor) const
852 Paragraph /*const*/ & par = *cursor.par();
853 pos_type const pos = cursor.pos();
855 lyx::Assert(par.getInset(pos));
857 Inset const & inset(*par.getInset(pos));
859 LyXFont const & font = text.getFont(buffer_, &par, pos);
861 int const width = inset.width(bv_, font);
862 int const inset_x = font.isVisibleRightToLeft()
863 ? (cursor.ix() - width) : cursor.ix();
866 inset_x + inset.scroll(),
868 cursor.iy() - inset.ascent(bv_, font),
869 cursor.iy() + inset.descent(bv_, font));
873 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
874 LyXCursor const & cursor,
875 int & x, int & y) const
877 pos_type const pos(cursor.pos());
878 Paragraph /*const*/ & par(*cursor.par());
880 if (pos >= par.size() || !par.isInset(pos)) {
884 Inset /*const*/ * inset = par.getInset(pos);
886 if (!isEditableInset(inset)) {
890 Box b(insetDimensions(text, cursor));
892 if (!b.contained(x, y)) {
893 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
894 << " box " << b << endl;
898 text.setCursor(bv_, &par, pos, true);
901 // The origin of an inset is on the baseline
902 y -= text.cursor.iy();
908 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
910 int y_tmp = y + text->first_y;
913 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
915 Inset * inset(checkInset(*text, cursor, x, y_tmp));
922 // look at previous position
924 if (cursor.pos() == 0) {
929 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
931 inset = checkInset(*text, cursor, x, y_tmp);
939 void BufferView::Pimpl::workAreaExpose()
941 static int work_area_width;
942 static unsigned int work_area_height;
944 bool const widthChange = workarea().workWidth() != work_area_width;
945 bool const heightChange = workarea().workHeight() != work_area_height;
947 // update from work area
948 work_area_width = workarea().workWidth();
949 work_area_height = workarea().workHeight();
952 // The visible LyXView need a resize
953 owner_->view()->resize();
955 // Remove all texts from the textcache
956 // This is not _really_ what we want to do. What
957 // we really want to do is to delete in textcache
958 // that does not have a BufferView with matching
959 // width, but as long as we have only one BufferView
960 // deleting all gives the same result.
961 if (lyxerr.debugging())
962 textcache.show(lyxerr, "Expose delete all");
964 buffer_->resizeInsets(bv_);
965 } else if (heightChange) {
966 // Rebuild image of current screen
968 // fitCursor() ensures we don't jump back
969 // to the start of the document on vertical
973 // The main window size has changed, repaint most stuff
976 screen().redraw(bv_->text, bv_);
979 // Grey box when we don't have a buffer
980 workarea().greyOut();
983 // always make sure that the scrollbar is sane.
985 owner_->updateLayoutChoice();
990 void BufferView::Pimpl::update()
992 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
993 LyXText::text_status st = bv_->text->status();
994 screen().update(bv_->text, bv_);
996 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
997 bv_->text->fullRebreak(bv_);
998 st = LyXText::NEED_MORE_REFRESH;
999 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1000 bv_->text->cursor.pos());
1001 if (bv_->text->selection.set()) {
1002 bv_->text->setCursor(bv_, bv_->text->selection.start,
1003 bv_->text->selection.start.par(),
1004 bv_->text->selection.start.pos());
1005 bv_->text->setCursor(bv_, bv_->text->selection.end,
1006 bv_->text->selection.end.par(),
1007 bv_->text->selection.end.pos());
1010 bv_->text->status(bv_, st);
1011 screen().update(bv_->text, bv_);
1013 // do this here instead of in the screen::update because of
1015 bv_->text->status(bv_, LyXText::UNCHANGED);
1021 // Values used when calling update:
1023 // -2 - update, move sel_cursor if selection, fitcursor
1024 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1025 // 0 - update, move sel_cursor if selection, fitcursor
1026 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1027 // 3 - update, move sel_cursor if selection
1030 // a simple redraw of the parts that need refresh
1032 // move sel_cursor if selection -
1033 // the text's sel_cursor is moved if there is selection is progress
1036 // fitCursor() is called and the scrollbar updated
1039 // the buffer is marked dirty.
1048 // UPDATE_ONLY = UPDATE;
1049 // UPDATE_SELECT = UPDATE | SELECT;
1050 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1051 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1053 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1054 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1055 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1056 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1057 // update(3) -> update(1) -> update(1) -> update(SELECT)
1059 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1061 owner_->updateLayoutChoice();
1063 if (!text->selection.set() && (f & SELECT)) {
1064 text->selection.cursor = text->cursor;
1067 text->fullRebreak(bv_);
1069 if (text->inset_owner) {
1070 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1071 updateInset(text->inset_owner, false);
1081 buffer_->markDirty();
1086 // Callback for cursor timer
1087 void BufferView::Pimpl::cursorToggle()
1090 cursor_timeout.restart();
1095 extern void reapSpellchecker(void);
1098 if (!bv_->theLockingInset()) {
1099 screen().cursorToggle(bv_);
1101 bv_->theLockingInset()->toggleInsetCursor(bv_);
1104 cursor_timeout.restart();
1108 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1110 if (!text->cursor.row()->previous()) {
1111 if (text->first_y > 0) {
1112 int new_y = bv_->text->first_y - workarea().workHeight();
1113 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1119 int y = text->first_y;
1120 Row * cursorrow = text->cursor.row();
1122 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1126 if (cursorrow == bv_->text->cursor.row()) {
1127 // we have a row which is higher than the workarea so we leave the
1128 // cursor on the start of the row and move only the draw up as soon
1129 // as we move the cursor or do something while inside the row (it may
1130 // span several workarea-heights) we'll move to the top again, but this
1131 // is better than just jump down and only display part of the row.
1132 new_y = bv_->text->first_y - workarea().workHeight();
1134 if (text->inset_owner) {
1135 new_y = bv_->text->cursor.iy()
1136 + bv_->theLockingInset()->insetInInsetY() + y
1137 + text->cursor.row()->height()
1138 - workarea().workHeight() + 1;
1140 new_y = text->cursor.y()
1141 - text->cursor.row()->baseline()
1142 + text->cursor.row()->height()
1143 - workarea().workHeight() + 1;
1146 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1147 if (text->cursor.row()->previous()) {
1149 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1150 text->cursor.row()->previous()->pos(), false);
1151 if (cur.y() > text->first_y) {
1152 text->cursorUp(bv_, true);
1159 void BufferView::Pimpl::cursorNext(LyXText * text)
1161 if (!text->cursor.row()->next()) {
1162 int y = text->cursor.y() - text->cursor.row()->baseline() +
1163 text->cursor.row()->height();
1164 if (y > int(text->first_y + workarea().workHeight())) {
1165 screen().draw(bv_->text, bv_,
1166 bv_->text->first_y + workarea().workHeight());
1172 int y = text->first_y + workarea().workHeight();
1173 if (text->inset_owner && !text->first_y) {
1174 y -= (bv_->text->cursor.iy()
1175 - bv_->text->first_y
1176 + bv_->theLockingInset()->insetInInsetY());
1179 text->getRowNearY(y);
1181 Row * cursorrow = text->cursor.row();
1182 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1186 if (cursorrow == bv_->text->cursor.row()) {
1187 // we have a row which is higher than the workarea so we leave the
1188 // cursor on the start of the row and move only the draw down as soon
1189 // as we move the cursor or do something while inside the row (it may
1190 // span several workarea-heights) we'll move to the top again, but this
1191 // is better than just jump down and only display part of the row.
1192 new_y = bv_->text->first_y + workarea().workHeight();
1194 if (text->inset_owner) {
1195 new_y = bv_->text->cursor.iy()
1196 + bv_->theLockingInset()->insetInInsetY()
1197 + y - text->cursor.row()->baseline();
1199 new_y = text->cursor.y() - text->cursor.row()->baseline();
1202 screen().draw(bv_->text, bv_, new_y);
1203 if (text->cursor.row()->next()) {
1205 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1206 text->cursor.row()->next()->pos(), false);
1207 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1208 text->cursorDown(bv_, true);
1215 bool BufferView::Pimpl::available() const
1217 if (buffer_ && bv_->text)
1223 void BufferView::Pimpl::beforeChange(LyXText * text)
1226 text->clearSelection();
1230 void BufferView::Pimpl::savePosition(unsigned int i)
1232 if (i >= saved_positions_num)
1234 saved_positions[i] = Position(buffer_->fileName(),
1235 bv_->text->cursor.par()->id(),
1236 bv_->text->cursor.pos());
1239 str << _("Saved bookmark") << ' ' << i;
1240 owner_->message(str.str().c_str());
1245 void BufferView::Pimpl::restorePosition(unsigned int i)
1247 if (i >= saved_positions_num)
1250 string const fname = saved_positions[i].filename;
1252 beforeChange(bv_->text);
1254 if (fname != buffer_->fileName()) {
1255 Buffer * b = bufferlist.exists(fname) ?
1256 bufferlist.getBuffer(fname) :
1257 bufferlist.loadLyXFile(fname); // don't ask, just load it
1258 if (b != 0) buffer(b);
1261 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1265 bv_->text->setCursor(bv_, par,
1266 min(par->size(), saved_positions[i].par_pos));
1268 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1271 str << _("Moved to bookmark") << ' ' << i;
1272 owner_->message(str.str().c_str());
1277 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1279 if (i >= saved_positions_num)
1282 return !saved_positions[i].filename.empty();
1286 void BufferView::Pimpl::setState()
1288 if (!lyxrc.rtl_support)
1291 LyXText * text = bv_->getLyXText();
1292 if (text->real_current_font.isRightToLeft()
1293 && !(bv_->theLockingInset()
1294 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1296 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1297 owner_->getIntl()->KeyMapSec();
1299 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1300 owner_->getIntl()->KeyMapPrim();
1305 void BufferView::Pimpl::insetUnlock()
1307 if (bv_->theLockingInset()) {
1308 bv_->theLockingInset()->insetUnlock(bv_);
1309 bv_->theLockingInset(0);
1315 bool BufferView::Pimpl::focus() const
1317 return workarea().hasFocus();
1321 void BufferView::Pimpl::focus(bool f)
1323 if (f) workarea().setFocus();
1327 void BufferView::Pimpl::showCursor()
1329 if (bv_->theLockingInset())
1330 bv_->theLockingInset()->showInsetCursor(bv_);
1332 screen().showCursor(bv_->text, bv_);
1336 void BufferView::Pimpl::hideCursor()
1338 if (!bv_->theLockingInset())
1339 screen().hideCursor();
1343 void BufferView::Pimpl::toggleSelection(bool b)
1345 if (bv_->theLockingInset())
1346 bv_->theLockingInset()->toggleSelection(bv_, b);
1347 screen().toggleSelection(bv_->text, bv_, b);
1351 void BufferView::Pimpl::toggleToggle()
1353 screen().toggleToggle(bv_->text, bv_);
1357 void BufferView::Pimpl::center()
1359 beforeChange(bv_->text);
1360 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1361 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1363 screen().draw(bv_->text, bv_, 0);
1365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1370 void BufferView::Pimpl::pasteClipboard(bool asPara)
1375 screen().hideCursor();
1376 beforeChange(bv_->text);
1378 string const clip(workarea().getClipboard());
1384 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1386 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1388 bv_->getLyXText()->clearSelection();
1389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1393 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1395 workarea().putClipboard(stuff);
1400 * Dispatch functions for actions which can be valid for BufferView->text
1401 * and/or InsetText->text!!!
1406 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1408 LyXText * lt = bv_->getLyXText();
1410 if (selecting || lt->selection.mark()) {
1411 lt->setSelection(bv_);
1415 updateInset(lt->inset_owner, false);
1419 update(lt, BufferView::SELECT|BufferView::FITCUR);
1421 update(lt, BufferView::SELECT);
1423 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1424 bv_->theLockingInset()->hideInsetCursor(bv_);
1425 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1429 if (!lt->selection.set())
1430 workarea().haveSelection(false);
1432 /* ---> Everytime the cursor is moved, show the current font state. */
1433 // should this too me moved out of this func?
1434 //owner->showState();
1439 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1441 LyXCursor cursor = bv_->getLyXText()->cursor;
1442 Buffer::inset_iterator it =
1443 find_if(Buffer::inset_iterator(
1444 cursor.par(), cursor.pos()),
1445 buffer_->inset_iterator_end(),
1446 lyx::compare_memfun(&Inset::lyxCode, code));
1447 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1451 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1453 string filename = filen;
1455 if (filename.empty()) {
1456 // Launch a file browser
1457 string initpath = lyxrc.document_path;
1460 string const trypath = owner_->buffer()->filePath();
1461 // If directory is writeable, use this as default.
1462 if (IsDirWriteable(trypath))
1466 FileDialog fileDlg(bv_->owner(),
1467 _("Select LyX document to insert"),
1469 make_pair(string(_("Documents|#o#O")),
1470 string(lyxrc.document_path)),
1471 make_pair(string(_("Examples|#E#e")),
1472 string(AddPath(system_lyxdir, "examples"))));
1474 FileDialog::Result result =
1475 fileDlg.Select(initpath,
1476 _("*.lyx| LyX Documents (*.lyx)"));
1478 if (result.first == FileDialog::Later)
1481 filename = result.second;
1483 // check selected filename
1484 if (filename.empty()) {
1485 owner_->message(_("Canceled."));
1490 // get absolute path of file and add ".lyx" to the filename if
1492 filename = FileSearch(string(), filename, "lyx");
1494 string const disp_fn(MakeDisplayPath(filename));
1497 s1 << _("Inserting document") << ' '
1498 << disp_fn << " ...";
1499 owner_->message(s1.str().c_str());
1500 bool const res = bv_->insertLyXFile(filename);
1503 str << _("Document") << ' ' << disp_fn
1504 << ' ' << _("inserted.");
1505 owner_->message(str.str().c_str());
1508 str << _("Could not insert document") << ' '
1510 owner_->message(str.str().c_str());
1515 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1517 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1518 << action <<"] arg[" << argument << "]" << endl;
1520 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1523 // --- Misc -------------------------------------------
1527 LyXText * lt = bv_->getLyXText();
1528 lt->toggleAppendix(bv_);
1531 | BufferView::FITCUR
1532 | BufferView::CHANGE);
1537 case LFUN_TOC_INSERT:
1539 InsetCommandParams p;
1540 p.setCmdName("tableofcontents");
1541 Inset * inset = new InsetTOC(p);
1542 if (!insertInset(inset, tclass.defaultLayoutName()))
1547 case LFUN_SCROLL_INSET:
1548 // this is not handled here as this funktion is only aktive
1549 // if we have a locking_inset and that one is (or contains)
1553 case LFUN_INSET_GRAPHICS:
1555 Inset * new_inset = new InsetGraphics;
1556 if (!insertInset(new_inset)) {
1559 // this is need because you don't use a inset->Edit()
1560 updateInset(new_inset, true);
1561 new_inset->edit(bv_);
1571 case LFUN_PASTESELECTION:
1573 bool asPara = false;
1574 if (argument == "paragraph")
1576 pasteClipboard(asPara);
1588 case LFUN_LAYOUT_COPY:
1589 bv_->copyEnvironment();
1592 case LFUN_LAYOUT_PASTE:
1593 bv_->pasteEnvironment();
1597 case LFUN_GOTOERROR:
1598 gotoInset(Inset::ERROR_CODE, false);
1602 gotoInset(Inset::IGNORE_CODE, false);
1605 case LFUN_REFERENCE_GOTO:
1607 vector<Inset::Code> tmp;
1608 tmp.push_back(Inset::LABEL_CODE);
1609 tmp.push_back(Inset::REF_CODE);
1610 gotoInset(tmp, true);
1614 case LFUN_HYPHENATION:
1615 specialChar(InsetSpecialChar::HYPHENATION);
1618 case LFUN_LIGATURE_BREAK:
1619 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1623 specialChar(InsetSpecialChar::LDOTS);
1626 case LFUN_END_OF_SENTENCE:
1627 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1630 case LFUN_MENU_SEPARATOR:
1631 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1638 case LFUN_DEPTH_MIN:
1639 changeDepth(bv_, bv_->getLyXText(), -1);
1642 case LFUN_DEPTH_PLUS:
1643 changeDepth(bv_, bv_->getLyXText(), 1);
1647 owner_->getDialogs()->setUserFreeFont();
1650 case LFUN_FILE_INSERT:
1651 MenuInsertLyXFile(argument);
1654 case LFUN_FILE_INSERT_ASCII_PARA:
1655 InsertAsciiFile(bv_, argument, true);
1658 case LFUN_FILE_INSERT_ASCII:
1659 InsertAsciiFile(bv_, argument, false);
1664 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1665 << argument << endl;
1667 // This is not the good solution to the empty argument
1668 // problem, but it will hopefully suffice for 1.2.0.
1669 // The correct solution would be to augument the
1670 // function list/array with information about what
1671 // functions needs arguments and their type.
1672 if (argument.empty()) {
1673 owner_->getLyXFunc()->setErrorMessage(
1674 _("LyX function 'layout' needs an argument."));
1678 // Derive layout number from given argument (string)
1679 // and current buffer's textclass (number). */
1680 bool hasLayout = tclass.hasLayout(argument);
1681 string layout = argument;
1683 // If the entry is obsolete, use the new one instead.
1685 string const & obs = tclass[layout].obsoleted_by();
1691 owner_->getLyXFunc()->setErrorMessage(
1692 string(N_("Layout ")) + argument +
1697 bool change_layout = (current_layout != layout);
1698 LyXText * lt = bv_->getLyXText();
1699 if (!change_layout && lt->selection.set() &&
1700 lt->selection.start.par() != lt->selection.end.par())
1702 Paragraph * spar = lt->selection.start.par();
1703 Paragraph * epar = lt->selection.end.par()->next();
1704 while(spar != epar) {
1705 if (spar->layout() != current_layout) {
1706 change_layout = true;
1711 if (change_layout) {
1713 current_layout = layout;
1716 | BufferView::FITCUR);
1717 lt->setLayout(bv_, layout);
1718 owner_->setLayout(layout);
1721 | BufferView::FITCUR
1722 | BufferView::CHANGE);
1729 lang(bv_, argument);
1731 owner_->showState();
1736 owner_->showState();
1741 owner_->showState();
1746 owner_->showState();
1751 owner_->showState();
1756 owner_->showState();
1761 owner_->showState();
1766 owner_->showState();
1769 case LFUN_UNDERLINE:
1771 owner_->showState();
1774 case LFUN_FONT_SIZE:
1775 fontSize(bv_, argument);
1776 owner_->showState();
1779 case LFUN_FONT_STATE:
1780 owner_->getLyXFunc()->setMessage(currentState(bv_));
1783 case LFUN_UPCASE_WORD:
1785 LyXText * lt = bv_->getLyXText();
1789 | BufferView::FITCUR);
1790 lt->changeCase(bv_, LyXText::text_uppercase);
1791 if (lt->inset_owner)
1792 updateInset(lt->inset_owner, true);
1795 | BufferView::FITCUR
1796 | BufferView::CHANGE);
1800 case LFUN_LOWCASE_WORD:
1802 LyXText * lt = bv_->getLyXText();
1804 update(lt, BufferView::SELECT|BufferView::FITCUR);
1805 lt->changeCase(bv_, LyXText::text_lowercase);
1806 if (lt->inset_owner)
1807 updateInset(lt->inset_owner, true);
1810 | BufferView::FITCUR
1811 | BufferView::CHANGE);
1815 case LFUN_CAPITALIZE_WORD:
1817 LyXText * lt = bv_->getLyXText();
1819 update(lt, BufferView::SELECT|BufferView::FITCUR);
1820 lt->changeCase(bv_, LyXText::text_capitalization);
1821 if (lt->inset_owner)
1822 updateInset(lt->inset_owner, true);
1825 | BufferView::FITCUR
1826 | BufferView::CHANGE);
1830 case LFUN_TRANSPOSE_CHARS:
1832 LyXText * lt = bv_->getLyXText();
1834 update(lt, BufferView::SELECT|BufferView::FITCUR);
1835 lt->transposeChars(*bv_);
1836 if (lt->inset_owner)
1837 updateInset(lt->inset_owner, true);
1840 | BufferView::FITCUR
1841 | BufferView::CHANGE);
1846 case LFUN_INSERT_LABEL:
1847 MenuInsertLabel(bv_, argument);
1850 case LFUN_REF_INSERT:
1851 if (argument.empty()) {
1852 InsetCommandParams p("ref");
1853 owner_->getDialogs()->createRef(p.getAsString());
1855 InsetCommandParams p;
1856 p.setFromString(argument);
1858 InsetRef * inset = new InsetRef(p, *buffer_);
1859 if (!insertInset(inset))
1862 updateInset(inset, true);
1866 case LFUN_BOOKMARK_SAVE:
1867 savePosition(strToUnsignedInt(argument));
1870 case LFUN_BOOKMARK_GOTO:
1871 restorePosition(strToUnsignedInt(argument));
1876 string label(argument);
1877 if (label.empty()) {
1879 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1881 label = inset->getContents();
1886 if (!label.empty()) {
1887 //bv_->savePosition(0);
1888 if (!bv_->gotoLabel(label))
1889 Alert::alert(_("Error"),
1890 _("Couldn't find this label"),
1891 _("in current document."));
1896 // --- Cursor Movements -----------------------------
1899 LyXText * lt = bv_->getLyXText();
1901 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1902 if (!lt->selection.mark())
1904 update(lt, BufferView::SELECT|BufferView::FITCUR);
1906 lt->cursorLeft(bv_, false);
1907 if (lt->cursor.pos() < lt->cursor.par()->size()
1908 && lt->cursor.par()->isInset(lt->cursor.pos())
1909 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1910 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1911 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1913 tmpinset->edit(bv_, false);
1915 tmpinset->edit(bv_);
1919 lt->cursorRight(bv_, false);
1921 moveCursorUpdate(false);
1922 owner_->showState();
1928 // This is soooo ugly. Isn`t it possible to make
1929 // it simpler? (Lgb)
1930 LyXText * lt = bv_->getLyXText();
1931 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1932 if (!lt->selection.mark())
1934 update(lt, BufferView::SELECT|BufferView::FITCUR);
1935 LyXCursor const cur = lt->cursor;
1937 lt->cursorLeft(bv_, false);
1938 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1939 lt->cursor.pos() < lt->cursor.par()->size() &&
1940 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1941 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1942 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1943 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1945 tmpinset->edit(bv_);
1947 tmpinset->edit(bv_, false);
1951 lt->cursorRight(bv_, false);
1954 moveCursorUpdate(false);
1955 owner_->showState();
1961 LyXText * lt = bv_->getLyXText();
1963 if (!lt->selection.mark())
1965 update(lt, BufferView::UPDATE);
1968 moveCursorUpdate(false);
1969 owner_->showState();
1975 LyXText * lt = bv_->getLyXText();
1977 if (!lt->selection.mark())
1979 update(lt, BufferView::UPDATE);
1980 lt->cursorDown(bv_);
1982 moveCursorUpdate(false);
1983 owner_->showState();
1987 case LFUN_UP_PARAGRAPH:
1989 LyXText * lt = bv_->getLyXText();
1991 if (!lt->selection.mark())
1993 update(lt, BufferView::UPDATE);
1994 lt->cursorUpParagraph(bv_);
1996 moveCursorUpdate(false);
1997 owner_->showState();
2001 case LFUN_DOWN_PARAGRAPH:
2003 LyXText * lt = bv_->getLyXText();
2005 if (!lt->selection.mark())
2007 update(lt, BufferView::UPDATE);
2008 lt->cursorDownParagraph(bv_);
2010 moveCursorUpdate(false);
2011 owner_->showState();
2017 LyXText * lt = bv_->getLyXText();
2019 if (!lt->selection.mark())
2021 update(lt, BufferView::UPDATE);
2024 moveCursorUpdate(false, false);
2025 owner_->showState();
2031 LyXText * lt = bv_->getLyXText();
2033 if (!lt->selection.mark())
2035 update(lt, BufferView::UPDATE);
2038 moveCursorUpdate(false, false);
2039 owner_->showState();
2045 LyXText * lt = bv_->getLyXText();
2047 if (!lt->selection.mark())
2049 update(lt, BufferView::SELECT|BufferView::FITCUR);
2050 lt->cursorHome(bv_);
2052 moveCursorUpdate(false);
2053 owner_->showState();
2059 LyXText * lt = bv_->getLyXText();
2061 if (!lt->selection.mark())
2064 BufferView::SELECT|BufferView::FITCUR);
2067 moveCursorUpdate(false);
2068 owner_->showState();
2072 case LFUN_SHIFT_TAB:
2075 LyXText * lt = bv_->getLyXText();
2077 if (!lt->selection.mark())
2080 BufferView::SELECT|BufferView::FITCUR);
2083 moveCursorUpdate(false);
2084 owner_->showState();
2088 case LFUN_WORDRIGHT:
2090 LyXText * lt = bv_->getLyXText();
2092 if (!lt->selection.mark())
2094 update(lt, BufferView::SELECT|BufferView::FITCUR);
2095 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2096 lt->cursorLeftOneWord(bv_);
2098 lt->cursorRightOneWord(bv_);
2100 moveCursorUpdate(false);
2101 owner_->showState();
2107 LyXText * lt = bv_->getLyXText();
2109 if (!lt->selection.mark())
2111 update(lt, BufferView::SELECT|BufferView::FITCUR);
2112 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2113 lt->cursorRightOneWord(bv_);
2115 lt->cursorLeftOneWord(bv_);
2117 moveCursorUpdate(false);
2118 owner_->showState();
2122 case LFUN_BEGINNINGBUF:
2124 LyXText * lt = bv_->getLyXText();
2126 if (!lt->selection.mark())
2129 BufferView::SELECT|BufferView::FITCUR);
2132 moveCursorUpdate(false);
2133 owner_->showState();
2139 LyXText * lt = bv_->getLyXText();
2141 if (!lt->selection.mark())
2144 BufferView::SELECT|BufferView::FITCUR);
2145 lt->cursorBottom(bv_);
2147 moveCursorUpdate(false);
2148 owner_->showState();
2152 /* cursor selection ---------------------------- */
2155 LyXText * lt = bv_->getLyXText();
2158 BufferView::SELECT|BufferView::FITCUR);
2159 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2160 lt->cursorLeft(bv_);
2162 lt->cursorRight(bv_);
2164 moveCursorUpdate(true);
2165 owner_->showState();
2171 LyXText * lt = bv_->getLyXText();
2174 BufferView::SELECT|BufferView::FITCUR);
2175 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2176 lt->cursorRight(bv_);
2178 lt->cursorLeft(bv_);
2180 moveCursorUpdate(true);
2181 owner_->showState();
2187 LyXText * lt = bv_->getLyXText();
2190 BufferView::SELECT|BufferView::FITCUR);
2191 lt->cursorUp(bv_, true);
2193 moveCursorUpdate(true);
2194 owner_->showState();
2200 LyXText * lt = bv_->getLyXText();
2203 BufferView::SELECT|BufferView::FITCUR);
2204 lt->cursorDown(bv_, true);
2206 moveCursorUpdate(true);
2207 owner_->showState();
2211 case LFUN_UP_PARAGRAPHSEL:
2213 LyXText * lt = bv_->getLyXText();
2216 BufferView::SELECT|BufferView::FITCUR);
2217 lt->cursorUpParagraph(bv_);
2219 moveCursorUpdate(true);
2220 owner_->showState();
2224 case LFUN_DOWN_PARAGRAPHSEL:
2226 LyXText * lt = bv_->getLyXText();
2229 BufferView::SELECT|BufferView::FITCUR);
2230 lt->cursorDownParagraph(bv_);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2244 moveCursorUpdate(true);
2245 owner_->showState();
2251 LyXText * lt = bv_->getLyXText();
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2256 moveCursorUpdate(true);
2257 owner_->showState();
2263 LyXText * lt = bv_->getLyXText();
2265 update(lt, BufferView::SELECT|BufferView::FITCUR);
2266 lt->cursorHome(bv_);
2268 moveCursorUpdate(true);
2269 owner_->showState();
2275 LyXText * lt = bv_->getLyXText();
2277 update(lt, BufferView::SELECT|BufferView::FITCUR);
2280 moveCursorUpdate(true);
2281 owner_->showState();
2285 case LFUN_WORDRIGHTSEL:
2287 LyXText * lt = bv_->getLyXText();
2289 update(lt, BufferView::SELECT|BufferView::FITCUR);
2290 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2291 lt->cursorLeftOneWord(bv_);
2293 lt->cursorRightOneWord(bv_);
2295 moveCursorUpdate(true);
2296 owner_->showState();
2300 case LFUN_WORDLEFTSEL:
2302 LyXText * lt = bv_->getLyXText();
2304 update(lt, BufferView::SELECT|BufferView::FITCUR);
2305 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2306 lt->cursorRightOneWord(bv_);
2308 lt->cursorLeftOneWord(bv_);
2310 moveCursorUpdate(true);
2311 owner_->showState();
2315 case LFUN_BEGINNINGBUFSEL:
2317 LyXText * lt = bv_->getLyXText();
2319 if (lt->inset_owner)
2321 update(lt, BufferView::SELECT|BufferView::FITCUR);
2324 moveCursorUpdate(true);
2325 owner_->showState();
2329 case LFUN_ENDBUFSEL:
2331 LyXText * lt = bv_->getLyXText();
2333 if (lt->inset_owner)
2336 BufferView::SELECT|BufferView::FITCUR);
2337 lt->cursorBottom(bv_);
2339 moveCursorUpdate(true);
2340 owner_->showState();
2344 // --- text changing commands ------------------------
2345 case LFUN_BREAKLINE:
2347 LyXText * lt = bv_->getLyXText();
2350 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2353 | BufferView::FITCUR
2354 | BufferView::CHANGE);
2355 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2356 moveCursorUpdate(false);
2360 case LFUN_PROTECTEDSPACE:
2362 LyXText * lt = bv_->getLyXText();
2364 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2366 if (style.free_spacing) {
2367 lt->insertChar(bv_, ' ');
2370 | BufferView::FITCUR
2371 | BufferView::CHANGE);
2373 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2375 moveCursorUpdate(false);
2381 LyXText * lt = bv_->getLyXText();
2383 if (lt->selection.mark()) {
2387 | BufferView::FITCUR);
2388 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2391 lt->selection.mark(true);
2394 | BufferView::FITCUR);
2395 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2397 lt->selection.cursor = lt->cursor;
2403 LyXText * lt = bv_->getLyXText();
2405 if (!lt->selection.set()) {
2407 lt->selection.cursor = lt->cursor;
2410 | BufferView::FITCUR
2411 | BufferView::CHANGE);
2412 // It is possible to make it a lot faster still
2413 // just comment out the line below...
2418 moveCursorUpdate(false);
2419 owner_->showState();
2424 case LFUN_DELETE_SKIP:
2426 LyXText * lt = bv_->getLyXText();
2428 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2430 LyXCursor cursor = lt->cursor;
2432 if (!lt->selection.set()) {
2433 if (cursor.pos() == cursor.par()->size()) {
2434 lt->cursorRight(bv_);
2435 cursor = lt->cursor;
2436 if (cursor.pos() == 0
2437 && !(cursor.par()->params().spaceTop()
2438 == VSpace (VSpace::NONE))) {
2441 cursor.par()->params().lineTop(),
2442 cursor.par()->params().lineBottom(),
2443 cursor.par()->params().pagebreakTop(),
2444 cursor.par()->params().pagebreakBottom(),
2445 VSpace(VSpace::NONE),
2446 cursor.par()->params().spaceBottom(),
2447 cursor.par()->params().spacing(),
2448 cursor.par()->params().align(),
2449 cursor.par()->params().labelWidthString(), 0);
2450 lt->cursorLeft(bv_);
2453 | BufferView::FITCUR
2454 | BufferView::CHANGE);
2456 lt->cursorLeft(bv_);
2458 lt->selection.cursor = lt->cursor;
2461 | BufferView::FITCUR
2462 | BufferView::CHANGE);
2466 lt->selection.cursor = lt->cursor;
2469 | BufferView::FITCUR
2470 | BufferView::CHANGE);
2478 /* -------> Delete word forward. */
2479 case LFUN_DELETE_WORD_FORWARD:
2480 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2481 bv_->getLyXText()->deleteWordForward(bv_);
2482 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2483 moveCursorUpdate(false);
2484 owner_->showState();
2487 /* -------> Delete word backward. */
2488 case LFUN_DELETE_WORD_BACKWARD:
2490 LyXText * lt = bv_->getLyXText();
2492 update(lt, BufferView::SELECT|BufferView::FITCUR);
2493 lt->deleteWordBackward(bv_);
2496 | BufferView::FITCUR
2497 | BufferView::CHANGE);
2498 moveCursorUpdate(false);
2499 owner_->showState();
2503 /* -------> Kill to end of line. */
2504 case LFUN_DELETE_LINE_FORWARD:
2506 LyXText * lt = bv_->getLyXText();
2508 update(lt, BufferView::SELECT|BufferView::FITCUR);
2509 lt->deleteLineForward(bv_);
2512 | BufferView::FITCUR
2513 | BufferView::CHANGE);
2514 moveCursorUpdate(false);
2518 /* -------> Set mark off. */
2521 LyXText * lt = bv_->getLyXText();
2524 update(lt, BufferView::SELECT|BufferView::FITCUR);
2525 lt->selection.cursor = lt->cursor;
2526 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2530 /* -------> Set mark on. */
2533 LyXText * lt = bv_->getLyXText();
2536 lt->selection.mark(true);
2537 update(lt, BufferView::SELECT|BufferView::FITCUR);
2538 lt->selection.cursor = lt->cursor;
2539 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2543 case LFUN_BACKSPACE:
2545 LyXText * lt = bv_->getLyXText();
2547 if (!lt->selection.set()) {
2548 if (owner_->getIntl()->getTrans().backspace()) {
2550 lt->selection.cursor = lt->cursor;
2553 | BufferView::FITCUR
2554 | BufferView::CHANGE);
2555 // It is possible to make it a lot faster still
2556 // just comment out the line below...
2562 owner_->showState();
2567 case LFUN_BACKSPACE_SKIP:
2569 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2570 LyXText * lt = bv_->getLyXText();
2572 LyXCursor cursor = lt->cursor;
2574 if (!lt->selection.set()) {
2575 if (cursor.pos() == 0
2576 && !(cursor.par()->params().spaceTop()
2577 == VSpace (VSpace::NONE))) {
2580 cursor.par()->params().lineTop(),
2581 cursor.par()->params().lineBottom(),
2582 cursor.par()->params().pagebreakTop(),
2583 cursor.par()->params().pagebreakBottom(),
2584 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2585 cursor.par()->params().spacing(),
2586 cursor.par()->params().align(),
2587 cursor.par()->params().labelWidthString(), 0);
2590 | BufferView::FITCUR
2591 | BufferView::CHANGE);
2594 lt->selection.cursor = cursor;
2597 | BufferView::FITCUR
2598 | BufferView::CHANGE);
2605 case LFUN_BREAKPARAGRAPH:
2607 LyXText * lt = bv_->getLyXText();
2610 lt->breakParagraph(bv_, 0);
2613 | BufferView::FITCUR
2614 | BufferView::CHANGE);
2615 lt->selection.cursor = lt->cursor;
2617 owner_->showState();
2621 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2623 LyXText * lt = bv_->getLyXText();
2626 lt->breakParagraph(bv_, 1);
2629 | BufferView::FITCUR
2630 | BufferView::CHANGE);
2631 lt->selection.cursor = lt->cursor;
2633 owner_->showState();
2637 case LFUN_BREAKPARAGRAPH_SKIP:
2639 // When at the beginning of a paragraph, remove
2640 // indentation and add a "defskip" at the top.
2641 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2642 LyXText * lt = bv_->getLyXText();
2644 LyXCursor cursor = lt->cursor;
2647 if (cursor.pos() == 0) {
2648 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2651 cursor.par()->params().lineTop(),
2652 cursor.par()->params().lineBottom(),
2653 cursor.par()->params().pagebreakTop(),
2654 cursor.par()->params().pagebreakBottom(),
2655 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2656 cursor.par()->params().spacing(),
2657 cursor.par()->params().align(),
2658 cursor.par()->params().labelWidthString(), 1);
2659 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2663 lt->breakParagraph(bv_, 0);
2664 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2669 | BufferView::FITCUR
2670 | BufferView::CHANGE);
2671 lt->selection.cursor = cursor;
2673 owner_->showState();
2677 case LFUN_PARAGRAPH_SPACING:
2679 LyXText * lt = bv_->getLyXText();
2681 Paragraph * par = lt->cursor.par();
2682 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2683 float cur_value = 1.0;
2684 if (cur_spacing == Spacing::Other) {
2685 cur_value = par->params().spacing().getValue();
2688 istringstream istr(argument.c_str());
2692 Spacing::Space new_spacing = cur_spacing;
2693 float new_value = cur_value;
2695 lyxerr << "Missing argument to `paragraph-spacing'"
2697 } else if (tmp == "single") {
2698 new_spacing = Spacing::Single;
2699 } else if (tmp == "onehalf") {
2700 new_spacing = Spacing::Onehalf;
2701 } else if (tmp == "double") {
2702 new_spacing = Spacing::Double;
2703 } else if (tmp == "other") {
2704 new_spacing = Spacing::Other;
2707 lyxerr << "new_value = " << tmpval << endl;
2710 } else if (tmp == "default") {
2711 new_spacing = Spacing::Default;
2713 lyxerr << _("Unknown spacing argument: ")
2714 << argument << endl;
2716 if (cur_spacing != new_spacing || cur_value != new_value) {
2717 par->params().spacing(Spacing(new_spacing, new_value));
2718 lt->redoParagraph(bv_);
2721 | BufferView::FITCUR
2722 | BufferView::CHANGE);
2727 case LFUN_INSET_TOGGLE:
2729 LyXText * lt = bv_->getLyXText();
2732 update(lt, BufferView::SELECT|BufferView::FITCUR);
2733 lt->toggleInset(bv_);
2734 update(lt, BufferView::SELECT|BufferView::FITCUR);
2746 InsetCommandParams p;
2747 if (action == LFUN_HTMLURL)
2748 p.setCmdName("htmlurl");
2750 p.setCmdName("url");
2751 owner_->getDialogs()->createUrl(p.getAsString());
2755 case LFUN_INSERT_URL:
2757 InsetCommandParams p;
2758 p.setFromString(argument);
2760 InsetUrl * inset = new InsetUrl(p);
2761 if (!insertInset(inset))
2764 updateInset(inset, true);
2768 case LFUN_INSET_ERT:
2769 insertAndEditInset(new InsetERT(buffer_->params));
2772 case LFUN_INSET_EXTERNAL:
2773 insertAndEditInset(new InsetExternal);
2776 case LFUN_INSET_FOOTNOTE:
2777 insertAndEditInset(new InsetFoot(buffer_->params));
2780 case LFUN_INSET_MARGINAL:
2781 insertAndEditInset(new InsetMarginal(buffer_->params));
2784 case LFUN_INSET_MINIPAGE:
2785 insertAndEditInset(new InsetMinipage(buffer_->params));
2788 case LFUN_INSERT_NOTE:
2789 insertAndEditInset(new InsetNote(buffer_->params));
2792 case LFUN_INSET_FLOAT:
2793 // check if the float type exist
2794 if (floatList.typeExist(argument)) {
2795 insertAndEditInset(new InsetFloat(buffer_->params,
2798 lyxerr << "Non-existent float type: "
2799 << argument << endl;
2803 case LFUN_INSET_WIDE_FLOAT:
2804 // check if the float type exist
2805 if (floatList.typeExist(argument)) {
2806 InsetFloat * new_inset =
2807 new InsetFloat(buffer_->params, argument);
2808 new_inset->wide(true);
2809 insertAndEditInset(new_inset);
2811 lyxerr << "Non-existent float type: "
2812 << argument << endl;
2817 case LFUN_INSET_LIST:
2818 insertAndEditInset(new InsetList);
2821 case LFUN_INSET_THEOREM:
2822 insertAndEditInset(new InsetTheorem);
2826 case LFUN_INSET_CAPTION:
2828 // Do we have a locking inset...
2829 if (bv_->theLockingInset()) {
2830 lyxerr << "Locking inset code: "
2831 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2832 InsetCaption * new_inset =
2833 new InsetCaption(buffer_->params);
2834 new_inset->setOwner(bv_->theLockingInset());
2835 new_inset->setAutoBreakRows(true);
2836 new_inset->setDrawFrame(0, InsetText::LOCKED);
2837 new_inset->setFrameColor(0, LColor::captionframe);
2838 if (insertInset(new_inset))
2839 new_inset->edit(bv_);
2846 case LFUN_INSET_TABULAR:
2850 if (!argument.empty())
2851 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2852 InsetTabular * new_inset =
2853 new InsetTabular(*buffer_, r, c);
2855 bv_->getLyXText()->real_current_font.isRightToLeft();
2856 if (!open_new_inset(new_inset, rtl))
2861 // --- lyxserver commands ----------------------------
2863 case LFUN_CHARATCURSOR:
2865 pos_type pos = bv_->getLyXText()->cursor.pos();
2866 if (pos < bv_->getLyXText()->cursor.par()->size())
2867 owner_->getLyXFunc()->setMessage(
2868 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2870 owner_->getLyXFunc()->setMessage("EOF");
2875 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2877 + tostr(bv_->getLyXText()->cursor.y()));
2884 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2885 lyxerr << "SETXY: Could not parse coordinates in '"
2886 << argument << std::endl;
2888 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2892 case LFUN_GETLAYOUT:
2893 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2898 LyXFont & font = bv_->getLyXText()->current_font;
2899 if (font.shape() == LyXFont::ITALIC_SHAPE)
2900 owner_->getLyXFunc()->setMessage("E");
2901 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2902 owner_->getLyXFunc()->setMessage("N");
2904 owner_->getLyXFunc()->setMessage("0");
2909 // --- accented characters ---------------------------
2912 case LFUN_CIRCUMFLEX:
2922 case LFUN_SPECIAL_CARON:
2925 case LFUN_HUNG_UMLAUT:
2928 if (argument.empty()) {
2930 owner_->getLyXFunc()->handleKeyFunc(action);
2932 owner_->getLyXFunc()->handleKeyFunc(action);
2933 owner_->getIntl()->getTrans()
2934 .TranslateAndInsert(argument[0], bv_->getLyXText());
2935 update(bv_->getLyXText(),
2937 | BufferView::FITCUR
2938 | BufferView::CHANGE);
2942 case LFUN_MATH_MACRO:
2943 mathDispatchMathMacro(bv_, argument);
2946 case LFUN_MATH_DELIM:
2947 mathDispatchMathDelim(bv_, argument);
2950 case LFUN_INSERT_MATRIX:
2951 mathDispatchInsertMatrix(bv_, argument);
2954 case LFUN_INSERT_MATH:
2955 mathDispatchInsertMath(bv_, argument);
2958 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2959 mathDispatchMathImportSelection(bv_, argument);
2962 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2963 mathDispatchMathDisplay(bv_, argument);
2966 case LFUN_MATH_MODE: // Open or create an inlined math inset
2967 mathDispatchMathMode(bv_, argument);
2970 case LFUN_GREEK: // Insert a single greek letter
2971 mathDispatchGreek(bv_, argument);
2974 case LFUN_CITATION_INSERT:
2976 InsetCommandParams p;
2977 p.setFromString(argument);
2979 InsetCitation * inset = new InsetCitation(p);
2980 if (!insertInset(inset))
2983 updateInset(inset, true);
2987 case LFUN_INSERT_BIBTEX:
2989 // ale970405+lasgoutt970425
2990 // The argument can be up to two tokens separated
2991 // by a space. The first one is the bibstyle.
2992 string const db = token(argument, ' ', 0);
2993 string const bibstyle = token(argument, ' ', 1);
2995 InsetCommandParams p("BibTeX", db, bibstyle);
2996 InsetBibtex * inset = new InsetBibtex(p);
2998 if (insertInset(inset)) {
2999 if (argument.empty())
3006 // BibTeX data bases
3007 case LFUN_BIBDB_ADD:
3009 InsetBibtex * inset =
3010 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3012 inset->addDatabase(argument);
3017 case LFUN_BIBDB_DEL:
3019 InsetBibtex * inset =
3020 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3022 inset->delDatabase(argument);
3027 case LFUN_BIBTEX_STYLE:
3029 InsetBibtex * inset =
3030 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3032 inset->setOptions(argument);
3037 case LFUN_INDEX_CREATE:
3039 InsetCommandParams p("index");
3040 if (argument.empty()) {
3041 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3042 p.setContents(idxstring);
3044 p.setContents(argument);
3047 owner_->getDialogs()->createIndex(p.getAsString());
3051 case LFUN_INDEX_INSERT:
3053 InsetCommandParams p;
3054 p.setFromString(argument);
3055 InsetIndex * inset = new InsetIndex(p);
3057 if (!insertInset(inset))
3060 updateInset(inset, true);
3064 case LFUN_INDEX_INSERT_LAST:
3066 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3067 if (!idxstring.empty()) {
3068 owner_->message(_("Word `")
3069 + idxstring + _(("' indexed.")));
3070 InsetCommandParams p("index", idxstring);
3071 InsetIndex * inset = new InsetIndex(p);
3073 if (!insertInset(inset))
3076 updateInset(inset, true);
3081 case LFUN_INDEX_PRINT:
3083 InsetCommandParams p("printindex");
3084 Inset * inset = new InsetPrintIndex(p);
3085 if (!insertInset(inset, tclass.defaultLayoutName()))
3090 case LFUN_PARENTINSERT:
3092 InsetCommandParams p("lyxparent", argument);
3093 Inset * inset = new InsetParent(p, *buffer_);
3094 if (!insertInset(inset, tclass.defaultLayoutName()))
3100 case LFUN_CHILD_INSERT:
3102 InsetInclude::Params p;
3103 p.cparams.setFromString(argument);
3104 p.masterFilename_ = buffer_->fileName();
3106 InsetInclude * inset = new InsetInclude(p);
3107 if (!insertInset(inset))
3110 updateInset(inset, true);
3111 bv_->owner()->getDialogs()->showInclude(inset);
3116 case LFUN_FLOAT_LIST:
3117 if (floatList.typeExist(argument)) {
3118 Inset * inset = new InsetFloatList(argument);
3119 if (!insertInset(inset, tclass.defaultLayoutName()))
3122 lyxerr << "Non-existent float type: "
3123 << argument << endl;
3127 case LFUN_THESAURUS_ENTRY:
3129 string arg = argument;
3132 arg = bv_->getLyXText()->selectionAsString(buffer_,
3136 if (arg.size() > 100 || arg.empty()) {
3137 // Get word or selection
3138 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3139 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3140 // FIXME: where is getLyXText()->unselect(bv_) ?
3144 bv_->owner()->getDialogs()->showThesaurus(arg);
3148 case LFUN_SELFINSERT:
3150 if (argument.empty()) break;
3152 /* Automatically delete the currently selected
3153 * text and replace it with what is being
3154 * typed in now. Depends on lyxrc settings
3155 * "auto_region_delete", which defaults to
3158 LyXText * lt = bv_->getLyXText();
3160 if (lyxrc.auto_region_delete) {
3161 if (lt->selection.set()) {
3162 lt->cutSelection(bv_, false, false);
3165 | BufferView::FITCUR
3166 | BufferView::CHANGE);
3168 workarea().haveSelection(false);
3172 LyXFont const old_font(lt->real_current_font);
3174 string::const_iterator cit = argument.begin();
3175 string::const_iterator end = argument.end();
3176 for (; cit != end; ++cit) {
3177 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3182 | BufferView::FITCUR
3183 | BufferView::CHANGE);
3185 lt->selection.cursor = lt->cursor;
3186 moveCursorUpdate(false);
3188 // real_current_font.number can change so we need to
3189 // update the minibuffer
3190 if (old_font != lt->real_current_font)
3191 owner_->showState();
3196 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3198 time_t now_time_t = time(NULL);
3199 struct tm * now_tm = localtime(&now_time_t);
3200 setlocale(LC_TIME, "");
3202 if (!argument.empty())
3205 arg = lyxrc.date_insert_format;
3207 int const datetmp_len =
3208 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3210 LyXText * lt = bv_->getLyXText();
3212 for (int i = 0; i < datetmp_len; i++) {
3213 lt->insertChar(bv_, datetmp[i]);
3216 | BufferView::FITCUR
3217 | BufferView::CHANGE);
3220 lt->selection.cursor = lt->cursor;
3221 moveCursorUpdate(false);
3225 case LFUN_UNKNOWN_ACTION:
3226 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3237 void BufferView::Pimpl::newline()
3240 LyXText * lt = bv_->getLyXText();
3244 | BufferView::FITCUR);
3245 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3248 | BufferView::FITCUR
3249 | BufferView::CHANGE);
3254 void BufferView::Pimpl::hfill()
3257 LyXText * lt = bv_->getLyXText();
3261 | BufferView::FITCUR);
3262 lt->insertChar(bv_, Paragraph::META_HFILL);
3265 | BufferView::FITCUR
3266 | BufferView::CHANGE);
3271 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3274 LyXText * lt = bv_->getLyXText();
3277 update(lt, BufferView::SELECT|BufferView::FITCUR);
3278 InsetSpecialChar * new_inset =
3279 new InsetSpecialChar(kind);
3280 if (!insertInset(new_inset))
3283 updateInset(new_inset, true);
3288 void BufferView::Pimpl::smartQuote()
3290 LyXText const * lt = bv_->getLyXText();
3291 Paragraph const * par = lt->cursor.par();
3292 pos_type pos = lt->cursor.pos();
3296 || (par->isInset(pos - 1)
3297 && par->getInset(pos - 1)->isSpace()))
3300 c = par->getChar(pos - 1);
3305 LyXLayout const & style =
3306 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3308 if (style.pass_thru ||
3309 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3310 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3314 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3316 if (insertInset(inset))
3323 // Open and lock an updatable inset
3324 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3326 LyXText * lt = bv_->getLyXText();
3330 if (!insertInset(new_inset)) {
3334 new_inset->edit(bv_, !behind);
3339 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3341 // if we are in a locking inset we should try to insert the
3342 // inset there otherwise this is a illegal function now
3343 if (bv_->theLockingInset()) {
3344 if (bv_->theLockingInset()->insetAllowed(inset))
3345 return bv_->theLockingInset()->insertInset(bv_, inset);
3349 // not quite sure if we want this...
3350 setCursorParUndo(bv_);
3353 beforeChange(bv_->text);
3354 if (!lout.empty()) {
3355 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3356 bv_->text->breakParagraph(bv_);
3357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3359 if (bv_->text->cursor.par()->size()) {
3360 bv_->text->cursorLeft(bv_);
3362 bv_->text->breakParagraph(bv_);
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 LyXTextClass const & tclass =
3368 textclasslist[buffer_->params.textclass];
3369 bool hasLayout = tclass.hasLayout(lres);
3370 string lay = tclass.defaultLayoutName();
3372 if (hasLayout != false) {
3376 // layout not fount using default
3377 lay = tclass.defaultLayoutName();
3380 bv_->text->setLayout(bv_, lay);
3382 bv_->text->setParagraph(bv_, 0, 0,
3384 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3392 bv_->text->insertInset(bv_, inset);
3393 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3400 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3402 if (!inset || !available())
3405 // first check for locking insets
3406 if (bv_->theLockingInset()) {
3407 if (bv_->theLockingInset() == inset) {
3408 if (bv_->text->updateInset(bv_, inset)) {
3411 buffer_->markDirty();
3416 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3417 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3420 buffer_->markDirty();
3428 // then check if the inset is a top_level inset (has no owner)
3429 // if yes do the update as always otherwise we have to update the
3430 // toplevel inset where this inset is inside
3431 Inset * tl_inset = inset;
3432 while(tl_inset->owner())
3433 tl_inset = tl_inset->owner();
3435 if (tl_inset == inset) {
3436 update(bv_->text, BufferView::UPDATE);
3437 if (bv_->text->updateInset(bv_, inset)) {
3441 | BufferView::FITCUR
3442 | BufferView::CHANGE);
3444 update(bv_->text, SELECT);
3448 } else if (static_cast<UpdatableInset *>(tl_inset)
3449 ->updateInsetInInset(bv_, inset))
3451 if (bv_->text->updateInset(bv_, tl_inset)) {
3459 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3462 if (!available()) return;
3465 beforeChange(bv_->text);
3466 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3468 LyXCursor const & cursor = bv_->text->cursor;
3472 cursor.par()->isInset(cursor.pos())) {
3473 Inset const * inset = cursor.par()->getInset(cursor.pos());
3474 if (find(codes.begin(), codes.end(), inset->lyxCode())
3477 static_cast<InsetCommand const *>(inset)->getContents();
3481 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3482 if (bv_->text->cursor.pos()
3483 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3484 LyXCursor tmp = bv_->text->cursor;
3485 bv_->text->cursor.par(bv_->text->ownerParagraph());
3486 bv_->text->cursor.pos(0);
3487 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3488 bv_->text->cursor = tmp;
3489 bv_->owner()->message(_("No more insets"));
3492 bv_->owner()->message(_("No more insets"));
3495 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3496 bv_->text->selection.cursor = bv_->text->cursor;
3500 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3502 gotoInset(vector<Inset::Code>(1, code), same_content);