12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
17 #include "paragraph.h"
19 #include "commandtags.h"
23 #include "bufferview_funcs.h"
24 #include "TextCache.h"
25 #include "bufferlist.h"
26 #include "lyx_gui_misc.h"
29 #include "support/LAssert.h"
30 #include "support/lstrings.h"
31 #include "frontends/Dialogs.h"
32 #include "frontends/Alert.h"
33 #include "insets/insetbib.h"
34 #include "insets/insettext.h"
35 /// added for Dispatch functions
37 #include "frontends/FileDialog.h"
39 #include "FloatList.h"
40 #include "support/filetools.h"
41 #include "support/lyxfunctional.h"
42 #include "insets/inseturl.h"
43 #include "insets/insetlatexaccent.h"
44 #include "insets/insettoc.h"
45 #include "insets/insetref.h"
46 #include "insets/insetparent.h"
47 #include "insets/insetindex.h"
48 #include "insets/insetnote.h"
49 #include "insets/insetinclude.h"
50 #include "insets/insetcite.h"
51 #include "insets/insetert.h"
52 #include "insets/insetexternal.h"
53 #include "insets/insetgraphics.h"
54 #include "insets/insetfoot.h"
55 #include "insets/insetmarginal.h"
56 #include "insets/insetminipage.h"
57 #include "insets/insetfloat.h"
58 #include "insets/insettabular.h"
60 #include "insets/insettheorem.h"
61 #include "insets/insetlist.h"
63 #include "insets/insetcaption.h"
64 #include "insets/insetfloatlist.h"
65 #include "insets/insetspecialchar.h"
67 #include "ParagraphParameters.h"
68 #include "undo_funcs.h"
69 #include "mathed/formulabase.h"
71 extern lyx::layout_type current_layout;
83 using lyx::layout_type;
84 using lyx::textclass_type;
86 /* the selection possible is needed, that only motion events are
87 * used, where the bottom press event was on the drawing area too */
88 bool selection_possible = false;
90 extern BufferList bufferlist;
91 extern char ascii_type;
93 extern void sigchldchecker(pid_t pid, int * status);
94 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
99 const unsigned int saved_positions_num = 20;
104 XSync(fl_get_display(), 0);
108 void SetXtermCursor(Window win)
110 static Cursor cursor;
111 static bool cursor_undefined = true;
112 if (cursor_undefined){
113 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
114 XFlush(fl_get_display());
115 cursor_undefined = false;
117 XDefineCursor(fl_get_display(), win, cursor);
118 XFlush(fl_get_display());
124 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
125 int xpos, int ypos, int width, int height)
126 : bv_(b), owner_(o), buffer_(0),
127 current_scrollbar_value(0), cursor_timeout(400),
128 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
132 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
133 workarea_.workAreaExpose
134 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
135 workarea_.workAreaEnter
136 .connect(slot(this, &BufferView::Pimpl::enterView));
137 workarea_.workAreaLeave
138 .connect(slot(this, &BufferView::Pimpl::leaveView));
139 workarea_.workAreaButtonPress
140 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
141 workarea_.workAreaButtonRelease
143 &BufferView::Pimpl::workAreaButtonRelease));
144 workarea_.workAreaMotionNotify
145 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
146 workarea_.workAreaDoubleClick
147 .connect(slot(this, &BufferView::Pimpl::doubleClick));
148 workarea_.workAreaTripleClick
149 .connect(slot(this, &BufferView::Pimpl::tripleClick));
150 workarea_.workAreaKeyPress
151 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
153 cursor_timeout.timeout.connect(slot(this,
154 &BufferView::Pimpl::cursorToggle));
155 cursor_timeout.start();
156 workarea_.setFocus();
157 saved_positions.resize(saved_positions_num);
161 Painter & BufferView::Pimpl::painter()
163 return workarea_.getPainter();
167 void BufferView::Pimpl::buffer(Buffer * b)
169 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
173 buffer_->delUser(bv_);
175 // Put the old text into the TextCache, but
176 // only if the buffer is still loaded.
177 // Also set the owner of the test to 0
178 // bv_->text->owner(0);
179 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
180 if (lyxerr.debugging())
181 textcache.show(lyxerr, "BufferView::buffer");
186 // Set current buffer
189 if (bufferlist.getState() == BufferList::CLOSING) return;
192 // screen is always deleted when the buffer is changed.
195 // If we are closing the buffer, use the first buffer as current
197 buffer_ = bufferlist.first();
201 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
202 buffer_->addUser(bv_);
203 // If we don't have a text object for this, we make one
204 if (bv_->text == 0) {
205 resizeCurrentBuffer();
210 bv_->text->first = screen_->topCursorVisible(bv_->text);
211 owner_->updateMenubar();
212 owner_->updateToolbar();
213 // Similarly, buffer-dependent dialogs should be updated or
214 // hidden. This should go here because some dialogs (eg ToC)
215 // require bv_->text.
216 owner_->getDialogs()->updateBufferDependent(true);
220 lyxerr[Debug::INFO] << " No Buffer!" << endl;
221 owner_->updateMenubar();
222 owner_->updateToolbar();
223 owner_->getDialogs()->hideBufferDependent();
227 // Also remove all remaining text's from the testcache.
228 // (there should not be any!) (if there is any it is a
230 if (lyxerr.debugging())
231 textcache.show(lyxerr, "buffer delete all");
234 // should update layoutchoice even if we don't have a buffer.
235 owner_->updateLayoutChoice();
237 owner_->updateWindowTitle();
241 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
243 workarea_.resize(xpos, ypos, width, height);
244 update(bv_->text, SELECT);
249 void BufferView::Pimpl::resize()
252 resizeCurrentBuffer();
256 void BufferView::Pimpl::redraw()
258 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
263 bool BufferView::Pimpl::fitCursor()
265 lyx::Assert(screen_.get());
269 if (bv_->theLockingInset()) {
270 bv_->theLockingInset()->fitInsetCursor(bv_);
273 ret = screen_->fitCursor(bv_->text, bv_);
276 bv_->owner()->getDialogs()->updateParagraph();
283 void BufferView::Pimpl::redoCurrentBuffer()
285 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
286 if (buffer_ && bv_->text) {
288 owner_->updateLayoutChoice();
293 int BufferView::Pimpl::resizeCurrentBuffer()
295 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
298 Paragraph * selstartpar = 0;
299 Paragraph * selendpar = 0;
300 UpdatableInset * the_locking_inset = 0;
303 pos_type selstartpos = 0;
304 pos_type selendpos = 0;
305 bool selection = false;
306 bool mark_set = false;
308 owner_->prohibitInput();
310 owner_->message(_("Formatting document..."));
313 par = bv_->text->cursor.par();
314 pos = bv_->text->cursor.pos();
315 selstartpar = bv_->text->selection.start.par();
316 selstartpos = bv_->text->selection.start.pos();
317 selendpar = bv_->text->selection.end.par();
318 selendpos = bv_->text->selection.end.pos();
319 selection = bv_->text->selection.set();
320 mark_set = bv_->text->selection.mark();
321 the_locking_inset = bv_->theLockingInset();
323 bv_->text = new LyXText(bv_);
324 bv_->text->init(bv_);
326 // See if we have a text in TextCache that fits
327 // the new buffer_ with the correct width.
328 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
330 if (lyxerr.debugging()) {
331 lyxerr << "Found a LyXText that fits:\n";
332 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
334 // Set the owner of the newly found text
335 // bv_->text->owner(bv_);
336 if (lyxerr.debugging())
337 textcache.show(lyxerr, "resizeCurrentBuffer");
339 bv_->text = new LyXText(bv_);
340 bv_->text->init(bv_);
346 bv_->text->selection.set(true);
347 /* at this point just to avoid the Delete-Empty-Paragraph
348 * Mechanism when setting the cursor */
349 bv_->text->selection.mark(mark_set);
351 bv_->text->setCursor(bv_, selstartpar, selstartpos);
352 bv_->text->selection.cursor = bv_->text->cursor;
353 bv_->text->setCursor(bv_, selendpar, selendpos);
354 bv_->text->setSelection(bv_);
355 bv_->text->setCursor(bv_, par, pos);
357 bv_->text->setCursor(bv_, par, pos);
358 bv_->text->selection.cursor = bv_->text->cursor;
359 bv_->text->selection.set(false);
361 // remake the inset locking
362 bv_->theLockingInset(the_locking_inset);
364 bv_->text->first = screen_->topCursorVisible(bv_->text);
365 buffer_->resizeInsets(bv_);
366 // this will scroll the screen such that the cursor becomes visible
371 owner_->allowInput();
373 /// clear the "Formatting Document" message
380 void BufferView::Pimpl::updateScreen()
382 // Regenerate the screen.
383 screen_.reset(new LyXScreen(workarea_));
387 void BufferView::Pimpl::updateScrollbar()
389 /* If the text is smaller than the working area, the scrollbar
390 * maximum must be the working area height. No scrolling will
393 workarea_.setScrollbar(0, 1.0);
397 long const text_height = bv_->text->height;
399 double const lineh = bv_->text->defaultHeight();
400 double const slider_size =
401 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
403 static long old_text_height = 0;
404 static double old_lineh = 0;
405 static double old_slider_size = 0;
407 if (text_height != old_text_height) {
408 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
409 old_text_height = text_height;
411 if (lineh != old_lineh) {
412 workarea_.setScrollbarIncrements(lineh);
415 if (current_scrollbar_value != bv_->text->first
416 || slider_size != old_slider_size) {
417 current_scrollbar_value = bv_->text->first;
418 workarea_.setScrollbar(current_scrollbar_value, slider_size);
419 old_slider_size = slider_size;
424 // Callback for scrollbar slider
425 void BufferView::Pimpl::scrollCB(double value)
427 if (!buffer_) return;
429 current_scrollbar_value = long(value);
430 if (current_scrollbar_value < 0)
431 current_scrollbar_value = 0;
436 screen_->draw(bv_->text, bv_, current_scrollbar_value);
438 if (!lyxrc.cursor_follows_scrollbar) {
443 LyXText * vbt = bv_->text;
445 int const height = vbt->defaultHeight();
446 int const first = static_cast<int>((bv_->text->first + height));
447 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
449 if (vbt->cursor.y() < first)
450 vbt->setCursorFromCoordinates(bv_, 0, first);
451 else if (vbt->cursor.y() > last)
452 vbt->setCursorFromCoordinates(bv_, 0, last);
458 int BufferView::Pimpl::scrollUp(long time)
460 if (!buffer_) return 0;
461 if (!screen_.get()) return 0;
463 double value = workarea_.getScrollbarValue();
465 if (value == 0) return 0;
467 float add_value = (bv_->text->defaultHeight()
468 + float(time) * float(time) * 0.125);
470 if (add_value > workarea_.height())
471 add_value = float(workarea_.height() -
472 bv_->text->defaultHeight());
479 workarea_.setScrollbarValue(value);
486 int BufferView::Pimpl::scrollDown(long time)
488 if (!buffer_) return 0;
489 if (!screen_.get()) return 0;
491 double value = workarea_.getScrollbarValue();
492 pair<float, float> p = workarea_.getScrollbarBounds();
493 double const max = p.second;
495 if (value == max) return 0;
497 float add_value = (bv_->text->defaultHeight()
498 + float(time) * float(time) * 0.125);
500 if (add_value > workarea_.height())
501 add_value = float(workarea_.height() -
502 bv_->text->defaultHeight());
509 workarea_.setScrollbarValue(value);
516 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
518 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
522 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
524 // Only use motion with button 1
525 if (!(state & Button1MotionMask))
528 if (!buffer_ || !screen_.get()) return;
530 // Check for inset locking
531 if (bv_->theLockingInset()) {
532 LyXCursor cursor = bv_->text->cursor;
533 LyXFont font = bv_->text->getFont(buffer_,
534 cursor.par(), cursor.pos());
535 int width = bv_->theLockingInset()->width(bv_, font);
536 int inset_x = font.isVisibleRightToLeft()
537 ? cursor.x() - width : cursor.x();
538 int start_x = inset_x + bv_->theLockingInset()->scroll();
539 bv_->theLockingInset()->
540 insetMotionNotify(bv_,
542 y - cursor.y() + bv_->text->first,
547 /* The test for not selection possible is needed, that only motion
548 events are used, where the bottom press event was on
549 the drawing area too */
550 if (!selection_possible)
553 screen_->hideCursor();
555 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
557 if (!bv_->text->selection.set())
558 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
560 bv_->text->setSelection(bv_);
561 screen_->toggleToggle(bv_->text, bv_);
564 screen_->showCursor(bv_->text, bv_);
571 // Single-click on work area
572 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
575 if (!buffer_ || !screen_.get()) return;
577 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
579 // ok ok, this is a hack.
580 if (button == 4 || button == 5) {
583 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
586 scrollDown(lyxrc.wheel_jump);
591 if (bv_->theLockingInset()) {
592 // We are in inset locking mode
594 /* Check whether the inset was hit. If not reset mode,
595 otherwise give the event to the inset */
596 if (inset_hit == bv_->theLockingInset()) {
597 bv_->theLockingInset()->
598 insetButtonPress(bv_,xpos, ypos,button);
601 bv_->unlockInset(bv_->theLockingInset());
606 selection_possible = true;
607 screen_->hideCursor();
609 int const screen_first = bv_->text->first;
611 // Middle button press pastes if we have a selection
612 bool paste_internally = false;
614 && bv_->text->selection.set()) {
615 owner_->getLyXFunc()->dispatch(LFUN_COPY);
616 paste_internally = true;
619 // Clear the selection
620 screen_->toggleSelection(bv_->text, bv_);
621 bv_->text->clearSelection();
622 bv_->text->fullRebreak(bv_);
624 screen_->update(bv_->text, bv_);
630 // Single left click in math inset?
631 if (isHighlyEditableInset(inset_hit)) {
632 // Highly editable inset, like math
633 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
634 selection_possible = false;
635 owner_->updateLayoutChoice();
636 owner_->message(inset->editMessage());
637 inset->insetButtonPress(bv_, xpos, ypos, button);
638 inset->edit(bv_, xpos, ypos, button);
642 // Right click on a footnote flag opens float menu
644 selection_possible = false;
648 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
649 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
651 bv_->text->selection.cursor = bv_->text->cursor;
652 bv_->text->cursor.x_fix(bv_->text->cursor.x());
654 owner_->updateLayoutChoice();
656 selection_possible = false;
659 // Insert primary selection with middle mouse
660 // if there is a local selection in the current buffer,
663 if (paste_internally)
664 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
666 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
668 selection_possible = false;
674 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
680 LyXText * text = bv_->getLyXText();
682 if (text->bv_owner && bv_->theLockingInset())
685 if (screen_.get() && button == 1) {
686 if (text->bv_owner) {
687 screen_->hideCursor();
688 screen_->toggleSelection(text, bv_);
689 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
690 screen_->toggleSelection(text, bv_, false);
692 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
694 /* This will fit the cursor on the screen
696 update(text, BufferView::SELECT|BufferView::FITCUR);
701 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
707 LyXText * text = bv_->getLyXText();
709 if (text->bv_owner && bv_->theLockingInset())
712 if (screen_.get() && (button == 1)) {
713 screen_->hideCursor();
714 screen_->toggleSelection(text, bv_);
715 text->cursorHome(bv_);
716 text->selection.cursor = text->cursor;
717 text->cursorEnd(bv_);
718 text->setSelection(bv_);
719 screen_->toggleSelection(text, bv_, false);
720 /* This will fit the cursor on the screen
722 update(text, BufferView::SELECT|BufferView::FITCUR);
727 void BufferView::Pimpl::enterView()
729 if (active() && available()) {
730 SetXtermCursor(workarea_.getWin());
731 using_xterm_cursor = true;
736 void BufferView::Pimpl::leaveView()
738 if (using_xterm_cursor) {
739 XUndefineCursor(fl_get_display(), workarea_.getWin());
740 using_xterm_cursor = false;
745 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
748 if (!buffer_ || !screen_.get()) return;
750 // If we hit an inset, we have the inset coordinates in these
751 // and inset_hit points to the inset. If we do not hit an
752 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
753 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
755 if (bv_->theLockingInset()) {
756 // We are in inset locking mode.
758 /* LyX does a kind of work-area grabbing for insets.
759 Only a ButtonPress Event outside the inset will
760 force a insetUnlock. */
761 bv_->theLockingInset()->
762 insetButtonRelease(bv_, x, y, button);
766 selection_possible = false;
774 // Did we hit an editable inset?
776 // Inset like error, notes and figures
777 selection_possible = false;
779 // if we reach this point with a selection, it
780 // must mean we are currently selecting.
781 // But we don't want to open the inset
782 // because that is annoying for the user.
783 // So just pretend we didn't hit it.
784 // this is OK because a "kosher" ButtonRelease
785 // will follow a ButtonPress that clears
787 // Note this also fixes selection drawing
788 // problems if we end up opening an inset
789 if (bv_->getLyXText()->selection.set())
792 // CHECK fix this proper in 0.13
793 // well, maybe 13.0 !!!!!!!!!
795 // Following a ref shouldn't issue
796 // a push on the undo-stack
797 // anylonger, now that we have
798 // keybindings for following
799 // references and returning from
800 // references. IMHO though, it
801 // should be the inset's own business
802 // to push or not push on the undo
803 // stack. They don't *have* to
804 // alter the document...
806 // ...or maybe the SetCursorParUndo()
807 // below isn't necessary at all anylonger?
808 if (inset_hit->lyxCode() == Inset::REF_CODE) {
809 setCursorParUndo(bv_);
812 owner_->message(inset_hit->editMessage());
814 if (isHighlyEditableInset(inset_hit)) {
815 // Highly editable inset, like math
816 UpdatableInset *inset = (UpdatableInset *)inset_hit;
817 inset->insetButtonRelease(bv_, x, y, button);
819 inset_hit->insetButtonRelease(bv_, x, y, button);
820 inset_hit->edit(bv_, x, y, button);
826 #warning variable c is set but never used. What is it good for?? (JMarc)
827 #warning isnt this code dead ?? "open a float" ??? (jbl)
829 // check whether we want to open a float
833 if (bv_->text->cursor.pos() <
834 bv_->text->cursor.par()->size()) {
835 c = bv_->text->cursor.par()->
836 getChar(bv_->text->cursor.pos());
838 if (bv_->text->cursor.pos() - 1 >= 0) {
839 c = bv_->text->cursor.par()->
840 getChar(bv_->text->cursor.pos() - 1);
843 selection_possible = false;
848 // Maybe we want to edit a bibitem ale970302
849 if (bv_->text->cursor.par()->bibkey && x < 20 +
850 bibitemMaxWidth(bv_, textclasslist.
852 params.textclass).defaultfont())) {
853 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
861 * Returns an inset if inset was hit. 0 otherwise.
862 * If hit, the coordinates are changed relative to the inset.
863 * Otherwise coordinates are not changed, and false is returned.
865 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
866 unsigned int /* button */)
871 int y_tmp = y + text->first;
874 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
875 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
879 if (cursor.pos() < cursor.par()->size()
880 && cursor.par()->isInset(cursor.pos())
881 && isEditableInset(cursor.par()->getInset(cursor.pos())))
884 } else if ((cursor.pos() - 1 >= 0)
885 && cursor.par()->isInset(cursor.pos() - 1)
886 && isEditableInset(cursor.par()->getInset(cursor.pos() - 1)))
888 pos = cursor.pos() - 1;
889 // if the inset takes a full row, then the cursor.y()
890 // at the end of the inset will be wrong. So step the cursor
892 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
897 // Check whether the inset really was hit
898 Inset * inset = cursor.par()->getInset(pos);
899 LyXFont const & font = text->getFont(buffer_, cursor.par(), pos);
900 int const width = inset->width(bv_, font);
901 int const inset_x = font.isVisibleRightToLeft()
902 ? cursor.x() - width : cursor.x();
903 int const start_x = inset_x + inset->scroll();
904 int const end_x = inset_x + width;
905 int const start_y = cursor.y() - inset->ascent(bv_, font);
906 int const end_y = cursor.y() + inset->descent(bv_, font);
908 if (x > start_x && x < end_x && y_tmp > start_y && y < end_y) {
909 text->setCursor(bv_, cursor.par(), pos, true);
911 // The origin of an inset is on the baseline
912 y = y_tmp - (text->cursor.y());
920 void BufferView::Pimpl::workAreaExpose()
922 static int work_area_width;
923 static unsigned int work_area_height;
925 bool const widthChange = workarea_.workWidth() != work_area_width;
926 bool const heightChange = workarea_.height() != work_area_height;
928 // update from work area
929 work_area_width = workarea_.workWidth();
930 work_area_height = workarea_.height();
933 // The visible LyXView need a resize
936 // Remove all texts from the textcache
937 // This is not _really_ what we want to do. What
938 // we really want to do is to delete in textcache
939 // that does not have a BufferView with matching
940 // width, but as long as we have only one BufferView
941 // deleting all gives the same result.
942 if (lyxerr.debugging())
943 textcache.show(lyxerr, "Expose delete all");
945 } else if (heightChange) {
946 // Rebuild image of current screen
948 // fitCursor() ensures we don't jump back
949 // to the start of the document on vertical
953 // The main window size has changed, repaint most stuff
955 } else if (screen_.get())
956 screen_->redraw(bv_->text, bv_);
958 // Grey box when we don't have a buffer
962 // always make sure that the scrollbar is sane.
964 owner_->updateLayoutChoice();
969 void BufferView::Pimpl::update()
972 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
974 LyXText::text_status st = bv_->text->status();
975 screen_->update(bv_->text, bv_);
977 while(bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
978 if (bv_->text->fullRebreak(bv_)) {
979 st = LyXText::NEED_MORE_REFRESH;
980 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
981 bv_->text->cursor.pos());
984 bv_->text->status(bv_, st);
985 screen_->update(bv_->text, bv_);
987 // do this here instead of in the screen::update because of
989 bv_->text->status(bv_, LyXText::UNCHANGED);
995 // Values used when calling update:
997 // -2 - update, move sel_cursor if selection, fitcursor
998 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
999 // 0 - update, move sel_cursor if selection, fitcursor
1000 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1001 // 3 - update, move sel_cursor if selection
1004 // a simple redraw of the parts that need refresh
1006 // move sel_cursor if selection -
1007 // the text's sel_cursor is moved if there is selection is progress
1010 // fitCursor() is called and the scrollbar updated
1013 // the buffer is marked dirty.
1022 // UPDATE_ONLY = UPDATE;
1023 // UPDATE_SELECT = UPDATE | SELECT;
1024 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1025 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1027 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1028 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1029 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1030 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1031 // update(3) -> update(1) -> update(1) -> update(SELECT)
1033 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1035 owner_->updateLayoutChoice();
1037 if (!text->selection.set() && (f & SELECT)) {
1038 text->selection.cursor = text->cursor;
1041 text->fullRebreak(bv_);
1043 if (text->inset_owner) {
1044 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1045 updateInset(text->inset_owner, false);
1055 buffer_->markDirty();
1060 // Callback for cursor timer
1061 void BufferView::Pimpl::cursorToggle()
1063 // Quite a nice place for asyncron Inset updating, isn't it?
1064 // Actually no! This is run even if no buffer exist... so (Lgb)
1066 cursor_timeout.restart();
1071 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1072 if (pid == -1) // error find out what is wrong
1073 ; // ignore it for now.
1075 sigchldchecker(pid, &status);
1077 updatelist.update(bv_);
1079 if (!screen_.get()) {
1080 cursor_timeout.restart();
1084 if (!bv_->theLockingInset()) {
1085 screen_->cursorToggle(bv_);
1087 bv_->theLockingInset()->toggleInsetCursor(bv_);
1090 cursor_timeout.restart();
1094 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1096 if (!text->cursor.row()->previous())
1099 int y = text->first;
1100 if (text->inset_owner)
1101 y += bv_->text->first;
1102 Row * cursorrow = text->cursor.row();
1103 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1105 // This is to allow jumping over large insets
1106 if ((cursorrow == text->cursor.row()))
1107 text->cursorUp(bv_);
1109 if (text->inset_owner ||
1110 text->cursor.row()->height() < workarea_.height())
1111 screen_->draw(bv_->text, bv_,
1113 - text->cursor.row()->baseline()
1114 + text->cursor.row()->height()
1115 - workarea_.height() + 1 );
1120 void BufferView::Pimpl::cursorNext(LyXText * text)
1122 if (!text->cursor.row()->next())
1125 int y = text->first + workarea_.height();
1126 // if (text->inset_owner)
1127 // y += bv_->text->first;
1128 text->getRowNearY(y);
1130 Row * cursorrow = text->cursor.row();
1131 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1133 // This is to allow jumping over large insets
1134 if ((cursorrow == bv_->text->cursor.row()))
1135 text->cursorDown(bv_);
1137 if (text->inset_owner ||
1138 text->cursor.row()->height() < workarea_.height())
1139 screen_->draw(bv_->text, bv_, text->cursor.y() -
1140 text->cursor.row()->baseline());
1145 bool BufferView::Pimpl::available() const
1147 if (buffer_ && bv_->text) return true;
1152 void BufferView::Pimpl::beforeChange(LyXText * text)
1155 text->clearSelection();
1159 void BufferView::Pimpl::savePosition(unsigned int i)
1161 if (i >= saved_positions_num)
1163 saved_positions[i] = Position(buffer_->fileName(),
1164 bv_->text->cursor.par()->id(),
1165 bv_->text->cursor.pos());
1168 str << _("Saved bookmark") << ' ' << i;
1169 owner_->message(str.str().c_str());
1174 void BufferView::Pimpl::restorePosition(unsigned int i)
1176 if (i >= saved_positions_num)
1179 string const fname = saved_positions[i].filename;
1181 beforeChange(bv_->text);
1183 if (fname != buffer_->fileName()) {
1184 Buffer * b = bufferlist.exists(fname) ?
1185 bufferlist.getBuffer(fname) :
1186 bufferlist.loadLyXFile(fname); // don't ask, just load it
1187 if (b != 0 ) buffer(b);
1190 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1194 bv_->text->setCursor(bv_, par,
1195 min(par->size(), saved_positions[i].par_pos));
1197 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1200 str << _("Moved to bookmark") << ' ' << i;
1201 owner_->message(str.str().c_str());
1206 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1208 if (i >= saved_positions_num)
1211 return !saved_positions[i].filename.empty();
1215 void BufferView::Pimpl::setState()
1217 if (!lyxrc.rtl_support)
1220 LyXText * text = bv_->getLyXText();
1221 if (text->real_current_font.isRightToLeft()) {
1222 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1223 owner_->getIntl()->KeyMapSec();
1225 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1226 owner_->getIntl()->KeyMapPrim();
1231 void BufferView::Pimpl::insetSleep()
1233 if (bv_->theLockingInset() && !inset_slept) {
1234 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1235 bv_->theLockingInset()->insetUnlock(bv_);
1241 void BufferView::Pimpl::insetWakeup()
1243 if (bv_->theLockingInset() && inset_slept) {
1244 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1245 inset_slept = false;
1250 void BufferView::Pimpl::insetUnlock()
1252 if (bv_->theLockingInset()) {
1254 bv_->theLockingInset()->insetUnlock(bv_);
1255 bv_->theLockingInset(0);
1257 inset_slept = false;
1262 bool BufferView::Pimpl::focus() const
1264 return workarea_.hasFocus();
1268 void BufferView::Pimpl::focus(bool f)
1270 if (f) workarea_.setFocus();
1274 bool BufferView::Pimpl::active() const
1276 return workarea_.active();
1280 bool BufferView::Pimpl::belowMouse() const
1282 return workarea_.belowMouse();
1286 void BufferView::Pimpl::showCursor()
1288 if (screen_.get()) {
1289 if (bv_->theLockingInset())
1290 bv_->theLockingInset()->showInsetCursor(bv_);
1292 screen_->showCursor(bv_->text, bv_);
1297 void BufferView::Pimpl::hideCursor()
1299 if (screen_.get()) {
1300 if (!bv_->theLockingInset())
1301 // bv_->theLockingInset()->hideInsetCursor(bv_);
1303 screen_->hideCursor();
1308 void BufferView::Pimpl::toggleSelection(bool b)
1310 if (screen_.get()) {
1311 if (bv_->theLockingInset())
1312 bv_->theLockingInset()->toggleSelection(bv_, b);
1313 screen_->toggleSelection(bv_->text, bv_, b);
1318 void BufferView::Pimpl::toggleToggle()
1321 screen_->toggleToggle(bv_->text, bv_);
1325 void BufferView::Pimpl::center()
1327 beforeChange(bv_->text);
1328 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1329 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1331 screen_->draw(bv_->text, bv_, 0);
1333 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1338 void BufferView::Pimpl::pasteClipboard(bool asPara)
1340 if (!buffer_) return;
1342 screen_->hideCursor();
1343 beforeChange(bv_->text);
1345 string const clip(workarea_.getClipboard());
1347 if (clip.empty()) return;
1350 bv_->text->insertStringAsParagraphs(bv_, clip);
1352 bv_->text->insertStringAsLines(bv_, clip);
1354 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1358 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1360 workarea_.putClipboard(stuff);
1365 * Dispatch functions for actions which can be valid for BufferView->text
1366 * and/or InsetText->text!!!
1371 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1373 LyXText * lt = bv_->getLyXText();
1375 if (selecting || lt->selection.mark()) {
1376 lt->setSelection(bv_);
1380 update(lt, BufferView::SELECT|BufferView::FITCUR);
1383 /* ---> Everytime the cursor is moved, show the current font state. */
1384 // should this too me moved out of this func?
1385 //owner->showState();
1390 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1392 LyXCursor cursor = bv_->getLyXText()->cursor;
1393 Buffer::inset_iterator it =
1394 find_if(Buffer::inset_iterator(
1395 cursor.par(), cursor.pos()),
1396 buffer_->inset_iterator_end(),
1397 lyx::compare_memfun(&Inset::lyxCode, code));
1398 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1402 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1404 string filename = filen;
1406 if (filename.empty()) {
1407 // Launch a file browser
1408 string initpath = lyxrc.document_path;
1411 string const trypath = owner_->buffer()->filepath;
1412 // If directory is writeable, use this as default.
1413 if (IsDirWriteable(trypath))
1417 FileDialog fileDlg(bv_->owner(),
1418 _("Select LyX document to insert"),
1420 make_pair(string(_("Documents")),
1421 string(lyxrc.document_path)),
1422 make_pair(string(_("Examples")),
1423 string(AddPath(system_lyxdir, "examples"))));
1425 FileDialog::Result result =
1426 fileDlg.Select(initpath,
1427 _("*.lyx| LyX Documents (*.lyx)"));
1429 if (result.first == FileDialog::Later)
1432 filename = result.second;
1434 // check selected filename
1435 if (filename.empty()) {
1436 owner_->message(_("Canceled."));
1441 // get absolute path of file and add ".lyx" to the filename if
1443 filename = FileSearch(string(), filename, "lyx");
1445 string const disp_fn(MakeDisplayPath(filename));
1448 s1 << _("Inserting document") << ' '
1449 << disp_fn << " ...";
1450 owner_->message(s1.str().c_str());
1451 bool const res = bv_->insertLyXFile(filename);
1454 str << _("Document") << ' ' << disp_fn
1455 << ' ' << _("inserted.");
1456 owner_->message(str.str().c_str());
1459 str << _("Could not insert document") << ' '
1461 owner_->message(str.str().c_str());
1466 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1468 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1469 << action <<"] arg[" << argument << "]" << endl;
1472 // --- Misc -------------------------------------------
1476 LyXText * lt = bv_->getLyXText();
1477 lt->toggleAppendix(bv_);
1480 | BufferView::FITCUR
1481 | BufferView::CHANGE);
1486 case LFUN_TOC_INSERT:
1488 InsetCommandParams p;
1489 p.setCmdName("tableofcontents");
1490 Inset * inset = new InsetTOC(p);
1491 if (!insertInset(inset, "Standard"))
1496 case LFUN_TABULAR_FEATURE:
1497 case LFUN_SCROLL_INSET:
1498 // this is not handled here as this funktion is only aktive
1499 // if we have a locking_inset and that one is (or contains)
1503 case LFUN_INSET_GRAPHICS:
1505 Inset * new_inset = new InsetGraphics;
1506 if (!insertInset(new_inset)) {
1509 // this is need because you don't use a inset->Edit()
1510 updateInset(new_inset, true);
1511 new_inset->edit(bv_);
1521 case LFUN_PASTESELECTION:
1523 bool asPara = false;
1524 if (argument == "paragraph") asPara = true;
1525 pasteClipboard(asPara);
1537 case LFUN_LAYOUT_COPY:
1538 bv_->copyEnvironment();
1541 case LFUN_LAYOUT_PASTE:
1542 bv_->pasteEnvironment();
1546 case LFUN_GOTOERROR:
1547 gotoInset(Inset::ERROR_CODE, false);
1551 gotoInset(Inset::IGNORE_CODE, false);
1554 case LFUN_REFERENCE_GOTO:
1556 vector<Inset::Code> tmp;
1557 tmp.push_back(Inset::LABEL_CODE);
1558 tmp.push_back(Inset::REF_CODE);
1559 gotoInset(tmp, true);
1563 case LFUN_HYPHENATION:
1564 specialChar(InsetSpecialChar::HYPHENATION);
1567 case LFUN_LIGATURE_BREAK:
1568 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1572 specialChar(InsetSpecialChar::LDOTS);
1575 case LFUN_END_OF_SENTENCE:
1576 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1579 case LFUN_MENU_SEPARATOR:
1580 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1588 changeDepth(bv_, bv_->getLyXText(), 0);
1591 case LFUN_DEPTH_MIN:
1592 changeDepth(bv_, bv_->getLyXText(), -1);
1595 case LFUN_DEPTH_PLUS:
1596 changeDepth(bv_, bv_->getLyXText(), 1);
1600 owner_->getDialogs()->setUserFreeFont();
1603 case LFUN_FILE_INSERT:
1604 MenuInsertLyXFile(argument);
1607 case LFUN_FILE_INSERT_ASCII_PARA:
1608 InsertAsciiFile(bv_, argument, true);
1611 case LFUN_FILE_INSERT_ASCII:
1612 InsertAsciiFile(bv_, argument, false);
1617 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1618 << argument << endl;
1620 // Derive layout number from given argument (string)
1621 // and current buffer's textclass (number). */
1622 textclass_type tclass = buffer_->params.textclass;
1623 pair <bool, layout_type> layout =
1624 textclasslist.NumberOfLayout(tclass, argument);
1626 // If the entry is obsolete, use the new one instead.
1628 string obs = textclasslist.Style(tclass, layout.second)
1631 layout = textclasslist.NumberOfLayout(tclass, obs);
1634 // see if we found the layout number:
1635 if (!layout.first) {
1636 owner_->getLyXFunc()->setErrorMessage(
1637 string(N_("Layout ")) + argument +
1642 if (current_layout != layout.second) {
1643 LyXText * lt = bv_->getLyXText();
1645 current_layout = layout.second;
1648 | BufferView::FITCUR);
1649 lt->setLayout(bv_, layout.second);
1650 owner_->setLayout(layout.second);
1653 | BufferView::FITCUR
1654 | BufferView::CHANGE);
1661 lang(bv_, argument);
1663 owner_->showState();
1668 owner_->showState();
1673 owner_->showState();
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1698 owner_->showState();
1701 case LFUN_UNDERLINE:
1703 owner_->showState();
1706 case LFUN_FONT_SIZE:
1707 fontSize(bv_, argument);
1708 owner_->showState();
1711 case LFUN_FONT_STATE:
1712 owner_->getLyXFunc()->setMessage(currentState(bv_));
1715 case LFUN_UPCASE_WORD:
1717 LyXText * lt = bv_->getLyXText();
1721 | BufferView::FITCUR);
1722 lt->changeCase(bv_, LyXText::text_uppercase);
1723 if (lt->inset_owner)
1724 updateInset(lt->inset_owner, true);
1727 | BufferView::FITCUR
1728 | BufferView::CHANGE);
1732 case LFUN_LOWCASE_WORD:
1734 LyXText * lt = bv_->getLyXText();
1736 update(lt, BufferView::SELECT|BufferView::FITCUR);
1737 lt->changeCase(bv_, LyXText::text_lowercase);
1738 if (lt->inset_owner)
1739 updateInset(lt->inset_owner, true);
1742 | BufferView::FITCUR
1743 | BufferView::CHANGE);
1747 case LFUN_CAPITALIZE_WORD:
1749 LyXText * lt = bv_->getLyXText();
1751 update(lt, BufferView::SELECT|BufferView::FITCUR);
1752 lt->changeCase(bv_, LyXText::text_capitalization);
1753 if (lt->inset_owner)
1754 updateInset(lt->inset_owner, true);
1757 | BufferView::FITCUR
1758 | BufferView::CHANGE);
1762 case LFUN_TRANSPOSE_CHARS:
1764 LyXText * lt = bv_->getLyXText();
1766 update(lt, BufferView::SELECT|BufferView::FITCUR);
1767 lt->transposeChars(*bv_);
1768 if (lt->inset_owner)
1769 updateInset(lt->inset_owner, true);
1772 | BufferView::FITCUR
1773 | BufferView::CHANGE);
1778 case LFUN_INSERT_LABEL:
1779 MenuInsertLabel(bv_, argument);
1782 case LFUN_REF_INSERT:
1783 if (argument.empty()) {
1784 InsetCommandParams p("ref");
1785 owner_->getDialogs()->createRef(p.getAsString());
1787 InsetCommandParams p;
1788 p.setFromString(argument);
1790 InsetRef * inset = new InsetRef(p, *buffer_);
1791 if (!insertInset(inset))
1794 updateInset(inset, true);
1798 case LFUN_BOOKMARK_SAVE:
1799 savePosition(strToUnsignedInt(argument));
1802 case LFUN_BOOKMARK_GOTO:
1803 restorePosition(strToUnsignedInt(argument));
1808 string label(argument);
1809 if (label.empty()) {
1811 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1813 label = inset->getContents();
1818 if (!label.empty()) {
1819 //bv_->savePosition(0);
1820 if (!bv_->gotoLabel(label))
1821 Alert::alert(_("Error"),
1822 _("Couldn't find this label"),
1823 _("in current document."));
1828 // --- Cursor Movements -----------------------------
1831 LyXText * lt = bv_->getLyXText();
1833 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1834 if (!lt->selection.mark())
1836 update(lt, BufferView::SELECT|BufferView::FITCUR);
1838 lt->cursorLeft(bv_, false);
1839 if (lt->cursor.pos() < lt->cursor.par()->size()
1840 && lt->cursor.par()->isInset(lt->cursor.pos())
1841 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1842 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1843 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1845 tmpinset->edit(bv_, false);
1847 tmpinset->edit(bv_);
1851 lt->cursorRight(bv_, false);
1853 moveCursorUpdate(false);
1854 owner_->showState();
1860 // This is soooo ugly. Isn`t it possible to make
1861 // it simpler? (Lgb)
1862 LyXText * lt = bv_->getLyXText();
1863 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1864 if (!lt->selection.mark())
1866 update(lt, BufferView::SELECT|BufferView::FITCUR);
1867 LyXCursor const cur = lt->cursor;
1869 lt->cursorLeft(bv_, false);
1870 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1871 lt->cursor.pos() < lt->cursor.par()->size() &&
1872 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1873 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1874 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1875 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1877 tmpinset->edit(bv_);
1879 tmpinset->edit(bv_, false);
1883 lt->cursorRight(bv_, false);
1886 moveCursorUpdate(false);
1887 owner_->showState();
1893 LyXText * lt = bv_->getLyXText();
1895 if (!lt->selection.mark())
1897 update(lt, BufferView::UPDATE);
1900 moveCursorUpdate(false);
1901 owner_->showState();
1907 LyXText * lt = bv_->getLyXText();
1909 if (!lt->selection.mark())
1911 update(lt, BufferView::UPDATE);
1912 lt->cursorDown(bv_);
1914 moveCursorUpdate(false);
1915 owner_->showState();
1919 case LFUN_UP_PARAGRAPH:
1921 LyXText * lt = bv_->getLyXText();
1923 if (!lt->selection.mark())
1925 update(lt, BufferView::UPDATE);
1926 lt->cursorUpParagraph(bv_);
1928 moveCursorUpdate(false);
1929 owner_->showState();
1933 case LFUN_DOWN_PARAGRAPH:
1935 LyXText * lt = bv_->getLyXText();
1937 if (!lt->selection.mark())
1939 update(lt, BufferView::UPDATE);
1940 lt->cursorDownParagraph(bv_);
1942 moveCursorUpdate(false);
1943 owner_->showState();
1949 LyXText * lt = bv_->getLyXText();
1951 if (!lt->selection.mark())
1953 update(lt, BufferView::UPDATE);
1956 moveCursorUpdate(false);
1957 owner_->showState();
1963 LyXText * lt = bv_->getLyXText();
1965 if (!lt->selection.mark())
1967 update(lt, BufferView::UPDATE);
1970 moveCursorUpdate(false);
1971 owner_->showState();
1977 LyXText * lt = bv_->getLyXText();
1979 if (!lt->selection.mark())
1981 update(lt, BufferView::SELECT|BufferView::FITCUR);
1982 lt->cursorHome(bv_);
1984 moveCursorUpdate(false);
1985 owner_->showState();
1991 LyXText * lt = bv_->getLyXText();
1993 if (!lt->selection.mark())
1996 BufferView::SELECT|BufferView::FITCUR);
1999 moveCursorUpdate(false);
2000 owner_->showState();
2004 case LFUN_SHIFT_TAB:
2007 LyXText * lt = bv_->getLyXText();
2009 if (!lt->selection.mark())
2012 BufferView::SELECT|BufferView::FITCUR);
2015 moveCursorUpdate(false);
2016 owner_->showState();
2020 case LFUN_WORDRIGHT:
2022 LyXText * lt = bv_->getLyXText();
2024 if (!lt->selection.mark())
2026 update(lt, BufferView::SELECT|BufferView::FITCUR);
2027 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2028 lt->cursorLeftOneWord(bv_);
2030 lt->cursorRightOneWord(bv_);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2039 LyXText * lt = bv_->getLyXText();
2041 if (!lt->selection.mark())
2043 update(lt, BufferView::SELECT|BufferView::FITCUR);
2044 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2045 lt->cursorRightOneWord(bv_);
2047 lt->cursorLeftOneWord(bv_);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2054 case LFUN_BEGINNINGBUF:
2056 LyXText * lt = bv_->getLyXText();
2058 if (!lt->selection.mark())
2061 BufferView::SELECT|BufferView::FITCUR);
2064 moveCursorUpdate(false);
2065 owner_->showState();
2071 LyXText * lt = bv_->getLyXText();
2073 if (!lt->selection.mark())
2076 BufferView::SELECT|BufferView::FITCUR);
2077 lt->cursorBottom(bv_);
2079 moveCursorUpdate(false);
2080 owner_->showState();
2084 /* cursor selection ---------------------------- */
2087 LyXText * lt = bv_->getLyXText();
2090 BufferView::SELECT|BufferView::FITCUR);
2091 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2092 lt->cursorLeft(bv_);
2094 lt->cursorRight(bv_);
2096 moveCursorUpdate(true);
2097 owner_->showState();
2103 LyXText * lt = bv_->getLyXText();
2106 BufferView::SELECT|BufferView::FITCUR);
2107 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2108 lt->cursorRight(bv_);
2110 lt->cursorLeft(bv_);
2112 moveCursorUpdate(true);
2113 owner_->showState();
2119 LyXText * lt = bv_->getLyXText();
2122 BufferView::SELECT|BufferView::FITCUR);
2125 moveCursorUpdate(true);
2126 owner_->showState();
2132 LyXText * lt = bv_->getLyXText();
2135 BufferView::SELECT|BufferView::FITCUR);
2136 lt->cursorDown(bv_);
2138 moveCursorUpdate(true);
2139 owner_->showState();
2143 case LFUN_UP_PARAGRAPHSEL:
2145 LyXText * lt = bv_->getLyXText();
2148 BufferView::SELECT|BufferView::FITCUR);
2149 lt->cursorUpParagraph(bv_);
2151 moveCursorUpdate(true);
2152 owner_->showState();
2156 case LFUN_DOWN_PARAGRAPHSEL:
2158 LyXText * lt = bv_->getLyXText();
2161 BufferView::SELECT|BufferView::FITCUR);
2162 lt->cursorDownParagraph(bv_);
2164 moveCursorUpdate(true);
2165 owner_->showState();
2171 LyXText * lt = bv_->getLyXText();
2173 update(lt, BufferView::SELECT|BufferView::FITCUR);
2176 moveCursorUpdate(true);
2177 owner_->showState();
2183 LyXText * lt = bv_->getLyXText();
2185 update(lt, BufferView::SELECT|BufferView::FITCUR);
2188 moveCursorUpdate(true);
2189 owner_->showState();
2195 LyXText * lt = bv_->getLyXText();
2197 update(lt, BufferView::SELECT|BufferView::FITCUR);
2198 lt->cursorHome(bv_);
2200 moveCursorUpdate(true);
2201 owner_->showState();
2207 LyXText * lt = bv_->getLyXText();
2209 update(lt, BufferView::SELECT|BufferView::FITCUR);
2212 moveCursorUpdate(true);
2213 owner_->showState();
2217 case LFUN_WORDRIGHTSEL:
2219 LyXText * lt = bv_->getLyXText();
2221 update(lt, BufferView::SELECT|BufferView::FITCUR);
2222 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2223 lt->cursorLeftOneWord(bv_);
2225 lt->cursorRightOneWord(bv_);
2227 moveCursorUpdate(true);
2228 owner_->showState();
2232 case LFUN_WORDLEFTSEL:
2234 LyXText * lt = bv_->getLyXText();
2236 update(lt, BufferView::SELECT|BufferView::FITCUR);
2237 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2238 lt->cursorRightOneWord(bv_);
2240 lt->cursorLeftOneWord(bv_);
2242 moveCursorUpdate(true);
2243 owner_->showState();
2247 case LFUN_BEGINNINGBUFSEL:
2249 LyXText * lt = bv_->getLyXText();
2251 if (lt->inset_owner)
2253 update(lt, BufferView::SELECT|BufferView::FITCUR);
2256 moveCursorUpdate(true);
2257 owner_->showState();
2261 case LFUN_ENDBUFSEL:
2263 LyXText * lt = bv_->getLyXText();
2265 if (lt->inset_owner)
2268 BufferView::SELECT|BufferView::FITCUR);
2269 lt->cursorBottom(bv_);
2271 moveCursorUpdate(true);
2272 owner_->showState();
2276 // --- text changing commands ------------------------
2277 case LFUN_BREAKLINE:
2279 LyXText * lt = bv_->getLyXText();
2282 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2285 | BufferView::FITCUR
2286 | BufferView::CHANGE);
2287 moveCursorUpdate(false);
2291 case LFUN_PROTECTEDSPACE:
2293 LyXText * lt = bv_->getLyXText();
2295 LyXLayout const & style = textclasslist
2296 .Style(buffer_->params.textclass,
2297 lt->cursor.par()->getLayout());
2299 if (style.free_spacing) {
2300 lt->insertChar(bv_, ' ');
2303 | BufferView::FITCUR
2304 | BufferView::CHANGE);
2308 moveCursorUpdate(false);
2314 LyXText * lt = bv_->getLyXText();
2316 if (lt->selection.mark()) {
2320 | BufferView::FITCUR);
2321 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2324 lt->selection.mark(true);
2327 | BufferView::FITCUR);
2328 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2330 lt->selection.cursor = lt->cursor;
2336 LyXText * lt = bv_->getLyXText();
2338 if (!lt->selection.set()) {
2340 lt->selection.cursor = lt->cursor;
2343 | BufferView::FITCUR
2344 | BufferView::CHANGE);
2345 // It is possible to make it a lot faster still
2346 // just comment out the line below...
2351 moveCursorUpdate(false);
2352 owner_->showState();
2357 case LFUN_DELETE_SKIP:
2359 LyXText * lt = bv_->getLyXText();
2361 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2363 LyXCursor cursor = lt->cursor;
2365 if (!lt->selection.set()) {
2366 if (cursor.pos() == cursor.par()->size()) {
2367 lt->cursorRight(bv_);
2368 cursor = lt->cursor;
2369 if (cursor.pos() == 0
2370 && !(cursor.par()->params().spaceTop()
2371 == VSpace (VSpace::NONE))) {
2374 cursor.par()->params().lineTop(),
2375 cursor.par()->params().lineBottom(),
2376 cursor.par()->params().pagebreakTop(),
2377 cursor.par()->params().pagebreakBottom(),
2378 VSpace(VSpace::NONE),
2379 cursor.par()->params().spaceBottom(),
2380 cursor.par()->params().spacing(),
2381 cursor.par()->params().align(),
2382 cursor.par()->params().labelWidthString(), 0);
2383 lt->cursorLeft(bv_);
2386 | BufferView::FITCUR
2387 | BufferView::CHANGE);
2389 lt->cursorLeft(bv_);
2391 lt->selection.cursor = lt->cursor;
2394 | BufferView::FITCUR
2395 | BufferView::CHANGE);
2399 lt->selection.cursor = lt->cursor;
2402 | BufferView::FITCUR
2403 | BufferView::CHANGE);
2411 /* -------> Delete word forward. */
2412 case LFUN_DELETE_WORD_FORWARD:
2413 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2414 bv_->getLyXText()->deleteWordForward(bv_);
2415 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2416 moveCursorUpdate(false);
2417 owner_->showState();
2420 /* -------> Delete word backward. */
2421 case LFUN_DELETE_WORD_BACKWARD:
2423 LyXText * lt = bv_->getLyXText();
2425 update(lt, BufferView::SELECT|BufferView::FITCUR);
2426 lt->deleteWordBackward(bv_);
2429 | BufferView::FITCUR
2430 | BufferView::CHANGE);
2431 moveCursorUpdate(false);
2432 owner_->showState();
2436 /* -------> Kill to end of line. */
2437 case LFUN_DELETE_LINE_FORWARD:
2439 LyXText * lt = bv_->getLyXText();
2441 update(lt, BufferView::SELECT|BufferView::FITCUR);
2442 lt->deleteLineForward(bv_);
2445 | BufferView::FITCUR
2446 | BufferView::CHANGE);
2447 moveCursorUpdate(false);
2451 /* -------> Set mark off. */
2454 LyXText * lt = bv_->getLyXText();
2457 update(lt, BufferView::SELECT|BufferView::FITCUR);
2458 lt->selection.cursor = lt->cursor;
2459 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2463 /* -------> Set mark on. */
2466 LyXText * lt = bv_->getLyXText();
2469 lt->selection.mark(true);
2470 update(lt, BufferView::SELECT|BufferView::FITCUR);
2471 lt->selection.cursor = lt->cursor;
2472 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2476 case LFUN_BACKSPACE:
2478 LyXText * lt = bv_->getLyXText();
2480 if (!lt->selection.set()) {
2481 if (owner_->getIntl()->getTrans().backspace()) {
2483 lt->selection.cursor = lt->cursor;
2486 | BufferView::FITCUR
2487 | BufferView::CHANGE);
2488 // It is possible to make it a lot faster still
2489 // just comment out the line below...
2495 owner_->showState();
2500 case LFUN_BACKSPACE_SKIP:
2502 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2503 LyXText * lt = bv_->getLyXText();
2505 LyXCursor cursor = lt->cursor;
2507 if (!lt->selection.set()) {
2508 if (cursor.pos() == 0
2509 && !(cursor.par()->params().spaceTop()
2510 == VSpace (VSpace::NONE))) {
2513 cursor.par()->params().lineTop(),
2514 cursor.par()->params().lineBottom(),
2515 cursor.par()->params().pagebreakTop(),
2516 cursor.par()->params().pagebreakBottom(),
2517 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2518 cursor.par()->params().spacing(),
2519 cursor.par()->params().align(),
2520 cursor.par()->params().labelWidthString(), 0);
2523 | BufferView::FITCUR
2524 | BufferView::CHANGE);
2527 lt->selection.cursor = cursor;
2530 | BufferView::FITCUR
2531 | BufferView::CHANGE);
2538 case LFUN_BREAKPARAGRAPH:
2540 LyXText * lt = bv_->getLyXText();
2543 lt->breakParagraph(bv_, 0);
2546 | BufferView::FITCUR
2547 | BufferView::CHANGE);
2548 lt->selection.cursor = lt->cursor;
2550 owner_->showState();
2554 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2556 LyXText * lt = bv_->getLyXText();
2559 lt->breakParagraph(bv_, 1);
2562 | BufferView::FITCUR
2563 | BufferView::CHANGE);
2564 lt->selection.cursor = lt->cursor;
2566 owner_->showState();
2570 case LFUN_BREAKPARAGRAPH_SKIP:
2572 // When at the beginning of a paragraph, remove
2573 // indentation and add a "defskip" at the top.
2574 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2575 LyXText * lt = bv_->getLyXText();
2577 LyXCursor cursor = lt->cursor;
2580 if (cursor.pos() == 0) {
2581 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2584 cursor.par()->params().lineTop(),
2585 cursor.par()->params().lineBottom(),
2586 cursor.par()->params().pagebreakTop(),
2587 cursor.par()->params().pagebreakBottom(),
2588 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2589 cursor.par()->params().spacing(),
2590 cursor.par()->params().align(),
2591 cursor.par()->params().labelWidthString(), 1);
2592 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2596 lt->breakParagraph(bv_, 0);
2597 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2602 | BufferView::FITCUR
2603 | BufferView::CHANGE);
2604 lt->selection.cursor = cursor;
2606 owner_->showState();
2610 case LFUN_PARAGRAPH_SPACING:
2612 LyXText * lt = bv_->getLyXText();
2614 Paragraph * par = lt->cursor.par();
2615 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2616 float cur_value = 1.0;
2617 if (cur_spacing == Spacing::Other) {
2618 cur_value = par->params().spacing().getValue();
2621 istringstream istr(argument.c_str());
2625 Spacing::Space new_spacing = cur_spacing;
2626 float new_value = cur_value;
2628 lyxerr << "Missing argument to `paragraph-spacing'"
2630 } else if (tmp == "single") {
2631 new_spacing = Spacing::Single;
2632 } else if (tmp == "onehalf") {
2633 new_spacing = Spacing::Onehalf;
2634 } else if (tmp == "double") {
2635 new_spacing = Spacing::Double;
2636 } else if (tmp == "other") {
2637 new_spacing = Spacing::Other;
2640 lyxerr << "new_value = " << tmpval << endl;
2643 } else if (tmp == "default") {
2644 new_spacing = Spacing::Default;
2646 lyxerr << _("Unknown spacing argument: ")
2647 << argument << endl;
2649 if (cur_spacing != new_spacing || cur_value != new_value) {
2650 par->params().spacing(Spacing(new_spacing, new_value));
2651 lt->redoParagraph(bv_);
2654 | BufferView::FITCUR
2655 | BufferView::CHANGE);
2660 case LFUN_INSET_TOGGLE:
2662 LyXText * lt = bv_->getLyXText();
2665 update(lt, BufferView::SELECT|BufferView::FITCUR);
2666 lt->toggleInset(bv_);
2667 update(lt, BufferView::SELECT|BufferView::FITCUR);
2679 InsetCommandParams p;
2680 if (action == LFUN_HTMLURL)
2681 p.setCmdName("htmlurl");
2683 p.setCmdName("url");
2684 owner_->getDialogs()->createUrl(p.getAsString());
2688 case LFUN_INSERT_URL:
2690 InsetCommandParams p;
2691 p.setFromString(argument);
2693 InsetUrl * inset = new InsetUrl(p);
2694 if (!insertInset(inset))
2697 updateInset(inset, true);
2701 case LFUN_INSET_TEXT:
2702 insertAndEditInset(new InsetText);
2705 case LFUN_INSET_ERT:
2706 insertAndEditInset(new InsetERT);
2709 case LFUN_INSET_EXTERNAL:
2710 insertAndEditInset(new InsetExternal);
2713 case LFUN_INSET_FOOTNOTE:
2714 insertAndEditInset(new InsetFoot);
2717 case LFUN_INSET_MARGINAL:
2718 insertAndEditInset(new InsetMarginal);
2721 case LFUN_INSET_MINIPAGE:
2722 insertAndEditInset(new InsetMinipage);
2725 case LFUN_INSERT_NOTE:
2726 insertAndEditInset(new InsetNote);
2729 case LFUN_INSET_FLOAT:
2730 // check if the float type exist
2731 if (floatList.typeExist(argument)) {
2732 insertAndEditInset(new InsetFloat(argument));
2734 lyxerr << "Non-existent float type: "
2735 << argument << endl;
2739 case LFUN_INSET_WIDE_FLOAT:
2741 // check if the float type exist
2742 if (floatList.typeExist(argument)) {
2743 InsetFloat * new_inset = new InsetFloat(argument);
2744 new_inset->wide(true);
2745 if (insertInset(new_inset))
2746 new_inset->edit(bv_);
2750 lyxerr << "Non-existent float type: "
2751 << argument << endl;
2758 case LFUN_INSET_LIST:
2759 insertAndEditInset(new InsetList);
2762 case LFUN_INSET_THEOREM:
2763 insertAndEditInset(new InsetTheorem);
2767 case LFUN_INSET_CAPTION:
2769 // Do we have a locking inset...
2770 if (bv_->theLockingInset()) {
2771 lyxerr << "Locking inset code: "
2772 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2773 InsetCaption * new_inset = new InsetCaption;
2774 new_inset->setOwner(bv_->theLockingInset());
2775 new_inset->setAutoBreakRows(true);
2776 new_inset->setDrawFrame(0, InsetText::LOCKED);
2777 new_inset->setFrameColor(0, LColor::captionframe);
2778 if (insertInset(new_inset))
2779 new_inset->edit(bv_);
2786 case LFUN_INSET_TABULAR:
2790 if (!argument.empty())
2791 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2792 InsetTabular * new_inset =
2793 new InsetTabular(*buffer_, r, c);
2795 bv_->getLyXText()->real_current_font.isRightToLeft();
2796 if (!open_new_inset(new_inset, rtl))
2801 // --- lyxserver commands ----------------------------
2803 case LFUN_CHARATCURSOR:
2805 pos_type pos = bv_->getLyXText()->cursor.pos();
2806 if (pos < bv_->getLyXText()->cursor.par()->size())
2807 owner_->getLyXFunc()->setMessage(
2808 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2810 owner_->getLyXFunc()->setMessage("EOF");
2815 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2817 + tostr(bv_->getLyXText()->cursor.y()));
2824 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2825 lyxerr << "SETXY: Could not parse coordinates in '"
2826 << argument << std::endl;
2828 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2832 case LFUN_GETLAYOUT:
2833 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2838 LyXFont & font = bv_->getLyXText()->current_font;
2839 if (font.shape() == LyXFont::ITALIC_SHAPE)
2840 owner_->getLyXFunc()->setMessage("E");
2841 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2842 owner_->getLyXFunc()->setMessage("N");
2844 owner_->getLyXFunc()->setMessage("0");
2849 // --- accented characters ---------------------------
2852 case LFUN_CIRCUMFLEX:
2862 case LFUN_SPECIAL_CARON:
2865 case LFUN_HUNG_UMLAUT:
2868 if (argument.empty()) {
2870 owner_->getLyXFunc()->handleKeyFunc(action);
2872 owner_->getLyXFunc()->handleKeyFunc(action);
2873 owner_->getIntl()->getTrans()
2874 .TranslateAndInsert(argument[0], bv_->getLyXText());
2875 update(bv_->getLyXText(),
2877 | BufferView::FITCUR
2878 | BufferView::CHANGE);
2882 case LFUN_MATH_MACRO:
2883 mathDispatchMathMacro(bv_, argument);
2886 case LFUN_MATH_DELIM:
2887 mathDispatchMathDelim(bv_, argument);
2890 case LFUN_INSERT_MATRIX:
2891 mathDispatchInsertMatrix(bv_, argument);
2894 case LFUN_INSERT_MATH:
2895 mathDispatchInsertMath(bv_, argument);
2898 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2899 mathDispatchMathImportSelection(bv_, argument);
2902 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2903 mathDispatchMathDisplay(bv_, argument);
2906 case LFUN_MATH_MODE: // Open or create an inlined math inset
2907 mathDispatchMathMode(bv_, argument);
2910 case LFUN_GREEK: // Insert a single greek letter
2911 mathDispatchGreek(bv_, argument);
2914 case LFUN_CITATION_INSERT:
2916 InsetCommandParams p;
2917 p.setFromString( argument );
2919 InsetCitation * inset = new InsetCitation( p );
2920 if (!insertInset(inset))
2923 updateInset( inset, true );
2927 case LFUN_INSERT_BIBTEX:
2929 // ale970405+lasgoutt970425
2930 // The argument can be up to two tokens separated
2931 // by a space. The first one is the bibstyle.
2932 string const db = token(argument, ' ', 0);
2933 string const bibstyle = token(argument, ' ', 1);
2935 InsetCommandParams p( "BibTeX", db, bibstyle );
2936 InsetBibtex * inset = new InsetBibtex(p);
2938 if (insertInset(inset)) {
2939 if (argument.empty())
2946 // BibTeX data bases
2947 case LFUN_BIBDB_ADD:
2949 InsetBibtex * inset =
2950 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2952 inset->addDatabase(argument);
2957 case LFUN_BIBDB_DEL:
2959 InsetBibtex * inset =
2960 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2962 inset->delDatabase(argument);
2967 case LFUN_BIBTEX_STYLE:
2969 InsetBibtex * inset =
2970 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2972 inset->setOptions(argument);
2977 case LFUN_INDEX_CREATE:
2979 InsetCommandParams p("index");
2980 if (argument.empty()) {
2981 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2982 p.setContents(idxstring);
2984 p.setContents(argument);
2987 owner_->getDialogs()->createIndex(p.getAsString());
2991 case LFUN_INDEX_INSERT:
2993 InsetCommandParams p;
2994 p.setFromString(argument);
2995 InsetIndex * inset = new InsetIndex(p);
2997 if (!insertInset(inset))
3000 updateInset(inset, true);
3004 case LFUN_INDEX_INSERT_LAST:
3006 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3007 if (!idxstring.empty()) {
3008 owner_->message(_("Word `")
3009 + idxstring + _(("' indexed.")));
3010 InsetCommandParams p("index", idxstring);
3011 InsetIndex * inset = new InsetIndex(p);
3013 if (!insertInset(inset))
3016 updateInset(inset, true);
3021 case LFUN_INDEX_PRINT:
3023 InsetCommandParams p("printindex");
3024 Inset * inset = new InsetPrintIndex(p);
3025 if (!insertInset(inset, "Standard"))
3030 case LFUN_PARENTINSERT:
3032 lyxerr << "arg " << argument << endl;
3033 InsetCommandParams p( "lyxparent", argument );
3034 Inset * inset = new InsetParent(p, *buffer_);
3035 if (!insertInset(inset, "Standard"))
3041 case LFUN_CHILD_INSERT:
3043 InsetInclude::Params p;
3044 p.cparams.setFromString(argument);
3045 p.masterFilename_ = buffer_->fileName();
3047 InsetInclude * inset = new InsetInclude(p);
3048 if (!insertInset(inset))
3051 updateInset(inset, true);
3052 bv_->owner()->getDialogs()->showInclude(inset);
3057 case LFUN_FLOAT_LIST:
3059 // We should check the argument for validity. (Lgb)
3060 Inset * inset = new InsetFloatList(argument);
3061 if (!insertInset(inset, "Standard"))
3066 case LFUN_THESAURUS_ENTRY:
3068 string arg = argument;
3071 arg = bv_->getLyXText()->selectionAsString(buffer_,
3075 if (arg.size() > 100 || arg.empty()) {
3076 // Get word or selection
3077 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3078 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3079 // FIXME: where is getLyXText()->unselect(bv_) ?
3083 bv_->owner()->getDialogs()->showThesaurus(arg);
3087 case LFUN_SELFINSERT:
3089 if (argument.empty()) break;
3091 /* Automatically delete the currently selected
3092 * text and replace it with what is being
3093 * typed in now. Depends on lyxrc settings
3094 * "auto_region_delete", which defaults to
3097 LyXText * lt = bv_->getLyXText();
3099 if (lyxrc.auto_region_delete) {
3100 if (lt->selection.set()) {
3101 lt->cutSelection(bv_, false, false);
3104 | BufferView::FITCUR
3105 | BufferView::CHANGE);
3110 LyXFont const old_font(lt->real_current_font);
3112 string::const_iterator cit = argument.begin();
3113 string::const_iterator end = argument.end();
3114 for (; cit != end; ++cit) {
3115 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3120 | BufferView::FITCUR
3121 | BufferView::CHANGE);
3123 lt->selection.cursor = lt->cursor;
3124 moveCursorUpdate(false);
3126 // real_current_font.number can change so we need to
3127 // update the minibuffer
3128 if (old_font != lt->real_current_font)
3129 owner_->showState();
3134 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3136 time_t now_time_t = time(NULL);
3137 struct tm * now_tm = localtime(&now_time_t);
3138 setlocale(LC_TIME, "");
3140 if (!argument.empty())
3143 arg = lyxrc.date_insert_format;
3145 int const datetmp_len =
3146 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3148 LyXText * lt = bv_->getLyXText();
3150 for (int i = 0; i < datetmp_len; i++) {
3151 lt->insertChar(bv_, datetmp[i]);
3154 | BufferView::FITCUR
3155 | BufferView::CHANGE);
3158 lt->selection.cursor = lt->cursor;
3159 moveCursorUpdate(false);
3163 case LFUN_UNKNOWN_ACTION:
3164 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3175 void BufferView::Pimpl::newline()
3178 LyXText * lt = bv_->getLyXText();
3182 | BufferView::FITCUR);
3183 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3186 | BufferView::FITCUR
3187 | BufferView::CHANGE);
3192 void BufferView::Pimpl::hfill()
3195 LyXText * lt = bv_->getLyXText();
3199 | BufferView::FITCUR);
3200 lt->insertChar(bv_, Paragraph::META_HFILL);
3203 | BufferView::FITCUR
3204 | BufferView::CHANGE);
3209 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3213 update(lt, BufferView::SELECT|BufferView::FITCUR);
3214 InsetSpecialChar * new_inset =
3215 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3216 #ifdef WITH_WARNINGS
3217 #warning Why is this code different from specialChar() below? (JMarc)
3218 // the code in specialChar is a generic version of what used to exist
3219 // for other special chars. I did not merge this case because of the
3220 // call to updateInset(), but what does it do?
3222 if (!insertInset(new_inset))
3225 updateInset(new_inset, true);
3230 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3233 LyXText * lt = bv_->getLyXText();
3236 update(lt, BufferView::SELECT|BufferView::FITCUR);
3237 InsetSpecialChar * new_inset =
3238 new InsetSpecialChar(kind);
3239 insertInset(new_inset);
3240 // Ok, what happens here if we are unable to insert
3241 // the inset? Leak it?
3246 void BufferView::Pimpl::smartQuote()
3248 LyXText const * lt = bv_->getLyXText();
3249 Paragraph const * par = lt->cursor.par();
3250 pos_type pos = lt->cursor.pos();
3254 || (par->isInset(pos - 1)
3255 && par->getInset(pos - 1)->isSpace()))
3258 c = par->getChar(pos - 1);
3263 LyXLayout const & style = textclasslist.Style(
3264 bv_->buffer()->params.textclass, par->getLayout());
3266 if (style.pass_thru ||
3267 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3268 Dispatch(LFUN_SELFINSERT, "\"");
3272 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3274 if (insertInset(inset))
3281 // Open and lock an updatable inset
3282 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3284 LyXText * lt = bv_->getLyXText();
3288 if (!insertInset(new_inset)) {
3292 new_inset->edit(bv_, !behind);
3297 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3299 // if we are in a locking inset we should try to insert the
3300 // inset there otherwise this is a illegal function now
3301 if (bv_->theLockingInset()) {
3302 if (bv_->theLockingInset()->insetAllowed(inset))
3303 return bv_->theLockingInset()->insertInset(bv_, inset);
3307 // not quite sure if we want this...
3308 setCursorParUndo(bv_);
3311 beforeChange(bv_->text);
3312 if (!lout.empty()) {
3313 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3314 bv_->text->breakParagraph(bv_);
3315 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3317 if (bv_->text->cursor.par()->size()) {
3318 bv_->text->cursorLeft(bv_);
3320 bv_->text->breakParagraph(bv_);
3321 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3324 pair<bool, layout_type> lres =
3325 textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
3326 layout_type lay = 0;
3327 if (lres.first != false) {
3331 // layout not fount using default "Standard" (0)
3335 bv_->text->setLayout(bv_, lay);
3337 bv_->text->setParagraph(bv_, 0, 0,
3339 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3344 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3347 bv_->text->insertInset(bv_, inset);
3348 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3355 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3360 // first check for locking insets
3361 if (bv_->theLockingInset()) {
3362 if (bv_->theLockingInset() == inset) {
3363 if (bv_->text->updateInset(bv_, inset)) {
3366 buffer_->markDirty();
3371 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3372 if (bv_->text->updateInset(bv_,
3373 bv_->theLockingInset())) {
3376 buffer_->markDirty();
3384 // then check the current buffer
3387 update(bv_->text, BufferView::UPDATE);
3388 if (bv_->text->updateInset(bv_, inset)) {
3392 | BufferView::FITCUR
3393 | BufferView::CHANGE);
3395 update(bv_->text, SELECT);
3403 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3406 if (!available()) return;
3409 beforeChange(bv_->text);
3410 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3412 LyXCursor const & cursor = bv_->text->cursor;
3416 cursor.par()->isInset(cursor.pos())) {
3417 Inset const * inset = cursor.par()->getInset(cursor.pos());
3418 if (find(codes.begin(), codes.end(), inset->lyxCode())
3421 static_cast<InsetCommand const *>(inset)->getContents();
3425 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3426 if (bv_->text->cursor.pos()
3427 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3428 LyXCursor tmp = bv_->text->cursor;
3429 bv_->text->cursor.par(bv_->text->firstParagraph());
3430 bv_->text->cursor.pos(0);
3431 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3432 bv_->text->cursor = tmp;
3433 bv_->owner()->message(_("No more insets"));
3436 bv_->owner()->message(_("No more insets"));
3439 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3440 bv_->text->selection.cursor = bv_->text->cursor;
3444 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3446 gotoInset(vector<Inset::Code>(1, code), same_content);