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"
13 #include "bufferview_funcs.h"
17 #include "FloatList.h"
18 #include "funcrequest.h"
21 #include "iterators.h"
22 #include "lyx_cb.h" // added for Dispatch functions
29 #include "paragraph.h"
30 #include "ParagraphParameters.h"
31 #include "TextCache.h"
32 #include "undo_funcs.h"
34 #include "insets/insetfloatlist.h"
35 #include "insets/insetgraphics.h"
36 #include "insets/insetinclude.h"
37 #include "insets/insetref.h"
38 #include "insets/insettext.h"
40 #include "frontends/Alert.h"
41 #include "frontends/Dialogs.h"
42 #include "frontends/FileDialog.h"
43 #include "frontends/LyXView.h"
44 #include "frontends/LyXScreenFactory.h"
45 #include "frontends/mouse_state.h"
46 #include "frontends/screen.h"
47 #include "frontends/WorkArea.h"
48 #include "frontends/WorkAreaFactory.h"
50 #include "mathed/formulabase.h"
52 #include "graphics/Previews.h"
54 #include "support/LAssert.h"
55 #include "support/lstrings.h"
56 #include "support/filetools.h"
58 #include <boost/bind.hpp>
59 #include <boost/signals/connection.hpp>
60 #include "BoostFormat.h"
76 extern BufferList bufferlist;
81 unsigned int const saved_positions_num = 20;
83 // All the below connection objects are needed because of a bug in some
84 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
85 // to these connections we avoid a segfault upon startup, and also at exit.
88 boost::signals::connection dispatchcon;
89 boost::signals::connection timecon;
90 boost::signals::connection doccon;
91 boost::signals::connection resizecon;
92 boost::signals::connection kpresscon;
93 boost::signals::connection selectioncon;
94 boost::signals::connection lostcon;
100 BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
101 int xpos, int ypos, int width, int height)
102 : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
103 using_xterm_cursor(false)
105 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
106 screen_.reset(LyXScreenFactory::create(workarea()));
109 doccon = workarea().scrollDocView
110 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
111 resizecon = workarea().workAreaResize
112 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
113 dispatchcon = workarea().dispatch
114 .connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
115 kpresscon = workarea().workAreaKeyPress
116 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
117 selectioncon = workarea().selectionRequested
118 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
119 lostcon = workarea().selectionLost
120 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
122 timecon = cursor_timeout.timeout
123 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
124 cursor_timeout.start();
125 saved_positions.resize(saved_positions_num);
129 WorkArea & BufferView::Pimpl::workarea() const
131 return *workarea_.get();
135 LyXScreen & BufferView::Pimpl::screen() const
137 return *screen_.get();
141 Painter & BufferView::Pimpl::painter() const
143 return workarea().getPainter();
147 void BufferView::Pimpl::buffer(Buffer * b)
149 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
152 buffer_->delUser(bv_);
154 // Put the old text into the TextCache, but
155 // only if the buffer is still loaded.
156 // Also set the owner of the test to 0
157 // bv_->text->owner(0);
158 textcache.add(buffer_, workarea().workWidth(), bv_->text);
159 if (lyxerr.debugging())
160 textcache.show(lyxerr, "BufferView::buffer");
165 // set current buffer
168 // if we're quitting lyx, don't bother updating stuff
172 // if we are closing the buffer, use the first buffer as current
174 buffer_ = bufferlist.first();
178 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
179 buffer_->addUser(bv_);
181 // If we don't have a text object for this, we make one
182 if (bv_->text == 0) {
183 resizeCurrentBuffer();
186 // FIXME: needed when ?
187 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
189 // Similarly, buffer-dependent dialogs should be updated or
190 // hidden. This should go here because some dialogs (eg ToC)
191 // require bv_->text.
192 owner_->getDialogs().updateBufferDependent(true);
194 lyxerr[Debug::INFO] << " No Buffer!" << endl;
195 owner_->getDialogs().hideBufferDependent();
197 // Also remove all remaining text's from the testcache.
198 // (there should not be any!) (if there is any it is a
200 if (lyxerr.debugging())
201 textcache.show(lyxerr, "buffer delete all");
207 owner_->updateMenubar();
208 owner_->updateToolbar();
209 owner_->updateLayoutChoice();
210 owner_->updateWindowTitle();
212 if (grfx::Previews::activated() && buffer_)
213 grfx::Previews::get().generateBufferPreviews(*buffer_);
217 bool BufferView::Pimpl::fitCursor()
221 if (bv_->theLockingInset()) {
222 bv_->theLockingInset()->fitInsetCursor(bv_);
225 ret = screen().fitCursor(bv_->text, bv_);
228 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
230 // We need to always update, in case we did a
231 // paste and we stayed anchored to a row, but
232 // the actual height of the doc changed ...
238 void BufferView::Pimpl::redoCurrentBuffer()
240 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
241 if (buffer_ && bv_->text) {
242 resizeCurrentBuffer();
244 owner_->updateLayoutChoice();
250 int BufferView::Pimpl::resizeCurrentBuffer()
252 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
255 Paragraph * selstartpar = 0;
256 Paragraph * selendpar = 0;
257 UpdatableInset * the_locking_inset = 0;
260 pos_type selstartpos = 0;
261 pos_type selendpos = 0;
262 bool selection = false;
263 bool mark_set = false;
267 owner_->message(_("Formatting document..."));
270 par = bv_->text->cursor.par();
271 pos = bv_->text->cursor.pos();
272 selstartpar = bv_->text->selection.start.par();
273 selstartpos = bv_->text->selection.start.pos();
274 selendpar = bv_->text->selection.end.par();
275 selendpos = bv_->text->selection.end.pos();
276 selection = bv_->text->selection.set();
277 mark_set = bv_->text->selection.mark();
278 the_locking_inset = bv_->theLockingInset();
279 buffer_->resizeInsets(bv_);
280 // I don't think the delete and new are necessary here we just could
281 // call only init! (Jug 20020419)
283 bv_->text = new LyXText(bv_);
284 bv_->text->init(bv_);
286 // See if we have a text in TextCache that fits
287 // the new buffer_ with the correct width.
288 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
290 if (lyxerr.debugging()) {
291 lyxerr << "Found a LyXText that fits:\n";
292 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
294 // Set the owner of the newly found text
295 // bv_->text->owner(bv_);
296 if (lyxerr.debugging())
297 textcache.show(lyxerr, "resizeCurrentBuffer");
299 buffer_->resizeInsets(bv_);
301 bv_->text = new LyXText(bv_);
302 bv_->text->init(bv_);
303 //buffer_->resizeInsets(bv_);
308 bv_->text->selection.set(true);
309 // At this point just to avoid the Delete-Empty-Paragraph-
310 // Mechanism when setting the cursor.
311 bv_->text->selection.mark(mark_set);
313 bv_->text->setCursor(selstartpar, selstartpos);
314 bv_->text->selection.cursor = bv_->text->cursor;
315 bv_->text->setCursor(selendpar, selendpos);
316 bv_->text->setSelection();
317 bv_->text->setCursor(par, pos);
319 bv_->text->setCursor(par, pos);
320 bv_->text->selection.cursor = bv_->text->cursor;
321 bv_->text->selection.set(false);
323 // remake the inset locking
324 bv_->theLockingInset(the_locking_inset);
327 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
338 void BufferView::Pimpl::repaint()
340 // Regenerate the screen.
341 screen().redraw(bv_->text, bv_);
345 void BufferView::Pimpl::updateScrollbar()
348 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
349 workarea().setScrollbarParams(0, 0, 0);
353 LyXText const & t = *bv_->text;
355 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
356 << t.top_y() << ", default height " << defaultRowHeight() << endl;
358 workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
362 void BufferView::Pimpl::scrollDocView(int value)
364 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
369 screen().draw(bv_->text, bv_, value);
371 if (!lyxrc.cursor_follows_scrollbar)
374 LyXText * vbt = bv_->text;
376 int const height = defaultRowHeight();
377 int const first = static_cast<int>((bv_->text->top_y() + height));
378 int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
380 if (vbt->cursor.y() < first)
381 vbt->setCursorFromCoordinates(0, first);
382 else if (vbt->cursor.y() > last)
383 vbt->setCursorFromCoordinates(0, last);
385 owner_->updateLayoutChoice();
389 void BufferView::Pimpl::scroll(int lines)
395 LyXText const * t = bv_->text;
396 int const line_height = defaultRowHeight();
398 // The new absolute coordinate
399 int new_top_y = t->top_y() + lines * line_height;
401 // Restrict to a valid value
402 new_top_y = std::min(t->height - 4 * line_height, new_top_y);
403 new_top_y = std::max(0, new_top_y);
405 scrollDocView(new_top_y);
407 // Update the scrollbar.
408 workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
412 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
413 key_modifier::state state)
415 bv_->owner()->getLyXFunc().processKeySym(key, state);
419 void BufferView::Pimpl::selectionRequested()
426 LyXText * text = bv_->getLyXText();
428 if (text->selection.set() &&
429 (!bv_->text->xsel_cache.set() ||
430 text->selection.start != bv_->text->xsel_cache.start ||
431 text->selection.end != bv_->text->xsel_cache.end))
433 bv_->text->xsel_cache = text->selection;
434 sel = text->selectionAsString(bv_->buffer(), false);
435 } else if (!text->selection.set()) {
437 bv_->text->xsel_cache.set(false);
440 workarea().putClipboard(sel);
445 void BufferView::Pimpl::selectionLost()
450 bv_->getLyXText()->clearSelection();
452 bv_->text->xsel_cache.set(false);
457 void BufferView::Pimpl::workAreaResize()
459 static int work_area_width;
460 static int work_area_height;
462 bool const widthChange = workarea().workWidth() != work_area_width;
463 bool const heightChange = workarea().workHeight() != work_area_height;
465 // update from work area
466 work_area_width = workarea().workWidth();
467 work_area_height = workarea().workHeight();
471 // The visible LyXView need a resize
472 resizeCurrentBuffer();
474 // Remove all texts from the textcache
475 // This is not _really_ what we want to do. What
476 // we really want to do is to delete in textcache
477 // that does not have a BufferView with matching
478 // width, but as long as we have only one BufferView
479 // deleting all gives the same result.
480 if (lyxerr.debugging())
481 textcache.show(lyxerr, "Expose delete all");
483 // FIXME: this is already done in resizeCurrentBuffer() ??
484 buffer_->resizeInsets(bv_);
485 } else if (heightChange) {
486 // fitCursor() ensures we don't jump back
487 // to the start of the document on vertical
493 if (widthChange || heightChange) {
497 // always make sure that the scrollbar is sane.
499 owner_->updateLayoutChoice();
504 void BufferView::Pimpl::update()
506 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
507 screen().update(*bv_);
508 bv_->text->clearPaint();
513 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
515 if (!text->selection.set() && (f & SELECT)) {
516 text->selection.cursor = text->cursor;
521 if (text->inset_owner) {
522 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
523 updateInset(text->inset_owner);
530 void BufferView::Pimpl::update(BufferView::UpdateCodes f)
532 LyXText * text = bv_->text;
534 if (!text->selection.set() && (f & SELECT)) {
535 text->selection.cursor = text->cursor;
540 if (text->inset_owner) {
541 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
542 updateInset(text->inset_owner);
549 // Callback for cursor timer
550 void BufferView::Pimpl::cursorToggle()
553 cursor_timeout.restart();
557 if (!bv_->theLockingInset()) {
558 screen().cursorToggle(bv_);
560 bv_->theLockingInset()->toggleInsetCursor(bv_);
563 cursor_timeout.restart();
567 bool BufferView::Pimpl::available() const
569 if (buffer_ && bv_->text)
575 Change const BufferView::Pimpl::getCurrentChange()
577 if (!bv_->buffer()->params.tracking_changes)
578 return Change(Change::UNCHANGED);
580 LyXText * t(bv_->getLyXText());
582 if (!t->selection.set())
583 return Change(Change::UNCHANGED);
585 LyXCursor const & cur(t->selection.start);
586 return cur.par()->lookupChangeFull(cur.pos());
590 void BufferView::Pimpl::beforeChange(LyXText * text)
593 text->clearSelection();
597 void BufferView::Pimpl::savePosition(unsigned int i)
599 if (i >= saved_positions_num)
601 saved_positions[i] = Position(buffer_->fileName(),
602 bv_->text->cursor.par()->id(),
603 bv_->text->cursor.pos());
607 str << boost::format(_("Saved bookmark %1$d")) % i;
609 str << _("Saved bookmark ") << i;
611 owner_->message(STRCONV(str.str()));
616 void BufferView::Pimpl::restorePosition(unsigned int i)
618 if (i >= saved_positions_num)
621 string const fname = saved_positions[i].filename;
623 beforeChange(bv_->text);
625 if (fname != buffer_->fileName()) {
626 Buffer * b = bufferlist.exists(fname) ?
627 bufferlist.getBuffer(fname) :
628 bufferlist.loadLyXFile(fname); // don't ask, just load it
629 if (b != 0) buffer(b);
632 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
636 bv_->text->setCursor(par,
637 min(par->size(), saved_positions[i].par_pos));
639 update(BufferView::SELECT);
643 str << boost::format(_("Moved to bookmark %1$d")) % i;
645 str << _("Moved to bookmark ") << i;
647 owner_->message(STRCONV(str.str()));
652 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
654 if (i >= saved_positions_num)
657 return !saved_positions[i].filename.empty();
661 void BufferView::Pimpl::switchKeyMap()
663 if (!lyxrc.rtl_support)
666 LyXText * text = bv_->getLyXText();
667 if (text->real_current_font.isRightToLeft()
668 && !(bv_->theLockingInset()
669 && bv_->theLockingInset()->lyxCode() == Inset::ERT_CODE))
671 if (owner_->getIntl().keymap == Intl::PRIMARY)
672 owner_->getIntl().KeyMapSec();
674 if (owner_->getIntl().keymap == Intl::SECONDARY)
675 owner_->getIntl().KeyMapPrim();
680 void BufferView::Pimpl::insetUnlock()
682 if (bv_->theLockingInset()) {
683 bv_->theLockingInset()->insetUnlock(bv_);
684 bv_->theLockingInset(0);
690 void BufferView::Pimpl::showCursor()
692 if (bv_->theLockingInset())
693 bv_->theLockingInset()->showInsetCursor(bv_);
695 screen().showCursor(bv_->text, bv_);
699 void BufferView::Pimpl::hideCursor()
701 if (!bv_->theLockingInset())
702 screen().hideCursor();
706 void BufferView::Pimpl::toggleSelection(bool b)
708 if (bv_->theLockingInset())
709 bv_->theLockingInset()->toggleSelection(bv_, b);
710 screen().toggleSelection(bv_->text, bv_, b);
714 void BufferView::Pimpl::toggleToggle()
716 screen().toggleToggle(bv_->text, bv_);
720 void BufferView::Pimpl::center()
722 LyXText * t = bv_->text;
725 int const half_height = workarea().workHeight() / 2;
728 if (t->cursor.y() > half_height) {
729 new_y = t->cursor.y() - half_height;
732 // FIXME: look at this comment again ...
734 // FIXME: can we do this w/o calling screen directly ?
735 // This updates top_y() but means the fitCursor() call
736 // from the update(FITCUR) doesn't realise that we might
737 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
738 // the scrollbar to be updated as it should, so we have
739 // to do it manually. Any operation that does a center()
740 // and also might have moved top_y() must make sure to call
741 // updateScrollbar() currently. Never mind that this is a
742 // pretty obfuscated way of updating t->top_y()
743 screen().draw(t, bv_, new_y);
745 update(BufferView::SELECT);
749 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
751 workarea().putClipboard(stuff);
756 * Dispatch functions for actions which can be valid for BufferView->text
757 * and/or InsetText->text!!!
761 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
764 LyXCursor cursor = bv_->getLyXText()->cursor;
765 Buffer::inset_iterator it =
766 find_if(Buffer::inset_iterator(
767 cursor.par(), cursor.pos()),
768 buffer_->inset_iterator_end(),
769 lyx::compare_memfun(&Inset::lyxCode, code));
770 return it != buffer_->inset_iterator_end() ? (*it) : 0;
772 // Ok, this is a little bit too brute force but it
773 // should work for now. Better infrastructure is comming. (Lgb)
775 Buffer * b = bv_->buffer();
776 LyXCursor cursor = bv_->getLyXText()->cursor;
778 Buffer::inset_iterator beg = b->inset_iterator_begin();
779 Buffer::inset_iterator end = b->inset_iterator_end();
781 bool cursor_par_seen = false;
783 for (; beg != end; ++beg) {
784 if (beg.getPar() == cursor.par()) {
785 cursor_par_seen = true;
787 if (cursor_par_seen) {
788 if (beg.getPar() == cursor.par()
789 && beg.getPos() >= cursor.pos()) {
791 } else if (beg.getPar() != cursor.par()) {
798 // Now find the first inset that matches code.
799 for (; beg != end; ++beg) {
800 if (beg->lyxCode() == code) {
810 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
812 string filename = filen;
814 if (filename.empty()) {
815 // Launch a file browser
816 string initpath = lyxrc.document_path;
819 string const trypath = owner_->buffer()->filePath();
820 // If directory is writeable, use this as default.
821 if (IsDirWriteable(trypath))
825 FileDialog fileDlg(_("Select LyX document to insert"),
827 make_pair(string(_("Documents|#o#O")),
828 string(lyxrc.document_path)),
829 make_pair(string(_("Examples|#E#e")),
830 string(AddPath(system_lyxdir, "examples"))));
832 FileDialog::Result result =
833 fileDlg.open(initpath,
834 _("*.lyx| LyX Documents (*.lyx)"));
836 if (result.first == FileDialog::Later)
839 filename = result.second;
841 // check selected filename
842 if (filename.empty()) {
843 owner_->message(_("Canceled."));
848 // get absolute path of file and add ".lyx" to the filename if
850 filename = FileSearch(string(), filename, "lyx");
852 string const disp_fn(MakeDisplayPath(filename));
856 s1 << boost::format(_("Inserting document %1$s...")) % disp_fn;
858 s1 << _("Inserting document ") << disp_fn << _("...");
860 owner_->message(STRCONV(s1.str()));
861 bool const res = bv_->insertLyXFile(filename);
865 str << boost::format(_("Document %1$s inserted.")) % disp_fn;
867 str << _("Document ") << disp_fn << _(" inserted.");
869 owner_->message(STRCONV(str.str()));
873 str << boost::format(_("Could not insert document %1$s")) % disp_fn;
875 str << _("Could not insert document ") << disp_fn;
877 owner_->message(STRCONV(str.str()));
882 void BufferView::Pimpl::trackChanges()
884 Buffer * buf(bv_->buffer());
885 bool const tracking(buf->params.tracking_changes);
888 ParIterator const end = buf->par_iterator_end();
889 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
890 (*it)->trackChanges();
892 buf->params.tracking_changes = true;
894 // we cannot allow undos beyond the freeze point
895 buf->undostack.clear();
897 update(BufferView::SELECT);
898 bv_->text->setCursor(&(*buf->paragraphs.begin()), 0);
899 #warning changes FIXME
900 //moveCursorUpdate(false);
902 bool found = lyxfind::findNextChange(bv_);
904 owner_->getDialogs().show("changes");
908 ParIterator const end = buf->par_iterator_end();
909 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
910 (*it)->untrackChanges();
912 buf->params.tracking_changes = false;
915 buf->redostack.clear();
919 // Doesn't go through lyxfunc, so we need to update the
920 // layout choice etc. ourselves
921 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in)
923 // e.g. Qt mouse press when no buffer
927 bool const res = dispatch(ev_in);
929 bv_->owner()->updateLayoutChoice();
936 bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
938 // Make sure that the cached BufferView is correct.
939 FuncRequest ev = ev_in;
942 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
943 << " action[" << ev.action << ']'
944 << " arg[" << ev.argument << ']'
945 << " x[" << ev.x << ']'
946 << " y[" << ev.y << ']'
947 << " button[" << ev.button() << ']'
950 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
954 case LFUN_SCROLL_INSET:
955 // this is not handled here as this function is only active
956 // if we have a locking_inset and that one is (or contains)
960 case LFUN_LAYOUT_COPY:
961 bv_->copyEnvironment();
964 case LFUN_LAYOUT_PASTE:
965 bv_->pasteEnvironment();
969 case LFUN_FILE_INSERT:
970 MenuInsertLyXFile(ev.argument);
973 case LFUN_FILE_INSERT_ASCII_PARA:
974 InsertAsciiFile(bv_, ev.argument, true);
977 case LFUN_FILE_INSERT_ASCII:
978 InsertAsciiFile(bv_, ev.argument, false);
982 lang(bv_, ev.argument);
984 owner_->view_state_changed();
989 owner_->view_state_changed();
994 owner_->view_state_changed();
999 owner_->view_state_changed();
1004 owner_->view_state_changed();
1009 owner_->view_state_changed();
1014 owner_->view_state_changed();
1019 owner_->view_state_changed();
1022 case LFUN_UNDERLINE:
1024 owner_->view_state_changed();
1027 case LFUN_FONT_SIZE:
1028 fontSize(bv_, ev.argument);
1029 owner_->view_state_changed();
1032 case LFUN_FONT_STATE:
1033 owner_->getLyXFunc().setMessage(currentState(bv_));
1036 case LFUN_INSERT_LABEL: {
1037 // Try and generate a valid label
1038 string const contents = ev.argument.empty() ?
1039 getPossibleLabel(*bv_) : ev.argument;
1040 InsetCommandParams icp("label", contents);
1041 string data = InsetCommandMailer::params2string("label", icp);
1042 owner_->getDialogs().show("label", data, 0);
1046 case LFUN_BOOKMARK_SAVE:
1047 savePosition(strToUnsignedInt(ev.argument));
1050 case LFUN_BOOKMARK_GOTO:
1051 restorePosition(strToUnsignedInt(ev.argument));
1054 case LFUN_REF_GOTO: {
1055 string label = ev.argument;
1056 if (label.empty()) {
1058 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1060 label = inset->getContents();
1066 bv_->gotoLabel(label);
1070 // --- accented characters ---------------------------
1073 case LFUN_CIRCUMFLEX:
1083 case LFUN_SPECIAL_CARON:
1086 case LFUN_HUNG_UMLAUT:
1089 if (ev.argument.empty()) {
1091 owner_->getLyXFunc().handleKeyFunc(ev.action);
1093 owner_->getLyXFunc().handleKeyFunc(ev.action);
1094 owner_->getIntl().getTransManager()
1095 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
1096 update(bv_->getLyXText(), BufferView::SELECT);
1100 case LFUN_MATH_MACRO:
1101 case LFUN_MATH_DELIM:
1102 case LFUN_INSERT_MATRIX:
1103 case LFUN_INSERT_MATH:
1104 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
1105 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
1106 case LFUN_MATH_MODE: // Open or create an inlined math inset
1110 case LFUN_INSET_APPLY: {
1111 string const name = ev.getArg(0);
1113 InsetBase * inset = owner_->getDialogs().getOpenInset(name);
1115 // This works both for 'original' and 'mathed' insets.
1116 // Note that the localDispatch performs updateInset
1118 FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
1119 inset->localDispatch(fr);
1121 FuncRequest fr(bv_, LFUN_INSET_INSERT, ev.argument);
1127 case LFUN_INSET_INSERT: {
1128 Inset * inset = createInset(ev);
1129 if (inset && insertInset(inset)) {
1132 string const name = ev.getArg(0);
1133 if (name == "bibitem") {
1134 // We need to do a redraw because the maximum
1135 // InsetBibitem width could have changed
1136 #warning please check you mean repaint() not update(),
1137 #warning and whether the repaint() is needed at all
1147 case LFUN_FLOAT_LIST:
1148 if (tclass.floats().typeExist(ev.argument)) {
1149 Inset * inset = new InsetFloatList(ev.argument);
1150 if (!insertInset(inset, tclass.defaultLayoutName()))
1153 lyxerr << "Non-existent float type: "
1154 << ev.argument << endl;
1158 case LFUN_LAYOUT_PARAGRAPH: {
1159 Paragraph const * par = bv_->getLyXText()->cursor.par();
1164 params2string(*par, data);
1166 data = "show\n" + data;
1167 bv_->owner()->getDialogs().show("paragraph", data);
1171 case LFUN_PARAGRAPH_UPDATE: {
1172 Paragraph const * par = bv_->getLyXText()->cursor.par();
1177 params2string(*par, data);
1179 // Will the paragraph accept changes from the dialog?
1180 Inset * const inset = par->inInset();
1182 !(inset && inset->forceDefaultParagraphs(inset));
1184 data = "update " + tostr(accept) + '\n' + data;
1185 bv_->owner()->getDialogs().update("paragraph", data);
1189 case LFUN_PARAGRAPH_APPLY:
1190 setParagraphParams(*bv_, ev.argument);
1193 case LFUN_THESAURUS_ENTRY:
1195 string arg = ev.argument;
1198 arg = bv_->getLyXText()->selectionAsString(buffer_,
1202 if (arg.size() > 100 || arg.empty()) {
1203 // Get word or selection
1204 bv_->getLyXText()->selectWordWhenUnderCursor(LyXText::WHOLE_WORD);
1205 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
1206 // FIXME: where is getLyXText()->unselect(bv_) ?
1210 bv_->owner()->getDialogs().show("thesaurus", arg);
1214 case LFUN_TRACK_CHANGES:
1218 case LFUN_MERGE_CHANGES:
1219 owner_->getDialogs().show("changes");
1222 case LFUN_ACCEPT_ALL_CHANGES: {
1223 update(BufferView::SELECT);
1224 bv_->text->setCursor(&(*bv_->buffer()->paragraphs.begin()), 0);
1225 #warning FIXME changes
1226 //moveCursorUpdate(false);
1228 while (lyxfind::findNextChange(bv_)) {
1229 bv_->getLyXText()->acceptChange();
1231 update(BufferView::SELECT);
1235 case LFUN_REJECT_ALL_CHANGES: {
1236 update(BufferView::SELECT);
1237 bv_->text->setCursor(&(*bv_->buffer()->paragraphs.begin()), 0);
1238 #warning FIXME changes
1239 //moveCursorUpdate(false);
1241 while (lyxfind::findNextChange(bv_)) {
1242 bv_->getLyXText()->rejectChange();
1244 update(BufferView::SELECT);
1248 case LFUN_ACCEPT_CHANGE: {
1249 bv_->getLyXText()->acceptChange();
1250 update(BufferView::SELECT);
1254 case LFUN_REJECT_CHANGE: {
1255 bv_->getLyXText()->rejectChange();
1256 update(BufferView::SELECT);
1260 case LFUN_UNKNOWN_ACTION:
1261 ev.errorMessage(N_("Unknown function!"));
1265 return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
1272 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
1274 // if we are in a locking inset we should try to insert the
1275 // inset there otherwise this is a illegal function now
1276 if (bv_->theLockingInset()) {
1277 if (bv_->theLockingInset()->insetAllowed(inset))
1278 return bv_->theLockingInset()->insertInset(bv_, inset);
1282 // not quite sure if we want this...
1283 setCursorParUndo(bv_);
1286 beforeChange(bv_->text);
1287 if (!lout.empty()) {
1288 update(BufferView::SELECT);
1289 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1290 update(BufferView::SELECT);
1292 if (!bv_->text->cursor.par()->empty()) {
1293 bv_->text->cursorLeft(bv_);
1295 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1296 update(BufferView::SELECT);
1300 LyXTextClass const & tclass =
1301 buffer_->params.getLyXTextClass();
1302 bool hasLayout = tclass.hasLayout(lres);
1303 string lay = tclass.defaultLayoutName();
1305 if (hasLayout != false) {
1309 // layout not fount using default
1310 lay = tclass.defaultLayoutName();
1313 bv_->text->setLayout(lay);
1315 bv_->text->setParagraph(0, 0,
1317 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
1322 update(BufferView::SELECT);
1325 bv_->text->insertInset(inset);
1326 update(BufferView::SELECT);
1333 void BufferView::Pimpl::updateInset(Inset * inset)
1335 if (!inset || !available())
1338 // first check for locking insets
1339 if (bv_->theLockingInset()) {
1340 if (bv_->theLockingInset() == inset) {
1341 if (bv_->text->updateInset(inset)) {
1346 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
1347 if (bv_->text->updateInset(bv_->theLockingInset())) {
1355 // then check if the inset is a top_level inset (has no owner)
1356 // if yes do the update as always otherwise we have to update the
1357 // toplevel inset where this inset is inside
1358 Inset * tl_inset = inset;
1359 while (tl_inset->owner())
1360 tl_inset = tl_inset->owner();
1362 if (tl_inset == inset) {
1363 update(BufferView::UPDATE);
1364 if (bv_->text->updateInset(inset)) {
1365 update(BufferView::SELECT);
1368 } else if (static_cast<UpdatableInset *>(tl_inset)
1369 ->updateInsetInInset(bv_, inset))
1371 if (bv_->text->updateInset(tl_inset)) {