12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
20 #include "minibuffer.h"
22 #include "bufferview_funcs.h"
23 #include "TextCache.h"
24 #include "bufferlist.h"
25 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "frontends/Dialogs.h"
30 #include "insets/insetbib.h"
31 #include "insets/insettext.h"
32 /// added for Dispatch functions
34 #include "frontends/FileDialog.h"
36 #include "FloatList.h"
37 #include "support/filetools.h"
38 #include "support/lyxfunctional.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetlatexaccent.h"
41 #include "insets/insettoc.h"
42 #include "insets/insetref.h"
43 #include "insets/insetparent.h"
44 #include "insets/insetindex.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "mathed/formulamacro.h"
59 extern LyXTextClass::size_type current_layout;
60 extern int greek_kb_flag;
70 /* the selection possible is needed, that only motion events are
71 * used, where the bottom press event was on the drawing area too */
72 bool selection_possible = false;
74 extern BufferList bufferlist;
75 extern char ascii_type;
77 extern bool math_insert_greek(BufferView *, char);
78 extern void sigchldhandler(pid_t pid, int * status);
79 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
81 const unsigned int saved_positions_num = 20;
88 XSync(fl_get_display(), 0);
92 void SetXtermCursor(Window win)
95 static bool cursor_undefined = true;
96 if (cursor_undefined){
97 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
98 XFlush(fl_get_display());
99 cursor_undefined = false;
101 XDefineCursor(fl_get_display(), win, cursor);
102 XFlush(fl_get_display());
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 /// get rid of the splash screen if it's not gone already
352 owner_->getDialogs()->destroySplash();
358 void BufferView::Pimpl::updateScreen()
360 // Regenerate the screen.
361 screen_.reset(new LyXScreen(workarea_));
363 //screen_ = new LyXScreen(workarea_);
367 void BufferView::Pimpl::updateScrollbar()
369 /* If the text is smaller than the working area, the scrollbar
370 * maximum must be the working area height. No scrolling will
374 workarea_.setScrollbar(0, 1.0);
378 static unsigned long max2 = 0;
379 static unsigned long height2 = 0;
381 unsigned long cbth = 0;
385 cbth = bv_->text->height;
386 cbsf = bv_->text->first;
389 // check if anything has changed.
391 height2 == workarea_.height() &&
392 current_scrollbar_value == cbsf)
395 height2 = workarea_.height();
396 current_scrollbar_value = cbsf;
398 if (cbth <= height2) { // text is smaller than screen
399 workarea_.setScrollbar(0, 1.0); // right?
403 long maximum_height = workarea_.height() * 3 / 4 + cbth;
407 double hfloat = workarea_.height();
408 double maxfloat = maximum_height;
410 float slider_size = 0.0;
411 int slider_value = value;
413 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
414 double const lineh = bv_->text->DefaultHeight();
415 workarea_.setScrollbarIncrements(lineh);
416 if (maxfloat > 0.0) {
417 if ((hfloat / maxfloat) * float(height2) < 3)
418 slider_size = 3.0/float(height2);
420 slider_size = hfloat / maxfloat;
422 slider_size = hfloat;
424 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
428 // Callback for scrollbar slider
429 void BufferView::Pimpl::scrollCB(double value)
431 if (!buffer_) return;
433 current_scrollbar_value = long(value);
434 if (current_scrollbar_value < 0)
435 current_scrollbar_value = 0;
440 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
442 if (!lyxrc.cursor_follows_scrollbar) {
447 LyXText * vbt = bv_->text;
449 int const height = vbt->DefaultHeight();
450 int const first = static_cast<int>((bv_->text->first + height));
451 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
453 if (vbt->cursor.y() < first)
454 vbt->SetCursorFromCoordinates(bv_, 0, first);
455 else if (vbt->cursor.y() > last)
456 vbt->SetCursorFromCoordinates(bv_, 0, last);
462 int BufferView::Pimpl::scrollUp(long time)
464 if (!buffer_) return 0;
465 if (!screen_.get()) return 0;
467 double value = workarea_.getScrollbarValue();
469 if (value == 0) return 0;
471 float add_value = (bv_->text->DefaultHeight()
472 + float(time) * float(time) * 0.125);
474 if (add_value > workarea_.height())
475 add_value = float(workarea_.height() -
476 bv_->text->DefaultHeight());
483 workarea_.setScrollbarValue(value);
490 int BufferView::Pimpl::scrollDown(long time)
492 if (!buffer_) return 0;
493 if (!screen_.get()) return 0;
495 double value = workarea_.getScrollbarValue();
496 pair<float, float> p = workarea_.getScrollbarBounds();
497 double max = p.second;
499 if (value == max) return 0;
501 float add_value = (bv_->text->DefaultHeight()
502 + float(time) * float(time) * 0.125);
504 if (add_value > workarea_.height())
505 add_value = float(workarea_.height() -
506 bv_->text->DefaultHeight());
513 workarea_.setScrollbarValue(value);
520 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
522 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
526 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
528 // Only use motion with button 1
529 if (!(state & Button1MotionMask))
532 if (!buffer_ || !screen_.get()) return;
534 // Check for inset locking
535 if (bv_->theLockingInset()) {
536 LyXCursor cursor = bv_->text->cursor;
537 LyXFont font = bv_->text->GetFont(bv_->buffer(),
538 cursor.par(), cursor.pos());
539 int width = bv_->theLockingInset()->width(bv_, font);
540 int inset_x = font.isVisibleRightToLeft()
541 ? cursor.x() - width : cursor.x();
542 int start_x = inset_x + bv_->theLockingInset()->scroll();
543 bv_->theLockingInset()->
544 InsetMotionNotify(bv_,
546 y - cursor.y() + bv_->text->first,
551 /* The test for not selection possible is needed, that only motion events are
552 * used, where the bottom press event was on the drawing area too */
553 if (!selection_possible)
556 screen_->HideCursor();
558 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
560 if (!bv_->text->selection)
561 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
563 bv_->text->SetSelection(bv_);
564 screen_->ToggleToggle(bv_->text, bv_);
565 fitCursor(bv_->text);
566 screen_->ShowCursor(bv_->text, bv_);
570 // Single-click on work area
571 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
577 if (!buffer_ || !screen_.get()) return;
579 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
581 // ok ok, this is a hack.
582 if (button == 4 || button == 5) {
585 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
588 scrollDown(lyxrc.wheel_jump);
593 if (bv_->theLockingInset()) {
594 // We are in inset locking mode
596 /* Check whether the inset was hit. If not reset mode,
597 otherwise give the event to the inset */
598 if (inset_hit == bv_->theLockingInset()) {
599 bv_->theLockingInset()->
600 InsetButtonPress(bv_,
605 bv_->unlockInset(bv_->theLockingInset());
610 selection_possible = true;
611 screen_->HideCursor();
613 int const screen_first = bv_->text->first;
615 // Middle button press pastes if we have a selection
616 bool paste_internally = false;
618 && bv_->text->selection) {
619 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
620 paste_internally = true;
623 // Clear the selection
624 screen_->ToggleSelection(bv_->text, bv_);
625 bv_->text->ClearSelection(bv_);
626 bv_->text->FullRebreak(bv_);
627 screen_->Update(bv_->text, bv_);
630 // Single left click in math inset?
631 if ((inset_hit != 0) &&
632 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
633 // Highly editable inset, like math
634 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
635 selection_possible = false;
636 owner_->updateLayoutChoice();
637 owner_->getMiniBuffer()->Set(inset->EditMessage());
638 inset->InsetButtonPress(bv_, xpos, ypos, button);
639 inset->Edit(bv_, xpos, ypos, button);
643 // Right click on a footnote flag opens float menu
645 selection_possible = false;
649 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
650 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
651 bv_->text->FinishUndo();
652 bv_->text->sel_cursor = bv_->text->cursor;
653 bv_->text->cursor.x_fix(bv_->text->cursor.x());
655 owner_->updateLayoutChoice();
656 if (fitCursor(bv_->text)) {
657 selection_possible = false;
660 // Insert primary selection with middle mouse
661 // if there is a local selection in the current buffer,
664 if (paste_internally)
665 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
667 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
669 selection_possible = false;
675 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
681 LyXText * text = bv_->getLyXText();
683 if (text->bv_owner && bv_->theLockingInset())
686 if (screen_.get() && button == 1) {
687 if (text->bv_owner) {
688 screen_->HideCursor();
689 screen_->ToggleSelection(text, bv_);
690 text->SelectWord(bv_);
691 screen_->ToggleSelection(text, bv_, false);
693 text->SelectWord(bv_);
695 /* This will fit the cursor on the screen
697 update(text, BufferView::SELECT|BufferView::FITCUR);
702 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
708 LyXText * text = bv_->getLyXText();
710 if (text->bv_owner && bv_->theLockingInset())
713 if (screen_.get() && (button == 1)) {
714 screen_->HideCursor();
715 screen_->ToggleSelection(text, bv_);
716 text->CursorHome(bv_);
717 text->sel_cursor = text->cursor;
718 text->CursorEnd(bv_);
719 text->SetSelection(bv_);
720 screen_->ToggleSelection(text, bv_, false);
721 /* This will fit the cursor on the screen
723 update(text, BufferView::SELECT|BufferView::FITCUR);
728 void BufferView::Pimpl::enterView()
730 if (active() && available()) {
731 SetXtermCursor(workarea_.getWin());
732 using_xterm_cursor = true;
737 void BufferView::Pimpl::leaveView()
739 if (using_xterm_cursor) {
740 XUndefineCursor(fl_get_display(), workarea_.getWin());
741 using_xterm_cursor = false;
746 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
749 if (!buffer_ || !screen_.get()) return;
751 // If we hit an inset, we have the inset coordinates in these
752 // and inset_hit points to the inset. If we do not hit an
753 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
754 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
756 if (bv_->theLockingInset()) {
757 // We are in inset locking mode.
759 /* LyX does a kind of work-area grabbing for insets.
760 Only a ButtonPress Event outside the inset will
761 force a InsetUnlock. */
762 bv_->theLockingInset()->
763 InsetButtonRelease(bv_, x, y, button);
767 selection_possible = false;
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);
924 text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
928 if (cursor.pos() < cursor.par()->Last()
930 if (cursor.pos() < cursor.par()->size()
932 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
933 && cursor.par()->GetInset(cursor.pos())
934 && cursor.par()->GetInset(cursor.pos())->Editable()) {
936 // Check whether the inset really was hit
937 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
938 LyXFont font = text->GetFont(bv_->buffer(),
939 cursor.par(), cursor.pos());
940 int const width = tmpinset->width(bv_, font);
941 int const inset_x = font.isVisibleRightToLeft()
942 ? cursor.x() - width : cursor.x();
943 int const start_x = inset_x + tmpinset->scroll();
944 int const end_x = inset_x + width;
946 if (x > start_x && x < end_x
947 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
948 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
949 text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
951 // The origin of an inset is on the baseline
952 y = y_tmp - (text->cursor.y());
957 if ((cursor.pos() - 1 >= 0) &&
958 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
959 (cursor.par()->GetInset(cursor.pos() - 1)) &&
960 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
961 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
962 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
964 int const width = tmpinset->width(bv_, font);
965 int const inset_x = font.isVisibleRightToLeft()
966 ? cursor.x() : cursor.x() - width;
967 int const start_x = inset_x + tmpinset->scroll();
968 int const end_x = inset_x + width;
970 if (x > start_x && x < end_x
971 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
972 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
974 if (move_cursor && (tmpinset != bv_->theLockingInset()))
976 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
978 // The origin of an inset is on the baseline
979 y = y_tmp - (text->cursor.y());
987 void BufferView::Pimpl::workAreaExpose()
989 static int work_area_width = 0;
990 static unsigned int work_area_height = 0;
992 bool const widthChange = workarea_.workWidth() != work_area_width;
993 bool const heightChange = workarea_.height() != work_area_height;
995 // update from work area
996 work_area_width = workarea_.workWidth();
997 work_area_height = workarea_.height();
1000 // All buffers need a resize
1001 bufferlist.resize();
1003 // Remove all texts from the textcache
1004 // This is not _really_ what we want to do. What
1005 // we really want to do is to delete in textcache
1006 // that does not have a BufferView with matching
1007 // width, but as long as we have only one BufferView
1008 // deleting all gives the same result.
1009 if (lyxerr.debugging())
1010 textcache.show(lyxerr, "Expose delete all");
1012 } else if (heightChange) {
1013 // Rebuild image of current screen
1015 // fitCursor() ensures we don't jump back
1016 // to the start of the document on vertical
1018 fitCursor(bv_->text);
1020 // The main window size has changed, repaint most stuff
1022 // ...including the minibuffer
1023 owner_->getMiniBuffer()->Init();
1025 } else if (screen_.get())
1026 screen_->Redraw(bv_->text, bv_);
1028 // Grey box when we don't have a buffer
1029 workarea_.greyOut();
1032 // always make sure that the scrollbar is sane.
1034 owner_->updateLayoutChoice();
1039 void BufferView::Pimpl::update()
1041 if (screen_.get()) screen_->Update(bv_->text, bv_);
1044 // Values used when calling update:
1046 // -2 - update, move sel_cursor if selection, fitcursor
1047 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1048 // 0 - update, move sel_cursor if selection, fitcursor
1049 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1050 // 3 - update, move sel_cursor if selection
1053 // a simple redraw of the parts that need refresh
1055 // move sel_cursor if selection -
1056 // the text's sel_cursor is moved if there is selection is progress
1059 // fitCursor() is called and the scrollbar updated
1062 // the buffer is marked dirty.
1071 // UPDATE_ONLY = UPDATE;
1072 // UPDATE_SELECT = UPDATE | SELECT;
1073 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1074 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1076 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1077 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1078 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1079 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1080 // update(3) -> update(1) -> update(1) -> update(SELECT)
1082 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1084 owner_->updateLayoutChoice();
1086 if (!text->selection && (f & SELECT)) {
1087 text->sel_cursor = text->cursor;
1090 text->FullRebreak(bv_);
1092 if (text->inset_owner) {
1093 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1094 bv_->updateInset(text->inset_owner, true);
1103 if (buffer_->isLyxClean()) {
1104 buffer_->markDirty();
1106 owner_->getMiniBuffer()->setTimer(4);
1109 buffer_->markDirty();
1115 // Callback for cursor timer
1116 void BufferView::Pimpl::cursorToggle()
1118 // Quite a nice place for asyncron Inset updating, isn't it?
1119 // Actually no! This is run even if no buffer exist... so (Lgb)
1121 cursor_timeout.restart();
1126 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1127 if (pid == -1) // error find out what is wrong
1128 ; // ignore it for now.
1130 sigchldhandler(pid, &status);
1132 updatelist.update(bv_);
1134 if (!screen_.get()) {
1135 cursor_timeout.restart();
1139 if (!bv_->theLockingInset()) {
1140 screen_->CursorToggle(bv_->text, bv_);
1142 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1145 cursor_timeout.restart();
1149 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1151 if (!text->cursor.row()->previous())
1154 int y = text->first;
1155 if (text->inset_owner)
1156 y += bv_->text->first;
1157 Row * cursorrow = text->cursor.row();
1158 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1159 bv_->text->FinishUndo();
1160 // This is to allow jumping over large insets
1161 if ((cursorrow == text->cursor.row()))
1162 text->CursorUp(bv_);
1164 if (text->inset_owner ||
1165 text->cursor.row()->height() < workarea_.height())
1166 screen_->Draw(bv_->text, bv_,
1168 - text->cursor.row()->baseline()
1169 + text->cursor.row()->height()
1170 - workarea_.height() + 1 );
1175 void BufferView::Pimpl::cursorNext(LyXText * text)
1177 if (!text->cursor.row()->next())
1180 int y = text->first + workarea_.height();
1181 // if (text->inset_owner)
1182 // y += bv_->text->first;
1183 text->GetRowNearY(y);
1185 Row * cursorrow = text->cursor.row();
1186 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1187 bv_->text->FinishUndo();
1188 // This is to allow jumping over large insets
1189 if ((cursorrow == bv_->text->cursor.row()))
1190 text->CursorDown(bv_);
1192 if (text->inset_owner ||
1193 text->cursor.row()->height() < workarea_.height())
1194 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1195 text->cursor.row()->baseline());
1200 bool BufferView::Pimpl::available() const
1202 if (buffer_ && bv_->text) return true;
1207 void BufferView::Pimpl::beforeChange(LyXText * text)
1210 text->ClearSelection(bv_);
1214 void BufferView::Pimpl::savePosition(unsigned int i)
1216 if (i >= saved_positions_num)
1218 saved_positions[i] = Position(buffer_->fileName(),
1219 bv_->text->cursor.par()->id(),
1220 bv_->text->cursor.pos());
1222 owner_->getMiniBuffer()->Set(_("Saved bookmark"), tostr(i));
1226 void BufferView::Pimpl::restorePosition(unsigned int i)
1228 if (i >= saved_positions_num)
1231 string fname = saved_positions[i].filename;
1233 beforeChange(bv_->text);
1235 if (fname != buffer_->fileName()) {
1236 Buffer * b = bufferlist.exists(fname) ?
1237 bufferlist.getBuffer(fname) :
1238 bufferlist.loadLyXFile(fname); // don't ask, just load it
1239 if (b != 0 ) buffer(b);
1242 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1247 bv_->text->SetCursor(bv_, par,
1248 min(par->Last(), saved_positions[i].par_pos));
1250 bv_->text->SetCursor(bv_, par,
1251 min(par->size(), saved_positions[i].par_pos));
1253 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1255 owner_->getMiniBuffer()->Set(_("Moved to bookmark"), tostr(i));
1259 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1261 if (i >= saved_positions_num)
1264 return !saved_positions[i].filename.empty();
1268 void BufferView::Pimpl::setState()
1270 if (!lyxrc.rtl_support)
1273 LyXText * text = bv_->getLyXText();
1274 if (text->real_current_font.isRightToLeft() &&
1275 text->real_current_font.latex() != LyXFont::ON) {
1276 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1277 owner_->getIntl()->KeyMapSec();
1279 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1280 owner_->getIntl()->KeyMapPrim();
1285 void BufferView::Pimpl::insetSleep()
1287 if (bv_->theLockingInset() && !bv_->inset_slept) {
1288 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1289 bv_->theLockingInset()->InsetUnlock(bv_);
1290 bv_->inset_slept = true;
1295 void BufferView::Pimpl::insetWakeup()
1297 if (bv_->theLockingInset() && bv_->inset_slept) {
1298 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1299 bv_->inset_slept = false;
1304 void BufferView::Pimpl::insetUnlock()
1306 if (bv_->theLockingInset()) {
1307 if (!bv_->inset_slept)
1308 bv_->theLockingInset()->InsetUnlock(bv_);
1309 bv_->theLockingInset(0);
1310 bv_->text->FinishUndo();
1311 bv_->inset_slept = false;
1316 bool BufferView::Pimpl::focus() const
1318 return workarea_.hasFocus();
1322 void BufferView::Pimpl::focus(bool f)
1324 if (f) workarea_.setFocus();
1328 bool BufferView::Pimpl::active() const
1330 return workarea_.active();
1334 bool BufferView::Pimpl::belowMouse() const
1336 return workarea_.belowMouse();
1340 void BufferView::Pimpl::showCursor()
1343 screen_->ShowCursor(bv_->text, bv_);
1347 void BufferView::Pimpl::hideCursor()
1350 screen_->HideCursor();
1354 void BufferView::Pimpl::toggleSelection(bool b)
1357 screen_->ToggleSelection(bv_->text, bv_, b);
1361 void BufferView::Pimpl::toggleToggle()
1364 screen_->ToggleToggle(bv_->text, bv_);
1368 void BufferView::Pimpl::center()
1370 beforeChange(bv_->text);
1371 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1372 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1374 screen_->Draw(bv_->text, bv_, 0);
1376 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1381 void BufferView::Pimpl::pasteClipboard(bool asPara)
1383 if (!buffer_) return;
1385 screen_->HideCursor();
1386 beforeChange(bv_->text);
1388 string const clip(workarea_.getClipboard());
1390 if (clip.empty()) return;
1393 bv_->text->InsertStringB(bv_, clip);
1395 bv_->text->InsertStringA(bv_, clip);
1397 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1401 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1403 workarea_.putClipboard(stuff);
1408 * Dispatch functions for actions which can be valid for BufferView->text
1409 * and/or InsetText->text!!!
1411 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1414 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1416 if (selecting || TEXT(bv_)->mark_set) {
1417 TEXT(bv_)->SetSelection(bv_);
1418 if (TEXT(bv_)->bv_owner)
1419 bv_->toggleToggle();
1421 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1424 /* ---> Everytime the cursor is moved, show the current font state. */
1425 // should this too me moved out of this func?
1426 //owner->showState();
1431 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1433 LyXCursor cursor = TEXT(bv_)->cursor;
1434 Buffer::inset_iterator it =
1435 find_if(Buffer::inset_iterator(
1436 cursor.par(), cursor.pos()),
1437 buffer_->inset_iterator_end(),
1438 compare_memfun(&Inset::LyxCode, code)
1440 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1444 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1446 string filename = filen;
1448 if (filename.empty()) {
1449 // Launch a file browser
1450 string initpath = lyxrc.document_path;
1453 string const trypath = owner_->buffer()->filepath;
1454 // If directory is writeable, use this as default.
1455 if (IsDirWriteable(trypath) == 1)
1459 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1461 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1462 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1464 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1466 if (result.first == FileDialog::Later)
1469 filename = result.second;
1471 // check selected filename
1472 if (filename.empty()) {
1473 owner_->getMiniBuffer()->Set(_("Canceled."));
1478 // get absolute path of file and make sure the filename ends
1480 filename = MakeAbsPath(filename);
1481 if (!IsLyXFilename(filename))
1485 owner_->getMiniBuffer()->Set(_("Inserting document"),
1486 MakeDisplayPath(filename), "...");
1487 bool const res = bv_->insertLyXFile(filename);
1489 owner_->getMiniBuffer()->Set(_("Document"),
1490 MakeDisplayPath(filename),
1493 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1494 MakeDisplayPath(filename));
1499 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1502 // --- Misc -------------------------------------------
1505 TEXT(bv_)->toggleAppendix(bv_);
1506 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1510 case LFUN_TOC_INSERT:
1511 case LFUN_LOA_INSERT:
1512 case LFUN_LOF_INSERT:
1513 case LFUN_LOT_INSERT:
1515 InsetCommandParams p;
1517 if (action == LFUN_TOC_INSERT )
1518 p.setCmdName( "tableofcontents" );
1519 else if (action == LFUN_LOA_INSERT )
1520 p.setCmdName( "listofalgorithms" );
1521 else if (action == LFUN_LOF_INSERT )
1522 p.setCmdName( "listoffigures" );
1524 p.setCmdName( "listoftables" );
1526 Inset * inset = new InsetTOC( p );
1527 if (!bv_->insertInset( inset, "Standard", true ) )
1532 case LFUN_TABULAR_FEATURE:
1533 case LFUN_SCROLL_INSET:
1534 // this is not handled here as this funktion is only aktive
1535 // if we have a locking_inset and that one is (or contains)
1539 case LFUN_INSET_GRAPHICS:
1541 Inset * new_inset = new InsetGraphics;
1542 if (!bv_->insertInset(new_inset)) {
1545 // this is need because you don't use a inset->Edit()
1546 bv_->updateInset(new_inset, true);
1547 new_inset->Edit(bv_, 0, 0, 0);
1557 case LFUN_PASTESELECTION:
1559 bool asPara = false;
1560 if (argument == "paragraph") asPara = true;
1561 pasteClipboard(asPara);
1573 case LFUN_LAYOUT_COPY:
1574 bv_->copyEnvironment();
1577 case LFUN_LAYOUT_PASTE:
1578 bv_->pasteEnvironment();
1582 case LFUN_GOTOERROR:
1583 bv_->gotoInset(Inset::ERROR_CODE, false);
1587 bv_->gotoInset(Inset::IGNORE_CODE, false);
1590 case LFUN_REFERENCE_GOTO:
1592 vector<Inset::Code> tmp;
1593 tmp.push_back(Inset::LABEL_CODE);
1594 tmp.push_back(Inset::REF_CODE);
1595 bv_->gotoInset(tmp, true);
1599 case LFUN_HYPHENATION:
1600 bv_->hyphenationPoint();
1607 case LFUN_END_OF_SENTENCE:
1608 bv_->endOfSentenceDot();
1611 case LFUN_MENU_SEPARATOR:
1612 bv_->menuSeparator();
1620 changeDepth(bv_, TEXT(bv_), 0);
1623 case LFUN_DEPTH_MIN:
1624 changeDepth(bv_, TEXT(bv_), -1);
1627 case LFUN_DEPTH_PLUS:
1628 changeDepth(bv_, TEXT(bv_), 1);
1632 owner_->getDialogs()->setUserFreeFont();
1638 owner_->showState();
1641 case LFUN_FILE_INSERT:
1643 MenuInsertLyXFile(argument);
1647 case LFUN_FILE_INSERT_ASCII_PARA:
1648 InsertAsciiFile(bv_, argument, true);
1651 case LFUN_FILE_INSERT_ASCII:
1652 InsertAsciiFile(bv_, argument, false);
1657 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1658 << argument << endl;
1660 // Derive layout number from given argument (string)
1661 // and current buffer's textclass (number). */
1662 LyXTextClassList::ClassList::size_type tclass =
1663 buffer_->params.textclass;
1664 pair <bool, LyXTextClass::size_type> layout =
1665 textclasslist.NumberOfLayout(tclass, argument);
1667 // If the entry is obsolete, use the new one instead.
1669 string obs = textclasslist.Style(tclass,layout.second)
1673 textclasslist.NumberOfLayout(tclass, obs);
1676 // see if we found the layout number:
1677 if (!layout.first) {
1678 owner_->getLyXFunc()->setErrorMessage(
1679 string(N_("Layout ")) + argument +
1684 if (current_layout != layout.second) {
1686 current_layout = layout.second;
1688 BufferView::SELECT|BufferView::FITCUR);
1689 TEXT(bv_)->SetLayout(bv_, layout.second);
1690 owner_->setLayout(layout.second);
1692 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1699 Lang(bv_, argument);
1701 owner_->showState();
1706 owner_->showState();
1711 owner_->showState();
1716 owner_->showState();
1721 owner_->showState();
1726 owner_->showState();
1731 owner_->showState();
1736 owner_->showState();
1739 case LFUN_UNDERLINE:
1741 owner_->showState();
1744 case LFUN_FONT_SIZE:
1745 FontSize(bv_, argument);
1746 owner_->showState();
1749 case LFUN_FONT_STATE:
1750 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1753 case LFUN_UPCASE_WORD:
1754 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1755 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1756 if (TEXT(bv_)->inset_owner)
1757 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1758 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1761 case LFUN_LOWCASE_WORD:
1762 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1763 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
1764 if (TEXT(bv_)->inset_owner)
1765 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1766 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1769 case LFUN_CAPITALIZE_WORD:
1770 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1771 TEXT(bv_)->ChangeWordCase(bv_,
1772 LyXText::text_capitalization);
1773 if (TEXT(bv_)->inset_owner)
1774 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1775 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1778 case LFUN_INSERT_LABEL:
1779 MenuInsertLabel(bv_, argument);
1782 case LFUN_REF_INSERT:
1783 if (argument.empty()) {
1784 InsetCommandParams p("ref");
1785 owner_->getDialogs()->createRef(p.getAsString());
1787 InsetCommandParams p;
1788 p.setFromString(argument);
1790 InsetRef * inset = new InsetRef(p, *buffer_);
1791 if (!bv_->insertInset(inset))
1794 bv_->updateInset(inset, true);
1798 case LFUN_BOOKMARK_SAVE:
1799 savePosition(strToUnsignedInt(argument));
1802 case LFUN_BOOKMARK_GOTO:
1803 restorePosition(strToUnsignedInt(argument));
1808 string label(argument);
1809 if (label.empty()) {
1811 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1813 label = inset->getContents();
1818 if (!label.empty()) {
1819 //bv_->savePosition(0);
1820 if (!bv_->gotoLabel(label))
1821 WriteAlert(_("Error"),
1822 _("Couldn't find this label"),
1823 _("in current document."));
1828 // --- Cursor Movements -----------------------------
1831 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1832 if (!TEXT(bv_)->mark_set)
1833 beforeChange(TEXT(bv_));
1834 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1836 TEXT(bv_)->CursorLeft(bv_, false);
1838 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1840 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
1842 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1843 == LyXParagraph::META_INSET
1844 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1845 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1846 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1847 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1851 TEXT(bv_)->GetFont(buffer_,
1852 TEXT(bv_)->cursor.par(),
1853 TEXT(bv_)->cursor.pos());
1854 y = tmpinset->descent(bv_,font);
1856 tmpinset->Edit(bv_, 0, y, 0);
1860 TEXT(bv_)->CursorRight(bv_, false);
1861 TEXT(bv_)->FinishUndo();
1862 moveCursorUpdate(false);
1863 owner_->showState();
1869 // This is soooo ugly. Isn`t it possible to make
1870 // it simpler? (Lgb)
1871 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1872 if (!TEXT(bv_)->mark_set)
1873 beforeChange(TEXT(bv_));
1874 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1875 LyXCursor cur = TEXT(bv_)->cursor;
1877 TEXT(bv_)->CursorLeft(bv_, false);
1878 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1880 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1882 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
1884 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1885 LyXParagraph::META_INSET) &&
1886 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1887 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1888 == Inset::HIGHLY_EDITABLE))
1890 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1891 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1892 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1893 TEXT(bv_)->cursor.par(),
1894 TEXT(bv_)->cursor.pos());
1896 : tmpinset->descent(bv_,font);
1899 tmpinset->width(bv_,font),
1904 TEXT(bv_)->CursorRight(bv_, false);
1906 TEXT(bv_)->FinishUndo();
1907 moveCursorUpdate(false);
1908 owner_->showState();
1913 if (!TEXT(bv_)->mark_set)
1914 beforeChange(TEXT(bv_));
1915 update(TEXT(bv_), BufferView::UPDATE);
1916 TEXT(bv_)->CursorUp(bv_);
1917 TEXT(bv_)->FinishUndo();
1918 moveCursorUpdate(false);
1919 owner_->showState();
1923 if (!TEXT(bv_)->mark_set)
1924 beforeChange(TEXT(bv_));
1925 update(TEXT(bv_), BufferView::UPDATE);
1926 TEXT(bv_)->CursorDown(bv_);
1927 TEXT(bv_)->FinishUndo();
1928 moveCursorUpdate(false);
1929 owner_->showState();
1932 case LFUN_UP_PARAGRAPH:
1933 if (!TEXT(bv_)->mark_set)
1934 beforeChange(TEXT(bv_));
1935 update(TEXT(bv_), BufferView::UPDATE);
1936 TEXT(bv_)->CursorUpParagraph(bv_);
1937 TEXT(bv_)->FinishUndo();
1938 moveCursorUpdate(false);
1939 owner_->showState();
1942 case LFUN_DOWN_PARAGRAPH:
1943 if (!TEXT(bv_)->mark_set)
1944 beforeChange(TEXT(bv_));
1945 update(TEXT(bv_), BufferView::UPDATE);
1946 TEXT(bv_)->CursorDownParagraph(bv_);
1947 TEXT(bv_)->FinishUndo();
1948 moveCursorUpdate(false);
1949 owner_->showState();
1953 if (!TEXT(bv_)->mark_set)
1954 beforeChange(TEXT(bv_));
1955 update(TEXT(bv_), BufferView::UPDATE);
1956 cursorPrevious(TEXT(bv_));
1957 TEXT(bv_)->FinishUndo();
1958 moveCursorUpdate(false);
1959 owner_->showState();
1963 if (!TEXT(bv_)->mark_set)
1964 beforeChange(TEXT(bv_));
1965 update(TEXT(bv_), BufferView::UPDATE);
1966 cursorNext(TEXT(bv_));
1967 TEXT(bv_)->FinishUndo();
1968 moveCursorUpdate(false);
1969 owner_->showState();
1973 if (!TEXT(bv_)->mark_set)
1974 beforeChange(TEXT(bv_));
1975 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1976 TEXT(bv_)->CursorHome(bv_);
1977 TEXT(bv_)->FinishUndo();
1978 moveCursorUpdate(false);
1979 owner_->showState();
1983 if (!TEXT(bv_)->mark_set)
1984 beforeChange(TEXT(bv_));
1986 BufferView::SELECT|BufferView::FITCUR);
1987 TEXT(bv_)->CursorEnd(bv_);
1988 TEXT(bv_)->FinishUndo();
1989 moveCursorUpdate(false);
1990 owner_->showState();
1993 case LFUN_SHIFT_TAB:
1995 if (!TEXT(bv_)->mark_set)
1996 beforeChange(TEXT(bv_));
1998 BufferView::SELECT|BufferView::FITCUR);
1999 TEXT(bv_)->CursorTab(bv_);
2000 TEXT(bv_)->FinishUndo();
2001 moveCursorUpdate(false);
2002 owner_->showState();
2005 case LFUN_WORDRIGHT:
2006 if (!TEXT(bv_)->mark_set)
2007 beforeChange(TEXT(bv_));
2008 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2009 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2010 TEXT(bv_)->CursorLeftOneWord(bv_);
2012 TEXT(bv_)->CursorRightOneWord(bv_);
2013 TEXT(bv_)->FinishUndo();
2014 moveCursorUpdate(false);
2015 owner_->showState();
2019 if (!TEXT(bv_)->mark_set)
2020 beforeChange(TEXT(bv_));
2021 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2022 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2023 TEXT(bv_)->CursorRightOneWord(bv_);
2025 TEXT(bv_)->CursorLeftOneWord(bv_);
2026 TEXT(bv_)->FinishUndo();
2027 moveCursorUpdate(false);
2028 owner_->showState();
2031 case LFUN_BEGINNINGBUF:
2032 if (!TEXT(bv_)->mark_set)
2033 beforeChange(TEXT(bv_));
2035 BufferView::SELECT|BufferView::FITCUR);
2036 TEXT(bv_)->CursorTop(bv_);
2037 TEXT(bv_)->FinishUndo();
2038 moveCursorUpdate(false);
2039 owner_->showState();
2043 if (!TEXT(bv_)->mark_set)
2044 beforeChange(TEXT(bv_));
2046 BufferView::SELECT|BufferView::FITCUR);
2047 TEXT(bv_)->CursorBottom(bv_);
2048 TEXT(bv_)->FinishUndo();
2049 moveCursorUpdate(false);
2050 owner_->showState();
2054 /* cursor selection ---------------------------- */
2057 BufferView::SELECT|BufferView::FITCUR);
2058 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2059 TEXT(bv_)->CursorLeft(bv_);
2061 TEXT(bv_)->CursorRight(bv_);
2062 TEXT(bv_)->FinishUndo();
2063 moveCursorUpdate(true);
2064 owner_->showState();
2069 BufferView::SELECT|BufferView::FITCUR);
2070 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2071 TEXT(bv_)->CursorRight(bv_);
2073 TEXT(bv_)->CursorLeft(bv_);
2074 TEXT(bv_)->FinishUndo();
2075 moveCursorUpdate(true);
2076 owner_->showState();
2081 BufferView::SELECT|BufferView::FITCUR);
2082 TEXT(bv_)->CursorUp(bv_);
2083 TEXT(bv_)->FinishUndo();
2084 moveCursorUpdate(true);
2085 owner_->showState();
2090 BufferView::SELECT|BufferView::FITCUR);
2091 TEXT(bv_)->CursorDown(bv_);
2092 TEXT(bv_)->FinishUndo();
2093 moveCursorUpdate(true);
2094 owner_->showState();
2097 case LFUN_UP_PARAGRAPHSEL:
2099 BufferView::SELECT|BufferView::FITCUR);
2100 TEXT(bv_)->CursorUpParagraph(bv_);
2101 TEXT(bv_)->FinishUndo();
2102 moveCursorUpdate(true);
2103 owner_->showState();
2106 case LFUN_DOWN_PARAGRAPHSEL:
2108 BufferView::SELECT|BufferView::FITCUR);
2109 TEXT(bv_)->CursorDownParagraph(bv_);
2110 TEXT(bv_)->FinishUndo();
2111 moveCursorUpdate(true);
2112 owner_->showState();
2116 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2117 cursorPrevious(TEXT(bv_));
2118 TEXT(bv_)->FinishUndo();
2119 moveCursorUpdate(true);
2120 owner_->showState();
2124 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2125 cursorNext(TEXT(bv_));
2126 TEXT(bv_)->FinishUndo();
2127 moveCursorUpdate(true);
2128 owner_->showState();
2132 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2133 TEXT(bv_)->CursorHome(bv_);
2134 TEXT(bv_)->FinishUndo();
2135 moveCursorUpdate(true);
2136 owner_->showState();
2140 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2141 TEXT(bv_)->CursorEnd(bv_);
2142 TEXT(bv_)->FinishUndo();
2143 moveCursorUpdate(true);
2144 owner_->showState();
2147 case LFUN_WORDRIGHTSEL:
2148 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2149 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2150 TEXT(bv_)->CursorLeftOneWord(bv_);
2152 TEXT(bv_)->CursorRightOneWord(bv_);
2153 TEXT(bv_)->FinishUndo();
2154 moveCursorUpdate(true);
2155 owner_->showState();
2158 case LFUN_WORDLEFTSEL:
2159 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2160 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2161 TEXT(bv_)->CursorRightOneWord(bv_);
2163 TEXT(bv_)->CursorLeftOneWord(bv_);
2164 TEXT(bv_)->FinishUndo();
2165 moveCursorUpdate(true);
2166 owner_->showState();
2169 case LFUN_BEGINNINGBUFSEL:
2170 if (TEXT(bv_)->inset_owner)
2172 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2173 TEXT(bv_)->CursorTop(bv_);
2174 TEXT(bv_)->FinishUndo();
2175 moveCursorUpdate(true);
2176 owner_->showState();
2179 case LFUN_ENDBUFSEL:
2180 if (TEXT(bv_)->inset_owner)
2183 BufferView::SELECT|BufferView::FITCUR);
2184 TEXT(bv_)->CursorBottom(bv_);
2185 TEXT(bv_)->FinishUndo();
2186 moveCursorUpdate(true);
2187 owner_->showState();
2190 // --- text changing commands ------------------------
2191 case LFUN_BREAKLINE:
2192 beforeChange(TEXT(bv_));
2193 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2195 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2196 moveCursorUpdate(false);
2199 case LFUN_PROTECTEDSPACE:
2201 LyXLayout const & style =
2202 textclasslist.Style(buffer_->params.textclass,
2203 TEXT(bv_)->cursor.par()->GetLayout());
2205 if (style.free_spacing) {
2206 TEXT(bv_)->InsertChar(bv_, ' ');
2207 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2209 bv_->protectedBlank(TEXT(bv_));
2211 moveCursorUpdate(false);
2216 if (TEXT(bv_)->mark_set) {
2217 beforeChange(TEXT(bv_));
2218 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2219 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2221 beforeChange(TEXT(bv_));
2222 TEXT(bv_)->mark_set = 1;
2223 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2224 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2226 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2230 if (!TEXT(bv_)->selection) {
2231 TEXT(bv_)->Delete(bv_);
2232 TEXT(bv_)->sel_cursor =
2235 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2236 // It is possible to make it a lot faster still
2237 // just comment out the line below...
2242 moveCursorUpdate(false);
2243 owner_->showState();
2247 case LFUN_DELETE_SKIP:
2249 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2251 LyXCursor cursor = TEXT(bv_)->cursor;
2253 if (!TEXT(bv_)->selection) {
2255 if (cursor.pos() == cursor.par()->Last()) {
2257 if (cursor.pos() == cursor.par()->size()) {
2259 TEXT(bv_)->CursorRight(bv_);
2260 cursor = TEXT(bv_)->cursor;
2261 if (cursor.pos() == 0
2262 && !(cursor.par()->params.spaceTop()
2263 == VSpace (VSpace::NONE))) {
2264 TEXT(bv_)->SetParagraph
2266 cursor.par()->params.lineTop(),
2267 cursor.par()->params.lineBottom(),
2268 cursor.par()->params.pagebreakTop(),
2269 cursor.par()->params.pagebreakBottom(),
2270 VSpace(VSpace::NONE),
2271 cursor.par()->params.spaceBottom(),
2272 cursor.par()->params.align(),
2273 cursor.par()->params.labelWidthString(), 0);
2274 TEXT(bv_)->CursorLeft(bv_);
2276 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2278 TEXT(bv_)->CursorLeft(bv_);
2279 TEXT(bv_)->Delete(bv_);
2280 TEXT(bv_)->sel_cursor =
2283 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2286 TEXT(bv_)->Delete(bv_);
2287 TEXT(bv_)->sel_cursor =
2290 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2298 /* -------> Delete word forward. */
2299 case LFUN_DELETE_WORD_FORWARD:
2300 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2301 TEXT(bv_)->DeleteWordForward(bv_);
2302 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2303 moveCursorUpdate(false);
2304 owner_->showState();
2307 /* -------> Delete word backward. */
2308 case LFUN_DELETE_WORD_BACKWARD:
2309 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2310 TEXT(bv_)->DeleteWordBackward(bv_);
2311 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2312 moveCursorUpdate(false);
2313 owner_->showState();
2316 /* -------> Kill to end of line. */
2317 case LFUN_DELETE_LINE_FORWARD:
2318 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2319 TEXT(bv_)->DeleteLineForward(bv_);
2320 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2321 moveCursorUpdate(false);
2324 /* -------> Set mark off. */
2326 beforeChange(TEXT(bv_));
2327 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2328 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2329 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2332 /* -------> Set mark on. */
2334 beforeChange(TEXT(bv_));
2335 TEXT(bv_)->mark_set = 1;
2336 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2337 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2338 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2341 case LFUN_BACKSPACE:
2343 if (!TEXT(bv_)->selection) {
2344 if (owner_->getIntl()->getTrans().backspace()) {
2345 TEXT(bv_)->Backspace(bv_);
2346 TEXT(bv_)->sel_cursor =
2349 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2350 // It is possible to make it a lot faster still
2351 // just comment out the line below...
2357 owner_->showState();
2362 case LFUN_BACKSPACE_SKIP:
2364 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2366 LyXCursor cursor = TEXT(bv_)->cursor;
2368 if (!TEXT(bv_)->selection) {
2369 if (cursor.pos() == 0
2370 && !(cursor.par()->params.spaceTop()
2371 == VSpace (VSpace::NONE))) {
2372 TEXT(bv_)->SetParagraph
2374 cursor.par()->params.lineTop(),
2375 cursor.par()->params.lineBottom(),
2376 cursor.par()->params.pagebreakTop(),
2377 cursor.par()->params.pagebreakBottom(),
2378 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2379 cursor.par()->params.align(),
2380 cursor.par()->params.labelWidthString(), 0);
2382 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2384 TEXT(bv_)->Backspace(bv_);
2385 TEXT(bv_)->sel_cursor
2388 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2395 case LFUN_BREAKPARAGRAPH:
2397 beforeChange(TEXT(bv_));
2398 TEXT(bv_)->BreakParagraph(bv_, 0);
2400 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2401 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2403 owner_->showState();
2407 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2409 beforeChange(TEXT(bv_));
2410 TEXT(bv_)->BreakParagraph(bv_, 1);
2412 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2413 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2415 owner_->showState();
2419 case LFUN_BREAKPARAGRAPH_SKIP:
2421 // When at the beginning of a paragraph, remove
2422 // indentation and add a "defskip" at the top.
2423 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2425 LyXCursor cursor = TEXT(bv_)->cursor;
2427 beforeChange(TEXT(bv_));
2428 if (cursor.pos() == 0) {
2429 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2430 TEXT(bv_)->SetParagraph
2432 cursor.par()->params.lineTop(),
2433 cursor.par()->params.lineBottom(),
2434 cursor.par()->params.pagebreakTop(),
2435 cursor.par()->params.pagebreakBottom(),
2436 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2437 cursor.par()->params.align(),
2438 cursor.par()->params.labelWidthString(), 1);
2439 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2443 TEXT(bv_)->BreakParagraph(bv_, 0);
2444 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2448 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2449 TEXT(bv_)->sel_cursor = cursor;
2451 owner_->showState();
2455 case LFUN_PARAGRAPH_SPACING:
2457 LyXParagraph * par = TEXT(bv_)->cursor.par();
2458 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2459 float cur_value = 1.0;
2460 if (cur_spacing == Spacing::Other) {
2461 cur_value = par->params.spacing().getValue();
2464 istringstream istr(argument.c_str());
2468 Spacing::Space new_spacing = cur_spacing;
2469 float new_value = cur_value;
2471 lyxerr << "Missing argument to `paragraph-spacing'"
2473 } else if (tmp == "single") {
2474 new_spacing = Spacing::Single;
2475 } else if (tmp == "onehalf") {
2476 new_spacing = Spacing::Onehalf;
2477 } else if (tmp == "double") {
2478 new_spacing = Spacing::Double;
2479 } else if (tmp == "other") {
2480 new_spacing = Spacing::Other;
2483 lyxerr << "new_value = " << tmpval << endl;
2486 } else if (tmp == "default") {
2487 new_spacing = Spacing::Default;
2489 lyxerr << _("Unknown spacing argument: ")
2490 << argument << endl;
2492 if (cur_spacing != new_spacing || cur_value != new_value) {
2493 par->params.spacing(Spacing(new_spacing, new_value));
2494 TEXT(bv_)->RedoParagraph(bv_);
2496 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2502 beforeChange(TEXT(bv_));
2503 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2504 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2505 moveCursorUpdate(false);
2511 InsetCommandParams p;
2512 if (action == LFUN_HTMLURL)
2513 p.setCmdName("htmlurl");
2515 p.setCmdName("url");
2516 owner_->getDialogs()->createUrl( p.getAsString() );
2520 case LFUN_INSERT_URL:
2522 InsetCommandParams p;
2523 p.setFromString( argument );
2525 InsetUrl * inset = new InsetUrl( p );
2526 if (!bv_->insertInset(inset))
2529 bv_->updateInset( inset, true );
2533 case LFUN_INSET_TEXT:
2535 InsetText * new_inset = new InsetText;
2536 if (bv_->insertInset(new_inset))
2537 new_inset->Edit(bv_, 0, 0, 0);
2543 case LFUN_INSET_ERT:
2545 InsetERT * new_inset = new InsetERT;
2546 if (bv_->insertInset(new_inset))
2547 new_inset->Edit(bv_, 0, 0, 0);
2553 case LFUN_INSET_EXTERNAL:
2555 InsetExternal * new_inset = new InsetExternal;
2556 if (bv_->insertInset(new_inset))
2557 new_inset->Edit(bv_, 0, 0, 0);
2563 case LFUN_INSET_FOOTNOTE:
2565 InsetFoot * new_inset = new InsetFoot;
2566 if (bv_->insertInset(new_inset))
2567 new_inset->Edit(bv_, 0, 0, 0);
2573 case LFUN_INSET_MARGINAL:
2575 InsetMarginal * new_inset = new InsetMarginal;
2576 if (bv_->insertInset(new_inset))
2577 new_inset->Edit(bv_, 0, 0, 0);
2583 case LFUN_INSET_MINIPAGE:
2585 InsetMinipage * new_inset = new InsetMinipage;
2586 if (bv_->insertInset(new_inset))
2587 new_inset->Edit(bv_, 0, 0, 0);
2593 case LFUN_INSET_FLOAT:
2595 // check if the float type exist
2596 if (floatList.typeExist(argument)) {
2597 InsetFloat * new_inset = new InsetFloat(argument);
2598 if (bv_->insertInset(new_inset))
2599 new_inset->Edit(bv_, 0, 0, 0);
2603 lyxerr << "Non-existant float type: "
2604 << argument << endl;
2610 case LFUN_INSET_LIST:
2612 InsetList * new_inset = new InsetList;
2613 if (bv_->insertInset(new_inset))
2614 new_inset->Edit(bv_, 0, 0, 0);
2620 case LFUN_INSET_THEOREM:
2622 InsetTheorem * new_inset = new InsetTheorem;
2623 if (bv_->insertInset(new_inset))
2624 new_inset->Edit(bv_, 0, 0, 0);
2630 case LFUN_INSET_CAPTION:
2632 // Do we have a locking inset...
2633 if (bv_->theLockingInset()) {
2634 lyxerr << "Locking inset code: "
2635 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2636 InsetCaption * new_inset = new InsetCaption;
2637 new_inset->setOwner(bv_->theLockingInset());
2638 new_inset->SetAutoBreakRows(true);
2639 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2640 new_inset->SetFrameColor(0, LColor::footnoteframe);
2641 if (bv_->insertInset(new_inset))
2642 new_inset->Edit(bv_, 0, 0, 0);
2649 case LFUN_INSET_TABULAR:
2652 if (!argument.empty())
2653 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2654 InsetTabular * new_inset =
2655 new InsetTabular(*buffer_, r, c);
2657 TEXT(bv_)->real_current_font.isRightToLeft();
2658 if (!bv_->open_new_inset(new_inset, rtl))
2663 // --- lyxserver commands ----------------------------
2665 case LFUN_CHARATCURSOR:
2667 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2668 if (pos < TEXT(bv_)->cursor.par()->size())
2669 owner_->getLyXFunc()->setMessage(
2670 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2672 owner_->getLyXFunc()->setMessage("EOF");
2677 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2679 + tostr(TEXT(bv_)->cursor.y()));
2686 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2687 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2691 case LFUN_GETLAYOUT:
2692 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2697 LyXFont & font = TEXT(bv_)->current_font;
2698 if (font.shape() == LyXFont::ITALIC_SHAPE)
2699 owner_->getLyXFunc()->setMessage("E");
2700 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2701 owner_->getLyXFunc()->setMessage("N");
2703 owner_->getLyXFunc()->setMessage("0");
2710 LyXFont & font = TEXT(bv_)->current_font;
2711 if (font.latex() == LyXFont::ON)
2712 owner_->getLyXFunc()->setMessage("L");
2714 owner_->getLyXFunc()->setMessage("0");
2718 // --- accented characters ---------------------------
2721 case LFUN_CIRCUMFLEX:
2731 case LFUN_SPECIAL_CARON:
2734 case LFUN_HUNG_UMLAUT:
2737 owner_->getLyXFunc()->handleKeyFunc(action);
2740 // --- insert characters ----------------------------------------
2742 case LFUN_MATH_DELIM:
2743 case LFUN_INSERT_MATRIX:
2746 if (bv_->open_new_inset(new InsetFormula(false)))
2748 bv_->theLockingInset()
2749 ->LocalDispatch(bv_, action, argument);
2755 case LFUN_INSERT_MATH:
2760 InsetFormula * f = new InsetFormula(true);
2761 bv_->open_new_inset(f);
2762 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2766 case LFUN_MATH_DISPLAY:
2769 bv_->open_new_inset(new InsetFormula(true));
2773 case LFUN_MATH_MACRO:
2778 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2780 string const s1 = token(s, ' ', 1);
2781 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2782 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2788 case LFUN_MATH_MODE: // Open or create a math inset
2791 bv_->open_new_inset(new InsetFormula);
2792 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2796 case LFUN_CITATION_INSERT:
2798 InsetCommandParams p;
2799 p.setFromString( argument );
2801 InsetCitation * inset = new InsetCitation( p );
2802 if (!bv_->insertInset(inset))
2805 bv_->updateInset( inset, true );
2809 case LFUN_INSERT_BIBTEX:
2811 // ale970405+lasgoutt970425
2812 // The argument can be up to two tokens separated
2813 // by a space. The first one is the bibstyle.
2814 string const db = token(argument, ' ', 0);
2815 string bibstyle = token(argument, ' ', 1);
2816 if (bibstyle.empty())
2819 InsetCommandParams p( "BibTeX", db, bibstyle );
2820 InsetBibtex * inset = new InsetBibtex(p);
2822 if (bv_->insertInset(inset)) {
2823 if (argument.empty())
2824 inset->Edit(bv_, 0, 0, 0);
2830 // BibTeX data bases
2831 case LFUN_BIBDB_ADD:
2833 InsetBibtex * inset =
2834 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2836 inset->addDatabase(argument);
2841 case LFUN_BIBDB_DEL:
2843 InsetBibtex * inset =
2844 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2846 inset->delDatabase(argument);
2851 case LFUN_BIBTEX_STYLE:
2853 InsetBibtex * inset =
2854 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2856 inset->setOptions(argument);
2861 case LFUN_INDEX_CREATE:
2863 InsetCommandParams p( "index" );
2865 if (argument.empty()) {
2866 // Get the word immediately preceding the cursor
2867 LyXParagraph::size_type curpos =
2868 TEXT(bv_)->cursor.pos() - 1;
2872 curstring = TEXT(bv_)
2873 ->cursor.par()->GetWord(curpos);
2875 p.setContents( curstring );
2877 p.setContents( argument );
2880 owner_->getDialogs()->createIndex( p.getAsString() );
2884 case LFUN_INDEX_INSERT:
2886 InsetCommandParams p;
2887 p.setFromString(argument);
2888 InsetIndex * inset = new InsetIndex(p);
2890 if (!bv_->insertInset(inset))
2893 bv_->updateInset(inset, true);
2897 case LFUN_INDEX_INSERT_LAST:
2899 // Get word immediately preceding the cursor
2900 LyXParagraph::size_type curpos =
2901 TEXT(bv_)->cursor.pos() - 1;
2902 // Can't do that at the beginning of a paragraph
2903 if (curpos < 0) break;
2905 string const curstring(TEXT(bv_)
2906 ->cursor.par()->GetWord(curpos));
2908 InsetCommandParams p("index", curstring);
2909 InsetIndex * inset = new InsetIndex(p);
2911 if (!bv_->insertInset(inset))
2914 bv_->updateInset(inset, true);
2918 case LFUN_INDEX_PRINT:
2920 InsetCommandParams p("printindex");
2921 Inset * inset = new InsetPrintIndex(p);
2922 if (!bv_->insertInset(inset, "Standard", true))
2927 case LFUN_PARENTINSERT:
2929 lyxerr << "arg " << argument << endl;
2930 InsetCommandParams p( "lyxparent", argument );
2931 Inset * inset = new InsetParent(p, *buffer_);
2932 if (!bv_->insertInset(inset, "Standard", true))
2938 case LFUN_CHILD_INSERT:
2940 InsetInclude::Params p;
2941 p.cparams.setFromString(argument);
2942 p.masterFilename_ = buffer_->fileName();
2944 InsetInclude * inset = new InsetInclude(p);
2945 if (!bv_->insertInset(inset))
2948 bv_->updateInset(inset, true);
2949 bv_->owner()->getDialogs()->showInclude(inset);
2954 case LFUN_INSERT_NOTE:
2958 case LFUN_SELFINSERT:
2960 LyXFont const old_font(TEXT(bv_)->real_current_font);
2961 for (string::size_type i = 0; i < argument.length(); ++i) {
2962 TEXT(bv_)->InsertChar(bv_, argument[i]);
2963 // This needs to be in the loop, or else we
2964 // won't break lines correctly. (Asger)
2966 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2968 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2969 moveCursorUpdate(false);
2971 // real_current_font.number can change so we need to
2972 // update the minibuffer
2973 if (old_font != TEXT(bv_)->real_current_font)
2974 owner_->showState();
2978 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2982 time_t now_time_t = time(NULL);
2983 now_tm = localtime(&now_time_t);
2984 setlocale(LC_TIME, "");
2986 if (!argument.empty())
2989 arg = lyxrc.date_insert_format;
2991 int const datetmp_len =
2992 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2993 for (int i = 0; i < datetmp_len; i++) {
2994 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2996 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2999 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3000 moveCursorUpdate(false);
3004 case LFUN_UNKNOWN_ACTION:
3007 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
3011 if (buffer_->isReadonly()) {
3012 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
3015 if (!argument.empty()) {
3016 /* Automatically delete the currently selected
3017 * text and replace it with what is being
3018 * typed in now. Depends on lyxrc settings
3019 * "auto_region_delete", which defaults to
3022 if (lyxrc.auto_region_delete) {
3023 if (TEXT(bv_)->selection){
3024 TEXT(bv_)->CutSelection(bv_, false);
3026 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3030 beforeChange(TEXT(bv_));
3031 LyXFont const old_font(TEXT(bv_)->real_current_font);
3032 for (string::size_type i = 0;
3033 i < argument.length(); ++i) {
3034 if (greek_kb_flag) {
3035 if (!math_insert_greek(bv_, argument[i]))
3036 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3038 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3041 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3043 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3044 moveCursorUpdate(false);
3046 // real_current_font.number can change so we need to
3047 // update the minibuffer
3048 if (old_font != TEXT(bv_)->real_current_font)
3049 owner_->showState();
3051 // if we don't have an argument there was something
3052 // strange going on so we just tell this to someone!
3053 owner_->getLyXFunc()->setErrorMessage(N_("No argument given"));