7 #include "BufferView_pimpl.h"
12 #include "paragraph.h"
14 #include "commandtags.h"
18 #include "bufferview_funcs.h"
19 #include "TextCache.h"
20 #include "bufferlist.h"
21 #include "lyx_gui_misc.h"
24 // added for Dispatch functions
27 #include "FloatList.h"
29 #include "ParagraphParameters.h"
30 #include "undo_funcs.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Alert.h"
34 #include "frontends/FileDialog.h"
36 #include "insets/insetbib.h"
37 #include "insets/insettext.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetnote.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetlist.h"
59 #include "insets/insetcaption.h"
60 #include "insets/insetfloatlist.h"
61 #include "insets/insetspecialchar.h"
63 #include "mathed/formulabase.h"
65 #include "support/LAssert.h"
66 #include "support/lstrings.h"
67 #include "support/filetools.h"
68 #include "support/lyxfunctional.h"
76 extern lyx::layout_type current_layout;
88 using lyx::layout_type;
89 using lyx::textclass_type;
91 /* the selection possible is needed, that only motion events are
92 * used, where the bottom press event was on the drawing area too */
93 bool selection_possible = false;
95 extern BufferList bufferlist;
96 extern char ascii_type;
98 extern void sigchldchecker(pid_t pid, int * status);
99 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
104 const unsigned int saved_positions_num = 20;
109 XSync(fl_get_display(), 0);
113 void SetXtermCursor(Window win)
115 static Cursor cursor;
116 static bool cursor_undefined = true;
117 if (cursor_undefined){
118 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
119 XFlush(fl_get_display());
120 cursor_undefined = false;
122 XDefineCursor(fl_get_display(), win, cursor);
123 XFlush(fl_get_display());
129 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
130 int xpos, int ypos, int width, int height)
131 : bv_(b), owner_(o), buffer_(0),
132 current_scrollbar_value(0), cursor_timeout(400),
133 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
137 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
138 workarea_.workAreaExpose
139 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
140 workarea_.workAreaEnter
141 .connect(slot(this, &BufferView::Pimpl::enterView));
142 workarea_.workAreaLeave
143 .connect(slot(this, &BufferView::Pimpl::leaveView));
144 workarea_.workAreaButtonPress
145 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
146 workarea_.workAreaButtonRelease
148 &BufferView::Pimpl::workAreaButtonRelease));
149 workarea_.workAreaMotionNotify
150 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
151 workarea_.workAreaDoubleClick
152 .connect(slot(this, &BufferView::Pimpl::doubleClick));
153 workarea_.workAreaTripleClick
154 .connect(slot(this, &BufferView::Pimpl::tripleClick));
155 workarea_.workAreaKeyPress
156 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
158 cursor_timeout.timeout.connect(slot(this,
159 &BufferView::Pimpl::cursorToggle));
160 cursor_timeout.start();
161 workarea_.setFocus();
162 saved_positions.resize(saved_positions_num);
166 Painter & BufferView::Pimpl::painter()
168 return workarea_.getPainter();
172 void BufferView::Pimpl::buffer(Buffer * b)
174 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
178 buffer_->delUser(bv_);
180 // Put the old text into the TextCache, but
181 // only if the buffer is still loaded.
182 // Also set the owner of the test to 0
183 // bv_->text->owner(0);
184 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
185 if (lyxerr.debugging())
186 textcache.show(lyxerr, "BufferView::buffer");
191 // Set current buffer
194 if (bufferlist.getState() == BufferList::CLOSING) return;
197 // screen is always deleted when the buffer is changed.
200 // If we are closing the buffer, use the first buffer as current
202 buffer_ = bufferlist.first();
206 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
207 buffer_->addUser(bv_);
208 // If we don't have a text object for this, we make one
209 if (bv_->text == 0) {
210 resizeCurrentBuffer();
215 bv_->text->first = screen_->topCursorVisible(bv_->text);
216 owner_->updateMenubar();
217 owner_->updateToolbar();
218 // Similarly, buffer-dependent dialogs should be updated or
219 // hidden. This should go here because some dialogs (eg ToC)
220 // require bv_->text.
221 owner_->getDialogs()->updateBufferDependent(true);
225 lyxerr[Debug::INFO] << " No Buffer!" << endl;
226 owner_->updateMenubar();
227 owner_->updateToolbar();
228 owner_->getDialogs()->hideBufferDependent();
232 // Also remove all remaining text's from the testcache.
233 // (there should not be any!) (if there is any it is a
235 if (lyxerr.debugging())
236 textcache.show(lyxerr, "buffer delete all");
239 // should update layoutchoice even if we don't have a buffer.
240 owner_->updateLayoutChoice();
242 owner_->updateWindowTitle();
246 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
248 workarea_.resize(xpos, ypos, width, height);
249 update(bv_->text, SELECT);
254 void BufferView::Pimpl::resize()
257 resizeCurrentBuffer();
261 void BufferView::Pimpl::redraw()
263 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
268 bool BufferView::Pimpl::fitCursor()
270 lyx::Assert(screen_.get());
274 if (bv_->theLockingInset()) {
275 bv_->theLockingInset()->fitInsetCursor(bv_);
278 ret = screen_->fitCursor(bv_->text, bv_);
281 bv_->owner()->getDialogs()->updateParagraph();
288 void BufferView::Pimpl::redoCurrentBuffer()
290 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
291 if (buffer_ && bv_->text) {
293 owner_->updateLayoutChoice();
298 int BufferView::Pimpl::resizeCurrentBuffer()
300 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
303 Paragraph * selstartpar = 0;
304 Paragraph * selendpar = 0;
305 UpdatableInset * the_locking_inset = 0;
308 pos_type selstartpos = 0;
309 pos_type selendpos = 0;
310 bool selection = false;
311 bool mark_set = false;
313 owner_->prohibitInput();
315 owner_->message(_("Formatting document..."));
318 par = bv_->text->cursor.par();
319 pos = bv_->text->cursor.pos();
320 selstartpar = bv_->text->selection.start.par();
321 selstartpos = bv_->text->selection.start.pos();
322 selendpar = bv_->text->selection.end.par();
323 selendpos = bv_->text->selection.end.pos();
324 selection = bv_->text->selection.set();
325 mark_set = bv_->text->selection.mark();
326 the_locking_inset = bv_->theLockingInset();
328 bv_->text = new LyXText(bv_);
329 bv_->text->init(bv_);
331 // See if we have a text in TextCache that fits
332 // the new buffer_ with the correct width.
333 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
335 if (lyxerr.debugging()) {
336 lyxerr << "Found a LyXText that fits:\n";
337 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
339 // Set the owner of the newly found text
340 // bv_->text->owner(bv_);
341 if (lyxerr.debugging())
342 textcache.show(lyxerr, "resizeCurrentBuffer");
344 bv_->text = new LyXText(bv_);
345 bv_->text->init(bv_);
351 bv_->text->selection.set(true);
352 /* at this point just to avoid the Delete-Empty-Paragraph
353 * Mechanism when setting the cursor */
354 bv_->text->selection.mark(mark_set);
356 bv_->text->setCursor(bv_, selstartpar, selstartpos);
357 bv_->text->selection.cursor = bv_->text->cursor;
358 bv_->text->setCursor(bv_, selendpar, selendpos);
359 bv_->text->setSelection(bv_);
360 bv_->text->setCursor(bv_, par, pos);
362 bv_->text->setCursor(bv_, par, pos);
363 bv_->text->selection.cursor = bv_->text->cursor;
364 bv_->text->selection.set(false);
366 // remake the inset locking
367 bv_->theLockingInset(the_locking_inset);
369 bv_->text->first = screen_->topCursorVisible(bv_->text);
371 buffer_->resizeInsets(bv_);
373 // this will scroll the screen such that the cursor becomes visible
378 owner_->allowInput();
380 /// clear the "Formatting Document" message
387 void BufferView::Pimpl::updateScreen()
389 // Regenerate the screen.
390 screen_.reset(new LyXScreen(workarea_));
394 void BufferView::Pimpl::updateScrollbar()
396 /* If the text is smaller than the working area, the scrollbar
397 * maximum must be the working area height. No scrolling will
400 workarea_.setScrollbar(0, 1.0);
404 long const text_height = bv_->text->height;
406 double const lineh = bv_->text->defaultHeight();
407 double const slider_size =
408 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
410 static long old_text_height = 0;
411 static double old_lineh = 0;
412 static double old_slider_size = 0;
414 if (text_height != old_text_height) {
415 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
416 old_text_height = text_height;
418 if (lineh != old_lineh) {
419 workarea_.setScrollbarIncrements(lineh);
422 if (current_scrollbar_value != bv_->text->first
423 || slider_size != old_slider_size) {
424 current_scrollbar_value = bv_->text->first;
425 workarea_.setScrollbar(current_scrollbar_value, slider_size);
426 old_slider_size = slider_size;
431 // Callback for scrollbar slider
432 void BufferView::Pimpl::scrollCB(double value)
434 if (!buffer_) return;
436 current_scrollbar_value = long(value);
437 if (current_scrollbar_value < 0)
438 current_scrollbar_value = 0;
443 screen_->draw(bv_->text, bv_, current_scrollbar_value);
445 if (!lyxrc.cursor_follows_scrollbar) {
450 LyXText * vbt = bv_->text;
452 int const height = vbt->defaultHeight();
453 int const first = static_cast<int>((bv_->text->first + height));
454 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
456 if (vbt->cursor.y() < first)
457 vbt->setCursorFromCoordinates(bv_, 0, first);
458 else if (vbt->cursor.y() > last)
459 vbt->setCursorFromCoordinates(bv_, 0, last);
465 int BufferView::Pimpl::scrollUp(long time)
467 if (!buffer_) return 0;
468 if (!screen_.get()) return 0;
470 double value = workarea_.getScrollbarValue();
472 if (value == 0) return 0;
474 float add_value = (bv_->text->defaultHeight()
475 + float(time) * float(time) * 0.125);
477 if (add_value > workarea_.height())
478 add_value = float(workarea_.height() -
479 bv_->text->defaultHeight());
486 workarea_.setScrollbarValue(value);
493 int BufferView::Pimpl::scrollDown(long time)
495 if (!buffer_) return 0;
496 if (!screen_.get()) return 0;
498 double value = workarea_.getScrollbarValue();
499 pair<float, float> p = workarea_.getScrollbarBounds();
500 double const max = p.second;
502 if (value == max) return 0;
504 float add_value = (bv_->text->defaultHeight()
505 + float(time) * float(time) * 0.125);
507 if (add_value > workarea_.height())
508 add_value = float(workarea_.height() -
509 bv_->text->defaultHeight());
516 workarea_.setScrollbarValue(value);
523 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
525 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
529 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
531 // Only use motion with button 1
532 if (!(state & Button1MotionMask))
535 if (!buffer_ || !screen_.get()) return;
537 // Check for inset locking
538 if (bv_->theLockingInset()) {
539 LyXCursor cursor = bv_->text->cursor;
540 LyXFont font = bv_->text->getFont(buffer_,
541 cursor.par(), cursor.pos());
542 int width = bv_->theLockingInset()->width(bv_, font);
543 int inset_x = font.isVisibleRightToLeft()
544 ? cursor.x() - width : cursor.x();
545 int start_x = inset_x + bv_->theLockingInset()->scroll();
546 bv_->theLockingInset()->
547 insetMotionNotify(bv_,
549 y - cursor.y() + bv_->text->first,
554 /* The test for not selection possible is needed, that only motion
555 events are used, where the bottom press event was on
556 the drawing area too */
557 if (!selection_possible)
560 screen_->hideCursor();
562 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
564 if (!bv_->text->selection.set())
565 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
567 bv_->text->setSelection(bv_);
568 screen_->toggleToggle(bv_->text, bv_);
571 screen_->showCursor(bv_->text, bv_);
578 // Single-click on work area
579 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
582 if (!buffer_ || !screen_.get()) return;
584 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
586 // ok ok, this is a hack.
587 if (button == 4 || button == 5) {
590 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
593 scrollDown(lyxrc.wheel_jump);
598 if (bv_->theLockingInset()) {
599 // We are in inset locking mode
601 /* Check whether the inset was hit. If not reset mode,
602 otherwise give the event to the inset */
603 if (inset_hit == bv_->theLockingInset()) {
604 bv_->theLockingInset()->
605 insetButtonPress(bv_,xpos, ypos,button);
608 bv_->unlockInset(bv_->theLockingInset());
613 selection_possible = true;
614 screen_->hideCursor();
616 int const screen_first = bv_->text->first;
618 // Middle button press pastes if we have a selection
619 bool paste_internally = false;
621 && bv_->text->selection.set()) {
622 owner_->getLyXFunc()->dispatch(LFUN_COPY);
623 paste_internally = true;
626 // Clear the selection
627 screen_->toggleSelection(bv_->text, bv_);
628 bv_->text->clearSelection();
629 bv_->text->fullRebreak(bv_);
631 screen_->update(bv_->text, bv_);
637 // Single left click in math inset?
638 if (isHighlyEditableInset(inset_hit)) {
639 // Highly editable inset, like math
640 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
641 selection_possible = false;
642 owner_->updateLayoutChoice();
643 owner_->message(inset->editMessage());
644 inset->insetButtonPress(bv_, xpos, ypos, button);
645 inset->edit(bv_, xpos, ypos, button);
649 // Right click on a footnote flag opens float menu
651 selection_possible = false;
655 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
656 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
658 bv_->text->selection.cursor = bv_->text->cursor;
659 bv_->text->cursor.x_fix(bv_->text->cursor.x());
661 owner_->updateLayoutChoice();
663 selection_possible = false;
666 // Insert primary selection with middle mouse
667 // if there is a local selection in the current buffer,
670 if (paste_internally)
671 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
673 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
675 selection_possible = false;
681 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
687 LyXText * text = bv_->getLyXText();
689 if (text->bv_owner && bv_->theLockingInset())
692 if (screen_.get() && button == 1) {
693 if (text->bv_owner) {
694 screen_->hideCursor();
695 screen_->toggleSelection(text, bv_);
696 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
697 screen_->toggleSelection(text, bv_, false);
699 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
701 /* This will fit the cursor on the screen
703 update(text, BufferView::SELECT|BufferView::FITCUR);
708 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
714 LyXText * text = bv_->getLyXText();
716 if (text->bv_owner && bv_->theLockingInset())
719 if (screen_.get() && (button == 1)) {
720 screen_->hideCursor();
721 screen_->toggleSelection(text, bv_);
722 text->cursorHome(bv_);
723 text->selection.cursor = text->cursor;
724 text->cursorEnd(bv_);
725 text->setSelection(bv_);
726 screen_->toggleSelection(text, bv_, false);
727 /* This will fit the cursor on the screen
729 update(text, BufferView::SELECT|BufferView::FITCUR);
734 void BufferView::Pimpl::enterView()
736 if (active() && available()) {
737 SetXtermCursor(workarea_.getWin());
738 using_xterm_cursor = true;
743 void BufferView::Pimpl::leaveView()
745 if (using_xterm_cursor) {
746 XUndefineCursor(fl_get_display(), workarea_.getWin());
747 using_xterm_cursor = false;
752 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
755 if (!buffer_ || !screen_.get()) return;
757 // If we hit an inset, we have the inset coordinates in these
758 // and inset_hit points to the inset. If we do not hit an
759 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
760 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
762 if (bv_->theLockingInset()) {
763 // We are in inset locking mode.
765 /* LyX does a kind of work-area grabbing for insets.
766 Only a ButtonPress Event outside the inset will
767 force a insetUnlock. */
768 bv_->theLockingInset()->
769 insetButtonRelease(bv_, x, y, button);
773 selection_possible = false;
781 // Did we hit an editable inset?
783 // Inset like error, notes and figures
784 selection_possible = false;
786 // if we reach this point with a selection, it
787 // must mean we are currently selecting.
788 // But we don't want to open the inset
789 // because that is annoying for the user.
790 // So just pretend we didn't hit it.
791 // this is OK because a "kosher" ButtonRelease
792 // will follow a ButtonPress that clears
794 // Note this also fixes selection drawing
795 // problems if we end up opening an inset
796 if (bv_->getLyXText()->selection.set())
799 // CHECK fix this proper in 0.13
800 // well, maybe 13.0 !!!!!!!!!
802 // Following a ref shouldn't issue
803 // a push on the undo-stack
804 // anylonger, now that we have
805 // keybindings for following
806 // references and returning from
807 // references. IMHO though, it
808 // should be the inset's own business
809 // to push or not push on the undo
810 // stack. They don't *have* to
811 // alter the document...
813 // ...or maybe the SetCursorParUndo()
814 // below isn't necessary at all anylonger?
815 if (inset_hit->lyxCode() == Inset::REF_CODE) {
816 setCursorParUndo(bv_);
819 owner_->message(inset_hit->editMessage());
821 if (isHighlyEditableInset(inset_hit)) {
822 // Highly editable inset, like math
823 UpdatableInset *inset = (UpdatableInset *)inset_hit;
824 inset->insetButtonRelease(bv_, x, y, button);
826 inset_hit->insetButtonRelease(bv_, x, y, button);
827 inset_hit->edit(bv_, x, y, button);
833 #warning variable c is set but never used. What is it good for?? (JMarc)
834 #warning isnt this code dead ?? "open a float" ??? (jbl)
836 // check whether we want to open a float
840 if (bv_->text->cursor.pos() <
841 bv_->text->cursor.par()->size()) {
842 c = bv_->text->cursor.par()->
843 getChar(bv_->text->cursor.pos());
845 if (bv_->text->cursor.pos() - 1 >= 0) {
846 c = bv_->text->cursor.par()->
847 getChar(bv_->text->cursor.pos() - 1);
850 selection_possible = false;
855 // Maybe we want to edit a bibitem ale970302
856 if (bv_->text->cursor.par()->bibkey && x < 20 +
857 bibitemMaxWidth(bv_, textclasslist.
859 params.textclass).defaultfont())) {
860 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
867 Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
869 Paragraph /*const*/ & par = *cursor.par();
870 pos_type const pos = cursor.pos();
872 lyx::Assert(par.getInset(pos));
874 Inset const & inset(*par.getInset(pos));
876 LyXFont const & font = text.getFont(buffer_, &par, pos);
878 int const width = inset.width(bv_, font);
879 int const inset_x = font.isVisibleRightToLeft()
880 ? (cursor.x() - width) : cursor.x();
883 inset_x + inset.scroll(),
885 cursor.y() - inset.ascent(bv_, font),
886 cursor.y() + inset.descent(bv_, font));
890 Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
892 pos_type const pos(cursor.pos());
893 Paragraph /*const*/ & par(*cursor.par());
895 if (pos >= par.size() || !par.isInset(pos)) {
899 Inset /*const*/ * inset = par.getInset(pos);
901 if (!isEditableInset(inset)) {
905 Box b(insetDimensions(text, cursor));
907 if (!b.contained(x, y)) {
911 text.setCursor(bv_, &par, pos, true);
914 // The origin of an inset is on the baseline
915 y -= (text.cursor.y());
921 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
926 int y_tmp = y + text->first;
929 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
931 Inset * inset(checkInset(*text, cursor, x, y_tmp));
938 // look at previous position
940 if (cursor.pos() == 0) {
945 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
947 inset = checkInset(*text, cursor, x, y_tmp);
955 void BufferView::Pimpl::workAreaExpose()
957 static int work_area_width;
958 static unsigned int work_area_height;
960 bool const widthChange = workarea_.workWidth() != work_area_width;
961 bool const heightChange = workarea_.height() != work_area_height;
963 // update from work area
964 work_area_width = workarea_.workWidth();
965 work_area_height = workarea_.height();
968 // The visible LyXView need a resize
971 // Remove all texts from the textcache
972 // This is not _really_ what we want to do. What
973 // we really want to do is to delete in textcache
974 // that does not have a BufferView with matching
975 // width, but as long as we have only one BufferView
976 // deleting all gives the same result.
977 if (lyxerr.debugging())
978 textcache.show(lyxerr, "Expose delete all");
980 } else if (heightChange) {
981 // Rebuild image of current screen
983 // fitCursor() ensures we don't jump back
984 // to the start of the document on vertical
988 // The main window size has changed, repaint most stuff
990 } else if (screen_.get())
991 screen_->redraw(bv_->text, bv_);
993 // Grey box when we don't have a buffer
997 // always make sure that the scrollbar is sane.
999 owner_->updateLayoutChoice();
1004 void BufferView::Pimpl::update()
1006 if (screen_.get() &&
1007 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1009 LyXText::text_status st = bv_->text->status();
1010 screen_->update(bv_->text, bv_);
1012 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1013 if (bv_->text->fullRebreak(bv_)) {
1014 st = LyXText::NEED_MORE_REFRESH;
1015 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1016 bv_->text->cursor.pos());
1019 bv_->text->status(bv_, st);
1020 screen_->update(bv_->text, bv_);
1022 // do this here instead of in the screen::update because of
1024 bv_->text->status(bv_, LyXText::UNCHANGED);
1030 // Values used when calling update:
1032 // -2 - update, move sel_cursor if selection, fitcursor
1033 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1034 // 0 - update, move sel_cursor if selection, fitcursor
1035 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1036 // 3 - update, move sel_cursor if selection
1039 // a simple redraw of the parts that need refresh
1041 // move sel_cursor if selection -
1042 // the text's sel_cursor is moved if there is selection is progress
1045 // fitCursor() is called and the scrollbar updated
1048 // the buffer is marked dirty.
1057 // UPDATE_ONLY = UPDATE;
1058 // UPDATE_SELECT = UPDATE | SELECT;
1059 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1060 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1062 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1063 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1064 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1065 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1066 // update(3) -> update(1) -> update(1) -> update(SELECT)
1068 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1070 owner_->updateLayoutChoice();
1072 if (!text->selection.set() && (f & SELECT)) {
1073 text->selection.cursor = text->cursor;
1076 text->fullRebreak(bv_);
1078 if (text->inset_owner) {
1079 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1080 updateInset(text->inset_owner, false);
1090 buffer_->markDirty();
1095 // Callback for cursor timer
1096 void BufferView::Pimpl::cursorToggle()
1098 // Quite a nice place for asyncron Inset updating, isn't it?
1099 // Actually no! This is run even if no buffer exist... so (Lgb)
1101 cursor_timeout.restart();
1106 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1107 if (pid == -1) // error find out what is wrong
1108 ; // ignore it for now.
1110 sigchldchecker(pid, &status);
1112 updatelist.update(bv_);
1114 if (!screen_.get()) {
1115 cursor_timeout.restart();
1119 if (!bv_->theLockingInset()) {
1120 screen_->cursorToggle(bv_);
1122 bv_->theLockingInset()->toggleInsetCursor(bv_);
1125 cursor_timeout.restart();
1129 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1131 if (!text->cursor.row()->previous())
1134 int y = text->first;
1135 if (text->inset_owner)
1136 y += bv_->text->first;
1137 Row * cursorrow = text->cursor.row();
1138 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1140 // This is to allow jumping over large insets
1141 if ((cursorrow == text->cursor.row()))
1142 text->cursorUp(bv_);
1144 if (text->inset_owner ||
1145 text->cursor.row()->height() < workarea_.height())
1146 screen_->draw(bv_->text, bv_,
1148 - text->cursor.row()->baseline()
1149 + text->cursor.row()->height()
1150 - workarea_.height() + 1 );
1155 void BufferView::Pimpl::cursorNext(LyXText * text)
1157 if (!text->cursor.row()->next())
1160 int y = text->first + workarea_.height();
1161 // if (text->inset_owner)
1162 // y += bv_->text->first;
1163 text->getRowNearY(y);
1165 Row * cursorrow = text->cursor.row();
1166 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1168 // This is to allow jumping over large insets
1169 if ((cursorrow == bv_->text->cursor.row()))
1170 text->cursorDown(bv_);
1172 if (text->inset_owner ||
1173 text->cursor.row()->height() < workarea_.height())
1174 screen_->draw(bv_->text, bv_, text->cursor.y() -
1175 text->cursor.row()->baseline());
1180 bool BufferView::Pimpl::available() const
1182 if (buffer_ && bv_->text) return true;
1187 void BufferView::Pimpl::beforeChange(LyXText * text)
1190 text->clearSelection();
1194 void BufferView::Pimpl::savePosition(unsigned int i)
1196 if (i >= saved_positions_num)
1198 saved_positions[i] = Position(buffer_->fileName(),
1199 bv_->text->cursor.par()->id(),
1200 bv_->text->cursor.pos());
1203 str << _("Saved bookmark") << ' ' << i;
1204 owner_->message(str.str().c_str());
1209 void BufferView::Pimpl::restorePosition(unsigned int i)
1211 if (i >= saved_positions_num)
1214 string const fname = saved_positions[i].filename;
1216 beforeChange(bv_->text);
1218 if (fname != buffer_->fileName()) {
1219 Buffer * b = bufferlist.exists(fname) ?
1220 bufferlist.getBuffer(fname) :
1221 bufferlist.loadLyXFile(fname); // don't ask, just load it
1222 if (b != 0 ) buffer(b);
1225 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1229 bv_->text->setCursor(bv_, par,
1230 min(par->size(), saved_positions[i].par_pos));
1232 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1235 str << _("Moved to bookmark") << ' ' << i;
1236 owner_->message(str.str().c_str());
1241 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1243 if (i >= saved_positions_num)
1246 return !saved_positions[i].filename.empty();
1250 void BufferView::Pimpl::setState()
1252 if (!lyxrc.rtl_support)
1255 LyXText * text = bv_->getLyXText();
1256 if (text->real_current_font.isRightToLeft()) {
1257 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1258 owner_->getIntl()->KeyMapSec();
1260 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1261 owner_->getIntl()->KeyMapPrim();
1266 void BufferView::Pimpl::insetSleep()
1268 if (bv_->theLockingInset() && !inset_slept) {
1269 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1270 bv_->theLockingInset()->insetUnlock(bv_);
1276 void BufferView::Pimpl::insetWakeup()
1278 if (bv_->theLockingInset() && inset_slept) {
1279 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1280 inset_slept = false;
1285 void BufferView::Pimpl::insetUnlock()
1287 if (bv_->theLockingInset()) {
1289 bv_->theLockingInset()->insetUnlock(bv_);
1290 bv_->theLockingInset(0);
1292 inset_slept = false;
1297 bool BufferView::Pimpl::focus() const
1299 return workarea_.hasFocus();
1303 void BufferView::Pimpl::focus(bool f)
1305 if (f) workarea_.setFocus();
1309 bool BufferView::Pimpl::active() const
1311 return workarea_.active();
1315 bool BufferView::Pimpl::belowMouse() const
1317 return workarea_.belowMouse();
1321 void BufferView::Pimpl::showCursor()
1323 if (screen_.get()) {
1324 if (bv_->theLockingInset())
1325 bv_->theLockingInset()->showInsetCursor(bv_);
1327 screen_->showCursor(bv_->text, bv_);
1332 void BufferView::Pimpl::hideCursor()
1334 if (screen_.get()) {
1335 if (!bv_->theLockingInset())
1336 // bv_->theLockingInset()->hideInsetCursor(bv_);
1338 screen_->hideCursor();
1343 void BufferView::Pimpl::toggleSelection(bool b)
1345 if (screen_.get()) {
1346 if (bv_->theLockingInset())
1347 bv_->theLockingInset()->toggleSelection(bv_, b);
1348 screen_->toggleSelection(bv_->text, bv_, b);
1353 void BufferView::Pimpl::toggleToggle()
1356 screen_->toggleToggle(bv_->text, bv_);
1360 void BufferView::Pimpl::center()
1362 beforeChange(bv_->text);
1363 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1364 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1366 screen_->draw(bv_->text, bv_, 0);
1368 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1373 void BufferView::Pimpl::pasteClipboard(bool asPara)
1375 if (!buffer_) return;
1377 screen_->hideCursor();
1378 beforeChange(bv_->text);
1380 string const clip(workarea_.getClipboard());
1382 if (clip.empty()) return;
1385 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1387 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1393 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1395 workarea_.putClipboard(stuff);
1400 * Dispatch functions for actions which can be valid for BufferView->text
1401 * and/or InsetText->text!!!
1406 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1408 LyXText * lt = bv_->getLyXText();
1410 if (selecting || lt->selection.mark()) {
1411 lt->setSelection(bv_);
1415 update(lt, BufferView::SELECT|BufferView::FITCUR);
1418 /* ---> Everytime the cursor is moved, show the current font state. */
1419 // should this too me moved out of this func?
1420 //owner->showState();
1425 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1427 LyXCursor cursor = bv_->getLyXText()->cursor;
1428 Buffer::inset_iterator it =
1429 find_if(Buffer::inset_iterator(
1430 cursor.par(), cursor.pos()),
1431 buffer_->inset_iterator_end(),
1432 lyx::compare_memfun(&Inset::lyxCode, code));
1433 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1437 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1439 string filename = filen;
1441 if (filename.empty()) {
1442 // Launch a file browser
1443 string initpath = lyxrc.document_path;
1446 string const trypath = owner_->buffer()->filepath;
1447 // If directory is writeable, use this as default.
1448 if (IsDirWriteable(trypath))
1452 FileDialog fileDlg(bv_->owner(),
1453 _("Select LyX document to insert"),
1455 make_pair(string(_("Documents")),
1456 string(lyxrc.document_path)),
1457 make_pair(string(_("Examples")),
1458 string(AddPath(system_lyxdir, "examples"))));
1460 FileDialog::Result result =
1461 fileDlg.Select(initpath,
1462 _("*.lyx| LyX Documents (*.lyx)"));
1464 if (result.first == FileDialog::Later)
1467 filename = result.second;
1469 // check selected filename
1470 if (filename.empty()) {
1471 owner_->message(_("Canceled."));
1476 // get absolute path of file and add ".lyx" to the filename if
1478 filename = FileSearch(string(), filename, "lyx");
1480 string const disp_fn(MakeDisplayPath(filename));
1483 s1 << _("Inserting document") << ' '
1484 << disp_fn << " ...";
1485 owner_->message(s1.str().c_str());
1486 bool const res = bv_->insertLyXFile(filename);
1489 str << _("Document") << ' ' << disp_fn
1490 << ' ' << _("inserted.");
1491 owner_->message(str.str().c_str());
1494 str << _("Could not insert document") << ' '
1496 owner_->message(str.str().c_str());
1501 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1503 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1504 << action <<"] arg[" << argument << "]" << endl;
1507 // --- Misc -------------------------------------------
1511 LyXText * lt = bv_->getLyXText();
1512 lt->toggleAppendix(bv_);
1515 | BufferView::FITCUR
1516 | BufferView::CHANGE);
1521 case LFUN_TOC_INSERT:
1523 InsetCommandParams p;
1524 p.setCmdName("tableofcontents");
1525 Inset * inset = new InsetTOC(p);
1526 if (!insertInset(inset, "Standard"))
1531 case LFUN_TABULAR_FEATURE:
1532 case LFUN_SCROLL_INSET:
1533 // this is not handled here as this funktion is only aktive
1534 // if we have a locking_inset and that one is (or contains)
1538 case LFUN_INSET_GRAPHICS:
1540 Inset * new_inset = new InsetGraphics;
1541 if (!insertInset(new_inset)) {
1544 // this is need because you don't use a inset->Edit()
1545 updateInset(new_inset, true);
1546 new_inset->edit(bv_);
1556 case LFUN_PASTESELECTION:
1558 bool asPara = false;
1559 if (argument == "paragraph")
1561 pasteClipboard(asPara);
1573 case LFUN_LAYOUT_COPY:
1574 bv_->copyEnvironment();
1577 case LFUN_LAYOUT_PASTE:
1578 bv_->pasteEnvironment();
1582 case LFUN_GOTOERROR:
1583 gotoInset(Inset::ERROR_CODE, false);
1587 gotoInset(Inset::IGNORE_CODE, false);
1590 case LFUN_REFERENCE_GOTO:
1592 vector<Inset::Code> tmp;
1593 tmp.push_back(Inset::LABEL_CODE);
1594 tmp.push_back(Inset::REF_CODE);
1595 gotoInset(tmp, true);
1599 case LFUN_HYPHENATION:
1600 specialChar(InsetSpecialChar::HYPHENATION);
1603 case LFUN_LIGATURE_BREAK:
1604 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1608 specialChar(InsetSpecialChar::LDOTS);
1611 case LFUN_END_OF_SENTENCE:
1612 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1615 case LFUN_MENU_SEPARATOR:
1616 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1624 changeDepth(bv_, bv_->getLyXText(), 0);
1627 case LFUN_DEPTH_MIN:
1628 changeDepth(bv_, bv_->getLyXText(), -1);
1631 case LFUN_DEPTH_PLUS:
1632 changeDepth(bv_, bv_->getLyXText(), 1);
1636 owner_->getDialogs()->setUserFreeFont();
1639 case LFUN_FILE_INSERT:
1640 MenuInsertLyXFile(argument);
1643 case LFUN_FILE_INSERT_ASCII_PARA:
1644 InsertAsciiFile(bv_, argument, true);
1647 case LFUN_FILE_INSERT_ASCII:
1648 InsertAsciiFile(bv_, argument, false);
1653 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1654 << argument << endl;
1656 // Derive layout number from given argument (string)
1657 // and current buffer's textclass (number). */
1658 textclass_type tclass = buffer_->params.textclass;
1659 pair <bool, layout_type> layout =
1660 textclasslist.NumberOfLayout(tclass, argument);
1662 // If the entry is obsolete, use the new one instead.
1664 string obs = textclasslist.Style(tclass, layout.second)
1667 layout = textclasslist.NumberOfLayout(tclass, obs);
1670 // see if we found the layout number:
1671 if (!layout.first) {
1672 owner_->getLyXFunc()->setErrorMessage(
1673 string(N_("Layout ")) + argument +
1678 if (current_layout != layout.second) {
1679 LyXText * lt = bv_->getLyXText();
1681 current_layout = layout.second;
1684 | BufferView::FITCUR);
1685 lt->setLayout(bv_, layout.second);
1686 owner_->setLayout(layout.second);
1689 | BufferView::FITCUR
1690 | BufferView::CHANGE);
1697 lang(bv_, argument);
1699 owner_->showState();
1704 owner_->showState();
1709 owner_->showState();
1714 owner_->showState();
1719 owner_->showState();
1724 owner_->showState();
1729 owner_->showState();
1734 owner_->showState();
1737 case LFUN_UNDERLINE:
1739 owner_->showState();
1742 case LFUN_FONT_SIZE:
1743 fontSize(bv_, argument);
1744 owner_->showState();
1747 case LFUN_FONT_STATE:
1748 owner_->getLyXFunc()->setMessage(currentState(bv_));
1751 case LFUN_UPCASE_WORD:
1753 LyXText * lt = bv_->getLyXText();
1757 | BufferView::FITCUR);
1758 lt->changeCase(bv_, LyXText::text_uppercase);
1759 if (lt->inset_owner)
1760 updateInset(lt->inset_owner, true);
1763 | BufferView::FITCUR
1764 | BufferView::CHANGE);
1768 case LFUN_LOWCASE_WORD:
1770 LyXText * lt = bv_->getLyXText();
1772 update(lt, BufferView::SELECT|BufferView::FITCUR);
1773 lt->changeCase(bv_, LyXText::text_lowercase);
1774 if (lt->inset_owner)
1775 updateInset(lt->inset_owner, true);
1778 | BufferView::FITCUR
1779 | BufferView::CHANGE);
1783 case LFUN_CAPITALIZE_WORD:
1785 LyXText * lt = bv_->getLyXText();
1787 update(lt, BufferView::SELECT|BufferView::FITCUR);
1788 lt->changeCase(bv_, LyXText::text_capitalization);
1789 if (lt->inset_owner)
1790 updateInset(lt->inset_owner, true);
1793 | BufferView::FITCUR
1794 | BufferView::CHANGE);
1798 case LFUN_TRANSPOSE_CHARS:
1800 LyXText * lt = bv_->getLyXText();
1802 update(lt, BufferView::SELECT|BufferView::FITCUR);
1803 lt->transposeChars(*bv_);
1804 if (lt->inset_owner)
1805 updateInset(lt->inset_owner, true);
1808 | BufferView::FITCUR
1809 | BufferView::CHANGE);
1814 case LFUN_INSERT_LABEL:
1815 MenuInsertLabel(bv_, argument);
1818 case LFUN_REF_INSERT:
1819 if (argument.empty()) {
1820 InsetCommandParams p("ref");
1821 owner_->getDialogs()->createRef(p.getAsString());
1823 InsetCommandParams p;
1824 p.setFromString(argument);
1826 InsetRef * inset = new InsetRef(p, *buffer_);
1827 if (!insertInset(inset))
1830 updateInset(inset, true);
1834 case LFUN_BOOKMARK_SAVE:
1835 savePosition(strToUnsignedInt(argument));
1838 case LFUN_BOOKMARK_GOTO:
1839 restorePosition(strToUnsignedInt(argument));
1844 string label(argument);
1845 if (label.empty()) {
1847 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1849 label = inset->getContents();
1854 if (!label.empty()) {
1855 //bv_->savePosition(0);
1856 if (!bv_->gotoLabel(label))
1857 Alert::alert(_("Error"),
1858 _("Couldn't find this label"),
1859 _("in current document."));
1864 // --- Cursor Movements -----------------------------
1867 LyXText * lt = bv_->getLyXText();
1869 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1870 if (!lt->selection.mark())
1872 update(lt, BufferView::SELECT|BufferView::FITCUR);
1874 lt->cursorLeft(bv_, false);
1875 if (lt->cursor.pos() < lt->cursor.par()->size()
1876 && lt->cursor.par()->isInset(lt->cursor.pos())
1877 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1878 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1879 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1881 tmpinset->edit(bv_, false);
1883 tmpinset->edit(bv_);
1887 lt->cursorRight(bv_, false);
1889 moveCursorUpdate(false);
1890 owner_->showState();
1896 // This is soooo ugly. Isn`t it possible to make
1897 // it simpler? (Lgb)
1898 LyXText * lt = bv_->getLyXText();
1899 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1900 if (!lt->selection.mark())
1902 update(lt, BufferView::SELECT|BufferView::FITCUR);
1903 LyXCursor const cur = lt->cursor;
1905 lt->cursorLeft(bv_, false);
1906 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1907 lt->cursor.pos() < lt->cursor.par()->size() &&
1908 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1909 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1910 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1911 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1913 tmpinset->edit(bv_);
1915 tmpinset->edit(bv_, false);
1919 lt->cursorRight(bv_, false);
1922 moveCursorUpdate(false);
1923 owner_->showState();
1929 LyXText * lt = bv_->getLyXText();
1931 if (!lt->selection.mark())
1933 update(lt, BufferView::UPDATE);
1936 moveCursorUpdate(false);
1937 owner_->showState();
1943 LyXText * lt = bv_->getLyXText();
1945 if (!lt->selection.mark())
1947 update(lt, BufferView::UPDATE);
1948 lt->cursorDown(bv_);
1950 moveCursorUpdate(false);
1951 owner_->showState();
1955 case LFUN_UP_PARAGRAPH:
1957 LyXText * lt = bv_->getLyXText();
1959 if (!lt->selection.mark())
1961 update(lt, BufferView::UPDATE);
1962 lt->cursorUpParagraph(bv_);
1964 moveCursorUpdate(false);
1965 owner_->showState();
1969 case LFUN_DOWN_PARAGRAPH:
1971 LyXText * lt = bv_->getLyXText();
1973 if (!lt->selection.mark())
1975 update(lt, BufferView::UPDATE);
1976 lt->cursorDownParagraph(bv_);
1978 moveCursorUpdate(false);
1979 owner_->showState();
1985 LyXText * lt = bv_->getLyXText();
1987 if (!lt->selection.mark())
1989 update(lt, BufferView::UPDATE);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1999 LyXText * lt = bv_->getLyXText();
2001 if (!lt->selection.mark())
2003 update(lt, BufferView::UPDATE);
2006 moveCursorUpdate(false);
2007 owner_->showState();
2013 LyXText * lt = bv_->getLyXText();
2015 if (!lt->selection.mark())
2017 update(lt, BufferView::SELECT|BufferView::FITCUR);
2018 lt->cursorHome(bv_);
2020 moveCursorUpdate(false);
2021 owner_->showState();
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2032 BufferView::SELECT|BufferView::FITCUR);
2035 moveCursorUpdate(false);
2036 owner_->showState();
2040 case LFUN_SHIFT_TAB:
2043 LyXText * lt = bv_->getLyXText();
2045 if (!lt->selection.mark())
2048 BufferView::SELECT|BufferView::FITCUR);
2051 moveCursorUpdate(false);
2052 owner_->showState();
2056 case LFUN_WORDRIGHT:
2058 LyXText * lt = bv_->getLyXText();
2060 if (!lt->selection.mark())
2062 update(lt, BufferView::SELECT|BufferView::FITCUR);
2063 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2064 lt->cursorLeftOneWord(bv_);
2066 lt->cursorRightOneWord(bv_);
2068 moveCursorUpdate(false);
2069 owner_->showState();
2075 LyXText * lt = bv_->getLyXText();
2077 if (!lt->selection.mark())
2079 update(lt, BufferView::SELECT|BufferView::FITCUR);
2080 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2081 lt->cursorRightOneWord(bv_);
2083 lt->cursorLeftOneWord(bv_);
2085 moveCursorUpdate(false);
2086 owner_->showState();
2090 case LFUN_BEGINNINGBUF:
2092 LyXText * lt = bv_->getLyXText();
2094 if (!lt->selection.mark())
2097 BufferView::SELECT|BufferView::FITCUR);
2100 moveCursorUpdate(false);
2101 owner_->showState();
2107 LyXText * lt = bv_->getLyXText();
2109 if (!lt->selection.mark())
2112 BufferView::SELECT|BufferView::FITCUR);
2113 lt->cursorBottom(bv_);
2115 moveCursorUpdate(false);
2116 owner_->showState();
2120 /* cursor selection ---------------------------- */
2123 LyXText * lt = bv_->getLyXText();
2126 BufferView::SELECT|BufferView::FITCUR);
2127 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2128 lt->cursorLeft(bv_);
2130 lt->cursorRight(bv_);
2132 moveCursorUpdate(true);
2133 owner_->showState();
2139 LyXText * lt = bv_->getLyXText();
2142 BufferView::SELECT|BufferView::FITCUR);
2143 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2144 lt->cursorRight(bv_);
2146 lt->cursorLeft(bv_);
2148 moveCursorUpdate(true);
2149 owner_->showState();
2155 LyXText * lt = bv_->getLyXText();
2158 BufferView::SELECT|BufferView::FITCUR);
2161 moveCursorUpdate(true);
2162 owner_->showState();
2168 LyXText * lt = bv_->getLyXText();
2171 BufferView::SELECT|BufferView::FITCUR);
2172 lt->cursorDown(bv_);
2174 moveCursorUpdate(true);
2175 owner_->showState();
2179 case LFUN_UP_PARAGRAPHSEL:
2181 LyXText * lt = bv_->getLyXText();
2184 BufferView::SELECT|BufferView::FITCUR);
2185 lt->cursorUpParagraph(bv_);
2187 moveCursorUpdate(true);
2188 owner_->showState();
2192 case LFUN_DOWN_PARAGRAPHSEL:
2194 LyXText * lt = bv_->getLyXText();
2197 BufferView::SELECT|BufferView::FITCUR);
2198 lt->cursorDownParagraph(bv_);
2200 moveCursorUpdate(true);
2201 owner_->showState();
2207 LyXText * lt = bv_->getLyXText();
2209 update(lt, BufferView::SELECT|BufferView::FITCUR);
2212 moveCursorUpdate(true);
2213 owner_->showState();
2219 LyXText * lt = bv_->getLyXText();
2221 update(lt, BufferView::SELECT|BufferView::FITCUR);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 lt->cursorHome(bv_);
2236 moveCursorUpdate(true);
2237 owner_->showState();
2243 LyXText * lt = bv_->getLyXText();
2245 update(lt, BufferView::SELECT|BufferView::FITCUR);
2248 moveCursorUpdate(true);
2249 owner_->showState();
2253 case LFUN_WORDRIGHTSEL:
2255 LyXText * lt = bv_->getLyXText();
2257 update(lt, BufferView::SELECT|BufferView::FITCUR);
2258 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2259 lt->cursorLeftOneWord(bv_);
2261 lt->cursorRightOneWord(bv_);
2263 moveCursorUpdate(true);
2264 owner_->showState();
2268 case LFUN_WORDLEFTSEL:
2270 LyXText * lt = bv_->getLyXText();
2272 update(lt, BufferView::SELECT|BufferView::FITCUR);
2273 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2274 lt->cursorRightOneWord(bv_);
2276 lt->cursorLeftOneWord(bv_);
2278 moveCursorUpdate(true);
2279 owner_->showState();
2283 case LFUN_BEGINNINGBUFSEL:
2285 LyXText * lt = bv_->getLyXText();
2287 if (lt->inset_owner)
2289 update(lt, BufferView::SELECT|BufferView::FITCUR);
2292 moveCursorUpdate(true);
2293 owner_->showState();
2297 case LFUN_ENDBUFSEL:
2299 LyXText * lt = bv_->getLyXText();
2301 if (lt->inset_owner)
2304 BufferView::SELECT|BufferView::FITCUR);
2305 lt->cursorBottom(bv_);
2307 moveCursorUpdate(true);
2308 owner_->showState();
2312 // --- text changing commands ------------------------
2313 case LFUN_BREAKLINE:
2315 LyXText * lt = bv_->getLyXText();
2318 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2321 | BufferView::FITCUR
2322 | BufferView::CHANGE);
2323 moveCursorUpdate(false);
2327 case LFUN_PROTECTEDSPACE:
2329 LyXText * lt = bv_->getLyXText();
2331 LyXLayout const & style = textclasslist
2332 .Style(buffer_->params.textclass,
2333 lt->cursor.par()->getLayout());
2335 if (style.free_spacing) {
2336 lt->insertChar(bv_, ' ');
2339 | BufferView::FITCUR
2340 | BufferView::CHANGE);
2344 moveCursorUpdate(false);
2350 LyXText * lt = bv_->getLyXText();
2352 if (lt->selection.mark()) {
2356 | BufferView::FITCUR);
2357 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2360 lt->selection.mark(true);
2363 | BufferView::FITCUR);
2364 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2366 lt->selection.cursor = lt->cursor;
2372 LyXText * lt = bv_->getLyXText();
2374 if (!lt->selection.set()) {
2376 lt->selection.cursor = lt->cursor;
2379 | BufferView::FITCUR
2380 | BufferView::CHANGE);
2381 // It is possible to make it a lot faster still
2382 // just comment out the line below...
2387 moveCursorUpdate(false);
2388 owner_->showState();
2393 case LFUN_DELETE_SKIP:
2395 LyXText * lt = bv_->getLyXText();
2397 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2399 LyXCursor cursor = lt->cursor;
2401 if (!lt->selection.set()) {
2402 if (cursor.pos() == cursor.par()->size()) {
2403 lt->cursorRight(bv_);
2404 cursor = lt->cursor;
2405 if (cursor.pos() == 0
2406 && !(cursor.par()->params().spaceTop()
2407 == VSpace (VSpace::NONE))) {
2410 cursor.par()->params().lineTop(),
2411 cursor.par()->params().lineBottom(),
2412 cursor.par()->params().pagebreakTop(),
2413 cursor.par()->params().pagebreakBottom(),
2414 VSpace(VSpace::NONE),
2415 cursor.par()->params().spaceBottom(),
2416 cursor.par()->params().spacing(),
2417 cursor.par()->params().align(),
2418 cursor.par()->params().labelWidthString(), 0);
2419 lt->cursorLeft(bv_);
2422 | BufferView::FITCUR
2423 | BufferView::CHANGE);
2425 lt->cursorLeft(bv_);
2427 lt->selection.cursor = lt->cursor;
2430 | BufferView::FITCUR
2431 | BufferView::CHANGE);
2435 lt->selection.cursor = lt->cursor;
2438 | BufferView::FITCUR
2439 | BufferView::CHANGE);
2447 /* -------> Delete word forward. */
2448 case LFUN_DELETE_WORD_FORWARD:
2449 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2450 bv_->getLyXText()->deleteWordForward(bv_);
2451 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2452 moveCursorUpdate(false);
2453 owner_->showState();
2456 /* -------> Delete word backward. */
2457 case LFUN_DELETE_WORD_BACKWARD:
2459 LyXText * lt = bv_->getLyXText();
2461 update(lt, BufferView::SELECT|BufferView::FITCUR);
2462 lt->deleteWordBackward(bv_);
2465 | BufferView::FITCUR
2466 | BufferView::CHANGE);
2467 moveCursorUpdate(false);
2468 owner_->showState();
2472 /* -------> Kill to end of line. */
2473 case LFUN_DELETE_LINE_FORWARD:
2475 LyXText * lt = bv_->getLyXText();
2477 update(lt, BufferView::SELECT|BufferView::FITCUR);
2478 lt->deleteLineForward(bv_);
2481 | BufferView::FITCUR
2482 | BufferView::CHANGE);
2483 moveCursorUpdate(false);
2487 /* -------> Set mark off. */
2490 LyXText * lt = bv_->getLyXText();
2493 update(lt, BufferView::SELECT|BufferView::FITCUR);
2494 lt->selection.cursor = lt->cursor;
2495 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2499 /* -------> Set mark on. */
2502 LyXText * lt = bv_->getLyXText();
2505 lt->selection.mark(true);
2506 update(lt, BufferView::SELECT|BufferView::FITCUR);
2507 lt->selection.cursor = lt->cursor;
2508 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2512 case LFUN_BACKSPACE:
2514 LyXText * lt = bv_->getLyXText();
2516 if (!lt->selection.set()) {
2517 if (owner_->getIntl()->getTrans().backspace()) {
2519 lt->selection.cursor = lt->cursor;
2522 | BufferView::FITCUR
2523 | BufferView::CHANGE);
2524 // It is possible to make it a lot faster still
2525 // just comment out the line below...
2531 owner_->showState();
2536 case LFUN_BACKSPACE_SKIP:
2538 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2539 LyXText * lt = bv_->getLyXText();
2541 LyXCursor cursor = lt->cursor;
2543 if (!lt->selection.set()) {
2544 if (cursor.pos() == 0
2545 && !(cursor.par()->params().spaceTop()
2546 == VSpace (VSpace::NONE))) {
2549 cursor.par()->params().lineTop(),
2550 cursor.par()->params().lineBottom(),
2551 cursor.par()->params().pagebreakTop(),
2552 cursor.par()->params().pagebreakBottom(),
2553 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2554 cursor.par()->params().spacing(),
2555 cursor.par()->params().align(),
2556 cursor.par()->params().labelWidthString(), 0);
2559 | BufferView::FITCUR
2560 | BufferView::CHANGE);
2563 lt->selection.cursor = cursor;
2566 | BufferView::FITCUR
2567 | BufferView::CHANGE);
2574 case LFUN_BREAKPARAGRAPH:
2576 LyXText * lt = bv_->getLyXText();
2579 lt->breakParagraph(bv_, 0);
2582 | BufferView::FITCUR
2583 | BufferView::CHANGE);
2584 lt->selection.cursor = lt->cursor;
2586 owner_->showState();
2590 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2592 LyXText * lt = bv_->getLyXText();
2595 lt->breakParagraph(bv_, 1);
2598 | BufferView::FITCUR
2599 | BufferView::CHANGE);
2600 lt->selection.cursor = lt->cursor;
2602 owner_->showState();
2606 case LFUN_BREAKPARAGRAPH_SKIP:
2608 // When at the beginning of a paragraph, remove
2609 // indentation and add a "defskip" at the top.
2610 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2611 LyXText * lt = bv_->getLyXText();
2613 LyXCursor cursor = lt->cursor;
2616 if (cursor.pos() == 0) {
2617 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2620 cursor.par()->params().lineTop(),
2621 cursor.par()->params().lineBottom(),
2622 cursor.par()->params().pagebreakTop(),
2623 cursor.par()->params().pagebreakBottom(),
2624 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2625 cursor.par()->params().spacing(),
2626 cursor.par()->params().align(),
2627 cursor.par()->params().labelWidthString(), 1);
2628 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2632 lt->breakParagraph(bv_, 0);
2633 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2638 | BufferView::FITCUR
2639 | BufferView::CHANGE);
2640 lt->selection.cursor = cursor;
2642 owner_->showState();
2646 case LFUN_PARAGRAPH_SPACING:
2648 LyXText * lt = bv_->getLyXText();
2650 Paragraph * par = lt->cursor.par();
2651 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2652 float cur_value = 1.0;
2653 if (cur_spacing == Spacing::Other) {
2654 cur_value = par->params().spacing().getValue();
2657 istringstream istr(argument.c_str());
2661 Spacing::Space new_spacing = cur_spacing;
2662 float new_value = cur_value;
2664 lyxerr << "Missing argument to `paragraph-spacing'"
2666 } else if (tmp == "single") {
2667 new_spacing = Spacing::Single;
2668 } else if (tmp == "onehalf") {
2669 new_spacing = Spacing::Onehalf;
2670 } else if (tmp == "double") {
2671 new_spacing = Spacing::Double;
2672 } else if (tmp == "other") {
2673 new_spacing = Spacing::Other;
2676 lyxerr << "new_value = " << tmpval << endl;
2679 } else if (tmp == "default") {
2680 new_spacing = Spacing::Default;
2682 lyxerr << _("Unknown spacing argument: ")
2683 << argument << endl;
2685 if (cur_spacing != new_spacing || cur_value != new_value) {
2686 par->params().spacing(Spacing(new_spacing, new_value));
2687 lt->redoParagraph(bv_);
2690 | BufferView::FITCUR
2691 | BufferView::CHANGE);
2696 case LFUN_INSET_TOGGLE:
2698 LyXText * lt = bv_->getLyXText();
2701 update(lt, BufferView::SELECT|BufferView::FITCUR);
2702 lt->toggleInset(bv_);
2703 update(lt, BufferView::SELECT|BufferView::FITCUR);
2715 InsetCommandParams p;
2716 if (action == LFUN_HTMLURL)
2717 p.setCmdName("htmlurl");
2719 p.setCmdName("url");
2720 owner_->getDialogs()->createUrl(p.getAsString());
2724 case LFUN_INSERT_URL:
2726 InsetCommandParams p;
2727 p.setFromString(argument);
2729 InsetUrl * inset = new InsetUrl(p);
2730 if (!insertInset(inset))
2733 updateInset(inset, true);
2737 case LFUN_INSET_TEXT:
2738 insertAndEditInset(new InsetText);
2741 case LFUN_INSET_ERT:
2742 insertAndEditInset(new InsetERT);
2745 case LFUN_INSET_EXTERNAL:
2746 insertAndEditInset(new InsetExternal);
2749 case LFUN_INSET_FOOTNOTE:
2750 insertAndEditInset(new InsetFoot);
2753 case LFUN_INSET_MARGINAL:
2754 insertAndEditInset(new InsetMarginal);
2757 case LFUN_INSET_MINIPAGE:
2758 insertAndEditInset(new InsetMinipage);
2761 case LFUN_INSERT_NOTE:
2762 insertAndEditInset(new InsetNote);
2765 case LFUN_INSET_FLOAT:
2766 // check if the float type exist
2767 if (floatList.typeExist(argument)) {
2768 insertAndEditInset(new InsetFloat(argument));
2770 lyxerr << "Non-existent float type: "
2771 << argument << endl;
2775 case LFUN_INSET_WIDE_FLOAT:
2777 // check if the float type exist
2778 if (floatList.typeExist(argument)) {
2779 InsetFloat * new_inset = new InsetFloat(argument);
2780 new_inset->wide(true);
2781 if (insertInset(new_inset))
2782 new_inset->edit(bv_);
2786 lyxerr << "Non-existent float type: "
2787 << argument << endl;
2794 case LFUN_INSET_LIST:
2795 insertAndEditInset(new InsetList);
2798 case LFUN_INSET_THEOREM:
2799 insertAndEditInset(new InsetTheorem);
2803 case LFUN_INSET_CAPTION:
2805 // Do we have a locking inset...
2806 if (bv_->theLockingInset()) {
2807 lyxerr << "Locking inset code: "
2808 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2809 InsetCaption * new_inset = new InsetCaption;
2810 new_inset->setOwner(bv_->theLockingInset());
2811 new_inset->setAutoBreakRows(true);
2812 new_inset->setDrawFrame(0, InsetText::LOCKED);
2813 new_inset->setFrameColor(0, LColor::captionframe);
2814 if (insertInset(new_inset))
2815 new_inset->edit(bv_);
2822 case LFUN_INSET_TABULAR:
2826 if (!argument.empty())
2827 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2828 InsetTabular * new_inset =
2829 new InsetTabular(*buffer_, r, c);
2831 bv_->getLyXText()->real_current_font.isRightToLeft();
2832 if (!open_new_inset(new_inset, rtl))
2837 // --- lyxserver commands ----------------------------
2839 case LFUN_CHARATCURSOR:
2841 pos_type pos = bv_->getLyXText()->cursor.pos();
2842 if (pos < bv_->getLyXText()->cursor.par()->size())
2843 owner_->getLyXFunc()->setMessage(
2844 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2846 owner_->getLyXFunc()->setMessage("EOF");
2851 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2853 + tostr(bv_->getLyXText()->cursor.y()));
2860 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2861 lyxerr << "SETXY: Could not parse coordinates in '"
2862 << argument << std::endl;
2864 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2868 case LFUN_GETLAYOUT:
2869 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2874 LyXFont & font = bv_->getLyXText()->current_font;
2875 if (font.shape() == LyXFont::ITALIC_SHAPE)
2876 owner_->getLyXFunc()->setMessage("E");
2877 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2878 owner_->getLyXFunc()->setMessage("N");
2880 owner_->getLyXFunc()->setMessage("0");
2885 // --- accented characters ---------------------------
2888 case LFUN_CIRCUMFLEX:
2898 case LFUN_SPECIAL_CARON:
2901 case LFUN_HUNG_UMLAUT:
2904 if (argument.empty()) {
2906 owner_->getLyXFunc()->handleKeyFunc(action);
2908 owner_->getLyXFunc()->handleKeyFunc(action);
2909 owner_->getIntl()->getTrans()
2910 .TranslateAndInsert(argument[0], bv_->getLyXText());
2911 update(bv_->getLyXText(),
2913 | BufferView::FITCUR
2914 | BufferView::CHANGE);
2918 case LFUN_MATH_MACRO:
2919 mathDispatchMathMacro(bv_, argument);
2922 case LFUN_MATH_DELIM:
2923 mathDispatchMathDelim(bv_, argument);
2926 case LFUN_INSERT_MATRIX:
2927 mathDispatchInsertMatrix(bv_, argument);
2930 case LFUN_INSERT_MATH:
2931 mathDispatchInsertMath(bv_, argument);
2934 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2935 mathDispatchMathImportSelection(bv_, argument);
2938 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2939 mathDispatchMathDisplay(bv_, argument);
2942 case LFUN_MATH_MODE: // Open or create an inlined math inset
2943 mathDispatchMathMode(bv_, argument);
2946 case LFUN_GREEK: // Insert a single greek letter
2947 mathDispatchGreek(bv_, argument);
2950 case LFUN_CITATION_INSERT:
2952 InsetCommandParams p;
2953 p.setFromString( argument );
2955 InsetCitation * inset = new InsetCitation( p );
2956 if (!insertInset(inset))
2959 updateInset( inset, true );
2963 case LFUN_INSERT_BIBTEX:
2965 // ale970405+lasgoutt970425
2966 // The argument can be up to two tokens separated
2967 // by a space. The first one is the bibstyle.
2968 string const db = token(argument, ' ', 0);
2969 string const bibstyle = token(argument, ' ', 1);
2971 InsetCommandParams p( "BibTeX", db, bibstyle );
2972 InsetBibtex * inset = new InsetBibtex(p);
2974 if (insertInset(inset)) {
2975 if (argument.empty())
2982 // BibTeX data bases
2983 case LFUN_BIBDB_ADD:
2985 InsetBibtex * inset =
2986 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2988 inset->addDatabase(argument);
2993 case LFUN_BIBDB_DEL:
2995 InsetBibtex * inset =
2996 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2998 inset->delDatabase(argument);
3003 case LFUN_BIBTEX_STYLE:
3005 InsetBibtex * inset =
3006 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3008 inset->setOptions(argument);
3013 case LFUN_INDEX_CREATE:
3015 InsetCommandParams p("index");
3016 if (argument.empty()) {
3017 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3018 p.setContents(idxstring);
3020 p.setContents(argument);
3023 owner_->getDialogs()->createIndex(p.getAsString());
3027 case LFUN_INDEX_INSERT:
3029 InsetCommandParams p;
3030 p.setFromString(argument);
3031 InsetIndex * inset = new InsetIndex(p);
3033 if (!insertInset(inset))
3036 updateInset(inset, true);
3040 case LFUN_INDEX_INSERT_LAST:
3042 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3043 if (!idxstring.empty()) {
3044 owner_->message(_("Word `")
3045 + idxstring + _(("' indexed.")));
3046 InsetCommandParams p("index", idxstring);
3047 InsetIndex * inset = new InsetIndex(p);
3049 if (!insertInset(inset))
3052 updateInset(inset, true);
3057 case LFUN_INDEX_PRINT:
3059 InsetCommandParams p("printindex");
3060 Inset * inset = new InsetPrintIndex(p);
3061 if (!insertInset(inset, "Standard"))
3066 case LFUN_PARENTINSERT:
3068 lyxerr << "arg " << argument << endl;
3069 InsetCommandParams p( "lyxparent", argument );
3070 Inset * inset = new InsetParent(p, *buffer_);
3071 if (!insertInset(inset, "Standard"))
3077 case LFUN_CHILD_INSERT:
3079 InsetInclude::Params p;
3080 p.cparams.setFromString(argument);
3081 p.masterFilename_ = buffer_->fileName();
3083 InsetInclude * inset = new InsetInclude(p);
3084 if (!insertInset(inset))
3087 updateInset(inset, true);
3088 bv_->owner()->getDialogs()->showInclude(inset);
3093 case LFUN_FLOAT_LIST:
3095 // We should check the argument for validity. (Lgb)
3096 Inset * inset = new InsetFloatList(argument);
3097 if (!insertInset(inset, "Standard"))
3102 case LFUN_THESAURUS_ENTRY:
3104 string arg = argument;
3107 arg = bv_->getLyXText()->selectionAsString(buffer_,
3111 if (arg.size() > 100 || arg.empty()) {
3112 // Get word or selection
3113 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3114 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3115 // FIXME: where is getLyXText()->unselect(bv_) ?
3119 bv_->owner()->getDialogs()->showThesaurus(arg);
3123 case LFUN_SELFINSERT:
3125 if (argument.empty()) break;
3127 /* Automatically delete the currently selected
3128 * text and replace it with what is being
3129 * typed in now. Depends on lyxrc settings
3130 * "auto_region_delete", which defaults to
3133 LyXText * lt = bv_->getLyXText();
3135 if (lyxrc.auto_region_delete) {
3136 if (lt->selection.set()) {
3137 lt->cutSelection(bv_, false, false);
3140 | BufferView::FITCUR
3141 | BufferView::CHANGE);
3146 LyXFont const old_font(lt->real_current_font);
3148 string::const_iterator cit = argument.begin();
3149 string::const_iterator end = argument.end();
3150 for (; cit != end; ++cit) {
3151 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3156 | BufferView::FITCUR
3157 | BufferView::CHANGE);
3159 lt->selection.cursor = lt->cursor;
3160 moveCursorUpdate(false);
3162 // real_current_font.number can change so we need to
3163 // update the minibuffer
3164 if (old_font != lt->real_current_font)
3165 owner_->showState();
3170 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3172 time_t now_time_t = time(NULL);
3173 struct tm * now_tm = localtime(&now_time_t);
3174 setlocale(LC_TIME, "");
3176 if (!argument.empty())
3179 arg = lyxrc.date_insert_format;
3181 int const datetmp_len =
3182 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3184 LyXText * lt = bv_->getLyXText();
3186 for (int i = 0; i < datetmp_len; i++) {
3187 lt->insertChar(bv_, datetmp[i]);
3190 | BufferView::FITCUR
3191 | BufferView::CHANGE);
3194 lt->selection.cursor = lt->cursor;
3195 moveCursorUpdate(false);
3199 case LFUN_UNKNOWN_ACTION:
3200 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3211 void BufferView::Pimpl::newline()
3214 LyXText * lt = bv_->getLyXText();
3218 | BufferView::FITCUR);
3219 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3222 | BufferView::FITCUR
3223 | BufferView::CHANGE);
3228 void BufferView::Pimpl::hfill()
3231 LyXText * lt = bv_->getLyXText();
3235 | BufferView::FITCUR);
3236 lt->insertChar(bv_, Paragraph::META_HFILL);
3239 | BufferView::FITCUR
3240 | BufferView::CHANGE);
3245 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3249 update(lt, BufferView::SELECT|BufferView::FITCUR);
3250 InsetSpecialChar * new_inset =
3251 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3252 #ifdef WITH_WARNINGS
3253 #warning Why is this code different from specialChar() below? (JMarc)
3254 // the code in specialChar is a generic version of what used to exist
3255 // for other special chars. I did not merge this case because of the
3256 // call to updateInset(), but what does it do?
3258 if (!insertInset(new_inset))
3261 updateInset(new_inset, true);
3266 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3269 LyXText * lt = bv_->getLyXText();
3272 update(lt, BufferView::SELECT|BufferView::FITCUR);
3273 InsetSpecialChar * new_inset =
3274 new InsetSpecialChar(kind);
3275 insertInset(new_inset);
3276 // Ok, what happens here if we are unable to insert
3277 // the inset? Leak it?
3282 void BufferView::Pimpl::smartQuote()
3284 LyXText const * lt = bv_->getLyXText();
3285 Paragraph const * par = lt->cursor.par();
3286 pos_type pos = lt->cursor.pos();
3290 || (par->isInset(pos - 1)
3291 && par->getInset(pos - 1)->isSpace()))
3294 c = par->getChar(pos - 1);
3299 LyXLayout const & style = textclasslist.Style(
3300 bv_->buffer()->params.textclass, par->getLayout());
3302 if (style.pass_thru ||
3303 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3304 Dispatch(LFUN_SELFINSERT, "\"");
3308 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3310 if (insertInset(inset))
3317 // Open and lock an updatable inset
3318 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3320 LyXText * lt = bv_->getLyXText();
3324 if (!insertInset(new_inset)) {
3328 new_inset->edit(bv_, !behind);
3333 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3335 // if we are in a locking inset we should try to insert the
3336 // inset there otherwise this is a illegal function now
3337 if (bv_->theLockingInset()) {
3338 if (bv_->theLockingInset()->insetAllowed(inset))
3339 return bv_->theLockingInset()->insertInset(bv_, inset);
3343 // not quite sure if we want this...
3344 setCursorParUndo(bv_);
3347 beforeChange(bv_->text);
3348 if (!lout.empty()) {
3349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3350 bv_->text->breakParagraph(bv_);
3351 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 if (bv_->text->cursor.par()->size()) {
3354 bv_->text->cursorLeft(bv_);
3356 bv_->text->breakParagraph(bv_);
3357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3360 pair<bool, layout_type> lres =
3361 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3362 layout_type lay = 0;
3363 if (lres.first != false) {
3367 // layout not fount using default "Standard" (0)
3371 bv_->text->setLayout(bv_, lay);
3373 bv_->text->setParagraph(bv_, 0, 0,
3375 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3383 bv_->text->insertInset(bv_, inset);
3384 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3391 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3396 // first check for locking insets
3397 if (bv_->theLockingInset()) {
3398 if (bv_->theLockingInset() == inset) {
3399 if (bv_->text->updateInset(bv_, inset)) {
3402 buffer_->markDirty();
3407 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3408 if (bv_->text->updateInset(bv_,
3409 bv_->theLockingInset())) {
3412 buffer_->markDirty();
3420 // then check the current buffer
3423 update(bv_->text, BufferView::UPDATE);
3424 if (bv_->text->updateInset(bv_, inset)) {
3428 | BufferView::FITCUR
3429 | BufferView::CHANGE);
3431 update(bv_->text, SELECT);
3439 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3442 if (!available()) return;
3445 beforeChange(bv_->text);
3446 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3448 LyXCursor const & cursor = bv_->text->cursor;
3452 cursor.par()->isInset(cursor.pos())) {
3453 Inset const * inset = cursor.par()->getInset(cursor.pos());
3454 if (find(codes.begin(), codes.end(), inset->lyxCode())
3457 static_cast<InsetCommand const *>(inset)->getContents();
3461 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3462 if (bv_->text->cursor.pos()
3463 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3464 LyXCursor tmp = bv_->text->cursor;
3465 bv_->text->cursor.par(bv_->text->firstParagraph());
3466 bv_->text->cursor.pos(0);
3467 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3468 bv_->text->cursor = tmp;
3469 bv_->owner()->message(_("No more insets"));
3472 bv_->owner()->message(_("No more insets"));
3475 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3476 bv_->text->selection.cursor = bv_->text->cursor;
3480 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3482 gotoInset(vector<Inset::Code>(1, code), same_content);