7 #include "BufferView_pimpl.h"
12 #include "paragraph.h"
14 #include "commandtags.h"
18 #include "bufferview_funcs.h"
19 #include "TextCache.h"
20 #include "bufferlist.h"
21 #include "lyx_gui_misc.h"
24 // added for Dispatch functions
27 #include "FloatList.h"
29 #include "ParagraphParameters.h"
30 #include "undo_funcs.h"
31 #include "lyxtextclasslist.h"
33 #include "frontends/Dialogs.h"
34 #include "frontends/Alert.h"
35 #include "frontends/FileDialog.h"
37 #include "insets/insetbib.h"
38 #include "insets/insettext.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetlatexaccent.h"
41 #include "insets/insettoc.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetnote.h"
46 #include "insets/insetinclude.h"
47 #include "insets/insetcite.h"
48 #include "insets/insetert.h"
49 #include "insets/insetexternal.h"
50 #include "insets/insetgraphics.h"
51 #include "insets/insetfoot.h"
52 #include "insets/insetmarginal.h"
53 #include "insets/insetminipage.h"
54 #include "insets/insetfloat.h"
55 #include "insets/insettabular.h"
57 #include "insets/insettheorem.h"
58 #include "insets/insetlist.h"
60 #include "insets/insetcaption.h"
61 #include "insets/insetfloatlist.h"
62 #include "insets/insetspecialchar.h"
64 #include "mathed/formulabase.h"
66 #include "support/LAssert.h"
67 #include "support/lstrings.h"
68 #include "support/filetools.h"
69 #include "support/lyxfunctional.h"
77 extern lyx::layout_type current_layout;
89 using lyx::layout_type;
90 using lyx::textclass_type;
92 /* the selection possible is needed, that only motion events are
93 * used, where the bottom press event was on the drawing area too */
94 bool selection_possible = false;
96 extern BufferList bufferlist;
97 extern char ascii_type;
99 extern void sigchldchecker(pid_t pid, int * status);
100 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
105 const unsigned int saved_positions_num = 20;
110 XSync(fl_get_display(), 0);
114 void SetXtermCursor(Window win)
116 static Cursor cursor;
117 static bool cursor_undefined = true;
118 if (cursor_undefined) {
119 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
120 XFlush(fl_get_display());
121 cursor_undefined = false;
123 XDefineCursor(fl_get_display(), win, cursor);
124 XFlush(fl_get_display());
130 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
131 int xpos, int ypos, int width, int height)
132 : bv_(b), owner_(o), buffer_(0),
133 current_scrollbar_value(0), cursor_timeout(400),
134 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
138 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
139 workarea_.workAreaExpose
140 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
141 workarea_.workAreaEnter
142 .connect(slot(this, &BufferView::Pimpl::enterView));
143 workarea_.workAreaLeave
144 .connect(slot(this, &BufferView::Pimpl::leaveView));
145 workarea_.workAreaButtonPress
146 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
147 workarea_.workAreaButtonRelease
149 &BufferView::Pimpl::workAreaButtonRelease));
150 workarea_.workAreaMotionNotify
151 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
152 workarea_.workAreaDoubleClick
153 .connect(slot(this, &BufferView::Pimpl::doubleClick));
154 workarea_.workAreaTripleClick
155 .connect(slot(this, &BufferView::Pimpl::tripleClick));
156 workarea_.workAreaKeyPress
157 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
158 workarea_.selectionRequested
159 .connect(slot(this, &BufferView::Pimpl::selectionRequested));
160 workarea_.selectionLost
161 .connect(slot(this, &BufferView::Pimpl::selectionLost));
163 cursor_timeout.timeout.connect(slot(this,
164 &BufferView::Pimpl::cursorToggle));
165 cursor_timeout.start();
166 workarea_.setFocus();
167 saved_positions.resize(saved_positions_num);
171 Painter & BufferView::Pimpl::painter()
173 return workarea_.getPainter();
177 void BufferView::Pimpl::buffer(Buffer * b)
179 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
183 buffer_->delUser(bv_);
185 // Put the old text into the TextCache, but
186 // only if the buffer is still loaded.
187 // Also set the owner of the test to 0
188 // bv_->text->owner(0);
189 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
190 if (lyxerr.debugging())
191 textcache.show(lyxerr, "BufferView::buffer");
196 // Set current buffer
199 if (bufferlist.getState() == BufferList::CLOSING) return;
202 // screen is always deleted when the buffer is changed.
205 // If we are closing the buffer, use the first buffer as current
207 buffer_ = bufferlist.first();
211 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
212 buffer_->addUser(bv_);
213 // If we don't have a text object for this, we make one
214 if (bv_->text == 0) {
215 resizeCurrentBuffer();
220 bv_->text->first = screen_->topCursorVisible(bv_->text);
221 owner_->updateMenubar();
222 owner_->updateToolbar();
223 // Similarly, buffer-dependent dialogs should be updated or
224 // hidden. This should go here because some dialogs (eg ToC)
225 // require bv_->text.
226 owner_->getDialogs()->updateBufferDependent(true);
230 lyxerr[Debug::INFO] << " No Buffer!" << endl;
231 owner_->updateMenubar();
232 owner_->updateToolbar();
233 owner_->getDialogs()->hideBufferDependent();
237 // Also remove all remaining text's from the testcache.
238 // (there should not be any!) (if there is any it is a
240 if (lyxerr.debugging())
241 textcache.show(lyxerr, "buffer delete all");
244 // should update layoutchoice even if we don't have a buffer.
245 owner_->updateLayoutChoice();
247 owner_->updateWindowTitle();
251 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
253 workarea_.resize(xpos, ypos, width, height);
254 update(bv_->text, SELECT);
259 void BufferView::Pimpl::resize()
262 resizeCurrentBuffer();
266 void BufferView::Pimpl::redraw()
268 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
273 bool BufferView::Pimpl::fitCursor()
275 lyx::Assert(screen_.get());
279 if (bv_->theLockingInset()) {
280 bv_->theLockingInset()->fitInsetCursor(bv_);
283 ret = screen_->fitCursor(bv_->text, bv_);
286 bv_->owner()->getDialogs()->updateParagraph();
293 void BufferView::Pimpl::redoCurrentBuffer()
295 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
296 if (buffer_ && bv_->text) {
298 owner_->updateLayoutChoice();
303 int BufferView::Pimpl::resizeCurrentBuffer()
305 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
308 Paragraph * selstartpar = 0;
309 Paragraph * selendpar = 0;
310 UpdatableInset * the_locking_inset = 0;
313 pos_type selstartpos = 0;
314 pos_type selendpos = 0;
315 bool selection = false;
316 bool mark_set = false;
318 owner_->prohibitInput();
320 owner_->message(_("Formatting document..."));
323 par = bv_->text->cursor.par();
324 pos = bv_->text->cursor.pos();
325 selstartpar = bv_->text->selection.start.par();
326 selstartpos = bv_->text->selection.start.pos();
327 selendpar = bv_->text->selection.end.par();
328 selendpos = bv_->text->selection.end.pos();
329 selection = bv_->text->selection.set();
330 mark_set = bv_->text->selection.mark();
331 the_locking_inset = bv_->theLockingInset();
333 bv_->text = new LyXText(bv_);
334 bv_->text->init(bv_);
336 // See if we have a text in TextCache that fits
337 // the new buffer_ with the correct width.
338 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
340 if (lyxerr.debugging()) {
341 lyxerr << "Found a LyXText that fits:\n";
342 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
344 // Set the owner of the newly found text
345 // bv_->text->owner(bv_);
346 if (lyxerr.debugging())
347 textcache.show(lyxerr, "resizeCurrentBuffer");
349 bv_->text = new LyXText(bv_);
350 bv_->text->init(bv_);
356 bv_->text->selection.set(true);
357 /* at this point just to avoid the Delete-Empty-Paragraph
358 * Mechanism when setting the cursor */
359 bv_->text->selection.mark(mark_set);
361 bv_->text->setCursor(bv_, selstartpar, selstartpos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->setCursor(bv_, selendpar, selendpos);
364 bv_->text->setSelection(bv_);
365 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->setCursor(bv_, par, pos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->selection.set(false);
371 // remake the inset locking
372 bv_->theLockingInset(the_locking_inset);
374 bv_->text->first = screen_->topCursorVisible(bv_->text);
376 buffer_->resizeInsets(bv_);
378 // this will scroll the screen such that the cursor becomes visible
383 owner_->allowInput();
385 /// clear the "Formatting Document" message
392 void BufferView::Pimpl::updateScreen()
394 // Regenerate the screen.
395 screen_.reset(new LyXScreen(workarea_));
399 void BufferView::Pimpl::updateScrollbar()
401 /* If the text is smaller than the working area, the scrollbar
402 * maximum must be the working area height. No scrolling will
405 workarea_.setScrollbar(0, 1.0);
409 long const text_height = bv_->text->height;
410 long const work_height = workarea_.height();
412 if (text_height <= work_height) {
413 workarea_.setScrollbarBounds(0.0, 0.0);
414 current_scrollbar_value = bv_->text->first;
415 workarea_.setScrollbar(current_scrollbar_value, 1.0);
419 double const lineh = bv_->text->defaultHeight();
420 double const slider_size =
421 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
423 static long old_text_height;
424 static double old_lineh;
425 static double old_slider_size;
427 if (text_height != old_text_height) {
428 workarea_.setScrollbarBounds(0.0,
429 text_height - work_height);
430 old_text_height = text_height;
432 if (lineh != old_lineh) {
433 workarea_.setScrollbarIncrements(lineh);
436 if (current_scrollbar_value != bv_->text->first
437 || slider_size != old_slider_size) {
438 current_scrollbar_value = bv_->text->first;
439 workarea_.setScrollbar(current_scrollbar_value, slider_size);
440 old_slider_size = slider_size;
445 // Callback for scrollbar slider
446 void BufferView::Pimpl::scrollCB(double value)
448 if (!buffer_) return;
450 current_scrollbar_value = long(value);
452 if (current_scrollbar_value < 0)
453 current_scrollbar_value = 0;
458 screen_->draw(bv_->text, bv_, current_scrollbar_value);
460 if (!lyxrc.cursor_follows_scrollbar) {
465 LyXText * vbt = bv_->text;
467 int const height = vbt->defaultHeight();
468 int const first = static_cast<int>((bv_->text->first + height));
469 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
471 if (vbt->cursor.y() < first)
472 vbt->setCursorFromCoordinates(bv_, 0, first);
473 else if (vbt->cursor.y() > last)
474 vbt->setCursorFromCoordinates(bv_, 0, last);
480 int BufferView::Pimpl::scrollUp(long time)
482 if (!buffer_) return 0;
483 if (!screen_.get()) return 0;
485 double value = workarea_.getScrollbarValue();
487 if (value == 0) return 0;
489 float add_value = (bv_->text->defaultHeight()
490 + float(time) * float(time) * 0.125);
492 if (add_value > workarea_.height())
493 add_value = float(workarea_.height() -
494 bv_->text->defaultHeight());
501 workarea_.setScrollbarValue(value);
508 int BufferView::Pimpl::scrollDown(long time)
510 if (!buffer_) return 0;
511 if (!screen_.get()) return 0;
513 double value = workarea_.getScrollbarValue();
514 pair<float, float> p = workarea_.getScrollbarBounds();
515 double const max = p.second;
517 if (value == max) return 0;
519 float add_value = (bv_->text->defaultHeight()
520 + float(time) * float(time) * 0.125);
522 if (add_value > workarea_.height())
523 add_value = float(workarea_.height() -
524 bv_->text->defaultHeight());
531 workarea_.setScrollbarValue(value);
538 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
540 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
544 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
546 // Only use motion with button 1
547 if (!(state & Button1MotionMask))
550 if (!buffer_ || !screen_.get()) return;
552 // Check for inset locking
553 if (bv_->theLockingInset()) {
554 LyXCursor cursor = bv_->text->cursor;
555 LyXFont font = bv_->text->getFont(buffer_,
556 cursor.par(), cursor.pos());
557 int width = bv_->theLockingInset()->width(bv_, font);
558 int inset_x = font.isVisibleRightToLeft()
559 ? cursor.x() - width : cursor.x();
560 int start_x = inset_x + bv_->theLockingInset()->scroll();
561 bv_->theLockingInset()->
562 insetMotionNotify(bv_,
564 y - cursor.y() + bv_->text->first,
569 /* The test for not selection possible is needed, that only motion
570 events are used, where the bottom press event was on
571 the drawing area too */
572 if (!selection_possible)
575 screen_->hideCursor();
577 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
579 if (!bv_->text->selection.set())
580 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
582 bv_->text->setSelection(bv_);
583 screen_->toggleToggle(bv_->text, bv_);
589 // Single-click on work area
590 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
593 if (!buffer_ || !screen_.get()) return;
595 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
597 // ok ok, this is a hack.
598 if (button == 4 || button == 5) {
601 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
604 scrollDown(lyxrc.wheel_jump);
609 if (bv_->theLockingInset()) {
610 // We are in inset locking mode
612 /* Check whether the inset was hit. If not reset mode,
613 otherwise give the event to the inset */
614 if (inset_hit == bv_->theLockingInset()) {
615 bv_->theLockingInset()->
616 insetButtonPress(bv_,xpos, ypos,button);
619 bv_->unlockInset(bv_->theLockingInset());
624 selection_possible = true;
625 screen_->hideCursor();
627 int const screen_first = bv_->text->first;
629 // Middle button press pastes if we have a selection
630 bool paste_internally = false;
632 && bv_->text->selection.set()) {
633 owner_->getLyXFunc()->dispatch(LFUN_COPY);
634 paste_internally = true;
637 // Clear the selection
638 screen_->toggleSelection(bv_->text, bv_);
639 bv_->text->clearSelection();
640 bv_->text->fullRebreak(bv_);
644 // Single left click in math inset?
645 if (isHighlyEditableInset(inset_hit)) {
646 // Highly editable inset, like math
647 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
648 selection_possible = false;
649 owner_->updateLayoutChoice();
650 owner_->message(inset->editMessage());
651 inset->insetButtonPress(bv_, xpos, ypos, button);
652 inset->edit(bv_, xpos, ypos, button);
656 // Right click on a footnote flag opens float menu
658 selection_possible = false;
662 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
663 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
665 bv_->text->selection.cursor = bv_->text->cursor;
666 bv_->text->cursor.x_fix(bv_->text->cursor.x());
668 owner_->updateLayoutChoice();
670 selection_possible = false;
673 // Insert primary selection with middle mouse
674 // if there is a local selection in the current buffer,
677 if (paste_internally)
678 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
680 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
682 selection_possible = false;
688 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
694 LyXText * text = bv_->getLyXText();
696 if (text->bv_owner && bv_->theLockingInset())
699 if (screen_.get() && button == 1) {
700 if (text->bv_owner) {
701 screen_->hideCursor();
702 screen_->toggleSelection(text, bv_);
703 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
704 screen_->toggleSelection(text, bv_, false);
706 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
708 /* This will fit the cursor on the screen
710 update(text, BufferView::SELECT|BufferView::FITCUR);
715 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
721 LyXText * text = bv_->getLyXText();
723 if (text->bv_owner && bv_->theLockingInset())
726 if (screen_.get() && (button == 1)) {
727 if (text->bv_owner) {
728 screen_->hideCursor();
729 screen_->toggleSelection(text, bv_);
731 text->cursorHome(bv_);
732 text->selection.cursor = text->cursor;
733 text->cursorEnd(bv_);
734 text->setSelection(bv_);
735 if (text->bv_owner) {
736 screen_->toggleSelection(text, bv_, false);
738 /* This will fit the cursor on the screen
740 update(text, BufferView::SELECT|BufferView::FITCUR);
745 void BufferView::Pimpl::selectionRequested()
750 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
753 workarea_.putClipboard(sel);
758 void BufferView::Pimpl::selectionLost()
762 bv_->getLyXText()->clearSelection();
767 void BufferView::Pimpl::enterView()
769 if (active() && available()) {
770 SetXtermCursor(workarea_.getWin());
771 using_xterm_cursor = true;
776 void BufferView::Pimpl::leaveView()
778 if (using_xterm_cursor) {
779 XUndefineCursor(fl_get_display(), workarea_.getWin());
780 using_xterm_cursor = false;
785 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
788 if (!buffer_ || !screen_.get()) return;
790 // If we hit an inset, we have the inset coordinates in these
791 // and inset_hit points to the inset. If we do not hit an
792 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
793 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
795 if (bv_->theLockingInset()) {
796 // We are in inset locking mode.
798 /* LyX does a kind of work-area grabbing for insets.
799 Only a ButtonPress Event outside the inset will
800 force a insetUnlock. */
801 bv_->theLockingInset()->
802 insetButtonRelease(bv_, x, y, button);
806 selection_possible = false;
813 workarea_.haveSelection(bv_->getLyXText()->selection.set());
818 owner_->updateMenubar();
819 owner_->updateToolbar();
821 // Did we hit an editable inset?
823 // Inset like error, notes and figures
824 selection_possible = false;
826 // if we reach this point with a selection, it
827 // must mean we are currently selecting.
828 // But we don't want to open the inset
829 // because that is annoying for the user.
830 // So just pretend we didn't hit it.
831 // this is OK because a "kosher" ButtonRelease
832 // will follow a ButtonPress that clears
834 // Note this also fixes selection drawing
835 // problems if we end up opening an inset
836 if (bv_->getLyXText()->selection.set())
839 // CHECK fix this proper in 0.13
840 // well, maybe 13.0 !!!!!!!!!
842 // Following a ref shouldn't issue
843 // a push on the undo-stack
844 // anylonger, now that we have
845 // keybindings for following
846 // references and returning from
847 // references. IMHO though, it
848 // should be the inset's own business
849 // to push or not push on the undo
850 // stack. They don't *have* to
851 // alter the document...
853 // ...or maybe the SetCursorParUndo()
854 // below isn't necessary at all anylonger?
855 if (inset_hit->lyxCode() == Inset::REF_CODE) {
856 setCursorParUndo(bv_);
859 owner_->message(inset_hit->editMessage());
861 if (isHighlyEditableInset(inset_hit)) {
862 // Highly editable inset, like math
863 UpdatableInset *inset = (UpdatableInset *)inset_hit;
864 inset->insetButtonRelease(bv_, x, y, button);
866 inset_hit->insetButtonRelease(bv_, x, y, button);
867 inset_hit->edit(bv_, x, y, button);
872 // Maybe we want to edit a bibitem ale970302
873 if (bv_->text->cursor.par()->bibkey && x < 20 +
874 bibitemMaxWidth(bv_, textclasslist.
876 params.textclass).defaultfont())) {
877 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
884 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
885 LyXCursor const & cursor) const
887 Paragraph /*const*/ & par = *cursor.par();
888 pos_type const pos = cursor.pos();
890 lyx::Assert(par.getInset(pos));
892 Inset const & inset(*par.getInset(pos));
894 LyXFont const & font = text.getFont(buffer_, &par, pos);
896 int const width = inset.width(bv_, font);
897 int const inset_x = font.isVisibleRightToLeft()
898 ? (cursor.x() - width) : cursor.x();
901 inset_x + inset.scroll(),
903 cursor.y() - inset.ascent(bv_, font),
904 cursor.y() + inset.descent(bv_, font));
908 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
909 LyXCursor const & cursor,
910 int & x, int & y) const
912 pos_type const pos(cursor.pos());
913 Paragraph /*const*/ & par(*cursor.par());
915 if (pos >= par.size() || !par.isInset(pos)) {
919 Inset /*const*/ * inset = par.getInset(pos);
921 if (!isEditableInset(inset)) {
925 Box b(insetDimensions(text, cursor));
927 if (!b.contained(x, y)) {
928 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
929 << " box " << b << endl;
933 text.setCursor(bv_, &par, pos, true);
936 // The origin of an inset is on the baseline
937 y -= (text.cursor.y());
943 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
948 int y_tmp = y + text->first;
951 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
953 Inset * inset(checkInset(*text, cursor, x, y_tmp));
960 // look at previous position
962 if (cursor.pos() == 0) {
967 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
969 inset = checkInset(*text, cursor, x, y_tmp);
977 void BufferView::Pimpl::workAreaExpose()
979 static int work_area_width;
980 static unsigned int work_area_height;
982 bool const widthChange = workarea_.workWidth() != work_area_width;
983 bool const heightChange = workarea_.height() != work_area_height;
985 // update from work area
986 work_area_width = workarea_.workWidth();
987 work_area_height = workarea_.height();
990 // The visible LyXView need a resize
993 // Remove all texts from the textcache
994 // This is not _really_ what we want to do. What
995 // we really want to do is to delete in textcache
996 // that does not have a BufferView with matching
997 // width, but as long as we have only one BufferView
998 // deleting all gives the same result.
999 if (lyxerr.debugging())
1000 textcache.show(lyxerr, "Expose delete all");
1002 } else if (heightChange) {
1003 // Rebuild image of current screen
1005 // fitCursor() ensures we don't jump back
1006 // to the start of the document on vertical
1010 // The main window size has changed, repaint most stuff
1012 } else if (screen_.get())
1013 screen_->redraw(bv_->text, bv_);
1015 // Grey box when we don't have a buffer
1016 workarea_.greyOut();
1019 // always make sure that the scrollbar is sane.
1021 owner_->updateLayoutChoice();
1026 void BufferView::Pimpl::update()
1028 if (screen_.get() &&
1029 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1031 LyXText::text_status st = bv_->text->status();
1032 screen_->update(bv_->text, bv_);
1034 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1035 if (bv_->text->fullRebreak(bv_)) {
1036 st = LyXText::NEED_MORE_REFRESH;
1037 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1038 bv_->text->cursor.pos());
1041 bv_->text->status(bv_, st);
1042 screen_->update(bv_->text, bv_);
1044 // do this here instead of in the screen::update because of
1046 bv_->text->status(bv_, LyXText::UNCHANGED);
1052 // Values used when calling update:
1054 // -2 - update, move sel_cursor if selection, fitcursor
1055 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1056 // 0 - update, move sel_cursor if selection, fitcursor
1057 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1058 // 3 - update, move sel_cursor if selection
1061 // a simple redraw of the parts that need refresh
1063 // move sel_cursor if selection -
1064 // the text's sel_cursor is moved if there is selection is progress
1067 // fitCursor() is called and the scrollbar updated
1070 // the buffer is marked dirty.
1079 // UPDATE_ONLY = UPDATE;
1080 // UPDATE_SELECT = UPDATE | SELECT;
1081 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1082 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1084 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1085 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1086 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1087 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1088 // update(3) -> update(1) -> update(1) -> update(SELECT)
1090 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1092 owner_->updateLayoutChoice();
1094 if (!text->selection.set() && (f & SELECT)) {
1095 text->selection.cursor = text->cursor;
1098 text->fullRebreak(bv_);
1100 if (text->inset_owner) {
1101 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1102 updateInset(text->inset_owner, false);
1112 buffer_->markDirty();
1117 // Callback for cursor timer
1118 void BufferView::Pimpl::cursorToggle()
1120 // Quite a nice place for asyncron Inset updating, isn't it?
1121 // Actually no! This is run even if no buffer exist... so (Lgb)
1123 cursor_timeout.restart();
1128 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1129 if (pid == -1) // error find out what is wrong
1130 ; // ignore it for now.
1132 sigchldchecker(pid, &status);
1134 updatelist.update(bv_);
1136 if (!screen_.get()) {
1137 cursor_timeout.restart();
1141 if (!bv_->theLockingInset()) {
1142 screen_->cursorToggle(bv_);
1144 bv_->theLockingInset()->toggleInsetCursor(bv_);
1147 cursor_timeout.restart();
1151 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1153 if (!text->cursor.row()->previous())
1156 int y = text->first;
1157 if (text->inset_owner)
1158 y += bv_->text->first;
1159 Row * cursorrow = text->cursor.row();
1160 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1162 // This is to allow jumping over large insets
1163 if ((cursorrow == text->cursor.row()))
1164 text->cursorUp(bv_);
1166 if (text->inset_owner ||
1167 text->cursor.row()->height() < workarea_.height())
1168 screen_->draw(bv_->text, bv_,
1170 - text->cursor.row()->baseline()
1171 + text->cursor.row()->height()
1172 - workarea_.height() + 1);
1177 void BufferView::Pimpl::cursorNext(LyXText * text)
1179 if (!text->cursor.row()->next())
1182 int y = text->first + workarea_.height();
1183 // if (text->inset_owner)
1184 // y += bv_->text->first;
1185 text->getRowNearY(y);
1187 Row * cursorrow = text->cursor.row();
1188 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1190 // This is to allow jumping over large insets
1191 if ((cursorrow == bv_->text->cursor.row()))
1192 text->cursorDown(bv_);
1194 if (text->inset_owner ||
1195 text->cursor.row()->height() < workarea_.height())
1196 screen_->draw(bv_->text, bv_, text->cursor.y() -
1197 text->cursor.row()->baseline());
1202 bool BufferView::Pimpl::available() const
1204 if (buffer_ && bv_->text) return true;
1209 void BufferView::Pimpl::beforeChange(LyXText * text)
1212 text->clearSelection();
1216 void BufferView::Pimpl::savePosition(unsigned int i)
1218 if (i >= saved_positions_num)
1220 saved_positions[i] = Position(buffer_->fileName(),
1221 bv_->text->cursor.par()->id(),
1222 bv_->text->cursor.pos());
1225 str << _("Saved bookmark") << ' ' << i;
1226 owner_->message(str.str().c_str());
1231 void BufferView::Pimpl::restorePosition(unsigned int i)
1233 if (i >= saved_positions_num)
1236 string const fname = saved_positions[i].filename;
1238 beforeChange(bv_->text);
1240 if (fname != buffer_->fileName()) {
1241 Buffer * b = bufferlist.exists(fname) ?
1242 bufferlist.getBuffer(fname) :
1243 bufferlist.loadLyXFile(fname); // don't ask, just load it
1244 if (b != 0) buffer(b);
1247 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1251 bv_->text->setCursor(bv_, par,
1252 min(par->size(), saved_positions[i].par_pos));
1254 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1257 str << _("Moved to bookmark") << ' ' << i;
1258 owner_->message(str.str().c_str());
1263 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1265 if (i >= saved_positions_num)
1268 return !saved_positions[i].filename.empty();
1272 void BufferView::Pimpl::setState()
1274 if (!lyxrc.rtl_support)
1277 LyXText * text = bv_->getLyXText();
1278 if (text->real_current_font.isRightToLeft()) {
1279 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1280 owner_->getIntl()->KeyMapSec();
1282 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1283 owner_->getIntl()->KeyMapPrim();
1288 void BufferView::Pimpl::insetSleep()
1290 if (bv_->theLockingInset() && !inset_slept) {
1291 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1292 bv_->theLockingInset()->insetUnlock(bv_);
1298 void BufferView::Pimpl::insetWakeup()
1300 if (bv_->theLockingInset() && inset_slept) {
1301 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1302 inset_slept = false;
1307 void BufferView::Pimpl::insetUnlock()
1309 if (bv_->theLockingInset()) {
1311 bv_->theLockingInset()->insetUnlock(bv_);
1312 bv_->theLockingInset(0);
1314 inset_slept = false;
1319 bool BufferView::Pimpl::focus() const
1321 return workarea_.hasFocus();
1325 void BufferView::Pimpl::focus(bool f)
1327 if (f) workarea_.setFocus();
1331 bool BufferView::Pimpl::active() const
1333 return workarea_.active();
1337 bool BufferView::Pimpl::belowMouse() const
1339 return workarea_.belowMouse();
1343 void BufferView::Pimpl::showCursor()
1345 if (screen_.get()) {
1346 if (bv_->theLockingInset())
1347 bv_->theLockingInset()->showInsetCursor(bv_);
1349 screen_->showCursor(bv_->text, bv_);
1354 void BufferView::Pimpl::hideCursor()
1356 if (screen_.get()) {
1357 if (!bv_->theLockingInset())
1358 // bv_->theLockingInset()->hideInsetCursor(bv_);
1360 screen_->hideCursor();
1365 void BufferView::Pimpl::toggleSelection(bool b)
1367 if (screen_.get()) {
1368 if (bv_->theLockingInset())
1369 bv_->theLockingInset()->toggleSelection(bv_, b);
1370 screen_->toggleSelection(bv_->text, bv_, b);
1375 void BufferView::Pimpl::toggleToggle()
1378 screen_->toggleToggle(bv_->text, bv_);
1382 void BufferView::Pimpl::center()
1384 beforeChange(bv_->text);
1385 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1386 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1388 screen_->draw(bv_->text, bv_, 0);
1390 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1395 void BufferView::Pimpl::pasteClipboard(bool asPara)
1397 if (!buffer_) return;
1399 screen_->hideCursor();
1400 beforeChange(bv_->text);
1402 string const clip(workarea_.getClipboard());
1404 if (clip.empty()) return;
1407 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1409 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1411 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1415 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1417 workarea_.putClipboard(stuff);
1422 * Dispatch functions for actions which can be valid for BufferView->text
1423 * and/or InsetText->text!!!
1428 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1430 LyXText * lt = bv_->getLyXText();
1432 if (selecting || lt->selection.mark()) {
1433 lt->setSelection(bv_);
1437 update(lt, BufferView::SELECT|BufferView::FITCUR);
1440 /* ---> Everytime the cursor is moved, show the current font state. */
1441 // should this too me moved out of this func?
1442 //owner->showState();
1447 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1449 LyXCursor cursor = bv_->getLyXText()->cursor;
1450 Buffer::inset_iterator it =
1451 find_if(Buffer::inset_iterator(
1452 cursor.par(), cursor.pos()),
1453 buffer_->inset_iterator_end(),
1454 lyx::compare_memfun(&Inset::lyxCode, code));
1455 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1459 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1461 string filename = filen;
1463 if (filename.empty()) {
1464 // Launch a file browser
1465 string initpath = lyxrc.document_path;
1468 string const trypath = owner_->buffer()->filePath();
1469 // If directory is writeable, use this as default.
1470 if (IsDirWriteable(trypath))
1474 FileDialog fileDlg(bv_->owner(),
1475 _("Select LyX document to insert"),
1477 make_pair(string(_("Documents|#o#O")),
1478 string(lyxrc.document_path)),
1479 make_pair(string(_("Examples|#E#e")),
1480 string(AddPath(system_lyxdir, "examples"))));
1482 FileDialog::Result result =
1483 fileDlg.Select(initpath,
1484 _("*.lyx| LyX Documents (*.lyx)"));
1486 if (result.first == FileDialog::Later)
1489 filename = result.second;
1491 // check selected filename
1492 if (filename.empty()) {
1493 owner_->message(_("Canceled."));
1498 // get absolute path of file and add ".lyx" to the filename if
1500 filename = FileSearch(string(), filename, "lyx");
1502 string const disp_fn(MakeDisplayPath(filename));
1505 s1 << _("Inserting document") << ' '
1506 << disp_fn << " ...";
1507 owner_->message(s1.str().c_str());
1508 bool const res = bv_->insertLyXFile(filename);
1511 str << _("Document") << ' ' << disp_fn
1512 << ' ' << _("inserted.");
1513 owner_->message(str.str().c_str());
1516 str << _("Could not insert document") << ' '
1518 owner_->message(str.str().c_str());
1523 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1525 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1526 << action <<"] arg[" << argument << "]" << endl;
1529 // --- Misc -------------------------------------------
1533 LyXText * lt = bv_->getLyXText();
1534 lt->toggleAppendix(bv_);
1537 | BufferView::FITCUR
1538 | BufferView::CHANGE);
1543 case LFUN_TOC_INSERT:
1545 InsetCommandParams p;
1546 p.setCmdName("tableofcontents");
1547 Inset * inset = new InsetTOC(p);
1548 if (!insertInset(inset, "Standard"))
1553 case LFUN_TABULAR_FEATURE:
1554 case LFUN_SCROLL_INSET:
1555 // this is not handled here as this funktion is only aktive
1556 // if we have a locking_inset and that one is (or contains)
1560 case LFUN_INSET_GRAPHICS:
1562 Inset * new_inset = new InsetGraphics;
1563 if (!insertInset(new_inset)) {
1566 // this is need because you don't use a inset->Edit()
1567 updateInset(new_inset, true);
1568 new_inset->edit(bv_);
1578 case LFUN_PASTESELECTION:
1580 bool asPara = false;
1581 if (argument == "paragraph")
1583 pasteClipboard(asPara);
1595 case LFUN_LAYOUT_COPY:
1596 bv_->copyEnvironment();
1599 case LFUN_LAYOUT_PASTE:
1600 bv_->pasteEnvironment();
1604 case LFUN_GOTOERROR:
1605 gotoInset(Inset::ERROR_CODE, false);
1609 gotoInset(Inset::IGNORE_CODE, false);
1612 case LFUN_REFERENCE_GOTO:
1614 vector<Inset::Code> tmp;
1615 tmp.push_back(Inset::LABEL_CODE);
1616 tmp.push_back(Inset::REF_CODE);
1617 gotoInset(tmp, true);
1621 case LFUN_HYPHENATION:
1622 specialChar(InsetSpecialChar::HYPHENATION);
1625 case LFUN_LIGATURE_BREAK:
1626 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1630 specialChar(InsetSpecialChar::LDOTS);
1633 case LFUN_END_OF_SENTENCE:
1634 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1637 case LFUN_MENU_SEPARATOR:
1638 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1646 changeDepth(bv_, bv_->getLyXText(), 0);
1649 case LFUN_DEPTH_MIN:
1650 changeDepth(bv_, bv_->getLyXText(), -1);
1653 case LFUN_DEPTH_PLUS:
1654 changeDepth(bv_, bv_->getLyXText(), 1);
1658 owner_->getDialogs()->setUserFreeFont();
1661 case LFUN_FILE_INSERT:
1662 MenuInsertLyXFile(argument);
1665 case LFUN_FILE_INSERT_ASCII_PARA:
1666 InsertAsciiFile(bv_, argument, true);
1669 case LFUN_FILE_INSERT_ASCII:
1670 InsertAsciiFile(bv_, argument, false);
1675 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1676 << argument << endl;
1678 // Derive layout number from given argument (string)
1679 // and current buffer's textclass (number). */
1680 textclass_type tclass = buffer_->params.textclass;
1681 pair <bool, layout_type> layout =
1682 textclasslist.NumberOfLayout(tclass, argument);
1684 // If the entry is obsolete, use the new one instead.
1686 string obs = textclasslist.Style(tclass, layout.second)
1689 layout = textclasslist.NumberOfLayout(tclass, obs);
1692 // see if we found the layout number:
1693 if (!layout.first) {
1694 owner_->getLyXFunc()->setErrorMessage(
1695 string(N_("Layout ")) + argument +
1700 if (current_layout != layout.second) {
1701 LyXText * lt = bv_->getLyXText();
1703 current_layout = layout.second;
1706 | BufferView::FITCUR);
1707 lt->setLayout(bv_, layout.second);
1708 owner_->setLayout(layout.second);
1711 | BufferView::FITCUR
1712 | BufferView::CHANGE);
1719 lang(bv_, argument);
1721 owner_->showState();
1726 owner_->showState();
1731 owner_->showState();
1736 owner_->showState();
1741 owner_->showState();
1746 owner_->showState();
1751 owner_->showState();
1756 owner_->showState();
1759 case LFUN_UNDERLINE:
1761 owner_->showState();
1764 case LFUN_FONT_SIZE:
1765 fontSize(bv_, argument);
1766 owner_->showState();
1769 case LFUN_FONT_STATE:
1770 owner_->getLyXFunc()->setMessage(currentState(bv_));
1773 case LFUN_UPCASE_WORD:
1775 LyXText * lt = bv_->getLyXText();
1779 | BufferView::FITCUR);
1780 lt->changeCase(bv_, LyXText::text_uppercase);
1781 if (lt->inset_owner)
1782 updateInset(lt->inset_owner, true);
1785 | BufferView::FITCUR
1786 | BufferView::CHANGE);
1790 case LFUN_LOWCASE_WORD:
1792 LyXText * lt = bv_->getLyXText();
1794 update(lt, BufferView::SELECT|BufferView::FITCUR);
1795 lt->changeCase(bv_, LyXText::text_lowercase);
1796 if (lt->inset_owner)
1797 updateInset(lt->inset_owner, true);
1800 | BufferView::FITCUR
1801 | BufferView::CHANGE);
1805 case LFUN_CAPITALIZE_WORD:
1807 LyXText * lt = bv_->getLyXText();
1809 update(lt, BufferView::SELECT|BufferView::FITCUR);
1810 lt->changeCase(bv_, LyXText::text_capitalization);
1811 if (lt->inset_owner)
1812 updateInset(lt->inset_owner, true);
1815 | BufferView::FITCUR
1816 | BufferView::CHANGE);
1820 case LFUN_TRANSPOSE_CHARS:
1822 LyXText * lt = bv_->getLyXText();
1824 update(lt, BufferView::SELECT|BufferView::FITCUR);
1825 lt->transposeChars(*bv_);
1826 if (lt->inset_owner)
1827 updateInset(lt->inset_owner, true);
1830 | BufferView::FITCUR
1831 | BufferView::CHANGE);
1836 case LFUN_INSERT_LABEL:
1837 MenuInsertLabel(bv_, argument);
1840 case LFUN_REF_INSERT:
1841 if (argument.empty()) {
1842 InsetCommandParams p("ref");
1843 owner_->getDialogs()->createRef(p.getAsString());
1845 InsetCommandParams p;
1846 p.setFromString(argument);
1848 InsetRef * inset = new InsetRef(p, *buffer_);
1849 if (!insertInset(inset))
1852 updateInset(inset, true);
1856 case LFUN_BOOKMARK_SAVE:
1857 savePosition(strToUnsignedInt(argument));
1860 case LFUN_BOOKMARK_GOTO:
1861 restorePosition(strToUnsignedInt(argument));
1866 string label(argument);
1867 if (label.empty()) {
1869 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1871 label = inset->getContents();
1876 if (!label.empty()) {
1877 //bv_->savePosition(0);
1878 if (!bv_->gotoLabel(label))
1879 Alert::alert(_("Error"),
1880 _("Couldn't find this label"),
1881 _("in current document."));
1886 // --- Cursor Movements -----------------------------
1889 LyXText * lt = bv_->getLyXText();
1891 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1892 if (!lt->selection.mark())
1894 update(lt, BufferView::SELECT|BufferView::FITCUR);
1896 lt->cursorLeft(bv_, false);
1897 if (lt->cursor.pos() < lt->cursor.par()->size()
1898 && lt->cursor.par()->isInset(lt->cursor.pos())
1899 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1900 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1901 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1903 tmpinset->edit(bv_, false);
1905 tmpinset->edit(bv_);
1909 lt->cursorRight(bv_, false);
1911 moveCursorUpdate(false);
1912 owner_->showState();
1918 // This is soooo ugly. Isn`t it possible to make
1919 // it simpler? (Lgb)
1920 LyXText * lt = bv_->getLyXText();
1921 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1922 if (!lt->selection.mark())
1924 update(lt, BufferView::SELECT|BufferView::FITCUR);
1925 LyXCursor const cur = lt->cursor;
1927 lt->cursorLeft(bv_, false);
1928 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1929 lt->cursor.pos() < lt->cursor.par()->size() &&
1930 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1931 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1932 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1933 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1935 tmpinset->edit(bv_);
1937 tmpinset->edit(bv_, false);
1941 lt->cursorRight(bv_, false);
1944 moveCursorUpdate(false);
1945 owner_->showState();
1951 LyXText * lt = bv_->getLyXText();
1953 if (!lt->selection.mark())
1955 update(lt, BufferView::UPDATE);
1958 moveCursorUpdate(false);
1959 owner_->showState();
1965 LyXText * lt = bv_->getLyXText();
1967 if (!lt->selection.mark())
1969 update(lt, BufferView::UPDATE);
1970 lt->cursorDown(bv_);
1972 moveCursorUpdate(false);
1973 owner_->showState();
1977 case LFUN_UP_PARAGRAPH:
1979 LyXText * lt = bv_->getLyXText();
1981 if (!lt->selection.mark())
1983 update(lt, BufferView::UPDATE);
1984 lt->cursorUpParagraph(bv_);
1986 moveCursorUpdate(false);
1987 owner_->showState();
1991 case LFUN_DOWN_PARAGRAPH:
1993 LyXText * lt = bv_->getLyXText();
1995 if (!lt->selection.mark())
1997 update(lt, BufferView::UPDATE);
1998 lt->cursorDownParagraph(bv_);
2000 moveCursorUpdate(false);
2001 owner_->showState();
2007 LyXText * lt = bv_->getLyXText();
2009 if (!lt->selection.mark())
2011 update(lt, BufferView::UPDATE);
2014 moveCursorUpdate(false);
2015 owner_->showState();
2021 LyXText * lt = bv_->getLyXText();
2023 if (!lt->selection.mark())
2025 update(lt, BufferView::UPDATE);
2028 moveCursorUpdate(false);
2029 owner_->showState();
2035 LyXText * lt = bv_->getLyXText();
2037 if (!lt->selection.mark())
2039 update(lt, BufferView::SELECT|BufferView::FITCUR);
2040 lt->cursorHome(bv_);
2042 moveCursorUpdate(false);
2043 owner_->showState();
2049 LyXText * lt = bv_->getLyXText();
2051 if (!lt->selection.mark())
2054 BufferView::SELECT|BufferView::FITCUR);
2057 moveCursorUpdate(false);
2058 owner_->showState();
2062 case LFUN_SHIFT_TAB:
2065 LyXText * lt = bv_->getLyXText();
2067 if (!lt->selection.mark())
2070 BufferView::SELECT|BufferView::FITCUR);
2073 moveCursorUpdate(false);
2074 owner_->showState();
2078 case LFUN_WORDRIGHT:
2080 LyXText * lt = bv_->getLyXText();
2082 if (!lt->selection.mark())
2084 update(lt, BufferView::SELECT|BufferView::FITCUR);
2085 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2086 lt->cursorLeftOneWord(bv_);
2088 lt->cursorRightOneWord(bv_);
2090 moveCursorUpdate(false);
2091 owner_->showState();
2097 LyXText * lt = bv_->getLyXText();
2099 if (!lt->selection.mark())
2101 update(lt, BufferView::SELECT|BufferView::FITCUR);
2102 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2103 lt->cursorRightOneWord(bv_);
2105 lt->cursorLeftOneWord(bv_);
2107 moveCursorUpdate(false);
2108 owner_->showState();
2112 case LFUN_BEGINNINGBUF:
2114 LyXText * lt = bv_->getLyXText();
2116 if (!lt->selection.mark())
2119 BufferView::SELECT|BufferView::FITCUR);
2122 moveCursorUpdate(false);
2123 owner_->showState();
2129 LyXText * lt = bv_->getLyXText();
2131 if (!lt->selection.mark())
2134 BufferView::SELECT|BufferView::FITCUR);
2135 lt->cursorBottom(bv_);
2137 moveCursorUpdate(false);
2138 owner_->showState();
2142 /* cursor selection ---------------------------- */
2145 LyXText * lt = bv_->getLyXText();
2148 BufferView::SELECT|BufferView::FITCUR);
2149 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2150 lt->cursorLeft(bv_);
2152 lt->cursorRight(bv_);
2154 moveCursorUpdate(true);
2155 owner_->showState();
2161 LyXText * lt = bv_->getLyXText();
2164 BufferView::SELECT|BufferView::FITCUR);
2165 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2166 lt->cursorRight(bv_);
2168 lt->cursorLeft(bv_);
2170 moveCursorUpdate(true);
2171 owner_->showState();
2177 LyXText * lt = bv_->getLyXText();
2180 BufferView::SELECT|BufferView::FITCUR);
2183 moveCursorUpdate(true);
2184 owner_->showState();
2190 LyXText * lt = bv_->getLyXText();
2193 BufferView::SELECT|BufferView::FITCUR);
2194 lt->cursorDown(bv_);
2196 moveCursorUpdate(true);
2197 owner_->showState();
2201 case LFUN_UP_PARAGRAPHSEL:
2203 LyXText * lt = bv_->getLyXText();
2206 BufferView::SELECT|BufferView::FITCUR);
2207 lt->cursorUpParagraph(bv_);
2209 moveCursorUpdate(true);
2210 owner_->showState();
2214 case LFUN_DOWN_PARAGRAPHSEL:
2216 LyXText * lt = bv_->getLyXText();
2219 BufferView::SELECT|BufferView::FITCUR);
2220 lt->cursorDownParagraph(bv_);
2222 moveCursorUpdate(true);
2223 owner_->showState();
2229 LyXText * lt = bv_->getLyXText();
2231 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 moveCursorUpdate(true);
2235 owner_->showState();
2241 LyXText * lt = bv_->getLyXText();
2243 update(lt, BufferView::SELECT|BufferView::FITCUR);
2246 moveCursorUpdate(true);
2247 owner_->showState();
2253 LyXText * lt = bv_->getLyXText();
2255 update(lt, BufferView::SELECT|BufferView::FITCUR);
2256 lt->cursorHome(bv_);
2258 moveCursorUpdate(true);
2259 owner_->showState();
2265 LyXText * lt = bv_->getLyXText();
2267 update(lt, BufferView::SELECT|BufferView::FITCUR);
2270 moveCursorUpdate(true);
2271 owner_->showState();
2275 case LFUN_WORDRIGHTSEL:
2277 LyXText * lt = bv_->getLyXText();
2279 update(lt, BufferView::SELECT|BufferView::FITCUR);
2280 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2281 lt->cursorLeftOneWord(bv_);
2283 lt->cursorRightOneWord(bv_);
2285 moveCursorUpdate(true);
2286 owner_->showState();
2290 case LFUN_WORDLEFTSEL:
2292 LyXText * lt = bv_->getLyXText();
2294 update(lt, BufferView::SELECT|BufferView::FITCUR);
2295 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2296 lt->cursorRightOneWord(bv_);
2298 lt->cursorLeftOneWord(bv_);
2300 moveCursorUpdate(true);
2301 owner_->showState();
2305 case LFUN_BEGINNINGBUFSEL:
2307 LyXText * lt = bv_->getLyXText();
2309 if (lt->inset_owner)
2311 update(lt, BufferView::SELECT|BufferView::FITCUR);
2314 moveCursorUpdate(true);
2315 owner_->showState();
2319 case LFUN_ENDBUFSEL:
2321 LyXText * lt = bv_->getLyXText();
2323 if (lt->inset_owner)
2326 BufferView::SELECT|BufferView::FITCUR);
2327 lt->cursorBottom(bv_);
2329 moveCursorUpdate(true);
2330 owner_->showState();
2334 // --- text changing commands ------------------------
2335 case LFUN_BREAKLINE:
2337 LyXText * lt = bv_->getLyXText();
2340 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2343 | BufferView::FITCUR
2344 | BufferView::CHANGE);
2345 moveCursorUpdate(false);
2349 case LFUN_PROTECTEDSPACE:
2351 LyXText * lt = bv_->getLyXText();
2353 LyXLayout const & style = textclasslist
2354 .Style(buffer_->params.textclass,
2355 lt->cursor.par()->getLayout());
2357 if (style.free_spacing) {
2358 lt->insertChar(bv_, ' ');
2361 | BufferView::FITCUR
2362 | BufferView::CHANGE);
2366 moveCursorUpdate(false);
2372 LyXText * lt = bv_->getLyXText();
2374 if (lt->selection.mark()) {
2378 | BufferView::FITCUR);
2379 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2382 lt->selection.mark(true);
2385 | BufferView::FITCUR);
2386 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2388 lt->selection.cursor = lt->cursor;
2394 LyXText * lt = bv_->getLyXText();
2396 if (!lt->selection.set()) {
2398 lt->selection.cursor = lt->cursor;
2401 | BufferView::FITCUR
2402 | BufferView::CHANGE);
2403 // It is possible to make it a lot faster still
2404 // just comment out the line below...
2409 moveCursorUpdate(false);
2410 owner_->showState();
2415 case LFUN_DELETE_SKIP:
2417 LyXText * lt = bv_->getLyXText();
2419 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2421 LyXCursor cursor = lt->cursor;
2423 if (!lt->selection.set()) {
2424 if (cursor.pos() == cursor.par()->size()) {
2425 lt->cursorRight(bv_);
2426 cursor = lt->cursor;
2427 if (cursor.pos() == 0
2428 && !(cursor.par()->params().spaceTop()
2429 == VSpace (VSpace::NONE))) {
2432 cursor.par()->params().lineTop(),
2433 cursor.par()->params().lineBottom(),
2434 cursor.par()->params().pagebreakTop(),
2435 cursor.par()->params().pagebreakBottom(),
2436 VSpace(VSpace::NONE),
2437 cursor.par()->params().spaceBottom(),
2438 cursor.par()->params().spacing(),
2439 cursor.par()->params().align(),
2440 cursor.par()->params().labelWidthString(), 0);
2441 lt->cursorLeft(bv_);
2444 | BufferView::FITCUR
2445 | BufferView::CHANGE);
2447 lt->cursorLeft(bv_);
2449 lt->selection.cursor = lt->cursor;
2452 | BufferView::FITCUR
2453 | BufferView::CHANGE);
2457 lt->selection.cursor = lt->cursor;
2460 | BufferView::FITCUR
2461 | BufferView::CHANGE);
2469 /* -------> Delete word forward. */
2470 case LFUN_DELETE_WORD_FORWARD:
2471 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2472 bv_->getLyXText()->deleteWordForward(bv_);
2473 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2474 moveCursorUpdate(false);
2475 owner_->showState();
2478 /* -------> Delete word backward. */
2479 case LFUN_DELETE_WORD_BACKWARD:
2481 LyXText * lt = bv_->getLyXText();
2483 update(lt, BufferView::SELECT|BufferView::FITCUR);
2484 lt->deleteWordBackward(bv_);
2487 | BufferView::FITCUR
2488 | BufferView::CHANGE);
2489 moveCursorUpdate(false);
2490 owner_->showState();
2494 /* -------> Kill to end of line. */
2495 case LFUN_DELETE_LINE_FORWARD:
2497 LyXText * lt = bv_->getLyXText();
2499 update(lt, BufferView::SELECT|BufferView::FITCUR);
2500 lt->deleteLineForward(bv_);
2503 | BufferView::FITCUR
2504 | BufferView::CHANGE);
2505 moveCursorUpdate(false);
2509 /* -------> Set mark off. */
2512 LyXText * lt = bv_->getLyXText();
2515 update(lt, BufferView::SELECT|BufferView::FITCUR);
2516 lt->selection.cursor = lt->cursor;
2517 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2521 /* -------> Set mark on. */
2524 LyXText * lt = bv_->getLyXText();
2527 lt->selection.mark(true);
2528 update(lt, BufferView::SELECT|BufferView::FITCUR);
2529 lt->selection.cursor = lt->cursor;
2530 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2534 case LFUN_BACKSPACE:
2536 LyXText * lt = bv_->getLyXText();
2538 if (!lt->selection.set()) {
2539 if (owner_->getIntl()->getTrans().backspace()) {
2541 lt->selection.cursor = lt->cursor;
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2546 // It is possible to make it a lot faster still
2547 // just comment out the line below...
2553 owner_->showState();
2558 case LFUN_BACKSPACE_SKIP:
2560 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2561 LyXText * lt = bv_->getLyXText();
2563 LyXCursor cursor = lt->cursor;
2565 if (!lt->selection.set()) {
2566 if (cursor.pos() == 0
2567 && !(cursor.par()->params().spaceTop()
2568 == VSpace (VSpace::NONE))) {
2571 cursor.par()->params().lineTop(),
2572 cursor.par()->params().lineBottom(),
2573 cursor.par()->params().pagebreakTop(),
2574 cursor.par()->params().pagebreakBottom(),
2575 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2576 cursor.par()->params().spacing(),
2577 cursor.par()->params().align(),
2578 cursor.par()->params().labelWidthString(), 0);
2581 | BufferView::FITCUR
2582 | BufferView::CHANGE);
2585 lt->selection.cursor = cursor;
2588 | BufferView::FITCUR
2589 | BufferView::CHANGE);
2596 case LFUN_BREAKPARAGRAPH:
2598 LyXText * lt = bv_->getLyXText();
2601 lt->breakParagraph(bv_, 0);
2604 | BufferView::FITCUR
2605 | BufferView::CHANGE);
2606 lt->selection.cursor = lt->cursor;
2608 owner_->showState();
2612 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2614 LyXText * lt = bv_->getLyXText();
2617 lt->breakParagraph(bv_, 1);
2620 | BufferView::FITCUR
2621 | BufferView::CHANGE);
2622 lt->selection.cursor = lt->cursor;
2624 owner_->showState();
2628 case LFUN_BREAKPARAGRAPH_SKIP:
2630 // When at the beginning of a paragraph, remove
2631 // indentation and add a "defskip" at the top.
2632 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2633 LyXText * lt = bv_->getLyXText();
2635 LyXCursor cursor = lt->cursor;
2638 if (cursor.pos() == 0) {
2639 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2642 cursor.par()->params().lineTop(),
2643 cursor.par()->params().lineBottom(),
2644 cursor.par()->params().pagebreakTop(),
2645 cursor.par()->params().pagebreakBottom(),
2646 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2647 cursor.par()->params().spacing(),
2648 cursor.par()->params().align(),
2649 cursor.par()->params().labelWidthString(), 1);
2650 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2654 lt->breakParagraph(bv_, 0);
2655 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2660 | BufferView::FITCUR
2661 | BufferView::CHANGE);
2662 lt->selection.cursor = cursor;
2664 owner_->showState();
2668 case LFUN_PARAGRAPH_SPACING:
2670 LyXText * lt = bv_->getLyXText();
2672 Paragraph * par = lt->cursor.par();
2673 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2674 float cur_value = 1.0;
2675 if (cur_spacing == Spacing::Other) {
2676 cur_value = par->params().spacing().getValue();
2679 istringstream istr(argument.c_str());
2683 Spacing::Space new_spacing = cur_spacing;
2684 float new_value = cur_value;
2686 lyxerr << "Missing argument to `paragraph-spacing'"
2688 } else if (tmp == "single") {
2689 new_spacing = Spacing::Single;
2690 } else if (tmp == "onehalf") {
2691 new_spacing = Spacing::Onehalf;
2692 } else if (tmp == "double") {
2693 new_spacing = Spacing::Double;
2694 } else if (tmp == "other") {
2695 new_spacing = Spacing::Other;
2698 lyxerr << "new_value = " << tmpval << endl;
2701 } else if (tmp == "default") {
2702 new_spacing = Spacing::Default;
2704 lyxerr << _("Unknown spacing argument: ")
2705 << argument << endl;
2707 if (cur_spacing != new_spacing || cur_value != new_value) {
2708 par->params().spacing(Spacing(new_spacing, new_value));
2709 lt->redoParagraph(bv_);
2712 | BufferView::FITCUR
2713 | BufferView::CHANGE);
2718 case LFUN_INSET_TOGGLE:
2720 LyXText * lt = bv_->getLyXText();
2723 update(lt, BufferView::SELECT|BufferView::FITCUR);
2724 lt->toggleInset(bv_);
2725 update(lt, BufferView::SELECT|BufferView::FITCUR);
2737 InsetCommandParams p;
2738 if (action == LFUN_HTMLURL)
2739 p.setCmdName("htmlurl");
2741 p.setCmdName("url");
2742 owner_->getDialogs()->createUrl(p.getAsString());
2746 case LFUN_INSERT_URL:
2748 InsetCommandParams p;
2749 p.setFromString(argument);
2751 InsetUrl * inset = new InsetUrl(p);
2752 if (!insertInset(inset))
2755 updateInset(inset, true);
2759 case LFUN_INSET_TEXT:
2760 insertAndEditInset(new InsetText);
2763 case LFUN_INSET_ERT:
2764 insertAndEditInset(new InsetERT);
2767 case LFUN_INSET_EXTERNAL:
2768 insertAndEditInset(new InsetExternal);
2771 case LFUN_INSET_FOOTNOTE:
2772 insertAndEditInset(new InsetFoot);
2775 case LFUN_INSET_MARGINAL:
2776 insertAndEditInset(new InsetMarginal);
2779 case LFUN_INSET_MINIPAGE:
2780 insertAndEditInset(new InsetMinipage);
2783 case LFUN_INSERT_NOTE:
2784 insertAndEditInset(new InsetNote);
2787 case LFUN_INSET_FLOAT:
2788 // check if the float type exist
2789 if (floatList.typeExist(argument)) {
2790 insertAndEditInset(new InsetFloat(argument));
2792 lyxerr << "Non-existent float type: "
2793 << argument << endl;
2797 case LFUN_INSET_WIDE_FLOAT:
2799 // check if the float type exist
2800 if (floatList.typeExist(argument)) {
2801 InsetFloat * new_inset = new InsetFloat(argument);
2802 new_inset->wide(true);
2803 if (insertInset(new_inset))
2804 new_inset->edit(bv_);
2808 lyxerr << "Non-existent float type: "
2809 << argument << endl;
2816 case LFUN_INSET_LIST:
2817 insertAndEditInset(new InsetList);
2820 case LFUN_INSET_THEOREM:
2821 insertAndEditInset(new InsetTheorem);
2825 case LFUN_INSET_CAPTION:
2827 // Do we have a locking inset...
2828 if (bv_->theLockingInset()) {
2829 lyxerr << "Locking inset code: "
2830 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2831 InsetCaption * new_inset = new InsetCaption;
2832 new_inset->setOwner(bv_->theLockingInset());
2833 new_inset->setAutoBreakRows(true);
2834 new_inset->setDrawFrame(0, InsetText::LOCKED);
2835 new_inset->setFrameColor(0, LColor::captionframe);
2836 if (insertInset(new_inset))
2837 new_inset->edit(bv_);
2844 case LFUN_INSET_TABULAR:
2848 if (!argument.empty())
2849 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2850 InsetTabular * new_inset =
2851 new InsetTabular(*buffer_, r, c);
2853 bv_->getLyXText()->real_current_font.isRightToLeft();
2854 if (!open_new_inset(new_inset, rtl))
2859 // --- lyxserver commands ----------------------------
2861 case LFUN_CHARATCURSOR:
2863 pos_type pos = bv_->getLyXText()->cursor.pos();
2864 if (pos < bv_->getLyXText()->cursor.par()->size())
2865 owner_->getLyXFunc()->setMessage(
2866 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2868 owner_->getLyXFunc()->setMessage("EOF");
2873 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2875 + tostr(bv_->getLyXText()->cursor.y()));
2882 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2883 lyxerr << "SETXY: Could not parse coordinates in '"
2884 << argument << std::endl;
2886 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2890 case LFUN_GETLAYOUT:
2891 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2896 LyXFont & font = bv_->getLyXText()->current_font;
2897 if (font.shape() == LyXFont::ITALIC_SHAPE)
2898 owner_->getLyXFunc()->setMessage("E");
2899 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2900 owner_->getLyXFunc()->setMessage("N");
2902 owner_->getLyXFunc()->setMessage("0");
2907 // --- accented characters ---------------------------
2910 case LFUN_CIRCUMFLEX:
2920 case LFUN_SPECIAL_CARON:
2923 case LFUN_HUNG_UMLAUT:
2926 if (argument.empty()) {
2928 owner_->getLyXFunc()->handleKeyFunc(action);
2930 owner_->getLyXFunc()->handleKeyFunc(action);
2931 owner_->getIntl()->getTrans()
2932 .TranslateAndInsert(argument[0], bv_->getLyXText());
2933 update(bv_->getLyXText(),
2935 | BufferView::FITCUR
2936 | BufferView::CHANGE);
2940 case LFUN_MATH_MACRO:
2941 mathDispatchMathMacro(bv_, argument);
2944 case LFUN_MATH_DELIM:
2945 mathDispatchMathDelim(bv_, argument);
2948 case LFUN_INSERT_MATRIX:
2949 mathDispatchInsertMatrix(bv_, argument);
2952 case LFUN_INSERT_MATH:
2953 mathDispatchInsertMath(bv_, argument);
2956 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2957 mathDispatchMathImportSelection(bv_, argument);
2960 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2961 mathDispatchMathDisplay(bv_, argument);
2964 case LFUN_MATH_MODE: // Open or create an inlined math inset
2965 mathDispatchMathMode(bv_, argument);
2968 case LFUN_GREEK: // Insert a single greek letter
2969 mathDispatchGreek(bv_, argument);
2972 case LFUN_CITATION_INSERT:
2974 InsetCommandParams p;
2975 p.setFromString(argument);
2977 InsetCitation * inset = new InsetCitation(p);
2978 if (!insertInset(inset))
2981 updateInset(inset, true);
2985 case LFUN_INSERT_BIBTEX:
2987 // ale970405+lasgoutt970425
2988 // The argument can be up to two tokens separated
2989 // by a space. The first one is the bibstyle.
2990 string const db = token(argument, ' ', 0);
2991 string const bibstyle = token(argument, ' ', 1);
2993 InsetCommandParams p("BibTeX", db, bibstyle);
2994 InsetBibtex * inset = new InsetBibtex(p);
2996 if (insertInset(inset)) {
2997 if (argument.empty())
3004 // BibTeX data bases
3005 case LFUN_BIBDB_ADD:
3007 InsetBibtex * inset =
3008 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3010 inset->addDatabase(argument);
3015 case LFUN_BIBDB_DEL:
3017 InsetBibtex * inset =
3018 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3020 inset->delDatabase(argument);
3025 case LFUN_BIBTEX_STYLE:
3027 InsetBibtex * inset =
3028 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3030 inset->setOptions(argument);
3035 case LFUN_INDEX_CREATE:
3037 InsetCommandParams p("index");
3038 if (argument.empty()) {
3039 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3040 p.setContents(idxstring);
3042 p.setContents(argument);
3045 owner_->getDialogs()->createIndex(p.getAsString());
3049 case LFUN_INDEX_INSERT:
3051 InsetCommandParams p;
3052 p.setFromString(argument);
3053 InsetIndex * inset = new InsetIndex(p);
3055 if (!insertInset(inset))
3058 updateInset(inset, true);
3062 case LFUN_INDEX_INSERT_LAST:
3064 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3065 if (!idxstring.empty()) {
3066 owner_->message(_("Word `")
3067 + idxstring + _(("' indexed.")));
3068 InsetCommandParams p("index", idxstring);
3069 InsetIndex * inset = new InsetIndex(p);
3071 if (!insertInset(inset))
3074 updateInset(inset, true);
3079 case LFUN_INDEX_PRINT:
3081 InsetCommandParams p("printindex");
3082 Inset * inset = new InsetPrintIndex(p);
3083 if (!insertInset(inset, "Standard"))
3088 case LFUN_PARENTINSERT:
3090 lyxerr << "arg " << argument << endl;
3091 InsetCommandParams p("lyxparent", argument);
3092 Inset * inset = new InsetParent(p, *buffer_);
3093 if (!insertInset(inset, "Standard"))
3099 case LFUN_CHILD_INSERT:
3101 InsetInclude::Params p;
3102 p.cparams.setFromString(argument);
3103 p.masterFilename_ = buffer_->fileName();
3105 InsetInclude * inset = new InsetInclude(p);
3106 if (!insertInset(inset))
3109 updateInset(inset, true);
3110 bv_->owner()->getDialogs()->showInclude(inset);
3115 case LFUN_FLOAT_LIST:
3117 // We should check the argument for validity. (Lgb)
3118 Inset * inset = new InsetFloatList(argument);
3119 if (!insertInset(inset, "Standard"))
3124 case LFUN_THESAURUS_ENTRY:
3126 string arg = argument;
3129 arg = bv_->getLyXText()->selectionAsString(buffer_,
3133 if (arg.size() > 100 || arg.empty()) {
3134 // Get word or selection
3135 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3136 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3137 // FIXME: where is getLyXText()->unselect(bv_) ?
3141 bv_->owner()->getDialogs()->showThesaurus(arg);
3145 case LFUN_SELFINSERT:
3147 if (argument.empty()) break;
3149 /* Automatically delete the currently selected
3150 * text and replace it with what is being
3151 * typed in now. Depends on lyxrc settings
3152 * "auto_region_delete", which defaults to
3155 LyXText * lt = bv_->getLyXText();
3157 if (lyxrc.auto_region_delete) {
3158 if (lt->selection.set()) {
3159 lt->cutSelection(bv_, false, false);
3162 | BufferView::FITCUR
3163 | BufferView::CHANGE);
3168 LyXFont const old_font(lt->real_current_font);
3170 string::const_iterator cit = argument.begin();
3171 string::const_iterator end = argument.end();
3172 for (; cit != end; ++cit) {
3173 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3178 | BufferView::FITCUR
3179 | BufferView::CHANGE);
3181 lt->selection.cursor = lt->cursor;
3182 moveCursorUpdate(false);
3184 // real_current_font.number can change so we need to
3185 // update the minibuffer
3186 if (old_font != lt->real_current_font)
3187 owner_->showState();
3192 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3194 time_t now_time_t = time(NULL);
3195 struct tm * now_tm = localtime(&now_time_t);
3196 setlocale(LC_TIME, "");
3198 if (!argument.empty())
3201 arg = lyxrc.date_insert_format;
3203 int const datetmp_len =
3204 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3206 LyXText * lt = bv_->getLyXText();
3208 for (int i = 0; i < datetmp_len; i++) {
3209 lt->insertChar(bv_, datetmp[i]);
3212 | BufferView::FITCUR
3213 | BufferView::CHANGE);
3216 lt->selection.cursor = lt->cursor;
3217 moveCursorUpdate(false);
3221 case LFUN_UNKNOWN_ACTION:
3222 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3233 void BufferView::Pimpl::newline()
3236 LyXText * lt = bv_->getLyXText();
3240 | BufferView::FITCUR);
3241 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3244 | BufferView::FITCUR
3245 | BufferView::CHANGE);
3250 void BufferView::Pimpl::hfill()
3253 LyXText * lt = bv_->getLyXText();
3257 | BufferView::FITCUR);
3258 lt->insertChar(bv_, Paragraph::META_HFILL);
3261 | BufferView::FITCUR
3262 | BufferView::CHANGE);
3267 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3271 update(lt, BufferView::SELECT|BufferView::FITCUR);
3272 InsetSpecialChar * new_inset =
3273 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3274 #ifdef WITH_WARNINGS
3275 #warning Why is this code different from specialChar() below? (JMarc)
3276 // the code in specialChar is a generic version of what used to exist
3277 // for other special chars. I did not merge this case because of the
3278 // call to updateInset(), but what does it do?
3280 if (!insertInset(new_inset))
3283 updateInset(new_inset, true);
3288 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3291 LyXText * lt = bv_->getLyXText();
3294 update(lt, BufferView::SELECT|BufferView::FITCUR);
3295 InsetSpecialChar * new_inset =
3296 new InsetSpecialChar(kind);
3297 if (!insertInset(new_inset))
3303 void BufferView::Pimpl::smartQuote()
3305 LyXText const * lt = bv_->getLyXText();
3306 Paragraph const * par = lt->cursor.par();
3307 pos_type pos = lt->cursor.pos();
3311 || (par->isInset(pos - 1)
3312 && par->getInset(pos - 1)->isSpace()))
3315 c = par->getChar(pos - 1);
3320 LyXLayout const & style = textclasslist.Style(
3321 bv_->buffer()->params.textclass, par->getLayout());
3323 if (style.pass_thru ||
3324 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3325 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3329 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3331 if (insertInset(inset))
3338 // Open and lock an updatable inset
3339 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3341 LyXText * lt = bv_->getLyXText();
3345 if (!insertInset(new_inset)) {
3349 new_inset->edit(bv_, !behind);
3354 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3356 // if we are in a locking inset we should try to insert the
3357 // inset there otherwise this is a illegal function now
3358 if (bv_->theLockingInset()) {
3359 if (bv_->theLockingInset()->insetAllowed(inset))
3360 return bv_->theLockingInset()->insertInset(bv_, inset);
3364 // not quite sure if we want this...
3365 setCursorParUndo(bv_);
3368 beforeChange(bv_->text);
3369 if (!lout.empty()) {
3370 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3371 bv_->text->breakParagraph(bv_);
3372 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3374 if (bv_->text->cursor.par()->size()) {
3375 bv_->text->cursorLeft(bv_);
3377 bv_->text->breakParagraph(bv_);
3378 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3381 pair<bool, layout_type> lres =
3382 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3383 layout_type lay = 0;
3384 if (lres.first != false) {
3388 // layout not fount using default "Standard" (0)
3392 bv_->text->setLayout(bv_, lay);
3394 bv_->text->setParagraph(bv_, 0, 0,
3396 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3401 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3404 bv_->text->insertInset(bv_, inset);
3405 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3412 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3417 // first check for locking insets
3418 if (bv_->theLockingInset()) {
3419 if (bv_->theLockingInset() == inset) {
3420 if (bv_->text->updateInset(bv_, inset)) {
3423 buffer_->markDirty();
3428 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3429 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3432 buffer_->markDirty();
3440 // then check the current buffer
3443 update(bv_->text, BufferView::UPDATE);
3444 if (bv_->text->updateInset(bv_, inset)) {
3448 | BufferView::FITCUR
3449 | BufferView::CHANGE);
3451 update(bv_->text, SELECT);
3459 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3462 if (!available()) return;
3465 beforeChange(bv_->text);
3466 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3468 LyXCursor const & cursor = bv_->text->cursor;
3472 cursor.par()->isInset(cursor.pos())) {
3473 Inset const * inset = cursor.par()->getInset(cursor.pos());
3474 if (find(codes.begin(), codes.end(), inset->lyxCode())
3477 static_cast<InsetCommand const *>(inset)->getContents();
3481 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3482 if (bv_->text->cursor.pos()
3483 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3484 LyXCursor tmp = bv_->text->cursor;
3485 bv_->text->cursor.par(bv_->text->ownerParagraph());
3486 bv_->text->cursor.pos(0);
3487 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3488 bv_->text->cursor = tmp;
3489 bv_->owner()->message(_("No more insets"));
3492 bv_->owner()->message(_("No more insets"));
3495 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3496 bv_->text->selection.cursor = bv_->text->cursor;
3500 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3502 gotoInset(vector<Inset::Code>(1, code), same_content);