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, button);
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, button);
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);
866 * Returns an inset if inset was hit. 0 otherwise.
867 * If hit, the coordinates are changed relative to the inset.
868 * Otherwise coordinates are not changed, and false is returned.
870 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
871 unsigned int /* button */)
876 int y_tmp = y + text->first;
879 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
880 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
884 if (cursor.pos() < cursor.par()->size()
885 && cursor.par()->isInset(cursor.pos())
886 && isEditableInset(cursor.par()->getInset(cursor.pos())))
889 } else if ((cursor.pos() - 1 >= 0)
890 && cursor.par()->isInset(cursor.pos() - 1)
891 && isEditableInset(cursor.par()->getInset(cursor.pos() - 1)))
893 pos = cursor.pos() - 1;
894 // if the inset takes a full row, then the cursor.y()
895 // at the end of the inset will be wrong. So step the cursor
897 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
902 // Check whether the inset really was hit
903 Inset * inset = cursor.par()->getInset(pos);
904 LyXFont const & font = text->getFont(buffer_, cursor.par(), pos);
905 int const width = inset->width(bv_, font);
906 int const inset_x = font.isVisibleRightToLeft()
907 ? cursor.x() - width : cursor.x();
908 int const start_x = inset_x + inset->scroll();
909 int const end_x = inset_x + width;
910 int const start_y = cursor.y() - inset->ascent(bv_, font);
911 int const end_y = cursor.y() + inset->descent(bv_, font);
913 if (x > start_x && x < end_x && y_tmp > start_y && y < end_y) {
914 text->setCursor(bv_, cursor.par(), pos, true);
916 // The origin of an inset is on the baseline
917 y = y_tmp - (text->cursor.y());
925 void BufferView::Pimpl::workAreaExpose()
927 static int work_area_width;
928 static unsigned int work_area_height;
930 bool const widthChange = workarea_.workWidth() != work_area_width;
931 bool const heightChange = workarea_.height() != work_area_height;
933 // update from work area
934 work_area_width = workarea_.workWidth();
935 work_area_height = workarea_.height();
938 // The visible LyXView need a resize
941 // Remove all texts from the textcache
942 // This is not _really_ what we want to do. What
943 // we really want to do is to delete in textcache
944 // that does not have a BufferView with matching
945 // width, but as long as we have only one BufferView
946 // deleting all gives the same result.
947 if (lyxerr.debugging())
948 textcache.show(lyxerr, "Expose delete all");
950 } else if (heightChange) {
951 // Rebuild image of current screen
953 // fitCursor() ensures we don't jump back
954 // to the start of the document on vertical
958 // The main window size has changed, repaint most stuff
960 } else if (screen_.get())
961 screen_->redraw(bv_->text, bv_);
963 // Grey box when we don't have a buffer
967 // always make sure that the scrollbar is sane.
969 owner_->updateLayoutChoice();
974 void BufferView::Pimpl::update()
977 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
979 LyXText::text_status st = bv_->text->status();
980 screen_->update(bv_->text, bv_);
982 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
983 if (bv_->text->fullRebreak(bv_)) {
984 st = LyXText::NEED_MORE_REFRESH;
985 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
986 bv_->text->cursor.pos());
989 bv_->text->status(bv_, st);
990 screen_->update(bv_->text, bv_);
992 // do this here instead of in the screen::update because of
994 bv_->text->status(bv_, LyXText::UNCHANGED);
1000 // Values used when calling update:
1002 // -2 - update, move sel_cursor if selection, fitcursor
1003 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1004 // 0 - update, move sel_cursor if selection, fitcursor
1005 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1006 // 3 - update, move sel_cursor if selection
1009 // a simple redraw of the parts that need refresh
1011 // move sel_cursor if selection -
1012 // the text's sel_cursor is moved if there is selection is progress
1015 // fitCursor() is called and the scrollbar updated
1018 // the buffer is marked dirty.
1027 // UPDATE_ONLY = UPDATE;
1028 // UPDATE_SELECT = UPDATE | SELECT;
1029 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1030 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1032 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1033 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1034 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1035 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1036 // update(3) -> update(1) -> update(1) -> update(SELECT)
1038 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1040 owner_->updateLayoutChoice();
1042 if (!text->selection.set() && (f & SELECT)) {
1043 text->selection.cursor = text->cursor;
1046 text->fullRebreak(bv_);
1048 if (text->inset_owner) {
1049 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1050 updateInset(text->inset_owner, false);
1060 buffer_->markDirty();
1065 // Callback for cursor timer
1066 void BufferView::Pimpl::cursorToggle()
1068 // Quite a nice place for asyncron Inset updating, isn't it?
1069 // Actually no! This is run even if no buffer exist... so (Lgb)
1071 cursor_timeout.restart();
1076 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1077 if (pid == -1) // error find out what is wrong
1078 ; // ignore it for now.
1080 sigchldchecker(pid, &status);
1082 updatelist.update(bv_);
1084 if (!screen_.get()) {
1085 cursor_timeout.restart();
1089 if (!bv_->theLockingInset()) {
1090 screen_->cursorToggle(bv_);
1092 bv_->theLockingInset()->toggleInsetCursor(bv_);
1095 cursor_timeout.restart();
1099 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1101 if (!text->cursor.row()->previous())
1104 int y = text->first;
1105 if (text->inset_owner)
1106 y += bv_->text->first;
1107 Row * cursorrow = text->cursor.row();
1108 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1110 // This is to allow jumping over large insets
1111 if ((cursorrow == text->cursor.row()))
1112 text->cursorUp(bv_);
1114 if (text->inset_owner ||
1115 text->cursor.row()->height() < workarea_.height())
1116 screen_->draw(bv_->text, bv_,
1118 - text->cursor.row()->baseline()
1119 + text->cursor.row()->height()
1120 - workarea_.height() + 1 );
1125 void BufferView::Pimpl::cursorNext(LyXText * text)
1127 if (!text->cursor.row()->next())
1130 int y = text->first + workarea_.height();
1131 // if (text->inset_owner)
1132 // y += bv_->text->first;
1133 text->getRowNearY(y);
1135 Row * cursorrow = text->cursor.row();
1136 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1138 // This is to allow jumping over large insets
1139 if ((cursorrow == bv_->text->cursor.row()))
1140 text->cursorDown(bv_);
1142 if (text->inset_owner ||
1143 text->cursor.row()->height() < workarea_.height())
1144 screen_->draw(bv_->text, bv_, text->cursor.y() -
1145 text->cursor.row()->baseline());
1150 bool BufferView::Pimpl::available() const
1152 if (buffer_ && bv_->text) return true;
1157 void BufferView::Pimpl::beforeChange(LyXText * text)
1160 text->clearSelection();
1164 void BufferView::Pimpl::savePosition(unsigned int i)
1166 if (i >= saved_positions_num)
1168 saved_positions[i] = Position(buffer_->fileName(),
1169 bv_->text->cursor.par()->id(),
1170 bv_->text->cursor.pos());
1173 str << _("Saved bookmark") << ' ' << i;
1174 owner_->message(str.str().c_str());
1179 void BufferView::Pimpl::restorePosition(unsigned int i)
1181 if (i >= saved_positions_num)
1184 string const fname = saved_positions[i].filename;
1186 beforeChange(bv_->text);
1188 if (fname != buffer_->fileName()) {
1189 Buffer * b = bufferlist.exists(fname) ?
1190 bufferlist.getBuffer(fname) :
1191 bufferlist.loadLyXFile(fname); // don't ask, just load it
1192 if (b != 0 ) buffer(b);
1195 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1199 bv_->text->setCursor(bv_, par,
1200 min(par->size(), saved_positions[i].par_pos));
1202 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1205 str << _("Moved to bookmark") << ' ' << i;
1206 owner_->message(str.str().c_str());
1211 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1213 if (i >= saved_positions_num)
1216 return !saved_positions[i].filename.empty();
1220 void BufferView::Pimpl::setState()
1222 if (!lyxrc.rtl_support)
1225 LyXText * text = bv_->getLyXText();
1226 if (text->real_current_font.isRightToLeft()) {
1227 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1228 owner_->getIntl()->KeyMapSec();
1230 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1231 owner_->getIntl()->KeyMapPrim();
1236 void BufferView::Pimpl::insetSleep()
1238 if (bv_->theLockingInset() && !inset_slept) {
1239 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1240 bv_->theLockingInset()->insetUnlock(bv_);
1246 void BufferView::Pimpl::insetWakeup()
1248 if (bv_->theLockingInset() && inset_slept) {
1249 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1250 inset_slept = false;
1255 void BufferView::Pimpl::insetUnlock()
1257 if (bv_->theLockingInset()) {
1259 bv_->theLockingInset()->insetUnlock(bv_);
1260 bv_->theLockingInset(0);
1262 inset_slept = false;
1267 bool BufferView::Pimpl::focus() const
1269 return workarea_.hasFocus();
1273 void BufferView::Pimpl::focus(bool f)
1275 if (f) workarea_.setFocus();
1279 bool BufferView::Pimpl::active() const
1281 return workarea_.active();
1285 bool BufferView::Pimpl::belowMouse() const
1287 return workarea_.belowMouse();
1291 void BufferView::Pimpl::showCursor()
1293 if (screen_.get()) {
1294 if (bv_->theLockingInset())
1295 bv_->theLockingInset()->showInsetCursor(bv_);
1297 screen_->showCursor(bv_->text, bv_);
1302 void BufferView::Pimpl::hideCursor()
1304 if (screen_.get()) {
1305 if (!bv_->theLockingInset())
1306 // bv_->theLockingInset()->hideInsetCursor(bv_);
1308 screen_->hideCursor();
1313 void BufferView::Pimpl::toggleSelection(bool b)
1315 if (screen_.get()) {
1316 if (bv_->theLockingInset())
1317 bv_->theLockingInset()->toggleSelection(bv_, b);
1318 screen_->toggleSelection(bv_->text, bv_, b);
1323 void BufferView::Pimpl::toggleToggle()
1326 screen_->toggleToggle(bv_->text, bv_);
1330 void BufferView::Pimpl::center()
1332 beforeChange(bv_->text);
1333 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1334 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1336 screen_->draw(bv_->text, bv_, 0);
1338 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1343 void BufferView::Pimpl::pasteClipboard(bool asPara)
1345 if (!buffer_) return;
1347 screen_->hideCursor();
1348 beforeChange(bv_->text);
1350 string const clip(workarea_.getClipboard());
1352 if (clip.empty()) return;
1355 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1357 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1359 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1363 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1365 workarea_.putClipboard(stuff);
1370 * Dispatch functions for actions which can be valid for BufferView->text
1371 * and/or InsetText->text!!!
1376 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1378 LyXText * lt = bv_->getLyXText();
1380 if (selecting || lt->selection.mark()) {
1381 lt->setSelection(bv_);
1385 update(lt, BufferView::SELECT|BufferView::FITCUR);
1388 /* ---> Everytime the cursor is moved, show the current font state. */
1389 // should this too me moved out of this func?
1390 //owner->showState();
1395 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1397 LyXCursor cursor = bv_->getLyXText()->cursor;
1398 Buffer::inset_iterator it =
1399 find_if(Buffer::inset_iterator(
1400 cursor.par(), cursor.pos()),
1401 buffer_->inset_iterator_end(),
1402 lyx::compare_memfun(&Inset::lyxCode, code));
1403 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1407 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1409 string filename = filen;
1411 if (filename.empty()) {
1412 // Launch a file browser
1413 string initpath = lyxrc.document_path;
1416 string const trypath = owner_->buffer()->filepath;
1417 // If directory is writeable, use this as default.
1418 if (IsDirWriteable(trypath))
1422 FileDialog fileDlg(bv_->owner(),
1423 _("Select LyX document to insert"),
1425 make_pair(string(_("Documents")),
1426 string(lyxrc.document_path)),
1427 make_pair(string(_("Examples")),
1428 string(AddPath(system_lyxdir, "examples"))));
1430 FileDialog::Result result =
1431 fileDlg.Select(initpath,
1432 _("*.lyx| LyX Documents (*.lyx)"));
1434 if (result.first == FileDialog::Later)
1437 filename = result.second;
1439 // check selected filename
1440 if (filename.empty()) {
1441 owner_->message(_("Canceled."));
1446 // get absolute path of file and add ".lyx" to the filename if
1448 filename = FileSearch(string(), filename, "lyx");
1450 string const disp_fn(MakeDisplayPath(filename));
1453 s1 << _("Inserting document") << ' '
1454 << disp_fn << " ...";
1455 owner_->message(s1.str().c_str());
1456 bool const res = bv_->insertLyXFile(filename);
1459 str << _("Document") << ' ' << disp_fn
1460 << ' ' << _("inserted.");
1461 owner_->message(str.str().c_str());
1464 str << _("Could not insert document") << ' '
1466 owner_->message(str.str().c_str());
1471 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1473 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1474 << action <<"] arg[" << argument << "]" << endl;
1477 // --- Misc -------------------------------------------
1481 LyXText * lt = bv_->getLyXText();
1482 lt->toggleAppendix(bv_);
1485 | BufferView::FITCUR
1486 | BufferView::CHANGE);
1491 case LFUN_TOC_INSERT:
1493 InsetCommandParams p;
1494 p.setCmdName("tableofcontents");
1495 Inset * inset = new InsetTOC(p);
1496 if (!insertInset(inset, "Standard"))
1501 case LFUN_TABULAR_FEATURE:
1502 case LFUN_SCROLL_INSET:
1503 // this is not handled here as this funktion is only aktive
1504 // if we have a locking_inset and that one is (or contains)
1508 case LFUN_INSET_GRAPHICS:
1510 Inset * new_inset = new InsetGraphics;
1511 if (!insertInset(new_inset)) {
1514 // this is need because you don't use a inset->Edit()
1515 updateInset(new_inset, true);
1516 new_inset->edit(bv_);
1526 case LFUN_PASTESELECTION:
1528 bool asPara = false;
1529 if (argument == "paragraph") asPara = true;
1530 pasteClipboard(asPara);
1542 case LFUN_LAYOUT_COPY:
1543 bv_->copyEnvironment();
1546 case LFUN_LAYOUT_PASTE:
1547 bv_->pasteEnvironment();
1551 case LFUN_GOTOERROR:
1552 gotoInset(Inset::ERROR_CODE, false);
1556 gotoInset(Inset::IGNORE_CODE, false);
1559 case LFUN_REFERENCE_GOTO:
1561 vector<Inset::Code> tmp;
1562 tmp.push_back(Inset::LABEL_CODE);
1563 tmp.push_back(Inset::REF_CODE);
1564 gotoInset(tmp, true);
1568 case LFUN_HYPHENATION:
1569 specialChar(InsetSpecialChar::HYPHENATION);
1572 case LFUN_LIGATURE_BREAK:
1573 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1577 specialChar(InsetSpecialChar::LDOTS);
1580 case LFUN_END_OF_SENTENCE:
1581 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1584 case LFUN_MENU_SEPARATOR:
1585 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1593 changeDepth(bv_, bv_->getLyXText(), 0);
1596 case LFUN_DEPTH_MIN:
1597 changeDepth(bv_, bv_->getLyXText(), -1);
1600 case LFUN_DEPTH_PLUS:
1601 changeDepth(bv_, bv_->getLyXText(), 1);
1605 owner_->getDialogs()->setUserFreeFont();
1608 case LFUN_FILE_INSERT:
1609 MenuInsertLyXFile(argument);
1612 case LFUN_FILE_INSERT_ASCII_PARA:
1613 InsertAsciiFile(bv_, argument, true);
1616 case LFUN_FILE_INSERT_ASCII:
1617 InsertAsciiFile(bv_, argument, false);
1622 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1623 << argument << endl;
1625 // Derive layout number from given argument (string)
1626 // and current buffer's textclass (number). */
1627 textclass_type tclass = buffer_->params.textclass;
1628 pair <bool, layout_type> layout =
1629 textclasslist.NumberOfLayout(tclass, argument);
1631 // If the entry is obsolete, use the new one instead.
1633 string obs = textclasslist.Style(tclass, layout.second)
1636 layout = textclasslist.NumberOfLayout(tclass, obs);
1639 // see if we found the layout number:
1640 if (!layout.first) {
1641 owner_->getLyXFunc()->setErrorMessage(
1642 string(N_("Layout ")) + argument +
1647 if (current_layout != layout.second) {
1648 LyXText * lt = bv_->getLyXText();
1650 current_layout = layout.second;
1653 | BufferView::FITCUR);
1654 lt->setLayout(bv_, layout.second);
1655 owner_->setLayout(layout.second);
1658 | BufferView::FITCUR
1659 | BufferView::CHANGE);
1666 lang(bv_, argument);
1668 owner_->showState();
1673 owner_->showState();
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1698 owner_->showState();
1703 owner_->showState();
1706 case LFUN_UNDERLINE:
1708 owner_->showState();
1711 case LFUN_FONT_SIZE:
1712 fontSize(bv_, argument);
1713 owner_->showState();
1716 case LFUN_FONT_STATE:
1717 owner_->getLyXFunc()->setMessage(currentState(bv_));
1720 case LFUN_UPCASE_WORD:
1722 LyXText * lt = bv_->getLyXText();
1726 | BufferView::FITCUR);
1727 lt->changeCase(bv_, LyXText::text_uppercase);
1728 if (lt->inset_owner)
1729 updateInset(lt->inset_owner, true);
1732 | BufferView::FITCUR
1733 | BufferView::CHANGE);
1737 case LFUN_LOWCASE_WORD:
1739 LyXText * lt = bv_->getLyXText();
1741 update(lt, BufferView::SELECT|BufferView::FITCUR);
1742 lt->changeCase(bv_, LyXText::text_lowercase);
1743 if (lt->inset_owner)
1744 updateInset(lt->inset_owner, true);
1747 | BufferView::FITCUR
1748 | BufferView::CHANGE);
1752 case LFUN_CAPITALIZE_WORD:
1754 LyXText * lt = bv_->getLyXText();
1756 update(lt, BufferView::SELECT|BufferView::FITCUR);
1757 lt->changeCase(bv_, LyXText::text_capitalization);
1758 if (lt->inset_owner)
1759 updateInset(lt->inset_owner, true);
1762 | BufferView::FITCUR
1763 | BufferView::CHANGE);
1767 case LFUN_TRANSPOSE_CHARS:
1769 LyXText * lt = bv_->getLyXText();
1771 update(lt, BufferView::SELECT|BufferView::FITCUR);
1772 lt->transposeChars(*bv_);
1773 if (lt->inset_owner)
1774 updateInset(lt->inset_owner, true);
1777 | BufferView::FITCUR
1778 | BufferView::CHANGE);
1783 case LFUN_INSERT_LABEL:
1784 MenuInsertLabel(bv_, argument);
1787 case LFUN_REF_INSERT:
1788 if (argument.empty()) {
1789 InsetCommandParams p("ref");
1790 owner_->getDialogs()->createRef(p.getAsString());
1792 InsetCommandParams p;
1793 p.setFromString(argument);
1795 InsetRef * inset = new InsetRef(p, *buffer_);
1796 if (!insertInset(inset))
1799 updateInset(inset, true);
1803 case LFUN_BOOKMARK_SAVE:
1804 savePosition(strToUnsignedInt(argument));
1807 case LFUN_BOOKMARK_GOTO:
1808 restorePosition(strToUnsignedInt(argument));
1813 string label(argument);
1814 if (label.empty()) {
1816 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1818 label = inset->getContents();
1823 if (!label.empty()) {
1824 //bv_->savePosition(0);
1825 if (!bv_->gotoLabel(label))
1826 Alert::alert(_("Error"),
1827 _("Couldn't find this label"),
1828 _("in current document."));
1833 // --- Cursor Movements -----------------------------
1836 LyXText * lt = bv_->getLyXText();
1838 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1839 if (!lt->selection.mark())
1841 update(lt, BufferView::SELECT|BufferView::FITCUR);
1843 lt->cursorLeft(bv_, false);
1844 if (lt->cursor.pos() < lt->cursor.par()->size()
1845 && lt->cursor.par()->isInset(lt->cursor.pos())
1846 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1847 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1848 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1850 tmpinset->edit(bv_, false);
1852 tmpinset->edit(bv_);
1856 lt->cursorRight(bv_, false);
1858 moveCursorUpdate(false);
1859 owner_->showState();
1865 // This is soooo ugly. Isn`t it possible to make
1866 // it simpler? (Lgb)
1867 LyXText * lt = bv_->getLyXText();
1868 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1869 if (!lt->selection.mark())
1871 update(lt, BufferView::SELECT|BufferView::FITCUR);
1872 LyXCursor const cur = lt->cursor;
1874 lt->cursorLeft(bv_, false);
1875 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1876 lt->cursor.pos() < lt->cursor.par()->size() &&
1877 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1878 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1879 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1880 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1882 tmpinset->edit(bv_);
1884 tmpinset->edit(bv_, false);
1888 lt->cursorRight(bv_, false);
1891 moveCursorUpdate(false);
1892 owner_->showState();
1898 LyXText * lt = bv_->getLyXText();
1900 if (!lt->selection.mark())
1902 update(lt, BufferView::UPDATE);
1905 moveCursorUpdate(false);
1906 owner_->showState();
1912 LyXText * lt = bv_->getLyXText();
1914 if (!lt->selection.mark())
1916 update(lt, BufferView::UPDATE);
1917 lt->cursorDown(bv_);
1919 moveCursorUpdate(false);
1920 owner_->showState();
1924 case LFUN_UP_PARAGRAPH:
1926 LyXText * lt = bv_->getLyXText();
1928 if (!lt->selection.mark())
1930 update(lt, BufferView::UPDATE);
1931 lt->cursorUpParagraph(bv_);
1933 moveCursorUpdate(false);
1934 owner_->showState();
1938 case LFUN_DOWN_PARAGRAPH:
1940 LyXText * lt = bv_->getLyXText();
1942 if (!lt->selection.mark())
1944 update(lt, BufferView::UPDATE);
1945 lt->cursorDownParagraph(bv_);
1947 moveCursorUpdate(false);
1948 owner_->showState();
1954 LyXText * lt = bv_->getLyXText();
1956 if (!lt->selection.mark())
1958 update(lt, BufferView::UPDATE);
1961 moveCursorUpdate(false);
1962 owner_->showState();
1968 LyXText * lt = bv_->getLyXText();
1970 if (!lt->selection.mark())
1972 update(lt, BufferView::UPDATE);
1975 moveCursorUpdate(false);
1976 owner_->showState();
1982 LyXText * lt = bv_->getLyXText();
1984 if (!lt->selection.mark())
1986 update(lt, BufferView::SELECT|BufferView::FITCUR);
1987 lt->cursorHome(bv_);
1989 moveCursorUpdate(false);
1990 owner_->showState();
1996 LyXText * lt = bv_->getLyXText();
1998 if (!lt->selection.mark())
2001 BufferView::SELECT|BufferView::FITCUR);
2004 moveCursorUpdate(false);
2005 owner_->showState();
2009 case LFUN_SHIFT_TAB:
2012 LyXText * lt = bv_->getLyXText();
2014 if (!lt->selection.mark())
2017 BufferView::SELECT|BufferView::FITCUR);
2020 moveCursorUpdate(false);
2021 owner_->showState();
2025 case LFUN_WORDRIGHT:
2027 LyXText * lt = bv_->getLyXText();
2029 if (!lt->selection.mark())
2031 update(lt, BufferView::SELECT|BufferView::FITCUR);
2032 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2033 lt->cursorLeftOneWord(bv_);
2035 lt->cursorRightOneWord(bv_);
2037 moveCursorUpdate(false);
2038 owner_->showState();
2044 LyXText * lt = bv_->getLyXText();
2046 if (!lt->selection.mark())
2048 update(lt, BufferView::SELECT|BufferView::FITCUR);
2049 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2050 lt->cursorRightOneWord(bv_);
2052 lt->cursorLeftOneWord(bv_);
2054 moveCursorUpdate(false);
2055 owner_->showState();
2059 case LFUN_BEGINNINGBUF:
2061 LyXText * lt = bv_->getLyXText();
2063 if (!lt->selection.mark())
2066 BufferView::SELECT|BufferView::FITCUR);
2069 moveCursorUpdate(false);
2070 owner_->showState();
2076 LyXText * lt = bv_->getLyXText();
2078 if (!lt->selection.mark())
2081 BufferView::SELECT|BufferView::FITCUR);
2082 lt->cursorBottom(bv_);
2084 moveCursorUpdate(false);
2085 owner_->showState();
2089 /* cursor selection ---------------------------- */
2092 LyXText * lt = bv_->getLyXText();
2095 BufferView::SELECT|BufferView::FITCUR);
2096 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2097 lt->cursorLeft(bv_);
2099 lt->cursorRight(bv_);
2101 moveCursorUpdate(true);
2102 owner_->showState();
2108 LyXText * lt = bv_->getLyXText();
2111 BufferView::SELECT|BufferView::FITCUR);
2112 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2113 lt->cursorRight(bv_);
2115 lt->cursorLeft(bv_);
2117 moveCursorUpdate(true);
2118 owner_->showState();
2124 LyXText * lt = bv_->getLyXText();
2127 BufferView::SELECT|BufferView::FITCUR);
2130 moveCursorUpdate(true);
2131 owner_->showState();
2137 LyXText * lt = bv_->getLyXText();
2140 BufferView::SELECT|BufferView::FITCUR);
2141 lt->cursorDown(bv_);
2143 moveCursorUpdate(true);
2144 owner_->showState();
2148 case LFUN_UP_PARAGRAPHSEL:
2150 LyXText * lt = bv_->getLyXText();
2153 BufferView::SELECT|BufferView::FITCUR);
2154 lt->cursorUpParagraph(bv_);
2156 moveCursorUpdate(true);
2157 owner_->showState();
2161 case LFUN_DOWN_PARAGRAPHSEL:
2163 LyXText * lt = bv_->getLyXText();
2166 BufferView::SELECT|BufferView::FITCUR);
2167 lt->cursorDownParagraph(bv_);
2169 moveCursorUpdate(true);
2170 owner_->showState();
2176 LyXText * lt = bv_->getLyXText();
2178 update(lt, BufferView::SELECT|BufferView::FITCUR);
2181 moveCursorUpdate(true);
2182 owner_->showState();
2188 LyXText * lt = bv_->getLyXText();
2190 update(lt, BufferView::SELECT|BufferView::FITCUR);
2193 moveCursorUpdate(true);
2194 owner_->showState();
2200 LyXText * lt = bv_->getLyXText();
2202 update(lt, BufferView::SELECT|BufferView::FITCUR);
2203 lt->cursorHome(bv_);
2205 moveCursorUpdate(true);
2206 owner_->showState();
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 moveCursorUpdate(true);
2218 owner_->showState();
2222 case LFUN_WORDRIGHTSEL:
2224 LyXText * lt = bv_->getLyXText();
2226 update(lt, BufferView::SELECT|BufferView::FITCUR);
2227 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2228 lt->cursorLeftOneWord(bv_);
2230 lt->cursorRightOneWord(bv_);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2237 case LFUN_WORDLEFTSEL:
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2242 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2243 lt->cursorRightOneWord(bv_);
2245 lt->cursorLeftOneWord(bv_);
2247 moveCursorUpdate(true);
2248 owner_->showState();
2252 case LFUN_BEGINNINGBUFSEL:
2254 LyXText * lt = bv_->getLyXText();
2256 if (lt->inset_owner)
2258 update(lt, BufferView::SELECT|BufferView::FITCUR);
2261 moveCursorUpdate(true);
2262 owner_->showState();
2266 case LFUN_ENDBUFSEL:
2268 LyXText * lt = bv_->getLyXText();
2270 if (lt->inset_owner)
2273 BufferView::SELECT|BufferView::FITCUR);
2274 lt->cursorBottom(bv_);
2276 moveCursorUpdate(true);
2277 owner_->showState();
2281 // --- text changing commands ------------------------
2282 case LFUN_BREAKLINE:
2284 LyXText * lt = bv_->getLyXText();
2287 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2290 | BufferView::FITCUR
2291 | BufferView::CHANGE);
2292 moveCursorUpdate(false);
2296 case LFUN_PROTECTEDSPACE:
2298 LyXText * lt = bv_->getLyXText();
2300 LyXLayout const & style = textclasslist
2301 .Style(buffer_->params.textclass,
2302 lt->cursor.par()->getLayout());
2304 if (style.free_spacing) {
2305 lt->insertChar(bv_, ' ');
2308 | BufferView::FITCUR
2309 | BufferView::CHANGE);
2313 moveCursorUpdate(false);
2319 LyXText * lt = bv_->getLyXText();
2321 if (lt->selection.mark()) {
2325 | BufferView::FITCUR);
2326 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2329 lt->selection.mark(true);
2332 | BufferView::FITCUR);
2333 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2335 lt->selection.cursor = lt->cursor;
2341 LyXText * lt = bv_->getLyXText();
2343 if (!lt->selection.set()) {
2345 lt->selection.cursor = lt->cursor;
2348 | BufferView::FITCUR
2349 | BufferView::CHANGE);
2350 // It is possible to make it a lot faster still
2351 // just comment out the line below...
2356 moveCursorUpdate(false);
2357 owner_->showState();
2362 case LFUN_DELETE_SKIP:
2364 LyXText * lt = bv_->getLyXText();
2366 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2368 LyXCursor cursor = lt->cursor;
2370 if (!lt->selection.set()) {
2371 if (cursor.pos() == cursor.par()->size()) {
2372 lt->cursorRight(bv_);
2373 cursor = lt->cursor;
2374 if (cursor.pos() == 0
2375 && !(cursor.par()->params().spaceTop()
2376 == VSpace (VSpace::NONE))) {
2379 cursor.par()->params().lineTop(),
2380 cursor.par()->params().lineBottom(),
2381 cursor.par()->params().pagebreakTop(),
2382 cursor.par()->params().pagebreakBottom(),
2383 VSpace(VSpace::NONE),
2384 cursor.par()->params().spaceBottom(),
2385 cursor.par()->params().spacing(),
2386 cursor.par()->params().align(),
2387 cursor.par()->params().labelWidthString(), 0);
2388 lt->cursorLeft(bv_);
2391 | BufferView::FITCUR
2392 | BufferView::CHANGE);
2394 lt->cursorLeft(bv_);
2396 lt->selection.cursor = lt->cursor;
2399 | BufferView::FITCUR
2400 | BufferView::CHANGE);
2404 lt->selection.cursor = lt->cursor;
2407 | BufferView::FITCUR
2408 | BufferView::CHANGE);
2416 /* -------> Delete word forward. */
2417 case LFUN_DELETE_WORD_FORWARD:
2418 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2419 bv_->getLyXText()->deleteWordForward(bv_);
2420 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2421 moveCursorUpdate(false);
2422 owner_->showState();
2425 /* -------> Delete word backward. */
2426 case LFUN_DELETE_WORD_BACKWARD:
2428 LyXText * lt = bv_->getLyXText();
2430 update(lt, BufferView::SELECT|BufferView::FITCUR);
2431 lt->deleteWordBackward(bv_);
2434 | BufferView::FITCUR
2435 | BufferView::CHANGE);
2436 moveCursorUpdate(false);
2437 owner_->showState();
2441 /* -------> Kill to end of line. */
2442 case LFUN_DELETE_LINE_FORWARD:
2444 LyXText * lt = bv_->getLyXText();
2446 update(lt, BufferView::SELECT|BufferView::FITCUR);
2447 lt->deleteLineForward(bv_);
2450 | BufferView::FITCUR
2451 | BufferView::CHANGE);
2452 moveCursorUpdate(false);
2456 /* -------> Set mark off. */
2459 LyXText * lt = bv_->getLyXText();
2462 update(lt, BufferView::SELECT|BufferView::FITCUR);
2463 lt->selection.cursor = lt->cursor;
2464 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2468 /* -------> Set mark on. */
2471 LyXText * lt = bv_->getLyXText();
2474 lt->selection.mark(true);
2475 update(lt, BufferView::SELECT|BufferView::FITCUR);
2476 lt->selection.cursor = lt->cursor;
2477 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2481 case LFUN_BACKSPACE:
2483 LyXText * lt = bv_->getLyXText();
2485 if (!lt->selection.set()) {
2486 if (owner_->getIntl()->getTrans().backspace()) {
2488 lt->selection.cursor = lt->cursor;
2491 | BufferView::FITCUR
2492 | BufferView::CHANGE);
2493 // It is possible to make it a lot faster still
2494 // just comment out the line below...
2500 owner_->showState();
2505 case LFUN_BACKSPACE_SKIP:
2507 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2508 LyXText * lt = bv_->getLyXText();
2510 LyXCursor cursor = lt->cursor;
2512 if (!lt->selection.set()) {
2513 if (cursor.pos() == 0
2514 && !(cursor.par()->params().spaceTop()
2515 == VSpace (VSpace::NONE))) {
2518 cursor.par()->params().lineTop(),
2519 cursor.par()->params().lineBottom(),
2520 cursor.par()->params().pagebreakTop(),
2521 cursor.par()->params().pagebreakBottom(),
2522 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2523 cursor.par()->params().spacing(),
2524 cursor.par()->params().align(),
2525 cursor.par()->params().labelWidthString(), 0);
2528 | BufferView::FITCUR
2529 | BufferView::CHANGE);
2532 lt->selection.cursor = cursor;
2535 | BufferView::FITCUR
2536 | BufferView::CHANGE);
2543 case LFUN_BREAKPARAGRAPH:
2545 LyXText * lt = bv_->getLyXText();
2548 lt->breakParagraph(bv_, 0);
2551 | BufferView::FITCUR
2552 | BufferView::CHANGE);
2553 lt->selection.cursor = lt->cursor;
2555 owner_->showState();
2559 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2561 LyXText * lt = bv_->getLyXText();
2564 lt->breakParagraph(bv_, 1);
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2569 lt->selection.cursor = lt->cursor;
2571 owner_->showState();
2575 case LFUN_BREAKPARAGRAPH_SKIP:
2577 // When at the beginning of a paragraph, remove
2578 // indentation and add a "defskip" at the top.
2579 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2580 LyXText * lt = bv_->getLyXText();
2582 LyXCursor cursor = lt->cursor;
2585 if (cursor.pos() == 0) {
2586 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2589 cursor.par()->params().lineTop(),
2590 cursor.par()->params().lineBottom(),
2591 cursor.par()->params().pagebreakTop(),
2592 cursor.par()->params().pagebreakBottom(),
2593 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2594 cursor.par()->params().spacing(),
2595 cursor.par()->params().align(),
2596 cursor.par()->params().labelWidthString(), 1);
2597 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2601 lt->breakParagraph(bv_, 0);
2602 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2607 | BufferView::FITCUR
2608 | BufferView::CHANGE);
2609 lt->selection.cursor = cursor;
2611 owner_->showState();
2615 case LFUN_PARAGRAPH_SPACING:
2617 LyXText * lt = bv_->getLyXText();
2619 Paragraph * par = lt->cursor.par();
2620 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2621 float cur_value = 1.0;
2622 if (cur_spacing == Spacing::Other) {
2623 cur_value = par->params().spacing().getValue();
2626 istringstream istr(argument.c_str());
2630 Spacing::Space new_spacing = cur_spacing;
2631 float new_value = cur_value;
2633 lyxerr << "Missing argument to `paragraph-spacing'"
2635 } else if (tmp == "single") {
2636 new_spacing = Spacing::Single;
2637 } else if (tmp == "onehalf") {
2638 new_spacing = Spacing::Onehalf;
2639 } else if (tmp == "double") {
2640 new_spacing = Spacing::Double;
2641 } else if (tmp == "other") {
2642 new_spacing = Spacing::Other;
2645 lyxerr << "new_value = " << tmpval << endl;
2648 } else if (tmp == "default") {
2649 new_spacing = Spacing::Default;
2651 lyxerr << _("Unknown spacing argument: ")
2652 << argument << endl;
2654 if (cur_spacing != new_spacing || cur_value != new_value) {
2655 par->params().spacing(Spacing(new_spacing, new_value));
2656 lt->redoParagraph(bv_);
2659 | BufferView::FITCUR
2660 | BufferView::CHANGE);
2665 case LFUN_INSET_TOGGLE:
2667 LyXText * lt = bv_->getLyXText();
2670 update(lt, BufferView::SELECT|BufferView::FITCUR);
2671 lt->toggleInset(bv_);
2672 update(lt, BufferView::SELECT|BufferView::FITCUR);
2684 InsetCommandParams p;
2685 if (action == LFUN_HTMLURL)
2686 p.setCmdName("htmlurl");
2688 p.setCmdName("url");
2689 owner_->getDialogs()->createUrl(p.getAsString());
2693 case LFUN_INSERT_URL:
2695 InsetCommandParams p;
2696 p.setFromString(argument);
2698 InsetUrl * inset = new InsetUrl(p);
2699 if (!insertInset(inset))
2702 updateInset(inset, true);
2706 case LFUN_INSET_TEXT:
2707 insertAndEditInset(new InsetText);
2710 case LFUN_INSET_ERT:
2711 insertAndEditInset(new InsetERT);
2714 case LFUN_INSET_EXTERNAL:
2715 insertAndEditInset(new InsetExternal);
2718 case LFUN_INSET_FOOTNOTE:
2719 insertAndEditInset(new InsetFoot);
2722 case LFUN_INSET_MARGINAL:
2723 insertAndEditInset(new InsetMarginal);
2726 case LFUN_INSET_MINIPAGE:
2727 insertAndEditInset(new InsetMinipage);
2730 case LFUN_INSERT_NOTE:
2731 insertAndEditInset(new InsetNote);
2734 case LFUN_INSET_FLOAT:
2735 // check if the float type exist
2736 if (floatList.typeExist(argument)) {
2737 insertAndEditInset(new InsetFloat(argument));
2739 lyxerr << "Non-existent float type: "
2740 << argument << endl;
2744 case LFUN_INSET_WIDE_FLOAT:
2746 // check if the float type exist
2747 if (floatList.typeExist(argument)) {
2748 InsetFloat * new_inset = new InsetFloat(argument);
2749 new_inset->wide(true);
2750 if (insertInset(new_inset))
2751 new_inset->edit(bv_);
2755 lyxerr << "Non-existent float type: "
2756 << argument << endl;
2763 case LFUN_INSET_LIST:
2764 insertAndEditInset(new InsetList);
2767 case LFUN_INSET_THEOREM:
2768 insertAndEditInset(new InsetTheorem);
2772 case LFUN_INSET_CAPTION:
2774 // Do we have a locking inset...
2775 if (bv_->theLockingInset()) {
2776 lyxerr << "Locking inset code: "
2777 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2778 InsetCaption * new_inset = new InsetCaption;
2779 new_inset->setOwner(bv_->theLockingInset());
2780 new_inset->setAutoBreakRows(true);
2781 new_inset->setDrawFrame(0, InsetText::LOCKED);
2782 new_inset->setFrameColor(0, LColor::captionframe);
2783 if (insertInset(new_inset))
2784 new_inset->edit(bv_);
2791 case LFUN_INSET_TABULAR:
2795 if (!argument.empty())
2796 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2797 InsetTabular * new_inset =
2798 new InsetTabular(*buffer_, r, c);
2800 bv_->getLyXText()->real_current_font.isRightToLeft();
2801 if (!open_new_inset(new_inset, rtl))
2806 // --- lyxserver commands ----------------------------
2808 case LFUN_CHARATCURSOR:
2810 pos_type pos = bv_->getLyXText()->cursor.pos();
2811 if (pos < bv_->getLyXText()->cursor.par()->size())
2812 owner_->getLyXFunc()->setMessage(
2813 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2815 owner_->getLyXFunc()->setMessage("EOF");
2820 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2822 + tostr(bv_->getLyXText()->cursor.y()));
2829 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2830 lyxerr << "SETXY: Could not parse coordinates in '"
2831 << argument << std::endl;
2833 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2837 case LFUN_GETLAYOUT:
2838 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2843 LyXFont & font = bv_->getLyXText()->current_font;
2844 if (font.shape() == LyXFont::ITALIC_SHAPE)
2845 owner_->getLyXFunc()->setMessage("E");
2846 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2847 owner_->getLyXFunc()->setMessage("N");
2849 owner_->getLyXFunc()->setMessage("0");
2854 // --- accented characters ---------------------------
2857 case LFUN_CIRCUMFLEX:
2867 case LFUN_SPECIAL_CARON:
2870 case LFUN_HUNG_UMLAUT:
2873 if (argument.empty()) {
2875 owner_->getLyXFunc()->handleKeyFunc(action);
2877 owner_->getLyXFunc()->handleKeyFunc(action);
2878 owner_->getIntl()->getTrans()
2879 .TranslateAndInsert(argument[0], bv_->getLyXText());
2880 update(bv_->getLyXText(),
2882 | BufferView::FITCUR
2883 | BufferView::CHANGE);
2887 case LFUN_MATH_MACRO:
2888 mathDispatchMathMacro(bv_, argument);
2891 case LFUN_MATH_DELIM:
2892 mathDispatchMathDelim(bv_, argument);
2895 case LFUN_INSERT_MATRIX:
2896 mathDispatchInsertMatrix(bv_, argument);
2899 case LFUN_INSERT_MATH:
2900 mathDispatchInsertMath(bv_, argument);
2903 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2904 mathDispatchMathImportSelection(bv_, argument);
2907 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2908 mathDispatchMathDisplay(bv_, argument);
2911 case LFUN_MATH_MODE: // Open or create an inlined math inset
2912 mathDispatchMathMode(bv_, argument);
2915 case LFUN_GREEK: // Insert a single greek letter
2916 mathDispatchGreek(bv_, argument);
2919 case LFUN_CITATION_INSERT:
2921 InsetCommandParams p;
2922 p.setFromString( argument );
2924 InsetCitation * inset = new InsetCitation( p );
2925 if (!insertInset(inset))
2928 updateInset( inset, true );
2932 case LFUN_INSERT_BIBTEX:
2934 // ale970405+lasgoutt970425
2935 // The argument can be up to two tokens separated
2936 // by a space. The first one is the bibstyle.
2937 string const db = token(argument, ' ', 0);
2938 string const bibstyle = token(argument, ' ', 1);
2940 InsetCommandParams p( "BibTeX", db, bibstyle );
2941 InsetBibtex * inset = new InsetBibtex(p);
2943 if (insertInset(inset)) {
2944 if (argument.empty())
2951 // BibTeX data bases
2952 case LFUN_BIBDB_ADD:
2954 InsetBibtex * inset =
2955 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2957 inset->addDatabase(argument);
2962 case LFUN_BIBDB_DEL:
2964 InsetBibtex * inset =
2965 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2967 inset->delDatabase(argument);
2972 case LFUN_BIBTEX_STYLE:
2974 InsetBibtex * inset =
2975 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2977 inset->setOptions(argument);
2982 case LFUN_INDEX_CREATE:
2984 InsetCommandParams p("index");
2985 if (argument.empty()) {
2986 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2987 p.setContents(idxstring);
2989 p.setContents(argument);
2992 owner_->getDialogs()->createIndex(p.getAsString());
2996 case LFUN_INDEX_INSERT:
2998 InsetCommandParams p;
2999 p.setFromString(argument);
3000 InsetIndex * inset = new InsetIndex(p);
3002 if (!insertInset(inset))
3005 updateInset(inset, true);
3009 case LFUN_INDEX_INSERT_LAST:
3011 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3012 if (!idxstring.empty()) {
3013 owner_->message(_("Word `")
3014 + idxstring + _(("' indexed.")));
3015 InsetCommandParams p("index", idxstring);
3016 InsetIndex * inset = new InsetIndex(p);
3018 if (!insertInset(inset))
3021 updateInset(inset, true);
3026 case LFUN_INDEX_PRINT:
3028 InsetCommandParams p("printindex");
3029 Inset * inset = new InsetPrintIndex(p);
3030 if (!insertInset(inset, "Standard"))
3035 case LFUN_PARENTINSERT:
3037 lyxerr << "arg " << argument << endl;
3038 InsetCommandParams p( "lyxparent", argument );
3039 Inset * inset = new InsetParent(p, *buffer_);
3040 if (!insertInset(inset, "Standard"))
3046 case LFUN_CHILD_INSERT:
3048 InsetInclude::Params p;
3049 p.cparams.setFromString(argument);
3050 p.masterFilename_ = buffer_->fileName();
3052 InsetInclude * inset = new InsetInclude(p);
3053 if (!insertInset(inset))
3056 updateInset(inset, true);
3057 bv_->owner()->getDialogs()->showInclude(inset);
3062 case LFUN_FLOAT_LIST:
3064 // We should check the argument for validity. (Lgb)
3065 Inset * inset = new InsetFloatList(argument);
3066 if (!insertInset(inset, "Standard"))
3071 case LFUN_THESAURUS_ENTRY:
3073 string arg = argument;
3076 arg = bv_->getLyXText()->selectionAsString(buffer_,
3080 if (arg.size() > 100 || arg.empty()) {
3081 // Get word or selection
3082 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3083 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3084 // FIXME: where is getLyXText()->unselect(bv_) ?
3088 bv_->owner()->getDialogs()->showThesaurus(arg);
3092 case LFUN_SELFINSERT:
3094 if (argument.empty()) break;
3096 /* Automatically delete the currently selected
3097 * text and replace it with what is being
3098 * typed in now. Depends on lyxrc settings
3099 * "auto_region_delete", which defaults to
3102 LyXText * lt = bv_->getLyXText();
3104 if (lyxrc.auto_region_delete) {
3105 if (lt->selection.set()) {
3106 lt->cutSelection(bv_, false, false);
3109 | BufferView::FITCUR
3110 | BufferView::CHANGE);
3115 LyXFont const old_font(lt->real_current_font);
3117 string::const_iterator cit = argument.begin();
3118 string::const_iterator end = argument.end();
3119 for (; cit != end; ++cit) {
3120 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3125 | BufferView::FITCUR
3126 | BufferView::CHANGE);
3128 lt->selection.cursor = lt->cursor;
3129 moveCursorUpdate(false);
3131 // real_current_font.number can change so we need to
3132 // update the minibuffer
3133 if (old_font != lt->real_current_font)
3134 owner_->showState();
3139 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3141 time_t now_time_t = time(NULL);
3142 struct tm * now_tm = localtime(&now_time_t);
3143 setlocale(LC_TIME, "");
3145 if (!argument.empty())
3148 arg = lyxrc.date_insert_format;
3150 int const datetmp_len =
3151 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3153 LyXText * lt = bv_->getLyXText();
3155 for (int i = 0; i < datetmp_len; i++) {
3156 lt->insertChar(bv_, datetmp[i]);
3159 | BufferView::FITCUR
3160 | BufferView::CHANGE);
3163 lt->selection.cursor = lt->cursor;
3164 moveCursorUpdate(false);
3168 case LFUN_UNKNOWN_ACTION:
3169 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3180 void BufferView::Pimpl::newline()
3183 LyXText * lt = bv_->getLyXText();
3187 | BufferView::FITCUR);
3188 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3191 | BufferView::FITCUR
3192 | BufferView::CHANGE);
3197 void BufferView::Pimpl::hfill()
3200 LyXText * lt = bv_->getLyXText();
3204 | BufferView::FITCUR);
3205 lt->insertChar(bv_, Paragraph::META_HFILL);
3208 | BufferView::FITCUR
3209 | BufferView::CHANGE);
3214 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3218 update(lt, BufferView::SELECT|BufferView::FITCUR);
3219 InsetSpecialChar * new_inset =
3220 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3221 #ifdef WITH_WARNINGS
3222 #warning Why is this code different from specialChar() below? (JMarc)
3223 // the code in specialChar is a generic version of what used to exist
3224 // for other special chars. I did not merge this case because of the
3225 // call to updateInset(), but what does it do?
3227 if (!insertInset(new_inset))
3230 updateInset(new_inset, true);
3235 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3238 LyXText * lt = bv_->getLyXText();
3241 update(lt, BufferView::SELECT|BufferView::FITCUR);
3242 InsetSpecialChar * new_inset =
3243 new InsetSpecialChar(kind);
3244 insertInset(new_inset);
3245 // Ok, what happens here if we are unable to insert
3246 // the inset? Leak it?
3251 void BufferView::Pimpl::smartQuote()
3253 LyXText const * lt = bv_->getLyXText();
3254 Paragraph const * par = lt->cursor.par();
3255 pos_type pos = lt->cursor.pos();
3259 || (par->isInset(pos - 1)
3260 && par->getInset(pos - 1)->isSpace()))
3263 c = par->getChar(pos - 1);
3268 LyXLayout const & style = textclasslist.Style(
3269 bv_->buffer()->params.textclass, par->getLayout());
3271 if (style.pass_thru ||
3272 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3273 Dispatch(LFUN_SELFINSERT, "\"");
3277 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3279 if (insertInset(inset))
3286 // Open and lock an updatable inset
3287 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3289 LyXText * lt = bv_->getLyXText();
3293 if (!insertInset(new_inset)) {
3297 new_inset->edit(bv_, !behind);
3302 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3304 // if we are in a locking inset we should try to insert the
3305 // inset there otherwise this is a illegal function now
3306 if (bv_->theLockingInset()) {
3307 if (bv_->theLockingInset()->insetAllowed(inset))
3308 return bv_->theLockingInset()->insertInset(bv_, inset);
3312 // not quite sure if we want this...
3313 setCursorParUndo(bv_);
3316 beforeChange(bv_->text);
3317 if (!lout.empty()) {
3318 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3319 bv_->text->breakParagraph(bv_);
3320 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3322 if (bv_->text->cursor.par()->size()) {
3323 bv_->text->cursorLeft(bv_);
3325 bv_->text->breakParagraph(bv_);
3326 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3329 pair<bool, layout_type> lres =
3330 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3331 layout_type lay = 0;
3332 if (lres.first != false) {
3336 // layout not fount using default "Standard" (0)
3340 bv_->text->setLayout(bv_, lay);
3342 bv_->text->setParagraph(bv_, 0, 0,
3344 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3352 bv_->text->insertInset(bv_, inset);
3353 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3360 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3365 // first check for locking insets
3366 if (bv_->theLockingInset()) {
3367 if (bv_->theLockingInset() == inset) {
3368 if (bv_->text->updateInset(bv_, inset)) {
3371 buffer_->markDirty();
3376 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3377 if (bv_->text->updateInset(bv_,
3378 bv_->theLockingInset())) {
3381 buffer_->markDirty();
3389 // then check the current buffer
3392 update(bv_->text, BufferView::UPDATE);
3393 if (bv_->text->updateInset(bv_, inset)) {
3397 | BufferView::FITCUR
3398 | BufferView::CHANGE);
3400 update(bv_->text, SELECT);
3408 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3411 if (!available()) return;
3414 beforeChange(bv_->text);
3415 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3417 LyXCursor const & cursor = bv_->text->cursor;
3421 cursor.par()->isInset(cursor.pos())) {
3422 Inset const * inset = cursor.par()->getInset(cursor.pos());
3423 if (find(codes.begin(), codes.end(), inset->lyxCode())
3426 static_cast<InsetCommand const *>(inset)->getContents();
3430 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3431 if (bv_->text->cursor.pos()
3432 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3433 LyXCursor tmp = bv_->text->cursor;
3434 bv_->text->cursor.par(bv_->text->firstParagraph());
3435 bv_->text->cursor.pos(0);
3436 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3437 bv_->text->cursor = tmp;
3438 bv_->owner()->message(_("No more insets"));
3441 bv_->owner()->message(_("No more insets"));
3444 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3445 bv_->text->selection.cursor = bv_->text->cursor;
3449 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3451 gotoInset(vector<Inset::Code>(1, code), same_content);