12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
22 #include "bufferview_funcs.h"
23 #include "TextCache.h"
24 #include "bufferlist.h"
25 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "support/lstrings.h"
30 #include "frontends/Dialogs.h"
31 #include "insets/insetbib.h"
32 #include "insets/insettext.h"
33 /// added for Dispatch functions
35 #include "frontends/FileDialog.h"
37 #include "FloatList.h"
38 #include "support/filetools.h"
39 #include "support/lyxfunctional.h"
40 #include "insets/inseturl.h"
41 #include "insets/insetlatexaccent.h"
42 #include "insets/insettoc.h"
43 #include "insets/insetref.h"
44 #include "insets/insetparent.h"
45 #include "insets/insetindex.h"
46 #include "insets/insetnote.h"
47 #include "insets/insetinclude.h"
48 #include "insets/insetcite.h"
49 #include "insets/insetert.h"
50 #include "insets/insetexternal.h"
51 #include "insets/insetgraphics.h"
52 #include "insets/insetfoot.h"
53 #include "insets/insetmarginal.h"
54 #include "insets/insetminipage.h"
55 #include "insets/insetfloat.h"
56 #include "insets/insettabular.h"
58 #include "insets/insettheorem.h"
59 #include "insets/insetlist.h"
61 #include "insets/insetcaption.h"
62 #include "insets/insetfloatlist.h"
63 #include "insets/insetspecialchar.h"
65 #include "ParagraphParameters.h"
66 #include "undo_funcs.h"
67 #include "mathed/formulabase.h"
69 extern LyXTextClass::size_type current_layout;
80 /* the selection possible is needed, that only motion events are
81 * used, where the bottom press event was on the drawing area too */
82 bool selection_possible = false;
84 extern BufferList bufferlist;
85 extern char ascii_type;
87 extern void sigchldchecker(pid_t pid, int * status);
88 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
93 const unsigned int saved_positions_num = 20;
98 XSync(fl_get_display(), 0);
102 void SetXtermCursor(Window win)
104 static Cursor cursor;
105 static bool cursor_undefined = true;
106 if (cursor_undefined){
107 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
108 XFlush(fl_get_display());
109 cursor_undefined = false;
111 XDefineCursor(fl_get_display(), win, cursor);
112 XFlush(fl_get_display());
118 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
119 int xpos, int ypos, int width, int height)
120 : bv_(b), owner_(o), buffer_(0),
121 current_scrollbar_value(0), cursor_timeout(400),
122 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
126 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
127 workarea_.workAreaExpose
128 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
129 workarea_.workAreaEnter
130 .connect(slot(this, &BufferView::Pimpl::enterView));
131 workarea_.workAreaLeave
132 .connect(slot(this, &BufferView::Pimpl::leaveView));
133 workarea_.workAreaButtonPress
134 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
135 workarea_.workAreaButtonRelease
137 &BufferView::Pimpl::workAreaButtonRelease));
138 workarea_.workAreaMotionNotify
139 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
140 workarea_.workAreaDoubleClick
141 .connect(slot(this, &BufferView::Pimpl::doubleClick));
142 workarea_.workAreaTripleClick
143 .connect(slot(this, &BufferView::Pimpl::tripleClick));
144 workarea_.workAreaKeyPress
145 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
147 cursor_timeout.timeout.connect(slot(this,
148 &BufferView::Pimpl::cursorToggle));
149 cursor_timeout.start();
150 workarea_.setFocus();
151 saved_positions.resize(saved_positions_num);
155 Painter & BufferView::Pimpl::painter()
157 return workarea_.getPainter();
161 void BufferView::Pimpl::buffer(Buffer * b)
163 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
167 buffer_->delUser(bv_);
169 // Put the old text into the TextCache, but
170 // only if the buffer is still loaded.
171 // Also set the owner of the test to 0
172 // bv_->text->owner(0);
173 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
174 if (lyxerr.debugging())
175 textcache.show(lyxerr, "BufferView::buffer");
180 // Set current buffer
183 if (bufferlist.getState() == BufferList::CLOSING) return;
186 // screen is always deleted when the buffer is changed.
189 // If we are closing the buffer, use the first buffer as current
191 buffer_ = bufferlist.first();
195 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
196 buffer_->addUser(bv_);
197 // If we don't have a text object for this, we make one
198 if (bv_->text == 0) {
199 resizeCurrentBuffer();
204 bv_->text->first = screen_->topCursorVisible(bv_->text);
205 owner_->updateMenubar();
206 owner_->updateToolbar();
207 // Similarly, buffer-dependent dialogs should be updated or
208 // hidden. This should go here because some dialogs (eg ToC)
209 // require bv_->text.
210 owner_->getDialogs()->updateBufferDependent(true);
214 lyxerr[Debug::INFO] << " No Buffer!" << endl;
215 owner_->updateMenubar();
216 owner_->updateToolbar();
217 owner_->getDialogs()->hideBufferDependent();
221 // Also remove all remaining text's from the testcache.
222 // (there should not be any!) (if there is any it is a
224 if (lyxerr.debugging())
225 textcache.show(lyxerr, "buffer delete all");
228 // should update layoutchoice even if we don't have a buffer.
229 owner_->updateLayoutChoice();
231 owner_->updateWindowTitle();
235 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
237 workarea_.resize(xpos, ypos, width, height);
238 update(bv_->text, SELECT);
243 void BufferView::Pimpl::resize()
246 resizeCurrentBuffer();
250 void BufferView::Pimpl::redraw()
252 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
257 bool BufferView::Pimpl::fitCursor()
259 lyx::Assert(screen_.get());
263 if (bv_->theLockingInset()) {
264 bv_->theLockingInset()->fitInsetCursor(bv_);
267 ret = screen_->fitCursor(bv_->text, bv_);
270 bv_->owner()->getDialogs()->updateParagraph();
277 void BufferView::Pimpl::redoCurrentBuffer()
279 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
280 if (buffer_ && bv_->text) {
282 owner_->updateLayoutChoice();
287 int BufferView::Pimpl::resizeCurrentBuffer()
289 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
292 Paragraph * selstartpar = 0;
293 Paragraph * selendpar = 0;
294 UpdatableInset * the_locking_inset = 0;
296 Paragraph::size_type pos = 0;
297 Paragraph::size_type selstartpos = 0;
298 Paragraph::size_type selendpos = 0;
299 bool selection = false;
300 bool mark_set = false;
302 owner_->prohibitInput();
304 owner_->message(_("Formatting document..."));
307 par = bv_->text->cursor.par();
308 pos = bv_->text->cursor.pos();
309 selstartpar = bv_->text->selection.start.par();
310 selstartpos = bv_->text->selection.start.pos();
311 selendpar = bv_->text->selection.end.par();
312 selendpos = bv_->text->selection.end.pos();
313 selection = bv_->text->selection.set();
314 mark_set = bv_->text->selection.mark();
315 the_locking_inset = bv_->theLockingInset();
317 bv_->text = new LyXText(bv_);
318 bv_->text->init(bv_);
320 // See if we have a text in TextCache that fits
321 // the new buffer_ with the correct width.
322 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
324 if (lyxerr.debugging()) {
325 lyxerr << "Found a LyXText that fits:\n";
326 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
328 // Set the owner of the newly found text
329 // bv_->text->owner(bv_);
330 if (lyxerr.debugging())
331 textcache.show(lyxerr, "resizeCurrentBuffer");
333 bv_->text = new LyXText(bv_);
334 bv_->text->init(bv_);
340 bv_->text->selection.set(true);
341 /* at this point just to avoid the Delete-Empty-Paragraph
342 * Mechanism when setting the cursor */
343 bv_->text->selection.mark(mark_set);
345 bv_->text->setCursor(bv_, selstartpar, selstartpos);
346 bv_->text->selection.cursor = bv_->text->cursor;
347 bv_->text->setCursor(bv_, selendpar, selendpos);
348 bv_->text->setSelection(bv_);
349 bv_->text->setCursor(bv_, par, pos);
351 bv_->text->setCursor(bv_, par, pos);
352 bv_->text->selection.cursor = bv_->text->cursor;
353 bv_->text->selection.set(false);
355 // remake the inset locking
356 bv_->theLockingInset(the_locking_inset);
358 bv_->text->first = screen_->topCursorVisible(bv_->text);
359 buffer_->resizeInsets(bv_);
360 // this will scroll the screen such that the cursor becomes visible
365 owner_->allowInput();
367 /// clear the "Formatting Document" message
374 void BufferView::Pimpl::updateScreen()
376 // Regenerate the screen.
377 screen_.reset(new LyXScreen(workarea_));
381 void BufferView::Pimpl::updateScrollbar()
383 /* If the text is smaller than the working area, the scrollbar
384 * maximum must be the working area height. No scrolling will
387 workarea_.setScrollbar(0, 1.0);
391 long const text_height = bv_->text->height;
393 double const lineh = bv_->text->defaultHeight();
394 double const slider_size =
395 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
397 static long old_text_height = 0;
398 static double old_lineh = 0;
399 static double old_slider_size = 0;
401 if (text_height != old_text_height) {
402 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
403 old_text_height = text_height;
405 if (lineh != old_lineh) {
406 workarea_.setScrollbarIncrements(lineh);
409 if (current_scrollbar_value != bv_->text->first
410 || slider_size != old_slider_size) {
411 current_scrollbar_value = bv_->text->first;
412 workarea_.setScrollbar(current_scrollbar_value, slider_size);
413 old_slider_size = slider_size;
418 // Callback for scrollbar slider
419 void BufferView::Pimpl::scrollCB(double value)
421 if (!buffer_) return;
423 current_scrollbar_value = long(value);
424 if (current_scrollbar_value < 0)
425 current_scrollbar_value = 0;
430 screen_->draw(bv_->text, bv_, current_scrollbar_value);
432 if (!lyxrc.cursor_follows_scrollbar) {
437 LyXText * vbt = bv_->text;
439 int const height = vbt->defaultHeight();
440 int const first = static_cast<int>((bv_->text->first + height));
441 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
443 if (vbt->cursor.y() < first)
444 vbt->setCursorFromCoordinates(bv_, 0, first);
445 else if (vbt->cursor.y() > last)
446 vbt->setCursorFromCoordinates(bv_, 0, last);
452 int BufferView::Pimpl::scrollUp(long time)
454 if (!buffer_) return 0;
455 if (!screen_.get()) return 0;
457 double value = workarea_.getScrollbarValue();
459 if (value == 0) return 0;
461 float add_value = (bv_->text->defaultHeight()
462 + float(time) * float(time) * 0.125);
464 if (add_value > workarea_.height())
465 add_value = float(workarea_.height() -
466 bv_->text->defaultHeight());
473 workarea_.setScrollbarValue(value);
480 int BufferView::Pimpl::scrollDown(long time)
482 if (!buffer_) return 0;
483 if (!screen_.get()) return 0;
485 double value = workarea_.getScrollbarValue();
486 pair<float, float> p = workarea_.getScrollbarBounds();
487 double const max = p.second;
489 if (value == max) return 0;
491 float add_value = (bv_->text->defaultHeight()
492 + float(time) * float(time) * 0.125);
494 if (add_value > workarea_.height())
495 add_value = float(workarea_.height() -
496 bv_->text->defaultHeight());
503 workarea_.setScrollbarValue(value);
510 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
512 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
516 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
518 // Only use motion with button 1
519 if (!(state & Button1MotionMask))
522 if (!buffer_ || !screen_.get()) return;
524 // Check for inset locking
525 if (bv_->theLockingInset()) {
526 LyXCursor cursor = bv_->text->cursor;
527 LyXFont font = bv_->text->getFont(buffer_,
528 cursor.par(), cursor.pos());
529 int width = bv_->theLockingInset()->width(bv_, font);
530 int inset_x = font.isVisibleRightToLeft()
531 ? cursor.x() - width : cursor.x();
532 int start_x = inset_x + bv_->theLockingInset()->scroll();
533 bv_->theLockingInset()->
534 insetMotionNotify(bv_,
536 y - cursor.y() + bv_->text->first,
541 /* The test for not selection possible is needed, that only motion
542 events are used, where the bottom press event was on
543 the drawing area too */
544 if (!selection_possible)
547 screen_->hideCursor();
549 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
551 if (!bv_->text->selection.set())
552 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
554 bv_->text->setSelection(bv_);
555 screen_->toggleToggle(bv_->text, bv_);
558 screen_->showCursor(bv_->text, bv_);
565 // Single-click on work area
566 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
569 if (!buffer_ || !screen_.get()) return;
571 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
573 // ok ok, this is a hack.
574 if (button == 4 || button == 5) {
577 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
580 scrollDown(lyxrc.wheel_jump);
585 if (bv_->theLockingInset()) {
586 // We are in inset locking mode
588 /* Check whether the inset was hit. If not reset mode,
589 otherwise give the event to the inset */
590 if (inset_hit == bv_->theLockingInset()) {
591 bv_->theLockingInset()->
592 insetButtonPress(bv_,xpos, ypos,button);
595 bv_->unlockInset(bv_->theLockingInset());
600 selection_possible = true;
601 screen_->hideCursor();
603 int const screen_first = bv_->text->first;
605 // Middle button press pastes if we have a selection
606 bool paste_internally = false;
608 && bv_->text->selection.set()) {
609 owner_->getLyXFunc()->dispatch(LFUN_COPY);
610 paste_internally = true;
613 // Clear the selection
614 screen_->toggleSelection(bv_->text, bv_);
615 bv_->text->clearSelection();
616 bv_->text->fullRebreak(bv_);
618 screen_->update(bv_->text, bv_);
624 // Single left click in math inset?
625 if (isHighlyEditableInset(inset_hit)) {
626 // Highly editable inset, like math
627 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
628 selection_possible = false;
629 owner_->updateLayoutChoice();
630 owner_->message(inset->editMessage());
631 inset->insetButtonPress(bv_, xpos, ypos, button);
632 inset->edit(bv_, xpos, ypos, button);
636 // Right click on a footnote flag opens float menu
638 selection_possible = false;
642 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
643 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
645 bv_->text->selection.cursor = bv_->text->cursor;
646 bv_->text->cursor.x_fix(bv_->text->cursor.x());
648 owner_->updateLayoutChoice();
650 selection_possible = false;
653 // Insert primary selection with middle mouse
654 // if there is a local selection in the current buffer,
657 if (paste_internally)
658 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
660 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
662 selection_possible = false;
668 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
674 LyXText * text = bv_->getLyXText();
676 if (text->bv_owner && bv_->theLockingInset())
679 if (screen_.get() && button == 1) {
680 if (text->bv_owner) {
681 screen_->hideCursor();
682 screen_->toggleSelection(text, bv_);
683 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
684 screen_->toggleSelection(text, bv_, false);
686 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
688 /* This will fit the cursor on the screen
690 update(text, BufferView::SELECT|BufferView::FITCUR);
695 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
701 LyXText * text = bv_->getLyXText();
703 if (text->bv_owner && bv_->theLockingInset())
706 if (screen_.get() && (button == 1)) {
707 screen_->hideCursor();
708 screen_->toggleSelection(text, bv_);
709 text->cursorHome(bv_);
710 text->selection.cursor = text->cursor;
711 text->cursorEnd(bv_);
712 text->setSelection(bv_);
713 screen_->toggleSelection(text, bv_, false);
714 /* This will fit the cursor on the screen
716 update(text, BufferView::SELECT|BufferView::FITCUR);
721 void BufferView::Pimpl::enterView()
723 if (active() && available()) {
724 SetXtermCursor(workarea_.getWin());
725 using_xterm_cursor = true;
730 void BufferView::Pimpl::leaveView()
732 if (using_xterm_cursor) {
733 XUndefineCursor(fl_get_display(), workarea_.getWin());
734 using_xterm_cursor = false;
739 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
742 if (!buffer_ || !screen_.get()) return;
744 // If we hit an inset, we have the inset coordinates in these
745 // and inset_hit points to the inset. If we do not hit an
746 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
747 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
749 if (bv_->theLockingInset()) {
750 // We are in inset locking mode.
752 /* LyX does a kind of work-area grabbing for insets.
753 Only a ButtonPress Event outside the inset will
754 force a insetUnlock. */
755 bv_->theLockingInset()->
756 insetButtonRelease(bv_, x, y, button);
760 selection_possible = false;
768 // Did we hit an editable inset?
770 // Inset like error, notes and figures
771 selection_possible = false;
773 // CHECK fix this proper in 0.13
775 // Following a ref shouldn't issue
776 // a push on the undo-stack
777 // anylonger, now that we have
778 // keybindings for following
779 // references and returning from
780 // references. IMHO though, it
781 // should be the inset's own business
782 // to push or not push on the undo
783 // stack. They don't *have* to
784 // alter the document...
786 // ...or maybe the SetCursorParUndo()
787 // below isn't necessary at all anylonger?
788 if (inset_hit->lyxCode() == Inset::REF_CODE) {
789 setCursorParUndo(bv_);
792 owner_->message(inset_hit->editMessage());
794 if (isHighlyEditableInset(inset_hit)) {
795 // Highly editable inset, like math
796 UpdatableInset *inset = (UpdatableInset *)inset_hit;
797 inset->insetButtonRelease(bv_, x, y, button);
799 inset_hit->insetButtonRelease(bv_, x, y, button);
800 inset_hit->edit(bv_, x, y, button);
806 #warning variable c is set but never used. What is it good for?? (JMarc)
808 // check whether we want to open a float
812 if (bv_->text->cursor.pos() <
813 bv_->text->cursor.par()->size()) {
814 c = bv_->text->cursor.par()->
815 getChar(bv_->text->cursor.pos());
817 if (bv_->text->cursor.pos() - 1 >= 0) {
818 c = bv_->text->cursor.par()->
819 getChar(bv_->text->cursor.pos() - 1);
822 selection_possible = false;
827 // Maybe we want to edit a bibitem ale970302
828 if (bv_->text->cursor.par()->bibkey && x < 20 +
829 bibitemMaxWidth(bv_, textclasslist.
831 params.textclass).defaultfont())) {
832 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
840 * Returns an inset if inset was hit. 0 otherwise.
841 * If hit, the coordinates are changed relative to the inset.
842 * Otherwise coordinates are not changed, and false is returned.
844 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
845 unsigned int /* button */)
850 int y_tmp = y + text->first;
853 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
854 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
857 if (cursor.pos() < cursor.par()->size()
858 && isMetaInset(cursor.par(), cursor.pos())
859 && isEditableInset(cursor.par()->getInset(cursor.pos()))) {
861 // Check whether the inset really was hit
862 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
863 LyXFont font = text->getFont(buffer_,
864 cursor.par(), cursor.pos());
865 int const width = tmpinset->width(bv_, font);
866 int const inset_x = font.isVisibleRightToLeft()
867 ? cursor.x() - width : cursor.x();
868 int const start_x = inset_x + tmpinset->scroll();
869 int const end_x = inset_x + width;
871 if (x > start_x && x < end_x
872 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
873 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
874 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
876 // The origin of an inset is on the baseline
877 y = y_tmp - (text->cursor.y());
882 if ((cursor.pos() - 1 >= 0) &&
883 isMetaInset(cursor.par(), cursor.pos() - 1) &&
884 isEditableInset(cursor.par()->getInset(cursor.pos() - 1))) {
885 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
886 LyXFont font = text->getFont(buffer_, cursor.par(),
888 int const width = tmpinset->width(bv_, font);
889 int const inset_x = font.isVisibleRightToLeft()
890 ? cursor.x() : cursor.x() - width;
891 int const start_x = inset_x + tmpinset->scroll();
892 int const end_x = inset_x + width;
894 if (x > start_x && x < end_x
895 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
896 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
898 if (move_cursor && (tmpinset != bv_->theLockingInset()))
900 text->setCursor(bv_, cursor.par(),
901 cursor.pos() - 1, true);
903 // The origin of an inset is on the baseline
904 y = y_tmp - (text->cursor.y());
912 void BufferView::Pimpl::workAreaExpose()
914 static int work_area_width;
915 static unsigned int work_area_height;
917 bool const widthChange = workarea_.workWidth() != work_area_width;
918 bool const heightChange = workarea_.height() != work_area_height;
920 // update from work area
921 work_area_width = workarea_.workWidth();
922 work_area_height = workarea_.height();
925 // The visible LyXView need a resize
928 // Remove all texts from the textcache
929 // This is not _really_ what we want to do. What
930 // we really want to do is to delete in textcache
931 // that does not have a BufferView with matching
932 // width, but as long as we have only one BufferView
933 // deleting all gives the same result.
934 if (lyxerr.debugging())
935 textcache.show(lyxerr, "Expose delete all");
937 } else if (heightChange) {
938 // Rebuild image of current screen
940 // fitCursor() ensures we don't jump back
941 // to the start of the document on vertical
945 // The main window size has changed, repaint most stuff
947 } else if (screen_.get())
948 screen_->redraw(bv_->text, bv_);
950 // Grey box when we don't have a buffer
954 // always make sure that the scrollbar is sane.
956 owner_->updateLayoutChoice();
961 void BufferView::Pimpl::update()
964 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
966 LyXText::text_status st = bv_->text->status();
967 screen_->update(bv_->text, bv_);
969 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
970 if (bv_->text->fullRebreak(bv_)) {
971 st = LyXText::NEED_MORE_REFRESH;
972 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
973 bv_->text->cursor.pos());
976 bv_->text->status(bv_, st);
977 screen_->update(bv_->text, bv_);
979 // do this here instead of in the screen::update because of
981 bv_->text->status(bv_, LyXText::UNCHANGED);
987 // Values used when calling update:
989 // -2 - update, move sel_cursor if selection, fitcursor
990 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
991 // 0 - update, move sel_cursor if selection, fitcursor
992 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
993 // 3 - update, move sel_cursor if selection
996 // a simple redraw of the parts that need refresh
998 // move sel_cursor if selection -
999 // the text's sel_cursor is moved if there is selection is progress
1002 // fitCursor() is called and the scrollbar updated
1005 // the buffer is marked dirty.
1014 // UPDATE_ONLY = UPDATE;
1015 // UPDATE_SELECT = UPDATE | SELECT;
1016 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1017 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1019 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1020 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1021 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1022 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1023 // update(3) -> update(1) -> update(1) -> update(SELECT)
1025 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1027 owner_->updateLayoutChoice();
1029 if (!text->selection.set() && (f & SELECT)) {
1030 text->selection.cursor = text->cursor;
1033 text->fullRebreak(bv_);
1035 if (text->inset_owner) {
1036 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1037 updateInset(text->inset_owner, false);
1047 buffer_->markDirty();
1052 // Callback for cursor timer
1053 void BufferView::Pimpl::cursorToggle()
1055 // Quite a nice place for asyncron Inset updating, isn't it?
1056 // Actually no! This is run even if no buffer exist... so (Lgb)
1058 cursor_timeout.restart();
1063 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1064 if (pid == -1) // error find out what is wrong
1065 ; // ignore it for now.
1067 sigchldchecker(pid, &status);
1069 updatelist.update(bv_);
1071 if (!screen_.get()) {
1072 cursor_timeout.restart();
1076 if (!bv_->theLockingInset()) {
1077 screen_->cursorToggle(bv_);
1079 bv_->theLockingInset()->toggleInsetCursor(bv_);
1082 cursor_timeout.restart();
1086 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1088 if (!text->cursor.row()->previous())
1091 int y = text->first;
1092 if (text->inset_owner)
1093 y += bv_->text->first;
1094 Row * cursorrow = text->cursor.row();
1095 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1097 // This is to allow jumping over large insets
1098 if ((cursorrow == text->cursor.row()))
1099 text->cursorUp(bv_);
1101 if (text->inset_owner ||
1102 text->cursor.row()->height() < workarea_.height())
1103 screen_->draw(bv_->text, bv_,
1105 - text->cursor.row()->baseline()
1106 + text->cursor.row()->height()
1107 - workarea_.height() + 1 );
1112 void BufferView::Pimpl::cursorNext(LyXText * text)
1114 if (!text->cursor.row()->next())
1117 int y = text->first + workarea_.height();
1118 // if (text->inset_owner)
1119 // y += bv_->text->first;
1120 text->getRowNearY(y);
1122 Row * cursorrow = text->cursor.row();
1123 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1125 // This is to allow jumping over large insets
1126 if ((cursorrow == bv_->text->cursor.row()))
1127 text->cursorDown(bv_);
1129 if (text->inset_owner ||
1130 text->cursor.row()->height() < workarea_.height())
1131 screen_->draw(bv_->text, bv_, text->cursor.y() -
1132 text->cursor.row()->baseline());
1137 bool BufferView::Pimpl::available() const
1139 if (buffer_ && bv_->text) return true;
1144 void BufferView::Pimpl::beforeChange(LyXText * text)
1147 text->clearSelection();
1151 void BufferView::Pimpl::savePosition(unsigned int i)
1153 if (i >= saved_positions_num)
1155 saved_positions[i] = Position(buffer_->fileName(),
1156 bv_->text->cursor.par()->id(),
1157 bv_->text->cursor.pos());
1160 str << _("Saved bookmark") << ' ' << i;
1161 owner_->message(str.str().c_str());
1166 void BufferView::Pimpl::restorePosition(unsigned int i)
1168 if (i >= saved_positions_num)
1171 string const fname = saved_positions[i].filename;
1173 beforeChange(bv_->text);
1175 if (fname != buffer_->fileName()) {
1176 Buffer * b = bufferlist.exists(fname) ?
1177 bufferlist.getBuffer(fname) :
1178 bufferlist.loadLyXFile(fname); // don't ask, just load it
1179 if (b != 0 ) buffer(b);
1182 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1186 bv_->text->setCursor(bv_, par,
1187 min(par->size(), saved_positions[i].par_pos));
1189 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1192 str << _("Moved to bookmark") << ' ' << i;
1193 owner_->message(str.str().c_str());
1198 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1200 if (i >= saved_positions_num)
1203 return !saved_positions[i].filename.empty();
1207 void BufferView::Pimpl::setState()
1209 if (!lyxrc.rtl_support)
1212 LyXText * text = bv_->getLyXText();
1213 if (text->real_current_font.isRightToLeft()) {
1214 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1215 owner_->getIntl()->KeyMapSec();
1217 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1218 owner_->getIntl()->KeyMapPrim();
1223 void BufferView::Pimpl::insetSleep()
1225 if (bv_->theLockingInset() && !inset_slept) {
1226 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1227 bv_->theLockingInset()->insetUnlock(bv_);
1233 void BufferView::Pimpl::insetWakeup()
1235 if (bv_->theLockingInset() && inset_slept) {
1236 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1237 inset_slept = false;
1242 void BufferView::Pimpl::insetUnlock()
1244 if (bv_->theLockingInset()) {
1246 bv_->theLockingInset()->insetUnlock(bv_);
1247 bv_->theLockingInset(0);
1249 inset_slept = false;
1254 bool BufferView::Pimpl::focus() const
1256 return workarea_.hasFocus();
1260 void BufferView::Pimpl::focus(bool f)
1262 if (f) workarea_.setFocus();
1266 bool BufferView::Pimpl::active() const
1268 return workarea_.active();
1272 bool BufferView::Pimpl::belowMouse() const
1274 return workarea_.belowMouse();
1278 void BufferView::Pimpl::showCursor()
1280 if (screen_.get()) {
1281 if (bv_->theLockingInset())
1282 bv_->theLockingInset()->showInsetCursor(bv_);
1284 screen_->showCursor(bv_->text, bv_);
1289 void BufferView::Pimpl::hideCursor()
1291 if (screen_.get()) {
1292 if (!bv_->theLockingInset())
1293 // bv_->theLockingInset()->hideInsetCursor(bv_);
1295 screen_->hideCursor();
1300 void BufferView::Pimpl::toggleSelection(bool b)
1302 if (screen_.get()) {
1303 if (bv_->theLockingInset())
1304 bv_->theLockingInset()->toggleSelection(bv_, b);
1305 screen_->toggleSelection(bv_->text, bv_, b);
1310 void BufferView::Pimpl::toggleToggle()
1313 screen_->toggleToggle(bv_->text, bv_);
1317 void BufferView::Pimpl::center()
1319 beforeChange(bv_->text);
1320 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1321 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1323 screen_->draw(bv_->text, bv_, 0);
1325 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1330 void BufferView::Pimpl::pasteClipboard(bool asPara)
1332 if (!buffer_) return;
1334 screen_->hideCursor();
1335 beforeChange(bv_->text);
1337 string const clip(workarea_.getClipboard());
1339 if (clip.empty()) return;
1342 bv_->text->insertStringAsParagraphs(bv_, clip);
1344 bv_->text->insertStringAsLines(bv_, clip);
1346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1350 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1352 workarea_.putClipboard(stuff);
1357 * Dispatch functions for actions which can be valid for BufferView->text
1358 * and/or InsetText->text!!!
1363 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1365 LyXText * lt = bv_->getLyXText();
1367 if (selecting || lt->selection.mark()) {
1368 lt->setSelection(bv_);
1372 update(lt, BufferView::SELECT|BufferView::FITCUR);
1375 /* ---> Everytime the cursor is moved, show the current font state. */
1376 // should this too me moved out of this func?
1377 //owner->showState();
1382 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1384 LyXCursor cursor = bv_->getLyXText()->cursor;
1385 Buffer::inset_iterator it =
1386 find_if(Buffer::inset_iterator(
1387 cursor.par(), cursor.pos()),
1388 buffer_->inset_iterator_end(),
1389 lyx::compare_memfun(&Inset::lyxCode, code));
1390 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1394 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1396 string filename = filen;
1398 if (filename.empty()) {
1399 // Launch a file browser
1400 string initpath = lyxrc.document_path;
1403 string const trypath = owner_->buffer()->filepath;
1404 // If directory is writeable, use this as default.
1405 if (IsDirWriteable(trypath))
1409 FileDialog fileDlg(bv_->owner(),
1410 _("Select LyX document to insert"),
1412 make_pair(string(_("Documents")),
1413 string(lyxrc.document_path)),
1414 make_pair(string(_("Examples")),
1415 string(AddPath(system_lyxdir, "examples"))));
1417 FileDialog::Result result =
1418 fileDlg.Select(initpath,
1419 _("*.lyx| LyX Documents (*.lyx)"));
1421 if (result.first == FileDialog::Later)
1424 filename = result.second;
1426 // check selected filename
1427 if (filename.empty()) {
1428 owner_->message(_("Canceled."));
1433 // get absolute path of file and add ".lyx" to the filename if
1435 filename = FileSearch(string(), filename, "lyx");
1437 string const disp_fn(MakeDisplayPath(filename));
1440 s1 << _("Inserting document") << ' '
1441 << disp_fn << " ...";
1442 owner_->message(s1.str().c_str());
1443 bool const res = bv_->insertLyXFile(filename);
1446 str << _("Document") << ' ' << disp_fn
1447 << ' ' << _("inserted.");
1448 owner_->message(str.str().c_str());
1451 str << _("Could not insert document") << ' '
1453 owner_->message(str.str().c_str());
1458 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1460 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1461 << action <<"] arg[" << argument << "]" << endl;
1464 // --- Misc -------------------------------------------
1468 LyXText * lt = bv_->getLyXText();
1469 lt->toggleAppendix(bv_);
1472 | BufferView::FITCUR
1473 | BufferView::CHANGE);
1478 case LFUN_TOC_INSERT:
1480 InsetCommandParams p;
1481 p.setCmdName("tableofcontents");
1482 Inset * inset = new InsetTOC(p);
1483 if (!insertInset(inset, "Standard"))
1488 case LFUN_TABULAR_FEATURE:
1489 case LFUN_SCROLL_INSET:
1490 // this is not handled here as this funktion is only aktive
1491 // if we have a locking_inset and that one is (or contains)
1495 case LFUN_INSET_GRAPHICS:
1497 Inset * new_inset = new InsetGraphics;
1498 if (!insertInset(new_inset)) {
1501 // this is need because you don't use a inset->Edit()
1502 updateInset(new_inset, true);
1503 new_inset->edit(bv_);
1513 case LFUN_PASTESELECTION:
1515 bool asPara = false;
1516 if (argument == "paragraph") asPara = true;
1517 pasteClipboard(asPara);
1529 case LFUN_LAYOUT_COPY:
1530 bv_->copyEnvironment();
1533 case LFUN_LAYOUT_PASTE:
1534 bv_->pasteEnvironment();
1538 case LFUN_GOTOERROR:
1539 gotoInset(Inset::ERROR_CODE, false);
1543 gotoInset(Inset::IGNORE_CODE, false);
1546 case LFUN_REFERENCE_GOTO:
1548 vector<Inset::Code> tmp;
1549 tmp.push_back(Inset::LABEL_CODE);
1550 tmp.push_back(Inset::REF_CODE);
1551 gotoInset(tmp, true);
1555 case LFUN_HYPHENATION:
1556 specialChar(InsetSpecialChar::HYPHENATION);
1559 case LFUN_LIGATURE_BREAK:
1560 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1564 specialChar(InsetSpecialChar::LDOTS);
1567 case LFUN_END_OF_SENTENCE:
1568 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1571 case LFUN_MENU_SEPARATOR:
1572 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1580 changeDepth(bv_, bv_->getLyXText(), 0);
1583 case LFUN_DEPTH_MIN:
1584 changeDepth(bv_, bv_->getLyXText(), -1);
1587 case LFUN_DEPTH_PLUS:
1588 changeDepth(bv_, bv_->getLyXText(), 1);
1592 owner_->getDialogs()->setUserFreeFont();
1595 case LFUN_FILE_INSERT:
1597 MenuInsertLyXFile(argument);
1601 case LFUN_FILE_INSERT_ASCII_PARA:
1602 InsertAsciiFile(bv_, argument, true);
1605 case LFUN_FILE_INSERT_ASCII:
1606 InsertAsciiFile(bv_, argument, false);
1611 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1612 << argument << endl;
1614 // Derive layout number from given argument (string)
1615 // and current buffer's textclass (number). */
1616 LyXTextClassList::ClassList::size_type tclass =
1617 buffer_->params.textclass;
1618 pair <bool, LyXTextClass::size_type> layout =
1619 textclasslist.NumberOfLayout(tclass, argument);
1621 // If the entry is obsolete, use the new one instead.
1623 string obs = textclasslist.Style(tclass,layout.second)
1627 textclasslist.NumberOfLayout(tclass, obs);
1630 // see if we found the layout number:
1631 if (!layout.first) {
1632 owner_->getLyXFunc()->setErrorMessage(
1633 string(N_("Layout ")) + argument +
1638 if (current_layout != layout.second) {
1639 LyXText * lt = bv_->getLyXText();
1641 current_layout = layout.second;
1644 | BufferView::FITCUR);
1645 lt->setLayout(bv_, layout.second);
1646 owner_->setLayout(layout.second);
1649 | BufferView::FITCUR
1650 | BufferView::CHANGE);
1657 lang(bv_, argument);
1659 owner_->showState();
1664 owner_->showState();
1669 owner_->showState();
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1694 owner_->showState();
1697 case LFUN_UNDERLINE:
1699 owner_->showState();
1702 case LFUN_FONT_SIZE:
1703 fontSize(bv_, argument);
1704 owner_->showState();
1707 case LFUN_FONT_STATE:
1708 owner_->getLyXFunc()->setMessage(currentState(bv_));
1711 case LFUN_UPCASE_WORD:
1713 LyXText * lt = bv_->getLyXText();
1717 | BufferView::FITCUR);
1718 lt->changeCase(bv_, LyXText::text_uppercase);
1719 if (lt->inset_owner)
1720 updateInset(lt->inset_owner, true);
1723 | BufferView::FITCUR
1724 | BufferView::CHANGE);
1728 case LFUN_LOWCASE_WORD:
1730 LyXText * lt = bv_->getLyXText();
1732 update(lt, BufferView::SELECT|BufferView::FITCUR);
1733 lt->changeCase(bv_, LyXText::text_lowercase);
1734 if (lt->inset_owner)
1735 updateInset(lt->inset_owner, true);
1738 | BufferView::FITCUR
1739 | BufferView::CHANGE);
1743 case LFUN_CAPITALIZE_WORD:
1745 LyXText * lt = bv_->getLyXText();
1747 update(lt, BufferView::SELECT|BufferView::FITCUR);
1748 lt->changeCase(bv_, LyXText::text_capitalization);
1749 if (lt->inset_owner)
1750 updateInset(lt->inset_owner, true);
1753 | BufferView::FITCUR
1754 | BufferView::CHANGE);
1758 case LFUN_TRANSPOSE_CHARS:
1760 LyXText * lt = bv_->getLyXText();
1762 update(lt, BufferView::SELECT|BufferView::FITCUR);
1763 lt->transposeChars(*bv_);
1764 if (lt->inset_owner)
1765 updateInset(lt->inset_owner, true);
1768 | BufferView::FITCUR
1769 | BufferView::CHANGE);
1774 case LFUN_INSERT_LABEL:
1775 MenuInsertLabel(bv_, argument);
1778 case LFUN_REF_INSERT:
1779 if (argument.empty()) {
1780 InsetCommandParams p("ref");
1781 owner_->getDialogs()->createRef(p.getAsString());
1783 InsetCommandParams p;
1784 p.setFromString(argument);
1786 InsetRef * inset = new InsetRef(p, *buffer_);
1787 if (!insertInset(inset))
1790 updateInset(inset, true);
1794 case LFUN_BOOKMARK_SAVE:
1795 savePosition(strToUnsignedInt(argument));
1798 case LFUN_BOOKMARK_GOTO:
1799 restorePosition(strToUnsignedInt(argument));
1804 string label(argument);
1805 if (label.empty()) {
1807 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1809 label = inset->getContents();
1814 if (!label.empty()) {
1815 //bv_->savePosition(0);
1816 if (!bv_->gotoLabel(label))
1817 WriteAlert(_("Error"),
1818 _("Couldn't find this label"),
1819 _("in current document."));
1824 // --- Cursor Movements -----------------------------
1827 LyXText * lt = bv_->getLyXText();
1829 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1830 if (!lt->selection.mark())
1832 update(lt, BufferView::SELECT|BufferView::FITCUR);
1834 lt->cursorLeft(bv_, false);
1835 if (lt->cursor.pos() < lt->cursor.par()->size()
1836 && isMetaInset(lt->cursor.par(), lt->cursor.pos())
1837 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1838 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1839 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1841 tmpinset->edit(bv_, false);
1843 tmpinset->edit(bv_);
1847 lt->cursorRight(bv_, false);
1849 moveCursorUpdate(false);
1850 owner_->showState();
1856 // This is soooo ugly. Isn`t it possible to make
1857 // it simpler? (Lgb)
1858 LyXText * lt = bv_->getLyXText();
1859 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1860 if (!lt->selection.mark())
1862 update(lt, BufferView::SELECT|BufferView::FITCUR);
1863 LyXCursor const cur = lt->cursor;
1865 lt->cursorLeft(bv_, false);
1866 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1867 lt->cursor.pos() < lt->cursor.par()->size() &&
1868 isMetaInset(lt->cursor.par(), lt->cursor.pos()) &&
1869 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1870 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1871 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1873 tmpinset->edit(bv_);
1875 tmpinset->edit(bv_, false);
1879 lt->cursorRight(bv_, false);
1882 moveCursorUpdate(false);
1883 owner_->showState();
1889 LyXText * lt = bv_->getLyXText();
1891 if (!lt->selection.mark())
1893 update(lt, BufferView::UPDATE);
1896 moveCursorUpdate(false);
1897 owner_->showState();
1903 LyXText * lt = bv_->getLyXText();
1905 if (!lt->selection.mark())
1907 update(lt, BufferView::UPDATE);
1908 lt->cursorDown(bv_);
1910 moveCursorUpdate(false);
1911 owner_->showState();
1915 case LFUN_UP_PARAGRAPH:
1917 LyXText * lt = bv_->getLyXText();
1919 if (!lt->selection.mark())
1921 update(lt, BufferView::UPDATE);
1922 lt->cursorUpParagraph(bv_);
1924 moveCursorUpdate(false);
1925 owner_->showState();
1929 case LFUN_DOWN_PARAGRAPH:
1931 LyXText * lt = bv_->getLyXText();
1933 if (!lt->selection.mark())
1935 update(lt, BufferView::UPDATE);
1936 lt->cursorDownParagraph(bv_);
1938 moveCursorUpdate(false);
1939 owner_->showState();
1945 LyXText * lt = bv_->getLyXText();
1947 if (!lt->selection.mark())
1949 update(lt, BufferView::UPDATE);
1952 moveCursorUpdate(false);
1953 owner_->showState();
1959 LyXText * lt = bv_->getLyXText();
1961 if (!lt->selection.mark())
1963 update(lt, BufferView::UPDATE);
1966 moveCursorUpdate(false);
1967 owner_->showState();
1973 LyXText * lt = bv_->getLyXText();
1975 if (!lt->selection.mark())
1977 update(lt, BufferView::SELECT|BufferView::FITCUR);
1978 lt->cursorHome(bv_);
1980 moveCursorUpdate(false);
1981 owner_->showState();
1987 LyXText * lt = bv_->getLyXText();
1989 if (!lt->selection.mark())
1992 BufferView::SELECT|BufferView::FITCUR);
1995 moveCursorUpdate(false);
1996 owner_->showState();
2000 case LFUN_SHIFT_TAB:
2003 LyXText * lt = bv_->getLyXText();
2005 if (!lt->selection.mark())
2008 BufferView::SELECT|BufferView::FITCUR);
2011 moveCursorUpdate(false);
2012 owner_->showState();
2016 case LFUN_WORDRIGHT:
2018 LyXText * lt = bv_->getLyXText();
2020 if (!lt->selection.mark())
2022 update(lt, BufferView::SELECT|BufferView::FITCUR);
2023 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2024 lt->cursorLeftOneWord(bv_);
2026 lt->cursorRightOneWord(bv_);
2028 moveCursorUpdate(false);
2029 owner_->showState();
2035 LyXText * lt = bv_->getLyXText();
2037 if (!lt->selection.mark())
2039 update(lt, BufferView::SELECT|BufferView::FITCUR);
2040 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2041 lt->cursorRightOneWord(bv_);
2043 lt->cursorLeftOneWord(bv_);
2045 moveCursorUpdate(false);
2046 owner_->showState();
2050 case LFUN_BEGINNINGBUF:
2052 LyXText * lt = bv_->getLyXText();
2054 if (!lt->selection.mark())
2057 BufferView::SELECT|BufferView::FITCUR);
2060 moveCursorUpdate(false);
2061 owner_->showState();
2067 LyXText * lt = bv_->getLyXText();
2069 if (!lt->selection.mark())
2072 BufferView::SELECT|BufferView::FITCUR);
2073 lt->cursorBottom(bv_);
2075 moveCursorUpdate(false);
2076 owner_->showState();
2080 /* cursor selection ---------------------------- */
2083 LyXText * lt = bv_->getLyXText();
2086 BufferView::SELECT|BufferView::FITCUR);
2087 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2088 lt->cursorLeft(bv_);
2090 lt->cursorRight(bv_);
2092 moveCursorUpdate(true);
2093 owner_->showState();
2099 LyXText * lt = bv_->getLyXText();
2102 BufferView::SELECT|BufferView::FITCUR);
2103 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2104 lt->cursorRight(bv_);
2106 lt->cursorLeft(bv_);
2108 moveCursorUpdate(true);
2109 owner_->showState();
2115 LyXText * lt = bv_->getLyXText();
2118 BufferView::SELECT|BufferView::FITCUR);
2121 moveCursorUpdate(true);
2122 owner_->showState();
2128 LyXText * lt = bv_->getLyXText();
2131 BufferView::SELECT|BufferView::FITCUR);
2132 lt->cursorDown(bv_);
2134 moveCursorUpdate(true);
2135 owner_->showState();
2139 case LFUN_UP_PARAGRAPHSEL:
2141 LyXText * lt = bv_->getLyXText();
2144 BufferView::SELECT|BufferView::FITCUR);
2145 lt->cursorUpParagraph(bv_);
2147 moveCursorUpdate(true);
2148 owner_->showState();
2152 case LFUN_DOWN_PARAGRAPHSEL:
2154 LyXText * lt = bv_->getLyXText();
2157 BufferView::SELECT|BufferView::FITCUR);
2158 lt->cursorDownParagraph(bv_);
2160 moveCursorUpdate(true);
2161 owner_->showState();
2167 LyXText * lt = bv_->getLyXText();
2169 update(lt, BufferView::SELECT|BufferView::FITCUR);
2172 moveCursorUpdate(true);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2181 update(lt, BufferView::SELECT|BufferView::FITCUR);
2184 moveCursorUpdate(true);
2185 owner_->showState();
2191 LyXText * lt = bv_->getLyXText();
2193 update(lt, BufferView::SELECT|BufferView::FITCUR);
2194 lt->cursorHome(bv_);
2196 moveCursorUpdate(true);
2197 owner_->showState();
2203 LyXText * lt = bv_->getLyXText();
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2208 moveCursorUpdate(true);
2209 owner_->showState();
2213 case LFUN_WORDRIGHTSEL:
2215 LyXText * lt = bv_->getLyXText();
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2218 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2219 lt->cursorLeftOneWord(bv_);
2221 lt->cursorRightOneWord(bv_);
2223 moveCursorUpdate(true);
2224 owner_->showState();
2228 case LFUN_WORDLEFTSEL:
2230 LyXText * lt = bv_->getLyXText();
2232 update(lt, BufferView::SELECT|BufferView::FITCUR);
2233 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2234 lt->cursorRightOneWord(bv_);
2236 lt->cursorLeftOneWord(bv_);
2238 moveCursorUpdate(true);
2239 owner_->showState();
2243 case LFUN_BEGINNINGBUFSEL:
2245 LyXText * lt = bv_->getLyXText();
2247 if (lt->inset_owner)
2249 update(lt, BufferView::SELECT|BufferView::FITCUR);
2252 moveCursorUpdate(true);
2253 owner_->showState();
2257 case LFUN_ENDBUFSEL:
2259 LyXText * lt = bv_->getLyXText();
2261 if (lt->inset_owner)
2264 BufferView::SELECT|BufferView::FITCUR);
2265 lt->cursorBottom(bv_);
2267 moveCursorUpdate(true);
2268 owner_->showState();
2272 // --- text changing commands ------------------------
2273 case LFUN_BREAKLINE:
2275 LyXText * lt = bv_->getLyXText();
2278 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2281 | BufferView::FITCUR
2282 | BufferView::CHANGE);
2283 moveCursorUpdate(false);
2287 case LFUN_PROTECTEDSPACE:
2289 LyXText * lt = bv_->getLyXText();
2291 LyXLayout const & style = textclasslist
2292 .Style(buffer_->params.textclass,
2293 lt->cursor.par()->getLayout());
2295 if (style.free_spacing) {
2296 lt->insertChar(bv_, ' ');
2299 | BufferView::FITCUR
2300 | BufferView::CHANGE);
2304 moveCursorUpdate(false);
2310 LyXText * lt = bv_->getLyXText();
2312 if (lt->selection.mark()) {
2316 | BufferView::FITCUR);
2317 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2320 lt->selection.mark(true);
2323 | BufferView::FITCUR);
2324 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2326 lt->selection.cursor = lt->cursor;
2332 LyXText * lt = bv_->getLyXText();
2334 if (!lt->selection.set()) {
2336 lt->selection.cursor = lt->cursor;
2339 | BufferView::FITCUR
2340 | BufferView::CHANGE);
2341 // It is possible to make it a lot faster still
2342 // just comment out the line below...
2347 moveCursorUpdate(false);
2348 owner_->showState();
2353 case LFUN_DELETE_SKIP:
2355 LyXText * lt = bv_->getLyXText();
2357 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2359 LyXCursor cursor = lt->cursor;
2361 if (!lt->selection.set()) {
2362 if (cursor.pos() == cursor.par()->size()) {
2363 lt->cursorRight(bv_);
2364 cursor = lt->cursor;
2365 if (cursor.pos() == 0
2366 && !(cursor.par()->params().spaceTop()
2367 == VSpace (VSpace::NONE))) {
2370 cursor.par()->params().lineTop(),
2371 cursor.par()->params().lineBottom(),
2372 cursor.par()->params().pagebreakTop(),
2373 cursor.par()->params().pagebreakBottom(),
2374 VSpace(VSpace::NONE),
2375 cursor.par()->params().spaceBottom(),
2376 cursor.par()->params().spacing(),
2377 cursor.par()->params().align(),
2378 cursor.par()->params().labelWidthString(), 0);
2379 lt->cursorLeft(bv_);
2382 | BufferView::FITCUR
2383 | BufferView::CHANGE);
2385 lt->cursorLeft(bv_);
2387 lt->selection.cursor = lt->cursor;
2390 | BufferView::FITCUR
2391 | BufferView::CHANGE);
2395 lt->selection.cursor = lt->cursor;
2398 | BufferView::FITCUR
2399 | BufferView::CHANGE);
2407 /* -------> Delete word forward. */
2408 case LFUN_DELETE_WORD_FORWARD:
2409 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2410 bv_->getLyXText()->deleteWordForward(bv_);
2411 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2412 moveCursorUpdate(false);
2413 owner_->showState();
2416 /* -------> Delete word backward. */
2417 case LFUN_DELETE_WORD_BACKWARD:
2419 LyXText * lt = bv_->getLyXText();
2421 update(lt, BufferView::SELECT|BufferView::FITCUR);
2422 lt->deleteWordBackward(bv_);
2425 | BufferView::FITCUR
2426 | BufferView::CHANGE);
2427 moveCursorUpdate(false);
2428 owner_->showState();
2432 /* -------> Kill to end of line. */
2433 case LFUN_DELETE_LINE_FORWARD:
2435 LyXText * lt = bv_->getLyXText();
2437 update(lt, BufferView::SELECT|BufferView::FITCUR);
2438 lt->deleteLineForward(bv_);
2441 | BufferView::FITCUR
2442 | BufferView::CHANGE);
2443 moveCursorUpdate(false);
2447 /* -------> Set mark off. */
2450 LyXText * lt = bv_->getLyXText();
2453 update(lt, BufferView::SELECT|BufferView::FITCUR);
2454 lt->selection.cursor = lt->cursor;
2455 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2459 /* -------> Set mark on. */
2462 LyXText * lt = bv_->getLyXText();
2465 lt->selection.mark(true);
2466 update(lt, BufferView::SELECT|BufferView::FITCUR);
2467 lt->selection.cursor = lt->cursor;
2468 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2472 case LFUN_BACKSPACE:
2474 LyXText * lt = bv_->getLyXText();
2476 if (!lt->selection.set()) {
2477 if (owner_->getIntl()->getTrans().backspace()) {
2479 lt->selection.cursor = lt->cursor;
2482 | BufferView::FITCUR
2483 | BufferView::CHANGE);
2484 // It is possible to make it a lot faster still
2485 // just comment out the line below...
2491 owner_->showState();
2496 case LFUN_BACKSPACE_SKIP:
2498 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2499 LyXText * lt = bv_->getLyXText();
2501 LyXCursor cursor = lt->cursor;
2503 if (!lt->selection.set()) {
2504 if (cursor.pos() == 0
2505 && !(cursor.par()->params().spaceTop()
2506 == VSpace (VSpace::NONE))) {
2509 cursor.par()->params().lineTop(),
2510 cursor.par()->params().lineBottom(),
2511 cursor.par()->params().pagebreakTop(),
2512 cursor.par()->params().pagebreakBottom(),
2513 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2514 cursor.par()->params().spacing(),
2515 cursor.par()->params().align(),
2516 cursor.par()->params().labelWidthString(), 0);
2519 | BufferView::FITCUR
2520 | BufferView::CHANGE);
2523 lt->selection.cursor = cursor;
2526 | BufferView::FITCUR
2527 | BufferView::CHANGE);
2534 case LFUN_BREAKPARAGRAPH:
2536 LyXText * lt = bv_->getLyXText();
2539 lt->breakParagraph(bv_, 0);
2542 | BufferView::FITCUR
2543 | BufferView::CHANGE);
2544 lt->selection.cursor = lt->cursor;
2546 owner_->showState();
2550 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2552 LyXText * lt = bv_->getLyXText();
2555 lt->breakParagraph(bv_, 1);
2558 | BufferView::FITCUR
2559 | BufferView::CHANGE);
2560 lt->selection.cursor = lt->cursor;
2562 owner_->showState();
2566 case LFUN_BREAKPARAGRAPH_SKIP:
2568 // When at the beginning of a paragraph, remove
2569 // indentation and add a "defskip" at the top.
2570 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2571 LyXText * lt = bv_->getLyXText();
2573 LyXCursor cursor = lt->cursor;
2576 if (cursor.pos() == 0) {
2577 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2580 cursor.par()->params().lineTop(),
2581 cursor.par()->params().lineBottom(),
2582 cursor.par()->params().pagebreakTop(),
2583 cursor.par()->params().pagebreakBottom(),
2584 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2585 cursor.par()->params().spacing(),
2586 cursor.par()->params().align(),
2587 cursor.par()->params().labelWidthString(), 1);
2588 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2592 lt->breakParagraph(bv_, 0);
2593 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2598 | BufferView::FITCUR
2599 | BufferView::CHANGE);
2600 lt->selection.cursor = cursor;
2602 owner_->showState();
2606 case LFUN_PARAGRAPH_SPACING:
2608 LyXText * lt = bv_->getLyXText();
2610 Paragraph * par = lt->cursor.par();
2611 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2612 float cur_value = 1.0;
2613 if (cur_spacing == Spacing::Other) {
2614 cur_value = par->params().spacing().getValue();
2617 istringstream istr(argument.c_str());
2621 Spacing::Space new_spacing = cur_spacing;
2622 float new_value = cur_value;
2624 lyxerr << "Missing argument to `paragraph-spacing'"
2626 } else if (tmp == "single") {
2627 new_spacing = Spacing::Single;
2628 } else if (tmp == "onehalf") {
2629 new_spacing = Spacing::Onehalf;
2630 } else if (tmp == "double") {
2631 new_spacing = Spacing::Double;
2632 } else if (tmp == "other") {
2633 new_spacing = Spacing::Other;
2636 lyxerr << "new_value = " << tmpval << endl;
2639 } else if (tmp == "default") {
2640 new_spacing = Spacing::Default;
2642 lyxerr << _("Unknown spacing argument: ")
2643 << argument << endl;
2645 if (cur_spacing != new_spacing || cur_value != new_value) {
2646 par->params().spacing(Spacing(new_spacing, new_value));
2647 lt->redoParagraph(bv_);
2650 | BufferView::FITCUR
2651 | BufferView::CHANGE);
2656 case LFUN_INSET_TOGGLE:
2658 LyXText * lt = bv_->getLyXText();
2661 update(lt, BufferView::SELECT|BufferView::FITCUR);
2662 lt->toggleInset(bv_);
2663 update(lt, BufferView::SELECT|BufferView::FITCUR);
2675 InsetCommandParams p;
2676 if (action == LFUN_HTMLURL)
2677 p.setCmdName("htmlurl");
2679 p.setCmdName("url");
2680 owner_->getDialogs()->createUrl(p.getAsString());
2684 case LFUN_INSERT_URL:
2686 InsetCommandParams p;
2687 p.setFromString(argument);
2689 InsetUrl * inset = new InsetUrl(p);
2690 if (!insertInset(inset))
2693 updateInset(inset, true);
2697 case LFUN_INSET_TEXT:
2698 insertAndEditInset(new InsetText);
2701 case LFUN_INSET_ERT:
2702 insertAndEditInset(new InsetERT);
2705 case LFUN_INSET_EXTERNAL:
2706 insertAndEditInset(new InsetExternal);
2709 case LFUN_INSET_FOOTNOTE:
2710 insertAndEditInset(new InsetFoot);
2713 case LFUN_INSET_MARGINAL:
2714 insertAndEditInset(new InsetMarginal);
2717 case LFUN_INSET_MINIPAGE:
2718 insertAndEditInset(new InsetMinipage);
2721 case LFUN_INSERT_NOTE:
2722 insertAndEditInset(new InsetNote);
2725 case LFUN_INSET_FLOAT:
2726 // check if the float type exist
2727 if (floatList.typeExist(argument)) {
2728 insertAndEditInset(new InsetFloat(argument));
2730 lyxerr << "Non-existent float type: "
2731 << argument << endl;
2735 case LFUN_INSET_WIDE_FLOAT:
2737 // check if the float type exist
2738 if (floatList.typeExist(argument)) {
2739 InsetFloat * new_inset = new InsetFloat(argument);
2740 new_inset->wide(true);
2741 if (insertInset(new_inset))
2742 new_inset->edit(bv_);
2746 lyxerr << "Non-existent float type: "
2747 << argument << endl;
2754 case LFUN_INSET_LIST:
2755 insertAndEditInset(new InsetList);
2758 case LFUN_INSET_THEOREM:
2759 insertAndEditInset(new InsetTheorem);
2763 case LFUN_INSET_CAPTION:
2765 // Do we have a locking inset...
2766 if (bv_->theLockingInset()) {
2767 lyxerr << "Locking inset code: "
2768 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2769 InsetCaption * new_inset = new InsetCaption;
2770 new_inset->setOwner(bv_->theLockingInset());
2771 new_inset->setAutoBreakRows(true);
2772 new_inset->setDrawFrame(0, InsetText::LOCKED);
2773 new_inset->setFrameColor(0, LColor::captionframe);
2774 if (insertInset(new_inset))
2775 new_inset->edit(bv_);
2782 case LFUN_INSET_TABULAR:
2786 if (!argument.empty())
2787 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2788 InsetTabular * new_inset =
2789 new InsetTabular(*buffer_, r, c);
2791 bv_->getLyXText()->real_current_font.isRightToLeft();
2792 if (!open_new_inset(new_inset, rtl))
2797 // --- lyxserver commands ----------------------------
2799 case LFUN_CHARATCURSOR:
2801 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2802 if (pos < bv_->getLyXText()->cursor.par()->size())
2803 owner_->getLyXFunc()->setMessage(
2804 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2806 owner_->getLyXFunc()->setMessage("EOF");
2811 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2813 + tostr(bv_->getLyXText()->cursor.y()));
2820 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2821 lyxerr << "SETXY: Could not parse coordinates in '"
2822 << argument << std::endl;
2824 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2828 case LFUN_GETLAYOUT:
2829 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2834 LyXFont & font = bv_->getLyXText()->current_font;
2835 if (font.shape() == LyXFont::ITALIC_SHAPE)
2836 owner_->getLyXFunc()->setMessage("E");
2837 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2838 owner_->getLyXFunc()->setMessage("N");
2840 owner_->getLyXFunc()->setMessage("0");
2845 // --- accented characters ---------------------------
2848 case LFUN_CIRCUMFLEX:
2858 case LFUN_SPECIAL_CARON:
2861 case LFUN_HUNG_UMLAUT:
2864 if (argument.empty()) {
2866 owner_->getLyXFunc()->handleKeyFunc(action);
2868 owner_->getLyXFunc()->handleKeyFunc(action);
2869 owner_->getIntl()->getTrans()
2870 .TranslateAndInsert(argument[0], bv_->getLyXText());
2871 update(bv_->getLyXText(),
2873 | BufferView::FITCUR
2874 | BufferView::CHANGE);
2878 case LFUN_MATH_MACRO:
2879 mathDispatchMathMacro(bv_, argument);
2882 case LFUN_MATH_DELIM:
2883 mathDispatchMathDelim(bv_, argument);
2886 case LFUN_INSERT_MATRIX:
2887 mathDispatchInsertMatrix(bv_, argument);
2890 case LFUN_INSERT_MATH:
2891 mathDispatchInsertMath(bv_, argument);
2894 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2895 mathDispatchMathImportSelection(bv_, argument);
2898 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2899 mathDispatchMathDisplay(bv_, argument);
2902 case LFUN_MATH_MODE: // Open or create an inlined math inset
2903 mathDispatchMathMode(bv_, argument);
2906 case LFUN_GREEK: // Insert a single greek letter
2907 mathDispatchGreek(bv_, argument);
2910 case LFUN_CITATION_INSERT:
2912 InsetCommandParams p;
2913 p.setFromString( argument );
2915 InsetCitation * inset = new InsetCitation( p );
2916 if (!insertInset(inset))
2919 updateInset( inset, true );
2923 case LFUN_INSERT_BIBTEX:
2925 // ale970405+lasgoutt970425
2926 // The argument can be up to two tokens separated
2927 // by a space. The first one is the bibstyle.
2928 string const db = token(argument, ' ', 0);
2929 string const bibstyle = token(argument, ' ', 1);
2931 InsetCommandParams p( "BibTeX", db, bibstyle );
2932 InsetBibtex * inset = new InsetBibtex(p);
2934 if (insertInset(inset)) {
2935 if (argument.empty())
2942 // BibTeX data bases
2943 case LFUN_BIBDB_ADD:
2945 InsetBibtex * inset =
2946 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2948 inset->addDatabase(argument);
2953 case LFUN_BIBDB_DEL:
2955 InsetBibtex * inset =
2956 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2958 inset->delDatabase(argument);
2963 case LFUN_BIBTEX_STYLE:
2965 InsetBibtex * inset =
2966 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2968 inset->setOptions(argument);
2973 case LFUN_INDEX_CREATE:
2975 InsetCommandParams p("index");
2976 if (argument.empty()) {
2977 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2978 p.setContents(idxstring);
2980 p.setContents(argument);
2983 owner_->getDialogs()->createIndex(p.getAsString());
2987 case LFUN_INDEX_INSERT:
2989 InsetCommandParams p;
2990 p.setFromString(argument);
2991 InsetIndex * inset = new InsetIndex(p);
2993 if (!insertInset(inset))
2996 updateInset(inset, true);
3000 case LFUN_INDEX_INSERT_LAST:
3002 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3003 if (!idxstring.empty()) {
3004 owner_->message(_("Word `")
3005 + idxstring + _(("' indexed.")));
3006 InsetCommandParams p("index", idxstring);
3007 InsetIndex * inset = new InsetIndex(p);
3009 if (!insertInset(inset))
3012 updateInset(inset, true);
3017 case LFUN_INDEX_PRINT:
3019 InsetCommandParams p("printindex");
3020 Inset * inset = new InsetPrintIndex(p);
3021 if (!insertInset(inset, "Standard"))
3026 case LFUN_PARENTINSERT:
3028 lyxerr << "arg " << argument << endl;
3029 InsetCommandParams p( "lyxparent", argument );
3030 Inset * inset = new InsetParent(p, *buffer_);
3031 if (!insertInset(inset, "Standard"))
3037 case LFUN_CHILD_INSERT:
3039 InsetInclude::Params p;
3040 p.cparams.setFromString(argument);
3041 p.masterFilename_ = buffer_->fileName();
3043 InsetInclude * inset = new InsetInclude(p);
3044 if (!insertInset(inset))
3047 updateInset(inset, true);
3048 bv_->owner()->getDialogs()->showInclude(inset);
3053 case LFUN_FLOAT_LIST:
3055 // We should check the argument for validity. (Lgb)
3056 Inset * inset = new InsetFloatList(argument);
3057 if (!insertInset(inset, "Standard"))
3062 case LFUN_THESAURUS_ENTRY:
3064 string arg = argument;
3067 arg = bv_->getLyXText()->selectionAsString(buffer_,
3071 if (arg.size() > 100 || arg.empty()) {
3072 // Get word or selection
3073 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3074 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3075 // FIXME: where is getLyXText()->unselect(bv_) ?
3079 bv_->owner()->getDialogs()->showThesaurus(arg);
3083 case LFUN_SELFINSERT:
3085 if (argument.empty()) break;
3087 /* Automatically delete the currently selected
3088 * text and replace it with what is being
3089 * typed in now. Depends on lyxrc settings
3090 * "auto_region_delete", which defaults to
3093 LyXText * lt = bv_->getLyXText();
3095 if (lyxrc.auto_region_delete) {
3096 if (lt->selection.set()) {
3097 lt->cutSelection(bv_, false, false);
3100 | BufferView::FITCUR
3101 | BufferView::CHANGE);
3106 LyXFont const old_font(lt->real_current_font);
3108 string::const_iterator cit = argument.begin();
3109 string::const_iterator end = argument.end();
3110 for (; cit != end; ++cit) {
3111 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3116 | BufferView::FITCUR
3117 | BufferView::CHANGE);
3119 lt->selection.cursor = lt->cursor;
3120 moveCursorUpdate(false);
3122 // real_current_font.number can change so we need to
3123 // update the minibuffer
3124 if (old_font != lt->real_current_font)
3125 owner_->showState();
3130 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3132 time_t now_time_t = time(NULL);
3133 struct tm * now_tm = localtime(&now_time_t);
3134 setlocale(LC_TIME, "");
3136 if (!argument.empty())
3139 arg = lyxrc.date_insert_format;
3141 int const datetmp_len =
3142 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3144 LyXText * lt = bv_->getLyXText();
3146 for (int i = 0; i < datetmp_len; i++) {
3147 lt->insertChar(bv_, datetmp[i]);
3150 | BufferView::FITCUR
3151 | BufferView::CHANGE);
3154 lt->selection.cursor = lt->cursor;
3155 moveCursorUpdate(false);
3159 case LFUN_UNKNOWN_ACTION:
3160 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3171 void BufferView::Pimpl::newline()
3174 LyXText * lt = bv_->getLyXText();
3178 | BufferView::FITCUR);
3179 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3182 | BufferView::FITCUR
3183 | BufferView::CHANGE);
3188 void BufferView::Pimpl::hfill()
3191 LyXText * lt = bv_->getLyXText();
3195 | BufferView::FITCUR);
3196 lt->insertChar(bv_, Paragraph::META_HFILL);
3199 | BufferView::FITCUR
3200 | BufferView::CHANGE);
3205 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3209 update(lt, BufferView::SELECT|BufferView::FITCUR);
3210 InsetSpecialChar * new_inset =
3211 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3212 #ifdef WITH_WARNINGS
3213 #warning Why is this code different from specialChar() below? (JMarc)
3214 // the code in specialChar is a generic version of what used to exist
3215 // for other special chars. I did not merge this case because of the
3216 // call to updateInset(), but what does it do?
3218 if (!insertInset(new_inset))
3221 updateInset(new_inset, true);
3226 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3229 LyXText * lt = bv_->getLyXText();
3232 update(lt, BufferView::SELECT|BufferView::FITCUR);
3233 InsetSpecialChar * new_inset =
3234 new InsetSpecialChar(kind);
3235 insertInset(new_inset);
3236 // Ok, what happens here if we are unable to insert
3237 // the inset? Leak it?
3242 void BufferView::Pimpl::smartQuote()
3244 LyXText const * lt = bv_->getLyXText();
3245 Paragraph const * par = lt->cursor.par();
3246 Paragraph::size_type pos = lt->cursor.pos();
3250 || (par->isInset(pos - 1)
3251 && par->getInset(pos - 1)->isSpace()))
3254 c = par->getChar(pos - 1);
3259 LyXLayout const & style = textclasslist.Style(
3260 bv_->buffer()->params.textclass, par->getLayout());
3262 if (style.pass_thru ||
3263 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3264 Dispatch(LFUN_SELFINSERT, "\"");
3268 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3270 if (insertInset(inset))
3277 // Open and lock an updatable inset
3278 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3280 LyXText * lt = bv_->getLyXText();
3284 if (!insertInset(new_inset)) {
3288 new_inset->edit(bv_, !behind);
3293 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3295 // if we are in a locking inset we should try to insert the
3296 // inset there otherwise this is a illegal function now
3297 if (bv_->theLockingInset()) {
3298 if (bv_->theLockingInset()->insetAllowed(inset))
3299 return bv_->theLockingInset()->insertInset(bv_, inset);
3303 // not quite sure if we want this...
3304 setCursorParUndo(bv_);
3307 beforeChange(bv_->text);
3308 if (!lout.empty()) {
3309 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3310 bv_->text->breakParagraph(bv_);
3311 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3313 if (bv_->text->cursor.par()->size()) {
3314 bv_->text->cursorLeft(bv_);
3316 bv_->text->breakParagraph(bv_);
3317 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3320 pair<bool, LyXTextClass::size_type> lres =
3321 textclasslist.NumberOfLayout(buffer_->params
3323 LyXTextClass::size_type lay;
3324 if (lres.first != false) {
3328 // layout not fount using default "Standard" (0)
3332 bv_->text->setLayout(bv_, lay);
3334 bv_->text->setParagraph(bv_, 0, 0,
3336 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3341 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3344 bv_->text->insertInset(bv_, inset);
3345 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3352 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3357 // first check for locking insets
3358 if (bv_->theLockingInset()) {
3359 if (bv_->theLockingInset() == inset) {
3360 if (bv_->text->updateInset(bv_, inset)) {
3363 buffer_->markDirty();
3368 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3369 if (bv_->text->updateInset(bv_,
3370 bv_->theLockingInset())) {
3373 buffer_->markDirty();
3381 // then check the current buffer
3384 update(bv_->text, BufferView::UPDATE);
3385 if (bv_->text->updateInset(bv_, inset)) {
3389 | BufferView::FITCUR
3390 | BufferView::CHANGE);
3392 update(bv_->text, SELECT);
3400 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3403 if (!available()) return;
3406 beforeChange(bv_->text);
3407 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3409 LyXCursor const & cursor = bv_->text->cursor;
3413 isMetaInset(cursor.par(), cursor.pos())) {
3414 Inset const * inset = cursor.par()->getInset(cursor.pos());
3415 if (find(codes.begin(), codes.end(), inset->lyxCode())
3418 static_cast<InsetCommand const *>(inset)->getContents();
3422 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3423 if (bv_->text->cursor.pos()
3424 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3425 LyXCursor tmp = bv_->text->cursor;
3426 bv_->text->cursor.par(bv_->text->firstParagraph());
3427 bv_->text->cursor.pos(0);
3428 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3429 bv_->text->cursor = tmp;
3430 bv_->owner()->message(_("No more insets"));
3433 bv_->owner()->message(_("No more insets"));
3436 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3437 bv_->text->selection.cursor = bv_->text->cursor;
3441 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3443 gotoInset(vector<Inset::Code>(1, code), same_content);