7 #include "BufferView_pimpl.h"
8 #include "frontends/WorkArea.h"
9 #include "frontends/screen.h"
12 #include "paragraph.h"
13 #include "frontends/LyXView.h"
14 #include "commandtags.h"
17 #include "bufferview_funcs.h"
18 #include "TextCache.h"
19 #include "bufferlist.h"
22 // added for Dispatch functions
25 #include "FloatList.h"
27 #include "ParagraphParameters.h"
28 #include "undo_funcs.h"
29 #include "lyxtextclasslist.h"
31 #include "frontends/Dialogs.h"
32 #include "frontends/Alert.h"
33 #include "frontends/FileDialog.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 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
143 workarea_.scrollCB.connect(boost::bind(&BufferView::Pimpl::scrollCB, this, _1));
144 workarea_.workAreaExpose
145 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
146 workarea_.workAreaEnter
147 .connect(boost::bind(&BufferView::Pimpl::enterView, this));
148 workarea_.workAreaLeave
149 .connect(boost::bind(&BufferView::Pimpl::leaveView, this));
150 workarea_.workAreaButtonPress
151 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
152 workarea_.workAreaButtonRelease
153 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
154 workarea_.workAreaMotionNotify
155 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
156 workarea_.workAreaDoubleClick
157 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
158 workarea_.workAreaTripleClick
159 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
160 workarea_.workAreaKeyPress
161 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
162 workarea_.selectionRequested
163 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
164 workarea_.selectionLost
165 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
167 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
168 cursor_timeout.start();
169 workarea_.setFocus();
170 saved_positions.resize(saved_positions_num);
174 Painter & BufferView::Pimpl::painter()
176 return workarea_.getPainter();
180 void BufferView::Pimpl::buffer(Buffer * b)
182 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
188 buffer_->delUser(bv_);
190 // Put the old text into the TextCache, but
191 // only if the buffer is still loaded.
192 // Also set the owner of the test to 0
193 // bv_->text->owner(0);
194 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
195 if (lyxerr.debugging())
196 textcache.show(lyxerr, "BufferView::buffer");
201 // Set current buffer
204 if (bufferlist.getState() == BufferList::CLOSING) return;
207 // screen is always deleted when the buffer is changed.
210 // If we are closing the buffer, use the first buffer as current
212 buffer_ = bufferlist.first();
216 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
217 buffer_->addUser(bv_);
218 // If we don't have a text object for this, we make one
219 if (bv_->text == 0) {
220 resizeCurrentBuffer();
225 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
226 owner_->updateMenubar();
227 owner_->updateToolbar();
228 // Similarly, buffer-dependent dialogs should be updated or
229 // hidden. This should go here because some dialogs (eg ToC)
230 // require bv_->text.
231 owner_->getDialogs()->updateBufferDependent(true);
237 lyxerr[Debug::INFO] << " No Buffer!" << endl;
238 owner_->updateMenubar();
239 owner_->updateToolbar();
240 owner_->getDialogs()->hideBufferDependent();
244 // Also remove all remaining text's from the testcache.
245 // (there should not be any!) (if there is any it is a
247 if (lyxerr.debugging())
248 textcache.show(lyxerr, "buffer delete all");
251 // should update layoutchoice even if we don't have a buffer.
252 owner_->updateLayoutChoice();
254 owner_->updateWindowTitle();
258 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
260 workarea_.resize(xpos, ypos, width, height);
261 update(bv_->text, SELECT);
266 void BufferView::Pimpl::resize()
269 resizeCurrentBuffer();
273 void BufferView::Pimpl::redraw()
275 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
280 bool BufferView::Pimpl::fitCursor()
282 lyx::Assert(screen_.get());
286 if (bv_->theLockingInset()) {
287 bv_->theLockingInset()->fitInsetCursor(bv_);
290 ret = screen_->fitCursor(bv_->text, bv_);
293 bv_->owner()->getDialogs()->updateParagraph();
300 void BufferView::Pimpl::redoCurrentBuffer()
302 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
303 if (buffer_ && bv_->text) {
305 owner_->updateLayoutChoice();
310 int BufferView::Pimpl::resizeCurrentBuffer()
312 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
315 Paragraph * selstartpar = 0;
316 Paragraph * selendpar = 0;
317 UpdatableInset * the_locking_inset = 0;
320 pos_type selstartpos = 0;
321 pos_type selendpos = 0;
322 bool selection = false;
323 bool mark_set = false;
325 owner_->prohibitInput();
327 owner_->message(_("Formatting document..."));
330 par = bv_->text->cursor.par();
331 pos = bv_->text->cursor.pos();
332 selstartpar = bv_->text->selection.start.par();
333 selstartpos = bv_->text->selection.start.pos();
334 selendpar = bv_->text->selection.end.par();
335 selendpos = bv_->text->selection.end.pos();
336 selection = bv_->text->selection.set();
337 mark_set = bv_->text->selection.mark();
338 the_locking_inset = bv_->theLockingInset();
339 buffer_->resizeInsets(bv_);
340 // I don't think the delete and new are necessary here we just could
341 // call only init! (Jug 20020419)
343 bv_->text = new LyXText(bv_);
344 bv_->text->init(bv_);
346 // See if we have a text in TextCache that fits
347 // the new buffer_ with the correct width.
348 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
350 if (lyxerr.debugging()) {
351 lyxerr << "Found a LyXText that fits:\n";
352 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
354 // Set the owner of the newly found text
355 // bv_->text->owner(bv_);
356 if (lyxerr.debugging())
357 textcache.show(lyxerr, "resizeCurrentBuffer");
359 bv_->text = new LyXText(bv_);
360 bv_->text->init(bv_);
361 //buffer_->resizeInsets(bv_);
368 bv_->text->selection.set(true);
369 // At this point just to avoid the Delete-Empty-Paragraph-
370 // Mechanism when setting the cursor.
371 bv_->text->selection.mark(mark_set);
373 bv_->text->setCursor(bv_, selstartpar, selstartpos);
374 bv_->text->selection.cursor = bv_->text->cursor;
375 bv_->text->setCursor(bv_, selendpar, selendpos);
376 bv_->text->setSelection(bv_);
377 bv_->text->setCursor(bv_, par, pos);
379 bv_->text->setCursor(bv_, par, pos);
380 bv_->text->selection.cursor = bv_->text->cursor;
381 bv_->text->selection.set(false);
383 // remake the inset locking
384 bv_->theLockingInset(the_locking_inset);
387 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
389 // this will scroll the screen such that the cursor becomes visible
394 owner_->allowInput();
396 /// clear the "Formatting Document" message
403 void BufferView::Pimpl::updateScreen()
405 // Regenerate the screen.
406 screen_.reset(new LyXScreen(workarea_));
410 void BufferView::Pimpl::updateScrollbar()
413 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
414 workarea_.setScrollbar(0, 1.0);
418 long const text_height = bv_->text->height;
419 long const work_height = workarea_.height();
421 double const lineh = bv_->text->defaultHeight();
422 double const slider_size =
423 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
425 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
426 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
428 /* If the text is smaller than the working area, the scrollbar
429 * maximum must be the working area height. No scrolling will
431 if (text_height <= work_height) {
432 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
433 workarea_.setScrollbarBounds(0.0, 0.0);
434 current_scrollbar_value = bv_->text->first_y;
435 workarea_.setScrollbar(current_scrollbar_value, 1.0);
439 workarea_.setScrollbarBounds(0.0, text_height - work_height);
440 workarea_.setScrollbarIncrements(lineh);
441 current_scrollbar_value = bv_->text->first_y;
442 workarea_.setScrollbar(current_scrollbar_value, slider_size);
446 // Callback for scrollbar slider
447 void BufferView::Pimpl::scrollCB(double value)
449 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
451 if (!buffer_) return;
453 current_scrollbar_value = long(value);
455 if (current_scrollbar_value < 0)
456 current_scrollbar_value = 0;
461 screen_->draw(bv_->text, bv_, current_scrollbar_value);
463 if (!lyxrc.cursor_follows_scrollbar) {
468 LyXText * vbt = bv_->text;
470 int const height = vbt->defaultHeight();
471 int const first = static_cast<int>((bv_->text->first_y + height));
472 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
474 if (vbt->cursor.y() < first)
475 vbt->setCursorFromCoordinates(bv_, 0, first);
476 else if (vbt->cursor.y() > last)
477 vbt->setCursorFromCoordinates(bv_, 0, last);
483 int BufferView::Pimpl::scrollUp(long time)
485 if (!buffer_ || !screen_.get())
488 double value = workarea_.getScrollbarValue();
494 float add_value = (bv_->text->defaultHeight()
495 + float(time) * float(time) * 0.125);
497 if (add_value > workarea_.height())
498 add_value = float(workarea_.height() -
499 bv_->text->defaultHeight());
501 float add_value = float(workarea_.height()) * float(time) / 100;
509 workarea_.setScrollbarValue(value);
516 int BufferView::Pimpl::scrollDown(long time)
518 if (!buffer_ || !screen_.get())
521 double value = workarea_.getScrollbarValue();
522 pair<float, float> p = workarea_.getScrollbarBounds();
523 double const max = p.second;
529 float add_value = (bv_->text->defaultHeight()
530 + float(time) * float(time) * 0.125);
532 if (add_value > workarea_.height())
533 add_value = float(workarea_.height() -
534 bv_->text->defaultHeight());
536 float add_value = float(workarea_.height()) * float(time) / 100;
544 workarea_.setScrollbarValue(value);
551 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, key_modifier::state state)
553 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
557 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
559 // Only use motion with button 1
560 if (!(state & mouse_button::button1))
563 if (!buffer_ || !screen_.get()) return;
565 // Check for inset locking
566 if (bv_->theLockingInset()) {
567 LyXCursor cursor = bv_->text->cursor;
568 LyXFont font = bv_->text->getFont(buffer_,
569 cursor.par(), cursor.pos());
570 int width = bv_->theLockingInset()->width(bv_, font);
571 int inset_x = font.isVisibleRightToLeft()
572 ? cursor.ix() - width : cursor.ix();
573 int start_x = inset_x + bv_->theLockingInset()->scroll();
574 bv_->theLockingInset()->
575 insetMotionNotify(bv_,
577 y - cursor.iy() + bv_->text->first_y,
582 /* The test for not selection possible is needed, that only motion
583 events are used, where the bottom press event was on
584 the drawing area too */
585 if (!selection_possible)
588 screen_->hideCursor();
590 int y_before = bv_->text->cursor.y();
592 Row * cursorrow = bv_->text->cursor.row();
593 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
595 // sorry for this but I have a strange error that the y value jumps at
596 // a certain point. This seems like an error in my xforms library or
597 // in some other local environment, but I would like to leave this here
598 // for the moment until I can remove this (Jug 20020418)
599 if (y_before < bv_->text->cursor.y())
600 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
602 // This is to allow jumping over large insets
603 if (cursorrow == bv_->text->cursor.row()) {
604 if (y >= int(workarea_.height())) {
605 bv_->text->cursorDown(bv_, false);
607 bv_->text->cursorUp(bv_, false);
611 if (!bv_->text->selection.set())
612 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
614 bv_->text->setSelection(bv_);
615 screen_->toggleToggle(bv_->text, bv_);
621 // Single-click on work area
622 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
623 mouse_button::state button)
625 if (!buffer_ || !screen_.get())
628 // ok ok, this is a hack.
630 if (button == mouse_button::button4) {
631 scrollUp(lyxrc.wheel_jump);
632 // We shouldn't go further down as we really should only do the
633 // scrolling and be done with this. Otherwise we may open some
634 // dialogs (Jug 20020424).
636 } else if (button == mouse_button::button5) {
637 scrollDown(lyxrc.wheel_jump);
638 // We shouldn't go further down as we really should only do the
639 // scrolling and be done with this. Otherwise we may open some
640 // dialogs (Jug 20020424).
644 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
646 // Middle button press pastes if we have a selection
647 // We do this here as if the selection was inside an inset
648 // it could get cleared on the unlocking of the inset so
649 // we have to check this first
650 bool paste_internally = false;
651 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
652 owner_->getLyXFunc()->dispatch(LFUN_COPY);
653 paste_internally = true;
656 int const screen_first = bv_->text->first_y;
658 if (bv_->theLockingInset()) {
659 // We are in inset locking mode
661 /* Check whether the inset was hit. If not reset mode,
662 otherwise give the event to the inset */
663 if (inset_hit == bv_->theLockingInset()) {
664 bv_->theLockingInset()->
665 insetButtonPress(bv_,xpos, ypos,button);
668 bv_->unlockInset(bv_->theLockingInset());
673 selection_possible = true;
674 screen_->hideCursor();
676 // Clear the selection
677 screen_->toggleSelection(bv_->text, bv_);
678 bv_->text->clearSelection();
679 bv_->text->fullRebreak(bv_);
683 // Single left click in math inset?
684 if (isHighlyEditableInset(inset_hit)) {
685 // Highly editable inset, like math
686 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
687 selection_possible = false;
688 owner_->updateLayoutChoice();
689 owner_->message(inset->editMessage());
690 //inset->edit(bv_, xpos, ypos, button);
691 // We just have to lock the inset before calling a PressEvent on it!
692 // we don't need the edit() call here! (Jug20020329)
693 if (!bv_->lockInset(inset)) {
694 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
696 inset->insetButtonPress(bv_, xpos, ypos, button);
699 // I'm not sure we should continue here if we hit an inset (Jug20020403)
701 // Right click on a footnote flag opens float menu
702 if (button == mouse_button::button3) {
703 selection_possible = false;
707 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
708 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
710 bv_->text->selection.cursor = bv_->text->cursor;
711 bv_->text->cursor.x_fix(bv_->text->cursor.x());
713 owner_->updateLayoutChoice();
715 selection_possible = false;
718 // Insert primary selection with middle mouse
719 // if there is a local selection in the current buffer,
721 if (button == mouse_button::button2) {
722 if (paste_internally)
723 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
725 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
727 selection_possible = false;
733 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
738 LyXText * text = bv_->getLyXText();
740 if (text->bv_owner && bv_->theLockingInset())
743 if (screen_.get() && button == mouse_button::button1) {
744 if (text->bv_owner) {
745 screen_->hideCursor();
746 screen_->toggleSelection(text, bv_);
747 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
748 screen_->toggleSelection(text, bv_, false);
750 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
752 /* This will fit the cursor on the screen
754 update(text, BufferView::SELECT|BufferView::FITCUR);
759 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
764 LyXText * text = bv_->getLyXText();
766 if (text->bv_owner && bv_->theLockingInset())
769 if (screen_.get() && (button == mouse_button::button1)) {
770 if (text->bv_owner) {
771 screen_->hideCursor();
772 screen_->toggleSelection(text, bv_);
774 text->cursorHome(bv_);
775 text->selection.cursor = text->cursor;
776 text->cursorEnd(bv_);
777 text->setSelection(bv_);
778 if (text->bv_owner) {
779 screen_->toggleSelection(text, bv_, false);
781 /* This will fit the cursor on the screen
783 update(text, BufferView::SELECT|BufferView::FITCUR);
788 void BufferView::Pimpl::selectionRequested()
795 LyXText * text = bv_->getLyXText();
797 if (text->selection.set() &&
798 (!bv_->text->xsel_cache.set() ||
799 text->selection.start != bv_->text->xsel_cache.start ||
800 text->selection.end != bv_->text->xsel_cache.end))
802 bv_->text->xsel_cache = text->selection;
803 sel = text->selectionAsString(bv_->buffer(), false);
804 } else if (!text->selection.set()) {
806 bv_->text->xsel_cache.set(false);
809 workarea_.putClipboard(sel);
814 void BufferView::Pimpl::selectionLost()
816 if (active() && available()) {
819 bv_->getLyXText()->clearSelection();
821 bv_->text->xsel_cache.set(false);
826 void BufferView::Pimpl::enterView()
828 if (active() && available()) {
829 SetXtermCursor(workarea_.getWin());
830 using_xterm_cursor = true;
835 void BufferView::Pimpl::leaveView()
837 if (using_xterm_cursor) {
838 XUndefineCursor(fl_get_display(), workarea_.getWin());
839 using_xterm_cursor = false;
844 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
845 mouse_button::state button)
847 // do nothing if we used the mouse wheel
848 if (!buffer_ || !screen_.get() || button == mouse_button::button4 || button == mouse_button::button5)
851 // If we hit an inset, we have the inset coordinates in these
852 // and inset_hit points to the inset. If we do not hit an
853 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
854 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
856 if (bv_->theLockingInset()) {
857 // We are in inset locking mode.
859 /* LyX does a kind of work-area grabbing for insets.
860 Only a ButtonPress Event outside the inset will
861 force a insetUnlock. */
862 bv_->theLockingInset()->
863 insetButtonRelease(bv_, x, y, button);
867 selection_possible = false;
869 if (button == mouse_button::button2)
873 if (button == mouse_button::button1) {
874 workarea_.haveSelection(bv_->getLyXText()->selection.set());
879 owner_->updateMenubar();
880 owner_->updateToolbar();
882 // Did we hit an editable inset?
884 selection_possible = false;
886 // if we reach this point with a selection, it
887 // must mean we are currently selecting.
888 // But we don't want to open the inset
889 // because that is annoying for the user.
890 // So just pretend we didn't hit it.
891 // this is OK because a "kosher" ButtonRelease
892 // will follow a ButtonPress that clears
894 // Note this also fixes selection drawing
895 // problems if we end up opening an inset
896 if (bv_->getLyXText()->selection.set())
899 // CHECK fix this proper in 0.13
900 // well, maybe 13.0 !!!!!!!!!
902 // Following a ref shouldn't issue
903 // a push on the undo-stack
904 // anylonger, now that we have
905 // keybindings for following
906 // references and returning from
907 // references. IMHO though, it
908 // should be the inset's own business
909 // to push or not push on the undo
910 // stack. They don't *have* to
911 // alter the document...
913 // ...or maybe the SetCursorParUndo()
914 // below isn't necessary at all anylonger?
915 if (inset_hit->lyxCode() == Inset::REF_CODE) {
916 setCursorParUndo(bv_);
919 owner_->message(inset_hit->editMessage());
921 if (isHighlyEditableInset(inset_hit)) {
922 // Highly editable inset, like math
923 UpdatableInset *inset = (UpdatableInset *)inset_hit;
924 inset->insetButtonRelease(bv_, x, y, button);
926 inset_hit->insetButtonRelease(bv_, x, y, button);
927 // IMO this is a grosshack! Inset's should be changed so that
928 // they call the actions they have to do with the insetButtonRel.
929 // function and not in the edit(). This should be changed
931 inset_hit->edit(bv_, x, y, button);
936 // Maybe we want to edit a bibitem ale970302
937 if (bv_->text->cursor.par()->bibkey && x < 20 +
938 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
939 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
946 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
947 LyXCursor const & cursor) const
949 Paragraph /*const*/ & par = *cursor.par();
950 pos_type const pos = cursor.pos();
952 lyx::Assert(par.getInset(pos));
954 Inset const & inset(*par.getInset(pos));
956 LyXFont const & font = text.getFont(buffer_, &par, pos);
958 int const width = inset.width(bv_, font);
959 int const inset_x = font.isVisibleRightToLeft()
960 ? (cursor.ix() - width) : cursor.ix();
963 inset_x + inset.scroll(),
965 cursor.iy() - inset.ascent(bv_, font),
966 cursor.iy() + inset.descent(bv_, font));
970 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
971 LyXCursor const & cursor,
972 int & x, int & y) const
974 pos_type const pos(cursor.pos());
975 Paragraph /*const*/ & par(*cursor.par());
977 if (pos >= par.size() || !par.isInset(pos)) {
981 Inset /*const*/ * inset = par.getInset(pos);
983 if (!isEditableInset(inset)) {
987 Box b(insetDimensions(text, cursor));
989 if (!b.contained(x, y)) {
990 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
991 << " box " << b << endl;
995 text.setCursor(bv_, &par, pos, true);
998 // The origin of an inset is on the baseline
999 y -= text.cursor.iy();
1005 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
1010 int y_tmp = y + text->first_y;
1013 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
1015 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1022 // look at previous position
1024 if (cursor.pos() == 0) {
1029 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1031 inset = checkInset(*text, cursor, x, y_tmp);
1039 void BufferView::Pimpl::workAreaExpose()
1041 static int work_area_width;
1042 static unsigned int work_area_height;
1044 bool const widthChange = workarea_.workWidth() != work_area_width;
1045 bool const heightChange = workarea_.height() != work_area_height;
1047 // update from work area
1048 work_area_width = workarea_.workWidth();
1049 work_area_height = workarea_.height();
1052 // The visible LyXView need a resize
1055 // Remove all texts from the textcache
1056 // This is not _really_ what we want to do. What
1057 // we really want to do is to delete in textcache
1058 // that does not have a BufferView with matching
1059 // width, but as long as we have only one BufferView
1060 // deleting all gives the same result.
1061 if (lyxerr.debugging())
1062 textcache.show(lyxerr, "Expose delete all");
1064 buffer_->resizeInsets(bv_);
1065 } else if (heightChange) {
1066 // Rebuild image of current screen
1068 // fitCursor() ensures we don't jump back
1069 // to the start of the document on vertical
1073 // The main window size has changed, repaint most stuff
1075 } else if (screen_.get())
1076 screen_->redraw(bv_->text, bv_);
1078 // Grey box when we don't have a buffer
1079 workarea_.greyOut();
1082 // always make sure that the scrollbar is sane.
1084 owner_->updateLayoutChoice();
1089 void BufferView::Pimpl::update()
1091 if (screen_.get() &&
1092 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1094 LyXText::text_status st = bv_->text->status();
1095 screen_->update(bv_->text, bv_);
1097 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1098 bv_->text->fullRebreak(bv_);
1099 st = LyXText::NEED_MORE_REFRESH;
1100 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1101 bv_->text->cursor.pos());
1102 if (bv_->text->selection.set()) {
1103 bv_->text->setCursor(bv_, bv_->text->selection.start,
1104 bv_->text->selection.start.par(),
1105 bv_->text->selection.start.pos());
1106 bv_->text->setCursor(bv_, bv_->text->selection.end,
1107 bv_->text->selection.end.par(),
1108 bv_->text->selection.end.pos());
1111 bv_->text->status(bv_, st);
1112 screen_->update(bv_->text, bv_);
1114 // do this here instead of in the screen::update because of
1116 bv_->text->status(bv_, LyXText::UNCHANGED);
1122 // Values used when calling update:
1124 // -2 - update, move sel_cursor if selection, fitcursor
1125 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1126 // 0 - update, move sel_cursor if selection, fitcursor
1127 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1128 // 3 - update, move sel_cursor if selection
1131 // a simple redraw of the parts that need refresh
1133 // move sel_cursor if selection -
1134 // the text's sel_cursor is moved if there is selection is progress
1137 // fitCursor() is called and the scrollbar updated
1140 // the buffer is marked dirty.
1149 // UPDATE_ONLY = UPDATE;
1150 // UPDATE_SELECT = UPDATE | SELECT;
1151 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1152 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1154 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1155 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1156 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1157 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1158 // update(3) -> update(1) -> update(1) -> update(SELECT)
1160 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1162 owner_->updateLayoutChoice();
1164 if (!text->selection.set() && (f & SELECT)) {
1165 text->selection.cursor = text->cursor;
1168 text->fullRebreak(bv_);
1170 if (text->inset_owner) {
1171 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1172 updateInset(text->inset_owner, false);
1182 buffer_->markDirty();
1187 // Callback for cursor timer
1188 void BufferView::Pimpl::cursorToggle()
1191 cursor_timeout.restart();
1195 if (!screen_.get()) {
1196 cursor_timeout.restart();
1201 extern void reapSpellchecker(void);
1204 if (!bv_->theLockingInset()) {
1205 screen_->cursorToggle(bv_);
1207 bv_->theLockingInset()->toggleInsetCursor(bv_);
1210 cursor_timeout.restart();
1214 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1216 if (!text->cursor.row()->previous()) {
1217 if (text->first_y > 0) {
1218 int new_y = bv_->text->first_y - workarea_.height();
1219 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1225 int y = text->first_y;
1226 Row * cursorrow = text->cursor.row();
1228 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1232 if (cursorrow == bv_->text->cursor.row()) {
1233 // we have a row which is higher than the workarea so we leave the
1234 // cursor on the start of the row and move only the draw up as soon
1235 // as we move the cursor or do something while inside the row (it may
1236 // span several workarea-heights) we'll move to the top again, but this
1237 // is better than just jump down and only display part of the row.
1238 new_y = bv_->text->first_y - workarea_.height();
1240 if (text->inset_owner) {
1241 new_y = bv_->text->cursor.iy()
1242 + bv_->theLockingInset()->insetInInsetY() + y
1243 + text->cursor.row()->height()
1244 - workarea_.height() + 1;
1246 new_y = text->cursor.y()
1247 - text->cursor.row()->baseline()
1248 + text->cursor.row()->height()
1249 - workarea_.height() + 1;
1252 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1253 if (text->cursor.row()->previous()) {
1255 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1256 text->cursor.row()->previous()->pos(), false);
1257 if (cur.y() > text->first_y) {
1258 text->cursorUp(bv_, true);
1265 void BufferView::Pimpl::cursorNext(LyXText * text)
1267 if (!text->cursor.row()->next()) {
1268 int y = text->cursor.y() - text->cursor.row()->baseline() +
1269 text->cursor.row()->height();
1270 if (y > int(text->first_y + workarea_.height())) {
1271 screen_->draw(bv_->text, bv_,
1272 bv_->text->first_y + workarea_.height());
1278 int y = text->first_y + workarea_.height();
1279 if (text->inset_owner && !text->first_y) {
1280 y -= (bv_->text->cursor.iy()
1281 - bv_->text->first_y
1282 + bv_->theLockingInset()->insetInInsetY());
1284 text->getRowNearY(y);
1286 Row * cursorrow = text->cursor.row();
1287 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1290 if (cursorrow == bv_->text->cursor.row()) {
1291 // we have a row which is higher than the workarea so we leave the
1292 // cursor on the start of the row and move only the draw down as soon
1293 // as we move the cursor or do something while inside the row (it may
1294 // span several workarea-heights) we'll move to the top again, but this
1295 // is better than just jump down and only display part of the row.
1296 new_y = bv_->text->first_y + workarea_.height();
1298 if (text->inset_owner) {
1299 new_y = bv_->text->cursor.iy()
1300 + bv_->theLockingInset()->insetInInsetY()
1301 + y - text->cursor.row()->baseline();
1303 new_y = text->cursor.y() - text->cursor.row()->baseline();
1306 screen_->draw(bv_->text, bv_, new_y);
1307 if (text->cursor.row()->next()) {
1309 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1310 text->cursor.row()->next()->pos(), false);
1311 if (cur.y() < int(text->first_y + workarea_.height())) {
1312 text->cursorDown(bv_, true);
1319 bool BufferView::Pimpl::available() const
1321 if (buffer_ && bv_->text)
1327 void BufferView::Pimpl::beforeChange(LyXText * text)
1330 text->clearSelection();
1334 void BufferView::Pimpl::savePosition(unsigned int i)
1336 if (i >= saved_positions_num)
1338 saved_positions[i] = Position(buffer_->fileName(),
1339 bv_->text->cursor.par()->id(),
1340 bv_->text->cursor.pos());
1343 str << _("Saved bookmark") << ' ' << i;
1344 owner_->message(str.str().c_str());
1349 void BufferView::Pimpl::restorePosition(unsigned int i)
1351 if (i >= saved_positions_num)
1354 string const fname = saved_positions[i].filename;
1356 beforeChange(bv_->text);
1358 if (fname != buffer_->fileName()) {
1359 Buffer * b = bufferlist.exists(fname) ?
1360 bufferlist.getBuffer(fname) :
1361 bufferlist.loadLyXFile(fname); // don't ask, just load it
1362 if (b != 0) buffer(b);
1365 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1369 bv_->text->setCursor(bv_, par,
1370 min(par->size(), saved_positions[i].par_pos));
1372 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1375 str << _("Moved to bookmark") << ' ' << i;
1376 owner_->message(str.str().c_str());
1381 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1383 if (i >= saved_positions_num)
1386 return !saved_positions[i].filename.empty();
1390 void BufferView::Pimpl::setState()
1392 if (!lyxrc.rtl_support)
1395 LyXText * text = bv_->getLyXText();
1396 if (text->real_current_font.isRightToLeft()
1397 && !(bv_->theLockingInset()
1398 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1400 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1401 owner_->getIntl()->KeyMapSec();
1403 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1404 owner_->getIntl()->KeyMapPrim();
1410 void BufferView::Pimpl::insetSleep()
1412 if (bv_->theLockingInset() && !inset_slept) {
1413 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1414 bv_->theLockingInset()->insetUnlock(bv_);
1420 void BufferView::Pimpl::insetWakeup()
1422 if (bv_->theLockingInset() && inset_slept) {
1423 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1424 inset_slept = false;
1430 void BufferView::Pimpl::insetUnlock()
1432 if (bv_->theLockingInset()) {
1434 bv_->theLockingInset()->insetUnlock(bv_);
1435 bv_->theLockingInset(0);
1437 inset_slept = false;
1442 bool BufferView::Pimpl::focus() const
1444 return workarea_.hasFocus();
1448 void BufferView::Pimpl::focus(bool f)
1450 if (f) workarea_.setFocus();
1454 bool BufferView::Pimpl::active() const
1456 return workarea_.active();
1460 bool BufferView::Pimpl::belowMouse() const
1462 return workarea_.belowMouse();
1466 void BufferView::Pimpl::showCursor()
1468 if (screen_.get()) {
1469 if (bv_->theLockingInset())
1470 bv_->theLockingInset()->showInsetCursor(bv_);
1472 screen_->showCursor(bv_->text, bv_);
1477 void BufferView::Pimpl::hideCursor()
1479 if (screen_.get()) {
1480 if (!bv_->theLockingInset())
1481 // bv_->theLockingInset()->hideInsetCursor(bv_);
1483 screen_->hideCursor();
1488 void BufferView::Pimpl::toggleSelection(bool b)
1490 if (screen_.get()) {
1491 if (bv_->theLockingInset())
1492 bv_->theLockingInset()->toggleSelection(bv_, b);
1493 screen_->toggleSelection(bv_->text, bv_, b);
1498 void BufferView::Pimpl::toggleToggle()
1501 screen_->toggleToggle(bv_->text, bv_);
1505 void BufferView::Pimpl::center()
1507 beforeChange(bv_->text);
1508 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1509 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1511 screen_->draw(bv_->text, bv_, 0);
1513 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1518 void BufferView::Pimpl::pasteClipboard(bool asPara)
1523 screen_->hideCursor();
1524 beforeChange(bv_->text);
1526 string const clip(workarea_.getClipboard());
1532 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1534 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1536 bv_->getLyXText()->clearSelection();
1537 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1541 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1543 workarea_.putClipboard(stuff);
1548 * Dispatch functions for actions which can be valid for BufferView->text
1549 * and/or InsetText->text!!!
1554 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1556 LyXText * lt = bv_->getLyXText();
1558 if (selecting || lt->selection.mark()) {
1559 lt->setSelection(bv_);
1563 updateInset(lt->inset_owner, false);
1567 update(lt, BufferView::SELECT|BufferView::FITCUR);
1569 update(lt, BufferView::SELECT);
1571 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1572 bv_->theLockingInset()->hideInsetCursor(bv_);
1573 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1577 if (!lt->selection.set())
1578 workarea_.haveSelection(false);
1580 /* ---> Everytime the cursor is moved, show the current font state. */
1581 // should this too me moved out of this func?
1582 //owner->showState();
1587 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1589 LyXCursor cursor = bv_->getLyXText()->cursor;
1590 Buffer::inset_iterator it =
1591 find_if(Buffer::inset_iterator(
1592 cursor.par(), cursor.pos()),
1593 buffer_->inset_iterator_end(),
1594 lyx::compare_memfun(&Inset::lyxCode, code));
1595 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1599 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1601 string filename = filen;
1603 if (filename.empty()) {
1604 // Launch a file browser
1605 string initpath = lyxrc.document_path;
1608 string const trypath = owner_->buffer()->filePath();
1609 // If directory is writeable, use this as default.
1610 if (IsDirWriteable(trypath))
1614 FileDialog fileDlg(bv_->owner(),
1615 _("Select LyX document to insert"),
1617 make_pair(string(_("Documents|#o#O")),
1618 string(lyxrc.document_path)),
1619 make_pair(string(_("Examples|#E#e")),
1620 string(AddPath(system_lyxdir, "examples"))));
1622 FileDialog::Result result =
1623 fileDlg.Select(initpath,
1624 _("*.lyx| LyX Documents (*.lyx)"));
1626 if (result.first == FileDialog::Later)
1629 filename = result.second;
1631 // check selected filename
1632 if (filename.empty()) {
1633 owner_->message(_("Canceled."));
1638 // get absolute path of file and add ".lyx" to the filename if
1640 filename = FileSearch(string(), filename, "lyx");
1642 string const disp_fn(MakeDisplayPath(filename));
1645 s1 << _("Inserting document") << ' '
1646 << disp_fn << " ...";
1647 owner_->message(s1.str().c_str());
1648 bool const res = bv_->insertLyXFile(filename);
1651 str << _("Document") << ' ' << disp_fn
1652 << ' ' << _("inserted.");
1653 owner_->message(str.str().c_str());
1656 str << _("Could not insert document") << ' '
1658 owner_->message(str.str().c_str());
1663 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1665 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1666 << action <<"] arg[" << argument << "]" << endl;
1668 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1671 // --- Misc -------------------------------------------
1675 LyXText * lt = bv_->getLyXText();
1676 lt->toggleAppendix(bv_);
1679 | BufferView::FITCUR
1680 | BufferView::CHANGE);
1685 case LFUN_TOC_INSERT:
1687 InsetCommandParams p;
1688 p.setCmdName("tableofcontents");
1689 Inset * inset = new InsetTOC(p);
1690 if (!insertInset(inset, tclass.defaultLayoutName()))
1695 case LFUN_SCROLL_INSET:
1696 // this is not handled here as this funktion is only aktive
1697 // if we have a locking_inset and that one is (or contains)
1701 case LFUN_INSET_GRAPHICS:
1703 Inset * new_inset = new InsetGraphics;
1704 if (!insertInset(new_inset)) {
1707 // this is need because you don't use a inset->Edit()
1708 updateInset(new_inset, true);
1709 new_inset->edit(bv_);
1719 case LFUN_PASTESELECTION:
1721 bool asPara = false;
1722 if (argument == "paragraph")
1724 pasteClipboard(asPara);
1736 case LFUN_LAYOUT_COPY:
1737 bv_->copyEnvironment();
1740 case LFUN_LAYOUT_PASTE:
1741 bv_->pasteEnvironment();
1745 case LFUN_GOTOERROR:
1746 gotoInset(Inset::ERROR_CODE, false);
1750 gotoInset(Inset::IGNORE_CODE, false);
1753 case LFUN_REFERENCE_GOTO:
1755 vector<Inset::Code> tmp;
1756 tmp.push_back(Inset::LABEL_CODE);
1757 tmp.push_back(Inset::REF_CODE);
1758 gotoInset(tmp, true);
1762 case LFUN_HYPHENATION:
1763 specialChar(InsetSpecialChar::HYPHENATION);
1766 case LFUN_LIGATURE_BREAK:
1767 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1771 specialChar(InsetSpecialChar::LDOTS);
1774 case LFUN_END_OF_SENTENCE:
1775 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1778 case LFUN_MENU_SEPARATOR:
1779 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1786 case LFUN_DEPTH_MIN:
1787 changeDepth(bv_, bv_->getLyXText(), -1);
1790 case LFUN_DEPTH_PLUS:
1791 changeDepth(bv_, bv_->getLyXText(), 1);
1795 owner_->getDialogs()->setUserFreeFont();
1798 case LFUN_FILE_INSERT:
1799 MenuInsertLyXFile(argument);
1802 case LFUN_FILE_INSERT_ASCII_PARA:
1803 InsertAsciiFile(bv_, argument, true);
1806 case LFUN_FILE_INSERT_ASCII:
1807 InsertAsciiFile(bv_, argument, false);
1812 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1813 << argument << endl;
1815 // This is not the good solution to the empty argument
1816 // problem, but it will hopefully suffice for 1.2.0.
1817 // The correct solution would be to augument the
1818 // function list/array with information about what
1819 // functions needs arguments and their type.
1820 if (argument.empty()) {
1821 owner_->getLyXFunc()->setErrorMessage(
1822 _("LyX function 'layout' needs an argument."));
1826 // Derive layout number from given argument (string)
1827 // and current buffer's textclass (number). */
1828 bool hasLayout = tclass.hasLayout(argument);
1829 string layout = argument;
1831 // If the entry is obsolete, use the new one instead.
1833 string const & obs = tclass[layout].obsoleted_by();
1839 owner_->getLyXFunc()->setErrorMessage(
1840 string(N_("Layout ")) + argument +
1845 bool change_layout = (current_layout != layout);
1846 LyXText * lt = bv_->getLyXText();
1847 if (!change_layout && lt->selection.set() &&
1848 lt->selection.start.par() != lt->selection.end.par())
1850 Paragraph * spar = lt->selection.start.par();
1851 Paragraph * epar = lt->selection.end.par()->next();
1852 while(spar != epar) {
1853 if (spar->layout() != current_layout) {
1854 change_layout = true;
1859 if (change_layout) {
1861 current_layout = layout;
1864 | BufferView::FITCUR);
1865 lt->setLayout(bv_, layout);
1866 owner_->setLayout(layout);
1869 | BufferView::FITCUR
1870 | BufferView::CHANGE);
1877 lang(bv_, argument);
1879 owner_->showState();
1884 owner_->showState();
1889 owner_->showState();
1894 owner_->showState();
1899 owner_->showState();
1904 owner_->showState();
1909 owner_->showState();
1914 owner_->showState();
1917 case LFUN_UNDERLINE:
1919 owner_->showState();
1922 case LFUN_FONT_SIZE:
1923 fontSize(bv_, argument);
1924 owner_->showState();
1927 case LFUN_FONT_STATE:
1928 owner_->getLyXFunc()->setMessage(currentState(bv_));
1931 case LFUN_UPCASE_WORD:
1933 LyXText * lt = bv_->getLyXText();
1937 | BufferView::FITCUR);
1938 lt->changeCase(bv_, LyXText::text_uppercase);
1939 if (lt->inset_owner)
1940 updateInset(lt->inset_owner, true);
1943 | BufferView::FITCUR
1944 | BufferView::CHANGE);
1948 case LFUN_LOWCASE_WORD:
1950 LyXText * lt = bv_->getLyXText();
1952 update(lt, BufferView::SELECT|BufferView::FITCUR);
1953 lt->changeCase(bv_, LyXText::text_lowercase);
1954 if (lt->inset_owner)
1955 updateInset(lt->inset_owner, true);
1958 | BufferView::FITCUR
1959 | BufferView::CHANGE);
1963 case LFUN_CAPITALIZE_WORD:
1965 LyXText * lt = bv_->getLyXText();
1967 update(lt, BufferView::SELECT|BufferView::FITCUR);
1968 lt->changeCase(bv_, LyXText::text_capitalization);
1969 if (lt->inset_owner)
1970 updateInset(lt->inset_owner, true);
1973 | BufferView::FITCUR
1974 | BufferView::CHANGE);
1978 case LFUN_TRANSPOSE_CHARS:
1980 LyXText * lt = bv_->getLyXText();
1982 update(lt, BufferView::SELECT|BufferView::FITCUR);
1983 lt->transposeChars(*bv_);
1984 if (lt->inset_owner)
1985 updateInset(lt->inset_owner, true);
1988 | BufferView::FITCUR
1989 | BufferView::CHANGE);
1994 case LFUN_INSERT_LABEL:
1995 MenuInsertLabel(bv_, argument);
1998 case LFUN_REF_INSERT:
1999 if (argument.empty()) {
2000 InsetCommandParams p("ref");
2001 owner_->getDialogs()->createRef(p.getAsString());
2003 InsetCommandParams p;
2004 p.setFromString(argument);
2006 InsetRef * inset = new InsetRef(p, *buffer_);
2007 if (!insertInset(inset))
2010 updateInset(inset, true);
2014 case LFUN_BOOKMARK_SAVE:
2015 savePosition(strToUnsignedInt(argument));
2018 case LFUN_BOOKMARK_GOTO:
2019 restorePosition(strToUnsignedInt(argument));
2024 string label(argument);
2025 if (label.empty()) {
2027 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
2029 label = inset->getContents();
2034 if (!label.empty()) {
2035 //bv_->savePosition(0);
2036 if (!bv_->gotoLabel(label))
2037 Alert::alert(_("Error"),
2038 _("Couldn't find this label"),
2039 _("in current document."));
2044 // --- Cursor Movements -----------------------------
2047 LyXText * lt = bv_->getLyXText();
2049 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2050 if (!lt->selection.mark())
2052 update(lt, BufferView::SELECT|BufferView::FITCUR);
2054 lt->cursorLeft(bv_, false);
2055 if (lt->cursor.pos() < lt->cursor.par()->size()
2056 && lt->cursor.par()->isInset(lt->cursor.pos())
2057 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2058 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2059 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2061 tmpinset->edit(bv_, false);
2063 tmpinset->edit(bv_);
2067 lt->cursorRight(bv_, false);
2069 moveCursorUpdate(false);
2070 owner_->showState();
2076 // This is soooo ugly. Isn`t it possible to make
2077 // it simpler? (Lgb)
2078 LyXText * lt = bv_->getLyXText();
2079 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2080 if (!lt->selection.mark())
2082 update(lt, BufferView::SELECT|BufferView::FITCUR);
2083 LyXCursor const cur = lt->cursor;
2085 lt->cursorLeft(bv_, false);
2086 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2087 lt->cursor.pos() < lt->cursor.par()->size() &&
2088 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2089 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2090 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2091 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2093 tmpinset->edit(bv_);
2095 tmpinset->edit(bv_, false);
2099 lt->cursorRight(bv_, false);
2102 moveCursorUpdate(false);
2103 owner_->showState();
2109 LyXText * lt = bv_->getLyXText();
2111 if (!lt->selection.mark())
2113 update(lt, BufferView::UPDATE);
2116 moveCursorUpdate(false);
2117 owner_->showState();
2123 LyXText * lt = bv_->getLyXText();
2125 if (!lt->selection.mark())
2127 update(lt, BufferView::UPDATE);
2128 lt->cursorDown(bv_);
2130 moveCursorUpdate(false);
2131 owner_->showState();
2135 case LFUN_UP_PARAGRAPH:
2137 LyXText * lt = bv_->getLyXText();
2139 if (!lt->selection.mark())
2141 update(lt, BufferView::UPDATE);
2142 lt->cursorUpParagraph(bv_);
2144 moveCursorUpdate(false);
2145 owner_->showState();
2149 case LFUN_DOWN_PARAGRAPH:
2151 LyXText * lt = bv_->getLyXText();
2153 if (!lt->selection.mark())
2155 update(lt, BufferView::UPDATE);
2156 lt->cursorDownParagraph(bv_);
2158 moveCursorUpdate(false);
2159 owner_->showState();
2165 LyXText * lt = bv_->getLyXText();
2167 if (!lt->selection.mark())
2169 update(lt, BufferView::UPDATE);
2172 moveCursorUpdate(false, false);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2181 if (!lt->selection.mark())
2183 update(lt, BufferView::UPDATE);
2186 moveCursorUpdate(false, false);
2187 owner_->showState();
2193 LyXText * lt = bv_->getLyXText();
2195 if (!lt->selection.mark())
2197 update(lt, BufferView::SELECT|BufferView::FITCUR);
2198 lt->cursorHome(bv_);
2200 moveCursorUpdate(false);
2201 owner_->showState();
2207 LyXText * lt = bv_->getLyXText();
2209 if (!lt->selection.mark())
2212 BufferView::SELECT|BufferView::FITCUR);
2215 moveCursorUpdate(false);
2216 owner_->showState();
2220 case LFUN_SHIFT_TAB:
2223 LyXText * lt = bv_->getLyXText();
2225 if (!lt->selection.mark())
2228 BufferView::SELECT|BufferView::FITCUR);
2231 moveCursorUpdate(false);
2232 owner_->showState();
2236 case LFUN_WORDRIGHT:
2238 LyXText * lt = bv_->getLyXText();
2240 if (!lt->selection.mark())
2242 update(lt, BufferView::SELECT|BufferView::FITCUR);
2243 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2244 lt->cursorLeftOneWord(bv_);
2246 lt->cursorRightOneWord(bv_);
2248 moveCursorUpdate(false);
2249 owner_->showState();
2255 LyXText * lt = bv_->getLyXText();
2257 if (!lt->selection.mark())
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2260 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2261 lt->cursorRightOneWord(bv_);
2263 lt->cursorLeftOneWord(bv_);
2265 moveCursorUpdate(false);
2266 owner_->showState();
2270 case LFUN_BEGINNINGBUF:
2272 LyXText * lt = bv_->getLyXText();
2274 if (!lt->selection.mark())
2277 BufferView::SELECT|BufferView::FITCUR);
2280 moveCursorUpdate(false);
2281 owner_->showState();
2287 LyXText * lt = bv_->getLyXText();
2289 if (!lt->selection.mark())
2292 BufferView::SELECT|BufferView::FITCUR);
2293 lt->cursorBottom(bv_);
2295 moveCursorUpdate(false);
2296 owner_->showState();
2300 /* cursor selection ---------------------------- */
2303 LyXText * lt = bv_->getLyXText();
2306 BufferView::SELECT|BufferView::FITCUR);
2307 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2308 lt->cursorLeft(bv_);
2310 lt->cursorRight(bv_);
2312 moveCursorUpdate(true);
2313 owner_->showState();
2319 LyXText * lt = bv_->getLyXText();
2322 BufferView::SELECT|BufferView::FITCUR);
2323 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2324 lt->cursorRight(bv_);
2326 lt->cursorLeft(bv_);
2328 moveCursorUpdate(true);
2329 owner_->showState();
2335 LyXText * lt = bv_->getLyXText();
2338 BufferView::SELECT|BufferView::FITCUR);
2339 lt->cursorUp(bv_, true);
2341 moveCursorUpdate(true);
2342 owner_->showState();
2348 LyXText * lt = bv_->getLyXText();
2351 BufferView::SELECT|BufferView::FITCUR);
2352 lt->cursorDown(bv_, true);
2354 moveCursorUpdate(true);
2355 owner_->showState();
2359 case LFUN_UP_PARAGRAPHSEL:
2361 LyXText * lt = bv_->getLyXText();
2364 BufferView::SELECT|BufferView::FITCUR);
2365 lt->cursorUpParagraph(bv_);
2367 moveCursorUpdate(true);
2368 owner_->showState();
2372 case LFUN_DOWN_PARAGRAPHSEL:
2374 LyXText * lt = bv_->getLyXText();
2377 BufferView::SELECT|BufferView::FITCUR);
2378 lt->cursorDownParagraph(bv_);
2380 moveCursorUpdate(true);
2381 owner_->showState();
2387 LyXText * lt = bv_->getLyXText();
2389 update(lt, BufferView::SELECT|BufferView::FITCUR);
2392 moveCursorUpdate(true);
2393 owner_->showState();
2399 LyXText * lt = bv_->getLyXText();
2401 update(lt, BufferView::SELECT|BufferView::FITCUR);
2404 moveCursorUpdate(true);
2405 owner_->showState();
2411 LyXText * lt = bv_->getLyXText();
2413 update(lt, BufferView::SELECT|BufferView::FITCUR);
2414 lt->cursorHome(bv_);
2416 moveCursorUpdate(true);
2417 owner_->showState();
2423 LyXText * lt = bv_->getLyXText();
2425 update(lt, BufferView::SELECT|BufferView::FITCUR);
2428 moveCursorUpdate(true);
2429 owner_->showState();
2433 case LFUN_WORDRIGHTSEL:
2435 LyXText * lt = bv_->getLyXText();
2437 update(lt, BufferView::SELECT|BufferView::FITCUR);
2438 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2439 lt->cursorLeftOneWord(bv_);
2441 lt->cursorRightOneWord(bv_);
2443 moveCursorUpdate(true);
2444 owner_->showState();
2448 case LFUN_WORDLEFTSEL:
2450 LyXText * lt = bv_->getLyXText();
2452 update(lt, BufferView::SELECT|BufferView::FITCUR);
2453 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2454 lt->cursorRightOneWord(bv_);
2456 lt->cursorLeftOneWord(bv_);
2458 moveCursorUpdate(true);
2459 owner_->showState();
2463 case LFUN_BEGINNINGBUFSEL:
2465 LyXText * lt = bv_->getLyXText();
2467 if (lt->inset_owner)
2469 update(lt, BufferView::SELECT|BufferView::FITCUR);
2472 moveCursorUpdate(true);
2473 owner_->showState();
2477 case LFUN_ENDBUFSEL:
2479 LyXText * lt = bv_->getLyXText();
2481 if (lt->inset_owner)
2484 BufferView::SELECT|BufferView::FITCUR);
2485 lt->cursorBottom(bv_);
2487 moveCursorUpdate(true);
2488 owner_->showState();
2492 // --- text changing commands ------------------------
2493 case LFUN_BREAKLINE:
2495 LyXText * lt = bv_->getLyXText();
2498 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2501 | BufferView::FITCUR
2502 | BufferView::CHANGE);
2503 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2504 moveCursorUpdate(false);
2508 case LFUN_PROTECTEDSPACE:
2510 LyXText * lt = bv_->getLyXText();
2512 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2514 if (style.free_spacing) {
2515 lt->insertChar(bv_, ' ');
2518 | BufferView::FITCUR
2519 | BufferView::CHANGE);
2521 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2523 moveCursorUpdate(false);
2529 LyXText * lt = bv_->getLyXText();
2531 if (lt->selection.mark()) {
2535 | BufferView::FITCUR);
2536 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2539 lt->selection.mark(true);
2542 | BufferView::FITCUR);
2543 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2545 lt->selection.cursor = lt->cursor;
2551 LyXText * lt = bv_->getLyXText();
2553 if (!lt->selection.set()) {
2555 lt->selection.cursor = lt->cursor;
2558 | BufferView::FITCUR
2559 | BufferView::CHANGE);
2560 // It is possible to make it a lot faster still
2561 // just comment out the line below...
2566 moveCursorUpdate(false);
2567 owner_->showState();
2572 case LFUN_DELETE_SKIP:
2574 LyXText * lt = bv_->getLyXText();
2576 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2578 LyXCursor cursor = lt->cursor;
2580 if (!lt->selection.set()) {
2581 if (cursor.pos() == cursor.par()->size()) {
2582 lt->cursorRight(bv_);
2583 cursor = lt->cursor;
2584 if (cursor.pos() == 0
2585 && !(cursor.par()->params().spaceTop()
2586 == VSpace (VSpace::NONE))) {
2589 cursor.par()->params().lineTop(),
2590 cursor.par()->params().lineBottom(),
2591 cursor.par()->params().pagebreakTop(),
2592 cursor.par()->params().pagebreakBottom(),
2593 VSpace(VSpace::NONE),
2594 cursor.par()->params().spaceBottom(),
2595 cursor.par()->params().spacing(),
2596 cursor.par()->params().align(),
2597 cursor.par()->params().labelWidthString(), 0);
2598 lt->cursorLeft(bv_);
2601 | BufferView::FITCUR
2602 | BufferView::CHANGE);
2604 lt->cursorLeft(bv_);
2606 lt->selection.cursor = lt->cursor;
2609 | BufferView::FITCUR
2610 | BufferView::CHANGE);
2614 lt->selection.cursor = lt->cursor;
2617 | BufferView::FITCUR
2618 | BufferView::CHANGE);
2626 /* -------> Delete word forward. */
2627 case LFUN_DELETE_WORD_FORWARD:
2628 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2629 bv_->getLyXText()->deleteWordForward(bv_);
2630 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2631 moveCursorUpdate(false);
2632 owner_->showState();
2635 /* -------> Delete word backward. */
2636 case LFUN_DELETE_WORD_BACKWARD:
2638 LyXText * lt = bv_->getLyXText();
2640 update(lt, BufferView::SELECT|BufferView::FITCUR);
2641 lt->deleteWordBackward(bv_);
2644 | BufferView::FITCUR
2645 | BufferView::CHANGE);
2646 moveCursorUpdate(false);
2647 owner_->showState();
2651 /* -------> Kill to end of line. */
2652 case LFUN_DELETE_LINE_FORWARD:
2654 LyXText * lt = bv_->getLyXText();
2656 update(lt, BufferView::SELECT|BufferView::FITCUR);
2657 lt->deleteLineForward(bv_);
2660 | BufferView::FITCUR
2661 | BufferView::CHANGE);
2662 moveCursorUpdate(false);
2666 /* -------> Set mark off. */
2669 LyXText * lt = bv_->getLyXText();
2672 update(lt, BufferView::SELECT|BufferView::FITCUR);
2673 lt->selection.cursor = lt->cursor;
2674 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2678 /* -------> Set mark on. */
2681 LyXText * lt = bv_->getLyXText();
2684 lt->selection.mark(true);
2685 update(lt, BufferView::SELECT|BufferView::FITCUR);
2686 lt->selection.cursor = lt->cursor;
2687 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2691 case LFUN_BACKSPACE:
2693 LyXText * lt = bv_->getLyXText();
2695 if (!lt->selection.set()) {
2696 if (owner_->getIntl()->getTrans().backspace()) {
2698 lt->selection.cursor = lt->cursor;
2701 | BufferView::FITCUR
2702 | BufferView::CHANGE);
2703 // It is possible to make it a lot faster still
2704 // just comment out the line below...
2710 owner_->showState();
2715 case LFUN_BACKSPACE_SKIP:
2717 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2718 LyXText * lt = bv_->getLyXText();
2720 LyXCursor cursor = lt->cursor;
2722 if (!lt->selection.set()) {
2723 if (cursor.pos() == 0
2724 && !(cursor.par()->params().spaceTop()
2725 == VSpace (VSpace::NONE))) {
2728 cursor.par()->params().lineTop(),
2729 cursor.par()->params().lineBottom(),
2730 cursor.par()->params().pagebreakTop(),
2731 cursor.par()->params().pagebreakBottom(),
2732 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2733 cursor.par()->params().spacing(),
2734 cursor.par()->params().align(),
2735 cursor.par()->params().labelWidthString(), 0);
2738 | BufferView::FITCUR
2739 | BufferView::CHANGE);
2742 lt->selection.cursor = cursor;
2745 | BufferView::FITCUR
2746 | BufferView::CHANGE);
2753 case LFUN_BREAKPARAGRAPH:
2755 LyXText * lt = bv_->getLyXText();
2758 lt->breakParagraph(bv_, 0);
2761 | BufferView::FITCUR
2762 | BufferView::CHANGE);
2763 lt->selection.cursor = lt->cursor;
2765 owner_->showState();
2769 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2771 LyXText * lt = bv_->getLyXText();
2774 lt->breakParagraph(bv_, 1);
2777 | BufferView::FITCUR
2778 | BufferView::CHANGE);
2779 lt->selection.cursor = lt->cursor;
2781 owner_->showState();
2785 case LFUN_BREAKPARAGRAPH_SKIP:
2787 // When at the beginning of a paragraph, remove
2788 // indentation and add a "defskip" at the top.
2789 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2790 LyXText * lt = bv_->getLyXText();
2792 LyXCursor cursor = lt->cursor;
2795 if (cursor.pos() == 0) {
2796 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2799 cursor.par()->params().lineTop(),
2800 cursor.par()->params().lineBottom(),
2801 cursor.par()->params().pagebreakTop(),
2802 cursor.par()->params().pagebreakBottom(),
2803 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2804 cursor.par()->params().spacing(),
2805 cursor.par()->params().align(),
2806 cursor.par()->params().labelWidthString(), 1);
2807 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2811 lt->breakParagraph(bv_, 0);
2812 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2817 | BufferView::FITCUR
2818 | BufferView::CHANGE);
2819 lt->selection.cursor = cursor;
2821 owner_->showState();
2825 case LFUN_PARAGRAPH_SPACING:
2827 LyXText * lt = bv_->getLyXText();
2829 Paragraph * par = lt->cursor.par();
2830 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2831 float cur_value = 1.0;
2832 if (cur_spacing == Spacing::Other) {
2833 cur_value = par->params().spacing().getValue();
2836 istringstream istr(argument.c_str());
2840 Spacing::Space new_spacing = cur_spacing;
2841 float new_value = cur_value;
2843 lyxerr << "Missing argument to `paragraph-spacing'"
2845 } else if (tmp == "single") {
2846 new_spacing = Spacing::Single;
2847 } else if (tmp == "onehalf") {
2848 new_spacing = Spacing::Onehalf;
2849 } else if (tmp == "double") {
2850 new_spacing = Spacing::Double;
2851 } else if (tmp == "other") {
2852 new_spacing = Spacing::Other;
2855 lyxerr << "new_value = " << tmpval << endl;
2858 } else if (tmp == "default") {
2859 new_spacing = Spacing::Default;
2861 lyxerr << _("Unknown spacing argument: ")
2862 << argument << endl;
2864 if (cur_spacing != new_spacing || cur_value != new_value) {
2865 par->params().spacing(Spacing(new_spacing, new_value));
2866 lt->redoParagraph(bv_);
2869 | BufferView::FITCUR
2870 | BufferView::CHANGE);
2875 case LFUN_INSET_TOGGLE:
2877 LyXText * lt = bv_->getLyXText();
2880 update(lt, BufferView::SELECT|BufferView::FITCUR);
2881 lt->toggleInset(bv_);
2882 update(lt, BufferView::SELECT|BufferView::FITCUR);
2894 InsetCommandParams p;
2895 if (action == LFUN_HTMLURL)
2896 p.setCmdName("htmlurl");
2898 p.setCmdName("url");
2899 owner_->getDialogs()->createUrl(p.getAsString());
2903 case LFUN_INSERT_URL:
2905 InsetCommandParams p;
2906 p.setFromString(argument);
2908 InsetUrl * inset = new InsetUrl(p);
2909 if (!insertInset(inset))
2912 updateInset(inset, true);
2916 case LFUN_INSET_ERT:
2917 insertAndEditInset(new InsetERT(buffer_->params));
2920 case LFUN_INSET_EXTERNAL:
2921 insertAndEditInset(new InsetExternal);
2924 case LFUN_INSET_FOOTNOTE:
2925 insertAndEditInset(new InsetFoot(buffer_->params));
2928 case LFUN_INSET_MARGINAL:
2929 insertAndEditInset(new InsetMarginal(buffer_->params));
2932 case LFUN_INSET_MINIPAGE:
2933 insertAndEditInset(new InsetMinipage(buffer_->params));
2936 case LFUN_INSERT_NOTE:
2937 insertAndEditInset(new InsetNote(buffer_->params));
2940 case LFUN_INSET_FLOAT:
2941 // check if the float type exist
2942 if (floatList.typeExist(argument)) {
2943 insertAndEditInset(new InsetFloat(buffer_->params,
2946 lyxerr << "Non-existent float type: "
2947 << argument << endl;
2951 case LFUN_INSET_WIDE_FLOAT:
2952 // check if the float type exist
2953 if (floatList.typeExist(argument)) {
2954 InsetFloat * new_inset =
2955 new InsetFloat(buffer_->params, argument);
2956 new_inset->wide(true);
2957 insertAndEditInset(new_inset);
2959 lyxerr << "Non-existent float type: "
2960 << argument << endl;
2965 case LFUN_INSET_LIST:
2966 insertAndEditInset(new InsetList);
2969 case LFUN_INSET_THEOREM:
2970 insertAndEditInset(new InsetTheorem);
2974 case LFUN_INSET_CAPTION:
2976 // Do we have a locking inset...
2977 if (bv_->theLockingInset()) {
2978 lyxerr << "Locking inset code: "
2979 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2980 InsetCaption * new_inset =
2981 new InsetCaption(buffer_->params);
2982 new_inset->setOwner(bv_->theLockingInset());
2983 new_inset->setAutoBreakRows(true);
2984 new_inset->setDrawFrame(0, InsetText::LOCKED);
2985 new_inset->setFrameColor(0, LColor::captionframe);
2986 if (insertInset(new_inset))
2987 new_inset->edit(bv_);
2994 case LFUN_INSET_TABULAR:
2998 if (!argument.empty())
2999 ::sscanf(argument.c_str(),"%d%d", &r, &c);
3000 InsetTabular * new_inset =
3001 new InsetTabular(*buffer_, r, c);
3003 bv_->getLyXText()->real_current_font.isRightToLeft();
3004 if (!open_new_inset(new_inset, rtl))
3009 // --- lyxserver commands ----------------------------
3011 case LFUN_CHARATCURSOR:
3013 pos_type pos = bv_->getLyXText()->cursor.pos();
3014 if (pos < bv_->getLyXText()->cursor.par()->size())
3015 owner_->getLyXFunc()->setMessage(
3016 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
3018 owner_->getLyXFunc()->setMessage("EOF");
3023 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
3025 + tostr(bv_->getLyXText()->cursor.y()));
3032 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
3033 lyxerr << "SETXY: Could not parse coordinates in '"
3034 << argument << std::endl;
3036 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
3040 case LFUN_GETLAYOUT:
3041 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3046 LyXFont & font = bv_->getLyXText()->current_font;
3047 if (font.shape() == LyXFont::ITALIC_SHAPE)
3048 owner_->getLyXFunc()->setMessage("E");
3049 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3050 owner_->getLyXFunc()->setMessage("N");
3052 owner_->getLyXFunc()->setMessage("0");
3057 // --- accented characters ---------------------------
3060 case LFUN_CIRCUMFLEX:
3070 case LFUN_SPECIAL_CARON:
3073 case LFUN_HUNG_UMLAUT:
3076 if (argument.empty()) {
3078 owner_->getLyXFunc()->handleKeyFunc(action);
3080 owner_->getLyXFunc()->handleKeyFunc(action);
3081 owner_->getIntl()->getTrans()
3082 .TranslateAndInsert(argument[0], bv_->getLyXText());
3083 update(bv_->getLyXText(),
3085 | BufferView::FITCUR
3086 | BufferView::CHANGE);
3090 case LFUN_MATH_MACRO:
3091 mathDispatchMathMacro(bv_, argument);
3094 case LFUN_MATH_DELIM:
3095 mathDispatchMathDelim(bv_, argument);
3098 case LFUN_INSERT_MATRIX:
3099 mathDispatchInsertMatrix(bv_, argument);
3102 case LFUN_INSERT_MATH:
3103 mathDispatchInsertMath(bv_, argument);
3106 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3107 mathDispatchMathImportSelection(bv_, argument);
3110 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3111 mathDispatchMathDisplay(bv_, argument);
3114 case LFUN_MATH_MODE: // Open or create an inlined math inset
3115 mathDispatchMathMode(bv_, argument);
3118 case LFUN_GREEK: // Insert a single greek letter
3119 mathDispatchGreek(bv_, argument);
3122 case LFUN_CITATION_INSERT:
3124 InsetCommandParams p;
3125 p.setFromString(argument);
3127 InsetCitation * inset = new InsetCitation(p);
3128 if (!insertInset(inset))
3131 updateInset(inset, true);
3135 case LFUN_INSERT_BIBTEX:
3137 // ale970405+lasgoutt970425
3138 // The argument can be up to two tokens separated
3139 // by a space. The first one is the bibstyle.
3140 string const db = token(argument, ' ', 0);
3141 string const bibstyle = token(argument, ' ', 1);
3143 InsetCommandParams p("BibTeX", db, bibstyle);
3144 InsetBibtex * inset = new InsetBibtex(p);
3146 if (insertInset(inset)) {
3147 if (argument.empty())
3154 // BibTeX data bases
3155 case LFUN_BIBDB_ADD:
3157 InsetBibtex * inset =
3158 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3160 inset->addDatabase(argument);
3165 case LFUN_BIBDB_DEL:
3167 InsetBibtex * inset =
3168 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3170 inset->delDatabase(argument);
3175 case LFUN_BIBTEX_STYLE:
3177 InsetBibtex * inset =
3178 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3180 inset->setOptions(argument);
3185 case LFUN_INDEX_CREATE:
3187 InsetCommandParams p("index");
3188 if (argument.empty()) {
3189 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3190 p.setContents(idxstring);
3192 p.setContents(argument);
3195 owner_->getDialogs()->createIndex(p.getAsString());
3199 case LFUN_INDEX_INSERT:
3201 InsetCommandParams p;
3202 p.setFromString(argument);
3203 InsetIndex * inset = new InsetIndex(p);
3205 if (!insertInset(inset))
3208 updateInset(inset, true);
3212 case LFUN_INDEX_INSERT_LAST:
3214 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3215 if (!idxstring.empty()) {
3216 owner_->message(_("Word `")
3217 + idxstring + _(("' indexed.")));
3218 InsetCommandParams p("index", idxstring);
3219 InsetIndex * inset = new InsetIndex(p);
3221 if (!insertInset(inset))
3224 updateInset(inset, true);
3229 case LFUN_INDEX_PRINT:
3231 InsetCommandParams p("printindex");
3232 Inset * inset = new InsetPrintIndex(p);
3233 if (!insertInset(inset, tclass.defaultLayoutName()))
3238 case LFUN_PARENTINSERT:
3240 InsetCommandParams p("lyxparent", argument);
3241 Inset * inset = new InsetParent(p, *buffer_);
3242 if (!insertInset(inset, tclass.defaultLayoutName()))
3248 case LFUN_CHILD_INSERT:
3250 InsetInclude::Params p;
3251 p.cparams.setFromString(argument);
3252 p.masterFilename_ = buffer_->fileName();
3254 InsetInclude * inset = new InsetInclude(p);
3255 if (!insertInset(inset))
3258 updateInset(inset, true);
3259 bv_->owner()->getDialogs()->showInclude(inset);
3264 case LFUN_FLOAT_LIST:
3265 if (floatList.typeExist(argument)) {
3266 Inset * inset = new InsetFloatList(argument);
3267 if (!insertInset(inset, tclass.defaultLayoutName()))
3270 lyxerr << "Non-existent float type: "
3271 << argument << endl;
3275 case LFUN_THESAURUS_ENTRY:
3277 string arg = argument;
3280 arg = bv_->getLyXText()->selectionAsString(buffer_,
3284 if (arg.size() > 100 || arg.empty()) {
3285 // Get word or selection
3286 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3287 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3288 // FIXME: where is getLyXText()->unselect(bv_) ?
3292 bv_->owner()->getDialogs()->showThesaurus(arg);
3296 case LFUN_SELFINSERT:
3298 if (argument.empty()) break;
3300 /* Automatically delete the currently selected
3301 * text and replace it with what is being
3302 * typed in now. Depends on lyxrc settings
3303 * "auto_region_delete", which defaults to
3306 LyXText * lt = bv_->getLyXText();
3308 if (lyxrc.auto_region_delete) {
3309 if (lt->selection.set()) {
3310 lt->cutSelection(bv_, false, false);
3313 | BufferView::FITCUR
3314 | BufferView::CHANGE);
3316 workarea_.haveSelection(false);
3320 LyXFont const old_font(lt->real_current_font);
3322 string::const_iterator cit = argument.begin();
3323 string::const_iterator end = argument.end();
3324 for (; cit != end; ++cit) {
3325 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3330 | BufferView::FITCUR
3331 | BufferView::CHANGE);
3333 lt->selection.cursor = lt->cursor;
3334 moveCursorUpdate(false);
3336 // real_current_font.number can change so we need to
3337 // update the minibuffer
3338 if (old_font != lt->real_current_font)
3339 owner_->showState();
3344 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3346 time_t now_time_t = time(NULL);
3347 struct tm * now_tm = localtime(&now_time_t);
3348 setlocale(LC_TIME, "");
3350 if (!argument.empty())
3353 arg = lyxrc.date_insert_format;
3355 int const datetmp_len =
3356 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3358 LyXText * lt = bv_->getLyXText();
3360 for (int i = 0; i < datetmp_len; i++) {
3361 lt->insertChar(bv_, datetmp[i]);
3364 | BufferView::FITCUR
3365 | BufferView::CHANGE);
3368 lt->selection.cursor = lt->cursor;
3369 moveCursorUpdate(false);
3373 case LFUN_UNKNOWN_ACTION:
3374 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3385 void BufferView::Pimpl::newline()
3388 LyXText * lt = bv_->getLyXText();
3392 | BufferView::FITCUR);
3393 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3396 | BufferView::FITCUR
3397 | BufferView::CHANGE);
3402 void BufferView::Pimpl::hfill()
3405 LyXText * lt = bv_->getLyXText();
3409 | BufferView::FITCUR);
3410 lt->insertChar(bv_, Paragraph::META_HFILL);
3413 | BufferView::FITCUR
3414 | BufferView::CHANGE);
3419 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3422 LyXText * lt = bv_->getLyXText();
3425 update(lt, BufferView::SELECT|BufferView::FITCUR);
3426 InsetSpecialChar * new_inset =
3427 new InsetSpecialChar(kind);
3428 if (!insertInset(new_inset))
3431 updateInset(new_inset, true);
3436 void BufferView::Pimpl::smartQuote()
3438 LyXText const * lt = bv_->getLyXText();
3439 Paragraph const * par = lt->cursor.par();
3440 pos_type pos = lt->cursor.pos();
3444 || (par->isInset(pos - 1)
3445 && par->getInset(pos - 1)->isSpace()))
3448 c = par->getChar(pos - 1);
3453 LyXLayout const & style =
3454 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3456 if (style.pass_thru ||
3457 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3458 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3462 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3464 if (insertInset(inset))
3471 // Open and lock an updatable inset
3472 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3474 LyXText * lt = bv_->getLyXText();
3478 if (!insertInset(new_inset)) {
3482 new_inset->edit(bv_, !behind);
3487 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3489 // if we are in a locking inset we should try to insert the
3490 // inset there otherwise this is a illegal function now
3491 if (bv_->theLockingInset()) {
3492 if (bv_->theLockingInset()->insetAllowed(inset))
3493 return bv_->theLockingInset()->insertInset(bv_, inset);
3497 // not quite sure if we want this...
3498 setCursorParUndo(bv_);
3501 beforeChange(bv_->text);
3502 if (!lout.empty()) {
3503 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3504 bv_->text->breakParagraph(bv_);
3505 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3507 if (bv_->text->cursor.par()->size()) {
3508 bv_->text->cursorLeft(bv_);
3510 bv_->text->breakParagraph(bv_);
3511 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3515 LyXTextClass const & tclass =
3516 textclasslist[buffer_->params.textclass];
3517 bool hasLayout = tclass.hasLayout(lres);
3518 string lay = tclass.defaultLayoutName();
3520 if (hasLayout != false) {
3524 // layout not fount using default
3525 lay = tclass.defaultLayoutName();
3528 bv_->text->setLayout(bv_, lay);
3530 bv_->text->setParagraph(bv_, 0, 0,
3532 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3537 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3540 bv_->text->insertInset(bv_, inset);
3541 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3548 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3550 if (!inset || !available())
3553 // first check for locking insets
3554 if (bv_->theLockingInset()) {
3555 if (bv_->theLockingInset() == inset) {
3556 if (bv_->text->updateInset(bv_, inset)) {
3559 buffer_->markDirty();
3564 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3565 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3568 buffer_->markDirty();
3576 // then check if the inset is a top_level inset (has no owner)
3577 // if yes do the update as always otherwise we have to update the
3578 // toplevel inset where this inset is inside
3579 Inset * tl_inset = inset;
3580 while(tl_inset->owner())
3581 tl_inset = tl_inset->owner();
3583 if (tl_inset == inset) {
3584 update(bv_->text, BufferView::UPDATE);
3585 if (bv_->text->updateInset(bv_, inset)) {
3589 | BufferView::FITCUR
3590 | BufferView::CHANGE);
3592 update(bv_->text, SELECT);
3596 } else if (static_cast<UpdatableInset *>(tl_inset)
3597 ->updateInsetInInset(bv_, inset))
3599 if (bv_->text->updateInset(bv_, tl_inset)) {
3607 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3610 if (!available()) return;
3613 beforeChange(bv_->text);
3614 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3616 LyXCursor const & cursor = bv_->text->cursor;
3620 cursor.par()->isInset(cursor.pos())) {
3621 Inset const * inset = cursor.par()->getInset(cursor.pos());
3622 if (find(codes.begin(), codes.end(), inset->lyxCode())
3625 static_cast<InsetCommand const *>(inset)->getContents();
3629 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3630 if (bv_->text->cursor.pos()
3631 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3632 LyXCursor tmp = bv_->text->cursor;
3633 bv_->text->cursor.par(bv_->text->ownerParagraph());
3634 bv_->text->cursor.pos(0);
3635 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3636 bv_->text->cursor = tmp;
3637 bv_->owner()->message(_("No more insets"));
3640 bv_->owner()->message(_("No more insets"));
3643 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3644 bv_->text->selection.cursor = bv_->text->cursor;
3648 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3650 gotoInset(vector<Inset::Code>(1, code), same_content);