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;
71 /* the selection possible is needed, that only motion events are
72 * used, where the bottom press event was on the drawing area too */
73 bool selection_possible = false;
75 extern BufferList bufferlist;
76 extern char ascii_type;
78 extern void sigchldhandler(pid_t pid, int * status);
79 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
81 const unsigned int saved_positions_num = 20;
86 XSync(fl_get_display(), 0);
91 void SetXtermCursor(Window win)
94 static bool cursor_undefined = true;
95 if (cursor_undefined){
96 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
97 XFlush(fl_get_display());
98 cursor_undefined = false;
100 XDefineCursor(fl_get_display(), win, cursor);
101 XFlush(fl_get_display());
105 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
106 int xpos, int ypos, int width, int height)
107 : bv_(b), owner_(o), buffer_(0),
108 current_scrollbar_value(0), cursor_timeout(400),
109 workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
112 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
113 workarea_.workAreaExpose
114 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
115 workarea_.workAreaEnter
116 .connect(slot(this, &BufferView::Pimpl::enterView));
117 workarea_.workAreaLeave
118 .connect(slot(this, &BufferView::Pimpl::leaveView));
119 workarea_.workAreaButtonPress
120 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
121 workarea_.workAreaButtonRelease
123 &BufferView::Pimpl::workAreaButtonRelease));
124 workarea_.workAreaMotionNotify
125 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
126 workarea_.workAreaDoubleClick
127 .connect(slot(this, &BufferView::Pimpl::doubleClick));
128 workarea_.workAreaTripleClick
129 .connect(slot(this, &BufferView::Pimpl::tripleClick));
130 workarea_.workAreaKeyPress
131 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
135 cursor_timeout.timeout.connect(slot(this,
136 &BufferView::Pimpl::cursorToggle));
137 //current_scrollbar_value = 0;
138 cursor_timeout.start();
139 workarea_.setFocus();
140 //using_xterm_cursor = false;
141 saved_positions.resize(saved_positions_num);
145 Painter & BufferView::Pimpl::painter()
147 return workarea_.getPainter();
151 void BufferView::Pimpl::buffer(Buffer * b)
153 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
157 buffer_->delUser(bv_);
159 // Put the old text into the TextCache, but
160 // only if the buffer is still loaded.
161 // Also set the owner of the test to 0
162 // bv_->text->owner(0);
163 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
164 if (lyxerr.debugging())
165 textcache.show(lyxerr, "BufferView::buffer");
170 // Set current buffer
173 if (bufferlist.getState() == BufferList::CLOSING) return;
176 // screen is always deleted when the buffer is changed.
181 // If we are closing the buffer, use the first buffer as current
183 buffer_ = bufferlist.first();
187 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
188 buffer_->addUser(bv_);
189 // If we don't have a text object for this, we make one
190 if (bv_->text == 0) {
191 resizeCurrentBuffer();
196 bv_->text->first = screen_->TopCursorVisible(bv_->text);
197 owner_->updateMenubar();
198 owner_->updateToolbar();
199 // Similarly, buffer-dependent dialogs should be updated or
200 // hidden. This should go here because some dialogs (eg ToC)
201 // require bv_->text.
202 owner_->getDialogs()->updateBufferDependent(true);
206 lyxerr[Debug::INFO] << " No Buffer!" << endl;
207 owner_->updateMenubar();
208 owner_->updateToolbar();
209 owner_->getDialogs()->hideBufferDependent();
213 // Also remove all remaining text's from the testcache.
214 // (there should not be any!) (if there is any it is a
216 if (lyxerr.debugging())
217 textcache.show(lyxerr, "buffer delete all");
220 // should update layoutchoice even if we don't have a buffer.
221 owner_->updateLayoutChoice();
222 owner_->getMiniBuffer()->Init();
223 owner_->updateWindowTitle();
227 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
229 workarea_.resize(xpos, ypos, width, height);
230 update(bv_->text, SELECT);
235 void BufferView::Pimpl::resize()
238 resizeCurrentBuffer();
242 void BufferView::Pimpl::redraw()
244 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
249 bool BufferView::Pimpl::fitCursor(LyXText * text)
251 Assert(screen_.get());
253 bool ret = screen_->FitCursor(text, bv_);
260 void BufferView::Pimpl::redoCurrentBuffer()
262 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
263 if (buffer_ && bv_->text) {
265 owner_->updateLayoutChoice();
270 int BufferView::Pimpl::resizeCurrentBuffer()
272 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
274 LyXParagraph * par = 0;
275 LyXParagraph * selstartpar = 0;
276 LyXParagraph * selendpar = 0;
277 UpdatableInset * the_locking_inset = 0;
279 LyXParagraph::size_type pos = 0;
280 LyXParagraph::size_type selstartpos = 0;
281 LyXParagraph::size_type selendpos = 0;
282 bool selection = false;
283 bool mark_set = false;
287 owner_->getMiniBuffer()->Set(_("Formatting document..."));
290 par = bv_->text->cursor.par();
291 pos = bv_->text->cursor.pos();
292 selstartpar = bv_->text->sel_start_cursor.par();
293 selstartpos = bv_->text->sel_start_cursor.pos();
294 selendpar = bv_->text->sel_end_cursor.par();
295 selendpos = bv_->text->sel_end_cursor.pos();
296 selection = bv_->text->selection;
297 mark_set = bv_->text->mark_set;
298 the_locking_inset = bv_->text->the_locking_inset;
300 bv_->text = new LyXText(bv_);
302 // See if we have a text in TextCache that fits
303 // the new buffer_ with the correct width.
304 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
306 if (lyxerr.debugging()) {
307 lyxerr << "Found a LyXText that fits:\n";
308 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
310 // Set the owner of the newly found text
311 // bv_->text->owner(bv_);
312 if (lyxerr.debugging())
313 textcache.show(lyxerr, "resizeCurrentBuffer");
315 bv_->text = new LyXText(bv_);
321 bv_->text->selection = true;
322 /* at this point just to avoid the Delete-Empty-Paragraph
323 * Mechanism when setting the cursor */
324 bv_->text->mark_set = mark_set;
326 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
327 bv_->text->sel_cursor = bv_->text->cursor;
328 bv_->text->SetCursor(bv_, selendpar, selendpos);
329 bv_->text->SetSelection(bv_);
330 bv_->text->SetCursor(bv_, par, pos);
332 bv_->text->SetCursor(bv_, par, pos);
333 bv_->text->sel_cursor = bv_->text->cursor;
334 bv_->text->selection = false;
336 // remake the inset locking
337 bv_->text->the_locking_inset = the_locking_inset;
339 bv_->text->first = screen_->TopCursorVisible(bv_->text);
340 buffer_->resizeInsets(bv_);
341 // this will scroll the screen such that the cursor becomes visible
344 owner_->getMiniBuffer()->Init();
348 /// get rid of the splash screen if it's not gone already
349 owner_->getDialogs()->destroySplash();
355 void BufferView::Pimpl::updateScreen()
357 // Regenerate the screen.
358 screen_.reset(new LyXScreen(workarea_));
360 //screen_ = new LyXScreen(workarea_);
364 void BufferView::Pimpl::updateScrollbar()
366 /* If the text is smaller than the working area, the scrollbar
367 * maximum must be the working area height. No scrolling will
371 workarea_.setScrollbar(0, 1.0);
375 static unsigned long max2 = 0;
376 static unsigned long height2 = 0;
378 unsigned long cbth = 0;
382 cbth = bv_->text->height;
383 cbsf = bv_->text->first;
386 // check if anything has changed.
388 height2 == workarea_.height() &&
389 current_scrollbar_value == cbsf)
392 height2 = workarea_.height();
393 current_scrollbar_value = cbsf;
395 if (cbth <= height2) { // text is smaller than screen
396 workarea_.setScrollbar(0, 1.0); // right?
400 long maximum_height = workarea_.height() * 3 / 4 + cbth;
404 double hfloat = workarea_.height();
405 double maxfloat = maximum_height;
407 float slider_size = 0.0;
408 int slider_value = value;
410 workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
411 double const lineh = bv_->text->DefaultHeight();
412 workarea_.setScrollbarIncrements(lineh);
413 if (maxfloat > 0.0) {
414 if ((hfloat / maxfloat) * float(height2) < 3)
415 slider_size = 3.0/float(height2);
417 slider_size = hfloat / maxfloat;
419 slider_size = hfloat;
421 workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
425 // Callback for scrollbar slider
426 void BufferView::Pimpl::scrollCB(double value)
428 if (!buffer_) return;
430 current_scrollbar_value = long(value);
431 if (current_scrollbar_value < 0)
432 current_scrollbar_value = 0;
437 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
439 if (!lyxrc.cursor_follows_scrollbar) {
444 LyXText * vbt = bv_->text;
446 int const height = vbt->DefaultHeight();
447 int const first = static_cast<int>((bv_->text->first + height));
448 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
450 if (vbt->cursor.y() < first)
451 vbt->SetCursorFromCoordinates(bv_, 0, first);
452 else if (vbt->cursor.y() > last)
453 vbt->SetCursorFromCoordinates(bv_, 0, last);
459 int BufferView::Pimpl::scrollUp(long time)
461 if (!buffer_) return 0;
462 if (!screen_.get()) return 0;
464 double value = workarea_.getScrollbarValue();
466 if (value == 0) return 0;
468 float add_value = (bv_->text->DefaultHeight()
469 + float(time) * float(time) * 0.125);
471 if (add_value > workarea_.height())
472 add_value = float(workarea_.height() -
473 bv_->text->DefaultHeight());
480 workarea_.setScrollbarValue(value);
487 int BufferView::Pimpl::scrollDown(long time)
489 if (!buffer_) return 0;
490 if (!screen_.get()) return 0;
492 double value = workarea_.getScrollbarValue();
493 pair<float, float> p = workarea_.getScrollbarBounds();
494 double max = p.second;
496 if (value == max) return 0;
498 float add_value = (bv_->text->DefaultHeight()
499 + float(time) * float(time) * 0.125);
501 if (add_value > workarea_.height())
502 add_value = float(workarea_.height() -
503 bv_->text->DefaultHeight());
510 workarea_.setScrollbarValue(value);
517 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
519 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
523 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
525 // Only use motion with button 1
526 if (!(state & Button1MotionMask))
529 if (!buffer_ || !screen_.get()) return;
531 // Check for inset locking
532 if (bv_->theLockingInset()) {
533 LyXCursor cursor = bv_->text->cursor;
534 LyXFont font = bv_->text->GetFont(bv_->buffer(),
535 cursor.par(), cursor.pos());
536 int width = bv_->theLockingInset()->width(bv_, font);
537 int inset_x = font.isVisibleRightToLeft()
538 ? cursor.x() - width : cursor.x();
539 int start_x = inset_x + bv_->theLockingInset()->scroll();
540 bv_->theLockingInset()->
541 InsetMotionNotify(bv_,
543 y - cursor.y() + bv_->text->first,
548 /* The test for not selection possible is needed, that only motion events are
549 * used, where the bottom press event was on the drawing area too */
550 if (!selection_possible)
553 screen_->HideCursor();
555 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
557 if (!bv_->text->selection)
558 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
560 bv_->text->SetSelection(bv_);
561 screen_->ToggleToggle(bv_->text, bv_);
562 fitCursor(bv_->text);
563 screen_->ShowCursor(bv_->text, bv_);
567 // Single-click on work area
568 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
574 if (!buffer_ || !screen_.get()) return;
576 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
578 // ok ok, this is a hack.
579 if (button == 4 || button == 5) {
582 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
585 scrollDown(lyxrc.wheel_jump);
590 if (bv_->theLockingInset()) {
591 // We are in inset locking mode
593 /* Check whether the inset was hit. If not reset mode,
594 otherwise give the event to the inset */
595 if (inset_hit == bv_->theLockingInset()) {
596 bv_->theLockingInset()->
597 InsetButtonPress(bv_,
602 bv_->unlockInset(bv_->theLockingInset());
607 selection_possible = true;
608 screen_->HideCursor();
610 int const screen_first = bv_->text->first;
612 // Middle button press pastes if we have a selection
613 bool paste_internally = false;
615 && bv_->text->selection) {
616 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
617 paste_internally = true;
620 // Clear the selection
621 screen_->ToggleSelection(bv_->text, bv_);
622 bv_->text->ClearSelection(bv_);
623 bv_->text->FullRebreak(bv_);
624 screen_->Update(bv_->text, bv_);
627 // Single left click in math inset?
628 if ((inset_hit != 0) &&
629 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
630 // Highly editable inset, like math
631 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
632 selection_possible = false;
633 owner_->updateLayoutChoice();
634 owner_->getMiniBuffer()->Set(inset->EditMessage());
635 inset->InsetButtonPress(bv_, xpos, ypos, button);
636 inset->Edit(bv_, xpos, ypos, button);
640 // Right click on a footnote flag opens float menu
642 selection_possible = false;
646 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
647 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
648 bv_->text->FinishUndo();
649 bv_->text->sel_cursor = bv_->text->cursor;
650 bv_->text->cursor.x_fix(bv_->text->cursor.x());
652 owner_->updateLayoutChoice();
653 if (fitCursor(bv_->text)) {
654 selection_possible = false;
657 // Insert primary selection with middle mouse
658 // if there is a local selection in the current buffer,
661 if (paste_internally)
662 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
664 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
666 selection_possible = false;
672 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
678 LyXText * text = bv_->getLyXText();
680 if (text->bv_owner && bv_->theLockingInset())
683 if (screen_.get() && button == 1) {
684 if (text->bv_owner) {
685 screen_->HideCursor();
686 screen_->ToggleSelection(text, bv_);
687 text->SelectWord(bv_);
688 screen_->ToggleSelection(text, bv_, false);
690 text->SelectWord(bv_);
692 /* This will fit the cursor on the screen
694 update(text, BufferView::SELECT|BufferView::FITCUR);
699 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
705 LyXText * text = bv_->getLyXText();
707 if (text->bv_owner && bv_->theLockingInset())
710 if (screen_.get() && (button == 1)) {
711 screen_->HideCursor();
712 screen_->ToggleSelection(text, bv_);
713 text->CursorHome(bv_);
714 text->sel_cursor = text->cursor;
715 text->CursorEnd(bv_);
716 text->SetSelection(bv_);
717 screen_->ToggleSelection(text, bv_, false);
718 /* This will fit the cursor on the screen
720 update(text, BufferView::SELECT|BufferView::FITCUR);
725 void BufferView::Pimpl::enterView()
727 if (active() && available()) {
728 SetXtermCursor(workarea_.getWin());
729 using_xterm_cursor = true;
734 void BufferView::Pimpl::leaveView()
736 if (using_xterm_cursor) {
737 XUndefineCursor(fl_get_display(), workarea_.getWin());
738 using_xterm_cursor = false;
743 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
746 if (!buffer_ || !screen_.get()) return;
748 // If we hit an inset, we have the inset coordinates in these
749 // and inset_hit points to the inset. If we do not hit an
750 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
751 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
753 if (bv_->theLockingInset()) {
754 // We are in inset locking mode.
756 /* LyX does a kind of work-area grabbing for insets.
757 Only a ButtonPress Event outside the inset will
758 force a InsetUnlock. */
759 bv_->theLockingInset()->
760 InsetButtonRelease(bv_, x, y, button);
764 selection_possible = false;
766 if (button >= 2) return;
771 // Did we hit an editable inset?
773 // Inset like error, notes and figures
774 selection_possible = false;
776 // CHECK fix this proper in 0.13
778 // Following a ref shouldn't issue
779 // a push on the undo-stack
780 // anylonger, now that we have
781 // keybindings for following
782 // references and returning from
783 // references. IMHO though, it
784 // should be the inset's own business
785 // to push or not push on the undo
786 // stack. They don't *have* to
787 // alter the document...
789 // ...or maybe the SetCursorParUndo()
790 // below isn't necessary at all anylonger?
791 if (inset_hit->LyxCode() == Inset::REF_CODE) {
792 bv_->text->SetCursorParUndo(bv_->buffer());
795 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
796 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
797 // Highly editable inset, like math
798 UpdatableInset *inset = (UpdatableInset *)inset_hit;
799 inset->InsetButtonRelease(bv_, x, y, button);
801 inset_hit->InsetButtonRelease(bv_, x, y, button);
802 inset_hit->Edit(bv_, x, y, button);
808 // check whether we want to open a float
812 if (bv_->text->cursor.pos() <
813 bv_->text->cursor.par()->Last()) {
814 c = bv_->text->cursor.par()->
815 GetChar(bv_->text->cursor.pos());
817 if(!bv_->text->selection)
818 if (c == LyXParagraph::META_FOOTNOTE
819 || c == LyXParagraph::META_MARGIN
820 || c == LyXParagraph::META_FIG
821 || c == LyXParagraph::META_TAB
822 || c == LyXParagraph::META_WIDE_FIG
823 || c == LyXParagraph::META_WIDE_TAB
824 || c == LyXParagraph::META_ALGORITHM){
827 if (bv_->text->cursor.pos() - 1 >= 0) {
828 c = bv_->text->cursor.par()->
829 GetChar(bv_->text->cursor.pos() - 1);
830 if (c == LyXParagraph::META_FOOTNOTE
831 || c == LyXParagraph::META_MARGIN
832 || c == LyXParagraph::META_FIG
833 || c == LyXParagraph::META_TAB
834 || c == LyXParagraph::META_WIDE_FIG
835 || c == LyXParagraph::META_WIDE_TAB
836 || c == LyXParagraph::META_ALGORITHM){
837 // We are one step too far to the right
838 bv_->text->CursorLeft(bv_);
844 selection_possible = false;
848 // Do we want to close a float? (click on the float-label)
849 if (bv_->text->cursor.row()->par()->footnoteflag ==
850 LyXParagraph::OPEN_FOOTNOTE
851 && bv_->text->cursor.row()->previous() &&
852 bv_->text->cursor.row()->previous()->par()->
853 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
854 LyXFont font(LyXFont::ALL_SANE);
855 font.setSize(LyXFont::SIZE_FOOTNOTE);
857 int box_x = 20; // LYX_PAPER_MARGIN;
858 box_x += lyxfont::width(" wide-tab ", font);
860 unsigned int screen_first = bv_->text->first;
863 && y + screen_first > bv_->text->cursor.y() -
864 bv_->text->cursor.row()->baseline()
865 && y + screen_first < bv_->text->cursor.y() -
866 bv_->text->cursor.row()->baseline()
867 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
869 selection_possible = false;
874 // check whether we want to open a float
878 if (bv_->text->cursor.pos() <
879 bv_->text->cursor.par()->size()) {
880 c = bv_->text->cursor.par()->
881 GetChar(bv_->text->cursor.pos());
883 if (bv_->text->cursor.pos() - 1 >= 0) {
884 c = bv_->text->cursor.par()->
885 GetChar(bv_->text->cursor.pos() - 1);
888 selection_possible = false;
893 // Maybe we want to edit a bibitem ale970302
894 if (bv_->text->cursor.par()->bibkey && x < 20 +
895 bibitemMaxWidth(bv_, textclasslist.
897 params.textclass).defaultfont())) {
898 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
906 * Returns an inset if inset was hit. 0 otherwise.
907 * If hit, the coordinates are changed relative to the inset.
908 * Otherwise coordinates are not changed, and false is returned.
910 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
911 unsigned int /* button */)
916 int y_tmp = y + text->first;
919 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
922 if (cursor.pos() < cursor.par()->Last()
924 if (cursor.pos() < cursor.par()->size()
926 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
927 && cursor.par()->GetInset(cursor.pos())
928 && cursor.par()->GetInset(cursor.pos())->Editable()) {
930 // Check whether the inset really was hit
931 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
932 LyXFont font = text->GetFont(bv_->buffer(),
933 cursor.par(), cursor.pos());
934 int width = tmpinset->width(bv_, font);
935 int inset_x = font.isVisibleRightToLeft()
936 ? cursor.x() - width : cursor.x();
937 int start_x = inset_x + tmpinset->scroll();
938 int end_x = inset_x + width;
940 if (x > start_x && x < end_x
941 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
942 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
943 text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
945 // The origin of an inset is on the baseline
946 y = y_tmp - (text->cursor.y());
951 if ((cursor.pos() - 1 >= 0) &&
952 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
953 (cursor.par()->GetInset(cursor.pos() - 1)) &&
954 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
955 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
956 LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
958 int width = tmpinset->width(bv_, font);
959 int inset_x = font.isVisibleRightToLeft()
960 ? cursor.x() : cursor.x() - width;
961 int start_x = inset_x + tmpinset->scroll();
962 int end_x = inset_x + width;
964 if (x > start_x && x < end_x
965 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
966 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
968 if (move_cursor && (tmpinset != bv_->theLockingInset()))
970 text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
972 // The origin of an inset is on the baseline
973 y = y_tmp - (text->cursor.y());
981 void BufferView::Pimpl::workAreaExpose()
983 static int work_area_width = 0;
984 static unsigned int work_area_height = 0;
986 bool widthChange = workarea_.workWidth() != work_area_width;
987 bool heightChange = workarea_.height() != work_area_height;
989 // update from work area
990 work_area_width = workarea_.workWidth();
991 work_area_height = workarea_.height();
994 // All buffers need a resize
997 // Remove all texts from the textcache
998 // This is not _really_ what we want to do. What
999 // we really want to do is to delete in textcache
1000 // that does not have a BufferView with matching
1001 // width, but as long as we have only one BufferView
1002 // deleting all gives the same result.
1003 if (lyxerr.debugging())
1004 textcache.show(lyxerr, "Expose delete all");
1006 } else if (heightChange) {
1007 // Rebuild image of current screen
1009 // fitCursor() ensures we don't jump back
1010 // to the start of the document on vertical
1012 fitCursor(bv_->text);
1014 // The main window size has changed, repaint most stuff
1016 // ...including the minibuffer
1017 owner_->getMiniBuffer()->Init();
1019 } else if (screen_.get())
1020 screen_->Redraw(bv_->text, bv_);
1022 // Grey box when we don't have a buffer
1023 workarea_.greyOut();
1026 // always make sure that the scrollbar is sane.
1028 owner_->updateLayoutChoice();
1033 void BufferView::Pimpl::update()
1035 if (screen_.get()) screen_->Update(bv_->text, bv_);
1038 // Values used when calling update:
1040 // -2 - update, move sel_cursor if selection, fitcursor
1041 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1042 // 0 - update, move sel_cursor if selection, fitcursor
1043 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
1044 // 3 - update, move sel_cursor if selection
1047 // a simple redraw of the parts that need refresh
1049 // move sel_cursor if selection -
1050 // the text's sel_cursor is moved if there is selection is progress
1053 // fitCursor() is called and the scrollbar updated
1056 // the buffer is marked dirty.
1065 // UPDATE_ONLY = UPDATE;
1066 // UPDATE_SELECT = UPDATE | SELECT;
1067 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1068 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1070 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1071 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1072 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1073 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1074 // update(3) -> update(1) -> update(1) -> update(SELECT)
1076 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1078 owner_->updateLayoutChoice();
1080 if (!text->selection && (f & SELECT)) {
1081 text->sel_cursor = text->cursor;
1084 text->FullRebreak(bv_);
1086 if (text->inset_owner) {
1087 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1088 bv_->updateInset(text->inset_owner, true);
1097 if (buffer_->isLyxClean()) {
1098 buffer_->markDirty();
1099 owner_->getMiniBuffer()->setTimer(4);
1101 buffer_->markDirty();
1107 // Callback for cursor timer
1108 void BufferView::Pimpl::cursorToggle()
1110 // Quite a nice place for asyncron Inset updating, isn't it?
1111 // Actually no! This is run even if no buffer exist... so (Lgb)
1113 cursor_timeout.restart();
1118 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1119 if (pid == -1) // error find out what is wrong
1120 ; // ignore it for now.
1122 sigchldhandler(pid, &status);
1124 updatelist.update(bv_);
1126 if (!screen_.get()) {
1127 cursor_timeout.restart();
1131 if (!bv_->theLockingInset()) {
1132 screen_->CursorToggle(bv_->text, bv_);
1134 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1137 cursor_timeout.restart();
1141 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1143 if (!text->cursor.row()->previous())
1146 int y = text->first;
1147 if (text->inset_owner)
1148 y += bv_->text->first;
1149 Row * cursorrow = text->cursor.row();
1150 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1151 bv_->text->FinishUndo();
1152 // This is to allow jumping over large insets
1153 if ((cursorrow == text->cursor.row()))
1154 text->CursorUp(bv_);
1156 if (text->inset_owner ||
1157 text->cursor.row()->height() < workarea_.height())
1158 screen_->Draw(bv_->text, bv_,
1160 - text->cursor.row()->baseline()
1161 + text->cursor.row()->height()
1162 - workarea_.height() + 1 );
1167 void BufferView::Pimpl::cursorNext(LyXText * text)
1169 if (!text->cursor.row()->next())
1172 int y = text->first + workarea_.height();
1173 // if (text->inset_owner)
1174 // y += bv_->text->first;
1175 text->GetRowNearY(y);
1177 Row * cursorrow = text->cursor.row();
1178 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1179 bv_->text->FinishUndo();
1180 // This is to allow jumping over large insets
1181 if ((cursorrow == bv_->text->cursor.row()))
1182 text->CursorDown(bv_);
1184 if (text->inset_owner ||
1185 text->cursor.row()->height() < workarea_.height())
1186 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1187 text->cursor.row()->baseline());
1192 bool BufferView::Pimpl::available() const
1194 if (buffer_ && bv_->text) return true;
1199 void BufferView::Pimpl::beforeChange(LyXText * text)
1202 text->ClearSelection(bv_);
1206 void BufferView::Pimpl::savePosition(unsigned int i)
1208 if (i >= saved_positions_num)
1210 saved_positions[i] = Position(buffer_->fileName(),
1211 bv_->text->cursor.par()->id(),
1212 bv_->text->cursor.pos());
1214 owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
1218 void BufferView::Pimpl::restorePosition(unsigned int i)
1220 if (i >= saved_positions_num)
1223 string fname = saved_positions[i].filename;
1225 beforeChange(bv_->text);
1227 if (fname != buffer_->fileName()) {
1228 Buffer * b = bufferlist.exists(fname) ?
1229 bufferlist.getBuffer(fname) :
1230 bufferlist.loadLyXFile(fname); // don't ask, just load it
1231 if (b != 0 ) buffer(b);
1234 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1239 bv_->text->SetCursor(bv_, par,
1240 min(par->Last(), saved_positions[i].par_pos));
1242 bv_->text->SetCursor(bv_, par,
1243 min(par->size(), saved_positions[i].par_pos));
1245 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1247 owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
1251 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1253 if (i >= saved_positions_num)
1256 return !saved_positions[i].filename.empty();
1260 void BufferView::Pimpl::setState()
1262 if (!lyxrc.rtl_support)
1265 LyXText * text = bv_->getLyXText();
1266 if (text->real_current_font.isRightToLeft() &&
1267 text->real_current_font.latex() != LyXFont::ON) {
1268 if (owner_->getIntl()->primarykeymap)
1269 owner_->getIntl()->KeyMapSec();
1271 if (!owner_->getIntl()->primarykeymap)
1272 owner_->getIntl()->KeyMapPrim();
1277 void BufferView::Pimpl::insetSleep()
1279 if (bv_->theLockingInset() && !bv_->inset_slept) {
1280 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1281 bv_->theLockingInset()->InsetUnlock(bv_);
1282 bv_->inset_slept = true;
1287 void BufferView::Pimpl::insetWakeup()
1289 if (bv_->theLockingInset() && bv_->inset_slept) {
1290 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1291 bv_->inset_slept = false;
1296 void BufferView::Pimpl::insetUnlock()
1298 if (bv_->theLockingInset()) {
1299 if (!bv_->inset_slept)
1300 bv_->theLockingInset()->InsetUnlock(bv_);
1301 bv_->theLockingInset(0);
1302 bv_->text->FinishUndo();
1303 bv_->inset_slept = false;
1308 bool BufferView::Pimpl::focus() const
1310 return workarea_.hasFocus();
1314 void BufferView::Pimpl::focus(bool f)
1316 if (f) workarea_.setFocus();
1320 bool BufferView::Pimpl::active() const
1322 return workarea_.active();
1326 bool BufferView::Pimpl::belowMouse() const
1328 return workarea_.belowMouse();
1332 void BufferView::Pimpl::showCursor()
1335 screen_->ShowCursor(bv_->text, bv_);
1339 void BufferView::Pimpl::hideCursor()
1342 screen_->HideCursor();
1346 void BufferView::Pimpl::toggleSelection(bool b)
1349 screen_->ToggleSelection(bv_->text, bv_, b);
1353 void BufferView::Pimpl::toggleToggle()
1356 screen_->ToggleToggle(bv_->text, bv_);
1360 void BufferView::Pimpl::center()
1362 beforeChange(bv_->text);
1363 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1364 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1366 screen_->Draw(bv_->text, bv_, 0);
1368 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1373 void BufferView::Pimpl::pasteClipboard(bool asPara)
1375 if (!buffer_) return;
1377 screen_->HideCursor();
1378 beforeChange(bv_->text);
1380 string const clip(workarea_.getClipboard());
1382 if (clip.empty()) return;
1385 bv_->text->InsertStringB(bv_, clip);
1387 bv_->text->InsertStringA(bv_, clip);
1389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1393 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1395 workarea_.putClipboard(stuff);
1400 * Dispatch functions for actions which can be valid for BufferView->text
1401 * and/or InsetText->text!!!
1403 static LyXText * TEXT(BufferView * bv) { return bv->getLyXText(); }
1406 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1408 if (selecting || TEXT(bv_)->mark_set) {
1409 TEXT(bv_)->SetSelection(bv_);
1410 if (TEXT(bv_)->bv_owner)
1411 bv_->toggleToggle();
1413 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1416 /* ---> Everytime the cursor is moved, show the current font state. */
1417 // should this too me moved out of this func?
1418 //owner->showState();
1423 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1425 LyXCursor cursor = TEXT(bv_)->cursor;
1426 Buffer::inset_iterator it =
1427 find_if(Buffer::inset_iterator(
1428 cursor.par(), cursor.pos()),
1429 buffer_->inset_iterator_end(),
1430 compare_memfun(&Inset::LyxCode, code)
1432 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1436 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1438 string filename = filen;
1440 if (filename.empty()) {
1441 // Launch a file browser
1442 string initpath = lyxrc.document_path;
1445 string const trypath = owner_->buffer()->filepath;
1446 // If directory is writeable, use this as default.
1447 if (IsDirWriteable(trypath) == 1)
1451 FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
1453 make_pair(string(_("Documents")), string(lyxrc.document_path)),
1454 make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
1456 FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
1458 if (result.first == FileDialog::Later)
1461 filename = result.second;
1463 // check selected filename
1464 if (filename.empty()) {
1465 owner_->getMiniBuffer()->Set(_("Canceled."));
1470 // get absolute path of file and make sure the filename ends
1472 filename = MakeAbsPath(filename);
1473 if (!IsLyXFilename(filename))
1477 owner_->getMiniBuffer()->Set(_("Inserting document"),
1478 MakeDisplayPath(filename), "...");
1479 bool const res = bv_->insertLyXFile(filename);
1481 owner_->getMiniBuffer()->Set(_("Document"),
1482 MakeDisplayPath(filename),
1485 owner_->getMiniBuffer()->Set(_("Could not insert document"),
1486 MakeDisplayPath(filename));
1491 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1494 // --- Misc -------------------------------------------
1497 TEXT(bv_)->toggleAppendix(bv_);
1498 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1502 case LFUN_TOC_INSERT:
1503 case LFUN_LOA_INSERT:
1504 case LFUN_LOF_INSERT:
1505 case LFUN_LOT_INSERT:
1507 InsetCommandParams p;
1509 if (action == LFUN_TOC_INSERT )
1510 p.setCmdName( "tableofcontents" );
1511 else if (action == LFUN_LOA_INSERT )
1512 p.setCmdName( "listofalgorithms" );
1513 else if (action == LFUN_LOF_INSERT )
1514 p.setCmdName( "listoffigures" );
1516 p.setCmdName( "listoftables" );
1518 Inset * inset = new InsetTOC( p );
1519 if (!bv_->insertInset( inset, "Standard", true ) )
1524 case LFUN_TABULAR_FEATURE:
1525 case LFUN_SCROLL_INSET:
1526 // this is not handled here as this funktion is only aktive
1527 // if we have a locking_inset and that one is (or contains)
1531 case LFUN_INSET_GRAPHICS:
1533 Inset * new_inset = new InsetGraphics;
1534 if (!bv_->insertInset(new_inset)) {
1537 // this is need because you don't use a inset->Edit()
1538 bv_->updateInset(new_inset, true);
1539 new_inset->Edit(bv_, 0, 0, 0);
1549 case LFUN_PASTESELECTION:
1551 bool asPara = false;
1552 if (argument == "paragraph") asPara = true;
1553 pasteClipboard(asPara);
1565 case LFUN_LAYOUT_COPY:
1566 bv_->copyEnvironment();
1569 case LFUN_LAYOUT_PASTE:
1570 bv_->pasteEnvironment();
1574 case LFUN_GOTOERROR:
1575 bv_->gotoInset(Inset::ERROR_CODE, false);
1579 bv_->gotoInset(Inset::IGNORE_CODE, false);
1582 case LFUN_REFERENCE_GOTO:
1584 vector<Inset::Code> tmp;
1585 tmp.push_back(Inset::LABEL_CODE);
1586 tmp.push_back(Inset::REF_CODE);
1587 bv_->gotoInset(tmp, true);
1591 case LFUN_HYPHENATION:
1592 bv_->hyphenationPoint();
1599 case LFUN_END_OF_SENTENCE:
1600 bv_->endOfSentenceDot();
1603 case LFUN_MENU_SEPARATOR:
1604 bv_->menuSeparator();
1612 changeDepth(bv_, TEXT(bv_), 0);
1615 case LFUN_DEPTH_MIN:
1616 changeDepth(bv_, TEXT(bv_), -1);
1619 case LFUN_DEPTH_PLUS:
1620 changeDepth(bv_, TEXT(bv_), 1);
1624 owner_->getDialogs()->setUserFreeFont();
1630 owner_->showState();
1633 case LFUN_FILE_INSERT:
1635 MenuInsertLyXFile(argument);
1639 case LFUN_FILE_INSERT_ASCII_PARA:
1640 InsertAsciiFile(bv_, argument, true);
1643 case LFUN_FILE_INSERT_ASCII:
1644 InsertAsciiFile(bv_, argument, false);
1649 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1650 << argument << endl;
1652 // Derive layout number from given argument (string)
1653 // and current buffer's textclass (number). */
1654 LyXTextClassList::ClassList::size_type tclass =
1655 buffer_->params.textclass;
1656 pair <bool, LyXTextClass::size_type> layout =
1657 textclasslist.NumberOfLayout(tclass, argument);
1659 // If the entry is obsolete, use the new one instead.
1661 string obs = textclasslist.Style(tclass,layout.second)
1665 textclasslist.NumberOfLayout(tclass, obs);
1668 // see if we found the layout number:
1669 if (!layout.first) {
1670 owner_->getLyXFunc()->setErrorMessage(
1671 string(N_("Layout ")) + argument +
1676 if (current_layout != layout.second) {
1678 current_layout = layout.second;
1680 BufferView::SELECT|BufferView::FITCUR);
1681 TEXT(bv_)->SetLayout(bv_, layout.second);
1682 owner_->setLayout(layout.second);
1684 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1691 Lang(bv_, argument);
1693 owner_->showState();
1698 owner_->showState();
1703 owner_->showState();
1708 owner_->showState();
1713 owner_->showState();
1718 owner_->showState();
1723 owner_->showState();
1728 owner_->showState();
1731 case LFUN_UNDERLINE:
1733 owner_->showState();
1736 case LFUN_FONT_SIZE:
1737 FontSize(bv_, argument);
1738 owner_->showState();
1741 case LFUN_FONT_STATE:
1742 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1745 case LFUN_UPCASE_WORD:
1746 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1747 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_uppercase);
1748 if (TEXT(bv_)->inset_owner)
1749 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1750 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1753 case LFUN_LOWCASE_WORD:
1754 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1755 TEXT(bv_)->ChangeWordCase(bv_, LyXText::text_lowercase);
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_CAPITALIZE_WORD:
1762 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1763 TEXT(bv_)->ChangeWordCase(bv_,
1764 LyXText::text_capitalization);
1765 if (TEXT(bv_)->inset_owner)
1766 bv_->updateInset(TEXT(bv_)->inset_owner, true);
1767 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1770 case LFUN_INSERT_LABEL:
1771 MenuInsertLabel(bv_, argument);
1774 case LFUN_REF_INSERT:
1775 if (argument.empty()) {
1776 InsetCommandParams p("ref");
1777 owner_->getDialogs()->createRef(p.getAsString());
1779 InsetCommandParams p;
1780 p.setFromString(argument);
1782 InsetRef * inset = new InsetRef(p, *buffer_);
1783 if (!bv_->insertInset(inset))
1786 bv_->updateInset(inset, true);
1790 case LFUN_BOOKMARK_SAVE:
1791 savePosition(strToUnsignedInt(argument));
1794 case LFUN_BOOKMARK_GOTO:
1795 restorePosition(strToUnsignedInt(argument));
1800 string label(argument);
1801 if (label.empty()) {
1803 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1805 label = inset->getContents();
1810 if (!label.empty()) {
1811 //bv_->savePosition(0);
1812 if (!bv_->gotoLabel(label))
1813 WriteAlert(_("Error"),
1814 _("Couldn't find this label"),
1815 _("in current document."));
1820 // --- Cursor Movements -----------------------------
1823 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1824 if (!TEXT(bv_)->mark_set)
1825 beforeChange(TEXT(bv_));
1826 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1828 TEXT(bv_)->CursorLeft(bv_, false);
1830 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
1832 if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
1834 && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
1835 == LyXParagraph::META_INSET
1836 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
1837 && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1838 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1839 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1843 TEXT(bv_)->GetFont(buffer_,
1844 TEXT(bv_)->cursor.par(),
1845 TEXT(bv_)->cursor.pos());
1846 y = tmpinset->descent(bv_,font);
1848 tmpinset->Edit(bv_, 0, y, 0);
1852 TEXT(bv_)->CursorRight(bv_, false);
1853 TEXT(bv_)->FinishUndo();
1854 moveCursorUpdate(false);
1855 owner_->showState();
1861 // This is soooo ugly. Isn`t it possible to make
1862 // it simpler? (Lgb)
1863 bool is_rtl = TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params);
1864 if (!TEXT(bv_)->mark_set)
1865 beforeChange(TEXT(bv_));
1866 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1867 LyXCursor cur = TEXT(bv_)->cursor;
1869 TEXT(bv_)->CursorLeft(bv_, false);
1870 if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
1872 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
1874 TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
1876 (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
1877 LyXParagraph::META_INSET) &&
1878 TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
1879 (TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())->Editable()
1880 == Inset::HIGHLY_EDITABLE))
1882 Inset * tmpinset = TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos());
1883 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1884 LyXFont font = TEXT(bv_)->GetFont(buffer_,
1885 TEXT(bv_)->cursor.par(),
1886 TEXT(bv_)->cursor.pos());
1888 : tmpinset->descent(bv_,font);
1891 tmpinset->width(bv_,font),
1896 TEXT(bv_)->CursorRight(bv_, false);
1898 TEXT(bv_)->FinishUndo();
1899 moveCursorUpdate(false);
1900 owner_->showState();
1905 if (!TEXT(bv_)->mark_set)
1906 beforeChange(TEXT(bv_));
1907 update(TEXT(bv_), BufferView::UPDATE);
1908 TEXT(bv_)->CursorUp(bv_);
1909 TEXT(bv_)->FinishUndo();
1910 moveCursorUpdate(false);
1911 owner_->showState();
1915 if (!TEXT(bv_)->mark_set)
1916 beforeChange(TEXT(bv_));
1917 update(TEXT(bv_), BufferView::UPDATE);
1918 TEXT(bv_)->CursorDown(bv_);
1919 TEXT(bv_)->FinishUndo();
1920 moveCursorUpdate(false);
1921 owner_->showState();
1924 case LFUN_UP_PARAGRAPH:
1925 if (!TEXT(bv_)->mark_set)
1926 beforeChange(TEXT(bv_));
1927 update(TEXT(bv_), BufferView::UPDATE);
1928 TEXT(bv_)->CursorUpParagraph(bv_);
1929 TEXT(bv_)->FinishUndo();
1930 moveCursorUpdate(false);
1931 owner_->showState();
1934 case LFUN_DOWN_PARAGRAPH:
1935 if (!TEXT(bv_)->mark_set)
1936 beforeChange(TEXT(bv_));
1937 update(TEXT(bv_), BufferView::UPDATE);
1938 TEXT(bv_)->CursorDownParagraph(bv_);
1939 TEXT(bv_)->FinishUndo();
1940 moveCursorUpdate(false);
1941 owner_->showState();
1945 if (!TEXT(bv_)->mark_set)
1946 beforeChange(TEXT(bv_));
1947 update(TEXT(bv_), BufferView::UPDATE);
1948 cursorPrevious(TEXT(bv_));
1949 TEXT(bv_)->FinishUndo();
1950 moveCursorUpdate(false);
1951 owner_->showState();
1955 if (!TEXT(bv_)->mark_set)
1956 beforeChange(TEXT(bv_));
1957 update(TEXT(bv_), BufferView::UPDATE);
1958 cursorNext(TEXT(bv_));
1959 TEXT(bv_)->FinishUndo();
1960 moveCursorUpdate(false);
1961 owner_->showState();
1965 if (!TEXT(bv_)->mark_set)
1966 beforeChange(TEXT(bv_));
1967 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
1968 TEXT(bv_)->CursorHome(bv_);
1969 TEXT(bv_)->FinishUndo();
1970 moveCursorUpdate(false);
1971 owner_->showState();
1975 if (!TEXT(bv_)->mark_set)
1976 beforeChange(TEXT(bv_));
1978 BufferView::SELECT|BufferView::FITCUR);
1979 TEXT(bv_)->CursorEnd(bv_);
1980 TEXT(bv_)->FinishUndo();
1981 moveCursorUpdate(false);
1982 owner_->showState();
1985 case LFUN_SHIFT_TAB:
1987 if (!TEXT(bv_)->mark_set)
1988 beforeChange(TEXT(bv_));
1990 BufferView::SELECT|BufferView::FITCUR);
1991 TEXT(bv_)->CursorTab(bv_);
1992 TEXT(bv_)->FinishUndo();
1993 moveCursorUpdate(false);
1994 owner_->showState();
1997 case LFUN_WORDRIGHT:
1998 if (!TEXT(bv_)->mark_set)
1999 beforeChange(TEXT(bv_));
2000 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2001 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2002 TEXT(bv_)->CursorLeftOneWord(bv_);
2004 TEXT(bv_)->CursorRightOneWord(bv_);
2005 TEXT(bv_)->FinishUndo();
2006 moveCursorUpdate(false);
2007 owner_->showState();
2011 if (!TEXT(bv_)->mark_set)
2012 beforeChange(TEXT(bv_));
2013 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2014 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2015 TEXT(bv_)->CursorRightOneWord(bv_);
2017 TEXT(bv_)->CursorLeftOneWord(bv_);
2018 TEXT(bv_)->FinishUndo();
2019 moveCursorUpdate(false);
2020 owner_->showState();
2023 case LFUN_BEGINNINGBUF:
2024 if (!TEXT(bv_)->mark_set)
2025 beforeChange(TEXT(bv_));
2027 BufferView::SELECT|BufferView::FITCUR);
2028 TEXT(bv_)->CursorTop(bv_);
2029 TEXT(bv_)->FinishUndo();
2030 moveCursorUpdate(false);
2031 owner_->showState();
2035 if (!TEXT(bv_)->mark_set)
2036 beforeChange(TEXT(bv_));
2038 BufferView::SELECT|BufferView::FITCUR);
2039 TEXT(bv_)->CursorBottom(bv_);
2040 TEXT(bv_)->FinishUndo();
2041 moveCursorUpdate(false);
2042 owner_->showState();
2046 /* cursor selection ---------------------------- */
2049 BufferView::SELECT|BufferView::FITCUR);
2050 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2051 TEXT(bv_)->CursorLeft(bv_);
2053 TEXT(bv_)->CursorRight(bv_);
2054 TEXT(bv_)->FinishUndo();
2055 moveCursorUpdate(true);
2056 owner_->showState();
2061 BufferView::SELECT|BufferView::FITCUR);
2062 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2063 TEXT(bv_)->CursorRight(bv_);
2065 TEXT(bv_)->CursorLeft(bv_);
2066 TEXT(bv_)->FinishUndo();
2067 moveCursorUpdate(true);
2068 owner_->showState();
2073 BufferView::SELECT|BufferView::FITCUR);
2074 TEXT(bv_)->CursorUp(bv_);
2075 TEXT(bv_)->FinishUndo();
2076 moveCursorUpdate(true);
2077 owner_->showState();
2082 BufferView::SELECT|BufferView::FITCUR);
2083 TEXT(bv_)->CursorDown(bv_);
2084 TEXT(bv_)->FinishUndo();
2085 moveCursorUpdate(true);
2086 owner_->showState();
2089 case LFUN_UP_PARAGRAPHSEL:
2091 BufferView::SELECT|BufferView::FITCUR);
2092 TEXT(bv_)->CursorUpParagraph(bv_);
2093 TEXT(bv_)->FinishUndo();
2094 moveCursorUpdate(true);
2095 owner_->showState();
2098 case LFUN_DOWN_PARAGRAPHSEL:
2100 BufferView::SELECT|BufferView::FITCUR);
2101 TEXT(bv_)->CursorDownParagraph(bv_);
2102 TEXT(bv_)->FinishUndo();
2103 moveCursorUpdate(true);
2104 owner_->showState();
2108 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2109 cursorPrevious(TEXT(bv_));
2110 TEXT(bv_)->FinishUndo();
2111 moveCursorUpdate(true);
2112 owner_->showState();
2116 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2117 cursorNext(TEXT(bv_));
2118 TEXT(bv_)->FinishUndo();
2119 moveCursorUpdate(true);
2120 owner_->showState();
2124 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2125 TEXT(bv_)->CursorHome(bv_);
2126 TEXT(bv_)->FinishUndo();
2127 moveCursorUpdate(true);
2128 owner_->showState();
2132 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2133 TEXT(bv_)->CursorEnd(bv_);
2134 TEXT(bv_)->FinishUndo();
2135 moveCursorUpdate(true);
2136 owner_->showState();
2139 case LFUN_WORDRIGHTSEL:
2140 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2141 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2142 TEXT(bv_)->CursorLeftOneWord(bv_);
2144 TEXT(bv_)->CursorRightOneWord(bv_);
2145 TEXT(bv_)->FinishUndo();
2146 moveCursorUpdate(true);
2147 owner_->showState();
2150 case LFUN_WORDLEFTSEL:
2151 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2152 if (TEXT(bv_)->cursor.par()->isRightToLeftPar(buffer_->params))
2153 TEXT(bv_)->CursorRightOneWord(bv_);
2155 TEXT(bv_)->CursorLeftOneWord(bv_);
2156 TEXT(bv_)->FinishUndo();
2157 moveCursorUpdate(true);
2158 owner_->showState();
2161 case LFUN_BEGINNINGBUFSEL:
2162 if (TEXT(bv_)->inset_owner)
2164 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2165 TEXT(bv_)->CursorTop(bv_);
2166 TEXT(bv_)->FinishUndo();
2167 moveCursorUpdate(true);
2168 owner_->showState();
2171 case LFUN_ENDBUFSEL:
2172 if (TEXT(bv_)->inset_owner)
2175 BufferView::SELECT|BufferView::FITCUR);
2176 TEXT(bv_)->CursorBottom(bv_);
2177 TEXT(bv_)->FinishUndo();
2178 moveCursorUpdate(true);
2179 owner_->showState();
2182 // --- text changing commands ------------------------
2183 case LFUN_BREAKLINE:
2184 beforeChange(TEXT(bv_));
2185 TEXT(bv_)->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2187 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2188 moveCursorUpdate(false);
2191 case LFUN_PROTECTEDSPACE:
2193 LyXLayout const & style =
2194 textclasslist.Style(buffer_->params.textclass,
2195 TEXT(bv_)->cursor.par()->GetLayout());
2197 if (style.free_spacing) {
2198 TEXT(bv_)->InsertChar(bv_, ' ');
2199 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2201 bv_->protectedBlank(TEXT(bv_));
2203 moveCursorUpdate(false);
2208 if (TEXT(bv_)->mark_set) {
2209 beforeChange(TEXT(bv_));
2210 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2211 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2213 beforeChange(TEXT(bv_));
2214 TEXT(bv_)->mark_set = 1;
2215 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2216 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2218 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2222 if (!TEXT(bv_)->selection) {
2223 TEXT(bv_)->Delete(bv_);
2224 TEXT(bv_)->sel_cursor =
2227 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2228 // It is possible to make it a lot faster still
2229 // just comment out the line below...
2234 moveCursorUpdate(false);
2235 owner_->showState();
2239 case LFUN_DELETE_SKIP:
2241 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2243 LyXCursor cursor = TEXT(bv_)->cursor;
2245 if (!TEXT(bv_)->selection) {
2247 if (cursor.pos() == cursor.par()->Last()) {
2249 if (cursor.pos() == cursor.par()->size()) {
2251 TEXT(bv_)->CursorRight(bv_);
2252 cursor = TEXT(bv_)->cursor;
2253 if (cursor.pos() == 0
2254 && !(cursor.par()->params.spaceTop()
2255 == VSpace (VSpace::NONE))) {
2256 TEXT(bv_)->SetParagraph
2258 cursor.par()->params.lineTop(),
2259 cursor.par()->params.lineBottom(),
2260 cursor.par()->params.pagebreakTop(),
2261 cursor.par()->params.pagebreakBottom(),
2262 VSpace(VSpace::NONE),
2263 cursor.par()->params.spaceBottom(),
2264 cursor.par()->params.align(),
2265 cursor.par()->params.labelWidthString(), 0);
2266 TEXT(bv_)->CursorLeft(bv_);
2268 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2270 TEXT(bv_)->CursorLeft(bv_);
2271 TEXT(bv_)->Delete(bv_);
2272 TEXT(bv_)->sel_cursor =
2275 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2278 TEXT(bv_)->Delete(bv_);
2279 TEXT(bv_)->sel_cursor =
2282 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2290 /* -------> Delete word forward. */
2291 case LFUN_DELETE_WORD_FORWARD:
2292 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2293 TEXT(bv_)->DeleteWordForward(bv_);
2294 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2295 moveCursorUpdate(false);
2296 owner_->showState();
2299 /* -------> Delete word backward. */
2300 case LFUN_DELETE_WORD_BACKWARD:
2301 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2302 TEXT(bv_)->DeleteWordBackward(bv_);
2303 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2304 moveCursorUpdate(false);
2305 owner_->showState();
2308 /* -------> Kill to end of line. */
2309 case LFUN_DELETE_LINE_FORWARD:
2310 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2311 TEXT(bv_)->DeleteLineForward(bv_);
2312 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2313 moveCursorUpdate(false);
2316 /* -------> Set mark off. */
2318 beforeChange(TEXT(bv_));
2319 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2320 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2321 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2324 /* -------> Set mark on. */
2326 beforeChange(TEXT(bv_));
2327 TEXT(bv_)->mark_set = 1;
2328 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
2329 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2330 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2333 case LFUN_BACKSPACE:
2335 if (!TEXT(bv_)->selection) {
2336 if (owner_->getIntl()->getTrans().backspace()) {
2337 TEXT(bv_)->Backspace(bv_);
2338 TEXT(bv_)->sel_cursor =
2341 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2342 // It is possible to make it a lot faster still
2343 // just comment out the line below...
2349 owner_->showState();
2354 case LFUN_BACKSPACE_SKIP:
2356 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2358 LyXCursor cursor = TEXT(bv_)->cursor;
2360 if (!TEXT(bv_)->selection) {
2361 if (cursor.pos() == 0
2362 && !(cursor.par()->params.spaceTop()
2363 == VSpace (VSpace::NONE))) {
2364 TEXT(bv_)->SetParagraph
2366 cursor.par()->params.lineTop(),
2367 cursor.par()->params.lineBottom(),
2368 cursor.par()->params.pagebreakTop(),
2369 cursor.par()->params.pagebreakBottom(),
2370 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2371 cursor.par()->params.align(),
2372 cursor.par()->params.labelWidthString(), 0);
2374 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2376 TEXT(bv_)->Backspace(bv_);
2377 TEXT(bv_)->sel_cursor
2380 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2387 case LFUN_BREAKPARAGRAPH:
2389 beforeChange(TEXT(bv_));
2390 TEXT(bv_)->BreakParagraph(bv_, 0);
2392 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2393 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2395 owner_->showState();
2399 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2401 beforeChange(TEXT(bv_));
2402 TEXT(bv_)->BreakParagraph(bv_, 1);
2404 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2405 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2407 owner_->showState();
2411 case LFUN_BREAKPARAGRAPH_SKIP:
2413 // When at the beginning of a paragraph, remove
2414 // indentation and add a "defskip" at the top.
2415 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2417 LyXCursor cursor = TEXT(bv_)->cursor;
2419 beforeChange(TEXT(bv_));
2420 if (cursor.pos() == 0) {
2421 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2422 TEXT(bv_)->SetParagraph
2424 cursor.par()->params.lineTop(),
2425 cursor.par()->params.lineBottom(),
2426 cursor.par()->params.pagebreakTop(),
2427 cursor.par()->params.pagebreakBottom(),
2428 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2429 cursor.par()->params.align(),
2430 cursor.par()->params.labelWidthString(), 1);
2431 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2435 TEXT(bv_)->BreakParagraph(bv_, 0);
2436 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2440 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2441 TEXT(bv_)->sel_cursor = cursor;
2443 owner_->showState();
2447 case LFUN_PARAGRAPH_SPACING:
2449 LyXParagraph * par = TEXT(bv_)->cursor.par();
2450 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2451 float cur_value = 1.0;
2452 if (cur_spacing == Spacing::Other) {
2453 cur_value = par->params.spacing().getValue();
2456 istringstream istr(argument.c_str());
2460 Spacing::Space new_spacing = cur_spacing;
2461 float new_value = cur_value;
2463 lyxerr << "Missing argument to `paragraph-spacing'"
2465 } else if (tmp == "single") {
2466 new_spacing = Spacing::Single;
2467 } else if (tmp == "onehalf") {
2468 new_spacing = Spacing::Onehalf;
2469 } else if (tmp == "double") {
2470 new_spacing = Spacing::Double;
2471 } else if (tmp == "other") {
2472 new_spacing = Spacing::Other;
2475 lyxerr << "new_value = " << tmpval << endl;
2478 } else if (tmp == "default") {
2479 new_spacing = Spacing::Default;
2481 lyxerr << _("Unknown spacing argument: ")
2482 << argument << endl;
2484 if (cur_spacing != new_spacing || cur_value != new_value) {
2485 par->params.spacing(Spacing(new_spacing, new_value));
2486 TEXT(bv_)->RedoParagraph(bv_);
2488 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2494 beforeChange(TEXT(bv_));
2495 TEXT(bv_)->InsertChar(bv_, '\"'); // This " matches the single quote in the code
2496 update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2497 moveCursorUpdate(false);
2503 InsetCommandParams p;
2504 if (action == LFUN_HTMLURL)
2505 p.setCmdName("htmlurl");
2507 p.setCmdName("url");
2508 owner_->getDialogs()->createUrl( p.getAsString() );
2512 case LFUN_INSERT_URL:
2514 InsetCommandParams p;
2515 p.setFromString( argument );
2517 InsetUrl * inset = new InsetUrl( p );
2518 if (!bv_->insertInset(inset))
2521 bv_->updateInset( inset, true );
2525 case LFUN_INSET_TEXT:
2527 InsetText * new_inset = new InsetText;
2528 if (bv_->insertInset(new_inset))
2529 new_inset->Edit(bv_, 0, 0, 0);
2535 case LFUN_INSET_ERT:
2537 InsetERT * new_inset = new InsetERT;
2538 if (bv_->insertInset(new_inset))
2539 new_inset->Edit(bv_, 0, 0, 0);
2545 case LFUN_INSET_EXTERNAL:
2547 InsetExternal * new_inset = new InsetExternal;
2548 if (bv_->insertInset(new_inset))
2549 new_inset->Edit(bv_, 0, 0, 0);
2555 case LFUN_INSET_FOOTNOTE:
2557 InsetFoot * new_inset = new InsetFoot;
2558 if (bv_->insertInset(new_inset))
2559 new_inset->Edit(bv_, 0, 0, 0);
2565 case LFUN_INSET_MARGINAL:
2567 InsetMarginal * new_inset = new InsetMarginal;
2568 if (bv_->insertInset(new_inset))
2569 new_inset->Edit(bv_, 0, 0, 0);
2575 case LFUN_INSET_MINIPAGE:
2577 InsetMinipage * new_inset = new InsetMinipage;
2578 if (bv_->insertInset(new_inset))
2579 new_inset->Edit(bv_, 0, 0, 0);
2585 case LFUN_INSET_FLOAT:
2587 // check if the float type exist
2588 if (floatList.typeExist(argument)) {
2589 InsetFloat * new_inset = new InsetFloat(argument);
2590 if (bv_->insertInset(new_inset))
2591 new_inset->Edit(bv_, 0, 0, 0);
2595 lyxerr << "Non-existant float type: "
2596 << argument << endl;
2602 case LFUN_INSET_LIST:
2604 InsetList * new_inset = new InsetList;
2605 if (bv_->insertInset(new_inset))
2606 new_inset->Edit(bv_, 0, 0, 0);
2612 case LFUN_INSET_THEOREM:
2614 InsetTheorem * new_inset = new InsetTheorem;
2615 if (bv_->insertInset(new_inset))
2616 new_inset->Edit(bv_, 0, 0, 0);
2622 case LFUN_INSET_CAPTION:
2624 // Do we have a locking inset...
2625 if (bv_->theLockingInset()) {
2626 lyxerr << "Locking inset code: "
2627 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2628 InsetCaption * new_inset = new InsetCaption;
2629 new_inset->setOwner(bv_->theLockingInset());
2630 new_inset->SetAutoBreakRows(true);
2631 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2632 new_inset->SetFrameColor(0, LColor::footnoteframe);
2633 if (bv_->insertInset(new_inset))
2634 new_inset->Edit(bv_, 0, 0, 0);
2641 case LFUN_INSET_TABULAR:
2644 if (!argument.empty())
2645 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2646 InsetTabular * new_inset =
2647 new InsetTabular(*buffer_, r, c);
2649 TEXT(bv_)->real_current_font.isRightToLeft();
2650 if (!bv_->open_new_inset(new_inset, rtl))
2655 // --- lyxserver commands ----------------------------
2657 case LFUN_CHARATCURSOR:
2659 LyXParagraph::size_type pos = TEXT(bv_)->cursor.pos();
2660 if (pos < TEXT(bv_)->cursor.par()->size())
2661 owner_->getLyXFunc()->setMessage(
2662 tostr(TEXT(bv_)->cursor.par()->GetChar(pos)));
2664 owner_->getLyXFunc()->setMessage("EOF");
2669 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.x())
2671 + tostr(TEXT(bv_)->cursor.y()));
2678 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2679 TEXT(bv_)->SetCursorFromCoordinates(bv_, x, y);
2683 case LFUN_GETLAYOUT:
2684 owner_->getLyXFunc()->setMessage(tostr(TEXT(bv_)->cursor.par()->layout));
2689 LyXFont & font = TEXT(bv_)->current_font;
2690 if (font.shape() == LyXFont::ITALIC_SHAPE)
2691 owner_->getLyXFunc()->setMessage("E");
2692 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2693 owner_->getLyXFunc()->setMessage("N");
2695 owner_->getLyXFunc()->setMessage("0");
2702 LyXFont & font = TEXT(bv_)->current_font;
2703 if (font.latex() == LyXFont::ON)
2704 owner_->getLyXFunc()->setMessage("L");
2706 owner_->getLyXFunc()->setMessage("0");
2710 // --- accented characters ---------------------------
2713 case LFUN_CIRCUMFLEX:
2723 case LFUN_SPECIAL_CARON:
2726 case LFUN_HUNG_UMLAUT:
2729 owner_->getLyXFunc()->handleKeyFunc(action);
2732 // --- insert characters ----------------------------------------
2734 case LFUN_MATH_DELIM:
2735 case LFUN_INSERT_MATRIX:
2738 if (bv_->open_new_inset(new InsetFormula(false)))
2740 bv_->theLockingInset()
2741 ->LocalDispatch(bv_, action, argument);
2747 case LFUN_INSERT_MATH:
2749 math_insert_symbol(bv_, argument);
2753 case LFUN_MATH_DISPLAY:
2756 bv_->open_new_inset(new InsetFormula(true));
2760 case LFUN_MATH_MACRO:
2765 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2767 string const s1 = token(s, ' ', 1);
2768 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2769 bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2775 case LFUN_MATH_MODE: // Open or create a math inset
2778 bv_->open_new_inset(new InsetFormula);
2779 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2783 case LFUN_CITATION_INSERT:
2785 InsetCommandParams p;
2786 p.setFromString( argument );
2788 InsetCitation * inset = new InsetCitation( p );
2789 if (!bv_->insertInset(inset))
2792 bv_->updateInset( inset, true );
2796 case LFUN_INSERT_BIBTEX:
2798 // ale970405+lasgoutt970425
2799 // The argument can be up to two tokens separated
2800 // by a space. The first one is the bibstyle.
2801 string const db = token(argument, ' ', 0);
2802 string bibstyle = token(argument, ' ', 1);
2803 if (bibstyle.empty())
2806 InsetCommandParams p( "BibTeX", db, bibstyle );
2807 InsetBibtex * inset = new InsetBibtex(p);
2809 if (bv_->insertInset(inset)) {
2810 if (argument.empty())
2811 inset->Edit(bv_, 0, 0, 0);
2817 // BibTeX data bases
2818 case LFUN_BIBDB_ADD:
2820 InsetBibtex * inset =
2821 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2823 inset->addDatabase(argument);
2828 case LFUN_BIBDB_DEL:
2830 InsetBibtex * inset =
2831 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2833 inset->delDatabase(argument);
2838 case LFUN_BIBTEX_STYLE:
2840 InsetBibtex * inset =
2841 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2843 inset->setOptions(argument);
2848 case LFUN_INDEX_CREATE:
2850 InsetCommandParams p( "index" );
2852 if (argument.empty()) {
2853 // Get the word immediately preceding the cursor
2854 LyXParagraph::size_type curpos =
2855 TEXT(bv_)->cursor.pos() - 1;
2859 curstring = TEXT(bv_)
2860 ->cursor.par()->GetWord(curpos);
2862 p.setContents( curstring );
2864 p.setContents( argument );
2867 owner_->getDialogs()->createIndex( p.getAsString() );
2871 case LFUN_INDEX_INSERT:
2873 InsetCommandParams p;
2874 p.setFromString(argument);
2875 InsetIndex * inset = new InsetIndex(p);
2877 if (!bv_->insertInset(inset))
2880 bv_->updateInset(inset, true);
2884 case LFUN_INDEX_INSERT_LAST:
2886 // Get word immediately preceding the cursor
2887 LyXParagraph::size_type curpos =
2888 TEXT(bv_)->cursor.pos() - 1;
2889 // Can't do that at the beginning of a paragraph
2890 if (curpos < 0) break;
2892 string const curstring(TEXT(bv_)
2893 ->cursor.par()->GetWord(curpos));
2895 InsetCommandParams p("index", curstring);
2896 InsetIndex * inset = new InsetIndex(p);
2898 if (!bv_->insertInset(inset))
2901 bv_->updateInset(inset, true);
2905 case LFUN_INDEX_PRINT:
2907 InsetCommandParams p("printindex");
2908 Inset * inset = new InsetPrintIndex(p);
2909 if (!bv_->insertInset(inset, "Standard", true))
2914 case LFUN_PARENTINSERT:
2916 lyxerr << "arg " << argument << endl;
2917 InsetCommandParams p( "lyxparent", argument );
2918 Inset * inset = new InsetParent(p, *buffer_);
2919 if (!bv_->insertInset(inset, "Standard", true))
2924 case LFUN_CHILD_INSERT:
2926 InsetInclude::InsetIncludeParams p;
2927 p.cparams.setFromString(argument);
2930 InsetInclude * inset = new InsetInclude(p);
2931 if (!bv_->insertInset(inset))
2934 bv_->updateInset(inset, true);
2935 bv_->owner()->getDialogs()->showInclude(inset);
2940 case LFUN_INSERT_NOTE:
2944 case LFUN_SELFINSERT:
2946 LyXFont const old_font(TEXT(bv_)->real_current_font);
2947 for (string::size_type i = 0; i < argument.length(); ++i) {
2948 TEXT(bv_)->InsertChar(bv_, argument[i]);
2949 // This needs to be in the loop, or else we
2950 // won't break lines correctly. (Asger)
2952 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2954 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2955 moveCursorUpdate(false);
2957 // real_current_font.number can change so we need to
2958 // update the minibuffer
2959 if (old_font != TEXT(bv_)->real_current_font)
2960 owner_->showState();
2964 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
2968 time_t now_time_t = time(NULL);
2969 now_tm = localtime(&now_time_t);
2970 setlocale(LC_TIME, "");
2972 if (!argument.empty())
2975 arg = lyxrc.date_insert_format;
2977 int const datetmp_len =
2978 ::strftime(datetmp, 32, arg.c_str(), now_tm);
2979 for (int i = 0; i < datetmp_len; i++) {
2980 TEXT(bv_)->InsertChar(bv_, datetmp[i]);
2982 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2985 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
2986 moveCursorUpdate(false);
2990 case LFUN_UNKNOWN_ACTION:
2993 owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
2997 if (buffer_->isReadonly()) {
2998 owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
3001 if (!argument.empty()) {
3002 /* Automatically delete the currently selected
3003 * text and replace it with what is being
3004 * typed in now. Depends on lyxrc settings
3005 * "auto_region_delete", which defaults to
3008 if (lyxrc.auto_region_delete) {
3009 if (TEXT(bv_)->selection){
3010 TEXT(bv_)->CutSelection(bv_, false);
3012 BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3016 beforeChange(TEXT(bv_));
3017 LyXFont const old_font(TEXT(bv_)->real_current_font);
3018 for (string::size_type i = 0;
3019 i < argument.length(); ++i) {
3020 if (greek_kb_flag) {
3021 if (!math_insert_greek(bv_,
3023 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3025 owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
3028 update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3030 TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
3031 moveCursorUpdate(false);
3033 // real_current_font.number can change so we need to
3034 // update the minibuffer
3035 if (old_font != TEXT(bv_)->real_current_font)
3036 owner_->showState();
3038 // if we don't have an argument there was something
3039 // strange going on so we just tell this to someone!
3040 owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));