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
75 /* the selection possible is needed, that only motion events are
76 * used, where the bottom press event was on the drawing area too */
77 bool selection_possible = false;
79 extern BufferList bufferlist;
80 extern char ascii_type;
82 extern void sigchldhandler(pid_t pid, int * status);
83 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
85 const unsigned int saved_positions_num = 20;
90 XSync(fl_get_display(), 0);
95 void SetXtermCursor(Window win)
98 static bool cursor_undefined = true;
99 if (cursor_undefined){
100 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
101 XFlush(fl_get_display());
102 cursor_undefined = false;
104 XDefineCursor(fl_get_display(), win, cursor);
105 XFlush(fl_get_display());
109 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
110 int xpos, int ypos, int width, int height)
111 : bv_(b), owner_(o), buffer_(0),
112 current_scrollbar_value(0), cursor_timeout(400),
113 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
116 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
117 workarea_.workAreaExpose
118 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
119 workarea_.workAreaEnter
120 .connect(slot(this, &BufferView::Pimpl::enterView));
121 workarea_.workAreaLeave
122 .connect(slot(this, &BufferView::Pimpl::leaveView));
123 workarea_.workAreaButtonPress
124 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
125 workarea_.workAreaButtonRelease
127 &BufferView::Pimpl::workAreaButtonRelease));
128 workarea_.workAreaMotionNotify
129 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
130 workarea_.workAreaDoubleClick
131 .connect(slot(this, &BufferView::Pimpl::doubleClick));
132 workarea_.workAreaTripleClick
133 .connect(slot(this, &BufferView::Pimpl::tripleClick));
134 workarea_.workAreaKeyPress
135 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
139 cursor_timeout.timeout.connect(slot(this,
140 &BufferView::Pimpl::cursorToggle));
141 //current_scrollbar_value = 0;
142 cursor_timeout.start();
143 workarea_.setFocus();
144 //using_xterm_cursor = false;
145 saved_positions.resize(saved_positions_num);
149 Painter & BufferView::Pimpl::painter()
151 return workarea_.getPainter();
155 void BufferView::Pimpl::buffer(Buffer * b)
157 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
161 buffer_->delUser(bv_);
163 // Put the old text into the TextCache, but
164 // only if the buffer is still loaded.
165 // Also set the owner of the test to 0
166 // bv_->text->owner(0);
167 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
168 if (lyxerr.debugging())
169 textcache.show(lyxerr, "BufferView::buffer");
174 // Set current buffer
177 if (bufferlist.getState() == BufferList::CLOSING) return;
180 // screen is always deleted when the buffer is changed.
185 // If we are closing the buffer, use the first buffer as current
187 buffer_ = bufferlist.first();
191 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
192 buffer_->addUser(bv_);
193 // If we don't have a text object for this, we make one
194 if (bv_->text == 0) {
195 resizeCurrentBuffer();
200 bv_->text->first = screen_->TopCursorVisible(bv_->text);
201 owner_->updateMenubar();
202 owner_->updateToolbar();
203 // Similarly, buffer-dependent dialogs should be updated or
204 // hidden. This should go here because some dialogs (eg ToC)
205 // require bv_->text.
206 owner_->getDialogs()->updateBufferDependent(true);
210 lyxerr[Debug::INFO] << " No Buffer!" << endl;
211 owner_->updateMenubar();
212 owner_->updateToolbar();
213 owner_->getDialogs()->hideBufferDependent();
217 // Also remove all remaining text's from the testcache.
218 // (there should not be any!) (if there is any it is a
220 if (lyxerr.debugging())
221 textcache.show(lyxerr, "buffer delete all");
224 // should update layoutchoice even if we don't have a buffer.
225 owner_->updateLayoutChoice();
226 owner_->getMiniBuffer()->Init();
227 owner_->updateWindowTitle();
231 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
233 workarea_.resize(xpos, ypos, width, height);
234 update(bv_->text, SELECT);
239 void BufferView::Pimpl::resize()
242 resizeCurrentBuffer();
246 void BufferView::Pimpl::redraw()
248 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
253 bool BufferView::Pimpl::fitCursor(LyXText * text)
255 Assert(screen_.get());
257 bool ret = screen_->FitCursor(text, bv_);
264 void BufferView::Pimpl::redoCurrentBuffer()
266 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
267 if (buffer_ && bv_->text) {
269 owner_->updateLayoutChoice();
274 int BufferView::Pimpl::resizeCurrentBuffer()
276 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
278 LyXParagraph * par = 0;
279 LyXParagraph * selstartpar = 0;
280 LyXParagraph * selendpar = 0;
281 UpdatableInset * the_locking_inset = 0;
283 LyXParagraph::size_type pos = 0;
284 LyXParagraph::size_type selstartpos = 0;
285 LyXParagraph::size_type selendpos = 0;
286 bool selection = false;
287 bool mark_set = false;
291 owner_->getMiniBuffer()->Set(_("Formatting document..."));
294 par = bv_->text->cursor.par();
295 pos = bv_->text->cursor.pos();
296 selstartpar = bv_->text->sel_start_cursor.par();
297 selstartpos = bv_->text->sel_start_cursor.pos();
298 selendpar = bv_->text->sel_end_cursor.par();
299 selendpos = bv_->text->sel_end_cursor.pos();
300 selection = bv_->text->selection;
301 mark_set = bv_->text->mark_set;
302 the_locking_inset = bv_->text->the_locking_inset;
304 bv_->text = new LyXText(bv_);
306 // See if we have a text in TextCache that fits
307 // the new buffer_ with the correct width.
308 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
310 if (lyxerr.debugging()) {
311 lyxerr << "Found a LyXText that fits:\n";
312 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
314 // Set the owner of the newly found text
315 // bv_->text->owner(bv_);
316 if (lyxerr.debugging())
317 textcache.show(lyxerr, "resizeCurrentBuffer");
319 bv_->text = new LyXText(bv_);
325 bv_->text->selection = true;
326 /* at this point just to avoid the Delete-Empty-Paragraph
327 * Mechanism when setting the cursor */
328 bv_->text->mark_set = mark_set;
330 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
331 bv_->text->sel_cursor = bv_->text->cursor;
332 bv_->text->SetCursor(bv_, selendpar, selendpos);
333 bv_->text->SetSelection(bv_);
334 bv_->text->SetCursor(bv_, par, pos);
336 bv_->text->SetCursor(bv_, par, pos);
337 bv_->text->sel_cursor = bv_->text->cursor;
338 bv_->text->selection = false;
340 // remake the inset locking
341 bv_->text->the_locking_inset = the_locking_inset;
343 bv_->text->first = screen_->TopCursorVisible(bv_->text);
344 buffer_->resizeInsets(bv_);
345 // this will scroll the screen such that the cursor becomes visible
348 owner_->getMiniBuffer()->Init();
352 /// get rid of the splash screen if it's not gone already
353 owner_->getDialogs()->destroySplash();
359 void BufferView::Pimpl::updateScreen()
361 // Regenerate the screen.
362 screen_.reset(new LyXScreen(workarea_));
364 //screen_ = new LyXScreen(workarea_);
368 void BufferView::Pimpl::updateScrollbar()
370 /* If the text is smaller than the working area, the scrollbar
371 * maximum must be the working area height. No scrolling will
375 workarea_.setScrollbar(0, 1.0);
379 static unsigned long max2 = 0;
380 static unsigned long height2 = 0;
382 unsigned long cbth = 0;
386 cbth = bv_->text->height;
387 cbsf = bv_->text->first;
390 // check if anything has changed.
392 height2 == workarea_.height() &&
393 current_scrollbar_value == cbsf)
396 height2 = workarea_.height();
397 current_scrollbar_value = cbsf;
399 if (cbth <= height2) { // text is smaller than screen
400 workarea_.setScrollbar(0, 1.0); // right?
404 long maximum_height = workarea_.height() * 3 / 4 + cbth;
408 double hfloat = workarea_.height();
409 double maxfloat = maximum_height;
411 float slider_size = 0.0;
412 int slider_value = value;
414 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
415 double const lineh = bv_->text->DefaultHeight();
416 workarea_.setScrollbarIncrements(lineh);
417 if (maxfloat > 0.0) {
418 if ((hfloat / maxfloat) * float(height2) < 3)
419 slider_size = 3.0/float(height2);
421 slider_size = hfloat / maxfloat;
423 slider_size = hfloat;
425 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
429 // Callback for scrollbar slider
430 void BufferView::Pimpl::scrollCB(double value)
432 if (!buffer_) return;
434 current_scrollbar_value = long(value);
435 if (current_scrollbar_value < 0)
436 current_scrollbar_value = 0;
441 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
443 if (!lyxrc.cursor_follows_scrollbar) {
448 LyXText * vbt = bv_->text;
450 int const height = vbt->DefaultHeight();
451 int const first = static_cast<int>((bv_->text->first + height));
452 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
454 if (vbt->cursor.y() < first)
455 vbt->SetCursorFromCoordinates(bv_, 0, first);
456 else if (vbt->cursor.y() > last)
457 vbt->SetCursorFromCoordinates(bv_, 0, last);
463 int BufferView::Pimpl::scrollUp(long time)
465 if (!buffer_) return 0;
466 if (!screen_.get()) return 0;
468 double value = workarea_.getScrollbarValue();
470 if (value == 0) return 0;
472 float add_value = (bv_->text->DefaultHeight()
473 + float(time) * float(time) * 0.125);
475 if (add_value > workarea_.height())
476 add_value = float(workarea_.height() -
477 bv_->text->DefaultHeight());
484 workarea_.setScrollbarValue(value);
491 int BufferView::Pimpl::scrollDown(long time)
493 if (!buffer_) return 0;
494 if (!screen_.get()) return 0;
496 double value = workarea_.getScrollbarValue();
497 pair<float, float> p = workarea_.getScrollbarBounds();
498 double max = p.second;
500 if (value == max) return 0;
502 float add_value = (bv_->text->DefaultHeight()
503 + float(time) * float(time) * 0.125);
505 if (add_value > workarea_.height())
506 add_value = float(workarea_.height() -
507 bv_->text->DefaultHeight());
514 workarea_.setScrollbarValue(value);
521 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
523 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
527 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
529 // Only use motion with button 1
530 if (!(state & Button1MotionMask))
533 if (!buffer_ || !screen_.get()) return;
535 // Check for inset locking
536 if (bv_->theLockingInset()) {
537 LyXCursor cursor = bv_->text->cursor;
538 LyXFont font = bv_->text->GetFont(bv_->buffer(),
539 cursor.par(), cursor.pos());
540 int width = bv_->theLockingInset()->width(bv_, font);
541 int inset_x = font.isVisibleRightToLeft()
542 ? cursor.x() - width : cursor.x();
543 int start_x = inset_x + bv_->theLockingInset()->scroll();
544 bv_->theLockingInset()->
545 InsetMotionNotify(bv_,
547 y - cursor.y() + bv_->text->first,
552 /* The test for not selection possible is needed, that only motion events are
553 * used, where the bottom press event was on the drawing area too */
554 if (!selection_possible)
557 screen_->HideCursor();
559 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
561 if (!bv_->text->selection)
562 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
564 bv_->text->SetSelection(bv_);
565 screen_->ToggleToggle(bv_->text, bv_);
566 fitCursor(bv_->text);
567 screen_->ShowCursor(bv_->text, bv_);
571 // Single-click on work area
572 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
578 if (!buffer_ || !screen_.get()) return;
580 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
582 // ok ok, this is a hack.
583 if (button == 4 || button == 5) {
586 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
589 scrollDown(lyxrc.wheel_jump);
594 if (bv_->theLockingInset()) {
595 // We are in inset locking mode
597 /* Check whether the inset was hit. If not reset mode,
598 otherwise give the event to the inset */
599 if (inset_hit == bv_->theLockingInset()) {
600 bv_->theLockingInset()->
601 InsetButtonPress(bv_,
606 bv_->unlockInset(bv_->theLockingInset());
611 selection_possible = true;
612 screen_->HideCursor();
614 int const screen_first = bv_->text->first;
616 // Middle button press pastes if we have a selection
617 bool paste_internally = false;
619 && bv_->text->selection) {
620 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
621 paste_internally = true;
624 // Clear the selection
625 screen_->ToggleSelection(bv_->text, bv_);
626 bv_->text->ClearSelection(bv_);
627 bv_->text->FullRebreak(bv_);
628 screen_->Update(bv_->text, bv_);
631 // Single left click in math inset?
632 if ((inset_hit != 0) &&
633 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
634 // Highly editable inset, like math
635 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
636 selection_possible = false;
637 owner_->updateLayoutChoice();
638 owner_->getMiniBuffer()->Set(inset->EditMessage());
639 inset->InsetButtonPress(bv_, xpos, ypos, button);
640 inset->Edit(bv_, xpos, ypos, button);
644 // Right click on a footnote flag opens float menu
646 selection_possible = false;
650 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
651 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
652 bv_->text->FinishUndo();
653 bv_->text->sel_cursor = bv_->text->cursor;
654 bv_->text->cursor.x_fix(bv_->text->cursor.x());
656 owner_->updateLayoutChoice();
657 if (fitCursor(bv_->text)) {
658 selection_possible = false;
661 // Insert primary selection with middle mouse
662 // if there is a local selection in the current buffer,
665 if (paste_internally)
666 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
668 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
670 selection_possible = false;
676 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
682 LyXText * text = bv_->getLyXText();
684 if (text->bv_owner && bv_->theLockingInset())
687 if (screen_.get() && button == 1) {
688 if (text->bv_owner) {
689 screen_->HideCursor();
690 screen_->ToggleSelection(text, bv_);
691 text->SelectWord(bv_);
692 screen_->ToggleSelection(text, bv_, false);
694 text->SelectWord(bv_);
696 /* This will fit the cursor on the screen
698 update(text, BufferView::SELECT|BufferView::FITCUR);
703 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
709 LyXText * text = bv_->getLyXText();
711 if (text->bv_owner && bv_->theLockingInset())
714 if (screen_.get() && (button == 1)) {
715 screen_->HideCursor();
716 screen_->ToggleSelection(text, bv_);
717 text->CursorHome(bv_);
718 text->sel_cursor = text->cursor;
719 text->CursorEnd(bv_);
720 text->SetSelection(bv_);
721 screen_->ToggleSelection(text, bv_, false);
722 /* This will fit the cursor on the screen
724 update(text, BufferView::SELECT|BufferView::FITCUR);
729 void BufferView::Pimpl::enterView()
731 if (active() && available()) {
732 SetXtermCursor(workarea_.getWin());
733 using_xterm_cursor = true;
738 void BufferView::Pimpl::leaveView()
740 if (using_xterm_cursor) {
741 XUndefineCursor(fl_get_display(), workarea_.getWin());
742 using_xterm_cursor = false;
747 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
750 if (!buffer_ || !screen_.get()) return;
752 // If we hit an inset, we have the inset coordinates in these
753 // and inset_hit points to the inset. If we do not hit an
754 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
755 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
757 if (bv_->theLockingInset()) {
758 // We are in inset locking mode.
760 /* LyX does a kind of work-area grabbing for insets.
761 Only a ButtonPress Event outside the inset will
762 force a InsetUnlock. */
763 bv_->theLockingInset()->
764 InsetButtonRelease(bv_, x, y, button);
768 selection_possible = false;
770 if (button >= 2) return;
775 // Did we hit an editable inset?
777 // Inset like error, notes and figures
778 selection_possible = false;
780 // CHECK fix this proper in 0.13
782 // Following a ref shouldn't issue
783 // a push on the undo-stack
784 // anylonger, now that we have
785 // keybindings for following
786 // references and returning from
787 // references. IMHO though, it
788 // should be the inset's own business
789 // to push or not push on the undo
790 // stack. They don't *have* to
791 // alter the document...
793 // ...or maybe the SetCursorParUndo()
794 // below isn't necessary at all anylonger?
795 if (inset_hit->LyxCode() == Inset::REF_CODE) {
796 bv_->text->SetCursorParUndo(bv_->buffer());
799 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
800 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
801 // Highly editable inset, like math
802 UpdatableInset *inset = (UpdatableInset *)inset_hit;
803 inset->InsetButtonRelease(bv_, x, y, button);
805 inset_hit->InsetButtonRelease(bv_, x, y, button);
806 inset_hit->Edit(bv_, x, y, button);
812 // check whether we want to open a float
816 if (bv_->text->cursor.pos() <
817 bv_->text->cursor.par()->Last()) {
818 c = bv_->text->cursor.par()->
819 GetChar(bv_->text->cursor.pos());
821 if(!bv_->text->selection)
822 if (c == LyXParagraph::META_FOOTNOTE
823 || c == LyXParagraph::META_MARGIN
824 || c == LyXParagraph::META_FIG
825 || c == LyXParagraph::META_TAB
826 || c == LyXParagraph::META_WIDE_FIG
827 || c == LyXParagraph::META_WIDE_TAB
828 || c == LyXParagraph::META_ALGORITHM){
831 if (bv_->text->cursor.pos() - 1 >= 0) {
832 c = bv_->text->cursor.par()->
833 GetChar(bv_->text->cursor.pos() - 1);
834 if (c == LyXParagraph::META_FOOTNOTE
835 || c == LyXParagraph::META_MARGIN
836 || c == LyXParagraph::META_FIG
837 || c == LyXParagraph::META_TAB
838 || c == LyXParagraph::META_WIDE_FIG
839 || c == LyXParagraph::META_WIDE_TAB
840 || c == LyXParagraph::META_ALGORITHM){
841 // We are one step too far to the right
842 bv_->text->CursorLeft(bv_);
848 selection_possible = false;
852 // Do we want to close a float? (click on the float-label)
853 if (bv_->text->cursor.row()->par()->footnoteflag ==
854 LyXParagraph::OPEN_FOOTNOTE
855 && bv_->text->cursor.row()->previous() &&
856 bv_->text->cursor.row()->previous()->par()->
857 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
858 LyXFont font(LyXFont::ALL_SANE);
859 font.setSize(LyXFont::SIZE_FOOTNOTE);
861 int box_x = 20; // LYX_PAPER_MARGIN;
862 box_x += lyxfont::width(" wide-tab ", font);
864 unsigned int screen_first = bv_->text->first;
867 && y + screen_first > bv_->text->cursor.y() -
868 bv_->text->cursor.row()->baseline()
869 && y + screen_first < bv_->text->cursor.y() -
870 bv_->text->cursor.row()->baseline()
871 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
873 selection_possible = false;
878 // check whether we want to open a float
882 if (bv_->text->cursor.pos() <
883 bv_->text->cursor.par()->size()) {
884 c = bv_->text->cursor.par()->
885 GetChar(bv_->text->cursor.pos());
887 if (bv_->text->cursor.pos() - 1 >= 0) {
888 c = bv_->text->cursor.par()->
889 GetChar(bv_->text->cursor.pos() - 1);
892 selection_possible = false;
897 // Maybe we want to edit a bibitem ale970302
898 if (bv_->text->cursor.par()->bibkey && x < 20 +
899 bibitemMaxWidth(bv_, textclasslist.
901 params.textclass).defaultfont())) {
902 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
910 * Returns an inset if inset was hit. 0 otherwise.
911 * If hit, the coordinates are changed relative to the inset.
912 * Otherwise coordinates are not changed, and false is returned.
914 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
915 unsigned int /* button */)
920 int y_tmp = y + text->first;
923 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
926 if (cursor.pos() < cursor.par()->Last()
928 if (cursor.pos() < cursor.par()->size()
930 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
931 && cursor.par()->GetInset(cursor.pos())
932 && cursor.par()->GetInset(cursor.pos())->Editable()) {
934 // Check whether the inset really was hit
935 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
936 LyXFont font = text->GetFont(bv_->buffer(),
937 cursor.par(), cursor.pos());
938 int width = tmpinset->width(bv_, font);
939 int inset_x = font.isVisibleRightToLeft()
940 ? cursor.x() - width : cursor.x();
941 int start_x = inset_x + tmpinset->scroll();
942 int end_x = inset_x + width;
944 if (x > start_x && x < end_x
945 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
946 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
947 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
949 // The origin of an inset is on the baseline
950 y = y_tmp - (text->cursor.y());
955 if ((cursor.pos() - 1 >= 0) &&
956 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
957 (cursor.par()->GetInset(cursor.pos() - 1)) &&
958 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
959 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
960 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
962 int width = tmpinset->width(bv_, font);
963 int inset_x = font.isVisibleRightToLeft()
964 ? cursor.x() : cursor.x() - width;
965 int start_x = inset_x + tmpinset->scroll();
966 int end_x = inset_x + width;
968 if (x > start_x && x < end_x
969 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
970 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
972 if (move_cursor && (tmpinset != bv_->theLockingInset()))
974 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
976 // The origin of an inset is on the baseline
977 y = y_tmp - (text->cursor.y());
985 void BufferView::Pimpl::workAreaExpose()
987 static int work_area_width = 0;
988 static unsigned int work_area_height = 0;
990 bool widthChange = workarea_.workWidth() != work_area_width;
991 bool heightChange = workarea_.height() != work_area_height;
993 // update from work area
994 work_area_width = workarea_.workWidth();
995 work_area_height = workarea_.height();
998 // All buffers need a resize
1001 // Remove all texts from the textcache
1002 // This is not _really_ what we want to do. What
1003 // we really want to do is to delete in textcache
1004 // that does not have a BufferView with matching
1005 // width, but as long as we have only one BufferView
1006 // deleting all gives the same result.
1007 if (lyxerr.debugging())
1008 textcache.show(lyxerr, "Expose delete all");
1010 } else if (heightChange) {
1011 // Rebuild image of current screen
1013 // fitCursor() ensures we don't jump back
1014 // to the start of the document on vertical
1016 fitCursor(bv_->text);
1018 // The main window size has changed, repaint most stuff
1020 // ...including the minibuffer
1021 owner_->getMiniBuffer()->Init();
1023 } else if (screen_.get())
1024 screen_->Redraw(bv_->text, bv_);
1026 // Grey box when we don't have a buffer
1027 workarea_.greyOut();
1030 // always make sure that the scrollbar is sane.
1032 owner_->updateLayoutChoice();
1037 void BufferView::Pimpl::update()
1039 if (screen_.get()) screen_->Update(bv_->text, bv_);
1042 // Values used when calling update:
1044 // -2 - update, move sel_cursor if selection, fitcursor
1045 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1046 // 0 - update, move sel_cursor if selection, fitcursor
1047 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1048 // 3 - update, move sel_cursor if selection
1051 // a simple redraw of the parts that need refresh
1053 // move sel_cursor if selection -
1054 // the text's sel_cursor is moved if there is selection is progress
1057 // fitCursor() is called and the scrollbar updated
1060 // the buffer is marked dirty.
1069 // UPDATE_ONLY = UPDATE;
1070 // UPDATE_SELECT = UPDATE | SELECT;
1071 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1072 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1074 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1075 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1076 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1077 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1078 // update(3) -> update(1) -> update(1) -> update(SELECT)
1080 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1082 owner_->updateLayoutChoice();
1084 if (!text->selection && (f & SELECT)) {
1085 text->sel_cursor = text->cursor;
1088 text->FullRebreak(bv_);
1090 if (text->inset_owner) {
1091 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1092 bv_->updateInset(text->inset_owner, true);
1101 if (buffer_->isLyxClean()) {
1102 buffer_->markDirty();
1103 owner_->getMiniBuffer()->setTimer(4);
1105 buffer_->markDirty();
1111 // Callback for cursor timer
1112 void BufferView::Pimpl::cursorToggle()
1114 // Quite a nice place for asyncron Inset updating, isn't it?
1115 // Actually no! This is run even if no buffer exist... so (Lgb)
1117 cursor_timeout.restart();
1122 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1123 if (pid == -1) // error find out what is wrong
1124 ; // ignore it for now.
1126 sigchldhandler(pid, &status);
1128 updatelist.update(bv_);
1130 if (!screen_.get()) {
1131 cursor_timeout.restart();
1135 if (!bv_->theLockingInset()) {
1136 screen_->CursorToggle(bv_->text, bv_);
1138 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1141 cursor_timeout.restart();
1145 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1147 if (!text->cursor.row()->previous())
1150 int y = text->first;
1151 if (text->inset_owner)
1152 y += bv_->text->first;
1153 Row * cursorrow = text->cursor.row();
1154 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1155 bv_->text->FinishUndo();
1156 // This is to allow jumping over large insets
1157 if ((cursorrow == text->cursor.row()))
1158 text->CursorUp(bv_);
1160 if (text->inset_owner ||
1161 text->cursor.row()->height() < workarea_.height())
1162 screen_->Draw(bv_->text, bv_,
1164 - text->cursor.row()->baseline()
1165 + text->cursor.row()->height()
1166 - workarea_.height() + 1 );
1171 void BufferView::Pimpl::cursorNext(LyXText * text)
1173 if (!text->cursor.row()->next())
1176 int y = text->first + workarea_.height();
1177 // if (text->inset_owner)
1178 // y += bv_->text->first;
1179 text->GetRowNearY(y);
1181 Row * cursorrow = text->cursor.row();
1182 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1183 bv_->text->FinishUndo();
1184 // This is to allow jumping over large insets
1185 if ((cursorrow == bv_->text->cursor.row()))
1186 text->CursorDown(bv_);
1188 if (text->inset_owner ||
1189 text->cursor.row()->height() < workarea_.height())
1190 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1191 text->cursor.row()->baseline());
1196 bool BufferView::Pimpl::available() const
1198 if (buffer_ && bv_->text) return true;
1203 void BufferView::Pimpl::beforeChange(LyXText * text)
1206 text->ClearSelection(bv_);
1210 void BufferView::Pimpl::savePosition(unsigned int i)
1212 if (i >= saved_positions_num)
1214 saved_positions[i] = Position(buffer_->fileName(),
1215 bv_->text->cursor.par()->id(),
1216 bv_->text->cursor.pos());
1218 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1222 void BufferView::Pimpl::restorePosition(unsigned int i)
1224 if (i >= saved_positions_num)
1227 string fname = saved_positions[i].filename;
1229 beforeChange(bv_->text);
1231 if (fname != buffer_->fileName()) {
1232 Buffer * b = bufferlist.exists(fname) ?
1233 bufferlist.getBuffer(fname) :
1234 bufferlist.loadLyXFile(fname); // don't ask, just load it
1235 if (b != 0 ) buffer(b);
1238 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1243 bv_->text->SetCursor(bv_, par,
1244 min(par->Last(), saved_positions[i].par_pos));
1246 bv_->text->SetCursor(bv_, par,
1247 min(par->size(), saved_positions[i].par_pos));
1249 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1251 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1255 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1257 if (i >= saved_positions_num)
1260 return !saved_positions[i].filename.empty();
1264 void BufferView::Pimpl::setState()
1266 if (!lyxrc.rtl_support)
1269 LyXText * text = bv_->getLyXText();
1270 if (text->real_current_font.isRightToLeft() &&
1271 text->real_current_font.latex() != LyXFont::ON) {
1272 if (owner_->getIntl()->primarykeymap)
1273 owner_->getIntl()->KeyMapSec();
1275 if (!owner_->getIntl()->primarykeymap)
1276 owner_->getIntl()->KeyMapPrim();
1281 void BufferView::Pimpl::insetSleep()
1283 if (bv_->theLockingInset() && !bv_->inset_slept) {
1284 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1285 bv_->theLockingInset()->InsetUnlock(bv_);
1286 bv_->inset_slept = true;
1291 void BufferView::Pimpl::insetWakeup()
1293 if (bv_->theLockingInset() && bv_->inset_slept) {
1294 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1295 bv_->inset_slept = false;
1300 void BufferView::Pimpl::insetUnlock()
1302 if (bv_->theLockingInset()) {
1303 if (!bv_->inset_slept)
1304 bv_->theLockingInset()->InsetUnlock(bv_);
1305 bv_->theLockingInset(0);
1306 bv_->text->FinishUndo();
1307 bv_->inset_slept = false;
1312 bool BufferView::Pimpl::focus() const
1314 return workarea_.hasFocus();
1318 void BufferView::Pimpl::focus(bool f)
1320 if (f) workarea_.setFocus();
1324 bool BufferView::Pimpl::active() const
1326 return workarea_.active();
1330 bool BufferView::Pimpl::belowMouse() const
1332 return workarea_.belowMouse();
1336 void BufferView::Pimpl::showCursor()
1339 screen_->ShowCursor(bv_->text, bv_);
1343 void BufferView::Pimpl::hideCursor()
1346 screen_->HideCursor();
1350 void BufferView::Pimpl::toggleSelection(bool b)
1353 screen_->ToggleSelection(bv_->text, bv_, b);
1357 void BufferView::Pimpl::toggleToggle()
1360 screen_->ToggleToggle(bv_->text, bv_);
1364 void BufferView::Pimpl::center()
1366 beforeChange(bv_->text);
1367 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1368 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1370 screen_->Draw(bv_->text, bv_, 0);
1372 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1377 void BufferView::Pimpl::pasteClipboard(bool asPara)
1379 if (!buffer_) return;
1381 screen_->HideCursor();
1382 beforeChange(bv_->text);
1384 string const clip(workarea_.getClipboard());
1386 if (clip.empty()) return;
1389 bv_->text->InsertStringB(bv_, clip);
1391 bv_->text->InsertStringA(bv_, clip);
1393 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1397 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1399 workarea_.putClipboard(stuff);
1404 * Dispatch functions for actions which can be valid for BufferView->text
1405 * and/or InsetText->text!!!
1407 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1410 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1412 if (selecting || TEXT(bv_)->mark_set) {
1413 TEXT(bv_)->SetSelection(bv_);
1414 if (TEXT(bv_)->bv_owner)
1415 bv_->toggleToggle();
1417 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1420 /* ---> Everytime the cursor is moved, show the current font state. */
1421 // should this too me moved out of this func?
1422 //owner->showState();
1427 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1429 LyXCursor cursor = TEXT(bv_)->cursor;
1430 Buffer::inset_iterator it =
1431 find_if(Buffer::inset_iterator(
1432 cursor.par(), cursor.pos()),
1433 buffer_->inset_iterator_end(),
1434 compare_memfun(&Inset::LyxCode, code)
1436 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1440 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1442 string filename = filen;
1444 if (filename.empty()) {
1445 // Launch a file browser
1446 string initpath = lyxrc.document_path;
1449 string const trypath = owner_->buffer()->filepath;
1450 // If directory is writeable, use this as default.
1451 if (IsDirWriteable(trypath) == 1)
1455 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1457 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1458 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1460 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1462 if (result.first == FileDialog::Later)
1465 filename = result.second;
1467 // check selected filename
1468 if (filename.empty()) {
1469 owner_->getMiniBuffer()->Set(_("Canceled."));
1474 // get absolute path of file and make sure the filename ends
1476 filename = MakeAbsPath(filename);
1477 if (!IsLyXFilename(filename))
1481 owner_->getMiniBuffer()->Set(_("Inserting document"),
1482 MakeDisplayPath(filename), "...");
1483 bool const res = bv_->insertLyXFile(filename);
1485 owner_->getMiniBuffer()->Set(_("Document"),
1486 MakeDisplayPath(filename),
1489 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1490 MakeDisplayPath(filename));
1495 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1498 // --- Misc -------------------------------------------
1501 TEXT(bv_)->toggleAppendix(bv_);
1502 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1506 case LFUN_TOC_INSERT:
1507 case LFUN_LOA_INSERT:
1508 case LFUN_LOF_INSERT:
1509 case LFUN_LOT_INSERT:
1511 InsetCommandParams p;
1513 if (action == LFUN_TOC_INSERT )
1514 p.setCmdName( "tableofcontents" );
1515 else if (action == LFUN_LOA_INSERT )
1516 p.setCmdName( "listofalgorithms" );
1517 else if (action == LFUN_LOF_INSERT )
1518 p.setCmdName( "listoffigures" );
1520 p.setCmdName( "listoftables" );
1522 Inset * inset = new InsetTOC( p );
1523 if (!bv_->insertInset( inset, "Standard", true ) )
1528 case LFUN_TABULAR_FEATURE:
1529 case LFUN_SCROLL_INSET:
1530 // this is not handled here as this funktion is only aktive
1531 // if we have a locking_inset and that one is (or contains)
1535 case LFUN_INSET_GRAPHICS:
1537 Inset * new_inset = new InsetGraphics;
1538 if (!bv_->insertInset(new_inset)) {
1541 // this is need because you don't use a inset->Edit()
1542 bv_->updateInset(new_inset, true);
1543 new_inset->Edit(bv_, 0, 0, 0);
1553 case LFUN_PASTESELECTION:
1555 bool asPara = false;
1556 if (argument == "paragraph") asPara = true;
1557 pasteClipboard(asPara);
1569 case LFUN_LAYOUT_COPY:
1570 bv_->copyEnvironment();
1573 case LFUN_LAYOUT_PASTE:
1574 bv_->pasteEnvironment();
1578 case LFUN_GOTOERROR:
1579 bv_->gotoInset(Inset::ERROR_CODE, false);
1583 bv_->gotoInset(Inset::IGNORE_CODE, false);
1586 case LFUN_REFERENCE_GOTO:
1588 vector<Inset::Code> tmp;
1589 tmp.push_back(Inset::LABEL_CODE);
1590 tmp.push_back(Inset::REF_CODE);
1591 bv_->gotoInset(tmp, true);
1595 case LFUN_HYPHENATION:
1596 bv_->hyphenationPoint();
1603 case LFUN_END_OF_SENTENCE:
1604 bv_->endOfSentenceDot();
1607 case LFUN_MENU_SEPARATOR:
1608 bv_->menuSeparator();
1616 changeDepth(bv_, TEXT(bv_), 0);
1619 case LFUN_DEPTH_MIN:
1620 changeDepth(bv_, TEXT(bv_), -1);
1623 case LFUN_DEPTH_PLUS:
1624 changeDepth(bv_, TEXT(bv_), 1);
1628 owner_->getDialogs()->setUserFreeFont();
1634 owner_->showState();
1637 case LFUN_FILE_INSERT:
1639 MenuInsertLyXFile(argument);
1643 case LFUN_FILE_INSERT_ASCII_PARA:
1644 InsertAsciiFile(bv_, argument, true);
1647 case LFUN_FILE_INSERT_ASCII:
1648 InsertAsciiFile(bv_, argument, false);
1653 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1654 << argument << endl;
1656 // Derive layout number from given argument (string)
1657 // and current buffer's textclass (number). */
1658 LyXTextClassList::ClassList::size_type tclass =
1659 buffer_->params.textclass;
1660 pair <bool, LyXTextClass::size_type> layout =
1661 textclasslist.NumberOfLayout(tclass, argument);
1663 // If the entry is obsolete, use the new one instead.
1665 string obs = textclasslist.Style(tclass,layout.second)
1669 textclasslist.NumberOfLayout(tclass, obs);
1672 // see if we found the layout number:
1673 if (!layout.first) {
1674 owner_->getLyXFunc()->setErrorMessage(
1675 string(N_("Layout ")) + argument +
1680 if (current_layout != layout.second) {
1682 current_layout = layout.second;
1684 BufferView::SELECT|BufferView::FITCUR);
1685 TEXT(bv_)->SetLayout(bv_, layout.second);
1686 owner_->setLayout(layout.second);
1688 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1695 Lang(bv_, argument);
1697 owner_->showState();
1702 owner_->showState();
1707 owner_->showState();
1712 owner_->showState();
1717 owner_->showState();
1722 owner_->showState();
1727 owner_->showState();
1732 owner_->showState();
1735 case LFUN_UNDERLINE:
1737 owner_->showState();
1740 case LFUN_FONT_SIZE:
1741 FontSize(bv_, argument);
1742 owner_->showState();
1745 case LFUN_FONT_STATE:
1746 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1749 case LFUN_UPCASE_WORD:
1750 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1751 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1752 if (TEXT(bv_)->inset_owner)
1753 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1754 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1757 case LFUN_LOWCASE_WORD:
1758 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1759 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1760 if (TEXT(bv_)->inset_owner)
1761 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1762 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1765 case LFUN_CAPITALIZE_WORD:
1766 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1767 TEXT(bv_)->ChangeWordCase(bv_,
1768 LyXText::text_capitalization);
1769 if (TEXT(bv_)->inset_owner)
1770 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1771 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1774 case LFUN_INSERT_LABEL:
1775 MenuInsertLabel(bv_, argument);
1778 case LFUN_REF_INSERT:
1779 if (argument.empty()) {
1780 InsetCommandParams p("ref");
1781 owner_->getDialogs()->createRef(p.getAsString());
1783 InsetCommandParams p;
1784 p.setFromString(argument);
1786 InsetRef * inset = new InsetRef(p, *buffer_);
1787 if (!bv_->insertInset(inset))
1790 bv_->updateInset(inset, true);
1794 case LFUN_BOOKMARK_SAVE:
1795 savePosition(strToUnsignedInt(argument));
1798 case LFUN_BOOKMARK_GOTO:
1799 restorePosition(strToUnsignedInt(argument));
1804 string label(argument);
1805 if (label.empty()) {
1807 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1809 label = inset->getContents();
1814 if (!label.empty()) {
1815 //bv_->savePosition(0);
1816 if (!bv_->gotoLabel(label))
1817 WriteAlert(_("Error"),
1818 _("Couldn't find this label"),
1819 _("in current document."));
1824 // --- Cursor Movements -----------------------------
1827 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1828 if (!TEXT(bv_)->mark_set)
1829 beforeChange(TEXT(bv_));
1830 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1832 TEXT(bv_)->CursorLeft(bv_, false);
1834 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1836 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
1838 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1839 == LyXParagraph::META_INSET
1840 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1841 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1842 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1843 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1847 TEXT(bv_)->GetFont(buffer_,
1848 TEXT(bv_)->cursor.par(),
1849 TEXT(bv_)->cursor.pos());
1850 y = tmpinset->descent(bv_,font);
1852 tmpinset->Edit(bv_, 0, y, 0);
1856 TEXT(bv_)->CursorRight(bv_, false);
1857 TEXT(bv_)->FinishUndo();
1858 moveCursorUpdate(false);
1859 owner_->showState();
1865 // This is soooo ugly. Isn`t it possible to make
1866 // it simpler? (Lgb)
1867 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1868 if (!TEXT(bv_)->mark_set)
1869 beforeChange(TEXT(bv_));
1870 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1871 LyXCursor cur = TEXT(bv_)->cursor;
1873 TEXT(bv_)->CursorLeft(bv_, false);
1874 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1876 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1878 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
1880 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1881 LyXParagraph::META_INSET) &&
1882 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1883 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1884 == Inset::HIGHLY_EDITABLE))
1886 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1887 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1888 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1889 TEXT(bv_)->cursor.par(),
1890 TEXT(bv_)->cursor.pos());
1892 : tmpinset->descent(bv_,font);
1895 tmpinset->width(bv_,font),
1900 TEXT(bv_)->CursorRight(bv_, false);
1902 TEXT(bv_)->FinishUndo();
1903 moveCursorUpdate(false);
1904 owner_->showState();
1909 if (!TEXT(bv_)->mark_set)
1910 beforeChange(TEXT(bv_));
1911 update(TEXT(bv_), BufferView::UPDATE);
1912 TEXT(bv_)->CursorUp(bv_);
1913 TEXT(bv_)->FinishUndo();
1914 moveCursorUpdate(false);
1915 owner_->showState();
1919 if (!TEXT(bv_)->mark_set)
1920 beforeChange(TEXT(bv_));
1921 update(TEXT(bv_), BufferView::UPDATE);
1922 TEXT(bv_)->CursorDown(bv_);
1923 TEXT(bv_)->FinishUndo();
1924 moveCursorUpdate(false);
1925 owner_->showState();
1928 case LFUN_UP_PARAGRAPH:
1929 if (!TEXT(bv_)->mark_set)
1930 beforeChange(TEXT(bv_));
1931 update(TEXT(bv_), BufferView::UPDATE);
1932 TEXT(bv_)->CursorUpParagraph(bv_);
1933 TEXT(bv_)->FinishUndo();
1934 moveCursorUpdate(false);
1935 owner_->showState();
1938 case LFUN_DOWN_PARAGRAPH:
1939 if (!TEXT(bv_)->mark_set)
1940 beforeChange(TEXT(bv_));
1941 update(TEXT(bv_), BufferView::UPDATE);
1942 TEXT(bv_)->CursorDownParagraph(bv_);
1943 TEXT(bv_)->FinishUndo();
1944 moveCursorUpdate(false);
1945 owner_->showState();
1949 if (!TEXT(bv_)->mark_set)
1950 beforeChange(TEXT(bv_));
1951 update(TEXT(bv_), BufferView::UPDATE);
1952 cursorPrevious(TEXT(bv_));
1953 TEXT(bv_)->FinishUndo();
1954 moveCursorUpdate(false);
1955 owner_->showState();
1959 if (!TEXT(bv_)->mark_set)
1960 beforeChange(TEXT(bv_));
1961 update(TEXT(bv_), BufferView::UPDATE);
1962 cursorNext(TEXT(bv_));
1963 TEXT(bv_)->FinishUndo();
1964 moveCursorUpdate(false);
1965 owner_->showState();
1969 if (!TEXT(bv_)->mark_set)
1970 beforeChange(TEXT(bv_));
1971 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1972 TEXT(bv_)->CursorHome(bv_);
1973 TEXT(bv_)->FinishUndo();
1974 moveCursorUpdate(false);
1975 owner_->showState();
1979 if (!TEXT(bv_)->mark_set)
1980 beforeChange(TEXT(bv_));
1982 BufferView::SELECT|BufferView::FITCUR);
1983 TEXT(bv_)->CursorEnd(bv_);
1984 TEXT(bv_)->FinishUndo();
1985 moveCursorUpdate(false);
1986 owner_->showState();
1989 case LFUN_SHIFT_TAB:
1991 if (!TEXT(bv_)->mark_set)
1992 beforeChange(TEXT(bv_));
1994 BufferView::SELECT|BufferView::FITCUR);
1995 TEXT(bv_)->CursorTab(bv_);
1996 TEXT(bv_)->FinishUndo();
1997 moveCursorUpdate(false);
1998 owner_->showState();
2001 case LFUN_WORDRIGHT:
2002 if (!TEXT(bv_)->mark_set)
2003 beforeChange(TEXT(bv_));
2004 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2005 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2006 TEXT(bv_)->CursorLeftOneWord(bv_);
2008 TEXT(bv_)->CursorRightOneWord(bv_);
2009 TEXT(bv_)->FinishUndo();
2010 moveCursorUpdate(false);
2011 owner_->showState();
2015 if (!TEXT(bv_)->mark_set)
2016 beforeChange(TEXT(bv_));
2017 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2018 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2019 TEXT(bv_)->CursorRightOneWord(bv_);
2021 TEXT(bv_)->CursorLeftOneWord(bv_);
2022 TEXT(bv_)->FinishUndo();
2023 moveCursorUpdate(false);
2024 owner_->showState();
2027 case LFUN_BEGINNINGBUF:
2028 if (!TEXT(bv_)->mark_set)
2029 beforeChange(TEXT(bv_));
2031 BufferView::SELECT|BufferView::FITCUR);
2032 TEXT(bv_)->CursorTop(bv_);
2033 TEXT(bv_)->FinishUndo();
2034 moveCursorUpdate(false);
2035 owner_->showState();
2039 if (!TEXT(bv_)->mark_set)
2040 beforeChange(TEXT(bv_));
2042 BufferView::SELECT|BufferView::FITCUR);
2043 TEXT(bv_)->CursorBottom(bv_);
2044 TEXT(bv_)->FinishUndo();
2045 moveCursorUpdate(false);
2046 owner_->showState();
2050 /* cursor selection ---------------------------- */
2053 BufferView::SELECT|BufferView::FITCUR);
2054 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2055 TEXT(bv_)->CursorLeft(bv_);
2057 TEXT(bv_)->CursorRight(bv_);
2058 TEXT(bv_)->FinishUndo();
2059 moveCursorUpdate(true);
2060 owner_->showState();
2065 BufferView::SELECT|BufferView::FITCUR);
2066 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2067 TEXT(bv_)->CursorRight(bv_);
2069 TEXT(bv_)->CursorLeft(bv_);
2070 TEXT(bv_)->FinishUndo();
2071 moveCursorUpdate(true);
2072 owner_->showState();
2077 BufferView::SELECT|BufferView::FITCUR);
2078 TEXT(bv_)->CursorUp(bv_);
2079 TEXT(bv_)->FinishUndo();
2080 moveCursorUpdate(true);
2081 owner_->showState();
2086 BufferView::SELECT|BufferView::FITCUR);
2087 TEXT(bv_)->CursorDown(bv_);
2088 TEXT(bv_)->FinishUndo();
2089 moveCursorUpdate(true);
2090 owner_->showState();
2093 case LFUN_UP_PARAGRAPHSEL:
2095 BufferView::SELECT|BufferView::FITCUR);
2096 TEXT(bv_)->CursorUpParagraph(bv_);
2097 TEXT(bv_)->FinishUndo();
2098 moveCursorUpdate(true);
2099 owner_->showState();
2102 case LFUN_DOWN_PARAGRAPHSEL:
2104 BufferView::SELECT|BufferView::FITCUR);
2105 TEXT(bv_)->CursorDownParagraph(bv_);
2106 TEXT(bv_)->FinishUndo();
2107 moveCursorUpdate(true);
2108 owner_->showState();
2112 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2113 cursorPrevious(TEXT(bv_));
2114 TEXT(bv_)->FinishUndo();
2115 moveCursorUpdate(true);
2116 owner_->showState();
2120 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2121 cursorNext(TEXT(bv_));
2122 TEXT(bv_)->FinishUndo();
2123 moveCursorUpdate(true);
2124 owner_->showState();
2128 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2129 TEXT(bv_)->CursorHome(bv_);
2130 TEXT(bv_)->FinishUndo();
2131 moveCursorUpdate(true);
2132 owner_->showState();
2136 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2137 TEXT(bv_)->CursorEnd(bv_);
2138 TEXT(bv_)->FinishUndo();
2139 moveCursorUpdate(true);
2140 owner_->showState();
2143 case LFUN_WORDRIGHTSEL:
2144 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2145 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2146 TEXT(bv_)->CursorLeftOneWord(bv_);
2148 TEXT(bv_)->CursorRightOneWord(bv_);
2149 TEXT(bv_)->FinishUndo();
2150 moveCursorUpdate(true);
2151 owner_->showState();
2154 case LFUN_WORDLEFTSEL:
2155 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2156 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2157 TEXT(bv_)->CursorRightOneWord(bv_);
2159 TEXT(bv_)->CursorLeftOneWord(bv_);
2160 TEXT(bv_)->FinishUndo();
2161 moveCursorUpdate(true);
2162 owner_->showState();
2165 case LFUN_BEGINNINGBUFSEL:
2166 if (TEXT(bv_)->inset_owner)
2168 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2169 TEXT(bv_)->CursorTop(bv_);
2170 TEXT(bv_)->FinishUndo();
2171 moveCursorUpdate(true);
2172 owner_->showState();
2175 case LFUN_ENDBUFSEL:
2176 if (TEXT(bv_)->inset_owner)
2179 BufferView::SELECT|BufferView::FITCUR);
2180 TEXT(bv_)->CursorBottom(bv_);
2181 TEXT(bv_)->FinishUndo();
2182 moveCursorUpdate(true);
2183 owner_->showState();
2186 // --- text changing commands ------------------------
2187 case LFUN_BREAKLINE:
2188 beforeChange(TEXT(bv_));
2189 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2191 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2192 moveCursorUpdate(false);
2195 case LFUN_PROTECTEDSPACE:
2197 LyXLayout const & style =
2198 textclasslist.Style(buffer_->params.textclass,
2199 TEXT(bv_)->cursor.par()->GetLayout());
2201 if (style.free_spacing) {
2202 TEXT(bv_)->InsertChar(bv_, ' ');
2203 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2205 bv_->protectedBlank(TEXT(bv_));
2207 moveCursorUpdate(false);
2212 if (TEXT(bv_)->mark_set) {
2213 beforeChange(TEXT(bv_));
2214 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2215 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2217 beforeChange(TEXT(bv_));
2218 TEXT(bv_)->mark_set = 1;
2219 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2220 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2222 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2226 if (!TEXT(bv_)->selection) {
2227 TEXT(bv_)->Delete(bv_);
2228 TEXT(bv_)->sel_cursor =
2231 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2232 // It is possible to make it a lot faster still
2233 // just comment out the line below...
2238 moveCursorUpdate(false);
2239 owner_->showState();
2243 case LFUN_DELETE_SKIP:
2245 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2247 LyXCursor cursor = TEXT(bv_)->cursor;
2249 if (!TEXT(bv_)->selection) {
2251 if (cursor.pos() == cursor.par()->Last()) {
2253 if (cursor.pos() == cursor.par()->size()) {
2255 TEXT(bv_)->CursorRight(bv_);
2256 cursor = TEXT(bv_)->cursor;
2257 if (cursor.pos() == 0
2258 && !(cursor.par()->params.spaceTop()
2259 == VSpace (VSpace::NONE))) {
2260 TEXT(bv_)->SetParagraph
2262 cursor.par()->params.lineTop(),
2263 cursor.par()->params.lineBottom(),
2264 cursor.par()->params.pagebreakTop(),
2265 cursor.par()->params.pagebreakBottom(),
2266 VSpace(VSpace::NONE),
2267 cursor.par()->params.spaceBottom(),
2268 cursor.par()->params.align(),
2269 cursor.par()->params.labelWidthString(), 0);
2270 TEXT(bv_)->CursorLeft(bv_);
2272 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2274 TEXT(bv_)->CursorLeft(bv_);
2275 TEXT(bv_)->Delete(bv_);
2276 TEXT(bv_)->sel_cursor =
2279 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2282 TEXT(bv_)->Delete(bv_);
2283 TEXT(bv_)->sel_cursor =
2286 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2294 /* -------> Delete word forward. */
2295 case LFUN_DELETE_WORD_FORWARD:
2296 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2297 TEXT(bv_)->DeleteWordForward(bv_);
2298 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2299 moveCursorUpdate(false);
2300 owner_->showState();
2303 /* -------> Delete word backward. */
2304 case LFUN_DELETE_WORD_BACKWARD:
2305 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2306 TEXT(bv_)->DeleteWordBackward(bv_);
2307 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2308 moveCursorUpdate(false);
2309 owner_->showState();
2312 /* -------> Kill to end of line. */
2313 case LFUN_DELETE_LINE_FORWARD:
2314 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2315 TEXT(bv_)->DeleteLineForward(bv_);
2316 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2317 moveCursorUpdate(false);
2320 /* -------> Set mark off. */
2322 beforeChange(TEXT(bv_));
2323 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2324 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2325 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2328 /* -------> Set mark on. */
2330 beforeChange(TEXT(bv_));
2331 TEXT(bv_)->mark_set = 1;
2332 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2333 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2334 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2337 case LFUN_BACKSPACE:
2339 if (!TEXT(bv_)->selection) {
2340 if (owner_->getIntl()->getTrans().backspace()) {
2341 TEXT(bv_)->Backspace(bv_);
2342 TEXT(bv_)->sel_cursor =
2345 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2346 // It is possible to make it a lot faster still
2347 // just comment out the line below...
2353 owner_->showState();
2358 case LFUN_BACKSPACE_SKIP:
2360 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2362 LyXCursor cursor = TEXT(bv_)->cursor;
2364 if (!TEXT(bv_)->selection) {
2365 if (cursor.pos() == 0
2366 && !(cursor.par()->params.spaceTop()
2367 == VSpace (VSpace::NONE))) {
2368 TEXT(bv_)->SetParagraph
2370 cursor.par()->params.lineTop(),
2371 cursor.par()->params.lineBottom(),
2372 cursor.par()->params.pagebreakTop(),
2373 cursor.par()->params.pagebreakBottom(),
2374 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2375 cursor.par()->params.align(),
2376 cursor.par()->params.labelWidthString(), 0);
2378 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2380 TEXT(bv_)->Backspace(bv_);
2381 TEXT(bv_)->sel_cursor
2384 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2391 case LFUN_BREAKPARAGRAPH:
2393 beforeChange(TEXT(bv_));
2394 TEXT(bv_)->BreakParagraph(bv_, 0);
2396 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2397 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2399 owner_->showState();
2403 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2405 beforeChange(TEXT(bv_));
2406 TEXT(bv_)->BreakParagraph(bv_, 1);
2408 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2409 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2411 owner_->showState();
2415 case LFUN_BREAKPARAGRAPH_SKIP:
2417 // When at the beginning of a paragraph, remove
2418 // indentation and add a "defskip" at the top.
2419 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2421 LyXCursor cursor = TEXT(bv_)->cursor;
2423 beforeChange(TEXT(bv_));
2424 if (cursor.pos() == 0) {
2425 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2426 TEXT(bv_)->SetParagraph
2428 cursor.par()->params.lineTop(),
2429 cursor.par()->params.lineBottom(),
2430 cursor.par()->params.pagebreakTop(),
2431 cursor.par()->params.pagebreakBottom(),
2432 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2433 cursor.par()->params.align(),
2434 cursor.par()->params.labelWidthString(), 1);
2435 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2439 TEXT(bv_)->BreakParagraph(bv_, 0);
2440 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2444 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2445 TEXT(bv_)->sel_cursor = cursor;
2447 owner_->showState();
2451 case LFUN_PARAGRAPH_SPACING:
2453 LyXParagraph * par = TEXT(bv_)->cursor.par();
2454 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2455 float cur_value = 1.0;
2456 if (cur_spacing == Spacing::Other) {
2457 cur_value = par->params.spacing().getValue();
2460 istringstream istr(argument.c_str());
2464 Spacing::Space new_spacing = cur_spacing;
2465 float new_value = cur_value;
2467 lyxerr << "Missing argument to `paragraph-spacing'"
2469 } else if (tmp == "single") {
2470 new_spacing = Spacing::Single;
2471 } else if (tmp == "onehalf") {
2472 new_spacing = Spacing::Onehalf;
2473 } else if (tmp == "double") {
2474 new_spacing = Spacing::Double;
2475 } else if (tmp == "other") {
2476 new_spacing = Spacing::Other;
2479 lyxerr << "new_value = " << tmpval << endl;
2482 } else if (tmp == "default") {
2483 new_spacing = Spacing::Default;
2485 lyxerr << _("Unknown spacing argument: ")
2486 << argument << endl;
2488 if (cur_spacing != new_spacing || cur_value != new_value) {
2489 par->params.spacing(Spacing(new_spacing, new_value));
2490 TEXT(bv_)->RedoParagraph(bv_);
2492 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2498 beforeChange(TEXT(bv_));
2499 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2500 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2501 moveCursorUpdate(false);
2507 InsetCommandParams p;
2508 if (action == LFUN_HTMLURL)
2509 p.setCmdName("htmlurl");
2511 p.setCmdName("url");
2512 owner_->getDialogs()->createUrl( p.getAsString() );
2516 case LFUN_INSERT_URL:
2518 InsetCommandParams p;
2519 p.setFromString( argument );
2521 InsetUrl * inset = new InsetUrl( p );
2522 if (!bv_->insertInset(inset))
2525 bv_->updateInset( inset, true );
2529 case LFUN_INSET_TEXT:
2531 InsetText * new_inset = new InsetText;
2532 if (bv_->insertInset(new_inset))
2533 new_inset->Edit(bv_, 0, 0, 0);
2539 case LFUN_INSET_ERT:
2541 InsetERT * new_inset = new InsetERT;
2542 if (bv_->insertInset(new_inset))
2543 new_inset->Edit(bv_, 0, 0, 0);
2549 case LFUN_INSET_EXTERNAL:
2551 InsetExternal * new_inset = new InsetExternal;
2552 if (bv_->insertInset(new_inset))
2553 new_inset->Edit(bv_, 0, 0, 0);
2559 case LFUN_INSET_FOOTNOTE:
2561 InsetFoot * new_inset = new InsetFoot;
2562 if (bv_->insertInset(new_inset))
2563 new_inset->Edit(bv_, 0, 0, 0);
2569 case LFUN_INSET_MARGINAL:
2571 InsetMarginal * new_inset = new InsetMarginal;
2572 if (bv_->insertInset(new_inset))
2573 new_inset->Edit(bv_, 0, 0, 0);
2579 case LFUN_INSET_MINIPAGE:
2581 InsetMinipage * new_inset = new InsetMinipage;
2582 if (bv_->insertInset(new_inset))
2583 new_inset->Edit(bv_, 0, 0, 0);
2589 case LFUN_INSET_FLOAT:
2591 // check if the float type exist
2592 if (floatList.typeExist(argument)) {
2593 InsetFloat * new_inset = new InsetFloat(argument);
2594 if (bv_->insertInset(new_inset))
2595 new_inset->Edit(bv_, 0, 0, 0);
2599 lyxerr << "Non-existant float type: "
2600 << argument << endl;
2606 case LFUN_INSET_LIST:
2608 InsetList * new_inset = new InsetList;
2609 if (bv_->insertInset(new_inset))
2610 new_inset->Edit(bv_, 0, 0, 0);
2616 case LFUN_INSET_THEOREM:
2618 InsetTheorem * new_inset = new InsetTheorem;
2619 if (bv_->insertInset(new_inset))
2620 new_inset->Edit(bv_, 0, 0, 0);
2626 case LFUN_INSET_CAPTION:
2628 // Do we have a locking inset...
2629 if (bv_->theLockingInset()) {
2630 lyxerr << "Locking inset code: "
2631 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2632 InsetCaption * new_inset = new InsetCaption;
2633 new_inset->setOwner(bv_->theLockingInset());
2634 new_inset->SetAutoBreakRows(true);
2635 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2636 new_inset->SetFrameColor(0, LColor::footnoteframe);
2637 if (bv_->insertInset(new_inset))
2638 new_inset->Edit(bv_, 0, 0, 0);
2645 case LFUN_INSET_TABULAR:
2648 if (!argument.empty())
2649 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2650 InsetTabular * new_inset =
2651 new InsetTabular(*buffer_, r, c);
2653 TEXT(bv_)->real_current_font.isRightToLeft();
2654 if (!bv_->open_new_inset(new_inset, rtl))
2659 // --- lyxserver commands ----------------------------
2661 case LFUN_CHARATCURSOR:
2663 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2664 if (pos < TEXT(bv_)->cursor.par()->size())
2665 owner_->getLyXFunc()->setMessage(
2666 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2668 owner_->getLyXFunc()->setMessage("EOF");
2673 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2675 + tostr(TEXT(bv_)->cursor.y()));
2682 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2683 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2687 case LFUN_GETLAYOUT:
2688 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2693 LyXFont & font = TEXT(bv_)->current_font;
2694 if (font.shape() == LyXFont::ITALIC_SHAPE)
2695 owner_->getLyXFunc()->setMessage("E");
2696 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2697 owner_->getLyXFunc()->setMessage("N");
2699 owner_->getLyXFunc()->setMessage("0");
2706 LyXFont & font = TEXT(bv_)->current_font;
2707 if (font.latex() == LyXFont::ON)
2708 owner_->getLyXFunc()->setMessage("L");
2710 owner_->getLyXFunc()->setMessage("0");
2714 // --- accented characters ---------------------------
2717 case LFUN_CIRCUMFLEX:
2727 case LFUN_SPECIAL_CARON:
2730 case LFUN_HUNG_UMLAUT:
2733 owner_->getLyXFunc()->handleKeyFunc(action);
2736 // --- insert characters ----------------------------------------
2738 case LFUN_MATH_DELIM:
2739 case LFUN_INSERT_MATRIX:
2742 if (bv_->open_new_inset(new InsetFormula(false)))
2744 bv_->theLockingInset()
2745 ->LocalDispatch(bv_, action, argument);
2751 case LFUN_INSERT_MATH:
2753 math_insert_symbol(bv_, argument);
2757 case LFUN_MATH_DISPLAY:
2760 bv_->open_new_inset(new InsetFormula(true));
2764 case LFUN_MATH_MACRO:
2769 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2771 string const s1 = token(s, ' ', 1);
2772 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2773 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2779 case LFUN_MATH_MODE: // Open or create a math inset
2782 bv_->open_new_inset(new InsetFormula);
2783 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2787 case LFUN_CITATION_INSERT:
2789 InsetCommandParams p;
2790 p.setFromString( argument );
2792 InsetCitation * inset = new InsetCitation( p );
2793 if (!bv_->insertInset(inset))
2796 bv_->updateInset( inset, true );
2800 case LFUN_INSERT_BIBTEX:
2802 // ale970405+lasgoutt970425
2803 // The argument can be up to two tokens separated
2804 // by a space. The first one is the bibstyle.
2805 string const db = token(argument, ' ', 0);
2806 string bibstyle = token(argument, ' ', 1);
2807 if (bibstyle.empty())
2810 InsetCommandParams p( "BibTeX", db, bibstyle );
2811 InsetBibtex * inset = new InsetBibtex(p);
2813 if (bv_->insertInset(inset)) {
2814 if (argument.empty())
2815 inset->Edit(bv_, 0, 0, 0);
2821 // BibTeX data bases
2822 case LFUN_BIBDB_ADD:
2824 InsetBibtex * inset =
2825 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2827 inset->addDatabase(argument);
2832 case LFUN_BIBDB_DEL:
2834 InsetBibtex * inset =
2835 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2837 inset->delDatabase(argument);
2842 case LFUN_BIBTEX_STYLE:
2844 InsetBibtex * inset =
2845 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2847 inset->setOptions(argument);
2852 case LFUN_INDEX_CREATE:
2854 InsetCommandParams p( "index" );
2856 if (argument.empty()) {
2857 // Get the word immediately preceding the cursor
2858 LyXParagraph::size_type curpos =
2859 TEXT(bv_)->cursor.pos() - 1;
2863 curstring = TEXT(bv_)
2864 ->cursor.par()->GetWord(curpos);
2866 p.setContents( curstring );
2868 p.setContents( argument );
2871 owner_->getDialogs()->createIndex( p.getAsString() );
2875 case LFUN_INDEX_INSERT:
2877 InsetCommandParams p;
2878 p.setFromString(argument);
2879 InsetIndex * inset = new InsetIndex(p);
2881 if (!bv_->insertInset(inset))
2884 bv_->updateInset(inset, true);
2888 case LFUN_INDEX_INSERT_LAST:
2890 // Get word immediately preceding the cursor
2891 LyXParagraph::size_type curpos =
2892 TEXT(bv_)->cursor.pos() - 1;
2893 // Can't do that at the beginning of a paragraph
2894 if (curpos < 0) break;
2896 string const curstring(TEXT(bv_)
2897 ->cursor.par()->GetWord(curpos));
2899 InsetCommandParams p("index", curstring);
2900 InsetIndex * inset = new InsetIndex(p);
2902 if (!bv_->insertInset(inset))
2905 bv_->updateInset(inset, true);
2909 case LFUN_INDEX_PRINT:
2911 InsetCommandParams p("printindex");
2912 Inset * inset = new InsetPrintIndex(p);
2913 if (!bv_->insertInset(inset, "Standard", true))
2918 case LFUN_PARENTINSERT:
2920 lyxerr << "arg " << argument << endl;
2921 InsetCommandParams p( "lyxparent", argument );
2922 Inset * inset = new InsetParent(p, *buffer_);
2923 if (!bv_->insertInset(inset, "Standard", true))
2928 case LFUN_CHILD_INSERT:
2930 InsetCommandParams p;
2931 p.setFromString(argument);
2933 InsetInclude * inset = new InsetInclude(p, *buffer_);
2934 if (!bv_->insertInset(inset))
2937 bv_->updateInset(inset, true);
2941 case LFUN_INSERT_NOTE:
2945 case LFUN_SELFINSERT:
2947 LyXFont const old_font(TEXT(bv_)->real_current_font);
2948 for (string::size_type i = 0; i < argument.length(); ++i) {
2949 TEXT(bv_)->InsertChar(bv_, argument[i]);
2950 // This needs to be in the loop, or else we
2951 // won't break lines correctly. (Asger)
2953 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2955 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2956 moveCursorUpdate(false);
2958 // real_current_font.number can change so we need to
2959 // update the minibuffer
2960 if (old_font != TEXT(bv_)->real_current_font)
2961 owner_->showState();
2965 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2969 time_t now_time_t = time(NULL);
2970 now_tm = localtime(&now_time_t);
2971 setlocale(LC_TIME, "");
2973 if (!argument.empty())
2976 arg = lyxrc.date_insert_format;
2978 int const datetmp_len =
2979 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2980 for (int i = 0; i < datetmp_len; i++) {
2981 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2983 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2986 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2987 moveCursorUpdate(false);
2991 case LFUN_UNKNOWN_ACTION:
2994 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2998 if (buffer_->isReadonly()) {
2999 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
3002 if (!argument.empty()) {
3003 /* Automatically delete the currently selected
3004 * text and replace it with what is being
3005 * typed in now. Depends on lyxrc settings
3006 * "auto_region_delete", which defaults to
3009 if (lyxrc.auto_region_delete) {
3010 if (TEXT(bv_)->selection){
3011 TEXT(bv_)->CutSelection(bv_, false);
3013 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3017 beforeChange(TEXT(bv_));
3018 LyXFont const old_font(TEXT(bv_)->real_current_font);
3019 for (string::size_type i = 0;
3020 i < argument.length(); ++i) {
3021 if (greek_kb_flag) {
3022 if (!math_insert_greek(bv_,
3024 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3026 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3029 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3031 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3032 moveCursorUpdate(false);
3034 // real_current_font.number can change so we need to
3035 // update the minibuffer
3036 if (old_font != TEXT(bv_)->real_current_font)
3037 owner_->showState();
3039 // if we don't have an argument there was something
3040 // strange going on so we just tell this to someone!
3041 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));