7 #include "BufferView_pimpl.h"
12 #include "paragraph.h"
14 #include "commandtags.h"
18 #include "bufferview_funcs.h"
19 #include "TextCache.h"
20 #include "bufferlist.h"
23 // added for Dispatch functions
26 #include "FloatList.h"
28 #include "ParagraphParameters.h"
29 #include "undo_funcs.h"
30 #include "lyxtextclasslist.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Alert.h"
34 #include "frontends/FileDialog.h"
36 #include "insets/insetbib.h"
37 #include "insets/insettext.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetnote.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetlist.h"
59 #include "insets/insetcaption.h"
60 #include "insets/insetfloatlist.h"
61 #include "insets/insetspecialchar.h"
63 #include "mathed/formulabase.h"
65 #include "support/LAssert.h"
66 #include "support/lstrings.h"
67 #include "support/filetools.h"
68 #include "support/lyxfunctional.h"
76 extern string current_layout;
88 using lyx::textclass_type;
90 /* the selection possible is needed, that only motion events are
91 * used, where the bottom press event was on the drawing area too */
92 bool selection_possible = false;
94 extern BufferList bufferlist;
95 extern char ascii_type;
97 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
102 const unsigned int saved_positions_num = 20;
107 XSync(fl_get_display(), 0);
111 void SetXtermCursor(Window win)
113 static Cursor cursor;
114 static bool cursor_undefined = true;
115 if (cursor_undefined) {
116 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
117 XFlush(fl_get_display());
118 cursor_undefined = false;
120 XDefineCursor(fl_get_display(), win, cursor);
121 XFlush(fl_get_display());
127 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
128 int xpos, int ypos, int width, int height)
129 : bv_(b), owner_(o), buffer_(0),
130 current_scrollbar_value(0), cursor_timeout(400),
131 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
135 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
136 workarea_.workAreaExpose
137 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
138 workarea_.workAreaEnter
139 .connect(slot(this, &BufferView::Pimpl::enterView));
140 workarea_.workAreaLeave
141 .connect(slot(this, &BufferView::Pimpl::leaveView));
142 workarea_.workAreaButtonPress
143 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
144 workarea_.workAreaButtonRelease
146 &BufferView::Pimpl::workAreaButtonRelease));
147 workarea_.workAreaMotionNotify
148 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
149 workarea_.workAreaDoubleClick
150 .connect(slot(this, &BufferView::Pimpl::doubleClick));
151 workarea_.workAreaTripleClick
152 .connect(slot(this, &BufferView::Pimpl::tripleClick));
153 workarea_.workAreaKeyPress
154 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
155 workarea_.selectionRequested
156 .connect(slot(this, &BufferView::Pimpl::selectionRequested));
157 workarea_.selectionLost
158 .connect(slot(this, &BufferView::Pimpl::selectionLost));
160 cursor_timeout.timeout.connect(slot(this,
161 &BufferView::Pimpl::cursorToggle));
162 cursor_timeout.start();
163 workarea_.setFocus();
164 saved_positions.resize(saved_positions_num);
168 Painter & BufferView::Pimpl::painter()
170 return workarea_.getPainter();
174 void BufferView::Pimpl::buffer(Buffer * b)
176 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
182 buffer_->delUser(bv_);
184 // Put the old text into the TextCache, but
185 // only if the buffer is still loaded.
186 // Also set the owner of the test to 0
187 // bv_->text->owner(0);
188 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
189 if (lyxerr.debugging())
190 textcache.show(lyxerr, "BufferView::buffer");
195 // Set current buffer
198 if (bufferlist.getState() == BufferList::CLOSING) return;
201 // screen is always deleted when the buffer is changed.
204 // If we are closing the buffer, use the first buffer as current
206 buffer_ = bufferlist.first();
210 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
211 buffer_->addUser(bv_);
212 // If we don't have a text object for this, we make one
213 if (bv_->text == 0) {
214 resizeCurrentBuffer();
219 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
220 owner_->updateMenubar();
221 owner_->updateToolbar();
222 // Similarly, buffer-dependent dialogs should be updated or
223 // hidden. This should go here because some dialogs (eg ToC)
224 // require bv_->text.
225 owner_->getDialogs()->updateBufferDependent(true);
231 lyxerr[Debug::INFO] << " No Buffer!" << endl;
232 owner_->updateMenubar();
233 owner_->updateToolbar();
234 owner_->getDialogs()->hideBufferDependent();
238 // Also remove all remaining text's from the testcache.
239 // (there should not be any!) (if there is any it is a
241 if (lyxerr.debugging())
242 textcache.show(lyxerr, "buffer delete all");
245 // should update layoutchoice even if we don't have a buffer.
246 owner_->updateLayoutChoice();
248 owner_->updateWindowTitle();
252 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
254 workarea_.resize(xpos, ypos, width, height);
255 update(bv_->text, SELECT);
260 void BufferView::Pimpl::resize()
263 resizeCurrentBuffer();
267 void BufferView::Pimpl::redraw()
269 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
274 bool BufferView::Pimpl::fitCursor()
276 lyx::Assert(screen_.get());
280 if (bv_->theLockingInset()) {
281 bv_->theLockingInset()->fitInsetCursor(bv_);
284 ret = screen_->fitCursor(bv_->text, bv_);
287 bv_->owner()->getDialogs()->updateParagraph();
294 void BufferView::Pimpl::redoCurrentBuffer()
296 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
297 if (buffer_ && bv_->text) {
299 owner_->updateLayoutChoice();
304 int BufferView::Pimpl::resizeCurrentBuffer()
306 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
309 Paragraph * selstartpar = 0;
310 Paragraph * selendpar = 0;
311 UpdatableInset * the_locking_inset = 0;
314 pos_type selstartpos = 0;
315 pos_type selendpos = 0;
316 bool selection = false;
317 bool mark_set = false;
319 owner_->prohibitInput();
321 owner_->message(_("Formatting document..."));
324 par = bv_->text->cursor.par();
325 pos = bv_->text->cursor.pos();
326 selstartpar = bv_->text->selection.start.par();
327 selstartpos = bv_->text->selection.start.pos();
328 selendpar = bv_->text->selection.end.par();
329 selendpos = bv_->text->selection.end.pos();
330 selection = bv_->text->selection.set();
331 mark_set = bv_->text->selection.mark();
332 the_locking_inset = bv_->theLockingInset();
333 buffer_->resizeInsets(bv_);
334 // I don't think the delete and new are necessary here we just could
335 // call only init! (Jug 20020419)
337 bv_->text = new LyXText(bv_);
338 bv_->text->init(bv_);
340 // See if we have a text in TextCache that fits
341 // the new buffer_ with the correct width.
342 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
344 if (lyxerr.debugging()) {
345 lyxerr << "Found a LyXText that fits:\n";
346 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
348 // Set the owner of the newly found text
349 // bv_->text->owner(bv_);
350 if (lyxerr.debugging())
351 textcache.show(lyxerr, "resizeCurrentBuffer");
353 bv_->text = new LyXText(bv_);
354 bv_->text->init(bv_);
355 //buffer_->resizeInsets(bv_);
362 bv_->text->selection.set(true);
363 // At this point just to avoid the Delete-Empty-Paragraph-
364 // Mechanism when setting the cursor.
365 bv_->text->selection.mark(mark_set);
367 bv_->text->setCursor(bv_, selstartpar, selstartpos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->setCursor(bv_, selendpar, selendpos);
370 bv_->text->setSelection(bv_);
371 bv_->text->setCursor(bv_, par, pos);
373 bv_->text->setCursor(bv_, par, pos);
374 bv_->text->selection.cursor = bv_->text->cursor;
375 bv_->text->selection.set(false);
377 // remake the inset locking
378 bv_->theLockingInset(the_locking_inset);
381 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
383 // this will scroll the screen such that the cursor becomes visible
388 owner_->allowInput();
390 /// clear the "Formatting Document" message
397 void BufferView::Pimpl::updateScreen()
399 // Regenerate the screen.
400 screen_.reset(new LyXScreen(workarea_));
404 void BufferView::Pimpl::updateScrollbar()
407 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
408 workarea_.setScrollbar(0, 1.0);
412 long const text_height = bv_->text->height;
413 long const work_height = workarea_.height();
415 double const lineh = bv_->text->defaultHeight();
416 double const slider_size =
417 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
419 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
420 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
422 /* If the text is smaller than the working area, the scrollbar
423 * maximum must be the working area height. No scrolling will
425 if (text_height <= work_height) {
426 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
427 workarea_.setScrollbarBounds(0.0, 0.0);
428 current_scrollbar_value = bv_->text->first_y;
429 workarea_.setScrollbar(current_scrollbar_value, 1.0);
433 workarea_.setScrollbarBounds(0.0, text_height - work_height);
434 workarea_.setScrollbarIncrements(lineh);
435 current_scrollbar_value = bv_->text->first_y;
436 workarea_.setScrollbar(current_scrollbar_value, slider_size);
440 // Callback for scrollbar slider
441 void BufferView::Pimpl::scrollCB(double value)
443 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
445 if (!buffer_) return;
447 current_scrollbar_value = long(value);
449 if (current_scrollbar_value < 0)
450 current_scrollbar_value = 0;
455 screen_->draw(bv_->text, bv_, current_scrollbar_value);
457 if (!lyxrc.cursor_follows_scrollbar) {
462 LyXText * vbt = bv_->text;
464 int const height = vbt->defaultHeight();
465 int const first = static_cast<int>((bv_->text->first_y + height));
466 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
468 if (vbt->cursor.y() < first)
469 vbt->setCursorFromCoordinates(bv_, 0, first);
470 else if (vbt->cursor.y() > last)
471 vbt->setCursorFromCoordinates(bv_, 0, last);
477 int BufferView::Pimpl::scrollUp(long time)
479 if (!buffer_ || !screen_.get())
482 double value = workarea_.getScrollbarValue();
488 float add_value = (bv_->text->defaultHeight()
489 + float(time) * float(time) * 0.125);
491 if (add_value > workarea_.height())
492 add_value = float(workarea_.height() -
493 bv_->text->defaultHeight());
495 float add_value = float(workarea_.height()) * float(time) / 100;
503 workarea_.setScrollbarValue(value);
510 int BufferView::Pimpl::scrollDown(long time)
512 if (!buffer_ || !screen_.get())
515 double value = workarea_.getScrollbarValue();
516 pair<float, float> p = workarea_.getScrollbarBounds();
517 double const max = p.second;
523 float add_value = (bv_->text->defaultHeight()
524 + float(time) * float(time) * 0.125);
526 if (add_value > workarea_.height())
527 add_value = float(workarea_.height() -
528 bv_->text->defaultHeight());
530 float add_value = float(workarea_.height()) * float(time) / 100;
538 workarea_.setScrollbarValue(value);
545 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
547 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
551 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
553 // Only use motion with button 1
554 if (!(state & Button1MotionMask))
557 if (!buffer_ || !screen_.get()) return;
559 // Check for inset locking
560 if (bv_->theLockingInset()) {
561 LyXCursor cursor = bv_->text->cursor;
562 LyXFont font = bv_->text->getFont(buffer_,
563 cursor.par(), cursor.pos());
564 int width = bv_->theLockingInset()->width(bv_, font);
565 int inset_x = font.isVisibleRightToLeft()
566 ? cursor.ix() - width : cursor.ix();
567 int start_x = inset_x + bv_->theLockingInset()->scroll();
568 bv_->theLockingInset()->
569 insetMotionNotify(bv_,
571 y - cursor.iy() + bv_->text->first_y,
576 /* The test for not selection possible is needed, that only motion
577 events are used, where the bottom press event was on
578 the drawing area too */
579 if (!selection_possible)
582 screen_->hideCursor();
584 int y_before = bv_->text->cursor.y();
586 Row * cursorrow = bv_->text->cursor.row();
587 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
589 // sorry for this but I have a strange error that the y value jumps at
590 // a certain point. This seems like an error in my xforms library or
591 // in some other local environment, but I would like to leave this here
592 // for the moment until I can remove this (Jug 20020418)
593 if (y_before < bv_->text->cursor.y())
594 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
596 // This is to allow jumping over large insets
597 if (cursorrow == bv_->text->cursor.row()) {
598 if (y >= int(workarea_.height())) {
599 bv_->text->cursorDown(bv_, false);
601 bv_->text->cursorUp(bv_, false);
605 if (!bv_->text->selection.set())
606 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
608 bv_->text->setSelection(bv_);
609 screen_->toggleToggle(bv_->text, bv_);
615 // Single-click on work area
616 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
619 if (!buffer_ || !screen_.get())
622 // ok ok, this is a hack.
623 // Why??? (Jug20020424)
624 if (button == 4 || button == 5) {
627 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
630 scrollDown(lyxrc.wheel_jump);
633 // We shouldn't go further down as we really should only do the
634 // scrolling and be done with this. Otherwise we may open some
635 // dialogs (Jug 20020424).
639 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
641 // Middle button press pastes if we have a selection
642 // We do this here as if the selection was inside an inset
643 // it could get cleared on the unlocking of the inset so
644 // we have to check this first
645 bool paste_internally = false;
646 if (button == 2 && bv_->getLyXText()->selection.set()) {
647 owner_->getLyXFunc()->dispatch(LFUN_COPY);
648 paste_internally = true;
651 int const screen_first = bv_->text->first_y;
653 if (bv_->theLockingInset()) {
654 // We are in inset locking mode
656 /* Check whether the inset was hit. If not reset mode,
657 otherwise give the event to the inset */
658 if (inset_hit == bv_->theLockingInset()) {
659 bv_->theLockingInset()->
660 insetButtonPress(bv_,xpos, ypos,button);
663 bv_->unlockInset(bv_->theLockingInset());
668 selection_possible = true;
669 screen_->hideCursor();
671 // Clear the selection
672 screen_->toggleSelection(bv_->text, bv_);
673 bv_->text->clearSelection();
674 bv_->text->fullRebreak(bv_);
678 // Single left click in math inset?
679 if (isHighlyEditableInset(inset_hit)) {
680 // Highly editable inset, like math
681 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
682 selection_possible = false;
683 owner_->updateLayoutChoice();
684 owner_->message(inset->editMessage());
685 //inset->edit(bv_, xpos, ypos, button);
686 // We just have to lock the inset before calling a PressEvent on it!
687 // we don't need the edit() call here! (Jug20020329)
688 if (!bv_->lockInset(inset)) {
689 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
691 inset->insetButtonPress(bv_, xpos, ypos, button);
694 // I'm not sure we should continue here if we hit an inset (Jug20020403)
696 // Right click on a footnote flag opens float menu
698 selection_possible = false;
702 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
703 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
705 bv_->text->selection.cursor = bv_->text->cursor;
706 bv_->text->cursor.x_fix(bv_->text->cursor.x());
708 owner_->updateLayoutChoice();
710 selection_possible = false;
713 // Insert primary selection with middle mouse
714 // if there is a local selection in the current buffer,
717 if (paste_internally)
718 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
720 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
722 selection_possible = false;
728 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
734 LyXText * text = bv_->getLyXText();
736 if (text->bv_owner && bv_->theLockingInset())
739 if (screen_.get() && button == 1) {
740 if (text->bv_owner) {
741 screen_->hideCursor();
742 screen_->toggleSelection(text, bv_);
743 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
744 screen_->toggleSelection(text, bv_, false);
746 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
748 /* This will fit the cursor on the screen
750 update(text, BufferView::SELECT|BufferView::FITCUR);
755 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
761 LyXText * text = bv_->getLyXText();
763 if (text->bv_owner && bv_->theLockingInset())
766 if (screen_.get() && (button == 1)) {
767 if (text->bv_owner) {
768 screen_->hideCursor();
769 screen_->toggleSelection(text, bv_);
771 text->cursorHome(bv_);
772 text->selection.cursor = text->cursor;
773 text->cursorEnd(bv_);
774 text->setSelection(bv_);
775 if (text->bv_owner) {
776 screen_->toggleSelection(text, bv_, false);
778 /* This will fit the cursor on the screen
780 update(text, BufferView::SELECT|BufferView::FITCUR);
785 void BufferView::Pimpl::selectionRequested()
792 LyXText * text = bv_->getLyXText();
794 if (text->selection.set() &&
795 (!bv_->text->xsel_cache.set() ||
796 text->selection.start != bv_->text->xsel_cache.start ||
797 text->selection.end != bv_->text->xsel_cache.end))
799 bv_->text->xsel_cache = text->selection;
800 sel = text->selectionAsString(bv_->buffer(), false);
801 } else if (!text->selection.set()) {
803 bv_->text->xsel_cache.set(false);
806 workarea_.putClipboard(sel);
811 void BufferView::Pimpl::selectionLost()
813 if (active() && available()) {
816 bv_->getLyXText()->clearSelection();
818 bv_->text->xsel_cache.set(false);
823 void BufferView::Pimpl::enterView()
825 if (active() && available()) {
826 SetXtermCursor(workarea_.getWin());
827 using_xterm_cursor = true;
832 void BufferView::Pimpl::leaveView()
834 if (using_xterm_cursor) {
835 XUndefineCursor(fl_get_display(), workarea_.getWin());
836 using_xterm_cursor = false;
841 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
844 // do nothing if we used the mouse wheel
845 if (!buffer_ || !screen_.get() || button == 4 || button == 5)
848 // If we hit an inset, we have the inset coordinates in these
849 // and inset_hit points to the inset. If we do not hit an
850 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
851 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
853 if (bv_->theLockingInset()) {
854 // We are in inset locking mode.
856 /* LyX does a kind of work-area grabbing for insets.
857 Only a ButtonPress Event outside the inset will
858 force a insetUnlock. */
859 bv_->theLockingInset()->
860 insetButtonRelease(bv_, x, y, button);
864 selection_possible = false;
871 workarea_.haveSelection(bv_->getLyXText()->selection.set());
876 owner_->updateMenubar();
877 owner_->updateToolbar();
879 // Did we hit an editable inset?
881 selection_possible = false;
883 // if we reach this point with a selection, it
884 // must mean we are currently selecting.
885 // But we don't want to open the inset
886 // because that is annoying for the user.
887 // So just pretend we didn't hit it.
888 // this is OK because a "kosher" ButtonRelease
889 // will follow a ButtonPress that clears
891 // Note this also fixes selection drawing
892 // problems if we end up opening an inset
893 if (bv_->getLyXText()->selection.set())
896 // CHECK fix this proper in 0.13
897 // well, maybe 13.0 !!!!!!!!!
899 // Following a ref shouldn't issue
900 // a push on the undo-stack
901 // anylonger, now that we have
902 // keybindings for following
903 // references and returning from
904 // references. IMHO though, it
905 // should be the inset's own business
906 // to push or not push on the undo
907 // stack. They don't *have* to
908 // alter the document...
910 // ...or maybe the SetCursorParUndo()
911 // below isn't necessary at all anylonger?
912 if (inset_hit->lyxCode() == Inset::REF_CODE) {
913 setCursorParUndo(bv_);
916 owner_->message(inset_hit->editMessage());
918 if (isHighlyEditableInset(inset_hit)) {
919 // Highly editable inset, like math
920 UpdatableInset *inset = (UpdatableInset *)inset_hit;
921 inset->insetButtonRelease(bv_, x, y, button);
923 inset_hit->insetButtonRelease(bv_, x, y, button);
924 // IMO this is a grosshack! Inset's should be changed so that
925 // they call the actions they have to do with the insetButtonRel.
926 // function and not in the edit(). This should be changed
928 inset_hit->edit(bv_, x, y, button);
933 // Maybe we want to edit a bibitem ale970302
934 if (bv_->text->cursor.par()->bibkey && x < 20 +
935 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
936 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
943 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
944 LyXCursor const & cursor) const
946 Paragraph /*const*/ & par = *cursor.par();
947 pos_type const pos = cursor.pos();
949 lyx::Assert(par.getInset(pos));
951 Inset const & inset(*par.getInset(pos));
953 LyXFont const & font = text.getFont(buffer_, &par, pos);
955 int const width = inset.width(bv_, font);
956 int const inset_x = font.isVisibleRightToLeft()
957 ? (cursor.ix() - width) : cursor.ix();
960 inset_x + inset.scroll(),
962 cursor.iy() - inset.ascent(bv_, font),
963 cursor.iy() + inset.descent(bv_, font));
967 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
968 LyXCursor const & cursor,
969 int & x, int & y) const
971 pos_type const pos(cursor.pos());
972 Paragraph /*const*/ & par(*cursor.par());
974 if (pos >= par.size() || !par.isInset(pos)) {
978 Inset /*const*/ * inset = par.getInset(pos);
980 if (!isEditableInset(inset)) {
984 Box b(insetDimensions(text, cursor));
986 if (!b.contained(x, y)) {
987 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
988 << " box " << b << endl;
992 text.setCursor(bv_, &par, pos, true);
995 // The origin of an inset is on the baseline
996 y -= text.cursor.iy();
1002 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
1007 int y_tmp = y + text->first_y;
1010 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
1012 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1019 // look at previous position
1021 if (cursor.pos() == 0) {
1026 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1028 inset = checkInset(*text, cursor, x, y_tmp);
1036 void BufferView::Pimpl::workAreaExpose()
1038 static int work_area_width;
1039 static unsigned int work_area_height;
1041 bool const widthChange = workarea_.workWidth() != work_area_width;
1042 bool const heightChange = workarea_.height() != work_area_height;
1044 // update from work area
1045 work_area_width = workarea_.workWidth();
1046 work_area_height = workarea_.height();
1049 // The visible LyXView need a resize
1052 // Remove all texts from the textcache
1053 // This is not _really_ what we want to do. What
1054 // we really want to do is to delete in textcache
1055 // that does not have a BufferView with matching
1056 // width, but as long as we have only one BufferView
1057 // deleting all gives the same result.
1058 if (lyxerr.debugging())
1059 textcache.show(lyxerr, "Expose delete all");
1061 buffer_->resizeInsets(bv_);
1062 } else if (heightChange) {
1063 // Rebuild image of current screen
1065 // fitCursor() ensures we don't jump back
1066 // to the start of the document on vertical
1070 // The main window size has changed, repaint most stuff
1072 } else if (screen_.get())
1073 screen_->redraw(bv_->text, bv_);
1075 // Grey box when we don't have a buffer
1076 workarea_.greyOut();
1079 // always make sure that the scrollbar is sane.
1081 owner_->updateLayoutChoice();
1086 void BufferView::Pimpl::update()
1088 if (screen_.get() &&
1089 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1091 LyXText::text_status st = bv_->text->status();
1092 screen_->update(bv_->text, bv_);
1094 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1095 bv_->text->fullRebreak(bv_);
1096 st = LyXText::NEED_MORE_REFRESH;
1097 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1098 bv_->text->cursor.pos());
1099 if (bv_->text->selection.set()) {
1100 bv_->text->setCursor(bv_, bv_->text->selection.start,
1101 bv_->text->selection.start.par(),
1102 bv_->text->selection.start.pos());
1103 bv_->text->setCursor(bv_, bv_->text->selection.end,
1104 bv_->text->selection.end.par(),
1105 bv_->text->selection.end.pos());
1108 bv_->text->status(bv_, st);
1109 screen_->update(bv_->text, bv_);
1111 // do this here instead of in the screen::update because of
1113 bv_->text->status(bv_, LyXText::UNCHANGED);
1119 // Values used when calling update:
1121 // -2 - update, move sel_cursor if selection, fitcursor
1122 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1123 // 0 - update, move sel_cursor if selection, fitcursor
1124 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1125 // 3 - update, move sel_cursor if selection
1128 // a simple redraw of the parts that need refresh
1130 // move sel_cursor if selection -
1131 // the text's sel_cursor is moved if there is selection is progress
1134 // fitCursor() is called and the scrollbar updated
1137 // the buffer is marked dirty.
1146 // UPDATE_ONLY = UPDATE;
1147 // UPDATE_SELECT = UPDATE | SELECT;
1148 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1149 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1151 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1152 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1153 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1154 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1155 // update(3) -> update(1) -> update(1) -> update(SELECT)
1157 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1159 owner_->updateLayoutChoice();
1161 if (!text->selection.set() && (f & SELECT)) {
1162 text->selection.cursor = text->cursor;
1165 text->fullRebreak(bv_);
1167 if (text->inset_owner) {
1168 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1169 updateInset(text->inset_owner, false);
1179 buffer_->markDirty();
1184 // Callback for cursor timer
1185 void BufferView::Pimpl::cursorToggle()
1188 cursor_timeout.restart();
1192 if (!screen_.get()) {
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 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1395 owner_->getIntl()->KeyMapSec();
1397 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1398 owner_->getIntl()->KeyMapPrim();
1404 void BufferView::Pimpl::insetSleep()
1406 if (bv_->theLockingInset() && !inset_slept) {
1407 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1408 bv_->theLockingInset()->insetUnlock(bv_);
1414 void BufferView::Pimpl::insetWakeup()
1416 if (bv_->theLockingInset() && inset_slept) {
1417 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1418 inset_slept = false;
1424 void BufferView::Pimpl::insetUnlock()
1426 if (bv_->theLockingInset()) {
1428 bv_->theLockingInset()->insetUnlock(bv_);
1429 bv_->theLockingInset(0);
1431 inset_slept = false;
1436 bool BufferView::Pimpl::focus() const
1438 return workarea_.hasFocus();
1442 void BufferView::Pimpl::focus(bool f)
1444 if (f) workarea_.setFocus();
1448 bool BufferView::Pimpl::active() const
1450 return workarea_.active();
1454 bool BufferView::Pimpl::belowMouse() const
1456 return workarea_.belowMouse();
1460 void BufferView::Pimpl::showCursor()
1462 if (screen_.get()) {
1463 if (bv_->theLockingInset())
1464 bv_->theLockingInset()->showInsetCursor(bv_);
1466 screen_->showCursor(bv_->text, bv_);
1471 void BufferView::Pimpl::hideCursor()
1473 if (screen_.get()) {
1474 if (!bv_->theLockingInset())
1475 // bv_->theLockingInset()->hideInsetCursor(bv_);
1477 screen_->hideCursor();
1482 void BufferView::Pimpl::toggleSelection(bool b)
1484 if (screen_.get()) {
1485 if (bv_->theLockingInset())
1486 bv_->theLockingInset()->toggleSelection(bv_, b);
1487 screen_->toggleSelection(bv_->text, bv_, b);
1492 void BufferView::Pimpl::toggleToggle()
1495 screen_->toggleToggle(bv_->text, bv_);
1499 void BufferView::Pimpl::center()
1501 beforeChange(bv_->text);
1502 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1503 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1505 screen_->draw(bv_->text, bv_, 0);
1507 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1512 void BufferView::Pimpl::pasteClipboard(bool asPara)
1517 screen_->hideCursor();
1518 beforeChange(bv_->text);
1520 string const clip(workarea_.getClipboard());
1526 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1528 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1530 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1534 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1536 workarea_.putClipboard(stuff);
1541 * Dispatch functions for actions which can be valid for BufferView->text
1542 * and/or InsetText->text!!!
1547 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1549 LyXText * lt = bv_->getLyXText();
1551 if (selecting || lt->selection.mark()) {
1552 lt->setSelection(bv_);
1556 updateInset(lt->inset_owner, false);
1560 update(lt, BufferView::SELECT|BufferView::FITCUR);
1562 update(lt, BufferView::SELECT);
1566 if (!lt->selection.set())
1567 workarea_.haveSelection(false);
1569 /* ---> Everytime the cursor is moved, show the current font state. */
1570 // should this too me moved out of this func?
1571 //owner->showState();
1576 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1578 LyXCursor cursor = bv_->getLyXText()->cursor;
1579 Buffer::inset_iterator it =
1580 find_if(Buffer::inset_iterator(
1581 cursor.par(), cursor.pos()),
1582 buffer_->inset_iterator_end(),
1583 lyx::compare_memfun(&Inset::lyxCode, code));
1584 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1588 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1590 string filename = filen;
1592 if (filename.empty()) {
1593 // Launch a file browser
1594 string initpath = lyxrc.document_path;
1597 string const trypath = owner_->buffer()->filePath();
1598 // If directory is writeable, use this as default.
1599 if (IsDirWriteable(trypath))
1603 FileDialog fileDlg(bv_->owner(),
1604 _("Select LyX document to insert"),
1606 make_pair(string(_("Documents|#o#O")),
1607 string(lyxrc.document_path)),
1608 make_pair(string(_("Examples|#E#e")),
1609 string(AddPath(system_lyxdir, "examples"))));
1611 FileDialog::Result result =
1612 fileDlg.Select(initpath,
1613 _("*.lyx| LyX Documents (*.lyx)"));
1615 if (result.first == FileDialog::Later)
1618 filename = result.second;
1620 // check selected filename
1621 if (filename.empty()) {
1622 owner_->message(_("Canceled."));
1627 // get absolute path of file and add ".lyx" to the filename if
1629 filename = FileSearch(string(), filename, "lyx");
1631 string const disp_fn(MakeDisplayPath(filename));
1634 s1 << _("Inserting document") << ' '
1635 << disp_fn << " ...";
1636 owner_->message(s1.str().c_str());
1637 bool const res = bv_->insertLyXFile(filename);
1640 str << _("Document") << ' ' << disp_fn
1641 << ' ' << _("inserted.");
1642 owner_->message(str.str().c_str());
1645 str << _("Could not insert document") << ' '
1647 owner_->message(str.str().c_str());
1652 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1654 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1655 << action <<"] arg[" << argument << "]" << endl;
1657 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1660 // --- Misc -------------------------------------------
1664 LyXText * lt = bv_->getLyXText();
1665 lt->toggleAppendix(bv_);
1668 | BufferView::FITCUR
1669 | BufferView::CHANGE);
1674 case LFUN_TOC_INSERT:
1676 InsetCommandParams p;
1677 p.setCmdName("tableofcontents");
1678 Inset * inset = new InsetTOC(p);
1679 if (!insertInset(inset, tclass.defaultLayoutName()))
1684 case LFUN_SCROLL_INSET:
1685 // this is not handled here as this funktion is only aktive
1686 // if we have a locking_inset and that one is (or contains)
1690 case LFUN_INSET_GRAPHICS:
1692 Inset * new_inset = new InsetGraphics;
1693 if (!insertInset(new_inset)) {
1696 // this is need because you don't use a inset->Edit()
1697 updateInset(new_inset, true);
1698 new_inset->edit(bv_);
1708 case LFUN_PASTESELECTION:
1710 bool asPara = false;
1711 if (argument == "paragraph")
1713 pasteClipboard(asPara);
1725 case LFUN_LAYOUT_COPY:
1726 bv_->copyEnvironment();
1729 case LFUN_LAYOUT_PASTE:
1730 bv_->pasteEnvironment();
1734 case LFUN_GOTOERROR:
1735 gotoInset(Inset::ERROR_CODE, false);
1739 gotoInset(Inset::IGNORE_CODE, false);
1742 case LFUN_REFERENCE_GOTO:
1744 vector<Inset::Code> tmp;
1745 tmp.push_back(Inset::LABEL_CODE);
1746 tmp.push_back(Inset::REF_CODE);
1747 gotoInset(tmp, true);
1751 case LFUN_HYPHENATION:
1752 specialChar(InsetSpecialChar::HYPHENATION);
1755 case LFUN_LIGATURE_BREAK:
1756 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1760 specialChar(InsetSpecialChar::LDOTS);
1763 case LFUN_END_OF_SENTENCE:
1764 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1767 case LFUN_MENU_SEPARATOR:
1768 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1775 case LFUN_DEPTH_MIN:
1776 changeDepth(bv_, bv_->getLyXText(), -1);
1779 case LFUN_DEPTH_PLUS:
1780 changeDepth(bv_, bv_->getLyXText(), 1);
1784 owner_->getDialogs()->setUserFreeFont();
1787 case LFUN_FILE_INSERT:
1788 MenuInsertLyXFile(argument);
1791 case LFUN_FILE_INSERT_ASCII_PARA:
1792 InsertAsciiFile(bv_, argument, true);
1795 case LFUN_FILE_INSERT_ASCII:
1796 InsertAsciiFile(bv_, argument, false);
1801 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1802 << argument << endl;
1804 // Derive layout number from given argument (string)
1805 // and current buffer's textclass (number). */
1806 bool hasLayout = tclass.hasLayout(argument);
1807 string layout = argument;
1809 // If the entry is obsolete, use the new one instead.
1811 string const & obs = tclass[layout].obsoleted_by();
1817 owner_->getLyXFunc()->setErrorMessage(
1818 string(N_("Layout ")) + argument +
1823 bool change_layout = (current_layout != layout);
1824 LyXText * lt = bv_->getLyXText();
1825 if (!change_layout && lt->selection.set() &&
1826 lt->selection.start.par() != lt->selection.end.par())
1828 Paragraph * spar = lt->selection.start.par();
1829 Paragraph * epar = lt->selection.end.par()->next();
1830 while(spar != epar) {
1831 if (spar->layout() != current_layout) {
1832 change_layout = true;
1837 if (change_layout) {
1839 current_layout = layout;
1842 | BufferView::FITCUR);
1843 lt->setLayout(bv_, layout);
1844 owner_->setLayout(layout);
1847 | BufferView::FITCUR
1848 | BufferView::CHANGE);
1855 lang(bv_, argument);
1857 owner_->showState();
1862 owner_->showState();
1867 owner_->showState();
1872 owner_->showState();
1877 owner_->showState();
1882 owner_->showState();
1887 owner_->showState();
1892 owner_->showState();
1895 case LFUN_UNDERLINE:
1897 owner_->showState();
1900 case LFUN_FONT_SIZE:
1901 fontSize(bv_, argument);
1902 owner_->showState();
1905 case LFUN_FONT_STATE:
1906 owner_->getLyXFunc()->setMessage(currentState(bv_));
1909 case LFUN_UPCASE_WORD:
1911 LyXText * lt = bv_->getLyXText();
1915 | BufferView::FITCUR);
1916 lt->changeCase(bv_, LyXText::text_uppercase);
1917 if (lt->inset_owner)
1918 updateInset(lt->inset_owner, true);
1921 | BufferView::FITCUR
1922 | BufferView::CHANGE);
1926 case LFUN_LOWCASE_WORD:
1928 LyXText * lt = bv_->getLyXText();
1930 update(lt, BufferView::SELECT|BufferView::FITCUR);
1931 lt->changeCase(bv_, LyXText::text_lowercase);
1932 if (lt->inset_owner)
1933 updateInset(lt->inset_owner, true);
1936 | BufferView::FITCUR
1937 | BufferView::CHANGE);
1941 case LFUN_CAPITALIZE_WORD:
1943 LyXText * lt = bv_->getLyXText();
1945 update(lt, BufferView::SELECT|BufferView::FITCUR);
1946 lt->changeCase(bv_, LyXText::text_capitalization);
1947 if (lt->inset_owner)
1948 updateInset(lt->inset_owner, true);
1951 | BufferView::FITCUR
1952 | BufferView::CHANGE);
1956 case LFUN_TRANSPOSE_CHARS:
1958 LyXText * lt = bv_->getLyXText();
1960 update(lt, BufferView::SELECT|BufferView::FITCUR);
1961 lt->transposeChars(*bv_);
1962 if (lt->inset_owner)
1963 updateInset(lt->inset_owner, true);
1966 | BufferView::FITCUR
1967 | BufferView::CHANGE);
1972 case LFUN_INSERT_LABEL:
1973 MenuInsertLabel(bv_, argument);
1976 case LFUN_REF_INSERT:
1977 if (argument.empty()) {
1978 InsetCommandParams p("ref");
1979 owner_->getDialogs()->createRef(p.getAsString());
1981 InsetCommandParams p;
1982 p.setFromString(argument);
1984 InsetRef * inset = new InsetRef(p, *buffer_);
1985 if (!insertInset(inset))
1988 updateInset(inset, true);
1992 case LFUN_BOOKMARK_SAVE:
1993 savePosition(strToUnsignedInt(argument));
1996 case LFUN_BOOKMARK_GOTO:
1997 restorePosition(strToUnsignedInt(argument));
2002 string label(argument);
2003 if (label.empty()) {
2005 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
2007 label = inset->getContents();
2012 if (!label.empty()) {
2013 //bv_->savePosition(0);
2014 if (!bv_->gotoLabel(label))
2015 Alert::alert(_("Error"),
2016 _("Couldn't find this label"),
2017 _("in current document."));
2022 // --- Cursor Movements -----------------------------
2025 LyXText * lt = bv_->getLyXText();
2027 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2028 if (!lt->selection.mark())
2030 update(lt, BufferView::SELECT|BufferView::FITCUR);
2032 lt->cursorLeft(bv_, false);
2033 if (lt->cursor.pos() < lt->cursor.par()->size()
2034 && lt->cursor.par()->isInset(lt->cursor.pos())
2035 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2036 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2037 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2039 tmpinset->edit(bv_, false);
2041 tmpinset->edit(bv_);
2045 lt->cursorRight(bv_, false);
2047 moveCursorUpdate(false);
2048 owner_->showState();
2054 // This is soooo ugly. Isn`t it possible to make
2055 // it simpler? (Lgb)
2056 LyXText * lt = bv_->getLyXText();
2057 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2058 if (!lt->selection.mark())
2060 update(lt, BufferView::SELECT|BufferView::FITCUR);
2061 LyXCursor const cur = lt->cursor;
2063 lt->cursorLeft(bv_, false);
2064 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2065 lt->cursor.pos() < lt->cursor.par()->size() &&
2066 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2067 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2068 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2069 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2071 tmpinset->edit(bv_);
2073 tmpinset->edit(bv_, false);
2077 lt->cursorRight(bv_, false);
2080 moveCursorUpdate(false);
2081 owner_->showState();
2087 LyXText * lt = bv_->getLyXText();
2089 if (!lt->selection.mark())
2091 update(lt, BufferView::UPDATE);
2094 moveCursorUpdate(false);
2095 owner_->showState();
2101 LyXText * lt = bv_->getLyXText();
2103 if (!lt->selection.mark())
2105 update(lt, BufferView::UPDATE);
2106 lt->cursorDown(bv_);
2108 moveCursorUpdate(false);
2109 owner_->showState();
2113 case LFUN_UP_PARAGRAPH:
2115 LyXText * lt = bv_->getLyXText();
2117 if (!lt->selection.mark())
2119 update(lt, BufferView::UPDATE);
2120 lt->cursorUpParagraph(bv_);
2122 moveCursorUpdate(false);
2123 owner_->showState();
2127 case LFUN_DOWN_PARAGRAPH:
2129 LyXText * lt = bv_->getLyXText();
2131 if (!lt->selection.mark())
2133 update(lt, BufferView::UPDATE);
2134 lt->cursorDownParagraph(bv_);
2136 moveCursorUpdate(false);
2137 owner_->showState();
2143 LyXText * lt = bv_->getLyXText();
2145 if (!lt->selection.mark())
2147 update(lt, BufferView::UPDATE);
2150 moveCursorUpdate(false, false);
2151 owner_->showState();
2157 LyXText * lt = bv_->getLyXText();
2159 if (!lt->selection.mark())
2161 update(lt, BufferView::UPDATE);
2164 moveCursorUpdate(false, false);
2165 owner_->showState();
2171 LyXText * lt = bv_->getLyXText();
2173 if (!lt->selection.mark())
2175 update(lt, BufferView::SELECT|BufferView::FITCUR);
2176 lt->cursorHome(bv_);
2178 moveCursorUpdate(false);
2179 owner_->showState();
2185 LyXText * lt = bv_->getLyXText();
2187 if (!lt->selection.mark())
2190 BufferView::SELECT|BufferView::FITCUR);
2193 moveCursorUpdate(false);
2194 owner_->showState();
2198 case LFUN_SHIFT_TAB:
2201 LyXText * lt = bv_->getLyXText();
2203 if (!lt->selection.mark())
2206 BufferView::SELECT|BufferView::FITCUR);
2209 moveCursorUpdate(false);
2210 owner_->showState();
2214 case LFUN_WORDRIGHT:
2216 LyXText * lt = bv_->getLyXText();
2218 if (!lt->selection.mark())
2220 update(lt, BufferView::SELECT|BufferView::FITCUR);
2221 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2222 lt->cursorLeftOneWord(bv_);
2224 lt->cursorRightOneWord(bv_);
2226 moveCursorUpdate(false);
2227 owner_->showState();
2233 LyXText * lt = bv_->getLyXText();
2235 if (!lt->selection.mark())
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2239 lt->cursorRightOneWord(bv_);
2241 lt->cursorLeftOneWord(bv_);
2243 moveCursorUpdate(false);
2244 owner_->showState();
2248 case LFUN_BEGINNINGBUF:
2250 LyXText * lt = bv_->getLyXText();
2252 if (!lt->selection.mark())
2255 BufferView::SELECT|BufferView::FITCUR);
2258 moveCursorUpdate(false);
2259 owner_->showState();
2265 LyXText * lt = bv_->getLyXText();
2267 if (!lt->selection.mark())
2270 BufferView::SELECT|BufferView::FITCUR);
2271 lt->cursorBottom(bv_);
2273 moveCursorUpdate(false);
2274 owner_->showState();
2278 /* cursor selection ---------------------------- */
2281 LyXText * lt = bv_->getLyXText();
2284 BufferView::SELECT|BufferView::FITCUR);
2285 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2286 lt->cursorLeft(bv_);
2288 lt->cursorRight(bv_);
2290 moveCursorUpdate(true);
2291 owner_->showState();
2297 LyXText * lt = bv_->getLyXText();
2300 BufferView::SELECT|BufferView::FITCUR);
2301 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2302 lt->cursorRight(bv_);
2304 lt->cursorLeft(bv_);
2306 moveCursorUpdate(true);
2307 owner_->showState();
2313 LyXText * lt = bv_->getLyXText();
2316 BufferView::SELECT|BufferView::FITCUR);
2317 lt->cursorUp(bv_, true);
2319 moveCursorUpdate(true);
2320 owner_->showState();
2326 LyXText * lt = bv_->getLyXText();
2329 BufferView::SELECT|BufferView::FITCUR);
2330 lt->cursorDown(bv_, true);
2332 moveCursorUpdate(true);
2333 owner_->showState();
2337 case LFUN_UP_PARAGRAPHSEL:
2339 LyXText * lt = bv_->getLyXText();
2342 BufferView::SELECT|BufferView::FITCUR);
2343 lt->cursorUpParagraph(bv_);
2345 moveCursorUpdate(true);
2346 owner_->showState();
2350 case LFUN_DOWN_PARAGRAPHSEL:
2352 LyXText * lt = bv_->getLyXText();
2355 BufferView::SELECT|BufferView::FITCUR);
2356 lt->cursorDownParagraph(bv_);
2358 moveCursorUpdate(true);
2359 owner_->showState();
2365 LyXText * lt = bv_->getLyXText();
2367 update(lt, BufferView::SELECT|BufferView::FITCUR);
2370 moveCursorUpdate(true);
2371 owner_->showState();
2377 LyXText * lt = bv_->getLyXText();
2379 update(lt, BufferView::SELECT|BufferView::FITCUR);
2382 moveCursorUpdate(true);
2383 owner_->showState();
2389 LyXText * lt = bv_->getLyXText();
2391 update(lt, BufferView::SELECT|BufferView::FITCUR);
2392 lt->cursorHome(bv_);
2394 moveCursorUpdate(true);
2395 owner_->showState();
2401 LyXText * lt = bv_->getLyXText();
2403 update(lt, BufferView::SELECT|BufferView::FITCUR);
2406 moveCursorUpdate(true);
2407 owner_->showState();
2411 case LFUN_WORDRIGHTSEL:
2413 LyXText * lt = bv_->getLyXText();
2415 update(lt, BufferView::SELECT|BufferView::FITCUR);
2416 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2417 lt->cursorLeftOneWord(bv_);
2419 lt->cursorRightOneWord(bv_);
2421 moveCursorUpdate(true);
2422 owner_->showState();
2426 case LFUN_WORDLEFTSEL:
2428 LyXText * lt = bv_->getLyXText();
2430 update(lt, BufferView::SELECT|BufferView::FITCUR);
2431 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2432 lt->cursorRightOneWord(bv_);
2434 lt->cursorLeftOneWord(bv_);
2436 moveCursorUpdate(true);
2437 owner_->showState();
2441 case LFUN_BEGINNINGBUFSEL:
2443 LyXText * lt = bv_->getLyXText();
2445 if (lt->inset_owner)
2447 update(lt, BufferView::SELECT|BufferView::FITCUR);
2450 moveCursorUpdate(true);
2451 owner_->showState();
2455 case LFUN_ENDBUFSEL:
2457 LyXText * lt = bv_->getLyXText();
2459 if (lt->inset_owner)
2462 BufferView::SELECT|BufferView::FITCUR);
2463 lt->cursorBottom(bv_);
2465 moveCursorUpdate(true);
2466 owner_->showState();
2470 // --- text changing commands ------------------------
2471 case LFUN_BREAKLINE:
2473 LyXText * lt = bv_->getLyXText();
2476 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2479 | BufferView::FITCUR
2480 | BufferView::CHANGE);
2481 moveCursorUpdate(false);
2485 case LFUN_PROTECTEDSPACE:
2487 LyXText * lt = bv_->getLyXText();
2489 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2491 if (style.free_spacing) {
2492 lt->insertChar(bv_, ' ');
2495 | BufferView::FITCUR
2496 | BufferView::CHANGE);
2498 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2500 moveCursorUpdate(false);
2506 LyXText * lt = bv_->getLyXText();
2508 if (lt->selection.mark()) {
2512 | BufferView::FITCUR);
2513 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2516 lt->selection.mark(true);
2519 | BufferView::FITCUR);
2520 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2522 lt->selection.cursor = lt->cursor;
2528 LyXText * lt = bv_->getLyXText();
2530 if (!lt->selection.set()) {
2532 lt->selection.cursor = lt->cursor;
2535 | BufferView::FITCUR
2536 | BufferView::CHANGE);
2537 // It is possible to make it a lot faster still
2538 // just comment out the line below...
2543 moveCursorUpdate(false);
2544 owner_->showState();
2549 case LFUN_DELETE_SKIP:
2551 LyXText * lt = bv_->getLyXText();
2553 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2555 LyXCursor cursor = lt->cursor;
2557 if (!lt->selection.set()) {
2558 if (cursor.pos() == cursor.par()->size()) {
2559 lt->cursorRight(bv_);
2560 cursor = lt->cursor;
2561 if (cursor.pos() == 0
2562 && !(cursor.par()->params().spaceTop()
2563 == VSpace (VSpace::NONE))) {
2566 cursor.par()->params().lineTop(),
2567 cursor.par()->params().lineBottom(),
2568 cursor.par()->params().pagebreakTop(),
2569 cursor.par()->params().pagebreakBottom(),
2570 VSpace(VSpace::NONE),
2571 cursor.par()->params().spaceBottom(),
2572 cursor.par()->params().spacing(),
2573 cursor.par()->params().align(),
2574 cursor.par()->params().labelWidthString(), 0);
2575 lt->cursorLeft(bv_);
2578 | BufferView::FITCUR
2579 | BufferView::CHANGE);
2581 lt->cursorLeft(bv_);
2583 lt->selection.cursor = lt->cursor;
2586 | BufferView::FITCUR
2587 | BufferView::CHANGE);
2591 lt->selection.cursor = lt->cursor;
2594 | BufferView::FITCUR
2595 | BufferView::CHANGE);
2603 /* -------> Delete word forward. */
2604 case LFUN_DELETE_WORD_FORWARD:
2605 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2606 bv_->getLyXText()->deleteWordForward(bv_);
2607 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2608 moveCursorUpdate(false);
2609 owner_->showState();
2612 /* -------> Delete word backward. */
2613 case LFUN_DELETE_WORD_BACKWARD:
2615 LyXText * lt = bv_->getLyXText();
2617 update(lt, BufferView::SELECT|BufferView::FITCUR);
2618 lt->deleteWordBackward(bv_);
2621 | BufferView::FITCUR
2622 | BufferView::CHANGE);
2623 moveCursorUpdate(false);
2624 owner_->showState();
2628 /* -------> Kill to end of line. */
2629 case LFUN_DELETE_LINE_FORWARD:
2631 LyXText * lt = bv_->getLyXText();
2633 update(lt, BufferView::SELECT|BufferView::FITCUR);
2634 lt->deleteLineForward(bv_);
2637 | BufferView::FITCUR
2638 | BufferView::CHANGE);
2639 moveCursorUpdate(false);
2643 /* -------> Set mark off. */
2646 LyXText * lt = bv_->getLyXText();
2649 update(lt, BufferView::SELECT|BufferView::FITCUR);
2650 lt->selection.cursor = lt->cursor;
2651 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2655 /* -------> Set mark on. */
2658 LyXText * lt = bv_->getLyXText();
2661 lt->selection.mark(true);
2662 update(lt, BufferView::SELECT|BufferView::FITCUR);
2663 lt->selection.cursor = lt->cursor;
2664 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2668 case LFUN_BACKSPACE:
2670 LyXText * lt = bv_->getLyXText();
2672 if (!lt->selection.set()) {
2673 if (owner_->getIntl()->getTrans().backspace()) {
2675 lt->selection.cursor = lt->cursor;
2678 | BufferView::FITCUR
2679 | BufferView::CHANGE);
2680 // It is possible to make it a lot faster still
2681 // just comment out the line below...
2687 owner_->showState();
2692 case LFUN_BACKSPACE_SKIP:
2694 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2695 LyXText * lt = bv_->getLyXText();
2697 LyXCursor cursor = lt->cursor;
2699 if (!lt->selection.set()) {
2700 if (cursor.pos() == 0
2701 && !(cursor.par()->params().spaceTop()
2702 == VSpace (VSpace::NONE))) {
2705 cursor.par()->params().lineTop(),
2706 cursor.par()->params().lineBottom(),
2707 cursor.par()->params().pagebreakTop(),
2708 cursor.par()->params().pagebreakBottom(),
2709 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2710 cursor.par()->params().spacing(),
2711 cursor.par()->params().align(),
2712 cursor.par()->params().labelWidthString(), 0);
2715 | BufferView::FITCUR
2716 | BufferView::CHANGE);
2719 lt->selection.cursor = cursor;
2722 | BufferView::FITCUR
2723 | BufferView::CHANGE);
2730 case LFUN_BREAKPARAGRAPH:
2732 LyXText * lt = bv_->getLyXText();
2735 lt->breakParagraph(bv_, 0);
2738 | BufferView::FITCUR
2739 | BufferView::CHANGE);
2740 lt->selection.cursor = lt->cursor;
2742 owner_->showState();
2746 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2748 LyXText * lt = bv_->getLyXText();
2751 lt->breakParagraph(bv_, 1);
2754 | BufferView::FITCUR
2755 | BufferView::CHANGE);
2756 lt->selection.cursor = lt->cursor;
2758 owner_->showState();
2762 case LFUN_BREAKPARAGRAPH_SKIP:
2764 // When at the beginning of a paragraph, remove
2765 // indentation and add a "defskip" at the top.
2766 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2767 LyXText * lt = bv_->getLyXText();
2769 LyXCursor cursor = lt->cursor;
2772 if (cursor.pos() == 0) {
2773 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2776 cursor.par()->params().lineTop(),
2777 cursor.par()->params().lineBottom(),
2778 cursor.par()->params().pagebreakTop(),
2779 cursor.par()->params().pagebreakBottom(),
2780 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2781 cursor.par()->params().spacing(),
2782 cursor.par()->params().align(),
2783 cursor.par()->params().labelWidthString(), 1);
2784 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2788 lt->breakParagraph(bv_, 0);
2789 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2794 | BufferView::FITCUR
2795 | BufferView::CHANGE);
2796 lt->selection.cursor = cursor;
2798 owner_->showState();
2802 case LFUN_PARAGRAPH_SPACING:
2804 LyXText * lt = bv_->getLyXText();
2806 Paragraph * par = lt->cursor.par();
2807 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2808 float cur_value = 1.0;
2809 if (cur_spacing == Spacing::Other) {
2810 cur_value = par->params().spacing().getValue();
2813 istringstream istr(argument.c_str());
2817 Spacing::Space new_spacing = cur_spacing;
2818 float new_value = cur_value;
2820 lyxerr << "Missing argument to `paragraph-spacing'"
2822 } else if (tmp == "single") {
2823 new_spacing = Spacing::Single;
2824 } else if (tmp == "onehalf") {
2825 new_spacing = Spacing::Onehalf;
2826 } else if (tmp == "double") {
2827 new_spacing = Spacing::Double;
2828 } else if (tmp == "other") {
2829 new_spacing = Spacing::Other;
2832 lyxerr << "new_value = " << tmpval << endl;
2835 } else if (tmp == "default") {
2836 new_spacing = Spacing::Default;
2838 lyxerr << _("Unknown spacing argument: ")
2839 << argument << endl;
2841 if (cur_spacing != new_spacing || cur_value != new_value) {
2842 par->params().spacing(Spacing(new_spacing, new_value));
2843 lt->redoParagraph(bv_);
2846 | BufferView::FITCUR
2847 | BufferView::CHANGE);
2852 case LFUN_INSET_TOGGLE:
2854 LyXText * lt = bv_->getLyXText();
2857 update(lt, BufferView::SELECT|BufferView::FITCUR);
2858 lt->toggleInset(bv_);
2859 update(lt, BufferView::SELECT|BufferView::FITCUR);
2871 InsetCommandParams p;
2872 if (action == LFUN_HTMLURL)
2873 p.setCmdName("htmlurl");
2875 p.setCmdName("url");
2876 owner_->getDialogs()->createUrl(p.getAsString());
2880 case LFUN_INSERT_URL:
2882 InsetCommandParams p;
2883 p.setFromString(argument);
2885 InsetUrl * inset = new InsetUrl(p);
2886 if (!insertInset(inset))
2889 updateInset(inset, true);
2893 case LFUN_INSET_ERT:
2894 insertAndEditInset(new InsetERT(buffer_->params));
2897 case LFUN_INSET_EXTERNAL:
2898 insertAndEditInset(new InsetExternal);
2901 case LFUN_INSET_FOOTNOTE:
2902 insertAndEditInset(new InsetFoot(buffer_->params));
2905 case LFUN_INSET_MARGINAL:
2906 insertAndEditInset(new InsetMarginal(buffer_->params));
2909 case LFUN_INSET_MINIPAGE:
2910 insertAndEditInset(new InsetMinipage(buffer_->params));
2913 case LFUN_INSERT_NOTE:
2914 insertAndEditInset(new InsetNote(buffer_->params));
2917 case LFUN_INSET_FLOAT:
2918 // check if the float type exist
2919 if (floatList.typeExist(argument)) {
2920 insertAndEditInset(new InsetFloat(buffer_->params,
2923 lyxerr << "Non-existent float type: "
2924 << argument << endl;
2928 case LFUN_INSET_WIDE_FLOAT:
2929 // check if the float type exist
2930 if (floatList.typeExist(argument)) {
2931 InsetFloat * new_inset =
2932 new InsetFloat(buffer_->params, argument);
2933 new_inset->wide(true);
2934 insertAndEditInset(new_inset);
2936 lyxerr << "Non-existent float type: "
2937 << argument << endl;
2942 case LFUN_INSET_LIST:
2943 insertAndEditInset(new InsetList);
2946 case LFUN_INSET_THEOREM:
2947 insertAndEditInset(new InsetTheorem);
2951 case LFUN_INSET_CAPTION:
2953 // Do we have a locking inset...
2954 if (bv_->theLockingInset()) {
2955 lyxerr << "Locking inset code: "
2956 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2957 InsetCaption * new_inset =
2958 new InsetCaption(buffer_->params);
2959 new_inset->setOwner(bv_->theLockingInset());
2960 new_inset->setAutoBreakRows(true);
2961 new_inset->setDrawFrame(0, InsetText::LOCKED);
2962 new_inset->setFrameColor(0, LColor::captionframe);
2963 if (insertInset(new_inset))
2964 new_inset->edit(bv_);
2971 case LFUN_INSET_TABULAR:
2975 if (!argument.empty())
2976 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2977 InsetTabular * new_inset =
2978 new InsetTabular(*buffer_, r, c);
2980 bv_->getLyXText()->real_current_font.isRightToLeft();
2981 if (!open_new_inset(new_inset, rtl))
2986 // --- lyxserver commands ----------------------------
2988 case LFUN_CHARATCURSOR:
2990 pos_type pos = bv_->getLyXText()->cursor.pos();
2991 if (pos < bv_->getLyXText()->cursor.par()->size())
2992 owner_->getLyXFunc()->setMessage(
2993 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2995 owner_->getLyXFunc()->setMessage("EOF");
3000 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
3002 + tostr(bv_->getLyXText()->cursor.y()));
3009 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
3010 lyxerr << "SETXY: Could not parse coordinates in '"
3011 << argument << std::endl;
3013 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
3017 case LFUN_GETLAYOUT:
3018 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3023 LyXFont & font = bv_->getLyXText()->current_font;
3024 if (font.shape() == LyXFont::ITALIC_SHAPE)
3025 owner_->getLyXFunc()->setMessage("E");
3026 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3027 owner_->getLyXFunc()->setMessage("N");
3029 owner_->getLyXFunc()->setMessage("0");
3034 // --- accented characters ---------------------------
3037 case LFUN_CIRCUMFLEX:
3047 case LFUN_SPECIAL_CARON:
3050 case LFUN_HUNG_UMLAUT:
3053 if (argument.empty()) {
3055 owner_->getLyXFunc()->handleKeyFunc(action);
3057 owner_->getLyXFunc()->handleKeyFunc(action);
3058 owner_->getIntl()->getTrans()
3059 .TranslateAndInsert(argument[0], bv_->getLyXText());
3060 update(bv_->getLyXText(),
3062 | BufferView::FITCUR
3063 | BufferView::CHANGE);
3067 case LFUN_MATH_MACRO:
3068 mathDispatchMathMacro(bv_, argument);
3071 case LFUN_MATH_DELIM:
3072 mathDispatchMathDelim(bv_, argument);
3075 case LFUN_INSERT_MATRIX:
3076 mathDispatchInsertMatrix(bv_, argument);
3079 case LFUN_INSERT_MATH:
3080 mathDispatchInsertMath(bv_, argument);
3083 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3084 mathDispatchMathImportSelection(bv_, argument);
3087 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3088 mathDispatchMathDisplay(bv_, argument);
3091 case LFUN_MATH_MODE: // Open or create an inlined math inset
3092 mathDispatchMathMode(bv_, argument);
3095 case LFUN_GREEK: // Insert a single greek letter
3096 mathDispatchGreek(bv_, argument);
3099 case LFUN_CITATION_INSERT:
3101 InsetCommandParams p;
3102 p.setFromString(argument);
3104 InsetCitation * inset = new InsetCitation(p);
3105 if (!insertInset(inset))
3108 updateInset(inset, true);
3112 case LFUN_INSERT_BIBTEX:
3114 // ale970405+lasgoutt970425
3115 // The argument can be up to two tokens separated
3116 // by a space. The first one is the bibstyle.
3117 string const db = token(argument, ' ', 0);
3118 string const bibstyle = token(argument, ' ', 1);
3120 InsetCommandParams p("BibTeX", db, bibstyle);
3121 InsetBibtex * inset = new InsetBibtex(p);
3123 if (insertInset(inset)) {
3124 if (argument.empty())
3131 // BibTeX data bases
3132 case LFUN_BIBDB_ADD:
3134 InsetBibtex * inset =
3135 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3137 inset->addDatabase(argument);
3142 case LFUN_BIBDB_DEL:
3144 InsetBibtex * inset =
3145 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3147 inset->delDatabase(argument);
3152 case LFUN_BIBTEX_STYLE:
3154 InsetBibtex * inset =
3155 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3157 inset->setOptions(argument);
3162 case LFUN_INDEX_CREATE:
3164 InsetCommandParams p("index");
3165 if (argument.empty()) {
3166 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3167 p.setContents(idxstring);
3169 p.setContents(argument);
3172 owner_->getDialogs()->createIndex(p.getAsString());
3176 case LFUN_INDEX_INSERT:
3178 InsetCommandParams p;
3179 p.setFromString(argument);
3180 InsetIndex * inset = new InsetIndex(p);
3182 if (!insertInset(inset))
3185 updateInset(inset, true);
3189 case LFUN_INDEX_INSERT_LAST:
3191 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3192 if (!idxstring.empty()) {
3193 owner_->message(_("Word `")
3194 + idxstring + _(("' indexed.")));
3195 InsetCommandParams p("index", idxstring);
3196 InsetIndex * inset = new InsetIndex(p);
3198 if (!insertInset(inset))
3201 updateInset(inset, true);
3206 case LFUN_INDEX_PRINT:
3208 InsetCommandParams p("printindex");
3209 Inset * inset = new InsetPrintIndex(p);
3210 if (!insertInset(inset, tclass.defaultLayoutName()))
3215 case LFUN_PARENTINSERT:
3217 InsetCommandParams p("lyxparent", argument);
3218 Inset * inset = new InsetParent(p, *buffer_);
3219 if (!insertInset(inset, tclass.defaultLayoutName()))
3225 case LFUN_CHILD_INSERT:
3227 InsetInclude::Params p;
3228 p.cparams.setFromString(argument);
3229 p.masterFilename_ = buffer_->fileName();
3231 InsetInclude * inset = new InsetInclude(p);
3232 if (!insertInset(inset))
3235 updateInset(inset, true);
3236 bv_->owner()->getDialogs()->showInclude(inset);
3241 case LFUN_FLOAT_LIST:
3242 if (floatList.typeExist(argument)) {
3243 Inset * inset = new InsetFloatList(argument);
3244 if (!insertInset(inset, tclass.defaultLayoutName()))
3247 lyxerr << "Non-existent float type: "
3248 << argument << endl;
3252 case LFUN_THESAURUS_ENTRY:
3254 string arg = argument;
3257 arg = bv_->getLyXText()->selectionAsString(buffer_,
3261 if (arg.size() > 100 || arg.empty()) {
3262 // Get word or selection
3263 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3264 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3265 // FIXME: where is getLyXText()->unselect(bv_) ?
3269 bv_->owner()->getDialogs()->showThesaurus(arg);
3273 case LFUN_SELFINSERT:
3275 if (argument.empty()) break;
3277 /* Automatically delete the currently selected
3278 * text and replace it with what is being
3279 * typed in now. Depends on lyxrc settings
3280 * "auto_region_delete", which defaults to
3283 LyXText * lt = bv_->getLyXText();
3285 if (lyxrc.auto_region_delete) {
3286 if (lt->selection.set()) {
3287 lt->cutSelection(bv_, false, false);
3290 | BufferView::FITCUR
3291 | BufferView::CHANGE);
3293 workarea_.haveSelection(false);
3297 LyXFont const old_font(lt->real_current_font);
3299 string::const_iterator cit = argument.begin();
3300 string::const_iterator end = argument.end();
3301 for (; cit != end; ++cit) {
3302 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3307 | BufferView::FITCUR
3308 | BufferView::CHANGE);
3310 lt->selection.cursor = lt->cursor;
3311 moveCursorUpdate(false);
3313 // real_current_font.number can change so we need to
3314 // update the minibuffer
3315 if (old_font != lt->real_current_font)
3316 owner_->showState();
3321 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3323 time_t now_time_t = time(NULL);
3324 struct tm * now_tm = localtime(&now_time_t);
3325 setlocale(LC_TIME, "");
3327 if (!argument.empty())
3330 arg = lyxrc.date_insert_format;
3332 int const datetmp_len =
3333 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3335 LyXText * lt = bv_->getLyXText();
3337 for (int i = 0; i < datetmp_len; i++) {
3338 lt->insertChar(bv_, datetmp[i]);
3341 | BufferView::FITCUR
3342 | BufferView::CHANGE);
3345 lt->selection.cursor = lt->cursor;
3346 moveCursorUpdate(false);
3350 case LFUN_UNKNOWN_ACTION:
3351 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3362 void BufferView::Pimpl::newline()
3365 LyXText * lt = bv_->getLyXText();
3369 | BufferView::FITCUR);
3370 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3373 | BufferView::FITCUR
3374 | BufferView::CHANGE);
3379 void BufferView::Pimpl::hfill()
3382 LyXText * lt = bv_->getLyXText();
3386 | BufferView::FITCUR);
3387 lt->insertChar(bv_, Paragraph::META_HFILL);
3390 | BufferView::FITCUR
3391 | BufferView::CHANGE);
3396 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3399 LyXText * lt = bv_->getLyXText();
3402 update(lt, BufferView::SELECT|BufferView::FITCUR);
3403 InsetSpecialChar * new_inset =
3404 new InsetSpecialChar(kind);
3405 if (!insertInset(new_inset))
3408 updateInset(new_inset, true);
3413 void BufferView::Pimpl::smartQuote()
3415 LyXText const * lt = bv_->getLyXText();
3416 Paragraph const * par = lt->cursor.par();
3417 pos_type pos = lt->cursor.pos();
3421 || (par->isInset(pos - 1)
3422 && par->getInset(pos - 1)->isSpace()))
3425 c = par->getChar(pos - 1);
3430 LyXLayout const & style =
3431 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3433 if (style.pass_thru ||
3434 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3435 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3439 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3441 if (insertInset(inset))
3448 // Open and lock an updatable inset
3449 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3451 LyXText * lt = bv_->getLyXText();
3455 if (!insertInset(new_inset)) {
3459 new_inset->edit(bv_, !behind);
3464 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3466 // if we are in a locking inset we should try to insert the
3467 // inset there otherwise this is a illegal function now
3468 if (bv_->theLockingInset()) {
3469 if (bv_->theLockingInset()->insetAllowed(inset))
3470 return bv_->theLockingInset()->insertInset(bv_, inset);
3474 // not quite sure if we want this...
3475 setCursorParUndo(bv_);
3478 beforeChange(bv_->text);
3479 if (!lout.empty()) {
3480 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3481 bv_->text->breakParagraph(bv_);
3482 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3484 if (bv_->text->cursor.par()->size()) {
3485 bv_->text->cursorLeft(bv_);
3487 bv_->text->breakParagraph(bv_);
3488 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3492 LyXTextClass const & tclass =
3493 textclasslist[buffer_->params.textclass];
3494 bool hasLayout = tclass.hasLayout(lres);
3495 string lay = tclass.defaultLayoutName();
3497 if (hasLayout != false) {
3501 // layout not fount using default
3502 lay = tclass.defaultLayoutName();
3505 bv_->text->setLayout(bv_, lay);
3507 bv_->text->setParagraph(bv_, 0, 0,
3509 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3514 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3517 bv_->text->insertInset(bv_, inset);
3518 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3525 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3527 if (!inset || !available())
3530 // first check for locking insets
3531 if (bv_->theLockingInset()) {
3532 if (bv_->theLockingInset() == inset) {
3533 if (bv_->text->updateInset(bv_, inset)) {
3536 buffer_->markDirty();
3541 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3542 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3545 buffer_->markDirty();
3553 // then check if the inset is a top_level inset (has no owner)
3554 // if yes do the update as always otherwise we have to update the
3555 // toplevel inset where this inset is inside
3556 Inset * tl_inset = inset;
3557 while(tl_inset->owner())
3558 tl_inset = tl_inset->owner();
3560 if (tl_inset == inset) {
3561 update(bv_->text, BufferView::UPDATE);
3562 if (bv_->text->updateInset(bv_, inset)) {
3566 | BufferView::FITCUR
3567 | BufferView::CHANGE);
3569 update(bv_->text, SELECT);
3573 } else if (static_cast<UpdatableInset *>(tl_inset)
3574 ->updateInsetInInset(bv_, inset))
3576 if (bv_->text->updateInset(bv_, tl_inset)) {
3584 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3587 if (!available()) return;
3590 beforeChange(bv_->text);
3591 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3593 LyXCursor const & cursor = bv_->text->cursor;
3597 cursor.par()->isInset(cursor.pos())) {
3598 Inset const * inset = cursor.par()->getInset(cursor.pos());
3599 if (find(codes.begin(), codes.end(), inset->lyxCode())
3602 static_cast<InsetCommand const *>(inset)->getContents();
3606 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3607 if (bv_->text->cursor.pos()
3608 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3609 LyXCursor tmp = bv_->text->cursor;
3610 bv_->text->cursor.par(bv_->text->ownerParagraph());
3611 bv_->text->cursor.pos(0);
3612 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3613 bv_->text->cursor = tmp;
3614 bv_->owner()->message(_("No more insets"));
3617 bv_->owner()->message(_("No more insets"));
3620 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3621 bv_->text->selection.cursor = bv_->text->cursor;
3625 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3627 gotoInset(vector<Inset::Code>(1, code), same_content);