10 #include "BufferView_pimpl.h"
12 #include "lyxscreen.h"
16 #include "commandtags.h"
18 #include "minibuffer.h"
20 #include "bufferview_funcs.h"
21 #include "TextCache.h"
22 #include "bufferlist.h"
23 #include "lyx_gui_misc.h"
26 #include "support/LAssert.h"
27 #include "frontends/Dialogs.h"
28 #include "insets/insetbib.h"
29 #include "insets/insettext.h"
30 /// added for Dispatch functions
34 #include "FloatList.h"
35 #include "support/filetools.h"
36 #include "support/lyxfunctional.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinclude.h"
44 #include "insets/insetcite.h"
45 #include "insets/insetert.h"
46 #include "insets/insetexternal.h"
47 #include "insets/insetgraphics.h"
48 #include "insets/insetfoot.h"
49 #include "insets/insetmarginal.h"
50 #include "insets/insetminipage.h"
51 #include "insets/insetfloat.h"
52 #include "insets/insetlist.h"
53 #include "insets/insettabular.h"
54 #include "insets/insettheorem.h"
55 #include "insets/insetcaption.h"
56 #include "mathed/formulamacro.h"
57 extern LyXTextClass::size_type current_layout;
58 extern void math_insert_symbol(BufferView *, string const &);
59 extern bool math_insert_greek(BufferView *, char);
60 extern int greek_kb_flag;
62 #ifdef SIGC_CXX_NAMESPACES
72 /* the selection possible is needed, that only motion events are
73 * used, where the bottom press event was on the drawing area too */
74 bool selection_possible = false;
76 extern BufferList bufferlist;
77 extern char ascii_type;
79 extern void sigchldhandler(pid_t pid, int * status);
80 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
82 const unsigned int saved_positions_num = 20;
87 XSync(fl_get_display(), 0);
92 void SetXtermCursor(Window win)
95 static bool cursor_undefined = true;
96 if (cursor_undefined){
97 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
98 XFlush(fl_get_display());
99 cursor_undefined = false;
101 XDefineCursor(fl_get_display(), win, cursor);
102 XFlush(fl_get_display());
106 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
107 int xpos, int ypos, int width, int height)
108 : bv_(b), owner_(o), cursor_timeout(400)
111 workarea_ = new WorkArea(xpos, ypos, width, height);
113 workarea_->scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
114 workarea_->workAreaExpose
115 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
116 workarea_->workAreaEnter
117 .connect(slot(this, &BufferView::Pimpl::enterView));
118 workarea_->workAreaLeave
119 .connect(slot(this, &BufferView::Pimpl::leaveView));
120 workarea_->workAreaButtonPress
121 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
122 workarea_->workAreaButtonRelease
124 &BufferView::Pimpl::workAreaButtonRelease));
125 workarea_->workAreaMotionNotify
126 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
127 workarea_->workAreaDoubleClick
128 .connect(slot(this, &BufferView::Pimpl::doubleClick));
129 workarea_->workAreaTripleClick
130 .connect(slot(this, &BufferView::Pimpl::tripleClick));
131 workarea_->workAreaKeyPress
132 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
136 cursor_timeout.timeout.connect(slot(this,
137 &BufferView::Pimpl::cursorToggle));
138 current_scrollbar_value = 0;
139 cursor_timeout.start();
140 workarea_->setFocus();
141 using_xterm_cursor = false;
142 saved_positions.resize(saved_positions_num);
146 Painter & BufferView::Pimpl::painter()
148 return workarea_->getPainter();
152 void BufferView::Pimpl::buffer(Buffer * b)
154 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
158 buffer_->delUser(bv_);
160 // Put the old text into the TextCache, but
161 // only if the buffer is still loaded.
162 // Also set the owner of the test to 0
163 // bv_->text->owner(0);
164 textcache.add(buffer_, workarea_->workWidth(), bv_->text);
165 if (lyxerr.debugging())
166 textcache.show(lyxerr, "BufferView::buffer");
171 // Set current buffer
174 if (bufferlist.getState() == BufferList::CLOSING) return;
177 // 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)
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;
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 owner_->getDialogs()->hideSplash();
354 void BufferView::Pimpl::updateScreen()
356 // Regenerate the screen.
358 screen_ = new LyXScreen(*workarea_);
362 void BufferView::Pimpl::updateScrollbar()
364 /* If the text is smaller than the working area, the scrollbar
365 * maximum must be the working area height. No scrolling will
369 workarea_->setScrollbar(0, 1.0);
373 static unsigned long max2 = 0;
374 static unsigned long height2 = 0;
376 unsigned long cbth = 0;
380 cbth = bv_->text->height;
381 cbsf = bv_->text->first;
384 // check if anything has changed.
386 height2 == workarea_->height() &&
387 current_scrollbar_value == cbsf)
390 height2 = workarea_->height();
391 current_scrollbar_value = cbsf;
393 if (cbth <= height2) { // text is smaller than screen
394 workarea_->setScrollbar(0, 1.0); // right?
398 long maximum_height = workarea_->height() * 3 / 4 + cbth;
402 double hfloat = workarea_->height();
403 double maxfloat = maximum_height;
405 float slider_size = 0.0;
406 int slider_value = value;
408 workarea_->setScrollbarBounds(0, bv_->text->height - workarea_->height());
409 double lineh = bv_->text->DefaultHeight();
410 workarea_->setScrollbarIncrements(lineh);
411 if (maxfloat > 0.0) {
412 if ((hfloat / maxfloat) * float(height2) < 3)
413 slider_size = 3.0/float(height2);
415 slider_size = hfloat / maxfloat;
417 slider_size = hfloat;
419 workarea_->setScrollbar(slider_value, slider_size / workarea_->height());
423 // Callback for scrollbar slider
424 void BufferView::Pimpl::scrollCB(double value)
426 if (!buffer_) return;
428 current_scrollbar_value = long(value);
429 if (current_scrollbar_value < 0)
430 current_scrollbar_value = 0;
435 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
437 if (!lyxrc.cursor_follows_scrollbar) {
442 LyXText * vbt = bv_->text;
444 int const height = vbt->DefaultHeight();
445 int const first = static_cast<int>((bv_->text->first + height));
446 int const last = static_cast<int>((bv_->text->first + workarea_->height() - height));
448 if (vbt->cursor.y() < first)
449 vbt->SetCursorFromCoordinates(bv_, 0, first);
450 else if (vbt->cursor.y() > last)
451 vbt->SetCursorFromCoordinates(bv_, 0, last);
457 int BufferView::Pimpl::scrollUp(long time)
459 if (!buffer_) return 0;
460 if (!screen_) return 0;
462 double value = workarea_->getScrollbarValue();
464 if (value == 0) return 0;
466 float add_value = (bv_->text->DefaultHeight()
467 + float(time) * float(time) * 0.125);
469 if (add_value > workarea_->height())
470 add_value = float(workarea_->height() -
471 bv_->text->DefaultHeight());
478 workarea_->setScrollbarValue(value);
485 int BufferView::Pimpl::scrollDown(long time)
487 if (!buffer_) return 0;
488 if (!screen_) return 0;
490 double value= workarea_->getScrollbarValue();
491 pair<float, float> p = workarea_->getScrollbarBounds();
492 double max = p.second;
494 if (value == max) return 0;
496 float add_value = (bv_->text->DefaultHeight()
497 + float(time) * float(time) * 0.125);
499 if (add_value > workarea_->height())
500 add_value = float(workarea_->height() -
501 bv_->text->DefaultHeight());
508 workarea_->setScrollbarValue(value);
515 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
517 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
521 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
523 // Only use motion with button 1
524 if (!(state & Button1MotionMask))
527 if (!buffer_ || !screen_) return;
529 // Check for inset locking
530 if (bv_->theLockingInset()) {
531 LyXCursor cursor = bv_->text->cursor;
532 LyXFont font = bv_->text->GetFont(bv_->buffer(),
533 cursor.par(), cursor.pos());
534 int width = bv_->theLockingInset()->width(bv_, font);
535 int inset_x = font.isVisibleRightToLeft()
536 ? cursor.x() - width : cursor.x();
537 int start_x = inset_x + bv_->theLockingInset()->scroll();
538 bv_->theLockingInset()->
539 InsetMotionNotify(bv_,
541 y - cursor.y() + bv_->text->first,
546 /* The test for not selection possible is needed, that only motion events are
547 * used, where the bottom press event was on the drawing area too */
548 if (!selection_possible)
551 screen_->HideCursor();
553 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
555 if (!bv_->text->selection)
556 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
558 bv_->text->SetSelection(bv_);
559 screen_->ToggleToggle(bv_->text, bv_);
560 fitCursor(bv_->text);
561 screen_->ShowCursor(bv_->text, bv_);
565 // Single-click on work area
566 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
572 if (!buffer_ || !screen_) return;
574 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
576 // ok ok, this is a hack.
577 if (button == 4 || button == 5) {
580 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
583 scrollDown(lyxrc.wheel_jump);
588 if (bv_->theLockingInset()) {
589 // We are in inset locking mode
591 /* Check whether the inset was hit. If not reset mode,
592 otherwise give the event to the inset */
593 if (inset_hit == bv_->theLockingInset()) {
594 bv_->theLockingInset()->
595 InsetButtonPress(bv_,
600 bv_->unlockInset(bv_->theLockingInset());
605 selection_possible = true;
606 screen_->HideCursor();
608 int const screen_first = bv_->text->first;
610 // Middle button press pastes if we have a selection
611 bool paste_internally = false;
613 && bv_->text->selection) {
614 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
615 paste_internally = true;
618 // Clear the selection
619 screen_->ToggleSelection(bv_->text, bv_);
620 bv_->text->ClearSelection(bv_);
621 bv_->text->FullRebreak(bv_);
622 screen_->Update(bv_->text, bv_);
625 // Single left click in math inset?
626 if ((inset_hit != 0) &&
627 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
628 // Highly editable inset, like math
629 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
630 selection_possible = false;
631 owner_->updateLayoutChoice();
632 owner_->getMiniBuffer()->Set(inset->EditMessage());
633 inset->InsetButtonPress(bv_, xpos, ypos, button);
634 inset->Edit(bv_, xpos, ypos, button);
638 // Right click on a footnote flag opens float menu
640 selection_possible = false;
644 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
645 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
646 bv_->text->FinishUndo();
647 bv_->text->sel_cursor = bv_->text->cursor;
648 bv_->text->cursor.x_fix(bv_->text->cursor.x());
650 owner_->updateLayoutChoice();
651 if (fitCursor(bv_->text)) {
652 selection_possible = false;
655 // Insert primary selection with middle mouse
656 // if there is a local selection in the current buffer,
659 if (paste_internally)
660 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
662 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
664 selection_possible = false;
670 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
676 LyXText * text = bv_->getLyXText();
678 if (text->bv_owner && bv_->theLockingInset())
681 if (screen_ && button == 1) {
682 if (text->bv_owner) {
683 screen_->HideCursor();
684 screen_->ToggleSelection(text, bv_);
685 text->SelectWord(bv_);
686 screen_->ToggleSelection(text, bv_, false);
688 text->SelectWord(bv_);
690 /* This will fit the cursor on the screen
692 update(text, BufferView::SELECT|BufferView::FITCUR);
697 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
703 LyXText * text = bv_->getLyXText();
705 if (text->bv_owner && bv_->theLockingInset())
708 if (screen_ && (button == 1)) {
709 screen_->HideCursor();
710 screen_->ToggleSelection(text, bv_);
711 text->CursorHome(bv_);
712 text->sel_cursor = text->cursor;
713 text->CursorEnd(bv_);
714 text->SetSelection(bv_);
715 screen_->ToggleSelection(text, bv_, false);
716 /* This will fit the cursor on the screen
718 update(text, BufferView::SELECT|BufferView::FITCUR);
723 void BufferView::Pimpl::enterView()
725 if (active() && available()) {
726 SetXtermCursor(workarea_->getWin());
727 using_xterm_cursor = true;
732 void BufferView::Pimpl::leaveView()
734 if (using_xterm_cursor) {
735 XUndefineCursor(fl_get_display(), workarea_->getWin());
736 using_xterm_cursor = false;
741 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
744 if (!buffer_ || !screen_) return;
746 // If we hit an inset, we have the inset coordinates in these
747 // and inset_hit points to the inset. If we do not hit an
748 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
749 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
751 if (bv_->theLockingInset()) {
752 // We are in inset locking mode.
754 /* LyX does a kind of work-area grabbing for insets.
755 Only a ButtonPress Event outside the inset will
756 force a InsetUnlock. */
757 bv_->theLockingInset()->
758 InsetButtonRelease(bv_, x, y, button);
762 selection_possible = false;
764 if (button >= 2) return;
769 // Did we hit an editable inset?
771 // Inset like error, notes and figures
772 selection_possible = false;
774 // CHECK fix this proper in 0.13
776 // Following a ref shouldn't issue
777 // a push on the undo-stack
778 // anylonger, now that we have
779 // keybindings for following
780 // references and returning from
781 // references. IMHO though, it
782 // should be the inset's own business
783 // to push or not push on the undo
784 // stack. They don't *have* to
785 // alter the document...
787 // ...or maybe the SetCursorParUndo()
788 // below isn't necessary at all anylonger?
789 if (inset_hit->LyxCode() == Inset::REF_CODE) {
790 bv_->text->SetCursorParUndo(bv_->buffer());
793 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
794 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
795 // Highly editable inset, like math
796 UpdatableInset *inset = (UpdatableInset *)inset_hit;
797 inset->InsetButtonRelease(bv_, x, y, button);
799 inset_hit->InsetButtonRelease(bv_, x, y, button);
800 inset_hit->Edit(bv_, x, y, button);
805 // check whether we want to open a float
809 if (bv_->text->cursor.pos() <
810 bv_->text->cursor.par()->Last()) {
811 c = bv_->text->cursor.par()->
812 GetChar(bv_->text->cursor.pos());
815 if(!bv_->text->selection)
816 if (c == LyXParagraph::META_FOOTNOTE
817 || c == LyXParagraph::META_MARGIN
818 || c == LyXParagraph::META_FIG
819 || c == LyXParagraph::META_TAB
820 || c == LyXParagraph::META_WIDE_FIG
821 || c == LyXParagraph::META_WIDE_TAB
822 || c == LyXParagraph::META_ALGORITHM){
826 if (bv_->text->cursor.pos() - 1 >= 0) {
827 c = bv_->text->cursor.par()->
828 GetChar(bv_->text->cursor.pos() - 1);
830 if (c == LyXParagraph::META_FOOTNOTE
831 || c == LyXParagraph::META_MARGIN
832 || c == LyXParagraph::META_FIG
833 || c == LyXParagraph::META_TAB
834 || c == LyXParagraph::META_WIDE_FIG
835 || c == LyXParagraph::META_WIDE_TAB
836 || c == LyXParagraph::META_ALGORITHM){
837 // We are one step too far to the right
838 bv_->text->CursorLeft(bv_);
847 selection_possible = false;
853 // Do we want to close a float? (click on the float-label)
854 if (bv_->text->cursor.row()->par()->footnoteflag ==
855 LyXParagraph::OPEN_FOOTNOTE
856 && bv_->text->cursor.row()->previous() &&
857 bv_->text->cursor.row()->previous()->par()->
858 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
859 LyXFont font(LyXFont::ALL_SANE);
860 font.setSize(LyXFont::SIZE_FOOTNOTE);
862 int box_x = 20; // LYX_PAPER_MARGIN;
863 box_x += lyxfont::width(" wide-tab ", font);
865 unsigned int screen_first = bv_->text->first;
868 && y + screen_first > bv_->text->cursor.y() -
869 bv_->text->cursor.row()->baseline()
870 && y + screen_first < bv_->text->cursor.y() -
871 bv_->text->cursor.row()->baseline()
872 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
874 selection_possible = false;
880 // Maybe we want to edit a bibitem ale970302
881 if (bv_->text->cursor.par()->bibkey && x < 20 +
882 bibitemMaxWidth(bv_, textclasslist.
884 params.textclass).defaultfont())) {
885 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
893 * Returns an inset if inset was hit. 0 otherwise.
894 * If hit, the coordinates are changed relative to the inset.
895 * Otherwise coordinates are not changed, and false is returned.
897 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
898 unsigned int /* button */)
903 int y_tmp = y + text->first;
906 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
908 if (cursor.pos() < cursor.par()->Last()
909 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
910 && cursor.par()->GetInset(cursor.pos())
911 && cursor.par()->GetInset(cursor.pos())->Editable()) {
913 // Check whether the inset really was hit
914 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
915 LyXFont font = text->GetFont(bv_->buffer(),
916 cursor.par(), cursor.pos());
917 int width = tmpinset->width(bv_, font);
918 int inset_x = font.isVisibleRightToLeft()
919 ? cursor.x() - width : cursor.x();
920 int start_x = inset_x + tmpinset->scroll();
921 int end_x = inset_x + width;
923 if (x > start_x && x < end_x
924 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
925 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
926 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
928 // The origin of an inset is on the baseline
929 y = y_tmp - (text->cursor.y());
934 if ((cursor.pos() - 1 >= 0) &&
935 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
936 (cursor.par()->GetInset(cursor.pos() - 1)) &&
937 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
938 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
939 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
941 int width = tmpinset->width(bv_, font);
942 int inset_x = font.isVisibleRightToLeft()
943 ? cursor.x() : cursor.x() - width;
944 int start_x = inset_x + tmpinset->scroll();
945 int end_x = inset_x + width;
947 if (x > start_x && x < end_x
948 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
949 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
951 if (move_cursor && (tmpinset != bv_->theLockingInset()))
953 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
955 // The origin of an inset is on the baseline
956 y = y_tmp - (text->cursor.y());
964 void BufferView::Pimpl::workAreaExpose()
966 static int work_area_width = 0;
967 static unsigned int work_area_height = 0;
969 bool widthChange = workarea_->workWidth() != work_area_width;
970 bool heightChange = workarea_->height() != work_area_height;
972 // update from work area
973 work_area_width = workarea_->workWidth();
974 work_area_height = workarea_->height();
977 // All buffers need a resize
980 // Remove all texts from the textcache
981 // This is not _really_ what we want to do. What
982 // we really want to do is to delete in textcache
983 // that does not have a BufferView with matching
984 // width, but as long as we have only one BufferView
985 // deleting all gives the same result.
986 if (lyxerr.debugging())
987 textcache.show(lyxerr, "Expose delete all");
989 } else if (heightChange) {
990 // Rebuild image of current screen
992 // fitCursor() ensures we don't jump back
993 // to the start of the document on vertical
995 fitCursor(bv_->text);
997 // The main window size has changed, repaint most stuff
999 // ...including the minibuffer
1000 owner_->getMiniBuffer()->Init();
1003 screen_->Redraw(bv_->text, bv_);
1005 // Grey box when we don't have a buffer
1006 workarea_->greyOut();
1009 // always make sure that the scrollbar is sane.
1011 owner_->updateLayoutChoice();
1016 void BufferView::Pimpl::update()
1018 if (screen_) screen_->Update(bv_->text, bv_);
1021 // Values used when calling update:
1023 // -2 - update, move sel_cursor if selection, fitcursor
1024 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1025 // 0 - update, move sel_cursor if selection, fitcursor
1026 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1027 // 3 - update, move sel_cursor if selection
1030 // a simple redraw of the parts that need refresh
1032 // move sel_cursor if selection -
1033 // the text's sel_cursor is moved if there is selection is progress
1036 // fitCursor() is called and the scrollbar updated
1039 // the buffer is marked dirty.
1048 // UPDATE_ONLY = UPDATE;
1049 // UPDATE_SELECT = UPDATE | SELECT;
1050 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1051 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1053 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1054 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1055 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1056 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1057 // update(3) -> update(1) -> update(1) -> update(SELECT)
1059 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1061 owner_->updateLayoutChoice();
1063 if (!text->selection && (f & SELECT)) {
1064 text->sel_cursor = text->cursor;
1067 text->FullRebreak(bv_);
1069 if (text->inset_owner) {
1070 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1071 bv_->updateInset(text->inset_owner, true);
1080 if (buffer_->isLyxClean()) {
1081 buffer_->markDirty();
1082 owner_->getMiniBuffer()->setTimer(4);
1084 buffer_->markDirty();
1090 // Callback for cursor timer
1091 void BufferView::Pimpl::cursorToggle()
1093 // Quite a nice place for asyncron Inset updating, isn't it?
1094 // Actually no! This is run even if no buffer exist... so (Lgb)
1096 cursor_timeout.restart();
1101 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1102 if (pid == -1) // error find out what is wrong
1103 ; // ignore it for now.
1105 sigchldhandler(pid, &status);
1107 updatelist.update(bv_);
1110 cursor_timeout.restart();
1114 if (!bv_->theLockingInset()) {
1115 screen_->CursorToggle(bv_->text, bv_);
1117 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1120 cursor_timeout.restart();
1124 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1126 if (!text->cursor.row()->previous())
1129 int y = text->first;
1130 if (text->inset_owner)
1131 y += bv_->text->first;
1132 Row * cursorrow = text->cursor.row();
1133 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1134 bv_->text->FinishUndo();
1135 // This is to allow jumping over large insets
1136 if ((cursorrow == text->cursor.row()))
1137 text->CursorUp(bv_);
1139 if (text->inset_owner ||
1140 text->cursor.row()->height() < workarea_->height())
1141 screen_->Draw(bv_->text, bv_,
1143 - text->cursor.row()->baseline()
1144 + text->cursor.row()->height()
1145 - workarea_->height() + 1 );
1150 void BufferView::Pimpl::cursorNext(LyXText * text)
1152 if (!text->cursor.row()->next())
1155 int y = text->first + workarea_->height();
1156 // if (text->inset_owner)
1157 // y += bv_->text->first;
1158 text->GetRowNearY(y);
1160 Row * cursorrow = text->cursor.row();
1161 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1162 bv_->text->FinishUndo();
1163 // This is to allow jumping over large insets
1164 if ((cursorrow == bv_->text->cursor.row()))
1165 text->CursorDown(bv_);
1167 if (text->inset_owner ||
1168 text->cursor.row()->height() < workarea_->height())
1169 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1170 text->cursor.row()->baseline());
1175 bool BufferView::Pimpl::available() const
1177 if (buffer_ && bv_->text) return true;
1182 void BufferView::Pimpl::beforeChange(LyXText * text)
1185 text->ClearSelection(bv_);
1189 void BufferView::Pimpl::savePosition(unsigned int i)
1191 if (i >= saved_positions_num)
1193 saved_positions[i] = Position(buffer_->fileName(),
1194 bv_->text->cursor.par()->id(),
1195 bv_->text->cursor.pos());
1197 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1201 void BufferView::Pimpl::restorePosition(unsigned int i)
1203 if (i >= saved_positions_num)
1206 string fname = saved_positions[i].filename;
1208 beforeChange(bv_->text);
1210 if (fname != buffer_->fileName()) {
1211 Buffer * b = bufferlist.exists(fname) ?
1212 bufferlist.getBuffer(fname) :
1213 bufferlist.loadLyXFile(fname); // don't ask, just load it
1214 if (b != 0 ) buffer(b);
1217 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1221 bv_->text->SetCursor(bv_, par,
1222 min(par->Last(), saved_positions[i].par_pos));
1223 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1225 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1229 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1231 if (i >= saved_positions_num)
1234 return !saved_positions[i].filename.empty();
1238 void BufferView::Pimpl::setState()
1240 if (!lyxrc.rtl_support)
1243 LyXText * text = bv_->getLyXText();
1244 if (text->real_current_font.isRightToLeft() &&
1245 text->real_current_font.latex() != LyXFont::ON) {
1246 if (owner_->getIntl()->primarykeymap)
1247 owner_->getIntl()->KeyMapSec();
1249 if (!owner_->getIntl()->primarykeymap)
1250 owner_->getIntl()->KeyMapPrim();
1255 void BufferView::Pimpl::insetSleep()
1257 if (bv_->theLockingInset() && !bv_->inset_slept) {
1258 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1259 bv_->theLockingInset()->InsetUnlock(bv_);
1260 bv_->inset_slept = true;
1265 void BufferView::Pimpl::insetWakeup()
1267 if (bv_->theLockingInset() && bv_->inset_slept) {
1268 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1269 bv_->inset_slept = false;
1274 void BufferView::Pimpl::insetUnlock()
1276 if (bv_->theLockingInset()) {
1277 if (!bv_->inset_slept)
1278 bv_->theLockingInset()->InsetUnlock(bv_);
1279 bv_->theLockingInset(0);
1280 bv_->text->FinishUndo();
1281 bv_->inset_slept = false;
1286 bool BufferView::Pimpl::focus() const
1288 return workarea_->hasFocus();
1292 void BufferView::Pimpl::focus(bool f)
1294 if (f) workarea_->setFocus();
1298 bool BufferView::Pimpl::active() const
1300 return workarea_->active();
1304 bool BufferView::Pimpl::belowMouse() const
1306 return workarea_->belowMouse();
1310 void BufferView::Pimpl::showCursor()
1313 screen_->ShowCursor(bv_->text, bv_);
1317 void BufferView::Pimpl::hideCursor()
1320 screen_->HideCursor();
1324 void BufferView::Pimpl::toggleSelection(bool b)
1327 screen_->ToggleSelection(bv_->text, bv_, b);
1331 void BufferView::Pimpl::toggleToggle()
1334 screen_->ToggleToggle(bv_->text, bv_);
1338 void BufferView::Pimpl::center()
1340 beforeChange(bv_->text);
1341 if (bv_->text->cursor.y() > static_cast<int>((workarea_->height() / 2))) {
1342 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_->height() / 2);
1344 screen_->Draw(bv_->text, bv_, 0);
1346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1351 void BufferView::Pimpl::pasteClipboard(bool asPara)
1353 if (!buffer_) return;
1355 screen_->HideCursor();
1356 beforeChange(bv_->text);
1358 string const clip(workarea_->getClipboard());
1360 if (clip.empty()) return;
1363 bv_->text->InsertStringB(bv_, clip);
1365 bv_->text->InsertStringA(bv_, clip);
1367 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1371 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1373 workarea_->putClipboard(stuff);
1378 * Dispatch functions for actions which can be valid for BufferView->text
1379 * and/or InsetText->text!!!
1381 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1384 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1386 if (selecting || TEXT(bv_)->mark_set) {
1387 TEXT(bv_)->SetSelection(bv_);
1388 if (TEXT(bv_)->bv_owner)
1389 bv_->toggleToggle();
1391 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1394 /* ---> Everytime the cursor is moved, show the current font state. */
1395 // should this too me moved out of this func?
1396 //owner->showState();
1401 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1403 LyXCursor cursor = TEXT(bv_)->cursor;
1404 Buffer::inset_iterator it =
1405 find_if(Buffer::inset_iterator(
1406 cursor.par(), cursor.pos()),
1407 buffer_->inset_iterator_end(),
1408 compare_memfun(&Inset::LyxCode, code)
1410 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1414 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1416 string filename = filen;
1418 if (filename.empty()) {
1419 // Launch a file browser
1420 string initpath = lyxrc.document_path;
1424 string const trypath = owner_->buffer()->filepath;
1425 // If directory is writeable, use this as default.
1426 if (IsDirWriteable(trypath) == 1)
1432 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
1433 fileDlg.SetButton(1, _("Examples"),
1434 AddPath(system_lyxdir, "examples"));
1435 filename = fileDlg.Select(_("Select Document to Insert"),
1439 // check selected filename
1440 if (filename.empty()) {
1441 owner_->getMiniBuffer()->Set(_("Canceled."));
1446 // get absolute path of file and make sure the filename ends
1448 filename = MakeAbsPath(filename);
1449 if (!IsLyXFilename(filename))
1453 owner_->getMiniBuffer()->Set(_("Inserting document"),
1454 MakeDisplayPath(filename), "...");
1455 bool const res = bv_->insertLyXFile(filename);
1457 owner_->getMiniBuffer()->Set(_("Document"),
1458 MakeDisplayPath(filename),
1461 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1462 MakeDisplayPath(filename));
1467 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1470 // --- Misc -------------------------------------------
1473 TEXT(bv_)->toggleAppendix(bv_);
1474 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1478 case LFUN_TOC_INSERT:
1479 case LFUN_LOA_INSERT:
1480 case LFUN_LOF_INSERT:
1481 case LFUN_LOT_INSERT:
1483 InsetCommandParams p;
1485 if (action == LFUN_TOC_INSERT )
1486 p.setCmdName( "tableofcontents" );
1487 else if (action == LFUN_LOA_INSERT )
1488 p.setCmdName( "listofalgorithms" );
1489 else if (action == LFUN_LOF_INSERT )
1490 p.setCmdName( "listoffigures" );
1492 p.setCmdName( "listoftables" );
1494 Inset * inset = new InsetTOC( p );
1495 if (!bv_->insertInset( inset, "Standard", true ) )
1500 case LFUN_TABULAR_FEATURE:
1501 case LFUN_SCROLL_INSET:
1502 // this is not handled here as this funktion is only aktive
1503 // if we have a locking_inset and that one is (or contains)
1507 case LFUN_INSET_GRAPHICS:
1509 Inset * new_inset = new InsetGraphics;
1510 if (!bv_->insertInset(new_inset)) {
1513 // this is need because you don't use a inset->Edit()
1514 bv_->updateInset(new_inset, true);
1515 new_inset->Edit(bv_, 0, 0, 0);
1525 case LFUN_PASTESELECTION:
1527 bool asPara = false;
1528 if (argument == "paragraph") asPara = true;
1529 pasteClipboard(asPara);
1541 case LFUN_LAYOUT_COPY:
1542 bv_->copyEnvironment();
1545 case LFUN_LAYOUT_PASTE:
1546 bv_->pasteEnvironment();
1550 case LFUN_GOTOERROR:
1551 bv_->gotoInset(Inset::ERROR_CODE, false);
1555 bv_->gotoInset(Inset::IGNORE_CODE, false);
1558 case LFUN_REFERENCE_GOTO:
1560 vector<Inset::Code> tmp;
1561 tmp.push_back(Inset::LABEL_CODE);
1562 tmp.push_back(Inset::REF_CODE);
1563 bv_->gotoInset(tmp, true);
1567 case LFUN_HYPHENATION:
1568 bv_->hyphenationPoint();
1575 case LFUN_END_OF_SENTENCE:
1576 bv_->endOfSentenceDot();
1579 case LFUN_MENU_SEPARATOR:
1580 bv_->menuSeparator();
1588 changeDepth(bv_, TEXT(bv_), 0);
1591 case LFUN_DEPTH_MIN:
1592 changeDepth(bv_, TEXT(bv_), -1);
1595 case LFUN_DEPTH_PLUS:
1596 changeDepth(bv_, TEXT(bv_), 1);
1600 owner_->getDialogs()->setUserFreeFont();
1606 owner_->showState();
1609 case LFUN_FILE_INSERT:
1611 MenuInsertLyXFile(argument);
1615 case LFUN_FILE_INSERT_ASCII:
1617 bool asPara = (argument == "paragraph");
1618 InsertAsciiFile(bv_, string(), asPara);
1624 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1625 << argument << endl;
1627 // Derive layout number from given argument (string)
1628 // and current buffer's textclass (number). */
1629 LyXTextClassList::ClassList::size_type tclass =
1630 buffer_->params.textclass;
1631 pair <bool, LyXTextClass::size_type> layout =
1632 textclasslist.NumberOfLayout(tclass, argument);
1634 // If the entry is obsolete, use the new one instead.
1636 string obs = textclasslist.Style(tclass,layout.second)
1640 textclasslist.NumberOfLayout(tclass, obs);
1643 // see if we found the layout number:
1644 if (!layout.first) {
1645 owner_->getLyXFunc()->setErrorMessage(
1646 string(N_("Layout ")) + argument +
1651 if (current_layout != layout.second) {
1653 current_layout = layout.second;
1655 BufferView::SELECT|BufferView::FITCUR);
1656 TEXT(bv_)->SetLayout(bv_, layout.second);
1657 owner_->setLayout(layout.second);
1659 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1666 Lang(bv_, argument);
1668 owner_->showState();
1673 owner_->showState();
1678 owner_->showState();
1683 owner_->showState();
1688 owner_->showState();
1693 owner_->showState();
1698 owner_->showState();
1703 owner_->showState();
1706 case LFUN_UNDERLINE:
1708 owner_->showState();
1711 case LFUN_FONT_SIZE:
1712 FontSize(bv_, argument);
1713 owner_->showState();
1716 case LFUN_FONT_STATE:
1717 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1720 case LFUN_UPCASE_WORD:
1721 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1722 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1723 if (TEXT(bv_)->inset_owner)
1724 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1725 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1728 case LFUN_LOWCASE_WORD:
1729 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1730 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1731 if (TEXT(bv_)->inset_owner)
1732 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1733 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1736 case LFUN_CAPITALIZE_WORD:
1737 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1738 TEXT(bv_)->ChangeWordCase(bv_,
1739 LyXText::text_capitalization);
1740 if (TEXT(bv_)->inset_owner)
1741 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1742 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1745 case LFUN_INSERT_LABEL:
1746 MenuInsertLabel(bv_, argument);
1749 case LFUN_REF_INSERT:
1750 if (argument.empty()) {
1751 InsetCommandParams p("ref");
1752 owner_->getDialogs()->createRef(p.getAsString());
1754 InsetCommandParams p;
1755 p.setFromString(argument);
1757 InsetRef * inset = new InsetRef(p, *buffer_);
1758 if (!bv_->insertInset(inset))
1761 bv_->updateInset(inset, true);
1765 case LFUN_BOOKMARK_SAVE:
1766 savePosition(strToUnsignedInt(argument));
1769 case LFUN_BOOKMARK_GOTO:
1770 restorePosition(strToUnsignedInt(argument));
1775 string label(argument);
1776 if (label.empty()) {
1778 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1780 label = inset->getContents();
1785 if (!label.empty()) {
1786 //bv_->savePosition(0);
1787 if (!bv_->gotoLabel(label))
1788 WriteAlert(_("Error"),
1789 _("Couldn't find this label"),
1790 _("in current document."));
1795 // --- Cursor Movements -----------------------------
1798 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1799 if (!TEXT(bv_)->mark_set)
1800 beforeChange(TEXT(bv_));
1801 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1803 TEXT(bv_)->CursorLeft(bv_, false);
1804 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1805 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1806 == LyXParagraph::META_INSET
1807 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1808 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1809 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1810 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1814 TEXT(bv_)->GetFont(buffer_,
1815 TEXT(bv_)->cursor.par(),
1816 TEXT(bv_)->cursor.pos());
1817 y = tmpinset->descent(bv_,font);
1819 tmpinset->Edit(bv_, 0, y, 0);
1823 TEXT(bv_)->CursorRight(bv_, false);
1824 TEXT(bv_)->FinishUndo();
1825 moveCursorUpdate(false);
1826 owner_->showState();
1832 // This is soooo ugly. Isn`t it possible to make
1833 // it simpler? (Lgb)
1834 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1835 if (!TEXT(bv_)->mark_set)
1836 beforeChange(TEXT(bv_));
1837 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1838 LyXCursor cur = TEXT(bv_)->cursor;
1840 TEXT(bv_)->CursorLeft(bv_, false);
1841 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1842 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1843 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1844 LyXParagraph::META_INSET) &&
1845 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1846 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1847 == Inset::HIGHLY_EDITABLE))
1849 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1850 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1851 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1852 TEXT(bv_)->cursor.par(),
1853 TEXT(bv_)->cursor.pos());
1855 : tmpinset->descent(bv_,font);
1858 tmpinset->width(bv_,font),
1863 TEXT(bv_)->CursorRight(bv_, false);
1865 TEXT(bv_)->FinishUndo();
1866 moveCursorUpdate(false);
1867 owner_->showState();
1872 if (!TEXT(bv_)->mark_set)
1873 beforeChange(TEXT(bv_));
1874 update(TEXT(bv_), BufferView::UPDATE);
1875 TEXT(bv_)->CursorUp(bv_);
1876 TEXT(bv_)->FinishUndo();
1877 moveCursorUpdate(false);
1878 owner_->showState();
1882 if (!TEXT(bv_)->mark_set)
1883 beforeChange(TEXT(bv_));
1884 update(TEXT(bv_), BufferView::UPDATE);
1885 TEXT(bv_)->CursorDown(bv_);
1886 TEXT(bv_)->FinishUndo();
1887 moveCursorUpdate(false);
1888 owner_->showState();
1891 case LFUN_UP_PARAGRAPH:
1892 if (!TEXT(bv_)->mark_set)
1893 beforeChange(TEXT(bv_));
1894 update(TEXT(bv_), BufferView::UPDATE);
1895 TEXT(bv_)->CursorUpParagraph(bv_);
1896 TEXT(bv_)->FinishUndo();
1897 moveCursorUpdate(false);
1898 owner_->showState();
1901 case LFUN_DOWN_PARAGRAPH:
1902 if (!TEXT(bv_)->mark_set)
1903 beforeChange(TEXT(bv_));
1904 update(TEXT(bv_), BufferView::UPDATE);
1905 TEXT(bv_)->CursorDownParagraph(bv_);
1906 TEXT(bv_)->FinishUndo();
1907 moveCursorUpdate(false);
1908 owner_->showState();
1912 if (!TEXT(bv_)->mark_set)
1913 beforeChange(TEXT(bv_));
1914 update(TEXT(bv_), BufferView::UPDATE);
1915 cursorPrevious(TEXT(bv_));
1916 TEXT(bv_)->FinishUndo();
1917 moveCursorUpdate(false);
1918 owner_->showState();
1922 if (!TEXT(bv_)->mark_set)
1923 beforeChange(TEXT(bv_));
1924 update(TEXT(bv_), BufferView::UPDATE);
1925 cursorNext(TEXT(bv_));
1926 TEXT(bv_)->FinishUndo();
1927 moveCursorUpdate(false);
1928 owner_->showState();
1932 if (!TEXT(bv_)->mark_set)
1933 beforeChange(TEXT(bv_));
1934 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1935 TEXT(bv_)->CursorHome(bv_);
1936 TEXT(bv_)->FinishUndo();
1937 moveCursorUpdate(false);
1938 owner_->showState();
1942 if (!TEXT(bv_)->mark_set)
1943 beforeChange(TEXT(bv_));
1945 BufferView::SELECT|BufferView::FITCUR);
1946 TEXT(bv_)->CursorEnd(bv_);
1947 TEXT(bv_)->FinishUndo();
1948 moveCursorUpdate(false);
1949 owner_->showState();
1952 case LFUN_SHIFT_TAB:
1954 if (!TEXT(bv_)->mark_set)
1955 beforeChange(TEXT(bv_));
1957 BufferView::SELECT|BufferView::FITCUR);
1958 TEXT(bv_)->CursorTab(bv_);
1959 TEXT(bv_)->FinishUndo();
1960 moveCursorUpdate(false);
1961 owner_->showState();
1964 case LFUN_WORDRIGHT:
1965 if (!TEXT(bv_)->mark_set)
1966 beforeChange(TEXT(bv_));
1967 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1968 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1969 TEXT(bv_)->CursorLeftOneWord(bv_);
1971 TEXT(bv_)->CursorRightOneWord(bv_);
1972 TEXT(bv_)->FinishUndo();
1973 moveCursorUpdate(false);
1974 owner_->showState();
1978 if (!TEXT(bv_)->mark_set)
1979 beforeChange(TEXT(bv_));
1980 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1981 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
1982 TEXT(bv_)->CursorRightOneWord(bv_);
1984 TEXT(bv_)->CursorLeftOneWord(bv_);
1985 TEXT(bv_)->FinishUndo();
1986 moveCursorUpdate(false);
1987 owner_->showState();
1990 case LFUN_BEGINNINGBUF:
1991 if (!TEXT(bv_)->mark_set)
1992 beforeChange(TEXT(bv_));
1994 BufferView::SELECT|BufferView::FITCUR);
1995 TEXT(bv_)->CursorTop(bv_);
1996 TEXT(bv_)->FinishUndo();
1997 moveCursorUpdate(false);
1998 owner_->showState();
2002 if (!TEXT(bv_)->mark_set)
2003 beforeChange(TEXT(bv_));
2005 BufferView::SELECT|BufferView::FITCUR);
2006 TEXT(bv_)->CursorBottom(bv_);
2007 TEXT(bv_)->FinishUndo();
2008 moveCursorUpdate(false);
2009 owner_->showState();
2013 /* cursor selection ---------------------------- */
2016 BufferView::SELECT|BufferView::FITCUR);
2017 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2018 TEXT(bv_)->CursorLeft(bv_);
2020 TEXT(bv_)->CursorRight(bv_);
2021 TEXT(bv_)->FinishUndo();
2022 moveCursorUpdate(true);
2023 owner_->showState();
2028 BufferView::SELECT|BufferView::FITCUR);
2029 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2030 TEXT(bv_)->CursorRight(bv_);
2032 TEXT(bv_)->CursorLeft(bv_);
2033 TEXT(bv_)->FinishUndo();
2034 moveCursorUpdate(true);
2035 owner_->showState();
2040 BufferView::SELECT|BufferView::FITCUR);
2041 TEXT(bv_)->CursorUp(bv_);
2042 TEXT(bv_)->FinishUndo();
2043 moveCursorUpdate(true);
2044 owner_->showState();
2049 BufferView::SELECT|BufferView::FITCUR);
2050 TEXT(bv_)->CursorDown(bv_);
2051 TEXT(bv_)->FinishUndo();
2052 moveCursorUpdate(true);
2053 owner_->showState();
2056 case LFUN_UP_PARAGRAPHSEL:
2058 BufferView::SELECT|BufferView::FITCUR);
2059 TEXT(bv_)->CursorUpParagraph(bv_);
2060 TEXT(bv_)->FinishUndo();
2061 moveCursorUpdate(true);
2062 owner_->showState();
2065 case LFUN_DOWN_PARAGRAPHSEL:
2067 BufferView::SELECT|BufferView::FITCUR);
2068 TEXT(bv_)->CursorDownParagraph(bv_);
2069 TEXT(bv_)->FinishUndo();
2070 moveCursorUpdate(true);
2071 owner_->showState();
2075 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2076 cursorPrevious(TEXT(bv_));
2077 TEXT(bv_)->FinishUndo();
2078 moveCursorUpdate(true);
2079 owner_->showState();
2083 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2084 cursorNext(TEXT(bv_));
2085 TEXT(bv_)->FinishUndo();
2086 moveCursorUpdate(true);
2087 owner_->showState();
2091 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2092 TEXT(bv_)->CursorHome(bv_);
2093 TEXT(bv_)->FinishUndo();
2094 moveCursorUpdate(true);
2095 owner_->showState();
2099 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2100 TEXT(bv_)->CursorEnd(bv_);
2101 TEXT(bv_)->FinishUndo();
2102 moveCursorUpdate(true);
2103 owner_->showState();
2106 case LFUN_WORDRIGHTSEL:
2107 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2108 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2109 TEXT(bv_)->CursorLeftOneWord(bv_);
2111 TEXT(bv_)->CursorRightOneWord(bv_);
2112 TEXT(bv_)->FinishUndo();
2113 moveCursorUpdate(true);
2114 owner_->showState();
2117 case LFUN_WORDLEFTSEL:
2118 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2119 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2120 TEXT(bv_)->CursorRightOneWord(bv_);
2122 TEXT(bv_)->CursorLeftOneWord(bv_);
2123 TEXT(bv_)->FinishUndo();
2124 moveCursorUpdate(true);
2125 owner_->showState();
2128 case LFUN_BEGINNINGBUFSEL:
2129 if (TEXT(bv_)->inset_owner)
2131 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2132 TEXT(bv_)->CursorTop(bv_);
2133 TEXT(bv_)->FinishUndo();
2134 moveCursorUpdate(true);
2135 owner_->showState();
2138 case LFUN_ENDBUFSEL:
2139 if (TEXT(bv_)->inset_owner)
2142 BufferView::SELECT|BufferView::FITCUR);
2143 TEXT(bv_)->CursorBottom(bv_);
2144 TEXT(bv_)->FinishUndo();
2145 moveCursorUpdate(true);
2146 owner_->showState();
2149 // --- text changing commands ------------------------
2150 case LFUN_BREAKLINE:
2151 beforeChange(TEXT(bv_));
2152 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2154 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2155 moveCursorUpdate(false);
2158 case LFUN_PROTECTEDSPACE:
2160 LyXLayout const & style =
2161 textclasslist.Style(buffer_->params.textclass,
2162 TEXT(bv_)->cursor.par()->GetLayout());
2164 if (style.free_spacing) {
2165 TEXT(bv_)->InsertChar(bv_, ' ');
2166 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2168 bv_->protectedBlank(TEXT(bv_));
2170 moveCursorUpdate(false);
2175 if (TEXT(bv_)->mark_set) {
2176 beforeChange(TEXT(bv_));
2177 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2178 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2180 beforeChange(TEXT(bv_));
2181 TEXT(bv_)->mark_set = 1;
2182 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2183 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2185 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2189 if (!TEXT(bv_)->selection) {
2190 TEXT(bv_)->Delete(bv_);
2191 TEXT(bv_)->sel_cursor =
2194 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2195 // It is possible to make it a lot faster still
2196 // just comment out the line below...
2201 moveCursorUpdate(false);
2202 owner_->showState();
2206 case LFUN_DELETE_SKIP:
2208 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2210 LyXCursor cursor = TEXT(bv_)->cursor;
2212 if (!TEXT(bv_)->selection) {
2213 if (cursor.pos() == cursor.par()->Last()) {
2214 TEXT(bv_)->CursorRight(bv_);
2215 cursor = TEXT(bv_)->cursor;
2216 if (cursor.pos() == 0
2217 && !(cursor.par()->added_space_top
2218 == VSpace (VSpace::NONE))) {
2219 TEXT(bv_)->SetParagraph
2221 cursor.par()->line_top,
2222 cursor.par()->line_bottom,
2223 cursor.par()->pagebreak_top,
2224 cursor.par()->pagebreak_bottom,
2225 VSpace(VSpace::NONE),
2226 cursor.par()->added_space_bottom,
2227 cursor.par()->align,
2228 cursor.par()->labelwidthstring, 0);
2229 TEXT(bv_)->CursorLeft(bv_);
2231 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2233 TEXT(bv_)->CursorLeft(bv_);
2234 TEXT(bv_)->Delete(bv_);
2235 TEXT(bv_)->sel_cursor =
2238 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2241 TEXT(bv_)->Delete(bv_);
2242 TEXT(bv_)->sel_cursor =
2245 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2253 /* -------> Delete word forward. */
2254 case LFUN_DELETE_WORD_FORWARD:
2255 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2256 TEXT(bv_)->DeleteWordForward(bv_);
2257 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2258 moveCursorUpdate(false);
2259 owner_->showState();
2262 /* -------> Delete word backward. */
2263 case LFUN_DELETE_WORD_BACKWARD:
2264 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2265 TEXT(bv_)->DeleteWordBackward(bv_);
2266 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2267 moveCursorUpdate(false);
2268 owner_->showState();
2271 /* -------> Kill to end of line. */
2272 case LFUN_DELETE_LINE_FORWARD:
2273 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2274 TEXT(bv_)->DeleteLineForward(bv_);
2275 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2276 moveCursorUpdate(false);
2279 /* -------> Set mark off. */
2281 beforeChange(TEXT(bv_));
2282 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2283 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2284 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2287 /* -------> Set mark on. */
2289 beforeChange(TEXT(bv_));
2290 TEXT(bv_)->mark_set = 1;
2291 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2292 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2293 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2296 case LFUN_BACKSPACE:
2298 if (!TEXT(bv_)->selection) {
2299 if (owner_->getIntl()->getTrans().backspace()) {
2300 TEXT(bv_)->Backspace(bv_);
2301 TEXT(bv_)->sel_cursor =
2304 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2305 // It is possible to make it a lot faster still
2306 // just comment out the line below...
2312 owner_->showState();
2317 case LFUN_BACKSPACE_SKIP:
2319 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2321 LyXCursor cursor = TEXT(bv_)->cursor;
2323 if (!TEXT(bv_)->selection) {
2324 if (cursor.pos() == 0
2325 && !(cursor.par()->added_space_top
2326 == VSpace (VSpace::NONE))) {
2327 TEXT(bv_)->SetParagraph
2329 cursor.par()->line_top,
2330 cursor.par()->line_bottom,
2331 cursor.par()->pagebreak_top,
2332 cursor.par()->pagebreak_bottom,
2333 VSpace(VSpace::NONE), cursor.par()->added_space_bottom,
2334 cursor.par()->align,
2335 cursor.par()->labelwidthstring, 0);
2337 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2339 TEXT(bv_)->Backspace(bv_);
2340 TEXT(bv_)->sel_cursor
2343 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2350 case LFUN_BREAKPARAGRAPH:
2352 beforeChange(TEXT(bv_));
2353 TEXT(bv_)->BreakParagraph(bv_, 0);
2355 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2356 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2358 owner_->showState();
2362 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2364 beforeChange(TEXT(bv_));
2365 TEXT(bv_)->BreakParagraph(bv_, 1);
2367 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2368 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2370 owner_->showState();
2374 case LFUN_BREAKPARAGRAPH_SKIP:
2376 // When at the beginning of a paragraph, remove
2377 // indentation and add a "defskip" at the top.
2378 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2380 LyXCursor cursor = TEXT(bv_)->cursor;
2382 beforeChange(TEXT(bv_));
2383 if (cursor.pos() == 0) {
2384 if (cursor.par()->added_space_top == VSpace(VSpace::NONE)) {
2385 TEXT(bv_)->SetParagraph
2387 cursor.par()->line_top,
2388 cursor.par()->line_bottom,
2389 cursor.par()->pagebreak_top,
2390 cursor.par()->pagebreak_bottom,
2391 VSpace(VSpace::DEFSKIP), cursor.par()->added_space_bottom,
2392 cursor.par()->align,
2393 cursor.par()->labelwidthstring, 1);
2394 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2398 TEXT(bv_)->BreakParagraph(bv_, 0);
2399 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2403 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2404 TEXT(bv_)->sel_cursor = cursor;
2406 owner_->showState();
2410 case LFUN_PARAGRAPH_SPACING:
2412 LyXParagraph * par = TEXT(bv_)->cursor.par();
2413 Spacing::Space cur_spacing = par->spacing.getSpace();
2414 float cur_value = 1.0;
2415 if (cur_spacing == Spacing::Other) {
2416 cur_value = par->spacing.getValue();
2419 istringstream istr(argument.c_str());
2423 Spacing::Space new_spacing = cur_spacing;
2424 float new_value = cur_value;
2426 lyxerr << "Missing argument to `paragraph-spacing'"
2428 } else if (tmp == "single") {
2429 new_spacing = Spacing::Single;
2430 } else if (tmp == "onehalf") {
2431 new_spacing = Spacing::Onehalf;
2432 } else if (tmp == "double") {
2433 new_spacing = Spacing::Double;
2434 } else if (tmp == "other") {
2435 new_spacing = Spacing::Other;
2438 lyxerr << "new_value = " << tmpval << endl;
2441 } else if (tmp == "default") {
2442 new_spacing = Spacing::Default;
2444 lyxerr << _("Unknown spacing argument: ")
2445 << argument << endl;
2447 if (cur_spacing != new_spacing || cur_value != new_value) {
2448 par->spacing.set(new_spacing, new_value);
2449 TEXT(bv_)->RedoParagraph(bv_);
2451 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2457 beforeChange(TEXT(bv_));
2458 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2459 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2460 moveCursorUpdate(false);
2466 InsetCommandParams p;
2467 if (action == LFUN_HTMLURL)
2468 p.setCmdName("htmlurl");
2470 p.setCmdName("url");
2471 owner_->getDialogs()->createUrl( p.getAsString() );
2475 case LFUN_INSERT_URL:
2477 InsetCommandParams p;
2478 p.setFromString( argument );
2480 InsetUrl * inset = new InsetUrl( p );
2481 if (!bv_->insertInset(inset))
2484 bv_->updateInset( inset, true );
2488 case LFUN_INSET_TEXT:
2490 InsetText * new_inset = new InsetText;
2491 if (bv_->insertInset(new_inset))
2492 new_inset->Edit(bv_, 0, 0, 0);
2498 case LFUN_INSET_ERT:
2500 InsetERT * new_inset = new InsetERT;
2501 if (bv_->insertInset(new_inset))
2502 new_inset->Edit(bv_, 0, 0, 0);
2508 case LFUN_INSET_EXTERNAL:
2510 InsetExternal * new_inset = new InsetExternal;
2511 if (bv_->insertInset(new_inset))
2512 new_inset->Edit(bv_, 0, 0, 0);
2518 case LFUN_INSET_FOOTNOTE:
2520 InsetFoot * new_inset = new InsetFoot;
2521 if (bv_->insertInset(new_inset))
2522 new_inset->Edit(bv_, 0, 0, 0);
2528 case LFUN_INSET_MARGINAL:
2530 InsetMarginal * new_inset = new InsetMarginal;
2531 if (bv_->insertInset(new_inset))
2532 new_inset->Edit(bv_, 0, 0, 0);
2538 case LFUN_INSET_MINIPAGE:
2540 InsetMinipage * new_inset = new InsetMinipage;
2541 if (bv_->insertInset(new_inset))
2542 new_inset->Edit(bv_, 0, 0, 0);
2548 case LFUN_INSET_FLOAT:
2550 // check if the float type exist
2551 if (floatList.typeExist(argument)) {
2552 InsetFloat * new_inset = new InsetFloat(argument);
2553 if (bv_->insertInset(new_inset))
2554 new_inset->Edit(bv_, 0, 0, 0);
2558 lyxerr << "Non-existant float type: "
2559 << argument << endl;
2565 case LFUN_INSET_LIST:
2567 InsetList * new_inset = new InsetList;
2568 if (bv_->insertInset(new_inset))
2569 new_inset->Edit(bv_, 0, 0, 0);
2575 case LFUN_INSET_THEOREM:
2577 InsetTheorem * new_inset = new InsetTheorem;
2578 if (bv_->insertInset(new_inset))
2579 new_inset->Edit(bv_, 0, 0, 0);
2585 case LFUN_INSET_CAPTION:
2587 // Do we have a locking inset...
2588 if (bv_->theLockingInset()) {
2589 lyxerr << "Locking inset code: "
2590 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2591 InsetCaption * new_inset = new InsetCaption;
2592 new_inset->setOwner(bv_->theLockingInset());
2593 new_inset->SetAutoBreakRows(true);
2594 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2595 new_inset->SetFrameColor(0, LColor::footnoteframe);
2596 if (bv_->insertInset(new_inset))
2597 new_inset->Edit(bv_, 0, 0, 0);
2604 case LFUN_INSET_TABULAR:
2607 if (!argument.empty())
2608 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2609 InsetTabular * new_inset =
2610 new InsetTabular(*buffer_, r, c);
2612 TEXT(bv_)->real_current_font.isRightToLeft();
2613 if (!bv_->open_new_inset(new_inset, rtl))
2618 // --- lyxserver commands ----------------------------
2620 case LFUN_CHARATCURSOR:
2622 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2623 if (pos < TEXT(bv_)->cursor.par()->size())
2624 owner_->getLyXFunc()->setMessage(
2625 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2627 owner_->getLyXFunc()->setMessage("EOF");
2632 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2634 + tostr(TEXT(bv_)->cursor.y()));
2641 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2642 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2646 case LFUN_GETLAYOUT:
2647 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2652 LyXFont & font = TEXT(bv_)->current_font;
2653 if (font.shape() == LyXFont::ITALIC_SHAPE)
2654 owner_->getLyXFunc()->setMessage("E");
2655 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2656 owner_->getLyXFunc()->setMessage("N");
2658 owner_->getLyXFunc()->setMessage("0");
2665 LyXFont & font = TEXT(bv_)->current_font;
2666 if (font.latex() == LyXFont::ON)
2667 owner_->getLyXFunc()->setMessage("L");
2669 owner_->getLyXFunc()->setMessage("0");
2673 // --- accented characters ---------------------------
2676 case LFUN_CIRCUMFLEX:
2686 case LFUN_SPECIAL_CARON:
2689 case LFUN_HUNG_UMLAUT:
2692 owner_->getLyXFunc()->handleKeyFunc(action);
2695 // --- insert characters ----------------------------------------
2697 case LFUN_MATH_DELIM:
2698 case LFUN_INSERT_MATRIX:
2701 if (bv_->open_new_inset(new InsetFormula(false)))
2703 bv_->theLockingInset()
2704 ->LocalDispatch(bv_, action, argument);
2710 case LFUN_INSERT_MATH:
2712 math_insert_symbol(bv_, argument);
2716 case LFUN_MATH_DISPLAY:
2719 bv_->open_new_inset(new InsetFormula(true));
2723 case LFUN_MATH_MACRO:
2728 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2730 string const s1 = token(s, ' ', 1);
2731 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2732 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2738 case LFUN_MATH_MODE: // Open or create a math inset
2741 bv_->open_new_inset(new InsetFormula);
2742 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2746 case LFUN_CITATION_INSERT:
2748 InsetCommandParams p;
2749 p.setFromString( argument );
2751 InsetCitation * inset = new InsetCitation( p );
2752 if (!bv_->insertInset(inset))
2755 bv_->updateInset( inset, true );
2759 case LFUN_INSERT_BIBTEX:
2761 // ale970405+lasgoutt970425
2762 // The argument can be up to two tokens separated
2763 // by a space. The first one is the bibstyle.
2764 string const db = token(argument, ' ', 0);
2765 string bibstyle = token(argument, ' ', 1);
2766 if (bibstyle.empty())
2769 InsetCommandParams p( "BibTeX", db, bibstyle );
2770 InsetBibtex * inset = new InsetBibtex(p);
2772 if (bv_->insertInset(inset)) {
2773 if (argument.empty())
2774 inset->Edit(bv_, 0, 0, 0);
2780 // BibTeX data bases
2781 case LFUN_BIBDB_ADD:
2783 InsetBibtex * inset =
2784 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2786 inset->addDatabase(argument);
2791 case LFUN_BIBDB_DEL:
2793 InsetBibtex * inset =
2794 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2796 inset->delDatabase(argument);
2801 case LFUN_BIBTEX_STYLE:
2803 InsetBibtex * inset =
2804 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2806 inset->setOptions(argument);
2811 case LFUN_INDEX_CREATE:
2813 InsetCommandParams p( "index" );
2815 if (argument.empty()) {
2816 // Get the word immediately preceding the cursor
2817 LyXParagraph::size_type curpos =
2818 TEXT(bv_)->cursor.pos() - 1;
2822 curstring = TEXT(bv_)
2823 ->cursor.par()->GetWord(curpos);
2825 p.setContents( curstring );
2827 p.setContents( argument );
2830 owner_->getDialogs()->createIndex( p.getAsString() );
2834 case LFUN_INDEX_INSERT:
2836 InsetCommandParams p;
2837 p.setFromString(argument);
2838 InsetIndex * inset = new InsetIndex(p);
2840 if (!bv_->insertInset(inset))
2843 bv_->updateInset(inset, true);
2847 case LFUN_INDEX_INSERT_LAST:
2849 // Get word immediately preceding the cursor
2850 LyXParagraph::size_type curpos =
2851 TEXT(bv_)->cursor.pos() - 1;
2852 // Can't do that at the beginning of a paragraph
2853 if (curpos < 0) break;
2855 string const curstring(TEXT(bv_)
2856 ->cursor.par()->GetWord(curpos));
2858 InsetCommandParams p("index", curstring);
2859 InsetIndex * inset = new InsetIndex(p);
2861 if (!bv_->insertInset(inset))
2864 bv_->updateInset(inset, true);
2868 case LFUN_INDEX_PRINT:
2870 InsetCommandParams p("printindex");
2871 Inset * inset = new InsetPrintIndex(p);
2872 if (!bv_->insertInset(inset, "Standard", true))
2877 case LFUN_PARENTINSERT:
2879 lyxerr << "arg " << argument << endl;
2880 InsetCommandParams p( "lyxparent", argument );
2881 Inset * inset = new InsetParent(p, *buffer_);
2882 if (!bv_->insertInset(inset, "Standard", true))
2887 case LFUN_CHILD_INSERT:
2889 InsetCommandParams p;
2890 p.setFromString(argument);
2892 InsetInclude * inset = new InsetInclude(p, *buffer_);
2893 if (!bv_->insertInset(inset))
2896 bv_->updateInset(inset, true);
2900 case LFUN_INSERT_NOTE:
2904 case LFUN_SELFINSERT:
2906 LyXFont const old_font(TEXT(bv_)->real_current_font);
2907 for (string::size_type i = 0; i < argument.length(); ++i) {
2908 TEXT(bv_)->InsertChar(bv_, argument[i]);
2909 // This needs to be in the loop, or else we
2910 // won't break lines correctly. (Asger)
2912 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2914 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2915 moveCursorUpdate(false);
2917 // real_current_font.number can change so we need to
2918 // update the minibuffer
2919 if (old_font != TEXT(bv_)->real_current_font)
2920 owner_->showState();
2924 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2928 time_t now_time_t = time(NULL);
2929 now_tm = localtime(&now_time_t);
2930 setlocale(LC_TIME, "");
2932 if (!argument.empty())
2935 arg = lyxrc.date_insert_format;
2937 int const datetmp_len =
2938 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2939 for (int i = 0; i < datetmp_len; i++) {
2940 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2942 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2945 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2946 moveCursorUpdate(false);
2950 case LFUN_UNKNOWN_ACTION:
2953 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2957 if (buffer_->isReadonly()) {
2958 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
2961 if (!argument.empty()) {
2962 /* Automatically delete the currently selected
2963 * text and replace it with what is being
2964 * typed in now. Depends on lyxrc settings
2965 * "auto_region_delete", which defaults to
2968 if (lyxrc.auto_region_delete) {
2969 if (TEXT(bv_)->selection){
2970 TEXT(bv_)->CutSelection(bv_, false);
2972 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2976 beforeChange(TEXT(bv_));
2977 LyXFont const old_font(TEXT(bv_)->real_current_font);
2978 for (string::size_type i = 0;
2979 i < argument.length(); ++i) {
2980 if (greek_kb_flag) {
2981 if (!math_insert_greek(bv_,
2983 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2985 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
2988 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2990 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2991 moveCursorUpdate(false);
2993 // real_current_font.number can change so we need to
2994 // update the minibuffer
2995 if (old_font != TEXT(bv_)->real_current_font)
2996 owner_->showState();
2998 // if we don't have an argument there was something
2999 // strange going on so we just tell this to someone!
3000 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));