12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
22 #include "bufferview_funcs.h"
23 #include "TextCache.h"
24 #include "bufferlist.h"
25 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "support/lstrings.h"
30 #include "frontends/Dialogs.h"
31 #include "insets/insetbib.h"
32 #include "insets/insettext.h"
33 /// added for Dispatch functions
35 #include "frontends/FileDialog.h"
37 #include "FloatList.h"
38 #include "support/filetools.h"
39 #include "support/lyxfunctional.h"
40 #include "insets/inseturl.h"
41 #include "insets/insetlatexaccent.h"
42 #include "insets/insettoc.h"
43 #include "insets/insetref.h"
44 #include "insets/insetparent.h"
45 #include "insets/insetindex.h"
46 #include "insets/insetnote.h"
47 #include "insets/insetinclude.h"
48 #include "insets/insetcite.h"
49 #include "insets/insetert.h"
50 #include "insets/insetexternal.h"
51 #include "insets/insetgraphics.h"
52 #include "insets/insetfoot.h"
53 #include "insets/insetmarginal.h"
54 #include "insets/insetminipage.h"
55 #include "insets/insetfloat.h"
56 #include "insets/insettabular.h"
58 #include "insets/insettheorem.h"
59 #include "insets/insetlist.h"
61 #include "insets/insetcaption.h"
62 #include "insets/insetfloatlist.h"
63 #include "insets/insetspecialchar.h"
65 #include "ParagraphParameters.h"
66 #include "undo_funcs.h"
67 #include "mathed/formulabase.h"
69 extern LyXTextClass::size_type current_layout;
70 extern int greek_kb_flag;
81 /* the selection possible is needed, that only motion events are
82 * used, where the bottom press event was on the drawing area too */
83 bool selection_possible = false;
85 extern BufferList bufferlist;
86 extern char ascii_type;
88 extern bool math_insert_greek(BufferView *, char);
89 extern void sigchldchecker(pid_t pid, int * status);
90 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
95 const unsigned int saved_positions_num = 20;
100 XSync(fl_get_display(), 0);
104 void SetXtermCursor(Window win)
106 static Cursor cursor;
107 static bool cursor_undefined = true;
108 if (cursor_undefined){
109 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
110 XFlush(fl_get_display());
111 cursor_undefined = false;
113 XDefineCursor(fl_get_display(), win, cursor);
114 XFlush(fl_get_display());
120 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
121 int xpos, int ypos, int width, int height)
122 : bv_(b), owner_(o), buffer_(0),
123 current_scrollbar_value(0), cursor_timeout(400),
124 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
128 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
129 workarea_.workAreaExpose
130 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
131 workarea_.workAreaEnter
132 .connect(slot(this, &BufferView::Pimpl::enterView));
133 workarea_.workAreaLeave
134 .connect(slot(this, &BufferView::Pimpl::leaveView));
135 workarea_.workAreaButtonPress
136 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
137 workarea_.workAreaButtonRelease
139 &BufferView::Pimpl::workAreaButtonRelease));
140 workarea_.workAreaMotionNotify
141 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
142 workarea_.workAreaDoubleClick
143 .connect(slot(this, &BufferView::Pimpl::doubleClick));
144 workarea_.workAreaTripleClick
145 .connect(slot(this, &BufferView::Pimpl::tripleClick));
146 workarea_.workAreaKeyPress
147 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
149 cursor_timeout.timeout.connect(slot(this,
150 &BufferView::Pimpl::cursorToggle));
151 cursor_timeout.start();
152 workarea_.setFocus();
153 saved_positions.resize(saved_positions_num);
157 Painter & BufferView::Pimpl::painter()
159 return workarea_.getPainter();
163 void BufferView::Pimpl::buffer(Buffer * b)
165 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
169 buffer_->delUser(bv_);
171 // Put the old text into the TextCache, but
172 // only if the buffer is still loaded.
173 // Also set the owner of the test to 0
174 // bv_->text->owner(0);
175 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
176 if (lyxerr.debugging())
177 textcache.show(lyxerr, "BufferView::buffer");
182 // Set current buffer
185 if (bufferlist.getState() == BufferList::CLOSING) return;
188 // screen is always deleted when the buffer is changed.
191 // If we are closing the buffer, use the first buffer as current
193 buffer_ = bufferlist.first();
197 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
198 buffer_->addUser(bv_);
199 // If we don't have a text object for this, we make one
200 if (bv_->text == 0) {
201 resizeCurrentBuffer();
206 bv_->text->first = screen_->topCursorVisible(bv_->text);
207 owner_->updateMenubar();
208 owner_->updateToolbar();
209 // Similarly, buffer-dependent dialogs should be updated or
210 // hidden. This should go here because some dialogs (eg ToC)
211 // require bv_->text.
212 owner_->getDialogs()->updateBufferDependent(true);
216 lyxerr[Debug::INFO] << " No Buffer!" << endl;
217 owner_->updateMenubar();
218 owner_->updateToolbar();
219 owner_->getDialogs()->hideBufferDependent();
223 // Also remove all remaining text's from the testcache.
224 // (there should not be any!) (if there is any it is a
226 if (lyxerr.debugging())
227 textcache.show(lyxerr, "buffer delete all");
230 // should update layoutchoice even if we don't have a buffer.
231 owner_->updateLayoutChoice();
233 owner_->updateWindowTitle();
237 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
239 workarea_.resize(xpos, ypos, width, height);
240 update(bv_->text, SELECT);
245 void BufferView::Pimpl::resize()
248 resizeCurrentBuffer();
252 void BufferView::Pimpl::redraw()
254 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
259 bool BufferView::Pimpl::fitCursor(LyXText * text)
261 lyx::Assert(screen_.get());
265 if (bv_->theLockingInset()) {
266 bv_->theLockingInset()->fitInsetCursor(bv_);
269 ret = screen_->fitCursor(text, bv_);
272 bv_->owner()->getDialogs()->updateParagraph();
279 void BufferView::Pimpl::redoCurrentBuffer()
281 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
282 if (buffer_ && bv_->text) {
284 owner_->updateLayoutChoice();
289 int BufferView::Pimpl::resizeCurrentBuffer()
291 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
294 Paragraph * selstartpar = 0;
295 Paragraph * selendpar = 0;
296 UpdatableInset * the_locking_inset = 0;
298 Paragraph::size_type pos = 0;
299 Paragraph::size_type selstartpos = 0;
300 Paragraph::size_type selendpos = 0;
301 bool selection = false;
302 bool mark_set = false;
304 owner_->prohibitInput();
306 owner_->message(_("Formatting document..."));
309 par = bv_->text->cursor.par();
310 pos = bv_->text->cursor.pos();
311 selstartpar = bv_->text->selection.start.par();
312 selstartpos = bv_->text->selection.start.pos();
313 selendpar = bv_->text->selection.end.par();
314 selendpos = bv_->text->selection.end.pos();
315 selection = bv_->text->selection.set();
316 mark_set = bv_->text->selection.mark();
317 the_locking_inset = bv_->theLockingInset();
319 bv_->text = new LyXText(bv_);
320 bv_->text->init(bv_);
322 // See if we have a text in TextCache that fits
323 // the new buffer_ with the correct width.
324 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
326 if (lyxerr.debugging()) {
327 lyxerr << "Found a LyXText that fits:\n";
328 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
330 // Set the owner of the newly found text
331 // bv_->text->owner(bv_);
332 if (lyxerr.debugging())
333 textcache.show(lyxerr, "resizeCurrentBuffer");
335 bv_->text = new LyXText(bv_);
336 bv_->text->init(bv_);
342 bv_->text->selection.set(true);
343 /* at this point just to avoid the Delete-Empty-Paragraph
344 * Mechanism when setting the cursor */
345 bv_->text->selection.mark(mark_set);
347 bv_->text->setCursor(bv_, selstartpar, selstartpos);
348 bv_->text->selection.cursor = bv_->text->cursor;
349 bv_->text->setCursor(bv_, selendpar, selendpos);
350 bv_->text->setSelection(bv_);
351 bv_->text->setCursor(bv_, par, pos);
353 bv_->text->setCursor(bv_, par, pos);
354 bv_->text->selection.cursor = bv_->text->cursor;
355 bv_->text->selection.set(false);
357 // remake the inset locking
358 bv_->theLockingInset(the_locking_inset);
360 bv_->text->first = screen_->topCursorVisible(bv_->text);
361 buffer_->resizeInsets(bv_);
362 // this will scroll the screen such that the cursor becomes visible
367 owner_->allowInput();
369 /// clear the "Formatting Document" message
372 /// get rid of the splash screen if it's not gone already
373 owner_->getDialogs()->destroySplash();
379 void BufferView::Pimpl::updateScreen()
381 // Regenerate the screen.
382 screen_.reset(new LyXScreen(workarea_));
386 void BufferView::Pimpl::updateScrollbar()
388 /* If the text is smaller than the working area, the scrollbar
389 * maximum must be the working area height. No scrolling will
392 workarea_.setScrollbar(0, 1.0);
396 long const text_height = bv_->text->height;
398 double const lineh = bv_->text->defaultHeight();
399 double const slider_size =
400 (text_height == 0) ? 1.0 : 1.0 / double(text_height);
402 static long old_text_height = 0;
403 static double old_lineh = 0;
404 static double old_slider_size = 0;
406 if (text_height != old_text_height) {
407 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
408 old_text_height = text_height;
410 if (lineh != old_lineh) {
411 workarea_.setScrollbarIncrements(lineh);
414 if (current_scrollbar_value != bv_->text->first
415 || slider_size != old_slider_size) {
416 current_scrollbar_value = bv_->text->first;
417 workarea_.setScrollbar(current_scrollbar_value, slider_size);
418 old_slider_size = slider_size;
423 // Callback for scrollbar slider
424 void BufferView::Pimpl::scrollCB(double value)
426 if (!buffer_) return;
428 current_scrollbar_value = long(value);
429 if (current_scrollbar_value < 0)
430 current_scrollbar_value = 0;
435 screen_->draw(bv_->text, bv_, current_scrollbar_value);
437 if (!lyxrc.cursor_follows_scrollbar) {
442 LyXText * vbt = bv_->text;
444 int const height = vbt->defaultHeight();
445 int const first = static_cast<int>((bv_->text->first + height));
446 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
448 if (vbt->cursor.y() < first)
449 vbt->setCursorFromCoordinates(bv_, 0, first);
450 else if (vbt->cursor.y() > last)
451 vbt->setCursorFromCoordinates(bv_, 0, last);
457 int BufferView::Pimpl::scrollUp(long time)
459 if (!buffer_) return 0;
460 if (!screen_.get()) return 0;
462 double value = workarea_.getScrollbarValue();
464 if (value == 0) return 0;
466 float add_value = (bv_->text->defaultHeight()
467 + float(time) * float(time) * 0.125);
469 if (add_value > workarea_.height())
470 add_value = float(workarea_.height() -
471 bv_->text->defaultHeight());
478 workarea_.setScrollbarValue(value);
485 int BufferView::Pimpl::scrollDown(long time)
487 if (!buffer_) return 0;
488 if (!screen_.get()) return 0;
490 double value = workarea_.getScrollbarValue();
491 pair<float, float> p = workarea_.getScrollbarBounds();
492 double const max = p.second;
494 if (value == max) return 0;
496 float add_value = (bv_->text->defaultHeight()
497 + float(time) * float(time) * 0.125);
499 if (add_value > workarea_.height())
500 add_value = float(workarea_.height() -
501 bv_->text->defaultHeight());
508 workarea_.setScrollbarValue(value);
515 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
517 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
521 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
523 // Only use motion with button 1
524 if (!(state & Button1MotionMask))
527 if (!buffer_ || !screen_.get()) return;
529 // Check for inset locking
530 if (bv_->theLockingInset()) {
531 LyXCursor cursor = bv_->text->cursor;
532 LyXFont font = bv_->text->getFont(buffer_,
533 cursor.par(), cursor.pos());
534 int width = bv_->theLockingInset()->width(bv_, font);
535 int inset_x = font.isVisibleRightToLeft()
536 ? cursor.x() - width : cursor.x();
537 int start_x = inset_x + bv_->theLockingInset()->scroll();
538 bv_->theLockingInset()->
539 insetMotionNotify(bv_,
541 y - cursor.y() + bv_->text->first,
546 /* The test for not selection possible is needed, that only motion
547 events are used, where the bottom press event was on
548 the drawing area too */
549 if (!selection_possible)
552 screen_->hideCursor();
554 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
556 if (!bv_->text->selection.set())
557 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
559 bv_->text->setSelection(bv_);
560 screen_->toggleToggle(bv_->text, bv_);
561 fitCursor(bv_->text);
562 screen_->showCursor(bv_->text, bv_);
566 // Single-click on work area
567 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
570 if (!buffer_ || !screen_.get()) return;
572 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
574 // ok ok, this is a hack.
575 if (button == 4 || button == 5) {
578 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
581 scrollDown(lyxrc.wheel_jump);
586 if (bv_->theLockingInset()) {
587 // We are in inset locking mode
589 /* Check whether the inset was hit. If not reset mode,
590 otherwise give the event to the inset */
591 if (inset_hit == bv_->theLockingInset()) {
592 bv_->theLockingInset()->
593 insetButtonPress(bv_,
598 bv_->unlockInset(bv_->theLockingInset());
603 selection_possible = true;
604 screen_->hideCursor();
606 int const screen_first = bv_->text->first;
608 // Middle button press pastes if we have a selection
609 bool paste_internally = false;
611 && bv_->text->selection.set()) {
612 owner_->getLyXFunc()->dispatch(LFUN_COPY);
613 paste_internally = true;
616 // Clear the selection
617 screen_->toggleSelection(bv_->text, bv_);
618 bv_->text->clearSelection(bv_);
619 bv_->text->fullRebreak(bv_);
620 screen_->update(bv_->text, bv_);
623 // Single left click in math inset?
624 if ((inset_hit != 0) &&
625 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
626 // Highly editable inset, like math
627 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
628 selection_possible = false;
629 owner_->updateLayoutChoice();
630 owner_->message(inset->editMessage());
631 inset->insetButtonPress(bv_, xpos, ypos, button);
632 inset->edit(bv_, xpos, ypos, button);
636 // Right click on a footnote flag opens float menu
638 selection_possible = false;
642 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
643 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
645 bv_->text->selection.cursor = bv_->text->cursor;
646 bv_->text->cursor.x_fix(bv_->text->cursor.x());
648 owner_->updateLayoutChoice();
649 if (fitCursor(bv_->text)) {
650 selection_possible = false;
653 // Insert primary selection with middle mouse
654 // if there is a local selection in the current buffer,
657 if (paste_internally)
658 owner_->getLyXFunc()->dispatch(LFUN_PASTE);
660 owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
662 selection_possible = false;
668 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
674 LyXText * text = bv_->getLyXText();
676 if (text->bv_owner && bv_->theLockingInset())
679 if (screen_.get() && button == 1) {
680 if (text->bv_owner) {
681 screen_->hideCursor();
682 screen_->toggleSelection(text, bv_);
683 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
684 screen_->toggleSelection(text, bv_, false);
686 text->selectWord(bv_, LyXText::WHOLE_WORD_STRICT);
688 /* This will fit the cursor on the screen
690 update(text, BufferView::SELECT|BufferView::FITCUR);
695 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
701 LyXText * text = bv_->getLyXText();
703 if (text->bv_owner && bv_->theLockingInset())
706 if (screen_.get() && (button == 1)) {
707 screen_->hideCursor();
708 screen_->toggleSelection(text, bv_);
709 text->cursorHome(bv_);
710 text->selection.cursor = text->cursor;
711 text->cursorEnd(bv_);
712 text->setSelection(bv_);
713 screen_->toggleSelection(text, bv_, false);
714 /* This will fit the cursor on the screen
716 update(text, BufferView::SELECT|BufferView::FITCUR);
721 void BufferView::Pimpl::enterView()
723 if (active() && available()) {
724 SetXtermCursor(workarea_.getWin());
725 using_xterm_cursor = true;
730 void BufferView::Pimpl::leaveView()
732 if (using_xterm_cursor) {
733 XUndefineCursor(fl_get_display(), workarea_.getWin());
734 using_xterm_cursor = false;
739 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
742 if (!buffer_ || !screen_.get()) return;
744 // If we hit an inset, we have the inset coordinates in these
745 // and inset_hit points to the inset. If we do not hit an
746 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
747 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
749 if (bv_->theLockingInset()) {
750 // We are in inset locking mode.
752 /* LyX does a kind of work-area grabbing for insets.
753 Only a ButtonPress Event outside the inset will
754 force a insetUnlock. */
755 bv_->theLockingInset()->
756 insetButtonRelease(bv_, x, y, button);
760 selection_possible = false;
768 // Did we hit an editable inset?
770 // Inset like error, notes and figures
771 selection_possible = false;
773 // CHECK fix this proper in 0.13
775 // Following a ref shouldn't issue
776 // a push on the undo-stack
777 // anylonger, now that we have
778 // keybindings for following
779 // references and returning from
780 // references. IMHO though, it
781 // should be the inset's own business
782 // to push or not push on the undo
783 // stack. They don't *have* to
784 // alter the document...
786 // ...or maybe the SetCursorParUndo()
787 // below isn't necessary at all anylonger?
788 if (inset_hit->lyxCode() == Inset::REF_CODE) {
789 setCursorParUndo(bv_);
792 owner_->message(inset_hit->editMessage());
794 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
795 // Highly editable inset, like math
796 UpdatableInset *inset = (UpdatableInset *)inset_hit;
797 inset->insetButtonRelease(bv_, x, y, button);
799 inset_hit->insetButtonRelease(bv_, x, y, button);
800 inset_hit->edit(bv_, x, y, button);
805 // check whether we want to open a float
809 if (bv_->text->cursor.pos() <
810 bv_->text->cursor.par()->size()) {
811 c = bv_->text->cursor.par()->
812 getChar(bv_->text->cursor.pos());
814 if (bv_->text->cursor.pos() - 1 >= 0) {
815 c = bv_->text->cursor.par()->
816 getChar(bv_->text->cursor.pos() - 1);
819 selection_possible = false;
824 // Maybe we want to edit a bibitem ale970302
825 if (bv_->text->cursor.par()->bibkey && x < 20 +
826 bibitemMaxWidth(bv_, textclasslist.
828 params.textclass).defaultfont())) {
829 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
837 * Returns an inset if inset was hit. 0 otherwise.
838 * If hit, the coordinates are changed relative to the inset.
839 * Otherwise coordinates are not changed, and false is returned.
841 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
842 unsigned int /* button */)
847 int y_tmp = y + text->first;
850 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
851 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
854 if (cursor.pos() < cursor.par()->size()
855 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
856 && cursor.par()->getInset(cursor.pos())
857 && cursor.par()->getInset(cursor.pos())->editable()) {
859 // Check whether the inset really was hit
860 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
861 LyXFont font = text->getFont(buffer_,
862 cursor.par(), cursor.pos());
863 int const width = tmpinset->width(bv_, font);
864 int const inset_x = font.isVisibleRightToLeft()
865 ? cursor.x() - width : cursor.x();
866 int const start_x = inset_x + tmpinset->scroll();
867 int const end_x = inset_x + width;
869 if (x > start_x && x < end_x
870 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
871 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
872 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
874 // The origin of an inset is on the baseline
875 y = y_tmp - (text->cursor.y());
880 if ((cursor.pos() - 1 >= 0) &&
881 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
882 (cursor.par()->getInset(cursor.pos() - 1)) &&
883 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
884 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
885 LyXFont font = text->getFont(buffer_, cursor.par(),
887 int const width = tmpinset->width(bv_, font);
888 int const inset_x = font.isVisibleRightToLeft()
889 ? cursor.x() : cursor.x() - width;
890 int const start_x = inset_x + tmpinset->scroll();
891 int const end_x = inset_x + width;
893 if (x > start_x && x < end_x
894 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
895 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
897 if (move_cursor && (tmpinset != bv_->theLockingInset()))
899 text->setCursor(bv_, cursor.par(),
900 cursor.pos() - 1, true);
902 // The origin of an inset is on the baseline
903 y = y_tmp - (text->cursor.y());
911 void BufferView::Pimpl::workAreaExpose()
913 static int work_area_width;
914 static unsigned int work_area_height;
916 bool const widthChange = workarea_.workWidth() != work_area_width;
917 bool const heightChange = workarea_.height() != work_area_height;
919 // update from work area
920 work_area_width = workarea_.workWidth();
921 work_area_height = workarea_.height();
924 // The visible LyXView need a resize
927 // Remove all texts from the textcache
928 // This is not _really_ what we want to do. What
929 // we really want to do is to delete in textcache
930 // that does not have a BufferView with matching
931 // width, but as long as we have only one BufferView
932 // deleting all gives the same result.
933 if (lyxerr.debugging())
934 textcache.show(lyxerr, "Expose delete all");
936 } else if (heightChange) {
937 // Rebuild image of current screen
939 // fitCursor() ensures we don't jump back
940 // to the start of the document on vertical
942 fitCursor(bv_->text);
944 // The main window size has changed, repaint most stuff
946 } else if (screen_.get())
947 screen_->redraw(bv_->text, bv_);
949 // Grey box when we don't have a buffer
953 // always make sure that the scrollbar is sane.
955 owner_->updateLayoutChoice();
960 void BufferView::Pimpl::update()
963 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
965 screen_->update(bv_->text, bv_);
969 // Values used when calling update:
971 // -2 - update, move sel_cursor if selection, fitcursor
972 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
973 // 0 - update, move sel_cursor if selection, fitcursor
974 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
975 // 3 - update, move sel_cursor if selection
978 // a simple redraw of the parts that need refresh
980 // move sel_cursor if selection -
981 // the text's sel_cursor is moved if there is selection is progress
984 // fitCursor() is called and the scrollbar updated
987 // the buffer is marked dirty.
996 // UPDATE_ONLY = UPDATE;
997 // UPDATE_SELECT = UPDATE | SELECT;
998 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
999 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1001 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
1002 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
1003 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1004 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1005 // update(3) -> update(1) -> update(1) -> update(SELECT)
1007 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1009 owner_->updateLayoutChoice();
1011 if (!text->selection.set() && (f & SELECT)) {
1012 text->selection.cursor = text->cursor;
1015 text->fullRebreak(bv_);
1017 if (text->inset_owner) {
1018 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1019 updateInset(text->inset_owner, true);
1029 buffer_->markDirty();
1034 // Callback for cursor timer
1035 void BufferView::Pimpl::cursorToggle()
1037 // Quite a nice place for asyncron Inset updating, isn't it?
1038 // Actually no! This is run even if no buffer exist... so (Lgb)
1040 cursor_timeout.restart();
1045 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1046 if (pid == -1) // error find out what is wrong
1047 ; // ignore it for now.
1049 sigchldchecker(pid, &status);
1051 updatelist.update(bv_);
1053 if (!screen_.get()) {
1054 cursor_timeout.restart();
1058 if (!bv_->theLockingInset()) {
1059 screen_->cursorToggle(bv_->text, bv_);
1061 bv_->theLockingInset()->toggleInsetCursor(bv_);
1064 cursor_timeout.restart();
1068 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1070 if (!text->cursor.row()->previous())
1073 int y = text->first;
1074 if (text->inset_owner)
1075 y += bv_->text->first;
1076 Row * cursorrow = text->cursor.row();
1077 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1079 // This is to allow jumping over large insets
1080 if ((cursorrow == text->cursor.row()))
1081 text->cursorUp(bv_);
1083 if (text->inset_owner ||
1084 text->cursor.row()->height() < workarea_.height())
1085 screen_->draw(bv_->text, bv_,
1087 - text->cursor.row()->baseline()
1088 + text->cursor.row()->height()
1089 - workarea_.height() + 1 );
1094 void BufferView::Pimpl::cursorNext(LyXText * text)
1096 if (!text->cursor.row()->next())
1099 int y = text->first + workarea_.height();
1100 // if (text->inset_owner)
1101 // y += bv_->text->first;
1102 text->getRowNearY(y);
1104 Row * cursorrow = text->cursor.row();
1105 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1107 // This is to allow jumping over large insets
1108 if ((cursorrow == bv_->text->cursor.row()))
1109 text->cursorDown(bv_);
1111 if (text->inset_owner ||
1112 text->cursor.row()->height() < workarea_.height())
1113 screen_->draw(bv_->text, bv_, text->cursor.y() -
1114 text->cursor.row()->baseline());
1119 bool BufferView::Pimpl::available() const
1121 if (buffer_ && bv_->text) return true;
1126 void BufferView::Pimpl::beforeChange(LyXText * text)
1129 text->clearSelection(bv_);
1133 void BufferView::Pimpl::savePosition(unsigned int i)
1135 if (i >= saved_positions_num)
1137 saved_positions[i] = Position(buffer_->fileName(),
1138 bv_->text->cursor.par()->id(),
1139 bv_->text->cursor.pos());
1142 str << _("Saved bookmark") << ' ' << i;
1143 owner_->message(str.str().c_str());
1148 void BufferView::Pimpl::restorePosition(unsigned int i)
1150 if (i >= saved_positions_num)
1153 string const fname = saved_positions[i].filename;
1155 beforeChange(bv_->text);
1157 if (fname != buffer_->fileName()) {
1158 Buffer * b = bufferlist.exists(fname) ?
1159 bufferlist.getBuffer(fname) :
1160 bufferlist.loadLyXFile(fname); // don't ask, just load it
1161 if (b != 0 ) buffer(b);
1164 Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
1168 bv_->text->setCursor(bv_, par,
1169 min(par->size(), saved_positions[i].par_pos));
1171 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1174 str << _("Moved to bookmark") << ' ' << i;
1175 owner_->message(str.str().c_str());
1180 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1182 if (i >= saved_positions_num)
1185 return !saved_positions[i].filename.empty();
1189 void BufferView::Pimpl::setState()
1191 if (!lyxrc.rtl_support)
1194 LyXText * text = bv_->getLyXText();
1195 if (text->real_current_font.isRightToLeft()
1198 text->real_current_font.latex() != LyXFont::ON
1201 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1202 owner_->getIntl()->KeyMapSec();
1204 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1205 owner_->getIntl()->KeyMapPrim();
1210 void BufferView::Pimpl::insetSleep()
1212 if (bv_->theLockingInset() && !inset_slept) {
1213 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1214 bv_->theLockingInset()->insetUnlock(bv_);
1220 void BufferView::Pimpl::insetWakeup()
1222 if (bv_->theLockingInset() && inset_slept) {
1223 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1224 inset_slept = false;
1229 void BufferView::Pimpl::insetUnlock()
1231 if (bv_->theLockingInset()) {
1233 bv_->theLockingInset()->insetUnlock(bv_);
1234 bv_->theLockingInset(0);
1236 inset_slept = false;
1241 bool BufferView::Pimpl::focus() const
1243 return workarea_.hasFocus();
1247 void BufferView::Pimpl::focus(bool f)
1249 if (f) workarea_.setFocus();
1253 bool BufferView::Pimpl::active() const
1255 return workarea_.active();
1259 bool BufferView::Pimpl::belowMouse() const
1261 return workarea_.belowMouse();
1265 void BufferView::Pimpl::showCursor()
1267 if (screen_.get()) {
1268 if (bv_->theLockingInset())
1269 bv_->theLockingInset()->showInsetCursor(bv_);
1271 screen_->showCursor(bv_->text, bv_);
1276 void BufferView::Pimpl::hideCursor()
1278 if (screen_.get()) {
1279 if (!bv_->theLockingInset())
1280 // bv_->theLockingInset()->hideInsetCursor(bv_);
1282 screen_->hideCursor();
1287 void BufferView::Pimpl::toggleSelection(bool b)
1289 if (screen_.get()) {
1290 if (bv_->theLockingInset())
1291 bv_->theLockingInset()->toggleSelection(bv_, b);
1292 screen_->toggleSelection(bv_->text, bv_, b);
1297 void BufferView::Pimpl::toggleToggle()
1300 screen_->toggleToggle(bv_->text, bv_);
1304 void BufferView::Pimpl::center()
1306 beforeChange(bv_->text);
1307 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1308 screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1310 screen_->draw(bv_->text, bv_, 0);
1312 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1317 void BufferView::Pimpl::pasteClipboard(bool asPara)
1319 if (!buffer_) return;
1321 screen_->hideCursor();
1322 beforeChange(bv_->text);
1324 string const clip(workarea_.getClipboard());
1326 if (clip.empty()) return;
1329 bv_->text->insertStringAsParagraphs(bv_, clip);
1331 bv_->text->insertStringAsLines(bv_, clip);
1333 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1337 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1339 workarea_.putClipboard(stuff);
1344 * Dispatch functions for actions which can be valid for BufferView->text
1345 * and/or InsetText->text!!!
1350 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1352 LyXText * lt = bv_->getLyXText();
1354 if (selecting || lt->selection.mark()) {
1355 lt->setSelection(bv_);
1359 update(lt, BufferView::SELECT|BufferView::FITCUR);
1362 /* ---> Everytime the cursor is moved, show the current font state. */
1363 // should this too me moved out of this func?
1364 //owner->showState();
1369 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1371 LyXCursor cursor = bv_->getLyXText()->cursor;
1372 Buffer::inset_iterator it =
1373 find_if(Buffer::inset_iterator(
1374 cursor.par(), cursor.pos()),
1375 buffer_->inset_iterator_end(),
1376 lyx::compare_memfun(&Inset::lyxCode, code));
1377 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1381 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1383 string filename = filen;
1385 if (filename.empty()) {
1386 // Launch a file browser
1387 string initpath = lyxrc.document_path;
1390 string const trypath = owner_->buffer()->filepath;
1391 // If directory is writeable, use this as default.
1392 if (IsDirWriteable(trypath) == 1)
1396 FileDialog fileDlg(bv_->owner(),
1397 _("Select LyX document to insert"),
1399 make_pair(string(_("Documents")),
1400 string(lyxrc.document_path)),
1401 make_pair(string(_("Examples")),
1402 string(AddPath(system_lyxdir, "examples"))));
1404 FileDialog::Result result =
1405 fileDlg.Select(initpath,
1406 _("*.lyx| LyX Documents (*.lyx)"));
1408 if (result.first == FileDialog::Later)
1411 filename = result.second;
1413 // check selected filename
1414 if (filename.empty()) {
1415 owner_->message(_("Canceled."));
1420 // get absolute path of file and add ".lyx" to the filename if
1422 filename = FileSearch(string(), filename, "lyx");
1424 string const disp_fn(MakeDisplayPath(filename));
1427 s1 << _("Inserting document") << ' '
1428 << disp_fn << " ...";
1429 owner_->message(s1.str().c_str());
1430 bool const res = bv_->insertLyXFile(filename);
1433 str << _("Document") << ' ' << disp_fn
1434 << ' ' << _("inserted.");
1435 owner_->message(str.str().c_str());
1438 str << _("Could not insert document") << ' '
1440 owner_->message(str.str().c_str());
1445 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1447 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1448 << action <<"] arg[" << argument << "]" << endl;
1451 // --- Misc -------------------------------------------
1455 LyXText * lt = bv_->getLyXText();
1456 lt->toggleAppendix(bv_);
1459 | BufferView::FITCUR
1460 | BufferView::CHANGE);
1465 case LFUN_TOC_INSERT:
1467 InsetCommandParams p;
1468 p.setCmdName("tableofcontents");
1469 Inset * inset = new InsetTOC(p);
1470 if (!insertInset(inset, "Standard"))
1475 case LFUN_TABULAR_FEATURE:
1476 case LFUN_SCROLL_INSET:
1477 // this is not handled here as this funktion is only aktive
1478 // if we have a locking_inset and that one is (or contains)
1482 case LFUN_INSET_GRAPHICS:
1484 Inset * new_inset = new InsetGraphics;
1485 if (!insertInset(new_inset)) {
1488 // this is need because you don't use a inset->Edit()
1489 updateInset(new_inset, true);
1490 new_inset->edit(bv_);
1500 case LFUN_PASTESELECTION:
1502 bool asPara = false;
1503 if (argument == "paragraph") asPara = true;
1504 pasteClipboard(asPara);
1516 case LFUN_LAYOUT_COPY:
1517 bv_->copyEnvironment();
1520 case LFUN_LAYOUT_PASTE:
1521 bv_->pasteEnvironment();
1525 case LFUN_GOTOERROR:
1526 gotoInset(Inset::ERROR_CODE, false);
1530 gotoInset(Inset::IGNORE_CODE, false);
1533 case LFUN_REFERENCE_GOTO:
1535 vector<Inset::Code> tmp;
1536 tmp.push_back(Inset::LABEL_CODE);
1537 tmp.push_back(Inset::REF_CODE);
1538 gotoInset(tmp, true);
1542 case LFUN_HYPHENATION:
1543 specialChar(InsetSpecialChar::HYPHENATION);
1546 case LFUN_LIGATURE_BREAK:
1547 specialChar(InsetSpecialChar::LIGATURE_BREAK);
1551 specialChar(InsetSpecialChar::LDOTS);
1554 case LFUN_END_OF_SENTENCE:
1555 specialChar(InsetSpecialChar::END_OF_SENTENCE);
1558 case LFUN_MENU_SEPARATOR:
1559 specialChar(InsetSpecialChar::MENU_SEPARATOR);
1567 changeDepth(bv_, bv_->getLyXText(), 0);
1570 case LFUN_DEPTH_MIN:
1571 changeDepth(bv_, bv_->getLyXText(), -1);
1574 case LFUN_DEPTH_PLUS:
1575 changeDepth(bv_, bv_->getLyXText(), 1);
1579 owner_->getDialogs()->setUserFreeFont();
1586 owner_->showState();
1590 case LFUN_FILE_INSERT:
1592 MenuInsertLyXFile(argument);
1596 case LFUN_FILE_INSERT_ASCII_PARA:
1597 InsertAsciiFile(bv_, argument, true);
1600 case LFUN_FILE_INSERT_ASCII:
1601 InsertAsciiFile(bv_, argument, false);
1606 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1607 << argument << endl;
1609 // Derive layout number from given argument (string)
1610 // and current buffer's textclass (number). */
1611 LyXTextClassList::ClassList::size_type tclass =
1612 buffer_->params.textclass;
1613 pair <bool, LyXTextClass::size_type> layout =
1614 textclasslist.NumberOfLayout(tclass, argument);
1616 // If the entry is obsolete, use the new one instead.
1618 string obs = textclasslist.Style(tclass,layout.second)
1622 textclasslist.NumberOfLayout(tclass, obs);
1625 // see if we found the layout number:
1626 if (!layout.first) {
1627 owner_->getLyXFunc()->setErrorMessage(
1628 string(N_("Layout ")) + argument +
1633 if (current_layout != layout.second) {
1634 LyXText * lt = bv_->getLyXText();
1636 current_layout = layout.second;
1639 | BufferView::FITCUR);
1640 lt->setLayout(bv_, layout.second);
1641 owner_->setLayout(layout.second);
1644 | BufferView::FITCUR
1645 | BufferView::CHANGE);
1652 Lang(bv_, argument);
1654 owner_->showState();
1659 owner_->showState();
1664 owner_->showState();
1669 owner_->showState();
1674 owner_->showState();
1679 owner_->showState();
1684 owner_->showState();
1689 owner_->showState();
1692 case LFUN_UNDERLINE:
1694 owner_->showState();
1697 case LFUN_FONT_SIZE:
1698 FontSize(bv_, argument);
1699 owner_->showState();
1702 case LFUN_FONT_STATE:
1703 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1706 case LFUN_UPCASE_WORD:
1708 LyXText * lt = bv_->getLyXText();
1712 | BufferView::FITCUR);
1713 lt->changeCase(bv_, LyXText::text_uppercase);
1714 if (lt->inset_owner)
1715 updateInset(lt->inset_owner, true);
1718 | BufferView::FITCUR
1719 | BufferView::CHANGE);
1723 case LFUN_LOWCASE_WORD:
1725 LyXText * lt = bv_->getLyXText();
1727 update(lt, BufferView::SELECT|BufferView::FITCUR);
1728 lt->changeCase(bv_, LyXText::text_lowercase);
1729 if (lt->inset_owner)
1730 updateInset(lt->inset_owner, true);
1733 | BufferView::FITCUR
1734 | BufferView::CHANGE);
1738 case LFUN_CAPITALIZE_WORD:
1740 LyXText * lt = bv_->getLyXText();
1742 update(lt, BufferView::SELECT|BufferView::FITCUR);
1743 lt->changeCase(bv_, LyXText::text_capitalization);
1744 if (lt->inset_owner)
1745 updateInset(lt->inset_owner, true);
1748 | BufferView::FITCUR
1749 | BufferView::CHANGE);
1753 case LFUN_TRANSPOSE_CHARS:
1755 LyXText * lt = bv_->getLyXText();
1757 update(lt, BufferView::SELECT|BufferView::FITCUR);
1758 lt->transposeChars(*bv_);
1759 if (lt->inset_owner)
1760 updateInset(lt->inset_owner, true);
1763 | BufferView::FITCUR
1764 | BufferView::CHANGE);
1769 case LFUN_INSERT_LABEL:
1770 MenuInsertLabel(bv_, argument);
1773 case LFUN_REF_INSERT:
1774 if (argument.empty()) {
1775 InsetCommandParams p("ref");
1776 owner_->getDialogs()->createRef(p.getAsString());
1778 InsetCommandParams p;
1779 p.setFromString(argument);
1781 InsetRef * inset = new InsetRef(p, *buffer_);
1782 if (!insertInset(inset))
1785 updateInset(inset, true);
1789 case LFUN_BOOKMARK_SAVE:
1790 savePosition(strToUnsignedInt(argument));
1793 case LFUN_BOOKMARK_GOTO:
1794 restorePosition(strToUnsignedInt(argument));
1799 string label(argument);
1800 if (label.empty()) {
1802 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1804 label = inset->getContents();
1809 if (!label.empty()) {
1810 //bv_->savePosition(0);
1811 if (!bv_->gotoLabel(label))
1812 WriteAlert(_("Error"),
1813 _("Couldn't find this label"),
1814 _("in current document."));
1819 // --- Cursor Movements -----------------------------
1822 LyXText * lt = bv_->getLyXText();
1824 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1825 if (!lt->selection.mark())
1827 update(lt, BufferView::SELECT|BufferView::FITCUR);
1829 lt->cursorLeft(bv_, false);
1830 if (lt->cursor.pos() < lt->cursor.par()->size()
1831 && lt->cursor.par()->getChar(lt->cursor.pos())
1832 == Paragraph::META_INSET
1833 && lt->cursor.par()->getInset(lt->cursor.pos())
1834 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1835 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1836 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1838 tmpinset->edit(bv_, false);
1840 tmpinset->edit(bv_);
1844 lt->cursorRight(bv_, false);
1846 moveCursorUpdate(false);
1847 owner_->showState();
1853 // This is soooo ugly. Isn`t it possible to make
1854 // it simpler? (Lgb)
1855 LyXText * lt = bv_->getLyXText();
1856 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1857 if (!lt->selection.mark())
1859 update(lt, BufferView::SELECT|BufferView::FITCUR);
1860 LyXCursor const cur = lt->cursor;
1862 lt->cursorLeft(bv_, false);
1863 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1864 lt->cursor.pos() < lt->cursor.par()->size() &&
1865 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1866 Paragraph::META_INSET) &&
1867 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1868 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1869 == Inset::HIGHLY_EDITABLE))
1871 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1872 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1874 tmpinset->edit(bv_);
1876 tmpinset->edit(bv_, false);
1880 lt->cursorRight(bv_, false);
1883 moveCursorUpdate(false);
1884 owner_->showState();
1890 LyXText * lt = bv_->getLyXText();
1892 if (!lt->selection.mark())
1894 update(lt, BufferView::UPDATE);
1897 moveCursorUpdate(false);
1898 owner_->showState();
1904 LyXText * lt = bv_->getLyXText();
1906 if (!lt->selection.mark())
1908 update(lt, BufferView::UPDATE);
1909 lt->cursorDown(bv_);
1911 moveCursorUpdate(false);
1912 owner_->showState();
1916 case LFUN_UP_PARAGRAPH:
1918 LyXText * lt = bv_->getLyXText();
1920 if (!lt->selection.mark())
1922 update(lt, BufferView::UPDATE);
1923 lt->cursorUpParagraph(bv_);
1925 moveCursorUpdate(false);
1926 owner_->showState();
1930 case LFUN_DOWN_PARAGRAPH:
1932 LyXText * lt = bv_->getLyXText();
1934 if (!lt->selection.mark())
1936 update(lt, BufferView::UPDATE);
1937 lt->cursorDownParagraph(bv_);
1939 moveCursorUpdate(false);
1940 owner_->showState();
1946 LyXText * lt = bv_->getLyXText();
1948 if (!lt->selection.mark())
1950 update(lt, BufferView::UPDATE);
1953 moveCursorUpdate(false);
1954 owner_->showState();
1960 LyXText * lt = bv_->getLyXText();
1962 if (!lt->selection.mark())
1964 update(lt, BufferView::UPDATE);
1967 moveCursorUpdate(false);
1968 owner_->showState();
1974 LyXText * lt = bv_->getLyXText();
1976 if (!lt->selection.mark())
1978 update(lt, BufferView::SELECT|BufferView::FITCUR);
1979 lt->cursorHome(bv_);
1981 moveCursorUpdate(false);
1982 owner_->showState();
1988 LyXText * lt = bv_->getLyXText();
1990 if (!lt->selection.mark())
1993 BufferView::SELECT|BufferView::FITCUR);
1996 moveCursorUpdate(false);
1997 owner_->showState();
2001 case LFUN_SHIFT_TAB:
2004 LyXText * lt = bv_->getLyXText();
2006 if (!lt->selection.mark())
2009 BufferView::SELECT|BufferView::FITCUR);
2012 moveCursorUpdate(false);
2013 owner_->showState();
2017 case LFUN_WORDRIGHT:
2019 LyXText * lt = bv_->getLyXText();
2021 if (!lt->selection.mark())
2023 update(lt, BufferView::SELECT|BufferView::FITCUR);
2024 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2025 lt->cursorLeftOneWord(bv_);
2027 lt->cursorRightOneWord(bv_);
2029 moveCursorUpdate(false);
2030 owner_->showState();
2036 LyXText * lt = bv_->getLyXText();
2038 if (!lt->selection.mark())
2040 update(lt, BufferView::SELECT|BufferView::FITCUR);
2041 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2042 lt->cursorRightOneWord(bv_);
2044 lt->cursorLeftOneWord(bv_);
2046 moveCursorUpdate(false);
2047 owner_->showState();
2051 case LFUN_BEGINNINGBUF:
2053 LyXText * lt = bv_->getLyXText();
2055 if (!lt->selection.mark())
2058 BufferView::SELECT|BufferView::FITCUR);
2061 moveCursorUpdate(false);
2062 owner_->showState();
2068 LyXText * lt = bv_->getLyXText();
2070 if (!lt->selection.mark())
2073 BufferView::SELECT|BufferView::FITCUR);
2074 lt->cursorBottom(bv_);
2076 moveCursorUpdate(false);
2077 owner_->showState();
2081 /* cursor selection ---------------------------- */
2084 LyXText * lt = bv_->getLyXText();
2087 BufferView::SELECT|BufferView::FITCUR);
2088 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2089 lt->cursorLeft(bv_);
2091 lt->cursorRight(bv_);
2093 moveCursorUpdate(true);
2094 owner_->showState();
2100 LyXText * lt = bv_->getLyXText();
2103 BufferView::SELECT|BufferView::FITCUR);
2104 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2105 lt->cursorRight(bv_);
2107 lt->cursorLeft(bv_);
2109 moveCursorUpdate(true);
2110 owner_->showState();
2116 LyXText * lt = bv_->getLyXText();
2119 BufferView::SELECT|BufferView::FITCUR);
2122 moveCursorUpdate(true);
2123 owner_->showState();
2129 LyXText * lt = bv_->getLyXText();
2132 BufferView::SELECT|BufferView::FITCUR);
2133 lt->cursorDown(bv_);
2135 moveCursorUpdate(true);
2136 owner_->showState();
2140 case LFUN_UP_PARAGRAPHSEL:
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 lt->cursorUpParagraph(bv_);
2148 moveCursorUpdate(true);
2149 owner_->showState();
2153 case LFUN_DOWN_PARAGRAPHSEL:
2155 LyXText * lt = bv_->getLyXText();
2158 BufferView::SELECT|BufferView::FITCUR);
2159 lt->cursorDownParagraph(bv_);
2161 moveCursorUpdate(true);
2162 owner_->showState();
2168 LyXText * lt = bv_->getLyXText();
2170 update(lt, BufferView::SELECT|BufferView::FITCUR);
2173 moveCursorUpdate(true);
2174 owner_->showState();
2180 LyXText * lt = bv_->getLyXText();
2182 update(lt, BufferView::SELECT|BufferView::FITCUR);
2185 moveCursorUpdate(true);
2186 owner_->showState();
2192 LyXText * lt = bv_->getLyXText();
2194 update(lt, BufferView::SELECT|BufferView::FITCUR);
2195 lt->cursorHome(bv_);
2197 moveCursorUpdate(true);
2198 owner_->showState();
2204 LyXText * lt = bv_->getLyXText();
2206 update(lt, BufferView::SELECT|BufferView::FITCUR);
2209 moveCursorUpdate(true);
2210 owner_->showState();
2214 case LFUN_WORDRIGHTSEL:
2216 LyXText * lt = bv_->getLyXText();
2218 update(lt, BufferView::SELECT|BufferView::FITCUR);
2219 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2220 lt->cursorLeftOneWord(bv_);
2222 lt->cursorRightOneWord(bv_);
2224 moveCursorUpdate(true);
2225 owner_->showState();
2229 case LFUN_WORDLEFTSEL:
2231 LyXText * lt = bv_->getLyXText();
2233 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2235 lt->cursorRightOneWord(bv_);
2237 lt->cursorLeftOneWord(bv_);
2239 moveCursorUpdate(true);
2240 owner_->showState();
2244 case LFUN_BEGINNINGBUFSEL:
2246 LyXText * lt = bv_->getLyXText();
2248 if (lt->inset_owner)
2250 update(lt, BufferView::SELECT|BufferView::FITCUR);
2253 moveCursorUpdate(true);
2254 owner_->showState();
2258 case LFUN_ENDBUFSEL:
2260 LyXText * lt = bv_->getLyXText();
2262 if (lt->inset_owner)
2265 BufferView::SELECT|BufferView::FITCUR);
2266 lt->cursorBottom(bv_);
2268 moveCursorUpdate(true);
2269 owner_->showState();
2273 // --- text changing commands ------------------------
2274 case LFUN_BREAKLINE:
2276 LyXText * lt = bv_->getLyXText();
2279 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2282 | BufferView::FITCUR
2283 | BufferView::CHANGE);
2284 moveCursorUpdate(false);
2288 case LFUN_PROTECTEDSPACE:
2290 LyXText * lt = bv_->getLyXText();
2292 LyXLayout const & style = textclasslist
2293 .Style(buffer_->params.textclass,
2294 lt->cursor.par()->getLayout());
2296 if (style.free_spacing) {
2297 lt->insertChar(bv_, ' ');
2300 | BufferView::FITCUR
2301 | BufferView::CHANGE);
2305 moveCursorUpdate(false);
2311 LyXText * lt = bv_->getLyXText();
2313 if (lt->selection.mark()) {
2317 | BufferView::FITCUR);
2318 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2321 lt->selection.mark(true);
2324 | BufferView::FITCUR);
2325 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2327 lt->selection.cursor = lt->cursor;
2333 LyXText * lt = bv_->getLyXText();
2335 if (!lt->selection.set()) {
2337 lt->selection.cursor = lt->cursor;
2340 | BufferView::FITCUR
2341 | BufferView::CHANGE);
2342 // It is possible to make it a lot faster still
2343 // just comment out the line below...
2348 moveCursorUpdate(false);
2349 owner_->showState();
2354 case LFUN_DELETE_SKIP:
2356 LyXText * lt = bv_->getLyXText();
2358 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2360 LyXCursor cursor = lt->cursor;
2362 if (!lt->selection.set()) {
2363 if (cursor.pos() == cursor.par()->size()) {
2364 lt->cursorRight(bv_);
2365 cursor = lt->cursor;
2366 if (cursor.pos() == 0
2367 && !(cursor.par()->params().spaceTop()
2368 == VSpace (VSpace::NONE))) {
2371 cursor.par()->params().lineTop(),
2372 cursor.par()->params().lineBottom(),
2373 cursor.par()->params().pagebreakTop(),
2374 cursor.par()->params().pagebreakBottom(),
2375 VSpace(VSpace::NONE),
2376 cursor.par()->params().spaceBottom(),
2377 cursor.par()->params().align(),
2378 cursor.par()->params().labelWidthString(), 0);
2379 lt->cursorLeft(bv_);
2382 | BufferView::FITCUR
2383 | BufferView::CHANGE);
2385 lt->cursorLeft(bv_);
2387 lt->selection.cursor = lt->cursor;
2390 | BufferView::FITCUR
2391 | BufferView::CHANGE);
2395 lt->selection.cursor = lt->cursor;
2398 | BufferView::FITCUR
2399 | BufferView::CHANGE);
2407 /* -------> Delete word forward. */
2408 case LFUN_DELETE_WORD_FORWARD:
2409 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2410 bv_->getLyXText()->deleteWordForward(bv_);
2411 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2412 moveCursorUpdate(false);
2413 owner_->showState();
2416 /* -------> Delete word backward. */
2417 case LFUN_DELETE_WORD_BACKWARD:
2419 LyXText * lt = bv_->getLyXText();
2421 update(lt, BufferView::SELECT|BufferView::FITCUR);
2422 lt->deleteWordBackward(bv_);
2425 | BufferView::FITCUR
2426 | BufferView::CHANGE);
2427 moveCursorUpdate(false);
2428 owner_->showState();
2432 /* -------> Kill to end of line. */
2433 case LFUN_DELETE_LINE_FORWARD:
2435 LyXText * lt = bv_->getLyXText();
2437 update(lt, BufferView::SELECT|BufferView::FITCUR);
2438 lt->deleteLineForward(bv_);
2441 | BufferView::FITCUR
2442 | BufferView::CHANGE);
2443 moveCursorUpdate(false);
2447 /* -------> Set mark off. */
2450 LyXText * lt = bv_->getLyXText();
2453 update(lt, BufferView::SELECT|BufferView::FITCUR);
2454 lt->selection.cursor = lt->cursor;
2455 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2459 /* -------> Set mark on. */
2462 LyXText * lt = bv_->getLyXText();
2465 lt->selection.mark(true);
2466 update(lt, BufferView::SELECT|BufferView::FITCUR);
2467 lt->selection.cursor = lt->cursor;
2468 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2472 case LFUN_BACKSPACE:
2474 LyXText * lt = bv_->getLyXText();
2476 if (!lt->selection.set()) {
2477 if (owner_->getIntl()->getTrans().backspace()) {
2479 lt->selection.cursor = lt->cursor;
2482 | BufferView::FITCUR
2483 | BufferView::CHANGE);
2484 // It is possible to make it a lot faster still
2485 // just comment out the line below...
2491 owner_->showState();
2496 case LFUN_BACKSPACE_SKIP:
2498 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2499 LyXText * lt = bv_->getLyXText();
2501 LyXCursor cursor = lt->cursor;
2503 if (!lt->selection.set()) {
2504 if (cursor.pos() == 0
2505 && !(cursor.par()->params().spaceTop()
2506 == VSpace (VSpace::NONE))) {
2509 cursor.par()->params().lineTop(),
2510 cursor.par()->params().lineBottom(),
2511 cursor.par()->params().pagebreakTop(),
2512 cursor.par()->params().pagebreakBottom(),
2513 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2514 cursor.par()->params().align(),
2515 cursor.par()->params().labelWidthString(), 0);
2518 | BufferView::FITCUR
2519 | BufferView::CHANGE);
2522 lt->selection.cursor = cursor;
2525 | BufferView::FITCUR
2526 | BufferView::CHANGE);
2533 case LFUN_BREAKPARAGRAPH:
2535 LyXText * lt = bv_->getLyXText();
2538 lt->breakParagraph(bv_, 0);
2541 | BufferView::FITCUR
2542 | BufferView::CHANGE);
2543 lt->selection.cursor = lt->cursor;
2545 owner_->showState();
2549 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2551 LyXText * lt = bv_->getLyXText();
2554 lt->breakParagraph(bv_, 1);
2557 | BufferView::FITCUR
2558 | BufferView::CHANGE);
2559 lt->selection.cursor = lt->cursor;
2561 owner_->showState();
2565 case LFUN_BREAKPARAGRAPH_SKIP:
2567 // When at the beginning of a paragraph, remove
2568 // indentation and add a "defskip" at the top.
2569 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2570 LyXText * lt = bv_->getLyXText();
2572 LyXCursor cursor = lt->cursor;
2575 if (cursor.pos() == 0) {
2576 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2579 cursor.par()->params().lineTop(),
2580 cursor.par()->params().lineBottom(),
2581 cursor.par()->params().pagebreakTop(),
2582 cursor.par()->params().pagebreakBottom(),
2583 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2584 cursor.par()->params().align(),
2585 cursor.par()->params().labelWidthString(), 1);
2586 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2590 lt->breakParagraph(bv_, 0);
2591 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2596 | BufferView::FITCUR
2597 | BufferView::CHANGE);
2598 lt->selection.cursor = cursor;
2600 owner_->showState();
2604 case LFUN_PARAGRAPH_SPACING:
2606 LyXText * lt = bv_->getLyXText();
2608 Paragraph * par = lt->cursor.par();
2609 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2610 float cur_value = 1.0;
2611 if (cur_spacing == Spacing::Other) {
2612 cur_value = par->params().spacing().getValue();
2615 istringstream istr(argument.c_str());
2619 Spacing::Space new_spacing = cur_spacing;
2620 float new_value = cur_value;
2622 lyxerr << "Missing argument to `paragraph-spacing'"
2624 } else if (tmp == "single") {
2625 new_spacing = Spacing::Single;
2626 } else if (tmp == "onehalf") {
2627 new_spacing = Spacing::Onehalf;
2628 } else if (tmp == "double") {
2629 new_spacing = Spacing::Double;
2630 } else if (tmp == "other") {
2631 new_spacing = Spacing::Other;
2634 lyxerr << "new_value = " << tmpval << endl;
2637 } else if (tmp == "default") {
2638 new_spacing = Spacing::Default;
2640 lyxerr << _("Unknown spacing argument: ")
2641 << argument << endl;
2643 if (cur_spacing != new_spacing || cur_value != new_value) {
2644 par->params().spacing(Spacing(new_spacing, new_value));
2645 lt->redoParagraph(bv_);
2648 | BufferView::FITCUR
2649 | BufferView::CHANGE);
2654 case LFUN_INSET_TOGGLE:
2656 LyXText * lt = bv_->getLyXText();
2659 update(lt, BufferView::SELECT|BufferView::FITCUR);
2660 lt->toggleInset(bv_);
2661 update(lt, BufferView::SELECT|BufferView::FITCUR);
2673 InsetCommandParams p;
2674 if (action == LFUN_HTMLURL)
2675 p.setCmdName("htmlurl");
2677 p.setCmdName("url");
2678 owner_->getDialogs()->createUrl(p.getAsString());
2682 case LFUN_INSERT_URL:
2684 InsetCommandParams p;
2685 p.setFromString(argument);
2687 InsetUrl * inset = new InsetUrl(p);
2688 if (!insertInset(inset))
2691 updateInset(inset, true);
2695 case LFUN_INSET_TEXT:
2696 insertAndEditInset(new InsetText);
2699 case LFUN_INSET_ERT:
2700 insertAndEditInset(new InsetERT);
2703 case LFUN_INSET_EXTERNAL:
2704 insertAndEditInset(new InsetExternal);
2707 case LFUN_INSET_FOOTNOTE:
2708 insertAndEditInset(new InsetFoot);
2711 case LFUN_INSET_MARGINAL:
2712 insertAndEditInset(new InsetMarginal);
2715 case LFUN_INSET_MINIPAGE:
2716 insertAndEditInset(new InsetMinipage);
2719 case LFUN_INSERT_NOTE:
2720 insertAndEditInset(new InsetNote);
2723 case LFUN_INSET_FLOAT:
2724 // check if the float type exist
2725 if (floatList.typeExist(argument)) {
2726 insertAndEditInset(new InsetFloat(argument));
2728 lyxerr << "Non-existant float type: "
2729 << argument << endl;
2733 case LFUN_INSET_WIDE_FLOAT:
2735 // check if the float type exist
2736 if (floatList.typeExist(argument)) {
2737 InsetFloat * new_inset = new InsetFloat(argument);
2738 new_inset->wide(true);
2739 if (insertInset(new_inset))
2740 new_inset->edit(bv_);
2744 lyxerr << "Non-existant float type: "
2745 << argument << endl;
2752 case LFUN_INSET_LIST:
2753 insertAndEditInset(new InsetList);
2756 case LFUN_INSET_THEOREM:
2757 insertAndEditInset(new InsetTheorem);
2761 case LFUN_INSET_CAPTION:
2763 // Do we have a locking inset...
2764 if (bv_->theLockingInset()) {
2765 lyxerr << "Locking inset code: "
2766 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2767 InsetCaption * new_inset = new InsetCaption;
2768 new_inset->setOwner(bv_->theLockingInset());
2769 new_inset->setAutoBreakRows(true);
2770 new_inset->setDrawFrame(0, InsetText::LOCKED);
2771 new_inset->setFrameColor(0, LColor::captionframe);
2772 if (insertInset(new_inset))
2773 new_inset->edit(bv_);
2780 case LFUN_INSET_TABULAR:
2784 if (!argument.empty())
2785 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2786 InsetTabular * new_inset =
2787 new InsetTabular(*buffer_, r, c);
2789 bv_->getLyXText()->real_current_font.isRightToLeft();
2790 if (!open_new_inset(new_inset, rtl))
2795 // --- lyxserver commands ----------------------------
2797 case LFUN_CHARATCURSOR:
2799 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2800 if (pos < bv_->getLyXText()->cursor.par()->size())
2801 owner_->getLyXFunc()->setMessage(
2802 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2804 owner_->getLyXFunc()->setMessage("EOF");
2809 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2811 + tostr(bv_->getLyXText()->cursor.y()));
2818 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2819 lyxerr << "SETXY: Could not parse coordinates in '"
2820 << argument << std::endl;
2822 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2826 case LFUN_GETLAYOUT:
2827 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2832 LyXFont & font = bv_->getLyXText()->current_font;
2833 if (font.shape() == LyXFont::ITALIC_SHAPE)
2834 owner_->getLyXFunc()->setMessage("E");
2835 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2836 owner_->getLyXFunc()->setMessage("N");
2838 owner_->getLyXFunc()->setMessage("0");
2846 LyXFont & font = bv_->getLyXText()->current_font;
2847 if (font.latex() == LyXFont::ON)
2848 owner_->getLyXFunc()->setMessage("L");
2851 owner_->getLyXFunc()->setMessage("0");
2855 // --- accented characters ---------------------------
2858 case LFUN_CIRCUMFLEX:
2868 case LFUN_SPECIAL_CARON:
2871 case LFUN_HUNG_UMLAUT:
2874 if (argument.empty()) {
2876 owner_->getLyXFunc()->handleKeyFunc(action);
2878 owner_->getLyXFunc()->handleKeyFunc(action);
2879 owner_->getIntl()->getTrans()
2880 .TranslateAndInsert(argument[0], bv_->getLyXText());
2881 update(bv_->getLyXText(),
2883 | BufferView::FITCUR
2884 | BufferView::CHANGE);
2888 case LFUN_MATH_MACRO:
2889 mathDispatchMathMacro(bv_, argument);
2892 case LFUN_MATH_DELIM:
2893 mathDispatchMathDelim(bv_, argument);
2896 case LFUN_INSERT_MATRIX:
2897 mathDispatchInsertMatrix(bv_, argument);
2900 case LFUN_INSERT_MATH:
2901 mathDispatchInsertMath(bv_, argument);
2904 case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
2905 mathDispatchMathImportSelection(bv_, argument);
2908 case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
2909 mathDispatchMathDisplay(bv_, argument);
2912 case LFUN_MATH_MODE: // Open or create an inlined math inset
2913 mathDispatchMathMode(bv_, argument);
2916 case LFUN_CITATION_INSERT:
2918 InsetCommandParams p;
2919 p.setFromString( argument );
2921 InsetCitation * inset = new InsetCitation( p );
2922 if (!insertInset(inset))
2925 updateInset( inset, true );
2929 case LFUN_INSERT_BIBTEX:
2931 // ale970405+lasgoutt970425
2932 // The argument can be up to two tokens separated
2933 // by a space. The first one is the bibstyle.
2934 string const db = token(argument, ' ', 0);
2935 string bibstyle = token(argument, ' ', 1);
2936 if (bibstyle.empty())
2939 InsetCommandParams p( "BibTeX", db, bibstyle );
2940 InsetBibtex * inset = new InsetBibtex(p);
2942 if (insertInset(inset)) {
2943 if (argument.empty())
2950 // BibTeX data bases
2951 case LFUN_BIBDB_ADD:
2953 InsetBibtex * inset =
2954 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2956 inset->addDatabase(argument);
2961 case LFUN_BIBDB_DEL:
2963 InsetBibtex * inset =
2964 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2966 inset->delDatabase(argument);
2971 case LFUN_BIBTEX_STYLE:
2973 InsetBibtex * inset =
2974 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2976 inset->setOptions(argument);
2981 case LFUN_INDEX_CREATE:
2983 InsetCommandParams p("index");
2984 LyXText * lt = bv_->getLyXText();
2986 if (argument.empty()) {
2987 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
2988 if (!idxstring.empty())
2989 p.setContents(idxstring);
2993 p.setContents(argument);
2996 owner_->getDialogs()->createIndex(p.getAsString());
3000 case LFUN_INDEX_INSERT:
3002 InsetCommandParams p;
3003 p.setFromString(argument);
3004 InsetIndex * inset = new InsetIndex(p);
3006 if (!insertInset(inset))
3009 updateInset(inset, true);
3013 case LFUN_INDEX_INSERT_LAST:
3015 string const idxstring(bv_->getLyXText()->getStringToIndex(bv_));
3016 if (!idxstring.empty()) {
3017 owner_->message(_("Word `")
3018 + idxstring + _(("' indexed.")));
3019 InsetCommandParams p("index", idxstring);
3020 InsetIndex * inset = new InsetIndex(p);
3022 if (!insertInset(inset))
3025 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_THESAURUS_ENTRY:
3077 string arg = argument;
3080 arg = bv_->getLyXText()->selectionAsString(buffer_);
3083 if (arg.size() > 100 || arg.empty()) {
3084 // Get word or selection
3085 bv_->getLyXText()->selectWordWhenUnderCursor(bv_, LyXText::WHOLE_WORD);
3086 arg = bv_->getLyXText()->selectionAsString(buffer_);
3087 // FIXME: where is getLyXText()->unselect(bv_) ?
3091 bv_->owner()->getDialogs()->showThesaurus(arg);
3095 case LFUN_SELFINSERT:
3097 if (argument.empty()) break;
3099 /* Automatically delete the currently selected
3100 * text and replace it with what is being
3101 * typed in now. Depends on lyxrc settings
3102 * "auto_region_delete", which defaults to
3105 LyXText * lt = bv_->getLyXText();
3107 if (lyxrc.auto_region_delete) {
3108 if (lt->selection.set()) {
3109 lt->cutSelection(bv_, false);
3112 | BufferView::FITCUR
3113 | BufferView::CHANGE);
3118 LyXFont const old_font(lt->real_current_font);
3120 string::const_iterator cit = argument.begin();
3121 string::const_iterator end = argument.end();
3122 for (; cit != end; ++cit) {
3123 if (greek_kb_flag) {
3124 if (!math_insert_greek(bv_, *cit))
3125 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3127 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3132 | BufferView::FITCUR
3133 | BufferView::CHANGE);
3135 lt->selection.cursor = lt->cursor;
3136 moveCursorUpdate(false);
3138 // real_current_font.number can change so we need to
3139 // update the minibuffer
3140 if (old_font != lt->real_current_font)
3141 owner_->showState();
3146 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3148 time_t now_time_t = time(NULL);
3149 struct tm * now_tm = localtime(&now_time_t);
3150 setlocale(LC_TIME, "");
3152 if (!argument.empty())
3155 arg = lyxrc.date_insert_format;
3157 int const datetmp_len =
3158 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3160 LyXText * lt = bv_->getLyXText();
3162 for (int i = 0; i < datetmp_len; i++) {
3163 lt->insertChar(bv_, datetmp[i]);
3166 | BufferView::FITCUR
3167 | BufferView::CHANGE);
3170 lt->selection.cursor = lt->cursor;
3171 moveCursorUpdate(false);
3175 case LFUN_UNKNOWN_ACTION:
3176 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3187 void BufferView::Pimpl::newline()
3190 LyXText * lt = bv_->getLyXText();
3194 | BufferView::FITCUR);
3195 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3198 | BufferView::FITCUR
3199 | BufferView::CHANGE);
3204 void BufferView::Pimpl::hfill()
3207 LyXText * lt = bv_->getLyXText();
3211 | BufferView::FITCUR);
3212 lt->insertChar(bv_, Paragraph::META_HFILL);
3215 | BufferView::FITCUR
3216 | BufferView::CHANGE);
3221 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3225 update(lt, BufferView::SELECT|BufferView::FITCUR);
3226 InsetSpecialChar * new_inset =
3227 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3228 #ifdef WITH_WARNINGS
3229 #warning Why is this code different from specialChar() below? (JMarc)
3230 // the code in specialChar is a generic version of what used to exist
3231 // for other special chars. I did not merge this case because of the
3232 // call to updateInset(), but what does it do?
3234 if (!insertInset(new_inset))
3237 updateInset(new_inset, true);
3242 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
3245 LyXText * lt = bv_->getLyXText();
3248 update(lt, BufferView::SELECT|BufferView::FITCUR);
3249 InsetSpecialChar * new_inset =
3250 new InsetSpecialChar(kind);
3251 insertInset(new_inset);
3256 void BufferView::Pimpl::smartQuote()
3259 LyXText * lt = bv_->getLyXText();
3261 if (lt->cursor.pos())
3262 c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
3267 if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
3268 Dispatch(LFUN_SELFINSERT, "\"");
3272 void BufferView::Pimpl::insertAndEditInset(Inset * inset)
3274 if (insertInset(inset))
3281 // Open and lock an updatable inset
3282 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3284 LyXText * lt = bv_->getLyXText();
3288 if (!insertInset(new_inset)) {
3292 new_inset->edit(bv_, !behind);
3297 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3299 // if we are in a locking inset we should try to insert the
3300 // inset there otherwise this is a illegal function now
3301 if (bv_->theLockingInset()) {
3302 if (bv_->theLockingInset()->insetAllowed(inset))
3303 return bv_->theLockingInset()->insertInset(bv_, inset);
3307 // not quite sure if we want this...
3308 setCursorParUndo(bv_);
3311 beforeChange(bv_->text);
3312 if (!lout.empty()) {
3313 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3314 bv_->text->breakParagraph(bv_);
3315 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3317 if (bv_->text->cursor.par()->size()) {
3318 bv_->text->cursorLeft(bv_);
3320 bv_->text->breakParagraph(bv_);
3321 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3324 pair<bool, LyXTextClass::size_type> lres =
3325 textclasslist.NumberOfLayout(buffer_->params
3327 LyXTextClass::size_type lay;
3328 if (lres.first != false) {
3332 // layout not fount using default "Standard" (0)
3336 bv_->text->setLayout(bv_, lay);
3338 bv_->text->setParagraph(bv_, 0, 0,
3340 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3344 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3346 bv_->text->current_font.setLatex(LyXFont::OFF);
3350 bv_->text->insertInset(bv_, inset);
3351 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3358 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3363 // first check for locking insets
3364 if (bv_->theLockingInset()) {
3365 if (bv_->theLockingInset() == inset) {
3366 if (bv_->text->updateInset(bv_, inset)) {
3369 buffer_->markDirty();
3374 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3375 if (bv_->text->updateInset(bv_,
3376 bv_->theLockingInset())) {
3379 buffer_->markDirty();
3387 // then check the current buffer
3390 update(bv_->text, BufferView::UPDATE);
3391 if (bv_->text->updateInset(bv_, inset)) {
3395 | BufferView::FITCUR
3396 | BufferView::CHANGE);
3398 update(bv_->text, SELECT);
3406 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3409 if (!available()) return;
3412 beforeChange(bv_->text);
3413 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3417 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3418 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3419 if (find(codes.begin(), codes.end(), inset->lyxCode())
3422 static_cast<InsetCommand const *>(inset)->getContents();
3425 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3426 if (bv_->text->cursor.pos()
3427 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3428 LyXCursor tmp = bv_->text->cursor;
3429 bv_->text->cursor.par(bv_->text->firstParagraph());
3430 bv_->text->cursor.pos(0);
3431 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3432 bv_->text->cursor = tmp;
3433 bv_->owner()->message(_("No more insets"));
3436 bv_->owner()->message(_("No more insets"));
3439 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3440 bv_->text->selection.cursor = bv_->text->cursor;
3444 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3446 gotoInset(vector<Inset::Code>(1, code), same_content);