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;
314 bool text_found = false;
316 owner_->prohibitInput();
318 owner_->message(_("Formatting document..."));
321 par = bv_->text->cursor.par();
322 pos = bv_->text->cursor.pos();
323 selstartpar = bv_->text->selection.start.par();
324 selstartpos = bv_->text->selection.start.pos();
325 selendpar = bv_->text->selection.end.par();
326 selendpos = bv_->text->selection.end.pos();
327 selection = bv_->text->selection.set();
328 mark_set = bv_->text->selection.mark();
329 the_locking_inset = bv_->theLockingInset();
331 bv_->text = new LyXText(bv_);
332 bv_->text->init(bv_);
334 // See if we have a text in TextCache that fits
335 // the new buffer_ with the correct width.
336 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
339 if (lyxerr.debugging()) {
340 lyxerr << "Found a LyXText that fits:\n";
341 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
343 // Set the owner of the newly found text
344 // bv_->text->owner(bv_);
345 if (lyxerr.debugging())
346 textcache.show(lyxerr, "resizeCurrentBuffer");
348 bv_->text = new LyXText(bv_);
349 bv_->text->init(bv_);
355 bv_->text->selection.set(true);
356 /* at this point just to avoid the Delete-Empty-Paragraph
357 * Mechanism when setting the cursor */
358 bv_->text->selection.mark(mark_set);
360 bv_->text->setCursor(bv_, selstartpar, selstartpos);
361 bv_->text->selection.cursor = bv_->text->cursor;
362 bv_->text->setCursor(bv_, selendpar, selendpos);
363 bv_->text->setSelection(bv_);
364 bv_->text->setCursor(bv_, par, pos);
366 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->selection.cursor = bv_->text->cursor;
368 bv_->text->selection.set(false);
370 // remake the inset locking
371 bv_->theLockingInset(the_locking_inset);
373 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
374 // please tell me WHY the heck you deactivated this code, whoever
375 // 'you' are (Jug 20020311)
378 buffer_->resizeInsets(bv_);
380 // this will scroll the screen such that the cursor becomes visible
385 owner_->allowInput();
387 /// clear the "Formatting Document" message
394 void BufferView::Pimpl::updateScreen()
396 // Regenerate the screen.
397 screen_.reset(new LyXScreen(workarea_));
401 void BufferView::Pimpl::updateScrollbar()
403 /* If the text is smaller than the working area, the scrollbar
404 * maximum must be the working area height. No scrolling will
407 workarea_.setScrollbar(0, 1.0);
411 long const text_height = bv_->text->height;
412 long const work_height = workarea_.height();
414 if (text_height <= work_height) {
415 workarea_.setScrollbarBounds(0.0, 0.0);
416 current_scrollbar_value = bv_->text->first_y;
417 workarea_.setScrollbar(current_scrollbar_value, 1.0);
421 double const lineh = bv_->text->defaultHeight();
422 double const slider_size =
423 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
425 static long old_text_height;
426 static double old_lineh;
427 static double old_slider_size;
429 if (text_height != old_text_height) {
430 workarea_.setScrollbarBounds(0.0,
431 text_height - work_height);
432 old_text_height = text_height;
434 if (lineh != old_lineh) {
435 workarea_.setScrollbarIncrements(lineh);
438 if (current_scrollbar_value != bv_->text->first_y
439 || slider_size != old_slider_size) {
440 current_scrollbar_value = bv_->text->first_y;
441 workarea_.setScrollbar(current_scrollbar_value, slider_size);
442 old_slider_size = slider_size;
447 // Callback for scrollbar slider
448 void BufferView::Pimpl::scrollCB(double value)
450 if (!buffer_) return;
452 current_scrollbar_value = long(value);
454 if (current_scrollbar_value < 0)
455 current_scrollbar_value = 0;
460 screen_->draw(bv_->text, bv_, current_scrollbar_value);
462 if (!lyxrc.cursor_follows_scrollbar) {
467 LyXText * vbt = bv_->text;
469 int const height = vbt->defaultHeight();
470 int const first = static_cast<int>((bv_->text->first_y + height));
471 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
473 if (vbt->cursor.y() < first)
474 vbt->setCursorFromCoordinates(bv_, 0, first);
475 else if (vbt->cursor.y() > last)
476 vbt->setCursorFromCoordinates(bv_, 0, last);
482 int BufferView::Pimpl::scrollUp(long time)
484 if (!buffer_) return 0;
485 if (!screen_.get()) return 0;
487 double value = workarea_.getScrollbarValue();
489 if (value == 0) return 0;
491 float add_value = (bv_->text->defaultHeight()
492 + float(time) * float(time) * 0.125);
494 if (add_value > workarea_.height())
495 add_value = float(workarea_.height() -
496 bv_->text->defaultHeight());
503 workarea_.setScrollbarValue(value);
510 int BufferView::Pimpl::scrollDown(long time)
512 if (!buffer_) return 0;
513 if (!screen_.get()) return 0;
515 double value = workarea_.getScrollbarValue();
516 pair<float, float> p = workarea_.getScrollbarBounds();
517 double const max = p.second;
519 if (value == max) return 0;
521 float add_value = (bv_->text->defaultHeight()
522 + float(time) * float(time) * 0.125);
524 if (add_value > workarea_.height())
525 add_value = float(workarea_.height() -
526 bv_->text->defaultHeight());
533 workarea_.setScrollbarValue(value);
540 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
542 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
546 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
548 // Only use motion with button 1
549 if (!(state & Button1MotionMask))
552 if (!buffer_ || !screen_.get()) return;
554 // Check for inset locking
555 if (bv_->theLockingInset()) {
556 LyXCursor cursor = bv_->text->cursor;
557 LyXFont font = bv_->text->getFont(buffer_,
558 cursor.par(), cursor.pos());
559 int width = bv_->theLockingInset()->width(bv_, font);
560 int inset_x = font.isVisibleRightToLeft()
561 ? cursor.x() - width : cursor.x();
562 int start_x = inset_x + bv_->theLockingInset()->scroll();
563 bv_->theLockingInset()->
564 insetMotionNotify(bv_,
566 y - cursor.y() + bv_->text->first_y,
571 /* The test for not selection possible is needed, that only motion
572 events are used, where the bottom press event was on
573 the drawing area too */
574 if (!selection_possible)
577 screen_->hideCursor();
579 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
581 if (!bv_->text->selection.set())
582 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
584 bv_->text->setSelection(bv_);
585 screen_->toggleToggle(bv_->text, bv_);
591 // Single-click on work area
592 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
595 if (!buffer_ || !screen_.get()) return;
597 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
599 // ok ok, this is a hack.
600 if (button == 4 || button == 5) {
603 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
606 scrollDown(lyxrc.wheel_jump);
611 if (bv_->theLockingInset()) {
612 // We are in inset locking mode
614 /* Check whether the inset was hit. If not reset mode,
615 otherwise give the event to the inset */
616 if (inset_hit == bv_->theLockingInset()) {
617 bv_->theLockingInset()->
618 insetButtonPress(bv_,xpos, ypos,button);
621 bv_->unlockInset(bv_->theLockingInset());
626 selection_possible = true;
627 screen_->hideCursor();
629 int const screen_first = bv_->text->first_y;
631 // Middle button press pastes if we have a selection
632 bool paste_internally = false;
634 && bv_->text->selection.set()) {
635 owner_->getLyXFunc()->dispatch(LFUN_COPY);
636 paste_internally = true;
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 } else if (heightChange) {
1006 // Rebuild image of current screen
1008 // fitCursor() ensures we don't jump back
1009 // to the start of the document on vertical
1013 // The main window size has changed, repaint most stuff
1015 } else if (screen_.get())
1016 screen_->redraw(bv_->text, bv_);
1018 // Grey box when we don't have a buffer
1019 workarea_.greyOut();
1022 // always make sure that the scrollbar is sane.
1024 owner_->updateLayoutChoice();
1029 void BufferView::Pimpl::update()
1031 if (screen_.get() &&
1032 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1034 LyXText::text_status st = bv_->text->status();
1035 screen_->update(bv_->text, bv_);
1037 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1038 if (bv_->text->fullRebreak(bv_)) {
1039 st = LyXText::NEED_MORE_REFRESH;
1040 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1041 bv_->text->cursor.pos());
1044 bv_->text->status(bv_, st);
1045 screen_->update(bv_->text, bv_);
1047 // do this here instead of in the screen::update because of
1049 bv_->text->status(bv_, LyXText::UNCHANGED);
1055 // Values used when calling update:
1057 // -2 - update, move sel_cursor if selection, fitcursor
1058 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1059 // 0 - update, move sel_cursor if selection, fitcursor
1060 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1061 // 3 - update, move sel_cursor if selection
1064 // a simple redraw of the parts that need refresh
1066 // move sel_cursor if selection -
1067 // the text's sel_cursor is moved if there is selection is progress
1070 // fitCursor() is called and the scrollbar updated
1073 // the buffer is marked dirty.
1082 // UPDATE_ONLY = UPDATE;
1083 // UPDATE_SELECT = UPDATE | SELECT;
1084 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1085 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1087 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1088 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1089 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1090 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1091 // update(3) -> update(1) -> update(1) -> update(SELECT)
1093 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1095 owner_->updateLayoutChoice();
1097 if (!text->selection.set() && (f & SELECT)) {
1098 text->selection.cursor = text->cursor;
1101 text->fullRebreak(bv_);
1103 if (text->inset_owner) {
1104 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1105 updateInset(text->inset_owner, false);
1115 buffer_->markDirty();
1120 // Callback for cursor timer
1121 void BufferView::Pimpl::cursorToggle()
1124 cursor_timeout.restart();
1128 if (!screen_.get()) {
1129 cursor_timeout.restart();
1134 extern void reapSpellchecker(void);
1137 if (!bv_->theLockingInset()) {
1138 screen_->cursorToggle(bv_);
1140 bv_->theLockingInset()->toggleInsetCursor(bv_);
1143 cursor_timeout.restart();
1147 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1149 if (!text->cursor.row()->previous())
1152 int y = text->first_y;
1153 Row * cursorrow = text->cursor.row();
1155 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1157 // This is to allow jumping over large insets
1158 if ((cursorrow == text->cursor.row()))
1159 text->cursorUp(bv_);
1161 if (text->inset_owner ||
1162 text->cursor.row()->height() < workarea_.height())
1163 screen_->draw(bv_->text, bv_,
1165 - text->cursor.row()->baseline()
1166 + text->cursor.row()->height()
1167 - workarea_.height() + 1);
1172 void BufferView::Pimpl::cursorNext(LyXText * text)
1174 if (!text->cursor.row()->next())
1177 int y = text->first_y + workarea_.height();
1178 // if (text->inset_owner)
1179 // y += bv_->text->first;
1180 text->getRowNearY(y);
1182 Row * cursorrow = text->cursor.row();
1183 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1185 // This is to allow jumping over large insets
1186 if ((cursorrow == bv_->text->cursor.row()))
1187 text->cursorDown(bv_);
1189 if (text->inset_owner ||
1190 text->cursor.row()->height() < workarea_.height())
1191 screen_->draw(bv_->text, bv_, text->cursor.y() -
1192 text->cursor.row()->baseline());
1197 bool BufferView::Pimpl::available() const
1199 if (buffer_ && bv_->text)
1205 void BufferView::Pimpl::beforeChange(LyXText * text)
1208 text->clearSelection();
1212 void BufferView::Pimpl::savePosition(unsigned int i)
1214 if (i >= saved_positions_num)
1216 saved_positions[i] = Position(buffer_->fileName(),
1217 bv_->text->cursor.par()->id(),
1218 bv_->text->cursor.pos());
1221 str << _("Saved bookmark") << ' ' << i;
1222 owner_->message(str.str().c_str());
1227 void BufferView::Pimpl::restorePosition(unsigned int i)
1229 if (i >= saved_positions_num)
1232 string const fname = saved_positions[i].filename;
1234 beforeChange(bv_->text);
1236 if (fname != buffer_->fileName()) {
1237 Buffer * b = bufferlist.exists(fname) ?
1238 bufferlist.getBuffer(fname) :
1239 bufferlist.loadLyXFile(fname); // don't ask, just load it
1240 if (b != 0) buffer(b);
1243 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1247 bv_->text->setCursor(bv_, par,
1248 min(par->size(), saved_positions[i].par_pos));
1250 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1253 str << _("Moved to bookmark") << ' ' << i;
1254 owner_->message(str.str().c_str());
1259 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1261 if (i >= saved_positions_num)
1264 return !saved_positions[i].filename.empty();
1268 void BufferView::Pimpl::setState()
1270 if (!lyxrc.rtl_support)
1273 LyXText * text = bv_->getLyXText();
1274 if (text->real_current_font.isRightToLeft()) {
1275 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1276 owner_->getIntl()->KeyMapSec();
1278 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1279 owner_->getIntl()->KeyMapPrim();
1284 void BufferView::Pimpl::insetSleep()
1286 if (bv_->theLockingInset() && !inset_slept) {
1287 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1288 bv_->theLockingInset()->insetUnlock(bv_);
1294 void BufferView::Pimpl::insetWakeup()
1296 if (bv_->theLockingInset() && inset_slept) {
1297 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1298 inset_slept = false;
1303 void BufferView::Pimpl::insetUnlock()
1305 if (bv_->theLockingInset()) {
1307 bv_->theLockingInset()->insetUnlock(bv_);
1308 bv_->theLockingInset(0);
1310 inset_slept = false;
1315 bool BufferView::Pimpl::focus() const
1317 return workarea_.hasFocus();
1321 void BufferView::Pimpl::focus(bool f)
1323 if (f) workarea_.setFocus();
1327 bool BufferView::Pimpl::active() const
1329 return workarea_.active();
1333 bool BufferView::Pimpl::belowMouse() const
1335 return workarea_.belowMouse();
1339 void BufferView::Pimpl::showCursor()
1341 if (screen_.get()) {
1342 if (bv_->theLockingInset())
1343 bv_->theLockingInset()->showInsetCursor(bv_);
1345 screen_->showCursor(bv_->text, bv_);
1350 void BufferView::Pimpl::hideCursor()
1352 if (screen_.get()) {
1353 if (!bv_->theLockingInset())
1354 // bv_->theLockingInset()->hideInsetCursor(bv_);
1356 screen_->hideCursor();
1361 void BufferView::Pimpl::toggleSelection(bool b)
1363 if (screen_.get()) {
1364 if (bv_->theLockingInset())
1365 bv_->theLockingInset()->toggleSelection(bv_, b);
1366 screen_->toggleSelection(bv_->text, bv_, b);
1371 void BufferView::Pimpl::toggleToggle()
1374 screen_->toggleToggle(bv_->text, bv_);
1378 void BufferView::Pimpl::center()
1380 beforeChange(bv_->text);
1381 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1382 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1384 screen_->draw(bv_->text, bv_, 0);
1386 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1391 void BufferView::Pimpl::pasteClipboard(bool asPara)
1393 if (!buffer_) return;
1395 screen_->hideCursor();
1396 beforeChange(bv_->text);
1398 string const clip(workarea_.getClipboard());
1400 if (clip.empty()) return;
1403 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1405 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1407 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1411 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1413 workarea_.putClipboard(stuff);
1418 * Dispatch functions for actions which can be valid for BufferView->text
1419 * and/or InsetText->text!!!
1424 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1426 LyXText * lt = bv_->getLyXText();
1428 if (selecting || lt->selection.mark()) {
1429 lt->setSelection(bv_);
1433 updateInset(lt->inset_owner, false);
1436 update(lt, BufferView::SELECT|BufferView::FITCUR);
1440 /* ---> Everytime the cursor is moved, show the current font state. */
1441 // should this too me moved out of this func?
1442 //owner->showState();
1447 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1449 LyXCursor cursor = bv_->getLyXText()->cursor;
1450 Buffer::inset_iterator it =
1451 find_if(Buffer::inset_iterator(
1452 cursor.par(), cursor.pos()),
1453 buffer_->inset_iterator_end(),
1454 lyx::compare_memfun(&Inset::lyxCode, code));
1455 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1459 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1461 string filename = filen;
1463 if (filename.empty()) {
1464 // Launch a file browser
1465 string initpath = lyxrc.document_path;
1468 string const trypath = owner_->buffer()->filePath();
1469 // If directory is writeable, use this as default.
1470 if (IsDirWriteable(trypath))
1474 FileDialog fileDlg(bv_->owner(),
1475 _("Select LyX document to insert"),
1477 make_pair(string(_("Documents|#o#O")),
1478 string(lyxrc.document_path)),
1479 make_pair(string(_("Examples|#E#e")),
1480 string(AddPath(system_lyxdir, "examples"))));
1482 FileDialog::Result result =
1483 fileDlg.Select(initpath,
1484 _("*.lyx| LyX Documents (*.lyx)"));
1486 if (result.first == FileDialog::Later)
1489 filename = result.second;
1491 // check selected filename
1492 if (filename.empty()) {
1493 owner_->message(_("Canceled."));
1498 // get absolute path of file and add ".lyx" to the filename if
1500 filename = FileSearch(string(), filename, "lyx");
1502 string const disp_fn(MakeDisplayPath(filename));
1505 s1 << _("Inserting document") << ' '
1506 << disp_fn << " ...";
1507 owner_->message(s1.str().c_str());
1508 bool const res = bv_->insertLyXFile(filename);
1511 str << _("Document") << ' ' << disp_fn
1512 << ' ' << _("inserted.");
1513 owner_->message(str.str().c_str());
1516 str << _("Could not insert document") << ' '
1518 owner_->message(str.str().c_str());
1523 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1525 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1526 << action <<"] arg[" << argument << "]" << endl;
1529 // --- Misc -------------------------------------------
1533 LyXText * lt = bv_->getLyXText();
1534 lt->toggleAppendix(bv_);
1537 | BufferView::FITCUR
1538 | BufferView::CHANGE);
1543 case LFUN_TOC_INSERT:
1545 InsetCommandParams p;
1546 p.setCmdName("tableofcontents");
1547 Inset * inset = new InsetTOC(p);
1548 if (!insertInset(inset, "Standard"))
1553 case LFUN_SCROLL_INSET:
1554 // this is not handled here as this funktion is only aktive
1555 // if we have a locking_inset and that one is (or contains)
1559 case LFUN_INSET_GRAPHICS:
1561 Inset * new_inset = new InsetGraphics;
1562 if (!insertInset(new_inset)) {
1565 // this is need because you don't use a inset->Edit()
1566 updateInset(new_inset, true);
1567 new_inset->edit(bv_);
1577 case LFUN_PASTESELECTION:
1579 bool asPara = false;
1580 if (argument == "paragraph")
1582 pasteClipboard(asPara);
1594 case LFUN_LAYOUT_COPY:
1595 bv_->copyEnvironment();
1598 case LFUN_LAYOUT_PASTE:
1599 bv_->pasteEnvironment();
1603 case LFUN_GOTOERROR:
1604 gotoInset(Inset::ERROR_CODE, false);
1608 gotoInset(Inset::IGNORE_CODE, false);
1611 case LFUN_REFERENCE_GOTO:
1613 vector<Inset::Code> tmp;
1614 tmp.push_back(Inset::LABEL_CODE);
1615 tmp.push_back(Inset::REF_CODE);
1616 gotoInset(tmp, true);
1620 case LFUN_HYPHENATION:
1621 specialChar(InsetSpecialChar::HYPHENATION);
1624 case LFUN_LIGATURE_BREAK:
1625 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1629 specialChar(InsetSpecialChar::LDOTS);
1632 case LFUN_END_OF_SENTENCE:
1633 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1636 case LFUN_MENU_SEPARATOR:
1637 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1645 changeDepth(bv_, bv_->getLyXText(), 0);
1648 case LFUN_DEPTH_MIN:
1649 changeDepth(bv_, bv_->getLyXText(), -1);
1652 case LFUN_DEPTH_PLUS:
1653 changeDepth(bv_, bv_->getLyXText(), 1);
1657 owner_->getDialogs()->setUserFreeFont();
1660 case LFUN_FILE_INSERT:
1661 MenuInsertLyXFile(argument);
1664 case LFUN_FILE_INSERT_ASCII_PARA:
1665 InsertAsciiFile(bv_, argument, true);
1668 case LFUN_FILE_INSERT_ASCII:
1669 InsertAsciiFile(bv_, argument, false);
1674 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1675 << argument << endl;
1677 // Derive layout number from given argument (string)
1678 // and current buffer's textclass (number). */
1679 textclass_type tclass = buffer_->params.textclass;
1681 textclasslist[tclass].hasLayout(argument);
1682 string layout = argument;
1684 // If the entry is obsolete, use the new one instead.
1686 string const & obs = textclasslist[tclass][layout]
1693 owner_->getLyXFunc()->setErrorMessage(
1694 string(N_("Layout ")) + argument +
1699 if (current_layout != layout) {
1700 LyXText * lt = bv_->getLyXText();
1702 current_layout = layout;
1705 | BufferView::FITCUR);
1706 lt->setLayout(bv_, layout);
1707 owner_->setLayout(layout);
1710 | BufferView::FITCUR
1711 | BufferView::CHANGE);
1718 lang(bv_, argument);
1720 owner_->showState();
1725 owner_->showState();
1730 owner_->showState();
1735 owner_->showState();
1740 owner_->showState();
1745 owner_->showState();
1750 owner_->showState();
1755 owner_->showState();
1758 case LFUN_UNDERLINE:
1760 owner_->showState();
1763 case LFUN_FONT_SIZE:
1764 fontSize(bv_, argument);
1765 owner_->showState();
1768 case LFUN_FONT_STATE:
1769 owner_->getLyXFunc()->setMessage(currentState(bv_));
1772 case LFUN_UPCASE_WORD:
1774 LyXText * lt = bv_->getLyXText();
1778 | BufferView::FITCUR);
1779 lt->changeCase(bv_, LyXText::text_uppercase);
1780 if (lt->inset_owner)
1781 updateInset(lt->inset_owner, true);
1784 | BufferView::FITCUR
1785 | BufferView::CHANGE);
1789 case LFUN_LOWCASE_WORD:
1791 LyXText * lt = bv_->getLyXText();
1793 update(lt, BufferView::SELECT|BufferView::FITCUR);
1794 lt->changeCase(bv_, LyXText::text_lowercase);
1795 if (lt->inset_owner)
1796 updateInset(lt->inset_owner, true);
1799 | BufferView::FITCUR
1800 | BufferView::CHANGE);
1804 case LFUN_CAPITALIZE_WORD:
1806 LyXText * lt = bv_->getLyXText();
1808 update(lt, BufferView::SELECT|BufferView::FITCUR);
1809 lt->changeCase(bv_, LyXText::text_capitalization);
1810 if (lt->inset_owner)
1811 updateInset(lt->inset_owner, true);
1814 | BufferView::FITCUR
1815 | BufferView::CHANGE);
1819 case LFUN_TRANSPOSE_CHARS:
1821 LyXText * lt = bv_->getLyXText();
1823 update(lt, BufferView::SELECT|BufferView::FITCUR);
1824 lt->transposeChars(*bv_);
1825 if (lt->inset_owner)
1826 updateInset(lt->inset_owner, true);
1829 | BufferView::FITCUR
1830 | BufferView::CHANGE);
1835 case LFUN_INSERT_LABEL:
1836 MenuInsertLabel(bv_, argument);
1839 case LFUN_REF_INSERT:
1840 if (argument.empty()) {
1841 InsetCommandParams p("ref");
1842 owner_->getDialogs()->createRef(p.getAsString());
1844 InsetCommandParams p;
1845 p.setFromString(argument);
1847 InsetRef * inset = new InsetRef(p, *buffer_);
1848 if (!insertInset(inset))
1851 updateInset(inset, true);
1855 case LFUN_BOOKMARK_SAVE:
1856 savePosition(strToUnsignedInt(argument));
1859 case LFUN_BOOKMARK_GOTO:
1860 restorePosition(strToUnsignedInt(argument));
1865 string label(argument);
1866 if (label.empty()) {
1868 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1870 label = inset->getContents();
1875 if (!label.empty()) {
1876 //bv_->savePosition(0);
1877 if (!bv_->gotoLabel(label))
1878 Alert::alert(_("Error"),
1879 _("Couldn't find this label"),
1880 _("in current document."));
1885 // --- Cursor Movements -----------------------------
1888 LyXText * lt = bv_->getLyXText();
1890 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1891 if (!lt->selection.mark())
1893 update(lt, BufferView::SELECT|BufferView::FITCUR);
1895 lt->cursorLeft(bv_, false);
1896 if (lt->cursor.pos() < lt->cursor.par()->size()
1897 && lt->cursor.par()->isInset(lt->cursor.pos())
1898 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1899 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1900 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1902 tmpinset->edit(bv_, false);
1904 tmpinset->edit(bv_);
1908 lt->cursorRight(bv_, false);
1910 moveCursorUpdate(false);
1911 owner_->showState();
1917 // This is soooo ugly. Isn`t it possible to make
1918 // it simpler? (Lgb)
1919 LyXText * lt = bv_->getLyXText();
1920 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1921 if (!lt->selection.mark())
1923 update(lt, BufferView::SELECT|BufferView::FITCUR);
1924 LyXCursor const cur = lt->cursor;
1926 lt->cursorLeft(bv_, false);
1927 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1928 lt->cursor.pos() < lt->cursor.par()->size() &&
1929 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1930 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1931 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1932 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1934 tmpinset->edit(bv_);
1936 tmpinset->edit(bv_, false);
1940 lt->cursorRight(bv_, false);
1943 moveCursorUpdate(false);
1944 owner_->showState();
1950 LyXText * lt = bv_->getLyXText();
1952 if (!lt->selection.mark())
1954 update(lt, BufferView::UPDATE);
1957 moveCursorUpdate(false);
1958 owner_->showState();
1964 LyXText * lt = bv_->getLyXText();
1966 if (!lt->selection.mark())
1968 update(lt, BufferView::UPDATE);
1969 lt->cursorDown(bv_);
1971 moveCursorUpdate(false);
1972 owner_->showState();
1976 case LFUN_UP_PARAGRAPH:
1978 LyXText * lt = bv_->getLyXText();
1980 if (!lt->selection.mark())
1982 update(lt, BufferView::UPDATE);
1983 lt->cursorUpParagraph(bv_);
1985 moveCursorUpdate(false);
1986 owner_->showState();
1990 case LFUN_DOWN_PARAGRAPH:
1992 LyXText * lt = bv_->getLyXText();
1994 if (!lt->selection.mark())
1996 update(lt, BufferView::UPDATE);
1997 lt->cursorDownParagraph(bv_);
1999 moveCursorUpdate(false);
2000 owner_->showState();
2006 LyXText * lt = bv_->getLyXText();
2008 if (!lt->selection.mark())
2010 update(lt, BufferView::UPDATE);
2013 moveCursorUpdate(false);
2014 owner_->showState();
2020 LyXText * lt = bv_->getLyXText();
2022 if (!lt->selection.mark())
2024 update(lt, BufferView::UPDATE);
2027 moveCursorUpdate(false);
2028 owner_->showState();
2034 LyXText * lt = bv_->getLyXText();
2036 if (!lt->selection.mark())
2038 update(lt, BufferView::SELECT|BufferView::FITCUR);
2039 lt->cursorHome(bv_);
2041 moveCursorUpdate(false);
2042 owner_->showState();
2048 LyXText * lt = bv_->getLyXText();
2050 if (!lt->selection.mark())
2053 BufferView::SELECT|BufferView::FITCUR);
2056 moveCursorUpdate(false);
2057 owner_->showState();
2061 case LFUN_SHIFT_TAB:
2064 LyXText * lt = bv_->getLyXText();
2066 if (!lt->selection.mark())
2069 BufferView::SELECT|BufferView::FITCUR);
2072 moveCursorUpdate(false);
2073 owner_->showState();
2077 case LFUN_WORDRIGHT:
2079 LyXText * lt = bv_->getLyXText();
2081 if (!lt->selection.mark())
2083 update(lt, BufferView::SELECT|BufferView::FITCUR);
2084 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2085 lt->cursorLeftOneWord(bv_);
2087 lt->cursorRightOneWord(bv_);
2089 moveCursorUpdate(false);
2090 owner_->showState();
2096 LyXText * lt = bv_->getLyXText();
2098 if (!lt->selection.mark())
2100 update(lt, BufferView::SELECT|BufferView::FITCUR);
2101 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2102 lt->cursorRightOneWord(bv_);
2104 lt->cursorLeftOneWord(bv_);
2106 moveCursorUpdate(false);
2107 owner_->showState();
2111 case LFUN_BEGINNINGBUF:
2113 LyXText * lt = bv_->getLyXText();
2115 if (!lt->selection.mark())
2118 BufferView::SELECT|BufferView::FITCUR);
2121 moveCursorUpdate(false);
2122 owner_->showState();
2128 LyXText * lt = bv_->getLyXText();
2130 if (!lt->selection.mark())
2133 BufferView::SELECT|BufferView::FITCUR);
2134 lt->cursorBottom(bv_);
2136 moveCursorUpdate(false);
2137 owner_->showState();
2141 /* cursor selection ---------------------------- */
2144 LyXText * lt = bv_->getLyXText();
2147 BufferView::SELECT|BufferView::FITCUR);
2148 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2149 lt->cursorLeft(bv_);
2151 lt->cursorRight(bv_);
2153 moveCursorUpdate(true);
2154 owner_->showState();
2160 LyXText * lt = bv_->getLyXText();
2163 BufferView::SELECT|BufferView::FITCUR);
2164 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2165 lt->cursorRight(bv_);
2167 lt->cursorLeft(bv_);
2169 moveCursorUpdate(true);
2170 owner_->showState();
2176 LyXText * lt = bv_->getLyXText();
2179 BufferView::SELECT|BufferView::FITCUR);
2182 moveCursorUpdate(true);
2183 owner_->showState();
2189 LyXText * lt = bv_->getLyXText();
2192 BufferView::SELECT|BufferView::FITCUR);
2193 lt->cursorDown(bv_);
2195 moveCursorUpdate(true);
2196 owner_->showState();
2200 case LFUN_UP_PARAGRAPHSEL:
2202 LyXText * lt = bv_->getLyXText();
2205 BufferView::SELECT|BufferView::FITCUR);
2206 lt->cursorUpParagraph(bv_);
2208 moveCursorUpdate(true);
2209 owner_->showState();
2213 case LFUN_DOWN_PARAGRAPHSEL:
2215 LyXText * lt = bv_->getLyXText();
2218 BufferView::SELECT|BufferView::FITCUR);
2219 lt->cursorDownParagraph(bv_);
2221 moveCursorUpdate(true);
2222 owner_->showState();
2228 LyXText * lt = bv_->getLyXText();
2230 update(lt, BufferView::SELECT|BufferView::FITCUR);
2233 moveCursorUpdate(true);
2234 owner_->showState();
2240 LyXText * lt = bv_->getLyXText();
2242 update(lt, BufferView::SELECT|BufferView::FITCUR);
2245 moveCursorUpdate(true);
2246 owner_->showState();
2252 LyXText * lt = bv_->getLyXText();
2254 update(lt, BufferView::SELECT|BufferView::FITCUR);
2255 lt->cursorHome(bv_);
2257 moveCursorUpdate(true);
2258 owner_->showState();
2264 LyXText * lt = bv_->getLyXText();
2266 update(lt, BufferView::SELECT|BufferView::FITCUR);
2269 moveCursorUpdate(true);
2270 owner_->showState();
2274 case LFUN_WORDRIGHTSEL:
2276 LyXText * lt = bv_->getLyXText();
2278 update(lt, BufferView::SELECT|BufferView::FITCUR);
2279 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2280 lt->cursorLeftOneWord(bv_);
2282 lt->cursorRightOneWord(bv_);
2284 moveCursorUpdate(true);
2285 owner_->showState();
2289 case LFUN_WORDLEFTSEL:
2291 LyXText * lt = bv_->getLyXText();
2293 update(lt, BufferView::SELECT|BufferView::FITCUR);
2294 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2295 lt->cursorRightOneWord(bv_);
2297 lt->cursorLeftOneWord(bv_);
2299 moveCursorUpdate(true);
2300 owner_->showState();
2304 case LFUN_BEGINNINGBUFSEL:
2306 LyXText * lt = bv_->getLyXText();
2308 if (lt->inset_owner)
2310 update(lt, BufferView::SELECT|BufferView::FITCUR);
2313 moveCursorUpdate(true);
2314 owner_->showState();
2318 case LFUN_ENDBUFSEL:
2320 LyXText * lt = bv_->getLyXText();
2322 if (lt->inset_owner)
2325 BufferView::SELECT|BufferView::FITCUR);
2326 lt->cursorBottom(bv_);
2328 moveCursorUpdate(true);
2329 owner_->showState();
2333 // --- text changing commands ------------------------
2334 case LFUN_BREAKLINE:
2336 LyXText * lt = bv_->getLyXText();
2339 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2342 | BufferView::FITCUR
2343 | BufferView::CHANGE);
2344 moveCursorUpdate(false);
2348 case LFUN_PROTECTEDSPACE:
2350 LyXText * lt = bv_->getLyXText();
2352 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2354 if (style.free_spacing) {
2355 lt->insertChar(bv_, ' ');
2358 | BufferView::FITCUR
2359 | BufferView::CHANGE);
2363 moveCursorUpdate(false);
2369 LyXText * lt = bv_->getLyXText();
2371 if (lt->selection.mark()) {
2375 | BufferView::FITCUR);
2376 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2379 lt->selection.mark(true);
2382 | BufferView::FITCUR);
2383 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2385 lt->selection.cursor = lt->cursor;
2391 LyXText * lt = bv_->getLyXText();
2393 if (!lt->selection.set()) {
2395 lt->selection.cursor = lt->cursor;
2398 | BufferView::FITCUR
2399 | BufferView::CHANGE);
2400 // It is possible to make it a lot faster still
2401 // just comment out the line below...
2406 moveCursorUpdate(false);
2407 owner_->showState();
2412 case LFUN_DELETE_SKIP:
2414 LyXText * lt = bv_->getLyXText();
2416 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2418 LyXCursor cursor = lt->cursor;
2420 if (!lt->selection.set()) {
2421 if (cursor.pos() == cursor.par()->size()) {
2422 lt->cursorRight(bv_);
2423 cursor = lt->cursor;
2424 if (cursor.pos() == 0
2425 && !(cursor.par()->params().spaceTop()
2426 == VSpace (VSpace::NONE))) {
2429 cursor.par()->params().lineTop(),
2430 cursor.par()->params().lineBottom(),
2431 cursor.par()->params().pagebreakTop(),
2432 cursor.par()->params().pagebreakBottom(),
2433 VSpace(VSpace::NONE),
2434 cursor.par()->params().spaceBottom(),
2435 cursor.par()->params().spacing(),
2436 cursor.par()->params().align(),
2437 cursor.par()->params().labelWidthString(), 0);
2438 lt->cursorLeft(bv_);
2441 | BufferView::FITCUR
2442 | BufferView::CHANGE);
2444 lt->cursorLeft(bv_);
2446 lt->selection.cursor = lt->cursor;
2449 | BufferView::FITCUR
2450 | BufferView::CHANGE);
2454 lt->selection.cursor = lt->cursor;
2457 | BufferView::FITCUR
2458 | BufferView::CHANGE);
2466 /* -------> Delete word forward. */
2467 case LFUN_DELETE_WORD_FORWARD:
2468 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2469 bv_->getLyXText()->deleteWordForward(bv_);
2470 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2471 moveCursorUpdate(false);
2472 owner_->showState();
2475 /* -------> Delete word backward. */
2476 case LFUN_DELETE_WORD_BACKWARD:
2478 LyXText * lt = bv_->getLyXText();
2480 update(lt, BufferView::SELECT|BufferView::FITCUR);
2481 lt->deleteWordBackward(bv_);
2484 | BufferView::FITCUR
2485 | BufferView::CHANGE);
2486 moveCursorUpdate(false);
2487 owner_->showState();
2491 /* -------> Kill to end of line. */
2492 case LFUN_DELETE_LINE_FORWARD:
2494 LyXText * lt = bv_->getLyXText();
2496 update(lt, BufferView::SELECT|BufferView::FITCUR);
2497 lt->deleteLineForward(bv_);
2500 | BufferView::FITCUR
2501 | BufferView::CHANGE);
2502 moveCursorUpdate(false);
2506 /* -------> Set mark off. */
2509 LyXText * lt = bv_->getLyXText();
2512 update(lt, BufferView::SELECT|BufferView::FITCUR);
2513 lt->selection.cursor = lt->cursor;
2514 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2518 /* -------> Set mark on. */
2521 LyXText * lt = bv_->getLyXText();
2524 lt->selection.mark(true);
2525 update(lt, BufferView::SELECT|BufferView::FITCUR);
2526 lt->selection.cursor = lt->cursor;
2527 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2531 case LFUN_BACKSPACE:
2533 LyXText * lt = bv_->getLyXText();
2535 if (!lt->selection.set()) {
2536 if (owner_->getIntl()->getTrans().backspace()) {
2538 lt->selection.cursor = lt->cursor;
2541 | BufferView::FITCUR
2542 | BufferView::CHANGE);
2543 // It is possible to make it a lot faster still
2544 // just comment out the line below...
2550 owner_->showState();
2555 case LFUN_BACKSPACE_SKIP:
2557 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2558 LyXText * lt = bv_->getLyXText();
2560 LyXCursor cursor = lt->cursor;
2562 if (!lt->selection.set()) {
2563 if (cursor.pos() == 0
2564 && !(cursor.par()->params().spaceTop()
2565 == VSpace (VSpace::NONE))) {
2568 cursor.par()->params().lineTop(),
2569 cursor.par()->params().lineBottom(),
2570 cursor.par()->params().pagebreakTop(),
2571 cursor.par()->params().pagebreakBottom(),
2572 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2573 cursor.par()->params().spacing(),
2574 cursor.par()->params().align(),
2575 cursor.par()->params().labelWidthString(), 0);
2578 | BufferView::FITCUR
2579 | BufferView::CHANGE);
2582 lt->selection.cursor = cursor;
2585 | BufferView::FITCUR
2586 | BufferView::CHANGE);
2593 case LFUN_BREAKPARAGRAPH:
2595 LyXText * lt = bv_->getLyXText();
2598 lt->breakParagraph(bv_, 0);
2601 | BufferView::FITCUR
2602 | BufferView::CHANGE);
2603 lt->selection.cursor = lt->cursor;
2605 owner_->showState();
2609 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2611 LyXText * lt = bv_->getLyXText();
2614 lt->breakParagraph(bv_, 1);
2617 | BufferView::FITCUR
2618 | BufferView::CHANGE);
2619 lt->selection.cursor = lt->cursor;
2621 owner_->showState();
2625 case LFUN_BREAKPARAGRAPH_SKIP:
2627 // When at the beginning of a paragraph, remove
2628 // indentation and add a "defskip" at the top.
2629 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2630 LyXText * lt = bv_->getLyXText();
2632 LyXCursor cursor = lt->cursor;
2635 if (cursor.pos() == 0) {
2636 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2639 cursor.par()->params().lineTop(),
2640 cursor.par()->params().lineBottom(),
2641 cursor.par()->params().pagebreakTop(),
2642 cursor.par()->params().pagebreakBottom(),
2643 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2644 cursor.par()->params().spacing(),
2645 cursor.par()->params().align(),
2646 cursor.par()->params().labelWidthString(), 1);
2647 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2651 lt->breakParagraph(bv_, 0);
2652 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2657 | BufferView::FITCUR
2658 | BufferView::CHANGE);
2659 lt->selection.cursor = cursor;
2661 owner_->showState();
2665 case LFUN_PARAGRAPH_SPACING:
2667 LyXText * lt = bv_->getLyXText();
2669 Paragraph * par = lt->cursor.par();
2670 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2671 float cur_value = 1.0;
2672 if (cur_spacing == Spacing::Other) {
2673 cur_value = par->params().spacing().getValue();
2676 istringstream istr(argument.c_str());
2680 Spacing::Space new_spacing = cur_spacing;
2681 float new_value = cur_value;
2683 lyxerr << "Missing argument to `paragraph-spacing'"
2685 } else if (tmp == "single") {
2686 new_spacing = Spacing::Single;
2687 } else if (tmp == "onehalf") {
2688 new_spacing = Spacing::Onehalf;
2689 } else if (tmp == "double") {
2690 new_spacing = Spacing::Double;
2691 } else if (tmp == "other") {
2692 new_spacing = Spacing::Other;
2695 lyxerr << "new_value = " << tmpval << endl;
2698 } else if (tmp == "default") {
2699 new_spacing = Spacing::Default;
2701 lyxerr << _("Unknown spacing argument: ")
2702 << argument << endl;
2704 if (cur_spacing != new_spacing || cur_value != new_value) {
2705 par->params().spacing(Spacing(new_spacing, new_value));
2706 lt->redoParagraph(bv_);
2709 | BufferView::FITCUR
2710 | BufferView::CHANGE);
2715 case LFUN_INSET_TOGGLE:
2717 LyXText * lt = bv_->getLyXText();
2720 update(lt, BufferView::SELECT|BufferView::FITCUR);
2721 lt->toggleInset(bv_);
2722 update(lt, BufferView::SELECT|BufferView::FITCUR);
2734 InsetCommandParams p;
2735 if (action == LFUN_HTMLURL)
2736 p.setCmdName("htmlurl");
2738 p.setCmdName("url");
2739 owner_->getDialogs()->createUrl(p.getAsString());
2743 case LFUN_INSERT_URL:
2745 InsetCommandParams p;
2746 p.setFromString(argument);
2748 InsetUrl * inset = new InsetUrl(p);
2749 if (!insertInset(inset))
2752 updateInset(inset, true);
2756 case LFUN_INSET_TEXT:
2757 insertAndEditInset(new InsetText(buffer_->params));
2760 case LFUN_INSET_ERT:
2761 insertAndEditInset(new InsetERT(buffer_->params));
2764 case LFUN_INSET_EXTERNAL:
2765 insertAndEditInset(new InsetExternal);
2768 case LFUN_INSET_FOOTNOTE:
2769 insertAndEditInset(new InsetFoot(buffer_->params));
2772 case LFUN_INSET_MARGINAL:
2773 insertAndEditInset(new InsetMarginal(buffer_->params));
2776 case LFUN_INSET_MINIPAGE:
2777 insertAndEditInset(new InsetMinipage(buffer_->params));
2780 case LFUN_INSERT_NOTE:
2781 insertAndEditInset(new InsetNote(buffer_->params));
2784 case LFUN_INSET_FLOAT:
2785 // check if the float type exist
2786 if (floatList.typeExist(argument)) {
2787 insertAndEditInset(new InsetFloat(buffer_->params,
2790 lyxerr << "Non-existent float type: "
2791 << argument << endl;
2795 case LFUN_INSET_WIDE_FLOAT:
2797 // check if the float type exist
2798 if (floatList.typeExist(argument)) {
2799 InsetFloat * new_inset =
2800 new InsetFloat(buffer_->params, argument);
2801 new_inset->wide(true);
2802 if (insertInset(new_inset))
2803 new_inset->edit(bv_);
2807 lyxerr << "Non-existent float type: "
2808 << argument << endl;
2815 case LFUN_INSET_LIST:
2816 insertAndEditInset(new InsetList);
2819 case LFUN_INSET_THEOREM:
2820 insertAndEditInset(new InsetTheorem);
2824 case LFUN_INSET_CAPTION:
2826 // Do we have a locking inset...
2827 if (bv_->theLockingInset()) {
2828 lyxerr << "Locking inset code: "
2829 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2830 InsetCaption * new_inset =
2831 new InsetCaption(buffer_->params);
2832 new_inset->setOwner(bv_->theLockingInset());
2833 new_inset->setAutoBreakRows(true);
2834 new_inset->setDrawFrame(0, InsetText::LOCKED);
2835 new_inset->setFrameColor(0, LColor::captionframe);
2836 if (insertInset(new_inset))
2837 new_inset->edit(bv_);
2844 case LFUN_INSET_TABULAR:
2848 if (!argument.empty())
2849 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2850 InsetTabular * new_inset =
2851 new InsetTabular(*buffer_, r, c);
2853 bv_->getLyXText()->real_current_font.isRightToLeft();
2854 if (!open_new_inset(new_inset, rtl))
2859 // --- lyxserver commands ----------------------------
2861 case LFUN_CHARATCURSOR:
2863 pos_type pos = bv_->getLyXText()->cursor.pos();
2864 if (pos < bv_->getLyXText()->cursor.par()->size())
2865 owner_->getLyXFunc()->setMessage(
2866 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2868 owner_->getLyXFunc()->setMessage("EOF");
2873 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2875 + tostr(bv_->getLyXText()->cursor.y()));
2882 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2883 lyxerr << "SETXY: Could not parse coordinates in '"
2884 << argument << std::endl;
2886 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2890 case LFUN_GETLAYOUT:
2891 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2896 LyXFont & font = bv_->getLyXText()->current_font;
2897 if (font.shape() == LyXFont::ITALIC_SHAPE)
2898 owner_->getLyXFunc()->setMessage("E");
2899 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2900 owner_->getLyXFunc()->setMessage("N");
2902 owner_->getLyXFunc()->setMessage("0");
2907 // --- accented characters ---------------------------
2910 case LFUN_CIRCUMFLEX:
2920 case LFUN_SPECIAL_CARON:
2923 case LFUN_HUNG_UMLAUT:
2926 if (argument.empty()) {
2928 owner_->getLyXFunc()->handleKeyFunc(action);
2930 owner_->getLyXFunc()->handleKeyFunc(action);
2931 owner_->getIntl()->getTrans()
2932 .TranslateAndInsert(argument[0], bv_->getLyXText());
2933 update(bv_->getLyXText(),
2935 | BufferView::FITCUR
2936 | BufferView::CHANGE);
2940 case LFUN_MATH_MACRO:
2941 mathDispatchMathMacro(bv_, argument);
2944 case LFUN_MATH_DELIM:
2945 mathDispatchMathDelim(bv_, argument);
2948 case LFUN_INSERT_MATRIX:
2949 mathDispatchInsertMatrix(bv_, argument);
2952 case LFUN_INSERT_MATH:
2953 mathDispatchInsertMath(bv_, argument);
2956 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2957 mathDispatchMathImportSelection(bv_, argument);
2960 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2961 mathDispatchMathDisplay(bv_, argument);
2964 case LFUN_MATH_MODE: // Open or create an inlined math inset
2965 mathDispatchMathMode(bv_, argument);
2968 case LFUN_GREEK: // Insert a single greek letter
2969 mathDispatchGreek(bv_, argument);
2972 case LFUN_CITATION_INSERT:
2974 InsetCommandParams p;
2975 p.setFromString(argument);
2977 InsetCitation * inset = new InsetCitation(p);
2978 if (!insertInset(inset))
2981 updateInset(inset, true);
2985 case LFUN_INSERT_BIBTEX:
2987 // ale970405+lasgoutt970425
2988 // The argument can be up to two tokens separated
2989 // by a space. The first one is the bibstyle.
2990 string const db = token(argument, ' ', 0);
2991 string const bibstyle = token(argument, ' ', 1);
2993 InsetCommandParams p("BibTeX", db, bibstyle);
2994 InsetBibtex * inset = new InsetBibtex(p);
2996 if (insertInset(inset)) {
2997 if (argument.empty())
3004 // BibTeX data bases
3005 case LFUN_BIBDB_ADD:
3007 InsetBibtex * inset =
3008 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3010 inset->addDatabase(argument);
3015 case LFUN_BIBDB_DEL:
3017 InsetBibtex * inset =
3018 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3020 inset->delDatabase(argument);
3025 case LFUN_BIBTEX_STYLE:
3027 InsetBibtex * inset =
3028 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3030 inset->setOptions(argument);
3035 case LFUN_INDEX_CREATE:
3037 InsetCommandParams p("index");
3038 if (argument.empty()) {
3039 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3040 p.setContents(idxstring);
3042 p.setContents(argument);
3045 owner_->getDialogs()->createIndex(p.getAsString());
3049 case LFUN_INDEX_INSERT:
3051 InsetCommandParams p;
3052 p.setFromString(argument);
3053 InsetIndex * inset = new InsetIndex(p);
3055 if (!insertInset(inset))
3058 updateInset(inset, true);
3062 case LFUN_INDEX_INSERT_LAST:
3064 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3065 if (!idxstring.empty()) {
3066 owner_->message(_("Word `")
3067 + idxstring + _(("' indexed.")));
3068 InsetCommandParams p("index", idxstring);
3069 InsetIndex * inset = new InsetIndex(p);
3071 if (!insertInset(inset))
3074 updateInset(inset, true);
3079 case LFUN_INDEX_PRINT:
3081 InsetCommandParams p("printindex");
3082 Inset * inset = new InsetPrintIndex(p);
3083 if (!insertInset(inset, "Standard"))
3088 case LFUN_PARENTINSERT:
3090 lyxerr << "arg " << argument << endl;
3091 InsetCommandParams p("lyxparent", argument);
3092 Inset * inset = new InsetParent(p, *buffer_);
3093 if (!insertInset(inset, "Standard"))
3099 case LFUN_CHILD_INSERT:
3101 InsetInclude::Params p;
3102 p.cparams.setFromString(argument);
3103 p.masterFilename_ = buffer_->fileName();
3105 InsetInclude * inset = new InsetInclude(p);
3106 if (!insertInset(inset))
3109 updateInset(inset, true);
3110 bv_->owner()->getDialogs()->showInclude(inset);
3115 case LFUN_FLOAT_LIST:
3117 // We should check the argument for validity. (Lgb)
3118 Inset * inset = new InsetFloatList(argument);
3119 if (!insertInset(inset, "Standard"))
3124 case LFUN_THESAURUS_ENTRY:
3126 string arg = argument;
3129 arg = bv_->getLyXText()->selectionAsString(buffer_,
3133 if (arg.size() > 100 || arg.empty()) {
3134 // Get word or selection
3135 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3136 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3137 // FIXME: where is getLyXText()->unselect(bv_) ?
3141 bv_->owner()->getDialogs()->showThesaurus(arg);
3145 case LFUN_SELFINSERT:
3147 if (argument.empty()) break;
3149 /* Automatically delete the currently selected
3150 * text and replace it with what is being
3151 * typed in now. Depends on lyxrc settings
3152 * "auto_region_delete", which defaults to
3155 LyXText * lt = bv_->getLyXText();
3157 if (lyxrc.auto_region_delete) {
3158 if (lt->selection.set()) {
3159 lt->cutSelection(bv_, false, false);
3162 | BufferView::FITCUR
3163 | BufferView::CHANGE);
3168 LyXFont const old_font(lt->real_current_font);
3170 string::const_iterator cit = argument.begin();
3171 string::const_iterator end = argument.end();
3172 for (; cit != end; ++cit) {
3173 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3178 | BufferView::FITCUR
3179 | BufferView::CHANGE);
3181 lt->selection.cursor = lt->cursor;
3182 moveCursorUpdate(false);
3184 // real_current_font.number can change so we need to
3185 // update the minibuffer
3186 if (old_font != lt->real_current_font)
3187 owner_->showState();
3192 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3194 time_t now_time_t = time(NULL);
3195 struct tm * now_tm = localtime(&now_time_t);
3196 setlocale(LC_TIME, "");
3198 if (!argument.empty())
3201 arg = lyxrc.date_insert_format;
3203 int const datetmp_len =
3204 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3206 LyXText * lt = bv_->getLyXText();
3208 for (int i = 0; i < datetmp_len; i++) {
3209 lt->insertChar(bv_, datetmp[i]);
3212 | BufferView::FITCUR
3213 | BufferView::CHANGE);
3216 lt->selection.cursor = lt->cursor;
3217 moveCursorUpdate(false);
3221 case LFUN_UNKNOWN_ACTION:
3222 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3233 void BufferView::Pimpl::newline()
3236 LyXText * lt = bv_->getLyXText();
3240 | BufferView::FITCUR);
3241 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3244 | BufferView::FITCUR
3245 | BufferView::CHANGE);
3250 void BufferView::Pimpl::hfill()
3253 LyXText * lt = bv_->getLyXText();
3257 | BufferView::FITCUR);
3258 lt->insertChar(bv_, Paragraph::META_HFILL);
3261 | BufferView::FITCUR
3262 | BufferView::CHANGE);
3267 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3271 update(lt, BufferView::SELECT|BufferView::FITCUR);
3272 InsetSpecialChar * new_inset =
3273 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3274 #ifdef WITH_WARNINGS
3275 #warning Why is this code different from specialChar() below? (JMarc)
3276 // the code in specialChar is a generic version of what used to exist
3277 // for other special chars. I did not merge this case because of the
3278 // call to updateInset(), but what does it do?
3280 if (!insertInset(new_inset))
3283 updateInset(new_inset, true);
3288 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3291 LyXText * lt = bv_->getLyXText();
3294 update(lt, BufferView::SELECT|BufferView::FITCUR);
3295 InsetSpecialChar * new_inset =
3296 new InsetSpecialChar(kind);
3297 if (!insertInset(new_inset))
3303 void BufferView::Pimpl::smartQuote()
3305 LyXText const * lt = bv_->getLyXText();
3306 Paragraph const * par = lt->cursor.par();
3307 pos_type pos = lt->cursor.pos();
3311 || (par->isInset(pos - 1)
3312 && par->getInset(pos - 1)->isSpace()))
3315 c = par->getChar(pos - 1);
3320 LyXLayout const & style =
3321 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3323 if (style.pass_thru ||
3324 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3325 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3329 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3331 if (insertInset(inset))
3338 // Open and lock an updatable inset
3339 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3341 LyXText * lt = bv_->getLyXText();
3345 if (!insertInset(new_inset)) {
3349 new_inset->edit(bv_, !behind);
3354 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3356 // if we are in a locking inset we should try to insert the
3357 // inset there otherwise this is a illegal function now
3358 if (bv_->theLockingInset()) {
3359 if (bv_->theLockingInset()->insetAllowed(inset))
3360 return bv_->theLockingInset()->insertInset(bv_, inset);
3364 // not quite sure if we want this...
3365 setCursorParUndo(bv_);
3368 beforeChange(bv_->text);
3369 if (!lout.empty()) {
3370 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3371 bv_->text->breakParagraph(bv_);
3372 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3374 if (bv_->text->cursor.par()->size()) {
3375 bv_->text->cursorLeft(bv_);
3377 bv_->text->breakParagraph(bv_);
3378 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3382 LyXTextClass const & tclass =
3383 textclasslist[buffer_->params.textclass];
3384 bool hasLayout = tclass.hasLayout(lres);
3385 string lay = tclass.defaultLayoutName();
3387 if (hasLayout != false) {
3391 // layout not fount using default
3392 lay = tclass.defaultLayoutName();
3395 bv_->text->setLayout(bv_, lay);
3397 bv_->text->setParagraph(bv_, 0, 0,
3399 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3404 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3407 bv_->text->insertInset(bv_, inset);
3408 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3415 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3417 if (!inset || !available())
3420 // first check for locking insets
3421 if (bv_->theLockingInset()) {
3422 if (bv_->theLockingInset() == inset) {
3423 if (bv_->text->updateInset(bv_, inset)) {
3426 buffer_->markDirty();
3431 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3432 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3435 buffer_->markDirty();
3443 // then check if the inset is a top_level inset (has no owner)
3444 // if yes do the update as always otherwise we have to update the
3445 // toplevel inset where this inset is inside
3446 Inset * tl_inset = inset;
3447 while(tl_inset->owner())
3448 tl_inset = tl_inset->owner();
3450 if (tl_inset == inset) {
3451 update(bv_->text, BufferView::UPDATE);
3452 if (bv_->text->updateInset(bv_, inset)) {
3456 | BufferView::FITCUR
3457 | BufferView::CHANGE);
3459 update(bv_->text, SELECT);
3463 } else if (static_cast<UpdatableInset *>(tl_inset)
3464 ->updateInsetInInset(bv_, inset))
3466 if (bv_->text->updateInset(bv_, tl_inset)) {
3474 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3477 if (!available()) return;
3480 beforeChange(bv_->text);
3481 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3483 LyXCursor const & cursor = bv_->text->cursor;
3487 cursor.par()->isInset(cursor.pos())) {
3488 Inset const * inset = cursor.par()->getInset(cursor.pos());
3489 if (find(codes.begin(), codes.end(), inset->lyxCode())
3492 static_cast<InsetCommand const *>(inset)->getContents();
3496 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3497 if (bv_->text->cursor.pos()
3498 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3499 LyXCursor tmp = bv_->text->cursor;
3500 bv_->text->cursor.par(bv_->text->ownerParagraph());
3501 bv_->text->cursor.pos(0);
3502 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3503 bv_->text->cursor = tmp;
3504 bv_->owner()->message(_("No more insets"));
3507 bv_->owner()->message(_("No more insets"));
3510 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3511 bv_->text->selection.cursor = bv_->text->cursor;
3515 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3517 gotoInset(vector<Inset::Code>(1, code), same_content);