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 ("
180 buffer_->delUser(bv_);
182 // Put the old text into the TextCache, but
183 // only if the buffer is still loaded.
184 // Also set the owner of the test to 0
185 // bv_->text->owner(0);
186 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
187 if (lyxerr.debugging())
188 textcache.show(lyxerr, "BufferView::buffer");
193 // Set current buffer
196 if (bufferlist.getState() == BufferList::CLOSING) return;
199 // screen is always deleted when the buffer is changed.
202 // If we are closing the buffer, use the first buffer as current
204 buffer_ = bufferlist.first();
208 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
209 buffer_->addUser(bv_);
210 // If we don't have a text object for this, we make one
211 if (bv_->text == 0) {
212 resizeCurrentBuffer();
217 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
218 owner_->updateMenubar();
219 owner_->updateToolbar();
220 // Similarly, buffer-dependent dialogs should be updated or
221 // hidden. This should go here because some dialogs (eg ToC)
222 // require bv_->text.
223 owner_->getDialogs()->updateBufferDependent(true);
227 lyxerr[Debug::INFO] << " No Buffer!" << endl;
228 owner_->updateMenubar();
229 owner_->updateToolbar();
230 owner_->getDialogs()->hideBufferDependent();
234 // Also remove all remaining text's from the testcache.
235 // (there should not be any!) (if there is any it is a
237 if (lyxerr.debugging())
238 textcache.show(lyxerr, "buffer delete all");
241 // should update layoutchoice even if we don't have a buffer.
242 owner_->updateLayoutChoice();
244 owner_->updateWindowTitle();
248 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
250 workarea_.resize(xpos, ypos, width, height);
251 update(bv_->text, SELECT);
256 void BufferView::Pimpl::resize()
259 resizeCurrentBuffer();
263 void BufferView::Pimpl::redraw()
265 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
270 bool BufferView::Pimpl::fitCursor()
272 lyx::Assert(screen_.get());
276 if (bv_->theLockingInset()) {
277 bv_->theLockingInset()->fitInsetCursor(bv_);
280 ret = screen_->fitCursor(bv_->text, bv_);
283 bv_->owner()->getDialogs()->updateParagraph();
290 void BufferView::Pimpl::redoCurrentBuffer()
292 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
293 if (buffer_ && bv_->text) {
295 owner_->updateLayoutChoice();
300 int BufferView::Pimpl::resizeCurrentBuffer()
302 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
305 Paragraph * selstartpar = 0;
306 Paragraph * selendpar = 0;
307 UpdatableInset * the_locking_inset = 0;
310 pos_type selstartpos = 0;
311 pos_type selendpos = 0;
312 bool selection = false;
313 bool mark_set = false;
315 owner_->prohibitInput();
317 owner_->message(_("Formatting document..."));
320 par = bv_->text->cursor.par();
321 pos = bv_->text->cursor.pos();
322 selstartpar = bv_->text->selection.start.par();
323 selstartpos = bv_->text->selection.start.pos();
324 selendpar = bv_->text->selection.end.par();
325 selendpos = bv_->text->selection.end.pos();
326 selection = bv_->text->selection.set();
327 mark_set = bv_->text->selection.mark();
328 the_locking_inset = bv_->theLockingInset();
330 bv_->text = new LyXText(bv_);
331 bv_->text->init(bv_);
332 buffer_->resizeInsets(bv_);
334 // See if we have a text in TextCache that fits
335 // the new buffer_ with the correct width.
336 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
338 if (lyxerr.debugging()) {
339 lyxerr << "Found a LyXText that fits:\n";
340 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
342 // Set the owner of the newly found text
343 // bv_->text->owner(bv_);
344 if (lyxerr.debugging())
345 textcache.show(lyxerr, "resizeCurrentBuffer");
347 bv_->text = new LyXText(bv_);
348 bv_->text->init(bv_);
349 //buffer_->resizeInsets(bv_);
356 bv_->text->selection.set(true);
357 // At this point just to avoid the Delete-Empty-Paragraph-
358 // Mechanism when setting the cursor.
359 bv_->text->selection.mark(mark_set);
361 bv_->text->setCursor(bv_, selstartpar, selstartpos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->setCursor(bv_, selendpar, selendpos);
364 bv_->text->setSelection(bv_);
365 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->setCursor(bv_, par, pos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->selection.set(false);
371 // remake the inset locking
372 bv_->theLockingInset(the_locking_inset);
375 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
377 // this will scroll the screen such that the cursor becomes visible
382 owner_->allowInput();
384 /// clear the "Formatting Document" message
391 void BufferView::Pimpl::updateScreen()
393 // Regenerate the screen.
394 screen_.reset(new LyXScreen(workarea_));
398 void BufferView::Pimpl::updateScrollbar()
401 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
402 workarea_.setScrollbar(0, 1.0);
406 long const text_height = bv_->text->height;
407 long const work_height = workarea_.height();
409 double const lineh = bv_->text->defaultHeight();
410 double const slider_size =
411 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
413 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
414 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
416 /* If the text is smaller than the working area, the scrollbar
417 * maximum must be the working area height. No scrolling will
419 if (text_height <= work_height) {
420 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
421 workarea_.setScrollbarBounds(0.0, 0.0);
422 current_scrollbar_value = bv_->text->first_y;
423 workarea_.setScrollbar(current_scrollbar_value, 1.0);
427 workarea_.setScrollbarBounds(0.0, text_height - work_height);
428 workarea_.setScrollbarIncrements(lineh);
429 current_scrollbar_value = bv_->text->first_y;
430 workarea_.setScrollbar(current_scrollbar_value, slider_size);
434 // Callback for scrollbar slider
435 void BufferView::Pimpl::scrollCB(double value)
437 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
439 if (!buffer_) return;
441 current_scrollbar_value = long(value);
443 if (current_scrollbar_value < 0)
444 current_scrollbar_value = 0;
449 screen_->draw(bv_->text, bv_, current_scrollbar_value);
451 if (!lyxrc.cursor_follows_scrollbar) {
456 LyXText * vbt = bv_->text;
458 int const height = vbt->defaultHeight();
459 int const first = static_cast<int>((bv_->text->first_y + height));
460 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
462 if (vbt->cursor.y() < first)
463 vbt->setCursorFromCoordinates(bv_, 0, first);
464 else if (vbt->cursor.y() > last)
465 vbt->setCursorFromCoordinates(bv_, 0, last);
471 int BufferView::Pimpl::scrollUp(long time)
473 if (!buffer_) return 0;
474 if (!screen_.get()) return 0;
476 double value = workarea_.getScrollbarValue();
478 if (value == 0) return 0;
480 float add_value = (bv_->text->defaultHeight()
481 + float(time) * float(time) * 0.125);
483 if (add_value > workarea_.height())
484 add_value = float(workarea_.height() -
485 bv_->text->defaultHeight());
492 workarea_.setScrollbarValue(value);
499 int BufferView::Pimpl::scrollDown(long time)
501 if (!buffer_) return 0;
502 if (!screen_.get()) return 0;
504 double value = workarea_.getScrollbarValue();
505 pair<float, float> p = workarea_.getScrollbarBounds();
506 double const max = p.second;
508 if (value == max) return 0;
510 float add_value = (bv_->text->defaultHeight()
511 + float(time) * float(time) * 0.125);
513 if (add_value > workarea_.height())
514 add_value = float(workarea_.height() -
515 bv_->text->defaultHeight());
522 workarea_.setScrollbarValue(value);
529 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
531 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
535 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
537 // Only use motion with button 1
538 if (!(state & Button1MotionMask))
541 if (!buffer_ || !screen_.get()) return;
543 // Check for inset locking
544 if (bv_->theLockingInset()) {
545 LyXCursor cursor = bv_->text->cursor;
546 LyXFont font = bv_->text->getFont(buffer_,
547 cursor.par(), cursor.pos());
548 int width = bv_->theLockingInset()->width(bv_, font);
549 int inset_x = font.isVisibleRightToLeft()
550 ? cursor.ix() - width : cursor.ix();
551 int start_x = inset_x + bv_->theLockingInset()->scroll();
552 bv_->theLockingInset()->
553 insetMotionNotify(bv_,
555 y - cursor.iy() + bv_->text->first_y,
560 /* The test for not selection possible is needed, that only motion
561 events are used, where the bottom press event was on
562 the drawing area too */
563 if (!selection_possible)
566 screen_->hideCursor();
568 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
570 if (!bv_->text->selection.set())
571 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
573 bv_->text->setSelection(bv_);
574 screen_->toggleToggle(bv_->text, bv_);
580 // Single-click on work area
581 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
584 if (!buffer_ || !screen_.get())
587 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
589 // ok ok, this is a hack.
590 if (button == 4 || button == 5) {
593 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
596 scrollDown(lyxrc.wheel_jump);
601 // Middle button press pastes if we have a selection
602 // We do this here as if the selection was inside an inset
603 // it could get cleared on the unlocking of the inset so
604 // we have to check this first
605 bool paste_internally = false;
606 if (button == 2 && bv_->getLyXText()->selection.set()) {
607 owner_->getLyXFunc()->dispatch(LFUN_COPY);
608 paste_internally = true;
611 int const screen_first = bv_->text->first_y;
613 if (bv_->theLockingInset()) {
614 // We are in inset locking mode
616 /* Check whether the inset was hit. If not reset mode,
617 otherwise give the event to the inset */
618 if (inset_hit == bv_->theLockingInset()) {
619 bv_->theLockingInset()->
620 insetButtonPress(bv_,xpos, ypos,button);
623 bv_->unlockInset(bv_->theLockingInset());
628 selection_possible = true;
629 screen_->hideCursor();
631 // Clear the selection
632 screen_->toggleSelection(bv_->text, bv_);
633 bv_->text->clearSelection();
634 bv_->text->fullRebreak(bv_);
638 // Single left click in math inset?
639 if (isHighlyEditableInset(inset_hit)) {
640 // Highly editable inset, like math
641 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
642 selection_possible = false;
643 owner_->updateLayoutChoice();
644 owner_->message(inset->editMessage());
645 //inset->edit(bv_, xpos, ypos, button);
646 // We just have to lock the inset before calling a PressEvent on it!
647 // we don't need the edit() call here! (Jug20020329)
648 if (!bv_->lockInset(inset)) {
649 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
651 inset->insetButtonPress(bv_, xpos, ypos, button);
654 // I'm not sure we should continue here if we hit an inset (Jug20020403)
656 // Right click on a footnote flag opens float menu
658 selection_possible = false;
662 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
663 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
665 bv_->text->selection.cursor = bv_->text->cursor;
666 bv_->text->cursor.x_fix(bv_->text->cursor.x());
668 owner_->updateLayoutChoice();
670 selection_possible = false;
673 // Insert primary selection with middle mouse
674 // if there is a local selection in the current buffer,
677 if (paste_internally)
678 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
680 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
682 selection_possible = false;
688 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
694 LyXText * text = bv_->getLyXText();
696 if (text->bv_owner && bv_->theLockingInset())
699 if (screen_.get() && button == 1) {
700 if (text->bv_owner) {
701 screen_->hideCursor();
702 screen_->toggleSelection(text, bv_);
703 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
704 screen_->toggleSelection(text, bv_, false);
706 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
708 /* This will fit the cursor on the screen
710 update(text, BufferView::SELECT|BufferView::FITCUR);
715 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
721 LyXText * text = bv_->getLyXText();
723 if (text->bv_owner && bv_->theLockingInset())
726 if (screen_.get() && (button == 1)) {
727 if (text->bv_owner) {
728 screen_->hideCursor();
729 screen_->toggleSelection(text, bv_);
731 text->cursorHome(bv_);
732 text->selection.cursor = text->cursor;
733 text->cursorEnd(bv_);
734 text->setSelection(bv_);
735 if (text->bv_owner) {
736 screen_->toggleSelection(text, bv_, false);
738 /* This will fit the cursor on the screen
740 update(text, BufferView::SELECT|BufferView::FITCUR);
745 void BufferView::Pimpl::selectionRequested()
752 LyXText * text = bv_->getLyXText();
754 if (text->selection.set() &&
755 (!bv_->text->xsel_cache.set() ||
756 text->selection.start != bv_->text->xsel_cache.start ||
757 text->selection.end != bv_->text->xsel_cache.end))
759 bv_->text->xsel_cache = text->selection;
760 sel = text->selectionAsString(bv_->buffer(), false);
761 } else if (!text->selection.set()) {
763 bv_->text->xsel_cache.set(false);
766 workarea_.putClipboard(sel);
771 void BufferView::Pimpl::selectionLost()
773 if (active() && available()) {
776 bv_->getLyXText()->clearSelection();
778 bv_->text->xsel_cache.set(false);
783 void BufferView::Pimpl::enterView()
785 if (active() && available()) {
786 SetXtermCursor(workarea_.getWin());
787 using_xterm_cursor = true;
792 void BufferView::Pimpl::leaveView()
794 if (using_xterm_cursor) {
795 XUndefineCursor(fl_get_display(), workarea_.getWin());
796 using_xterm_cursor = false;
801 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
804 if (!buffer_ || !screen_.get()) return;
806 // If we hit an inset, we have the inset coordinates in these
807 // and inset_hit points to the inset. If we do not hit an
808 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
809 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
811 if (bv_->theLockingInset()) {
812 // We are in inset locking mode.
814 /* LyX does a kind of work-area grabbing for insets.
815 Only a ButtonPress Event outside the inset will
816 force a insetUnlock. */
817 bv_->theLockingInset()->
818 insetButtonRelease(bv_, x, y, button);
822 selection_possible = false;
829 workarea_.haveSelection(bv_->getLyXText()->selection.set());
834 owner_->updateMenubar();
835 owner_->updateToolbar();
837 // Did we hit an editable inset?
839 selection_possible = false;
841 // if we reach this point with a selection, it
842 // must mean we are currently selecting.
843 // But we don't want to open the inset
844 // because that is annoying for the user.
845 // So just pretend we didn't hit it.
846 // this is OK because a "kosher" ButtonRelease
847 // will follow a ButtonPress that clears
849 // Note this also fixes selection drawing
850 // problems if we end up opening an inset
851 if (bv_->getLyXText()->selection.set())
854 // CHECK fix this proper in 0.13
855 // well, maybe 13.0 !!!!!!!!!
857 // Following a ref shouldn't issue
858 // a push on the undo-stack
859 // anylonger, now that we have
860 // keybindings for following
861 // references and returning from
862 // references. IMHO though, it
863 // should be the inset's own business
864 // to push or not push on the undo
865 // stack. They don't *have* to
866 // alter the document...
868 // ...or maybe the SetCursorParUndo()
869 // below isn't necessary at all anylonger?
870 if (inset_hit->lyxCode() == Inset::REF_CODE) {
871 setCursorParUndo(bv_);
874 owner_->message(inset_hit->editMessage());
876 if (isHighlyEditableInset(inset_hit)) {
877 // Highly editable inset, like math
878 UpdatableInset *inset = (UpdatableInset *)inset_hit;
879 inset->insetButtonRelease(bv_, x, y, button);
881 inset_hit->insetButtonRelease(bv_, x, y, button);
882 // IMO this is a grosshack! Inset's should be changed so that
883 // they call the actions they have to do with the insetButtonRel.
884 // function and not in the edit(). This should be changed
886 inset_hit->edit(bv_, x, y, button);
891 // Maybe we want to edit a bibitem ale970302
892 if (bv_->text->cursor.par()->bibkey && x < 20 +
893 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
894 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
901 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
902 LyXCursor const & cursor) const
904 Paragraph /*const*/ & par = *cursor.par();
905 pos_type const pos = cursor.pos();
907 lyx::Assert(par.getInset(pos));
909 Inset const & inset(*par.getInset(pos));
911 LyXFont const & font = text.getFont(buffer_, &par, pos);
913 int const width = inset.width(bv_, font);
914 int const inset_x = font.isVisibleRightToLeft()
915 ? (cursor.ix() - width) : cursor.ix();
918 inset_x + inset.scroll(),
920 cursor.iy() - inset.ascent(bv_, font),
921 cursor.iy() + inset.descent(bv_, font));
925 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
926 LyXCursor const & cursor,
927 int & x, int & y) const
929 pos_type const pos(cursor.pos());
930 Paragraph /*const*/ & par(*cursor.par());
932 if (pos >= par.size() || !par.isInset(pos)) {
936 Inset /*const*/ * inset = par.getInset(pos);
938 if (!isEditableInset(inset)) {
942 Box b(insetDimensions(text, cursor));
944 if (!b.contained(x, y)) {
945 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
946 << " box " << b << endl;
950 text.setCursor(bv_, &par, pos, true);
953 // The origin of an inset is on the baseline
954 y -= text.cursor.iy();
960 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
965 int y_tmp = y + text->first_y;
968 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
970 Inset * inset(checkInset(*text, cursor, x, y_tmp));
977 // look at previous position
979 if (cursor.pos() == 0) {
984 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
986 inset = checkInset(*text, cursor, x, y_tmp);
994 void BufferView::Pimpl::workAreaExpose()
996 static int work_area_width;
997 static unsigned int work_area_height;
999 bool const widthChange = workarea_.workWidth() != work_area_width;
1000 bool const heightChange = workarea_.height() != work_area_height;
1002 // update from work area
1003 work_area_width = workarea_.workWidth();
1004 work_area_height = workarea_.height();
1007 // The visible LyXView need a resize
1010 // Remove all texts from the textcache
1011 // This is not _really_ what we want to do. What
1012 // we really want to do is to delete in textcache
1013 // that does not have a BufferView with matching
1014 // width, but as long as we have only one BufferView
1015 // deleting all gives the same result.
1016 if (lyxerr.debugging())
1017 textcache.show(lyxerr, "Expose delete all");
1019 buffer_->resizeInsets(bv_);
1020 } else if (heightChange) {
1021 // Rebuild image of current screen
1023 // fitCursor() ensures we don't jump back
1024 // to the start of the document on vertical
1028 // The main window size has changed, repaint most stuff
1030 } else if (screen_.get())
1031 screen_->redraw(bv_->text, bv_);
1033 // Grey box when we don't have a buffer
1034 workarea_.greyOut();
1037 // always make sure that the scrollbar is sane.
1039 owner_->updateLayoutChoice();
1044 void BufferView::Pimpl::update()
1046 if (screen_.get() &&
1047 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1049 LyXText::text_status st = bv_->text->status();
1050 screen_->update(bv_->text, bv_);
1052 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1053 if (bv_->text->fullRebreak(bv_)) {
1054 st = LyXText::NEED_MORE_REFRESH;
1055 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1056 bv_->text->cursor.pos());
1059 bv_->text->status(bv_, st);
1060 screen_->update(bv_->text, bv_);
1062 // do this here instead of in the screen::update because of
1064 bv_->text->status(bv_, LyXText::UNCHANGED);
1070 // Values used when calling update:
1072 // -2 - update, move sel_cursor if selection, fitcursor
1073 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1074 // 0 - update, move sel_cursor if selection, fitcursor
1075 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1076 // 3 - update, move sel_cursor if selection
1079 // a simple redraw of the parts that need refresh
1081 // move sel_cursor if selection -
1082 // the text's sel_cursor is moved if there is selection is progress
1085 // fitCursor() is called and the scrollbar updated
1088 // the buffer is marked dirty.
1097 // UPDATE_ONLY = UPDATE;
1098 // UPDATE_SELECT = UPDATE | SELECT;
1099 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1100 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1102 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1103 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1104 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1105 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1106 // update(3) -> update(1) -> update(1) -> update(SELECT)
1108 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1110 owner_->updateLayoutChoice();
1112 if (!text->selection.set() && (f & SELECT)) {
1113 text->selection.cursor = text->cursor;
1116 text->fullRebreak(bv_);
1118 if (text->inset_owner) {
1119 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1120 updateInset(text->inset_owner, false);
1130 buffer_->markDirty();
1135 // Callback for cursor timer
1136 void BufferView::Pimpl::cursorToggle()
1139 cursor_timeout.restart();
1143 if (!screen_.get()) {
1144 cursor_timeout.restart();
1149 extern void reapSpellchecker(void);
1152 if (!bv_->theLockingInset()) {
1153 screen_->cursorToggle(bv_);
1155 bv_->theLockingInset()->toggleInsetCursor(bv_);
1158 cursor_timeout.restart();
1162 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1164 if (!text->cursor.row()->previous())
1167 int y = text->first_y;
1168 Row * cursorrow = text->cursor.row();
1170 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1172 // This is to allow jumping over large insets
1173 if ((cursorrow == text->cursor.row()))
1174 text->cursorUp(bv_);
1176 if (text->inset_owner) {
1177 int new_y = bv_->text->cursor.iy()
1178 + bv_->theLockingInset()->insetInInsetY()
1180 + text->cursor.row()->height()
1181 - workarea_.height() + 1;
1183 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1184 } else if (text->cursor.row()->height() < workarea_.height()) {
1185 screen_->draw(text, bv_,
1187 - text->cursor.row()->baseline()
1188 + text->cursor.row()->height()
1189 - workarea_.height() + 1);
1195 void BufferView::Pimpl::cursorNext(LyXText * text)
1197 if (!text->cursor.row()->next())
1200 int y = text->first_y + workarea_.height();
1201 if (text->inset_owner && !text->first_y) {
1202 y -= (bv_->text->cursor.iy()
1203 - bv_->text->first_y
1204 + bv_->theLockingInset()->insetInInsetY());
1206 text->getRowNearY(y);
1208 Row * cursorrow = text->cursor.row();
1209 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1211 // This is to allow jumping over large insets
1212 if ((cursorrow == bv_->text->cursor.row()))
1213 text->cursorDown(bv_);
1215 if (text->inset_owner) {
1216 screen_->draw(bv_->text, bv_,
1217 bv_->text->cursor.iy()
1218 + bv_->theLockingInset()->insetInInsetY()
1219 + y - text->cursor.row()->baseline());
1220 } else if (text->cursor.row()->height() < workarea_.height()) {
1221 screen_->draw(text, bv_, text->cursor.y() -
1222 text->cursor.row()->baseline());
1228 bool BufferView::Pimpl::available() const
1230 if (buffer_ && bv_->text)
1236 void BufferView::Pimpl::beforeChange(LyXText * text)
1239 text->clearSelection();
1243 void BufferView::Pimpl::savePosition(unsigned int i)
1245 if (i >= saved_positions_num)
1247 saved_positions[i] = Position(buffer_->fileName(),
1248 bv_->text->cursor.par()->id(),
1249 bv_->text->cursor.pos());
1252 str << _("Saved bookmark") << ' ' << i;
1253 owner_->message(str.str().c_str());
1258 void BufferView::Pimpl::restorePosition(unsigned int i)
1260 if (i >= saved_positions_num)
1263 string const fname = saved_positions[i].filename;
1265 beforeChange(bv_->text);
1267 if (fname != buffer_->fileName()) {
1268 Buffer * b = bufferlist.exists(fname) ?
1269 bufferlist.getBuffer(fname) :
1270 bufferlist.loadLyXFile(fname); // don't ask, just load it
1271 if (b != 0) buffer(b);
1274 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1278 bv_->text->setCursor(bv_, par,
1279 min(par->size(), saved_positions[i].par_pos));
1281 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1284 str << _("Moved to bookmark") << ' ' << i;
1285 owner_->message(str.str().c_str());
1290 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1292 if (i >= saved_positions_num)
1295 return !saved_positions[i].filename.empty();
1299 void BufferView::Pimpl::setState()
1301 if (!lyxrc.rtl_support)
1304 LyXText * text = bv_->getLyXText();
1305 if (text->real_current_font.isRightToLeft()) {
1306 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1307 owner_->getIntl()->KeyMapSec();
1309 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1310 owner_->getIntl()->KeyMapPrim();
1315 void BufferView::Pimpl::insetSleep()
1317 if (bv_->theLockingInset() && !inset_slept) {
1318 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1319 bv_->theLockingInset()->insetUnlock(bv_);
1325 void BufferView::Pimpl::insetWakeup()
1327 if (bv_->theLockingInset() && inset_slept) {
1328 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1329 inset_slept = false;
1334 void BufferView::Pimpl::insetUnlock()
1336 if (bv_->theLockingInset()) {
1338 bv_->theLockingInset()->insetUnlock(bv_);
1339 bv_->theLockingInset(0);
1341 inset_slept = false;
1346 bool BufferView::Pimpl::focus() const
1348 return workarea_.hasFocus();
1352 void BufferView::Pimpl::focus(bool f)
1354 if (f) workarea_.setFocus();
1358 bool BufferView::Pimpl::active() const
1360 return workarea_.active();
1364 bool BufferView::Pimpl::belowMouse() const
1366 return workarea_.belowMouse();
1370 void BufferView::Pimpl::showCursor()
1372 if (screen_.get()) {
1373 if (bv_->theLockingInset())
1374 bv_->theLockingInset()->showInsetCursor(bv_);
1376 screen_->showCursor(bv_->text, bv_);
1381 void BufferView::Pimpl::hideCursor()
1383 if (screen_.get()) {
1384 if (!bv_->theLockingInset())
1385 // bv_->theLockingInset()->hideInsetCursor(bv_);
1387 screen_->hideCursor();
1392 void BufferView::Pimpl::toggleSelection(bool b)
1394 if (screen_.get()) {
1395 if (bv_->theLockingInset())
1396 bv_->theLockingInset()->toggleSelection(bv_, b);
1397 screen_->toggleSelection(bv_->text, bv_, b);
1402 void BufferView::Pimpl::toggleToggle()
1405 screen_->toggleToggle(bv_->text, bv_);
1409 void BufferView::Pimpl::center()
1411 beforeChange(bv_->text);
1412 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1413 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1415 screen_->draw(bv_->text, bv_, 0);
1417 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1422 void BufferView::Pimpl::pasteClipboard(bool asPara)
1427 screen_->hideCursor();
1428 beforeChange(bv_->text);
1430 string const clip(workarea_.getClipboard());
1436 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1438 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1440 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1444 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1446 workarea_.putClipboard(stuff);
1451 * Dispatch functions for actions which can be valid for BufferView->text
1452 * and/or InsetText->text!!!
1457 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1459 LyXText * lt = bv_->getLyXText();
1461 if (selecting || lt->selection.mark()) {
1462 lt->setSelection(bv_);
1466 updateInset(lt->inset_owner, false);
1469 update(lt, BufferView::SELECT|BufferView::FITCUR);
1473 if (!lt->selection.set())
1474 workarea_.haveSelection(false);
1476 /* ---> Everytime the cursor is moved, show the current font state. */
1477 // should this too me moved out of this func?
1478 //owner->showState();
1483 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1485 LyXCursor cursor = bv_->getLyXText()->cursor;
1486 Buffer::inset_iterator it =
1487 find_if(Buffer::inset_iterator(
1488 cursor.par(), cursor.pos()),
1489 buffer_->inset_iterator_end(),
1490 lyx::compare_memfun(&Inset::lyxCode, code));
1491 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1495 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1497 string filename = filen;
1499 if (filename.empty()) {
1500 // Launch a file browser
1501 string initpath = lyxrc.document_path;
1504 string const trypath = owner_->buffer()->filePath();
1505 // If directory is writeable, use this as default.
1506 if (IsDirWriteable(trypath))
1510 FileDialog fileDlg(bv_->owner(),
1511 _("Select LyX document to insert"),
1513 make_pair(string(_("Documents|#o#O")),
1514 string(lyxrc.document_path)),
1515 make_pair(string(_("Examples|#E#e")),
1516 string(AddPath(system_lyxdir, "examples"))));
1518 FileDialog::Result result =
1519 fileDlg.Select(initpath,
1520 _("*.lyx| LyX Documents (*.lyx)"));
1522 if (result.first == FileDialog::Later)
1525 filename = result.second;
1527 // check selected filename
1528 if (filename.empty()) {
1529 owner_->message(_("Canceled."));
1534 // get absolute path of file and add ".lyx" to the filename if
1536 filename = FileSearch(string(), filename, "lyx");
1538 string const disp_fn(MakeDisplayPath(filename));
1541 s1 << _("Inserting document") << ' '
1542 << disp_fn << " ...";
1543 owner_->message(s1.str().c_str());
1544 bool const res = bv_->insertLyXFile(filename);
1547 str << _("Document") << ' ' << disp_fn
1548 << ' ' << _("inserted.");
1549 owner_->message(str.str().c_str());
1552 str << _("Could not insert document") << ' '
1554 owner_->message(str.str().c_str());
1559 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1561 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1562 << action <<"] arg[" << argument << "]" << endl;
1565 // --- Misc -------------------------------------------
1569 LyXText * lt = bv_->getLyXText();
1570 lt->toggleAppendix(bv_);
1573 | BufferView::FITCUR
1574 | BufferView::CHANGE);
1579 case LFUN_TOC_INSERT:
1581 InsetCommandParams p;
1582 p.setCmdName("tableofcontents");
1583 Inset * inset = new InsetTOC(p);
1584 if (!insertInset(inset, "Standard"))
1589 case LFUN_SCROLL_INSET:
1590 // this is not handled here as this funktion is only aktive
1591 // if we have a locking_inset and that one is (or contains)
1595 case LFUN_INSET_GRAPHICS:
1597 Inset * new_inset = new InsetGraphics;
1598 if (!insertInset(new_inset)) {
1601 // this is need because you don't use a inset->Edit()
1602 updateInset(new_inset, true);
1603 new_inset->edit(bv_);
1613 case LFUN_PASTESELECTION:
1615 bool asPara = false;
1616 if (argument == "paragraph")
1618 pasteClipboard(asPara);
1630 case LFUN_LAYOUT_COPY:
1631 bv_->copyEnvironment();
1634 case LFUN_LAYOUT_PASTE:
1635 bv_->pasteEnvironment();
1639 case LFUN_GOTOERROR:
1640 gotoInset(Inset::ERROR_CODE, false);
1644 gotoInset(Inset::IGNORE_CODE, false);
1647 case LFUN_REFERENCE_GOTO:
1649 vector<Inset::Code> tmp;
1650 tmp.push_back(Inset::LABEL_CODE);
1651 tmp.push_back(Inset::REF_CODE);
1652 gotoInset(tmp, true);
1656 case LFUN_HYPHENATION:
1657 specialChar(InsetSpecialChar::HYPHENATION);
1660 case LFUN_LIGATURE_BREAK:
1661 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1665 specialChar(InsetSpecialChar::LDOTS);
1668 case LFUN_END_OF_SENTENCE:
1669 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1672 case LFUN_MENU_SEPARATOR:
1673 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1680 case LFUN_DEPTH_MIN:
1681 changeDepth(bv_, bv_->getLyXText(), -1);
1684 case LFUN_DEPTH_PLUS:
1685 changeDepth(bv_, bv_->getLyXText(), 1);
1689 owner_->getDialogs()->setUserFreeFont();
1692 case LFUN_FILE_INSERT:
1693 MenuInsertLyXFile(argument);
1696 case LFUN_FILE_INSERT_ASCII_PARA:
1697 InsertAsciiFile(bv_, argument, true);
1700 case LFUN_FILE_INSERT_ASCII:
1701 InsertAsciiFile(bv_, argument, false);
1706 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1707 << argument << endl;
1709 // Derive layout number from given argument (string)
1710 // and current buffer's textclass (number). */
1711 textclass_type tclass = buffer_->params.textclass;
1713 textclasslist[tclass].hasLayout(argument);
1714 string layout = argument;
1716 // If the entry is obsolete, use the new one instead.
1718 string const & obs = textclasslist[tclass][layout]
1725 owner_->getLyXFunc()->setErrorMessage(
1726 string(N_("Layout ")) + argument +
1731 if (current_layout != layout) {
1732 LyXText * lt = bv_->getLyXText();
1734 current_layout = layout;
1737 | BufferView::FITCUR);
1738 lt->setLayout(bv_, layout);
1739 owner_->setLayout(layout);
1742 | BufferView::FITCUR
1743 | BufferView::CHANGE);
1750 lang(bv_, argument);
1752 owner_->showState();
1757 owner_->showState();
1762 owner_->showState();
1767 owner_->showState();
1772 owner_->showState();
1777 owner_->showState();
1782 owner_->showState();
1787 owner_->showState();
1790 case LFUN_UNDERLINE:
1792 owner_->showState();
1795 case LFUN_FONT_SIZE:
1796 fontSize(bv_, argument);
1797 owner_->showState();
1800 case LFUN_FONT_STATE:
1801 owner_->getLyXFunc()->setMessage(currentState(bv_));
1804 case LFUN_UPCASE_WORD:
1806 LyXText * lt = bv_->getLyXText();
1810 | BufferView::FITCUR);
1811 lt->changeCase(bv_, LyXText::text_uppercase);
1812 if (lt->inset_owner)
1813 updateInset(lt->inset_owner, true);
1816 | BufferView::FITCUR
1817 | BufferView::CHANGE);
1821 case LFUN_LOWCASE_WORD:
1823 LyXText * lt = bv_->getLyXText();
1825 update(lt, BufferView::SELECT|BufferView::FITCUR);
1826 lt->changeCase(bv_, LyXText::text_lowercase);
1827 if (lt->inset_owner)
1828 updateInset(lt->inset_owner, true);
1831 | BufferView::FITCUR
1832 | BufferView::CHANGE);
1836 case LFUN_CAPITALIZE_WORD:
1838 LyXText * lt = bv_->getLyXText();
1840 update(lt, BufferView::SELECT|BufferView::FITCUR);
1841 lt->changeCase(bv_, LyXText::text_capitalization);
1842 if (lt->inset_owner)
1843 updateInset(lt->inset_owner, true);
1846 | BufferView::FITCUR
1847 | BufferView::CHANGE);
1851 case LFUN_TRANSPOSE_CHARS:
1853 LyXText * lt = bv_->getLyXText();
1855 update(lt, BufferView::SELECT|BufferView::FITCUR);
1856 lt->transposeChars(*bv_);
1857 if (lt->inset_owner)
1858 updateInset(lt->inset_owner, true);
1861 | BufferView::FITCUR
1862 | BufferView::CHANGE);
1867 case LFUN_INSERT_LABEL:
1868 MenuInsertLabel(bv_, argument);
1871 case LFUN_REF_INSERT:
1872 if (argument.empty()) {
1873 InsetCommandParams p("ref");
1874 owner_->getDialogs()->createRef(p.getAsString());
1876 InsetCommandParams p;
1877 p.setFromString(argument);
1879 InsetRef * inset = new InsetRef(p, *buffer_);
1880 if (!insertInset(inset))
1883 updateInset(inset, true);
1887 case LFUN_BOOKMARK_SAVE:
1888 savePosition(strToUnsignedInt(argument));
1891 case LFUN_BOOKMARK_GOTO:
1892 restorePosition(strToUnsignedInt(argument));
1897 string label(argument);
1898 if (label.empty()) {
1900 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1902 label = inset->getContents();
1907 if (!label.empty()) {
1908 //bv_->savePosition(0);
1909 if (!bv_->gotoLabel(label))
1910 Alert::alert(_("Error"),
1911 _("Couldn't find this label"),
1912 _("in current document."));
1917 // --- Cursor Movements -----------------------------
1920 LyXText * lt = bv_->getLyXText();
1922 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1923 if (!lt->selection.mark())
1925 update(lt, BufferView::SELECT|BufferView::FITCUR);
1927 lt->cursorLeft(bv_, false);
1928 if (lt->cursor.pos() < lt->cursor.par()->size()
1929 && lt->cursor.par()->isInset(lt->cursor.pos())
1930 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1931 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1932 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1934 tmpinset->edit(bv_, false);
1936 tmpinset->edit(bv_);
1940 lt->cursorRight(bv_, false);
1942 moveCursorUpdate(false);
1943 owner_->showState();
1949 // This is soooo ugly. Isn`t it possible to make
1950 // it simpler? (Lgb)
1951 LyXText * lt = bv_->getLyXText();
1952 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1953 if (!lt->selection.mark())
1955 update(lt, BufferView::SELECT|BufferView::FITCUR);
1956 LyXCursor const cur = lt->cursor;
1958 lt->cursorLeft(bv_, false);
1959 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1960 lt->cursor.pos() < lt->cursor.par()->size() &&
1961 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1962 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1963 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1964 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1966 tmpinset->edit(bv_);
1968 tmpinset->edit(bv_, false);
1972 lt->cursorRight(bv_, false);
1975 moveCursorUpdate(false);
1976 owner_->showState();
1982 LyXText * lt = bv_->getLyXText();
1984 if (!lt->selection.mark())
1986 update(lt, BufferView::UPDATE);
1989 moveCursorUpdate(false);
1990 owner_->showState();
1996 LyXText * lt = bv_->getLyXText();
1998 if (!lt->selection.mark())
2000 update(lt, BufferView::UPDATE);
2001 lt->cursorDown(bv_);
2003 moveCursorUpdate(false);
2004 owner_->showState();
2008 case LFUN_UP_PARAGRAPH:
2010 LyXText * lt = bv_->getLyXText();
2012 if (!lt->selection.mark())
2014 update(lt, BufferView::UPDATE);
2015 lt->cursorUpParagraph(bv_);
2017 moveCursorUpdate(false);
2018 owner_->showState();
2022 case LFUN_DOWN_PARAGRAPH:
2024 LyXText * lt = bv_->getLyXText();
2026 if (!lt->selection.mark())
2028 update(lt, BufferView::UPDATE);
2029 lt->cursorDownParagraph(bv_);
2031 moveCursorUpdate(false);
2032 owner_->showState();
2038 LyXText * lt = bv_->getLyXText();
2040 if (!lt->selection.mark())
2042 update(lt, BufferView::UPDATE);
2045 moveCursorUpdate(false);
2046 owner_->showState();
2052 LyXText * lt = bv_->getLyXText();
2054 if (!lt->selection.mark())
2056 update(lt, BufferView::UPDATE);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2066 LyXText * lt = bv_->getLyXText();
2068 if (!lt->selection.mark())
2070 update(lt, BufferView::SELECT|BufferView::FITCUR);
2071 lt->cursorHome(bv_);
2073 moveCursorUpdate(false);
2074 owner_->showState();
2080 LyXText * lt = bv_->getLyXText();
2082 if (!lt->selection.mark())
2085 BufferView::SELECT|BufferView::FITCUR);
2088 moveCursorUpdate(false);
2089 owner_->showState();
2093 case LFUN_SHIFT_TAB:
2096 LyXText * lt = bv_->getLyXText();
2098 if (!lt->selection.mark())
2101 BufferView::SELECT|BufferView::FITCUR);
2104 moveCursorUpdate(false);
2105 owner_->showState();
2109 case LFUN_WORDRIGHT:
2111 LyXText * lt = bv_->getLyXText();
2113 if (!lt->selection.mark())
2115 update(lt, BufferView::SELECT|BufferView::FITCUR);
2116 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2117 lt->cursorLeftOneWord(bv_);
2119 lt->cursorRightOneWord(bv_);
2121 moveCursorUpdate(false);
2122 owner_->showState();
2128 LyXText * lt = bv_->getLyXText();
2130 if (!lt->selection.mark())
2132 update(lt, BufferView::SELECT|BufferView::FITCUR);
2133 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2134 lt->cursorRightOneWord(bv_);
2136 lt->cursorLeftOneWord(bv_);
2138 moveCursorUpdate(false);
2139 owner_->showState();
2143 case LFUN_BEGINNINGBUF:
2145 LyXText * lt = bv_->getLyXText();
2147 if (!lt->selection.mark())
2150 BufferView::SELECT|BufferView::FITCUR);
2153 moveCursorUpdate(false);
2154 owner_->showState();
2160 LyXText * lt = bv_->getLyXText();
2162 if (!lt->selection.mark())
2165 BufferView::SELECT|BufferView::FITCUR);
2166 lt->cursorBottom(bv_);
2168 moveCursorUpdate(false);
2169 owner_->showState();
2173 /* cursor selection ---------------------------- */
2176 LyXText * lt = bv_->getLyXText();
2179 BufferView::SELECT|BufferView::FITCUR);
2180 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2181 lt->cursorLeft(bv_);
2183 lt->cursorRight(bv_);
2185 moveCursorUpdate(true);
2186 owner_->showState();
2192 LyXText * lt = bv_->getLyXText();
2195 BufferView::SELECT|BufferView::FITCUR);
2196 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2197 lt->cursorRight(bv_);
2199 lt->cursorLeft(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2208 LyXText * lt = bv_->getLyXText();
2211 BufferView::SELECT|BufferView::FITCUR);
2214 moveCursorUpdate(true);
2215 owner_->showState();
2221 LyXText * lt = bv_->getLyXText();
2224 BufferView::SELECT|BufferView::FITCUR);
2225 lt->cursorDown(bv_);
2227 moveCursorUpdate(true);
2228 owner_->showState();
2232 case LFUN_UP_PARAGRAPHSEL:
2234 LyXText * lt = bv_->getLyXText();
2237 BufferView::SELECT|BufferView::FITCUR);
2238 lt->cursorUpParagraph(bv_);
2240 moveCursorUpdate(true);
2241 owner_->showState();
2245 case LFUN_DOWN_PARAGRAPHSEL:
2247 LyXText * lt = bv_->getLyXText();
2250 BufferView::SELECT|BufferView::FITCUR);
2251 lt->cursorDownParagraph(bv_);
2253 moveCursorUpdate(true);
2254 owner_->showState();
2260 LyXText * lt = bv_->getLyXText();
2262 update(lt, BufferView::SELECT|BufferView::FITCUR);
2265 moveCursorUpdate(true);
2266 owner_->showState();
2272 LyXText * lt = bv_->getLyXText();
2274 update(lt, BufferView::SELECT|BufferView::FITCUR);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2284 LyXText * lt = bv_->getLyXText();
2286 update(lt, BufferView::SELECT|BufferView::FITCUR);
2287 lt->cursorHome(bv_);
2289 moveCursorUpdate(true);
2290 owner_->showState();
2296 LyXText * lt = bv_->getLyXText();
2298 update(lt, BufferView::SELECT|BufferView::FITCUR);
2301 moveCursorUpdate(true);
2302 owner_->showState();
2306 case LFUN_WORDRIGHTSEL:
2308 LyXText * lt = bv_->getLyXText();
2310 update(lt, BufferView::SELECT|BufferView::FITCUR);
2311 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2312 lt->cursorLeftOneWord(bv_);
2314 lt->cursorRightOneWord(bv_);
2316 moveCursorUpdate(true);
2317 owner_->showState();
2321 case LFUN_WORDLEFTSEL:
2323 LyXText * lt = bv_->getLyXText();
2325 update(lt, BufferView::SELECT|BufferView::FITCUR);
2326 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2327 lt->cursorRightOneWord(bv_);
2329 lt->cursorLeftOneWord(bv_);
2331 moveCursorUpdate(true);
2332 owner_->showState();
2336 case LFUN_BEGINNINGBUFSEL:
2338 LyXText * lt = bv_->getLyXText();
2340 if (lt->inset_owner)
2342 update(lt, BufferView::SELECT|BufferView::FITCUR);
2345 moveCursorUpdate(true);
2346 owner_->showState();
2350 case LFUN_ENDBUFSEL:
2352 LyXText * lt = bv_->getLyXText();
2354 if (lt->inset_owner)
2357 BufferView::SELECT|BufferView::FITCUR);
2358 lt->cursorBottom(bv_);
2360 moveCursorUpdate(true);
2361 owner_->showState();
2365 // --- text changing commands ------------------------
2366 case LFUN_BREAKLINE:
2368 LyXText * lt = bv_->getLyXText();
2371 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2374 | BufferView::FITCUR
2375 | BufferView::CHANGE);
2376 moveCursorUpdate(false);
2380 case LFUN_PROTECTEDSPACE:
2382 LyXText * lt = bv_->getLyXText();
2384 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2386 if (style.free_spacing) {
2387 lt->insertChar(bv_, ' ');
2390 | BufferView::FITCUR
2391 | BufferView::CHANGE);
2393 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2395 moveCursorUpdate(false);
2401 LyXText * lt = bv_->getLyXText();
2403 if (lt->selection.mark()) {
2407 | BufferView::FITCUR);
2408 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2411 lt->selection.mark(true);
2414 | BufferView::FITCUR);
2415 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2417 lt->selection.cursor = lt->cursor;
2423 LyXText * lt = bv_->getLyXText();
2425 if (!lt->selection.set()) {
2427 lt->selection.cursor = lt->cursor;
2430 | BufferView::FITCUR
2431 | BufferView::CHANGE);
2432 // It is possible to make it a lot faster still
2433 // just comment out the line below...
2438 moveCursorUpdate(false);
2439 owner_->showState();
2444 case LFUN_DELETE_SKIP:
2446 LyXText * lt = bv_->getLyXText();
2448 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2450 LyXCursor cursor = lt->cursor;
2452 if (!lt->selection.set()) {
2453 if (cursor.pos() == cursor.par()->size()) {
2454 lt->cursorRight(bv_);
2455 cursor = lt->cursor;
2456 if (cursor.pos() == 0
2457 && !(cursor.par()->params().spaceTop()
2458 == VSpace (VSpace::NONE))) {
2461 cursor.par()->params().lineTop(),
2462 cursor.par()->params().lineBottom(),
2463 cursor.par()->params().pagebreakTop(),
2464 cursor.par()->params().pagebreakBottom(),
2465 VSpace(VSpace::NONE),
2466 cursor.par()->params().spaceBottom(),
2467 cursor.par()->params().spacing(),
2468 cursor.par()->params().align(),
2469 cursor.par()->params().labelWidthString(), 0);
2470 lt->cursorLeft(bv_);
2473 | BufferView::FITCUR
2474 | BufferView::CHANGE);
2476 lt->cursorLeft(bv_);
2478 lt->selection.cursor = lt->cursor;
2481 | BufferView::FITCUR
2482 | BufferView::CHANGE);
2486 lt->selection.cursor = lt->cursor;
2489 | BufferView::FITCUR
2490 | BufferView::CHANGE);
2498 /* -------> Delete word forward. */
2499 case LFUN_DELETE_WORD_FORWARD:
2500 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2501 bv_->getLyXText()->deleteWordForward(bv_);
2502 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2503 moveCursorUpdate(false);
2504 owner_->showState();
2507 /* -------> Delete word backward. */
2508 case LFUN_DELETE_WORD_BACKWARD:
2510 LyXText * lt = bv_->getLyXText();
2512 update(lt, BufferView::SELECT|BufferView::FITCUR);
2513 lt->deleteWordBackward(bv_);
2516 | BufferView::FITCUR
2517 | BufferView::CHANGE);
2518 moveCursorUpdate(false);
2519 owner_->showState();
2523 /* -------> Kill to end of line. */
2524 case LFUN_DELETE_LINE_FORWARD:
2526 LyXText * lt = bv_->getLyXText();
2528 update(lt, BufferView::SELECT|BufferView::FITCUR);
2529 lt->deleteLineForward(bv_);
2532 | BufferView::FITCUR
2533 | BufferView::CHANGE);
2534 moveCursorUpdate(false);
2538 /* -------> Set mark off. */
2541 LyXText * lt = bv_->getLyXText();
2544 update(lt, BufferView::SELECT|BufferView::FITCUR);
2545 lt->selection.cursor = lt->cursor;
2546 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2550 /* -------> Set mark on. */
2553 LyXText * lt = bv_->getLyXText();
2556 lt->selection.mark(true);
2557 update(lt, BufferView::SELECT|BufferView::FITCUR);
2558 lt->selection.cursor = lt->cursor;
2559 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2563 case LFUN_BACKSPACE:
2565 LyXText * lt = bv_->getLyXText();
2567 if (!lt->selection.set()) {
2568 if (owner_->getIntl()->getTrans().backspace()) {
2570 lt->selection.cursor = lt->cursor;
2573 | BufferView::FITCUR
2574 | BufferView::CHANGE);
2575 // It is possible to make it a lot faster still
2576 // just comment out the line below...
2582 owner_->showState();
2587 case LFUN_BACKSPACE_SKIP:
2589 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2590 LyXText * lt = bv_->getLyXText();
2592 LyXCursor cursor = lt->cursor;
2594 if (!lt->selection.set()) {
2595 if (cursor.pos() == 0
2596 && !(cursor.par()->params().spaceTop()
2597 == VSpace (VSpace::NONE))) {
2600 cursor.par()->params().lineTop(),
2601 cursor.par()->params().lineBottom(),
2602 cursor.par()->params().pagebreakTop(),
2603 cursor.par()->params().pagebreakBottom(),
2604 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2605 cursor.par()->params().spacing(),
2606 cursor.par()->params().align(),
2607 cursor.par()->params().labelWidthString(), 0);
2610 | BufferView::FITCUR
2611 | BufferView::CHANGE);
2614 lt->selection.cursor = cursor;
2617 | BufferView::FITCUR
2618 | BufferView::CHANGE);
2625 case LFUN_BREAKPARAGRAPH:
2627 LyXText * lt = bv_->getLyXText();
2630 lt->breakParagraph(bv_, 0);
2633 | BufferView::FITCUR
2634 | BufferView::CHANGE);
2635 lt->selection.cursor = lt->cursor;
2637 owner_->showState();
2641 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2643 LyXText * lt = bv_->getLyXText();
2646 lt->breakParagraph(bv_, 1);
2649 | BufferView::FITCUR
2650 | BufferView::CHANGE);
2651 lt->selection.cursor = lt->cursor;
2653 owner_->showState();
2657 case LFUN_BREAKPARAGRAPH_SKIP:
2659 // When at the beginning of a paragraph, remove
2660 // indentation and add a "defskip" at the top.
2661 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2662 LyXText * lt = bv_->getLyXText();
2664 LyXCursor cursor = lt->cursor;
2667 if (cursor.pos() == 0) {
2668 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2671 cursor.par()->params().lineTop(),
2672 cursor.par()->params().lineBottom(),
2673 cursor.par()->params().pagebreakTop(),
2674 cursor.par()->params().pagebreakBottom(),
2675 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2676 cursor.par()->params().spacing(),
2677 cursor.par()->params().align(),
2678 cursor.par()->params().labelWidthString(), 1);
2679 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2683 lt->breakParagraph(bv_, 0);
2684 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2689 | BufferView::FITCUR
2690 | BufferView::CHANGE);
2691 lt->selection.cursor = cursor;
2693 owner_->showState();
2697 case LFUN_PARAGRAPH_SPACING:
2699 LyXText * lt = bv_->getLyXText();
2701 Paragraph * par = lt->cursor.par();
2702 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2703 float cur_value = 1.0;
2704 if (cur_spacing == Spacing::Other) {
2705 cur_value = par->params().spacing().getValue();
2708 istringstream istr(argument.c_str());
2712 Spacing::Space new_spacing = cur_spacing;
2713 float new_value = cur_value;
2715 lyxerr << "Missing argument to `paragraph-spacing'"
2717 } else if (tmp == "single") {
2718 new_spacing = Spacing::Single;
2719 } else if (tmp == "onehalf") {
2720 new_spacing = Spacing::Onehalf;
2721 } else if (tmp == "double") {
2722 new_spacing = Spacing::Double;
2723 } else if (tmp == "other") {
2724 new_spacing = Spacing::Other;
2727 lyxerr << "new_value = " << tmpval << endl;
2730 } else if (tmp == "default") {
2731 new_spacing = Spacing::Default;
2733 lyxerr << _("Unknown spacing argument: ")
2734 << argument << endl;
2736 if (cur_spacing != new_spacing || cur_value != new_value) {
2737 par->params().spacing(Spacing(new_spacing, new_value));
2738 lt->redoParagraph(bv_);
2741 | BufferView::FITCUR
2742 | BufferView::CHANGE);
2747 case LFUN_INSET_TOGGLE:
2749 LyXText * lt = bv_->getLyXText();
2752 update(lt, BufferView::SELECT|BufferView::FITCUR);
2753 lt->toggleInset(bv_);
2754 update(lt, BufferView::SELECT|BufferView::FITCUR);
2766 InsetCommandParams p;
2767 if (action == LFUN_HTMLURL)
2768 p.setCmdName("htmlurl");
2770 p.setCmdName("url");
2771 owner_->getDialogs()->createUrl(p.getAsString());
2775 case LFUN_INSERT_URL:
2777 InsetCommandParams p;
2778 p.setFromString(argument);
2780 InsetUrl * inset = new InsetUrl(p);
2781 if (!insertInset(inset))
2784 updateInset(inset, true);
2788 case LFUN_INSET_ERT:
2789 insertAndEditInset(new InsetERT(buffer_->params));
2792 case LFUN_INSET_EXTERNAL:
2793 insertAndEditInset(new InsetExternal);
2796 case LFUN_INSET_FOOTNOTE:
2797 insertAndEditInset(new InsetFoot(buffer_->params));
2800 case LFUN_INSET_MARGINAL:
2801 insertAndEditInset(new InsetMarginal(buffer_->params));
2804 case LFUN_INSET_MINIPAGE:
2805 insertAndEditInset(new InsetMinipage(buffer_->params));
2808 case LFUN_INSERT_NOTE:
2809 insertAndEditInset(new InsetNote(buffer_->params));
2812 case LFUN_INSET_FLOAT:
2813 // check if the float type exist
2814 if (floatList.typeExist(argument)) {
2815 insertAndEditInset(new InsetFloat(buffer_->params,
2818 lyxerr << "Non-existent float type: "
2819 << argument << endl;
2823 case LFUN_INSET_WIDE_FLOAT:
2825 // check if the float type exist
2826 if (floatList.typeExist(argument)) {
2827 InsetFloat * new_inset =
2828 new InsetFloat(buffer_->params, argument);
2829 new_inset->wide(true);
2830 if (insertInset(new_inset))
2831 new_inset->edit(bv_);
2835 lyxerr << "Non-existent float type: "
2836 << argument << endl;
2843 case LFUN_INSET_LIST:
2844 insertAndEditInset(new InsetList);
2847 case LFUN_INSET_THEOREM:
2848 insertAndEditInset(new InsetTheorem);
2852 case LFUN_INSET_CAPTION:
2854 // Do we have a locking inset...
2855 if (bv_->theLockingInset()) {
2856 lyxerr << "Locking inset code: "
2857 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2858 InsetCaption * new_inset =
2859 new InsetCaption(buffer_->params);
2860 new_inset->setOwner(bv_->theLockingInset());
2861 new_inset->setAutoBreakRows(true);
2862 new_inset->setDrawFrame(0, InsetText::LOCKED);
2863 new_inset->setFrameColor(0, LColor::captionframe);
2864 if (insertInset(new_inset))
2865 new_inset->edit(bv_);
2872 case LFUN_INSET_TABULAR:
2876 if (!argument.empty())
2877 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2878 InsetTabular * new_inset =
2879 new InsetTabular(*buffer_, r, c);
2881 bv_->getLyXText()->real_current_font.isRightToLeft();
2882 if (!open_new_inset(new_inset, rtl))
2887 // --- lyxserver commands ----------------------------
2889 case LFUN_CHARATCURSOR:
2891 pos_type pos = bv_->getLyXText()->cursor.pos();
2892 if (pos < bv_->getLyXText()->cursor.par()->size())
2893 owner_->getLyXFunc()->setMessage(
2894 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2896 owner_->getLyXFunc()->setMessage("EOF");
2901 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2903 + tostr(bv_->getLyXText()->cursor.y()));
2910 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2911 lyxerr << "SETXY: Could not parse coordinates in '"
2912 << argument << std::endl;
2914 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2918 case LFUN_GETLAYOUT:
2919 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2924 LyXFont & font = bv_->getLyXText()->current_font;
2925 if (font.shape() == LyXFont::ITALIC_SHAPE)
2926 owner_->getLyXFunc()->setMessage("E");
2927 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2928 owner_->getLyXFunc()->setMessage("N");
2930 owner_->getLyXFunc()->setMessage("0");
2935 // --- accented characters ---------------------------
2938 case LFUN_CIRCUMFLEX:
2948 case LFUN_SPECIAL_CARON:
2951 case LFUN_HUNG_UMLAUT:
2954 if (argument.empty()) {
2956 owner_->getLyXFunc()->handleKeyFunc(action);
2958 owner_->getLyXFunc()->handleKeyFunc(action);
2959 owner_->getIntl()->getTrans()
2960 .TranslateAndInsert(argument[0], bv_->getLyXText());
2961 update(bv_->getLyXText(),
2963 | BufferView::FITCUR
2964 | BufferView::CHANGE);
2968 case LFUN_MATH_MACRO:
2969 mathDispatchMathMacro(bv_, argument);
2972 case LFUN_MATH_DELIM:
2973 mathDispatchMathDelim(bv_, argument);
2976 case LFUN_INSERT_MATRIX:
2977 mathDispatchInsertMatrix(bv_, argument);
2980 case LFUN_INSERT_MATH:
2981 mathDispatchInsertMath(bv_, argument);
2984 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2985 mathDispatchMathImportSelection(bv_, argument);
2988 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2989 mathDispatchMathDisplay(bv_, argument);
2992 case LFUN_MATH_MODE: // Open or create an inlined math inset
2993 mathDispatchMathMode(bv_, argument);
2996 case LFUN_GREEK: // Insert a single greek letter
2997 mathDispatchGreek(bv_, argument);
3000 case LFUN_CITATION_INSERT:
3002 InsetCommandParams p;
3003 p.setFromString(argument);
3005 InsetCitation * inset = new InsetCitation(p);
3006 if (!insertInset(inset))
3009 updateInset(inset, true);
3013 case LFUN_INSERT_BIBTEX:
3015 // ale970405+lasgoutt970425
3016 // The argument can be up to two tokens separated
3017 // by a space. The first one is the bibstyle.
3018 string const db = token(argument, ' ', 0);
3019 string const bibstyle = token(argument, ' ', 1);
3021 InsetCommandParams p("BibTeX", db, bibstyle);
3022 InsetBibtex * inset = new InsetBibtex(p);
3024 if (insertInset(inset)) {
3025 if (argument.empty())
3032 // BibTeX data bases
3033 case LFUN_BIBDB_ADD:
3035 InsetBibtex * inset =
3036 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3038 inset->addDatabase(argument);
3043 case LFUN_BIBDB_DEL:
3045 InsetBibtex * inset =
3046 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3048 inset->delDatabase(argument);
3053 case LFUN_BIBTEX_STYLE:
3055 InsetBibtex * inset =
3056 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3058 inset->setOptions(argument);
3063 case LFUN_INDEX_CREATE:
3065 InsetCommandParams p("index");
3066 if (argument.empty()) {
3067 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3068 p.setContents(idxstring);
3070 p.setContents(argument);
3073 owner_->getDialogs()->createIndex(p.getAsString());
3077 case LFUN_INDEX_INSERT:
3079 InsetCommandParams p;
3080 p.setFromString(argument);
3081 InsetIndex * inset = new InsetIndex(p);
3083 if (!insertInset(inset))
3086 updateInset(inset, true);
3090 case LFUN_INDEX_INSERT_LAST:
3092 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3093 if (!idxstring.empty()) {
3094 owner_->message(_("Word `")
3095 + idxstring + _(("' indexed.")));
3096 InsetCommandParams p("index", idxstring);
3097 InsetIndex * inset = new InsetIndex(p);
3099 if (!insertInset(inset))
3102 updateInset(inset, true);
3107 case LFUN_INDEX_PRINT:
3109 InsetCommandParams p("printindex");
3110 Inset * inset = new InsetPrintIndex(p);
3111 if (!insertInset(inset, "Standard"))
3116 case LFUN_PARENTINSERT:
3118 InsetCommandParams p("lyxparent", argument);
3119 Inset * inset = new InsetParent(p, *buffer_);
3120 if (!insertInset(inset, "Standard"))
3126 case LFUN_CHILD_INSERT:
3128 InsetInclude::Params p;
3129 p.cparams.setFromString(argument);
3130 p.masterFilename_ = buffer_->fileName();
3132 InsetInclude * inset = new InsetInclude(p);
3133 if (!insertInset(inset))
3136 updateInset(inset, true);
3137 bv_->owner()->getDialogs()->showInclude(inset);
3142 case LFUN_FLOAT_LIST:
3144 // We should check the argument for validity. (Lgb)
3145 Inset * inset = new InsetFloatList(argument);
3146 if (!insertInset(inset, "Standard"))
3151 case LFUN_THESAURUS_ENTRY:
3153 string arg = argument;
3156 arg = bv_->getLyXText()->selectionAsString(buffer_,
3160 if (arg.size() > 100 || arg.empty()) {
3161 // Get word or selection
3162 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3163 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3164 // FIXME: where is getLyXText()->unselect(bv_) ?
3168 bv_->owner()->getDialogs()->showThesaurus(arg);
3172 case LFUN_SELFINSERT:
3174 if (argument.empty()) break;
3176 /* Automatically delete the currently selected
3177 * text and replace it with what is being
3178 * typed in now. Depends on lyxrc settings
3179 * "auto_region_delete", which defaults to
3182 LyXText * lt = bv_->getLyXText();
3184 if (lyxrc.auto_region_delete) {
3185 if (lt->selection.set()) {
3186 lt->cutSelection(bv_, false, false);
3189 | BufferView::FITCUR
3190 | BufferView::CHANGE);
3192 workarea_.haveSelection(false);
3196 LyXFont const old_font(lt->real_current_font);
3198 string::const_iterator cit = argument.begin();
3199 string::const_iterator end = argument.end();
3200 for (; cit != end; ++cit) {
3201 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3206 | BufferView::FITCUR
3207 | BufferView::CHANGE);
3209 lt->selection.cursor = lt->cursor;
3210 moveCursorUpdate(false);
3212 // real_current_font.number can change so we need to
3213 // update the minibuffer
3214 if (old_font != lt->real_current_font)
3215 owner_->showState();
3220 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3222 time_t now_time_t = time(NULL);
3223 struct tm * now_tm = localtime(&now_time_t);
3224 setlocale(LC_TIME, "");
3226 if (!argument.empty())
3229 arg = lyxrc.date_insert_format;
3231 int const datetmp_len =
3232 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3234 LyXText * lt = bv_->getLyXText();
3236 for (int i = 0; i < datetmp_len; i++) {
3237 lt->insertChar(bv_, datetmp[i]);
3240 | BufferView::FITCUR
3241 | BufferView::CHANGE);
3244 lt->selection.cursor = lt->cursor;
3245 moveCursorUpdate(false);
3249 case LFUN_UNKNOWN_ACTION:
3250 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3261 void BufferView::Pimpl::newline()
3264 LyXText * lt = bv_->getLyXText();
3268 | BufferView::FITCUR);
3269 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3272 | BufferView::FITCUR
3273 | BufferView::CHANGE);
3278 void BufferView::Pimpl::hfill()
3281 LyXText * lt = bv_->getLyXText();
3285 | BufferView::FITCUR);
3286 lt->insertChar(bv_, Paragraph::META_HFILL);
3289 | BufferView::FITCUR
3290 | BufferView::CHANGE);
3295 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3298 LyXText * lt = bv_->getLyXText();
3301 update(lt, BufferView::SELECT|BufferView::FITCUR);
3302 InsetSpecialChar * new_inset =
3303 new InsetSpecialChar(kind);
3304 if (!insertInset(new_inset))
3307 updateInset(new_inset, true);
3312 void BufferView::Pimpl::smartQuote()
3314 LyXText const * lt = bv_->getLyXText();
3315 Paragraph const * par = lt->cursor.par();
3316 pos_type pos = lt->cursor.pos();
3320 || (par->isInset(pos - 1)
3321 && par->getInset(pos - 1)->isSpace()))
3324 c = par->getChar(pos - 1);
3329 LyXLayout const & style =
3330 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3332 if (style.pass_thru ||
3333 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3334 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3338 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3340 if (insertInset(inset))
3347 // Open and lock an updatable inset
3348 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3350 LyXText * lt = bv_->getLyXText();
3354 if (!insertInset(new_inset)) {
3358 new_inset->edit(bv_, !behind);
3363 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3365 // if we are in a locking inset we should try to insert the
3366 // inset there otherwise this is a illegal function now
3367 if (bv_->theLockingInset()) {
3368 if (bv_->theLockingInset()->insetAllowed(inset))
3369 return bv_->theLockingInset()->insertInset(bv_, inset);
3373 // not quite sure if we want this...
3374 setCursorParUndo(bv_);
3377 beforeChange(bv_->text);
3378 if (!lout.empty()) {
3379 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3380 bv_->text->breakParagraph(bv_);
3381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3383 if (bv_->text->cursor.par()->size()) {
3384 bv_->text->cursorLeft(bv_);
3386 bv_->text->breakParagraph(bv_);
3387 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3391 LyXTextClass const & tclass =
3392 textclasslist[buffer_->params.textclass];
3393 bool hasLayout = tclass.hasLayout(lres);
3394 string lay = tclass.defaultLayoutName();
3396 if (hasLayout != false) {
3400 // layout not fount using default
3401 lay = tclass.defaultLayoutName();
3404 bv_->text->setLayout(bv_, lay);
3406 bv_->text->setParagraph(bv_, 0, 0,
3408 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3413 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3416 bv_->text->insertInset(bv_, inset);
3417 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3424 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3426 if (!inset || !available())
3429 // first check for locking insets
3430 if (bv_->theLockingInset()) {
3431 if (bv_->theLockingInset() == inset) {
3432 if (bv_->text->updateInset(bv_, inset)) {
3435 buffer_->markDirty();
3440 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3441 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3444 buffer_->markDirty();
3452 // then check if the inset is a top_level inset (has no owner)
3453 // if yes do the update as always otherwise we have to update the
3454 // toplevel inset where this inset is inside
3455 Inset * tl_inset = inset;
3456 while(tl_inset->owner())
3457 tl_inset = tl_inset->owner();
3459 if (tl_inset == inset) {
3460 update(bv_->text, BufferView::UPDATE);
3461 if (bv_->text->updateInset(bv_, inset)) {
3465 | BufferView::FITCUR
3466 | BufferView::CHANGE);
3468 update(bv_->text, SELECT);
3472 } else if (static_cast<UpdatableInset *>(tl_inset)
3473 ->updateInsetInInset(bv_, inset))
3475 if (bv_->text->updateInset(bv_, tl_inset)) {
3483 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3486 if (!available()) return;
3489 beforeChange(bv_->text);
3490 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3492 LyXCursor const & cursor = bv_->text->cursor;
3496 cursor.par()->isInset(cursor.pos())) {
3497 Inset const * inset = cursor.par()->getInset(cursor.pos());
3498 if (find(codes.begin(), codes.end(), inset->lyxCode())
3501 static_cast<InsetCommand const *>(inset)->getContents();
3505 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3506 if (bv_->text->cursor.pos()
3507 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3508 LyXCursor tmp = bv_->text->cursor;
3509 bv_->text->cursor.par(bv_->text->ownerParagraph());
3510 bv_->text->cursor.pos(0);
3511 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3512 bv_->text->cursor = tmp;
3513 bv_->owner()->message(_("No more insets"));
3516 bv_->owner()->message(_("No more insets"));
3519 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3520 bv_->text->selection.cursor = bv_->text->cursor;
3524 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3526 gotoInset(vector<Inset::Code>(1, code), same_content);