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),
146 current_scrollbar_value(0), cursor_timeout(400),
147 using_xterm_cursor(false)
149 workarea_.reset(new WorkArea(xpos, ypos, width, height));
150 screen_.reset(new LScreen(workarea()));
153 workarea().scrollCB.connect(boost::bind(&BufferView::Pimpl::scrollCB, this, _1));
154 workarea().workAreaExpose
155 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
156 workarea().workAreaButtonPress
157 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
158 workarea().workAreaButtonRelease
159 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
160 workarea().workAreaMotionNotify
161 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
162 workarea().workAreaDoubleClick
163 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
164 workarea().workAreaTripleClick
165 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
166 workarea().workAreaKeyPress
167 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
168 workarea().selectionRequested
169 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
170 workarea().selectionLost
171 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
173 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
174 cursor_timeout.start();
175 workarea().setFocus();
176 saved_positions.resize(saved_positions_num);
180 WorkArea & BufferView::Pimpl::workarea() const
182 return *workarea_.get();
186 LScreen & BufferView::Pimpl::screen() const
188 return *screen_.get();
192 Painter & BufferView::Pimpl::painter() const
194 return workarea().getPainter();
198 void BufferView::Pimpl::buffer(Buffer * b)
200 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
203 buffer_->delUser(bv_);
205 // Put the old text into the TextCache, but
206 // only if the buffer is still loaded.
207 // Also set the owner of the test to 0
208 // bv_->text->owner(0);
209 textcache.add(buffer_, workarea().workWidth(), bv_->text);
210 if (lyxerr.debugging())
211 textcache.show(lyxerr, "BufferView::buffer");
216 // Set current buffer
219 if (bufferlist.getState() == BufferList::CLOSING) return;
221 // If we are closing the buffer, use the first buffer as current
223 buffer_ = bufferlist.first();
227 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
228 buffer_->addUser(bv_);
229 // If we don't have a text object for this, we make one
230 if (bv_->text == 0) {
231 resizeCurrentBuffer();
236 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
237 owner_->updateMenubar();
238 owner_->updateToolbar();
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);
245 lyxerr[Debug::INFO] << " No Buffer!" << endl;
246 owner_->updateMenubar();
247 owner_->updateToolbar();
248 owner_->getDialogs()->hideBufferDependent();
252 // Also remove all remaining text's from the testcache.
253 // (there should not be any!) (if there is any it is a
255 if (lyxerr.debugging())
256 textcache.show(lyxerr, "buffer delete all");
259 // should update layoutchoice even if we don't have a buffer.
260 owner_->updateLayoutChoice();
262 owner_->updateWindowTitle();
266 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
268 workarea().resize(xpos, ypos, width, height);
269 update(bv_->text, SELECT);
274 void BufferView::Pimpl::resize()
277 resizeCurrentBuffer();
281 void BufferView::Pimpl::redraw()
283 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
288 bool BufferView::Pimpl::fitCursor()
292 if (bv_->theLockingInset()) {
293 bv_->theLockingInset()->fitInsetCursor(bv_);
296 ret = screen().fitCursor(bv_->text, bv_);
299 bv_->owner()->getDialogs()->updateParagraph();
306 void BufferView::Pimpl::redoCurrentBuffer()
308 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
309 if (buffer_ && bv_->text) {
311 owner_->updateLayoutChoice();
316 int BufferView::Pimpl::resizeCurrentBuffer()
318 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
321 Paragraph * selstartpar = 0;
322 Paragraph * selendpar = 0;
323 UpdatableInset * the_locking_inset = 0;
326 pos_type selstartpos = 0;
327 pos_type selendpos = 0;
328 bool selection = false;
329 bool mark_set = false;
331 owner_->prohibitInput();
333 owner_->message(_("Formatting document..."));
336 par = bv_->text->cursor.par();
337 pos = bv_->text->cursor.pos();
338 selstartpar = bv_->text->selection.start.par();
339 selstartpos = bv_->text->selection.start.pos();
340 selendpar = bv_->text->selection.end.par();
341 selendpos = bv_->text->selection.end.pos();
342 selection = bv_->text->selection.set();
343 mark_set = bv_->text->selection.mark();
344 the_locking_inset = bv_->theLockingInset();
345 buffer_->resizeInsets(bv_);
346 // I don't think the delete and new are necessary here we just could
347 // call only init! (Jug 20020419)
349 bv_->text = new LyXText(bv_);
350 bv_->text->init(bv_);
352 // See if we have a text in TextCache that fits
353 // the new buffer_ with the correct width.
354 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
356 if (lyxerr.debugging()) {
357 lyxerr << "Found a LyXText that fits:\n";
358 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
360 // Set the owner of the newly found text
361 // bv_->text->owner(bv_);
362 if (lyxerr.debugging())
363 textcache.show(lyxerr, "resizeCurrentBuffer");
365 bv_->text = new LyXText(bv_);
366 bv_->text->init(bv_);
367 //buffer_->resizeInsets(bv_);
374 bv_->text->selection.set(true);
375 // At this point just to avoid the Delete-Empty-Paragraph-
376 // Mechanism when setting the cursor.
377 bv_->text->selection.mark(mark_set);
379 bv_->text->setCursor(bv_, selstartpar, selstartpos);
380 bv_->text->selection.cursor = bv_->text->cursor;
381 bv_->text->setCursor(bv_, selendpar, selendpos);
382 bv_->text->setSelection(bv_);
383 bv_->text->setCursor(bv_, par, pos);
385 bv_->text->setCursor(bv_, par, pos);
386 bv_->text->selection.cursor = bv_->text->cursor;
387 bv_->text->selection.set(false);
389 // remake the inset locking
390 bv_->theLockingInset(the_locking_inset);
393 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
395 // this will scroll the screen such that the cursor becomes visible
400 owner_->allowInput();
402 /// clear the "Formatting Document" message
409 void BufferView::Pimpl::updateScreen()
411 // Regenerate the screen.
416 void BufferView::Pimpl::updateScrollbar()
419 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
420 workarea().setScrollbar(0, 1.0);
424 long const text_height = bv_->text->height;
425 long const work_height = workarea().workHeight();
427 double const lineh = bv_->text->defaultHeight();
428 double const slider_size =
429 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
431 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
432 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
434 /* If the text is smaller than the working area, the scrollbar
435 * maximum must be the working area height. No scrolling will
437 if (text_height <= work_height) {
438 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
439 workarea().setScrollbarBounds(0.0, 0.0);
440 current_scrollbar_value = bv_->text->first_y;
441 workarea().setScrollbar(current_scrollbar_value, 1.0);
445 workarea().setScrollbarBounds(0.0, text_height - work_height);
446 workarea().setScrollbarIncrements(lineh);
447 current_scrollbar_value = bv_->text->first_y;
448 workarea().setScrollbar(current_scrollbar_value, slider_size);
452 // Callback for scrollbar slider
453 void BufferView::Pimpl::scrollCB(double value)
455 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
457 if (!buffer_) return;
459 current_scrollbar_value = long(value);
461 if (current_scrollbar_value < 0)
462 current_scrollbar_value = 0;
464 screen().draw(bv_->text, bv_, current_scrollbar_value);
466 if (!lyxrc.cursor_follows_scrollbar) {
471 LyXText * vbt = bv_->text;
473 int const height = vbt->defaultHeight();
474 int const first = static_cast<int>((bv_->text->first_y + height));
475 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
477 if (vbt->cursor.y() < first)
478 vbt->setCursorFromCoordinates(bv_, 0, first);
479 else if (vbt->cursor.y() > last)
480 vbt->setCursorFromCoordinates(bv_, 0, last);
486 int BufferView::Pimpl::scrollUp(long time)
491 double value = workarea().getScrollbarValue();
497 float add_value = (bv_->text->defaultHeight()
498 + float(time) * float(time) * 0.125);
500 if (add_value > workarea().workHeight())
501 add_value = float(workarea().workHeight() -
502 bv_->text->defaultHeight());
504 float add_value = float(workarea().workHeight()) * float(time) / 100;
512 workarea().setScrollbarValue(value);
519 int BufferView::Pimpl::scrollDown(long time)
524 double value = workarea().getScrollbarValue();
525 pair<float, float> p = workarea().getScrollbarBounds();
526 double const max = p.second;
532 float add_value = (bv_->text->defaultHeight()
533 + float(time) * float(time) * 0.125);
535 if (add_value > workarea().workHeight())
536 add_value = float(workarea().workHeight() -
537 bv_->text->defaultHeight());
539 float add_value = float(workarea().workHeight()) * float(time) / 100;
547 workarea().setScrollbarValue(value);
554 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, key_modifier::state state)
556 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
560 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
562 // Only use motion with button 1
563 if (!(state & mouse_button::button1))
569 // Check for inset locking
570 if (bv_->theLockingInset()) {
571 LyXCursor cursor = bv_->text->cursor;
572 LyXFont font = bv_->text->getFont(buffer_,
573 cursor.par(), cursor.pos());
574 int width = bv_->theLockingInset()->width(bv_, font);
575 int inset_x = font.isVisibleRightToLeft()
576 ? cursor.ix() - width : cursor.ix();
577 int start_x = inset_x + bv_->theLockingInset()->scroll();
579 bv_->theLockingInset()->
580 insetMotionNotify(bv_,
582 y - cursor.iy() + bv_->text->first_y,
587 /* The test for not selection possible is needed, that only motion
588 events are used, where the bottom press event was on
589 the drawing area too */
590 if (!selection_possible)
593 screen().hideCursor();
595 Row * cursorrow = bv_->text->cursor.row();
596 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
598 // sorry for this but I have a strange error that the y value jumps at
599 // a certain point. This seems like an error in my xforms library or
600 // in some other local environment, but I would like to leave this here
601 // for the moment until I can remove this (Jug 20020418)
602 if (y_before < bv_->text->cursor.y())
603 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
605 // This is to allow jumping over large insets
606 if (cursorrow == bv_->text->cursor.row()) {
607 if (y >= int(workarea().workHeight())) {
608 bv_->text->cursorDown(bv_, false);
610 bv_->text->cursorUp(bv_, false);
614 if (!bv_->text->selection.set())
615 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
617 bv_->text->setSelection(bv_);
618 screen().toggleToggle(bv_->text, bv_);
624 // Single-click on work area
625 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
626 mouse_button::state button)
631 // ok ok, this is a hack (for xforms)
633 if (button == mouse_button::button4) {
634 scrollUp(lyxrc.wheel_jump);
635 // We shouldn't go further down as we really should only do the
636 // scrolling and be done with this. Otherwise we may open some
637 // dialogs (Jug 20020424).
639 } else if (button == mouse_button::button5) {
640 scrollDown(lyxrc.wheel_jump);
641 // We shouldn't go further down as we really should only do the
642 // scrolling and be done with this. Otherwise we may open some
643 // dialogs (Jug 20020424).
647 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
649 // Middle button press pastes if we have a selection
650 // We do this here as if the selection was inside an inset
651 // it could get cleared on the unlocking of the inset so
652 // we have to check this first
653 bool paste_internally = false;
654 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
655 owner_->getLyXFunc()->dispatch(LFUN_COPY);
656 paste_internally = true;
659 int const screen_first = bv_->text->first_y;
661 if (bv_->theLockingInset()) {
662 // We are in inset locking mode
664 /* Check whether the inset was hit. If not reset mode,
665 otherwise give the event to the inset */
666 if (inset_hit == bv_->theLockingInset()) {
667 bv_->theLockingInset()->
668 insetButtonPress(bv_, xpos, ypos, button);
671 bv_->unlockInset(bv_->theLockingInset());
676 selection_possible = true;
677 screen().hideCursor();
679 // Clear the selection
680 screen().toggleSelection(bv_->text, bv_);
681 bv_->text->clearSelection();
682 bv_->text->fullRebreak(bv_);
686 // Single left click in math inset?
687 if (isHighlyEditableInset(inset_hit)) {
688 // Highly editable inset, like math
689 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
690 selection_possible = false;
691 owner_->updateLayoutChoice();
692 owner_->message(inset->editMessage());
693 //inset->edit(bv_, xpos, ypos, button);
694 // We just have to lock the inset before calling a PressEvent on it!
695 // we don't need the edit() call here! (Jug20020329)
696 if (!bv_->lockInset(inset)) {
697 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
699 inset->insetButtonPress(bv_, xpos, ypos, button);
702 // I'm not sure we should continue here if we hit an inset (Jug20020403)
704 // Right click on a footnote flag opens float menu
705 if (button == mouse_button::button3) {
706 selection_possible = false;
710 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
711 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
713 bv_->text->selection.cursor = bv_->text->cursor;
714 bv_->text->cursor.x_fix(bv_->text->cursor.x());
716 owner_->updateLayoutChoice();
718 selection_possible = false;
721 // Insert primary selection with middle mouse
722 // if there is a local selection in the current buffer,
724 if (button == mouse_button::button2) {
725 if (paste_internally)
726 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
728 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
730 selection_possible = false;
736 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
741 LyXText * text = bv_->getLyXText();
743 if (text->bv_owner && bv_->theLockingInset())
746 if (button == mouse_button::button1) {
747 if (text->bv_owner) {
748 screen().hideCursor();
749 screen().toggleSelection(text, bv_);
750 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
751 screen().toggleSelection(text, bv_, false);
753 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
755 /* This will fit the cursor on the screen
757 update(text, BufferView::SELECT|BufferView::FITCUR);
762 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
767 LyXText * text = bv_->getLyXText();
769 if (text->bv_owner && bv_->theLockingInset())
772 if (button == mouse_button::button1) {
773 if (text->bv_owner) {
774 screen().hideCursor();
775 screen().toggleSelection(text, bv_);
777 text->cursorHome(bv_);
778 text->selection.cursor = text->cursor;
779 text->cursorEnd(bv_);
780 text->setSelection(bv_);
781 if (text->bv_owner) {
782 screen().toggleSelection(text, bv_, false);
784 /* This will fit the cursor on the screen
786 update(text, BufferView::SELECT|BufferView::FITCUR);
791 void BufferView::Pimpl::selectionRequested()
798 LyXText * text = bv_->getLyXText();
800 if (text->selection.set() &&
801 (!bv_->text->xsel_cache.set() ||
802 text->selection.start != bv_->text->xsel_cache.start ||
803 text->selection.end != bv_->text->xsel_cache.end))
805 bv_->text->xsel_cache = text->selection;
806 sel = text->selectionAsString(bv_->buffer(), false);
807 } else if (!text->selection.set()) {
809 bv_->text->xsel_cache.set(false);
812 workarea().putClipboard(sel);
817 void BufferView::Pimpl::selectionLost()
822 bv_->getLyXText()->clearSelection();
824 bv_->text->xsel_cache.set(false);
829 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
830 mouse_button::state button)
832 // do nothing if we used the mouse wheel
833 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
836 // If we hit an inset, we have the inset coordinates in these
837 // and inset_hit points to the inset. If we do not hit an
838 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
839 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
841 if (bv_->theLockingInset()) {
842 // We are in inset locking mode.
844 /* LyX does a kind of work-area grabbing for insets.
845 Only a ButtonPress Event outside the inset will
846 force a insetUnlock. */
847 bv_->theLockingInset()->
848 insetButtonRelease(bv_, x, y, button);
852 selection_possible = false;
854 if (button == mouse_button::button2)
858 if (button == mouse_button::button1) {
859 workarea().haveSelection(bv_->getLyXText()->selection.set());
864 owner_->updateMenubar();
865 owner_->updateToolbar();
867 // Did we hit an editable inset?
869 selection_possible = false;
871 // if we reach this point with a selection, it
872 // must mean we are currently selecting.
873 // But we don't want to open the inset
874 // because that is annoying for the user.
875 // So just pretend we didn't hit it.
876 // this is OK because a "kosher" ButtonRelease
877 // will follow a ButtonPress that clears
879 // Note this also fixes selection drawing
880 // problems if we end up opening an inset
881 if (bv_->getLyXText()->selection.set())
884 // CHECK fix this proper in 0.13
885 // well, maybe 13.0 !!!!!!!!!
887 // Following a ref shouldn't issue
888 // a push on the undo-stack
889 // anylonger, now that we have
890 // keybindings for following
891 // references and returning from
892 // references. IMHO though, it
893 // should be the inset's own business
894 // to push or not push on the undo
895 // stack. They don't *have* to
896 // alter the document...
898 // ...or maybe the SetCursorParUndo()
899 // below isn't necessary at all anylonger?
900 if (inset_hit->lyxCode() == Inset::REF_CODE) {
901 setCursorParUndo(bv_);
904 owner_->message(inset_hit->editMessage());
906 if (isHighlyEditableInset(inset_hit)) {
907 // Highly editable inset, like math
908 UpdatableInset *inset = (UpdatableInset *)inset_hit;
909 inset->insetButtonRelease(bv_, x, y, button);
911 inset_hit->insetButtonRelease(bv_, x, y, button);
912 // IMO this is a grosshack! Inset's should be changed so that
913 // they call the actions they have to do with the insetButtonRel.
914 // function and not in the edit(). This should be changed
916 inset_hit->edit(bv_, x, y, button);
921 // Maybe we want to edit a bibitem ale970302
922 if (bv_->text->cursor.par()->bibkey && x < 20 +
923 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
924 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
931 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
932 LyXCursor const & cursor) const
934 Paragraph /*const*/ & par = *cursor.par();
935 pos_type const pos = cursor.pos();
937 lyx::Assert(par.getInset(pos));
939 Inset const & inset(*par.getInset(pos));
941 LyXFont const & font = text.getFont(buffer_, &par, pos);
943 int const width = inset.width(bv_, font);
944 int const inset_x = font.isVisibleRightToLeft()
945 ? (cursor.ix() - width) : cursor.ix();
948 inset_x + inset.scroll(),
950 cursor.iy() - inset.ascent(bv_, font),
951 cursor.iy() + inset.descent(bv_, font));
955 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
956 LyXCursor const & cursor,
957 int & x, int & y) const
959 pos_type const pos(cursor.pos());
960 Paragraph /*const*/ & par(*cursor.par());
962 if (pos >= par.size() || !par.isInset(pos)) {
966 Inset /*const*/ * inset = par.getInset(pos);
968 if (!isEditableInset(inset)) {
972 Box b(insetDimensions(text, cursor));
974 if (!b.contained(x, y)) {
975 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
976 << " box " << b << endl;
980 text.setCursor(bv_, &par, pos, true);
983 // The origin of an inset is on the baseline
984 y -= text.cursor.iy();
990 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
992 int y_tmp = y + text->first_y;
995 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
997 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1004 // look at previous position
1006 if (cursor.pos() == 0) {
1011 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1013 inset = checkInset(*text, cursor, x, y_tmp);
1021 void BufferView::Pimpl::workAreaExpose()
1023 static int work_area_width;
1024 static unsigned int work_area_height;
1026 bool const widthChange = workarea().workWidth() != work_area_width;
1027 bool const heightChange = workarea().workHeight() != work_area_height;
1029 // update from work area
1030 work_area_width = workarea().workWidth();
1031 work_area_height = workarea().workHeight();
1034 // The visible LyXView need a resize
1035 owner_->view()->resize();
1037 // Remove all texts from the textcache
1038 // This is not _really_ what we want to do. What
1039 // we really want to do is to delete in textcache
1040 // that does not have a BufferView with matching
1041 // width, but as long as we have only one BufferView
1042 // deleting all gives the same result.
1043 if (lyxerr.debugging())
1044 textcache.show(lyxerr, "Expose delete all");
1046 buffer_->resizeInsets(bv_);
1047 } else if (heightChange) {
1048 // Rebuild image of current screen
1050 // fitCursor() ensures we don't jump back
1051 // to the start of the document on vertical
1055 // The main window size has changed, repaint most stuff
1058 screen().redraw(bv_->text, bv_);
1061 // Grey box when we don't have a buffer
1062 workarea().greyOut();
1065 // always make sure that the scrollbar is sane.
1067 owner_->updateLayoutChoice();
1072 void BufferView::Pimpl::update()
1074 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
1075 LyXText::text_status st = bv_->text->status();
1076 screen().update(bv_->text, bv_);
1078 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1079 bv_->text->fullRebreak(bv_);
1080 st = LyXText::NEED_MORE_REFRESH;
1081 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1082 bv_->text->cursor.pos());
1083 if (bv_->text->selection.set()) {
1084 bv_->text->setCursor(bv_, bv_->text->selection.start,
1085 bv_->text->selection.start.par(),
1086 bv_->text->selection.start.pos());
1087 bv_->text->setCursor(bv_, bv_->text->selection.end,
1088 bv_->text->selection.end.par(),
1089 bv_->text->selection.end.pos());
1092 bv_->text->status(bv_, st);
1093 screen().update(bv_->text, bv_);
1095 // do this here instead of in the screen::update because of
1097 bv_->text->status(bv_, LyXText::UNCHANGED);
1103 // Values used when calling update:
1105 // -2 - update, move sel_cursor if selection, fitcursor
1106 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1107 // 0 - update, move sel_cursor if selection, fitcursor
1108 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1109 // 3 - update, move sel_cursor if selection
1112 // a simple redraw of the parts that need refresh
1114 // move sel_cursor if selection -
1115 // the text's sel_cursor is moved if there is selection is progress
1118 // fitCursor() is called and the scrollbar updated
1121 // the buffer is marked dirty.
1130 // UPDATE_ONLY = UPDATE;
1131 // UPDATE_SELECT = UPDATE | SELECT;
1132 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1133 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1135 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1136 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1137 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1138 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1139 // update(3) -> update(1) -> update(1) -> update(SELECT)
1141 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1143 owner_->updateLayoutChoice();
1145 if (!text->selection.set() && (f & SELECT)) {
1146 text->selection.cursor = text->cursor;
1149 text->fullRebreak(bv_);
1151 if (text->inset_owner) {
1152 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1153 updateInset(text->inset_owner, false);
1163 buffer_->markDirty();
1168 // Callback for cursor timer
1169 void BufferView::Pimpl::cursorToggle()
1172 cursor_timeout.restart();
1177 extern void reapSpellchecker(void);
1180 if (!bv_->theLockingInset()) {
1181 screen().cursorToggle(bv_);
1183 bv_->theLockingInset()->toggleInsetCursor(bv_);
1186 cursor_timeout.restart();
1190 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1192 if (!text->cursor.row()->previous()) {
1193 if (text->first_y > 0) {
1194 int new_y = bv_->text->first_y - workarea().workHeight();
1195 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1201 int y = text->first_y;
1202 Row * cursorrow = text->cursor.row();
1204 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1208 if (cursorrow == bv_->text->cursor.row()) {
1209 // we have a row which is higher than the workarea so we leave the
1210 // cursor on the start of the row and move only the draw up as soon
1211 // as we move the cursor or do something while inside the row (it may
1212 // span several workarea-heights) we'll move to the top again, but this
1213 // is better than just jump down and only display part of the row.
1214 new_y = bv_->text->first_y - workarea().workHeight();
1216 if (text->inset_owner) {
1217 new_y = bv_->text->cursor.iy()
1218 + bv_->theLockingInset()->insetInInsetY() + y
1219 + text->cursor.row()->height()
1220 - workarea().workHeight() + 1;
1222 new_y = text->cursor.y()
1223 - text->cursor.row()->baseline()
1224 + text->cursor.row()->height()
1225 - workarea().workHeight() + 1;
1228 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1229 if (text->cursor.row()->previous()) {
1231 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1232 text->cursor.row()->previous()->pos(), false);
1233 if (cur.y() > text->first_y) {
1234 text->cursorUp(bv_, true);
1241 void BufferView::Pimpl::cursorNext(LyXText * text)
1243 if (!text->cursor.row()->next()) {
1244 int y = text->cursor.y() - text->cursor.row()->baseline() +
1245 text->cursor.row()->height();
1246 if (y > int(text->first_y + workarea().workHeight())) {
1247 screen().draw(bv_->text, bv_,
1248 bv_->text->first_y + workarea().workHeight());
1254 int y = text->first_y + workarea().workHeight();
1255 if (text->inset_owner && !text->first_y) {
1256 y -= (bv_->text->cursor.iy()
1257 - bv_->text->first_y
1258 + bv_->theLockingInset()->insetInInsetY());
1261 text->getRowNearY(y);
1263 Row * cursorrow = text->cursor.row();
1264 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1268 if (cursorrow == bv_->text->cursor.row()) {
1269 // we have a row which is higher than the workarea so we leave the
1270 // cursor on the start of the row and move only the draw down as soon
1271 // as we move the cursor or do something while inside the row (it may
1272 // span several workarea-heights) we'll move to the top again, but this
1273 // is better than just jump down and only display part of the row.
1274 new_y = bv_->text->first_y + workarea().workHeight();
1276 if (text->inset_owner) {
1277 new_y = bv_->text->cursor.iy()
1278 + bv_->theLockingInset()->insetInInsetY()
1279 + y - text->cursor.row()->baseline();
1281 new_y = text->cursor.y() - text->cursor.row()->baseline();
1284 screen().draw(bv_->text, bv_, new_y);
1285 if (text->cursor.row()->next()) {
1287 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1288 text->cursor.row()->next()->pos(), false);
1289 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1290 text->cursorDown(bv_, true);
1297 bool BufferView::Pimpl::available() const
1299 if (buffer_ && bv_->text)
1305 void BufferView::Pimpl::beforeChange(LyXText * text)
1308 text->clearSelection();
1312 void BufferView::Pimpl::savePosition(unsigned int i)
1314 if (i >= saved_positions_num)
1316 saved_positions[i] = Position(buffer_->fileName(),
1317 bv_->text->cursor.par()->id(),
1318 bv_->text->cursor.pos());
1321 str << _("Saved bookmark") << ' ' << i;
1322 owner_->message(str.str().c_str());
1327 void BufferView::Pimpl::restorePosition(unsigned int i)
1329 if (i >= saved_positions_num)
1332 string const fname = saved_positions[i].filename;
1334 beforeChange(bv_->text);
1336 if (fname != buffer_->fileName()) {
1337 Buffer * b = bufferlist.exists(fname) ?
1338 bufferlist.getBuffer(fname) :
1339 bufferlist.loadLyXFile(fname); // don't ask, just load it
1340 if (b != 0) buffer(b);
1343 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1347 bv_->text->setCursor(bv_, par,
1348 min(par->size(), saved_positions[i].par_pos));
1350 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1353 str << _("Moved to bookmark") << ' ' << i;
1354 owner_->message(str.str().c_str());
1359 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1361 if (i >= saved_positions_num)
1364 return !saved_positions[i].filename.empty();
1368 void BufferView::Pimpl::setState()
1370 if (!lyxrc.rtl_support)
1373 LyXText * text = bv_->getLyXText();
1374 if (text->real_current_font.isRightToLeft()
1375 && !(bv_->theLockingInset()
1376 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1378 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1379 owner_->getIntl()->KeyMapSec();
1381 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1382 owner_->getIntl()->KeyMapPrim();
1387 void BufferView::Pimpl::insetUnlock()
1389 if (bv_->theLockingInset()) {
1390 bv_->theLockingInset()->insetUnlock(bv_);
1391 bv_->theLockingInset(0);
1397 bool BufferView::Pimpl::focus() const
1399 return workarea().hasFocus();
1403 void BufferView::Pimpl::focus(bool f)
1405 if (f) workarea().setFocus();
1409 void BufferView::Pimpl::showCursor()
1411 if (bv_->theLockingInset())
1412 bv_->theLockingInset()->showInsetCursor(bv_);
1414 screen().showCursor(bv_->text, bv_);
1418 void BufferView::Pimpl::hideCursor()
1420 if (!bv_->theLockingInset())
1421 screen().hideCursor();
1425 void BufferView::Pimpl::toggleSelection(bool b)
1427 if (bv_->theLockingInset())
1428 bv_->theLockingInset()->toggleSelection(bv_, b);
1429 screen().toggleSelection(bv_->text, bv_, b);
1433 void BufferView::Pimpl::toggleToggle()
1435 screen().toggleToggle(bv_->text, bv_);
1439 void BufferView::Pimpl::center()
1441 beforeChange(bv_->text);
1442 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1443 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1445 screen().draw(bv_->text, bv_, 0);
1447 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1452 void BufferView::Pimpl::pasteClipboard(bool asPara)
1457 screen().hideCursor();
1458 beforeChange(bv_->text);
1460 string const clip(workarea().getClipboard());
1466 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1468 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1470 bv_->getLyXText()->clearSelection();
1471 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1475 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1477 workarea().putClipboard(stuff);
1482 * Dispatch functions for actions which can be valid for BufferView->text
1483 * and/or InsetText->text!!!
1488 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1490 LyXText * lt = bv_->getLyXText();
1492 if (selecting || lt->selection.mark()) {
1493 lt->setSelection(bv_);
1497 updateInset(lt->inset_owner, false);
1501 update(lt, BufferView::SELECT|BufferView::FITCUR);
1503 update(lt, BufferView::SELECT);
1505 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1506 bv_->theLockingInset()->hideInsetCursor(bv_);
1507 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1511 if (!lt->selection.set())
1512 workarea().haveSelection(false);
1514 /* ---> Everytime the cursor is moved, show the current font state. */
1515 // should this too me moved out of this func?
1516 //owner->showState();
1521 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1523 LyXCursor cursor = bv_->getLyXText()->cursor;
1524 Buffer::inset_iterator it =
1525 find_if(Buffer::inset_iterator(
1526 cursor.par(), cursor.pos()),
1527 buffer_->inset_iterator_end(),
1528 lyx::compare_memfun(&Inset::lyxCode, code));
1529 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1533 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1535 string filename = filen;
1537 if (filename.empty()) {
1538 // Launch a file browser
1539 string initpath = lyxrc.document_path;
1542 string const trypath = owner_->buffer()->filePath();
1543 // If directory is writeable, use this as default.
1544 if (IsDirWriteable(trypath))
1548 FileDialog fileDlg(bv_->owner(),
1549 _("Select LyX document to insert"),
1551 make_pair(string(_("Documents|#o#O")),
1552 string(lyxrc.document_path)),
1553 make_pair(string(_("Examples|#E#e")),
1554 string(AddPath(system_lyxdir, "examples"))));
1556 FileDialog::Result result =
1557 fileDlg.Select(initpath,
1558 _("*.lyx| LyX Documents (*.lyx)"));
1560 if (result.first == FileDialog::Later)
1563 filename = result.second;
1565 // check selected filename
1566 if (filename.empty()) {
1567 owner_->message(_("Canceled."));
1572 // get absolute path of file and add ".lyx" to the filename if
1574 filename = FileSearch(string(), filename, "lyx");
1576 string const disp_fn(MakeDisplayPath(filename));
1579 s1 << _("Inserting document") << ' '
1580 << disp_fn << " ...";
1581 owner_->message(s1.str().c_str());
1582 bool const res = bv_->insertLyXFile(filename);
1585 str << _("Document") << ' ' << disp_fn
1586 << ' ' << _("inserted.");
1587 owner_->message(str.str().c_str());
1590 str << _("Could not insert document") << ' '
1592 owner_->message(str.str().c_str());
1597 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1599 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1600 << action <<"] arg[" << argument << "]" << endl;
1602 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1605 // --- Misc -------------------------------------------
1609 LyXText * lt = bv_->getLyXText();
1610 lt->toggleAppendix(bv_);
1613 | BufferView::FITCUR
1614 | BufferView::CHANGE);
1619 case LFUN_TOC_INSERT:
1621 InsetCommandParams p;
1622 p.setCmdName("tableofcontents");
1623 Inset * inset = new InsetTOC(p);
1624 if (!insertInset(inset, tclass.defaultLayoutName()))
1629 case LFUN_SCROLL_INSET:
1630 // this is not handled here as this funktion is only aktive
1631 // if we have a locking_inset and that one is (or contains)
1635 case LFUN_INSET_GRAPHICS:
1637 Inset * new_inset = new InsetGraphics;
1638 if (!insertInset(new_inset)) {
1641 // this is need because you don't use a inset->Edit()
1642 updateInset(new_inset, true);
1643 new_inset->edit(bv_);
1653 case LFUN_PASTESELECTION:
1655 bool asPara = false;
1656 if (argument == "paragraph")
1658 pasteClipboard(asPara);
1670 case LFUN_LAYOUT_COPY:
1671 bv_->copyEnvironment();
1674 case LFUN_LAYOUT_PASTE:
1675 bv_->pasteEnvironment();
1679 case LFUN_GOTOERROR:
1680 gotoInset(Inset::ERROR_CODE, false);
1684 gotoInset(Inset::IGNORE_CODE, false);
1687 case LFUN_REFERENCE_GOTO:
1689 vector<Inset::Code> tmp;
1690 tmp.push_back(Inset::LABEL_CODE);
1691 tmp.push_back(Inset::REF_CODE);
1692 gotoInset(tmp, true);
1696 case LFUN_HYPHENATION:
1697 specialChar(InsetSpecialChar::HYPHENATION);
1700 case LFUN_LIGATURE_BREAK:
1701 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1705 specialChar(InsetSpecialChar::LDOTS);
1708 case LFUN_END_OF_SENTENCE:
1709 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1712 case LFUN_MENU_SEPARATOR:
1713 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1720 case LFUN_DEPTH_MIN:
1721 changeDepth(bv_, bv_->getLyXText(), -1);
1724 case LFUN_DEPTH_PLUS:
1725 changeDepth(bv_, bv_->getLyXText(), 1);
1729 owner_->getDialogs()->setUserFreeFont();
1732 case LFUN_FILE_INSERT:
1733 MenuInsertLyXFile(argument);
1736 case LFUN_FILE_INSERT_ASCII_PARA:
1737 InsertAsciiFile(bv_, argument, true);
1740 case LFUN_FILE_INSERT_ASCII:
1741 InsertAsciiFile(bv_, argument, false);
1746 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1747 << argument << endl;
1749 // This is not the good solution to the empty argument
1750 // problem, but it will hopefully suffice for 1.2.0.
1751 // The correct solution would be to augument the
1752 // function list/array with information about what
1753 // functions needs arguments and their type.
1754 if (argument.empty()) {
1755 owner_->getLyXFunc()->setErrorMessage(
1756 _("LyX function 'layout' needs an argument."));
1760 // Derive layout number from given argument (string)
1761 // and current buffer's textclass (number). */
1762 bool hasLayout = tclass.hasLayout(argument);
1763 string layout = argument;
1765 // If the entry is obsolete, use the new one instead.
1767 string const & obs = tclass[layout].obsoleted_by();
1773 owner_->getLyXFunc()->setErrorMessage(
1774 string(N_("Layout ")) + argument +
1779 bool change_layout = (current_layout != layout);
1780 LyXText * lt = bv_->getLyXText();
1781 if (!change_layout && lt->selection.set() &&
1782 lt->selection.start.par() != lt->selection.end.par())
1784 Paragraph * spar = lt->selection.start.par();
1785 Paragraph * epar = lt->selection.end.par()->next();
1786 while(spar != epar) {
1787 if (spar->layout() != current_layout) {
1788 change_layout = true;
1793 if (change_layout) {
1795 current_layout = layout;
1798 | BufferView::FITCUR);
1799 lt->setLayout(bv_, layout);
1800 owner_->setLayout(layout);
1803 | BufferView::FITCUR
1804 | BufferView::CHANGE);
1811 lang(bv_, argument);
1813 owner_->showState();
1818 owner_->showState();
1823 owner_->showState();
1828 owner_->showState();
1833 owner_->showState();
1838 owner_->showState();
1843 owner_->showState();
1848 owner_->showState();
1851 case LFUN_UNDERLINE:
1853 owner_->showState();
1856 case LFUN_FONT_SIZE:
1857 fontSize(bv_, argument);
1858 owner_->showState();
1861 case LFUN_FONT_STATE:
1862 owner_->getLyXFunc()->setMessage(currentState(bv_));
1865 case LFUN_UPCASE_WORD:
1867 LyXText * lt = bv_->getLyXText();
1871 | BufferView::FITCUR);
1872 lt->changeCase(bv_, LyXText::text_uppercase);
1873 if (lt->inset_owner)
1874 updateInset(lt->inset_owner, true);
1877 | BufferView::FITCUR
1878 | BufferView::CHANGE);
1882 case LFUN_LOWCASE_WORD:
1884 LyXText * lt = bv_->getLyXText();
1886 update(lt, BufferView::SELECT|BufferView::FITCUR);
1887 lt->changeCase(bv_, LyXText::text_lowercase);
1888 if (lt->inset_owner)
1889 updateInset(lt->inset_owner, true);
1892 | BufferView::FITCUR
1893 | BufferView::CHANGE);
1897 case LFUN_CAPITALIZE_WORD:
1899 LyXText * lt = bv_->getLyXText();
1901 update(lt, BufferView::SELECT|BufferView::FITCUR);
1902 lt->changeCase(bv_, LyXText::text_capitalization);
1903 if (lt->inset_owner)
1904 updateInset(lt->inset_owner, true);
1907 | BufferView::FITCUR
1908 | BufferView::CHANGE);
1912 case LFUN_TRANSPOSE_CHARS:
1914 LyXText * lt = bv_->getLyXText();
1916 update(lt, BufferView::SELECT|BufferView::FITCUR);
1917 lt->transposeChars(*bv_);
1918 if (lt->inset_owner)
1919 updateInset(lt->inset_owner, true);
1922 | BufferView::FITCUR
1923 | BufferView::CHANGE);
1928 case LFUN_INSERT_LABEL:
1929 MenuInsertLabel(bv_, argument);
1932 case LFUN_REF_INSERT:
1933 if (argument.empty()) {
1934 InsetCommandParams p("ref");
1935 owner_->getDialogs()->createRef(p.getAsString());
1937 InsetCommandParams p;
1938 p.setFromString(argument);
1940 InsetRef * inset = new InsetRef(p, *buffer_);
1941 if (!insertInset(inset))
1944 updateInset(inset, true);
1948 case LFUN_BOOKMARK_SAVE:
1949 savePosition(strToUnsignedInt(argument));
1952 case LFUN_BOOKMARK_GOTO:
1953 restorePosition(strToUnsignedInt(argument));
1958 string label(argument);
1959 if (label.empty()) {
1961 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1963 label = inset->getContents();
1968 if (!label.empty()) {
1969 //bv_->savePosition(0);
1970 if (!bv_->gotoLabel(label))
1971 Alert::alert(_("Error"),
1972 _("Couldn't find this label"),
1973 _("in current document."));
1978 // --- Cursor Movements -----------------------------
1981 LyXText * lt = bv_->getLyXText();
1983 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1984 if (!lt->selection.mark())
1986 update(lt, BufferView::SELECT|BufferView::FITCUR);
1988 lt->cursorLeft(bv_, false);
1989 if (lt->cursor.pos() < lt->cursor.par()->size()
1990 && lt->cursor.par()->isInset(lt->cursor.pos())
1991 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1992 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1993 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1995 tmpinset->edit(bv_, false);
1997 tmpinset->edit(bv_);
2001 lt->cursorRight(bv_, false);
2003 moveCursorUpdate(false);
2004 owner_->showState();
2010 // This is soooo ugly. Isn`t it possible to make
2011 // it simpler? (Lgb)
2012 LyXText * lt = bv_->getLyXText();
2013 bool const is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2014 if (!lt->selection.mark())
2016 update(lt, BufferView::SELECT|BufferView::FITCUR);
2017 LyXCursor const cur = lt->cursor;
2019 lt->cursorLeft(bv_, false);
2020 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2021 lt->cursor.pos() < lt->cursor.par()->size() &&
2022 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2023 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2024 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2025 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2027 tmpinset->edit(bv_);
2029 tmpinset->edit(bv_, false);
2033 lt->cursorRight(bv_, false);
2036 moveCursorUpdate(false);
2037 owner_->showState();
2043 LyXText * lt = bv_->getLyXText();
2045 if (!lt->selection.mark())
2047 update(lt, BufferView::UPDATE);
2050 moveCursorUpdate(false);
2051 owner_->showState();
2057 LyXText * lt = bv_->getLyXText();
2059 if (!lt->selection.mark())
2061 update(lt, BufferView::UPDATE);
2062 lt->cursorDown(bv_);
2064 moveCursorUpdate(false);
2065 owner_->showState();
2069 case LFUN_UP_PARAGRAPH:
2071 LyXText * lt = bv_->getLyXText();
2073 if (!lt->selection.mark())
2075 update(lt, BufferView::UPDATE);
2076 lt->cursorUpParagraph(bv_);
2078 moveCursorUpdate(false);
2079 owner_->showState();
2083 case LFUN_DOWN_PARAGRAPH:
2085 LyXText * lt = bv_->getLyXText();
2087 if (!lt->selection.mark())
2089 update(lt, BufferView::UPDATE);
2090 lt->cursorDownParagraph(bv_);
2092 moveCursorUpdate(false);
2093 owner_->showState();
2099 LyXText * lt = bv_->getLyXText();
2101 if (!lt->selection.mark())
2103 update(lt, BufferView::UPDATE);
2106 moveCursorUpdate(false, false);
2107 owner_->showState();
2113 LyXText * lt = bv_->getLyXText();
2115 if (!lt->selection.mark())
2117 update(lt, BufferView::UPDATE);
2120 moveCursorUpdate(false, false);
2121 owner_->showState();
2127 LyXText * lt = bv_->getLyXText();
2129 if (!lt->selection.mark())
2131 update(lt, BufferView::SELECT|BufferView::FITCUR);
2132 lt->cursorHome(bv_);
2134 moveCursorUpdate(false);
2135 owner_->showState();
2141 LyXText * lt = bv_->getLyXText();
2143 if (!lt->selection.mark())
2146 BufferView::SELECT|BufferView::FITCUR);
2149 moveCursorUpdate(false);
2150 owner_->showState();
2154 case LFUN_SHIFT_TAB:
2157 LyXText * lt = bv_->getLyXText();
2159 if (!lt->selection.mark())
2162 BufferView::SELECT|BufferView::FITCUR);
2165 moveCursorUpdate(false);
2166 owner_->showState();
2170 case LFUN_WORDRIGHT:
2172 LyXText * lt = bv_->getLyXText();
2174 if (!lt->selection.mark())
2176 update(lt, BufferView::SELECT|BufferView::FITCUR);
2177 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2178 lt->cursorLeftOneWord(bv_);
2180 lt->cursorRightOneWord(bv_);
2182 moveCursorUpdate(false);
2183 owner_->showState();
2189 LyXText * lt = bv_->getLyXText();
2191 if (!lt->selection.mark())
2193 update(lt, BufferView::SELECT|BufferView::FITCUR);
2194 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2195 lt->cursorRightOneWord(bv_);
2197 lt->cursorLeftOneWord(bv_);
2199 moveCursorUpdate(false);
2200 owner_->showState();
2204 case LFUN_BEGINNINGBUF:
2206 LyXText * lt = bv_->getLyXText();
2208 if (!lt->selection.mark())
2211 BufferView::SELECT|BufferView::FITCUR);
2214 moveCursorUpdate(false);
2215 owner_->showState();
2221 LyXText * lt = bv_->getLyXText();
2223 if (!lt->selection.mark())
2226 BufferView::SELECT|BufferView::FITCUR);
2227 lt->cursorBottom(bv_);
2229 moveCursorUpdate(false);
2230 owner_->showState();
2234 /* cursor selection ---------------------------- */
2237 LyXText * lt = bv_->getLyXText();
2240 BufferView::SELECT|BufferView::FITCUR);
2241 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2242 lt->cursorLeft(bv_);
2244 lt->cursorRight(bv_);
2246 moveCursorUpdate(true);
2247 owner_->showState();
2253 LyXText * lt = bv_->getLyXText();
2256 BufferView::SELECT|BufferView::FITCUR);
2257 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2258 lt->cursorRight(bv_);
2260 lt->cursorLeft(bv_);
2262 moveCursorUpdate(true);
2263 owner_->showState();
2269 LyXText * lt = bv_->getLyXText();
2272 BufferView::SELECT|BufferView::FITCUR);
2273 lt->cursorUp(bv_, true);
2275 moveCursorUpdate(true);
2276 owner_->showState();
2282 LyXText * lt = bv_->getLyXText();
2285 BufferView::SELECT|BufferView::FITCUR);
2286 lt->cursorDown(bv_, true);
2288 moveCursorUpdate(true);
2289 owner_->showState();
2293 case LFUN_UP_PARAGRAPHSEL:
2295 LyXText * lt = bv_->getLyXText();
2298 BufferView::SELECT|BufferView::FITCUR);
2299 lt->cursorUpParagraph(bv_);
2301 moveCursorUpdate(true);
2302 owner_->showState();
2306 case LFUN_DOWN_PARAGRAPHSEL:
2308 LyXText * lt = bv_->getLyXText();
2311 BufferView::SELECT|BufferView::FITCUR);
2312 lt->cursorDownParagraph(bv_);
2314 moveCursorUpdate(true);
2315 owner_->showState();
2321 LyXText * lt = bv_->getLyXText();
2323 update(lt, BufferView::SELECT|BufferView::FITCUR);
2326 moveCursorUpdate(true);
2327 owner_->showState();
2333 LyXText * lt = bv_->getLyXText();
2335 update(lt, BufferView::SELECT|BufferView::FITCUR);
2338 moveCursorUpdate(true);
2339 owner_->showState();
2345 LyXText * lt = bv_->getLyXText();
2347 update(lt, BufferView::SELECT|BufferView::FITCUR);
2348 lt->cursorHome(bv_);
2350 moveCursorUpdate(true);
2351 owner_->showState();
2357 LyXText * lt = bv_->getLyXText();
2359 update(lt, BufferView::SELECT|BufferView::FITCUR);
2362 moveCursorUpdate(true);
2363 owner_->showState();
2367 case LFUN_WORDRIGHTSEL:
2369 LyXText * lt = bv_->getLyXText();
2371 update(lt, BufferView::SELECT|BufferView::FITCUR);
2372 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2373 lt->cursorLeftOneWord(bv_);
2375 lt->cursorRightOneWord(bv_);
2377 moveCursorUpdate(true);
2378 owner_->showState();
2382 case LFUN_WORDLEFTSEL:
2384 LyXText * lt = bv_->getLyXText();
2386 update(lt, BufferView::SELECT|BufferView::FITCUR);
2387 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2388 lt->cursorRightOneWord(bv_);
2390 lt->cursorLeftOneWord(bv_);
2392 moveCursorUpdate(true);
2393 owner_->showState();
2397 case LFUN_BEGINNINGBUFSEL:
2399 LyXText * lt = bv_->getLyXText();
2401 if (lt->inset_owner)
2403 update(lt, BufferView::SELECT|BufferView::FITCUR);
2406 moveCursorUpdate(true);
2407 owner_->showState();
2411 case LFUN_ENDBUFSEL:
2413 LyXText * lt = bv_->getLyXText();
2415 if (lt->inset_owner)
2418 BufferView::SELECT|BufferView::FITCUR);
2419 lt->cursorBottom(bv_);
2421 moveCursorUpdate(true);
2422 owner_->showState();
2426 // --- text changing commands ------------------------
2427 case LFUN_BREAKLINE:
2429 LyXText * lt = bv_->getLyXText();
2432 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2435 | BufferView::FITCUR
2436 | BufferView::CHANGE);
2437 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2438 moveCursorUpdate(false);
2442 case LFUN_PROTECTEDSPACE:
2444 LyXText * lt = bv_->getLyXText();
2446 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2448 if (style.free_spacing) {
2449 lt->insertChar(bv_, ' ');
2452 | BufferView::FITCUR
2453 | BufferView::CHANGE);
2455 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2457 moveCursorUpdate(false);
2463 LyXText * lt = bv_->getLyXText();
2465 if (lt->selection.mark()) {
2469 | BufferView::FITCUR);
2470 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2473 lt->selection.mark(true);
2476 | BufferView::FITCUR);
2477 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2479 lt->selection.cursor = lt->cursor;
2485 LyXText * lt = bv_->getLyXText();
2487 if (!lt->selection.set()) {
2489 lt->selection.cursor = lt->cursor;
2492 | BufferView::FITCUR
2493 | BufferView::CHANGE);
2494 // It is possible to make it a lot faster still
2495 // just comment out the line below...
2500 moveCursorUpdate(false);
2501 owner_->showState();
2506 case LFUN_DELETE_SKIP:
2508 LyXText * lt = bv_->getLyXText();
2510 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2512 LyXCursor cursor = lt->cursor;
2514 if (!lt->selection.set()) {
2515 if (cursor.pos() == cursor.par()->size()) {
2516 lt->cursorRight(bv_);
2517 cursor = lt->cursor;
2518 if (cursor.pos() == 0
2519 && !(cursor.par()->params().spaceTop()
2520 == VSpace (VSpace::NONE))) {
2523 cursor.par()->params().lineTop(),
2524 cursor.par()->params().lineBottom(),
2525 cursor.par()->params().pagebreakTop(),
2526 cursor.par()->params().pagebreakBottom(),
2527 VSpace(VSpace::NONE),
2528 cursor.par()->params().spaceBottom(),
2529 cursor.par()->params().spacing(),
2530 cursor.par()->params().align(),
2531 cursor.par()->params().labelWidthString(), 0);
2532 lt->cursorLeft(bv_);
2535 | BufferView::FITCUR
2536 | BufferView::CHANGE);
2538 lt->cursorLeft(bv_);
2540 lt->selection.cursor = lt->cursor;
2543 | BufferView::FITCUR
2544 | BufferView::CHANGE);
2548 lt->selection.cursor = lt->cursor;
2551 | BufferView::FITCUR
2552 | BufferView::CHANGE);
2560 /* -------> Delete word forward. */
2561 case LFUN_DELETE_WORD_FORWARD:
2562 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2563 bv_->getLyXText()->deleteWordForward(bv_);
2564 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2565 moveCursorUpdate(false);
2566 owner_->showState();
2569 /* -------> Delete word backward. */
2570 case LFUN_DELETE_WORD_BACKWARD:
2572 LyXText * lt = bv_->getLyXText();
2574 update(lt, BufferView::SELECT|BufferView::FITCUR);
2575 lt->deleteWordBackward(bv_);
2578 | BufferView::FITCUR
2579 | BufferView::CHANGE);
2580 moveCursorUpdate(false);
2581 owner_->showState();
2585 /* -------> Kill to end of line. */
2586 case LFUN_DELETE_LINE_FORWARD:
2588 LyXText * lt = bv_->getLyXText();
2590 update(lt, BufferView::SELECT|BufferView::FITCUR);
2591 lt->deleteLineForward(bv_);
2594 | BufferView::FITCUR
2595 | BufferView::CHANGE);
2596 moveCursorUpdate(false);
2600 /* -------> Set mark off. */
2603 LyXText * lt = bv_->getLyXText();
2606 update(lt, BufferView::SELECT|BufferView::FITCUR);
2607 lt->selection.cursor = lt->cursor;
2608 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2612 /* -------> Set mark on. */
2615 LyXText * lt = bv_->getLyXText();
2618 lt->selection.mark(true);
2619 update(lt, BufferView::SELECT|BufferView::FITCUR);
2620 lt->selection.cursor = lt->cursor;
2621 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2625 case LFUN_BACKSPACE:
2627 LyXText * lt = bv_->getLyXText();
2629 if (!lt->selection.set()) {
2630 if (owner_->getIntl()->getTrans().backspace()) {
2632 lt->selection.cursor = lt->cursor;
2635 | BufferView::FITCUR
2636 | BufferView::CHANGE);
2637 // It is possible to make it a lot faster still
2638 // just comment out the line below...
2644 owner_->showState();
2649 case LFUN_BACKSPACE_SKIP:
2651 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2652 LyXText * lt = bv_->getLyXText();
2654 LyXCursor cursor = lt->cursor;
2656 if (!lt->selection.set()) {
2657 if (cursor.pos() == 0
2658 && !(cursor.par()->params().spaceTop()
2659 == VSpace (VSpace::NONE))) {
2662 cursor.par()->params().lineTop(),
2663 cursor.par()->params().lineBottom(),
2664 cursor.par()->params().pagebreakTop(),
2665 cursor.par()->params().pagebreakBottom(),
2666 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2667 cursor.par()->params().spacing(),
2668 cursor.par()->params().align(),
2669 cursor.par()->params().labelWidthString(), 0);
2672 | BufferView::FITCUR
2673 | BufferView::CHANGE);
2676 lt->selection.cursor = cursor;
2679 | BufferView::FITCUR
2680 | BufferView::CHANGE);
2687 case LFUN_BREAKPARAGRAPH:
2689 LyXText * lt = bv_->getLyXText();
2692 lt->breakParagraph(bv_, 0);
2695 | BufferView::FITCUR
2696 | BufferView::CHANGE);
2697 lt->selection.cursor = lt->cursor;
2699 owner_->showState();
2703 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2705 LyXText * lt = bv_->getLyXText();
2708 lt->breakParagraph(bv_, 1);
2711 | BufferView::FITCUR
2712 | BufferView::CHANGE);
2713 lt->selection.cursor = lt->cursor;
2715 owner_->showState();
2719 case LFUN_BREAKPARAGRAPH_SKIP:
2721 // When at the beginning of a paragraph, remove
2722 // indentation and add a "defskip" at the top.
2723 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2724 LyXText * lt = bv_->getLyXText();
2726 LyXCursor cursor = lt->cursor;
2729 if (cursor.pos() == 0) {
2730 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2733 cursor.par()->params().lineTop(),
2734 cursor.par()->params().lineBottom(),
2735 cursor.par()->params().pagebreakTop(),
2736 cursor.par()->params().pagebreakBottom(),
2737 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2738 cursor.par()->params().spacing(),
2739 cursor.par()->params().align(),
2740 cursor.par()->params().labelWidthString(), 1);
2741 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2745 lt->breakParagraph(bv_, 0);
2746 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2751 | BufferView::FITCUR
2752 | BufferView::CHANGE);
2753 lt->selection.cursor = cursor;
2755 owner_->showState();
2759 case LFUN_PARAGRAPH_SPACING:
2761 LyXText * lt = bv_->getLyXText();
2763 Paragraph * par = lt->cursor.par();
2764 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2765 float cur_value = 1.0;
2766 if (cur_spacing == Spacing::Other) {
2767 cur_value = par->params().spacing().getValue();
2770 istringstream istr(argument.c_str());
2774 Spacing::Space new_spacing = cur_spacing;
2775 float new_value = cur_value;
2777 lyxerr << "Missing argument to `paragraph-spacing'"
2779 } else if (tmp == "single") {
2780 new_spacing = Spacing::Single;
2781 } else if (tmp == "onehalf") {
2782 new_spacing = Spacing::Onehalf;
2783 } else if (tmp == "double") {
2784 new_spacing = Spacing::Double;
2785 } else if (tmp == "other") {
2786 new_spacing = Spacing::Other;
2789 lyxerr << "new_value = " << tmpval << endl;
2792 } else if (tmp == "default") {
2793 new_spacing = Spacing::Default;
2795 lyxerr << _("Unknown spacing argument: ")
2796 << argument << endl;
2798 if (cur_spacing != new_spacing || cur_value != new_value) {
2799 par->params().spacing(Spacing(new_spacing, new_value));
2800 lt->redoParagraph(bv_);
2803 | BufferView::FITCUR
2804 | BufferView::CHANGE);
2809 case LFUN_INSET_TOGGLE:
2811 LyXText * lt = bv_->getLyXText();
2814 update(lt, BufferView::SELECT|BufferView::FITCUR);
2815 lt->toggleInset(bv_);
2816 update(lt, BufferView::SELECT|BufferView::FITCUR);
2828 InsetCommandParams p;
2829 if (action == LFUN_HTMLURL)
2830 p.setCmdName("htmlurl");
2832 p.setCmdName("url");
2833 owner_->getDialogs()->createUrl(p.getAsString());
2837 case LFUN_INSERT_URL:
2839 InsetCommandParams p;
2840 p.setFromString(argument);
2842 InsetUrl * inset = new InsetUrl(p);
2843 if (!insertInset(inset))
2846 updateInset(inset, true);
2850 case LFUN_INSET_ERT:
2851 insertAndEditInset(new InsetERT(buffer_->params));
2854 case LFUN_INSET_EXTERNAL:
2855 insertAndEditInset(new InsetExternal);
2858 case LFUN_INSET_FOOTNOTE:
2859 insertAndEditInset(new InsetFoot(buffer_->params));
2862 case LFUN_INSET_MARGINAL:
2863 insertAndEditInset(new InsetMarginal(buffer_->params));
2866 case LFUN_INSET_MINIPAGE:
2867 insertAndEditInset(new InsetMinipage(buffer_->params));
2870 case LFUN_INSERT_NOTE:
2871 insertAndEditInset(new InsetNote(buffer_->params));
2874 case LFUN_INSET_FLOAT:
2875 // check if the float type exist
2876 if (floatList.typeExist(argument)) {
2877 insertAndEditInset(new InsetFloat(buffer_->params,
2880 lyxerr << "Non-existent float type: "
2881 << argument << endl;
2885 case LFUN_INSET_WIDE_FLOAT:
2886 // check if the float type exist
2887 if (floatList.typeExist(argument)) {
2888 InsetFloat * new_inset =
2889 new InsetFloat(buffer_->params, argument);
2890 new_inset->wide(true);
2891 insertAndEditInset(new_inset);
2893 lyxerr << "Non-existent float type: "
2894 << argument << endl;
2899 case LFUN_INSET_LIST:
2900 insertAndEditInset(new InsetList);
2903 case LFUN_INSET_THEOREM:
2904 insertAndEditInset(new InsetTheorem);
2908 case LFUN_INSET_CAPTION:
2910 // Do we have a locking inset...
2911 if (bv_->theLockingInset()) {
2912 lyxerr << "Locking inset code: "
2913 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2914 InsetCaption * new_inset =
2915 new InsetCaption(buffer_->params);
2916 new_inset->setOwner(bv_->theLockingInset());
2917 new_inset->setAutoBreakRows(true);
2918 new_inset->setDrawFrame(0, InsetText::LOCKED);
2919 new_inset->setFrameColor(0, LColor::captionframe);
2920 if (insertInset(new_inset))
2921 new_inset->edit(bv_);
2928 case LFUN_INSET_TABULAR:
2932 if (!argument.empty())
2933 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2934 InsetTabular * new_inset =
2935 new InsetTabular(*buffer_, r, c);
2937 bv_->getLyXText()->real_current_font.isRightToLeft();
2938 if (!open_new_inset(new_inset, rtl))
2943 // --- lyxserver commands ----------------------------
2945 case LFUN_CHARATCURSOR:
2947 pos_type pos = bv_->getLyXText()->cursor.pos();
2948 if (pos < bv_->getLyXText()->cursor.par()->size())
2949 owner_->getLyXFunc()->setMessage(
2950 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2952 owner_->getLyXFunc()->setMessage("EOF");
2957 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2959 + tostr(bv_->getLyXText()->cursor.y()));
2966 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2967 lyxerr << "SETXY: Could not parse coordinates in '"
2968 << argument << std::endl;
2970 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2974 case LFUN_GETLAYOUT:
2975 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2980 LyXFont & font = bv_->getLyXText()->current_font;
2981 if (font.shape() == LyXFont::ITALIC_SHAPE)
2982 owner_->getLyXFunc()->setMessage("E");
2983 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2984 owner_->getLyXFunc()->setMessage("N");
2986 owner_->getLyXFunc()->setMessage("0");
2991 // --- accented characters ---------------------------
2994 case LFUN_CIRCUMFLEX:
3004 case LFUN_SPECIAL_CARON:
3007 case LFUN_HUNG_UMLAUT:
3010 if (argument.empty()) {
3012 owner_->getLyXFunc()->handleKeyFunc(action);
3014 owner_->getLyXFunc()->handleKeyFunc(action);
3015 owner_->getIntl()->getTrans()
3016 .TranslateAndInsert(argument[0], bv_->getLyXText());
3017 update(bv_->getLyXText(),
3019 | BufferView::FITCUR
3020 | BufferView::CHANGE);
3024 case LFUN_MATH_MACRO:
3025 mathDispatchMathMacro(bv_, argument);
3028 case LFUN_MATH_DELIM:
3029 mathDispatchMathDelim(bv_, argument);
3032 case LFUN_INSERT_MATRIX:
3033 mathDispatchInsertMatrix(bv_, argument);
3036 case LFUN_INSERT_MATH:
3037 mathDispatchInsertMath(bv_, argument);
3040 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3041 mathDispatchMathImportSelection(bv_, argument);
3044 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3045 mathDispatchMathDisplay(bv_, argument);
3048 case LFUN_MATH_MODE: // Open or create an inlined math inset
3049 mathDispatchMathMode(bv_, argument);
3052 case LFUN_GREEK: // Insert a single greek letter
3053 mathDispatchGreek(bv_, argument);
3056 case LFUN_CITATION_INSERT:
3058 InsetCommandParams p;
3059 p.setFromString(argument);
3061 InsetCitation * inset = new InsetCitation(p);
3062 if (!insertInset(inset))
3065 updateInset(inset, true);
3069 case LFUN_INSERT_BIBTEX:
3071 // ale970405+lasgoutt970425
3072 // The argument can be up to two tokens separated
3073 // by a space. The first one is the bibstyle.
3074 string const db = token(argument, ' ', 0);
3075 string const bibstyle = token(argument, ' ', 1);
3077 InsetCommandParams p("BibTeX", db, bibstyle);
3078 InsetBibtex * inset = new InsetBibtex(p);
3080 if (insertInset(inset)) {
3081 if (argument.empty())
3088 // BibTeX data bases
3089 case LFUN_BIBDB_ADD:
3091 InsetBibtex * inset =
3092 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3094 inset->addDatabase(argument);
3099 case LFUN_BIBDB_DEL:
3101 InsetBibtex * inset =
3102 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3104 inset->delDatabase(argument);
3109 case LFUN_BIBTEX_STYLE:
3111 InsetBibtex * inset =
3112 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3114 inset->setOptions(argument);
3119 case LFUN_INDEX_CREATE:
3121 InsetCommandParams p("index");
3122 if (argument.empty()) {
3123 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3124 p.setContents(idxstring);
3126 p.setContents(argument);
3129 owner_->getDialogs()->createIndex(p.getAsString());
3133 case LFUN_INDEX_INSERT:
3135 InsetCommandParams p;
3136 p.setFromString(argument);
3137 InsetIndex * inset = new InsetIndex(p);
3139 if (!insertInset(inset))
3142 updateInset(inset, true);
3146 case LFUN_INDEX_INSERT_LAST:
3148 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3149 if (!idxstring.empty()) {
3150 owner_->message(_("Word `")
3151 + idxstring + _(("' indexed.")));
3152 InsetCommandParams p("index", idxstring);
3153 InsetIndex * inset = new InsetIndex(p);
3155 if (!insertInset(inset))
3158 updateInset(inset, true);
3163 case LFUN_INDEX_PRINT:
3165 InsetCommandParams p("printindex");
3166 Inset * inset = new InsetPrintIndex(p);
3167 if (!insertInset(inset, tclass.defaultLayoutName()))
3172 case LFUN_PARENTINSERT:
3174 InsetCommandParams p("lyxparent", argument);
3175 Inset * inset = new InsetParent(p, *buffer_);
3176 if (!insertInset(inset, tclass.defaultLayoutName()))
3182 case LFUN_CHILD_INSERT:
3184 InsetInclude::Params p;
3185 p.cparams.setFromString(argument);
3186 p.masterFilename_ = buffer_->fileName();
3188 InsetInclude * inset = new InsetInclude(p);
3189 if (!insertInset(inset))
3192 updateInset(inset, true);
3193 bv_->owner()->getDialogs()->showInclude(inset);
3198 case LFUN_FLOAT_LIST:
3199 if (floatList.typeExist(argument)) {
3200 Inset * inset = new InsetFloatList(argument);
3201 if (!insertInset(inset, tclass.defaultLayoutName()))
3204 lyxerr << "Non-existent float type: "
3205 << argument << endl;
3209 case LFUN_THESAURUS_ENTRY:
3211 string arg = argument;
3214 arg = bv_->getLyXText()->selectionAsString(buffer_,
3218 if (arg.size() > 100 || arg.empty()) {
3219 // Get word or selection
3220 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3221 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3222 // FIXME: where is getLyXText()->unselect(bv_) ?
3226 bv_->owner()->getDialogs()->showThesaurus(arg);
3230 case LFUN_SELFINSERT:
3232 if (argument.empty()) break;
3234 /* Automatically delete the currently selected
3235 * text and replace it with what is being
3236 * typed in now. Depends on lyxrc settings
3237 * "auto_region_delete", which defaults to
3240 LyXText * lt = bv_->getLyXText();
3242 if (lyxrc.auto_region_delete) {
3243 if (lt->selection.set()) {
3244 lt->cutSelection(bv_, false, false);
3247 | BufferView::FITCUR
3248 | BufferView::CHANGE);
3250 workarea().haveSelection(false);
3254 LyXFont const old_font(lt->real_current_font);
3256 string::const_iterator cit = argument.begin();
3257 string::const_iterator end = argument.end();
3258 for (; cit != end; ++cit) {
3259 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3264 | BufferView::FITCUR
3265 | BufferView::CHANGE);
3267 lt->selection.cursor = lt->cursor;
3268 moveCursorUpdate(false);
3270 // real_current_font.number can change so we need to
3271 // update the minibuffer
3272 if (old_font != lt->real_current_font)
3273 owner_->showState();
3278 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3280 time_t now_time_t = time(NULL);
3281 struct tm * now_tm = localtime(&now_time_t);
3282 setlocale(LC_TIME, "");
3284 if (!argument.empty())
3287 arg = lyxrc.date_insert_format;
3289 int const datetmp_len =
3290 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3292 LyXText * lt = bv_->getLyXText();
3294 for (int i = 0; i < datetmp_len; i++) {
3295 lt->insertChar(bv_, datetmp[i]);
3298 | BufferView::FITCUR
3299 | BufferView::CHANGE);
3302 lt->selection.cursor = lt->cursor;
3303 moveCursorUpdate(false);
3307 case LFUN_UNKNOWN_ACTION:
3308 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3319 void BufferView::Pimpl::newline()
3322 LyXText * lt = bv_->getLyXText();
3326 | BufferView::FITCUR);
3327 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3330 | BufferView::FITCUR
3331 | BufferView::CHANGE);
3336 void BufferView::Pimpl::hfill()
3339 LyXText * lt = bv_->getLyXText();
3343 | BufferView::FITCUR);
3344 lt->insertChar(bv_, Paragraph::META_HFILL);
3347 | BufferView::FITCUR
3348 | BufferView::CHANGE);
3353 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3356 LyXText * lt = bv_->getLyXText();
3359 update(lt, BufferView::SELECT|BufferView::FITCUR);
3360 InsetSpecialChar * new_inset =
3361 new InsetSpecialChar(kind);
3362 if (!insertInset(new_inset))
3365 updateInset(new_inset, true);
3370 void BufferView::Pimpl::smartQuote()
3372 LyXText const * lt = bv_->getLyXText();
3373 Paragraph const * par = lt->cursor.par();
3374 pos_type pos = lt->cursor.pos();
3378 || (par->isInset(pos - 1)
3379 && par->getInset(pos - 1)->isSpace()))
3382 c = par->getChar(pos - 1);
3387 LyXLayout const & style =
3388 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3390 if (style.pass_thru ||
3391 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3392 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3396 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3398 if (insertInset(inset))
3405 // Open and lock an updatable inset
3406 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3408 LyXText * lt = bv_->getLyXText();
3412 if (!insertInset(new_inset)) {
3416 new_inset->edit(bv_, !behind);
3421 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3423 // if we are in a locking inset we should try to insert the
3424 // inset there otherwise this is a illegal function now
3425 if (bv_->theLockingInset()) {
3426 if (bv_->theLockingInset()->insetAllowed(inset))
3427 return bv_->theLockingInset()->insertInset(bv_, inset);
3431 // not quite sure if we want this...
3432 setCursorParUndo(bv_);
3435 beforeChange(bv_->text);
3436 if (!lout.empty()) {
3437 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3438 bv_->text->breakParagraph(bv_);
3439 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3441 if (bv_->text->cursor.par()->size()) {
3442 bv_->text->cursorLeft(bv_);
3444 bv_->text->breakParagraph(bv_);
3445 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3449 LyXTextClass const & tclass =
3450 textclasslist[buffer_->params.textclass];
3451 bool hasLayout = tclass.hasLayout(lres);
3452 string lay = tclass.defaultLayoutName();
3454 if (hasLayout != false) {
3458 // layout not fount using default
3459 lay = tclass.defaultLayoutName();
3462 bv_->text->setLayout(bv_, lay);
3464 bv_->text->setParagraph(bv_, 0, 0,
3466 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3471 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3474 bv_->text->insertInset(bv_, inset);
3475 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3482 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3484 if (!inset || !available())
3487 // first check for locking insets
3488 if (bv_->theLockingInset()) {
3489 if (bv_->theLockingInset() == inset) {
3490 if (bv_->text->updateInset(bv_, inset)) {
3493 buffer_->markDirty();
3498 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3499 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3502 buffer_->markDirty();
3510 // then check if the inset is a top_level inset (has no owner)
3511 // if yes do the update as always otherwise we have to update the
3512 // toplevel inset where this inset is inside
3513 Inset * tl_inset = inset;
3514 while(tl_inset->owner())
3515 tl_inset = tl_inset->owner();
3517 if (tl_inset == inset) {
3518 update(bv_->text, BufferView::UPDATE);
3519 if (bv_->text->updateInset(bv_, inset)) {
3523 | BufferView::FITCUR
3524 | BufferView::CHANGE);
3526 update(bv_->text, SELECT);
3530 } else if (static_cast<UpdatableInset *>(tl_inset)
3531 ->updateInsetInInset(bv_, inset))
3533 if (bv_->text->updateInset(bv_, tl_inset)) {
3541 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3544 if (!available()) return;
3547 beforeChange(bv_->text);
3548 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3550 LyXCursor const & cursor = bv_->text->cursor;
3554 cursor.par()->isInset(cursor.pos())) {
3555 Inset const * inset = cursor.par()->getInset(cursor.pos());
3556 if (find(codes.begin(), codes.end(), inset->lyxCode())
3559 static_cast<InsetCommand const *>(inset)->getContents();
3563 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3564 if (bv_->text->cursor.pos()
3565 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3566 LyXCursor tmp = bv_->text->cursor;
3567 bv_->text->cursor.par(bv_->text->ownerParagraph());
3568 bv_->text->cursor.pos(0);
3569 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3570 bv_->text->cursor = tmp;
3571 bv_->owner()->message(_("No more insets"));
3574 bv_->owner()->message(_("No more insets"));
3577 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3578 bv_->text->selection.cursor = bv_->text->cursor;
3582 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3584 gotoInset(vector<Inset::Code>(1, code), same_content);