12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
20 #include "bufferview_funcs.h"
21 #include "TextCache.h"
22 #include "bufferlist.h"
23 #include "lyx_gui_misc.h"
26 #include "support/LAssert.h"
27 #include "frontends/Dialogs.h"
28 #include "insets/insetbib.h"
29 #include "insets/insettext.h"
30 /// added for Dispatch functions
32 #include "frontends/FileDialog.h"
34 #include "FloatList.h"
35 #include "support/filetools.h"
36 #include "support/lyxfunctional.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinfo.h"
44 #include "insets/insetinclude.h"
45 #include "insets/insetcite.h"
46 #include "insets/insetert.h"
47 #include "insets/insetexternal.h"
48 #include "insets/insetgraphics.h"
49 #include "insets/insetfoot.h"
50 #include "insets/insetmarginal.h"
51 #include "insets/insetminipage.h"
52 #include "insets/insetfloat.h"
53 #include "insets/insetlist.h"
54 #include "insets/insettabular.h"
55 #include "insets/insettheorem.h"
56 #include "insets/insetcaption.h"
57 #include "insets/insetfloatlist.h"
58 #include "insets/insetspecialchar.h"
59 #include "mathed/formulamacro.h"
62 extern LyXTextClass::size_type current_layout;
63 extern int greek_kb_flag;
74 /* the selection possible is needed, that only motion events are
75 * used, where the bottom press event was on the drawing area too */
76 bool selection_possible = false;
78 extern BufferList bufferlist;
79 extern char ascii_type;
81 extern bool math_insert_greek(BufferView *, char);
82 extern void sigchldhandler(pid_t pid, int * status);
83 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
87 const unsigned int saved_positions_num = 20;
92 XSync(fl_get_display(), 0);
96 void SetXtermCursor(Window win)
99 static bool cursor_undefined = true;
100 if (cursor_undefined){
101 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
102 XFlush(fl_get_display());
103 cursor_undefined = false;
105 XDefineCursor(fl_get_display(), win, cursor);
106 XFlush(fl_get_display());
112 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
113 int xpos, int ypos, int width, int height)
114 : bv_(b), owner_(o), buffer_(0),
115 current_scrollbar_value(0), cursor_timeout(400),
116 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
120 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
121 workarea_.workAreaExpose
122 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
123 workarea_.workAreaEnter
124 .connect(slot(this, &BufferView::Pimpl::enterView));
125 workarea_.workAreaLeave
126 .connect(slot(this, &BufferView::Pimpl::leaveView));
127 workarea_.workAreaButtonPress
128 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
129 workarea_.workAreaButtonRelease
131 &BufferView::Pimpl::workAreaButtonRelease));
132 workarea_.workAreaMotionNotify
133 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
134 workarea_.workAreaDoubleClick
135 .connect(slot(this, &BufferView::Pimpl::doubleClick));
136 workarea_.workAreaTripleClick
137 .connect(slot(this, &BufferView::Pimpl::tripleClick));
138 workarea_.workAreaKeyPress
139 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
141 cursor_timeout.timeout.connect(slot(this,
142 &BufferView::Pimpl::cursorToggle));
143 cursor_timeout.start();
144 workarea_.setFocus();
145 saved_positions.resize(saved_positions_num);
149 Painter & BufferView::Pimpl::painter()
151 return workarea_.getPainter();
155 void BufferView::Pimpl::buffer(Buffer * b)
157 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
161 buffer_->delUser(bv_);
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");
174 // Set current buffer
177 if (bufferlist.getState() == BufferList::CLOSING) return;
180 // screen is always deleted when the buffer is changed.
183 // If we are closing the buffer, use the first buffer as current
185 buffer_ = bufferlist.first();
189 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
190 buffer_->addUser(bv_);
191 // If we don't have a text object for this, we make one
192 if (bv_->text == 0) {
193 resizeCurrentBuffer();
198 bv_->text->first = screen_->TopCursorVisible(bv_->text);
199 owner_->updateMenubar();
200 owner_->updateToolbar();
201 // Similarly, buffer-dependent dialogs should be updated or
202 // hidden. This should go here because some dialogs (eg ToC)
203 // require bv_->text.
204 owner_->getDialogs()->updateBufferDependent(true);
208 lyxerr[Debug::INFO] << " No Buffer!" << endl;
209 owner_->updateMenubar();
210 owner_->updateToolbar();
211 owner_->getDialogs()->hideBufferDependent();
215 // Also remove all remaining text's from the testcache.
216 // (there should not be any!) (if there is any it is a
218 if (lyxerr.debugging())
219 textcache.show(lyxerr, "buffer delete all");
222 // should update layoutchoice even if we don't have a buffer.
223 owner_->updateLayoutChoice();
225 owner_->updateWindowTitle();
229 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
231 workarea_.resize(xpos, ypos, width, height);
232 update(bv_->text, SELECT);
237 void BufferView::Pimpl::resize()
240 resizeCurrentBuffer();
244 void BufferView::Pimpl::redraw()
246 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
251 bool BufferView::Pimpl::fitCursor(LyXText * text)
253 lyx::Assert(screen_.get());
255 bv_->owner()->getDialogs()->updateParagraph();
257 bool const ret = screen_->FitCursor(text, bv_);
264 void BufferView::Pimpl::redoCurrentBuffer()
266 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
267 if (buffer_ && bv_->text) {
269 owner_->updateLayoutChoice();
274 int BufferView::Pimpl::resizeCurrentBuffer()
276 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
278 LyXParagraph * par = 0;
279 LyXParagraph * selstartpar = 0;
280 LyXParagraph * selendpar = 0;
281 UpdatableInset * the_locking_inset = 0;
283 LyXParagraph::size_type pos = 0;
284 LyXParagraph::size_type selstartpos = 0;
285 LyXParagraph::size_type selendpos = 0;
286 bool selection = false;
287 bool mark_set = false;
291 owner_->message(_("Formatting document..."));
294 par = bv_->text->cursor.par();
295 pos = bv_->text->cursor.pos();
296 selstartpar = bv_->text->selection.start.par();
297 selstartpos = bv_->text->selection.start.pos();
298 selendpar = bv_->text->selection.end.par();
299 selendpos = bv_->text->selection.end.pos();
300 selection = bv_->text->selection.set();
301 mark_set = bv_->text->selection.mark();
302 the_locking_inset = bv_->theLockingInset();
304 bv_->text = new LyXText(bv_);
306 // See if we have a text in TextCache that fits
307 // the new buffer_ with the correct width.
308 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
310 if (lyxerr.debugging()) {
311 lyxerr << "Found a LyXText that fits:\n";
312 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
314 // Set the owner of the newly found text
315 // bv_->text->owner(bv_);
316 if (lyxerr.debugging())
317 textcache.show(lyxerr, "resizeCurrentBuffer");
319 bv_->text = new LyXText(bv_);
325 bv_->text->selection.set(true);
326 /* at this point just to avoid the Delete-Empty-Paragraph
327 * Mechanism when setting the cursor */
328 bv_->text->selection.mark(mark_set);
330 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
331 bv_->text->selection.cursor = bv_->text->cursor;
332 bv_->text->SetCursor(bv_, selendpar, selendpos);
333 bv_->text->SetSelection(bv_);
334 bv_->text->SetCursor(bv_, par, pos);
336 bv_->text->SetCursor(bv_, par, pos);
337 bv_->text->selection.cursor = bv_->text->cursor;
338 bv_->text->selection.set(false);
340 // remake the inset locking
341 bv_->theLockingInset(the_locking_inset);
343 bv_->text->first = screen_->TopCursorVisible(bv_->text);
344 buffer_->resizeInsets(bv_);
345 // this will scroll the screen such that the cursor becomes visible
352 /// clear the "Formatting Document" message
355 /// get rid of the splash screen if it's not gone already
356 owner_->getDialogs()->destroySplash();
362 void BufferView::Pimpl::updateScreen()
364 // Regenerate the screen.
365 screen_.reset(new LyXScreen(workarea_));
369 void BufferView::Pimpl::updateScrollbar()
371 /* If the text is smaller than the working area, the scrollbar
372 * maximum must be the working area height. No scrolling will
376 workarea_.setScrollbar(0, 1.0);
380 static unsigned long text_height;
381 static unsigned long work_height;
383 unsigned long const tmp_text_height = bv_->text->height;
384 long const tmp_scrollbar_value = bv_->text->first;
386 // check if anything has changed.
387 if (text_height == tmp_text_height
388 && work_height == workarea_.height()
389 && current_scrollbar_value == tmp_scrollbar_value)
393 text_height = tmp_text_height;
394 work_height = workarea_.height();
395 current_scrollbar_value = tmp_scrollbar_value;
397 long const height_diff = text_height - work_height;
399 if (height_diff <= 0) {
400 workarea_.setScrollbar(0, 1.0);
405 workarea_.setScrollbarBounds(0, height_diff);
406 double const lineh = bv_->text->DefaultHeight();
407 workarea_.setScrollbarIncrements(lineh);
408 double const slider_size = 1.0 / double(height_diff) ;
409 workarea_.setScrollbar(current_scrollbar_value, slider_size);
413 // Callback for scrollbar slider
414 void BufferView::Pimpl::scrollCB(double value)
416 if (!buffer_) return;
418 current_scrollbar_value = long(value);
419 if (current_scrollbar_value < 0)
420 current_scrollbar_value = 0;
425 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
427 if (!lyxrc.cursor_follows_scrollbar) {
432 LyXText * vbt = bv_->text;
434 int const height = vbt->DefaultHeight();
435 int const first = static_cast<int>((bv_->text->first + height));
436 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
438 if (vbt->cursor.y() < first)
439 vbt->SetCursorFromCoordinates(bv_, 0, first);
440 else if (vbt->cursor.y() > last)
441 vbt->SetCursorFromCoordinates(bv_, 0, last);
447 int BufferView::Pimpl::scrollUp(long time)
449 if (!buffer_) return 0;
450 if (!screen_.get()) return 0;
452 double value = workarea_.getScrollbarValue();
454 if (value == 0) return 0;
456 float add_value = (bv_->text->DefaultHeight()
457 + float(time) * float(time) * 0.125);
459 if (add_value > workarea_.height())
460 add_value = float(workarea_.height() -
461 bv_->text->DefaultHeight());
468 workarea_.setScrollbarValue(value);
475 int BufferView::Pimpl::scrollDown(long time)
477 if (!buffer_) return 0;
478 if (!screen_.get()) return 0;
480 double value = workarea_.getScrollbarValue();
481 pair<float, float> p = workarea_.getScrollbarBounds();
482 double const max = p.second;
484 if (value == max) return 0;
486 float add_value = (bv_->text->DefaultHeight()
487 + float(time) * float(time) * 0.125);
489 if (add_value > workarea_.height())
490 add_value = float(workarea_.height() -
491 bv_->text->DefaultHeight());
498 workarea_.setScrollbarValue(value);
505 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
507 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
511 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
513 // Only use motion with button 1
514 if (!(state & Button1MotionMask))
517 if (!buffer_ || !screen_.get()) return;
519 // Check for inset locking
520 if (bv_->theLockingInset()) {
521 LyXCursor cursor = bv_->text->cursor;
522 LyXFont font = bv_->text->GetFont(buffer_,
523 cursor.par(), cursor.pos());
524 int width = bv_->theLockingInset()->width(bv_, font);
525 int inset_x = font.isVisibleRightToLeft()
526 ? cursor.x() - width : cursor.x();
527 int start_x = inset_x + bv_->theLockingInset()->scroll();
528 bv_->theLockingInset()->
529 InsetMotionNotify(bv_,
531 y - cursor.y() + bv_->text->first,
536 /* The test for not selection possible is needed, that only motion
537 events are used, where the bottom press event was on
538 the drawing area too */
539 if (!selection_possible)
542 screen_->HideCursor();
544 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
546 if (!bv_->text->selection.set())
547 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
549 bv_->text->SetSelection(bv_);
550 screen_->ToggleToggle(bv_->text, bv_);
551 fitCursor(bv_->text);
552 screen_->ShowCursor(bv_->text, bv_);
556 // Single-click on work area
557 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
560 if (!buffer_ || !screen_.get()) return;
562 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
564 // ok ok, this is a hack.
565 if (button == 4 || button == 5) {
568 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
571 scrollDown(lyxrc.wheel_jump);
576 if (bv_->theLockingInset()) {
577 // We are in inset locking mode
579 /* Check whether the inset was hit. If not reset mode,
580 otherwise give the event to the inset */
581 if (inset_hit == bv_->theLockingInset()) {
582 bv_->theLockingInset()->
583 InsetButtonPress(bv_,
588 bv_->unlockInset(bv_->theLockingInset());
593 selection_possible = true;
594 screen_->HideCursor();
596 int const screen_first = bv_->text->first;
598 // Middle button press pastes if we have a selection
599 bool paste_internally = false;
601 && bv_->text->selection.set()) {
602 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
603 paste_internally = true;
606 // Clear the selection
607 screen_->ToggleSelection(bv_->text, bv_);
608 bv_->text->ClearSelection(bv_);
609 bv_->text->FullRebreak(bv_);
610 screen_->Update(bv_->text, bv_);
613 // Single left click in math inset?
614 if ((inset_hit != 0) &&
615 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
616 // Highly editable inset, like math
617 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
618 selection_possible = false;
619 owner_->updateLayoutChoice();
620 owner_->message(inset->EditMessage());
621 inset->InsetButtonPress(bv_, xpos, ypos, button);
622 inset->Edit(bv_, xpos, ypos, button);
626 // Right click on a footnote flag opens float menu
628 selection_possible = false;
632 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
633 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
634 bv_->text->FinishUndo();
635 bv_->text->selection.cursor = bv_->text->cursor;
636 bv_->text->cursor.x_fix(bv_->text->cursor.x());
638 owner_->updateLayoutChoice();
639 if (fitCursor(bv_->text)) {
640 selection_possible = false;
643 // Insert primary selection with middle mouse
644 // if there is a local selection in the current buffer,
647 if (paste_internally)
648 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
650 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
652 selection_possible = false;
658 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
664 LyXText * text = bv_->getLyXText();
666 if (text->bv_owner && bv_->theLockingInset())
669 if (screen_.get() && button == 1) {
670 if (text->bv_owner) {
671 screen_->HideCursor();
672 screen_->ToggleSelection(text, bv_);
673 text->SelectWord(bv_);
674 screen_->ToggleSelection(text, bv_, false);
676 text->SelectWord(bv_);
678 /* This will fit the cursor on the screen
680 update(text, BufferView::SELECT|BufferView::FITCUR);
685 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
691 LyXText * text = bv_->getLyXText();
693 if (text->bv_owner && bv_->theLockingInset())
696 if (screen_.get() && (button == 1)) {
697 screen_->HideCursor();
698 screen_->ToggleSelection(text, bv_);
699 text->CursorHome(bv_);
700 text->selection.cursor = text->cursor;
701 text->CursorEnd(bv_);
702 text->SetSelection(bv_);
703 screen_->ToggleSelection(text, bv_, false);
704 /* This will fit the cursor on the screen
706 update(text, BufferView::SELECT|BufferView::FITCUR);
711 void BufferView::Pimpl::enterView()
713 if (active() && available()) {
714 SetXtermCursor(workarea_.getWin());
715 using_xterm_cursor = true;
720 void BufferView::Pimpl::leaveView()
722 if (using_xterm_cursor) {
723 XUndefineCursor(fl_get_display(), workarea_.getWin());
724 using_xterm_cursor = false;
729 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
732 if (!buffer_ || !screen_.get()) return;
734 // If we hit an inset, we have the inset coordinates in these
735 // and inset_hit points to the inset. If we do not hit an
736 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
737 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
739 if (bv_->theLockingInset()) {
740 // We are in inset locking mode.
742 /* LyX does a kind of work-area grabbing for insets.
743 Only a ButtonPress Event outside the inset will
744 force a InsetUnlock. */
745 bv_->theLockingInset()->
746 InsetButtonRelease(bv_, x, y, button);
750 selection_possible = false;
758 // Did we hit an editable inset?
760 // Inset like error, notes and figures
761 selection_possible = false;
763 // CHECK fix this proper in 0.13
765 // Following a ref shouldn't issue
766 // a push on the undo-stack
767 // anylonger, now that we have
768 // keybindings for following
769 // references and returning from
770 // references. IMHO though, it
771 // should be the inset's own business
772 // to push or not push on the undo
773 // stack. They don't *have* to
774 // alter the document...
776 // ...or maybe the SetCursorParUndo()
777 // below isn't necessary at all anylonger?
778 if (inset_hit->LyxCode() == Inset::REF_CODE) {
779 bv_->text->SetCursorParUndo(buffer_);
782 owner_->message(inset_hit->EditMessage());
784 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
785 // Highly editable inset, like math
786 UpdatableInset *inset = (UpdatableInset *)inset_hit;
787 inset->InsetButtonRelease(bv_, x, y, button);
789 inset_hit->InsetButtonRelease(bv_, x, y, button);
790 inset_hit->Edit(bv_, x, y, button);
795 // check whether we want to open a float
799 if (bv_->text->cursor.pos() <
800 bv_->text->cursor.par()->size()) {
801 c = bv_->text->cursor.par()->
802 GetChar(bv_->text->cursor.pos());
804 if (bv_->text->cursor.pos() - 1 >= 0) {
805 c = bv_->text->cursor.par()->
806 GetChar(bv_->text->cursor.pos() - 1);
809 selection_possible = false;
814 // Maybe we want to edit a bibitem ale970302
815 if (bv_->text->cursor.par()->bibkey && x < 20 +
816 bibitemMaxWidth(bv_, textclasslist.
818 params.textclass).defaultfont())) {
819 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
827 * Returns an inset if inset was hit. 0 otherwise.
828 * If hit, the coordinates are changed relative to the inset.
829 * Otherwise coordinates are not changed, and false is returned.
831 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
832 unsigned int /* button */)
837 int y_tmp = y + text->first;
840 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
841 text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
844 if (cursor.pos() < cursor.par()->size()
845 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
846 && cursor.par()->GetInset(cursor.pos())
847 && cursor.par()->GetInset(cursor.pos())->Editable()) {
849 // Check whether the inset really was hit
850 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
851 LyXFont font = text->GetFont(buffer_,
852 cursor.par(), cursor.pos());
853 int const width = tmpinset->width(bv_, font);
854 int const inset_x = font.isVisibleRightToLeft()
855 ? cursor.x() - width : cursor.x();
856 int const start_x = inset_x + tmpinset->scroll();
857 int const end_x = inset_x + width;
859 if (x > start_x && x < end_x
860 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
861 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
862 text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
864 // The origin of an inset is on the baseline
865 y = y_tmp - (text->cursor.y());
870 if ((cursor.pos() - 1 >= 0) &&
871 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
872 (cursor.par()->GetInset(cursor.pos() - 1)) &&
873 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
874 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
875 LyXFont font = text->GetFont(buffer_, cursor.par(),
877 int const width = tmpinset->width(bv_, font);
878 int const inset_x = font.isVisibleRightToLeft()
879 ? cursor.x() : cursor.x() - width;
880 int const start_x = inset_x + tmpinset->scroll();
881 int const end_x = inset_x + width;
883 if (x > start_x && x < end_x
884 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
885 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
887 if (move_cursor && (tmpinset != bv_->theLockingInset()))
889 text->SetCursor(bv_, cursor.par(),
890 cursor.pos() - 1, true);
892 // The origin of an inset is on the baseline
893 y = y_tmp - (text->cursor.y());
901 void BufferView::Pimpl::workAreaExpose()
903 static int work_area_width;
904 static unsigned int work_area_height;
906 bool const widthChange = workarea_.workWidth() != work_area_width;
907 bool const heightChange = workarea_.height() != work_area_height;
909 // update from work area
910 work_area_width = workarea_.workWidth();
911 work_area_height = workarea_.height();
914 // All buffers need a resize
917 // Remove all texts from the textcache
918 // This is not _really_ what we want to do. What
919 // we really want to do is to delete in textcache
920 // that does not have a BufferView with matching
921 // width, but as long as we have only one BufferView
922 // deleting all gives the same result.
923 if (lyxerr.debugging())
924 textcache.show(lyxerr, "Expose delete all");
926 } else if (heightChange) {
927 // Rebuild image of current screen
929 // fitCursor() ensures we don't jump back
930 // to the start of the document on vertical
932 fitCursor(bv_->text);
934 // The main window size has changed, repaint most stuff
936 } else if (screen_.get())
937 screen_->Redraw(bv_->text, bv_);
939 // Grey box when we don't have a buffer
943 // always make sure that the scrollbar is sane.
945 owner_->updateLayoutChoice();
950 void BufferView::Pimpl::update()
953 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
955 screen_->Update(bv_->text, bv_);
959 // Values used when calling update:
961 // -2 - update, move sel_cursor if selection, fitcursor
962 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
963 // 0 - update, move sel_cursor if selection, fitcursor
964 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
965 // 3 - update, move sel_cursor if selection
968 // a simple redraw of the parts that need refresh
970 // move sel_cursor if selection -
971 // the text's sel_cursor is moved if there is selection is progress
974 // fitCursor() is called and the scrollbar updated
977 // the buffer is marked dirty.
986 // UPDATE_ONLY = UPDATE;
987 // UPDATE_SELECT = UPDATE | SELECT;
988 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
989 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
991 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
992 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
993 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
994 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
995 // update(3) -> update(1) -> update(1) -> update(SELECT)
997 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
999 owner_->updateLayoutChoice();
1001 if (!text->selection.set() && (f & SELECT)) {
1002 text->selection.cursor = text->cursor;
1005 text->FullRebreak(bv_);
1007 if (text->inset_owner) {
1008 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1009 updateInset(text->inset_owner, true);
1018 buffer_->markDirty();
1023 // Callback for cursor timer
1024 void BufferView::Pimpl::cursorToggle()
1026 // Quite a nice place for asyncron Inset updating, isn't it?
1027 // Actually no! This is run even if no buffer exist... so (Lgb)
1029 cursor_timeout.restart();
1034 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1035 if (pid == -1) // error find out what is wrong
1036 ; // ignore it for now.
1038 sigchldhandler(pid, &status);
1040 updatelist.update(bv_);
1042 if (!screen_.get()) {
1043 cursor_timeout.restart();
1047 if (!bv_->theLockingInset()) {
1048 screen_->CursorToggle(bv_->text, bv_);
1050 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1053 cursor_timeout.restart();
1057 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1059 if (!text->cursor.row()->previous())
1062 int y = text->first;
1063 if (text->inset_owner)
1064 y += bv_->text->first;
1065 Row * cursorrow = text->cursor.row();
1066 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1067 bv_->text->FinishUndo();
1068 // This is to allow jumping over large insets
1069 if ((cursorrow == text->cursor.row()))
1070 text->CursorUp(bv_);
1072 if (text->inset_owner ||
1073 text->cursor.row()->height() < workarea_.height())
1074 screen_->Draw(bv_->text, bv_,
1076 - text->cursor.row()->baseline()
1077 + text->cursor.row()->height()
1078 - workarea_.height() + 1 );
1083 void BufferView::Pimpl::cursorNext(LyXText * text)
1085 if (!text->cursor.row()->next())
1088 int y = text->first + workarea_.height();
1089 // if (text->inset_owner)
1090 // y += bv_->text->first;
1091 text->GetRowNearY(y);
1093 Row * cursorrow = text->cursor.row();
1094 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1095 bv_->text->FinishUndo();
1096 // This is to allow jumping over large insets
1097 if ((cursorrow == bv_->text->cursor.row()))
1098 text->CursorDown(bv_);
1100 if (text->inset_owner ||
1101 text->cursor.row()->height() < workarea_.height())
1102 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1103 text->cursor.row()->baseline());
1108 bool BufferView::Pimpl::available() const
1110 if (buffer_ && bv_->text) return true;
1115 void BufferView::Pimpl::beforeChange(LyXText * text)
1118 text->ClearSelection(bv_);
1122 void BufferView::Pimpl::savePosition(unsigned int i)
1124 if (i >= saved_positions_num)
1126 saved_positions[i] = Position(buffer_->fileName(),
1127 bv_->text->cursor.par()->id(),
1128 bv_->text->cursor.pos());
1131 str << _("Saved bookmark") << ' ' << i;
1132 owner_->message(str.str().c_str());
1137 void BufferView::Pimpl::restorePosition(unsigned int i)
1139 if (i >= saved_positions_num)
1142 string const fname = saved_positions[i].filename;
1144 beforeChange(bv_->text);
1146 if (fname != buffer_->fileName()) {
1147 Buffer * b = bufferlist.exists(fname) ?
1148 bufferlist.getBuffer(fname) :
1149 bufferlist.loadLyXFile(fname); // don't ask, just load it
1150 if (b != 0 ) buffer(b);
1153 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1157 bv_->text->SetCursor(bv_, par,
1158 min(par->size(), saved_positions[i].par_pos));
1160 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1163 str << _("Moved to bookmark") << ' ' << i;
1164 owner_->message(str.str().c_str());
1169 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1171 if (i >= saved_positions_num)
1174 return !saved_positions[i].filename.empty();
1178 void BufferView::Pimpl::setState()
1180 if (!lyxrc.rtl_support)
1183 LyXText * text = bv_->getLyXText();
1184 if (text->real_current_font.isRightToLeft() &&
1185 text->real_current_font.latex() != LyXFont::ON) {
1186 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1187 owner_->getIntl()->KeyMapSec();
1189 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1190 owner_->getIntl()->KeyMapPrim();
1195 void BufferView::Pimpl::insetSleep()
1197 if (bv_->theLockingInset() && !inset_slept) {
1198 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1199 bv_->theLockingInset()->InsetUnlock(bv_);
1205 void BufferView::Pimpl::insetWakeup()
1207 if (bv_->theLockingInset() && inset_slept) {
1208 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1209 inset_slept = false;
1214 void BufferView::Pimpl::insetUnlock()
1216 if (bv_->theLockingInset()) {
1218 bv_->theLockingInset()->InsetUnlock(bv_);
1219 bv_->theLockingInset(0);
1220 bv_->text->FinishUndo();
1221 inset_slept = false;
1226 bool BufferView::Pimpl::focus() const
1228 return workarea_.hasFocus();
1232 void BufferView::Pimpl::focus(bool f)
1234 if (f) workarea_.setFocus();
1238 bool BufferView::Pimpl::active() const
1240 return workarea_.active();
1244 bool BufferView::Pimpl::belowMouse() const
1246 return workarea_.belowMouse();
1250 void BufferView::Pimpl::showCursor()
1253 screen_->ShowCursor(bv_->text, bv_);
1257 void BufferView::Pimpl::hideCursor()
1260 screen_->HideCursor();
1264 void BufferView::Pimpl::toggleSelection(bool b)
1267 screen_->ToggleSelection(bv_->text, bv_, b);
1271 void BufferView::Pimpl::toggleToggle()
1274 screen_->ToggleToggle(bv_->text, bv_);
1278 void BufferView::Pimpl::center()
1280 beforeChange(bv_->text);
1281 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1282 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1284 screen_->Draw(bv_->text, bv_, 0);
1286 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1291 void BufferView::Pimpl::pasteClipboard(bool asPara)
1293 if (!buffer_) return;
1295 screen_->HideCursor();
1296 beforeChange(bv_->text);
1298 string const clip(workarea_.getClipboard());
1300 if (clip.empty()) return;
1303 bv_->text->InsertStringB(bv_, clip);
1305 bv_->text->InsertStringA(bv_, clip);
1307 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1311 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1313 workarea_.putClipboard(stuff);
1318 * Dispatch functions for actions which can be valid for BufferView->text
1319 * and/or InsetText->text!!!
1324 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1326 LyXText * lt = bv_->getLyXText();
1328 if (selecting || lt->selection.mark()) {
1329 lt->SetSelection(bv_);
1333 update(lt, BufferView::SELECT|BufferView::FITCUR);
1336 /* ---> Everytime the cursor is moved, show the current font state. */
1337 // should this too me moved out of this func?
1338 //owner->showState();
1343 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1345 LyXCursor cursor = bv_->getLyXText()->cursor;
1346 Buffer::inset_iterator it =
1347 find_if(Buffer::inset_iterator(
1348 cursor.par(), cursor.pos()),
1349 buffer_->inset_iterator_end(),
1350 lyx::compare_memfun(&Inset::LyxCode, code));
1351 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1355 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1357 string filename = filen;
1359 if (filename.empty()) {
1360 // Launch a file browser
1361 string initpath = lyxrc.document_path;
1364 string const trypath = owner_->buffer()->filepath;
1365 // If directory is writeable, use this as default.
1366 if (IsDirWriteable(trypath) == 1)
1370 FileDialog fileDlg(bv_->owner(),
1371 _("Select LyX document to insert"),
1373 make_pair(string(_("Documents")),
1374 string(lyxrc.document_path)),
1375 make_pair(string(_("Examples")),
1376 string(AddPath(system_lyxdir, "examples"))));
1378 FileDialog::Result result =
1379 fileDlg.Select(initpath,
1380 _("*.lyx| LyX Documents (*.lyx)"));
1382 if (result.first == FileDialog::Later)
1385 filename = result.second;
1387 // check selected filename
1388 if (filename.empty()) {
1389 owner_->message(_("Canceled."));
1394 // get absolute path of file and make sure the filename ends
1396 filename = MakeAbsPath(filename);
1397 if (!IsLyXFilename(filename))
1400 string const disp_fn(MakeDisplayPath(filename));
1404 s1 << _("Inserting document") << ' '
1405 << disp_fn << " ...";
1406 owner_->message(s1.str().c_str());
1407 bool const res = bv_->insertLyXFile(filename);
1410 str << _("Document") << ' ' << disp_fn
1411 << ' ' << _("inserted.");
1412 owner_->message(str.str().c_str());
1415 str << _("Could not insert document") << ' '
1417 owner_->message(str.str().c_str());
1422 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1425 // --- Misc -------------------------------------------
1429 LyXText * lt = bv_->getLyXText();
1430 lt->toggleAppendix(bv_);
1433 | BufferView::FITCUR
1434 | BufferView::CHANGE);
1439 case LFUN_TOC_INSERT:
1441 InsetCommandParams p;
1442 p.setCmdName("tableofcontents");
1443 Inset * inset = new InsetTOC(p);
1444 if (!insertInset(inset, "Standard"))
1449 case LFUN_TABULAR_FEATURE:
1450 case LFUN_SCROLL_INSET:
1451 // this is not handled here as this funktion is only aktive
1452 // if we have a locking_inset and that one is (or contains)
1456 case LFUN_INSET_GRAPHICS:
1458 Inset * new_inset = new InsetGraphics;
1459 if (!insertInset(new_inset)) {
1462 // this is need because you don't use a inset->Edit()
1463 updateInset(new_inset, true);
1464 new_inset->Edit(bv_, 0, 0, 0);
1474 case LFUN_PASTESELECTION:
1476 bool asPara = false;
1477 if (argument == "paragraph") asPara = true;
1478 pasteClipboard(asPara);
1490 case LFUN_LAYOUT_COPY:
1491 bv_->copyEnvironment();
1494 case LFUN_LAYOUT_PASTE:
1495 bv_->pasteEnvironment();
1499 case LFUN_GOTOERROR:
1500 gotoInset(Inset::ERROR_CODE, false);
1504 gotoInset(Inset::IGNORE_CODE, false);
1507 case LFUN_REFERENCE_GOTO:
1509 vector<Inset::Code> tmp;
1510 tmp.push_back(Inset::LABEL_CODE);
1511 tmp.push_back(Inset::REF_CODE);
1512 gotoInset(tmp, true);
1516 case LFUN_HYPHENATION:
1524 case LFUN_END_OF_SENTENCE:
1528 case LFUN_MENU_SEPARATOR:
1537 changeDepth(bv_, bv_->getLyXText(), 0);
1540 case LFUN_DEPTH_MIN:
1541 changeDepth(bv_, bv_->getLyXText(), -1);
1544 case LFUN_DEPTH_PLUS:
1545 changeDepth(bv_, bv_->getLyXText(), 1);
1549 owner_->getDialogs()->setUserFreeFont();
1555 owner_->showState();
1558 case LFUN_FILE_INSERT:
1560 MenuInsertLyXFile(argument);
1564 case LFUN_FILE_INSERT_ASCII_PARA:
1565 InsertAsciiFile(bv_, argument, true);
1568 case LFUN_FILE_INSERT_ASCII:
1569 InsertAsciiFile(bv_, argument, false);
1574 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1575 << argument << endl;
1577 // Derive layout number from given argument (string)
1578 // and current buffer's textclass (number). */
1579 LyXTextClassList::ClassList::size_type tclass =
1580 buffer_->params.textclass;
1581 pair <bool, LyXTextClass::size_type> layout =
1582 textclasslist.NumberOfLayout(tclass, argument);
1584 // If the entry is obsolete, use the new one instead.
1586 string obs = textclasslist.Style(tclass,layout.second)
1590 textclasslist.NumberOfLayout(tclass, obs);
1593 // see if we found the layout number:
1594 if (!layout.first) {
1595 owner_->getLyXFunc()->setErrorMessage(
1596 string(N_("Layout ")) + argument +
1601 if (current_layout != layout.second) {
1602 LyXText * lt = bv_->getLyXText();
1604 current_layout = layout.second;
1607 | BufferView::FITCUR);
1608 lt->SetLayout(bv_, layout.second);
1609 owner_->setLayout(layout.second);
1612 | BufferView::FITCUR
1613 | BufferView::CHANGE);
1620 Lang(bv_, argument);
1622 owner_->showState();
1627 owner_->showState();
1632 owner_->showState();
1637 owner_->showState();
1642 owner_->showState();
1647 owner_->showState();
1652 owner_->showState();
1657 owner_->showState();
1660 case LFUN_UNDERLINE:
1662 owner_->showState();
1665 case LFUN_FONT_SIZE:
1666 FontSize(bv_, argument);
1667 owner_->showState();
1670 case LFUN_FONT_STATE:
1671 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1674 case LFUN_UPCASE_WORD:
1676 LyXText * lt = bv_->getLyXText();
1680 | BufferView::FITCUR);
1681 lt->ChangeWordCase(bv_, LyXText::text_uppercase);
1682 if (lt->inset_owner)
1683 updateInset(lt->inset_owner, true);
1686 | BufferView::FITCUR
1687 | BufferView::CHANGE);
1691 case LFUN_LOWCASE_WORD:
1693 LyXText * lt = bv_->getLyXText();
1695 update(lt, BufferView::SELECT|BufferView::FITCUR);
1696 lt->ChangeWordCase(bv_, LyXText::text_lowercase);
1697 if (lt->inset_owner)
1698 updateInset(lt->inset_owner, true);
1701 | BufferView::FITCUR
1702 | BufferView::CHANGE);
1706 case LFUN_CAPITALIZE_WORD:
1708 LyXText * lt = bv_->getLyXText();
1710 update(lt, BufferView::SELECT|BufferView::FITCUR);
1711 lt->ChangeWordCase(bv_,
1712 LyXText::text_capitalization);
1713 if (lt->inset_owner)
1714 updateInset(lt->inset_owner, true);
1717 | BufferView::FITCUR
1718 | BufferView::CHANGE);
1722 case LFUN_TRANSPOSE_CHARS:
1724 LyXText * lt = bv_->getLyXText();
1726 update(lt, BufferView::SELECT|BufferView::FITCUR);
1727 lt->TransposeChars(*bv_);
1728 if (lt->inset_owner)
1729 updateInset(lt->inset_owner, true);
1732 | BufferView::FITCUR
1733 | BufferView::CHANGE);
1738 case LFUN_INSERT_LABEL:
1739 MenuInsertLabel(bv_, argument);
1742 case LFUN_REF_INSERT:
1743 if (argument.empty()) {
1744 InsetCommandParams p("ref");
1745 owner_->getDialogs()->createRef(p.getAsString());
1747 InsetCommandParams p;
1748 p.setFromString(argument);
1750 InsetRef * inset = new InsetRef(p, *buffer_);
1751 if (!insertInset(inset))
1754 updateInset(inset, true);
1758 case LFUN_BOOKMARK_SAVE:
1759 savePosition(strToUnsignedInt(argument));
1762 case LFUN_BOOKMARK_GOTO:
1763 restorePosition(strToUnsignedInt(argument));
1768 string label(argument);
1769 if (label.empty()) {
1771 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1773 label = inset->getContents();
1778 if (!label.empty()) {
1779 //bv_->savePosition(0);
1780 if (!bv_->gotoLabel(label))
1781 WriteAlert(_("Error"),
1782 _("Couldn't find this label"),
1783 _("in current document."));
1788 // --- Cursor Movements -----------------------------
1791 LyXText * lt = bv_->getLyXText();
1793 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1794 if (!lt->selection.mark())
1796 update(lt, BufferView::SELECT|BufferView::FITCUR);
1798 lt->CursorLeft(bv_, false);
1799 if (lt->cursor.pos() < lt->cursor.par()->size()
1800 && lt->cursor.par()->GetChar(lt->cursor.pos())
1801 == LyXParagraph::META_INSET
1802 && lt->cursor.par()->GetInset(lt->cursor.pos())
1803 && lt->cursor.par()->GetInset(lt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1804 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1805 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1808 LyXFont const font =
1809 lt->GetFont(buffer_,
1812 y = tmpinset->descent(bv_,font);
1814 tmpinset->Edit(bv_, 0, y, 0);
1818 lt->CursorRight(bv_, false);
1820 moveCursorUpdate(false);
1821 owner_->showState();
1827 // This is soooo ugly. Isn`t it possible to make
1828 // it simpler? (Lgb)
1829 LyXText * lt = bv_->getLyXText();
1830 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1831 if (!lt->selection.mark())
1833 update(lt, BufferView::SELECT|BufferView::FITCUR);
1834 LyXCursor const cur = lt->cursor;
1836 lt->CursorLeft(bv_, false);
1837 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1838 lt->cursor.pos() < lt->cursor.par()->size() &&
1839 (lt->cursor.par()->GetChar(lt->cursor.pos()) ==
1840 LyXParagraph::META_INSET) &&
1841 lt->cursor.par()->GetInset(lt->cursor.pos()) &&
1842 (lt->cursor.par()->GetInset(lt->cursor.pos())->Editable()
1843 == Inset::HIGHLY_EDITABLE))
1845 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1846 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1847 LyXFont const font = lt->GetFont(buffer_,
1851 : tmpinset->descent(bv_,font);
1854 tmpinset->width(bv_,font),
1859 lt->CursorRight(bv_, false);
1862 moveCursorUpdate(false);
1863 owner_->showState();
1869 LyXText * lt = bv_->getLyXText();
1871 if (!lt->selection.mark())
1873 update(lt, BufferView::UPDATE);
1876 moveCursorUpdate(false);
1877 owner_->showState();
1883 LyXText * lt = bv_->getLyXText();
1885 if (!lt->selection.mark())
1887 update(lt, BufferView::UPDATE);
1888 lt->CursorDown(bv_);
1890 moveCursorUpdate(false);
1891 owner_->showState();
1895 case LFUN_UP_PARAGRAPH:
1897 LyXText * lt = bv_->getLyXText();
1899 if (!lt->selection.mark())
1901 update(lt, BufferView::UPDATE);
1902 lt->CursorUpParagraph(bv_);
1904 moveCursorUpdate(false);
1905 owner_->showState();
1909 case LFUN_DOWN_PARAGRAPH:
1911 LyXText * lt = bv_->getLyXText();
1913 if (!lt->selection.mark())
1915 update(lt, BufferView::UPDATE);
1916 lt->CursorDownParagraph(bv_);
1918 moveCursorUpdate(false);
1919 owner_->showState();
1925 LyXText * lt = bv_->getLyXText();
1927 if (!lt->selection.mark())
1929 update(lt, BufferView::UPDATE);
1932 moveCursorUpdate(false);
1933 owner_->showState();
1939 LyXText * lt = bv_->getLyXText();
1941 if (!lt->selection.mark())
1943 update(lt, BufferView::UPDATE);
1946 moveCursorUpdate(false);
1947 owner_->showState();
1953 LyXText * lt = bv_->getLyXText();
1955 if (!lt->selection.mark())
1957 update(lt, BufferView::SELECT|BufferView::FITCUR);
1958 lt->CursorHome(bv_);
1960 moveCursorUpdate(false);
1961 owner_->showState();
1967 LyXText * lt = bv_->getLyXText();
1969 if (!lt->selection.mark())
1972 BufferView::SELECT|BufferView::FITCUR);
1975 moveCursorUpdate(false);
1976 owner_->showState();
1980 case LFUN_SHIFT_TAB:
1983 LyXText * lt = bv_->getLyXText();
1985 if (!lt->selection.mark())
1988 BufferView::SELECT|BufferView::FITCUR);
1991 moveCursorUpdate(false);
1992 owner_->showState();
1996 case LFUN_WORDRIGHT:
1998 LyXText * lt = bv_->getLyXText();
2000 if (!lt->selection.mark())
2002 update(lt, BufferView::SELECT|BufferView::FITCUR);
2003 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2004 lt->CursorLeftOneWord(bv_);
2006 lt->CursorRightOneWord(bv_);
2008 moveCursorUpdate(false);
2009 owner_->showState();
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2019 update(lt, BufferView::SELECT|BufferView::FITCUR);
2020 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2021 lt->CursorRightOneWord(bv_);
2023 lt->CursorLeftOneWord(bv_);
2025 moveCursorUpdate(false);
2026 owner_->showState();
2030 case LFUN_BEGINNINGBUF:
2032 LyXText * lt = bv_->getLyXText();
2034 if (!lt->selection.mark())
2037 BufferView::SELECT|BufferView::FITCUR);
2040 moveCursorUpdate(false);
2041 owner_->showState();
2047 LyXText * lt = bv_->getLyXText();
2049 if (!lt->selection.mark())
2052 BufferView::SELECT|BufferView::FITCUR);
2053 lt->CursorBottom(bv_);
2055 moveCursorUpdate(false);
2056 owner_->showState();
2060 /* cursor selection ---------------------------- */
2063 LyXText * lt = bv_->getLyXText();
2066 BufferView::SELECT|BufferView::FITCUR);
2067 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2068 lt->CursorLeft(bv_);
2070 lt->CursorRight(bv_);
2072 moveCursorUpdate(true);
2073 owner_->showState();
2079 LyXText * lt = bv_->getLyXText();
2082 BufferView::SELECT|BufferView::FITCUR);
2083 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2084 lt->CursorRight(bv_);
2086 lt->CursorLeft(bv_);
2088 moveCursorUpdate(true);
2089 owner_->showState();
2095 LyXText * lt = bv_->getLyXText();
2098 BufferView::SELECT|BufferView::FITCUR);
2101 moveCursorUpdate(true);
2102 owner_->showState();
2108 LyXText * lt = bv_->getLyXText();
2111 BufferView::SELECT|BufferView::FITCUR);
2112 lt->CursorDown(bv_);
2114 moveCursorUpdate(true);
2115 owner_->showState();
2119 case LFUN_UP_PARAGRAPHSEL:
2121 LyXText * lt = bv_->getLyXText();
2124 BufferView::SELECT|BufferView::FITCUR);
2125 lt->CursorUpParagraph(bv_);
2127 moveCursorUpdate(true);
2128 owner_->showState();
2132 case LFUN_DOWN_PARAGRAPHSEL:
2134 LyXText * lt = bv_->getLyXText();
2137 BufferView::SELECT|BufferView::FITCUR);
2138 lt->CursorDownParagraph(bv_);
2140 moveCursorUpdate(true);
2141 owner_->showState();
2147 LyXText * lt = bv_->getLyXText();
2149 update(lt, BufferView::SELECT|BufferView::FITCUR);
2152 moveCursorUpdate(true);
2153 owner_->showState();
2159 LyXText * lt = bv_->getLyXText();
2161 update(lt, BufferView::SELECT|BufferView::FITCUR);
2164 moveCursorUpdate(true);
2165 owner_->showState();
2171 LyXText * lt = bv_->getLyXText();
2173 update(lt, BufferView::SELECT|BufferView::FITCUR);
2174 lt->CursorHome(bv_);
2176 moveCursorUpdate(true);
2177 owner_->showState();
2183 LyXText * lt = bv_->getLyXText();
2185 update(lt, BufferView::SELECT|BufferView::FITCUR);
2188 moveCursorUpdate(true);
2189 owner_->showState();
2193 case LFUN_WORDRIGHTSEL:
2195 LyXText * lt = bv_->getLyXText();
2197 update(lt, BufferView::SELECT|BufferView::FITCUR);
2198 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2199 lt->CursorLeftOneWord(bv_);
2201 lt->CursorRightOneWord(bv_);
2203 moveCursorUpdate(true);
2204 owner_->showState();
2208 case LFUN_WORDLEFTSEL:
2210 LyXText * lt = bv_->getLyXText();
2212 update(lt, BufferView::SELECT|BufferView::FITCUR);
2213 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2214 lt->CursorRightOneWord(bv_);
2216 lt->CursorLeftOneWord(bv_);
2218 moveCursorUpdate(true);
2219 owner_->showState();
2223 case LFUN_BEGINNINGBUFSEL:
2225 LyXText * lt = bv_->getLyXText();
2227 if (lt->inset_owner)
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2232 moveCursorUpdate(true);
2233 owner_->showState();
2237 case LFUN_ENDBUFSEL:
2239 LyXText * lt = bv_->getLyXText();
2241 if (lt->inset_owner)
2244 BufferView::SELECT|BufferView::FITCUR);
2245 lt->CursorBottom(bv_);
2247 moveCursorUpdate(true);
2248 owner_->showState();
2252 // --- text changing commands ------------------------
2253 case LFUN_BREAKLINE:
2255 LyXText * lt = bv_->getLyXText();
2258 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2261 | BufferView::FITCUR
2262 | BufferView::CHANGE);
2263 moveCursorUpdate(false);
2267 case LFUN_PROTECTEDSPACE:
2269 LyXText * lt = bv_->getLyXText();
2271 LyXLayout const & style = textclasslist
2272 .Style(buffer_->params.textclass,
2273 lt->cursor.par()->GetLayout());
2275 if (style.free_spacing) {
2276 lt->InsertChar(bv_, ' ');
2279 | BufferView::FITCUR
2280 | BufferView::CHANGE);
2284 moveCursorUpdate(false);
2290 LyXText * lt = bv_->getLyXText();
2292 if (lt->selection.mark()) {
2296 | BufferView::FITCUR);
2297 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2300 lt->selection.mark(true);
2303 | BufferView::FITCUR);
2304 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2306 lt->selection.cursor = lt->cursor;
2312 LyXText * lt = bv_->getLyXText();
2314 if (!lt->selection.set()) {
2316 lt->selection.cursor = lt->cursor;
2319 | BufferView::FITCUR
2320 | BufferView::CHANGE);
2321 // It is possible to make it a lot faster still
2322 // just comment out the line below...
2327 moveCursorUpdate(false);
2328 owner_->showState();
2333 case LFUN_DELETE_SKIP:
2335 LyXText * lt = bv_->getLyXText();
2337 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2339 LyXCursor cursor = lt->cursor;
2341 if (!lt->selection.set()) {
2342 if (cursor.pos() == cursor.par()->size()) {
2343 lt->CursorRight(bv_);
2344 cursor = lt->cursor;
2345 if (cursor.pos() == 0
2346 && !(cursor.par()->params.spaceTop()
2347 == VSpace (VSpace::NONE))) {
2350 cursor.par()->params.lineTop(),
2351 cursor.par()->params.lineBottom(),
2352 cursor.par()->params.pagebreakTop(),
2353 cursor.par()->params.pagebreakBottom(),
2354 VSpace(VSpace::NONE),
2355 cursor.par()->params.spaceBottom(),
2356 cursor.par()->params.align(),
2357 cursor.par()->params.labelWidthString(), 0);
2358 lt->CursorLeft(bv_);
2361 | BufferView::FITCUR
2362 | BufferView::CHANGE);
2364 lt->CursorLeft(bv_);
2366 lt->selection.cursor = lt->cursor;
2369 | BufferView::FITCUR
2370 | BufferView::CHANGE);
2374 lt->selection.cursor = lt->cursor;
2377 | BufferView::FITCUR
2378 | BufferView::CHANGE);
2386 /* -------> Delete word forward. */
2387 case LFUN_DELETE_WORD_FORWARD:
2388 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2389 bv_->getLyXText()->DeleteWordForward(bv_);
2390 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2391 moveCursorUpdate(false);
2392 owner_->showState();
2395 /* -------> Delete word backward. */
2396 case LFUN_DELETE_WORD_BACKWARD:
2398 LyXText * lt = bv_->getLyXText();
2400 update(lt, BufferView::SELECT|BufferView::FITCUR);
2401 lt->DeleteWordBackward(bv_);
2404 | BufferView::FITCUR
2405 | BufferView::CHANGE);
2406 moveCursorUpdate(false);
2407 owner_->showState();
2411 /* -------> Kill to end of line. */
2412 case LFUN_DELETE_LINE_FORWARD:
2414 LyXText * lt = bv_->getLyXText();
2416 update(lt, BufferView::SELECT|BufferView::FITCUR);
2417 lt->DeleteLineForward(bv_);
2420 | BufferView::FITCUR
2421 | BufferView::CHANGE);
2422 moveCursorUpdate(false);
2426 /* -------> Set mark off. */
2429 LyXText * lt = bv_->getLyXText();
2432 update(lt, BufferView::SELECT|BufferView::FITCUR);
2433 lt->selection.cursor = lt->cursor;
2434 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2438 /* -------> Set mark on. */
2441 LyXText * lt = bv_->getLyXText();
2444 lt->selection.mark(true);
2445 update(lt, BufferView::SELECT|BufferView::FITCUR);
2446 lt->selection.cursor = lt->cursor;
2447 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2451 case LFUN_BACKSPACE:
2453 LyXText * lt = bv_->getLyXText();
2455 if (!lt->selection.set()) {
2456 if (owner_->getIntl()->getTrans().backspace()) {
2458 lt->selection.cursor = lt->cursor;
2461 | BufferView::FITCUR
2462 | BufferView::CHANGE);
2463 // It is possible to make it a lot faster still
2464 // just comment out the line below...
2470 owner_->showState();
2475 case LFUN_BACKSPACE_SKIP:
2477 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2478 LyXText * lt = bv_->getLyXText();
2480 LyXCursor cursor = lt->cursor;
2482 if (!lt->selection.set()) {
2483 if (cursor.pos() == 0
2484 && !(cursor.par()->params.spaceTop()
2485 == VSpace (VSpace::NONE))) {
2488 cursor.par()->params.lineTop(),
2489 cursor.par()->params.lineBottom(),
2490 cursor.par()->params.pagebreakTop(),
2491 cursor.par()->params.pagebreakBottom(),
2492 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2493 cursor.par()->params.align(),
2494 cursor.par()->params.labelWidthString(), 0);
2497 | BufferView::FITCUR
2498 | BufferView::CHANGE);
2501 lt->selection.cursor = cursor;
2504 | BufferView::FITCUR
2505 | BufferView::CHANGE);
2512 case LFUN_BREAKPARAGRAPH:
2514 LyXText * lt = bv_->getLyXText();
2517 lt->BreakParagraph(bv_, 0);
2520 | BufferView::FITCUR
2521 | BufferView::CHANGE);
2522 lt->selection.cursor = lt->cursor;
2524 owner_->showState();
2528 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2530 LyXText * lt = bv_->getLyXText();
2533 lt->BreakParagraph(bv_, 1);
2536 | BufferView::FITCUR
2537 | BufferView::CHANGE);
2538 lt->selection.cursor = lt->cursor;
2540 owner_->showState();
2544 case LFUN_BREAKPARAGRAPH_SKIP:
2546 // When at the beginning of a paragraph, remove
2547 // indentation and add a "defskip" at the top.
2548 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2549 LyXText * lt = bv_->getLyXText();
2551 LyXCursor cursor = lt->cursor;
2554 if (cursor.pos() == 0) {
2555 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2558 cursor.par()->params.lineTop(),
2559 cursor.par()->params.lineBottom(),
2560 cursor.par()->params.pagebreakTop(),
2561 cursor.par()->params.pagebreakBottom(),
2562 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2563 cursor.par()->params.align(),
2564 cursor.par()->params.labelWidthString(), 1);
2565 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2569 lt->BreakParagraph(bv_, 0);
2570 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2575 | BufferView::FITCUR
2576 | BufferView::CHANGE);
2577 lt->selection.cursor = cursor;
2579 owner_->showState();
2583 case LFUN_PARAGRAPH_SPACING:
2585 LyXText * lt = bv_->getLyXText();
2587 LyXParagraph * par = lt->cursor.par();
2588 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2589 float cur_value = 1.0;
2590 if (cur_spacing == Spacing::Other) {
2591 cur_value = par->params.spacing().getValue();
2594 istringstream istr(argument.c_str());
2598 Spacing::Space new_spacing = cur_spacing;
2599 float new_value = cur_value;
2601 lyxerr << "Missing argument to `paragraph-spacing'"
2603 } else if (tmp == "single") {
2604 new_spacing = Spacing::Single;
2605 } else if (tmp == "onehalf") {
2606 new_spacing = Spacing::Onehalf;
2607 } else if (tmp == "double") {
2608 new_spacing = Spacing::Double;
2609 } else if (tmp == "other") {
2610 new_spacing = Spacing::Other;
2613 lyxerr << "new_value = " << tmpval << endl;
2616 } else if (tmp == "default") {
2617 new_spacing = Spacing::Default;
2619 lyxerr << _("Unknown spacing argument: ")
2620 << argument << endl;
2622 if (cur_spacing != new_spacing || cur_value != new_value) {
2623 par->params.spacing(Spacing(new_spacing, new_value));
2624 lt->RedoParagraph(bv_);
2627 | BufferView::FITCUR
2628 | BufferView::CHANGE);
2634 bv_->insertCorrectQuote();
2640 InsetCommandParams p;
2641 if (action == LFUN_HTMLURL)
2642 p.setCmdName("htmlurl");
2644 p.setCmdName("url");
2645 owner_->getDialogs()->createUrl( p.getAsString() );
2649 case LFUN_INSERT_URL:
2651 InsetCommandParams p;
2652 p.setFromString( argument );
2654 InsetUrl * inset = new InsetUrl( p );
2655 if (!insertInset(inset))
2658 updateInset( inset, true );
2662 case LFUN_INSET_TEXT:
2664 InsetText * new_inset = new InsetText;
2665 if (insertInset(new_inset))
2666 new_inset->Edit(bv_, 0, 0, 0);
2672 case LFUN_INSET_ERT:
2674 InsetERT * new_inset = new InsetERT;
2675 if (insertInset(new_inset))
2676 new_inset->Edit(bv_, 0, 0, 0);
2682 case LFUN_INSET_EXTERNAL:
2684 InsetExternal * new_inset = new InsetExternal;
2685 if (insertInset(new_inset))
2686 new_inset->Edit(bv_, 0, 0, 0);
2692 case LFUN_INSET_FOOTNOTE:
2694 InsetFoot * new_inset = new InsetFoot;
2695 if (insertInset(new_inset))
2696 new_inset->Edit(bv_, 0, 0, 0);
2702 case LFUN_INSET_MARGINAL:
2704 InsetMarginal * new_inset = new InsetMarginal;
2705 if (insertInset(new_inset))
2706 new_inset->Edit(bv_, 0, 0, 0);
2712 case LFUN_INSET_MINIPAGE:
2714 InsetMinipage * new_inset = new InsetMinipage;
2715 if (insertInset(new_inset))
2716 new_inset->Edit(bv_, 0, 0, 0);
2722 case LFUN_INSET_FLOAT:
2724 // check if the float type exist
2725 if (floatList.typeExist(argument)) {
2726 InsetFloat * new_inset = new InsetFloat(argument);
2727 if (insertInset(new_inset))
2728 new_inset->Edit(bv_, 0, 0, 0);
2732 lyxerr << "Non-existant float type: "
2733 << argument << endl;
2739 case LFUN_INSET_WIDE_FLOAT:
2741 // check if the float type exist
2742 if (floatList.typeExist(argument)) {
2743 InsetFloat * new_inset = new InsetFloat(argument);
2744 new_inset->wide(true);
2745 if (insertInset(new_inset))
2746 new_inset->Edit(bv_, 0, 0, 0);
2750 lyxerr << "Non-existant float type: "
2751 << argument << endl;
2757 case LFUN_INSET_LIST:
2759 InsetList * new_inset = new InsetList;
2760 if (insertInset(new_inset))
2761 new_inset->Edit(bv_, 0, 0, 0);
2767 case LFUN_INSET_THEOREM:
2769 InsetTheorem * new_inset = new InsetTheorem;
2770 if (insertInset(new_inset))
2771 new_inset->Edit(bv_, 0, 0, 0);
2777 case LFUN_INSET_CAPTION:
2779 // Do we have a locking inset...
2780 if (bv_->theLockingInset()) {
2781 lyxerr << "Locking inset code: "
2782 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2783 InsetCaption * new_inset = new InsetCaption;
2784 new_inset->setOwner(bv_->theLockingInset());
2785 new_inset->SetAutoBreakRows(true);
2786 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2787 new_inset->SetFrameColor(0, LColor::captionframe);
2788 if (insertInset(new_inset))
2789 new_inset->Edit(bv_, 0, 0, 0);
2796 case LFUN_INSET_TABULAR:
2800 if (!argument.empty())
2801 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2802 InsetTabular * new_inset =
2803 new InsetTabular(*buffer_, r, c);
2805 bv_->getLyXText()->real_current_font.isRightToLeft();
2806 if (!open_new_inset(new_inset, rtl))
2811 // --- lyxserver commands ----------------------------
2813 case LFUN_CHARATCURSOR:
2815 LyXParagraph::size_type pos = bv_->getLyXText()->cursor.pos();
2816 if (pos < bv_->getLyXText()->cursor.par()->size())
2817 owner_->getLyXFunc()->setMessage(
2818 tostr(bv_->getLyXText()->cursor.par()->GetChar(pos)));
2820 owner_->getLyXFunc()->setMessage("EOF");
2825 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2827 + tostr(bv_->getLyXText()->cursor.y()));
2832 #warning Should check sscanf for errors (Lgb)
2835 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2836 bv_->getLyXText()->SetCursorFromCoordinates(bv_, x, y);
2840 case LFUN_GETLAYOUT:
2841 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2846 LyXFont & font = bv_->getLyXText()->current_font;
2847 if (font.shape() == LyXFont::ITALIC_SHAPE)
2848 owner_->getLyXFunc()->setMessage("E");
2849 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2850 owner_->getLyXFunc()->setMessage("N");
2852 owner_->getLyXFunc()->setMessage("0");
2859 LyXFont & font = bv_->getLyXText()->current_font;
2860 if (font.latex() == LyXFont::ON)
2861 owner_->getLyXFunc()->setMessage("L");
2863 owner_->getLyXFunc()->setMessage("0");
2867 // --- accented characters ---------------------------
2870 case LFUN_CIRCUMFLEX:
2880 case LFUN_SPECIAL_CARON:
2883 case LFUN_HUNG_UMLAUT:
2886 if (argument.empty()) {
2888 owner_->getLyXFunc()->handleKeyFunc(action);
2890 owner_->getLyXFunc()->handleKeyFunc(action);
2891 owner_->getIntl()->getTrans()
2892 .TranslateAndInsert(argument[0], bv_->getLyXText());
2893 update(bv_->getLyXText(),
2895 | BufferView::FITCUR
2896 | BufferView::CHANGE);
2900 // --- insert characters ----------------------------------------
2902 case LFUN_MATH_DELIM:
2903 case LFUN_INSERT_MATRIX:
2906 if (open_new_inset(new InsetFormula(false))) {
2907 bv_->theLockingInset()
2908 ->LocalDispatch(bv_, action, argument);
2914 case LFUN_INSERT_MATH:
2919 InsetFormula * f = new InsetFormula(true);
2921 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2925 case LFUN_MATH_DISPLAY:
2928 open_new_inset(new InsetFormula(true));
2932 case LFUN_MATH_MACRO:
2937 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2939 string const s1 = token(s, ' ', 1);
2940 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2941 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2947 case LFUN_MATH_MODE: // Open or create a math inset
2950 open_new_inset(new InsetFormula);
2951 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2955 case LFUN_CITATION_INSERT:
2957 InsetCommandParams p;
2958 p.setFromString( argument );
2960 InsetCitation * inset = new InsetCitation( p );
2961 if (!insertInset(inset))
2964 updateInset( inset, true );
2968 case LFUN_INSERT_BIBTEX:
2970 // ale970405+lasgoutt970425
2971 // The argument can be up to two tokens separated
2972 // by a space. The first one is the bibstyle.
2973 string const db = token(argument, ' ', 0);
2974 string bibstyle = token(argument, ' ', 1);
2975 if (bibstyle.empty())
2978 InsetCommandParams p( "BibTeX", db, bibstyle );
2979 InsetBibtex * inset = new InsetBibtex(p);
2981 if (insertInset(inset)) {
2982 if (argument.empty())
2983 inset->Edit(bv_, 0, 0, 0);
2989 // BibTeX data bases
2990 case LFUN_BIBDB_ADD:
2992 InsetBibtex * inset =
2993 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2995 inset->addDatabase(argument);
3000 case LFUN_BIBDB_DEL:
3002 InsetBibtex * inset =
3003 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3005 inset->delDatabase(argument);
3010 case LFUN_BIBTEX_STYLE:
3012 InsetBibtex * inset =
3013 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3015 inset->setOptions(argument);
3020 case LFUN_INDEX_CREATE:
3022 InsetCommandParams p( "index" );
3024 if (argument.empty()) {
3025 // Get the word immediately preceding the cursor
3026 LyXParagraph::size_type curpos =
3027 bv_->getLyXText()->cursor.pos() - 1;
3031 curstring = bv_->getLyXText()
3032 ->cursor.par()->GetWord(curpos);
3034 p.setContents( curstring );
3036 p.setContents( argument );
3039 owner_->getDialogs()->createIndex( p.getAsString() );
3043 case LFUN_INDEX_INSERT:
3045 InsetCommandParams p;
3046 p.setFromString(argument);
3047 InsetIndex * inset = new InsetIndex(p);
3049 if (!insertInset(inset))
3052 updateInset(inset, true);
3056 case LFUN_INDEX_INSERT_LAST:
3058 // Get word immediately preceding the cursor
3059 LyXParagraph::size_type curpos =
3060 bv_->getLyXText()->cursor.pos() - 1;
3061 // Can't do that at the beginning of a paragraph
3062 if (curpos < 0) break;
3064 string const curstring(bv_->getLyXText()
3065 ->cursor.par()->GetWord(curpos));
3067 InsetCommandParams p("index", curstring);
3068 InsetIndex * inset = new InsetIndex(p);
3070 if (!insertInset(inset))
3073 updateInset(inset, true);
3077 case LFUN_INDEX_PRINT:
3079 InsetCommandParams p("printindex");
3080 Inset * inset = new InsetPrintIndex(p);
3081 if (!insertInset(inset, "Standard"))
3086 case LFUN_PARENTINSERT:
3088 lyxerr << "arg " << argument << endl;
3089 InsetCommandParams p( "lyxparent", argument );
3090 Inset * inset = new InsetParent(p, *buffer_);
3091 if (!insertInset(inset, "Standard"))
3097 case LFUN_CHILD_INSERT:
3099 InsetInclude::Params p;
3100 p.cparams.setFromString(argument);
3101 p.masterFilename_ = buffer_->fileName();
3103 InsetInclude * inset = new InsetInclude(p);
3104 if (!insertInset(inset))
3107 updateInset(inset, true);
3108 bv_->owner()->getDialogs()->showInclude(inset);
3113 case LFUN_FLOAT_LIST:
3115 // We should check the argument for validity. (Lgb)
3116 Inset * inset = new InsetFloatList(argument);
3117 if (!insertInset(inset, "Standard"))
3122 case LFUN_INSERT_NOTE:
3126 case LFUN_SELFINSERT:
3128 if (argument.empty()) break;
3130 /* Automatically delete the currently selected
3131 * text and replace it with what is being
3132 * typed in now. Depends on lyxrc settings
3133 * "auto_region_delete", which defaults to
3136 LyXText * lt = bv_->getLyXText();
3138 if (lyxrc.auto_region_delete) {
3139 if (lt->selection.set()) {
3140 lt->CutSelection(bv_, false);
3143 | BufferView::FITCUR
3144 | BufferView::CHANGE);
3148 bv_->beforeChange(lt);
3149 LyXFont const old_font(lt->real_current_font);
3151 string::const_iterator cit = argument.begin();
3152 string::const_iterator end = argument.end();
3153 for (; cit != end; ++cit) {
3154 if (greek_kb_flag) {
3155 if (!math_insert_greek(bv_, *cit))
3156 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3158 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3163 | BufferView::FITCUR
3164 | BufferView::CHANGE);
3166 lt->selection.cursor = lt->cursor;
3167 moveCursorUpdate(false);
3169 // real_current_font.number can change so we need to
3170 // update the minibuffer
3171 if (old_font != lt->real_current_font)
3172 owner_->showState();
3177 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3179 time_t now_time_t = time(NULL);
3180 struct tm * now_tm = localtime(&now_time_t);
3181 setlocale(LC_TIME, "");
3183 if (!argument.empty())
3186 arg = lyxrc.date_insert_format;
3188 int const datetmp_len =
3189 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3191 LyXText * lt = bv_->getLyXText();
3193 for (int i = 0; i < datetmp_len; i++) {
3194 lt->InsertChar(bv_, datetmp[i]);
3197 | BufferView::FITCUR
3198 | BufferView::CHANGE);
3201 lt->selection.cursor = lt->cursor;
3202 moveCursorUpdate(false);
3206 case LFUN_UNKNOWN_ACTION:
3207 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3218 void BufferView::Pimpl::newline()
3221 LyXText * lt = bv_->getLyXText();
3225 | BufferView::FITCUR);
3226 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
3229 | BufferView::FITCUR
3230 | BufferView::CHANGE);
3235 void BufferView::Pimpl::hfill()
3238 LyXText * lt = bv_->getLyXText();
3242 | BufferView::FITCUR);
3243 lt->InsertChar(bv_, LyXParagraph::META_HFILL);
3246 | BufferView::FITCUR
3247 | BufferView::CHANGE);
3252 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3256 update(lt, BufferView::SELECT|BufferView::FITCUR);
3257 InsetSpecialChar * new_inset =
3258 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3259 if (!insertInset(new_inset))
3262 updateInset(new_inset, true);
3267 void BufferView::Pimpl::menuSeparator()
3270 LyXText * lt = bv_->getLyXText();
3273 update(lt, BufferView::SELECT|BufferView::FITCUR);
3274 InsetSpecialChar * new_inset =
3275 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3276 insertInset(new_inset);
3281 void BufferView::Pimpl::endOfSentenceDot()
3285 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3286 InsetSpecialChar * new_inset =
3287 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3288 insertInset(new_inset);
3293 void BufferView::Pimpl::ldots()
3297 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3298 InsetSpecialChar * new_inset =
3299 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3300 insertInset(new_inset);
3305 void BufferView::Pimpl::hyphenationPoint()
3309 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3310 InsetSpecialChar * new_inset =
3311 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3312 insertInset(new_inset);
3317 void BufferView::Pimpl::insertNote()
3319 InsetInfo * new_inset = new InsetInfo();
3320 insertInset(new_inset);
3321 new_inset->Edit(bv_, 0, 0, 0);
3325 // Open and lock an updatable inset
3326 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3328 LyXText * lt = bv_->getLyXText();
3332 if (!insertInset(new_inset)) {
3337 LyXFont & font = lt->real_current_font;
3338 new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
3340 new_inset->Edit(bv_, 0, 0, 0);
3345 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3347 // if we are in a locking inset we should try to insert the
3348 // inset there otherwise this is a illegal function now
3349 if (bv_->theLockingInset()) {
3350 if (bv_->theLockingInset()->InsertInsetAllowed(inset))
3351 return bv_->theLockingInset()->InsertInset(bv_, inset);
3355 // not quite sure if we want this...
3356 bv_->text->SetCursorParUndo(buffer_);
3357 bv_->text->FreezeUndo();
3359 beforeChange(bv_->text);
3360 if (!lout.empty()) {
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3362 bv_->text->BreakParagraph(bv_);
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3365 if (bv_->text->cursor.par()->size()) {
3366 bv_->text->CursorLeft(bv_);
3368 bv_->text->BreakParagraph(bv_);
3369 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3372 pair<bool, LyXTextClass::size_type> lres =
3373 textclasslist.NumberOfLayout(buffer_->params
3375 LyXTextClass::size_type lay;
3376 if (lres.first != false) {
3380 // layout not fount using default "Standard" (0)
3384 bv_->text->SetLayout(bv_, lay);
3386 bv_->text->SetParagraph(bv_, 0, 0,
3388 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3392 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3394 bv_->text->current_font.setLatex(LyXFont::OFF);
3397 bv_->text->InsertInset(bv_, inset);
3398 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3400 bv_->text->UnFreezeUndo();
3405 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3410 // first check for locking insets
3411 if (bv_->theLockingInset()) {
3412 if (bv_->theLockingInset() == inset) {
3413 if (bv_->text->UpdateInset(bv_, inset)) {
3416 buffer_->markDirty();
3421 } else if (bv_->theLockingInset()->UpdateInsetInInset(bv_, inset)) {
3422 if (bv_->text->UpdateInset(bv_,
3423 bv_->theLockingInset())) {
3426 buffer_->markDirty();
3434 // then check the current buffer
3437 update(bv_->text, BufferView::UPDATE);
3438 if (bv_->text->UpdateInset(bv_, inset)) {
3442 | BufferView::FITCUR
3443 | BufferView::CHANGE);
3445 update(bv_->text, SELECT);
3453 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3456 if (!available()) return;
3459 beforeChange(bv_->text);
3460 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3464 bv_->text->cursor.par()->GetChar(bv_->text->cursor.pos()) == LyXParagraph::META_INSET) {
3465 Inset const * inset = bv_->text->cursor.par()->GetInset(bv_->text->cursor.pos());
3466 if (find(codes.begin(), codes.end(), inset->LyxCode())
3469 static_cast<InsetCommand const *>(inset)->getContents();
3472 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3473 if (bv_->text->cursor.pos()
3474 || bv_->text->cursor.par() != bv_->text->FirstParagraph()) {
3475 LyXCursor tmp = bv_->text->cursor;
3476 bv_->text->cursor.par(bv_->text->FirstParagraph());
3477 bv_->text->cursor.pos(0);
3478 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3479 bv_->text->cursor = tmp;
3480 bv_->owner()->message(_("No more insets"));
3483 bv_->owner()->message(_("No more insets"));
3486 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3487 bv_->text->selection.cursor = bv_->text->cursor;
3491 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3493 gotoInset(vector<Inset::Code>(1, code), same_content);