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/insetnote.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/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetlist.h"
59 #include "insets/insetcaption.h"
60 #include "insets/insetfloatlist.h"
61 #include "insets/insetspecialchar.h"
63 #include "ParagraphParameters.h"
64 #include "undo_funcs.h"
65 #include "mathed/formulabase.h"
67 extern LyXTextClass::size_type current_layout;
68 extern int greek_kb_flag;
79 /* the selection possible is needed, that only motion events are
80 * used, where the bottom press event was on the drawing area too */
81 bool selection_possible = false;
83 extern BufferList bufferlist;
84 extern char ascii_type;
86 extern bool math_insert_greek(BufferView *, char);
87 extern void sigchldchecker(pid_t pid, int * status);
88 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
93 const unsigned int saved_positions_num = 20;
98 XSync(fl_get_display(), 0);
102 void SetXtermCursor(Window win)
104 static Cursor cursor;
105 static bool cursor_undefined = true;
106 if (cursor_undefined){
107 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
108 XFlush(fl_get_display());
109 cursor_undefined = false;
111 XDefineCursor(fl_get_display(), win, cursor);
112 XFlush(fl_get_display());
118 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
119 int xpos, int ypos, int width, int height)
120 : bv_(b), owner_(o), buffer_(0),
121 current_scrollbar_value(0), cursor_timeout(400),
122 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
126 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
127 workarea_.workAreaExpose
128 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
129 workarea_.workAreaEnter
130 .connect(slot(this, &BufferView::Pimpl::enterView));
131 workarea_.workAreaLeave
132 .connect(slot(this, &BufferView::Pimpl::leaveView));
133 workarea_.workAreaButtonPress
134 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
135 workarea_.workAreaButtonRelease
137 &BufferView::Pimpl::workAreaButtonRelease));
138 workarea_.workAreaMotionNotify
139 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
140 workarea_.workAreaDoubleClick
141 .connect(slot(this, &BufferView::Pimpl::doubleClick));
142 workarea_.workAreaTripleClick
143 .connect(slot(this, &BufferView::Pimpl::tripleClick));
144 workarea_.workAreaKeyPress
145 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
147 cursor_timeout.timeout.connect(slot(this,
148 &BufferView::Pimpl::cursorToggle));
149 cursor_timeout.start();
150 workarea_.setFocus();
151 saved_positions.resize(saved_positions_num);
155 Painter & BufferView::Pimpl::painter()
157 return workarea_.getPainter();
161 void BufferView::Pimpl::buffer(Buffer * b)
163 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
167 buffer_->delUser(bv_);
169 // Put the old text into the TextCache, but
170 // only if the buffer is still loaded.
171 // Also set the owner of the test to 0
172 // bv_->text->owner(0);
173 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
174 if (lyxerr.debugging())
175 textcache.show(lyxerr, "BufferView::buffer");
180 // Set current buffer
183 if (bufferlist.getState() == BufferList::CLOSING) return;
186 // screen is always deleted when the buffer is changed.
189 // If we are closing the buffer, use the first buffer as current
191 buffer_ = bufferlist.first();
195 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
196 buffer_->addUser(bv_);
197 // If we don't have a text object for this, we make one
198 if (bv_->text == 0) {
199 resizeCurrentBuffer();
204 bv_->text->first = screen_->topCursorVisible(bv_->text);
205 owner_->updateMenubar();
206 owner_->updateToolbar();
207 // Similarly, buffer-dependent dialogs should be updated or
208 // hidden. This should go here because some dialogs (eg ToC)
209 // require bv_->text.
210 owner_->getDialogs()->updateBufferDependent(true);
214 lyxerr[Debug::INFO] << " No Buffer!" << endl;
215 owner_->updateMenubar();
216 owner_->updateToolbar();
217 owner_->getDialogs()->hideBufferDependent();
221 // Also remove all remaining text's from the testcache.
222 // (there should not be any!) (if there is any it is a
224 if (lyxerr.debugging())
225 textcache.show(lyxerr, "buffer delete all");
228 // should update layoutchoice even if we don't have a buffer.
229 owner_->updateLayoutChoice();
231 owner_->updateWindowTitle();
235 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
237 workarea_.resize(xpos, ypos, width, height);
238 update(bv_->text, SELECT);
243 void BufferView::Pimpl::resize()
246 resizeCurrentBuffer();
250 void BufferView::Pimpl::redraw()
252 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
257 bool BufferView::Pimpl::fitCursor(LyXText * text)
259 lyx::Assert(screen_.get());
263 if (bv_->theLockingInset()) {
264 bv_->theLockingInset()->fitInsetCursor(bv_);
267 ret = screen_->fitCursor(text, bv_);
270 bv_->owner()->getDialogs()->updateParagraph();
277 void BufferView::Pimpl::redoCurrentBuffer()
279 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
280 if (buffer_ && bv_->text) {
282 owner_->updateLayoutChoice();
287 int BufferView::Pimpl::resizeCurrentBuffer()
289 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
292 Paragraph * selstartpar = 0;
293 Paragraph * selendpar = 0;
294 UpdatableInset * the_locking_inset = 0;
296 Paragraph::size_type pos = 0;
297 Paragraph::size_type selstartpos = 0;
298 Paragraph::size_type selendpos = 0;
299 bool selection = false;
300 bool mark_set = false;
302 owner_->prohibitInput();
304 owner_->message(_("Formatting document..."));
307 par = bv_->text->cursor.par();
308 pos = bv_->text->cursor.pos();
309 selstartpar = bv_->text->selection.start.par();
310 selstartpos = bv_->text->selection.start.pos();
311 selendpar = bv_->text->selection.end.par();
312 selendpos = bv_->text->selection.end.pos();
313 selection = bv_->text->selection.set();
314 mark_set = bv_->text->selection.mark();
315 the_locking_inset = bv_->theLockingInset();
317 bv_->text = new LyXText(bv_);
318 bv_->text->init(bv_);
320 // See if we have a text in TextCache that fits
321 // the new buffer_ with the correct width.
322 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
324 if (lyxerr.debugging()) {
325 lyxerr << "Found a LyXText that fits:\n";
326 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
328 // Set the owner of the newly found text
329 // bv_->text->owner(bv_);
330 if (lyxerr.debugging())
331 textcache.show(lyxerr, "resizeCurrentBuffer");
333 bv_->text = new LyXText(bv_);
334 bv_->text->init(bv_);
340 bv_->text->selection.set(true);
341 /* at this point just to avoid the Delete-Empty-Paragraph
342 * Mechanism when setting the cursor */
343 bv_->text->selection.mark(mark_set);
345 bv_->text->setCursor(bv_, selstartpar, selstartpos);
346 bv_->text->selection.cursor = bv_->text->cursor;
347 bv_->text->setCursor(bv_, selendpar, selendpos);
348 bv_->text->setSelection(bv_);
349 bv_->text->setCursor(bv_, par, pos);
351 bv_->text->setCursor(bv_, par, pos);
352 bv_->text->selection.cursor = bv_->text->cursor;
353 bv_->text->selection.set(false);
355 // remake the inset locking
356 bv_->theLockingInset(the_locking_inset);
358 bv_->text->first = screen_->topCursorVisible(bv_->text);
359 buffer_->resizeInsets(bv_);
360 // this will scroll the screen such that the cursor becomes visible
365 owner_->allowInput();
367 /// clear the "Formatting Document" message
370 /// get rid of the splash screen if it's not gone already
371 owner_->getDialogs()->destroySplash();
377 void BufferView::Pimpl::updateScreen()
379 // Regenerate the screen.
380 screen_.reset(new LyXScreen(workarea_));
384 void BufferView::Pimpl::updateScrollbar()
386 /* If the text is smaller than the working area, the scrollbar
387 * maximum must be the working area height. No scrolling will
390 workarea_.setScrollbar(0, 1.0);
394 long const text_height = bv_->text->height;
396 double const lineh = bv_->text->defaultHeight();
397 double const slider_size =
398 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
400 static long old_text_height = 0;
401 static double old_lineh = 0;
402 static double old_slider_size = 0;
404 if (text_height != old_text_height) {
405 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
406 old_text_height = text_height;
408 if (lineh != old_lineh) {
409 workarea_.setScrollbarIncrements(lineh);
412 if (current_scrollbar_value != bv_->text->first
413 || slider_size != old_slider_size) {
414 current_scrollbar_value = bv_->text->first;
415 workarea_.setScrollbar(current_scrollbar_value, slider_size);
416 old_slider_size = slider_size;
421 // Callback for scrollbar slider
422 void BufferView::Pimpl::scrollCB(double value)
424 if (!buffer_) return;
426 current_scrollbar_value = long(value);
427 if (current_scrollbar_value < 0)
428 current_scrollbar_value = 0;
433 screen_->draw(bv_->text, bv_, current_scrollbar_value);
435 if (!lyxrc.cursor_follows_scrollbar) {
440 LyXText * vbt = bv_->text;
442 int const height = vbt->defaultHeight();
443 int const first = static_cast<int>((bv_->text->first + height));
444 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
446 if (vbt->cursor.y() < first)
447 vbt->setCursorFromCoordinates(bv_, 0, first);
448 else if (vbt->cursor.y() > last)
449 vbt->setCursorFromCoordinates(bv_, 0, last);
455 int BufferView::Pimpl::scrollUp(long time)
457 if (!buffer_) return 0;
458 if (!screen_.get()) return 0;
460 double value = workarea_.getScrollbarValue();
462 if (value == 0) return 0;
464 float add_value = (bv_->text->defaultHeight()
465 + float(time) * float(time) * 0.125);
467 if (add_value > workarea_.height())
468 add_value = float(workarea_.height() -
469 bv_->text->defaultHeight());
476 workarea_.setScrollbarValue(value);
483 int BufferView::Pimpl::scrollDown(long time)
485 if (!buffer_) return 0;
486 if (!screen_.get()) return 0;
488 double value = workarea_.getScrollbarValue();
489 pair<float, float> p = workarea_.getScrollbarBounds();
490 double const max = p.second;
492 if (value == max) return 0;
494 float add_value = (bv_->text->defaultHeight()
495 + float(time) * float(time) * 0.125);
497 if (add_value > workarea_.height())
498 add_value = float(workarea_.height() -
499 bv_->text->defaultHeight());
506 workarea_.setScrollbarValue(value);
513 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
515 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
519 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
521 // Only use motion with button 1
522 if (!(state & Button1MotionMask))
525 if (!buffer_ || !screen_.get()) return;
527 // Check for inset locking
528 if (bv_->theLockingInset()) {
529 LyXCursor cursor = bv_->text->cursor;
530 LyXFont font = bv_->text->getFont(buffer_,
531 cursor.par(), cursor.pos());
532 int width = bv_->theLockingInset()->width(bv_, font);
533 int inset_x = font.isVisibleRightToLeft()
534 ? cursor.x() - width : cursor.x();
535 int start_x = inset_x + bv_->theLockingInset()->scroll();
536 bv_->theLockingInset()->
537 insetMotionNotify(bv_,
539 y - cursor.y() + bv_->text->first,
544 /* The test for not selection possible is needed, that only motion
545 events are used, where the bottom press event was on
546 the drawing area too */
547 if (!selection_possible)
550 screen_->hideCursor();
552 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
554 if (!bv_->text->selection.set())
555 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
557 bv_->text->setSelection(bv_);
558 screen_->toggleToggle(bv_->text, bv_);
559 fitCursor(bv_->text);
560 screen_->showCursor(bv_->text, bv_);
564 // Single-click on work area
565 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
568 if (!buffer_ || !screen_.get()) return;
570 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
572 // ok ok, this is a hack.
573 if (button == 4 || button == 5) {
576 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
579 scrollDown(lyxrc.wheel_jump);
584 if (bv_->theLockingInset()) {
585 // We are in inset locking mode
587 /* Check whether the inset was hit. If not reset mode,
588 otherwise give the event to the inset */
589 if (inset_hit == bv_->theLockingInset()) {
590 bv_->theLockingInset()->
591 insetButtonPress(bv_,
596 bv_->unlockInset(bv_->theLockingInset());
601 selection_possible = true;
602 screen_->hideCursor();
604 int const screen_first = bv_->text->first;
606 // Middle button press pastes if we have a selection
607 bool paste_internally = false;
609 && bv_->text->selection.set()) {
610 owner_->getLyXFunc()->dispatch(LFUN_COPY);
611 paste_internally = true;
614 // Clear the selection
615 screen_->toggleSelection(bv_->text, bv_);
616 bv_->text->clearSelection(bv_);
617 bv_->text->fullRebreak(bv_);
618 screen_->update(bv_->text, bv_);
621 // Single left click in math inset?
622 if ((inset_hit != 0) &&
623 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
624 // Highly editable inset, like math
625 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
626 selection_possible = false;
627 owner_->updateLayoutChoice();
628 owner_->message(inset->editMessage());
629 inset->insetButtonPress(bv_, xpos, ypos, button);
630 inset->edit(bv_, xpos, ypos, button);
634 // Right click on a footnote flag opens float menu
636 selection_possible = false;
640 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
641 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
643 bv_->text->selection.cursor = bv_->text->cursor;
644 bv_->text->cursor.x_fix(bv_->text->cursor.x());
646 owner_->updateLayoutChoice();
647 if (fitCursor(bv_->text)) {
648 selection_possible = false;
651 // Insert primary selection with middle mouse
652 // if there is a local selection in the current buffer,
655 if (paste_internally)
656 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
658 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
660 selection_possible = false;
666 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
672 LyXText * text = bv_->getLyXText();
674 if (text->bv_owner && bv_->theLockingInset())
677 if (screen_.get() && button == 1) {
678 if (text->bv_owner) {
679 screen_->hideCursor();
680 screen_->toggleSelection(text, bv_);
681 text->selectWord(bv_);
682 screen_->toggleSelection(text, bv_, false);
684 text->selectWord(bv_);
686 /* This will fit the cursor on the screen
688 update(text, BufferView::SELECT|BufferView::FITCUR);
693 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
699 LyXText * text = bv_->getLyXText();
701 if (text->bv_owner && bv_->theLockingInset())
704 if (screen_.get() && (button == 1)) {
705 screen_->hideCursor();
706 screen_->toggleSelection(text, bv_);
707 text->cursorHome(bv_);
708 text->selection.cursor = text->cursor;
709 text->cursorEnd(bv_);
710 text->setSelection(bv_);
711 screen_->toggleSelection(text, bv_, false);
712 /* This will fit the cursor on the screen
714 update(text, BufferView::SELECT|BufferView::FITCUR);
719 void BufferView::Pimpl::enterView()
721 if (active() && available()) {
722 SetXtermCursor(workarea_.getWin());
723 using_xterm_cursor = true;
728 void BufferView::Pimpl::leaveView()
730 if (using_xterm_cursor) {
731 XUndefineCursor(fl_get_display(), workarea_.getWin());
732 using_xterm_cursor = false;
737 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
740 if (!buffer_ || !screen_.get()) return;
742 // If we hit an inset, we have the inset coordinates in these
743 // and inset_hit points to the inset. If we do not hit an
744 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
745 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
747 if (bv_->theLockingInset()) {
748 // We are in inset locking mode.
750 /* LyX does a kind of work-area grabbing for insets.
751 Only a ButtonPress Event outside the inset will
752 force a insetUnlock. */
753 bv_->theLockingInset()->
754 insetButtonRelease(bv_, x, y, button);
758 selection_possible = false;
766 // Did we hit an editable inset?
768 // Inset like error, notes and figures
769 selection_possible = false;
771 // CHECK fix this proper in 0.13
773 // Following a ref shouldn't issue
774 // a push on the undo-stack
775 // anylonger, now that we have
776 // keybindings for following
777 // references and returning from
778 // references. IMHO though, it
779 // should be the inset's own business
780 // to push or not push on the undo
781 // stack. They don't *have* to
782 // alter the document...
784 // ...or maybe the SetCursorParUndo()
785 // below isn't necessary at all anylonger?
786 if (inset_hit->lyxCode() == Inset::REF_CODE) {
787 setCursorParUndo(bv_);
790 owner_->message(inset_hit->editMessage());
792 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
793 // Highly editable inset, like math
794 UpdatableInset *inset = (UpdatableInset *)inset_hit;
795 inset->insetButtonRelease(bv_, x, y, button);
797 inset_hit->insetButtonRelease(bv_, x, y, button);
798 inset_hit->edit(bv_, x, y, button);
803 // check whether we want to open a float
807 if (bv_->text->cursor.pos() <
808 bv_->text->cursor.par()->size()) {
809 c = bv_->text->cursor.par()->
810 getChar(bv_->text->cursor.pos());
812 if (bv_->text->cursor.pos() - 1 >= 0) {
813 c = bv_->text->cursor.par()->
814 getChar(bv_->text->cursor.pos() - 1);
817 selection_possible = false;
822 // Maybe we want to edit a bibitem ale970302
823 if (bv_->text->cursor.par()->bibkey && x < 20 +
824 bibitemMaxWidth(bv_, textclasslist.
826 params.textclass).defaultfont())) {
827 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
835 * Returns an inset if inset was hit. 0 otherwise.
836 * If hit, the coordinates are changed relative to the inset.
837 * Otherwise coordinates are not changed, and false is returned.
839 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
840 unsigned int /* button */)
845 int y_tmp = y + text->first;
848 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
849 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
852 if (cursor.pos() < cursor.par()->size()
853 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
854 && cursor.par()->getInset(cursor.pos())
855 && cursor.par()->getInset(cursor.pos())->editable()) {
857 // Check whether the inset really was hit
858 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
859 LyXFont font = text->getFont(buffer_,
860 cursor.par(), cursor.pos());
861 int const width = tmpinset->width(bv_, font);
862 int const inset_x = font.isVisibleRightToLeft()
863 ? cursor.x() - width : cursor.x();
864 int const start_x = inset_x + tmpinset->scroll();
865 int const end_x = inset_x + width;
867 if (x > start_x && x < end_x
868 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
869 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
870 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
872 // The origin of an inset is on the baseline
873 y = y_tmp - (text->cursor.y());
878 if ((cursor.pos() - 1 >= 0) &&
879 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
880 (cursor.par()->getInset(cursor.pos() - 1)) &&
881 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
882 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
883 LyXFont font = text->getFont(buffer_, cursor.par(),
885 int const width = tmpinset->width(bv_, font);
886 int const inset_x = font.isVisibleRightToLeft()
887 ? cursor.x() : cursor.x() - width;
888 int const start_x = inset_x + tmpinset->scroll();
889 int const end_x = inset_x + width;
891 if (x > start_x && x < end_x
892 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
893 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
895 if (move_cursor && (tmpinset != bv_->theLockingInset()))
897 text->setCursor(bv_, cursor.par(),
898 cursor.pos() - 1, true);
900 // The origin of an inset is on the baseline
901 y = y_tmp - (text->cursor.y());
909 void BufferView::Pimpl::workAreaExpose()
911 static int work_area_width;
912 static unsigned int work_area_height;
914 bool const widthChange = workarea_.workWidth() != work_area_width;
915 bool const heightChange = workarea_.height() != work_area_height;
917 // update from work area
918 work_area_width = workarea_.workWidth();
919 work_area_height = workarea_.height();
922 // The visible LyXView need a resize
925 // Remove all texts from the textcache
926 // This is not _really_ what we want to do. What
927 // we really want to do is to delete in textcache
928 // that does not have a BufferView with matching
929 // width, but as long as we have only one BufferView
930 // deleting all gives the same result.
931 if (lyxerr.debugging())
932 textcache.show(lyxerr, "Expose delete all");
934 } else if (heightChange) {
935 // Rebuild image of current screen
937 // fitCursor() ensures we don't jump back
938 // to the start of the document on vertical
940 fitCursor(bv_->text);
942 // The main window size has changed, repaint most stuff
944 } else if (screen_.get())
945 screen_->redraw(bv_->text, bv_);
947 // Grey box when we don't have a buffer
951 // always make sure that the scrollbar is sane.
953 owner_->updateLayoutChoice();
958 void BufferView::Pimpl::update()
961 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
963 screen_->update(bv_->text, bv_);
967 // Values used when calling update:
969 // -2 - update, move sel_cursor if selection, fitcursor
970 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
971 // 0 - update, move sel_cursor if selection, fitcursor
972 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
973 // 3 - update, move sel_cursor if selection
976 // a simple redraw of the parts that need refresh
978 // move sel_cursor if selection -
979 // the text's sel_cursor is moved if there is selection is progress
982 // fitCursor() is called and the scrollbar updated
985 // the buffer is marked dirty.
994 // UPDATE_ONLY = UPDATE;
995 // UPDATE_SELECT = UPDATE | SELECT;
996 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
997 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
999 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1000 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1001 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1002 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1003 // update(3) -> update(1) -> update(1) -> update(SELECT)
1005 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1007 owner_->updateLayoutChoice();
1009 if (!text->selection.set() && (f & SELECT)) {
1010 text->selection.cursor = text->cursor;
1013 text->fullRebreak(bv_);
1015 if (text->inset_owner) {
1016 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1017 updateInset(text->inset_owner, true);
1027 buffer_->markDirty();
1032 // Callback for cursor timer
1033 void BufferView::Pimpl::cursorToggle()
1035 // Quite a nice place for asyncron Inset updating, isn't it?
1036 // Actually no! This is run even if no buffer exist... so (Lgb)
1038 cursor_timeout.restart();
1043 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1044 if (pid == -1) // error find out what is wrong
1045 ; // ignore it for now.
1047 sigchldchecker(pid, &status);
1049 updatelist.update(bv_);
1051 if (!screen_.get()) {
1052 cursor_timeout.restart();
1056 if (!bv_->theLockingInset()) {
1057 screen_->cursorToggle(bv_->text, bv_);
1059 bv_->theLockingInset()->toggleInsetCursor(bv_);
1062 cursor_timeout.restart();
1066 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1068 if (!text->cursor.row()->previous())
1071 int y = text->first;
1072 if (text->inset_owner)
1073 y += bv_->text->first;
1074 Row * cursorrow = text->cursor.row();
1075 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1077 // This is to allow jumping over large insets
1078 if ((cursorrow == text->cursor.row()))
1079 text->cursorUp(bv_);
1081 if (text->inset_owner ||
1082 text->cursor.row()->height() < workarea_.height())
1083 screen_->draw(bv_->text, bv_,
1085 - text->cursor.row()->baseline()
1086 + text->cursor.row()->height()
1087 - workarea_.height() + 1 );
1092 void BufferView::Pimpl::cursorNext(LyXText * text)
1094 if (!text->cursor.row()->next())
1097 int y = text->first + workarea_.height();
1098 // if (text->inset_owner)
1099 // y += bv_->text->first;
1100 text->getRowNearY(y);
1102 Row * cursorrow = text->cursor.row();
1103 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1105 // This is to allow jumping over large insets
1106 if ((cursorrow == bv_->text->cursor.row()))
1107 text->cursorDown(bv_);
1109 if (text->inset_owner ||
1110 text->cursor.row()->height() < workarea_.height())
1111 screen_->draw(bv_->text, bv_, text->cursor.y() -
1112 text->cursor.row()->baseline());
1117 bool BufferView::Pimpl::available() const
1119 if (buffer_ && bv_->text) return true;
1124 void BufferView::Pimpl::beforeChange(LyXText * text)
1127 text->clearSelection(bv_);
1131 void BufferView::Pimpl::savePosition(unsigned int i)
1133 if (i >= saved_positions_num)
1135 saved_positions[i] = Position(buffer_->fileName(),
1136 bv_->text->cursor.par()->id(),
1137 bv_->text->cursor.pos());
1140 str << _("Saved bookmark") << ' ' << i;
1141 owner_->message(str.str().c_str());
1146 void BufferView::Pimpl::restorePosition(unsigned int i)
1148 if (i >= saved_positions_num)
1151 string const fname = saved_positions[i].filename;
1153 beforeChange(bv_->text);
1155 if (fname != buffer_->fileName()) {
1156 Buffer * b = bufferlist.exists(fname) ?
1157 bufferlist.getBuffer(fname) :
1158 bufferlist.loadLyXFile(fname); // don't ask, just load it
1159 if (b != 0 ) buffer(b);
1162 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1166 bv_->text->setCursor(bv_, par,
1167 min(par->size(), saved_positions[i].par_pos));
1169 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1172 str << _("Moved to bookmark") << ' ' << i;
1173 owner_->message(str.str().c_str());
1178 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1180 if (i >= saved_positions_num)
1183 return !saved_positions[i].filename.empty();
1187 void BufferView::Pimpl::setState()
1189 if (!lyxrc.rtl_support)
1192 LyXText * text = bv_->getLyXText();
1193 if (text->real_current_font.isRightToLeft()
1196 text->real_current_font.latex() != LyXFont::ON
1199 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1200 owner_->getIntl()->KeyMapSec();
1202 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1203 owner_->getIntl()->KeyMapPrim();
1208 void BufferView::Pimpl::insetSleep()
1210 if (bv_->theLockingInset() && !inset_slept) {
1211 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1212 bv_->theLockingInset()->insetUnlock(bv_);
1218 void BufferView::Pimpl::insetWakeup()
1220 if (bv_->theLockingInset() && inset_slept) {
1221 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1222 inset_slept = false;
1227 void BufferView::Pimpl::insetUnlock()
1229 if (bv_->theLockingInset()) {
1231 bv_->theLockingInset()->insetUnlock(bv_);
1232 bv_->theLockingInset(0);
1234 inset_slept = false;
1239 bool BufferView::Pimpl::focus() const
1241 return workarea_.hasFocus();
1245 void BufferView::Pimpl::focus(bool f)
1247 if (f) workarea_.setFocus();
1251 bool BufferView::Pimpl::active() const
1253 return workarea_.active();
1257 bool BufferView::Pimpl::belowMouse() const
1259 return workarea_.belowMouse();
1263 void BufferView::Pimpl::showCursor()
1265 if (screen_.get()) {
1266 if (bv_->theLockingInset())
1267 bv_->theLockingInset()->showInsetCursor(bv_);
1269 screen_->showCursor(bv_->text, bv_);
1274 void BufferView::Pimpl::hideCursor()
1276 if (screen_.get()) {
1277 if (!bv_->theLockingInset())
1278 // bv_->theLockingInset()->hideInsetCursor(bv_);
1280 screen_->hideCursor();
1285 void BufferView::Pimpl::toggleSelection(bool b)
1287 if (screen_.get()) {
1288 if (bv_->theLockingInset())
1289 bv_->theLockingInset()->toggleSelection(bv_, b);
1290 screen_->toggleSelection(bv_->text, bv_, b);
1295 void BufferView::Pimpl::toggleToggle()
1298 screen_->toggleToggle(bv_->text, bv_);
1302 void BufferView::Pimpl::center()
1304 beforeChange(bv_->text);
1305 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1306 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1308 screen_->draw(bv_->text, bv_, 0);
1310 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1315 void BufferView::Pimpl::pasteClipboard(bool asPara)
1317 if (!buffer_) return;
1319 screen_->hideCursor();
1320 beforeChange(bv_->text);
1322 string const clip(workarea_.getClipboard());
1324 if (clip.empty()) return;
1327 bv_->text->insertStringAsParagraphs(bv_, clip);
1329 bv_->text->insertStringAsLines(bv_, clip);
1331 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1335 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1337 workarea_.putClipboard(stuff);
1342 * Dispatch functions for actions which can be valid for BufferView->text
1343 * and/or InsetText->text!!!
1348 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1350 LyXText * lt = bv_->getLyXText();
1352 if (selecting || lt->selection.mark()) {
1353 lt->setSelection(bv_);
1357 update(lt, BufferView::SELECT|BufferView::FITCUR);
1360 /* ---> Everytime the cursor is moved, show the current font state. */
1361 // should this too me moved out of this func?
1362 //owner->showState();
1367 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1369 LyXCursor cursor = bv_->getLyXText()->cursor;
1370 Buffer::inset_iterator it =
1371 find_if(Buffer::inset_iterator(
1372 cursor.par(), cursor.pos()),
1373 buffer_->inset_iterator_end(),
1374 lyx::compare_memfun(&Inset::lyxCode, code));
1375 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1379 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1381 string filename = filen;
1383 if (filename.empty()) {
1384 // Launch a file browser
1385 string initpath = lyxrc.document_path;
1388 string const trypath = owner_->buffer()->filepath;
1389 // If directory is writeable, use this as default.
1390 if (IsDirWriteable(trypath) == 1)
1394 FileDialog fileDlg(bv_->owner(),
1395 _("Select LyX document to insert"),
1397 make_pair(string(_("Documents")),
1398 string(lyxrc.document_path)),
1399 make_pair(string(_("Examples")),
1400 string(AddPath(system_lyxdir, "examples"))));
1402 FileDialog::Result result =
1403 fileDlg.Select(initpath,
1404 _("*.lyx| LyX Documents (*.lyx)"));
1406 if (result.first == FileDialog::Later)
1409 filename = result.second;
1411 // check selected filename
1412 if (filename.empty()) {
1413 owner_->message(_("Canceled."));
1418 // get absolute path of file and add ".lyx" to the filename if
1420 filename = FileSearch(string(), filename, "lyx");
1422 string const disp_fn(MakeDisplayPath(filename));
1425 s1 << _("Inserting document") << ' '
1426 << disp_fn << " ...";
1427 owner_->message(s1.str().c_str());
1428 bool const res = bv_->insertLyXFile(filename);
1431 str << _("Document") << ' ' << disp_fn
1432 << ' ' << _("inserted.");
1433 owner_->message(str.str().c_str());
1436 str << _("Could not insert document") << ' '
1438 owner_->message(str.str().c_str());
1443 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1445 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1446 << action <<"] arg[" << argument << "]" << endl;
1449 // --- Misc -------------------------------------------
1453 LyXText * lt = bv_->getLyXText();
1454 lt->toggleAppendix(bv_);
1457 | BufferView::FITCUR
1458 | BufferView::CHANGE);
1463 case LFUN_TOC_INSERT:
1465 InsetCommandParams p;
1466 p.setCmdName("tableofcontents");
1467 Inset * inset = new InsetTOC(p);
1468 if (!insertInset(inset, "Standard"))
1473 case LFUN_TABULAR_FEATURE:
1474 case LFUN_SCROLL_INSET:
1475 // this is not handled here as this funktion is only aktive
1476 // if we have a locking_inset and that one is (or contains)
1480 case LFUN_INSET_GRAPHICS:
1482 Inset * new_inset = new InsetGraphics;
1483 if (!insertInset(new_inset)) {
1486 // this is need because you don't use a inset->Edit()
1487 updateInset(new_inset, true);
1488 new_inset->edit(bv_);
1498 case LFUN_PASTESELECTION:
1500 bool asPara = false;
1501 if (argument == "paragraph") asPara = true;
1502 pasteClipboard(asPara);
1514 case LFUN_LAYOUT_COPY:
1515 bv_->copyEnvironment();
1518 case LFUN_LAYOUT_PASTE:
1519 bv_->pasteEnvironment();
1523 case LFUN_GOTOERROR:
1524 gotoInset(Inset::ERROR_CODE, false);
1528 gotoInset(Inset::IGNORE_CODE, false);
1531 case LFUN_REFERENCE_GOTO:
1533 vector<Inset::Code> tmp;
1534 tmp.push_back(Inset::LABEL_CODE);
1535 tmp.push_back(Inset::REF_CODE);
1536 gotoInset(tmp, true);
1540 case LFUN_HYPHENATION:
1541 specialChar(InsetSpecialChar::HYPHENATION);
1544 case LFUN_LIGATURE_BREAK:
1545 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1549 specialChar(InsetSpecialChar::LDOTS);
1552 case LFUN_END_OF_SENTENCE:
1553 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1556 case LFUN_MENU_SEPARATOR:
1557 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1565 changeDepth(bv_, bv_->getLyXText(), 0);
1568 case LFUN_DEPTH_MIN:
1569 changeDepth(bv_, bv_->getLyXText(), -1);
1572 case LFUN_DEPTH_PLUS:
1573 changeDepth(bv_, bv_->getLyXText(), 1);
1577 owner_->getDialogs()->setUserFreeFont();
1584 owner_->showState();
1588 case LFUN_FILE_INSERT:
1590 MenuInsertLyXFile(argument);
1594 case LFUN_FILE_INSERT_ASCII_PARA:
1595 InsertAsciiFile(bv_, argument, true);
1598 case LFUN_FILE_INSERT_ASCII:
1599 InsertAsciiFile(bv_, argument, false);
1604 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1605 << argument << endl;
1607 // Derive layout number from given argument (string)
1608 // and current buffer's textclass (number). */
1609 LyXTextClassList::ClassList::size_type tclass =
1610 buffer_->params.textclass;
1611 pair <bool, LyXTextClass::size_type> layout =
1612 textclasslist.NumberOfLayout(tclass, argument);
1614 // If the entry is obsolete, use the new one instead.
1616 string obs = textclasslist.Style(tclass,layout.second)
1620 textclasslist.NumberOfLayout(tclass, obs);
1623 // see if we found the layout number:
1624 if (!layout.first) {
1625 owner_->getLyXFunc()->setErrorMessage(
1626 string(N_("Layout ")) + argument +
1631 if (current_layout != layout.second) {
1632 LyXText * lt = bv_->getLyXText();
1634 current_layout = layout.second;
1637 | BufferView::FITCUR);
1638 lt->setLayout(bv_, layout.second);
1639 owner_->setLayout(layout.second);
1642 | BufferView::FITCUR
1643 | BufferView::CHANGE);
1650 Lang(bv_, argument);
1652 owner_->showState();
1657 owner_->showState();
1662 owner_->showState();
1667 owner_->showState();
1672 owner_->showState();
1677 owner_->showState();
1682 owner_->showState();
1687 owner_->showState();
1690 case LFUN_UNDERLINE:
1692 owner_->showState();
1695 case LFUN_FONT_SIZE:
1696 FontSize(bv_, argument);
1697 owner_->showState();
1700 case LFUN_FONT_STATE:
1701 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1704 case LFUN_UPCASE_WORD:
1706 LyXText * lt = bv_->getLyXText();
1710 | BufferView::FITCUR);
1711 lt->changeCase(bv_, LyXText::text_uppercase);
1712 if (lt->inset_owner)
1713 updateInset(lt->inset_owner, true);
1716 | BufferView::FITCUR
1717 | BufferView::CHANGE);
1721 case LFUN_LOWCASE_WORD:
1723 LyXText * lt = bv_->getLyXText();
1725 update(lt, BufferView::SELECT|BufferView::FITCUR);
1726 lt->changeCase(bv_, LyXText::text_lowercase);
1727 if (lt->inset_owner)
1728 updateInset(lt->inset_owner, true);
1731 | BufferView::FITCUR
1732 | BufferView::CHANGE);
1736 case LFUN_CAPITALIZE_WORD:
1738 LyXText * lt = bv_->getLyXText();
1740 update(lt, BufferView::SELECT|BufferView::FITCUR);
1741 lt->changeCase(bv_, LyXText::text_capitalization);
1742 if (lt->inset_owner)
1743 updateInset(lt->inset_owner, true);
1746 | BufferView::FITCUR
1747 | BufferView::CHANGE);
1751 case LFUN_TRANSPOSE_CHARS:
1753 LyXText * lt = bv_->getLyXText();
1755 update(lt, BufferView::SELECT|BufferView::FITCUR);
1756 lt->transposeChars(*bv_);
1757 if (lt->inset_owner)
1758 updateInset(lt->inset_owner, true);
1761 | BufferView::FITCUR
1762 | BufferView::CHANGE);
1767 case LFUN_INSERT_LABEL:
1768 MenuInsertLabel(bv_, argument);
1771 case LFUN_REF_INSERT:
1772 if (argument.empty()) {
1773 InsetCommandParams p("ref");
1774 owner_->getDialogs()->createRef(p.getAsString());
1776 InsetCommandParams p;
1777 p.setFromString(argument);
1779 InsetRef * inset = new InsetRef(p, *buffer_);
1780 if (!insertInset(inset))
1783 updateInset(inset, true);
1787 case LFUN_BOOKMARK_SAVE:
1788 savePosition(strToUnsignedInt(argument));
1791 case LFUN_BOOKMARK_GOTO:
1792 restorePosition(strToUnsignedInt(argument));
1797 string label(argument);
1798 if (label.empty()) {
1800 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1802 label = inset->getContents();
1807 if (!label.empty()) {
1808 //bv_->savePosition(0);
1809 if (!bv_->gotoLabel(label))
1810 WriteAlert(_("Error"),
1811 _("Couldn't find this label"),
1812 _("in current document."));
1817 // --- Cursor Movements -----------------------------
1820 LyXText * lt = bv_->getLyXText();
1822 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1823 if (!lt->selection.mark())
1825 update(lt, BufferView::SELECT|BufferView::FITCUR);
1827 lt->cursorLeft(bv_, false);
1828 if (lt->cursor.pos() < lt->cursor.par()->size()
1829 && lt->cursor.par()->getChar(lt->cursor.pos())
1830 == Paragraph::META_INSET
1831 && lt->cursor.par()->getInset(lt->cursor.pos())
1832 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1833 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1834 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1836 tmpinset->edit(bv_, false);
1838 tmpinset->edit(bv_);
1842 lt->cursorRight(bv_, false);
1844 moveCursorUpdate(false);
1845 owner_->showState();
1851 // This is soooo ugly. Isn`t it possible to make
1852 // it simpler? (Lgb)
1853 LyXText * lt = bv_->getLyXText();
1854 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1855 if (!lt->selection.mark())
1857 update(lt, BufferView::SELECT|BufferView::FITCUR);
1858 LyXCursor const cur = lt->cursor;
1860 lt->cursorLeft(bv_, false);
1861 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1862 lt->cursor.pos() < lt->cursor.par()->size() &&
1863 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1864 Paragraph::META_INSET) &&
1865 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1866 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1867 == Inset::HIGHLY_EDITABLE))
1869 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1870 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1872 tmpinset->edit(bv_);
1874 tmpinset->edit(bv_, false);
1878 lt->cursorRight(bv_, false);
1881 moveCursorUpdate(false);
1882 owner_->showState();
1888 LyXText * lt = bv_->getLyXText();
1890 if (!lt->selection.mark())
1892 update(lt, BufferView::UPDATE);
1895 moveCursorUpdate(false);
1896 owner_->showState();
1902 LyXText * lt = bv_->getLyXText();
1904 if (!lt->selection.mark())
1906 update(lt, BufferView::UPDATE);
1907 lt->cursorDown(bv_);
1909 moveCursorUpdate(false);
1910 owner_->showState();
1914 case LFUN_UP_PARAGRAPH:
1916 LyXText * lt = bv_->getLyXText();
1918 if (!lt->selection.mark())
1920 update(lt, BufferView::UPDATE);
1921 lt->cursorUpParagraph(bv_);
1923 moveCursorUpdate(false);
1924 owner_->showState();
1928 case LFUN_DOWN_PARAGRAPH:
1930 LyXText * lt = bv_->getLyXText();
1932 if (!lt->selection.mark())
1934 update(lt, BufferView::UPDATE);
1935 lt->cursorDownParagraph(bv_);
1937 moveCursorUpdate(false);
1938 owner_->showState();
1944 LyXText * lt = bv_->getLyXText();
1946 if (!lt->selection.mark())
1948 update(lt, BufferView::UPDATE);
1951 moveCursorUpdate(false);
1952 owner_->showState();
1958 LyXText * lt = bv_->getLyXText();
1960 if (!lt->selection.mark())
1962 update(lt, BufferView::UPDATE);
1965 moveCursorUpdate(false);
1966 owner_->showState();
1972 LyXText * lt = bv_->getLyXText();
1974 if (!lt->selection.mark())
1976 update(lt, BufferView::SELECT|BufferView::FITCUR);
1977 lt->cursorHome(bv_);
1979 moveCursorUpdate(false);
1980 owner_->showState();
1986 LyXText * lt = bv_->getLyXText();
1988 if (!lt->selection.mark())
1991 BufferView::SELECT|BufferView::FITCUR);
1994 moveCursorUpdate(false);
1995 owner_->showState();
1999 case LFUN_SHIFT_TAB:
2002 LyXText * lt = bv_->getLyXText();
2004 if (!lt->selection.mark())
2007 BufferView::SELECT|BufferView::FITCUR);
2010 moveCursorUpdate(false);
2011 owner_->showState();
2015 case LFUN_WORDRIGHT:
2017 LyXText * lt = bv_->getLyXText();
2019 if (!lt->selection.mark())
2021 update(lt, BufferView::SELECT|BufferView::FITCUR);
2022 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2023 lt->cursorLeftOneWord(bv_);
2025 lt->cursorRightOneWord(bv_);
2027 moveCursorUpdate(false);
2028 owner_->showState();
2034 LyXText * lt = bv_->getLyXText();
2036 if (!lt->selection.mark())
2038 update(lt, BufferView::SELECT|BufferView::FITCUR);
2039 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2040 lt->cursorRightOneWord(bv_);
2042 lt->cursorLeftOneWord(bv_);
2044 moveCursorUpdate(false);
2045 owner_->showState();
2049 case LFUN_BEGINNINGBUF:
2051 LyXText * lt = bv_->getLyXText();
2053 if (!lt->selection.mark())
2056 BufferView::SELECT|BufferView::FITCUR);
2059 moveCursorUpdate(false);
2060 owner_->showState();
2066 LyXText * lt = bv_->getLyXText();
2068 if (!lt->selection.mark())
2071 BufferView::SELECT|BufferView::FITCUR);
2072 lt->cursorBottom(bv_);
2074 moveCursorUpdate(false);
2075 owner_->showState();
2079 /* cursor selection ---------------------------- */
2082 LyXText * lt = bv_->getLyXText();
2085 BufferView::SELECT|BufferView::FITCUR);
2086 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2087 lt->cursorLeft(bv_);
2089 lt->cursorRight(bv_);
2091 moveCursorUpdate(true);
2092 owner_->showState();
2098 LyXText * lt = bv_->getLyXText();
2101 BufferView::SELECT|BufferView::FITCUR);
2102 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2103 lt->cursorRight(bv_);
2105 lt->cursorLeft(bv_);
2107 moveCursorUpdate(true);
2108 owner_->showState();
2114 LyXText * lt = bv_->getLyXText();
2117 BufferView::SELECT|BufferView::FITCUR);
2120 moveCursorUpdate(true);
2121 owner_->showState();
2127 LyXText * lt = bv_->getLyXText();
2130 BufferView::SELECT|BufferView::FITCUR);
2131 lt->cursorDown(bv_);
2133 moveCursorUpdate(true);
2134 owner_->showState();
2138 case LFUN_UP_PARAGRAPHSEL:
2140 LyXText * lt = bv_->getLyXText();
2143 BufferView::SELECT|BufferView::FITCUR);
2144 lt->cursorUpParagraph(bv_);
2146 moveCursorUpdate(true);
2147 owner_->showState();
2151 case LFUN_DOWN_PARAGRAPHSEL:
2153 LyXText * lt = bv_->getLyXText();
2156 BufferView::SELECT|BufferView::FITCUR);
2157 lt->cursorDownParagraph(bv_);
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);
2183 moveCursorUpdate(true);
2184 owner_->showState();
2190 LyXText * lt = bv_->getLyXText();
2192 update(lt, BufferView::SELECT|BufferView::FITCUR);
2193 lt->cursorHome(bv_);
2195 moveCursorUpdate(true);
2196 owner_->showState();
2202 LyXText * lt = bv_->getLyXText();
2204 update(lt, BufferView::SELECT|BufferView::FITCUR);
2207 moveCursorUpdate(true);
2208 owner_->showState();
2212 case LFUN_WORDRIGHTSEL:
2214 LyXText * lt = bv_->getLyXText();
2216 update(lt, BufferView::SELECT|BufferView::FITCUR);
2217 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2218 lt->cursorLeftOneWord(bv_);
2220 lt->cursorRightOneWord(bv_);
2222 moveCursorUpdate(true);
2223 owner_->showState();
2227 case LFUN_WORDLEFTSEL:
2229 LyXText * lt = bv_->getLyXText();
2231 update(lt, BufferView::SELECT|BufferView::FITCUR);
2232 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2233 lt->cursorRightOneWord(bv_);
2235 lt->cursorLeftOneWord(bv_);
2237 moveCursorUpdate(true);
2238 owner_->showState();
2242 case LFUN_BEGINNINGBUFSEL:
2244 LyXText * lt = bv_->getLyXText();
2246 if (lt->inset_owner)
2248 update(lt, BufferView::SELECT|BufferView::FITCUR);
2251 moveCursorUpdate(true);
2252 owner_->showState();
2256 case LFUN_ENDBUFSEL:
2258 LyXText * lt = bv_->getLyXText();
2260 if (lt->inset_owner)
2263 BufferView::SELECT|BufferView::FITCUR);
2264 lt->cursorBottom(bv_);
2266 moveCursorUpdate(true);
2267 owner_->showState();
2271 // --- text changing commands ------------------------
2272 case LFUN_BREAKLINE:
2274 LyXText * lt = bv_->getLyXText();
2277 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2280 | BufferView::FITCUR
2281 | BufferView::CHANGE);
2282 moveCursorUpdate(false);
2286 case LFUN_PROTECTEDSPACE:
2288 LyXText * lt = bv_->getLyXText();
2290 LyXLayout const & style = textclasslist
2291 .Style(buffer_->params.textclass,
2292 lt->cursor.par()->getLayout());
2294 if (style.free_spacing) {
2295 lt->insertChar(bv_, ' ');
2298 | BufferView::FITCUR
2299 | BufferView::CHANGE);
2303 moveCursorUpdate(false);
2309 LyXText * lt = bv_->getLyXText();
2311 if (lt->selection.mark()) {
2315 | BufferView::FITCUR);
2316 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2319 lt->selection.mark(true);
2322 | BufferView::FITCUR);
2323 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2325 lt->selection.cursor = lt->cursor;
2331 LyXText * lt = bv_->getLyXText();
2333 if (!lt->selection.set()) {
2335 lt->selection.cursor = lt->cursor;
2338 | BufferView::FITCUR
2339 | BufferView::CHANGE);
2340 // It is possible to make it a lot faster still
2341 // just comment out the line below...
2346 moveCursorUpdate(false);
2347 owner_->showState();
2352 case LFUN_DELETE_SKIP:
2354 LyXText * lt = bv_->getLyXText();
2356 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2358 LyXCursor cursor = lt->cursor;
2360 if (!lt->selection.set()) {
2361 if (cursor.pos() == cursor.par()->size()) {
2362 lt->cursorRight(bv_);
2363 cursor = lt->cursor;
2364 if (cursor.pos() == 0
2365 && !(cursor.par()->params().spaceTop()
2366 == VSpace (VSpace::NONE))) {
2369 cursor.par()->params().lineTop(),
2370 cursor.par()->params().lineBottom(),
2371 cursor.par()->params().pagebreakTop(),
2372 cursor.par()->params().pagebreakBottom(),
2373 VSpace(VSpace::NONE),
2374 cursor.par()->params().spaceBottom(),
2375 cursor.par()->params().align(),
2376 cursor.par()->params().labelWidthString(), 0);
2377 lt->cursorLeft(bv_);
2380 | BufferView::FITCUR
2381 | BufferView::CHANGE);
2383 lt->cursorLeft(bv_);
2385 lt->selection.cursor = lt->cursor;
2388 | BufferView::FITCUR
2389 | BufferView::CHANGE);
2393 lt->selection.cursor = lt->cursor;
2396 | BufferView::FITCUR
2397 | BufferView::CHANGE);
2405 /* -------> Delete word forward. */
2406 case LFUN_DELETE_WORD_FORWARD:
2407 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2408 bv_->getLyXText()->deleteWordForward(bv_);
2409 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2410 moveCursorUpdate(false);
2411 owner_->showState();
2414 /* -------> Delete word backward. */
2415 case LFUN_DELETE_WORD_BACKWARD:
2417 LyXText * lt = bv_->getLyXText();
2419 update(lt, BufferView::SELECT|BufferView::FITCUR);
2420 lt->deleteWordBackward(bv_);
2423 | BufferView::FITCUR
2424 | BufferView::CHANGE);
2425 moveCursorUpdate(false);
2426 owner_->showState();
2430 /* -------> Kill to end of line. */
2431 case LFUN_DELETE_LINE_FORWARD:
2433 LyXText * lt = bv_->getLyXText();
2435 update(lt, BufferView::SELECT|BufferView::FITCUR);
2436 lt->deleteLineForward(bv_);
2439 | BufferView::FITCUR
2440 | BufferView::CHANGE);
2441 moveCursorUpdate(false);
2445 /* -------> Set mark off. */
2448 LyXText * lt = bv_->getLyXText();
2451 update(lt, BufferView::SELECT|BufferView::FITCUR);
2452 lt->selection.cursor = lt->cursor;
2453 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2457 /* -------> Set mark on. */
2460 LyXText * lt = bv_->getLyXText();
2463 lt->selection.mark(true);
2464 update(lt, BufferView::SELECT|BufferView::FITCUR);
2465 lt->selection.cursor = lt->cursor;
2466 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2470 case LFUN_BACKSPACE:
2472 LyXText * lt = bv_->getLyXText();
2474 if (!lt->selection.set()) {
2475 if (owner_->getIntl()->getTrans().backspace()) {
2477 lt->selection.cursor = lt->cursor;
2480 | BufferView::FITCUR
2481 | BufferView::CHANGE);
2482 // It is possible to make it a lot faster still
2483 // just comment out the line below...
2489 owner_->showState();
2494 case LFUN_BACKSPACE_SKIP:
2496 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2497 LyXText * lt = bv_->getLyXText();
2499 LyXCursor cursor = lt->cursor;
2501 if (!lt->selection.set()) {
2502 if (cursor.pos() == 0
2503 && !(cursor.par()->params().spaceTop()
2504 == VSpace (VSpace::NONE))) {
2507 cursor.par()->params().lineTop(),
2508 cursor.par()->params().lineBottom(),
2509 cursor.par()->params().pagebreakTop(),
2510 cursor.par()->params().pagebreakBottom(),
2511 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2512 cursor.par()->params().align(),
2513 cursor.par()->params().labelWidthString(), 0);
2516 | BufferView::FITCUR
2517 | BufferView::CHANGE);
2520 lt->selection.cursor = cursor;
2523 | BufferView::FITCUR
2524 | BufferView::CHANGE);
2531 case LFUN_BREAKPARAGRAPH:
2533 LyXText * lt = bv_->getLyXText();
2536 lt->breakParagraph(bv_, 0);
2539 | BufferView::FITCUR
2540 | BufferView::CHANGE);
2541 lt->selection.cursor = lt->cursor;
2543 owner_->showState();
2547 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2549 LyXText * lt = bv_->getLyXText();
2552 lt->breakParagraph(bv_, 1);
2555 | BufferView::FITCUR
2556 | BufferView::CHANGE);
2557 lt->selection.cursor = lt->cursor;
2559 owner_->showState();
2563 case LFUN_BREAKPARAGRAPH_SKIP:
2565 // When at the beginning of a paragraph, remove
2566 // indentation and add a "defskip" at the top.
2567 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2568 LyXText * lt = bv_->getLyXText();
2570 LyXCursor cursor = lt->cursor;
2573 if (cursor.pos() == 0) {
2574 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2577 cursor.par()->params().lineTop(),
2578 cursor.par()->params().lineBottom(),
2579 cursor.par()->params().pagebreakTop(),
2580 cursor.par()->params().pagebreakBottom(),
2581 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2582 cursor.par()->params().align(),
2583 cursor.par()->params().labelWidthString(), 1);
2584 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2588 lt->breakParagraph(bv_, 0);
2589 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2594 | BufferView::FITCUR
2595 | BufferView::CHANGE);
2596 lt->selection.cursor = cursor;
2598 owner_->showState();
2602 case LFUN_PARAGRAPH_SPACING:
2604 LyXText * lt = bv_->getLyXText();
2606 Paragraph * par = lt->cursor.par();
2607 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2608 float cur_value = 1.0;
2609 if (cur_spacing == Spacing::Other) {
2610 cur_value = par->params().spacing().getValue();
2613 istringstream istr(argument.c_str());
2617 Spacing::Space new_spacing = cur_spacing;
2618 float new_value = cur_value;
2620 lyxerr << "Missing argument to `paragraph-spacing'"
2622 } else if (tmp == "single") {
2623 new_spacing = Spacing::Single;
2624 } else if (tmp == "onehalf") {
2625 new_spacing = Spacing::Onehalf;
2626 } else if (tmp == "double") {
2627 new_spacing = Spacing::Double;
2628 } else if (tmp == "other") {
2629 new_spacing = Spacing::Other;
2632 lyxerr << "new_value = " << tmpval << endl;
2635 } else if (tmp == "default") {
2636 new_spacing = Spacing::Default;
2638 lyxerr << _("Unknown spacing argument: ")
2639 << argument << endl;
2641 if (cur_spacing != new_spacing || cur_value != new_value) {
2642 par->params().spacing(Spacing(new_spacing, new_value));
2643 lt->redoParagraph(bv_);
2646 | BufferView::FITCUR
2647 | BufferView::CHANGE);
2652 case LFUN_INSET_TOGGLE:
2654 LyXText * lt = bv_->getLyXText();
2657 update(lt, BufferView::SELECT|BufferView::FITCUR);
2658 lt->toggleInset(bv_);
2659 update(lt, BufferView::SELECT|BufferView::FITCUR);
2671 InsetCommandParams p;
2672 if (action == LFUN_HTMLURL)
2673 p.setCmdName("htmlurl");
2675 p.setCmdName("url");
2676 owner_->getDialogs()->createUrl(p.getAsString());
2680 case LFUN_INSERT_URL:
2682 InsetCommandParams p;
2683 p.setFromString(argument);
2685 InsetUrl * inset = new InsetUrl(p);
2686 if (!insertInset(inset))
2689 updateInset(inset, true);
2693 case LFUN_INSET_TEXT:
2694 insertAndEditInset(new InsetText);
2697 case LFUN_INSET_ERT:
2698 insertAndEditInset(new InsetERT);
2701 case LFUN_INSET_EXTERNAL:
2702 insertAndEditInset(new InsetExternal);
2705 case LFUN_INSET_FOOTNOTE:
2706 insertAndEditInset(new InsetFoot);
2709 case LFUN_INSET_MARGINAL:
2710 insertAndEditInset(new InsetMarginal);
2713 case LFUN_INSET_MINIPAGE:
2714 insertAndEditInset(new InsetMinipage);
2717 case LFUN_INSERT_NOTE:
2718 insertAndEditInset(new InsetNote);
2721 case LFUN_INSET_FLOAT:
2722 // check if the float type exist
2723 if (floatList.typeExist(argument)) {
2724 insertAndEditInset(new InsetFloat(argument));
2726 lyxerr << "Non-existant float type: "
2727 << argument << endl;
2731 case LFUN_INSET_WIDE_FLOAT:
2733 // check if the float type exist
2734 if (floatList.typeExist(argument)) {
2735 InsetFloat * new_inset = new InsetFloat(argument);
2736 new_inset->wide(true);
2737 if (insertInset(new_inset))
2738 new_inset->edit(bv_);
2742 lyxerr << "Non-existant float type: "
2743 << argument << endl;
2750 case LFUN_INSET_LIST:
2751 insertAndEditInset(new InsetList);
2754 case LFUN_INSET_THEOREM:
2755 insertAndEditInset(new InsetTheorem);
2759 case LFUN_INSET_CAPTION:
2761 // Do we have a locking inset...
2762 if (bv_->theLockingInset()) {
2763 lyxerr << "Locking inset code: "
2764 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2765 InsetCaption * new_inset = new InsetCaption;
2766 new_inset->setOwner(bv_->theLockingInset());
2767 new_inset->setAutoBreakRows(true);
2768 new_inset->setDrawFrame(0, InsetText::LOCKED);
2769 new_inset->setFrameColor(0, LColor::captionframe);
2770 if (insertInset(new_inset))
2771 new_inset->edit(bv_);
2778 case LFUN_INSET_TABULAR:
2782 if (!argument.empty())
2783 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2784 InsetTabular * new_inset =
2785 new InsetTabular(*buffer_, r, c);
2787 bv_->getLyXText()->real_current_font.isRightToLeft();
2788 if (!open_new_inset(new_inset, rtl))
2793 // --- lyxserver commands ----------------------------
2795 case LFUN_CHARATCURSOR:
2797 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2798 if (pos < bv_->getLyXText()->cursor.par()->size())
2799 owner_->getLyXFunc()->setMessage(
2800 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2802 owner_->getLyXFunc()->setMessage("EOF");
2807 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2809 + tostr(bv_->getLyXText()->cursor.y()));
2816 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2817 lyxerr << "SETXY: Could not parse coordinates in '"
2818 << argument << std::endl;
2820 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2824 case LFUN_GETLAYOUT:
2825 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2830 LyXFont & font = bv_->getLyXText()->current_font;
2831 if (font.shape() == LyXFont::ITALIC_SHAPE)
2832 owner_->getLyXFunc()->setMessage("E");
2833 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2834 owner_->getLyXFunc()->setMessage("N");
2836 owner_->getLyXFunc()->setMessage("0");
2844 LyXFont & font = bv_->getLyXText()->current_font;
2845 if (font.latex() == LyXFont::ON)
2846 owner_->getLyXFunc()->setMessage("L");
2849 owner_->getLyXFunc()->setMessage("0");
2853 // --- accented characters ---------------------------
2856 case LFUN_CIRCUMFLEX:
2866 case LFUN_SPECIAL_CARON:
2869 case LFUN_HUNG_UMLAUT:
2872 if (argument.empty()) {
2874 owner_->getLyXFunc()->handleKeyFunc(action);
2876 owner_->getLyXFunc()->handleKeyFunc(action);
2877 owner_->getIntl()->getTrans()
2878 .TranslateAndInsert(argument[0], bv_->getLyXText());
2879 update(bv_->getLyXText(),
2881 | BufferView::FITCUR
2882 | BufferView::CHANGE);
2886 case LFUN_MATH_MACRO:
2887 mathDispatchMathMacro(bv_, argument);
2890 case LFUN_MATH_DELIM:
2891 mathDispatchMathDelim(bv_, argument);
2894 case LFUN_INSERT_MATRIX:
2895 mathDispatchInsertMatrix(bv_, argument);
2898 case LFUN_INSERT_MATH:
2899 mathDispatchInsertMath(bv_, argument);
2902 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2903 mathDispatchMathImportSelection(bv_, argument);
2906 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2907 mathDispatchMathDisplay(bv_, argument);
2910 case LFUN_MATH_MODE: // Open or create an inlined math inset
2911 mathDispatchMathMode(bv_, argument);
2914 case LFUN_CITATION_INSERT:
2916 InsetCommandParams p;
2917 p.setFromString( argument );
2919 InsetCitation * inset = new InsetCitation( p );
2920 if (!insertInset(inset))
2923 updateInset( inset, true );
2927 case LFUN_INSERT_BIBTEX:
2929 // ale970405+lasgoutt970425
2930 // The argument can be up to two tokens separated
2931 // by a space. The first one is the bibstyle.
2932 string const db = token(argument, ' ', 0);
2933 string bibstyle = token(argument, ' ', 1);
2934 if (bibstyle.empty())
2937 InsetCommandParams p( "BibTeX", db, bibstyle );
2938 InsetBibtex * inset = new InsetBibtex(p);
2940 if (insertInset(inset)) {
2941 if (argument.empty())
2948 // BibTeX data bases
2949 case LFUN_BIBDB_ADD:
2951 InsetBibtex * inset =
2952 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2954 inset->addDatabase(argument);
2959 case LFUN_BIBDB_DEL:
2961 InsetBibtex * inset =
2962 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2964 inset->delDatabase(argument);
2969 case LFUN_BIBTEX_STYLE:
2971 InsetBibtex * inset =
2972 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2974 inset->setOptions(argument);
2979 case LFUN_INDEX_CREATE:
2981 InsetCommandParams p("index");
2983 if (argument.empty()) {
2984 // Get word or selection
2985 bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
2987 string const curstring =
2988 bv_->getLyXText()->selectionAsString(buffer_);
2990 p.setContents(curstring);
2992 p.setContents(argument);
2995 owner_->getDialogs()->createIndex(p.getAsString());
2999 case LFUN_INDEX_INSERT:
3001 InsetCommandParams p;
3002 p.setFromString(argument);
3003 InsetIndex * inset = new InsetIndex(p);
3005 if (!insertInset(inset))
3008 updateInset(inset, true);
3012 case LFUN_INDEX_INSERT_LAST:
3014 // Get word or selection
3015 bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
3017 string const curstring =
3018 bv_->getLyXText()->selectionAsString(buffer_);
3020 InsetCommandParams p("index", curstring);
3021 InsetIndex * inset = new InsetIndex(p);
3023 if (!insertInset(inset))
3026 updateInset(inset, true);
3030 case LFUN_INDEX_PRINT:
3032 InsetCommandParams p("printindex");
3033 Inset * inset = new InsetPrintIndex(p);
3034 if (!insertInset(inset, "Standard"))
3039 case LFUN_PARENTINSERT:
3041 lyxerr << "arg " << argument << endl;
3042 InsetCommandParams p( "lyxparent", argument );
3043 Inset * inset = new InsetParent(p, *buffer_);
3044 if (!insertInset(inset, "Standard"))
3050 case LFUN_CHILD_INSERT:
3052 InsetInclude::Params p;
3053 p.cparams.setFromString(argument);
3054 p.masterFilename_ = buffer_->fileName();
3056 InsetInclude * inset = new InsetInclude(p);
3057 if (!insertInset(inset))
3060 updateInset(inset, true);
3061 bv_->owner()->getDialogs()->showInclude(inset);
3066 case LFUN_FLOAT_LIST:
3068 // We should check the argument for validity. (Lgb)
3069 Inset * inset = new InsetFloatList(argument);
3070 if (!insertInset(inset, "Standard"))
3075 case LFUN_SELFINSERT:
3077 if (argument.empty()) break;
3079 /* Automatically delete the currently selected
3080 * text and replace it with what is being
3081 * typed in now. Depends on lyxrc settings
3082 * "auto_region_delete", which defaults to
3085 LyXText * lt = bv_->getLyXText();
3087 if (lyxrc.auto_region_delete) {
3088 if (lt->selection.set()) {
3089 lt->cutSelection(bv_, false);
3092 | BufferView::FITCUR
3093 | BufferView::CHANGE);
3098 LyXFont const old_font(lt->real_current_font);
3100 string::const_iterator cit = argument.begin();
3101 string::const_iterator end = argument.end();
3102 for (; cit != end; ++cit) {
3103 if (greek_kb_flag) {
3104 if (!math_insert_greek(bv_, *cit))
3105 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3107 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3112 | BufferView::FITCUR
3113 | BufferView::CHANGE);
3115 lt->selection.cursor = lt->cursor;
3116 moveCursorUpdate(false);
3118 // real_current_font.number can change so we need to
3119 // update the minibuffer
3120 if (old_font != lt->real_current_font)
3121 owner_->showState();
3126 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3128 time_t now_time_t = time(NULL);
3129 struct tm * now_tm = localtime(&now_time_t);
3130 setlocale(LC_TIME, "");
3132 if (!argument.empty())
3135 arg = lyxrc.date_insert_format;
3137 int const datetmp_len =
3138 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3140 LyXText * lt = bv_->getLyXText();
3142 for (int i = 0; i < datetmp_len; i++) {
3143 lt->insertChar(bv_, datetmp[i]);
3146 | BufferView::FITCUR
3147 | BufferView::CHANGE);
3150 lt->selection.cursor = lt->cursor;
3151 moveCursorUpdate(false);
3155 case LFUN_UNKNOWN_ACTION:
3156 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3167 void BufferView::Pimpl::newline()
3170 LyXText * lt = bv_->getLyXText();
3174 | BufferView::FITCUR);
3175 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3178 | BufferView::FITCUR
3179 | BufferView::CHANGE);
3184 void BufferView::Pimpl::hfill()
3187 LyXText * lt = bv_->getLyXText();
3191 | BufferView::FITCUR);
3192 lt->insertChar(bv_, Paragraph::META_HFILL);
3195 | BufferView::FITCUR
3196 | BufferView::CHANGE);
3201 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3205 update(lt, BufferView::SELECT|BufferView::FITCUR);
3206 InsetSpecialChar * new_inset =
3207 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3208 #ifdef WITH_WARNINGS
3209 #warning Why is this code different from specialChar() below? (JMarc)
3210 // the code in specialChar is a generic version of what used to exist
3211 // for other special chars. I did not merge this case because of the
3212 // call to updateInset(), but what does it do?
3214 if (!insertInset(new_inset))
3217 updateInset(new_inset, true);
3222 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3225 LyXText * lt = bv_->getLyXText();
3228 update(lt, BufferView::SELECT|BufferView::FITCUR);
3229 InsetSpecialChar * new_inset =
3230 new InsetSpecialChar(kind);
3231 insertInset(new_inset);
3236 void BufferView::Pimpl::smartQuote()
3239 LyXText * lt = bv_->getLyXText();
3241 if (lt->cursor.pos())
3242 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3247 if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
3248 Dispatch(LFUN_SELFINSERT, "\"");
3252 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3254 if (insertInset(inset))
3261 // Open and lock an updatable inset
3262 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3264 LyXText * lt = bv_->getLyXText();
3268 if (!insertInset(new_inset)) {
3272 new_inset->edit(bv_, !behind);
3277 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3279 // if we are in a locking inset we should try to insert the
3280 // inset there otherwise this is a illegal function now
3281 if (bv_->theLockingInset()) {
3282 if (bv_->theLockingInset()->insetAllowed(inset))
3283 return bv_->theLockingInset()->insertInset(bv_, inset);
3287 // not quite sure if we want this...
3288 setCursorParUndo(bv_);
3291 beforeChange(bv_->text);
3292 if (!lout.empty()) {
3293 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3294 bv_->text->breakParagraph(bv_);
3295 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3297 if (bv_->text->cursor.par()->size()) {
3298 bv_->text->cursorLeft(bv_);
3300 bv_->text->breakParagraph(bv_);
3301 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3304 pair<bool, LyXTextClass::size_type> lres =
3305 textclasslist.NumberOfLayout(buffer_->params
3307 LyXTextClass::size_type lay;
3308 if (lres.first != false) {
3312 // layout not fount using default "Standard" (0)
3316 bv_->text->setLayout(bv_, lay);
3318 bv_->text->setParagraph(bv_, 0, 0,
3320 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3324 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3326 bv_->text->current_font.setLatex(LyXFont::OFF);
3330 bv_->text->insertInset(bv_, inset);
3331 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3338 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3343 // first check for locking insets
3344 if (bv_->theLockingInset()) {
3345 if (bv_->theLockingInset() == inset) {
3346 if (bv_->text->updateInset(bv_, inset)) {
3349 buffer_->markDirty();
3354 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3355 if (bv_->text->updateInset(bv_,
3356 bv_->theLockingInset())) {
3359 buffer_->markDirty();
3367 // then check the current buffer
3370 update(bv_->text, BufferView::UPDATE);
3371 if (bv_->text->updateInset(bv_, inset)) {
3375 | BufferView::FITCUR
3376 | BufferView::CHANGE);
3378 update(bv_->text, SELECT);
3386 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3389 if (!available()) return;
3392 beforeChange(bv_->text);
3393 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3397 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3398 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3399 if (find(codes.begin(), codes.end(), inset->lyxCode())
3402 static_cast<InsetCommand const *>(inset)->getContents();
3405 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3406 if (bv_->text->cursor.pos()
3407 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3408 LyXCursor tmp = bv_->text->cursor;
3409 bv_->text->cursor.par(bv_->text->firstParagraph());
3410 bv_->text->cursor.pos(0);
3411 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3412 bv_->text->cursor = tmp;
3413 bv_->owner()->message(_("No more insets"));
3416 bv_->owner()->message(_("No more insets"));
3419 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3420 bv_->text->selection.cursor = bv_->text->cursor;
3424 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3426 gotoInset(vector<Inset::Code>(1, code), same_content);