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));
144 workarea().scrollCB.connect(boost::bind(&BufferView::Pimpl::scrollCB, this, _1));
145 workarea().workAreaExpose
146 .connect(boost::bind(&BufferView::Pimpl::workAreaExpose, this));
147 workarea().workAreaEnter
148 .connect(boost::bind(&BufferView::Pimpl::enterView, this));
149 workarea().workAreaLeave
150 .connect(boost::bind(&BufferView::Pimpl::leaveView, this));
151 workarea().workAreaButtonPress
152 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
153 workarea().workAreaButtonRelease
154 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
155 workarea().workAreaMotionNotify
156 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
157 workarea().workAreaDoubleClick
158 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
159 workarea().workAreaTripleClick
160 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
161 workarea().workAreaKeyPress
162 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
163 workarea().selectionRequested
164 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
165 workarea().selectionLost
166 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
168 cursor_timeout.timeout.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
169 cursor_timeout.start();
170 workarea().setFocus();
171 saved_positions.resize(saved_positions_num);
175 WorkArea & BufferView::Pimpl::workarea() const
177 return *workarea_.get();
181 Painter & BufferView::Pimpl::painter()
183 return workarea().getPainter();
187 void BufferView::Pimpl::buffer(Buffer * b)
189 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
195 buffer_->delUser(bv_);
197 // Put the old text into the TextCache, but
198 // only if the buffer is still loaded.
199 // Also set the owner of the test to 0
200 // bv_->text->owner(0);
201 textcache.add(buffer_, workarea().workWidth(), bv_->text);
202 if (lyxerr.debugging())
203 textcache.show(lyxerr, "BufferView::buffer");
208 // Set current buffer
211 if (bufferlist.getState() == BufferList::CLOSING) return;
214 // screen is always deleted when the buffer is changed.
217 // If we are closing the buffer, use the first buffer as current
219 buffer_ = bufferlist.first();
223 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
224 buffer_->addUser(bv_);
225 // If we don't have a text object for this, we make one
226 if (bv_->text == 0) {
227 resizeCurrentBuffer();
232 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
233 owner_->updateMenubar();
234 owner_->updateToolbar();
235 // Similarly, buffer-dependent dialogs should be updated or
236 // hidden. This should go here because some dialogs (eg ToC)
237 // require bv_->text.
238 owner_->getDialogs()->updateBufferDependent(true);
244 lyxerr[Debug::INFO] << " No Buffer!" << endl;
245 owner_->updateMenubar();
246 owner_->updateToolbar();
247 owner_->getDialogs()->hideBufferDependent();
251 // Also remove all remaining text's from the testcache.
252 // (there should not be any!) (if there is any it is a
254 if (lyxerr.debugging())
255 textcache.show(lyxerr, "buffer delete all");
258 // should update layoutchoice even if we don't have a buffer.
259 owner_->updateLayoutChoice();
261 owner_->updateWindowTitle();
265 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
267 workarea().resize(xpos, ypos, width, height);
268 update(bv_->text, SELECT);
273 void BufferView::Pimpl::resize()
276 resizeCurrentBuffer();
280 void BufferView::Pimpl::redraw()
282 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
287 bool BufferView::Pimpl::fitCursor()
289 lyx::Assert(screen_.get());
293 if (bv_->theLockingInset()) {
294 bv_->theLockingInset()->fitInsetCursor(bv_);
297 ret = screen_->fitCursor(bv_->text, bv_);
300 bv_->owner()->getDialogs()->updateParagraph();
307 void BufferView::Pimpl::redoCurrentBuffer()
309 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
310 if (buffer_ && bv_->text) {
312 owner_->updateLayoutChoice();
317 int BufferView::Pimpl::resizeCurrentBuffer()
319 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
322 Paragraph * selstartpar = 0;
323 Paragraph * selendpar = 0;
324 UpdatableInset * the_locking_inset = 0;
327 pos_type selstartpos = 0;
328 pos_type selendpos = 0;
329 bool selection = false;
330 bool mark_set = false;
332 owner_->prohibitInput();
334 owner_->message(_("Formatting document..."));
337 par = bv_->text->cursor.par();
338 pos = bv_->text->cursor.pos();
339 selstartpar = bv_->text->selection.start.par();
340 selstartpos = bv_->text->selection.start.pos();
341 selendpar = bv_->text->selection.end.par();
342 selendpos = bv_->text->selection.end.pos();
343 selection = bv_->text->selection.set();
344 mark_set = bv_->text->selection.mark();
345 the_locking_inset = bv_->theLockingInset();
346 buffer_->resizeInsets(bv_);
347 // I don't think the delete and new are necessary here we just could
348 // call only init! (Jug 20020419)
350 bv_->text = new LyXText(bv_);
351 bv_->text->init(bv_);
353 // See if we have a text in TextCache that fits
354 // the new buffer_ with the correct width.
355 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
357 if (lyxerr.debugging()) {
358 lyxerr << "Found a LyXText that fits:\n";
359 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
361 // Set the owner of the newly found text
362 // bv_->text->owner(bv_);
363 if (lyxerr.debugging())
364 textcache.show(lyxerr, "resizeCurrentBuffer");
366 bv_->text = new LyXText(bv_);
367 bv_->text->init(bv_);
368 //buffer_->resizeInsets(bv_);
375 bv_->text->selection.set(true);
376 // At this point just to avoid the Delete-Empty-Paragraph-
377 // Mechanism when setting the cursor.
378 bv_->text->selection.mark(mark_set);
380 bv_->text->setCursor(bv_, selstartpar, selstartpos);
381 bv_->text->selection.cursor = bv_->text->cursor;
382 bv_->text->setCursor(bv_, selendpar, selendpos);
383 bv_->text->setSelection(bv_);
384 bv_->text->setCursor(bv_, par, pos);
386 bv_->text->setCursor(bv_, par, pos);
387 bv_->text->selection.cursor = bv_->text->cursor;
388 bv_->text->selection.set(false);
390 // remake the inset locking
391 bv_->theLockingInset(the_locking_inset);
394 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
396 // this will scroll the screen such that the cursor becomes visible
401 owner_->allowInput();
403 /// clear the "Formatting Document" message
410 void BufferView::Pimpl::updateScreen()
412 // Regenerate the screen.
413 screen_.reset(new LyXScreen(workarea()));
417 void BufferView::Pimpl::updateScrollbar()
420 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
421 workarea().setScrollbar(0, 1.0);
425 long const text_height = bv_->text->height;
426 long const work_height = workarea().height();
428 double const lineh = bv_->text->defaultHeight();
429 double const slider_size =
430 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
432 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
433 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
435 /* If the text is smaller than the working area, the scrollbar
436 * maximum must be the working area height. No scrolling will
438 if (text_height <= work_height) {
439 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
440 workarea().setScrollbarBounds(0.0, 0.0);
441 current_scrollbar_value = bv_->text->first_y;
442 workarea().setScrollbar(current_scrollbar_value, 1.0);
446 workarea().setScrollbarBounds(0.0, text_height - work_height);
447 workarea().setScrollbarIncrements(lineh);
448 current_scrollbar_value = bv_->text->first_y;
449 workarea().setScrollbar(current_scrollbar_value, slider_size);
453 // Callback for scrollbar slider
454 void BufferView::Pimpl::scrollCB(double value)
456 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
458 if (!buffer_) return;
460 current_scrollbar_value = long(value);
462 if (current_scrollbar_value < 0)
463 current_scrollbar_value = 0;
468 screen_->draw(bv_->text, bv_, current_scrollbar_value);
470 if (!lyxrc.cursor_follows_scrollbar) {
475 LyXText * vbt = bv_->text;
477 int const height = vbt->defaultHeight();
478 int const first = static_cast<int>((bv_->text->first_y + height));
479 int const last = static_cast<int>((bv_->text->first_y + workarea().height() - height));
481 if (vbt->cursor.y() < first)
482 vbt->setCursorFromCoordinates(bv_, 0, first);
483 else if (vbt->cursor.y() > last)
484 vbt->setCursorFromCoordinates(bv_, 0, last);
490 int BufferView::Pimpl::scrollUp(long time)
492 if (!buffer_ || !screen_.get())
495 double value = workarea().getScrollbarValue();
501 float add_value = (bv_->text->defaultHeight()
502 + float(time) * float(time) * 0.125);
504 if (add_value > workarea().height())
505 add_value = float(workarea().height() -
506 bv_->text->defaultHeight());
508 float add_value = float(workarea().height()) * float(time) / 100;
516 workarea().setScrollbarValue(value);
523 int BufferView::Pimpl::scrollDown(long time)
525 if (!buffer_ || !screen_.get())
528 double value = workarea().getScrollbarValue();
529 pair<float, float> p = workarea().getScrollbarBounds();
530 double const max = p.second;
536 float add_value = (bv_->text->defaultHeight()
537 + float(time) * float(time) * 0.125);
539 if (add_value > workarea().height())
540 add_value = float(workarea().height() -
541 bv_->text->defaultHeight());
543 float add_value = float(workarea().height()) * float(time) / 100;
551 workarea().setScrollbarValue(value);
558 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, key_modifier::state state)
560 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
564 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
566 // Only use motion with button 1
567 if (!(state & mouse_button::button1))
570 if (!buffer_ || !screen_.get()) return;
572 // Check for inset locking
573 if (bv_->theLockingInset()) {
574 LyXCursor cursor = bv_->text->cursor;
575 LyXFont font = bv_->text->getFont(buffer_,
576 cursor.par(), cursor.pos());
577 int width = bv_->theLockingInset()->width(bv_, font);
578 int inset_x = font.isVisibleRightToLeft()
579 ? cursor.ix() - width : cursor.ix();
580 int start_x = inset_x + bv_->theLockingInset()->scroll();
581 bv_->theLockingInset()->
582 insetMotionNotify(bv_,
584 y - cursor.iy() + bv_->text->first_y,
589 /* The test for not selection possible is needed, that only motion
590 events are used, where the bottom press event was on
591 the drawing area too */
592 if (!selection_possible)
595 screen_->hideCursor();
597 int y_before = bv_->text->cursor.y();
599 Row * cursorrow = bv_->text->cursor.row();
600 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
602 // sorry for this but I have a strange error that the y value jumps at
603 // a certain point. This seems like an error in my xforms library or
604 // in some other local environment, but I would like to leave this here
605 // for the moment until I can remove this (Jug 20020418)
606 if (y_before < bv_->text->cursor.y())
607 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
609 // This is to allow jumping over large insets
610 if (cursorrow == bv_->text->cursor.row()) {
611 if (y >= int(workarea().height())) {
612 bv_->text->cursorDown(bv_, false);
614 bv_->text->cursorUp(bv_, false);
618 if (!bv_->text->selection.set())
619 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
621 bv_->text->setSelection(bv_);
622 screen_->toggleToggle(bv_->text, bv_);
628 // Single-click on work area
629 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
630 mouse_button::state button)
632 if (!buffer_ || !screen_.get())
635 // ok ok, this is a hack.
637 if (button == mouse_button::button4) {
638 scrollUp(lyxrc.wheel_jump);
639 // We shouldn't go further down as we really should only do the
640 // scrolling and be done with this. Otherwise we may open some
641 // dialogs (Jug 20020424).
643 } else if (button == mouse_button::button5) {
644 scrollDown(lyxrc.wheel_jump);
645 // We shouldn't go further down as we really should only do the
646 // scrolling and be done with this. Otherwise we may open some
647 // dialogs (Jug 20020424).
651 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
653 // Middle button press pastes if we have a selection
654 // We do this here as if the selection was inside an inset
655 // it could get cleared on the unlocking of the inset so
656 // we have to check this first
657 bool paste_internally = false;
658 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
659 owner_->getLyXFunc()->dispatch(LFUN_COPY);
660 paste_internally = true;
663 int const screen_first = bv_->text->first_y;
665 if (bv_->theLockingInset()) {
666 // We are in inset locking mode
668 /* Check whether the inset was hit. If not reset mode,
669 otherwise give the event to the inset */
670 if (inset_hit == bv_->theLockingInset()) {
671 bv_->theLockingInset()->
672 insetButtonPress(bv_,xpos, ypos,button);
675 bv_->unlockInset(bv_->theLockingInset());
680 selection_possible = true;
681 screen_->hideCursor();
683 // Clear the selection
684 screen_->toggleSelection(bv_->text, bv_);
685 bv_->text->clearSelection();
686 bv_->text->fullRebreak(bv_);
690 // Single left click in math inset?
691 if (isHighlyEditableInset(inset_hit)) {
692 // Highly editable inset, like math
693 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
694 selection_possible = false;
695 owner_->updateLayoutChoice();
696 owner_->message(inset->editMessage());
697 //inset->edit(bv_, xpos, ypos, button);
698 // We just have to lock the inset before calling a PressEvent on it!
699 // we don't need the edit() call here! (Jug20020329)
700 if (!bv_->lockInset(inset)) {
701 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
703 inset->insetButtonPress(bv_, xpos, ypos, button);
706 // I'm not sure we should continue here if we hit an inset (Jug20020403)
708 // Right click on a footnote flag opens float menu
709 if (button == mouse_button::button3) {
710 selection_possible = false;
714 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
715 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
717 bv_->text->selection.cursor = bv_->text->cursor;
718 bv_->text->cursor.x_fix(bv_->text->cursor.x());
720 owner_->updateLayoutChoice();
722 selection_possible = false;
725 // Insert primary selection with middle mouse
726 // if there is a local selection in the current buffer,
728 if (button == mouse_button::button2) {
729 if (paste_internally)
730 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
732 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
734 selection_possible = false;
740 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
745 LyXText * text = bv_->getLyXText();
747 if (text->bv_owner && bv_->theLockingInset())
750 if (screen_.get() && button == mouse_button::button1) {
751 if (text->bv_owner) {
752 screen_->hideCursor();
753 screen_->toggleSelection(text, bv_);
754 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
755 screen_->toggleSelection(text, bv_, false);
757 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
759 /* This will fit the cursor on the screen
761 update(text, BufferView::SELECT|BufferView::FITCUR);
766 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
771 LyXText * text = bv_->getLyXText();
773 if (text->bv_owner && bv_->theLockingInset())
776 if (screen_.get() && (button == mouse_button::button1)) {
777 if (text->bv_owner) {
778 screen_->hideCursor();
779 screen_->toggleSelection(text, bv_);
781 text->cursorHome(bv_);
782 text->selection.cursor = text->cursor;
783 text->cursorEnd(bv_);
784 text->setSelection(bv_);
785 if (text->bv_owner) {
786 screen_->toggleSelection(text, bv_, false);
788 /* This will fit the cursor on the screen
790 update(text, BufferView::SELECT|BufferView::FITCUR);
795 void BufferView::Pimpl::selectionRequested()
802 LyXText * text = bv_->getLyXText();
804 if (text->selection.set() &&
805 (!bv_->text->xsel_cache.set() ||
806 text->selection.start != bv_->text->xsel_cache.start ||
807 text->selection.end != bv_->text->xsel_cache.end))
809 bv_->text->xsel_cache = text->selection;
810 sel = text->selectionAsString(bv_->buffer(), false);
811 } else if (!text->selection.set()) {
813 bv_->text->xsel_cache.set(false);
816 workarea().putClipboard(sel);
821 void BufferView::Pimpl::selectionLost()
826 bv_->getLyXText()->clearSelection();
828 bv_->text->xsel_cache.set(false);
833 void BufferView::Pimpl::enterView()
836 SetXtermCursor(workarea().getWin());
837 using_xterm_cursor = true;
842 void BufferView::Pimpl::leaveView()
844 if (using_xterm_cursor) {
845 XUndefineCursor(fl_get_display(), workarea().getWin());
846 using_xterm_cursor = false;
851 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
852 mouse_button::state button)
854 // do nothing if we used the mouse wheel
855 if (!buffer_ || !screen_.get() || button == mouse_button::button4 || button == mouse_button::button5)
858 // If we hit an inset, we have the inset coordinates in these
859 // and inset_hit points to the inset. If we do not hit an
860 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
861 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
863 if (bv_->theLockingInset()) {
864 // We are in inset locking mode.
866 /* LyX does a kind of work-area grabbing for insets.
867 Only a ButtonPress Event outside the inset will
868 force a insetUnlock. */
869 bv_->theLockingInset()->
870 insetButtonRelease(bv_, x, y, button);
874 selection_possible = false;
876 if (button == mouse_button::button2)
880 if (button == mouse_button::button1) {
881 workarea().haveSelection(bv_->getLyXText()->selection.set());
886 owner_->updateMenubar();
887 owner_->updateToolbar();
889 // Did we hit an editable inset?
891 selection_possible = false;
893 // if we reach this point with a selection, it
894 // must mean we are currently selecting.
895 // But we don't want to open the inset
896 // because that is annoying for the user.
897 // So just pretend we didn't hit it.
898 // this is OK because a "kosher" ButtonRelease
899 // will follow a ButtonPress that clears
901 // Note this also fixes selection drawing
902 // problems if we end up opening an inset
903 if (bv_->getLyXText()->selection.set())
906 // CHECK fix this proper in 0.13
907 // well, maybe 13.0 !!!!!!!!!
909 // Following a ref shouldn't issue
910 // a push on the undo-stack
911 // anylonger, now that we have
912 // keybindings for following
913 // references and returning from
914 // references. IMHO though, it
915 // should be the inset's own business
916 // to push or not push on the undo
917 // stack. They don't *have* to
918 // alter the document...
920 // ...or maybe the SetCursorParUndo()
921 // below isn't necessary at all anylonger?
922 if (inset_hit->lyxCode() == Inset::REF_CODE) {
923 setCursorParUndo(bv_);
926 owner_->message(inset_hit->editMessage());
928 if (isHighlyEditableInset(inset_hit)) {
929 // Highly editable inset, like math
930 UpdatableInset *inset = (UpdatableInset *)inset_hit;
931 inset->insetButtonRelease(bv_, x, y, button);
933 inset_hit->insetButtonRelease(bv_, x, y, button);
934 // IMO this is a grosshack! Inset's should be changed so that
935 // they call the actions they have to do with the insetButtonRel.
936 // function and not in the edit(). This should be changed
938 inset_hit->edit(bv_, x, y, button);
943 // Maybe we want to edit a bibitem ale970302
944 if (bv_->text->cursor.par()->bibkey && x < 20 +
945 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
946 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
953 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
954 LyXCursor const & cursor) const
956 Paragraph /*const*/ & par = *cursor.par();
957 pos_type const pos = cursor.pos();
959 lyx::Assert(par.getInset(pos));
961 Inset const & inset(*par.getInset(pos));
963 LyXFont const & font = text.getFont(buffer_, &par, pos);
965 int const width = inset.width(bv_, font);
966 int const inset_x = font.isVisibleRightToLeft()
967 ? (cursor.ix() - width) : cursor.ix();
970 inset_x + inset.scroll(),
972 cursor.iy() - inset.ascent(bv_, font),
973 cursor.iy() + inset.descent(bv_, font));
977 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
978 LyXCursor const & cursor,
979 int & x, int & y) const
981 pos_type const pos(cursor.pos());
982 Paragraph /*const*/ & par(*cursor.par());
984 if (pos >= par.size() || !par.isInset(pos)) {
988 Inset /*const*/ * inset = par.getInset(pos);
990 if (!isEditableInset(inset)) {
994 Box b(insetDimensions(text, cursor));
996 if (!b.contained(x, y)) {
997 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
998 << " box " << b << endl;
1002 text.setCursor(bv_, &par, pos, true);
1005 // The origin of an inset is on the baseline
1006 y -= text.cursor.iy();
1012 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
1017 int y_tmp = y + text->first_y;
1020 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
1022 Inset * inset(checkInset(*text, cursor, x, y_tmp));
1029 // look at previous position
1031 if (cursor.pos() == 0) {
1036 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
1038 inset = checkInset(*text, cursor, x, y_tmp);
1046 void BufferView::Pimpl::workAreaExpose()
1048 static int work_area_width;
1049 static unsigned int work_area_height;
1051 bool const widthChange = workarea().workWidth() != work_area_width;
1052 bool const heightChange = workarea().height() != work_area_height;
1054 // update from work area
1055 work_area_width = workarea().workWidth();
1056 work_area_height = workarea().height();
1059 // The visible LyXView need a resize
1062 // Remove all texts from the textcache
1063 // This is not _really_ what we want to do. What
1064 // we really want to do is to delete in textcache
1065 // that does not have a BufferView with matching
1066 // width, but as long as we have only one BufferView
1067 // deleting all gives the same result.
1068 if (lyxerr.debugging())
1069 textcache.show(lyxerr, "Expose delete all");
1071 buffer_->resizeInsets(bv_);
1072 } else if (heightChange) {
1073 // Rebuild image of current screen
1075 // fitCursor() ensures we don't jump back
1076 // to the start of the document on vertical
1080 // The main window size has changed, repaint most stuff
1082 } else if (screen_.get())
1083 screen_->redraw(bv_->text, bv_);
1085 // Grey box when we don't have a buffer
1086 workarea().greyOut();
1089 // always make sure that the scrollbar is sane.
1091 owner_->updateLayoutChoice();
1096 void BufferView::Pimpl::update()
1098 if (screen_.get() &&
1099 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1101 LyXText::text_status st = bv_->text->status();
1102 screen_->update(bv_->text, bv_);
1104 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1105 bv_->text->fullRebreak(bv_);
1106 st = LyXText::NEED_MORE_REFRESH;
1107 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1108 bv_->text->cursor.pos());
1109 if (bv_->text->selection.set()) {
1110 bv_->text->setCursor(bv_, bv_->text->selection.start,
1111 bv_->text->selection.start.par(),
1112 bv_->text->selection.start.pos());
1113 bv_->text->setCursor(bv_, bv_->text->selection.end,
1114 bv_->text->selection.end.par(),
1115 bv_->text->selection.end.pos());
1118 bv_->text->status(bv_, st);
1119 screen_->update(bv_->text, bv_);
1121 // do this here instead of in the screen::update because of
1123 bv_->text->status(bv_, LyXText::UNCHANGED);
1129 // Values used when calling update:
1131 // -2 - update, move sel_cursor if selection, fitcursor
1132 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1133 // 0 - update, move sel_cursor if selection, fitcursor
1134 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1135 // 3 - update, move sel_cursor if selection
1138 // a simple redraw of the parts that need refresh
1140 // move sel_cursor if selection -
1141 // the text's sel_cursor is moved if there is selection is progress
1144 // fitCursor() is called and the scrollbar updated
1147 // the buffer is marked dirty.
1156 // UPDATE_ONLY = UPDATE;
1157 // UPDATE_SELECT = UPDATE | SELECT;
1158 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1159 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1161 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1162 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1163 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1164 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1165 // update(3) -> update(1) -> update(1) -> update(SELECT)
1167 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1169 owner_->updateLayoutChoice();
1171 if (!text->selection.set() && (f & SELECT)) {
1172 text->selection.cursor = text->cursor;
1175 text->fullRebreak(bv_);
1177 if (text->inset_owner) {
1178 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1179 updateInset(text->inset_owner, false);
1189 buffer_->markDirty();
1194 // Callback for cursor timer
1195 void BufferView::Pimpl::cursorToggle()
1198 cursor_timeout.restart();
1202 if (!screen_.get()) {
1203 cursor_timeout.restart();
1208 extern void reapSpellchecker(void);
1211 if (!bv_->theLockingInset()) {
1212 screen_->cursorToggle(bv_);
1214 bv_->theLockingInset()->toggleInsetCursor(bv_);
1217 cursor_timeout.restart();
1221 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1223 if (!text->cursor.row()->previous()) {
1224 if (text->first_y > 0) {
1225 int new_y = bv_->text->first_y - workarea().height();
1226 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1232 int y = text->first_y;
1233 Row * cursorrow = text->cursor.row();
1235 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
1239 if (cursorrow == bv_->text->cursor.row()) {
1240 // we have a row which is higher than the workarea so we leave the
1241 // cursor on the start of the row and move only the draw up as soon
1242 // as we move the cursor or do something while inside the row (it may
1243 // span several workarea-heights) we'll move to the top again, but this
1244 // is better than just jump down and only display part of the row.
1245 new_y = bv_->text->first_y - workarea().height();
1247 if (text->inset_owner) {
1248 new_y = bv_->text->cursor.iy()
1249 + bv_->theLockingInset()->insetInInsetY() + y
1250 + text->cursor.row()->height()
1251 - workarea().height() + 1;
1253 new_y = text->cursor.y()
1254 - text->cursor.row()->baseline()
1255 + text->cursor.row()->height()
1256 - workarea().height() + 1;
1259 screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
1260 if (text->cursor.row()->previous()) {
1262 text->setCursor(bv_, cur, text->cursor.row()->previous()->par(),
1263 text->cursor.row()->previous()->pos(), false);
1264 if (cur.y() > text->first_y) {
1265 text->cursorUp(bv_, true);
1272 void BufferView::Pimpl::cursorNext(LyXText * text)
1274 if (!text->cursor.row()->next()) {
1275 int y = text->cursor.y() - text->cursor.row()->baseline() +
1276 text->cursor.row()->height();
1277 if (y > int(text->first_y + workarea().height())) {
1278 screen_->draw(bv_->text, bv_,
1279 bv_->text->first_y + workarea().height());
1285 int y = text->first_y + workarea().height();
1286 if (text->inset_owner && !text->first_y) {
1287 y -= (bv_->text->cursor.iy()
1288 - bv_->text->first_y
1289 + bv_->theLockingInset()->insetInInsetY());
1291 text->getRowNearY(y);
1293 Row * cursorrow = text->cursor.row();
1294 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea().height());
1297 if (cursorrow == bv_->text->cursor.row()) {
1298 // we have a row which is higher than the workarea so we leave the
1299 // cursor on the start of the row and move only the draw down as soon
1300 // as we move the cursor or do something while inside the row (it may
1301 // span several workarea-heights) we'll move to the top again, but this
1302 // is better than just jump down and only display part of the row.
1303 new_y = bv_->text->first_y + workarea().height();
1305 if (text->inset_owner) {
1306 new_y = bv_->text->cursor.iy()
1307 + bv_->theLockingInset()->insetInInsetY()
1308 + y - text->cursor.row()->baseline();
1310 new_y = text->cursor.y() - text->cursor.row()->baseline();
1313 screen_->draw(bv_->text, bv_, new_y);
1314 if (text->cursor.row()->next()) {
1316 text->setCursor(bv_, cur, text->cursor.row()->next()->par(),
1317 text->cursor.row()->next()->pos(), false);
1318 if (cur.y() < int(text->first_y + workarea().height())) {
1319 text->cursorDown(bv_, true);
1326 bool BufferView::Pimpl::available() const
1328 if (buffer_ && bv_->text)
1334 void BufferView::Pimpl::beforeChange(LyXText * text)
1337 text->clearSelection();
1341 void BufferView::Pimpl::savePosition(unsigned int i)
1343 if (i >= saved_positions_num)
1345 saved_positions[i] = Position(buffer_->fileName(),
1346 bv_->text->cursor.par()->id(),
1347 bv_->text->cursor.pos());
1350 str << _("Saved bookmark") << ' ' << i;
1351 owner_->message(str.str().c_str());
1356 void BufferView::Pimpl::restorePosition(unsigned int i)
1358 if (i >= saved_positions_num)
1361 string const fname = saved_positions[i].filename;
1363 beforeChange(bv_->text);
1365 if (fname != buffer_->fileName()) {
1366 Buffer * b = bufferlist.exists(fname) ?
1367 bufferlist.getBuffer(fname) :
1368 bufferlist.loadLyXFile(fname); // don't ask, just load it
1369 if (b != 0) buffer(b);
1372 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1376 bv_->text->setCursor(bv_, par,
1377 min(par->size(), saved_positions[i].par_pos));
1379 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1382 str << _("Moved to bookmark") << ' ' << i;
1383 owner_->message(str.str().c_str());
1388 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1390 if (i >= saved_positions_num)
1393 return !saved_positions[i].filename.empty();
1397 void BufferView::Pimpl::setState()
1399 if (!lyxrc.rtl_support)
1402 LyXText * text = bv_->getLyXText();
1403 if (text->real_current_font.isRightToLeft()
1404 && !(bv_->theLockingInset()
1405 && bv_->theLockingInset()->lyxCode()== Inset::ERT_CODE))
1407 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1408 owner_->getIntl()->KeyMapSec();
1410 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1411 owner_->getIntl()->KeyMapPrim();
1417 void BufferView::Pimpl::insetSleep()
1419 if (bv_->theLockingInset() && !inset_slept) {
1420 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1421 bv_->theLockingInset()->insetUnlock(bv_);
1427 void BufferView::Pimpl::insetWakeup()
1429 if (bv_->theLockingInset() && inset_slept) {
1430 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1431 inset_slept = false;
1437 void BufferView::Pimpl::insetUnlock()
1439 if (bv_->theLockingInset()) {
1441 bv_->theLockingInset()->insetUnlock(bv_);
1442 bv_->theLockingInset(0);
1444 inset_slept = false;
1449 bool BufferView::Pimpl::focus() const
1451 return workarea().hasFocus();
1455 void BufferView::Pimpl::focus(bool f)
1457 if (f) workarea().setFocus();
1461 void BufferView::Pimpl::showCursor()
1463 if (screen_.get()) {
1464 if (bv_->theLockingInset())
1465 bv_->theLockingInset()->showInsetCursor(bv_);
1467 screen_->showCursor(bv_->text, bv_);
1472 void BufferView::Pimpl::hideCursor()
1474 if (screen_.get()) {
1475 if (!bv_->theLockingInset())
1476 // bv_->theLockingInset()->hideInsetCursor(bv_);
1478 screen_->hideCursor();
1483 void BufferView::Pimpl::toggleSelection(bool b)
1485 if (screen_.get()) {
1486 if (bv_->theLockingInset())
1487 bv_->theLockingInset()->toggleSelection(bv_, b);
1488 screen_->toggleSelection(bv_->text, bv_, b);
1493 void BufferView::Pimpl::toggleToggle()
1496 screen_->toggleToggle(bv_->text, bv_);
1500 void BufferView::Pimpl::center()
1502 beforeChange(bv_->text);
1503 if (bv_->text->cursor.y() > static_cast<int>((workarea().height() / 2))) {
1504 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea().height() / 2);
1506 screen_->draw(bv_->text, bv_, 0);
1508 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1513 void BufferView::Pimpl::pasteClipboard(bool asPara)
1518 screen_->hideCursor();
1519 beforeChange(bv_->text);
1521 string const clip(workarea().getClipboard());
1527 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1529 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1531 bv_->getLyXText()->clearSelection();
1532 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1536 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1538 workarea().putClipboard(stuff);
1543 * Dispatch functions for actions which can be valid for BufferView->text
1544 * and/or InsetText->text!!!
1549 void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
1551 LyXText * lt = bv_->getLyXText();
1553 if (selecting || lt->selection.mark()) {
1554 lt->setSelection(bv_);
1558 updateInset(lt->inset_owner, false);
1562 update(lt, BufferView::SELECT|BufferView::FITCUR);
1564 update(lt, BufferView::SELECT);
1566 } else if (bv_->text->status() != LyXText::UNCHANGED) {
1567 bv_->theLockingInset()->hideInsetCursor(bv_);
1568 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1572 if (!lt->selection.set())
1573 workarea().haveSelection(false);
1575 /* ---> Everytime the cursor is moved, show the current font state. */
1576 // should this too me moved out of this func?
1577 //owner->showState();
1582 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1584 LyXCursor cursor = bv_->getLyXText()->cursor;
1585 Buffer::inset_iterator it =
1586 find_if(Buffer::inset_iterator(
1587 cursor.par(), cursor.pos()),
1588 buffer_->inset_iterator_end(),
1589 lyx::compare_memfun(&Inset::lyxCode, code));
1590 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1594 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1596 string filename = filen;
1598 if (filename.empty()) {
1599 // Launch a file browser
1600 string initpath = lyxrc.document_path;
1603 string const trypath = owner_->buffer()->filePath();
1604 // If directory is writeable, use this as default.
1605 if (IsDirWriteable(trypath))
1609 FileDialog fileDlg(bv_->owner(),
1610 _("Select LyX document to insert"),
1612 make_pair(string(_("Documents|#o#O")),
1613 string(lyxrc.document_path)),
1614 make_pair(string(_("Examples|#E#e")),
1615 string(AddPath(system_lyxdir, "examples"))));
1617 FileDialog::Result result =
1618 fileDlg.Select(initpath,
1619 _("*.lyx| LyX Documents (*.lyx)"));
1621 if (result.first == FileDialog::Later)
1624 filename = result.second;
1626 // check selected filename
1627 if (filename.empty()) {
1628 owner_->message(_("Canceled."));
1633 // get absolute path of file and add ".lyx" to the filename if
1635 filename = FileSearch(string(), filename, "lyx");
1637 string const disp_fn(MakeDisplayPath(filename));
1640 s1 << _("Inserting document") << ' '
1641 << disp_fn << " ...";
1642 owner_->message(s1.str().c_str());
1643 bool const res = bv_->insertLyXFile(filename);
1646 str << _("Document") << ' ' << disp_fn
1647 << ' ' << _("inserted.");
1648 owner_->message(str.str().c_str());
1651 str << _("Could not insert document") << ' '
1653 owner_->message(str.str().c_str());
1658 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1660 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1661 << action <<"] arg[" << argument << "]" << endl;
1663 LyXTextClass const & tclass = textclasslist[buffer_->params.textclass];
1666 // --- Misc -------------------------------------------
1670 LyXText * lt = bv_->getLyXText();
1671 lt->toggleAppendix(bv_);
1674 | BufferView::FITCUR
1675 | BufferView::CHANGE);
1680 case LFUN_TOC_INSERT:
1682 InsetCommandParams p;
1683 p.setCmdName("tableofcontents");
1684 Inset * inset = new InsetTOC(p);
1685 if (!insertInset(inset, tclass.defaultLayoutName()))
1690 case LFUN_SCROLL_INSET:
1691 // this is not handled here as this funktion is only aktive
1692 // if we have a locking_inset and that one is (or contains)
1696 case LFUN_INSET_GRAPHICS:
1698 Inset * new_inset = new InsetGraphics;
1699 if (!insertInset(new_inset)) {
1702 // this is need because you don't use a inset->Edit()
1703 updateInset(new_inset, true);
1704 new_inset->edit(bv_);
1714 case LFUN_PASTESELECTION:
1716 bool asPara = false;
1717 if (argument == "paragraph")
1719 pasteClipboard(asPara);
1731 case LFUN_LAYOUT_COPY:
1732 bv_->copyEnvironment();
1735 case LFUN_LAYOUT_PASTE:
1736 bv_->pasteEnvironment();
1740 case LFUN_GOTOERROR:
1741 gotoInset(Inset::ERROR_CODE, false);
1745 gotoInset(Inset::IGNORE_CODE, false);
1748 case LFUN_REFERENCE_GOTO:
1750 vector<Inset::Code> tmp;
1751 tmp.push_back(Inset::LABEL_CODE);
1752 tmp.push_back(Inset::REF_CODE);
1753 gotoInset(tmp, true);
1757 case LFUN_HYPHENATION:
1758 specialChar(InsetSpecialChar::HYPHENATION);
1761 case LFUN_LIGATURE_BREAK:
1762 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1766 specialChar(InsetSpecialChar::LDOTS);
1769 case LFUN_END_OF_SENTENCE:
1770 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1773 case LFUN_MENU_SEPARATOR:
1774 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1781 case LFUN_DEPTH_MIN:
1782 changeDepth(bv_, bv_->getLyXText(), -1);
1785 case LFUN_DEPTH_PLUS:
1786 changeDepth(bv_, bv_->getLyXText(), 1);
1790 owner_->getDialogs()->setUserFreeFont();
1793 case LFUN_FILE_INSERT:
1794 MenuInsertLyXFile(argument);
1797 case LFUN_FILE_INSERT_ASCII_PARA:
1798 InsertAsciiFile(bv_, argument, true);
1801 case LFUN_FILE_INSERT_ASCII:
1802 InsertAsciiFile(bv_, argument, false);
1807 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1808 << argument << endl;
1810 // This is not the good solution to the empty argument
1811 // problem, but it will hopefully suffice for 1.2.0.
1812 // The correct solution would be to augument the
1813 // function list/array with information about what
1814 // functions needs arguments and their type.
1815 if (argument.empty()) {
1816 owner_->getLyXFunc()->setErrorMessage(
1817 _("LyX function 'layout' needs an argument."));
1821 // Derive layout number from given argument (string)
1822 // and current buffer's textclass (number). */
1823 bool hasLayout = tclass.hasLayout(argument);
1824 string layout = argument;
1826 // If the entry is obsolete, use the new one instead.
1828 string const & obs = tclass[layout].obsoleted_by();
1834 owner_->getLyXFunc()->setErrorMessage(
1835 string(N_("Layout ")) + argument +
1840 bool change_layout = (current_layout != layout);
1841 LyXText * lt = bv_->getLyXText();
1842 if (!change_layout && lt->selection.set() &&
1843 lt->selection.start.par() != lt->selection.end.par())
1845 Paragraph * spar = lt->selection.start.par();
1846 Paragraph * epar = lt->selection.end.par()->next();
1847 while(spar != epar) {
1848 if (spar->layout() != current_layout) {
1849 change_layout = true;
1854 if (change_layout) {
1856 current_layout = layout;
1859 | BufferView::FITCUR);
1860 lt->setLayout(bv_, layout);
1861 owner_->setLayout(layout);
1864 | BufferView::FITCUR
1865 | BufferView::CHANGE);
1872 lang(bv_, argument);
1874 owner_->showState();
1879 owner_->showState();
1884 owner_->showState();
1889 owner_->showState();
1894 owner_->showState();
1899 owner_->showState();
1904 owner_->showState();
1909 owner_->showState();
1912 case LFUN_UNDERLINE:
1914 owner_->showState();
1917 case LFUN_FONT_SIZE:
1918 fontSize(bv_, argument);
1919 owner_->showState();
1922 case LFUN_FONT_STATE:
1923 owner_->getLyXFunc()->setMessage(currentState(bv_));
1926 case LFUN_UPCASE_WORD:
1928 LyXText * lt = bv_->getLyXText();
1932 | BufferView::FITCUR);
1933 lt->changeCase(bv_, LyXText::text_uppercase);
1934 if (lt->inset_owner)
1935 updateInset(lt->inset_owner, true);
1938 | BufferView::FITCUR
1939 | BufferView::CHANGE);
1943 case LFUN_LOWCASE_WORD:
1945 LyXText * lt = bv_->getLyXText();
1947 update(lt, BufferView::SELECT|BufferView::FITCUR);
1948 lt->changeCase(bv_, LyXText::text_lowercase);
1949 if (lt->inset_owner)
1950 updateInset(lt->inset_owner, true);
1953 | BufferView::FITCUR
1954 | BufferView::CHANGE);
1958 case LFUN_CAPITALIZE_WORD:
1960 LyXText * lt = bv_->getLyXText();
1962 update(lt, BufferView::SELECT|BufferView::FITCUR);
1963 lt->changeCase(bv_, LyXText::text_capitalization);
1964 if (lt->inset_owner)
1965 updateInset(lt->inset_owner, true);
1968 | BufferView::FITCUR
1969 | BufferView::CHANGE);
1973 case LFUN_TRANSPOSE_CHARS:
1975 LyXText * lt = bv_->getLyXText();
1977 update(lt, BufferView::SELECT|BufferView::FITCUR);
1978 lt->transposeChars(*bv_);
1979 if (lt->inset_owner)
1980 updateInset(lt->inset_owner, true);
1983 | BufferView::FITCUR
1984 | BufferView::CHANGE);
1989 case LFUN_INSERT_LABEL:
1990 MenuInsertLabel(bv_, argument);
1993 case LFUN_REF_INSERT:
1994 if (argument.empty()) {
1995 InsetCommandParams p("ref");
1996 owner_->getDialogs()->createRef(p.getAsString());
1998 InsetCommandParams p;
1999 p.setFromString(argument);
2001 InsetRef * inset = new InsetRef(p, *buffer_);
2002 if (!insertInset(inset))
2005 updateInset(inset, true);
2009 case LFUN_BOOKMARK_SAVE:
2010 savePosition(strToUnsignedInt(argument));
2013 case LFUN_BOOKMARK_GOTO:
2014 restorePosition(strToUnsignedInt(argument));
2019 string label(argument);
2020 if (label.empty()) {
2022 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
2024 label = inset->getContents();
2029 if (!label.empty()) {
2030 //bv_->savePosition(0);
2031 if (!bv_->gotoLabel(label))
2032 Alert::alert(_("Error"),
2033 _("Couldn't find this label"),
2034 _("in current document."));
2039 // --- Cursor Movements -----------------------------
2042 LyXText * lt = bv_->getLyXText();
2044 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2045 if (!lt->selection.mark())
2047 update(lt, BufferView::SELECT|BufferView::FITCUR);
2049 lt->cursorLeft(bv_, false);
2050 if (lt->cursor.pos() < lt->cursor.par()->size()
2051 && lt->cursor.par()->isInset(lt->cursor.pos())
2052 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2053 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2054 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2056 tmpinset->edit(bv_, false);
2058 tmpinset->edit(bv_);
2062 lt->cursorRight(bv_, false);
2064 moveCursorUpdate(false);
2065 owner_->showState();
2071 // This is soooo ugly. Isn`t it possible to make
2072 // it simpler? (Lgb)
2073 LyXText * lt = bv_->getLyXText();
2074 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
2075 if (!lt->selection.mark())
2077 update(lt, BufferView::SELECT|BufferView::FITCUR);
2078 LyXCursor const cur = lt->cursor;
2080 lt->cursorLeft(bv_, false);
2081 if ((is_rtl || cur != lt->cursor) && // only if really moved!
2082 lt->cursor.pos() < lt->cursor.par()->size() &&
2083 lt->cursor.par()->isInset(lt->cursor.pos()) &&
2084 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
2085 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
2086 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
2088 tmpinset->edit(bv_);
2090 tmpinset->edit(bv_, false);
2094 lt->cursorRight(bv_, false);
2097 moveCursorUpdate(false);
2098 owner_->showState();
2104 LyXText * lt = bv_->getLyXText();
2106 if (!lt->selection.mark())
2108 update(lt, BufferView::UPDATE);
2111 moveCursorUpdate(false);
2112 owner_->showState();
2118 LyXText * lt = bv_->getLyXText();
2120 if (!lt->selection.mark())
2122 update(lt, BufferView::UPDATE);
2123 lt->cursorDown(bv_);
2125 moveCursorUpdate(false);
2126 owner_->showState();
2130 case LFUN_UP_PARAGRAPH:
2132 LyXText * lt = bv_->getLyXText();
2134 if (!lt->selection.mark())
2136 update(lt, BufferView::UPDATE);
2137 lt->cursorUpParagraph(bv_);
2139 moveCursorUpdate(false);
2140 owner_->showState();
2144 case LFUN_DOWN_PARAGRAPH:
2146 LyXText * lt = bv_->getLyXText();
2148 if (!lt->selection.mark())
2150 update(lt, BufferView::UPDATE);
2151 lt->cursorDownParagraph(bv_);
2153 moveCursorUpdate(false);
2154 owner_->showState();
2160 LyXText * lt = bv_->getLyXText();
2162 if (!lt->selection.mark())
2164 update(lt, BufferView::UPDATE);
2167 moveCursorUpdate(false, false);
2168 owner_->showState();
2174 LyXText * lt = bv_->getLyXText();
2176 if (!lt->selection.mark())
2178 update(lt, BufferView::UPDATE);
2181 moveCursorUpdate(false, false);
2182 owner_->showState();
2188 LyXText * lt = bv_->getLyXText();
2190 if (!lt->selection.mark())
2192 update(lt, BufferView::SELECT|BufferView::FITCUR);
2193 lt->cursorHome(bv_);
2195 moveCursorUpdate(false);
2196 owner_->showState();
2202 LyXText * lt = bv_->getLyXText();
2204 if (!lt->selection.mark())
2207 BufferView::SELECT|BufferView::FITCUR);
2210 moveCursorUpdate(false);
2211 owner_->showState();
2215 case LFUN_SHIFT_TAB:
2218 LyXText * lt = bv_->getLyXText();
2220 if (!lt->selection.mark())
2223 BufferView::SELECT|BufferView::FITCUR);
2226 moveCursorUpdate(false);
2227 owner_->showState();
2231 case LFUN_WORDRIGHT:
2233 LyXText * lt = bv_->getLyXText();
2235 if (!lt->selection.mark())
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2239 lt->cursorLeftOneWord(bv_);
2241 lt->cursorRightOneWord(bv_);
2243 moveCursorUpdate(false);
2244 owner_->showState();
2250 LyXText * lt = bv_->getLyXText();
2252 if (!lt->selection.mark())
2254 update(lt, BufferView::SELECT|BufferView::FITCUR);
2255 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2256 lt->cursorRightOneWord(bv_);
2258 lt->cursorLeftOneWord(bv_);
2260 moveCursorUpdate(false);
2261 owner_->showState();
2265 case LFUN_BEGINNINGBUF:
2267 LyXText * lt = bv_->getLyXText();
2269 if (!lt->selection.mark())
2272 BufferView::SELECT|BufferView::FITCUR);
2275 moveCursorUpdate(false);
2276 owner_->showState();
2282 LyXText * lt = bv_->getLyXText();
2284 if (!lt->selection.mark())
2287 BufferView::SELECT|BufferView::FITCUR);
2288 lt->cursorBottom(bv_);
2290 moveCursorUpdate(false);
2291 owner_->showState();
2295 /* cursor selection ---------------------------- */
2298 LyXText * lt = bv_->getLyXText();
2301 BufferView::SELECT|BufferView::FITCUR);
2302 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2303 lt->cursorLeft(bv_);
2305 lt->cursorRight(bv_);
2307 moveCursorUpdate(true);
2308 owner_->showState();
2314 LyXText * lt = bv_->getLyXText();
2317 BufferView::SELECT|BufferView::FITCUR);
2318 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2319 lt->cursorRight(bv_);
2321 lt->cursorLeft(bv_);
2323 moveCursorUpdate(true);
2324 owner_->showState();
2330 LyXText * lt = bv_->getLyXText();
2333 BufferView::SELECT|BufferView::FITCUR);
2334 lt->cursorUp(bv_, true);
2336 moveCursorUpdate(true);
2337 owner_->showState();
2343 LyXText * lt = bv_->getLyXText();
2346 BufferView::SELECT|BufferView::FITCUR);
2347 lt->cursorDown(bv_, true);
2349 moveCursorUpdate(true);
2350 owner_->showState();
2354 case LFUN_UP_PARAGRAPHSEL:
2356 LyXText * lt = bv_->getLyXText();
2359 BufferView::SELECT|BufferView::FITCUR);
2360 lt->cursorUpParagraph(bv_);
2362 moveCursorUpdate(true);
2363 owner_->showState();
2367 case LFUN_DOWN_PARAGRAPHSEL:
2369 LyXText * lt = bv_->getLyXText();
2372 BufferView::SELECT|BufferView::FITCUR);
2373 lt->cursorDownParagraph(bv_);
2375 moveCursorUpdate(true);
2376 owner_->showState();
2382 LyXText * lt = bv_->getLyXText();
2384 update(lt, BufferView::SELECT|BufferView::FITCUR);
2387 moveCursorUpdate(true);
2388 owner_->showState();
2394 LyXText * lt = bv_->getLyXText();
2396 update(lt, BufferView::SELECT|BufferView::FITCUR);
2399 moveCursorUpdate(true);
2400 owner_->showState();
2406 LyXText * lt = bv_->getLyXText();
2408 update(lt, BufferView::SELECT|BufferView::FITCUR);
2409 lt->cursorHome(bv_);
2411 moveCursorUpdate(true);
2412 owner_->showState();
2418 LyXText * lt = bv_->getLyXText();
2420 update(lt, BufferView::SELECT|BufferView::FITCUR);
2423 moveCursorUpdate(true);
2424 owner_->showState();
2428 case LFUN_WORDRIGHTSEL:
2430 LyXText * lt = bv_->getLyXText();
2432 update(lt, BufferView::SELECT|BufferView::FITCUR);
2433 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2434 lt->cursorLeftOneWord(bv_);
2436 lt->cursorRightOneWord(bv_);
2438 moveCursorUpdate(true);
2439 owner_->showState();
2443 case LFUN_WORDLEFTSEL:
2445 LyXText * lt = bv_->getLyXText();
2447 update(lt, BufferView::SELECT|BufferView::FITCUR);
2448 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2449 lt->cursorRightOneWord(bv_);
2451 lt->cursorLeftOneWord(bv_);
2453 moveCursorUpdate(true);
2454 owner_->showState();
2458 case LFUN_BEGINNINGBUFSEL:
2460 LyXText * lt = bv_->getLyXText();
2462 if (lt->inset_owner)
2464 update(lt, BufferView::SELECT|BufferView::FITCUR);
2467 moveCursorUpdate(true);
2468 owner_->showState();
2472 case LFUN_ENDBUFSEL:
2474 LyXText * lt = bv_->getLyXText();
2476 if (lt->inset_owner)
2479 BufferView::SELECT|BufferView::FITCUR);
2480 lt->cursorBottom(bv_);
2482 moveCursorUpdate(true);
2483 owner_->showState();
2487 // --- text changing commands ------------------------
2488 case LFUN_BREAKLINE:
2490 LyXText * lt = bv_->getLyXText();
2493 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2496 | BufferView::FITCUR
2497 | BufferView::CHANGE);
2498 lt->setCursor(bv_, lt->cursor.par(), lt->cursor.pos());
2499 moveCursorUpdate(false);
2503 case LFUN_PROTECTEDSPACE:
2505 LyXText * lt = bv_->getLyXText();
2507 LyXLayout const & style = tclass[lt->cursor.par()->layout()];
2509 if (style.free_spacing) {
2510 lt->insertChar(bv_, ' ');
2513 | BufferView::FITCUR
2514 | BufferView::CHANGE);
2516 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2518 moveCursorUpdate(false);
2524 LyXText * lt = bv_->getLyXText();
2526 if (lt->selection.mark()) {
2530 | BufferView::FITCUR);
2531 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2534 lt->selection.mark(true);
2537 | BufferView::FITCUR);
2538 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2540 lt->selection.cursor = lt->cursor;
2546 LyXText * lt = bv_->getLyXText();
2548 if (!lt->selection.set()) {
2550 lt->selection.cursor = lt->cursor;
2553 | BufferView::FITCUR
2554 | BufferView::CHANGE);
2555 // It is possible to make it a lot faster still
2556 // just comment out the line below...
2561 moveCursorUpdate(false);
2562 owner_->showState();
2567 case LFUN_DELETE_SKIP:
2569 LyXText * lt = bv_->getLyXText();
2571 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2573 LyXCursor cursor = lt->cursor;
2575 if (!lt->selection.set()) {
2576 if (cursor.pos() == cursor.par()->size()) {
2577 lt->cursorRight(bv_);
2578 cursor = lt->cursor;
2579 if (cursor.pos() == 0
2580 && !(cursor.par()->params().spaceTop()
2581 == VSpace (VSpace::NONE))) {
2584 cursor.par()->params().lineTop(),
2585 cursor.par()->params().lineBottom(),
2586 cursor.par()->params().pagebreakTop(),
2587 cursor.par()->params().pagebreakBottom(),
2588 VSpace(VSpace::NONE),
2589 cursor.par()->params().spaceBottom(),
2590 cursor.par()->params().spacing(),
2591 cursor.par()->params().align(),
2592 cursor.par()->params().labelWidthString(), 0);
2593 lt->cursorLeft(bv_);
2596 | BufferView::FITCUR
2597 | BufferView::CHANGE);
2599 lt->cursorLeft(bv_);
2601 lt->selection.cursor = lt->cursor;
2604 | BufferView::FITCUR
2605 | BufferView::CHANGE);
2609 lt->selection.cursor = lt->cursor;
2612 | BufferView::FITCUR
2613 | BufferView::CHANGE);
2621 /* -------> Delete word forward. */
2622 case LFUN_DELETE_WORD_FORWARD:
2623 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2624 bv_->getLyXText()->deleteWordForward(bv_);
2625 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2626 moveCursorUpdate(false);
2627 owner_->showState();
2630 /* -------> Delete word backward. */
2631 case LFUN_DELETE_WORD_BACKWARD:
2633 LyXText * lt = bv_->getLyXText();
2635 update(lt, BufferView::SELECT|BufferView::FITCUR);
2636 lt->deleteWordBackward(bv_);
2639 | BufferView::FITCUR
2640 | BufferView::CHANGE);
2641 moveCursorUpdate(false);
2642 owner_->showState();
2646 /* -------> Kill to end of line. */
2647 case LFUN_DELETE_LINE_FORWARD:
2649 LyXText * lt = bv_->getLyXText();
2651 update(lt, BufferView::SELECT|BufferView::FITCUR);
2652 lt->deleteLineForward(bv_);
2655 | BufferView::FITCUR
2656 | BufferView::CHANGE);
2657 moveCursorUpdate(false);
2661 /* -------> Set mark off. */
2664 LyXText * lt = bv_->getLyXText();
2667 update(lt, BufferView::SELECT|BufferView::FITCUR);
2668 lt->selection.cursor = lt->cursor;
2669 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2673 /* -------> Set mark on. */
2676 LyXText * lt = bv_->getLyXText();
2679 lt->selection.mark(true);
2680 update(lt, BufferView::SELECT|BufferView::FITCUR);
2681 lt->selection.cursor = lt->cursor;
2682 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2686 case LFUN_BACKSPACE:
2688 LyXText * lt = bv_->getLyXText();
2690 if (!lt->selection.set()) {
2691 if (owner_->getIntl()->getTrans().backspace()) {
2693 lt->selection.cursor = lt->cursor;
2696 | BufferView::FITCUR
2697 | BufferView::CHANGE);
2698 // It is possible to make it a lot faster still
2699 // just comment out the line below...
2705 owner_->showState();
2710 case LFUN_BACKSPACE_SKIP:
2712 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2713 LyXText * lt = bv_->getLyXText();
2715 LyXCursor cursor = lt->cursor;
2717 if (!lt->selection.set()) {
2718 if (cursor.pos() == 0
2719 && !(cursor.par()->params().spaceTop()
2720 == VSpace (VSpace::NONE))) {
2723 cursor.par()->params().lineTop(),
2724 cursor.par()->params().lineBottom(),
2725 cursor.par()->params().pagebreakTop(),
2726 cursor.par()->params().pagebreakBottom(),
2727 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2728 cursor.par()->params().spacing(),
2729 cursor.par()->params().align(),
2730 cursor.par()->params().labelWidthString(), 0);
2733 | BufferView::FITCUR
2734 | BufferView::CHANGE);
2737 lt->selection.cursor = cursor;
2740 | BufferView::FITCUR
2741 | BufferView::CHANGE);
2748 case LFUN_BREAKPARAGRAPH:
2750 LyXText * lt = bv_->getLyXText();
2753 lt->breakParagraph(bv_, 0);
2756 | BufferView::FITCUR
2757 | BufferView::CHANGE);
2758 lt->selection.cursor = lt->cursor;
2760 owner_->showState();
2764 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2766 LyXText * lt = bv_->getLyXText();
2769 lt->breakParagraph(bv_, 1);
2772 | BufferView::FITCUR
2773 | BufferView::CHANGE);
2774 lt->selection.cursor = lt->cursor;
2776 owner_->showState();
2780 case LFUN_BREAKPARAGRAPH_SKIP:
2782 // When at the beginning of a paragraph, remove
2783 // indentation and add a "defskip" at the top.
2784 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2785 LyXText * lt = bv_->getLyXText();
2787 LyXCursor cursor = lt->cursor;
2790 if (cursor.pos() == 0) {
2791 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2794 cursor.par()->params().lineTop(),
2795 cursor.par()->params().lineBottom(),
2796 cursor.par()->params().pagebreakTop(),
2797 cursor.par()->params().pagebreakBottom(),
2798 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2799 cursor.par()->params().spacing(),
2800 cursor.par()->params().align(),
2801 cursor.par()->params().labelWidthString(), 1);
2802 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2806 lt->breakParagraph(bv_, 0);
2807 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2812 | BufferView::FITCUR
2813 | BufferView::CHANGE);
2814 lt->selection.cursor = cursor;
2816 owner_->showState();
2820 case LFUN_PARAGRAPH_SPACING:
2822 LyXText * lt = bv_->getLyXText();
2824 Paragraph * par = lt->cursor.par();
2825 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2826 float cur_value = 1.0;
2827 if (cur_spacing == Spacing::Other) {
2828 cur_value = par->params().spacing().getValue();
2831 istringstream istr(argument.c_str());
2835 Spacing::Space new_spacing = cur_spacing;
2836 float new_value = cur_value;
2838 lyxerr << "Missing argument to `paragraph-spacing'"
2840 } else if (tmp == "single") {
2841 new_spacing = Spacing::Single;
2842 } else if (tmp == "onehalf") {
2843 new_spacing = Spacing::Onehalf;
2844 } else if (tmp == "double") {
2845 new_spacing = Spacing::Double;
2846 } else if (tmp == "other") {
2847 new_spacing = Spacing::Other;
2850 lyxerr << "new_value = " << tmpval << endl;
2853 } else if (tmp == "default") {
2854 new_spacing = Spacing::Default;
2856 lyxerr << _("Unknown spacing argument: ")
2857 << argument << endl;
2859 if (cur_spacing != new_spacing || cur_value != new_value) {
2860 par->params().spacing(Spacing(new_spacing, new_value));
2861 lt->redoParagraph(bv_);
2864 | BufferView::FITCUR
2865 | BufferView::CHANGE);
2870 case LFUN_INSET_TOGGLE:
2872 LyXText * lt = bv_->getLyXText();
2875 update(lt, BufferView::SELECT|BufferView::FITCUR);
2876 lt->toggleInset(bv_);
2877 update(lt, BufferView::SELECT|BufferView::FITCUR);
2889 InsetCommandParams p;
2890 if (action == LFUN_HTMLURL)
2891 p.setCmdName("htmlurl");
2893 p.setCmdName("url");
2894 owner_->getDialogs()->createUrl(p.getAsString());
2898 case LFUN_INSERT_URL:
2900 InsetCommandParams p;
2901 p.setFromString(argument);
2903 InsetUrl * inset = new InsetUrl(p);
2904 if (!insertInset(inset))
2907 updateInset(inset, true);
2911 case LFUN_INSET_ERT:
2912 insertAndEditInset(new InsetERT(buffer_->params));
2915 case LFUN_INSET_EXTERNAL:
2916 insertAndEditInset(new InsetExternal);
2919 case LFUN_INSET_FOOTNOTE:
2920 insertAndEditInset(new InsetFoot(buffer_->params));
2923 case LFUN_INSET_MARGINAL:
2924 insertAndEditInset(new InsetMarginal(buffer_->params));
2927 case LFUN_INSET_MINIPAGE:
2928 insertAndEditInset(new InsetMinipage(buffer_->params));
2931 case LFUN_INSERT_NOTE:
2932 insertAndEditInset(new InsetNote(buffer_->params));
2935 case LFUN_INSET_FLOAT:
2936 // check if the float type exist
2937 if (floatList.typeExist(argument)) {
2938 insertAndEditInset(new InsetFloat(buffer_->params,
2941 lyxerr << "Non-existent float type: "
2942 << argument << endl;
2946 case LFUN_INSET_WIDE_FLOAT:
2947 // check if the float type exist
2948 if (floatList.typeExist(argument)) {
2949 InsetFloat * new_inset =
2950 new InsetFloat(buffer_->params, argument);
2951 new_inset->wide(true);
2952 insertAndEditInset(new_inset);
2954 lyxerr << "Non-existent float type: "
2955 << argument << endl;
2960 case LFUN_INSET_LIST:
2961 insertAndEditInset(new InsetList);
2964 case LFUN_INSET_THEOREM:
2965 insertAndEditInset(new InsetTheorem);
2969 case LFUN_INSET_CAPTION:
2971 // Do we have a locking inset...
2972 if (bv_->theLockingInset()) {
2973 lyxerr << "Locking inset code: "
2974 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2975 InsetCaption * new_inset =
2976 new InsetCaption(buffer_->params);
2977 new_inset->setOwner(bv_->theLockingInset());
2978 new_inset->setAutoBreakRows(true);
2979 new_inset->setDrawFrame(0, InsetText::LOCKED);
2980 new_inset->setFrameColor(0, LColor::captionframe);
2981 if (insertInset(new_inset))
2982 new_inset->edit(bv_);
2989 case LFUN_INSET_TABULAR:
2993 if (!argument.empty())
2994 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2995 InsetTabular * new_inset =
2996 new InsetTabular(*buffer_, r, c);
2998 bv_->getLyXText()->real_current_font.isRightToLeft();
2999 if (!open_new_inset(new_inset, rtl))
3004 // --- lyxserver commands ----------------------------
3006 case LFUN_CHARATCURSOR:
3008 pos_type pos = bv_->getLyXText()->cursor.pos();
3009 if (pos < bv_->getLyXText()->cursor.par()->size())
3010 owner_->getLyXFunc()->setMessage(
3011 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
3013 owner_->getLyXFunc()->setMessage("EOF");
3018 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
3020 + tostr(bv_->getLyXText()->cursor.y()));
3027 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
3028 lyxerr << "SETXY: Could not parse coordinates in '"
3029 << argument << std::endl;
3031 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
3035 case LFUN_GETLAYOUT:
3036 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
3041 LyXFont & font = bv_->getLyXText()->current_font;
3042 if (font.shape() == LyXFont::ITALIC_SHAPE)
3043 owner_->getLyXFunc()->setMessage("E");
3044 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
3045 owner_->getLyXFunc()->setMessage("N");
3047 owner_->getLyXFunc()->setMessage("0");
3052 // --- accented characters ---------------------------
3055 case LFUN_CIRCUMFLEX:
3065 case LFUN_SPECIAL_CARON:
3068 case LFUN_HUNG_UMLAUT:
3071 if (argument.empty()) {
3073 owner_->getLyXFunc()->handleKeyFunc(action);
3075 owner_->getLyXFunc()->handleKeyFunc(action);
3076 owner_->getIntl()->getTrans()
3077 .TranslateAndInsert(argument[0], bv_->getLyXText());
3078 update(bv_->getLyXText(),
3080 | BufferView::FITCUR
3081 | BufferView::CHANGE);
3085 case LFUN_MATH_MACRO:
3086 mathDispatchMathMacro(bv_, argument);
3089 case LFUN_MATH_DELIM:
3090 mathDispatchMathDelim(bv_, argument);
3093 case LFUN_INSERT_MATRIX:
3094 mathDispatchInsertMatrix(bv_, argument);
3097 case LFUN_INSERT_MATH:
3098 mathDispatchInsertMath(bv_, argument);
3101 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
3102 mathDispatchMathImportSelection(bv_, argument);
3105 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
3106 mathDispatchMathDisplay(bv_, argument);
3109 case LFUN_MATH_MODE: // Open or create an inlined math inset
3110 mathDispatchMathMode(bv_, argument);
3113 case LFUN_GREEK: // Insert a single greek letter
3114 mathDispatchGreek(bv_, argument);
3117 case LFUN_CITATION_INSERT:
3119 InsetCommandParams p;
3120 p.setFromString(argument);
3122 InsetCitation * inset = new InsetCitation(p);
3123 if (!insertInset(inset))
3126 updateInset(inset, true);
3130 case LFUN_INSERT_BIBTEX:
3132 // ale970405+lasgoutt970425
3133 // The argument can be up to two tokens separated
3134 // by a space. The first one is the bibstyle.
3135 string const db = token(argument, ' ', 0);
3136 string const bibstyle = token(argument, ' ', 1);
3138 InsetCommandParams p("BibTeX", db, bibstyle);
3139 InsetBibtex * inset = new InsetBibtex(p);
3141 if (insertInset(inset)) {
3142 if (argument.empty())
3149 // BibTeX data bases
3150 case LFUN_BIBDB_ADD:
3152 InsetBibtex * inset =
3153 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3155 inset->addDatabase(argument);
3160 case LFUN_BIBDB_DEL:
3162 InsetBibtex * inset =
3163 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3165 inset->delDatabase(argument);
3170 case LFUN_BIBTEX_STYLE:
3172 InsetBibtex * inset =
3173 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3175 inset->setOptions(argument);
3180 case LFUN_INDEX_CREATE:
3182 InsetCommandParams p("index");
3183 if (argument.empty()) {
3184 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3185 p.setContents(idxstring);
3187 p.setContents(argument);
3190 owner_->getDialogs()->createIndex(p.getAsString());
3194 case LFUN_INDEX_INSERT:
3196 InsetCommandParams p;
3197 p.setFromString(argument);
3198 InsetIndex * inset = new InsetIndex(p);
3200 if (!insertInset(inset))
3203 updateInset(inset, true);
3207 case LFUN_INDEX_INSERT_LAST:
3209 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3210 if (!idxstring.empty()) {
3211 owner_->message(_("Word `")
3212 + idxstring + _(("' indexed.")));
3213 InsetCommandParams p("index", idxstring);
3214 InsetIndex * inset = new InsetIndex(p);
3216 if (!insertInset(inset))
3219 updateInset(inset, true);
3224 case LFUN_INDEX_PRINT:
3226 InsetCommandParams p("printindex");
3227 Inset * inset = new InsetPrintIndex(p);
3228 if (!insertInset(inset, tclass.defaultLayoutName()))
3233 case LFUN_PARENTINSERT:
3235 InsetCommandParams p("lyxparent", argument);
3236 Inset * inset = new InsetParent(p, *buffer_);
3237 if (!insertInset(inset, tclass.defaultLayoutName()))
3243 case LFUN_CHILD_INSERT:
3245 InsetInclude::Params p;
3246 p.cparams.setFromString(argument);
3247 p.masterFilename_ = buffer_->fileName();
3249 InsetInclude * inset = new InsetInclude(p);
3250 if (!insertInset(inset))
3253 updateInset(inset, true);
3254 bv_->owner()->getDialogs()->showInclude(inset);
3259 case LFUN_FLOAT_LIST:
3260 if (floatList.typeExist(argument)) {
3261 Inset * inset = new InsetFloatList(argument);
3262 if (!insertInset(inset, tclass.defaultLayoutName()))
3265 lyxerr << "Non-existent float type: "
3266 << argument << endl;
3270 case LFUN_THESAURUS_ENTRY:
3272 string arg = argument;
3275 arg = bv_->getLyXText()->selectionAsString(buffer_,
3279 if (arg.size() > 100 || arg.empty()) {
3280 // Get word or selection
3281 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3282 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3283 // FIXME: where is getLyXText()->unselect(bv_) ?
3287 bv_->owner()->getDialogs()->showThesaurus(arg);
3291 case LFUN_SELFINSERT:
3293 if (argument.empty()) break;
3295 /* Automatically delete the currently selected
3296 * text and replace it with what is being
3297 * typed in now. Depends on lyxrc settings
3298 * "auto_region_delete", which defaults to
3301 LyXText * lt = bv_->getLyXText();
3303 if (lyxrc.auto_region_delete) {
3304 if (lt->selection.set()) {
3305 lt->cutSelection(bv_, false, false);
3308 | BufferView::FITCUR
3309 | BufferView::CHANGE);
3311 workarea().haveSelection(false);
3315 LyXFont const old_font(lt->real_current_font);
3317 string::const_iterator cit = argument.begin();
3318 string::const_iterator end = argument.end();
3319 for (; cit != end; ++cit) {
3320 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3325 | BufferView::FITCUR
3326 | BufferView::CHANGE);
3328 lt->selection.cursor = lt->cursor;
3329 moveCursorUpdate(false);
3331 // real_current_font.number can change so we need to
3332 // update the minibuffer
3333 if (old_font != lt->real_current_font)
3334 owner_->showState();
3339 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3341 time_t now_time_t = time(NULL);
3342 struct tm * now_tm = localtime(&now_time_t);
3343 setlocale(LC_TIME, "");
3345 if (!argument.empty())
3348 arg = lyxrc.date_insert_format;
3350 int const datetmp_len =
3351 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3353 LyXText * lt = bv_->getLyXText();
3355 for (int i = 0; i < datetmp_len; i++) {
3356 lt->insertChar(bv_, datetmp[i]);
3359 | BufferView::FITCUR
3360 | BufferView::CHANGE);
3363 lt->selection.cursor = lt->cursor;
3364 moveCursorUpdate(false);
3368 case LFUN_UNKNOWN_ACTION:
3369 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3380 void BufferView::Pimpl::newline()
3383 LyXText * lt = bv_->getLyXText();
3387 | BufferView::FITCUR);
3388 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3391 | BufferView::FITCUR
3392 | BufferView::CHANGE);
3397 void BufferView::Pimpl::hfill()
3400 LyXText * lt = bv_->getLyXText();
3404 | BufferView::FITCUR);
3405 lt->insertChar(bv_, Paragraph::META_HFILL);
3408 | BufferView::FITCUR
3409 | BufferView::CHANGE);
3414 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3417 LyXText * lt = bv_->getLyXText();
3420 update(lt, BufferView::SELECT|BufferView::FITCUR);
3421 InsetSpecialChar * new_inset =
3422 new InsetSpecialChar(kind);
3423 if (!insertInset(new_inset))
3426 updateInset(new_inset, true);
3431 void BufferView::Pimpl::smartQuote()
3433 LyXText const * lt = bv_->getLyXText();
3434 Paragraph const * par = lt->cursor.par();
3435 pos_type pos = lt->cursor.pos();
3439 || (par->isInset(pos - 1)
3440 && par->getInset(pos - 1)->isSpace()))
3443 c = par->getChar(pos - 1);
3448 LyXLayout const & style =
3449 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3451 if (style.pass_thru ||
3452 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3453 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3457 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3459 if (insertInset(inset))
3466 // Open and lock an updatable inset
3467 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3469 LyXText * lt = bv_->getLyXText();
3473 if (!insertInset(new_inset)) {
3477 new_inset->edit(bv_, !behind);
3482 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3484 // if we are in a locking inset we should try to insert the
3485 // inset there otherwise this is a illegal function now
3486 if (bv_->theLockingInset()) {
3487 if (bv_->theLockingInset()->insetAllowed(inset))
3488 return bv_->theLockingInset()->insertInset(bv_, inset);
3492 // not quite sure if we want this...
3493 setCursorParUndo(bv_);
3496 beforeChange(bv_->text);
3497 if (!lout.empty()) {
3498 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3499 bv_->text->breakParagraph(bv_);
3500 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3502 if (bv_->text->cursor.par()->size()) {
3503 bv_->text->cursorLeft(bv_);
3505 bv_->text->breakParagraph(bv_);
3506 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3510 LyXTextClass const & tclass =
3511 textclasslist[buffer_->params.textclass];
3512 bool hasLayout = tclass.hasLayout(lres);
3513 string lay = tclass.defaultLayoutName();
3515 if (hasLayout != false) {
3519 // layout not fount using default
3520 lay = tclass.defaultLayoutName();
3523 bv_->text->setLayout(bv_, lay);
3525 bv_->text->setParagraph(bv_, 0, 0,
3527 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3532 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3535 bv_->text->insertInset(bv_, inset);
3536 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3543 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3545 if (!inset || !available())
3548 // first check for locking insets
3549 if (bv_->theLockingInset()) {
3550 if (bv_->theLockingInset() == inset) {
3551 if (bv_->text->updateInset(bv_, inset)) {
3554 buffer_->markDirty();
3559 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3560 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3563 buffer_->markDirty();
3571 // then check if the inset is a top_level inset (has no owner)
3572 // if yes do the update as always otherwise we have to update the
3573 // toplevel inset where this inset is inside
3574 Inset * tl_inset = inset;
3575 while(tl_inset->owner())
3576 tl_inset = tl_inset->owner();
3578 if (tl_inset == inset) {
3579 update(bv_->text, BufferView::UPDATE);
3580 if (bv_->text->updateInset(bv_, inset)) {
3584 | BufferView::FITCUR
3585 | BufferView::CHANGE);
3587 update(bv_->text, SELECT);
3591 } else if (static_cast<UpdatableInset *>(tl_inset)
3592 ->updateInsetInInset(bv_, inset))
3594 if (bv_->text->updateInset(bv_, tl_inset)) {
3602 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3605 if (!available()) return;
3608 beforeChange(bv_->text);
3609 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3611 LyXCursor const & cursor = bv_->text->cursor;
3615 cursor.par()->isInset(cursor.pos())) {
3616 Inset const * inset = cursor.par()->getInset(cursor.pos());
3617 if (find(codes.begin(), codes.end(), inset->lyxCode())
3620 static_cast<InsetCommand const *>(inset)->getContents();
3624 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3625 if (bv_->text->cursor.pos()
3626 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3627 LyXCursor tmp = bv_->text->cursor;
3628 bv_->text->cursor.par(bv_->text->ownerParagraph());
3629 bv_->text->cursor.pos(0);
3630 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3631 bv_->text->cursor = tmp;
3632 bv_->owner()->message(_("No more insets"));
3635 bv_->owner()->message(_("No more insets"));
3638 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3639 bv_->text->selection.cursor = bv_->text->cursor;
3643 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3645 gotoInset(vector<Inset::Code>(1, code), same_content);