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 int y_before = bv_->text->cursor.y();
570 Row * cursorrow = bv_->text->cursor.row();
571 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
573 // sorry for this but I have a strange error that the y value jumps at
574 // a certain point. This seems like an error in my xforms library or
575 // in some other local environment, but I would like to leave this here
576 // for the moment until I can remove this (Jug 20020418)
577 if (y_before < bv_->text->cursor.y())
578 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
580 // This is to allow jumping over large insets
581 if (cursorrow == bv_->text->cursor.row()) {
582 if (y >= int(workarea_.height())) {
583 bv_->text->cursorDown(bv_, false);
585 bv_->text->cursorUp(bv_, false);
589 if (!bv_->text->selection.set())
590 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
592 bv_->text->setSelection(bv_);
593 screen_->toggleToggle(bv_->text, bv_);
599 // Single-click on work area
600 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
603 if (!buffer_ || !screen_.get())
606 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
608 // ok ok, this is a hack.
609 if (button == 4 || button == 5) {
612 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
615 scrollDown(lyxrc.wheel_jump);
620 // Middle button press pastes if we have a selection
621 // We do this here as if the selection was inside an inset
622 // it could get cleared on the unlocking of the inset so
623 // we have to check this first
624 bool paste_internally = false;
625 if (button == 2 && bv_->getLyXText()->selection.set()) {
626 owner_->getLyXFunc()->dispatch(LFUN_COPY);
627 paste_internally = true;
630 int const screen_first = bv_->text->first_y;
632 if (bv_->theLockingInset()) {
633 // We are in inset locking mode
635 /* Check whether the inset was hit. If not reset mode,
636 otherwise give the event to the inset */
637 if (inset_hit == bv_->theLockingInset()) {
638 bv_->theLockingInset()->
639 insetButtonPress(bv_,xpos, ypos,button);
642 bv_->unlockInset(bv_->theLockingInset());
647 selection_possible = true;
648 screen_->hideCursor();
650 // Clear the selection
651 screen_->toggleSelection(bv_->text, bv_);
652 bv_->text->clearSelection();
653 bv_->text->fullRebreak(bv_);
657 // Single left click in math inset?
658 if (isHighlyEditableInset(inset_hit)) {
659 // Highly editable inset, like math
660 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
661 selection_possible = false;
662 owner_->updateLayoutChoice();
663 owner_->message(inset->editMessage());
664 //inset->edit(bv_, xpos, ypos, button);
665 // We just have to lock the inset before calling a PressEvent on it!
666 // we don't need the edit() call here! (Jug20020329)
667 if (!bv_->lockInset(inset)) {
668 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
670 inset->insetButtonPress(bv_, xpos, ypos, button);
673 // I'm not sure we should continue here if we hit an inset (Jug20020403)
675 // Right click on a footnote flag opens float menu
677 selection_possible = false;
681 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
682 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
684 bv_->text->selection.cursor = bv_->text->cursor;
685 bv_->text->cursor.x_fix(bv_->text->cursor.x());
687 owner_->updateLayoutChoice();
689 selection_possible = false;
692 // Insert primary selection with middle mouse
693 // if there is a local selection in the current buffer,
696 if (paste_internally)
697 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
699 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
701 selection_possible = false;
707 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
713 LyXText * text = bv_->getLyXText();
715 if (text->bv_owner && bv_->theLockingInset())
718 if (screen_.get() && button == 1) {
719 if (text->bv_owner) {
720 screen_->hideCursor();
721 screen_->toggleSelection(text, bv_);
722 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
723 screen_->toggleSelection(text, bv_, false);
725 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
727 /* This will fit the cursor on the screen
729 update(text, BufferView::SELECT|BufferView::FITCUR);
734 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
740 LyXText * text = bv_->getLyXText();
742 if (text->bv_owner && bv_->theLockingInset())
745 if (screen_.get() && (button == 1)) {
746 if (text->bv_owner) {
747 screen_->hideCursor();
748 screen_->toggleSelection(text, bv_);
750 text->cursorHome(bv_);
751 text->selection.cursor = text->cursor;
752 text->cursorEnd(bv_);
753 text->setSelection(bv_);
754 if (text->bv_owner) {
755 screen_->toggleSelection(text, bv_, false);
757 /* This will fit the cursor on the screen
759 update(text, BufferView::SELECT|BufferView::FITCUR);
764 void BufferView::Pimpl::selectionRequested()
771 LyXText * text = bv_->getLyXText();
773 if (text->selection.set() &&
774 (!bv_->text->xsel_cache.set() ||
775 text->selection.start != bv_->text->xsel_cache.start ||
776 text->selection.end != bv_->text->xsel_cache.end))
778 bv_->text->xsel_cache = text->selection;
779 sel = text->selectionAsString(bv_->buffer(), false);
780 } else if (!text->selection.set()) {
782 bv_->text->xsel_cache.set(false);
785 workarea_.putClipboard(sel);
790 void BufferView::Pimpl::selectionLost()
792 if (active() && available()) {
795 bv_->getLyXText()->clearSelection();
797 bv_->text->xsel_cache.set(false);
802 void BufferView::Pimpl::enterView()
804 if (active() && available()) {
805 SetXtermCursor(workarea_.getWin());
806 using_xterm_cursor = true;
811 void BufferView::Pimpl::leaveView()
813 if (using_xterm_cursor) {
814 XUndefineCursor(fl_get_display(), workarea_.getWin());
815 using_xterm_cursor = false;
820 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
823 if (!buffer_ || !screen_.get()) return;
825 // If we hit an inset, we have the inset coordinates in these
826 // and inset_hit points to the inset. If we do not hit an
827 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
828 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
830 if (bv_->theLockingInset()) {
831 // We are in inset locking mode.
833 /* LyX does a kind of work-area grabbing for insets.
834 Only a ButtonPress Event outside the inset will
835 force a insetUnlock. */
836 bv_->theLockingInset()->
837 insetButtonRelease(bv_, x, y, button);
841 selection_possible = false;
848 workarea_.haveSelection(bv_->getLyXText()->selection.set());
853 owner_->updateMenubar();
854 owner_->updateToolbar();
856 // Did we hit an editable inset?
858 selection_possible = false;
860 // if we reach this point with a selection, it
861 // must mean we are currently selecting.
862 // But we don't want to open the inset
863 // because that is annoying for the user.
864 // So just pretend we didn't hit it.
865 // this is OK because a "kosher" ButtonRelease
866 // will follow a ButtonPress that clears
868 // Note this also fixes selection drawing
869 // problems if we end up opening an inset
870 if (bv_->getLyXText()->selection.set())
873 // CHECK fix this proper in 0.13
874 // well, maybe 13.0 !!!!!!!!!
876 // Following a ref shouldn't issue
877 // a push on the undo-stack
878 // anylonger, now that we have
879 // keybindings for following
880 // references and returning from
881 // references. IMHO though, it
882 // should be the inset's own business
883 // to push or not push on the undo
884 // stack. They don't *have* to
885 // alter the document...
887 // ...or maybe the SetCursorParUndo()
888 // below isn't necessary at all anylonger?
889 if (inset_hit->lyxCode() == Inset::REF_CODE) {
890 setCursorParUndo(bv_);
893 owner_->message(inset_hit->editMessage());
895 if (isHighlyEditableInset(inset_hit)) {
896 // Highly editable inset, like math
897 UpdatableInset *inset = (UpdatableInset *)inset_hit;
898 inset->insetButtonRelease(bv_, x, y, button);
900 inset_hit->insetButtonRelease(bv_, x, y, button);
901 // IMO this is a grosshack! Inset's should be changed so that
902 // they call the actions they have to do with the insetButtonRel.
903 // function and not in the edit(). This should be changed
905 inset_hit->edit(bv_, x, y, button);
910 // Maybe we want to edit a bibitem ale970302
911 if (bv_->text->cursor.par()->bibkey && x < 20 +
912 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
913 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
920 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
921 LyXCursor const & cursor) const
923 Paragraph /*const*/ & par = *cursor.par();
924 pos_type const pos = cursor.pos();
926 lyx::Assert(par.getInset(pos));
928 Inset const & inset(*par.getInset(pos));
930 LyXFont const & font = text.getFont(buffer_, &par, pos);
932 int const width = inset.width(bv_, font);
933 int const inset_x = font.isVisibleRightToLeft()
934 ? (cursor.ix() - width) : cursor.ix();
937 inset_x + inset.scroll(),
939 cursor.iy() - inset.ascent(bv_, font),
940 cursor.iy() + inset.descent(bv_, font));
944 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
945 LyXCursor const & cursor,
946 int & x, int & y) const
948 pos_type const pos(cursor.pos());
949 Paragraph /*const*/ & par(*cursor.par());
951 if (pos >= par.size() || !par.isInset(pos)) {
955 Inset /*const*/ * inset = par.getInset(pos);
957 if (!isEditableInset(inset)) {
961 Box b(insetDimensions(text, cursor));
963 if (!b.contained(x, y)) {
964 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
965 << " box " << b << endl;
969 text.setCursor(bv_, &par, pos, true);
972 // The origin of an inset is on the baseline
973 y -= text.cursor.iy();
979 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
984 int y_tmp = y + text->first_y;
987 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
989 Inset * inset(checkInset(*text, cursor, x, y_tmp));
996 // look at previous position
998 if (cursor.pos() == 0) {
1003 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1005 inset = checkInset(*text, cursor, x, y_tmp);
1013 void BufferView::Pimpl::workAreaExpose()
1015 static int work_area_width;
1016 static unsigned int work_area_height;
1018 bool const widthChange = workarea_.workWidth() != work_area_width;
1019 bool const heightChange = workarea_.height() != work_area_height;
1021 // update from work area
1022 work_area_width = workarea_.workWidth();
1023 work_area_height = workarea_.height();
1026 // The visible LyXView need a resize
1029 // Remove all texts from the textcache
1030 // This is not _really_ what we want to do. What
1031 // we really want to do is to delete in textcache
1032 // that does not have a BufferView with matching
1033 // width, but as long as we have only one BufferView
1034 // deleting all gives the same result.
1035 if (lyxerr.debugging())
1036 textcache.show(lyxerr, "Expose delete all");
1038 buffer_->resizeInsets(bv_);
1039 } else if (heightChange) {
1040 // Rebuild image of current screen
1042 // fitCursor() ensures we don't jump back
1043 // to the start of the document on vertical
1047 // The main window size has changed, repaint most stuff
1049 } else if (screen_.get())
1050 screen_->redraw(bv_->text, bv_);
1052 // Grey box when we don't have a buffer
1053 workarea_.greyOut();
1056 // always make sure that the scrollbar is sane.
1058 owner_->updateLayoutChoice();
1063 void BufferView::Pimpl::update()
1065 if (screen_.get() &&
1066 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1068 LyXText::text_status st = bv_->text->status();
1069 screen_->update(bv_->text, bv_);
1071 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1072 if (bv_->text->fullRebreak(bv_)) {
1073 st = LyXText::NEED_MORE_REFRESH;
1074 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1075 bv_->text->cursor.pos());
1078 bv_->text->status(bv_, st);
1079 screen_->update(bv_->text, bv_);
1081 // do this here instead of in the screen::update because of
1083 bv_->text->status(bv_, LyXText::UNCHANGED);
1089 // Values used when calling update:
1091 // -2 - update, move sel_cursor if selection, fitcursor
1092 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1093 // 0 - update, move sel_cursor if selection, fitcursor
1094 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1095 // 3 - update, move sel_cursor if selection
1098 // a simple redraw of the parts that need refresh
1100 // move sel_cursor if selection -
1101 // the text's sel_cursor is moved if there is selection is progress
1104 // fitCursor() is called and the scrollbar updated
1107 // the buffer is marked dirty.
1116 // UPDATE_ONLY = UPDATE;
1117 // UPDATE_SELECT = UPDATE | SELECT;
1118 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1119 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1121 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1122 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1123 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1124 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1125 // update(3) -> update(1) -> update(1) -> update(SELECT)
1127 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1129 owner_->updateLayoutChoice();
1131 if (!text->selection.set() && (f & SELECT)) {
1132 text->selection.cursor = text->cursor;
1135 text->fullRebreak(bv_);
1137 if (text->inset_owner) {
1138 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1139 updateInset(text->inset_owner, false);
1149 buffer_->markDirty();
1154 // Callback for cursor timer
1155 void BufferView::Pimpl::cursorToggle()
1158 cursor_timeout.restart();
1162 if (!screen_.get()) {
1163 cursor_timeout.restart();
1168 extern void reapSpellchecker(void);
1171 if (!bv_->theLockingInset()) {
1172 screen_->cursorToggle(bv_);
1174 bv_->theLockingInset()->toggleInsetCursor(bv_);
1177 cursor_timeout.restart();
1181 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1183 if (!text->cursor.row()->previous()) {
1184 if (text->first_y > 0) {
1185 int new_y = bv_->text->first_y - workarea_.height();
1186 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1192 int y = text->first_y;
1193 Row * cursorrow = text->cursor.row();
1195 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1199 if (cursorrow == bv_->text->cursor.row()) {
1200 // we have a row which is higher than the workarea so we leave the
1201 // cursor on the start of the row and move only the draw up as soon
1202 // as we move the cursor or do something while inside the row (it may
1203 // span several workarea-heights) we'll move to the top again, but this
1204 // is better than just jump down and only display part of the row.
1205 new_y = bv_->text->first_y - workarea_.height();
1207 if (text->inset_owner) {
1208 new_y = bv_->text->cursor.iy()
1209 + bv_->theLockingInset()->insetInInsetY() + y
1210 + text->cursor.row()->height()
1211 - workarea_.height() + 1;
1213 new_y = text->cursor.y()
1214 - text->cursor.row()->baseline()
1215 + text->cursor.row()->height()
1216 - workarea_.height() + 1;
1219 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1220 if (text->cursor.row()->previous()) {
1222 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1223 text->cursor.row()->previous()->pos(), false);
1224 if (cur.y() > text->first_y) {
1225 text->cursorUp(bv_, true);
1232 void BufferView::Pimpl::cursorNext(LyXText * text)
1234 if (!text->cursor.row()->next()) {
1235 int y = text->cursor.y() - text->cursor.row()->baseline() +
1236 text->cursor.row()->height();
1237 if (y > int(text->first_y + workarea_.height())) {
1238 screen_->draw(bv_->text, bv_,
1239 bv_->text->first_y + workarea_.height());
1245 int y = text->first_y + workarea_.height();
1246 if (text->inset_owner && !text->first_y) {
1247 y -= (bv_->text->cursor.iy()
1248 - bv_->text->first_y
1249 + bv_->theLockingInset()->insetInInsetY());
1251 text->getRowNearY(y);
1253 Row * cursorrow = text->cursor.row();
1254 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1257 if (cursorrow == bv_->text->cursor.row()) {
1258 // we have a row which is higher than the workarea so we leave the
1259 // cursor on the start of the row and move only the draw down as soon
1260 // as we move the cursor or do something while inside the row (it may
1261 // span several workarea-heights) we'll move to the top again, but this
1262 // is better than just jump down and only display part of the row.
1263 new_y = bv_->text->first_y + workarea_.height();
1265 if (text->inset_owner) {
1266 new_y = bv_->text->cursor.iy()
1267 + bv_->theLockingInset()->insetInInsetY()
1268 + y - text->cursor.row()->baseline();
1270 new_y = text->cursor.y() - text->cursor.row()->baseline();
1273 screen_->draw(bv_->text, bv_, new_y);
1274 if (text->cursor.row()->next()) {
1276 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1277 text->cursor.row()->next()->pos(), false);
1278 if (cur.y() < int(text->first_y + workarea_.height())) {
1279 text->cursorDown(bv_, true);
1286 bool BufferView::Pimpl::available() const
1288 if (buffer_ && bv_->text)
1294 void BufferView::Pimpl::beforeChange(LyXText * text)
1297 text->clearSelection();
1301 void BufferView::Pimpl::savePosition(unsigned int i)
1303 if (i >= saved_positions_num)
1305 saved_positions[i] = Position(buffer_->fileName(),
1306 bv_->text->cursor.par()->id(),
1307 bv_->text->cursor.pos());
1310 str << _("Saved bookmark") << ' ' << i;
1311 owner_->message(str.str().c_str());
1316 void BufferView::Pimpl::restorePosition(unsigned int i)
1318 if (i >= saved_positions_num)
1321 string const fname = saved_positions[i].filename;
1323 beforeChange(bv_->text);
1325 if (fname != buffer_->fileName()) {
1326 Buffer * b = bufferlist.exists(fname) ?
1327 bufferlist.getBuffer(fname) :
1328 bufferlist.loadLyXFile(fname); // don't ask, just load it
1329 if (b != 0) buffer(b);
1332 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1336 bv_->text->setCursor(bv_, par,
1337 min(par->size(), saved_positions[i].par_pos));
1339 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1342 str << _("Moved to bookmark") << ' ' << i;
1343 owner_->message(str.str().c_str());
1348 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1350 if (i >= saved_positions_num)
1353 return !saved_positions[i].filename.empty();
1357 void BufferView::Pimpl::setState()
1359 if (!lyxrc.rtl_support)
1362 LyXText * text = bv_->getLyXText();
1363 if (text->real_current_font.isRightToLeft()) {
1364 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1365 owner_->getIntl()->KeyMapSec();
1367 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1368 owner_->getIntl()->KeyMapPrim();
1373 void BufferView::Pimpl::insetSleep()
1375 if (bv_->theLockingInset() && !inset_slept) {
1376 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1377 bv_->theLockingInset()->insetUnlock(bv_);
1383 void BufferView::Pimpl::insetWakeup()
1385 if (bv_->theLockingInset() && inset_slept) {
1386 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1387 inset_slept = false;
1392 void BufferView::Pimpl::insetUnlock()
1394 if (bv_->theLockingInset()) {
1396 bv_->theLockingInset()->insetUnlock(bv_);
1397 bv_->theLockingInset(0);
1399 inset_slept = false;
1404 bool BufferView::Pimpl::focus() const
1406 return workarea_.hasFocus();
1410 void BufferView::Pimpl::focus(bool f)
1412 if (f) workarea_.setFocus();
1416 bool BufferView::Pimpl::active() const
1418 return workarea_.active();
1422 bool BufferView::Pimpl::belowMouse() const
1424 return workarea_.belowMouse();
1428 void BufferView::Pimpl::showCursor()
1430 if (screen_.get()) {
1431 if (bv_->theLockingInset())
1432 bv_->theLockingInset()->showInsetCursor(bv_);
1434 screen_->showCursor(bv_->text, bv_);
1439 void BufferView::Pimpl::hideCursor()
1441 if (screen_.get()) {
1442 if (!bv_->theLockingInset())
1443 // bv_->theLockingInset()->hideInsetCursor(bv_);
1445 screen_->hideCursor();
1450 void BufferView::Pimpl::toggleSelection(bool b)
1452 if (screen_.get()) {
1453 if (bv_->theLockingInset())
1454 bv_->theLockingInset()->toggleSelection(bv_, b);
1455 screen_->toggleSelection(bv_->text, bv_, b);
1460 void BufferView::Pimpl::toggleToggle()
1463 screen_->toggleToggle(bv_->text, bv_);
1467 void BufferView::Pimpl::center()
1469 beforeChange(bv_->text);
1470 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1471 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1473 screen_->draw(bv_->text, bv_, 0);
1475 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1480 void BufferView::Pimpl::pasteClipboard(bool asPara)
1485 screen_->hideCursor();
1486 beforeChange(bv_->text);
1488 string const clip(workarea_.getClipboard());
1494 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1496 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1498 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1502 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1504 workarea_.putClipboard(stuff);
1509 * Dispatch functions for actions which can be valid for BufferView->text
1510 * and/or InsetText->text!!!
1515 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1517 LyXText * lt = bv_->getLyXText();
1519 if (selecting || lt->selection.mark()) {
1520 lt->setSelection(bv_);
1524 updateInset(lt->inset_owner, false);
1528 update(lt, BufferView::SELECT|BufferView::FITCUR);
1530 update(lt, BufferView::SELECT);
1534 if (!lt->selection.set())
1535 workarea_.haveSelection(false);
1537 /* ---> Everytime the cursor is moved, show the current font state. */
1538 // should this too me moved out of this func?
1539 //owner->showState();
1544 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1546 LyXCursor cursor = bv_->getLyXText()->cursor;
1547 Buffer::inset_iterator it =
1548 find_if(Buffer::inset_iterator(
1549 cursor.par(), cursor.pos()),
1550 buffer_->inset_iterator_end(),
1551 lyx::compare_memfun(&Inset::lyxCode, code));
1552 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1556 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1558 string filename = filen;
1560 if (filename.empty()) {
1561 // Launch a file browser
1562 string initpath = lyxrc.document_path;
1565 string const trypath = owner_->buffer()->filePath();
1566 // If directory is writeable, use this as default.
1567 if (IsDirWriteable(trypath))
1571 FileDialog fileDlg(bv_->owner(),
1572 _("Select LyX document to insert"),
1574 make_pair(string(_("Documents|#o#O")),
1575 string(lyxrc.document_path)),
1576 make_pair(string(_("Examples|#E#e")),
1577 string(AddPath(system_lyxdir, "examples"))));
1579 FileDialog::Result result =
1580 fileDlg.Select(initpath,
1581 _("*.lyx| LyX Documents (*.lyx)"));
1583 if (result.first == FileDialog::Later)
1586 filename = result.second;
1588 // check selected filename
1589 if (filename.empty()) {
1590 owner_->message(_("Canceled."));
1595 // get absolute path of file and add ".lyx" to the filename if
1597 filename = FileSearch(string(), filename, "lyx");
1599 string const disp_fn(MakeDisplayPath(filename));
1602 s1 << _("Inserting document") << ' '
1603 << disp_fn << " ...";
1604 owner_->message(s1.str().c_str());
1605 bool const res = bv_->insertLyXFile(filename);
1608 str << _("Document") << ' ' << disp_fn
1609 << ' ' << _("inserted.");
1610 owner_->message(str.str().c_str());
1613 str << _("Could not insert document") << ' '
1615 owner_->message(str.str().c_str());
1620 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1622 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1623 << action <<"] arg[" << argument << "]" << endl;
1626 // --- Misc -------------------------------------------
1630 LyXText * lt = bv_->getLyXText();
1631 lt->toggleAppendix(bv_);
1634 | BufferView::FITCUR
1635 | BufferView::CHANGE);
1640 case LFUN_TOC_INSERT:
1642 InsetCommandParams p;
1643 p.setCmdName("tableofcontents");
1644 Inset * inset = new InsetTOC(p);
1645 if (!insertInset(inset, "Standard"))
1650 case LFUN_SCROLL_INSET:
1651 // this is not handled here as this funktion is only aktive
1652 // if we have a locking_inset and that one is (or contains)
1656 case LFUN_INSET_GRAPHICS:
1658 Inset * new_inset = new InsetGraphics;
1659 if (!insertInset(new_inset)) {
1662 // this is need because you don't use a inset->Edit()
1663 updateInset(new_inset, true);
1664 new_inset->edit(bv_);
1674 case LFUN_PASTESELECTION:
1676 bool asPara = false;
1677 if (argument == "paragraph")
1679 pasteClipboard(asPara);
1691 case LFUN_LAYOUT_COPY:
1692 bv_->copyEnvironment();
1695 case LFUN_LAYOUT_PASTE:
1696 bv_->pasteEnvironment();
1700 case LFUN_GOTOERROR:
1701 gotoInset(Inset::ERROR_CODE, false);
1705 gotoInset(Inset::IGNORE_CODE, false);
1708 case LFUN_REFERENCE_GOTO:
1710 vector<Inset::Code> tmp;
1711 tmp.push_back(Inset::LABEL_CODE);
1712 tmp.push_back(Inset::REF_CODE);
1713 gotoInset(tmp, true);
1717 case LFUN_HYPHENATION:
1718 specialChar(InsetSpecialChar::HYPHENATION);
1721 case LFUN_LIGATURE_BREAK:
1722 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1726 specialChar(InsetSpecialChar::LDOTS);
1729 case LFUN_END_OF_SENTENCE:
1730 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1733 case LFUN_MENU_SEPARATOR:
1734 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1741 case LFUN_DEPTH_MIN:
1742 changeDepth(bv_, bv_->getLyXText(), -1);
1745 case LFUN_DEPTH_PLUS:
1746 changeDepth(bv_, bv_->getLyXText(), 1);
1750 owner_->getDialogs()->setUserFreeFont();
1753 case LFUN_FILE_INSERT:
1754 MenuInsertLyXFile(argument);
1757 case LFUN_FILE_INSERT_ASCII_PARA:
1758 InsertAsciiFile(bv_, argument, true);
1761 case LFUN_FILE_INSERT_ASCII:
1762 InsertAsciiFile(bv_, argument, false);
1767 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1768 << argument << endl;
1770 // Derive layout number from given argument (string)
1771 // and current buffer's textclass (number). */
1772 textclass_type tclass = buffer_->params.textclass;
1774 textclasslist[tclass].hasLayout(argument);
1775 string layout = argument;
1777 // If the entry is obsolete, use the new one instead.
1779 string const & obs = textclasslist[tclass][layout]
1786 owner_->getLyXFunc()->setErrorMessage(
1787 string(N_("Layout ")) + argument +
1792 bool change_layout = (current_layout != layout);
1793 LyXText * lt = bv_->getLyXText();
1794 if (!change_layout && lt->selection.set() &&
1795 lt->selection.start.par() != lt->selection.end.par())
1797 Paragraph * spar = lt->selection.start.par();
1798 Paragraph * epar = lt->selection.end.par()->next();
1799 while(spar != epar) {
1800 if (spar->layout() != current_layout) {
1801 change_layout = true;
1806 if (change_layout) {
1808 current_layout = layout;
1811 | BufferView::FITCUR);
1812 lt->setLayout(bv_, layout);
1813 owner_->setLayout(layout);
1816 | BufferView::FITCUR
1817 | BufferView::CHANGE);
1824 lang(bv_, argument);
1826 owner_->showState();
1831 owner_->showState();
1836 owner_->showState();
1841 owner_->showState();
1846 owner_->showState();
1851 owner_->showState();
1856 owner_->showState();
1861 owner_->showState();
1864 case LFUN_UNDERLINE:
1866 owner_->showState();
1869 case LFUN_FONT_SIZE:
1870 fontSize(bv_, argument);
1871 owner_->showState();
1874 case LFUN_FONT_STATE:
1875 owner_->getLyXFunc()->setMessage(currentState(bv_));
1878 case LFUN_UPCASE_WORD:
1880 LyXText * lt = bv_->getLyXText();
1884 | BufferView::FITCUR);
1885 lt->changeCase(bv_, LyXText::text_uppercase);
1886 if (lt->inset_owner)
1887 updateInset(lt->inset_owner, true);
1890 | BufferView::FITCUR
1891 | BufferView::CHANGE);
1895 case LFUN_LOWCASE_WORD:
1897 LyXText * lt = bv_->getLyXText();
1899 update(lt, BufferView::SELECT|BufferView::FITCUR);
1900 lt->changeCase(bv_, LyXText::text_lowercase);
1901 if (lt->inset_owner)
1902 updateInset(lt->inset_owner, true);
1905 | BufferView::FITCUR
1906 | BufferView::CHANGE);
1910 case LFUN_CAPITALIZE_WORD:
1912 LyXText * lt = bv_->getLyXText();
1914 update(lt, BufferView::SELECT|BufferView::FITCUR);
1915 lt->changeCase(bv_, LyXText::text_capitalization);
1916 if (lt->inset_owner)
1917 updateInset(lt->inset_owner, true);
1920 | BufferView::FITCUR
1921 | BufferView::CHANGE);
1925 case LFUN_TRANSPOSE_CHARS:
1927 LyXText * lt = bv_->getLyXText();
1929 update(lt, BufferView::SELECT|BufferView::FITCUR);
1930 lt->transposeChars(*bv_);
1931 if (lt->inset_owner)
1932 updateInset(lt->inset_owner, true);
1935 | BufferView::FITCUR
1936 | BufferView::CHANGE);
1941 case LFUN_INSERT_LABEL:
1942 MenuInsertLabel(bv_, argument);
1945 case LFUN_REF_INSERT:
1946 if (argument.empty()) {
1947 InsetCommandParams p("ref");
1948 owner_->getDialogs()->createRef(p.getAsString());
1950 InsetCommandParams p;
1951 p.setFromString(argument);
1953 InsetRef * inset = new InsetRef(p, *buffer_);
1954 if (!insertInset(inset))
1957 updateInset(inset, true);
1961 case LFUN_BOOKMARK_SAVE:
1962 savePosition(strToUnsignedInt(argument));
1965 case LFUN_BOOKMARK_GOTO:
1966 restorePosition(strToUnsignedInt(argument));
1971 string label(argument);
1972 if (label.empty()) {
1974 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1976 label = inset->getContents();
1981 if (!label.empty()) {
1982 //bv_->savePosition(0);
1983 if (!bv_->gotoLabel(label))
1984 Alert::alert(_("Error"),
1985 _("Couldn't find this label"),
1986 _("in current document."));
1991 // --- Cursor Movements -----------------------------
1994 LyXText * lt = bv_->getLyXText();
1996 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1997 if (!lt->selection.mark())
1999 update(lt, BufferView::SELECT|BufferView::FITCUR);
2001 lt->cursorLeft(bv_, false);
2002 if (lt->cursor.pos() < lt->cursor.par()->size()
2003 && lt->cursor.par()->isInset(lt->cursor.pos())
2004 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2005 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2006 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2008 tmpinset->edit(bv_, false);
2010 tmpinset->edit(bv_);
2014 lt->cursorRight(bv_, false);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2023 // This is soooo ugly. Isn`t it possible to make
2024 // it simpler? (Lgb)
2025 LyXText * lt = bv_->getLyXText();
2026 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2027 if (!lt->selection.mark())
2029 update(lt, BufferView::SELECT|BufferView::FITCUR);
2030 LyXCursor const cur = lt->cursor;
2032 lt->cursorLeft(bv_, false);
2033 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2034 lt->cursor.pos() < lt->cursor.par()->size() &&
2035 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2036 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2037 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2038 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2040 tmpinset->edit(bv_);
2042 tmpinset->edit(bv_, false);
2046 lt->cursorRight(bv_, false);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2056 LyXText * lt = bv_->getLyXText();
2058 if (!lt->selection.mark())
2060 update(lt, BufferView::UPDATE);
2063 moveCursorUpdate(false);
2064 owner_->showState();
2070 LyXText * lt = bv_->getLyXText();
2072 if (!lt->selection.mark())
2074 update(lt, BufferView::UPDATE);
2075 lt->cursorDown(bv_);
2077 moveCursorUpdate(false);
2078 owner_->showState();
2082 case LFUN_UP_PARAGRAPH:
2084 LyXText * lt = bv_->getLyXText();
2086 if (!lt->selection.mark())
2088 update(lt, BufferView::UPDATE);
2089 lt->cursorUpParagraph(bv_);
2091 moveCursorUpdate(false);
2092 owner_->showState();
2096 case LFUN_DOWN_PARAGRAPH:
2098 LyXText * lt = bv_->getLyXText();
2100 if (!lt->selection.mark())
2102 update(lt, BufferView::UPDATE);
2103 lt->cursorDownParagraph(bv_);
2105 moveCursorUpdate(false);
2106 owner_->showState();
2112 LyXText * lt = bv_->getLyXText();
2114 if (!lt->selection.mark())
2116 update(lt, BufferView::UPDATE);
2119 moveCursorUpdate(false, false);
2120 owner_->showState();
2126 LyXText * lt = bv_->getLyXText();
2128 if (!lt->selection.mark())
2130 update(lt, BufferView::UPDATE);
2133 moveCursorUpdate(false, false);
2134 owner_->showState();
2140 LyXText * lt = bv_->getLyXText();
2142 if (!lt->selection.mark())
2144 update(lt, BufferView::SELECT|BufferView::FITCUR);
2145 lt->cursorHome(bv_);
2147 moveCursorUpdate(false);
2148 owner_->showState();
2154 LyXText * lt = bv_->getLyXText();
2156 if (!lt->selection.mark())
2159 BufferView::SELECT|BufferView::FITCUR);
2162 moveCursorUpdate(false);
2163 owner_->showState();
2167 case LFUN_SHIFT_TAB:
2170 LyXText * lt = bv_->getLyXText();
2172 if (!lt->selection.mark())
2175 BufferView::SELECT|BufferView::FITCUR);
2178 moveCursorUpdate(false);
2179 owner_->showState();
2183 case LFUN_WORDRIGHT:
2185 LyXText * lt = bv_->getLyXText();
2187 if (!lt->selection.mark())
2189 update(lt, BufferView::SELECT|BufferView::FITCUR);
2190 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2191 lt->cursorLeftOneWord(bv_);
2193 lt->cursorRightOneWord(bv_);
2195 moveCursorUpdate(false);
2196 owner_->showState();
2202 LyXText * lt = bv_->getLyXText();
2204 if (!lt->selection.mark())
2206 update(lt, BufferView::SELECT|BufferView::FITCUR);
2207 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2208 lt->cursorRightOneWord(bv_);
2210 lt->cursorLeftOneWord(bv_);
2212 moveCursorUpdate(false);
2213 owner_->showState();
2217 case LFUN_BEGINNINGBUF:
2219 LyXText * lt = bv_->getLyXText();
2221 if (!lt->selection.mark())
2224 BufferView::SELECT|BufferView::FITCUR);
2227 moveCursorUpdate(false);
2228 owner_->showState();
2234 LyXText * lt = bv_->getLyXText();
2236 if (!lt->selection.mark())
2239 BufferView::SELECT|BufferView::FITCUR);
2240 lt->cursorBottom(bv_);
2242 moveCursorUpdate(false);
2243 owner_->showState();
2247 /* cursor selection ---------------------------- */
2250 LyXText * lt = bv_->getLyXText();
2253 BufferView::SELECT|BufferView::FITCUR);
2254 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2255 lt->cursorLeft(bv_);
2257 lt->cursorRight(bv_);
2259 moveCursorUpdate(true);
2260 owner_->showState();
2266 LyXText * lt = bv_->getLyXText();
2269 BufferView::SELECT|BufferView::FITCUR);
2270 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2271 lt->cursorRight(bv_);
2273 lt->cursorLeft(bv_);
2275 moveCursorUpdate(true);
2276 owner_->showState();
2282 LyXText * lt = bv_->getLyXText();
2285 BufferView::SELECT|BufferView::FITCUR);
2286 lt->cursorUp(bv_, true);
2288 moveCursorUpdate(true);
2289 owner_->showState();
2295 LyXText * lt = bv_->getLyXText();
2298 BufferView::SELECT|BufferView::FITCUR);
2299 lt->cursorDown(bv_, true);
2301 moveCursorUpdate(true);
2302 owner_->showState();
2306 case LFUN_UP_PARAGRAPHSEL:
2308 LyXText * lt = bv_->getLyXText();
2311 BufferView::SELECT|BufferView::FITCUR);
2312 lt->cursorUpParagraph(bv_);
2314 moveCursorUpdate(true);
2315 owner_->showState();
2319 case LFUN_DOWN_PARAGRAPHSEL:
2321 LyXText * lt = bv_->getLyXText();
2324 BufferView::SELECT|BufferView::FITCUR);
2325 lt->cursorDownParagraph(bv_);
2327 moveCursorUpdate(true);
2328 owner_->showState();
2334 LyXText * lt = bv_->getLyXText();
2336 update(lt, BufferView::SELECT|BufferView::FITCUR);
2339 moveCursorUpdate(true);
2340 owner_->showState();
2346 LyXText * lt = bv_->getLyXText();
2348 update(lt, BufferView::SELECT|BufferView::FITCUR);
2351 moveCursorUpdate(true);
2352 owner_->showState();
2358 LyXText * lt = bv_->getLyXText();
2360 update(lt, BufferView::SELECT|BufferView::FITCUR);
2361 lt->cursorHome(bv_);
2363 moveCursorUpdate(true);
2364 owner_->showState();
2370 LyXText * lt = bv_->getLyXText();
2372 update(lt, BufferView::SELECT|BufferView::FITCUR);
2375 moveCursorUpdate(true);
2376 owner_->showState();
2380 case LFUN_WORDRIGHTSEL:
2382 LyXText * lt = bv_->getLyXText();
2384 update(lt, BufferView::SELECT|BufferView::FITCUR);
2385 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2386 lt->cursorLeftOneWord(bv_);
2388 lt->cursorRightOneWord(bv_);
2390 moveCursorUpdate(true);
2391 owner_->showState();
2395 case LFUN_WORDLEFTSEL:
2397 LyXText * lt = bv_->getLyXText();
2399 update(lt, BufferView::SELECT|BufferView::FITCUR);
2400 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2401 lt->cursorRightOneWord(bv_);
2403 lt->cursorLeftOneWord(bv_);
2405 moveCursorUpdate(true);
2406 owner_->showState();
2410 case LFUN_BEGINNINGBUFSEL:
2412 LyXText * lt = bv_->getLyXText();
2414 if (lt->inset_owner)
2416 update(lt, BufferView::SELECT|BufferView::FITCUR);
2419 moveCursorUpdate(true);
2420 owner_->showState();
2424 case LFUN_ENDBUFSEL:
2426 LyXText * lt = bv_->getLyXText();
2428 if (lt->inset_owner)
2431 BufferView::SELECT|BufferView::FITCUR);
2432 lt->cursorBottom(bv_);
2434 moveCursorUpdate(true);
2435 owner_->showState();
2439 // --- text changing commands ------------------------
2440 case LFUN_BREAKLINE:
2442 LyXText * lt = bv_->getLyXText();
2445 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2448 | BufferView::FITCUR
2449 | BufferView::CHANGE);
2450 moveCursorUpdate(false);
2454 case LFUN_PROTECTEDSPACE:
2456 LyXText * lt = bv_->getLyXText();
2458 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2460 if (style.free_spacing) {
2461 lt->insertChar(bv_, ' ');
2464 | BufferView::FITCUR
2465 | BufferView::CHANGE);
2467 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2469 moveCursorUpdate(false);
2475 LyXText * lt = bv_->getLyXText();
2477 if (lt->selection.mark()) {
2481 | BufferView::FITCUR);
2482 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2485 lt->selection.mark(true);
2488 | BufferView::FITCUR);
2489 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2491 lt->selection.cursor = lt->cursor;
2497 LyXText * lt = bv_->getLyXText();
2499 if (!lt->selection.set()) {
2501 lt->selection.cursor = lt->cursor;
2504 | BufferView::FITCUR
2505 | BufferView::CHANGE);
2506 // It is possible to make it a lot faster still
2507 // just comment out the line below...
2512 moveCursorUpdate(false);
2513 owner_->showState();
2518 case LFUN_DELETE_SKIP:
2520 LyXText * lt = bv_->getLyXText();
2522 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2524 LyXCursor cursor = lt->cursor;
2526 if (!lt->selection.set()) {
2527 if (cursor.pos() == cursor.par()->size()) {
2528 lt->cursorRight(bv_);
2529 cursor = lt->cursor;
2530 if (cursor.pos() == 0
2531 && !(cursor.par()->params().spaceTop()
2532 == VSpace (VSpace::NONE))) {
2535 cursor.par()->params().lineTop(),
2536 cursor.par()->params().lineBottom(),
2537 cursor.par()->params().pagebreakTop(),
2538 cursor.par()->params().pagebreakBottom(),
2539 VSpace(VSpace::NONE),
2540 cursor.par()->params().spaceBottom(),
2541 cursor.par()->params().spacing(),
2542 cursor.par()->params().align(),
2543 cursor.par()->params().labelWidthString(), 0);
2544 lt->cursorLeft(bv_);
2547 | BufferView::FITCUR
2548 | BufferView::CHANGE);
2550 lt->cursorLeft(bv_);
2552 lt->selection.cursor = lt->cursor;
2555 | BufferView::FITCUR
2556 | BufferView::CHANGE);
2560 lt->selection.cursor = lt->cursor;
2563 | BufferView::FITCUR
2564 | BufferView::CHANGE);
2572 /* -------> Delete word forward. */
2573 case LFUN_DELETE_WORD_FORWARD:
2574 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2575 bv_->getLyXText()->deleteWordForward(bv_);
2576 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2577 moveCursorUpdate(false);
2578 owner_->showState();
2581 /* -------> Delete word backward. */
2582 case LFUN_DELETE_WORD_BACKWARD:
2584 LyXText * lt = bv_->getLyXText();
2586 update(lt, BufferView::SELECT|BufferView::FITCUR);
2587 lt->deleteWordBackward(bv_);
2590 | BufferView::FITCUR
2591 | BufferView::CHANGE);
2592 moveCursorUpdate(false);
2593 owner_->showState();
2597 /* -------> Kill to end of line. */
2598 case LFUN_DELETE_LINE_FORWARD:
2600 LyXText * lt = bv_->getLyXText();
2602 update(lt, BufferView::SELECT|BufferView::FITCUR);
2603 lt->deleteLineForward(bv_);
2606 | BufferView::FITCUR
2607 | BufferView::CHANGE);
2608 moveCursorUpdate(false);
2612 /* -------> Set mark off. */
2615 LyXText * lt = bv_->getLyXText();
2618 update(lt, BufferView::SELECT|BufferView::FITCUR);
2619 lt->selection.cursor = lt->cursor;
2620 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2624 /* -------> Set mark on. */
2627 LyXText * lt = bv_->getLyXText();
2630 lt->selection.mark(true);
2631 update(lt, BufferView::SELECT|BufferView::FITCUR);
2632 lt->selection.cursor = lt->cursor;
2633 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2637 case LFUN_BACKSPACE:
2639 LyXText * lt = bv_->getLyXText();
2641 if (!lt->selection.set()) {
2642 if (owner_->getIntl()->getTrans().backspace()) {
2644 lt->selection.cursor = lt->cursor;
2647 | BufferView::FITCUR
2648 | BufferView::CHANGE);
2649 // It is possible to make it a lot faster still
2650 // just comment out the line below...
2656 owner_->showState();
2661 case LFUN_BACKSPACE_SKIP:
2663 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2664 LyXText * lt = bv_->getLyXText();
2666 LyXCursor cursor = lt->cursor;
2668 if (!lt->selection.set()) {
2669 if (cursor.pos() == 0
2670 && !(cursor.par()->params().spaceTop()
2671 == VSpace (VSpace::NONE))) {
2674 cursor.par()->params().lineTop(),
2675 cursor.par()->params().lineBottom(),
2676 cursor.par()->params().pagebreakTop(),
2677 cursor.par()->params().pagebreakBottom(),
2678 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2679 cursor.par()->params().spacing(),
2680 cursor.par()->params().align(),
2681 cursor.par()->params().labelWidthString(), 0);
2684 | BufferView::FITCUR
2685 | BufferView::CHANGE);
2688 lt->selection.cursor = cursor;
2691 | BufferView::FITCUR
2692 | BufferView::CHANGE);
2699 case LFUN_BREAKPARAGRAPH:
2701 LyXText * lt = bv_->getLyXText();
2704 lt->breakParagraph(bv_, 0);
2707 | BufferView::FITCUR
2708 | BufferView::CHANGE);
2709 lt->selection.cursor = lt->cursor;
2711 owner_->showState();
2715 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2717 LyXText * lt = bv_->getLyXText();
2720 lt->breakParagraph(bv_, 1);
2723 | BufferView::FITCUR
2724 | BufferView::CHANGE);
2725 lt->selection.cursor = lt->cursor;
2727 owner_->showState();
2731 case LFUN_BREAKPARAGRAPH_SKIP:
2733 // When at the beginning of a paragraph, remove
2734 // indentation and add a "defskip" at the top.
2735 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2736 LyXText * lt = bv_->getLyXText();
2738 LyXCursor cursor = lt->cursor;
2741 if (cursor.pos() == 0) {
2742 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2745 cursor.par()->params().lineTop(),
2746 cursor.par()->params().lineBottom(),
2747 cursor.par()->params().pagebreakTop(),
2748 cursor.par()->params().pagebreakBottom(),
2749 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2750 cursor.par()->params().spacing(),
2751 cursor.par()->params().align(),
2752 cursor.par()->params().labelWidthString(), 1);
2753 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2757 lt->breakParagraph(bv_, 0);
2758 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2763 | BufferView::FITCUR
2764 | BufferView::CHANGE);
2765 lt->selection.cursor = cursor;
2767 owner_->showState();
2771 case LFUN_PARAGRAPH_SPACING:
2773 LyXText * lt = bv_->getLyXText();
2775 Paragraph * par = lt->cursor.par();
2776 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2777 float cur_value = 1.0;
2778 if (cur_spacing == Spacing::Other) {
2779 cur_value = par->params().spacing().getValue();
2782 istringstream istr(argument.c_str());
2786 Spacing::Space new_spacing = cur_spacing;
2787 float new_value = cur_value;
2789 lyxerr << "Missing argument to `paragraph-spacing'"
2791 } else if (tmp == "single") {
2792 new_spacing = Spacing::Single;
2793 } else if (tmp == "onehalf") {
2794 new_spacing = Spacing::Onehalf;
2795 } else if (tmp == "double") {
2796 new_spacing = Spacing::Double;
2797 } else if (tmp == "other") {
2798 new_spacing = Spacing::Other;
2801 lyxerr << "new_value = " << tmpval << endl;
2804 } else if (tmp == "default") {
2805 new_spacing = Spacing::Default;
2807 lyxerr << _("Unknown spacing argument: ")
2808 << argument << endl;
2810 if (cur_spacing != new_spacing || cur_value != new_value) {
2811 par->params().spacing(Spacing(new_spacing, new_value));
2812 lt->redoParagraph(bv_);
2815 | BufferView::FITCUR
2816 | BufferView::CHANGE);
2821 case LFUN_INSET_TOGGLE:
2823 LyXText * lt = bv_->getLyXText();
2826 update(lt, BufferView::SELECT|BufferView::FITCUR);
2827 lt->toggleInset(bv_);
2828 update(lt, BufferView::SELECT|BufferView::FITCUR);
2840 InsetCommandParams p;
2841 if (action == LFUN_HTMLURL)
2842 p.setCmdName("htmlurl");
2844 p.setCmdName("url");
2845 owner_->getDialogs()->createUrl(p.getAsString());
2849 case LFUN_INSERT_URL:
2851 InsetCommandParams p;
2852 p.setFromString(argument);
2854 InsetUrl * inset = new InsetUrl(p);
2855 if (!insertInset(inset))
2858 updateInset(inset, true);
2862 case LFUN_INSET_ERT:
2863 insertAndEditInset(new InsetERT(buffer_->params));
2866 case LFUN_INSET_EXTERNAL:
2867 insertAndEditInset(new InsetExternal);
2870 case LFUN_INSET_FOOTNOTE:
2871 insertAndEditInset(new InsetFoot(buffer_->params));
2874 case LFUN_INSET_MARGINAL:
2875 insertAndEditInset(new InsetMarginal(buffer_->params));
2878 case LFUN_INSET_MINIPAGE:
2879 insertAndEditInset(new InsetMinipage(buffer_->params));
2882 case LFUN_INSERT_NOTE:
2883 insertAndEditInset(new InsetNote(buffer_->params));
2886 case LFUN_INSET_FLOAT:
2887 // check if the float type exist
2888 if (floatList.typeExist(argument)) {
2889 insertAndEditInset(new InsetFloat(buffer_->params,
2892 lyxerr << "Non-existent float type: "
2893 << argument << endl;
2897 case LFUN_INSET_WIDE_FLOAT:
2899 // check if the float type exist
2900 if (floatList.typeExist(argument)) {
2901 InsetFloat * new_inset =
2902 new InsetFloat(buffer_->params, argument);
2903 new_inset->wide(true);
2904 if (insertInset(new_inset))
2905 new_inset->edit(bv_);
2909 lyxerr << "Non-existent float type: "
2910 << argument << endl;
2917 case LFUN_INSET_LIST:
2918 insertAndEditInset(new InsetList);
2921 case LFUN_INSET_THEOREM:
2922 insertAndEditInset(new InsetTheorem);
2926 case LFUN_INSET_CAPTION:
2928 // Do we have a locking inset...
2929 if (bv_->theLockingInset()) {
2930 lyxerr << "Locking inset code: "
2931 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2932 InsetCaption * new_inset =
2933 new InsetCaption(buffer_->params);
2934 new_inset->setOwner(bv_->theLockingInset());
2935 new_inset->setAutoBreakRows(true);
2936 new_inset->setDrawFrame(0, InsetText::LOCKED);
2937 new_inset->setFrameColor(0, LColor::captionframe);
2938 if (insertInset(new_inset))
2939 new_inset->edit(bv_);
2946 case LFUN_INSET_TABULAR:
2950 if (!argument.empty())
2951 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2952 InsetTabular * new_inset =
2953 new InsetTabular(*buffer_, r, c);
2955 bv_->getLyXText()->real_current_font.isRightToLeft();
2956 if (!open_new_inset(new_inset, rtl))
2961 // --- lyxserver commands ----------------------------
2963 case LFUN_CHARATCURSOR:
2965 pos_type pos = bv_->getLyXText()->cursor.pos();
2966 if (pos < bv_->getLyXText()->cursor.par()->size())
2967 owner_->getLyXFunc()->setMessage(
2968 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2970 owner_->getLyXFunc()->setMessage("EOF");
2975 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2977 + tostr(bv_->getLyXText()->cursor.y()));
2984 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2985 lyxerr << "SETXY: Could not parse coordinates in '"
2986 << argument << std::endl;
2988 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2992 case LFUN_GETLAYOUT:
2993 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2998 LyXFont & font = bv_->getLyXText()->current_font;
2999 if (font.shape() == LyXFont::ITALIC_SHAPE)
3000 owner_->getLyXFunc()->setMessage("E");
3001 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3002 owner_->getLyXFunc()->setMessage("N");
3004 owner_->getLyXFunc()->setMessage("0");
3009 // --- accented characters ---------------------------
3012 case LFUN_CIRCUMFLEX:
3022 case LFUN_SPECIAL_CARON:
3025 case LFUN_HUNG_UMLAUT:
3028 if (argument.empty()) {
3030 owner_->getLyXFunc()->handleKeyFunc(action);
3032 owner_->getLyXFunc()->handleKeyFunc(action);
3033 owner_->getIntl()->getTrans()
3034 .TranslateAndInsert(argument[0], bv_->getLyXText());
3035 update(bv_->getLyXText(),
3037 | BufferView::FITCUR
3038 | BufferView::CHANGE);
3042 case LFUN_MATH_MACRO:
3043 mathDispatchMathMacro(bv_, argument);
3046 case LFUN_MATH_DELIM:
3047 mathDispatchMathDelim(bv_, argument);
3050 case LFUN_INSERT_MATRIX:
3051 mathDispatchInsertMatrix(bv_, argument);
3054 case LFUN_INSERT_MATH:
3055 mathDispatchInsertMath(bv_, argument);
3058 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3059 mathDispatchMathImportSelection(bv_, argument);
3062 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3063 mathDispatchMathDisplay(bv_, argument);
3066 case LFUN_MATH_MODE: // Open or create an inlined math inset
3067 mathDispatchMathMode(bv_, argument);
3070 case LFUN_GREEK: // Insert a single greek letter
3071 mathDispatchGreek(bv_, argument);
3074 case LFUN_CITATION_INSERT:
3076 InsetCommandParams p;
3077 p.setFromString(argument);
3079 InsetCitation * inset = new InsetCitation(p);
3080 if (!insertInset(inset))
3083 updateInset(inset, true);
3087 case LFUN_INSERT_BIBTEX:
3089 // ale970405+lasgoutt970425
3090 // The argument can be up to two tokens separated
3091 // by a space. The first one is the bibstyle.
3092 string const db = token(argument, ' ', 0);
3093 string const bibstyle = token(argument, ' ', 1);
3095 InsetCommandParams p("BibTeX", db, bibstyle);
3096 InsetBibtex * inset = new InsetBibtex(p);
3098 if (insertInset(inset)) {
3099 if (argument.empty())
3106 // BibTeX data bases
3107 case LFUN_BIBDB_ADD:
3109 InsetBibtex * inset =
3110 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3112 inset->addDatabase(argument);
3117 case LFUN_BIBDB_DEL:
3119 InsetBibtex * inset =
3120 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3122 inset->delDatabase(argument);
3127 case LFUN_BIBTEX_STYLE:
3129 InsetBibtex * inset =
3130 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3132 inset->setOptions(argument);
3137 case LFUN_INDEX_CREATE:
3139 InsetCommandParams p("index");
3140 if (argument.empty()) {
3141 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3142 p.setContents(idxstring);
3144 p.setContents(argument);
3147 owner_->getDialogs()->createIndex(p.getAsString());
3151 case LFUN_INDEX_INSERT:
3153 InsetCommandParams p;
3154 p.setFromString(argument);
3155 InsetIndex * inset = new InsetIndex(p);
3157 if (!insertInset(inset))
3160 updateInset(inset, true);
3164 case LFUN_INDEX_INSERT_LAST:
3166 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3167 if (!idxstring.empty()) {
3168 owner_->message(_("Word `")
3169 + idxstring + _(("' indexed.")));
3170 InsetCommandParams p("index", idxstring);
3171 InsetIndex * inset = new InsetIndex(p);
3173 if (!insertInset(inset))
3176 updateInset(inset, true);
3181 case LFUN_INDEX_PRINT:
3183 InsetCommandParams p("printindex");
3184 Inset * inset = new InsetPrintIndex(p);
3185 if (!insertInset(inset, "Standard"))
3190 case LFUN_PARENTINSERT:
3192 InsetCommandParams p("lyxparent", argument);
3193 Inset * inset = new InsetParent(p, *buffer_);
3194 if (!insertInset(inset, "Standard"))
3200 case LFUN_CHILD_INSERT:
3202 InsetInclude::Params p;
3203 p.cparams.setFromString(argument);
3204 p.masterFilename_ = buffer_->fileName();
3206 InsetInclude * inset = new InsetInclude(p);
3207 if (!insertInset(inset))
3210 updateInset(inset, true);
3211 bv_->owner()->getDialogs()->showInclude(inset);
3216 case LFUN_FLOAT_LIST:
3218 // We should check the argument for validity. (Lgb)
3219 Inset * inset = new InsetFloatList(argument);
3220 if (!insertInset(inset, "Standard"))
3225 case LFUN_THESAURUS_ENTRY:
3227 string arg = argument;
3230 arg = bv_->getLyXText()->selectionAsString(buffer_,
3234 if (arg.size() > 100 || arg.empty()) {
3235 // Get word or selection
3236 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3237 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3238 // FIXME: where is getLyXText()->unselect(bv_) ?
3242 bv_->owner()->getDialogs()->showThesaurus(arg);
3246 case LFUN_SELFINSERT:
3248 if (argument.empty()) break;
3250 /* Automatically delete the currently selected
3251 * text and replace it with what is being
3252 * typed in now. Depends on lyxrc settings
3253 * "auto_region_delete", which defaults to
3256 LyXText * lt = bv_->getLyXText();
3258 if (lyxrc.auto_region_delete) {
3259 if (lt->selection.set()) {
3260 lt->cutSelection(bv_, false, false);
3263 | BufferView::FITCUR
3264 | BufferView::CHANGE);
3266 workarea_.haveSelection(false);
3270 LyXFont const old_font(lt->real_current_font);
3272 string::const_iterator cit = argument.begin();
3273 string::const_iterator end = argument.end();
3274 for (; cit != end; ++cit) {
3275 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3280 | BufferView::FITCUR
3281 | BufferView::CHANGE);
3283 lt->selection.cursor = lt->cursor;
3284 moveCursorUpdate(false);
3286 // real_current_font.number can change so we need to
3287 // update the minibuffer
3288 if (old_font != lt->real_current_font)
3289 owner_->showState();
3294 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3296 time_t now_time_t = time(NULL);
3297 struct tm * now_tm = localtime(&now_time_t);
3298 setlocale(LC_TIME, "");
3300 if (!argument.empty())
3303 arg = lyxrc.date_insert_format;
3305 int const datetmp_len =
3306 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3308 LyXText * lt = bv_->getLyXText();
3310 for (int i = 0; i < datetmp_len; i++) {
3311 lt->insertChar(bv_, datetmp[i]);
3314 | BufferView::FITCUR
3315 | BufferView::CHANGE);
3318 lt->selection.cursor = lt->cursor;
3319 moveCursorUpdate(false);
3323 case LFUN_UNKNOWN_ACTION:
3324 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3335 void BufferView::Pimpl::newline()
3338 LyXText * lt = bv_->getLyXText();
3342 | BufferView::FITCUR);
3343 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3346 | BufferView::FITCUR
3347 | BufferView::CHANGE);
3352 void BufferView::Pimpl::hfill()
3355 LyXText * lt = bv_->getLyXText();
3359 | BufferView::FITCUR);
3360 lt->insertChar(bv_, Paragraph::META_HFILL);
3363 | BufferView::FITCUR
3364 | BufferView::CHANGE);
3369 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3372 LyXText * lt = bv_->getLyXText();
3375 update(lt, BufferView::SELECT|BufferView::FITCUR);
3376 InsetSpecialChar * new_inset =
3377 new InsetSpecialChar(kind);
3378 if (!insertInset(new_inset))
3381 updateInset(new_inset, true);
3386 void BufferView::Pimpl::smartQuote()
3388 LyXText const * lt = bv_->getLyXText();
3389 Paragraph const * par = lt->cursor.par();
3390 pos_type pos = lt->cursor.pos();
3394 || (par->isInset(pos - 1)
3395 && par->getInset(pos - 1)->isSpace()))
3398 c = par->getChar(pos - 1);
3403 LyXLayout const & style =
3404 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3406 if (style.pass_thru ||
3407 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3408 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3412 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3414 if (insertInset(inset))
3421 // Open and lock an updatable inset
3422 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3424 LyXText * lt = bv_->getLyXText();
3428 if (!insertInset(new_inset)) {
3432 new_inset->edit(bv_, !behind);
3437 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3439 // if we are in a locking inset we should try to insert the
3440 // inset there otherwise this is a illegal function now
3441 if (bv_->theLockingInset()) {
3442 if (bv_->theLockingInset()->insetAllowed(inset))
3443 return bv_->theLockingInset()->insertInset(bv_, inset);
3447 // not quite sure if we want this...
3448 setCursorParUndo(bv_);
3451 beforeChange(bv_->text);
3452 if (!lout.empty()) {
3453 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3454 bv_->text->breakParagraph(bv_);
3455 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3457 if (bv_->text->cursor.par()->size()) {
3458 bv_->text->cursorLeft(bv_);
3460 bv_->text->breakParagraph(bv_);
3461 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3465 LyXTextClass const & tclass =
3466 textclasslist[buffer_->params.textclass];
3467 bool hasLayout = tclass.hasLayout(lres);
3468 string lay = tclass.defaultLayoutName();
3470 if (hasLayout != false) {
3474 // layout not fount using default
3475 lay = tclass.defaultLayoutName();
3478 bv_->text->setLayout(bv_, lay);
3480 bv_->text->setParagraph(bv_, 0, 0,
3482 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3487 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3490 bv_->text->insertInset(bv_, inset);
3491 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3498 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3500 if (!inset || !available())
3503 // first check for locking insets
3504 if (bv_->theLockingInset()) {
3505 if (bv_->theLockingInset() == inset) {
3506 if (bv_->text->updateInset(bv_, inset)) {
3509 buffer_->markDirty();
3514 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3515 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3518 buffer_->markDirty();
3526 // then check if the inset is a top_level inset (has no owner)
3527 // if yes do the update as always otherwise we have to update the
3528 // toplevel inset where this inset is inside
3529 Inset * tl_inset = inset;
3530 while(tl_inset->owner())
3531 tl_inset = tl_inset->owner();
3533 if (tl_inset == inset) {
3534 update(bv_->text, BufferView::UPDATE);
3535 if (bv_->text->updateInset(bv_, inset)) {
3539 | BufferView::FITCUR
3540 | BufferView::CHANGE);
3542 update(bv_->text, SELECT);
3546 } else if (static_cast<UpdatableInset *>(tl_inset)
3547 ->updateInsetInInset(bv_, inset))
3549 if (bv_->text->updateInset(bv_, tl_inset)) {
3557 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3560 if (!available()) return;
3563 beforeChange(bv_->text);
3564 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3566 LyXCursor const & cursor = bv_->text->cursor;
3570 cursor.par()->isInset(cursor.pos())) {
3571 Inset const * inset = cursor.par()->getInset(cursor.pos());
3572 if (find(codes.begin(), codes.end(), inset->lyxCode())
3575 static_cast<InsetCommand const *>(inset)->getContents();
3579 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3580 if (bv_->text->cursor.pos()
3581 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3582 LyXCursor tmp = bv_->text->cursor;
3583 bv_->text->cursor.par(bv_->text->ownerParagraph());
3584 bv_->text->cursor.pos(0);
3585 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3586 bv_->text->cursor = tmp;
3587 bv_->owner()->message(_("No more insets"));
3590 bv_->owner()->message(_("No more insets"));
3593 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3594 bv_->text->selection.cursor = bv_->text->cursor;
3598 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3600 gotoInset(vector<Inset::Code>(1, code), same_content);