12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
20 #include "minibuffer.h"
22 #include "bufferview_funcs.h"
23 #include "TextCache.h"
24 #include "bufferlist.h"
25 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "frontends/Dialogs.h"
30 #include "insets/insetbib.h"
31 #include "insets/insettext.h"
32 /// added for Dispatch functions
34 #include "frontends/FileDialog.h"
36 #include "FloatList.h"
37 #include "support/filetools.h"
38 #include "support/lyxfunctional.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetlatexaccent.h"
41 #include "insets/insettoc.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "mathed/formulamacro.h"
59 extern LyXTextClass::size_type current_layout;
60 extern int greek_kb_flag;
70 /* the selection possible is needed, that only motion events are
71 * used, where the bottom press event was on the drawing area too */
72 bool selection_possible = false;
74 extern BufferList bufferlist;
75 extern char ascii_type;
77 extern bool math_insert_greek(BufferView *, char);
78 extern void sigchldhandler(pid_t pid, int * status);
79 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
81 const unsigned int saved_positions_num = 20;
86 XSync(fl_get_display(), 0);
91 void SetXtermCursor(Window win)
94 static bool cursor_undefined = true;
95 if (cursor_undefined){
96 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
97 XFlush(fl_get_display());
98 cursor_undefined = false;
100 XDefineCursor(fl_get_display(), win, cursor);
101 XFlush(fl_get_display());
105 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
106 int xpos, int ypos, int width, int height)
107 : bv_(b), owner_(o), buffer_(0),
108 current_scrollbar_value(0), cursor_timeout(400),
109 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
112 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
113 workarea_.workAreaExpose
114 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
115 workarea_.workAreaEnter
116 .connect(slot(this, &BufferView::Pimpl::enterView));
117 workarea_.workAreaLeave
118 .connect(slot(this, &BufferView::Pimpl::leaveView));
119 workarea_.workAreaButtonPress
120 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
121 workarea_.workAreaButtonRelease
123 &BufferView::Pimpl::workAreaButtonRelease));
124 workarea_.workAreaMotionNotify
125 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
126 workarea_.workAreaDoubleClick
127 .connect(slot(this, &BufferView::Pimpl::doubleClick));
128 workarea_.workAreaTripleClick
129 .connect(slot(this, &BufferView::Pimpl::tripleClick));
130 workarea_.workAreaKeyPress
131 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
135 cursor_timeout.timeout.connect(slot(this,
136 &BufferView::Pimpl::cursorToggle));
137 //current_scrollbar_value = 0;
138 cursor_timeout.start();
139 workarea_.setFocus();
140 //using_xterm_cursor = false;
141 saved_positions.resize(saved_positions_num);
145 Painter & BufferView::Pimpl::painter()
147 return workarea_.getPainter();
151 void BufferView::Pimpl::buffer(Buffer * b)
153 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
157 buffer_->delUser(bv_);
159 // Put the old text into the TextCache, but
160 // only if the buffer is still loaded.
161 // Also set the owner of the test to 0
162 // bv_->text->owner(0);
163 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
164 if (lyxerr.debugging())
165 textcache.show(lyxerr, "BufferView::buffer");
170 // Set current buffer
173 if (bufferlist.getState() == BufferList::CLOSING) return;
176 // screen is always deleted when the buffer is changed.
181 // If we are closing the buffer, use the first buffer as current
183 buffer_ = bufferlist.first();
187 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
188 buffer_->addUser(bv_);
189 // If we don't have a text object for this, we make one
190 if (bv_->text == 0) {
191 resizeCurrentBuffer();
196 bv_->text->first = screen_->TopCursorVisible(bv_->text);
197 owner_->updateMenubar();
198 owner_->updateToolbar();
199 // Similarly, buffer-dependent dialogs should be updated or
200 // hidden. This should go here because some dialogs (eg ToC)
201 // require bv_->text.
202 owner_->getDialogs()->updateBufferDependent(true);
206 lyxerr[Debug::INFO] << " No Buffer!" << endl;
207 owner_->updateMenubar();
208 owner_->updateToolbar();
209 owner_->getDialogs()->hideBufferDependent();
213 // Also remove all remaining text's from the testcache.
214 // (there should not be any!) (if there is any it is a
216 if (lyxerr.debugging())
217 textcache.show(lyxerr, "buffer delete all");
220 // should update layoutchoice even if we don't have a buffer.
221 owner_->updateLayoutChoice();
222 owner_->getMiniBuffer()->Init();
223 owner_->updateWindowTitle();
227 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
229 workarea_.resize(xpos, ypos, width, height);
230 update(bv_->text, SELECT);
235 void BufferView::Pimpl::resize()
238 resizeCurrentBuffer();
242 void BufferView::Pimpl::redraw()
244 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
249 bool BufferView::Pimpl::fitCursor(LyXText * text)
251 Assert(screen_.get());
253 bool ret = screen_->FitCursor(text, bv_);
260 void BufferView::Pimpl::redoCurrentBuffer()
262 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
263 if (buffer_ && bv_->text) {
265 owner_->updateLayoutChoice();
270 int BufferView::Pimpl::resizeCurrentBuffer()
272 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
274 LyXParagraph * par = 0;
275 LyXParagraph * selstartpar = 0;
276 LyXParagraph * selendpar = 0;
277 UpdatableInset * the_locking_inset = 0;
279 LyXParagraph::size_type pos = 0;
280 LyXParagraph::size_type selstartpos = 0;
281 LyXParagraph::size_type selendpos = 0;
282 bool selection = false;
283 bool mark_set = false;
287 owner_->getMiniBuffer()->Set(_("Formatting document..."));
290 par = bv_->text->cursor.par();
291 pos = bv_->text->cursor.pos();
292 selstartpar = bv_->text->sel_start_cursor.par();
293 selstartpos = bv_->text->sel_start_cursor.pos();
294 selendpar = bv_->text->sel_end_cursor.par();
295 selendpos = bv_->text->sel_end_cursor.pos();
296 selection = bv_->text->selection;
297 mark_set = bv_->text->mark_set;
298 the_locking_inset = bv_->text->the_locking_inset;
300 bv_->text = new LyXText(bv_);
302 // See if we have a text in TextCache that fits
303 // the new buffer_ with the correct width.
304 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
306 if (lyxerr.debugging()) {
307 lyxerr << "Found a LyXText that fits:\n";
308 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
310 // Set the owner of the newly found text
311 // bv_->text->owner(bv_);
312 if (lyxerr.debugging())
313 textcache.show(lyxerr, "resizeCurrentBuffer");
315 bv_->text = new LyXText(bv_);
321 bv_->text->selection = true;
322 /* at this point just to avoid the Delete-Empty-Paragraph
323 * Mechanism when setting the cursor */
324 bv_->text->mark_set = mark_set;
326 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
327 bv_->text->sel_cursor = bv_->text->cursor;
328 bv_->text->SetCursor(bv_, selendpar, selendpos);
329 bv_->text->SetSelection(bv_);
330 bv_->text->SetCursor(bv_, par, pos);
332 bv_->text->SetCursor(bv_, par, pos);
333 bv_->text->sel_cursor = bv_->text->cursor;
334 bv_->text->selection = false;
336 // remake the inset locking
337 bv_->text->the_locking_inset = the_locking_inset;
339 bv_->text->first = screen_->TopCursorVisible(bv_->text);
340 buffer_->resizeInsets(bv_);
341 // this will scroll the screen such that the cursor becomes visible
344 owner_->getMiniBuffer()->Init();
348 /// get rid of the splash screen if it's not gone already
349 owner_->getDialogs()->destroySplash();
355 void BufferView::Pimpl::updateScreen()
357 // Regenerate the screen.
358 screen_.reset(new LyXScreen(workarea_));
360 //screen_ = new LyXScreen(workarea_);
364 void BufferView::Pimpl::updateScrollbar()
366 /* If the text is smaller than the working area, the scrollbar
367 * maximum must be the working area height. No scrolling will
371 workarea_.setScrollbar(0, 1.0);
375 static unsigned long max2 = 0;
376 static unsigned long height2 = 0;
378 unsigned long cbth = 0;
382 cbth = bv_->text->height;
383 cbsf = bv_->text->first;
386 // check if anything has changed.
388 height2 == workarea_.height() &&
389 current_scrollbar_value == cbsf)
392 height2 = workarea_.height();
393 current_scrollbar_value = cbsf;
395 if (cbth <= height2) { // text is smaller than screen
396 workarea_.setScrollbar(0, 1.0); // right?
400 long maximum_height = workarea_.height() * 3 / 4 + cbth;
404 double hfloat = workarea_.height();
405 double maxfloat = maximum_height;
407 float slider_size = 0.0;
408 int slider_value = value;
410 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
411 double const lineh = bv_->text->DefaultHeight();
412 workarea_.setScrollbarIncrements(lineh);
413 if (maxfloat > 0.0) {
414 if ((hfloat / maxfloat) * float(height2) < 3)
415 slider_size = 3.0/float(height2);
417 slider_size = hfloat / maxfloat;
419 slider_size = hfloat;
421 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
425 // Callback for scrollbar slider
426 void BufferView::Pimpl::scrollCB(double value)
428 if (!buffer_) return;
430 current_scrollbar_value = long(value);
431 if (current_scrollbar_value < 0)
432 current_scrollbar_value = 0;
437 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
439 if (!lyxrc.cursor_follows_scrollbar) {
444 LyXText * vbt = bv_->text;
446 int const height = vbt->DefaultHeight();
447 int const first = static_cast<int>((bv_->text->first + height));
448 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
450 if (vbt->cursor.y() < first)
451 vbt->SetCursorFromCoordinates(bv_, 0, first);
452 else if (vbt->cursor.y() > last)
453 vbt->SetCursorFromCoordinates(bv_, 0, last);
459 int BufferView::Pimpl::scrollUp(long time)
461 if (!buffer_) return 0;
462 if (!screen_.get()) return 0;
464 double value = workarea_.getScrollbarValue();
466 if (value == 0) return 0;
468 float add_value = (bv_->text->DefaultHeight()
469 + float(time) * float(time) * 0.125);
471 if (add_value > workarea_.height())
472 add_value = float(workarea_.height() -
473 bv_->text->DefaultHeight());
480 workarea_.setScrollbarValue(value);
487 int BufferView::Pimpl::scrollDown(long time)
489 if (!buffer_) return 0;
490 if (!screen_.get()) return 0;
492 double value = workarea_.getScrollbarValue();
493 pair<float, float> p = workarea_.getScrollbarBounds();
494 double max = p.second;
496 if (value == max) return 0;
498 float add_value = (bv_->text->DefaultHeight()
499 + float(time) * float(time) * 0.125);
501 if (add_value > workarea_.height())
502 add_value = float(workarea_.height() -
503 bv_->text->DefaultHeight());
510 workarea_.setScrollbarValue(value);
517 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
519 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
523 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
525 // Only use motion with button 1
526 if (!(state & Button1MotionMask))
529 if (!buffer_ || !screen_.get()) return;
531 // Check for inset locking
532 if (bv_->theLockingInset()) {
533 LyXCursor cursor = bv_->text->cursor;
534 LyXFont font = bv_->text->GetFont(bv_->buffer(),
535 cursor.par(), cursor.pos());
536 int width = bv_->theLockingInset()->width(bv_, font);
537 int inset_x = font.isVisibleRightToLeft()
538 ? cursor.x() - width : cursor.x();
539 int start_x = inset_x + bv_->theLockingInset()->scroll();
540 bv_->theLockingInset()->
541 InsetMotionNotify(bv_,
543 y - cursor.y() + bv_->text->first,
548 /* The test for not selection possible is needed, that only motion events are
549 * used, where the bottom press event was on the drawing area too */
550 if (!selection_possible)
553 screen_->HideCursor();
555 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
557 if (!bv_->text->selection)
558 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
560 bv_->text->SetSelection(bv_);
561 screen_->ToggleToggle(bv_->text, bv_);
562 fitCursor(bv_->text);
563 screen_->ShowCursor(bv_->text, bv_);
567 // Single-click on work area
568 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
574 if (!buffer_ || !screen_.get()) return;
576 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
578 // ok ok, this is a hack.
579 if (button == 4 || button == 5) {
582 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
585 scrollDown(lyxrc.wheel_jump);
590 if (bv_->theLockingInset()) {
591 // We are in inset locking mode
593 /* Check whether the inset was hit. If not reset mode,
594 otherwise give the event to the inset */
595 if (inset_hit == bv_->theLockingInset()) {
596 bv_->theLockingInset()->
597 InsetButtonPress(bv_,
602 bv_->unlockInset(bv_->theLockingInset());
607 selection_possible = true;
608 screen_->HideCursor();
610 int const screen_first = bv_->text->first;
612 // Middle button press pastes if we have a selection
613 bool paste_internally = false;
615 && bv_->text->selection) {
616 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
617 paste_internally = true;
620 // Clear the selection
621 screen_->ToggleSelection(bv_->text, bv_);
622 bv_->text->ClearSelection(bv_);
623 bv_->text->FullRebreak(bv_);
624 screen_->Update(bv_->text, bv_);
627 // Single left click in math inset?
628 if ((inset_hit != 0) &&
629 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
630 // Highly editable inset, like math
631 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
632 selection_possible = false;
633 owner_->updateLayoutChoice();
634 owner_->getMiniBuffer()->Set(inset->EditMessage());
635 inset->InsetButtonPress(bv_, xpos, ypos, button);
636 inset->Edit(bv_, xpos, ypos, button);
640 // Right click on a footnote flag opens float menu
642 selection_possible = false;
646 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
647 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
648 bv_->text->FinishUndo();
649 bv_->text->sel_cursor = bv_->text->cursor;
650 bv_->text->cursor.x_fix(bv_->text->cursor.x());
652 owner_->updateLayoutChoice();
653 if (fitCursor(bv_->text)) {
654 selection_possible = false;
657 // Insert primary selection with middle mouse
658 // if there is a local selection in the current buffer,
661 if (paste_internally)
662 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
664 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
666 selection_possible = false;
672 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
678 LyXText * text = bv_->getLyXText();
680 if (text->bv_owner && bv_->theLockingInset())
683 if (screen_.get() && button == 1) {
684 if (text->bv_owner) {
685 screen_->HideCursor();
686 screen_->ToggleSelection(text, bv_);
687 text->SelectWord(bv_);
688 screen_->ToggleSelection(text, bv_, false);
690 text->SelectWord(bv_);
692 /* This will fit the cursor on the screen
694 update(text, BufferView::SELECT|BufferView::FITCUR);
699 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
705 LyXText * text = bv_->getLyXText();
707 if (text->bv_owner && bv_->theLockingInset())
710 if (screen_.get() && (button == 1)) {
711 screen_->HideCursor();
712 screen_->ToggleSelection(text, bv_);
713 text->CursorHome(bv_);
714 text->sel_cursor = text->cursor;
715 text->CursorEnd(bv_);
716 text->SetSelection(bv_);
717 screen_->ToggleSelection(text, bv_, false);
718 /* This will fit the cursor on the screen
720 update(text, BufferView::SELECT|BufferView::FITCUR);
725 void BufferView::Pimpl::enterView()
727 if (active() && available()) {
728 SetXtermCursor(workarea_.getWin());
729 using_xterm_cursor = true;
734 void BufferView::Pimpl::leaveView()
736 if (using_xterm_cursor) {
737 XUndefineCursor(fl_get_display(), workarea_.getWin());
738 using_xterm_cursor = false;
743 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
746 if (!buffer_ || !screen_.get()) return;
748 // If we hit an inset, we have the inset coordinates in these
749 // and inset_hit points to the inset. If we do not hit an
750 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
751 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
753 if (bv_->theLockingInset()) {
754 // We are in inset locking mode.
756 /* LyX does a kind of work-area grabbing for insets.
757 Only a ButtonPress Event outside the inset will
758 force a InsetUnlock. */
759 bv_->theLockingInset()->
760 InsetButtonRelease(bv_, x, y, button);
764 selection_possible = false;
772 // Did we hit an editable inset?
774 // Inset like error, notes and figures
775 selection_possible = false;
777 // CHECK fix this proper in 0.13
779 // Following a ref shouldn't issue
780 // a push on the undo-stack
781 // anylonger, now that we have
782 // keybindings for following
783 // references and returning from
784 // references. IMHO though, it
785 // should be the inset's own business
786 // to push or not push on the undo
787 // stack. They don't *have* to
788 // alter the document...
790 // ...or maybe the SetCursorParUndo()
791 // below isn't necessary at all anylonger?
792 if (inset_hit->LyxCode() == Inset::REF_CODE) {
793 bv_->text->SetCursorParUndo(bv_->buffer());
796 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
797 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
798 // Highly editable inset, like math
799 UpdatableInset *inset = (UpdatableInset *)inset_hit;
800 inset->InsetButtonRelease(bv_, x, y, button);
802 inset_hit->InsetButtonRelease(bv_, x, y, button);
803 inset_hit->Edit(bv_, x, y, button);
809 // check whether we want to open a float
813 if (bv_->text->cursor.pos() <
814 bv_->text->cursor.par()->Last()) {
815 c = bv_->text->cursor.par()->
816 GetChar(bv_->text->cursor.pos());
818 if(!bv_->text->selection)
819 if (c == LyXParagraph::META_FOOTNOTE
820 || c == LyXParagraph::META_MARGIN
821 || c == LyXParagraph::META_FIG
822 || c == LyXParagraph::META_TAB
823 || c == LyXParagraph::META_WIDE_FIG
824 || c == LyXParagraph::META_WIDE_TAB
825 || c == LyXParagraph::META_ALGORITHM){
828 if (bv_->text->cursor.pos() - 1 >= 0) {
829 c = bv_->text->cursor.par()->
830 GetChar(bv_->text->cursor.pos() - 1);
831 if (c == LyXParagraph::META_FOOTNOTE
832 || c == LyXParagraph::META_MARGIN
833 || c == LyXParagraph::META_FIG
834 || c == LyXParagraph::META_TAB
835 || c == LyXParagraph::META_WIDE_FIG
836 || c == LyXParagraph::META_WIDE_TAB
837 || c == LyXParagraph::META_ALGORITHM){
838 // We are one step too far to the right
839 bv_->text->CursorLeft(bv_);
845 selection_possible = false;
849 // Do we want to close a float? (click on the float-label)
850 if (bv_->text->cursor.row()->par()->footnoteflag ==
851 LyXParagraph::OPEN_FOOTNOTE
852 && bv_->text->cursor.row()->previous() &&
853 bv_->text->cursor.row()->previous()->par()->
854 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
855 LyXFont font(LyXFont::ALL_SANE);
856 font.setSize(LyXFont::SIZE_FOOTNOTE);
858 int box_x = 20; // LYX_PAPER_MARGIN;
859 box_x += lyxfont::width(" wide-tab ", font);
861 unsigned int screen_first = bv_->text->first;
864 && y + screen_first > bv_->text->cursor.y() -
865 bv_->text->cursor.row()->baseline()
866 && y + screen_first < bv_->text->cursor.y() -
867 bv_->text->cursor.row()->baseline()
868 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
870 selection_possible = false;
875 // check whether we want to open a float
879 if (bv_->text->cursor.pos() <
880 bv_->text->cursor.par()->size()) {
881 c = bv_->text->cursor.par()->
882 GetChar(bv_->text->cursor.pos());
884 if (bv_->text->cursor.pos() - 1 >= 0) {
885 c = bv_->text->cursor.par()->
886 GetChar(bv_->text->cursor.pos() - 1);
889 selection_possible = false;
894 // Maybe we want to edit a bibitem ale970302
895 if (bv_->text->cursor.par()->bibkey && x < 20 +
896 bibitemMaxWidth(bv_, textclasslist.
898 params.textclass).defaultfont())) {
899 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
907 * Returns an inset if inset was hit. 0 otherwise.
908 * If hit, the coordinates are changed relative to the inset.
909 * Otherwise coordinates are not changed, and false is returned.
911 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
912 unsigned int /* button */)
917 int y_tmp = y + text->first;
920 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
923 if (cursor.pos() < cursor.par()->Last()
925 if (cursor.pos() < cursor.par()->size()
927 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
928 && cursor.par()->GetInset(cursor.pos())
929 && cursor.par()->GetInset(cursor.pos())->Editable()) {
931 // Check whether the inset really was hit
932 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
933 LyXFont font = text->GetFont(bv_->buffer(),
934 cursor.par(), cursor.pos());
935 int width = tmpinset->width(bv_, font);
936 int inset_x = font.isVisibleRightToLeft()
937 ? cursor.x() - width : cursor.x();
938 int start_x = inset_x + tmpinset->scroll();
939 int end_x = inset_x + width;
941 if (x > start_x && x < end_x
942 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
943 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
944 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
946 // The origin of an inset is on the baseline
947 y = y_tmp - (text->cursor.y());
952 if ((cursor.pos() - 1 >= 0) &&
953 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
954 (cursor.par()->GetInset(cursor.pos() - 1)) &&
955 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
956 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
957 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
959 int width = tmpinset->width(bv_, font);
960 int inset_x = font.isVisibleRightToLeft()
961 ? cursor.x() : cursor.x() - width;
962 int start_x = inset_x + tmpinset->scroll();
963 int end_x = inset_x + width;
965 if (x > start_x && x < end_x
966 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
967 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
969 if (move_cursor && (tmpinset != bv_->theLockingInset()))
971 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
973 // The origin of an inset is on the baseline
974 y = y_tmp - (text->cursor.y());
982 void BufferView::Pimpl::workAreaExpose()
984 static int work_area_width = 0;
985 static unsigned int work_area_height = 0;
987 bool widthChange = workarea_.workWidth() != work_area_width;
988 bool heightChange = workarea_.height() != work_area_height;
990 // update from work area
991 work_area_width = workarea_.workWidth();
992 work_area_height = workarea_.height();
995 // All buffers need a resize
998 // Remove all texts from the textcache
999 // This is not _really_ what we want to do. What
1000 // we really want to do is to delete in textcache
1001 // that does not have a BufferView with matching
1002 // width, but as long as we have only one BufferView
1003 // deleting all gives the same result.
1004 if (lyxerr.debugging())
1005 textcache.show(lyxerr, "Expose delete all");
1007 } else if (heightChange) {
1008 // Rebuild image of current screen
1010 // fitCursor() ensures we don't jump back
1011 // to the start of the document on vertical
1013 fitCursor(bv_->text);
1015 // The main window size has changed, repaint most stuff
1017 // ...including the minibuffer
1018 owner_->getMiniBuffer()->Init();
1020 } else if (screen_.get())
1021 screen_->Redraw(bv_->text, bv_);
1023 // Grey box when we don't have a buffer
1024 workarea_.greyOut();
1027 // always make sure that the scrollbar is sane.
1029 owner_->updateLayoutChoice();
1034 void BufferView::Pimpl::update()
1036 if (screen_.get()) screen_->Update(bv_->text, bv_);
1039 // Values used when calling update:
1041 // -2 - update, move sel_cursor if selection, fitcursor
1042 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1043 // 0 - update, move sel_cursor if selection, fitcursor
1044 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1045 // 3 - update, move sel_cursor if selection
1048 // a simple redraw of the parts that need refresh
1050 // move sel_cursor if selection -
1051 // the text's sel_cursor is moved if there is selection is progress
1054 // fitCursor() is called and the scrollbar updated
1057 // the buffer is marked dirty.
1066 // UPDATE_ONLY = UPDATE;
1067 // UPDATE_SELECT = UPDATE | SELECT;
1068 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1069 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1071 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1072 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1073 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1074 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1075 // update(3) -> update(1) -> update(1) -> update(SELECT)
1077 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1079 owner_->updateLayoutChoice();
1081 if (!text->selection && (f & SELECT)) {
1082 text->sel_cursor = text->cursor;
1085 text->FullRebreak(bv_);
1087 if (text->inset_owner) {
1088 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1089 bv_->updateInset(text->inset_owner, true);
1098 if (buffer_->isLyxClean()) {
1099 buffer_->markDirty();
1100 owner_->getMiniBuffer()->setTimer(4);
1102 buffer_->markDirty();
1108 // Callback for cursor timer
1109 void BufferView::Pimpl::cursorToggle()
1111 // Quite a nice place for asyncron Inset updating, isn't it?
1112 // Actually no! This is run even if no buffer exist... so (Lgb)
1114 cursor_timeout.restart();
1119 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1120 if (pid == -1) // error find out what is wrong
1121 ; // ignore it for now.
1123 sigchldhandler(pid, &status);
1125 updatelist.update(bv_);
1127 if (!screen_.get()) {
1128 cursor_timeout.restart();
1132 if (!bv_->theLockingInset()) {
1133 screen_->CursorToggle(bv_->text, bv_);
1135 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1138 cursor_timeout.restart();
1142 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1144 if (!text->cursor.row()->previous())
1147 int y = text->first;
1148 if (text->inset_owner)
1149 y += bv_->text->first;
1150 Row * cursorrow = text->cursor.row();
1151 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1152 bv_->text->FinishUndo();
1153 // This is to allow jumping over large insets
1154 if ((cursorrow == text->cursor.row()))
1155 text->CursorUp(bv_);
1157 if (text->inset_owner ||
1158 text->cursor.row()->height() < workarea_.height())
1159 screen_->Draw(bv_->text, bv_,
1161 - text->cursor.row()->baseline()
1162 + text->cursor.row()->height()
1163 - workarea_.height() + 1 );
1168 void BufferView::Pimpl::cursorNext(LyXText * text)
1170 if (!text->cursor.row()->next())
1173 int y = text->first + workarea_.height();
1174 // if (text->inset_owner)
1175 // y += bv_->text->first;
1176 text->GetRowNearY(y);
1178 Row * cursorrow = text->cursor.row();
1179 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1180 bv_->text->FinishUndo();
1181 // This is to allow jumping over large insets
1182 if ((cursorrow == bv_->text->cursor.row()))
1183 text->CursorDown(bv_);
1185 if (text->inset_owner ||
1186 text->cursor.row()->height() < workarea_.height())
1187 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1188 text->cursor.row()->baseline());
1193 bool BufferView::Pimpl::available() const
1195 if (buffer_ && bv_->text) return true;
1200 void BufferView::Pimpl::beforeChange(LyXText * text)
1203 text->ClearSelection(bv_);
1207 void BufferView::Pimpl::savePosition(unsigned int i)
1209 if (i >= saved_positions_num)
1211 saved_positions[i] = Position(buffer_->fileName(),
1212 bv_->text->cursor.par()->id(),
1213 bv_->text->cursor.pos());
1215 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1219 void BufferView::Pimpl::restorePosition(unsigned int i)
1221 if (i >= saved_positions_num)
1224 string fname = saved_positions[i].filename;
1226 beforeChange(bv_->text);
1228 if (fname != buffer_->fileName()) {
1229 Buffer * b = bufferlist.exists(fname) ?
1230 bufferlist.getBuffer(fname) :
1231 bufferlist.loadLyXFile(fname); // don't ask, just load it
1232 if (b != 0 ) buffer(b);
1235 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1240 bv_->text->SetCursor(bv_, par,
1241 min(par->Last(), saved_positions[i].par_pos));
1243 bv_->text->SetCursor(bv_, par,
1244 min(par->size(), saved_positions[i].par_pos));
1246 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1248 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1252 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1254 if (i >= saved_positions_num)
1257 return !saved_positions[i].filename.empty();
1261 void BufferView::Pimpl::setState()
1263 if (!lyxrc.rtl_support)
1266 LyXText * text = bv_->getLyXText();
1267 if (text->real_current_font.isRightToLeft() &&
1268 text->real_current_font.latex() != LyXFont::ON) {
1269 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1270 owner_->getIntl()->KeyMapSec();
1272 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1273 owner_->getIntl()->KeyMapPrim();
1278 void BufferView::Pimpl::insetSleep()
1280 if (bv_->theLockingInset() && !bv_->inset_slept) {
1281 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1282 bv_->theLockingInset()->InsetUnlock(bv_);
1283 bv_->inset_slept = true;
1288 void BufferView::Pimpl::insetWakeup()
1290 if (bv_->theLockingInset() && bv_->inset_slept) {
1291 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1292 bv_->inset_slept = false;
1297 void BufferView::Pimpl::insetUnlock()
1299 if (bv_->theLockingInset()) {
1300 if (!bv_->inset_slept)
1301 bv_->theLockingInset()->InsetUnlock(bv_);
1302 bv_->theLockingInset(0);
1303 bv_->text->FinishUndo();
1304 bv_->inset_slept = false;
1309 bool BufferView::Pimpl::focus() const
1311 return workarea_.hasFocus();
1315 void BufferView::Pimpl::focus(bool f)
1317 if (f) workarea_.setFocus();
1321 bool BufferView::Pimpl::active() const
1323 return workarea_.active();
1327 bool BufferView::Pimpl::belowMouse() const
1329 return workarea_.belowMouse();
1333 void BufferView::Pimpl::showCursor()
1336 screen_->ShowCursor(bv_->text, bv_);
1340 void BufferView::Pimpl::hideCursor()
1343 screen_->HideCursor();
1347 void BufferView::Pimpl::toggleSelection(bool b)
1350 screen_->ToggleSelection(bv_->text, bv_, b);
1354 void BufferView::Pimpl::toggleToggle()
1357 screen_->ToggleToggle(bv_->text, bv_);
1361 void BufferView::Pimpl::center()
1363 beforeChange(bv_->text);
1364 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1365 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1367 screen_->Draw(bv_->text, bv_, 0);
1369 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1374 void BufferView::Pimpl::pasteClipboard(bool asPara)
1376 if (!buffer_) return;
1378 screen_->HideCursor();
1379 beforeChange(bv_->text);
1381 string const clip(workarea_.getClipboard());
1383 if (clip.empty()) return;
1386 bv_->text->InsertStringB(bv_, clip);
1388 bv_->text->InsertStringA(bv_, clip);
1390 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1394 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1396 workarea_.putClipboard(stuff);
1401 * Dispatch functions for actions which can be valid for BufferView->text
1402 * and/or InsetText->text!!!
1404 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1407 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1409 if (selecting || TEXT(bv_)->mark_set) {
1410 TEXT(bv_)->SetSelection(bv_);
1411 if (TEXT(bv_)->bv_owner)
1412 bv_->toggleToggle();
1414 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1417 /* ---> Everytime the cursor is moved, show the current font state. */
1418 // should this too me moved out of this func?
1419 //owner->showState();
1424 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1426 LyXCursor cursor = TEXT(bv_)->cursor;
1427 Buffer::inset_iterator it =
1428 find_if(Buffer::inset_iterator(
1429 cursor.par(), cursor.pos()),
1430 buffer_->inset_iterator_end(),
1431 compare_memfun(&Inset::LyxCode, code)
1433 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1437 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1439 string filename = filen;
1441 if (filename.empty()) {
1442 // Launch a file browser
1443 string initpath = lyxrc.document_path;
1446 string const trypath = owner_->buffer()->filepath;
1447 // If directory is writeable, use this as default.
1448 if (IsDirWriteable(trypath) == 1)
1452 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1454 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1455 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1457 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1459 if (result.first == FileDialog::Later)
1462 filename = result.second;
1464 // check selected filename
1465 if (filename.empty()) {
1466 owner_->getMiniBuffer()->Set(_("Canceled."));
1471 // get absolute path of file and make sure the filename ends
1473 filename = MakeAbsPath(filename);
1474 if (!IsLyXFilename(filename))
1478 owner_->getMiniBuffer()->Set(_("Inserting document"),
1479 MakeDisplayPath(filename), "...");
1480 bool const res = bv_->insertLyXFile(filename);
1482 owner_->getMiniBuffer()->Set(_("Document"),
1483 MakeDisplayPath(filename),
1486 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1487 MakeDisplayPath(filename));
1492 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1495 // --- Misc -------------------------------------------
1498 TEXT(bv_)->toggleAppendix(bv_);
1499 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1503 case LFUN_TOC_INSERT:
1504 case LFUN_LOA_INSERT:
1505 case LFUN_LOF_INSERT:
1506 case LFUN_LOT_INSERT:
1508 InsetCommandParams p;
1510 if (action == LFUN_TOC_INSERT )
1511 p.setCmdName( "tableofcontents" );
1512 else if (action == LFUN_LOA_INSERT )
1513 p.setCmdName( "listofalgorithms" );
1514 else if (action == LFUN_LOF_INSERT )
1515 p.setCmdName( "listoffigures" );
1517 p.setCmdName( "listoftables" );
1519 Inset * inset = new InsetTOC( p );
1520 if (!bv_->insertInset( inset, "Standard", true ) )
1525 case LFUN_TABULAR_FEATURE:
1526 case LFUN_SCROLL_INSET:
1527 // this is not handled here as this funktion is only aktive
1528 // if we have a locking_inset and that one is (or contains)
1532 case LFUN_INSET_GRAPHICS:
1534 Inset * new_inset = new InsetGraphics;
1535 if (!bv_->insertInset(new_inset)) {
1538 // this is need because you don't use a inset->Edit()
1539 bv_->updateInset(new_inset, true);
1540 new_inset->Edit(bv_, 0, 0, 0);
1550 case LFUN_PASTESELECTION:
1552 bool asPara = false;
1553 if (argument == "paragraph") asPara = true;
1554 pasteClipboard(asPara);
1566 case LFUN_LAYOUT_COPY:
1567 bv_->copyEnvironment();
1570 case LFUN_LAYOUT_PASTE:
1571 bv_->pasteEnvironment();
1575 case LFUN_GOTOERROR:
1576 bv_->gotoInset(Inset::ERROR_CODE, false);
1580 bv_->gotoInset(Inset::IGNORE_CODE, false);
1583 case LFUN_REFERENCE_GOTO:
1585 vector<Inset::Code> tmp;
1586 tmp.push_back(Inset::LABEL_CODE);
1587 tmp.push_back(Inset::REF_CODE);
1588 bv_->gotoInset(tmp, true);
1592 case LFUN_HYPHENATION:
1593 bv_->hyphenationPoint();
1600 case LFUN_END_OF_SENTENCE:
1601 bv_->endOfSentenceDot();
1604 case LFUN_MENU_SEPARATOR:
1605 bv_->menuSeparator();
1613 changeDepth(bv_, TEXT(bv_), 0);
1616 case LFUN_DEPTH_MIN:
1617 changeDepth(bv_, TEXT(bv_), -1);
1620 case LFUN_DEPTH_PLUS:
1621 changeDepth(bv_, TEXT(bv_), 1);
1625 owner_->getDialogs()->setUserFreeFont();
1631 owner_->showState();
1634 case LFUN_FILE_INSERT:
1636 MenuInsertLyXFile(argument);
1640 case LFUN_FILE_INSERT_ASCII_PARA:
1641 InsertAsciiFile(bv_, argument, true);
1644 case LFUN_FILE_INSERT_ASCII:
1645 InsertAsciiFile(bv_, argument, false);
1650 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1651 << argument << endl;
1653 // Derive layout number from given argument (string)
1654 // and current buffer's textclass (number). */
1655 LyXTextClassList::ClassList::size_type tclass =
1656 buffer_->params.textclass;
1657 pair <bool, LyXTextClass::size_type> layout =
1658 textclasslist.NumberOfLayout(tclass, argument);
1660 // If the entry is obsolete, use the new one instead.
1662 string obs = textclasslist.Style(tclass,layout.second)
1666 textclasslist.NumberOfLayout(tclass, obs);
1669 // see if we found the layout number:
1670 if (!layout.first) {
1671 owner_->getLyXFunc()->setErrorMessage(
1672 string(N_("Layout ")) + argument +
1677 if (current_layout != layout.second) {
1679 current_layout = layout.second;
1681 BufferView::SELECT|BufferView::FITCUR);
1682 TEXT(bv_)->SetLayout(bv_, layout.second);
1683 owner_->setLayout(layout.second);
1685 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1692 Lang(bv_, argument);
1694 owner_->showState();
1699 owner_->showState();
1704 owner_->showState();
1709 owner_->showState();
1714 owner_->showState();
1719 owner_->showState();
1724 owner_->showState();
1729 owner_->showState();
1732 case LFUN_UNDERLINE:
1734 owner_->showState();
1737 case LFUN_FONT_SIZE:
1738 FontSize(bv_, argument);
1739 owner_->showState();
1742 case LFUN_FONT_STATE:
1743 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1746 case LFUN_UPCASE_WORD:
1747 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1748 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
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_LOWCASE_WORD:
1755 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1756 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1757 if (TEXT(bv_)->inset_owner)
1758 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1759 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1762 case LFUN_CAPITALIZE_WORD:
1763 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1764 TEXT(bv_)->ChangeWordCase(bv_,
1765 LyXText::text_capitalization);
1766 if (TEXT(bv_)->inset_owner)
1767 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1768 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1771 case LFUN_INSERT_LABEL:
1772 MenuInsertLabel(bv_, argument);
1775 case LFUN_REF_INSERT:
1776 if (argument.empty()) {
1777 InsetCommandParams p("ref");
1778 owner_->getDialogs()->createRef(p.getAsString());
1780 InsetCommandParams p;
1781 p.setFromString(argument);
1783 InsetRef * inset = new InsetRef(p, *buffer_);
1784 if (!bv_->insertInset(inset))
1787 bv_->updateInset(inset, true);
1791 case LFUN_BOOKMARK_SAVE:
1792 savePosition(strToUnsignedInt(argument));
1795 case LFUN_BOOKMARK_GOTO:
1796 restorePosition(strToUnsignedInt(argument));
1801 string label(argument);
1802 if (label.empty()) {
1804 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1806 label = inset->getContents();
1811 if (!label.empty()) {
1812 //bv_->savePosition(0);
1813 if (!bv_->gotoLabel(label))
1814 WriteAlert(_("Error"),
1815 _("Couldn't find this label"),
1816 _("in current document."));
1821 // --- Cursor Movements -----------------------------
1824 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1825 if (!TEXT(bv_)->mark_set)
1826 beforeChange(TEXT(bv_));
1827 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1829 TEXT(bv_)->CursorLeft(bv_, false);
1831 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1833 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
1835 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1836 == LyXParagraph::META_INSET
1837 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1838 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1839 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1840 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1844 TEXT(bv_)->GetFont(buffer_,
1845 TEXT(bv_)->cursor.par(),
1846 TEXT(bv_)->cursor.pos());
1847 y = tmpinset->descent(bv_,font);
1849 tmpinset->Edit(bv_, 0, y, 0);
1853 TEXT(bv_)->CursorRight(bv_, false);
1854 TEXT(bv_)->FinishUndo();
1855 moveCursorUpdate(false);
1856 owner_->showState();
1862 // This is soooo ugly. Isn`t it possible to make
1863 // it simpler? (Lgb)
1864 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1865 if (!TEXT(bv_)->mark_set)
1866 beforeChange(TEXT(bv_));
1867 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1868 LyXCursor cur = TEXT(bv_)->cursor;
1870 TEXT(bv_)->CursorLeft(bv_, false);
1871 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1873 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1875 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
1877 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1878 LyXParagraph::META_INSET) &&
1879 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1880 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1881 == Inset::HIGHLY_EDITABLE))
1883 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1884 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1885 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1886 TEXT(bv_)->cursor.par(),
1887 TEXT(bv_)->cursor.pos());
1889 : tmpinset->descent(bv_,font);
1892 tmpinset->width(bv_,font),
1897 TEXT(bv_)->CursorRight(bv_, false);
1899 TEXT(bv_)->FinishUndo();
1900 moveCursorUpdate(false);
1901 owner_->showState();
1906 if (!TEXT(bv_)->mark_set)
1907 beforeChange(TEXT(bv_));
1908 update(TEXT(bv_), BufferView::UPDATE);
1909 TEXT(bv_)->CursorUp(bv_);
1910 TEXT(bv_)->FinishUndo();
1911 moveCursorUpdate(false);
1912 owner_->showState();
1916 if (!TEXT(bv_)->mark_set)
1917 beforeChange(TEXT(bv_));
1918 update(TEXT(bv_), BufferView::UPDATE);
1919 TEXT(bv_)->CursorDown(bv_);
1920 TEXT(bv_)->FinishUndo();
1921 moveCursorUpdate(false);
1922 owner_->showState();
1925 case LFUN_UP_PARAGRAPH:
1926 if (!TEXT(bv_)->mark_set)
1927 beforeChange(TEXT(bv_));
1928 update(TEXT(bv_), BufferView::UPDATE);
1929 TEXT(bv_)->CursorUpParagraph(bv_);
1930 TEXT(bv_)->FinishUndo();
1931 moveCursorUpdate(false);
1932 owner_->showState();
1935 case LFUN_DOWN_PARAGRAPH:
1936 if (!TEXT(bv_)->mark_set)
1937 beforeChange(TEXT(bv_));
1938 update(TEXT(bv_), BufferView::UPDATE);
1939 TEXT(bv_)->CursorDownParagraph(bv_);
1940 TEXT(bv_)->FinishUndo();
1941 moveCursorUpdate(false);
1942 owner_->showState();
1946 if (!TEXT(bv_)->mark_set)
1947 beforeChange(TEXT(bv_));
1948 update(TEXT(bv_), BufferView::UPDATE);
1949 cursorPrevious(TEXT(bv_));
1950 TEXT(bv_)->FinishUndo();
1951 moveCursorUpdate(false);
1952 owner_->showState();
1956 if (!TEXT(bv_)->mark_set)
1957 beforeChange(TEXT(bv_));
1958 update(TEXT(bv_), BufferView::UPDATE);
1959 cursorNext(TEXT(bv_));
1960 TEXT(bv_)->FinishUndo();
1961 moveCursorUpdate(false);
1962 owner_->showState();
1966 if (!TEXT(bv_)->mark_set)
1967 beforeChange(TEXT(bv_));
1968 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1969 TEXT(bv_)->CursorHome(bv_);
1970 TEXT(bv_)->FinishUndo();
1971 moveCursorUpdate(false);
1972 owner_->showState();
1976 if (!TEXT(bv_)->mark_set)
1977 beforeChange(TEXT(bv_));
1979 BufferView::SELECT|BufferView::FITCUR);
1980 TEXT(bv_)->CursorEnd(bv_);
1981 TEXT(bv_)->FinishUndo();
1982 moveCursorUpdate(false);
1983 owner_->showState();
1986 case LFUN_SHIFT_TAB:
1988 if (!TEXT(bv_)->mark_set)
1989 beforeChange(TEXT(bv_));
1991 BufferView::SELECT|BufferView::FITCUR);
1992 TEXT(bv_)->CursorTab(bv_);
1993 TEXT(bv_)->FinishUndo();
1994 moveCursorUpdate(false);
1995 owner_->showState();
1998 case LFUN_WORDRIGHT:
1999 if (!TEXT(bv_)->mark_set)
2000 beforeChange(TEXT(bv_));
2001 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2002 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2003 TEXT(bv_)->CursorLeftOneWord(bv_);
2005 TEXT(bv_)->CursorRightOneWord(bv_);
2006 TEXT(bv_)->FinishUndo();
2007 moveCursorUpdate(false);
2008 owner_->showState();
2012 if (!TEXT(bv_)->mark_set)
2013 beforeChange(TEXT(bv_));
2014 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2015 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2016 TEXT(bv_)->CursorRightOneWord(bv_);
2018 TEXT(bv_)->CursorLeftOneWord(bv_);
2019 TEXT(bv_)->FinishUndo();
2020 moveCursorUpdate(false);
2021 owner_->showState();
2024 case LFUN_BEGINNINGBUF:
2025 if (!TEXT(bv_)->mark_set)
2026 beforeChange(TEXT(bv_));
2028 BufferView::SELECT|BufferView::FITCUR);
2029 TEXT(bv_)->CursorTop(bv_);
2030 TEXT(bv_)->FinishUndo();
2031 moveCursorUpdate(false);
2032 owner_->showState();
2036 if (!TEXT(bv_)->mark_set)
2037 beforeChange(TEXT(bv_));
2039 BufferView::SELECT|BufferView::FITCUR);
2040 TEXT(bv_)->CursorBottom(bv_);
2041 TEXT(bv_)->FinishUndo();
2042 moveCursorUpdate(false);
2043 owner_->showState();
2047 /* cursor selection ---------------------------- */
2050 BufferView::SELECT|BufferView::FITCUR);
2051 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2052 TEXT(bv_)->CursorLeft(bv_);
2054 TEXT(bv_)->CursorRight(bv_);
2055 TEXT(bv_)->FinishUndo();
2056 moveCursorUpdate(true);
2057 owner_->showState();
2062 BufferView::SELECT|BufferView::FITCUR);
2063 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2064 TEXT(bv_)->CursorRight(bv_);
2066 TEXT(bv_)->CursorLeft(bv_);
2067 TEXT(bv_)->FinishUndo();
2068 moveCursorUpdate(true);
2069 owner_->showState();
2074 BufferView::SELECT|BufferView::FITCUR);
2075 TEXT(bv_)->CursorUp(bv_);
2076 TEXT(bv_)->FinishUndo();
2077 moveCursorUpdate(true);
2078 owner_->showState();
2083 BufferView::SELECT|BufferView::FITCUR);
2084 TEXT(bv_)->CursorDown(bv_);
2085 TEXT(bv_)->FinishUndo();
2086 moveCursorUpdate(true);
2087 owner_->showState();
2090 case LFUN_UP_PARAGRAPHSEL:
2092 BufferView::SELECT|BufferView::FITCUR);
2093 TEXT(bv_)->CursorUpParagraph(bv_);
2094 TEXT(bv_)->FinishUndo();
2095 moveCursorUpdate(true);
2096 owner_->showState();
2099 case LFUN_DOWN_PARAGRAPHSEL:
2101 BufferView::SELECT|BufferView::FITCUR);
2102 TEXT(bv_)->CursorDownParagraph(bv_);
2103 TEXT(bv_)->FinishUndo();
2104 moveCursorUpdate(true);
2105 owner_->showState();
2109 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2110 cursorPrevious(TEXT(bv_));
2111 TEXT(bv_)->FinishUndo();
2112 moveCursorUpdate(true);
2113 owner_->showState();
2117 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2118 cursorNext(TEXT(bv_));
2119 TEXT(bv_)->FinishUndo();
2120 moveCursorUpdate(true);
2121 owner_->showState();
2125 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2126 TEXT(bv_)->CursorHome(bv_);
2127 TEXT(bv_)->FinishUndo();
2128 moveCursorUpdate(true);
2129 owner_->showState();
2133 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2134 TEXT(bv_)->CursorEnd(bv_);
2135 TEXT(bv_)->FinishUndo();
2136 moveCursorUpdate(true);
2137 owner_->showState();
2140 case LFUN_WORDRIGHTSEL:
2141 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2142 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2143 TEXT(bv_)->CursorLeftOneWord(bv_);
2145 TEXT(bv_)->CursorRightOneWord(bv_);
2146 TEXT(bv_)->FinishUndo();
2147 moveCursorUpdate(true);
2148 owner_->showState();
2151 case LFUN_WORDLEFTSEL:
2152 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2153 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2154 TEXT(bv_)->CursorRightOneWord(bv_);
2156 TEXT(bv_)->CursorLeftOneWord(bv_);
2157 TEXT(bv_)->FinishUndo();
2158 moveCursorUpdate(true);
2159 owner_->showState();
2162 case LFUN_BEGINNINGBUFSEL:
2163 if (TEXT(bv_)->inset_owner)
2165 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2166 TEXT(bv_)->CursorTop(bv_);
2167 TEXT(bv_)->FinishUndo();
2168 moveCursorUpdate(true);
2169 owner_->showState();
2172 case LFUN_ENDBUFSEL:
2173 if (TEXT(bv_)->inset_owner)
2176 BufferView::SELECT|BufferView::FITCUR);
2177 TEXT(bv_)->CursorBottom(bv_);
2178 TEXT(bv_)->FinishUndo();
2179 moveCursorUpdate(true);
2180 owner_->showState();
2183 // --- text changing commands ------------------------
2184 case LFUN_BREAKLINE:
2185 beforeChange(TEXT(bv_));
2186 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2188 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2189 moveCursorUpdate(false);
2192 case LFUN_PROTECTEDSPACE:
2194 LyXLayout const & style =
2195 textclasslist.Style(buffer_->params.textclass,
2196 TEXT(bv_)->cursor.par()->GetLayout());
2198 if (style.free_spacing) {
2199 TEXT(bv_)->InsertChar(bv_, ' ');
2200 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2202 bv_->protectedBlank(TEXT(bv_));
2204 moveCursorUpdate(false);
2209 if (TEXT(bv_)->mark_set) {
2210 beforeChange(TEXT(bv_));
2211 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2212 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2214 beforeChange(TEXT(bv_));
2215 TEXT(bv_)->mark_set = 1;
2216 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2217 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2219 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2223 if (!TEXT(bv_)->selection) {
2224 TEXT(bv_)->Delete(bv_);
2225 TEXT(bv_)->sel_cursor =
2228 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2229 // It is possible to make it a lot faster still
2230 // just comment out the line below...
2235 moveCursorUpdate(false);
2236 owner_->showState();
2240 case LFUN_DELETE_SKIP:
2242 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2244 LyXCursor cursor = TEXT(bv_)->cursor;
2246 if (!TEXT(bv_)->selection) {
2248 if (cursor.pos() == cursor.par()->Last()) {
2250 if (cursor.pos() == cursor.par()->size()) {
2252 TEXT(bv_)->CursorRight(bv_);
2253 cursor = TEXT(bv_)->cursor;
2254 if (cursor.pos() == 0
2255 && !(cursor.par()->params.spaceTop()
2256 == VSpace (VSpace::NONE))) {
2257 TEXT(bv_)->SetParagraph
2259 cursor.par()->params.lineTop(),
2260 cursor.par()->params.lineBottom(),
2261 cursor.par()->params.pagebreakTop(),
2262 cursor.par()->params.pagebreakBottom(),
2263 VSpace(VSpace::NONE),
2264 cursor.par()->params.spaceBottom(),
2265 cursor.par()->params.align(),
2266 cursor.par()->params.labelWidthString(), 0);
2267 TEXT(bv_)->CursorLeft(bv_);
2269 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2271 TEXT(bv_)->CursorLeft(bv_);
2272 TEXT(bv_)->Delete(bv_);
2273 TEXT(bv_)->sel_cursor =
2276 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2279 TEXT(bv_)->Delete(bv_);
2280 TEXT(bv_)->sel_cursor =
2283 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2291 /* -------> Delete word forward. */
2292 case LFUN_DELETE_WORD_FORWARD:
2293 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2294 TEXT(bv_)->DeleteWordForward(bv_);
2295 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2296 moveCursorUpdate(false);
2297 owner_->showState();
2300 /* -------> Delete word backward. */
2301 case LFUN_DELETE_WORD_BACKWARD:
2302 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2303 TEXT(bv_)->DeleteWordBackward(bv_);
2304 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2305 moveCursorUpdate(false);
2306 owner_->showState();
2309 /* -------> Kill to end of line. */
2310 case LFUN_DELETE_LINE_FORWARD:
2311 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2312 TEXT(bv_)->DeleteLineForward(bv_);
2313 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2314 moveCursorUpdate(false);
2317 /* -------> Set mark off. */
2319 beforeChange(TEXT(bv_));
2320 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2321 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2322 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2325 /* -------> Set mark on. */
2327 beforeChange(TEXT(bv_));
2328 TEXT(bv_)->mark_set = 1;
2329 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2330 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2331 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2334 case LFUN_BACKSPACE:
2336 if (!TEXT(bv_)->selection) {
2337 if (owner_->getIntl()->getTrans().backspace()) {
2338 TEXT(bv_)->Backspace(bv_);
2339 TEXT(bv_)->sel_cursor =
2342 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2343 // It is possible to make it a lot faster still
2344 // just comment out the line below...
2350 owner_->showState();
2355 case LFUN_BACKSPACE_SKIP:
2357 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2359 LyXCursor cursor = TEXT(bv_)->cursor;
2361 if (!TEXT(bv_)->selection) {
2362 if (cursor.pos() == 0
2363 && !(cursor.par()->params.spaceTop()
2364 == VSpace (VSpace::NONE))) {
2365 TEXT(bv_)->SetParagraph
2367 cursor.par()->params.lineTop(),
2368 cursor.par()->params.lineBottom(),
2369 cursor.par()->params.pagebreakTop(),
2370 cursor.par()->params.pagebreakBottom(),
2371 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2372 cursor.par()->params.align(),
2373 cursor.par()->params.labelWidthString(), 0);
2375 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2377 TEXT(bv_)->Backspace(bv_);
2378 TEXT(bv_)->sel_cursor
2381 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2388 case LFUN_BREAKPARAGRAPH:
2390 beforeChange(TEXT(bv_));
2391 TEXT(bv_)->BreakParagraph(bv_, 0);
2393 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2394 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2396 owner_->showState();
2400 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2402 beforeChange(TEXT(bv_));
2403 TEXT(bv_)->BreakParagraph(bv_, 1);
2405 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2406 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2408 owner_->showState();
2412 case LFUN_BREAKPARAGRAPH_SKIP:
2414 // When at the beginning of a paragraph, remove
2415 // indentation and add a "defskip" at the top.
2416 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2418 LyXCursor cursor = TEXT(bv_)->cursor;
2420 beforeChange(TEXT(bv_));
2421 if (cursor.pos() == 0) {
2422 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2423 TEXT(bv_)->SetParagraph
2425 cursor.par()->params.lineTop(),
2426 cursor.par()->params.lineBottom(),
2427 cursor.par()->params.pagebreakTop(),
2428 cursor.par()->params.pagebreakBottom(),
2429 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2430 cursor.par()->params.align(),
2431 cursor.par()->params.labelWidthString(), 1);
2432 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2436 TEXT(bv_)->BreakParagraph(bv_, 0);
2437 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2441 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2442 TEXT(bv_)->sel_cursor = cursor;
2444 owner_->showState();
2448 case LFUN_PARAGRAPH_SPACING:
2450 LyXParagraph * par = TEXT(bv_)->cursor.par();
2451 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2452 float cur_value = 1.0;
2453 if (cur_spacing == Spacing::Other) {
2454 cur_value = par->params.spacing().getValue();
2457 istringstream istr(argument.c_str());
2461 Spacing::Space new_spacing = cur_spacing;
2462 float new_value = cur_value;
2464 lyxerr << "Missing argument to `paragraph-spacing'"
2466 } else if (tmp == "single") {
2467 new_spacing = Spacing::Single;
2468 } else if (tmp == "onehalf") {
2469 new_spacing = Spacing::Onehalf;
2470 } else if (tmp == "double") {
2471 new_spacing = Spacing::Double;
2472 } else if (tmp == "other") {
2473 new_spacing = Spacing::Other;
2476 lyxerr << "new_value = " << tmpval << endl;
2479 } else if (tmp == "default") {
2480 new_spacing = Spacing::Default;
2482 lyxerr << _("Unknown spacing argument: ")
2483 << argument << endl;
2485 if (cur_spacing != new_spacing || cur_value != new_value) {
2486 par->params.spacing(Spacing(new_spacing, new_value));
2487 TEXT(bv_)->RedoParagraph(bv_);
2489 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2495 beforeChange(TEXT(bv_));
2496 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2497 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2498 moveCursorUpdate(false);
2504 InsetCommandParams p;
2505 if (action == LFUN_HTMLURL)
2506 p.setCmdName("htmlurl");
2508 p.setCmdName("url");
2509 owner_->getDialogs()->createUrl( p.getAsString() );
2513 case LFUN_INSERT_URL:
2515 InsetCommandParams p;
2516 p.setFromString( argument );
2518 InsetUrl * inset = new InsetUrl( p );
2519 if (!bv_->insertInset(inset))
2522 bv_->updateInset( inset, true );
2526 case LFUN_INSET_TEXT:
2528 InsetText * new_inset = new InsetText;
2529 if (bv_->insertInset(new_inset))
2530 new_inset->Edit(bv_, 0, 0, 0);
2536 case LFUN_INSET_ERT:
2538 InsetERT * new_inset = new InsetERT;
2539 if (bv_->insertInset(new_inset))
2540 new_inset->Edit(bv_, 0, 0, 0);
2546 case LFUN_INSET_EXTERNAL:
2548 InsetExternal * new_inset = new InsetExternal;
2549 if (bv_->insertInset(new_inset))
2550 new_inset->Edit(bv_, 0, 0, 0);
2556 case LFUN_INSET_FOOTNOTE:
2558 InsetFoot * new_inset = new InsetFoot;
2559 if (bv_->insertInset(new_inset))
2560 new_inset->Edit(bv_, 0, 0, 0);
2566 case LFUN_INSET_MARGINAL:
2568 InsetMarginal * new_inset = new InsetMarginal;
2569 if (bv_->insertInset(new_inset))
2570 new_inset->Edit(bv_, 0, 0, 0);
2576 case LFUN_INSET_MINIPAGE:
2578 InsetMinipage * new_inset = new InsetMinipage;
2579 if (bv_->insertInset(new_inset))
2580 new_inset->Edit(bv_, 0, 0, 0);
2586 case LFUN_INSET_FLOAT:
2588 // check if the float type exist
2589 if (floatList.typeExist(argument)) {
2590 InsetFloat * new_inset = new InsetFloat(argument);
2591 if (bv_->insertInset(new_inset))
2592 new_inset->Edit(bv_, 0, 0, 0);
2596 lyxerr << "Non-existant float type: "
2597 << argument << endl;
2603 case LFUN_INSET_LIST:
2605 InsetList * new_inset = new InsetList;
2606 if (bv_->insertInset(new_inset))
2607 new_inset->Edit(bv_, 0, 0, 0);
2613 case LFUN_INSET_THEOREM:
2615 InsetTheorem * new_inset = new InsetTheorem;
2616 if (bv_->insertInset(new_inset))
2617 new_inset->Edit(bv_, 0, 0, 0);
2623 case LFUN_INSET_CAPTION:
2625 // Do we have a locking inset...
2626 if (bv_->theLockingInset()) {
2627 lyxerr << "Locking inset code: "
2628 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2629 InsetCaption * new_inset = new InsetCaption;
2630 new_inset->setOwner(bv_->theLockingInset());
2631 new_inset->SetAutoBreakRows(true);
2632 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2633 new_inset->SetFrameColor(0, LColor::footnoteframe);
2634 if (bv_->insertInset(new_inset))
2635 new_inset->Edit(bv_, 0, 0, 0);
2642 case LFUN_INSET_TABULAR:
2645 if (!argument.empty())
2646 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2647 InsetTabular * new_inset =
2648 new InsetTabular(*buffer_, r, c);
2650 TEXT(bv_)->real_current_font.isRightToLeft();
2651 if (!bv_->open_new_inset(new_inset, rtl))
2656 // --- lyxserver commands ----------------------------
2658 case LFUN_CHARATCURSOR:
2660 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2661 if (pos < TEXT(bv_)->cursor.par()->size())
2662 owner_->getLyXFunc()->setMessage(
2663 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2665 owner_->getLyXFunc()->setMessage("EOF");
2670 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2672 + tostr(TEXT(bv_)->cursor.y()));
2679 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2680 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2684 case LFUN_GETLAYOUT:
2685 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2690 LyXFont & font = TEXT(bv_)->current_font;
2691 if (font.shape() == LyXFont::ITALIC_SHAPE)
2692 owner_->getLyXFunc()->setMessage("E");
2693 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2694 owner_->getLyXFunc()->setMessage("N");
2696 owner_->getLyXFunc()->setMessage("0");
2703 LyXFont & font = TEXT(bv_)->current_font;
2704 if (font.latex() == LyXFont::ON)
2705 owner_->getLyXFunc()->setMessage("L");
2707 owner_->getLyXFunc()->setMessage("0");
2711 // --- accented characters ---------------------------
2714 case LFUN_CIRCUMFLEX:
2724 case LFUN_SPECIAL_CARON:
2727 case LFUN_HUNG_UMLAUT:
2730 owner_->getLyXFunc()->handleKeyFunc(action);
2733 // --- insert characters ----------------------------------------
2735 case LFUN_MATH_DELIM:
2736 case LFUN_INSERT_MATRIX:
2739 if (bv_->open_new_inset(new InsetFormula(false)))
2741 bv_->theLockingInset()
2742 ->LocalDispatch(bv_, action, argument);
2748 case LFUN_INSERT_MATH:
2753 InsetFormula * f = new InsetFormula(true);
2754 bv_->open_new_inset(f);
2755 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2759 case LFUN_MATH_DISPLAY:
2762 bv_->open_new_inset(new InsetFormula(true));
2766 case LFUN_MATH_MACRO:
2771 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2773 string const s1 = token(s, ' ', 1);
2774 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2775 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2781 case LFUN_MATH_MODE: // Open or create a math inset
2784 bv_->open_new_inset(new InsetFormula);
2785 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2789 case LFUN_CITATION_INSERT:
2791 InsetCommandParams p;
2792 p.setFromString( argument );
2794 InsetCitation * inset = new InsetCitation( p );
2795 if (!bv_->insertInset(inset))
2798 bv_->updateInset( inset, true );
2802 case LFUN_INSERT_BIBTEX:
2804 // ale970405+lasgoutt970425
2805 // The argument can be up to two tokens separated
2806 // by a space. The first one is the bibstyle.
2807 string const db = token(argument, ' ', 0);
2808 string bibstyle = token(argument, ' ', 1);
2809 if (bibstyle.empty())
2812 InsetCommandParams p( "BibTeX", db, bibstyle );
2813 InsetBibtex * inset = new InsetBibtex(p);
2815 if (bv_->insertInset(inset)) {
2816 if (argument.empty())
2817 inset->Edit(bv_, 0, 0, 0);
2823 // BibTeX data bases
2824 case LFUN_BIBDB_ADD:
2826 InsetBibtex * inset =
2827 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2829 inset->addDatabase(argument);
2834 case LFUN_BIBDB_DEL:
2836 InsetBibtex * inset =
2837 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2839 inset->delDatabase(argument);
2844 case LFUN_BIBTEX_STYLE:
2846 InsetBibtex * inset =
2847 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2849 inset->setOptions(argument);
2854 case LFUN_INDEX_CREATE:
2856 InsetCommandParams p( "index" );
2858 if (argument.empty()) {
2859 // Get the word immediately preceding the cursor
2860 LyXParagraph::size_type curpos =
2861 TEXT(bv_)->cursor.pos() - 1;
2865 curstring = TEXT(bv_)
2866 ->cursor.par()->GetWord(curpos);
2868 p.setContents( curstring );
2870 p.setContents( argument );
2873 owner_->getDialogs()->createIndex( p.getAsString() );
2877 case LFUN_INDEX_INSERT:
2879 InsetCommandParams p;
2880 p.setFromString(argument);
2881 InsetIndex * inset = new InsetIndex(p);
2883 if (!bv_->insertInset(inset))
2886 bv_->updateInset(inset, true);
2890 case LFUN_INDEX_INSERT_LAST:
2892 // Get word immediately preceding the cursor
2893 LyXParagraph::size_type curpos =
2894 TEXT(bv_)->cursor.pos() - 1;
2895 // Can't do that at the beginning of a paragraph
2896 if (curpos < 0) break;
2898 string const curstring(TEXT(bv_)
2899 ->cursor.par()->GetWord(curpos));
2901 InsetCommandParams p("index", curstring);
2902 InsetIndex * inset = new InsetIndex(p);
2904 if (!bv_->insertInset(inset))
2907 bv_->updateInset(inset, true);
2911 case LFUN_INDEX_PRINT:
2913 InsetCommandParams p("printindex");
2914 Inset * inset = new InsetPrintIndex(p);
2915 if (!bv_->insertInset(inset, "Standard", true))
2920 case LFUN_PARENTINSERT:
2922 lyxerr << "arg " << argument << endl;
2923 InsetCommandParams p( "lyxparent", argument );
2924 Inset * inset = new InsetParent(p, *buffer_);
2925 if (!bv_->insertInset(inset, "Standard", true))
2930 case LFUN_CHILD_INSERT:
2932 InsetInclude::InsetIncludeParams p;
2933 p.cparams.setFromString(argument);
2936 InsetInclude * inset = new InsetInclude(p);
2937 if (!bv_->insertInset(inset))
2940 bv_->updateInset(inset, true);
2941 bv_->owner()->getDialogs()->showInclude(inset);
2946 case LFUN_INSERT_NOTE:
2950 case LFUN_SELFINSERT:
2952 LyXFont const old_font(TEXT(bv_)->real_current_font);
2953 for (string::size_type i = 0; i < argument.length(); ++i) {
2954 TEXT(bv_)->InsertChar(bv_, argument[i]);
2955 // This needs to be in the loop, or else we
2956 // won't break lines correctly. (Asger)
2958 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2960 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2961 moveCursorUpdate(false);
2963 // real_current_font.number can change so we need to
2964 // update the minibuffer
2965 if (old_font != TEXT(bv_)->real_current_font)
2966 owner_->showState();
2970 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2974 time_t now_time_t = time(NULL);
2975 now_tm = localtime(&now_time_t);
2976 setlocale(LC_TIME, "");
2978 if (!argument.empty())
2981 arg = lyxrc.date_insert_format;
2983 int const datetmp_len =
2984 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2985 for (int i = 0; i < datetmp_len; i++) {
2986 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2988 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2991 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2992 moveCursorUpdate(false);
2996 case LFUN_UNKNOWN_ACTION:
2999 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
3003 if (buffer_->isReadonly()) {
3004 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
3007 if (!argument.empty()) {
3008 /* Automatically delete the currently selected
3009 * text and replace it with what is being
3010 * typed in now. Depends on lyxrc settings
3011 * "auto_region_delete", which defaults to
3014 if (lyxrc.auto_region_delete) {
3015 if (TEXT(bv_)->selection){
3016 TEXT(bv_)->CutSelection(bv_, false);
3018 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3022 beforeChange(TEXT(bv_));
3023 LyXFont const old_font(TEXT(bv_)->real_current_font);
3024 for (string::size_type i = 0;
3025 i < argument.length(); ++i) {
3026 if (greek_kb_flag) {
3027 if (!math_insert_greek(bv_, argument[i]))
3028 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3030 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3033 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3035 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3036 moveCursorUpdate(false);
3038 // real_current_font.number can change so we need to
3039 // update the minibuffer
3040 if (old_font != TEXT(bv_)->real_current_font)
3041 owner_->showState();
3043 // if we don't have an argument there was something
3044 // strange going on so we just tell this to someone!
3045 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));