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 int greek_kb_flag;
70 /* the selection possible is needed, that only motion events are
71 * used, where the bottom press event was on the drawing area too */
72 bool selection_possible = false;
74 extern BufferList bufferlist;
75 extern char ascii_type;
77 extern bool math_insert_greek(BufferView *, char);
78 extern void sigchldhandler(pid_t pid, int * status);
79 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
81 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());
110 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
111 int xpos, int ypos, int width, int height)
112 : bv_(b), owner_(o), buffer_(0),
113 current_scrollbar_value(0), cursor_timeout(400),
114 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
117 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
118 workarea_.workAreaExpose
119 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
120 workarea_.workAreaEnter
121 .connect(slot(this, &BufferView::Pimpl::enterView));
122 workarea_.workAreaLeave
123 .connect(slot(this, &BufferView::Pimpl::leaveView));
124 workarea_.workAreaButtonPress
125 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
126 workarea_.workAreaButtonRelease
128 &BufferView::Pimpl::workAreaButtonRelease));
129 workarea_.workAreaMotionNotify
130 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
131 workarea_.workAreaDoubleClick
132 .connect(slot(this, &BufferView::Pimpl::doubleClick));
133 workarea_.workAreaTripleClick
134 .connect(slot(this, &BufferView::Pimpl::tripleClick));
135 workarea_.workAreaKeyPress
136 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
140 cursor_timeout.timeout.connect(slot(this,
141 &BufferView::Pimpl::cursorToggle));
142 //current_scrollbar_value = 0;
143 cursor_timeout.start();
144 workarea_.setFocus();
145 //using_xterm_cursor = false;
146 saved_positions.resize(saved_positions_num);
150 Painter & BufferView::Pimpl::painter()
152 return workarea_.getPainter();
156 void BufferView::Pimpl::buffer(Buffer * b)
158 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
162 buffer_->delUser(bv_);
164 // Put the old text into the TextCache, but
165 // only if the buffer is still loaded.
166 // Also set the owner of the test to 0
167 // bv_->text->owner(0);
168 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
169 if (lyxerr.debugging())
170 textcache.show(lyxerr, "BufferView::buffer");
175 // Set current buffer
178 if (bufferlist.getState() == BufferList::CLOSING) return;
181 // screen is always deleted when the buffer is changed.
186 // If we are closing the buffer, use the first buffer as current
188 buffer_ = bufferlist.first();
192 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
193 buffer_->addUser(bv_);
194 // If we don't have a text object for this, we make one
195 if (bv_->text == 0) {
196 resizeCurrentBuffer();
201 bv_->text->first = screen_->TopCursorVisible(bv_->text);
202 owner_->updateMenubar();
203 owner_->updateToolbar();
204 // Similarly, buffer-dependent dialogs should be updated or
205 // hidden. This should go here because some dialogs (eg ToC)
206 // require bv_->text.
207 owner_->getDialogs()->updateBufferDependent(true);
211 lyxerr[Debug::INFO] << " No Buffer!" << endl;
212 owner_->updateMenubar();
213 owner_->updateToolbar();
214 owner_->getDialogs()->hideBufferDependent();
218 // Also remove all remaining text's from the testcache.
219 // (there should not be any!) (if there is any it is a
221 if (lyxerr.debugging())
222 textcache.show(lyxerr, "buffer delete all");
225 // should update layoutchoice even if we don't have a buffer.
226 owner_->updateLayoutChoice();
227 owner_->getMiniBuffer()->Init();
228 owner_->updateWindowTitle();
232 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
234 workarea_.resize(xpos, ypos, width, height);
235 update(bv_->text, SELECT);
240 void BufferView::Pimpl::resize()
243 resizeCurrentBuffer();
247 void BufferView::Pimpl::redraw()
249 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
254 bool BufferView::Pimpl::fitCursor(LyXText * text)
256 Assert(screen_.get());
258 bool ret = screen_->FitCursor(text, bv_);
265 void BufferView::Pimpl::redoCurrentBuffer()
267 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
268 if (buffer_ && bv_->text) {
270 owner_->updateLayoutChoice();
275 int BufferView::Pimpl::resizeCurrentBuffer()
277 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
279 LyXParagraph * par = 0;
280 LyXParagraph * selstartpar = 0;
281 LyXParagraph * selendpar = 0;
282 UpdatableInset * the_locking_inset = 0;
284 LyXParagraph::size_type pos = 0;
285 LyXParagraph::size_type selstartpos = 0;
286 LyXParagraph::size_type selendpos = 0;
287 bool selection = false;
288 bool mark_set = false;
292 owner_->getMiniBuffer()->Set(_("Formatting document..."));
295 par = bv_->text->cursor.par();
296 pos = bv_->text->cursor.pos();
297 selstartpar = bv_->text->sel_start_cursor.par();
298 selstartpos = bv_->text->sel_start_cursor.pos();
299 selendpar = bv_->text->sel_end_cursor.par();
300 selendpos = bv_->text->sel_end_cursor.pos();
301 selection = bv_->text->selection;
302 mark_set = bv_->text->mark_set;
303 the_locking_inset = bv_->text->the_locking_inset;
305 bv_->text = new LyXText(bv_);
307 // See if we have a text in TextCache that fits
308 // the new buffer_ with the correct width.
309 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
311 if (lyxerr.debugging()) {
312 lyxerr << "Found a LyXText that fits:\n";
313 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
315 // Set the owner of the newly found text
316 // bv_->text->owner(bv_);
317 if (lyxerr.debugging())
318 textcache.show(lyxerr, "resizeCurrentBuffer");
320 bv_->text = new LyXText(bv_);
326 bv_->text->selection = true;
327 /* at this point just to avoid the Delete-Empty-Paragraph
328 * Mechanism when setting the cursor */
329 bv_->text->mark_set = mark_set;
331 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
332 bv_->text->sel_cursor = bv_->text->cursor;
333 bv_->text->SetCursor(bv_, selendpar, selendpos);
334 bv_->text->SetSelection(bv_);
335 bv_->text->SetCursor(bv_, par, pos);
337 bv_->text->SetCursor(bv_, par, pos);
338 bv_->text->sel_cursor = bv_->text->cursor;
339 bv_->text->selection = false;
341 // remake the inset locking
342 bv_->text->the_locking_inset = the_locking_inset;
344 bv_->text->first = screen_->TopCursorVisible(bv_->text);
345 buffer_->resizeInsets(bv_);
346 // this will scroll the screen such that the cursor becomes visible
349 owner_->getMiniBuffer()->Init();
353 /// get rid of the splash screen if it's not gone already
354 owner_->getDialogs()->destroySplash();
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;
777 // Did we hit an editable inset?
779 // Inset like error, notes and figures
780 selection_possible = false;
782 // CHECK fix this proper in 0.13
784 // Following a ref shouldn't issue
785 // a push on the undo-stack
786 // anylonger, now that we have
787 // keybindings for following
788 // references and returning from
789 // references. IMHO though, it
790 // should be the inset's own business
791 // to push or not push on the undo
792 // stack. They don't *have* to
793 // alter the document...
795 // ...or maybe the SetCursorParUndo()
796 // below isn't necessary at all anylonger?
797 if (inset_hit->LyxCode() == Inset::REF_CODE) {
798 bv_->text->SetCursorParUndo(bv_->buffer());
801 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
802 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
803 // Highly editable inset, like math
804 UpdatableInset *inset = (UpdatableInset *)inset_hit;
805 inset->InsetButtonRelease(bv_, x, y, button);
807 inset_hit->InsetButtonRelease(bv_, x, y, button);
808 inset_hit->Edit(bv_, x, y, button);
814 // check whether we want to open a float
818 if (bv_->text->cursor.pos() <
819 bv_->text->cursor.par()->Last()) {
820 c = bv_->text->cursor.par()->
821 GetChar(bv_->text->cursor.pos());
823 if(!bv_->text->selection)
824 if (c == LyXParagraph::META_FOOTNOTE
825 || c == LyXParagraph::META_MARGIN
826 || c == LyXParagraph::META_FIG
827 || c == LyXParagraph::META_TAB
828 || c == LyXParagraph::META_WIDE_FIG
829 || c == LyXParagraph::META_WIDE_TAB
830 || 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);
836 if (c == LyXParagraph::META_FOOTNOTE
837 || c == LyXParagraph::META_MARGIN
838 || c == LyXParagraph::META_FIG
839 || c == LyXParagraph::META_TAB
840 || c == LyXParagraph::META_WIDE_FIG
841 || c == LyXParagraph::META_WIDE_TAB
842 || c == LyXParagraph::META_ALGORITHM){
843 // We are one step too far to the right
844 bv_->text->CursorLeft(bv_);
850 selection_possible = false;
854 // Do we want to close a float? (click on the float-label)
855 if (bv_->text->cursor.row()->par()->footnoteflag ==
856 LyXParagraph::OPEN_FOOTNOTE
857 && bv_->text->cursor.row()->previous() &&
858 bv_->text->cursor.row()->previous()->par()->
859 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
860 LyXFont font(LyXFont::ALL_SANE);
861 font.setSize(LyXFont::SIZE_FOOTNOTE);
863 int box_x = 20; // LYX_PAPER_MARGIN;
864 box_x += lyxfont::width(" wide-tab ", font);
866 unsigned int screen_first = bv_->text->first;
869 && y + screen_first > bv_->text->cursor.y() -
870 bv_->text->cursor.row()->baseline()
871 && y + screen_first < bv_->text->cursor.y() -
872 bv_->text->cursor.row()->baseline()
873 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
875 selection_possible = false;
880 // check whether we want to open a float
884 if (bv_->text->cursor.pos() <
885 bv_->text->cursor.par()->size()) {
886 c = bv_->text->cursor.par()->
887 GetChar(bv_->text->cursor.pos());
889 if (bv_->text->cursor.pos() - 1 >= 0) {
890 c = bv_->text->cursor.par()->
891 GetChar(bv_->text->cursor.pos() - 1);
894 selection_possible = false;
899 // Maybe we want to edit a bibitem ale970302
900 if (bv_->text->cursor.par()->bibkey && x < 20 +
901 bibitemMaxWidth(bv_, textclasslist.
903 params.textclass).defaultfont())) {
904 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
912 * Returns an inset if inset was hit. 0 otherwise.
913 * If hit, the coordinates are changed relative to the inset.
914 * Otherwise coordinates are not changed, and false is returned.
916 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
917 unsigned int /* button */)
922 int y_tmp = y + text->first;
925 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
928 if (cursor.pos() < cursor.par()->Last()
930 if (cursor.pos() < cursor.par()->size()
932 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
933 && cursor.par()->GetInset(cursor.pos())
934 && cursor.par()->GetInset(cursor.pos())->Editable()) {
936 // Check whether the inset really was hit
937 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
938 LyXFont font = text->GetFont(bv_->buffer(),
939 cursor.par(), cursor.pos());
940 int width = tmpinset->width(bv_, font);
941 int inset_x = font.isVisibleRightToLeft()
942 ? cursor.x() - width : cursor.x();
943 int start_x = inset_x + tmpinset->scroll();
944 int end_x = inset_x + width;
946 if (x > start_x && x < end_x
947 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
948 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
949 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
951 // The origin of an inset is on the baseline
952 y = y_tmp - (text->cursor.y());
957 if ((cursor.pos() - 1 >= 0) &&
958 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
959 (cursor.par()->GetInset(cursor.pos() - 1)) &&
960 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
961 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
962 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
964 int width = tmpinset->width(bv_, font);
965 int inset_x = font.isVisibleRightToLeft()
966 ? cursor.x() : cursor.x() - width;
967 int start_x = inset_x + tmpinset->scroll();
968 int end_x = inset_x + width;
970 if (x > start_x && x < end_x
971 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
972 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
974 if (move_cursor && (tmpinset != bv_->theLockingInset()))
976 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
978 // The origin of an inset is on the baseline
979 y = y_tmp - (text->cursor.y());
987 void BufferView::Pimpl::workAreaExpose()
989 static int work_area_width = 0;
990 static unsigned int work_area_height = 0;
992 bool widthChange = workarea_.workWidth() != work_area_width;
993 bool heightChange = workarea_.height() != work_area_height;
995 // update from work area
996 work_area_width = workarea_.workWidth();
997 work_area_height = workarea_.height();
1000 // All buffers need a resize
1001 bufferlist.resize();
1003 // Remove all texts from the textcache
1004 // This is not _really_ what we want to do. What
1005 // we really want to do is to delete in textcache
1006 // that does not have a BufferView with matching
1007 // width, but as long as we have only one BufferView
1008 // deleting all gives the same result.
1009 if (lyxerr.debugging())
1010 textcache.show(lyxerr, "Expose delete all");
1012 } else if (heightChange) {
1013 // Rebuild image of current screen
1015 // fitCursor() ensures we don't jump back
1016 // to the start of the document on vertical
1018 fitCursor(bv_->text);
1020 // The main window size has changed, repaint most stuff
1022 // ...including the minibuffer
1023 owner_->getMiniBuffer()->Init();
1025 } else if (screen_.get())
1026 screen_->Redraw(bv_->text, bv_);
1028 // Grey box when we don't have a buffer
1029 workarea_.greyOut();
1032 // always make sure that the scrollbar is sane.
1034 owner_->updateLayoutChoice();
1039 void BufferView::Pimpl::update()
1041 if (screen_.get()) screen_->Update(bv_->text, bv_);
1044 // Values used when calling update:
1046 // -2 - update, move sel_cursor if selection, fitcursor
1047 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1048 // 0 - update, move sel_cursor if selection, fitcursor
1049 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1050 // 3 - update, move sel_cursor if selection
1053 // a simple redraw of the parts that need refresh
1055 // move sel_cursor if selection -
1056 // the text's sel_cursor is moved if there is selection is progress
1059 // fitCursor() is called and the scrollbar updated
1062 // the buffer is marked dirty.
1071 // UPDATE_ONLY = UPDATE;
1072 // UPDATE_SELECT = UPDATE | SELECT;
1073 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1074 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1076 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1077 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1078 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1079 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1080 // update(3) -> update(1) -> update(1) -> update(SELECT)
1082 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1084 owner_->updateLayoutChoice();
1086 if (!text->selection && (f & SELECT)) {
1087 text->sel_cursor = text->cursor;
1090 text->FullRebreak(bv_);
1092 if (text->inset_owner) {
1093 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1094 bv_->updateInset(text->inset_owner, true);
1103 if (buffer_->isLyxClean()) {
1104 buffer_->markDirty();
1105 owner_->getMiniBuffer()->setTimer(4);
1107 buffer_->markDirty();
1113 // Callback for cursor timer
1114 void BufferView::Pimpl::cursorToggle()
1116 // Quite a nice place for asyncron Inset updating, isn't it?
1117 // Actually no! This is run even if no buffer exist... so (Lgb)
1119 cursor_timeout.restart();
1124 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1125 if (pid == -1) // error find out what is wrong
1126 ; // ignore it for now.
1128 sigchldhandler(pid, &status);
1130 updatelist.update(bv_);
1132 if (!screen_.get()) {
1133 cursor_timeout.restart();
1137 if (!bv_->theLockingInset()) {
1138 screen_->CursorToggle(bv_->text, bv_);
1140 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1143 cursor_timeout.restart();
1147 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1149 if (!text->cursor.row()->previous())
1152 int y = text->first;
1153 if (text->inset_owner)
1154 y += bv_->text->first;
1155 Row * cursorrow = text->cursor.row();
1156 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1157 bv_->text->FinishUndo();
1158 // This is to allow jumping over large insets
1159 if ((cursorrow == text->cursor.row()))
1160 text->CursorUp(bv_);
1162 if (text->inset_owner ||
1163 text->cursor.row()->height() < workarea_.height())
1164 screen_->Draw(bv_->text, bv_,
1166 - text->cursor.row()->baseline()
1167 + text->cursor.row()->height()
1168 - workarea_.height() + 1 );
1173 void BufferView::Pimpl::cursorNext(LyXText * text)
1175 if (!text->cursor.row()->next())
1178 int y = text->first + workarea_.height();
1179 // if (text->inset_owner)
1180 // y += bv_->text->first;
1181 text->GetRowNearY(y);
1183 Row * cursorrow = text->cursor.row();
1184 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1185 bv_->text->FinishUndo();
1186 // This is to allow jumping over large insets
1187 if ((cursorrow == bv_->text->cursor.row()))
1188 text->CursorDown(bv_);
1190 if (text->inset_owner ||
1191 text->cursor.row()->height() < workarea_.height())
1192 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1193 text->cursor.row()->baseline());
1198 bool BufferView::Pimpl::available() const
1200 if (buffer_ && bv_->text) return true;
1205 void BufferView::Pimpl::beforeChange(LyXText * text)
1208 text->ClearSelection(bv_);
1212 void BufferView::Pimpl::savePosition(unsigned int i)
1214 if (i >= saved_positions_num)
1216 saved_positions[i] = Position(buffer_->fileName(),
1217 bv_->text->cursor.par()->id(),
1218 bv_->text->cursor.pos());
1220 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1224 void BufferView::Pimpl::restorePosition(unsigned int i)
1226 if (i >= saved_positions_num)
1229 string fname = saved_positions[i].filename;
1231 beforeChange(bv_->text);
1233 if (fname != buffer_->fileName()) {
1234 Buffer * b = bufferlist.exists(fname) ?
1235 bufferlist.getBuffer(fname) :
1236 bufferlist.loadLyXFile(fname); // don't ask, just load it
1237 if (b != 0 ) buffer(b);
1240 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1245 bv_->text->SetCursor(bv_, par,
1246 min(par->Last(), saved_positions[i].par_pos));
1248 bv_->text->SetCursor(bv_, par,
1249 min(par->size(), saved_positions[i].par_pos));
1251 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1253 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1257 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1259 if (i >= saved_positions_num)
1262 return !saved_positions[i].filename.empty();
1266 void BufferView::Pimpl::setState()
1268 if (!lyxrc.rtl_support)
1271 LyXText * text = bv_->getLyXText();
1272 if (text->real_current_font.isRightToLeft() &&
1273 text->real_current_font.latex() != LyXFont::ON) {
1274 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1275 owner_->getIntl()->KeyMapSec();
1277 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1278 owner_->getIntl()->KeyMapPrim();
1283 void BufferView::Pimpl::insetSleep()
1285 if (bv_->theLockingInset() && !bv_->inset_slept) {
1286 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1287 bv_->theLockingInset()->InsetUnlock(bv_);
1288 bv_->inset_slept = true;
1293 void BufferView::Pimpl::insetWakeup()
1295 if (bv_->theLockingInset() && bv_->inset_slept) {
1296 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1297 bv_->inset_slept = false;
1302 void BufferView::Pimpl::insetUnlock()
1304 if (bv_->theLockingInset()) {
1305 if (!bv_->inset_slept)
1306 bv_->theLockingInset()->InsetUnlock(bv_);
1307 bv_->theLockingInset(0);
1308 bv_->text->FinishUndo();
1309 bv_->inset_slept = false;
1314 bool BufferView::Pimpl::focus() const
1316 return workarea_.hasFocus();
1320 void BufferView::Pimpl::focus(bool f)
1322 if (f) workarea_.setFocus();
1326 bool BufferView::Pimpl::active() const
1328 return workarea_.active();
1332 bool BufferView::Pimpl::belowMouse() const
1334 return workarea_.belowMouse();
1338 void BufferView::Pimpl::showCursor()
1341 screen_->ShowCursor(bv_->text, bv_);
1345 void BufferView::Pimpl::hideCursor()
1348 screen_->HideCursor();
1352 void BufferView::Pimpl::toggleSelection(bool b)
1355 screen_->ToggleSelection(bv_->text, bv_, b);
1359 void BufferView::Pimpl::toggleToggle()
1362 screen_->ToggleToggle(bv_->text, bv_);
1366 void BufferView::Pimpl::center()
1368 beforeChange(bv_->text);
1369 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1370 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1372 screen_->Draw(bv_->text, bv_, 0);
1374 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1379 void BufferView::Pimpl::pasteClipboard(bool asPara)
1381 if (!buffer_) return;
1383 screen_->HideCursor();
1384 beforeChange(bv_->text);
1386 string const clip(workarea_.getClipboard());
1388 if (clip.empty()) return;
1391 bv_->text->InsertStringB(bv_, clip);
1393 bv_->text->InsertStringA(bv_, clip);
1395 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1399 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1401 workarea_.putClipboard(stuff);
1406 * Dispatch functions for actions which can be valid for BufferView->text
1407 * and/or InsetText->text!!!
1409 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1412 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1414 if (selecting || TEXT(bv_)->mark_set) {
1415 TEXT(bv_)->SetSelection(bv_);
1416 if (TEXT(bv_)->bv_owner)
1417 bv_->toggleToggle();
1419 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1422 /* ---> Everytime the cursor is moved, show the current font state. */
1423 // should this too me moved out of this func?
1424 //owner->showState();
1429 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1431 LyXCursor cursor = TEXT(bv_)->cursor;
1432 Buffer::inset_iterator it =
1433 find_if(Buffer::inset_iterator(
1434 cursor.par(), cursor.pos()),
1435 buffer_->inset_iterator_end(),
1436 compare_memfun(&Inset::LyxCode, code)
1438 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1442 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1444 string filename = filen;
1446 if (filename.empty()) {
1447 // Launch a file browser
1448 string initpath = lyxrc.document_path;
1451 string const trypath = owner_->buffer()->filepath;
1452 // If directory is writeable, use this as default.
1453 if (IsDirWriteable(trypath) == 1)
1457 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1459 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1460 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1462 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1464 if (result.first == FileDialog::Later)
1467 filename = result.second;
1469 // check selected filename
1470 if (filename.empty()) {
1471 owner_->getMiniBuffer()->Set(_("Canceled."));
1476 // get absolute path of file and make sure the filename ends
1478 filename = MakeAbsPath(filename);
1479 if (!IsLyXFilename(filename))
1483 owner_->getMiniBuffer()->Set(_("Inserting document"),
1484 MakeDisplayPath(filename), "...");
1485 bool const res = bv_->insertLyXFile(filename);
1487 owner_->getMiniBuffer()->Set(_("Document"),
1488 MakeDisplayPath(filename),
1491 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1492 MakeDisplayPath(filename));
1497 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1500 // --- Misc -------------------------------------------
1503 TEXT(bv_)->toggleAppendix(bv_);
1504 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1508 case LFUN_TOC_INSERT:
1509 case LFUN_LOA_INSERT:
1510 case LFUN_LOF_INSERT:
1511 case LFUN_LOT_INSERT:
1513 InsetCommandParams p;
1515 if (action == LFUN_TOC_INSERT )
1516 p.setCmdName( "tableofcontents" );
1517 else if (action == LFUN_LOA_INSERT )
1518 p.setCmdName( "listofalgorithms" );
1519 else if (action == LFUN_LOF_INSERT )
1520 p.setCmdName( "listoffigures" );
1522 p.setCmdName( "listoftables" );
1524 Inset * inset = new InsetTOC( p );
1525 if (!bv_->insertInset( inset, "Standard", true ) )
1530 case LFUN_TABULAR_FEATURE:
1531 case LFUN_SCROLL_INSET:
1532 // this is not handled here as this funktion is only aktive
1533 // if we have a locking_inset and that one is (or contains)
1537 case LFUN_INSET_GRAPHICS:
1539 Inset * new_inset = new InsetGraphics;
1540 if (!bv_->insertInset(new_inset)) {
1543 // this is need because you don't use a inset->Edit()
1544 bv_->updateInset(new_inset, true);
1545 new_inset->Edit(bv_, 0, 0, 0);
1555 case LFUN_PASTESELECTION:
1557 bool asPara = false;
1558 if (argument == "paragraph") asPara = true;
1559 pasteClipboard(asPara);
1571 case LFUN_LAYOUT_COPY:
1572 bv_->copyEnvironment();
1575 case LFUN_LAYOUT_PASTE:
1576 bv_->pasteEnvironment();
1580 case LFUN_GOTOERROR:
1581 bv_->gotoInset(Inset::ERROR_CODE, false);
1585 bv_->gotoInset(Inset::IGNORE_CODE, false);
1588 case LFUN_REFERENCE_GOTO:
1590 vector<Inset::Code> tmp;
1591 tmp.push_back(Inset::LABEL_CODE);
1592 tmp.push_back(Inset::REF_CODE);
1593 bv_->gotoInset(tmp, true);
1597 case LFUN_HYPHENATION:
1598 bv_->hyphenationPoint();
1605 case LFUN_END_OF_SENTENCE:
1606 bv_->endOfSentenceDot();
1609 case LFUN_MENU_SEPARATOR:
1610 bv_->menuSeparator();
1618 changeDepth(bv_, TEXT(bv_), 0);
1621 case LFUN_DEPTH_MIN:
1622 changeDepth(bv_, TEXT(bv_), -1);
1625 case LFUN_DEPTH_PLUS:
1626 changeDepth(bv_, TEXT(bv_), 1);
1630 owner_->getDialogs()->setUserFreeFont();
1636 owner_->showState();
1639 case LFUN_FILE_INSERT:
1641 MenuInsertLyXFile(argument);
1645 case LFUN_FILE_INSERT_ASCII_PARA:
1646 InsertAsciiFile(bv_, argument, true);
1649 case LFUN_FILE_INSERT_ASCII:
1650 InsertAsciiFile(bv_, argument, false);
1655 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1656 << argument << endl;
1658 // Derive layout number from given argument (string)
1659 // and current buffer's textclass (number). */
1660 LyXTextClassList::ClassList::size_type tclass =
1661 buffer_->params.textclass;
1662 pair <bool, LyXTextClass::size_type> layout =
1663 textclasslist.NumberOfLayout(tclass, argument);
1665 // If the entry is obsolete, use the new one instead.
1667 string obs = textclasslist.Style(tclass,layout.second)
1671 textclasslist.NumberOfLayout(tclass, obs);
1674 // see if we found the layout number:
1675 if (!layout.first) {
1676 owner_->getLyXFunc()->setErrorMessage(
1677 string(N_("Layout ")) + argument +
1682 if (current_layout != layout.second) {
1684 current_layout = layout.second;
1686 BufferView::SELECT|BufferView::FITCUR);
1687 TEXT(bv_)->SetLayout(bv_, layout.second);
1688 owner_->setLayout(layout.second);
1690 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1697 Lang(bv_, argument);
1699 owner_->showState();
1704 owner_->showState();
1709 owner_->showState();
1714 owner_->showState();
1719 owner_->showState();
1724 owner_->showState();
1729 owner_->showState();
1734 owner_->showState();
1737 case LFUN_UNDERLINE:
1739 owner_->showState();
1742 case LFUN_FONT_SIZE:
1743 FontSize(bv_, argument);
1744 owner_->showState();
1747 case LFUN_FONT_STATE:
1748 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1751 case LFUN_UPCASE_WORD:
1752 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1753 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1754 if (TEXT(bv_)->inset_owner)
1755 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1756 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1759 case LFUN_LOWCASE_WORD:
1760 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1761 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1762 if (TEXT(bv_)->inset_owner)
1763 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1764 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1767 case LFUN_CAPITALIZE_WORD:
1768 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1769 TEXT(bv_)->ChangeWordCase(bv_,
1770 LyXText::text_capitalization);
1771 if (TEXT(bv_)->inset_owner)
1772 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1773 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1776 case LFUN_INSERT_LABEL:
1777 MenuInsertLabel(bv_, argument);
1780 case LFUN_REF_INSERT:
1781 if (argument.empty()) {
1782 InsetCommandParams p("ref");
1783 owner_->getDialogs()->createRef(p.getAsString());
1785 InsetCommandParams p;
1786 p.setFromString(argument);
1788 InsetRef * inset = new InsetRef(p, *buffer_);
1789 if (!bv_->insertInset(inset))
1792 bv_->updateInset(inset, true);
1796 case LFUN_BOOKMARK_SAVE:
1797 savePosition(strToUnsignedInt(argument));
1800 case LFUN_BOOKMARK_GOTO:
1801 restorePosition(strToUnsignedInt(argument));
1806 string label(argument);
1807 if (label.empty()) {
1809 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1811 label = inset->getContents();
1816 if (!label.empty()) {
1817 //bv_->savePosition(0);
1818 if (!bv_->gotoLabel(label))
1819 WriteAlert(_("Error"),
1820 _("Couldn't find this label"),
1821 _("in current document."));
1826 // --- Cursor Movements -----------------------------
1829 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1830 if (!TEXT(bv_)->mark_set)
1831 beforeChange(TEXT(bv_));
1832 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1834 TEXT(bv_)->CursorLeft(bv_, false);
1836 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1838 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
1840 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1841 == LyXParagraph::META_INSET
1842 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1843 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1844 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1845 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1849 TEXT(bv_)->GetFont(buffer_,
1850 TEXT(bv_)->cursor.par(),
1851 TEXT(bv_)->cursor.pos());
1852 y = tmpinset->descent(bv_,font);
1854 tmpinset->Edit(bv_, 0, y, 0);
1858 TEXT(bv_)->CursorRight(bv_, false);
1859 TEXT(bv_)->FinishUndo();
1860 moveCursorUpdate(false);
1861 owner_->showState();
1867 // This is soooo ugly. Isn`t it possible to make
1868 // it simpler? (Lgb)
1869 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1870 if (!TEXT(bv_)->mark_set)
1871 beforeChange(TEXT(bv_));
1872 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1873 LyXCursor cur = TEXT(bv_)->cursor;
1875 TEXT(bv_)->CursorLeft(bv_, false);
1876 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1878 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1880 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
1882 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1883 LyXParagraph::META_INSET) &&
1884 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1885 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1886 == Inset::HIGHLY_EDITABLE))
1888 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1889 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1890 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1891 TEXT(bv_)->cursor.par(),
1892 TEXT(bv_)->cursor.pos());
1894 : tmpinset->descent(bv_,font);
1897 tmpinset->width(bv_,font),
1902 TEXT(bv_)->CursorRight(bv_, false);
1904 TEXT(bv_)->FinishUndo();
1905 moveCursorUpdate(false);
1906 owner_->showState();
1911 if (!TEXT(bv_)->mark_set)
1912 beforeChange(TEXT(bv_));
1913 update(TEXT(bv_), BufferView::UPDATE);
1914 TEXT(bv_)->CursorUp(bv_);
1915 TEXT(bv_)->FinishUndo();
1916 moveCursorUpdate(false);
1917 owner_->showState();
1921 if (!TEXT(bv_)->mark_set)
1922 beforeChange(TEXT(bv_));
1923 update(TEXT(bv_), BufferView::UPDATE);
1924 TEXT(bv_)->CursorDown(bv_);
1925 TEXT(bv_)->FinishUndo();
1926 moveCursorUpdate(false);
1927 owner_->showState();
1930 case LFUN_UP_PARAGRAPH:
1931 if (!TEXT(bv_)->mark_set)
1932 beforeChange(TEXT(bv_));
1933 update(TEXT(bv_), BufferView::UPDATE);
1934 TEXT(bv_)->CursorUpParagraph(bv_);
1935 TEXT(bv_)->FinishUndo();
1936 moveCursorUpdate(false);
1937 owner_->showState();
1940 case LFUN_DOWN_PARAGRAPH:
1941 if (!TEXT(bv_)->mark_set)
1942 beforeChange(TEXT(bv_));
1943 update(TEXT(bv_), BufferView::UPDATE);
1944 TEXT(bv_)->CursorDownParagraph(bv_);
1945 TEXT(bv_)->FinishUndo();
1946 moveCursorUpdate(false);
1947 owner_->showState();
1951 if (!TEXT(bv_)->mark_set)
1952 beforeChange(TEXT(bv_));
1953 update(TEXT(bv_), BufferView::UPDATE);
1954 cursorPrevious(TEXT(bv_));
1955 TEXT(bv_)->FinishUndo();
1956 moveCursorUpdate(false);
1957 owner_->showState();
1961 if (!TEXT(bv_)->mark_set)
1962 beforeChange(TEXT(bv_));
1963 update(TEXT(bv_), BufferView::UPDATE);
1964 cursorNext(TEXT(bv_));
1965 TEXT(bv_)->FinishUndo();
1966 moveCursorUpdate(false);
1967 owner_->showState();
1971 if (!TEXT(bv_)->mark_set)
1972 beforeChange(TEXT(bv_));
1973 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1974 TEXT(bv_)->CursorHome(bv_);
1975 TEXT(bv_)->FinishUndo();
1976 moveCursorUpdate(false);
1977 owner_->showState();
1981 if (!TEXT(bv_)->mark_set)
1982 beforeChange(TEXT(bv_));
1984 BufferView::SELECT|BufferView::FITCUR);
1985 TEXT(bv_)->CursorEnd(bv_);
1986 TEXT(bv_)->FinishUndo();
1987 moveCursorUpdate(false);
1988 owner_->showState();
1991 case LFUN_SHIFT_TAB:
1993 if (!TEXT(bv_)->mark_set)
1994 beforeChange(TEXT(bv_));
1996 BufferView::SELECT|BufferView::FITCUR);
1997 TEXT(bv_)->CursorTab(bv_);
1998 TEXT(bv_)->FinishUndo();
1999 moveCursorUpdate(false);
2000 owner_->showState();
2003 case LFUN_WORDRIGHT:
2004 if (!TEXT(bv_)->mark_set)
2005 beforeChange(TEXT(bv_));
2006 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2007 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2008 TEXT(bv_)->CursorLeftOneWord(bv_);
2010 TEXT(bv_)->CursorRightOneWord(bv_);
2011 TEXT(bv_)->FinishUndo();
2012 moveCursorUpdate(false);
2013 owner_->showState();
2017 if (!TEXT(bv_)->mark_set)
2018 beforeChange(TEXT(bv_));
2019 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2020 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2021 TEXT(bv_)->CursorRightOneWord(bv_);
2023 TEXT(bv_)->CursorLeftOneWord(bv_);
2024 TEXT(bv_)->FinishUndo();
2025 moveCursorUpdate(false);
2026 owner_->showState();
2029 case LFUN_BEGINNINGBUF:
2030 if (!TEXT(bv_)->mark_set)
2031 beforeChange(TEXT(bv_));
2033 BufferView::SELECT|BufferView::FITCUR);
2034 TEXT(bv_)->CursorTop(bv_);
2035 TEXT(bv_)->FinishUndo();
2036 moveCursorUpdate(false);
2037 owner_->showState();
2041 if (!TEXT(bv_)->mark_set)
2042 beforeChange(TEXT(bv_));
2044 BufferView::SELECT|BufferView::FITCUR);
2045 TEXT(bv_)->CursorBottom(bv_);
2046 TEXT(bv_)->FinishUndo();
2047 moveCursorUpdate(false);
2048 owner_->showState();
2052 /* cursor selection ---------------------------- */
2055 BufferView::SELECT|BufferView::FITCUR);
2056 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2057 TEXT(bv_)->CursorLeft(bv_);
2059 TEXT(bv_)->CursorRight(bv_);
2060 TEXT(bv_)->FinishUndo();
2061 moveCursorUpdate(true);
2062 owner_->showState();
2067 BufferView::SELECT|BufferView::FITCUR);
2068 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2069 TEXT(bv_)->CursorRight(bv_);
2071 TEXT(bv_)->CursorLeft(bv_);
2072 TEXT(bv_)->FinishUndo();
2073 moveCursorUpdate(true);
2074 owner_->showState();
2079 BufferView::SELECT|BufferView::FITCUR);
2080 TEXT(bv_)->CursorUp(bv_);
2081 TEXT(bv_)->FinishUndo();
2082 moveCursorUpdate(true);
2083 owner_->showState();
2088 BufferView::SELECT|BufferView::FITCUR);
2089 TEXT(bv_)->CursorDown(bv_);
2090 TEXT(bv_)->FinishUndo();
2091 moveCursorUpdate(true);
2092 owner_->showState();
2095 case LFUN_UP_PARAGRAPHSEL:
2097 BufferView::SELECT|BufferView::FITCUR);
2098 TEXT(bv_)->CursorUpParagraph(bv_);
2099 TEXT(bv_)->FinishUndo();
2100 moveCursorUpdate(true);
2101 owner_->showState();
2104 case LFUN_DOWN_PARAGRAPHSEL:
2106 BufferView::SELECT|BufferView::FITCUR);
2107 TEXT(bv_)->CursorDownParagraph(bv_);
2108 TEXT(bv_)->FinishUndo();
2109 moveCursorUpdate(true);
2110 owner_->showState();
2114 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2115 cursorPrevious(TEXT(bv_));
2116 TEXT(bv_)->FinishUndo();
2117 moveCursorUpdate(true);
2118 owner_->showState();
2122 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2123 cursorNext(TEXT(bv_));
2124 TEXT(bv_)->FinishUndo();
2125 moveCursorUpdate(true);
2126 owner_->showState();
2130 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2131 TEXT(bv_)->CursorHome(bv_);
2132 TEXT(bv_)->FinishUndo();
2133 moveCursorUpdate(true);
2134 owner_->showState();
2138 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2139 TEXT(bv_)->CursorEnd(bv_);
2140 TEXT(bv_)->FinishUndo();
2141 moveCursorUpdate(true);
2142 owner_->showState();
2145 case LFUN_WORDRIGHTSEL:
2146 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2147 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2148 TEXT(bv_)->CursorLeftOneWord(bv_);
2150 TEXT(bv_)->CursorRightOneWord(bv_);
2151 TEXT(bv_)->FinishUndo();
2152 moveCursorUpdate(true);
2153 owner_->showState();
2156 case LFUN_WORDLEFTSEL:
2157 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2158 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2159 TEXT(bv_)->CursorRightOneWord(bv_);
2161 TEXT(bv_)->CursorLeftOneWord(bv_);
2162 TEXT(bv_)->FinishUndo();
2163 moveCursorUpdate(true);
2164 owner_->showState();
2167 case LFUN_BEGINNINGBUFSEL:
2168 if (TEXT(bv_)->inset_owner)
2170 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2171 TEXT(bv_)->CursorTop(bv_);
2172 TEXT(bv_)->FinishUndo();
2173 moveCursorUpdate(true);
2174 owner_->showState();
2177 case LFUN_ENDBUFSEL:
2178 if (TEXT(bv_)->inset_owner)
2181 BufferView::SELECT|BufferView::FITCUR);
2182 TEXT(bv_)->CursorBottom(bv_);
2183 TEXT(bv_)->FinishUndo();
2184 moveCursorUpdate(true);
2185 owner_->showState();
2188 // --- text changing commands ------------------------
2189 case LFUN_BREAKLINE:
2190 beforeChange(TEXT(bv_));
2191 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2193 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2194 moveCursorUpdate(false);
2197 case LFUN_PROTECTEDSPACE:
2199 LyXLayout const & style =
2200 textclasslist.Style(buffer_->params.textclass,
2201 TEXT(bv_)->cursor.par()->GetLayout());
2203 if (style.free_spacing) {
2204 TEXT(bv_)->InsertChar(bv_, ' ');
2205 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2207 bv_->protectedBlank(TEXT(bv_));
2209 moveCursorUpdate(false);
2214 if (TEXT(bv_)->mark_set) {
2215 beforeChange(TEXT(bv_));
2216 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2217 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2219 beforeChange(TEXT(bv_));
2220 TEXT(bv_)->mark_set = 1;
2221 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2222 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2224 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2228 if (!TEXT(bv_)->selection) {
2229 TEXT(bv_)->Delete(bv_);
2230 TEXT(bv_)->sel_cursor =
2233 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2234 // It is possible to make it a lot faster still
2235 // just comment out the line below...
2240 moveCursorUpdate(false);
2241 owner_->showState();
2245 case LFUN_DELETE_SKIP:
2247 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2249 LyXCursor cursor = TEXT(bv_)->cursor;
2251 if (!TEXT(bv_)->selection) {
2253 if (cursor.pos() == cursor.par()->Last()) {
2255 if (cursor.pos() == cursor.par()->size()) {
2257 TEXT(bv_)->CursorRight(bv_);
2258 cursor = TEXT(bv_)->cursor;
2259 if (cursor.pos() == 0
2260 && !(cursor.par()->params.spaceTop()
2261 == VSpace (VSpace::NONE))) {
2262 TEXT(bv_)->SetParagraph
2264 cursor.par()->params.lineTop(),
2265 cursor.par()->params.lineBottom(),
2266 cursor.par()->params.pagebreakTop(),
2267 cursor.par()->params.pagebreakBottom(),
2268 VSpace(VSpace::NONE),
2269 cursor.par()->params.spaceBottom(),
2270 cursor.par()->params.align(),
2271 cursor.par()->params.labelWidthString(), 0);
2272 TEXT(bv_)->CursorLeft(bv_);
2274 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2276 TEXT(bv_)->CursorLeft(bv_);
2277 TEXT(bv_)->Delete(bv_);
2278 TEXT(bv_)->sel_cursor =
2281 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2284 TEXT(bv_)->Delete(bv_);
2285 TEXT(bv_)->sel_cursor =
2288 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2296 /* -------> Delete word forward. */
2297 case LFUN_DELETE_WORD_FORWARD:
2298 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2299 TEXT(bv_)->DeleteWordForward(bv_);
2300 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2301 moveCursorUpdate(false);
2302 owner_->showState();
2305 /* -------> Delete word backward. */
2306 case LFUN_DELETE_WORD_BACKWARD:
2307 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2308 TEXT(bv_)->DeleteWordBackward(bv_);
2309 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2310 moveCursorUpdate(false);
2311 owner_->showState();
2314 /* -------> Kill to end of line. */
2315 case LFUN_DELETE_LINE_FORWARD:
2316 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2317 TEXT(bv_)->DeleteLineForward(bv_);
2318 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2319 moveCursorUpdate(false);
2322 /* -------> Set mark off. */
2324 beforeChange(TEXT(bv_));
2325 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2326 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2327 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2330 /* -------> Set mark on. */
2332 beforeChange(TEXT(bv_));
2333 TEXT(bv_)->mark_set = 1;
2334 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2335 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2336 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2339 case LFUN_BACKSPACE:
2341 if (!TEXT(bv_)->selection) {
2342 if (owner_->getIntl()->getTrans().backspace()) {
2343 TEXT(bv_)->Backspace(bv_);
2344 TEXT(bv_)->sel_cursor =
2347 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2348 // It is possible to make it a lot faster still
2349 // just comment out the line below...
2355 owner_->showState();
2360 case LFUN_BACKSPACE_SKIP:
2362 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2364 LyXCursor cursor = TEXT(bv_)->cursor;
2366 if (!TEXT(bv_)->selection) {
2367 if (cursor.pos() == 0
2368 && !(cursor.par()->params.spaceTop()
2369 == VSpace (VSpace::NONE))) {
2370 TEXT(bv_)->SetParagraph
2372 cursor.par()->params.lineTop(),
2373 cursor.par()->params.lineBottom(),
2374 cursor.par()->params.pagebreakTop(),
2375 cursor.par()->params.pagebreakBottom(),
2376 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2377 cursor.par()->params.align(),
2378 cursor.par()->params.labelWidthString(), 0);
2380 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2382 TEXT(bv_)->Backspace(bv_);
2383 TEXT(bv_)->sel_cursor
2386 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2393 case LFUN_BREAKPARAGRAPH:
2395 beforeChange(TEXT(bv_));
2396 TEXT(bv_)->BreakParagraph(bv_, 0);
2398 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2399 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2401 owner_->showState();
2405 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2407 beforeChange(TEXT(bv_));
2408 TEXT(bv_)->BreakParagraph(bv_, 1);
2410 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2411 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2413 owner_->showState();
2417 case LFUN_BREAKPARAGRAPH_SKIP:
2419 // When at the beginning of a paragraph, remove
2420 // indentation and add a "defskip" at the top.
2421 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2423 LyXCursor cursor = TEXT(bv_)->cursor;
2425 beforeChange(TEXT(bv_));
2426 if (cursor.pos() == 0) {
2427 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2428 TEXT(bv_)->SetParagraph
2430 cursor.par()->params.lineTop(),
2431 cursor.par()->params.lineBottom(),
2432 cursor.par()->params.pagebreakTop(),
2433 cursor.par()->params.pagebreakBottom(),
2434 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2435 cursor.par()->params.align(),
2436 cursor.par()->params.labelWidthString(), 1);
2437 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2441 TEXT(bv_)->BreakParagraph(bv_, 0);
2442 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2446 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2447 TEXT(bv_)->sel_cursor = cursor;
2449 owner_->showState();
2453 case LFUN_PARAGRAPH_SPACING:
2455 LyXParagraph * par = TEXT(bv_)->cursor.par();
2456 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2457 float cur_value = 1.0;
2458 if (cur_spacing == Spacing::Other) {
2459 cur_value = par->params.spacing().getValue();
2462 istringstream istr(argument.c_str());
2466 Spacing::Space new_spacing = cur_spacing;
2467 float new_value = cur_value;
2469 lyxerr << "Missing argument to `paragraph-spacing'"
2471 } else if (tmp == "single") {
2472 new_spacing = Spacing::Single;
2473 } else if (tmp == "onehalf") {
2474 new_spacing = Spacing::Onehalf;
2475 } else if (tmp == "double") {
2476 new_spacing = Spacing::Double;
2477 } else if (tmp == "other") {
2478 new_spacing = Spacing::Other;
2481 lyxerr << "new_value = " << tmpval << endl;
2484 } else if (tmp == "default") {
2485 new_spacing = Spacing::Default;
2487 lyxerr << _("Unknown spacing argument: ")
2488 << argument << endl;
2490 if (cur_spacing != new_spacing || cur_value != new_value) {
2491 par->params.spacing(Spacing(new_spacing, new_value));
2492 TEXT(bv_)->RedoParagraph(bv_);
2494 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2500 beforeChange(TEXT(bv_));
2501 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2502 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2503 moveCursorUpdate(false);
2509 InsetCommandParams p;
2510 if (action == LFUN_HTMLURL)
2511 p.setCmdName("htmlurl");
2513 p.setCmdName("url");
2514 owner_->getDialogs()->createUrl( p.getAsString() );
2518 case LFUN_INSERT_URL:
2520 InsetCommandParams p;
2521 p.setFromString( argument );
2523 InsetUrl * inset = new InsetUrl( p );
2524 if (!bv_->insertInset(inset))
2527 bv_->updateInset( inset, true );
2531 case LFUN_INSET_TEXT:
2533 InsetText * new_inset = new InsetText;
2534 if (bv_->insertInset(new_inset))
2535 new_inset->Edit(bv_, 0, 0, 0);
2541 case LFUN_INSET_ERT:
2543 InsetERT * new_inset = new InsetERT;
2544 if (bv_->insertInset(new_inset))
2545 new_inset->Edit(bv_, 0, 0, 0);
2551 case LFUN_INSET_EXTERNAL:
2553 InsetExternal * new_inset = new InsetExternal;
2554 if (bv_->insertInset(new_inset))
2555 new_inset->Edit(bv_, 0, 0, 0);
2561 case LFUN_INSET_FOOTNOTE:
2563 InsetFoot * new_inset = new InsetFoot;
2564 if (bv_->insertInset(new_inset))
2565 new_inset->Edit(bv_, 0, 0, 0);
2571 case LFUN_INSET_MARGINAL:
2573 InsetMarginal * new_inset = new InsetMarginal;
2574 if (bv_->insertInset(new_inset))
2575 new_inset->Edit(bv_, 0, 0, 0);
2581 case LFUN_INSET_MINIPAGE:
2583 InsetMinipage * new_inset = new InsetMinipage;
2584 if (bv_->insertInset(new_inset))
2585 new_inset->Edit(bv_, 0, 0, 0);
2591 case LFUN_INSET_FLOAT:
2593 // check if the float type exist
2594 if (floatList.typeExist(argument)) {
2595 InsetFloat * new_inset = new InsetFloat(argument);
2596 if (bv_->insertInset(new_inset))
2597 new_inset->Edit(bv_, 0, 0, 0);
2601 lyxerr << "Non-existant float type: "
2602 << argument << endl;
2608 case LFUN_INSET_LIST:
2610 InsetList * new_inset = new InsetList;
2611 if (bv_->insertInset(new_inset))
2612 new_inset->Edit(bv_, 0, 0, 0);
2618 case LFUN_INSET_THEOREM:
2620 InsetTheorem * new_inset = new InsetTheorem;
2621 if (bv_->insertInset(new_inset))
2622 new_inset->Edit(bv_, 0, 0, 0);
2628 case LFUN_INSET_CAPTION:
2630 // Do we have a locking inset...
2631 if (bv_->theLockingInset()) {
2632 lyxerr << "Locking inset code: "
2633 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2634 InsetCaption * new_inset = new InsetCaption;
2635 new_inset->setOwner(bv_->theLockingInset());
2636 new_inset->SetAutoBreakRows(true);
2637 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2638 new_inset->SetFrameColor(0, LColor::footnoteframe);
2639 if (bv_->insertInset(new_inset))
2640 new_inset->Edit(bv_, 0, 0, 0);
2647 case LFUN_INSET_TABULAR:
2650 if (!argument.empty())
2651 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2652 InsetTabular * new_inset =
2653 new InsetTabular(*buffer_, r, c);
2655 TEXT(bv_)->real_current_font.isRightToLeft();
2656 if (!bv_->open_new_inset(new_inset, rtl))
2661 // --- lyxserver commands ----------------------------
2663 case LFUN_CHARATCURSOR:
2665 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2666 if (pos < TEXT(bv_)->cursor.par()->size())
2667 owner_->getLyXFunc()->setMessage(
2668 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2670 owner_->getLyXFunc()->setMessage("EOF");
2675 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2677 + tostr(TEXT(bv_)->cursor.y()));
2684 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2685 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2689 case LFUN_GETLAYOUT:
2690 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2695 LyXFont & font = TEXT(bv_)->current_font;
2696 if (font.shape() == LyXFont::ITALIC_SHAPE)
2697 owner_->getLyXFunc()->setMessage("E");
2698 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2699 owner_->getLyXFunc()->setMessage("N");
2701 owner_->getLyXFunc()->setMessage("0");
2708 LyXFont & font = TEXT(bv_)->current_font;
2709 if (font.latex() == LyXFont::ON)
2710 owner_->getLyXFunc()->setMessage("L");
2712 owner_->getLyXFunc()->setMessage("0");
2716 // --- accented characters ---------------------------
2719 case LFUN_CIRCUMFLEX:
2729 case LFUN_SPECIAL_CARON:
2732 case LFUN_HUNG_UMLAUT:
2735 owner_->getLyXFunc()->handleKeyFunc(action);
2738 // --- insert characters ----------------------------------------
2740 case LFUN_MATH_DELIM:
2741 case LFUN_INSERT_MATRIX:
2744 if (bv_->open_new_inset(new InsetFormula(false)))
2746 bv_->theLockingInset()
2747 ->LocalDispatch(bv_, action, argument);
2753 case LFUN_INSERT_MATH:
2758 InsetFormula * f = new InsetFormula(true);
2759 bv_->open_new_inset(f);
2760 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2764 case LFUN_MATH_DISPLAY:
2767 bv_->open_new_inset(new InsetFormula(true));
2771 case LFUN_MATH_MACRO:
2776 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2778 string const s1 = token(s, ' ', 1);
2779 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2780 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2786 case LFUN_MATH_MODE: // Open or create a math inset
2789 bv_->open_new_inset(new InsetFormula);
2790 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2794 case LFUN_CITATION_INSERT:
2796 InsetCommandParams p;
2797 p.setFromString( argument );
2799 InsetCitation * inset = new InsetCitation( p );
2800 if (!bv_->insertInset(inset))
2803 bv_->updateInset( inset, true );
2807 case LFUN_INSERT_BIBTEX:
2809 // ale970405+lasgoutt970425
2810 // The argument can be up to two tokens separated
2811 // by a space. The first one is the bibstyle.
2812 string const db = token(argument, ' ', 0);
2813 string bibstyle = token(argument, ' ', 1);
2814 if (bibstyle.empty())
2817 InsetCommandParams p( "BibTeX", db, bibstyle );
2818 InsetBibtex * inset = new InsetBibtex(p);
2820 if (bv_->insertInset(inset)) {
2821 if (argument.empty())
2822 inset->Edit(bv_, 0, 0, 0);
2828 // BibTeX data bases
2829 case LFUN_BIBDB_ADD:
2831 InsetBibtex * inset =
2832 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2834 inset->addDatabase(argument);
2839 case LFUN_BIBDB_DEL:
2841 InsetBibtex * inset =
2842 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2844 inset->delDatabase(argument);
2849 case LFUN_BIBTEX_STYLE:
2851 InsetBibtex * inset =
2852 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2854 inset->setOptions(argument);
2859 case LFUN_INDEX_CREATE:
2861 InsetCommandParams p( "index" );
2863 if (argument.empty()) {
2864 // Get the word immediately preceding the cursor
2865 LyXParagraph::size_type curpos =
2866 TEXT(bv_)->cursor.pos() - 1;
2870 curstring = TEXT(bv_)
2871 ->cursor.par()->GetWord(curpos);
2873 p.setContents( curstring );
2875 p.setContents( argument );
2878 owner_->getDialogs()->createIndex( p.getAsString() );
2882 case LFUN_INDEX_INSERT:
2884 InsetCommandParams p;
2885 p.setFromString(argument);
2886 InsetIndex * inset = new InsetIndex(p);
2888 if (!bv_->insertInset(inset))
2891 bv_->updateInset(inset, true);
2895 case LFUN_INDEX_INSERT_LAST:
2897 // Get word immediately preceding the cursor
2898 LyXParagraph::size_type curpos =
2899 TEXT(bv_)->cursor.pos() - 1;
2900 // Can't do that at the beginning of a paragraph
2901 if (curpos < 0) break;
2903 string const curstring(TEXT(bv_)
2904 ->cursor.par()->GetWord(curpos));
2906 InsetCommandParams p("index", curstring);
2907 InsetIndex * inset = new InsetIndex(p);
2909 if (!bv_->insertInset(inset))
2912 bv_->updateInset(inset, true);
2916 case LFUN_INDEX_PRINT:
2918 InsetCommandParams p("printindex");
2919 Inset * inset = new InsetPrintIndex(p);
2920 if (!bv_->insertInset(inset, "Standard", true))
2925 case LFUN_PARENTINSERT:
2927 lyxerr << "arg " << argument << endl;
2928 InsetCommandParams p( "lyxparent", argument );
2929 Inset * inset = new InsetParent(p, *buffer_);
2930 if (!bv_->insertInset(inset, "Standard", true))
2935 case LFUN_CHILD_INSERT:
2937 InsetInclude::InsetIncludeParams p;
2938 p.cparams.setFromString(argument);
2941 InsetInclude * inset = new InsetInclude(p);
2942 if (!bv_->insertInset(inset))
2945 bv_->updateInset(inset, true);
2946 bv_->owner()->getDialogs()->showInclude(inset);
2951 case LFUN_INSERT_NOTE:
2955 case LFUN_SELFINSERT:
2957 LyXFont const old_font(TEXT(bv_)->real_current_font);
2958 for (string::size_type i = 0; i < argument.length(); ++i) {
2959 TEXT(bv_)->InsertChar(bv_, argument[i]);
2960 // This needs to be in the loop, or else we
2961 // won't break lines correctly. (Asger)
2963 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2965 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2966 moveCursorUpdate(false);
2968 // real_current_font.number can change so we need to
2969 // update the minibuffer
2970 if (old_font != TEXT(bv_)->real_current_font)
2971 owner_->showState();
2975 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2979 time_t now_time_t = time(NULL);
2980 now_tm = localtime(&now_time_t);
2981 setlocale(LC_TIME, "");
2983 if (!argument.empty())
2986 arg = lyxrc.date_insert_format;
2988 int const datetmp_len =
2989 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2990 for (int i = 0; i < datetmp_len; i++) {
2991 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2993 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2996 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2997 moveCursorUpdate(false);
3001 case LFUN_UNKNOWN_ACTION:
3004 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
3008 if (buffer_->isReadonly()) {
3009 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
3012 if (!argument.empty()) {
3013 /* Automatically delete the currently selected
3014 * text and replace it with what is being
3015 * typed in now. Depends on lyxrc settings
3016 * "auto_region_delete", which defaults to
3019 if (lyxrc.auto_region_delete) {
3020 if (TEXT(bv_)->selection){
3021 TEXT(bv_)->CutSelection(bv_, false);
3023 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3027 beforeChange(TEXT(bv_));
3028 LyXFont const old_font(TEXT(bv_)->real_current_font);
3029 for (string::size_type i = 0;
3030 i < argument.length(); ++i) {
3031 if (greek_kb_flag) {
3032 if (!math_insert_greek(bv_, argument[i]))
3033 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3035 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3038 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3040 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3041 moveCursorUpdate(false);
3043 // real_current_font.number can change so we need to
3044 // update the minibuffer
3045 if (old_font != TEXT(bv_)->real_current_font)
3046 owner_->showState();
3048 // if we don't have an argument there was something
3049 // strange going on so we just tell this to someone!
3050 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));