2 * \file BufferView_pimpl.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
12 #pragma implementation
15 #include "BufferView_pimpl.h"
16 #include "frontends/WorkArea.h"
17 #include "frontends/screen.h"
18 #include "frontends/LyXScreenFactory.h"
19 #include "frontends/WorkAreaFactory.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/Alert.h"
22 #include "frontends/FileDialog.h"
25 #include "paragraph.h"
26 #include "frontends/LyXView.h"
27 #include "commandtags.h"
30 #include "bufferview_funcs.h"
31 #include "TextCache.h"
32 #include "bufferlist.h"
35 // added for Dispatch functions
38 #include "FloatList.h"
40 #include "ParagraphParameters.h"
41 #include "undo_funcs.h"
42 #include "funcrequest.h"
45 #include "insets/insetbib.h"
46 #include "insets/insettext.h"
47 #include "insets/inseturl.h"
48 #include "insets/insetlatexaccent.h"
49 #include "insets/insettoc.h"
50 #include "insets/insetref.h"
51 #include "insets/insetparent.h"
52 #include "insets/insetindex.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetgraphics.h"
56 #include "insets/insetmarginal.h"
57 #include "insets/insettabular.h"
58 #include "insets/insetcaption.h"
59 #include "insets/insetfloatlist.h"
61 #include "mathed/formulabase.h"
63 #include "graphics/Previews.h"
65 #include "support/LAssert.h"
66 #include "support/lstrings.h"
67 #include "support/filetools.h"
69 #include <boost/bind.hpp>
70 #include <boost/signals/connection.hpp>
87 /* the selection possible is needed, that only motion events are
88 * used, where the bottom press event was on the drawing area too */
89 bool selection_possible = false;
91 extern BufferList bufferlist;
92 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
97 unsigned int const saved_positions_num = 20;
99 // All the below connection objects are needed because of a bug in some
100 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
101 // to these connections we avoid a segfault upon startup, and also at exit.
104 boost::signals::connection timecon;
105 boost::signals::connection doccon;
106 boost::signals::connection resizecon;
107 boost::signals::connection bpresscon;
108 boost::signals::connection breleasecon;
109 boost::signals::connection motioncon;
110 boost::signals::connection doublecon;
111 boost::signals::connection triplecon;
112 boost::signals::connection kpresscon;
113 boost::signals::connection selectioncon;
114 boost::signals::connection lostcon;
119 BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
120 int xpos, int ypos, int width, int height)
121 : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
122 using_xterm_cursor(false)
124 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
125 screen_.reset(LyXScreenFactory::create(workarea()));
128 doccon = workarea().scrollDocView
129 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
130 resizecon = workarea().workAreaResize
131 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
132 bpresscon = workarea().workAreaButtonPress
133 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonPress, this, _1, _2, _3));
134 breleasecon = workarea().workAreaButtonRelease
135 .connect(boost::bind(&BufferView::Pimpl::workAreaButtonRelease, this, _1, _2, _3));
136 motioncon = workarea().workAreaMotionNotify
137 .connect(boost::bind(&BufferView::Pimpl::workAreaMotionNotify, this, _1, _2, _3));
138 doublecon = workarea().workAreaDoubleClick
139 .connect(boost::bind(&BufferView::Pimpl::doubleClick, this, _1, _2, _3));
140 triplecon = workarea().workAreaTripleClick
141 .connect(boost::bind(&BufferView::Pimpl::tripleClick, this, _1, _2, _3));
142 kpresscon = workarea().workAreaKeyPress
143 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
144 selectioncon = workarea().selectionRequested
145 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
146 lostcon = workarea().selectionLost
147 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
149 timecon = cursor_timeout.timeout
150 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
151 cursor_timeout.start();
152 saved_positions.resize(saved_positions_num);
156 WorkArea & BufferView::Pimpl::workarea() const
158 return *workarea_.get();
162 LyXScreen & BufferView::Pimpl::screen() const
164 return *screen_.get();
168 Painter & BufferView::Pimpl::painter() const
170 return workarea().getPainter();
174 void BufferView::Pimpl::buffer(Buffer * b)
176 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
179 buffer_->delUser(bv_);
181 // Put the old text into the TextCache, but
182 // only if the buffer is still loaded.
183 // Also set the owner of the test to 0
184 // bv_->text->owner(0);
185 textcache.add(buffer_, workarea().workWidth(), bv_->text);
186 if (lyxerr.debugging())
187 textcache.show(lyxerr, "BufferView::buffer");
192 // set current buffer
195 if (bufferlist.getState() == BufferList::CLOSING) return;
197 // if we are closing the buffer, use the first buffer as current
199 buffer_ = bufferlist.first();
203 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
204 buffer_->addUser(bv_);
206 // If we don't have a text object for this, we make one
207 if (bv_->text == 0) {
208 resizeCurrentBuffer();
211 // FIXME: needed when ?
213 screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
215 // Similarly, buffer-dependent dialogs should be updated or
216 // hidden. This should go here because some dialogs (eg ToC)
217 // require bv_->text.
218 owner_->getDialogs().updateBufferDependent(true);
220 lyxerr[Debug::INFO] << " No Buffer!" << endl;
221 owner_->getDialogs().hideBufferDependent();
223 // Also remove all remaining text's from the testcache.
224 // (there should not be any!) (if there is any it is a
226 if (lyxerr.debugging())
227 textcache.show(lyxerr, "buffer delete all");
233 owner_->updateMenubar();
234 owner_->updateToolbar();
235 owner_->updateLayoutChoice();
236 owner_->updateWindowTitle();
238 if (grfx::Previews::activated() && buffer_)
239 grfx::Previews::get().generateBufferPreviews(*buffer_);
243 bool BufferView::Pimpl::fitCursor()
247 if (bv_->theLockingInset()) {
248 bv_->theLockingInset()->fitInsetCursor(bv_);
251 ret = screen().fitCursor(bv_->text, bv_);
254 bv_->owner()->getDialogs().updateParagraph();
261 void BufferView::Pimpl::redoCurrentBuffer()
263 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
264 if (buffer_ && bv_->text) {
265 resizeCurrentBuffer();
267 owner_->updateLayoutChoice();
273 int BufferView::Pimpl::resizeCurrentBuffer()
275 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
278 Paragraph * selstartpar = 0;
279 Paragraph * selendpar = 0;
280 UpdatableInset * the_locking_inset = 0;
283 pos_type selstartpos = 0;
284 pos_type selendpos = 0;
285 bool selection = false;
286 bool mark_set = false;
288 owner_->prohibitInput();
290 owner_->message(_("Formatting document..."));
293 par = bv_->text->cursor.par();
294 pos = bv_->text->cursor.pos();
295 selstartpar = bv_->text->selection.start.par();
296 selstartpos = bv_->text->selection.start.pos();
297 selendpar = bv_->text->selection.end.par();
298 selendpos = bv_->text->selection.end.pos();
299 selection = bv_->text->selection.set();
300 mark_set = bv_->text->selection.mark();
301 the_locking_inset = bv_->theLockingInset();
302 buffer_->resizeInsets(bv_);
303 // I don't think the delete and new are necessary here we just could
304 // call only init! (Jug 20020419)
306 bv_->text = new LyXText(bv_);
307 bv_->text->init(bv_);
309 // See if we have a text in TextCache that fits
310 // the new buffer_ with the correct width.
311 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
313 if (lyxerr.debugging()) {
314 lyxerr << "Found a LyXText that fits:\n";
315 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
317 // Set the owner of the newly found text
318 // bv_->text->owner(bv_);
319 if (lyxerr.debugging())
320 textcache.show(lyxerr, "resizeCurrentBuffer");
322 bv_->text = new LyXText(bv_);
323 bv_->text->init(bv_);
324 //buffer_->resizeInsets(bv_);
329 bv_->text->selection.set(true);
330 // At this point just to avoid the Delete-Empty-Paragraph-
331 // Mechanism when setting the cursor.
332 bv_->text->selection.mark(mark_set);
334 bv_->text->setCursor(bv_, selstartpar, selstartpos);
335 bv_->text->selection.cursor = bv_->text->cursor;
336 bv_->text->setCursor(bv_, selendpar, selendpos);
337 bv_->text->setSelection(bv_);
338 bv_->text->setCursor(bv_, par, pos);
340 bv_->text->setCursor(bv_, par, pos);
341 bv_->text->selection.cursor = bv_->text->cursor;
342 bv_->text->selection.set(false);
344 // remake the inset locking
345 bv_->theLockingInset(the_locking_inset);
348 bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
351 owner_->allowInput();
359 void BufferView::Pimpl::repaint()
361 // Regenerate the screen.
362 screen().redraw(bv_->text, bv_);
366 void BufferView::Pimpl::updateScrollbar()
369 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
370 workarea().setScrollbarParams(0, 0, 0);
374 LyXText const & t = *bv_->text;
376 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
377 << t.first_y << ", default height " << t.defaultHeight() << endl;
379 workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
383 void BufferView::Pimpl::scrollDocView(int value)
385 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
387 if (!buffer_) return;
389 screen().draw(bv_->text, bv_, value);
391 if (!lyxrc.cursor_follows_scrollbar) {
395 LyXText * vbt = bv_->text;
397 int const height = vbt->defaultHeight();
398 int const first = static_cast<int>((bv_->text->first_y + height));
399 int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
401 if (vbt->cursor.y() < first)
402 vbt->setCursorFromCoordinates(bv_, 0, first);
403 else if (vbt->cursor.y() > last)
404 vbt->setCursorFromCoordinates(bv_, 0, last);
408 int BufferView::Pimpl::scroll(long time)
413 LyXText const * t = bv_->text;
415 double const diff = t->defaultHeight()
416 + double(time) * double(time) * 0.125;
418 scrollDocView(int(diff));
419 workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
424 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
425 key_modifier::state state)
427 bv_->owner()->getLyXFunc().processKeySym(key, state);
431 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, mouse_button::state state)
433 // Only use motion with button 1
434 if (!(state & mouse_button::button1))
440 // Check for inset locking
441 if (bv_->theLockingInset()) {
442 LyXCursor cursor = bv_->text->cursor;
443 LyXFont font = bv_->text->getFont(buffer_,
444 cursor.par(), cursor.pos());
445 int width = bv_->theLockingInset()->width(bv_, font);
446 int inset_x = font.isVisibleRightToLeft()
447 ? cursor.ix() - width : cursor.ix();
448 int start_x = inset_x + bv_->theLockingInset()->scroll();
450 FuncRequest cmd(bv_, LFUN_MOUSE_MOTION,
451 x - start_x, y - cursor.iy() + bv_->text->first_y, state);
452 bv_->theLockingInset()->localDispatch(cmd);
456 // The test for not selection possible is needed, that only motion
457 // events are used, where the bottom press event was on
458 // the drawing area too
459 if (!selection_possible)
462 screen().hideCursor();
464 Row * cursorrow = bv_->text->cursor.row();
465 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
467 // sorry for this but I have a strange error that the y value jumps at
468 // a certain point. This seems like an error in my xforms library or
469 // in some other local environment, but I would like to leave this here
470 // for the moment until I can remove this (Jug 20020418)
471 if (y_before < bv_->text->cursor.y())
472 lyxerr << y_before << ":" << bv_->text->cursor.y() << endl;
474 // This is to allow jumping over large insets
475 if (cursorrow == bv_->text->cursor.row()) {
476 if (y >= int(workarea().workHeight())) {
477 bv_->text->cursorDown(bv_, false);
479 bv_->text->cursorUp(bv_, false);
483 if (!bv_->text->selection.set())
484 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
486 bv_->text->setSelection(bv_);
487 screen().toggleToggle(bv_->text, bv_);
493 // Single-click on work area
494 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
495 mouse_button::state button)
500 // ok ok, this is a hack (for xforms)
501 if (button == mouse_button::button4) {
502 scroll(-lyxrc.wheel_jump);
503 // We shouldn't go further down as we really should only do the
504 // scrolling and be done with this. Otherwise we may open some
505 // dialogs (Jug 20020424).
507 } else if (button == mouse_button::button5) {
508 scroll(lyxrc.wheel_jump);
509 // We shouldn't go further down as we really should only do the
510 // scrolling and be done with this. Otherwise we may open some
511 // dialogs (Jug 20020424).
515 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
517 // Middle button press pastes if we have a selection
518 // We do this here as if the selection was inside an inset
519 // it could get cleared on the unlocking of the inset so
520 // we have to check this first
521 bool paste_internally = false;
522 if (button == mouse_button::button2 && bv_->getLyXText()->selection.set()) {
523 owner_->dispatch(FuncRequest(LFUN_COPY));
524 paste_internally = true;
527 int const screen_first = bv_->text->first_y;
529 if (bv_->theLockingInset()) {
530 // We are in inset locking mode
532 // Check whether the inset was hit. If not reset mode,
533 // otherwise give the event to the inset
534 if (inset_hit == bv_->theLockingInset()) {
535 FuncRequest cmd(bv_, LFUN_MOUSE_PRESS, xpos, ypos, button);
536 bv_->theLockingInset()->localDispatch(cmd);
539 bv_->unlockInset(bv_->theLockingInset());
543 selection_possible = true;
544 screen().hideCursor();
546 // Clear the selection
547 screen().toggleSelection(bv_->text, bv_);
548 bv_->text->clearSelection();
549 bv_->text->fullRebreak(bv_);
553 // Single left click in math inset?
554 if (isHighlyEditableInset(inset_hit)) {
555 // Highly editable inset, like math
556 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
557 selection_possible = false;
558 owner_->updateLayoutChoice();
559 owner_->message(inset->editMessage());
560 //inset->edit(bv_, xpos, ypos, button);
561 // We just have to lock the inset before calling a PressEvent on it!
562 // we don't need the edit() call here! (Jug20020329)
563 if (!bv_->lockInset(inset)) {
564 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
566 FuncRequest cmd(bv_, LFUN_MOUSE_PRESS, xpos, ypos, button);
567 inset->localDispatch(cmd);
570 // I'm not sure we should continue here if we hit an inset (Jug20020403)
572 // Right click on a footnote flag opens float menu
573 if (button == mouse_button::button3) {
574 selection_possible = false;
578 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
579 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
581 bv_->text->selection.cursor = bv_->text->cursor;
582 bv_->text->cursor.x_fix(bv_->text->cursor.x());
584 owner_->updateLayoutChoice();
586 selection_possible = false;
589 // Insert primary selection with middle mouse
590 // if there is a local selection in the current buffer,
592 if (button == mouse_button::button2) {
593 if (paste_internally)
594 owner_->dispatch(FuncRequest(LFUN_PASTE));
596 owner_->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
597 selection_possible = false;
603 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, mouse_button::state button)
608 LyXText * text = bv_->getLyXText();
610 if (text->bv_owner && bv_->theLockingInset())
613 if (button == mouse_button::button1) {
614 if (text->bv_owner) {
615 screen().hideCursor();
616 screen().toggleSelection(text, bv_);
617 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
618 screen().toggleSelection(text, bv_, false);
620 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
622 // This will fit the cursor on the screen if necessary
623 update(text, BufferView::SELECT|BufferView::FITCUR);
624 workarea().haveSelection(bv_->getLyXText()->selection.set());
629 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, mouse_button::state button)
634 LyXText * text = bv_->getLyXText();
636 if (text->bv_owner && bv_->theLockingInset())
639 if (button == mouse_button::button1) {
640 if (text->bv_owner) {
641 screen().hideCursor();
642 screen().toggleSelection(text, bv_);
644 text->cursorHome(bv_);
645 text->selection.cursor = text->cursor;
646 text->cursorEnd(bv_);
647 text->setSelection(bv_);
648 if (text->bv_owner) {
649 screen().toggleSelection(text, bv_, false);
651 // This will fit the cursor on the screen if necessary
652 update(text, BufferView::SELECT|BufferView::FITCUR);
653 workarea().haveSelection(bv_->getLyXText()->selection.set());
658 void BufferView::Pimpl::selectionRequested()
665 LyXText * text = bv_->getLyXText();
667 if (text->selection.set() &&
668 (!bv_->text->xsel_cache.set() ||
669 text->selection.start != bv_->text->xsel_cache.start ||
670 text->selection.end != bv_->text->xsel_cache.end))
672 bv_->text->xsel_cache = text->selection;
673 sel = text->selectionAsString(bv_->buffer(), false);
674 } else if (!text->selection.set()) {
676 bv_->text->xsel_cache.set(false);
679 workarea().putClipboard(sel);
684 void BufferView::Pimpl::selectionLost()
689 bv_->getLyXText()->clearSelection();
691 bv_->text->xsel_cache.set(false);
696 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
697 mouse_button::state button)
699 // do nothing if we used the mouse wheel
700 if (!buffer_ || button == mouse_button::button4 || button == mouse_button::button5)
703 // If we hit an inset, we have the inset coordinates in these
704 // and inset_hit points to the inset. If we do not hit an
705 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
706 Inset * inset_hit = checkInsetHit(bv_->text, x, y);
708 if (bv_->theLockingInset()) {
709 // We are in inset locking mode.
711 // LyX does a kind of work-area grabbing for insets.
712 // Only a ButtonPress FuncRequest outside the inset will
713 // force a insetUnlock.
714 FuncRequest cmd(bv_, LFUN_MOUSE_RELEASE, x, y, button);
715 bv_->theLockingInset()->localDispatch(cmd);
719 selection_possible = false;
721 if (button == mouse_button::button2)
725 if (button == mouse_button::button1) {
726 workarea().haveSelection(bv_->getLyXText()->selection.set());
730 owner_->view_state_changed();
731 owner_->updateMenubar();
732 owner_->updateToolbar();
734 // Did we hit an editable inset?
736 selection_possible = false;
738 // if we reach this point with a selection, it
739 // must mean we are currently selecting.
740 // But we don't want to open the inset
741 // because that is annoying for the user.
742 // So just pretend we didn't hit it.
743 // this is OK because a "kosher" ButtonRelease
744 // will follow a ButtonPress that clears
746 // Note this also fixes selection drawing
747 // problems if we end up opening an inset
748 if (bv_->getLyXText()->selection.set())
751 // CHECK fix this proper in 0.13
752 // well, maybe 13.0 !!!!!!!!!
754 // Following a ref shouldn't issue
755 // a push on the undo-stack
756 // anylonger, now that we have
757 // keybindings for following
758 // references and returning from
759 // references. IMHO though, it
760 // should be the inset's own business
761 // to push or not push on the undo
762 // stack. They don't *have* to
763 // alter the document...
765 // ...or maybe the SetCursorParUndo()
766 // below isn't necessary at all anylonger?
767 if (inset_hit->lyxCode() == Inset::REF_CODE) {
768 setCursorParUndo(bv_);
771 owner_->message(inset_hit->editMessage());
773 if (isHighlyEditableInset(inset_hit)) {
774 // Highly editable inset, like math
775 UpdatableInset *inset = (UpdatableInset *)inset_hit;
776 FuncRequest cmd(bv_, LFUN_MOUSE_RELEASE, x, y, button);
777 inset->localDispatch(cmd);
779 FuncRequest cmd(bv_, LFUN_MOUSE_RELEASE, x, y, button);
780 inset_hit->localDispatch(cmd);
781 // IMO this is a grosshack! Inset's should be changed so that
782 // they call the actions they have to do with the insetButtonRel.
783 // function and not in the edit(). This should be changed
786 #warning Please remove donot call inset->edit() here (Jug 20020812)
788 inset_hit->edit(bv_, x, y, button);
793 // Maybe we want to edit a bibitem ale970302
794 if (bv_->text->cursor.par()->bibkey) {
795 bool const is_rtl = bv_->text->cursor.par()->isRightToLeftPar(buffer_->params);
796 int const width = bibitemMaxWidth(bv_, buffer_->params.getLyXTextClass().defaultfont());
797 if ((is_rtl && x > bv_->text->workWidth(bv_)-20-width) ||
798 (!is_rtl && x < 20+width)) {
799 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, mouse_button::none);
807 Box BufferView::Pimpl::insetDimensions(LyXText const & text,
808 LyXCursor const & cursor) const
810 Paragraph /*const*/ & par = *cursor.par();
811 pos_type const pos = cursor.pos();
813 lyx::Assert(par.getInset(pos));
815 Inset const & inset(*par.getInset(pos));
817 LyXFont const & font = text.getFont(buffer_, &par, pos);
819 int const width = inset.width(bv_, font);
820 int const inset_x = font.isVisibleRightToLeft()
821 ? (cursor.ix() - width) : cursor.ix();
824 inset_x + inset.scroll(),
826 cursor.iy() - inset.ascent(bv_, font),
827 cursor.iy() + inset.descent(bv_, font));
831 Inset * BufferView::Pimpl::checkInset(LyXText const & text,
832 LyXCursor const & cursor,
833 int & x, int & y) const
835 pos_type const pos(cursor.pos());
836 Paragraph /*const*/ & par(*cursor.par());
838 if (pos >= par.size() || !par.isInset(pos)) {
842 Inset /*const*/ * inset = par.getInset(pos);
844 if (!isEditableInset(inset)) {
848 Box b(insetDimensions(text, cursor));
850 if (!b.contained(x, y)) {
851 lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
852 << " box " << b << endl;
856 text.setCursor(bv_, &par, pos, true);
859 // The origin of an inset is on the baseline
860 y -= text.cursor.iy();
866 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
868 int y_tmp = y + text->first_y;
871 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
873 Inset * inset = checkInset(*text, cursor, x, y_tmp);
880 // look at previous position
881 if (cursor.pos() == 0) {
886 text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true);
888 inset = checkInset(*text, cursor, x, y_tmp);
896 void BufferView::Pimpl::workAreaResize()
898 static int work_area_width;
899 static int work_area_height;
901 bool const widthChange = workarea().workWidth() != work_area_width;
902 bool const heightChange = workarea().workHeight() != work_area_height;
904 // update from work area
905 work_area_width = workarea().workWidth();
906 work_area_height = workarea().workHeight();
910 // The visible LyXView need a resize
911 resizeCurrentBuffer();
913 // Remove all texts from the textcache
914 // This is not _really_ what we want to do. What
915 // we really want to do is to delete in textcache
916 // that does not have a BufferView with matching
917 // width, but as long as we have only one BufferView
918 // deleting all gives the same result.
919 if (lyxerr.debugging())
920 textcache.show(lyxerr, "Expose delete all");
922 // FIXME: this is already done in resizeCurrentBuffer() ??
923 buffer_->resizeInsets(bv_);
924 } else if (heightChange) {
925 // fitCursor() ensures we don't jump back
926 // to the start of the document on vertical
932 if (widthChange || heightChange) {
936 // always make sure that the scrollbar is sane.
938 owner_->updateLayoutChoice();
943 void BufferView::Pimpl::update()
945 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
946 LyXText::text_status st = bv_->text->status();
947 screen().update(bv_->text, bv_);
949 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
950 bv_->text->fullRebreak(bv_);
951 st = LyXText::NEED_MORE_REFRESH;
952 bv_->text->setCursor(bv_, bv_->text->cursor.par(),
953 bv_->text->cursor.pos());
954 if (bv_->text->selection.set()) {
955 bv_->text->setCursor(bv_, bv_->text->selection.start,
956 bv_->text->selection.start.par(),
957 bv_->text->selection.start.pos());
958 bv_->text->setCursor(bv_, bv_->text->selection.end,
959 bv_->text->selection.end.par(),
960 bv_->text->selection.end.pos());
963 bv_->text->status(bv_, st);
964 screen().update(bv_->text, bv_);
966 // do this here instead of in the screen::update because of
968 bv_->text->status(bv_, LyXText::UNCHANGED);
974 // Values used when calling update:
976 // -2 - update, move sel_cursor if selection, fitcursor
977 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
978 // 0 - update, move sel_cursor if selection, fitcursor
979 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
980 // 3 - update, move sel_cursor if selection
983 // a simple redraw of the parts that need refresh
985 // move sel_cursor if selection -
986 // the text's sel_cursor is moved if there is selection is progress
989 // fitCursor() is called and the scrollbar updated
992 // the buffer is marked dirty.
1001 // UPDATE_ONLY = UPDATE;
1002 // UPDATE_SELECT = UPDATE | SELECT;
1003 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1004 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1006 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1007 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1008 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1009 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1010 // update(3) -> update(1) -> update(1) -> update(SELECT)
1012 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1014 owner_->updateLayoutChoice();
1016 if (!text->selection.set() && (f & SELECT)) {
1017 text->selection.cursor = text->cursor;
1020 text->fullRebreak(bv_);
1022 if (text->inset_owner) {
1023 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1024 updateInset(text->inset_owner, false);
1034 buffer_->markDirty();
1039 // Callback for cursor timer
1040 void BufferView::Pimpl::cursorToggle()
1043 cursor_timeout.restart();
1048 extern void reapSpellchecker(void);
1051 if (!bv_->theLockingInset()) {
1052 screen().cursorToggle(bv_);
1054 bv_->theLockingInset()->toggleInsetCursor(bv_);
1057 cursor_timeout.restart();
1061 bool BufferView::Pimpl::available() const
1063 if (buffer_ && bv_->text)
1069 void BufferView::Pimpl::beforeChange(LyXText * text)
1072 text->clearSelection();
1076 void BufferView::Pimpl::savePosition(unsigned int i)
1078 if (i >= saved_positions_num)
1080 saved_positions[i] = Position(buffer_->fileName(),
1081 bv_->text->cursor.par()->id(),
1082 bv_->text->cursor.pos());
1085 str << _("Saved bookmark") << ' ' << i;
1086 owner_->message(str.str().c_str());
1091 void BufferView::Pimpl::restorePosition(unsigned int i)
1093 if (i >= saved_positions_num)
1096 string const fname = saved_positions[i].filename;
1098 beforeChange(bv_->text);
1100 if (fname != buffer_->fileName()) {
1101 Buffer * b = bufferlist.exists(fname) ?
1102 bufferlist.getBuffer(fname) :
1103 bufferlist.loadLyXFile(fname); // don't ask, just load it
1104 if (b != 0) buffer(b);
1107 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1111 bv_->text->setCursor(bv_, par,
1112 min(par->size(), saved_positions[i].par_pos));
1114 update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1117 str << _("Moved to bookmark") << ' ' << i;
1118 owner_->message(str.str().c_str());
1123 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1125 if (i >= saved_positions_num)
1128 return !saved_positions[i].filename.empty();
1132 void BufferView::Pimpl::switchKeyMap()
1134 if (!lyxrc.rtl_support)
1137 LyXText * text = bv_->getLyXText();
1138 if (text->real_current_font.isRightToLeft()
1139 && !(bv_->theLockingInset()
1140 && bv_->theLockingInset()->lyxCode() == Inset::ERT_CODE))
1142 if (owner_->getIntl().keymap == Intl::PRIMARY)
1143 owner_->getIntl().KeyMapSec();
1145 if (owner_->getIntl().keymap == Intl::SECONDARY)
1146 owner_->getIntl().KeyMapPrim();
1151 void BufferView::Pimpl::insetUnlock()
1153 if (bv_->theLockingInset()) {
1154 bv_->theLockingInset()->insetUnlock(bv_);
1155 bv_->theLockingInset(0);
1161 void BufferView::Pimpl::showCursor()
1163 if (bv_->theLockingInset())
1164 bv_->theLockingInset()->showInsetCursor(bv_);
1166 screen().showCursor(bv_->text, bv_);
1170 void BufferView::Pimpl::hideCursor()
1172 if (!bv_->theLockingInset())
1173 screen().hideCursor();
1177 void BufferView::Pimpl::toggleSelection(bool b)
1179 if (bv_->theLockingInset())
1180 bv_->theLockingInset()->toggleSelection(bv_, b);
1181 screen().toggleSelection(bv_->text, bv_, b);
1185 void BufferView::Pimpl::toggleToggle()
1187 screen().toggleToggle(bv_->text, bv_);
1191 void BufferView::Pimpl::center()
1193 LyXText * t = bv_->text;
1196 int const half_height = workarea().workHeight() / 2;
1199 if (t->cursor.y() > half_height) {
1200 new_y = t->cursor.y() - half_height;
1203 // FIXME: can we do this w/o calling screen directly ?
1204 // This updates first_y but means the fitCursor() call
1205 // from the update(FITCUR) doesn't realise that we might
1206 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
1207 // the scrollbar to be updated as it should, so we have
1208 // to do it manually. Any operation that does a center()
1209 // and also might have moved first_y must make sure to call
1210 // updateScrollbar() currently. Never mind that this is a
1211 // pretty obfuscated way of updating t->first_y
1212 screen().draw(t, bv_, new_y);
1214 update(t, BufferView::SELECT | BufferView::FITCUR);
1218 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1220 workarea().putClipboard(stuff);
1225 * Dispatch functions for actions which can be valid for BufferView->text
1226 * and/or InsetText->text!!!
1230 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1233 LyXCursor cursor = bv_->getLyXText()->cursor;
1234 Buffer::inset_iterator it =
1235 find_if(Buffer::inset_iterator(
1236 cursor.par(), cursor.pos()),
1237 buffer_->inset_iterator_end(),
1238 lyx::compare_memfun(&Inset::lyxCode, code));
1239 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1241 // Ok, this is a little bit too brute force but it
1242 // should work for now. Better infrastructure is comming. (Lgb)
1244 Buffer * b = bv_->buffer();
1245 LyXCursor cursor = bv_->getLyXText()->cursor;
1247 Buffer::inset_iterator beg = b->inset_iterator_begin();
1248 Buffer::inset_iterator end = b->inset_iterator_end();
1250 bool cursor_par_seen = false;
1252 for (; beg != end; ++beg) {
1253 if (beg.getPar() == cursor.par()) {
1254 cursor_par_seen = true;
1256 if (cursor_par_seen) {
1257 if (beg.getPar() == cursor.par()
1258 && beg.getPos() >= cursor.pos()) {
1260 } else if (beg.getPar() != cursor.par()) {
1267 // Now find the first inset that matches code.
1268 for (; beg != end; ++beg) {
1269 if (beg->lyxCode() == code) {
1279 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1281 string filename = filen;
1283 if (filename.empty()) {
1284 // Launch a file browser
1285 string initpath = lyxrc.document_path;
1288 string const trypath = owner_->buffer()->filePath();
1289 // If directory is writeable, use this as default.
1290 if (IsDirWriteable(trypath))
1294 FileDialog fileDlg(bv_->owner(),
1295 _("Select LyX document to insert"),
1297 make_pair(string(_("Documents|#o#O")),
1298 string(lyxrc.document_path)),
1299 make_pair(string(_("Examples|#E#e")),
1300 string(AddPath(system_lyxdir, "examples"))));
1302 FileDialog::Result result =
1303 fileDlg.Select(initpath,
1304 _("*.lyx| LyX Documents (*.lyx)"));
1306 if (result.first == FileDialog::Later)
1309 filename = result.second;
1311 // check selected filename
1312 if (filename.empty()) {
1313 owner_->message(_("Canceled."));
1318 // get absolute path of file and add ".lyx" to the filename if
1320 filename = FileSearch(string(), filename, "lyx");
1322 string const disp_fn(MakeDisplayPath(filename));
1325 s1 << _("Inserting document") << ' '
1326 << disp_fn << " ...";
1327 owner_->message(s1.str().c_str());
1328 bool const res = bv_->insertLyXFile(filename);
1331 str << _("Document") << ' ' << disp_fn
1332 << ' ' << _("inserted.");
1333 owner_->message(str.str().c_str());
1336 str << _("Could not insert document") << ' '
1338 owner_->message(str.str().c_str());
1343 bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
1345 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1346 << ev.action <<"] arg[" << ev.argument << "]" << endl;
1348 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
1350 switch (ev.action) {
1352 case LFUN_TOC_INSERT:
1354 InsetCommandParams p;
1355 p.setCmdName("tableofcontents");
1356 Inset * inset = new InsetTOC(p);
1357 if (!insertInset(inset, tclass.defaultLayoutName()))
1362 case LFUN_SCROLL_INSET:
1363 // this is not handled here as this function is only active
1364 // if we have a locking_inset and that one is (or contains)
1368 case LFUN_INSET_GRAPHICS:
1370 Inset * new_inset = new InsetGraphics;
1371 if (!insertInset(new_inset)) {
1374 // this is need because you don't use a inset->Edit()
1375 updateInset(new_inset, true);
1376 new_inset->edit(bv_);
1381 case LFUN_LAYOUT_COPY:
1382 bv_->copyEnvironment();
1385 case LFUN_LAYOUT_PASTE:
1386 bv_->pasteEnvironment();
1390 case LFUN_DEPTH_MIN:
1391 changeDepth(bv_, bv_->getLyXText(), -1);
1394 case LFUN_DEPTH_PLUS:
1395 changeDepth(bv_, bv_->getLyXText(), 1);
1399 owner_->getDialogs().setUserFreeFont();
1402 case LFUN_FILE_INSERT:
1403 MenuInsertLyXFile(ev.argument);
1406 case LFUN_FILE_INSERT_ASCII_PARA:
1407 InsertAsciiFile(bv_, ev.argument, true);
1410 case LFUN_FILE_INSERT_ASCII:
1411 InsertAsciiFile(bv_, ev.argument, false);
1415 lang(bv_, ev.argument);
1417 owner_->view_state_changed();
1422 owner_->view_state_changed();
1427 owner_->view_state_changed();
1432 owner_->view_state_changed();
1437 owner_->view_state_changed();
1442 owner_->view_state_changed();
1447 owner_->view_state_changed();
1452 owner_->view_state_changed();
1455 case LFUN_UNDERLINE:
1457 owner_->view_state_changed();
1460 case LFUN_FONT_SIZE:
1461 fontSize(bv_, ev.argument);
1462 owner_->view_state_changed();
1465 case LFUN_FONT_STATE:
1466 owner_->getLyXFunc().setMessage(currentState(bv_));
1469 case LFUN_INSERT_LABEL:
1470 MenuInsertLabel(bv_, ev.argument);
1473 case LFUN_REF_INSERT:
1474 if (ev.argument.empty()) {
1475 InsetCommandParams p("ref");
1476 owner_->getDialogs().createRef(p.getAsString());
1478 InsetCommandParams p;
1479 p.setFromString(ev.argument);
1481 InsetRef * inset = new InsetRef(p, *buffer_);
1482 if (!insertInset(inset))
1485 updateInset(inset, true);
1489 case LFUN_BOOKMARK_SAVE:
1490 savePosition(strToUnsignedInt(ev.argument));
1493 case LFUN_BOOKMARK_GOTO:
1494 restorePosition(strToUnsignedInt(ev.argument));
1499 string label = ev.argument;
1500 if (label.empty()) {
1502 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1504 label = inset->getContents();
1509 if (!label.empty()) {
1510 //bv_->savePosition(0);
1511 if (!bv_->gotoLabel(label))
1512 Alert::alert(_("Error"),
1513 _("Couldn't find this label"),
1514 _("in current document."));
1522 InsetCommandParams p;
1523 if (ev.action == LFUN_HTMLURL)
1524 p.setCmdName("htmlurl");
1526 p.setCmdName("url");
1527 owner_->getDialogs().createUrl(p.getAsString());
1531 case LFUN_INSERT_URL:
1533 InsetCommandParams p;
1534 p.setFromString(ev.argument);
1536 InsetUrl * inset = new InsetUrl(p);
1537 if (!insertInset(inset))
1540 updateInset(inset, true);
1545 case LFUN_INSET_LIST:
1546 case LFUN_INSET_THEOREM:
1548 case LFUN_INSERT_NOTE:
1549 case LFUN_INSET_ERT:
1550 case LFUN_INSET_EXTERNAL:
1551 case LFUN_INSET_FLOAT:
1552 case LFUN_INSET_FOOTNOTE:
1553 case LFUN_INSET_MARGINAL:
1554 case LFUN_INSET_MINIPAGE:
1555 case LFUN_INSET_OPTARG:
1556 case LFUN_INSET_WIDE_FLOAT:
1558 FuncRequest cmd = ev;
1560 Inset * inset = createInset(cmd);
1562 bool gotsel = false;
1564 if (bv_->getLyXText()->selection.set()) {
1565 bv_->getLyXText()->cutSelection(bv_, true, false);
1569 if (insertInset(inset)) {
1572 owner_->dispatch(FuncRequest(LFUN_PASTESELECTION));
1580 case LFUN_INSET_CAPTION:
1582 // Do we have a locking inset...
1583 if (bv_->theLockingInset()) {
1584 lyxerr << "Locking inset code: "
1585 << static_cast<int>(bv_->theLockingInset()->lyxCode());
1586 InsetCaption * new_inset =
1587 new InsetCaption(buffer_->params);
1588 new_inset->setOwner(bv_->theLockingInset());
1589 new_inset->setAutoBreakRows(true);
1590 new_inset->setDrawFrame(0, InsetText::LOCKED);
1591 new_inset->setFrameColor(0, LColor::captionframe);
1592 if (insertInset(new_inset))
1593 new_inset->edit(bv_);
1600 case LFUN_TABULAR_INSERT:
1602 if (ev.argument.empty()) {
1603 owner_->getDialogs().showTabularCreate();
1609 ::sscanf(ev.argument.c_str(),"%d%d", &r, &c);
1610 InsetTabular * new_inset =
1611 new InsetTabular(*buffer_, r, c);
1613 bv_->getLyXText()->real_current_font.isRightToLeft();
1614 if (!open_new_inset(new_inset, rtl))
1620 // --- accented characters ---------------------------
1623 case LFUN_CIRCUMFLEX:
1633 case LFUN_SPECIAL_CARON:
1636 case LFUN_HUNG_UMLAUT:
1639 if (ev.argument.empty()) {
1641 owner_->getLyXFunc().handleKeyFunc(ev.action);
1643 owner_->getLyXFunc().handleKeyFunc(ev.action);
1644 owner_->getIntl().getTransManager()
1645 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
1646 update(bv_->getLyXText(),
1648 | BufferView::FITCUR
1649 | BufferView::CHANGE);
1653 case LFUN_MATH_MACRO:
1654 case LFUN_MATH_DELIM:
1655 case LFUN_INSERT_MATRIX:
1656 case LFUN_INSERT_MATH:
1657 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
1658 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
1659 case LFUN_MATH_MODE: // Open or create an inlined math inset
1660 case LFUN_GREEK: // Insert a single greek letter
1661 mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
1664 case LFUN_CITATION_INSERT:
1666 InsetCommandParams p;
1667 p.setFromString(ev.argument);
1669 InsetCitation * inset = new InsetCitation(p);
1670 if (!insertInset(inset))
1673 updateInset(inset, true);
1677 case LFUN_INSERT_BIBTEX:
1679 // ale970405+lasgoutt970425
1680 // The argument can be up to two tokens separated
1681 // by a space. The first one is the bibstyle.
1682 string const db = token(ev.argument, ' ', 0);
1683 string bibstyle = token(ev.argument, ' ', 1);
1684 if (bibstyle.empty())
1687 InsetCommandParams p("BibTeX", db, bibstyle);
1688 InsetBibtex * inset = new InsetBibtex(p);
1690 if (insertInset(inset)) {
1691 if (ev.argument.empty())
1698 // BibTeX data bases
1699 case LFUN_BIBDB_ADD:
1701 InsetBibtex * inset =
1702 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
1704 inset->addDatabase(ev.argument);
1709 case LFUN_BIBDB_DEL:
1711 InsetBibtex * inset =
1712 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
1714 inset->delDatabase(ev.argument);
1719 case LFUN_BIBTEX_STYLE:
1721 InsetBibtex * inset =
1722 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
1724 inset->setOptions(ev.argument);
1729 case LFUN_INDEX_INSERT:
1731 string entry = ev.argument;
1733 entry = bv_->getLyXText()->getStringToIndex(bv_);
1735 if (entry.empty()) {
1736 owner_->getDialogs().createIndex();
1740 InsetIndex * inset = new InsetIndex(InsetCommandParams("index", entry));
1742 if (!insertInset(inset)) {
1745 updateInset(inset, true);
1750 case LFUN_INDEX_PRINT:
1752 InsetCommandParams p("printindex");
1753 Inset * inset = new InsetPrintIndex(p);
1754 if (!insertInset(inset, tclass.defaultLayoutName()))
1759 case LFUN_PARENTINSERT:
1761 InsetCommandParams p("lyxparent", ev.argument);
1762 Inset * inset = new InsetParent(p, *buffer_);
1763 if (!insertInset(inset, tclass.defaultLayoutName()))
1769 case LFUN_CHILD_INSERT:
1771 InsetInclude::Params p;
1772 p.cparams.setFromString(ev.argument);
1773 p.masterFilename_ = buffer_->fileName();
1775 InsetInclude * inset = new InsetInclude(p);
1776 if (!insertInset(inset))
1779 updateInset(inset, true);
1780 bv_->owner()->getDialogs().showInclude(inset);
1785 case LFUN_FLOAT_LIST:
1786 if (floatList.typeExist(ev.argument)) {
1787 Inset * inset = new InsetFloatList(ev.argument);
1788 if (!insertInset(inset, tclass.defaultLayoutName()))
1791 lyxerr << "Non-existent float type: "
1792 << ev.argument << endl;
1796 case LFUN_THESAURUS_ENTRY:
1798 string arg = ev.argument;
1801 arg = bv_->getLyXText()->selectionAsString(buffer_,
1805 if (arg.size() > 100 || arg.empty()) {
1806 // Get word or selection
1807 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
1808 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
1809 // FIXME: where is getLyXText()->unselect(bv_) ?
1813 bv_->owner()->getDialogs().showThesaurus(arg);
1817 case LFUN_UNKNOWN_ACTION:
1818 ev.errorMessage(N_("Unknown function!"));
1822 FuncRequest cmd = ev;
1824 return bv_->getLyXText()->dispatch(cmd);
1831 // Open and lock an updatable inset
1832 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
1834 LyXText * lt = bv_->getLyXText();
1838 if (!insertInset(new_inset)) {
1842 new_inset->edit(bv_, !behind);
1847 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
1849 // if we are in a locking inset we should try to insert the
1850 // inset there otherwise this is a illegal function now
1851 if (bv_->theLockingInset()) {
1852 if (bv_->theLockingInset()->insetAllowed(inset))
1853 return bv_->theLockingInset()->insertInset(bv_, inset);
1857 // not quite sure if we want this...
1858 setCursorParUndo(bv_);
1861 beforeChange(bv_->text);
1862 if (!lout.empty()) {
1863 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1864 bv_->text->breakParagraph(bv_);
1865 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1867 if (!bv_->text->cursor.par()->empty()) {
1868 bv_->text->cursorLeft(bv_);
1870 bv_->text->breakParagraph(bv_);
1871 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1875 LyXTextClass const & tclass =
1876 buffer_->params.getLyXTextClass();
1877 bool hasLayout = tclass.hasLayout(lres);
1878 string lay = tclass.defaultLayoutName();
1880 if (hasLayout != false) {
1884 // layout not fount using default
1885 lay = tclass.defaultLayoutName();
1888 bv_->text->setLayout(bv_, lay);
1890 bv_->text->setParagraph(bv_, 0, 0,
1892 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
1897 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1900 bv_->text->insertInset(bv_, inset);
1901 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1908 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
1910 if (!inset || !available())
1913 // first check for locking insets
1914 if (bv_->theLockingInset()) {
1915 if (bv_->theLockingInset() == inset) {
1916 if (bv_->text->updateInset(bv_, inset)) {
1919 buffer_->markDirty();
1924 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
1925 if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
1928 buffer_->markDirty();
1936 // then check if the inset is a top_level inset (has no owner)
1937 // if yes do the update as always otherwise we have to update the
1938 // toplevel inset where this inset is inside
1939 Inset * tl_inset = inset;
1940 while (tl_inset->owner())
1941 tl_inset = tl_inset->owner();
1943 if (tl_inset == inset) {
1944 update(bv_->text, BufferView::UPDATE);
1945 if (bv_->text->updateInset(bv_, inset)) {
1949 | BufferView::FITCUR
1950 | BufferView::CHANGE);
1952 update(bv_->text, SELECT);
1956 } else if (static_cast<UpdatableInset *>(tl_inset)
1957 ->updateInsetInInset(bv_, inset))
1959 if (bv_->text->updateInset(bv_, tl_inset)) {