7 #include "BufferView_pimpl.h"
8 #include "frontends/WorkArea.h"
9 #include "frontends/screen.h"
10 #include "frontends/Dialogs.h"
11 #include "frontends/Alert.h"
12 #include "frontends/FileDialog.h"
15 #include "paragraph.h"
16 #include "frontends/LyXView.h"
17 #include "commandtags.h"
20 #include "bufferview_funcs.h"
21 #include "TextCache.h"
22 #include "bufferlist.h"
25 // added for Dispatch functions
28 #include "FloatList.h"
30 #include "ParagraphParameters.h"
31 #include "undo_funcs.h"
32 #include "lyxtextclasslist.h"
35 #include "insets/insetbib.h"
36 #include "insets/insettext.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetnote.h"
44 #include "insets/insetinclude.h"
45 #include "insets/insetcite.h"
46 #include "insets/insetert.h"
47 #include "insets/insetexternal.h"
48 #include "insets/insetgraphics.h"
49 #include "insets/insetfoot.h"
50 #include "insets/insetmarginal.h"
51 #include "insets/insetminipage.h"
52 #include "insets/insetfloat.h"
53 #include "insets/insettabular.h"
55 #include "insets/insettheorem.h"
56 #include "insets/insetlist.h"
58 #include "insets/insetcaption.h"
59 #include "insets/insetfloatlist.h"
60 #include "insets/insetspecialchar.h"
62 #include "mathed/formulabase.h"
64 #include "support/LAssert.h"
65 #include "support/lstrings.h"
66 #include "support/filetools.h"
67 #include "support/lyxfunctional.h"
69 #include <boost/bind.hpp>
77 extern string current_layout;
79 #ifndef CXX_GLOBAL_CSTD
96 using lyx::textclass_type;
98 /* the selection possible is needed, that only motion events are
99 * used, where the bottom press event was on the drawing area too */
100 bool selection_possible = false;
102 extern BufferList bufferlist;
103 extern char ascii_type;
105 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
110 const unsigned int saved_positions_num = 20;
115 XSync(fl_get_display(), 0);
119 void SetXtermCursor(Window win)
121 static Cursor cursor;
122 static bool cursor_undefined = true;
123 if (cursor_undefined) {
124 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
125 XFlush(fl_get_display());
126 cursor_undefined = false;
128 XDefineCursor(fl_get_display(), win, cursor);
129 XFlush(fl_get_display());
135 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
136 int xpos, int ypos, int width, int height)
137 : bv_(b), owner_(o), buffer_(0),
138 current_scrollbar_value(0), cursor_timeout(400),
139 using_xterm_cursor(false), inset_slept(false)
141 workarea_.reset(new WorkArea(xpos, ypos, width, height));
142 screen_.reset(new LScreen(workarea()));
145 workarea().scrollCB.connect(boost::bind(&BufferView::Pimpl::scrollCB, this, _1));
146 workarea().workAreaExpose
147 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
148 workarea().workAreaEnter
149 .connect(boost::bind(&BufferView::Pimpl::enterView, this));
150 workarea().workAreaLeave
151 .connect(boost::bind(&BufferView::Pimpl::leaveView, this));
152 workarea().workAreaButtonPress
153 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
154 workarea().workAreaButtonRelease
155 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
156 workarea().workAreaMotionNotify
157 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
158 workarea().workAreaDoubleClick
159 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
160 workarea().workAreaTripleClick
161 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
162 workarea().workAreaKeyPress
163 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
164 workarea().selectionRequested
165 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
166 workarea().selectionLost
167 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
169 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
170 cursor_timeout.start();
171 workarea().setFocus();
172 saved_positions.resize(saved_positions_num);
176 WorkArea & BufferView::Pimpl::workarea() const
178 return *workarea_.get();
182 LScreen & BufferView::Pimpl::screen() const
184 return *screen_.get();
188 Painter & BufferView::Pimpl::painter()
190 return workarea().getPainter();
194 void BufferView::Pimpl::buffer(Buffer * b)
196 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);
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);
247 lyxerr[Debug::INFO] << " No Buffer!" << endl;
248 owner_->updateMenubar();
249 owner_->updateToolbar();
250 owner_->getDialogs()->hideBufferDependent();
254 // Also remove all remaining text's from the testcache.
255 // (there should not be any!) (if there is any it is a
257 if (lyxerr.debugging())
258 textcache.show(lyxerr, "buffer delete all");
261 // should update layoutchoice even if we don't have a buffer.
262 owner_->updateLayoutChoice();
264 owner_->updateWindowTitle();
268 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
270 workarea().resize(xpos, ypos, width, height);
271 update(bv_->text, SELECT);
276 void BufferView::Pimpl::resize()
279 resizeCurrentBuffer();
283 void BufferView::Pimpl::redraw()
285 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
290 bool BufferView::Pimpl::fitCursor()
294 if (bv_->theLockingInset()) {
295 bv_->theLockingInset()->fitInsetCursor(bv_);
298 ret = screen().fitCursor(bv_->text, bv_);
301 bv_->owner()->getDialogs()->updateParagraph();
308 void BufferView::Pimpl::redoCurrentBuffer()
310 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
311 if (buffer_ && bv_->text) {
313 owner_->updateLayoutChoice();
318 int BufferView::Pimpl::resizeCurrentBuffer()
320 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
323 Paragraph * selstartpar = 0;
324 Paragraph * selendpar = 0;
325 UpdatableInset * the_locking_inset = 0;
328 pos_type selstartpos = 0;
329 pos_type selendpos = 0;
330 bool selection = false;
331 bool mark_set = false;
333 owner_->prohibitInput();
335 owner_->message(_("Formatting document..."));
338 par = bv_->text->cursor.par();
339 pos = bv_->text->cursor.pos();
340 selstartpar = bv_->text->selection.start.par();
341 selstartpos = bv_->text->selection.start.pos();
342 selendpar = bv_->text->selection.end.par();
343 selendpos = bv_->text->selection.end.pos();
344 selection = bv_->text->selection.set();
345 mark_set = bv_->text->selection.mark();
346 the_locking_inset = bv_->theLockingInset();
347 buffer_->resizeInsets(bv_);
348 // I don't think the delete and new are necessary here we just could
349 // call only init! (Jug 20020419)
351 bv_->text = new LyXText(bv_);
352 bv_->text->init(bv_);
354 // See if we have a text in TextCache that fits
355 // the new buffer_ with the correct width.
356 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
358 if (lyxerr.debugging()) {
359 lyxerr << "Found a LyXText that fits:\n";
360 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
362 // Set the owner of the newly found text
363 // bv_->text->owner(bv_);
364 if (lyxerr.debugging())
365 textcache.show(lyxerr, "resizeCurrentBuffer");
367 bv_->text = new LyXText(bv_);
368 bv_->text->init(bv_);
369 //buffer_->resizeInsets(bv_);
376 bv_->text->selection.set(true);
377 // At this point just to avoid the Delete-Empty-Paragraph-
378 // Mechanism when setting the cursor.
379 bv_->text->selection.mark(mark_set);
381 bv_->text->setCursor(bv_, selstartpar, selstartpos);
382 bv_->text->selection.cursor = bv_->text->cursor;
383 bv_->text->setCursor(bv_, selendpar, selendpos);
384 bv_->text->setSelection(bv_);
385 bv_->text->setCursor(bv_, par, pos);
387 bv_->text->setCursor(bv_, par, pos);
388 bv_->text->selection.cursor = bv_->text->cursor;
389 bv_->text->selection.set(false);
391 // remake the inset locking
392 bv_->theLockingInset(the_locking_inset);
395 bv_->text->first_y = screen().topCursorVisible(bv_->text);
397 // this will scroll the screen such that the cursor becomes visible
402 owner_->allowInput();
404 /// clear the "Formatting Document" message
411 void BufferView::Pimpl::updateScreen()
413 // Regenerate the screen.
418 void BufferView::Pimpl::updateScrollbar()
421 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
422 workarea().setScrollbar(0, 1.0);
426 long const text_height = bv_->text->height;
427 long const work_height = workarea().height();
429 double const lineh = bv_->text->defaultHeight();
430 double const slider_size =
431 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
433 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
434 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
436 /* If the text is smaller than the working area, the scrollbar
437 * maximum must be the working area height. No scrolling will
439 if (text_height <= work_height) {
440 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
441 workarea().setScrollbarBounds(0.0, 0.0);
442 current_scrollbar_value = bv_->text->first_y;
443 workarea().setScrollbar(current_scrollbar_value, 1.0);
447 workarea().setScrollbarBounds(0.0, text_height - work_height);
448 workarea().setScrollbarIncrements(lineh);
449 current_scrollbar_value = bv_->text->first_y;
450 workarea().setScrollbar(current_scrollbar_value, slider_size);
454 // Callback for scrollbar slider
455 void BufferView::Pimpl::scrollCB(double value)
457 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
459 if (!buffer_) return;
461 current_scrollbar_value = long(value);
463 if (current_scrollbar_value < 0)
464 current_scrollbar_value = 0;
466 screen().draw(bv_->text, bv_, current_scrollbar_value);
468 if (!lyxrc.cursor_follows_scrollbar) {
473 LyXText * vbt = bv_->text;
475 int const height = vbt->defaultHeight();
476 int const first = static_cast<int>((bv_->text->first_y + height));
477 int const last = static_cast<int>((bv_->text->first_y + workarea().height() - height));
479 if (vbt->cursor.y() < first)
480 vbt->setCursorFromCoordinates(bv_, 0, first);
481 else if (vbt->cursor.y() > last)
482 vbt->setCursorFromCoordinates(bv_, 0, last);
488 int BufferView::Pimpl::scrollUp(long time)
493 double value = workarea().getScrollbarValue();
499 float add_value = (bv_->text->defaultHeight()
500 + float(time) * float(time) * 0.125);
502 if (add_value > workarea().height())
503 add_value = float(workarea().height() -
504 bv_->text->defaultHeight());
506 float add_value = float(workarea().height()) * float(time) / 100;
514 workarea().setScrollbarValue(value);
521 int BufferView::Pimpl::scrollDown(long time)
526 double value = workarea().getScrollbarValue();
527 pair<float, float> p = workarea().getScrollbarBounds();
528 double const max = p.second;
534 float add_value = (bv_->text->defaultHeight()
535 + float(time) * float(time) * 0.125);
537 if (add_value > workarea().height())
538 add_value = float(workarea().height() -
539 bv_->text->defaultHeight());
541 float add_value = float(workarea().height()) * float(time) / 100;
549 workarea().setScrollbarValue(value);
556 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, key_modifier::state state)
558 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
562 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
564 // Only use motion with button 1
565 if (!(state & mouse_button::button1))
571 // Check for inset locking
572 if (bv_->theLockingInset()) {
573 LyXCursor cursor = bv_->text->cursor;
574 LyXFont font = bv_->text->getFont(buffer_,
575 cursor.par(), cursor.pos());
576 int width = bv_->theLockingInset()->width(bv_, font);
577 int inset_x = font.isVisibleRightToLeft()
578 ? cursor.ix() - width : cursor.ix();
579 int start_x = inset_x + bv_->theLockingInset()->scroll();
580 bv_->theLockingInset()->
581 insetMotionNotify(bv_,
583 y - cursor.iy() + bv_->text->first_y,
588 /* The test for not selection possible is needed, that only motion
589 events are used, where the bottom press event was on
590 the drawing area too */
591 if (!selection_possible)
594 screen().hideCursor();
596 int y_before = bv_->text->cursor.y();
598 Row * cursorrow = bv_->text->cursor.row();
599 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
601 // sorry for this but I have a strange error that the y value jumps at
602 // a certain point. This seems like an error in my xforms library or
603 // in some other local environment, but I would like to leave this here
604 // for the moment until I can remove this (Jug 20020418)
605 if (y_before < bv_->text->cursor.y())
606 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
608 // This is to allow jumping over large insets
609 if (cursorrow == bv_->text->cursor.row()) {
610 if (y >= int(workarea().height())) {
611 bv_->text->cursorDown(bv_, false);
613 bv_->text->cursorUp(bv_, false);
617 if (!bv_->text->selection.set())
618 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
620 bv_->text->setSelection(bv_);
621 screen().toggleToggle(bv_->text, bv_);
627 // Single-click on work area
628 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
629 mouse_button::state button)
634 // ok ok, this is a hack.
636 if (button == mouse_button::button4) {
637 scrollUp(lyxrc.wheel_jump);
638 // We shouldn't go further down as we really should only do the
639 // scrolling and be done with this. Otherwise we may open some
640 // dialogs (Jug 20020424).
642 } else if (button == mouse_button::button5) {
643 scrollDown(lyxrc.wheel_jump);
644 // We shouldn't go further down as we really should only do the
645 // scrolling and be done with this. Otherwise we may open some
646 // dialogs (Jug 20020424).
650 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
652 // Middle button press pastes if we have a selection
653 // We do this here as if the selection was inside an inset
654 // it could get cleared on the unlocking of the inset so
655 // we have to check this first
656 bool paste_internally = false;
657 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
658 owner_->getLyXFunc()->dispatch(LFUN_COPY);
659 paste_internally = true;
662 int const screen_first = bv_->text->first_y;
664 if (bv_->theLockingInset()) {
665 // We are in inset locking mode
667 /* Check whether the inset was hit. If not reset mode,
668 otherwise give the event to the inset */
669 if (inset_hit == bv_->theLockingInset()) {
670 bv_->theLockingInset()->
671 insetButtonPress(bv_,xpos, ypos,button);
674 bv_->unlockInset(bv_->theLockingInset());
679 selection_possible = true;
680 screen().hideCursor();
682 // Clear the selection
683 screen().toggleSelection(bv_->text, bv_);
684 bv_->text->clearSelection();
685 bv_->text->fullRebreak(bv_);
689 // Single left click in math inset?
690 if (isHighlyEditableInset(inset_hit)) {
691 // Highly editable inset, like math
692 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
693 selection_possible = false;
694 owner_->updateLayoutChoice();
695 owner_->message(inset->editMessage());
696 //inset->edit(bv_, xpos, ypos, button);
697 // We just have to lock the inset before calling a PressEvent on it!
698 // we don't need the edit() call here! (Jug20020329)
699 if (!bv_->lockInset(inset)) {
700 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
702 inset->insetButtonPress(bv_, xpos, ypos, button);
705 // I'm not sure we should continue here if we hit an inset (Jug20020403)
707 // Right click on a footnote flag opens float menu
708 if (button == mouse_button::button3) {
709 selection_possible = false;
713 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
714 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
716 bv_->text->selection.cursor = bv_->text->cursor;
717 bv_->text->cursor.x_fix(bv_->text->cursor.x());
719 owner_->updateLayoutChoice();
721 selection_possible = false;
724 // Insert primary selection with middle mouse
725 // if there is a local selection in the current buffer,
727 if (button == mouse_button::button2) {
728 if (paste_internally)
729 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
731 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
733 selection_possible = false;
739 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
744 LyXText * text = bv_->getLyXText();
746 if (text->bv_owner && bv_->theLockingInset())
749 if (button == mouse_button::button1) {
750 if (text->bv_owner) {
751 screen().hideCursor();
752 screen().toggleSelection(text, bv_);
753 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
754 screen().toggleSelection(text, bv_, false);
756 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
758 /* This will fit the cursor on the screen
760 update(text, BufferView::SELECT|BufferView::FITCUR);
765 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
770 LyXText * text = bv_->getLyXText();
772 if (text->bv_owner && bv_->theLockingInset())
775 if (button == mouse_button::button1) {
776 if (text->bv_owner) {
777 screen().hideCursor();
778 screen().toggleSelection(text, bv_);
780 text->cursorHome(bv_);
781 text->selection.cursor = text->cursor;
782 text->cursorEnd(bv_);
783 text->setSelection(bv_);
784 if (text->bv_owner) {
785 screen().toggleSelection(text, bv_, false);
787 /* This will fit the cursor on the screen
789 update(text, BufferView::SELECT|BufferView::FITCUR);
794 void BufferView::Pimpl::selectionRequested()
801 LyXText * text = bv_->getLyXText();
803 if (text->selection.set() &&
804 (!bv_->text->xsel_cache.set() ||
805 text->selection.start != bv_->text->xsel_cache.start ||
806 text->selection.end != bv_->text->xsel_cache.end))
808 bv_->text->xsel_cache = text->selection;
809 sel = text->selectionAsString(bv_->buffer(), false);
810 } else if (!text->selection.set()) {
812 bv_->text->xsel_cache.set(false);
815 workarea().putClipboard(sel);
820 void BufferView::Pimpl::selectionLost()
825 bv_->getLyXText()->clearSelection();
827 bv_->text->xsel_cache.set(false);
832 void BufferView::Pimpl::enterView()
835 SetXtermCursor(workarea().getWin());
836 using_xterm_cursor = true;
841 void BufferView::Pimpl::leaveView()
843 if (using_xterm_cursor) {
844 XUndefineCursor(fl_get_display(), workarea().getWin());
845 using_xterm_cursor = false;
850 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
851 mouse_button::state button)
853 // do nothing if we used the mouse wheel
854 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
857 // If we hit an inset, we have the inset coordinates in these
858 // and inset_hit points to the inset. If we do not hit an
859 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
860 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
862 if (bv_->theLockingInset()) {
863 // We are in inset locking mode.
865 /* LyX does a kind of work-area grabbing for insets.
866 Only a ButtonPress Event outside the inset will
867 force a insetUnlock. */
868 bv_->theLockingInset()->
869 insetButtonRelease(bv_, x, y, button);
873 selection_possible = false;
875 if (button == mouse_button::button2)
879 if (button == mouse_button::button1) {
880 workarea().haveSelection(bv_->getLyXText()->selection.set());
885 owner_->updateMenubar();
886 owner_->updateToolbar();
888 // Did we hit an editable inset?
890 selection_possible = false;
892 // if we reach this point with a selection, it
893 // must mean we are currently selecting.
894 // But we don't want to open the inset
895 // because that is annoying for the user.
896 // So just pretend we didn't hit it.
897 // this is OK because a "kosher" ButtonRelease
898 // will follow a ButtonPress that clears
900 // Note this also fixes selection drawing
901 // problems if we end up opening an inset
902 if (bv_->getLyXText()->selection.set())
905 // CHECK fix this proper in 0.13
906 // well, maybe 13.0 !!!!!!!!!
908 // Following a ref shouldn't issue
909 // a push on the undo-stack
910 // anylonger, now that we have
911 // keybindings for following
912 // references and returning from
913 // references. IMHO though, it
914 // should be the inset's own business
915 // to push or not push on the undo
916 // stack. They don't *have* to
917 // alter the document...
919 // ...or maybe the SetCursorParUndo()
920 // below isn't necessary at all anylonger?
921 if (inset_hit->lyxCode() == Inset::REF_CODE) {
922 setCursorParUndo(bv_);
925 owner_->message(inset_hit->editMessage());
927 if (isHighlyEditableInset(inset_hit)) {
928 // Highly editable inset, like math
929 UpdatableInset *inset = (UpdatableInset *)inset_hit;
930 inset->insetButtonRelease(bv_, x, y, button);
932 inset_hit->insetButtonRelease(bv_, x, y, button);
933 // IMO this is a grosshack! Inset's should be changed so that
934 // they call the actions they have to do with the insetButtonRel.
935 // function and not in the edit(). This should be changed
937 inset_hit->edit(bv_, x, y, button);
942 // Maybe we want to edit a bibitem ale970302
943 if (bv_->text->cursor.par()->bibkey && x < 20 +
944 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
945 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
952 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
953 LyXCursor const & cursor) const
955 Paragraph /*const*/ & par = *cursor.par();
956 pos_type const pos = cursor.pos();
958 lyx::Assert(par.getInset(pos));
960 Inset const & inset(*par.getInset(pos));
962 LyXFont const & font = text.getFont(buffer_, &par, pos);
964 int const width = inset.width(bv_, font);
965 int const inset_x = font.isVisibleRightToLeft()
966 ? (cursor.ix() - width) : cursor.ix();
969 inset_x + inset.scroll(),
971 cursor.iy() - inset.ascent(bv_, font),
972 cursor.iy() + inset.descent(bv_, font));
976 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
977 LyXCursor const & cursor,
978 int & x, int & y) const
980 pos_type const pos(cursor.pos());
981 Paragraph /*const*/ & par(*cursor.par());
983 if (pos >= par.size() || !par.isInset(pos)) {
987 Inset /*const*/ * inset = par.getInset(pos);
989 if (!isEditableInset(inset)) {
993 Box b(insetDimensions(text, cursor));
995 if (!b.contained(x, y)) {
996 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
997 << " box " << b << endl;
1001 text.setCursor(bv_, &par, pos, true);
1004 // The origin of an inset is on the baseline
1005 y -= text.cursor.iy();
1011 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
1013 int y_tmp = y + text->first_y;
1016 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
1018 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1025 // look at previous position
1027 if (cursor.pos() == 0) {
1032 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1034 inset = checkInset(*text, cursor, x, y_tmp);
1042 void BufferView::Pimpl::workAreaExpose()
1044 static int work_area_width;
1045 static unsigned int work_area_height;
1047 bool const widthChange = workarea().workWidth() != work_area_width;
1048 bool const heightChange = workarea().height() != work_area_height;
1050 // update from work area
1051 work_area_width = workarea().workWidth();
1052 work_area_height = workarea().height();
1055 // The visible LyXView need a resize
1058 // Remove all texts from the textcache
1059 // This is not _really_ what we want to do. What
1060 // we really want to do is to delete in textcache
1061 // that does not have a BufferView with matching
1062 // width, but as long as we have only one BufferView
1063 // deleting all gives the same result.
1064 if (lyxerr.debugging())
1065 textcache.show(lyxerr, "Expose delete all");
1067 buffer_->resizeInsets(bv_);
1068 } else if (heightChange) {
1069 // Rebuild image of current screen
1071 // fitCursor() ensures we don't jump back
1072 // to the start of the document on vertical
1076 // The main window size has changed, repaint most stuff
1079 screen().redraw(bv_->text, bv_);
1082 // Grey box when we don't have a buffer
1083 workarea().greyOut();
1086 // always make sure that the scrollbar is sane.
1088 owner_->updateLayoutChoice();
1093 void BufferView::Pimpl::update()
1095 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
1096 LyXText::text_status st = bv_->text->status();
1097 screen().update(bv_->text, bv_);
1099 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1100 bv_->text->fullRebreak(bv_);
1101 st = LyXText::NEED_MORE_REFRESH;
1102 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1103 bv_->text->cursor.pos());
1104 if (bv_->text->selection.set()) {
1105 bv_->text->setCursor(bv_, bv_->text->selection.start,
1106 bv_->text->selection.start.par(),
1107 bv_->text->selection.start.pos());
1108 bv_->text->setCursor(bv_, bv_->text->selection.end,
1109 bv_->text->selection.end.par(),
1110 bv_->text->selection.end.pos());
1113 bv_->text->status(bv_, st);
1114 screen().update(bv_->text, bv_);
1116 // do this here instead of in the screen::update because of
1118 bv_->text->status(bv_, LyXText::UNCHANGED);
1124 // Values used when calling update:
1126 // -2 - update, move sel_cursor if selection, fitcursor
1127 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1128 // 0 - update, move sel_cursor if selection, fitcursor
1129 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1130 // 3 - update, move sel_cursor if selection
1133 // a simple redraw of the parts that need refresh
1135 // move sel_cursor if selection -
1136 // the text's sel_cursor is moved if there is selection is progress
1139 // fitCursor() is called and the scrollbar updated
1142 // the buffer is marked dirty.
1151 // UPDATE_ONLY = UPDATE;
1152 // UPDATE_SELECT = UPDATE | SELECT;
1153 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1154 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1156 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1157 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1158 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1159 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1160 // update(3) -> update(1) -> update(1) -> update(SELECT)
1162 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1164 owner_->updateLayoutChoice();
1166 if (!text->selection.set() && (f & SELECT)) {
1167 text->selection.cursor = text->cursor;
1170 text->fullRebreak(bv_);
1172 if (text->inset_owner) {
1173 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1174 updateInset(text->inset_owner, false);
1184 buffer_->markDirty();
1189 // Callback for cursor timer
1190 void BufferView::Pimpl::cursorToggle()
1193 cursor_timeout.restart();
1198 extern void reapSpellchecker(void);
1201 if (!bv_->theLockingInset()) {
1202 screen().cursorToggle(bv_);
1204 bv_->theLockingInset()->toggleInsetCursor(bv_);
1207 cursor_timeout.restart();
1211 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1213 if (!text->cursor.row()->previous()) {
1214 if (text->first_y > 0) {
1215 int new_y = bv_->text->first_y - workarea().height();
1216 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1222 int y = text->first_y;
1223 Row * cursorrow = text->cursor.row();
1225 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1229 if (cursorrow == bv_->text->cursor.row()) {
1230 // we have a row which is higher than the workarea so we leave the
1231 // cursor on the start of the row and move only the draw up as soon
1232 // as we move the cursor or do something while inside the row (it may
1233 // span several workarea-heights) we'll move to the top again, but this
1234 // is better than just jump down and only display part of the row.
1235 new_y = bv_->text->first_y - workarea().height();
1237 if (text->inset_owner) {
1238 new_y = bv_->text->cursor.iy()
1239 + bv_->theLockingInset()->insetInInsetY() + y
1240 + text->cursor.row()->height()
1241 - workarea().height() + 1;
1243 new_y = text->cursor.y()
1244 - text->cursor.row()->baseline()
1245 + text->cursor.row()->height()
1246 - workarea().height() + 1;
1249 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1250 if (text->cursor.row()->previous()) {
1252 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1253 text->cursor.row()->previous()->pos(), false);
1254 if (cur.y() > text->first_y) {
1255 text->cursorUp(bv_, true);
1262 void BufferView::Pimpl::cursorNext(LyXText * text)
1264 if (!text->cursor.row()->next()) {
1265 int y = text->cursor.y() - text->cursor.row()->baseline() +
1266 text->cursor.row()->height();
1267 if (y > int(text->first_y + workarea().height())) {
1268 screen().draw(bv_->text, bv_,
1269 bv_->text->first_y + workarea().height());
1275 int y = text->first_y + workarea().height();
1276 if (text->inset_owner && !text->first_y) {
1277 y -= (bv_->text->cursor.iy()
1278 - bv_->text->first_y
1279 + bv_->theLockingInset()->insetInInsetY());
1281 text->getRowNearY(y);
1283 Row * cursorrow = text->cursor.row();
1284 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().height());
1287 if (cursorrow == bv_->text->cursor.row()) {
1288 // we have a row which is higher than the workarea so we leave the
1289 // cursor on the start of the row and move only the draw down as soon
1290 // as we move the cursor or do something while inside the row (it may
1291 // span several workarea-heights) we'll move to the top again, but this
1292 // is better than just jump down and only display part of the row.
1293 new_y = bv_->text->first_y + workarea().height();
1295 if (text->inset_owner) {
1296 new_y = bv_->text->cursor.iy()
1297 + bv_->theLockingInset()->insetInInsetY()
1298 + y - text->cursor.row()->baseline();
1300 new_y = text->cursor.y() - text->cursor.row()->baseline();
1303 screen().draw(bv_->text, bv_, new_y);
1304 if (text->cursor.row()->next()) {
1306 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1307 text->cursor.row()->next()->pos(), false);
1308 if (cur.y() < int(text->first_y + workarea().height())) {
1309 text->cursorDown(bv_, true);
1316 bool BufferView::Pimpl::available() const
1318 if (buffer_ && bv_->text)
1324 void BufferView::Pimpl::beforeChange(LyXText * text)
1327 text->clearSelection();
1331 void BufferView::Pimpl::savePosition(unsigned int i)
1333 if (i >= saved_positions_num)
1335 saved_positions[i] = Position(buffer_->fileName(),
1336 bv_->text->cursor.par()->id(),
1337 bv_->text->cursor.pos());
1340 str << _("Saved bookmark") << ' ' << i;
1341 owner_->message(str.str().c_str());
1346 void BufferView::Pimpl::restorePosition(unsigned int i)
1348 if (i >= saved_positions_num)
1351 string const fname = saved_positions[i].filename;
1353 beforeChange(bv_->text);
1355 if (fname != buffer_->fileName()) {
1356 Buffer * b = bufferlist.exists(fname) ?
1357 bufferlist.getBuffer(fname) :
1358 bufferlist.loadLyXFile(fname); // don't ask, just load it
1359 if (b != 0) buffer(b);
1362 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1366 bv_->text->setCursor(bv_, par,
1367 min(par->size(), saved_positions[i].par_pos));
1369 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1372 str << _("Moved to bookmark") << ' ' << i;
1373 owner_->message(str.str().c_str());
1378 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1380 if (i >= saved_positions_num)
1383 return !saved_positions[i].filename.empty();
1387 void BufferView::Pimpl::setState()
1389 if (!lyxrc.rtl_support)
1392 LyXText * text = bv_->getLyXText();
1393 if (text->real_current_font.isRightToLeft()
1394 && !(bv_->theLockingInset()
1395 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1397 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1398 owner_->getIntl()->KeyMapSec();
1400 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1401 owner_->getIntl()->KeyMapPrim();
1407 void BufferView::Pimpl::insetSleep()
1409 if (bv_->theLockingInset() && !inset_slept) {
1410 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1411 bv_->theLockingInset()->insetUnlock(bv_);
1417 void BufferView::Pimpl::insetWakeup()
1419 if (bv_->theLockingInset() && inset_slept) {
1420 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1421 inset_slept = false;
1427 void BufferView::Pimpl::insetUnlock()
1429 if (bv_->theLockingInset()) {
1431 bv_->theLockingInset()->insetUnlock(bv_);
1432 bv_->theLockingInset(0);
1434 inset_slept = false;
1439 bool BufferView::Pimpl::focus() const
1441 return workarea().hasFocus();
1445 void BufferView::Pimpl::focus(bool f)
1447 if (f) workarea().setFocus();
1451 void BufferView::Pimpl::showCursor()
1453 if (bv_->theLockingInset())
1454 bv_->theLockingInset()->showInsetCursor(bv_);
1456 screen().showCursor(bv_->text, bv_);
1460 void BufferView::Pimpl::hideCursor()
1462 if (!bv_->theLockingInset())
1463 screen().hideCursor();
1467 void BufferView::Pimpl::toggleSelection(bool b)
1469 if (bv_->theLockingInset())
1470 bv_->theLockingInset()->toggleSelection(bv_, b);
1471 screen().toggleSelection(bv_->text, bv_, b);
1475 void BufferView::Pimpl::toggleToggle()
1477 screen().toggleToggle(bv_->text, bv_);
1481 void BufferView::Pimpl::center()
1483 beforeChange(bv_->text);
1484 if (bv_->text->cursor.y() > static_cast<int>((workarea().height() / 2))) {
1485 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().height() / 2);
1487 screen().draw(bv_->text, bv_, 0);
1489 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1494 void BufferView::Pimpl::pasteClipboard(bool asPara)
1499 screen().hideCursor();
1500 beforeChange(bv_->text);
1502 string const clip(workarea().getClipboard());
1508 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1510 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1512 bv_->getLyXText()->clearSelection();
1513 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1517 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1519 workarea().putClipboard(stuff);
1524 * Dispatch functions for actions which can be valid for BufferView->text
1525 * and/or InsetText->text!!!
1530 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1532 LyXText * lt = bv_->getLyXText();
1534 if (selecting || lt->selection.mark()) {
1535 lt->setSelection(bv_);
1539 updateInset(lt->inset_owner, false);
1543 update(lt, BufferView::SELECT|BufferView::FITCUR);
1545 update(lt, BufferView::SELECT);
1547 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1548 bv_->theLockingInset()->hideInsetCursor(bv_);
1549 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1553 if (!lt->selection.set())
1554 workarea().haveSelection(false);
1556 /* ---> Everytime the cursor is moved, show the current font state. */
1557 // should this too me moved out of this func?
1558 //owner->showState();
1563 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1565 LyXCursor cursor = bv_->getLyXText()->cursor;
1566 Buffer::inset_iterator it =
1567 find_if(Buffer::inset_iterator(
1568 cursor.par(), cursor.pos()),
1569 buffer_->inset_iterator_end(),
1570 lyx::compare_memfun(&Inset::lyxCode, code));
1571 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1575 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1577 string filename = filen;
1579 if (filename.empty()) {
1580 // Launch a file browser
1581 string initpath = lyxrc.document_path;
1584 string const trypath = owner_->buffer()->filePath();
1585 // If directory is writeable, use this as default.
1586 if (IsDirWriteable(trypath))
1590 FileDialog fileDlg(bv_->owner(),
1591 _("Select LyX document to insert"),
1593 make_pair(string(_("Documents|#o#O")),
1594 string(lyxrc.document_path)),
1595 make_pair(string(_("Examples|#E#e")),
1596 string(AddPath(system_lyxdir, "examples"))));
1598 FileDialog::Result result =
1599 fileDlg.Select(initpath,
1600 _("*.lyx| LyX Documents (*.lyx)"));
1602 if (result.first == FileDialog::Later)
1605 filename = result.second;
1607 // check selected filename
1608 if (filename.empty()) {
1609 owner_->message(_("Canceled."));
1614 // get absolute path of file and add ".lyx" to the filename if
1616 filename = FileSearch(string(), filename, "lyx");
1618 string const disp_fn(MakeDisplayPath(filename));
1621 s1 << _("Inserting document") << ' '
1622 << disp_fn << " ...";
1623 owner_->message(s1.str().c_str());
1624 bool const res = bv_->insertLyXFile(filename);
1627 str << _("Document") << ' ' << disp_fn
1628 << ' ' << _("inserted.");
1629 owner_->message(str.str().c_str());
1632 str << _("Could not insert document") << ' '
1634 owner_->message(str.str().c_str());
1639 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1641 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1642 << action <<"] arg[" << argument << "]" << endl;
1644 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1647 // --- Misc -------------------------------------------
1651 LyXText * lt = bv_->getLyXText();
1652 lt->toggleAppendix(bv_);
1655 | BufferView::FITCUR
1656 | BufferView::CHANGE);
1661 case LFUN_TOC_INSERT:
1663 InsetCommandParams p;
1664 p.setCmdName("tableofcontents");
1665 Inset * inset = new InsetTOC(p);
1666 if (!insertInset(inset, tclass.defaultLayoutName()))
1671 case LFUN_SCROLL_INSET:
1672 // this is not handled here as this funktion is only aktive
1673 // if we have a locking_inset and that one is (or contains)
1677 case LFUN_INSET_GRAPHICS:
1679 Inset * new_inset = new InsetGraphics;
1680 if (!insertInset(new_inset)) {
1683 // this is need because you don't use a inset->Edit()
1684 updateInset(new_inset, true);
1685 new_inset->edit(bv_);
1695 case LFUN_PASTESELECTION:
1697 bool asPara = false;
1698 if (argument == "paragraph")
1700 pasteClipboard(asPara);
1712 case LFUN_LAYOUT_COPY:
1713 bv_->copyEnvironment();
1716 case LFUN_LAYOUT_PASTE:
1717 bv_->pasteEnvironment();
1721 case LFUN_GOTOERROR:
1722 gotoInset(Inset::ERROR_CODE, false);
1726 gotoInset(Inset::IGNORE_CODE, false);
1729 case LFUN_REFERENCE_GOTO:
1731 vector<Inset::Code> tmp;
1732 tmp.push_back(Inset::LABEL_CODE);
1733 tmp.push_back(Inset::REF_CODE);
1734 gotoInset(tmp, true);
1738 case LFUN_HYPHENATION:
1739 specialChar(InsetSpecialChar::HYPHENATION);
1742 case LFUN_LIGATURE_BREAK:
1743 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1747 specialChar(InsetSpecialChar::LDOTS);
1750 case LFUN_END_OF_SENTENCE:
1751 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1754 case LFUN_MENU_SEPARATOR:
1755 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1762 case LFUN_DEPTH_MIN:
1763 changeDepth(bv_, bv_->getLyXText(), -1);
1766 case LFUN_DEPTH_PLUS:
1767 changeDepth(bv_, bv_->getLyXText(), 1);
1771 owner_->getDialogs()->setUserFreeFont();
1774 case LFUN_FILE_INSERT:
1775 MenuInsertLyXFile(argument);
1778 case LFUN_FILE_INSERT_ASCII_PARA:
1779 InsertAsciiFile(bv_, argument, true);
1782 case LFUN_FILE_INSERT_ASCII:
1783 InsertAsciiFile(bv_, argument, false);
1788 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1789 << argument << endl;
1791 // This is not the good solution to the empty argument
1792 // problem, but it will hopefully suffice for 1.2.0.
1793 // The correct solution would be to augument the
1794 // function list/array with information about what
1795 // functions needs arguments and their type.
1796 if (argument.empty()) {
1797 owner_->getLyXFunc()->setErrorMessage(
1798 _("LyX function 'layout' needs an argument."));
1802 // Derive layout number from given argument (string)
1803 // and current buffer's textclass (number). */
1804 bool hasLayout = tclass.hasLayout(argument);
1805 string layout = argument;
1807 // If the entry is obsolete, use the new one instead.
1809 string const & obs = tclass[layout].obsoleted_by();
1815 owner_->getLyXFunc()->setErrorMessage(
1816 string(N_("Layout ")) + argument +
1821 bool change_layout = (current_layout != layout);
1822 LyXText * lt = bv_->getLyXText();
1823 if (!change_layout && lt->selection.set() &&
1824 lt->selection.start.par() != lt->selection.end.par())
1826 Paragraph * spar = lt->selection.start.par();
1827 Paragraph * epar = lt->selection.end.par()->next();
1828 while(spar != epar) {
1829 if (spar->layout() != current_layout) {
1830 change_layout = true;
1835 if (change_layout) {
1837 current_layout = layout;
1840 | BufferView::FITCUR);
1841 lt->setLayout(bv_, layout);
1842 owner_->setLayout(layout);
1845 | BufferView::FITCUR
1846 | BufferView::CHANGE);
1853 lang(bv_, argument);
1855 owner_->showState();
1860 owner_->showState();
1865 owner_->showState();
1870 owner_->showState();
1875 owner_->showState();
1880 owner_->showState();
1885 owner_->showState();
1890 owner_->showState();
1893 case LFUN_UNDERLINE:
1895 owner_->showState();
1898 case LFUN_FONT_SIZE:
1899 fontSize(bv_, argument);
1900 owner_->showState();
1903 case LFUN_FONT_STATE:
1904 owner_->getLyXFunc()->setMessage(currentState(bv_));
1907 case LFUN_UPCASE_WORD:
1909 LyXText * lt = bv_->getLyXText();
1913 | BufferView::FITCUR);
1914 lt->changeCase(bv_, LyXText::text_uppercase);
1915 if (lt->inset_owner)
1916 updateInset(lt->inset_owner, true);
1919 | BufferView::FITCUR
1920 | BufferView::CHANGE);
1924 case LFUN_LOWCASE_WORD:
1926 LyXText * lt = bv_->getLyXText();
1928 update(lt, BufferView::SELECT|BufferView::FITCUR);
1929 lt->changeCase(bv_, LyXText::text_lowercase);
1930 if (lt->inset_owner)
1931 updateInset(lt->inset_owner, true);
1934 | BufferView::FITCUR
1935 | BufferView::CHANGE);
1939 case LFUN_CAPITALIZE_WORD:
1941 LyXText * lt = bv_->getLyXText();
1943 update(lt, BufferView::SELECT|BufferView::FITCUR);
1944 lt->changeCase(bv_, LyXText::text_capitalization);
1945 if (lt->inset_owner)
1946 updateInset(lt->inset_owner, true);
1949 | BufferView::FITCUR
1950 | BufferView::CHANGE);
1954 case LFUN_TRANSPOSE_CHARS:
1956 LyXText * lt = bv_->getLyXText();
1958 update(lt, BufferView::SELECT|BufferView::FITCUR);
1959 lt->transposeChars(*bv_);
1960 if (lt->inset_owner)
1961 updateInset(lt->inset_owner, true);
1964 | BufferView::FITCUR
1965 | BufferView::CHANGE);
1970 case LFUN_INSERT_LABEL:
1971 MenuInsertLabel(bv_, argument);
1974 case LFUN_REF_INSERT:
1975 if (argument.empty()) {
1976 InsetCommandParams p("ref");
1977 owner_->getDialogs()->createRef(p.getAsString());
1979 InsetCommandParams p;
1980 p.setFromString(argument);
1982 InsetRef * inset = new InsetRef(p, *buffer_);
1983 if (!insertInset(inset))
1986 updateInset(inset, true);
1990 case LFUN_BOOKMARK_SAVE:
1991 savePosition(strToUnsignedInt(argument));
1994 case LFUN_BOOKMARK_GOTO:
1995 restorePosition(strToUnsignedInt(argument));
2000 string label(argument);
2001 if (label.empty()) {
2003 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
2005 label = inset->getContents();
2010 if (!label.empty()) {
2011 //bv_->savePosition(0);
2012 if (!bv_->gotoLabel(label))
2013 Alert::alert(_("Error"),
2014 _("Couldn't find this label"),
2015 _("in current document."));
2020 // --- Cursor Movements -----------------------------
2023 LyXText * lt = bv_->getLyXText();
2025 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2026 if (!lt->selection.mark())
2028 update(lt, BufferView::SELECT|BufferView::FITCUR);
2030 lt->cursorLeft(bv_, false);
2031 if (lt->cursor.pos() < lt->cursor.par()->size()
2032 && lt->cursor.par()->isInset(lt->cursor.pos())
2033 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2034 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2035 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2037 tmpinset->edit(bv_, false);
2039 tmpinset->edit(bv_);
2043 lt->cursorRight(bv_, false);
2045 moveCursorUpdate(false);
2046 owner_->showState();
2052 // This is soooo ugly. Isn`t it possible to make
2053 // it simpler? (Lgb)
2054 LyXText * lt = bv_->getLyXText();
2055 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2056 if (!lt->selection.mark())
2058 update(lt, BufferView::SELECT|BufferView::FITCUR);
2059 LyXCursor const cur = lt->cursor;
2061 lt->cursorLeft(bv_, false);
2062 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2063 lt->cursor.pos() < lt->cursor.par()->size() &&
2064 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2065 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2066 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2067 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2069 tmpinset->edit(bv_);
2071 tmpinset->edit(bv_, false);
2075 lt->cursorRight(bv_, false);
2078 moveCursorUpdate(false);
2079 owner_->showState();
2085 LyXText * lt = bv_->getLyXText();
2087 if (!lt->selection.mark())
2089 update(lt, BufferView::UPDATE);
2092 moveCursorUpdate(false);
2093 owner_->showState();
2099 LyXText * lt = bv_->getLyXText();
2101 if (!lt->selection.mark())
2103 update(lt, BufferView::UPDATE);
2104 lt->cursorDown(bv_);
2106 moveCursorUpdate(false);
2107 owner_->showState();
2111 case LFUN_UP_PARAGRAPH:
2113 LyXText * lt = bv_->getLyXText();
2115 if (!lt->selection.mark())
2117 update(lt, BufferView::UPDATE);
2118 lt->cursorUpParagraph(bv_);
2120 moveCursorUpdate(false);
2121 owner_->showState();
2125 case LFUN_DOWN_PARAGRAPH:
2127 LyXText * lt = bv_->getLyXText();
2129 if (!lt->selection.mark())
2131 update(lt, BufferView::UPDATE);
2132 lt->cursorDownParagraph(bv_);
2134 moveCursorUpdate(false);
2135 owner_->showState();
2141 LyXText * lt = bv_->getLyXText();
2143 if (!lt->selection.mark())
2145 update(lt, BufferView::UPDATE);
2148 moveCursorUpdate(false, false);
2149 owner_->showState();
2155 LyXText * lt = bv_->getLyXText();
2157 if (!lt->selection.mark())
2159 update(lt, BufferView::UPDATE);
2162 moveCursorUpdate(false, false);
2163 owner_->showState();
2169 LyXText * lt = bv_->getLyXText();
2171 if (!lt->selection.mark())
2173 update(lt, BufferView::SELECT|BufferView::FITCUR);
2174 lt->cursorHome(bv_);
2176 moveCursorUpdate(false);
2177 owner_->showState();
2183 LyXText * lt = bv_->getLyXText();
2185 if (!lt->selection.mark())
2188 BufferView::SELECT|BufferView::FITCUR);
2191 moveCursorUpdate(false);
2192 owner_->showState();
2196 case LFUN_SHIFT_TAB:
2199 LyXText * lt = bv_->getLyXText();
2201 if (!lt->selection.mark())
2204 BufferView::SELECT|BufferView::FITCUR);
2207 moveCursorUpdate(false);
2208 owner_->showState();
2212 case LFUN_WORDRIGHT:
2214 LyXText * lt = bv_->getLyXText();
2216 if (!lt->selection.mark())
2218 update(lt, BufferView::SELECT|BufferView::FITCUR);
2219 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2220 lt->cursorLeftOneWord(bv_);
2222 lt->cursorRightOneWord(bv_);
2224 moveCursorUpdate(false);
2225 owner_->showState();
2231 LyXText * lt = bv_->getLyXText();
2233 if (!lt->selection.mark())
2235 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2237 lt->cursorRightOneWord(bv_);
2239 lt->cursorLeftOneWord(bv_);
2241 moveCursorUpdate(false);
2242 owner_->showState();
2246 case LFUN_BEGINNINGBUF:
2248 LyXText * lt = bv_->getLyXText();
2250 if (!lt->selection.mark())
2253 BufferView::SELECT|BufferView::FITCUR);
2256 moveCursorUpdate(false);
2257 owner_->showState();
2263 LyXText * lt = bv_->getLyXText();
2265 if (!lt->selection.mark())
2268 BufferView::SELECT|BufferView::FITCUR);
2269 lt->cursorBottom(bv_);
2271 moveCursorUpdate(false);
2272 owner_->showState();
2276 /* cursor selection ---------------------------- */
2279 LyXText * lt = bv_->getLyXText();
2282 BufferView::SELECT|BufferView::FITCUR);
2283 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2284 lt->cursorLeft(bv_);
2286 lt->cursorRight(bv_);
2288 moveCursorUpdate(true);
2289 owner_->showState();
2295 LyXText * lt = bv_->getLyXText();
2298 BufferView::SELECT|BufferView::FITCUR);
2299 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2300 lt->cursorRight(bv_);
2302 lt->cursorLeft(bv_);
2304 moveCursorUpdate(true);
2305 owner_->showState();
2311 LyXText * lt = bv_->getLyXText();
2314 BufferView::SELECT|BufferView::FITCUR);
2315 lt->cursorUp(bv_, true);
2317 moveCursorUpdate(true);
2318 owner_->showState();
2324 LyXText * lt = bv_->getLyXText();
2327 BufferView::SELECT|BufferView::FITCUR);
2328 lt->cursorDown(bv_, true);
2330 moveCursorUpdate(true);
2331 owner_->showState();
2335 case LFUN_UP_PARAGRAPHSEL:
2337 LyXText * lt = bv_->getLyXText();
2340 BufferView::SELECT|BufferView::FITCUR);
2341 lt->cursorUpParagraph(bv_);
2343 moveCursorUpdate(true);
2344 owner_->showState();
2348 case LFUN_DOWN_PARAGRAPHSEL:
2350 LyXText * lt = bv_->getLyXText();
2353 BufferView::SELECT|BufferView::FITCUR);
2354 lt->cursorDownParagraph(bv_);
2356 moveCursorUpdate(true);
2357 owner_->showState();
2363 LyXText * lt = bv_->getLyXText();
2365 update(lt, BufferView::SELECT|BufferView::FITCUR);
2368 moveCursorUpdate(true);
2369 owner_->showState();
2375 LyXText * lt = bv_->getLyXText();
2377 update(lt, BufferView::SELECT|BufferView::FITCUR);
2380 moveCursorUpdate(true);
2381 owner_->showState();
2387 LyXText * lt = bv_->getLyXText();
2389 update(lt, BufferView::SELECT|BufferView::FITCUR);
2390 lt->cursorHome(bv_);
2392 moveCursorUpdate(true);
2393 owner_->showState();
2399 LyXText * lt = bv_->getLyXText();
2401 update(lt, BufferView::SELECT|BufferView::FITCUR);
2404 moveCursorUpdate(true);
2405 owner_->showState();
2409 case LFUN_WORDRIGHTSEL:
2411 LyXText * lt = bv_->getLyXText();
2413 update(lt, BufferView::SELECT|BufferView::FITCUR);
2414 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2415 lt->cursorLeftOneWord(bv_);
2417 lt->cursorRightOneWord(bv_);
2419 moveCursorUpdate(true);
2420 owner_->showState();
2424 case LFUN_WORDLEFTSEL:
2426 LyXText * lt = bv_->getLyXText();
2428 update(lt, BufferView::SELECT|BufferView::FITCUR);
2429 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2430 lt->cursorRightOneWord(bv_);
2432 lt->cursorLeftOneWord(bv_);
2434 moveCursorUpdate(true);
2435 owner_->showState();
2439 case LFUN_BEGINNINGBUFSEL:
2441 LyXText * lt = bv_->getLyXText();
2443 if (lt->inset_owner)
2445 update(lt, BufferView::SELECT|BufferView::FITCUR);
2448 moveCursorUpdate(true);
2449 owner_->showState();
2453 case LFUN_ENDBUFSEL:
2455 LyXText * lt = bv_->getLyXText();
2457 if (lt->inset_owner)
2460 BufferView::SELECT|BufferView::FITCUR);
2461 lt->cursorBottom(bv_);
2463 moveCursorUpdate(true);
2464 owner_->showState();
2468 // --- text changing commands ------------------------
2469 case LFUN_BREAKLINE:
2471 LyXText * lt = bv_->getLyXText();
2474 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2477 | BufferView::FITCUR
2478 | BufferView::CHANGE);
2479 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2480 moveCursorUpdate(false);
2484 case LFUN_PROTECTEDSPACE:
2486 LyXText * lt = bv_->getLyXText();
2488 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2490 if (style.free_spacing) {
2491 lt->insertChar(bv_, ' ');
2494 | BufferView::FITCUR
2495 | BufferView::CHANGE);
2497 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2499 moveCursorUpdate(false);
2505 LyXText * lt = bv_->getLyXText();
2507 if (lt->selection.mark()) {
2511 | BufferView::FITCUR);
2512 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2515 lt->selection.mark(true);
2518 | BufferView::FITCUR);
2519 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2521 lt->selection.cursor = lt->cursor;
2527 LyXText * lt = bv_->getLyXText();
2529 if (!lt->selection.set()) {
2531 lt->selection.cursor = lt->cursor;
2534 | BufferView::FITCUR
2535 | BufferView::CHANGE);
2536 // It is possible to make it a lot faster still
2537 // just comment out the line below...
2542 moveCursorUpdate(false);
2543 owner_->showState();
2548 case LFUN_DELETE_SKIP:
2550 LyXText * lt = bv_->getLyXText();
2552 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2554 LyXCursor cursor = lt->cursor;
2556 if (!lt->selection.set()) {
2557 if (cursor.pos() == cursor.par()->size()) {
2558 lt->cursorRight(bv_);
2559 cursor = lt->cursor;
2560 if (cursor.pos() == 0
2561 && !(cursor.par()->params().spaceTop()
2562 == VSpace (VSpace::NONE))) {
2565 cursor.par()->params().lineTop(),
2566 cursor.par()->params().lineBottom(),
2567 cursor.par()->params().pagebreakTop(),
2568 cursor.par()->params().pagebreakBottom(),
2569 VSpace(VSpace::NONE),
2570 cursor.par()->params().spaceBottom(),
2571 cursor.par()->params().spacing(),
2572 cursor.par()->params().align(),
2573 cursor.par()->params().labelWidthString(), 0);
2574 lt->cursorLeft(bv_);
2577 | BufferView::FITCUR
2578 | BufferView::CHANGE);
2580 lt->cursorLeft(bv_);
2582 lt->selection.cursor = lt->cursor;
2585 | BufferView::FITCUR
2586 | BufferView::CHANGE);
2590 lt->selection.cursor = lt->cursor;
2593 | BufferView::FITCUR
2594 | BufferView::CHANGE);
2602 /* -------> Delete word forward. */
2603 case LFUN_DELETE_WORD_FORWARD:
2604 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2605 bv_->getLyXText()->deleteWordForward(bv_);
2606 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2607 moveCursorUpdate(false);
2608 owner_->showState();
2611 /* -------> Delete word backward. */
2612 case LFUN_DELETE_WORD_BACKWARD:
2614 LyXText * lt = bv_->getLyXText();
2616 update(lt, BufferView::SELECT|BufferView::FITCUR);
2617 lt->deleteWordBackward(bv_);
2620 | BufferView::FITCUR
2621 | BufferView::CHANGE);
2622 moveCursorUpdate(false);
2623 owner_->showState();
2627 /* -------> Kill to end of line. */
2628 case LFUN_DELETE_LINE_FORWARD:
2630 LyXText * lt = bv_->getLyXText();
2632 update(lt, BufferView::SELECT|BufferView::FITCUR);
2633 lt->deleteLineForward(bv_);
2636 | BufferView::FITCUR
2637 | BufferView::CHANGE);
2638 moveCursorUpdate(false);
2642 /* -------> Set mark off. */
2645 LyXText * lt = bv_->getLyXText();
2648 update(lt, BufferView::SELECT|BufferView::FITCUR);
2649 lt->selection.cursor = lt->cursor;
2650 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2654 /* -------> Set mark on. */
2657 LyXText * lt = bv_->getLyXText();
2660 lt->selection.mark(true);
2661 update(lt, BufferView::SELECT|BufferView::FITCUR);
2662 lt->selection.cursor = lt->cursor;
2663 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2667 case LFUN_BACKSPACE:
2669 LyXText * lt = bv_->getLyXText();
2671 if (!lt->selection.set()) {
2672 if (owner_->getIntl()->getTrans().backspace()) {
2674 lt->selection.cursor = lt->cursor;
2677 | BufferView::FITCUR
2678 | BufferView::CHANGE);
2679 // It is possible to make it a lot faster still
2680 // just comment out the line below...
2686 owner_->showState();
2691 case LFUN_BACKSPACE_SKIP:
2693 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2694 LyXText * lt = bv_->getLyXText();
2696 LyXCursor cursor = lt->cursor;
2698 if (!lt->selection.set()) {
2699 if (cursor.pos() == 0
2700 && !(cursor.par()->params().spaceTop()
2701 == VSpace (VSpace::NONE))) {
2704 cursor.par()->params().lineTop(),
2705 cursor.par()->params().lineBottom(),
2706 cursor.par()->params().pagebreakTop(),
2707 cursor.par()->params().pagebreakBottom(),
2708 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2709 cursor.par()->params().spacing(),
2710 cursor.par()->params().align(),
2711 cursor.par()->params().labelWidthString(), 0);
2714 | BufferView::FITCUR
2715 | BufferView::CHANGE);
2718 lt->selection.cursor = cursor;
2721 | BufferView::FITCUR
2722 | BufferView::CHANGE);
2729 case LFUN_BREAKPARAGRAPH:
2731 LyXText * lt = bv_->getLyXText();
2734 lt->breakParagraph(bv_, 0);
2737 | BufferView::FITCUR
2738 | BufferView::CHANGE);
2739 lt->selection.cursor = lt->cursor;
2741 owner_->showState();
2745 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2747 LyXText * lt = bv_->getLyXText();
2750 lt->breakParagraph(bv_, 1);
2753 | BufferView::FITCUR
2754 | BufferView::CHANGE);
2755 lt->selection.cursor = lt->cursor;
2757 owner_->showState();
2761 case LFUN_BREAKPARAGRAPH_SKIP:
2763 // When at the beginning of a paragraph, remove
2764 // indentation and add a "defskip" at the top.
2765 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2766 LyXText * lt = bv_->getLyXText();
2768 LyXCursor cursor = lt->cursor;
2771 if (cursor.pos() == 0) {
2772 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2775 cursor.par()->params().lineTop(),
2776 cursor.par()->params().lineBottom(),
2777 cursor.par()->params().pagebreakTop(),
2778 cursor.par()->params().pagebreakBottom(),
2779 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2780 cursor.par()->params().spacing(),
2781 cursor.par()->params().align(),
2782 cursor.par()->params().labelWidthString(), 1);
2783 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2787 lt->breakParagraph(bv_, 0);
2788 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2793 | BufferView::FITCUR
2794 | BufferView::CHANGE);
2795 lt->selection.cursor = cursor;
2797 owner_->showState();
2801 case LFUN_PARAGRAPH_SPACING:
2803 LyXText * lt = bv_->getLyXText();
2805 Paragraph * par = lt->cursor.par();
2806 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2807 float cur_value = 1.0;
2808 if (cur_spacing == Spacing::Other) {
2809 cur_value = par->params().spacing().getValue();
2812 istringstream istr(argument.c_str());
2816 Spacing::Space new_spacing = cur_spacing;
2817 float new_value = cur_value;
2819 lyxerr << "Missing argument to `paragraph-spacing'"
2821 } else if (tmp == "single") {
2822 new_spacing = Spacing::Single;
2823 } else if (tmp == "onehalf") {
2824 new_spacing = Spacing::Onehalf;
2825 } else if (tmp == "double") {
2826 new_spacing = Spacing::Double;
2827 } else if (tmp == "other") {
2828 new_spacing = Spacing::Other;
2831 lyxerr << "new_value = " << tmpval << endl;
2834 } else if (tmp == "default") {
2835 new_spacing = Spacing::Default;
2837 lyxerr << _("Unknown spacing argument: ")
2838 << argument << endl;
2840 if (cur_spacing != new_spacing || cur_value != new_value) {
2841 par->params().spacing(Spacing(new_spacing, new_value));
2842 lt->redoParagraph(bv_);
2845 | BufferView::FITCUR
2846 | BufferView::CHANGE);
2851 case LFUN_INSET_TOGGLE:
2853 LyXText * lt = bv_->getLyXText();
2856 update(lt, BufferView::SELECT|BufferView::FITCUR);
2857 lt->toggleInset(bv_);
2858 update(lt, BufferView::SELECT|BufferView::FITCUR);
2870 InsetCommandParams p;
2871 if (action == LFUN_HTMLURL)
2872 p.setCmdName("htmlurl");
2874 p.setCmdName("url");
2875 owner_->getDialogs()->createUrl(p.getAsString());
2879 case LFUN_INSERT_URL:
2881 InsetCommandParams p;
2882 p.setFromString(argument);
2884 InsetUrl * inset = new InsetUrl(p);
2885 if (!insertInset(inset))
2888 updateInset(inset, true);
2892 case LFUN_INSET_ERT:
2893 insertAndEditInset(new InsetERT(buffer_->params));
2896 case LFUN_INSET_EXTERNAL:
2897 insertAndEditInset(new InsetExternal);
2900 case LFUN_INSET_FOOTNOTE:
2901 insertAndEditInset(new InsetFoot(buffer_->params));
2904 case LFUN_INSET_MARGINAL:
2905 insertAndEditInset(new InsetMarginal(buffer_->params));
2908 case LFUN_INSET_MINIPAGE:
2909 insertAndEditInset(new InsetMinipage(buffer_->params));
2912 case LFUN_INSERT_NOTE:
2913 insertAndEditInset(new InsetNote(buffer_->params));
2916 case LFUN_INSET_FLOAT:
2917 // check if the float type exist
2918 if (floatList.typeExist(argument)) {
2919 insertAndEditInset(new InsetFloat(buffer_->params,
2922 lyxerr << "Non-existent float type: "
2923 << argument << endl;
2927 case LFUN_INSET_WIDE_FLOAT:
2928 // check if the float type exist
2929 if (floatList.typeExist(argument)) {
2930 InsetFloat * new_inset =
2931 new InsetFloat(buffer_->params, argument);
2932 new_inset->wide(true);
2933 insertAndEditInset(new_inset);
2935 lyxerr << "Non-existent float type: "
2936 << argument << endl;
2941 case LFUN_INSET_LIST:
2942 insertAndEditInset(new InsetList);
2945 case LFUN_INSET_THEOREM:
2946 insertAndEditInset(new InsetTheorem);
2950 case LFUN_INSET_CAPTION:
2952 // Do we have a locking inset...
2953 if (bv_->theLockingInset()) {
2954 lyxerr << "Locking inset code: "
2955 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2956 InsetCaption * new_inset =
2957 new InsetCaption(buffer_->params);
2958 new_inset->setOwner(bv_->theLockingInset());
2959 new_inset->setAutoBreakRows(true);
2960 new_inset->setDrawFrame(0, InsetText::LOCKED);
2961 new_inset->setFrameColor(0, LColor::captionframe);
2962 if (insertInset(new_inset))
2963 new_inset->edit(bv_);
2970 case LFUN_INSET_TABULAR:
2974 if (!argument.empty())
2975 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2976 InsetTabular * new_inset =
2977 new InsetTabular(*buffer_, r, c);
2979 bv_->getLyXText()->real_current_font.isRightToLeft();
2980 if (!open_new_inset(new_inset, rtl))
2985 // --- lyxserver commands ----------------------------
2987 case LFUN_CHARATCURSOR:
2989 pos_type pos = bv_->getLyXText()->cursor.pos();
2990 if (pos < bv_->getLyXText()->cursor.par()->size())
2991 owner_->getLyXFunc()->setMessage(
2992 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2994 owner_->getLyXFunc()->setMessage("EOF");
2999 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
3001 + tostr(bv_->getLyXText()->cursor.y()));
3008 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
3009 lyxerr << "SETXY: Could not parse coordinates in '"
3010 << argument << std::endl;
3012 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
3016 case LFUN_GETLAYOUT:
3017 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3022 LyXFont & font = bv_->getLyXText()->current_font;
3023 if (font.shape() == LyXFont::ITALIC_SHAPE)
3024 owner_->getLyXFunc()->setMessage("E");
3025 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3026 owner_->getLyXFunc()->setMessage("N");
3028 owner_->getLyXFunc()->setMessage("0");
3033 // --- accented characters ---------------------------
3036 case LFUN_CIRCUMFLEX:
3046 case LFUN_SPECIAL_CARON:
3049 case LFUN_HUNG_UMLAUT:
3052 if (argument.empty()) {
3054 owner_->getLyXFunc()->handleKeyFunc(action);
3056 owner_->getLyXFunc()->handleKeyFunc(action);
3057 owner_->getIntl()->getTrans()
3058 .TranslateAndInsert(argument[0], bv_->getLyXText());
3059 update(bv_->getLyXText(),
3061 | BufferView::FITCUR
3062 | BufferView::CHANGE);
3066 case LFUN_MATH_MACRO:
3067 mathDispatchMathMacro(bv_, argument);
3070 case LFUN_MATH_DELIM:
3071 mathDispatchMathDelim(bv_, argument);
3074 case LFUN_INSERT_MATRIX:
3075 mathDispatchInsertMatrix(bv_, argument);
3078 case LFUN_INSERT_MATH:
3079 mathDispatchInsertMath(bv_, argument);
3082 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3083 mathDispatchMathImportSelection(bv_, argument);
3086 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3087 mathDispatchMathDisplay(bv_, argument);
3090 case LFUN_MATH_MODE: // Open or create an inlined math inset
3091 mathDispatchMathMode(bv_, argument);
3094 case LFUN_GREEK: // Insert a single greek letter
3095 mathDispatchGreek(bv_, argument);
3098 case LFUN_CITATION_INSERT:
3100 InsetCommandParams p;
3101 p.setFromString(argument);
3103 InsetCitation * inset = new InsetCitation(p);
3104 if (!insertInset(inset))
3107 updateInset(inset, true);
3111 case LFUN_INSERT_BIBTEX:
3113 // ale970405+lasgoutt970425
3114 // The argument can be up to two tokens separated
3115 // by a space. The first one is the bibstyle.
3116 string const db = token(argument, ' ', 0);
3117 string const bibstyle = token(argument, ' ', 1);
3119 InsetCommandParams p("BibTeX", db, bibstyle);
3120 InsetBibtex * inset = new InsetBibtex(p);
3122 if (insertInset(inset)) {
3123 if (argument.empty())
3130 // BibTeX data bases
3131 case LFUN_BIBDB_ADD:
3133 InsetBibtex * inset =
3134 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3136 inset->addDatabase(argument);
3141 case LFUN_BIBDB_DEL:
3143 InsetBibtex * inset =
3144 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3146 inset->delDatabase(argument);
3151 case LFUN_BIBTEX_STYLE:
3153 InsetBibtex * inset =
3154 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3156 inset->setOptions(argument);
3161 case LFUN_INDEX_CREATE:
3163 InsetCommandParams p("index");
3164 if (argument.empty()) {
3165 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3166 p.setContents(idxstring);
3168 p.setContents(argument);
3171 owner_->getDialogs()->createIndex(p.getAsString());
3175 case LFUN_INDEX_INSERT:
3177 InsetCommandParams p;
3178 p.setFromString(argument);
3179 InsetIndex * inset = new InsetIndex(p);
3181 if (!insertInset(inset))
3184 updateInset(inset, true);
3188 case LFUN_INDEX_INSERT_LAST:
3190 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3191 if (!idxstring.empty()) {
3192 owner_->message(_("Word `")
3193 + idxstring + _(("' indexed.")));
3194 InsetCommandParams p("index", idxstring);
3195 InsetIndex * inset = new InsetIndex(p);
3197 if (!insertInset(inset))
3200 updateInset(inset, true);
3205 case LFUN_INDEX_PRINT:
3207 InsetCommandParams p("printindex");
3208 Inset * inset = new InsetPrintIndex(p);
3209 if (!insertInset(inset, tclass.defaultLayoutName()))
3214 case LFUN_PARENTINSERT:
3216 InsetCommandParams p("lyxparent", argument);
3217 Inset * inset = new InsetParent(p, *buffer_);
3218 if (!insertInset(inset, tclass.defaultLayoutName()))
3224 case LFUN_CHILD_INSERT:
3226 InsetInclude::Params p;
3227 p.cparams.setFromString(argument);
3228 p.masterFilename_ = buffer_->fileName();
3230 InsetInclude * inset = new InsetInclude(p);
3231 if (!insertInset(inset))
3234 updateInset(inset, true);
3235 bv_->owner()->getDialogs()->showInclude(inset);
3240 case LFUN_FLOAT_LIST:
3241 if (floatList.typeExist(argument)) {
3242 Inset * inset = new InsetFloatList(argument);
3243 if (!insertInset(inset, tclass.defaultLayoutName()))
3246 lyxerr << "Non-existent float type: "
3247 << argument << endl;
3251 case LFUN_THESAURUS_ENTRY:
3253 string arg = argument;
3256 arg = bv_->getLyXText()->selectionAsString(buffer_,
3260 if (arg.size() > 100 || arg.empty()) {
3261 // Get word or selection
3262 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3263 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3264 // FIXME: where is getLyXText()->unselect(bv_) ?
3268 bv_->owner()->getDialogs()->showThesaurus(arg);
3272 case LFUN_SELFINSERT:
3274 if (argument.empty()) break;
3276 /* Automatically delete the currently selected
3277 * text and replace it with what is being
3278 * typed in now. Depends on lyxrc settings
3279 * "auto_region_delete", which defaults to
3282 LyXText * lt = bv_->getLyXText();
3284 if (lyxrc.auto_region_delete) {
3285 if (lt->selection.set()) {
3286 lt->cutSelection(bv_, false, false);
3289 | BufferView::FITCUR
3290 | BufferView::CHANGE);
3292 workarea().haveSelection(false);
3296 LyXFont const old_font(lt->real_current_font);
3298 string::const_iterator cit = argument.begin();
3299 string::const_iterator end = argument.end();
3300 for (; cit != end; ++cit) {
3301 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3306 | BufferView::FITCUR
3307 | BufferView::CHANGE);
3309 lt->selection.cursor = lt->cursor;
3310 moveCursorUpdate(false);
3312 // real_current_font.number can change so we need to
3313 // update the minibuffer
3314 if (old_font != lt->real_current_font)
3315 owner_->showState();
3320 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3322 time_t now_time_t = time(NULL);
3323 struct tm * now_tm = localtime(&now_time_t);
3324 setlocale(LC_TIME, "");
3326 if (!argument.empty())
3329 arg = lyxrc.date_insert_format;
3331 int const datetmp_len =
3332 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3334 LyXText * lt = bv_->getLyXText();
3336 for (int i = 0; i < datetmp_len; i++) {
3337 lt->insertChar(bv_, datetmp[i]);
3340 | BufferView::FITCUR
3341 | BufferView::CHANGE);
3344 lt->selection.cursor = lt->cursor;
3345 moveCursorUpdate(false);
3349 case LFUN_UNKNOWN_ACTION:
3350 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3361 void BufferView::Pimpl::newline()
3364 LyXText * lt = bv_->getLyXText();
3368 | BufferView::FITCUR);
3369 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3372 | BufferView::FITCUR
3373 | BufferView::CHANGE);
3378 void BufferView::Pimpl::hfill()
3381 LyXText * lt = bv_->getLyXText();
3385 | BufferView::FITCUR);
3386 lt->insertChar(bv_, Paragraph::META_HFILL);
3389 | BufferView::FITCUR
3390 | BufferView::CHANGE);
3395 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3398 LyXText * lt = bv_->getLyXText();
3401 update(lt, BufferView::SELECT|BufferView::FITCUR);
3402 InsetSpecialChar * new_inset =
3403 new InsetSpecialChar(kind);
3404 if (!insertInset(new_inset))
3407 updateInset(new_inset, true);
3412 void BufferView::Pimpl::smartQuote()
3414 LyXText const * lt = bv_->getLyXText();
3415 Paragraph const * par = lt->cursor.par();
3416 pos_type pos = lt->cursor.pos();
3420 || (par->isInset(pos - 1)
3421 && par->getInset(pos - 1)->isSpace()))
3424 c = par->getChar(pos - 1);
3429 LyXLayout const & style =
3430 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3432 if (style.pass_thru ||
3433 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3434 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3438 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3440 if (insertInset(inset))
3447 // Open and lock an updatable inset
3448 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3450 LyXText * lt = bv_->getLyXText();
3454 if (!insertInset(new_inset)) {
3458 new_inset->edit(bv_, !behind);
3463 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3465 // if we are in a locking inset we should try to insert the
3466 // inset there otherwise this is a illegal function now
3467 if (bv_->theLockingInset()) {
3468 if (bv_->theLockingInset()->insetAllowed(inset))
3469 return bv_->theLockingInset()->insertInset(bv_, inset);
3473 // not quite sure if we want this...
3474 setCursorParUndo(bv_);
3477 beforeChange(bv_->text);
3478 if (!lout.empty()) {
3479 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3480 bv_->text->breakParagraph(bv_);
3481 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3483 if (bv_->text->cursor.par()->size()) {
3484 bv_->text->cursorLeft(bv_);
3486 bv_->text->breakParagraph(bv_);
3487 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3491 LyXTextClass const & tclass =
3492 textclasslist[buffer_->params.textclass];
3493 bool hasLayout = tclass.hasLayout(lres);
3494 string lay = tclass.defaultLayoutName();
3496 if (hasLayout != false) {
3500 // layout not fount using default
3501 lay = tclass.defaultLayoutName();
3504 bv_->text->setLayout(bv_, lay);
3506 bv_->text->setParagraph(bv_, 0, 0,
3508 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3513 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3516 bv_->text->insertInset(bv_, inset);
3517 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3524 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3526 if (!inset || !available())
3529 // first check for locking insets
3530 if (bv_->theLockingInset()) {
3531 if (bv_->theLockingInset() == inset) {
3532 if (bv_->text->updateInset(bv_, inset)) {
3535 buffer_->markDirty();
3540 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3541 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3544 buffer_->markDirty();
3552 // then check if the inset is a top_level inset (has no owner)
3553 // if yes do the update as always otherwise we have to update the
3554 // toplevel inset where this inset is inside
3555 Inset * tl_inset = inset;
3556 while(tl_inset->owner())
3557 tl_inset = tl_inset->owner();
3559 if (tl_inset == inset) {
3560 update(bv_->text, BufferView::UPDATE);
3561 if (bv_->text->updateInset(bv_, inset)) {
3565 | BufferView::FITCUR
3566 | BufferView::CHANGE);
3568 update(bv_->text, SELECT);
3572 } else if (static_cast<UpdatableInset *>(tl_inset)
3573 ->updateInsetInInset(bv_, inset))
3575 if (bv_->text->updateInset(bv_, tl_inset)) {
3583 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3586 if (!available()) return;
3589 beforeChange(bv_->text);
3590 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3592 LyXCursor const & cursor = bv_->text->cursor;
3596 cursor.par()->isInset(cursor.pos())) {
3597 Inset const * inset = cursor.par()->getInset(cursor.pos());
3598 if (find(codes.begin(), codes.end(), inset->lyxCode())
3601 static_cast<InsetCommand const *>(inset)->getContents();
3605 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3606 if (bv_->text->cursor.pos()
3607 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3608 LyXCursor tmp = bv_->text->cursor;
3609 bv_->text->cursor.par(bv_->text->ownerParagraph());
3610 bv_->text->cursor.pos(0);
3611 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3612 bv_->text->cursor = tmp;
3613 bv_->owner()->message(_("No more insets"));
3616 bv_->owner()->message(_("No more insets"));
3619 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3620 bv_->text->selection.cursor = bv_->text->cursor;
3624 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3626 gotoInset(vector<Inset::Code>(1, code), same_content);