2 * \file BufferView_pimpl.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
11 #include "BufferView_pimpl.h"
12 #include "bufferlist.h"
14 #include "bufferview_funcs.h"
18 #include "FloatList.h"
19 #include "funcrequest.h"
22 #include "iterators.h"
24 #include "lyx_cb.h" // added for Dispatch functions
31 #include "paragraph.h"
32 #include "ParagraphParameters.h"
33 #include "TextCache.h"
34 #include "undo_funcs.h"
36 #include "insets/insetfloatlist.h"
37 #include "insets/insetgraphics.h"
38 #include "insets/insetinclude.h"
39 #include "insets/insetref.h"
40 #include "insets/insettext.h"
42 #include "frontends/Alert.h"
43 #include "frontends/Dialogs.h"
44 #include "frontends/FileDialog.h"
45 #include "frontends/LyXView.h"
46 #include "frontends/LyXScreenFactory.h"
47 #include "frontends/mouse_state.h"
48 #include "frontends/screen.h"
49 #include "frontends/WorkArea.h"
50 #include "frontends/WorkAreaFactory.h"
52 #include "mathed/formulabase.h"
54 #include "graphics/Previews.h"
56 #include "support/LAssert.h"
57 #include "support/tostr.h"
58 #include "support/filetools.h"
60 #include <boost/bind.hpp>
61 #include <boost/signals/connection.hpp>
76 using namespace bv_funcs;
78 extern BufferList bufferlist;
83 unsigned int const saved_positions_num = 20;
85 // All the below connection objects are needed because of a bug in some
86 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
87 // to these connections we avoid a segfault upon startup, and also at exit.
90 boost::signals::connection dispatchcon;
91 boost::signals::connection timecon;
92 boost::signals::connection doccon;
93 boost::signals::connection resizecon;
94 boost::signals::connection kpresscon;
95 boost::signals::connection selectioncon;
96 boost::signals::connection lostcon;
102 BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
103 int xpos, int ypos, int width, int height)
104 : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
105 using_xterm_cursor(false)
107 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
108 screen_.reset(LyXScreenFactory::create(workarea()));
111 doccon = workarea().scrollDocView
112 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
113 resizecon = workarea().workAreaResize
114 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
115 dispatchcon = workarea().dispatch
116 .connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
117 kpresscon = workarea().workAreaKeyPress
118 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
119 selectioncon = workarea().selectionRequested
120 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
121 lostcon = workarea().selectionLost
122 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
124 timecon = cursor_timeout.timeout
125 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
126 cursor_timeout.start();
127 saved_positions.resize(saved_positions_num);
131 WorkArea & BufferView::Pimpl::workarea() const
133 return *workarea_.get();
137 LyXScreen & BufferView::Pimpl::screen() const
139 return *screen_.get();
143 Painter & BufferView::Pimpl::painter() const
145 return workarea().getPainter();
149 void BufferView::Pimpl::buffer(Buffer * b)
151 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
154 buffer_->delUser(bv_);
156 // Put the old text into the TextCache, but
157 // only if the buffer is still loaded.
158 // Also set the owner of the test to 0
159 // bv_->text->owner(0);
160 textcache.add(buffer_, workarea().workWidth(), bv_->text);
161 if (lyxerr.debugging())
162 textcache.show(lyxerr, "BufferView::buffer");
167 // set current buffer
170 // if we're quitting lyx, don't bother updating stuff
174 // if we are closing the buffer, use the first buffer as current
176 buffer_ = bufferlist.first();
180 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
181 buffer_->addUser(bv_);
183 // If we don't have a text object for this, we make one
184 if (bv_->text == 0) {
185 resizeCurrentBuffer();
188 // FIXME: needed when ?
189 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
191 // Buffer-dependent dialogs should be updated or
192 // hidden. This should go here because some dialogs (eg ToC)
193 // require bv_->text.
194 owner_->getDialogs().updateBufferDependent(true);
196 lyxerr[Debug::INFO] << " No Buffer!" << endl;
197 owner_->getDialogs().hideBufferDependent();
199 // Also remove all remaining text's from the testcache.
200 // (there should not be any!) (if there is any it is a
202 if (lyxerr.debugging())
203 textcache.show(lyxerr, "buffer delete all");
209 owner_->updateMenubar();
210 owner_->updateToolbar();
211 owner_->updateLayoutChoice();
212 owner_->updateWindowTitle();
215 // Don't forget to update the Layout
216 string const layoutname =
217 bv_->text->cursor.par()->layout()->name();
218 owner_->setLayout(layoutname);
221 if (grfx::Previews::activated() && buffer_)
222 grfx::Previews::get().generateBufferPreviews(*buffer_);
226 bool BufferView::Pimpl::fitCursor()
230 if (bv_->theLockingInset()) {
231 bv_->theLockingInset()->fitInsetCursor(bv_);
234 ret = screen().fitCursor(bv_->text, bv_);
237 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
239 // We need to always update, in case we did a
240 // paste and we stayed anchored to a row, but
241 // the actual height of the doc changed ...
247 void BufferView::Pimpl::redoCurrentBuffer()
249 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
250 if (buffer_ && bv_->text) {
251 resizeCurrentBuffer();
253 owner_->updateLayoutChoice();
259 int BufferView::Pimpl::resizeCurrentBuffer()
261 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
264 Paragraph * selstartpar = 0;
265 Paragraph * selendpar = 0;
266 UpdatableInset * the_locking_inset = 0;
269 pos_type selstartpos = 0;
270 pos_type selendpos = 0;
271 bool selection = false;
272 bool mark_set = false;
276 owner_->message(_("Formatting document..."));
279 par = &*bv_->text->cursor.par();
280 pos = bv_->text->cursor.pos();
281 selstartpar = &*bv_->text->selection.start.par();
282 selstartpos = bv_->text->selection.start.pos();
283 selendpar = &*bv_->text->selection.end.par();
284 selendpos = bv_->text->selection.end.pos();
285 selection = bv_->text->selection.set();
286 mark_set = bv_->text->selection.mark();
287 the_locking_inset = bv_->theLockingInset();
288 buffer_->resizeInsets(bv_);
289 // I don't think the delete and new are necessary here we just could
290 // call only init! (Jug 20020419)
292 bv_->text = new LyXText(bv_);
293 bv_->text->init(bv_);
295 // See if we have a text in TextCache that fits
296 // the new buffer_ with the correct width.
297 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
299 if (lyxerr.debugging()) {
300 lyxerr << "Found a LyXText that fits:\n";
301 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
303 // Set the owner of the newly found text
304 // bv_->text->owner(bv_);
305 if (lyxerr.debugging())
306 textcache.show(lyxerr, "resizeCurrentBuffer");
308 buffer_->resizeInsets(bv_);
310 bv_->text = new LyXText(bv_);
311 bv_->text->init(bv_);
312 //buffer_->resizeInsets(bv_);
317 bv_->text->selection.set(true);
318 // At this point just to avoid the Delete-Empty-Paragraph-
319 // Mechanism when setting the cursor.
320 bv_->text->selection.mark(mark_set);
322 bv_->text->setCursor(selstartpar, selstartpos);
323 bv_->text->selection.cursor = bv_->text->cursor;
324 bv_->text->setCursor(selendpar, selendpos);
325 bv_->text->setSelection();
326 bv_->text->setCursor(par, pos);
328 bv_->text->setCursor(par, pos);
329 bv_->text->selection.cursor = bv_->text->cursor;
330 bv_->text->selection.set(false);
332 // remake the inset locking
333 bv_->theLockingInset(the_locking_inset);
336 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
341 // reset the "Formatting..." message
342 owner_->clearMessage();
350 void BufferView::Pimpl::repaint()
352 // Regenerate the screen.
353 screen().redraw(bv_->text, bv_);
357 void BufferView::Pimpl::updateScrollbar()
360 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
361 workarea().setScrollbarParams(0, 0, 0);
365 LyXText const & t = *bv_->text;
367 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
368 << t.top_y() << ", default height " << defaultRowHeight() << endl;
370 workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
374 void BufferView::Pimpl::scrollDocView(int value)
376 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
381 screen().hideCursor();
383 screen().draw(bv_->text, bv_, value);
385 if (!lyxrc.cursor_follows_scrollbar)
388 LyXText * vbt = bv_->text;
390 int const height = defaultRowHeight();
391 int const first = static_cast<int>((bv_->text->top_y() + height));
392 int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
394 if (vbt->cursor.y() < first)
395 vbt->setCursorFromCoordinates(0, first);
396 else if (vbt->cursor.y() > last)
397 vbt->setCursorFromCoordinates(0, last);
399 owner_->updateLayoutChoice();
403 void BufferView::Pimpl::scroll(int lines)
409 LyXText const * t = bv_->text;
410 int const line_height = defaultRowHeight();
412 // The new absolute coordinate
413 int new_top_y = t->top_y() + lines * line_height;
415 // Restrict to a valid value
416 new_top_y = std::min(t->height - 4 * line_height, new_top_y);
417 new_top_y = std::max(0, new_top_y);
419 scrollDocView(new_top_y);
421 // Update the scrollbar.
422 workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
426 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
427 key_modifier::state state)
429 bv_->owner()->getLyXFunc().processKeySym(key, state);
431 /* This is perhaps a bit of a hack. When we move
432 * around, or type, it's nice to be able to see
433 * the cursor immediately after the keypress. So
434 * we reset the toggle timeout and force the visibility
435 * of the cursor. Note we cannot do this inside
436 * dispatch() itself, because that's called recursively.
439 cursor_timeout.restart();
440 screen().showCursor(*bv_);
445 void BufferView::Pimpl::selectionRequested()
452 LyXText * text = bv_->getLyXText();
454 if (text->selection.set() &&
455 (!bv_->text->xsel_cache.set() ||
456 text->selection.start != bv_->text->xsel_cache.start ||
457 text->selection.end != bv_->text->xsel_cache.end))
459 bv_->text->xsel_cache = text->selection;
460 sel = text->selectionAsString(bv_->buffer(), false);
461 } else if (!text->selection.set()) {
463 bv_->text->xsel_cache.set(false);
466 workarea().putClipboard(sel);
471 void BufferView::Pimpl::selectionLost()
474 screen().hideCursor();
476 bv_->getLyXText()->clearSelection();
477 bv_->text->xsel_cache.set(false);
482 void BufferView::Pimpl::workAreaResize()
484 static int work_area_width;
485 static int work_area_height;
487 bool const widthChange = workarea().workWidth() != work_area_width;
488 bool const heightChange = workarea().workHeight() != work_area_height;
490 // update from work area
491 work_area_width = workarea().workWidth();
492 work_area_height = workarea().workHeight();
496 // The visible LyXView need a resize
497 resizeCurrentBuffer();
499 // Remove all texts from the textcache
500 // This is not _really_ what we want to do. What
501 // we really want to do is to delete in textcache
502 // that does not have a BufferView with matching
503 // width, but as long as we have only one BufferView
504 // deleting all gives the same result.
505 if (lyxerr.debugging())
506 textcache.show(lyxerr, "Expose delete all");
508 // FIXME: this is already done in resizeCurrentBuffer() ??
509 buffer_->resizeInsets(bv_);
510 } else if (heightChange) {
511 // fitCursor() ensures we don't jump back
512 // to the start of the document on vertical
518 if (widthChange || heightChange) {
522 // always make sure that the scrollbar is sane.
524 owner_->updateLayoutChoice();
529 void BufferView::Pimpl::update()
531 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
532 screen().update(*bv_);
533 bv_->text->clearPaint();
538 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
540 if (!text->selection.set() && (f & SELECT)) {
541 text->selection.cursor = text->cursor;
546 if (text->inset_owner) {
547 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
548 updateInset(text->inset_owner);
555 void BufferView::Pimpl::update(BufferView::UpdateCodes f)
557 LyXText * text = bv_->text;
559 if (!text->selection.set() && (f & SELECT)) {
560 text->selection.cursor = text->cursor;
565 if (text->inset_owner) {
566 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
567 updateInset(text->inset_owner);
574 // Callback for cursor timer
575 void BufferView::Pimpl::cursorToggle()
578 cursor_timeout.restart();
582 screen().toggleCursor(*bv_);
584 cursor_timeout.restart();
588 bool BufferView::Pimpl::available() const
590 if (buffer_ && bv_->text)
596 Change const BufferView::Pimpl::getCurrentChange()
598 if (!bv_->buffer()->params.tracking_changes)
599 return Change(Change::UNCHANGED);
601 LyXText * t(bv_->getLyXText());
603 if (!t->selection.set())
604 return Change(Change::UNCHANGED);
606 LyXCursor const & cur(t->selection.start);
607 return cur.par()->lookupChangeFull(cur.pos());
611 void BufferView::Pimpl::beforeChange(LyXText * text)
614 text->clearSelection();
618 void BufferView::Pimpl::savePosition(unsigned int i)
620 if (i >= saved_positions_num)
622 saved_positions[i] = Position(buffer_->fileName(),
623 bv_->text->cursor.par()->id(),
624 bv_->text->cursor.pos());
626 owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
630 void BufferView::Pimpl::restorePosition(unsigned int i)
632 if (i >= saved_positions_num)
635 string const fname = saved_positions[i].filename;
637 beforeChange(bv_->text);
639 if (fname != buffer_->fileName()) {
640 Buffer * b = bufferlist.exists(fname) ?
641 bufferlist.getBuffer(fname) :
642 bufferlist.loadLyXFile(fname); // don't ask, just load it
643 if (b != 0) buffer(b);
646 ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
647 if (par == buffer_->par_iterator_end())
650 bv_->text->setCursor(*par,
651 min((*par)->size(), saved_positions[i].par_pos));
653 update(BufferView::SELECT);
655 owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
659 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
661 if (i >= saved_positions_num)
664 return !saved_positions[i].filename.empty();
668 void BufferView::Pimpl::switchKeyMap()
670 if (!lyxrc.rtl_support)
673 LyXText * text = bv_->getLyXText();
674 if (text->real_current_font.isRightToLeft()
675 && !(bv_->theLockingInset()
676 && bv_->theLockingInset()->lyxCode() == Inset::ERT_CODE))
678 if (owner_->getIntl().keymap == Intl::PRIMARY)
679 owner_->getIntl().KeyMapSec();
681 if (owner_->getIntl().keymap == Intl::SECONDARY)
682 owner_->getIntl().KeyMapPrim();
687 void BufferView::Pimpl::insetUnlock()
689 if (bv_->theLockingInset()) {
690 bv_->theLockingInset()->insetUnlock(bv_);
691 bv_->theLockingInset(0);
697 void BufferView::Pimpl::toggleSelection(bool b)
699 if (bv_->theLockingInset())
700 bv_->theLockingInset()->toggleSelection(bv_, b);
701 screen().toggleSelection(bv_->text, bv_, b);
705 void BufferView::Pimpl::toggleToggle()
707 screen().toggleToggle(bv_->text, bv_);
711 void BufferView::Pimpl::center()
713 LyXText * t = bv_->text;
716 int const half_height = workarea().workHeight() / 2;
719 if (t->cursor.y() > half_height) {
720 new_y = t->cursor.y() - half_height;
723 // FIXME: look at this comment again ...
725 // FIXME: can we do this w/o calling screen directly ?
726 // This updates top_y() but means the fitCursor() call
727 // from the update(FITCUR) doesn't realise that we might
728 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
729 // the scrollbar to be updated as it should, so we have
730 // to do it manually. Any operation that does a center()
731 // and also might have moved top_y() must make sure to call
732 // updateScrollbar() currently. Never mind that this is a
733 // pretty obfuscated way of updating t->top_y()
734 screen().draw(t, bv_, new_y);
736 update(BufferView::SELECT);
740 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
742 workarea().putClipboard(stuff);
747 * Dispatch functions for actions which can be valid for BufferView->text
748 * and/or InsetText->text!!!
752 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
755 LyXCursor cursor = bv_->getLyXText()->cursor;
756 Buffer::inset_iterator it =
757 find_if(Buffer::inset_iterator(
758 cursor.par(), cursor.pos()),
759 buffer_->inset_iterator_end(),
760 lyx::compare_memfun(&Inset::lyxCode, code));
761 return it != buffer_->inset_iterator_end() ? (*it) : 0;
763 // Ok, this is a little bit too brute force but it
764 // should work for now. Better infrastructure is comming. (Lgb)
766 Buffer * b = bv_->buffer();
767 LyXCursor cursor = bv_->getLyXText()->cursor;
769 Buffer::inset_iterator beg = b->inset_iterator_begin();
770 Buffer::inset_iterator end = b->inset_iterator_end();
772 bool cursor_par_seen = false;
774 for (; beg != end; ++beg) {
775 if (beg.getPar() == cursor.par()) {
776 cursor_par_seen = true;
778 if (cursor_par_seen) {
779 if (beg.getPar() == cursor.par()
780 && beg.getPos() >= cursor.pos()) {
782 } else if (beg.getPar() != cursor.par()) {
789 // Now find the first inset that matches code.
790 for (; beg != end; ++beg) {
791 if (beg->lyxCode() == code) {
801 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
803 string filename = filen;
805 if (filename.empty()) {
806 // Launch a file browser
807 string initpath = lyxrc.document_path;
810 string const trypath = owner_->buffer()->filePath();
811 // If directory is writeable, use this as default.
812 if (IsDirWriteable(trypath))
816 FileDialog fileDlg(_("Select LyX document to insert"),
818 make_pair(string(_("Documents|#o#O")),
819 string(lyxrc.document_path)),
820 make_pair(string(_("Examples|#E#e")),
821 string(AddPath(system_lyxdir, "examples"))));
823 FileDialog::Result result =
824 fileDlg.open(initpath,
825 _("*.lyx| LyX Documents (*.lyx)"));
827 if (result.first == FileDialog::Later)
830 filename = result.second;
832 // check selected filename
833 if (filename.empty()) {
834 owner_->message(_("Canceled."));
839 // get absolute path of file and add ".lyx" to the filename if
841 filename = FileSearch(string(), filename, "lyx");
843 string const disp_fn = MakeDisplayPath(filename);
844 owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
845 bool const res = bv_->insertLyXFile(filename);
847 owner_->message(bformat(_("Document %1$s inserted."), disp_fn));
849 owner_->message(bformat(_("Could not insert document %1$s"), disp_fn));
853 void BufferView::Pimpl::trackChanges()
855 Buffer * buf(bv_->buffer());
856 bool const tracking(buf->params.tracking_changes);
859 ParIterator const end = buf->par_iterator_end();
860 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
861 (*it)->trackChanges();
863 buf->params.tracking_changes = true;
865 // we cannot allow undos beyond the freeze point
866 buf->undostack.clear();
868 update(BufferView::SELECT);
869 bv_->text->setCursor(buf->paragraphs.begin(), 0);
870 #warning changes FIXME
871 //moveCursorUpdate(false);
873 bool found = lyxfind::findNextChange(bv_);
875 owner_->getDialogs().show("changes");
879 ParIterator const end = buf->par_iterator_end();
880 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
881 (*it)->untrackChanges();
883 buf->params.tracking_changes = false;
886 buf->redostack.clear();
890 // Doesn't go through lyxfunc, so we need to update the
891 // layout choice etc. ourselves
892 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in)
894 // e.g. Qt mouse press when no buffer
898 screen().hideCursor();
900 bool const res = dispatch(ev_in);
902 // see workAreaKeyPress
903 cursor_timeout.restart();
904 screen().showCursor(*bv_);
906 // FIXME: we should skip these when selecting
907 bv_->owner()->updateLayoutChoice();
908 bv_->owner()->updateToolbar();
911 // slight hack: this is only called currently when
912 // we clicked somewhere, so we force through the display
913 // of the new status here.
914 bv_->owner()->clearMessage();
920 bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
922 // Make sure that the cached BufferView is correct.
923 FuncRequest ev = ev_in;
926 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
927 << " action[" << ev.action << ']'
928 << " arg[" << ev.argument << ']'
929 << " x[" << ev.x << ']'
930 << " y[" << ev.y << ']'
931 << " button[" << ev.button() << ']'
934 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
938 case LFUN_SCROLL_INSET:
939 // this is not handled here as this function is only active
940 // if we have a locking_inset and that one is (or contains)
944 case LFUN_FILE_INSERT:
945 MenuInsertLyXFile(ev.argument);
948 case LFUN_FILE_INSERT_ASCII_PARA:
949 InsertAsciiFile(bv_, ev.argument, true);
952 case LFUN_FILE_INSERT_ASCII:
953 InsertAsciiFile(bv_, ev.argument, false);
957 lang(bv_, ev.argument);
959 owner_->view_state_changed();
964 owner_->view_state_changed();
969 owner_->view_state_changed();
974 owner_->view_state_changed();
979 owner_->view_state_changed();
984 owner_->view_state_changed();
989 owner_->view_state_changed();
994 owner_->view_state_changed();
999 owner_->view_state_changed();
1002 case LFUN_FONT_SIZE:
1003 fontSize(bv_, ev.argument);
1004 owner_->view_state_changed();
1007 case LFUN_FONT_STATE:
1008 owner_->getLyXFunc().setMessage(currentState(bv_));
1011 case LFUN_INSERT_LABEL: {
1012 // Try and generate a valid label
1013 string const contents = ev.argument.empty() ?
1014 getPossibleLabel(*bv_) : ev.argument;
1015 InsetCommandParams icp("label", contents);
1016 string data = InsetCommandMailer::params2string("label", icp);
1017 owner_->getDialogs().show("label", data, 0);
1021 case LFUN_BOOKMARK_SAVE:
1022 savePosition(strToUnsignedInt(ev.argument));
1025 case LFUN_BOOKMARK_GOTO:
1026 restorePosition(strToUnsignedInt(ev.argument));
1029 case LFUN_REF_GOTO: {
1030 string label = ev.argument;
1031 if (label.empty()) {
1033 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1035 label = inset->getContents();
1041 bv_->gotoLabel(label);
1045 // --- accented characters ---------------------------
1048 case LFUN_CIRCUMFLEX:
1058 case LFUN_SPECIAL_CARON:
1061 case LFUN_HUNG_UMLAUT:
1064 if (ev.argument.empty()) {
1066 owner_->getLyXFunc().handleKeyFunc(ev.action);
1068 owner_->getLyXFunc().handleKeyFunc(ev.action);
1069 owner_->getIntl().getTransManager()
1070 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
1071 update(bv_->getLyXText(), BufferView::SELECT);
1075 case LFUN_MATH_MACRO:
1076 case LFUN_MATH_DELIM:
1077 case LFUN_INSERT_MATRIX:
1078 case LFUN_INSERT_MATH:
1079 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
1080 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
1081 case LFUN_MATH_MODE: // Open or create an inlined math inset
1085 case LFUN_INSET_APPLY: {
1086 string const name = ev.getArg(0);
1088 InsetBase * inset = owner_->getDialogs().getOpenInset(name);
1090 // This works both for 'original' and 'mathed' insets.
1091 // Note that the localDispatch performs updateInset
1093 FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
1094 inset->localDispatch(fr);
1096 FuncRequest fr(bv_, LFUN_INSET_INSERT, ev.argument);
1102 case LFUN_INSET_INSERT: {
1103 Inset * inset = createInset(ev);
1104 if (inset && insertInset(inset)) {
1107 string const name = ev.getArg(0);
1108 if (name == "bibitem") {
1109 // We need to do a redraw because the maximum
1110 // InsetBibitem width could have changed
1111 #warning please check you mean repaint() not update(),
1112 #warning and whether the repaint() is needed at all
1122 case LFUN_FLOAT_LIST:
1123 if (tclass.floats().typeExist(ev.argument)) {
1124 Inset * inset = new InsetFloatList(ev.argument);
1125 if (!insertInset(inset, tclass.defaultLayoutName()))
1128 lyxerr << "Non-existent float type: "
1129 << ev.argument << endl;
1133 case LFUN_LAYOUT_PARAGRAPH: {
1134 Paragraph const * par = &*bv_->getLyXText()->cursor.par();
1139 params2string(*par, data);
1141 data = "show\n" + data;
1142 bv_->owner()->getDialogs().show("paragraph", data);
1146 case LFUN_PARAGRAPH_UPDATE: {
1147 Paragraph const * par = &*bv_->getLyXText()->cursor.par();
1152 params2string(*par, data);
1154 // Will the paragraph accept changes from the dialog?
1155 Inset * const inset = par->inInset();
1157 !(inset && inset->forceDefaultParagraphs(inset));
1159 data = "update " + tostr(accept) + '\n' + data;
1160 bv_->owner()->getDialogs().update("paragraph", data);
1164 case LFUN_PARAGRAPH_APPLY:
1165 setParagraphParams(*bv_, ev.argument);
1168 case LFUN_THESAURUS_ENTRY:
1170 string arg = ev.argument;
1173 arg = bv_->getLyXText()->selectionAsString(buffer_,
1177 if (arg.size() > 100 || arg.empty()) {
1178 // Get word or selection
1179 bv_->getLyXText()->selectWordWhenUnderCursor(LyXText::WHOLE_WORD);
1180 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
1181 // FIXME: where is getLyXText()->unselect(bv_) ?
1185 bv_->owner()->getDialogs().show("thesaurus", arg);
1189 case LFUN_TRACK_CHANGES:
1193 case LFUN_MERGE_CHANGES:
1194 owner_->getDialogs().show("changes");
1197 case LFUN_ACCEPT_ALL_CHANGES: {
1198 update(BufferView::SELECT);
1199 bv_->text->setCursor(bv_->buffer()->paragraphs.begin(), 0);
1200 #warning FIXME changes
1201 //moveCursorUpdate(false);
1203 while (lyxfind::findNextChange(bv_)) {
1204 bv_->getLyXText()->acceptChange();
1206 update(BufferView::SELECT);
1210 case LFUN_REJECT_ALL_CHANGES: {
1211 update(BufferView::SELECT);
1212 bv_->text->setCursor(bv_->buffer()->paragraphs.begin(), 0);
1213 #warning FIXME changes
1214 //moveCursorUpdate(false);
1216 while (lyxfind::findNextChange(bv_)) {
1217 bv_->getLyXText()->rejectChange();
1219 update(BufferView::SELECT);
1223 case LFUN_ACCEPT_CHANGE: {
1224 bv_->getLyXText()->acceptChange();
1225 update(BufferView::SELECT);
1229 case LFUN_REJECT_CHANGE: {
1230 bv_->getLyXText()->rejectChange();
1231 update(BufferView::SELECT);
1235 case LFUN_UNKNOWN_ACTION:
1236 ev.errorMessage(N_("Unknown function!"));
1240 return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
1247 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
1249 // if we are in a locking inset we should try to insert the
1250 // inset there otherwise this is a illegal function now
1251 if (bv_->theLockingInset()) {
1252 if (bv_->theLockingInset()->insetAllowed(inset))
1253 return bv_->theLockingInset()->insertInset(bv_, inset);
1257 // not quite sure if we want this...
1258 setCursorParUndo(bv_);
1261 beforeChange(bv_->text);
1262 if (!lout.empty()) {
1263 update(BufferView::SELECT);
1264 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1265 update(BufferView::SELECT);
1267 if (!bv_->text->cursor.par()->empty()) {
1268 bv_->text->cursorLeft(bv_);
1270 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1271 update(BufferView::SELECT);
1275 LyXTextClass const & tclass =
1276 buffer_->params.getLyXTextClass();
1277 bool hasLayout = tclass.hasLayout(lres);
1278 string lay = tclass.defaultLayoutName();
1280 if (hasLayout != false) {
1284 // layout not fount using default
1285 lay = tclass.defaultLayoutName();
1288 bv_->text->setLayout(lay);
1290 bv_->text->setParagraph(0, 0,
1292 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
1297 update(BufferView::SELECT);
1300 bv_->text->insertInset(inset);
1301 update(BufferView::SELECT);
1308 void BufferView::Pimpl::updateInset(Inset * inset)
1310 if (!inset || !available())
1313 // first check for locking insets
1314 if (bv_->theLockingInset()) {
1315 if (bv_->theLockingInset() == inset) {
1316 if (bv_->text->updateInset(inset)) {
1321 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
1322 if (bv_->text->updateInset(bv_->theLockingInset())) {
1330 // then check if the inset is a top_level inset (has no owner)
1331 // if yes do the update as always otherwise we have to update the
1332 // toplevel inset where this inset is inside
1333 Inset * tl_inset = inset;
1334 while (tl_inset->owner())
1335 tl_inset = tl_inset->owner();
1336 if (tl_inset == inset) {
1337 update(BufferView::UPDATE);
1338 if (bv_->text->updateInset(inset)) {
1339 update(BufferView::SELECT);
1342 } else if (static_cast<UpdatableInset *>(tl_inset)
1343 ->updateInsetInInset(bv_, inset))
1345 if (bv_->text->updateInset(tl_inset)) {