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));
236 void BufferView::Pimpl::redoCurrentBuffer()
238 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
239 if (buffer_ && bv_->text) {
240 resizeCurrentBuffer();
242 owner_->updateLayoutChoice();
248 int BufferView::Pimpl::resizeCurrentBuffer()
250 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
253 Paragraph * selstartpar = 0;
254 Paragraph * selendpar = 0;
255 UpdatableInset * the_locking_inset = 0;
258 pos_type selstartpos = 0;
259 pos_type selendpos = 0;
260 bool selection = false;
261 bool mark_set = false;
265 owner_->message(_("Formatting document..."));
268 par = bv_->text->cursor.par();
269 pos = bv_->text->cursor.pos();
270 selstartpar = bv_->text->selection.start.par();
271 selstartpos = bv_->text->selection.start.pos();
272 selendpar = bv_->text->selection.end.par();
273 selendpos = bv_->text->selection.end.pos();
274 selection = bv_->text->selection.set();
275 mark_set = bv_->text->selection.mark();
276 the_locking_inset = bv_->theLockingInset();
277 buffer_->resizeInsets(bv_);
278 // I don't think the delete and new are necessary here we just could
279 // call only init! (Jug 20020419)
281 bv_->text = new LyXText(bv_);
282 bv_->text->init(bv_);
284 // See if we have a text in TextCache that fits
285 // the new buffer_ with the correct width.
286 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
288 if (lyxerr.debugging()) {
289 lyxerr << "Found a LyXText that fits:\n";
290 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
292 // Set the owner of the newly found text
293 // bv_->text->owner(bv_);
294 if (lyxerr.debugging())
295 textcache.show(lyxerr, "resizeCurrentBuffer");
297 buffer_->resizeInsets(bv_);
299 bv_->text = new LyXText(bv_);
300 bv_->text->init(bv_);
301 //buffer_->resizeInsets(bv_);
306 bv_->text->selection.set(true);
307 // At this point just to avoid the Delete-Empty-Paragraph-
308 // Mechanism when setting the cursor.
309 bv_->text->selection.mark(mark_set);
311 bv_->text->setCursor(selstartpar, selstartpos);
312 bv_->text->selection.cursor = bv_->text->cursor;
313 bv_->text->setCursor(selendpar, selendpos);
314 bv_->text->setSelection();
315 bv_->text->setCursor(par, pos);
317 bv_->text->setCursor(par, pos);
318 bv_->text->selection.cursor = bv_->text->cursor;
319 bv_->text->selection.set(false);
321 // remake the inset locking
322 bv_->theLockingInset(the_locking_inset);
325 bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
336 void BufferView::Pimpl::repaint()
338 // Regenerate the screen.
339 screen().redraw(bv_->text, bv_);
343 void BufferView::Pimpl::updateScrollbar()
346 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
347 workarea().setScrollbarParams(0, 0, 0);
351 LyXText const & t = *bv_->text;
353 lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
354 << t.top_y() << ", default height " << defaultRowHeight() << endl;
356 workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
360 void BufferView::Pimpl::scrollDocView(int value)
362 lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
367 screen().draw(bv_->text, bv_, value);
369 if (!lyxrc.cursor_follows_scrollbar)
372 LyXText * vbt = bv_->text;
374 int const height = defaultRowHeight();
375 int const first = static_cast<int>((bv_->text->top_y() + height));
376 int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
378 if (vbt->cursor.y() < first)
379 vbt->setCursorFromCoordinates(0, first);
380 else if (vbt->cursor.y() > last)
381 vbt->setCursorFromCoordinates(0, last);
383 owner_->updateLayoutChoice();
387 void BufferView::Pimpl::scroll(int lines)
393 LyXText const * t = bv_->text;
394 int const line_height = defaultRowHeight();
396 // The new absolute coordinate
397 int new_top_y = t->top_y() + lines * line_height;
399 // Restrict to a valid value
400 new_top_y = std::min(t->height - 4 * line_height, new_top_y);
401 new_top_y = std::max(0, new_top_y);
403 scrollDocView(new_top_y);
405 // Update the scrollbar.
406 workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
410 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
411 key_modifier::state state)
413 bv_->owner()->getLyXFunc().processKeySym(key, state);
417 void BufferView::Pimpl::selectionRequested()
424 LyXText * text = bv_->getLyXText();
426 if (text->selection.set() &&
427 (!bv_->text->xsel_cache.set() ||
428 text->selection.start != bv_->text->xsel_cache.start ||
429 text->selection.end != bv_->text->xsel_cache.end))
431 bv_->text->xsel_cache = text->selection;
432 sel = text->selectionAsString(bv_->buffer(), false);
433 } else if (!text->selection.set()) {
435 bv_->text->xsel_cache.set(false);
438 workarea().putClipboard(sel);
443 void BufferView::Pimpl::selectionLost()
448 bv_->getLyXText()->clearSelection();
450 bv_->text->xsel_cache.set(false);
455 void BufferView::Pimpl::workAreaResize()
457 static int work_area_width;
458 static int work_area_height;
460 bool const widthChange = workarea().workWidth() != work_area_width;
461 bool const heightChange = workarea().workHeight() != work_area_height;
463 // update from work area
464 work_area_width = workarea().workWidth();
465 work_area_height = workarea().workHeight();
469 // The visible LyXView need a resize
470 resizeCurrentBuffer();
472 // Remove all texts from the textcache
473 // This is not _really_ what we want to do. What
474 // we really want to do is to delete in textcache
475 // that does not have a BufferView with matching
476 // width, but as long as we have only one BufferView
477 // deleting all gives the same result.
478 if (lyxerr.debugging())
479 textcache.show(lyxerr, "Expose delete all");
481 // FIXME: this is already done in resizeCurrentBuffer() ??
482 buffer_->resizeInsets(bv_);
483 } else if (heightChange) {
484 // fitCursor() ensures we don't jump back
485 // to the start of the document on vertical
491 if (widthChange || heightChange) {
495 // always make sure that the scrollbar is sane.
497 owner_->updateLayoutChoice();
502 void BufferView::Pimpl::update()
504 if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
505 screen().update(*bv_);
506 bv_->text->clearPaint();
511 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
513 if (!text->selection.set() && (f & SELECT)) {
514 text->selection.cursor = text->cursor;
519 if (text->inset_owner) {
520 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
521 updateInset(text->inset_owner);
528 void BufferView::Pimpl::update(BufferView::UpdateCodes f)
530 LyXText * text = bv_->text;
532 if (!text->selection.set() && (f & SELECT)) {
533 text->selection.cursor = text->cursor;
538 if (text->inset_owner) {
539 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
540 updateInset(text->inset_owner);
547 // Callback for cursor timer
548 void BufferView::Pimpl::cursorToggle()
551 cursor_timeout.restart();
555 if (!bv_->theLockingInset()) {
556 screen().cursorToggle(bv_);
558 bv_->theLockingInset()->toggleInsetCursor(bv_);
561 cursor_timeout.restart();
565 bool BufferView::Pimpl::available() const
567 if (buffer_ && bv_->text)
573 Change const BufferView::Pimpl::getCurrentChange()
575 if (!bv_->buffer()->params.tracking_changes)
576 return Change(Change::UNCHANGED);
578 LyXText * t(bv_->getLyXText());
580 if (!t->selection.set())
581 return Change(Change::UNCHANGED);
583 LyXCursor const & cur(t->selection.start);
584 return cur.par()->lookupChangeFull(cur.pos());
588 void BufferView::Pimpl::beforeChange(LyXText * text)
591 text->clearSelection();
595 void BufferView::Pimpl::savePosition(unsigned int i)
597 if (i >= saved_positions_num)
599 saved_positions[i] = Position(buffer_->fileName(),
600 bv_->text->cursor.par()->id(),
601 bv_->text->cursor.pos());
605 str << boost::format(_("Saved bookmark %1$d")) % i;
607 str << _("Saved bookmark ") << i;
609 owner_->message(STRCONV(str.str()));
614 void BufferView::Pimpl::restorePosition(unsigned int i)
616 if (i >= saved_positions_num)
619 string const fname = saved_positions[i].filename;
621 beforeChange(bv_->text);
623 if (fname != buffer_->fileName()) {
624 Buffer * b = bufferlist.exists(fname) ?
625 bufferlist.getBuffer(fname) :
626 bufferlist.loadLyXFile(fname); // don't ask, just load it
627 if (b != 0) buffer(b);
630 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
634 bv_->text->setCursor(par,
635 min(par->size(), saved_positions[i].par_pos));
637 update(BufferView::SELECT);
641 str << boost::format(_("Moved to bookmark %1$d")) % i;
643 str << _("Moved to bookmark ") << i;
645 owner_->message(STRCONV(str.str()));
650 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
652 if (i >= saved_positions_num)
655 return !saved_positions[i].filename.empty();
659 void BufferView::Pimpl::switchKeyMap()
661 if (!lyxrc.rtl_support)
664 LyXText * text = bv_->getLyXText();
665 if (text->real_current_font.isRightToLeft()
666 && !(bv_->theLockingInset()
667 && bv_->theLockingInset()->lyxCode() == Inset::ERT_CODE))
669 if (owner_->getIntl().keymap == Intl::PRIMARY)
670 owner_->getIntl().KeyMapSec();
672 if (owner_->getIntl().keymap == Intl::SECONDARY)
673 owner_->getIntl().KeyMapPrim();
678 void BufferView::Pimpl::insetUnlock()
680 if (bv_->theLockingInset()) {
681 bv_->theLockingInset()->insetUnlock(bv_);
682 bv_->theLockingInset(0);
688 void BufferView::Pimpl::showCursor()
690 if (bv_->theLockingInset())
691 bv_->theLockingInset()->showInsetCursor(bv_);
693 screen().showCursor(bv_->text, bv_);
697 void BufferView::Pimpl::hideCursor()
699 if (!bv_->theLockingInset())
700 screen().hideCursor();
704 void BufferView::Pimpl::toggleSelection(bool b)
706 if (bv_->theLockingInset())
707 bv_->theLockingInset()->toggleSelection(bv_, b);
708 screen().toggleSelection(bv_->text, bv_, b);
712 void BufferView::Pimpl::toggleToggle()
714 screen().toggleToggle(bv_->text, bv_);
718 void BufferView::Pimpl::center()
720 LyXText * t = bv_->text;
723 int const half_height = workarea().workHeight() / 2;
726 if (t->cursor.y() > half_height) {
727 new_y = t->cursor.y() - half_height;
730 // FIXME: look at this comment again ...
732 // FIXME: can we do this w/o calling screen directly ?
733 // This updates top_y() but means the fitCursor() call
734 // from the update(FITCUR) doesn't realise that we might
735 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
736 // the scrollbar to be updated as it should, so we have
737 // to do it manually. Any operation that does a center()
738 // and also might have moved top_y() must make sure to call
739 // updateScrollbar() currently. Never mind that this is a
740 // pretty obfuscated way of updating t->top_y()
741 screen().draw(t, bv_, new_y);
743 update(BufferView::SELECT);
747 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
749 workarea().putClipboard(stuff);
754 * Dispatch functions for actions which can be valid for BufferView->text
755 * and/or InsetText->text!!!
759 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
762 LyXCursor cursor = bv_->getLyXText()->cursor;
763 Buffer::inset_iterator it =
764 find_if(Buffer::inset_iterator(
765 cursor.par(), cursor.pos()),
766 buffer_->inset_iterator_end(),
767 lyx::compare_memfun(&Inset::lyxCode, code));
768 return it != buffer_->inset_iterator_end() ? (*it) : 0;
770 // Ok, this is a little bit too brute force but it
771 // should work for now. Better infrastructure is comming. (Lgb)
773 Buffer * b = bv_->buffer();
774 LyXCursor cursor = bv_->getLyXText()->cursor;
776 Buffer::inset_iterator beg = b->inset_iterator_begin();
777 Buffer::inset_iterator end = b->inset_iterator_end();
779 bool cursor_par_seen = false;
781 for (; beg != end; ++beg) {
782 if (beg.getPar() == cursor.par()) {
783 cursor_par_seen = true;
785 if (cursor_par_seen) {
786 if (beg.getPar() == cursor.par()
787 && beg.getPos() >= cursor.pos()) {
789 } else if (beg.getPar() != cursor.par()) {
796 // Now find the first inset that matches code.
797 for (; beg != end; ++beg) {
798 if (beg->lyxCode() == code) {
808 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
810 string filename = filen;
812 if (filename.empty()) {
813 // Launch a file browser
814 string initpath = lyxrc.document_path;
817 string const trypath = owner_->buffer()->filePath();
818 // If directory is writeable, use this as default.
819 if (IsDirWriteable(trypath))
823 FileDialog fileDlg(_("Select LyX document to insert"),
825 make_pair(string(_("Documents|#o#O")),
826 string(lyxrc.document_path)),
827 make_pair(string(_("Examples|#E#e")),
828 string(AddPath(system_lyxdir, "examples"))));
830 FileDialog::Result result =
831 fileDlg.open(initpath,
832 _("*.lyx| LyX Documents (*.lyx)"));
834 if (result.first == FileDialog::Later)
837 filename = result.second;
839 // check selected filename
840 if (filename.empty()) {
841 owner_->message(_("Canceled."));
846 // get absolute path of file and add ".lyx" to the filename if
848 filename = FileSearch(string(), filename, "lyx");
850 string const disp_fn(MakeDisplayPath(filename));
854 s1 << boost::format(_("Inserting document %1$s...")) % disp_fn;
856 s1 << _("Inserting document ") << disp_fn << _("...");
858 owner_->message(STRCONV(s1.str()));
859 bool const res = bv_->insertLyXFile(filename);
863 str << boost::format(_("Document %1$s inserted.")) % disp_fn;
865 str << _("Document ") << disp_fn << _(" inserted.");
867 owner_->message(STRCONV(str.str()));
871 str << boost::format(_("Could not insert document %1$s")) % disp_fn;
873 str << _("Could not insert document ") << disp_fn;
875 owner_->message(STRCONV(str.str()));
880 void BufferView::Pimpl::trackChanges()
882 Buffer * buf(bv_->buffer());
883 bool const tracking(buf->params.tracking_changes);
886 ParIterator const end = buf->par_iterator_end();
887 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
888 (*it)->trackChanges();
890 buf->params.tracking_changes = true;
892 // we cannot allow undos beyond the freeze point
893 buf->undostack.clear();
895 update(BufferView::SELECT);
896 bv_->text->setCursor(&(*buf->paragraphs.begin()), 0);
897 #warning changes FIXME
898 //moveCursorUpdate(false);
900 bool found = lyxfind::findNextChange(bv_);
902 owner_->getDialogs().show("changes");
906 ParIterator const end = buf->par_iterator_end();
907 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
908 (*it)->untrackChanges();
910 buf->params.tracking_changes = false;
913 buf->redostack.clear();
917 // Doesn't go through lyxfunc, so we need to update the
918 // layout choice etc. ourselves
919 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in)
921 // e.g. Qt mouse press when no buffer
925 bool const res = dispatch(ev_in);
927 bv_->owner()->updateLayoutChoice();
934 bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
936 // Make sure that the cached BufferView is correct.
937 FuncRequest ev = ev_in;
940 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
941 << " action[" << ev.action << ']'
942 << " arg[" << ev.argument << ']'
943 << " x[" << ev.x << ']'
944 << " y[" << ev.y << ']'
945 << " button[" << ev.button() << ']'
948 LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
952 case LFUN_SCROLL_INSET:
953 // this is not handled here as this function is only active
954 // if we have a locking_inset and that one is (or contains)
958 case LFUN_LAYOUT_COPY:
959 bv_->copyEnvironment();
962 case LFUN_LAYOUT_PASTE:
963 bv_->pasteEnvironment();
967 case LFUN_FILE_INSERT:
968 MenuInsertLyXFile(ev.argument);
971 case LFUN_FILE_INSERT_ASCII_PARA:
972 InsertAsciiFile(bv_, ev.argument, true);
975 case LFUN_FILE_INSERT_ASCII:
976 InsertAsciiFile(bv_, ev.argument, false);
980 lang(bv_, ev.argument);
982 owner_->view_state_changed();
987 owner_->view_state_changed();
992 owner_->view_state_changed();
997 owner_->view_state_changed();
1002 owner_->view_state_changed();
1007 owner_->view_state_changed();
1012 owner_->view_state_changed();
1017 owner_->view_state_changed();
1020 case LFUN_UNDERLINE:
1022 owner_->view_state_changed();
1025 case LFUN_FONT_SIZE:
1026 fontSize(bv_, ev.argument);
1027 owner_->view_state_changed();
1030 case LFUN_FONT_STATE:
1031 owner_->getLyXFunc().setMessage(currentState(bv_));
1034 case LFUN_INSERT_LABEL: {
1035 // Try and generate a valid label
1036 string const contents = ev.argument.empty() ?
1037 getPossibleLabel(*bv_) : ev.argument;
1038 InsetCommandParams icp("label", contents);
1039 string data = InsetCommandMailer::params2string("label", icp);
1040 owner_->getDialogs().show("label", data, 0);
1044 case LFUN_BOOKMARK_SAVE:
1045 savePosition(strToUnsignedInt(ev.argument));
1048 case LFUN_BOOKMARK_GOTO:
1049 restorePosition(strToUnsignedInt(ev.argument));
1054 string label = ev.argument;
1055 if (label.empty()) {
1057 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1059 label = inset->getContents();
1064 if (!label.empty()) {
1065 //bv_->savePosition(0);
1066 if (!bv_->gotoLabel(label))
1067 Alert::alert(_("Error"),
1068 _("Couldn't find this label"),
1069 _("in current document."));
1074 // --- accented characters ---------------------------
1077 case LFUN_CIRCUMFLEX:
1087 case LFUN_SPECIAL_CARON:
1090 case LFUN_HUNG_UMLAUT:
1093 if (ev.argument.empty()) {
1095 owner_->getLyXFunc().handleKeyFunc(ev.action);
1097 owner_->getLyXFunc().handleKeyFunc(ev.action);
1098 owner_->getIntl().getTransManager()
1099 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
1100 update(bv_->getLyXText(), BufferView::SELECT);
1104 case LFUN_MATH_MACRO:
1105 case LFUN_MATH_DELIM:
1106 case LFUN_INSERT_MATRIX:
1107 case LFUN_INSERT_MATH:
1108 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
1109 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
1110 case LFUN_MATH_MODE: // Open or create an inlined math inset
1114 case LFUN_INSET_APPLY: {
1115 string const name = ev.getArg(0);
1117 InsetBase * inset = owner_->getDialogs().getOpenInset(name);
1119 // This works both for 'original' and 'mathed' insets.
1120 // Note that the localDispatch performs updateInset
1122 FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
1123 inset->localDispatch(fr);
1125 FuncRequest fr(bv_, LFUN_INSET_INSERT, ev.argument);
1131 case LFUN_INSET_INSERT: {
1132 Inset * inset = createInset(ev);
1133 if (inset && insertInset(inset)) {
1136 string const name = ev.getArg(0);
1137 if (name == "bibitem") {
1138 // We need to do a redraw because the maximum
1139 // InsetBibitem width could have changed
1140 #warning please check you mean repaint() not update(),
1141 #warning and whether the repaint() is needed at all
1151 case LFUN_FLOAT_LIST:
1152 if (tclass.floats().typeExist(ev.argument)) {
1153 Inset * inset = new InsetFloatList(ev.argument);
1154 if (!insertInset(inset, tclass.defaultLayoutName()))
1157 lyxerr << "Non-existent float type: "
1158 << ev.argument << endl;
1162 case LFUN_LAYOUT_PARAGRAPH: {
1163 Paragraph const * par = bv_->getLyXText()->cursor.par();
1168 params2string(*par, data);
1170 data = "show\n" + data;
1171 bv_->owner()->getDialogs().show("paragraph", data);
1175 case LFUN_PARAGRAPH_UPDATE: {
1176 Paragraph const * par = bv_->getLyXText()->cursor.par();
1181 params2string(*par, data);
1183 // Will the paragraph accept changes from the dialog?
1184 Inset * const inset = par->inInset();
1186 !(inset && inset->forceDefaultParagraphs(inset));
1188 data = "update " + tostr(accept) + '\n' + data;
1189 bv_->owner()->getDialogs().update("paragraph", data);
1193 case LFUN_PARAGRAPH_APPLY:
1194 setParagraphParams(*bv_, ev.argument);
1197 case LFUN_THESAURUS_ENTRY:
1199 string arg = ev.argument;
1202 arg = bv_->getLyXText()->selectionAsString(buffer_,
1206 if (arg.size() > 100 || arg.empty()) {
1207 // Get word or selection
1208 bv_->getLyXText()->selectWordWhenUnderCursor(LyXText::WHOLE_WORD);
1209 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
1210 // FIXME: where is getLyXText()->unselect(bv_) ?
1214 bv_->owner()->getDialogs().show("thesaurus", arg);
1218 case LFUN_TRACK_CHANGES:
1222 case LFUN_MERGE_CHANGES:
1223 owner_->getDialogs().show("changes");
1226 case LFUN_ACCEPT_ALL_CHANGES: {
1227 update(BufferView::SELECT);
1228 bv_->text->setCursor(&(*bv_->buffer()->paragraphs.begin()), 0);
1229 #warning FIXME changes
1230 //moveCursorUpdate(false);
1232 while (lyxfind::findNextChange(bv_)) {
1233 bv_->getLyXText()->acceptChange();
1235 update(BufferView::SELECT);
1239 case LFUN_REJECT_ALL_CHANGES: {
1240 update(BufferView::SELECT);
1241 bv_->text->setCursor(&(*bv_->buffer()->paragraphs.begin()), 0);
1242 #warning FIXME changes
1243 //moveCursorUpdate(false);
1245 while (lyxfind::findNextChange(bv_)) {
1246 bv_->getLyXText()->rejectChange();
1248 update(BufferView::SELECT);
1252 case LFUN_ACCEPT_CHANGE: {
1253 bv_->getLyXText()->acceptChange();
1254 update(BufferView::SELECT);
1258 case LFUN_REJECT_CHANGE: {
1259 bv_->getLyXText()->rejectChange();
1260 update(BufferView::SELECT);
1264 case LFUN_UNKNOWN_ACTION:
1265 ev.errorMessage(N_("Unknown function!"));
1269 return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
1276 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
1278 // if we are in a locking inset we should try to insert the
1279 // inset there otherwise this is a illegal function now
1280 if (bv_->theLockingInset()) {
1281 if (bv_->theLockingInset()->insetAllowed(inset))
1282 return bv_->theLockingInset()->insertInset(bv_, inset);
1286 // not quite sure if we want this...
1287 setCursorParUndo(bv_);
1290 beforeChange(bv_->text);
1291 if (!lout.empty()) {
1292 update(BufferView::SELECT);
1293 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1294 update(BufferView::SELECT);
1296 if (!bv_->text->cursor.par()->empty()) {
1297 bv_->text->cursorLeft(bv_);
1299 bv_->text->breakParagraph(bv_->buffer()->paragraphs);
1300 update(BufferView::SELECT);
1304 LyXTextClass const & tclass =
1305 buffer_->params.getLyXTextClass();
1306 bool hasLayout = tclass.hasLayout(lres);
1307 string lay = tclass.defaultLayoutName();
1309 if (hasLayout != false) {
1313 // layout not fount using default
1314 lay = tclass.defaultLayoutName();
1317 bv_->text->setLayout(lay);
1319 bv_->text->setParagraph(0, 0,
1321 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
1326 update(BufferView::SELECT);
1329 bv_->text->insertInset(inset);
1330 update(BufferView::SELECT);
1337 void BufferView::Pimpl::updateInset(Inset * inset)
1339 if (!inset || !available())
1342 // first check for locking insets
1343 if (bv_->theLockingInset()) {
1344 if (bv_->theLockingInset() == inset) {
1345 if (bv_->text->updateInset(inset)) {
1350 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
1351 if (bv_->text->updateInset(bv_->theLockingInset())) {
1359 // then check if the inset is a top_level inset (has no owner)
1360 // if yes do the update as always otherwise we have to update the
1361 // toplevel inset where this inset is inside
1362 Inset * tl_inset = inset;
1363 while (tl_inset->owner())
1364 tl_inset = tl_inset->owner();
1366 if (tl_inset == inset) {
1367 update(BufferView::UPDATE);
1368 if (bv_->text->updateInset(inset)) {
1369 update(BufferView::SELECT);
1372 } else if (static_cast<UpdatableInset *>(tl_inset)
1373 ->updateInsetInInset(bv_, inset))
1375 if (bv_->text->updateInset(tl_inset)) {