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));
161 cursor_timeout.timeout.connect(slot(this,
162 &BufferView::Pimpl::cursorToggle));
163 cursor_timeout.start();
164 workarea_.setFocus();
165 saved_positions.resize(saved_positions_num);
169 Painter & BufferView::Pimpl::painter()
171 return workarea_.getPainter();
175 void BufferView::Pimpl::buffer(Buffer * b)
177 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
181 buffer_->delUser(bv_);
183 // Put the old text into the TextCache, but
184 // only if the buffer is still loaded.
185 // Also set the owner of the test to 0
186 // bv_->text->owner(0);
187 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
188 if (lyxerr.debugging())
189 textcache.show(lyxerr, "BufferView::buffer");
194 // Set current buffer
197 if (bufferlist.getState() == BufferList::CLOSING) return;
200 // screen is always deleted when the buffer is changed.
203 // If we are closing the buffer, use the first buffer as current
205 buffer_ = bufferlist.first();
209 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
210 buffer_->addUser(bv_);
211 // If we don't have a text object for this, we make one
212 if (bv_->text == 0) {
213 resizeCurrentBuffer();
218 bv_->text->first = screen_->topCursorVisible(bv_->text);
219 owner_->updateMenubar();
220 owner_->updateToolbar();
221 // Similarly, buffer-dependent dialogs should be updated or
222 // hidden. This should go here because some dialogs (eg ToC)
223 // require bv_->text.
224 owner_->getDialogs()->updateBufferDependent(true);
228 lyxerr[Debug::INFO] << " No Buffer!" << endl;
229 owner_->updateMenubar();
230 owner_->updateToolbar();
231 owner_->getDialogs()->hideBufferDependent();
235 // Also remove all remaining text's from the testcache.
236 // (there should not be any!) (if there is any it is a
238 if (lyxerr.debugging())
239 textcache.show(lyxerr, "buffer delete all");
242 // should update layoutchoice even if we don't have a buffer.
243 owner_->updateLayoutChoice();
245 owner_->updateWindowTitle();
249 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
251 workarea_.resize(xpos, ypos, width, height);
252 update(bv_->text, SELECT);
257 void BufferView::Pimpl::resize()
260 resizeCurrentBuffer();
264 void BufferView::Pimpl::redraw()
266 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
271 bool BufferView::Pimpl::fitCursor()
273 lyx::Assert(screen_.get());
277 if (bv_->theLockingInset()) {
278 bv_->theLockingInset()->fitInsetCursor(bv_);
281 ret = screen_->fitCursor(bv_->text, bv_);
284 bv_->owner()->getDialogs()->updateParagraph();
291 void BufferView::Pimpl::redoCurrentBuffer()
293 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
294 if (buffer_ && bv_->text) {
296 owner_->updateLayoutChoice();
301 int BufferView::Pimpl::resizeCurrentBuffer()
303 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
306 Paragraph * selstartpar = 0;
307 Paragraph * selendpar = 0;
308 UpdatableInset * the_locking_inset = 0;
311 pos_type selstartpos = 0;
312 pos_type selendpos = 0;
313 bool selection = false;
314 bool mark_set = false;
316 owner_->prohibitInput();
318 owner_->message(_("Formatting document..."));
321 par = bv_->text->cursor.par();
322 pos = bv_->text->cursor.pos();
323 selstartpar = bv_->text->selection.start.par();
324 selstartpos = bv_->text->selection.start.pos();
325 selendpar = bv_->text->selection.end.par();
326 selendpos = bv_->text->selection.end.pos();
327 selection = bv_->text->selection.set();
328 mark_set = bv_->text->selection.mark();
329 the_locking_inset = bv_->theLockingInset();
331 bv_->text = new LyXText(bv_);
332 bv_->text->init(bv_);
334 // See if we have a text in TextCache that fits
335 // the new buffer_ with the correct width.
336 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
338 if (lyxerr.debugging()) {
339 lyxerr << "Found a LyXText that fits:\n";
340 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
342 // Set the owner of the newly found text
343 // bv_->text->owner(bv_);
344 if (lyxerr.debugging())
345 textcache.show(lyxerr, "resizeCurrentBuffer");
347 bv_->text = new LyXText(bv_);
348 bv_->text->init(bv_);
354 bv_->text->selection.set(true);
355 /* at this point just to avoid the Delete-Empty-Paragraph
356 * Mechanism when setting the cursor */
357 bv_->text->selection.mark(mark_set);
359 bv_->text->setCursor(bv_, selstartpar, selstartpos);
360 bv_->text->selection.cursor = bv_->text->cursor;
361 bv_->text->setCursor(bv_, selendpar, selendpos);
362 bv_->text->setSelection(bv_);
363 bv_->text->setCursor(bv_, par, pos);
365 bv_->text->setCursor(bv_, par, pos);
366 bv_->text->selection.cursor = bv_->text->cursor;
367 bv_->text->selection.set(false);
369 // remake the inset locking
370 bv_->theLockingInset(the_locking_inset);
372 bv_->text->first = screen_->topCursorVisible(bv_->text);
374 buffer_->resizeInsets(bv_);
376 // this will scroll the screen such that the cursor becomes visible
381 owner_->allowInput();
383 /// clear the "Formatting Document" message
390 void BufferView::Pimpl::updateScreen()
392 // Regenerate the screen.
393 screen_.reset(new LyXScreen(workarea_));
397 void BufferView::Pimpl::updateScrollbar()
399 /* If the text is smaller than the working area, the scrollbar
400 * maximum must be the working area height. No scrolling will
403 workarea_.setScrollbar(0, 1.0);
407 long const text_height = bv_->text->height;
409 double const lineh = bv_->text->defaultHeight();
410 double const slider_size =
411 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
413 static long old_text_height = 0;
414 static double old_lineh = 0;
415 static double old_slider_size = 0;
417 if (text_height != old_text_height) {
418 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
419 old_text_height = text_height;
421 if (lineh != old_lineh) {
422 workarea_.setScrollbarIncrements(lineh);
425 if (current_scrollbar_value != bv_->text->first
426 || slider_size != old_slider_size) {
427 current_scrollbar_value = bv_->text->first;
428 workarea_.setScrollbar(current_scrollbar_value, slider_size);
429 old_slider_size = slider_size;
434 // Callback for scrollbar slider
435 void BufferView::Pimpl::scrollCB(double value)
437 if (!buffer_) return;
439 current_scrollbar_value = long(value);
440 if (current_scrollbar_value < 0)
441 current_scrollbar_value = 0;
446 screen_->draw(bv_->text, bv_, current_scrollbar_value);
448 if (!lyxrc.cursor_follows_scrollbar) {
453 LyXText * vbt = bv_->text;
455 int const height = vbt->defaultHeight();
456 int const first = static_cast<int>((bv_->text->first + height));
457 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
459 if (vbt->cursor.y() < first)
460 vbt->setCursorFromCoordinates(bv_, 0, first);
461 else if (vbt->cursor.y() > last)
462 vbt->setCursorFromCoordinates(bv_, 0, last);
468 int BufferView::Pimpl::scrollUp(long time)
470 if (!buffer_) return 0;
471 if (!screen_.get()) return 0;
473 double value = workarea_.getScrollbarValue();
475 if (value == 0) return 0;
477 float add_value = (bv_->text->defaultHeight()
478 + float(time) * float(time) * 0.125);
480 if (add_value > workarea_.height())
481 add_value = float(workarea_.height() -
482 bv_->text->defaultHeight());
489 workarea_.setScrollbarValue(value);
496 int BufferView::Pimpl::scrollDown(long time)
498 if (!buffer_) return 0;
499 if (!screen_.get()) return 0;
501 double value = workarea_.getScrollbarValue();
502 pair<float, float> p = workarea_.getScrollbarBounds();
503 double const max = p.second;
505 if (value == max) return 0;
507 float add_value = (bv_->text->defaultHeight()
508 + float(time) * float(time) * 0.125);
510 if (add_value > workarea_.height())
511 add_value = float(workarea_.height() -
512 bv_->text->defaultHeight());
519 workarea_.setScrollbarValue(value);
526 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
528 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
532 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
534 // Only use motion with button 1
535 if (!(state & Button1MotionMask))
538 if (!buffer_ || !screen_.get()) return;
540 // Check for inset locking
541 if (bv_->theLockingInset()) {
542 LyXCursor cursor = bv_->text->cursor;
543 LyXFont font = bv_->text->getFont(buffer_,
544 cursor.par(), cursor.pos());
545 int width = bv_->theLockingInset()->width(bv_, font);
546 int inset_x = font.isVisibleRightToLeft()
547 ? cursor.x() - width : cursor.x();
548 int start_x = inset_x + bv_->theLockingInset()->scroll();
549 bv_->theLockingInset()->
550 insetMotionNotify(bv_,
552 y - cursor.y() + bv_->text->first,
557 /* The test for not selection possible is needed, that only motion
558 events are used, where the bottom press event was on
559 the drawing area too */
560 if (!selection_possible)
563 screen_->hideCursor();
565 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
567 if (!bv_->text->selection.set())
568 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
570 bv_->text->setSelection(bv_);
571 screen_->toggleToggle(bv_->text, bv_);
574 screen_->showCursor(bv_->text, bv_);
581 // Single-click on work area
582 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
585 if (!buffer_ || !screen_.get()) return;
587 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
589 // ok ok, this is a hack.
590 if (button == 4 || button == 5) {
593 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
596 scrollDown(lyxrc.wheel_jump);
601 if (bv_->theLockingInset()) {
602 // We are in inset locking mode
604 /* Check whether the inset was hit. If not reset mode,
605 otherwise give the event to the inset */
606 if (inset_hit == bv_->theLockingInset()) {
607 bv_->theLockingInset()->
608 insetButtonPress(bv_,xpos, ypos,button);
611 bv_->unlockInset(bv_->theLockingInset());
616 selection_possible = true;
617 screen_->hideCursor();
619 int const screen_first = bv_->text->first;
621 // Middle button press pastes if we have a selection
622 bool paste_internally = false;
624 && bv_->text->selection.set()) {
625 owner_->getLyXFunc()->dispatch(LFUN_COPY);
626 paste_internally = true;
629 // Clear the selection
630 screen_->toggleSelection(bv_->text, bv_);
631 bv_->text->clearSelection();
632 bv_->text->fullRebreak(bv_);
634 screen_->update(bv_->text, bv_);
640 // Single left click in math inset?
641 if (isHighlyEditableInset(inset_hit)) {
642 // Highly editable inset, like math
643 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
644 selection_possible = false;
645 owner_->updateLayoutChoice();
646 owner_->message(inset->editMessage());
647 inset->insetButtonPress(bv_, xpos, ypos, button);
648 inset->edit(bv_, xpos, ypos, button);
652 // Right click on a footnote flag opens float menu
654 selection_possible = false;
658 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
659 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
661 bv_->text->selection.cursor = bv_->text->cursor;
662 bv_->text->cursor.x_fix(bv_->text->cursor.x());
664 owner_->updateLayoutChoice();
666 selection_possible = false;
669 // Insert primary selection with middle mouse
670 // if there is a local selection in the current buffer,
673 if (paste_internally)
674 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
676 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
678 selection_possible = false;
684 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
690 LyXText * text = bv_->getLyXText();
692 if (text->bv_owner && bv_->theLockingInset())
695 if (screen_.get() && button == 1) {
696 if (text->bv_owner) {
697 screen_->hideCursor();
698 screen_->toggleSelection(text, bv_);
699 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
700 screen_->toggleSelection(text, bv_, false);
702 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
704 /* This will fit the cursor on the screen
706 update(text, BufferView::SELECT|BufferView::FITCUR);
711 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
717 LyXText * text = bv_->getLyXText();
719 if (text->bv_owner && bv_->theLockingInset())
722 if (screen_.get() && (button == 1)) {
723 if (text->bv_owner) {
724 screen_->hideCursor();
725 screen_->toggleSelection(text, bv_);
727 text->cursorHome(bv_);
728 text->selection.cursor = text->cursor;
729 text->cursorEnd(bv_);
730 text->setSelection(bv_);
731 if (text->bv_owner) {
732 screen_->toggleSelection(text, bv_, false);
734 /* This will fit the cursor on the screen
736 update(text, BufferView::SELECT|BufferView::FITCUR);
741 void BufferView::Pimpl::selectionRequested()
743 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(), false));
745 workarea_.putClipboard(sel);
750 void BufferView::Pimpl::enterView()
752 if (active() && available()) {
753 SetXtermCursor(workarea_.getWin());
754 using_xterm_cursor = true;
759 void BufferView::Pimpl::leaveView()
761 if (using_xterm_cursor) {
762 XUndefineCursor(fl_get_display(), workarea_.getWin());
763 using_xterm_cursor = false;
768 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
771 if (!buffer_ || !screen_.get()) return;
773 // If we hit an inset, we have the inset coordinates in these
774 // and inset_hit points to the inset. If we do not hit an
775 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
776 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
778 if (bv_->theLockingInset()) {
779 // We are in inset locking mode.
781 /* LyX does a kind of work-area grabbing for insets.
782 Only a ButtonPress Event outside the inset will
783 force a insetUnlock. */
784 bv_->theLockingInset()->
785 insetButtonRelease(bv_, x, y, button);
789 selection_possible = false;
796 workarea_.haveSelection(bv_->getLyXText()->selection.set());
801 owner_->updateMenubar();
802 owner_->updateToolbar();
804 // Did we hit an editable inset?
806 // Inset like error, notes and figures
807 selection_possible = false;
809 // if we reach this point with a selection, it
810 // must mean we are currently selecting.
811 // But we don't want to open the inset
812 // because that is annoying for the user.
813 // So just pretend we didn't hit it.
814 // this is OK because a "kosher" ButtonRelease
815 // will follow a ButtonPress that clears
817 // Note this also fixes selection drawing
818 // problems if we end up opening an inset
819 if (bv_->getLyXText()->selection.set())
822 // CHECK fix this proper in 0.13
823 // well, maybe 13.0 !!!!!!!!!
825 // Following a ref shouldn't issue
826 // a push on the undo-stack
827 // anylonger, now that we have
828 // keybindings for following
829 // references and returning from
830 // references. IMHO though, it
831 // should be the inset's own business
832 // to push or not push on the undo
833 // stack. They don't *have* to
834 // alter the document...
836 // ...or maybe the SetCursorParUndo()
837 // below isn't necessary at all anylonger?
838 if (inset_hit->lyxCode() == Inset::REF_CODE) {
839 setCursorParUndo(bv_);
842 owner_->message(inset_hit->editMessage());
844 if (isHighlyEditableInset(inset_hit)) {
845 // Highly editable inset, like math
846 UpdatableInset *inset = (UpdatableInset *)inset_hit;
847 inset->insetButtonRelease(bv_, x, y, button);
849 inset_hit->insetButtonRelease(bv_, x, y, button);
850 inset_hit->edit(bv_, x, y, button);
855 // Maybe we want to edit a bibitem ale970302
856 if (bv_->text->cursor.par()->bibkey && x < 20 +
857 bibitemMaxWidth(bv_, textclasslist.
859 params.textclass).defaultfont())) {
860 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
867 Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
869 Paragraph /*const*/ & par = *cursor.par();
870 pos_type const pos = cursor.pos();
872 lyx::Assert(par.getInset(pos));
874 Inset const & inset(*par.getInset(pos));
876 LyXFont const & font = text.getFont(buffer_, &par, pos);
878 int const width = inset.width(bv_, font);
879 int const inset_x = font.isVisibleRightToLeft()
880 ? (cursor.x() - width) : cursor.x();
883 inset_x + inset.scroll(),
885 cursor.y() - inset.ascent(bv_, font),
886 cursor.y() + inset.descent(bv_, font));
890 Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
892 pos_type const pos(cursor.pos());
893 Paragraph /*const*/ & par(*cursor.par());
895 if (pos >= par.size() || !par.isInset(pos)) {
899 Inset /*const*/ * inset = par.getInset(pos);
901 if (!isEditableInset(inset)) {
905 Box b(insetDimensions(text, cursor));
907 if (!b.contained(x, y)) {
908 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
909 << " box " << b << endl;
913 text.setCursor(bv_, &par, pos, true);
916 // The origin of an inset is on the baseline
917 y -= (text.cursor.y());
923 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
928 int y_tmp = y + text->first;
931 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
933 Inset * inset(checkInset(*text, cursor, x, y_tmp));
940 // look at previous position
942 if (cursor.pos() == 0) {
947 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
949 inset = checkInset(*text, cursor, x, y_tmp);
957 void BufferView::Pimpl::workAreaExpose()
959 static int work_area_width;
960 static unsigned int work_area_height;
962 bool const widthChange = workarea_.workWidth() != work_area_width;
963 bool const heightChange = workarea_.height() != work_area_height;
965 // update from work area
966 work_area_width = workarea_.workWidth();
967 work_area_height = workarea_.height();
970 // The visible LyXView need a resize
973 // Remove all texts from the textcache
974 // This is not _really_ what we want to do. What
975 // we really want to do is to delete in textcache
976 // that does not have a BufferView with matching
977 // width, but as long as we have only one BufferView
978 // deleting all gives the same result.
979 if (lyxerr.debugging())
980 textcache.show(lyxerr, "Expose delete all");
982 } else if (heightChange) {
983 // Rebuild image of current screen
985 // fitCursor() ensures we don't jump back
986 // to the start of the document on vertical
990 // The main window size has changed, repaint most stuff
992 } else if (screen_.get())
993 screen_->redraw(bv_->text, bv_);
995 // Grey box when we don't have a buffer
999 // always make sure that the scrollbar is sane.
1001 owner_->updateLayoutChoice();
1006 void BufferView::Pimpl::update()
1008 if (screen_.get() &&
1009 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1011 LyXText::text_status st = bv_->text->status();
1012 screen_->update(bv_->text, bv_);
1014 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1015 if (bv_->text->fullRebreak(bv_)) {
1016 st = LyXText::NEED_MORE_REFRESH;
1017 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1018 bv_->text->cursor.pos());
1021 bv_->text->status(bv_, st);
1022 screen_->update(bv_->text, bv_);
1024 // do this here instead of in the screen::update because of
1026 bv_->text->status(bv_, LyXText::UNCHANGED);
1032 // Values used when calling update:
1034 // -2 - update, move sel_cursor if selection, fitcursor
1035 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1036 // 0 - update, move sel_cursor if selection, fitcursor
1037 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1038 // 3 - update, move sel_cursor if selection
1041 // a simple redraw of the parts that need refresh
1043 // move sel_cursor if selection -
1044 // the text's sel_cursor is moved if there is selection is progress
1047 // fitCursor() is called and the scrollbar updated
1050 // the buffer is marked dirty.
1059 // UPDATE_ONLY = UPDATE;
1060 // UPDATE_SELECT = UPDATE | SELECT;
1061 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1062 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1064 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1065 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1066 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1067 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1068 // update(3) -> update(1) -> update(1) -> update(SELECT)
1070 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1072 owner_->updateLayoutChoice();
1074 if (!text->selection.set() && (f & SELECT)) {
1075 text->selection.cursor = text->cursor;
1078 text->fullRebreak(bv_);
1080 if (text->inset_owner) {
1081 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1082 updateInset(text->inset_owner, false);
1092 buffer_->markDirty();
1097 // Callback for cursor timer
1098 void BufferView::Pimpl::cursorToggle()
1100 // Quite a nice place for asyncron Inset updating, isn't it?
1101 // Actually no! This is run even if no buffer exist... so (Lgb)
1103 cursor_timeout.restart();
1108 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1109 if (pid == -1) // error find out what is wrong
1110 ; // ignore it for now.
1112 sigchldchecker(pid, &status);
1114 updatelist.update(bv_);
1116 if (!screen_.get()) {
1117 cursor_timeout.restart();
1121 if (!bv_->theLockingInset()) {
1122 screen_->cursorToggle(bv_);
1124 bv_->theLockingInset()->toggleInsetCursor(bv_);
1127 cursor_timeout.restart();
1131 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1133 if (!text->cursor.row()->previous())
1136 int y = text->first;
1137 if (text->inset_owner)
1138 y += bv_->text->first;
1139 Row * cursorrow = text->cursor.row();
1140 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1142 // This is to allow jumping over large insets
1143 if ((cursorrow == text->cursor.row()))
1144 text->cursorUp(bv_);
1146 if (text->inset_owner ||
1147 text->cursor.row()->height() < workarea_.height())
1148 screen_->draw(bv_->text, bv_,
1150 - text->cursor.row()->baseline()
1151 + text->cursor.row()->height()
1152 - workarea_.height() + 1 );
1157 void BufferView::Pimpl::cursorNext(LyXText * text)
1159 if (!text->cursor.row()->next())
1162 int y = text->first + workarea_.height();
1163 // if (text->inset_owner)
1164 // y += bv_->text->first;
1165 text->getRowNearY(y);
1167 Row * cursorrow = text->cursor.row();
1168 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1170 // This is to allow jumping over large insets
1171 if ((cursorrow == bv_->text->cursor.row()))
1172 text->cursorDown(bv_);
1174 if (text->inset_owner ||
1175 text->cursor.row()->height() < workarea_.height())
1176 screen_->draw(bv_->text, bv_, text->cursor.y() -
1177 text->cursor.row()->baseline());
1182 bool BufferView::Pimpl::available() const
1184 if (buffer_ && bv_->text) return true;
1189 void BufferView::Pimpl::beforeChange(LyXText * text)
1192 text->clearSelection();
1196 void BufferView::Pimpl::savePosition(unsigned int i)
1198 if (i >= saved_positions_num)
1200 saved_positions[i] = Position(buffer_->fileName(),
1201 bv_->text->cursor.par()->id(),
1202 bv_->text->cursor.pos());
1205 str << _("Saved bookmark") << ' ' << i;
1206 owner_->message(str.str().c_str());
1211 void BufferView::Pimpl::restorePosition(unsigned int i)
1213 if (i >= saved_positions_num)
1216 string const fname = saved_positions[i].filename;
1218 beforeChange(bv_->text);
1220 if (fname != buffer_->fileName()) {
1221 Buffer * b = bufferlist.exists(fname) ?
1222 bufferlist.getBuffer(fname) :
1223 bufferlist.loadLyXFile(fname); // don't ask, just load it
1224 if (b != 0 ) buffer(b);
1227 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1231 bv_->text->setCursor(bv_, par,
1232 min(par->size(), saved_positions[i].par_pos));
1234 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1237 str << _("Moved to bookmark") << ' ' << i;
1238 owner_->message(str.str().c_str());
1243 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1245 if (i >= saved_positions_num)
1248 return !saved_positions[i].filename.empty();
1252 void BufferView::Pimpl::setState()
1254 if (!lyxrc.rtl_support)
1257 LyXText * text = bv_->getLyXText();
1258 if (text->real_current_font.isRightToLeft()) {
1259 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1260 owner_->getIntl()->KeyMapSec();
1262 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1263 owner_->getIntl()->KeyMapPrim();
1268 void BufferView::Pimpl::insetSleep()
1270 if (bv_->theLockingInset() && !inset_slept) {
1271 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1272 bv_->theLockingInset()->insetUnlock(bv_);
1278 void BufferView::Pimpl::insetWakeup()
1280 if (bv_->theLockingInset() && inset_slept) {
1281 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1282 inset_slept = false;
1287 void BufferView::Pimpl::insetUnlock()
1289 if (bv_->theLockingInset()) {
1291 bv_->theLockingInset()->insetUnlock(bv_);
1292 bv_->theLockingInset(0);
1294 inset_slept = false;
1299 bool BufferView::Pimpl::focus() const
1301 return workarea_.hasFocus();
1305 void BufferView::Pimpl::focus(bool f)
1307 if (f) workarea_.setFocus();
1311 bool BufferView::Pimpl::active() const
1313 return workarea_.active();
1317 bool BufferView::Pimpl::belowMouse() const
1319 return workarea_.belowMouse();
1323 void BufferView::Pimpl::showCursor()
1325 if (screen_.get()) {
1326 if (bv_->theLockingInset())
1327 bv_->theLockingInset()->showInsetCursor(bv_);
1329 screen_->showCursor(bv_->text, bv_);
1334 void BufferView::Pimpl::hideCursor()
1336 if (screen_.get()) {
1337 if (!bv_->theLockingInset())
1338 // bv_->theLockingInset()->hideInsetCursor(bv_);
1340 screen_->hideCursor();
1345 void BufferView::Pimpl::toggleSelection(bool b)
1347 if (screen_.get()) {
1348 if (bv_->theLockingInset())
1349 bv_->theLockingInset()->toggleSelection(bv_, b);
1350 screen_->toggleSelection(bv_->text, bv_, b);
1355 void BufferView::Pimpl::toggleToggle()
1358 screen_->toggleToggle(bv_->text, bv_);
1362 void BufferView::Pimpl::center()
1364 beforeChange(bv_->text);
1365 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1366 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1368 screen_->draw(bv_->text, bv_, 0);
1370 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1375 void BufferView::Pimpl::pasteClipboard(bool asPara)
1377 if (!buffer_) return;
1379 screen_->hideCursor();
1380 beforeChange(bv_->text);
1382 string const clip(workarea_.getClipboard());
1384 if (clip.empty()) return;
1387 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1389 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1391 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1395 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1397 workarea_.putClipboard(stuff);
1402 * Dispatch functions for actions which can be valid for BufferView->text
1403 * and/or InsetText->text!!!
1408 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1410 LyXText * lt = bv_->getLyXText();
1412 if (selecting || lt->selection.mark()) {
1413 lt->setSelection(bv_);
1417 update(lt, BufferView::SELECT|BufferView::FITCUR);
1420 /* ---> Everytime the cursor is moved, show the current font state. */
1421 // should this too me moved out of this func?
1422 //owner->showState();
1427 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1429 LyXCursor cursor = bv_->getLyXText()->cursor;
1430 Buffer::inset_iterator it =
1431 find_if(Buffer::inset_iterator(
1432 cursor.par(), cursor.pos()),
1433 buffer_->inset_iterator_end(),
1434 lyx::compare_memfun(&Inset::lyxCode, code));
1435 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1439 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1441 string filename = filen;
1443 if (filename.empty()) {
1444 // Launch a file browser
1445 string initpath = lyxrc.document_path;
1448 string const trypath = owner_->buffer()->filePath();
1449 // If directory is writeable, use this as default.
1450 if (IsDirWriteable(trypath))
1454 FileDialog fileDlg(bv_->owner(),
1455 _("Select LyX document to insert"),
1457 make_pair(string(_("Documents|#o#O")),
1458 string(lyxrc.document_path)),
1459 make_pair(string(_("Examples|#E#e")),
1460 string(AddPath(system_lyxdir, "examples"))));
1462 FileDialog::Result result =
1463 fileDlg.Select(initpath,
1464 _("*.lyx| LyX Documents (*.lyx)"));
1466 if (result.first == FileDialog::Later)
1469 filename = result.second;
1471 // check selected filename
1472 if (filename.empty()) {
1473 owner_->message(_("Canceled."));
1478 // get absolute path of file and add ".lyx" to the filename if
1480 filename = FileSearch(string(), filename, "lyx");
1482 string const disp_fn(MakeDisplayPath(filename));
1485 s1 << _("Inserting document") << ' '
1486 << disp_fn << " ...";
1487 owner_->message(s1.str().c_str());
1488 bool const res = bv_->insertLyXFile(filename);
1491 str << _("Document") << ' ' << disp_fn
1492 << ' ' << _("inserted.");
1493 owner_->message(str.str().c_str());
1496 str << _("Could not insert document") << ' '
1498 owner_->message(str.str().c_str());
1503 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1505 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1506 << action <<"] arg[" << argument << "]" << endl;
1509 // --- Misc -------------------------------------------
1513 LyXText * lt = bv_->getLyXText();
1514 lt->toggleAppendix(bv_);
1517 | BufferView::FITCUR
1518 | BufferView::CHANGE);
1523 case LFUN_TOC_INSERT:
1525 InsetCommandParams p;
1526 p.setCmdName("tableofcontents");
1527 Inset * inset = new InsetTOC(p);
1528 if (!insertInset(inset, "Standard"))
1533 case LFUN_TABULAR_FEATURE:
1534 case LFUN_SCROLL_INSET:
1535 // this is not handled here as this funktion is only aktive
1536 // if we have a locking_inset and that one is (or contains)
1540 case LFUN_INSET_GRAPHICS:
1542 Inset * new_inset = new InsetGraphics;
1543 if (!insertInset(new_inset)) {
1546 // this is need because you don't use a inset->Edit()
1547 updateInset(new_inset, true);
1548 new_inset->edit(bv_);
1558 case LFUN_PASTESELECTION:
1560 bool asPara = false;
1561 if (argument == "paragraph")
1563 pasteClipboard(asPara);
1575 case LFUN_LAYOUT_COPY:
1576 bv_->copyEnvironment();
1579 case LFUN_LAYOUT_PASTE:
1580 bv_->pasteEnvironment();
1584 case LFUN_GOTOERROR:
1585 gotoInset(Inset::ERROR_CODE, false);
1589 gotoInset(Inset::IGNORE_CODE, false);
1592 case LFUN_REFERENCE_GOTO:
1594 vector<Inset::Code> tmp;
1595 tmp.push_back(Inset::LABEL_CODE);
1596 tmp.push_back(Inset::REF_CODE);
1597 gotoInset(tmp, true);
1601 case LFUN_HYPHENATION:
1602 specialChar(InsetSpecialChar::HYPHENATION);
1605 case LFUN_LIGATURE_BREAK:
1606 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1610 specialChar(InsetSpecialChar::LDOTS);
1613 case LFUN_END_OF_SENTENCE:
1614 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1617 case LFUN_MENU_SEPARATOR:
1618 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1626 changeDepth(bv_, bv_->getLyXText(), 0);
1629 case LFUN_DEPTH_MIN:
1630 changeDepth(bv_, bv_->getLyXText(), -1);
1633 case LFUN_DEPTH_PLUS:
1634 changeDepth(bv_, bv_->getLyXText(), 1);
1638 owner_->getDialogs()->setUserFreeFont();
1641 case LFUN_FILE_INSERT:
1642 MenuInsertLyXFile(argument);
1645 case LFUN_FILE_INSERT_ASCII_PARA:
1646 InsertAsciiFile(bv_, argument, true);
1649 case LFUN_FILE_INSERT_ASCII:
1650 InsertAsciiFile(bv_, argument, false);
1655 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1656 << argument << endl;
1658 // Derive layout number from given argument (string)
1659 // and current buffer's textclass (number). */
1660 textclass_type tclass = buffer_->params.textclass;
1661 pair <bool, layout_type> layout =
1662 textclasslist.NumberOfLayout(tclass, argument);
1664 // If the entry is obsolete, use the new one instead.
1666 string obs = textclasslist.Style(tclass, layout.second)
1669 layout = textclasslist.NumberOfLayout(tclass, obs);
1672 // see if we found the layout number:
1673 if (!layout.first) {
1674 owner_->getLyXFunc()->setErrorMessage(
1675 string(N_("Layout ")) + argument +
1680 if (current_layout != layout.second) {
1681 LyXText * lt = bv_->getLyXText();
1683 current_layout = layout.second;
1686 | BufferView::FITCUR);
1687 lt->setLayout(bv_, layout.second);
1688 owner_->setLayout(layout.second);
1691 | BufferView::FITCUR
1692 | BufferView::CHANGE);
1699 lang(bv_, argument);
1701 owner_->showState();
1706 owner_->showState();
1711 owner_->showState();
1716 owner_->showState();
1721 owner_->showState();
1726 owner_->showState();
1731 owner_->showState();
1736 owner_->showState();
1739 case LFUN_UNDERLINE:
1741 owner_->showState();
1744 case LFUN_FONT_SIZE:
1745 fontSize(bv_, argument);
1746 owner_->showState();
1749 case LFUN_FONT_STATE:
1750 owner_->getLyXFunc()->setMessage(currentState(bv_));
1753 case LFUN_UPCASE_WORD:
1755 LyXText * lt = bv_->getLyXText();
1759 | BufferView::FITCUR);
1760 lt->changeCase(bv_, LyXText::text_uppercase);
1761 if (lt->inset_owner)
1762 updateInset(lt->inset_owner, true);
1765 | BufferView::FITCUR
1766 | BufferView::CHANGE);
1770 case LFUN_LOWCASE_WORD:
1772 LyXText * lt = bv_->getLyXText();
1774 update(lt, BufferView::SELECT|BufferView::FITCUR);
1775 lt->changeCase(bv_, LyXText::text_lowercase);
1776 if (lt->inset_owner)
1777 updateInset(lt->inset_owner, true);
1780 | BufferView::FITCUR
1781 | BufferView::CHANGE);
1785 case LFUN_CAPITALIZE_WORD:
1787 LyXText * lt = bv_->getLyXText();
1789 update(lt, BufferView::SELECT|BufferView::FITCUR);
1790 lt->changeCase(bv_, LyXText::text_capitalization);
1791 if (lt->inset_owner)
1792 updateInset(lt->inset_owner, true);
1795 | BufferView::FITCUR
1796 | BufferView::CHANGE);
1800 case LFUN_TRANSPOSE_CHARS:
1802 LyXText * lt = bv_->getLyXText();
1804 update(lt, BufferView::SELECT|BufferView::FITCUR);
1805 lt->transposeChars(*bv_);
1806 if (lt->inset_owner)
1807 updateInset(lt->inset_owner, true);
1810 | BufferView::FITCUR
1811 | BufferView::CHANGE);
1816 case LFUN_INSERT_LABEL:
1817 MenuInsertLabel(bv_, argument);
1820 case LFUN_REF_INSERT:
1821 if (argument.empty()) {
1822 InsetCommandParams p("ref");
1823 owner_->getDialogs()->createRef(p.getAsString());
1825 InsetCommandParams p;
1826 p.setFromString(argument);
1828 InsetRef * inset = new InsetRef(p, *buffer_);
1829 if (!insertInset(inset))
1832 updateInset(inset, true);
1836 case LFUN_BOOKMARK_SAVE:
1837 savePosition(strToUnsignedInt(argument));
1840 case LFUN_BOOKMARK_GOTO:
1841 restorePosition(strToUnsignedInt(argument));
1846 string label(argument);
1847 if (label.empty()) {
1849 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1851 label = inset->getContents();
1856 if (!label.empty()) {
1857 //bv_->savePosition(0);
1858 if (!bv_->gotoLabel(label))
1859 Alert::alert(_("Error"),
1860 _("Couldn't find this label"),
1861 _("in current document."));
1866 // --- Cursor Movements -----------------------------
1869 LyXText * lt = bv_->getLyXText();
1871 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1872 if (!lt->selection.mark())
1874 update(lt, BufferView::SELECT|BufferView::FITCUR);
1876 lt->cursorLeft(bv_, false);
1877 if (lt->cursor.pos() < lt->cursor.par()->size()
1878 && lt->cursor.par()->isInset(lt->cursor.pos())
1879 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1880 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1881 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1883 tmpinset->edit(bv_, false);
1885 tmpinset->edit(bv_);
1889 lt->cursorRight(bv_, false);
1891 moveCursorUpdate(false);
1892 owner_->showState();
1898 // This is soooo ugly. Isn`t it possible to make
1899 // it simpler? (Lgb)
1900 LyXText * lt = bv_->getLyXText();
1901 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1902 if (!lt->selection.mark())
1904 update(lt, BufferView::SELECT|BufferView::FITCUR);
1905 LyXCursor const cur = lt->cursor;
1907 lt->cursorLeft(bv_, false);
1908 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1909 lt->cursor.pos() < lt->cursor.par()->size() &&
1910 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1911 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1912 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1913 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1915 tmpinset->edit(bv_);
1917 tmpinset->edit(bv_, false);
1921 lt->cursorRight(bv_, false);
1924 moveCursorUpdate(false);
1925 owner_->showState();
1931 LyXText * lt = bv_->getLyXText();
1933 if (!lt->selection.mark())
1935 update(lt, BufferView::UPDATE);
1938 moveCursorUpdate(false);
1939 owner_->showState();
1945 LyXText * lt = bv_->getLyXText();
1947 if (!lt->selection.mark())
1949 update(lt, BufferView::UPDATE);
1950 lt->cursorDown(bv_);
1952 moveCursorUpdate(false);
1953 owner_->showState();
1957 case LFUN_UP_PARAGRAPH:
1959 LyXText * lt = bv_->getLyXText();
1961 if (!lt->selection.mark())
1963 update(lt, BufferView::UPDATE);
1964 lt->cursorUpParagraph(bv_);
1966 moveCursorUpdate(false);
1967 owner_->showState();
1971 case LFUN_DOWN_PARAGRAPH:
1973 LyXText * lt = bv_->getLyXText();
1975 if (!lt->selection.mark())
1977 update(lt, BufferView::UPDATE);
1978 lt->cursorDownParagraph(bv_);
1980 moveCursorUpdate(false);
1981 owner_->showState();
1987 LyXText * lt = bv_->getLyXText();
1989 if (!lt->selection.mark())
1991 update(lt, BufferView::UPDATE);
1994 moveCursorUpdate(false);
1995 owner_->showState();
2001 LyXText * lt = bv_->getLyXText();
2003 if (!lt->selection.mark())
2005 update(lt, BufferView::UPDATE);
2008 moveCursorUpdate(false);
2009 owner_->showState();
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2019 update(lt, BufferView::SELECT|BufferView::FITCUR);
2020 lt->cursorHome(bv_);
2022 moveCursorUpdate(false);
2023 owner_->showState();
2029 LyXText * lt = bv_->getLyXText();
2031 if (!lt->selection.mark())
2034 BufferView::SELECT|BufferView::FITCUR);
2037 moveCursorUpdate(false);
2038 owner_->showState();
2042 case LFUN_SHIFT_TAB:
2045 LyXText * lt = bv_->getLyXText();
2047 if (!lt->selection.mark())
2050 BufferView::SELECT|BufferView::FITCUR);
2053 moveCursorUpdate(false);
2054 owner_->showState();
2058 case LFUN_WORDRIGHT:
2060 LyXText * lt = bv_->getLyXText();
2062 if (!lt->selection.mark())
2064 update(lt, BufferView::SELECT|BufferView::FITCUR);
2065 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2066 lt->cursorLeftOneWord(bv_);
2068 lt->cursorRightOneWord(bv_);
2070 moveCursorUpdate(false);
2071 owner_->showState();
2077 LyXText * lt = bv_->getLyXText();
2079 if (!lt->selection.mark())
2081 update(lt, BufferView::SELECT|BufferView::FITCUR);
2082 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2083 lt->cursorRightOneWord(bv_);
2085 lt->cursorLeftOneWord(bv_);
2087 moveCursorUpdate(false);
2088 owner_->showState();
2092 case LFUN_BEGINNINGBUF:
2094 LyXText * lt = bv_->getLyXText();
2096 if (!lt->selection.mark())
2099 BufferView::SELECT|BufferView::FITCUR);
2102 moveCursorUpdate(false);
2103 owner_->showState();
2109 LyXText * lt = bv_->getLyXText();
2111 if (!lt->selection.mark())
2114 BufferView::SELECT|BufferView::FITCUR);
2115 lt->cursorBottom(bv_);
2117 moveCursorUpdate(false);
2118 owner_->showState();
2122 /* cursor selection ---------------------------- */
2125 LyXText * lt = bv_->getLyXText();
2128 BufferView::SELECT|BufferView::FITCUR);
2129 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2130 lt->cursorLeft(bv_);
2132 lt->cursorRight(bv_);
2134 moveCursorUpdate(true);
2135 owner_->showState();
2141 LyXText * lt = bv_->getLyXText();
2144 BufferView::SELECT|BufferView::FITCUR);
2145 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2146 lt->cursorRight(bv_);
2148 lt->cursorLeft(bv_);
2150 moveCursorUpdate(true);
2151 owner_->showState();
2157 LyXText * lt = bv_->getLyXText();
2160 BufferView::SELECT|BufferView::FITCUR);
2163 moveCursorUpdate(true);
2164 owner_->showState();
2170 LyXText * lt = bv_->getLyXText();
2173 BufferView::SELECT|BufferView::FITCUR);
2174 lt->cursorDown(bv_);
2176 moveCursorUpdate(true);
2177 owner_->showState();
2181 case LFUN_UP_PARAGRAPHSEL:
2183 LyXText * lt = bv_->getLyXText();
2186 BufferView::SELECT|BufferView::FITCUR);
2187 lt->cursorUpParagraph(bv_);
2189 moveCursorUpdate(true);
2190 owner_->showState();
2194 case LFUN_DOWN_PARAGRAPHSEL:
2196 LyXText * lt = bv_->getLyXText();
2199 BufferView::SELECT|BufferView::FITCUR);
2200 lt->cursorDownParagraph(bv_);
2202 moveCursorUpdate(true);
2203 owner_->showState();
2209 LyXText * lt = bv_->getLyXText();
2211 update(lt, BufferView::SELECT|BufferView::FITCUR);
2214 moveCursorUpdate(true);
2215 owner_->showState();
2221 LyXText * lt = bv_->getLyXText();
2223 update(lt, BufferView::SELECT|BufferView::FITCUR);
2226 moveCursorUpdate(true);
2227 owner_->showState();
2233 LyXText * lt = bv_->getLyXText();
2235 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 lt->cursorHome(bv_);
2238 moveCursorUpdate(true);
2239 owner_->showState();
2245 LyXText * lt = bv_->getLyXText();
2247 update(lt, BufferView::SELECT|BufferView::FITCUR);
2250 moveCursorUpdate(true);
2251 owner_->showState();
2255 case LFUN_WORDRIGHTSEL:
2257 LyXText * lt = bv_->getLyXText();
2259 update(lt, BufferView::SELECT|BufferView::FITCUR);
2260 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2261 lt->cursorLeftOneWord(bv_);
2263 lt->cursorRightOneWord(bv_);
2265 moveCursorUpdate(true);
2266 owner_->showState();
2270 case LFUN_WORDLEFTSEL:
2272 LyXText * lt = bv_->getLyXText();
2274 update(lt, BufferView::SELECT|BufferView::FITCUR);
2275 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2276 lt->cursorRightOneWord(bv_);
2278 lt->cursorLeftOneWord(bv_);
2280 moveCursorUpdate(true);
2281 owner_->showState();
2285 case LFUN_BEGINNINGBUFSEL:
2287 LyXText * lt = bv_->getLyXText();
2289 if (lt->inset_owner)
2291 update(lt, BufferView::SELECT|BufferView::FITCUR);
2294 moveCursorUpdate(true);
2295 owner_->showState();
2299 case LFUN_ENDBUFSEL:
2301 LyXText * lt = bv_->getLyXText();
2303 if (lt->inset_owner)
2306 BufferView::SELECT|BufferView::FITCUR);
2307 lt->cursorBottom(bv_);
2309 moveCursorUpdate(true);
2310 owner_->showState();
2314 // --- text changing commands ------------------------
2315 case LFUN_BREAKLINE:
2317 LyXText * lt = bv_->getLyXText();
2320 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2323 | BufferView::FITCUR
2324 | BufferView::CHANGE);
2325 moveCursorUpdate(false);
2329 case LFUN_PROTECTEDSPACE:
2331 LyXText * lt = bv_->getLyXText();
2333 LyXLayout const & style = textclasslist
2334 .Style(buffer_->params.textclass,
2335 lt->cursor.par()->getLayout());
2337 if (style.free_spacing) {
2338 lt->insertChar(bv_, ' ');
2341 | BufferView::FITCUR
2342 | BufferView::CHANGE);
2346 moveCursorUpdate(false);
2352 LyXText * lt = bv_->getLyXText();
2354 if (lt->selection.mark()) {
2358 | BufferView::FITCUR);
2359 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2362 lt->selection.mark(true);
2365 | BufferView::FITCUR);
2366 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2368 lt->selection.cursor = lt->cursor;
2374 LyXText * lt = bv_->getLyXText();
2376 if (!lt->selection.set()) {
2378 lt->selection.cursor = lt->cursor;
2381 | BufferView::FITCUR
2382 | BufferView::CHANGE);
2383 // It is possible to make it a lot faster still
2384 // just comment out the line below...
2389 moveCursorUpdate(false);
2390 owner_->showState();
2395 case LFUN_DELETE_SKIP:
2397 LyXText * lt = bv_->getLyXText();
2399 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2401 LyXCursor cursor = lt->cursor;
2403 if (!lt->selection.set()) {
2404 if (cursor.pos() == cursor.par()->size()) {
2405 lt->cursorRight(bv_);
2406 cursor = lt->cursor;
2407 if (cursor.pos() == 0
2408 && !(cursor.par()->params().spaceTop()
2409 == VSpace (VSpace::NONE))) {
2412 cursor.par()->params().lineTop(),
2413 cursor.par()->params().lineBottom(),
2414 cursor.par()->params().pagebreakTop(),
2415 cursor.par()->params().pagebreakBottom(),
2416 VSpace(VSpace::NONE),
2417 cursor.par()->params().spaceBottom(),
2418 cursor.par()->params().spacing(),
2419 cursor.par()->params().align(),
2420 cursor.par()->params().labelWidthString(), 0);
2421 lt->cursorLeft(bv_);
2424 | BufferView::FITCUR
2425 | BufferView::CHANGE);
2427 lt->cursorLeft(bv_);
2429 lt->selection.cursor = lt->cursor;
2432 | BufferView::FITCUR
2433 | BufferView::CHANGE);
2437 lt->selection.cursor = lt->cursor;
2440 | BufferView::FITCUR
2441 | BufferView::CHANGE);
2449 /* -------> Delete word forward. */
2450 case LFUN_DELETE_WORD_FORWARD:
2451 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2452 bv_->getLyXText()->deleteWordForward(bv_);
2453 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2454 moveCursorUpdate(false);
2455 owner_->showState();
2458 /* -------> Delete word backward. */
2459 case LFUN_DELETE_WORD_BACKWARD:
2461 LyXText * lt = bv_->getLyXText();
2463 update(lt, BufferView::SELECT|BufferView::FITCUR);
2464 lt->deleteWordBackward(bv_);
2467 | BufferView::FITCUR
2468 | BufferView::CHANGE);
2469 moveCursorUpdate(false);
2470 owner_->showState();
2474 /* -------> Kill to end of line. */
2475 case LFUN_DELETE_LINE_FORWARD:
2477 LyXText * lt = bv_->getLyXText();
2479 update(lt, BufferView::SELECT|BufferView::FITCUR);
2480 lt->deleteLineForward(bv_);
2483 | BufferView::FITCUR
2484 | BufferView::CHANGE);
2485 moveCursorUpdate(false);
2489 /* -------> Set mark off. */
2492 LyXText * lt = bv_->getLyXText();
2495 update(lt, BufferView::SELECT|BufferView::FITCUR);
2496 lt->selection.cursor = lt->cursor;
2497 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2501 /* -------> Set mark on. */
2504 LyXText * lt = bv_->getLyXText();
2507 lt->selection.mark(true);
2508 update(lt, BufferView::SELECT|BufferView::FITCUR);
2509 lt->selection.cursor = lt->cursor;
2510 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2514 case LFUN_BACKSPACE:
2516 LyXText * lt = bv_->getLyXText();
2518 if (!lt->selection.set()) {
2519 if (owner_->getIntl()->getTrans().backspace()) {
2521 lt->selection.cursor = lt->cursor;
2524 | BufferView::FITCUR
2525 | BufferView::CHANGE);
2526 // It is possible to make it a lot faster still
2527 // just comment out the line below...
2533 owner_->showState();
2538 case LFUN_BACKSPACE_SKIP:
2540 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2541 LyXText * lt = bv_->getLyXText();
2543 LyXCursor cursor = lt->cursor;
2545 if (!lt->selection.set()) {
2546 if (cursor.pos() == 0
2547 && !(cursor.par()->params().spaceTop()
2548 == VSpace (VSpace::NONE))) {
2551 cursor.par()->params().lineTop(),
2552 cursor.par()->params().lineBottom(),
2553 cursor.par()->params().pagebreakTop(),
2554 cursor.par()->params().pagebreakBottom(),
2555 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2556 cursor.par()->params().spacing(),
2557 cursor.par()->params().align(),
2558 cursor.par()->params().labelWidthString(), 0);
2561 | BufferView::FITCUR
2562 | BufferView::CHANGE);
2565 lt->selection.cursor = cursor;
2568 | BufferView::FITCUR
2569 | BufferView::CHANGE);
2576 case LFUN_BREAKPARAGRAPH:
2578 LyXText * lt = bv_->getLyXText();
2581 lt->breakParagraph(bv_, 0);
2584 | BufferView::FITCUR
2585 | BufferView::CHANGE);
2586 lt->selection.cursor = lt->cursor;
2588 owner_->showState();
2592 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2594 LyXText * lt = bv_->getLyXText();
2597 lt->breakParagraph(bv_, 1);
2600 | BufferView::FITCUR
2601 | BufferView::CHANGE);
2602 lt->selection.cursor = lt->cursor;
2604 owner_->showState();
2608 case LFUN_BREAKPARAGRAPH_SKIP:
2610 // When at the beginning of a paragraph, remove
2611 // indentation and add a "defskip" at the top.
2612 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2613 LyXText * lt = bv_->getLyXText();
2615 LyXCursor cursor = lt->cursor;
2618 if (cursor.pos() == 0) {
2619 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2622 cursor.par()->params().lineTop(),
2623 cursor.par()->params().lineBottom(),
2624 cursor.par()->params().pagebreakTop(),
2625 cursor.par()->params().pagebreakBottom(),
2626 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2627 cursor.par()->params().spacing(),
2628 cursor.par()->params().align(),
2629 cursor.par()->params().labelWidthString(), 1);
2630 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2634 lt->breakParagraph(bv_, 0);
2635 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2640 | BufferView::FITCUR
2641 | BufferView::CHANGE);
2642 lt->selection.cursor = cursor;
2644 owner_->showState();
2648 case LFUN_PARAGRAPH_SPACING:
2650 LyXText * lt = bv_->getLyXText();
2652 Paragraph * par = lt->cursor.par();
2653 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2654 float cur_value = 1.0;
2655 if (cur_spacing == Spacing::Other) {
2656 cur_value = par->params().spacing().getValue();
2659 istringstream istr(argument.c_str());
2663 Spacing::Space new_spacing = cur_spacing;
2664 float new_value = cur_value;
2666 lyxerr << "Missing argument to `paragraph-spacing'"
2668 } else if (tmp == "single") {
2669 new_spacing = Spacing::Single;
2670 } else if (tmp == "onehalf") {
2671 new_spacing = Spacing::Onehalf;
2672 } else if (tmp == "double") {
2673 new_spacing = Spacing::Double;
2674 } else if (tmp == "other") {
2675 new_spacing = Spacing::Other;
2678 lyxerr << "new_value = " << tmpval << endl;
2681 } else if (tmp == "default") {
2682 new_spacing = Spacing::Default;
2684 lyxerr << _("Unknown spacing argument: ")
2685 << argument << endl;
2687 if (cur_spacing != new_spacing || cur_value != new_value) {
2688 par->params().spacing(Spacing(new_spacing, new_value));
2689 lt->redoParagraph(bv_);
2692 | BufferView::FITCUR
2693 | BufferView::CHANGE);
2698 case LFUN_INSET_TOGGLE:
2700 LyXText * lt = bv_->getLyXText();
2703 update(lt, BufferView::SELECT|BufferView::FITCUR);
2704 lt->toggleInset(bv_);
2705 update(lt, BufferView::SELECT|BufferView::FITCUR);
2717 InsetCommandParams p;
2718 if (action == LFUN_HTMLURL)
2719 p.setCmdName("htmlurl");
2721 p.setCmdName("url");
2722 owner_->getDialogs()->createUrl(p.getAsString());
2726 case LFUN_INSERT_URL:
2728 InsetCommandParams p;
2729 p.setFromString(argument);
2731 InsetUrl * inset = new InsetUrl(p);
2732 if (!insertInset(inset))
2735 updateInset(inset, true);
2739 case LFUN_INSET_TEXT:
2740 insertAndEditInset(new InsetText);
2743 case LFUN_INSET_ERT:
2744 insertAndEditInset(new InsetERT);
2747 case LFUN_INSET_EXTERNAL:
2748 insertAndEditInset(new InsetExternal);
2751 case LFUN_INSET_FOOTNOTE:
2752 insertAndEditInset(new InsetFoot);
2755 case LFUN_INSET_MARGINAL:
2756 insertAndEditInset(new InsetMarginal);
2759 case LFUN_INSET_MINIPAGE:
2760 insertAndEditInset(new InsetMinipage);
2763 case LFUN_INSERT_NOTE:
2764 insertAndEditInset(new InsetNote);
2767 case LFUN_INSET_FLOAT:
2768 // check if the float type exist
2769 if (floatList.typeExist(argument)) {
2770 insertAndEditInset(new InsetFloat(argument));
2772 lyxerr << "Non-existent float type: "
2773 << argument << endl;
2777 case LFUN_INSET_WIDE_FLOAT:
2779 // check if the float type exist
2780 if (floatList.typeExist(argument)) {
2781 InsetFloat * new_inset = new InsetFloat(argument);
2782 new_inset->wide(true);
2783 if (insertInset(new_inset))
2784 new_inset->edit(bv_);
2788 lyxerr << "Non-existent float type: "
2789 << argument << endl;
2796 case LFUN_INSET_LIST:
2797 insertAndEditInset(new InsetList);
2800 case LFUN_INSET_THEOREM:
2801 insertAndEditInset(new InsetTheorem);
2805 case LFUN_INSET_CAPTION:
2807 // Do we have a locking inset...
2808 if (bv_->theLockingInset()) {
2809 lyxerr << "Locking inset code: "
2810 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2811 InsetCaption * new_inset = new InsetCaption;
2812 new_inset->setOwner(bv_->theLockingInset());
2813 new_inset->setAutoBreakRows(true);
2814 new_inset->setDrawFrame(0, InsetText::LOCKED);
2815 new_inset->setFrameColor(0, LColor::captionframe);
2816 if (insertInset(new_inset))
2817 new_inset->edit(bv_);
2824 case LFUN_INSET_TABULAR:
2828 if (!argument.empty())
2829 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2830 InsetTabular * new_inset =
2831 new InsetTabular(*buffer_, r, c);
2833 bv_->getLyXText()->real_current_font.isRightToLeft();
2834 if (!open_new_inset(new_inset, rtl))
2839 // --- lyxserver commands ----------------------------
2841 case LFUN_CHARATCURSOR:
2843 pos_type pos = bv_->getLyXText()->cursor.pos();
2844 if (pos < bv_->getLyXText()->cursor.par()->size())
2845 owner_->getLyXFunc()->setMessage(
2846 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2848 owner_->getLyXFunc()->setMessage("EOF");
2853 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2855 + tostr(bv_->getLyXText()->cursor.y()));
2862 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2863 lyxerr << "SETXY: Could not parse coordinates in '"
2864 << argument << std::endl;
2866 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2870 case LFUN_GETLAYOUT:
2871 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2876 LyXFont & font = bv_->getLyXText()->current_font;
2877 if (font.shape() == LyXFont::ITALIC_SHAPE)
2878 owner_->getLyXFunc()->setMessage("E");
2879 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2880 owner_->getLyXFunc()->setMessage("N");
2882 owner_->getLyXFunc()->setMessage("0");
2887 // --- accented characters ---------------------------
2890 case LFUN_CIRCUMFLEX:
2900 case LFUN_SPECIAL_CARON:
2903 case LFUN_HUNG_UMLAUT:
2906 if (argument.empty()) {
2908 owner_->getLyXFunc()->handleKeyFunc(action);
2910 owner_->getLyXFunc()->handleKeyFunc(action);
2911 owner_->getIntl()->getTrans()
2912 .TranslateAndInsert(argument[0], bv_->getLyXText());
2913 update(bv_->getLyXText(),
2915 | BufferView::FITCUR
2916 | BufferView::CHANGE);
2920 case LFUN_MATH_MACRO:
2921 mathDispatchMathMacro(bv_, argument);
2924 case LFUN_MATH_DELIM:
2925 mathDispatchMathDelim(bv_, argument);
2928 case LFUN_INSERT_MATRIX:
2929 mathDispatchInsertMatrix(bv_, argument);
2932 case LFUN_INSERT_MATH:
2933 mathDispatchInsertMath(bv_, argument);
2936 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2937 mathDispatchMathImportSelection(bv_, argument);
2940 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2941 mathDispatchMathDisplay(bv_, argument);
2944 case LFUN_MATH_MODE: // Open or create an inlined math inset
2945 mathDispatchMathMode(bv_, argument);
2948 case LFUN_GREEK: // Insert a single greek letter
2949 mathDispatchGreek(bv_, argument);
2952 case LFUN_CITATION_INSERT:
2954 InsetCommandParams p;
2955 p.setFromString( argument );
2957 InsetCitation * inset = new InsetCitation( p );
2958 if (!insertInset(inset))
2961 updateInset( inset, true );
2965 case LFUN_INSERT_BIBTEX:
2967 // ale970405+lasgoutt970425
2968 // The argument can be up to two tokens separated
2969 // by a space. The first one is the bibstyle.
2970 string const db = token(argument, ' ', 0);
2971 string const bibstyle = token(argument, ' ', 1);
2973 InsetCommandParams p( "BibTeX", db, bibstyle );
2974 InsetBibtex * inset = new InsetBibtex(p);
2976 if (insertInset(inset)) {
2977 if (argument.empty())
2984 // BibTeX data bases
2985 case LFUN_BIBDB_ADD:
2987 InsetBibtex * inset =
2988 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2990 inset->addDatabase(argument);
2995 case LFUN_BIBDB_DEL:
2997 InsetBibtex * inset =
2998 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3000 inset->delDatabase(argument);
3005 case LFUN_BIBTEX_STYLE:
3007 InsetBibtex * inset =
3008 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3010 inset->setOptions(argument);
3015 case LFUN_INDEX_CREATE:
3017 InsetCommandParams p("index");
3018 if (argument.empty()) {
3019 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3020 p.setContents(idxstring);
3022 p.setContents(argument);
3025 owner_->getDialogs()->createIndex(p.getAsString());
3029 case LFUN_INDEX_INSERT:
3031 InsetCommandParams p;
3032 p.setFromString(argument);
3033 InsetIndex * inset = new InsetIndex(p);
3035 if (!insertInset(inset))
3038 updateInset(inset, true);
3042 case LFUN_INDEX_INSERT_LAST:
3044 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3045 if (!idxstring.empty()) {
3046 owner_->message(_("Word `")
3047 + idxstring + _(("' indexed.")));
3048 InsetCommandParams p("index", idxstring);
3049 InsetIndex * inset = new InsetIndex(p);
3051 if (!insertInset(inset))
3054 updateInset(inset, true);
3059 case LFUN_INDEX_PRINT:
3061 InsetCommandParams p("printindex");
3062 Inset * inset = new InsetPrintIndex(p);
3063 if (!insertInset(inset, "Standard"))
3068 case LFUN_PARENTINSERT:
3070 lyxerr << "arg " << argument << endl;
3071 InsetCommandParams p( "lyxparent", argument );
3072 Inset * inset = new InsetParent(p, *buffer_);
3073 if (!insertInset(inset, "Standard"))
3079 case LFUN_CHILD_INSERT:
3081 InsetInclude::Params p;
3082 p.cparams.setFromString(argument);
3083 p.masterFilename_ = buffer_->fileName();
3085 InsetInclude * inset = new InsetInclude(p);
3086 if (!insertInset(inset))
3089 updateInset(inset, true);
3090 bv_->owner()->getDialogs()->showInclude(inset);
3095 case LFUN_FLOAT_LIST:
3097 // We should check the argument for validity. (Lgb)
3098 Inset * inset = new InsetFloatList(argument);
3099 if (!insertInset(inset, "Standard"))
3104 case LFUN_THESAURUS_ENTRY:
3106 string arg = argument;
3109 arg = bv_->getLyXText()->selectionAsString(buffer_,
3113 if (arg.size() > 100 || arg.empty()) {
3114 // Get word or selection
3115 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3116 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3117 // FIXME: where is getLyXText()->unselect(bv_) ?
3121 bv_->owner()->getDialogs()->showThesaurus(arg);
3125 case LFUN_SELFINSERT:
3127 if (argument.empty()) break;
3129 /* Automatically delete the currently selected
3130 * text and replace it with what is being
3131 * typed in now. Depends on lyxrc settings
3132 * "auto_region_delete", which defaults to
3135 LyXText * lt = bv_->getLyXText();
3137 if (lyxrc.auto_region_delete) {
3138 if (lt->selection.set()) {
3139 lt->cutSelection(bv_, false, false);
3142 | BufferView::FITCUR
3143 | BufferView::CHANGE);
3148 LyXFont const old_font(lt->real_current_font);
3150 string::const_iterator cit = argument.begin();
3151 string::const_iterator end = argument.end();
3152 for (; cit != end; ++cit) {
3153 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3158 | BufferView::FITCUR
3159 | BufferView::CHANGE);
3161 lt->selection.cursor = lt->cursor;
3162 moveCursorUpdate(false);
3164 // real_current_font.number can change so we need to
3165 // update the minibuffer
3166 if (old_font != lt->real_current_font)
3167 owner_->showState();
3172 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3174 time_t now_time_t = time(NULL);
3175 struct tm * now_tm = localtime(&now_time_t);
3176 setlocale(LC_TIME, "");
3178 if (!argument.empty())
3181 arg = lyxrc.date_insert_format;
3183 int const datetmp_len =
3184 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3186 LyXText * lt = bv_->getLyXText();
3188 for (int i = 0; i < datetmp_len; i++) {
3189 lt->insertChar(bv_, datetmp[i]);
3192 | BufferView::FITCUR
3193 | BufferView::CHANGE);
3196 lt->selection.cursor = lt->cursor;
3197 moveCursorUpdate(false);
3201 case LFUN_UNKNOWN_ACTION:
3202 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3213 void BufferView::Pimpl::newline()
3216 LyXText * lt = bv_->getLyXText();
3220 | BufferView::FITCUR);
3221 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3224 | BufferView::FITCUR
3225 | BufferView::CHANGE);
3230 void BufferView::Pimpl::hfill()
3233 LyXText * lt = bv_->getLyXText();
3237 | BufferView::FITCUR);
3238 lt->insertChar(bv_, Paragraph::META_HFILL);
3241 | BufferView::FITCUR
3242 | BufferView::CHANGE);
3247 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3251 update(lt, BufferView::SELECT|BufferView::FITCUR);
3252 InsetSpecialChar * new_inset =
3253 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3254 #ifdef WITH_WARNINGS
3255 #warning Why is this code different from specialChar() below? (JMarc)
3256 // the code in specialChar is a generic version of what used to exist
3257 // for other special chars. I did not merge this case because of the
3258 // call to updateInset(), but what does it do?
3260 if (!insertInset(new_inset))
3263 updateInset(new_inset, true);
3268 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3271 LyXText * lt = bv_->getLyXText();
3274 update(lt, BufferView::SELECT|BufferView::FITCUR);
3275 InsetSpecialChar * new_inset =
3276 new InsetSpecialChar(kind);
3277 if (!insertInset(new_inset))
3283 void BufferView::Pimpl::smartQuote()
3285 LyXText const * lt = bv_->getLyXText();
3286 Paragraph const * par = lt->cursor.par();
3287 pos_type pos = lt->cursor.pos();
3291 || (par->isInset(pos - 1)
3292 && par->getInset(pos - 1)->isSpace()))
3295 c = par->getChar(pos - 1);
3300 LyXLayout const & style = textclasslist.Style(
3301 bv_->buffer()->params.textclass, par->getLayout());
3303 if (style.pass_thru ||
3304 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3305 Dispatch(LFUN_SELFINSERT, "\"");
3309 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3311 if (insertInset(inset))
3318 // Open and lock an updatable inset
3319 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3321 LyXText * lt = bv_->getLyXText();
3325 if (!insertInset(new_inset)) {
3329 new_inset->edit(bv_, !behind);
3334 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3336 // if we are in a locking inset we should try to insert the
3337 // inset there otherwise this is a illegal function now
3338 if (bv_->theLockingInset()) {
3339 if (bv_->theLockingInset()->insetAllowed(inset))
3340 return bv_->theLockingInset()->insertInset(bv_, inset);
3344 // not quite sure if we want this...
3345 setCursorParUndo(bv_);
3348 beforeChange(bv_->text);
3349 if (!lout.empty()) {
3350 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3351 bv_->text->breakParagraph(bv_);
3352 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3354 if (bv_->text->cursor.par()->size()) {
3355 bv_->text->cursorLeft(bv_);
3357 bv_->text->breakParagraph(bv_);
3358 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3361 pair<bool, layout_type> lres =
3362 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3363 layout_type lay = 0;
3364 if (lres.first != false) {
3368 // layout not fount using default "Standard" (0)
3372 bv_->text->setLayout(bv_, lay);
3374 bv_->text->setParagraph(bv_, 0, 0,
3376 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3384 bv_->text->insertInset(bv_, inset);
3385 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3392 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3397 // first check for locking insets
3398 if (bv_->theLockingInset()) {
3399 if (bv_->theLockingInset() == inset) {
3400 if (bv_->text->updateInset(bv_, inset)) {
3403 buffer_->markDirty();
3408 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3409 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3412 buffer_->markDirty();
3420 // then check the current buffer
3423 update(bv_->text, BufferView::UPDATE);
3424 if (bv_->text->updateInset(bv_, inset)) {
3428 | BufferView::FITCUR
3429 | BufferView::CHANGE);
3431 update(bv_->text, SELECT);
3439 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3442 if (!available()) return;
3445 beforeChange(bv_->text);
3446 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3448 LyXCursor const & cursor = bv_->text->cursor;
3452 cursor.par()->isInset(cursor.pos())) {
3453 Inset const * inset = cursor.par()->getInset(cursor.pos());
3454 if (find(codes.begin(), codes.end(), inset->lyxCode())
3457 static_cast<InsetCommand const *>(inset)->getContents();
3461 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3462 if (bv_->text->cursor.pos()
3463 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3464 LyXCursor tmp = bv_->text->cursor;
3465 bv_->text->cursor.par(bv_->text->ownerParagraph());
3466 bv_->text->cursor.pos(0);
3467 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3468 bv_->text->cursor = tmp;
3469 bv_->owner()->message(_("No more insets"));
3472 bv_->owner()->message(_("No more insets"));
3475 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3476 bv_->text->selection.cursor = bv_->text->cursor;
3480 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3482 gotoInset(vector<Inset::Code>(1, code), same_content);