12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
20 #include "minibuffer.h"
22 #include "bufferview_funcs.h"
23 #include "TextCache.h"
24 #include "bufferlist.h"
25 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "frontends/Dialogs.h"
30 #include "insets/insetbib.h"
31 #include "insets/insettext.h"
32 /// added for Dispatch functions
34 #include "frontends/FileDialog.h"
36 #include "FloatList.h"
37 #include "support/filetools.h"
38 #include "support/lyxfunctional.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetlatexaccent.h"
41 #include "insets/insettoc.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "mathed/formulamacro.h"
59 extern LyXTextClass::size_type current_layout;
60 extern void math_insert_symbol(BufferView *, string const &);
61 extern bool math_insert_greek(BufferView *, char);
62 extern int greek_kb_flag;
64 #ifdef SIGC_CXX_NAMESPACES
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 void sigchldhandler(pid_t pid, int * status);
82 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
84 const unsigned int saved_positions_num = 20;
89 XSync(fl_get_display(), 0);
94 void SetXtermCursor(Window win)
97 static bool cursor_undefined = true;
98 if (cursor_undefined){
99 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
100 XFlush(fl_get_display());
101 cursor_undefined = false;
103 XDefineCursor(fl_get_display(), win, cursor);
104 XFlush(fl_get_display());
108 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
109 int xpos, int ypos, int width, int height)
110 : bv_(b), owner_(o), buffer_(0),
111 current_scrollbar_value(0), cursor_timeout(400),
112 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
115 //workarea_ = new WorkArea(xpos, ypos, width, height);
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));
141 cursor_timeout.timeout.connect(slot(this,
142 &BufferView::Pimpl::cursorToggle));
143 //current_scrollbar_value = 0;
144 cursor_timeout.start();
145 workarea_.setFocus();
146 //using_xterm_cursor = false;
147 saved_positions.resize(saved_positions_num);
151 Painter & BufferView::Pimpl::painter()
153 return workarea_.getPainter();
157 void BufferView::Pimpl::buffer(Buffer * b)
159 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
163 buffer_->delUser(bv_);
165 // Put the old text into the TextCache, but
166 // only if the buffer is still loaded.
167 // Also set the owner of the test to 0
168 // bv_->text->owner(0);
169 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
170 if (lyxerr.debugging())
171 textcache.show(lyxerr, "BufferView::buffer");
176 // Set current buffer
179 if (bufferlist.getState() == BufferList::CLOSING) return;
182 // screen is always deleted when the buffer is changed.
187 // If we are closing the buffer, use the first buffer as current
189 buffer_ = bufferlist.first();
193 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
194 buffer_->addUser(bv_);
195 // If we don't have a text object for this, we make one
196 if (bv_->text == 0) {
197 resizeCurrentBuffer();
202 bv_->text->first = screen_->TopCursorVisible(bv_->text);
203 owner_->updateMenubar();
204 owner_->updateToolbar();
205 // Similarly, buffer-dependent dialogs should be updated or
206 // hidden. This should go here because some dialogs (eg ToC)
207 // require bv_->text.
208 owner_->getDialogs()->updateBufferDependent(true);
212 lyxerr[Debug::INFO] << " No Buffer!" << endl;
213 owner_->updateMenubar();
214 owner_->updateToolbar();
215 owner_->getDialogs()->hideBufferDependent();
219 // Also remove all remaining text's from the testcache.
220 // (there should not be any!) (if there is any it is a
222 if (lyxerr.debugging())
223 textcache.show(lyxerr, "buffer delete all");
226 // should update layoutchoice even if we don't have a buffer.
227 owner_->updateLayoutChoice();
228 owner_->getMiniBuffer()->Init();
229 owner_->updateWindowTitle();
233 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
235 workarea_.resize(xpos, ypos, width, height);
236 update(bv_->text, SELECT);
241 void BufferView::Pimpl::resize()
244 resizeCurrentBuffer();
248 void BufferView::Pimpl::redraw()
250 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
255 bool BufferView::Pimpl::fitCursor(LyXText * text)
257 Assert(screen_.get());
259 bool ret = screen_->FitCursor(text, bv_);
266 void BufferView::Pimpl::redoCurrentBuffer()
268 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
269 if (buffer_ && bv_->text) {
271 owner_->updateLayoutChoice();
276 int BufferView::Pimpl::resizeCurrentBuffer()
278 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
280 LyXParagraph * par = 0;
281 LyXParagraph * selstartpar = 0;
282 LyXParagraph * selendpar = 0;
283 UpdatableInset * the_locking_inset = 0;
285 LyXParagraph::size_type pos = 0;
286 LyXParagraph::size_type selstartpos = 0;
287 LyXParagraph::size_type selendpos = 0;
288 bool selection = false;
289 bool mark_set = false;
293 owner_->getMiniBuffer()->Set(_("Formatting document..."));
296 par = bv_->text->cursor.par();
297 pos = bv_->text->cursor.pos();
298 selstartpar = bv_->text->sel_start_cursor.par();
299 selstartpos = bv_->text->sel_start_cursor.pos();
300 selendpar = bv_->text->sel_end_cursor.par();
301 selendpos = bv_->text->sel_end_cursor.pos();
302 selection = bv_->text->selection;
303 mark_set = bv_->text->mark_set;
304 the_locking_inset = bv_->text->the_locking_inset;
306 bv_->text = new LyXText(bv_);
308 // See if we have a text in TextCache that fits
309 // the new buffer_ with the correct width.
310 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
312 if (lyxerr.debugging()) {
313 lyxerr << "Found a LyXText that fits:\n";
314 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
316 // Set the owner of the newly found text
317 // bv_->text->owner(bv_);
318 if (lyxerr.debugging())
319 textcache.show(lyxerr, "resizeCurrentBuffer");
321 bv_->text = new LyXText(bv_);
327 bv_->text->selection = true;
328 /* at this point just to avoid the Delete-Empty-Paragraph
329 * Mechanism when setting the cursor */
330 bv_->text->mark_set = mark_set;
332 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
333 bv_->text->sel_cursor = bv_->text->cursor;
334 bv_->text->SetCursor(bv_, selendpar, selendpos);
335 bv_->text->SetSelection(bv_);
336 bv_->text->SetCursor(bv_, par, pos);
338 bv_->text->SetCursor(bv_, par, pos);
339 bv_->text->sel_cursor = bv_->text->cursor;
340 bv_->text->selection = false;
342 // remake the inset locking
343 bv_->text->the_locking_inset = the_locking_inset;
345 bv_->text->first = screen_->TopCursorVisible(bv_->text);
346 buffer_->resizeInsets(bv_);
347 // this will scroll the screen such that the cursor becomes visible
350 owner_->getMiniBuffer()->Init();
354 owner_->getDialogs()->hideSplash();
360 void BufferView::Pimpl::updateScreen()
362 // Regenerate the screen.
363 screen_.reset(new LyXScreen(workarea_));
365 //screen_ = 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 max2 = 0;
381 static unsigned long height2 = 0;
383 unsigned long cbth = 0;
387 cbth = bv_->text->height;
388 cbsf = bv_->text->first;
391 // check if anything has changed.
393 height2 == workarea_.height() &&
394 current_scrollbar_value == cbsf)
397 height2 = workarea_.height();
398 current_scrollbar_value = cbsf;
400 if (cbth <= height2) { // text is smaller than screen
401 workarea_.setScrollbar(0, 1.0); // right?
405 long maximum_height = workarea_.height() * 3 / 4 + cbth;
409 double hfloat = workarea_.height();
410 double maxfloat = maximum_height;
412 float slider_size = 0.0;
413 int slider_value = value;
415 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
416 double const lineh = bv_->text->DefaultHeight();
417 workarea_.setScrollbarIncrements(lineh);
418 if (maxfloat > 0.0) {
419 if ((hfloat / maxfloat) * float(height2) < 3)
420 slider_size = 3.0/float(height2);
422 slider_size = hfloat / maxfloat;
424 slider_size = hfloat;
426 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
430 // Callback for scrollbar slider
431 void BufferView::Pimpl::scrollCB(double value)
433 if (!buffer_) return;
435 current_scrollbar_value = long(value);
436 if (current_scrollbar_value < 0)
437 current_scrollbar_value = 0;
442 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
444 if (!lyxrc.cursor_follows_scrollbar) {
449 LyXText * vbt = bv_->text;
451 int const height = vbt->DefaultHeight();
452 int const first = static_cast<int>((bv_->text->first + height));
453 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
455 if (vbt->cursor.y() < first)
456 vbt->SetCursorFromCoordinates(bv_, 0, first);
457 else if (vbt->cursor.y() > last)
458 vbt->SetCursorFromCoordinates(bv_, 0, last);
464 int BufferView::Pimpl::scrollUp(long time)
466 if (!buffer_) return 0;
467 if (!screen_.get()) return 0;
469 double value = workarea_.getScrollbarValue();
471 if (value == 0) return 0;
473 float add_value = (bv_->text->DefaultHeight()
474 + float(time) * float(time) * 0.125);
476 if (add_value > workarea_.height())
477 add_value = float(workarea_.height() -
478 bv_->text->DefaultHeight());
485 workarea_.setScrollbarValue(value);
492 int BufferView::Pimpl::scrollDown(long time)
494 if (!buffer_) return 0;
495 if (!screen_.get()) return 0;
497 double value = workarea_.getScrollbarValue();
498 pair<float, float> p = workarea_.getScrollbarBounds();
499 double max = p.second;
501 if (value == max) return 0;
503 float add_value = (bv_->text->DefaultHeight()
504 + float(time) * float(time) * 0.125);
506 if (add_value > workarea_.height())
507 add_value = float(workarea_.height() -
508 bv_->text->DefaultHeight());
515 workarea_.setScrollbarValue(value);
522 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
524 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
528 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
530 // Only use motion with button 1
531 if (!(state & Button1MotionMask))
534 if (!buffer_ || !screen_.get()) return;
536 // Check for inset locking
537 if (bv_->theLockingInset()) {
538 LyXCursor cursor = bv_->text->cursor;
539 LyXFont font = bv_->text->GetFont(bv_->buffer(),
540 cursor.par(), cursor.pos());
541 int width = bv_->theLockingInset()->width(bv_, font);
542 int inset_x = font.isVisibleRightToLeft()
543 ? cursor.x() - width : cursor.x();
544 int start_x = inset_x + bv_->theLockingInset()->scroll();
545 bv_->theLockingInset()->
546 InsetMotionNotify(bv_,
548 y - cursor.y() + bv_->text->first,
553 /* The test for not selection possible is needed, that only motion events are
554 * used, where the bottom press event was on the drawing area too */
555 if (!selection_possible)
558 screen_->HideCursor();
560 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
562 if (!bv_->text->selection)
563 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
565 bv_->text->SetSelection(bv_);
566 screen_->ToggleToggle(bv_->text, bv_);
567 fitCursor(bv_->text);
568 screen_->ShowCursor(bv_->text, bv_);
572 // Single-click on work area
573 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
579 if (!buffer_ || !screen_.get()) return;
581 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
583 // ok ok, this is a hack.
584 if (button == 4 || button == 5) {
587 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
590 scrollDown(lyxrc.wheel_jump);
595 if (bv_->theLockingInset()) {
596 // We are in inset locking mode
598 /* Check whether the inset was hit. If not reset mode,
599 otherwise give the event to the inset */
600 if (inset_hit == bv_->theLockingInset()) {
601 bv_->theLockingInset()->
602 InsetButtonPress(bv_,
607 bv_->unlockInset(bv_->theLockingInset());
612 selection_possible = true;
613 screen_->HideCursor();
615 int const screen_first = bv_->text->first;
617 // Middle button press pastes if we have a selection
618 bool paste_internally = false;
620 && bv_->text->selection) {
621 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
622 paste_internally = true;
625 // Clear the selection
626 screen_->ToggleSelection(bv_->text, bv_);
627 bv_->text->ClearSelection(bv_);
628 bv_->text->FullRebreak(bv_);
629 screen_->Update(bv_->text, bv_);
632 // Single left click in math inset?
633 if ((inset_hit != 0) &&
634 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
635 // Highly editable inset, like math
636 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
637 selection_possible = false;
638 owner_->updateLayoutChoice();
639 owner_->getMiniBuffer()->Set(inset->EditMessage());
640 inset->InsetButtonPress(bv_, xpos, ypos, button);
641 inset->Edit(bv_, xpos, ypos, button);
645 // Right click on a footnote flag opens float menu
647 selection_possible = false;
651 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
652 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
653 bv_->text->FinishUndo();
654 bv_->text->sel_cursor = bv_->text->cursor;
655 bv_->text->cursor.x_fix(bv_->text->cursor.x());
657 owner_->updateLayoutChoice();
658 if (fitCursor(bv_->text)) {
659 selection_possible = false;
662 // Insert primary selection with middle mouse
663 // if there is a local selection in the current buffer,
666 if (paste_internally)
667 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
669 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
671 selection_possible = false;
677 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
683 LyXText * text = bv_->getLyXText();
685 if (text->bv_owner && bv_->theLockingInset())
688 if (screen_.get() && button == 1) {
689 if (text->bv_owner) {
690 screen_->HideCursor();
691 screen_->ToggleSelection(text, bv_);
692 text->SelectWord(bv_);
693 screen_->ToggleSelection(text, bv_, false);
695 text->SelectWord(bv_);
697 /* This will fit the cursor on the screen
699 update(text, BufferView::SELECT|BufferView::FITCUR);
704 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
710 LyXText * text = bv_->getLyXText();
712 if (text->bv_owner && bv_->theLockingInset())
715 if (screen_.get() && (button == 1)) {
716 screen_->HideCursor();
717 screen_->ToggleSelection(text, bv_);
718 text->CursorHome(bv_);
719 text->sel_cursor = text->cursor;
720 text->CursorEnd(bv_);
721 text->SetSelection(bv_);
722 screen_->ToggleSelection(text, bv_, false);
723 /* This will fit the cursor on the screen
725 update(text, BufferView::SELECT|BufferView::FITCUR);
730 void BufferView::Pimpl::enterView()
732 if (active() && available()) {
733 SetXtermCursor(workarea_.getWin());
734 using_xterm_cursor = true;
739 void BufferView::Pimpl::leaveView()
741 if (using_xterm_cursor) {
742 XUndefineCursor(fl_get_display(), workarea_.getWin());
743 using_xterm_cursor = false;
748 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
751 if (!buffer_ || !screen_.get()) return;
753 // If we hit an inset, we have the inset coordinates in these
754 // and inset_hit points to the inset. If we do not hit an
755 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
756 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
758 if (bv_->theLockingInset()) {
759 // We are in inset locking mode.
761 /* LyX does a kind of work-area grabbing for insets.
762 Only a ButtonPress Event outside the inset will
763 force a InsetUnlock. */
764 bv_->theLockingInset()->
765 InsetButtonRelease(bv_, x, y, button);
769 selection_possible = false;
771 if (button >= 2) return;
776 // Did we hit an editable inset?
778 // Inset like error, notes and figures
779 selection_possible = false;
781 // CHECK fix this proper in 0.13
783 // Following a ref shouldn't issue
784 // a push on the undo-stack
785 // anylonger, now that we have
786 // keybindings for following
787 // references and returning from
788 // references. IMHO though, it
789 // should be the inset's own business
790 // to push or not push on the undo
791 // stack. They don't *have* to
792 // alter the document...
794 // ...or maybe the SetCursorParUndo()
795 // below isn't necessary at all anylonger?
796 if (inset_hit->LyxCode() == Inset::REF_CODE) {
797 bv_->text->SetCursorParUndo(bv_->buffer());
800 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
801 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
802 // Highly editable inset, like math
803 UpdatableInset *inset = (UpdatableInset *)inset_hit;
804 inset->InsetButtonRelease(bv_, x, y, button);
806 inset_hit->InsetButtonRelease(bv_, x, y, button);
807 inset_hit->Edit(bv_, x, y, button);
812 // check whether we want to open a float
816 if (bv_->text->cursor.pos() <
817 bv_->text->cursor.par()->Last()) {
818 c = bv_->text->cursor.par()->
819 GetChar(bv_->text->cursor.pos());
822 if(!bv_->text->selection)
823 if (c == LyXParagraph::META_FOOTNOTE
824 || c == LyXParagraph::META_MARGIN
825 || c == LyXParagraph::META_FIG
826 || c == LyXParagraph::META_TAB
827 || c == LyXParagraph::META_WIDE_FIG
828 || c == LyXParagraph::META_WIDE_TAB
829 || c == LyXParagraph::META_ALGORITHM){
833 if (bv_->text->cursor.pos() - 1 >= 0) {
834 c = bv_->text->cursor.par()->
835 GetChar(bv_->text->cursor.pos() - 1);
837 if (c == LyXParagraph::META_FOOTNOTE
838 || c == LyXParagraph::META_MARGIN
839 || c == LyXParagraph::META_FIG
840 || c == LyXParagraph::META_TAB
841 || c == LyXParagraph::META_WIDE_FIG
842 || c == LyXParagraph::META_WIDE_TAB
843 || c == LyXParagraph::META_ALGORITHM){
844 // We are one step too far to the right
845 bv_->text->CursorLeft(bv_);
854 selection_possible = false;
860 // Do we want to close a float? (click on the float-label)
861 if (bv_->text->cursor.row()->par()->footnoteflag ==
862 LyXParagraph::OPEN_FOOTNOTE
863 && bv_->text->cursor.row()->previous() &&
864 bv_->text->cursor.row()->previous()->par()->
865 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
866 LyXFont font(LyXFont::ALL_SANE);
867 font.setSize(LyXFont::SIZE_FOOTNOTE);
869 int box_x = 20; // LYX_PAPER_MARGIN;
870 box_x += lyxfont::width(" wide-tab ", font);
872 unsigned int screen_first = bv_->text->first;
875 && y + screen_first > bv_->text->cursor.y() -
876 bv_->text->cursor.row()->baseline()
877 && y + screen_first < bv_->text->cursor.y() -
878 bv_->text->cursor.row()->baseline()
879 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
881 selection_possible = false;
887 // Maybe we want to edit a bibitem ale970302
888 if (bv_->text->cursor.par()->bibkey && x < 20 +
889 bibitemMaxWidth(bv_, textclasslist.
891 params.textclass).defaultfont())) {
892 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
900 * Returns an inset if inset was hit. 0 otherwise.
901 * If hit, the coordinates are changed relative to the inset.
902 * Otherwise coordinates are not changed, and false is returned.
904 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
905 unsigned int /* button */)
910 int y_tmp = y + text->first;
913 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
915 if (cursor.pos() < cursor.par()->Last()
916 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
917 && cursor.par()->GetInset(cursor.pos())
918 && cursor.par()->GetInset(cursor.pos())->Editable()) {
920 // Check whether the inset really was hit
921 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
922 LyXFont font = text->GetFont(bv_->buffer(),
923 cursor.par(), cursor.pos());
924 int width = tmpinset->width(bv_, font);
925 int inset_x = font.isVisibleRightToLeft()
926 ? cursor.x() - width : cursor.x();
927 int start_x = inset_x + tmpinset->scroll();
928 int end_x = inset_x + width;
930 if (x > start_x && x < end_x
931 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
932 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
933 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
935 // The origin of an inset is on the baseline
936 y = y_tmp - (text->cursor.y());
941 if ((cursor.pos() - 1 >= 0) &&
942 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
943 (cursor.par()->GetInset(cursor.pos() - 1)) &&
944 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
945 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
946 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
948 int width = tmpinset->width(bv_, font);
949 int inset_x = font.isVisibleRightToLeft()
950 ? cursor.x() : cursor.x() - width;
951 int start_x = inset_x + tmpinset->scroll();
952 int end_x = inset_x + width;
954 if (x > start_x && x < end_x
955 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
956 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
958 if (move_cursor && (tmpinset != bv_->theLockingInset()))
960 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
962 // The origin of an inset is on the baseline
963 y = y_tmp - (text->cursor.y());
971 void BufferView::Pimpl::workAreaExpose()
973 static int work_area_width = 0;
974 static unsigned int work_area_height = 0;
976 bool widthChange = workarea_.workWidth() != work_area_width;
977 bool heightChange = workarea_.height() != work_area_height;
979 // update from work area
980 work_area_width = workarea_.workWidth();
981 work_area_height = workarea_.height();
984 // All buffers need a resize
987 // Remove all texts from the textcache
988 // This is not _really_ what we want to do. What
989 // we really want to do is to delete in textcache
990 // that does not have a BufferView with matching
991 // width, but as long as we have only one BufferView
992 // deleting all gives the same result.
993 if (lyxerr.debugging())
994 textcache.show(lyxerr, "Expose delete all");
996 } else if (heightChange) {
997 // Rebuild image of current screen
999 // fitCursor() ensures we don't jump back
1000 // to the start of the document on vertical
1002 fitCursor(bv_->text);
1004 // The main window size has changed, repaint most stuff
1006 // ...including the minibuffer
1007 owner_->getMiniBuffer()->Init();
1009 } else if (screen_.get())
1010 screen_->Redraw(bv_->text, bv_);
1012 // Grey box when we don't have a buffer
1013 workarea_.greyOut();
1016 // always make sure that the scrollbar is sane.
1018 owner_->updateLayoutChoice();
1023 void BufferView::Pimpl::update()
1025 if (screen_.get()) screen_->Update(bv_->text, bv_);
1028 // Values used when calling update:
1030 // -2 - update, move sel_cursor if selection, fitcursor
1031 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1032 // 0 - update, move sel_cursor if selection, fitcursor
1033 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1034 // 3 - update, move sel_cursor if selection
1037 // a simple redraw of the parts that need refresh
1039 // move sel_cursor if selection -
1040 // the text's sel_cursor is moved if there is selection is progress
1043 // fitCursor() is called and the scrollbar updated
1046 // the buffer is marked dirty.
1055 // UPDATE_ONLY = UPDATE;
1056 // UPDATE_SELECT = UPDATE | SELECT;
1057 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1058 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1060 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1061 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1062 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1063 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1064 // update(3) -> update(1) -> update(1) -> update(SELECT)
1066 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1068 owner_->updateLayoutChoice();
1070 if (!text->selection && (f & SELECT)) {
1071 text->sel_cursor = text->cursor;
1074 text->FullRebreak(bv_);
1076 if (text->inset_owner) {
1077 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1078 bv_->updateInset(text->inset_owner, true);
1087 if (buffer_->isLyxClean()) {
1088 buffer_->markDirty();
1089 owner_->getMiniBuffer()->setTimer(4);
1091 buffer_->markDirty();
1097 // Callback for cursor timer
1098 void BufferView::Pimpl::cursorToggle()
1100 // Quite a nice place for asyncron Inset updating, isn't it?
1101 // Actually no! This is run even if no buffer exist... so (Lgb)
1103 cursor_timeout.restart();
1108 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1109 if (pid == -1) // error find out what is wrong
1110 ; // ignore it for now.
1112 sigchldhandler(pid, &status);
1114 updatelist.update(bv_);
1116 if (!screen_.get()) {
1117 cursor_timeout.restart();
1121 if (!bv_->theLockingInset()) {
1122 screen_->CursorToggle(bv_->text, bv_);
1124 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1127 cursor_timeout.restart();
1131 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1133 if (!text->cursor.row()->previous())
1136 int y = text->first;
1137 if (text->inset_owner)
1138 y += bv_->text->first;
1139 Row * cursorrow = text->cursor.row();
1140 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1141 bv_->text->FinishUndo();
1142 // This is to allow jumping over large insets
1143 if ((cursorrow == text->cursor.row()))
1144 text->CursorUp(bv_);
1146 if (text->inset_owner ||
1147 text->cursor.row()->height() < workarea_.height())
1148 screen_->Draw(bv_->text, bv_,
1150 - text->cursor.row()->baseline()
1151 + text->cursor.row()->height()
1152 - workarea_.height() + 1 );
1157 void BufferView::Pimpl::cursorNext(LyXText * text)
1159 if (!text->cursor.row()->next())
1162 int y = text->first + workarea_.height();
1163 // if (text->inset_owner)
1164 // y += bv_->text->first;
1165 text->GetRowNearY(y);
1167 Row * cursorrow = text->cursor.row();
1168 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1169 bv_->text->FinishUndo();
1170 // This is to allow jumping over large insets
1171 if ((cursorrow == bv_->text->cursor.row()))
1172 text->CursorDown(bv_);
1174 if (text->inset_owner ||
1175 text->cursor.row()->height() < workarea_.height())
1176 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1177 text->cursor.row()->baseline());
1182 bool BufferView::Pimpl::available() const
1184 if (buffer_ && bv_->text) return true;
1189 void BufferView::Pimpl::beforeChange(LyXText * text)
1192 text->ClearSelection(bv_);
1196 void BufferView::Pimpl::savePosition(unsigned int i)
1198 if (i >= saved_positions_num)
1200 saved_positions[i] = Position(buffer_->fileName(),
1201 bv_->text->cursor.par()->id(),
1202 bv_->text->cursor.pos());
1204 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1208 void BufferView::Pimpl::restorePosition(unsigned int i)
1210 if (i >= saved_positions_num)
1213 string fname = saved_positions[i].filename;
1215 beforeChange(bv_->text);
1217 if (fname != buffer_->fileName()) {
1218 Buffer * b = bufferlist.exists(fname) ?
1219 bufferlist.getBuffer(fname) :
1220 bufferlist.loadLyXFile(fname); // don't ask, just load it
1221 if (b != 0 ) buffer(b);
1224 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1228 bv_->text->SetCursor(bv_, par,
1229 min(par->Last(), saved_positions[i].par_pos));
1230 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1232 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1236 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1238 if (i >= saved_positions_num)
1241 return !saved_positions[i].filename.empty();
1245 void BufferView::Pimpl::setState()
1247 if (!lyxrc.rtl_support)
1250 LyXText * text = bv_->getLyXText();
1251 if (text->real_current_font.isRightToLeft() &&
1252 text->real_current_font.latex() != LyXFont::ON) {
1253 if (owner_->getIntl()->primarykeymap)
1254 owner_->getIntl()->KeyMapSec();
1256 if (!owner_->getIntl()->primarykeymap)
1257 owner_->getIntl()->KeyMapPrim();
1262 void BufferView::Pimpl::insetSleep()
1264 if (bv_->theLockingInset() && !bv_->inset_slept) {
1265 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1266 bv_->theLockingInset()->InsetUnlock(bv_);
1267 bv_->inset_slept = true;
1272 void BufferView::Pimpl::insetWakeup()
1274 if (bv_->theLockingInset() && bv_->inset_slept) {
1275 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1276 bv_->inset_slept = false;
1281 void BufferView::Pimpl::insetUnlock()
1283 if (bv_->theLockingInset()) {
1284 if (!bv_->inset_slept)
1285 bv_->theLockingInset()->InsetUnlock(bv_);
1286 bv_->theLockingInset(0);
1287 bv_->text->FinishUndo();
1288 bv_->inset_slept = false;
1293 bool BufferView::Pimpl::focus() const
1295 return workarea_.hasFocus();
1299 void BufferView::Pimpl::focus(bool f)
1301 if (f) workarea_.setFocus();
1305 bool BufferView::Pimpl::active() const
1307 return workarea_.active();
1311 bool BufferView::Pimpl::belowMouse() const
1313 return workarea_.belowMouse();
1317 void BufferView::Pimpl::showCursor()
1320 screen_->ShowCursor(bv_->text, bv_);
1324 void BufferView::Pimpl::hideCursor()
1327 screen_->HideCursor();
1331 void BufferView::Pimpl::toggleSelection(bool b)
1334 screen_->ToggleSelection(bv_->text, bv_, b);
1338 void BufferView::Pimpl::toggleToggle()
1341 screen_->ToggleToggle(bv_->text, bv_);
1345 void BufferView::Pimpl::center()
1347 beforeChange(bv_->text);
1348 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1349 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1351 screen_->Draw(bv_->text, bv_, 0);
1353 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1358 void BufferView::Pimpl::pasteClipboard(bool asPara)
1360 if (!buffer_) return;
1362 screen_->HideCursor();
1363 beforeChange(bv_->text);
1365 string const clip(workarea_.getClipboard());
1367 if (clip.empty()) return;
1370 bv_->text->InsertStringB(bv_, clip);
1372 bv_->text->InsertStringA(bv_, clip);
1374 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1378 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1380 workarea_.putClipboard(stuff);
1385 * Dispatch functions for actions which can be valid for BufferView->text
1386 * and/or InsetText->text!!!
1388 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1391 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1393 if (selecting || TEXT(bv_)->mark_set) {
1394 TEXT(bv_)->SetSelection(bv_);
1395 if (TEXT(bv_)->bv_owner)
1396 bv_->toggleToggle();
1398 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1401 /* ---> Everytime the cursor is moved, show the current font state. */
1402 // should this too me moved out of this func?
1403 //owner->showState();
1408 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1410 LyXCursor cursor = TEXT(bv_)->cursor;
1411 Buffer::inset_iterator it =
1412 find_if(Buffer::inset_iterator(
1413 cursor.par(), cursor.pos()),
1414 buffer_->inset_iterator_end(),
1415 compare_memfun(&Inset::LyxCode, code)
1417 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1421 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1423 string filename = filen;
1425 if (filename.empty()) {
1426 // Launch a file browser
1427 string initpath = lyxrc.document_path;
1430 string const trypath = owner_->buffer()->filepath;
1431 // If directory is writeable, use this as default.
1432 if (IsDirWriteable(trypath) == 1)
1436 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1438 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1439 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1441 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1443 if (result.first == FileDialog::Later)
1446 filename = result.second;
1448 // check selected filename
1449 if (filename.empty()) {
1450 owner_->getMiniBuffer()->Set(_("Canceled."));
1455 // get absolute path of file and make sure the filename ends
1457 filename = MakeAbsPath(filename);
1458 if (!IsLyXFilename(filename))
1462 owner_->getMiniBuffer()->Set(_("Inserting document"),
1463 MakeDisplayPath(filename), "...");
1464 bool const res = bv_->insertLyXFile(filename);
1466 owner_->getMiniBuffer()->Set(_("Document"),
1467 MakeDisplayPath(filename),
1470 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1471 MakeDisplayPath(filename));
1476 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1479 // --- Misc -------------------------------------------
1482 TEXT(bv_)->toggleAppendix(bv_);
1483 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1487 case LFUN_TOC_INSERT:
1488 case LFUN_LOA_INSERT:
1489 case LFUN_LOF_INSERT:
1490 case LFUN_LOT_INSERT:
1492 InsetCommandParams p;
1494 if (action == LFUN_TOC_INSERT )
1495 p.setCmdName( "tableofcontents" );
1496 else if (action == LFUN_LOA_INSERT )
1497 p.setCmdName( "listofalgorithms" );
1498 else if (action == LFUN_LOF_INSERT )
1499 p.setCmdName( "listoffigures" );
1501 p.setCmdName( "listoftables" );
1503 Inset * inset = new InsetTOC( p );
1504 if (!bv_->insertInset( inset, "Standard", true ) )
1509 case LFUN_TABULAR_FEATURE:
1510 case LFUN_SCROLL_INSET:
1511 // this is not handled here as this funktion is only aktive
1512 // if we have a locking_inset and that one is (or contains)
1516 case LFUN_INSET_GRAPHICS:
1518 Inset * new_inset = new InsetGraphics;
1519 if (!bv_->insertInset(new_inset)) {
1522 // this is need because you don't use a inset->Edit()
1523 bv_->updateInset(new_inset, true);
1524 new_inset->Edit(bv_, 0, 0, 0);
1534 case LFUN_PASTESELECTION:
1536 bool asPara = false;
1537 if (argument == "paragraph") asPara = true;
1538 pasteClipboard(asPara);
1550 case LFUN_LAYOUT_COPY:
1551 bv_->copyEnvironment();
1554 case LFUN_LAYOUT_PASTE:
1555 bv_->pasteEnvironment();
1559 case LFUN_GOTOERROR:
1560 bv_->gotoInset(Inset::ERROR_CODE, false);
1564 bv_->gotoInset(Inset::IGNORE_CODE, false);
1567 case LFUN_REFERENCE_GOTO:
1569 vector<Inset::Code> tmp;
1570 tmp.push_back(Inset::LABEL_CODE);
1571 tmp.push_back(Inset::REF_CODE);
1572 bv_->gotoInset(tmp, true);
1576 case LFUN_HYPHENATION:
1577 bv_->hyphenationPoint();
1584 case LFUN_END_OF_SENTENCE:
1585 bv_->endOfSentenceDot();
1588 case LFUN_MENU_SEPARATOR:
1589 bv_->menuSeparator();
1597 changeDepth(bv_, TEXT(bv_), 0);
1600 case LFUN_DEPTH_MIN:
1601 changeDepth(bv_, TEXT(bv_), -1);
1604 case LFUN_DEPTH_PLUS:
1605 changeDepth(bv_, TEXT(bv_), 1);
1609 owner_->getDialogs()->setUserFreeFont();
1615 owner_->showState();
1618 case LFUN_FILE_INSERT:
1620 MenuInsertLyXFile(argument);
1624 case LFUN_FILE_INSERT_ASCII_PARA:
1625 InsertAsciiFile(bv_, argument, true);
1628 case LFUN_FILE_INSERT_ASCII:
1629 InsertAsciiFile(bv_, argument, false);
1634 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1635 << argument << endl;
1637 // Derive layout number from given argument (string)
1638 // and current buffer's textclass (number). */
1639 LyXTextClassList::ClassList::size_type tclass =
1640 buffer_->params.textclass;
1641 pair <bool, LyXTextClass::size_type> layout =
1642 textclasslist.NumberOfLayout(tclass, argument);
1644 // If the entry is obsolete, use the new one instead.
1646 string obs = textclasslist.Style(tclass,layout.second)
1650 textclasslist.NumberOfLayout(tclass, obs);
1653 // see if we found the layout number:
1654 if (!layout.first) {
1655 owner_->getLyXFunc()->setErrorMessage(
1656 string(N_("Layout ")) + argument +
1661 if (current_layout != layout.second) {
1663 current_layout = layout.second;
1665 BufferView::SELECT|BufferView::FITCUR);
1666 TEXT(bv_)->SetLayout(bv_, layout.second);
1667 owner_->setLayout(layout.second);
1669 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1676 Lang(bv_, argument);
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1698 owner_->showState();
1703 owner_->showState();
1708 owner_->showState();
1713 owner_->showState();
1716 case LFUN_UNDERLINE:
1718 owner_->showState();
1721 case LFUN_FONT_SIZE:
1722 FontSize(bv_, argument);
1723 owner_->showState();
1726 case LFUN_FONT_STATE:
1727 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1730 case LFUN_UPCASE_WORD:
1731 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1732 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1733 if (TEXT(bv_)->inset_owner)
1734 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1735 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1738 case LFUN_LOWCASE_WORD:
1739 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1740 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1741 if (TEXT(bv_)->inset_owner)
1742 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1743 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1746 case LFUN_CAPITALIZE_WORD:
1747 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1748 TEXT(bv_)->ChangeWordCase(bv_,
1749 LyXText::text_capitalization);
1750 if (TEXT(bv_)->inset_owner)
1751 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1752 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1755 case LFUN_INSERT_LABEL:
1756 MenuInsertLabel(bv_, argument);
1759 case LFUN_REF_INSERT:
1760 if (argument.empty()) {
1761 InsetCommandParams p("ref");
1762 owner_->getDialogs()->createRef(p.getAsString());
1764 InsetCommandParams p;
1765 p.setFromString(argument);
1767 InsetRef * inset = new InsetRef(p, *buffer_);
1768 if (!bv_->insertInset(inset))
1771 bv_->updateInset(inset, true);
1775 case LFUN_BOOKMARK_SAVE:
1776 savePosition(strToUnsignedInt(argument));
1779 case LFUN_BOOKMARK_GOTO:
1780 restorePosition(strToUnsignedInt(argument));
1785 string label(argument);
1786 if (label.empty()) {
1788 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1790 label = inset->getContents();
1795 if (!label.empty()) {
1796 //bv_->savePosition(0);
1797 if (!bv_->gotoLabel(label))
1798 WriteAlert(_("Error"),
1799 _("Couldn't find this label"),
1800 _("in current document."));
1805 // --- Cursor Movements -----------------------------
1808 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1809 if (!TEXT(bv_)->mark_set)
1810 beforeChange(TEXT(bv_));
1811 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1813 TEXT(bv_)->CursorLeft(bv_, false);
1814 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1815 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1816 == LyXParagraph::META_INSET
1817 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1818 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1819 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1820 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1824 TEXT(bv_)->GetFont(buffer_,
1825 TEXT(bv_)->cursor.par(),
1826 TEXT(bv_)->cursor.pos());
1827 y = tmpinset->descent(bv_,font);
1829 tmpinset->Edit(bv_, 0, y, 0);
1833 TEXT(bv_)->CursorRight(bv_, false);
1834 TEXT(bv_)->FinishUndo();
1835 moveCursorUpdate(false);
1836 owner_->showState();
1842 // This is soooo ugly. Isn`t it possible to make
1843 // it simpler? (Lgb)
1844 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1845 if (!TEXT(bv_)->mark_set)
1846 beforeChange(TEXT(bv_));
1847 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1848 LyXCursor cur = TEXT(bv_)->cursor;
1850 TEXT(bv_)->CursorLeft(bv_, false);
1851 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1852 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1853 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1854 LyXParagraph::META_INSET) &&
1855 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1856 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1857 == Inset::HIGHLY_EDITABLE))
1859 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1860 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1861 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1862 TEXT(bv_)->cursor.par(),
1863 TEXT(bv_)->cursor.pos());
1865 : tmpinset->descent(bv_,font);
1868 tmpinset->width(bv_,font),
1873 TEXT(bv_)->CursorRight(bv_, false);
1875 TEXT(bv_)->FinishUndo();
1876 moveCursorUpdate(false);
1877 owner_->showState();
1882 if (!TEXT(bv_)->mark_set)
1883 beforeChange(TEXT(bv_));
1884 update(TEXT(bv_), BufferView::UPDATE);
1885 TEXT(bv_)->CursorUp(bv_);
1886 TEXT(bv_)->FinishUndo();
1887 moveCursorUpdate(false);
1888 owner_->showState();
1892 if (!TEXT(bv_)->mark_set)
1893 beforeChange(TEXT(bv_));
1894 update(TEXT(bv_), BufferView::UPDATE);
1895 TEXT(bv_)->CursorDown(bv_);
1896 TEXT(bv_)->FinishUndo();
1897 moveCursorUpdate(false);
1898 owner_->showState();
1901 case LFUN_UP_PARAGRAPH:
1902 if (!TEXT(bv_)->mark_set)
1903 beforeChange(TEXT(bv_));
1904 update(TEXT(bv_), BufferView::UPDATE);
1905 TEXT(bv_)->CursorUpParagraph(bv_);
1906 TEXT(bv_)->FinishUndo();
1907 moveCursorUpdate(false);
1908 owner_->showState();
1911 case LFUN_DOWN_PARAGRAPH:
1912 if (!TEXT(bv_)->mark_set)
1913 beforeChange(TEXT(bv_));
1914 update(TEXT(bv_), BufferView::UPDATE);
1915 TEXT(bv_)->CursorDownParagraph(bv_);
1916 TEXT(bv_)->FinishUndo();
1917 moveCursorUpdate(false);
1918 owner_->showState();
1922 if (!TEXT(bv_)->mark_set)
1923 beforeChange(TEXT(bv_));
1924 update(TEXT(bv_), BufferView::UPDATE);
1925 cursorPrevious(TEXT(bv_));
1926 TEXT(bv_)->FinishUndo();
1927 moveCursorUpdate(false);
1928 owner_->showState();
1932 if (!TEXT(bv_)->mark_set)
1933 beforeChange(TEXT(bv_));
1934 update(TEXT(bv_), BufferView::UPDATE);
1935 cursorNext(TEXT(bv_));
1936 TEXT(bv_)->FinishUndo();
1937 moveCursorUpdate(false);
1938 owner_->showState();
1942 if (!TEXT(bv_)->mark_set)
1943 beforeChange(TEXT(bv_));
1944 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1945 TEXT(bv_)->CursorHome(bv_);
1946 TEXT(bv_)->FinishUndo();
1947 moveCursorUpdate(false);
1948 owner_->showState();
1952 if (!TEXT(bv_)->mark_set)
1953 beforeChange(TEXT(bv_));
1955 BufferView::SELECT|BufferView::FITCUR);
1956 TEXT(bv_)->CursorEnd(bv_);
1957 TEXT(bv_)->FinishUndo();
1958 moveCursorUpdate(false);
1959 owner_->showState();
1962 case LFUN_SHIFT_TAB:
1964 if (!TEXT(bv_)->mark_set)
1965 beforeChange(TEXT(bv_));
1967 BufferView::SELECT|BufferView::FITCUR);
1968 TEXT(bv_)->CursorTab(bv_);
1969 TEXT(bv_)->FinishUndo();
1970 moveCursorUpdate(false);
1971 owner_->showState();
1974 case LFUN_WORDRIGHT:
1975 if (!TEXT(bv_)->mark_set)
1976 beforeChange(TEXT(bv_));
1977 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1978 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1979 TEXT(bv_)->CursorLeftOneWord(bv_);
1981 TEXT(bv_)->CursorRightOneWord(bv_);
1982 TEXT(bv_)->FinishUndo();
1983 moveCursorUpdate(false);
1984 owner_->showState();
1988 if (!TEXT(bv_)->mark_set)
1989 beforeChange(TEXT(bv_));
1990 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1991 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1992 TEXT(bv_)->CursorRightOneWord(bv_);
1994 TEXT(bv_)->CursorLeftOneWord(bv_);
1995 TEXT(bv_)->FinishUndo();
1996 moveCursorUpdate(false);
1997 owner_->showState();
2000 case LFUN_BEGINNINGBUF:
2001 if (!TEXT(bv_)->mark_set)
2002 beforeChange(TEXT(bv_));
2004 BufferView::SELECT|BufferView::FITCUR);
2005 TEXT(bv_)->CursorTop(bv_);
2006 TEXT(bv_)->FinishUndo();
2007 moveCursorUpdate(false);
2008 owner_->showState();
2012 if (!TEXT(bv_)->mark_set)
2013 beforeChange(TEXT(bv_));
2015 BufferView::SELECT|BufferView::FITCUR);
2016 TEXT(bv_)->CursorBottom(bv_);
2017 TEXT(bv_)->FinishUndo();
2018 moveCursorUpdate(false);
2019 owner_->showState();
2023 /* cursor selection ---------------------------- */
2026 BufferView::SELECT|BufferView::FITCUR);
2027 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2028 TEXT(bv_)->CursorLeft(bv_);
2030 TEXT(bv_)->CursorRight(bv_);
2031 TEXT(bv_)->FinishUndo();
2032 moveCursorUpdate(true);
2033 owner_->showState();
2038 BufferView::SELECT|BufferView::FITCUR);
2039 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2040 TEXT(bv_)->CursorRight(bv_);
2042 TEXT(bv_)->CursorLeft(bv_);
2043 TEXT(bv_)->FinishUndo();
2044 moveCursorUpdate(true);
2045 owner_->showState();
2050 BufferView::SELECT|BufferView::FITCUR);
2051 TEXT(bv_)->CursorUp(bv_);
2052 TEXT(bv_)->FinishUndo();
2053 moveCursorUpdate(true);
2054 owner_->showState();
2059 BufferView::SELECT|BufferView::FITCUR);
2060 TEXT(bv_)->CursorDown(bv_);
2061 TEXT(bv_)->FinishUndo();
2062 moveCursorUpdate(true);
2063 owner_->showState();
2066 case LFUN_UP_PARAGRAPHSEL:
2068 BufferView::SELECT|BufferView::FITCUR);
2069 TEXT(bv_)->CursorUpParagraph(bv_);
2070 TEXT(bv_)->FinishUndo();
2071 moveCursorUpdate(true);
2072 owner_->showState();
2075 case LFUN_DOWN_PARAGRAPHSEL:
2077 BufferView::SELECT|BufferView::FITCUR);
2078 TEXT(bv_)->CursorDownParagraph(bv_);
2079 TEXT(bv_)->FinishUndo();
2080 moveCursorUpdate(true);
2081 owner_->showState();
2085 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2086 cursorPrevious(TEXT(bv_));
2087 TEXT(bv_)->FinishUndo();
2088 moveCursorUpdate(true);
2089 owner_->showState();
2093 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2094 cursorNext(TEXT(bv_));
2095 TEXT(bv_)->FinishUndo();
2096 moveCursorUpdate(true);
2097 owner_->showState();
2101 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2102 TEXT(bv_)->CursorHome(bv_);
2103 TEXT(bv_)->FinishUndo();
2104 moveCursorUpdate(true);
2105 owner_->showState();
2109 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2110 TEXT(bv_)->CursorEnd(bv_);
2111 TEXT(bv_)->FinishUndo();
2112 moveCursorUpdate(true);
2113 owner_->showState();
2116 case LFUN_WORDRIGHTSEL:
2117 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2118 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2119 TEXT(bv_)->CursorLeftOneWord(bv_);
2121 TEXT(bv_)->CursorRightOneWord(bv_);
2122 TEXT(bv_)->FinishUndo();
2123 moveCursorUpdate(true);
2124 owner_->showState();
2127 case LFUN_WORDLEFTSEL:
2128 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2129 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2130 TEXT(bv_)->CursorRightOneWord(bv_);
2132 TEXT(bv_)->CursorLeftOneWord(bv_);
2133 TEXT(bv_)->FinishUndo();
2134 moveCursorUpdate(true);
2135 owner_->showState();
2138 case LFUN_BEGINNINGBUFSEL:
2139 if (TEXT(bv_)->inset_owner)
2141 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2142 TEXT(bv_)->CursorTop(bv_);
2143 TEXT(bv_)->FinishUndo();
2144 moveCursorUpdate(true);
2145 owner_->showState();
2148 case LFUN_ENDBUFSEL:
2149 if (TEXT(bv_)->inset_owner)
2152 BufferView::SELECT|BufferView::FITCUR);
2153 TEXT(bv_)->CursorBottom(bv_);
2154 TEXT(bv_)->FinishUndo();
2155 moveCursorUpdate(true);
2156 owner_->showState();
2159 // --- text changing commands ------------------------
2160 case LFUN_BREAKLINE:
2161 beforeChange(TEXT(bv_));
2162 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2164 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2165 moveCursorUpdate(false);
2168 case LFUN_PROTECTEDSPACE:
2170 LyXLayout const & style =
2171 textclasslist.Style(buffer_->params.textclass,
2172 TEXT(bv_)->cursor.par()->GetLayout());
2174 if (style.free_spacing) {
2175 TEXT(bv_)->InsertChar(bv_, ' ');
2176 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2178 bv_->protectedBlank(TEXT(bv_));
2180 moveCursorUpdate(false);
2185 if (TEXT(bv_)->mark_set) {
2186 beforeChange(TEXT(bv_));
2187 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2188 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2190 beforeChange(TEXT(bv_));
2191 TEXT(bv_)->mark_set = 1;
2192 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2193 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2195 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2199 if (!TEXT(bv_)->selection) {
2200 TEXT(bv_)->Delete(bv_);
2201 TEXT(bv_)->sel_cursor =
2204 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2205 // It is possible to make it a lot faster still
2206 // just comment out the line below...
2211 moveCursorUpdate(false);
2212 owner_->showState();
2216 case LFUN_DELETE_SKIP:
2218 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2220 LyXCursor cursor = TEXT(bv_)->cursor;
2222 if (!TEXT(bv_)->selection) {
2223 if (cursor.pos() == cursor.par()->Last()) {
2224 TEXT(bv_)->CursorRight(bv_);
2225 cursor = TEXT(bv_)->cursor;
2226 if (cursor.pos() == 0
2227 && !(cursor.par()->params.spaceTop()
2228 == VSpace (VSpace::NONE))) {
2229 TEXT(bv_)->SetParagraph
2231 cursor.par()->params.lineTop(),
2232 cursor.par()->params.lineBottom(),
2233 cursor.par()->params.pagebreakTop(),
2234 cursor.par()->params.pagebreakBottom(),
2235 VSpace(VSpace::NONE),
2236 cursor.par()->params.spaceBottom(),
2237 cursor.par()->params.align(),
2238 cursor.par()->params.labelWidthString(), 0);
2239 TEXT(bv_)->CursorLeft(bv_);
2241 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2243 TEXT(bv_)->CursorLeft(bv_);
2244 TEXT(bv_)->Delete(bv_);
2245 TEXT(bv_)->sel_cursor =
2248 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2251 TEXT(bv_)->Delete(bv_);
2252 TEXT(bv_)->sel_cursor =
2255 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2263 /* -------> Delete word forward. */
2264 case LFUN_DELETE_WORD_FORWARD:
2265 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2266 TEXT(bv_)->DeleteWordForward(bv_);
2267 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2268 moveCursorUpdate(false);
2269 owner_->showState();
2272 /* -------> Delete word backward. */
2273 case LFUN_DELETE_WORD_BACKWARD:
2274 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2275 TEXT(bv_)->DeleteWordBackward(bv_);
2276 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2277 moveCursorUpdate(false);
2278 owner_->showState();
2281 /* -------> Kill to end of line. */
2282 case LFUN_DELETE_LINE_FORWARD:
2283 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2284 TEXT(bv_)->DeleteLineForward(bv_);
2285 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2286 moveCursorUpdate(false);
2289 /* -------> Set mark off. */
2291 beforeChange(TEXT(bv_));
2292 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2293 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2294 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2297 /* -------> Set mark on. */
2299 beforeChange(TEXT(bv_));
2300 TEXT(bv_)->mark_set = 1;
2301 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2302 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2303 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2306 case LFUN_BACKSPACE:
2308 if (!TEXT(bv_)->selection) {
2309 if (owner_->getIntl()->getTrans().backspace()) {
2310 TEXT(bv_)->Backspace(bv_);
2311 TEXT(bv_)->sel_cursor =
2314 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2315 // It is possible to make it a lot faster still
2316 // just comment out the line below...
2322 owner_->showState();
2327 case LFUN_BACKSPACE_SKIP:
2329 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2331 LyXCursor cursor = TEXT(bv_)->cursor;
2333 if (!TEXT(bv_)->selection) {
2334 if (cursor.pos() == 0
2335 && !(cursor.par()->params.spaceTop()
2336 == VSpace (VSpace::NONE))) {
2337 TEXT(bv_)->SetParagraph
2339 cursor.par()->params.lineTop(),
2340 cursor.par()->params.lineBottom(),
2341 cursor.par()->params.pagebreakTop(),
2342 cursor.par()->params.pagebreakBottom(),
2343 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2344 cursor.par()->params.align(),
2345 cursor.par()->params.labelWidthString(), 0);
2347 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2349 TEXT(bv_)->Backspace(bv_);
2350 TEXT(bv_)->sel_cursor
2353 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2360 case LFUN_BREAKPARAGRAPH:
2362 beforeChange(TEXT(bv_));
2363 TEXT(bv_)->BreakParagraph(bv_, 0);
2365 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2366 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2368 owner_->showState();
2372 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2374 beforeChange(TEXT(bv_));
2375 TEXT(bv_)->BreakParagraph(bv_, 1);
2377 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2378 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2380 owner_->showState();
2384 case LFUN_BREAKPARAGRAPH_SKIP:
2386 // When at the beginning of a paragraph, remove
2387 // indentation and add a "defskip" at the top.
2388 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2390 LyXCursor cursor = TEXT(bv_)->cursor;
2392 beforeChange(TEXT(bv_));
2393 if (cursor.pos() == 0) {
2394 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2395 TEXT(bv_)->SetParagraph
2397 cursor.par()->params.lineTop(),
2398 cursor.par()->params.lineBottom(),
2399 cursor.par()->params.pagebreakTop(),
2400 cursor.par()->params.pagebreakBottom(),
2401 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2402 cursor.par()->params.align(),
2403 cursor.par()->params.labelWidthString(), 1);
2404 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2408 TEXT(bv_)->BreakParagraph(bv_, 0);
2409 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2413 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2414 TEXT(bv_)->sel_cursor = cursor;
2416 owner_->showState();
2420 case LFUN_PARAGRAPH_SPACING:
2422 LyXParagraph * par = TEXT(bv_)->cursor.par();
2423 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2424 float cur_value = 1.0;
2425 if (cur_spacing == Spacing::Other) {
2426 cur_value = par->params.spacing().getValue();
2429 istringstream istr(argument.c_str());
2433 Spacing::Space new_spacing = cur_spacing;
2434 float new_value = cur_value;
2436 lyxerr << "Missing argument to `paragraph-spacing'"
2438 } else if (tmp == "single") {
2439 new_spacing = Spacing::Single;
2440 } else if (tmp == "onehalf") {
2441 new_spacing = Spacing::Onehalf;
2442 } else if (tmp == "double") {
2443 new_spacing = Spacing::Double;
2444 } else if (tmp == "other") {
2445 new_spacing = Spacing::Other;
2448 lyxerr << "new_value = " << tmpval << endl;
2451 } else if (tmp == "default") {
2452 new_spacing = Spacing::Default;
2454 lyxerr << _("Unknown spacing argument: ")
2455 << argument << endl;
2457 if (cur_spacing != new_spacing || cur_value != new_value) {
2458 par->params.spacing(Spacing(new_spacing, new_value));
2459 TEXT(bv_)->RedoParagraph(bv_);
2461 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2467 beforeChange(TEXT(bv_));
2468 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2469 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2470 moveCursorUpdate(false);
2476 InsetCommandParams p;
2477 if (action == LFUN_HTMLURL)
2478 p.setCmdName("htmlurl");
2480 p.setCmdName("url");
2481 owner_->getDialogs()->createUrl( p.getAsString() );
2485 case LFUN_INSERT_URL:
2487 InsetCommandParams p;
2488 p.setFromString( argument );
2490 InsetUrl * inset = new InsetUrl( p );
2491 if (!bv_->insertInset(inset))
2494 bv_->updateInset( inset, true );
2498 case LFUN_INSET_TEXT:
2500 InsetText * new_inset = new InsetText;
2501 if (bv_->insertInset(new_inset))
2502 new_inset->Edit(bv_, 0, 0, 0);
2508 case LFUN_INSET_ERT:
2510 InsetERT * new_inset = new InsetERT;
2511 if (bv_->insertInset(new_inset))
2512 new_inset->Edit(bv_, 0, 0, 0);
2518 case LFUN_INSET_EXTERNAL:
2520 InsetExternal * new_inset = new InsetExternal;
2521 if (bv_->insertInset(new_inset))
2522 new_inset->Edit(bv_, 0, 0, 0);
2528 case LFUN_INSET_FOOTNOTE:
2530 InsetFoot * new_inset = new InsetFoot;
2531 if (bv_->insertInset(new_inset))
2532 new_inset->Edit(bv_, 0, 0, 0);
2538 case LFUN_INSET_MARGINAL:
2540 InsetMarginal * new_inset = new InsetMarginal;
2541 if (bv_->insertInset(new_inset))
2542 new_inset->Edit(bv_, 0, 0, 0);
2548 case LFUN_INSET_MINIPAGE:
2550 InsetMinipage * new_inset = new InsetMinipage;
2551 if (bv_->insertInset(new_inset))
2552 new_inset->Edit(bv_, 0, 0, 0);
2558 case LFUN_INSET_FLOAT:
2560 // check if the float type exist
2561 if (floatList.typeExist(argument)) {
2562 InsetFloat * new_inset = new InsetFloat(argument);
2563 if (bv_->insertInset(new_inset))
2564 new_inset->Edit(bv_, 0, 0, 0);
2568 lyxerr << "Non-existant float type: "
2569 << argument << endl;
2575 case LFUN_INSET_LIST:
2577 InsetList * new_inset = new InsetList;
2578 if (bv_->insertInset(new_inset))
2579 new_inset->Edit(bv_, 0, 0, 0);
2585 case LFUN_INSET_THEOREM:
2587 InsetTheorem * new_inset = new InsetTheorem;
2588 if (bv_->insertInset(new_inset))
2589 new_inset->Edit(bv_, 0, 0, 0);
2595 case LFUN_INSET_CAPTION:
2597 // Do we have a locking inset...
2598 if (bv_->theLockingInset()) {
2599 lyxerr << "Locking inset code: "
2600 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2601 InsetCaption * new_inset = new InsetCaption;
2602 new_inset->setOwner(bv_->theLockingInset());
2603 new_inset->SetAutoBreakRows(true);
2604 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2605 new_inset->SetFrameColor(0, LColor::footnoteframe);
2606 if (bv_->insertInset(new_inset))
2607 new_inset->Edit(bv_, 0, 0, 0);
2614 case LFUN_INSET_TABULAR:
2617 if (!argument.empty())
2618 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2619 InsetTabular * new_inset =
2620 new InsetTabular(*buffer_, r, c);
2622 TEXT(bv_)->real_current_font.isRightToLeft();
2623 if (!bv_->open_new_inset(new_inset, rtl))
2628 // --- lyxserver commands ----------------------------
2630 case LFUN_CHARATCURSOR:
2632 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2633 if (pos < TEXT(bv_)->cursor.par()->size())
2634 owner_->getLyXFunc()->setMessage(
2635 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2637 owner_->getLyXFunc()->setMessage("EOF");
2642 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2644 + tostr(TEXT(bv_)->cursor.y()));
2651 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2652 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2656 case LFUN_GETLAYOUT:
2657 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2662 LyXFont & font = TEXT(bv_)->current_font;
2663 if (font.shape() == LyXFont::ITALIC_SHAPE)
2664 owner_->getLyXFunc()->setMessage("E");
2665 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2666 owner_->getLyXFunc()->setMessage("N");
2668 owner_->getLyXFunc()->setMessage("0");
2675 LyXFont & font = TEXT(bv_)->current_font;
2676 if (font.latex() == LyXFont::ON)
2677 owner_->getLyXFunc()->setMessage("L");
2679 owner_->getLyXFunc()->setMessage("0");
2683 // --- accented characters ---------------------------
2686 case LFUN_CIRCUMFLEX:
2696 case LFUN_SPECIAL_CARON:
2699 case LFUN_HUNG_UMLAUT:
2702 owner_->getLyXFunc()->handleKeyFunc(action);
2705 // --- insert characters ----------------------------------------
2707 case LFUN_MATH_DELIM:
2708 case LFUN_INSERT_MATRIX:
2711 if (bv_->open_new_inset(new InsetFormula(false)))
2713 bv_->theLockingInset()
2714 ->LocalDispatch(bv_, action, argument);
2720 case LFUN_INSERT_MATH:
2722 math_insert_symbol(bv_, argument);
2726 case LFUN_MATH_DISPLAY:
2729 bv_->open_new_inset(new InsetFormula(true));
2733 case LFUN_MATH_MACRO:
2738 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2740 string const s1 = token(s, ' ', 1);
2741 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2742 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2748 case LFUN_MATH_MODE: // Open or create a math inset
2751 bv_->open_new_inset(new InsetFormula);
2752 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2756 case LFUN_CITATION_INSERT:
2758 InsetCommandParams p;
2759 p.setFromString( argument );
2761 InsetCitation * inset = new InsetCitation( p );
2762 if (!bv_->insertInset(inset))
2765 bv_->updateInset( inset, true );
2769 case LFUN_INSERT_BIBTEX:
2771 // ale970405+lasgoutt970425
2772 // The argument can be up to two tokens separated
2773 // by a space. The first one is the bibstyle.
2774 string const db = token(argument, ' ', 0);
2775 string bibstyle = token(argument, ' ', 1);
2776 if (bibstyle.empty())
2779 InsetCommandParams p( "BibTeX", db, bibstyle );
2780 InsetBibtex * inset = new InsetBibtex(p);
2782 if (bv_->insertInset(inset)) {
2783 if (argument.empty())
2784 inset->Edit(bv_, 0, 0, 0);
2790 // BibTeX data bases
2791 case LFUN_BIBDB_ADD:
2793 InsetBibtex * inset =
2794 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2796 inset->addDatabase(argument);
2801 case LFUN_BIBDB_DEL:
2803 InsetBibtex * inset =
2804 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2806 inset->delDatabase(argument);
2811 case LFUN_BIBTEX_STYLE:
2813 InsetBibtex * inset =
2814 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2816 inset->setOptions(argument);
2821 case LFUN_INDEX_CREATE:
2823 InsetCommandParams p( "index" );
2825 if (argument.empty()) {
2826 // Get the word immediately preceding the cursor
2827 LyXParagraph::size_type curpos =
2828 TEXT(bv_)->cursor.pos() - 1;
2832 curstring = TEXT(bv_)
2833 ->cursor.par()->GetWord(curpos);
2835 p.setContents( curstring );
2837 p.setContents( argument );
2840 owner_->getDialogs()->createIndex( p.getAsString() );
2844 case LFUN_INDEX_INSERT:
2846 InsetCommandParams p;
2847 p.setFromString(argument);
2848 InsetIndex * inset = new InsetIndex(p);
2850 if (!bv_->insertInset(inset))
2853 bv_->updateInset(inset, true);
2857 case LFUN_INDEX_INSERT_LAST:
2859 // Get word immediately preceding the cursor
2860 LyXParagraph::size_type curpos =
2861 TEXT(bv_)->cursor.pos() - 1;
2862 // Can't do that at the beginning of a paragraph
2863 if (curpos < 0) break;
2865 string const curstring(TEXT(bv_)
2866 ->cursor.par()->GetWord(curpos));
2868 InsetCommandParams p("index", curstring);
2869 InsetIndex * inset = new InsetIndex(p);
2871 if (!bv_->insertInset(inset))
2874 bv_->updateInset(inset, true);
2878 case LFUN_INDEX_PRINT:
2880 InsetCommandParams p("printindex");
2881 Inset * inset = new InsetPrintIndex(p);
2882 if (!bv_->insertInset(inset, "Standard", true))
2887 case LFUN_PARENTINSERT:
2889 lyxerr << "arg " << argument << endl;
2890 InsetCommandParams p( "lyxparent", argument );
2891 Inset * inset = new InsetParent(p, *buffer_);
2892 if (!bv_->insertInset(inset, "Standard", true))
2897 case LFUN_CHILD_INSERT:
2899 InsetCommandParams p;
2900 p.setFromString(argument);
2902 InsetInclude * inset = new InsetInclude(p, *buffer_);
2903 if (!bv_->insertInset(inset))
2906 bv_->updateInset(inset, true);
2910 case LFUN_INSERT_NOTE:
2914 case LFUN_SELFINSERT:
2916 LyXFont const old_font(TEXT(bv_)->real_current_font);
2917 for (string::size_type i = 0; i < argument.length(); ++i) {
2918 TEXT(bv_)->InsertChar(bv_, argument[i]);
2919 // This needs to be in the loop, or else we
2920 // won't break lines correctly. (Asger)
2922 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2924 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2925 moveCursorUpdate(false);
2927 // real_current_font.number can change so we need to
2928 // update the minibuffer
2929 if (old_font != TEXT(bv_)->real_current_font)
2930 owner_->showState();
2934 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2938 time_t now_time_t = time(NULL);
2939 now_tm = localtime(&now_time_t);
2940 setlocale(LC_TIME, "");
2942 if (!argument.empty())
2945 arg = lyxrc.date_insert_format;
2947 int const datetmp_len =
2948 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2949 for (int i = 0; i < datetmp_len; i++) {
2950 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2952 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2955 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2956 moveCursorUpdate(false);
2960 case LFUN_UNKNOWN_ACTION:
2963 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2967 if (buffer_->isReadonly()) {
2968 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
2971 if (!argument.empty()) {
2972 /* Automatically delete the currently selected
2973 * text and replace it with what is being
2974 * typed in now. Depends on lyxrc settings
2975 * "auto_region_delete", which defaults to
2978 if (lyxrc.auto_region_delete) {
2979 if (TEXT(bv_)->selection){
2980 TEXT(bv_)->CutSelection(bv_, false);
2982 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2986 beforeChange(TEXT(bv_));
2987 LyXFont const old_font(TEXT(bv_)->real_current_font);
2988 for (string::size_type i = 0;
2989 i < argument.length(); ++i) {
2990 if (greek_kb_flag) {
2991 if (!math_insert_greek(bv_,
2993 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2995 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2998 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3000 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3001 moveCursorUpdate(false);
3003 // real_current_font.number can change so we need to
3004 // update the minibuffer
3005 if (old_font != TEXT(bv_)->real_current_font)
3006 owner_->showState();
3008 // if we don't have an argument there was something
3009 // strange going on so we just tell this to someone!
3010 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));