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
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;
1430 string const trypath = owner_->buffer()->filepath;
1431 // If directory is writeable, use this as default.
1432 if (IsDirWriteable(trypath) == 1)
1438 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
1439 fileDlg.SetButton(1, _("Examples"),
1440 AddPath(system_lyxdir, "examples"));
1441 filename = fileDlg.Select(_("Select Document to Insert"),
1445 // check selected filename
1446 if (filename.empty()) {
1447 owner_->getMiniBuffer()->Set(_("Canceled."));
1452 // get absolute path of file and make sure the filename ends
1454 filename = MakeAbsPath(filename);
1455 if (!IsLyXFilename(filename))
1459 owner_->getMiniBuffer()->Set(_("Inserting document"),
1460 MakeDisplayPath(filename), "...");
1461 bool const res = bv_->insertLyXFile(filename);
1463 owner_->getMiniBuffer()->Set(_("Document"),
1464 MakeDisplayPath(filename),
1467 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1468 MakeDisplayPath(filename));
1473 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1476 // --- Misc -------------------------------------------
1479 TEXT(bv_)->toggleAppendix(bv_);
1480 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1484 case LFUN_TOC_INSERT:
1485 case LFUN_LOA_INSERT:
1486 case LFUN_LOF_INSERT:
1487 case LFUN_LOT_INSERT:
1489 InsetCommandParams p;
1491 if (action == LFUN_TOC_INSERT )
1492 p.setCmdName( "tableofcontents" );
1493 else if (action == LFUN_LOA_INSERT )
1494 p.setCmdName( "listofalgorithms" );
1495 else if (action == LFUN_LOF_INSERT )
1496 p.setCmdName( "listoffigures" );
1498 p.setCmdName( "listoftables" );
1500 Inset * inset = new InsetTOC( p );
1501 if (!bv_->insertInset( inset, "Standard", true ) )
1506 case LFUN_TABULAR_FEATURE:
1507 case LFUN_SCROLL_INSET:
1508 // this is not handled here as this funktion is only aktive
1509 // if we have a locking_inset and that one is (or contains)
1513 case LFUN_INSET_GRAPHICS:
1515 Inset * new_inset = new InsetGraphics;
1516 if (!bv_->insertInset(new_inset)) {
1519 // this is need because you don't use a inset->Edit()
1520 bv_->updateInset(new_inset, true);
1521 new_inset->Edit(bv_, 0, 0, 0);
1531 case LFUN_PASTESELECTION:
1533 bool asPara = false;
1534 if (argument == "paragraph") asPara = true;
1535 pasteClipboard(asPara);
1547 case LFUN_LAYOUT_COPY:
1548 bv_->copyEnvironment();
1551 case LFUN_LAYOUT_PASTE:
1552 bv_->pasteEnvironment();
1556 case LFUN_GOTOERROR:
1557 bv_->gotoInset(Inset::ERROR_CODE, false);
1561 bv_->gotoInset(Inset::IGNORE_CODE, false);
1564 case LFUN_REFERENCE_GOTO:
1566 vector<Inset::Code> tmp;
1567 tmp.push_back(Inset::LABEL_CODE);
1568 tmp.push_back(Inset::REF_CODE);
1569 bv_->gotoInset(tmp, true);
1573 case LFUN_HYPHENATION:
1574 bv_->hyphenationPoint();
1581 case LFUN_END_OF_SENTENCE:
1582 bv_->endOfSentenceDot();
1585 case LFUN_MENU_SEPARATOR:
1586 bv_->menuSeparator();
1594 changeDepth(bv_, TEXT(bv_), 0);
1597 case LFUN_DEPTH_MIN:
1598 changeDepth(bv_, TEXT(bv_), -1);
1601 case LFUN_DEPTH_PLUS:
1602 changeDepth(bv_, TEXT(bv_), 1);
1606 owner_->getDialogs()->setUserFreeFont();
1612 owner_->showState();
1615 case LFUN_FILE_INSERT:
1617 MenuInsertLyXFile(argument);
1621 case LFUN_FILE_INSERT_ASCII:
1623 bool asPara = (argument == "paragraph");
1624 InsertAsciiFile(bv_, string(), asPara);
1630 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1631 << argument << endl;
1633 // Derive layout number from given argument (string)
1634 // and current buffer's textclass (number). */
1635 LyXTextClassList::ClassList::size_type tclass =
1636 buffer_->params.textclass;
1637 pair <bool, LyXTextClass::size_type> layout =
1638 textclasslist.NumberOfLayout(tclass, argument);
1640 // If the entry is obsolete, use the new one instead.
1642 string obs = textclasslist.Style(tclass,layout.second)
1646 textclasslist.NumberOfLayout(tclass, obs);
1649 // see if we found the layout number:
1650 if (!layout.first) {
1651 owner_->getLyXFunc()->setErrorMessage(
1652 string(N_("Layout ")) + argument +
1657 if (current_layout != layout.second) {
1659 current_layout = layout.second;
1661 BufferView::SELECT|BufferView::FITCUR);
1662 TEXT(bv_)->SetLayout(bv_, layout.second);
1663 owner_->setLayout(layout.second);
1665 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1672 Lang(bv_, argument);
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1694 owner_->showState();
1699 owner_->showState();
1704 owner_->showState();
1709 owner_->showState();
1712 case LFUN_UNDERLINE:
1714 owner_->showState();
1717 case LFUN_FONT_SIZE:
1718 FontSize(bv_, argument);
1719 owner_->showState();
1722 case LFUN_FONT_STATE:
1723 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1726 case LFUN_UPCASE_WORD:
1727 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1728 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1729 if (TEXT(bv_)->inset_owner)
1730 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1731 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1734 case LFUN_LOWCASE_WORD:
1735 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1736 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1737 if (TEXT(bv_)->inset_owner)
1738 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1739 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1742 case LFUN_CAPITALIZE_WORD:
1743 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1744 TEXT(bv_)->ChangeWordCase(bv_,
1745 LyXText::text_capitalization);
1746 if (TEXT(bv_)->inset_owner)
1747 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1748 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1751 case LFUN_INSERT_LABEL:
1752 MenuInsertLabel(bv_, argument);
1755 case LFUN_REF_INSERT:
1756 if (argument.empty()) {
1757 InsetCommandParams p("ref");
1758 owner_->getDialogs()->createRef(p.getAsString());
1760 InsetCommandParams p;
1761 p.setFromString(argument);
1763 InsetRef * inset = new InsetRef(p, *buffer_);
1764 if (!bv_->insertInset(inset))
1767 bv_->updateInset(inset, true);
1771 case LFUN_BOOKMARK_SAVE:
1772 savePosition(strToUnsignedInt(argument));
1775 case LFUN_BOOKMARK_GOTO:
1776 restorePosition(strToUnsignedInt(argument));
1781 string label(argument);
1782 if (label.empty()) {
1784 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1786 label = inset->getContents();
1791 if (!label.empty()) {
1792 //bv_->savePosition(0);
1793 if (!bv_->gotoLabel(label))
1794 WriteAlert(_("Error"),
1795 _("Couldn't find this label"),
1796 _("in current document."));
1801 // --- Cursor Movements -----------------------------
1804 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1805 if (!TEXT(bv_)->mark_set)
1806 beforeChange(TEXT(bv_));
1807 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1809 TEXT(bv_)->CursorLeft(bv_, false);
1810 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1811 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1812 == LyXParagraph::META_INSET
1813 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1814 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1815 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1816 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1820 TEXT(bv_)->GetFont(buffer_,
1821 TEXT(bv_)->cursor.par(),
1822 TEXT(bv_)->cursor.pos());
1823 y = tmpinset->descent(bv_,font);
1825 tmpinset->Edit(bv_, 0, y, 0);
1829 TEXT(bv_)->CursorRight(bv_, false);
1830 TEXT(bv_)->FinishUndo();
1831 moveCursorUpdate(false);
1832 owner_->showState();
1838 // This is soooo ugly. Isn`t it possible to make
1839 // it simpler? (Lgb)
1840 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1841 if (!TEXT(bv_)->mark_set)
1842 beforeChange(TEXT(bv_));
1843 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1844 LyXCursor cur = TEXT(bv_)->cursor;
1846 TEXT(bv_)->CursorLeft(bv_, false);
1847 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1848 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1849 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1850 LyXParagraph::META_INSET) &&
1851 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1852 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1853 == Inset::HIGHLY_EDITABLE))
1855 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1856 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1857 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1858 TEXT(bv_)->cursor.par(),
1859 TEXT(bv_)->cursor.pos());
1861 : tmpinset->descent(bv_,font);
1864 tmpinset->width(bv_,font),
1869 TEXT(bv_)->CursorRight(bv_, false);
1871 TEXT(bv_)->FinishUndo();
1872 moveCursorUpdate(false);
1873 owner_->showState();
1878 if (!TEXT(bv_)->mark_set)
1879 beforeChange(TEXT(bv_));
1880 update(TEXT(bv_), BufferView::UPDATE);
1881 TEXT(bv_)->CursorUp(bv_);
1882 TEXT(bv_)->FinishUndo();
1883 moveCursorUpdate(false);
1884 owner_->showState();
1888 if (!TEXT(bv_)->mark_set)
1889 beforeChange(TEXT(bv_));
1890 update(TEXT(bv_), BufferView::UPDATE);
1891 TEXT(bv_)->CursorDown(bv_);
1892 TEXT(bv_)->FinishUndo();
1893 moveCursorUpdate(false);
1894 owner_->showState();
1897 case LFUN_UP_PARAGRAPH:
1898 if (!TEXT(bv_)->mark_set)
1899 beforeChange(TEXT(bv_));
1900 update(TEXT(bv_), BufferView::UPDATE);
1901 TEXT(bv_)->CursorUpParagraph(bv_);
1902 TEXT(bv_)->FinishUndo();
1903 moveCursorUpdate(false);
1904 owner_->showState();
1907 case LFUN_DOWN_PARAGRAPH:
1908 if (!TEXT(bv_)->mark_set)
1909 beforeChange(TEXT(bv_));
1910 update(TEXT(bv_), BufferView::UPDATE);
1911 TEXT(bv_)->CursorDownParagraph(bv_);
1912 TEXT(bv_)->FinishUndo();
1913 moveCursorUpdate(false);
1914 owner_->showState();
1918 if (!TEXT(bv_)->mark_set)
1919 beforeChange(TEXT(bv_));
1920 update(TEXT(bv_), BufferView::UPDATE);
1921 cursorPrevious(TEXT(bv_));
1922 TEXT(bv_)->FinishUndo();
1923 moveCursorUpdate(false);
1924 owner_->showState();
1928 if (!TEXT(bv_)->mark_set)
1929 beforeChange(TEXT(bv_));
1930 update(TEXT(bv_), BufferView::UPDATE);
1931 cursorNext(TEXT(bv_));
1932 TEXT(bv_)->FinishUndo();
1933 moveCursorUpdate(false);
1934 owner_->showState();
1938 if (!TEXT(bv_)->mark_set)
1939 beforeChange(TEXT(bv_));
1940 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1941 TEXT(bv_)->CursorHome(bv_);
1942 TEXT(bv_)->FinishUndo();
1943 moveCursorUpdate(false);
1944 owner_->showState();
1948 if (!TEXT(bv_)->mark_set)
1949 beforeChange(TEXT(bv_));
1951 BufferView::SELECT|BufferView::FITCUR);
1952 TEXT(bv_)->CursorEnd(bv_);
1953 TEXT(bv_)->FinishUndo();
1954 moveCursorUpdate(false);
1955 owner_->showState();
1958 case LFUN_SHIFT_TAB:
1960 if (!TEXT(bv_)->mark_set)
1961 beforeChange(TEXT(bv_));
1963 BufferView::SELECT|BufferView::FITCUR);
1964 TEXT(bv_)->CursorTab(bv_);
1965 TEXT(bv_)->FinishUndo();
1966 moveCursorUpdate(false);
1967 owner_->showState();
1970 case LFUN_WORDRIGHT:
1971 if (!TEXT(bv_)->mark_set)
1972 beforeChange(TEXT(bv_));
1973 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1974 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1975 TEXT(bv_)->CursorLeftOneWord(bv_);
1977 TEXT(bv_)->CursorRightOneWord(bv_);
1978 TEXT(bv_)->FinishUndo();
1979 moveCursorUpdate(false);
1980 owner_->showState();
1984 if (!TEXT(bv_)->mark_set)
1985 beforeChange(TEXT(bv_));
1986 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1987 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1988 TEXT(bv_)->CursorRightOneWord(bv_);
1990 TEXT(bv_)->CursorLeftOneWord(bv_);
1991 TEXT(bv_)->FinishUndo();
1992 moveCursorUpdate(false);
1993 owner_->showState();
1996 case LFUN_BEGINNINGBUF:
1997 if (!TEXT(bv_)->mark_set)
1998 beforeChange(TEXT(bv_));
2000 BufferView::SELECT|BufferView::FITCUR);
2001 TEXT(bv_)->CursorTop(bv_);
2002 TEXT(bv_)->FinishUndo();
2003 moveCursorUpdate(false);
2004 owner_->showState();
2008 if (!TEXT(bv_)->mark_set)
2009 beforeChange(TEXT(bv_));
2011 BufferView::SELECT|BufferView::FITCUR);
2012 TEXT(bv_)->CursorBottom(bv_);
2013 TEXT(bv_)->FinishUndo();
2014 moveCursorUpdate(false);
2015 owner_->showState();
2019 /* cursor selection ---------------------------- */
2022 BufferView::SELECT|BufferView::FITCUR);
2023 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2024 TEXT(bv_)->CursorLeft(bv_);
2026 TEXT(bv_)->CursorRight(bv_);
2027 TEXT(bv_)->FinishUndo();
2028 moveCursorUpdate(true);
2029 owner_->showState();
2034 BufferView::SELECT|BufferView::FITCUR);
2035 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2036 TEXT(bv_)->CursorRight(bv_);
2038 TEXT(bv_)->CursorLeft(bv_);
2039 TEXT(bv_)->FinishUndo();
2040 moveCursorUpdate(true);
2041 owner_->showState();
2046 BufferView::SELECT|BufferView::FITCUR);
2047 TEXT(bv_)->CursorUp(bv_);
2048 TEXT(bv_)->FinishUndo();
2049 moveCursorUpdate(true);
2050 owner_->showState();
2055 BufferView::SELECT|BufferView::FITCUR);
2056 TEXT(bv_)->CursorDown(bv_);
2057 TEXT(bv_)->FinishUndo();
2058 moveCursorUpdate(true);
2059 owner_->showState();
2062 case LFUN_UP_PARAGRAPHSEL:
2064 BufferView::SELECT|BufferView::FITCUR);
2065 TEXT(bv_)->CursorUpParagraph(bv_);
2066 TEXT(bv_)->FinishUndo();
2067 moveCursorUpdate(true);
2068 owner_->showState();
2071 case LFUN_DOWN_PARAGRAPHSEL:
2073 BufferView::SELECT|BufferView::FITCUR);
2074 TEXT(bv_)->CursorDownParagraph(bv_);
2075 TEXT(bv_)->FinishUndo();
2076 moveCursorUpdate(true);
2077 owner_->showState();
2081 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2082 cursorPrevious(TEXT(bv_));
2083 TEXT(bv_)->FinishUndo();
2084 moveCursorUpdate(true);
2085 owner_->showState();
2089 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2090 cursorNext(TEXT(bv_));
2091 TEXT(bv_)->FinishUndo();
2092 moveCursorUpdate(true);
2093 owner_->showState();
2097 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2098 TEXT(bv_)->CursorHome(bv_);
2099 TEXT(bv_)->FinishUndo();
2100 moveCursorUpdate(true);
2101 owner_->showState();
2105 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2106 TEXT(bv_)->CursorEnd(bv_);
2107 TEXT(bv_)->FinishUndo();
2108 moveCursorUpdate(true);
2109 owner_->showState();
2112 case LFUN_WORDRIGHTSEL:
2113 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2114 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2115 TEXT(bv_)->CursorLeftOneWord(bv_);
2117 TEXT(bv_)->CursorRightOneWord(bv_);
2118 TEXT(bv_)->FinishUndo();
2119 moveCursorUpdate(true);
2120 owner_->showState();
2123 case LFUN_WORDLEFTSEL:
2124 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2125 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2126 TEXT(bv_)->CursorRightOneWord(bv_);
2128 TEXT(bv_)->CursorLeftOneWord(bv_);
2129 TEXT(bv_)->FinishUndo();
2130 moveCursorUpdate(true);
2131 owner_->showState();
2134 case LFUN_BEGINNINGBUFSEL:
2135 if (TEXT(bv_)->inset_owner)
2137 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2138 TEXT(bv_)->CursorTop(bv_);
2139 TEXT(bv_)->FinishUndo();
2140 moveCursorUpdate(true);
2141 owner_->showState();
2144 case LFUN_ENDBUFSEL:
2145 if (TEXT(bv_)->inset_owner)
2148 BufferView::SELECT|BufferView::FITCUR);
2149 TEXT(bv_)->CursorBottom(bv_);
2150 TEXT(bv_)->FinishUndo();
2151 moveCursorUpdate(true);
2152 owner_->showState();
2155 // --- text changing commands ------------------------
2156 case LFUN_BREAKLINE:
2157 beforeChange(TEXT(bv_));
2158 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2160 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2161 moveCursorUpdate(false);
2164 case LFUN_PROTECTEDSPACE:
2166 LyXLayout const & style =
2167 textclasslist.Style(buffer_->params.textclass,
2168 TEXT(bv_)->cursor.par()->GetLayout());
2170 if (style.free_spacing) {
2171 TEXT(bv_)->InsertChar(bv_, ' ');
2172 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2174 bv_->protectedBlank(TEXT(bv_));
2176 moveCursorUpdate(false);
2181 if (TEXT(bv_)->mark_set) {
2182 beforeChange(TEXT(bv_));
2183 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2184 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2186 beforeChange(TEXT(bv_));
2187 TEXT(bv_)->mark_set = 1;
2188 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2189 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2191 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2195 if (!TEXT(bv_)->selection) {
2196 TEXT(bv_)->Delete(bv_);
2197 TEXT(bv_)->sel_cursor =
2200 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2201 // It is possible to make it a lot faster still
2202 // just comment out the line below...
2207 moveCursorUpdate(false);
2208 owner_->showState();
2212 case LFUN_DELETE_SKIP:
2214 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2216 LyXCursor cursor = TEXT(bv_)->cursor;
2218 if (!TEXT(bv_)->selection) {
2219 if (cursor.pos() == cursor.par()->Last()) {
2220 TEXT(bv_)->CursorRight(bv_);
2221 cursor = TEXT(bv_)->cursor;
2222 if (cursor.pos() == 0
2223 && !(cursor.par()->params.spaceTop()
2224 == VSpace (VSpace::NONE))) {
2225 TEXT(bv_)->SetParagraph
2227 cursor.par()->params.lineTop(),
2228 cursor.par()->params.lineBottom(),
2229 cursor.par()->params.pagebreakTop(),
2230 cursor.par()->params.pagebreakBottom(),
2231 VSpace(VSpace::NONE),
2232 cursor.par()->params.spaceBottom(),
2233 cursor.par()->params.align(),
2234 cursor.par()->params.labelWidthString(), 0);
2235 TEXT(bv_)->CursorLeft(bv_);
2237 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2239 TEXT(bv_)->CursorLeft(bv_);
2240 TEXT(bv_)->Delete(bv_);
2241 TEXT(bv_)->sel_cursor =
2244 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2247 TEXT(bv_)->Delete(bv_);
2248 TEXT(bv_)->sel_cursor =
2251 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2259 /* -------> Delete word forward. */
2260 case LFUN_DELETE_WORD_FORWARD:
2261 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2262 TEXT(bv_)->DeleteWordForward(bv_);
2263 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2264 moveCursorUpdate(false);
2265 owner_->showState();
2268 /* -------> Delete word backward. */
2269 case LFUN_DELETE_WORD_BACKWARD:
2270 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2271 TEXT(bv_)->DeleteWordBackward(bv_);
2272 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2273 moveCursorUpdate(false);
2274 owner_->showState();
2277 /* -------> Kill to end of line. */
2278 case LFUN_DELETE_LINE_FORWARD:
2279 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2280 TEXT(bv_)->DeleteLineForward(bv_);
2281 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2282 moveCursorUpdate(false);
2285 /* -------> Set mark off. */
2287 beforeChange(TEXT(bv_));
2288 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2289 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2290 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2293 /* -------> Set mark on. */
2295 beforeChange(TEXT(bv_));
2296 TEXT(bv_)->mark_set = 1;
2297 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2298 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2299 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2302 case LFUN_BACKSPACE:
2304 if (!TEXT(bv_)->selection) {
2305 if (owner_->getIntl()->getTrans().backspace()) {
2306 TEXT(bv_)->Backspace(bv_);
2307 TEXT(bv_)->sel_cursor =
2310 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2311 // It is possible to make it a lot faster still
2312 // just comment out the line below...
2318 owner_->showState();
2323 case LFUN_BACKSPACE_SKIP:
2325 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2327 LyXCursor cursor = TEXT(bv_)->cursor;
2329 if (!TEXT(bv_)->selection) {
2330 if (cursor.pos() == 0
2331 && !(cursor.par()->params.spaceTop()
2332 == VSpace (VSpace::NONE))) {
2333 TEXT(bv_)->SetParagraph
2335 cursor.par()->params.lineTop(),
2336 cursor.par()->params.lineBottom(),
2337 cursor.par()->params.pagebreakTop(),
2338 cursor.par()->params.pagebreakBottom(),
2339 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2340 cursor.par()->params.align(),
2341 cursor.par()->params.labelWidthString(), 0);
2343 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2345 TEXT(bv_)->Backspace(bv_);
2346 TEXT(bv_)->sel_cursor
2349 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2356 case LFUN_BREAKPARAGRAPH:
2358 beforeChange(TEXT(bv_));
2359 TEXT(bv_)->BreakParagraph(bv_, 0);
2361 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2362 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2364 owner_->showState();
2368 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2370 beforeChange(TEXT(bv_));
2371 TEXT(bv_)->BreakParagraph(bv_, 1);
2373 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2374 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2376 owner_->showState();
2380 case LFUN_BREAKPARAGRAPH_SKIP:
2382 // When at the beginning of a paragraph, remove
2383 // indentation and add a "defskip" at the top.
2384 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2386 LyXCursor cursor = TEXT(bv_)->cursor;
2388 beforeChange(TEXT(bv_));
2389 if (cursor.pos() == 0) {
2390 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2391 TEXT(bv_)->SetParagraph
2393 cursor.par()->params.lineTop(),
2394 cursor.par()->params.lineBottom(),
2395 cursor.par()->params.pagebreakTop(),
2396 cursor.par()->params.pagebreakBottom(),
2397 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2398 cursor.par()->params.align(),
2399 cursor.par()->params.labelWidthString(), 1);
2400 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2404 TEXT(bv_)->BreakParagraph(bv_, 0);
2405 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2409 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2410 TEXT(bv_)->sel_cursor = cursor;
2412 owner_->showState();
2416 case LFUN_PARAGRAPH_SPACING:
2418 LyXParagraph * par = TEXT(bv_)->cursor.par();
2419 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2420 float cur_value = 1.0;
2421 if (cur_spacing == Spacing::Other) {
2422 cur_value = par->params.spacing().getValue();
2425 istringstream istr(argument.c_str());
2429 Spacing::Space new_spacing = cur_spacing;
2430 float new_value = cur_value;
2432 lyxerr << "Missing argument to `paragraph-spacing'"
2434 } else if (tmp == "single") {
2435 new_spacing = Spacing::Single;
2436 } else if (tmp == "onehalf") {
2437 new_spacing = Spacing::Onehalf;
2438 } else if (tmp == "double") {
2439 new_spacing = Spacing::Double;
2440 } else if (tmp == "other") {
2441 new_spacing = Spacing::Other;
2444 lyxerr << "new_value = " << tmpval << endl;
2447 } else if (tmp == "default") {
2448 new_spacing = Spacing::Default;
2450 lyxerr << _("Unknown spacing argument: ")
2451 << argument << endl;
2453 if (cur_spacing != new_spacing || cur_value != new_value) {
2454 par->params.spacing(Spacing(new_spacing, new_value));
2455 TEXT(bv_)->RedoParagraph(bv_);
2457 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2463 beforeChange(TEXT(bv_));
2464 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2465 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2466 moveCursorUpdate(false);
2472 InsetCommandParams p;
2473 if (action == LFUN_HTMLURL)
2474 p.setCmdName("htmlurl");
2476 p.setCmdName("url");
2477 owner_->getDialogs()->createUrl( p.getAsString() );
2481 case LFUN_INSERT_URL:
2483 InsetCommandParams p;
2484 p.setFromString( argument );
2486 InsetUrl * inset = new InsetUrl( p );
2487 if (!bv_->insertInset(inset))
2490 bv_->updateInset( inset, true );
2494 case LFUN_INSET_TEXT:
2496 InsetText * new_inset = new InsetText;
2497 if (bv_->insertInset(new_inset))
2498 new_inset->Edit(bv_, 0, 0, 0);
2504 case LFUN_INSET_ERT:
2506 InsetERT * new_inset = new InsetERT;
2507 if (bv_->insertInset(new_inset))
2508 new_inset->Edit(bv_, 0, 0, 0);
2514 case LFUN_INSET_EXTERNAL:
2516 InsetExternal * new_inset = new InsetExternal;
2517 if (bv_->insertInset(new_inset))
2518 new_inset->Edit(bv_, 0, 0, 0);
2524 case LFUN_INSET_FOOTNOTE:
2526 InsetFoot * new_inset = new InsetFoot;
2527 if (bv_->insertInset(new_inset))
2528 new_inset->Edit(bv_, 0, 0, 0);
2534 case LFUN_INSET_MARGINAL:
2536 InsetMarginal * new_inset = new InsetMarginal;
2537 if (bv_->insertInset(new_inset))
2538 new_inset->Edit(bv_, 0, 0, 0);
2544 case LFUN_INSET_MINIPAGE:
2546 InsetMinipage * new_inset = new InsetMinipage;
2547 if (bv_->insertInset(new_inset))
2548 new_inset->Edit(bv_, 0, 0, 0);
2554 case LFUN_INSET_FLOAT:
2556 // check if the float type exist
2557 if (floatList.typeExist(argument)) {
2558 InsetFloat * new_inset = new InsetFloat(argument);
2559 if (bv_->insertInset(new_inset))
2560 new_inset->Edit(bv_, 0, 0, 0);
2564 lyxerr << "Non-existant float type: "
2565 << argument << endl;
2571 case LFUN_INSET_LIST:
2573 InsetList * new_inset = new InsetList;
2574 if (bv_->insertInset(new_inset))
2575 new_inset->Edit(bv_, 0, 0, 0);
2581 case LFUN_INSET_THEOREM:
2583 InsetTheorem * new_inset = new InsetTheorem;
2584 if (bv_->insertInset(new_inset))
2585 new_inset->Edit(bv_, 0, 0, 0);
2591 case LFUN_INSET_CAPTION:
2593 // Do we have a locking inset...
2594 if (bv_->theLockingInset()) {
2595 lyxerr << "Locking inset code: "
2596 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2597 InsetCaption * new_inset = new InsetCaption;
2598 new_inset->setOwner(bv_->theLockingInset());
2599 new_inset->SetAutoBreakRows(true);
2600 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2601 new_inset->SetFrameColor(0, LColor::footnoteframe);
2602 if (bv_->insertInset(new_inset))
2603 new_inset->Edit(bv_, 0, 0, 0);
2610 case LFUN_INSET_TABULAR:
2613 if (!argument.empty())
2614 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2615 InsetTabular * new_inset =
2616 new InsetTabular(*buffer_, r, c);
2618 TEXT(bv_)->real_current_font.isRightToLeft();
2619 if (!bv_->open_new_inset(new_inset, rtl))
2624 // --- lyxserver commands ----------------------------
2626 case LFUN_CHARATCURSOR:
2628 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2629 if (pos < TEXT(bv_)->cursor.par()->size())
2630 owner_->getLyXFunc()->setMessage(
2631 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2633 owner_->getLyXFunc()->setMessage("EOF");
2638 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2640 + tostr(TEXT(bv_)->cursor.y()));
2647 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2648 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2652 case LFUN_GETLAYOUT:
2653 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2658 LyXFont & font = TEXT(bv_)->current_font;
2659 if (font.shape() == LyXFont::ITALIC_SHAPE)
2660 owner_->getLyXFunc()->setMessage("E");
2661 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2662 owner_->getLyXFunc()->setMessage("N");
2664 owner_->getLyXFunc()->setMessage("0");
2671 LyXFont & font = TEXT(bv_)->current_font;
2672 if (font.latex() == LyXFont::ON)
2673 owner_->getLyXFunc()->setMessage("L");
2675 owner_->getLyXFunc()->setMessage("0");
2679 // --- accented characters ---------------------------
2682 case LFUN_CIRCUMFLEX:
2692 case LFUN_SPECIAL_CARON:
2695 case LFUN_HUNG_UMLAUT:
2698 owner_->getLyXFunc()->handleKeyFunc(action);
2701 // --- insert characters ----------------------------------------
2703 case LFUN_MATH_DELIM:
2704 case LFUN_INSERT_MATRIX:
2707 if (bv_->open_new_inset(new InsetFormula(false)))
2709 bv_->theLockingInset()
2710 ->LocalDispatch(bv_, action, argument);
2716 case LFUN_INSERT_MATH:
2718 math_insert_symbol(bv_, argument);
2722 case LFUN_MATH_DISPLAY:
2725 bv_->open_new_inset(new InsetFormula(true));
2729 case LFUN_MATH_MACRO:
2734 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2736 string const s1 = token(s, ' ', 1);
2737 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2738 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2744 case LFUN_MATH_MODE: // Open or create a math inset
2747 bv_->open_new_inset(new InsetFormula);
2748 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2752 case LFUN_CITATION_INSERT:
2754 InsetCommandParams p;
2755 p.setFromString( argument );
2757 InsetCitation * inset = new InsetCitation( p );
2758 if (!bv_->insertInset(inset))
2761 bv_->updateInset( inset, true );
2765 case LFUN_INSERT_BIBTEX:
2767 // ale970405+lasgoutt970425
2768 // The argument can be up to two tokens separated
2769 // by a space. The first one is the bibstyle.
2770 string const db = token(argument, ' ', 0);
2771 string bibstyle = token(argument, ' ', 1);
2772 if (bibstyle.empty())
2775 InsetCommandParams p( "BibTeX", db, bibstyle );
2776 InsetBibtex * inset = new InsetBibtex(p);
2778 if (bv_->insertInset(inset)) {
2779 if (argument.empty())
2780 inset->Edit(bv_, 0, 0, 0);
2786 // BibTeX data bases
2787 case LFUN_BIBDB_ADD:
2789 InsetBibtex * inset =
2790 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2792 inset->addDatabase(argument);
2797 case LFUN_BIBDB_DEL:
2799 InsetBibtex * inset =
2800 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2802 inset->delDatabase(argument);
2807 case LFUN_BIBTEX_STYLE:
2809 InsetBibtex * inset =
2810 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2812 inset->setOptions(argument);
2817 case LFUN_INDEX_CREATE:
2819 InsetCommandParams p( "index" );
2821 if (argument.empty()) {
2822 // Get the word immediately preceding the cursor
2823 LyXParagraph::size_type curpos =
2824 TEXT(bv_)->cursor.pos() - 1;
2828 curstring = TEXT(bv_)
2829 ->cursor.par()->GetWord(curpos);
2831 p.setContents( curstring );
2833 p.setContents( argument );
2836 owner_->getDialogs()->createIndex( p.getAsString() );
2840 case LFUN_INDEX_INSERT:
2842 InsetCommandParams p;
2843 p.setFromString(argument);
2844 InsetIndex * inset = new InsetIndex(p);
2846 if (!bv_->insertInset(inset))
2849 bv_->updateInset(inset, true);
2853 case LFUN_INDEX_INSERT_LAST:
2855 // Get word immediately preceding the cursor
2856 LyXParagraph::size_type curpos =
2857 TEXT(bv_)->cursor.pos() - 1;
2858 // Can't do that at the beginning of a paragraph
2859 if (curpos < 0) break;
2861 string const curstring(TEXT(bv_)
2862 ->cursor.par()->GetWord(curpos));
2864 InsetCommandParams p("index", curstring);
2865 InsetIndex * inset = new InsetIndex(p);
2867 if (!bv_->insertInset(inset))
2870 bv_->updateInset(inset, true);
2874 case LFUN_INDEX_PRINT:
2876 InsetCommandParams p("printindex");
2877 Inset * inset = new InsetPrintIndex(p);
2878 if (!bv_->insertInset(inset, "Standard", true))
2883 case LFUN_PARENTINSERT:
2885 lyxerr << "arg " << argument << endl;
2886 InsetCommandParams p( "lyxparent", argument );
2887 Inset * inset = new InsetParent(p, *buffer_);
2888 if (!bv_->insertInset(inset, "Standard", true))
2893 case LFUN_CHILD_INSERT:
2895 InsetCommandParams p;
2896 p.setFromString(argument);
2898 InsetInclude * inset = new InsetInclude(p, *buffer_);
2899 if (!bv_->insertInset(inset))
2902 bv_->updateInset(inset, true);
2906 case LFUN_INSERT_NOTE:
2910 case LFUN_SELFINSERT:
2912 LyXFont const old_font(TEXT(bv_)->real_current_font);
2913 for (string::size_type i = 0; i < argument.length(); ++i) {
2914 TEXT(bv_)->InsertChar(bv_, argument[i]);
2915 // This needs to be in the loop, or else we
2916 // won't break lines correctly. (Asger)
2918 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2920 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2921 moveCursorUpdate(false);
2923 // real_current_font.number can change so we need to
2924 // update the minibuffer
2925 if (old_font != TEXT(bv_)->real_current_font)
2926 owner_->showState();
2930 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2934 time_t now_time_t = time(NULL);
2935 now_tm = localtime(&now_time_t);
2936 setlocale(LC_TIME, "");
2938 if (!argument.empty())
2941 arg = lyxrc.date_insert_format;
2943 int const datetmp_len =
2944 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2945 for (int i = 0; i < datetmp_len; i++) {
2946 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2948 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2951 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2952 moveCursorUpdate(false);
2956 case LFUN_UNKNOWN_ACTION:
2959 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2963 if (buffer_->isReadonly()) {
2964 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
2967 if (!argument.empty()) {
2968 /* Automatically delete the currently selected
2969 * text and replace it with what is being
2970 * typed in now. Depends on lyxrc settings
2971 * "auto_region_delete", which defaults to
2974 if (lyxrc.auto_region_delete) {
2975 if (TEXT(bv_)->selection){
2976 TEXT(bv_)->CutSelection(bv_, false);
2978 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2982 beforeChange(TEXT(bv_));
2983 LyXFont const old_font(TEXT(bv_)->real_current_font);
2984 for (string::size_type i = 0;
2985 i < argument.length(); ++i) {
2986 if (greek_kb_flag) {
2987 if (!math_insert_greek(bv_,
2989 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2991 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2994 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2996 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2997 moveCursorUpdate(false);
2999 // real_current_font.number can change so we need to
3000 // update the minibuffer
3001 if (old_font != TEXT(bv_)->real_current_font)
3002 owner_->showState();
3004 // if we don't have an argument there was something
3005 // strange going on so we just tell this to someone!
3006 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));