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 ((inset_hit != 0) &&
626 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
627 // Highly editable inset, like math
628 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
629 selection_possible = false;
630 owner_->updateLayoutChoice();
631 owner_->message(inset->editMessage());
632 inset->insetButtonPress(bv_, xpos, ypos, button);
633 inset->edit(bv_, xpos, ypos, button);
637 // Right click on a footnote flag opens float menu
639 selection_possible = false;
643 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
644 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
646 bv_->text->selection.cursor = bv_->text->cursor;
647 bv_->text->cursor.x_fix(bv_->text->cursor.x());
649 owner_->updateLayoutChoice();
651 selection_possible = false;
654 // Insert primary selection with middle mouse
655 // if there is a local selection in the current buffer,
658 if (paste_internally)
659 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
661 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
663 selection_possible = false;
669 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
675 LyXText * text = bv_->getLyXText();
677 if (text->bv_owner && bv_->theLockingInset())
680 if (screen_.get() && button == 1) {
681 if (text->bv_owner) {
682 screen_->hideCursor();
683 screen_->toggleSelection(text, bv_);
684 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
685 screen_->toggleSelection(text, bv_, false);
687 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
689 /* This will fit the cursor on the screen
691 update(text, BufferView::SELECT|BufferView::FITCUR);
696 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
702 LyXText * text = bv_->getLyXText();
704 if (text->bv_owner && bv_->theLockingInset())
707 if (screen_.get() && (button == 1)) {
708 screen_->hideCursor();
709 screen_->toggleSelection(text, bv_);
710 text->cursorHome(bv_);
711 text->selection.cursor = text->cursor;
712 text->cursorEnd(bv_);
713 text->setSelection(bv_);
714 screen_->toggleSelection(text, bv_, false);
715 /* This will fit the cursor on the screen
717 update(text, BufferView::SELECT|BufferView::FITCUR);
722 void BufferView::Pimpl::enterView()
724 if (active() && available()) {
725 SetXtermCursor(workarea_.getWin());
726 using_xterm_cursor = true;
731 void BufferView::Pimpl::leaveView()
733 if (using_xterm_cursor) {
734 XUndefineCursor(fl_get_display(), workarea_.getWin());
735 using_xterm_cursor = false;
740 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
743 if (!buffer_ || !screen_.get()) return;
745 // If we hit an inset, we have the inset coordinates in these
746 // and inset_hit points to the inset. If we do not hit an
747 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
748 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
750 if (bv_->theLockingInset()) {
751 // We are in inset locking mode.
753 /* LyX does a kind of work-area grabbing for insets.
754 Only a ButtonPress Event outside the inset will
755 force a insetUnlock. */
756 bv_->theLockingInset()->
757 insetButtonRelease(bv_, x, y, button);
761 selection_possible = false;
769 // Did we hit an editable inset?
771 // Inset like error, notes and figures
772 selection_possible = false;
774 // CHECK fix this proper in 0.13
776 // Following a ref shouldn't issue
777 // a push on the undo-stack
778 // anylonger, now that we have
779 // keybindings for following
780 // references and returning from
781 // references. IMHO though, it
782 // should be the inset's own business
783 // to push or not push on the undo
784 // stack. They don't *have* to
785 // alter the document...
787 // ...or maybe the SetCursorParUndo()
788 // below isn't necessary at all anylonger?
789 if (inset_hit->lyxCode() == Inset::REF_CODE) {
790 setCursorParUndo(bv_);
793 owner_->message(inset_hit->editMessage());
795 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
796 // Highly editable inset, like math
797 UpdatableInset *inset = (UpdatableInset *)inset_hit;
798 inset->insetButtonRelease(bv_, x, y, button);
800 inset_hit->insetButtonRelease(bv_, x, y, button);
801 inset_hit->edit(bv_, x, y, button);
807 #warning variable c is set but never used. What is it good for?? (JMarc)
809 // check whether we want to open a float
813 if (bv_->text->cursor.pos() <
814 bv_->text->cursor.par()->size()) {
815 c = bv_->text->cursor.par()->
816 getChar(bv_->text->cursor.pos());
818 if (bv_->text->cursor.pos() - 1 >= 0) {
819 c = bv_->text->cursor.par()->
820 getChar(bv_->text->cursor.pos() - 1);
823 selection_possible = false;
828 // Maybe we want to edit a bibitem ale970302
829 if (bv_->text->cursor.par()->bibkey && x < 20 +
830 bibitemMaxWidth(bv_, textclasslist.
832 params.textclass).defaultfont())) {
833 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
841 * Returns an inset if inset was hit. 0 otherwise.
842 * If hit, the coordinates are changed relative to the inset.
843 * Otherwise coordinates are not changed, and false is returned.
845 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
846 unsigned int /* button */)
851 int y_tmp = y + text->first;
854 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
855 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
858 if (cursor.pos() < cursor.par()->size()
859 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
860 && cursor.par()->getInset(cursor.pos())
861 && cursor.par()->getInset(cursor.pos())->editable()) {
863 // Check whether the inset really was hit
864 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
865 LyXFont font = text->getFont(buffer_,
866 cursor.par(), cursor.pos());
867 int const width = tmpinset->width(bv_, font);
868 int const inset_x = font.isVisibleRightToLeft()
869 ? cursor.x() - width : cursor.x();
870 int const start_x = inset_x + tmpinset->scroll();
871 int const end_x = inset_x + width;
873 if (x > start_x && x < end_x
874 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
875 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
876 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
878 // The origin of an inset is on the baseline
879 y = y_tmp - (text->cursor.y());
884 if ((cursor.pos() - 1 >= 0) &&
885 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
886 (cursor.par()->getInset(cursor.pos() - 1)) &&
887 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
888 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
889 LyXFont font = text->getFont(buffer_, cursor.par(),
891 int const width = tmpinset->width(bv_, font);
892 int const inset_x = font.isVisibleRightToLeft()
893 ? cursor.x() : cursor.x() - width;
894 int const start_x = inset_x + tmpinset->scroll();
895 int const end_x = inset_x + width;
897 if (x > start_x && x < end_x
898 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
899 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
901 if (move_cursor && (tmpinset != bv_->theLockingInset()))
903 text->setCursor(bv_, cursor.par(),
904 cursor.pos() - 1, true);
906 // The origin of an inset is on the baseline
907 y = y_tmp - (text->cursor.y());
915 void BufferView::Pimpl::workAreaExpose()
917 static int work_area_width;
918 static unsigned int work_area_height;
920 bool const widthChange = workarea_.workWidth() != work_area_width;
921 bool const heightChange = workarea_.height() != work_area_height;
923 // update from work area
924 work_area_width = workarea_.workWidth();
925 work_area_height = workarea_.height();
928 // The visible LyXView need a resize
931 // Remove all texts from the textcache
932 // This is not _really_ what we want to do. What
933 // we really want to do is to delete in textcache
934 // that does not have a BufferView with matching
935 // width, but as long as we have only one BufferView
936 // deleting all gives the same result.
937 if (lyxerr.debugging())
938 textcache.show(lyxerr, "Expose delete all");
940 } else if (heightChange) {
941 // Rebuild image of current screen
943 // fitCursor() ensures we don't jump back
944 // to the start of the document on vertical
948 // The main window size has changed, repaint most stuff
950 } else if (screen_.get())
951 screen_->redraw(bv_->text, bv_);
953 // Grey box when we don't have a buffer
957 // always make sure that the scrollbar is sane.
959 owner_->updateLayoutChoice();
964 void BufferView::Pimpl::update()
967 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
969 LyXText::text_status st = bv_->text->status();
970 screen_->update(bv_->text, bv_);
972 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
973 if (bv_->text->fullRebreak(bv_)) {
974 st = LyXText::NEED_MORE_REFRESH;
975 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
976 bv_->text->cursor.pos());
979 bv_->text->status(bv_, st);
980 screen_->update(bv_->text, bv_);
982 // do this here instead of in the screen::update because of
984 bv_->text->status(bv_, LyXText::UNCHANGED);
990 // Values used when calling update:
992 // -2 - update, move sel_cursor if selection, fitcursor
993 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
994 // 0 - update, move sel_cursor if selection, fitcursor
995 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
996 // 3 - update, move sel_cursor if selection
999 // a simple redraw of the parts that need refresh
1001 // move sel_cursor if selection -
1002 // the text's sel_cursor is moved if there is selection is progress
1005 // fitCursor() is called and the scrollbar updated
1008 // the buffer is marked dirty.
1017 // UPDATE_ONLY = UPDATE;
1018 // UPDATE_SELECT = UPDATE | SELECT;
1019 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1020 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1022 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1023 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1024 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1025 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1026 // update(3) -> update(1) -> update(1) -> update(SELECT)
1028 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1030 owner_->updateLayoutChoice();
1032 if (!text->selection.set() && (f & SELECT)) {
1033 text->selection.cursor = text->cursor;
1036 text->fullRebreak(bv_);
1038 if (text->inset_owner) {
1039 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1040 updateInset(text->inset_owner, false);
1050 buffer_->markDirty();
1055 // Callback for cursor timer
1056 void BufferView::Pimpl::cursorToggle()
1058 // Quite a nice place for asyncron Inset updating, isn't it?
1059 // Actually no! This is run even if no buffer exist... so (Lgb)
1061 cursor_timeout.restart();
1066 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1067 if (pid == -1) // error find out what is wrong
1068 ; // ignore it for now.
1070 sigchldchecker(pid, &status);
1072 updatelist.update(bv_);
1074 if (!screen_.get()) {
1075 cursor_timeout.restart();
1079 if (!bv_->theLockingInset()) {
1080 screen_->cursorToggle(bv_);
1082 bv_->theLockingInset()->toggleInsetCursor(bv_);
1085 cursor_timeout.restart();
1089 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1091 if (!text->cursor.row()->previous())
1094 int y = text->first;
1095 if (text->inset_owner)
1096 y += bv_->text->first;
1097 Row * cursorrow = text->cursor.row();
1098 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1100 // This is to allow jumping over large insets
1101 if ((cursorrow == text->cursor.row()))
1102 text->cursorUp(bv_);
1104 if (text->inset_owner ||
1105 text->cursor.row()->height() < workarea_.height())
1106 screen_->draw(bv_->text, bv_,
1108 - text->cursor.row()->baseline()
1109 + text->cursor.row()->height()
1110 - workarea_.height() + 1 );
1115 void BufferView::Pimpl::cursorNext(LyXText * text)
1117 if (!text->cursor.row()->next())
1120 int y = text->first + workarea_.height();
1121 // if (text->inset_owner)
1122 // y += bv_->text->first;
1123 text->getRowNearY(y);
1125 Row * cursorrow = text->cursor.row();
1126 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1128 // This is to allow jumping over large insets
1129 if ((cursorrow == bv_->text->cursor.row()))
1130 text->cursorDown(bv_);
1132 if (text->inset_owner ||
1133 text->cursor.row()->height() < workarea_.height())
1134 screen_->draw(bv_->text, bv_, text->cursor.y() -
1135 text->cursor.row()->baseline());
1140 bool BufferView::Pimpl::available() const
1142 if (buffer_ && bv_->text) return true;
1147 void BufferView::Pimpl::beforeChange(LyXText * text)
1150 text->clearSelection();
1154 void BufferView::Pimpl::savePosition(unsigned int i)
1156 if (i >= saved_positions_num)
1158 saved_positions[i] = Position(buffer_->fileName(),
1159 bv_->text->cursor.par()->id(),
1160 bv_->text->cursor.pos());
1163 str << _("Saved bookmark") << ' ' << i;
1164 owner_->message(str.str().c_str());
1169 void BufferView::Pimpl::restorePosition(unsigned int i)
1171 if (i >= saved_positions_num)
1174 string const fname = saved_positions[i].filename;
1176 beforeChange(bv_->text);
1178 if (fname != buffer_->fileName()) {
1179 Buffer * b = bufferlist.exists(fname) ?
1180 bufferlist.getBuffer(fname) :
1181 bufferlist.loadLyXFile(fname); // don't ask, just load it
1182 if (b != 0 ) buffer(b);
1185 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1189 bv_->text->setCursor(bv_, par,
1190 min(par->size(), saved_positions[i].par_pos));
1192 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1195 str << _("Moved to bookmark") << ' ' << i;
1196 owner_->message(str.str().c_str());
1201 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1203 if (i >= saved_positions_num)
1206 return !saved_positions[i].filename.empty();
1210 void BufferView::Pimpl::setState()
1212 if (!lyxrc.rtl_support)
1215 LyXText * text = bv_->getLyXText();
1216 if (text->real_current_font.isRightToLeft()) {
1217 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1218 owner_->getIntl()->KeyMapSec();
1220 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1221 owner_->getIntl()->KeyMapPrim();
1226 void BufferView::Pimpl::insetSleep()
1228 if (bv_->theLockingInset() && !inset_slept) {
1229 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1230 bv_->theLockingInset()->insetUnlock(bv_);
1236 void BufferView::Pimpl::insetWakeup()
1238 if (bv_->theLockingInset() && inset_slept) {
1239 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1240 inset_slept = false;
1245 void BufferView::Pimpl::insetUnlock()
1247 if (bv_->theLockingInset()) {
1249 bv_->theLockingInset()->insetUnlock(bv_);
1250 bv_->theLockingInset(0);
1252 inset_slept = false;
1257 bool BufferView::Pimpl::focus() const
1259 return workarea_.hasFocus();
1263 void BufferView::Pimpl::focus(bool f)
1265 if (f) workarea_.setFocus();
1269 bool BufferView::Pimpl::active() const
1271 return workarea_.active();
1275 bool BufferView::Pimpl::belowMouse() const
1277 return workarea_.belowMouse();
1281 void BufferView::Pimpl::showCursor()
1283 if (screen_.get()) {
1284 if (bv_->theLockingInset())
1285 bv_->theLockingInset()->showInsetCursor(bv_);
1287 screen_->showCursor(bv_->text, bv_);
1292 void BufferView::Pimpl::hideCursor()
1294 if (screen_.get()) {
1295 if (!bv_->theLockingInset())
1296 // bv_->theLockingInset()->hideInsetCursor(bv_);
1298 screen_->hideCursor();
1303 void BufferView::Pimpl::toggleSelection(bool b)
1305 if (screen_.get()) {
1306 if (bv_->theLockingInset())
1307 bv_->theLockingInset()->toggleSelection(bv_, b);
1308 screen_->toggleSelection(bv_->text, bv_, b);
1313 void BufferView::Pimpl::toggleToggle()
1316 screen_->toggleToggle(bv_->text, bv_);
1320 void BufferView::Pimpl::center()
1322 beforeChange(bv_->text);
1323 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1324 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1326 screen_->draw(bv_->text, bv_, 0);
1328 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1333 void BufferView::Pimpl::pasteClipboard(bool asPara)
1335 if (!buffer_) return;
1337 screen_->hideCursor();
1338 beforeChange(bv_->text);
1340 string const clip(workarea_.getClipboard());
1342 if (clip.empty()) return;
1345 bv_->text->insertStringAsParagraphs(bv_, clip);
1347 bv_->text->insertStringAsLines(bv_, clip);
1349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1353 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1355 workarea_.putClipboard(stuff);
1360 * Dispatch functions for actions which can be valid for BufferView->text
1361 * and/or InsetText->text!!!
1366 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1368 LyXText * lt = bv_->getLyXText();
1370 if (selecting || lt->selection.mark()) {
1371 lt->setSelection(bv_);
1375 update(lt, BufferView::SELECT|BufferView::FITCUR);
1378 /* ---> Everytime the cursor is moved, show the current font state. */
1379 // should this too me moved out of this func?
1380 //owner->showState();
1385 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1387 LyXCursor cursor = bv_->getLyXText()->cursor;
1388 Buffer::inset_iterator it =
1389 find_if(Buffer::inset_iterator(
1390 cursor.par(), cursor.pos()),
1391 buffer_->inset_iterator_end(),
1392 lyx::compare_memfun(&Inset::lyxCode, code));
1393 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1397 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1399 string filename = filen;
1401 if (filename.empty()) {
1402 // Launch a file browser
1403 string initpath = lyxrc.document_path;
1406 string const trypath = owner_->buffer()->filepath;
1407 // If directory is writeable, use this as default.
1408 if (IsDirWriteable(trypath))
1412 FileDialog fileDlg(bv_->owner(),
1413 _("Select LyX document to insert"),
1415 make_pair(string(_("Documents")),
1416 string(lyxrc.document_path)),
1417 make_pair(string(_("Examples")),
1418 string(AddPath(system_lyxdir, "examples"))));
1420 FileDialog::Result result =
1421 fileDlg.Select(initpath,
1422 _("*.lyx| LyX Documents (*.lyx)"));
1424 if (result.first == FileDialog::Later)
1427 filename = result.second;
1429 // check selected filename
1430 if (filename.empty()) {
1431 owner_->message(_("Canceled."));
1436 // get absolute path of file and add ".lyx" to the filename if
1438 filename = FileSearch(string(), filename, "lyx");
1440 string const disp_fn(MakeDisplayPath(filename));
1443 s1 << _("Inserting document") << ' '
1444 << disp_fn << " ...";
1445 owner_->message(s1.str().c_str());
1446 bool const res = bv_->insertLyXFile(filename);
1449 str << _("Document") << ' ' << disp_fn
1450 << ' ' << _("inserted.");
1451 owner_->message(str.str().c_str());
1454 str << _("Could not insert document") << ' '
1456 owner_->message(str.str().c_str());
1461 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1463 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1464 << action <<"] arg[" << argument << "]" << endl;
1467 // --- Misc -------------------------------------------
1471 LyXText * lt = bv_->getLyXText();
1472 lt->toggleAppendix(bv_);
1475 | BufferView::FITCUR
1476 | BufferView::CHANGE);
1481 case LFUN_TOC_INSERT:
1483 InsetCommandParams p;
1484 p.setCmdName("tableofcontents");
1485 Inset * inset = new InsetTOC(p);
1486 if (!insertInset(inset, "Standard"))
1491 case LFUN_TABULAR_FEATURE:
1492 case LFUN_SCROLL_INSET:
1493 // this is not handled here as this funktion is only aktive
1494 // if we have a locking_inset and that one is (or contains)
1498 case LFUN_INSET_GRAPHICS:
1500 Inset * new_inset = new InsetGraphics;
1501 if (!insertInset(new_inset)) {
1504 // this is need because you don't use a inset->Edit()
1505 updateInset(new_inset, true);
1506 new_inset->edit(bv_);
1516 case LFUN_PASTESELECTION:
1518 bool asPara = false;
1519 if (argument == "paragraph") asPara = true;
1520 pasteClipboard(asPara);
1532 case LFUN_LAYOUT_COPY:
1533 bv_->copyEnvironment();
1536 case LFUN_LAYOUT_PASTE:
1537 bv_->pasteEnvironment();
1541 case LFUN_GOTOERROR:
1542 gotoInset(Inset::ERROR_CODE, false);
1546 gotoInset(Inset::IGNORE_CODE, false);
1549 case LFUN_REFERENCE_GOTO:
1551 vector<Inset::Code> tmp;
1552 tmp.push_back(Inset::LABEL_CODE);
1553 tmp.push_back(Inset::REF_CODE);
1554 gotoInset(tmp, true);
1558 case LFUN_HYPHENATION:
1559 specialChar(InsetSpecialChar::HYPHENATION);
1562 case LFUN_LIGATURE_BREAK:
1563 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1567 specialChar(InsetSpecialChar::LDOTS);
1570 case LFUN_END_OF_SENTENCE:
1571 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1574 case LFUN_MENU_SEPARATOR:
1575 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1583 changeDepth(bv_, bv_->getLyXText(), 0);
1586 case LFUN_DEPTH_MIN:
1587 changeDepth(bv_, bv_->getLyXText(), -1);
1590 case LFUN_DEPTH_PLUS:
1591 changeDepth(bv_, bv_->getLyXText(), 1);
1595 owner_->getDialogs()->setUserFreeFont();
1598 case LFUN_FILE_INSERT:
1600 MenuInsertLyXFile(argument);
1604 case LFUN_FILE_INSERT_ASCII_PARA:
1605 InsertAsciiFile(bv_, argument, true);
1608 case LFUN_FILE_INSERT_ASCII:
1609 InsertAsciiFile(bv_, argument, false);
1614 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1615 << argument << endl;
1617 // Derive layout number from given argument (string)
1618 // and current buffer's textclass (number). */
1619 LyXTextClassList::ClassList::size_type tclass =
1620 buffer_->params.textclass;
1621 pair <bool, LyXTextClass::size_type> layout =
1622 textclasslist.NumberOfLayout(tclass, argument);
1624 // If the entry is obsolete, use the new one instead.
1626 string obs = textclasslist.Style(tclass,layout.second)
1630 textclasslist.NumberOfLayout(tclass, obs);
1633 // see if we found the layout number:
1634 if (!layout.first) {
1635 owner_->getLyXFunc()->setErrorMessage(
1636 string(N_("Layout ")) + argument +
1641 if (current_layout != layout.second) {
1642 LyXText * lt = bv_->getLyXText();
1644 current_layout = layout.second;
1647 | BufferView::FITCUR);
1648 lt->setLayout(bv_, layout.second);
1649 owner_->setLayout(layout.second);
1652 | BufferView::FITCUR
1653 | BufferView::CHANGE);
1660 lang(bv_, argument);
1662 owner_->showState();
1667 owner_->showState();
1672 owner_->showState();
1677 owner_->showState();
1682 owner_->showState();
1687 owner_->showState();
1692 owner_->showState();
1697 owner_->showState();
1700 case LFUN_UNDERLINE:
1702 owner_->showState();
1705 case LFUN_FONT_SIZE:
1706 fontSize(bv_, argument);
1707 owner_->showState();
1710 case LFUN_FONT_STATE:
1711 owner_->getLyXFunc()->setMessage(currentState(bv_));
1714 case LFUN_UPCASE_WORD:
1716 LyXText * lt = bv_->getLyXText();
1720 | BufferView::FITCUR);
1721 lt->changeCase(bv_, LyXText::text_uppercase);
1722 if (lt->inset_owner)
1723 updateInset(lt->inset_owner, true);
1726 | BufferView::FITCUR
1727 | BufferView::CHANGE);
1731 case LFUN_LOWCASE_WORD:
1733 LyXText * lt = bv_->getLyXText();
1735 update(lt, BufferView::SELECT|BufferView::FITCUR);
1736 lt->changeCase(bv_, LyXText::text_lowercase);
1737 if (lt->inset_owner)
1738 updateInset(lt->inset_owner, true);
1741 | BufferView::FITCUR
1742 | BufferView::CHANGE);
1746 case LFUN_CAPITALIZE_WORD:
1748 LyXText * lt = bv_->getLyXText();
1750 update(lt, BufferView::SELECT|BufferView::FITCUR);
1751 lt->changeCase(bv_, LyXText::text_capitalization);
1752 if (lt->inset_owner)
1753 updateInset(lt->inset_owner, true);
1756 | BufferView::FITCUR
1757 | BufferView::CHANGE);
1761 case LFUN_TRANSPOSE_CHARS:
1763 LyXText * lt = bv_->getLyXText();
1765 update(lt, BufferView::SELECT|BufferView::FITCUR);
1766 lt->transposeChars(*bv_);
1767 if (lt->inset_owner)
1768 updateInset(lt->inset_owner, true);
1771 | BufferView::FITCUR
1772 | BufferView::CHANGE);
1777 case LFUN_INSERT_LABEL:
1778 MenuInsertLabel(bv_, argument);
1781 case LFUN_REF_INSERT:
1782 if (argument.empty()) {
1783 InsetCommandParams p("ref");
1784 owner_->getDialogs()->createRef(p.getAsString());
1786 InsetCommandParams p;
1787 p.setFromString(argument);
1789 InsetRef * inset = new InsetRef(p, *buffer_);
1790 if (!insertInset(inset))
1793 updateInset(inset, true);
1797 case LFUN_BOOKMARK_SAVE:
1798 savePosition(strToUnsignedInt(argument));
1801 case LFUN_BOOKMARK_GOTO:
1802 restorePosition(strToUnsignedInt(argument));
1807 string label(argument);
1808 if (label.empty()) {
1810 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1812 label = inset->getContents();
1817 if (!label.empty()) {
1818 //bv_->savePosition(0);
1819 if (!bv_->gotoLabel(label))
1820 WriteAlert(_("Error"),
1821 _("Couldn't find this label"),
1822 _("in current document."));
1827 // --- Cursor Movements -----------------------------
1830 LyXText * lt = bv_->getLyXText();
1832 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1833 if (!lt->selection.mark())
1835 update(lt, BufferView::SELECT|BufferView::FITCUR);
1837 lt->cursorLeft(bv_, false);
1838 if (lt->cursor.pos() < lt->cursor.par()->size()
1839 && lt->cursor.par()->getChar(lt->cursor.pos())
1840 == Paragraph::META_INSET
1841 && lt->cursor.par()->getInset(lt->cursor.pos())
1842 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1843 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1844 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1846 tmpinset->edit(bv_, false);
1848 tmpinset->edit(bv_);
1852 lt->cursorRight(bv_, false);
1854 moveCursorUpdate(false);
1855 owner_->showState();
1861 // This is soooo ugly. Isn`t it possible to make
1862 // it simpler? (Lgb)
1863 LyXText * lt = bv_->getLyXText();
1864 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1865 if (!lt->selection.mark())
1867 update(lt, BufferView::SELECT|BufferView::FITCUR);
1868 LyXCursor const cur = lt->cursor;
1870 lt->cursorLeft(bv_, false);
1871 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1872 lt->cursor.pos() < lt->cursor.par()->size() &&
1873 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1874 Paragraph::META_INSET) &&
1875 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1876 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1877 == Inset::HIGHLY_EDITABLE))
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 Paragraph::size_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()
3254 LyXText * lt = bv_->getLyXText();
3256 if (lt->cursor.pos())
3257 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3263 LyXLayout const & style = textclasslist.Style(
3264 bv_->buffer()->params.textclass,
3265 lt->cursor.par()->getLayout());
3267 if (style.pass_thru ||
3268 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3269 Dispatch(LFUN_SELFINSERT, "\"");
3273 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3275 if (insertInset(inset))
3282 // Open and lock an updatable inset
3283 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3285 LyXText * lt = bv_->getLyXText();
3289 if (!insertInset(new_inset)) {
3293 new_inset->edit(bv_, !behind);
3298 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3300 // if we are in a locking inset we should try to insert the
3301 // inset there otherwise this is a illegal function now
3302 if (bv_->theLockingInset()) {
3303 if (bv_->theLockingInset()->insetAllowed(inset))
3304 return bv_->theLockingInset()->insertInset(bv_, inset);
3308 // not quite sure if we want this...
3309 setCursorParUndo(bv_);
3312 beforeChange(bv_->text);
3313 if (!lout.empty()) {
3314 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3315 bv_->text->breakParagraph(bv_);
3316 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3318 if (bv_->text->cursor.par()->size()) {
3319 bv_->text->cursorLeft(bv_);
3321 bv_->text->breakParagraph(bv_);
3322 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3325 pair<bool, LyXTextClass::size_type> lres =
3326 textclasslist.NumberOfLayout(buffer_->params
3328 LyXTextClass::size_type lay;
3329 if (lres.first != false) {
3333 // layout not fount using default "Standard" (0)
3337 bv_->text->setLayout(bv_, lay);
3339 bv_->text->setParagraph(bv_, 0, 0,
3341 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3349 bv_->text->insertInset(bv_, inset);
3350 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3357 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3362 // first check for locking insets
3363 if (bv_->theLockingInset()) {
3364 if (bv_->theLockingInset() == inset) {
3365 if (bv_->text->updateInset(bv_, inset)) {
3368 buffer_->markDirty();
3373 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3374 if (bv_->text->updateInset(bv_,
3375 bv_->theLockingInset())) {
3378 buffer_->markDirty();
3386 // then check the current buffer
3389 update(bv_->text, BufferView::UPDATE);
3390 if (bv_->text->updateInset(bv_, inset)) {
3394 | BufferView::FITCUR
3395 | BufferView::CHANGE);
3397 update(bv_->text, SELECT);
3405 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3408 if (!available()) return;
3411 beforeChange(bv_->text);
3412 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3416 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3417 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3418 if (find(codes.begin(), codes.end(), inset->lyxCode())
3421 static_cast<InsetCommand const *>(inset)->getContents();
3424 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3425 if (bv_->text->cursor.pos()
3426 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3427 LyXCursor tmp = bv_->text->cursor;
3428 bv_->text->cursor.par(bv_->text->firstParagraph());
3429 bv_->text->cursor.pos(0);
3430 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3431 bv_->text->cursor = tmp;
3432 bv_->owner()->message(_("No more insets"));
3435 bv_->owner()->message(_("No more insets"));
3438 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3439 bv_->text->selection.cursor = bv_->text->cursor;
3443 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3445 gotoInset(vector<Inset::Code>(1, code), same_content);