]> git.lyx.org Git - lyx.git/blob - src/BufferView_pimpl.C
The big change tracking patch. Changes from posted version :
[lyx.git] / src / BufferView_pimpl.C
1 /**
2  * \file BufferView_pimpl.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author various
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "BufferView_pimpl.h"
16 #include "frontends/WorkArea.h"
17 #include "frontends/screen.h"
18 #include "frontends/LyXScreenFactory.h"
19 #include "frontends/WorkAreaFactory.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/Alert.h"
22 #include "frontends/FileDialog.h"
23 #include "frontends/mouse_state.h"
24 #include "lyxtext.h"
25 #include "lyxrow.h"
26 #include "paragraph.h"
27 #include "frontends/LyXView.h"
28 #include "commandtags.h"
29 #include "lyxfunc.h"
30 #include "debug.h"
31 #include "bufferview_funcs.h"
32 #include "TextCache.h"
33 #include "bufferlist.h"
34 #include "lyxrc.h"
35 #include "intl.h"
36 // added for Dispatch functions
37 #include "lyx_cb.h"
38 #include "lyx_main.h"
39 #include "FloatList.h"
40 #include "gettext.h"
41 #include "ParagraphParameters.h"
42 #include "undo_funcs.h"
43 #include "funcrequest.h"
44 #include "iterators.h"
45 #include "lyxfind.h"
46
47 #include "insets/insetbib.h"
48 #include "insets/insettext.h"
49 #include "insets/insetlatexaccent.h"
50 #include "insets/insettoc.h"
51 #include "insets/insetindex.h"
52 #include "insets/insetref.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetgraphics.h"
56 #include "insets/insetmarginal.h"
57 #include "insets/insetfloatlist.h"
58
59 #include "mathed/formulabase.h"
60
61 #include "graphics/Previews.h"
62
63 #include "support/LAssert.h"
64 #include "support/lstrings.h"
65 #include "support/filetools.h"
66
67 #include <boost/bind.hpp>
68 #include <boost/signals/connection.hpp>
69 #include "BoostFormat.h"
70
71 #include <unistd.h>
72 #include <sys/wait.h>
73
74
75 using std::vector;
76 using std::find_if;
77 using std::find;
78 using std::pair;
79 using std::endl;
80 using std::make_pair;
81 using std::min;
82
83 using lyx::pos_type;
84
85 extern BufferList bufferlist;
86
87
88 namespace {
89
90 unsigned int const saved_positions_num = 20;
91
92 // All the below connection objects are needed because of a bug in some
93 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
94 // to these connections we avoid a segfault upon startup, and also at exit.
95 // (Lgb)
96
97 boost::signals::connection dispatchcon;
98 boost::signals::connection timecon;
99 boost::signals::connection doccon;
100 boost::signals::connection resizecon;
101 boost::signals::connection kpresscon;
102 boost::signals::connection selectioncon;
103 boost::signals::connection lostcon;
104
105
106 } // anon namespace
107
108
109 BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
110              int xpos, int ypos, int width, int height)
111         : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
112           using_xterm_cursor(false)
113 {
114         workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
115         screen_.reset(LyXScreenFactory::create(workarea()));
116
117         // Setup the signals
118         doccon = workarea().scrollDocView
119                 .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
120         resizecon = workarea().workAreaResize
121                 .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
122         dispatchcon = workarea().dispatch
123                 .connect(boost::bind(&BufferView::Pimpl::dispatch, this, _1));
124         kpresscon = workarea().workAreaKeyPress
125                 .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
126         selectioncon = workarea().selectionRequested
127                 .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
128         lostcon = workarea().selectionLost
129                 .connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
130
131         timecon = cursor_timeout.timeout
132                 .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
133         cursor_timeout.start();
134         saved_positions.resize(saved_positions_num);
135 }
136
137
138 WorkArea & BufferView::Pimpl::workarea() const
139 {
140         return *workarea_.get();
141 }
142
143
144 LyXScreen & BufferView::Pimpl::screen() const
145 {
146         return *screen_.get();
147 }
148
149
150 Painter & BufferView::Pimpl::painter() const
151 {
152         return workarea().getPainter();
153 }
154
155
156 void BufferView::Pimpl::buffer(Buffer * b)
157 {
158         lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
159                             << b << ')' << endl;
160         if (buffer_) {
161                 buffer_->delUser(bv_);
162
163                 // Put the old text into the TextCache, but
164                 // only if the buffer is still loaded.
165                 // Also set the owner of the test to 0
166                 //              bv_->text->owner(0);
167                 textcache.add(buffer_, workarea().workWidth(), bv_->text);
168                 if (lyxerr.debugging())
169                         textcache.show(lyxerr, "BufferView::buffer");
170
171                 bv_->text = 0;
172         }
173
174         // set current buffer
175         buffer_ = b;
176
177         if (bufferlist.getState() == BufferList::CLOSING) return;
178
179         // if we are closing the buffer, use the first buffer as current
180         if (!buffer_) {
181                 buffer_ = bufferlist.first();
182         }
183
184         if (buffer_) {
185                 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
186                 buffer_->addUser(bv_);
187
188                 // If we don't have a text object for this, we make one
189                 if (bv_->text == 0) {
190                         resizeCurrentBuffer();
191                 }
192
193                 // FIXME: needed when ?
194                 bv_->text->first_y =
195                         screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
196
197                 // Similarly, buffer-dependent dialogs should be updated or
198                 // hidden. This should go here because some dialogs (eg ToC)
199                 // require bv_->text.
200                 owner_->getDialogs().updateBufferDependent(true);
201         } else {
202                 lyxerr[Debug::INFO] << "  No Buffer!" << endl;
203                 owner_->getDialogs().hideBufferDependent();
204
205                 // Also remove all remaining text's from the testcache.
206                 // (there should not be any!) (if there is any it is a
207                 // bug!)
208                 if (lyxerr.debugging())
209                         textcache.show(lyxerr, "buffer delete all");
210                 textcache.clear();
211         }
212
213         repaint();
214         updateScrollbar();
215         owner_->updateMenubar();
216         owner_->updateToolbar();
217         owner_->updateLayoutChoice();
218         owner_->updateWindowTitle();
219
220         if (grfx::Previews::activated() && buffer_)
221                 grfx::Previews::get().generateBufferPreviews(*buffer_);
222 }
223
224
225 bool BufferView::Pimpl::fitCursor()
226 {
227         bool ret;
228
229         if (bv_->theLockingInset()) {
230                 bv_->theLockingInset()->fitInsetCursor(bv_);
231                 ret = true;
232         } else {
233                 ret = screen().fitCursor(bv_->text, bv_);
234         }
235
236         bv_->owner()->getDialogs().updateParagraph();
237         if (ret)
238                 updateScrollbar();
239         return ret;
240 }
241
242
243 void BufferView::Pimpl::redoCurrentBuffer()
244 {
245         lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
246         if (buffer_ && bv_->text) {
247                 resizeCurrentBuffer();
248                 updateScrollbar();
249                 owner_->updateLayoutChoice();
250                 repaint();
251         }
252 }
253
254
255 int BufferView::Pimpl::resizeCurrentBuffer()
256 {
257         lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
258
259         Paragraph * par = 0;
260         Paragraph * selstartpar = 0;
261         Paragraph * selendpar = 0;
262         UpdatableInset * the_locking_inset = 0;
263
264         pos_type pos = 0;
265         pos_type selstartpos = 0;
266         pos_type selendpos = 0;
267         bool selection = false;
268         bool mark_set  = false;
269
270         owner_->prohibitInput();
271
272         owner_->message(_("Formatting document..."));
273
274         if (bv_->text) {
275                 par = bv_->text->cursor.par();
276                 pos = bv_->text->cursor.pos();
277                 selstartpar = bv_->text->selection.start.par();
278                 selstartpos = bv_->text->selection.start.pos();
279                 selendpar = bv_->text->selection.end.par();
280                 selendpos = bv_->text->selection.end.pos();
281                 selection = bv_->text->selection.set();
282                 mark_set = bv_->text->selection.mark();
283                 the_locking_inset = bv_->theLockingInset();
284                 buffer_->resizeInsets(bv_);
285                 // I don't think the delete and new are necessary here we just could
286                 // call only init! (Jug 20020419)
287                 delete bv_->text;
288                 bv_->text = new LyXText(bv_);
289                 bv_->text->init(bv_);
290         } else {
291                 // See if we have a text in TextCache that fits
292                 // the new buffer_ with the correct width.
293                 bv_->text = textcache.findFit(buffer_, workarea().workWidth());
294                 if (bv_->text) {
295                         if (lyxerr.debugging()) {
296                                 lyxerr << "Found a LyXText that fits:\n";
297                                 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
298                         }
299                         // Set the owner of the newly found text
300                         //      bv_->text->owner(bv_);
301                         if (lyxerr.debugging())
302                                 textcache.show(lyxerr, "resizeCurrentBuffer");
303
304                         buffer_->resizeInsets(bv_);
305                 } else {
306                         bv_->text = new LyXText(bv_);
307                         bv_->text->init(bv_);
308                         //buffer_->resizeInsets(bv_);
309                 }
310         }
311
312         if (par) {
313                 bv_->text->selection.set(true);
314                 // At this point just to avoid the Delete-Empty-Paragraph-
315                 // Mechanism when setting the cursor.
316                 bv_->text->selection.mark(mark_set);
317                 if (selection) {
318                         bv_->text->setCursor(bv_, selstartpar, selstartpos);
319                         bv_->text->selection.cursor = bv_->text->cursor;
320                         bv_->text->setCursor(bv_, selendpar, selendpos);
321                         bv_->text->setSelection(bv_);
322                         bv_->text->setCursor(bv_, par, pos);
323                 } else {
324                         bv_->text->setCursor(bv_, par, pos);
325                         bv_->text->selection.cursor = bv_->text->cursor;
326                         bv_->text->selection.set(false);
327                 }
328                 // remake the inset locking
329                 bv_->theLockingInset(the_locking_inset);
330         }
331
332         bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
333
334         switchKeyMap();
335         owner_->allowInput();
336
337         updateScrollbar();
338
339         return 0;
340 }
341
342
343 void BufferView::Pimpl::repaint()
344 {
345         // Regenerate the screen.
346         screen().redraw(bv_->text, bv_);
347 }
348
349
350 void BufferView::Pimpl::updateScrollbar()
351 {
352         if (!bv_->text) {
353                 lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
354                 workarea().setScrollbarParams(0, 0, 0);
355                 return;
356         }
357
358         LyXText const & t = *bv_->text;
359
360         lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
361                 << t.first_y << ", default height " << t.defaultHeight() << endl;
362
363         workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight());
364 }
365
366
367 void BufferView::Pimpl::scrollDocView(int value)
368 {
369         lyxerr[Debug::GUI] << "scrollDocView of " << value << endl;
370
371         if (!buffer_)
372                 return;
373
374         screen().draw(bv_->text, bv_, value);
375
376         if (!lyxrc.cursor_follows_scrollbar)
377                 return;
378
379         LyXText * vbt = bv_->text;
380
381         int const height = vbt->defaultHeight();
382         int const first = static_cast<int>((bv_->text->first_y + height));
383         int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
384
385         if (vbt->cursor.y() < first)
386                 vbt->setCursorFromCoordinates(bv_, 0, first);
387         else if (vbt->cursor.y() > last)
388                 vbt->setCursorFromCoordinates(bv_, 0, last);
389 }
390
391
392 void BufferView::Pimpl::scroll(int lines)
393 {
394         if (!buffer_) {
395                 return;
396         }
397
398         LyXText const * t = bv_->text;
399         int const line_height = t->defaultHeight();
400
401         // The new absolute coordinate
402         int new_first_y = t->first_y + lines * line_height;
403
404         // Restrict to a valid value
405         new_first_y = std::min(t->height - 4 * line_height, new_first_y);
406         new_first_y = std::max(0, new_first_y);
407
408         scrollDocView(new_first_y);
409
410         // Update the scrollbar.
411         workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight());
412 }
413
414
415 void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
416                                          key_modifier::state state)
417 {
418         bv_->owner()->getLyXFunc().processKeySym(key, state);
419 }
420
421
422 void BufferView::Pimpl::selectionRequested()
423 {
424         static string sel;
425
426         if (!available())
427                 return;
428
429         LyXText * text = bv_->getLyXText();
430
431         if (text->selection.set() &&
432                 (!bv_->text->xsel_cache.set() ||
433                  text->selection.start != bv_->text->xsel_cache.start ||
434                  text->selection.end != bv_->text->xsel_cache.end))
435         {
436                 bv_->text->xsel_cache = text->selection;
437                 sel = text->selectionAsString(bv_->buffer(), false);
438         } else if (!text->selection.set()) {
439                 sel = string();
440                 bv_->text->xsel_cache.set(false);
441         }
442         if (!sel.empty()) {
443                 workarea().putClipboard(sel);
444         }
445 }
446
447
448 void BufferView::Pimpl::selectionLost()
449 {
450         if (available()) {
451                 hideCursor();
452                 toggleSelection();
453                 bv_->getLyXText()->clearSelection();
454                 showCursor();
455                 bv_->text->xsel_cache.set(false);
456         }
457 }
458
459
460 void BufferView::Pimpl::workAreaResize()
461 {
462         static int work_area_width;
463         static int work_area_height;
464
465         bool const widthChange = workarea().workWidth() != work_area_width;
466         bool const heightChange = workarea().workHeight() != work_area_height;
467
468         // update from work area
469         work_area_width = workarea().workWidth();
470         work_area_height = workarea().workHeight();
471
472         if (buffer_ != 0) {
473                 if (widthChange) {
474                         // The visible LyXView need a resize
475                         resizeCurrentBuffer();
476
477                         // Remove all texts from the textcache
478                         // This is not _really_ what we want to do. What
479                         // we really want to do is to delete in textcache
480                         // that does not have a BufferView with matching
481                         // width, but as long as we have only one BufferView
482                         // deleting all gives the same result.
483                         if (lyxerr.debugging())
484                                 textcache.show(lyxerr, "Expose delete all");
485                         textcache.clear();
486                         // FIXME: this is already done in resizeCurrentBuffer() ??
487                         buffer_->resizeInsets(bv_);
488                 } else if (heightChange) {
489                         // fitCursor() ensures we don't jump back
490                         // to the start of the document on vertical
491                         // resize
492                         fitCursor();
493                 }
494         }
495
496         if (widthChange || heightChange) {
497                 repaint();
498         }
499
500         // always make sure that the scrollbar is sane.
501         updateScrollbar();
502         owner_->updateLayoutChoice();
503         return;
504 }
505
506
507 void BufferView::Pimpl::update()
508 {
509         if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
510                 LyXText::text_status st = bv_->text->status();
511                 screen().update(bv_->text, bv_);
512                 bool fitc = false;
513                 while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) {
514                         bv_->text->fullRebreak(bv_);
515                         st = LyXText::NEED_MORE_REFRESH;
516                         bv_->text->setCursor(bv_, bv_->text->cursor.par(),
517                                              bv_->text->cursor.pos());
518                         if (bv_->text->selection.set()) {
519                                 bv_->text->setCursor(bv_, bv_->text->selection.start,
520                                                      bv_->text->selection.start.par(),
521                                                      bv_->text->selection.start.pos());
522                                 bv_->text->setCursor(bv_, bv_->text->selection.end,
523                                                      bv_->text->selection.end.par(),
524                                                      bv_->text->selection.end.pos());
525                         }
526                         fitc = true;
527                         bv_->text->status(bv_, st);
528                         screen().update(bv_->text, bv_);
529                 }
530                 // do this here instead of in the screen::update because of
531                 // the above loop!
532                 bv_->text->status(bv_, LyXText::UNCHANGED);
533                 if (fitc)
534                         fitCursor();
535         }
536 }
537
538 // Values used when calling update:
539 // -3 - update
540 // -2 - update, move sel_cursor if selection, fitcursor
541 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
542 //  0 - update, move sel_cursor if selection, fitcursor
543 //  1 - update, move sel_cursor if selection, fitcursor, mark dirty
544 //  3 - update, move sel_cursor if selection
545 //
546 // update -
547 // a simple redraw of the parts that need refresh
548 //
549 // move sel_cursor if selection -
550 // the text's sel_cursor is moved if there is selection is progress
551 //
552 // fitcursor -
553 // fitCursor() is called and the scrollbar updated
554 //
555 // mark dirty -
556 // the buffer is marked dirty.
557 //
558 // enum {
559 //       UPDATE = 0,
560 //       SELECT = 1,
561 //       FITCUR = 2,
562 //       CHANGE = 4
563 // };
564 //
565 // UPDATE_ONLY = UPDATE;
566 // UPDATE_SELECT = UPDATE | SELECT;
567 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
568 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
569 //
570 // update(-3) -> update(0)         -> update(0) -> update(UPDATE)
571 // update(-2) -> update(1 + 2)     -> update(3) -> update(SELECT|FITCUR)
572 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
573 // update(1)  -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
574 // update(3)  -> update(1)         -> update(1) -> update(SELECT)
575
576 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
577 {
578         owner_->updateLayoutChoice();
579
580         if (!text->selection.set() && (f & SELECT)) {
581                 text->selection.cursor = text->cursor;
582         }
583
584         text->fullRebreak(bv_);
585
586         if (text->inset_owner) {
587                 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
588                 updateInset(text->inset_owner, false);
589         } else {
590                 update();
591         }
592
593         if ((f & FITCUR)) {
594                 fitCursor();
595         }
596
597         if ((f & CHANGE)) {
598                 buffer_->markDirty();
599         }
600 }
601
602
603 // Callback for cursor timer
604 void BufferView::Pimpl::cursorToggle()
605 {
606         if (!buffer_) {
607                 cursor_timeout.restart();
608                 return;
609         }
610
611         if (!bv_->theLockingInset()) {
612                 screen().cursorToggle(bv_);
613         } else {
614                 bv_->theLockingInset()->toggleInsetCursor(bv_);
615         }
616
617         cursor_timeout.restart();
618 }
619
620
621 bool BufferView::Pimpl::available() const
622 {
623         if (buffer_ && bv_->text)
624                 return true;
625         return false;
626 }
627
628
629 Change const BufferView::Pimpl::getCurrentChange()
630 {
631         if (!bv_->buffer()->params.tracking_changes) 
632                 return Change(Change::UNCHANGED);
633
634         LyXText * t(bv_->getLyXText());
635  
636         if (!t->selection.set())
637                 return Change(Change::UNCHANGED);
638  
639         LyXCursor const & cur(t->selection.start);
640         return cur.par()->lookupChangeFull(cur.pos());
641 }
642
643
644 void BufferView::Pimpl::beforeChange(LyXText * text)
645 {
646         toggleSelection();
647         text->clearSelection();
648 }
649
650
651 void BufferView::Pimpl::savePosition(unsigned int i)
652 {
653         if (i >= saved_positions_num)
654                 return;
655         saved_positions[i] = Position(buffer_->fileName(),
656                                       bv_->text->cursor.par()->id(),
657                                       bv_->text->cursor.pos());
658         if (i > 0) {
659                 ostringstream str;
660 #if USE_BOOST_FORMAT
661                 str << boost::format(_("Saved bookmark %1$d")) % i;
662 #else
663                 str << _("Saved bookmark ") << i;
664 #endif
665                 owner_->message(STRCONV(str.str()));
666         }
667 }
668
669
670 void BufferView::Pimpl::restorePosition(unsigned int i)
671 {
672         if (i >= saved_positions_num)
673                 return;
674
675         string const fname = saved_positions[i].filename;
676
677         beforeChange(bv_->text);
678
679         if (fname != buffer_->fileName()) {
680                 Buffer * b = bufferlist.exists(fname) ?
681                         bufferlist.getBuffer(fname) :
682                         bufferlist.loadLyXFile(fname); // don't ask, just load it
683                 if (b != 0) buffer(b);
684         }
685
686         Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
687         if (!par)
688                 return;
689
690         bv_->text->setCursor(bv_, par,
691                              min(par->size(), saved_positions[i].par_pos));
692
693         update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
694         if (i > 0) {
695                 ostringstream str;
696 #if USE_BOOST_FORMAT
697                 str << boost::format(_("Moved to bookmark %1$d")) % i;
698 #else
699                 str << _("Moved to bookmark ") << i;
700 #endif
701                 owner_->message(STRCONV(str.str()));
702         }
703 }
704
705
706 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
707 {
708         if (i >= saved_positions_num)
709                 return false;
710
711         return !saved_positions[i].filename.empty();
712 }
713
714
715 void BufferView::Pimpl::switchKeyMap()
716 {
717         if (!lyxrc.rtl_support)
718                 return;
719
720         LyXText * text = bv_->getLyXText();
721         if (text->real_current_font.isRightToLeft()
722             && !(bv_->theLockingInset()
723                  && bv_->theLockingInset()->lyxCode() == Inset::ERT_CODE))
724         {
725                 if (owner_->getIntl().keymap == Intl::PRIMARY)
726                         owner_->getIntl().KeyMapSec();
727         } else {
728                 if (owner_->getIntl().keymap == Intl::SECONDARY)
729                         owner_->getIntl().KeyMapPrim();
730         }
731 }
732
733
734 void BufferView::Pimpl::insetUnlock()
735 {
736         if (bv_->theLockingInset()) {
737                 bv_->theLockingInset()->insetUnlock(bv_);
738                 bv_->theLockingInset(0);
739                 finishUndo();
740         }
741 }
742
743
744 void BufferView::Pimpl::showCursor()
745 {
746         if (bv_->theLockingInset())
747                 bv_->theLockingInset()->showInsetCursor(bv_);
748         else
749                 screen().showCursor(bv_->text, bv_);
750 }
751
752
753 void BufferView::Pimpl::hideCursor()
754 {
755         if (!bv_->theLockingInset())
756                 screen().hideCursor();
757 }
758
759
760 void BufferView::Pimpl::toggleSelection(bool b)
761 {
762         if (bv_->theLockingInset())
763                 bv_->theLockingInset()->toggleSelection(bv_, b);
764         screen().toggleSelection(bv_->text, bv_, b);
765 }
766
767
768 void BufferView::Pimpl::toggleToggle()
769 {
770         screen().toggleToggle(bv_->text, bv_);
771 }
772
773
774 void BufferView::Pimpl::center()
775 {
776         LyXText * t = bv_->text;
777
778         beforeChange(t);
779         int const half_height = workarea().workHeight() / 2;
780         int new_y = 0;
781
782         if (t->cursor.y() > half_height) {
783                 new_y = t->cursor.y() - half_height;
784         }
785
786         // FIXME: can we do this w/o calling screen directly ?
787         // This updates first_y but means the fitCursor() call
788         // from the update(FITCUR) doesn't realise that we might
789         // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
790         // the scrollbar to be updated as it should, so we have
791         // to do it manually. Any operation that does a center()
792         // and also might have moved first_y must make sure to call
793         // updateScrollbar() currently. Never mind that this is a
794         // pretty obfuscated way of updating t->first_y
795         screen().draw(t, bv_, new_y);
796
797         update(t, BufferView::SELECT | BufferView::FITCUR);
798 }
799
800
801 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
802 {
803         workarea().putClipboard(stuff);
804 }
805
806
807 /*
808  * Dispatch functions for actions which can be valid for BufferView->text
809  * and/or InsetText->text!!!
810  */
811
812
813 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
814 {
815 #if 0
816         LyXCursor cursor = bv_->getLyXText()->cursor;
817         Buffer::inset_iterator it =
818                 find_if(Buffer::inset_iterator(
819                         cursor.par(), cursor.pos()),
820                         buffer_->inset_iterator_end(),
821                         lyx::compare_memfun(&Inset::lyxCode, code));
822         return it != buffer_->inset_iterator_end() ? (*it) : 0;
823 #else
824         // Ok, this is a little bit too brute force but it
825         // should work for now. Better infrastructure is comming. (Lgb)
826
827         Buffer * b = bv_->buffer();
828         LyXCursor cursor = bv_->getLyXText()->cursor;
829
830         Buffer::inset_iterator beg = b->inset_iterator_begin();
831         Buffer::inset_iterator end = b->inset_iterator_end();
832
833         bool cursor_par_seen = false;
834
835         for (; beg != end; ++beg) {
836                 if (beg.getPar() == cursor.par()) {
837                         cursor_par_seen = true;
838                 }
839                 if (cursor_par_seen) {
840                         if (beg.getPar() == cursor.par()
841                             && beg.getPos() >= cursor.pos()) {
842                                 break;
843                         } else if (beg.getPar() != cursor.par()) {
844                                 break;
845                         }
846                 }
847
848         }
849         if (beg != end) {
850                 // Now find the first inset that matches code.
851                 for (; beg != end; ++beg) {
852                         if (beg->lyxCode() == code) {
853                                 return &(*beg);
854                         }
855                 }
856         }
857         return 0;
858 #endif
859 }
860
861
862 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
863 {
864         string filename = filen;
865
866         if (filename.empty()) {
867                 // Launch a file browser
868                 string initpath = lyxrc.document_path;
869
870                 if (available()) {
871                         string const trypath = owner_->buffer()->filePath();
872                         // If directory is writeable, use this as default.
873                         if (IsDirWriteable(trypath))
874                                 initpath = trypath;
875                 }
876
877                 FileDialog fileDlg(bv_->owner(),
878                                    _("Select LyX document to insert"),
879                         LFUN_FILE_INSERT,
880                         make_pair(string(_("Documents|#o#O")),
881                                   string(lyxrc.document_path)),
882                         make_pair(string(_("Examples|#E#e")),
883                                   string(AddPath(system_lyxdir, "examples"))));
884
885                 FileDialog::Result result =
886                         fileDlg.open(initpath,
887                                        _("*.lyx| LyX Documents (*.lyx)"));
888
889                 if (result.first == FileDialog::Later)
890                         return;
891
892                 filename = result.second;
893
894                 // check selected filename
895                 if (filename.empty()) {
896                         owner_->message(_("Canceled."));
897                         return;
898                 }
899         }
900
901         // get absolute path of file and add ".lyx" to the filename if
902         // necessary
903         filename = FileSearch(string(), filename, "lyx");
904
905         string const disp_fn(MakeDisplayPath(filename));
906
907         ostringstream s1;
908 #if USE_BOOST_FORMAT
909         s1 << boost::format(_("Inserting document %1$s...")) % disp_fn;
910 #else
911         s1 << _("Inserting document ") << disp_fn << _("...");
912 #endif
913         owner_->message(STRCONV(s1.str()));
914         bool const res = bv_->insertLyXFile(filename);
915         if (res) {
916                 ostringstream str;
917 #if USE_BOOST_FORMAT
918                 str << boost::format(_("Document %1$s inserted.")) % disp_fn;
919 #else
920                 str << _("Document ") << disp_fn << _(" inserted.");
921 #endif
922                 owner_->message(STRCONV(str.str()));
923         } else {
924                 ostringstream str;
925 #if USE_BOOST_FORMAT
926                 str << boost::format(_("Could not insert document %1$s")) % disp_fn;
927 #else
928                 str << _("Could not insert document ") << disp_fn;
929 #endif
930                 owner_->message(STRCONV(str.str()));
931         }
932 }
933
934
935 void BufferView::Pimpl::trackChanges()
936 {
937         Buffer * buf(bv_->buffer());
938         bool const tracking(buf->params.tracking_changes);
939
940         if (!tracking) {
941                 ParIterator const end = buf->par_iterator_end();
942                 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
943                         (*it)->trackChanges();
944                 }
945                 buf->params.tracking_changes = true;
946
947                 // we cannot allow undos beyond the freeze point
948                 buf->undostack.clear();
949         } else {
950                 bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
951                 bv_->text->setCursor(bv_, &(*buf->paragraphs.begin()), 0);
952 #warning changes FIXME 
953                 //moveCursorUpdate(false);
954
955                 bool found = lyxfind::findNextChange(bv_);
956                 if (found) {
957                         owner_->getDialogs().showMergeChanges();
958                         return;
959                 }
960
961                 ParIterator const end = buf->par_iterator_end();
962                 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
963                         (*it)->untrackChanges();
964                 }
965                 buf->params.tracking_changes = false;
966         }
967  
968         buf->redostack.clear();
969 }
970
971
972 bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
973 {
974         lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
975                 << " action[" << ev.action << ']'
976                 << " arg[" << ev.argument << ']'
977                 << " x[" << ev.x << ']'
978                 << " y[" << ev.y << ']'
979                 << " button[" << ev.button() << ']'
980                 << endl;
981
982         // e.g. Qt mouse press when no buffer
983         if (!buffer_)
984                 return false;
985
986         LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
987
988         switch (ev.action) {
989
990         case LFUN_SCROLL_INSET:
991                 // this is not handled here as this function is only active
992                 // if we have a locking_inset and that one is (or contains)
993                 // a tabular-inset
994                 break;
995
996         case LFUN_INSET_GRAPHICS:
997         {
998                 Inset * new_inset = new InsetGraphics;
999                 if (!insertInset(new_inset)) {
1000                         delete new_inset;
1001                 } else {
1002                         // this is need because you don't use a inset->Edit()
1003                         updateInset(new_inset, true);
1004                         new_inset->edit(bv_);
1005                 }
1006                 break;
1007         }
1008
1009         case LFUN_LAYOUT_COPY:
1010                 bv_->copyEnvironment();
1011                 break;
1012
1013         case LFUN_LAYOUT_PASTE:
1014                 bv_->pasteEnvironment();
1015                 switchKeyMap();
1016                 break;
1017
1018         case LFUN_DEPTH_MIN:
1019                 changeDepth(bv_, bv_->getLyXText(), -1);
1020                 break;
1021
1022         case LFUN_DEPTH_PLUS:
1023                 changeDepth(bv_, bv_->getLyXText(), 1);
1024                 break;
1025
1026         case LFUN_FREE:
1027                 owner_->getDialogs().setUserFreeFont();
1028                 break;
1029
1030         case LFUN_FILE_INSERT:
1031                 MenuInsertLyXFile(ev.argument);
1032                 break;
1033
1034         case LFUN_FILE_INSERT_ASCII_PARA:
1035                 InsertAsciiFile(bv_, ev.argument, true);
1036                 break;
1037
1038         case LFUN_FILE_INSERT_ASCII:
1039                 InsertAsciiFile(bv_, ev.argument, false);
1040                 break;
1041
1042         case LFUN_LANGUAGE:
1043                 lang(bv_, ev.argument);
1044                 switchKeyMap();
1045                 owner_->view_state_changed();
1046                 break;
1047
1048         case LFUN_EMPH:
1049                 emph(bv_);
1050                 owner_->view_state_changed();
1051                 break;
1052
1053         case LFUN_BOLD:
1054                 bold(bv_);
1055                 owner_->view_state_changed();
1056                 break;
1057
1058         case LFUN_NOUN:
1059                 noun(bv_);
1060                 owner_->view_state_changed();
1061                 break;
1062
1063         case LFUN_CODE:
1064                 code(bv_);
1065                 owner_->view_state_changed();
1066                 break;
1067
1068         case LFUN_SANS:
1069                 sans(bv_);
1070                 owner_->view_state_changed();
1071                 break;
1072
1073         case LFUN_ROMAN:
1074                 roman(bv_);
1075                 owner_->view_state_changed();
1076                 break;
1077
1078         case LFUN_DEFAULT:
1079                 styleReset(bv_);
1080                 owner_->view_state_changed();
1081                 break;
1082
1083         case LFUN_UNDERLINE:
1084                 underline(bv_);
1085                 owner_->view_state_changed();
1086                 break;
1087
1088         case LFUN_FONT_SIZE:
1089                 fontSize(bv_, ev.argument);
1090                 owner_->view_state_changed();
1091                 break;
1092
1093         case LFUN_FONT_STATE:
1094                 owner_->getLyXFunc().setMessage(currentState(bv_));
1095                 break;
1096
1097         case LFUN_INSERT_LABEL:
1098                 MenuInsertLabel(bv_, ev.argument);
1099                 break;
1100
1101         case LFUN_REF_INSERT:
1102                 if (ev.argument.empty()) {
1103                         InsetCommandParams p("ref");
1104                         owner_->getDialogs().createRef(p.getAsString());
1105                 } else {
1106                         InsetCommandParams p;
1107                         p.setFromString(ev.argument);
1108
1109                         InsetRef * inset = new InsetRef(p, *buffer_);
1110                         if (!insertInset(inset))
1111                                 delete inset;
1112                         else
1113                                 updateInset(inset, true);
1114                 }
1115                 break;
1116
1117         case LFUN_BOOKMARK_SAVE:
1118                 savePosition(strToUnsignedInt(ev.argument));
1119                 break;
1120
1121         case LFUN_BOOKMARK_GOTO:
1122                 restorePosition(strToUnsignedInt(ev.argument));
1123                 break;
1124
1125         case LFUN_REF_GOTO:
1126         {
1127                 string label = ev.argument;
1128                 if (label.empty()) {
1129                         InsetRef * inset =
1130                                 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1131                         if (inset) {
1132                                 label = inset->getContents();
1133                                 savePosition(0);
1134                         }
1135                 }
1136
1137                 if (!label.empty()) {
1138                         //bv_->savePosition(0);
1139                         if (!bv_->gotoLabel(label))
1140                                 Alert::alert(_("Error"),
1141                                            _("Couldn't find this label"),
1142                                            _("in current document."));
1143                 }
1144         }
1145         break;
1146
1147         // --- accented characters ---------------------------
1148
1149         case LFUN_UMLAUT:
1150         case LFUN_CIRCUMFLEX:
1151         case LFUN_GRAVE:
1152         case LFUN_ACUTE:
1153         case LFUN_TILDE:
1154         case LFUN_CEDILLA:
1155         case LFUN_MACRON:
1156         case LFUN_DOT:
1157         case LFUN_UNDERDOT:
1158         case LFUN_UNDERBAR:
1159         case LFUN_CARON:
1160         case LFUN_SPECIAL_CARON:
1161         case LFUN_BREVE:
1162         case LFUN_TIE:
1163         case LFUN_HUNG_UMLAUT:
1164         case LFUN_CIRCLE:
1165         case LFUN_OGONEK:
1166                 if (ev.argument.empty()) {
1167                         // As always...
1168                         owner_->getLyXFunc().handleKeyFunc(ev.action);
1169                 } else {
1170                         owner_->getLyXFunc().handleKeyFunc(ev.action);
1171                         owner_->getIntl().getTransManager()
1172                                 .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
1173                         update(bv_->getLyXText(),
1174                                BufferView::SELECT
1175                                | BufferView::FITCUR
1176                                | BufferView::CHANGE);
1177                 }
1178                 break;
1179
1180         case LFUN_MATH_MACRO:
1181         case LFUN_MATH_DELIM:
1182         case LFUN_INSERT_MATRIX:
1183         case LFUN_INSERT_MATH:
1184         case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
1185         case LFUN_MATH_DISPLAY:          // Open or create a displayed math inset
1186         case LFUN_MATH_MODE:             // Open or create an inlined math inset
1187         case LFUN_GREEK:                 // Insert a single greek letter
1188                 mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
1189                 break;
1190
1191         case LFUN_CITATION_INSERT:
1192         {
1193                 InsetCommandParams p;
1194                 p.setFromString(ev.argument);
1195
1196                 InsetCitation * inset = new InsetCitation(p);
1197                 if (!insertInset(inset))
1198                         delete inset;
1199                 else {
1200                         inset->setLoadingBuffer(bv_->buffer(), false);
1201                         updateInset(inset, true);
1202                 }
1203
1204         }
1205         break;
1206
1207         case LFUN_INSERT_BIBTEX:
1208         {
1209                 // ale970405+lasgoutt970425
1210                 // The argument can be up to two tokens separated
1211                 // by a space. The first one is the bibstyle.
1212                 string const db = token(ev.argument, ' ', 0);
1213                 string bibstyle = token(ev.argument, ' ', 1);
1214                 if (bibstyle.empty())
1215                         bibstyle = "plain";
1216
1217                 InsetCommandParams p("BibTeX", db, bibstyle);
1218                 InsetBibtex * inset = new InsetBibtex(p);
1219
1220                 if (insertInset(inset)) {
1221                         if (ev.argument.empty())
1222                                 inset->edit(bv_);
1223                 } else
1224                         delete inset;
1225         }
1226         break;
1227
1228         // BibTeX data bases
1229         case LFUN_BIBDB_ADD:
1230         {
1231                 InsetBibtex * inset =
1232                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
1233                 if (inset) {
1234                         inset->addDatabase(ev.argument);
1235                 }
1236         }
1237         break;
1238
1239         case LFUN_BIBDB_DEL:
1240         {
1241                 InsetBibtex * inset =
1242                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
1243                 if (inset)
1244                         inset->delDatabase(ev.argument);
1245         }
1246         break;
1247
1248         case LFUN_BIBTEX_STYLE:
1249         {
1250                 InsetBibtex * inset =
1251                         static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
1252                 if (inset)
1253                         inset->setOptions(ev.argument);
1254         }
1255         break;
1256
1257         case LFUN_CHILD_INSERT:
1258         {
1259                 InsetInclude::Params p;
1260                 if (!ev.argument.empty())
1261                         p.cparams.setFromString(ev.argument);
1262                 p.masterFilename_ = buffer_->fileName();
1263
1264                 InsetInclude * inset = new InsetInclude(p);
1265                 if (!insertInset(inset))
1266                         delete inset;
1267                 else {
1268                         updateInset(inset, true);
1269                         bv_->owner()->getDialogs().showInclude(inset);
1270                 }
1271         }
1272         break;
1273
1274         case LFUN_FLOAT_LIST:
1275                 if (tclass.floats().typeExist(ev.argument)) {
1276                         Inset * inset = new InsetFloatList(ev.argument);
1277                         if (!insertInset(inset, tclass.defaultLayoutName()))
1278                                 delete inset;
1279                 } else {
1280                         lyxerr << "Non-existent float type: "
1281                                << ev.argument << endl;
1282                 }
1283                 break;
1284
1285         case LFUN_THESAURUS_ENTRY:
1286         {
1287                 string arg = ev.argument;
1288
1289                 if (arg.empty()) {
1290                         arg = bv_->getLyXText()->selectionAsString(buffer_,
1291                                                                    false);
1292
1293                         // FIXME
1294                         if (arg.size() > 100 || arg.empty()) {
1295                                 // Get word or selection
1296                                 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
1297                                 arg = bv_->getLyXText()->selectionAsString(buffer_, false);
1298                                 // FIXME: where is getLyXText()->unselect(bv_) ?
1299                         }
1300                 }
1301
1302                 bv_->owner()->getDialogs().showThesaurus(arg);
1303         }
1304                 break;
1305
1306         case LFUN_TRACK_CHANGES:
1307                 trackChanges();
1308                 break;
1309  
1310         case LFUN_MERGE_CHANGES:
1311                 owner_->getDialogs().showMergeChanges();
1312                 break;
1313  
1314         case LFUN_ACCEPT_ALL_CHANGES: {
1315                 bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1316                 bv_->text->setCursor(bv_, &(*bv_->buffer()->paragraphs.begin()), 0);
1317 #warning FIXME changes 
1318                 //moveCursorUpdate(false);
1319
1320                 while (lyxfind::findNextChange(bv_)) {
1321                         bv_->getLyXText()->acceptChange(bv_);
1322                 }
1323                 update(bv_->text,
1324                         BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
1325                 break;
1326         }
1327  
1328         case LFUN_REJECT_ALL_CHANGES: {
1329                 bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
1330                 bv_->text->setCursor(bv_, &(*bv_->buffer()->paragraphs.begin()), 0);
1331 #warning FIXME changes 
1332                 //moveCursorUpdate(false);
1333
1334                 while (lyxfind::findNextChange(bv_)) {
1335                         bv_->getLyXText()->rejectChange(bv_);
1336                 }
1337                 update(bv_->text,
1338                         BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
1339                 break;
1340         }
1341  
1342         case LFUN_ACCEPT_CHANGE: {
1343                 bv_->getLyXText()->acceptChange(bv_);
1344                 update(bv_->text,
1345                         BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
1346                 break;
1347         }
1348
1349         case LFUN_REJECT_CHANGE: {
1350                 bv_->getLyXText()->rejectChange(bv_);
1351                 update(bv_->text,
1352                         BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
1353                 break;
1354         }
1355  
1356         case LFUN_UNKNOWN_ACTION:
1357                 ev.errorMessage(N_("Unknown function!"));
1358                 break;
1359
1360         default:
1361                 return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
1362         } // end of switch
1363
1364         return true;
1365 }
1366
1367
1368 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
1369 {
1370         // if we are in a locking inset we should try to insert the
1371         // inset there otherwise this is a illegal function now
1372         if (bv_->theLockingInset()) {
1373                 if (bv_->theLockingInset()->insetAllowed(inset))
1374                         return bv_->theLockingInset()->insertInset(bv_, inset);
1375                 return false;
1376         }
1377
1378         // not quite sure if we want this...
1379         setCursorParUndo(bv_);
1380         freezeUndo();
1381
1382         beforeChange(bv_->text);
1383         if (!lout.empty()) {
1384                 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1385                 bv_->text->breakParagraph(bv_);
1386                 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1387
1388                 if (!bv_->text->cursor.par()->empty()) {
1389                         bv_->text->cursorLeft(bv_);
1390
1391                         bv_->text->breakParagraph(bv_);
1392                         update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1393                 }
1394
1395                 string lres = lout;
1396                 LyXTextClass const & tclass =
1397                         buffer_->params.getLyXTextClass();
1398                 bool hasLayout = tclass.hasLayout(lres);
1399                 string lay = tclass.defaultLayoutName();
1400
1401                 if (hasLayout != false) {
1402                         // layout found
1403                         lay = lres;
1404                 } else {
1405                         // layout not fount using default
1406                         lay = tclass.defaultLayoutName();
1407                 }
1408
1409                 bv_->text->setLayout(bv_, lay);
1410
1411                 bv_->text->setParagraph(bv_, 0, 0,
1412                                    0, 0,
1413                                    VSpace(VSpace::NONE), VSpace(VSpace::NONE),
1414                                    Spacing(),
1415                                    LYX_ALIGN_LAYOUT,
1416                                    string(),
1417                                    0);
1418                 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1419         }
1420
1421         bv_->text->insertInset(bv_, inset);
1422         update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1423
1424         unFreezeUndo();
1425         return true;
1426 }
1427
1428
1429 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
1430 {
1431         if (!inset || !available())
1432                 return;
1433
1434         // first check for locking insets
1435         if (bv_->theLockingInset()) {
1436                 if (bv_->theLockingInset() == inset) {
1437                         if (bv_->text->updateInset(bv_, inset)) {
1438                                 update();
1439                                 if (mark_dirty) {
1440                                         buffer_->markDirty();
1441                                 }
1442                                 updateScrollbar();
1443                                 return;
1444                         }
1445                 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
1446                         if (bv_->text->updateInset(bv_,  bv_->theLockingInset())) {
1447                                 update();
1448                                 if (mark_dirty) {
1449                                         buffer_->markDirty();
1450                                 }
1451                                 updateScrollbar();
1452                                 return;
1453                         }
1454                 }
1455         }
1456
1457         // then check if the inset is a top_level inset (has no owner)
1458         // if yes do the update as always otherwise we have to update the
1459         // toplevel inset where this inset is inside
1460         Inset * tl_inset = inset;
1461         while (tl_inset->owner())
1462                 tl_inset = tl_inset->owner();
1463         hideCursor();
1464         if (tl_inset == inset) {
1465                 update(bv_->text, BufferView::UPDATE);
1466                 if (bv_->text->updateInset(bv_, inset)) {
1467                         if (mark_dirty) {
1468                                 update(bv_->text,
1469                                        BufferView::SELECT
1470                                        | BufferView::FITCUR
1471                                        | BufferView::CHANGE);
1472                         } else {
1473                                 update(bv_->text, SELECT);
1474                         }
1475                         return;
1476                 }
1477         } else if (static_cast<UpdatableInset *>(tl_inset)
1478                            ->updateInsetInInset(bv_, inset))
1479         {
1480                 if (bv_->text->updateInset(bv_, tl_inset)) {
1481                         update();
1482                         updateScrollbar();
1483                 }
1484         }
1485 }