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/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());
261 if (bv_->theLockingInset()) {
262 bv_->theLockingInset()->fitInsetCursor(bv_);
265 ret = screen_->fitCursor(text, bv_);
268 bv_->owner()->getDialogs()->updateParagraph();
275 void BufferView::Pimpl::redoCurrentBuffer()
277 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
278 if (buffer_ && bv_->text) {
280 owner_->updateLayoutChoice();
285 int BufferView::Pimpl::resizeCurrentBuffer()
287 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
290 Paragraph * selstartpar = 0;
291 Paragraph * selendpar = 0;
292 UpdatableInset * the_locking_inset = 0;
294 Paragraph::size_type pos = 0;
295 Paragraph::size_type selstartpos = 0;
296 Paragraph::size_type selendpos = 0;
297 bool selection = false;
298 bool mark_set = false;
300 owner_->prohibitInput();
302 owner_->message(_("Formatting document..."));
305 par = bv_->text->cursor.par();
306 pos = bv_->text->cursor.pos();
307 selstartpar = bv_->text->selection.start.par();
308 selstartpos = bv_->text->selection.start.pos();
309 selendpar = bv_->text->selection.end.par();
310 selendpos = bv_->text->selection.end.pos();
311 selection = bv_->text->selection.set();
312 mark_set = bv_->text->selection.mark();
313 the_locking_inset = bv_->theLockingInset();
315 bv_->text = new LyXText(bv_);
316 bv_->text->init(bv_);
318 // See if we have a text in TextCache that fits
319 // the new buffer_ with the correct width.
320 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
322 if (lyxerr.debugging()) {
323 lyxerr << "Found a LyXText that fits:\n";
324 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
326 // Set the owner of the newly found text
327 // bv_->text->owner(bv_);
328 if (lyxerr.debugging())
329 textcache.show(lyxerr, "resizeCurrentBuffer");
331 bv_->text = new LyXText(bv_);
332 bv_->text->init(bv_);
338 bv_->text->selection.set(true);
339 /* at this point just to avoid the Delete-Empty-Paragraph
340 * Mechanism when setting the cursor */
341 bv_->text->selection.mark(mark_set);
343 bv_->text->setCursor(bv_, selstartpar, selstartpos);
344 bv_->text->selection.cursor = bv_->text->cursor;
345 bv_->text->setCursor(bv_, selendpar, selendpos);
346 bv_->text->setSelection(bv_);
347 bv_->text->setCursor(bv_, par, pos);
349 bv_->text->setCursor(bv_, par, pos);
350 bv_->text->selection.cursor = bv_->text->cursor;
351 bv_->text->selection.set(false);
353 // remake the inset locking
354 bv_->theLockingInset(the_locking_inset);
356 bv_->text->first = screen_->topCursorVisible(bv_->text);
357 buffer_->resizeInsets(bv_);
358 // this will scroll the screen such that the cursor becomes visible
363 owner_->allowInput();
365 /// clear the "Formatting Document" message
368 /// get rid of the splash screen if it's not gone already
369 owner_->getDialogs()->destroySplash();
375 void BufferView::Pimpl::updateScreen()
377 // Regenerate the screen.
378 screen_.reset(new LyXScreen(workarea_));
382 void BufferView::Pimpl::updateScrollbar()
384 /* If the text is smaller than the working area, the scrollbar
385 * maximum must be the working area height. No scrolling will
388 workarea_.setScrollbar(0, 1.0);
392 long const text_height = bv_->text->height;
394 double const lineh = bv_->text->defaultHeight();
395 double const slider_size =
396 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
398 static long old_text_height = 0;
399 static double old_lineh = 0;
400 static double old_slider_size = 0;
402 if (text_height != old_text_height) {
403 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
404 old_text_height = text_height;
406 if (lineh != old_lineh) {
407 workarea_.setScrollbarIncrements(lineh);
410 if (current_scrollbar_value != bv_->text->first
411 || slider_size != old_slider_size) {
412 current_scrollbar_value = bv_->text->first;
413 workarea_.setScrollbar(current_scrollbar_value, slider_size);
414 old_slider_size = slider_size;
419 // Callback for scrollbar slider
420 void BufferView::Pimpl::scrollCB(double value)
422 if (!buffer_) return;
424 current_scrollbar_value = long(value);
425 if (current_scrollbar_value < 0)
426 current_scrollbar_value = 0;
431 screen_->draw(bv_->text, bv_, current_scrollbar_value);
433 if (!lyxrc.cursor_follows_scrollbar) {
438 LyXText * vbt = bv_->text;
440 int const height = vbt->defaultHeight();
441 int const first = static_cast<int>((bv_->text->first + height));
442 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
444 if (vbt->cursor.y() < first)
445 vbt->setCursorFromCoordinates(bv_, 0, first);
446 else if (vbt->cursor.y() > last)
447 vbt->setCursorFromCoordinates(bv_, 0, last);
453 int BufferView::Pimpl::scrollUp(long time)
455 if (!buffer_) return 0;
456 if (!screen_.get()) return 0;
458 double value = workarea_.getScrollbarValue();
460 if (value == 0) return 0;
462 float add_value = (bv_->text->defaultHeight()
463 + float(time) * float(time) * 0.125);
465 if (add_value > workarea_.height())
466 add_value = float(workarea_.height() -
467 bv_->text->defaultHeight());
474 workarea_.setScrollbarValue(value);
481 int BufferView::Pimpl::scrollDown(long time)
483 if (!buffer_) return 0;
484 if (!screen_.get()) return 0;
486 double value = workarea_.getScrollbarValue();
487 pair<float, float> p = workarea_.getScrollbarBounds();
488 double const max = p.second;
490 if (value == max) return 0;
492 float add_value = (bv_->text->defaultHeight()
493 + float(time) * float(time) * 0.125);
495 if (add_value > workarea_.height())
496 add_value = float(workarea_.height() -
497 bv_->text->defaultHeight());
504 workarea_.setScrollbarValue(value);
511 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
513 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
517 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
519 // Only use motion with button 1
520 if (!(state & Button1MotionMask))
523 if (!buffer_ || !screen_.get()) return;
525 // Check for inset locking
526 if (bv_->theLockingInset()) {
527 LyXCursor cursor = bv_->text->cursor;
528 LyXFont font = bv_->text->getFont(buffer_,
529 cursor.par(), cursor.pos());
530 int width = bv_->theLockingInset()->width(bv_, font);
531 int inset_x = font.isVisibleRightToLeft()
532 ? cursor.x() - width : cursor.x();
533 int start_x = inset_x + bv_->theLockingInset()->scroll();
534 bv_->theLockingInset()->
535 insetMotionNotify(bv_,
537 y - cursor.y() + bv_->text->first,
542 /* The test for not selection possible is needed, that only motion
543 events are used, where the bottom press event was on
544 the drawing area too */
545 if (!selection_possible)
548 screen_->hideCursor();
550 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
552 if (!bv_->text->selection.set())
553 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
555 bv_->text->setSelection(bv_);
556 screen_->toggleToggle(bv_->text, bv_);
557 fitCursor(bv_->text);
558 screen_->showCursor(bv_->text, bv_);
562 // Single-click on work area
563 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
566 if (!buffer_ || !screen_.get()) return;
568 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
570 // ok ok, this is a hack.
571 if (button == 4 || button == 5) {
574 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
577 scrollDown(lyxrc.wheel_jump);
582 if (bv_->theLockingInset()) {
583 // We are in inset locking mode
585 /* Check whether the inset was hit. If not reset mode,
586 otherwise give the event to the inset */
587 if (inset_hit == bv_->theLockingInset()) {
588 bv_->theLockingInset()->
589 insetButtonPress(bv_,
594 bv_->unlockInset(bv_->theLockingInset());
599 selection_possible = true;
600 screen_->hideCursor();
602 int const screen_first = bv_->text->first;
604 // Middle button press pastes if we have a selection
605 bool paste_internally = false;
607 && bv_->text->selection.set()) {
608 owner_->getLyXFunc()->dispatch(LFUN_COPY);
609 paste_internally = true;
612 // Clear the selection
613 screen_->toggleSelection(bv_->text, bv_);
614 bv_->text->clearSelection(bv_);
615 bv_->text->fullRebreak(bv_);
616 screen_->update(bv_->text, bv_);
619 // Single left click in math inset?
620 if ((inset_hit != 0) &&
621 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
622 // Highly editable inset, like math
623 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
624 selection_possible = false;
625 owner_->updateLayoutChoice();
626 owner_->message(inset->editMessage());
627 inset->insetButtonPress(bv_, xpos, ypos, button);
628 inset->edit(bv_, xpos, ypos, button);
632 // Right click on a footnote flag opens float menu
634 selection_possible = false;
638 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
639 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
641 bv_->text->selection.cursor = bv_->text->cursor;
642 bv_->text->cursor.x_fix(bv_->text->cursor.x());
644 owner_->updateLayoutChoice();
645 if (fitCursor(bv_->text)) {
646 selection_possible = false;
649 // Insert primary selection with middle mouse
650 // if there is a local selection in the current buffer,
653 if (paste_internally)
654 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
656 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
658 selection_possible = false;
664 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
670 LyXText * text = bv_->getLyXText();
672 if (text->bv_owner && bv_->theLockingInset())
675 if (screen_.get() && button == 1) {
676 if (text->bv_owner) {
677 screen_->hideCursor();
678 screen_->toggleSelection(text, bv_);
679 text->selectWord(bv_);
680 screen_->toggleSelection(text, bv_, false);
682 text->selectWord(bv_);
684 /* This will fit the cursor on the screen
686 update(text, BufferView::SELECT|BufferView::FITCUR);
691 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
697 LyXText * text = bv_->getLyXText();
699 if (text->bv_owner && bv_->theLockingInset())
702 if (screen_.get() && (button == 1)) {
703 screen_->hideCursor();
704 screen_->toggleSelection(text, bv_);
705 text->cursorHome(bv_);
706 text->selection.cursor = text->cursor;
707 text->cursorEnd(bv_);
708 text->setSelection(bv_);
709 screen_->toggleSelection(text, bv_, false);
710 /* This will fit the cursor on the screen
712 update(text, BufferView::SELECT|BufferView::FITCUR);
717 void BufferView::Pimpl::enterView()
719 if (active() && available()) {
720 SetXtermCursor(workarea_.getWin());
721 using_xterm_cursor = true;
726 void BufferView::Pimpl::leaveView()
728 if (using_xterm_cursor) {
729 XUndefineCursor(fl_get_display(), workarea_.getWin());
730 using_xterm_cursor = false;
735 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
738 if (!buffer_ || !screen_.get()) return;
740 // If we hit an inset, we have the inset coordinates in these
741 // and inset_hit points to the inset. If we do not hit an
742 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
743 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
745 if (bv_->theLockingInset()) {
746 // We are in inset locking mode.
748 /* LyX does a kind of work-area grabbing for insets.
749 Only a ButtonPress Event outside the inset will
750 force a insetUnlock. */
751 bv_->theLockingInset()->
752 insetButtonRelease(bv_, x, y, button);
756 selection_possible = false;
764 // Did we hit an editable inset?
766 // Inset like error, notes and figures
767 selection_possible = false;
769 // CHECK fix this proper in 0.13
771 // Following a ref shouldn't issue
772 // a push on the undo-stack
773 // anylonger, now that we have
774 // keybindings for following
775 // references and returning from
776 // references. IMHO though, it
777 // should be the inset's own business
778 // to push or not push on the undo
779 // stack. They don't *have* to
780 // alter the document...
782 // ...or maybe the SetCursorParUndo()
783 // below isn't necessary at all anylonger?
784 if (inset_hit->lyxCode() == Inset::REF_CODE) {
785 setCursorParUndo(bv_);
788 owner_->message(inset_hit->editMessage());
790 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
791 // Highly editable inset, like math
792 UpdatableInset *inset = (UpdatableInset *)inset_hit;
793 inset->insetButtonRelease(bv_, x, y, button);
795 inset_hit->insetButtonRelease(bv_, x, y, button);
796 inset_hit->edit(bv_, x, y, button);
801 // check whether we want to open a float
805 if (bv_->text->cursor.pos() <
806 bv_->text->cursor.par()->size()) {
807 c = bv_->text->cursor.par()->
808 getChar(bv_->text->cursor.pos());
810 if (bv_->text->cursor.pos() - 1 >= 0) {
811 c = bv_->text->cursor.par()->
812 getChar(bv_->text->cursor.pos() - 1);
815 selection_possible = false;
820 // Maybe we want to edit a bibitem ale970302
821 if (bv_->text->cursor.par()->bibkey && x < 20 +
822 bibitemMaxWidth(bv_, textclasslist.
824 params.textclass).defaultfont())) {
825 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
833 * Returns an inset if inset was hit. 0 otherwise.
834 * If hit, the coordinates are changed relative to the inset.
835 * Otherwise coordinates are not changed, and false is returned.
837 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
838 unsigned int /* button */)
843 int y_tmp = y + text->first;
846 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
847 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
850 if (cursor.pos() < cursor.par()->size()
851 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
852 && cursor.par()->getInset(cursor.pos())
853 && cursor.par()->getInset(cursor.pos())->editable()) {
855 // Check whether the inset really was hit
856 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
857 LyXFont font = text->getFont(buffer_,
858 cursor.par(), cursor.pos());
859 int const width = tmpinset->width(bv_, font);
860 int const inset_x = font.isVisibleRightToLeft()
861 ? cursor.x() - width : cursor.x();
862 int const start_x = inset_x + tmpinset->scroll();
863 int const end_x = inset_x + width;
865 if (x > start_x && x < end_x
866 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
867 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
868 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
870 // The origin of an inset is on the baseline
871 y = y_tmp - (text->cursor.y());
876 if ((cursor.pos() - 1 >= 0) &&
877 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
878 (cursor.par()->getInset(cursor.pos() - 1)) &&
879 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
880 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
881 LyXFont font = text->getFont(buffer_, cursor.par(),
883 int const width = tmpinset->width(bv_, font);
884 int const inset_x = font.isVisibleRightToLeft()
885 ? cursor.x() : cursor.x() - width;
886 int const start_x = inset_x + tmpinset->scroll();
887 int const end_x = inset_x + width;
889 if (x > start_x && x < end_x
890 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
891 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
893 if (move_cursor && (tmpinset != bv_->theLockingInset()))
895 text->setCursor(bv_, cursor.par(),
896 cursor.pos() - 1, true);
898 // The origin of an inset is on the baseline
899 y = y_tmp - (text->cursor.y());
907 void BufferView::Pimpl::workAreaExpose()
909 static int work_area_width;
910 static unsigned int work_area_height;
912 bool const widthChange = workarea_.workWidth() != work_area_width;
913 bool const heightChange = workarea_.height() != work_area_height;
915 // update from work area
916 work_area_width = workarea_.workWidth();
917 work_area_height = workarea_.height();
920 // The visible LyXView need a resize
923 // Remove all texts from the textcache
924 // This is not _really_ what we want to do. What
925 // we really want to do is to delete in textcache
926 // that does not have a BufferView with matching
927 // width, but as long as we have only one BufferView
928 // deleting all gives the same result.
929 if (lyxerr.debugging())
930 textcache.show(lyxerr, "Expose delete all");
932 } else if (heightChange) {
933 // Rebuild image of current screen
935 // fitCursor() ensures we don't jump back
936 // to the start of the document on vertical
938 fitCursor(bv_->text);
940 // The main window size has changed, repaint most stuff
942 } else if (screen_.get())
943 screen_->redraw(bv_->text, bv_);
945 // Grey box when we don't have a buffer
949 // always make sure that the scrollbar is sane.
951 owner_->updateLayoutChoice();
956 void BufferView::Pimpl::update()
959 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
961 screen_->update(bv_->text, bv_);
965 // Values used when calling update:
967 // -2 - update, move sel_cursor if selection, fitcursor
968 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
969 // 0 - update, move sel_cursor if selection, fitcursor
970 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
971 // 3 - update, move sel_cursor if selection
974 // a simple redraw of the parts that need refresh
976 // move sel_cursor if selection -
977 // the text's sel_cursor is moved if there is selection is progress
980 // fitCursor() is called and the scrollbar updated
983 // the buffer is marked dirty.
992 // UPDATE_ONLY = UPDATE;
993 // UPDATE_SELECT = UPDATE | SELECT;
994 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
995 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
997 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
998 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
999 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1000 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1001 // update(3) -> update(1) -> update(1) -> update(SELECT)
1003 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1005 owner_->updateLayoutChoice();
1007 if (!text->selection.set() && (f & SELECT)) {
1008 text->selection.cursor = text->cursor;
1011 text->fullRebreak(bv_);
1013 if (text->inset_owner) {
1014 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1015 updateInset(text->inset_owner, true);
1025 buffer_->markDirty();
1030 // Callback for cursor timer
1031 void BufferView::Pimpl::cursorToggle()
1033 // Quite a nice place for asyncron Inset updating, isn't it?
1034 // Actually no! This is run even if no buffer exist... so (Lgb)
1036 cursor_timeout.restart();
1041 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1042 if (pid == -1) // error find out what is wrong
1043 ; // ignore it for now.
1045 sigchldchecker(pid, &status);
1047 updatelist.update(bv_);
1049 if (!screen_.get()) {
1050 cursor_timeout.restart();
1054 if (!bv_->theLockingInset()) {
1055 screen_->cursorToggle(bv_->text, bv_);
1057 bv_->theLockingInset()->toggleInsetCursor(bv_);
1060 cursor_timeout.restart();
1064 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1066 if (!text->cursor.row()->previous())
1069 int y = text->first;
1070 if (text->inset_owner)
1071 y += bv_->text->first;
1072 Row * cursorrow = text->cursor.row();
1073 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1075 // This is to allow jumping over large insets
1076 if ((cursorrow == text->cursor.row()))
1077 text->cursorUp(bv_);
1079 if (text->inset_owner ||
1080 text->cursor.row()->height() < workarea_.height())
1081 screen_->draw(bv_->text, bv_,
1083 - text->cursor.row()->baseline()
1084 + text->cursor.row()->height()
1085 - workarea_.height() + 1 );
1090 void BufferView::Pimpl::cursorNext(LyXText * text)
1092 if (!text->cursor.row()->next())
1095 int y = text->first + workarea_.height();
1096 // if (text->inset_owner)
1097 // y += bv_->text->first;
1098 text->getRowNearY(y);
1100 Row * cursorrow = text->cursor.row();
1101 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1103 // This is to allow jumping over large insets
1104 if ((cursorrow == bv_->text->cursor.row()))
1105 text->cursorDown(bv_);
1107 if (text->inset_owner ||
1108 text->cursor.row()->height() < workarea_.height())
1109 screen_->draw(bv_->text, bv_, text->cursor.y() -
1110 text->cursor.row()->baseline());
1115 bool BufferView::Pimpl::available() const
1117 if (buffer_ && bv_->text) return true;
1122 void BufferView::Pimpl::beforeChange(LyXText * text)
1125 text->clearSelection(bv_);
1129 void BufferView::Pimpl::savePosition(unsigned int i)
1131 if (i >= saved_positions_num)
1133 saved_positions[i] = Position(buffer_->fileName(),
1134 bv_->text->cursor.par()->id(),
1135 bv_->text->cursor.pos());
1138 str << _("Saved bookmark") << ' ' << i;
1139 owner_->message(str.str().c_str());
1144 void BufferView::Pimpl::restorePosition(unsigned int i)
1146 if (i >= saved_positions_num)
1149 string const fname = saved_positions[i].filename;
1151 beforeChange(bv_->text);
1153 if (fname != buffer_->fileName()) {
1154 Buffer * b = bufferlist.exists(fname) ?
1155 bufferlist.getBuffer(fname) :
1156 bufferlist.loadLyXFile(fname); // don't ask, just load it
1157 if (b != 0 ) buffer(b);
1160 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1164 bv_->text->setCursor(bv_, par,
1165 min(par->size(), saved_positions[i].par_pos));
1167 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1170 str << _("Moved to bookmark") << ' ' << i;
1171 owner_->message(str.str().c_str());
1176 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1178 if (i >= saved_positions_num)
1181 return !saved_positions[i].filename.empty();
1185 void BufferView::Pimpl::setState()
1187 if (!lyxrc.rtl_support)
1190 LyXText * text = bv_->getLyXText();
1191 if (text->real_current_font.isRightToLeft()
1194 text->real_current_font.latex() != LyXFont::ON
1197 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1198 owner_->getIntl()->KeyMapSec();
1200 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1201 owner_->getIntl()->KeyMapPrim();
1206 void BufferView::Pimpl::insetSleep()
1208 if (bv_->theLockingInset() && !inset_slept) {
1209 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1210 bv_->theLockingInset()->insetUnlock(bv_);
1216 void BufferView::Pimpl::insetWakeup()
1218 if (bv_->theLockingInset() && inset_slept) {
1219 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1220 inset_slept = false;
1225 void BufferView::Pimpl::insetUnlock()
1227 if (bv_->theLockingInset()) {
1229 bv_->theLockingInset()->insetUnlock(bv_);
1230 bv_->theLockingInset(0);
1232 inset_slept = false;
1237 bool BufferView::Pimpl::focus() const
1239 return workarea_.hasFocus();
1243 void BufferView::Pimpl::focus(bool f)
1245 if (f) workarea_.setFocus();
1249 bool BufferView::Pimpl::active() const
1251 return workarea_.active();
1255 bool BufferView::Pimpl::belowMouse() const
1257 return workarea_.belowMouse();
1261 void BufferView::Pimpl::showCursor()
1263 if (screen_.get()) {
1264 if (bv_->theLockingInset())
1265 bv_->theLockingInset()->showInsetCursor(bv_);
1267 screen_->showCursor(bv_->text, bv_);
1272 void BufferView::Pimpl::hideCursor()
1274 if (screen_.get()) {
1275 if (!bv_->theLockingInset())
1276 // bv_->theLockingInset()->hideInsetCursor(bv_);
1278 screen_->hideCursor();
1283 void BufferView::Pimpl::toggleSelection(bool b)
1285 if (screen_.get()) {
1286 if (bv_->theLockingInset())
1287 bv_->theLockingInset()->toggleSelection(bv_, b);
1288 screen_->toggleSelection(bv_->text, bv_, b);
1293 void BufferView::Pimpl::toggleToggle()
1296 screen_->toggleToggle(bv_->text, bv_);
1300 void BufferView::Pimpl::center()
1302 beforeChange(bv_->text);
1303 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1304 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1306 screen_->draw(bv_->text, bv_, 0);
1308 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1313 void BufferView::Pimpl::pasteClipboard(bool asPara)
1315 if (!buffer_) return;
1317 screen_->hideCursor();
1318 beforeChange(bv_->text);
1320 string const clip(workarea_.getClipboard());
1322 if (clip.empty()) return;
1325 bv_->text->insertStringAsParagraphs(bv_, clip);
1327 bv_->text->insertStringAsLines(bv_, clip);
1329 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1333 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1335 workarea_.putClipboard(stuff);
1340 * Dispatch functions for actions which can be valid for BufferView->text
1341 * and/or InsetText->text!!!
1346 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1348 LyXText * lt = bv_->getLyXText();
1350 if (selecting || lt->selection.mark()) {
1351 lt->setSelection(bv_);
1355 update(lt, BufferView::SELECT|BufferView::FITCUR);
1358 /* ---> Everytime the cursor is moved, show the current font state. */
1359 // should this too me moved out of this func?
1360 //owner->showState();
1365 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1367 LyXCursor cursor = bv_->getLyXText()->cursor;
1368 Buffer::inset_iterator it =
1369 find_if(Buffer::inset_iterator(
1370 cursor.par(), cursor.pos()),
1371 buffer_->inset_iterator_end(),
1372 lyx::compare_memfun(&Inset::lyxCode, code));
1373 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1377 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1379 string filename = filen;
1381 if (filename.empty()) {
1382 // Launch a file browser
1383 string initpath = lyxrc.document_path;
1386 string const trypath = owner_->buffer()->filepath;
1387 // If directory is writeable, use this as default.
1388 if (IsDirWriteable(trypath) == 1)
1392 FileDialog fileDlg(bv_->owner(),
1393 _("Select LyX document to insert"),
1395 make_pair(string(_("Documents")),
1396 string(lyxrc.document_path)),
1397 make_pair(string(_("Examples")),
1398 string(AddPath(system_lyxdir, "examples"))));
1400 FileDialog::Result result =
1401 fileDlg.Select(initpath,
1402 _("*.lyx| LyX Documents (*.lyx)"));
1404 if (result.first == FileDialog::Later)
1407 filename = result.second;
1409 // check selected filename
1410 if (filename.empty()) {
1411 owner_->message(_("Canceled."));
1416 // get absolute path of file and add ".lyx" to the filename if
1418 filename = FileSearch(string(), filename, "lyx");
1420 string const disp_fn(MakeDisplayPath(filename));
1423 s1 << _("Inserting document") << ' '
1424 << disp_fn << " ...";
1425 owner_->message(s1.str().c_str());
1426 bool const res = bv_->insertLyXFile(filename);
1429 str << _("Document") << ' ' << disp_fn
1430 << ' ' << _("inserted.");
1431 owner_->message(str.str().c_str());
1434 str << _("Could not insert document") << ' '
1436 owner_->message(str.str().c_str());
1441 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1443 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1444 << action <<"] arg[" << argument << "]" << endl;
1447 // --- Misc -------------------------------------------
1451 LyXText * lt = bv_->getLyXText();
1452 lt->toggleAppendix(bv_);
1455 | BufferView::FITCUR
1456 | BufferView::CHANGE);
1461 case LFUN_TOC_INSERT:
1463 InsetCommandParams p;
1464 p.setCmdName("tableofcontents");
1465 Inset * inset = new InsetTOC(p);
1466 if (!insertInset(inset, "Standard"))
1471 case LFUN_TABULAR_FEATURE:
1472 case LFUN_SCROLL_INSET:
1473 // this is not handled here as this funktion is only aktive
1474 // if we have a locking_inset and that one is (or contains)
1478 case LFUN_INSET_GRAPHICS:
1480 Inset * new_inset = new InsetGraphics;
1481 if (!insertInset(new_inset)) {
1484 // this is need because you don't use a inset->Edit()
1485 updateInset(new_inset, true);
1486 new_inset->edit(bv_);
1496 case LFUN_PASTESELECTION:
1498 bool asPara = false;
1499 if (argument == "paragraph") asPara = true;
1500 pasteClipboard(asPara);
1512 case LFUN_LAYOUT_COPY:
1513 bv_->copyEnvironment();
1516 case LFUN_LAYOUT_PASTE:
1517 bv_->pasteEnvironment();
1521 case LFUN_GOTOERROR:
1522 gotoInset(Inset::ERROR_CODE, false);
1526 gotoInset(Inset::IGNORE_CODE, false);
1529 case LFUN_REFERENCE_GOTO:
1531 vector<Inset::Code> tmp;
1532 tmp.push_back(Inset::LABEL_CODE);
1533 tmp.push_back(Inset::REF_CODE);
1534 gotoInset(tmp, true);
1538 case LFUN_HYPHENATION:
1539 specialChar(InsetSpecialChar::HYPHENATION);
1542 case LFUN_LIGATURE_BREAK:
1543 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1547 specialChar(InsetSpecialChar::LDOTS);
1550 case LFUN_END_OF_SENTENCE:
1551 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1554 case LFUN_MENU_SEPARATOR:
1555 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1563 changeDepth(bv_, bv_->getLyXText(), 0);
1566 case LFUN_DEPTH_MIN:
1567 changeDepth(bv_, bv_->getLyXText(), -1);
1570 case LFUN_DEPTH_PLUS:
1571 changeDepth(bv_, bv_->getLyXText(), 1);
1575 owner_->getDialogs()->setUserFreeFont();
1582 owner_->showState();
1586 case LFUN_FILE_INSERT:
1588 MenuInsertLyXFile(argument);
1592 case LFUN_FILE_INSERT_ASCII_PARA:
1593 InsertAsciiFile(bv_, argument, true);
1596 case LFUN_FILE_INSERT_ASCII:
1597 InsertAsciiFile(bv_, argument, false);
1602 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1603 << argument << endl;
1605 // Derive layout number from given argument (string)
1606 // and current buffer's textclass (number). */
1607 LyXTextClassList::ClassList::size_type tclass =
1608 buffer_->params.textclass;
1609 pair <bool, LyXTextClass::size_type> layout =
1610 textclasslist.NumberOfLayout(tclass, argument);
1612 // If the entry is obsolete, use the new one instead.
1614 string obs = textclasslist.Style(tclass,layout.second)
1618 textclasslist.NumberOfLayout(tclass, obs);
1621 // see if we found the layout number:
1622 if (!layout.first) {
1623 owner_->getLyXFunc()->setErrorMessage(
1624 string(N_("Layout ")) + argument +
1629 if (current_layout != layout.second) {
1630 LyXText * lt = bv_->getLyXText();
1632 current_layout = layout.second;
1635 | BufferView::FITCUR);
1636 lt->setLayout(bv_, layout.second);
1637 owner_->setLayout(layout.second);
1640 | BufferView::FITCUR
1641 | BufferView::CHANGE);
1648 Lang(bv_, argument);
1650 owner_->showState();
1655 owner_->showState();
1660 owner_->showState();
1665 owner_->showState();
1670 owner_->showState();
1675 owner_->showState();
1680 owner_->showState();
1685 owner_->showState();
1688 case LFUN_UNDERLINE:
1690 owner_->showState();
1693 case LFUN_FONT_SIZE:
1694 FontSize(bv_, argument);
1695 owner_->showState();
1698 case LFUN_FONT_STATE:
1699 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1702 case LFUN_UPCASE_WORD:
1704 LyXText * lt = bv_->getLyXText();
1708 | BufferView::FITCUR);
1709 lt->changeCase(bv_, LyXText::text_uppercase);
1710 if (lt->inset_owner)
1711 updateInset(lt->inset_owner, true);
1714 | BufferView::FITCUR
1715 | BufferView::CHANGE);
1719 case LFUN_LOWCASE_WORD:
1721 LyXText * lt = bv_->getLyXText();
1723 update(lt, BufferView::SELECT|BufferView::FITCUR);
1724 lt->changeCase(bv_, LyXText::text_lowercase);
1725 if (lt->inset_owner)
1726 updateInset(lt->inset_owner, true);
1729 | BufferView::FITCUR
1730 | BufferView::CHANGE);
1734 case LFUN_CAPITALIZE_WORD:
1736 LyXText * lt = bv_->getLyXText();
1738 update(lt, BufferView::SELECT|BufferView::FITCUR);
1739 lt->changeCase(bv_, LyXText::text_capitalization);
1740 if (lt->inset_owner)
1741 updateInset(lt->inset_owner, true);
1744 | BufferView::FITCUR
1745 | BufferView::CHANGE);
1749 case LFUN_TRANSPOSE_CHARS:
1751 LyXText * lt = bv_->getLyXText();
1753 update(lt, BufferView::SELECT|BufferView::FITCUR);
1754 lt->transposeChars(*bv_);
1755 if (lt->inset_owner)
1756 updateInset(lt->inset_owner, true);
1759 | BufferView::FITCUR
1760 | BufferView::CHANGE);
1765 case LFUN_INSERT_LABEL:
1766 MenuInsertLabel(bv_, argument);
1769 case LFUN_REF_INSERT:
1770 if (argument.empty()) {
1771 InsetCommandParams p("ref");
1772 owner_->getDialogs()->createRef(p.getAsString());
1774 InsetCommandParams p;
1775 p.setFromString(argument);
1777 InsetRef * inset = new InsetRef(p, *buffer_);
1778 if (!insertInset(inset))
1781 updateInset(inset, true);
1785 case LFUN_BOOKMARK_SAVE:
1786 savePosition(strToUnsignedInt(argument));
1789 case LFUN_BOOKMARK_GOTO:
1790 restorePosition(strToUnsignedInt(argument));
1795 string label(argument);
1796 if (label.empty()) {
1798 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1800 label = inset->getContents();
1805 if (!label.empty()) {
1806 //bv_->savePosition(0);
1807 if (!bv_->gotoLabel(label))
1808 WriteAlert(_("Error"),
1809 _("Couldn't find this label"),
1810 _("in current document."));
1815 // --- Cursor Movements -----------------------------
1818 LyXText * lt = bv_->getLyXText();
1820 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1821 if (!lt->selection.mark())
1823 update(lt, BufferView::SELECT|BufferView::FITCUR);
1825 lt->cursorLeft(bv_, false);
1826 if (lt->cursor.pos() < lt->cursor.par()->size()
1827 && lt->cursor.par()->getChar(lt->cursor.pos())
1828 == Paragraph::META_INSET
1829 && lt->cursor.par()->getInset(lt->cursor.pos())
1830 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1831 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1832 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1834 tmpinset->edit(bv_, false);
1836 tmpinset->edit(bv_);
1840 lt->cursorRight(bv_, false);
1842 moveCursorUpdate(false);
1843 owner_->showState();
1849 // This is soooo ugly. Isn`t it possible to make
1850 // it simpler? (Lgb)
1851 LyXText * lt = bv_->getLyXText();
1852 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1853 if (!lt->selection.mark())
1855 update(lt, BufferView::SELECT|BufferView::FITCUR);
1856 LyXCursor const cur = lt->cursor;
1858 lt->cursorLeft(bv_, false);
1859 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1860 lt->cursor.pos() < lt->cursor.par()->size() &&
1861 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1862 Paragraph::META_INSET) &&
1863 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1864 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1865 == Inset::HIGHLY_EDITABLE))
1867 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1868 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1870 tmpinset->edit(bv_);
1872 tmpinset->edit(bv_, false);
1876 lt->cursorRight(bv_, false);
1879 moveCursorUpdate(false);
1880 owner_->showState();
1886 LyXText * lt = bv_->getLyXText();
1888 if (!lt->selection.mark())
1890 update(lt, BufferView::UPDATE);
1893 moveCursorUpdate(false);
1894 owner_->showState();
1900 LyXText * lt = bv_->getLyXText();
1902 if (!lt->selection.mark())
1904 update(lt, BufferView::UPDATE);
1905 lt->cursorDown(bv_);
1907 moveCursorUpdate(false);
1908 owner_->showState();
1912 case LFUN_UP_PARAGRAPH:
1914 LyXText * lt = bv_->getLyXText();
1916 if (!lt->selection.mark())
1918 update(lt, BufferView::UPDATE);
1919 lt->cursorUpParagraph(bv_);
1921 moveCursorUpdate(false);
1922 owner_->showState();
1926 case LFUN_DOWN_PARAGRAPH:
1928 LyXText * lt = bv_->getLyXText();
1930 if (!lt->selection.mark())
1932 update(lt, BufferView::UPDATE);
1933 lt->cursorDownParagraph(bv_);
1935 moveCursorUpdate(false);
1936 owner_->showState();
1942 LyXText * lt = bv_->getLyXText();
1944 if (!lt->selection.mark())
1946 update(lt, BufferView::UPDATE);
1949 moveCursorUpdate(false);
1950 owner_->showState();
1956 LyXText * lt = bv_->getLyXText();
1958 if (!lt->selection.mark())
1960 update(lt, BufferView::UPDATE);
1963 moveCursorUpdate(false);
1964 owner_->showState();
1970 LyXText * lt = bv_->getLyXText();
1972 if (!lt->selection.mark())
1974 update(lt, BufferView::SELECT|BufferView::FITCUR);
1975 lt->cursorHome(bv_);
1977 moveCursorUpdate(false);
1978 owner_->showState();
1984 LyXText * lt = bv_->getLyXText();
1986 if (!lt->selection.mark())
1989 BufferView::SELECT|BufferView::FITCUR);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1997 case LFUN_SHIFT_TAB:
2000 LyXText * lt = bv_->getLyXText();
2002 if (!lt->selection.mark())
2005 BufferView::SELECT|BufferView::FITCUR);
2008 moveCursorUpdate(false);
2009 owner_->showState();
2013 case LFUN_WORDRIGHT:
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2019 update(lt, BufferView::SELECT|BufferView::FITCUR);
2020 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2021 lt->cursorLeftOneWord(bv_);
2023 lt->cursorRightOneWord(bv_);
2025 moveCursorUpdate(false);
2026 owner_->showState();
2032 LyXText * lt = bv_->getLyXText();
2034 if (!lt->selection.mark())
2036 update(lt, BufferView::SELECT|BufferView::FITCUR);
2037 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2038 lt->cursorRightOneWord(bv_);
2040 lt->cursorLeftOneWord(bv_);
2042 moveCursorUpdate(false);
2043 owner_->showState();
2047 case LFUN_BEGINNINGBUF:
2049 LyXText * lt = bv_->getLyXText();
2051 if (!lt->selection.mark())
2054 BufferView::SELECT|BufferView::FITCUR);
2057 moveCursorUpdate(false);
2058 owner_->showState();
2064 LyXText * lt = bv_->getLyXText();
2066 if (!lt->selection.mark())
2069 BufferView::SELECT|BufferView::FITCUR);
2070 lt->cursorBottom(bv_);
2072 moveCursorUpdate(false);
2073 owner_->showState();
2077 /* cursor selection ---------------------------- */
2080 LyXText * lt = bv_->getLyXText();
2083 BufferView::SELECT|BufferView::FITCUR);
2084 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2085 lt->cursorLeft(bv_);
2087 lt->cursorRight(bv_);
2089 moveCursorUpdate(true);
2090 owner_->showState();
2096 LyXText * lt = bv_->getLyXText();
2099 BufferView::SELECT|BufferView::FITCUR);
2100 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2101 lt->cursorRight(bv_);
2103 lt->cursorLeft(bv_);
2105 moveCursorUpdate(true);
2106 owner_->showState();
2112 LyXText * lt = bv_->getLyXText();
2115 BufferView::SELECT|BufferView::FITCUR);
2118 moveCursorUpdate(true);
2119 owner_->showState();
2125 LyXText * lt = bv_->getLyXText();
2128 BufferView::SELECT|BufferView::FITCUR);
2129 lt->cursorDown(bv_);
2131 moveCursorUpdate(true);
2132 owner_->showState();
2136 case LFUN_UP_PARAGRAPHSEL:
2138 LyXText * lt = bv_->getLyXText();
2141 BufferView::SELECT|BufferView::FITCUR);
2142 lt->cursorUpParagraph(bv_);
2144 moveCursorUpdate(true);
2145 owner_->showState();
2149 case LFUN_DOWN_PARAGRAPHSEL:
2151 LyXText * lt = bv_->getLyXText();
2154 BufferView::SELECT|BufferView::FITCUR);
2155 lt->cursorDownParagraph(bv_);
2157 moveCursorUpdate(true);
2158 owner_->showState();
2164 LyXText * lt = bv_->getLyXText();
2166 update(lt, BufferView::SELECT|BufferView::FITCUR);
2169 moveCursorUpdate(true);
2170 owner_->showState();
2176 LyXText * lt = bv_->getLyXText();
2178 update(lt, BufferView::SELECT|BufferView::FITCUR);
2181 moveCursorUpdate(true);
2182 owner_->showState();
2188 LyXText * lt = bv_->getLyXText();
2190 update(lt, BufferView::SELECT|BufferView::FITCUR);
2191 lt->cursorHome(bv_);
2193 moveCursorUpdate(true);
2194 owner_->showState();
2200 LyXText * lt = bv_->getLyXText();
2202 update(lt, BufferView::SELECT|BufferView::FITCUR);
2205 moveCursorUpdate(true);
2206 owner_->showState();
2210 case LFUN_WORDRIGHTSEL:
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2215 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2216 lt->cursorLeftOneWord(bv_);
2218 lt->cursorRightOneWord(bv_);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2225 case LFUN_WORDLEFTSEL:
2227 LyXText * lt = bv_->getLyXText();
2229 update(lt, BufferView::SELECT|BufferView::FITCUR);
2230 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2231 lt->cursorRightOneWord(bv_);
2233 lt->cursorLeftOneWord(bv_);
2235 moveCursorUpdate(true);
2236 owner_->showState();
2240 case LFUN_BEGINNINGBUFSEL:
2242 LyXText * lt = bv_->getLyXText();
2244 if (lt->inset_owner)
2246 update(lt, BufferView::SELECT|BufferView::FITCUR);
2249 moveCursorUpdate(true);
2250 owner_->showState();
2254 case LFUN_ENDBUFSEL:
2256 LyXText * lt = bv_->getLyXText();
2258 if (lt->inset_owner)
2261 BufferView::SELECT|BufferView::FITCUR);
2262 lt->cursorBottom(bv_);
2264 moveCursorUpdate(true);
2265 owner_->showState();
2269 // --- text changing commands ------------------------
2270 case LFUN_BREAKLINE:
2272 LyXText * lt = bv_->getLyXText();
2275 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2278 | BufferView::FITCUR
2279 | BufferView::CHANGE);
2280 moveCursorUpdate(false);
2284 case LFUN_PROTECTEDSPACE:
2286 LyXText * lt = bv_->getLyXText();
2288 LyXLayout const & style = textclasslist
2289 .Style(buffer_->params.textclass,
2290 lt->cursor.par()->getLayout());
2292 if (style.free_spacing) {
2293 lt->insertChar(bv_, ' ');
2296 | BufferView::FITCUR
2297 | BufferView::CHANGE);
2301 moveCursorUpdate(false);
2307 LyXText * lt = bv_->getLyXText();
2309 if (lt->selection.mark()) {
2313 | BufferView::FITCUR);
2314 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2317 lt->selection.mark(true);
2320 | BufferView::FITCUR);
2321 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2323 lt->selection.cursor = lt->cursor;
2329 LyXText * lt = bv_->getLyXText();
2331 if (!lt->selection.set()) {
2333 lt->selection.cursor = lt->cursor;
2336 | BufferView::FITCUR
2337 | BufferView::CHANGE);
2338 // It is possible to make it a lot faster still
2339 // just comment out the line below...
2344 moveCursorUpdate(false);
2345 owner_->showState();
2350 case LFUN_DELETE_SKIP:
2352 LyXText * lt = bv_->getLyXText();
2354 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2356 LyXCursor cursor = lt->cursor;
2358 if (!lt->selection.set()) {
2359 if (cursor.pos() == cursor.par()->size()) {
2360 lt->cursorRight(bv_);
2361 cursor = lt->cursor;
2362 if (cursor.pos() == 0
2363 && !(cursor.par()->params().spaceTop()
2364 == VSpace (VSpace::NONE))) {
2367 cursor.par()->params().lineTop(),
2368 cursor.par()->params().lineBottom(),
2369 cursor.par()->params().pagebreakTop(),
2370 cursor.par()->params().pagebreakBottom(),
2371 VSpace(VSpace::NONE),
2372 cursor.par()->params().spaceBottom(),
2373 cursor.par()->params().align(),
2374 cursor.par()->params().labelWidthString(), 0);
2375 lt->cursorLeft(bv_);
2378 | BufferView::FITCUR
2379 | BufferView::CHANGE);
2381 lt->cursorLeft(bv_);
2383 lt->selection.cursor = lt->cursor;
2386 | BufferView::FITCUR
2387 | BufferView::CHANGE);
2391 lt->selection.cursor = lt->cursor;
2394 | BufferView::FITCUR
2395 | BufferView::CHANGE);
2403 /* -------> Delete word forward. */
2404 case LFUN_DELETE_WORD_FORWARD:
2405 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2406 bv_->getLyXText()->deleteWordForward(bv_);
2407 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2408 moveCursorUpdate(false);
2409 owner_->showState();
2412 /* -------> Delete word backward. */
2413 case LFUN_DELETE_WORD_BACKWARD:
2415 LyXText * lt = bv_->getLyXText();
2417 update(lt, BufferView::SELECT|BufferView::FITCUR);
2418 lt->deleteWordBackward(bv_);
2421 | BufferView::FITCUR
2422 | BufferView::CHANGE);
2423 moveCursorUpdate(false);
2424 owner_->showState();
2428 /* -------> Kill to end of line. */
2429 case LFUN_DELETE_LINE_FORWARD:
2431 LyXText * lt = bv_->getLyXText();
2433 update(lt, BufferView::SELECT|BufferView::FITCUR);
2434 lt->deleteLineForward(bv_);
2437 | BufferView::FITCUR
2438 | BufferView::CHANGE);
2439 moveCursorUpdate(false);
2443 /* -------> Set mark off. */
2446 LyXText * lt = bv_->getLyXText();
2449 update(lt, BufferView::SELECT|BufferView::FITCUR);
2450 lt->selection.cursor = lt->cursor;
2451 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2455 /* -------> Set mark on. */
2458 LyXText * lt = bv_->getLyXText();
2461 lt->selection.mark(true);
2462 update(lt, BufferView::SELECT|BufferView::FITCUR);
2463 lt->selection.cursor = lt->cursor;
2464 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2468 case LFUN_BACKSPACE:
2470 LyXText * lt = bv_->getLyXText();
2472 if (!lt->selection.set()) {
2473 if (owner_->getIntl()->getTrans().backspace()) {
2475 lt->selection.cursor = lt->cursor;
2478 | BufferView::FITCUR
2479 | BufferView::CHANGE);
2480 // It is possible to make it a lot faster still
2481 // just comment out the line below...
2487 owner_->showState();
2492 case LFUN_BACKSPACE_SKIP:
2494 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2495 LyXText * lt = bv_->getLyXText();
2497 LyXCursor cursor = lt->cursor;
2499 if (!lt->selection.set()) {
2500 if (cursor.pos() == 0
2501 && !(cursor.par()->params().spaceTop()
2502 == VSpace (VSpace::NONE))) {
2505 cursor.par()->params().lineTop(),
2506 cursor.par()->params().lineBottom(),
2507 cursor.par()->params().pagebreakTop(),
2508 cursor.par()->params().pagebreakBottom(),
2509 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2510 cursor.par()->params().align(),
2511 cursor.par()->params().labelWidthString(), 0);
2514 | BufferView::FITCUR
2515 | BufferView::CHANGE);
2518 lt->selection.cursor = cursor;
2521 | BufferView::FITCUR
2522 | BufferView::CHANGE);
2529 case LFUN_BREAKPARAGRAPH:
2531 LyXText * lt = bv_->getLyXText();
2534 lt->breakParagraph(bv_, 0);
2537 | BufferView::FITCUR
2538 | BufferView::CHANGE);
2539 lt->selection.cursor = lt->cursor;
2541 owner_->showState();
2545 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2547 LyXText * lt = bv_->getLyXText();
2550 lt->breakParagraph(bv_, 1);
2553 | BufferView::FITCUR
2554 | BufferView::CHANGE);
2555 lt->selection.cursor = lt->cursor;
2557 owner_->showState();
2561 case LFUN_BREAKPARAGRAPH_SKIP:
2563 // When at the beginning of a paragraph, remove
2564 // indentation and add a "defskip" at the top.
2565 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2566 LyXText * lt = bv_->getLyXText();
2568 LyXCursor cursor = lt->cursor;
2571 if (cursor.pos() == 0) {
2572 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2575 cursor.par()->params().lineTop(),
2576 cursor.par()->params().lineBottom(),
2577 cursor.par()->params().pagebreakTop(),
2578 cursor.par()->params().pagebreakBottom(),
2579 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2580 cursor.par()->params().align(),
2581 cursor.par()->params().labelWidthString(), 1);
2582 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2586 lt->breakParagraph(bv_, 0);
2587 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2592 | BufferView::FITCUR
2593 | BufferView::CHANGE);
2594 lt->selection.cursor = cursor;
2596 owner_->showState();
2600 case LFUN_PARAGRAPH_SPACING:
2602 LyXText * lt = bv_->getLyXText();
2604 Paragraph * par = lt->cursor.par();
2605 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2606 float cur_value = 1.0;
2607 if (cur_spacing == Spacing::Other) {
2608 cur_value = par->params().spacing().getValue();
2611 istringstream istr(argument.c_str());
2615 Spacing::Space new_spacing = cur_spacing;
2616 float new_value = cur_value;
2618 lyxerr << "Missing argument to `paragraph-spacing'"
2620 } else if (tmp == "single") {
2621 new_spacing = Spacing::Single;
2622 } else if (tmp == "onehalf") {
2623 new_spacing = Spacing::Onehalf;
2624 } else if (tmp == "double") {
2625 new_spacing = Spacing::Double;
2626 } else if (tmp == "other") {
2627 new_spacing = Spacing::Other;
2630 lyxerr << "new_value = " << tmpval << endl;
2633 } else if (tmp == "default") {
2634 new_spacing = Spacing::Default;
2636 lyxerr << _("Unknown spacing argument: ")
2637 << argument << endl;
2639 if (cur_spacing != new_spacing || cur_value != new_value) {
2640 par->params().spacing(Spacing(new_spacing, new_value));
2641 lt->redoParagraph(bv_);
2644 | BufferView::FITCUR
2645 | BufferView::CHANGE);
2650 case LFUN_INSET_TOGGLE:
2652 LyXText * lt = bv_->getLyXText();
2655 update(lt, BufferView::SELECT|BufferView::FITCUR);
2656 lt->toggleInset(bv_);
2657 update(lt, BufferView::SELECT|BufferView::FITCUR);
2669 InsetCommandParams p;
2670 if (action == LFUN_HTMLURL)
2671 p.setCmdName("htmlurl");
2673 p.setCmdName("url");
2674 owner_->getDialogs()->createUrl(p.getAsString());
2678 case LFUN_INSERT_URL:
2680 InsetCommandParams p;
2681 p.setFromString(argument);
2683 InsetUrl * inset = new InsetUrl(p);
2684 if (!insertInset(inset))
2687 updateInset(inset, true);
2691 case LFUN_INSET_TEXT:
2692 insertAndEditInset(new InsetText);
2695 case LFUN_INSET_ERT:
2696 insertAndEditInset(new InsetERT);
2699 case LFUN_INSET_EXTERNAL:
2700 insertAndEditInset(new InsetExternal);
2703 case LFUN_INSET_FOOTNOTE:
2704 insertAndEditInset(new InsetFoot);
2707 case LFUN_INSET_MARGINAL:
2708 insertAndEditInset(new InsetMarginal);
2711 case LFUN_INSET_MINIPAGE:
2712 insertAndEditInset(new InsetMinipage);
2715 case LFUN_INSERT_NOTE:
2716 insertAndEditInset(new InsetNote);
2719 case LFUN_INSET_FLOAT:
2720 // check if the float type exist
2721 if (floatList.typeExist(argument)) {
2722 insertAndEditInset(new InsetFloat(argument));
2724 lyxerr << "Non-existant float type: "
2725 << argument << endl;
2729 case LFUN_INSET_WIDE_FLOAT:
2731 // check if the float type exist
2732 if (floatList.typeExist(argument)) {
2733 InsetFloat * new_inset = new InsetFloat(argument);
2734 new_inset->wide(true);
2735 if (insertInset(new_inset))
2736 new_inset->edit(bv_);
2740 lyxerr << "Non-existant float type: "
2741 << argument << endl;
2747 case LFUN_INSET_LIST:
2748 insertAndEditInset(new InsetList);
2751 case LFUN_INSET_THEOREM:
2752 insertAndEditInset(new InsetTheorem);
2755 case LFUN_INSET_CAPTION:
2757 // Do we have a locking inset...
2758 if (bv_->theLockingInset()) {
2759 lyxerr << "Locking inset code: "
2760 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2761 InsetCaption * new_inset = new InsetCaption;
2762 new_inset->setOwner(bv_->theLockingInset());
2763 new_inset->setAutoBreakRows(true);
2764 new_inset->setDrawFrame(0, InsetText::LOCKED);
2765 new_inset->setFrameColor(0, LColor::captionframe);
2766 if (insertInset(new_inset))
2767 new_inset->edit(bv_);
2774 case LFUN_INSET_TABULAR:
2778 if (!argument.empty())
2779 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2780 InsetTabular * new_inset =
2781 new InsetTabular(*buffer_, r, c);
2783 bv_->getLyXText()->real_current_font.isRightToLeft();
2784 if (!open_new_inset(new_inset, rtl))
2789 // --- lyxserver commands ----------------------------
2791 case LFUN_CHARATCURSOR:
2793 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2794 if (pos < bv_->getLyXText()->cursor.par()->size())
2795 owner_->getLyXFunc()->setMessage(
2796 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2798 owner_->getLyXFunc()->setMessage("EOF");
2803 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2805 + tostr(bv_->getLyXText()->cursor.y()));
2812 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2813 lyxerr << "SETXY: Could not parse coordinates in '"
2814 << argument << std::endl;
2816 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2820 case LFUN_GETLAYOUT:
2821 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2826 LyXFont & font = bv_->getLyXText()->current_font;
2827 if (font.shape() == LyXFont::ITALIC_SHAPE)
2828 owner_->getLyXFunc()->setMessage("E");
2829 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2830 owner_->getLyXFunc()->setMessage("N");
2832 owner_->getLyXFunc()->setMessage("0");
2840 LyXFont & font = bv_->getLyXText()->current_font;
2841 if (font.latex() == LyXFont::ON)
2842 owner_->getLyXFunc()->setMessage("L");
2845 owner_->getLyXFunc()->setMessage("0");
2849 // --- accented characters ---------------------------
2852 case LFUN_CIRCUMFLEX:
2862 case LFUN_SPECIAL_CARON:
2865 case LFUN_HUNG_UMLAUT:
2868 if (argument.empty()) {
2870 owner_->getLyXFunc()->handleKeyFunc(action);
2872 owner_->getLyXFunc()->handleKeyFunc(action);
2873 owner_->getIntl()->getTrans()
2874 .TranslateAndInsert(argument[0], bv_->getLyXText());
2875 update(bv_->getLyXText(),
2877 | BufferView::FITCUR
2878 | BufferView::CHANGE);
2882 case LFUN_MATH_MACRO:
2883 mathDispatchMathMacro(bv_, argument);
2886 case LFUN_MATH_DELIM:
2887 mathDispatchMathDelim(bv_, argument);
2890 case LFUN_INSERT_MATRIX:
2891 mathDispatchInsertMatrix(bv_, argument);
2894 case LFUN_INSERT_MATH:
2895 mathDispatchInsertMath(bv_, argument);
2898 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2899 mathDispatchMathImportSelection(bv_, argument);
2902 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2903 mathDispatchMathDisplay(bv_, argument);
2906 case LFUN_MATH_MODE: // Open or create an inlined math inset
2907 mathDispatchMathMode(bv_, argument);
2910 case LFUN_CITATION_INSERT:
2912 InsetCommandParams p;
2913 p.setFromString( argument );
2915 InsetCitation * inset = new InsetCitation( p );
2916 if (!insertInset(inset))
2919 updateInset( inset, true );
2923 case LFUN_INSERT_BIBTEX:
2925 // ale970405+lasgoutt970425
2926 // The argument can be up to two tokens separated
2927 // by a space. The first one is the bibstyle.
2928 string const db = token(argument, ' ', 0);
2929 string bibstyle = token(argument, ' ', 1);
2930 if (bibstyle.empty())
2933 InsetCommandParams p( "BibTeX", db, bibstyle );
2934 InsetBibtex * inset = new InsetBibtex(p);
2936 if (insertInset(inset)) {
2937 if (argument.empty())
2944 // BibTeX data bases
2945 case LFUN_BIBDB_ADD:
2947 InsetBibtex * inset =
2948 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2950 inset->addDatabase(argument);
2955 case LFUN_BIBDB_DEL:
2957 InsetBibtex * inset =
2958 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2960 inset->delDatabase(argument);
2965 case LFUN_BIBTEX_STYLE:
2967 InsetBibtex * inset =
2968 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2970 inset->setOptions(argument);
2975 case LFUN_INDEX_CREATE:
2977 InsetCommandParams p("index");
2979 if (argument.empty()) {
2980 // Get word or selection
2981 bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
2983 string const curstring =
2984 bv_->getLyXText()->selectionAsString(buffer_);
2986 p.setContents(curstring);
2988 p.setContents(argument);
2991 owner_->getDialogs()->createIndex(p.getAsString());
2995 case LFUN_INDEX_INSERT:
2997 InsetCommandParams p;
2998 p.setFromString(argument);
2999 InsetIndex * inset = new InsetIndex(p);
3001 if (!insertInset(inset))
3004 updateInset(inset, true);
3008 case LFUN_INDEX_INSERT_LAST:
3010 // Get word or selection
3011 bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
3013 string const curstring =
3014 bv_->getLyXText()->selectionAsString(buffer_);
3016 InsetCommandParams p("index", curstring);
3017 InsetIndex * inset = new InsetIndex(p);
3019 if (!insertInset(inset))
3022 updateInset(inset, true);
3026 case LFUN_INDEX_PRINT:
3028 InsetCommandParams p("printindex");
3029 Inset * inset = new InsetPrintIndex(p);
3030 if (!insertInset(inset, "Standard"))
3035 case LFUN_PARENTINSERT:
3037 lyxerr << "arg " << argument << endl;
3038 InsetCommandParams p( "lyxparent", argument );
3039 Inset * inset = new InsetParent(p, *buffer_);
3040 if (!insertInset(inset, "Standard"))
3046 case LFUN_CHILD_INSERT:
3048 InsetInclude::Params p;
3049 p.cparams.setFromString(argument);
3050 p.masterFilename_ = buffer_->fileName();
3052 InsetInclude * inset = new InsetInclude(p);
3053 if (!insertInset(inset))
3056 updateInset(inset, true);
3057 bv_->owner()->getDialogs()->showInclude(inset);
3062 case LFUN_FLOAT_LIST:
3064 // We should check the argument for validity. (Lgb)
3065 Inset * inset = new InsetFloatList(argument);
3066 if (!insertInset(inset, "Standard"))
3071 case LFUN_SELFINSERT:
3073 if (argument.empty()) break;
3075 /* Automatically delete the currently selected
3076 * text and replace it with what is being
3077 * typed in now. Depends on lyxrc settings
3078 * "auto_region_delete", which defaults to
3081 LyXText * lt = bv_->getLyXText();
3083 if (lyxrc.auto_region_delete) {
3084 if (lt->selection.set()) {
3085 lt->cutSelection(bv_, false);
3088 | BufferView::FITCUR
3089 | BufferView::CHANGE);
3094 LyXFont const old_font(lt->real_current_font);
3096 string::const_iterator cit = argument.begin();
3097 string::const_iterator end = argument.end();
3098 for (; cit != end; ++cit) {
3099 if (greek_kb_flag) {
3100 if (!math_insert_greek(bv_, *cit))
3101 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3103 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3108 | BufferView::FITCUR
3109 | BufferView::CHANGE);
3111 lt->selection.cursor = lt->cursor;
3112 moveCursorUpdate(false);
3114 // real_current_font.number can change so we need to
3115 // update the minibuffer
3116 if (old_font != lt->real_current_font)
3117 owner_->showState();
3122 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3124 time_t now_time_t = time(NULL);
3125 struct tm * now_tm = localtime(&now_time_t);
3126 setlocale(LC_TIME, "");
3128 if (!argument.empty())
3131 arg = lyxrc.date_insert_format;
3133 int const datetmp_len =
3134 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3136 LyXText * lt = bv_->getLyXText();
3138 for (int i = 0; i < datetmp_len; i++) {
3139 lt->insertChar(bv_, datetmp[i]);
3142 | BufferView::FITCUR
3143 | BufferView::CHANGE);
3146 lt->selection.cursor = lt->cursor;
3147 moveCursorUpdate(false);
3151 case LFUN_UNKNOWN_ACTION:
3152 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3163 void BufferView::Pimpl::newline()
3166 LyXText * lt = bv_->getLyXText();
3170 | BufferView::FITCUR);
3171 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3174 | BufferView::FITCUR
3175 | BufferView::CHANGE);
3180 void BufferView::Pimpl::hfill()
3183 LyXText * lt = bv_->getLyXText();
3187 | BufferView::FITCUR);
3188 lt->insertChar(bv_, Paragraph::META_HFILL);
3191 | BufferView::FITCUR
3192 | BufferView::CHANGE);
3197 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3201 update(lt, BufferView::SELECT|BufferView::FITCUR);
3202 InsetSpecialChar * new_inset =
3203 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3204 #ifdef WITH_WARNINGS
3205 #warning Why is this code different from specialChar() below? (JMarc)
3206 // the code in specialChar is a generic version of what used to exist
3207 // for other special chars. I did not merge this case because of the
3208 // call to updateInset(), but what does it do?
3210 if (!insertInset(new_inset))
3213 updateInset(new_inset, true);
3218 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3221 LyXText * lt = bv_->getLyXText();
3224 update(lt, BufferView::SELECT|BufferView::FITCUR);
3225 InsetSpecialChar * new_inset =
3226 new InsetSpecialChar(kind);
3227 insertInset(new_inset);
3232 void BufferView::Pimpl::smartQuote()
3235 LyXText * lt = bv_->getLyXText();
3237 if (lt->cursor.pos())
3238 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3243 if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
3244 Dispatch(LFUN_SELFINSERT, "\"");
3248 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3250 if (insertInset(inset))
3257 // Open and lock an updatable inset
3258 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3260 LyXText * lt = bv_->getLyXText();
3264 if (!insertInset(new_inset)) {
3268 new_inset->edit(bv_, !behind);
3273 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3275 // if we are in a locking inset we should try to insert the
3276 // inset there otherwise this is a illegal function now
3277 if (bv_->theLockingInset()) {
3278 if (bv_->theLockingInset()->insetAllowed(inset))
3279 return bv_->theLockingInset()->insertInset(bv_, inset);
3283 // not quite sure if we want this...
3284 setCursorParUndo(bv_);
3287 beforeChange(bv_->text);
3288 if (!lout.empty()) {
3289 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3290 bv_->text->breakParagraph(bv_);
3291 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3293 if (bv_->text->cursor.par()->size()) {
3294 bv_->text->cursorLeft(bv_);
3296 bv_->text->breakParagraph(bv_);
3297 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3300 pair<bool, LyXTextClass::size_type> lres =
3301 textclasslist.NumberOfLayout(buffer_->params
3303 LyXTextClass::size_type lay;
3304 if (lres.first != false) {
3308 // layout not fount using default "Standard" (0)
3312 bv_->text->setLayout(bv_, lay);
3314 bv_->text->setParagraph(bv_, 0, 0,
3316 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3320 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3322 bv_->text->current_font.setLatex(LyXFont::OFF);
3326 bv_->text->insertInset(bv_, inset);
3327 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3334 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3339 // first check for locking insets
3340 if (bv_->theLockingInset()) {
3341 if (bv_->theLockingInset() == inset) {
3342 if (bv_->text->updateInset(bv_, inset)) {
3345 buffer_->markDirty();
3350 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3351 if (bv_->text->updateInset(bv_,
3352 bv_->theLockingInset())) {
3355 buffer_->markDirty();
3363 // then check the current buffer
3366 update(bv_->text, BufferView::UPDATE);
3367 if (bv_->text->updateInset(bv_, inset)) {
3371 | BufferView::FITCUR
3372 | BufferView::CHANGE);
3374 update(bv_->text, SELECT);
3382 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3385 if (!available()) return;
3388 beforeChange(bv_->text);
3389 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3393 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3394 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3395 if (find(codes.begin(), codes.end(), inset->lyxCode())
3398 static_cast<InsetCommand const *>(inset)->getContents();
3401 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3402 if (bv_->text->cursor.pos()
3403 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3404 LyXCursor tmp = bv_->text->cursor;
3405 bv_->text->cursor.par(bv_->text->firstParagraph());
3406 bv_->text->cursor.pos(0);
3407 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3408 bv_->text->cursor = tmp;
3409 bv_->owner()->message(_("No more insets"));
3412 bv_->owner()->message(_("No more insets"));
3415 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3416 bv_->text->selection.cursor = bv_->text->cursor;
3420 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3422 gotoInset(vector<Inset::Code>(1, code), same_content);