7 #include "BufferView_pimpl.h"
8 #include "frontends/WorkArea.h"
9 #include "frontends/screen.h"
10 #include "frontends/Dialogs.h"
11 #include "frontends/Alert.h"
12 #include "frontends/FileDialog.h"
15 #include "paragraph.h"
16 #include "frontends/LyXView.h"
17 #include "commandtags.h"
20 #include "bufferview_funcs.h"
21 #include "TextCache.h"
22 #include "bufferlist.h"
25 // added for Dispatch functions
28 #include "FloatList.h"
30 #include "ParagraphParameters.h"
31 #include "undo_funcs.h"
32 #include "lyxtextclasslist.h"
35 #include "insets/insetbib.h"
36 #include "insets/insettext.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetnote.h"
44 #include "insets/insetinclude.h"
45 #include "insets/insetcite.h"
46 #include "insets/insetert.h"
47 #include "insets/insetexternal.h"
48 #include "insets/insetgraphics.h"
49 #include "insets/insetfoot.h"
50 #include "insets/insetmarginal.h"
51 #include "insets/insetminipage.h"
52 #include "insets/insetfloat.h"
53 #include "insets/insettabular.h"
55 #include "insets/insettheorem.h"
56 #include "insets/insetlist.h"
58 #include "insets/insetcaption.h"
59 #include "insets/insetfloatlist.h"
60 #include "insets/insetspecialchar.h"
62 #include "mathed/formulabase.h"
64 #include "support/LAssert.h"
65 #include "support/lstrings.h"
66 #include "support/filetools.h"
67 #include "support/lyxfunctional.h"
69 #include <boost/bind.hpp>
77 extern string current_layout;
79 #ifndef CXX_GLOBAL_CSTD
96 using lyx::textclass_type;
98 /* the selection possible is needed, that only motion events are
99 * used, where the bottom press event was on the drawing area too */
100 bool selection_possible = false;
102 extern BufferList bufferlist;
103 extern char ascii_type;
105 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
110 const unsigned int saved_positions_num = 20;
115 XSync(fl_get_display(), 0);
119 void SetXtermCursor(Window win)
121 static Cursor cursor;
122 static bool cursor_undefined = true;
123 if (cursor_undefined) {
124 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
125 XFlush(fl_get_display());
126 cursor_undefined = false;
128 XDefineCursor(fl_get_display(), win, cursor);
129 XFlush(fl_get_display());
135 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
136 int xpos, int ypos, int width, int height)
137 : bv_(b), owner_(o), buffer_(0),
138 current_scrollbar_value(0), cursor_timeout(400),
139 using_xterm_cursor(false), inset_slept(false)
141 workarea_.reset(new WorkArea(xpos, ypos, width, height));
142 screen_.reset(new LScreen(workarea()));
145 workarea().scrollCB.connect(boost::bind(&BufferView::Pimpl::scrollCB, this, _1));
146 workarea().workAreaExpose
147 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
148 workarea().workAreaButtonPress
149 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
150 workarea().workAreaButtonRelease
151 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
152 workarea().workAreaMotionNotify
153 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
154 workarea().workAreaDoubleClick
155 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
156 workarea().workAreaTripleClick
157 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
158 workarea().workAreaKeyPress
159 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
160 workarea().selectionRequested
161 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
162 workarea().selectionLost
163 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
165 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
166 cursor_timeout.start();
167 workarea().setFocus();
168 saved_positions.resize(saved_positions_num);
172 WorkArea & BufferView::Pimpl::workarea() const
174 return *workarea_.get();
178 LScreen & BufferView::Pimpl::screen() const
180 return *screen_.get();
184 Painter & BufferView::Pimpl::painter()
186 return workarea().getPainter();
190 void BufferView::Pimpl::buffer(Buffer * b)
192 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
198 buffer_->delUser(bv_);
200 // Put the old text into the TextCache, but
201 // only if the buffer is still loaded.
202 // Also set the owner of the test to 0
203 // bv_->text->owner(0);
204 textcache.add(buffer_, workarea().workWidth(), bv_->text);
205 if (lyxerr.debugging())
206 textcache.show(lyxerr, "BufferView::buffer");
211 // Set current buffer
214 if (bufferlist.getState() == BufferList::CLOSING) return;
216 // If we are closing the buffer, use the first buffer as current
218 buffer_ = bufferlist.first();
222 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
223 buffer_->addUser(bv_);
224 // If we don't have a text object for this, we make one
225 if (bv_->text == 0) {
226 resizeCurrentBuffer();
231 bv_->text->first_y = screen().topCursorVisible(bv_->text);
232 owner_->updateMenubar();
233 owner_->updateToolbar();
234 // Similarly, buffer-dependent dialogs should be updated or
235 // hidden. This should go here because some dialogs (eg ToC)
236 // require bv_->text.
237 owner_->getDialogs()->updateBufferDependent(true);
243 lyxerr[Debug::INFO] << " No Buffer!" << endl;
244 owner_->updateMenubar();
245 owner_->updateToolbar();
246 owner_->getDialogs()->hideBufferDependent();
250 // Also remove all remaining text's from the testcache.
251 // (there should not be any!) (if there is any it is a
253 if (lyxerr.debugging())
254 textcache.show(lyxerr, "buffer delete all");
257 // should update layoutchoice even if we don't have a buffer.
258 owner_->updateLayoutChoice();
260 owner_->updateWindowTitle();
264 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
266 workarea().resize(xpos, ypos, width, height);
267 update(bv_->text, SELECT);
272 void BufferView::Pimpl::resize()
275 resizeCurrentBuffer();
279 void BufferView::Pimpl::redraw()
281 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
286 bool BufferView::Pimpl::fitCursor()
290 if (bv_->theLockingInset()) {
291 bv_->theLockingInset()->fitInsetCursor(bv_);
294 ret = screen().fitCursor(bv_->text, bv_);
297 bv_->owner()->getDialogs()->updateParagraph();
304 void BufferView::Pimpl::redoCurrentBuffer()
306 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
307 if (buffer_ && bv_->text) {
309 owner_->updateLayoutChoice();
314 int BufferView::Pimpl::resizeCurrentBuffer()
316 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
319 Paragraph * selstartpar = 0;
320 Paragraph * selendpar = 0;
321 UpdatableInset * the_locking_inset = 0;
324 pos_type selstartpos = 0;
325 pos_type selendpos = 0;
326 bool selection = false;
327 bool mark_set = false;
329 owner_->prohibitInput();
331 owner_->message(_("Formatting document..."));
334 par = bv_->text->cursor.par();
335 pos = bv_->text->cursor.pos();
336 selstartpar = bv_->text->selection.start.par();
337 selstartpos = bv_->text->selection.start.pos();
338 selendpar = bv_->text->selection.end.par();
339 selendpos = bv_->text->selection.end.pos();
340 selection = bv_->text->selection.set();
341 mark_set = bv_->text->selection.mark();
342 the_locking_inset = bv_->theLockingInset();
343 buffer_->resizeInsets(bv_);
344 // I don't think the delete and new are necessary here we just could
345 // call only init! (Jug 20020419)
347 bv_->text = new LyXText(bv_);
348 bv_->text->init(bv_);
350 // See if we have a text in TextCache that fits
351 // the new buffer_ with the correct width.
352 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
354 if (lyxerr.debugging()) {
355 lyxerr << "Found a LyXText that fits:\n";
356 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
358 // Set the owner of the newly found text
359 // bv_->text->owner(bv_);
360 if (lyxerr.debugging())
361 textcache.show(lyxerr, "resizeCurrentBuffer");
363 bv_->text = new LyXText(bv_);
364 bv_->text->init(bv_);
365 //buffer_->resizeInsets(bv_);
372 bv_->text->selection.set(true);
373 // At this point just to avoid the Delete-Empty-Paragraph-
374 // Mechanism when setting the cursor.
375 bv_->text->selection.mark(mark_set);
377 bv_->text->setCursor(bv_, selstartpar, selstartpos);
378 bv_->text->selection.cursor = bv_->text->cursor;
379 bv_->text->setCursor(bv_, selendpar, selendpos);
380 bv_->text->setSelection(bv_);
381 bv_->text->setCursor(bv_, par, pos);
383 bv_->text->setCursor(bv_, par, pos);
384 bv_->text->selection.cursor = bv_->text->cursor;
385 bv_->text->selection.set(false);
387 // remake the inset locking
388 bv_->theLockingInset(the_locking_inset);
391 bv_->text->first_y = screen().topCursorVisible(bv_->text);
393 // this will scroll the screen such that the cursor becomes visible
398 owner_->allowInput();
400 /// clear the "Formatting Document" message
407 void BufferView::Pimpl::updateScreen()
409 // Regenerate the screen.
414 void BufferView::Pimpl::updateScrollbar()
417 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
418 workarea().setScrollbar(0, 1.0);
422 long const text_height = bv_->text->height;
423 long const work_height = workarea().workHeight();
425 double const lineh = bv_->text->defaultHeight();
426 double const slider_size =
427 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
429 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
430 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
432 /* If the text is smaller than the working area, the scrollbar
433 * maximum must be the working area height. No scrolling will
435 if (text_height <= work_height) {
436 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
437 workarea().setScrollbarBounds(0.0, 0.0);
438 current_scrollbar_value = bv_->text->first_y;
439 workarea().setScrollbar(current_scrollbar_value, 1.0);
443 workarea().setScrollbarBounds(0.0, text_height - work_height);
444 workarea().setScrollbarIncrements(lineh);
445 current_scrollbar_value = bv_->text->first_y;
446 workarea().setScrollbar(current_scrollbar_value, slider_size);
450 // Callback for scrollbar slider
451 void BufferView::Pimpl::scrollCB(double value)
453 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
455 if (!buffer_) return;
457 current_scrollbar_value = long(value);
459 if (current_scrollbar_value < 0)
460 current_scrollbar_value = 0;
462 screen().draw(bv_->text, bv_, current_scrollbar_value);
464 if (!lyxrc.cursor_follows_scrollbar) {
469 LyXText * vbt = bv_->text;
471 int const height = vbt->defaultHeight();
472 int const first = static_cast<int>((bv_->text->first_y + height));
473 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
475 if (vbt->cursor.y() < first)
476 vbt->setCursorFromCoordinates(bv_, 0, first);
477 else if (vbt->cursor.y() > last)
478 vbt->setCursorFromCoordinates(bv_, 0, last);
484 int BufferView::Pimpl::scrollUp(long time)
489 double value = workarea().getScrollbarValue();
495 float add_value = (bv_->text->defaultHeight()
496 + float(time) * float(time) * 0.125);
498 if (add_value > workarea().workHeight())
499 add_value = float(workarea().workHeight() -
500 bv_->text->defaultHeight());
502 float add_value = float(workarea().workHeight()) * float(time) / 100;
510 workarea().setScrollbarValue(value);
517 int BufferView::Pimpl::scrollDown(long time)
522 double value = workarea().getScrollbarValue();
523 pair<float, float> p = workarea().getScrollbarBounds();
524 double const max = p.second;
530 float add_value = (bv_->text->defaultHeight()
531 + float(time) * float(time) * 0.125);
533 if (add_value > workarea().workHeight())
534 add_value = float(workarea().workHeight() -
535 bv_->text->defaultHeight());
537 float add_value = float(workarea().workHeight()) * float(time) / 100;
545 workarea().setScrollbarValue(value);
552 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, key_modifier::state state)
554 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
558 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
560 // Only use motion with button 1
561 if (!(state & mouse_button::button1))
567 // Check for inset locking
568 if (bv_->theLockingInset()) {
569 LyXCursor cursor = bv_->text->cursor;
570 LyXFont font = bv_->text->getFont(buffer_,
571 cursor.par(), cursor.pos());
572 int width = bv_->theLockingInset()->width(bv_, font);
573 int inset_x = font.isVisibleRightToLeft()
574 ? cursor.ix() - width : cursor.ix();
575 int start_x = inset_x + bv_->theLockingInset()->scroll();
576 bv_->theLockingInset()->
577 insetMotionNotify(bv_,
579 y - cursor.iy() + bv_->text->first_y,
584 /* The test for not selection possible is needed, that only motion
585 events are used, where the bottom press event was on
586 the drawing area too */
587 if (!selection_possible)
590 screen().hideCursor();
592 int y_before = bv_->text->cursor.y();
594 Row * cursorrow = bv_->text->cursor.row();
595 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
597 // sorry for this but I have a strange error that the y value jumps at
598 // a certain point. This seems like an error in my xforms library or
599 // in some other local environment, but I would like to leave this here
600 // for the moment until I can remove this (Jug 20020418)
601 if (y_before < bv_->text->cursor.y())
602 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
604 // This is to allow jumping over large insets
605 if (cursorrow == bv_->text->cursor.row()) {
606 if (y >= int(workarea().workHeight())) {
607 bv_->text->cursorDown(bv_, false);
609 bv_->text->cursorUp(bv_, false);
613 if (!bv_->text->selection.set())
614 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
616 bv_->text->setSelection(bv_);
617 screen().toggleToggle(bv_->text, bv_);
623 // Single-click on work area
624 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
625 mouse_button::state button)
630 // ok ok, this is a hack.
632 if (button == mouse_button::button4) {
633 scrollUp(lyxrc.wheel_jump);
634 // We shouldn't go further down as we really should only do the
635 // scrolling and be done with this. Otherwise we may open some
636 // dialogs (Jug 20020424).
638 } else if (button == mouse_button::button5) {
639 scrollDown(lyxrc.wheel_jump);
640 // We shouldn't go further down as we really should only do the
641 // scrolling and be done with this. Otherwise we may open some
642 // dialogs (Jug 20020424).
646 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
648 // Middle button press pastes if we have a selection
649 // We do this here as if the selection was inside an inset
650 // it could get cleared on the unlocking of the inset so
651 // we have to check this first
652 bool paste_internally = false;
653 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
654 owner_->getLyXFunc()->dispatch(LFUN_COPY);
655 paste_internally = true;
658 int const screen_first = bv_->text->first_y;
660 if (bv_->theLockingInset()) {
661 // We are in inset locking mode
663 /* Check whether the inset was hit. If not reset mode,
664 otherwise give the event to the inset */
665 if (inset_hit == bv_->theLockingInset()) {
666 bv_->theLockingInset()->
667 insetButtonPress(bv_,xpos, ypos,button);
670 bv_->unlockInset(bv_->theLockingInset());
675 selection_possible = true;
676 screen().hideCursor();
678 // Clear the selection
679 screen().toggleSelection(bv_->text, bv_);
680 bv_->text->clearSelection();
681 bv_->text->fullRebreak(bv_);
685 // Single left click in math inset?
686 if (isHighlyEditableInset(inset_hit)) {
687 // Highly editable inset, like math
688 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
689 selection_possible = false;
690 owner_->updateLayoutChoice();
691 owner_->message(inset->editMessage());
692 //inset->edit(bv_, xpos, ypos, button);
693 // We just have to lock the inset before calling a PressEvent on it!
694 // we don't need the edit() call here! (Jug20020329)
695 if (!bv_->lockInset(inset)) {
696 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
698 inset->insetButtonPress(bv_, xpos, ypos, button);
701 // I'm not sure we should continue here if we hit an inset (Jug20020403)
703 // Right click on a footnote flag opens float menu
704 if (button == mouse_button::button3) {
705 selection_possible = false;
709 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
710 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
712 bv_->text->selection.cursor = bv_->text->cursor;
713 bv_->text->cursor.x_fix(bv_->text->cursor.x());
715 owner_->updateLayoutChoice();
717 selection_possible = false;
720 // Insert primary selection with middle mouse
721 // if there is a local selection in the current buffer,
723 if (button == mouse_button::button2) {
724 if (paste_internally)
725 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
727 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
729 selection_possible = false;
735 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
740 LyXText * text = bv_->getLyXText();
742 if (text->bv_owner && bv_->theLockingInset())
745 if (button == mouse_button::button1) {
746 if (text->bv_owner) {
747 screen().hideCursor();
748 screen().toggleSelection(text, bv_);
749 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
750 screen().toggleSelection(text, bv_, false);
752 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
754 /* This will fit the cursor on the screen
756 update(text, BufferView::SELECT|BufferView::FITCUR);
761 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
766 LyXText * text = bv_->getLyXText();
768 if (text->bv_owner && bv_->theLockingInset())
771 if (button == mouse_button::button1) {
772 if (text->bv_owner) {
773 screen().hideCursor();
774 screen().toggleSelection(text, bv_);
776 text->cursorHome(bv_);
777 text->selection.cursor = text->cursor;
778 text->cursorEnd(bv_);
779 text->setSelection(bv_);
780 if (text->bv_owner) {
781 screen().toggleSelection(text, bv_, false);
783 /* This will fit the cursor on the screen
785 update(text, BufferView::SELECT|BufferView::FITCUR);
790 void BufferView::Pimpl::selectionRequested()
797 LyXText * text = bv_->getLyXText();
799 if (text->selection.set() &&
800 (!bv_->text->xsel_cache.set() ||
801 text->selection.start != bv_->text->xsel_cache.start ||
802 text->selection.end != bv_->text->xsel_cache.end))
804 bv_->text->xsel_cache = text->selection;
805 sel = text->selectionAsString(bv_->buffer(), false);
806 } else if (!text->selection.set()) {
808 bv_->text->xsel_cache.set(false);
811 workarea().putClipboard(sel);
816 void BufferView::Pimpl::selectionLost()
821 bv_->getLyXText()->clearSelection();
823 bv_->text->xsel_cache.set(false);
828 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
829 mouse_button::state button)
831 // do nothing if we used the mouse wheel
832 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
835 // If we hit an inset, we have the inset coordinates in these
836 // and inset_hit points to the inset. If we do not hit an
837 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
838 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
840 if (bv_->theLockingInset()) {
841 // We are in inset locking mode.
843 /* LyX does a kind of work-area grabbing for insets.
844 Only a ButtonPress Event outside the inset will
845 force a insetUnlock. */
846 bv_->theLockingInset()->
847 insetButtonRelease(bv_, x, y, button);
851 selection_possible = false;
853 if (button == mouse_button::button2)
857 if (button == mouse_button::button1) {
858 workarea().haveSelection(bv_->getLyXText()->selection.set());
863 owner_->updateMenubar();
864 owner_->updateToolbar();
866 // Did we hit an editable inset?
868 selection_possible = false;
870 // if we reach this point with a selection, it
871 // must mean we are currently selecting.
872 // But we don't want to open the inset
873 // because that is annoying for the user.
874 // So just pretend we didn't hit it.
875 // this is OK because a "kosher" ButtonRelease
876 // will follow a ButtonPress that clears
878 // Note this also fixes selection drawing
879 // problems if we end up opening an inset
880 if (bv_->getLyXText()->selection.set())
883 // CHECK fix this proper in 0.13
884 // well, maybe 13.0 !!!!!!!!!
886 // Following a ref shouldn't issue
887 // a push on the undo-stack
888 // anylonger, now that we have
889 // keybindings for following
890 // references and returning from
891 // references. IMHO though, it
892 // should be the inset's own business
893 // to push or not push on the undo
894 // stack. They don't *have* to
895 // alter the document...
897 // ...or maybe the SetCursorParUndo()
898 // below isn't necessary at all anylonger?
899 if (inset_hit->lyxCode() == Inset::REF_CODE) {
900 setCursorParUndo(bv_);
903 owner_->message(inset_hit->editMessage());
905 if (isHighlyEditableInset(inset_hit)) {
906 // Highly editable inset, like math
907 UpdatableInset *inset = (UpdatableInset *)inset_hit;
908 inset->insetButtonRelease(bv_, x, y, button);
910 inset_hit->insetButtonRelease(bv_, x, y, button);
911 // IMO this is a grosshack! Inset's should be changed so that
912 // they call the actions they have to do with the insetButtonRel.
913 // function and not in the edit(). This should be changed
915 inset_hit->edit(bv_, x, y, button);
920 // Maybe we want to edit a bibitem ale970302
921 if (bv_->text->cursor.par()->bibkey && x < 20 +
922 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
923 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
930 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
931 LyXCursor const & cursor) const
933 Paragraph /*const*/ & par = *cursor.par();
934 pos_type const pos = cursor.pos();
936 lyx::Assert(par.getInset(pos));
938 Inset const & inset(*par.getInset(pos));
940 LyXFont const & font = text.getFont(buffer_, &par, pos);
942 int const width = inset.width(bv_, font);
943 int const inset_x = font.isVisibleRightToLeft()
944 ? (cursor.ix() - width) : cursor.ix();
947 inset_x + inset.scroll(),
949 cursor.iy() - inset.ascent(bv_, font),
950 cursor.iy() + inset.descent(bv_, font));
954 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
955 LyXCursor const & cursor,
956 int & x, int & y) const
958 pos_type const pos(cursor.pos());
959 Paragraph /*const*/ & par(*cursor.par());
961 if (pos >= par.size() || !par.isInset(pos)) {
965 Inset /*const*/ * inset = par.getInset(pos);
967 if (!isEditableInset(inset)) {
971 Box b(insetDimensions(text, cursor));
973 if (!b.contained(x, y)) {
974 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
975 << " box " << b << endl;
979 text.setCursor(bv_, &par, pos, true);
982 // The origin of an inset is on the baseline
983 y -= text.cursor.iy();
989 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
991 int y_tmp = y + text->first_y;
994 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
996 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1003 // look at previous position
1005 if (cursor.pos() == 0) {
1010 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1012 inset = checkInset(*text, cursor, x, y_tmp);
1020 void BufferView::Pimpl::workAreaExpose()
1022 static int work_area_width;
1023 static unsigned int work_area_height;
1025 bool const widthChange = workarea().workWidth() != work_area_width;
1026 bool const heightChange = workarea().workHeight() != work_area_height;
1028 // update from work area
1029 work_area_width = workarea().workWidth();
1030 work_area_height = workarea().workHeight();
1033 // The visible LyXView need a resize
1036 // Remove all texts from the textcache
1037 // This is not _really_ what we want to do. What
1038 // we really want to do is to delete in textcache
1039 // that does not have a BufferView with matching
1040 // width, but as long as we have only one BufferView
1041 // deleting all gives the same result.
1042 if (lyxerr.debugging())
1043 textcache.show(lyxerr, "Expose delete all");
1045 buffer_->resizeInsets(bv_);
1046 } else if (heightChange) {
1047 // Rebuild image of current screen
1049 // fitCursor() ensures we don't jump back
1050 // to the start of the document on vertical
1054 // The main window size has changed, repaint most stuff
1057 screen().redraw(bv_->text, bv_);
1060 // Grey box when we don't have a buffer
1061 workarea().greyOut();
1064 // always make sure that the scrollbar is sane.
1066 owner_->updateLayoutChoice();
1071 void BufferView::Pimpl::update()
1073 if (!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 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());
1091 bv_->text->status(bv_, st);
1092 screen().update(bv_->text, bv_);
1094 // do this here instead of in the screen::update because of
1096 bv_->text->status(bv_, LyXText::UNCHANGED);
1102 // Values used when calling update:
1104 // -2 - update, move sel_cursor if selection, fitcursor
1105 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1106 // 0 - update, move sel_cursor if selection, fitcursor
1107 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1108 // 3 - update, move sel_cursor if selection
1111 // a simple redraw of the parts that need refresh
1113 // move sel_cursor if selection -
1114 // the text's sel_cursor is moved if there is selection is progress
1117 // fitCursor() is called and the scrollbar updated
1120 // the buffer is marked dirty.
1129 // UPDATE_ONLY = UPDATE;
1130 // UPDATE_SELECT = UPDATE | SELECT;
1131 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1132 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1134 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1135 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1136 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1137 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1138 // update(3) -> update(1) -> update(1) -> update(SELECT)
1140 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1142 owner_->updateLayoutChoice();
1144 if (!text->selection.set() && (f & SELECT)) {
1145 text->selection.cursor = text->cursor;
1148 text->fullRebreak(bv_);
1150 if (text->inset_owner) {
1151 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1152 updateInset(text->inset_owner, false);
1162 buffer_->markDirty();
1167 // Callback for cursor timer
1168 void BufferView::Pimpl::cursorToggle()
1171 cursor_timeout.restart();
1176 extern void reapSpellchecker(void);
1179 if (!bv_->theLockingInset()) {
1180 screen().cursorToggle(bv_);
1182 bv_->theLockingInset()->toggleInsetCursor(bv_);
1185 cursor_timeout.restart();
1189 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1191 if (!text->cursor.row()->previous()) {
1192 if (text->first_y > 0) {
1193 int new_y = bv_->text->first_y - workarea().workHeight();
1194 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1200 int y = text->first_y;
1201 Row * cursorrow = text->cursor.row();
1203 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1207 if (cursorrow == bv_->text->cursor.row()) {
1208 // we have a row which is higher than the workarea so we leave the
1209 // cursor on the start of the row and move only the draw up as soon
1210 // as we move the cursor or do something while inside the row (it may
1211 // span several workarea-heights) we'll move to the top again, but this
1212 // is better than just jump down and only display part of the row.
1213 new_y = bv_->text->first_y - workarea().workHeight();
1215 if (text->inset_owner) {
1216 new_y = bv_->text->cursor.iy()
1217 + bv_->theLockingInset()->insetInInsetY() + y
1218 + text->cursor.row()->height()
1219 - workarea().workHeight() + 1;
1221 new_y = text->cursor.y()
1222 - text->cursor.row()->baseline()
1223 + text->cursor.row()->height()
1224 - workarea().workHeight() + 1;
1227 screen().draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1228 if (text->cursor.row()->previous()) {
1230 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1231 text->cursor.row()->previous()->pos(), false);
1232 if (cur.y() > text->first_y) {
1233 text->cursorUp(bv_, true);
1240 void BufferView::Pimpl::cursorNext(LyXText * text)
1242 if (!text->cursor.row()->next()) {
1243 int y = text->cursor.y() - text->cursor.row()->baseline() +
1244 text->cursor.row()->height();
1245 if (y > int(text->first_y + workarea().workHeight())) {
1246 screen().draw(bv_->text, bv_,
1247 bv_->text->first_y + workarea().workHeight());
1253 int y = text->first_y + workarea().workHeight();
1254 if (text->inset_owner && !text->first_y) {
1255 y -= (bv_->text->cursor.iy()
1256 - bv_->text->first_y
1257 + bv_->theLockingInset()->insetInInsetY());
1259 text->getRowNearY(y);
1261 Row * cursorrow = text->cursor.row();
1262 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().workHeight());
1265 if (cursorrow == bv_->text->cursor.row()) {
1266 // we have a row which is higher than the workarea so we leave the
1267 // cursor on the start of the row and move only the draw down as soon
1268 // as we move the cursor or do something while inside the row (it may
1269 // span several workarea-heights) we'll move to the top again, but this
1270 // is better than just jump down and only display part of the row.
1271 new_y = bv_->text->first_y + workarea().workHeight();
1273 if (text->inset_owner) {
1274 new_y = bv_->text->cursor.iy()
1275 + bv_->theLockingInset()->insetInInsetY()
1276 + y - text->cursor.row()->baseline();
1278 new_y = text->cursor.y() - text->cursor.row()->baseline();
1281 screen().draw(bv_->text, bv_, new_y);
1282 if (text->cursor.row()->next()) {
1284 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1285 text->cursor.row()->next()->pos(), false);
1286 if (cur.y() < int(text->first_y + workarea().workHeight())) {
1287 text->cursorDown(bv_, true);
1294 bool BufferView::Pimpl::available() const
1296 if (buffer_ && bv_->text)
1302 void BufferView::Pimpl::beforeChange(LyXText * text)
1305 text->clearSelection();
1309 void BufferView::Pimpl::savePosition(unsigned int i)
1311 if (i >= saved_positions_num)
1313 saved_positions[i] = Position(buffer_->fileName(),
1314 bv_->text->cursor.par()->id(),
1315 bv_->text->cursor.pos());
1318 str << _("Saved bookmark") << ' ' << i;
1319 owner_->message(str.str().c_str());
1324 void BufferView::Pimpl::restorePosition(unsigned int i)
1326 if (i >= saved_positions_num)
1329 string const fname = saved_positions[i].filename;
1331 beforeChange(bv_->text);
1333 if (fname != buffer_->fileName()) {
1334 Buffer * b = bufferlist.exists(fname) ?
1335 bufferlist.getBuffer(fname) :
1336 bufferlist.loadLyXFile(fname); // don't ask, just load it
1337 if (b != 0) buffer(b);
1340 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1344 bv_->text->setCursor(bv_, par,
1345 min(par->size(), saved_positions[i].par_pos));
1347 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1350 str << _("Moved to bookmark") << ' ' << i;
1351 owner_->message(str.str().c_str());
1356 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1358 if (i >= saved_positions_num)
1361 return !saved_positions[i].filename.empty();
1365 void BufferView::Pimpl::setState()
1367 if (!lyxrc.rtl_support)
1370 LyXText * text = bv_->getLyXText();
1371 if (text->real_current_font.isRightToLeft()
1372 && !(bv_->theLockingInset()
1373 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1375 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1376 owner_->getIntl()->KeyMapSec();
1378 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1379 owner_->getIntl()->KeyMapPrim();
1385 void BufferView::Pimpl::insetSleep()
1387 if (bv_->theLockingInset() && !inset_slept) {
1388 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1389 bv_->theLockingInset()->insetUnlock(bv_);
1395 void BufferView::Pimpl::insetWakeup()
1397 if (bv_->theLockingInset() && inset_slept) {
1398 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1399 inset_slept = false;
1405 void BufferView::Pimpl::insetUnlock()
1407 if (bv_->theLockingInset()) {
1409 bv_->theLockingInset()->insetUnlock(bv_);
1410 bv_->theLockingInset(0);
1412 inset_slept = false;
1417 bool BufferView::Pimpl::focus() const
1419 return workarea().hasFocus();
1423 void BufferView::Pimpl::focus(bool f)
1425 if (f) workarea().setFocus();
1429 void BufferView::Pimpl::showCursor()
1431 if (bv_->theLockingInset())
1432 bv_->theLockingInset()->showInsetCursor(bv_);
1434 screen().showCursor(bv_->text, bv_);
1438 void BufferView::Pimpl::hideCursor()
1440 if (!bv_->theLockingInset())
1441 screen().hideCursor();
1445 void BufferView::Pimpl::toggleSelection(bool b)
1447 if (bv_->theLockingInset())
1448 bv_->theLockingInset()->toggleSelection(bv_, b);
1449 screen().toggleSelection(bv_->text, bv_, b);
1453 void BufferView::Pimpl::toggleToggle()
1455 screen().toggleToggle(bv_->text, bv_);
1459 void BufferView::Pimpl::center()
1461 beforeChange(bv_->text);
1462 if (bv_->text->cursor.y() > static_cast<int>((workarea().workHeight() / 2))) {
1463 screen().draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().workHeight() / 2);
1465 screen().draw(bv_->text, bv_, 0);
1467 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1472 void BufferView::Pimpl::pasteClipboard(bool asPara)
1477 screen().hideCursor();
1478 beforeChange(bv_->text);
1480 string const clip(workarea().getClipboard());
1486 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1488 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1490 bv_->getLyXText()->clearSelection();
1491 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1495 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1497 workarea().putClipboard(stuff);
1502 * Dispatch functions for actions which can be valid for BufferView->text
1503 * and/or InsetText->text!!!
1508 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1510 LyXText * lt = bv_->getLyXText();
1512 if (selecting || lt->selection.mark()) {
1513 lt->setSelection(bv_);
1517 updateInset(lt->inset_owner, false);
1521 update(lt, BufferView::SELECT|BufferView::FITCUR);
1523 update(lt, BufferView::SELECT);
1525 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1526 bv_->theLockingInset()->hideInsetCursor(bv_);
1527 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1531 if (!lt->selection.set())
1532 workarea().haveSelection(false);
1534 /* ---> Everytime the cursor is moved, show the current font state. */
1535 // should this too me moved out of this func?
1536 //owner->showState();
1541 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1543 LyXCursor cursor = bv_->getLyXText()->cursor;
1544 Buffer::inset_iterator it =
1545 find_if(Buffer::inset_iterator(
1546 cursor.par(), cursor.pos()),
1547 buffer_->inset_iterator_end(),
1548 lyx::compare_memfun(&Inset::lyxCode, code));
1549 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1553 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1555 string filename = filen;
1557 if (filename.empty()) {
1558 // Launch a file browser
1559 string initpath = lyxrc.document_path;
1562 string const trypath = owner_->buffer()->filePath();
1563 // If directory is writeable, use this as default.
1564 if (IsDirWriteable(trypath))
1568 FileDialog fileDlg(bv_->owner(),
1569 _("Select LyX document to insert"),
1571 make_pair(string(_("Documents|#o#O")),
1572 string(lyxrc.document_path)),
1573 make_pair(string(_("Examples|#E#e")),
1574 string(AddPath(system_lyxdir, "examples"))));
1576 FileDialog::Result result =
1577 fileDlg.Select(initpath,
1578 _("*.lyx| LyX Documents (*.lyx)"));
1580 if (result.first == FileDialog::Later)
1583 filename = result.second;
1585 // check selected filename
1586 if (filename.empty()) {
1587 owner_->message(_("Canceled."));
1592 // get absolute path of file and add ".lyx" to the filename if
1594 filename = FileSearch(string(), filename, "lyx");
1596 string const disp_fn(MakeDisplayPath(filename));
1599 s1 << _("Inserting document") << ' '
1600 << disp_fn << " ...";
1601 owner_->message(s1.str().c_str());
1602 bool const res = bv_->insertLyXFile(filename);
1605 str << _("Document") << ' ' << disp_fn
1606 << ' ' << _("inserted.");
1607 owner_->message(str.str().c_str());
1610 str << _("Could not insert document") << ' '
1612 owner_->message(str.str().c_str());
1617 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1619 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1620 << action <<"] arg[" << argument << "]" << endl;
1622 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1625 // --- Misc -------------------------------------------
1629 LyXText * lt = bv_->getLyXText();
1630 lt->toggleAppendix(bv_);
1633 | BufferView::FITCUR
1634 | BufferView::CHANGE);
1639 case LFUN_TOC_INSERT:
1641 InsetCommandParams p;
1642 p.setCmdName("tableofcontents");
1643 Inset * inset = new InsetTOC(p);
1644 if (!insertInset(inset, tclass.defaultLayoutName()))
1649 case LFUN_SCROLL_INSET:
1650 // this is not handled here as this funktion is only aktive
1651 // if we have a locking_inset and that one is (or contains)
1655 case LFUN_INSET_GRAPHICS:
1657 Inset * new_inset = new InsetGraphics;
1658 if (!insertInset(new_inset)) {
1661 // this is need because you don't use a inset->Edit()
1662 updateInset(new_inset, true);
1663 new_inset->edit(bv_);
1673 case LFUN_PASTESELECTION:
1675 bool asPara = false;
1676 if (argument == "paragraph")
1678 pasteClipboard(asPara);
1690 case LFUN_LAYOUT_COPY:
1691 bv_->copyEnvironment();
1694 case LFUN_LAYOUT_PASTE:
1695 bv_->pasteEnvironment();
1699 case LFUN_GOTOERROR:
1700 gotoInset(Inset::ERROR_CODE, false);
1704 gotoInset(Inset::IGNORE_CODE, false);
1707 case LFUN_REFERENCE_GOTO:
1709 vector<Inset::Code> tmp;
1710 tmp.push_back(Inset::LABEL_CODE);
1711 tmp.push_back(Inset::REF_CODE);
1712 gotoInset(tmp, true);
1716 case LFUN_HYPHENATION:
1717 specialChar(InsetSpecialChar::HYPHENATION);
1720 case LFUN_LIGATURE_BREAK:
1721 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1725 specialChar(InsetSpecialChar::LDOTS);
1728 case LFUN_END_OF_SENTENCE:
1729 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1732 case LFUN_MENU_SEPARATOR:
1733 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1740 case LFUN_DEPTH_MIN:
1741 changeDepth(bv_, bv_->getLyXText(), -1);
1744 case LFUN_DEPTH_PLUS:
1745 changeDepth(bv_, bv_->getLyXText(), 1);
1749 owner_->getDialogs()->setUserFreeFont();
1752 case LFUN_FILE_INSERT:
1753 MenuInsertLyXFile(argument);
1756 case LFUN_FILE_INSERT_ASCII_PARA:
1757 InsertAsciiFile(bv_, argument, true);
1760 case LFUN_FILE_INSERT_ASCII:
1761 InsertAsciiFile(bv_, argument, false);
1766 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1767 << argument << endl;
1769 // This is not the good solution to the empty argument
1770 // problem, but it will hopefully suffice for 1.2.0.
1771 // The correct solution would be to augument the
1772 // function list/array with information about what
1773 // functions needs arguments and their type.
1774 if (argument.empty()) {
1775 owner_->getLyXFunc()->setErrorMessage(
1776 _("LyX function 'layout' needs an argument."));
1780 // Derive layout number from given argument (string)
1781 // and current buffer's textclass (number). */
1782 bool hasLayout = tclass.hasLayout(argument);
1783 string layout = argument;
1785 // If the entry is obsolete, use the new one instead.
1787 string const & obs = tclass[layout].obsoleted_by();
1793 owner_->getLyXFunc()->setErrorMessage(
1794 string(N_("Layout ")) + argument +
1799 bool change_layout = (current_layout != layout);
1800 LyXText * lt = bv_->getLyXText();
1801 if (!change_layout && lt->selection.set() &&
1802 lt->selection.start.par() != lt->selection.end.par())
1804 Paragraph * spar = lt->selection.start.par();
1805 Paragraph * epar = lt->selection.end.par()->next();
1806 while(spar != epar) {
1807 if (spar->layout() != current_layout) {
1808 change_layout = true;
1813 if (change_layout) {
1815 current_layout = layout;
1818 | BufferView::FITCUR);
1819 lt->setLayout(bv_, layout);
1820 owner_->setLayout(layout);
1823 | BufferView::FITCUR
1824 | BufferView::CHANGE);
1831 lang(bv_, argument);
1833 owner_->showState();
1838 owner_->showState();
1843 owner_->showState();
1848 owner_->showState();
1853 owner_->showState();
1858 owner_->showState();
1863 owner_->showState();
1868 owner_->showState();
1871 case LFUN_UNDERLINE:
1873 owner_->showState();
1876 case LFUN_FONT_SIZE:
1877 fontSize(bv_, argument);
1878 owner_->showState();
1881 case LFUN_FONT_STATE:
1882 owner_->getLyXFunc()->setMessage(currentState(bv_));
1885 case LFUN_UPCASE_WORD:
1887 LyXText * lt = bv_->getLyXText();
1891 | BufferView::FITCUR);
1892 lt->changeCase(bv_, LyXText::text_uppercase);
1893 if (lt->inset_owner)
1894 updateInset(lt->inset_owner, true);
1897 | BufferView::FITCUR
1898 | BufferView::CHANGE);
1902 case LFUN_LOWCASE_WORD:
1904 LyXText * lt = bv_->getLyXText();
1906 update(lt, BufferView::SELECT|BufferView::FITCUR);
1907 lt->changeCase(bv_, LyXText::text_lowercase);
1908 if (lt->inset_owner)
1909 updateInset(lt->inset_owner, true);
1912 | BufferView::FITCUR
1913 | BufferView::CHANGE);
1917 case LFUN_CAPITALIZE_WORD:
1919 LyXText * lt = bv_->getLyXText();
1921 update(lt, BufferView::SELECT|BufferView::FITCUR);
1922 lt->changeCase(bv_, LyXText::text_capitalization);
1923 if (lt->inset_owner)
1924 updateInset(lt->inset_owner, true);
1927 | BufferView::FITCUR
1928 | BufferView::CHANGE);
1932 case LFUN_TRANSPOSE_CHARS:
1934 LyXText * lt = bv_->getLyXText();
1936 update(lt, BufferView::SELECT|BufferView::FITCUR);
1937 lt->transposeChars(*bv_);
1938 if (lt->inset_owner)
1939 updateInset(lt->inset_owner, true);
1942 | BufferView::FITCUR
1943 | BufferView::CHANGE);
1948 case LFUN_INSERT_LABEL:
1949 MenuInsertLabel(bv_, argument);
1952 case LFUN_REF_INSERT:
1953 if (argument.empty()) {
1954 InsetCommandParams p("ref");
1955 owner_->getDialogs()->createRef(p.getAsString());
1957 InsetCommandParams p;
1958 p.setFromString(argument);
1960 InsetRef * inset = new InsetRef(p, *buffer_);
1961 if (!insertInset(inset))
1964 updateInset(inset, true);
1968 case LFUN_BOOKMARK_SAVE:
1969 savePosition(strToUnsignedInt(argument));
1972 case LFUN_BOOKMARK_GOTO:
1973 restorePosition(strToUnsignedInt(argument));
1978 string label(argument);
1979 if (label.empty()) {
1981 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1983 label = inset->getContents();
1988 if (!label.empty()) {
1989 //bv_->savePosition(0);
1990 if (!bv_->gotoLabel(label))
1991 Alert::alert(_("Error"),
1992 _("Couldn't find this label"),
1993 _("in current document."));
1998 // --- Cursor Movements -----------------------------
2001 LyXText * lt = bv_->getLyXText();
2003 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2004 if (!lt->selection.mark())
2006 update(lt, BufferView::SELECT|BufferView::FITCUR);
2008 lt->cursorLeft(bv_, false);
2009 if (lt->cursor.pos() < lt->cursor.par()->size()
2010 && lt->cursor.par()->isInset(lt->cursor.pos())
2011 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2012 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2013 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2015 tmpinset->edit(bv_, false);
2017 tmpinset->edit(bv_);
2021 lt->cursorRight(bv_, false);
2023 moveCursorUpdate(false);
2024 owner_->showState();
2030 // This is soooo ugly. Isn`t it possible to make
2031 // it simpler? (Lgb)
2032 LyXText * lt = bv_->getLyXText();
2033 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2034 if (!lt->selection.mark())
2036 update(lt, BufferView::SELECT|BufferView::FITCUR);
2037 LyXCursor const cur = lt->cursor;
2039 lt->cursorLeft(bv_, false);
2040 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2041 lt->cursor.pos() < lt->cursor.par()->size() &&
2042 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2043 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2044 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2045 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2047 tmpinset->edit(bv_);
2049 tmpinset->edit(bv_, false);
2053 lt->cursorRight(bv_, false);
2056 moveCursorUpdate(false);
2057 owner_->showState();
2063 LyXText * lt = bv_->getLyXText();
2065 if (!lt->selection.mark())
2067 update(lt, BufferView::UPDATE);
2070 moveCursorUpdate(false);
2071 owner_->showState();
2077 LyXText * lt = bv_->getLyXText();
2079 if (!lt->selection.mark())
2081 update(lt, BufferView::UPDATE);
2082 lt->cursorDown(bv_);
2084 moveCursorUpdate(false);
2085 owner_->showState();
2089 case LFUN_UP_PARAGRAPH:
2091 LyXText * lt = bv_->getLyXText();
2093 if (!lt->selection.mark())
2095 update(lt, BufferView::UPDATE);
2096 lt->cursorUpParagraph(bv_);
2098 moveCursorUpdate(false);
2099 owner_->showState();
2103 case LFUN_DOWN_PARAGRAPH:
2105 LyXText * lt = bv_->getLyXText();
2107 if (!lt->selection.mark())
2109 update(lt, BufferView::UPDATE);
2110 lt->cursorDownParagraph(bv_);
2112 moveCursorUpdate(false);
2113 owner_->showState();
2119 LyXText * lt = bv_->getLyXText();
2121 if (!lt->selection.mark())
2123 update(lt, BufferView::UPDATE);
2126 moveCursorUpdate(false, false);
2127 owner_->showState();
2133 LyXText * lt = bv_->getLyXText();
2135 if (!lt->selection.mark())
2137 update(lt, BufferView::UPDATE);
2140 moveCursorUpdate(false, false);
2141 owner_->showState();
2147 LyXText * lt = bv_->getLyXText();
2149 if (!lt->selection.mark())
2151 update(lt, BufferView::SELECT|BufferView::FITCUR);
2152 lt->cursorHome(bv_);
2154 moveCursorUpdate(false);
2155 owner_->showState();
2161 LyXText * lt = bv_->getLyXText();
2163 if (!lt->selection.mark())
2166 BufferView::SELECT|BufferView::FITCUR);
2169 moveCursorUpdate(false);
2170 owner_->showState();
2174 case LFUN_SHIFT_TAB:
2177 LyXText * lt = bv_->getLyXText();
2179 if (!lt->selection.mark())
2182 BufferView::SELECT|BufferView::FITCUR);
2185 moveCursorUpdate(false);
2186 owner_->showState();
2190 case LFUN_WORDRIGHT:
2192 LyXText * lt = bv_->getLyXText();
2194 if (!lt->selection.mark())
2196 update(lt, BufferView::SELECT|BufferView::FITCUR);
2197 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2198 lt->cursorLeftOneWord(bv_);
2200 lt->cursorRightOneWord(bv_);
2202 moveCursorUpdate(false);
2203 owner_->showState();
2209 LyXText * lt = bv_->getLyXText();
2211 if (!lt->selection.mark())
2213 update(lt, BufferView::SELECT|BufferView::FITCUR);
2214 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2215 lt->cursorRightOneWord(bv_);
2217 lt->cursorLeftOneWord(bv_);
2219 moveCursorUpdate(false);
2220 owner_->showState();
2224 case LFUN_BEGINNINGBUF:
2226 LyXText * lt = bv_->getLyXText();
2228 if (!lt->selection.mark())
2231 BufferView::SELECT|BufferView::FITCUR);
2234 moveCursorUpdate(false);
2235 owner_->showState();
2241 LyXText * lt = bv_->getLyXText();
2243 if (!lt->selection.mark())
2246 BufferView::SELECT|BufferView::FITCUR);
2247 lt->cursorBottom(bv_);
2249 moveCursorUpdate(false);
2250 owner_->showState();
2254 /* cursor selection ---------------------------- */
2257 LyXText * lt = bv_->getLyXText();
2260 BufferView::SELECT|BufferView::FITCUR);
2261 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2262 lt->cursorLeft(bv_);
2264 lt->cursorRight(bv_);
2266 moveCursorUpdate(true);
2267 owner_->showState();
2273 LyXText * lt = bv_->getLyXText();
2276 BufferView::SELECT|BufferView::FITCUR);
2277 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2278 lt->cursorRight(bv_);
2280 lt->cursorLeft(bv_);
2282 moveCursorUpdate(true);
2283 owner_->showState();
2289 LyXText * lt = bv_->getLyXText();
2292 BufferView::SELECT|BufferView::FITCUR);
2293 lt->cursorUp(bv_, true);
2295 moveCursorUpdate(true);
2296 owner_->showState();
2302 LyXText * lt = bv_->getLyXText();
2305 BufferView::SELECT|BufferView::FITCUR);
2306 lt->cursorDown(bv_, true);
2308 moveCursorUpdate(true);
2309 owner_->showState();
2313 case LFUN_UP_PARAGRAPHSEL:
2315 LyXText * lt = bv_->getLyXText();
2318 BufferView::SELECT|BufferView::FITCUR);
2319 lt->cursorUpParagraph(bv_);
2321 moveCursorUpdate(true);
2322 owner_->showState();
2326 case LFUN_DOWN_PARAGRAPHSEL:
2328 LyXText * lt = bv_->getLyXText();
2331 BufferView::SELECT|BufferView::FITCUR);
2332 lt->cursorDownParagraph(bv_);
2334 moveCursorUpdate(true);
2335 owner_->showState();
2341 LyXText * lt = bv_->getLyXText();
2343 update(lt, BufferView::SELECT|BufferView::FITCUR);
2346 moveCursorUpdate(true);
2347 owner_->showState();
2353 LyXText * lt = bv_->getLyXText();
2355 update(lt, BufferView::SELECT|BufferView::FITCUR);
2358 moveCursorUpdate(true);
2359 owner_->showState();
2365 LyXText * lt = bv_->getLyXText();
2367 update(lt, BufferView::SELECT|BufferView::FITCUR);
2368 lt->cursorHome(bv_);
2370 moveCursorUpdate(true);
2371 owner_->showState();
2377 LyXText * lt = bv_->getLyXText();
2379 update(lt, BufferView::SELECT|BufferView::FITCUR);
2382 moveCursorUpdate(true);
2383 owner_->showState();
2387 case LFUN_WORDRIGHTSEL:
2389 LyXText * lt = bv_->getLyXText();
2391 update(lt, BufferView::SELECT|BufferView::FITCUR);
2392 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2393 lt->cursorLeftOneWord(bv_);
2395 lt->cursorRightOneWord(bv_);
2397 moveCursorUpdate(true);
2398 owner_->showState();
2402 case LFUN_WORDLEFTSEL:
2404 LyXText * lt = bv_->getLyXText();
2406 update(lt, BufferView::SELECT|BufferView::FITCUR);
2407 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2408 lt->cursorRightOneWord(bv_);
2410 lt->cursorLeftOneWord(bv_);
2412 moveCursorUpdate(true);
2413 owner_->showState();
2417 case LFUN_BEGINNINGBUFSEL:
2419 LyXText * lt = bv_->getLyXText();
2421 if (lt->inset_owner)
2423 update(lt, BufferView::SELECT|BufferView::FITCUR);
2426 moveCursorUpdate(true);
2427 owner_->showState();
2431 case LFUN_ENDBUFSEL:
2433 LyXText * lt = bv_->getLyXText();
2435 if (lt->inset_owner)
2438 BufferView::SELECT|BufferView::FITCUR);
2439 lt->cursorBottom(bv_);
2441 moveCursorUpdate(true);
2442 owner_->showState();
2446 // --- text changing commands ------------------------
2447 case LFUN_BREAKLINE:
2449 LyXText * lt = bv_->getLyXText();
2452 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2455 | BufferView::FITCUR
2456 | BufferView::CHANGE);
2457 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2458 moveCursorUpdate(false);
2462 case LFUN_PROTECTEDSPACE:
2464 LyXText * lt = bv_->getLyXText();
2466 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2468 if (style.free_spacing) {
2469 lt->insertChar(bv_, ' ');
2472 | BufferView::FITCUR
2473 | BufferView::CHANGE);
2475 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2477 moveCursorUpdate(false);
2483 LyXText * lt = bv_->getLyXText();
2485 if (lt->selection.mark()) {
2489 | BufferView::FITCUR);
2490 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2493 lt->selection.mark(true);
2496 | BufferView::FITCUR);
2497 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2499 lt->selection.cursor = lt->cursor;
2505 LyXText * lt = bv_->getLyXText();
2507 if (!lt->selection.set()) {
2509 lt->selection.cursor = lt->cursor;
2512 | BufferView::FITCUR
2513 | BufferView::CHANGE);
2514 // It is possible to make it a lot faster still
2515 // just comment out the line below...
2520 moveCursorUpdate(false);
2521 owner_->showState();
2526 case LFUN_DELETE_SKIP:
2528 LyXText * lt = bv_->getLyXText();
2530 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2532 LyXCursor cursor = lt->cursor;
2534 if (!lt->selection.set()) {
2535 if (cursor.pos() == cursor.par()->size()) {
2536 lt->cursorRight(bv_);
2537 cursor = lt->cursor;
2538 if (cursor.pos() == 0
2539 && !(cursor.par()->params().spaceTop()
2540 == VSpace (VSpace::NONE))) {
2543 cursor.par()->params().lineTop(),
2544 cursor.par()->params().lineBottom(),
2545 cursor.par()->params().pagebreakTop(),
2546 cursor.par()->params().pagebreakBottom(),
2547 VSpace(VSpace::NONE),
2548 cursor.par()->params().spaceBottom(),
2549 cursor.par()->params().spacing(),
2550 cursor.par()->params().align(),
2551 cursor.par()->params().labelWidthString(), 0);
2552 lt->cursorLeft(bv_);
2555 | BufferView::FITCUR
2556 | BufferView::CHANGE);
2558 lt->cursorLeft(bv_);
2560 lt->selection.cursor = lt->cursor;
2563 | BufferView::FITCUR
2564 | BufferView::CHANGE);
2568 lt->selection.cursor = lt->cursor;
2571 | BufferView::FITCUR
2572 | BufferView::CHANGE);
2580 /* -------> Delete word forward. */
2581 case LFUN_DELETE_WORD_FORWARD:
2582 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2583 bv_->getLyXText()->deleteWordForward(bv_);
2584 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2585 moveCursorUpdate(false);
2586 owner_->showState();
2589 /* -------> Delete word backward. */
2590 case LFUN_DELETE_WORD_BACKWARD:
2592 LyXText * lt = bv_->getLyXText();
2594 update(lt, BufferView::SELECT|BufferView::FITCUR);
2595 lt->deleteWordBackward(bv_);
2598 | BufferView::FITCUR
2599 | BufferView::CHANGE);
2600 moveCursorUpdate(false);
2601 owner_->showState();
2605 /* -------> Kill to end of line. */
2606 case LFUN_DELETE_LINE_FORWARD:
2608 LyXText * lt = bv_->getLyXText();
2610 update(lt, BufferView::SELECT|BufferView::FITCUR);
2611 lt->deleteLineForward(bv_);
2614 | BufferView::FITCUR
2615 | BufferView::CHANGE);
2616 moveCursorUpdate(false);
2620 /* -------> Set mark off. */
2623 LyXText * lt = bv_->getLyXText();
2626 update(lt, BufferView::SELECT|BufferView::FITCUR);
2627 lt->selection.cursor = lt->cursor;
2628 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2632 /* -------> Set mark on. */
2635 LyXText * lt = bv_->getLyXText();
2638 lt->selection.mark(true);
2639 update(lt, BufferView::SELECT|BufferView::FITCUR);
2640 lt->selection.cursor = lt->cursor;
2641 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2645 case LFUN_BACKSPACE:
2647 LyXText * lt = bv_->getLyXText();
2649 if (!lt->selection.set()) {
2650 if (owner_->getIntl()->getTrans().backspace()) {
2652 lt->selection.cursor = lt->cursor;
2655 | BufferView::FITCUR
2656 | BufferView::CHANGE);
2657 // It is possible to make it a lot faster still
2658 // just comment out the line below...
2664 owner_->showState();
2669 case LFUN_BACKSPACE_SKIP:
2671 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2672 LyXText * lt = bv_->getLyXText();
2674 LyXCursor cursor = lt->cursor;
2676 if (!lt->selection.set()) {
2677 if (cursor.pos() == 0
2678 && !(cursor.par()->params().spaceTop()
2679 == VSpace (VSpace::NONE))) {
2682 cursor.par()->params().lineTop(),
2683 cursor.par()->params().lineBottom(),
2684 cursor.par()->params().pagebreakTop(),
2685 cursor.par()->params().pagebreakBottom(),
2686 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2687 cursor.par()->params().spacing(),
2688 cursor.par()->params().align(),
2689 cursor.par()->params().labelWidthString(), 0);
2692 | BufferView::FITCUR
2693 | BufferView::CHANGE);
2696 lt->selection.cursor = cursor;
2699 | BufferView::FITCUR
2700 | BufferView::CHANGE);
2707 case LFUN_BREAKPARAGRAPH:
2709 LyXText * lt = bv_->getLyXText();
2712 lt->breakParagraph(bv_, 0);
2715 | BufferView::FITCUR
2716 | BufferView::CHANGE);
2717 lt->selection.cursor = lt->cursor;
2719 owner_->showState();
2723 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2725 LyXText * lt = bv_->getLyXText();
2728 lt->breakParagraph(bv_, 1);
2731 | BufferView::FITCUR
2732 | BufferView::CHANGE);
2733 lt->selection.cursor = lt->cursor;
2735 owner_->showState();
2739 case LFUN_BREAKPARAGRAPH_SKIP:
2741 // When at the beginning of a paragraph, remove
2742 // indentation and add a "defskip" at the top.
2743 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2744 LyXText * lt = bv_->getLyXText();
2746 LyXCursor cursor = lt->cursor;
2749 if (cursor.pos() == 0) {
2750 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2753 cursor.par()->params().lineTop(),
2754 cursor.par()->params().lineBottom(),
2755 cursor.par()->params().pagebreakTop(),
2756 cursor.par()->params().pagebreakBottom(),
2757 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2758 cursor.par()->params().spacing(),
2759 cursor.par()->params().align(),
2760 cursor.par()->params().labelWidthString(), 1);
2761 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2765 lt->breakParagraph(bv_, 0);
2766 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2771 | BufferView::FITCUR
2772 | BufferView::CHANGE);
2773 lt->selection.cursor = cursor;
2775 owner_->showState();
2779 case LFUN_PARAGRAPH_SPACING:
2781 LyXText * lt = bv_->getLyXText();
2783 Paragraph * par = lt->cursor.par();
2784 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2785 float cur_value = 1.0;
2786 if (cur_spacing == Spacing::Other) {
2787 cur_value = par->params().spacing().getValue();
2790 istringstream istr(argument.c_str());
2794 Spacing::Space new_spacing = cur_spacing;
2795 float new_value = cur_value;
2797 lyxerr << "Missing argument to `paragraph-spacing'"
2799 } else if (tmp == "single") {
2800 new_spacing = Spacing::Single;
2801 } else if (tmp == "onehalf") {
2802 new_spacing = Spacing::Onehalf;
2803 } else if (tmp == "double") {
2804 new_spacing = Spacing::Double;
2805 } else if (tmp == "other") {
2806 new_spacing = Spacing::Other;
2809 lyxerr << "new_value = " << tmpval << endl;
2812 } else if (tmp == "default") {
2813 new_spacing = Spacing::Default;
2815 lyxerr << _("Unknown spacing argument: ")
2816 << argument << endl;
2818 if (cur_spacing != new_spacing || cur_value != new_value) {
2819 par->params().spacing(Spacing(new_spacing, new_value));
2820 lt->redoParagraph(bv_);
2823 | BufferView::FITCUR
2824 | BufferView::CHANGE);
2829 case LFUN_INSET_TOGGLE:
2831 LyXText * lt = bv_->getLyXText();
2834 update(lt, BufferView::SELECT|BufferView::FITCUR);
2835 lt->toggleInset(bv_);
2836 update(lt, BufferView::SELECT|BufferView::FITCUR);
2848 InsetCommandParams p;
2849 if (action == LFUN_HTMLURL)
2850 p.setCmdName("htmlurl");
2852 p.setCmdName("url");
2853 owner_->getDialogs()->createUrl(p.getAsString());
2857 case LFUN_INSERT_URL:
2859 InsetCommandParams p;
2860 p.setFromString(argument);
2862 InsetUrl * inset = new InsetUrl(p);
2863 if (!insertInset(inset))
2866 updateInset(inset, true);
2870 case LFUN_INSET_ERT:
2871 insertAndEditInset(new InsetERT(buffer_->params));
2874 case LFUN_INSET_EXTERNAL:
2875 insertAndEditInset(new InsetExternal);
2878 case LFUN_INSET_FOOTNOTE:
2879 insertAndEditInset(new InsetFoot(buffer_->params));
2882 case LFUN_INSET_MARGINAL:
2883 insertAndEditInset(new InsetMarginal(buffer_->params));
2886 case LFUN_INSET_MINIPAGE:
2887 insertAndEditInset(new InsetMinipage(buffer_->params));
2890 case LFUN_INSERT_NOTE:
2891 insertAndEditInset(new InsetNote(buffer_->params));
2894 case LFUN_INSET_FLOAT:
2895 // check if the float type exist
2896 if (floatList.typeExist(argument)) {
2897 insertAndEditInset(new InsetFloat(buffer_->params,
2900 lyxerr << "Non-existent float type: "
2901 << argument << endl;
2905 case LFUN_INSET_WIDE_FLOAT:
2906 // check if the float type exist
2907 if (floatList.typeExist(argument)) {
2908 InsetFloat * new_inset =
2909 new InsetFloat(buffer_->params, argument);
2910 new_inset->wide(true);
2911 insertAndEditInset(new_inset);
2913 lyxerr << "Non-existent float type: "
2914 << argument << endl;
2919 case LFUN_INSET_LIST:
2920 insertAndEditInset(new InsetList);
2923 case LFUN_INSET_THEOREM:
2924 insertAndEditInset(new InsetTheorem);
2928 case LFUN_INSET_CAPTION:
2930 // Do we have a locking inset...
2931 if (bv_->theLockingInset()) {
2932 lyxerr << "Locking inset code: "
2933 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2934 InsetCaption * new_inset =
2935 new InsetCaption(buffer_->params);
2936 new_inset->setOwner(bv_->theLockingInset());
2937 new_inset->setAutoBreakRows(true);
2938 new_inset->setDrawFrame(0, InsetText::LOCKED);
2939 new_inset->setFrameColor(0, LColor::captionframe);
2940 if (insertInset(new_inset))
2941 new_inset->edit(bv_);
2948 case LFUN_INSET_TABULAR:
2952 if (!argument.empty())
2953 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2954 InsetTabular * new_inset =
2955 new InsetTabular(*buffer_, r, c);
2957 bv_->getLyXText()->real_current_font.isRightToLeft();
2958 if (!open_new_inset(new_inset, rtl))
2963 // --- lyxserver commands ----------------------------
2965 case LFUN_CHARATCURSOR:
2967 pos_type pos = bv_->getLyXText()->cursor.pos();
2968 if (pos < bv_->getLyXText()->cursor.par()->size())
2969 owner_->getLyXFunc()->setMessage(
2970 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2972 owner_->getLyXFunc()->setMessage("EOF");
2977 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2979 + tostr(bv_->getLyXText()->cursor.y()));
2986 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2987 lyxerr << "SETXY: Could not parse coordinates in '"
2988 << argument << std::endl;
2990 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2994 case LFUN_GETLAYOUT:
2995 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3000 LyXFont & font = bv_->getLyXText()->current_font;
3001 if (font.shape() == LyXFont::ITALIC_SHAPE)
3002 owner_->getLyXFunc()->setMessage("E");
3003 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3004 owner_->getLyXFunc()->setMessage("N");
3006 owner_->getLyXFunc()->setMessage("0");
3011 // --- accented characters ---------------------------
3014 case LFUN_CIRCUMFLEX:
3024 case LFUN_SPECIAL_CARON:
3027 case LFUN_HUNG_UMLAUT:
3030 if (argument.empty()) {
3032 owner_->getLyXFunc()->handleKeyFunc(action);
3034 owner_->getLyXFunc()->handleKeyFunc(action);
3035 owner_->getIntl()->getTrans()
3036 .TranslateAndInsert(argument[0], bv_->getLyXText());
3037 update(bv_->getLyXText(),
3039 | BufferView::FITCUR
3040 | BufferView::CHANGE);
3044 case LFUN_MATH_MACRO:
3045 mathDispatchMathMacro(bv_, argument);
3048 case LFUN_MATH_DELIM:
3049 mathDispatchMathDelim(bv_, argument);
3052 case LFUN_INSERT_MATRIX:
3053 mathDispatchInsertMatrix(bv_, argument);
3056 case LFUN_INSERT_MATH:
3057 mathDispatchInsertMath(bv_, argument);
3060 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3061 mathDispatchMathImportSelection(bv_, argument);
3064 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3065 mathDispatchMathDisplay(bv_, argument);
3068 case LFUN_MATH_MODE: // Open or create an inlined math inset
3069 mathDispatchMathMode(bv_, argument);
3072 case LFUN_GREEK: // Insert a single greek letter
3073 mathDispatchGreek(bv_, argument);
3076 case LFUN_CITATION_INSERT:
3078 InsetCommandParams p;
3079 p.setFromString(argument);
3081 InsetCitation * inset = new InsetCitation(p);
3082 if (!insertInset(inset))
3085 updateInset(inset, true);
3089 case LFUN_INSERT_BIBTEX:
3091 // ale970405+lasgoutt970425
3092 // The argument can be up to two tokens separated
3093 // by a space. The first one is the bibstyle.
3094 string const db = token(argument, ' ', 0);
3095 string const bibstyle = token(argument, ' ', 1);
3097 InsetCommandParams p("BibTeX", db, bibstyle);
3098 InsetBibtex * inset = new InsetBibtex(p);
3100 if (insertInset(inset)) {
3101 if (argument.empty())
3108 // BibTeX data bases
3109 case LFUN_BIBDB_ADD:
3111 InsetBibtex * inset =
3112 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3114 inset->addDatabase(argument);
3119 case LFUN_BIBDB_DEL:
3121 InsetBibtex * inset =
3122 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3124 inset->delDatabase(argument);
3129 case LFUN_BIBTEX_STYLE:
3131 InsetBibtex * inset =
3132 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3134 inset->setOptions(argument);
3139 case LFUN_INDEX_CREATE:
3141 InsetCommandParams p("index");
3142 if (argument.empty()) {
3143 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3144 p.setContents(idxstring);
3146 p.setContents(argument);
3149 owner_->getDialogs()->createIndex(p.getAsString());
3153 case LFUN_INDEX_INSERT:
3155 InsetCommandParams p;
3156 p.setFromString(argument);
3157 InsetIndex * inset = new InsetIndex(p);
3159 if (!insertInset(inset))
3162 updateInset(inset, true);
3166 case LFUN_INDEX_INSERT_LAST:
3168 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3169 if (!idxstring.empty()) {
3170 owner_->message(_("Word `")
3171 + idxstring + _(("' indexed.")));
3172 InsetCommandParams p("index", idxstring);
3173 InsetIndex * inset = new InsetIndex(p);
3175 if (!insertInset(inset))
3178 updateInset(inset, true);
3183 case LFUN_INDEX_PRINT:
3185 InsetCommandParams p("printindex");
3186 Inset * inset = new InsetPrintIndex(p);
3187 if (!insertInset(inset, tclass.defaultLayoutName()))
3192 case LFUN_PARENTINSERT:
3194 InsetCommandParams p("lyxparent", argument);
3195 Inset * inset = new InsetParent(p, *buffer_);
3196 if (!insertInset(inset, tclass.defaultLayoutName()))
3202 case LFUN_CHILD_INSERT:
3204 InsetInclude::Params p;
3205 p.cparams.setFromString(argument);
3206 p.masterFilename_ = buffer_->fileName();
3208 InsetInclude * inset = new InsetInclude(p);
3209 if (!insertInset(inset))
3212 updateInset(inset, true);
3213 bv_->owner()->getDialogs()->showInclude(inset);
3218 case LFUN_FLOAT_LIST:
3219 if (floatList.typeExist(argument)) {
3220 Inset * inset = new InsetFloatList(argument);
3221 if (!insertInset(inset, tclass.defaultLayoutName()))
3224 lyxerr << "Non-existent float type: "
3225 << argument << endl;
3229 case LFUN_THESAURUS_ENTRY:
3231 string arg = argument;
3234 arg = bv_->getLyXText()->selectionAsString(buffer_,
3238 if (arg.size() > 100 || arg.empty()) {
3239 // Get word or selection
3240 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3241 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3242 // FIXME: where is getLyXText()->unselect(bv_) ?
3246 bv_->owner()->getDialogs()->showThesaurus(arg);
3250 case LFUN_SELFINSERT:
3252 if (argument.empty()) break;
3254 /* Automatically delete the currently selected
3255 * text and replace it with what is being
3256 * typed in now. Depends on lyxrc settings
3257 * "auto_region_delete", which defaults to
3260 LyXText * lt = bv_->getLyXText();
3262 if (lyxrc.auto_region_delete) {
3263 if (lt->selection.set()) {
3264 lt->cutSelection(bv_, false, false);
3267 | BufferView::FITCUR
3268 | BufferView::CHANGE);
3270 workarea().haveSelection(false);
3274 LyXFont const old_font(lt->real_current_font);
3276 string::const_iterator cit = argument.begin();
3277 string::const_iterator end = argument.end();
3278 for (; cit != end; ++cit) {
3279 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3284 | BufferView::FITCUR
3285 | BufferView::CHANGE);
3287 lt->selection.cursor = lt->cursor;
3288 moveCursorUpdate(false);
3290 // real_current_font.number can change so we need to
3291 // update the minibuffer
3292 if (old_font != lt->real_current_font)
3293 owner_->showState();
3298 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3300 time_t now_time_t = time(NULL);
3301 struct tm * now_tm = localtime(&now_time_t);
3302 setlocale(LC_TIME, "");
3304 if (!argument.empty())
3307 arg = lyxrc.date_insert_format;
3309 int const datetmp_len =
3310 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3312 LyXText * lt = bv_->getLyXText();
3314 for (int i = 0; i < datetmp_len; i++) {
3315 lt->insertChar(bv_, datetmp[i]);
3318 | BufferView::FITCUR
3319 | BufferView::CHANGE);
3322 lt->selection.cursor = lt->cursor;
3323 moveCursorUpdate(false);
3327 case LFUN_UNKNOWN_ACTION:
3328 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3339 void BufferView::Pimpl::newline()
3342 LyXText * lt = bv_->getLyXText();
3346 | BufferView::FITCUR);
3347 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3350 | BufferView::FITCUR
3351 | BufferView::CHANGE);
3356 void BufferView::Pimpl::hfill()
3359 LyXText * lt = bv_->getLyXText();
3363 | BufferView::FITCUR);
3364 lt->insertChar(bv_, Paragraph::META_HFILL);
3367 | BufferView::FITCUR
3368 | BufferView::CHANGE);
3373 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3376 LyXText * lt = bv_->getLyXText();
3379 update(lt, BufferView::SELECT|BufferView::FITCUR);
3380 InsetSpecialChar * new_inset =
3381 new InsetSpecialChar(kind);
3382 if (!insertInset(new_inset))
3385 updateInset(new_inset, true);
3390 void BufferView::Pimpl::smartQuote()
3392 LyXText const * lt = bv_->getLyXText();
3393 Paragraph const * par = lt->cursor.par();
3394 pos_type pos = lt->cursor.pos();
3398 || (par->isInset(pos - 1)
3399 && par->getInset(pos - 1)->isSpace()))
3402 c = par->getChar(pos - 1);
3407 LyXLayout const & style =
3408 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3410 if (style.pass_thru ||
3411 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3412 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3416 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3418 if (insertInset(inset))
3425 // Open and lock an updatable inset
3426 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3428 LyXText * lt = bv_->getLyXText();
3432 if (!insertInset(new_inset)) {
3436 new_inset->edit(bv_, !behind);
3441 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3443 // if we are in a locking inset we should try to insert the
3444 // inset there otherwise this is a illegal function now
3445 if (bv_->theLockingInset()) {
3446 if (bv_->theLockingInset()->insetAllowed(inset))
3447 return bv_->theLockingInset()->insertInset(bv_, inset);
3451 // not quite sure if we want this...
3452 setCursorParUndo(bv_);
3455 beforeChange(bv_->text);
3456 if (!lout.empty()) {
3457 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3458 bv_->text->breakParagraph(bv_);
3459 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3461 if (bv_->text->cursor.par()->size()) {
3462 bv_->text->cursorLeft(bv_);
3464 bv_->text->breakParagraph(bv_);
3465 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3469 LyXTextClass const & tclass =
3470 textclasslist[buffer_->params.textclass];
3471 bool hasLayout = tclass.hasLayout(lres);
3472 string lay = tclass.defaultLayoutName();
3474 if (hasLayout != false) {
3478 // layout not fount using default
3479 lay = tclass.defaultLayoutName();
3482 bv_->text->setLayout(bv_, lay);
3484 bv_->text->setParagraph(bv_, 0, 0,
3486 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3491 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3494 bv_->text->insertInset(bv_, inset);
3495 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3502 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3504 if (!inset || !available())
3507 // first check for locking insets
3508 if (bv_->theLockingInset()) {
3509 if (bv_->theLockingInset() == inset) {
3510 if (bv_->text->updateInset(bv_, inset)) {
3513 buffer_->markDirty();
3518 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3519 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3522 buffer_->markDirty();
3530 // then check if the inset is a top_level inset (has no owner)
3531 // if yes do the update as always otherwise we have to update the
3532 // toplevel inset where this inset is inside
3533 Inset * tl_inset = inset;
3534 while(tl_inset->owner())
3535 tl_inset = tl_inset->owner();
3537 if (tl_inset == inset) {
3538 update(bv_->text, BufferView::UPDATE);
3539 if (bv_->text->updateInset(bv_, inset)) {
3543 | BufferView::FITCUR
3544 | BufferView::CHANGE);
3546 update(bv_->text, SELECT);
3550 } else if (static_cast<UpdatableInset *>(tl_inset)
3551 ->updateInsetInInset(bv_, inset))
3553 if (bv_->text->updateInset(bv_, tl_inset)) {
3561 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3564 if (!available()) return;
3567 beforeChange(bv_->text);
3568 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3570 LyXCursor const & cursor = bv_->text->cursor;
3574 cursor.par()->isInset(cursor.pos())) {
3575 Inset const * inset = cursor.par()->getInset(cursor.pos());
3576 if (find(codes.begin(), codes.end(), inset->lyxCode())
3579 static_cast<InsetCommand const *>(inset)->getContents();
3583 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3584 if (bv_->text->cursor.pos()
3585 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3586 LyXCursor tmp = bv_->text->cursor;
3587 bv_->text->cursor.par(bv_->text->ownerParagraph());
3588 bv_->text->cursor.pos(0);
3589 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3590 bv_->text->cursor = tmp;
3591 bv_->owner()->message(_("No more insets"));
3594 bv_->owner()->message(_("No more insets"));
3597 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3598 bv_->text->selection.cursor = bv_->text->cursor;
3602 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3604 gotoInset(vector<Inset::Code>(1, code), same_content);