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 // IMO the inset has to be first in edit-mode and then we send the
652 // button press. (Jug 20020222)
653 inset->edit(bv_); //, xpos, ypos, button);
654 inset->insetButtonPress(bv_, xpos, ypos, button);
658 // Right click on a footnote flag opens float menu
660 selection_possible = false;
664 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
665 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
667 bv_->text->selection.cursor = bv_->text->cursor;
668 bv_->text->cursor.x_fix(bv_->text->cursor.x());
670 owner_->updateLayoutChoice();
672 selection_possible = false;
675 // Insert primary selection with middle mouse
676 // if there is a local selection in the current buffer,
679 if (paste_internally)
680 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
682 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
684 selection_possible = false;
690 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
696 LyXText * text = bv_->getLyXText();
698 if (text->bv_owner && bv_->theLockingInset())
701 if (screen_.get() && button == 1) {
702 if (text->bv_owner) {
703 screen_->hideCursor();
704 screen_->toggleSelection(text, bv_);
705 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
706 screen_->toggleSelection(text, bv_, false);
708 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
710 /* This will fit the cursor on the screen
712 update(text, BufferView::SELECT|BufferView::FITCUR);
717 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
723 LyXText * text = bv_->getLyXText();
725 if (text->bv_owner && bv_->theLockingInset())
728 if (screen_.get() && (button == 1)) {
729 if (text->bv_owner) {
730 screen_->hideCursor();
731 screen_->toggleSelection(text, bv_);
733 text->cursorHome(bv_);
734 text->selection.cursor = text->cursor;
735 text->cursorEnd(bv_);
736 text->setSelection(bv_);
737 if (text->bv_owner) {
738 screen_->toggleSelection(text, bv_, false);
740 /* This will fit the cursor on the screen
742 update(text, BufferView::SELECT|BufferView::FITCUR);
747 void BufferView::Pimpl::selectionRequested()
752 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
755 workarea_.putClipboard(sel);
760 void BufferView::Pimpl::selectionLost()
764 bv_->getLyXText()->clearSelection();
769 void BufferView::Pimpl::enterView()
771 if (active() && available()) {
772 SetXtermCursor(workarea_.getWin());
773 using_xterm_cursor = true;
778 void BufferView::Pimpl::leaveView()
780 if (using_xterm_cursor) {
781 XUndefineCursor(fl_get_display(), workarea_.getWin());
782 using_xterm_cursor = false;
787 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
790 if (!buffer_ || !screen_.get()) return;
792 // If we hit an inset, we have the inset coordinates in these
793 // and inset_hit points to the inset. If we do not hit an
794 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
795 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
797 if (bv_->theLockingInset()) {
798 // We are in inset locking mode.
800 /* LyX does a kind of work-area grabbing for insets.
801 Only a ButtonPress Event outside the inset will
802 force a insetUnlock. */
803 bv_->theLockingInset()->
804 insetButtonRelease(bv_, x, y, button);
808 selection_possible = false;
815 workarea_.haveSelection(bv_->getLyXText()->selection.set());
820 owner_->updateMenubar();
821 owner_->updateToolbar();
823 // Did we hit an editable inset?
825 // Inset like error, notes and figures
826 selection_possible = false;
828 // if we reach this point with a selection, it
829 // must mean we are currently selecting.
830 // But we don't want to open the inset
831 // because that is annoying for the user.
832 // So just pretend we didn't hit it.
833 // this is OK because a "kosher" ButtonRelease
834 // will follow a ButtonPress that clears
836 // Note this also fixes selection drawing
837 // problems if we end up opening an inset
838 if (bv_->getLyXText()->selection.set())
841 // CHECK fix this proper in 0.13
842 // well, maybe 13.0 !!!!!!!!!
844 // Following a ref shouldn't issue
845 // a push on the undo-stack
846 // anylonger, now that we have
847 // keybindings for following
848 // references and returning from
849 // references. IMHO though, it
850 // should be the inset's own business
851 // to push or not push on the undo
852 // stack. They don't *have* to
853 // alter the document...
855 // ...or maybe the SetCursorParUndo()
856 // below isn't necessary at all anylonger?
857 if (inset_hit->lyxCode() == Inset::REF_CODE) {
858 setCursorParUndo(bv_);
861 owner_->message(inset_hit->editMessage());
863 if (isHighlyEditableInset(inset_hit)) {
864 // Highly editable inset, like math
865 UpdatableInset *inset = (UpdatableInset *)inset_hit;
866 inset->insetButtonRelease(bv_, x, y, button);
868 inset_hit->insetButtonRelease(bv_, x, y, button);
869 inset_hit->edit(bv_, x, y, button);
874 // Maybe we want to edit a bibitem ale970302
875 if (bv_->text->cursor.par()->bibkey && x < 20 +
876 bibitemMaxWidth(bv_, textclasslist.
878 params.textclass).defaultfont())) {
879 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
886 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
887 LyXCursor const & cursor) const
889 Paragraph /*const*/ & par = *cursor.par();
890 pos_type const pos = cursor.pos();
892 lyx::Assert(par.getInset(pos));
894 Inset const & inset(*par.getInset(pos));
896 LyXFont const & font = text.getFont(buffer_, &par, pos);
898 int const width = inset.width(bv_, font);
899 int const inset_x = font.isVisibleRightToLeft()
900 ? (cursor.x() - width) : cursor.x();
903 inset_x + inset.scroll(),
905 cursor.y() - inset.ascent(bv_, font),
906 cursor.y() + inset.descent(bv_, font));
910 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
911 LyXCursor const & cursor,
912 int & x, int & y) const
914 pos_type const pos(cursor.pos());
915 Paragraph /*const*/ & par(*cursor.par());
917 if (pos >= par.size() || !par.isInset(pos)) {
921 Inset /*const*/ * inset = par.getInset(pos);
923 if (!isEditableInset(inset)) {
927 Box b(insetDimensions(text, cursor));
929 if (!b.contained(x, y)) {
930 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
931 << " box " << b << endl;
935 text.setCursor(bv_, &par, pos, true);
938 // The origin of an inset is on the baseline
939 y -= (text.cursor.y());
945 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
950 int y_tmp = y + text->first;
953 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
955 Inset * inset(checkInset(*text, cursor, x, y_tmp));
962 // look at previous position
964 if (cursor.pos() == 0) {
969 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
971 inset = checkInset(*text, cursor, x, y_tmp);
979 void BufferView::Pimpl::workAreaExpose()
981 static int work_area_width;
982 static unsigned int work_area_height;
984 bool const widthChange = workarea_.workWidth() != work_area_width;
985 bool const heightChange = workarea_.height() != work_area_height;
987 // update from work area
988 work_area_width = workarea_.workWidth();
989 work_area_height = workarea_.height();
992 // The visible LyXView need a resize
995 // Remove all texts from the textcache
996 // This is not _really_ what we want to do. What
997 // we really want to do is to delete in textcache
998 // that does not have a BufferView with matching
999 // width, but as long as we have only one BufferView
1000 // deleting all gives the same result.
1001 if (lyxerr.debugging())
1002 textcache.show(lyxerr, "Expose delete all");
1004 } else if (heightChange) {
1005 // Rebuild image of current screen
1007 // fitCursor() ensures we don't jump back
1008 // to the start of the document on vertical
1012 // The main window size has changed, repaint most stuff
1014 } else if (screen_.get())
1015 screen_->redraw(bv_->text, bv_);
1017 // Grey box when we don't have a buffer
1018 workarea_.greyOut();
1021 // always make sure that the scrollbar is sane.
1023 owner_->updateLayoutChoice();
1028 void BufferView::Pimpl::update()
1030 if (screen_.get() &&
1031 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1033 LyXText::text_status st = bv_->text->status();
1034 screen_->update(bv_->text, bv_);
1036 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1037 if (bv_->text->fullRebreak(bv_)) {
1038 st = LyXText::NEED_MORE_REFRESH;
1039 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1040 bv_->text->cursor.pos());
1043 bv_->text->status(bv_, st);
1044 screen_->update(bv_->text, bv_);
1046 // do this here instead of in the screen::update because of
1048 bv_->text->status(bv_, LyXText::UNCHANGED);
1054 // Values used when calling update:
1056 // -2 - update, move sel_cursor if selection, fitcursor
1057 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1058 // 0 - update, move sel_cursor if selection, fitcursor
1059 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1060 // 3 - update, move sel_cursor if selection
1063 // a simple redraw of the parts that need refresh
1065 // move sel_cursor if selection -
1066 // the text's sel_cursor is moved if there is selection is progress
1069 // fitCursor() is called and the scrollbar updated
1072 // the buffer is marked dirty.
1081 // UPDATE_ONLY = UPDATE;
1082 // UPDATE_SELECT = UPDATE | SELECT;
1083 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1084 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1086 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1087 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1088 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1089 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1090 // update(3) -> update(1) -> update(1) -> update(SELECT)
1092 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1094 owner_->updateLayoutChoice();
1096 if (!text->selection.set() && (f & SELECT)) {
1097 text->selection.cursor = text->cursor;
1100 text->fullRebreak(bv_);
1102 if (text->inset_owner) {
1103 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1104 updateInset(text->inset_owner, false);
1114 buffer_->markDirty();
1119 // Callback for cursor timer
1120 void BufferView::Pimpl::cursorToggle()
1122 // Quite a nice place for asyncron Inset updating, isn't it?
1123 // Actually no! This is run even if no buffer exist... so (Lgb)
1125 cursor_timeout.restart();
1130 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1131 if (pid == -1) // error find out what is wrong
1132 ; // ignore it for now.
1134 sigchldchecker(pid, &status);
1136 updatelist.update(bv_);
1138 if (!screen_.get()) {
1139 cursor_timeout.restart();
1143 if (!bv_->theLockingInset()) {
1144 screen_->cursorToggle(bv_);
1146 bv_->theLockingInset()->toggleInsetCursor(bv_);
1149 cursor_timeout.restart();
1153 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1155 if (!text->cursor.row()->previous())
1158 int y = text->first;
1159 if (text->inset_owner)
1160 y += bv_->text->first;
1161 Row * cursorrow = text->cursor.row();
1162 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1164 // This is to allow jumping over large insets
1165 if ((cursorrow == text->cursor.row()))
1166 text->cursorUp(bv_);
1168 if (text->inset_owner ||
1169 text->cursor.row()->height() < workarea_.height())
1170 screen_->draw(bv_->text, bv_,
1172 - text->cursor.row()->baseline()
1173 + text->cursor.row()->height()
1174 - workarea_.height() + 1);
1179 void BufferView::Pimpl::cursorNext(LyXText * text)
1181 if (!text->cursor.row()->next())
1184 int y = text->first + workarea_.height();
1185 // if (text->inset_owner)
1186 // y += bv_->text->first;
1187 text->getRowNearY(y);
1189 Row * cursorrow = text->cursor.row();
1190 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1192 // This is to allow jumping over large insets
1193 if ((cursorrow == bv_->text->cursor.row()))
1194 text->cursorDown(bv_);
1196 if (text->inset_owner ||
1197 text->cursor.row()->height() < workarea_.height())
1198 screen_->draw(bv_->text, bv_, text->cursor.y() -
1199 text->cursor.row()->baseline());
1204 bool BufferView::Pimpl::available() const
1206 if (buffer_ && bv_->text) return true;
1211 void BufferView::Pimpl::beforeChange(LyXText * text)
1214 text->clearSelection();
1218 void BufferView::Pimpl::savePosition(unsigned int i)
1220 if (i >= saved_positions_num)
1222 saved_positions[i] = Position(buffer_->fileName(),
1223 bv_->text->cursor.par()->id(),
1224 bv_->text->cursor.pos());
1227 str << _("Saved bookmark") << ' ' << i;
1228 owner_->message(str.str().c_str());
1233 void BufferView::Pimpl::restorePosition(unsigned int i)
1235 if (i >= saved_positions_num)
1238 string const fname = saved_positions[i].filename;
1240 beforeChange(bv_->text);
1242 if (fname != buffer_->fileName()) {
1243 Buffer * b = bufferlist.exists(fname) ?
1244 bufferlist.getBuffer(fname) :
1245 bufferlist.loadLyXFile(fname); // don't ask, just load it
1246 if (b != 0) buffer(b);
1249 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1253 bv_->text->setCursor(bv_, par,
1254 min(par->size(), saved_positions[i].par_pos));
1256 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1259 str << _("Moved to bookmark") << ' ' << i;
1260 owner_->message(str.str().c_str());
1265 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1267 if (i >= saved_positions_num)
1270 return !saved_positions[i].filename.empty();
1274 void BufferView::Pimpl::setState()
1276 if (!lyxrc.rtl_support)
1279 LyXText * text = bv_->getLyXText();
1280 if (text->real_current_font.isRightToLeft()) {
1281 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1282 owner_->getIntl()->KeyMapSec();
1284 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1285 owner_->getIntl()->KeyMapPrim();
1290 void BufferView::Pimpl::insetSleep()
1292 if (bv_->theLockingInset() && !inset_slept) {
1293 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1294 bv_->theLockingInset()->insetUnlock(bv_);
1300 void BufferView::Pimpl::insetWakeup()
1302 if (bv_->theLockingInset() && inset_slept) {
1303 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1304 inset_slept = false;
1309 void BufferView::Pimpl::insetUnlock()
1311 if (bv_->theLockingInset()) {
1313 bv_->theLockingInset()->insetUnlock(bv_);
1314 bv_->theLockingInset(0);
1316 inset_slept = false;
1321 bool BufferView::Pimpl::focus() const
1323 return workarea_.hasFocus();
1327 void BufferView::Pimpl::focus(bool f)
1329 if (f) workarea_.setFocus();
1333 bool BufferView::Pimpl::active() const
1335 return workarea_.active();
1339 bool BufferView::Pimpl::belowMouse() const
1341 return workarea_.belowMouse();
1345 void BufferView::Pimpl::showCursor()
1347 if (screen_.get()) {
1348 if (bv_->theLockingInset())
1349 bv_->theLockingInset()->showInsetCursor(bv_);
1351 screen_->showCursor(bv_->text, bv_);
1356 void BufferView::Pimpl::hideCursor()
1358 if (screen_.get()) {
1359 if (!bv_->theLockingInset())
1360 // bv_->theLockingInset()->hideInsetCursor(bv_);
1362 screen_->hideCursor();
1367 void BufferView::Pimpl::toggleSelection(bool b)
1369 if (screen_.get()) {
1370 if (bv_->theLockingInset())
1371 bv_->theLockingInset()->toggleSelection(bv_, b);
1372 screen_->toggleSelection(bv_->text, bv_, b);
1377 void BufferView::Pimpl::toggleToggle()
1380 screen_->toggleToggle(bv_->text, bv_);
1384 void BufferView::Pimpl::center()
1386 beforeChange(bv_->text);
1387 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1388 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1390 screen_->draw(bv_->text, bv_, 0);
1392 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1397 void BufferView::Pimpl::pasteClipboard(bool asPara)
1399 if (!buffer_) return;
1401 screen_->hideCursor();
1402 beforeChange(bv_->text);
1404 string const clip(workarea_.getClipboard());
1406 if (clip.empty()) return;
1409 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1411 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1413 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1417 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1419 workarea_.putClipboard(stuff);
1424 * Dispatch functions for actions which can be valid for BufferView->text
1425 * and/or InsetText->text!!!
1430 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1432 LyXText * lt = bv_->getLyXText();
1434 if (selecting || lt->selection.mark()) {
1435 lt->setSelection(bv_);
1439 update(lt, BufferView::SELECT|BufferView::FITCUR);
1442 /* ---> Everytime the cursor is moved, show the current font state. */
1443 // should this too me moved out of this func?
1444 //owner->showState();
1449 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1451 LyXCursor cursor = bv_->getLyXText()->cursor;
1452 Buffer::inset_iterator it =
1453 find_if(Buffer::inset_iterator(
1454 cursor.par(), cursor.pos()),
1455 buffer_->inset_iterator_end(),
1456 lyx::compare_memfun(&Inset::lyxCode, code));
1457 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1461 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1463 string filename = filen;
1465 if (filename.empty()) {
1466 // Launch a file browser
1467 string initpath = lyxrc.document_path;
1470 string const trypath = owner_->buffer()->filePath();
1471 // If directory is writeable, use this as default.
1472 if (IsDirWriteable(trypath))
1476 FileDialog fileDlg(bv_->owner(),
1477 _("Select LyX document to insert"),
1479 make_pair(string(_("Documents|#o#O")),
1480 string(lyxrc.document_path)),
1481 make_pair(string(_("Examples|#E#e")),
1482 string(AddPath(system_lyxdir, "examples"))));
1484 FileDialog::Result result =
1485 fileDlg.Select(initpath,
1486 _("*.lyx| LyX Documents (*.lyx)"));
1488 if (result.first == FileDialog::Later)
1491 filename = result.second;
1493 // check selected filename
1494 if (filename.empty()) {
1495 owner_->message(_("Canceled."));
1500 // get absolute path of file and add ".lyx" to the filename if
1502 filename = FileSearch(string(), filename, "lyx");
1504 string const disp_fn(MakeDisplayPath(filename));
1507 s1 << _("Inserting document") << ' '
1508 << disp_fn << " ...";
1509 owner_->message(s1.str().c_str());
1510 bool const res = bv_->insertLyXFile(filename);
1513 str << _("Document") << ' ' << disp_fn
1514 << ' ' << _("inserted.");
1515 owner_->message(str.str().c_str());
1518 str << _("Could not insert document") << ' '
1520 owner_->message(str.str().c_str());
1525 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1527 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1528 << action <<"] arg[" << argument << "]" << endl;
1531 // --- Misc -------------------------------------------
1535 LyXText * lt = bv_->getLyXText();
1536 lt->toggleAppendix(bv_);
1539 | BufferView::FITCUR
1540 | BufferView::CHANGE);
1545 case LFUN_TOC_INSERT:
1547 InsetCommandParams p;
1548 p.setCmdName("tableofcontents");
1549 Inset * inset = new InsetTOC(p);
1550 if (!insertInset(inset, "Standard"))
1555 case LFUN_TABULAR_FEATURE:
1556 case LFUN_SCROLL_INSET:
1557 // this is not handled here as this funktion is only aktive
1558 // if we have a locking_inset and that one is (or contains)
1562 case LFUN_INSET_GRAPHICS:
1564 Inset * new_inset = new InsetGraphics;
1565 if (!insertInset(new_inset)) {
1568 // this is need because you don't use a inset->Edit()
1569 updateInset(new_inset, true);
1570 new_inset->edit(bv_);
1580 case LFUN_PASTESELECTION:
1582 bool asPara = false;
1583 if (argument == "paragraph")
1585 pasteClipboard(asPara);
1597 case LFUN_LAYOUT_COPY:
1598 bv_->copyEnvironment();
1601 case LFUN_LAYOUT_PASTE:
1602 bv_->pasteEnvironment();
1606 case LFUN_GOTOERROR:
1607 gotoInset(Inset::ERROR_CODE, false);
1611 gotoInset(Inset::IGNORE_CODE, false);
1614 case LFUN_REFERENCE_GOTO:
1616 vector<Inset::Code> tmp;
1617 tmp.push_back(Inset::LABEL_CODE);
1618 tmp.push_back(Inset::REF_CODE);
1619 gotoInset(tmp, true);
1623 case LFUN_HYPHENATION:
1624 specialChar(InsetSpecialChar::HYPHENATION);
1627 case LFUN_LIGATURE_BREAK:
1628 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1632 specialChar(InsetSpecialChar::LDOTS);
1635 case LFUN_END_OF_SENTENCE:
1636 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1639 case LFUN_MENU_SEPARATOR:
1640 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1648 changeDepth(bv_, bv_->getLyXText(), 0);
1651 case LFUN_DEPTH_MIN:
1652 changeDepth(bv_, bv_->getLyXText(), -1);
1655 case LFUN_DEPTH_PLUS:
1656 changeDepth(bv_, bv_->getLyXText(), 1);
1660 owner_->getDialogs()->setUserFreeFont();
1663 case LFUN_FILE_INSERT:
1664 MenuInsertLyXFile(argument);
1667 case LFUN_FILE_INSERT_ASCII_PARA:
1668 InsertAsciiFile(bv_, argument, true);
1671 case LFUN_FILE_INSERT_ASCII:
1672 InsertAsciiFile(bv_, argument, false);
1677 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1678 << argument << endl;
1680 // Derive layout number from given argument (string)
1681 // and current buffer's textclass (number). */
1682 textclass_type tclass = buffer_->params.textclass;
1683 pair <bool, layout_type> layout =
1684 textclasslist.NumberOfLayout(tclass, argument);
1686 // If the entry is obsolete, use the new one instead.
1688 string obs = textclasslist.Style(tclass, layout.second)
1691 layout = textclasslist.NumberOfLayout(tclass, obs);
1694 // see if we found the layout number:
1695 if (!layout.first) {
1696 owner_->getLyXFunc()->setErrorMessage(
1697 string(N_("Layout ")) + argument +
1702 if (current_layout != layout.second) {
1703 LyXText * lt = bv_->getLyXText();
1705 current_layout = layout.second;
1708 | BufferView::FITCUR);
1709 lt->setLayout(bv_, layout.second);
1710 owner_->setLayout(layout.second);
1713 | BufferView::FITCUR
1714 | BufferView::CHANGE);
1721 lang(bv_, argument);
1723 owner_->showState();
1728 owner_->showState();
1733 owner_->showState();
1738 owner_->showState();
1743 owner_->showState();
1748 owner_->showState();
1753 owner_->showState();
1758 owner_->showState();
1761 case LFUN_UNDERLINE:
1763 owner_->showState();
1766 case LFUN_FONT_SIZE:
1767 fontSize(bv_, argument);
1768 owner_->showState();
1771 case LFUN_FONT_STATE:
1772 owner_->getLyXFunc()->setMessage(currentState(bv_));
1775 case LFUN_UPCASE_WORD:
1777 LyXText * lt = bv_->getLyXText();
1781 | BufferView::FITCUR);
1782 lt->changeCase(bv_, LyXText::text_uppercase);
1783 if (lt->inset_owner)
1784 updateInset(lt->inset_owner, true);
1787 | BufferView::FITCUR
1788 | BufferView::CHANGE);
1792 case LFUN_LOWCASE_WORD:
1794 LyXText * lt = bv_->getLyXText();
1796 update(lt, BufferView::SELECT|BufferView::FITCUR);
1797 lt->changeCase(bv_, LyXText::text_lowercase);
1798 if (lt->inset_owner)
1799 updateInset(lt->inset_owner, true);
1802 | BufferView::FITCUR
1803 | BufferView::CHANGE);
1807 case LFUN_CAPITALIZE_WORD:
1809 LyXText * lt = bv_->getLyXText();
1811 update(lt, BufferView::SELECT|BufferView::FITCUR);
1812 lt->changeCase(bv_, LyXText::text_capitalization);
1813 if (lt->inset_owner)
1814 updateInset(lt->inset_owner, true);
1817 | BufferView::FITCUR
1818 | BufferView::CHANGE);
1822 case LFUN_TRANSPOSE_CHARS:
1824 LyXText * lt = bv_->getLyXText();
1826 update(lt, BufferView::SELECT|BufferView::FITCUR);
1827 lt->transposeChars(*bv_);
1828 if (lt->inset_owner)
1829 updateInset(lt->inset_owner, true);
1832 | BufferView::FITCUR
1833 | BufferView::CHANGE);
1838 case LFUN_INSERT_LABEL:
1839 MenuInsertLabel(bv_, argument);
1842 case LFUN_REF_INSERT:
1843 if (argument.empty()) {
1844 InsetCommandParams p("ref");
1845 owner_->getDialogs()->createRef(p.getAsString());
1847 InsetCommandParams p;
1848 p.setFromString(argument);
1850 InsetRef * inset = new InsetRef(p, *buffer_);
1851 if (!insertInset(inset))
1854 updateInset(inset, true);
1858 case LFUN_BOOKMARK_SAVE:
1859 savePosition(strToUnsignedInt(argument));
1862 case LFUN_BOOKMARK_GOTO:
1863 restorePosition(strToUnsignedInt(argument));
1868 string label(argument);
1869 if (label.empty()) {
1871 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1873 label = inset->getContents();
1878 if (!label.empty()) {
1879 //bv_->savePosition(0);
1880 if (!bv_->gotoLabel(label))
1881 Alert::alert(_("Error"),
1882 _("Couldn't find this label"),
1883 _("in current document."));
1888 // --- Cursor Movements -----------------------------
1891 LyXText * lt = bv_->getLyXText();
1893 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1894 if (!lt->selection.mark())
1896 update(lt, BufferView::SELECT|BufferView::FITCUR);
1898 lt->cursorLeft(bv_, false);
1899 if (lt->cursor.pos() < lt->cursor.par()->size()
1900 && lt->cursor.par()->isInset(lt->cursor.pos())
1901 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1902 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1903 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1905 tmpinset->edit(bv_, false);
1907 tmpinset->edit(bv_);
1911 lt->cursorRight(bv_, false);
1913 moveCursorUpdate(false);
1914 owner_->showState();
1920 // This is soooo ugly. Isn`t it possible to make
1921 // it simpler? (Lgb)
1922 LyXText * lt = bv_->getLyXText();
1923 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1924 if (!lt->selection.mark())
1926 update(lt, BufferView::SELECT|BufferView::FITCUR);
1927 LyXCursor const cur = lt->cursor;
1929 lt->cursorLeft(bv_, false);
1930 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1931 lt->cursor.pos() < lt->cursor.par()->size() &&
1932 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1933 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1934 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1935 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1937 tmpinset->edit(bv_);
1939 tmpinset->edit(bv_, false);
1943 lt->cursorRight(bv_, false);
1946 moveCursorUpdate(false);
1947 owner_->showState();
1953 LyXText * lt = bv_->getLyXText();
1955 if (!lt->selection.mark())
1957 update(lt, BufferView::UPDATE);
1960 moveCursorUpdate(false);
1961 owner_->showState();
1967 LyXText * lt = bv_->getLyXText();
1969 if (!lt->selection.mark())
1971 update(lt, BufferView::UPDATE);
1972 lt->cursorDown(bv_);
1974 moveCursorUpdate(false);
1975 owner_->showState();
1979 case LFUN_UP_PARAGRAPH:
1981 LyXText * lt = bv_->getLyXText();
1983 if (!lt->selection.mark())
1985 update(lt, BufferView::UPDATE);
1986 lt->cursorUpParagraph(bv_);
1988 moveCursorUpdate(false);
1989 owner_->showState();
1993 case LFUN_DOWN_PARAGRAPH:
1995 LyXText * lt = bv_->getLyXText();
1997 if (!lt->selection.mark())
1999 update(lt, BufferView::UPDATE);
2000 lt->cursorDownParagraph(bv_);
2002 moveCursorUpdate(false);
2003 owner_->showState();
2009 LyXText * lt = bv_->getLyXText();
2011 if (!lt->selection.mark())
2013 update(lt, BufferView::UPDATE);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2027 update(lt, BufferView::UPDATE);
2030 moveCursorUpdate(false);
2031 owner_->showState();
2037 LyXText * lt = bv_->getLyXText();
2039 if (!lt->selection.mark())
2041 update(lt, BufferView::SELECT|BufferView::FITCUR);
2042 lt->cursorHome(bv_);
2044 moveCursorUpdate(false);
2045 owner_->showState();
2051 LyXText * lt = bv_->getLyXText();
2053 if (!lt->selection.mark())
2056 BufferView::SELECT|BufferView::FITCUR);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2064 case LFUN_SHIFT_TAB:
2067 LyXText * lt = bv_->getLyXText();
2069 if (!lt->selection.mark())
2072 BufferView::SELECT|BufferView::FITCUR);
2075 moveCursorUpdate(false);
2076 owner_->showState();
2080 case LFUN_WORDRIGHT:
2082 LyXText * lt = bv_->getLyXText();
2084 if (!lt->selection.mark())
2086 update(lt, BufferView::SELECT|BufferView::FITCUR);
2087 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2088 lt->cursorLeftOneWord(bv_);
2090 lt->cursorRightOneWord(bv_);
2092 moveCursorUpdate(false);
2093 owner_->showState();
2099 LyXText * lt = bv_->getLyXText();
2101 if (!lt->selection.mark())
2103 update(lt, BufferView::SELECT|BufferView::FITCUR);
2104 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2105 lt->cursorRightOneWord(bv_);
2107 lt->cursorLeftOneWord(bv_);
2109 moveCursorUpdate(false);
2110 owner_->showState();
2114 case LFUN_BEGINNINGBUF:
2116 LyXText * lt = bv_->getLyXText();
2118 if (!lt->selection.mark())
2121 BufferView::SELECT|BufferView::FITCUR);
2124 moveCursorUpdate(false);
2125 owner_->showState();
2131 LyXText * lt = bv_->getLyXText();
2133 if (!lt->selection.mark())
2136 BufferView::SELECT|BufferView::FITCUR);
2137 lt->cursorBottom(bv_);
2139 moveCursorUpdate(false);
2140 owner_->showState();
2144 /* cursor selection ---------------------------- */
2147 LyXText * lt = bv_->getLyXText();
2150 BufferView::SELECT|BufferView::FITCUR);
2151 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2152 lt->cursorLeft(bv_);
2154 lt->cursorRight(bv_);
2156 moveCursorUpdate(true);
2157 owner_->showState();
2163 LyXText * lt = bv_->getLyXText();
2166 BufferView::SELECT|BufferView::FITCUR);
2167 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2168 lt->cursorRight(bv_);
2170 lt->cursorLeft(bv_);
2172 moveCursorUpdate(true);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2182 BufferView::SELECT|BufferView::FITCUR);
2185 moveCursorUpdate(true);
2186 owner_->showState();
2192 LyXText * lt = bv_->getLyXText();
2195 BufferView::SELECT|BufferView::FITCUR);
2196 lt->cursorDown(bv_);
2198 moveCursorUpdate(true);
2199 owner_->showState();
2203 case LFUN_UP_PARAGRAPHSEL:
2205 LyXText * lt = bv_->getLyXText();
2208 BufferView::SELECT|BufferView::FITCUR);
2209 lt->cursorUpParagraph(bv_);
2211 moveCursorUpdate(true);
2212 owner_->showState();
2216 case LFUN_DOWN_PARAGRAPHSEL:
2218 LyXText * lt = bv_->getLyXText();
2221 BufferView::SELECT|BufferView::FITCUR);
2222 lt->cursorDownParagraph(bv_);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 moveCursorUpdate(true);
2237 owner_->showState();
2243 LyXText * lt = bv_->getLyXText();
2245 update(lt, BufferView::SELECT|BufferView::FITCUR);
2248 moveCursorUpdate(true);
2249 owner_->showState();
2255 LyXText * lt = bv_->getLyXText();
2257 update(lt, BufferView::SELECT|BufferView::FITCUR);
2258 lt->cursorHome(bv_);
2260 moveCursorUpdate(true);
2261 owner_->showState();
2267 LyXText * lt = bv_->getLyXText();
2269 update(lt, BufferView::SELECT|BufferView::FITCUR);
2272 moveCursorUpdate(true);
2273 owner_->showState();
2277 case LFUN_WORDRIGHTSEL:
2279 LyXText * lt = bv_->getLyXText();
2281 update(lt, BufferView::SELECT|BufferView::FITCUR);
2282 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2283 lt->cursorLeftOneWord(bv_);
2285 lt->cursorRightOneWord(bv_);
2287 moveCursorUpdate(true);
2288 owner_->showState();
2292 case LFUN_WORDLEFTSEL:
2294 LyXText * lt = bv_->getLyXText();
2296 update(lt, BufferView::SELECT|BufferView::FITCUR);
2297 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2298 lt->cursorRightOneWord(bv_);
2300 lt->cursorLeftOneWord(bv_);
2302 moveCursorUpdate(true);
2303 owner_->showState();
2307 case LFUN_BEGINNINGBUFSEL:
2309 LyXText * lt = bv_->getLyXText();
2311 if (lt->inset_owner)
2313 update(lt, BufferView::SELECT|BufferView::FITCUR);
2316 moveCursorUpdate(true);
2317 owner_->showState();
2321 case LFUN_ENDBUFSEL:
2323 LyXText * lt = bv_->getLyXText();
2325 if (lt->inset_owner)
2328 BufferView::SELECT|BufferView::FITCUR);
2329 lt->cursorBottom(bv_);
2331 moveCursorUpdate(true);
2332 owner_->showState();
2336 // --- text changing commands ------------------------
2337 case LFUN_BREAKLINE:
2339 LyXText * lt = bv_->getLyXText();
2342 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2345 | BufferView::FITCUR
2346 | BufferView::CHANGE);
2347 moveCursorUpdate(false);
2351 case LFUN_PROTECTEDSPACE:
2353 LyXText * lt = bv_->getLyXText();
2355 LyXLayout const & style = textclasslist
2356 .Style(buffer_->params.textclass,
2357 lt->cursor.par()->getLayout());
2359 if (style.free_spacing) {
2360 lt->insertChar(bv_, ' ');
2363 | BufferView::FITCUR
2364 | BufferView::CHANGE);
2368 moveCursorUpdate(false);
2374 LyXText * lt = bv_->getLyXText();
2376 if (lt->selection.mark()) {
2380 | BufferView::FITCUR);
2381 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2384 lt->selection.mark(true);
2387 | BufferView::FITCUR);
2388 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2390 lt->selection.cursor = lt->cursor;
2396 LyXText * lt = bv_->getLyXText();
2398 if (!lt->selection.set()) {
2400 lt->selection.cursor = lt->cursor;
2403 | BufferView::FITCUR
2404 | BufferView::CHANGE);
2405 // It is possible to make it a lot faster still
2406 // just comment out the line below...
2411 moveCursorUpdate(false);
2412 owner_->showState();
2417 case LFUN_DELETE_SKIP:
2419 LyXText * lt = bv_->getLyXText();
2421 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2423 LyXCursor cursor = lt->cursor;
2425 if (!lt->selection.set()) {
2426 if (cursor.pos() == cursor.par()->size()) {
2427 lt->cursorRight(bv_);
2428 cursor = lt->cursor;
2429 if (cursor.pos() == 0
2430 && !(cursor.par()->params().spaceTop()
2431 == VSpace (VSpace::NONE))) {
2434 cursor.par()->params().lineTop(),
2435 cursor.par()->params().lineBottom(),
2436 cursor.par()->params().pagebreakTop(),
2437 cursor.par()->params().pagebreakBottom(),
2438 VSpace(VSpace::NONE),
2439 cursor.par()->params().spaceBottom(),
2440 cursor.par()->params().spacing(),
2441 cursor.par()->params().align(),
2442 cursor.par()->params().labelWidthString(), 0);
2443 lt->cursorLeft(bv_);
2446 | BufferView::FITCUR
2447 | BufferView::CHANGE);
2449 lt->cursorLeft(bv_);
2451 lt->selection.cursor = lt->cursor;
2454 | BufferView::FITCUR
2455 | BufferView::CHANGE);
2459 lt->selection.cursor = lt->cursor;
2462 | BufferView::FITCUR
2463 | BufferView::CHANGE);
2471 /* -------> Delete word forward. */
2472 case LFUN_DELETE_WORD_FORWARD:
2473 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2474 bv_->getLyXText()->deleteWordForward(bv_);
2475 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2476 moveCursorUpdate(false);
2477 owner_->showState();
2480 /* -------> Delete word backward. */
2481 case LFUN_DELETE_WORD_BACKWARD:
2483 LyXText * lt = bv_->getLyXText();
2485 update(lt, BufferView::SELECT|BufferView::FITCUR);
2486 lt->deleteWordBackward(bv_);
2489 | BufferView::FITCUR
2490 | BufferView::CHANGE);
2491 moveCursorUpdate(false);
2492 owner_->showState();
2496 /* -------> Kill to end of line. */
2497 case LFUN_DELETE_LINE_FORWARD:
2499 LyXText * lt = bv_->getLyXText();
2501 update(lt, BufferView::SELECT|BufferView::FITCUR);
2502 lt->deleteLineForward(bv_);
2505 | BufferView::FITCUR
2506 | BufferView::CHANGE);
2507 moveCursorUpdate(false);
2511 /* -------> Set mark off. */
2514 LyXText * lt = bv_->getLyXText();
2517 update(lt, BufferView::SELECT|BufferView::FITCUR);
2518 lt->selection.cursor = lt->cursor;
2519 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2523 /* -------> Set mark on. */
2526 LyXText * lt = bv_->getLyXText();
2529 lt->selection.mark(true);
2530 update(lt, BufferView::SELECT|BufferView::FITCUR);
2531 lt->selection.cursor = lt->cursor;
2532 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2536 case LFUN_BACKSPACE:
2538 LyXText * lt = bv_->getLyXText();
2540 if (!lt->selection.set()) {
2541 if (owner_->getIntl()->getTrans().backspace()) {
2543 lt->selection.cursor = lt->cursor;
2546 | BufferView::FITCUR
2547 | BufferView::CHANGE);
2548 // It is possible to make it a lot faster still
2549 // just comment out the line below...
2555 owner_->showState();
2560 case LFUN_BACKSPACE_SKIP:
2562 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2563 LyXText * lt = bv_->getLyXText();
2565 LyXCursor cursor = lt->cursor;
2567 if (!lt->selection.set()) {
2568 if (cursor.pos() == 0
2569 && !(cursor.par()->params().spaceTop()
2570 == VSpace (VSpace::NONE))) {
2573 cursor.par()->params().lineTop(),
2574 cursor.par()->params().lineBottom(),
2575 cursor.par()->params().pagebreakTop(),
2576 cursor.par()->params().pagebreakBottom(),
2577 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2578 cursor.par()->params().spacing(),
2579 cursor.par()->params().align(),
2580 cursor.par()->params().labelWidthString(), 0);
2583 | BufferView::FITCUR
2584 | BufferView::CHANGE);
2587 lt->selection.cursor = cursor;
2590 | BufferView::FITCUR
2591 | BufferView::CHANGE);
2598 case LFUN_BREAKPARAGRAPH:
2600 LyXText * lt = bv_->getLyXText();
2603 lt->breakParagraph(bv_, 0);
2606 | BufferView::FITCUR
2607 | BufferView::CHANGE);
2608 lt->selection.cursor = lt->cursor;
2610 owner_->showState();
2614 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2616 LyXText * lt = bv_->getLyXText();
2619 lt->breakParagraph(bv_, 1);
2622 | BufferView::FITCUR
2623 | BufferView::CHANGE);
2624 lt->selection.cursor = lt->cursor;
2626 owner_->showState();
2630 case LFUN_BREAKPARAGRAPH_SKIP:
2632 // When at the beginning of a paragraph, remove
2633 // indentation and add a "defskip" at the top.
2634 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2635 LyXText * lt = bv_->getLyXText();
2637 LyXCursor cursor = lt->cursor;
2640 if (cursor.pos() == 0) {
2641 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2644 cursor.par()->params().lineTop(),
2645 cursor.par()->params().lineBottom(),
2646 cursor.par()->params().pagebreakTop(),
2647 cursor.par()->params().pagebreakBottom(),
2648 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2649 cursor.par()->params().spacing(),
2650 cursor.par()->params().align(),
2651 cursor.par()->params().labelWidthString(), 1);
2652 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2656 lt->breakParagraph(bv_, 0);
2657 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2662 | BufferView::FITCUR
2663 | BufferView::CHANGE);
2664 lt->selection.cursor = cursor;
2666 owner_->showState();
2670 case LFUN_PARAGRAPH_SPACING:
2672 LyXText * lt = bv_->getLyXText();
2674 Paragraph * par = lt->cursor.par();
2675 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2676 float cur_value = 1.0;
2677 if (cur_spacing == Spacing::Other) {
2678 cur_value = par->params().spacing().getValue();
2681 istringstream istr(argument.c_str());
2685 Spacing::Space new_spacing = cur_spacing;
2686 float new_value = cur_value;
2688 lyxerr << "Missing argument to `paragraph-spacing'"
2690 } else if (tmp == "single") {
2691 new_spacing = Spacing::Single;
2692 } else if (tmp == "onehalf") {
2693 new_spacing = Spacing::Onehalf;
2694 } else if (tmp == "double") {
2695 new_spacing = Spacing::Double;
2696 } else if (tmp == "other") {
2697 new_spacing = Spacing::Other;
2700 lyxerr << "new_value = " << tmpval << endl;
2703 } else if (tmp == "default") {
2704 new_spacing = Spacing::Default;
2706 lyxerr << _("Unknown spacing argument: ")
2707 << argument << endl;
2709 if (cur_spacing != new_spacing || cur_value != new_value) {
2710 par->params().spacing(Spacing(new_spacing, new_value));
2711 lt->redoParagraph(bv_);
2714 | BufferView::FITCUR
2715 | BufferView::CHANGE);
2720 case LFUN_INSET_TOGGLE:
2722 LyXText * lt = bv_->getLyXText();
2725 update(lt, BufferView::SELECT|BufferView::FITCUR);
2726 lt->toggleInset(bv_);
2727 update(lt, BufferView::SELECT|BufferView::FITCUR);
2739 InsetCommandParams p;
2740 if (action == LFUN_HTMLURL)
2741 p.setCmdName("htmlurl");
2743 p.setCmdName("url");
2744 owner_->getDialogs()->createUrl(p.getAsString());
2748 case LFUN_INSERT_URL:
2750 InsetCommandParams p;
2751 p.setFromString(argument);
2753 InsetUrl * inset = new InsetUrl(p);
2754 if (!insertInset(inset))
2757 updateInset(inset, true);
2761 case LFUN_INSET_TEXT:
2762 insertAndEditInset(new InsetText);
2765 case LFUN_INSET_ERT:
2766 insertAndEditInset(new InsetERT);
2769 case LFUN_INSET_EXTERNAL:
2770 insertAndEditInset(new InsetExternal);
2773 case LFUN_INSET_FOOTNOTE:
2774 insertAndEditInset(new InsetFoot);
2777 case LFUN_INSET_MARGINAL:
2778 insertAndEditInset(new InsetMarginal);
2781 case LFUN_INSET_MINIPAGE:
2782 insertAndEditInset(new InsetMinipage);
2785 case LFUN_INSERT_NOTE:
2786 insertAndEditInset(new InsetNote);
2789 case LFUN_INSET_FLOAT:
2790 // check if the float type exist
2791 if (floatList.typeExist(argument)) {
2792 insertAndEditInset(new InsetFloat(argument));
2794 lyxerr << "Non-existent float type: "
2795 << argument << endl;
2799 case LFUN_INSET_WIDE_FLOAT:
2801 // check if the float type exist
2802 if (floatList.typeExist(argument)) {
2803 InsetFloat * new_inset = new InsetFloat(argument);
2804 new_inset->wide(true);
2805 if (insertInset(new_inset))
2806 new_inset->edit(bv_);
2810 lyxerr << "Non-existent float type: "
2811 << argument << endl;
2818 case LFUN_INSET_LIST:
2819 insertAndEditInset(new InsetList);
2822 case LFUN_INSET_THEOREM:
2823 insertAndEditInset(new InsetTheorem);
2827 case LFUN_INSET_CAPTION:
2829 // Do we have a locking inset...
2830 if (bv_->theLockingInset()) {
2831 lyxerr << "Locking inset code: "
2832 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2833 InsetCaption * new_inset = new InsetCaption;
2834 new_inset->setOwner(bv_->theLockingInset());
2835 new_inset->setAutoBreakRows(true);
2836 new_inset->setDrawFrame(0, InsetText::LOCKED);
2837 new_inset->setFrameColor(0, LColor::captionframe);
2838 if (insertInset(new_inset))
2839 new_inset->edit(bv_);
2846 case LFUN_INSET_TABULAR:
2850 if (!argument.empty())
2851 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2852 InsetTabular * new_inset =
2853 new InsetTabular(*buffer_, r, c);
2855 bv_->getLyXText()->real_current_font.isRightToLeft();
2856 if (!open_new_inset(new_inset, rtl))
2861 // --- lyxserver commands ----------------------------
2863 case LFUN_CHARATCURSOR:
2865 pos_type pos = bv_->getLyXText()->cursor.pos();
2866 if (pos < bv_->getLyXText()->cursor.par()->size())
2867 owner_->getLyXFunc()->setMessage(
2868 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2870 owner_->getLyXFunc()->setMessage("EOF");
2875 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2877 + tostr(bv_->getLyXText()->cursor.y()));
2884 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2885 lyxerr << "SETXY: Could not parse coordinates in '"
2886 << argument << std::endl;
2888 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2892 case LFUN_GETLAYOUT:
2893 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2898 LyXFont & font = bv_->getLyXText()->current_font;
2899 if (font.shape() == LyXFont::ITALIC_SHAPE)
2900 owner_->getLyXFunc()->setMessage("E");
2901 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2902 owner_->getLyXFunc()->setMessage("N");
2904 owner_->getLyXFunc()->setMessage("0");
2909 // --- accented characters ---------------------------
2912 case LFUN_CIRCUMFLEX:
2922 case LFUN_SPECIAL_CARON:
2925 case LFUN_HUNG_UMLAUT:
2928 if (argument.empty()) {
2930 owner_->getLyXFunc()->handleKeyFunc(action);
2932 owner_->getLyXFunc()->handleKeyFunc(action);
2933 owner_->getIntl()->getTrans()
2934 .TranslateAndInsert(argument[0], bv_->getLyXText());
2935 update(bv_->getLyXText(),
2937 | BufferView::FITCUR
2938 | BufferView::CHANGE);
2942 case LFUN_MATH_MACRO:
2943 mathDispatchMathMacro(bv_, argument);
2946 case LFUN_MATH_DELIM:
2947 mathDispatchMathDelim(bv_, argument);
2950 case LFUN_INSERT_MATRIX:
2951 mathDispatchInsertMatrix(bv_, argument);
2954 case LFUN_INSERT_MATH:
2955 mathDispatchInsertMath(bv_, argument);
2958 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2959 mathDispatchMathImportSelection(bv_, argument);
2962 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2963 mathDispatchMathDisplay(bv_, argument);
2966 case LFUN_MATH_MODE: // Open or create an inlined math inset
2967 mathDispatchMathMode(bv_, argument);
2970 case LFUN_GREEK: // Insert a single greek letter
2971 mathDispatchGreek(bv_, argument);
2974 case LFUN_CITATION_INSERT:
2976 InsetCommandParams p;
2977 p.setFromString(argument);
2979 InsetCitation * inset = new InsetCitation(p);
2980 if (!insertInset(inset))
2983 updateInset(inset, true);
2987 case LFUN_INSERT_BIBTEX:
2989 // ale970405+lasgoutt970425
2990 // The argument can be up to two tokens separated
2991 // by a space. The first one is the bibstyle.
2992 string const db = token(argument, ' ', 0);
2993 string const bibstyle = token(argument, ' ', 1);
2995 InsetCommandParams p("BibTeX", db, bibstyle);
2996 InsetBibtex * inset = new InsetBibtex(p);
2998 if (insertInset(inset)) {
2999 if (argument.empty())
3006 // BibTeX data bases
3007 case LFUN_BIBDB_ADD:
3009 InsetBibtex * inset =
3010 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3012 inset->addDatabase(argument);
3017 case LFUN_BIBDB_DEL:
3019 InsetBibtex * inset =
3020 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3022 inset->delDatabase(argument);
3027 case LFUN_BIBTEX_STYLE:
3029 InsetBibtex * inset =
3030 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3032 inset->setOptions(argument);
3037 case LFUN_INDEX_CREATE:
3039 InsetCommandParams p("index");
3040 if (argument.empty()) {
3041 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3042 p.setContents(idxstring);
3044 p.setContents(argument);
3047 owner_->getDialogs()->createIndex(p.getAsString());
3051 case LFUN_INDEX_INSERT:
3053 InsetCommandParams p;
3054 p.setFromString(argument);
3055 InsetIndex * inset = new InsetIndex(p);
3057 if (!insertInset(inset))
3060 updateInset(inset, true);
3064 case LFUN_INDEX_INSERT_LAST:
3066 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3067 if (!idxstring.empty()) {
3068 owner_->message(_("Word `")
3069 + idxstring + _(("' indexed.")));
3070 InsetCommandParams p("index", idxstring);
3071 InsetIndex * inset = new InsetIndex(p);
3073 if (!insertInset(inset))
3076 updateInset(inset, true);
3081 case LFUN_INDEX_PRINT:
3083 InsetCommandParams p("printindex");
3084 Inset * inset = new InsetPrintIndex(p);
3085 if (!insertInset(inset, "Standard"))
3090 case LFUN_PARENTINSERT:
3092 lyxerr << "arg " << argument << endl;
3093 InsetCommandParams p("lyxparent", argument);
3094 Inset * inset = new InsetParent(p, *buffer_);
3095 if (!insertInset(inset, "Standard"))
3101 case LFUN_CHILD_INSERT:
3103 InsetInclude::Params p;
3104 p.cparams.setFromString(argument);
3105 p.masterFilename_ = buffer_->fileName();
3107 InsetInclude * inset = new InsetInclude(p);
3108 if (!insertInset(inset))
3111 updateInset(inset, true);
3112 bv_->owner()->getDialogs()->showInclude(inset);
3117 case LFUN_FLOAT_LIST:
3119 // We should check the argument for validity. (Lgb)
3120 Inset * inset = new InsetFloatList(argument);
3121 if (!insertInset(inset, "Standard"))
3126 case LFUN_THESAURUS_ENTRY:
3128 string arg = argument;
3131 arg = bv_->getLyXText()->selectionAsString(buffer_,
3135 if (arg.size() > 100 || arg.empty()) {
3136 // Get word or selection
3137 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3138 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3139 // FIXME: where is getLyXText()->unselect(bv_) ?
3143 bv_->owner()->getDialogs()->showThesaurus(arg);
3147 case LFUN_SELFINSERT:
3149 if (argument.empty()) break;
3151 /* Automatically delete the currently selected
3152 * text and replace it with what is being
3153 * typed in now. Depends on lyxrc settings
3154 * "auto_region_delete", which defaults to
3157 LyXText * lt = bv_->getLyXText();
3159 if (lyxrc.auto_region_delete) {
3160 if (lt->selection.set()) {
3161 lt->cutSelection(bv_, false, false);
3164 | BufferView::FITCUR
3165 | BufferView::CHANGE);
3170 LyXFont const old_font(lt->real_current_font);
3172 string::const_iterator cit = argument.begin();
3173 string::const_iterator end = argument.end();
3174 for (; cit != end; ++cit) {
3175 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3180 | BufferView::FITCUR
3181 | BufferView::CHANGE);
3183 lt->selection.cursor = lt->cursor;
3184 moveCursorUpdate(false);
3186 // real_current_font.number can change so we need to
3187 // update the minibuffer
3188 if (old_font != lt->real_current_font)
3189 owner_->showState();
3194 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3196 time_t now_time_t = time(NULL);
3197 struct tm * now_tm = localtime(&now_time_t);
3198 setlocale(LC_TIME, "");
3200 if (!argument.empty())
3203 arg = lyxrc.date_insert_format;
3205 int const datetmp_len =
3206 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3208 LyXText * lt = bv_->getLyXText();
3210 for (int i = 0; i < datetmp_len; i++) {
3211 lt->insertChar(bv_, datetmp[i]);
3214 | BufferView::FITCUR
3215 | BufferView::CHANGE);
3218 lt->selection.cursor = lt->cursor;
3219 moveCursorUpdate(false);
3223 case LFUN_UNKNOWN_ACTION:
3224 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3235 void BufferView::Pimpl::newline()
3238 LyXText * lt = bv_->getLyXText();
3242 | BufferView::FITCUR);
3243 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3246 | BufferView::FITCUR
3247 | BufferView::CHANGE);
3252 void BufferView::Pimpl::hfill()
3255 LyXText * lt = bv_->getLyXText();
3259 | BufferView::FITCUR);
3260 lt->insertChar(bv_, Paragraph::META_HFILL);
3263 | BufferView::FITCUR
3264 | BufferView::CHANGE);
3269 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3273 update(lt, BufferView::SELECT|BufferView::FITCUR);
3274 InsetSpecialChar * new_inset =
3275 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3276 #ifdef WITH_WARNINGS
3277 #warning Why is this code different from specialChar() below? (JMarc)
3278 // the code in specialChar is a generic version of what used to exist
3279 // for other special chars. I did not merge this case because of the
3280 // call to updateInset(), but what does it do?
3282 if (!insertInset(new_inset))
3285 updateInset(new_inset, true);
3290 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3293 LyXText * lt = bv_->getLyXText();
3296 update(lt, BufferView::SELECT|BufferView::FITCUR);
3297 InsetSpecialChar * new_inset =
3298 new InsetSpecialChar(kind);
3299 if (!insertInset(new_inset))
3305 void BufferView::Pimpl::smartQuote()
3307 LyXText const * lt = bv_->getLyXText();
3308 Paragraph const * par = lt->cursor.par();
3309 pos_type pos = lt->cursor.pos();
3313 || (par->isInset(pos - 1)
3314 && par->getInset(pos - 1)->isSpace()))
3317 c = par->getChar(pos - 1);
3322 LyXLayout const & style = textclasslist.Style(
3323 bv_->buffer()->params.textclass, par->getLayout());
3325 if (style.pass_thru ||
3326 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3327 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3331 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3333 if (insertInset(inset))
3340 // Open and lock an updatable inset
3341 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3343 LyXText * lt = bv_->getLyXText();
3347 if (!insertInset(new_inset)) {
3351 new_inset->edit(bv_, !behind);
3356 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3358 // if we are in a locking inset we should try to insert the
3359 // inset there otherwise this is a illegal function now
3360 if (bv_->theLockingInset()) {
3361 if (bv_->theLockingInset()->insetAllowed(inset))
3362 return bv_->theLockingInset()->insertInset(bv_, inset);
3366 // not quite sure if we want this...
3367 setCursorParUndo(bv_);
3370 beforeChange(bv_->text);
3371 if (!lout.empty()) {
3372 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3373 bv_->text->breakParagraph(bv_);
3374 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3376 if (bv_->text->cursor.par()->size()) {
3377 bv_->text->cursorLeft(bv_);
3379 bv_->text->breakParagraph(bv_);
3380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3383 pair<bool, layout_type> lres =
3384 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3385 layout_type lay = 0;
3386 if (lres.first != false) {
3390 // layout not fount using default "Standard" (0)
3394 bv_->text->setLayout(bv_, lay);
3396 bv_->text->setParagraph(bv_, 0, 0,
3398 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3403 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3406 bv_->text->insertInset(bv_, inset);
3407 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3414 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3419 // first check for locking insets
3420 if (bv_->theLockingInset()) {
3421 if (bv_->theLockingInset() == inset) {
3422 if (bv_->text->updateInset(bv_, inset)) {
3425 buffer_->markDirty();
3430 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3431 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3434 buffer_->markDirty();
3442 // then check the current buffer
3445 update(bv_->text, BufferView::UPDATE);
3446 if (bv_->text->updateInset(bv_, inset)) {
3450 | BufferView::FITCUR
3451 | BufferView::CHANGE);
3453 update(bv_->text, SELECT);
3461 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3464 if (!available()) return;
3467 beforeChange(bv_->text);
3468 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3470 LyXCursor const & cursor = bv_->text->cursor;
3474 cursor.par()->isInset(cursor.pos())) {
3475 Inset const * inset = cursor.par()->getInset(cursor.pos());
3476 if (find(codes.begin(), codes.end(), inset->lyxCode())
3479 static_cast<InsetCommand const *>(inset)->getContents();
3483 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3484 if (bv_->text->cursor.pos()
3485 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3486 LyXCursor tmp = bv_->text->cursor;
3487 bv_->text->cursor.par(bv_->text->ownerParagraph());
3488 bv_->text->cursor.pos(0);
3489 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3490 bv_->text->cursor = tmp;
3491 bv_->owner()->message(_("No more insets"));
3494 bv_->owner()->message(_("No more insets"));
3497 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3498 bv_->text->selection.cursor = bv_->text->cursor;
3502 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3504 gotoInset(vector<Inset::Code>(1, code), same_content);