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 void math_insert_symbol(BufferView *, string const &);
61 extern bool math_insert_greek(BufferView *, char);
62 extern int greek_kb_flag;
64 #ifdef SIGC_CXX_NAMESPACES
74 /* the selection possible is needed, that only motion events are
75 * used, where the bottom press event was on the drawing area too */
76 bool selection_possible = false;
78 extern BufferList bufferlist;
79 extern char ascii_type;
81 extern void sigchldhandler(pid_t pid, int * status);
82 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
84 const unsigned int saved_positions_num = 20;
89 XSync(fl_get_display(), 0);
94 void SetXtermCursor(Window win)
97 static bool cursor_undefined = true;
98 if (cursor_undefined){
99 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
100 XFlush(fl_get_display());
101 cursor_undefined = false;
103 XDefineCursor(fl_get_display(), win, cursor);
104 XFlush(fl_get_display());
108 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
109 int xpos, int ypos, int width, int height)
110 : bv_(b), owner_(o), buffer_(0),
111 current_scrollbar_value(0), cursor_timeout(400),
112 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
115 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
116 workarea_.workAreaExpose
117 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
118 workarea_.workAreaEnter
119 .connect(slot(this, &BufferView::Pimpl::enterView));
120 workarea_.workAreaLeave
121 .connect(slot(this, &BufferView::Pimpl::leaveView));
122 workarea_.workAreaButtonPress
123 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
124 workarea_.workAreaButtonRelease
126 &BufferView::Pimpl::workAreaButtonRelease));
127 workarea_.workAreaMotionNotify
128 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
129 workarea_.workAreaDoubleClick
130 .connect(slot(this, &BufferView::Pimpl::doubleClick));
131 workarea_.workAreaTripleClick
132 .connect(slot(this, &BufferView::Pimpl::tripleClick));
133 workarea_.workAreaKeyPress
134 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
138 cursor_timeout.timeout.connect(slot(this,
139 &BufferView::Pimpl::cursorToggle));
140 //current_scrollbar_value = 0;
141 cursor_timeout.start();
142 workarea_.setFocus();
143 //using_xterm_cursor = false;
144 saved_positions.resize(saved_positions_num);
148 Painter & BufferView::Pimpl::painter()
150 return workarea_.getPainter();
154 void BufferView::Pimpl::buffer(Buffer * b)
156 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
160 buffer_->delUser(bv_);
162 // Put the old text into the TextCache, but
163 // only if the buffer is still loaded.
164 // Also set the owner of the test to 0
165 // bv_->text->owner(0);
166 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
167 if (lyxerr.debugging())
168 textcache.show(lyxerr, "BufferView::buffer");
173 // Set current buffer
176 if (bufferlist.getState() == BufferList::CLOSING) return;
179 // screen is always deleted when the buffer is changed.
184 // If we are closing the buffer, use the first buffer as current
186 buffer_ = bufferlist.first();
190 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
191 buffer_->addUser(bv_);
192 // If we don't have a text object for this, we make one
193 if (bv_->text == 0) {
194 resizeCurrentBuffer();
199 bv_->text->first = screen_->TopCursorVisible(bv_->text);
200 owner_->updateMenubar();
201 owner_->updateToolbar();
202 // Similarly, buffer-dependent dialogs should be updated or
203 // hidden. This should go here because some dialogs (eg ToC)
204 // require bv_->text.
205 owner_->getDialogs()->updateBufferDependent(true);
209 lyxerr[Debug::INFO] << " No Buffer!" << endl;
210 owner_->updateMenubar();
211 owner_->updateToolbar();
212 owner_->getDialogs()->hideBufferDependent();
216 // Also remove all remaining text's from the testcache.
217 // (there should not be any!) (if there is any it is a
219 if (lyxerr.debugging())
220 textcache.show(lyxerr, "buffer delete all");
223 // should update layoutchoice even if we don't have a buffer.
224 owner_->updateLayoutChoice();
225 owner_->getMiniBuffer()->Init();
226 owner_->updateWindowTitle();
230 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
232 workarea_.resize(xpos, ypos, width, height);
233 update(bv_->text, SELECT);
238 void BufferView::Pimpl::resize()
241 resizeCurrentBuffer();
245 void BufferView::Pimpl::redraw()
247 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
252 bool BufferView::Pimpl::fitCursor(LyXText * text)
254 Assert(screen_.get());
256 bool ret = screen_->FitCursor(text, bv_);
263 void BufferView::Pimpl::redoCurrentBuffer()
265 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
266 if (buffer_ && bv_->text) {
268 owner_->updateLayoutChoice();
273 int BufferView::Pimpl::resizeCurrentBuffer()
275 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
277 LyXParagraph * par = 0;
278 LyXParagraph * selstartpar = 0;
279 LyXParagraph * selendpar = 0;
280 UpdatableInset * the_locking_inset = 0;
282 LyXParagraph::size_type pos = 0;
283 LyXParagraph::size_type selstartpos = 0;
284 LyXParagraph::size_type selendpos = 0;
285 bool selection = false;
286 bool mark_set = false;
290 owner_->getMiniBuffer()->Set(_("Formatting document..."));
293 par = bv_->text->cursor.par();
294 pos = bv_->text->cursor.pos();
295 selstartpar = bv_->text->sel_start_cursor.par();
296 selstartpos = bv_->text->sel_start_cursor.pos();
297 selendpar = bv_->text->sel_end_cursor.par();
298 selendpos = bv_->text->sel_end_cursor.pos();
299 selection = bv_->text->selection;
300 mark_set = bv_->text->mark_set;
301 the_locking_inset = bv_->text->the_locking_inset;
303 bv_->text = new LyXText(bv_);
305 // See if we have a text in TextCache that fits
306 // the new buffer_ with the correct width.
307 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
309 if (lyxerr.debugging()) {
310 lyxerr << "Found a LyXText that fits:\n";
311 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
313 // Set the owner of the newly found text
314 // bv_->text->owner(bv_);
315 if (lyxerr.debugging())
316 textcache.show(lyxerr, "resizeCurrentBuffer");
318 bv_->text = new LyXText(bv_);
324 bv_->text->selection = true;
325 /* at this point just to avoid the Delete-Empty-Paragraph
326 * Mechanism when setting the cursor */
327 bv_->text->mark_set = mark_set;
329 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
330 bv_->text->sel_cursor = bv_->text->cursor;
331 bv_->text->SetCursor(bv_, selendpar, selendpos);
332 bv_->text->SetSelection(bv_);
333 bv_->text->SetCursor(bv_, par, pos);
335 bv_->text->SetCursor(bv_, par, pos);
336 bv_->text->sel_cursor = bv_->text->cursor;
337 bv_->text->selection = false;
339 // remake the inset locking
340 bv_->text->the_locking_inset = the_locking_inset;
342 bv_->text->first = screen_->TopCursorVisible(bv_->text);
343 buffer_->resizeInsets(bv_);
344 // this will scroll the screen such that the cursor becomes visible
347 owner_->getMiniBuffer()->Init();
351 owner_->getDialogs()->hideSplash();
357 void BufferView::Pimpl::updateScreen()
359 // Regenerate the screen.
360 screen_.reset(new LyXScreen(workarea_));
362 //screen_ = new LyXScreen(workarea_);
366 void BufferView::Pimpl::updateScrollbar()
368 /* If the text is smaller than the working area, the scrollbar
369 * maximum must be the working area height. No scrolling will
373 workarea_.setScrollbar(0, 1.0);
377 static unsigned long max2 = 0;
378 static unsigned long height2 = 0;
380 unsigned long cbth = 0;
384 cbth = bv_->text->height;
385 cbsf = bv_->text->first;
388 // check if anything has changed.
390 height2 == workarea_.height() &&
391 current_scrollbar_value == cbsf)
394 height2 = workarea_.height();
395 current_scrollbar_value = cbsf;
397 if (cbth <= height2) { // text is smaller than screen
398 workarea_.setScrollbar(0, 1.0); // right?
402 long maximum_height = workarea_.height() * 3 / 4 + cbth;
406 double hfloat = workarea_.height();
407 double maxfloat = maximum_height;
409 float slider_size = 0.0;
410 int slider_value = value;
412 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
413 double const lineh = bv_->text->DefaultHeight();
414 workarea_.setScrollbarIncrements(lineh);
415 if (maxfloat > 0.0) {
416 if ((hfloat / maxfloat) * float(height2) < 3)
417 slider_size = 3.0/float(height2);
419 slider_size = hfloat / maxfloat;
421 slider_size = hfloat;
423 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
427 // Callback for scrollbar slider
428 void BufferView::Pimpl::scrollCB(double value)
430 if (!buffer_) return;
432 current_scrollbar_value = long(value);
433 if (current_scrollbar_value < 0)
434 current_scrollbar_value = 0;
439 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
441 if (!lyxrc.cursor_follows_scrollbar) {
446 LyXText * vbt = bv_->text;
448 int const height = vbt->DefaultHeight();
449 int const first = static_cast<int>((bv_->text->first + height));
450 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
452 if (vbt->cursor.y() < first)
453 vbt->SetCursorFromCoordinates(bv_, 0, first);
454 else if (vbt->cursor.y() > last)
455 vbt->SetCursorFromCoordinates(bv_, 0, last);
461 int BufferView::Pimpl::scrollUp(long time)
463 if (!buffer_) return 0;
464 if (!screen_.get()) return 0;
466 double value = workarea_.getScrollbarValue();
468 if (value == 0) return 0;
470 float add_value = (bv_->text->DefaultHeight()
471 + float(time) * float(time) * 0.125);
473 if (add_value > workarea_.height())
474 add_value = float(workarea_.height() -
475 bv_->text->DefaultHeight());
482 workarea_.setScrollbarValue(value);
489 int BufferView::Pimpl::scrollDown(long time)
491 if (!buffer_) return 0;
492 if (!screen_.get()) return 0;
494 double value = workarea_.getScrollbarValue();
495 pair<float, float> p = workarea_.getScrollbarBounds();
496 double max = p.second;
498 if (value == max) return 0;
500 float add_value = (bv_->text->DefaultHeight()
501 + float(time) * float(time) * 0.125);
503 if (add_value > workarea_.height())
504 add_value = float(workarea_.height() -
505 bv_->text->DefaultHeight());
512 workarea_.setScrollbarValue(value);
519 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
521 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
525 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
527 // Only use motion with button 1
528 if (!(state & Button1MotionMask))
531 if (!buffer_ || !screen_.get()) return;
533 // Check for inset locking
534 if (bv_->theLockingInset()) {
535 LyXCursor cursor = bv_->text->cursor;
536 LyXFont font = bv_->text->GetFont(bv_->buffer(),
537 cursor.par(), cursor.pos());
538 int width = bv_->theLockingInset()->width(bv_, font);
539 int inset_x = font.isVisibleRightToLeft()
540 ? cursor.x() - width : cursor.x();
541 int start_x = inset_x + bv_->theLockingInset()->scroll();
542 bv_->theLockingInset()->
543 InsetMotionNotify(bv_,
545 y - cursor.y() + bv_->text->first,
550 /* The test for not selection possible is needed, that only motion events are
551 * used, where the bottom press event was on the drawing area too */
552 if (!selection_possible)
555 screen_->HideCursor();
557 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
559 if (!bv_->text->selection)
560 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
562 bv_->text->SetSelection(bv_);
563 screen_->ToggleToggle(bv_->text, bv_);
564 fitCursor(bv_->text);
565 screen_->ShowCursor(bv_->text, bv_);
569 // Single-click on work area
570 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
576 if (!buffer_ || !screen_.get()) return;
578 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
580 // ok ok, this is a hack.
581 if (button == 4 || button == 5) {
584 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
587 scrollDown(lyxrc.wheel_jump);
592 if (bv_->theLockingInset()) {
593 // We are in inset locking mode
595 /* Check whether the inset was hit. If not reset mode,
596 otherwise give the event to the inset */
597 if (inset_hit == bv_->theLockingInset()) {
598 bv_->theLockingInset()->
599 InsetButtonPress(bv_,
604 bv_->unlockInset(bv_->theLockingInset());
609 selection_possible = true;
610 screen_->HideCursor();
612 int const screen_first = bv_->text->first;
614 // Middle button press pastes if we have a selection
615 bool paste_internally = false;
617 && bv_->text->selection) {
618 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
619 paste_internally = true;
622 // Clear the selection
623 screen_->ToggleSelection(bv_->text, bv_);
624 bv_->text->ClearSelection(bv_);
625 bv_->text->FullRebreak(bv_);
626 screen_->Update(bv_->text, bv_);
629 // Single left click in math inset?
630 if ((inset_hit != 0) &&
631 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
632 // Highly editable inset, like math
633 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
634 selection_possible = false;
635 owner_->updateLayoutChoice();
636 owner_->getMiniBuffer()->Set(inset->EditMessage());
637 inset->InsetButtonPress(bv_, xpos, ypos, button);
638 inset->Edit(bv_, xpos, ypos, button);
642 // Right click on a footnote flag opens float menu
644 selection_possible = false;
648 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
649 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
650 bv_->text->FinishUndo();
651 bv_->text->sel_cursor = bv_->text->cursor;
652 bv_->text->cursor.x_fix(bv_->text->cursor.x());
654 owner_->updateLayoutChoice();
655 if (fitCursor(bv_->text)) {
656 selection_possible = false;
659 // Insert primary selection with middle mouse
660 // if there is a local selection in the current buffer,
663 if (paste_internally)
664 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
666 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
668 selection_possible = false;
674 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
680 LyXText * text = bv_->getLyXText();
682 if (text->bv_owner && bv_->theLockingInset())
685 if (screen_.get() && button == 1) {
686 if (text->bv_owner) {
687 screen_->HideCursor();
688 screen_->ToggleSelection(text, bv_);
689 text->SelectWord(bv_);
690 screen_->ToggleSelection(text, bv_, false);
692 text->SelectWord(bv_);
694 /* This will fit the cursor on the screen
696 update(text, BufferView::SELECT|BufferView::FITCUR);
701 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
707 LyXText * text = bv_->getLyXText();
709 if (text->bv_owner && bv_->theLockingInset())
712 if (screen_.get() && (button == 1)) {
713 screen_->HideCursor();
714 screen_->ToggleSelection(text, bv_);
715 text->CursorHome(bv_);
716 text->sel_cursor = text->cursor;
717 text->CursorEnd(bv_);
718 text->SetSelection(bv_);
719 screen_->ToggleSelection(text, bv_, false);
720 /* This will fit the cursor on the screen
722 update(text, BufferView::SELECT|BufferView::FITCUR);
727 void BufferView::Pimpl::enterView()
729 if (active() && available()) {
730 SetXtermCursor(workarea_.getWin());
731 using_xterm_cursor = true;
736 void BufferView::Pimpl::leaveView()
738 if (using_xterm_cursor) {
739 XUndefineCursor(fl_get_display(), workarea_.getWin());
740 using_xterm_cursor = false;
745 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
748 if (!buffer_ || !screen_.get()) return;
750 // If we hit an inset, we have the inset coordinates in these
751 // and inset_hit points to the inset. If we do not hit an
752 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
753 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
755 if (bv_->theLockingInset()) {
756 // We are in inset locking mode.
758 /* LyX does a kind of work-area grabbing for insets.
759 Only a ButtonPress Event outside the inset will
760 force a InsetUnlock. */
761 bv_->theLockingInset()->
762 InsetButtonRelease(bv_, x, y, button);
766 selection_possible = false;
768 if (button >= 2) return;
773 // Did we hit an editable inset?
775 // Inset like error, notes and figures
776 selection_possible = false;
778 // CHECK fix this proper in 0.13
780 // Following a ref shouldn't issue
781 // a push on the undo-stack
782 // anylonger, now that we have
783 // keybindings for following
784 // references and returning from
785 // references. IMHO though, it
786 // should be the inset's own business
787 // to push or not push on the undo
788 // stack. They don't *have* to
789 // alter the document...
791 // ...or maybe the SetCursorParUndo()
792 // below isn't necessary at all anylonger?
793 if (inset_hit->LyxCode() == Inset::REF_CODE) {
794 bv_->text->SetCursorParUndo(bv_->buffer());
797 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
798 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
799 // Highly editable inset, like math
800 UpdatableInset *inset = (UpdatableInset *)inset_hit;
801 inset->InsetButtonRelease(bv_, x, y, button);
803 inset_hit->InsetButtonRelease(bv_, x, y, button);
804 inset_hit->Edit(bv_, x, y, button);
810 // check whether we want to open a float
814 if (bv_->text->cursor.pos() <
815 bv_->text->cursor.par()->Last()) {
816 c = bv_->text->cursor.par()->
817 GetChar(bv_->text->cursor.pos());
819 if(!bv_->text->selection)
820 if (c == LyXParagraph::META_FOOTNOTE
821 || c == LyXParagraph::META_MARGIN
822 || c == LyXParagraph::META_FIG
823 || c == LyXParagraph::META_TAB
824 || c == LyXParagraph::META_WIDE_FIG
825 || c == LyXParagraph::META_WIDE_TAB
826 || c == LyXParagraph::META_ALGORITHM){
829 if (bv_->text->cursor.pos() - 1 >= 0) {
830 c = bv_->text->cursor.par()->
831 GetChar(bv_->text->cursor.pos() - 1);
832 if (c == LyXParagraph::META_FOOTNOTE
833 || c == LyXParagraph::META_MARGIN
834 || c == LyXParagraph::META_FIG
835 || c == LyXParagraph::META_TAB
836 || c == LyXParagraph::META_WIDE_FIG
837 || c == LyXParagraph::META_WIDE_TAB
838 || c == LyXParagraph::META_ALGORITHM){
839 // We are one step too far to the right
840 bv_->text->CursorLeft(bv_);
846 selection_possible = false;
850 // Do we want to close a float? (click on the float-label)
851 if (bv_->text->cursor.row()->par()->footnoteflag ==
852 LyXParagraph::OPEN_FOOTNOTE
853 && bv_->text->cursor.row()->previous() &&
854 bv_->text->cursor.row()->previous()->par()->
855 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
856 LyXFont font(LyXFont::ALL_SANE);
857 font.setSize(LyXFont::SIZE_FOOTNOTE);
859 int box_x = 20; // LYX_PAPER_MARGIN;
860 box_x += lyxfont::width(" wide-tab ", font);
862 unsigned int screen_first = bv_->text->first;
865 && y + screen_first > bv_->text->cursor.y() -
866 bv_->text->cursor.row()->baseline()
867 && y + screen_first < bv_->text->cursor.y() -
868 bv_->text->cursor.row()->baseline()
869 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
871 selection_possible = false;
876 // check whether we want to open a float
880 if (bv_->text->cursor.pos() <
881 bv_->text->cursor.par()->size()) {
882 c = bv_->text->cursor.par()->
883 GetChar(bv_->text->cursor.pos());
885 if (bv_->text->cursor.pos() - 1 >= 0) {
886 c = bv_->text->cursor.par()->
887 GetChar(bv_->text->cursor.pos() - 1);
890 selection_possible = false;
895 // Maybe we want to edit a bibitem ale970302
896 if (bv_->text->cursor.par()->bibkey && x < 20 +
897 bibitemMaxWidth(bv_, textclasslist.
899 params.textclass).defaultfont())) {
900 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
908 * Returns an inset if inset was hit. 0 otherwise.
909 * If hit, the coordinates are changed relative to the inset.
910 * Otherwise coordinates are not changed, and false is returned.
912 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
913 unsigned int /* button */)
918 int y_tmp = y + text->first;
921 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
924 if (cursor.pos() < cursor.par()->Last()
926 if (cursor.pos() < cursor.par()->size()
928 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
929 && cursor.par()->GetInset(cursor.pos())
930 && cursor.par()->GetInset(cursor.pos())->Editable()) {
932 // Check whether the inset really was hit
933 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
934 LyXFont font = text->GetFont(bv_->buffer(),
935 cursor.par(), cursor.pos());
936 int width = tmpinset->width(bv_, font);
937 int inset_x = font.isVisibleRightToLeft()
938 ? cursor.x() - width : cursor.x();
939 int start_x = inset_x + tmpinset->scroll();
940 int end_x = inset_x + width;
942 if (x > start_x && x < end_x
943 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
944 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
945 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
947 // The origin of an inset is on the baseline
948 y = y_tmp - (text->cursor.y());
953 if ((cursor.pos() - 1 >= 0) &&
954 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
955 (cursor.par()->GetInset(cursor.pos() - 1)) &&
956 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
957 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
958 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
960 int width = tmpinset->width(bv_, font);
961 int inset_x = font.isVisibleRightToLeft()
962 ? cursor.x() : cursor.x() - width;
963 int start_x = inset_x + tmpinset->scroll();
964 int end_x = inset_x + width;
966 if (x > start_x && x < end_x
967 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
968 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
970 if (move_cursor && (tmpinset != bv_->theLockingInset()))
972 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
974 // The origin of an inset is on the baseline
975 y = y_tmp - (text->cursor.y());
983 void BufferView::Pimpl::workAreaExpose()
985 static int work_area_width = 0;
986 static unsigned int work_area_height = 0;
988 bool widthChange = workarea_.workWidth() != work_area_width;
989 bool heightChange = workarea_.height() != work_area_height;
991 // update from work area
992 work_area_width = workarea_.workWidth();
993 work_area_height = workarea_.height();
996 // All buffers need a resize
999 // Remove all texts from the textcache
1000 // This is not _really_ what we want to do. What
1001 // we really want to do is to delete in textcache
1002 // that does not have a BufferView with matching
1003 // width, but as long as we have only one BufferView
1004 // deleting all gives the same result.
1005 if (lyxerr.debugging())
1006 textcache.show(lyxerr, "Expose delete all");
1008 } else if (heightChange) {
1009 // Rebuild image of current screen
1011 // fitCursor() ensures we don't jump back
1012 // to the start of the document on vertical
1014 fitCursor(bv_->text);
1016 // The main window size has changed, repaint most stuff
1018 // ...including the minibuffer
1019 owner_->getMiniBuffer()->Init();
1021 } else if (screen_.get())
1022 screen_->Redraw(bv_->text, bv_);
1024 // Grey box when we don't have a buffer
1025 workarea_.greyOut();
1028 // always make sure that the scrollbar is sane.
1030 owner_->updateLayoutChoice();
1035 void BufferView::Pimpl::update()
1037 if (screen_.get()) screen_->Update(bv_->text, bv_);
1040 // Values used when calling update:
1042 // -2 - update, move sel_cursor if selection, fitcursor
1043 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1044 // 0 - update, move sel_cursor if selection, fitcursor
1045 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1046 // 3 - update, move sel_cursor if selection
1049 // a simple redraw of the parts that need refresh
1051 // move sel_cursor if selection -
1052 // the text's sel_cursor is moved if there is selection is progress
1055 // fitCursor() is called and the scrollbar updated
1058 // the buffer is marked dirty.
1067 // UPDATE_ONLY = UPDATE;
1068 // UPDATE_SELECT = UPDATE | SELECT;
1069 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1070 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1072 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1073 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1074 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1075 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1076 // update(3) -> update(1) -> update(1) -> update(SELECT)
1078 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1080 owner_->updateLayoutChoice();
1082 if (!text->selection && (f & SELECT)) {
1083 text->sel_cursor = text->cursor;
1086 text->FullRebreak(bv_);
1088 if (text->inset_owner) {
1089 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1090 bv_->updateInset(text->inset_owner, true);
1099 if (buffer_->isLyxClean()) {
1100 buffer_->markDirty();
1101 owner_->getMiniBuffer()->setTimer(4);
1103 buffer_->markDirty();
1109 // Callback for cursor timer
1110 void BufferView::Pimpl::cursorToggle()
1112 // Quite a nice place for asyncron Inset updating, isn't it?
1113 // Actually no! This is run even if no buffer exist... so (Lgb)
1115 cursor_timeout.restart();
1120 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1121 if (pid == -1) // error find out what is wrong
1122 ; // ignore it for now.
1124 sigchldhandler(pid, &status);
1126 updatelist.update(bv_);
1128 if (!screen_.get()) {
1129 cursor_timeout.restart();
1133 if (!bv_->theLockingInset()) {
1134 screen_->CursorToggle(bv_->text, bv_);
1136 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1139 cursor_timeout.restart();
1143 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1145 if (!text->cursor.row()->previous())
1148 int y = text->first;
1149 if (text->inset_owner)
1150 y += bv_->text->first;
1151 Row * cursorrow = text->cursor.row();
1152 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1153 bv_->text->FinishUndo();
1154 // This is to allow jumping over large insets
1155 if ((cursorrow == text->cursor.row()))
1156 text->CursorUp(bv_);
1158 if (text->inset_owner ||
1159 text->cursor.row()->height() < workarea_.height())
1160 screen_->Draw(bv_->text, bv_,
1162 - text->cursor.row()->baseline()
1163 + text->cursor.row()->height()
1164 - workarea_.height() + 1 );
1169 void BufferView::Pimpl::cursorNext(LyXText * text)
1171 if (!text->cursor.row()->next())
1174 int y = text->first + workarea_.height();
1175 // if (text->inset_owner)
1176 // y += bv_->text->first;
1177 text->GetRowNearY(y);
1179 Row * cursorrow = text->cursor.row();
1180 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1181 bv_->text->FinishUndo();
1182 // This is to allow jumping over large insets
1183 if ((cursorrow == bv_->text->cursor.row()))
1184 text->CursorDown(bv_);
1186 if (text->inset_owner ||
1187 text->cursor.row()->height() < workarea_.height())
1188 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1189 text->cursor.row()->baseline());
1194 bool BufferView::Pimpl::available() const
1196 if (buffer_ && bv_->text) return true;
1201 void BufferView::Pimpl::beforeChange(LyXText * text)
1204 text->ClearSelection(bv_);
1208 void BufferView::Pimpl::savePosition(unsigned int i)
1210 if (i >= saved_positions_num)
1212 saved_positions[i] = Position(buffer_->fileName(),
1213 bv_->text->cursor.par()->id(),
1214 bv_->text->cursor.pos());
1216 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1220 void BufferView::Pimpl::restorePosition(unsigned int i)
1222 if (i >= saved_positions_num)
1225 string fname = saved_positions[i].filename;
1227 beforeChange(bv_->text);
1229 if (fname != buffer_->fileName()) {
1230 Buffer * b = bufferlist.exists(fname) ?
1231 bufferlist.getBuffer(fname) :
1232 bufferlist.loadLyXFile(fname); // don't ask, just load it
1233 if (b != 0 ) buffer(b);
1236 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1241 bv_->text->SetCursor(bv_, par,
1242 min(par->Last(), saved_positions[i].par_pos));
1244 bv_->text->SetCursor(bv_, par,
1245 min(par->size(), saved_positions[i].par_pos));
1247 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1249 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1253 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1255 if (i >= saved_positions_num)
1258 return !saved_positions[i].filename.empty();
1262 void BufferView::Pimpl::setState()
1264 if (!lyxrc.rtl_support)
1267 LyXText * text = bv_->getLyXText();
1268 if (text->real_current_font.isRightToLeft() &&
1269 text->real_current_font.latex() != LyXFont::ON) {
1270 if (owner_->getIntl()->primarykeymap)
1271 owner_->getIntl()->KeyMapSec();
1273 if (!owner_->getIntl()->primarykeymap)
1274 owner_->getIntl()->KeyMapPrim();
1279 void BufferView::Pimpl::insetSleep()
1281 if (bv_->theLockingInset() && !bv_->inset_slept) {
1282 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1283 bv_->theLockingInset()->InsetUnlock(bv_);
1284 bv_->inset_slept = true;
1289 void BufferView::Pimpl::insetWakeup()
1291 if (bv_->theLockingInset() && bv_->inset_slept) {
1292 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1293 bv_->inset_slept = false;
1298 void BufferView::Pimpl::insetUnlock()
1300 if (bv_->theLockingInset()) {
1301 if (!bv_->inset_slept)
1302 bv_->theLockingInset()->InsetUnlock(bv_);
1303 bv_->theLockingInset(0);
1304 bv_->text->FinishUndo();
1305 bv_->inset_slept = false;
1310 bool BufferView::Pimpl::focus() const
1312 return workarea_.hasFocus();
1316 void BufferView::Pimpl::focus(bool f)
1318 if (f) workarea_.setFocus();
1322 bool BufferView::Pimpl::active() const
1324 return workarea_.active();
1328 bool BufferView::Pimpl::belowMouse() const
1330 return workarea_.belowMouse();
1334 void BufferView::Pimpl::showCursor()
1337 screen_->ShowCursor(bv_->text, bv_);
1341 void BufferView::Pimpl::hideCursor()
1344 screen_->HideCursor();
1348 void BufferView::Pimpl::toggleSelection(bool b)
1351 screen_->ToggleSelection(bv_->text, bv_, b);
1355 void BufferView::Pimpl::toggleToggle()
1358 screen_->ToggleToggle(bv_->text, bv_);
1362 void BufferView::Pimpl::center()
1364 beforeChange(bv_->text);
1365 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1366 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1368 screen_->Draw(bv_->text, bv_, 0);
1370 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1375 void BufferView::Pimpl::pasteClipboard(bool asPara)
1377 if (!buffer_) return;
1379 screen_->HideCursor();
1380 beforeChange(bv_->text);
1382 string const clip(workarea_.getClipboard());
1384 if (clip.empty()) return;
1387 bv_->text->InsertStringB(bv_, clip);
1389 bv_->text->InsertStringA(bv_, clip);
1391 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1395 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1397 workarea_.putClipboard(stuff);
1402 * Dispatch functions for actions which can be valid for BufferView->text
1403 * and/or InsetText->text!!!
1405 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1408 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1410 if (selecting || TEXT(bv_)->mark_set) {
1411 TEXT(bv_)->SetSelection(bv_);
1412 if (TEXT(bv_)->bv_owner)
1413 bv_->toggleToggle();
1415 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1418 /* ---> Everytime the cursor is moved, show the current font state. */
1419 // should this too me moved out of this func?
1420 //owner->showState();
1425 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1427 LyXCursor cursor = TEXT(bv_)->cursor;
1428 Buffer::inset_iterator it =
1429 find_if(Buffer::inset_iterator(
1430 cursor.par(), cursor.pos()),
1431 buffer_->inset_iterator_end(),
1432 compare_memfun(&Inset::LyxCode, code)
1434 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1438 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1440 string filename = filen;
1442 if (filename.empty()) {
1443 // Launch a file browser
1444 string initpath = lyxrc.document_path;
1447 string const trypath = owner_->buffer()->filepath;
1448 // If directory is writeable, use this as default.
1449 if (IsDirWriteable(trypath) == 1)
1453 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1455 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1456 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1458 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1460 if (result.first == FileDialog::Later)
1463 filename = result.second;
1465 // check selected filename
1466 if (filename.empty()) {
1467 owner_->getMiniBuffer()->Set(_("Canceled."));
1472 // get absolute path of file and make sure the filename ends
1474 filename = MakeAbsPath(filename);
1475 if (!IsLyXFilename(filename))
1479 owner_->getMiniBuffer()->Set(_("Inserting document"),
1480 MakeDisplayPath(filename), "...");
1481 bool const res = bv_->insertLyXFile(filename);
1483 owner_->getMiniBuffer()->Set(_("Document"),
1484 MakeDisplayPath(filename),
1487 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1488 MakeDisplayPath(filename));
1493 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1496 // --- Misc -------------------------------------------
1499 TEXT(bv_)->toggleAppendix(bv_);
1500 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1504 case LFUN_TOC_INSERT:
1505 case LFUN_LOA_INSERT:
1506 case LFUN_LOF_INSERT:
1507 case LFUN_LOT_INSERT:
1509 InsetCommandParams p;
1511 if (action == LFUN_TOC_INSERT )
1512 p.setCmdName( "tableofcontents" );
1513 else if (action == LFUN_LOA_INSERT )
1514 p.setCmdName( "listofalgorithms" );
1515 else if (action == LFUN_LOF_INSERT )
1516 p.setCmdName( "listoffigures" );
1518 p.setCmdName( "listoftables" );
1520 Inset * inset = new InsetTOC( p );
1521 if (!bv_->insertInset( inset, "Standard", true ) )
1526 case LFUN_TABULAR_FEATURE:
1527 case LFUN_SCROLL_INSET:
1528 // this is not handled here as this funktion is only aktive
1529 // if we have a locking_inset and that one is (or contains)
1533 case LFUN_INSET_GRAPHICS:
1535 Inset * new_inset = new InsetGraphics;
1536 if (!bv_->insertInset(new_inset)) {
1539 // this is need because you don't use a inset->Edit()
1540 bv_->updateInset(new_inset, true);
1541 new_inset->Edit(bv_, 0, 0, 0);
1551 case LFUN_PASTESELECTION:
1553 bool asPara = false;
1554 if (argument == "paragraph") asPara = true;
1555 pasteClipboard(asPara);
1567 case LFUN_LAYOUT_COPY:
1568 bv_->copyEnvironment();
1571 case LFUN_LAYOUT_PASTE:
1572 bv_->pasteEnvironment();
1576 case LFUN_GOTOERROR:
1577 bv_->gotoInset(Inset::ERROR_CODE, false);
1581 bv_->gotoInset(Inset::IGNORE_CODE, false);
1584 case LFUN_REFERENCE_GOTO:
1586 vector<Inset::Code> tmp;
1587 tmp.push_back(Inset::LABEL_CODE);
1588 tmp.push_back(Inset::REF_CODE);
1589 bv_->gotoInset(tmp, true);
1593 case LFUN_HYPHENATION:
1594 bv_->hyphenationPoint();
1601 case LFUN_END_OF_SENTENCE:
1602 bv_->endOfSentenceDot();
1605 case LFUN_MENU_SEPARATOR:
1606 bv_->menuSeparator();
1614 changeDepth(bv_, TEXT(bv_), 0);
1617 case LFUN_DEPTH_MIN:
1618 changeDepth(bv_, TEXT(bv_), -1);
1621 case LFUN_DEPTH_PLUS:
1622 changeDepth(bv_, TEXT(bv_), 1);
1626 owner_->getDialogs()->setUserFreeFont();
1632 owner_->showState();
1635 case LFUN_FILE_INSERT:
1637 MenuInsertLyXFile(argument);
1641 case LFUN_FILE_INSERT_ASCII_PARA:
1642 InsertAsciiFile(bv_, argument, true);
1645 case LFUN_FILE_INSERT_ASCII:
1646 InsertAsciiFile(bv_, argument, false);
1651 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1652 << argument << endl;
1654 // Derive layout number from given argument (string)
1655 // and current buffer's textclass (number). */
1656 LyXTextClassList::ClassList::size_type tclass =
1657 buffer_->params.textclass;
1658 pair <bool, LyXTextClass::size_type> layout =
1659 textclasslist.NumberOfLayout(tclass, argument);
1661 // If the entry is obsolete, use the new one instead.
1663 string obs = textclasslist.Style(tclass,layout.second)
1667 textclasslist.NumberOfLayout(tclass, obs);
1670 // see if we found the layout number:
1671 if (!layout.first) {
1672 owner_->getLyXFunc()->setErrorMessage(
1673 string(N_("Layout ")) + argument +
1678 if (current_layout != layout.second) {
1680 current_layout = layout.second;
1682 BufferView::SELECT|BufferView::FITCUR);
1683 TEXT(bv_)->SetLayout(bv_, layout.second);
1684 owner_->setLayout(layout.second);
1686 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1693 Lang(bv_, argument);
1695 owner_->showState();
1700 owner_->showState();
1705 owner_->showState();
1710 owner_->showState();
1715 owner_->showState();
1720 owner_->showState();
1725 owner_->showState();
1730 owner_->showState();
1733 case LFUN_UNDERLINE:
1735 owner_->showState();
1738 case LFUN_FONT_SIZE:
1739 FontSize(bv_, argument);
1740 owner_->showState();
1743 case LFUN_FONT_STATE:
1744 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1747 case LFUN_UPCASE_WORD:
1748 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1749 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1750 if (TEXT(bv_)->inset_owner)
1751 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1752 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1755 case LFUN_LOWCASE_WORD:
1756 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1757 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1758 if (TEXT(bv_)->inset_owner)
1759 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1760 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1763 case LFUN_CAPITALIZE_WORD:
1764 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1765 TEXT(bv_)->ChangeWordCase(bv_,
1766 LyXText::text_capitalization);
1767 if (TEXT(bv_)->inset_owner)
1768 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1769 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1772 case LFUN_INSERT_LABEL:
1773 MenuInsertLabel(bv_, argument);
1776 case LFUN_REF_INSERT:
1777 if (argument.empty()) {
1778 InsetCommandParams p("ref");
1779 owner_->getDialogs()->createRef(p.getAsString());
1781 InsetCommandParams p;
1782 p.setFromString(argument);
1784 InsetRef * inset = new InsetRef(p, *buffer_);
1785 if (!bv_->insertInset(inset))
1788 bv_->updateInset(inset, true);
1792 case LFUN_BOOKMARK_SAVE:
1793 savePosition(strToUnsignedInt(argument));
1796 case LFUN_BOOKMARK_GOTO:
1797 restorePosition(strToUnsignedInt(argument));
1802 string label(argument);
1803 if (label.empty()) {
1805 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1807 label = inset->getContents();
1812 if (!label.empty()) {
1813 //bv_->savePosition(0);
1814 if (!bv_->gotoLabel(label))
1815 WriteAlert(_("Error"),
1816 _("Couldn't find this label"),
1817 _("in current document."));
1822 // --- Cursor Movements -----------------------------
1825 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1826 if (!TEXT(bv_)->mark_set)
1827 beforeChange(TEXT(bv_));
1828 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1830 TEXT(bv_)->CursorLeft(bv_, false);
1832 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1834 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
1836 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1837 == LyXParagraph::META_INSET
1838 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1839 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1840 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1841 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1845 TEXT(bv_)->GetFont(buffer_,
1846 TEXT(bv_)->cursor.par(),
1847 TEXT(bv_)->cursor.pos());
1848 y = tmpinset->descent(bv_,font);
1850 tmpinset->Edit(bv_, 0, y, 0);
1854 TEXT(bv_)->CursorRight(bv_, false);
1855 TEXT(bv_)->FinishUndo();
1856 moveCursorUpdate(false);
1857 owner_->showState();
1863 // This is soooo ugly. Isn`t it possible to make
1864 // it simpler? (Lgb)
1865 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1866 if (!TEXT(bv_)->mark_set)
1867 beforeChange(TEXT(bv_));
1868 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1869 LyXCursor cur = TEXT(bv_)->cursor;
1871 TEXT(bv_)->CursorLeft(bv_, false);
1872 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1874 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1876 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
1878 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1879 LyXParagraph::META_INSET) &&
1880 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1881 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1882 == Inset::HIGHLY_EDITABLE))
1884 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1885 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1886 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1887 TEXT(bv_)->cursor.par(),
1888 TEXT(bv_)->cursor.pos());
1890 : tmpinset->descent(bv_,font);
1893 tmpinset->width(bv_,font),
1898 TEXT(bv_)->CursorRight(bv_, false);
1900 TEXT(bv_)->FinishUndo();
1901 moveCursorUpdate(false);
1902 owner_->showState();
1907 if (!TEXT(bv_)->mark_set)
1908 beforeChange(TEXT(bv_));
1909 update(TEXT(bv_), BufferView::UPDATE);
1910 TEXT(bv_)->CursorUp(bv_);
1911 TEXT(bv_)->FinishUndo();
1912 moveCursorUpdate(false);
1913 owner_->showState();
1917 if (!TEXT(bv_)->mark_set)
1918 beforeChange(TEXT(bv_));
1919 update(TEXT(bv_), BufferView::UPDATE);
1920 TEXT(bv_)->CursorDown(bv_);
1921 TEXT(bv_)->FinishUndo();
1922 moveCursorUpdate(false);
1923 owner_->showState();
1926 case LFUN_UP_PARAGRAPH:
1927 if (!TEXT(bv_)->mark_set)
1928 beforeChange(TEXT(bv_));
1929 update(TEXT(bv_), BufferView::UPDATE);
1930 TEXT(bv_)->CursorUpParagraph(bv_);
1931 TEXT(bv_)->FinishUndo();
1932 moveCursorUpdate(false);
1933 owner_->showState();
1936 case LFUN_DOWN_PARAGRAPH:
1937 if (!TEXT(bv_)->mark_set)
1938 beforeChange(TEXT(bv_));
1939 update(TEXT(bv_), BufferView::UPDATE);
1940 TEXT(bv_)->CursorDownParagraph(bv_);
1941 TEXT(bv_)->FinishUndo();
1942 moveCursorUpdate(false);
1943 owner_->showState();
1947 if (!TEXT(bv_)->mark_set)
1948 beforeChange(TEXT(bv_));
1949 update(TEXT(bv_), BufferView::UPDATE);
1950 cursorPrevious(TEXT(bv_));
1951 TEXT(bv_)->FinishUndo();
1952 moveCursorUpdate(false);
1953 owner_->showState();
1957 if (!TEXT(bv_)->mark_set)
1958 beforeChange(TEXT(bv_));
1959 update(TEXT(bv_), BufferView::UPDATE);
1960 cursorNext(TEXT(bv_));
1961 TEXT(bv_)->FinishUndo();
1962 moveCursorUpdate(false);
1963 owner_->showState();
1967 if (!TEXT(bv_)->mark_set)
1968 beforeChange(TEXT(bv_));
1969 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1970 TEXT(bv_)->CursorHome(bv_);
1971 TEXT(bv_)->FinishUndo();
1972 moveCursorUpdate(false);
1973 owner_->showState();
1977 if (!TEXT(bv_)->mark_set)
1978 beforeChange(TEXT(bv_));
1980 BufferView::SELECT|BufferView::FITCUR);
1981 TEXT(bv_)->CursorEnd(bv_);
1982 TEXT(bv_)->FinishUndo();
1983 moveCursorUpdate(false);
1984 owner_->showState();
1987 case LFUN_SHIFT_TAB:
1989 if (!TEXT(bv_)->mark_set)
1990 beforeChange(TEXT(bv_));
1992 BufferView::SELECT|BufferView::FITCUR);
1993 TEXT(bv_)->CursorTab(bv_);
1994 TEXT(bv_)->FinishUndo();
1995 moveCursorUpdate(false);
1996 owner_->showState();
1999 case LFUN_WORDRIGHT:
2000 if (!TEXT(bv_)->mark_set)
2001 beforeChange(TEXT(bv_));
2002 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2003 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2004 TEXT(bv_)->CursorLeftOneWord(bv_);
2006 TEXT(bv_)->CursorRightOneWord(bv_);
2007 TEXT(bv_)->FinishUndo();
2008 moveCursorUpdate(false);
2009 owner_->showState();
2013 if (!TEXT(bv_)->mark_set)
2014 beforeChange(TEXT(bv_));
2015 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2016 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2017 TEXT(bv_)->CursorRightOneWord(bv_);
2019 TEXT(bv_)->CursorLeftOneWord(bv_);
2020 TEXT(bv_)->FinishUndo();
2021 moveCursorUpdate(false);
2022 owner_->showState();
2025 case LFUN_BEGINNINGBUF:
2026 if (!TEXT(bv_)->mark_set)
2027 beforeChange(TEXT(bv_));
2029 BufferView::SELECT|BufferView::FITCUR);
2030 TEXT(bv_)->CursorTop(bv_);
2031 TEXT(bv_)->FinishUndo();
2032 moveCursorUpdate(false);
2033 owner_->showState();
2037 if (!TEXT(bv_)->mark_set)
2038 beforeChange(TEXT(bv_));
2040 BufferView::SELECT|BufferView::FITCUR);
2041 TEXT(bv_)->CursorBottom(bv_);
2042 TEXT(bv_)->FinishUndo();
2043 moveCursorUpdate(false);
2044 owner_->showState();
2048 /* cursor selection ---------------------------- */
2051 BufferView::SELECT|BufferView::FITCUR);
2052 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2053 TEXT(bv_)->CursorLeft(bv_);
2055 TEXT(bv_)->CursorRight(bv_);
2056 TEXT(bv_)->FinishUndo();
2057 moveCursorUpdate(true);
2058 owner_->showState();
2063 BufferView::SELECT|BufferView::FITCUR);
2064 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2065 TEXT(bv_)->CursorRight(bv_);
2067 TEXT(bv_)->CursorLeft(bv_);
2068 TEXT(bv_)->FinishUndo();
2069 moveCursorUpdate(true);
2070 owner_->showState();
2075 BufferView::SELECT|BufferView::FITCUR);
2076 TEXT(bv_)->CursorUp(bv_);
2077 TEXT(bv_)->FinishUndo();
2078 moveCursorUpdate(true);
2079 owner_->showState();
2084 BufferView::SELECT|BufferView::FITCUR);
2085 TEXT(bv_)->CursorDown(bv_);
2086 TEXT(bv_)->FinishUndo();
2087 moveCursorUpdate(true);
2088 owner_->showState();
2091 case LFUN_UP_PARAGRAPHSEL:
2093 BufferView::SELECT|BufferView::FITCUR);
2094 TEXT(bv_)->CursorUpParagraph(bv_);
2095 TEXT(bv_)->FinishUndo();
2096 moveCursorUpdate(true);
2097 owner_->showState();
2100 case LFUN_DOWN_PARAGRAPHSEL:
2102 BufferView::SELECT|BufferView::FITCUR);
2103 TEXT(bv_)->CursorDownParagraph(bv_);
2104 TEXT(bv_)->FinishUndo();
2105 moveCursorUpdate(true);
2106 owner_->showState();
2110 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2111 cursorPrevious(TEXT(bv_));
2112 TEXT(bv_)->FinishUndo();
2113 moveCursorUpdate(true);
2114 owner_->showState();
2118 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2119 cursorNext(TEXT(bv_));
2120 TEXT(bv_)->FinishUndo();
2121 moveCursorUpdate(true);
2122 owner_->showState();
2126 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2127 TEXT(bv_)->CursorHome(bv_);
2128 TEXT(bv_)->FinishUndo();
2129 moveCursorUpdate(true);
2130 owner_->showState();
2134 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2135 TEXT(bv_)->CursorEnd(bv_);
2136 TEXT(bv_)->FinishUndo();
2137 moveCursorUpdate(true);
2138 owner_->showState();
2141 case LFUN_WORDRIGHTSEL:
2142 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2143 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2144 TEXT(bv_)->CursorLeftOneWord(bv_);
2146 TEXT(bv_)->CursorRightOneWord(bv_);
2147 TEXT(bv_)->FinishUndo();
2148 moveCursorUpdate(true);
2149 owner_->showState();
2152 case LFUN_WORDLEFTSEL:
2153 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2154 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2155 TEXT(bv_)->CursorRightOneWord(bv_);
2157 TEXT(bv_)->CursorLeftOneWord(bv_);
2158 TEXT(bv_)->FinishUndo();
2159 moveCursorUpdate(true);
2160 owner_->showState();
2163 case LFUN_BEGINNINGBUFSEL:
2164 if (TEXT(bv_)->inset_owner)
2166 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2167 TEXT(bv_)->CursorTop(bv_);
2168 TEXT(bv_)->FinishUndo();
2169 moveCursorUpdate(true);
2170 owner_->showState();
2173 case LFUN_ENDBUFSEL:
2174 if (TEXT(bv_)->inset_owner)
2177 BufferView::SELECT|BufferView::FITCUR);
2178 TEXT(bv_)->CursorBottom(bv_);
2179 TEXT(bv_)->FinishUndo();
2180 moveCursorUpdate(true);
2181 owner_->showState();
2184 // --- text changing commands ------------------------
2185 case LFUN_BREAKLINE:
2186 beforeChange(TEXT(bv_));
2187 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2189 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2190 moveCursorUpdate(false);
2193 case LFUN_PROTECTEDSPACE:
2195 LyXLayout const & style =
2196 textclasslist.Style(buffer_->params.textclass,
2197 TEXT(bv_)->cursor.par()->GetLayout());
2199 if (style.free_spacing) {
2200 TEXT(bv_)->InsertChar(bv_, ' ');
2201 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2203 bv_->protectedBlank(TEXT(bv_));
2205 moveCursorUpdate(false);
2210 if (TEXT(bv_)->mark_set) {
2211 beforeChange(TEXT(bv_));
2212 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2213 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2215 beforeChange(TEXT(bv_));
2216 TEXT(bv_)->mark_set = 1;
2217 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2218 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2220 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2224 if (!TEXT(bv_)->selection) {
2225 TEXT(bv_)->Delete(bv_);
2226 TEXT(bv_)->sel_cursor =
2229 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2230 // It is possible to make it a lot faster still
2231 // just comment out the line below...
2236 moveCursorUpdate(false);
2237 owner_->showState();
2241 case LFUN_DELETE_SKIP:
2243 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2245 LyXCursor cursor = TEXT(bv_)->cursor;
2247 if (!TEXT(bv_)->selection) {
2249 if (cursor.pos() == cursor.par()->Last()) {
2251 if (cursor.pos() == cursor.par()->size()) {
2253 TEXT(bv_)->CursorRight(bv_);
2254 cursor = TEXT(bv_)->cursor;
2255 if (cursor.pos() == 0
2256 && !(cursor.par()->params.spaceTop()
2257 == VSpace (VSpace::NONE))) {
2258 TEXT(bv_)->SetParagraph
2260 cursor.par()->params.lineTop(),
2261 cursor.par()->params.lineBottom(),
2262 cursor.par()->params.pagebreakTop(),
2263 cursor.par()->params.pagebreakBottom(),
2264 VSpace(VSpace::NONE),
2265 cursor.par()->params.spaceBottom(),
2266 cursor.par()->params.align(),
2267 cursor.par()->params.labelWidthString(), 0);
2268 TEXT(bv_)->CursorLeft(bv_);
2270 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2272 TEXT(bv_)->CursorLeft(bv_);
2273 TEXT(bv_)->Delete(bv_);
2274 TEXT(bv_)->sel_cursor =
2277 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2280 TEXT(bv_)->Delete(bv_);
2281 TEXT(bv_)->sel_cursor =
2284 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2292 /* -------> Delete word forward. */
2293 case LFUN_DELETE_WORD_FORWARD:
2294 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2295 TEXT(bv_)->DeleteWordForward(bv_);
2296 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2297 moveCursorUpdate(false);
2298 owner_->showState();
2301 /* -------> Delete word backward. */
2302 case LFUN_DELETE_WORD_BACKWARD:
2303 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2304 TEXT(bv_)->DeleteWordBackward(bv_);
2305 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2306 moveCursorUpdate(false);
2307 owner_->showState();
2310 /* -------> Kill to end of line. */
2311 case LFUN_DELETE_LINE_FORWARD:
2312 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2313 TEXT(bv_)->DeleteLineForward(bv_);
2314 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2315 moveCursorUpdate(false);
2318 /* -------> Set mark off. */
2320 beforeChange(TEXT(bv_));
2321 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2322 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2323 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2326 /* -------> Set mark on. */
2328 beforeChange(TEXT(bv_));
2329 TEXT(bv_)->mark_set = 1;
2330 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2331 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2332 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2335 case LFUN_BACKSPACE:
2337 if (!TEXT(bv_)->selection) {
2338 if (owner_->getIntl()->getTrans().backspace()) {
2339 TEXT(bv_)->Backspace(bv_);
2340 TEXT(bv_)->sel_cursor =
2343 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2344 // It is possible to make it a lot faster still
2345 // just comment out the line below...
2351 owner_->showState();
2356 case LFUN_BACKSPACE_SKIP:
2358 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2360 LyXCursor cursor = TEXT(bv_)->cursor;
2362 if (!TEXT(bv_)->selection) {
2363 if (cursor.pos() == 0
2364 && !(cursor.par()->params.spaceTop()
2365 == VSpace (VSpace::NONE))) {
2366 TEXT(bv_)->SetParagraph
2368 cursor.par()->params.lineTop(),
2369 cursor.par()->params.lineBottom(),
2370 cursor.par()->params.pagebreakTop(),
2371 cursor.par()->params.pagebreakBottom(),
2372 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2373 cursor.par()->params.align(),
2374 cursor.par()->params.labelWidthString(), 0);
2376 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2378 TEXT(bv_)->Backspace(bv_);
2379 TEXT(bv_)->sel_cursor
2382 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2389 case LFUN_BREAKPARAGRAPH:
2391 beforeChange(TEXT(bv_));
2392 TEXT(bv_)->BreakParagraph(bv_, 0);
2394 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2395 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2397 owner_->showState();
2401 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2403 beforeChange(TEXT(bv_));
2404 TEXT(bv_)->BreakParagraph(bv_, 1);
2406 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2407 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2409 owner_->showState();
2413 case LFUN_BREAKPARAGRAPH_SKIP:
2415 // When at the beginning of a paragraph, remove
2416 // indentation and add a "defskip" at the top.
2417 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2419 LyXCursor cursor = TEXT(bv_)->cursor;
2421 beforeChange(TEXT(bv_));
2422 if (cursor.pos() == 0) {
2423 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2424 TEXT(bv_)->SetParagraph
2426 cursor.par()->params.lineTop(),
2427 cursor.par()->params.lineBottom(),
2428 cursor.par()->params.pagebreakTop(),
2429 cursor.par()->params.pagebreakBottom(),
2430 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2431 cursor.par()->params.align(),
2432 cursor.par()->params.labelWidthString(), 1);
2433 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2437 TEXT(bv_)->BreakParagraph(bv_, 0);
2438 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2442 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2443 TEXT(bv_)->sel_cursor = cursor;
2445 owner_->showState();
2449 case LFUN_PARAGRAPH_SPACING:
2451 LyXParagraph * par = TEXT(bv_)->cursor.par();
2452 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2453 float cur_value = 1.0;
2454 if (cur_spacing == Spacing::Other) {
2455 cur_value = par->params.spacing().getValue();
2458 istringstream istr(argument.c_str());
2462 Spacing::Space new_spacing = cur_spacing;
2463 float new_value = cur_value;
2465 lyxerr << "Missing argument to `paragraph-spacing'"
2467 } else if (tmp == "single") {
2468 new_spacing = Spacing::Single;
2469 } else if (tmp == "onehalf") {
2470 new_spacing = Spacing::Onehalf;
2471 } else if (tmp == "double") {
2472 new_spacing = Spacing::Double;
2473 } else if (tmp == "other") {
2474 new_spacing = Spacing::Other;
2477 lyxerr << "new_value = " << tmpval << endl;
2480 } else if (tmp == "default") {
2481 new_spacing = Spacing::Default;
2483 lyxerr << _("Unknown spacing argument: ")
2484 << argument << endl;
2486 if (cur_spacing != new_spacing || cur_value != new_value) {
2487 par->params.spacing(Spacing(new_spacing, new_value));
2488 TEXT(bv_)->RedoParagraph(bv_);
2490 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2496 beforeChange(TEXT(bv_));
2497 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2498 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2499 moveCursorUpdate(false);
2505 InsetCommandParams p;
2506 if (action == LFUN_HTMLURL)
2507 p.setCmdName("htmlurl");
2509 p.setCmdName("url");
2510 owner_->getDialogs()->createUrl( p.getAsString() );
2514 case LFUN_INSERT_URL:
2516 InsetCommandParams p;
2517 p.setFromString( argument );
2519 InsetUrl * inset = new InsetUrl( p );
2520 if (!bv_->insertInset(inset))
2523 bv_->updateInset( inset, true );
2527 case LFUN_INSET_TEXT:
2529 InsetText * new_inset = new InsetText;
2530 if (bv_->insertInset(new_inset))
2531 new_inset->Edit(bv_, 0, 0, 0);
2537 case LFUN_INSET_ERT:
2539 InsetERT * new_inset = new InsetERT;
2540 if (bv_->insertInset(new_inset))
2541 new_inset->Edit(bv_, 0, 0, 0);
2547 case LFUN_INSET_EXTERNAL:
2549 InsetExternal * new_inset = new InsetExternal;
2550 if (bv_->insertInset(new_inset))
2551 new_inset->Edit(bv_, 0, 0, 0);
2557 case LFUN_INSET_FOOTNOTE:
2559 InsetFoot * new_inset = new InsetFoot;
2560 if (bv_->insertInset(new_inset))
2561 new_inset->Edit(bv_, 0, 0, 0);
2567 case LFUN_INSET_MARGINAL:
2569 InsetMarginal * new_inset = new InsetMarginal;
2570 if (bv_->insertInset(new_inset))
2571 new_inset->Edit(bv_, 0, 0, 0);
2577 case LFUN_INSET_MINIPAGE:
2579 InsetMinipage * new_inset = new InsetMinipage;
2580 if (bv_->insertInset(new_inset))
2581 new_inset->Edit(bv_, 0, 0, 0);
2587 case LFUN_INSET_FLOAT:
2589 // check if the float type exist
2590 if (floatList.typeExist(argument)) {
2591 InsetFloat * new_inset = new InsetFloat(argument);
2592 if (bv_->insertInset(new_inset))
2593 new_inset->Edit(bv_, 0, 0, 0);
2597 lyxerr << "Non-existant float type: "
2598 << argument << endl;
2604 case LFUN_INSET_LIST:
2606 InsetList * new_inset = new InsetList;
2607 if (bv_->insertInset(new_inset))
2608 new_inset->Edit(bv_, 0, 0, 0);
2614 case LFUN_INSET_THEOREM:
2616 InsetTheorem * new_inset = new InsetTheorem;
2617 if (bv_->insertInset(new_inset))
2618 new_inset->Edit(bv_, 0, 0, 0);
2624 case LFUN_INSET_CAPTION:
2626 // Do we have a locking inset...
2627 if (bv_->theLockingInset()) {
2628 lyxerr << "Locking inset code: "
2629 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2630 InsetCaption * new_inset = new InsetCaption;
2631 new_inset->setOwner(bv_->theLockingInset());
2632 new_inset->SetAutoBreakRows(true);
2633 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2634 new_inset->SetFrameColor(0, LColor::footnoteframe);
2635 if (bv_->insertInset(new_inset))
2636 new_inset->Edit(bv_, 0, 0, 0);
2643 case LFUN_INSET_TABULAR:
2646 if (!argument.empty())
2647 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2648 InsetTabular * new_inset =
2649 new InsetTabular(*buffer_, r, c);
2651 TEXT(bv_)->real_current_font.isRightToLeft();
2652 if (!bv_->open_new_inset(new_inset, rtl))
2657 // --- lyxserver commands ----------------------------
2659 case LFUN_CHARATCURSOR:
2661 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2662 if (pos < TEXT(bv_)->cursor.par()->size())
2663 owner_->getLyXFunc()->setMessage(
2664 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2666 owner_->getLyXFunc()->setMessage("EOF");
2671 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2673 + tostr(TEXT(bv_)->cursor.y()));
2680 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2681 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2685 case LFUN_GETLAYOUT:
2686 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2691 LyXFont & font = TEXT(bv_)->current_font;
2692 if (font.shape() == LyXFont::ITALIC_SHAPE)
2693 owner_->getLyXFunc()->setMessage("E");
2694 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2695 owner_->getLyXFunc()->setMessage("N");
2697 owner_->getLyXFunc()->setMessage("0");
2704 LyXFont & font = TEXT(bv_)->current_font;
2705 if (font.latex() == LyXFont::ON)
2706 owner_->getLyXFunc()->setMessage("L");
2708 owner_->getLyXFunc()->setMessage("0");
2712 // --- accented characters ---------------------------
2715 case LFUN_CIRCUMFLEX:
2725 case LFUN_SPECIAL_CARON:
2728 case LFUN_HUNG_UMLAUT:
2731 owner_->getLyXFunc()->handleKeyFunc(action);
2734 // --- insert characters ----------------------------------------
2736 case LFUN_MATH_DELIM:
2737 case LFUN_INSERT_MATRIX:
2740 if (bv_->open_new_inset(new InsetFormula(false)))
2742 bv_->theLockingInset()
2743 ->LocalDispatch(bv_, action, argument);
2749 case LFUN_INSERT_MATH:
2751 math_insert_symbol(bv_, argument);
2755 case LFUN_MATH_DISPLAY:
2758 bv_->open_new_inset(new InsetFormula(true));
2762 case LFUN_MATH_MACRO:
2767 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2769 string const s1 = token(s, ' ', 1);
2770 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2771 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2777 case LFUN_MATH_MODE: // Open or create a math inset
2780 bv_->open_new_inset(new InsetFormula);
2781 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2785 case LFUN_CITATION_INSERT:
2787 InsetCommandParams p;
2788 p.setFromString( argument );
2790 InsetCitation * inset = new InsetCitation( p );
2791 if (!bv_->insertInset(inset))
2794 bv_->updateInset( inset, true );
2798 case LFUN_INSERT_BIBTEX:
2800 // ale970405+lasgoutt970425
2801 // The argument can be up to two tokens separated
2802 // by a space. The first one is the bibstyle.
2803 string const db = token(argument, ' ', 0);
2804 string bibstyle = token(argument, ' ', 1);
2805 if (bibstyle.empty())
2808 InsetCommandParams p( "BibTeX", db, bibstyle );
2809 InsetBibtex * inset = new InsetBibtex(p);
2811 if (bv_->insertInset(inset)) {
2812 if (argument.empty())
2813 inset->Edit(bv_, 0, 0, 0);
2819 // BibTeX data bases
2820 case LFUN_BIBDB_ADD:
2822 InsetBibtex * inset =
2823 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2825 inset->addDatabase(argument);
2830 case LFUN_BIBDB_DEL:
2832 InsetBibtex * inset =
2833 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2835 inset->delDatabase(argument);
2840 case LFUN_BIBTEX_STYLE:
2842 InsetBibtex * inset =
2843 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2845 inset->setOptions(argument);
2850 case LFUN_INDEX_CREATE:
2852 InsetCommandParams p( "index" );
2854 if (argument.empty()) {
2855 // Get the word immediately preceding the cursor
2856 LyXParagraph::size_type curpos =
2857 TEXT(bv_)->cursor.pos() - 1;
2861 curstring = TEXT(bv_)
2862 ->cursor.par()->GetWord(curpos);
2864 p.setContents( curstring );
2866 p.setContents( argument );
2869 owner_->getDialogs()->createIndex( p.getAsString() );
2873 case LFUN_INDEX_INSERT:
2875 InsetCommandParams p;
2876 p.setFromString(argument);
2877 InsetIndex * inset = new InsetIndex(p);
2879 if (!bv_->insertInset(inset))
2882 bv_->updateInset(inset, true);
2886 case LFUN_INDEX_INSERT_LAST:
2888 // Get word immediately preceding the cursor
2889 LyXParagraph::size_type curpos =
2890 TEXT(bv_)->cursor.pos() - 1;
2891 // Can't do that at the beginning of a paragraph
2892 if (curpos < 0) break;
2894 string const curstring(TEXT(bv_)
2895 ->cursor.par()->GetWord(curpos));
2897 InsetCommandParams p("index", curstring);
2898 InsetIndex * inset = new InsetIndex(p);
2900 if (!bv_->insertInset(inset))
2903 bv_->updateInset(inset, true);
2907 case LFUN_INDEX_PRINT:
2909 InsetCommandParams p("printindex");
2910 Inset * inset = new InsetPrintIndex(p);
2911 if (!bv_->insertInset(inset, "Standard", true))
2916 case LFUN_PARENTINSERT:
2918 lyxerr << "arg " << argument << endl;
2919 InsetCommandParams p( "lyxparent", argument );
2920 Inset * inset = new InsetParent(p, *buffer_);
2921 if (!bv_->insertInset(inset, "Standard", true))
2926 case LFUN_CHILD_INSERT:
2928 InsetCommandParams p;
2929 p.setFromString(argument);
2931 InsetInclude * inset = new InsetInclude(p, *buffer_);
2932 if (!bv_->insertInset(inset))
2935 bv_->updateInset(inset, true);
2939 case LFUN_INSERT_NOTE:
2943 case LFUN_SELFINSERT:
2945 LyXFont const old_font(TEXT(bv_)->real_current_font);
2946 for (string::size_type i = 0; i < argument.length(); ++i) {
2947 TEXT(bv_)->InsertChar(bv_, argument[i]);
2948 // This needs to be in the loop, or else we
2949 // won't break lines correctly. (Asger)
2951 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2953 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2954 moveCursorUpdate(false);
2956 // real_current_font.number can change so we need to
2957 // update the minibuffer
2958 if (old_font != TEXT(bv_)->real_current_font)
2959 owner_->showState();
2963 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2967 time_t now_time_t = time(NULL);
2968 now_tm = localtime(&now_time_t);
2969 setlocale(LC_TIME, "");
2971 if (!argument.empty())
2974 arg = lyxrc.date_insert_format;
2976 int const datetmp_len =
2977 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2978 for (int i = 0; i < datetmp_len; i++) {
2979 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2981 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2984 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2985 moveCursorUpdate(false);
2989 case LFUN_UNKNOWN_ACTION:
2992 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2996 if (buffer_->isReadonly()) {
2997 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
3000 if (!argument.empty()) {
3001 /* Automatically delete the currently selected
3002 * text and replace it with what is being
3003 * typed in now. Depends on lyxrc settings
3004 * "auto_region_delete", which defaults to
3007 if (lyxrc.auto_region_delete) {
3008 if (TEXT(bv_)->selection){
3009 TEXT(bv_)->CutSelection(bv_, false);
3011 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3015 beforeChange(TEXT(bv_));
3016 LyXFont const old_font(TEXT(bv_)->real_current_font);
3017 for (string::size_type i = 0;
3018 i < argument.length(); ++i) {
3019 if (greek_kb_flag) {
3020 if (!math_insert_greek(bv_,
3022 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3024 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3027 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3029 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3030 moveCursorUpdate(false);
3032 // real_current_font.number can change so we need to
3033 // update the minibuffer
3034 if (old_font != TEXT(bv_)->real_current_font)
3035 owner_->showState();
3037 // if we don't have an argument there was something
3038 // strange going on so we just tell this to someone!
3039 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));