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 "support/BoostFormat.h"
75 using namespace bv_funcs;
77 extern BufferList bufferlist;
82 unsigned int const saved_positions_num = 20;
84 // All the below connection objects are needed because of a bug in some
85 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
86 // to these connections we avoid a segfault upon startup, and also at exit.
89 boost::signals::connection dispatchcon;
90 boost::signals::connection timecon;
91 boost::signals::connection doccon;
92 boost::signals::connection resizecon;
93 boost::signals::connection kpresscon;
94 boost::signals::connection selectioncon;
95 boost::signals::connection lostcon;
101 BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
102 int xpos, int ypos, int width, int height)
103 : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
104 using_xterm_cursor(false)
106 workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
107 screen_.reset(LyXScreenFactory::create(workarea()));
110 doccon = workarea().scrollDocView
111 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
112 resizecon = workarea().workAreaResize
113 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
114 dispatchcon = workarea().dispatch
115 .connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
116 kpresscon = workarea().workAreaKeyPress
117 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
118 selectioncon = workarea().selectionRequested
119 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
120 lostcon = workarea().selectionLost
121 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
123 timecon = cursor_timeout.timeout
124 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
125 cursor_timeout.start();
126 saved_positions.resize(saved_positions_num);
130 WorkArea & BufferView::Pimpl::workarea() const
132 return *workarea_.get();
136 LyXScreen & BufferView::Pimpl::screen() const
138 return *screen_.get();
142 Painter & BufferView::Pimpl::painter() const
144 return workarea().getPainter();
148 void BufferView::Pimpl::buffer(Buffer * b)
150 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
153 buffer_->delUser(bv_);
155 // Put the old text into the TextCache, but
156 // only if the buffer is still loaded.
157 // Also set the owner of the test to 0
158 // bv_->text->owner(0);
159 textcache.add(buffer_, workarea().workWidth(), bv_->text);
160 if (lyxerr.debugging())
161 textcache.show(lyxerr, "BufferView::buffer");
166 // set current buffer
169 // if we're quitting lyx, don't bother updating stuff
173 // if we are closing the buffer, use the first buffer as current
175 buffer_ = bufferlist.first();
179 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
180 buffer_->addUser(bv_);
182 // If we don't have a text object for this, we make one
183 if (bv_->text == 0) {
184 resizeCurrentBuffer();
187 // FIXME: needed when ?
188 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
190 // Buffer-dependent dialogs should be updated or
191 // hidden. This should go here because some dialogs (eg ToC)
192 // require bv_->text.
193 owner_->getDialogs().updateBufferDependent(true);
195 lyxerr[Debug::INFO] << " No Buffer!" << endl;
196 owner_->getDialogs().hideBufferDependent();
198 // Also remove all remaining text's from the testcache.
199 // (there should not be any!) (if there is any it is a
201 if (lyxerr.debugging())
202 textcache.show(lyxerr, "buffer delete all");
208 owner_->updateMenubar();
209 owner_->updateToolbar();
210 owner_->updateLayoutChoice();
211 owner_->updateWindowTitle();
214 // Don't forget to update the Layout
215 string const layoutname =
216 bv_->text->cursor.par()->layout()->name();
217 owner_->setLayout(layoutname);
220 if (grfx::Previews::activated() && buffer_)
221 grfx::Previews::get().generateBufferPreviews(*buffer_);
225 bool BufferView::Pimpl::fitCursor()
229 if (bv_->theLockingInset()) {
230 bv_->theLockingInset()->fitInsetCursor(bv_);
233 ret = screen().fitCursor(bv_->text, bv_);
236 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
238 // We need to always update, in case we did a
239 // paste and we stayed anchored to a row, but
240 // the actual height of the doc changed ...
246 void BufferView::Pimpl::redoCurrentBuffer()
248 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
249 if (buffer_ && bv_->text) {
250 resizeCurrentBuffer();
252 owner_->updateLayoutChoice();
258 int BufferView::Pimpl::resizeCurrentBuffer()
260 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
263 Paragraph * selstartpar = 0;
264 Paragraph * selendpar = 0;
265 UpdatableInset * the_locking_inset = 0;
268 pos_type selstartpos = 0;
269 pos_type selendpos = 0;
270 bool selection = false;
271 bool mark_set = false;
275 owner_->message(_("Formatting document..."));
278 par = bv_->text->cursor.par();
279 pos = bv_->text->cursor.pos();
280 selstartpar = bv_->text->selection.start.par();
281 selstartpos = bv_->text->selection.start.pos();
282 selendpar = bv_->text->selection.end.par();
283 selendpos = bv_->text->selection.end.pos();
284 selection = bv_->text->selection.set();
285 mark_set = bv_->text->selection.mark();
286 the_locking_inset = bv_->theLockingInset();
287 buffer_->resizeInsets(bv_);
288 // I don't think the delete and new are necessary here we just could
289 // call only init! (Jug 20020419)
291 bv_->text = new LyXText(bv_);
292 bv_->text->init(bv_);
294 // See if we have a text in TextCache that fits
295 // the new buffer_ with the correct width.
296 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
298 if (lyxerr.debugging()) {
299 lyxerr << "Found a LyXText that fits:\n";
300 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
302 // Set the owner of the newly found text
303 // bv_->text->owner(bv_);
304 if (lyxerr.debugging())
305 textcache.show(lyxerr, "resizeCurrentBuffer");
307 buffer_->resizeInsets(bv_);
309 bv_->text = new LyXText(bv_);
310 bv_->text->init(bv_);
311 //buffer_->resizeInsets(bv_);
316 bv_->text->selection.set(true);
317 // At this point just to avoid the Delete-Empty-Paragraph-
318 // Mechanism when setting the cursor.
319 bv_->text->selection.mark(mark_set);
321 bv_->text->setCursor(selstartpar, selstartpos);
322 bv_->text->selection.cursor = bv_->text->cursor;
323 bv_->text->setCursor(selendpar, selendpos);
324 bv_->text->setSelection();
325 bv_->text->setCursor(par, pos);
327 bv_->text->setCursor(par, pos);
328 bv_->text->selection.cursor = bv_->text->cursor;
329 bv_->text->selection.set(false);
331 // remake the inset locking
332 bv_->theLockingInset(the_locking_inset);
335 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
340 // reset the "Formatting..." message
341 owner_->clearMessage();
349 void BufferView::Pimpl::repaint()
351 // Regenerate the screen.
352 screen().redraw(bv_->text, bv_);
356 void BufferView::Pimpl::updateScrollbar()
359 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
360 workarea().setScrollbarParams(0, 0, 0);
364 LyXText const & t = *bv_->text;
366 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
367 << t.top_y() << ", default height " << defaultRowHeight() << endl;
369 workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
373 void BufferView::Pimpl::scrollDocView(int value)
375 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
380 screen().draw(bv_->text, bv_, value);
382 if (!lyxrc.cursor_follows_scrollbar)
385 LyXText * vbt = bv_->text;
387 int const height = defaultRowHeight();
388 int const first = static_cast<int>((bv_->text->top_y() + height));
389 int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
391 if (vbt->cursor.y() < first)
392 vbt->setCursorFromCoordinates(0, first);
393 else if (vbt->cursor.y() > last)
394 vbt->setCursorFromCoordinates(0, last);
396 owner_->updateLayoutChoice();
400 void BufferView::Pimpl::scroll(int lines)
406 LyXText const * t = bv_->text;
407 int const line_height = defaultRowHeight();
409 // The new absolute coordinate
410 int new_top_y = t->top_y() + lines * line_height;
412 // Restrict to a valid value
413 new_top_y = std::min(t->height - 4 * line_height, new_top_y);
414 new_top_y = std::max(0, new_top_y);
416 scrollDocView(new_top_y);
418 // Update the scrollbar.
419 workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
423 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
424 key_modifier::state state)
426 bv_->owner()->getLyXFunc().processKeySym(key, state);
430 void BufferView::Pimpl::selectionRequested()
437 LyXText * text = bv_->getLyXText();
439 if (text->selection.set() &&
440 (!bv_->text->xsel_cache.set() ||
441 text->selection.start != bv_->text->xsel_cache.start ||
442 text->selection.end != bv_->text->xsel_cache.end))
444 bv_->text->xsel_cache = text->selection;
445 sel = text->selectionAsString(bv_->buffer(), false);
446 } else if (!text->selection.set()) {
448 bv_->text->xsel_cache.set(false);
451 workarea().putClipboard(sel);
456 void BufferView::Pimpl::selectionLost()
461 bv_->getLyXText()->clearSelection();
463 bv_->text->xsel_cache.set(false);
468 void BufferView::Pimpl::workAreaResize()
470 static int work_area_width;
471 static int work_area_height;
473 bool const widthChange = workarea().workWidth() != work_area_width;
474 bool const heightChange = workarea().workHeight() != work_area_height;
476 // update from work area
477 work_area_width = workarea().workWidth();
478 work_area_height = workarea().workHeight();
482 // The visible LyXView need a resize
483 resizeCurrentBuffer();
485 // Remove all texts from the textcache
486 // This is not _really_ what we want to do. What
487 // we really want to do is to delete in textcache
488 // that does not have a BufferView with matching
489 // width, but as long as we have only one BufferView
490 // deleting all gives the same result.
491 if (lyxerr.debugging())
492 textcache.show(lyxerr, "Expose delete all");
494 // FIXME: this is already done in resizeCurrentBuffer() ??
495 buffer_->resizeInsets(bv_);
496 } else if (heightChange) {
497 // fitCursor() ensures we don't jump back
498 // to the start of the document on vertical
504 if (widthChange || heightChange) {
508 // always make sure that the scrollbar is sane.
510 owner_->updateLayoutChoice();
515 void BufferView::Pimpl::update()
517 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
518 screen().update(*bv_);
519 bv_->text->clearPaint();
524 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
526 if (!text->selection.set() && (f & SELECT)) {
527 text->selection.cursor = text->cursor;
532 if (text->inset_owner) {
533 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
534 updateInset(text->inset_owner);
541 void BufferView::Pimpl::update(BufferView::UpdateCodes f)
543 LyXText * text = bv_->text;
545 if (!text->selection.set() && (f & SELECT)) {
546 text->selection.cursor = text->cursor;
551 if (text->inset_owner) {
552 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
553 updateInset(text->inset_owner);
560 // Callback for cursor timer
561 void BufferView::Pimpl::cursorToggle()
564 cursor_timeout.restart();
568 if (!bv_->theLockingInset()) {
569 screen().cursorToggle(bv_);
571 bv_->theLockingInset()->toggleInsetCursor(bv_);
574 cursor_timeout.restart();
578 bool BufferView::Pimpl::available() const
580 if (buffer_ && bv_->text)
586 Change const BufferView::Pimpl::getCurrentChange()
588 if (!bv_->buffer()->params.tracking_changes)
589 return Change(Change::UNCHANGED);
591 LyXText * t(bv_->getLyXText());
593 if (!t->selection.set())
594 return Change(Change::UNCHANGED);
596 LyXCursor const & cur(t->selection.start);
597 return cur.par()->lookupChangeFull(cur.pos());
601 void BufferView::Pimpl::beforeChange(LyXText * text)
604 text->clearSelection();
608 void BufferView::Pimpl::savePosition(unsigned int i)
610 if (i >= saved_positions_num)
612 saved_positions[i] = Position(buffer_->fileName(),
613 bv_->text->cursor.par()->id(),
614 bv_->text->cursor.pos());
618 str << boost::format(_("Saved bookmark %1$d")) % i;
620 str << _("Saved bookmark ") << i;
622 owner_->message(STRCONV(str.str()));
627 void BufferView::Pimpl::restorePosition(unsigned int i)
629 if (i >= saved_positions_num)
632 string const fname = saved_positions[i].filename;
634 beforeChange(bv_->text);
636 if (fname != buffer_->fileName()) {
637 Buffer * b = bufferlist.exists(fname) ?
638 bufferlist.getBuffer(fname) :
639 bufferlist.loadLyXFile(fname); // don't ask, just load it
640 if (b != 0) buffer(b);
643 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
647 bv_->text->setCursor(par,
648 min(par->size(), saved_positions[i].par_pos));
650 update(BufferView::SELECT);
654 str << boost::format(_("Moved to bookmark %1$d")) % i;
656 str << _("Moved to bookmark ") << i;
658 owner_->message(STRCONV(str.str()));
663 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
665 if (i >= saved_positions_num)
668 return !saved_positions[i].filename.empty();
672 void BufferView::Pimpl::switchKeyMap()
674 if (!lyxrc.rtl_support)
677 LyXText * text = bv_->getLyXText();
678 if (text->real_current_font.isRightToLeft()
679 && !(bv_->theLockingInset()
680 && bv_->theLockingInset()->lyxCode() == Inset::ERT_CODE))
682 if (owner_->getIntl().keymap == Intl::PRIMARY)
683 owner_->getIntl().KeyMapSec();
685 if (owner_->getIntl().keymap == Intl::SECONDARY)
686 owner_->getIntl().KeyMapPrim();
691 void BufferView::Pimpl::insetUnlock()
693 if (bv_->theLockingInset()) {
694 bv_->theLockingInset()->insetUnlock(bv_);
695 bv_->theLockingInset(0);
701 void BufferView::Pimpl::showCursor()
703 if (bv_->theLockingInset())
704 bv_->theLockingInset()->showInsetCursor(bv_);
706 screen().showCursor(bv_->text, bv_);
710 void BufferView::Pimpl::hideCursor()
712 if (!bv_->theLockingInset())
713 screen().hideCursor();
717 void BufferView::Pimpl::toggleSelection(bool b)
719 if (bv_->theLockingInset())
720 bv_->theLockingInset()->toggleSelection(bv_, b);
721 screen().toggleSelection(bv_->text, bv_, b);
725 void BufferView::Pimpl::toggleToggle()
727 screen().toggleToggle(bv_->text, bv_);
731 void BufferView::Pimpl::center()
733 LyXText * t = bv_->text;
736 int const half_height = workarea().workHeight() / 2;
739 if (t->cursor.y() > half_height) {
740 new_y = t->cursor.y() - half_height;
743 // FIXME: look at this comment again ...
745 // FIXME: can we do this w/o calling screen directly ?
746 // This updates top_y() but means the fitCursor() call
747 // from the update(FITCUR) doesn't realise that we might
748 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
749 // the scrollbar to be updated as it should, so we have
750 // to do it manually. Any operation that does a center()
751 // and also might have moved top_y() must make sure to call
752 // updateScrollbar() currently. Never mind that this is a
753 // pretty obfuscated way of updating t->top_y()
754 screen().draw(t, bv_, new_y);
756 update(BufferView::SELECT);
760 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
762 workarea().putClipboard(stuff);
767 * Dispatch functions for actions which can be valid for BufferView->text
768 * and/or InsetText->text!!!
772 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
775 LyXCursor cursor = bv_->getLyXText()->cursor;
776 Buffer::inset_iterator it =
777 find_if(Buffer::inset_iterator(
778 cursor.par(), cursor.pos()),
779 buffer_->inset_iterator_end(),
780 lyx::compare_memfun(&Inset::lyxCode, code));
781 return it != buffer_->inset_iterator_end() ? (*it) : 0;
783 // Ok, this is a little bit too brute force but it
784 // should work for now. Better infrastructure is comming. (Lgb)
786 Buffer * b = bv_->buffer();
787 LyXCursor cursor = bv_->getLyXText()->cursor;
789 Buffer::inset_iterator beg = b->inset_iterator_begin();
790 Buffer::inset_iterator end = b->inset_iterator_end();
792 bool cursor_par_seen = false;
794 for (; beg != end; ++beg) {
795 if (beg.getPar() == cursor.par()) {
796 cursor_par_seen = true;
798 if (cursor_par_seen) {
799 if (beg.getPar() == cursor.par()
800 && beg.getPos() >= cursor.pos()) {
802 } else if (beg.getPar() != cursor.par()) {
809 // Now find the first inset that matches code.
810 for (; beg != end; ++beg) {
811 if (beg->lyxCode() == code) {
821 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
823 string filename = filen;
825 if (filename.empty()) {
826 // Launch a file browser
827 string initpath = lyxrc.document_path;
830 string const trypath = owner_->buffer()->filePath();
831 // If directory is writeable, use this as default.
832 if (IsDirWriteable(trypath))
836 FileDialog fileDlg(_("Select LyX document to insert"),
838 make_pair(string(_("Documents|#o#O")),
839 string(lyxrc.document_path)),
840 make_pair(string(_("Examples|#E#e")),
841 string(AddPath(system_lyxdir, "examples"))));
843 FileDialog::Result result =
844 fileDlg.open(initpath,
845 _("*.lyx| LyX Documents (*.lyx)"));
847 if (result.first == FileDialog::Later)
850 filename = result.second;
852 // check selected filename
853 if (filename.empty()) {
854 owner_->message(_("Canceled."));
859 // get absolute path of file and add ".lyx" to the filename if
861 filename = FileSearch(string(), filename, "lyx");
863 string const disp_fn(MakeDisplayPath(filename));
867 s1 << boost::format(_("Inserting document %1$s...")) % disp_fn;
869 s1 << _("Inserting document ") << disp_fn << _("...");
871 owner_->message(STRCONV(s1.str()));
872 bool const res = bv_->insertLyXFile(filename);
876 str << boost::format(_("Document %1$s inserted.")) % disp_fn;
878 str << _("Document ") << disp_fn << _(" inserted.");
880 owner_->message(STRCONV(str.str()));
884 str << boost::format(_("Could not insert document %1$s")) % disp_fn;
886 str << _("Could not insert document ") << disp_fn;
888 owner_->message(STRCONV(str.str()));
893 void BufferView::Pimpl::trackChanges()
895 Buffer * buf(bv_->buffer());
896 bool const tracking(buf->params.tracking_changes);
899 ParIterator const end = buf->par_iterator_end();
900 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
901 (*it)->trackChanges();
903 buf->params.tracking_changes = true;
905 // we cannot allow undos beyond the freeze point
906 buf->undostack.clear();
908 update(BufferView::SELECT);
909 bv_->text->setCursor(&(*buf->paragraphs.begin()), 0);
910 #warning changes FIXME
911 //moveCursorUpdate(false);
913 bool found = lyxfind::findNextChange(bv_);
915 owner_->getDialogs().show("changes");
919 ParIterator const end = buf->par_iterator_end();
920 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
921 (*it)->untrackChanges();
923 buf->params.tracking_changes = false;
926 buf->redostack.clear();
930 // Doesn't go through lyxfunc, so we need to update the
931 // layout choice etc. ourselves
932 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in)
934 // e.g. Qt mouse press when no buffer
938 bool const res = dispatch(ev_in);
940 bv_->owner()->updateLayoutChoice();
943 // slight hack: this is only called currently when
944 // we clicked somewhere, so we force through the display
945 // of the new status here.
946 bv_->owner()->clearMessage();
952 bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
954 // Make sure that the cached BufferView is correct.
955 FuncRequest ev = ev_in;
958 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
959 << " action[" << ev.action << ']'
960 << " arg[" << ev.argument << ']'
961 << " x[" << ev.x << ']'
962 << " y[" << ev.y << ']'
963 << " button[" << ev.button() << ']'
966 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
970 case LFUN_SCROLL_INSET:
971 // this is not handled here as this function is only active
972 // if we have a locking_inset and that one is (or contains)
976 case LFUN_LAYOUT_COPY:
977 bv_->copyEnvironment();
980 case LFUN_LAYOUT_PASTE:
981 bv_->pasteEnvironment();
985 case LFUN_FILE_INSERT:
986 MenuInsertLyXFile(ev.argument);
989 case LFUN_FILE_INSERT_ASCII_PARA:
990 InsertAsciiFile(bv_, ev.argument, true);
993 case LFUN_FILE_INSERT_ASCII:
994 InsertAsciiFile(bv_, ev.argument, false);
998 lang(bv_, ev.argument);
1000 owner_->view_state_changed();
1005 owner_->view_state_changed();
1010 owner_->view_state_changed();
1015 owner_->view_state_changed();
1020 owner_->view_state_changed();
1025 owner_->view_state_changed();
1030 owner_->view_state_changed();
1035 owner_->view_state_changed();
1038 case LFUN_UNDERLINE:
1040 owner_->view_state_changed();
1043 case LFUN_FONT_SIZE:
1044 fontSize(bv_, ev.argument);
1045 owner_->view_state_changed();
1048 case LFUN_FONT_STATE:
1049 owner_->getLyXFunc().setMessage(currentState(bv_));
1052 case LFUN_INSERT_LABEL: {
1053 // Try and generate a valid label
1054 string const contents = ev.argument.empty() ?
1055 getPossibleLabel(*bv_) : ev.argument;
1056 InsetCommandParams icp("label", contents);
1057 string data = InsetCommandMailer::params2string("label", icp);
1058 owner_->getDialogs().show("label", data, 0);
1062 case LFUN_BOOKMARK_SAVE:
1063 savePosition(strToUnsignedInt(ev.argument));
1066 case LFUN_BOOKMARK_GOTO:
1067 restorePosition(strToUnsignedInt(ev.argument));
1070 case LFUN_REF_GOTO: {
1071 string label = ev.argument;
1072 if (label.empty()) {
1074 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1076 label = inset->getContents();
1082 bv_->gotoLabel(label);
1086 // --- accented characters ---------------------------
1089 case LFUN_CIRCUMFLEX:
1099 case LFUN_SPECIAL_CARON:
1102 case LFUN_HUNG_UMLAUT:
1105 if (ev.argument.empty()) {
1107 owner_->getLyXFunc().handleKeyFunc(ev.action);
1109 owner_->getLyXFunc().handleKeyFunc(ev.action);
1110 owner_->getIntl().getTransManager()
1111 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
1112 update(bv_->getLyXText(), BufferView::SELECT);
1116 case LFUN_MATH_MACRO:
1117 case LFUN_MATH_DELIM:
1118 case LFUN_INSERT_MATRIX:
1119 case LFUN_INSERT_MATH:
1120 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
1121 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
1122 case LFUN_MATH_MODE: // Open or create an inlined math inset
1126 case LFUN_INSET_APPLY: {
1127 string const name = ev.getArg(0);
1129 InsetBase * inset = owner_->getDialogs().getOpenInset(name);
1131 // This works both for 'original' and 'mathed' insets.
1132 // Note that the localDispatch performs updateInset
1134 FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
1135 inset->localDispatch(fr);
1137 FuncRequest fr(bv_, LFUN_INSET_INSERT, ev.argument);
1143 case LFUN_INSET_INSERT: {
1144 Inset * inset = createInset(ev);
1145 if (inset && insertInset(inset)) {
1148 string const name = ev.getArg(0);
1149 if (name == "bibitem") {
1150 // We need to do a redraw because the maximum
1151 // InsetBibitem width could have changed
1152 #warning please check you mean repaint() not update(),
1153 #warning and whether the repaint() is needed at all
1163 case LFUN_FLOAT_LIST:
1164 if (tclass.floats().typeExist(ev.argument)) {
1165 Inset * inset = new InsetFloatList(ev.argument);
1166 if (!insertInset(inset, tclass.defaultLayoutName()))
1169 lyxerr << "Non-existent float type: "
1170 << ev.argument << endl;
1174 case LFUN_LAYOUT_PARAGRAPH: {
1175 Paragraph const * par = bv_->getLyXText()->cursor.par();
1180 params2string(*par, data);
1182 data = "show\n" + data;
1183 bv_->owner()->getDialogs().show("paragraph", data);
1187 case LFUN_PARAGRAPH_UPDATE: {
1188 Paragraph const * par = bv_->getLyXText()->cursor.par();
1193 params2string(*par, data);
1195 // Will the paragraph accept changes from the dialog?
1196 Inset * const inset = par->inInset();
1198 !(inset && inset->forceDefaultParagraphs(inset));
1200 data = "update " + tostr(accept) + '\n' + data;
1201 bv_->owner()->getDialogs().update("paragraph", data);
1205 case LFUN_PARAGRAPH_APPLY:
1206 setParagraphParams(*bv_, ev.argument);
1209 case LFUN_THESAURUS_ENTRY:
1211 string arg = ev.argument;
1214 arg = bv_->getLyXText()->selectionAsString(buffer_,
1218 if (arg.size() > 100 || arg.empty()) {
1219 // Get word or selection
1220 bv_->getLyXText()->selectWordWhenUnderCursor(LyXText::WHOLE_WORD);
1221 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
1222 // FIXME: where is getLyXText()->unselect(bv_) ?
1226 bv_->owner()->getDialogs().show("thesaurus", arg);
1230 case LFUN_TRACK_CHANGES:
1234 case LFUN_MERGE_CHANGES:
1235 owner_->getDialogs().show("changes");
1238 case LFUN_ACCEPT_ALL_CHANGES: {
1239 update(BufferView::SELECT);
1240 bv_->text->setCursor(&(*bv_->buffer()->paragraphs.begin()), 0);
1241 #warning FIXME changes
1242 //moveCursorUpdate(false);
1244 while (lyxfind::findNextChange(bv_)) {
1245 bv_->getLyXText()->acceptChange();
1247 update(BufferView::SELECT);
1251 case LFUN_REJECT_ALL_CHANGES: {
1252 update(BufferView::SELECT);
1253 bv_->text->setCursor(&(*bv_->buffer()->paragraphs.begin()), 0);
1254 #warning FIXME changes
1255 //moveCursorUpdate(false);
1257 while (lyxfind::findNextChange(bv_)) {
1258 bv_->getLyXText()->rejectChange();
1260 update(BufferView::SELECT);
1264 case LFUN_ACCEPT_CHANGE: {
1265 bv_->getLyXText()->acceptChange();
1266 update(BufferView::SELECT);
1270 case LFUN_REJECT_CHANGE: {
1271 bv_->getLyXText()->rejectChange();
1272 update(BufferView::SELECT);
1276 case LFUN_UNKNOWN_ACTION:
1277 ev.errorMessage(N_("Unknown function!"));
1281 return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
1288 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
1290 // if we are in a locking inset we should try to insert the
1291 // inset there otherwise this is a illegal function now
1292 if (bv_->theLockingInset()) {
1293 if (bv_->theLockingInset()->insetAllowed(inset))
1294 return bv_->theLockingInset()->insertInset(bv_, inset);
1298 // not quite sure if we want this...
1299 setCursorParUndo(bv_);
1302 beforeChange(bv_->text);
1303 if (!lout.empty()) {
1304 update(BufferView::SELECT);
1305 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1306 update(BufferView::SELECT);
1308 if (!bv_->text->cursor.par()->empty()) {
1309 bv_->text->cursorLeft(bv_);
1311 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1312 update(BufferView::SELECT);
1316 LyXTextClass const & tclass =
1317 buffer_->params.getLyXTextClass();
1318 bool hasLayout = tclass.hasLayout(lres);
1319 string lay = tclass.defaultLayoutName();
1321 if (hasLayout != false) {
1325 // layout not fount using default
1326 lay = tclass.defaultLayoutName();
1329 bv_->text->setLayout(lay);
1331 bv_->text->setParagraph(0, 0,
1333 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
1338 update(BufferView::SELECT);
1341 bv_->text->insertInset(inset);
1342 update(BufferView::SELECT);
1349 void BufferView::Pimpl::updateInset(Inset * inset)
1351 if (!inset || !available())
1354 // first check for locking insets
1355 if (bv_->theLockingInset()) {
1356 if (bv_->theLockingInset() == inset) {
1357 if (bv_->text->updateInset(inset)) {
1362 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
1363 if (bv_->text->updateInset(bv_->theLockingInset())) {
1371 // then check if the inset is a top_level inset (has no owner)
1372 // if yes do the update as always otherwise we have to update the
1373 // toplevel inset where this inset is inside
1374 Inset * tl_inset = inset;
1375 while (tl_inset->owner())
1376 tl_inset = tl_inset->owner();
1378 if (tl_inset == inset) {
1379 update(BufferView::UPDATE);
1380 if (bv_->text->updateInset(inset)) {
1381 update(BufferView::SELECT);
1384 } else if (static_cast<UpdatableInset *>(tl_inset)
1385 ->updateInsetInInset(bv_, inset))
1387 if (bv_->text->updateInset(tl_inset)) {