12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
21 #include "bufferview_funcs.h"
22 #include "TextCache.h"
23 #include "bufferlist.h"
24 #include "lyx_gui_misc.h"
27 #include "support/LAssert.h"
28 #include "frontends/Dialogs.h"
29 #include "insets/insetbib.h"
30 #include "insets/insettext.h"
31 /// added for Dispatch functions
33 #include "frontends/FileDialog.h"
35 #include "FloatList.h"
36 #include "support/filetools.h"
37 #include "support/lyxfunctional.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetinfo.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 "insets/insetfloatlist.h"
59 #include "insets/insetspecialchar.h"
61 #include "ParagraphParameters.h"
62 #include "undo_funcs.h"
63 #include "mathed/formulabase.h"
65 extern LyXTextClass::size_type current_layout;
66 extern int greek_kb_flag;
77 /* the selection possible is needed, that only motion events are
78 * used, where the bottom press event was on the drawing area too */
79 bool selection_possible = false;
81 extern BufferList bufferlist;
82 extern char ascii_type;
84 extern bool math_insert_greek(BufferView *, char);
85 extern void sigchldchecker(pid_t pid, int * status);
86 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
91 const unsigned int saved_positions_num = 20;
96 XSync(fl_get_display(), 0);
100 void SetXtermCursor(Window win)
102 static Cursor cursor;
103 static bool cursor_undefined = true;
104 if (cursor_undefined){
105 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
106 XFlush(fl_get_display());
107 cursor_undefined = false;
109 XDefineCursor(fl_get_display(), win, cursor);
110 XFlush(fl_get_display());
116 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
117 int xpos, int ypos, int width, int height)
118 : bv_(b), owner_(o), buffer_(0),
119 current_scrollbar_value(0), cursor_timeout(400),
120 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
124 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
125 workarea_.workAreaExpose
126 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
127 workarea_.workAreaEnter
128 .connect(slot(this, &BufferView::Pimpl::enterView));
129 workarea_.workAreaLeave
130 .connect(slot(this, &BufferView::Pimpl::leaveView));
131 workarea_.workAreaButtonPress
132 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
133 workarea_.workAreaButtonRelease
135 &BufferView::Pimpl::workAreaButtonRelease));
136 workarea_.workAreaMotionNotify
137 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
138 workarea_.workAreaDoubleClick
139 .connect(slot(this, &BufferView::Pimpl::doubleClick));
140 workarea_.workAreaTripleClick
141 .connect(slot(this, &BufferView::Pimpl::tripleClick));
142 workarea_.workAreaKeyPress
143 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
145 cursor_timeout.timeout.connect(slot(this,
146 &BufferView::Pimpl::cursorToggle));
147 cursor_timeout.start();
148 workarea_.setFocus();
149 saved_positions.resize(saved_positions_num);
153 Painter & BufferView::Pimpl::painter()
155 return workarea_.getPainter();
159 void BufferView::Pimpl::buffer(Buffer * b)
161 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
165 buffer_->delUser(bv_);
167 // Put the old text into the TextCache, but
168 // only if the buffer is still loaded.
169 // Also set the owner of the test to 0
170 // bv_->text->owner(0);
171 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
172 if (lyxerr.debugging())
173 textcache.show(lyxerr, "BufferView::buffer");
178 // Set current buffer
181 if (bufferlist.getState() == BufferList::CLOSING) return;
184 // screen is always deleted when the buffer is changed.
187 // If we are closing the buffer, use the first buffer as current
189 buffer_ = bufferlist.first();
193 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
194 buffer_->addUser(bv_);
195 // If we don't have a text object for this, we make one
196 if (bv_->text == 0) {
197 resizeCurrentBuffer();
202 bv_->text->first = screen_->topCursorVisible(bv_->text);
203 owner_->updateMenubar();
204 owner_->updateToolbar();
205 // Similarly, buffer-dependent dialogs should be updated or
206 // hidden. This should go here because some dialogs (eg ToC)
207 // require bv_->text.
208 owner_->getDialogs()->updateBufferDependent(true);
212 lyxerr[Debug::INFO] << " No Buffer!" << endl;
213 owner_->updateMenubar();
214 owner_->updateToolbar();
215 owner_->getDialogs()->hideBufferDependent();
219 // Also remove all remaining text's from the testcache.
220 // (there should not be any!) (if there is any it is a
222 if (lyxerr.debugging())
223 textcache.show(lyxerr, "buffer delete all");
226 // should update layoutchoice even if we don't have a buffer.
227 owner_->updateLayoutChoice();
229 owner_->updateWindowTitle();
233 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
235 workarea_.resize(xpos, ypos, width, height);
236 update(bv_->text, SELECT);
241 void BufferView::Pimpl::resize()
244 resizeCurrentBuffer();
248 void BufferView::Pimpl::redraw()
250 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
255 bool BufferView::Pimpl::fitCursor(LyXText * text)
257 lyx::Assert(screen_.get());
259 bv_->owner()->getDialogs()->updateParagraph();
261 bool const ret = screen_->fitCursor(text, bv_);
268 void BufferView::Pimpl::redoCurrentBuffer()
270 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
271 if (buffer_ && bv_->text) {
273 owner_->updateLayoutChoice();
278 int BufferView::Pimpl::resizeCurrentBuffer()
280 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
283 Paragraph * selstartpar = 0;
284 Paragraph * selendpar = 0;
285 UpdatableInset * the_locking_inset = 0;
287 Paragraph::size_type pos = 0;
288 Paragraph::size_type selstartpos = 0;
289 Paragraph::size_type selendpos = 0;
290 bool selection = false;
291 bool mark_set = false;
293 owner_->prohibitInput();
295 owner_->message(_("Formatting document..."));
298 par = bv_->text->cursor.par();
299 pos = bv_->text->cursor.pos();
300 selstartpar = bv_->text->selection.start.par();
301 selstartpos = bv_->text->selection.start.pos();
302 selendpar = bv_->text->selection.end.par();
303 selendpos = bv_->text->selection.end.pos();
304 selection = bv_->text->selection.set();
305 mark_set = bv_->text->selection.mark();
306 the_locking_inset = bv_->theLockingInset();
308 bv_->text = new LyXText(bv_);
309 bv_->text->init(bv_);
311 // See if we have a text in TextCache that fits
312 // the new buffer_ with the correct width.
313 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
315 if (lyxerr.debugging()) {
316 lyxerr << "Found a LyXText that fits:\n";
317 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
319 // Set the owner of the newly found text
320 // bv_->text->owner(bv_);
321 if (lyxerr.debugging())
322 textcache.show(lyxerr, "resizeCurrentBuffer");
324 bv_->text = new LyXText(bv_);
325 bv_->text->init(bv_);
331 bv_->text->selection.set(true);
332 /* at this point just to avoid the Delete-Empty-Paragraph
333 * Mechanism when setting the cursor */
334 bv_->text->selection.mark(mark_set);
336 bv_->text->setCursor(bv_, selstartpar, selstartpos);
337 bv_->text->selection.cursor = bv_->text->cursor;
338 bv_->text->setCursor(bv_, selendpar, selendpos);
339 bv_->text->setSelection(bv_);
340 bv_->text->setCursor(bv_, par, pos);
342 bv_->text->setCursor(bv_, par, pos);
343 bv_->text->selection.cursor = bv_->text->cursor;
344 bv_->text->selection.set(false);
346 // remake the inset locking
347 bv_->theLockingInset(the_locking_inset);
349 bv_->text->first = screen_->topCursorVisible(bv_->text);
350 buffer_->resizeInsets(bv_);
351 // this will scroll the screen such that the cursor becomes visible
356 owner_->allowInput();
358 /// clear the "Formatting Document" message
361 /// get rid of the splash screen if it's not gone already
362 owner_->getDialogs()->destroySplash();
368 void BufferView::Pimpl::updateScreen()
370 // Regenerate the screen.
371 screen_.reset(new LyXScreen(workarea_));
375 void BufferView::Pimpl::updateScrollbar()
377 /* If the text is smaller than the working area, the scrollbar
378 * maximum must be the working area height. No scrolling will
381 workarea_.setScrollbar(0, 1.0);
385 long const text_height = bv_->text->height;
387 double const lineh = bv_->text->defaultHeight();
388 double const slider_size =
389 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
391 static long old_text_height = 0;
392 static double old_lineh = 0;
393 static double old_slider_size = 0;
395 if (text_height != old_text_height) {
396 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
397 old_text_height = text_height;
399 if (lineh != old_lineh) {
400 workarea_.setScrollbarIncrements(lineh);
403 if (current_scrollbar_value != bv_->text->first
404 || slider_size != old_slider_size) {
405 current_scrollbar_value = bv_->text->first;
406 workarea_.setScrollbar(current_scrollbar_value, slider_size);
407 old_slider_size = slider_size;
412 // Callback for scrollbar slider
413 void BufferView::Pimpl::scrollCB(double value)
415 if (!buffer_) return;
417 current_scrollbar_value = long(value);
418 if (current_scrollbar_value < 0)
419 current_scrollbar_value = 0;
424 screen_->draw(bv_->text, bv_, current_scrollbar_value);
426 if (!lyxrc.cursor_follows_scrollbar) {
431 LyXText * vbt = bv_->text;
433 int const height = vbt->defaultHeight();
434 int const first = static_cast<int>((bv_->text->first + height));
435 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
437 if (vbt->cursor.y() < first)
438 vbt->setCursorFromCoordinates(bv_, 0, first);
439 else if (vbt->cursor.y() > last)
440 vbt->setCursorFromCoordinates(bv_, 0, last);
446 int BufferView::Pimpl::scrollUp(long time)
448 if (!buffer_) return 0;
449 if (!screen_.get()) return 0;
451 double value = workarea_.getScrollbarValue();
453 if (value == 0) return 0;
455 float add_value = (bv_->text->defaultHeight()
456 + float(time) * float(time) * 0.125);
458 if (add_value > workarea_.height())
459 add_value = float(workarea_.height() -
460 bv_->text->defaultHeight());
467 workarea_.setScrollbarValue(value);
474 int BufferView::Pimpl::scrollDown(long time)
476 if (!buffer_) return 0;
477 if (!screen_.get()) return 0;
479 double value = workarea_.getScrollbarValue();
480 pair<float, float> p = workarea_.getScrollbarBounds();
481 double const max = p.second;
483 if (value == max) return 0;
485 float add_value = (bv_->text->defaultHeight()
486 + float(time) * float(time) * 0.125);
488 if (add_value > workarea_.height())
489 add_value = float(workarea_.height() -
490 bv_->text->defaultHeight());
497 workarea_.setScrollbarValue(value);
504 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
506 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
510 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
512 // Only use motion with button 1
513 if (!(state & Button1MotionMask))
516 if (!buffer_ || !screen_.get()) return;
518 // Check for inset locking
519 if (bv_->theLockingInset()) {
520 LyXCursor cursor = bv_->text->cursor;
521 LyXFont font = bv_->text->getFont(buffer_,
522 cursor.par(), cursor.pos());
523 int width = bv_->theLockingInset()->width(bv_, font);
524 int inset_x = font.isVisibleRightToLeft()
525 ? cursor.x() - width : cursor.x();
526 int start_x = inset_x + bv_->theLockingInset()->scroll();
527 bv_->theLockingInset()->
528 insetMotionNotify(bv_,
530 y - cursor.y() + bv_->text->first,
535 /* The test for not selection possible is needed, that only motion
536 events are used, where the bottom press event was on
537 the drawing area too */
538 if (!selection_possible)
541 screen_->hideCursor();
543 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
545 if (!bv_->text->selection.set())
546 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
548 bv_->text->setSelection(bv_);
549 screen_->toggleToggle(bv_->text, bv_);
550 fitCursor(bv_->text);
551 screen_->showCursor(bv_->text, bv_);
555 // Single-click on work area
556 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
559 if (!buffer_ || !screen_.get()) return;
561 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
563 // ok ok, this is a hack.
564 if (button == 4 || button == 5) {
567 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
570 scrollDown(lyxrc.wheel_jump);
575 if (bv_->theLockingInset()) {
576 // We are in inset locking mode
578 /* Check whether the inset was hit. If not reset mode,
579 otherwise give the event to the inset */
580 if (inset_hit == bv_->theLockingInset()) {
581 bv_->theLockingInset()->
582 insetButtonPress(bv_,
587 bv_->unlockInset(bv_->theLockingInset());
592 selection_possible = true;
593 screen_->hideCursor();
595 int const screen_first = bv_->text->first;
597 // Middle button press pastes if we have a selection
598 bool paste_internally = false;
600 && bv_->text->selection.set()) {
601 owner_->getLyXFunc()->dispatch(LFUN_COPY);
602 paste_internally = true;
605 // Clear the selection
606 screen_->toggleSelection(bv_->text, bv_);
607 bv_->text->clearSelection(bv_);
608 bv_->text->fullRebreak(bv_);
609 screen_->update(bv_->text, bv_);
612 // Single left click in math inset?
613 if ((inset_hit != 0) &&
614 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
615 // Highly editable inset, like math
616 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
617 selection_possible = false;
618 owner_->updateLayoutChoice();
619 owner_->message(inset->editMessage());
620 inset->insetButtonPress(bv_, xpos, ypos, button);
621 inset->edit(bv_, xpos, ypos, button);
625 // Right click on a footnote flag opens float menu
627 selection_possible = false;
631 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
632 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
634 bv_->text->selection.cursor = bv_->text->cursor;
635 bv_->text->cursor.x_fix(bv_->text->cursor.x());
637 owner_->updateLayoutChoice();
638 if (fitCursor(bv_->text)) {
639 selection_possible = false;
642 // Insert primary selection with middle mouse
643 // if there is a local selection in the current buffer,
646 if (paste_internally)
647 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
649 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
651 selection_possible = false;
657 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
663 LyXText * text = bv_->getLyXText();
665 if (text->bv_owner && bv_->theLockingInset())
668 if (screen_.get() && button == 1) {
669 if (text->bv_owner) {
670 screen_->hideCursor();
671 screen_->toggleSelection(text, bv_);
672 text->selectWord(bv_);
673 screen_->toggleSelection(text, bv_, false);
675 text->selectWord(bv_);
677 /* This will fit the cursor on the screen
679 update(text, BufferView::SELECT|BufferView::FITCUR);
684 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
690 LyXText * text = bv_->getLyXText();
692 if (text->bv_owner && bv_->theLockingInset())
695 if (screen_.get() && (button == 1)) {
696 screen_->hideCursor();
697 screen_->toggleSelection(text, bv_);
698 text->cursorHome(bv_);
699 text->selection.cursor = text->cursor;
700 text->cursorEnd(bv_);
701 text->setSelection(bv_);
702 screen_->toggleSelection(text, bv_, false);
703 /* This will fit the cursor on the screen
705 update(text, BufferView::SELECT|BufferView::FITCUR);
710 void BufferView::Pimpl::enterView()
712 if (active() && available()) {
713 SetXtermCursor(workarea_.getWin());
714 using_xterm_cursor = true;
719 void BufferView::Pimpl::leaveView()
721 if (using_xterm_cursor) {
722 XUndefineCursor(fl_get_display(), workarea_.getWin());
723 using_xterm_cursor = false;
728 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
731 if (!buffer_ || !screen_.get()) return;
733 // If we hit an inset, we have the inset coordinates in these
734 // and inset_hit points to the inset. If we do not hit an
735 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
736 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
738 if (bv_->theLockingInset()) {
739 // We are in inset locking mode.
741 /* LyX does a kind of work-area grabbing for insets.
742 Only a ButtonPress Event outside the inset will
743 force a insetUnlock. */
744 bv_->theLockingInset()->
745 insetButtonRelease(bv_, x, y, button);
749 selection_possible = false;
757 // Did we hit an editable inset?
759 // Inset like error, notes and figures
760 selection_possible = false;
762 // CHECK fix this proper in 0.13
764 // Following a ref shouldn't issue
765 // a push on the undo-stack
766 // anylonger, now that we have
767 // keybindings for following
768 // references and returning from
769 // references. IMHO though, it
770 // should be the inset's own business
771 // to push or not push on the undo
772 // stack. They don't *have* to
773 // alter the document...
775 // ...or maybe the SetCursorParUndo()
776 // below isn't necessary at all anylonger?
777 if (inset_hit->lyxCode() == Inset::REF_CODE) {
778 setCursorParUndo(bv_);
781 owner_->message(inset_hit->editMessage());
783 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
784 // Highly editable inset, like math
785 UpdatableInset *inset = (UpdatableInset *)inset_hit;
786 inset->insetButtonRelease(bv_, x, y, button);
788 inset_hit->insetButtonRelease(bv_, x, y, button);
789 inset_hit->edit(bv_, x, y, button);
794 // check whether we want to open a float
798 if (bv_->text->cursor.pos() <
799 bv_->text->cursor.par()->size()) {
800 c = bv_->text->cursor.par()->
801 getChar(bv_->text->cursor.pos());
803 if (bv_->text->cursor.pos() - 1 >= 0) {
804 c = bv_->text->cursor.par()->
805 getChar(bv_->text->cursor.pos() - 1);
808 selection_possible = false;
813 // Maybe we want to edit a bibitem ale970302
814 if (bv_->text->cursor.par()->bibkey && x < 20 +
815 bibitemMaxWidth(bv_, textclasslist.
817 params.textclass).defaultfont())) {
818 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
826 * Returns an inset if inset was hit. 0 otherwise.
827 * If hit, the coordinates are changed relative to the inset.
828 * Otherwise coordinates are not changed, and false is returned.
830 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
831 unsigned int /* button */)
836 int y_tmp = y + text->first;
839 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
840 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
843 if (cursor.pos() < cursor.par()->size()
844 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
845 && cursor.par()->getInset(cursor.pos())
846 && cursor.par()->getInset(cursor.pos())->editable()) {
848 // Check whether the inset really was hit
849 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
850 LyXFont font = text->getFont(buffer_,
851 cursor.par(), cursor.pos());
852 int const width = tmpinset->width(bv_, font);
853 int const inset_x = font.isVisibleRightToLeft()
854 ? cursor.x() - width : cursor.x();
855 int const start_x = inset_x + tmpinset->scroll();
856 int const end_x = inset_x + width;
858 if (x > start_x && x < end_x
859 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
860 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
861 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
863 // The origin of an inset is on the baseline
864 y = y_tmp - (text->cursor.y());
869 if ((cursor.pos() - 1 >= 0) &&
870 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
871 (cursor.par()->getInset(cursor.pos() - 1)) &&
872 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
873 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
874 LyXFont font = text->getFont(buffer_, cursor.par(),
876 int const width = tmpinset->width(bv_, font);
877 int const inset_x = font.isVisibleRightToLeft()
878 ? cursor.x() : cursor.x() - width;
879 int const start_x = inset_x + tmpinset->scroll();
880 int const end_x = inset_x + width;
882 if (x > start_x && x < end_x
883 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
884 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
886 if (move_cursor && (tmpinset != bv_->theLockingInset()))
888 text->setCursor(bv_, cursor.par(),
889 cursor.pos() - 1, true);
891 // The origin of an inset is on the baseline
892 y = y_tmp - (text->cursor.y());
900 void BufferView::Pimpl::workAreaExpose()
902 static int work_area_width;
903 static unsigned int work_area_height;
905 bool const widthChange = workarea_.workWidth() != work_area_width;
906 bool const heightChange = workarea_.height() != work_area_height;
908 // update from work area
909 work_area_width = workarea_.workWidth();
910 work_area_height = workarea_.height();
913 // The visible LyXView need a resize
916 // Remove all texts from the textcache
917 // This is not _really_ what we want to do. What
918 // we really want to do is to delete in textcache
919 // that does not have a BufferView with matching
920 // width, but as long as we have only one BufferView
921 // deleting all gives the same result.
922 if (lyxerr.debugging())
923 textcache.show(lyxerr, "Expose delete all");
925 } else if (heightChange) {
926 // Rebuild image of current screen
928 // fitCursor() ensures we don't jump back
929 // to the start of the document on vertical
931 fitCursor(bv_->text);
933 // The main window size has changed, repaint most stuff
935 } else if (screen_.get())
936 screen_->redraw(bv_->text, bv_);
938 // Grey box when we don't have a buffer
942 // always make sure that the scrollbar is sane.
944 owner_->updateLayoutChoice();
949 void BufferView::Pimpl::update()
952 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
954 screen_->update(bv_->text, bv_);
958 // Values used when calling update:
960 // -2 - update, move sel_cursor if selection, fitcursor
961 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
962 // 0 - update, move sel_cursor if selection, fitcursor
963 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
964 // 3 - update, move sel_cursor if selection
967 // a simple redraw of the parts that need refresh
969 // move sel_cursor if selection -
970 // the text's sel_cursor is moved if there is selection is progress
973 // fitCursor() is called and the scrollbar updated
976 // the buffer is marked dirty.
985 // UPDATE_ONLY = UPDATE;
986 // UPDATE_SELECT = UPDATE | SELECT;
987 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
988 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
990 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
991 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
992 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
993 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
994 // update(3) -> update(1) -> update(1) -> update(SELECT)
996 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
998 owner_->updateLayoutChoice();
1000 if (!text->selection.set() && (f & SELECT)) {
1001 text->selection.cursor = text->cursor;
1004 text->fullRebreak(bv_);
1006 if (text->inset_owner) {
1007 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1008 updateInset(text->inset_owner, true);
1017 buffer_->markDirty();
1022 // Callback for cursor timer
1023 void BufferView::Pimpl::cursorToggle()
1025 // Quite a nice place for asyncron Inset updating, isn't it?
1026 // Actually no! This is run even if no buffer exist... so (Lgb)
1028 cursor_timeout.restart();
1033 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1034 if (pid == -1) // error find out what is wrong
1035 ; // ignore it for now.
1037 sigchldchecker(pid, &status);
1039 updatelist.update(bv_);
1041 if (!screen_.get()) {
1042 cursor_timeout.restart();
1046 if (!bv_->theLockingInset()) {
1047 screen_->cursorToggle(bv_->text, bv_);
1049 bv_->theLockingInset()->toggleInsetCursor(bv_);
1052 cursor_timeout.restart();
1056 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1058 if (!text->cursor.row()->previous())
1061 int y = text->first;
1062 if (text->inset_owner)
1063 y += bv_->text->first;
1064 Row * cursorrow = text->cursor.row();
1065 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1067 // This is to allow jumping over large insets
1068 if ((cursorrow == text->cursor.row()))
1069 text->cursorUp(bv_);
1071 if (text->inset_owner ||
1072 text->cursor.row()->height() < workarea_.height())
1073 screen_->draw(bv_->text, bv_,
1075 - text->cursor.row()->baseline()
1076 + text->cursor.row()->height()
1077 - workarea_.height() + 1 );
1082 void BufferView::Pimpl::cursorNext(LyXText * text)
1084 if (!text->cursor.row()->next())
1087 int y = text->first + workarea_.height();
1088 // if (text->inset_owner)
1089 // y += bv_->text->first;
1090 text->getRowNearY(y);
1092 Row * cursorrow = text->cursor.row();
1093 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1095 // This is to allow jumping over large insets
1096 if ((cursorrow == bv_->text->cursor.row()))
1097 text->cursorDown(bv_);
1099 if (text->inset_owner ||
1100 text->cursor.row()->height() < workarea_.height())
1101 screen_->draw(bv_->text, bv_, text->cursor.y() -
1102 text->cursor.row()->baseline());
1107 bool BufferView::Pimpl::available() const
1109 if (buffer_ && bv_->text) return true;
1114 void BufferView::Pimpl::beforeChange(LyXText * text)
1117 text->clearSelection(bv_);
1121 void BufferView::Pimpl::savePosition(unsigned int i)
1123 if (i >= saved_positions_num)
1125 saved_positions[i] = Position(buffer_->fileName(),
1126 bv_->text->cursor.par()->id(),
1127 bv_->text->cursor.pos());
1130 str << _("Saved bookmark") << ' ' << i;
1131 owner_->message(str.str().c_str());
1136 void BufferView::Pimpl::restorePosition(unsigned int i)
1138 if (i >= saved_positions_num)
1141 string const fname = saved_positions[i].filename;
1143 beforeChange(bv_->text);
1145 if (fname != buffer_->fileName()) {
1146 Buffer * b = bufferlist.exists(fname) ?
1147 bufferlist.getBuffer(fname) :
1148 bufferlist.loadLyXFile(fname); // don't ask, just load it
1149 if (b != 0 ) buffer(b);
1152 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1156 bv_->text->setCursor(bv_, par,
1157 min(par->size(), saved_positions[i].par_pos));
1159 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1162 str << _("Moved to bookmark") << ' ' << i;
1163 owner_->message(str.str().c_str());
1168 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1170 if (i >= saved_positions_num)
1173 return !saved_positions[i].filename.empty();
1177 void BufferView::Pimpl::setState()
1179 if (!lyxrc.rtl_support)
1182 LyXText * text = bv_->getLyXText();
1183 if (text->real_current_font.isRightToLeft()
1186 text->real_current_font.latex() != LyXFont::ON
1189 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1190 owner_->getIntl()->KeyMapSec();
1192 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1193 owner_->getIntl()->KeyMapPrim();
1198 void BufferView::Pimpl::insetSleep()
1200 if (bv_->theLockingInset() && !inset_slept) {
1201 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1202 bv_->theLockingInset()->insetUnlock(bv_);
1208 void BufferView::Pimpl::insetWakeup()
1210 if (bv_->theLockingInset() && inset_slept) {
1211 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1212 inset_slept = false;
1217 void BufferView::Pimpl::insetUnlock()
1219 if (bv_->theLockingInset()) {
1221 bv_->theLockingInset()->insetUnlock(bv_);
1222 bv_->theLockingInset(0);
1224 inset_slept = false;
1229 bool BufferView::Pimpl::focus() const
1231 return workarea_.hasFocus();
1235 void BufferView::Pimpl::focus(bool f)
1237 if (f) workarea_.setFocus();
1241 bool BufferView::Pimpl::active() const
1243 return workarea_.active();
1247 bool BufferView::Pimpl::belowMouse() const
1249 return workarea_.belowMouse();
1253 void BufferView::Pimpl::showCursor()
1256 screen_->showCursor(bv_->text, bv_);
1260 void BufferView::Pimpl::hideCursor()
1263 screen_->hideCursor();
1267 void BufferView::Pimpl::toggleSelection(bool b)
1269 if (screen_.get()) {
1270 if (bv_->theLockingInset())
1271 bv_->theLockingInset()->toggleSelection(bv_, b);
1272 screen_->toggleSelection(bv_->text, bv_, b);
1277 void BufferView::Pimpl::toggleToggle()
1280 screen_->toggleToggle(bv_->text, bv_);
1284 void BufferView::Pimpl::center()
1286 beforeChange(bv_->text);
1287 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1288 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1290 screen_->draw(bv_->text, bv_, 0);
1292 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1297 void BufferView::Pimpl::pasteClipboard(bool asPara)
1299 if (!buffer_) return;
1301 screen_->hideCursor();
1302 beforeChange(bv_->text);
1304 string const clip(workarea_.getClipboard());
1306 if (clip.empty()) return;
1309 bv_->text->insertStringAsParagraphs(bv_, clip);
1311 bv_->text->insertStringAsLines(bv_, clip);
1313 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1317 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1319 workarea_.putClipboard(stuff);
1324 * Dispatch functions for actions which can be valid for BufferView->text
1325 * and/or InsetText->text!!!
1330 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1332 LyXText * lt = bv_->getLyXText();
1334 if (selecting || lt->selection.mark()) {
1335 lt->setSelection(bv_);
1339 update(lt, BufferView::SELECT|BufferView::FITCUR);
1342 /* ---> Everytime the cursor is moved, show the current font state. */
1343 // should this too me moved out of this func?
1344 //owner->showState();
1349 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1351 LyXCursor cursor = bv_->getLyXText()->cursor;
1352 Buffer::inset_iterator it =
1353 find_if(Buffer::inset_iterator(
1354 cursor.par(), cursor.pos()),
1355 buffer_->inset_iterator_end(),
1356 lyx::compare_memfun(&Inset::lyxCode, code));
1357 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1361 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1363 string filename = filen;
1365 if (filename.empty()) {
1366 // Launch a file browser
1367 string initpath = lyxrc.document_path;
1370 string const trypath = owner_->buffer()->filepath;
1371 // If directory is writeable, use this as default.
1372 if (IsDirWriteable(trypath) == 1)
1376 FileDialog fileDlg(bv_->owner(),
1377 _("Select LyX document to insert"),
1379 make_pair(string(_("Documents")),
1380 string(lyxrc.document_path)),
1381 make_pair(string(_("Examples")),
1382 string(AddPath(system_lyxdir, "examples"))));
1384 FileDialog::Result result =
1385 fileDlg.Select(initpath,
1386 _("*.lyx| LyX Documents (*.lyx)"));
1388 if (result.first == FileDialog::Later)
1391 filename = result.second;
1393 // check selected filename
1394 if (filename.empty()) {
1395 owner_->message(_("Canceled."));
1400 // get absolute path of file and add ".lyx" to the filename if
1402 filename = FileSearch(string(), filename, "lyx");
1404 string const disp_fn(MakeDisplayPath(filename));
1407 s1 << _("Inserting document") << ' '
1408 << disp_fn << " ...";
1409 owner_->message(s1.str().c_str());
1410 bool const res = bv_->insertLyXFile(filename);
1413 str << _("Document") << ' ' << disp_fn
1414 << ' ' << _("inserted.");
1415 owner_->message(str.str().c_str());
1418 str << _("Could not insert document") << ' '
1420 owner_->message(str.str().c_str());
1425 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1427 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1428 << action <<"] arg[" << argument << "]" << endl;
1431 // --- Misc -------------------------------------------
1435 LyXText * lt = bv_->getLyXText();
1436 lt->toggleAppendix(bv_);
1439 | BufferView::FITCUR
1440 | BufferView::CHANGE);
1445 case LFUN_TOC_INSERT:
1447 InsetCommandParams p;
1448 p.setCmdName("tableofcontents");
1449 Inset * inset = new InsetTOC(p);
1450 if (!insertInset(inset, "Standard"))
1455 case LFUN_TABULAR_FEATURE:
1456 case LFUN_SCROLL_INSET:
1457 // this is not handled here as this funktion is only aktive
1458 // if we have a locking_inset and that one is (or contains)
1462 case LFUN_INSET_GRAPHICS:
1464 Inset * new_inset = new InsetGraphics;
1465 if (!insertInset(new_inset)) {
1468 // this is need because you don't use a inset->Edit()
1469 updateInset(new_inset, true);
1470 new_inset->edit(bv_, 0, 0, 0);
1480 case LFUN_PASTESELECTION:
1482 bool asPara = false;
1483 if (argument == "paragraph") asPara = true;
1484 pasteClipboard(asPara);
1496 case LFUN_LAYOUT_COPY:
1497 bv_->copyEnvironment();
1500 case LFUN_LAYOUT_PASTE:
1501 bv_->pasteEnvironment();
1505 case LFUN_GOTOERROR:
1506 gotoInset(Inset::ERROR_CODE, false);
1510 gotoInset(Inset::IGNORE_CODE, false);
1513 case LFUN_REFERENCE_GOTO:
1515 vector<Inset::Code> tmp;
1516 tmp.push_back(Inset::LABEL_CODE);
1517 tmp.push_back(Inset::REF_CODE);
1518 gotoInset(tmp, true);
1522 case LFUN_HYPHENATION:
1530 case LFUN_END_OF_SENTENCE:
1534 case LFUN_MENU_SEPARATOR:
1543 changeDepth(bv_, bv_->getLyXText(), 0);
1546 case LFUN_DEPTH_MIN:
1547 changeDepth(bv_, bv_->getLyXText(), -1);
1550 case LFUN_DEPTH_PLUS:
1551 changeDepth(bv_, bv_->getLyXText(), 1);
1555 owner_->getDialogs()->setUserFreeFont();
1562 owner_->showState();
1566 case LFUN_FILE_INSERT:
1568 MenuInsertLyXFile(argument);
1572 case LFUN_FILE_INSERT_ASCII_PARA:
1573 InsertAsciiFile(bv_, argument, true);
1576 case LFUN_FILE_INSERT_ASCII:
1577 InsertAsciiFile(bv_, argument, false);
1582 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1583 << argument << endl;
1585 // Derive layout number from given argument (string)
1586 // and current buffer's textclass (number). */
1587 LyXTextClassList::ClassList::size_type tclass =
1588 buffer_->params.textclass;
1589 pair <bool, LyXTextClass::size_type> layout =
1590 textclasslist.NumberOfLayout(tclass, argument);
1592 // If the entry is obsolete, use the new one instead.
1594 string obs = textclasslist.Style(tclass,layout.second)
1598 textclasslist.NumberOfLayout(tclass, obs);
1601 // see if we found the layout number:
1602 if (!layout.first) {
1603 owner_->getLyXFunc()->setErrorMessage(
1604 string(N_("Layout ")) + argument +
1609 if (current_layout != layout.second) {
1610 LyXText * lt = bv_->getLyXText();
1612 current_layout = layout.second;
1615 | BufferView::FITCUR);
1616 lt->setLayout(bv_, layout.second);
1617 owner_->setLayout(layout.second);
1620 | BufferView::FITCUR
1621 | BufferView::CHANGE);
1628 Lang(bv_, argument);
1630 owner_->showState();
1635 owner_->showState();
1640 owner_->showState();
1645 owner_->showState();
1650 owner_->showState();
1655 owner_->showState();
1660 owner_->showState();
1665 owner_->showState();
1668 case LFUN_UNDERLINE:
1670 owner_->showState();
1673 case LFUN_FONT_SIZE:
1674 FontSize(bv_, argument);
1675 owner_->showState();
1678 case LFUN_FONT_STATE:
1679 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1682 case LFUN_UPCASE_WORD:
1684 LyXText * lt = bv_->getLyXText();
1688 | BufferView::FITCUR);
1689 lt->changeCase(bv_, LyXText::text_uppercase);
1690 if (lt->inset_owner)
1691 updateInset(lt->inset_owner, true);
1694 | BufferView::FITCUR
1695 | BufferView::CHANGE);
1699 case LFUN_LOWCASE_WORD:
1701 LyXText * lt = bv_->getLyXText();
1703 update(lt, BufferView::SELECT|BufferView::FITCUR);
1704 lt->changeCase(bv_, LyXText::text_lowercase);
1705 if (lt->inset_owner)
1706 updateInset(lt->inset_owner, true);
1709 | BufferView::FITCUR
1710 | BufferView::CHANGE);
1714 case LFUN_CAPITALIZE_WORD:
1716 LyXText * lt = bv_->getLyXText();
1718 update(lt, BufferView::SELECT|BufferView::FITCUR);
1719 lt->changeCase(bv_, LyXText::text_capitalization);
1720 if (lt->inset_owner)
1721 updateInset(lt->inset_owner, true);
1724 | BufferView::FITCUR
1725 | BufferView::CHANGE);
1729 case LFUN_TRANSPOSE_CHARS:
1731 LyXText * lt = bv_->getLyXText();
1733 update(lt, BufferView::SELECT|BufferView::FITCUR);
1734 lt->transposeChars(*bv_);
1735 if (lt->inset_owner)
1736 updateInset(lt->inset_owner, true);
1739 | BufferView::FITCUR
1740 | BufferView::CHANGE);
1745 case LFUN_INSERT_LABEL:
1746 MenuInsertLabel(bv_, argument);
1749 case LFUN_REF_INSERT:
1750 if (argument.empty()) {
1751 InsetCommandParams p("ref");
1752 owner_->getDialogs()->createRef(p.getAsString());
1754 InsetCommandParams p;
1755 p.setFromString(argument);
1757 InsetRef * inset = new InsetRef(p, *buffer_);
1758 if (!insertInset(inset))
1761 updateInset(inset, true);
1765 case LFUN_BOOKMARK_SAVE:
1766 savePosition(strToUnsignedInt(argument));
1769 case LFUN_BOOKMARK_GOTO:
1770 restorePosition(strToUnsignedInt(argument));
1775 string label(argument);
1776 if (label.empty()) {
1778 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1780 label = inset->getContents();
1785 if (!label.empty()) {
1786 //bv_->savePosition(0);
1787 if (!bv_->gotoLabel(label))
1788 WriteAlert(_("Error"),
1789 _("Couldn't find this label"),
1790 _("in current document."));
1795 // --- Cursor Movements -----------------------------
1798 LyXText * lt = bv_->getLyXText();
1800 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1801 if (!lt->selection.mark())
1803 update(lt, BufferView::SELECT|BufferView::FITCUR);
1805 lt->cursorLeft(bv_, false);
1806 if (lt->cursor.pos() < lt->cursor.par()->size()
1807 && lt->cursor.par()->getChar(lt->cursor.pos())
1808 == Paragraph::META_INSET
1809 && lt->cursor.par()->getInset(lt->cursor.pos())
1810 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1811 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1812 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1815 LyXFont const font =
1816 lt->getFont(buffer_,
1819 y = tmpinset->descent(bv_,font);
1821 tmpinset->edit(bv_, 0, y, 0);
1825 lt->cursorRight(bv_, false);
1827 moveCursorUpdate(false);
1828 owner_->showState();
1834 // This is soooo ugly. Isn`t it possible to make
1835 // it simpler? (Lgb)
1836 LyXText * lt = bv_->getLyXText();
1837 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1838 if (!lt->selection.mark())
1840 update(lt, BufferView::SELECT|BufferView::FITCUR);
1841 LyXCursor const cur = lt->cursor;
1843 lt->cursorLeft(bv_, false);
1844 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1845 lt->cursor.pos() < lt->cursor.par()->size() &&
1846 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1847 Paragraph::META_INSET) &&
1848 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1849 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1850 == Inset::HIGHLY_EDITABLE))
1852 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1853 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1854 LyXFont const font = lt->getFont(buffer_,
1858 : tmpinset->descent(bv_,font);
1861 tmpinset->width(bv_,font),
1866 lt->cursorRight(bv_, false);
1869 moveCursorUpdate(false);
1870 owner_->showState();
1876 LyXText * lt = bv_->getLyXText();
1878 if (!lt->selection.mark())
1880 update(lt, BufferView::UPDATE);
1883 moveCursorUpdate(false);
1884 owner_->showState();
1890 LyXText * lt = bv_->getLyXText();
1892 if (!lt->selection.mark())
1894 update(lt, BufferView::UPDATE);
1895 lt->cursorDown(bv_);
1897 moveCursorUpdate(false);
1898 owner_->showState();
1902 case LFUN_UP_PARAGRAPH:
1904 LyXText * lt = bv_->getLyXText();
1906 if (!lt->selection.mark())
1908 update(lt, BufferView::UPDATE);
1909 lt->cursorUpParagraph(bv_);
1911 moveCursorUpdate(false);
1912 owner_->showState();
1916 case LFUN_DOWN_PARAGRAPH:
1918 LyXText * lt = bv_->getLyXText();
1920 if (!lt->selection.mark())
1922 update(lt, BufferView::UPDATE);
1923 lt->cursorDownParagraph(bv_);
1925 moveCursorUpdate(false);
1926 owner_->showState();
1932 LyXText * lt = bv_->getLyXText();
1934 if (!lt->selection.mark())
1936 update(lt, BufferView::UPDATE);
1939 moveCursorUpdate(false);
1940 owner_->showState();
1946 LyXText * lt = bv_->getLyXText();
1948 if (!lt->selection.mark())
1950 update(lt, BufferView::UPDATE);
1953 moveCursorUpdate(false);
1954 owner_->showState();
1960 LyXText * lt = bv_->getLyXText();
1962 if (!lt->selection.mark())
1964 update(lt, BufferView::SELECT|BufferView::FITCUR);
1965 lt->cursorHome(bv_);
1967 moveCursorUpdate(false);
1968 owner_->showState();
1974 LyXText * lt = bv_->getLyXText();
1976 if (!lt->selection.mark())
1979 BufferView::SELECT|BufferView::FITCUR);
1982 moveCursorUpdate(false);
1983 owner_->showState();
1987 case LFUN_SHIFT_TAB:
1990 LyXText * lt = bv_->getLyXText();
1992 if (!lt->selection.mark())
1995 BufferView::SELECT|BufferView::FITCUR);
1998 moveCursorUpdate(false);
1999 owner_->showState();
2003 case LFUN_WORDRIGHT:
2005 LyXText * lt = bv_->getLyXText();
2007 if (!lt->selection.mark())
2009 update(lt, BufferView::SELECT|BufferView::FITCUR);
2010 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2011 lt->cursorLeftOneWord(bv_);
2013 lt->cursorRightOneWord(bv_);
2015 moveCursorUpdate(false);
2016 owner_->showState();
2022 LyXText * lt = bv_->getLyXText();
2024 if (!lt->selection.mark())
2026 update(lt, BufferView::SELECT|BufferView::FITCUR);
2027 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2028 lt->cursorRightOneWord(bv_);
2030 lt->cursorLeftOneWord(bv_);
2032 moveCursorUpdate(false);
2033 owner_->showState();
2037 case LFUN_BEGINNINGBUF:
2039 LyXText * lt = bv_->getLyXText();
2041 if (!lt->selection.mark())
2044 BufferView::SELECT|BufferView::FITCUR);
2047 moveCursorUpdate(false);
2048 owner_->showState();
2054 LyXText * lt = bv_->getLyXText();
2056 if (!lt->selection.mark())
2059 BufferView::SELECT|BufferView::FITCUR);
2060 lt->cursorBottom(bv_);
2062 moveCursorUpdate(false);
2063 owner_->showState();
2067 /* cursor selection ---------------------------- */
2070 LyXText * lt = bv_->getLyXText();
2073 BufferView::SELECT|BufferView::FITCUR);
2074 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2075 lt->cursorLeft(bv_);
2077 lt->cursorRight(bv_);
2079 moveCursorUpdate(true);
2080 owner_->showState();
2086 LyXText * lt = bv_->getLyXText();
2089 BufferView::SELECT|BufferView::FITCUR);
2090 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2091 lt->cursorRight(bv_);
2093 lt->cursorLeft(bv_);
2095 moveCursorUpdate(true);
2096 owner_->showState();
2102 LyXText * lt = bv_->getLyXText();
2105 BufferView::SELECT|BufferView::FITCUR);
2108 moveCursorUpdate(true);
2109 owner_->showState();
2115 LyXText * lt = bv_->getLyXText();
2118 BufferView::SELECT|BufferView::FITCUR);
2119 lt->cursorDown(bv_);
2121 moveCursorUpdate(true);
2122 owner_->showState();
2126 case LFUN_UP_PARAGRAPHSEL:
2128 LyXText * lt = bv_->getLyXText();
2131 BufferView::SELECT|BufferView::FITCUR);
2132 lt->cursorUpParagraph(bv_);
2134 moveCursorUpdate(true);
2135 owner_->showState();
2139 case LFUN_DOWN_PARAGRAPHSEL:
2141 LyXText * lt = bv_->getLyXText();
2144 BufferView::SELECT|BufferView::FITCUR);
2145 lt->cursorDownParagraph(bv_);
2147 moveCursorUpdate(true);
2148 owner_->showState();
2154 LyXText * lt = bv_->getLyXText();
2156 update(lt, BufferView::SELECT|BufferView::FITCUR);
2159 moveCursorUpdate(true);
2160 owner_->showState();
2166 LyXText * lt = bv_->getLyXText();
2168 update(lt, BufferView::SELECT|BufferView::FITCUR);
2171 moveCursorUpdate(true);
2172 owner_->showState();
2178 LyXText * lt = bv_->getLyXText();
2180 update(lt, BufferView::SELECT|BufferView::FITCUR);
2181 lt->cursorHome(bv_);
2183 moveCursorUpdate(true);
2184 owner_->showState();
2190 LyXText * lt = bv_->getLyXText();
2192 update(lt, BufferView::SELECT|BufferView::FITCUR);
2195 moveCursorUpdate(true);
2196 owner_->showState();
2200 case LFUN_WORDRIGHTSEL:
2202 LyXText * lt = bv_->getLyXText();
2204 update(lt, BufferView::SELECT|BufferView::FITCUR);
2205 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2206 lt->cursorLeftOneWord(bv_);
2208 lt->cursorRightOneWord(bv_);
2210 moveCursorUpdate(true);
2211 owner_->showState();
2215 case LFUN_WORDLEFTSEL:
2217 LyXText * lt = bv_->getLyXText();
2219 update(lt, BufferView::SELECT|BufferView::FITCUR);
2220 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2221 lt->cursorRightOneWord(bv_);
2223 lt->cursorLeftOneWord(bv_);
2225 moveCursorUpdate(true);
2226 owner_->showState();
2230 case LFUN_BEGINNINGBUFSEL:
2232 LyXText * lt = bv_->getLyXText();
2234 if (lt->inset_owner)
2236 update(lt, BufferView::SELECT|BufferView::FITCUR);
2239 moveCursorUpdate(true);
2240 owner_->showState();
2244 case LFUN_ENDBUFSEL:
2246 LyXText * lt = bv_->getLyXText();
2248 if (lt->inset_owner)
2251 BufferView::SELECT|BufferView::FITCUR);
2252 lt->cursorBottom(bv_);
2254 moveCursorUpdate(true);
2255 owner_->showState();
2259 // --- text changing commands ------------------------
2260 case LFUN_BREAKLINE:
2262 LyXText * lt = bv_->getLyXText();
2265 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2268 | BufferView::FITCUR
2269 | BufferView::CHANGE);
2270 moveCursorUpdate(false);
2274 case LFUN_PROTECTEDSPACE:
2276 LyXText * lt = bv_->getLyXText();
2278 LyXLayout const & style = textclasslist
2279 .Style(buffer_->params.textclass,
2280 lt->cursor.par()->getLayout());
2282 if (style.free_spacing) {
2283 lt->insertChar(bv_, ' ');
2286 | BufferView::FITCUR
2287 | BufferView::CHANGE);
2291 moveCursorUpdate(false);
2297 LyXText * lt = bv_->getLyXText();
2299 if (lt->selection.mark()) {
2303 | BufferView::FITCUR);
2304 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2307 lt->selection.mark(true);
2310 | BufferView::FITCUR);
2311 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2313 lt->selection.cursor = lt->cursor;
2319 LyXText * lt = bv_->getLyXText();
2321 if (!lt->selection.set()) {
2323 lt->selection.cursor = lt->cursor;
2326 | BufferView::FITCUR
2327 | BufferView::CHANGE);
2328 // It is possible to make it a lot faster still
2329 // just comment out the line below...
2334 moveCursorUpdate(false);
2335 owner_->showState();
2340 case LFUN_DELETE_SKIP:
2342 LyXText * lt = bv_->getLyXText();
2344 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2346 LyXCursor cursor = lt->cursor;
2348 if (!lt->selection.set()) {
2349 if (cursor.pos() == cursor.par()->size()) {
2350 lt->cursorRight(bv_);
2351 cursor = lt->cursor;
2352 if (cursor.pos() == 0
2353 && !(cursor.par()->params().spaceTop()
2354 == VSpace (VSpace::NONE))) {
2357 cursor.par()->params().lineTop(),
2358 cursor.par()->params().lineBottom(),
2359 cursor.par()->params().pagebreakTop(),
2360 cursor.par()->params().pagebreakBottom(),
2361 VSpace(VSpace::NONE),
2362 cursor.par()->params().spaceBottom(),
2363 cursor.par()->params().align(),
2364 cursor.par()->params().labelWidthString(), 0);
2365 lt->cursorLeft(bv_);
2368 | BufferView::FITCUR
2369 | BufferView::CHANGE);
2371 lt->cursorLeft(bv_);
2373 lt->selection.cursor = lt->cursor;
2376 | BufferView::FITCUR
2377 | BufferView::CHANGE);
2381 lt->selection.cursor = lt->cursor;
2384 | BufferView::FITCUR
2385 | BufferView::CHANGE);
2393 /* -------> Delete word forward. */
2394 case LFUN_DELETE_WORD_FORWARD:
2395 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2396 bv_->getLyXText()->deleteWordForward(bv_);
2397 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2398 moveCursorUpdate(false);
2399 owner_->showState();
2402 /* -------> Delete word backward. */
2403 case LFUN_DELETE_WORD_BACKWARD:
2405 LyXText * lt = bv_->getLyXText();
2407 update(lt, BufferView::SELECT|BufferView::FITCUR);
2408 lt->deleteWordBackward(bv_);
2411 | BufferView::FITCUR
2412 | BufferView::CHANGE);
2413 moveCursorUpdate(false);
2414 owner_->showState();
2418 /* -------> Kill to end of line. */
2419 case LFUN_DELETE_LINE_FORWARD:
2421 LyXText * lt = bv_->getLyXText();
2423 update(lt, BufferView::SELECT|BufferView::FITCUR);
2424 lt->deleteLineForward(bv_);
2427 | BufferView::FITCUR
2428 | BufferView::CHANGE);
2429 moveCursorUpdate(false);
2433 /* -------> Set mark off. */
2436 LyXText * lt = bv_->getLyXText();
2439 update(lt, BufferView::SELECT|BufferView::FITCUR);
2440 lt->selection.cursor = lt->cursor;
2441 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2445 /* -------> Set mark on. */
2448 LyXText * lt = bv_->getLyXText();
2451 lt->selection.mark(true);
2452 update(lt, BufferView::SELECT|BufferView::FITCUR);
2453 lt->selection.cursor = lt->cursor;
2454 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2458 case LFUN_BACKSPACE:
2460 LyXText * lt = bv_->getLyXText();
2462 if (!lt->selection.set()) {
2463 if (owner_->getIntl()->getTrans().backspace()) {
2465 lt->selection.cursor = lt->cursor;
2468 | BufferView::FITCUR
2469 | BufferView::CHANGE);
2470 // It is possible to make it a lot faster still
2471 // just comment out the line below...
2477 owner_->showState();
2482 case LFUN_BACKSPACE_SKIP:
2484 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2485 LyXText * lt = bv_->getLyXText();
2487 LyXCursor cursor = lt->cursor;
2489 if (!lt->selection.set()) {
2490 if (cursor.pos() == 0
2491 && !(cursor.par()->params().spaceTop()
2492 == VSpace (VSpace::NONE))) {
2495 cursor.par()->params().lineTop(),
2496 cursor.par()->params().lineBottom(),
2497 cursor.par()->params().pagebreakTop(),
2498 cursor.par()->params().pagebreakBottom(),
2499 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2500 cursor.par()->params().align(),
2501 cursor.par()->params().labelWidthString(), 0);
2504 | BufferView::FITCUR
2505 | BufferView::CHANGE);
2508 lt->selection.cursor = cursor;
2511 | BufferView::FITCUR
2512 | BufferView::CHANGE);
2519 case LFUN_BREAKPARAGRAPH:
2521 LyXText * lt = bv_->getLyXText();
2524 lt->breakParagraph(bv_, 0);
2527 | BufferView::FITCUR
2528 | BufferView::CHANGE);
2529 lt->selection.cursor = lt->cursor;
2531 owner_->showState();
2535 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2537 LyXText * lt = bv_->getLyXText();
2540 lt->breakParagraph(bv_, 1);
2543 | BufferView::FITCUR
2544 | BufferView::CHANGE);
2545 lt->selection.cursor = lt->cursor;
2547 owner_->showState();
2551 case LFUN_BREAKPARAGRAPH_SKIP:
2553 // When at the beginning of a paragraph, remove
2554 // indentation and add a "defskip" at the top.
2555 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2556 LyXText * lt = bv_->getLyXText();
2558 LyXCursor cursor = lt->cursor;
2561 if (cursor.pos() == 0) {
2562 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2565 cursor.par()->params().lineTop(),
2566 cursor.par()->params().lineBottom(),
2567 cursor.par()->params().pagebreakTop(),
2568 cursor.par()->params().pagebreakBottom(),
2569 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2570 cursor.par()->params().align(),
2571 cursor.par()->params().labelWidthString(), 1);
2572 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2576 lt->breakParagraph(bv_, 0);
2577 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2582 | BufferView::FITCUR
2583 | BufferView::CHANGE);
2584 lt->selection.cursor = cursor;
2586 owner_->showState();
2590 case LFUN_PARAGRAPH_SPACING:
2592 LyXText * lt = bv_->getLyXText();
2594 Paragraph * par = lt->cursor.par();
2595 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2596 float cur_value = 1.0;
2597 if (cur_spacing == Spacing::Other) {
2598 cur_value = par->params().spacing().getValue();
2601 istringstream istr(argument.c_str());
2605 Spacing::Space new_spacing = cur_spacing;
2606 float new_value = cur_value;
2608 lyxerr << "Missing argument to `paragraph-spacing'"
2610 } else if (tmp == "single") {
2611 new_spacing = Spacing::Single;
2612 } else if (tmp == "onehalf") {
2613 new_spacing = Spacing::Onehalf;
2614 } else if (tmp == "double") {
2615 new_spacing = Spacing::Double;
2616 } else if (tmp == "other") {
2617 new_spacing = Spacing::Other;
2620 lyxerr << "new_value = " << tmpval << endl;
2623 } else if (tmp == "default") {
2624 new_spacing = Spacing::Default;
2626 lyxerr << _("Unknown spacing argument: ")
2627 << argument << endl;
2629 if (cur_spacing != new_spacing || cur_value != new_value) {
2630 par->params().spacing(Spacing(new_spacing, new_value));
2631 lt->redoParagraph(bv_);
2634 | BufferView::FITCUR
2635 | BufferView::CHANGE);
2640 case LFUN_INSET_TOGGLE:
2642 LyXText * lt = bv_->getLyXText();
2645 update(lt, BufferView::SELECT|BufferView::FITCUR);
2646 lt->toggleInset(bv_);
2647 update(lt, BufferView::SELECT|BufferView::FITCUR);
2653 bv_->insertCorrectQuote();
2659 InsetCommandParams p;
2660 if (action == LFUN_HTMLURL)
2661 p.setCmdName("htmlurl");
2663 p.setCmdName("url");
2664 owner_->getDialogs()->createUrl( p.getAsString() );
2668 case LFUN_INSERT_URL:
2670 InsetCommandParams p;
2671 p.setFromString( argument );
2673 InsetUrl * inset = new InsetUrl( p );
2674 if (!insertInset(inset))
2677 updateInset( inset, true );
2681 case LFUN_INSET_TEXT:
2683 InsetText * new_inset = new InsetText;
2684 if (insertInset(new_inset))
2685 new_inset->edit(bv_, 0, 0, 0);
2691 case LFUN_INSET_ERT:
2693 InsetERT * new_inset = new InsetERT;
2694 if (insertInset(new_inset))
2695 new_inset->edit(bv_, 0, 0, 0);
2701 case LFUN_INSET_EXTERNAL:
2703 InsetExternal * new_inset = new InsetExternal;
2704 if (insertInset(new_inset))
2705 new_inset->edit(bv_, 0, 0, 0);
2711 case LFUN_INSET_FOOTNOTE:
2713 InsetFoot * new_inset = new InsetFoot;
2714 if (insertInset(new_inset))
2715 new_inset->edit(bv_, 0, 0, 0);
2721 case LFUN_INSET_MARGINAL:
2723 InsetMarginal * new_inset = new InsetMarginal;
2724 if (insertInset(new_inset))
2725 new_inset->edit(bv_, 0, 0, 0);
2731 case LFUN_INSET_MINIPAGE:
2733 InsetMinipage * new_inset = new InsetMinipage;
2734 if (insertInset(new_inset))
2735 new_inset->edit(bv_, 0, 0, 0);
2741 case LFUN_INSET_FLOAT:
2743 // check if the float type exist
2744 if (floatList.typeExist(argument)) {
2745 InsetFloat * new_inset = new InsetFloat(argument);
2746 if (insertInset(new_inset))
2747 new_inset->edit(bv_, 0, 0, 0);
2751 lyxerr << "Non-existant float type: "
2752 << argument << endl;
2758 case LFUN_INSET_WIDE_FLOAT:
2760 // check if the float type exist
2761 if (floatList.typeExist(argument)) {
2762 InsetFloat * new_inset = new InsetFloat(argument);
2763 new_inset->wide(true);
2764 if (insertInset(new_inset))
2765 new_inset->edit(bv_, 0, 0, 0);
2769 lyxerr << "Non-existant float type: "
2770 << argument << endl;
2776 case LFUN_INSET_LIST:
2778 InsetList * new_inset = new InsetList;
2779 if (insertInset(new_inset))
2780 new_inset->edit(bv_, 0, 0, 0);
2786 case LFUN_INSET_THEOREM:
2788 InsetTheorem * new_inset = new InsetTheorem;
2789 if (insertInset(new_inset))
2790 new_inset->edit(bv_, 0, 0, 0);
2796 case LFUN_INSET_CAPTION:
2798 // Do we have a locking inset...
2799 if (bv_->theLockingInset()) {
2800 lyxerr << "Locking inset code: "
2801 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2802 InsetCaption * new_inset = new InsetCaption;
2803 new_inset->setOwner(bv_->theLockingInset());
2804 new_inset->setAutoBreakRows(true);
2805 new_inset->setDrawFrame(0, InsetText::LOCKED);
2806 new_inset->setFrameColor(0, LColor::captionframe);
2807 if (insertInset(new_inset))
2808 new_inset->edit(bv_, 0, 0, 0);
2815 case LFUN_INSET_TABULAR:
2819 if (!argument.empty())
2820 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2821 InsetTabular * new_inset =
2822 new InsetTabular(*buffer_, r, c);
2824 bv_->getLyXText()->real_current_font.isRightToLeft();
2825 if (!open_new_inset(new_inset, rtl))
2830 // --- lyxserver commands ----------------------------
2832 case LFUN_CHARATCURSOR:
2834 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2835 if (pos < bv_->getLyXText()->cursor.par()->size())
2836 owner_->getLyXFunc()->setMessage(
2837 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2839 owner_->getLyXFunc()->setMessage("EOF");
2844 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2846 + tostr(bv_->getLyXText()->cursor.y()));
2853 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2854 lyxerr << "SETXY: Could not parse coordinates in '"
2855 << argument << std::endl;
2857 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2861 case LFUN_GETLAYOUT:
2862 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2867 LyXFont & font = bv_->getLyXText()->current_font;
2868 if (font.shape() == LyXFont::ITALIC_SHAPE)
2869 owner_->getLyXFunc()->setMessage("E");
2870 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2871 owner_->getLyXFunc()->setMessage("N");
2873 owner_->getLyXFunc()->setMessage("0");
2881 LyXFont & font = bv_->getLyXText()->current_font;
2882 if (font.latex() == LyXFont::ON)
2883 owner_->getLyXFunc()->setMessage("L");
2886 owner_->getLyXFunc()->setMessage("0");
2890 // --- accented characters ---------------------------
2893 case LFUN_CIRCUMFLEX:
2903 case LFUN_SPECIAL_CARON:
2906 case LFUN_HUNG_UMLAUT:
2909 if (argument.empty()) {
2911 owner_->getLyXFunc()->handleKeyFunc(action);
2913 owner_->getLyXFunc()->handleKeyFunc(action);
2914 owner_->getIntl()->getTrans()
2915 .TranslateAndInsert(argument[0], bv_->getLyXText());
2916 update(bv_->getLyXText(),
2918 | BufferView::FITCUR
2919 | BufferView::CHANGE);
2923 case LFUN_MATH_MACRO:
2924 mathDispatchMathMacro(bv_, argument);
2927 case LFUN_MATH_DELIM:
2928 mathDispatchMathDelim(bv_, argument);
2931 case LFUN_INSERT_MATRIX:
2932 mathDispatchInsertMatrix(bv_, argument);
2935 case LFUN_INSERT_MATH:
2936 mathDispatchInsertMath(bv_, argument);
2939 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2940 mathDispatchMathImportSelection(bv_, argument);
2943 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2944 mathDispatchMathDisplay(bv_, argument);
2947 case LFUN_MATH_MODE: // Open or create an inlined math inset
2948 mathDispatchMathMode(bv_, argument);
2951 case LFUN_CITATION_INSERT:
2953 InsetCommandParams p;
2954 p.setFromString( argument );
2956 InsetCitation * inset = new InsetCitation( p );
2957 if (!insertInset(inset))
2960 updateInset( inset, true );
2964 case LFUN_INSERT_BIBTEX:
2966 // ale970405+lasgoutt970425
2967 // The argument can be up to two tokens separated
2968 // by a space. The first one is the bibstyle.
2969 string const db = token(argument, ' ', 0);
2970 string bibstyle = token(argument, ' ', 1);
2971 if (bibstyle.empty())
2974 InsetCommandParams p( "BibTeX", db, bibstyle );
2975 InsetBibtex * inset = new InsetBibtex(p);
2977 if (insertInset(inset)) {
2978 if (argument.empty())
2979 inset->edit(bv_, 0, 0, 0);
2985 // BibTeX data bases
2986 case LFUN_BIBDB_ADD:
2988 InsetBibtex * inset =
2989 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2991 inset->addDatabase(argument);
2996 case LFUN_BIBDB_DEL:
2998 InsetBibtex * inset =
2999 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3001 inset->delDatabase(argument);
3006 case LFUN_BIBTEX_STYLE:
3008 InsetBibtex * inset =
3009 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3011 inset->setOptions(argument);
3016 case LFUN_INDEX_CREATE:
3018 InsetCommandParams p( "index" );
3020 if (argument.empty()) {
3021 // Get the word immediately preceding the cursor
3022 Paragraph::size_type curpos =
3023 bv_->getLyXText()->cursor.pos() - 1;
3027 curstring = bv_->getLyXText()
3028 ->cursor.par()->getWord(curpos);
3030 p.setContents( curstring );
3032 p.setContents( argument );
3035 owner_->getDialogs()->createIndex( p.getAsString() );
3039 case LFUN_INDEX_INSERT:
3041 InsetCommandParams p;
3042 p.setFromString(argument);
3043 InsetIndex * inset = new InsetIndex(p);
3045 if (!insertInset(inset))
3048 updateInset(inset, true);
3052 case LFUN_INDEX_INSERT_LAST:
3054 // Get word immediately preceding the cursor
3055 Paragraph::size_type curpos =
3056 bv_->getLyXText()->cursor.pos() - 1;
3057 // Can't do that at the beginning of a paragraph
3058 if (curpos < 0) break;
3060 string const curstring(bv_->getLyXText()
3061 ->cursor.par()->getWord(curpos));
3063 InsetCommandParams p("index", curstring);
3064 InsetIndex * inset = new InsetIndex(p);
3066 if (!insertInset(inset))
3069 updateInset(inset, true);
3073 case LFUN_INDEX_PRINT:
3075 InsetCommandParams p("printindex");
3076 Inset * inset = new InsetPrintIndex(p);
3077 if (!insertInset(inset, "Standard"))
3082 case LFUN_PARENTINSERT:
3084 lyxerr << "arg " << argument << endl;
3085 InsetCommandParams p( "lyxparent", argument );
3086 Inset * inset = new InsetParent(p, *buffer_);
3087 if (!insertInset(inset, "Standard"))
3093 case LFUN_CHILD_INSERT:
3095 InsetInclude::Params p;
3096 p.cparams.setFromString(argument);
3097 p.masterFilename_ = buffer_->fileName();
3099 InsetInclude * inset = new InsetInclude(p);
3100 if (!insertInset(inset))
3103 updateInset(inset, true);
3104 bv_->owner()->getDialogs()->showInclude(inset);
3109 case LFUN_FLOAT_LIST:
3111 // We should check the argument for validity. (Lgb)
3112 Inset * inset = new InsetFloatList(argument);
3113 if (!insertInset(inset, "Standard"))
3118 case LFUN_INSERT_NOTE:
3122 case LFUN_SELFINSERT:
3124 if (argument.empty()) break;
3126 /* Automatically delete the currently selected
3127 * text and replace it with what is being
3128 * typed in now. Depends on lyxrc settings
3129 * "auto_region_delete", which defaults to
3132 LyXText * lt = bv_->getLyXText();
3134 if (lyxrc.auto_region_delete) {
3135 if (lt->selection.set()) {
3136 lt->cutSelection(bv_, false);
3139 | BufferView::FITCUR
3140 | BufferView::CHANGE);
3144 bv_->beforeChange(lt);
3145 LyXFont const old_font(lt->real_current_font);
3147 string::const_iterator cit = argument.begin();
3148 string::const_iterator end = argument.end();
3149 for (; cit != end; ++cit) {
3150 if (greek_kb_flag) {
3151 if (!math_insert_greek(bv_, *cit))
3152 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3154 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3159 | BufferView::FITCUR
3160 | BufferView::CHANGE);
3162 lt->selection.cursor = lt->cursor;
3163 moveCursorUpdate(false);
3165 // real_current_font.number can change so we need to
3166 // update the minibuffer
3167 if (old_font != lt->real_current_font)
3168 owner_->showState();
3173 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3175 time_t now_time_t = time(NULL);
3176 struct tm * now_tm = localtime(&now_time_t);
3177 setlocale(LC_TIME, "");
3179 if (!argument.empty())
3182 arg = lyxrc.date_insert_format;
3184 int const datetmp_len =
3185 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3187 LyXText * lt = bv_->getLyXText();
3189 for (int i = 0; i < datetmp_len; i++) {
3190 lt->insertChar(bv_, datetmp[i]);
3193 | BufferView::FITCUR
3194 | BufferView::CHANGE);
3197 lt->selection.cursor = lt->cursor;
3198 moveCursorUpdate(false);
3202 case LFUN_UNKNOWN_ACTION:
3203 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3214 void BufferView::Pimpl::newline()
3217 LyXText * lt = bv_->getLyXText();
3221 | BufferView::FITCUR);
3222 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3225 | BufferView::FITCUR
3226 | BufferView::CHANGE);
3231 void BufferView::Pimpl::hfill()
3234 LyXText * lt = bv_->getLyXText();
3238 | BufferView::FITCUR);
3239 lt->insertChar(bv_, Paragraph::META_HFILL);
3242 | BufferView::FITCUR
3243 | BufferView::CHANGE);
3248 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3252 update(lt, BufferView::SELECT|BufferView::FITCUR);
3253 InsetSpecialChar * new_inset =
3254 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3255 if (!insertInset(new_inset))
3258 updateInset(new_inset, true);
3263 void BufferView::Pimpl::menuSeparator()
3266 LyXText * lt = bv_->getLyXText();
3269 update(lt, BufferView::SELECT|BufferView::FITCUR);
3270 InsetSpecialChar * new_inset =
3271 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3272 insertInset(new_inset);
3277 void BufferView::Pimpl::endOfSentenceDot()
3281 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3282 InsetSpecialChar * new_inset =
3283 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3284 insertInset(new_inset);
3289 void BufferView::Pimpl::ldots()
3293 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3294 InsetSpecialChar * new_inset =
3295 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3296 insertInset(new_inset);
3301 void BufferView::Pimpl::hyphenationPoint()
3305 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3306 InsetSpecialChar * new_inset =
3307 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3308 insertInset(new_inset);
3313 void BufferView::Pimpl::insertNote()
3315 InsetInfo * new_inset = new InsetInfo();
3316 insertInset(new_inset);
3317 new_inset->edit(bv_, 0, 0, 0);
3321 // Open and lock an updatable inset
3322 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3324 LyXText * lt = bv_->getLyXText();
3328 if (!insertInset(new_inset)) {
3333 LyXFont & font = lt->real_current_font;
3334 new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
3336 new_inset->edit(bv_, 0, 0, 0);
3341 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3343 // if we are in a locking inset we should try to insert the
3344 // inset there otherwise this is a illegal function now
3345 if (bv_->theLockingInset()) {
3346 if (bv_->theLockingInset()->insetAllowed(inset))
3347 return bv_->theLockingInset()->insertInset(bv_, inset);
3351 // not quite sure if we want this...
3352 setCursorParUndo(bv_);
3355 beforeChange(bv_->text);
3356 if (!lout.empty()) {
3357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3358 bv_->text->breakParagraph(bv_);
3359 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3361 if (bv_->text->cursor.par()->size()) {
3362 bv_->text->cursorLeft(bv_);
3364 bv_->text->breakParagraph(bv_);
3365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3368 pair<bool, LyXTextClass::size_type> lres =
3369 textclasslist.NumberOfLayout(buffer_->params
3371 LyXTextClass::size_type lay;
3372 if (lres.first != false) {
3376 // layout not fount using default "Standard" (0)
3380 bv_->text->setLayout(bv_, lay);
3382 bv_->text->setParagraph(bv_, 0, 0,
3384 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3388 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3390 bv_->text->current_font.setLatex(LyXFont::OFF);
3394 bv_->text->insertInset(bv_, inset);
3395 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3402 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3407 // first check for locking insets
3408 if (bv_->theLockingInset()) {
3409 if (bv_->theLockingInset() == inset) {
3410 if (bv_->text->updateInset(bv_, inset)) {
3413 buffer_->markDirty();
3418 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3419 if (bv_->text->updateInset(bv_,
3420 bv_->theLockingInset())) {
3423 buffer_->markDirty();
3431 // then check the current buffer
3434 update(bv_->text, BufferView::UPDATE);
3435 if (bv_->text->updateInset(bv_, inset)) {
3439 | BufferView::FITCUR
3440 | BufferView::CHANGE);
3442 update(bv_->text, SELECT);
3450 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3453 if (!available()) return;
3456 beforeChange(bv_->text);
3457 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3461 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3462 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3463 if (find(codes.begin(), codes.end(), inset->lyxCode())
3466 static_cast<InsetCommand const *>(inset)->getContents();
3469 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3470 if (bv_->text->cursor.pos()
3471 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3472 LyXCursor tmp = bv_->text->cursor;
3473 bv_->text->cursor.par(bv_->text->firstParagraph());
3474 bv_->text->cursor.pos(0);
3475 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3476 bv_->text->cursor = tmp;
3477 bv_->owner()->message(_("No more insets"));
3480 bv_->owner()->message(_("No more insets"));
3483 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3484 bv_->text->selection.cursor = bv_->text->cursor;
3488 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3490 gotoInset(vector<Inset::Code>(1, code), same_content);