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));
159 cursor_timeout.timeout.connect(slot(this,
160 &BufferView::Pimpl::cursorToggle));
161 cursor_timeout.start();
162 workarea_.setFocus();
163 saved_positions.resize(saved_positions_num);
167 Painter & BufferView::Pimpl::painter()
169 return workarea_.getPainter();
173 void BufferView::Pimpl::buffer(Buffer * b)
175 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
179 buffer_->delUser(bv_);
181 // Put the old text into the TextCache, but
182 // only if the buffer is still loaded.
183 // Also set the owner of the test to 0
184 // bv_->text->owner(0);
185 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
186 if (lyxerr.debugging())
187 textcache.show(lyxerr, "BufferView::buffer");
192 // Set current buffer
195 if (bufferlist.getState() == BufferList::CLOSING) return;
198 // screen is always deleted when the buffer is changed.
201 // If we are closing the buffer, use the first buffer as current
203 buffer_ = bufferlist.first();
207 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
208 buffer_->addUser(bv_);
209 // If we don't have a text object for this, we make one
210 if (bv_->text == 0) {
211 resizeCurrentBuffer();
216 bv_->text->first = screen_->topCursorVisible(bv_->text);
217 owner_->updateMenubar();
218 owner_->updateToolbar();
219 // Similarly, buffer-dependent dialogs should be updated or
220 // hidden. This should go here because some dialogs (eg ToC)
221 // require bv_->text.
222 owner_->getDialogs()->updateBufferDependent(true);
226 lyxerr[Debug::INFO] << " No Buffer!" << endl;
227 owner_->updateMenubar();
228 owner_->updateToolbar();
229 owner_->getDialogs()->hideBufferDependent();
233 // Also remove all remaining text's from the testcache.
234 // (there should not be any!) (if there is any it is a
236 if (lyxerr.debugging())
237 textcache.show(lyxerr, "buffer delete all");
240 // should update layoutchoice even if we don't have a buffer.
241 owner_->updateLayoutChoice();
243 owner_->updateWindowTitle();
247 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
249 workarea_.resize(xpos, ypos, width, height);
250 update(bv_->text, SELECT);
255 void BufferView::Pimpl::resize()
258 resizeCurrentBuffer();
262 void BufferView::Pimpl::redraw()
264 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
269 bool BufferView::Pimpl::fitCursor()
271 lyx::Assert(screen_.get());
275 if (bv_->theLockingInset()) {
276 bv_->theLockingInset()->fitInsetCursor(bv_);
279 ret = screen_->fitCursor(bv_->text, bv_);
282 bv_->owner()->getDialogs()->updateParagraph();
289 void BufferView::Pimpl::redoCurrentBuffer()
291 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
292 if (buffer_ && bv_->text) {
294 owner_->updateLayoutChoice();
299 int BufferView::Pimpl::resizeCurrentBuffer()
301 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
304 Paragraph * selstartpar = 0;
305 Paragraph * selendpar = 0;
306 UpdatableInset * the_locking_inset = 0;
309 pos_type selstartpos = 0;
310 pos_type selendpos = 0;
311 bool selection = false;
312 bool mark_set = false;
314 owner_->prohibitInput();
316 owner_->message(_("Formatting document..."));
319 par = bv_->text->cursor.par();
320 pos = bv_->text->cursor.pos();
321 selstartpar = bv_->text->selection.start.par();
322 selstartpos = bv_->text->selection.start.pos();
323 selendpar = bv_->text->selection.end.par();
324 selendpos = bv_->text->selection.end.pos();
325 selection = bv_->text->selection.set();
326 mark_set = bv_->text->selection.mark();
327 the_locking_inset = bv_->theLockingInset();
329 bv_->text = new LyXText(bv_);
330 bv_->text->init(bv_);
332 // See if we have a text in TextCache that fits
333 // the new buffer_ with the correct width.
334 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
336 if (lyxerr.debugging()) {
337 lyxerr << "Found a LyXText that fits:\n";
338 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
340 // Set the owner of the newly found text
341 // bv_->text->owner(bv_);
342 if (lyxerr.debugging())
343 textcache.show(lyxerr, "resizeCurrentBuffer");
345 bv_->text = new LyXText(bv_);
346 bv_->text->init(bv_);
352 bv_->text->selection.set(true);
353 /* at this point just to avoid the Delete-Empty-Paragraph
354 * Mechanism when setting the cursor */
355 bv_->text->selection.mark(mark_set);
357 bv_->text->setCursor(bv_, selstartpar, selstartpos);
358 bv_->text->selection.cursor = bv_->text->cursor;
359 bv_->text->setCursor(bv_, selendpar, selendpos);
360 bv_->text->setSelection(bv_);
361 bv_->text->setCursor(bv_, par, pos);
363 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->selection.cursor = bv_->text->cursor;
365 bv_->text->selection.set(false);
367 // remake the inset locking
368 bv_->theLockingInset(the_locking_inset);
370 bv_->text->first = screen_->topCursorVisible(bv_->text);
372 buffer_->resizeInsets(bv_);
374 // this will scroll the screen such that the cursor becomes visible
379 owner_->allowInput();
381 /// clear the "Formatting Document" message
388 void BufferView::Pimpl::updateScreen()
390 // Regenerate the screen.
391 screen_.reset(new LyXScreen(workarea_));
395 void BufferView::Pimpl::updateScrollbar()
397 /* If the text is smaller than the working area, the scrollbar
398 * maximum must be the working area height. No scrolling will
401 workarea_.setScrollbar(0, 1.0);
405 long const text_height = bv_->text->height;
407 double const lineh = bv_->text->defaultHeight();
408 double const slider_size =
409 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
411 static long old_text_height = 0;
412 static double old_lineh = 0;
413 static double old_slider_size = 0;
415 if (text_height != old_text_height) {
416 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
417 old_text_height = text_height;
419 if (lineh != old_lineh) {
420 workarea_.setScrollbarIncrements(lineh);
423 if (current_scrollbar_value != bv_->text->first
424 || slider_size != old_slider_size) {
425 current_scrollbar_value = bv_->text->first;
426 workarea_.setScrollbar(current_scrollbar_value, slider_size);
427 old_slider_size = slider_size;
432 // Callback for scrollbar slider
433 void BufferView::Pimpl::scrollCB(double value)
435 if (!buffer_) return;
437 current_scrollbar_value = long(value);
438 if (current_scrollbar_value < 0)
439 current_scrollbar_value = 0;
444 screen_->draw(bv_->text, bv_, current_scrollbar_value);
446 if (!lyxrc.cursor_follows_scrollbar) {
451 LyXText * vbt = bv_->text;
453 int const height = vbt->defaultHeight();
454 int const first = static_cast<int>((bv_->text->first + height));
455 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
457 if (vbt->cursor.y() < first)
458 vbt->setCursorFromCoordinates(bv_, 0, first);
459 else if (vbt->cursor.y() > last)
460 vbt->setCursorFromCoordinates(bv_, 0, last);
466 int BufferView::Pimpl::scrollUp(long time)
468 if (!buffer_) return 0;
469 if (!screen_.get()) return 0;
471 double value = workarea_.getScrollbarValue();
473 if (value == 0) return 0;
475 float add_value = (bv_->text->defaultHeight()
476 + float(time) * float(time) * 0.125);
478 if (add_value > workarea_.height())
479 add_value = float(workarea_.height() -
480 bv_->text->defaultHeight());
487 workarea_.setScrollbarValue(value);
494 int BufferView::Pimpl::scrollDown(long time)
496 if (!buffer_) return 0;
497 if (!screen_.get()) return 0;
499 double value = workarea_.getScrollbarValue();
500 pair<float, float> p = workarea_.getScrollbarBounds();
501 double const max = p.second;
503 if (value == max) return 0;
505 float add_value = (bv_->text->defaultHeight()
506 + float(time) * float(time) * 0.125);
508 if (add_value > workarea_.height())
509 add_value = float(workarea_.height() -
510 bv_->text->defaultHeight());
517 workarea_.setScrollbarValue(value);
524 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
526 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
530 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
532 // Only use motion with button 1
533 if (!(state & Button1MotionMask))
536 if (!buffer_ || !screen_.get()) return;
538 // Check for inset locking
539 if (bv_->theLockingInset()) {
540 LyXCursor cursor = bv_->text->cursor;
541 LyXFont font = bv_->text->getFont(buffer_,
542 cursor.par(), cursor.pos());
543 int width = bv_->theLockingInset()->width(bv_, font);
544 int inset_x = font.isVisibleRightToLeft()
545 ? cursor.x() - width : cursor.x();
546 int start_x = inset_x + bv_->theLockingInset()->scroll();
547 bv_->theLockingInset()->
548 insetMotionNotify(bv_,
550 y - cursor.y() + bv_->text->first,
555 /* The test for not selection possible is needed, that only motion
556 events are used, where the bottom press event was on
557 the drawing area too */
558 if (!selection_possible)
561 screen_->hideCursor();
563 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
565 if (!bv_->text->selection.set())
566 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
568 bv_->text->setSelection(bv_);
569 screen_->toggleToggle(bv_->text, bv_);
572 screen_->showCursor(bv_->text, bv_);
579 // Single-click on work area
580 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
583 if (!buffer_ || !screen_.get()) return;
585 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
587 // ok ok, this is a hack.
588 if (button == 4 || button == 5) {
591 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
594 scrollDown(lyxrc.wheel_jump);
599 if (bv_->theLockingInset()) {
600 // We are in inset locking mode
602 /* Check whether the inset was hit. If not reset mode,
603 otherwise give the event to the inset */
604 if (inset_hit == bv_->theLockingInset()) {
605 bv_->theLockingInset()->
606 insetButtonPress(bv_,xpos, ypos,button);
609 bv_->unlockInset(bv_->theLockingInset());
614 selection_possible = true;
615 screen_->hideCursor();
617 int const screen_first = bv_->text->first;
619 // Middle button press pastes if we have a selection
620 bool paste_internally = false;
622 && bv_->text->selection.set()) {
623 owner_->getLyXFunc()->dispatch(LFUN_COPY);
624 paste_internally = true;
627 // Clear the selection
628 screen_->toggleSelection(bv_->text, bv_);
629 bv_->text->clearSelection();
630 bv_->text->fullRebreak(bv_);
632 screen_->update(bv_->text, bv_);
638 // Single left click in math inset?
639 if (isHighlyEditableInset(inset_hit)) {
640 // Highly editable inset, like math
641 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
642 selection_possible = false;
643 owner_->updateLayoutChoice();
644 owner_->message(inset->editMessage());
645 inset->insetButtonPress(bv_, xpos, ypos, button);
646 inset->edit(bv_, xpos, ypos, button);
650 // Right click on a footnote flag opens float menu
652 selection_possible = false;
656 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
657 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
659 bv_->text->selection.cursor = bv_->text->cursor;
660 bv_->text->cursor.x_fix(bv_->text->cursor.x());
662 owner_->updateLayoutChoice();
664 selection_possible = false;
667 // Insert primary selection with middle mouse
668 // if there is a local selection in the current buffer,
671 if (paste_internally)
672 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
674 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
676 selection_possible = false;
682 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
688 LyXText * text = bv_->getLyXText();
690 if (text->bv_owner && bv_->theLockingInset())
693 if (screen_.get() && button == 1) {
694 if (text->bv_owner) {
695 screen_->hideCursor();
696 screen_->toggleSelection(text, bv_);
697 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
698 screen_->toggleSelection(text, bv_, false);
700 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
702 /* This will fit the cursor on the screen
704 update(text, BufferView::SELECT|BufferView::FITCUR);
709 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
715 LyXText * text = bv_->getLyXText();
717 if (text->bv_owner && bv_->theLockingInset())
720 if (screen_.get() && (button == 1)) {
721 if (text->bv_owner) {
722 screen_->hideCursor();
723 screen_->toggleSelection(text, bv_);
725 text->cursorHome(bv_);
726 text->selection.cursor = text->cursor;
727 text->cursorEnd(bv_);
728 text->setSelection(bv_);
729 if (text->bv_owner) {
730 screen_->toggleSelection(text, bv_, false);
732 /* This will fit the cursor on the screen
734 update(text, BufferView::SELECT|BufferView::FITCUR);
739 void BufferView::Pimpl::enterView()
741 if (active() && available()) {
742 SetXtermCursor(workarea_.getWin());
743 using_xterm_cursor = true;
748 void BufferView::Pimpl::leaveView()
750 if (using_xterm_cursor) {
751 XUndefineCursor(fl_get_display(), workarea_.getWin());
752 using_xterm_cursor = false;
757 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
760 if (!buffer_ || !screen_.get()) return;
762 // If we hit an inset, we have the inset coordinates in these
763 // and inset_hit points to the inset. If we do not hit an
764 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
765 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
767 if (bv_->theLockingInset()) {
768 // We are in inset locking mode.
770 /* LyX does a kind of work-area grabbing for insets.
771 Only a ButtonPress Event outside the inset will
772 force a insetUnlock. */
773 bv_->theLockingInset()->
774 insetButtonRelease(bv_, x, y, button);
778 selection_possible = false;
786 // Did we hit an editable inset?
788 // Inset like error, notes and figures
789 selection_possible = false;
791 // if we reach this point with a selection, it
792 // must mean we are currently selecting.
793 // But we don't want to open the inset
794 // because that is annoying for the user.
795 // So just pretend we didn't hit it.
796 // this is OK because a "kosher" ButtonRelease
797 // will follow a ButtonPress that clears
799 // Note this also fixes selection drawing
800 // problems if we end up opening an inset
801 if (bv_->getLyXText()->selection.set())
804 // CHECK fix this proper in 0.13
805 // well, maybe 13.0 !!!!!!!!!
807 // Following a ref shouldn't issue
808 // a push on the undo-stack
809 // anylonger, now that we have
810 // keybindings for following
811 // references and returning from
812 // references. IMHO though, it
813 // should be the inset's own business
814 // to push or not push on the undo
815 // stack. They don't *have* to
816 // alter the document...
818 // ...or maybe the SetCursorParUndo()
819 // below isn't necessary at all anylonger?
820 if (inset_hit->lyxCode() == Inset::REF_CODE) {
821 setCursorParUndo(bv_);
824 owner_->message(inset_hit->editMessage());
826 if (isHighlyEditableInset(inset_hit)) {
827 // Highly editable inset, like math
828 UpdatableInset *inset = (UpdatableInset *)inset_hit;
829 inset->insetButtonRelease(bv_, x, y, button);
831 inset_hit->insetButtonRelease(bv_, x, y, button);
832 inset_hit->edit(bv_, x, y, button);
838 #warning variable c is set but never used. What is it good for?? (JMarc)
839 #warning isnt this code dead ?? "open a float" ??? (jbl)
841 // check whether we want to open a float
845 if (bv_->text->cursor.pos() <
846 bv_->text->cursor.par()->size()) {
847 c = bv_->text->cursor.par()->
848 getChar(bv_->text->cursor.pos());
850 if (bv_->text->cursor.pos() - 1 >= 0) {
851 c = bv_->text->cursor.par()->
852 getChar(bv_->text->cursor.pos() - 1);
855 selection_possible = false;
860 // Maybe we want to edit a bibitem ale970302
861 if (bv_->text->cursor.par()->bibkey && x < 20 +
862 bibitemMaxWidth(bv_, textclasslist.
864 params.textclass).defaultfont())) {
865 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
872 Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
874 Paragraph /*const*/ & par = *cursor.par();
875 pos_type const pos = cursor.pos();
877 lyx::Assert(par.getInset(pos));
879 Inset const & inset(*par.getInset(pos));
881 LyXFont const & font = text.getFont(buffer_, &par, pos);
883 int const width = inset.width(bv_, font);
884 int const inset_x = font.isVisibleRightToLeft()
885 ? (cursor.x() - width) : cursor.x();
888 inset_x + inset.scroll(),
890 cursor.y() - inset.ascent(bv_, font),
891 cursor.y() + inset.descent(bv_, font));
895 Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
897 pos_type const pos(cursor.pos());
898 Paragraph /*const*/ & par(*cursor.par());
900 if (pos >= par.size() || !par.isInset(pos)) {
904 Inset /*const*/ * inset = par.getInset(pos);
906 if (!isEditableInset(inset)) {
910 Box b(insetDimensions(text, cursor));
912 if (!b.contained(x, y)) {
913 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
914 << " box " << b << endl;
918 text.setCursor(bv_, &par, pos, true);
921 // The origin of an inset is on the baseline
922 y -= (text.cursor.y());
928 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
933 int y_tmp = y + text->first;
936 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
938 Inset * inset(checkInset(*text, cursor, x, y_tmp));
945 // look at previous position
947 if (cursor.pos() == 0) {
952 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
954 inset = checkInset(*text, cursor, x, y_tmp);
962 void BufferView::Pimpl::workAreaExpose()
964 static int work_area_width;
965 static unsigned int work_area_height;
967 bool const widthChange = workarea_.workWidth() != work_area_width;
968 bool const heightChange = workarea_.height() != work_area_height;
970 // update from work area
971 work_area_width = workarea_.workWidth();
972 work_area_height = workarea_.height();
975 // The visible LyXView need a resize
978 // Remove all texts from the textcache
979 // This is not _really_ what we want to do. What
980 // we really want to do is to delete in textcache
981 // that does not have a BufferView with matching
982 // width, but as long as we have only one BufferView
983 // deleting all gives the same result.
984 if (lyxerr.debugging())
985 textcache.show(lyxerr, "Expose delete all");
987 } else if (heightChange) {
988 // Rebuild image of current screen
990 // fitCursor() ensures we don't jump back
991 // to the start of the document on vertical
995 // The main window size has changed, repaint most stuff
997 } else if (screen_.get())
998 screen_->redraw(bv_->text, bv_);
1000 // Grey box when we don't have a buffer
1001 workarea_.greyOut();
1004 // always make sure that the scrollbar is sane.
1006 owner_->updateLayoutChoice();
1011 void BufferView::Pimpl::update()
1013 if (screen_.get() &&
1014 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1016 LyXText::text_status st = bv_->text->status();
1017 screen_->update(bv_->text, bv_);
1019 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1020 if (bv_->text->fullRebreak(bv_)) {
1021 st = LyXText::NEED_MORE_REFRESH;
1022 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1023 bv_->text->cursor.pos());
1026 bv_->text->status(bv_, st);
1027 screen_->update(bv_->text, bv_);
1029 // do this here instead of in the screen::update because of
1031 bv_->text->status(bv_, LyXText::UNCHANGED);
1037 // Values used when calling update:
1039 // -2 - update, move sel_cursor if selection, fitcursor
1040 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1041 // 0 - update, move sel_cursor if selection, fitcursor
1042 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1043 // 3 - update, move sel_cursor if selection
1046 // a simple redraw of the parts that need refresh
1048 // move sel_cursor if selection -
1049 // the text's sel_cursor is moved if there is selection is progress
1052 // fitCursor() is called and the scrollbar updated
1055 // the buffer is marked dirty.
1064 // UPDATE_ONLY = UPDATE;
1065 // UPDATE_SELECT = UPDATE | SELECT;
1066 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1067 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1069 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1070 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1071 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1072 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1073 // update(3) -> update(1) -> update(1) -> update(SELECT)
1075 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1077 owner_->updateLayoutChoice();
1079 if (!text->selection.set() && (f & SELECT)) {
1080 text->selection.cursor = text->cursor;
1083 text->fullRebreak(bv_);
1085 if (text->inset_owner) {
1086 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1087 updateInset(text->inset_owner, false);
1097 buffer_->markDirty();
1102 // Callback for cursor timer
1103 void BufferView::Pimpl::cursorToggle()
1105 // Quite a nice place for asyncron Inset updating, isn't it?
1106 // Actually no! This is run even if no buffer exist... so (Lgb)
1108 cursor_timeout.restart();
1113 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1114 if (pid == -1) // error find out what is wrong
1115 ; // ignore it for now.
1117 sigchldchecker(pid, &status);
1119 updatelist.update(bv_);
1121 if (!screen_.get()) {
1122 cursor_timeout.restart();
1126 if (!bv_->theLockingInset()) {
1127 screen_->cursorToggle(bv_);
1129 bv_->theLockingInset()->toggleInsetCursor(bv_);
1132 cursor_timeout.restart();
1136 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1138 if (!text->cursor.row()->previous())
1141 int y = text->first;
1142 if (text->inset_owner)
1143 y += bv_->text->first;
1144 Row * cursorrow = text->cursor.row();
1145 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1147 // This is to allow jumping over large insets
1148 if ((cursorrow == text->cursor.row()))
1149 text->cursorUp(bv_);
1151 if (text->inset_owner ||
1152 text->cursor.row()->height() < workarea_.height())
1153 screen_->draw(bv_->text, bv_,
1155 - text->cursor.row()->baseline()
1156 + text->cursor.row()->height()
1157 - workarea_.height() + 1 );
1162 void BufferView::Pimpl::cursorNext(LyXText * text)
1164 if (!text->cursor.row()->next())
1167 int y = text->first + workarea_.height();
1168 // if (text->inset_owner)
1169 // y += bv_->text->first;
1170 text->getRowNearY(y);
1172 Row * cursorrow = text->cursor.row();
1173 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1175 // This is to allow jumping over large insets
1176 if ((cursorrow == bv_->text->cursor.row()))
1177 text->cursorDown(bv_);
1179 if (text->inset_owner ||
1180 text->cursor.row()->height() < workarea_.height())
1181 screen_->draw(bv_->text, bv_, text->cursor.y() -
1182 text->cursor.row()->baseline());
1187 bool BufferView::Pimpl::available() const
1189 if (buffer_ && bv_->text) return true;
1194 void BufferView::Pimpl::beforeChange(LyXText * text)
1197 text->clearSelection();
1201 void BufferView::Pimpl::savePosition(unsigned int i)
1203 if (i >= saved_positions_num)
1205 saved_positions[i] = Position(buffer_->fileName(),
1206 bv_->text->cursor.par()->id(),
1207 bv_->text->cursor.pos());
1210 str << _("Saved bookmark") << ' ' << i;
1211 owner_->message(str.str().c_str());
1216 void BufferView::Pimpl::restorePosition(unsigned int i)
1218 if (i >= saved_positions_num)
1221 string const fname = saved_positions[i].filename;
1223 beforeChange(bv_->text);
1225 if (fname != buffer_->fileName()) {
1226 Buffer * b = bufferlist.exists(fname) ?
1227 bufferlist.getBuffer(fname) :
1228 bufferlist.loadLyXFile(fname); // don't ask, just load it
1229 if (b != 0 ) buffer(b);
1232 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1236 bv_->text->setCursor(bv_, par,
1237 min(par->size(), saved_positions[i].par_pos));
1239 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1242 str << _("Moved to bookmark") << ' ' << i;
1243 owner_->message(str.str().c_str());
1248 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1250 if (i >= saved_positions_num)
1253 return !saved_positions[i].filename.empty();
1257 void BufferView::Pimpl::setState()
1259 if (!lyxrc.rtl_support)
1262 LyXText * text = bv_->getLyXText();
1263 if (text->real_current_font.isRightToLeft()) {
1264 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1265 owner_->getIntl()->KeyMapSec();
1267 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1268 owner_->getIntl()->KeyMapPrim();
1273 void BufferView::Pimpl::insetSleep()
1275 if (bv_->theLockingInset() && !inset_slept) {
1276 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1277 bv_->theLockingInset()->insetUnlock(bv_);
1283 void BufferView::Pimpl::insetWakeup()
1285 if (bv_->theLockingInset() && inset_slept) {
1286 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1287 inset_slept = false;
1292 void BufferView::Pimpl::insetUnlock()
1294 if (bv_->theLockingInset()) {
1296 bv_->theLockingInset()->insetUnlock(bv_);
1297 bv_->theLockingInset(0);
1299 inset_slept = false;
1304 bool BufferView::Pimpl::focus() const
1306 return workarea_.hasFocus();
1310 void BufferView::Pimpl::focus(bool f)
1312 if (f) workarea_.setFocus();
1316 bool BufferView::Pimpl::active() const
1318 return workarea_.active();
1322 bool BufferView::Pimpl::belowMouse() const
1324 return workarea_.belowMouse();
1328 void BufferView::Pimpl::showCursor()
1330 if (screen_.get()) {
1331 if (bv_->theLockingInset())
1332 bv_->theLockingInset()->showInsetCursor(bv_);
1334 screen_->showCursor(bv_->text, bv_);
1339 void BufferView::Pimpl::hideCursor()
1341 if (screen_.get()) {
1342 if (!bv_->theLockingInset())
1343 // bv_->theLockingInset()->hideInsetCursor(bv_);
1345 screen_->hideCursor();
1350 void BufferView::Pimpl::toggleSelection(bool b)
1352 if (screen_.get()) {
1353 if (bv_->theLockingInset())
1354 bv_->theLockingInset()->toggleSelection(bv_, b);
1355 screen_->toggleSelection(bv_->text, bv_, b);
1360 void BufferView::Pimpl::toggleToggle()
1363 screen_->toggleToggle(bv_->text, bv_);
1367 void BufferView::Pimpl::center()
1369 beforeChange(bv_->text);
1370 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1371 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1373 screen_->draw(bv_->text, bv_, 0);
1375 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1380 void BufferView::Pimpl::pasteClipboard(bool asPara)
1382 if (!buffer_) return;
1384 screen_->hideCursor();
1385 beforeChange(bv_->text);
1387 string const clip(workarea_.getClipboard());
1389 if (clip.empty()) return;
1392 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1394 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1396 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1400 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1402 workarea_.putClipboard(stuff);
1407 * Dispatch functions for actions which can be valid for BufferView->text
1408 * and/or InsetText->text!!!
1413 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1415 LyXText * lt = bv_->getLyXText();
1417 if (selecting || lt->selection.mark()) {
1418 lt->setSelection(bv_);
1422 update(lt, BufferView::SELECT|BufferView::FITCUR);
1425 /* ---> Everytime the cursor is moved, show the current font state. */
1426 // should this too me moved out of this func?
1427 //owner->showState();
1432 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1434 LyXCursor cursor = bv_->getLyXText()->cursor;
1435 Buffer::inset_iterator it =
1436 find_if(Buffer::inset_iterator(
1437 cursor.par(), cursor.pos()),
1438 buffer_->inset_iterator_end(),
1439 lyx::compare_memfun(&Inset::lyxCode, code));
1440 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1444 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1446 string filename = filen;
1448 if (filename.empty()) {
1449 // Launch a file browser
1450 string initpath = lyxrc.document_path;
1453 string const trypath = owner_->buffer()->filepath;
1454 // If directory is writeable, use this as default.
1455 if (IsDirWriteable(trypath))
1459 FileDialog fileDlg(bv_->owner(),
1460 _("Select LyX document to insert"),
1462 make_pair(string(_("Documents")),
1463 string(lyxrc.document_path)),
1464 make_pair(string(_("Examples")),
1465 string(AddPath(system_lyxdir, "examples"))));
1467 FileDialog::Result result =
1468 fileDlg.Select(initpath,
1469 _("*.lyx| LyX Documents (*.lyx)"));
1471 if (result.first == FileDialog::Later)
1474 filename = result.second;
1476 // check selected filename
1477 if (filename.empty()) {
1478 owner_->message(_("Canceled."));
1483 // get absolute path of file and add ".lyx" to the filename if
1485 filename = FileSearch(string(), filename, "lyx");
1487 string const disp_fn(MakeDisplayPath(filename));
1490 s1 << _("Inserting document") << ' '
1491 << disp_fn << " ...";
1492 owner_->message(s1.str().c_str());
1493 bool const res = bv_->insertLyXFile(filename);
1496 str << _("Document") << ' ' << disp_fn
1497 << ' ' << _("inserted.");
1498 owner_->message(str.str().c_str());
1501 str << _("Could not insert document") << ' '
1503 owner_->message(str.str().c_str());
1508 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1510 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1511 << action <<"] arg[" << argument << "]" << endl;
1514 // --- Misc -------------------------------------------
1518 LyXText * lt = bv_->getLyXText();
1519 lt->toggleAppendix(bv_);
1522 | BufferView::FITCUR
1523 | BufferView::CHANGE);
1528 case LFUN_TOC_INSERT:
1530 InsetCommandParams p;
1531 p.setCmdName("tableofcontents");
1532 Inset * inset = new InsetTOC(p);
1533 if (!insertInset(inset, "Standard"))
1538 case LFUN_TABULAR_FEATURE:
1539 case LFUN_SCROLL_INSET:
1540 // this is not handled here as this funktion is only aktive
1541 // if we have a locking_inset and that one is (or contains)
1545 case LFUN_INSET_GRAPHICS:
1547 Inset * new_inset = new InsetGraphics;
1548 if (!insertInset(new_inset)) {
1551 // this is need because you don't use a inset->Edit()
1552 updateInset(new_inset, true);
1553 new_inset->edit(bv_);
1563 case LFUN_PASTESELECTION:
1565 bool asPara = false;
1566 if (argument == "paragraph")
1568 pasteClipboard(asPara);
1580 case LFUN_LAYOUT_COPY:
1581 bv_->copyEnvironment();
1584 case LFUN_LAYOUT_PASTE:
1585 bv_->pasteEnvironment();
1589 case LFUN_GOTOERROR:
1590 gotoInset(Inset::ERROR_CODE, false);
1594 gotoInset(Inset::IGNORE_CODE, false);
1597 case LFUN_REFERENCE_GOTO:
1599 vector<Inset::Code> tmp;
1600 tmp.push_back(Inset::LABEL_CODE);
1601 tmp.push_back(Inset::REF_CODE);
1602 gotoInset(tmp, true);
1606 case LFUN_HYPHENATION:
1607 specialChar(InsetSpecialChar::HYPHENATION);
1610 case LFUN_LIGATURE_BREAK:
1611 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1615 specialChar(InsetSpecialChar::LDOTS);
1618 case LFUN_END_OF_SENTENCE:
1619 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1622 case LFUN_MENU_SEPARATOR:
1623 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1631 changeDepth(bv_, bv_->getLyXText(), 0);
1634 case LFUN_DEPTH_MIN:
1635 changeDepth(bv_, bv_->getLyXText(), -1);
1638 case LFUN_DEPTH_PLUS:
1639 changeDepth(bv_, bv_->getLyXText(), 1);
1643 owner_->getDialogs()->setUserFreeFont();
1646 case LFUN_FILE_INSERT:
1647 MenuInsertLyXFile(argument);
1650 case LFUN_FILE_INSERT_ASCII_PARA:
1651 InsertAsciiFile(bv_, argument, true);
1654 case LFUN_FILE_INSERT_ASCII:
1655 InsertAsciiFile(bv_, argument, false);
1660 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1661 << argument << endl;
1663 // Derive layout number from given argument (string)
1664 // and current buffer's textclass (number). */
1665 textclass_type tclass = buffer_->params.textclass;
1666 pair <bool, layout_type> layout =
1667 textclasslist.NumberOfLayout(tclass, argument);
1669 // If the entry is obsolete, use the new one instead.
1671 string obs = textclasslist.Style(tclass, layout.second)
1674 layout = textclasslist.NumberOfLayout(tclass, obs);
1677 // see if we found the layout number:
1678 if (!layout.first) {
1679 owner_->getLyXFunc()->setErrorMessage(
1680 string(N_("Layout ")) + argument +
1685 if (current_layout != layout.second) {
1686 LyXText * lt = bv_->getLyXText();
1688 current_layout = layout.second;
1691 | BufferView::FITCUR);
1692 lt->setLayout(bv_, layout.second);
1693 owner_->setLayout(layout.second);
1696 | BufferView::FITCUR
1697 | BufferView::CHANGE);
1704 lang(bv_, argument);
1706 owner_->showState();
1711 owner_->showState();
1716 owner_->showState();
1721 owner_->showState();
1726 owner_->showState();
1731 owner_->showState();
1736 owner_->showState();
1741 owner_->showState();
1744 case LFUN_UNDERLINE:
1746 owner_->showState();
1749 case LFUN_FONT_SIZE:
1750 fontSize(bv_, argument);
1751 owner_->showState();
1754 case LFUN_FONT_STATE:
1755 owner_->getLyXFunc()->setMessage(currentState(bv_));
1758 case LFUN_UPCASE_WORD:
1760 LyXText * lt = bv_->getLyXText();
1764 | BufferView::FITCUR);
1765 lt->changeCase(bv_, LyXText::text_uppercase);
1766 if (lt->inset_owner)
1767 updateInset(lt->inset_owner, true);
1770 | BufferView::FITCUR
1771 | BufferView::CHANGE);
1775 case LFUN_LOWCASE_WORD:
1777 LyXText * lt = bv_->getLyXText();
1779 update(lt, BufferView::SELECT|BufferView::FITCUR);
1780 lt->changeCase(bv_, LyXText::text_lowercase);
1781 if (lt->inset_owner)
1782 updateInset(lt->inset_owner, true);
1785 | BufferView::FITCUR
1786 | BufferView::CHANGE);
1790 case LFUN_CAPITALIZE_WORD:
1792 LyXText * lt = bv_->getLyXText();
1794 update(lt, BufferView::SELECT|BufferView::FITCUR);
1795 lt->changeCase(bv_, LyXText::text_capitalization);
1796 if (lt->inset_owner)
1797 updateInset(lt->inset_owner, true);
1800 | BufferView::FITCUR
1801 | BufferView::CHANGE);
1805 case LFUN_TRANSPOSE_CHARS:
1807 LyXText * lt = bv_->getLyXText();
1809 update(lt, BufferView::SELECT|BufferView::FITCUR);
1810 lt->transposeChars(*bv_);
1811 if (lt->inset_owner)
1812 updateInset(lt->inset_owner, true);
1815 | BufferView::FITCUR
1816 | BufferView::CHANGE);
1821 case LFUN_INSERT_LABEL:
1822 MenuInsertLabel(bv_, argument);
1825 case LFUN_REF_INSERT:
1826 if (argument.empty()) {
1827 InsetCommandParams p("ref");
1828 owner_->getDialogs()->createRef(p.getAsString());
1830 InsetCommandParams p;
1831 p.setFromString(argument);
1833 InsetRef * inset = new InsetRef(p, *buffer_);
1834 if (!insertInset(inset))
1837 updateInset(inset, true);
1841 case LFUN_BOOKMARK_SAVE:
1842 savePosition(strToUnsignedInt(argument));
1845 case LFUN_BOOKMARK_GOTO:
1846 restorePosition(strToUnsignedInt(argument));
1851 string label(argument);
1852 if (label.empty()) {
1854 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1856 label = inset->getContents();
1861 if (!label.empty()) {
1862 //bv_->savePosition(0);
1863 if (!bv_->gotoLabel(label))
1864 Alert::alert(_("Error"),
1865 _("Couldn't find this label"),
1866 _("in current document."));
1871 // --- Cursor Movements -----------------------------
1874 LyXText * lt = bv_->getLyXText();
1876 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1877 if (!lt->selection.mark())
1879 update(lt, BufferView::SELECT|BufferView::FITCUR);
1881 lt->cursorLeft(bv_, false);
1882 if (lt->cursor.pos() < lt->cursor.par()->size()
1883 && lt->cursor.par()->isInset(lt->cursor.pos())
1884 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1885 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1886 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1888 tmpinset->edit(bv_, false);
1890 tmpinset->edit(bv_);
1894 lt->cursorRight(bv_, false);
1896 moveCursorUpdate(false);
1897 owner_->showState();
1903 // This is soooo ugly. Isn`t it possible to make
1904 // it simpler? (Lgb)
1905 LyXText * lt = bv_->getLyXText();
1906 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1907 if (!lt->selection.mark())
1909 update(lt, BufferView::SELECT|BufferView::FITCUR);
1910 LyXCursor const cur = lt->cursor;
1912 lt->cursorLeft(bv_, false);
1913 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1914 lt->cursor.pos() < lt->cursor.par()->size() &&
1915 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1916 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1917 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1918 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1920 tmpinset->edit(bv_);
1922 tmpinset->edit(bv_, false);
1926 lt->cursorRight(bv_, false);
1929 moveCursorUpdate(false);
1930 owner_->showState();
1936 LyXText * lt = bv_->getLyXText();
1938 if (!lt->selection.mark())
1940 update(lt, BufferView::UPDATE);
1943 moveCursorUpdate(false);
1944 owner_->showState();
1950 LyXText * lt = bv_->getLyXText();
1952 if (!lt->selection.mark())
1954 update(lt, BufferView::UPDATE);
1955 lt->cursorDown(bv_);
1957 moveCursorUpdate(false);
1958 owner_->showState();
1962 case LFUN_UP_PARAGRAPH:
1964 LyXText * lt = bv_->getLyXText();
1966 if (!lt->selection.mark())
1968 update(lt, BufferView::UPDATE);
1969 lt->cursorUpParagraph(bv_);
1971 moveCursorUpdate(false);
1972 owner_->showState();
1976 case LFUN_DOWN_PARAGRAPH:
1978 LyXText * lt = bv_->getLyXText();
1980 if (!lt->selection.mark())
1982 update(lt, BufferView::UPDATE);
1983 lt->cursorDownParagraph(bv_);
1985 moveCursorUpdate(false);
1986 owner_->showState();
1992 LyXText * lt = bv_->getLyXText();
1994 if (!lt->selection.mark())
1996 update(lt, BufferView::UPDATE);
1999 moveCursorUpdate(false);
2000 owner_->showState();
2006 LyXText * lt = bv_->getLyXText();
2008 if (!lt->selection.mark())
2010 update(lt, BufferView::UPDATE);
2013 moveCursorUpdate(false);
2014 owner_->showState();
2020 LyXText * lt = bv_->getLyXText();
2022 if (!lt->selection.mark())
2024 update(lt, BufferView::SELECT|BufferView::FITCUR);
2025 lt->cursorHome(bv_);
2027 moveCursorUpdate(false);
2028 owner_->showState();
2034 LyXText * lt = bv_->getLyXText();
2036 if (!lt->selection.mark())
2039 BufferView::SELECT|BufferView::FITCUR);
2042 moveCursorUpdate(false);
2043 owner_->showState();
2047 case LFUN_SHIFT_TAB:
2050 LyXText * lt = bv_->getLyXText();
2052 if (!lt->selection.mark())
2055 BufferView::SELECT|BufferView::FITCUR);
2058 moveCursorUpdate(false);
2059 owner_->showState();
2063 case LFUN_WORDRIGHT:
2065 LyXText * lt = bv_->getLyXText();
2067 if (!lt->selection.mark())
2069 update(lt, BufferView::SELECT|BufferView::FITCUR);
2070 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2071 lt->cursorLeftOneWord(bv_);
2073 lt->cursorRightOneWord(bv_);
2075 moveCursorUpdate(false);
2076 owner_->showState();
2082 LyXText * lt = bv_->getLyXText();
2084 if (!lt->selection.mark())
2086 update(lt, BufferView::SELECT|BufferView::FITCUR);
2087 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2088 lt->cursorRightOneWord(bv_);
2090 lt->cursorLeftOneWord(bv_);
2092 moveCursorUpdate(false);
2093 owner_->showState();
2097 case LFUN_BEGINNINGBUF:
2099 LyXText * lt = bv_->getLyXText();
2101 if (!lt->selection.mark())
2104 BufferView::SELECT|BufferView::FITCUR);
2107 moveCursorUpdate(false);
2108 owner_->showState();
2114 LyXText * lt = bv_->getLyXText();
2116 if (!lt->selection.mark())
2119 BufferView::SELECT|BufferView::FITCUR);
2120 lt->cursorBottom(bv_);
2122 moveCursorUpdate(false);
2123 owner_->showState();
2127 /* cursor selection ---------------------------- */
2130 LyXText * lt = bv_->getLyXText();
2133 BufferView::SELECT|BufferView::FITCUR);
2134 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2135 lt->cursorLeft(bv_);
2137 lt->cursorRight(bv_);
2139 moveCursorUpdate(true);
2140 owner_->showState();
2146 LyXText * lt = bv_->getLyXText();
2149 BufferView::SELECT|BufferView::FITCUR);
2150 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2151 lt->cursorRight(bv_);
2153 lt->cursorLeft(bv_);
2155 moveCursorUpdate(true);
2156 owner_->showState();
2162 LyXText * lt = bv_->getLyXText();
2165 BufferView::SELECT|BufferView::FITCUR);
2168 moveCursorUpdate(true);
2169 owner_->showState();
2175 LyXText * lt = bv_->getLyXText();
2178 BufferView::SELECT|BufferView::FITCUR);
2179 lt->cursorDown(bv_);
2181 moveCursorUpdate(true);
2182 owner_->showState();
2186 case LFUN_UP_PARAGRAPHSEL:
2188 LyXText * lt = bv_->getLyXText();
2191 BufferView::SELECT|BufferView::FITCUR);
2192 lt->cursorUpParagraph(bv_);
2194 moveCursorUpdate(true);
2195 owner_->showState();
2199 case LFUN_DOWN_PARAGRAPHSEL:
2201 LyXText * lt = bv_->getLyXText();
2204 BufferView::SELECT|BufferView::FITCUR);
2205 lt->cursorDownParagraph(bv_);
2207 moveCursorUpdate(true);
2208 owner_->showState();
2214 LyXText * lt = bv_->getLyXText();
2216 update(lt, BufferView::SELECT|BufferView::FITCUR);
2219 moveCursorUpdate(true);
2220 owner_->showState();
2226 LyXText * lt = bv_->getLyXText();
2228 update(lt, BufferView::SELECT|BufferView::FITCUR);
2231 moveCursorUpdate(true);
2232 owner_->showState();
2238 LyXText * lt = bv_->getLyXText();
2240 update(lt, BufferView::SELECT|BufferView::FITCUR);
2241 lt->cursorHome(bv_);
2243 moveCursorUpdate(true);
2244 owner_->showState();
2250 LyXText * lt = bv_->getLyXText();
2252 update(lt, BufferView::SELECT|BufferView::FITCUR);
2255 moveCursorUpdate(true);
2256 owner_->showState();
2260 case LFUN_WORDRIGHTSEL:
2262 LyXText * lt = bv_->getLyXText();
2264 update(lt, BufferView::SELECT|BufferView::FITCUR);
2265 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2266 lt->cursorLeftOneWord(bv_);
2268 lt->cursorRightOneWord(bv_);
2270 moveCursorUpdate(true);
2271 owner_->showState();
2275 case LFUN_WORDLEFTSEL:
2277 LyXText * lt = bv_->getLyXText();
2279 update(lt, BufferView::SELECT|BufferView::FITCUR);
2280 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2281 lt->cursorRightOneWord(bv_);
2283 lt->cursorLeftOneWord(bv_);
2285 moveCursorUpdate(true);
2286 owner_->showState();
2290 case LFUN_BEGINNINGBUFSEL:
2292 LyXText * lt = bv_->getLyXText();
2294 if (lt->inset_owner)
2296 update(lt, BufferView::SELECT|BufferView::FITCUR);
2299 moveCursorUpdate(true);
2300 owner_->showState();
2304 case LFUN_ENDBUFSEL:
2306 LyXText * lt = bv_->getLyXText();
2308 if (lt->inset_owner)
2311 BufferView::SELECT|BufferView::FITCUR);
2312 lt->cursorBottom(bv_);
2314 moveCursorUpdate(true);
2315 owner_->showState();
2319 // --- text changing commands ------------------------
2320 case LFUN_BREAKLINE:
2322 LyXText * lt = bv_->getLyXText();
2325 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2328 | BufferView::FITCUR
2329 | BufferView::CHANGE);
2330 moveCursorUpdate(false);
2334 case LFUN_PROTECTEDSPACE:
2336 LyXText * lt = bv_->getLyXText();
2338 LyXLayout const & style = textclasslist
2339 .Style(buffer_->params.textclass,
2340 lt->cursor.par()->getLayout());
2342 if (style.free_spacing) {
2343 lt->insertChar(bv_, ' ');
2346 | BufferView::FITCUR
2347 | BufferView::CHANGE);
2351 moveCursorUpdate(false);
2357 LyXText * lt = bv_->getLyXText();
2359 if (lt->selection.mark()) {
2363 | BufferView::FITCUR);
2364 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2367 lt->selection.mark(true);
2370 | BufferView::FITCUR);
2371 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2373 lt->selection.cursor = lt->cursor;
2379 LyXText * lt = bv_->getLyXText();
2381 if (!lt->selection.set()) {
2383 lt->selection.cursor = lt->cursor;
2386 | BufferView::FITCUR
2387 | BufferView::CHANGE);
2388 // It is possible to make it a lot faster still
2389 // just comment out the line below...
2394 moveCursorUpdate(false);
2395 owner_->showState();
2400 case LFUN_DELETE_SKIP:
2402 LyXText * lt = bv_->getLyXText();
2404 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2406 LyXCursor cursor = lt->cursor;
2408 if (!lt->selection.set()) {
2409 if (cursor.pos() == cursor.par()->size()) {
2410 lt->cursorRight(bv_);
2411 cursor = lt->cursor;
2412 if (cursor.pos() == 0
2413 && !(cursor.par()->params().spaceTop()
2414 == VSpace (VSpace::NONE))) {
2417 cursor.par()->params().lineTop(),
2418 cursor.par()->params().lineBottom(),
2419 cursor.par()->params().pagebreakTop(),
2420 cursor.par()->params().pagebreakBottom(),
2421 VSpace(VSpace::NONE),
2422 cursor.par()->params().spaceBottom(),
2423 cursor.par()->params().spacing(),
2424 cursor.par()->params().align(),
2425 cursor.par()->params().labelWidthString(), 0);
2426 lt->cursorLeft(bv_);
2429 | BufferView::FITCUR
2430 | BufferView::CHANGE);
2432 lt->cursorLeft(bv_);
2434 lt->selection.cursor = lt->cursor;
2437 | BufferView::FITCUR
2438 | BufferView::CHANGE);
2442 lt->selection.cursor = lt->cursor;
2445 | BufferView::FITCUR
2446 | BufferView::CHANGE);
2454 /* -------> Delete word forward. */
2455 case LFUN_DELETE_WORD_FORWARD:
2456 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2457 bv_->getLyXText()->deleteWordForward(bv_);
2458 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2459 moveCursorUpdate(false);
2460 owner_->showState();
2463 /* -------> Delete word backward. */
2464 case LFUN_DELETE_WORD_BACKWARD:
2466 LyXText * lt = bv_->getLyXText();
2468 update(lt, BufferView::SELECT|BufferView::FITCUR);
2469 lt->deleteWordBackward(bv_);
2472 | BufferView::FITCUR
2473 | BufferView::CHANGE);
2474 moveCursorUpdate(false);
2475 owner_->showState();
2479 /* -------> Kill to end of line. */
2480 case LFUN_DELETE_LINE_FORWARD:
2482 LyXText * lt = bv_->getLyXText();
2484 update(lt, BufferView::SELECT|BufferView::FITCUR);
2485 lt->deleteLineForward(bv_);
2488 | BufferView::FITCUR
2489 | BufferView::CHANGE);
2490 moveCursorUpdate(false);
2494 /* -------> Set mark off. */
2497 LyXText * lt = bv_->getLyXText();
2500 update(lt, BufferView::SELECT|BufferView::FITCUR);
2501 lt->selection.cursor = lt->cursor;
2502 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2506 /* -------> Set mark on. */
2509 LyXText * lt = bv_->getLyXText();
2512 lt->selection.mark(true);
2513 update(lt, BufferView::SELECT|BufferView::FITCUR);
2514 lt->selection.cursor = lt->cursor;
2515 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2519 case LFUN_BACKSPACE:
2521 LyXText * lt = bv_->getLyXText();
2523 if (!lt->selection.set()) {
2524 if (owner_->getIntl()->getTrans().backspace()) {
2526 lt->selection.cursor = lt->cursor;
2529 | BufferView::FITCUR
2530 | BufferView::CHANGE);
2531 // It is possible to make it a lot faster still
2532 // just comment out the line below...
2538 owner_->showState();
2543 case LFUN_BACKSPACE_SKIP:
2545 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2546 LyXText * lt = bv_->getLyXText();
2548 LyXCursor cursor = lt->cursor;
2550 if (!lt->selection.set()) {
2551 if (cursor.pos() == 0
2552 && !(cursor.par()->params().spaceTop()
2553 == VSpace (VSpace::NONE))) {
2556 cursor.par()->params().lineTop(),
2557 cursor.par()->params().lineBottom(),
2558 cursor.par()->params().pagebreakTop(),
2559 cursor.par()->params().pagebreakBottom(),
2560 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2561 cursor.par()->params().spacing(),
2562 cursor.par()->params().align(),
2563 cursor.par()->params().labelWidthString(), 0);
2566 | BufferView::FITCUR
2567 | BufferView::CHANGE);
2570 lt->selection.cursor = cursor;
2573 | BufferView::FITCUR
2574 | BufferView::CHANGE);
2581 case LFUN_BREAKPARAGRAPH:
2583 LyXText * lt = bv_->getLyXText();
2586 lt->breakParagraph(bv_, 0);
2589 | BufferView::FITCUR
2590 | BufferView::CHANGE);
2591 lt->selection.cursor = lt->cursor;
2593 owner_->showState();
2597 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2599 LyXText * lt = bv_->getLyXText();
2602 lt->breakParagraph(bv_, 1);
2605 | BufferView::FITCUR
2606 | BufferView::CHANGE);
2607 lt->selection.cursor = lt->cursor;
2609 owner_->showState();
2613 case LFUN_BREAKPARAGRAPH_SKIP:
2615 // When at the beginning of a paragraph, remove
2616 // indentation and add a "defskip" at the top.
2617 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2618 LyXText * lt = bv_->getLyXText();
2620 LyXCursor cursor = lt->cursor;
2623 if (cursor.pos() == 0) {
2624 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2627 cursor.par()->params().lineTop(),
2628 cursor.par()->params().lineBottom(),
2629 cursor.par()->params().pagebreakTop(),
2630 cursor.par()->params().pagebreakBottom(),
2631 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2632 cursor.par()->params().spacing(),
2633 cursor.par()->params().align(),
2634 cursor.par()->params().labelWidthString(), 1);
2635 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2639 lt->breakParagraph(bv_, 0);
2640 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2645 | BufferView::FITCUR
2646 | BufferView::CHANGE);
2647 lt->selection.cursor = cursor;
2649 owner_->showState();
2653 case LFUN_PARAGRAPH_SPACING:
2655 LyXText * lt = bv_->getLyXText();
2657 Paragraph * par = lt->cursor.par();
2658 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2659 float cur_value = 1.0;
2660 if (cur_spacing == Spacing::Other) {
2661 cur_value = par->params().spacing().getValue();
2664 istringstream istr(argument.c_str());
2668 Spacing::Space new_spacing = cur_spacing;
2669 float new_value = cur_value;
2671 lyxerr << "Missing argument to `paragraph-spacing'"
2673 } else if (tmp == "single") {
2674 new_spacing = Spacing::Single;
2675 } else if (tmp == "onehalf") {
2676 new_spacing = Spacing::Onehalf;
2677 } else if (tmp == "double") {
2678 new_spacing = Spacing::Double;
2679 } else if (tmp == "other") {
2680 new_spacing = Spacing::Other;
2683 lyxerr << "new_value = " << tmpval << endl;
2686 } else if (tmp == "default") {
2687 new_spacing = Spacing::Default;
2689 lyxerr << _("Unknown spacing argument: ")
2690 << argument << endl;
2692 if (cur_spacing != new_spacing || cur_value != new_value) {
2693 par->params().spacing(Spacing(new_spacing, new_value));
2694 lt->redoParagraph(bv_);
2697 | BufferView::FITCUR
2698 | BufferView::CHANGE);
2703 case LFUN_INSET_TOGGLE:
2705 LyXText * lt = bv_->getLyXText();
2708 update(lt, BufferView::SELECT|BufferView::FITCUR);
2709 lt->toggleInset(bv_);
2710 update(lt, BufferView::SELECT|BufferView::FITCUR);
2722 InsetCommandParams p;
2723 if (action == LFUN_HTMLURL)
2724 p.setCmdName("htmlurl");
2726 p.setCmdName("url");
2727 owner_->getDialogs()->createUrl(p.getAsString());
2731 case LFUN_INSERT_URL:
2733 InsetCommandParams p;
2734 p.setFromString(argument);
2736 InsetUrl * inset = new InsetUrl(p);
2737 if (!insertInset(inset))
2740 updateInset(inset, true);
2744 case LFUN_INSET_TEXT:
2745 insertAndEditInset(new InsetText);
2748 case LFUN_INSET_ERT:
2749 insertAndEditInset(new InsetERT);
2752 case LFUN_INSET_EXTERNAL:
2753 insertAndEditInset(new InsetExternal);
2756 case LFUN_INSET_FOOTNOTE:
2757 insertAndEditInset(new InsetFoot);
2760 case LFUN_INSET_MARGINAL:
2761 insertAndEditInset(new InsetMarginal);
2764 case LFUN_INSET_MINIPAGE:
2765 insertAndEditInset(new InsetMinipage);
2768 case LFUN_INSERT_NOTE:
2769 insertAndEditInset(new InsetNote);
2772 case LFUN_INSET_FLOAT:
2773 // check if the float type exist
2774 if (floatList.typeExist(argument)) {
2775 insertAndEditInset(new InsetFloat(argument));
2777 lyxerr << "Non-existent float type: "
2778 << argument << endl;
2782 case LFUN_INSET_WIDE_FLOAT:
2784 // check if the float type exist
2785 if (floatList.typeExist(argument)) {
2786 InsetFloat * new_inset = new InsetFloat(argument);
2787 new_inset->wide(true);
2788 if (insertInset(new_inset))
2789 new_inset->edit(bv_);
2793 lyxerr << "Non-existent float type: "
2794 << argument << endl;
2801 case LFUN_INSET_LIST:
2802 insertAndEditInset(new InsetList);
2805 case LFUN_INSET_THEOREM:
2806 insertAndEditInset(new InsetTheorem);
2810 case LFUN_INSET_CAPTION:
2812 // Do we have a locking inset...
2813 if (bv_->theLockingInset()) {
2814 lyxerr << "Locking inset code: "
2815 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2816 InsetCaption * new_inset = new InsetCaption;
2817 new_inset->setOwner(bv_->theLockingInset());
2818 new_inset->setAutoBreakRows(true);
2819 new_inset->setDrawFrame(0, InsetText::LOCKED);
2820 new_inset->setFrameColor(0, LColor::captionframe);
2821 if (insertInset(new_inset))
2822 new_inset->edit(bv_);
2829 case LFUN_INSET_TABULAR:
2833 if (!argument.empty())
2834 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2835 InsetTabular * new_inset =
2836 new InsetTabular(*buffer_, r, c);
2838 bv_->getLyXText()->real_current_font.isRightToLeft();
2839 if (!open_new_inset(new_inset, rtl))
2844 // --- lyxserver commands ----------------------------
2846 case LFUN_CHARATCURSOR:
2848 pos_type pos = bv_->getLyXText()->cursor.pos();
2849 if (pos < bv_->getLyXText()->cursor.par()->size())
2850 owner_->getLyXFunc()->setMessage(
2851 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2853 owner_->getLyXFunc()->setMessage("EOF");
2858 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2860 + tostr(bv_->getLyXText()->cursor.y()));
2867 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2868 lyxerr << "SETXY: Could not parse coordinates in '"
2869 << argument << std::endl;
2871 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2875 case LFUN_GETLAYOUT:
2876 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2881 LyXFont & font = bv_->getLyXText()->current_font;
2882 if (font.shape() == LyXFont::ITALIC_SHAPE)
2883 owner_->getLyXFunc()->setMessage("E");
2884 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2885 owner_->getLyXFunc()->setMessage("N");
2887 owner_->getLyXFunc()->setMessage("0");
2892 // --- accented characters ---------------------------
2895 case LFUN_CIRCUMFLEX:
2905 case LFUN_SPECIAL_CARON:
2908 case LFUN_HUNG_UMLAUT:
2911 if (argument.empty()) {
2913 owner_->getLyXFunc()->handleKeyFunc(action);
2915 owner_->getLyXFunc()->handleKeyFunc(action);
2916 owner_->getIntl()->getTrans()
2917 .TranslateAndInsert(argument[0], bv_->getLyXText());
2918 update(bv_->getLyXText(),
2920 | BufferView::FITCUR
2921 | BufferView::CHANGE);
2925 case LFUN_MATH_MACRO:
2926 mathDispatchMathMacro(bv_, argument);
2929 case LFUN_MATH_DELIM:
2930 mathDispatchMathDelim(bv_, argument);
2933 case LFUN_INSERT_MATRIX:
2934 mathDispatchInsertMatrix(bv_, argument);
2937 case LFUN_INSERT_MATH:
2938 mathDispatchInsertMath(bv_, argument);
2941 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2942 mathDispatchMathImportSelection(bv_, argument);
2945 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2946 mathDispatchMathDisplay(bv_, argument);
2949 case LFUN_MATH_MODE: // Open or create an inlined math inset
2950 mathDispatchMathMode(bv_, argument);
2953 case LFUN_GREEK: // Insert a single greek letter
2954 mathDispatchGreek(bv_, argument);
2957 case LFUN_CITATION_INSERT:
2959 InsetCommandParams p;
2960 p.setFromString( argument );
2962 InsetCitation * inset = new InsetCitation( p );
2963 if (!insertInset(inset))
2966 updateInset( inset, true );
2970 case LFUN_INSERT_BIBTEX:
2972 // ale970405+lasgoutt970425
2973 // The argument can be up to two tokens separated
2974 // by a space. The first one is the bibstyle.
2975 string const db = token(argument, ' ', 0);
2976 string const bibstyle = token(argument, ' ', 1);
2978 InsetCommandParams p( "BibTeX", db, bibstyle );
2979 InsetBibtex * inset = new InsetBibtex(p);
2981 if (insertInset(inset)) {
2982 if (argument.empty())
2989 // BibTeX data bases
2990 case LFUN_BIBDB_ADD:
2992 InsetBibtex * inset =
2993 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2995 inset->addDatabase(argument);
3000 case LFUN_BIBDB_DEL:
3002 InsetBibtex * inset =
3003 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3005 inset->delDatabase(argument);
3010 case LFUN_BIBTEX_STYLE:
3012 InsetBibtex * inset =
3013 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3015 inset->setOptions(argument);
3020 case LFUN_INDEX_CREATE:
3022 InsetCommandParams p("index");
3023 if (argument.empty()) {
3024 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3025 p.setContents(idxstring);
3027 p.setContents(argument);
3030 owner_->getDialogs()->createIndex(p.getAsString());
3034 case LFUN_INDEX_INSERT:
3036 InsetCommandParams p;
3037 p.setFromString(argument);
3038 InsetIndex * inset = new InsetIndex(p);
3040 if (!insertInset(inset))
3043 updateInset(inset, true);
3047 case LFUN_INDEX_INSERT_LAST:
3049 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3050 if (!idxstring.empty()) {
3051 owner_->message(_("Word `")
3052 + idxstring + _(("' indexed.")));
3053 InsetCommandParams p("index", idxstring);
3054 InsetIndex * inset = new InsetIndex(p);
3056 if (!insertInset(inset))
3059 updateInset(inset, true);
3064 case LFUN_INDEX_PRINT:
3066 InsetCommandParams p("printindex");
3067 Inset * inset = new InsetPrintIndex(p);
3068 if (!insertInset(inset, "Standard"))
3073 case LFUN_PARENTINSERT:
3075 lyxerr << "arg " << argument << endl;
3076 InsetCommandParams p( "lyxparent", argument );
3077 Inset * inset = new InsetParent(p, *buffer_);
3078 if (!insertInset(inset, "Standard"))
3084 case LFUN_CHILD_INSERT:
3086 InsetInclude::Params p;
3087 p.cparams.setFromString(argument);
3088 p.masterFilename_ = buffer_->fileName();
3090 InsetInclude * inset = new InsetInclude(p);
3091 if (!insertInset(inset))
3094 updateInset(inset, true);
3095 bv_->owner()->getDialogs()->showInclude(inset);
3100 case LFUN_FLOAT_LIST:
3102 // We should check the argument for validity. (Lgb)
3103 Inset * inset = new InsetFloatList(argument);
3104 if (!insertInset(inset, "Standard"))
3109 case LFUN_THESAURUS_ENTRY:
3111 string arg = argument;
3114 arg = bv_->getLyXText()->selectionAsString(buffer_,
3118 if (arg.size() > 100 || arg.empty()) {
3119 // Get word or selection
3120 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3121 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3122 // FIXME: where is getLyXText()->unselect(bv_) ?
3126 bv_->owner()->getDialogs()->showThesaurus(arg);
3130 case LFUN_SELFINSERT:
3132 if (argument.empty()) break;
3134 /* Automatically delete the currently selected
3135 * text and replace it with what is being
3136 * typed in now. Depends on lyxrc settings
3137 * "auto_region_delete", which defaults to
3140 LyXText * lt = bv_->getLyXText();
3142 if (lyxrc.auto_region_delete) {
3143 if (lt->selection.set()) {
3144 lt->cutSelection(bv_, false, false);
3147 | BufferView::FITCUR
3148 | BufferView::CHANGE);
3153 LyXFont const old_font(lt->real_current_font);
3155 string::const_iterator cit = argument.begin();
3156 string::const_iterator end = argument.end();
3157 for (; cit != end; ++cit) {
3158 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3163 | BufferView::FITCUR
3164 | BufferView::CHANGE);
3166 lt->selection.cursor = lt->cursor;
3167 moveCursorUpdate(false);
3169 // real_current_font.number can change so we need to
3170 // update the minibuffer
3171 if (old_font != lt->real_current_font)
3172 owner_->showState();
3177 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3179 time_t now_time_t = time(NULL);
3180 struct tm * now_tm = localtime(&now_time_t);
3181 setlocale(LC_TIME, "");
3183 if (!argument.empty())
3186 arg = lyxrc.date_insert_format;
3188 int const datetmp_len =
3189 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3191 LyXText * lt = bv_->getLyXText();
3193 for (int i = 0; i < datetmp_len; i++) {
3194 lt->insertChar(bv_, datetmp[i]);
3197 | BufferView::FITCUR
3198 | BufferView::CHANGE);
3201 lt->selection.cursor = lt->cursor;
3202 moveCursorUpdate(false);
3206 case LFUN_UNKNOWN_ACTION:
3207 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3218 void BufferView::Pimpl::newline()
3221 LyXText * lt = bv_->getLyXText();
3225 | BufferView::FITCUR);
3226 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3229 | BufferView::FITCUR
3230 | BufferView::CHANGE);
3235 void BufferView::Pimpl::hfill()
3238 LyXText * lt = bv_->getLyXText();
3242 | BufferView::FITCUR);
3243 lt->insertChar(bv_, Paragraph::META_HFILL);
3246 | BufferView::FITCUR
3247 | BufferView::CHANGE);
3252 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3256 update(lt, BufferView::SELECT|BufferView::FITCUR);
3257 InsetSpecialChar * new_inset =
3258 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3259 #ifdef WITH_WARNINGS
3260 #warning Why is this code different from specialChar() below? (JMarc)
3261 // the code in specialChar is a generic version of what used to exist
3262 // for other special chars. I did not merge this case because of the
3263 // call to updateInset(), but what does it do?
3265 if (!insertInset(new_inset))
3268 updateInset(new_inset, true);
3273 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3276 LyXText * lt = bv_->getLyXText();
3279 update(lt, BufferView::SELECT|BufferView::FITCUR);
3280 InsetSpecialChar * new_inset =
3281 new InsetSpecialChar(kind);
3282 insertInset(new_inset);
3283 // Ok, what happens here if we are unable to insert
3284 // the inset? Leak it?
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 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_,
3416 bv_->theLockingInset())) {
3419 buffer_->markDirty();
3427 // then check the current buffer
3430 update(bv_->text, BufferView::UPDATE);
3431 if (bv_->text->updateInset(bv_, inset)) {
3435 | BufferView::FITCUR
3436 | BufferView::CHANGE);
3438 update(bv_->text, SELECT);
3446 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3449 if (!available()) return;
3452 beforeChange(bv_->text);
3453 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3455 LyXCursor const & cursor = bv_->text->cursor;
3459 cursor.par()->isInset(cursor.pos())) {
3460 Inset const * inset = cursor.par()->getInset(cursor.pos());
3461 if (find(codes.begin(), codes.end(), inset->lyxCode())
3464 static_cast<InsetCommand const *>(inset)->getContents();
3468 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3469 if (bv_->text->cursor.pos()
3470 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3471 LyXCursor tmp = bv_->text->cursor;
3472 bv_->text->cursor.par(bv_->text->firstParagraph());
3473 bv_->text->cursor.pos(0);
3474 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3475 bv_->text->cursor = tmp;
3476 bv_->owner()->message(_("No more insets"));
3479 bv_->owner()->message(_("No more insets"));
3482 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3483 bv_->text->selection.cursor = bv_->text->cursor;
3487 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3489 gotoInset(vector<Inset::Code>(1, code), same_content);