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;
70 extern int greek_kb_flag;
81 /* the selection possible is needed, that only motion events are
82 * used, where the bottom press event was on the drawing area too */
83 bool selection_possible = false;
85 extern BufferList bufferlist;
86 extern char ascii_type;
88 extern bool math_insert_greek(BufferView *, char);
89 extern void sigchldchecker(pid_t pid, int * status);
90 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
95 const unsigned int saved_positions_num = 20;
100 XSync(fl_get_display(), 0);
104 void SetXtermCursor(Window win)
106 static Cursor cursor;
107 static bool cursor_undefined = true;
108 if (cursor_undefined){
109 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
110 XFlush(fl_get_display());
111 cursor_undefined = false;
113 XDefineCursor(fl_get_display(), win, cursor);
114 XFlush(fl_get_display());
120 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
121 int xpos, int ypos, int width, int height)
122 : bv_(b), owner_(o), buffer_(0),
123 current_scrollbar_value(0), cursor_timeout(400),
124 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
128 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
129 workarea_.workAreaExpose
130 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
131 workarea_.workAreaEnter
132 .connect(slot(this, &BufferView::Pimpl::enterView));
133 workarea_.workAreaLeave
134 .connect(slot(this, &BufferView::Pimpl::leaveView));
135 workarea_.workAreaButtonPress
136 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
137 workarea_.workAreaButtonRelease
139 &BufferView::Pimpl::workAreaButtonRelease));
140 workarea_.workAreaMotionNotify
141 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
142 workarea_.workAreaDoubleClick
143 .connect(slot(this, &BufferView::Pimpl::doubleClick));
144 workarea_.workAreaTripleClick
145 .connect(slot(this, &BufferView::Pimpl::tripleClick));
146 workarea_.workAreaKeyPress
147 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
149 cursor_timeout.timeout.connect(slot(this,
150 &BufferView::Pimpl::cursorToggle));
151 cursor_timeout.start();
152 workarea_.setFocus();
153 saved_positions.resize(saved_positions_num);
157 Painter & BufferView::Pimpl::painter()
159 return workarea_.getPainter();
163 void BufferView::Pimpl::buffer(Buffer * b)
165 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
169 buffer_->delUser(bv_);
171 // Put the old text into the TextCache, but
172 // only if the buffer is still loaded.
173 // Also set the owner of the test to 0
174 // bv_->text->owner(0);
175 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
176 if (lyxerr.debugging())
177 textcache.show(lyxerr, "BufferView::buffer");
182 // Set current buffer
185 if (bufferlist.getState() == BufferList::CLOSING) return;
188 // screen is always deleted when the buffer is changed.
191 // If we are closing the buffer, use the first buffer as current
193 buffer_ = bufferlist.first();
197 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
198 buffer_->addUser(bv_);
199 // If we don't have a text object for this, we make one
200 if (bv_->text == 0) {
201 resizeCurrentBuffer();
206 bv_->text->first = screen_->topCursorVisible(bv_->text);
207 owner_->updateMenubar();
208 owner_->updateToolbar();
209 // Similarly, buffer-dependent dialogs should be updated or
210 // hidden. This should go here because some dialogs (eg ToC)
211 // require bv_->text.
212 owner_->getDialogs()->updateBufferDependent(true);
216 lyxerr[Debug::INFO] << " No Buffer!" << endl;
217 owner_->updateMenubar();
218 owner_->updateToolbar();
219 owner_->getDialogs()->hideBufferDependent();
223 // Also remove all remaining text's from the testcache.
224 // (there should not be any!) (if there is any it is a
226 if (lyxerr.debugging())
227 textcache.show(lyxerr, "buffer delete all");
230 // should update layoutchoice even if we don't have a buffer.
231 owner_->updateLayoutChoice();
233 owner_->updateWindowTitle();
237 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
239 workarea_.resize(xpos, ypos, width, height);
240 update(bv_->text, SELECT);
245 void BufferView::Pimpl::resize()
248 resizeCurrentBuffer();
252 void BufferView::Pimpl::redraw()
254 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
259 bool BufferView::Pimpl::fitCursor()
261 lyx::Assert(screen_.get());
265 if (bv_->theLockingInset()) {
266 bv_->theLockingInset()->fitInsetCursor(bv_);
269 ret = screen_->fitCursor(bv_->text, bv_);
272 bv_->owner()->getDialogs()->updateParagraph();
279 void BufferView::Pimpl::redoCurrentBuffer()
281 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
282 if (buffer_ && bv_->text) {
284 owner_->updateLayoutChoice();
289 int BufferView::Pimpl::resizeCurrentBuffer()
291 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
294 Paragraph * selstartpar = 0;
295 Paragraph * selendpar = 0;
296 UpdatableInset * the_locking_inset = 0;
298 Paragraph::size_type pos = 0;
299 Paragraph::size_type selstartpos = 0;
300 Paragraph::size_type selendpos = 0;
301 bool selection = false;
302 bool mark_set = false;
304 owner_->prohibitInput();
306 owner_->message(_("Formatting document..."));
309 par = bv_->text->cursor.par();
310 pos = bv_->text->cursor.pos();
311 selstartpar = bv_->text->selection.start.par();
312 selstartpos = bv_->text->selection.start.pos();
313 selendpar = bv_->text->selection.end.par();
314 selendpos = bv_->text->selection.end.pos();
315 selection = bv_->text->selection.set();
316 mark_set = bv_->text->selection.mark();
317 the_locking_inset = bv_->theLockingInset();
319 bv_->text = new LyXText(bv_);
320 bv_->text->init(bv_);
322 // See if we have a text in TextCache that fits
323 // the new buffer_ with the correct width.
324 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
326 if (lyxerr.debugging()) {
327 lyxerr << "Found a LyXText that fits:\n";
328 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
330 // Set the owner of the newly found text
331 // bv_->text->owner(bv_);
332 if (lyxerr.debugging())
333 textcache.show(lyxerr, "resizeCurrentBuffer");
335 bv_->text = new LyXText(bv_);
336 bv_->text->init(bv_);
342 bv_->text->selection.set(true);
343 /* at this point just to avoid the Delete-Empty-Paragraph
344 * Mechanism when setting the cursor */
345 bv_->text->selection.mark(mark_set);
347 bv_->text->setCursor(bv_, selstartpar, selstartpos);
348 bv_->text->selection.cursor = bv_->text->cursor;
349 bv_->text->setCursor(bv_, selendpar, selendpos);
350 bv_->text->setSelection(bv_);
351 bv_->text->setCursor(bv_, par, pos);
353 bv_->text->setCursor(bv_, par, pos);
354 bv_->text->selection.cursor = bv_->text->cursor;
355 bv_->text->selection.set(false);
357 // remake the inset locking
358 bv_->theLockingInset(the_locking_inset);
360 bv_->text->first = screen_->topCursorVisible(bv_->text);
361 buffer_->resizeInsets(bv_);
362 // this will scroll the screen such that the cursor becomes visible
367 owner_->allowInput();
369 /// clear the "Formatting Document" message
372 /// get rid of the splash screen if it's not gone already
373 owner_->getDialogs()->destroySplash();
379 void BufferView::Pimpl::updateScreen()
381 // Regenerate the screen.
382 screen_.reset(new LyXScreen(workarea_));
386 void BufferView::Pimpl::updateScrollbar()
388 /* If the text is smaller than the working area, the scrollbar
389 * maximum must be the working area height. No scrolling will
392 workarea_.setScrollbar(0, 1.0);
396 long const text_height = bv_->text->height;
398 double const lineh = bv_->text->defaultHeight();
399 double const slider_size =
400 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
402 static long old_text_height = 0;
403 static double old_lineh = 0;
404 static double old_slider_size = 0;
406 if (text_height != old_text_height) {
407 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
408 old_text_height = text_height;
410 if (lineh != old_lineh) {
411 workarea_.setScrollbarIncrements(lineh);
414 if (current_scrollbar_value != bv_->text->first
415 || slider_size != old_slider_size) {
416 current_scrollbar_value = bv_->text->first;
417 workarea_.setScrollbar(current_scrollbar_value, slider_size);
418 old_slider_size = slider_size;
423 // Callback for scrollbar slider
424 void BufferView::Pimpl::scrollCB(double value)
426 if (!buffer_) return;
428 current_scrollbar_value = long(value);
429 if (current_scrollbar_value < 0)
430 current_scrollbar_value = 0;
435 screen_->draw(bv_->text, bv_, current_scrollbar_value);
437 if (!lyxrc.cursor_follows_scrollbar) {
442 LyXText * vbt = bv_->text;
444 int const height = vbt->defaultHeight();
445 int const first = static_cast<int>((bv_->text->first + height));
446 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
448 if (vbt->cursor.y() < first)
449 vbt->setCursorFromCoordinates(bv_, 0, first);
450 else if (vbt->cursor.y() > last)
451 vbt->setCursorFromCoordinates(bv_, 0, last);
457 int BufferView::Pimpl::scrollUp(long time)
459 if (!buffer_) return 0;
460 if (!screen_.get()) return 0;
462 double value = workarea_.getScrollbarValue();
464 if (value == 0) return 0;
466 float add_value = (bv_->text->defaultHeight()
467 + float(time) * float(time) * 0.125);
469 if (add_value > workarea_.height())
470 add_value = float(workarea_.height() -
471 bv_->text->defaultHeight());
478 workarea_.setScrollbarValue(value);
485 int BufferView::Pimpl::scrollDown(long time)
487 if (!buffer_) return 0;
488 if (!screen_.get()) return 0;
490 double value = workarea_.getScrollbarValue();
491 pair<float, float> p = workarea_.getScrollbarBounds();
492 double const max = p.second;
494 if (value == max) return 0;
496 float add_value = (bv_->text->defaultHeight()
497 + float(time) * float(time) * 0.125);
499 if (add_value > workarea_.height())
500 add_value = float(workarea_.height() -
501 bv_->text->defaultHeight());
508 workarea_.setScrollbarValue(value);
515 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
517 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
521 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
523 // Only use motion with button 1
524 if (!(state & Button1MotionMask))
527 if (!buffer_ || !screen_.get()) return;
529 // Check for inset locking
530 if (bv_->theLockingInset()) {
531 LyXCursor cursor = bv_->text->cursor;
532 LyXFont font = bv_->text->getFont(buffer_,
533 cursor.par(), cursor.pos());
534 int width = bv_->theLockingInset()->width(bv_, font);
535 int inset_x = font.isVisibleRightToLeft()
536 ? cursor.x() - width : cursor.x();
537 int start_x = inset_x + bv_->theLockingInset()->scroll();
538 bv_->theLockingInset()->
539 insetMotionNotify(bv_,
541 y - cursor.y() + bv_->text->first,
546 /* The test for not selection possible is needed, that only motion
547 events are used, where the bottom press event was on
548 the drawing area too */
549 if (!selection_possible)
552 screen_->hideCursor();
554 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
556 if (!bv_->text->selection.set())
557 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
559 bv_->text->setSelection(bv_);
560 screen_->toggleToggle(bv_->text, bv_);
563 screen_->showCursor(bv_->text, bv_);
570 // Single-click on work area
571 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
574 if (!buffer_ || !screen_.get()) return;
576 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
578 // ok ok, this is a hack.
579 if (button == 4 || button == 5) {
582 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
585 scrollDown(lyxrc.wheel_jump);
590 if (bv_->theLockingInset()) {
591 // We are in inset locking mode
593 /* Check whether the inset was hit. If not reset mode,
594 otherwise give the event to the inset */
595 if (inset_hit == bv_->theLockingInset()) {
596 bv_->theLockingInset()->
597 insetButtonPress(bv_,
602 bv_->unlockInset(bv_->theLockingInset());
607 selection_possible = true;
608 screen_->hideCursor();
610 int const screen_first = bv_->text->first;
612 // Middle button press pastes if we have a selection
613 bool paste_internally = false;
615 && bv_->text->selection.set()) {
616 owner_->getLyXFunc()->dispatch(LFUN_COPY);
617 paste_internally = true;
620 // Clear the selection
621 screen_->toggleSelection(bv_->text, bv_);
622 bv_->text->clearSelection();
623 bv_->text->fullRebreak(bv_);
625 screen_->update(bv_->text, bv_);
631 // Single left click in math inset?
632 if ((inset_hit != 0) &&
633 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
634 // Highly editable inset, like math
635 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
636 selection_possible = false;
637 owner_->updateLayoutChoice();
638 owner_->message(inset->editMessage());
639 inset->insetButtonPress(bv_, xpos, ypos, button);
640 inset->edit(bv_, xpos, ypos, button);
644 // Right click on a footnote flag opens float menu
646 selection_possible = false;
650 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
651 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
653 bv_->text->selection.cursor = bv_->text->cursor;
654 bv_->text->cursor.x_fix(bv_->text->cursor.x());
656 owner_->updateLayoutChoice();
658 selection_possible = false;
661 // Insert primary selection with middle mouse
662 // if there is a local selection in the current buffer,
665 if (paste_internally)
666 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
668 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
670 selection_possible = false;
676 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
682 LyXText * text = bv_->getLyXText();
684 if (text->bv_owner && bv_->theLockingInset())
687 if (screen_.get() && button == 1) {
688 if (text->bv_owner) {
689 screen_->hideCursor();
690 screen_->toggleSelection(text, bv_);
691 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
692 screen_->toggleSelection(text, bv_, false);
694 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
696 /* This will fit the cursor on the screen
698 update(text, BufferView::SELECT|BufferView::FITCUR);
703 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
709 LyXText * text = bv_->getLyXText();
711 if (text->bv_owner && bv_->theLockingInset())
714 if (screen_.get() && (button == 1)) {
715 screen_->hideCursor();
716 screen_->toggleSelection(text, bv_);
717 text->cursorHome(bv_);
718 text->selection.cursor = text->cursor;
719 text->cursorEnd(bv_);
720 text->setSelection(bv_);
721 screen_->toggleSelection(text, bv_, false);
722 /* This will fit the cursor on the screen
724 update(text, BufferView::SELECT|BufferView::FITCUR);
729 void BufferView::Pimpl::enterView()
731 if (active() && available()) {
732 SetXtermCursor(workarea_.getWin());
733 using_xterm_cursor = true;
738 void BufferView::Pimpl::leaveView()
740 if (using_xterm_cursor) {
741 XUndefineCursor(fl_get_display(), workarea_.getWin());
742 using_xterm_cursor = false;
747 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
750 if (!buffer_ || !screen_.get()) return;
752 // If we hit an inset, we have the inset coordinates in these
753 // and inset_hit points to the inset. If we do not hit an
754 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
755 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
757 if (bv_->theLockingInset()) {
758 // We are in inset locking mode.
760 /* LyX does a kind of work-area grabbing for insets.
761 Only a ButtonPress Event outside the inset will
762 force a insetUnlock. */
763 bv_->theLockingInset()->
764 insetButtonRelease(bv_, x, y, button);
768 selection_possible = false;
776 // Did we hit an editable inset?
778 // Inset like error, notes and figures
779 selection_possible = false;
781 // CHECK fix this proper in 0.13
783 // Following a ref shouldn't issue
784 // a push on the undo-stack
785 // anylonger, now that we have
786 // keybindings for following
787 // references and returning from
788 // references. IMHO though, it
789 // should be the inset's own business
790 // to push or not push on the undo
791 // stack. They don't *have* to
792 // alter the document...
794 // ...or maybe the SetCursorParUndo()
795 // below isn't necessary at all anylonger?
796 if (inset_hit->lyxCode() == Inset::REF_CODE) {
797 setCursorParUndo(bv_);
800 owner_->message(inset_hit->editMessage());
802 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
803 // Highly editable inset, like math
804 UpdatableInset *inset = (UpdatableInset *)inset_hit;
805 inset->insetButtonRelease(bv_, x, y, button);
807 inset_hit->insetButtonRelease(bv_, x, y, button);
808 inset_hit->edit(bv_, x, y, button);
813 // check whether we want to open a float
817 if (bv_->text->cursor.pos() <
818 bv_->text->cursor.par()->size()) {
819 c = bv_->text->cursor.par()->
820 getChar(bv_->text->cursor.pos());
822 if (bv_->text->cursor.pos() - 1 >= 0) {
823 c = bv_->text->cursor.par()->
824 getChar(bv_->text->cursor.pos() - 1);
827 selection_possible = false;
832 // Maybe we want to edit a bibitem ale970302
833 if (bv_->text->cursor.par()->bibkey && x < 20 +
834 bibitemMaxWidth(bv_, textclasslist.
836 params.textclass).defaultfont())) {
837 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
845 * Returns an inset if inset was hit. 0 otherwise.
846 * If hit, the coordinates are changed relative to the inset.
847 * Otherwise coordinates are not changed, and false is returned.
849 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
850 unsigned int /* button */)
855 int y_tmp = y + text->first;
858 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
859 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
862 if (cursor.pos() < cursor.par()->size()
863 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
864 && cursor.par()->getInset(cursor.pos())
865 && cursor.par()->getInset(cursor.pos())->editable()) {
867 // Check whether the inset really was hit
868 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
869 LyXFont font = text->getFont(buffer_,
870 cursor.par(), cursor.pos());
871 int const width = tmpinset->width(bv_, font);
872 int const inset_x = font.isVisibleRightToLeft()
873 ? cursor.x() - width : cursor.x();
874 int const start_x = inset_x + tmpinset->scroll();
875 int const end_x = inset_x + width;
877 if (x > start_x && x < end_x
878 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
879 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
880 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
882 // The origin of an inset is on the baseline
883 y = y_tmp - (text->cursor.y());
888 if ((cursor.pos() - 1 >= 0) &&
889 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
890 (cursor.par()->getInset(cursor.pos() - 1)) &&
891 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
892 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
893 LyXFont font = text->getFont(buffer_, cursor.par(),
895 int const width = tmpinset->width(bv_, font);
896 int const inset_x = font.isVisibleRightToLeft()
897 ? cursor.x() : cursor.x() - width;
898 int const start_x = inset_x + tmpinset->scroll();
899 int const end_x = inset_x + width;
901 if (x > start_x && x < end_x
902 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
903 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
905 if (move_cursor && (tmpinset != bv_->theLockingInset()))
907 text->setCursor(bv_, cursor.par(),
908 cursor.pos() - 1, true);
910 // The origin of an inset is on the baseline
911 y = y_tmp - (text->cursor.y());
919 void BufferView::Pimpl::workAreaExpose()
921 static int work_area_width;
922 static unsigned int work_area_height;
924 bool const widthChange = workarea_.workWidth() != work_area_width;
925 bool const heightChange = workarea_.height() != work_area_height;
927 // update from work area
928 work_area_width = workarea_.workWidth();
929 work_area_height = workarea_.height();
932 // The visible LyXView need a resize
935 // Remove all texts from the textcache
936 // This is not _really_ what we want to do. What
937 // we really want to do is to delete in textcache
938 // that does not have a BufferView with matching
939 // width, but as long as we have only one BufferView
940 // deleting all gives the same result.
941 if (lyxerr.debugging())
942 textcache.show(lyxerr, "Expose delete all");
944 } else if (heightChange) {
945 // Rebuild image of current screen
947 // fitCursor() ensures we don't jump back
948 // to the start of the document on vertical
952 // The main window size has changed, repaint most stuff
954 } else if (screen_.get())
955 screen_->redraw(bv_->text, bv_);
957 // Grey box when we don't have a buffer
961 // always make sure that the scrollbar is sane.
963 owner_->updateLayoutChoice();
968 void BufferView::Pimpl::update()
971 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
973 LyXText::text_status st = bv_->text->status();
974 screen_->update(bv_->text, bv_);
975 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
976 if (bv_->text->fullRebreak(bv_)) {
977 st = LyXText::NEED_MORE_REFRESH;
978 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
979 bv_->text->cursor.pos());
982 bv_->text->status(bv_, st);
983 screen_->update(bv_->text, bv_);
988 // Values used when calling update:
990 // -2 - update, move sel_cursor if selection, fitcursor
991 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
992 // 0 - update, move sel_cursor if selection, fitcursor
993 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
994 // 3 - update, move sel_cursor if selection
997 // a simple redraw of the parts that need refresh
999 // move sel_cursor if selection -
1000 // the text's sel_cursor is moved if there is selection is progress
1003 // fitCursor() is called and the scrollbar updated
1006 // the buffer is marked dirty.
1015 // UPDATE_ONLY = UPDATE;
1016 // UPDATE_SELECT = UPDATE | SELECT;
1017 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1018 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1020 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1021 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1022 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1023 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1024 // update(3) -> update(1) -> update(1) -> update(SELECT)
1026 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1028 owner_->updateLayoutChoice();
1030 if (!text->selection.set() && (f & SELECT)) {
1031 text->selection.cursor = text->cursor;
1034 text->fullRebreak(bv_);
1036 if (text->inset_owner) {
1037 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1038 updateInset(text->inset_owner, true);
1048 buffer_->markDirty();
1053 // Callback for cursor timer
1054 void BufferView::Pimpl::cursorToggle()
1056 // Quite a nice place for asyncron Inset updating, isn't it?
1057 // Actually no! This is run even if no buffer exist... so (Lgb)
1059 cursor_timeout.restart();
1064 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1065 if (pid == -1) // error find out what is wrong
1066 ; // ignore it for now.
1068 sigchldchecker(pid, &status);
1070 updatelist.update(bv_);
1072 if (!screen_.get()) {
1073 cursor_timeout.restart();
1077 if (!bv_->theLockingInset()) {
1078 screen_->cursorToggle(bv_);
1080 bv_->theLockingInset()->toggleInsetCursor(bv_);
1083 cursor_timeout.restart();
1087 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1089 if (!text->cursor.row()->previous())
1092 int y = text->first;
1093 if (text->inset_owner)
1094 y += bv_->text->first;
1095 Row * cursorrow = text->cursor.row();
1096 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1098 // This is to allow jumping over large insets
1099 if ((cursorrow == text->cursor.row()))
1100 text->cursorUp(bv_);
1102 if (text->inset_owner ||
1103 text->cursor.row()->height() < workarea_.height())
1104 screen_->draw(bv_->text, bv_,
1106 - text->cursor.row()->baseline()
1107 + text->cursor.row()->height()
1108 - workarea_.height() + 1 );
1113 void BufferView::Pimpl::cursorNext(LyXText * text)
1115 if (!text->cursor.row()->next())
1118 int y = text->first + workarea_.height();
1119 // if (text->inset_owner)
1120 // y += bv_->text->first;
1121 text->getRowNearY(y);
1123 Row * cursorrow = text->cursor.row();
1124 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1126 // This is to allow jumping over large insets
1127 if ((cursorrow == bv_->text->cursor.row()))
1128 text->cursorDown(bv_);
1130 if (text->inset_owner ||
1131 text->cursor.row()->height() < workarea_.height())
1132 screen_->draw(bv_->text, bv_, text->cursor.y() -
1133 text->cursor.row()->baseline());
1138 bool BufferView::Pimpl::available() const
1140 if (buffer_ && bv_->text) return true;
1145 void BufferView::Pimpl::beforeChange(LyXText * text)
1148 text->clearSelection();
1152 void BufferView::Pimpl::savePosition(unsigned int i)
1154 if (i >= saved_positions_num)
1156 saved_positions[i] = Position(buffer_->fileName(),
1157 bv_->text->cursor.par()->id(),
1158 bv_->text->cursor.pos());
1161 str << _("Saved bookmark") << ' ' << i;
1162 owner_->message(str.str().c_str());
1167 void BufferView::Pimpl::restorePosition(unsigned int i)
1169 if (i >= saved_positions_num)
1172 string const fname = saved_positions[i].filename;
1174 beforeChange(bv_->text);
1176 if (fname != buffer_->fileName()) {
1177 Buffer * b = bufferlist.exists(fname) ?
1178 bufferlist.getBuffer(fname) :
1179 bufferlist.loadLyXFile(fname); // don't ask, just load it
1180 if (b != 0 ) buffer(b);
1183 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1187 bv_->text->setCursor(bv_, par,
1188 min(par->size(), saved_positions[i].par_pos));
1190 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1193 str << _("Moved to bookmark") << ' ' << i;
1194 owner_->message(str.str().c_str());
1199 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1201 if (i >= saved_positions_num)
1204 return !saved_positions[i].filename.empty();
1208 void BufferView::Pimpl::setState()
1210 if (!lyxrc.rtl_support)
1213 LyXText * text = bv_->getLyXText();
1214 if (text->real_current_font.isRightToLeft()
1217 text->real_current_font.latex() != LyXFont::ON
1220 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1221 owner_->getIntl()->KeyMapSec();
1223 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1224 owner_->getIntl()->KeyMapPrim();
1229 void BufferView::Pimpl::insetSleep()
1231 if (bv_->theLockingInset() && !inset_slept) {
1232 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1233 bv_->theLockingInset()->insetUnlock(bv_);
1239 void BufferView::Pimpl::insetWakeup()
1241 if (bv_->theLockingInset() && inset_slept) {
1242 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1243 inset_slept = false;
1248 void BufferView::Pimpl::insetUnlock()
1250 if (bv_->theLockingInset()) {
1252 bv_->theLockingInset()->insetUnlock(bv_);
1253 bv_->theLockingInset(0);
1255 inset_slept = false;
1260 bool BufferView::Pimpl::focus() const
1262 return workarea_.hasFocus();
1266 void BufferView::Pimpl::focus(bool f)
1268 if (f) workarea_.setFocus();
1272 bool BufferView::Pimpl::active() const
1274 return workarea_.active();
1278 bool BufferView::Pimpl::belowMouse() const
1280 return workarea_.belowMouse();
1284 void BufferView::Pimpl::showCursor()
1286 if (screen_.get()) {
1287 if (bv_->theLockingInset())
1288 bv_->theLockingInset()->showInsetCursor(bv_);
1290 screen_->showCursor(bv_->text, bv_);
1295 void BufferView::Pimpl::hideCursor()
1297 if (screen_.get()) {
1298 if (!bv_->theLockingInset())
1299 // bv_->theLockingInset()->hideInsetCursor(bv_);
1301 screen_->hideCursor();
1306 void BufferView::Pimpl::toggleSelection(bool b)
1308 if (screen_.get()) {
1309 if (bv_->theLockingInset())
1310 bv_->theLockingInset()->toggleSelection(bv_, b);
1311 screen_->toggleSelection(bv_->text, bv_, b);
1316 void BufferView::Pimpl::toggleToggle()
1319 screen_->toggleToggle(bv_->text, bv_);
1323 void BufferView::Pimpl::center()
1325 beforeChange(bv_->text);
1326 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1327 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1329 screen_->draw(bv_->text, bv_, 0);
1331 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1336 void BufferView::Pimpl::pasteClipboard(bool asPara)
1338 if (!buffer_) return;
1340 screen_->hideCursor();
1341 beforeChange(bv_->text);
1343 string const clip(workarea_.getClipboard());
1345 if (clip.empty()) return;
1348 bv_->text->insertStringAsParagraphs(bv_, clip);
1350 bv_->text->insertStringAsLines(bv_, clip);
1352 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1356 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1358 workarea_.putClipboard(stuff);
1363 * Dispatch functions for actions which can be valid for BufferView->text
1364 * and/or InsetText->text!!!
1369 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1371 LyXText * lt = bv_->getLyXText();
1373 if (selecting || lt->selection.mark()) {
1374 lt->setSelection(bv_);
1378 update(lt, BufferView::SELECT|BufferView::FITCUR);
1381 /* ---> Everytime the cursor is moved, show the current font state. */
1382 // should this too me moved out of this func?
1383 //owner->showState();
1388 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1390 LyXCursor cursor = bv_->getLyXText()->cursor;
1391 Buffer::inset_iterator it =
1392 find_if(Buffer::inset_iterator(
1393 cursor.par(), cursor.pos()),
1394 buffer_->inset_iterator_end(),
1395 lyx::compare_memfun(&Inset::lyxCode, code));
1396 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1400 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1402 string filename = filen;
1404 if (filename.empty()) {
1405 // Launch a file browser
1406 string initpath = lyxrc.document_path;
1409 string const trypath = owner_->buffer()->filepath;
1410 // If directory is writeable, use this as default.
1411 if (IsDirWriteable(trypath))
1415 FileDialog fileDlg(bv_->owner(),
1416 _("Select LyX document to insert"),
1418 make_pair(string(_("Documents")),
1419 string(lyxrc.document_path)),
1420 make_pair(string(_("Examples")),
1421 string(AddPath(system_lyxdir, "examples"))));
1423 FileDialog::Result result =
1424 fileDlg.Select(initpath,
1425 _("*.lyx| LyX Documents (*.lyx)"));
1427 if (result.first == FileDialog::Later)
1430 filename = result.second;
1432 // check selected filename
1433 if (filename.empty()) {
1434 owner_->message(_("Canceled."));
1439 // get absolute path of file and add ".lyx" to the filename if
1441 filename = FileSearch(string(), filename, "lyx");
1443 string const disp_fn(MakeDisplayPath(filename));
1446 s1 << _("Inserting document") << ' '
1447 << disp_fn << " ...";
1448 owner_->message(s1.str().c_str());
1449 bool const res = bv_->insertLyXFile(filename);
1452 str << _("Document") << ' ' << disp_fn
1453 << ' ' << _("inserted.");
1454 owner_->message(str.str().c_str());
1457 str << _("Could not insert document") << ' '
1459 owner_->message(str.str().c_str());
1464 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1466 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1467 << action <<"] arg[" << argument << "]" << endl;
1470 // --- Misc -------------------------------------------
1474 LyXText * lt = bv_->getLyXText();
1475 lt->toggleAppendix(bv_);
1478 | BufferView::FITCUR
1479 | BufferView::CHANGE);
1484 case LFUN_TOC_INSERT:
1486 InsetCommandParams p;
1487 p.setCmdName("tableofcontents");
1488 Inset * inset = new InsetTOC(p);
1489 if (!insertInset(inset, "Standard"))
1494 case LFUN_TABULAR_FEATURE:
1495 case LFUN_SCROLL_INSET:
1496 // this is not handled here as this funktion is only aktive
1497 // if we have a locking_inset and that one is (or contains)
1501 case LFUN_INSET_GRAPHICS:
1503 Inset * new_inset = new InsetGraphics;
1504 if (!insertInset(new_inset)) {
1507 // this is need because you don't use a inset->Edit()
1508 updateInset(new_inset, true);
1509 new_inset->edit(bv_);
1519 case LFUN_PASTESELECTION:
1521 bool asPara = false;
1522 if (argument == "paragraph") asPara = true;
1523 pasteClipboard(asPara);
1535 case LFUN_LAYOUT_COPY:
1536 bv_->copyEnvironment();
1539 case LFUN_LAYOUT_PASTE:
1540 bv_->pasteEnvironment();
1544 case LFUN_GOTOERROR:
1545 gotoInset(Inset::ERROR_CODE, false);
1549 gotoInset(Inset::IGNORE_CODE, false);
1552 case LFUN_REFERENCE_GOTO:
1554 vector<Inset::Code> tmp;
1555 tmp.push_back(Inset::LABEL_CODE);
1556 tmp.push_back(Inset::REF_CODE);
1557 gotoInset(tmp, true);
1561 case LFUN_HYPHENATION:
1562 specialChar(InsetSpecialChar::HYPHENATION);
1565 case LFUN_LIGATURE_BREAK:
1566 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1570 specialChar(InsetSpecialChar::LDOTS);
1573 case LFUN_END_OF_SENTENCE:
1574 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1577 case LFUN_MENU_SEPARATOR:
1578 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1586 changeDepth(bv_, bv_->getLyXText(), 0);
1589 case LFUN_DEPTH_MIN:
1590 changeDepth(bv_, bv_->getLyXText(), -1);
1593 case LFUN_DEPTH_PLUS:
1594 changeDepth(bv_, bv_->getLyXText(), 1);
1598 owner_->getDialogs()->setUserFreeFont();
1605 owner_->showState();
1609 case LFUN_FILE_INSERT:
1611 MenuInsertLyXFile(argument);
1615 case LFUN_FILE_INSERT_ASCII_PARA:
1616 InsertAsciiFile(bv_, argument, true);
1619 case LFUN_FILE_INSERT_ASCII:
1620 InsertAsciiFile(bv_, argument, false);
1625 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1626 << argument << endl;
1628 // Derive layout number from given argument (string)
1629 // and current buffer's textclass (number). */
1630 LyXTextClassList::ClassList::size_type tclass =
1631 buffer_->params.textclass;
1632 pair <bool, LyXTextClass::size_type> layout =
1633 textclasslist.NumberOfLayout(tclass, argument);
1635 // If the entry is obsolete, use the new one instead.
1637 string obs = textclasslist.Style(tclass,layout.second)
1641 textclasslist.NumberOfLayout(tclass, obs);
1644 // see if we found the layout number:
1645 if (!layout.first) {
1646 owner_->getLyXFunc()->setErrorMessage(
1647 string(N_("Layout ")) + argument +
1652 if (current_layout != layout.second) {
1653 LyXText * lt = bv_->getLyXText();
1655 current_layout = layout.second;
1658 | BufferView::FITCUR);
1659 lt->setLayout(bv_, layout.second);
1660 owner_->setLayout(layout.second);
1663 | BufferView::FITCUR
1664 | BufferView::CHANGE);
1671 Lang(bv_, argument);
1673 owner_->showState();
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1698 owner_->showState();
1703 owner_->showState();
1708 owner_->showState();
1711 case LFUN_UNDERLINE:
1713 owner_->showState();
1716 case LFUN_FONT_SIZE:
1717 FontSize(bv_, argument);
1718 owner_->showState();
1721 case LFUN_FONT_STATE:
1722 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1725 case LFUN_UPCASE_WORD:
1727 LyXText * lt = bv_->getLyXText();
1731 | BufferView::FITCUR);
1732 lt->changeCase(bv_, LyXText::text_uppercase);
1733 if (lt->inset_owner)
1734 updateInset(lt->inset_owner, true);
1737 | BufferView::FITCUR
1738 | BufferView::CHANGE);
1742 case LFUN_LOWCASE_WORD:
1744 LyXText * lt = bv_->getLyXText();
1746 update(lt, BufferView::SELECT|BufferView::FITCUR);
1747 lt->changeCase(bv_, LyXText::text_lowercase);
1748 if (lt->inset_owner)
1749 updateInset(lt->inset_owner, true);
1752 | BufferView::FITCUR
1753 | BufferView::CHANGE);
1757 case LFUN_CAPITALIZE_WORD:
1759 LyXText * lt = bv_->getLyXText();
1761 update(lt, BufferView::SELECT|BufferView::FITCUR);
1762 lt->changeCase(bv_, LyXText::text_capitalization);
1763 if (lt->inset_owner)
1764 updateInset(lt->inset_owner, true);
1767 | BufferView::FITCUR
1768 | BufferView::CHANGE);
1772 case LFUN_TRANSPOSE_CHARS:
1774 LyXText * lt = bv_->getLyXText();
1776 update(lt, BufferView::SELECT|BufferView::FITCUR);
1777 lt->transposeChars(*bv_);
1778 if (lt->inset_owner)
1779 updateInset(lt->inset_owner, true);
1782 | BufferView::FITCUR
1783 | BufferView::CHANGE);
1788 case LFUN_INSERT_LABEL:
1789 MenuInsertLabel(bv_, argument);
1792 case LFUN_REF_INSERT:
1793 if (argument.empty()) {
1794 InsetCommandParams p("ref");
1795 owner_->getDialogs()->createRef(p.getAsString());
1797 InsetCommandParams p;
1798 p.setFromString(argument);
1800 InsetRef * inset = new InsetRef(p, *buffer_);
1801 if (!insertInset(inset))
1804 updateInset(inset, true);
1808 case LFUN_BOOKMARK_SAVE:
1809 savePosition(strToUnsignedInt(argument));
1812 case LFUN_BOOKMARK_GOTO:
1813 restorePosition(strToUnsignedInt(argument));
1818 string label(argument);
1819 if (label.empty()) {
1821 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1823 label = inset->getContents();
1828 if (!label.empty()) {
1829 //bv_->savePosition(0);
1830 if (!bv_->gotoLabel(label))
1831 WriteAlert(_("Error"),
1832 _("Couldn't find this label"),
1833 _("in current document."));
1838 // --- Cursor Movements -----------------------------
1841 LyXText * lt = bv_->getLyXText();
1843 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1844 if (!lt->selection.mark())
1846 update(lt, BufferView::SELECT|BufferView::FITCUR);
1848 lt->cursorLeft(bv_, false);
1849 if (lt->cursor.pos() < lt->cursor.par()->size()
1850 && lt->cursor.par()->getChar(lt->cursor.pos())
1851 == Paragraph::META_INSET
1852 && lt->cursor.par()->getInset(lt->cursor.pos())
1853 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1854 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1855 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1857 tmpinset->edit(bv_, false);
1859 tmpinset->edit(bv_);
1863 lt->cursorRight(bv_, false);
1865 moveCursorUpdate(false);
1866 owner_->showState();
1872 // This is soooo ugly. Isn`t it possible to make
1873 // it simpler? (Lgb)
1874 LyXText * lt = bv_->getLyXText();
1875 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1876 if (!lt->selection.mark())
1878 update(lt, BufferView::SELECT|BufferView::FITCUR);
1879 LyXCursor const cur = lt->cursor;
1881 lt->cursorLeft(bv_, false);
1882 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1883 lt->cursor.pos() < lt->cursor.par()->size() &&
1884 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1885 Paragraph::META_INSET) &&
1886 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1887 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1888 == Inset::HIGHLY_EDITABLE))
1890 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1891 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1893 tmpinset->edit(bv_);
1895 tmpinset->edit(bv_, false);
1899 lt->cursorRight(bv_, false);
1902 moveCursorUpdate(false);
1903 owner_->showState();
1909 LyXText * lt = bv_->getLyXText();
1911 if (!lt->selection.mark())
1913 update(lt, BufferView::UPDATE);
1916 moveCursorUpdate(false);
1917 owner_->showState();
1923 LyXText * lt = bv_->getLyXText();
1925 if (!lt->selection.mark())
1927 update(lt, BufferView::UPDATE);
1928 lt->cursorDown(bv_);
1930 moveCursorUpdate(false);
1931 owner_->showState();
1935 case LFUN_UP_PARAGRAPH:
1937 LyXText * lt = bv_->getLyXText();
1939 if (!lt->selection.mark())
1941 update(lt, BufferView::UPDATE);
1942 lt->cursorUpParagraph(bv_);
1944 moveCursorUpdate(false);
1945 owner_->showState();
1949 case LFUN_DOWN_PARAGRAPH:
1951 LyXText * lt = bv_->getLyXText();
1953 if (!lt->selection.mark())
1955 update(lt, BufferView::UPDATE);
1956 lt->cursorDownParagraph(bv_);
1958 moveCursorUpdate(false);
1959 owner_->showState();
1965 LyXText * lt = bv_->getLyXText();
1967 if (!lt->selection.mark())
1969 update(lt, BufferView::UPDATE);
1972 moveCursorUpdate(false);
1973 owner_->showState();
1979 LyXText * lt = bv_->getLyXText();
1981 if (!lt->selection.mark())
1983 update(lt, BufferView::UPDATE);
1986 moveCursorUpdate(false);
1987 owner_->showState();
1993 LyXText * lt = bv_->getLyXText();
1995 if (!lt->selection.mark())
1997 update(lt, BufferView::SELECT|BufferView::FITCUR);
1998 lt->cursorHome(bv_);
2000 moveCursorUpdate(false);
2001 owner_->showState();
2007 LyXText * lt = bv_->getLyXText();
2009 if (!lt->selection.mark())
2012 BufferView::SELECT|BufferView::FITCUR);
2015 moveCursorUpdate(false);
2016 owner_->showState();
2020 case LFUN_SHIFT_TAB:
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2028 BufferView::SELECT|BufferView::FITCUR);
2031 moveCursorUpdate(false);
2032 owner_->showState();
2036 case LFUN_WORDRIGHT:
2038 LyXText * lt = bv_->getLyXText();
2040 if (!lt->selection.mark())
2042 update(lt, BufferView::SELECT|BufferView::FITCUR);
2043 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2044 lt->cursorLeftOneWord(bv_);
2046 lt->cursorRightOneWord(bv_);
2048 moveCursorUpdate(false);
2049 owner_->showState();
2055 LyXText * lt = bv_->getLyXText();
2057 if (!lt->selection.mark())
2059 update(lt, BufferView::SELECT|BufferView::FITCUR);
2060 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2061 lt->cursorRightOneWord(bv_);
2063 lt->cursorLeftOneWord(bv_);
2065 moveCursorUpdate(false);
2066 owner_->showState();
2070 case LFUN_BEGINNINGBUF:
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2077 BufferView::SELECT|BufferView::FITCUR);
2080 moveCursorUpdate(false);
2081 owner_->showState();
2087 LyXText * lt = bv_->getLyXText();
2089 if (!lt->selection.mark())
2092 BufferView::SELECT|BufferView::FITCUR);
2093 lt->cursorBottom(bv_);
2095 moveCursorUpdate(false);
2096 owner_->showState();
2100 /* cursor selection ---------------------------- */
2103 LyXText * lt = bv_->getLyXText();
2106 BufferView::SELECT|BufferView::FITCUR);
2107 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2108 lt->cursorLeft(bv_);
2110 lt->cursorRight(bv_);
2112 moveCursorUpdate(true);
2113 owner_->showState();
2119 LyXText * lt = bv_->getLyXText();
2122 BufferView::SELECT|BufferView::FITCUR);
2123 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2124 lt->cursorRight(bv_);
2126 lt->cursorLeft(bv_);
2128 moveCursorUpdate(true);
2129 owner_->showState();
2135 LyXText * lt = bv_->getLyXText();
2138 BufferView::SELECT|BufferView::FITCUR);
2141 moveCursorUpdate(true);
2142 owner_->showState();
2148 LyXText * lt = bv_->getLyXText();
2151 BufferView::SELECT|BufferView::FITCUR);
2152 lt->cursorDown(bv_);
2154 moveCursorUpdate(true);
2155 owner_->showState();
2159 case LFUN_UP_PARAGRAPHSEL:
2161 LyXText * lt = bv_->getLyXText();
2164 BufferView::SELECT|BufferView::FITCUR);
2165 lt->cursorUpParagraph(bv_);
2167 moveCursorUpdate(true);
2168 owner_->showState();
2172 case LFUN_DOWN_PARAGRAPHSEL:
2174 LyXText * lt = bv_->getLyXText();
2177 BufferView::SELECT|BufferView::FITCUR);
2178 lt->cursorDownParagraph(bv_);
2180 moveCursorUpdate(true);
2181 owner_->showState();
2187 LyXText * lt = bv_->getLyXText();
2189 update(lt, BufferView::SELECT|BufferView::FITCUR);
2192 moveCursorUpdate(true);
2193 owner_->showState();
2199 LyXText * lt = bv_->getLyXText();
2201 update(lt, BufferView::SELECT|BufferView::FITCUR);
2204 moveCursorUpdate(true);
2205 owner_->showState();
2211 LyXText * lt = bv_->getLyXText();
2213 update(lt, BufferView::SELECT|BufferView::FITCUR);
2214 lt->cursorHome(bv_);
2216 moveCursorUpdate(true);
2217 owner_->showState();
2223 LyXText * lt = bv_->getLyXText();
2225 update(lt, BufferView::SELECT|BufferView::FITCUR);
2228 moveCursorUpdate(true);
2229 owner_->showState();
2233 case LFUN_WORDRIGHTSEL:
2235 LyXText * lt = bv_->getLyXText();
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2238 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2239 lt->cursorLeftOneWord(bv_);
2241 lt->cursorRightOneWord(bv_);
2243 moveCursorUpdate(true);
2244 owner_->showState();
2248 case LFUN_WORDLEFTSEL:
2250 LyXText * lt = bv_->getLyXText();
2252 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2254 lt->cursorRightOneWord(bv_);
2256 lt->cursorLeftOneWord(bv_);
2258 moveCursorUpdate(true);
2259 owner_->showState();
2263 case LFUN_BEGINNINGBUFSEL:
2265 LyXText * lt = bv_->getLyXText();
2267 if (lt->inset_owner)
2269 update(lt, BufferView::SELECT|BufferView::FITCUR);
2272 moveCursorUpdate(true);
2273 owner_->showState();
2277 case LFUN_ENDBUFSEL:
2279 LyXText * lt = bv_->getLyXText();
2281 if (lt->inset_owner)
2284 BufferView::SELECT|BufferView::FITCUR);
2285 lt->cursorBottom(bv_);
2287 moveCursorUpdate(true);
2288 owner_->showState();
2292 // --- text changing commands ------------------------
2293 case LFUN_BREAKLINE:
2295 LyXText * lt = bv_->getLyXText();
2298 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2301 | BufferView::FITCUR
2302 | BufferView::CHANGE);
2303 moveCursorUpdate(false);
2307 case LFUN_PROTECTEDSPACE:
2309 LyXText * lt = bv_->getLyXText();
2311 LyXLayout const & style = textclasslist
2312 .Style(buffer_->params.textclass,
2313 lt->cursor.par()->getLayout());
2315 if (style.free_spacing) {
2316 lt->insertChar(bv_, ' ');
2319 | BufferView::FITCUR
2320 | BufferView::CHANGE);
2324 moveCursorUpdate(false);
2330 LyXText * lt = bv_->getLyXText();
2332 if (lt->selection.mark()) {
2336 | BufferView::FITCUR);
2337 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2340 lt->selection.mark(true);
2343 | BufferView::FITCUR);
2344 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2346 lt->selection.cursor = lt->cursor;
2352 LyXText * lt = bv_->getLyXText();
2354 if (!lt->selection.set()) {
2356 lt->selection.cursor = lt->cursor;
2359 | BufferView::FITCUR
2360 | BufferView::CHANGE);
2361 // It is possible to make it a lot faster still
2362 // just comment out the line below...
2367 moveCursorUpdate(false);
2368 owner_->showState();
2373 case LFUN_DELETE_SKIP:
2375 LyXText * lt = bv_->getLyXText();
2377 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2379 LyXCursor cursor = lt->cursor;
2381 if (!lt->selection.set()) {
2382 if (cursor.pos() == cursor.par()->size()) {
2383 lt->cursorRight(bv_);
2384 cursor = lt->cursor;
2385 if (cursor.pos() == 0
2386 && !(cursor.par()->params().spaceTop()
2387 == VSpace (VSpace::NONE))) {
2390 cursor.par()->params().lineTop(),
2391 cursor.par()->params().lineBottom(),
2392 cursor.par()->params().pagebreakTop(),
2393 cursor.par()->params().pagebreakBottom(),
2394 VSpace(VSpace::NONE),
2395 cursor.par()->params().spaceBottom(),
2396 cursor.par()->params().align(),
2397 cursor.par()->params().labelWidthString(), 0);
2398 lt->cursorLeft(bv_);
2401 | BufferView::FITCUR
2402 | BufferView::CHANGE);
2404 lt->cursorLeft(bv_);
2406 lt->selection.cursor = lt->cursor;
2409 | BufferView::FITCUR
2410 | BufferView::CHANGE);
2414 lt->selection.cursor = lt->cursor;
2417 | BufferView::FITCUR
2418 | BufferView::CHANGE);
2426 /* -------> Delete word forward. */
2427 case LFUN_DELETE_WORD_FORWARD:
2428 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2429 bv_->getLyXText()->deleteWordForward(bv_);
2430 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2431 moveCursorUpdate(false);
2432 owner_->showState();
2435 /* -------> Delete word backward. */
2436 case LFUN_DELETE_WORD_BACKWARD:
2438 LyXText * lt = bv_->getLyXText();
2440 update(lt, BufferView::SELECT|BufferView::FITCUR);
2441 lt->deleteWordBackward(bv_);
2444 | BufferView::FITCUR
2445 | BufferView::CHANGE);
2446 moveCursorUpdate(false);
2447 owner_->showState();
2451 /* -------> Kill to end of line. */
2452 case LFUN_DELETE_LINE_FORWARD:
2454 LyXText * lt = bv_->getLyXText();
2456 update(lt, BufferView::SELECT|BufferView::FITCUR);
2457 lt->deleteLineForward(bv_);
2460 | BufferView::FITCUR
2461 | BufferView::CHANGE);
2462 moveCursorUpdate(false);
2466 /* -------> Set mark off. */
2469 LyXText * lt = bv_->getLyXText();
2472 update(lt, BufferView::SELECT|BufferView::FITCUR);
2473 lt->selection.cursor = lt->cursor;
2474 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2478 /* -------> Set mark on. */
2481 LyXText * lt = bv_->getLyXText();
2484 lt->selection.mark(true);
2485 update(lt, BufferView::SELECT|BufferView::FITCUR);
2486 lt->selection.cursor = lt->cursor;
2487 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2491 case LFUN_BACKSPACE:
2493 LyXText * lt = bv_->getLyXText();
2495 if (!lt->selection.set()) {
2496 if (owner_->getIntl()->getTrans().backspace()) {
2498 lt->selection.cursor = lt->cursor;
2501 | BufferView::FITCUR
2502 | BufferView::CHANGE);
2503 // It is possible to make it a lot faster still
2504 // just comment out the line below...
2510 owner_->showState();
2515 case LFUN_BACKSPACE_SKIP:
2517 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2518 LyXText * lt = bv_->getLyXText();
2520 LyXCursor cursor = lt->cursor;
2522 if (!lt->selection.set()) {
2523 if (cursor.pos() == 0
2524 && !(cursor.par()->params().spaceTop()
2525 == VSpace (VSpace::NONE))) {
2528 cursor.par()->params().lineTop(),
2529 cursor.par()->params().lineBottom(),
2530 cursor.par()->params().pagebreakTop(),
2531 cursor.par()->params().pagebreakBottom(),
2532 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2533 cursor.par()->params().align(),
2534 cursor.par()->params().labelWidthString(), 0);
2537 | BufferView::FITCUR
2538 | BufferView::CHANGE);
2541 lt->selection.cursor = cursor;
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2552 case LFUN_BREAKPARAGRAPH:
2554 LyXText * lt = bv_->getLyXText();
2557 lt->breakParagraph(bv_, 0);
2560 | BufferView::FITCUR
2561 | BufferView::CHANGE);
2562 lt->selection.cursor = lt->cursor;
2564 owner_->showState();
2568 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2570 LyXText * lt = bv_->getLyXText();
2573 lt->breakParagraph(bv_, 1);
2576 | BufferView::FITCUR
2577 | BufferView::CHANGE);
2578 lt->selection.cursor = lt->cursor;
2580 owner_->showState();
2584 case LFUN_BREAKPARAGRAPH_SKIP:
2586 // When at the beginning of a paragraph, remove
2587 // indentation and add a "defskip" at the top.
2588 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2589 LyXText * lt = bv_->getLyXText();
2591 LyXCursor cursor = lt->cursor;
2594 if (cursor.pos() == 0) {
2595 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2598 cursor.par()->params().lineTop(),
2599 cursor.par()->params().lineBottom(),
2600 cursor.par()->params().pagebreakTop(),
2601 cursor.par()->params().pagebreakBottom(),
2602 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2603 cursor.par()->params().align(),
2604 cursor.par()->params().labelWidthString(), 1);
2605 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2609 lt->breakParagraph(bv_, 0);
2610 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2615 | BufferView::FITCUR
2616 | BufferView::CHANGE);
2617 lt->selection.cursor = cursor;
2619 owner_->showState();
2623 case LFUN_PARAGRAPH_SPACING:
2625 LyXText * lt = bv_->getLyXText();
2627 Paragraph * par = lt->cursor.par();
2628 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2629 float cur_value = 1.0;
2630 if (cur_spacing == Spacing::Other) {
2631 cur_value = par->params().spacing().getValue();
2634 istringstream istr(argument.c_str());
2638 Spacing::Space new_spacing = cur_spacing;
2639 float new_value = cur_value;
2641 lyxerr << "Missing argument to `paragraph-spacing'"
2643 } else if (tmp == "single") {
2644 new_spacing = Spacing::Single;
2645 } else if (tmp == "onehalf") {
2646 new_spacing = Spacing::Onehalf;
2647 } else if (tmp == "double") {
2648 new_spacing = Spacing::Double;
2649 } else if (tmp == "other") {
2650 new_spacing = Spacing::Other;
2653 lyxerr << "new_value = " << tmpval << endl;
2656 } else if (tmp == "default") {
2657 new_spacing = Spacing::Default;
2659 lyxerr << _("Unknown spacing argument: ")
2660 << argument << endl;
2662 if (cur_spacing != new_spacing || cur_value != new_value) {
2663 par->params().spacing(Spacing(new_spacing, new_value));
2664 lt->redoParagraph(bv_);
2667 | BufferView::FITCUR
2668 | BufferView::CHANGE);
2673 case LFUN_INSET_TOGGLE:
2675 LyXText * lt = bv_->getLyXText();
2678 update(lt, BufferView::SELECT|BufferView::FITCUR);
2679 lt->toggleInset(bv_);
2680 update(lt, BufferView::SELECT|BufferView::FITCUR);
2692 InsetCommandParams p;
2693 if (action == LFUN_HTMLURL)
2694 p.setCmdName("htmlurl");
2696 p.setCmdName("url");
2697 owner_->getDialogs()->createUrl(p.getAsString());
2701 case LFUN_INSERT_URL:
2703 InsetCommandParams p;
2704 p.setFromString(argument);
2706 InsetUrl * inset = new InsetUrl(p);
2707 if (!insertInset(inset))
2710 updateInset(inset, true);
2714 case LFUN_INSET_TEXT:
2715 insertAndEditInset(new InsetText);
2718 case LFUN_INSET_ERT:
2719 insertAndEditInset(new InsetERT);
2722 case LFUN_INSET_EXTERNAL:
2723 insertAndEditInset(new InsetExternal);
2726 case LFUN_INSET_FOOTNOTE:
2727 insertAndEditInset(new InsetFoot);
2730 case LFUN_INSET_MARGINAL:
2731 insertAndEditInset(new InsetMarginal);
2734 case LFUN_INSET_MINIPAGE:
2735 insertAndEditInset(new InsetMinipage);
2738 case LFUN_INSERT_NOTE:
2739 insertAndEditInset(new InsetNote);
2742 case LFUN_INSET_FLOAT:
2743 // check if the float type exist
2744 if (floatList.typeExist(argument)) {
2745 insertAndEditInset(new InsetFloat(argument));
2747 lyxerr << "Non-existant float type: "
2748 << argument << endl;
2752 case LFUN_INSET_WIDE_FLOAT:
2754 // check if the float type exist
2755 if (floatList.typeExist(argument)) {
2756 InsetFloat * new_inset = new InsetFloat(argument);
2757 new_inset->wide(true);
2758 if (insertInset(new_inset))
2759 new_inset->edit(bv_);
2763 lyxerr << "Non-existant float type: "
2764 << argument << endl;
2771 case LFUN_INSET_LIST:
2772 insertAndEditInset(new InsetList);
2775 case LFUN_INSET_THEOREM:
2776 insertAndEditInset(new InsetTheorem);
2780 case LFUN_INSET_CAPTION:
2782 // Do we have a locking inset...
2783 if (bv_->theLockingInset()) {
2784 lyxerr << "Locking inset code: "
2785 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2786 InsetCaption * new_inset = new InsetCaption;
2787 new_inset->setOwner(bv_->theLockingInset());
2788 new_inset->setAutoBreakRows(true);
2789 new_inset->setDrawFrame(0, InsetText::LOCKED);
2790 new_inset->setFrameColor(0, LColor::captionframe);
2791 if (insertInset(new_inset))
2792 new_inset->edit(bv_);
2799 case LFUN_INSET_TABULAR:
2803 if (!argument.empty())
2804 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2805 InsetTabular * new_inset =
2806 new InsetTabular(*buffer_, r, c);
2808 bv_->getLyXText()->real_current_font.isRightToLeft();
2809 if (!open_new_inset(new_inset, rtl))
2814 // --- lyxserver commands ----------------------------
2816 case LFUN_CHARATCURSOR:
2818 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2819 if (pos < bv_->getLyXText()->cursor.par()->size())
2820 owner_->getLyXFunc()->setMessage(
2821 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2823 owner_->getLyXFunc()->setMessage("EOF");
2828 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2830 + tostr(bv_->getLyXText()->cursor.y()));
2837 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2838 lyxerr << "SETXY: Could not parse coordinates in '"
2839 << argument << std::endl;
2841 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2845 case LFUN_GETLAYOUT:
2846 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2851 LyXFont & font = bv_->getLyXText()->current_font;
2852 if (font.shape() == LyXFont::ITALIC_SHAPE)
2853 owner_->getLyXFunc()->setMessage("E");
2854 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2855 owner_->getLyXFunc()->setMessage("N");
2857 owner_->getLyXFunc()->setMessage("0");
2865 LyXFont & font = bv_->getLyXText()->current_font;
2866 if (font.latex() == LyXFont::ON)
2867 owner_->getLyXFunc()->setMessage("L");
2870 owner_->getLyXFunc()->setMessage("0");
2874 // --- accented characters ---------------------------
2877 case LFUN_CIRCUMFLEX:
2887 case LFUN_SPECIAL_CARON:
2890 case LFUN_HUNG_UMLAUT:
2893 if (argument.empty()) {
2895 owner_->getLyXFunc()->handleKeyFunc(action);
2897 owner_->getLyXFunc()->handleKeyFunc(action);
2898 owner_->getIntl()->getTrans()
2899 .TranslateAndInsert(argument[0], bv_->getLyXText());
2900 update(bv_->getLyXText(),
2902 | BufferView::FITCUR
2903 | BufferView::CHANGE);
2907 case LFUN_MATH_MACRO:
2908 mathDispatchMathMacro(bv_, argument);
2911 case LFUN_MATH_DELIM:
2912 mathDispatchMathDelim(bv_, argument);
2915 case LFUN_INSERT_MATRIX:
2916 mathDispatchInsertMatrix(bv_, argument);
2919 case LFUN_INSERT_MATH:
2920 mathDispatchInsertMath(bv_, argument);
2923 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2924 mathDispatchMathImportSelection(bv_, argument);
2927 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2928 mathDispatchMathDisplay(bv_, argument);
2931 case LFUN_MATH_MODE: // Open or create an inlined math inset
2932 mathDispatchMathMode(bv_, argument);
2935 case LFUN_CITATION_INSERT:
2937 InsetCommandParams p;
2938 p.setFromString( argument );
2940 InsetCitation * inset = new InsetCitation( p );
2941 if (!insertInset(inset))
2944 updateInset( inset, true );
2948 case LFUN_INSERT_BIBTEX:
2950 // ale970405+lasgoutt970425
2951 // The argument can be up to two tokens separated
2952 // by a space. The first one is the bibstyle.
2953 string const db = token(argument, ' ', 0);
2954 string bibstyle = token(argument, ' ', 1);
2955 if (bibstyle.empty())
2958 InsetCommandParams p( "BibTeX", db, bibstyle );
2959 InsetBibtex * inset = new InsetBibtex(p);
2961 if (insertInset(inset)) {
2962 if (argument.empty())
2969 // BibTeX data bases
2970 case LFUN_BIBDB_ADD:
2972 InsetBibtex * inset =
2973 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2975 inset->addDatabase(argument);
2980 case LFUN_BIBDB_DEL:
2982 InsetBibtex * inset =
2983 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2985 inset->delDatabase(argument);
2990 case LFUN_BIBTEX_STYLE:
2992 InsetBibtex * inset =
2993 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2995 inset->setOptions(argument);
3000 case LFUN_INDEX_CREATE:
3002 InsetCommandParams p("index");
3003 if (argument.empty()) {
3004 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3005 if (!idxstring.empty())
3006 p.setContents(idxstring);
3010 p.setContents(argument);
3013 owner_->getDialogs()->createIndex(p.getAsString());
3017 case LFUN_INDEX_INSERT:
3019 InsetCommandParams p;
3020 p.setFromString(argument);
3021 InsetIndex * inset = new InsetIndex(p);
3023 if (!insertInset(inset))
3026 updateInset(inset, true);
3030 case LFUN_INDEX_INSERT_LAST:
3032 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3033 if (!idxstring.empty()) {
3034 owner_->message(_("Word `")
3035 + idxstring + _(("' indexed.")));
3036 InsetCommandParams p("index", idxstring);
3037 InsetIndex * inset = new InsetIndex(p);
3039 if (!insertInset(inset))
3042 updateInset(inset, true);
3047 case LFUN_INDEX_PRINT:
3049 InsetCommandParams p("printindex");
3050 Inset * inset = new InsetPrintIndex(p);
3051 if (!insertInset(inset, "Standard"))
3056 case LFUN_PARENTINSERT:
3058 lyxerr << "arg " << argument << endl;
3059 InsetCommandParams p( "lyxparent", argument );
3060 Inset * inset = new InsetParent(p, *buffer_);
3061 if (!insertInset(inset, "Standard"))
3067 case LFUN_CHILD_INSERT:
3069 InsetInclude::Params p;
3070 p.cparams.setFromString(argument);
3071 p.masterFilename_ = buffer_->fileName();
3073 InsetInclude * inset = new InsetInclude(p);
3074 if (!insertInset(inset))
3077 updateInset(inset, true);
3078 bv_->owner()->getDialogs()->showInclude(inset);
3083 case LFUN_FLOAT_LIST:
3085 // We should check the argument for validity. (Lgb)
3086 Inset * inset = new InsetFloatList(argument);
3087 if (!insertInset(inset, "Standard"))
3092 case LFUN_THESAURUS_ENTRY:
3094 string arg = argument;
3097 arg = bv_->getLyXText()->selectionAsString(buffer_);
3100 if (arg.size() > 100 || arg.empty()) {
3101 // Get word or selection
3102 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3103 arg = bv_->getLyXText()->selectionAsString(buffer_);
3104 // FIXME: where is getLyXText()->unselect(bv_) ?
3108 bv_->owner()->getDialogs()->showThesaurus(arg);
3112 case LFUN_SELFINSERT:
3114 if (argument.empty()) break;
3116 /* Automatically delete the currently selected
3117 * text and replace it with what is being
3118 * typed in now. Depends on lyxrc settings
3119 * "auto_region_delete", which defaults to
3122 LyXText * lt = bv_->getLyXText();
3124 if (lyxrc.auto_region_delete) {
3125 if (lt->selection.set()) {
3126 lt->cutSelection(bv_, false);
3129 | BufferView::FITCUR
3130 | BufferView::CHANGE);
3135 LyXFont const old_font(lt->real_current_font);
3137 string::const_iterator cit = argument.begin();
3138 string::const_iterator end = argument.end();
3139 for (; cit != end; ++cit) {
3140 if (greek_kb_flag) {
3141 if (!math_insert_greek(bv_, *cit))
3142 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3144 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3149 | BufferView::FITCUR
3150 | BufferView::CHANGE);
3152 lt->selection.cursor = lt->cursor;
3153 moveCursorUpdate(false);
3155 // real_current_font.number can change so we need to
3156 // update the minibuffer
3157 if (old_font != lt->real_current_font)
3158 owner_->showState();
3163 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3165 time_t now_time_t = time(NULL);
3166 struct tm * now_tm = localtime(&now_time_t);
3167 setlocale(LC_TIME, "");
3169 if (!argument.empty())
3172 arg = lyxrc.date_insert_format;
3174 int const datetmp_len =
3175 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3177 LyXText * lt = bv_->getLyXText();
3179 for (int i = 0; i < datetmp_len; i++) {
3180 lt->insertChar(bv_, datetmp[i]);
3183 | BufferView::FITCUR
3184 | BufferView::CHANGE);
3187 lt->selection.cursor = lt->cursor;
3188 moveCursorUpdate(false);
3192 case LFUN_UNKNOWN_ACTION:
3193 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3204 void BufferView::Pimpl::newline()
3207 LyXText * lt = bv_->getLyXText();
3211 | BufferView::FITCUR);
3212 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3215 | BufferView::FITCUR
3216 | BufferView::CHANGE);
3221 void BufferView::Pimpl::hfill()
3224 LyXText * lt = bv_->getLyXText();
3228 | BufferView::FITCUR);
3229 lt->insertChar(bv_, Paragraph::META_HFILL);
3232 | BufferView::FITCUR
3233 | BufferView::CHANGE);
3238 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3242 update(lt, BufferView::SELECT|BufferView::FITCUR);
3243 InsetSpecialChar * new_inset =
3244 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3245 #ifdef WITH_WARNINGS
3246 #warning Why is this code different from specialChar() below? (JMarc)
3247 // the code in specialChar is a generic version of what used to exist
3248 // for other special chars. I did not merge this case because of the
3249 // call to updateInset(), but what does it do?
3251 if (!insertInset(new_inset))
3254 updateInset(new_inset, true);
3259 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3262 LyXText * lt = bv_->getLyXText();
3265 update(lt, BufferView::SELECT|BufferView::FITCUR);
3266 InsetSpecialChar * new_inset =
3267 new InsetSpecialChar(kind);
3268 insertInset(new_inset);
3273 void BufferView::Pimpl::smartQuote()
3276 LyXText * lt = bv_->getLyXText();
3278 if (lt->cursor.pos())
3279 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3284 if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
3285 Dispatch(LFUN_SELFINSERT, "\"");
3289 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3291 if (insertInset(inset))
3298 // Open and lock an updatable inset
3299 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3301 LyXText * lt = bv_->getLyXText();
3305 if (!insertInset(new_inset)) {
3309 new_inset->edit(bv_, !behind);
3314 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3316 // if we are in a locking inset we should try to insert the
3317 // inset there otherwise this is a illegal function now
3318 if (bv_->theLockingInset()) {
3319 if (bv_->theLockingInset()->insetAllowed(inset))
3320 return bv_->theLockingInset()->insertInset(bv_, inset);
3324 // not quite sure if we want this...
3325 setCursorParUndo(bv_);
3328 beforeChange(bv_->text);
3329 if (!lout.empty()) {
3330 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3331 bv_->text->breakParagraph(bv_);
3332 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3334 if (bv_->text->cursor.par()->size()) {
3335 bv_->text->cursorLeft(bv_);
3337 bv_->text->breakParagraph(bv_);
3338 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3341 pair<bool, LyXTextClass::size_type> lres =
3342 textclasslist.NumberOfLayout(buffer_->params
3344 LyXTextClass::size_type lay;
3345 if (lres.first != false) {
3349 // layout not fount using default "Standard" (0)
3353 bv_->text->setLayout(bv_, lay);
3355 bv_->text->setParagraph(bv_, 0, 0,
3357 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3363 bv_->text->current_font.setLatex(LyXFont::OFF);
3367 bv_->text->insertInset(bv_, inset);
3368 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3375 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3380 // first check for locking insets
3381 if (bv_->theLockingInset()) {
3382 if (bv_->theLockingInset() == inset) {
3383 if (bv_->text->updateInset(bv_, inset)) {
3386 buffer_->markDirty();
3391 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3392 if (bv_->text->updateInset(bv_,
3393 bv_->theLockingInset())) {
3396 buffer_->markDirty();
3404 // then check the current buffer
3407 update(bv_->text, BufferView::UPDATE);
3408 if (bv_->text->updateInset(bv_, inset)) {
3412 | BufferView::FITCUR
3413 | BufferView::CHANGE);
3415 update(bv_->text, SELECT);
3423 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3426 if (!available()) return;
3429 beforeChange(bv_->text);
3430 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3434 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3435 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3436 if (find(codes.begin(), codes.end(), inset->lyxCode())
3439 static_cast<InsetCommand const *>(inset)->getContents();
3442 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3443 if (bv_->text->cursor.pos()
3444 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3445 LyXCursor tmp = bv_->text->cursor;
3446 bv_->text->cursor.par(bv_->text->firstParagraph());
3447 bv_->text->cursor.pos(0);
3448 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3449 bv_->text->cursor = tmp;
3450 bv_->owner()->message(_("No more insets"));
3453 bv_->owner()->message(_("No more insets"));
3456 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3457 bv_->text->selection.cursor = bv_->text->cursor;
3461 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3463 gotoInset(vector<Inset::Code>(1, code), same_content);