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 = 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_);
333 // See if we have a text in TextCache that fits
334 // the new buffer_ with the correct width.
335 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
337 if (lyxerr.debugging()) {
338 lyxerr << "Found a LyXText that fits:\n";
339 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
341 // Set the owner of the newly found text
342 // bv_->text->owner(bv_);
343 if (lyxerr.debugging())
344 textcache.show(lyxerr, "resizeCurrentBuffer");
346 bv_->text = new LyXText(bv_);
347 bv_->text->init(bv_);
353 bv_->text->selection.set(true);
354 /* at this point just to avoid the Delete-Empty-Paragraph
355 * Mechanism when setting the cursor */
356 bv_->text->selection.mark(mark_set);
358 bv_->text->setCursor(bv_, selstartpar, selstartpos);
359 bv_->text->selection.cursor = bv_->text->cursor;
360 bv_->text->setCursor(bv_, selendpar, selendpos);
361 bv_->text->setSelection(bv_);
362 bv_->text->setCursor(bv_, par, pos);
364 bv_->text->setCursor(bv_, par, pos);
365 bv_->text->selection.cursor = bv_->text->cursor;
366 bv_->text->selection.set(false);
368 // remake the inset locking
369 bv_->theLockingInset(the_locking_inset);
371 bv_->text->first = screen_->topCursorVisible(bv_->text);
373 buffer_->resizeInsets(bv_);
375 // this will scroll the screen such that the cursor becomes visible
380 owner_->allowInput();
382 /// clear the "Formatting Document" message
389 void BufferView::Pimpl::updateScreen()
391 // Regenerate the screen.
392 screen_.reset(new LyXScreen(workarea_));
396 void BufferView::Pimpl::updateScrollbar()
398 /* If the text is smaller than the working area, the scrollbar
399 * maximum must be the working area height. No scrolling will
402 workarea_.setScrollbar(0, 1.0);
406 long const text_height = bv_->text->height;
407 long const work_height = workarea_.height();
409 if (text_height <= work_height) {
410 workarea_.setScrollbarBounds(0.0, 0.0);
411 current_scrollbar_value = bv_->text->first;
412 workarea_.setScrollbar(current_scrollbar_value, 1.0);
416 double const lineh = bv_->text->defaultHeight();
417 double const slider_size =
418 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
420 static long old_text_height;
421 static double old_lineh;
422 static double old_slider_size;
424 if (text_height != old_text_height) {
425 workarea_.setScrollbarBounds(0.0,
426 text_height - work_height);
427 old_text_height = text_height;
429 if (lineh != old_lineh) {
430 workarea_.setScrollbarIncrements(lineh);
433 if (current_scrollbar_value != bv_->text->first
434 || slider_size != old_slider_size) {
435 current_scrollbar_value = bv_->text->first;
436 workarea_.setScrollbar(current_scrollbar_value, slider_size);
437 old_slider_size = slider_size;
442 // Callback for scrollbar slider
443 void BufferView::Pimpl::scrollCB(double value)
445 if (!buffer_) return;
447 current_scrollbar_value = long(value);
449 if (current_scrollbar_value < 0)
450 current_scrollbar_value = 0;
455 screen_->draw(bv_->text, bv_, current_scrollbar_value);
457 if (!lyxrc.cursor_follows_scrollbar) {
462 LyXText * vbt = bv_->text;
464 int const height = vbt->defaultHeight();
465 int const first = static_cast<int>((bv_->text->first + height));
466 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
468 if (vbt->cursor.y() < first)
469 vbt->setCursorFromCoordinates(bv_, 0, first);
470 else if (vbt->cursor.y() > last)
471 vbt->setCursorFromCoordinates(bv_, 0, last);
477 int BufferView::Pimpl::scrollUp(long time)
479 if (!buffer_) return 0;
480 if (!screen_.get()) return 0;
482 double value = workarea_.getScrollbarValue();
484 if (value == 0) return 0;
486 float add_value = (bv_->text->defaultHeight()
487 + float(time) * float(time) * 0.125);
489 if (add_value > workarea_.height())
490 add_value = float(workarea_.height() -
491 bv_->text->defaultHeight());
498 workarea_.setScrollbarValue(value);
505 int BufferView::Pimpl::scrollDown(long time)
507 if (!buffer_) return 0;
508 if (!screen_.get()) return 0;
510 double value = workarea_.getScrollbarValue();
511 pair<float, float> p = workarea_.getScrollbarBounds();
512 double const max = p.second;
514 if (value == max) return 0;
516 float add_value = (bv_->text->defaultHeight()
517 + float(time) * float(time) * 0.125);
519 if (add_value > workarea_.height())
520 add_value = float(workarea_.height() -
521 bv_->text->defaultHeight());
528 workarea_.setScrollbarValue(value);
535 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
537 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
541 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
543 // Only use motion with button 1
544 if (!(state & Button1MotionMask))
547 if (!buffer_ || !screen_.get()) return;
549 // Check for inset locking
550 if (bv_->theLockingInset()) {
551 LyXCursor cursor = bv_->text->cursor;
552 LyXFont font = bv_->text->getFont(buffer_,
553 cursor.par(), cursor.pos());
554 int width = bv_->theLockingInset()->width(bv_, font);
555 int inset_x = font.isVisibleRightToLeft()
556 ? cursor.x() - width : cursor.x();
557 int start_x = inset_x + bv_->theLockingInset()->scroll();
558 bv_->theLockingInset()->
559 insetMotionNotify(bv_,
561 y - cursor.y() + bv_->text->first,
566 /* The test for not selection possible is needed, that only motion
567 events are used, where the bottom press event was on
568 the drawing area too */
569 if (!selection_possible)
572 screen_->hideCursor();
574 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
576 if (!bv_->text->selection.set())
577 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
579 bv_->text->setSelection(bv_);
580 screen_->toggleToggle(bv_->text, bv_);
586 // Single-click on work area
587 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
590 if (!buffer_ || !screen_.get()) return;
592 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
594 // ok ok, this is a hack.
595 if (button == 4 || button == 5) {
598 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
601 scrollDown(lyxrc.wheel_jump);
606 if (bv_->theLockingInset()) {
607 // We are in inset locking mode
609 /* Check whether the inset was hit. If not reset mode,
610 otherwise give the event to the inset */
611 if (inset_hit == bv_->theLockingInset()) {
612 bv_->theLockingInset()->
613 insetButtonPress(bv_,xpos, ypos,button);
616 bv_->unlockInset(bv_->theLockingInset());
621 selection_possible = true;
622 screen_->hideCursor();
624 int const screen_first = bv_->text->first;
626 // Middle button press pastes if we have a selection
627 bool paste_internally = false;
629 && bv_->text->selection.set()) {
630 owner_->getLyXFunc()->dispatch(LFUN_COPY);
631 paste_internally = true;
634 // Clear the selection
635 screen_->toggleSelection(bv_->text, bv_);
636 bv_->text->clearSelection();
637 bv_->text->fullRebreak(bv_);
641 // Single left click in math inset?
642 if (isHighlyEditableInset(inset_hit)) {
643 // Highly editable inset, like math
644 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
645 selection_possible = false;
646 owner_->updateLayoutChoice();
647 owner_->message(inset->editMessage());
648 // IMO the inset has to be first in edit-mode and then we send the
649 // button press. (Jug 20020222)
650 inset->edit(bv_); //, xpos, ypos, button);
651 inset->insetButtonPress(bv_, xpos, ypos, button);
655 // Right click on a footnote flag opens float menu
657 selection_possible = false;
661 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
662 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
664 bv_->text->selection.cursor = bv_->text->cursor;
665 bv_->text->cursor.x_fix(bv_->text->cursor.x());
667 owner_->updateLayoutChoice();
669 selection_possible = false;
672 // Insert primary selection with middle mouse
673 // if there is a local selection in the current buffer,
676 if (paste_internally)
677 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
679 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
681 selection_possible = false;
687 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
693 LyXText * text = bv_->getLyXText();
695 if (text->bv_owner && bv_->theLockingInset())
698 if (screen_.get() && button == 1) {
699 if (text->bv_owner) {
700 screen_->hideCursor();
701 screen_->toggleSelection(text, bv_);
702 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
703 screen_->toggleSelection(text, bv_, false);
705 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
707 /* This will fit the cursor on the screen
709 update(text, BufferView::SELECT|BufferView::FITCUR);
714 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
720 LyXText * text = bv_->getLyXText();
722 if (text->bv_owner && bv_->theLockingInset())
725 if (screen_.get() && (button == 1)) {
726 if (text->bv_owner) {
727 screen_->hideCursor();
728 screen_->toggleSelection(text, bv_);
730 text->cursorHome(bv_);
731 text->selection.cursor = text->cursor;
732 text->cursorEnd(bv_);
733 text->setSelection(bv_);
734 if (text->bv_owner) {
735 screen_->toggleSelection(text, bv_, false);
737 /* This will fit the cursor on the screen
739 update(text, BufferView::SELECT|BufferView::FITCUR);
744 void BufferView::Pimpl::selectionRequested()
749 string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
752 workarea_.putClipboard(sel);
757 void BufferView::Pimpl::selectionLost()
761 bv_->getLyXText()->clearSelection();
766 void BufferView::Pimpl::enterView()
768 if (active() && available()) {
769 SetXtermCursor(workarea_.getWin());
770 using_xterm_cursor = true;
775 void BufferView::Pimpl::leaveView()
777 if (using_xterm_cursor) {
778 XUndefineCursor(fl_get_display(), workarea_.getWin());
779 using_xterm_cursor = false;
784 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
787 if (!buffer_ || !screen_.get()) return;
789 // If we hit an inset, we have the inset coordinates in these
790 // and inset_hit points to the inset. If we do not hit an
791 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
792 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
794 if (bv_->theLockingInset()) {
795 // We are in inset locking mode.
797 /* LyX does a kind of work-area grabbing for insets.
798 Only a ButtonPress Event outside the inset will
799 force a insetUnlock. */
800 bv_->theLockingInset()->
801 insetButtonRelease(bv_, x, y, button);
805 selection_possible = false;
812 workarea_.haveSelection(bv_->getLyXText()->selection.set());
817 owner_->updateMenubar();
818 owner_->updateToolbar();
820 // Did we hit an editable inset?
822 selection_possible = false;
824 // if we reach this point with a selection, it
825 // must mean we are currently selecting.
826 // But we don't want to open the inset
827 // because that is annoying for the user.
828 // So just pretend we didn't hit it.
829 // this is OK because a "kosher" ButtonRelease
830 // will follow a ButtonPress that clears
832 // Note this also fixes selection drawing
833 // problems if we end up opening an inset
834 if (bv_->getLyXText()->selection.set())
837 // CHECK fix this proper in 0.13
838 // well, maybe 13.0 !!!!!!!!!
840 // Following a ref shouldn't issue
841 // a push on the undo-stack
842 // anylonger, now that we have
843 // keybindings for following
844 // references and returning from
845 // references. IMHO though, it
846 // should be the inset's own business
847 // to push or not push on the undo
848 // stack. They don't *have* to
849 // alter the document...
851 // ...or maybe the SetCursorParUndo()
852 // below isn't necessary at all anylonger?
853 if (inset_hit->lyxCode() == Inset::REF_CODE) {
854 setCursorParUndo(bv_);
857 owner_->message(inset_hit->editMessage());
859 if (isHighlyEditableInset(inset_hit)) {
860 // Highly editable inset, like math
861 UpdatableInset *inset = (UpdatableInset *)inset_hit;
862 inset->insetButtonRelease(bv_, x, y, button);
864 inset_hit->insetButtonRelease(bv_, x, y, button);
865 inset_hit->edit(bv_, x, y, button);
870 // Maybe we want to edit a bibitem ale970302
871 if (bv_->text->cursor.par()->bibkey && x < 20 +
872 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
873 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
880 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
881 LyXCursor const & cursor) const
883 Paragraph /*const*/ & par = *cursor.par();
884 pos_type const pos = cursor.pos();
886 lyx::Assert(par.getInset(pos));
888 Inset const & inset(*par.getInset(pos));
890 LyXFont const & font = text.getFont(buffer_, &par, pos);
892 int const width = inset.width(bv_, font);
893 int const inset_x = font.isVisibleRightToLeft()
894 ? (cursor.x() - width) : cursor.x();
897 inset_x + inset.scroll(),
899 cursor.y() - inset.ascent(bv_, font),
900 cursor.y() + inset.descent(bv_, font));
904 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
905 LyXCursor const & cursor,
906 int & x, int & y) const
908 pos_type const pos(cursor.pos());
909 Paragraph /*const*/ & par(*cursor.par());
911 if (pos >= par.size() || !par.isInset(pos)) {
915 Inset /*const*/ * inset = par.getInset(pos);
917 if (!isEditableInset(inset)) {
921 Box b(insetDimensions(text, cursor));
923 if (!b.contained(x, y)) {
924 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
925 << " box " << b << endl;
929 text.setCursor(bv_, &par, pos, true);
932 // The origin of an inset is on the baseline
933 y -= (text.cursor.y());
939 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
944 int y_tmp = y + text->first;
947 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
949 Inset * inset(checkInset(*text, cursor, x, y_tmp));
956 // look at previous position
958 if (cursor.pos() == 0) {
963 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
965 inset = checkInset(*text, cursor, x, y_tmp);
973 void BufferView::Pimpl::workAreaExpose()
975 static int work_area_width;
976 static unsigned int work_area_height;
978 bool const widthChange = workarea_.workWidth() != work_area_width;
979 bool const heightChange = workarea_.height() != work_area_height;
981 // update from work area
982 work_area_width = workarea_.workWidth();
983 work_area_height = workarea_.height();
986 // The visible LyXView need a resize
989 // Remove all texts from the textcache
990 // This is not _really_ what we want to do. What
991 // we really want to do is to delete in textcache
992 // that does not have a BufferView with matching
993 // width, but as long as we have only one BufferView
994 // deleting all gives the same result.
995 if (lyxerr.debugging())
996 textcache.show(lyxerr, "Expose delete all");
998 } else if (heightChange) {
999 // Rebuild image of current screen
1001 // fitCursor() ensures we don't jump back
1002 // to the start of the document on vertical
1006 // The main window size has changed, repaint most stuff
1008 } else if (screen_.get())
1009 screen_->redraw(bv_->text, bv_);
1011 // Grey box when we don't have a buffer
1012 workarea_.greyOut();
1015 // always make sure that the scrollbar is sane.
1017 owner_->updateLayoutChoice();
1022 void BufferView::Pimpl::update()
1024 if (screen_.get() &&
1025 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1027 LyXText::text_status st = bv_->text->status();
1028 screen_->update(bv_->text, bv_);
1030 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1031 if (bv_->text->fullRebreak(bv_)) {
1032 st = LyXText::NEED_MORE_REFRESH;
1033 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1034 bv_->text->cursor.pos());
1037 bv_->text->status(bv_, st);
1038 screen_->update(bv_->text, bv_);
1040 // do this here instead of in the screen::update because of
1042 bv_->text->status(bv_, LyXText::UNCHANGED);
1048 // Values used when calling update:
1050 // -2 - update, move sel_cursor if selection, fitcursor
1051 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1052 // 0 - update, move sel_cursor if selection, fitcursor
1053 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1054 // 3 - update, move sel_cursor if selection
1057 // a simple redraw of the parts that need refresh
1059 // move sel_cursor if selection -
1060 // the text's sel_cursor is moved if there is selection is progress
1063 // fitCursor() is called and the scrollbar updated
1066 // the buffer is marked dirty.
1075 // UPDATE_ONLY = UPDATE;
1076 // UPDATE_SELECT = UPDATE | SELECT;
1077 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1078 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1080 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1081 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1082 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1083 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1084 // update(3) -> update(1) -> update(1) -> update(SELECT)
1086 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1088 owner_->updateLayoutChoice();
1090 if (!text->selection.set() && (f & SELECT)) {
1091 text->selection.cursor = text->cursor;
1094 text->fullRebreak(bv_);
1096 if (text->inset_owner) {
1097 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1098 updateInset(text->inset_owner, false);
1108 buffer_->markDirty();
1113 // Callback for cursor timer
1114 void BufferView::Pimpl::cursorToggle()
1117 cursor_timeout.restart();
1121 if (!screen_.get()) {
1122 cursor_timeout.restart();
1127 extern void reapSpellchecker(void);
1130 if (!bv_->theLockingInset()) {
1131 screen_->cursorToggle(bv_);
1133 bv_->theLockingInset()->toggleInsetCursor(bv_);
1136 cursor_timeout.restart();
1140 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1142 if (!text->cursor.row()->previous())
1145 int y = text->first;
1146 if (text->inset_owner)
1147 y += bv_->text->first;
1148 Row * cursorrow = text->cursor.row();
1149 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1151 // This is to allow jumping over large insets
1152 if ((cursorrow == text->cursor.row()))
1153 text->cursorUp(bv_);
1155 if (text->inset_owner ||
1156 text->cursor.row()->height() < workarea_.height())
1157 screen_->draw(bv_->text, bv_,
1159 - text->cursor.row()->baseline()
1160 + text->cursor.row()->height()
1161 - workarea_.height() + 1);
1166 void BufferView::Pimpl::cursorNext(LyXText * text)
1168 if (!text->cursor.row()->next())
1171 int y = text->first + workarea_.height();
1172 // if (text->inset_owner)
1173 // y += bv_->text->first;
1174 text->getRowNearY(y);
1176 Row * cursorrow = text->cursor.row();
1177 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1179 // This is to allow jumping over large insets
1180 if ((cursorrow == bv_->text->cursor.row()))
1181 text->cursorDown(bv_);
1183 if (text->inset_owner ||
1184 text->cursor.row()->height() < workarea_.height())
1185 screen_->draw(bv_->text, bv_, text->cursor.y() -
1186 text->cursor.row()->baseline());
1191 bool BufferView::Pimpl::available() const
1193 if (buffer_ && bv_->text) return true;
1198 void BufferView::Pimpl::beforeChange(LyXText * text)
1201 text->clearSelection();
1205 void BufferView::Pimpl::savePosition(unsigned int i)
1207 if (i >= saved_positions_num)
1209 saved_positions[i] = Position(buffer_->fileName(),
1210 bv_->text->cursor.par()->id(),
1211 bv_->text->cursor.pos());
1214 str << _("Saved bookmark") << ' ' << i;
1215 owner_->message(str.str().c_str());
1220 void BufferView::Pimpl::restorePosition(unsigned int i)
1222 if (i >= saved_positions_num)
1225 string const fname = saved_positions[i].filename;
1227 beforeChange(bv_->text);
1229 if (fname != buffer_->fileName()) {
1230 Buffer * b = bufferlist.exists(fname) ?
1231 bufferlist.getBuffer(fname) :
1232 bufferlist.loadLyXFile(fname); // don't ask, just load it
1233 if (b != 0) buffer(b);
1236 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1240 bv_->text->setCursor(bv_, par,
1241 min(par->size(), saved_positions[i].par_pos));
1243 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1246 str << _("Moved to bookmark") << ' ' << i;
1247 owner_->message(str.str().c_str());
1252 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1254 if (i >= saved_positions_num)
1257 return !saved_positions[i].filename.empty();
1261 void BufferView::Pimpl::setState()
1263 if (!lyxrc.rtl_support)
1266 LyXText * text = bv_->getLyXText();
1267 if (text->real_current_font.isRightToLeft()) {
1268 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1269 owner_->getIntl()->KeyMapSec();
1271 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1272 owner_->getIntl()->KeyMapPrim();
1277 void BufferView::Pimpl::insetSleep()
1279 if (bv_->theLockingInset() && !inset_slept) {
1280 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1281 bv_->theLockingInset()->insetUnlock(bv_);
1287 void BufferView::Pimpl::insetWakeup()
1289 if (bv_->theLockingInset() && inset_slept) {
1290 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1291 inset_slept = false;
1296 void BufferView::Pimpl::insetUnlock()
1298 if (bv_->theLockingInset()) {
1300 bv_->theLockingInset()->insetUnlock(bv_);
1301 bv_->theLockingInset(0);
1303 inset_slept = false;
1308 bool BufferView::Pimpl::focus() const
1310 return workarea_.hasFocus();
1314 void BufferView::Pimpl::focus(bool f)
1316 if (f) workarea_.setFocus();
1320 bool BufferView::Pimpl::active() const
1322 return workarea_.active();
1326 bool BufferView::Pimpl::belowMouse() const
1328 return workarea_.belowMouse();
1332 void BufferView::Pimpl::showCursor()
1334 if (screen_.get()) {
1335 if (bv_->theLockingInset())
1336 bv_->theLockingInset()->showInsetCursor(bv_);
1338 screen_->showCursor(bv_->text, bv_);
1343 void BufferView::Pimpl::hideCursor()
1345 if (screen_.get()) {
1346 if (!bv_->theLockingInset())
1347 // bv_->theLockingInset()->hideInsetCursor(bv_);
1349 screen_->hideCursor();
1354 void BufferView::Pimpl::toggleSelection(bool b)
1356 if (screen_.get()) {
1357 if (bv_->theLockingInset())
1358 bv_->theLockingInset()->toggleSelection(bv_, b);
1359 screen_->toggleSelection(bv_->text, bv_, b);
1364 void BufferView::Pimpl::toggleToggle()
1367 screen_->toggleToggle(bv_->text, bv_);
1371 void BufferView::Pimpl::center()
1373 beforeChange(bv_->text);
1374 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1375 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1377 screen_->draw(bv_->text, bv_, 0);
1379 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1384 void BufferView::Pimpl::pasteClipboard(bool asPara)
1386 if (!buffer_) return;
1388 screen_->hideCursor();
1389 beforeChange(bv_->text);
1391 string const clip(workarea_.getClipboard());
1393 if (clip.empty()) return;
1396 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1398 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1400 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1404 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1406 workarea_.putClipboard(stuff);
1411 * Dispatch functions for actions which can be valid for BufferView->text
1412 * and/or InsetText->text!!!
1417 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1419 LyXText * lt = bv_->getLyXText();
1421 if (selecting || lt->selection.mark()) {
1422 lt->setSelection(bv_);
1426 update(lt, BufferView::SELECT|BufferView::FITCUR);
1429 /* ---> Everytime the cursor is moved, show the current font state. */
1430 // should this too me moved out of this func?
1431 //owner->showState();
1436 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1438 LyXCursor cursor = bv_->getLyXText()->cursor;
1439 Buffer::inset_iterator it =
1440 find_if(Buffer::inset_iterator(
1441 cursor.par(), cursor.pos()),
1442 buffer_->inset_iterator_end(),
1443 lyx::compare_memfun(&Inset::lyxCode, code));
1444 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1448 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1450 string filename = filen;
1452 if (filename.empty()) {
1453 // Launch a file browser
1454 string initpath = lyxrc.document_path;
1457 string const trypath = owner_->buffer()->filePath();
1458 // If directory is writeable, use this as default.
1459 if (IsDirWriteable(trypath))
1463 FileDialog fileDlg(bv_->owner(),
1464 _("Select LyX document to insert"),
1466 make_pair(string(_("Documents|#o#O")),
1467 string(lyxrc.document_path)),
1468 make_pair(string(_("Examples|#E#e")),
1469 string(AddPath(system_lyxdir, "examples"))));
1471 FileDialog::Result result =
1472 fileDlg.Select(initpath,
1473 _("*.lyx| LyX Documents (*.lyx)"));
1475 if (result.first == FileDialog::Later)
1478 filename = result.second;
1480 // check selected filename
1481 if (filename.empty()) {
1482 owner_->message(_("Canceled."));
1487 // get absolute path of file and add ".lyx" to the filename if
1489 filename = FileSearch(string(), filename, "lyx");
1491 string const disp_fn(MakeDisplayPath(filename));
1494 s1 << _("Inserting document") << ' '
1495 << disp_fn << " ...";
1496 owner_->message(s1.str().c_str());
1497 bool const res = bv_->insertLyXFile(filename);
1500 str << _("Document") << ' ' << disp_fn
1501 << ' ' << _("inserted.");
1502 owner_->message(str.str().c_str());
1505 str << _("Could not insert document") << ' '
1507 owner_->message(str.str().c_str());
1512 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1514 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1515 << action <<"] arg[" << argument << "]" << endl;
1518 // --- Misc -------------------------------------------
1522 LyXText * lt = bv_->getLyXText();
1523 lt->toggleAppendix(bv_);
1526 | BufferView::FITCUR
1527 | BufferView::CHANGE);
1532 case LFUN_TOC_INSERT:
1534 InsetCommandParams p;
1535 p.setCmdName("tableofcontents");
1536 Inset * inset = new InsetTOC(p);
1537 if (!insertInset(inset, "Standard"))
1542 case LFUN_SCROLL_INSET:
1543 // this is not handled here as this funktion is only aktive
1544 // if we have a locking_inset and that one is (or contains)
1548 case LFUN_INSET_GRAPHICS:
1550 Inset * new_inset = new InsetGraphics;
1551 if (!insertInset(new_inset)) {
1554 // this is need because you don't use a inset->Edit()
1555 updateInset(new_inset, true);
1556 new_inset->edit(bv_);
1566 case LFUN_PASTESELECTION:
1568 bool asPara = false;
1569 if (argument == "paragraph")
1571 pasteClipboard(asPara);
1583 case LFUN_LAYOUT_COPY:
1584 bv_->copyEnvironment();
1587 case LFUN_LAYOUT_PASTE:
1588 bv_->pasteEnvironment();
1592 case LFUN_GOTOERROR:
1593 gotoInset(Inset::ERROR_CODE, false);
1597 gotoInset(Inset::IGNORE_CODE, false);
1600 case LFUN_REFERENCE_GOTO:
1602 vector<Inset::Code> tmp;
1603 tmp.push_back(Inset::LABEL_CODE);
1604 tmp.push_back(Inset::REF_CODE);
1605 gotoInset(tmp, true);
1609 case LFUN_HYPHENATION:
1610 specialChar(InsetSpecialChar::HYPHENATION);
1613 case LFUN_LIGATURE_BREAK:
1614 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1618 specialChar(InsetSpecialChar::LDOTS);
1621 case LFUN_END_OF_SENTENCE:
1622 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1625 case LFUN_MENU_SEPARATOR:
1626 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1634 changeDepth(bv_, bv_->getLyXText(), 0);
1637 case LFUN_DEPTH_MIN:
1638 changeDepth(bv_, bv_->getLyXText(), -1);
1641 case LFUN_DEPTH_PLUS:
1642 changeDepth(bv_, bv_->getLyXText(), 1);
1646 owner_->getDialogs()->setUserFreeFont();
1649 case LFUN_FILE_INSERT:
1650 MenuInsertLyXFile(argument);
1653 case LFUN_FILE_INSERT_ASCII_PARA:
1654 InsertAsciiFile(bv_, argument, true);
1657 case LFUN_FILE_INSERT_ASCII:
1658 InsertAsciiFile(bv_, argument, false);
1663 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1664 << argument << endl;
1666 // Derive layout number from given argument (string)
1667 // and current buffer's textclass (number). */
1668 textclass_type tclass = buffer_->params.textclass;
1670 textclasslist[tclass].hasLayout(argument);
1671 string layout = argument;
1673 // If the entry is obsolete, use the new one instead.
1675 string const & obs = textclasslist[tclass][layout]
1682 owner_->getLyXFunc()->setErrorMessage(
1683 string(N_("Layout ")) + argument +
1688 if (current_layout != layout) {
1689 LyXText * lt = bv_->getLyXText();
1691 current_layout = layout;
1694 | BufferView::FITCUR);
1695 lt->setLayout(bv_, layout);
1696 owner_->setLayout(layout);
1699 | BufferView::FITCUR
1700 | BufferView::CHANGE);
1707 lang(bv_, argument);
1709 owner_->showState();
1714 owner_->showState();
1719 owner_->showState();
1724 owner_->showState();
1729 owner_->showState();
1734 owner_->showState();
1739 owner_->showState();
1744 owner_->showState();
1747 case LFUN_UNDERLINE:
1749 owner_->showState();
1752 case LFUN_FONT_SIZE:
1753 fontSize(bv_, argument);
1754 owner_->showState();
1757 case LFUN_FONT_STATE:
1758 owner_->getLyXFunc()->setMessage(currentState(bv_));
1761 case LFUN_UPCASE_WORD:
1763 LyXText * lt = bv_->getLyXText();
1767 | BufferView::FITCUR);
1768 lt->changeCase(bv_, LyXText::text_uppercase);
1769 if (lt->inset_owner)
1770 updateInset(lt->inset_owner, true);
1773 | BufferView::FITCUR
1774 | BufferView::CHANGE);
1778 case LFUN_LOWCASE_WORD:
1780 LyXText * lt = bv_->getLyXText();
1782 update(lt, BufferView::SELECT|BufferView::FITCUR);
1783 lt->changeCase(bv_, LyXText::text_lowercase);
1784 if (lt->inset_owner)
1785 updateInset(lt->inset_owner, true);
1788 | BufferView::FITCUR
1789 | BufferView::CHANGE);
1793 case LFUN_CAPITALIZE_WORD:
1795 LyXText * lt = bv_->getLyXText();
1797 update(lt, BufferView::SELECT|BufferView::FITCUR);
1798 lt->changeCase(bv_, LyXText::text_capitalization);
1799 if (lt->inset_owner)
1800 updateInset(lt->inset_owner, true);
1803 | BufferView::FITCUR
1804 | BufferView::CHANGE);
1808 case LFUN_TRANSPOSE_CHARS:
1810 LyXText * lt = bv_->getLyXText();
1812 update(lt, BufferView::SELECT|BufferView::FITCUR);
1813 lt->transposeChars(*bv_);
1814 if (lt->inset_owner)
1815 updateInset(lt->inset_owner, true);
1818 | BufferView::FITCUR
1819 | BufferView::CHANGE);
1824 case LFUN_INSERT_LABEL:
1825 MenuInsertLabel(bv_, argument);
1828 case LFUN_REF_INSERT:
1829 if (argument.empty()) {
1830 InsetCommandParams p("ref");
1831 owner_->getDialogs()->createRef(p.getAsString());
1833 InsetCommandParams p;
1834 p.setFromString(argument);
1836 InsetRef * inset = new InsetRef(p, *buffer_);
1837 if (!insertInset(inset))
1840 updateInset(inset, true);
1844 case LFUN_BOOKMARK_SAVE:
1845 savePosition(strToUnsignedInt(argument));
1848 case LFUN_BOOKMARK_GOTO:
1849 restorePosition(strToUnsignedInt(argument));
1854 string label(argument);
1855 if (label.empty()) {
1857 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1859 label = inset->getContents();
1864 if (!label.empty()) {
1865 //bv_->savePosition(0);
1866 if (!bv_->gotoLabel(label))
1867 Alert::alert(_("Error"),
1868 _("Couldn't find this label"),
1869 _("in current document."));
1874 // --- Cursor Movements -----------------------------
1877 LyXText * lt = bv_->getLyXText();
1879 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1880 if (!lt->selection.mark())
1882 update(lt, BufferView::SELECT|BufferView::FITCUR);
1884 lt->cursorLeft(bv_, false);
1885 if (lt->cursor.pos() < lt->cursor.par()->size()
1886 && lt->cursor.par()->isInset(lt->cursor.pos())
1887 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1888 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1889 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1891 tmpinset->edit(bv_, false);
1893 tmpinset->edit(bv_);
1897 lt->cursorRight(bv_, false);
1899 moveCursorUpdate(false);
1900 owner_->showState();
1906 // This is soooo ugly. Isn`t it possible to make
1907 // it simpler? (Lgb)
1908 LyXText * lt = bv_->getLyXText();
1909 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1910 if (!lt->selection.mark())
1912 update(lt, BufferView::SELECT|BufferView::FITCUR);
1913 LyXCursor const cur = lt->cursor;
1915 lt->cursorLeft(bv_, false);
1916 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1917 lt->cursor.pos() < lt->cursor.par()->size() &&
1918 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1919 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1920 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1921 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1923 tmpinset->edit(bv_);
1925 tmpinset->edit(bv_, false);
1929 lt->cursorRight(bv_, false);
1932 moveCursorUpdate(false);
1933 owner_->showState();
1939 LyXText * lt = bv_->getLyXText();
1941 if (!lt->selection.mark())
1943 update(lt, BufferView::UPDATE);
1946 moveCursorUpdate(false);
1947 owner_->showState();
1953 LyXText * lt = bv_->getLyXText();
1955 if (!lt->selection.mark())
1957 update(lt, BufferView::UPDATE);
1958 lt->cursorDown(bv_);
1960 moveCursorUpdate(false);
1961 owner_->showState();
1965 case LFUN_UP_PARAGRAPH:
1967 LyXText * lt = bv_->getLyXText();
1969 if (!lt->selection.mark())
1971 update(lt, BufferView::UPDATE);
1972 lt->cursorUpParagraph(bv_);
1974 moveCursorUpdate(false);
1975 owner_->showState();
1979 case LFUN_DOWN_PARAGRAPH:
1981 LyXText * lt = bv_->getLyXText();
1983 if (!lt->selection.mark())
1985 update(lt, BufferView::UPDATE);
1986 lt->cursorDownParagraph(bv_);
1988 moveCursorUpdate(false);
1989 owner_->showState();
1995 LyXText * lt = bv_->getLyXText();
1997 if (!lt->selection.mark())
1999 update(lt, BufferView::UPDATE);
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::SELECT|BufferView::FITCUR);
2028 lt->cursorHome(bv_);
2030 moveCursorUpdate(false);
2031 owner_->showState();
2037 LyXText * lt = bv_->getLyXText();
2039 if (!lt->selection.mark())
2042 BufferView::SELECT|BufferView::FITCUR);
2045 moveCursorUpdate(false);
2046 owner_->showState();
2050 case LFUN_SHIFT_TAB:
2053 LyXText * lt = bv_->getLyXText();
2055 if (!lt->selection.mark())
2058 BufferView::SELECT|BufferView::FITCUR);
2061 moveCursorUpdate(false);
2062 owner_->showState();
2066 case LFUN_WORDRIGHT:
2068 LyXText * lt = bv_->getLyXText();
2070 if (!lt->selection.mark())
2072 update(lt, BufferView::SELECT|BufferView::FITCUR);
2073 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2074 lt->cursorLeftOneWord(bv_);
2076 lt->cursorRightOneWord(bv_);
2078 moveCursorUpdate(false);
2079 owner_->showState();
2085 LyXText * lt = bv_->getLyXText();
2087 if (!lt->selection.mark())
2089 update(lt, BufferView::SELECT|BufferView::FITCUR);
2090 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2091 lt->cursorRightOneWord(bv_);
2093 lt->cursorLeftOneWord(bv_);
2095 moveCursorUpdate(false);
2096 owner_->showState();
2100 case LFUN_BEGINNINGBUF:
2102 LyXText * lt = bv_->getLyXText();
2104 if (!lt->selection.mark())
2107 BufferView::SELECT|BufferView::FITCUR);
2110 moveCursorUpdate(false);
2111 owner_->showState();
2117 LyXText * lt = bv_->getLyXText();
2119 if (!lt->selection.mark())
2122 BufferView::SELECT|BufferView::FITCUR);
2123 lt->cursorBottom(bv_);
2125 moveCursorUpdate(false);
2126 owner_->showState();
2130 /* cursor selection ---------------------------- */
2133 LyXText * lt = bv_->getLyXText();
2136 BufferView::SELECT|BufferView::FITCUR);
2137 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2138 lt->cursorLeft(bv_);
2140 lt->cursorRight(bv_);
2142 moveCursorUpdate(true);
2143 owner_->showState();
2149 LyXText * lt = bv_->getLyXText();
2152 BufferView::SELECT|BufferView::FITCUR);
2153 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2154 lt->cursorRight(bv_);
2156 lt->cursorLeft(bv_);
2158 moveCursorUpdate(true);
2159 owner_->showState();
2165 LyXText * lt = bv_->getLyXText();
2168 BufferView::SELECT|BufferView::FITCUR);
2171 moveCursorUpdate(true);
2172 owner_->showState();
2178 LyXText * lt = bv_->getLyXText();
2181 BufferView::SELECT|BufferView::FITCUR);
2182 lt->cursorDown(bv_);
2184 moveCursorUpdate(true);
2185 owner_->showState();
2189 case LFUN_UP_PARAGRAPHSEL:
2191 LyXText * lt = bv_->getLyXText();
2194 BufferView::SELECT|BufferView::FITCUR);
2195 lt->cursorUpParagraph(bv_);
2197 moveCursorUpdate(true);
2198 owner_->showState();
2202 case LFUN_DOWN_PARAGRAPHSEL:
2204 LyXText * lt = bv_->getLyXText();
2207 BufferView::SELECT|BufferView::FITCUR);
2208 lt->cursorDownParagraph(bv_);
2210 moveCursorUpdate(true);
2211 owner_->showState();
2217 LyXText * lt = bv_->getLyXText();
2219 update(lt, BufferView::SELECT|BufferView::FITCUR);
2222 moveCursorUpdate(true);
2223 owner_->showState();
2229 LyXText * lt = bv_->getLyXText();
2231 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 moveCursorUpdate(true);
2235 owner_->showState();
2241 LyXText * lt = bv_->getLyXText();
2243 update(lt, BufferView::SELECT|BufferView::FITCUR);
2244 lt->cursorHome(bv_);
2246 moveCursorUpdate(true);
2247 owner_->showState();
2253 LyXText * lt = bv_->getLyXText();
2255 update(lt, BufferView::SELECT|BufferView::FITCUR);
2258 moveCursorUpdate(true);
2259 owner_->showState();
2263 case LFUN_WORDRIGHTSEL:
2265 LyXText * lt = bv_->getLyXText();
2267 update(lt, BufferView::SELECT|BufferView::FITCUR);
2268 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2269 lt->cursorLeftOneWord(bv_);
2271 lt->cursorRightOneWord(bv_);
2273 moveCursorUpdate(true);
2274 owner_->showState();
2278 case LFUN_WORDLEFTSEL:
2280 LyXText * lt = bv_->getLyXText();
2282 update(lt, BufferView::SELECT|BufferView::FITCUR);
2283 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2284 lt->cursorRightOneWord(bv_);
2286 lt->cursorLeftOneWord(bv_);
2288 moveCursorUpdate(true);
2289 owner_->showState();
2293 case LFUN_BEGINNINGBUFSEL:
2295 LyXText * lt = bv_->getLyXText();
2297 if (lt->inset_owner)
2299 update(lt, BufferView::SELECT|BufferView::FITCUR);
2302 moveCursorUpdate(true);
2303 owner_->showState();
2307 case LFUN_ENDBUFSEL:
2309 LyXText * lt = bv_->getLyXText();
2311 if (lt->inset_owner)
2314 BufferView::SELECT|BufferView::FITCUR);
2315 lt->cursorBottom(bv_);
2317 moveCursorUpdate(true);
2318 owner_->showState();
2322 // --- text changing commands ------------------------
2323 case LFUN_BREAKLINE:
2325 LyXText * lt = bv_->getLyXText();
2328 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2331 | BufferView::FITCUR
2332 | BufferView::CHANGE);
2333 moveCursorUpdate(false);
2337 case LFUN_PROTECTEDSPACE:
2339 LyXText * lt = bv_->getLyXText();
2341 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2343 if (style.free_spacing) {
2344 lt->insertChar(bv_, ' ');
2347 | BufferView::FITCUR
2348 | BufferView::CHANGE);
2352 moveCursorUpdate(false);
2358 LyXText * lt = bv_->getLyXText();
2360 if (lt->selection.mark()) {
2364 | BufferView::FITCUR);
2365 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2368 lt->selection.mark(true);
2371 | BufferView::FITCUR);
2372 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2374 lt->selection.cursor = lt->cursor;
2380 LyXText * lt = bv_->getLyXText();
2382 if (!lt->selection.set()) {
2384 lt->selection.cursor = lt->cursor;
2387 | BufferView::FITCUR
2388 | BufferView::CHANGE);
2389 // It is possible to make it a lot faster still
2390 // just comment out the line below...
2395 moveCursorUpdate(false);
2396 owner_->showState();
2401 case LFUN_DELETE_SKIP:
2403 LyXText * lt = bv_->getLyXText();
2405 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2407 LyXCursor cursor = lt->cursor;
2409 if (!lt->selection.set()) {
2410 if (cursor.pos() == cursor.par()->size()) {
2411 lt->cursorRight(bv_);
2412 cursor = lt->cursor;
2413 if (cursor.pos() == 0
2414 && !(cursor.par()->params().spaceTop()
2415 == VSpace (VSpace::NONE))) {
2418 cursor.par()->params().lineTop(),
2419 cursor.par()->params().lineBottom(),
2420 cursor.par()->params().pagebreakTop(),
2421 cursor.par()->params().pagebreakBottom(),
2422 VSpace(VSpace::NONE),
2423 cursor.par()->params().spaceBottom(),
2424 cursor.par()->params().spacing(),
2425 cursor.par()->params().align(),
2426 cursor.par()->params().labelWidthString(), 0);
2427 lt->cursorLeft(bv_);
2430 | BufferView::FITCUR
2431 | BufferView::CHANGE);
2433 lt->cursorLeft(bv_);
2435 lt->selection.cursor = lt->cursor;
2438 | BufferView::FITCUR
2439 | BufferView::CHANGE);
2443 lt->selection.cursor = lt->cursor;
2446 | BufferView::FITCUR
2447 | BufferView::CHANGE);
2455 /* -------> Delete word forward. */
2456 case LFUN_DELETE_WORD_FORWARD:
2457 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2458 bv_->getLyXText()->deleteWordForward(bv_);
2459 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2460 moveCursorUpdate(false);
2461 owner_->showState();
2464 /* -------> Delete word backward. */
2465 case LFUN_DELETE_WORD_BACKWARD:
2467 LyXText * lt = bv_->getLyXText();
2469 update(lt, BufferView::SELECT|BufferView::FITCUR);
2470 lt->deleteWordBackward(bv_);
2473 | BufferView::FITCUR
2474 | BufferView::CHANGE);
2475 moveCursorUpdate(false);
2476 owner_->showState();
2480 /* -------> Kill to end of line. */
2481 case LFUN_DELETE_LINE_FORWARD:
2483 LyXText * lt = bv_->getLyXText();
2485 update(lt, BufferView::SELECT|BufferView::FITCUR);
2486 lt->deleteLineForward(bv_);
2489 | BufferView::FITCUR
2490 | BufferView::CHANGE);
2491 moveCursorUpdate(false);
2495 /* -------> Set mark off. */
2498 LyXText * lt = bv_->getLyXText();
2501 update(lt, BufferView::SELECT|BufferView::FITCUR);
2502 lt->selection.cursor = lt->cursor;
2503 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2507 /* -------> Set mark on. */
2510 LyXText * lt = bv_->getLyXText();
2513 lt->selection.mark(true);
2514 update(lt, BufferView::SELECT|BufferView::FITCUR);
2515 lt->selection.cursor = lt->cursor;
2516 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2520 case LFUN_BACKSPACE:
2522 LyXText * lt = bv_->getLyXText();
2524 if (!lt->selection.set()) {
2525 if (owner_->getIntl()->getTrans().backspace()) {
2527 lt->selection.cursor = lt->cursor;
2530 | BufferView::FITCUR
2531 | BufferView::CHANGE);
2532 // It is possible to make it a lot faster still
2533 // just comment out the line below...
2539 owner_->showState();
2544 case LFUN_BACKSPACE_SKIP:
2546 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2547 LyXText * lt = bv_->getLyXText();
2549 LyXCursor cursor = lt->cursor;
2551 if (!lt->selection.set()) {
2552 if (cursor.pos() == 0
2553 && !(cursor.par()->params().spaceTop()
2554 == VSpace (VSpace::NONE))) {
2557 cursor.par()->params().lineTop(),
2558 cursor.par()->params().lineBottom(),
2559 cursor.par()->params().pagebreakTop(),
2560 cursor.par()->params().pagebreakBottom(),
2561 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2562 cursor.par()->params().spacing(),
2563 cursor.par()->params().align(),
2564 cursor.par()->params().labelWidthString(), 0);
2567 | BufferView::FITCUR
2568 | BufferView::CHANGE);
2571 lt->selection.cursor = cursor;
2574 | BufferView::FITCUR
2575 | BufferView::CHANGE);
2582 case LFUN_BREAKPARAGRAPH:
2584 LyXText * lt = bv_->getLyXText();
2587 lt->breakParagraph(bv_, 0);
2590 | BufferView::FITCUR
2591 | BufferView::CHANGE);
2592 lt->selection.cursor = lt->cursor;
2594 owner_->showState();
2598 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2600 LyXText * lt = bv_->getLyXText();
2603 lt->breakParagraph(bv_, 1);
2606 | BufferView::FITCUR
2607 | BufferView::CHANGE);
2608 lt->selection.cursor = lt->cursor;
2610 owner_->showState();
2614 case LFUN_BREAKPARAGRAPH_SKIP:
2616 // When at the beginning of a paragraph, remove
2617 // indentation and add a "defskip" at the top.
2618 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2619 LyXText * lt = bv_->getLyXText();
2621 LyXCursor cursor = lt->cursor;
2624 if (cursor.pos() == 0) {
2625 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2628 cursor.par()->params().lineTop(),
2629 cursor.par()->params().lineBottom(),
2630 cursor.par()->params().pagebreakTop(),
2631 cursor.par()->params().pagebreakBottom(),
2632 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2633 cursor.par()->params().spacing(),
2634 cursor.par()->params().align(),
2635 cursor.par()->params().labelWidthString(), 1);
2636 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2640 lt->breakParagraph(bv_, 0);
2641 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2646 | BufferView::FITCUR
2647 | BufferView::CHANGE);
2648 lt->selection.cursor = cursor;
2650 owner_->showState();
2654 case LFUN_PARAGRAPH_SPACING:
2656 LyXText * lt = bv_->getLyXText();
2658 Paragraph * par = lt->cursor.par();
2659 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2660 float cur_value = 1.0;
2661 if (cur_spacing == Spacing::Other) {
2662 cur_value = par->params().spacing().getValue();
2665 istringstream istr(argument.c_str());
2669 Spacing::Space new_spacing = cur_spacing;
2670 float new_value = cur_value;
2672 lyxerr << "Missing argument to `paragraph-spacing'"
2674 } else if (tmp == "single") {
2675 new_spacing = Spacing::Single;
2676 } else if (tmp == "onehalf") {
2677 new_spacing = Spacing::Onehalf;
2678 } else if (tmp == "double") {
2679 new_spacing = Spacing::Double;
2680 } else if (tmp == "other") {
2681 new_spacing = Spacing::Other;
2684 lyxerr << "new_value = " << tmpval << endl;
2687 } else if (tmp == "default") {
2688 new_spacing = Spacing::Default;
2690 lyxerr << _("Unknown spacing argument: ")
2691 << argument << endl;
2693 if (cur_spacing != new_spacing || cur_value != new_value) {
2694 par->params().spacing(Spacing(new_spacing, new_value));
2695 lt->redoParagraph(bv_);
2698 | BufferView::FITCUR
2699 | BufferView::CHANGE);
2704 case LFUN_INSET_TOGGLE:
2706 LyXText * lt = bv_->getLyXText();
2709 update(lt, BufferView::SELECT|BufferView::FITCUR);
2710 lt->toggleInset(bv_);
2711 update(lt, BufferView::SELECT|BufferView::FITCUR);
2723 InsetCommandParams p;
2724 if (action == LFUN_HTMLURL)
2725 p.setCmdName("htmlurl");
2727 p.setCmdName("url");
2728 owner_->getDialogs()->createUrl(p.getAsString());
2732 case LFUN_INSERT_URL:
2734 InsetCommandParams p;
2735 p.setFromString(argument);
2737 InsetUrl * inset = new InsetUrl(p);
2738 if (!insertInset(inset))
2741 updateInset(inset, true);
2745 case LFUN_INSET_TEXT:
2746 insertAndEditInset(new InsetText);
2749 case LFUN_INSET_ERT:
2750 insertAndEditInset(new InsetERT);
2753 case LFUN_INSET_EXTERNAL:
2754 insertAndEditInset(new InsetExternal);
2757 case LFUN_INSET_FOOTNOTE:
2758 insertAndEditInset(new InsetFoot);
2761 case LFUN_INSET_MARGINAL:
2762 insertAndEditInset(new InsetMarginal);
2765 case LFUN_INSET_MINIPAGE:
2766 insertAndEditInset(new InsetMinipage);
2769 case LFUN_INSERT_NOTE:
2770 insertAndEditInset(new InsetNote);
2773 case LFUN_INSET_FLOAT:
2774 // check if the float type exist
2775 if (floatList.typeExist(argument)) {
2776 insertAndEditInset(new InsetFloat(argument));
2778 lyxerr << "Non-existent float type: "
2779 << argument << endl;
2783 case LFUN_INSET_WIDE_FLOAT:
2785 // check if the float type exist
2786 if (floatList.typeExist(argument)) {
2787 InsetFloat * new_inset = new InsetFloat(argument);
2788 new_inset->wide(true);
2789 if (insertInset(new_inset))
2790 new_inset->edit(bv_);
2794 lyxerr << "Non-existent float type: "
2795 << argument << endl;
2802 case LFUN_INSET_LIST:
2803 insertAndEditInset(new InsetList);
2806 case LFUN_INSET_THEOREM:
2807 insertAndEditInset(new InsetTheorem);
2811 case LFUN_INSET_CAPTION:
2813 // Do we have a locking inset...
2814 if (bv_->theLockingInset()) {
2815 lyxerr << "Locking inset code: "
2816 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2817 InsetCaption * new_inset = new InsetCaption;
2818 new_inset->setOwner(bv_->theLockingInset());
2819 new_inset->setAutoBreakRows(true);
2820 new_inset->setDrawFrame(0, InsetText::LOCKED);
2821 new_inset->setFrameColor(0, LColor::captionframe);
2822 if (insertInset(new_inset))
2823 new_inset->edit(bv_);
2830 case LFUN_INSET_TABULAR:
2834 if (!argument.empty())
2835 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2836 InsetTabular * new_inset =
2837 new InsetTabular(*buffer_, r, c);
2839 bv_->getLyXText()->real_current_font.isRightToLeft();
2840 if (!open_new_inset(new_inset, rtl))
2845 // --- lyxserver commands ----------------------------
2847 case LFUN_CHARATCURSOR:
2849 pos_type pos = bv_->getLyXText()->cursor.pos();
2850 if (pos < bv_->getLyXText()->cursor.par()->size())
2851 owner_->getLyXFunc()->setMessage(
2852 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2854 owner_->getLyXFunc()->setMessage("EOF");
2859 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2861 + tostr(bv_->getLyXText()->cursor.y()));
2868 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2869 lyxerr << "SETXY: Could not parse coordinates in '"
2870 << argument << std::endl;
2872 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2876 case LFUN_GETLAYOUT:
2877 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2882 LyXFont & font = bv_->getLyXText()->current_font;
2883 if (font.shape() == LyXFont::ITALIC_SHAPE)
2884 owner_->getLyXFunc()->setMessage("E");
2885 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2886 owner_->getLyXFunc()->setMessage("N");
2888 owner_->getLyXFunc()->setMessage("0");
2893 // --- accented characters ---------------------------
2896 case LFUN_CIRCUMFLEX:
2906 case LFUN_SPECIAL_CARON:
2909 case LFUN_HUNG_UMLAUT:
2912 if (argument.empty()) {
2914 owner_->getLyXFunc()->handleKeyFunc(action);
2916 owner_->getLyXFunc()->handleKeyFunc(action);
2917 owner_->getIntl()->getTrans()
2918 .TranslateAndInsert(argument[0], bv_->getLyXText());
2919 update(bv_->getLyXText(),
2921 | BufferView::FITCUR
2922 | BufferView::CHANGE);
2926 case LFUN_MATH_MACRO:
2927 mathDispatchMathMacro(bv_, argument);
2930 case LFUN_MATH_DELIM:
2931 mathDispatchMathDelim(bv_, argument);
2934 case LFUN_INSERT_MATRIX:
2935 mathDispatchInsertMatrix(bv_, argument);
2938 case LFUN_INSERT_MATH:
2939 mathDispatchInsertMath(bv_, argument);
2942 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2943 mathDispatchMathImportSelection(bv_, argument);
2946 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2947 mathDispatchMathDisplay(bv_, argument);
2950 case LFUN_MATH_MODE: // Open or create an inlined math inset
2951 mathDispatchMathMode(bv_, argument);
2954 case LFUN_GREEK: // Insert a single greek letter
2955 mathDispatchGreek(bv_, argument);
2958 case LFUN_CITATION_INSERT:
2960 InsetCommandParams p;
2961 p.setFromString(argument);
2963 InsetCitation * inset = new InsetCitation(p);
2964 if (!insertInset(inset))
2967 updateInset(inset, true);
2971 case LFUN_INSERT_BIBTEX:
2973 // ale970405+lasgoutt970425
2974 // The argument can be up to two tokens separated
2975 // by a space. The first one is the bibstyle.
2976 string const db = token(argument, ' ', 0);
2977 string const bibstyle = token(argument, ' ', 1);
2979 InsetCommandParams p("BibTeX", db, bibstyle);
2980 InsetBibtex * inset = new InsetBibtex(p);
2982 if (insertInset(inset)) {
2983 if (argument.empty())
2990 // BibTeX data bases
2991 case LFUN_BIBDB_ADD:
2993 InsetBibtex * inset =
2994 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2996 inset->addDatabase(argument);
3001 case LFUN_BIBDB_DEL:
3003 InsetBibtex * inset =
3004 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3006 inset->delDatabase(argument);
3011 case LFUN_BIBTEX_STYLE:
3013 InsetBibtex * inset =
3014 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3016 inset->setOptions(argument);
3021 case LFUN_INDEX_CREATE:
3023 InsetCommandParams p("index");
3024 if (argument.empty()) {
3025 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3026 p.setContents(idxstring);
3028 p.setContents(argument);
3031 owner_->getDialogs()->createIndex(p.getAsString());
3035 case LFUN_INDEX_INSERT:
3037 InsetCommandParams p;
3038 p.setFromString(argument);
3039 InsetIndex * inset = new InsetIndex(p);
3041 if (!insertInset(inset))
3044 updateInset(inset, true);
3048 case LFUN_INDEX_INSERT_LAST:
3050 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3051 if (!idxstring.empty()) {
3052 owner_->message(_("Word `")
3053 + idxstring + _(("' indexed.")));
3054 InsetCommandParams p("index", idxstring);
3055 InsetIndex * inset = new InsetIndex(p);
3057 if (!insertInset(inset))
3060 updateInset(inset, true);
3065 case LFUN_INDEX_PRINT:
3067 InsetCommandParams p("printindex");
3068 Inset * inset = new InsetPrintIndex(p);
3069 if (!insertInset(inset, "Standard"))
3074 case LFUN_PARENTINSERT:
3076 lyxerr << "arg " << argument << endl;
3077 InsetCommandParams p("lyxparent", argument);
3078 Inset * inset = new InsetParent(p, *buffer_);
3079 if (!insertInset(inset, "Standard"))
3085 case LFUN_CHILD_INSERT:
3087 InsetInclude::Params p;
3088 p.cparams.setFromString(argument);
3089 p.masterFilename_ = buffer_->fileName();
3091 InsetInclude * inset = new InsetInclude(p);
3092 if (!insertInset(inset))
3095 updateInset(inset, true);
3096 bv_->owner()->getDialogs()->showInclude(inset);
3101 case LFUN_FLOAT_LIST:
3103 // We should check the argument for validity. (Lgb)
3104 Inset * inset = new InsetFloatList(argument);
3105 if (!insertInset(inset, "Standard"))
3110 case LFUN_THESAURUS_ENTRY:
3112 string arg = argument;
3115 arg = bv_->getLyXText()->selectionAsString(buffer_,
3119 if (arg.size() > 100 || arg.empty()) {
3120 // Get word or selection
3121 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3122 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3123 // FIXME: where is getLyXText()->unselect(bv_) ?
3127 bv_->owner()->getDialogs()->showThesaurus(arg);
3131 case LFUN_SELFINSERT:
3133 if (argument.empty()) break;
3135 /* Automatically delete the currently selected
3136 * text and replace it with what is being
3137 * typed in now. Depends on lyxrc settings
3138 * "auto_region_delete", which defaults to
3141 LyXText * lt = bv_->getLyXText();
3143 if (lyxrc.auto_region_delete) {
3144 if (lt->selection.set()) {
3145 lt->cutSelection(bv_, false, false);
3148 | BufferView::FITCUR
3149 | BufferView::CHANGE);
3154 LyXFont const old_font(lt->real_current_font);
3156 string::const_iterator cit = argument.begin();
3157 string::const_iterator end = argument.end();
3158 for (; cit != end; ++cit) {
3159 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3164 | BufferView::FITCUR
3165 | BufferView::CHANGE);
3167 lt->selection.cursor = lt->cursor;
3168 moveCursorUpdate(false);
3170 // real_current_font.number can change so we need to
3171 // update the minibuffer
3172 if (old_font != lt->real_current_font)
3173 owner_->showState();
3178 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3180 time_t now_time_t = time(NULL);
3181 struct tm * now_tm = localtime(&now_time_t);
3182 setlocale(LC_TIME, "");
3184 if (!argument.empty())
3187 arg = lyxrc.date_insert_format;
3189 int const datetmp_len =
3190 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3192 LyXText * lt = bv_->getLyXText();
3194 for (int i = 0; i < datetmp_len; i++) {
3195 lt->insertChar(bv_, datetmp[i]);
3198 | BufferView::FITCUR
3199 | BufferView::CHANGE);
3202 lt->selection.cursor = lt->cursor;
3203 moveCursorUpdate(false);
3207 case LFUN_UNKNOWN_ACTION:
3208 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3219 void BufferView::Pimpl::newline()
3222 LyXText * lt = bv_->getLyXText();
3226 | BufferView::FITCUR);
3227 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3230 | BufferView::FITCUR
3231 | BufferView::CHANGE);
3236 void BufferView::Pimpl::hfill()
3239 LyXText * lt = bv_->getLyXText();
3243 | BufferView::FITCUR);
3244 lt->insertChar(bv_, Paragraph::META_HFILL);
3247 | BufferView::FITCUR
3248 | BufferView::CHANGE);
3253 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3257 update(lt, BufferView::SELECT|BufferView::FITCUR);
3258 InsetSpecialChar * new_inset =
3259 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3260 #ifdef WITH_WARNINGS
3261 #warning Why is this code different from specialChar() below? (JMarc)
3262 // the code in specialChar is a generic version of what used to exist
3263 // for other special chars. I did not merge this case because of the
3264 // call to updateInset(), but what does it do?
3266 if (!insertInset(new_inset))
3269 updateInset(new_inset, true);
3274 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3277 LyXText * lt = bv_->getLyXText();
3280 update(lt, BufferView::SELECT|BufferView::FITCUR);
3281 InsetSpecialChar * new_inset =
3282 new InsetSpecialChar(kind);
3283 if (!insertInset(new_inset))
3289 void BufferView::Pimpl::smartQuote()
3291 LyXText const * lt = bv_->getLyXText();
3292 Paragraph const * par = lt->cursor.par();
3293 pos_type pos = lt->cursor.pos();
3297 || (par->isInset(pos - 1)
3298 && par->getInset(pos - 1)->isSpace()))
3301 c = par->getChar(pos - 1);
3306 LyXLayout const & style =
3307 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3309 if (style.pass_thru ||
3310 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3311 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3315 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3317 if (insertInset(inset))
3324 // Open and lock an updatable inset
3325 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3327 LyXText * lt = bv_->getLyXText();
3331 if (!insertInset(new_inset)) {
3335 new_inset->edit(bv_, !behind);
3340 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3342 // if we are in a locking inset we should try to insert the
3343 // inset there otherwise this is a illegal function now
3344 if (bv_->theLockingInset()) {
3345 if (bv_->theLockingInset()->insetAllowed(inset))
3346 return bv_->theLockingInset()->insertInset(bv_, inset);
3350 // not quite sure if we want this...
3351 setCursorParUndo(bv_);
3354 beforeChange(bv_->text);
3355 if (!lout.empty()) {
3356 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3357 bv_->text->breakParagraph(bv_);
3358 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3360 if (bv_->text->cursor.par()->size()) {
3361 bv_->text->cursorLeft(bv_);
3363 bv_->text->breakParagraph(bv_);
3364 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3368 LyXTextClass const & tclass =
3369 textclasslist[buffer_->params.textclass];
3370 bool hasLayout = tclass.hasLayout(lres);
3371 string lay = tclass.defaultLayoutName();
3373 if (hasLayout != false) {
3377 // layout not fount using default
3378 lay = tclass.defaultLayoutName();
3381 bv_->text->setLayout(bv_, lay);
3383 bv_->text->setParagraph(bv_, 0, 0,
3385 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3390 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3393 bv_->text->insertInset(bv_, inset);
3394 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3401 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3406 // first check for locking insets
3407 if (bv_->theLockingInset()) {
3408 if (bv_->theLockingInset() == inset) {
3409 if (bv_->text->updateInset(bv_, inset)) {
3412 buffer_->markDirty();
3417 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3418 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3421 buffer_->markDirty();
3429 // then check the current buffer
3432 update(bv_->text, BufferView::UPDATE);
3433 if (bv_->text->updateInset(bv_, inset)) {
3437 | BufferView::FITCUR
3438 | BufferView::CHANGE);
3440 update(bv_->text, SELECT);
3448 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3451 if (!available()) return;
3454 beforeChange(bv_->text);
3455 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3457 LyXCursor const & cursor = bv_->text->cursor;
3461 cursor.par()->isInset(cursor.pos())) {
3462 Inset const * inset = cursor.par()->getInset(cursor.pos());
3463 if (find(codes.begin(), codes.end(), inset->lyxCode())
3466 static_cast<InsetCommand const *>(inset)->getContents();
3470 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3471 if (bv_->text->cursor.pos()
3472 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3473 LyXCursor tmp = bv_->text->cursor;
3474 bv_->text->cursor.par(bv_->text->ownerParagraph());
3475 bv_->text->cursor.pos(0);
3476 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3477 bv_->text->cursor = tmp;
3478 bv_->owner()->message(_("No more insets"));
3481 bv_->owner()->message(_("No more insets"));
3484 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3485 bv_->text->selection.cursor = bv_->text->cursor;
3489 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3491 gotoInset(vector<Inset::Code>(1, code), same_content);