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()
748 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
751 workarea_.putClipboard(sel);
756 void BufferView::Pimpl::enterView()
758 if (active() && available()) {
759 SetXtermCursor(workarea_.getWin());
760 using_xterm_cursor = true;
765 void BufferView::Pimpl::leaveView()
767 if (using_xterm_cursor) {
768 XUndefineCursor(fl_get_display(), workarea_.getWin());
769 using_xterm_cursor = false;
774 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
777 if (!buffer_ || !screen_.get()) return;
779 // If we hit an inset, we have the inset coordinates in these
780 // and inset_hit points to the inset. If we do not hit an
781 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
782 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
784 if (bv_->theLockingInset()) {
785 // We are in inset locking mode.
787 /* LyX does a kind of work-area grabbing for insets.
788 Only a ButtonPress Event outside the inset will
789 force a insetUnlock. */
790 bv_->theLockingInset()->
791 insetButtonRelease(bv_, x, y, button);
795 selection_possible = false;
802 workarea_.haveSelection(bv_->getLyXText()->selection.set());
807 owner_->updateMenubar();
808 owner_->updateToolbar();
810 // Did we hit an editable inset?
812 // Inset like error, notes and figures
813 selection_possible = false;
815 // if we reach this point with a selection, it
816 // must mean we are currently selecting.
817 // But we don't want to open the inset
818 // because that is annoying for the user.
819 // So just pretend we didn't hit it.
820 // this is OK because a "kosher" ButtonRelease
821 // will follow a ButtonPress that clears
823 // Note this also fixes selection drawing
824 // problems if we end up opening an inset
825 if (bv_->getLyXText()->selection.set())
828 // CHECK fix this proper in 0.13
829 // well, maybe 13.0 !!!!!!!!!
831 // Following a ref shouldn't issue
832 // a push on the undo-stack
833 // anylonger, now that we have
834 // keybindings for following
835 // references and returning from
836 // references. IMHO though, it
837 // should be the inset's own business
838 // to push or not push on the undo
839 // stack. They don't *have* to
840 // alter the document...
842 // ...or maybe the SetCursorParUndo()
843 // below isn't necessary at all anylonger?
844 if (inset_hit->lyxCode() == Inset::REF_CODE) {
845 setCursorParUndo(bv_);
848 owner_->message(inset_hit->editMessage());
850 if (isHighlyEditableInset(inset_hit)) {
851 // Highly editable inset, like math
852 UpdatableInset *inset = (UpdatableInset *)inset_hit;
853 inset->insetButtonRelease(bv_, x, y, button);
855 inset_hit->insetButtonRelease(bv_, x, y, button);
856 inset_hit->edit(bv_, x, y, button);
861 // Maybe we want to edit a bibitem ale970302
862 if (bv_->text->cursor.par()->bibkey && x < 20 +
863 bibitemMaxWidth(bv_, textclasslist.
865 params.textclass).defaultfont())) {
866 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
873 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
874 LyXCursor const & cursor) const
876 Paragraph /*const*/ & par = *cursor.par();
877 pos_type const pos = cursor.pos();
879 lyx::Assert(par.getInset(pos));
881 Inset const & inset(*par.getInset(pos));
883 LyXFont const & font = text.getFont(buffer_, &par, pos);
885 int const width = inset.width(bv_, font);
886 int const inset_x = font.isVisibleRightToLeft()
887 ? (cursor.x() - width) : cursor.x();
890 inset_x + inset.scroll(),
892 cursor.y() - inset.ascent(bv_, font),
893 cursor.y() + inset.descent(bv_, font));
897 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
898 LyXCursor const & cursor,
899 int & x, int & y) const
901 pos_type const pos(cursor.pos());
902 Paragraph /*const*/ & par(*cursor.par());
904 if (pos >= par.size() || !par.isInset(pos)) {
908 Inset /*const*/ * inset = par.getInset(pos);
910 if (!isEditableInset(inset)) {
914 Box b(insetDimensions(text, cursor));
916 if (!b.contained(x, y)) {
917 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
918 << " box " << b << endl;
922 text.setCursor(bv_, &par, pos, true);
925 // The origin of an inset is on the baseline
926 y -= (text.cursor.y());
932 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
937 int y_tmp = y + text->first;
940 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
942 Inset * inset(checkInset(*text, cursor, x, y_tmp));
949 // look at previous position
951 if (cursor.pos() == 0) {
956 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
958 inset = checkInset(*text, cursor, x, y_tmp);
966 void BufferView::Pimpl::workAreaExpose()
968 static int work_area_width;
969 static unsigned int work_area_height;
971 bool const widthChange = workarea_.workWidth() != work_area_width;
972 bool const heightChange = workarea_.height() != work_area_height;
974 // update from work area
975 work_area_width = workarea_.workWidth();
976 work_area_height = workarea_.height();
979 // The visible LyXView need a resize
982 // Remove all texts from the textcache
983 // This is not _really_ what we want to do. What
984 // we really want to do is to delete in textcache
985 // that does not have a BufferView with matching
986 // width, but as long as we have only one BufferView
987 // deleting all gives the same result.
988 if (lyxerr.debugging())
989 textcache.show(lyxerr, "Expose delete all");
991 } else if (heightChange) {
992 // Rebuild image of current screen
994 // fitCursor() ensures we don't jump back
995 // to the start of the document on vertical
999 // The main window size has changed, repaint most stuff
1001 } else if (screen_.get())
1002 screen_->redraw(bv_->text, bv_);
1004 // Grey box when we don't have a buffer
1005 workarea_.greyOut();
1008 // always make sure that the scrollbar is sane.
1010 owner_->updateLayoutChoice();
1015 void BufferView::Pimpl::update()
1017 if (screen_.get() &&
1018 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1020 LyXText::text_status st = bv_->text->status();
1021 screen_->update(bv_->text, bv_);
1023 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1024 if (bv_->text->fullRebreak(bv_)) {
1025 st = LyXText::NEED_MORE_REFRESH;
1026 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1027 bv_->text->cursor.pos());
1030 bv_->text->status(bv_, st);
1031 screen_->update(bv_->text, bv_);
1033 // do this here instead of in the screen::update because of
1035 bv_->text->status(bv_, LyXText::UNCHANGED);
1041 // Values used when calling update:
1043 // -2 - update, move sel_cursor if selection, fitcursor
1044 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1045 // 0 - update, move sel_cursor if selection, fitcursor
1046 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1047 // 3 - update, move sel_cursor if selection
1050 // a simple redraw of the parts that need refresh
1052 // move sel_cursor if selection -
1053 // the text's sel_cursor is moved if there is selection is progress
1056 // fitCursor() is called and the scrollbar updated
1059 // the buffer is marked dirty.
1068 // UPDATE_ONLY = UPDATE;
1069 // UPDATE_SELECT = UPDATE | SELECT;
1070 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1071 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1073 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1074 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1075 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1076 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1077 // update(3) -> update(1) -> update(1) -> update(SELECT)
1079 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1081 owner_->updateLayoutChoice();
1083 if (!text->selection.set() && (f & SELECT)) {
1084 text->selection.cursor = text->cursor;
1087 text->fullRebreak(bv_);
1089 if (text->inset_owner) {
1090 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1091 updateInset(text->inset_owner, false);
1101 buffer_->markDirty();
1106 // Callback for cursor timer
1107 void BufferView::Pimpl::cursorToggle()
1109 // Quite a nice place for asyncron Inset updating, isn't it?
1110 // Actually no! This is run even if no buffer exist... so (Lgb)
1112 cursor_timeout.restart();
1117 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1118 if (pid == -1) // error find out what is wrong
1119 ; // ignore it for now.
1121 sigchldchecker(pid, &status);
1123 updatelist.update(bv_);
1125 if (!screen_.get()) {
1126 cursor_timeout.restart();
1130 if (!bv_->theLockingInset()) {
1131 screen_->cursorToggle(bv_);
1133 bv_->theLockingInset()->toggleInsetCursor(bv_);
1136 cursor_timeout.restart();
1140 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1142 if (!text->cursor.row()->previous())
1145 int y = text->first;
1146 if (text->inset_owner)
1147 y += bv_->text->first;
1148 Row * cursorrow = text->cursor.row();
1149 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1151 // This is to allow jumping over large insets
1152 if ((cursorrow == text->cursor.row()))
1153 text->cursorUp(bv_);
1155 if (text->inset_owner ||
1156 text->cursor.row()->height() < workarea_.height())
1157 screen_->draw(bv_->text, bv_,
1159 - text->cursor.row()->baseline()
1160 + text->cursor.row()->height()
1161 - workarea_.height() + 1 );
1166 void BufferView::Pimpl::cursorNext(LyXText * text)
1168 if (!text->cursor.row()->next())
1171 int y = text->first + workarea_.height();
1172 // if (text->inset_owner)
1173 // y += bv_->text->first;
1174 text->getRowNearY(y);
1176 Row * cursorrow = text->cursor.row();
1177 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1179 // This is to allow jumping over large insets
1180 if ((cursorrow == bv_->text->cursor.row()))
1181 text->cursorDown(bv_);
1183 if (text->inset_owner ||
1184 text->cursor.row()->height() < workarea_.height())
1185 screen_->draw(bv_->text, bv_, text->cursor.y() -
1186 text->cursor.row()->baseline());
1191 bool BufferView::Pimpl::available() const
1193 if (buffer_ && bv_->text) return true;
1198 void BufferView::Pimpl::beforeChange(LyXText * text)
1201 text->clearSelection();
1205 void BufferView::Pimpl::savePosition(unsigned int i)
1207 if (i >= saved_positions_num)
1209 saved_positions[i] = Position(buffer_->fileName(),
1210 bv_->text->cursor.par()->id(),
1211 bv_->text->cursor.pos());
1214 str << _("Saved bookmark") << ' ' << i;
1215 owner_->message(str.str().c_str());
1220 void BufferView::Pimpl::restorePosition(unsigned int i)
1222 if (i >= saved_positions_num)
1225 string const fname = saved_positions[i].filename;
1227 beforeChange(bv_->text);
1229 if (fname != buffer_->fileName()) {
1230 Buffer * b = bufferlist.exists(fname) ?
1231 bufferlist.getBuffer(fname) :
1232 bufferlist.loadLyXFile(fname); // don't ask, just load it
1233 if (b != 0 ) buffer(b);
1236 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1240 bv_->text->setCursor(bv_, par,
1241 min(par->size(), saved_positions[i].par_pos));
1243 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1246 str << _("Moved to bookmark") << ' ' << i;
1247 owner_->message(str.str().c_str());
1252 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1254 if (i >= saved_positions_num)
1257 return !saved_positions[i].filename.empty();
1261 void BufferView::Pimpl::setState()
1263 if (!lyxrc.rtl_support)
1266 LyXText * text = bv_->getLyXText();
1267 if (text->real_current_font.isRightToLeft()) {
1268 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1269 owner_->getIntl()->KeyMapSec();
1271 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1272 owner_->getIntl()->KeyMapPrim();
1277 void BufferView::Pimpl::insetSleep()
1279 if (bv_->theLockingInset() && !inset_slept) {
1280 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1281 bv_->theLockingInset()->insetUnlock(bv_);
1287 void BufferView::Pimpl::insetWakeup()
1289 if (bv_->theLockingInset() && inset_slept) {
1290 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1291 inset_slept = false;
1296 void BufferView::Pimpl::insetUnlock()
1298 if (bv_->theLockingInset()) {
1300 bv_->theLockingInset()->insetUnlock(bv_);
1301 bv_->theLockingInset(0);
1303 inset_slept = false;
1308 bool BufferView::Pimpl::focus() const
1310 return workarea_.hasFocus();
1314 void BufferView::Pimpl::focus(bool f)
1316 if (f) workarea_.setFocus();
1320 bool BufferView::Pimpl::active() const
1322 return workarea_.active();
1326 bool BufferView::Pimpl::belowMouse() const
1328 return workarea_.belowMouse();
1332 void BufferView::Pimpl::showCursor()
1334 if (screen_.get()) {
1335 if (bv_->theLockingInset())
1336 bv_->theLockingInset()->showInsetCursor(bv_);
1338 screen_->showCursor(bv_->text, bv_);
1343 void BufferView::Pimpl::hideCursor()
1345 if (screen_.get()) {
1346 if (!bv_->theLockingInset())
1347 // bv_->theLockingInset()->hideInsetCursor(bv_);
1349 screen_->hideCursor();
1354 void BufferView::Pimpl::toggleSelection(bool b)
1356 if (screen_.get()) {
1357 if (bv_->theLockingInset())
1358 bv_->theLockingInset()->toggleSelection(bv_, b);
1359 screen_->toggleSelection(bv_->text, bv_, b);
1364 void BufferView::Pimpl::toggleToggle()
1367 screen_->toggleToggle(bv_->text, bv_);
1371 void BufferView::Pimpl::center()
1373 beforeChange(bv_->text);
1374 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1375 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1377 screen_->draw(bv_->text, bv_, 0);
1379 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1384 void BufferView::Pimpl::pasteClipboard(bool asPara)
1386 if (!buffer_) return;
1388 screen_->hideCursor();
1389 beforeChange(bv_->text);
1391 string const clip(workarea_.getClipboard());
1393 if (clip.empty()) return;
1396 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1398 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1400 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1404 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1406 workarea_.putClipboard(stuff);
1411 * Dispatch functions for actions which can be valid for BufferView->text
1412 * and/or InsetText->text!!!
1417 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1419 LyXText * lt = bv_->getLyXText();
1421 if (selecting || lt->selection.mark()) {
1422 lt->setSelection(bv_);
1426 update(lt, BufferView::SELECT|BufferView::FITCUR);
1429 /* ---> Everytime the cursor is moved, show the current font state. */
1430 // should this too me moved out of this func?
1431 //owner->showState();
1436 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1438 LyXCursor cursor = bv_->getLyXText()->cursor;
1439 Buffer::inset_iterator it =
1440 find_if(Buffer::inset_iterator(
1441 cursor.par(), cursor.pos()),
1442 buffer_->inset_iterator_end(),
1443 lyx::compare_memfun(&Inset::lyxCode, code));
1444 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1448 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1450 string filename = filen;
1452 if (filename.empty()) {
1453 // Launch a file browser
1454 string initpath = lyxrc.document_path;
1457 string const trypath = owner_->buffer()->filePath();
1458 // If directory is writeable, use this as default.
1459 if (IsDirWriteable(trypath))
1463 FileDialog fileDlg(bv_->owner(),
1464 _("Select LyX document to insert"),
1466 make_pair(string(_("Documents|#o#O")),
1467 string(lyxrc.document_path)),
1468 make_pair(string(_("Examples|#E#e")),
1469 string(AddPath(system_lyxdir, "examples"))));
1471 FileDialog::Result result =
1472 fileDlg.Select(initpath,
1473 _("*.lyx| LyX Documents (*.lyx)"));
1475 if (result.first == FileDialog::Later)
1478 filename = result.second;
1480 // check selected filename
1481 if (filename.empty()) {
1482 owner_->message(_("Canceled."));
1487 // get absolute path of file and add ".lyx" to the filename if
1489 filename = FileSearch(string(), filename, "lyx");
1491 string const disp_fn(MakeDisplayPath(filename));
1494 s1 << _("Inserting document") << ' '
1495 << disp_fn << " ...";
1496 owner_->message(s1.str().c_str());
1497 bool const res = bv_->insertLyXFile(filename);
1500 str << _("Document") << ' ' << disp_fn
1501 << ' ' << _("inserted.");
1502 owner_->message(str.str().c_str());
1505 str << _("Could not insert document") << ' '
1507 owner_->message(str.str().c_str());
1512 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1514 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1515 << action <<"] arg[" << argument << "]" << endl;
1518 // --- Misc -------------------------------------------
1522 LyXText * lt = bv_->getLyXText();
1523 lt->toggleAppendix(bv_);
1526 | BufferView::FITCUR
1527 | BufferView::CHANGE);
1532 case LFUN_TOC_INSERT:
1534 InsetCommandParams p;
1535 p.setCmdName("tableofcontents");
1536 Inset * inset = new InsetTOC(p);
1537 if (!insertInset(inset, "Standard"))
1542 case LFUN_TABULAR_FEATURE:
1543 case LFUN_SCROLL_INSET:
1544 // this is not handled here as this funktion is only aktive
1545 // if we have a locking_inset and that one is (or contains)
1549 case LFUN_INSET_GRAPHICS:
1551 Inset * new_inset = new InsetGraphics;
1552 if (!insertInset(new_inset)) {
1555 // this is need because you don't use a inset->Edit()
1556 updateInset(new_inset, true);
1557 new_inset->edit(bv_);
1567 case LFUN_PASTESELECTION:
1569 bool asPara = false;
1570 if (argument == "paragraph")
1572 pasteClipboard(asPara);
1584 case LFUN_LAYOUT_COPY:
1585 bv_->copyEnvironment();
1588 case LFUN_LAYOUT_PASTE:
1589 bv_->pasteEnvironment();
1593 case LFUN_GOTOERROR:
1594 gotoInset(Inset::ERROR_CODE, false);
1598 gotoInset(Inset::IGNORE_CODE, false);
1601 case LFUN_REFERENCE_GOTO:
1603 vector<Inset::Code> tmp;
1604 tmp.push_back(Inset::LABEL_CODE);
1605 tmp.push_back(Inset::REF_CODE);
1606 gotoInset(tmp, true);
1610 case LFUN_HYPHENATION:
1611 specialChar(InsetSpecialChar::HYPHENATION);
1614 case LFUN_LIGATURE_BREAK:
1615 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1619 specialChar(InsetSpecialChar::LDOTS);
1622 case LFUN_END_OF_SENTENCE:
1623 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1626 case LFUN_MENU_SEPARATOR:
1627 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1635 changeDepth(bv_, bv_->getLyXText(), 0);
1638 case LFUN_DEPTH_MIN:
1639 changeDepth(bv_, bv_->getLyXText(), -1);
1642 case LFUN_DEPTH_PLUS:
1643 changeDepth(bv_, bv_->getLyXText(), 1);
1647 owner_->getDialogs()->setUserFreeFont();
1650 case LFUN_FILE_INSERT:
1651 MenuInsertLyXFile(argument);
1654 case LFUN_FILE_INSERT_ASCII_PARA:
1655 InsertAsciiFile(bv_, argument, true);
1658 case LFUN_FILE_INSERT_ASCII:
1659 InsertAsciiFile(bv_, argument, false);
1664 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1665 << argument << endl;
1667 // Derive layout number from given argument (string)
1668 // and current buffer's textclass (number). */
1669 textclass_type tclass = buffer_->params.textclass;
1670 pair <bool, layout_type> layout =
1671 textclasslist.NumberOfLayout(tclass, argument);
1673 // If the entry is obsolete, use the new one instead.
1675 string obs = textclasslist.Style(tclass, layout.second)
1678 layout = textclasslist.NumberOfLayout(tclass, obs);
1681 // see if we found the layout number:
1682 if (!layout.first) {
1683 owner_->getLyXFunc()->setErrorMessage(
1684 string(N_("Layout ")) + argument +
1689 if (current_layout != layout.second) {
1690 LyXText * lt = bv_->getLyXText();
1692 current_layout = layout.second;
1695 | BufferView::FITCUR);
1696 lt->setLayout(bv_, layout.second);
1697 owner_->setLayout(layout.second);
1700 | BufferView::FITCUR
1701 | BufferView::CHANGE);
1708 lang(bv_, argument);
1710 owner_->showState();
1715 owner_->showState();
1720 owner_->showState();
1725 owner_->showState();
1730 owner_->showState();
1735 owner_->showState();
1740 owner_->showState();
1745 owner_->showState();
1748 case LFUN_UNDERLINE:
1750 owner_->showState();
1753 case LFUN_FONT_SIZE:
1754 fontSize(bv_, argument);
1755 owner_->showState();
1758 case LFUN_FONT_STATE:
1759 owner_->getLyXFunc()->setMessage(currentState(bv_));
1762 case LFUN_UPCASE_WORD:
1764 LyXText * lt = bv_->getLyXText();
1768 | BufferView::FITCUR);
1769 lt->changeCase(bv_, LyXText::text_uppercase);
1770 if (lt->inset_owner)
1771 updateInset(lt->inset_owner, true);
1774 | BufferView::FITCUR
1775 | BufferView::CHANGE);
1779 case LFUN_LOWCASE_WORD:
1781 LyXText * lt = bv_->getLyXText();
1783 update(lt, BufferView::SELECT|BufferView::FITCUR);
1784 lt->changeCase(bv_, LyXText::text_lowercase);
1785 if (lt->inset_owner)
1786 updateInset(lt->inset_owner, true);
1789 | BufferView::FITCUR
1790 | BufferView::CHANGE);
1794 case LFUN_CAPITALIZE_WORD:
1796 LyXText * lt = bv_->getLyXText();
1798 update(lt, BufferView::SELECT|BufferView::FITCUR);
1799 lt->changeCase(bv_, LyXText::text_capitalization);
1800 if (lt->inset_owner)
1801 updateInset(lt->inset_owner, true);
1804 | BufferView::FITCUR
1805 | BufferView::CHANGE);
1809 case LFUN_TRANSPOSE_CHARS:
1811 LyXText * lt = bv_->getLyXText();
1813 update(lt, BufferView::SELECT|BufferView::FITCUR);
1814 lt->transposeChars(*bv_);
1815 if (lt->inset_owner)
1816 updateInset(lt->inset_owner, true);
1819 | BufferView::FITCUR
1820 | BufferView::CHANGE);
1825 case LFUN_INSERT_LABEL:
1826 MenuInsertLabel(bv_, argument);
1829 case LFUN_REF_INSERT:
1830 if (argument.empty()) {
1831 InsetCommandParams p("ref");
1832 owner_->getDialogs()->createRef(p.getAsString());
1834 InsetCommandParams p;
1835 p.setFromString(argument);
1837 InsetRef * inset = new InsetRef(p, *buffer_);
1838 if (!insertInset(inset))
1841 updateInset(inset, true);
1845 case LFUN_BOOKMARK_SAVE:
1846 savePosition(strToUnsignedInt(argument));
1849 case LFUN_BOOKMARK_GOTO:
1850 restorePosition(strToUnsignedInt(argument));
1855 string label(argument);
1856 if (label.empty()) {
1858 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1860 label = inset->getContents();
1865 if (!label.empty()) {
1866 //bv_->savePosition(0);
1867 if (!bv_->gotoLabel(label))
1868 Alert::alert(_("Error"),
1869 _("Couldn't find this label"),
1870 _("in current document."));
1875 // --- Cursor Movements -----------------------------
1878 LyXText * lt = bv_->getLyXText();
1880 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1881 if (!lt->selection.mark())
1883 update(lt, BufferView::SELECT|BufferView::FITCUR);
1885 lt->cursorLeft(bv_, false);
1886 if (lt->cursor.pos() < lt->cursor.par()->size()
1887 && lt->cursor.par()->isInset(lt->cursor.pos())
1888 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1889 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1890 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1892 tmpinset->edit(bv_, false);
1894 tmpinset->edit(bv_);
1898 lt->cursorRight(bv_, false);
1900 moveCursorUpdate(false);
1901 owner_->showState();
1907 // This is soooo ugly. Isn`t it possible to make
1908 // it simpler? (Lgb)
1909 LyXText * lt = bv_->getLyXText();
1910 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1911 if (!lt->selection.mark())
1913 update(lt, BufferView::SELECT|BufferView::FITCUR);
1914 LyXCursor const cur = lt->cursor;
1916 lt->cursorLeft(bv_, false);
1917 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1918 lt->cursor.pos() < lt->cursor.par()->size() &&
1919 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1920 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1921 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1922 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1924 tmpinset->edit(bv_);
1926 tmpinset->edit(bv_, false);
1930 lt->cursorRight(bv_, false);
1933 moveCursorUpdate(false);
1934 owner_->showState();
1940 LyXText * lt = bv_->getLyXText();
1942 if (!lt->selection.mark())
1944 update(lt, BufferView::UPDATE);
1947 moveCursorUpdate(false);
1948 owner_->showState();
1954 LyXText * lt = bv_->getLyXText();
1956 if (!lt->selection.mark())
1958 update(lt, BufferView::UPDATE);
1959 lt->cursorDown(bv_);
1961 moveCursorUpdate(false);
1962 owner_->showState();
1966 case LFUN_UP_PARAGRAPH:
1968 LyXText * lt = bv_->getLyXText();
1970 if (!lt->selection.mark())
1972 update(lt, BufferView::UPDATE);
1973 lt->cursorUpParagraph(bv_);
1975 moveCursorUpdate(false);
1976 owner_->showState();
1980 case LFUN_DOWN_PARAGRAPH:
1982 LyXText * lt = bv_->getLyXText();
1984 if (!lt->selection.mark())
1986 update(lt, BufferView::UPDATE);
1987 lt->cursorDownParagraph(bv_);
1989 moveCursorUpdate(false);
1990 owner_->showState();
1996 LyXText * lt = bv_->getLyXText();
1998 if (!lt->selection.mark())
2000 update(lt, BufferView::UPDATE);
2003 moveCursorUpdate(false);
2004 owner_->showState();
2010 LyXText * lt = bv_->getLyXText();
2012 if (!lt->selection.mark())
2014 update(lt, BufferView::UPDATE);
2017 moveCursorUpdate(false);
2018 owner_->showState();
2024 LyXText * lt = bv_->getLyXText();
2026 if (!lt->selection.mark())
2028 update(lt, BufferView::SELECT|BufferView::FITCUR);
2029 lt->cursorHome(bv_);
2031 moveCursorUpdate(false);
2032 owner_->showState();
2038 LyXText * lt = bv_->getLyXText();
2040 if (!lt->selection.mark())
2043 BufferView::SELECT|BufferView::FITCUR);
2046 moveCursorUpdate(false);
2047 owner_->showState();
2051 case LFUN_SHIFT_TAB:
2054 LyXText * lt = bv_->getLyXText();
2056 if (!lt->selection.mark())
2059 BufferView::SELECT|BufferView::FITCUR);
2062 moveCursorUpdate(false);
2063 owner_->showState();
2067 case LFUN_WORDRIGHT:
2069 LyXText * lt = bv_->getLyXText();
2071 if (!lt->selection.mark())
2073 update(lt, BufferView::SELECT|BufferView::FITCUR);
2074 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2075 lt->cursorLeftOneWord(bv_);
2077 lt->cursorRightOneWord(bv_);
2079 moveCursorUpdate(false);
2080 owner_->showState();
2086 LyXText * lt = bv_->getLyXText();
2088 if (!lt->selection.mark())
2090 update(lt, BufferView::SELECT|BufferView::FITCUR);
2091 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2092 lt->cursorRightOneWord(bv_);
2094 lt->cursorLeftOneWord(bv_);
2096 moveCursorUpdate(false);
2097 owner_->showState();
2101 case LFUN_BEGINNINGBUF:
2103 LyXText * lt = bv_->getLyXText();
2105 if (!lt->selection.mark())
2108 BufferView::SELECT|BufferView::FITCUR);
2111 moveCursorUpdate(false);
2112 owner_->showState();
2118 LyXText * lt = bv_->getLyXText();
2120 if (!lt->selection.mark())
2123 BufferView::SELECT|BufferView::FITCUR);
2124 lt->cursorBottom(bv_);
2126 moveCursorUpdate(false);
2127 owner_->showState();
2131 /* cursor selection ---------------------------- */
2134 LyXText * lt = bv_->getLyXText();
2137 BufferView::SELECT|BufferView::FITCUR);
2138 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2139 lt->cursorLeft(bv_);
2141 lt->cursorRight(bv_);
2143 moveCursorUpdate(true);
2144 owner_->showState();
2150 LyXText * lt = bv_->getLyXText();
2153 BufferView::SELECT|BufferView::FITCUR);
2154 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2155 lt->cursorRight(bv_);
2157 lt->cursorLeft(bv_);
2159 moveCursorUpdate(true);
2160 owner_->showState();
2166 LyXText * lt = bv_->getLyXText();
2169 BufferView::SELECT|BufferView::FITCUR);
2172 moveCursorUpdate(true);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2182 BufferView::SELECT|BufferView::FITCUR);
2183 lt->cursorDown(bv_);
2185 moveCursorUpdate(true);
2186 owner_->showState();
2190 case LFUN_UP_PARAGRAPHSEL:
2192 LyXText * lt = bv_->getLyXText();
2195 BufferView::SELECT|BufferView::FITCUR);
2196 lt->cursorUpParagraph(bv_);
2198 moveCursorUpdate(true);
2199 owner_->showState();
2203 case LFUN_DOWN_PARAGRAPHSEL:
2205 LyXText * lt = bv_->getLyXText();
2208 BufferView::SELECT|BufferView::FITCUR);
2209 lt->cursorDownParagraph(bv_);
2211 moveCursorUpdate(true);
2212 owner_->showState();
2218 LyXText * lt = bv_->getLyXText();
2220 update(lt, BufferView::SELECT|BufferView::FITCUR);
2223 moveCursorUpdate(true);
2224 owner_->showState();
2230 LyXText * lt = bv_->getLyXText();
2232 update(lt, BufferView::SELECT|BufferView::FITCUR);
2235 moveCursorUpdate(true);
2236 owner_->showState();
2242 LyXText * lt = bv_->getLyXText();
2244 update(lt, BufferView::SELECT|BufferView::FITCUR);
2245 lt->cursorHome(bv_);
2247 moveCursorUpdate(true);
2248 owner_->showState();
2254 LyXText * lt = bv_->getLyXText();
2256 update(lt, BufferView::SELECT|BufferView::FITCUR);
2259 moveCursorUpdate(true);
2260 owner_->showState();
2264 case LFUN_WORDRIGHTSEL:
2266 LyXText * lt = bv_->getLyXText();
2268 update(lt, BufferView::SELECT|BufferView::FITCUR);
2269 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2270 lt->cursorLeftOneWord(bv_);
2272 lt->cursorRightOneWord(bv_);
2274 moveCursorUpdate(true);
2275 owner_->showState();
2279 case LFUN_WORDLEFTSEL:
2281 LyXText * lt = bv_->getLyXText();
2283 update(lt, BufferView::SELECT|BufferView::FITCUR);
2284 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2285 lt->cursorRightOneWord(bv_);
2287 lt->cursorLeftOneWord(bv_);
2289 moveCursorUpdate(true);
2290 owner_->showState();
2294 case LFUN_BEGINNINGBUFSEL:
2296 LyXText * lt = bv_->getLyXText();
2298 if (lt->inset_owner)
2300 update(lt, BufferView::SELECT|BufferView::FITCUR);
2303 moveCursorUpdate(true);
2304 owner_->showState();
2308 case LFUN_ENDBUFSEL:
2310 LyXText * lt = bv_->getLyXText();
2312 if (lt->inset_owner)
2315 BufferView::SELECT|BufferView::FITCUR);
2316 lt->cursorBottom(bv_);
2318 moveCursorUpdate(true);
2319 owner_->showState();
2323 // --- text changing commands ------------------------
2324 case LFUN_BREAKLINE:
2326 LyXText * lt = bv_->getLyXText();
2329 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2332 | BufferView::FITCUR
2333 | BufferView::CHANGE);
2334 moveCursorUpdate(false);
2338 case LFUN_PROTECTEDSPACE:
2340 LyXText * lt = bv_->getLyXText();
2342 LyXLayout const & style = textclasslist
2343 .Style(buffer_->params.textclass,
2344 lt->cursor.par()->getLayout());
2346 if (style.free_spacing) {
2347 lt->insertChar(bv_, ' ');
2350 | BufferView::FITCUR
2351 | BufferView::CHANGE);
2355 moveCursorUpdate(false);
2361 LyXText * lt = bv_->getLyXText();
2363 if (lt->selection.mark()) {
2367 | BufferView::FITCUR);
2368 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2371 lt->selection.mark(true);
2374 | BufferView::FITCUR);
2375 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2377 lt->selection.cursor = lt->cursor;
2383 LyXText * lt = bv_->getLyXText();
2385 if (!lt->selection.set()) {
2387 lt->selection.cursor = lt->cursor;
2390 | BufferView::FITCUR
2391 | BufferView::CHANGE);
2392 // It is possible to make it a lot faster still
2393 // just comment out the line below...
2398 moveCursorUpdate(false);
2399 owner_->showState();
2404 case LFUN_DELETE_SKIP:
2406 LyXText * lt = bv_->getLyXText();
2408 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2410 LyXCursor cursor = lt->cursor;
2412 if (!lt->selection.set()) {
2413 if (cursor.pos() == cursor.par()->size()) {
2414 lt->cursorRight(bv_);
2415 cursor = lt->cursor;
2416 if (cursor.pos() == 0
2417 && !(cursor.par()->params().spaceTop()
2418 == VSpace (VSpace::NONE))) {
2421 cursor.par()->params().lineTop(),
2422 cursor.par()->params().lineBottom(),
2423 cursor.par()->params().pagebreakTop(),
2424 cursor.par()->params().pagebreakBottom(),
2425 VSpace(VSpace::NONE),
2426 cursor.par()->params().spaceBottom(),
2427 cursor.par()->params().spacing(),
2428 cursor.par()->params().align(),
2429 cursor.par()->params().labelWidthString(), 0);
2430 lt->cursorLeft(bv_);
2433 | BufferView::FITCUR
2434 | BufferView::CHANGE);
2436 lt->cursorLeft(bv_);
2438 lt->selection.cursor = lt->cursor;
2441 | BufferView::FITCUR
2442 | BufferView::CHANGE);
2446 lt->selection.cursor = lt->cursor;
2449 | BufferView::FITCUR
2450 | BufferView::CHANGE);
2458 /* -------> Delete word forward. */
2459 case LFUN_DELETE_WORD_FORWARD:
2460 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2461 bv_->getLyXText()->deleteWordForward(bv_);
2462 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2463 moveCursorUpdate(false);
2464 owner_->showState();
2467 /* -------> Delete word backward. */
2468 case LFUN_DELETE_WORD_BACKWARD:
2470 LyXText * lt = bv_->getLyXText();
2472 update(lt, BufferView::SELECT|BufferView::FITCUR);
2473 lt->deleteWordBackward(bv_);
2476 | BufferView::FITCUR
2477 | BufferView::CHANGE);
2478 moveCursorUpdate(false);
2479 owner_->showState();
2483 /* -------> Kill to end of line. */
2484 case LFUN_DELETE_LINE_FORWARD:
2486 LyXText * lt = bv_->getLyXText();
2488 update(lt, BufferView::SELECT|BufferView::FITCUR);
2489 lt->deleteLineForward(bv_);
2492 | BufferView::FITCUR
2493 | BufferView::CHANGE);
2494 moveCursorUpdate(false);
2498 /* -------> Set mark off. */
2501 LyXText * lt = bv_->getLyXText();
2504 update(lt, BufferView::SELECT|BufferView::FITCUR);
2505 lt->selection.cursor = lt->cursor;
2506 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2510 /* -------> Set mark on. */
2513 LyXText * lt = bv_->getLyXText();
2516 lt->selection.mark(true);
2517 update(lt, BufferView::SELECT|BufferView::FITCUR);
2518 lt->selection.cursor = lt->cursor;
2519 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2523 case LFUN_BACKSPACE:
2525 LyXText * lt = bv_->getLyXText();
2527 if (!lt->selection.set()) {
2528 if (owner_->getIntl()->getTrans().backspace()) {
2530 lt->selection.cursor = lt->cursor;
2533 | BufferView::FITCUR
2534 | BufferView::CHANGE);
2535 // It is possible to make it a lot faster still
2536 // just comment out the line below...
2542 owner_->showState();
2547 case LFUN_BACKSPACE_SKIP:
2549 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2550 LyXText * lt = bv_->getLyXText();
2552 LyXCursor cursor = lt->cursor;
2554 if (!lt->selection.set()) {
2555 if (cursor.pos() == 0
2556 && !(cursor.par()->params().spaceTop()
2557 == VSpace (VSpace::NONE))) {
2560 cursor.par()->params().lineTop(),
2561 cursor.par()->params().lineBottom(),
2562 cursor.par()->params().pagebreakTop(),
2563 cursor.par()->params().pagebreakBottom(),
2564 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2565 cursor.par()->params().spacing(),
2566 cursor.par()->params().align(),
2567 cursor.par()->params().labelWidthString(), 0);
2570 | BufferView::FITCUR
2571 | BufferView::CHANGE);
2574 lt->selection.cursor = cursor;
2577 | BufferView::FITCUR
2578 | BufferView::CHANGE);
2585 case LFUN_BREAKPARAGRAPH:
2587 LyXText * lt = bv_->getLyXText();
2590 lt->breakParagraph(bv_, 0);
2593 | BufferView::FITCUR
2594 | BufferView::CHANGE);
2595 lt->selection.cursor = lt->cursor;
2597 owner_->showState();
2601 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2603 LyXText * lt = bv_->getLyXText();
2606 lt->breakParagraph(bv_, 1);
2609 | BufferView::FITCUR
2610 | BufferView::CHANGE);
2611 lt->selection.cursor = lt->cursor;
2613 owner_->showState();
2617 case LFUN_BREAKPARAGRAPH_SKIP:
2619 // When at the beginning of a paragraph, remove
2620 // indentation and add a "defskip" at the top.
2621 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2622 LyXText * lt = bv_->getLyXText();
2624 LyXCursor cursor = lt->cursor;
2627 if (cursor.pos() == 0) {
2628 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2631 cursor.par()->params().lineTop(),
2632 cursor.par()->params().lineBottom(),
2633 cursor.par()->params().pagebreakTop(),
2634 cursor.par()->params().pagebreakBottom(),
2635 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2636 cursor.par()->params().spacing(),
2637 cursor.par()->params().align(),
2638 cursor.par()->params().labelWidthString(), 1);
2639 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2643 lt->breakParagraph(bv_, 0);
2644 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2649 | BufferView::FITCUR
2650 | BufferView::CHANGE);
2651 lt->selection.cursor = cursor;
2653 owner_->showState();
2657 case LFUN_PARAGRAPH_SPACING:
2659 LyXText * lt = bv_->getLyXText();
2661 Paragraph * par = lt->cursor.par();
2662 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2663 float cur_value = 1.0;
2664 if (cur_spacing == Spacing::Other) {
2665 cur_value = par->params().spacing().getValue();
2668 istringstream istr(argument.c_str());
2672 Spacing::Space new_spacing = cur_spacing;
2673 float new_value = cur_value;
2675 lyxerr << "Missing argument to `paragraph-spacing'"
2677 } else if (tmp == "single") {
2678 new_spacing = Spacing::Single;
2679 } else if (tmp == "onehalf") {
2680 new_spacing = Spacing::Onehalf;
2681 } else if (tmp == "double") {
2682 new_spacing = Spacing::Double;
2683 } else if (tmp == "other") {
2684 new_spacing = Spacing::Other;
2687 lyxerr << "new_value = " << tmpval << endl;
2690 } else if (tmp == "default") {
2691 new_spacing = Spacing::Default;
2693 lyxerr << _("Unknown spacing argument: ")
2694 << argument << endl;
2696 if (cur_spacing != new_spacing || cur_value != new_value) {
2697 par->params().spacing(Spacing(new_spacing, new_value));
2698 lt->redoParagraph(bv_);
2701 | BufferView::FITCUR
2702 | BufferView::CHANGE);
2707 case LFUN_INSET_TOGGLE:
2709 LyXText * lt = bv_->getLyXText();
2712 update(lt, BufferView::SELECT|BufferView::FITCUR);
2713 lt->toggleInset(bv_);
2714 update(lt, BufferView::SELECT|BufferView::FITCUR);
2726 InsetCommandParams p;
2727 if (action == LFUN_HTMLURL)
2728 p.setCmdName("htmlurl");
2730 p.setCmdName("url");
2731 owner_->getDialogs()->createUrl(p.getAsString());
2735 case LFUN_INSERT_URL:
2737 InsetCommandParams p;
2738 p.setFromString(argument);
2740 InsetUrl * inset = new InsetUrl(p);
2741 if (!insertInset(inset))
2744 updateInset(inset, true);
2748 case LFUN_INSET_TEXT:
2749 insertAndEditInset(new InsetText);
2752 case LFUN_INSET_ERT:
2753 insertAndEditInset(new InsetERT);
2756 case LFUN_INSET_EXTERNAL:
2757 insertAndEditInset(new InsetExternal);
2760 case LFUN_INSET_FOOTNOTE:
2761 insertAndEditInset(new InsetFoot);
2764 case LFUN_INSET_MARGINAL:
2765 insertAndEditInset(new InsetMarginal);
2768 case LFUN_INSET_MINIPAGE:
2769 insertAndEditInset(new InsetMinipage);
2772 case LFUN_INSERT_NOTE:
2773 insertAndEditInset(new InsetNote);
2776 case LFUN_INSET_FLOAT:
2777 // check if the float type exist
2778 if (floatList.typeExist(argument)) {
2779 insertAndEditInset(new InsetFloat(argument));
2781 lyxerr << "Non-existent float type: "
2782 << argument << endl;
2786 case LFUN_INSET_WIDE_FLOAT:
2788 // check if the float type exist
2789 if (floatList.typeExist(argument)) {
2790 InsetFloat * new_inset = new InsetFloat(argument);
2791 new_inset->wide(true);
2792 if (insertInset(new_inset))
2793 new_inset->edit(bv_);
2797 lyxerr << "Non-existent float type: "
2798 << argument << endl;
2805 case LFUN_INSET_LIST:
2806 insertAndEditInset(new InsetList);
2809 case LFUN_INSET_THEOREM:
2810 insertAndEditInset(new InsetTheorem);
2814 case LFUN_INSET_CAPTION:
2816 // Do we have a locking inset...
2817 if (bv_->theLockingInset()) {
2818 lyxerr << "Locking inset code: "
2819 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2820 InsetCaption * new_inset = new InsetCaption;
2821 new_inset->setOwner(bv_->theLockingInset());
2822 new_inset->setAutoBreakRows(true);
2823 new_inset->setDrawFrame(0, InsetText::LOCKED);
2824 new_inset->setFrameColor(0, LColor::captionframe);
2825 if (insertInset(new_inset))
2826 new_inset->edit(bv_);
2833 case LFUN_INSET_TABULAR:
2837 if (!argument.empty())
2838 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2839 InsetTabular * new_inset =
2840 new InsetTabular(*buffer_, r, c);
2842 bv_->getLyXText()->real_current_font.isRightToLeft();
2843 if (!open_new_inset(new_inset, rtl))
2848 // --- lyxserver commands ----------------------------
2850 case LFUN_CHARATCURSOR:
2852 pos_type pos = bv_->getLyXText()->cursor.pos();
2853 if (pos < bv_->getLyXText()->cursor.par()->size())
2854 owner_->getLyXFunc()->setMessage(
2855 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2857 owner_->getLyXFunc()->setMessage("EOF");
2862 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2864 + tostr(bv_->getLyXText()->cursor.y()));
2871 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2872 lyxerr << "SETXY: Could not parse coordinates in '"
2873 << argument << std::endl;
2875 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2879 case LFUN_GETLAYOUT:
2880 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2885 LyXFont & font = bv_->getLyXText()->current_font;
2886 if (font.shape() == LyXFont::ITALIC_SHAPE)
2887 owner_->getLyXFunc()->setMessage("E");
2888 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2889 owner_->getLyXFunc()->setMessage("N");
2891 owner_->getLyXFunc()->setMessage("0");
2896 // --- accented characters ---------------------------
2899 case LFUN_CIRCUMFLEX:
2909 case LFUN_SPECIAL_CARON:
2912 case LFUN_HUNG_UMLAUT:
2915 if (argument.empty()) {
2917 owner_->getLyXFunc()->handleKeyFunc(action);
2919 owner_->getLyXFunc()->handleKeyFunc(action);
2920 owner_->getIntl()->getTrans()
2921 .TranslateAndInsert(argument[0], bv_->getLyXText());
2922 update(bv_->getLyXText(),
2924 | BufferView::FITCUR
2925 | BufferView::CHANGE);
2929 case LFUN_MATH_MACRO:
2930 mathDispatchMathMacro(bv_, argument);
2933 case LFUN_MATH_DELIM:
2934 mathDispatchMathDelim(bv_, argument);
2937 case LFUN_INSERT_MATRIX:
2938 mathDispatchInsertMatrix(bv_, argument);
2941 case LFUN_INSERT_MATH:
2942 mathDispatchInsertMath(bv_, argument);
2945 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2946 mathDispatchMathImportSelection(bv_, argument);
2949 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2950 mathDispatchMathDisplay(bv_, argument);
2953 case LFUN_MATH_MODE: // Open or create an inlined math inset
2954 mathDispatchMathMode(bv_, argument);
2957 case LFUN_GREEK: // Insert a single greek letter
2958 mathDispatchGreek(bv_, argument);
2961 case LFUN_CITATION_INSERT:
2963 InsetCommandParams p;
2964 p.setFromString( argument );
2966 InsetCitation * inset = new InsetCitation( p );
2967 if (!insertInset(inset))
2970 updateInset( inset, true );
2974 case LFUN_INSERT_BIBTEX:
2976 // ale970405+lasgoutt970425
2977 // The argument can be up to two tokens separated
2978 // by a space. The first one is the bibstyle.
2979 string const db = token(argument, ' ', 0);
2980 string const bibstyle = token(argument, ' ', 1);
2982 InsetCommandParams p( "BibTeX", db, bibstyle );
2983 InsetBibtex * inset = new InsetBibtex(p);
2985 if (insertInset(inset)) {
2986 if (argument.empty())
2993 // BibTeX data bases
2994 case LFUN_BIBDB_ADD:
2996 InsetBibtex * inset =
2997 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2999 inset->addDatabase(argument);
3004 case LFUN_BIBDB_DEL:
3006 InsetBibtex * inset =
3007 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3009 inset->delDatabase(argument);
3014 case LFUN_BIBTEX_STYLE:
3016 InsetBibtex * inset =
3017 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3019 inset->setOptions(argument);
3024 case LFUN_INDEX_CREATE:
3026 InsetCommandParams p("index");
3027 if (argument.empty()) {
3028 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3029 p.setContents(idxstring);
3031 p.setContents(argument);
3034 owner_->getDialogs()->createIndex(p.getAsString());
3038 case LFUN_INDEX_INSERT:
3040 InsetCommandParams p;
3041 p.setFromString(argument);
3042 InsetIndex * inset = new InsetIndex(p);
3044 if (!insertInset(inset))
3047 updateInset(inset, true);
3051 case LFUN_INDEX_INSERT_LAST:
3053 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3054 if (!idxstring.empty()) {
3055 owner_->message(_("Word `")
3056 + idxstring + _(("' indexed.")));
3057 InsetCommandParams p("index", idxstring);
3058 InsetIndex * inset = new InsetIndex(p);
3060 if (!insertInset(inset))
3063 updateInset(inset, true);
3068 case LFUN_INDEX_PRINT:
3070 InsetCommandParams p("printindex");
3071 Inset * inset = new InsetPrintIndex(p);
3072 if (!insertInset(inset, "Standard"))
3077 case LFUN_PARENTINSERT:
3079 lyxerr << "arg " << argument << endl;
3080 InsetCommandParams p( "lyxparent", argument );
3081 Inset * inset = new InsetParent(p, *buffer_);
3082 if (!insertInset(inset, "Standard"))
3088 case LFUN_CHILD_INSERT:
3090 InsetInclude::Params p;
3091 p.cparams.setFromString(argument);
3092 p.masterFilename_ = buffer_->fileName();
3094 InsetInclude * inset = new InsetInclude(p);
3095 if (!insertInset(inset))
3098 updateInset(inset, true);
3099 bv_->owner()->getDialogs()->showInclude(inset);
3104 case LFUN_FLOAT_LIST:
3106 // We should check the argument for validity. (Lgb)
3107 Inset * inset = new InsetFloatList(argument);
3108 if (!insertInset(inset, "Standard"))
3113 case LFUN_THESAURUS_ENTRY:
3115 string arg = argument;
3118 arg = bv_->getLyXText()->selectionAsString(buffer_,
3122 if (arg.size() > 100 || arg.empty()) {
3123 // Get word or selection
3124 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3125 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3126 // FIXME: where is getLyXText()->unselect(bv_) ?
3130 bv_->owner()->getDialogs()->showThesaurus(arg);
3134 case LFUN_SELFINSERT:
3136 if (argument.empty()) break;
3138 /* Automatically delete the currently selected
3139 * text and replace it with what is being
3140 * typed in now. Depends on lyxrc settings
3141 * "auto_region_delete", which defaults to
3144 LyXText * lt = bv_->getLyXText();
3146 if (lyxrc.auto_region_delete) {
3147 if (lt->selection.set()) {
3148 lt->cutSelection(bv_, false, false);
3151 | BufferView::FITCUR
3152 | BufferView::CHANGE);
3157 LyXFont const old_font(lt->real_current_font);
3159 string::const_iterator cit = argument.begin();
3160 string::const_iterator end = argument.end();
3161 for (; cit != end; ++cit) {
3162 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3167 | BufferView::FITCUR
3168 | BufferView::CHANGE);
3170 lt->selection.cursor = lt->cursor;
3171 moveCursorUpdate(false);
3173 // real_current_font.number can change so we need to
3174 // update the minibuffer
3175 if (old_font != lt->real_current_font)
3176 owner_->showState();
3181 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3183 time_t now_time_t = time(NULL);
3184 struct tm * now_tm = localtime(&now_time_t);
3185 setlocale(LC_TIME, "");
3187 if (!argument.empty())
3190 arg = lyxrc.date_insert_format;
3192 int const datetmp_len =
3193 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3195 LyXText * lt = bv_->getLyXText();
3197 for (int i = 0; i < datetmp_len; i++) {
3198 lt->insertChar(bv_, datetmp[i]);
3201 | BufferView::FITCUR
3202 | BufferView::CHANGE);
3205 lt->selection.cursor = lt->cursor;
3206 moveCursorUpdate(false);
3210 case LFUN_UNKNOWN_ACTION:
3211 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3222 void BufferView::Pimpl::newline()
3225 LyXText * lt = bv_->getLyXText();
3229 | BufferView::FITCUR);
3230 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3233 | BufferView::FITCUR
3234 | BufferView::CHANGE);
3239 void BufferView::Pimpl::hfill()
3242 LyXText * lt = bv_->getLyXText();
3246 | BufferView::FITCUR);
3247 lt->insertChar(bv_, Paragraph::META_HFILL);
3250 | BufferView::FITCUR
3251 | BufferView::CHANGE);
3256 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3260 update(lt, BufferView::SELECT|BufferView::FITCUR);
3261 InsetSpecialChar * new_inset =
3262 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3263 #ifdef WITH_WARNINGS
3264 #warning Why is this code different from specialChar() below? (JMarc)
3265 // the code in specialChar is a generic version of what used to exist
3266 // for other special chars. I did not merge this case because of the
3267 // call to updateInset(), but what does it do?
3269 if (!insertInset(new_inset))
3272 updateInset(new_inset, true);
3277 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3280 LyXText * lt = bv_->getLyXText();
3283 update(lt, BufferView::SELECT|BufferView::FITCUR);
3284 InsetSpecialChar * new_inset =
3285 new InsetSpecialChar(kind);
3286 if (!insertInset(new_inset))
3292 void BufferView::Pimpl::smartQuote()
3294 LyXText const * lt = bv_->getLyXText();
3295 Paragraph const * par = lt->cursor.par();
3296 pos_type pos = lt->cursor.pos();
3300 || (par->isInset(pos - 1)
3301 && par->getInset(pos - 1)->isSpace()))
3304 c = par->getChar(pos - 1);
3309 LyXLayout const & style = textclasslist.Style(
3310 bv_->buffer()->params.textclass, par->getLayout());
3312 if (style.pass_thru ||
3313 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3314 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3318 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3320 if (insertInset(inset))
3327 // Open and lock an updatable inset
3328 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3330 LyXText * lt = bv_->getLyXText();
3334 if (!insertInset(new_inset)) {
3338 new_inset->edit(bv_, !behind);
3343 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3345 // if we are in a locking inset we should try to insert the
3346 // inset there otherwise this is a illegal function now
3347 if (bv_->theLockingInset()) {
3348 if (bv_->theLockingInset()->insetAllowed(inset))
3349 return bv_->theLockingInset()->insertInset(bv_, inset);
3353 // not quite sure if we want this...
3354 setCursorParUndo(bv_);
3357 beforeChange(bv_->text);
3358 if (!lout.empty()) {
3359 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3360 bv_->text->breakParagraph(bv_);
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3363 if (bv_->text->cursor.par()->size()) {
3364 bv_->text->cursorLeft(bv_);
3366 bv_->text->breakParagraph(bv_);
3367 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3370 pair<bool, layout_type> lres =
3371 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3372 layout_type lay = 0;
3373 if (lres.first != false) {
3377 // layout not fount using default "Standard" (0)
3381 bv_->text->setLayout(bv_, lay);
3383 bv_->text->setParagraph(bv_, 0, 0,
3385 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3390 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3393 bv_->text->insertInset(bv_, inset);
3394 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3401 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3406 // first check for locking insets
3407 if (bv_->theLockingInset()) {
3408 if (bv_->theLockingInset() == inset) {
3409 if (bv_->text->updateInset(bv_, inset)) {
3412 buffer_->markDirty();
3417 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3418 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3421 buffer_->markDirty();
3429 // then check the current buffer
3432 update(bv_->text, BufferView::UPDATE);
3433 if (bv_->text->updateInset(bv_, inset)) {
3437 | BufferView::FITCUR
3438 | BufferView::CHANGE);
3440 update(bv_->text, SELECT);
3448 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3451 if (!available()) return;
3454 beforeChange(bv_->text);
3455 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3457 LyXCursor const & cursor = bv_->text->cursor;
3461 cursor.par()->isInset(cursor.pos())) {
3462 Inset const * inset = cursor.par()->getInset(cursor.pos());
3463 if (find(codes.begin(), codes.end(), inset->lyxCode())
3466 static_cast<InsetCommand const *>(inset)->getContents();
3470 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3471 if (bv_->text->cursor.pos()
3472 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3473 LyXCursor tmp = bv_->text->cursor;
3474 bv_->text->cursor.par(bv_->text->ownerParagraph());
3475 bv_->text->cursor.pos(0);
3476 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3477 bv_->text->cursor = tmp;
3478 bv_->owner()->message(_("No more insets"));
3481 bv_->owner()->message(_("No more insets"));
3484 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3485 bv_->text->selection.cursor = bv_->text->cursor;
3489 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3491 gotoInset(vector<Inset::Code>(1, code), same_content);