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;
73 /* the selection possible is needed, that only motion events are
74 * used, where the bottom press event was on the drawing area too */
75 bool selection_possible = false;
77 extern BufferList bufferlist;
78 extern char ascii_type;
80 extern bool math_insert_greek(BufferView *, char);
81 extern void sigchldhandler(pid_t pid, int * status);
82 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
84 const unsigned int saved_positions_num = 20;
91 XSync(fl_get_display(), 0);
95 void SetXtermCursor(Window win)
98 static bool cursor_undefined = true;
99 if (cursor_undefined){
100 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
101 XFlush(fl_get_display());
102 cursor_undefined = false;
104 XDefineCursor(fl_get_display(), win, cursor);
105 XFlush(fl_get_display());
111 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
112 int xpos, int ypos, int width, int height)
113 : bv_(b), owner_(o), buffer_(0),
114 current_scrollbar_value(0), cursor_timeout(400),
115 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
118 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
119 workarea_.workAreaExpose
120 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
121 workarea_.workAreaEnter
122 .connect(slot(this, &BufferView::Pimpl::enterView));
123 workarea_.workAreaLeave
124 .connect(slot(this, &BufferView::Pimpl::leaveView));
125 workarea_.workAreaButtonPress
126 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
127 workarea_.workAreaButtonRelease
129 &BufferView::Pimpl::workAreaButtonRelease));
130 workarea_.workAreaMotionNotify
131 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
132 workarea_.workAreaDoubleClick
133 .connect(slot(this, &BufferView::Pimpl::doubleClick));
134 workarea_.workAreaTripleClick
135 .connect(slot(this, &BufferView::Pimpl::tripleClick));
136 workarea_.workAreaKeyPress
137 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
139 cursor_timeout.timeout.connect(slot(this,
140 &BufferView::Pimpl::cursorToggle));
141 //current_scrollbar_value = 0;
142 cursor_timeout.start();
143 workarea_.setFocus();
144 //using_xterm_cursor = false;
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 bool const ret = screen_->FitCursor(text, bv_);
262 void BufferView::Pimpl::redoCurrentBuffer()
264 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
265 if (buffer_ && bv_->text) {
267 owner_->updateLayoutChoice();
272 int BufferView::Pimpl::resizeCurrentBuffer()
274 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
276 LyXParagraph * par = 0;
277 LyXParagraph * selstartpar = 0;
278 LyXParagraph * selendpar = 0;
279 UpdatableInset * the_locking_inset = 0;
281 LyXParagraph::size_type pos = 0;
282 LyXParagraph::size_type selstartpos = 0;
283 LyXParagraph::size_type selendpos = 0;
284 bool selection = false;
285 bool mark_set = false;
289 owner_->message(_("Formatting document..."));
292 par = bv_->text->cursor.par();
293 pos = bv_->text->cursor.pos();
294 selstartpar = bv_->text->selection.start.par();
295 selstartpos = bv_->text->selection.start.pos();
296 selendpar = bv_->text->selection.end.par();
297 selendpos = bv_->text->selection.end.pos();
298 selection = bv_->text->selection.set();
299 mark_set = bv_->text->selection.mark();
300 the_locking_inset = bv_->text->the_locking_inset;
302 bv_->text = new LyXText(bv_);
304 // See if we have a text in TextCache that fits
305 // the new buffer_ with the correct width.
306 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
308 if (lyxerr.debugging()) {
309 lyxerr << "Found a LyXText that fits:\n";
310 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
312 // Set the owner of the newly found text
313 // bv_->text->owner(bv_);
314 if (lyxerr.debugging())
315 textcache.show(lyxerr, "resizeCurrentBuffer");
317 bv_->text = new LyXText(bv_);
323 bv_->text->selection.set(true);
324 /* at this point just to avoid the Delete-Empty-Paragraph
325 * Mechanism when setting the cursor */
326 bv_->text->selection.mark(mark_set);
328 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
329 bv_->text->selection.cursor = bv_->text->cursor;
330 bv_->text->SetCursor(bv_, selendpar, selendpos);
331 bv_->text->SetSelection(bv_);
332 bv_->text->SetCursor(bv_, par, pos);
334 bv_->text->SetCursor(bv_, par, pos);
335 bv_->text->selection.cursor = bv_->text->cursor;
336 bv_->text->selection.set(false);
338 // remake the inset locking
339 bv_->text->the_locking_inset = the_locking_inset;
341 bv_->text->first = screen_->TopCursorVisible(bv_->text);
342 buffer_->resizeInsets(bv_);
343 // this will scroll the screen such that the cursor becomes visible
350 /// get rid of the splash screen if it's not gone already
351 owner_->getDialogs()->destroySplash();
357 void BufferView::Pimpl::updateScreen()
359 // Regenerate the screen.
360 screen_.reset(new LyXScreen(workarea_));
364 void BufferView::Pimpl::updateScrollbar()
366 /* If the text is smaller than the working area, the scrollbar
367 * maximum must be the working area height. No scrolling will
371 workarea_.setScrollbar(0, 1.0);
375 static unsigned long max2 = 0;
376 static unsigned long height2 = 0;
378 unsigned long cbth = 0;
382 cbth = bv_->text->height;
383 cbsf = bv_->text->first;
386 // check if anything has changed.
388 height2 == workarea_.height() &&
389 current_scrollbar_value == cbsf)
392 height2 = workarea_.height();
393 current_scrollbar_value = cbsf;
395 if (cbth <= height2) { // text is smaller than screen
396 workarea_.setScrollbar(0, 1.0); // right?
400 long maximum_height = workarea_.height() * 3 / 4 + cbth;
404 double hfloat = workarea_.height();
405 double maxfloat = maximum_height;
407 float slider_size = 0.0;
408 int slider_value = value;
410 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
411 double const lineh = bv_->text->DefaultHeight();
412 workarea_.setScrollbarIncrements(lineh);
413 if (maxfloat > 0.0) {
414 if ((hfloat / maxfloat) * float(height2) < 3)
415 slider_size = 3.0/float(height2);
417 slider_size = hfloat / maxfloat;
419 slider_size = hfloat;
421 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
425 // Callback for scrollbar slider
426 void BufferView::Pimpl::scrollCB(double value)
428 if (!buffer_) return;
430 current_scrollbar_value = long(value);
431 if (current_scrollbar_value < 0)
432 current_scrollbar_value = 0;
437 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
439 if (!lyxrc.cursor_follows_scrollbar) {
444 LyXText * vbt = bv_->text;
446 int const height = vbt->DefaultHeight();
447 int const first = static_cast<int>((bv_->text->first + height));
448 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
450 if (vbt->cursor.y() < first)
451 vbt->SetCursorFromCoordinates(bv_, 0, first);
452 else if (vbt->cursor.y() > last)
453 vbt->SetCursorFromCoordinates(bv_, 0, last);
459 int BufferView::Pimpl::scrollUp(long time)
461 if (!buffer_) return 0;
462 if (!screen_.get()) return 0;
464 double value = workarea_.getScrollbarValue();
466 if (value == 0) return 0;
468 float add_value = (bv_->text->DefaultHeight()
469 + float(time) * float(time) * 0.125);
471 if (add_value > workarea_.height())
472 add_value = float(workarea_.height() -
473 bv_->text->DefaultHeight());
480 workarea_.setScrollbarValue(value);
487 int BufferView::Pimpl::scrollDown(long time)
489 if (!buffer_) return 0;
490 if (!screen_.get()) return 0;
492 double value = workarea_.getScrollbarValue();
493 pair<float, float> p = workarea_.getScrollbarBounds();
494 double max = p.second;
496 if (value == max) return 0;
498 float add_value = (bv_->text->DefaultHeight()
499 + float(time) * float(time) * 0.125);
501 if (add_value > workarea_.height())
502 add_value = float(workarea_.height() -
503 bv_->text->DefaultHeight());
510 workarea_.setScrollbarValue(value);
517 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
519 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
523 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
525 // Only use motion with button 1
526 if (!(state & Button1MotionMask))
529 if (!buffer_ || !screen_.get()) return;
531 // Check for inset locking
532 if (bv_->theLockingInset()) {
533 LyXCursor cursor = bv_->text->cursor;
534 LyXFont font = bv_->text->GetFont(bv_->buffer(),
535 cursor.par(), cursor.pos());
536 int width = bv_->theLockingInset()->width(bv_, font);
537 int inset_x = font.isVisibleRightToLeft()
538 ? cursor.x() - width : cursor.x();
539 int start_x = inset_x + bv_->theLockingInset()->scroll();
540 bv_->theLockingInset()->
541 InsetMotionNotify(bv_,
543 y - cursor.y() + bv_->text->first,
548 /* The test for not selection possible is needed, that only motion events are
549 * used, where the bottom press event was on the drawing area too */
550 if (!selection_possible)
553 screen_->HideCursor();
555 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
557 if (!bv_->text->selection.set())
558 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
560 bv_->text->SetSelection(bv_);
561 screen_->ToggleToggle(bv_->text, bv_);
562 fitCursor(bv_->text);
563 screen_->ShowCursor(bv_->text, bv_);
567 // Single-click on work area
568 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
574 if (!buffer_ || !screen_.get()) return;
576 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
578 // ok ok, this is a hack.
579 if (button == 4 || button == 5) {
582 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
585 scrollDown(lyxrc.wheel_jump);
590 if (bv_->theLockingInset()) {
591 // We are in inset locking mode
593 /* Check whether the inset was hit. If not reset mode,
594 otherwise give the event to the inset */
595 if (inset_hit == bv_->theLockingInset()) {
596 bv_->theLockingInset()->
597 InsetButtonPress(bv_,
602 bv_->unlockInset(bv_->theLockingInset());
607 selection_possible = true;
608 screen_->HideCursor();
610 int const screen_first = bv_->text->first;
612 // Middle button press pastes if we have a selection
613 bool paste_internally = false;
615 && bv_->text->selection.set()) {
616 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
617 paste_internally = true;
620 // Clear the selection
621 screen_->ToggleSelection(bv_->text, bv_);
622 bv_->text->ClearSelection(bv_);
623 bv_->text->FullRebreak(bv_);
624 screen_->Update(bv_->text, bv_);
627 // Single left click in math inset?
628 if ((inset_hit != 0) &&
629 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
630 // Highly editable inset, like math
631 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
632 selection_possible = false;
633 owner_->updateLayoutChoice();
634 owner_->message(inset->EditMessage());
635 inset->InsetButtonPress(bv_, xpos, ypos, button);
636 inset->Edit(bv_, xpos, ypos, button);
640 // Right click on a footnote flag opens float menu
642 selection_possible = false;
646 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
647 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
648 bv_->text->FinishUndo();
649 bv_->text->selection.cursor = bv_->text->cursor;
650 bv_->text->cursor.x_fix(bv_->text->cursor.x());
652 owner_->updateLayoutChoice();
653 if (fitCursor(bv_->text)) {
654 selection_possible = false;
657 // Insert primary selection with middle mouse
658 // if there is a local selection in the current buffer,
661 if (paste_internally)
662 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
664 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
666 selection_possible = false;
672 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
678 LyXText * text = bv_->getLyXText();
680 if (text->bv_owner && bv_->theLockingInset())
683 if (screen_.get() && button == 1) {
684 if (text->bv_owner) {
685 screen_->HideCursor();
686 screen_->ToggleSelection(text, bv_);
687 text->SelectWord(bv_);
688 screen_->ToggleSelection(text, bv_, false);
690 text->SelectWord(bv_);
692 /* This will fit the cursor on the screen
694 update(text, BufferView::SELECT|BufferView::FITCUR);
699 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
705 LyXText * text = bv_->getLyXText();
707 if (text->bv_owner && bv_->theLockingInset())
710 if (screen_.get() && (button == 1)) {
711 screen_->HideCursor();
712 screen_->ToggleSelection(text, bv_);
713 text->CursorHome(bv_);
714 text->selection.cursor = text->cursor;
715 text->CursorEnd(bv_);
716 text->SetSelection(bv_);
717 screen_->ToggleSelection(text, bv_, false);
718 /* This will fit the cursor on the screen
720 update(text, BufferView::SELECT|BufferView::FITCUR);
725 void BufferView::Pimpl::enterView()
727 if (active() && available()) {
728 SetXtermCursor(workarea_.getWin());
729 using_xterm_cursor = true;
734 void BufferView::Pimpl::leaveView()
736 if (using_xterm_cursor) {
737 XUndefineCursor(fl_get_display(), workarea_.getWin());
738 using_xterm_cursor = false;
743 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
746 if (!buffer_ || !screen_.get()) return;
748 // If we hit an inset, we have the inset coordinates in these
749 // and inset_hit points to the inset. If we do not hit an
750 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
751 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
753 if (bv_->theLockingInset()) {
754 // We are in inset locking mode.
756 /* LyX does a kind of work-area grabbing for insets.
757 Only a ButtonPress Event outside the inset will
758 force a InsetUnlock. */
759 bv_->theLockingInset()->
760 InsetButtonRelease(bv_, x, y, button);
764 selection_possible = false;
772 // Did we hit an editable inset?
774 // Inset like error, notes and figures
775 selection_possible = false;
777 // CHECK fix this proper in 0.13
779 // Following a ref shouldn't issue
780 // a push on the undo-stack
781 // anylonger, now that we have
782 // keybindings for following
783 // references and returning from
784 // references. IMHO though, it
785 // should be the inset's own business
786 // to push or not push on the undo
787 // stack. They don't *have* to
788 // alter the document...
790 // ...or maybe the SetCursorParUndo()
791 // below isn't necessary at all anylonger?
792 if (inset_hit->LyxCode() == Inset::REF_CODE) {
793 bv_->text->SetCursorParUndo(bv_->buffer());
796 owner_->message(inset_hit->EditMessage());
798 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
799 // Highly editable inset, like math
800 UpdatableInset *inset = (UpdatableInset *)inset_hit;
801 inset->InsetButtonRelease(bv_, x, y, button);
803 inset_hit->InsetButtonRelease(bv_, x, y, button);
804 inset_hit->Edit(bv_, x, y, button);
809 // check whether we want to open a float
813 if (bv_->text->cursor.pos() <
814 bv_->text->cursor.par()->size()) {
815 c = bv_->text->cursor.par()->
816 GetChar(bv_->text->cursor.pos());
818 if (bv_->text->cursor.pos() - 1 >= 0) {
819 c = bv_->text->cursor.par()->
820 GetChar(bv_->text->cursor.pos() - 1);
823 selection_possible = false;
828 // Maybe we want to edit a bibitem ale970302
829 if (bv_->text->cursor.par()->bibkey && x < 20 +
830 bibitemMaxWidth(bv_, textclasslist.
832 params.textclass).defaultfont())) {
833 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
841 * Returns an inset if inset was hit. 0 otherwise.
842 * If hit, the coordinates are changed relative to the inset.
843 * Otherwise coordinates are not changed, and false is returned.
845 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
846 unsigned int /* button */)
851 int y_tmp = y + text->first;
854 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
855 text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
858 if (cursor.pos() < cursor.par()->size()
859 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
860 && cursor.par()->GetInset(cursor.pos())
861 && cursor.par()->GetInset(cursor.pos())->Editable()) {
863 // Check whether the inset really was hit
864 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
865 LyXFont font = text->GetFont(bv_->buffer(),
866 cursor.par(), cursor.pos());
867 int const width = tmpinset->width(bv_, font);
868 int const inset_x = font.isVisibleRightToLeft()
869 ? cursor.x() - width : cursor.x();
870 int const start_x = inset_x + tmpinset->scroll();
871 int const end_x = inset_x + width;
873 if (x > start_x && x < end_x
874 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
875 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
876 text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
878 // The origin of an inset is on the baseline
879 y = y_tmp - (text->cursor.y());
884 if ((cursor.pos() - 1 >= 0) &&
885 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
886 (cursor.par()->GetInset(cursor.pos() - 1)) &&
887 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
888 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
889 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
891 int const width = tmpinset->width(bv_, font);
892 int const inset_x = font.isVisibleRightToLeft()
893 ? cursor.x() : cursor.x() - width;
894 int const start_x = inset_x + tmpinset->scroll();
895 int const end_x = inset_x + width;
897 if (x > start_x && x < end_x
898 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
899 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
901 if (move_cursor && (tmpinset != bv_->theLockingInset()))
903 text->SetCursor(bv_, cursor.par(),
904 cursor.pos() - 1, true);
906 // The origin of an inset is on the baseline
907 y = y_tmp - (text->cursor.y());
915 void BufferView::Pimpl::workAreaExpose()
917 static int work_area_width = 0;
918 static unsigned int work_area_height = 0;
920 bool const widthChange = workarea_.workWidth() != work_area_width;
921 bool const heightChange = workarea_.height() != work_area_height;
923 // update from work area
924 work_area_width = workarea_.workWidth();
925 work_area_height = workarea_.height();
928 // All buffers need a resize
931 // Remove all texts from the textcache
932 // This is not _really_ what we want to do. What
933 // we really want to do is to delete in textcache
934 // that does not have a BufferView with matching
935 // width, but as long as we have only one BufferView
936 // deleting all gives the same result.
937 if (lyxerr.debugging())
938 textcache.show(lyxerr, "Expose delete all");
940 } else if (heightChange) {
941 // Rebuild image of current screen
943 // fitCursor() ensures we don't jump back
944 // to the start of the document on vertical
946 fitCursor(bv_->text);
948 // The main window size has changed, repaint most stuff
950 } else if (screen_.get())
951 screen_->Redraw(bv_->text, bv_);
953 // Grey box when we don't have a buffer
957 // always make sure that the scrollbar is sane.
959 owner_->updateLayoutChoice();
964 void BufferView::Pimpl::update()
966 if (screen_.get()) screen_->Update(bv_->text, bv_);
969 // Values used when calling update:
971 // -2 - update, move sel_cursor if selection, fitcursor
972 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
973 // 0 - update, move sel_cursor if selection, fitcursor
974 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
975 // 3 - update, move sel_cursor if selection
978 // a simple redraw of the parts that need refresh
980 // move sel_cursor if selection -
981 // the text's sel_cursor is moved if there is selection is progress
984 // fitCursor() is called and the scrollbar updated
987 // the buffer is marked dirty.
996 // UPDATE_ONLY = UPDATE;
997 // UPDATE_SELECT = UPDATE | SELECT;
998 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
999 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1001 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1002 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1003 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1004 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1005 // update(3) -> update(1) -> update(1) -> update(SELECT)
1007 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1009 owner_->updateLayoutChoice();
1011 if (!text->selection.set() && (f & SELECT)) {
1012 text->selection.cursor = text->cursor;
1015 text->FullRebreak(bv_);
1017 if (text->inset_owner) {
1018 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1019 bv_->updateInset(text->inset_owner, true);
1028 buffer_->markDirty();
1033 // Callback for cursor timer
1034 void BufferView::Pimpl::cursorToggle()
1036 // Quite a nice place for asyncron Inset updating, isn't it?
1037 // Actually no! This is run even if no buffer exist... so (Lgb)
1039 cursor_timeout.restart();
1044 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1045 if (pid == -1) // error find out what is wrong
1046 ; // ignore it for now.
1048 sigchldhandler(pid, &status);
1050 updatelist.update(bv_);
1052 if (!screen_.get()) {
1053 cursor_timeout.restart();
1057 if (!bv_->theLockingInset()) {
1058 screen_->CursorToggle(bv_->text, bv_);
1060 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1063 cursor_timeout.restart();
1067 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1069 if (!text->cursor.row()->previous())
1072 int y = text->first;
1073 if (text->inset_owner)
1074 y += bv_->text->first;
1075 Row * cursorrow = text->cursor.row();
1076 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1077 bv_->text->FinishUndo();
1078 // This is to allow jumping over large insets
1079 if ((cursorrow == text->cursor.row()))
1080 text->CursorUp(bv_);
1082 if (text->inset_owner ||
1083 text->cursor.row()->height() < workarea_.height())
1084 screen_->Draw(bv_->text, bv_,
1086 - text->cursor.row()->baseline()
1087 + text->cursor.row()->height()
1088 - workarea_.height() + 1 );
1093 void BufferView::Pimpl::cursorNext(LyXText * text)
1095 if (!text->cursor.row()->next())
1098 int y = text->first + workarea_.height();
1099 // if (text->inset_owner)
1100 // y += bv_->text->first;
1101 text->GetRowNearY(y);
1103 Row * cursorrow = text->cursor.row();
1104 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1105 bv_->text->FinishUndo();
1106 // This is to allow jumping over large insets
1107 if ((cursorrow == bv_->text->cursor.row()))
1108 text->CursorDown(bv_);
1110 if (text->inset_owner ||
1111 text->cursor.row()->height() < workarea_.height())
1112 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1113 text->cursor.row()->baseline());
1118 bool BufferView::Pimpl::available() const
1120 if (buffer_ && bv_->text) return true;
1125 void BufferView::Pimpl::beforeChange(LyXText * text)
1128 text->ClearSelection(bv_);
1132 void BufferView::Pimpl::savePosition(unsigned int i)
1134 if (i >= saved_positions_num)
1136 saved_positions[i] = Position(buffer_->fileName(),
1137 bv_->text->cursor.par()->id(),
1138 bv_->text->cursor.pos());
1140 string const str = _("Saved bookmark") + ' ' + tostr(i);
1141 owner_->message(str);
1146 void BufferView::Pimpl::restorePosition(unsigned int i)
1148 if (i >= saved_positions_num)
1151 string const fname = saved_positions[i].filename;
1153 beforeChange(bv_->text);
1155 if (fname != buffer_->fileName()) {
1156 Buffer * b = bufferlist.exists(fname) ?
1157 bufferlist.getBuffer(fname) :
1158 bufferlist.loadLyXFile(fname); // don't ask, just load it
1159 if (b != 0 ) buffer(b);
1162 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1166 bv_->text->SetCursor(bv_, par,
1167 min(par->size(), saved_positions[i].par_pos));
1169 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1171 string const str = _("Moved to bookmark") + ' ' + tostr(i);
1172 owner_->message(str);
1177 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1179 if (i >= saved_positions_num)
1182 return !saved_positions[i].filename.empty();
1186 void BufferView::Pimpl::setState()
1188 if (!lyxrc.rtl_support)
1191 LyXText * text = bv_->getLyXText();
1192 if (text->real_current_font.isRightToLeft() &&
1193 text->real_current_font.latex() != LyXFont::ON) {
1194 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1195 owner_->getIntl()->KeyMapSec();
1197 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1198 owner_->getIntl()->KeyMapPrim();
1203 void BufferView::Pimpl::insetSleep()
1205 if (bv_->theLockingInset() && !bv_->inset_slept) {
1206 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1207 bv_->theLockingInset()->InsetUnlock(bv_);
1208 bv_->inset_slept = true;
1213 void BufferView::Pimpl::insetWakeup()
1215 if (bv_->theLockingInset() && bv_->inset_slept) {
1216 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1217 bv_->inset_slept = false;
1222 void BufferView::Pimpl::insetUnlock()
1224 if (bv_->theLockingInset()) {
1225 if (!bv_->inset_slept)
1226 bv_->theLockingInset()->InsetUnlock(bv_);
1227 bv_->theLockingInset(0);
1228 bv_->text->FinishUndo();
1229 bv_->inset_slept = false;
1234 bool BufferView::Pimpl::focus() const
1236 return workarea_.hasFocus();
1240 void BufferView::Pimpl::focus(bool f)
1242 if (f) workarea_.setFocus();
1246 bool BufferView::Pimpl::active() const
1248 return workarea_.active();
1252 bool BufferView::Pimpl::belowMouse() const
1254 return workarea_.belowMouse();
1258 void BufferView::Pimpl::showCursor()
1261 screen_->ShowCursor(bv_->text, bv_);
1265 void BufferView::Pimpl::hideCursor()
1268 screen_->HideCursor();
1272 void BufferView::Pimpl::toggleSelection(bool b)
1275 screen_->ToggleSelection(bv_->text, bv_, b);
1279 void BufferView::Pimpl::toggleToggle()
1282 screen_->ToggleToggle(bv_->text, bv_);
1286 void BufferView::Pimpl::center()
1288 beforeChange(bv_->text);
1289 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1290 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1292 screen_->Draw(bv_->text, bv_, 0);
1294 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1299 void BufferView::Pimpl::pasteClipboard(bool asPara)
1301 if (!buffer_) return;
1303 screen_->HideCursor();
1304 beforeChange(bv_->text);
1306 string const clip(workarea_.getClipboard());
1308 if (clip.empty()) return;
1311 bv_->text->InsertStringB(bv_, clip);
1313 bv_->text->InsertStringA(bv_, clip);
1315 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1319 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1321 workarea_.putClipboard(stuff);
1326 * Dispatch functions for actions which can be valid for BufferView->text
1327 * and/or InsetText->text!!!
1332 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1334 LyXText * lt = bv_->getLyXText();
1336 if (selecting || lt->selection.mark()) {
1337 lt->SetSelection(bv_);
1339 bv_->toggleToggle();
1341 update(lt, BufferView::SELECT|BufferView::FITCUR);
1344 /* ---> Everytime the cursor is moved, show the current font state. */
1345 // should this too me moved out of this func?
1346 //owner->showState();
1351 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1353 LyXCursor cursor = bv_->getLyXText()->cursor;
1354 Buffer::inset_iterator it =
1355 find_if(Buffer::inset_iterator(
1356 cursor.par(), cursor.pos()),
1357 buffer_->inset_iterator_end(),
1358 lyx::compare_memfun(&Inset::LyxCode, code)
1360 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1364 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1366 string filename = filen;
1368 if (filename.empty()) {
1369 // Launch a file browser
1370 string initpath = lyxrc.document_path;
1373 string const trypath = owner_->buffer()->filepath;
1374 // If directory is writeable, use this as default.
1375 if (IsDirWriteable(trypath) == 1)
1379 FileDialog fileDlg(bv_->owner(),
1380 _("Select LyX document to insert"),
1382 make_pair(string(_("Documents")),
1383 string(lyxrc.document_path)),
1384 make_pair(string(_("Examples")),
1385 string(AddPath(system_lyxdir, "examples"))));
1387 FileDialog::Result result =
1388 fileDlg.Select(initpath,
1389 _("*.lyx| LyX Documents (*.lyx)"));
1391 if (result.first == FileDialog::Later)
1394 filename = result.second;
1396 // check selected filename
1397 if (filename.empty()) {
1398 owner_->message(_("Canceled."));
1403 // get absolute path of file and make sure the filename ends
1405 filename = MakeAbsPath(filename);
1406 if (!IsLyXFilename(filename))
1410 string const s1 = _("Inserting document") + ' '
1411 + MakeDisplayPath(filename) + " ...";
1412 owner_->message(s1);
1413 bool const res = bv_->insertLyXFile(filename);
1415 string const str = _("Document") + ' '
1416 + MakeDisplayPath(filename) + ' ' + _("inserted.");
1417 owner_->message(str);
1419 string const str = _("Could not insert document") + ' '
1420 + MakeDisplayPath(filename);
1421 owner_->message(str);
1426 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1429 // --- Misc -------------------------------------------
1433 LyXText * lt = bv_->getLyXText();
1434 lt->toggleAppendix(bv_);
1437 | BufferView::FITCUR
1438 | BufferView::CHANGE);
1443 case LFUN_TOC_INSERT:
1445 InsetCommandParams p;
1446 p.setCmdName("tableofcontents");
1447 Inset * inset = new InsetTOC(p);
1448 if (!bv_->insertInset(inset, "Standard", true))
1453 case LFUN_TABULAR_FEATURE:
1454 case LFUN_SCROLL_INSET:
1455 // this is not handled here as this funktion is only aktive
1456 // if we have a locking_inset and that one is (or contains)
1460 case LFUN_INSET_GRAPHICS:
1462 Inset * new_inset = new InsetGraphics;
1463 if (!bv_->insertInset(new_inset)) {
1466 // this is need because you don't use a inset->Edit()
1467 bv_->updateInset(new_inset, true);
1468 new_inset->Edit(bv_, 0, 0, 0);
1478 case LFUN_PASTESELECTION:
1480 bool asPara = false;
1481 if (argument == "paragraph") asPara = true;
1482 pasteClipboard(asPara);
1494 case LFUN_LAYOUT_COPY:
1495 bv_->copyEnvironment();
1498 case LFUN_LAYOUT_PASTE:
1499 bv_->pasteEnvironment();
1503 case LFUN_GOTOERROR:
1504 bv_->gotoInset(Inset::ERROR_CODE, false);
1508 bv_->gotoInset(Inset::IGNORE_CODE, false);
1511 case LFUN_REFERENCE_GOTO:
1513 vector<Inset::Code> tmp;
1514 tmp.push_back(Inset::LABEL_CODE);
1515 tmp.push_back(Inset::REF_CODE);
1516 bv_->gotoInset(tmp, true);
1520 case LFUN_HYPHENATION:
1528 case LFUN_END_OF_SENTENCE:
1532 case LFUN_MENU_SEPARATOR:
1541 changeDepth(bv_, bv_->getLyXText(), 0);
1544 case LFUN_DEPTH_MIN:
1545 changeDepth(bv_, bv_->getLyXText(), -1);
1548 case LFUN_DEPTH_PLUS:
1549 changeDepth(bv_, bv_->getLyXText(), 1);
1553 owner_->getDialogs()->setUserFreeFont();
1559 owner_->showState();
1562 case LFUN_FILE_INSERT:
1564 MenuInsertLyXFile(argument);
1568 case LFUN_FILE_INSERT_ASCII_PARA:
1569 InsertAsciiFile(bv_, argument, true);
1572 case LFUN_FILE_INSERT_ASCII:
1573 InsertAsciiFile(bv_, argument, false);
1578 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1579 << argument << endl;
1581 // Derive layout number from given argument (string)
1582 // and current buffer's textclass (number). */
1583 LyXTextClassList::ClassList::size_type tclass =
1584 buffer_->params.textclass;
1585 pair <bool, LyXTextClass::size_type> layout =
1586 textclasslist.NumberOfLayout(tclass, argument);
1588 // If the entry is obsolete, use the new one instead.
1590 string obs = textclasslist.Style(tclass,layout.second)
1594 textclasslist.NumberOfLayout(tclass, obs);
1597 // see if we found the layout number:
1598 if (!layout.first) {
1599 owner_->getLyXFunc()->setErrorMessage(
1600 string(N_("Layout ")) + argument +
1605 if (current_layout != layout.second) {
1606 LyXText * lt = bv_->getLyXText();
1608 current_layout = layout.second;
1611 | BufferView::FITCUR);
1612 lt->SetLayout(bv_, layout.second);
1613 owner_->setLayout(layout.second);
1616 | BufferView::FITCUR
1617 | BufferView::CHANGE);
1624 Lang(bv_, argument);
1626 owner_->showState();
1631 owner_->showState();
1636 owner_->showState();
1641 owner_->showState();
1646 owner_->showState();
1651 owner_->showState();
1656 owner_->showState();
1661 owner_->showState();
1664 case LFUN_UNDERLINE:
1666 owner_->showState();
1669 case LFUN_FONT_SIZE:
1670 FontSize(bv_, argument);
1671 owner_->showState();
1674 case LFUN_FONT_STATE:
1675 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1678 case LFUN_UPCASE_WORD:
1680 LyXText * lt = bv_->getLyXText();
1684 | BufferView::FITCUR);
1685 lt->ChangeWordCase(bv_, LyXText::text_uppercase);
1686 if (lt->inset_owner)
1687 bv_->updateInset(lt->inset_owner, true);
1690 | BufferView::FITCUR
1691 | BufferView::CHANGE);
1695 case LFUN_LOWCASE_WORD:
1697 LyXText * lt = bv_->getLyXText();
1699 update(lt, BufferView::SELECT|BufferView::FITCUR);
1700 lt->ChangeWordCase(bv_, LyXText::text_lowercase);
1701 if (lt->inset_owner)
1702 bv_->updateInset(lt->inset_owner, true);
1705 | BufferView::FITCUR
1706 | BufferView::CHANGE);
1710 case LFUN_CAPITALIZE_WORD:
1712 LyXText * lt = bv_->getLyXText();
1714 update(lt, BufferView::SELECT|BufferView::FITCUR);
1715 lt->ChangeWordCase(bv_,
1716 LyXText::text_capitalization);
1717 if (lt->inset_owner)
1718 bv_->updateInset(lt->inset_owner, true);
1721 | BufferView::FITCUR
1722 | BufferView::CHANGE);
1726 case LFUN_TRANSPOSE_CHARS:
1728 LyXText * lt = bv_->getLyXText();
1730 update(lt, BufferView::SELECT|BufferView::FITCUR);
1731 lt->TransposeChars(*bv_);
1732 if (lt->inset_owner)
1733 bv_->updateInset(lt->inset_owner, true);
1736 | BufferView::FITCUR
1737 | BufferView::CHANGE);
1742 case LFUN_INSERT_LABEL:
1743 MenuInsertLabel(bv_, argument);
1746 case LFUN_REF_INSERT:
1747 if (argument.empty()) {
1748 InsetCommandParams p("ref");
1749 owner_->getDialogs()->createRef(p.getAsString());
1751 InsetCommandParams p;
1752 p.setFromString(argument);
1754 InsetRef * inset = new InsetRef(p, *buffer_);
1755 if (!bv_->insertInset(inset))
1758 bv_->updateInset(inset, true);
1762 case LFUN_BOOKMARK_SAVE:
1763 savePosition(strToUnsignedInt(argument));
1766 case LFUN_BOOKMARK_GOTO:
1767 restorePosition(strToUnsignedInt(argument));
1772 string label(argument);
1773 if (label.empty()) {
1775 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1777 label = inset->getContents();
1782 if (!label.empty()) {
1783 //bv_->savePosition(0);
1784 if (!bv_->gotoLabel(label))
1785 WriteAlert(_("Error"),
1786 _("Couldn't find this label"),
1787 _("in current document."));
1792 // --- Cursor Movements -----------------------------
1795 LyXText * lt = bv_->getLyXText();
1797 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1798 if (!lt->selection.mark())
1800 update(lt, BufferView::SELECT|BufferView::FITCUR);
1802 lt->CursorLeft(bv_, false);
1803 if (lt->cursor.pos() < lt->cursor.par()->size()
1804 && lt->cursor.par()->GetChar(lt->cursor.pos())
1805 == LyXParagraph::META_INSET
1806 && lt->cursor.par()->GetInset(lt->cursor.pos())
1807 && lt->cursor.par()->GetInset(lt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1808 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1809 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1812 LyXFont const font =
1813 lt->GetFont(buffer_,
1816 y = tmpinset->descent(bv_,font);
1818 tmpinset->Edit(bv_, 0, y, 0);
1822 lt->CursorRight(bv_, false);
1824 moveCursorUpdate(false);
1825 owner_->showState();
1831 // This is soooo ugly. Isn`t it possible to make
1832 // it simpler? (Lgb)
1833 LyXText * lt = bv_->getLyXText();
1834 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1835 if (!lt->selection.mark())
1837 update(lt, BufferView::SELECT|BufferView::FITCUR);
1838 LyXCursor const cur = lt->cursor;
1840 lt->CursorLeft(bv_, false);
1841 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1842 lt->cursor.pos() < lt->cursor.par()->size() &&
1843 (lt->cursor.par()->GetChar(lt->cursor.pos()) ==
1844 LyXParagraph::META_INSET) &&
1845 lt->cursor.par()->GetInset(lt->cursor.pos()) &&
1846 (lt->cursor.par()->GetInset(lt->cursor.pos())->Editable()
1847 == Inset::HIGHLY_EDITABLE))
1849 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1850 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1851 LyXFont const font = lt->GetFont(buffer_,
1855 : tmpinset->descent(bv_,font);
1858 tmpinset->width(bv_,font),
1863 lt->CursorRight(bv_, false);
1866 moveCursorUpdate(false);
1867 owner_->showState();
1873 LyXText * lt = bv_->getLyXText();
1875 if (!lt->selection.mark())
1877 update(lt, BufferView::UPDATE);
1880 moveCursorUpdate(false);
1881 owner_->showState();
1887 LyXText * lt = bv_->getLyXText();
1889 if (!lt->selection.mark())
1891 update(lt, BufferView::UPDATE);
1892 lt->CursorDown(bv_);
1894 moveCursorUpdate(false);
1895 owner_->showState();
1899 case LFUN_UP_PARAGRAPH:
1901 LyXText * lt = bv_->getLyXText();
1903 if (!lt->selection.mark())
1905 update(lt, BufferView::UPDATE);
1906 lt->CursorUpParagraph(bv_);
1908 moveCursorUpdate(false);
1909 owner_->showState();
1913 case LFUN_DOWN_PARAGRAPH:
1915 LyXText * lt = bv_->getLyXText();
1917 if (!lt->selection.mark())
1919 update(lt, BufferView::UPDATE);
1920 lt->CursorDownParagraph(bv_);
1922 moveCursorUpdate(false);
1923 owner_->showState();
1929 LyXText * lt = bv_->getLyXText();
1931 if (!lt->selection.mark())
1933 update(lt, BufferView::UPDATE);
1936 moveCursorUpdate(false);
1937 owner_->showState();
1943 LyXText * lt = bv_->getLyXText();
1945 if (!lt->selection.mark())
1947 update(lt, BufferView::UPDATE);
1950 moveCursorUpdate(false);
1951 owner_->showState();
1957 LyXText * lt = bv_->getLyXText();
1959 if (!lt->selection.mark())
1961 update(lt, BufferView::SELECT|BufferView::FITCUR);
1962 lt->CursorHome(bv_);
1964 moveCursorUpdate(false);
1965 owner_->showState();
1971 LyXText * lt = bv_->getLyXText();
1973 if (!lt->selection.mark())
1976 BufferView::SELECT|BufferView::FITCUR);
1979 moveCursorUpdate(false);
1980 owner_->showState();
1984 case LFUN_SHIFT_TAB:
1987 LyXText * lt = bv_->getLyXText();
1989 if (!lt->selection.mark())
1992 BufferView::SELECT|BufferView::FITCUR);
1995 moveCursorUpdate(false);
1996 owner_->showState();
2000 case LFUN_WORDRIGHT:
2002 LyXText * lt = bv_->getLyXText();
2004 if (!lt->selection.mark())
2006 update(lt, BufferView::SELECT|BufferView::FITCUR);
2007 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2008 lt->CursorLeftOneWord(bv_);
2010 lt->CursorRightOneWord(bv_);
2012 moveCursorUpdate(false);
2013 owner_->showState();
2019 LyXText * lt = bv_->getLyXText();
2021 if (!lt->selection.mark())
2023 update(lt, BufferView::SELECT|BufferView::FITCUR);
2024 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2025 lt->CursorRightOneWord(bv_);
2027 lt->CursorLeftOneWord(bv_);
2029 moveCursorUpdate(false);
2030 owner_->showState();
2034 case LFUN_BEGINNINGBUF:
2036 LyXText * lt = bv_->getLyXText();
2038 if (!lt->selection.mark())
2041 BufferView::SELECT|BufferView::FITCUR);
2044 moveCursorUpdate(false);
2045 owner_->showState();
2051 LyXText * lt = bv_->getLyXText();
2053 if (!lt->selection.mark())
2056 BufferView::SELECT|BufferView::FITCUR);
2057 lt->CursorBottom(bv_);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2064 /* cursor selection ---------------------------- */
2067 LyXText * lt = bv_->getLyXText();
2070 BufferView::SELECT|BufferView::FITCUR);
2071 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2072 lt->CursorLeft(bv_);
2074 lt->CursorRight(bv_);
2076 moveCursorUpdate(true);
2077 owner_->showState();
2083 LyXText * lt = bv_->getLyXText();
2086 BufferView::SELECT|BufferView::FITCUR);
2087 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2088 lt->CursorRight(bv_);
2090 lt->CursorLeft(bv_);
2092 moveCursorUpdate(true);
2093 owner_->showState();
2099 LyXText * lt = bv_->getLyXText();
2102 BufferView::SELECT|BufferView::FITCUR);
2105 moveCursorUpdate(true);
2106 owner_->showState();
2112 LyXText * lt = bv_->getLyXText();
2115 BufferView::SELECT|BufferView::FITCUR);
2116 lt->CursorDown(bv_);
2118 moveCursorUpdate(true);
2119 owner_->showState();
2123 case LFUN_UP_PARAGRAPHSEL:
2125 LyXText * lt = bv_->getLyXText();
2128 BufferView::SELECT|BufferView::FITCUR);
2129 lt->CursorUpParagraph(bv_);
2131 moveCursorUpdate(true);
2132 owner_->showState();
2136 case LFUN_DOWN_PARAGRAPHSEL:
2138 LyXText * lt = bv_->getLyXText();
2141 BufferView::SELECT|BufferView::FITCUR);
2142 lt->CursorDownParagraph(bv_);
2144 moveCursorUpdate(true);
2145 owner_->showState();
2151 LyXText * lt = bv_->getLyXText();
2153 update(lt, BufferView::SELECT|BufferView::FITCUR);
2156 moveCursorUpdate(true);
2157 owner_->showState();
2163 LyXText * lt = bv_->getLyXText();
2165 update(lt, BufferView::SELECT|BufferView::FITCUR);
2168 moveCursorUpdate(true);
2169 owner_->showState();
2175 LyXText * lt = bv_->getLyXText();
2177 update(lt, BufferView::SELECT|BufferView::FITCUR);
2178 lt->CursorHome(bv_);
2180 moveCursorUpdate(true);
2181 owner_->showState();
2187 LyXText * lt = bv_->getLyXText();
2189 update(lt, BufferView::SELECT|BufferView::FITCUR);
2192 moveCursorUpdate(true);
2193 owner_->showState();
2197 case LFUN_WORDRIGHTSEL:
2199 LyXText * lt = bv_->getLyXText();
2201 update(lt, BufferView::SELECT|BufferView::FITCUR);
2202 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2203 lt->CursorLeftOneWord(bv_);
2205 lt->CursorRightOneWord(bv_);
2207 moveCursorUpdate(true);
2208 owner_->showState();
2212 case LFUN_WORDLEFTSEL:
2214 LyXText * lt = bv_->getLyXText();
2216 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2218 lt->CursorRightOneWord(bv_);
2220 lt->CursorLeftOneWord(bv_);
2222 moveCursorUpdate(true);
2223 owner_->showState();
2227 case LFUN_BEGINNINGBUFSEL:
2229 LyXText * lt = bv_->getLyXText();
2231 if (lt->inset_owner)
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2236 moveCursorUpdate(true);
2237 owner_->showState();
2241 case LFUN_ENDBUFSEL:
2243 LyXText * lt = bv_->getLyXText();
2245 if (lt->inset_owner)
2248 BufferView::SELECT|BufferView::FITCUR);
2249 lt->CursorBottom(bv_);
2251 moveCursorUpdate(true);
2252 owner_->showState();
2256 // --- text changing commands ------------------------
2257 case LFUN_BREAKLINE:
2259 LyXText * lt = bv_->getLyXText();
2262 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2265 | BufferView::FITCUR
2266 | BufferView::CHANGE);
2267 moveCursorUpdate(false);
2271 case LFUN_PROTECTEDSPACE:
2273 LyXText * lt = bv_->getLyXText();
2275 LyXLayout const & style = textclasslist
2276 .Style(buffer_->params.textclass,
2277 lt->cursor.par()->GetLayout());
2279 if (style.free_spacing) {
2280 lt->InsertChar(bv_, ' ');
2283 | BufferView::FITCUR
2284 | BufferView::CHANGE);
2288 moveCursorUpdate(false);
2294 LyXText * lt = bv_->getLyXText();
2296 if (lt->selection.mark()) {
2300 | BufferView::FITCUR);
2301 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2304 lt->selection.mark(true);
2307 | BufferView::FITCUR);
2308 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2310 lt->selection.cursor = lt->cursor;
2316 LyXText * lt = bv_->getLyXText();
2318 if (!lt->selection.set()) {
2320 lt->selection.cursor = lt->cursor;
2323 | BufferView::FITCUR
2324 | BufferView::CHANGE);
2325 // It is possible to make it a lot faster still
2326 // just comment out the line below...
2331 moveCursorUpdate(false);
2332 owner_->showState();
2337 case LFUN_DELETE_SKIP:
2339 LyXText * lt = bv_->getLyXText();
2341 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2343 LyXCursor cursor = lt->cursor;
2345 if (!lt->selection.set()) {
2346 if (cursor.pos() == cursor.par()->size()) {
2347 lt->CursorRight(bv_);
2348 cursor = lt->cursor;
2349 if (cursor.pos() == 0
2350 && !(cursor.par()->params.spaceTop()
2351 == VSpace (VSpace::NONE))) {
2354 cursor.par()->params.lineTop(),
2355 cursor.par()->params.lineBottom(),
2356 cursor.par()->params.pagebreakTop(),
2357 cursor.par()->params.pagebreakBottom(),
2358 VSpace(VSpace::NONE),
2359 cursor.par()->params.spaceBottom(),
2360 cursor.par()->params.align(),
2361 cursor.par()->params.labelWidthString(), 0);
2362 lt->CursorLeft(bv_);
2365 | BufferView::FITCUR
2366 | BufferView::CHANGE);
2368 lt->CursorLeft(bv_);
2370 lt->selection.cursor = lt->cursor;
2373 | BufferView::FITCUR
2374 | BufferView::CHANGE);
2378 lt->selection.cursor = lt->cursor;
2381 | BufferView::FITCUR
2382 | BufferView::CHANGE);
2390 /* -------> Delete word forward. */
2391 case LFUN_DELETE_WORD_FORWARD:
2392 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2393 bv_->getLyXText()->DeleteWordForward(bv_);
2394 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2395 moveCursorUpdate(false);
2396 owner_->showState();
2399 /* -------> Delete word backward. */
2400 case LFUN_DELETE_WORD_BACKWARD:
2402 LyXText * lt = bv_->getLyXText();
2404 update(lt, BufferView::SELECT|BufferView::FITCUR);
2405 lt->DeleteWordBackward(bv_);
2408 | BufferView::FITCUR
2409 | BufferView::CHANGE);
2410 moveCursorUpdate(false);
2411 owner_->showState();
2415 /* -------> Kill to end of line. */
2416 case LFUN_DELETE_LINE_FORWARD:
2418 LyXText * lt = bv_->getLyXText();
2420 update(lt, BufferView::SELECT|BufferView::FITCUR);
2421 lt->DeleteLineForward(bv_);
2424 | BufferView::FITCUR
2425 | BufferView::CHANGE);
2426 moveCursorUpdate(false);
2430 /* -------> Set mark off. */
2433 LyXText * lt = bv_->getLyXText();
2436 update(lt, BufferView::SELECT|BufferView::FITCUR);
2437 lt->selection.cursor = lt->cursor;
2438 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2442 /* -------> Set mark on. */
2445 LyXText * lt = bv_->getLyXText();
2448 lt->selection.mark(true);
2449 update(lt, BufferView::SELECT|BufferView::FITCUR);
2450 lt->selection.cursor = lt->cursor;
2451 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2455 case LFUN_BACKSPACE:
2457 LyXText * lt = bv_->getLyXText();
2459 if (!lt->selection.set()) {
2460 if (owner_->getIntl()->getTrans().backspace()) {
2462 lt->selection.cursor = lt->cursor;
2465 | BufferView::FITCUR
2466 | BufferView::CHANGE);
2467 // It is possible to make it a lot faster still
2468 // just comment out the line below...
2474 owner_->showState();
2479 case LFUN_BACKSPACE_SKIP:
2481 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2482 LyXText * lt = bv_->getLyXText();
2484 LyXCursor cursor = lt->cursor;
2486 if (!lt->selection.set()) {
2487 if (cursor.pos() == 0
2488 && !(cursor.par()->params.spaceTop()
2489 == VSpace (VSpace::NONE))) {
2492 cursor.par()->params.lineTop(),
2493 cursor.par()->params.lineBottom(),
2494 cursor.par()->params.pagebreakTop(),
2495 cursor.par()->params.pagebreakBottom(),
2496 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2497 cursor.par()->params.align(),
2498 cursor.par()->params.labelWidthString(), 0);
2501 | BufferView::FITCUR
2502 | BufferView::CHANGE);
2505 lt->selection.cursor = cursor;
2508 | BufferView::FITCUR
2509 | BufferView::CHANGE);
2516 case LFUN_BREAKPARAGRAPH:
2518 LyXText * lt = bv_->getLyXText();
2521 lt->BreakParagraph(bv_, 0);
2524 | BufferView::FITCUR
2525 | BufferView::CHANGE);
2526 lt->selection.cursor = lt->cursor;
2528 owner_->showState();
2532 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2534 LyXText * lt = bv_->getLyXText();
2537 lt->BreakParagraph(bv_, 1);
2540 | BufferView::FITCUR
2541 | BufferView::CHANGE);
2542 lt->selection.cursor = lt->cursor;
2544 owner_->showState();
2548 case LFUN_BREAKPARAGRAPH_SKIP:
2550 // When at the beginning of a paragraph, remove
2551 // indentation and add a "defskip" at the top.
2552 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2553 LyXText * lt = bv_->getLyXText();
2555 LyXCursor cursor = lt->cursor;
2558 if (cursor.pos() == 0) {
2559 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2562 cursor.par()->params.lineTop(),
2563 cursor.par()->params.lineBottom(),
2564 cursor.par()->params.pagebreakTop(),
2565 cursor.par()->params.pagebreakBottom(),
2566 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2567 cursor.par()->params.align(),
2568 cursor.par()->params.labelWidthString(), 1);
2569 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2573 lt->BreakParagraph(bv_, 0);
2574 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2579 | BufferView::FITCUR
2580 | BufferView::CHANGE);
2581 lt->selection.cursor = cursor;
2583 owner_->showState();
2587 case LFUN_PARAGRAPH_SPACING:
2589 LyXText * lt = bv_->getLyXText();
2591 LyXParagraph * par = lt->cursor.par();
2592 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2593 float cur_value = 1.0;
2594 if (cur_spacing == Spacing::Other) {
2595 cur_value = par->params.spacing().getValue();
2598 istringstream istr(argument.c_str());
2602 Spacing::Space new_spacing = cur_spacing;
2603 float new_value = cur_value;
2605 lyxerr << "Missing argument to `paragraph-spacing'"
2607 } else if (tmp == "single") {
2608 new_spacing = Spacing::Single;
2609 } else if (tmp == "onehalf") {
2610 new_spacing = Spacing::Onehalf;
2611 } else if (tmp == "double") {
2612 new_spacing = Spacing::Double;
2613 } else if (tmp == "other") {
2614 new_spacing = Spacing::Other;
2617 lyxerr << "new_value = " << tmpval << endl;
2620 } else if (tmp == "default") {
2621 new_spacing = Spacing::Default;
2623 lyxerr << _("Unknown spacing argument: ")
2624 << argument << endl;
2626 if (cur_spacing != new_spacing || cur_value != new_value) {
2627 par->params.spacing(Spacing(new_spacing, new_value));
2628 lt->RedoParagraph(bv_);
2631 | BufferView::FITCUR
2632 | BufferView::CHANGE);
2638 bv_->insertCorrectQuote();
2644 InsetCommandParams p;
2645 if (action == LFUN_HTMLURL)
2646 p.setCmdName("htmlurl");
2648 p.setCmdName("url");
2649 owner_->getDialogs()->createUrl( p.getAsString() );
2653 case LFUN_INSERT_URL:
2655 InsetCommandParams p;
2656 p.setFromString( argument );
2658 InsetUrl * inset = new InsetUrl( p );
2659 if (!bv_->insertInset(inset))
2662 bv_->updateInset( inset, true );
2666 case LFUN_INSET_TEXT:
2668 InsetText * new_inset = new InsetText;
2669 if (bv_->insertInset(new_inset))
2670 new_inset->Edit(bv_, 0, 0, 0);
2676 case LFUN_INSET_ERT:
2678 InsetERT * new_inset = new InsetERT;
2679 if (bv_->insertInset(new_inset))
2680 new_inset->Edit(bv_, 0, 0, 0);
2686 case LFUN_INSET_EXTERNAL:
2688 InsetExternal * new_inset = new InsetExternal;
2689 if (bv_->insertInset(new_inset))
2690 new_inset->Edit(bv_, 0, 0, 0);
2696 case LFUN_INSET_FOOTNOTE:
2698 InsetFoot * new_inset = new InsetFoot;
2699 if (bv_->insertInset(new_inset))
2700 new_inset->Edit(bv_, 0, 0, 0);
2706 case LFUN_INSET_MARGINAL:
2708 InsetMarginal * new_inset = new InsetMarginal;
2709 if (bv_->insertInset(new_inset))
2710 new_inset->Edit(bv_, 0, 0, 0);
2716 case LFUN_INSET_MINIPAGE:
2718 InsetMinipage * new_inset = new InsetMinipage;
2719 if (bv_->insertInset(new_inset))
2720 new_inset->Edit(bv_, 0, 0, 0);
2726 case LFUN_INSET_FLOAT:
2728 // check if the float type exist
2729 if (floatList.typeExist(argument)) {
2730 InsetFloat * new_inset = new InsetFloat(argument);
2731 if (bv_->insertInset(new_inset))
2732 new_inset->Edit(bv_, 0, 0, 0);
2736 lyxerr << "Non-existant float type: "
2737 << argument << endl;
2743 case LFUN_INSET_WIDE_FLOAT:
2745 // check if the float type exist
2746 if (floatList.typeExist(argument)) {
2747 InsetFloat * new_inset = new InsetFloat(argument);
2748 new_inset->wide(true);
2749 if (bv_->insertInset(new_inset))
2750 new_inset->Edit(bv_, 0, 0, 0);
2754 lyxerr << "Non-existant float type: "
2755 << argument << endl;
2761 case LFUN_INSET_LIST:
2763 InsetList * new_inset = new InsetList;
2764 if (bv_->insertInset(new_inset))
2765 new_inset->Edit(bv_, 0, 0, 0);
2771 case LFUN_INSET_THEOREM:
2773 InsetTheorem * new_inset = new InsetTheorem;
2774 if (bv_->insertInset(new_inset))
2775 new_inset->Edit(bv_, 0, 0, 0);
2781 case LFUN_INSET_CAPTION:
2783 // Do we have a locking inset...
2784 if (bv_->theLockingInset()) {
2785 lyxerr << "Locking inset code: "
2786 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2787 InsetCaption * new_inset = new InsetCaption;
2788 new_inset->setOwner(bv_->theLockingInset());
2789 new_inset->SetAutoBreakRows(true);
2790 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2791 new_inset->SetFrameColor(0, LColor::footnoteframe);
2792 if (bv_->insertInset(new_inset))
2793 new_inset->Edit(bv_, 0, 0, 0);
2800 case LFUN_INSET_TABULAR:
2803 if (!argument.empty())
2804 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2805 InsetTabular * new_inset =
2806 new InsetTabular(*buffer_, r, c);
2808 bv_->getLyXText()->real_current_font.isRightToLeft();
2809 if (!open_new_inset(new_inset, rtl))
2814 // --- lyxserver commands ----------------------------
2816 case LFUN_CHARATCURSOR:
2818 LyXParagraph::size_type pos = bv_->getLyXText()->cursor.pos();
2819 if (pos < bv_->getLyXText()->cursor.par()->size())
2820 owner_->getLyXFunc()->setMessage(
2821 tostr(bv_->getLyXText()->cursor.par()->GetChar(pos)));
2823 owner_->getLyXFunc()->setMessage("EOF");
2828 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2830 + tostr(bv_->getLyXText()->cursor.y()));
2837 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2838 bv_->getLyXText()->SetCursorFromCoordinates(bv_, x, y);
2842 case LFUN_GETLAYOUT:
2843 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2848 LyXFont & font = bv_->getLyXText()->current_font;
2849 if (font.shape() == LyXFont::ITALIC_SHAPE)
2850 owner_->getLyXFunc()->setMessage("E");
2851 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2852 owner_->getLyXFunc()->setMessage("N");
2854 owner_->getLyXFunc()->setMessage("0");
2861 LyXFont & font = bv_->getLyXText()->current_font;
2862 if (font.latex() == LyXFont::ON)
2863 owner_->getLyXFunc()->setMessage("L");
2865 owner_->getLyXFunc()->setMessage("0");
2869 // --- accented characters ---------------------------
2872 case LFUN_CIRCUMFLEX:
2882 case LFUN_SPECIAL_CARON:
2885 case LFUN_HUNG_UMLAUT:
2888 if (argument.empty()) {
2890 owner_->getLyXFunc()->handleKeyFunc(action);
2892 owner_->getLyXFunc()->handleKeyFunc(action);
2893 owner_->getIntl()->getTrans()
2894 .TranslateAndInsert(argument[0], bv_->getLyXText());
2895 update(bv_->getLyXText(),
2897 | BufferView::FITCUR
2898 | BufferView::CHANGE);
2902 // --- insert characters ----------------------------------------
2904 case LFUN_MATH_DELIM:
2905 case LFUN_INSERT_MATRIX:
2908 if (open_new_inset(new InsetFormula(false))) {
2909 bv_->theLockingInset()
2910 ->LocalDispatch(bv_, action, argument);
2916 case LFUN_INSERT_MATH:
2921 InsetFormula * f = new InsetFormula(true);
2923 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2927 case LFUN_MATH_DISPLAY:
2930 open_new_inset(new InsetFormula(true));
2934 case LFUN_MATH_MACRO:
2939 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2941 string const s1 = token(s, ' ', 1);
2942 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2943 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2949 case LFUN_MATH_MODE: // Open or create a math inset
2952 open_new_inset(new InsetFormula);
2953 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2957 case LFUN_CITATION_INSERT:
2959 InsetCommandParams p;
2960 p.setFromString( argument );
2962 InsetCitation * inset = new InsetCitation( p );
2963 if (!bv_->insertInset(inset))
2966 bv_->updateInset( inset, true );
2970 case LFUN_INSERT_BIBTEX:
2972 // ale970405+lasgoutt970425
2973 // The argument can be up to two tokens separated
2974 // by a space. The first one is the bibstyle.
2975 string const db = token(argument, ' ', 0);
2976 string bibstyle = token(argument, ' ', 1);
2977 if (bibstyle.empty())
2980 InsetCommandParams p( "BibTeX", db, bibstyle );
2981 InsetBibtex * inset = new InsetBibtex(p);
2983 if (bv_->insertInset(inset)) {
2984 if (argument.empty())
2985 inset->Edit(bv_, 0, 0, 0);
2991 // BibTeX data bases
2992 case LFUN_BIBDB_ADD:
2994 InsetBibtex * inset =
2995 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2997 inset->addDatabase(argument);
3002 case LFUN_BIBDB_DEL:
3004 InsetBibtex * inset =
3005 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3007 inset->delDatabase(argument);
3012 case LFUN_BIBTEX_STYLE:
3014 InsetBibtex * inset =
3015 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3017 inset->setOptions(argument);
3022 case LFUN_INDEX_CREATE:
3024 InsetCommandParams p( "index" );
3026 if (argument.empty()) {
3027 // Get the word immediately preceding the cursor
3028 LyXParagraph::size_type curpos =
3029 bv_->getLyXText()->cursor.pos() - 1;
3033 curstring = bv_->getLyXText()
3034 ->cursor.par()->GetWord(curpos);
3036 p.setContents( curstring );
3038 p.setContents( argument );
3041 owner_->getDialogs()->createIndex( p.getAsString() );
3045 case LFUN_INDEX_INSERT:
3047 InsetCommandParams p;
3048 p.setFromString(argument);
3049 InsetIndex * inset = new InsetIndex(p);
3051 if (!bv_->insertInset(inset))
3054 bv_->updateInset(inset, true);
3058 case LFUN_INDEX_INSERT_LAST:
3060 // Get word immediately preceding the cursor
3061 LyXParagraph::size_type curpos =
3062 bv_->getLyXText()->cursor.pos() - 1;
3063 // Can't do that at the beginning of a paragraph
3064 if (curpos < 0) break;
3066 string const curstring(bv_->getLyXText()
3067 ->cursor.par()->GetWord(curpos));
3069 InsetCommandParams p("index", curstring);
3070 InsetIndex * inset = new InsetIndex(p);
3072 if (!bv_->insertInset(inset))
3075 bv_->updateInset(inset, true);
3079 case LFUN_INDEX_PRINT:
3081 InsetCommandParams p("printindex");
3082 Inset * inset = new InsetPrintIndex(p);
3083 if (!bv_->insertInset(inset, "Standard", true))
3088 case LFUN_PARENTINSERT:
3090 lyxerr << "arg " << argument << endl;
3091 InsetCommandParams p( "lyxparent", argument );
3092 Inset * inset = new InsetParent(p, *buffer_);
3093 if (!bv_->insertInset(inset, "Standard", true))
3099 case LFUN_CHILD_INSERT:
3101 InsetInclude::Params p;
3102 p.cparams.setFromString(argument);
3103 p.masterFilename_ = buffer_->fileName();
3105 InsetInclude * inset = new InsetInclude(p);
3106 if (!bv_->insertInset(inset))
3109 bv_->updateInset(inset, true);
3110 bv_->owner()->getDialogs()->showInclude(inset);
3115 case LFUN_FLOAT_LIST:
3117 // We should check the argument for validity. (Lgb)
3118 Inset * inset = new InsetFloatList(argument);
3119 if (!bv_->insertInset(inset, "Standard", true))
3124 case LFUN_INSERT_NOTE:
3128 case LFUN_SELFINSERT:
3130 if (argument.empty()) break;
3132 /* Automatically delete the currently selected
3133 * text and replace it with what is being
3134 * typed in now. Depends on lyxrc settings
3135 * "auto_region_delete", which defaults to
3138 LyXText * lt = bv_->getLyXText();
3140 if (lyxrc.auto_region_delete) {
3141 if (lt->selection.set()) {
3142 lt->CutSelection(bv_, false);
3145 | BufferView::FITCUR
3146 | BufferView::CHANGE);
3150 bv_->beforeChange(lt);
3151 LyXFont const old_font(lt->real_current_font);
3153 string::const_iterator cit = argument.begin();
3154 string::const_iterator end = argument.end();
3155 for (; cit != end; ++cit) {
3156 if (greek_kb_flag) {
3157 if (!math_insert_greek(bv_, *cit))
3158 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3160 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3165 | BufferView::FITCUR
3166 | BufferView::CHANGE);
3168 lt->selection.cursor = lt->cursor;
3169 moveCursorUpdate(false);
3171 // real_current_font.number can change so we need to
3172 // update the minibuffer
3173 if (old_font != lt->real_current_font)
3174 owner_->showState();
3179 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3181 time_t now_time_t = time(NULL);
3182 struct tm * now_tm = localtime(&now_time_t);
3183 setlocale(LC_TIME, "");
3185 if (!argument.empty())
3188 arg = lyxrc.date_insert_format;
3190 int const datetmp_len =
3191 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3193 LyXText * lt = bv_->getLyXText();
3195 for (int i = 0; i < datetmp_len; i++) {
3196 lt->InsertChar(bv_, datetmp[i]);
3199 | BufferView::FITCUR
3200 | BufferView::CHANGE);
3203 lt->selection.cursor = lt->cursor;
3204 moveCursorUpdate(false);
3208 case LFUN_UNKNOWN_ACTION:
3209 owner_->getLyXFunc()->setErrorMessage(N_("Unknow function!"));
3220 void BufferView::Pimpl::newline()
3223 LyXText * lt = bv_->getLyXText();
3227 | BufferView::FITCUR);
3228 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
3231 | BufferView::FITCUR
3232 | BufferView::CHANGE);
3237 void BufferView::Pimpl::hfill()
3240 LyXText * lt = bv_->getLyXText();
3244 | BufferView::FITCUR);
3245 lt->InsertChar(bv_, LyXParagraph::META_HFILL);
3248 | BufferView::FITCUR
3249 | BufferView::CHANGE);
3254 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3258 update(lt, BufferView::SELECT|BufferView::FITCUR);
3259 InsetSpecialChar * new_inset =
3260 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3261 if (!bv_->insertInset(new_inset))
3264 bv_->updateInset(new_inset, true);
3269 void BufferView::Pimpl::menuSeparator()
3272 LyXText * lt = bv_->getLyXText();
3275 update(lt, BufferView::SELECT|BufferView::FITCUR);
3276 InsetSpecialChar * new_inset =
3277 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3278 bv_->insertInset(new_inset);
3283 void BufferView::Pimpl::endOfSentenceDot()
3287 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3288 InsetSpecialChar * new_inset =
3289 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3290 bv_->insertInset(new_inset);
3295 void BufferView::Pimpl::ldots()
3299 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3300 InsetSpecialChar * new_inset =
3301 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3302 bv_->insertInset(new_inset);
3307 void BufferView::Pimpl::hyphenationPoint()
3311 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3312 InsetSpecialChar * new_inset =
3313 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3314 bv_->insertInset(new_inset);
3319 void BufferView::Pimpl::insertNote()
3321 InsetInfo * new_inset = new InsetInfo();
3322 bv_->insertInset(new_inset);
3323 new_inset->Edit(bv_, 0, 0, 0);
3327 // Open and lock an updatable inset
3328 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3330 LyXText * lt = bv_->getLyXText();
3334 if (!bv_->insertInset(new_inset)) {
3339 LyXFont & font = lt->real_current_font;
3340 new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
3342 new_inset->Edit(bv_, 0, 0, 0);