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;
408 long const work_height = workarea_.height();
410 if (text_height <= work_height) {
411 workarea_.setScrollbarBounds(0.0, 0.0);
412 current_scrollbar_value = bv_->text->first;
413 workarea_.setScrollbar(current_scrollbar_value, 1.0);
417 double const lineh = bv_->text->defaultHeight();
418 double const slider_size =
419 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
421 static long old_text_height;
422 static double old_lineh;
423 static double old_slider_size;
425 if (text_height != old_text_height) {
426 workarea_.setScrollbarBounds(0.0,
427 text_height - work_height);
428 old_text_height = text_height;
430 if (lineh != old_lineh) {
431 workarea_.setScrollbarIncrements(lineh);
434 if (current_scrollbar_value != bv_->text->first
435 || slider_size != old_slider_size) {
436 current_scrollbar_value = bv_->text->first;
437 workarea_.setScrollbar(current_scrollbar_value, slider_size);
438 old_slider_size = slider_size;
443 // Callback for scrollbar slider
444 void BufferView::Pimpl::scrollCB(double value)
446 if (!buffer_) return;
448 current_scrollbar_value = long(value);
450 if (current_scrollbar_value < 0)
451 current_scrollbar_value = 0;
456 screen_->draw(bv_->text, bv_, current_scrollbar_value);
458 if (!lyxrc.cursor_follows_scrollbar) {
463 LyXText * vbt = bv_->text;
465 int const height = vbt->defaultHeight();
466 int const first = static_cast<int>((bv_->text->first + height));
467 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
469 if (vbt->cursor.y() < first)
470 vbt->setCursorFromCoordinates(bv_, 0, first);
471 else if (vbt->cursor.y() > last)
472 vbt->setCursorFromCoordinates(bv_, 0, last);
478 int BufferView::Pimpl::scrollUp(long time)
480 if (!buffer_) return 0;
481 if (!screen_.get()) return 0;
483 double value = workarea_.getScrollbarValue();
485 if (value == 0) return 0;
487 float add_value = (bv_->text->defaultHeight()
488 + float(time) * float(time) * 0.125);
490 if (add_value > workarea_.height())
491 add_value = float(workarea_.height() -
492 bv_->text->defaultHeight());
499 workarea_.setScrollbarValue(value);
506 int BufferView::Pimpl::scrollDown(long time)
508 if (!buffer_) return 0;
509 if (!screen_.get()) return 0;
511 double value = workarea_.getScrollbarValue();
512 pair<float, float> p = workarea_.getScrollbarBounds();
513 double const max = p.second;
515 if (value == max) return 0;
517 float add_value = (bv_->text->defaultHeight()
518 + float(time) * float(time) * 0.125);
520 if (add_value > workarea_.height())
521 add_value = float(workarea_.height() -
522 bv_->text->defaultHeight());
529 workarea_.setScrollbarValue(value);
536 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
538 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
542 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
544 // Only use motion with button 1
545 if (!(state & Button1MotionMask))
548 if (!buffer_ || !screen_.get()) return;
550 // Check for inset locking
551 if (bv_->theLockingInset()) {
552 LyXCursor cursor = bv_->text->cursor;
553 LyXFont font = bv_->text->getFont(buffer_,
554 cursor.par(), cursor.pos());
555 int width = bv_->theLockingInset()->width(bv_, font);
556 int inset_x = font.isVisibleRightToLeft()
557 ? cursor.x() - width : cursor.x();
558 int start_x = inset_x + bv_->theLockingInset()->scroll();
559 bv_->theLockingInset()->
560 insetMotionNotify(bv_,
562 y - cursor.y() + bv_->text->first,
567 /* The test for not selection possible is needed, that only motion
568 events are used, where the bottom press event was on
569 the drawing area too */
570 if (!selection_possible)
573 screen_->hideCursor();
575 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
577 if (!bv_->text->selection.set())
578 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
580 bv_->text->setSelection(bv_);
581 screen_->toggleToggle(bv_->text, bv_);
587 // Single-click on work area
588 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
591 if (!buffer_ || !screen_.get()) return;
593 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
595 // ok ok, this is a hack.
596 if (button == 4 || button == 5) {
599 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
602 scrollDown(lyxrc.wheel_jump);
607 if (bv_->theLockingInset()) {
608 // We are in inset locking mode
610 /* Check whether the inset was hit. If not reset mode,
611 otherwise give the event to the inset */
612 if (inset_hit == bv_->theLockingInset()) {
613 bv_->theLockingInset()->
614 insetButtonPress(bv_,xpos, ypos,button);
617 bv_->unlockInset(bv_->theLockingInset());
622 selection_possible = true;
623 screen_->hideCursor();
625 int const screen_first = bv_->text->first;
627 // Middle button press pastes if we have a selection
628 bool paste_internally = false;
630 && bv_->text->selection.set()) {
631 owner_->getLyXFunc()->dispatch(LFUN_COPY);
632 paste_internally = true;
635 // Clear the selection
636 screen_->toggleSelection(bv_->text, bv_);
637 bv_->text->clearSelection();
638 bv_->text->fullRebreak(bv_);
642 // Single left click in math inset?
643 if (isHighlyEditableInset(inset_hit)) {
644 // Highly editable inset, like math
645 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
646 selection_possible = false;
647 owner_->updateLayoutChoice();
648 owner_->message(inset->editMessage());
649 inset->insetButtonPress(bv_, xpos, ypos, button);
650 inset->edit(bv_, xpos, ypos, button);
654 // Right click on a footnote flag opens float menu
656 selection_possible = false;
660 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
661 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
663 bv_->text->selection.cursor = bv_->text->cursor;
664 bv_->text->cursor.x_fix(bv_->text->cursor.x());
666 owner_->updateLayoutChoice();
668 selection_possible = false;
671 // Insert primary selection with middle mouse
672 // if there is a local selection in the current buffer,
675 if (paste_internally)
676 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
678 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
680 selection_possible = false;
686 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
692 LyXText * text = bv_->getLyXText();
694 if (text->bv_owner && bv_->theLockingInset())
697 if (screen_.get() && button == 1) {
698 if (text->bv_owner) {
699 screen_->hideCursor();
700 screen_->toggleSelection(text, bv_);
701 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
702 screen_->toggleSelection(text, bv_, false);
704 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
706 /* This will fit the cursor on the screen
708 update(text, BufferView::SELECT|BufferView::FITCUR);
713 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
719 LyXText * text = bv_->getLyXText();
721 if (text->bv_owner && bv_->theLockingInset())
724 if (screen_.get() && (button == 1)) {
725 if (text->bv_owner) {
726 screen_->hideCursor();
727 screen_->toggleSelection(text, bv_);
729 text->cursorHome(bv_);
730 text->selection.cursor = text->cursor;
731 text->cursorEnd(bv_);
732 text->setSelection(bv_);
733 if (text->bv_owner) {
734 screen_->toggleSelection(text, bv_, false);
736 /* This will fit the cursor on the screen
738 update(text, BufferView::SELECT|BufferView::FITCUR);
743 void BufferView::Pimpl::selectionRequested()
745 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
748 workarea_.putClipboard(sel);
753 void BufferView::Pimpl::enterView()
755 if (active() && available()) {
756 SetXtermCursor(workarea_.getWin());
757 using_xterm_cursor = true;
762 void BufferView::Pimpl::leaveView()
764 if (using_xterm_cursor) {
765 XUndefineCursor(fl_get_display(), workarea_.getWin());
766 using_xterm_cursor = false;
771 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
774 if (!buffer_ || !screen_.get()) return;
776 // If we hit an inset, we have the inset coordinates in these
777 // and inset_hit points to the inset. If we do not hit an
778 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
779 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
781 if (bv_->theLockingInset()) {
782 // We are in inset locking mode.
784 /* LyX does a kind of work-area grabbing for insets.
785 Only a ButtonPress Event outside the inset will
786 force a insetUnlock. */
787 bv_->theLockingInset()->
788 insetButtonRelease(bv_, x, y, button);
792 selection_possible = false;
799 workarea_.haveSelection(bv_->getLyXText()->selection.set());
804 owner_->updateMenubar();
805 owner_->updateToolbar();
807 // Did we hit an editable inset?
809 // Inset like error, notes and figures
810 selection_possible = false;
812 // if we reach this point with a selection, it
813 // must mean we are currently selecting.
814 // But we don't want to open the inset
815 // because that is annoying for the user.
816 // So just pretend we didn't hit it.
817 // this is OK because a "kosher" ButtonRelease
818 // will follow a ButtonPress that clears
820 // Note this also fixes selection drawing
821 // problems if we end up opening an inset
822 if (bv_->getLyXText()->selection.set())
825 // CHECK fix this proper in 0.13
826 // well, maybe 13.0 !!!!!!!!!
828 // Following a ref shouldn't issue
829 // a push on the undo-stack
830 // anylonger, now that we have
831 // keybindings for following
832 // references and returning from
833 // references. IMHO though, it
834 // should be the inset's own business
835 // to push or not push on the undo
836 // stack. They don't *have* to
837 // alter the document...
839 // ...or maybe the SetCursorParUndo()
840 // below isn't necessary at all anylonger?
841 if (inset_hit->lyxCode() == Inset::REF_CODE) {
842 setCursorParUndo(bv_);
845 owner_->message(inset_hit->editMessage());
847 if (isHighlyEditableInset(inset_hit)) {
848 // Highly editable inset, like math
849 UpdatableInset *inset = (UpdatableInset *)inset_hit;
850 inset->insetButtonRelease(bv_, x, y, button);
852 inset_hit->insetButtonRelease(bv_, x, y, button);
853 inset_hit->edit(bv_, x, y, button);
858 // Maybe we want to edit a bibitem ale970302
859 if (bv_->text->cursor.par()->bibkey && x < 20 +
860 bibitemMaxWidth(bv_, textclasslist.
862 params.textclass).defaultfont())) {
863 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
870 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
871 LyXCursor const & cursor) const
873 Paragraph /*const*/ & par = *cursor.par();
874 pos_type const pos = cursor.pos();
876 lyx::Assert(par.getInset(pos));
878 Inset const & inset(*par.getInset(pos));
880 LyXFont const & font = text.getFont(buffer_, &par, pos);
882 int const width = inset.width(bv_, font);
883 int const inset_x = font.isVisibleRightToLeft()
884 ? (cursor.x() - width) : cursor.x();
887 inset_x + inset.scroll(),
889 cursor.y() - inset.ascent(bv_, font),
890 cursor.y() + inset.descent(bv_, font));
894 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
895 LyXCursor const & cursor,
896 int & x, int & y) const
898 pos_type const pos(cursor.pos());
899 Paragraph /*const*/ & par(*cursor.par());
901 if (pos >= par.size() || !par.isInset(pos)) {
905 Inset /*const*/ * inset = par.getInset(pos);
907 if (!isEditableInset(inset)) {
911 Box b(insetDimensions(text, cursor));
913 if (!b.contained(x, y)) {
914 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
915 << " box " << b << endl;
919 text.setCursor(bv_, &par, pos, true);
922 // The origin of an inset is on the baseline
923 y -= (text.cursor.y());
929 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
934 int y_tmp = y + text->first;
937 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
939 Inset * inset(checkInset(*text, cursor, x, y_tmp));
946 // look at previous position
948 if (cursor.pos() == 0) {
953 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
955 inset = checkInset(*text, cursor, x, y_tmp);
963 void BufferView::Pimpl::workAreaExpose()
965 static int work_area_width;
966 static unsigned int work_area_height;
968 bool const widthChange = workarea_.workWidth() != work_area_width;
969 bool const heightChange = workarea_.height() != work_area_height;
971 // update from work area
972 work_area_width = workarea_.workWidth();
973 work_area_height = workarea_.height();
976 // The visible LyXView need a resize
979 // Remove all texts from the textcache
980 // This is not _really_ what we want to do. What
981 // we really want to do is to delete in textcache
982 // that does not have a BufferView with matching
983 // width, but as long as we have only one BufferView
984 // deleting all gives the same result.
985 if (lyxerr.debugging())
986 textcache.show(lyxerr, "Expose delete all");
988 } else if (heightChange) {
989 // Rebuild image of current screen
991 // fitCursor() ensures we don't jump back
992 // to the start of the document on vertical
996 // The main window size has changed, repaint most stuff
998 } else if (screen_.get())
999 screen_->redraw(bv_->text, bv_);
1001 // Grey box when we don't have a buffer
1002 workarea_.greyOut();
1005 // always make sure that the scrollbar is sane.
1007 owner_->updateLayoutChoice();
1012 void BufferView::Pimpl::update()
1014 if (screen_.get() &&
1015 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1017 LyXText::text_status st = bv_->text->status();
1018 screen_->update(bv_->text, bv_);
1020 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1021 if (bv_->text->fullRebreak(bv_)) {
1022 st = LyXText::NEED_MORE_REFRESH;
1023 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1024 bv_->text->cursor.pos());
1027 bv_->text->status(bv_, st);
1028 screen_->update(bv_->text, bv_);
1030 // do this here instead of in the screen::update because of
1032 bv_->text->status(bv_, LyXText::UNCHANGED);
1038 // Values used when calling update:
1040 // -2 - update, move sel_cursor if selection, fitcursor
1041 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1042 // 0 - update, move sel_cursor if selection, fitcursor
1043 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1044 // 3 - update, move sel_cursor if selection
1047 // a simple redraw of the parts that need refresh
1049 // move sel_cursor if selection -
1050 // the text's sel_cursor is moved if there is selection is progress
1053 // fitCursor() is called and the scrollbar updated
1056 // the buffer is marked dirty.
1065 // UPDATE_ONLY = UPDATE;
1066 // UPDATE_SELECT = UPDATE | SELECT;
1067 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1068 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1070 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1071 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1072 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1073 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1074 // update(3) -> update(1) -> update(1) -> update(SELECT)
1076 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1078 owner_->updateLayoutChoice();
1080 if (!text->selection.set() && (f & SELECT)) {
1081 text->selection.cursor = text->cursor;
1084 text->fullRebreak(bv_);
1086 if (text->inset_owner) {
1087 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1088 updateInset(text->inset_owner, false);
1098 buffer_->markDirty();
1103 // Callback for cursor timer
1104 void BufferView::Pimpl::cursorToggle()
1106 // Quite a nice place for asyncron Inset updating, isn't it?
1107 // Actually no! This is run even if no buffer exist... so (Lgb)
1109 cursor_timeout.restart();
1114 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1115 if (pid == -1) // error find out what is wrong
1116 ; // ignore it for now.
1118 sigchldchecker(pid, &status);
1120 updatelist.update(bv_);
1122 if (!screen_.get()) {
1123 cursor_timeout.restart();
1127 if (!bv_->theLockingInset()) {
1128 screen_->cursorToggle(bv_);
1130 bv_->theLockingInset()->toggleInsetCursor(bv_);
1133 cursor_timeout.restart();
1137 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1139 if (!text->cursor.row()->previous())
1142 int y = text->first;
1143 if (text->inset_owner)
1144 y += bv_->text->first;
1145 Row * cursorrow = text->cursor.row();
1146 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1148 // This is to allow jumping over large insets
1149 if ((cursorrow == text->cursor.row()))
1150 text->cursorUp(bv_);
1152 if (text->inset_owner ||
1153 text->cursor.row()->height() < workarea_.height())
1154 screen_->draw(bv_->text, bv_,
1156 - text->cursor.row()->baseline()
1157 + text->cursor.row()->height()
1158 - workarea_.height() + 1 );
1163 void BufferView::Pimpl::cursorNext(LyXText * text)
1165 if (!text->cursor.row()->next())
1168 int y = text->first + workarea_.height();
1169 // if (text->inset_owner)
1170 // y += bv_->text->first;
1171 text->getRowNearY(y);
1173 Row * cursorrow = text->cursor.row();
1174 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1176 // This is to allow jumping over large insets
1177 if ((cursorrow == bv_->text->cursor.row()))
1178 text->cursorDown(bv_);
1180 if (text->inset_owner ||
1181 text->cursor.row()->height() < workarea_.height())
1182 screen_->draw(bv_->text, bv_, text->cursor.y() -
1183 text->cursor.row()->baseline());
1188 bool BufferView::Pimpl::available() const
1190 if (buffer_ && bv_->text) return true;
1195 void BufferView::Pimpl::beforeChange(LyXText * text)
1198 text->clearSelection();
1202 void BufferView::Pimpl::savePosition(unsigned int i)
1204 if (i >= saved_positions_num)
1206 saved_positions[i] = Position(buffer_->fileName(),
1207 bv_->text->cursor.par()->id(),
1208 bv_->text->cursor.pos());
1211 str << _("Saved bookmark") << ' ' << i;
1212 owner_->message(str.str().c_str());
1217 void BufferView::Pimpl::restorePosition(unsigned int i)
1219 if (i >= saved_positions_num)
1222 string const fname = saved_positions[i].filename;
1224 beforeChange(bv_->text);
1226 if (fname != buffer_->fileName()) {
1227 Buffer * b = bufferlist.exists(fname) ?
1228 bufferlist.getBuffer(fname) :
1229 bufferlist.loadLyXFile(fname); // don't ask, just load it
1230 if (b != 0 ) buffer(b);
1233 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1237 bv_->text->setCursor(bv_, par,
1238 min(par->size(), saved_positions[i].par_pos));
1240 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1243 str << _("Moved to bookmark") << ' ' << i;
1244 owner_->message(str.str().c_str());
1249 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1251 if (i >= saved_positions_num)
1254 return !saved_positions[i].filename.empty();
1258 void BufferView::Pimpl::setState()
1260 if (!lyxrc.rtl_support)
1263 LyXText * text = bv_->getLyXText();
1264 if (text->real_current_font.isRightToLeft()) {
1265 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1266 owner_->getIntl()->KeyMapSec();
1268 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1269 owner_->getIntl()->KeyMapPrim();
1274 void BufferView::Pimpl::insetSleep()
1276 if (bv_->theLockingInset() && !inset_slept) {
1277 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1278 bv_->theLockingInset()->insetUnlock(bv_);
1284 void BufferView::Pimpl::insetWakeup()
1286 if (bv_->theLockingInset() && inset_slept) {
1287 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1288 inset_slept = false;
1293 void BufferView::Pimpl::insetUnlock()
1295 if (bv_->theLockingInset()) {
1297 bv_->theLockingInset()->insetUnlock(bv_);
1298 bv_->theLockingInset(0);
1300 inset_slept = false;
1305 bool BufferView::Pimpl::focus() const
1307 return workarea_.hasFocus();
1311 void BufferView::Pimpl::focus(bool f)
1313 if (f) workarea_.setFocus();
1317 bool BufferView::Pimpl::active() const
1319 return workarea_.active();
1323 bool BufferView::Pimpl::belowMouse() const
1325 return workarea_.belowMouse();
1329 void BufferView::Pimpl::showCursor()
1331 if (screen_.get()) {
1332 if (bv_->theLockingInset())
1333 bv_->theLockingInset()->showInsetCursor(bv_);
1335 screen_->showCursor(bv_->text, bv_);
1340 void BufferView::Pimpl::hideCursor()
1342 if (screen_.get()) {
1343 if (!bv_->theLockingInset())
1344 // bv_->theLockingInset()->hideInsetCursor(bv_);
1346 screen_->hideCursor();
1351 void BufferView::Pimpl::toggleSelection(bool b)
1353 if (screen_.get()) {
1354 if (bv_->theLockingInset())
1355 bv_->theLockingInset()->toggleSelection(bv_, b);
1356 screen_->toggleSelection(bv_->text, bv_, b);
1361 void BufferView::Pimpl::toggleToggle()
1364 screen_->toggleToggle(bv_->text, bv_);
1368 void BufferView::Pimpl::center()
1370 beforeChange(bv_->text);
1371 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1372 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1374 screen_->draw(bv_->text, bv_, 0);
1376 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1381 void BufferView::Pimpl::pasteClipboard(bool asPara)
1383 if (!buffer_) return;
1385 screen_->hideCursor();
1386 beforeChange(bv_->text);
1388 string const clip(workarea_.getClipboard());
1390 if (clip.empty()) return;
1393 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1395 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1397 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1401 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1403 workarea_.putClipboard(stuff);
1408 * Dispatch functions for actions which can be valid for BufferView->text
1409 * and/or InsetText->text!!!
1414 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1416 LyXText * lt = bv_->getLyXText();
1418 if (selecting || lt->selection.mark()) {
1419 lt->setSelection(bv_);
1423 update(lt, BufferView::SELECT|BufferView::FITCUR);
1426 /* ---> Everytime the cursor is moved, show the current font state. */
1427 // should this too me moved out of this func?
1428 //owner->showState();
1433 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1435 LyXCursor cursor = bv_->getLyXText()->cursor;
1436 Buffer::inset_iterator it =
1437 find_if(Buffer::inset_iterator(
1438 cursor.par(), cursor.pos()),
1439 buffer_->inset_iterator_end(),
1440 lyx::compare_memfun(&Inset::lyxCode, code));
1441 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1445 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1447 string filename = filen;
1449 if (filename.empty()) {
1450 // Launch a file browser
1451 string initpath = lyxrc.document_path;
1454 string const trypath = owner_->buffer()->filePath();
1455 // If directory is writeable, use this as default.
1456 if (IsDirWriteable(trypath))
1460 FileDialog fileDlg(bv_->owner(),
1461 _("Select LyX document to insert"),
1463 make_pair(string(_("Documents|#o#O")),
1464 string(lyxrc.document_path)),
1465 make_pair(string(_("Examples|#E#e")),
1466 string(AddPath(system_lyxdir, "examples"))));
1468 FileDialog::Result result =
1469 fileDlg.Select(initpath,
1470 _("*.lyx| LyX Documents (*.lyx)"));
1472 if (result.first == FileDialog::Later)
1475 filename = result.second;
1477 // check selected filename
1478 if (filename.empty()) {
1479 owner_->message(_("Canceled."));
1484 // get absolute path of file and add ".lyx" to the filename if
1486 filename = FileSearch(string(), filename, "lyx");
1488 string const disp_fn(MakeDisplayPath(filename));
1491 s1 << _("Inserting document") << ' '
1492 << disp_fn << " ...";
1493 owner_->message(s1.str().c_str());
1494 bool const res = bv_->insertLyXFile(filename);
1497 str << _("Document") << ' ' << disp_fn
1498 << ' ' << _("inserted.");
1499 owner_->message(str.str().c_str());
1502 str << _("Could not insert document") << ' '
1504 owner_->message(str.str().c_str());
1509 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1511 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1512 << action <<"] arg[" << argument << "]" << endl;
1515 // --- Misc -------------------------------------------
1519 LyXText * lt = bv_->getLyXText();
1520 lt->toggleAppendix(bv_);
1523 | BufferView::FITCUR
1524 | BufferView::CHANGE);
1529 case LFUN_TOC_INSERT:
1531 InsetCommandParams p;
1532 p.setCmdName("tableofcontents");
1533 Inset * inset = new InsetTOC(p);
1534 if (!insertInset(inset, "Standard"))
1539 case LFUN_TABULAR_FEATURE:
1540 case LFUN_SCROLL_INSET:
1541 // this is not handled here as this funktion is only aktive
1542 // if we have a locking_inset and that one is (or contains)
1546 case LFUN_INSET_GRAPHICS:
1548 Inset * new_inset = new InsetGraphics;
1549 if (!insertInset(new_inset)) {
1552 // this is need because you don't use a inset->Edit()
1553 updateInset(new_inset, true);
1554 new_inset->edit(bv_);
1564 case LFUN_PASTESELECTION:
1566 bool asPara = false;
1567 if (argument == "paragraph")
1569 pasteClipboard(asPara);
1581 case LFUN_LAYOUT_COPY:
1582 bv_->copyEnvironment();
1585 case LFUN_LAYOUT_PASTE:
1586 bv_->pasteEnvironment();
1590 case LFUN_GOTOERROR:
1591 gotoInset(Inset::ERROR_CODE, false);
1595 gotoInset(Inset::IGNORE_CODE, false);
1598 case LFUN_REFERENCE_GOTO:
1600 vector<Inset::Code> tmp;
1601 tmp.push_back(Inset::LABEL_CODE);
1602 tmp.push_back(Inset::REF_CODE);
1603 gotoInset(tmp, true);
1607 case LFUN_HYPHENATION:
1608 specialChar(InsetSpecialChar::HYPHENATION);
1611 case LFUN_LIGATURE_BREAK:
1612 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1616 specialChar(InsetSpecialChar::LDOTS);
1619 case LFUN_END_OF_SENTENCE:
1620 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1623 case LFUN_MENU_SEPARATOR:
1624 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1632 changeDepth(bv_, bv_->getLyXText(), 0);
1635 case LFUN_DEPTH_MIN:
1636 changeDepth(bv_, bv_->getLyXText(), -1);
1639 case LFUN_DEPTH_PLUS:
1640 changeDepth(bv_, bv_->getLyXText(), 1);
1644 owner_->getDialogs()->setUserFreeFont();
1647 case LFUN_FILE_INSERT:
1648 MenuInsertLyXFile(argument);
1651 case LFUN_FILE_INSERT_ASCII_PARA:
1652 InsertAsciiFile(bv_, argument, true);
1655 case LFUN_FILE_INSERT_ASCII:
1656 InsertAsciiFile(bv_, argument, false);
1661 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1662 << argument << endl;
1664 // Derive layout number from given argument (string)
1665 // and current buffer's textclass (number). */
1666 textclass_type tclass = buffer_->params.textclass;
1667 pair <bool, layout_type> layout =
1668 textclasslist.NumberOfLayout(tclass, argument);
1670 // If the entry is obsolete, use the new one instead.
1672 string obs = textclasslist.Style(tclass, layout.second)
1675 layout = textclasslist.NumberOfLayout(tclass, obs);
1678 // see if we found the layout number:
1679 if (!layout.first) {
1680 owner_->getLyXFunc()->setErrorMessage(
1681 string(N_("Layout ")) + argument +
1686 if (current_layout != layout.second) {
1687 LyXText * lt = bv_->getLyXText();
1689 current_layout = layout.second;
1692 | BufferView::FITCUR);
1693 lt->setLayout(bv_, layout.second);
1694 owner_->setLayout(layout.second);
1697 | BufferView::FITCUR
1698 | BufferView::CHANGE);
1705 lang(bv_, argument);
1707 owner_->showState();
1712 owner_->showState();
1717 owner_->showState();
1722 owner_->showState();
1727 owner_->showState();
1732 owner_->showState();
1737 owner_->showState();
1742 owner_->showState();
1745 case LFUN_UNDERLINE:
1747 owner_->showState();
1750 case LFUN_FONT_SIZE:
1751 fontSize(bv_, argument);
1752 owner_->showState();
1755 case LFUN_FONT_STATE:
1756 owner_->getLyXFunc()->setMessage(currentState(bv_));
1759 case LFUN_UPCASE_WORD:
1761 LyXText * lt = bv_->getLyXText();
1765 | BufferView::FITCUR);
1766 lt->changeCase(bv_, LyXText::text_uppercase);
1767 if (lt->inset_owner)
1768 updateInset(lt->inset_owner, true);
1771 | BufferView::FITCUR
1772 | BufferView::CHANGE);
1776 case LFUN_LOWCASE_WORD:
1778 LyXText * lt = bv_->getLyXText();
1780 update(lt, BufferView::SELECT|BufferView::FITCUR);
1781 lt->changeCase(bv_, LyXText::text_lowercase);
1782 if (lt->inset_owner)
1783 updateInset(lt->inset_owner, true);
1786 | BufferView::FITCUR
1787 | BufferView::CHANGE);
1791 case LFUN_CAPITALIZE_WORD:
1793 LyXText * lt = bv_->getLyXText();
1795 update(lt, BufferView::SELECT|BufferView::FITCUR);
1796 lt->changeCase(bv_, LyXText::text_capitalization);
1797 if (lt->inset_owner)
1798 updateInset(lt->inset_owner, true);
1801 | BufferView::FITCUR
1802 | BufferView::CHANGE);
1806 case LFUN_TRANSPOSE_CHARS:
1808 LyXText * lt = bv_->getLyXText();
1810 update(lt, BufferView::SELECT|BufferView::FITCUR);
1811 lt->transposeChars(*bv_);
1812 if (lt->inset_owner)
1813 updateInset(lt->inset_owner, true);
1816 | BufferView::FITCUR
1817 | BufferView::CHANGE);
1822 case LFUN_INSERT_LABEL:
1823 MenuInsertLabel(bv_, argument);
1826 case LFUN_REF_INSERT:
1827 if (argument.empty()) {
1828 InsetCommandParams p("ref");
1829 owner_->getDialogs()->createRef(p.getAsString());
1831 InsetCommandParams p;
1832 p.setFromString(argument);
1834 InsetRef * inset = new InsetRef(p, *buffer_);
1835 if (!insertInset(inset))
1838 updateInset(inset, true);
1842 case LFUN_BOOKMARK_SAVE:
1843 savePosition(strToUnsignedInt(argument));
1846 case LFUN_BOOKMARK_GOTO:
1847 restorePosition(strToUnsignedInt(argument));
1852 string label(argument);
1853 if (label.empty()) {
1855 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1857 label = inset->getContents();
1862 if (!label.empty()) {
1863 //bv_->savePosition(0);
1864 if (!bv_->gotoLabel(label))
1865 Alert::alert(_("Error"),
1866 _("Couldn't find this label"),
1867 _("in current document."));
1872 // --- Cursor Movements -----------------------------
1875 LyXText * lt = bv_->getLyXText();
1877 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1878 if (!lt->selection.mark())
1880 update(lt, BufferView::SELECT|BufferView::FITCUR);
1882 lt->cursorLeft(bv_, false);
1883 if (lt->cursor.pos() < lt->cursor.par()->size()
1884 && lt->cursor.par()->isInset(lt->cursor.pos())
1885 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1886 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1887 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1889 tmpinset->edit(bv_, false);
1891 tmpinset->edit(bv_);
1895 lt->cursorRight(bv_, false);
1897 moveCursorUpdate(false);
1898 owner_->showState();
1904 // This is soooo ugly. Isn`t it possible to make
1905 // it simpler? (Lgb)
1906 LyXText * lt = bv_->getLyXText();
1907 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1908 if (!lt->selection.mark())
1910 update(lt, BufferView::SELECT|BufferView::FITCUR);
1911 LyXCursor const cur = lt->cursor;
1913 lt->cursorLeft(bv_, false);
1914 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1915 lt->cursor.pos() < lt->cursor.par()->size() &&
1916 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1917 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1918 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1919 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1921 tmpinset->edit(bv_);
1923 tmpinset->edit(bv_, false);
1927 lt->cursorRight(bv_, false);
1930 moveCursorUpdate(false);
1931 owner_->showState();
1937 LyXText * lt = bv_->getLyXText();
1939 if (!lt->selection.mark())
1941 update(lt, BufferView::UPDATE);
1944 moveCursorUpdate(false);
1945 owner_->showState();
1951 LyXText * lt = bv_->getLyXText();
1953 if (!lt->selection.mark())
1955 update(lt, BufferView::UPDATE);
1956 lt->cursorDown(bv_);
1958 moveCursorUpdate(false);
1959 owner_->showState();
1963 case LFUN_UP_PARAGRAPH:
1965 LyXText * lt = bv_->getLyXText();
1967 if (!lt->selection.mark())
1969 update(lt, BufferView::UPDATE);
1970 lt->cursorUpParagraph(bv_);
1972 moveCursorUpdate(false);
1973 owner_->showState();
1977 case LFUN_DOWN_PARAGRAPH:
1979 LyXText * lt = bv_->getLyXText();
1981 if (!lt->selection.mark())
1983 update(lt, BufferView::UPDATE);
1984 lt->cursorDownParagraph(bv_);
1986 moveCursorUpdate(false);
1987 owner_->showState();
1993 LyXText * lt = bv_->getLyXText();
1995 if (!lt->selection.mark())
1997 update(lt, BufferView::UPDATE);
2000 moveCursorUpdate(false);
2001 owner_->showState();
2007 LyXText * lt = bv_->getLyXText();
2009 if (!lt->selection.mark())
2011 update(lt, BufferView::UPDATE);
2014 moveCursorUpdate(false);
2015 owner_->showState();
2021 LyXText * lt = bv_->getLyXText();
2023 if (!lt->selection.mark())
2025 update(lt, BufferView::SELECT|BufferView::FITCUR);
2026 lt->cursorHome(bv_);
2028 moveCursorUpdate(false);
2029 owner_->showState();
2035 LyXText * lt = bv_->getLyXText();
2037 if (!lt->selection.mark())
2040 BufferView::SELECT|BufferView::FITCUR);
2043 moveCursorUpdate(false);
2044 owner_->showState();
2048 case LFUN_SHIFT_TAB:
2051 LyXText * lt = bv_->getLyXText();
2053 if (!lt->selection.mark())
2056 BufferView::SELECT|BufferView::FITCUR);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2064 case LFUN_WORDRIGHT:
2066 LyXText * lt = bv_->getLyXText();
2068 if (!lt->selection.mark())
2070 update(lt, BufferView::SELECT|BufferView::FITCUR);
2071 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2072 lt->cursorLeftOneWord(bv_);
2074 lt->cursorRightOneWord(bv_);
2076 moveCursorUpdate(false);
2077 owner_->showState();
2083 LyXText * lt = bv_->getLyXText();
2085 if (!lt->selection.mark())
2087 update(lt, BufferView::SELECT|BufferView::FITCUR);
2088 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2089 lt->cursorRightOneWord(bv_);
2091 lt->cursorLeftOneWord(bv_);
2093 moveCursorUpdate(false);
2094 owner_->showState();
2098 case LFUN_BEGINNINGBUF:
2100 LyXText * lt = bv_->getLyXText();
2102 if (!lt->selection.mark())
2105 BufferView::SELECT|BufferView::FITCUR);
2108 moveCursorUpdate(false);
2109 owner_->showState();
2115 LyXText * lt = bv_->getLyXText();
2117 if (!lt->selection.mark())
2120 BufferView::SELECT|BufferView::FITCUR);
2121 lt->cursorBottom(bv_);
2123 moveCursorUpdate(false);
2124 owner_->showState();
2128 /* cursor selection ---------------------------- */
2131 LyXText * lt = bv_->getLyXText();
2134 BufferView::SELECT|BufferView::FITCUR);
2135 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2136 lt->cursorLeft(bv_);
2138 lt->cursorRight(bv_);
2140 moveCursorUpdate(true);
2141 owner_->showState();
2147 LyXText * lt = bv_->getLyXText();
2150 BufferView::SELECT|BufferView::FITCUR);
2151 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2152 lt->cursorRight(bv_);
2154 lt->cursorLeft(bv_);
2156 moveCursorUpdate(true);
2157 owner_->showState();
2163 LyXText * lt = bv_->getLyXText();
2166 BufferView::SELECT|BufferView::FITCUR);
2169 moveCursorUpdate(true);
2170 owner_->showState();
2176 LyXText * lt = bv_->getLyXText();
2179 BufferView::SELECT|BufferView::FITCUR);
2180 lt->cursorDown(bv_);
2182 moveCursorUpdate(true);
2183 owner_->showState();
2187 case LFUN_UP_PARAGRAPHSEL:
2189 LyXText * lt = bv_->getLyXText();
2192 BufferView::SELECT|BufferView::FITCUR);
2193 lt->cursorUpParagraph(bv_);
2195 moveCursorUpdate(true);
2196 owner_->showState();
2200 case LFUN_DOWN_PARAGRAPHSEL:
2202 LyXText * lt = bv_->getLyXText();
2205 BufferView::SELECT|BufferView::FITCUR);
2206 lt->cursorDownParagraph(bv_);
2208 moveCursorUpdate(true);
2209 owner_->showState();
2215 LyXText * lt = bv_->getLyXText();
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2239 LyXText * lt = bv_->getLyXText();
2241 update(lt, BufferView::SELECT|BufferView::FITCUR);
2242 lt->cursorHome(bv_);
2244 moveCursorUpdate(true);
2245 owner_->showState();
2251 LyXText * lt = bv_->getLyXText();
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2256 moveCursorUpdate(true);
2257 owner_->showState();
2261 case LFUN_WORDRIGHTSEL:
2263 LyXText * lt = bv_->getLyXText();
2265 update(lt, BufferView::SELECT|BufferView::FITCUR);
2266 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2267 lt->cursorLeftOneWord(bv_);
2269 lt->cursorRightOneWord(bv_);
2271 moveCursorUpdate(true);
2272 owner_->showState();
2276 case LFUN_WORDLEFTSEL:
2278 LyXText * lt = bv_->getLyXText();
2280 update(lt, BufferView::SELECT|BufferView::FITCUR);
2281 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2282 lt->cursorRightOneWord(bv_);
2284 lt->cursorLeftOneWord(bv_);
2286 moveCursorUpdate(true);
2287 owner_->showState();
2291 case LFUN_BEGINNINGBUFSEL:
2293 LyXText * lt = bv_->getLyXText();
2295 if (lt->inset_owner)
2297 update(lt, BufferView::SELECT|BufferView::FITCUR);
2300 moveCursorUpdate(true);
2301 owner_->showState();
2305 case LFUN_ENDBUFSEL:
2307 LyXText * lt = bv_->getLyXText();
2309 if (lt->inset_owner)
2312 BufferView::SELECT|BufferView::FITCUR);
2313 lt->cursorBottom(bv_);
2315 moveCursorUpdate(true);
2316 owner_->showState();
2320 // --- text changing commands ------------------------
2321 case LFUN_BREAKLINE:
2323 LyXText * lt = bv_->getLyXText();
2326 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2329 | BufferView::FITCUR
2330 | BufferView::CHANGE);
2331 moveCursorUpdate(false);
2335 case LFUN_PROTECTEDSPACE:
2337 LyXText * lt = bv_->getLyXText();
2339 LyXLayout const & style = textclasslist
2340 .Style(buffer_->params.textclass,
2341 lt->cursor.par()->getLayout());
2343 if (style.free_spacing) {
2344 lt->insertChar(bv_, ' ');
2347 | BufferView::FITCUR
2348 | BufferView::CHANGE);
2352 moveCursorUpdate(false);
2358 LyXText * lt = bv_->getLyXText();
2360 if (lt->selection.mark()) {
2364 | BufferView::FITCUR);
2365 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2368 lt->selection.mark(true);
2371 | BufferView::FITCUR);
2372 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2374 lt->selection.cursor = lt->cursor;
2380 LyXText * lt = bv_->getLyXText();
2382 if (!lt->selection.set()) {
2384 lt->selection.cursor = lt->cursor;
2387 | BufferView::FITCUR
2388 | BufferView::CHANGE);
2389 // It is possible to make it a lot faster still
2390 // just comment out the line below...
2395 moveCursorUpdate(false);
2396 owner_->showState();
2401 case LFUN_DELETE_SKIP:
2403 LyXText * lt = bv_->getLyXText();
2405 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2407 LyXCursor cursor = lt->cursor;
2409 if (!lt->selection.set()) {
2410 if (cursor.pos() == cursor.par()->size()) {
2411 lt->cursorRight(bv_);
2412 cursor = lt->cursor;
2413 if (cursor.pos() == 0
2414 && !(cursor.par()->params().spaceTop()
2415 == VSpace (VSpace::NONE))) {
2418 cursor.par()->params().lineTop(),
2419 cursor.par()->params().lineBottom(),
2420 cursor.par()->params().pagebreakTop(),
2421 cursor.par()->params().pagebreakBottom(),
2422 VSpace(VSpace::NONE),
2423 cursor.par()->params().spaceBottom(),
2424 cursor.par()->params().spacing(),
2425 cursor.par()->params().align(),
2426 cursor.par()->params().labelWidthString(), 0);
2427 lt->cursorLeft(bv_);
2430 | BufferView::FITCUR
2431 | BufferView::CHANGE);
2433 lt->cursorLeft(bv_);
2435 lt->selection.cursor = lt->cursor;
2438 | BufferView::FITCUR
2439 | BufferView::CHANGE);
2443 lt->selection.cursor = lt->cursor;
2446 | BufferView::FITCUR
2447 | BufferView::CHANGE);
2455 /* -------> Delete word forward. */
2456 case LFUN_DELETE_WORD_FORWARD:
2457 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2458 bv_->getLyXText()->deleteWordForward(bv_);
2459 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2460 moveCursorUpdate(false);
2461 owner_->showState();
2464 /* -------> Delete word backward. */
2465 case LFUN_DELETE_WORD_BACKWARD:
2467 LyXText * lt = bv_->getLyXText();
2469 update(lt, BufferView::SELECT|BufferView::FITCUR);
2470 lt->deleteWordBackward(bv_);
2473 | BufferView::FITCUR
2474 | BufferView::CHANGE);
2475 moveCursorUpdate(false);
2476 owner_->showState();
2480 /* -------> Kill to end of line. */
2481 case LFUN_DELETE_LINE_FORWARD:
2483 LyXText * lt = bv_->getLyXText();
2485 update(lt, BufferView::SELECT|BufferView::FITCUR);
2486 lt->deleteLineForward(bv_);
2489 | BufferView::FITCUR
2490 | BufferView::CHANGE);
2491 moveCursorUpdate(false);
2495 /* -------> Set mark off. */
2498 LyXText * lt = bv_->getLyXText();
2501 update(lt, BufferView::SELECT|BufferView::FITCUR);
2502 lt->selection.cursor = lt->cursor;
2503 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2507 /* -------> Set mark on. */
2510 LyXText * lt = bv_->getLyXText();
2513 lt->selection.mark(true);
2514 update(lt, BufferView::SELECT|BufferView::FITCUR);
2515 lt->selection.cursor = lt->cursor;
2516 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2520 case LFUN_BACKSPACE:
2522 LyXText * lt = bv_->getLyXText();
2524 if (!lt->selection.set()) {
2525 if (owner_->getIntl()->getTrans().backspace()) {
2527 lt->selection.cursor = lt->cursor;
2530 | BufferView::FITCUR
2531 | BufferView::CHANGE);
2532 // It is possible to make it a lot faster still
2533 // just comment out the line below...
2539 owner_->showState();
2544 case LFUN_BACKSPACE_SKIP:
2546 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2547 LyXText * lt = bv_->getLyXText();
2549 LyXCursor cursor = lt->cursor;
2551 if (!lt->selection.set()) {
2552 if (cursor.pos() == 0
2553 && !(cursor.par()->params().spaceTop()
2554 == VSpace (VSpace::NONE))) {
2557 cursor.par()->params().lineTop(),
2558 cursor.par()->params().lineBottom(),
2559 cursor.par()->params().pagebreakTop(),
2560 cursor.par()->params().pagebreakBottom(),
2561 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2562 cursor.par()->params().spacing(),
2563 cursor.par()->params().align(),
2564 cursor.par()->params().labelWidthString(), 0);
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2571 lt->selection.cursor = cursor;
2574 | BufferView::FITCUR
2575 | BufferView::CHANGE);
2582 case LFUN_BREAKPARAGRAPH:
2584 LyXText * lt = bv_->getLyXText();
2587 lt->breakParagraph(bv_, 0);
2590 | BufferView::FITCUR
2591 | BufferView::CHANGE);
2592 lt->selection.cursor = lt->cursor;
2594 owner_->showState();
2598 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2600 LyXText * lt = bv_->getLyXText();
2603 lt->breakParagraph(bv_, 1);
2606 | BufferView::FITCUR
2607 | BufferView::CHANGE);
2608 lt->selection.cursor = lt->cursor;
2610 owner_->showState();
2614 case LFUN_BREAKPARAGRAPH_SKIP:
2616 // When at the beginning of a paragraph, remove
2617 // indentation and add a "defskip" at the top.
2618 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2619 LyXText * lt = bv_->getLyXText();
2621 LyXCursor cursor = lt->cursor;
2624 if (cursor.pos() == 0) {
2625 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2628 cursor.par()->params().lineTop(),
2629 cursor.par()->params().lineBottom(),
2630 cursor.par()->params().pagebreakTop(),
2631 cursor.par()->params().pagebreakBottom(),
2632 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2633 cursor.par()->params().spacing(),
2634 cursor.par()->params().align(),
2635 cursor.par()->params().labelWidthString(), 1);
2636 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2640 lt->breakParagraph(bv_, 0);
2641 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2646 | BufferView::FITCUR
2647 | BufferView::CHANGE);
2648 lt->selection.cursor = cursor;
2650 owner_->showState();
2654 case LFUN_PARAGRAPH_SPACING:
2656 LyXText * lt = bv_->getLyXText();
2658 Paragraph * par = lt->cursor.par();
2659 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2660 float cur_value = 1.0;
2661 if (cur_spacing == Spacing::Other) {
2662 cur_value = par->params().spacing().getValue();
2665 istringstream istr(argument.c_str());
2669 Spacing::Space new_spacing = cur_spacing;
2670 float new_value = cur_value;
2672 lyxerr << "Missing argument to `paragraph-spacing'"
2674 } else if (tmp == "single") {
2675 new_spacing = Spacing::Single;
2676 } else if (tmp == "onehalf") {
2677 new_spacing = Spacing::Onehalf;
2678 } else if (tmp == "double") {
2679 new_spacing = Spacing::Double;
2680 } else if (tmp == "other") {
2681 new_spacing = Spacing::Other;
2684 lyxerr << "new_value = " << tmpval << endl;
2687 } else if (tmp == "default") {
2688 new_spacing = Spacing::Default;
2690 lyxerr << _("Unknown spacing argument: ")
2691 << argument << endl;
2693 if (cur_spacing != new_spacing || cur_value != new_value) {
2694 par->params().spacing(Spacing(new_spacing, new_value));
2695 lt->redoParagraph(bv_);
2698 | BufferView::FITCUR
2699 | BufferView::CHANGE);
2704 case LFUN_INSET_TOGGLE:
2706 LyXText * lt = bv_->getLyXText();
2709 update(lt, BufferView::SELECT|BufferView::FITCUR);
2710 lt->toggleInset(bv_);
2711 update(lt, BufferView::SELECT|BufferView::FITCUR);
2723 InsetCommandParams p;
2724 if (action == LFUN_HTMLURL)
2725 p.setCmdName("htmlurl");
2727 p.setCmdName("url");
2728 owner_->getDialogs()->createUrl(p.getAsString());
2732 case LFUN_INSERT_URL:
2734 InsetCommandParams p;
2735 p.setFromString(argument);
2737 InsetUrl * inset = new InsetUrl(p);
2738 if (!insertInset(inset))
2741 updateInset(inset, true);
2745 case LFUN_INSET_TEXT:
2746 insertAndEditInset(new InsetText);
2749 case LFUN_INSET_ERT:
2750 insertAndEditInset(new InsetERT);
2753 case LFUN_INSET_EXTERNAL:
2754 insertAndEditInset(new InsetExternal);
2757 case LFUN_INSET_FOOTNOTE:
2758 insertAndEditInset(new InsetFoot);
2761 case LFUN_INSET_MARGINAL:
2762 insertAndEditInset(new InsetMarginal);
2765 case LFUN_INSET_MINIPAGE:
2766 insertAndEditInset(new InsetMinipage);
2769 case LFUN_INSERT_NOTE:
2770 insertAndEditInset(new InsetNote);
2773 case LFUN_INSET_FLOAT:
2774 // check if the float type exist
2775 if (floatList.typeExist(argument)) {
2776 insertAndEditInset(new InsetFloat(argument));
2778 lyxerr << "Non-existent float type: "
2779 << argument << endl;
2783 case LFUN_INSET_WIDE_FLOAT:
2785 // check if the float type exist
2786 if (floatList.typeExist(argument)) {
2787 InsetFloat * new_inset = new InsetFloat(argument);
2788 new_inset->wide(true);
2789 if (insertInset(new_inset))
2790 new_inset->edit(bv_);
2794 lyxerr << "Non-existent float type: "
2795 << argument << endl;
2802 case LFUN_INSET_LIST:
2803 insertAndEditInset(new InsetList);
2806 case LFUN_INSET_THEOREM:
2807 insertAndEditInset(new InsetTheorem);
2811 case LFUN_INSET_CAPTION:
2813 // Do we have a locking inset...
2814 if (bv_->theLockingInset()) {
2815 lyxerr << "Locking inset code: "
2816 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2817 InsetCaption * new_inset = new InsetCaption;
2818 new_inset->setOwner(bv_->theLockingInset());
2819 new_inset->setAutoBreakRows(true);
2820 new_inset->setDrawFrame(0, InsetText::LOCKED);
2821 new_inset->setFrameColor(0, LColor::captionframe);
2822 if (insertInset(new_inset))
2823 new_inset->edit(bv_);
2830 case LFUN_INSET_TABULAR:
2834 if (!argument.empty())
2835 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2836 InsetTabular * new_inset =
2837 new InsetTabular(*buffer_, r, c);
2839 bv_->getLyXText()->real_current_font.isRightToLeft();
2840 if (!open_new_inset(new_inset, rtl))
2845 // --- lyxserver commands ----------------------------
2847 case LFUN_CHARATCURSOR:
2849 pos_type pos = bv_->getLyXText()->cursor.pos();
2850 if (pos < bv_->getLyXText()->cursor.par()->size())
2851 owner_->getLyXFunc()->setMessage(
2852 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2854 owner_->getLyXFunc()->setMessage("EOF");
2859 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2861 + tostr(bv_->getLyXText()->cursor.y()));
2868 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2869 lyxerr << "SETXY: Could not parse coordinates in '"
2870 << argument << std::endl;
2872 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2876 case LFUN_GETLAYOUT:
2877 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2882 LyXFont & font = bv_->getLyXText()->current_font;
2883 if (font.shape() == LyXFont::ITALIC_SHAPE)
2884 owner_->getLyXFunc()->setMessage("E");
2885 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2886 owner_->getLyXFunc()->setMessage("N");
2888 owner_->getLyXFunc()->setMessage("0");
2893 // --- accented characters ---------------------------
2896 case LFUN_CIRCUMFLEX:
2906 case LFUN_SPECIAL_CARON:
2909 case LFUN_HUNG_UMLAUT:
2912 if (argument.empty()) {
2914 owner_->getLyXFunc()->handleKeyFunc(action);
2916 owner_->getLyXFunc()->handleKeyFunc(action);
2917 owner_->getIntl()->getTrans()
2918 .TranslateAndInsert(argument[0], bv_->getLyXText());
2919 update(bv_->getLyXText(),
2921 | BufferView::FITCUR
2922 | BufferView::CHANGE);
2926 case LFUN_MATH_MACRO:
2927 mathDispatchMathMacro(bv_, argument);
2930 case LFUN_MATH_DELIM:
2931 mathDispatchMathDelim(bv_, argument);
2934 case LFUN_INSERT_MATRIX:
2935 mathDispatchInsertMatrix(bv_, argument);
2938 case LFUN_INSERT_MATH:
2939 mathDispatchInsertMath(bv_, argument);
2942 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2943 mathDispatchMathImportSelection(bv_, argument);
2946 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2947 mathDispatchMathDisplay(bv_, argument);
2950 case LFUN_MATH_MODE: // Open or create an inlined math inset
2951 mathDispatchMathMode(bv_, argument);
2954 case LFUN_GREEK: // Insert a single greek letter
2955 mathDispatchGreek(bv_, argument);
2958 case LFUN_CITATION_INSERT:
2960 InsetCommandParams p;
2961 p.setFromString( argument );
2963 InsetCitation * inset = new InsetCitation( p );
2964 if (!insertInset(inset))
2967 updateInset( inset, true );
2971 case LFUN_INSERT_BIBTEX:
2973 // ale970405+lasgoutt970425
2974 // The argument can be up to two tokens separated
2975 // by a space. The first one is the bibstyle.
2976 string const db = token(argument, ' ', 0);
2977 string const bibstyle = token(argument, ' ', 1);
2979 InsetCommandParams p( "BibTeX", db, bibstyle );
2980 InsetBibtex * inset = new InsetBibtex(p);
2982 if (insertInset(inset)) {
2983 if (argument.empty())
2990 // BibTeX data bases
2991 case LFUN_BIBDB_ADD:
2993 InsetBibtex * inset =
2994 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2996 inset->addDatabase(argument);
3001 case LFUN_BIBDB_DEL:
3003 InsetBibtex * inset =
3004 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3006 inset->delDatabase(argument);
3011 case LFUN_BIBTEX_STYLE:
3013 InsetBibtex * inset =
3014 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3016 inset->setOptions(argument);
3021 case LFUN_INDEX_CREATE:
3023 InsetCommandParams p("index");
3024 if (argument.empty()) {
3025 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3026 p.setContents(idxstring);
3028 p.setContents(argument);
3031 owner_->getDialogs()->createIndex(p.getAsString());
3035 case LFUN_INDEX_INSERT:
3037 InsetCommandParams p;
3038 p.setFromString(argument);
3039 InsetIndex * inset = new InsetIndex(p);
3041 if (!insertInset(inset))
3044 updateInset(inset, true);
3048 case LFUN_INDEX_INSERT_LAST:
3050 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3051 if (!idxstring.empty()) {
3052 owner_->message(_("Word `")
3053 + idxstring + _(("' indexed.")));
3054 InsetCommandParams p("index", idxstring);
3055 InsetIndex * inset = new InsetIndex(p);
3057 if (!insertInset(inset))
3060 updateInset(inset, true);
3065 case LFUN_INDEX_PRINT:
3067 InsetCommandParams p("printindex");
3068 Inset * inset = new InsetPrintIndex(p);
3069 if (!insertInset(inset, "Standard"))
3074 case LFUN_PARENTINSERT:
3076 lyxerr << "arg " << argument << endl;
3077 InsetCommandParams p( "lyxparent", argument );
3078 Inset * inset = new InsetParent(p, *buffer_);
3079 if (!insertInset(inset, "Standard"))
3085 case LFUN_CHILD_INSERT:
3087 InsetInclude::Params p;
3088 p.cparams.setFromString(argument);
3089 p.masterFilename_ = buffer_->fileName();
3091 InsetInclude * inset = new InsetInclude(p);
3092 if (!insertInset(inset))
3095 updateInset(inset, true);
3096 bv_->owner()->getDialogs()->showInclude(inset);
3101 case LFUN_FLOAT_LIST:
3103 // We should check the argument for validity. (Lgb)
3104 Inset * inset = new InsetFloatList(argument);
3105 if (!insertInset(inset, "Standard"))
3110 case LFUN_THESAURUS_ENTRY:
3112 string arg = argument;
3115 arg = bv_->getLyXText()->selectionAsString(buffer_,
3119 if (arg.size() > 100 || arg.empty()) {
3120 // Get word or selection
3121 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3122 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3123 // FIXME: where is getLyXText()->unselect(bv_) ?
3127 bv_->owner()->getDialogs()->showThesaurus(arg);
3131 case LFUN_SELFINSERT:
3133 if (argument.empty()) break;
3135 /* Automatically delete the currently selected
3136 * text and replace it with what is being
3137 * typed in now. Depends on lyxrc settings
3138 * "auto_region_delete", which defaults to
3141 LyXText * lt = bv_->getLyXText();
3143 if (lyxrc.auto_region_delete) {
3144 if (lt->selection.set()) {
3145 lt->cutSelection(bv_, false, false);
3148 | BufferView::FITCUR
3149 | BufferView::CHANGE);
3154 LyXFont const old_font(lt->real_current_font);
3156 string::const_iterator cit = argument.begin();
3157 string::const_iterator end = argument.end();
3158 for (; cit != end; ++cit) {
3159 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3164 | BufferView::FITCUR
3165 | BufferView::CHANGE);
3167 lt->selection.cursor = lt->cursor;
3168 moveCursorUpdate(false);
3170 // real_current_font.number can change so we need to
3171 // update the minibuffer
3172 if (old_font != lt->real_current_font)
3173 owner_->showState();
3178 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3180 time_t now_time_t = time(NULL);
3181 struct tm * now_tm = localtime(&now_time_t);
3182 setlocale(LC_TIME, "");
3184 if (!argument.empty())
3187 arg = lyxrc.date_insert_format;
3189 int const datetmp_len =
3190 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3192 LyXText * lt = bv_->getLyXText();
3194 for (int i = 0; i < datetmp_len; i++) {
3195 lt->insertChar(bv_, datetmp[i]);
3198 | BufferView::FITCUR
3199 | BufferView::CHANGE);
3202 lt->selection.cursor = lt->cursor;
3203 moveCursorUpdate(false);
3207 case LFUN_UNKNOWN_ACTION:
3208 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3219 void BufferView::Pimpl::newline()
3222 LyXText * lt = bv_->getLyXText();
3226 | BufferView::FITCUR);
3227 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3230 | BufferView::FITCUR
3231 | BufferView::CHANGE);
3236 void BufferView::Pimpl::hfill()
3239 LyXText * lt = bv_->getLyXText();
3243 | BufferView::FITCUR);
3244 lt->insertChar(bv_, Paragraph::META_HFILL);
3247 | BufferView::FITCUR
3248 | BufferView::CHANGE);
3253 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3257 update(lt, BufferView::SELECT|BufferView::FITCUR);
3258 InsetSpecialChar * new_inset =
3259 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3260 #ifdef WITH_WARNINGS
3261 #warning Why is this code different from specialChar() below? (JMarc)
3262 // the code in specialChar is a generic version of what used to exist
3263 // for other special chars. I did not merge this case because of the
3264 // call to updateInset(), but what does it do?
3266 if (!insertInset(new_inset))
3269 updateInset(new_inset, true);
3274 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3277 LyXText * lt = bv_->getLyXText();
3280 update(lt, BufferView::SELECT|BufferView::FITCUR);
3281 InsetSpecialChar * new_inset =
3282 new InsetSpecialChar(kind);
3283 if (!insertInset(new_inset))
3289 void BufferView::Pimpl::smartQuote()
3291 LyXText const * lt = bv_->getLyXText();
3292 Paragraph const * par = lt->cursor.par();
3293 pos_type pos = lt->cursor.pos();
3297 || (par->isInset(pos - 1)
3298 && par->getInset(pos - 1)->isSpace()))
3301 c = par->getChar(pos - 1);
3306 LyXLayout const & style = textclasslist.Style(
3307 bv_->buffer()->params.textclass, par->getLayout());
3309 if (style.pass_thru ||
3310 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3311 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3315 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3317 if (insertInset(inset))
3324 // Open and lock an updatable inset
3325 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3327 LyXText * lt = bv_->getLyXText();
3331 if (!insertInset(new_inset)) {
3335 new_inset->edit(bv_, !behind);
3340 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3342 // if we are in a locking inset we should try to insert the
3343 // inset there otherwise this is a illegal function now
3344 if (bv_->theLockingInset()) {
3345 if (bv_->theLockingInset()->insetAllowed(inset))
3346 return bv_->theLockingInset()->insertInset(bv_, inset);
3350 // not quite sure if we want this...
3351 setCursorParUndo(bv_);
3354 beforeChange(bv_->text);
3355 if (!lout.empty()) {
3356 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3357 bv_->text->breakParagraph(bv_);
3358 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3360 if (bv_->text->cursor.par()->size()) {
3361 bv_->text->cursorLeft(bv_);
3363 bv_->text->breakParagraph(bv_);
3364 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 pair<bool, layout_type> lres =
3368 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3369 layout_type lay = 0;
3370 if (lres.first != false) {
3374 // layout not fount using default "Standard" (0)
3378 bv_->text->setLayout(bv_, lay);
3380 bv_->text->setParagraph(bv_, 0, 0,
3382 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3387 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3390 bv_->text->insertInset(bv_, inset);
3391 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3398 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3403 // first check for locking insets
3404 if (bv_->theLockingInset()) {
3405 if (bv_->theLockingInset() == inset) {
3406 if (bv_->text->updateInset(bv_, inset)) {
3409 buffer_->markDirty();
3414 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3415 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3418 buffer_->markDirty();
3426 // then check the current buffer
3429 update(bv_->text, BufferView::UPDATE);
3430 if (bv_->text->updateInset(bv_, inset)) {
3434 | BufferView::FITCUR
3435 | BufferView::CHANGE);
3437 update(bv_->text, SELECT);
3445 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3448 if (!available()) return;
3451 beforeChange(bv_->text);
3452 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3454 LyXCursor const & cursor = bv_->text->cursor;
3458 cursor.par()->isInset(cursor.pos())) {
3459 Inset const * inset = cursor.par()->getInset(cursor.pos());
3460 if (find(codes.begin(), codes.end(), inset->lyxCode())
3463 static_cast<InsetCommand const *>(inset)->getContents();
3467 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3468 if (bv_->text->cursor.pos()
3469 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3470 LyXCursor tmp = bv_->text->cursor;
3471 bv_->text->cursor.par(bv_->text->ownerParagraph());
3472 bv_->text->cursor.pos(0);
3473 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3474 bv_->text->cursor = tmp;
3475 bv_->owner()->message(_("No more insets"));
3478 bv_->owner()->message(_("No more insets"));
3481 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3482 bv_->text->selection.cursor = bv_->text->cursor;
3486 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3488 gotoInset(vector<Inset::Code>(1, code), same_content);