7 #include "BufferView_pimpl.h"
12 #include "paragraph.h"
14 #include "commandtags.h"
18 #include "bufferview_funcs.h"
19 #include "TextCache.h"
20 #include "bufferlist.h"
23 // added for Dispatch functions
26 #include "FloatList.h"
28 #include "ParagraphParameters.h"
29 #include "undo_funcs.h"
30 #include "lyxtextclasslist.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Alert.h"
34 #include "frontends/FileDialog.h"
36 #include "insets/insetbib.h"
37 #include "insets/insettext.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetnote.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetlist.h"
59 #include "insets/insetcaption.h"
60 #include "insets/insetfloatlist.h"
61 #include "insets/insetspecialchar.h"
63 #include "mathed/formulabase.h"
65 #include "support/LAssert.h"
66 #include "support/lstrings.h"
67 #include "support/filetools.h"
68 #include "support/lyxfunctional.h"
76 extern string current_layout;
88 using lyx::textclass_type;
90 /* the selection possible is needed, that only motion events are
91 * used, where the bottom press event was on the drawing area too */
92 bool selection_possible = false;
94 extern BufferList bufferlist;
95 extern char ascii_type;
97 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
102 const unsigned int saved_positions_num = 20;
107 XSync(fl_get_display(), 0);
111 void SetXtermCursor(Window win)
113 static Cursor cursor;
114 static bool cursor_undefined = true;
115 if (cursor_undefined) {
116 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
117 XFlush(fl_get_display());
118 cursor_undefined = false;
120 XDefineCursor(fl_get_display(), win, cursor);
121 XFlush(fl_get_display());
127 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
128 int xpos, int ypos, int width, int height)
129 : bv_(b), owner_(o), buffer_(0),
130 current_scrollbar_value(0), cursor_timeout(400),
131 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
135 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
136 workarea_.workAreaExpose
137 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
138 workarea_.workAreaEnter
139 .connect(slot(this, &BufferView::Pimpl::enterView));
140 workarea_.workAreaLeave
141 .connect(slot(this, &BufferView::Pimpl::leaveView));
142 workarea_.workAreaButtonPress
143 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
144 workarea_.workAreaButtonRelease
146 &BufferView::Pimpl::workAreaButtonRelease));
147 workarea_.workAreaMotionNotify
148 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
149 workarea_.workAreaDoubleClick
150 .connect(slot(this, &BufferView::Pimpl::doubleClick));
151 workarea_.workAreaTripleClick
152 .connect(slot(this, &BufferView::Pimpl::tripleClick));
153 workarea_.workAreaKeyPress
154 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
155 workarea_.selectionRequested
156 .connect(slot(this, &BufferView::Pimpl::selectionRequested));
157 workarea_.selectionLost
158 .connect(slot(this, &BufferView::Pimpl::selectionLost));
160 cursor_timeout.timeout.connect(slot(this,
161 &BufferView::Pimpl::cursorToggle));
162 cursor_timeout.start();
163 workarea_.setFocus();
164 saved_positions.resize(saved_positions_num);
168 Painter & BufferView::Pimpl::painter()
170 return workarea_.getPainter();
174 void BufferView::Pimpl::buffer(Buffer * b)
176 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
180 buffer_->delUser(bv_);
182 // Put the old text into the TextCache, but
183 // only if the buffer is still loaded.
184 // Also set the owner of the test to 0
185 // bv_->text->owner(0);
186 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
187 if (lyxerr.debugging())
188 textcache.show(lyxerr, "BufferView::buffer");
193 // Set current buffer
196 if (bufferlist.getState() == BufferList::CLOSING) return;
199 // screen is always deleted when the buffer is changed.
202 // If we are closing the buffer, use the first buffer as current
204 buffer_ = bufferlist.first();
208 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
209 buffer_->addUser(bv_);
210 // If we don't have a text object for this, we make one
211 if (bv_->text == 0) {
212 resizeCurrentBuffer();
217 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
218 owner_->updateMenubar();
219 owner_->updateToolbar();
220 // Similarly, buffer-dependent dialogs should be updated or
221 // hidden. This should go here because some dialogs (eg ToC)
222 // require bv_->text.
223 owner_->getDialogs()->updateBufferDependent(true);
227 lyxerr[Debug::INFO] << " No Buffer!" << endl;
228 owner_->updateMenubar();
229 owner_->updateToolbar();
230 owner_->getDialogs()->hideBufferDependent();
234 // Also remove all remaining text's from the testcache.
235 // (there should not be any!) (if there is any it is a
237 if (lyxerr.debugging())
238 textcache.show(lyxerr, "buffer delete all");
241 // should update layoutchoice even if we don't have a buffer.
242 owner_->updateLayoutChoice();
244 owner_->updateWindowTitle();
248 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
250 workarea_.resize(xpos, ypos, width, height);
251 update(bv_->text, SELECT);
256 void BufferView::Pimpl::resize()
259 resizeCurrentBuffer();
263 void BufferView::Pimpl::redraw()
265 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
270 bool BufferView::Pimpl::fitCursor()
272 lyx::Assert(screen_.get());
276 if (bv_->theLockingInset()) {
277 bv_->theLockingInset()->fitInsetCursor(bv_);
280 ret = screen_->fitCursor(bv_->text, bv_);
283 bv_->owner()->getDialogs()->updateParagraph();
290 void BufferView::Pimpl::redoCurrentBuffer()
292 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
293 if (buffer_ && bv_->text) {
295 owner_->updateLayoutChoice();
300 int BufferView::Pimpl::resizeCurrentBuffer()
302 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
305 Paragraph * selstartpar = 0;
306 Paragraph * selendpar = 0;
307 UpdatableInset * the_locking_inset = 0;
310 pos_type selstartpos = 0;
311 pos_type selendpos = 0;
312 bool selection = false;
313 bool mark_set = false;
315 owner_->prohibitInput();
317 owner_->message(_("Formatting document..."));
320 par = bv_->text->cursor.par();
321 pos = bv_->text->cursor.pos();
322 selstartpar = bv_->text->selection.start.par();
323 selstartpos = bv_->text->selection.start.pos();
324 selendpar = bv_->text->selection.end.par();
325 selendpos = bv_->text->selection.end.pos();
326 selection = bv_->text->selection.set();
327 mark_set = bv_->text->selection.mark();
328 the_locking_inset = bv_->theLockingInset();
330 bv_->text = new LyXText(bv_);
331 bv_->text->init(bv_);
332 buffer_->resizeInsets(bv_);
334 // See if we have a text in TextCache that fits
335 // the new buffer_ with the correct width.
336 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
338 if (lyxerr.debugging()) {
339 lyxerr << "Found a LyXText that fits:\n";
340 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
342 // Set the owner of the newly found text
343 // bv_->text->owner(bv_);
344 if (lyxerr.debugging())
345 textcache.show(lyxerr, "resizeCurrentBuffer");
347 bv_->text = new LyXText(bv_);
348 bv_->text->init(bv_);
349 //buffer_->resizeInsets(bv_);
356 bv_->text->selection.set(true);
357 // At this point just to avoid the Delete-Empty-Paragraph-
358 // Mechanism when setting the cursor.
359 bv_->text->selection.mark(mark_set);
361 bv_->text->setCursor(bv_, selstartpar, selstartpos);
362 bv_->text->selection.cursor = bv_->text->cursor;
363 bv_->text->setCursor(bv_, selendpar, selendpos);
364 bv_->text->setSelection(bv_);
365 bv_->text->setCursor(bv_, par, pos);
367 bv_->text->setCursor(bv_, par, pos);
368 bv_->text->selection.cursor = bv_->text->cursor;
369 bv_->text->selection.set(false);
371 // remake the inset locking
372 bv_->theLockingInset(the_locking_inset);
375 bv_->text->first_y = screen_->topCursorVisible(bv_->text);
377 // this will scroll the screen such that the cursor becomes visible
382 owner_->allowInput();
384 /// clear the "Formatting Document" message
391 void BufferView::Pimpl::updateScreen()
393 // Regenerate the screen.
394 screen_.reset(new LyXScreen(workarea_));
398 void BufferView::Pimpl::updateScrollbar()
401 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
402 workarea_.setScrollbar(0, 1.0);
406 long const text_height = bv_->text->height;
407 long const work_height = workarea_.height();
409 double const lineh = bv_->text->defaultHeight();
410 double const slider_size =
411 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
413 lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
414 lyxerr[Debug::GUI] << "work_height " << work_height << endl;
416 /* If the text is smaller than the working area, the scrollbar
417 * maximum must be the working area height. No scrolling will
419 if (text_height <= work_height) {
420 lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
421 workarea_.setScrollbarBounds(0.0, 0.0);
422 current_scrollbar_value = bv_->text->first_y;
423 workarea_.setScrollbar(current_scrollbar_value, 1.0);
427 workarea_.setScrollbarBounds(0.0, text_height - work_height);
428 workarea_.setScrollbarIncrements(lineh);
429 current_scrollbar_value = bv_->text->first_y;
430 workarea_.setScrollbar(current_scrollbar_value, slider_size);
434 // Callback for scrollbar slider
435 void BufferView::Pimpl::scrollCB(double value)
437 lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
439 if (!buffer_) return;
441 current_scrollbar_value = long(value);
443 if (current_scrollbar_value < 0)
444 current_scrollbar_value = 0;
449 screen_->draw(bv_->text, bv_, current_scrollbar_value);
451 if (!lyxrc.cursor_follows_scrollbar) {
456 LyXText * vbt = bv_->text;
458 int const height = vbt->defaultHeight();
459 int const first = static_cast<int>((bv_->text->first_y + height));
460 int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
462 if (vbt->cursor.y() < first)
463 vbt->setCursorFromCoordinates(bv_, 0, first);
464 else if (vbt->cursor.y() > last)
465 vbt->setCursorFromCoordinates(bv_, 0, last);
471 int BufferView::Pimpl::scrollUp(long time)
473 if (!buffer_) return 0;
474 if (!screen_.get()) return 0;
476 double value = workarea_.getScrollbarValue();
478 if (value == 0) return 0;
480 float add_value = (bv_->text->defaultHeight()
481 + float(time) * float(time) * 0.125);
483 if (add_value > workarea_.height())
484 add_value = float(workarea_.height() -
485 bv_->text->defaultHeight());
492 workarea_.setScrollbarValue(value);
499 int BufferView::Pimpl::scrollDown(long time)
501 if (!buffer_) return 0;
502 if (!screen_.get()) return 0;
504 double value = workarea_.getScrollbarValue();
505 pair<float, float> p = workarea_.getScrollbarBounds();
506 double const max = p.second;
508 if (value == max) return 0;
510 float add_value = (bv_->text->defaultHeight()
511 + float(time) * float(time) * 0.125);
513 if (add_value > workarea_.height())
514 add_value = float(workarea_.height() -
515 bv_->text->defaultHeight());
522 workarea_.setScrollbarValue(value);
529 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
531 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
535 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
537 // Only use motion with button 1
538 if (!(state & Button1MotionMask))
541 if (!buffer_ || !screen_.get()) return;
543 // Check for inset locking
544 if (bv_->theLockingInset()) {
545 LyXCursor cursor = bv_->text->cursor;
546 LyXFont font = bv_->text->getFont(buffer_,
547 cursor.par(), cursor.pos());
548 int width = bv_->theLockingInset()->width(bv_, font);
549 int inset_x = font.isVisibleRightToLeft()
550 ? cursor.x() - width : cursor.x();
551 int start_x = inset_x + bv_->theLockingInset()->scroll();
552 bv_->theLockingInset()->
553 insetMotionNotify(bv_,
555 y - cursor.y() + bv_->text->first_y,
560 /* The test for not selection possible is needed, that only motion
561 events are used, where the bottom press event was on
562 the drawing area too */
563 if (!selection_possible)
566 screen_->hideCursor();
568 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
570 if (!bv_->text->selection.set())
571 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
573 bv_->text->setSelection(bv_);
574 screen_->toggleToggle(bv_->text, bv_);
580 // Single-click on work area
581 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
584 if (!buffer_ || !screen_.get())
587 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
589 // ok ok, this is a hack.
590 if (button == 4 || button == 5) {
593 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
596 scrollDown(lyxrc.wheel_jump);
601 // Middle button press pastes if we have a selection
602 // We do this here as if the selection was inside an inset
603 // it could get cleared on the unlocking of the inset so
604 // we have to check this first
605 bool paste_internally = false;
606 if (button == 2 && bv_->getLyXText()->selection.set()) {
607 owner_->getLyXFunc()->dispatch(LFUN_COPY);
608 paste_internally = true;
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 // Clear the selection
632 screen_->toggleSelection(bv_->text, bv_);
633 bv_->text->clearSelection();
634 bv_->text->fullRebreak(bv_);
638 // Single left click in math inset?
639 if (isHighlyEditableInset(inset_hit)) {
640 // Highly editable inset, like math
641 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
642 selection_possible = false;
643 owner_->updateLayoutChoice();
644 owner_->message(inset->editMessage());
645 // IMO the inset has to be first in edit-mode and then we send the
646 // button press. (Jug 20020222)
647 inset->edit(bv_); //, xpos, ypos, button);
648 inset->insetButtonPress(bv_, xpos, ypos, button);
652 // Right click on a footnote flag opens float menu
654 selection_possible = false;
658 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
659 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
661 bv_->text->selection.cursor = bv_->text->cursor;
662 bv_->text->cursor.x_fix(bv_->text->cursor.x());
664 owner_->updateLayoutChoice();
666 selection_possible = false;
669 // Insert primary selection with middle mouse
670 // if there is a local selection in the current buffer,
673 if (paste_internally)
674 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
676 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
678 selection_possible = false;
684 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
690 LyXText * text = bv_->getLyXText();
692 if (text->bv_owner && bv_->theLockingInset())
695 if (screen_.get() && button == 1) {
696 if (text->bv_owner) {
697 screen_->hideCursor();
698 screen_->toggleSelection(text, bv_);
699 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
700 screen_->toggleSelection(text, bv_, false);
702 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
704 /* This will fit the cursor on the screen
706 update(text, BufferView::SELECT|BufferView::FITCUR);
711 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
717 LyXText * text = bv_->getLyXText();
719 if (text->bv_owner && bv_->theLockingInset())
722 if (screen_.get() && (button == 1)) {
723 if (text->bv_owner) {
724 screen_->hideCursor();
725 screen_->toggleSelection(text, bv_);
727 text->cursorHome(bv_);
728 text->selection.cursor = text->cursor;
729 text->cursorEnd(bv_);
730 text->setSelection(bv_);
731 if (text->bv_owner) {
732 screen_->toggleSelection(text, bv_, false);
734 /* This will fit the cursor on the screen
736 update(text, BufferView::SELECT|BufferView::FITCUR);
741 void BufferView::Pimpl::selectionRequested()
748 LyXText * text = bv_->getLyXText();
750 if (text->selection.set() &&
751 (!bv_->text->xsel_cache.set() ||
752 text->selection.start != bv_->text->xsel_cache.start ||
753 text->selection.end != bv_->text->xsel_cache.end))
755 bv_->text->xsel_cache = text->selection;
756 sel = text->selectionAsString(bv_->buffer(), false);
757 } else if (!text->selection.set()) {
759 bv_->text->xsel_cache.set(false);
762 workarea_.putClipboard(sel);
767 void BufferView::Pimpl::selectionLost()
769 if (active() && available()) {
772 bv_->getLyXText()->clearSelection();
774 bv_->text->xsel_cache.set(false);
779 void BufferView::Pimpl::enterView()
781 if (active() && available()) {
782 SetXtermCursor(workarea_.getWin());
783 using_xterm_cursor = true;
788 void BufferView::Pimpl::leaveView()
790 if (using_xterm_cursor) {
791 XUndefineCursor(fl_get_display(), workarea_.getWin());
792 using_xterm_cursor = false;
797 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
800 if (!buffer_ || !screen_.get()) return;
802 // If we hit an inset, we have the inset coordinates in these
803 // and inset_hit points to the inset. If we do not hit an
804 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
805 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
807 if (bv_->theLockingInset()) {
808 // We are in inset locking mode.
810 /* LyX does a kind of work-area grabbing for insets.
811 Only a ButtonPress Event outside the inset will
812 force a insetUnlock. */
813 bv_->theLockingInset()->
814 insetButtonRelease(bv_, x, y, button);
818 selection_possible = false;
825 workarea_.haveSelection(bv_->getLyXText()->selection.set());
830 owner_->updateMenubar();
831 owner_->updateToolbar();
833 // Did we hit an editable inset?
835 selection_possible = false;
837 // if we reach this point with a selection, it
838 // must mean we are currently selecting.
839 // But we don't want to open the inset
840 // because that is annoying for the user.
841 // So just pretend we didn't hit it.
842 // this is OK because a "kosher" ButtonRelease
843 // will follow a ButtonPress that clears
845 // Note this also fixes selection drawing
846 // problems if we end up opening an inset
847 if (bv_->getLyXText()->selection.set())
850 // CHECK fix this proper in 0.13
851 // well, maybe 13.0 !!!!!!!!!
853 // Following a ref shouldn't issue
854 // a push on the undo-stack
855 // anylonger, now that we have
856 // keybindings for following
857 // references and returning from
858 // references. IMHO though, it
859 // should be the inset's own business
860 // to push or not push on the undo
861 // stack. They don't *have* to
862 // alter the document...
864 // ...or maybe the SetCursorParUndo()
865 // below isn't necessary at all anylonger?
866 if (inset_hit->lyxCode() == Inset::REF_CODE) {
867 setCursorParUndo(bv_);
870 owner_->message(inset_hit->editMessage());
872 if (isHighlyEditableInset(inset_hit)) {
873 // Highly editable inset, like math
874 UpdatableInset *inset = (UpdatableInset *)inset_hit;
875 inset->insetButtonRelease(bv_, x, y, button);
877 inset_hit->insetButtonRelease(bv_, x, y, button);
878 inset_hit->edit(bv_, x, y, button);
883 // Maybe we want to edit a bibitem ale970302
884 if (bv_->text->cursor.par()->bibkey && x < 20 +
885 bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
886 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
893 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
894 LyXCursor const & cursor) const
896 Paragraph /*const*/ & par = *cursor.par();
897 pos_type const pos = cursor.pos();
899 lyx::Assert(par.getInset(pos));
901 Inset const & inset(*par.getInset(pos));
903 LyXFont const & font = text.getFont(buffer_, &par, pos);
905 int const width = inset.width(bv_, font);
906 int const inset_x = font.isVisibleRightToLeft()
907 ? (cursor.x() - width) : cursor.x();
910 inset_x + inset.scroll(),
912 cursor.y() - inset.ascent(bv_, font),
913 cursor.y() + inset.descent(bv_, font));
917 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
918 LyXCursor const & cursor,
919 int & x, int & y) const
921 pos_type const pos(cursor.pos());
922 Paragraph /*const*/ & par(*cursor.par());
924 if (pos >= par.size() || !par.isInset(pos)) {
928 Inset /*const*/ * inset = par.getInset(pos);
930 if (!isEditableInset(inset)) {
934 Box b(insetDimensions(text, cursor));
936 if (!b.contained(x, y)) {
937 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
938 << " box " << b << endl;
942 text.setCursor(bv_, &par, pos, true);
945 // The origin of an inset is on the baseline
946 y -= (text.cursor.y());
952 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
957 int y_tmp = y + text->first_y;
960 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
962 Inset * inset(checkInset(*text, cursor, x, y_tmp));
969 // look at previous position
971 if (cursor.pos() == 0) {
976 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
978 inset = checkInset(*text, cursor, x, y_tmp);
986 void BufferView::Pimpl::workAreaExpose()
988 static int work_area_width;
989 static unsigned int work_area_height;
991 bool const widthChange = workarea_.workWidth() != work_area_width;
992 bool const heightChange = workarea_.height() != work_area_height;
994 // update from work area
995 work_area_width = workarea_.workWidth();
996 work_area_height = workarea_.height();
999 // The visible LyXView need a resize
1002 // Remove all texts from the textcache
1003 // This is not _really_ what we want to do. What
1004 // we really want to do is to delete in textcache
1005 // that does not have a BufferView with matching
1006 // width, but as long as we have only one BufferView
1007 // deleting all gives the same result.
1008 if (lyxerr.debugging())
1009 textcache.show(lyxerr, "Expose delete all");
1011 buffer_->resizeInsets(bv_);
1012 } else if (heightChange) {
1013 // Rebuild image of current screen
1015 // fitCursor() ensures we don't jump back
1016 // to the start of the document on vertical
1020 // The main window size has changed, repaint most stuff
1022 } else if (screen_.get())
1023 screen_->redraw(bv_->text, bv_);
1025 // Grey box when we don't have a buffer
1026 workarea_.greyOut();
1029 // always make sure that the scrollbar is sane.
1031 owner_->updateLayoutChoice();
1036 void BufferView::Pimpl::update()
1038 if (screen_.get() &&
1039 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
1041 LyXText::text_status st = bv_->text->status();
1042 screen_->update(bv_->text, bv_);
1044 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
1045 if (bv_->text->fullRebreak(bv_)) {
1046 st = LyXText::NEED_MORE_REFRESH;
1047 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
1048 bv_->text->cursor.pos());
1051 bv_->text->status(bv_, st);
1052 screen_->update(bv_->text, bv_);
1054 // do this here instead of in the screen::update because of
1056 bv_->text->status(bv_, LyXText::UNCHANGED);
1062 // Values used when calling update:
1064 // -2 - update, move sel_cursor if selection, fitcursor
1065 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1066 // 0 - update, move sel_cursor if selection, fitcursor
1067 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1068 // 3 - update, move sel_cursor if selection
1071 // a simple redraw of the parts that need refresh
1073 // move sel_cursor if selection -
1074 // the text's sel_cursor is moved if there is selection is progress
1077 // fitCursor() is called and the scrollbar updated
1080 // the buffer is marked dirty.
1089 // UPDATE_ONLY = UPDATE;
1090 // UPDATE_SELECT = UPDATE | SELECT;
1091 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1092 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1094 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1095 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1096 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1097 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1098 // update(3) -> update(1) -> update(1) -> update(SELECT)
1100 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1102 owner_->updateLayoutChoice();
1104 if (!text->selection.set() && (f & SELECT)) {
1105 text->selection.cursor = text->cursor;
1108 text->fullRebreak(bv_);
1110 if (text->inset_owner) {
1111 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1112 updateInset(text->inset_owner, false);
1122 buffer_->markDirty();
1127 // Callback for cursor timer
1128 void BufferView::Pimpl::cursorToggle()
1131 cursor_timeout.restart();
1135 if (!screen_.get()) {
1136 cursor_timeout.restart();
1141 extern void reapSpellchecker(void);
1144 if (!bv_->theLockingInset()) {
1145 screen_->cursorToggle(bv_);
1147 bv_->theLockingInset()->toggleInsetCursor(bv_);
1150 cursor_timeout.restart();
1154 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1156 if (!text->cursor.row()->previous())
1159 int y = text->first_y;
1160 Row * cursorrow = text->cursor.row();
1162 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1164 // This is to allow jumping over large insets
1165 if ((cursorrow == text->cursor.row()))
1166 text->cursorUp(bv_);
1168 if (text->inset_owner ||
1169 text->cursor.row()->height() < workarea_.height())
1170 screen_->draw(bv_->text, bv_,
1172 - text->cursor.row()->baseline()
1173 + text->cursor.row()->height()
1174 - workarea_.height() + 1);
1179 void BufferView::Pimpl::cursorNext(LyXText * text)
1181 if (!text->cursor.row()->next())
1184 int y = text->first_y + workarea_.height();
1185 // if (text->inset_owner)
1186 // y += bv_->text->first;
1187 text->getRowNearY(y);
1189 Row * cursorrow = text->cursor.row();
1190 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1192 // This is to allow jumping over large insets
1193 if ((cursorrow == bv_->text->cursor.row()))
1194 text->cursorDown(bv_);
1196 if (text->inset_owner ||
1197 text->cursor.row()->height() < workarea_.height())
1198 screen_->draw(bv_->text, bv_, text->cursor.y() -
1199 text->cursor.row()->baseline());
1204 bool BufferView::Pimpl::available() const
1206 if (buffer_ && bv_->text)
1212 void BufferView::Pimpl::beforeChange(LyXText * text)
1215 text->clearSelection();
1219 void BufferView::Pimpl::savePosition(unsigned int i)
1221 if (i >= saved_positions_num)
1223 saved_positions[i] = Position(buffer_->fileName(),
1224 bv_->text->cursor.par()->id(),
1225 bv_->text->cursor.pos());
1228 str << _("Saved bookmark") << ' ' << i;
1229 owner_->message(str.str().c_str());
1234 void BufferView::Pimpl::restorePosition(unsigned int i)
1236 if (i >= saved_positions_num)
1239 string const fname = saved_positions[i].filename;
1241 beforeChange(bv_->text);
1243 if (fname != buffer_->fileName()) {
1244 Buffer * b = bufferlist.exists(fname) ?
1245 bufferlist.getBuffer(fname) :
1246 bufferlist.loadLyXFile(fname); // don't ask, just load it
1247 if (b != 0) buffer(b);
1250 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1254 bv_->text->setCursor(bv_, par,
1255 min(par->size(), saved_positions[i].par_pos));
1257 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1260 str << _("Moved to bookmark") << ' ' << i;
1261 owner_->message(str.str().c_str());
1266 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1268 if (i >= saved_positions_num)
1271 return !saved_positions[i].filename.empty();
1275 void BufferView::Pimpl::setState()
1277 if (!lyxrc.rtl_support)
1280 LyXText * text = bv_->getLyXText();
1281 if (text->real_current_font.isRightToLeft()) {
1282 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1283 owner_->getIntl()->KeyMapSec();
1285 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1286 owner_->getIntl()->KeyMapPrim();
1291 void BufferView::Pimpl::insetSleep()
1293 if (bv_->theLockingInset() && !inset_slept) {
1294 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1295 bv_->theLockingInset()->insetUnlock(bv_);
1301 void BufferView::Pimpl::insetWakeup()
1303 if (bv_->theLockingInset() && inset_slept) {
1304 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1305 inset_slept = false;
1310 void BufferView::Pimpl::insetUnlock()
1312 if (bv_->theLockingInset()) {
1314 bv_->theLockingInset()->insetUnlock(bv_);
1315 bv_->theLockingInset(0);
1317 inset_slept = false;
1322 bool BufferView::Pimpl::focus() const
1324 return workarea_.hasFocus();
1328 void BufferView::Pimpl::focus(bool f)
1330 if (f) workarea_.setFocus();
1334 bool BufferView::Pimpl::active() const
1336 return workarea_.active();
1340 bool BufferView::Pimpl::belowMouse() const
1342 return workarea_.belowMouse();
1346 void BufferView::Pimpl::showCursor()
1348 if (screen_.get()) {
1349 if (bv_->theLockingInset())
1350 bv_->theLockingInset()->showInsetCursor(bv_);
1352 screen_->showCursor(bv_->text, bv_);
1357 void BufferView::Pimpl::hideCursor()
1359 if (screen_.get()) {
1360 if (!bv_->theLockingInset())
1361 // bv_->theLockingInset()->hideInsetCursor(bv_);
1363 screen_->hideCursor();
1368 void BufferView::Pimpl::toggleSelection(bool b)
1370 if (screen_.get()) {
1371 if (bv_->theLockingInset())
1372 bv_->theLockingInset()->toggleSelection(bv_, b);
1373 screen_->toggleSelection(bv_->text, bv_, b);
1378 void BufferView::Pimpl::toggleToggle()
1381 screen_->toggleToggle(bv_->text, bv_);
1385 void BufferView::Pimpl::center()
1387 beforeChange(bv_->text);
1388 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1389 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1391 screen_->draw(bv_->text, bv_, 0);
1393 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1398 void BufferView::Pimpl::pasteClipboard(bool asPara)
1403 screen_->hideCursor();
1404 beforeChange(bv_->text);
1406 string const clip(workarea_.getClipboard());
1412 bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
1414 bv_->getLyXText()->insertStringAsLines(bv_, clip);
1416 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1420 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1422 workarea_.putClipboard(stuff);
1427 * Dispatch functions for actions which can be valid for BufferView->text
1428 * and/or InsetText->text!!!
1433 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1435 LyXText * lt = bv_->getLyXText();
1437 if (selecting || lt->selection.mark()) {
1438 lt->setSelection(bv_);
1442 updateInset(lt->inset_owner, false);
1445 update(lt, BufferView::SELECT|BufferView::FITCUR);
1449 if (!lt->selection.set())
1450 workarea_.haveSelection(false);
1452 /* ---> Everytime the cursor is moved, show the current font state. */
1453 // should this too me moved out of this func?
1454 //owner->showState();
1459 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1461 LyXCursor cursor = bv_->getLyXText()->cursor;
1462 Buffer::inset_iterator it =
1463 find_if(Buffer::inset_iterator(
1464 cursor.par(), cursor.pos()),
1465 buffer_->inset_iterator_end(),
1466 lyx::compare_memfun(&Inset::lyxCode, code));
1467 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1471 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1473 string filename = filen;
1475 if (filename.empty()) {
1476 // Launch a file browser
1477 string initpath = lyxrc.document_path;
1480 string const trypath = owner_->buffer()->filePath();
1481 // If directory is writeable, use this as default.
1482 if (IsDirWriteable(trypath))
1486 FileDialog fileDlg(bv_->owner(),
1487 _("Select LyX document to insert"),
1489 make_pair(string(_("Documents|#o#O")),
1490 string(lyxrc.document_path)),
1491 make_pair(string(_("Examples|#E#e")),
1492 string(AddPath(system_lyxdir, "examples"))));
1494 FileDialog::Result result =
1495 fileDlg.Select(initpath,
1496 _("*.lyx| LyX Documents (*.lyx)"));
1498 if (result.first == FileDialog::Later)
1501 filename = result.second;
1503 // check selected filename
1504 if (filename.empty()) {
1505 owner_->message(_("Canceled."));
1510 // get absolute path of file and add ".lyx" to the filename if
1512 filename = FileSearch(string(), filename, "lyx");
1514 string const disp_fn(MakeDisplayPath(filename));
1517 s1 << _("Inserting document") << ' '
1518 << disp_fn << " ...";
1519 owner_->message(s1.str().c_str());
1520 bool const res = bv_->insertLyXFile(filename);
1523 str << _("Document") << ' ' << disp_fn
1524 << ' ' << _("inserted.");
1525 owner_->message(str.str().c_str());
1528 str << _("Could not insert document") << ' '
1530 owner_->message(str.str().c_str());
1535 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1537 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1538 << action <<"] arg[" << argument << "]" << endl;
1541 // --- Misc -------------------------------------------
1545 LyXText * lt = bv_->getLyXText();
1546 lt->toggleAppendix(bv_);
1549 | BufferView::FITCUR
1550 | BufferView::CHANGE);
1555 case LFUN_TOC_INSERT:
1557 InsetCommandParams p;
1558 p.setCmdName("tableofcontents");
1559 Inset * inset = new InsetTOC(p);
1560 if (!insertInset(inset, "Standard"))
1565 case LFUN_SCROLL_INSET:
1566 // this is not handled here as this funktion is only aktive
1567 // if we have a locking_inset and that one is (or contains)
1571 case LFUN_INSET_GRAPHICS:
1573 Inset * new_inset = new InsetGraphics;
1574 if (!insertInset(new_inset)) {
1577 // this is need because you don't use a inset->Edit()
1578 updateInset(new_inset, true);
1579 new_inset->edit(bv_);
1589 case LFUN_PASTESELECTION:
1591 bool asPara = false;
1592 if (argument == "paragraph")
1594 pasteClipboard(asPara);
1606 case LFUN_LAYOUT_COPY:
1607 bv_->copyEnvironment();
1610 case LFUN_LAYOUT_PASTE:
1611 bv_->pasteEnvironment();
1615 case LFUN_GOTOERROR:
1616 gotoInset(Inset::ERROR_CODE, false);
1620 gotoInset(Inset::IGNORE_CODE, false);
1623 case LFUN_REFERENCE_GOTO:
1625 vector<Inset::Code> tmp;
1626 tmp.push_back(Inset::LABEL_CODE);
1627 tmp.push_back(Inset::REF_CODE);
1628 gotoInset(tmp, true);
1632 case LFUN_HYPHENATION:
1633 specialChar(InsetSpecialChar::HYPHENATION);
1636 case LFUN_LIGATURE_BREAK:
1637 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1641 specialChar(InsetSpecialChar::LDOTS);
1644 case LFUN_END_OF_SENTENCE:
1645 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1648 case LFUN_MENU_SEPARATOR:
1649 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1656 case LFUN_DEPTH_MIN:
1657 changeDepth(bv_, bv_->getLyXText(), -1);
1660 case LFUN_DEPTH_PLUS:
1661 changeDepth(bv_, bv_->getLyXText(), 1);
1665 owner_->getDialogs()->setUserFreeFont();
1668 case LFUN_FILE_INSERT:
1669 MenuInsertLyXFile(argument);
1672 case LFUN_FILE_INSERT_ASCII_PARA:
1673 InsertAsciiFile(bv_, argument, true);
1676 case LFUN_FILE_INSERT_ASCII:
1677 InsertAsciiFile(bv_, argument, false);
1682 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1683 << argument << endl;
1685 // Derive layout number from given argument (string)
1686 // and current buffer's textclass (number). */
1687 textclass_type tclass = buffer_->params.textclass;
1689 textclasslist[tclass].hasLayout(argument);
1690 string layout = argument;
1692 // If the entry is obsolete, use the new one instead.
1694 string const & obs = textclasslist[tclass][layout]
1701 owner_->getLyXFunc()->setErrorMessage(
1702 string(N_("Layout ")) + argument +
1707 if (current_layout != layout) {
1708 LyXText * lt = bv_->getLyXText();
1710 current_layout = layout;
1713 | BufferView::FITCUR);
1714 lt->setLayout(bv_, layout);
1715 owner_->setLayout(layout);
1718 | BufferView::FITCUR
1719 | BufferView::CHANGE);
1726 lang(bv_, argument);
1728 owner_->showState();
1733 owner_->showState();
1738 owner_->showState();
1743 owner_->showState();
1748 owner_->showState();
1753 owner_->showState();
1758 owner_->showState();
1763 owner_->showState();
1766 case LFUN_UNDERLINE:
1768 owner_->showState();
1771 case LFUN_FONT_SIZE:
1772 fontSize(bv_, argument);
1773 owner_->showState();
1776 case LFUN_FONT_STATE:
1777 owner_->getLyXFunc()->setMessage(currentState(bv_));
1780 case LFUN_UPCASE_WORD:
1782 LyXText * lt = bv_->getLyXText();
1786 | BufferView::FITCUR);
1787 lt->changeCase(bv_, LyXText::text_uppercase);
1788 if (lt->inset_owner)
1789 updateInset(lt->inset_owner, true);
1792 | BufferView::FITCUR
1793 | BufferView::CHANGE);
1797 case LFUN_LOWCASE_WORD:
1799 LyXText * lt = bv_->getLyXText();
1801 update(lt, BufferView::SELECT|BufferView::FITCUR);
1802 lt->changeCase(bv_, LyXText::text_lowercase);
1803 if (lt->inset_owner)
1804 updateInset(lt->inset_owner, true);
1807 | BufferView::FITCUR
1808 | BufferView::CHANGE);
1812 case LFUN_CAPITALIZE_WORD:
1814 LyXText * lt = bv_->getLyXText();
1816 update(lt, BufferView::SELECT|BufferView::FITCUR);
1817 lt->changeCase(bv_, LyXText::text_capitalization);
1818 if (lt->inset_owner)
1819 updateInset(lt->inset_owner, true);
1822 | BufferView::FITCUR
1823 | BufferView::CHANGE);
1827 case LFUN_TRANSPOSE_CHARS:
1829 LyXText * lt = bv_->getLyXText();
1831 update(lt, BufferView::SELECT|BufferView::FITCUR);
1832 lt->transposeChars(*bv_);
1833 if (lt->inset_owner)
1834 updateInset(lt->inset_owner, true);
1837 | BufferView::FITCUR
1838 | BufferView::CHANGE);
1843 case LFUN_INSERT_LABEL:
1844 MenuInsertLabel(bv_, argument);
1847 case LFUN_REF_INSERT:
1848 if (argument.empty()) {
1849 InsetCommandParams p("ref");
1850 owner_->getDialogs()->createRef(p.getAsString());
1852 InsetCommandParams p;
1853 p.setFromString(argument);
1855 InsetRef * inset = new InsetRef(p, *buffer_);
1856 if (!insertInset(inset))
1859 updateInset(inset, true);
1863 case LFUN_BOOKMARK_SAVE:
1864 savePosition(strToUnsignedInt(argument));
1867 case LFUN_BOOKMARK_GOTO:
1868 restorePosition(strToUnsignedInt(argument));
1873 string label(argument);
1874 if (label.empty()) {
1876 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1878 label = inset->getContents();
1883 if (!label.empty()) {
1884 //bv_->savePosition(0);
1885 if (!bv_->gotoLabel(label))
1886 Alert::alert(_("Error"),
1887 _("Couldn't find this label"),
1888 _("in current document."));
1893 // --- Cursor Movements -----------------------------
1896 LyXText * lt = bv_->getLyXText();
1898 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1899 if (!lt->selection.mark())
1901 update(lt, BufferView::SELECT|BufferView::FITCUR);
1903 lt->cursorLeft(bv_, false);
1904 if (lt->cursor.pos() < lt->cursor.par()->size()
1905 && lt->cursor.par()->isInset(lt->cursor.pos())
1906 && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1907 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1908 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1910 tmpinset->edit(bv_, false);
1912 tmpinset->edit(bv_);
1916 lt->cursorRight(bv_, false);
1918 moveCursorUpdate(false);
1919 owner_->showState();
1925 // This is soooo ugly. Isn`t it possible to make
1926 // it simpler? (Lgb)
1927 LyXText * lt = bv_->getLyXText();
1928 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1929 if (!lt->selection.mark())
1931 update(lt, BufferView::SELECT|BufferView::FITCUR);
1932 LyXCursor const cur = lt->cursor;
1934 lt->cursorLeft(bv_, false);
1935 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1936 lt->cursor.pos() < lt->cursor.par()->size() &&
1937 lt->cursor.par()->isInset(lt->cursor.pos()) &&
1938 isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
1939 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1940 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1942 tmpinset->edit(bv_);
1944 tmpinset->edit(bv_, false);
1948 lt->cursorRight(bv_, false);
1951 moveCursorUpdate(false);
1952 owner_->showState();
1958 LyXText * lt = bv_->getLyXText();
1960 if (!lt->selection.mark())
1962 update(lt, BufferView::UPDATE);
1965 moveCursorUpdate(false);
1966 owner_->showState();
1972 LyXText * lt = bv_->getLyXText();
1974 if (!lt->selection.mark())
1976 update(lt, BufferView::UPDATE);
1977 lt->cursorDown(bv_);
1979 moveCursorUpdate(false);
1980 owner_->showState();
1984 case LFUN_UP_PARAGRAPH:
1986 LyXText * lt = bv_->getLyXText();
1988 if (!lt->selection.mark())
1990 update(lt, BufferView::UPDATE);
1991 lt->cursorUpParagraph(bv_);
1993 moveCursorUpdate(false);
1994 owner_->showState();
1998 case LFUN_DOWN_PARAGRAPH:
2000 LyXText * lt = bv_->getLyXText();
2002 if (!lt->selection.mark())
2004 update(lt, BufferView::UPDATE);
2005 lt->cursorDownParagraph(bv_);
2007 moveCursorUpdate(false);
2008 owner_->showState();
2014 LyXText * lt = bv_->getLyXText();
2016 if (!lt->selection.mark())
2018 update(lt, BufferView::UPDATE);
2021 moveCursorUpdate(false);
2022 owner_->showState();
2028 LyXText * lt = bv_->getLyXText();
2030 if (!lt->selection.mark())
2032 update(lt, BufferView::UPDATE);
2035 moveCursorUpdate(false);
2036 owner_->showState();
2042 LyXText * lt = bv_->getLyXText();
2044 if (!lt->selection.mark())
2046 update(lt, BufferView::SELECT|BufferView::FITCUR);
2047 lt->cursorHome(bv_);
2049 moveCursorUpdate(false);
2050 owner_->showState();
2056 LyXText * lt = bv_->getLyXText();
2058 if (!lt->selection.mark())
2061 BufferView::SELECT|BufferView::FITCUR);
2064 moveCursorUpdate(false);
2065 owner_->showState();
2069 case LFUN_SHIFT_TAB:
2072 LyXText * lt = bv_->getLyXText();
2074 if (!lt->selection.mark())
2077 BufferView::SELECT|BufferView::FITCUR);
2080 moveCursorUpdate(false);
2081 owner_->showState();
2085 case LFUN_WORDRIGHT:
2087 LyXText * lt = bv_->getLyXText();
2089 if (!lt->selection.mark())
2091 update(lt, BufferView::SELECT|BufferView::FITCUR);
2092 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2093 lt->cursorLeftOneWord(bv_);
2095 lt->cursorRightOneWord(bv_);
2097 moveCursorUpdate(false);
2098 owner_->showState();
2104 LyXText * lt = bv_->getLyXText();
2106 if (!lt->selection.mark())
2108 update(lt, BufferView::SELECT|BufferView::FITCUR);
2109 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2110 lt->cursorRightOneWord(bv_);
2112 lt->cursorLeftOneWord(bv_);
2114 moveCursorUpdate(false);
2115 owner_->showState();
2119 case LFUN_BEGINNINGBUF:
2121 LyXText * lt = bv_->getLyXText();
2123 if (!lt->selection.mark())
2126 BufferView::SELECT|BufferView::FITCUR);
2129 moveCursorUpdate(false);
2130 owner_->showState();
2136 LyXText * lt = bv_->getLyXText();
2138 if (!lt->selection.mark())
2141 BufferView::SELECT|BufferView::FITCUR);
2142 lt->cursorBottom(bv_);
2144 moveCursorUpdate(false);
2145 owner_->showState();
2149 /* cursor selection ---------------------------- */
2152 LyXText * lt = bv_->getLyXText();
2155 BufferView::SELECT|BufferView::FITCUR);
2156 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2157 lt->cursorLeft(bv_);
2159 lt->cursorRight(bv_);
2161 moveCursorUpdate(true);
2162 owner_->showState();
2168 LyXText * lt = bv_->getLyXText();
2171 BufferView::SELECT|BufferView::FITCUR);
2172 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2173 lt->cursorRight(bv_);
2175 lt->cursorLeft(bv_);
2177 moveCursorUpdate(true);
2178 owner_->showState();
2184 LyXText * lt = bv_->getLyXText();
2187 BufferView::SELECT|BufferView::FITCUR);
2190 moveCursorUpdate(true);
2191 owner_->showState();
2197 LyXText * lt = bv_->getLyXText();
2200 BufferView::SELECT|BufferView::FITCUR);
2201 lt->cursorDown(bv_);
2203 moveCursorUpdate(true);
2204 owner_->showState();
2208 case LFUN_UP_PARAGRAPHSEL:
2210 LyXText * lt = bv_->getLyXText();
2213 BufferView::SELECT|BufferView::FITCUR);
2214 lt->cursorUpParagraph(bv_);
2216 moveCursorUpdate(true);
2217 owner_->showState();
2221 case LFUN_DOWN_PARAGRAPHSEL:
2223 LyXText * lt = bv_->getLyXText();
2226 BufferView::SELECT|BufferView::FITCUR);
2227 lt->cursorDownParagraph(bv_);
2229 moveCursorUpdate(true);
2230 owner_->showState();
2236 LyXText * lt = bv_->getLyXText();
2238 update(lt, BufferView::SELECT|BufferView::FITCUR);
2241 moveCursorUpdate(true);
2242 owner_->showState();
2248 LyXText * lt = bv_->getLyXText();
2250 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 moveCursorUpdate(true);
2254 owner_->showState();
2260 LyXText * lt = bv_->getLyXText();
2262 update(lt, BufferView::SELECT|BufferView::FITCUR);
2263 lt->cursorHome(bv_);
2265 moveCursorUpdate(true);
2266 owner_->showState();
2272 LyXText * lt = bv_->getLyXText();
2274 update(lt, BufferView::SELECT|BufferView::FITCUR);
2277 moveCursorUpdate(true);
2278 owner_->showState();
2282 case LFUN_WORDRIGHTSEL:
2284 LyXText * lt = bv_->getLyXText();
2286 update(lt, BufferView::SELECT|BufferView::FITCUR);
2287 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2288 lt->cursorLeftOneWord(bv_);
2290 lt->cursorRightOneWord(bv_);
2292 moveCursorUpdate(true);
2293 owner_->showState();
2297 case LFUN_WORDLEFTSEL:
2299 LyXText * lt = bv_->getLyXText();
2301 update(lt, BufferView::SELECT|BufferView::FITCUR);
2302 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2303 lt->cursorRightOneWord(bv_);
2305 lt->cursorLeftOneWord(bv_);
2307 moveCursorUpdate(true);
2308 owner_->showState();
2312 case LFUN_BEGINNINGBUFSEL:
2314 LyXText * lt = bv_->getLyXText();
2316 if (lt->inset_owner)
2318 update(lt, BufferView::SELECT|BufferView::FITCUR);
2321 moveCursorUpdate(true);
2322 owner_->showState();
2326 case LFUN_ENDBUFSEL:
2328 LyXText * lt = bv_->getLyXText();
2330 if (lt->inset_owner)
2333 BufferView::SELECT|BufferView::FITCUR);
2334 lt->cursorBottom(bv_);
2336 moveCursorUpdate(true);
2337 owner_->showState();
2341 // --- text changing commands ------------------------
2342 case LFUN_BREAKLINE:
2344 LyXText * lt = bv_->getLyXText();
2347 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2350 | BufferView::FITCUR
2351 | BufferView::CHANGE);
2352 moveCursorUpdate(false);
2356 case LFUN_PROTECTEDSPACE:
2358 LyXText * lt = bv_->getLyXText();
2360 LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
2362 if (style.free_spacing) {
2363 lt->insertChar(bv_, ' ');
2366 | BufferView::FITCUR
2367 | BufferView::CHANGE);
2369 specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
2371 moveCursorUpdate(false);
2377 LyXText * lt = bv_->getLyXText();
2379 if (lt->selection.mark()) {
2383 | BufferView::FITCUR);
2384 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2387 lt->selection.mark(true);
2390 | BufferView::FITCUR);
2391 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2393 lt->selection.cursor = lt->cursor;
2399 LyXText * lt = bv_->getLyXText();
2401 if (!lt->selection.set()) {
2403 lt->selection.cursor = lt->cursor;
2406 | BufferView::FITCUR
2407 | BufferView::CHANGE);
2408 // It is possible to make it a lot faster still
2409 // just comment out the line below...
2414 moveCursorUpdate(false);
2415 owner_->showState();
2420 case LFUN_DELETE_SKIP:
2422 LyXText * lt = bv_->getLyXText();
2424 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2426 LyXCursor cursor = lt->cursor;
2428 if (!lt->selection.set()) {
2429 if (cursor.pos() == cursor.par()->size()) {
2430 lt->cursorRight(bv_);
2431 cursor = lt->cursor;
2432 if (cursor.pos() == 0
2433 && !(cursor.par()->params().spaceTop()
2434 == VSpace (VSpace::NONE))) {
2437 cursor.par()->params().lineTop(),
2438 cursor.par()->params().lineBottom(),
2439 cursor.par()->params().pagebreakTop(),
2440 cursor.par()->params().pagebreakBottom(),
2441 VSpace(VSpace::NONE),
2442 cursor.par()->params().spaceBottom(),
2443 cursor.par()->params().spacing(),
2444 cursor.par()->params().align(),
2445 cursor.par()->params().labelWidthString(), 0);
2446 lt->cursorLeft(bv_);
2449 | BufferView::FITCUR
2450 | BufferView::CHANGE);
2452 lt->cursorLeft(bv_);
2454 lt->selection.cursor = lt->cursor;
2457 | BufferView::FITCUR
2458 | BufferView::CHANGE);
2462 lt->selection.cursor = lt->cursor;
2465 | BufferView::FITCUR
2466 | BufferView::CHANGE);
2474 /* -------> Delete word forward. */
2475 case LFUN_DELETE_WORD_FORWARD:
2476 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2477 bv_->getLyXText()->deleteWordForward(bv_);
2478 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2479 moveCursorUpdate(false);
2480 owner_->showState();
2483 /* -------> Delete word backward. */
2484 case LFUN_DELETE_WORD_BACKWARD:
2486 LyXText * lt = bv_->getLyXText();
2488 update(lt, BufferView::SELECT|BufferView::FITCUR);
2489 lt->deleteWordBackward(bv_);
2492 | BufferView::FITCUR
2493 | BufferView::CHANGE);
2494 moveCursorUpdate(false);
2495 owner_->showState();
2499 /* -------> Kill to end of line. */
2500 case LFUN_DELETE_LINE_FORWARD:
2502 LyXText * lt = bv_->getLyXText();
2504 update(lt, BufferView::SELECT|BufferView::FITCUR);
2505 lt->deleteLineForward(bv_);
2508 | BufferView::FITCUR
2509 | BufferView::CHANGE);
2510 moveCursorUpdate(false);
2514 /* -------> Set mark off. */
2517 LyXText * lt = bv_->getLyXText();
2520 update(lt, BufferView::SELECT|BufferView::FITCUR);
2521 lt->selection.cursor = lt->cursor;
2522 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2526 /* -------> Set mark on. */
2529 LyXText * lt = bv_->getLyXText();
2532 lt->selection.mark(true);
2533 update(lt, BufferView::SELECT|BufferView::FITCUR);
2534 lt->selection.cursor = lt->cursor;
2535 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2539 case LFUN_BACKSPACE:
2541 LyXText * lt = bv_->getLyXText();
2543 if (!lt->selection.set()) {
2544 if (owner_->getIntl()->getTrans().backspace()) {
2546 lt->selection.cursor = lt->cursor;
2549 | BufferView::FITCUR
2550 | BufferView::CHANGE);
2551 // It is possible to make it a lot faster still
2552 // just comment out the line below...
2558 owner_->showState();
2563 case LFUN_BACKSPACE_SKIP:
2565 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2566 LyXText * lt = bv_->getLyXText();
2568 LyXCursor cursor = lt->cursor;
2570 if (!lt->selection.set()) {
2571 if (cursor.pos() == 0
2572 && !(cursor.par()->params().spaceTop()
2573 == VSpace (VSpace::NONE))) {
2576 cursor.par()->params().lineTop(),
2577 cursor.par()->params().lineBottom(),
2578 cursor.par()->params().pagebreakTop(),
2579 cursor.par()->params().pagebreakBottom(),
2580 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2581 cursor.par()->params().spacing(),
2582 cursor.par()->params().align(),
2583 cursor.par()->params().labelWidthString(), 0);
2586 | BufferView::FITCUR
2587 | BufferView::CHANGE);
2590 lt->selection.cursor = cursor;
2593 | BufferView::FITCUR
2594 | BufferView::CHANGE);
2601 case LFUN_BREAKPARAGRAPH:
2603 LyXText * lt = bv_->getLyXText();
2606 lt->breakParagraph(bv_, 0);
2609 | BufferView::FITCUR
2610 | BufferView::CHANGE);
2611 lt->selection.cursor = lt->cursor;
2613 owner_->showState();
2617 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2619 LyXText * lt = bv_->getLyXText();
2622 lt->breakParagraph(bv_, 1);
2625 | BufferView::FITCUR
2626 | BufferView::CHANGE);
2627 lt->selection.cursor = lt->cursor;
2629 owner_->showState();
2633 case LFUN_BREAKPARAGRAPH_SKIP:
2635 // When at the beginning of a paragraph, remove
2636 // indentation and add a "defskip" at the top.
2637 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2638 LyXText * lt = bv_->getLyXText();
2640 LyXCursor cursor = lt->cursor;
2643 if (cursor.pos() == 0) {
2644 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2647 cursor.par()->params().lineTop(),
2648 cursor.par()->params().lineBottom(),
2649 cursor.par()->params().pagebreakTop(),
2650 cursor.par()->params().pagebreakBottom(),
2651 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2652 cursor.par()->params().spacing(),
2653 cursor.par()->params().align(),
2654 cursor.par()->params().labelWidthString(), 1);
2655 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2659 lt->breakParagraph(bv_, 0);
2660 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2665 | BufferView::FITCUR
2666 | BufferView::CHANGE);
2667 lt->selection.cursor = cursor;
2669 owner_->showState();
2673 case LFUN_PARAGRAPH_SPACING:
2675 LyXText * lt = bv_->getLyXText();
2677 Paragraph * par = lt->cursor.par();
2678 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2679 float cur_value = 1.0;
2680 if (cur_spacing == Spacing::Other) {
2681 cur_value = par->params().spacing().getValue();
2684 istringstream istr(argument.c_str());
2688 Spacing::Space new_spacing = cur_spacing;
2689 float new_value = cur_value;
2691 lyxerr << "Missing argument to `paragraph-spacing'"
2693 } else if (tmp == "single") {
2694 new_spacing = Spacing::Single;
2695 } else if (tmp == "onehalf") {
2696 new_spacing = Spacing::Onehalf;
2697 } else if (tmp == "double") {
2698 new_spacing = Spacing::Double;
2699 } else if (tmp == "other") {
2700 new_spacing = Spacing::Other;
2703 lyxerr << "new_value = " << tmpval << endl;
2706 } else if (tmp == "default") {
2707 new_spacing = Spacing::Default;
2709 lyxerr << _("Unknown spacing argument: ")
2710 << argument << endl;
2712 if (cur_spacing != new_spacing || cur_value != new_value) {
2713 par->params().spacing(Spacing(new_spacing, new_value));
2714 lt->redoParagraph(bv_);
2717 | BufferView::FITCUR
2718 | BufferView::CHANGE);
2723 case LFUN_INSET_TOGGLE:
2725 LyXText * lt = bv_->getLyXText();
2728 update(lt, BufferView::SELECT|BufferView::FITCUR);
2729 lt->toggleInset(bv_);
2730 update(lt, BufferView::SELECT|BufferView::FITCUR);
2742 InsetCommandParams p;
2743 if (action == LFUN_HTMLURL)
2744 p.setCmdName("htmlurl");
2746 p.setCmdName("url");
2747 owner_->getDialogs()->createUrl(p.getAsString());
2751 case LFUN_INSERT_URL:
2753 InsetCommandParams p;
2754 p.setFromString(argument);
2756 InsetUrl * inset = new InsetUrl(p);
2757 if (!insertInset(inset))
2760 updateInset(inset, true);
2764 case LFUN_INSET_ERT:
2765 insertAndEditInset(new InsetERT(buffer_->params));
2768 case LFUN_INSET_EXTERNAL:
2769 insertAndEditInset(new InsetExternal);
2772 case LFUN_INSET_FOOTNOTE:
2773 insertAndEditInset(new InsetFoot(buffer_->params));
2776 case LFUN_INSET_MARGINAL:
2777 insertAndEditInset(new InsetMarginal(buffer_->params));
2780 case LFUN_INSET_MINIPAGE:
2781 insertAndEditInset(new InsetMinipage(buffer_->params));
2784 case LFUN_INSERT_NOTE:
2785 insertAndEditInset(new InsetNote(buffer_->params));
2788 case LFUN_INSET_FLOAT:
2789 // check if the float type exist
2790 if (floatList.typeExist(argument)) {
2791 insertAndEditInset(new InsetFloat(buffer_->params,
2794 lyxerr << "Non-existent float type: "
2795 << argument << endl;
2799 case LFUN_INSET_WIDE_FLOAT:
2801 // check if the float type exist
2802 if (floatList.typeExist(argument)) {
2803 InsetFloat * new_inset =
2804 new InsetFloat(buffer_->params, argument);
2805 new_inset->wide(true);
2806 if (insertInset(new_inset))
2807 new_inset->edit(bv_);
2811 lyxerr << "Non-existent float type: "
2812 << argument << endl;
2819 case LFUN_INSET_LIST:
2820 insertAndEditInset(new InsetList);
2823 case LFUN_INSET_THEOREM:
2824 insertAndEditInset(new InsetTheorem);
2828 case LFUN_INSET_CAPTION:
2830 // Do we have a locking inset...
2831 if (bv_->theLockingInset()) {
2832 lyxerr << "Locking inset code: "
2833 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2834 InsetCaption * new_inset =
2835 new InsetCaption(buffer_->params);
2836 new_inset->setOwner(bv_->theLockingInset());
2837 new_inset->setAutoBreakRows(true);
2838 new_inset->setDrawFrame(0, InsetText::LOCKED);
2839 new_inset->setFrameColor(0, LColor::captionframe);
2840 if (insertInset(new_inset))
2841 new_inset->edit(bv_);
2848 case LFUN_INSET_TABULAR:
2852 if (!argument.empty())
2853 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2854 InsetTabular * new_inset =
2855 new InsetTabular(*buffer_, r, c);
2857 bv_->getLyXText()->real_current_font.isRightToLeft();
2858 if (!open_new_inset(new_inset, rtl))
2863 // --- lyxserver commands ----------------------------
2865 case LFUN_CHARATCURSOR:
2867 pos_type pos = bv_->getLyXText()->cursor.pos();
2868 if (pos < bv_->getLyXText()->cursor.par()->size())
2869 owner_->getLyXFunc()->setMessage(
2870 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2872 owner_->getLyXFunc()->setMessage("EOF");
2877 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2879 + tostr(bv_->getLyXText()->cursor.y()));
2886 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2887 lyxerr << "SETXY: Could not parse coordinates in '"
2888 << argument << std::endl;
2890 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2894 case LFUN_GETLAYOUT:
2895 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
2900 LyXFont & font = bv_->getLyXText()->current_font;
2901 if (font.shape() == LyXFont::ITALIC_SHAPE)
2902 owner_->getLyXFunc()->setMessage("E");
2903 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2904 owner_->getLyXFunc()->setMessage("N");
2906 owner_->getLyXFunc()->setMessage("0");
2911 // --- accented characters ---------------------------
2914 case LFUN_CIRCUMFLEX:
2924 case LFUN_SPECIAL_CARON:
2927 case LFUN_HUNG_UMLAUT:
2930 if (argument.empty()) {
2932 owner_->getLyXFunc()->handleKeyFunc(action);
2934 owner_->getLyXFunc()->handleKeyFunc(action);
2935 owner_->getIntl()->getTrans()
2936 .TranslateAndInsert(argument[0], bv_->getLyXText());
2937 update(bv_->getLyXText(),
2939 | BufferView::FITCUR
2940 | BufferView::CHANGE);
2944 case LFUN_MATH_MACRO:
2945 mathDispatchMathMacro(bv_, argument);
2948 case LFUN_MATH_DELIM:
2949 mathDispatchMathDelim(bv_, argument);
2952 case LFUN_INSERT_MATRIX:
2953 mathDispatchInsertMatrix(bv_, argument);
2956 case LFUN_INSERT_MATH:
2957 mathDispatchInsertMath(bv_, argument);
2960 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2961 mathDispatchMathImportSelection(bv_, argument);
2964 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2965 mathDispatchMathDisplay(bv_, argument);
2968 case LFUN_MATH_MODE: // Open or create an inlined math inset
2969 mathDispatchMathMode(bv_, argument);
2972 case LFUN_GREEK: // Insert a single greek letter
2973 mathDispatchGreek(bv_, argument);
2976 case LFUN_CITATION_INSERT:
2978 InsetCommandParams p;
2979 p.setFromString(argument);
2981 InsetCitation * inset = new InsetCitation(p);
2982 if (!insertInset(inset))
2985 updateInset(inset, true);
2989 case LFUN_INSERT_BIBTEX:
2991 // ale970405+lasgoutt970425
2992 // The argument can be up to two tokens separated
2993 // by a space. The first one is the bibstyle.
2994 string const db = token(argument, ' ', 0);
2995 string const bibstyle = token(argument, ' ', 1);
2997 InsetCommandParams p("BibTeX", db, bibstyle);
2998 InsetBibtex * inset = new InsetBibtex(p);
3000 if (insertInset(inset)) {
3001 if (argument.empty())
3008 // BibTeX data bases
3009 case LFUN_BIBDB_ADD:
3011 InsetBibtex * inset =
3012 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3014 inset->addDatabase(argument);
3019 case LFUN_BIBDB_DEL:
3021 InsetBibtex * inset =
3022 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3024 inset->delDatabase(argument);
3029 case LFUN_BIBTEX_STYLE:
3031 InsetBibtex * inset =
3032 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3034 inset->setOptions(argument);
3039 case LFUN_INDEX_CREATE:
3041 InsetCommandParams p("index");
3042 if (argument.empty()) {
3043 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3044 p.setContents(idxstring);
3046 p.setContents(argument);
3049 owner_->getDialogs()->createIndex(p.getAsString());
3053 case LFUN_INDEX_INSERT:
3055 InsetCommandParams p;
3056 p.setFromString(argument);
3057 InsetIndex * inset = new InsetIndex(p);
3059 if (!insertInset(inset))
3062 updateInset(inset, true);
3066 case LFUN_INDEX_INSERT_LAST:
3068 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3069 if (!idxstring.empty()) {
3070 owner_->message(_("Word `")
3071 + idxstring + _(("' indexed.")));
3072 InsetCommandParams p("index", idxstring);
3073 InsetIndex * inset = new InsetIndex(p);
3075 if (!insertInset(inset))
3078 updateInset(inset, true);
3083 case LFUN_INDEX_PRINT:
3085 InsetCommandParams p("printindex");
3086 Inset * inset = new InsetPrintIndex(p);
3087 if (!insertInset(inset, "Standard"))
3092 case LFUN_PARENTINSERT:
3094 InsetCommandParams p("lyxparent", argument);
3095 Inset * inset = new InsetParent(p, *buffer_);
3096 if (!insertInset(inset, "Standard"))
3102 case LFUN_CHILD_INSERT:
3104 InsetInclude::Params p;
3105 p.cparams.setFromString(argument);
3106 p.masterFilename_ = buffer_->fileName();
3108 InsetInclude * inset = new InsetInclude(p);
3109 if (!insertInset(inset))
3112 updateInset(inset, true);
3113 bv_->owner()->getDialogs()->showInclude(inset);
3118 case LFUN_FLOAT_LIST:
3120 // We should check the argument for validity. (Lgb)
3121 Inset * inset = new InsetFloatList(argument);
3122 if (!insertInset(inset, "Standard"))
3127 case LFUN_THESAURUS_ENTRY:
3129 string arg = argument;
3132 arg = bv_->getLyXText()->selectionAsString(buffer_,
3136 if (arg.size() > 100 || arg.empty()) {
3137 // Get word or selection
3138 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3139 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
3140 // FIXME: where is getLyXText()->unselect(bv_) ?
3144 bv_->owner()->getDialogs()->showThesaurus(arg);
3148 case LFUN_SELFINSERT:
3150 if (argument.empty()) break;
3152 /* Automatically delete the currently selected
3153 * text and replace it with what is being
3154 * typed in now. Depends on lyxrc settings
3155 * "auto_region_delete", which defaults to
3158 LyXText * lt = bv_->getLyXText();
3160 if (lyxrc.auto_region_delete) {
3161 if (lt->selection.set()) {
3162 lt->cutSelection(bv_, false, false);
3165 | BufferView::FITCUR
3166 | BufferView::CHANGE);
3168 workarea_.haveSelection(false);
3172 LyXFont const old_font(lt->real_current_font);
3174 string::const_iterator cit = argument.begin();
3175 string::const_iterator end = argument.end();
3176 for (; cit != end; ++cit) {
3177 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3182 | BufferView::FITCUR
3183 | BufferView::CHANGE);
3185 lt->selection.cursor = lt->cursor;
3186 moveCursorUpdate(false);
3188 // real_current_font.number can change so we need to
3189 // update the minibuffer
3190 if (old_font != lt->real_current_font)
3191 owner_->showState();
3196 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3198 time_t now_time_t = time(NULL);
3199 struct tm * now_tm = localtime(&now_time_t);
3200 setlocale(LC_TIME, "");
3202 if (!argument.empty())
3205 arg = lyxrc.date_insert_format;
3207 int const datetmp_len =
3208 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3210 LyXText * lt = bv_->getLyXText();
3212 for (int i = 0; i < datetmp_len; i++) {
3213 lt->insertChar(bv_, datetmp[i]);
3216 | BufferView::FITCUR
3217 | BufferView::CHANGE);
3220 lt->selection.cursor = lt->cursor;
3221 moveCursorUpdate(false);
3225 case LFUN_UNKNOWN_ACTION:
3226 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3237 void BufferView::Pimpl::newline()
3240 LyXText * lt = bv_->getLyXText();
3244 | BufferView::FITCUR);
3245 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3248 | BufferView::FITCUR
3249 | BufferView::CHANGE);
3254 void BufferView::Pimpl::hfill()
3257 LyXText * lt = bv_->getLyXText();
3261 | BufferView::FITCUR);
3262 lt->insertChar(bv_, Paragraph::META_HFILL);
3265 | BufferView::FITCUR
3266 | BufferView::CHANGE);
3271 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3274 LyXText * lt = bv_->getLyXText();
3277 update(lt, BufferView::SELECT|BufferView::FITCUR);
3278 InsetSpecialChar * new_inset =
3279 new InsetSpecialChar(kind);
3280 if (!insertInset(new_inset))
3283 updateInset(new_inset, true);
3288 void BufferView::Pimpl::smartQuote()
3290 LyXText const * lt = bv_->getLyXText();
3291 Paragraph const * par = lt->cursor.par();
3292 pos_type pos = lt->cursor.pos();
3296 || (par->isInset(pos - 1)
3297 && par->getInset(pos - 1)->isSpace()))
3300 c = par->getChar(pos - 1);
3305 LyXLayout const & style =
3306 textclasslist[bv_->buffer()->params.textclass][par->layout()];
3308 if (style.pass_thru ||
3309 (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
3310 bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
3314 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3316 if (insertInset(inset))
3323 // Open and lock an updatable inset
3324 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3326 LyXText * lt = bv_->getLyXText();
3330 if (!insertInset(new_inset)) {
3334 new_inset->edit(bv_, !behind);
3339 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3341 // if we are in a locking inset we should try to insert the
3342 // inset there otherwise this is a illegal function now
3343 if (bv_->theLockingInset()) {
3344 if (bv_->theLockingInset()->insetAllowed(inset))
3345 return bv_->theLockingInset()->insertInset(bv_, inset);
3349 // not quite sure if we want this...
3350 setCursorParUndo(bv_);
3353 beforeChange(bv_->text);
3354 if (!lout.empty()) {
3355 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3356 bv_->text->breakParagraph(bv_);
3357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3359 if (bv_->text->cursor.par()->size()) {
3360 bv_->text->cursorLeft(bv_);
3362 bv_->text->breakParagraph(bv_);
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 LyXTextClass const & tclass =
3368 textclasslist[buffer_->params.textclass];
3369 bool hasLayout = tclass.hasLayout(lres);
3370 string lay = tclass.defaultLayoutName();
3372 if (hasLayout != false) {
3376 // layout not fount using default
3377 lay = tclass.defaultLayoutName();
3380 bv_->text->setLayout(bv_, lay);
3382 bv_->text->setParagraph(bv_, 0, 0,
3384 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3392 bv_->text->insertInset(bv_, inset);
3393 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3400 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3402 if (!inset || !available())
3405 // first check for locking insets
3406 if (bv_->theLockingInset()) {
3407 if (bv_->theLockingInset() == inset) {
3408 if (bv_->text->updateInset(bv_, inset)) {
3411 buffer_->markDirty();
3416 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3417 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
3420 buffer_->markDirty();
3428 // then check if the inset is a top_level inset (has no owner)
3429 // if yes do the update as always otherwise we have to update the
3430 // toplevel inset where this inset is inside
3431 Inset * tl_inset = inset;
3432 while(tl_inset->owner())
3433 tl_inset = tl_inset->owner();
3435 if (tl_inset == inset) {
3436 update(bv_->text, BufferView::UPDATE);
3437 if (bv_->text->updateInset(bv_, inset)) {
3441 | BufferView::FITCUR
3442 | BufferView::CHANGE);
3444 update(bv_->text, SELECT);
3448 } else if (static_cast<UpdatableInset *>(tl_inset)
3449 ->updateInsetInInset(bv_, inset))
3451 if (bv_->text->updateInset(bv_, tl_inset)) {
3459 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3462 if (!available()) return;
3465 beforeChange(bv_->text);
3466 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3468 LyXCursor const & cursor = bv_->text->cursor;
3472 cursor.par()->isInset(cursor.pos())) {
3473 Inset const * inset = cursor.par()->getInset(cursor.pos());
3474 if (find(codes.begin(), codes.end(), inset->lyxCode())
3477 static_cast<InsetCommand const *>(inset)->getContents();
3481 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3482 if (bv_->text->cursor.pos()
3483 || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
3484 LyXCursor tmp = bv_->text->cursor;
3485 bv_->text->cursor.par(bv_->text->ownerParagraph());
3486 bv_->text->cursor.pos(0);
3487 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3488 bv_->text->cursor = tmp;
3489 bv_->owner()->message(_("No more insets"));
3492 bv_->owner()->message(_("No more insets"));
3495 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3496 bv_->text->selection.cursor = bv_->text->cursor;
3500 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3502 gotoInset(vector<Inset::Code>(1, code), same_content);