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);
370 buffer_->resizeInsets(bv_);
371 // this will scroll the screen such that the cursor becomes visible
376 owner_->allowInput();
378 /// clear the "Formatting Document" message
385 void BufferView::Pimpl::updateScreen()
387 // Regenerate the screen.
388 screen_.reset(new LyXScreen(workarea_));
392 void BufferView::Pimpl::updateScrollbar()
394 /* If the text is smaller than the working area, the scrollbar
395 * maximum must be the working area height. No scrolling will
398 workarea_.setScrollbar(0, 1.0);
402 long const text_height = bv_->text->height;
404 double const lineh = bv_->text->defaultHeight();
405 double const slider_size =
406 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
408 static long old_text_height = 0;
409 static double old_lineh = 0;
410 static double old_slider_size = 0;
412 if (text_height != old_text_height) {
413 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
414 old_text_height = text_height;
416 if (lineh != old_lineh) {
417 workarea_.setScrollbarIncrements(lineh);
420 if (current_scrollbar_value != bv_->text->first
421 || slider_size != old_slider_size) {
422 current_scrollbar_value = bv_->text->first;
423 workarea_.setScrollbar(current_scrollbar_value, slider_size);
424 old_slider_size = slider_size;
429 // Callback for scrollbar slider
430 void BufferView::Pimpl::scrollCB(double value)
432 if (!buffer_) return;
434 current_scrollbar_value = long(value);
435 if (current_scrollbar_value < 0)
436 current_scrollbar_value = 0;
441 screen_->draw(bv_->text, bv_, current_scrollbar_value);
443 if (!lyxrc.cursor_follows_scrollbar) {
448 LyXText * vbt = bv_->text;
450 int const height = vbt->defaultHeight();
451 int const first = static_cast<int>((bv_->text->first + height));
452 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
454 if (vbt->cursor.y() < first)
455 vbt->setCursorFromCoordinates(bv_, 0, first);
456 else if (vbt->cursor.y() > last)
457 vbt->setCursorFromCoordinates(bv_, 0, last);
463 int BufferView::Pimpl::scrollUp(long time)
465 if (!buffer_) return 0;
466 if (!screen_.get()) return 0;
468 double value = workarea_.getScrollbarValue();
470 if (value == 0) return 0;
472 float add_value = (bv_->text->defaultHeight()
473 + float(time) * float(time) * 0.125);
475 if (add_value > workarea_.height())
476 add_value = float(workarea_.height() -
477 bv_->text->defaultHeight());
484 workarea_.setScrollbarValue(value);
491 int BufferView::Pimpl::scrollDown(long time)
493 if (!buffer_) return 0;
494 if (!screen_.get()) return 0;
496 double value = workarea_.getScrollbarValue();
497 pair<float, float> p = workarea_.getScrollbarBounds();
498 double const max = p.second;
500 if (value == max) return 0;
502 float add_value = (bv_->text->defaultHeight()
503 + float(time) * float(time) * 0.125);
505 if (add_value > workarea_.height())
506 add_value = float(workarea_.height() -
507 bv_->text->defaultHeight());
514 workarea_.setScrollbarValue(value);
521 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
523 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
527 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
529 // Only use motion with button 1
530 if (!(state & Button1MotionMask))
533 if (!buffer_ || !screen_.get()) return;
535 // Check for inset locking
536 if (bv_->theLockingInset()) {
537 LyXCursor cursor = bv_->text->cursor;
538 LyXFont font = bv_->text->getFont(buffer_,
539 cursor.par(), cursor.pos());
540 int width = bv_->theLockingInset()->width(bv_, font);
541 int inset_x = font.isVisibleRightToLeft()
542 ? cursor.x() - width : cursor.x();
543 int start_x = inset_x + bv_->theLockingInset()->scroll();
544 bv_->theLockingInset()->
545 insetMotionNotify(bv_,
547 y - cursor.y() + bv_->text->first,
552 /* The test for not selection possible is needed, that only motion
553 events are used, where the bottom press event was on
554 the drawing area too */
555 if (!selection_possible)
558 screen_->hideCursor();
560 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
562 if (!bv_->text->selection.set())
563 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
565 bv_->text->setSelection(bv_);
566 screen_->toggleToggle(bv_->text, bv_);
569 screen_->showCursor(bv_->text, bv_);
576 // Single-click on work area
577 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
580 if (!buffer_ || !screen_.get()) return;
582 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
584 // ok ok, this is a hack.
585 if (button == 4 || button == 5) {
588 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
591 scrollDown(lyxrc.wheel_jump);
596 if (bv_->theLockingInset()) {
597 // We are in inset locking mode
599 /* Check whether the inset was hit. If not reset mode,
600 otherwise give the event to the inset */
601 if (inset_hit == bv_->theLockingInset()) {
602 bv_->theLockingInset()->
603 insetButtonPress(bv_,xpos, ypos,button);
606 bv_->unlockInset(bv_->theLockingInset());
611 selection_possible = true;
612 screen_->hideCursor();
614 int const screen_first = bv_->text->first;
616 // Middle button press pastes if we have a selection
617 bool paste_internally = false;
619 && bv_->text->selection.set()) {
620 owner_->getLyXFunc()->dispatch(LFUN_COPY);
621 paste_internally = true;
624 // Clear the selection
625 screen_->toggleSelection(bv_->text, bv_);
626 bv_->text->clearSelection();
627 bv_->text->fullRebreak(bv_);
629 screen_->update(bv_->text, bv_);
635 // Single left click in math inset?
636 if (isHighlyEditableInset(inset_hit)) {
637 // Highly editable inset, like math
638 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
639 selection_possible = false;
640 owner_->updateLayoutChoice();
641 owner_->message(inset->editMessage());
642 inset->insetButtonPress(bv_, xpos, ypos, button);
643 inset->edit(bv_, xpos, ypos, button);
647 // Right click on a footnote flag opens float menu
649 selection_possible = false;
653 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
654 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
656 bv_->text->selection.cursor = bv_->text->cursor;
657 bv_->text->cursor.x_fix(bv_->text->cursor.x());
659 owner_->updateLayoutChoice();
661 selection_possible = false;
664 // Insert primary selection with middle mouse
665 // if there is a local selection in the current buffer,
668 if (paste_internally)
669 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
671 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
673 selection_possible = false;
679 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
685 LyXText * text = bv_->getLyXText();
687 if (text->bv_owner && bv_->theLockingInset())
690 if (screen_.get() && button == 1) {
691 if (text->bv_owner) {
692 screen_->hideCursor();
693 screen_->toggleSelection(text, bv_);
694 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
695 screen_->toggleSelection(text, bv_, false);
697 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
699 /* This will fit the cursor on the screen
701 update(text, BufferView::SELECT|BufferView::FITCUR);
706 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
712 LyXText * text = bv_->getLyXText();
714 if (text->bv_owner && bv_->theLockingInset())
717 if (screen_.get() && (button == 1)) {
718 screen_->hideCursor();
719 screen_->toggleSelection(text, bv_);
720 text->cursorHome(bv_);
721 text->selection.cursor = text->cursor;
722 text->cursorEnd(bv_);
723 text->setSelection(bv_);
724 screen_->toggleSelection(text, bv_, false);
725 /* This will fit the cursor on the screen
727 update(text, BufferView::SELECT|BufferView::FITCUR);
732 void BufferView::Pimpl::enterView()
734 if (active() && available()) {
735 SetXtermCursor(workarea_.getWin());
736 using_xterm_cursor = true;
741 void BufferView::Pimpl::leaveView()
743 if (using_xterm_cursor) {
744 XUndefineCursor(fl_get_display(), workarea_.getWin());
745 using_xterm_cursor = false;
750 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
753 if (!buffer_ || !screen_.get()) return;
755 // If we hit an inset, we have the inset coordinates in these
756 // and inset_hit points to the inset. If we do not hit an
757 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
758 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
760 if (bv_->theLockingInset()) {
761 // We are in inset locking mode.
763 /* LyX does a kind of work-area grabbing for insets.
764 Only a ButtonPress Event outside the inset will
765 force a insetUnlock. */
766 bv_->theLockingInset()->
767 insetButtonRelease(bv_, x, y, button);
771 selection_possible = false;
779 // Did we hit an editable inset?
781 // Inset like error, notes and figures
782 selection_possible = false;
784 // if we reach this point with a selection, it
785 // must mean we are currently selecting.
786 // But we don't want to open the inset
787 // because that is annoying for the user.
788 // So just pretend we didn't hit it.
789 // this is OK because a "kosher" ButtonRelease
790 // will follow a ButtonPress that clears
792 // Note this also fixes selection drawing
793 // problems if we end up opening an inset
794 if (bv_->getLyXText()->selection.set())
797 // CHECK fix this proper in 0.13
798 // well, maybe 13.0 !!!!!!!!!
800 // Following a ref shouldn't issue
801 // a push on the undo-stack
802 // anylonger, now that we have
803 // keybindings for following
804 // references and returning from
805 // references. IMHO though, it
806 // should be the inset's own business
807 // to push or not push on the undo
808 // stack. They don't *have* to
809 // alter the document...
811 // ...or maybe the SetCursorParUndo()
812 // below isn't necessary at all anylonger?
813 if (inset_hit->lyxCode() == Inset::REF_CODE) {
814 setCursorParUndo(bv_);
817 owner_->message(inset_hit->editMessage());
819 if (isHighlyEditableInset(inset_hit)) {
820 // Highly editable inset, like math
821 UpdatableInset *inset = (UpdatableInset *)inset_hit;
822 inset->insetButtonRelease(bv_, x, y, button);
824 inset_hit->insetButtonRelease(bv_, x, y, button);
825 inset_hit->edit(bv_, x, y, button);
831 #warning variable c is set but never used. What is it good for?? (JMarc)
832 #warning isnt this code dead ?? "open a float" ??? (jbl)
834 // check whether we want to open a float
838 if (bv_->text->cursor.pos() <
839 bv_->text->cursor.par()->size()) {
840 c = bv_->text->cursor.par()->
841 getChar(bv_->text->cursor.pos());
843 if (bv_->text->cursor.pos() - 1 >= 0) {
844 c = bv_->text->cursor.par()->
845 getChar(bv_->text->cursor.pos() - 1);
848 selection_possible = false;
853 // Maybe we want to edit a bibitem ale970302
854 if (bv_->text->cursor.par()->bibkey && x < 20 +
855 bibitemMaxWidth(bv_, textclasslist.
857 params.textclass).defaultfont())) {
858 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
865 Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
867 Paragraph /*const*/ & par = *cursor.par();
868 pos_type const pos = cursor.pos();
870 lyx::Assert(par.getInset(pos));
872 Inset const & inset(*par.getInset(pos));
874 LyXFont const & font = text.getFont(buffer_, &par, pos);
876 int const width = inset.width(bv_, font);
877 int const inset_x = font.isVisibleRightToLeft()
878 ? (cursor.x() - width) : cursor.x();
881 inset_x + inset.scroll(),
883 cursor.y() - inset.ascent(bv_, font),
884 cursor.y() + inset.descent(bv_, font));
888 Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
890 pos_type const pos(cursor.pos());
891 Paragraph /*const*/ & par(*cursor.par());
893 if (pos >= par.size() || !par.isInset(pos)) {
897 Inset /*const*/ * inset = par.getInset(pos);
899 if (!isEditableInset(inset)) {
903 Box b(insetDimensions(text, cursor));
905 if (!b.contained(x, y)) {
909 text.setCursor(bv_, &par, pos, true);
912 // The origin of an inset is on the baseline
913 y -= (text.cursor.y());
919 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
924 int y_tmp = y + text->first;
927 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
929 Inset * inset(checkInset(*text, cursor, x, y_tmp));
936 // look at previous position
938 if (cursor.pos() == 0) {
943 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
945 inset = checkInset(*text, cursor, x, y_tmp);
953 void BufferView::Pimpl::workAreaExpose()
955 static int work_area_width;
956 static unsigned int work_area_height;
958 bool const widthChange = workarea_.workWidth() != work_area_width;
959 bool const heightChange = workarea_.height() != work_area_height;
961 // update from work area
962 work_area_width = workarea_.workWidth();
963 work_area_height = workarea_.height();
966 // The visible LyXView need a resize
969 // Remove all texts from the textcache
970 // This is not _really_ what we want to do. What
971 // we really want to do is to delete in textcache
972 // that does not have a BufferView with matching
973 // width, but as long as we have only one BufferView
974 // deleting all gives the same result.
975 if (lyxerr.debugging())
976 textcache.show(lyxerr, "Expose delete all");
978 } else if (heightChange) {
979 // Rebuild image of current screen
981 // fitCursor() ensures we don't jump back
982 // to the start of the document on vertical
986 // The main window size has changed, repaint most stuff
988 } else if (screen_.get())
989 screen_->redraw(bv_->text, bv_);
991 // Grey box when we don't have a buffer
995 // always make sure that the scrollbar is sane.
997 owner_->updateLayoutChoice();
1002 void BufferView::Pimpl::update()
1004 if (screen_.get() &&
1005 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1007 LyXText::text_status st = bv_->text->status();
1008 screen_->update(bv_->text, bv_);
1010 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1011 if (bv_->text->fullRebreak(bv_)) {
1012 st = LyXText::NEED_MORE_REFRESH;
1013 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1014 bv_->text->cursor.pos());
1017 bv_->text->status(bv_, st);
1018 screen_->update(bv_->text, bv_);
1020 // do this here instead of in the screen::update because of
1022 bv_->text->status(bv_, LyXText::UNCHANGED);
1028 // Values used when calling update:
1030 // -2 - update, move sel_cursor if selection, fitcursor
1031 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1032 // 0 - update, move sel_cursor if selection, fitcursor
1033 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1034 // 3 - update, move sel_cursor if selection
1037 // a simple redraw of the parts that need refresh
1039 // move sel_cursor if selection -
1040 // the text's sel_cursor is moved if there is selection is progress
1043 // fitCursor() is called and the scrollbar updated
1046 // the buffer is marked dirty.
1055 // UPDATE_ONLY = UPDATE;
1056 // UPDATE_SELECT = UPDATE | SELECT;
1057 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1058 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1060 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1061 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1062 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1063 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1064 // update(3) -> update(1) -> update(1) -> update(SELECT)
1066 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1068 owner_->updateLayoutChoice();
1070 if (!text->selection.set() && (f & SELECT)) {
1071 text->selection.cursor = text->cursor;
1074 text->fullRebreak(bv_);
1076 if (text->inset_owner) {
1077 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1078 updateInset(text->inset_owner, false);
1088 buffer_->markDirty();
1093 // Callback for cursor timer
1094 void BufferView::Pimpl::cursorToggle()
1096 // Quite a nice place for asyncron Inset updating, isn't it?
1097 // Actually no! This is run even if no buffer exist... so (Lgb)
1099 cursor_timeout.restart();
1104 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1105 if (pid == -1) // error find out what is wrong
1106 ; // ignore it for now.
1108 sigchldchecker(pid, &status);
1110 updatelist.update(bv_);
1112 if (!screen_.get()) {
1113 cursor_timeout.restart();
1117 if (!bv_->theLockingInset()) {
1118 screen_->cursorToggle(bv_);
1120 bv_->theLockingInset()->toggleInsetCursor(bv_);
1123 cursor_timeout.restart();
1127 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1129 if (!text->cursor.row()->previous())
1132 int y = text->first;
1133 if (text->inset_owner)
1134 y += bv_->text->first;
1135 Row * cursorrow = text->cursor.row();
1136 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1138 // This is to allow jumping over large insets
1139 if ((cursorrow == text->cursor.row()))
1140 text->cursorUp(bv_);
1142 if (text->inset_owner ||
1143 text->cursor.row()->height() < workarea_.height())
1144 screen_->draw(bv_->text, bv_,
1146 - text->cursor.row()->baseline()
1147 + text->cursor.row()->height()
1148 - workarea_.height() + 1 );
1153 void BufferView::Pimpl::cursorNext(LyXText * text)
1155 if (!text->cursor.row()->next())
1158 int y = text->first + workarea_.height();
1159 // if (text->inset_owner)
1160 // y += bv_->text->first;
1161 text->getRowNearY(y);
1163 Row * cursorrow = text->cursor.row();
1164 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1166 // This is to allow jumping over large insets
1167 if ((cursorrow == bv_->text->cursor.row()))
1168 text->cursorDown(bv_);
1170 if (text->inset_owner ||
1171 text->cursor.row()->height() < workarea_.height())
1172 screen_->draw(bv_->text, bv_, text->cursor.y() -
1173 text->cursor.row()->baseline());
1178 bool BufferView::Pimpl::available() const
1180 if (buffer_ && bv_->text) return true;
1185 void BufferView::Pimpl::beforeChange(LyXText * text)
1188 text->clearSelection();
1192 void BufferView::Pimpl::savePosition(unsigned int i)
1194 if (i >= saved_positions_num)
1196 saved_positions[i] = Position(buffer_->fileName(),
1197 bv_->text->cursor.par()->id(),
1198 bv_->text->cursor.pos());
1201 str << _("Saved bookmark") << ' ' << i;
1202 owner_->message(str.str().c_str());
1207 void BufferView::Pimpl::restorePosition(unsigned int i)
1209 if (i >= saved_positions_num)
1212 string const fname = saved_positions[i].filename;
1214 beforeChange(bv_->text);
1216 if (fname != buffer_->fileName()) {
1217 Buffer * b = bufferlist.exists(fname) ?
1218 bufferlist.getBuffer(fname) :
1219 bufferlist.loadLyXFile(fname); // don't ask, just load it
1220 if (b != 0 ) buffer(b);
1223 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1227 bv_->text->setCursor(bv_, par,
1228 min(par->size(), saved_positions[i].par_pos));
1230 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1233 str << _("Moved to bookmark") << ' ' << i;
1234 owner_->message(str.str().c_str());
1239 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1241 if (i >= saved_positions_num)
1244 return !saved_positions[i].filename.empty();
1248 void BufferView::Pimpl::setState()
1250 if (!lyxrc.rtl_support)
1253 LyXText * text = bv_->getLyXText();
1254 if (text->real_current_font.isRightToLeft()) {
1255 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1256 owner_->getIntl()->KeyMapSec();
1258 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1259 owner_->getIntl()->KeyMapPrim();
1264 void BufferView::Pimpl::insetSleep()
1266 if (bv_->theLockingInset() && !inset_slept) {
1267 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1268 bv_->theLockingInset()->insetUnlock(bv_);
1274 void BufferView::Pimpl::insetWakeup()
1276 if (bv_->theLockingInset() && inset_slept) {
1277 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1278 inset_slept = false;
1283 void BufferView::Pimpl::insetUnlock()
1285 if (bv_->theLockingInset()) {
1287 bv_->theLockingInset()->insetUnlock(bv_);
1288 bv_->theLockingInset(0);
1290 inset_slept = false;
1295 bool BufferView::Pimpl::focus() const
1297 return workarea_.hasFocus();
1301 void BufferView::Pimpl::focus(bool f)
1303 if (f) workarea_.setFocus();
1307 bool BufferView::Pimpl::active() const
1309 return workarea_.active();
1313 bool BufferView::Pimpl::belowMouse() const
1315 return workarea_.belowMouse();
1319 void BufferView::Pimpl::showCursor()
1321 if (screen_.get()) {
1322 if (bv_->theLockingInset())
1323 bv_->theLockingInset()->showInsetCursor(bv_);
1325 screen_->showCursor(bv_->text, bv_);
1330 void BufferView::Pimpl::hideCursor()
1332 if (screen_.get()) {
1333 if (!bv_->theLockingInset())
1334 // bv_->theLockingInset()->hideInsetCursor(bv_);
1336 screen_->hideCursor();
1341 void BufferView::Pimpl::toggleSelection(bool b)
1343 if (screen_.get()) {
1344 if (bv_->theLockingInset())
1345 bv_->theLockingInset()->toggleSelection(bv_, b);
1346 screen_->toggleSelection(bv_->text, bv_, b);
1351 void BufferView::Pimpl::toggleToggle()
1354 screen_->toggleToggle(bv_->text, bv_);
1358 void BufferView::Pimpl::center()
1360 beforeChange(bv_->text);
1361 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1362 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1364 screen_->draw(bv_->text, bv_, 0);
1366 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1371 void BufferView::Pimpl::pasteClipboard(bool asPara)
1373 if (!buffer_) return;
1375 screen_->hideCursor();
1376 beforeChange(bv_->text);
1378 string const clip(workarea_.getClipboard());
1380 if (clip.empty()) return;
1383 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1385 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1387 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1391 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1393 workarea_.putClipboard(stuff);
1398 * Dispatch functions for actions which can be valid for BufferView->text
1399 * and/or InsetText->text!!!
1404 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1406 LyXText * lt = bv_->getLyXText();
1408 if (selecting || lt->selection.mark()) {
1409 lt->setSelection(bv_);
1413 update(lt, BufferView::SELECT|BufferView::FITCUR);
1416 /* ---> Everytime the cursor is moved, show the current font state. */
1417 // should this too me moved out of this func?
1418 //owner->showState();
1423 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1425 LyXCursor cursor = bv_->getLyXText()->cursor;
1426 Buffer::inset_iterator it =
1427 find_if(Buffer::inset_iterator(
1428 cursor.par(), cursor.pos()),
1429 buffer_->inset_iterator_end(),
1430 lyx::compare_memfun(&Inset::lyxCode, code));
1431 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1435 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1437 string filename = filen;
1439 if (filename.empty()) {
1440 // Launch a file browser
1441 string initpath = lyxrc.document_path;
1444 string const trypath = owner_->buffer()->filepath;
1445 // If directory is writeable, use this as default.
1446 if (IsDirWriteable(trypath))
1450 FileDialog fileDlg(bv_->owner(),
1451 _("Select LyX document to insert"),
1453 make_pair(string(_("Documents")),
1454 string(lyxrc.document_path)),
1455 make_pair(string(_("Examples")),
1456 string(AddPath(system_lyxdir, "examples"))));
1458 FileDialog::Result result =
1459 fileDlg.Select(initpath,
1460 _("*.lyx| LyX Documents (*.lyx)"));
1462 if (result.first == FileDialog::Later)
1465 filename = result.second;
1467 // check selected filename
1468 if (filename.empty()) {
1469 owner_->message(_("Canceled."));
1474 // get absolute path of file and add ".lyx" to the filename if
1476 filename = FileSearch(string(), filename, "lyx");
1478 string const disp_fn(MakeDisplayPath(filename));
1481 s1 << _("Inserting document") << ' '
1482 << disp_fn << " ...";
1483 owner_->message(s1.str().c_str());
1484 bool const res = bv_->insertLyXFile(filename);
1487 str << _("Document") << ' ' << disp_fn
1488 << ' ' << _("inserted.");
1489 owner_->message(str.str().c_str());
1492 str << _("Could not insert document") << ' '
1494 owner_->message(str.str().c_str());
1499 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1501 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1502 << action <<"] arg[" << argument << "]" << endl;
1505 // --- Misc -------------------------------------------
1509 LyXText * lt = bv_->getLyXText();
1510 lt->toggleAppendix(bv_);
1513 | BufferView::FITCUR
1514 | BufferView::CHANGE);
1519 case LFUN_TOC_INSERT:
1521 InsetCommandParams p;
1522 p.setCmdName("tableofcontents");
1523 Inset * inset = new InsetTOC(p);
1524 if (!insertInset(inset, "Standard"))
1529 case LFUN_TABULAR_FEATURE:
1530 case LFUN_SCROLL_INSET:
1531 // this is not handled here as this funktion is only aktive
1532 // if we have a locking_inset and that one is (or contains)
1536 case LFUN_INSET_GRAPHICS:
1538 Inset * new_inset = new InsetGraphics;
1539 if (!insertInset(new_inset)) {
1542 // this is need because you don't use a inset->Edit()
1543 updateInset(new_inset, true);
1544 new_inset->edit(bv_);
1554 case LFUN_PASTESELECTION:
1556 bool asPara = false;
1557 if (argument == "paragraph") asPara = true;
1558 pasteClipboard(asPara);
1570 case LFUN_LAYOUT_COPY:
1571 bv_->copyEnvironment();
1574 case LFUN_LAYOUT_PASTE:
1575 bv_->pasteEnvironment();
1579 case LFUN_GOTOERROR:
1580 gotoInset(Inset::ERROR_CODE, false);
1584 gotoInset(Inset::IGNORE_CODE, false);
1587 case LFUN_REFERENCE_GOTO:
1589 vector<Inset::Code> tmp;
1590 tmp.push_back(Inset::LABEL_CODE);
1591 tmp.push_back(Inset::REF_CODE);
1592 gotoInset(tmp, true);
1596 case LFUN_HYPHENATION:
1597 specialChar(InsetSpecialChar::HYPHENATION);
1600 case LFUN_LIGATURE_BREAK:
1601 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1605 specialChar(InsetSpecialChar::LDOTS);
1608 case LFUN_END_OF_SENTENCE:
1609 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1612 case LFUN_MENU_SEPARATOR:
1613 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1621 changeDepth(bv_, bv_->getLyXText(), 0);
1624 case LFUN_DEPTH_MIN:
1625 changeDepth(bv_, bv_->getLyXText(), -1);
1628 case LFUN_DEPTH_PLUS:
1629 changeDepth(bv_, bv_->getLyXText(), 1);
1633 owner_->getDialogs()->setUserFreeFont();
1636 case LFUN_FILE_INSERT:
1637 MenuInsertLyXFile(argument);
1640 case LFUN_FILE_INSERT_ASCII_PARA:
1641 InsertAsciiFile(bv_, argument, true);
1644 case LFUN_FILE_INSERT_ASCII:
1645 InsertAsciiFile(bv_, argument, false);
1650 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1651 << argument << endl;
1653 // Derive layout number from given argument (string)
1654 // and current buffer's textclass (number). */
1655 textclass_type tclass = buffer_->params.textclass;
1656 pair <bool, layout_type> layout =
1657 textclasslist.NumberOfLayout(tclass, argument);
1659 // If the entry is obsolete, use the new one instead.
1661 string obs = textclasslist.Style(tclass, layout.second)
1664 layout = textclasslist.NumberOfLayout(tclass, obs);
1667 // see if we found the layout number:
1668 if (!layout.first) {
1669 owner_->getLyXFunc()->setErrorMessage(
1670 string(N_("Layout ")) + argument +
1675 if (current_layout != layout.second) {
1676 LyXText * lt = bv_->getLyXText();
1678 current_layout = layout.second;
1681 | BufferView::FITCUR);
1682 lt->setLayout(bv_, layout.second);
1683 owner_->setLayout(layout.second);
1686 | BufferView::FITCUR
1687 | BufferView::CHANGE);
1694 lang(bv_, argument);
1696 owner_->showState();
1701 owner_->showState();
1706 owner_->showState();
1711 owner_->showState();
1716 owner_->showState();
1721 owner_->showState();
1726 owner_->showState();
1731 owner_->showState();
1734 case LFUN_UNDERLINE:
1736 owner_->showState();
1739 case LFUN_FONT_SIZE:
1740 fontSize(bv_, argument);
1741 owner_->showState();
1744 case LFUN_FONT_STATE:
1745 owner_->getLyXFunc()->setMessage(currentState(bv_));
1748 case LFUN_UPCASE_WORD:
1750 LyXText * lt = bv_->getLyXText();
1754 | BufferView::FITCUR);
1755 lt->changeCase(bv_, LyXText::text_uppercase);
1756 if (lt->inset_owner)
1757 updateInset(lt->inset_owner, true);
1760 | BufferView::FITCUR
1761 | BufferView::CHANGE);
1765 case LFUN_LOWCASE_WORD:
1767 LyXText * lt = bv_->getLyXText();
1769 update(lt, BufferView::SELECT|BufferView::FITCUR);
1770 lt->changeCase(bv_, LyXText::text_lowercase);
1771 if (lt->inset_owner)
1772 updateInset(lt->inset_owner, true);
1775 | BufferView::FITCUR
1776 | BufferView::CHANGE);
1780 case LFUN_CAPITALIZE_WORD:
1782 LyXText * lt = bv_->getLyXText();
1784 update(lt, BufferView::SELECT|BufferView::FITCUR);
1785 lt->changeCase(bv_, LyXText::text_capitalization);
1786 if (lt->inset_owner)
1787 updateInset(lt->inset_owner, true);
1790 | BufferView::FITCUR
1791 | BufferView::CHANGE);
1795 case LFUN_TRANSPOSE_CHARS:
1797 LyXText * lt = bv_->getLyXText();
1799 update(lt, BufferView::SELECT|BufferView::FITCUR);
1800 lt->transposeChars(*bv_);
1801 if (lt->inset_owner)
1802 updateInset(lt->inset_owner, true);
1805 | BufferView::FITCUR
1806 | BufferView::CHANGE);
1811 case LFUN_INSERT_LABEL:
1812 MenuInsertLabel(bv_, argument);
1815 case LFUN_REF_INSERT:
1816 if (argument.empty()) {
1817 InsetCommandParams p("ref");
1818 owner_->getDialogs()->createRef(p.getAsString());
1820 InsetCommandParams p;
1821 p.setFromString(argument);
1823 InsetRef * inset = new InsetRef(p, *buffer_);
1824 if (!insertInset(inset))
1827 updateInset(inset, true);
1831 case LFUN_BOOKMARK_SAVE:
1832 savePosition(strToUnsignedInt(argument));
1835 case LFUN_BOOKMARK_GOTO:
1836 restorePosition(strToUnsignedInt(argument));
1841 string label(argument);
1842 if (label.empty()) {
1844 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1846 label = inset->getContents();
1851 if (!label.empty()) {
1852 //bv_->savePosition(0);
1853 if (!bv_->gotoLabel(label))
1854 Alert::alert(_("Error"),
1855 _("Couldn't find this label"),
1856 _("in current document."));
1861 // --- Cursor Movements -----------------------------
1864 LyXText * lt = bv_->getLyXText();
1866 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1867 if (!lt->selection.mark())
1869 update(lt, BufferView::SELECT|BufferView::FITCUR);
1871 lt->cursorLeft(bv_, false);
1872 if (lt->cursor.pos() < lt->cursor.par()->size()
1873 && lt->cursor.par()->isInset(lt->cursor.pos())
1874 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1875 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1876 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1878 tmpinset->edit(bv_, false);
1880 tmpinset->edit(bv_);
1884 lt->cursorRight(bv_, false);
1886 moveCursorUpdate(false);
1887 owner_->showState();
1893 // This is soooo ugly. Isn`t it possible to make
1894 // it simpler? (Lgb)
1895 LyXText * lt = bv_->getLyXText();
1896 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1897 if (!lt->selection.mark())
1899 update(lt, BufferView::SELECT|BufferView::FITCUR);
1900 LyXCursor const cur = lt->cursor;
1902 lt->cursorLeft(bv_, false);
1903 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1904 lt->cursor.pos() < lt->cursor.par()->size() &&
1905 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1906 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1907 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1908 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1910 tmpinset->edit(bv_);
1912 tmpinset->edit(bv_, false);
1916 lt->cursorRight(bv_, false);
1919 moveCursorUpdate(false);
1920 owner_->showState();
1926 LyXText * lt = bv_->getLyXText();
1928 if (!lt->selection.mark())
1930 update(lt, BufferView::UPDATE);
1933 moveCursorUpdate(false);
1934 owner_->showState();
1940 LyXText * lt = bv_->getLyXText();
1942 if (!lt->selection.mark())
1944 update(lt, BufferView::UPDATE);
1945 lt->cursorDown(bv_);
1947 moveCursorUpdate(false);
1948 owner_->showState();
1952 case LFUN_UP_PARAGRAPH:
1954 LyXText * lt = bv_->getLyXText();
1956 if (!lt->selection.mark())
1958 update(lt, BufferView::UPDATE);
1959 lt->cursorUpParagraph(bv_);
1961 moveCursorUpdate(false);
1962 owner_->showState();
1966 case LFUN_DOWN_PARAGRAPH:
1968 LyXText * lt = bv_->getLyXText();
1970 if (!lt->selection.mark())
1972 update(lt, BufferView::UPDATE);
1973 lt->cursorDownParagraph(bv_);
1975 moveCursorUpdate(false);
1976 owner_->showState();
1982 LyXText * lt = bv_->getLyXText();
1984 if (!lt->selection.mark())
1986 update(lt, BufferView::UPDATE);
1989 moveCursorUpdate(false);
1990 owner_->showState();
1996 LyXText * lt = bv_->getLyXText();
1998 if (!lt->selection.mark())
2000 update(lt, BufferView::UPDATE);
2003 moveCursorUpdate(false);
2004 owner_->showState();
2010 LyXText * lt = bv_->getLyXText();
2012 if (!lt->selection.mark())
2014 update(lt, BufferView::SELECT|BufferView::FITCUR);
2015 lt->cursorHome(bv_);
2017 moveCursorUpdate(false);
2018 owner_->showState();
2024 LyXText * lt = bv_->getLyXText();
2026 if (!lt->selection.mark())
2029 BufferView::SELECT|BufferView::FITCUR);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2037 case LFUN_SHIFT_TAB:
2040 LyXText * lt = bv_->getLyXText();
2042 if (!lt->selection.mark())
2045 BufferView::SELECT|BufferView::FITCUR);
2048 moveCursorUpdate(false);
2049 owner_->showState();
2053 case LFUN_WORDRIGHT:
2055 LyXText * lt = bv_->getLyXText();
2057 if (!lt->selection.mark())
2059 update(lt, BufferView::SELECT|BufferView::FITCUR);
2060 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2061 lt->cursorLeftOneWord(bv_);
2063 lt->cursorRightOneWord(bv_);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2076 update(lt, BufferView::SELECT|BufferView::FITCUR);
2077 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2078 lt->cursorRightOneWord(bv_);
2080 lt->cursorLeftOneWord(bv_);
2082 moveCursorUpdate(false);
2083 owner_->showState();
2087 case LFUN_BEGINNINGBUF:
2089 LyXText * lt = bv_->getLyXText();
2091 if (!lt->selection.mark())
2094 BufferView::SELECT|BufferView::FITCUR);
2097 moveCursorUpdate(false);
2098 owner_->showState();
2104 LyXText * lt = bv_->getLyXText();
2106 if (!lt->selection.mark())
2109 BufferView::SELECT|BufferView::FITCUR);
2110 lt->cursorBottom(bv_);
2112 moveCursorUpdate(false);
2113 owner_->showState();
2117 /* cursor selection ---------------------------- */
2120 LyXText * lt = bv_->getLyXText();
2123 BufferView::SELECT|BufferView::FITCUR);
2124 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2125 lt->cursorLeft(bv_);
2127 lt->cursorRight(bv_);
2129 moveCursorUpdate(true);
2130 owner_->showState();
2136 LyXText * lt = bv_->getLyXText();
2139 BufferView::SELECT|BufferView::FITCUR);
2140 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2141 lt->cursorRight(bv_);
2143 lt->cursorLeft(bv_);
2145 moveCursorUpdate(true);
2146 owner_->showState();
2152 LyXText * lt = bv_->getLyXText();
2155 BufferView::SELECT|BufferView::FITCUR);
2158 moveCursorUpdate(true);
2159 owner_->showState();
2165 LyXText * lt = bv_->getLyXText();
2168 BufferView::SELECT|BufferView::FITCUR);
2169 lt->cursorDown(bv_);
2171 moveCursorUpdate(true);
2172 owner_->showState();
2176 case LFUN_UP_PARAGRAPHSEL:
2178 LyXText * lt = bv_->getLyXText();
2181 BufferView::SELECT|BufferView::FITCUR);
2182 lt->cursorUpParagraph(bv_);
2184 moveCursorUpdate(true);
2185 owner_->showState();
2189 case LFUN_DOWN_PARAGRAPHSEL:
2191 LyXText * lt = bv_->getLyXText();
2194 BufferView::SELECT|BufferView::FITCUR);
2195 lt->cursorDownParagraph(bv_);
2197 moveCursorUpdate(true);
2198 owner_->showState();
2204 LyXText * lt = bv_->getLyXText();
2206 update(lt, BufferView::SELECT|BufferView::FITCUR);
2209 moveCursorUpdate(true);
2210 owner_->showState();
2216 LyXText * lt = bv_->getLyXText();
2218 update(lt, BufferView::SELECT|BufferView::FITCUR);
2221 moveCursorUpdate(true);
2222 owner_->showState();
2228 LyXText * lt = bv_->getLyXText();
2230 update(lt, BufferView::SELECT|BufferView::FITCUR);
2231 lt->cursorHome(bv_);
2233 moveCursorUpdate(true);
2234 owner_->showState();
2240 LyXText * lt = bv_->getLyXText();
2242 update(lt, BufferView::SELECT|BufferView::FITCUR);
2245 moveCursorUpdate(true);
2246 owner_->showState();
2250 case LFUN_WORDRIGHTSEL:
2252 LyXText * lt = bv_->getLyXText();
2254 update(lt, BufferView::SELECT|BufferView::FITCUR);
2255 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2256 lt->cursorLeftOneWord(bv_);
2258 lt->cursorRightOneWord(bv_);
2260 moveCursorUpdate(true);
2261 owner_->showState();
2265 case LFUN_WORDLEFTSEL:
2267 LyXText * lt = bv_->getLyXText();
2269 update(lt, BufferView::SELECT|BufferView::FITCUR);
2270 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2271 lt->cursorRightOneWord(bv_);
2273 lt->cursorLeftOneWord(bv_);
2275 moveCursorUpdate(true);
2276 owner_->showState();
2280 case LFUN_BEGINNINGBUFSEL:
2282 LyXText * lt = bv_->getLyXText();
2284 if (lt->inset_owner)
2286 update(lt, BufferView::SELECT|BufferView::FITCUR);
2289 moveCursorUpdate(true);
2290 owner_->showState();
2294 case LFUN_ENDBUFSEL:
2296 LyXText * lt = bv_->getLyXText();
2298 if (lt->inset_owner)
2301 BufferView::SELECT|BufferView::FITCUR);
2302 lt->cursorBottom(bv_);
2304 moveCursorUpdate(true);
2305 owner_->showState();
2309 // --- text changing commands ------------------------
2310 case LFUN_BREAKLINE:
2312 LyXText * lt = bv_->getLyXText();
2315 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2318 | BufferView::FITCUR
2319 | BufferView::CHANGE);
2320 moveCursorUpdate(false);
2324 case LFUN_PROTECTEDSPACE:
2326 LyXText * lt = bv_->getLyXText();
2328 LyXLayout const & style = textclasslist
2329 .Style(buffer_->params.textclass,
2330 lt->cursor.par()->getLayout());
2332 if (style.free_spacing) {
2333 lt->insertChar(bv_, ' ');
2336 | BufferView::FITCUR
2337 | BufferView::CHANGE);
2341 moveCursorUpdate(false);
2347 LyXText * lt = bv_->getLyXText();
2349 if (lt->selection.mark()) {
2353 | BufferView::FITCUR);
2354 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2357 lt->selection.mark(true);
2360 | BufferView::FITCUR);
2361 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2363 lt->selection.cursor = lt->cursor;
2369 LyXText * lt = bv_->getLyXText();
2371 if (!lt->selection.set()) {
2373 lt->selection.cursor = lt->cursor;
2376 | BufferView::FITCUR
2377 | BufferView::CHANGE);
2378 // It is possible to make it a lot faster still
2379 // just comment out the line below...
2384 moveCursorUpdate(false);
2385 owner_->showState();
2390 case LFUN_DELETE_SKIP:
2392 LyXText * lt = bv_->getLyXText();
2394 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2396 LyXCursor cursor = lt->cursor;
2398 if (!lt->selection.set()) {
2399 if (cursor.pos() == cursor.par()->size()) {
2400 lt->cursorRight(bv_);
2401 cursor = lt->cursor;
2402 if (cursor.pos() == 0
2403 && !(cursor.par()->params().spaceTop()
2404 == VSpace (VSpace::NONE))) {
2407 cursor.par()->params().lineTop(),
2408 cursor.par()->params().lineBottom(),
2409 cursor.par()->params().pagebreakTop(),
2410 cursor.par()->params().pagebreakBottom(),
2411 VSpace(VSpace::NONE),
2412 cursor.par()->params().spaceBottom(),
2413 cursor.par()->params().spacing(),
2414 cursor.par()->params().align(),
2415 cursor.par()->params().labelWidthString(), 0);
2416 lt->cursorLeft(bv_);
2419 | BufferView::FITCUR
2420 | BufferView::CHANGE);
2422 lt->cursorLeft(bv_);
2424 lt->selection.cursor = lt->cursor;
2427 | BufferView::FITCUR
2428 | BufferView::CHANGE);
2432 lt->selection.cursor = lt->cursor;
2435 | BufferView::FITCUR
2436 | BufferView::CHANGE);
2444 /* -------> Delete word forward. */
2445 case LFUN_DELETE_WORD_FORWARD:
2446 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2447 bv_->getLyXText()->deleteWordForward(bv_);
2448 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2449 moveCursorUpdate(false);
2450 owner_->showState();
2453 /* -------> Delete word backward. */
2454 case LFUN_DELETE_WORD_BACKWARD:
2456 LyXText * lt = bv_->getLyXText();
2458 update(lt, BufferView::SELECT|BufferView::FITCUR);
2459 lt->deleteWordBackward(bv_);
2462 | BufferView::FITCUR
2463 | BufferView::CHANGE);
2464 moveCursorUpdate(false);
2465 owner_->showState();
2469 /* -------> Kill to end of line. */
2470 case LFUN_DELETE_LINE_FORWARD:
2472 LyXText * lt = bv_->getLyXText();
2474 update(lt, BufferView::SELECT|BufferView::FITCUR);
2475 lt->deleteLineForward(bv_);
2478 | BufferView::FITCUR
2479 | BufferView::CHANGE);
2480 moveCursorUpdate(false);
2484 /* -------> Set mark off. */
2487 LyXText * lt = bv_->getLyXText();
2490 update(lt, BufferView::SELECT|BufferView::FITCUR);
2491 lt->selection.cursor = lt->cursor;
2492 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2496 /* -------> Set mark on. */
2499 LyXText * lt = bv_->getLyXText();
2502 lt->selection.mark(true);
2503 update(lt, BufferView::SELECT|BufferView::FITCUR);
2504 lt->selection.cursor = lt->cursor;
2505 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2509 case LFUN_BACKSPACE:
2511 LyXText * lt = bv_->getLyXText();
2513 if (!lt->selection.set()) {
2514 if (owner_->getIntl()->getTrans().backspace()) {
2516 lt->selection.cursor = lt->cursor;
2519 | BufferView::FITCUR
2520 | BufferView::CHANGE);
2521 // It is possible to make it a lot faster still
2522 // just comment out the line below...
2528 owner_->showState();
2533 case LFUN_BACKSPACE_SKIP:
2535 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2536 LyXText * lt = bv_->getLyXText();
2538 LyXCursor cursor = lt->cursor;
2540 if (!lt->selection.set()) {
2541 if (cursor.pos() == 0
2542 && !(cursor.par()->params().spaceTop()
2543 == VSpace (VSpace::NONE))) {
2546 cursor.par()->params().lineTop(),
2547 cursor.par()->params().lineBottom(),
2548 cursor.par()->params().pagebreakTop(),
2549 cursor.par()->params().pagebreakBottom(),
2550 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2551 cursor.par()->params().spacing(),
2552 cursor.par()->params().align(),
2553 cursor.par()->params().labelWidthString(), 0);
2556 | BufferView::FITCUR
2557 | BufferView::CHANGE);
2560 lt->selection.cursor = cursor;
2563 | BufferView::FITCUR
2564 | BufferView::CHANGE);
2571 case LFUN_BREAKPARAGRAPH:
2573 LyXText * lt = bv_->getLyXText();
2576 lt->breakParagraph(bv_, 0);
2579 | BufferView::FITCUR
2580 | BufferView::CHANGE);
2581 lt->selection.cursor = lt->cursor;
2583 owner_->showState();
2587 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2589 LyXText * lt = bv_->getLyXText();
2592 lt->breakParagraph(bv_, 1);
2595 | BufferView::FITCUR
2596 | BufferView::CHANGE);
2597 lt->selection.cursor = lt->cursor;
2599 owner_->showState();
2603 case LFUN_BREAKPARAGRAPH_SKIP:
2605 // When at the beginning of a paragraph, remove
2606 // indentation and add a "defskip" at the top.
2607 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2608 LyXText * lt = bv_->getLyXText();
2610 LyXCursor cursor = lt->cursor;
2613 if (cursor.pos() == 0) {
2614 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2617 cursor.par()->params().lineTop(),
2618 cursor.par()->params().lineBottom(),
2619 cursor.par()->params().pagebreakTop(),
2620 cursor.par()->params().pagebreakBottom(),
2621 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2622 cursor.par()->params().spacing(),
2623 cursor.par()->params().align(),
2624 cursor.par()->params().labelWidthString(), 1);
2625 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2629 lt->breakParagraph(bv_, 0);
2630 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2635 | BufferView::FITCUR
2636 | BufferView::CHANGE);
2637 lt->selection.cursor = cursor;
2639 owner_->showState();
2643 case LFUN_PARAGRAPH_SPACING:
2645 LyXText * lt = bv_->getLyXText();
2647 Paragraph * par = lt->cursor.par();
2648 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2649 float cur_value = 1.0;
2650 if (cur_spacing == Spacing::Other) {
2651 cur_value = par->params().spacing().getValue();
2654 istringstream istr(argument.c_str());
2658 Spacing::Space new_spacing = cur_spacing;
2659 float new_value = cur_value;
2661 lyxerr << "Missing argument to `paragraph-spacing'"
2663 } else if (tmp == "single") {
2664 new_spacing = Spacing::Single;
2665 } else if (tmp == "onehalf") {
2666 new_spacing = Spacing::Onehalf;
2667 } else if (tmp == "double") {
2668 new_spacing = Spacing::Double;
2669 } else if (tmp == "other") {
2670 new_spacing = Spacing::Other;
2673 lyxerr << "new_value = " << tmpval << endl;
2676 } else if (tmp == "default") {
2677 new_spacing = Spacing::Default;
2679 lyxerr << _("Unknown spacing argument: ")
2680 << argument << endl;
2682 if (cur_spacing != new_spacing || cur_value != new_value) {
2683 par->params().spacing(Spacing(new_spacing, new_value));
2684 lt->redoParagraph(bv_);
2687 | BufferView::FITCUR
2688 | BufferView::CHANGE);
2693 case LFUN_INSET_TOGGLE:
2695 LyXText * lt = bv_->getLyXText();
2698 update(lt, BufferView::SELECT|BufferView::FITCUR);
2699 lt->toggleInset(bv_);
2700 update(lt, BufferView::SELECT|BufferView::FITCUR);
2712 InsetCommandParams p;
2713 if (action == LFUN_HTMLURL)
2714 p.setCmdName("htmlurl");
2716 p.setCmdName("url");
2717 owner_->getDialogs()->createUrl(p.getAsString());
2721 case LFUN_INSERT_URL:
2723 InsetCommandParams p;
2724 p.setFromString(argument);
2726 InsetUrl * inset = new InsetUrl(p);
2727 if (!insertInset(inset))
2730 updateInset(inset, true);
2734 case LFUN_INSET_TEXT:
2735 insertAndEditInset(new InsetText);
2738 case LFUN_INSET_ERT:
2739 insertAndEditInset(new InsetERT);
2742 case LFUN_INSET_EXTERNAL:
2743 insertAndEditInset(new InsetExternal);
2746 case LFUN_INSET_FOOTNOTE:
2747 insertAndEditInset(new InsetFoot);
2750 case LFUN_INSET_MARGINAL:
2751 insertAndEditInset(new InsetMarginal);
2754 case LFUN_INSET_MINIPAGE:
2755 insertAndEditInset(new InsetMinipage);
2758 case LFUN_INSERT_NOTE:
2759 insertAndEditInset(new InsetNote);
2762 case LFUN_INSET_FLOAT:
2763 // check if the float type exist
2764 if (floatList.typeExist(argument)) {
2765 insertAndEditInset(new InsetFloat(argument));
2767 lyxerr << "Non-existent float type: "
2768 << argument << endl;
2772 case LFUN_INSET_WIDE_FLOAT:
2774 // check if the float type exist
2775 if (floatList.typeExist(argument)) {
2776 InsetFloat * new_inset = new InsetFloat(argument);
2777 new_inset->wide(true);
2778 if (insertInset(new_inset))
2779 new_inset->edit(bv_);
2783 lyxerr << "Non-existent float type: "
2784 << argument << endl;
2791 case LFUN_INSET_LIST:
2792 insertAndEditInset(new InsetList);
2795 case LFUN_INSET_THEOREM:
2796 insertAndEditInset(new InsetTheorem);
2800 case LFUN_INSET_CAPTION:
2802 // Do we have a locking inset...
2803 if (bv_->theLockingInset()) {
2804 lyxerr << "Locking inset code: "
2805 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2806 InsetCaption * new_inset = new InsetCaption;
2807 new_inset->setOwner(bv_->theLockingInset());
2808 new_inset->setAutoBreakRows(true);
2809 new_inset->setDrawFrame(0, InsetText::LOCKED);
2810 new_inset->setFrameColor(0, LColor::captionframe);
2811 if (insertInset(new_inset))
2812 new_inset->edit(bv_);
2819 case LFUN_INSET_TABULAR:
2823 if (!argument.empty())
2824 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2825 InsetTabular * new_inset =
2826 new InsetTabular(*buffer_, r, c);
2828 bv_->getLyXText()->real_current_font.isRightToLeft();
2829 if (!open_new_inset(new_inset, rtl))
2834 // --- lyxserver commands ----------------------------
2836 case LFUN_CHARATCURSOR:
2838 pos_type pos = bv_->getLyXText()->cursor.pos();
2839 if (pos < bv_->getLyXText()->cursor.par()->size())
2840 owner_->getLyXFunc()->setMessage(
2841 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2843 owner_->getLyXFunc()->setMessage("EOF");
2848 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2850 + tostr(bv_->getLyXText()->cursor.y()));
2857 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2858 lyxerr << "SETXY: Could not parse coordinates in '"
2859 << argument << std::endl;
2861 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2865 case LFUN_GETLAYOUT:
2866 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2871 LyXFont & font = bv_->getLyXText()->current_font;
2872 if (font.shape() == LyXFont::ITALIC_SHAPE)
2873 owner_->getLyXFunc()->setMessage("E");
2874 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2875 owner_->getLyXFunc()->setMessage("N");
2877 owner_->getLyXFunc()->setMessage("0");
2882 // --- accented characters ---------------------------
2885 case LFUN_CIRCUMFLEX:
2895 case LFUN_SPECIAL_CARON:
2898 case LFUN_HUNG_UMLAUT:
2901 if (argument.empty()) {
2903 owner_->getLyXFunc()->handleKeyFunc(action);
2905 owner_->getLyXFunc()->handleKeyFunc(action);
2906 owner_->getIntl()->getTrans()
2907 .TranslateAndInsert(argument[0], bv_->getLyXText());
2908 update(bv_->getLyXText(),
2910 | BufferView::FITCUR
2911 | BufferView::CHANGE);
2915 case LFUN_MATH_MACRO:
2916 mathDispatchMathMacro(bv_, argument);
2919 case LFUN_MATH_DELIM:
2920 mathDispatchMathDelim(bv_, argument);
2923 case LFUN_INSERT_MATRIX:
2924 mathDispatchInsertMatrix(bv_, argument);
2927 case LFUN_INSERT_MATH:
2928 mathDispatchInsertMath(bv_, argument);
2931 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2932 mathDispatchMathImportSelection(bv_, argument);
2935 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2936 mathDispatchMathDisplay(bv_, argument);
2939 case LFUN_MATH_MODE: // Open or create an inlined math inset
2940 mathDispatchMathMode(bv_, argument);
2943 case LFUN_GREEK: // Insert a single greek letter
2944 mathDispatchGreek(bv_, argument);
2947 case LFUN_CITATION_INSERT:
2949 InsetCommandParams p;
2950 p.setFromString( argument );
2952 InsetCitation * inset = new InsetCitation( p );
2953 if (!insertInset(inset))
2956 updateInset( inset, true );
2960 case LFUN_INSERT_BIBTEX:
2962 // ale970405+lasgoutt970425
2963 // The argument can be up to two tokens separated
2964 // by a space. The first one is the bibstyle.
2965 string const db = token(argument, ' ', 0);
2966 string const bibstyle = token(argument, ' ', 1);
2968 InsetCommandParams p( "BibTeX", db, bibstyle );
2969 InsetBibtex * inset = new InsetBibtex(p);
2971 if (insertInset(inset)) {
2972 if (argument.empty())
2979 // BibTeX data bases
2980 case LFUN_BIBDB_ADD:
2982 InsetBibtex * inset =
2983 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2985 inset->addDatabase(argument);
2990 case LFUN_BIBDB_DEL:
2992 InsetBibtex * inset =
2993 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2995 inset->delDatabase(argument);
3000 case LFUN_BIBTEX_STYLE:
3002 InsetBibtex * inset =
3003 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3005 inset->setOptions(argument);
3010 case LFUN_INDEX_CREATE:
3012 InsetCommandParams p("index");
3013 if (argument.empty()) {
3014 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3015 p.setContents(idxstring);
3017 p.setContents(argument);
3020 owner_->getDialogs()->createIndex(p.getAsString());
3024 case LFUN_INDEX_INSERT:
3026 InsetCommandParams p;
3027 p.setFromString(argument);
3028 InsetIndex * inset = new InsetIndex(p);
3030 if (!insertInset(inset))
3033 updateInset(inset, true);
3037 case LFUN_INDEX_INSERT_LAST:
3039 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3040 if (!idxstring.empty()) {
3041 owner_->message(_("Word `")
3042 + idxstring + _(("' indexed.")));
3043 InsetCommandParams p("index", idxstring);
3044 InsetIndex * inset = new InsetIndex(p);
3046 if (!insertInset(inset))
3049 updateInset(inset, true);
3054 case LFUN_INDEX_PRINT:
3056 InsetCommandParams p("printindex");
3057 Inset * inset = new InsetPrintIndex(p);
3058 if (!insertInset(inset, "Standard"))
3063 case LFUN_PARENTINSERT:
3065 lyxerr << "arg " << argument << endl;
3066 InsetCommandParams p( "lyxparent", argument );
3067 Inset * inset = new InsetParent(p, *buffer_);
3068 if (!insertInset(inset, "Standard"))
3074 case LFUN_CHILD_INSERT:
3076 InsetInclude::Params p;
3077 p.cparams.setFromString(argument);
3078 p.masterFilename_ = buffer_->fileName();
3080 InsetInclude * inset = new InsetInclude(p);
3081 if (!insertInset(inset))
3084 updateInset(inset, true);
3085 bv_->owner()->getDialogs()->showInclude(inset);
3090 case LFUN_FLOAT_LIST:
3092 // We should check the argument for validity. (Lgb)
3093 Inset * inset = new InsetFloatList(argument);
3094 if (!insertInset(inset, "Standard"))
3099 case LFUN_THESAURUS_ENTRY:
3101 string arg = argument;
3104 arg = bv_->getLyXText()->selectionAsString(buffer_,
3108 if (arg.size() > 100 || arg.empty()) {
3109 // Get word or selection
3110 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3111 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3112 // FIXME: where is getLyXText()->unselect(bv_) ?
3116 bv_->owner()->getDialogs()->showThesaurus(arg);
3120 case LFUN_SELFINSERT:
3122 if (argument.empty()) break;
3124 /* Automatically delete the currently selected
3125 * text and replace it with what is being
3126 * typed in now. Depends on lyxrc settings
3127 * "auto_region_delete", which defaults to
3130 LyXText * lt = bv_->getLyXText();
3132 if (lyxrc.auto_region_delete) {
3133 if (lt->selection.set()) {
3134 lt->cutSelection(bv_, false, false);
3137 | BufferView::FITCUR
3138 | BufferView::CHANGE);
3143 LyXFont const old_font(lt->real_current_font);
3145 string::const_iterator cit = argument.begin();
3146 string::const_iterator end = argument.end();
3147 for (; cit != end; ++cit) {
3148 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3153 | BufferView::FITCUR
3154 | BufferView::CHANGE);
3156 lt->selection.cursor = lt->cursor;
3157 moveCursorUpdate(false);
3159 // real_current_font.number can change so we need to
3160 // update the minibuffer
3161 if (old_font != lt->real_current_font)
3162 owner_->showState();
3167 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3169 time_t now_time_t = time(NULL);
3170 struct tm * now_tm = localtime(&now_time_t);
3171 setlocale(LC_TIME, "");
3173 if (!argument.empty())
3176 arg = lyxrc.date_insert_format;
3178 int const datetmp_len =
3179 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3181 LyXText * lt = bv_->getLyXText();
3183 for (int i = 0; i < datetmp_len; i++) {
3184 lt->insertChar(bv_, datetmp[i]);
3187 | BufferView::FITCUR
3188 | BufferView::CHANGE);
3191 lt->selection.cursor = lt->cursor;
3192 moveCursorUpdate(false);
3196 case LFUN_UNKNOWN_ACTION:
3197 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3208 void BufferView::Pimpl::newline()
3211 LyXText * lt = bv_->getLyXText();
3215 | BufferView::FITCUR);
3216 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3219 | BufferView::FITCUR
3220 | BufferView::CHANGE);
3225 void BufferView::Pimpl::hfill()
3228 LyXText * lt = bv_->getLyXText();
3232 | BufferView::FITCUR);
3233 lt->insertChar(bv_, Paragraph::META_HFILL);
3236 | BufferView::FITCUR
3237 | BufferView::CHANGE);
3242 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3246 update(lt, BufferView::SELECT|BufferView::FITCUR);
3247 InsetSpecialChar * new_inset =
3248 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3249 #ifdef WITH_WARNINGS
3250 #warning Why is this code different from specialChar() below? (JMarc)
3251 // the code in specialChar is a generic version of what used to exist
3252 // for other special chars. I did not merge this case because of the
3253 // call to updateInset(), but what does it do?
3255 if (!insertInset(new_inset))
3258 updateInset(new_inset, true);
3263 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3266 LyXText * lt = bv_->getLyXText();
3269 update(lt, BufferView::SELECT|BufferView::FITCUR);
3270 InsetSpecialChar * new_inset =
3271 new InsetSpecialChar(kind);
3272 insertInset(new_inset);
3273 // Ok, what happens here if we are unable to insert
3274 // the inset? Leak it?
3279 void BufferView::Pimpl::smartQuote()
3281 LyXText const * lt = bv_->getLyXText();
3282 Paragraph const * par = lt->cursor.par();
3283 pos_type pos = lt->cursor.pos();
3287 || (par->isInset(pos - 1)
3288 && par->getInset(pos - 1)->isSpace()))
3291 c = par->getChar(pos - 1);
3296 LyXLayout const & style = textclasslist.Style(
3297 bv_->buffer()->params.textclass, par->getLayout());
3299 if (style.pass_thru ||
3300 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3301 Dispatch(LFUN_SELFINSERT, "\"");
3305 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3307 if (insertInset(inset))
3314 // Open and lock an updatable inset
3315 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3317 LyXText * lt = bv_->getLyXText();
3321 if (!insertInset(new_inset)) {
3325 new_inset->edit(bv_, !behind);
3330 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3332 // if we are in a locking inset we should try to insert the
3333 // inset there otherwise this is a illegal function now
3334 if (bv_->theLockingInset()) {
3335 if (bv_->theLockingInset()->insetAllowed(inset))
3336 return bv_->theLockingInset()->insertInset(bv_, inset);
3340 // not quite sure if we want this...
3341 setCursorParUndo(bv_);
3344 beforeChange(bv_->text);
3345 if (!lout.empty()) {
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3347 bv_->text->breakParagraph(bv_);
3348 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3350 if (bv_->text->cursor.par()->size()) {
3351 bv_->text->cursorLeft(bv_);
3353 bv_->text->breakParagraph(bv_);
3354 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3357 pair<bool, layout_type> lres =
3358 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3359 layout_type lay = 0;
3360 if (lres.first != false) {
3364 // layout not fount using default "Standard" (0)
3368 bv_->text->setLayout(bv_, lay);
3370 bv_->text->setParagraph(bv_, 0, 0,
3372 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3377 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3380 bv_->text->insertInset(bv_, inset);
3381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3388 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3393 // first check for locking insets
3394 if (bv_->theLockingInset()) {
3395 if (bv_->theLockingInset() == inset) {
3396 if (bv_->text->updateInset(bv_, inset)) {
3399 buffer_->markDirty();
3404 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3405 if (bv_->text->updateInset(bv_,
3406 bv_->theLockingInset())) {
3409 buffer_->markDirty();
3417 // then check the current buffer
3420 update(bv_->text, BufferView::UPDATE);
3421 if (bv_->text->updateInset(bv_, inset)) {
3425 | BufferView::FITCUR
3426 | BufferView::CHANGE);
3428 update(bv_->text, SELECT);
3436 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3439 if (!available()) return;
3442 beforeChange(bv_->text);
3443 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3445 LyXCursor const & cursor = bv_->text->cursor;
3449 cursor.par()->isInset(cursor.pos())) {
3450 Inset const * inset = cursor.par()->getInset(cursor.pos());
3451 if (find(codes.begin(), codes.end(), inset->lyxCode())
3454 static_cast<InsetCommand const *>(inset)->getContents();
3458 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3459 if (bv_->text->cursor.pos()
3460 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3461 LyXCursor tmp = bv_->text->cursor;
3462 bv_->text->cursor.par(bv_->text->firstParagraph());
3463 bv_->text->cursor.pos(0);
3464 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3465 bv_->text->cursor = tmp;
3466 bv_->owner()->message(_("No more insets"));
3469 bv_->owner()->message(_("No more insets"));
3472 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3473 bv_->text->selection.cursor = bv_->text->cursor;
3477 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3479 gotoInset(vector<Inset::Code>(1, code), same_content);