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"
23 // added for Dispatch functions
26 #include "FloatList.h"
28 #include "ParagraphParameters.h"
29 #include "undo_funcs.h"
30 #include "lyxtextclasslist.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Alert.h"
34 #include "frontends/FileDialog.h"
36 #include "insets/insetbib.h"
37 #include "insets/insettext.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetnote.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetlist.h"
59 #include "insets/insetcaption.h"
60 #include "insets/insetfloatlist.h"
61 #include "insets/insetspecialchar.h"
63 #include "mathed/formulabase.h"
65 #include "support/LAssert.h"
66 #include "support/lstrings.h"
67 #include "support/filetools.h"
68 #include "support/lyxfunctional.h"
76 extern string current_layout;
88 using lyx::textclass_type;
90 /* the selection possible is needed, that only motion events are
91 * used, where the bottom press event was on the drawing area too */
92 bool selection_possible = false;
94 extern BufferList bufferlist;
95 extern char ascii_type;
97 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
102 const unsigned int saved_positions_num = 20;
107 XSync(fl_get_display(), 0);
111 void SetXtermCursor(Window win)
113 static Cursor cursor;
114 static bool cursor_undefined = true;
115 if (cursor_undefined) {
116 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
117 XFlush(fl_get_display());
118 cursor_undefined = false;
120 XDefineCursor(fl_get_display(), win, cursor);
121 XFlush(fl_get_display());
127 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
128 int xpos, int ypos, int width, int height)
129 : bv_(b), owner_(o), buffer_(0),
130 current_scrollbar_value(0), cursor_timeout(400),
131 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
135 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
136 workarea_.workAreaExpose
137 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
138 workarea_.workAreaEnter
139 .connect(slot(this, &BufferView::Pimpl::enterView));
140 workarea_.workAreaLeave
141 .connect(slot(this, &BufferView::Pimpl::leaveView));
142 workarea_.workAreaButtonPress
143 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
144 workarea_.workAreaButtonRelease
146 &BufferView::Pimpl::workAreaButtonRelease));
147 workarea_.workAreaMotionNotify
148 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
149 workarea_.workAreaDoubleClick
150 .connect(slot(this, &BufferView::Pimpl::doubleClick));
151 workarea_.workAreaTripleClick
152 .connect(slot(this, &BufferView::Pimpl::tripleClick));
153 workarea_.workAreaKeyPress
154 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
155 workarea_.selectionRequested
156 .connect(slot(this, &BufferView::Pimpl::selectionRequested));
157 workarea_.selectionLost
158 .connect(slot(this, &BufferView::Pimpl::selectionLost));
160 cursor_timeout.timeout.connect(slot(this,
161 &BufferView::Pimpl::cursorToggle));
162 cursor_timeout.start();
163 workarea_.setFocus();
164 saved_positions.resize(saved_positions_num);
168 Painter & BufferView::Pimpl::painter()
170 return workarea_.getPainter();
174 void BufferView::Pimpl::buffer(Buffer * b)
176 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
180 buffer_->delUser(bv_);
182 // Put the old text into the TextCache, but
183 // only if the buffer is still loaded.
184 // Also set the owner of the test to 0
185 // bv_->text->owner(0);
186 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
187 if (lyxerr.debugging())
188 textcache.show(lyxerr, "BufferView::buffer");
193 // Set current buffer
196 if (bufferlist.getState() == BufferList::CLOSING) return;
199 // screen is always deleted when the buffer is changed.
202 // If we are closing the buffer, use the first buffer as current
204 buffer_ = bufferlist.first();
208 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
209 buffer_->addUser(bv_);
210 // If we don't have a text object for this, we make one
211 if (bv_->text == 0) {
212 resizeCurrentBuffer();
217 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
218 owner_->updateMenubar();
219 owner_->updateToolbar();
220 // Similarly, buffer-dependent dialogs should be updated or
221 // hidden. This should go here because some dialogs (eg ToC)
222 // require bv_->text.
223 owner_->getDialogs()->updateBufferDependent(true);
227 lyxerr[Debug::INFO] << " No Buffer!" << endl;
228 owner_->updateMenubar();
229 owner_->updateToolbar();
230 owner_->getDialogs()->hideBufferDependent();
234 // Also remove all remaining text's from the testcache.
235 // (there should not be any!) (if there is any it is a
237 if (lyxerr.debugging())
238 textcache.show(lyxerr, "buffer delete all");
241 // should update layoutchoice even if we don't have a buffer.
242 owner_->updateLayoutChoice();
244 owner_->updateWindowTitle();
248 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
250 workarea_.resize(xpos, ypos, width, height);
251 update(bv_->text, SELECT);
256 void BufferView::Pimpl::resize()
259 resizeCurrentBuffer();
263 void BufferView::Pimpl::redraw()
265 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
270 bool BufferView::Pimpl::fitCursor()
272 lyx::Assert(screen_.get());
276 if (bv_->theLockingInset()) {
277 bv_->theLockingInset()->fitInsetCursor(bv_);
280 ret = screen_->fitCursor(bv_->text, bv_);
283 bv_->owner()->getDialogs()->updateParagraph();
290 void BufferView::Pimpl::redoCurrentBuffer()
292 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
293 if (buffer_ && bv_->text) {
295 owner_->updateLayoutChoice();
300 int BufferView::Pimpl::resizeCurrentBuffer()
302 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
305 Paragraph * selstartpar = 0;
306 Paragraph * selendpar = 0;
307 UpdatableInset * the_locking_inset = 0;
310 pos_type selstartpos = 0;
311 pos_type selendpos = 0;
312 bool selection = false;
313 bool mark_set = false;
315 owner_->prohibitInput();
317 owner_->message(_("Formatting document..."));
320 par = bv_->text->cursor.par();
321 pos = bv_->text->cursor.pos();
322 selstartpar = bv_->text->selection.start.par();
323 selstartpos = bv_->text->selection.start.pos();
324 selendpar = bv_->text->selection.end.par();
325 selendpos = bv_->text->selection.end.pos();
326 selection = bv_->text->selection.set();
327 mark_set = bv_->text->selection.mark();
328 the_locking_inset = bv_->theLockingInset();
330 bv_->text = new LyXText(bv_);
331 bv_->text->init(bv_);
332 buffer_->resizeInsets(bv_);
334 // See if we have a text in TextCache that fits
335 // the new buffer_ with the correct width.
336 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
338 if (lyxerr.debugging()) {
339 lyxerr << "Found a LyXText that fits:\n";
340 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
342 // Set the owner of the newly found text
343 // bv_->text->owner(bv_);
344 if (lyxerr.debugging())
345 textcache.show(lyxerr, "resizeCurrentBuffer");
347 bv_->text = new LyXText(bv_);
348 bv_->text->init(bv_);
349 //buffer_->resizeInsets(bv_);
356 bv_->text->selection.set(true);
357 // At this point just to avoid the Delete-Empty-Paragraph-
358 // Mechanism when setting the cursor.
359 bv_->text->selection.mark(mark_set);
361 bv_->text->setCursor(bv_, selstartpar, selstartpos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->setCursor(bv_, selendpar, selendpos);
364 bv_->text->setSelection(bv_);
365 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->setCursor(bv_, par, pos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->selection.set(false);
371 // remake the inset locking
372 bv_->theLockingInset(the_locking_inset);
375 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
377 // this will scroll the screen such that the cursor becomes visible
382 owner_->allowInput();
384 /// clear the "Formatting Document" message
391 void BufferView::Pimpl::updateScreen()
393 // Regenerate the screen.
394 screen_.reset(new LyXScreen(workarea_));
398 void BufferView::Pimpl::updateScrollbar()
400 /* If the text is smaller than the working area, the scrollbar
401 * maximum must be the working area height. No scrolling will
404 workarea_.setScrollbar(0, 1.0);
408 long const text_height = bv_->text->height;
409 long const work_height = workarea_.height();
411 if (text_height <= work_height) {
412 workarea_.setScrollbarBounds(0.0, 0.0);
413 current_scrollbar_value = bv_->text->first_y;
414 workarea_.setScrollbar(current_scrollbar_value, 1.0);
418 double const lineh = bv_->text->defaultHeight();
419 double const slider_size =
420 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
422 static long old_text_height;
423 static double old_lineh;
424 static double old_slider_size;
426 if (text_height != old_text_height) {
427 workarea_.setScrollbarBounds(0.0,
428 text_height - work_height);
429 old_text_height = text_height;
431 if (lineh != old_lineh) {
432 workarea_.setScrollbarIncrements(lineh);
435 if (current_scrollbar_value != bv_->text->first_y
436 || slider_size != old_slider_size) {
437 current_scrollbar_value = bv_->text->first_y;
438 workarea_.setScrollbar(current_scrollbar_value, slider_size);
439 old_slider_size = slider_size;
444 // Callback for scrollbar slider
445 void BufferView::Pimpl::scrollCB(double value)
447 if (!buffer_) return;
449 current_scrollbar_value = long(value);
451 if (current_scrollbar_value < 0)
452 current_scrollbar_value = 0;
457 screen_->draw(bv_->text, bv_, current_scrollbar_value);
459 if (!lyxrc.cursor_follows_scrollbar) {
464 LyXText * vbt = bv_->text;
466 int const height = vbt->defaultHeight();
467 int const first = static_cast<int>((bv_->text->first_y + height));
468 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
470 if (vbt->cursor.y() < first)
471 vbt->setCursorFromCoordinates(bv_, 0, first);
472 else if (vbt->cursor.y() > last)
473 vbt->setCursorFromCoordinates(bv_, 0, last);
479 int BufferView::Pimpl::scrollUp(long time)
481 if (!buffer_) return 0;
482 if (!screen_.get()) return 0;
484 double value = workarea_.getScrollbarValue();
486 if (value == 0) return 0;
488 float add_value = (bv_->text->defaultHeight()
489 + float(time) * float(time) * 0.125);
491 if (add_value > workarea_.height())
492 add_value = float(workarea_.height() -
493 bv_->text->defaultHeight());
500 workarea_.setScrollbarValue(value);
507 int BufferView::Pimpl::scrollDown(long time)
509 if (!buffer_) return 0;
510 if (!screen_.get()) return 0;
512 double value = workarea_.getScrollbarValue();
513 pair<float, float> p = workarea_.getScrollbarBounds();
514 double const max = p.second;
516 if (value == max) return 0;
518 float add_value = (bv_->text->defaultHeight()
519 + float(time) * float(time) * 0.125);
521 if (add_value > workarea_.height())
522 add_value = float(workarea_.height() -
523 bv_->text->defaultHeight());
530 workarea_.setScrollbarValue(value);
537 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
539 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
543 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
545 // Only use motion with button 1
546 if (!(state & Button1MotionMask))
549 if (!buffer_ || !screen_.get()) return;
551 // Check for inset locking
552 if (bv_->theLockingInset()) {
553 LyXCursor cursor = bv_->text->cursor;
554 LyXFont font = bv_->text->getFont(buffer_,
555 cursor.par(), cursor.pos());
556 int width = bv_->theLockingInset()->width(bv_, font);
557 int inset_x = font.isVisibleRightToLeft()
558 ? cursor.x() - width : cursor.x();
559 int start_x = inset_x + bv_->theLockingInset()->scroll();
560 bv_->theLockingInset()->
561 insetMotionNotify(bv_,
563 y - cursor.y() + bv_->text->first_y,
568 /* The test for not selection possible is needed, that only motion
569 events are used, where the bottom press event was on
570 the drawing area too */
571 if (!selection_possible)
574 screen_->hideCursor();
576 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
578 if (!bv_->text->selection.set())
579 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
581 bv_->text->setSelection(bv_);
582 screen_->toggleToggle(bv_->text, bv_);
588 // Single-click on work area
589 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
592 if (!buffer_ || !screen_.get())
595 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
597 // ok ok, this is a hack.
598 if (button == 4 || button == 5) {
601 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
604 scrollDown(lyxrc.wheel_jump);
609 // Middle button press pastes if we have a selection
610 // We do this here as if the selection was inside an inset
611 // it could get cleared on the unlocking of the inset so
612 // we have to check this first
613 bool paste_internally = false;
614 if (button == 2 && bv_->getLyXText()->selection.set()) {
615 owner_->getLyXFunc()->dispatch(LFUN_COPY);
616 paste_internally = true;
619 if (bv_->theLockingInset()) {
620 // We are in inset locking mode
622 /* Check whether the inset was hit. If not reset mode,
623 otherwise give the event to the inset */
624 if (inset_hit == bv_->theLockingInset()) {
625 bv_->theLockingInset()->
626 insetButtonPress(bv_,xpos, ypos,button);
629 bv_->unlockInset(bv_->theLockingInset());
634 selection_possible = true;
635 screen_->hideCursor();
637 int const screen_first = bv_->text->first_y;
639 // Clear the selection
640 screen_->toggleSelection(bv_->text, bv_);
641 bv_->text->clearSelection();
642 bv_->text->fullRebreak(bv_);
646 // Single left click in math inset?
647 if (isHighlyEditableInset(inset_hit)) {
648 // Highly editable inset, like math
649 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
650 selection_possible = false;
651 owner_->updateLayoutChoice();
652 owner_->message(inset->editMessage());
653 // IMO the inset has to be first in edit-mode and then we send the
654 // button press. (Jug 20020222)
655 inset->edit(bv_); //, xpos, ypos, button);
656 inset->insetButtonPress(bv_, xpos, ypos, button);
660 // Right click on a footnote flag opens float menu
662 selection_possible = false;
666 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
667 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
669 bv_->text->selection.cursor = bv_->text->cursor;
670 bv_->text->cursor.x_fix(bv_->text->cursor.x());
672 owner_->updateLayoutChoice();
674 selection_possible = false;
677 // Insert primary selection with middle mouse
678 // if there is a local selection in the current buffer,
681 if (paste_internally)
682 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
684 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
686 selection_possible = false;
692 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
698 LyXText * text = bv_->getLyXText();
700 if (text->bv_owner && bv_->theLockingInset())
703 if (screen_.get() && button == 1) {
704 if (text->bv_owner) {
705 screen_->hideCursor();
706 screen_->toggleSelection(text, bv_);
707 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
708 screen_->toggleSelection(text, bv_, false);
710 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
712 /* This will fit the cursor on the screen
714 update(text, BufferView::SELECT|BufferView::FITCUR);
719 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
725 LyXText * text = bv_->getLyXText();
727 if (text->bv_owner && bv_->theLockingInset())
730 if (screen_.get() && (button == 1)) {
731 if (text->bv_owner) {
732 screen_->hideCursor();
733 screen_->toggleSelection(text, bv_);
735 text->cursorHome(bv_);
736 text->selection.cursor = text->cursor;
737 text->cursorEnd(bv_);
738 text->setSelection(bv_);
739 if (text->bv_owner) {
740 screen_->toggleSelection(text, bv_, false);
742 /* This will fit the cursor on the screen
744 update(text, BufferView::SELECT|BufferView::FITCUR);
749 void BufferView::Pimpl::selectionRequested()
754 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
757 workarea_.putClipboard(sel);
762 void BufferView::Pimpl::selectionLost()
764 if (active() && available()) {
767 bv_->getLyXText()->clearSelection();
773 void BufferView::Pimpl::enterView()
775 if (active() && available()) {
776 SetXtermCursor(workarea_.getWin());
777 using_xterm_cursor = true;
782 void BufferView::Pimpl::leaveView()
784 if (using_xterm_cursor) {
785 XUndefineCursor(fl_get_display(), workarea_.getWin());
786 using_xterm_cursor = false;
791 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
794 if (!buffer_ || !screen_.get()) return;
796 // If we hit an inset, we have the inset coordinates in these
797 // and inset_hit points to the inset. If we do not hit an
798 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
799 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
801 if (bv_->theLockingInset()) {
802 // We are in inset locking mode.
804 /* LyX does a kind of work-area grabbing for insets.
805 Only a ButtonPress Event outside the inset will
806 force a insetUnlock. */
807 bv_->theLockingInset()->
808 insetButtonRelease(bv_, x, y, button);
812 selection_possible = false;
819 workarea_.haveSelection(bv_->getLyXText()->selection.set());
824 owner_->updateMenubar();
825 owner_->updateToolbar();
827 // Did we hit an editable inset?
829 selection_possible = false;
831 // if we reach this point with a selection, it
832 // must mean we are currently selecting.
833 // But we don't want to open the inset
834 // because that is annoying for the user.
835 // So just pretend we didn't hit it.
836 // this is OK because a "kosher" ButtonRelease
837 // will follow a ButtonPress that clears
839 // Note this also fixes selection drawing
840 // problems if we end up opening an inset
841 if (bv_->getLyXText()->selection.set())
844 // CHECK fix this proper in 0.13
845 // well, maybe 13.0 !!!!!!!!!
847 // Following a ref shouldn't issue
848 // a push on the undo-stack
849 // anylonger, now that we have
850 // keybindings for following
851 // references and returning from
852 // references. IMHO though, it
853 // should be the inset's own business
854 // to push or not push on the undo
855 // stack. They don't *have* to
856 // alter the document...
858 // ...or maybe the SetCursorParUndo()
859 // below isn't necessary at all anylonger?
860 if (inset_hit->lyxCode() == Inset::REF_CODE) {
861 setCursorParUndo(bv_);
864 owner_->message(inset_hit->editMessage());
866 if (isHighlyEditableInset(inset_hit)) {
867 // Highly editable inset, like math
868 UpdatableInset *inset = (UpdatableInset *)inset_hit;
869 inset->insetButtonRelease(bv_, x, y, button);
871 inset_hit->insetButtonRelease(bv_, x, y, button);
872 inset_hit->edit(bv_, x, y, button);
877 // Maybe we want to edit a bibitem ale970302
878 if (bv_->text->cursor.par()->bibkey && x < 20 +
879 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
880 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
887 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
888 LyXCursor const & cursor) const
890 Paragraph /*const*/ & par = *cursor.par();
891 pos_type const pos = cursor.pos();
893 lyx::Assert(par.getInset(pos));
895 Inset const & inset(*par.getInset(pos));
897 LyXFont const & font = text.getFont(buffer_, &par, pos);
899 int const width = inset.width(bv_, font);
900 int const inset_x = font.isVisibleRightToLeft()
901 ? (cursor.x() - width) : cursor.x();
904 inset_x + inset.scroll(),
906 cursor.y() - inset.ascent(bv_, font),
907 cursor.y() + inset.descent(bv_, font));
911 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
912 LyXCursor const & cursor,
913 int & x, int & y) const
915 pos_type const pos(cursor.pos());
916 Paragraph /*const*/ & par(*cursor.par());
918 if (pos >= par.size() || !par.isInset(pos)) {
922 Inset /*const*/ * inset = par.getInset(pos);
924 if (!isEditableInset(inset)) {
928 Box b(insetDimensions(text, cursor));
930 if (!b.contained(x, y)) {
931 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
932 << " box " << b << endl;
936 text.setCursor(bv_, &par, pos, true);
939 // The origin of an inset is on the baseline
940 y -= (text.cursor.y());
946 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
951 int y_tmp = y + text->first_y;
954 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
956 Inset * inset(checkInset(*text, cursor, x, y_tmp));
963 // look at previous position
965 if (cursor.pos() == 0) {
970 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
972 inset = checkInset(*text, cursor, x, y_tmp);
980 void BufferView::Pimpl::workAreaExpose()
982 static int work_area_width;
983 static unsigned int work_area_height;
985 bool const widthChange = workarea_.workWidth() != work_area_width;
986 bool const heightChange = workarea_.height() != work_area_height;
988 // update from work area
989 work_area_width = workarea_.workWidth();
990 work_area_height = workarea_.height();
993 // The visible LyXView need a resize
996 // Remove all texts from the textcache
997 // This is not _really_ what we want to do. What
998 // we really want to do is to delete in textcache
999 // that does not have a BufferView with matching
1000 // width, but as long as we have only one BufferView
1001 // deleting all gives the same result.
1002 if (lyxerr.debugging())
1003 textcache.show(lyxerr, "Expose delete all");
1005 buffer_->resizeInsets(bv_);
1006 } else if (heightChange) {
1007 // Rebuild image of current screen
1009 // fitCursor() ensures we don't jump back
1010 // to the start of the document on vertical
1014 // The main window size has changed, repaint most stuff
1016 } else if (screen_.get())
1017 screen_->redraw(bv_->text, bv_);
1019 // Grey box when we don't have a buffer
1020 workarea_.greyOut();
1023 // always make sure that the scrollbar is sane.
1025 owner_->updateLayoutChoice();
1030 void BufferView::Pimpl::update()
1032 if (screen_.get() &&
1033 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1035 LyXText::text_status st = bv_->text->status();
1036 screen_->update(bv_->text, bv_);
1038 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1039 if (bv_->text->fullRebreak(bv_)) {
1040 st = LyXText::NEED_MORE_REFRESH;
1041 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1042 bv_->text->cursor.pos());
1045 bv_->text->status(bv_, st);
1046 screen_->update(bv_->text, bv_);
1048 // do this here instead of in the screen::update because of
1050 bv_->text->status(bv_, LyXText::UNCHANGED);
1056 // Values used when calling update:
1058 // -2 - update, move sel_cursor if selection, fitcursor
1059 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1060 // 0 - update, move sel_cursor if selection, fitcursor
1061 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1062 // 3 - update, move sel_cursor if selection
1065 // a simple redraw of the parts that need refresh
1067 // move sel_cursor if selection -
1068 // the text's sel_cursor is moved if there is selection is progress
1071 // fitCursor() is called and the scrollbar updated
1074 // the buffer is marked dirty.
1083 // UPDATE_ONLY = UPDATE;
1084 // UPDATE_SELECT = UPDATE | SELECT;
1085 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1086 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1088 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1089 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1090 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1091 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1092 // update(3) -> update(1) -> update(1) -> update(SELECT)
1094 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1096 owner_->updateLayoutChoice();
1098 if (!text->selection.set() && (f & SELECT)) {
1099 text->selection.cursor = text->cursor;
1102 text->fullRebreak(bv_);
1104 if (text->inset_owner) {
1105 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1106 updateInset(text->inset_owner, false);
1116 buffer_->markDirty();
1121 // Callback for cursor timer
1122 void BufferView::Pimpl::cursorToggle()
1125 cursor_timeout.restart();
1129 if (!screen_.get()) {
1130 cursor_timeout.restart();
1135 extern void reapSpellchecker(void);
1138 if (!bv_->theLockingInset()) {
1139 screen_->cursorToggle(bv_);
1141 bv_->theLockingInset()->toggleInsetCursor(bv_);
1144 cursor_timeout.restart();
1148 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1150 if (!text->cursor.row()->previous())
1153 int y = text->first_y;
1154 Row * cursorrow = text->cursor.row();
1156 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1158 // This is to allow jumping over large insets
1159 if ((cursorrow == text->cursor.row()))
1160 text->cursorUp(bv_);
1162 if (text->inset_owner ||
1163 text->cursor.row()->height() < workarea_.height())
1164 screen_->draw(bv_->text, bv_,
1166 - text->cursor.row()->baseline()
1167 + text->cursor.row()->height()
1168 - workarea_.height() + 1);
1173 void BufferView::Pimpl::cursorNext(LyXText * text)
1175 if (!text->cursor.row()->next())
1178 int y = text->first_y + workarea_.height();
1179 // if (text->inset_owner)
1180 // y += bv_->text->first;
1181 text->getRowNearY(y);
1183 Row * cursorrow = text->cursor.row();
1184 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1186 // This is to allow jumping over large insets
1187 if ((cursorrow == bv_->text->cursor.row()))
1188 text->cursorDown(bv_);
1190 if (text->inset_owner ||
1191 text->cursor.row()->height() < workarea_.height())
1192 screen_->draw(bv_->text, bv_, text->cursor.y() -
1193 text->cursor.row()->baseline());
1198 bool BufferView::Pimpl::available() const
1200 if (buffer_ && bv_->text)
1206 void BufferView::Pimpl::beforeChange(LyXText * text)
1209 text->clearSelection();
1213 void BufferView::Pimpl::savePosition(unsigned int i)
1215 if (i >= saved_positions_num)
1217 saved_positions[i] = Position(buffer_->fileName(),
1218 bv_->text->cursor.par()->id(),
1219 bv_->text->cursor.pos());
1222 str << _("Saved bookmark") << ' ' << i;
1223 owner_->message(str.str().c_str());
1228 void BufferView::Pimpl::restorePosition(unsigned int i)
1230 if (i >= saved_positions_num)
1233 string const fname = saved_positions[i].filename;
1235 beforeChange(bv_->text);
1237 if (fname != buffer_->fileName()) {
1238 Buffer * b = bufferlist.exists(fname) ?
1239 bufferlist.getBuffer(fname) :
1240 bufferlist.loadLyXFile(fname); // don't ask, just load it
1241 if (b != 0) buffer(b);
1244 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1248 bv_->text->setCursor(bv_, par,
1249 min(par->size(), saved_positions[i].par_pos));
1251 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1254 str << _("Moved to bookmark") << ' ' << i;
1255 owner_->message(str.str().c_str());
1260 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1262 if (i >= saved_positions_num)
1265 return !saved_positions[i].filename.empty();
1269 void BufferView::Pimpl::setState()
1271 if (!lyxrc.rtl_support)
1274 LyXText * text = bv_->getLyXText();
1275 if (text->real_current_font.isRightToLeft()) {
1276 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1277 owner_->getIntl()->KeyMapSec();
1279 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1280 owner_->getIntl()->KeyMapPrim();
1285 void BufferView::Pimpl::insetSleep()
1287 if (bv_->theLockingInset() && !inset_slept) {
1288 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1289 bv_->theLockingInset()->insetUnlock(bv_);
1295 void BufferView::Pimpl::insetWakeup()
1297 if (bv_->theLockingInset() && inset_slept) {
1298 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1299 inset_slept = false;
1304 void BufferView::Pimpl::insetUnlock()
1306 if (bv_->theLockingInset()) {
1308 bv_->theLockingInset()->insetUnlock(bv_);
1309 bv_->theLockingInset(0);
1311 inset_slept = false;
1316 bool BufferView::Pimpl::focus() const
1318 return workarea_.hasFocus();
1322 void BufferView::Pimpl::focus(bool f)
1324 if (f) workarea_.setFocus();
1328 bool BufferView::Pimpl::active() const
1330 return workarea_.active();
1334 bool BufferView::Pimpl::belowMouse() const
1336 return workarea_.belowMouse();
1340 void BufferView::Pimpl::showCursor()
1342 if (screen_.get()) {
1343 if (bv_->theLockingInset())
1344 bv_->theLockingInset()->showInsetCursor(bv_);
1346 screen_->showCursor(bv_->text, bv_);
1351 void BufferView::Pimpl::hideCursor()
1353 if (screen_.get()) {
1354 if (!bv_->theLockingInset())
1355 // bv_->theLockingInset()->hideInsetCursor(bv_);
1357 screen_->hideCursor();
1362 void BufferView::Pimpl::toggleSelection(bool b)
1364 if (screen_.get()) {
1365 if (bv_->theLockingInset())
1366 bv_->theLockingInset()->toggleSelection(bv_, b);
1367 screen_->toggleSelection(bv_->text, bv_, b);
1372 void BufferView::Pimpl::toggleToggle()
1375 screen_->toggleToggle(bv_->text, bv_);
1379 void BufferView::Pimpl::center()
1381 beforeChange(bv_->text);
1382 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1383 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1385 screen_->draw(bv_->text, bv_, 0);
1387 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1392 void BufferView::Pimpl::pasteClipboard(bool asPara)
1397 screen_->hideCursor();
1398 beforeChange(bv_->text);
1400 string const clip(workarea_.getClipboard());
1406 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1408 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1410 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1414 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1416 workarea_.putClipboard(stuff);
1421 * Dispatch functions for actions which can be valid for BufferView->text
1422 * and/or InsetText->text!!!
1427 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1429 LyXText * lt = bv_->getLyXText();
1431 if (selecting || lt->selection.mark()) {
1432 lt->setSelection(bv_);
1436 updateInset(lt->inset_owner, false);
1439 update(lt, BufferView::SELECT|BufferView::FITCUR);
1443 /* ---> Everytime the cursor is moved, show the current font state. */
1444 // should this too me moved out of this func?
1445 //owner->showState();
1450 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1452 LyXCursor cursor = bv_->getLyXText()->cursor;
1453 Buffer::inset_iterator it =
1454 find_if(Buffer::inset_iterator(
1455 cursor.par(), cursor.pos()),
1456 buffer_->inset_iterator_end(),
1457 lyx::compare_memfun(&Inset::lyxCode, code));
1458 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1462 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1464 string filename = filen;
1466 if (filename.empty()) {
1467 // Launch a file browser
1468 string initpath = lyxrc.document_path;
1471 string const trypath = owner_->buffer()->filePath();
1472 // If directory is writeable, use this as default.
1473 if (IsDirWriteable(trypath))
1477 FileDialog fileDlg(bv_->owner(),
1478 _("Select LyX document to insert"),
1480 make_pair(string(_("Documents|#o#O")),
1481 string(lyxrc.document_path)),
1482 make_pair(string(_("Examples|#E#e")),
1483 string(AddPath(system_lyxdir, "examples"))));
1485 FileDialog::Result result =
1486 fileDlg.Select(initpath,
1487 _("*.lyx| LyX Documents (*.lyx)"));
1489 if (result.first == FileDialog::Later)
1492 filename = result.second;
1494 // check selected filename
1495 if (filename.empty()) {
1496 owner_->message(_("Canceled."));
1501 // get absolute path of file and add ".lyx" to the filename if
1503 filename = FileSearch(string(), filename, "lyx");
1505 string const disp_fn(MakeDisplayPath(filename));
1508 s1 << _("Inserting document") << ' '
1509 << disp_fn << " ...";
1510 owner_->message(s1.str().c_str());
1511 bool const res = bv_->insertLyXFile(filename);
1514 str << _("Document") << ' ' << disp_fn
1515 << ' ' << _("inserted.");
1516 owner_->message(str.str().c_str());
1519 str << _("Could not insert document") << ' '
1521 owner_->message(str.str().c_str());
1526 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1528 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1529 << action <<"] arg[" << argument << "]" << endl;
1532 // --- Misc -------------------------------------------
1536 LyXText * lt = bv_->getLyXText();
1537 lt->toggleAppendix(bv_);
1540 | BufferView::FITCUR
1541 | BufferView::CHANGE);
1546 case LFUN_TOC_INSERT:
1548 InsetCommandParams p;
1549 p.setCmdName("tableofcontents");
1550 Inset * inset = new InsetTOC(p);
1551 if (!insertInset(inset, "Standard"))
1556 case LFUN_SCROLL_INSET:
1557 // this is not handled here as this funktion is only aktive
1558 // if we have a locking_inset and that one is (or contains)
1562 case LFUN_INSET_GRAPHICS:
1564 Inset * new_inset = new InsetGraphics;
1565 if (!insertInset(new_inset)) {
1568 // this is need because you don't use a inset->Edit()
1569 updateInset(new_inset, true);
1570 new_inset->edit(bv_);
1580 case LFUN_PASTESELECTION:
1582 bool asPara = false;
1583 if (argument == "paragraph")
1585 pasteClipboard(asPara);
1597 case LFUN_LAYOUT_COPY:
1598 bv_->copyEnvironment();
1601 case LFUN_LAYOUT_PASTE:
1602 bv_->pasteEnvironment();
1606 case LFUN_GOTOERROR:
1607 gotoInset(Inset::ERROR_CODE, false);
1611 gotoInset(Inset::IGNORE_CODE, false);
1614 case LFUN_REFERENCE_GOTO:
1616 vector<Inset::Code> tmp;
1617 tmp.push_back(Inset::LABEL_CODE);
1618 tmp.push_back(Inset::REF_CODE);
1619 gotoInset(tmp, true);
1623 case LFUN_HYPHENATION:
1624 specialChar(InsetSpecialChar::HYPHENATION);
1627 case LFUN_LIGATURE_BREAK:
1628 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1632 specialChar(InsetSpecialChar::LDOTS);
1635 case LFUN_END_OF_SENTENCE:
1636 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1639 case LFUN_MENU_SEPARATOR:
1640 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1648 changeDepth(bv_, bv_->getLyXText(), 0);
1651 case LFUN_DEPTH_MIN:
1652 changeDepth(bv_, bv_->getLyXText(), -1);
1655 case LFUN_DEPTH_PLUS:
1656 changeDepth(bv_, bv_->getLyXText(), 1);
1660 owner_->getDialogs()->setUserFreeFont();
1663 case LFUN_FILE_INSERT:
1664 MenuInsertLyXFile(argument);
1667 case LFUN_FILE_INSERT_ASCII_PARA:
1668 InsertAsciiFile(bv_, argument, true);
1671 case LFUN_FILE_INSERT_ASCII:
1672 InsertAsciiFile(bv_, argument, false);
1677 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1678 << argument << endl;
1680 // Derive layout number from given argument (string)
1681 // and current buffer's textclass (number). */
1682 textclass_type tclass = buffer_->params.textclass;
1684 textclasslist[tclass].hasLayout(argument);
1685 string layout = argument;
1687 // If the entry is obsolete, use the new one instead.
1689 string const & obs = textclasslist[tclass][layout]
1696 owner_->getLyXFunc()->setErrorMessage(
1697 string(N_("Layout ")) + argument +
1702 if (current_layout != layout) {
1703 LyXText * lt = bv_->getLyXText();
1705 current_layout = layout;
1708 | BufferView::FITCUR);
1709 lt->setLayout(bv_, layout);
1710 owner_->setLayout(layout);
1713 | BufferView::FITCUR
1714 | BufferView::CHANGE);
1721 lang(bv_, argument);
1723 owner_->showState();
1728 owner_->showState();
1733 owner_->showState();
1738 owner_->showState();
1743 owner_->showState();
1748 owner_->showState();
1753 owner_->showState();
1758 owner_->showState();
1761 case LFUN_UNDERLINE:
1763 owner_->showState();
1766 case LFUN_FONT_SIZE:
1767 fontSize(bv_, argument);
1768 owner_->showState();
1771 case LFUN_FONT_STATE:
1772 owner_->getLyXFunc()->setMessage(currentState(bv_));
1775 case LFUN_UPCASE_WORD:
1777 LyXText * lt = bv_->getLyXText();
1781 | BufferView::FITCUR);
1782 lt->changeCase(bv_, LyXText::text_uppercase);
1783 if (lt->inset_owner)
1784 updateInset(lt->inset_owner, true);
1787 | BufferView::FITCUR
1788 | BufferView::CHANGE);
1792 case LFUN_LOWCASE_WORD:
1794 LyXText * lt = bv_->getLyXText();
1796 update(lt, BufferView::SELECT|BufferView::FITCUR);
1797 lt->changeCase(bv_, LyXText::text_lowercase);
1798 if (lt->inset_owner)
1799 updateInset(lt->inset_owner, true);
1802 | BufferView::FITCUR
1803 | BufferView::CHANGE);
1807 case LFUN_CAPITALIZE_WORD:
1809 LyXText * lt = bv_->getLyXText();
1811 update(lt, BufferView::SELECT|BufferView::FITCUR);
1812 lt->changeCase(bv_, LyXText::text_capitalization);
1813 if (lt->inset_owner)
1814 updateInset(lt->inset_owner, true);
1817 | BufferView::FITCUR
1818 | BufferView::CHANGE);
1822 case LFUN_TRANSPOSE_CHARS:
1824 LyXText * lt = bv_->getLyXText();
1826 update(lt, BufferView::SELECT|BufferView::FITCUR);
1827 lt->transposeChars(*bv_);
1828 if (lt->inset_owner)
1829 updateInset(lt->inset_owner, true);
1832 | BufferView::FITCUR
1833 | BufferView::CHANGE);
1838 case LFUN_INSERT_LABEL:
1839 MenuInsertLabel(bv_, argument);
1842 case LFUN_REF_INSERT:
1843 if (argument.empty()) {
1844 InsetCommandParams p("ref");
1845 owner_->getDialogs()->createRef(p.getAsString());
1847 InsetCommandParams p;
1848 p.setFromString(argument);
1850 InsetRef * inset = new InsetRef(p, *buffer_);
1851 if (!insertInset(inset))
1854 updateInset(inset, true);
1858 case LFUN_BOOKMARK_SAVE:
1859 savePosition(strToUnsignedInt(argument));
1862 case LFUN_BOOKMARK_GOTO:
1863 restorePosition(strToUnsignedInt(argument));
1868 string label(argument);
1869 if (label.empty()) {
1871 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1873 label = inset->getContents();
1878 if (!label.empty()) {
1879 //bv_->savePosition(0);
1880 if (!bv_->gotoLabel(label))
1881 Alert::alert(_("Error"),
1882 _("Couldn't find this label"),
1883 _("in current document."));
1888 // --- Cursor Movements -----------------------------
1891 LyXText * lt = bv_->getLyXText();
1893 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1894 if (!lt->selection.mark())
1896 update(lt, BufferView::SELECT|BufferView::FITCUR);
1898 lt->cursorLeft(bv_, false);
1899 if (lt->cursor.pos() < lt->cursor.par()->size()
1900 && lt->cursor.par()->isInset(lt->cursor.pos())
1901 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1902 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1903 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1905 tmpinset->edit(bv_, false);
1907 tmpinset->edit(bv_);
1911 lt->cursorRight(bv_, false);
1913 moveCursorUpdate(false);
1914 owner_->showState();
1920 // This is soooo ugly. Isn`t it possible to make
1921 // it simpler? (Lgb)
1922 LyXText * lt = bv_->getLyXText();
1923 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1924 if (!lt->selection.mark())
1926 update(lt, BufferView::SELECT|BufferView::FITCUR);
1927 LyXCursor const cur = lt->cursor;
1929 lt->cursorLeft(bv_, false);
1930 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1931 lt->cursor.pos() < lt->cursor.par()->size() &&
1932 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1933 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1934 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1935 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1937 tmpinset->edit(bv_);
1939 tmpinset->edit(bv_, false);
1943 lt->cursorRight(bv_, false);
1946 moveCursorUpdate(false);
1947 owner_->showState();
1953 LyXText * lt = bv_->getLyXText();
1955 if (!lt->selection.mark())
1957 update(lt, BufferView::UPDATE);
1960 moveCursorUpdate(false);
1961 owner_->showState();
1967 LyXText * lt = bv_->getLyXText();
1969 if (!lt->selection.mark())
1971 update(lt, BufferView::UPDATE);
1972 lt->cursorDown(bv_);
1974 moveCursorUpdate(false);
1975 owner_->showState();
1979 case LFUN_UP_PARAGRAPH:
1981 LyXText * lt = bv_->getLyXText();
1983 if (!lt->selection.mark())
1985 update(lt, BufferView::UPDATE);
1986 lt->cursorUpParagraph(bv_);
1988 moveCursorUpdate(false);
1989 owner_->showState();
1993 case LFUN_DOWN_PARAGRAPH:
1995 LyXText * lt = bv_->getLyXText();
1997 if (!lt->selection.mark())
1999 update(lt, BufferView::UPDATE);
2000 lt->cursorDownParagraph(bv_);
2002 moveCursorUpdate(false);
2003 owner_->showState();
2009 LyXText * lt = bv_->getLyXText();
2011 if (!lt->selection.mark())
2013 update(lt, BufferView::UPDATE);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2027 update(lt, BufferView::UPDATE);
2030 moveCursorUpdate(false);
2031 owner_->showState();
2037 LyXText * lt = bv_->getLyXText();
2039 if (!lt->selection.mark())
2041 update(lt, BufferView::SELECT|BufferView::FITCUR);
2042 lt->cursorHome(bv_);
2044 moveCursorUpdate(false);
2045 owner_->showState();
2051 LyXText * lt = bv_->getLyXText();
2053 if (!lt->selection.mark())
2056 BufferView::SELECT|BufferView::FITCUR);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2064 case LFUN_SHIFT_TAB:
2067 LyXText * lt = bv_->getLyXText();
2069 if (!lt->selection.mark())
2072 BufferView::SELECT|BufferView::FITCUR);
2075 moveCursorUpdate(false);
2076 owner_->showState();
2080 case LFUN_WORDRIGHT:
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->cursorLeftOneWord(bv_);
2090 lt->cursorRightOneWord(bv_);
2092 moveCursorUpdate(false);
2093 owner_->showState();
2099 LyXText * lt = bv_->getLyXText();
2101 if (!lt->selection.mark())
2103 update(lt, BufferView::SELECT|BufferView::FITCUR);
2104 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2105 lt->cursorRightOneWord(bv_);
2107 lt->cursorLeftOneWord(bv_);
2109 moveCursorUpdate(false);
2110 owner_->showState();
2114 case LFUN_BEGINNINGBUF:
2116 LyXText * lt = bv_->getLyXText();
2118 if (!lt->selection.mark())
2121 BufferView::SELECT|BufferView::FITCUR);
2124 moveCursorUpdate(false);
2125 owner_->showState();
2131 LyXText * lt = bv_->getLyXText();
2133 if (!lt->selection.mark())
2136 BufferView::SELECT|BufferView::FITCUR);
2137 lt->cursorBottom(bv_);
2139 moveCursorUpdate(false);
2140 owner_->showState();
2144 /* cursor selection ---------------------------- */
2147 LyXText * lt = bv_->getLyXText();
2150 BufferView::SELECT|BufferView::FITCUR);
2151 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2152 lt->cursorLeft(bv_);
2154 lt->cursorRight(bv_);
2156 moveCursorUpdate(true);
2157 owner_->showState();
2163 LyXText * lt = bv_->getLyXText();
2166 BufferView::SELECT|BufferView::FITCUR);
2167 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2168 lt->cursorRight(bv_);
2170 lt->cursorLeft(bv_);
2172 moveCursorUpdate(true);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2182 BufferView::SELECT|BufferView::FITCUR);
2185 moveCursorUpdate(true);
2186 owner_->showState();
2192 LyXText * lt = bv_->getLyXText();
2195 BufferView::SELECT|BufferView::FITCUR);
2196 lt->cursorDown(bv_);
2198 moveCursorUpdate(true);
2199 owner_->showState();
2203 case LFUN_UP_PARAGRAPHSEL:
2205 LyXText * lt = bv_->getLyXText();
2208 BufferView::SELECT|BufferView::FITCUR);
2209 lt->cursorUpParagraph(bv_);
2211 moveCursorUpdate(true);
2212 owner_->showState();
2216 case LFUN_DOWN_PARAGRAPHSEL:
2218 LyXText * lt = bv_->getLyXText();
2221 BufferView::SELECT|BufferView::FITCUR);
2222 lt->cursorDownParagraph(bv_);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 moveCursorUpdate(true);
2237 owner_->showState();
2243 LyXText * lt = bv_->getLyXText();
2245 update(lt, BufferView::SELECT|BufferView::FITCUR);
2248 moveCursorUpdate(true);
2249 owner_->showState();
2255 LyXText * lt = bv_->getLyXText();
2257 update(lt, BufferView::SELECT|BufferView::FITCUR);
2258 lt->cursorHome(bv_);
2260 moveCursorUpdate(true);
2261 owner_->showState();
2267 LyXText * lt = bv_->getLyXText();
2269 update(lt, BufferView::SELECT|BufferView::FITCUR);
2272 moveCursorUpdate(true);
2273 owner_->showState();
2277 case LFUN_WORDRIGHTSEL:
2279 LyXText * lt = bv_->getLyXText();
2281 update(lt, BufferView::SELECT|BufferView::FITCUR);
2282 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2283 lt->cursorLeftOneWord(bv_);
2285 lt->cursorRightOneWord(bv_);
2287 moveCursorUpdate(true);
2288 owner_->showState();
2292 case LFUN_WORDLEFTSEL:
2294 LyXText * lt = bv_->getLyXText();
2296 update(lt, BufferView::SELECT|BufferView::FITCUR);
2297 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2298 lt->cursorRightOneWord(bv_);
2300 lt->cursorLeftOneWord(bv_);
2302 moveCursorUpdate(true);
2303 owner_->showState();
2307 case LFUN_BEGINNINGBUFSEL:
2309 LyXText * lt = bv_->getLyXText();
2311 if (lt->inset_owner)
2313 update(lt, BufferView::SELECT|BufferView::FITCUR);
2316 moveCursorUpdate(true);
2317 owner_->showState();
2321 case LFUN_ENDBUFSEL:
2323 LyXText * lt = bv_->getLyXText();
2325 if (lt->inset_owner)
2328 BufferView::SELECT|BufferView::FITCUR);
2329 lt->cursorBottom(bv_);
2331 moveCursorUpdate(true);
2332 owner_->showState();
2336 // --- text changing commands ------------------------
2337 case LFUN_BREAKLINE:
2339 LyXText * lt = bv_->getLyXText();
2342 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2345 | BufferView::FITCUR
2346 | BufferView::CHANGE);
2347 moveCursorUpdate(false);
2351 case LFUN_PROTECTEDSPACE:
2353 LyXText * lt = bv_->getLyXText();
2355 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2357 if (style.free_spacing) {
2358 lt->insertChar(bv_, ' ');
2361 | BufferView::FITCUR
2362 | BufferView::CHANGE);
2364 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2366 moveCursorUpdate(false);
2372 LyXText * lt = bv_->getLyXText();
2374 if (lt->selection.mark()) {
2378 | BufferView::FITCUR);
2379 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2382 lt->selection.mark(true);
2385 | BufferView::FITCUR);
2386 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2388 lt->selection.cursor = lt->cursor;
2394 LyXText * lt = bv_->getLyXText();
2396 if (!lt->selection.set()) {
2398 lt->selection.cursor = lt->cursor;
2401 | BufferView::FITCUR
2402 | BufferView::CHANGE);
2403 // It is possible to make it a lot faster still
2404 // just comment out the line below...
2409 moveCursorUpdate(false);
2410 owner_->showState();
2415 case LFUN_DELETE_SKIP:
2417 LyXText * lt = bv_->getLyXText();
2419 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2421 LyXCursor cursor = lt->cursor;
2423 if (!lt->selection.set()) {
2424 if (cursor.pos() == cursor.par()->size()) {
2425 lt->cursorRight(bv_);
2426 cursor = lt->cursor;
2427 if (cursor.pos() == 0
2428 && !(cursor.par()->params().spaceTop()
2429 == VSpace (VSpace::NONE))) {
2432 cursor.par()->params().lineTop(),
2433 cursor.par()->params().lineBottom(),
2434 cursor.par()->params().pagebreakTop(),
2435 cursor.par()->params().pagebreakBottom(),
2436 VSpace(VSpace::NONE),
2437 cursor.par()->params().spaceBottom(),
2438 cursor.par()->params().spacing(),
2439 cursor.par()->params().align(),
2440 cursor.par()->params().labelWidthString(), 0);
2441 lt->cursorLeft(bv_);
2444 | BufferView::FITCUR
2445 | BufferView::CHANGE);
2447 lt->cursorLeft(bv_);
2449 lt->selection.cursor = lt->cursor;
2452 | BufferView::FITCUR
2453 | BufferView::CHANGE);
2457 lt->selection.cursor = lt->cursor;
2460 | BufferView::FITCUR
2461 | BufferView::CHANGE);
2469 /* -------> Delete word forward. */
2470 case LFUN_DELETE_WORD_FORWARD:
2471 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2472 bv_->getLyXText()->deleteWordForward(bv_);
2473 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2474 moveCursorUpdate(false);
2475 owner_->showState();
2478 /* -------> Delete word backward. */
2479 case LFUN_DELETE_WORD_BACKWARD:
2481 LyXText * lt = bv_->getLyXText();
2483 update(lt, BufferView::SELECT|BufferView::FITCUR);
2484 lt->deleteWordBackward(bv_);
2487 | BufferView::FITCUR
2488 | BufferView::CHANGE);
2489 moveCursorUpdate(false);
2490 owner_->showState();
2494 /* -------> Kill to end of line. */
2495 case LFUN_DELETE_LINE_FORWARD:
2497 LyXText * lt = bv_->getLyXText();
2499 update(lt, BufferView::SELECT|BufferView::FITCUR);
2500 lt->deleteLineForward(bv_);
2503 | BufferView::FITCUR
2504 | BufferView::CHANGE);
2505 moveCursorUpdate(false);
2509 /* -------> Set mark off. */
2512 LyXText * lt = bv_->getLyXText();
2515 update(lt, BufferView::SELECT|BufferView::FITCUR);
2516 lt->selection.cursor = lt->cursor;
2517 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2521 /* -------> Set mark on. */
2524 LyXText * lt = bv_->getLyXText();
2527 lt->selection.mark(true);
2528 update(lt, BufferView::SELECT|BufferView::FITCUR);
2529 lt->selection.cursor = lt->cursor;
2530 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2534 case LFUN_BACKSPACE:
2536 LyXText * lt = bv_->getLyXText();
2538 if (!lt->selection.set()) {
2539 if (owner_->getIntl()->getTrans().backspace()) {
2541 lt->selection.cursor = lt->cursor;
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2546 // It is possible to make it a lot faster still
2547 // just comment out the line below...
2553 owner_->showState();
2558 case LFUN_BACKSPACE_SKIP:
2560 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2561 LyXText * lt = bv_->getLyXText();
2563 LyXCursor cursor = lt->cursor;
2565 if (!lt->selection.set()) {
2566 if (cursor.pos() == 0
2567 && !(cursor.par()->params().spaceTop()
2568 == VSpace (VSpace::NONE))) {
2571 cursor.par()->params().lineTop(),
2572 cursor.par()->params().lineBottom(),
2573 cursor.par()->params().pagebreakTop(),
2574 cursor.par()->params().pagebreakBottom(),
2575 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2576 cursor.par()->params().spacing(),
2577 cursor.par()->params().align(),
2578 cursor.par()->params().labelWidthString(), 0);
2581 | BufferView::FITCUR
2582 | BufferView::CHANGE);
2585 lt->selection.cursor = cursor;
2588 | BufferView::FITCUR
2589 | BufferView::CHANGE);
2596 case LFUN_BREAKPARAGRAPH:
2598 LyXText * lt = bv_->getLyXText();
2601 lt->breakParagraph(bv_, 0);
2604 | BufferView::FITCUR
2605 | BufferView::CHANGE);
2606 lt->selection.cursor = lt->cursor;
2608 owner_->showState();
2612 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2614 LyXText * lt = bv_->getLyXText();
2617 lt->breakParagraph(bv_, 1);
2620 | BufferView::FITCUR
2621 | BufferView::CHANGE);
2622 lt->selection.cursor = lt->cursor;
2624 owner_->showState();
2628 case LFUN_BREAKPARAGRAPH_SKIP:
2630 // When at the beginning of a paragraph, remove
2631 // indentation and add a "defskip" at the top.
2632 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2633 LyXText * lt = bv_->getLyXText();
2635 LyXCursor cursor = lt->cursor;
2638 if (cursor.pos() == 0) {
2639 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2642 cursor.par()->params().lineTop(),
2643 cursor.par()->params().lineBottom(),
2644 cursor.par()->params().pagebreakTop(),
2645 cursor.par()->params().pagebreakBottom(),
2646 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2647 cursor.par()->params().spacing(),
2648 cursor.par()->params().align(),
2649 cursor.par()->params().labelWidthString(), 1);
2650 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2654 lt->breakParagraph(bv_, 0);
2655 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2660 | BufferView::FITCUR
2661 | BufferView::CHANGE);
2662 lt->selection.cursor = cursor;
2664 owner_->showState();
2668 case LFUN_PARAGRAPH_SPACING:
2670 LyXText * lt = bv_->getLyXText();
2672 Paragraph * par = lt->cursor.par();
2673 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2674 float cur_value = 1.0;
2675 if (cur_spacing == Spacing::Other) {
2676 cur_value = par->params().spacing().getValue();
2679 istringstream istr(argument.c_str());
2683 Spacing::Space new_spacing = cur_spacing;
2684 float new_value = cur_value;
2686 lyxerr << "Missing argument to `paragraph-spacing'"
2688 } else if (tmp == "single") {
2689 new_spacing = Spacing::Single;
2690 } else if (tmp == "onehalf") {
2691 new_spacing = Spacing::Onehalf;
2692 } else if (tmp == "double") {
2693 new_spacing = Spacing::Double;
2694 } else if (tmp == "other") {
2695 new_spacing = Spacing::Other;
2698 lyxerr << "new_value = " << tmpval << endl;
2701 } else if (tmp == "default") {
2702 new_spacing = Spacing::Default;
2704 lyxerr << _("Unknown spacing argument: ")
2705 << argument << endl;
2707 if (cur_spacing != new_spacing || cur_value != new_value) {
2708 par->params().spacing(Spacing(new_spacing, new_value));
2709 lt->redoParagraph(bv_);
2712 | BufferView::FITCUR
2713 | BufferView::CHANGE);
2718 case LFUN_INSET_TOGGLE:
2720 LyXText * lt = bv_->getLyXText();
2723 update(lt, BufferView::SELECT|BufferView::FITCUR);
2724 lt->toggleInset(bv_);
2725 update(lt, BufferView::SELECT|BufferView::FITCUR);
2737 InsetCommandParams p;
2738 if (action == LFUN_HTMLURL)
2739 p.setCmdName("htmlurl");
2741 p.setCmdName("url");
2742 owner_->getDialogs()->createUrl(p.getAsString());
2746 case LFUN_INSERT_URL:
2748 InsetCommandParams p;
2749 p.setFromString(argument);
2751 InsetUrl * inset = new InsetUrl(p);
2752 if (!insertInset(inset))
2755 updateInset(inset, true);
2759 case LFUN_INSET_ERT:
2760 insertAndEditInset(new InsetERT(buffer_->params));
2763 case LFUN_INSET_EXTERNAL:
2764 insertAndEditInset(new InsetExternal);
2767 case LFUN_INSET_FOOTNOTE:
2768 insertAndEditInset(new InsetFoot(buffer_->params));
2771 case LFUN_INSET_MARGINAL:
2772 insertAndEditInset(new InsetMarginal(buffer_->params));
2775 case LFUN_INSET_MINIPAGE:
2776 insertAndEditInset(new InsetMinipage(buffer_->params));
2779 case LFUN_INSERT_NOTE:
2780 insertAndEditInset(new InsetNote(buffer_->params));
2783 case LFUN_INSET_FLOAT:
2784 // check if the float type exist
2785 if (floatList.typeExist(argument)) {
2786 insertAndEditInset(new InsetFloat(buffer_->params,
2789 lyxerr << "Non-existent float type: "
2790 << argument << endl;
2794 case LFUN_INSET_WIDE_FLOAT:
2796 // check if the float type exist
2797 if (floatList.typeExist(argument)) {
2798 InsetFloat * new_inset =
2799 new InsetFloat(buffer_->params, argument);
2800 new_inset->wide(true);
2801 if (insertInset(new_inset))
2802 new_inset->edit(bv_);
2806 lyxerr << "Non-existent float type: "
2807 << argument << endl;
2814 case LFUN_INSET_LIST:
2815 insertAndEditInset(new InsetList);
2818 case LFUN_INSET_THEOREM:
2819 insertAndEditInset(new InsetTheorem);
2823 case LFUN_INSET_CAPTION:
2825 // Do we have a locking inset...
2826 if (bv_->theLockingInset()) {
2827 lyxerr << "Locking inset code: "
2828 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2829 InsetCaption * new_inset =
2830 new InsetCaption(buffer_->params);
2831 new_inset->setOwner(bv_->theLockingInset());
2832 new_inset->setAutoBreakRows(true);
2833 new_inset->setDrawFrame(0, InsetText::LOCKED);
2834 new_inset->setFrameColor(0, LColor::captionframe);
2835 if (insertInset(new_inset))
2836 new_inset->edit(bv_);
2843 case LFUN_INSET_TABULAR:
2847 if (!argument.empty())
2848 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2849 InsetTabular * new_inset =
2850 new InsetTabular(*buffer_, r, c);
2852 bv_->getLyXText()->real_current_font.isRightToLeft();
2853 if (!open_new_inset(new_inset, rtl))
2858 // --- lyxserver commands ----------------------------
2860 case LFUN_CHARATCURSOR:
2862 pos_type pos = bv_->getLyXText()->cursor.pos();
2863 if (pos < bv_->getLyXText()->cursor.par()->size())
2864 owner_->getLyXFunc()->setMessage(
2865 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2867 owner_->getLyXFunc()->setMessage("EOF");
2872 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2874 + tostr(bv_->getLyXText()->cursor.y()));
2881 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2882 lyxerr << "SETXY: Could not parse coordinates in '"
2883 << argument << std::endl;
2885 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2889 case LFUN_GETLAYOUT:
2890 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2895 LyXFont & font = bv_->getLyXText()->current_font;
2896 if (font.shape() == LyXFont::ITALIC_SHAPE)
2897 owner_->getLyXFunc()->setMessage("E");
2898 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2899 owner_->getLyXFunc()->setMessage("N");
2901 owner_->getLyXFunc()->setMessage("0");
2906 // --- accented characters ---------------------------
2909 case LFUN_CIRCUMFLEX:
2919 case LFUN_SPECIAL_CARON:
2922 case LFUN_HUNG_UMLAUT:
2925 if (argument.empty()) {
2927 owner_->getLyXFunc()->handleKeyFunc(action);
2929 owner_->getLyXFunc()->handleKeyFunc(action);
2930 owner_->getIntl()->getTrans()
2931 .TranslateAndInsert(argument[0], bv_->getLyXText());
2932 update(bv_->getLyXText(),
2934 | BufferView::FITCUR
2935 | BufferView::CHANGE);
2939 case LFUN_MATH_MACRO:
2940 mathDispatchMathMacro(bv_, argument);
2943 case LFUN_MATH_DELIM:
2944 mathDispatchMathDelim(bv_, argument);
2947 case LFUN_INSERT_MATRIX:
2948 mathDispatchInsertMatrix(bv_, argument);
2951 case LFUN_INSERT_MATH:
2952 mathDispatchInsertMath(bv_, argument);
2955 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2956 mathDispatchMathImportSelection(bv_, argument);
2959 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2960 mathDispatchMathDisplay(bv_, argument);
2963 case LFUN_MATH_MODE: // Open or create an inlined math inset
2964 mathDispatchMathMode(bv_, argument);
2967 case LFUN_GREEK: // Insert a single greek letter
2968 mathDispatchGreek(bv_, argument);
2971 case LFUN_CITATION_INSERT:
2973 InsetCommandParams p;
2974 p.setFromString(argument);
2976 InsetCitation * inset = new InsetCitation(p);
2977 if (!insertInset(inset))
2980 updateInset(inset, true);
2984 case LFUN_INSERT_BIBTEX:
2986 // ale970405+lasgoutt970425
2987 // The argument can be up to two tokens separated
2988 // by a space. The first one is the bibstyle.
2989 string const db = token(argument, ' ', 0);
2990 string const bibstyle = token(argument, ' ', 1);
2992 InsetCommandParams p("BibTeX", db, bibstyle);
2993 InsetBibtex * inset = new InsetBibtex(p);
2995 if (insertInset(inset)) {
2996 if (argument.empty())
3003 // BibTeX data bases
3004 case LFUN_BIBDB_ADD:
3006 InsetBibtex * inset =
3007 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3009 inset->addDatabase(argument);
3014 case LFUN_BIBDB_DEL:
3016 InsetBibtex * inset =
3017 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3019 inset->delDatabase(argument);
3024 case LFUN_BIBTEX_STYLE:
3026 InsetBibtex * inset =
3027 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3029 inset->setOptions(argument);
3034 case LFUN_INDEX_CREATE:
3036 InsetCommandParams p("index");
3037 if (argument.empty()) {
3038 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3039 p.setContents(idxstring);
3041 p.setContents(argument);
3044 owner_->getDialogs()->createIndex(p.getAsString());
3048 case LFUN_INDEX_INSERT:
3050 InsetCommandParams p;
3051 p.setFromString(argument);
3052 InsetIndex * inset = new InsetIndex(p);
3054 if (!insertInset(inset))
3057 updateInset(inset, true);
3061 case LFUN_INDEX_INSERT_LAST:
3063 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3064 if (!idxstring.empty()) {
3065 owner_->message(_("Word `")
3066 + idxstring + _(("' indexed.")));
3067 InsetCommandParams p("index", idxstring);
3068 InsetIndex * inset = new InsetIndex(p);
3070 if (!insertInset(inset))
3073 updateInset(inset, true);
3078 case LFUN_INDEX_PRINT:
3080 InsetCommandParams p("printindex");
3081 Inset * inset = new InsetPrintIndex(p);
3082 if (!insertInset(inset, "Standard"))
3087 case LFUN_PARENTINSERT:
3089 lyxerr << "arg " << argument << endl;
3090 InsetCommandParams p("lyxparent", argument);
3091 Inset * inset = new InsetParent(p, *buffer_);
3092 if (!insertInset(inset, "Standard"))
3098 case LFUN_CHILD_INSERT:
3100 InsetInclude::Params p;
3101 p.cparams.setFromString(argument);
3102 p.masterFilename_ = buffer_->fileName();
3104 InsetInclude * inset = new InsetInclude(p);
3105 if (!insertInset(inset))
3108 updateInset(inset, true);
3109 bv_->owner()->getDialogs()->showInclude(inset);
3114 case LFUN_FLOAT_LIST:
3116 // We should check the argument for validity. (Lgb)
3117 Inset * inset = new InsetFloatList(argument);
3118 if (!insertInset(inset, "Standard"))
3123 case LFUN_THESAURUS_ENTRY:
3125 string arg = argument;
3128 arg = bv_->getLyXText()->selectionAsString(buffer_,
3132 if (arg.size() > 100 || arg.empty()) {
3133 // Get word or selection
3134 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3135 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3136 // FIXME: where is getLyXText()->unselect(bv_) ?
3140 bv_->owner()->getDialogs()->showThesaurus(arg);
3144 case LFUN_SELFINSERT:
3146 if (argument.empty()) break;
3148 /* Automatically delete the currently selected
3149 * text and replace it with what is being
3150 * typed in now. Depends on lyxrc settings
3151 * "auto_region_delete", which defaults to
3154 LyXText * lt = bv_->getLyXText();
3156 if (lyxrc.auto_region_delete) {
3157 if (lt->selection.set()) {
3158 lt->cutSelection(bv_, false, false);
3161 | BufferView::FITCUR
3162 | BufferView::CHANGE);
3167 LyXFont const old_font(lt->real_current_font);
3169 string::const_iterator cit = argument.begin();
3170 string::const_iterator end = argument.end();
3171 for (; cit != end; ++cit) {
3172 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3177 | BufferView::FITCUR
3178 | BufferView::CHANGE);
3180 lt->selection.cursor = lt->cursor;
3181 moveCursorUpdate(false);
3183 // real_current_font.number can change so we need to
3184 // update the minibuffer
3185 if (old_font != lt->real_current_font)
3186 owner_->showState();
3191 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3193 time_t now_time_t = time(NULL);
3194 struct tm * now_tm = localtime(&now_time_t);
3195 setlocale(LC_TIME, "");
3197 if (!argument.empty())
3200 arg = lyxrc.date_insert_format;
3202 int const datetmp_len =
3203 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3205 LyXText * lt = bv_->getLyXText();
3207 for (int i = 0; i < datetmp_len; i++) {
3208 lt->insertChar(bv_, datetmp[i]);
3211 | BufferView::FITCUR
3212 | BufferView::CHANGE);
3215 lt->selection.cursor = lt->cursor;
3216 moveCursorUpdate(false);
3220 case LFUN_UNKNOWN_ACTION:
3221 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3232 void BufferView::Pimpl::newline()
3235 LyXText * lt = bv_->getLyXText();
3239 | BufferView::FITCUR);
3240 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3243 | BufferView::FITCUR
3244 | BufferView::CHANGE);
3249 void BufferView::Pimpl::hfill()
3252 LyXText * lt = bv_->getLyXText();
3256 | BufferView::FITCUR);
3257 lt->insertChar(bv_, Paragraph::META_HFILL);
3260 | BufferView::FITCUR
3261 | BufferView::CHANGE);
3266 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3269 LyXText * lt = bv_->getLyXText();
3272 update(lt, BufferView::SELECT|BufferView::FITCUR);
3273 InsetSpecialChar * new_inset =
3274 new InsetSpecialChar(kind);
3275 if (!insertInset(new_inset))
3278 updateInset(new_inset, true);
3283 void BufferView::Pimpl::smartQuote()
3285 LyXText const * lt = bv_->getLyXText();
3286 Paragraph const * par = lt->cursor.par();
3287 pos_type pos = lt->cursor.pos();
3291 || (par->isInset(pos - 1)
3292 && par->getInset(pos - 1)->isSpace()))
3295 c = par->getChar(pos - 1);
3300 LyXLayout const & style =
3301 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3303 if (style.pass_thru ||
3304 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3305 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3309 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3311 if (insertInset(inset))
3318 // Open and lock an updatable inset
3319 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3321 LyXText * lt = bv_->getLyXText();
3325 if (!insertInset(new_inset)) {
3329 new_inset->edit(bv_, !behind);
3334 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3336 // if we are in a locking inset we should try to insert the
3337 // inset there otherwise this is a illegal function now
3338 if (bv_->theLockingInset()) {
3339 if (bv_->theLockingInset()->insetAllowed(inset))
3340 return bv_->theLockingInset()->insertInset(bv_, inset);
3344 // not quite sure if we want this...
3345 setCursorParUndo(bv_);
3348 beforeChange(bv_->text);
3349 if (!lout.empty()) {
3350 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3351 bv_->text->breakParagraph(bv_);
3352 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3354 if (bv_->text->cursor.par()->size()) {
3355 bv_->text->cursorLeft(bv_);
3357 bv_->text->breakParagraph(bv_);
3358 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3362 LyXTextClass const & tclass =
3363 textclasslist[buffer_->params.textclass];
3364 bool hasLayout = tclass.hasLayout(lres);
3365 string lay = tclass.defaultLayoutName();
3367 if (hasLayout != false) {
3371 // layout not fount using default
3372 lay = tclass.defaultLayoutName();
3375 bv_->text->setLayout(bv_, lay);
3377 bv_->text->setParagraph(bv_, 0, 0,
3379 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3384 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3387 bv_->text->insertInset(bv_, inset);
3388 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3395 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3397 if (!inset || !available())
3400 // first check for locking insets
3401 if (bv_->theLockingInset()) {
3402 if (bv_->theLockingInset() == inset) {
3403 if (bv_->text->updateInset(bv_, inset)) {
3406 buffer_->markDirty();
3411 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3412 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3415 buffer_->markDirty();
3423 // then check if the inset is a top_level inset (has no owner)
3424 // if yes do the update as always otherwise we have to update the
3425 // toplevel inset where this inset is inside
3426 Inset * tl_inset = inset;
3427 while(tl_inset->owner())
3428 tl_inset = tl_inset->owner();
3430 if (tl_inset == inset) {
3431 update(bv_->text, BufferView::UPDATE);
3432 if (bv_->text->updateInset(bv_, inset)) {
3436 | BufferView::FITCUR
3437 | BufferView::CHANGE);
3439 update(bv_->text, SELECT);
3443 } else if (static_cast<UpdatableInset *>(tl_inset)
3444 ->updateInsetInInset(bv_, inset))
3446 if (bv_->text->updateInset(bv_, tl_inset)) {
3454 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3457 if (!available()) return;
3460 beforeChange(bv_->text);
3461 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3463 LyXCursor const & cursor = bv_->text->cursor;
3467 cursor.par()->isInset(cursor.pos())) {
3468 Inset const * inset = cursor.par()->getInset(cursor.pos());
3469 if (find(codes.begin(), codes.end(), inset->lyxCode())
3472 static_cast<InsetCommand const *>(inset)->getContents();
3476 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3477 if (bv_->text->cursor.pos()
3478 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3479 LyXCursor tmp = bv_->text->cursor;
3480 bv_->text->cursor.par(bv_->text->ownerParagraph());
3481 bv_->text->cursor.pos(0);
3482 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3483 bv_->text->cursor = tmp;
3484 bv_->owner()->message(_("No more insets"));
3487 bv_->owner()->message(_("No more insets"));
3490 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3491 bv_->text->selection.cursor = bv_->text->cursor;
3495 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3497 gotoInset(vector<Inset::Code>(1, code), same_content);