11 #include "BufferView_pimpl.h"
13 #include "lyxscreen.h"
17 #include "commandtags.h"
19 #include "minibuffer.h"
21 #include "bufferview_funcs.h"
22 #include "TextCache.h"
23 #include "bufferlist.h"
24 #include "lyx_gui_misc.h"
27 #include "support/LAssert.h"
28 #include "frontends/Dialogs.h"
29 #include "insets/insetbib.h"
30 #include "insets/insettext.h"
31 /// added for Dispatch functions
33 #include "frontends/FileDialog.h"
35 #include "FloatList.h"
36 #include "support/filetools.h"
37 #include "support/lyxfunctional.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetinclude.h"
45 #include "insets/insetcite.h"
46 #include "insets/insetert.h"
47 #include "insets/insetexternal.h"
48 #include "insets/insetgraphics.h"
49 #include "insets/insetfoot.h"
50 #include "insets/insetmarginal.h"
51 #include "insets/insetminipage.h"
52 #include "insets/insetfloat.h"
53 #include "insets/insetlist.h"
54 #include "insets/insettabular.h"
55 #include "insets/insettheorem.h"
56 #include "insets/insetcaption.h"
57 #include "mathed/formulamacro.h"
58 extern LyXTextClass::size_type current_layout;
59 extern void math_insert_symbol(BufferView *, string const &);
60 extern bool math_insert_greek(BufferView *, char);
61 extern int greek_kb_flag;
63 #ifdef SIGC_CXX_NAMESPACES
73 /* the selection possible is needed, that only motion events are
74 * used, where the bottom press event was on the drawing area too */
75 bool selection_possible = false;
77 extern BufferList bufferlist;
78 extern char ascii_type;
80 extern void sigchldhandler(pid_t pid, int * status);
81 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
83 const unsigned int saved_positions_num = 20;
88 XSync(fl_get_display(), 0);
93 void SetXtermCursor(Window win)
96 static bool cursor_undefined = true;
97 if (cursor_undefined){
98 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
99 XFlush(fl_get_display());
100 cursor_undefined = false;
102 XDefineCursor(fl_get_display(), win, cursor);
103 XFlush(fl_get_display());
107 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
108 int xpos, int ypos, int width, int height)
109 : bv_(b), owner_(o), buffer_(0),
110 current_scrollbar_value(0), cursor_timeout(400),
111 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
114 //workarea_ = new WorkArea(xpos, ypos, width, height);
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;
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 owner_->getDialogs()->hideSplash();
359 void BufferView::Pimpl::updateScreen()
361 // Regenerate the screen.
362 screen_.reset(new LyXScreen(workarea_));
364 //screen_ = new LyXScreen(workarea_);
368 void BufferView::Pimpl::updateScrollbar()
370 /* If the text is smaller than the working area, the scrollbar
371 * maximum must be the working area height. No scrolling will
375 workarea_.setScrollbar(0, 1.0);
379 static unsigned long max2 = 0;
380 static unsigned long height2 = 0;
382 unsigned long cbth = 0;
386 cbth = bv_->text->height;
387 cbsf = bv_->text->first;
390 // check if anything has changed.
392 height2 == workarea_.height() &&
393 current_scrollbar_value == cbsf)
396 height2 = workarea_.height();
397 current_scrollbar_value = cbsf;
399 if (cbth <= height2) { // text is smaller than screen
400 workarea_.setScrollbar(0, 1.0); // right?
404 long maximum_height = workarea_.height() * 3 / 4 + cbth;
408 double hfloat = workarea_.height();
409 double maxfloat = maximum_height;
411 float slider_size = 0.0;
412 int slider_value = value;
414 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
415 double const lineh = bv_->text->DefaultHeight();
416 workarea_.setScrollbarIncrements(lineh);
417 if (maxfloat > 0.0) {
418 if ((hfloat / maxfloat) * float(height2) < 3)
419 slider_size = 3.0/float(height2);
421 slider_size = hfloat / maxfloat;
423 slider_size = hfloat;
425 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
429 // Callback for scrollbar slider
430 void BufferView::Pimpl::scrollCB(double value)
432 if (!buffer_) return;
434 current_scrollbar_value = long(value);
435 if (current_scrollbar_value < 0)
436 current_scrollbar_value = 0;
441 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
443 if (!lyxrc.cursor_follows_scrollbar) {
448 LyXText * vbt = bv_->text;
450 int const height = vbt->DefaultHeight();
451 int const first = static_cast<int>((bv_->text->first + height));
452 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
454 if (vbt->cursor.y() < first)
455 vbt->SetCursorFromCoordinates(bv_, 0, first);
456 else if (vbt->cursor.y() > last)
457 vbt->SetCursorFromCoordinates(bv_, 0, last);
463 int BufferView::Pimpl::scrollUp(long time)
465 if (!buffer_) return 0;
466 if (!screen_.get()) return 0;
468 double value = workarea_.getScrollbarValue();
470 if (value == 0) return 0;
472 float add_value = (bv_->text->DefaultHeight()
473 + float(time) * float(time) * 0.125);
475 if (add_value > workarea_.height())
476 add_value = float(workarea_.height() -
477 bv_->text->DefaultHeight());
484 workarea_.setScrollbarValue(value);
491 int BufferView::Pimpl::scrollDown(long time)
493 if (!buffer_) return 0;
494 if (!screen_.get()) return 0;
496 double value = workarea_.getScrollbarValue();
497 pair<float, float> p = workarea_.getScrollbarBounds();
498 double max = p.second;
500 if (value == max) return 0;
502 float add_value = (bv_->text->DefaultHeight()
503 + float(time) * float(time) * 0.125);
505 if (add_value > workarea_.height())
506 add_value = float(workarea_.height() -
507 bv_->text->DefaultHeight());
514 workarea_.setScrollbarValue(value);
521 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
523 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
527 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
529 // Only use motion with button 1
530 if (!(state & Button1MotionMask))
533 if (!buffer_ || !screen_.get()) return;
535 // Check for inset locking
536 if (bv_->theLockingInset()) {
537 LyXCursor cursor = bv_->text->cursor;
538 LyXFont font = bv_->text->GetFont(bv_->buffer(),
539 cursor.par(), cursor.pos());
540 int width = bv_->theLockingInset()->width(bv_, font);
541 int inset_x = font.isVisibleRightToLeft()
542 ? cursor.x() - width : cursor.x();
543 int start_x = inset_x + bv_->theLockingInset()->scroll();
544 bv_->theLockingInset()->
545 InsetMotionNotify(bv_,
547 y - cursor.y() + bv_->text->first,
552 /* The test for not selection possible is needed, that only motion events are
553 * used, where the bottom press event was on the drawing area too */
554 if (!selection_possible)
557 screen_->HideCursor();
559 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
561 if (!bv_->text->selection)
562 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
564 bv_->text->SetSelection(bv_);
565 screen_->ToggleToggle(bv_->text, bv_);
566 fitCursor(bv_->text);
567 screen_->ShowCursor(bv_->text, bv_);
571 // Single-click on work area
572 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
578 if (!buffer_ || !screen_.get()) return;
580 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
582 // ok ok, this is a hack.
583 if (button == 4 || button == 5) {
586 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
589 scrollDown(lyxrc.wheel_jump);
594 if (bv_->theLockingInset()) {
595 // We are in inset locking mode
597 /* Check whether the inset was hit. If not reset mode,
598 otherwise give the event to the inset */
599 if (inset_hit == bv_->theLockingInset()) {
600 bv_->theLockingInset()->
601 InsetButtonPress(bv_,
606 bv_->unlockInset(bv_->theLockingInset());
611 selection_possible = true;
612 screen_->HideCursor();
614 int const screen_first = bv_->text->first;
616 // Middle button press pastes if we have a selection
617 bool paste_internally = false;
619 && bv_->text->selection) {
620 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
621 paste_internally = true;
624 // Clear the selection
625 screen_->ToggleSelection(bv_->text, bv_);
626 bv_->text->ClearSelection(bv_);
627 bv_->text->FullRebreak(bv_);
628 screen_->Update(bv_->text, bv_);
631 // Single left click in math inset?
632 if ((inset_hit != 0) &&
633 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
634 // Highly editable inset, like math
635 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
636 selection_possible = false;
637 owner_->updateLayoutChoice();
638 owner_->getMiniBuffer()->Set(inset->EditMessage());
639 inset->InsetButtonPress(bv_, xpos, ypos, button);
640 inset->Edit(bv_, xpos, ypos, button);
644 // Right click on a footnote flag opens float menu
646 selection_possible = false;
650 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
651 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
652 bv_->text->FinishUndo();
653 bv_->text->sel_cursor = bv_->text->cursor;
654 bv_->text->cursor.x_fix(bv_->text->cursor.x());
656 owner_->updateLayoutChoice();
657 if (fitCursor(bv_->text)) {
658 selection_possible = false;
661 // Insert primary selection with middle mouse
662 // if there is a local selection in the current buffer,
665 if (paste_internally)
666 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
668 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
670 selection_possible = false;
676 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
682 LyXText * text = bv_->getLyXText();
684 if (text->bv_owner && bv_->theLockingInset())
687 if (screen_.get() && button == 1) {
688 if (text->bv_owner) {
689 screen_->HideCursor();
690 screen_->ToggleSelection(text, bv_);
691 text->SelectWord(bv_);
692 screen_->ToggleSelection(text, bv_, false);
694 text->SelectWord(bv_);
696 /* This will fit the cursor on the screen
698 update(text, BufferView::SELECT|BufferView::FITCUR);
703 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
709 LyXText * text = bv_->getLyXText();
711 if (text->bv_owner && bv_->theLockingInset())
714 if (screen_.get() && (button == 1)) {
715 screen_->HideCursor();
716 screen_->ToggleSelection(text, bv_);
717 text->CursorHome(bv_);
718 text->sel_cursor = text->cursor;
719 text->CursorEnd(bv_);
720 text->SetSelection(bv_);
721 screen_->ToggleSelection(text, bv_, false);
722 /* This will fit the cursor on the screen
724 update(text, BufferView::SELECT|BufferView::FITCUR);
729 void BufferView::Pimpl::enterView()
731 if (active() && available()) {
732 SetXtermCursor(workarea_.getWin());
733 using_xterm_cursor = true;
738 void BufferView::Pimpl::leaveView()
740 if (using_xterm_cursor) {
741 XUndefineCursor(fl_get_display(), workarea_.getWin());
742 using_xterm_cursor = false;
747 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
750 if (!buffer_ || !screen_.get()) return;
752 // If we hit an inset, we have the inset coordinates in these
753 // and inset_hit points to the inset. If we do not hit an
754 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
755 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
757 if (bv_->theLockingInset()) {
758 // We are in inset locking mode.
760 /* LyX does a kind of work-area grabbing for insets.
761 Only a ButtonPress Event outside the inset will
762 force a InsetUnlock. */
763 bv_->theLockingInset()->
764 InsetButtonRelease(bv_, x, y, button);
768 selection_possible = false;
770 if (button >= 2) return;
775 // Did we hit an editable inset?
777 // Inset like error, notes and figures
778 selection_possible = false;
780 // CHECK fix this proper in 0.13
782 // Following a ref shouldn't issue
783 // a push on the undo-stack
784 // anylonger, now that we have
785 // keybindings for following
786 // references and returning from
787 // references. IMHO though, it
788 // should be the inset's own business
789 // to push or not push on the undo
790 // stack. They don't *have* to
791 // alter the document...
793 // ...or maybe the SetCursorParUndo()
794 // below isn't necessary at all anylonger?
795 if (inset_hit->LyxCode() == Inset::REF_CODE) {
796 bv_->text->SetCursorParUndo(bv_->buffer());
799 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
800 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
801 // Highly editable inset, like math
802 UpdatableInset *inset = (UpdatableInset *)inset_hit;
803 inset->InsetButtonRelease(bv_, x, y, button);
805 inset_hit->InsetButtonRelease(bv_, x, y, button);
806 inset_hit->Edit(bv_, x, y, button);
811 // check whether we want to open a float
815 if (bv_->text->cursor.pos() <
816 bv_->text->cursor.par()->Last()) {
817 c = bv_->text->cursor.par()->
818 GetChar(bv_->text->cursor.pos());
821 if(!bv_->text->selection)
822 if (c == LyXParagraph::META_FOOTNOTE
823 || c == LyXParagraph::META_MARGIN
824 || c == LyXParagraph::META_FIG
825 || c == LyXParagraph::META_TAB
826 || c == LyXParagraph::META_WIDE_FIG
827 || c == LyXParagraph::META_WIDE_TAB
828 || c == LyXParagraph::META_ALGORITHM){
832 if (bv_->text->cursor.pos() - 1 >= 0) {
833 c = bv_->text->cursor.par()->
834 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_);
853 selection_possible = false;
859 // Do we want to close a float? (click on the float-label)
860 if (bv_->text->cursor.row()->par()->footnoteflag ==
861 LyXParagraph::OPEN_FOOTNOTE
862 && bv_->text->cursor.row()->previous() &&
863 bv_->text->cursor.row()->previous()->par()->
864 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
865 LyXFont font(LyXFont::ALL_SANE);
866 font.setSize(LyXFont::SIZE_FOOTNOTE);
868 int box_x = 20; // LYX_PAPER_MARGIN;
869 box_x += lyxfont::width(" wide-tab ", font);
871 unsigned int screen_first = bv_->text->first;
874 && y + screen_first > bv_->text->cursor.y() -
875 bv_->text->cursor.row()->baseline()
876 && y + screen_first < bv_->text->cursor.y() -
877 bv_->text->cursor.row()->baseline()
878 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
880 selection_possible = false;
886 // Maybe we want to edit a bibitem ale970302
887 if (bv_->text->cursor.par()->bibkey && x < 20 +
888 bibitemMaxWidth(bv_, textclasslist.
890 params.textclass).defaultfont())) {
891 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
899 * Returns an inset if inset was hit. 0 otherwise.
900 * If hit, the coordinates are changed relative to the inset.
901 * Otherwise coordinates are not changed, and false is returned.
903 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
904 unsigned int /* button */)
909 int y_tmp = y + text->first;
912 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
914 if (cursor.pos() < cursor.par()->Last()
915 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
916 && cursor.par()->GetInset(cursor.pos())
917 && cursor.par()->GetInset(cursor.pos())->Editable()) {
919 // Check whether the inset really was hit
920 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
921 LyXFont font = text->GetFont(bv_->buffer(),
922 cursor.par(), cursor.pos());
923 int width = tmpinset->width(bv_, font);
924 int inset_x = font.isVisibleRightToLeft()
925 ? cursor.x() - width : cursor.x();
926 int start_x = inset_x + tmpinset->scroll();
927 int end_x = inset_x + width;
929 if (x > start_x && x < end_x
930 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
931 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
932 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
934 // The origin of an inset is on the baseline
935 y = y_tmp - (text->cursor.y());
940 if ((cursor.pos() - 1 >= 0) &&
941 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
942 (cursor.par()->GetInset(cursor.pos() - 1)) &&
943 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
944 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
945 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
947 int width = tmpinset->width(bv_, font);
948 int inset_x = font.isVisibleRightToLeft()
949 ? cursor.x() : cursor.x() - width;
950 int start_x = inset_x + tmpinset->scroll();
951 int end_x = inset_x + width;
953 if (x > start_x && x < end_x
954 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
955 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
957 if (move_cursor && (tmpinset != bv_->theLockingInset()))
959 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
961 // The origin of an inset is on the baseline
962 y = y_tmp - (text->cursor.y());
970 void BufferView::Pimpl::workAreaExpose()
972 static int work_area_width = 0;
973 static unsigned int work_area_height = 0;
975 bool widthChange = workarea_.workWidth() != work_area_width;
976 bool heightChange = workarea_.height() != work_area_height;
978 // update from work area
979 work_area_width = workarea_.workWidth();
980 work_area_height = workarea_.height();
983 // All buffers need a resize
986 // Remove all texts from the textcache
987 // This is not _really_ what we want to do. What
988 // we really want to do is to delete in textcache
989 // that does not have a BufferView with matching
990 // width, but as long as we have only one BufferView
991 // deleting all gives the same result.
992 if (lyxerr.debugging())
993 textcache.show(lyxerr, "Expose delete all");
995 } else if (heightChange) {
996 // Rebuild image of current screen
998 // fitCursor() ensures we don't jump back
999 // to the start of the document on vertical
1001 fitCursor(bv_->text);
1003 // The main window size has changed, repaint most stuff
1005 // ...including the minibuffer
1006 owner_->getMiniBuffer()->Init();
1008 } else if (screen_.get())
1009 screen_->Redraw(bv_->text, bv_);
1011 // Grey box when we don't have a buffer
1012 workarea_.greyOut();
1015 // always make sure that the scrollbar is sane.
1017 owner_->updateLayoutChoice();
1022 void BufferView::Pimpl::update()
1024 if (screen_.get()) screen_->Update(bv_->text, bv_);
1027 // Values used when calling update:
1029 // -2 - update, move sel_cursor if selection, fitcursor
1030 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1031 // 0 - update, move sel_cursor if selection, fitcursor
1032 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1033 // 3 - update, move sel_cursor if selection
1036 // a simple redraw of the parts that need refresh
1038 // move sel_cursor if selection -
1039 // the text's sel_cursor is moved if there is selection is progress
1042 // fitCursor() is called and the scrollbar updated
1045 // the buffer is marked dirty.
1054 // UPDATE_ONLY = UPDATE;
1055 // UPDATE_SELECT = UPDATE | SELECT;
1056 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1057 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1059 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1060 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1061 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1062 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1063 // update(3) -> update(1) -> update(1) -> update(SELECT)
1065 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1067 owner_->updateLayoutChoice();
1069 if (!text->selection && (f & SELECT)) {
1070 text->sel_cursor = text->cursor;
1073 text->FullRebreak(bv_);
1075 if (text->inset_owner) {
1076 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1077 bv_->updateInset(text->inset_owner, true);
1086 if (buffer_->isLyxClean()) {
1087 buffer_->markDirty();
1088 owner_->getMiniBuffer()->setTimer(4);
1090 buffer_->markDirty();
1096 // Callback for cursor timer
1097 void BufferView::Pimpl::cursorToggle()
1099 // Quite a nice place for asyncron Inset updating, isn't it?
1100 // Actually no! This is run even if no buffer exist... so (Lgb)
1102 cursor_timeout.restart();
1107 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1108 if (pid == -1) // error find out what is wrong
1109 ; // ignore it for now.
1111 sigchldhandler(pid, &status);
1113 updatelist.update(bv_);
1115 if (!screen_.get()) {
1116 cursor_timeout.restart();
1120 if (!bv_->theLockingInset()) {
1121 screen_->CursorToggle(bv_->text, bv_);
1123 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1126 cursor_timeout.restart();
1130 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1132 if (!text->cursor.row()->previous())
1135 int y = text->first;
1136 if (text->inset_owner)
1137 y += bv_->text->first;
1138 Row * cursorrow = text->cursor.row();
1139 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1140 bv_->text->FinishUndo();
1141 // This is to allow jumping over large insets
1142 if ((cursorrow == text->cursor.row()))
1143 text->CursorUp(bv_);
1145 if (text->inset_owner ||
1146 text->cursor.row()->height() < workarea_.height())
1147 screen_->Draw(bv_->text, bv_,
1149 - text->cursor.row()->baseline()
1150 + text->cursor.row()->height()
1151 - workarea_.height() + 1 );
1156 void BufferView::Pimpl::cursorNext(LyXText * text)
1158 if (!text->cursor.row()->next())
1161 int y = text->first + workarea_.height();
1162 // if (text->inset_owner)
1163 // y += bv_->text->first;
1164 text->GetRowNearY(y);
1166 Row * cursorrow = text->cursor.row();
1167 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1168 bv_->text->FinishUndo();
1169 // This is to allow jumping over large insets
1170 if ((cursorrow == bv_->text->cursor.row()))
1171 text->CursorDown(bv_);
1173 if (text->inset_owner ||
1174 text->cursor.row()->height() < workarea_.height())
1175 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1176 text->cursor.row()->baseline());
1181 bool BufferView::Pimpl::available() const
1183 if (buffer_ && bv_->text) return true;
1188 void BufferView::Pimpl::beforeChange(LyXText * text)
1191 text->ClearSelection(bv_);
1195 void BufferView::Pimpl::savePosition(unsigned int i)
1197 if (i >= saved_positions_num)
1199 saved_positions[i] = Position(buffer_->fileName(),
1200 bv_->text->cursor.par()->id(),
1201 bv_->text->cursor.pos());
1203 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1207 void BufferView::Pimpl::restorePosition(unsigned int i)
1209 if (i >= saved_positions_num)
1212 string fname = saved_positions[i].filename;
1214 beforeChange(bv_->text);
1216 if (fname != buffer_->fileName()) {
1217 Buffer * b = bufferlist.exists(fname) ?
1218 bufferlist.getBuffer(fname) :
1219 bufferlist.loadLyXFile(fname); // don't ask, just load it
1220 if (b != 0 ) buffer(b);
1223 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1227 bv_->text->SetCursor(bv_, par,
1228 min(par->Last(), saved_positions[i].par_pos));
1229 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1231 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1235 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1237 if (i >= saved_positions_num)
1240 return !saved_positions[i].filename.empty();
1244 void BufferView::Pimpl::setState()
1246 if (!lyxrc.rtl_support)
1249 LyXText * text = bv_->getLyXText();
1250 if (text->real_current_font.isRightToLeft() &&
1251 text->real_current_font.latex() != LyXFont::ON) {
1252 if (owner_->getIntl()->primarykeymap)
1253 owner_->getIntl()->KeyMapSec();
1255 if (!owner_->getIntl()->primarykeymap)
1256 owner_->getIntl()->KeyMapPrim();
1261 void BufferView::Pimpl::insetSleep()
1263 if (bv_->theLockingInset() && !bv_->inset_slept) {
1264 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1265 bv_->theLockingInset()->InsetUnlock(bv_);
1266 bv_->inset_slept = true;
1271 void BufferView::Pimpl::insetWakeup()
1273 if (bv_->theLockingInset() && bv_->inset_slept) {
1274 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1275 bv_->inset_slept = false;
1280 void BufferView::Pimpl::insetUnlock()
1282 if (bv_->theLockingInset()) {
1283 if (!bv_->inset_slept)
1284 bv_->theLockingInset()->InsetUnlock(bv_);
1285 bv_->theLockingInset(0);
1286 bv_->text->FinishUndo();
1287 bv_->inset_slept = false;
1292 bool BufferView::Pimpl::focus() const
1294 return workarea_.hasFocus();
1298 void BufferView::Pimpl::focus(bool f)
1300 if (f) workarea_.setFocus();
1304 bool BufferView::Pimpl::active() const
1306 return workarea_.active();
1310 bool BufferView::Pimpl::belowMouse() const
1312 return workarea_.belowMouse();
1316 void BufferView::Pimpl::showCursor()
1319 screen_->ShowCursor(bv_->text, bv_);
1323 void BufferView::Pimpl::hideCursor()
1326 screen_->HideCursor();
1330 void BufferView::Pimpl::toggleSelection(bool b)
1333 screen_->ToggleSelection(bv_->text, bv_, b);
1337 void BufferView::Pimpl::toggleToggle()
1340 screen_->ToggleToggle(bv_->text, bv_);
1344 void BufferView::Pimpl::center()
1346 beforeChange(bv_->text);
1347 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1348 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1350 screen_->Draw(bv_->text, bv_, 0);
1352 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1357 void BufferView::Pimpl::pasteClipboard(bool asPara)
1359 if (!buffer_) return;
1361 screen_->HideCursor();
1362 beforeChange(bv_->text);
1364 string const clip(workarea_.getClipboard());
1366 if (clip.empty()) return;
1369 bv_->text->InsertStringB(bv_, clip);
1371 bv_->text->InsertStringA(bv_, clip);
1373 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1377 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1379 workarea_.putClipboard(stuff);
1384 * Dispatch functions for actions which can be valid for BufferView->text
1385 * and/or InsetText->text!!!
1387 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1390 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1392 if (selecting || TEXT(bv_)->mark_set) {
1393 TEXT(bv_)->SetSelection(bv_);
1394 if (TEXT(bv_)->bv_owner)
1395 bv_->toggleToggle();
1397 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1400 /* ---> Everytime the cursor is moved, show the current font state. */
1401 // should this too me moved out of this func?
1402 //owner->showState();
1407 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1409 LyXCursor cursor = TEXT(bv_)->cursor;
1410 Buffer::inset_iterator it =
1411 find_if(Buffer::inset_iterator(
1412 cursor.par(), cursor.pos()),
1413 buffer_->inset_iterator_end(),
1414 compare_memfun(&Inset::LyxCode, code)
1416 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1420 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1422 string filename = filen;
1424 if (filename.empty()) {
1425 // Launch a file browser
1426 string initpath = lyxrc.document_path;
1429 string const trypath = owner_->buffer()->filepath;
1430 // If directory is writeable, use this as default.
1431 if (IsDirWriteable(trypath) == 1)
1435 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1437 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1438 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1440 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1442 if (result.first == FileDialog::Later)
1445 filename = result.second;
1447 // check selected filename
1448 if (filename.empty()) {
1449 owner_->getMiniBuffer()->Set(_("Canceled."));
1454 // get absolute path of file and make sure the filename ends
1456 filename = MakeAbsPath(filename);
1457 if (!IsLyXFilename(filename))
1461 owner_->getMiniBuffer()->Set(_("Inserting document"),
1462 MakeDisplayPath(filename), "...");
1463 bool const res = bv_->insertLyXFile(filename);
1465 owner_->getMiniBuffer()->Set(_("Document"),
1466 MakeDisplayPath(filename),
1469 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1470 MakeDisplayPath(filename));
1475 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1478 // --- Misc -------------------------------------------
1481 TEXT(bv_)->toggleAppendix(bv_);
1482 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1486 case LFUN_TOC_INSERT:
1487 case LFUN_LOA_INSERT:
1488 case LFUN_LOF_INSERT:
1489 case LFUN_LOT_INSERT:
1491 InsetCommandParams p;
1493 if (action == LFUN_TOC_INSERT )
1494 p.setCmdName( "tableofcontents" );
1495 else if (action == LFUN_LOA_INSERT )
1496 p.setCmdName( "listofalgorithms" );
1497 else if (action == LFUN_LOF_INSERT )
1498 p.setCmdName( "listoffigures" );
1500 p.setCmdName( "listoftables" );
1502 Inset * inset = new InsetTOC( p );
1503 if (!bv_->insertInset( inset, "Standard", true ) )
1508 case LFUN_TABULAR_FEATURE:
1509 case LFUN_SCROLL_INSET:
1510 // this is not handled here as this funktion is only aktive
1511 // if we have a locking_inset and that one is (or contains)
1515 case LFUN_INSET_GRAPHICS:
1517 Inset * new_inset = new InsetGraphics;
1518 if (!bv_->insertInset(new_inset)) {
1521 // this is need because you don't use a inset->Edit()
1522 bv_->updateInset(new_inset, true);
1523 new_inset->Edit(bv_, 0, 0, 0);
1533 case LFUN_PASTESELECTION:
1535 bool asPara = false;
1536 if (argument == "paragraph") asPara = true;
1537 pasteClipboard(asPara);
1549 case LFUN_LAYOUT_COPY:
1550 bv_->copyEnvironment();
1553 case LFUN_LAYOUT_PASTE:
1554 bv_->pasteEnvironment();
1558 case LFUN_GOTOERROR:
1559 bv_->gotoInset(Inset::ERROR_CODE, false);
1563 bv_->gotoInset(Inset::IGNORE_CODE, false);
1566 case LFUN_REFERENCE_GOTO:
1568 vector<Inset::Code> tmp;
1569 tmp.push_back(Inset::LABEL_CODE);
1570 tmp.push_back(Inset::REF_CODE);
1571 bv_->gotoInset(tmp, true);
1575 case LFUN_HYPHENATION:
1576 bv_->hyphenationPoint();
1583 case LFUN_END_OF_SENTENCE:
1584 bv_->endOfSentenceDot();
1587 case LFUN_MENU_SEPARATOR:
1588 bv_->menuSeparator();
1596 changeDepth(bv_, TEXT(bv_), 0);
1599 case LFUN_DEPTH_MIN:
1600 changeDepth(bv_, TEXT(bv_), -1);
1603 case LFUN_DEPTH_PLUS:
1604 changeDepth(bv_, TEXT(bv_), 1);
1608 owner_->getDialogs()->setUserFreeFont();
1614 owner_->showState();
1617 case LFUN_FILE_INSERT:
1619 MenuInsertLyXFile(argument);
1623 case LFUN_FILE_INSERT_ASCII_PARA:
1624 InsertAsciiFile(bv_, argument, true);
1627 case LFUN_FILE_INSERT_ASCII:
1628 InsertAsciiFile(bv_, argument, false);
1633 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1634 << argument << endl;
1636 // Derive layout number from given argument (string)
1637 // and current buffer's textclass (number). */
1638 LyXTextClassList::ClassList::size_type tclass =
1639 buffer_->params.textclass;
1640 pair <bool, LyXTextClass::size_type> layout =
1641 textclasslist.NumberOfLayout(tclass, argument);
1643 // If the entry is obsolete, use the new one instead.
1645 string obs = textclasslist.Style(tclass,layout.second)
1649 textclasslist.NumberOfLayout(tclass, obs);
1652 // see if we found the layout number:
1653 if (!layout.first) {
1654 owner_->getLyXFunc()->setErrorMessage(
1655 string(N_("Layout ")) + argument +
1660 if (current_layout != layout.second) {
1662 current_layout = layout.second;
1664 BufferView::SELECT|BufferView::FITCUR);
1665 TEXT(bv_)->SetLayout(bv_, layout.second);
1666 owner_->setLayout(layout.second);
1668 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1675 Lang(bv_, argument);
1677 owner_->showState();
1682 owner_->showState();
1687 owner_->showState();
1692 owner_->showState();
1697 owner_->showState();
1702 owner_->showState();
1707 owner_->showState();
1712 owner_->showState();
1715 case LFUN_UNDERLINE:
1717 owner_->showState();
1720 case LFUN_FONT_SIZE:
1721 FontSize(bv_, argument);
1722 owner_->showState();
1725 case LFUN_FONT_STATE:
1726 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1729 case LFUN_UPCASE_WORD:
1730 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1731 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1732 if (TEXT(bv_)->inset_owner)
1733 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1734 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1737 case LFUN_LOWCASE_WORD:
1738 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1739 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1740 if (TEXT(bv_)->inset_owner)
1741 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1742 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1745 case LFUN_CAPITALIZE_WORD:
1746 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1747 TEXT(bv_)->ChangeWordCase(bv_,
1748 LyXText::text_capitalization);
1749 if (TEXT(bv_)->inset_owner)
1750 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1751 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1754 case LFUN_INSERT_LABEL:
1755 MenuInsertLabel(bv_, argument);
1758 case LFUN_REF_INSERT:
1759 if (argument.empty()) {
1760 InsetCommandParams p("ref");
1761 owner_->getDialogs()->createRef(p.getAsString());
1763 InsetCommandParams p;
1764 p.setFromString(argument);
1766 InsetRef * inset = new InsetRef(p, *buffer_);
1767 if (!bv_->insertInset(inset))
1770 bv_->updateInset(inset, true);
1774 case LFUN_BOOKMARK_SAVE:
1775 savePosition(strToUnsignedInt(argument));
1778 case LFUN_BOOKMARK_GOTO:
1779 restorePosition(strToUnsignedInt(argument));
1784 string label(argument);
1785 if (label.empty()) {
1787 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1789 label = inset->getContents();
1794 if (!label.empty()) {
1795 //bv_->savePosition(0);
1796 if (!bv_->gotoLabel(label))
1797 WriteAlert(_("Error"),
1798 _("Couldn't find this label"),
1799 _("in current document."));
1804 // --- Cursor Movements -----------------------------
1807 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1808 if (!TEXT(bv_)->mark_set)
1809 beforeChange(TEXT(bv_));
1810 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1812 TEXT(bv_)->CursorLeft(bv_, false);
1813 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1814 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1815 == LyXParagraph::META_INSET
1816 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1817 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1818 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1819 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1823 TEXT(bv_)->GetFont(buffer_,
1824 TEXT(bv_)->cursor.par(),
1825 TEXT(bv_)->cursor.pos());
1826 y = tmpinset->descent(bv_,font);
1828 tmpinset->Edit(bv_, 0, y, 0);
1832 TEXT(bv_)->CursorRight(bv_, false);
1833 TEXT(bv_)->FinishUndo();
1834 moveCursorUpdate(false);
1835 owner_->showState();
1841 // This is soooo ugly. Isn`t it possible to make
1842 // it simpler? (Lgb)
1843 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1844 if (!TEXT(bv_)->mark_set)
1845 beforeChange(TEXT(bv_));
1846 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1847 LyXCursor cur = TEXT(bv_)->cursor;
1849 TEXT(bv_)->CursorLeft(bv_, false);
1850 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1851 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1852 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1853 LyXParagraph::META_INSET) &&
1854 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1855 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1856 == Inset::HIGHLY_EDITABLE))
1858 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1859 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1860 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1861 TEXT(bv_)->cursor.par(),
1862 TEXT(bv_)->cursor.pos());
1864 : tmpinset->descent(bv_,font);
1867 tmpinset->width(bv_,font),
1872 TEXT(bv_)->CursorRight(bv_, false);
1874 TEXT(bv_)->FinishUndo();
1875 moveCursorUpdate(false);
1876 owner_->showState();
1881 if (!TEXT(bv_)->mark_set)
1882 beforeChange(TEXT(bv_));
1883 update(TEXT(bv_), BufferView::UPDATE);
1884 TEXT(bv_)->CursorUp(bv_);
1885 TEXT(bv_)->FinishUndo();
1886 moveCursorUpdate(false);
1887 owner_->showState();
1891 if (!TEXT(bv_)->mark_set)
1892 beforeChange(TEXT(bv_));
1893 update(TEXT(bv_), BufferView::UPDATE);
1894 TEXT(bv_)->CursorDown(bv_);
1895 TEXT(bv_)->FinishUndo();
1896 moveCursorUpdate(false);
1897 owner_->showState();
1900 case LFUN_UP_PARAGRAPH:
1901 if (!TEXT(bv_)->mark_set)
1902 beforeChange(TEXT(bv_));
1903 update(TEXT(bv_), BufferView::UPDATE);
1904 TEXT(bv_)->CursorUpParagraph(bv_);
1905 TEXT(bv_)->FinishUndo();
1906 moveCursorUpdate(false);
1907 owner_->showState();
1910 case LFUN_DOWN_PARAGRAPH:
1911 if (!TEXT(bv_)->mark_set)
1912 beforeChange(TEXT(bv_));
1913 update(TEXT(bv_), BufferView::UPDATE);
1914 TEXT(bv_)->CursorDownParagraph(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 cursorPrevious(TEXT(bv_));
1925 TEXT(bv_)->FinishUndo();
1926 moveCursorUpdate(false);
1927 owner_->showState();
1931 if (!TEXT(bv_)->mark_set)
1932 beforeChange(TEXT(bv_));
1933 update(TEXT(bv_), BufferView::UPDATE);
1934 cursorNext(TEXT(bv_));
1935 TEXT(bv_)->FinishUndo();
1936 moveCursorUpdate(false);
1937 owner_->showState();
1941 if (!TEXT(bv_)->mark_set)
1942 beforeChange(TEXT(bv_));
1943 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1944 TEXT(bv_)->CursorHome(bv_);
1945 TEXT(bv_)->FinishUndo();
1946 moveCursorUpdate(false);
1947 owner_->showState();
1951 if (!TEXT(bv_)->mark_set)
1952 beforeChange(TEXT(bv_));
1954 BufferView::SELECT|BufferView::FITCUR);
1955 TEXT(bv_)->CursorEnd(bv_);
1956 TEXT(bv_)->FinishUndo();
1957 moveCursorUpdate(false);
1958 owner_->showState();
1961 case LFUN_SHIFT_TAB:
1963 if (!TEXT(bv_)->mark_set)
1964 beforeChange(TEXT(bv_));
1966 BufferView::SELECT|BufferView::FITCUR);
1967 TEXT(bv_)->CursorTab(bv_);
1968 TEXT(bv_)->FinishUndo();
1969 moveCursorUpdate(false);
1970 owner_->showState();
1973 case LFUN_WORDRIGHT:
1974 if (!TEXT(bv_)->mark_set)
1975 beforeChange(TEXT(bv_));
1976 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1977 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1978 TEXT(bv_)->CursorLeftOneWord(bv_);
1980 TEXT(bv_)->CursorRightOneWord(bv_);
1981 TEXT(bv_)->FinishUndo();
1982 moveCursorUpdate(false);
1983 owner_->showState();
1987 if (!TEXT(bv_)->mark_set)
1988 beforeChange(TEXT(bv_));
1989 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1990 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1991 TEXT(bv_)->CursorRightOneWord(bv_);
1993 TEXT(bv_)->CursorLeftOneWord(bv_);
1994 TEXT(bv_)->FinishUndo();
1995 moveCursorUpdate(false);
1996 owner_->showState();
1999 case LFUN_BEGINNINGBUF:
2000 if (!TEXT(bv_)->mark_set)
2001 beforeChange(TEXT(bv_));
2003 BufferView::SELECT|BufferView::FITCUR);
2004 TEXT(bv_)->CursorTop(bv_);
2005 TEXT(bv_)->FinishUndo();
2006 moveCursorUpdate(false);
2007 owner_->showState();
2011 if (!TEXT(bv_)->mark_set)
2012 beforeChange(TEXT(bv_));
2014 BufferView::SELECT|BufferView::FITCUR);
2015 TEXT(bv_)->CursorBottom(bv_);
2016 TEXT(bv_)->FinishUndo();
2017 moveCursorUpdate(false);
2018 owner_->showState();
2022 /* cursor selection ---------------------------- */
2025 BufferView::SELECT|BufferView::FITCUR);
2026 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2027 TEXT(bv_)->CursorLeft(bv_);
2029 TEXT(bv_)->CursorRight(bv_);
2030 TEXT(bv_)->FinishUndo();
2031 moveCursorUpdate(true);
2032 owner_->showState();
2037 BufferView::SELECT|BufferView::FITCUR);
2038 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2039 TEXT(bv_)->CursorRight(bv_);
2041 TEXT(bv_)->CursorLeft(bv_);
2042 TEXT(bv_)->FinishUndo();
2043 moveCursorUpdate(true);
2044 owner_->showState();
2049 BufferView::SELECT|BufferView::FITCUR);
2050 TEXT(bv_)->CursorUp(bv_);
2051 TEXT(bv_)->FinishUndo();
2052 moveCursorUpdate(true);
2053 owner_->showState();
2058 BufferView::SELECT|BufferView::FITCUR);
2059 TEXT(bv_)->CursorDown(bv_);
2060 TEXT(bv_)->FinishUndo();
2061 moveCursorUpdate(true);
2062 owner_->showState();
2065 case LFUN_UP_PARAGRAPHSEL:
2067 BufferView::SELECT|BufferView::FITCUR);
2068 TEXT(bv_)->CursorUpParagraph(bv_);
2069 TEXT(bv_)->FinishUndo();
2070 moveCursorUpdate(true);
2071 owner_->showState();
2074 case LFUN_DOWN_PARAGRAPHSEL:
2076 BufferView::SELECT|BufferView::FITCUR);
2077 TEXT(bv_)->CursorDownParagraph(bv_);
2078 TEXT(bv_)->FinishUndo();
2079 moveCursorUpdate(true);
2080 owner_->showState();
2084 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2085 cursorPrevious(TEXT(bv_));
2086 TEXT(bv_)->FinishUndo();
2087 moveCursorUpdate(true);
2088 owner_->showState();
2092 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2093 cursorNext(TEXT(bv_));
2094 TEXT(bv_)->FinishUndo();
2095 moveCursorUpdate(true);
2096 owner_->showState();
2100 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2101 TEXT(bv_)->CursorHome(bv_);
2102 TEXT(bv_)->FinishUndo();
2103 moveCursorUpdate(true);
2104 owner_->showState();
2108 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2109 TEXT(bv_)->CursorEnd(bv_);
2110 TEXT(bv_)->FinishUndo();
2111 moveCursorUpdate(true);
2112 owner_->showState();
2115 case LFUN_WORDRIGHTSEL:
2116 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2117 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2118 TEXT(bv_)->CursorLeftOneWord(bv_);
2120 TEXT(bv_)->CursorRightOneWord(bv_);
2121 TEXT(bv_)->FinishUndo();
2122 moveCursorUpdate(true);
2123 owner_->showState();
2126 case LFUN_WORDLEFTSEL:
2127 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2128 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2129 TEXT(bv_)->CursorRightOneWord(bv_);
2131 TEXT(bv_)->CursorLeftOneWord(bv_);
2132 TEXT(bv_)->FinishUndo();
2133 moveCursorUpdate(true);
2134 owner_->showState();
2137 case LFUN_BEGINNINGBUFSEL:
2138 if (TEXT(bv_)->inset_owner)
2140 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2141 TEXT(bv_)->CursorTop(bv_);
2142 TEXT(bv_)->FinishUndo();
2143 moveCursorUpdate(true);
2144 owner_->showState();
2147 case LFUN_ENDBUFSEL:
2148 if (TEXT(bv_)->inset_owner)
2151 BufferView::SELECT|BufferView::FITCUR);
2152 TEXT(bv_)->CursorBottom(bv_);
2153 TEXT(bv_)->FinishUndo();
2154 moveCursorUpdate(true);
2155 owner_->showState();
2158 // --- text changing commands ------------------------
2159 case LFUN_BREAKLINE:
2160 beforeChange(TEXT(bv_));
2161 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2163 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2164 moveCursorUpdate(false);
2167 case LFUN_PROTECTEDSPACE:
2169 LyXLayout const & style =
2170 textclasslist.Style(buffer_->params.textclass,
2171 TEXT(bv_)->cursor.par()->GetLayout());
2173 if (style.free_spacing) {
2174 TEXT(bv_)->InsertChar(bv_, ' ');
2175 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2177 bv_->protectedBlank(TEXT(bv_));
2179 moveCursorUpdate(false);
2184 if (TEXT(bv_)->mark_set) {
2185 beforeChange(TEXT(bv_));
2186 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2187 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2189 beforeChange(TEXT(bv_));
2190 TEXT(bv_)->mark_set = 1;
2191 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2192 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2194 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2198 if (!TEXT(bv_)->selection) {
2199 TEXT(bv_)->Delete(bv_);
2200 TEXT(bv_)->sel_cursor =
2203 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2204 // It is possible to make it a lot faster still
2205 // just comment out the line below...
2210 moveCursorUpdate(false);
2211 owner_->showState();
2215 case LFUN_DELETE_SKIP:
2217 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2219 LyXCursor cursor = TEXT(bv_)->cursor;
2221 if (!TEXT(bv_)->selection) {
2222 if (cursor.pos() == cursor.par()->Last()) {
2223 TEXT(bv_)->CursorRight(bv_);
2224 cursor = TEXT(bv_)->cursor;
2225 if (cursor.pos() == 0
2226 && !(cursor.par()->params.spaceTop()
2227 == VSpace (VSpace::NONE))) {
2228 TEXT(bv_)->SetParagraph
2230 cursor.par()->params.lineTop(),
2231 cursor.par()->params.lineBottom(),
2232 cursor.par()->params.pagebreakTop(),
2233 cursor.par()->params.pagebreakBottom(),
2234 VSpace(VSpace::NONE),
2235 cursor.par()->params.spaceBottom(),
2236 cursor.par()->params.align(),
2237 cursor.par()->params.labelWidthString(), 0);
2238 TEXT(bv_)->CursorLeft(bv_);
2240 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2242 TEXT(bv_)->CursorLeft(bv_);
2243 TEXT(bv_)->Delete(bv_);
2244 TEXT(bv_)->sel_cursor =
2247 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2250 TEXT(bv_)->Delete(bv_);
2251 TEXT(bv_)->sel_cursor =
2254 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2262 /* -------> Delete word forward. */
2263 case LFUN_DELETE_WORD_FORWARD:
2264 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2265 TEXT(bv_)->DeleteWordForward(bv_);
2266 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2267 moveCursorUpdate(false);
2268 owner_->showState();
2271 /* -------> Delete word backward. */
2272 case LFUN_DELETE_WORD_BACKWARD:
2273 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2274 TEXT(bv_)->DeleteWordBackward(bv_);
2275 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2276 moveCursorUpdate(false);
2277 owner_->showState();
2280 /* -------> Kill to end of line. */
2281 case LFUN_DELETE_LINE_FORWARD:
2282 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2283 TEXT(bv_)->DeleteLineForward(bv_);
2284 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2285 moveCursorUpdate(false);
2288 /* -------> Set mark off. */
2290 beforeChange(TEXT(bv_));
2291 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2292 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2293 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2296 /* -------> Set mark on. */
2298 beforeChange(TEXT(bv_));
2299 TEXT(bv_)->mark_set = 1;
2300 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2301 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2302 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2305 case LFUN_BACKSPACE:
2307 if (!TEXT(bv_)->selection) {
2308 if (owner_->getIntl()->getTrans().backspace()) {
2309 TEXT(bv_)->Backspace(bv_);
2310 TEXT(bv_)->sel_cursor =
2313 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2314 // It is possible to make it a lot faster still
2315 // just comment out the line below...
2321 owner_->showState();
2326 case LFUN_BACKSPACE_SKIP:
2328 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2330 LyXCursor cursor = TEXT(bv_)->cursor;
2332 if (!TEXT(bv_)->selection) {
2333 if (cursor.pos() == 0
2334 && !(cursor.par()->params.spaceTop()
2335 == VSpace (VSpace::NONE))) {
2336 TEXT(bv_)->SetParagraph
2338 cursor.par()->params.lineTop(),
2339 cursor.par()->params.lineBottom(),
2340 cursor.par()->params.pagebreakTop(),
2341 cursor.par()->params.pagebreakBottom(),
2342 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2343 cursor.par()->params.align(),
2344 cursor.par()->params.labelWidthString(), 0);
2346 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2348 TEXT(bv_)->Backspace(bv_);
2349 TEXT(bv_)->sel_cursor
2352 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2359 case LFUN_BREAKPARAGRAPH:
2361 beforeChange(TEXT(bv_));
2362 TEXT(bv_)->BreakParagraph(bv_, 0);
2364 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2365 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2367 owner_->showState();
2371 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2373 beforeChange(TEXT(bv_));
2374 TEXT(bv_)->BreakParagraph(bv_, 1);
2376 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2377 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2379 owner_->showState();
2383 case LFUN_BREAKPARAGRAPH_SKIP:
2385 // When at the beginning of a paragraph, remove
2386 // indentation and add a "defskip" at the top.
2387 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2389 LyXCursor cursor = TEXT(bv_)->cursor;
2391 beforeChange(TEXT(bv_));
2392 if (cursor.pos() == 0) {
2393 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2394 TEXT(bv_)->SetParagraph
2396 cursor.par()->params.lineTop(),
2397 cursor.par()->params.lineBottom(),
2398 cursor.par()->params.pagebreakTop(),
2399 cursor.par()->params.pagebreakBottom(),
2400 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2401 cursor.par()->params.align(),
2402 cursor.par()->params.labelWidthString(), 1);
2403 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2407 TEXT(bv_)->BreakParagraph(bv_, 0);
2408 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2412 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2413 TEXT(bv_)->sel_cursor = cursor;
2415 owner_->showState();
2419 case LFUN_PARAGRAPH_SPACING:
2421 LyXParagraph * par = TEXT(bv_)->cursor.par();
2422 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2423 float cur_value = 1.0;
2424 if (cur_spacing == Spacing::Other) {
2425 cur_value = par->params.spacing().getValue();
2428 istringstream istr(argument.c_str());
2432 Spacing::Space new_spacing = cur_spacing;
2433 float new_value = cur_value;
2435 lyxerr << "Missing argument to `paragraph-spacing'"
2437 } else if (tmp == "single") {
2438 new_spacing = Spacing::Single;
2439 } else if (tmp == "onehalf") {
2440 new_spacing = Spacing::Onehalf;
2441 } else if (tmp == "double") {
2442 new_spacing = Spacing::Double;
2443 } else if (tmp == "other") {
2444 new_spacing = Spacing::Other;
2447 lyxerr << "new_value = " << tmpval << endl;
2450 } else if (tmp == "default") {
2451 new_spacing = Spacing::Default;
2453 lyxerr << _("Unknown spacing argument: ")
2454 << argument << endl;
2456 if (cur_spacing != new_spacing || cur_value != new_value) {
2457 par->params.spacing(Spacing(new_spacing, new_value));
2458 TEXT(bv_)->RedoParagraph(bv_);
2460 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2466 beforeChange(TEXT(bv_));
2467 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2468 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2469 moveCursorUpdate(false);
2475 InsetCommandParams p;
2476 if (action == LFUN_HTMLURL)
2477 p.setCmdName("htmlurl");
2479 p.setCmdName("url");
2480 owner_->getDialogs()->createUrl( p.getAsString() );
2484 case LFUN_INSERT_URL:
2486 InsetCommandParams p;
2487 p.setFromString( argument );
2489 InsetUrl * inset = new InsetUrl( p );
2490 if (!bv_->insertInset(inset))
2493 bv_->updateInset( inset, true );
2497 case LFUN_INSET_TEXT:
2499 InsetText * new_inset = new InsetText;
2500 if (bv_->insertInset(new_inset))
2501 new_inset->Edit(bv_, 0, 0, 0);
2507 case LFUN_INSET_ERT:
2509 InsetERT * new_inset = new InsetERT;
2510 if (bv_->insertInset(new_inset))
2511 new_inset->Edit(bv_, 0, 0, 0);
2517 case LFUN_INSET_EXTERNAL:
2519 InsetExternal * new_inset = new InsetExternal;
2520 if (bv_->insertInset(new_inset))
2521 new_inset->Edit(bv_, 0, 0, 0);
2527 case LFUN_INSET_FOOTNOTE:
2529 InsetFoot * new_inset = new InsetFoot;
2530 if (bv_->insertInset(new_inset))
2531 new_inset->Edit(bv_, 0, 0, 0);
2537 case LFUN_INSET_MARGINAL:
2539 InsetMarginal * new_inset = new InsetMarginal;
2540 if (bv_->insertInset(new_inset))
2541 new_inset->Edit(bv_, 0, 0, 0);
2547 case LFUN_INSET_MINIPAGE:
2549 InsetMinipage * new_inset = new InsetMinipage;
2550 if (bv_->insertInset(new_inset))
2551 new_inset->Edit(bv_, 0, 0, 0);
2557 case LFUN_INSET_FLOAT:
2559 // check if the float type exist
2560 if (floatList.typeExist(argument)) {
2561 InsetFloat * new_inset = new InsetFloat(argument);
2562 if (bv_->insertInset(new_inset))
2563 new_inset->Edit(bv_, 0, 0, 0);
2567 lyxerr << "Non-existant float type: "
2568 << argument << endl;
2574 case LFUN_INSET_LIST:
2576 InsetList * new_inset = new InsetList;
2577 if (bv_->insertInset(new_inset))
2578 new_inset->Edit(bv_, 0, 0, 0);
2584 case LFUN_INSET_THEOREM:
2586 InsetTheorem * new_inset = new InsetTheorem;
2587 if (bv_->insertInset(new_inset))
2588 new_inset->Edit(bv_, 0, 0, 0);
2594 case LFUN_INSET_CAPTION:
2596 // Do we have a locking inset...
2597 if (bv_->theLockingInset()) {
2598 lyxerr << "Locking inset code: "
2599 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2600 InsetCaption * new_inset = new InsetCaption;
2601 new_inset->setOwner(bv_->theLockingInset());
2602 new_inset->SetAutoBreakRows(true);
2603 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2604 new_inset->SetFrameColor(0, LColor::footnoteframe);
2605 if (bv_->insertInset(new_inset))
2606 new_inset->Edit(bv_, 0, 0, 0);
2613 case LFUN_INSET_TABULAR:
2616 if (!argument.empty())
2617 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2618 InsetTabular * new_inset =
2619 new InsetTabular(*buffer_, r, c);
2621 TEXT(bv_)->real_current_font.isRightToLeft();
2622 if (!bv_->open_new_inset(new_inset, rtl))
2627 // --- lyxserver commands ----------------------------
2629 case LFUN_CHARATCURSOR:
2631 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2632 if (pos < TEXT(bv_)->cursor.par()->size())
2633 owner_->getLyXFunc()->setMessage(
2634 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2636 owner_->getLyXFunc()->setMessage("EOF");
2641 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2643 + tostr(TEXT(bv_)->cursor.y()));
2650 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2651 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2655 case LFUN_GETLAYOUT:
2656 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2661 LyXFont & font = TEXT(bv_)->current_font;
2662 if (font.shape() == LyXFont::ITALIC_SHAPE)
2663 owner_->getLyXFunc()->setMessage("E");
2664 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2665 owner_->getLyXFunc()->setMessage("N");
2667 owner_->getLyXFunc()->setMessage("0");
2674 LyXFont & font = TEXT(bv_)->current_font;
2675 if (font.latex() == LyXFont::ON)
2676 owner_->getLyXFunc()->setMessage("L");
2678 owner_->getLyXFunc()->setMessage("0");
2682 // --- accented characters ---------------------------
2685 case LFUN_CIRCUMFLEX:
2695 case LFUN_SPECIAL_CARON:
2698 case LFUN_HUNG_UMLAUT:
2701 owner_->getLyXFunc()->handleKeyFunc(action);
2704 // --- insert characters ----------------------------------------
2706 case LFUN_MATH_DELIM:
2707 case LFUN_INSERT_MATRIX:
2710 if (bv_->open_new_inset(new InsetFormula(false)))
2712 bv_->theLockingInset()
2713 ->LocalDispatch(bv_, action, argument);
2719 case LFUN_INSERT_MATH:
2721 math_insert_symbol(bv_, argument);
2725 case LFUN_MATH_DISPLAY:
2728 bv_->open_new_inset(new InsetFormula(true));
2732 case LFUN_MATH_MACRO:
2737 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2739 string const s1 = token(s, ' ', 1);
2740 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2741 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2747 case LFUN_MATH_MODE: // Open or create a math inset
2750 bv_->open_new_inset(new InsetFormula);
2751 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2755 case LFUN_CITATION_INSERT:
2757 InsetCommandParams p;
2758 p.setFromString( argument );
2760 InsetCitation * inset = new InsetCitation( p );
2761 if (!bv_->insertInset(inset))
2764 bv_->updateInset( inset, true );
2768 case LFUN_INSERT_BIBTEX:
2770 // ale970405+lasgoutt970425
2771 // The argument can be up to two tokens separated
2772 // by a space. The first one is the bibstyle.
2773 string const db = token(argument, ' ', 0);
2774 string bibstyle = token(argument, ' ', 1);
2775 if (bibstyle.empty())
2778 InsetCommandParams p( "BibTeX", db, bibstyle );
2779 InsetBibtex * inset = new InsetBibtex(p);
2781 if (bv_->insertInset(inset)) {
2782 if (argument.empty())
2783 inset->Edit(bv_, 0, 0, 0);
2789 // BibTeX data bases
2790 case LFUN_BIBDB_ADD:
2792 InsetBibtex * inset =
2793 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2795 inset->addDatabase(argument);
2800 case LFUN_BIBDB_DEL:
2802 InsetBibtex * inset =
2803 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2805 inset->delDatabase(argument);
2810 case LFUN_BIBTEX_STYLE:
2812 InsetBibtex * inset =
2813 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2815 inset->setOptions(argument);
2820 case LFUN_INDEX_CREATE:
2822 InsetCommandParams p( "index" );
2824 if (argument.empty()) {
2825 // Get the word immediately preceding the cursor
2826 LyXParagraph::size_type curpos =
2827 TEXT(bv_)->cursor.pos() - 1;
2831 curstring = TEXT(bv_)
2832 ->cursor.par()->GetWord(curpos);
2834 p.setContents( curstring );
2836 p.setContents( argument );
2839 owner_->getDialogs()->createIndex( p.getAsString() );
2843 case LFUN_INDEX_INSERT:
2845 InsetCommandParams p;
2846 p.setFromString(argument);
2847 InsetIndex * inset = new InsetIndex(p);
2849 if (!bv_->insertInset(inset))
2852 bv_->updateInset(inset, true);
2856 case LFUN_INDEX_INSERT_LAST:
2858 // Get word immediately preceding the cursor
2859 LyXParagraph::size_type curpos =
2860 TEXT(bv_)->cursor.pos() - 1;
2861 // Can't do that at the beginning of a paragraph
2862 if (curpos < 0) break;
2864 string const curstring(TEXT(bv_)
2865 ->cursor.par()->GetWord(curpos));
2867 InsetCommandParams p("index", curstring);
2868 InsetIndex * inset = new InsetIndex(p);
2870 if (!bv_->insertInset(inset))
2873 bv_->updateInset(inset, true);
2877 case LFUN_INDEX_PRINT:
2879 InsetCommandParams p("printindex");
2880 Inset * inset = new InsetPrintIndex(p);
2881 if (!bv_->insertInset(inset, "Standard", true))
2886 case LFUN_PARENTINSERT:
2888 lyxerr << "arg " << argument << endl;
2889 InsetCommandParams p( "lyxparent", argument );
2890 Inset * inset = new InsetParent(p, *buffer_);
2891 if (!bv_->insertInset(inset, "Standard", true))
2896 case LFUN_CHILD_INSERT:
2898 InsetCommandParams p;
2899 p.setFromString(argument);
2901 InsetInclude * inset = new InsetInclude(p, *buffer_);
2902 if (!bv_->insertInset(inset))
2905 bv_->updateInset(inset, true);
2909 case LFUN_INSERT_NOTE:
2913 case LFUN_SELFINSERT:
2915 LyXFont const old_font(TEXT(bv_)->real_current_font);
2916 for (string::size_type i = 0; i < argument.length(); ++i) {
2917 TEXT(bv_)->InsertChar(bv_, argument[i]);
2918 // This needs to be in the loop, or else we
2919 // won't break lines correctly. (Asger)
2921 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2923 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2924 moveCursorUpdate(false);
2926 // real_current_font.number can change so we need to
2927 // update the minibuffer
2928 if (old_font != TEXT(bv_)->real_current_font)
2929 owner_->showState();
2933 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2937 time_t now_time_t = time(NULL);
2938 now_tm = localtime(&now_time_t);
2939 setlocale(LC_TIME, "");
2941 if (!argument.empty())
2944 arg = lyxrc.date_insert_format;
2946 int const datetmp_len =
2947 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2948 for (int i = 0; i < datetmp_len; i++) {
2949 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2951 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2954 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2955 moveCursorUpdate(false);
2959 case LFUN_UNKNOWN_ACTION:
2962 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2966 if (buffer_->isReadonly()) {
2967 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
2970 if (!argument.empty()) {
2971 /* Automatically delete the currently selected
2972 * text and replace it with what is being
2973 * typed in now. Depends on lyxrc settings
2974 * "auto_region_delete", which defaults to
2977 if (lyxrc.auto_region_delete) {
2978 if (TEXT(bv_)->selection){
2979 TEXT(bv_)->CutSelection(bv_, false);
2981 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2985 beforeChange(TEXT(bv_));
2986 LyXFont const old_font(TEXT(bv_)->real_current_font);
2987 for (string::size_type i = 0;
2988 i < argument.length(); ++i) {
2989 if (greek_kb_flag) {
2990 if (!math_insert_greek(bv_,
2992 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2994 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2997 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2999 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3000 moveCursorUpdate(false);
3002 // real_current_font.number can change so we need to
3003 // update the minibuffer
3004 if (old_font != TEXT(bv_)->real_current_font)
3005 owner_->showState();
3007 // if we don't have an argument there was something
3008 // strange going on so we just tell this to someone!
3009 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));