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_) return 0;
480 if (!screen_.get()) return 0;
482 double value = workarea_.getScrollbarValue();
484 if (value == 0) return 0;
486 float add_value = (bv_->text->defaultHeight()
487 + float(time) * float(time) * 0.125);
489 if (add_value > workarea_.height())
490 add_value = float(workarea_.height() -
491 bv_->text->defaultHeight());
498 workarea_.setScrollbarValue(value);
505 int BufferView::Pimpl::scrollDown(long time)
507 if (!buffer_) return 0;
508 if (!screen_.get()) return 0;
510 double value = workarea_.getScrollbarValue();
511 pair<float, float> p = workarea_.getScrollbarBounds();
512 double const max = p.second;
514 if (value == max) return 0;
516 float add_value = (bv_->text->defaultHeight()
517 + float(time) * float(time) * 0.125);
519 if (add_value > workarea_.height())
520 add_value = float(workarea_.height() -
521 bv_->text->defaultHeight());
528 workarea_.setScrollbarValue(value);
535 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
537 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
541 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
543 // Only use motion with button 1
544 if (!(state & Button1MotionMask))
547 if (!buffer_ || !screen_.get()) return;
549 // Check for inset locking
550 if (bv_->theLockingInset()) {
551 LyXCursor cursor = bv_->text->cursor;
552 LyXFont font = bv_->text->getFont(buffer_,
553 cursor.par(), cursor.pos());
554 int width = bv_->theLockingInset()->width(bv_, font);
555 int inset_x = font.isVisibleRightToLeft()
556 ? cursor.ix() - width : cursor.ix();
557 int start_x = inset_x + bv_->theLockingInset()->scroll();
558 bv_->theLockingInset()->
559 insetMotionNotify(bv_,
561 y - cursor.iy() + bv_->text->first_y,
566 /* The test for not selection possible is needed, that only motion
567 events are used, where the bottom press event was on
568 the drawing area too */
569 if (!selection_possible)
572 screen_->hideCursor();
574 int y_before = bv_->text->cursor.y();
576 Row * cursorrow = bv_->text->cursor.row();
577 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
579 // sorry for this but I have a strange error that the y value jumps at
580 // a certain point. This seems like an error in my xforms library or
581 // in some other local environment, but I would like to leave this here
582 // for the moment until I can remove this (Jug 20020418)
583 if (y_before < bv_->text->cursor.y())
584 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
586 // This is to allow jumping over large insets
587 if (cursorrow == bv_->text->cursor.row()) {
588 if (y >= int(workarea_.height())) {
589 bv_->text->cursorDown(bv_, false);
591 bv_->text->cursorUp(bv_, false);
595 if (!bv_->text->selection.set())
596 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
598 bv_->text->setSelection(bv_);
599 screen_->toggleToggle(bv_->text, bv_);
605 // Single-click on work area
606 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
609 if (!buffer_ || !screen_.get())
612 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
614 // ok ok, this is a hack.
615 if (button == 4 || button == 5) {
618 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
621 scrollDown(lyxrc.wheel_jump);
626 // Middle button press pastes if we have a selection
627 // We do this here as if the selection was inside an inset
628 // it could get cleared on the unlocking of the inset so
629 // we have to check this first
630 bool paste_internally = false;
631 if (button == 2 && bv_->getLyXText()->selection.set()) {
632 owner_->getLyXFunc()->dispatch(LFUN_COPY);
633 paste_internally = true;
636 int const screen_first = bv_->text->first_y;
638 if (bv_->theLockingInset()) {
639 // We are in inset locking mode
641 /* Check whether the inset was hit. If not reset mode,
642 otherwise give the event to the inset */
643 if (inset_hit == bv_->theLockingInset()) {
644 bv_->theLockingInset()->
645 insetButtonPress(bv_,xpos, ypos,button);
648 bv_->unlockInset(bv_->theLockingInset());
653 selection_possible = true;
654 screen_->hideCursor();
656 // Clear the selection
657 screen_->toggleSelection(bv_->text, bv_);
658 bv_->text->clearSelection();
659 bv_->text->fullRebreak(bv_);
663 // Single left click in math inset?
664 if (isHighlyEditableInset(inset_hit)) {
665 // Highly editable inset, like math
666 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
667 selection_possible = false;
668 owner_->updateLayoutChoice();
669 owner_->message(inset->editMessage());
670 //inset->edit(bv_, xpos, ypos, button);
671 // We just have to lock the inset before calling a PressEvent on it!
672 // we don't need the edit() call here! (Jug20020329)
673 if (!bv_->lockInset(inset)) {
674 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
676 inset->insetButtonPress(bv_, xpos, ypos, button);
679 // I'm not sure we should continue here if we hit an inset (Jug20020403)
681 // Right click on a footnote flag opens float menu
683 selection_possible = false;
687 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
688 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
690 bv_->text->selection.cursor = bv_->text->cursor;
691 bv_->text->cursor.x_fix(bv_->text->cursor.x());
693 owner_->updateLayoutChoice();
695 selection_possible = false;
698 // Insert primary selection with middle mouse
699 // if there is a local selection in the current buffer,
702 if (paste_internally)
703 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
705 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
707 selection_possible = false;
713 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
719 LyXText * text = bv_->getLyXText();
721 if (text->bv_owner && bv_->theLockingInset())
724 if (screen_.get() && button == 1) {
725 if (text->bv_owner) {
726 screen_->hideCursor();
727 screen_->toggleSelection(text, bv_);
728 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
729 screen_->toggleSelection(text, bv_, false);
731 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
733 /* This will fit the cursor on the screen
735 update(text, BufferView::SELECT|BufferView::FITCUR);
740 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
746 LyXText * text = bv_->getLyXText();
748 if (text->bv_owner && bv_->theLockingInset())
751 if (screen_.get() && (button == 1)) {
752 if (text->bv_owner) {
753 screen_->hideCursor();
754 screen_->toggleSelection(text, bv_);
756 text->cursorHome(bv_);
757 text->selection.cursor = text->cursor;
758 text->cursorEnd(bv_);
759 text->setSelection(bv_);
760 if (text->bv_owner) {
761 screen_->toggleSelection(text, bv_, false);
763 /* This will fit the cursor on the screen
765 update(text, BufferView::SELECT|BufferView::FITCUR);
770 void BufferView::Pimpl::selectionRequested()
777 LyXText * text = bv_->getLyXText();
779 if (text->selection.set() &&
780 (!bv_->text->xsel_cache.set() ||
781 text->selection.start != bv_->text->xsel_cache.start ||
782 text->selection.end != bv_->text->xsel_cache.end))
784 bv_->text->xsel_cache = text->selection;
785 sel = text->selectionAsString(bv_->buffer(), false);
786 } else if (!text->selection.set()) {
788 bv_->text->xsel_cache.set(false);
791 workarea_.putClipboard(sel);
796 void BufferView::Pimpl::selectionLost()
798 if (active() && available()) {
801 bv_->getLyXText()->clearSelection();
803 bv_->text->xsel_cache.set(false);
808 void BufferView::Pimpl::enterView()
810 if (active() && available()) {
811 SetXtermCursor(workarea_.getWin());
812 using_xterm_cursor = true;
817 void BufferView::Pimpl::leaveView()
819 if (using_xterm_cursor) {
820 XUndefineCursor(fl_get_display(), workarea_.getWin());
821 using_xterm_cursor = false;
826 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
829 if (!buffer_ || !screen_.get()) return;
831 // If we hit an inset, we have the inset coordinates in these
832 // and inset_hit points to the inset. If we do not hit an
833 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
834 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
836 if (bv_->theLockingInset()) {
837 // We are in inset locking mode.
839 /* LyX does a kind of work-area grabbing for insets.
840 Only a ButtonPress Event outside the inset will
841 force a insetUnlock. */
842 bv_->theLockingInset()->
843 insetButtonRelease(bv_, x, y, button);
847 selection_possible = false;
854 workarea_.haveSelection(bv_->getLyXText()->selection.set());
859 owner_->updateMenubar();
860 owner_->updateToolbar();
862 // Did we hit an editable inset?
864 selection_possible = false;
866 // if we reach this point with a selection, it
867 // must mean we are currently selecting.
868 // But we don't want to open the inset
869 // because that is annoying for the user.
870 // So just pretend we didn't hit it.
871 // this is OK because a "kosher" ButtonRelease
872 // will follow a ButtonPress that clears
874 // Note this also fixes selection drawing
875 // problems if we end up opening an inset
876 if (bv_->getLyXText()->selection.set())
879 // CHECK fix this proper in 0.13
880 // well, maybe 13.0 !!!!!!!!!
882 // Following a ref shouldn't issue
883 // a push on the undo-stack
884 // anylonger, now that we have
885 // keybindings for following
886 // references and returning from
887 // references. IMHO though, it
888 // should be the inset's own business
889 // to push or not push on the undo
890 // stack. They don't *have* to
891 // alter the document...
893 // ...or maybe the SetCursorParUndo()
894 // below isn't necessary at all anylonger?
895 if (inset_hit->lyxCode() == Inset::REF_CODE) {
896 setCursorParUndo(bv_);
899 owner_->message(inset_hit->editMessage());
901 if (isHighlyEditableInset(inset_hit)) {
902 // Highly editable inset, like math
903 UpdatableInset *inset = (UpdatableInset *)inset_hit;
904 inset->insetButtonRelease(bv_, x, y, button);
906 inset_hit->insetButtonRelease(bv_, x, y, button);
907 // IMO this is a grosshack! Inset's should be changed so that
908 // they call the actions they have to do with the insetButtonRel.
909 // function and not in the edit(). This should be changed
911 inset_hit->edit(bv_, x, y, button);
916 // Maybe we want to edit a bibitem ale970302
917 if (bv_->text->cursor.par()->bibkey && x < 20 +
918 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
919 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
926 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
927 LyXCursor const & cursor) const
929 Paragraph /*const*/ & par = *cursor.par();
930 pos_type const pos = cursor.pos();
932 lyx::Assert(par.getInset(pos));
934 Inset const & inset(*par.getInset(pos));
936 LyXFont const & font = text.getFont(buffer_, &par, pos);
938 int const width = inset.width(bv_, font);
939 int const inset_x = font.isVisibleRightToLeft()
940 ? (cursor.ix() - width) : cursor.ix();
943 inset_x + inset.scroll(),
945 cursor.iy() - inset.ascent(bv_, font),
946 cursor.iy() + inset.descent(bv_, font));
950 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
951 LyXCursor const & cursor,
952 int & x, int & y) const
954 pos_type const pos(cursor.pos());
955 Paragraph /*const*/ & par(*cursor.par());
957 if (pos >= par.size() || !par.isInset(pos)) {
961 Inset /*const*/ * inset = par.getInset(pos);
963 if (!isEditableInset(inset)) {
967 Box b(insetDimensions(text, cursor));
969 if (!b.contained(x, y)) {
970 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
971 << " box " << b << endl;
975 text.setCursor(bv_, &par, pos, true);
978 // The origin of an inset is on the baseline
979 y -= text.cursor.iy();
985 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
990 int y_tmp = y + text->first_y;
993 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
995 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1002 // look at previous position
1004 if (cursor.pos() == 0) {
1009 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1011 inset = checkInset(*text, cursor, x, y_tmp);
1019 void BufferView::Pimpl::workAreaExpose()
1021 static int work_area_width;
1022 static unsigned int work_area_height;
1024 bool const widthChange = workarea_.workWidth() != work_area_width;
1025 bool const heightChange = workarea_.height() != work_area_height;
1027 // update from work area
1028 work_area_width = workarea_.workWidth();
1029 work_area_height = workarea_.height();
1032 // The visible LyXView need a resize
1035 // Remove all texts from the textcache
1036 // This is not _really_ what we want to do. What
1037 // we really want to do is to delete in textcache
1038 // that does not have a BufferView with matching
1039 // width, but as long as we have only one BufferView
1040 // deleting all gives the same result.
1041 if (lyxerr.debugging())
1042 textcache.show(lyxerr, "Expose delete all");
1044 buffer_->resizeInsets(bv_);
1045 } else if (heightChange) {
1046 // Rebuild image of current screen
1048 // fitCursor() ensures we don't jump back
1049 // to the start of the document on vertical
1053 // The main window size has changed, repaint most stuff
1055 } else if (screen_.get())
1056 screen_->redraw(bv_->text, bv_);
1058 // Grey box when we don't have a buffer
1059 workarea_.greyOut();
1062 // always make sure that the scrollbar is sane.
1064 owner_->updateLayoutChoice();
1069 void BufferView::Pimpl::update()
1071 if (screen_.get() &&
1072 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1074 LyXText::text_status st = bv_->text->status();
1075 screen_->update(bv_->text, bv_);
1077 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1078 if (bv_->text->fullRebreak(bv_)) {
1079 st = LyXText::NEED_MORE_REFRESH;
1080 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1081 bv_->text->cursor.pos());
1082 if (bv_->text->selection.set()) {
1083 bv_->text->setCursor(bv_, bv_->text->selection.start,
1084 bv_->text->selection.start.par(),
1085 bv_->text->selection.start.pos());
1086 bv_->text->setCursor(bv_, bv_->text->selection.end,
1087 bv_->text->selection.end.par(),
1088 bv_->text->selection.end.pos());
1092 bv_->text->status(bv_, st);
1093 screen_->update(bv_->text, bv_);
1095 // do this here instead of in the screen::update because of
1097 bv_->text->status(bv_, LyXText::UNCHANGED);
1103 // Values used when calling update:
1105 // -2 - update, move sel_cursor if selection, fitcursor
1106 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1107 // 0 - update, move sel_cursor if selection, fitcursor
1108 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1109 // 3 - update, move sel_cursor if selection
1112 // a simple redraw of the parts that need refresh
1114 // move sel_cursor if selection -
1115 // the text's sel_cursor is moved if there is selection is progress
1118 // fitCursor() is called and the scrollbar updated
1121 // the buffer is marked dirty.
1130 // UPDATE_ONLY = UPDATE;
1131 // UPDATE_SELECT = UPDATE | SELECT;
1132 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1133 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1135 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1136 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1137 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1138 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1139 // update(3) -> update(1) -> update(1) -> update(SELECT)
1141 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1143 owner_->updateLayoutChoice();
1145 if (!text->selection.set() && (f & SELECT)) {
1146 text->selection.cursor = text->cursor;
1149 text->fullRebreak(bv_);
1151 if (text->inset_owner) {
1152 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1153 updateInset(text->inset_owner, false);
1163 buffer_->markDirty();
1168 // Callback for cursor timer
1169 void BufferView::Pimpl::cursorToggle()
1172 cursor_timeout.restart();
1176 if (!screen_.get()) {
1177 cursor_timeout.restart();
1182 extern void reapSpellchecker(void);
1185 if (!bv_->theLockingInset()) {
1186 screen_->cursorToggle(bv_);
1188 bv_->theLockingInset()->toggleInsetCursor(bv_);
1191 cursor_timeout.restart();
1195 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1197 if (!text->cursor.row()->previous()) {
1198 if (text->first_y > 0) {
1199 int new_y = bv_->text->first_y - workarea_.height();
1200 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1206 int y = text->first_y;
1207 Row * cursorrow = text->cursor.row();
1209 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1213 if (cursorrow == bv_->text->cursor.row()) {
1214 // we have a row which is higher than the workarea so we leave the
1215 // cursor on the start of the row and move only the draw up as soon
1216 // as we move the cursor or do something while inside the row (it may
1217 // span several workarea-heights) we'll move to the top again, but this
1218 // is better than just jump down and only display part of the row.
1219 new_y = bv_->text->first_y - workarea_.height();
1221 if (text->inset_owner) {
1222 new_y = bv_->text->cursor.iy()
1223 + bv_->theLockingInset()->insetInInsetY() + y
1224 + text->cursor.row()->height()
1225 - workarea_.height() + 1;
1227 new_y = text->cursor.y()
1228 - text->cursor.row()->baseline()
1229 + text->cursor.row()->height()
1230 - workarea_.height() + 1;
1233 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1234 if (text->cursor.row()->previous()) {
1236 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1237 text->cursor.row()->previous()->pos(), false);
1238 if (cur.y() > text->first_y) {
1239 text->cursorUp(bv_, true);
1246 void BufferView::Pimpl::cursorNext(LyXText * text)
1248 if (!text->cursor.row()->next()) {
1249 int y = text->cursor.y() - text->cursor.row()->baseline() +
1250 text->cursor.row()->height();
1251 if (y > int(text->first_y + workarea_.height())) {
1252 screen_->draw(bv_->text, bv_,
1253 bv_->text->first_y + workarea_.height());
1259 int y = text->first_y + workarea_.height();
1260 if (text->inset_owner && !text->first_y) {
1261 y -= (bv_->text->cursor.iy()
1262 - bv_->text->first_y
1263 + bv_->theLockingInset()->insetInInsetY());
1265 text->getRowNearY(y);
1267 Row * cursorrow = text->cursor.row();
1268 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1271 if (cursorrow == bv_->text->cursor.row()) {
1272 // we have a row which is higher than the workarea so we leave the
1273 // cursor on the start of the row and move only the draw down as soon
1274 // as we move the cursor or do something while inside the row (it may
1275 // span several workarea-heights) we'll move to the top again, but this
1276 // is better than just jump down and only display part of the row.
1277 new_y = bv_->text->first_y + workarea_.height();
1279 if (text->inset_owner) {
1280 new_y = bv_->text->cursor.iy()
1281 + bv_->theLockingInset()->insetInInsetY()
1282 + y - text->cursor.row()->baseline();
1284 new_y = text->cursor.y() - text->cursor.row()->baseline();
1287 screen_->draw(bv_->text, bv_, new_y);
1288 if (text->cursor.row()->next()) {
1290 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1291 text->cursor.row()->next()->pos(), false);
1292 if (cur.y() < int(text->first_y + workarea_.height())) {
1293 text->cursorDown(bv_, true);
1300 bool BufferView::Pimpl::available() const
1302 if (buffer_ && bv_->text)
1308 void BufferView::Pimpl::beforeChange(LyXText * text)
1311 text->clearSelection();
1315 void BufferView::Pimpl::savePosition(unsigned int i)
1317 if (i >= saved_positions_num)
1319 saved_positions[i] = Position(buffer_->fileName(),
1320 bv_->text->cursor.par()->id(),
1321 bv_->text->cursor.pos());
1324 str << _("Saved bookmark") << ' ' << i;
1325 owner_->message(str.str().c_str());
1330 void BufferView::Pimpl::restorePosition(unsigned int i)
1332 if (i >= saved_positions_num)
1335 string const fname = saved_positions[i].filename;
1337 beforeChange(bv_->text);
1339 if (fname != buffer_->fileName()) {
1340 Buffer * b = bufferlist.exists(fname) ?
1341 bufferlist.getBuffer(fname) :
1342 bufferlist.loadLyXFile(fname); // don't ask, just load it
1343 if (b != 0) buffer(b);
1346 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1350 bv_->text->setCursor(bv_, par,
1351 min(par->size(), saved_positions[i].par_pos));
1353 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1356 str << _("Moved to bookmark") << ' ' << i;
1357 owner_->message(str.str().c_str());
1362 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1364 if (i >= saved_positions_num)
1367 return !saved_positions[i].filename.empty();
1371 void BufferView::Pimpl::setState()
1373 if (!lyxrc.rtl_support)
1376 LyXText * text = bv_->getLyXText();
1377 if (text->real_current_font.isRightToLeft()) {
1378 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1379 owner_->getIntl()->KeyMapSec();
1381 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1382 owner_->getIntl()->KeyMapPrim();
1388 void BufferView::Pimpl::insetSleep()
1390 if (bv_->theLockingInset() && !inset_slept) {
1391 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1392 bv_->theLockingInset()->insetUnlock(bv_);
1398 void BufferView::Pimpl::insetWakeup()
1400 if (bv_->theLockingInset() && inset_slept) {
1401 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1402 inset_slept = false;
1408 void BufferView::Pimpl::insetUnlock()
1410 if (bv_->theLockingInset()) {
1412 bv_->theLockingInset()->insetUnlock(bv_);
1413 bv_->theLockingInset(0);
1415 inset_slept = false;
1420 bool BufferView::Pimpl::focus() const
1422 return workarea_.hasFocus();
1426 void BufferView::Pimpl::focus(bool f)
1428 if (f) workarea_.setFocus();
1432 bool BufferView::Pimpl::active() const
1434 return workarea_.active();
1438 bool BufferView::Pimpl::belowMouse() const
1440 return workarea_.belowMouse();
1444 void BufferView::Pimpl::showCursor()
1446 if (screen_.get()) {
1447 if (bv_->theLockingInset())
1448 bv_->theLockingInset()->showInsetCursor(bv_);
1450 screen_->showCursor(bv_->text, bv_);
1455 void BufferView::Pimpl::hideCursor()
1457 if (screen_.get()) {
1458 if (!bv_->theLockingInset())
1459 // bv_->theLockingInset()->hideInsetCursor(bv_);
1461 screen_->hideCursor();
1466 void BufferView::Pimpl::toggleSelection(bool b)
1468 if (screen_.get()) {
1469 if (bv_->theLockingInset())
1470 bv_->theLockingInset()->toggleSelection(bv_, b);
1471 screen_->toggleSelection(bv_->text, bv_, b);
1476 void BufferView::Pimpl::toggleToggle()
1479 screen_->toggleToggle(bv_->text, bv_);
1483 void BufferView::Pimpl::center()
1485 beforeChange(bv_->text);
1486 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1487 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1489 screen_->draw(bv_->text, bv_, 0);
1491 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1496 void BufferView::Pimpl::pasteClipboard(bool asPara)
1501 screen_->hideCursor();
1502 beforeChange(bv_->text);
1504 string const clip(workarea_.getClipboard());
1510 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1512 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1514 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1518 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1520 workarea_.putClipboard(stuff);
1525 * Dispatch functions for actions which can be valid for BufferView->text
1526 * and/or InsetText->text!!!
1531 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1533 LyXText * lt = bv_->getLyXText();
1535 if (selecting || lt->selection.mark()) {
1536 lt->setSelection(bv_);
1540 updateInset(lt->inset_owner, false);
1544 update(lt, BufferView::SELECT|BufferView::FITCUR);
1546 update(lt, BufferView::SELECT);
1550 if (!lt->selection.set())
1551 workarea_.haveSelection(false);
1553 /* ---> Everytime the cursor is moved, show the current font state. */
1554 // should this too me moved out of this func?
1555 //owner->showState();
1560 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1562 LyXCursor cursor = bv_->getLyXText()->cursor;
1563 Buffer::inset_iterator it =
1564 find_if(Buffer::inset_iterator(
1565 cursor.par(), cursor.pos()),
1566 buffer_->inset_iterator_end(),
1567 lyx::compare_memfun(&Inset::lyxCode, code));
1568 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1572 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1574 string filename = filen;
1576 if (filename.empty()) {
1577 // Launch a file browser
1578 string initpath = lyxrc.document_path;
1581 string const trypath = owner_->buffer()->filePath();
1582 // If directory is writeable, use this as default.
1583 if (IsDirWriteable(trypath))
1587 FileDialog fileDlg(bv_->owner(),
1588 _("Select LyX document to insert"),
1590 make_pair(string(_("Documents|#o#O")),
1591 string(lyxrc.document_path)),
1592 make_pair(string(_("Examples|#E#e")),
1593 string(AddPath(system_lyxdir, "examples"))));
1595 FileDialog::Result result =
1596 fileDlg.Select(initpath,
1597 _("*.lyx| LyX Documents (*.lyx)"));
1599 if (result.first == FileDialog::Later)
1602 filename = result.second;
1604 // check selected filename
1605 if (filename.empty()) {
1606 owner_->message(_("Canceled."));
1611 // get absolute path of file and add ".lyx" to the filename if
1613 filename = FileSearch(string(), filename, "lyx");
1615 string const disp_fn(MakeDisplayPath(filename));
1618 s1 << _("Inserting document") << ' '
1619 << disp_fn << " ...";
1620 owner_->message(s1.str().c_str());
1621 bool const res = bv_->insertLyXFile(filename);
1624 str << _("Document") << ' ' << disp_fn
1625 << ' ' << _("inserted.");
1626 owner_->message(str.str().c_str());
1629 str << _("Could not insert document") << ' '
1631 owner_->message(str.str().c_str());
1636 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1638 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1639 << action <<"] arg[" << argument << "]" << endl;
1642 // --- Misc -------------------------------------------
1646 LyXText * lt = bv_->getLyXText();
1647 lt->toggleAppendix(bv_);
1650 | BufferView::FITCUR
1651 | BufferView::CHANGE);
1656 case LFUN_TOC_INSERT:
1658 InsetCommandParams p;
1659 p.setCmdName("tableofcontents");
1660 Inset * inset = new InsetTOC(p);
1661 if (!insertInset(inset, "Standard"))
1666 case LFUN_SCROLL_INSET:
1667 // this is not handled here as this funktion is only aktive
1668 // if we have a locking_inset and that one is (or contains)
1672 case LFUN_INSET_GRAPHICS:
1674 Inset * new_inset = new InsetGraphics;
1675 if (!insertInset(new_inset)) {
1678 // this is need because you don't use a inset->Edit()
1679 updateInset(new_inset, true);
1680 new_inset->edit(bv_);
1690 case LFUN_PASTESELECTION:
1692 bool asPara = false;
1693 if (argument == "paragraph")
1695 pasteClipboard(asPara);
1707 case LFUN_LAYOUT_COPY:
1708 bv_->copyEnvironment();
1711 case LFUN_LAYOUT_PASTE:
1712 bv_->pasteEnvironment();
1716 case LFUN_GOTOERROR:
1717 gotoInset(Inset::ERROR_CODE, false);
1721 gotoInset(Inset::IGNORE_CODE, false);
1724 case LFUN_REFERENCE_GOTO:
1726 vector<Inset::Code> tmp;
1727 tmp.push_back(Inset::LABEL_CODE);
1728 tmp.push_back(Inset::REF_CODE);
1729 gotoInset(tmp, true);
1733 case LFUN_HYPHENATION:
1734 specialChar(InsetSpecialChar::HYPHENATION);
1737 case LFUN_LIGATURE_BREAK:
1738 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1742 specialChar(InsetSpecialChar::LDOTS);
1745 case LFUN_END_OF_SENTENCE:
1746 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1749 case LFUN_MENU_SEPARATOR:
1750 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1757 case LFUN_DEPTH_MIN:
1758 changeDepth(bv_, bv_->getLyXText(), -1);
1761 case LFUN_DEPTH_PLUS:
1762 changeDepth(bv_, bv_->getLyXText(), 1);
1766 owner_->getDialogs()->setUserFreeFont();
1769 case LFUN_FILE_INSERT:
1770 MenuInsertLyXFile(argument);
1773 case LFUN_FILE_INSERT_ASCII_PARA:
1774 InsertAsciiFile(bv_, argument, true);
1777 case LFUN_FILE_INSERT_ASCII:
1778 InsertAsciiFile(bv_, argument, false);
1783 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1784 << argument << endl;
1786 // Derive layout number from given argument (string)
1787 // and current buffer's textclass (number). */
1788 textclass_type tclass = buffer_->params.textclass;
1790 textclasslist[tclass].hasLayout(argument);
1791 string layout = argument;
1793 // If the entry is obsolete, use the new one instead.
1795 string const & obs = textclasslist[tclass][layout]
1802 owner_->getLyXFunc()->setErrorMessage(
1803 string(N_("Layout ")) + argument +
1808 bool change_layout = (current_layout != layout);
1809 LyXText * lt = bv_->getLyXText();
1810 if (!change_layout && lt->selection.set() &&
1811 lt->selection.start.par() != lt->selection.end.par())
1813 Paragraph * spar = lt->selection.start.par();
1814 Paragraph * epar = lt->selection.end.par()->next();
1815 while(spar != epar) {
1816 if (spar->layout() != current_layout) {
1817 change_layout = true;
1822 if (change_layout) {
1824 current_layout = layout;
1827 | BufferView::FITCUR);
1828 lt->setLayout(bv_, layout);
1829 owner_->setLayout(layout);
1832 | BufferView::FITCUR
1833 | BufferView::CHANGE);
1840 lang(bv_, argument);
1842 owner_->showState();
1847 owner_->showState();
1852 owner_->showState();
1857 owner_->showState();
1862 owner_->showState();
1867 owner_->showState();
1872 owner_->showState();
1877 owner_->showState();
1880 case LFUN_UNDERLINE:
1882 owner_->showState();
1885 case LFUN_FONT_SIZE:
1886 fontSize(bv_, argument);
1887 owner_->showState();
1890 case LFUN_FONT_STATE:
1891 owner_->getLyXFunc()->setMessage(currentState(bv_));
1894 case LFUN_UPCASE_WORD:
1896 LyXText * lt = bv_->getLyXText();
1900 | BufferView::FITCUR);
1901 lt->changeCase(bv_, LyXText::text_uppercase);
1902 if (lt->inset_owner)
1903 updateInset(lt->inset_owner, true);
1906 | BufferView::FITCUR
1907 | BufferView::CHANGE);
1911 case LFUN_LOWCASE_WORD:
1913 LyXText * lt = bv_->getLyXText();
1915 update(lt, BufferView::SELECT|BufferView::FITCUR);
1916 lt->changeCase(bv_, LyXText::text_lowercase);
1917 if (lt->inset_owner)
1918 updateInset(lt->inset_owner, true);
1921 | BufferView::FITCUR
1922 | BufferView::CHANGE);
1926 case LFUN_CAPITALIZE_WORD:
1928 LyXText * lt = bv_->getLyXText();
1930 update(lt, BufferView::SELECT|BufferView::FITCUR);
1931 lt->changeCase(bv_, LyXText::text_capitalization);
1932 if (lt->inset_owner)
1933 updateInset(lt->inset_owner, true);
1936 | BufferView::FITCUR
1937 | BufferView::CHANGE);
1941 case LFUN_TRANSPOSE_CHARS:
1943 LyXText * lt = bv_->getLyXText();
1945 update(lt, BufferView::SELECT|BufferView::FITCUR);
1946 lt->transposeChars(*bv_);
1947 if (lt->inset_owner)
1948 updateInset(lt->inset_owner, true);
1951 | BufferView::FITCUR
1952 | BufferView::CHANGE);
1957 case LFUN_INSERT_LABEL:
1958 MenuInsertLabel(bv_, argument);
1961 case LFUN_REF_INSERT:
1962 if (argument.empty()) {
1963 InsetCommandParams p("ref");
1964 owner_->getDialogs()->createRef(p.getAsString());
1966 InsetCommandParams p;
1967 p.setFromString(argument);
1969 InsetRef * inset = new InsetRef(p, *buffer_);
1970 if (!insertInset(inset))
1973 updateInset(inset, true);
1977 case LFUN_BOOKMARK_SAVE:
1978 savePosition(strToUnsignedInt(argument));
1981 case LFUN_BOOKMARK_GOTO:
1982 restorePosition(strToUnsignedInt(argument));
1987 string label(argument);
1988 if (label.empty()) {
1990 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1992 label = inset->getContents();
1997 if (!label.empty()) {
1998 //bv_->savePosition(0);
1999 if (!bv_->gotoLabel(label))
2000 Alert::alert(_("Error"),
2001 _("Couldn't find this label"),
2002 _("in current document."));
2007 // --- Cursor Movements -----------------------------
2010 LyXText * lt = bv_->getLyXText();
2012 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2013 if (!lt->selection.mark())
2015 update(lt, BufferView::SELECT|BufferView::FITCUR);
2017 lt->cursorLeft(bv_, false);
2018 if (lt->cursor.pos() < lt->cursor.par()->size()
2019 && lt->cursor.par()->isInset(lt->cursor.pos())
2020 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2021 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2022 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2024 tmpinset->edit(bv_, false);
2026 tmpinset->edit(bv_);
2030 lt->cursorRight(bv_, false);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2039 // This is soooo ugly. Isn`t it possible to make
2040 // it simpler? (Lgb)
2041 LyXText * lt = bv_->getLyXText();
2042 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2043 if (!lt->selection.mark())
2045 update(lt, BufferView::SELECT|BufferView::FITCUR);
2046 LyXCursor const cur = lt->cursor;
2048 lt->cursorLeft(bv_, false);
2049 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2050 lt->cursor.pos() < lt->cursor.par()->size() &&
2051 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2052 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2053 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2054 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2056 tmpinset->edit(bv_);
2058 tmpinset->edit(bv_, false);
2062 lt->cursorRight(bv_, false);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2076 update(lt, BufferView::UPDATE);
2079 moveCursorUpdate(false);
2080 owner_->showState();
2086 LyXText * lt = bv_->getLyXText();
2088 if (!lt->selection.mark())
2090 update(lt, BufferView::UPDATE);
2091 lt->cursorDown(bv_);
2093 moveCursorUpdate(false);
2094 owner_->showState();
2098 case LFUN_UP_PARAGRAPH:
2100 LyXText * lt = bv_->getLyXText();
2102 if (!lt->selection.mark())
2104 update(lt, BufferView::UPDATE);
2105 lt->cursorUpParagraph(bv_);
2107 moveCursorUpdate(false);
2108 owner_->showState();
2112 case LFUN_DOWN_PARAGRAPH:
2114 LyXText * lt = bv_->getLyXText();
2116 if (!lt->selection.mark())
2118 update(lt, BufferView::UPDATE);
2119 lt->cursorDownParagraph(bv_);
2121 moveCursorUpdate(false);
2122 owner_->showState();
2128 LyXText * lt = bv_->getLyXText();
2130 if (!lt->selection.mark())
2132 update(lt, BufferView::UPDATE);
2135 moveCursorUpdate(false, false);
2136 owner_->showState();
2142 LyXText * lt = bv_->getLyXText();
2144 if (!lt->selection.mark())
2146 update(lt, BufferView::UPDATE);
2149 moveCursorUpdate(false, false);
2150 owner_->showState();
2156 LyXText * lt = bv_->getLyXText();
2158 if (!lt->selection.mark())
2160 update(lt, BufferView::SELECT|BufferView::FITCUR);
2161 lt->cursorHome(bv_);
2163 moveCursorUpdate(false);
2164 owner_->showState();
2170 LyXText * lt = bv_->getLyXText();
2172 if (!lt->selection.mark())
2175 BufferView::SELECT|BufferView::FITCUR);
2178 moveCursorUpdate(false);
2179 owner_->showState();
2183 case LFUN_SHIFT_TAB:
2186 LyXText * lt = bv_->getLyXText();
2188 if (!lt->selection.mark())
2191 BufferView::SELECT|BufferView::FITCUR);
2194 moveCursorUpdate(false);
2195 owner_->showState();
2199 case LFUN_WORDRIGHT:
2201 LyXText * lt = bv_->getLyXText();
2203 if (!lt->selection.mark())
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2206 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2207 lt->cursorLeftOneWord(bv_);
2209 lt->cursorRightOneWord(bv_);
2211 moveCursorUpdate(false);
2212 owner_->showState();
2218 LyXText * lt = bv_->getLyXText();
2220 if (!lt->selection.mark())
2222 update(lt, BufferView::SELECT|BufferView::FITCUR);
2223 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2224 lt->cursorRightOneWord(bv_);
2226 lt->cursorLeftOneWord(bv_);
2228 moveCursorUpdate(false);
2229 owner_->showState();
2233 case LFUN_BEGINNINGBUF:
2235 LyXText * lt = bv_->getLyXText();
2237 if (!lt->selection.mark())
2240 BufferView::SELECT|BufferView::FITCUR);
2243 moveCursorUpdate(false);
2244 owner_->showState();
2250 LyXText * lt = bv_->getLyXText();
2252 if (!lt->selection.mark())
2255 BufferView::SELECT|BufferView::FITCUR);
2256 lt->cursorBottom(bv_);
2258 moveCursorUpdate(false);
2259 owner_->showState();
2263 /* cursor selection ---------------------------- */
2266 LyXText * lt = bv_->getLyXText();
2269 BufferView::SELECT|BufferView::FITCUR);
2270 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2271 lt->cursorLeft(bv_);
2273 lt->cursorRight(bv_);
2275 moveCursorUpdate(true);
2276 owner_->showState();
2282 LyXText * lt = bv_->getLyXText();
2285 BufferView::SELECT|BufferView::FITCUR);
2286 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2287 lt->cursorRight(bv_);
2289 lt->cursorLeft(bv_);
2291 moveCursorUpdate(true);
2292 owner_->showState();
2298 LyXText * lt = bv_->getLyXText();
2301 BufferView::SELECT|BufferView::FITCUR);
2302 lt->cursorUp(bv_, true);
2304 moveCursorUpdate(true);
2305 owner_->showState();
2311 LyXText * lt = bv_->getLyXText();
2314 BufferView::SELECT|BufferView::FITCUR);
2315 lt->cursorDown(bv_, true);
2317 moveCursorUpdate(true);
2318 owner_->showState();
2322 case LFUN_UP_PARAGRAPHSEL:
2324 LyXText * lt = bv_->getLyXText();
2327 BufferView::SELECT|BufferView::FITCUR);
2328 lt->cursorUpParagraph(bv_);
2330 moveCursorUpdate(true);
2331 owner_->showState();
2335 case LFUN_DOWN_PARAGRAPHSEL:
2337 LyXText * lt = bv_->getLyXText();
2340 BufferView::SELECT|BufferView::FITCUR);
2341 lt->cursorDownParagraph(bv_);
2343 moveCursorUpdate(true);
2344 owner_->showState();
2350 LyXText * lt = bv_->getLyXText();
2352 update(lt, BufferView::SELECT|BufferView::FITCUR);
2355 moveCursorUpdate(true);
2356 owner_->showState();
2362 LyXText * lt = bv_->getLyXText();
2364 update(lt, BufferView::SELECT|BufferView::FITCUR);
2367 moveCursorUpdate(true);
2368 owner_->showState();
2374 LyXText * lt = bv_->getLyXText();
2376 update(lt, BufferView::SELECT|BufferView::FITCUR);
2377 lt->cursorHome(bv_);
2379 moveCursorUpdate(true);
2380 owner_->showState();
2386 LyXText * lt = bv_->getLyXText();
2388 update(lt, BufferView::SELECT|BufferView::FITCUR);
2391 moveCursorUpdate(true);
2392 owner_->showState();
2396 case LFUN_WORDRIGHTSEL:
2398 LyXText * lt = bv_->getLyXText();
2400 update(lt, BufferView::SELECT|BufferView::FITCUR);
2401 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2402 lt->cursorLeftOneWord(bv_);
2404 lt->cursorRightOneWord(bv_);
2406 moveCursorUpdate(true);
2407 owner_->showState();
2411 case LFUN_WORDLEFTSEL:
2413 LyXText * lt = bv_->getLyXText();
2415 update(lt, BufferView::SELECT|BufferView::FITCUR);
2416 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2417 lt->cursorRightOneWord(bv_);
2419 lt->cursorLeftOneWord(bv_);
2421 moveCursorUpdate(true);
2422 owner_->showState();
2426 case LFUN_BEGINNINGBUFSEL:
2428 LyXText * lt = bv_->getLyXText();
2430 if (lt->inset_owner)
2432 update(lt, BufferView::SELECT|BufferView::FITCUR);
2435 moveCursorUpdate(true);
2436 owner_->showState();
2440 case LFUN_ENDBUFSEL:
2442 LyXText * lt = bv_->getLyXText();
2444 if (lt->inset_owner)
2447 BufferView::SELECT|BufferView::FITCUR);
2448 lt->cursorBottom(bv_);
2450 moveCursorUpdate(true);
2451 owner_->showState();
2455 // --- text changing commands ------------------------
2456 case LFUN_BREAKLINE:
2458 LyXText * lt = bv_->getLyXText();
2461 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2464 | BufferView::FITCUR
2465 | BufferView::CHANGE);
2466 moveCursorUpdate(false);
2470 case LFUN_PROTECTEDSPACE:
2472 LyXText * lt = bv_->getLyXText();
2474 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2476 if (style.free_spacing) {
2477 lt->insertChar(bv_, ' ');
2480 | BufferView::FITCUR
2481 | BufferView::CHANGE);
2483 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2485 moveCursorUpdate(false);
2491 LyXText * lt = bv_->getLyXText();
2493 if (lt->selection.mark()) {
2497 | BufferView::FITCUR);
2498 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2501 lt->selection.mark(true);
2504 | BufferView::FITCUR);
2505 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2507 lt->selection.cursor = lt->cursor;
2513 LyXText * lt = bv_->getLyXText();
2515 if (!lt->selection.set()) {
2517 lt->selection.cursor = lt->cursor;
2520 | BufferView::FITCUR
2521 | BufferView::CHANGE);
2522 // It is possible to make it a lot faster still
2523 // just comment out the line below...
2528 moveCursorUpdate(false);
2529 owner_->showState();
2534 case LFUN_DELETE_SKIP:
2536 LyXText * lt = bv_->getLyXText();
2538 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2540 LyXCursor cursor = lt->cursor;
2542 if (!lt->selection.set()) {
2543 if (cursor.pos() == cursor.par()->size()) {
2544 lt->cursorRight(bv_);
2545 cursor = lt->cursor;
2546 if (cursor.pos() == 0
2547 && !(cursor.par()->params().spaceTop()
2548 == VSpace (VSpace::NONE))) {
2551 cursor.par()->params().lineTop(),
2552 cursor.par()->params().lineBottom(),
2553 cursor.par()->params().pagebreakTop(),
2554 cursor.par()->params().pagebreakBottom(),
2555 VSpace(VSpace::NONE),
2556 cursor.par()->params().spaceBottom(),
2557 cursor.par()->params().spacing(),
2558 cursor.par()->params().align(),
2559 cursor.par()->params().labelWidthString(), 0);
2560 lt->cursorLeft(bv_);
2563 | BufferView::FITCUR
2564 | BufferView::CHANGE);
2566 lt->cursorLeft(bv_);
2568 lt->selection.cursor = lt->cursor;
2571 | BufferView::FITCUR
2572 | BufferView::CHANGE);
2576 lt->selection.cursor = lt->cursor;
2579 | BufferView::FITCUR
2580 | BufferView::CHANGE);
2588 /* -------> Delete word forward. */
2589 case LFUN_DELETE_WORD_FORWARD:
2590 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2591 bv_->getLyXText()->deleteWordForward(bv_);
2592 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2593 moveCursorUpdate(false);
2594 owner_->showState();
2597 /* -------> Delete word backward. */
2598 case LFUN_DELETE_WORD_BACKWARD:
2600 LyXText * lt = bv_->getLyXText();
2602 update(lt, BufferView::SELECT|BufferView::FITCUR);
2603 lt->deleteWordBackward(bv_);
2606 | BufferView::FITCUR
2607 | BufferView::CHANGE);
2608 moveCursorUpdate(false);
2609 owner_->showState();
2613 /* -------> Kill to end of line. */
2614 case LFUN_DELETE_LINE_FORWARD:
2616 LyXText * lt = bv_->getLyXText();
2618 update(lt, BufferView::SELECT|BufferView::FITCUR);
2619 lt->deleteLineForward(bv_);
2622 | BufferView::FITCUR
2623 | BufferView::CHANGE);
2624 moveCursorUpdate(false);
2628 /* -------> Set mark off. */
2631 LyXText * lt = bv_->getLyXText();
2634 update(lt, BufferView::SELECT|BufferView::FITCUR);
2635 lt->selection.cursor = lt->cursor;
2636 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2640 /* -------> Set mark on. */
2643 LyXText * lt = bv_->getLyXText();
2646 lt->selection.mark(true);
2647 update(lt, BufferView::SELECT|BufferView::FITCUR);
2648 lt->selection.cursor = lt->cursor;
2649 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2653 case LFUN_BACKSPACE:
2655 LyXText * lt = bv_->getLyXText();
2657 if (!lt->selection.set()) {
2658 if (owner_->getIntl()->getTrans().backspace()) {
2660 lt->selection.cursor = lt->cursor;
2663 | BufferView::FITCUR
2664 | BufferView::CHANGE);
2665 // It is possible to make it a lot faster still
2666 // just comment out the line below...
2672 owner_->showState();
2677 case LFUN_BACKSPACE_SKIP:
2679 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2680 LyXText * lt = bv_->getLyXText();
2682 LyXCursor cursor = lt->cursor;
2684 if (!lt->selection.set()) {
2685 if (cursor.pos() == 0
2686 && !(cursor.par()->params().spaceTop()
2687 == VSpace (VSpace::NONE))) {
2690 cursor.par()->params().lineTop(),
2691 cursor.par()->params().lineBottom(),
2692 cursor.par()->params().pagebreakTop(),
2693 cursor.par()->params().pagebreakBottom(),
2694 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2695 cursor.par()->params().spacing(),
2696 cursor.par()->params().align(),
2697 cursor.par()->params().labelWidthString(), 0);
2700 | BufferView::FITCUR
2701 | BufferView::CHANGE);
2704 lt->selection.cursor = cursor;
2707 | BufferView::FITCUR
2708 | BufferView::CHANGE);
2715 case LFUN_BREAKPARAGRAPH:
2717 LyXText * lt = bv_->getLyXText();
2720 lt->breakParagraph(bv_, 0);
2723 | BufferView::FITCUR
2724 | BufferView::CHANGE);
2725 lt->selection.cursor = lt->cursor;
2727 owner_->showState();
2731 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2733 LyXText * lt = bv_->getLyXText();
2736 lt->breakParagraph(bv_, 1);
2739 | BufferView::FITCUR
2740 | BufferView::CHANGE);
2741 lt->selection.cursor = lt->cursor;
2743 owner_->showState();
2747 case LFUN_BREAKPARAGRAPH_SKIP:
2749 // When at the beginning of a paragraph, remove
2750 // indentation and add a "defskip" at the top.
2751 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2752 LyXText * lt = bv_->getLyXText();
2754 LyXCursor cursor = lt->cursor;
2757 if (cursor.pos() == 0) {
2758 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2761 cursor.par()->params().lineTop(),
2762 cursor.par()->params().lineBottom(),
2763 cursor.par()->params().pagebreakTop(),
2764 cursor.par()->params().pagebreakBottom(),
2765 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2766 cursor.par()->params().spacing(),
2767 cursor.par()->params().align(),
2768 cursor.par()->params().labelWidthString(), 1);
2769 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2773 lt->breakParagraph(bv_, 0);
2774 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2779 | BufferView::FITCUR
2780 | BufferView::CHANGE);
2781 lt->selection.cursor = cursor;
2783 owner_->showState();
2787 case LFUN_PARAGRAPH_SPACING:
2789 LyXText * lt = bv_->getLyXText();
2791 Paragraph * par = lt->cursor.par();
2792 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2793 float cur_value = 1.0;
2794 if (cur_spacing == Spacing::Other) {
2795 cur_value = par->params().spacing().getValue();
2798 istringstream istr(argument.c_str());
2802 Spacing::Space new_spacing = cur_spacing;
2803 float new_value = cur_value;
2805 lyxerr << "Missing argument to `paragraph-spacing'"
2807 } else if (tmp == "single") {
2808 new_spacing = Spacing::Single;
2809 } else if (tmp == "onehalf") {
2810 new_spacing = Spacing::Onehalf;
2811 } else if (tmp == "double") {
2812 new_spacing = Spacing::Double;
2813 } else if (tmp == "other") {
2814 new_spacing = Spacing::Other;
2817 lyxerr << "new_value = " << tmpval << endl;
2820 } else if (tmp == "default") {
2821 new_spacing = Spacing::Default;
2823 lyxerr << _("Unknown spacing argument: ")
2824 << argument << endl;
2826 if (cur_spacing != new_spacing || cur_value != new_value) {
2827 par->params().spacing(Spacing(new_spacing, new_value));
2828 lt->redoParagraph(bv_);
2831 | BufferView::FITCUR
2832 | BufferView::CHANGE);
2837 case LFUN_INSET_TOGGLE:
2839 LyXText * lt = bv_->getLyXText();
2842 update(lt, BufferView::SELECT|BufferView::FITCUR);
2843 lt->toggleInset(bv_);
2844 update(lt, BufferView::SELECT|BufferView::FITCUR);
2856 InsetCommandParams p;
2857 if (action == LFUN_HTMLURL)
2858 p.setCmdName("htmlurl");
2860 p.setCmdName("url");
2861 owner_->getDialogs()->createUrl(p.getAsString());
2865 case LFUN_INSERT_URL:
2867 InsetCommandParams p;
2868 p.setFromString(argument);
2870 InsetUrl * inset = new InsetUrl(p);
2871 if (!insertInset(inset))
2874 updateInset(inset, true);
2878 case LFUN_INSET_ERT:
2879 insertAndEditInset(new InsetERT(buffer_->params));
2882 case LFUN_INSET_EXTERNAL:
2883 insertAndEditInset(new InsetExternal);
2886 case LFUN_INSET_FOOTNOTE:
2887 insertAndEditInset(new InsetFoot(buffer_->params));
2890 case LFUN_INSET_MARGINAL:
2891 insertAndEditInset(new InsetMarginal(buffer_->params));
2894 case LFUN_INSET_MINIPAGE:
2895 insertAndEditInset(new InsetMinipage(buffer_->params));
2898 case LFUN_INSERT_NOTE:
2899 insertAndEditInset(new InsetNote(buffer_->params));
2902 case LFUN_INSET_FLOAT:
2903 // check if the float type exist
2904 if (floatList.typeExist(argument)) {
2905 insertAndEditInset(new InsetFloat(buffer_->params,
2908 lyxerr << "Non-existent float type: "
2909 << argument << endl;
2913 case LFUN_INSET_WIDE_FLOAT:
2915 // check if the float type exist
2916 if (floatList.typeExist(argument)) {
2917 InsetFloat * new_inset =
2918 new InsetFloat(buffer_->params, argument);
2919 new_inset->wide(true);
2920 if (insertInset(new_inset))
2921 new_inset->edit(bv_);
2925 lyxerr << "Non-existent float type: "
2926 << argument << endl;
2933 case LFUN_INSET_LIST:
2934 insertAndEditInset(new InsetList);
2937 case LFUN_INSET_THEOREM:
2938 insertAndEditInset(new InsetTheorem);
2942 case LFUN_INSET_CAPTION:
2944 // Do we have a locking inset...
2945 if (bv_->theLockingInset()) {
2946 lyxerr << "Locking inset code: "
2947 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2948 InsetCaption * new_inset =
2949 new InsetCaption(buffer_->params);
2950 new_inset->setOwner(bv_->theLockingInset());
2951 new_inset->setAutoBreakRows(true);
2952 new_inset->setDrawFrame(0, InsetText::LOCKED);
2953 new_inset->setFrameColor(0, LColor::captionframe);
2954 if (insertInset(new_inset))
2955 new_inset->edit(bv_);
2962 case LFUN_INSET_TABULAR:
2966 if (!argument.empty())
2967 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2968 InsetTabular * new_inset =
2969 new InsetTabular(*buffer_, r, c);
2971 bv_->getLyXText()->real_current_font.isRightToLeft();
2972 if (!open_new_inset(new_inset, rtl))
2977 // --- lyxserver commands ----------------------------
2979 case LFUN_CHARATCURSOR:
2981 pos_type pos = bv_->getLyXText()->cursor.pos();
2982 if (pos < bv_->getLyXText()->cursor.par()->size())
2983 owner_->getLyXFunc()->setMessage(
2984 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2986 owner_->getLyXFunc()->setMessage("EOF");
2991 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2993 + tostr(bv_->getLyXText()->cursor.y()));
3000 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
3001 lyxerr << "SETXY: Could not parse coordinates in '"
3002 << argument << std::endl;
3004 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
3008 case LFUN_GETLAYOUT:
3009 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3014 LyXFont & font = bv_->getLyXText()->current_font;
3015 if (font.shape() == LyXFont::ITALIC_SHAPE)
3016 owner_->getLyXFunc()->setMessage("E");
3017 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3018 owner_->getLyXFunc()->setMessage("N");
3020 owner_->getLyXFunc()->setMessage("0");
3025 // --- accented characters ---------------------------
3028 case LFUN_CIRCUMFLEX:
3038 case LFUN_SPECIAL_CARON:
3041 case LFUN_HUNG_UMLAUT:
3044 if (argument.empty()) {
3046 owner_->getLyXFunc()->handleKeyFunc(action);
3048 owner_->getLyXFunc()->handleKeyFunc(action);
3049 owner_->getIntl()->getTrans()
3050 .TranslateAndInsert(argument[0], bv_->getLyXText());
3051 update(bv_->getLyXText(),
3053 | BufferView::FITCUR
3054 | BufferView::CHANGE);
3058 case LFUN_MATH_MACRO:
3059 mathDispatchMathMacro(bv_, argument);
3062 case LFUN_MATH_DELIM:
3063 mathDispatchMathDelim(bv_, argument);
3066 case LFUN_INSERT_MATRIX:
3067 mathDispatchInsertMatrix(bv_, argument);
3070 case LFUN_INSERT_MATH:
3071 mathDispatchInsertMath(bv_, argument);
3074 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3075 mathDispatchMathImportSelection(bv_, argument);
3078 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3079 mathDispatchMathDisplay(bv_, argument);
3082 case LFUN_MATH_MODE: // Open or create an inlined math inset
3083 mathDispatchMathMode(bv_, argument);
3086 case LFUN_GREEK: // Insert a single greek letter
3087 mathDispatchGreek(bv_, argument);
3090 case LFUN_CITATION_INSERT:
3092 InsetCommandParams p;
3093 p.setFromString(argument);
3095 InsetCitation * inset = new InsetCitation(p);
3096 if (!insertInset(inset))
3099 updateInset(inset, true);
3103 case LFUN_INSERT_BIBTEX:
3105 // ale970405+lasgoutt970425
3106 // The argument can be up to two tokens separated
3107 // by a space. The first one is the bibstyle.
3108 string const db = token(argument, ' ', 0);
3109 string const bibstyle = token(argument, ' ', 1);
3111 InsetCommandParams p("BibTeX", db, bibstyle);
3112 InsetBibtex * inset = new InsetBibtex(p);
3114 if (insertInset(inset)) {
3115 if (argument.empty())
3122 // BibTeX data bases
3123 case LFUN_BIBDB_ADD:
3125 InsetBibtex * inset =
3126 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3128 inset->addDatabase(argument);
3133 case LFUN_BIBDB_DEL:
3135 InsetBibtex * inset =
3136 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3138 inset->delDatabase(argument);
3143 case LFUN_BIBTEX_STYLE:
3145 InsetBibtex * inset =
3146 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3148 inset->setOptions(argument);
3153 case LFUN_INDEX_CREATE:
3155 InsetCommandParams p("index");
3156 if (argument.empty()) {
3157 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3158 p.setContents(idxstring);
3160 p.setContents(argument);
3163 owner_->getDialogs()->createIndex(p.getAsString());
3167 case LFUN_INDEX_INSERT:
3169 InsetCommandParams p;
3170 p.setFromString(argument);
3171 InsetIndex * inset = new InsetIndex(p);
3173 if (!insertInset(inset))
3176 updateInset(inset, true);
3180 case LFUN_INDEX_INSERT_LAST:
3182 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3183 if (!idxstring.empty()) {
3184 owner_->message(_("Word `")
3185 + idxstring + _(("' indexed.")));
3186 InsetCommandParams p("index", idxstring);
3187 InsetIndex * inset = new InsetIndex(p);
3189 if (!insertInset(inset))
3192 updateInset(inset, true);
3197 case LFUN_INDEX_PRINT:
3199 InsetCommandParams p("printindex");
3200 Inset * inset = new InsetPrintIndex(p);
3201 if (!insertInset(inset, "Standard"))
3206 case LFUN_PARENTINSERT:
3208 InsetCommandParams p("lyxparent", argument);
3209 Inset * inset = new InsetParent(p, *buffer_);
3210 if (!insertInset(inset, "Standard"))
3216 case LFUN_CHILD_INSERT:
3218 InsetInclude::Params p;
3219 p.cparams.setFromString(argument);
3220 p.masterFilename_ = buffer_->fileName();
3222 InsetInclude * inset = new InsetInclude(p);
3223 if (!insertInset(inset))
3226 updateInset(inset, true);
3227 bv_->owner()->getDialogs()->showInclude(inset);
3232 case LFUN_FLOAT_LIST:
3234 // We should check the argument for validity. (Lgb)
3235 Inset * inset = new InsetFloatList(argument);
3236 if (!insertInset(inset, "Standard"))
3241 case LFUN_THESAURUS_ENTRY:
3243 string arg = argument;
3246 arg = bv_->getLyXText()->selectionAsString(buffer_,
3250 if (arg.size() > 100 || arg.empty()) {
3251 // Get word or selection
3252 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3253 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3254 // FIXME: where is getLyXText()->unselect(bv_) ?
3258 bv_->owner()->getDialogs()->showThesaurus(arg);
3262 case LFUN_SELFINSERT:
3264 if (argument.empty()) break;
3266 /* Automatically delete the currently selected
3267 * text and replace it with what is being
3268 * typed in now. Depends on lyxrc settings
3269 * "auto_region_delete", which defaults to
3272 LyXText * lt = bv_->getLyXText();
3274 if (lyxrc.auto_region_delete) {
3275 if (lt->selection.set()) {
3276 lt->cutSelection(bv_, false, false);
3279 | BufferView::FITCUR
3280 | BufferView::CHANGE);
3282 workarea_.haveSelection(false);
3286 LyXFont const old_font(lt->real_current_font);
3288 string::const_iterator cit = argument.begin();
3289 string::const_iterator end = argument.end();
3290 for (; cit != end; ++cit) {
3291 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3296 | BufferView::FITCUR
3297 | BufferView::CHANGE);
3299 lt->selection.cursor = lt->cursor;
3300 moveCursorUpdate(false);
3302 // real_current_font.number can change so we need to
3303 // update the minibuffer
3304 if (old_font != lt->real_current_font)
3305 owner_->showState();
3310 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3312 time_t now_time_t = time(NULL);
3313 struct tm * now_tm = localtime(&now_time_t);
3314 setlocale(LC_TIME, "");
3316 if (!argument.empty())
3319 arg = lyxrc.date_insert_format;
3321 int const datetmp_len =
3322 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3324 LyXText * lt = bv_->getLyXText();
3326 for (int i = 0; i < datetmp_len; i++) {
3327 lt->insertChar(bv_, datetmp[i]);
3330 | BufferView::FITCUR
3331 | BufferView::CHANGE);
3334 lt->selection.cursor = lt->cursor;
3335 moveCursorUpdate(false);
3339 case LFUN_UNKNOWN_ACTION:
3340 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3351 void BufferView::Pimpl::newline()
3354 LyXText * lt = bv_->getLyXText();
3358 | BufferView::FITCUR);
3359 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3362 | BufferView::FITCUR
3363 | BufferView::CHANGE);
3368 void BufferView::Pimpl::hfill()
3371 LyXText * lt = bv_->getLyXText();
3375 | BufferView::FITCUR);
3376 lt->insertChar(bv_, Paragraph::META_HFILL);
3379 | BufferView::FITCUR
3380 | BufferView::CHANGE);
3385 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3388 LyXText * lt = bv_->getLyXText();
3391 update(lt, BufferView::SELECT|BufferView::FITCUR);
3392 InsetSpecialChar * new_inset =
3393 new InsetSpecialChar(kind);
3394 if (!insertInset(new_inset))
3397 updateInset(new_inset, true);
3402 void BufferView::Pimpl::smartQuote()
3404 LyXText const * lt = bv_->getLyXText();
3405 Paragraph const * par = lt->cursor.par();
3406 pos_type pos = lt->cursor.pos();
3410 || (par->isInset(pos - 1)
3411 && par->getInset(pos - 1)->isSpace()))
3414 c = par->getChar(pos - 1);
3419 LyXLayout const & style =
3420 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3422 if (style.pass_thru ||
3423 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3424 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3428 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3430 if (insertInset(inset))
3437 // Open and lock an updatable inset
3438 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3440 LyXText * lt = bv_->getLyXText();
3444 if (!insertInset(new_inset)) {
3448 new_inset->edit(bv_, !behind);
3453 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3455 // if we are in a locking inset we should try to insert the
3456 // inset there otherwise this is a illegal function now
3457 if (bv_->theLockingInset()) {
3458 if (bv_->theLockingInset()->insetAllowed(inset))
3459 return bv_->theLockingInset()->insertInset(bv_, inset);
3463 // not quite sure if we want this...
3464 setCursorParUndo(bv_);
3467 beforeChange(bv_->text);
3468 if (!lout.empty()) {
3469 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3470 bv_->text->breakParagraph(bv_);
3471 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3473 if (bv_->text->cursor.par()->size()) {
3474 bv_->text->cursorLeft(bv_);
3476 bv_->text->breakParagraph(bv_);
3477 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3481 LyXTextClass const & tclass =
3482 textclasslist[buffer_->params.textclass];
3483 bool hasLayout = tclass.hasLayout(lres);
3484 string lay = tclass.defaultLayoutName();
3486 if (hasLayout != false) {
3490 // layout not fount using default
3491 lay = tclass.defaultLayoutName();
3494 bv_->text->setLayout(bv_, lay);
3496 bv_->text->setParagraph(bv_, 0, 0,
3498 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3503 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3506 bv_->text->insertInset(bv_, inset);
3507 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3514 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3516 if (!inset || !available())
3519 // first check for locking insets
3520 if (bv_->theLockingInset()) {
3521 if (bv_->theLockingInset() == inset) {
3522 if (bv_->text->updateInset(bv_, inset)) {
3525 buffer_->markDirty();
3530 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3531 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3534 buffer_->markDirty();
3542 // then check if the inset is a top_level inset (has no owner)
3543 // if yes do the update as always otherwise we have to update the
3544 // toplevel inset where this inset is inside
3545 Inset * tl_inset = inset;
3546 while(tl_inset->owner())
3547 tl_inset = tl_inset->owner();
3549 if (tl_inset == inset) {
3550 update(bv_->text, BufferView::UPDATE);
3551 if (bv_->text->updateInset(bv_, inset)) {
3555 | BufferView::FITCUR
3556 | BufferView::CHANGE);
3558 update(bv_->text, SELECT);
3562 } else if (static_cast<UpdatableInset *>(tl_inset)
3563 ->updateInsetInInset(bv_, inset))
3565 if (bv_->text->updateInset(bv_, tl_inset)) {
3573 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3576 if (!available()) return;
3579 beforeChange(bv_->text);
3580 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3582 LyXCursor const & cursor = bv_->text->cursor;
3586 cursor.par()->isInset(cursor.pos())) {
3587 Inset const * inset = cursor.par()->getInset(cursor.pos());
3588 if (find(codes.begin(), codes.end(), inset->lyxCode())
3591 static_cast<InsetCommand const *>(inset)->getContents();
3595 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3596 if (bv_->text->cursor.pos()
3597 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3598 LyXCursor tmp = bv_->text->cursor;
3599 bv_->text->cursor.par(bv_->text->ownerParagraph());
3600 bv_->text->cursor.pos(0);
3601 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3602 bv_->text->cursor = tmp;
3603 bv_->owner()->message(_("No more insets"));
3606 bv_->owner()->message(_("No more insets"));
3609 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3610 bv_->text->selection.cursor = bv_->text->cursor;
3614 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3616 gotoInset(vector<Inset::Code>(1, code), same_content);