12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
21 #include "bufferview_funcs.h"
22 #include "TextCache.h"
23 #include "bufferlist.h"
24 #include "lyx_gui_misc.h"
27 #include "support/LAssert.h"
28 #include "frontends/Dialogs.h"
29 #include "insets/insetbib.h"
30 #include "insets/insettext.h"
31 /// added for Dispatch functions
33 #include "frontends/FileDialog.h"
35 #include "FloatList.h"
36 #include "support/filetools.h"
37 #include "support/lyxfunctional.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetinfo.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "insets/insetfloatlist.h"
59 #include "insets/insetspecialchar.h"
60 #include "mathed/formulamacro.h"
61 #include "mathed/formula.h"
63 #include "ParagraphParameters.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 sigchldhandler(pid_t pid, int * status);
86 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
90 const unsigned int saved_positions_num = 20;
95 XSync(fl_get_display(), 0);
99 void SetXtermCursor(Window win)
101 static Cursor cursor;
102 static bool cursor_undefined = true;
103 if (cursor_undefined){
104 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
105 XFlush(fl_get_display());
106 cursor_undefined = false;
108 XDefineCursor(fl_get_display(), win, cursor);
109 XFlush(fl_get_display());
115 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
116 int xpos, int ypos, int width, int height)
117 : bv_(b), owner_(o), buffer_(0),
118 current_scrollbar_value(0), cursor_timeout(400),
119 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
123 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
124 workarea_.workAreaExpose
125 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
126 workarea_.workAreaEnter
127 .connect(slot(this, &BufferView::Pimpl::enterView));
128 workarea_.workAreaLeave
129 .connect(slot(this, &BufferView::Pimpl::leaveView));
130 workarea_.workAreaButtonPress
131 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
132 workarea_.workAreaButtonRelease
134 &BufferView::Pimpl::workAreaButtonRelease));
135 workarea_.workAreaMotionNotify
136 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
137 workarea_.workAreaDoubleClick
138 .connect(slot(this, &BufferView::Pimpl::doubleClick));
139 workarea_.workAreaTripleClick
140 .connect(slot(this, &BufferView::Pimpl::tripleClick));
141 workarea_.workAreaKeyPress
142 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
144 cursor_timeout.timeout.connect(slot(this,
145 &BufferView::Pimpl::cursorToggle));
146 cursor_timeout.start();
147 workarea_.setFocus();
148 saved_positions.resize(saved_positions_num);
152 Painter & BufferView::Pimpl::painter()
154 return workarea_.getPainter();
158 void BufferView::Pimpl::buffer(Buffer * b)
160 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
164 buffer_->delUser(bv_);
166 // Put the old text into the TextCache, but
167 // only if the buffer is still loaded.
168 // Also set the owner of the test to 0
169 // bv_->text->owner(0);
170 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
171 if (lyxerr.debugging())
172 textcache.show(lyxerr, "BufferView::buffer");
177 // Set current buffer
180 if (bufferlist.getState() == BufferList::CLOSING) return;
183 // screen is always deleted when the buffer is changed.
186 // If we are closing the buffer, use the first buffer as current
188 buffer_ = bufferlist.first();
192 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
193 buffer_->addUser(bv_);
194 // If we don't have a text object for this, we make one
195 if (bv_->text == 0) {
196 resizeCurrentBuffer();
201 bv_->text->first = screen_->TopCursorVisible(bv_->text);
202 owner_->updateMenubar();
203 owner_->updateToolbar();
204 // Similarly, buffer-dependent dialogs should be updated or
205 // hidden. This should go here because some dialogs (eg ToC)
206 // require bv_->text.
207 owner_->getDialogs()->updateBufferDependent(true);
211 lyxerr[Debug::INFO] << " No Buffer!" << endl;
212 owner_->updateMenubar();
213 owner_->updateToolbar();
214 owner_->getDialogs()->hideBufferDependent();
218 // Also remove all remaining text's from the testcache.
219 // (there should not be any!) (if there is any it is a
221 if (lyxerr.debugging())
222 textcache.show(lyxerr, "buffer delete all");
225 // should update layoutchoice even if we don't have a buffer.
226 owner_->updateLayoutChoice();
228 owner_->updateWindowTitle();
232 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
234 workarea_.resize(xpos, ypos, width, height);
235 update(bv_->text, SELECT);
240 void BufferView::Pimpl::resize()
243 resizeCurrentBuffer();
247 void BufferView::Pimpl::redraw()
249 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
254 bool BufferView::Pimpl::fitCursor(LyXText * text)
256 lyx::Assert(screen_.get());
258 bv_->owner()->getDialogs()->updateParagraph();
260 bool const ret = screen_->FitCursor(text, bv_);
267 void BufferView::Pimpl::redoCurrentBuffer()
269 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
270 if (buffer_ && bv_->text) {
272 owner_->updateLayoutChoice();
277 int BufferView::Pimpl::resizeCurrentBuffer()
279 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
282 Paragraph * selstartpar = 0;
283 Paragraph * selendpar = 0;
284 UpdatableInset * the_locking_inset = 0;
286 Paragraph::size_type pos = 0;
287 Paragraph::size_type selstartpos = 0;
288 Paragraph::size_type selendpos = 0;
289 bool selection = false;
290 bool mark_set = false;
294 owner_->message(_("Formatting document..."));
297 par = bv_->text->cursor.par();
298 pos = bv_->text->cursor.pos();
299 selstartpar = bv_->text->selection.start.par();
300 selstartpos = bv_->text->selection.start.pos();
301 selendpar = bv_->text->selection.end.par();
302 selendpos = bv_->text->selection.end.pos();
303 selection = bv_->text->selection.set();
304 mark_set = bv_->text->selection.mark();
305 the_locking_inset = bv_->theLockingInset();
307 bv_->text = new LyXText(bv_);
309 // See if we have a text in TextCache that fits
310 // the new buffer_ with the correct width.
311 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
313 if (lyxerr.debugging()) {
314 lyxerr << "Found a LyXText that fits:\n";
315 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
317 // Set the owner of the newly found text
318 // bv_->text->owner(bv_);
319 if (lyxerr.debugging())
320 textcache.show(lyxerr, "resizeCurrentBuffer");
322 bv_->text = new LyXText(bv_);
328 bv_->text->selection.set(true);
329 /* at this point just to avoid the Delete-Empty-Paragraph
330 * Mechanism when setting the cursor */
331 bv_->text->selection.mark(mark_set);
333 bv_->text->setCursor(bv_, selstartpar, selstartpos);
334 bv_->text->selection.cursor = bv_->text->cursor;
335 bv_->text->setCursor(bv_, selendpar, selendpos);
336 bv_->text->setSelection(bv_);
337 bv_->text->setCursor(bv_, par, pos);
339 bv_->text->setCursor(bv_, par, pos);
340 bv_->text->selection.cursor = bv_->text->cursor;
341 bv_->text->selection.set(false);
343 // remake the inset locking
344 bv_->theLockingInset(the_locking_inset);
346 bv_->text->first = screen_->TopCursorVisible(bv_->text);
347 buffer_->resizeInsets(bv_);
348 // this will scroll the screen such that the cursor becomes visible
355 /// clear the "Formatting Document" message
358 /// get rid of the splash screen if it's not gone already
359 owner_->getDialogs()->destroySplash();
365 void BufferView::Pimpl::updateScreen()
367 // Regenerate the screen.
368 screen_.reset(new LyXScreen(workarea_));
372 void BufferView::Pimpl::updateScrollbar()
374 /* If the text is smaller than the working area, the scrollbar
375 * maximum must be the working area height. No scrolling will
379 workarea_.setScrollbar(0, 1.0);
383 static unsigned long text_height;
384 static unsigned long work_height;
386 unsigned long const tmp_text_height = bv_->text->height;
387 long const tmp_scrollbar_value = bv_->text->first;
389 // check if anything has changed.
390 if (text_height == tmp_text_height
391 && work_height == workarea_.height()
392 && current_scrollbar_value == tmp_scrollbar_value)
396 text_height = tmp_text_height;
397 work_height = workarea_.height();
398 current_scrollbar_value = tmp_scrollbar_value;
400 long const height_diff = text_height - work_height;
402 if (height_diff <= 0) {
403 workarea_.setScrollbar(0, 1.0);
408 workarea_.setScrollbarBounds(0, height_diff);
409 double const lineh = bv_->text->defaultHeight();
410 workarea_.setScrollbarIncrements(lineh);
411 double const slider_size = 1.0 / double(height_diff) ;
412 workarea_.setScrollbar(current_scrollbar_value, slider_size);
416 // Callback for scrollbar slider
417 void BufferView::Pimpl::scrollCB(double value)
419 if (!buffer_) return;
421 current_scrollbar_value = long(value);
422 if (current_scrollbar_value < 0)
423 current_scrollbar_value = 0;
428 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
430 if (!lyxrc.cursor_follows_scrollbar) {
435 LyXText * vbt = bv_->text;
437 int const height = vbt->defaultHeight();
438 int const first = static_cast<int>((bv_->text->first + height));
439 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
441 if (vbt->cursor.y() < first)
442 vbt->setCursorFromCoordinates(bv_, 0, first);
443 else if (vbt->cursor.y() > last)
444 vbt->setCursorFromCoordinates(bv_, 0, last);
450 int BufferView::Pimpl::scrollUp(long time)
452 if (!buffer_) return 0;
453 if (!screen_.get()) return 0;
455 double value = workarea_.getScrollbarValue();
457 if (value == 0) return 0;
459 float add_value = (bv_->text->defaultHeight()
460 + float(time) * float(time) * 0.125);
462 if (add_value > workarea_.height())
463 add_value = float(workarea_.height() -
464 bv_->text->defaultHeight());
471 workarea_.setScrollbarValue(value);
478 int BufferView::Pimpl::scrollDown(long time)
480 if (!buffer_) return 0;
481 if (!screen_.get()) return 0;
483 double value = workarea_.getScrollbarValue();
484 pair<float, float> p = workarea_.getScrollbarBounds();
485 double const max = p.second;
487 if (value == max) return 0;
489 float add_value = (bv_->text->defaultHeight()
490 + float(time) * float(time) * 0.125);
492 if (add_value > workarea_.height())
493 add_value = float(workarea_.height() -
494 bv_->text->defaultHeight());
501 workarea_.setScrollbarValue(value);
508 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
510 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
514 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
516 // Only use motion with button 1
517 if (!(state & Button1MotionMask))
520 if (!buffer_ || !screen_.get()) return;
522 // Check for inset locking
523 if (bv_->theLockingInset()) {
524 LyXCursor cursor = bv_->text->cursor;
525 LyXFont font = bv_->text->getFont(buffer_,
526 cursor.par(), cursor.pos());
527 int width = bv_->theLockingInset()->width(bv_, font);
528 int inset_x = font.isVisibleRightToLeft()
529 ? cursor.x() - width : cursor.x();
530 int start_x = inset_x + bv_->theLockingInset()->scroll();
531 bv_->theLockingInset()->
532 insetMotionNotify(bv_,
534 y - cursor.y() + bv_->text->first,
539 /* The test for not selection possible is needed, that only motion
540 events are used, where the bottom press event was on
541 the drawing area too */
542 if (!selection_possible)
545 screen_->HideCursor();
547 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
549 if (!bv_->text->selection.set())
550 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
552 bv_->text->setSelection(bv_);
553 screen_->ToggleToggle(bv_->text, bv_);
554 fitCursor(bv_->text);
555 screen_->ShowCursor(bv_->text, bv_);
559 // Single-click on work area
560 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
563 if (!buffer_ || !screen_.get()) return;
565 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
567 // ok ok, this is a hack.
568 if (button == 4 || button == 5) {
571 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
574 scrollDown(lyxrc.wheel_jump);
579 if (bv_->theLockingInset()) {
580 // We are in inset locking mode
582 /* Check whether the inset was hit. If not reset mode,
583 otherwise give the event to the inset */
584 if (inset_hit == bv_->theLockingInset()) {
585 bv_->theLockingInset()->
586 insetButtonPress(bv_,
591 bv_->unlockInset(bv_->theLockingInset());
596 selection_possible = true;
597 screen_->HideCursor();
599 int const screen_first = bv_->text->first;
601 // Middle button press pastes if we have a selection
602 bool paste_internally = false;
604 && bv_->text->selection.set()) {
605 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
606 paste_internally = true;
609 // Clear the selection
610 screen_->ToggleSelection(bv_->text, bv_);
611 bv_->text->clearSelection(bv_);
612 bv_->text->fullRebreak(bv_);
613 screen_->Update(bv_->text, bv_);
616 // Single left click in math inset?
617 if ((inset_hit != 0) &&
618 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
619 // Highly editable inset, like math
620 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
621 selection_possible = false;
622 owner_->updateLayoutChoice();
623 owner_->message(inset->editMessage());
624 inset->insetButtonPress(bv_, xpos, ypos, button);
625 inset->edit(bv_, xpos, ypos, button);
629 // Right click on a footnote flag opens float menu
631 selection_possible = false;
635 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
636 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
637 bv_->text->finishUndo();
638 bv_->text->selection.cursor = bv_->text->cursor;
639 bv_->text->cursor.x_fix(bv_->text->cursor.x());
641 owner_->updateLayoutChoice();
642 if (fitCursor(bv_->text)) {
643 selection_possible = false;
646 // Insert primary selection with middle mouse
647 // if there is a local selection in the current buffer,
650 if (paste_internally)
651 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
653 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
655 selection_possible = false;
661 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
667 LyXText * text = bv_->getLyXText();
669 if (text->bv_owner && bv_->theLockingInset())
672 if (screen_.get() && button == 1) {
673 if (text->bv_owner) {
674 screen_->HideCursor();
675 screen_->ToggleSelection(text, bv_);
676 text->selectWord(bv_);
677 screen_->ToggleSelection(text, bv_, false);
679 text->selectWord(bv_);
681 /* This will fit the cursor on the screen
683 update(text, BufferView::SELECT|BufferView::FITCUR);
688 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
694 LyXText * text = bv_->getLyXText();
696 if (text->bv_owner && bv_->theLockingInset())
699 if (screen_.get() && (button == 1)) {
700 screen_->HideCursor();
701 screen_->ToggleSelection(text, bv_);
702 text->cursorHome(bv_);
703 text->selection.cursor = text->cursor;
704 text->cursorEnd(bv_);
705 text->setSelection(bv_);
706 screen_->ToggleSelection(text, bv_, false);
707 /* This will fit the cursor on the screen
709 update(text, BufferView::SELECT|BufferView::FITCUR);
714 void BufferView::Pimpl::enterView()
716 if (active() && available()) {
717 SetXtermCursor(workarea_.getWin());
718 using_xterm_cursor = true;
723 void BufferView::Pimpl::leaveView()
725 if (using_xterm_cursor) {
726 XUndefineCursor(fl_get_display(), workarea_.getWin());
727 using_xterm_cursor = false;
732 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
735 if (!buffer_ || !screen_.get()) return;
737 // If we hit an inset, we have the inset coordinates in these
738 // and inset_hit points to the inset. If we do not hit an
739 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
740 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
742 if (bv_->theLockingInset()) {
743 // We are in inset locking mode.
745 /* LyX does a kind of work-area grabbing for insets.
746 Only a ButtonPress Event outside the inset will
747 force a insetUnlock. */
748 bv_->theLockingInset()->
749 insetButtonRelease(bv_, x, y, button);
753 selection_possible = false;
761 // Did we hit an editable inset?
763 // Inset like error, notes and figures
764 selection_possible = false;
766 // CHECK fix this proper in 0.13
768 // Following a ref shouldn't issue
769 // a push on the undo-stack
770 // anylonger, now that we have
771 // keybindings for following
772 // references and returning from
773 // references. IMHO though, it
774 // should be the inset's own business
775 // to push or not push on the undo
776 // stack. They don't *have* to
777 // alter the document...
779 // ...or maybe the SetCursorParUndo()
780 // below isn't necessary at all anylonger?
781 if (inset_hit->lyxCode() == Inset::REF_CODE) {
782 bv_->text->setCursorParUndo(buffer_);
785 owner_->message(inset_hit->editMessage());
787 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
788 // Highly editable inset, like math
789 UpdatableInset *inset = (UpdatableInset *)inset_hit;
790 inset->insetButtonRelease(bv_, x, y, button);
792 inset_hit->insetButtonRelease(bv_, x, y, button);
793 inset_hit->edit(bv_, x, y, button);
798 // check whether we want to open a float
802 if (bv_->text->cursor.pos() <
803 bv_->text->cursor.par()->size()) {
804 c = bv_->text->cursor.par()->
805 getChar(bv_->text->cursor.pos());
807 if (bv_->text->cursor.pos() - 1 >= 0) {
808 c = bv_->text->cursor.par()->
809 getChar(bv_->text->cursor.pos() - 1);
812 selection_possible = false;
817 // Maybe we want to edit a bibitem ale970302
818 if (bv_->text->cursor.par()->bibkey && x < 20 +
819 bibitemMaxWidth(bv_, textclasslist.
821 params.textclass).defaultfont())) {
822 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
830 * Returns an inset if inset was hit. 0 otherwise.
831 * If hit, the coordinates are changed relative to the inset.
832 * Otherwise coordinates are not changed, and false is returned.
834 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
835 unsigned int /* button */)
840 int y_tmp = y + text->first;
843 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
844 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
847 if (cursor.pos() < cursor.par()->size()
848 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
849 && cursor.par()->getInset(cursor.pos())
850 && cursor.par()->getInset(cursor.pos())->editable()) {
852 // Check whether the inset really was hit
853 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
854 LyXFont font = text->getFont(buffer_,
855 cursor.par(), cursor.pos());
856 int const width = tmpinset->width(bv_, font);
857 int const inset_x = font.isVisibleRightToLeft()
858 ? cursor.x() - width : cursor.x();
859 int const start_x = inset_x + tmpinset->scroll();
860 int const end_x = inset_x + width;
862 if (x > start_x && x < end_x
863 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
864 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
865 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
867 // The origin of an inset is on the baseline
868 y = y_tmp - (text->cursor.y());
873 if ((cursor.pos() - 1 >= 0) &&
874 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
875 (cursor.par()->getInset(cursor.pos() - 1)) &&
876 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
877 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
878 LyXFont font = text->getFont(buffer_, cursor.par(),
880 int const width = tmpinset->width(bv_, font);
881 int const inset_x = font.isVisibleRightToLeft()
882 ? cursor.x() : cursor.x() - width;
883 int const start_x = inset_x + tmpinset->scroll();
884 int const end_x = inset_x + width;
886 if (x > start_x && x < end_x
887 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
888 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
890 if (move_cursor && (tmpinset != bv_->theLockingInset()))
892 text->setCursor(bv_, cursor.par(),
893 cursor.pos() - 1, true);
895 // The origin of an inset is on the baseline
896 y = y_tmp - (text->cursor.y());
904 void BufferView::Pimpl::workAreaExpose()
906 static int work_area_width;
907 static unsigned int work_area_height;
909 bool const widthChange = workarea_.workWidth() != work_area_width;
910 bool const heightChange = workarea_.height() != work_area_height;
912 // update from work area
913 work_area_width = workarea_.workWidth();
914 work_area_height = workarea_.height();
917 // The visible LyXView need a resize
920 // Remove all texts from the textcache
921 // This is not _really_ what we want to do. What
922 // we really want to do is to delete in textcache
923 // that does not have a BufferView with matching
924 // width, but as long as we have only one BufferView
925 // deleting all gives the same result.
926 if (lyxerr.debugging())
927 textcache.show(lyxerr, "Expose delete all");
929 } else if (heightChange) {
930 // Rebuild image of current screen
932 // fitCursor() ensures we don't jump back
933 // to the start of the document on vertical
935 fitCursor(bv_->text);
937 // The main window size has changed, repaint most stuff
939 } else if (screen_.get())
940 screen_->Redraw(bv_->text, bv_);
942 // Grey box when we don't have a buffer
946 // always make sure that the scrollbar is sane.
948 owner_->updateLayoutChoice();
953 void BufferView::Pimpl::update()
956 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
958 screen_->Update(bv_->text, bv_);
962 // Values used when calling update:
964 // -2 - update, move sel_cursor if selection, fitcursor
965 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
966 // 0 - update, move sel_cursor if selection, fitcursor
967 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
968 // 3 - update, move sel_cursor if selection
971 // a simple redraw of the parts that need refresh
973 // move sel_cursor if selection -
974 // the text's sel_cursor is moved if there is selection is progress
977 // fitCursor() is called and the scrollbar updated
980 // the buffer is marked dirty.
989 // UPDATE_ONLY = UPDATE;
990 // UPDATE_SELECT = UPDATE | SELECT;
991 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
992 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
994 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
995 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
996 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
997 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
998 // update(3) -> update(1) -> update(1) -> update(SELECT)
1000 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1002 owner_->updateLayoutChoice();
1004 if (!text->selection.set() && (f & SELECT)) {
1005 text->selection.cursor = text->cursor;
1008 text->fullRebreak(bv_);
1010 if (text->inset_owner) {
1011 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1012 updateInset(text->inset_owner, true);
1021 buffer_->markDirty();
1026 // Callback for cursor timer
1027 void BufferView::Pimpl::cursorToggle()
1029 // Quite a nice place for asyncron Inset updating, isn't it?
1030 // Actually no! This is run even if no buffer exist... so (Lgb)
1032 cursor_timeout.restart();
1037 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1038 if (pid == -1) // error find out what is wrong
1039 ; // ignore it for now.
1041 sigchldhandler(pid, &status);
1043 updatelist.update(bv_);
1045 if (!screen_.get()) {
1046 cursor_timeout.restart();
1050 if (!bv_->theLockingInset()) {
1051 screen_->CursorToggle(bv_->text, bv_);
1053 bv_->theLockingInset()->toggleInsetCursor(bv_);
1056 cursor_timeout.restart();
1060 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1062 if (!text->cursor.row()->previous())
1065 int y = text->first;
1066 if (text->inset_owner)
1067 y += bv_->text->first;
1068 Row * cursorrow = text->cursor.row();
1069 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1070 bv_->text->finishUndo();
1071 // This is to allow jumping over large insets
1072 if ((cursorrow == text->cursor.row()))
1073 text->cursorUp(bv_);
1075 if (text->inset_owner ||
1076 text->cursor.row()->height() < workarea_.height())
1077 screen_->Draw(bv_->text, bv_,
1079 - text->cursor.row()->baseline()
1080 + text->cursor.row()->height()
1081 - workarea_.height() + 1 );
1086 void BufferView::Pimpl::cursorNext(LyXText * text)
1088 if (!text->cursor.row()->next())
1091 int y = text->first + workarea_.height();
1092 // if (text->inset_owner)
1093 // y += bv_->text->first;
1094 text->getRowNearY(y);
1096 Row * cursorrow = text->cursor.row();
1097 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1098 bv_->text->finishUndo();
1099 // This is to allow jumping over large insets
1100 if ((cursorrow == bv_->text->cursor.row()))
1101 text->cursorDown(bv_);
1103 if (text->inset_owner ||
1104 text->cursor.row()->height() < workarea_.height())
1105 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1106 text->cursor.row()->baseline());
1111 bool BufferView::Pimpl::available() const
1113 if (buffer_ && bv_->text) return true;
1118 void BufferView::Pimpl::beforeChange(LyXText * text)
1121 text->clearSelection(bv_);
1125 void BufferView::Pimpl::savePosition(unsigned int i)
1127 if (i >= saved_positions_num)
1129 saved_positions[i] = Position(buffer_->fileName(),
1130 bv_->text->cursor.par()->id(),
1131 bv_->text->cursor.pos());
1134 str << _("Saved bookmark") << ' ' << i;
1135 owner_->message(str.str().c_str());
1140 void BufferView::Pimpl::restorePosition(unsigned int i)
1142 if (i >= saved_positions_num)
1145 string const fname = saved_positions[i].filename;
1147 beforeChange(bv_->text);
1149 if (fname != buffer_->fileName()) {
1150 Buffer * b = bufferlist.exists(fname) ?
1151 bufferlist.getBuffer(fname) :
1152 bufferlist.loadLyXFile(fname); // don't ask, just load it
1153 if (b != 0 ) buffer(b);
1156 Paragraph * par = bv_->text->getParFromID(saved_positions[i].par_id);
1160 bv_->text->setCursor(bv_, par,
1161 min(par->size(), saved_positions[i].par_pos));
1163 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1166 str << _("Moved to bookmark") << ' ' << i;
1167 owner_->message(str.str().c_str());
1172 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1174 if (i >= saved_positions_num)
1177 return !saved_positions[i].filename.empty();
1181 void BufferView::Pimpl::setState()
1183 if (!lyxrc.rtl_support)
1186 LyXText * text = bv_->getLyXText();
1187 if (text->real_current_font.isRightToLeft()
1190 text->real_current_font.latex() != LyXFont::ON
1193 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1194 owner_->getIntl()->KeyMapSec();
1196 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1197 owner_->getIntl()->KeyMapPrim();
1202 void BufferView::Pimpl::insetSleep()
1204 if (bv_->theLockingInset() && !inset_slept) {
1205 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1206 bv_->theLockingInset()->insetUnlock(bv_);
1212 void BufferView::Pimpl::insetWakeup()
1214 if (bv_->theLockingInset() && inset_slept) {
1215 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1216 inset_slept = false;
1221 void BufferView::Pimpl::insetUnlock()
1223 if (bv_->theLockingInset()) {
1225 bv_->theLockingInset()->insetUnlock(bv_);
1226 bv_->theLockingInset(0);
1227 bv_->text->finishUndo();
1228 inset_slept = false;
1233 bool BufferView::Pimpl::focus() const
1235 return workarea_.hasFocus();
1239 void BufferView::Pimpl::focus(bool f)
1241 if (f) workarea_.setFocus();
1245 bool BufferView::Pimpl::active() const
1247 return workarea_.active();
1251 bool BufferView::Pimpl::belowMouse() const
1253 return workarea_.belowMouse();
1257 void BufferView::Pimpl::showCursor()
1260 screen_->ShowCursor(bv_->text, bv_);
1264 void BufferView::Pimpl::hideCursor()
1267 screen_->HideCursor();
1271 void BufferView::Pimpl::toggleSelection(bool b)
1274 screen_->ToggleSelection(bv_->text, bv_, b);
1278 void BufferView::Pimpl::toggleToggle()
1281 screen_->ToggleToggle(bv_->text, bv_);
1285 void BufferView::Pimpl::center()
1287 beforeChange(bv_->text);
1288 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1289 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1291 screen_->Draw(bv_->text, bv_, 0);
1293 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1298 void BufferView::Pimpl::pasteClipboard(bool asPara)
1300 if (!buffer_) return;
1302 screen_->HideCursor();
1303 beforeChange(bv_->text);
1305 string const clip(workarea_.getClipboard());
1307 if (clip.empty()) return;
1310 bv_->text->insertStringAsParagraphs(bv_, clip);
1312 bv_->text->insertStringAsLines(bv_, clip);
1314 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1318 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1320 workarea_.putClipboard(stuff);
1325 * Dispatch functions for actions which can be valid for BufferView->text
1326 * and/or InsetText->text!!!
1331 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1333 LyXText * lt = bv_->getLyXText();
1335 if (selecting || lt->selection.mark()) {
1336 lt->setSelection(bv_);
1340 update(lt, BufferView::SELECT|BufferView::FITCUR);
1343 /* ---> Everytime the cursor is moved, show the current font state. */
1344 // should this too me moved out of this func?
1345 //owner->showState();
1350 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1352 LyXCursor cursor = bv_->getLyXText()->cursor;
1353 Buffer::inset_iterator it =
1354 find_if(Buffer::inset_iterator(
1355 cursor.par(), cursor.pos()),
1356 buffer_->inset_iterator_end(),
1357 lyx::compare_memfun(&Inset::lyxCode, code));
1358 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1362 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1364 string filename = filen;
1366 if (filename.empty()) {
1367 // Launch a file browser
1368 string initpath = lyxrc.document_path;
1371 string const trypath = owner_->buffer()->filepath;
1372 // If directory is writeable, use this as default.
1373 if (IsDirWriteable(trypath) == 1)
1377 FileDialog fileDlg(bv_->owner(),
1378 _("Select LyX document to insert"),
1380 make_pair(string(_("Documents")),
1381 string(lyxrc.document_path)),
1382 make_pair(string(_("Examples")),
1383 string(AddPath(system_lyxdir, "examples"))));
1385 FileDialog::Result result =
1386 fileDlg.Select(initpath,
1387 _("*.lyx| LyX Documents (*.lyx)"));
1389 if (result.first == FileDialog::Later)
1392 filename = result.second;
1394 // check selected filename
1395 if (filename.empty()) {
1396 owner_->message(_("Canceled."));
1401 // get absolute path of file and add ".lyx" to the filename if
1403 filename = FileSearch(string(), filename, "lyx");
1405 string const disp_fn(MakeDisplayPath(filename));
1408 s1 << _("Inserting document") << ' '
1409 << disp_fn << " ...";
1410 owner_->message(s1.str().c_str());
1411 bool const res = bv_->insertLyXFile(filename);
1414 str << _("Document") << ' ' << disp_fn
1415 << ' ' << _("inserted.");
1416 owner_->message(str.str().c_str());
1419 str << _("Could not insert document") << ' '
1421 owner_->message(str.str().c_str());
1426 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1428 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1429 << action <<"] arg[" << argument << "]" << endl;
1432 // --- Misc -------------------------------------------
1436 LyXText * lt = bv_->getLyXText();
1437 lt->toggleAppendix(bv_);
1440 | BufferView::FITCUR
1441 | BufferView::CHANGE);
1446 case LFUN_TOC_INSERT:
1448 InsetCommandParams p;
1449 p.setCmdName("tableofcontents");
1450 Inset * inset = new InsetTOC(p);
1451 if (!insertInset(inset, "Standard"))
1456 case LFUN_TABULAR_FEATURE:
1457 case LFUN_SCROLL_INSET:
1458 // this is not handled here as this funktion is only aktive
1459 // if we have a locking_inset and that one is (or contains)
1463 case LFUN_INSET_GRAPHICS:
1465 Inset * new_inset = new InsetGraphics;
1466 if (!insertInset(new_inset)) {
1469 // this is need because you don't use a inset->Edit()
1470 updateInset(new_inset, true);
1471 new_inset->edit(bv_, 0, 0, 0);
1481 case LFUN_PASTESELECTION:
1483 bool asPara = false;
1484 if (argument == "paragraph") asPara = true;
1485 pasteClipboard(asPara);
1497 case LFUN_LAYOUT_COPY:
1498 bv_->copyEnvironment();
1501 case LFUN_LAYOUT_PASTE:
1502 bv_->pasteEnvironment();
1506 case LFUN_GOTOERROR:
1507 gotoInset(Inset::ERROR_CODE, false);
1511 gotoInset(Inset::IGNORE_CODE, false);
1514 case LFUN_REFERENCE_GOTO:
1516 vector<Inset::Code> tmp;
1517 tmp.push_back(Inset::LABEL_CODE);
1518 tmp.push_back(Inset::REF_CODE);
1519 gotoInset(tmp, true);
1523 case LFUN_HYPHENATION:
1531 case LFUN_END_OF_SENTENCE:
1535 case LFUN_MENU_SEPARATOR:
1544 changeDepth(bv_, bv_->getLyXText(), 0);
1547 case LFUN_DEPTH_MIN:
1548 changeDepth(bv_, bv_->getLyXText(), -1);
1551 case LFUN_DEPTH_PLUS:
1552 changeDepth(bv_, bv_->getLyXText(), 1);
1556 owner_->getDialogs()->setUserFreeFont();
1563 owner_->showState();
1567 case LFUN_FILE_INSERT:
1569 MenuInsertLyXFile(argument);
1573 case LFUN_FILE_INSERT_ASCII_PARA:
1574 InsertAsciiFile(bv_, argument, true);
1577 case LFUN_FILE_INSERT_ASCII:
1578 InsertAsciiFile(bv_, argument, false);
1583 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1584 << argument << endl;
1586 // Derive layout number from given argument (string)
1587 // and current buffer's textclass (number). */
1588 LyXTextClassList::ClassList::size_type tclass =
1589 buffer_->params.textclass;
1590 pair <bool, LyXTextClass::size_type> layout =
1591 textclasslist.NumberOfLayout(tclass, argument);
1593 // If the entry is obsolete, use the new one instead.
1595 string obs = textclasslist.Style(tclass,layout.second)
1599 textclasslist.NumberOfLayout(tclass, obs);
1602 // see if we found the layout number:
1603 if (!layout.first) {
1604 owner_->getLyXFunc()->setErrorMessage(
1605 string(N_("Layout ")) + argument +
1610 if (current_layout != layout.second) {
1611 LyXText * lt = bv_->getLyXText();
1613 current_layout = layout.second;
1616 | BufferView::FITCUR);
1617 lt->setLayout(bv_, layout.second);
1618 owner_->setLayout(layout.second);
1621 | BufferView::FITCUR
1622 | BufferView::CHANGE);
1629 Lang(bv_, argument);
1631 owner_->showState();
1636 owner_->showState();
1641 owner_->showState();
1646 owner_->showState();
1651 owner_->showState();
1656 owner_->showState();
1661 owner_->showState();
1666 owner_->showState();
1669 case LFUN_UNDERLINE:
1671 owner_->showState();
1674 case LFUN_FONT_SIZE:
1675 FontSize(bv_, argument);
1676 owner_->showState();
1679 case LFUN_FONT_STATE:
1680 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1683 case LFUN_UPCASE_WORD:
1685 LyXText * lt = bv_->getLyXText();
1689 | BufferView::FITCUR);
1690 lt->changeCase(bv_, LyXText::text_uppercase);
1691 if (lt->inset_owner)
1692 updateInset(lt->inset_owner, true);
1695 | BufferView::FITCUR
1696 | BufferView::CHANGE);
1700 case LFUN_LOWCASE_WORD:
1702 LyXText * lt = bv_->getLyXText();
1704 update(lt, BufferView::SELECT|BufferView::FITCUR);
1705 lt->changeCase(bv_, LyXText::text_lowercase);
1706 if (lt->inset_owner)
1707 updateInset(lt->inset_owner, true);
1710 | BufferView::FITCUR
1711 | BufferView::CHANGE);
1715 case LFUN_CAPITALIZE_WORD:
1717 LyXText * lt = bv_->getLyXText();
1719 update(lt, BufferView::SELECT|BufferView::FITCUR);
1720 lt->changeCase(bv_, LyXText::text_capitalization);
1721 if (lt->inset_owner)
1722 updateInset(lt->inset_owner, true);
1725 | BufferView::FITCUR
1726 | BufferView::CHANGE);
1730 case LFUN_TRANSPOSE_CHARS:
1732 LyXText * lt = bv_->getLyXText();
1734 update(lt, BufferView::SELECT|BufferView::FITCUR);
1735 lt->transposeChars(*bv_);
1736 if (lt->inset_owner)
1737 updateInset(lt->inset_owner, true);
1740 | BufferView::FITCUR
1741 | BufferView::CHANGE);
1746 case LFUN_INSERT_LABEL:
1747 MenuInsertLabel(bv_, argument);
1750 case LFUN_REF_INSERT:
1751 if (argument.empty()) {
1752 InsetCommandParams p("ref");
1753 owner_->getDialogs()->createRef(p.getAsString());
1755 InsetCommandParams p;
1756 p.setFromString(argument);
1758 InsetRef * inset = new InsetRef(p, *buffer_);
1759 if (!insertInset(inset))
1762 updateInset(inset, true);
1766 case LFUN_BOOKMARK_SAVE:
1767 savePosition(strToUnsignedInt(argument));
1770 case LFUN_BOOKMARK_GOTO:
1771 restorePosition(strToUnsignedInt(argument));
1776 string label(argument);
1777 if (label.empty()) {
1779 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1781 label = inset->getContents();
1786 if (!label.empty()) {
1787 //bv_->savePosition(0);
1788 if (!bv_->gotoLabel(label))
1789 WriteAlert(_("Error"),
1790 _("Couldn't find this label"),
1791 _("in current document."));
1796 // --- Cursor Movements -----------------------------
1799 LyXText * lt = bv_->getLyXText();
1801 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1802 if (!lt->selection.mark())
1804 update(lt, BufferView::SELECT|BufferView::FITCUR);
1806 lt->cursorLeft(bv_, false);
1807 if (lt->cursor.pos() < lt->cursor.par()->size()
1808 && lt->cursor.par()->getChar(lt->cursor.pos())
1809 == Paragraph::META_INSET
1810 && lt->cursor.par()->getInset(lt->cursor.pos())
1811 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1812 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1813 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1816 LyXFont const font =
1817 lt->getFont(buffer_,
1820 y = tmpinset->descent(bv_,font);
1822 tmpinset->edit(bv_, 0, y, 0);
1826 lt->cursorRight(bv_, false);
1828 moveCursorUpdate(false);
1829 owner_->showState();
1835 // This is soooo ugly. Isn`t it possible to make
1836 // it simpler? (Lgb)
1837 LyXText * lt = bv_->getLyXText();
1838 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1839 if (!lt->selection.mark())
1841 update(lt, BufferView::SELECT|BufferView::FITCUR);
1842 LyXCursor const cur = lt->cursor;
1844 lt->cursorLeft(bv_, false);
1845 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1846 lt->cursor.pos() < lt->cursor.par()->size() &&
1847 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1848 Paragraph::META_INSET) &&
1849 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1850 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1851 == Inset::HIGHLY_EDITABLE))
1853 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1854 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1855 LyXFont const font = lt->getFont(buffer_,
1859 : tmpinset->descent(bv_,font);
1862 tmpinset->width(bv_,font),
1867 lt->cursorRight(bv_, false);
1870 moveCursorUpdate(false);
1871 owner_->showState();
1877 LyXText * lt = bv_->getLyXText();
1879 if (!lt->selection.mark())
1881 update(lt, BufferView::UPDATE);
1884 moveCursorUpdate(false);
1885 owner_->showState();
1891 LyXText * lt = bv_->getLyXText();
1893 if (!lt->selection.mark())
1895 update(lt, BufferView::UPDATE);
1896 lt->cursorDown(bv_);
1898 moveCursorUpdate(false);
1899 owner_->showState();
1903 case LFUN_UP_PARAGRAPH:
1905 LyXText * lt = bv_->getLyXText();
1907 if (!lt->selection.mark())
1909 update(lt, BufferView::UPDATE);
1910 lt->cursorUpParagraph(bv_);
1912 moveCursorUpdate(false);
1913 owner_->showState();
1917 case LFUN_DOWN_PARAGRAPH:
1919 LyXText * lt = bv_->getLyXText();
1921 if (!lt->selection.mark())
1923 update(lt, BufferView::UPDATE);
1924 lt->cursorDownParagraph(bv_);
1926 moveCursorUpdate(false);
1927 owner_->showState();
1933 LyXText * lt = bv_->getLyXText();
1935 if (!lt->selection.mark())
1937 update(lt, BufferView::UPDATE);
1940 moveCursorUpdate(false);
1941 owner_->showState();
1947 LyXText * lt = bv_->getLyXText();
1949 if (!lt->selection.mark())
1951 update(lt, BufferView::UPDATE);
1954 moveCursorUpdate(false);
1955 owner_->showState();
1961 LyXText * lt = bv_->getLyXText();
1963 if (!lt->selection.mark())
1965 update(lt, BufferView::SELECT|BufferView::FITCUR);
1966 lt->cursorHome(bv_);
1968 moveCursorUpdate(false);
1969 owner_->showState();
1975 LyXText * lt = bv_->getLyXText();
1977 if (!lt->selection.mark())
1980 BufferView::SELECT|BufferView::FITCUR);
1983 moveCursorUpdate(false);
1984 owner_->showState();
1988 case LFUN_SHIFT_TAB:
1991 LyXText * lt = bv_->getLyXText();
1993 if (!lt->selection.mark())
1996 BufferView::SELECT|BufferView::FITCUR);
1999 moveCursorUpdate(false);
2000 owner_->showState();
2004 case LFUN_WORDRIGHT:
2006 LyXText * lt = bv_->getLyXText();
2008 if (!lt->selection.mark())
2010 update(lt, BufferView::SELECT|BufferView::FITCUR);
2011 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2012 lt->cursorLeftOneWord(bv_);
2014 lt->cursorRightOneWord(bv_);
2016 moveCursorUpdate(false);
2017 owner_->showState();
2023 LyXText * lt = bv_->getLyXText();
2025 if (!lt->selection.mark())
2027 update(lt, BufferView::SELECT|BufferView::FITCUR);
2028 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2029 lt->cursorRightOneWord(bv_);
2031 lt->cursorLeftOneWord(bv_);
2033 moveCursorUpdate(false);
2034 owner_->showState();
2038 case LFUN_BEGINNINGBUF:
2040 LyXText * lt = bv_->getLyXText();
2042 if (!lt->selection.mark())
2045 BufferView::SELECT|BufferView::FITCUR);
2048 moveCursorUpdate(false);
2049 owner_->showState();
2055 LyXText * lt = bv_->getLyXText();
2057 if (!lt->selection.mark())
2060 BufferView::SELECT|BufferView::FITCUR);
2061 lt->cursorBottom(bv_);
2063 moveCursorUpdate(false);
2064 owner_->showState();
2068 /* cursor selection ---------------------------- */
2071 LyXText * lt = bv_->getLyXText();
2074 BufferView::SELECT|BufferView::FITCUR);
2075 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2076 lt->cursorLeft(bv_);
2078 lt->cursorRight(bv_);
2080 moveCursorUpdate(true);
2081 owner_->showState();
2087 LyXText * lt = bv_->getLyXText();
2090 BufferView::SELECT|BufferView::FITCUR);
2091 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2092 lt->cursorRight(bv_);
2094 lt->cursorLeft(bv_);
2096 moveCursorUpdate(true);
2097 owner_->showState();
2103 LyXText * lt = bv_->getLyXText();
2106 BufferView::SELECT|BufferView::FITCUR);
2109 moveCursorUpdate(true);
2110 owner_->showState();
2116 LyXText * lt = bv_->getLyXText();
2119 BufferView::SELECT|BufferView::FITCUR);
2120 lt->cursorDown(bv_);
2122 moveCursorUpdate(true);
2123 owner_->showState();
2127 case LFUN_UP_PARAGRAPHSEL:
2129 LyXText * lt = bv_->getLyXText();
2132 BufferView::SELECT|BufferView::FITCUR);
2133 lt->cursorUpParagraph(bv_);
2135 moveCursorUpdate(true);
2136 owner_->showState();
2140 case LFUN_DOWN_PARAGRAPHSEL:
2142 LyXText * lt = bv_->getLyXText();
2145 BufferView::SELECT|BufferView::FITCUR);
2146 lt->cursorDownParagraph(bv_);
2148 moveCursorUpdate(true);
2149 owner_->showState();
2155 LyXText * lt = bv_->getLyXText();
2157 update(lt, BufferView::SELECT|BufferView::FITCUR);
2160 moveCursorUpdate(true);
2161 owner_->showState();
2167 LyXText * lt = bv_->getLyXText();
2169 update(lt, BufferView::SELECT|BufferView::FITCUR);
2172 moveCursorUpdate(true);
2173 owner_->showState();
2179 LyXText * lt = bv_->getLyXText();
2181 update(lt, BufferView::SELECT|BufferView::FITCUR);
2182 lt->cursorHome(bv_);
2184 moveCursorUpdate(true);
2185 owner_->showState();
2191 LyXText * lt = bv_->getLyXText();
2193 update(lt, BufferView::SELECT|BufferView::FITCUR);
2196 moveCursorUpdate(true);
2197 owner_->showState();
2201 case LFUN_WORDRIGHTSEL:
2203 LyXText * lt = bv_->getLyXText();
2205 update(lt, BufferView::SELECT|BufferView::FITCUR);
2206 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2207 lt->cursorLeftOneWord(bv_);
2209 lt->cursorRightOneWord(bv_);
2211 moveCursorUpdate(true);
2212 owner_->showState();
2216 case LFUN_WORDLEFTSEL:
2218 LyXText * lt = bv_->getLyXText();
2220 update(lt, BufferView::SELECT|BufferView::FITCUR);
2221 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2222 lt->cursorRightOneWord(bv_);
2224 lt->cursorLeftOneWord(bv_);
2226 moveCursorUpdate(true);
2227 owner_->showState();
2231 case LFUN_BEGINNINGBUFSEL:
2233 LyXText * lt = bv_->getLyXText();
2235 if (lt->inset_owner)
2237 update(lt, BufferView::SELECT|BufferView::FITCUR);
2240 moveCursorUpdate(true);
2241 owner_->showState();
2245 case LFUN_ENDBUFSEL:
2247 LyXText * lt = bv_->getLyXText();
2249 if (lt->inset_owner)
2252 BufferView::SELECT|BufferView::FITCUR);
2253 lt->cursorBottom(bv_);
2255 moveCursorUpdate(true);
2256 owner_->showState();
2260 // --- text changing commands ------------------------
2261 case LFUN_BREAKLINE:
2263 LyXText * lt = bv_->getLyXText();
2266 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2269 | BufferView::FITCUR
2270 | BufferView::CHANGE);
2271 moveCursorUpdate(false);
2275 case LFUN_PROTECTEDSPACE:
2277 LyXText * lt = bv_->getLyXText();
2279 LyXLayout const & style = textclasslist
2280 .Style(buffer_->params.textclass,
2281 lt->cursor.par()->getLayout());
2283 if (style.free_spacing) {
2284 lt->insertChar(bv_, ' ');
2287 | BufferView::FITCUR
2288 | BufferView::CHANGE);
2292 moveCursorUpdate(false);
2298 LyXText * lt = bv_->getLyXText();
2300 if (lt->selection.mark()) {
2304 | BufferView::FITCUR);
2305 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2308 lt->selection.mark(true);
2311 | BufferView::FITCUR);
2312 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2314 lt->selection.cursor = lt->cursor;
2320 LyXText * lt = bv_->getLyXText();
2322 if (!lt->selection.set()) {
2324 lt->selection.cursor = lt->cursor;
2327 | BufferView::FITCUR
2328 | BufferView::CHANGE);
2329 // It is possible to make it a lot faster still
2330 // just comment out the line below...
2335 moveCursorUpdate(false);
2336 owner_->showState();
2341 case LFUN_DELETE_SKIP:
2343 LyXText * lt = bv_->getLyXText();
2345 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2347 LyXCursor cursor = lt->cursor;
2349 if (!lt->selection.set()) {
2350 if (cursor.pos() == cursor.par()->size()) {
2351 lt->cursorRight(bv_);
2352 cursor = lt->cursor;
2353 if (cursor.pos() == 0
2354 && !(cursor.par()->params().spaceTop()
2355 == VSpace (VSpace::NONE))) {
2358 cursor.par()->params().lineTop(),
2359 cursor.par()->params().lineBottom(),
2360 cursor.par()->params().pagebreakTop(),
2361 cursor.par()->params().pagebreakBottom(),
2362 VSpace(VSpace::NONE),
2363 cursor.par()->params().spaceBottom(),
2364 cursor.par()->params().align(),
2365 cursor.par()->params().labelWidthString(), 0);
2366 lt->cursorLeft(bv_);
2369 | BufferView::FITCUR
2370 | BufferView::CHANGE);
2372 lt->cursorLeft(bv_);
2374 lt->selection.cursor = lt->cursor;
2377 | BufferView::FITCUR
2378 | BufferView::CHANGE);
2382 lt->selection.cursor = lt->cursor;
2385 | BufferView::FITCUR
2386 | BufferView::CHANGE);
2394 /* -------> Delete word forward. */
2395 case LFUN_DELETE_WORD_FORWARD:
2396 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2397 bv_->getLyXText()->deleteWordForward(bv_);
2398 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2399 moveCursorUpdate(false);
2400 owner_->showState();
2403 /* -------> Delete word backward. */
2404 case LFUN_DELETE_WORD_BACKWARD:
2406 LyXText * lt = bv_->getLyXText();
2408 update(lt, BufferView::SELECT|BufferView::FITCUR);
2409 lt->deleteWordBackward(bv_);
2412 | BufferView::FITCUR
2413 | BufferView::CHANGE);
2414 moveCursorUpdate(false);
2415 owner_->showState();
2419 /* -------> Kill to end of line. */
2420 case LFUN_DELETE_LINE_FORWARD:
2422 LyXText * lt = bv_->getLyXText();
2424 update(lt, BufferView::SELECT|BufferView::FITCUR);
2425 lt->deleteLineForward(bv_);
2428 | BufferView::FITCUR
2429 | BufferView::CHANGE);
2430 moveCursorUpdate(false);
2434 /* -------> Set mark off. */
2437 LyXText * lt = bv_->getLyXText();
2440 update(lt, BufferView::SELECT|BufferView::FITCUR);
2441 lt->selection.cursor = lt->cursor;
2442 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2446 /* -------> Set mark on. */
2449 LyXText * lt = bv_->getLyXText();
2452 lt->selection.mark(true);
2453 update(lt, BufferView::SELECT|BufferView::FITCUR);
2454 lt->selection.cursor = lt->cursor;
2455 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2459 case LFUN_BACKSPACE:
2461 LyXText * lt = bv_->getLyXText();
2463 if (!lt->selection.set()) {
2464 if (owner_->getIntl()->getTrans().backspace()) {
2466 lt->selection.cursor = lt->cursor;
2469 | BufferView::FITCUR
2470 | BufferView::CHANGE);
2471 // It is possible to make it a lot faster still
2472 // just comment out the line below...
2478 owner_->showState();
2483 case LFUN_BACKSPACE_SKIP:
2485 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2486 LyXText * lt = bv_->getLyXText();
2488 LyXCursor cursor = lt->cursor;
2490 if (!lt->selection.set()) {
2491 if (cursor.pos() == 0
2492 && !(cursor.par()->params().spaceTop()
2493 == VSpace (VSpace::NONE))) {
2496 cursor.par()->params().lineTop(),
2497 cursor.par()->params().lineBottom(),
2498 cursor.par()->params().pagebreakTop(),
2499 cursor.par()->params().pagebreakBottom(),
2500 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2501 cursor.par()->params().align(),
2502 cursor.par()->params().labelWidthString(), 0);
2505 | BufferView::FITCUR
2506 | BufferView::CHANGE);
2509 lt->selection.cursor = cursor;
2512 | BufferView::FITCUR
2513 | BufferView::CHANGE);
2520 case LFUN_BREAKPARAGRAPH:
2522 LyXText * lt = bv_->getLyXText();
2525 lt->breakParagraph(bv_, 0);
2528 | BufferView::FITCUR
2529 | BufferView::CHANGE);
2530 lt->selection.cursor = lt->cursor;
2532 owner_->showState();
2536 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2538 LyXText * lt = bv_->getLyXText();
2541 lt->breakParagraph(bv_, 1);
2544 | BufferView::FITCUR
2545 | BufferView::CHANGE);
2546 lt->selection.cursor = lt->cursor;
2548 owner_->showState();
2552 case LFUN_BREAKPARAGRAPH_SKIP:
2554 // When at the beginning of a paragraph, remove
2555 // indentation and add a "defskip" at the top.
2556 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2557 LyXText * lt = bv_->getLyXText();
2559 LyXCursor cursor = lt->cursor;
2562 if (cursor.pos() == 0) {
2563 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2566 cursor.par()->params().lineTop(),
2567 cursor.par()->params().lineBottom(),
2568 cursor.par()->params().pagebreakTop(),
2569 cursor.par()->params().pagebreakBottom(),
2570 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2571 cursor.par()->params().align(),
2572 cursor.par()->params().labelWidthString(), 1);
2573 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2577 lt->breakParagraph(bv_, 0);
2578 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2583 | BufferView::FITCUR
2584 | BufferView::CHANGE);
2585 lt->selection.cursor = cursor;
2587 owner_->showState();
2591 case LFUN_PARAGRAPH_SPACING:
2593 LyXText * lt = bv_->getLyXText();
2595 Paragraph * par = lt->cursor.par();
2596 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2597 float cur_value = 1.0;
2598 if (cur_spacing == Spacing::Other) {
2599 cur_value = par->params().spacing().getValue();
2602 istringstream istr(argument.c_str());
2606 Spacing::Space new_spacing = cur_spacing;
2607 float new_value = cur_value;
2609 lyxerr << "Missing argument to `paragraph-spacing'"
2611 } else if (tmp == "single") {
2612 new_spacing = Spacing::Single;
2613 } else if (tmp == "onehalf") {
2614 new_spacing = Spacing::Onehalf;
2615 } else if (tmp == "double") {
2616 new_spacing = Spacing::Double;
2617 } else if (tmp == "other") {
2618 new_spacing = Spacing::Other;
2621 lyxerr << "new_value = " << tmpval << endl;
2624 } else if (tmp == "default") {
2625 new_spacing = Spacing::Default;
2627 lyxerr << _("Unknown spacing argument: ")
2628 << argument << endl;
2630 if (cur_spacing != new_spacing || cur_value != new_value) {
2631 par->params().spacing(Spacing(new_spacing, new_value));
2632 lt->redoParagraph(bv_);
2635 | BufferView::FITCUR
2636 | BufferView::CHANGE);
2642 bv_->insertCorrectQuote();
2648 InsetCommandParams p;
2649 if (action == LFUN_HTMLURL)
2650 p.setCmdName("htmlurl");
2652 p.setCmdName("url");
2653 owner_->getDialogs()->createUrl( p.getAsString() );
2657 case LFUN_INSERT_URL:
2659 InsetCommandParams p;
2660 p.setFromString( argument );
2662 InsetUrl * inset = new InsetUrl( p );
2663 if (!insertInset(inset))
2666 updateInset( inset, true );
2670 case LFUN_INSET_TEXT:
2672 InsetText * new_inset = new InsetText;
2673 if (insertInset(new_inset))
2674 new_inset->edit(bv_, 0, 0, 0);
2680 case LFUN_INSET_ERT:
2682 InsetERT * new_inset = new InsetERT;
2683 if (insertInset(new_inset))
2684 new_inset->edit(bv_, 0, 0, 0);
2690 case LFUN_INSET_EXTERNAL:
2692 InsetExternal * new_inset = new InsetExternal;
2693 if (insertInset(new_inset))
2694 new_inset->edit(bv_, 0, 0, 0);
2700 case LFUN_INSET_FOOTNOTE:
2702 InsetFoot * new_inset = new InsetFoot;
2703 if (insertInset(new_inset))
2704 new_inset->edit(bv_, 0, 0, 0);
2710 case LFUN_INSET_MARGINAL:
2712 InsetMarginal * new_inset = new InsetMarginal;
2713 if (insertInset(new_inset))
2714 new_inset->edit(bv_, 0, 0, 0);
2720 case LFUN_INSET_MINIPAGE:
2722 InsetMinipage * new_inset = new InsetMinipage;
2723 if (insertInset(new_inset))
2724 new_inset->edit(bv_, 0, 0, 0);
2730 case LFUN_INSET_FLOAT:
2732 // check if the float type exist
2733 if (floatList.typeExist(argument)) {
2734 InsetFloat * new_inset = new InsetFloat(argument);
2735 if (insertInset(new_inset))
2736 new_inset->edit(bv_, 0, 0, 0);
2740 lyxerr << "Non-existant float type: "
2741 << argument << endl;
2747 case LFUN_INSET_WIDE_FLOAT:
2749 // check if the float type exist
2750 if (floatList.typeExist(argument)) {
2751 InsetFloat * new_inset = new InsetFloat(argument);
2752 new_inset->wide(true);
2753 if (insertInset(new_inset))
2754 new_inset->edit(bv_, 0, 0, 0);
2758 lyxerr << "Non-existant float type: "
2759 << argument << endl;
2765 case LFUN_INSET_LIST:
2767 InsetList * new_inset = new InsetList;
2768 if (insertInset(new_inset))
2769 new_inset->edit(bv_, 0, 0, 0);
2775 case LFUN_INSET_THEOREM:
2777 InsetTheorem * new_inset = new InsetTheorem;
2778 if (insertInset(new_inset))
2779 new_inset->edit(bv_, 0, 0, 0);
2785 case LFUN_INSET_CAPTION:
2787 // Do we have a locking inset...
2788 if (bv_->theLockingInset()) {
2789 lyxerr << "Locking inset code: "
2790 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2791 InsetCaption * new_inset = new InsetCaption;
2792 new_inset->setOwner(bv_->theLockingInset());
2793 new_inset->setAutoBreakRows(true);
2794 new_inset->setDrawFrame(0, InsetText::LOCKED);
2795 new_inset->setFrameColor(0, LColor::captionframe);
2796 if (insertInset(new_inset))
2797 new_inset->edit(bv_, 0, 0, 0);
2804 case LFUN_INSET_TABULAR:
2808 if (!argument.empty())
2809 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2810 InsetTabular * new_inset =
2811 new InsetTabular(*buffer_, r, c);
2813 bv_->getLyXText()->real_current_font.isRightToLeft();
2814 if (!open_new_inset(new_inset, rtl))
2819 // --- lyxserver commands ----------------------------
2821 case LFUN_CHARATCURSOR:
2823 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2824 if (pos < bv_->getLyXText()->cursor.par()->size())
2825 owner_->getLyXFunc()->setMessage(
2826 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2828 owner_->getLyXFunc()->setMessage("EOF");
2833 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2835 + tostr(bv_->getLyXText()->cursor.y()));
2842 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2843 lyxerr << "SETXY: Could not parse coordinates in '"
2844 << argument << std::endl;
2846 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2850 case LFUN_GETLAYOUT:
2851 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2856 LyXFont & font = bv_->getLyXText()->current_font;
2857 if (font.shape() == LyXFont::ITALIC_SHAPE)
2858 owner_->getLyXFunc()->setMessage("E");
2859 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2860 owner_->getLyXFunc()->setMessage("N");
2862 owner_->getLyXFunc()->setMessage("0");
2870 LyXFont & font = bv_->getLyXText()->current_font;
2871 if (font.latex() == LyXFont::ON)
2872 owner_->getLyXFunc()->setMessage("L");
2875 owner_->getLyXFunc()->setMessage("0");
2879 // --- accented characters ---------------------------
2882 case LFUN_CIRCUMFLEX:
2892 case LFUN_SPECIAL_CARON:
2895 case LFUN_HUNG_UMLAUT:
2898 if (argument.empty()) {
2900 owner_->getLyXFunc()->handleKeyFunc(action);
2902 owner_->getLyXFunc()->handleKeyFunc(action);
2903 owner_->getIntl()->getTrans()
2904 .TranslateAndInsert(argument[0], bv_->getLyXText());
2905 update(bv_->getLyXText(),
2907 | BufferView::FITCUR
2908 | BufferView::CHANGE);
2912 // --- insert characters ----------------------------------------
2914 case LFUN_MATH_DELIM:
2915 case LFUN_INSERT_MATRIX:
2918 if (open_new_inset(new InsetFormula, false)) {
2919 bv_->theLockingInset()
2920 ->localDispatch(bv_, action, argument);
2926 case LFUN_INSERT_MATH:
2931 InsetFormula * f = new InsetFormula(LM_OT_EQUATION);
2933 f->localDispatch(bv_, LFUN_INSERT_MATH, argument);
2937 case LFUN_MATH_DISPLAY:
2940 open_new_inset(new InsetFormula(LM_OT_EQUATION), false);
2944 case LFUN_MATH_MACRO:
2949 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2951 string const s1 = token(s, ' ', 1);
2952 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2953 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na), false);
2959 case LFUN_MATH_MODE: // Open or create a math inset
2962 open_new_inset(new InsetFormula, false);
2963 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2967 case LFUN_CITATION_INSERT:
2969 InsetCommandParams p;
2970 p.setFromString( argument );
2972 InsetCitation * inset = new InsetCitation( p );
2973 if (!insertInset(inset))
2976 updateInset( inset, true );
2980 case LFUN_INSERT_BIBTEX:
2982 // ale970405+lasgoutt970425
2983 // The argument can be up to two tokens separated
2984 // by a space. The first one is the bibstyle.
2985 string const db = token(argument, ' ', 0);
2986 string bibstyle = token(argument, ' ', 1);
2987 if (bibstyle.empty())
2990 InsetCommandParams p( "BibTeX", db, bibstyle );
2991 InsetBibtex * inset = new InsetBibtex(p);
2993 if (insertInset(inset)) {
2994 if (argument.empty())
2995 inset->edit(bv_, 0, 0, 0);
3001 // BibTeX data bases
3002 case LFUN_BIBDB_ADD:
3004 InsetBibtex * inset =
3005 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3007 inset->addDatabase(argument);
3012 case LFUN_BIBDB_DEL:
3014 InsetBibtex * inset =
3015 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3017 inset->delDatabase(argument);
3022 case LFUN_BIBTEX_STYLE:
3024 InsetBibtex * inset =
3025 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3027 inset->setOptions(argument);
3032 case LFUN_INDEX_CREATE:
3034 InsetCommandParams p( "index" );
3036 if (argument.empty()) {
3037 // Get the word immediately preceding the cursor
3038 Paragraph::size_type curpos =
3039 bv_->getLyXText()->cursor.pos() - 1;
3043 curstring = bv_->getLyXText()
3044 ->cursor.par()->getWord(curpos);
3046 p.setContents( curstring );
3048 p.setContents( argument );
3051 owner_->getDialogs()->createIndex( p.getAsString() );
3055 case LFUN_INDEX_INSERT:
3057 InsetCommandParams p;
3058 p.setFromString(argument);
3059 InsetIndex * inset = new InsetIndex(p);
3061 if (!insertInset(inset))
3064 updateInset(inset, true);
3068 case LFUN_INDEX_INSERT_LAST:
3070 // Get word immediately preceding the cursor
3071 Paragraph::size_type curpos =
3072 bv_->getLyXText()->cursor.pos() - 1;
3073 // Can't do that at the beginning of a paragraph
3074 if (curpos < 0) break;
3076 string const curstring(bv_->getLyXText()
3077 ->cursor.par()->getWord(curpos));
3079 InsetCommandParams p("index", curstring);
3080 InsetIndex * inset = new InsetIndex(p);
3082 if (!insertInset(inset))
3085 updateInset(inset, true);
3089 case LFUN_INDEX_PRINT:
3091 InsetCommandParams p("printindex");
3092 Inset * inset = new InsetPrintIndex(p);
3093 if (!insertInset(inset, "Standard"))
3098 case LFUN_PARENTINSERT:
3100 lyxerr << "arg " << argument << endl;
3101 InsetCommandParams p( "lyxparent", argument );
3102 Inset * inset = new InsetParent(p, *buffer_);
3103 if (!insertInset(inset, "Standard"))
3109 case LFUN_CHILD_INSERT:
3111 InsetInclude::Params p;
3112 p.cparams.setFromString(argument);
3113 p.masterFilename_ = buffer_->fileName();
3115 InsetInclude * inset = new InsetInclude(p);
3116 if (!insertInset(inset))
3119 updateInset(inset, true);
3120 bv_->owner()->getDialogs()->showInclude(inset);
3125 case LFUN_FLOAT_LIST:
3127 // We should check the argument for validity. (Lgb)
3128 Inset * inset = new InsetFloatList(argument);
3129 if (!insertInset(inset, "Standard"))
3134 case LFUN_INSERT_NOTE:
3138 case LFUN_SELFINSERT:
3140 if (argument.empty()) break;
3142 /* Automatically delete the currently selected
3143 * text and replace it with what is being
3144 * typed in now. Depends on lyxrc settings
3145 * "auto_region_delete", which defaults to
3148 LyXText * lt = bv_->getLyXText();
3150 if (lyxrc.auto_region_delete) {
3151 if (lt->selection.set()) {
3152 lt->cutSelection(bv_, false);
3155 | BufferView::FITCUR
3156 | BufferView::CHANGE);
3160 bv_->beforeChange(lt);
3161 LyXFont const old_font(lt->real_current_font);
3163 string::const_iterator cit = argument.begin();
3164 string::const_iterator end = argument.end();
3165 for (; cit != end; ++cit) {
3166 if (greek_kb_flag) {
3167 if (!math_insert_greek(bv_, *cit))
3168 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3170 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3175 | BufferView::FITCUR
3176 | BufferView::CHANGE);
3178 lt->selection.cursor = lt->cursor;
3179 moveCursorUpdate(false);
3181 // real_current_font.number can change so we need to
3182 // update the minibuffer
3183 if (old_font != lt->real_current_font)
3184 owner_->showState();
3189 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3191 time_t now_time_t = time(NULL);
3192 struct tm * now_tm = localtime(&now_time_t);
3193 setlocale(LC_TIME, "");
3195 if (!argument.empty())
3198 arg = lyxrc.date_insert_format;
3200 int const datetmp_len =
3201 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3203 LyXText * lt = bv_->getLyXText();
3205 for (int i = 0; i < datetmp_len; i++) {
3206 lt->insertChar(bv_, datetmp[i]);
3209 | BufferView::FITCUR
3210 | BufferView::CHANGE);
3213 lt->selection.cursor = lt->cursor;
3214 moveCursorUpdate(false);
3218 case LFUN_UNKNOWN_ACTION:
3219 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3230 void BufferView::Pimpl::newline()
3233 LyXText * lt = bv_->getLyXText();
3237 | BufferView::FITCUR);
3238 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3241 | BufferView::FITCUR
3242 | BufferView::CHANGE);
3247 void BufferView::Pimpl::hfill()
3250 LyXText * lt = bv_->getLyXText();
3254 | BufferView::FITCUR);
3255 lt->insertChar(bv_, Paragraph::META_HFILL);
3258 | BufferView::FITCUR
3259 | BufferView::CHANGE);
3264 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3268 update(lt, BufferView::SELECT|BufferView::FITCUR);
3269 InsetSpecialChar * new_inset =
3270 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3271 if (!insertInset(new_inset))
3274 updateInset(new_inset, true);
3279 void BufferView::Pimpl::menuSeparator()
3282 LyXText * lt = bv_->getLyXText();
3285 update(lt, BufferView::SELECT|BufferView::FITCUR);
3286 InsetSpecialChar * new_inset =
3287 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3288 insertInset(new_inset);
3293 void BufferView::Pimpl::endOfSentenceDot()
3297 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3298 InsetSpecialChar * new_inset =
3299 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3300 insertInset(new_inset);
3305 void BufferView::Pimpl::ldots()
3309 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3310 InsetSpecialChar * new_inset =
3311 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3312 insertInset(new_inset);
3317 void BufferView::Pimpl::hyphenationPoint()
3321 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3322 InsetSpecialChar * new_inset =
3323 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3324 insertInset(new_inset);
3329 void BufferView::Pimpl::insertNote()
3331 InsetInfo * new_inset = new InsetInfo();
3332 insertInset(new_inset);
3333 new_inset->edit(bv_, 0, 0, 0);
3337 // Open and lock an updatable inset
3338 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3340 LyXText * lt = bv_->getLyXText();
3344 if (!insertInset(new_inset)) {
3349 LyXFont & font = lt->real_current_font;
3350 new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
3352 new_inset->edit(bv_, 0, 0, 0);
3357 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3359 // if we are in a locking inset we should try to insert the
3360 // inset there otherwise this is a illegal function now
3361 if (bv_->theLockingInset()) {
3362 if (bv_->theLockingInset()->insertInsetAllowed(inset))
3363 return bv_->theLockingInset()->insertInset(bv_, inset);
3367 // not quite sure if we want this...
3368 bv_->text->setCursorParUndo(buffer_);
3369 bv_->text->freezeUndo();
3371 beforeChange(bv_->text);
3372 if (!lout.empty()) {
3373 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3374 bv_->text->breakParagraph(bv_);
3375 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3377 if (bv_->text->cursor.par()->size()) {
3378 bv_->text->cursorLeft(bv_);
3380 bv_->text->breakParagraph(bv_);
3381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3384 pair<bool, LyXTextClass::size_type> lres =
3385 textclasslist.NumberOfLayout(buffer_->params
3387 LyXTextClass::size_type lay;
3388 if (lres.first != false) {
3392 // layout not fount using default "Standard" (0)
3396 bv_->text->setLayout(bv_, lay);
3398 bv_->text->setParagraph(bv_, 0, 0,
3400 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3404 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3406 bv_->text->current_font.setLatex(LyXFont::OFF);
3410 bv_->text->insertInset(bv_, inset);
3411 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3413 bv_->text->unFreezeUndo();
3418 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3423 // first check for locking insets
3424 if (bv_->theLockingInset()) {
3425 if (bv_->theLockingInset() == inset) {
3426 if (bv_->text->updateInset(bv_, inset)) {
3429 buffer_->markDirty();
3434 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3435 if (bv_->text->updateInset(bv_,
3436 bv_->theLockingInset())) {
3439 buffer_->markDirty();
3447 // then check the current buffer
3450 update(bv_->text, BufferView::UPDATE);
3451 if (bv_->text->updateInset(bv_, inset)) {
3455 | BufferView::FITCUR
3456 | BufferView::CHANGE);
3458 update(bv_->text, SELECT);
3466 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3469 if (!available()) return;
3472 beforeChange(bv_->text);
3473 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3477 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3478 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3479 if (find(codes.begin(), codes.end(), inset->lyxCode())
3482 static_cast<InsetCommand const *>(inset)->getContents();
3485 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3486 if (bv_->text->cursor.pos()
3487 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3488 LyXCursor tmp = bv_->text->cursor;
3489 bv_->text->cursor.par(bv_->text->firstParagraph());
3490 bv_->text->cursor.pos(0);
3491 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3492 bv_->text->cursor = tmp;
3493 bv_->owner()->message(_("No more insets"));
3496 bv_->owner()->message(_("No more insets"));
3499 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3500 bv_->text->selection.cursor = bv_->text->cursor;
3504 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3506 gotoInset(vector<Inset::Code>(1, code), same_content);