12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
20 #include "bufferview_funcs.h"
21 #include "TextCache.h"
22 #include "bufferlist.h"
23 #include "lyx_gui_misc.h"
26 #include "support/LAssert.h"
27 #include "frontends/Dialogs.h"
28 #include "insets/insetbib.h"
29 #include "insets/insettext.h"
30 /// added for Dispatch functions
32 #include "frontends/FileDialog.h"
34 #include "FloatList.h"
35 #include "support/filetools.h"
36 #include "support/lyxfunctional.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetlatexaccent.h"
39 #include "insets/insettoc.h"
40 #include "insets/insetref.h"
41 #include "insets/insetparent.h"
42 #include "insets/insetindex.h"
43 #include "insets/insetinfo.h"
44 #include "insets/insetinclude.h"
45 #include "insets/insetcite.h"
46 #include "insets/insetert.h"
47 #include "insets/insetexternal.h"
48 #include "insets/insetgraphics.h"
49 #include "insets/insetfoot.h"
50 #include "insets/insetmarginal.h"
51 #include "insets/insetminipage.h"
52 #include "insets/insetfloat.h"
53 #include "insets/insetlist.h"
54 #include "insets/insettabular.h"
55 #include "insets/insettheorem.h"
56 #include "insets/insetcaption.h"
57 #include "insets/insetfloatlist.h"
58 #include "insets/insetspecialchar.h"
59 #include "mathed/formulamacro.h"
60 #include "mathed/formula.h"
62 #include "ParagraphParameters.h"
64 extern LyXTextClass::size_type current_layout;
65 extern int greek_kb_flag;
76 /* the selection possible is needed, that only motion events are
77 * used, where the bottom press event was on the drawing area too */
78 bool selection_possible = false;
80 extern BufferList bufferlist;
81 extern char ascii_type;
83 extern bool math_insert_greek(BufferView *, char);
84 extern void sigchldhandler(pid_t pid, int * status);
85 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
89 const unsigned int saved_positions_num = 20;
94 XSync(fl_get_display(), 0);
98 void SetXtermCursor(Window win)
100 static Cursor cursor;
101 static bool cursor_undefined = true;
102 if (cursor_undefined){
103 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
104 XFlush(fl_get_display());
105 cursor_undefined = false;
107 XDefineCursor(fl_get_display(), win, cursor);
108 XFlush(fl_get_display());
114 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
115 int xpos, int ypos, int width, int height)
116 : bv_(b), owner_(o), buffer_(0),
117 current_scrollbar_value(0), cursor_timeout(400),
118 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
122 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
123 workarea_.workAreaExpose
124 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
125 workarea_.workAreaEnter
126 .connect(slot(this, &BufferView::Pimpl::enterView));
127 workarea_.workAreaLeave
128 .connect(slot(this, &BufferView::Pimpl::leaveView));
129 workarea_.workAreaButtonPress
130 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
131 workarea_.workAreaButtonRelease
133 &BufferView::Pimpl::workAreaButtonRelease));
134 workarea_.workAreaMotionNotify
135 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
136 workarea_.workAreaDoubleClick
137 .connect(slot(this, &BufferView::Pimpl::doubleClick));
138 workarea_.workAreaTripleClick
139 .connect(slot(this, &BufferView::Pimpl::tripleClick));
140 workarea_.workAreaKeyPress
141 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
143 cursor_timeout.timeout.connect(slot(this,
144 &BufferView::Pimpl::cursorToggle));
145 cursor_timeout.start();
146 workarea_.setFocus();
147 saved_positions.resize(saved_positions_num);
151 Painter & BufferView::Pimpl::painter()
153 return workarea_.getPainter();
157 void BufferView::Pimpl::buffer(Buffer * b)
159 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
163 buffer_->delUser(bv_);
165 // Put the old text into the TextCache, but
166 // only if the buffer is still loaded.
167 // Also set the owner of the test to 0
168 // bv_->text->owner(0);
169 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
170 if (lyxerr.debugging())
171 textcache.show(lyxerr, "BufferView::buffer");
176 // Set current buffer
179 if (bufferlist.getState() == BufferList::CLOSING) return;
182 // screen is always deleted when the buffer is changed.
185 // If we are closing the buffer, use the first buffer as current
187 buffer_ = bufferlist.first();
191 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
192 buffer_->addUser(bv_);
193 // If we don't have a text object for this, we make one
194 if (bv_->text == 0) {
195 resizeCurrentBuffer();
200 bv_->text->first = screen_->TopCursorVisible(bv_->text);
201 owner_->updateMenubar();
202 owner_->updateToolbar();
203 // Similarly, buffer-dependent dialogs should be updated or
204 // hidden. This should go here because some dialogs (eg ToC)
205 // require bv_->text.
206 owner_->getDialogs()->updateBufferDependent(true);
210 lyxerr[Debug::INFO] << " No Buffer!" << endl;
211 owner_->updateMenubar();
212 owner_->updateToolbar();
213 owner_->getDialogs()->hideBufferDependent();
217 // Also remove all remaining text's from the testcache.
218 // (there should not be any!) (if there is any it is a
220 if (lyxerr.debugging())
221 textcache.show(lyxerr, "buffer delete all");
224 // should update layoutchoice even if we don't have a buffer.
225 owner_->updateLayoutChoice();
227 owner_->updateWindowTitle();
231 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
233 workarea_.resize(xpos, ypos, width, height);
234 update(bv_->text, SELECT);
239 void BufferView::Pimpl::resize()
242 resizeCurrentBuffer();
246 void BufferView::Pimpl::redraw()
248 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
253 bool BufferView::Pimpl::fitCursor(LyXText * text)
255 lyx::Assert(screen_.get());
257 bv_->owner()->getDialogs()->updateParagraph();
259 bool const ret = screen_->FitCursor(text, bv_);
266 void BufferView::Pimpl::redoCurrentBuffer()
268 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
269 if (buffer_ && bv_->text) {
271 owner_->updateLayoutChoice();
276 int BufferView::Pimpl::resizeCurrentBuffer()
278 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
281 Paragraph * selstartpar = 0;
282 Paragraph * selendpar = 0;
283 UpdatableInset * the_locking_inset = 0;
285 Paragraph::size_type pos = 0;
286 Paragraph::size_type selstartpos = 0;
287 Paragraph::size_type selendpos = 0;
288 bool selection = false;
289 bool mark_set = false;
293 owner_->message(_("Formatting document..."));
296 par = bv_->text->cursor.par();
297 pos = bv_->text->cursor.pos();
298 selstartpar = bv_->text->selection.start.par();
299 selstartpos = bv_->text->selection.start.pos();
300 selendpar = bv_->text->selection.end.par();
301 selendpos = bv_->text->selection.end.pos();
302 selection = bv_->text->selection.set();
303 mark_set = bv_->text->selection.mark();
304 the_locking_inset = bv_->theLockingInset();
306 bv_->text = new LyXText(bv_);
308 // See if we have a text in TextCache that fits
309 // the new buffer_ with the correct width.
310 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
312 if (lyxerr.debugging()) {
313 lyxerr << "Found a LyXText that fits:\n";
314 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
316 // Set the owner of the newly found text
317 // bv_->text->owner(bv_);
318 if (lyxerr.debugging())
319 textcache.show(lyxerr, "resizeCurrentBuffer");
321 bv_->text = new LyXText(bv_);
327 bv_->text->selection.set(true);
328 /* at this point just to avoid the Delete-Empty-Paragraph
329 * Mechanism when setting the cursor */
330 bv_->text->selection.mark(mark_set);
332 bv_->text->setCursor(bv_, selstartpar, selstartpos);
333 bv_->text->selection.cursor = bv_->text->cursor;
334 bv_->text->setCursor(bv_, selendpar, selendpos);
335 bv_->text->setSelection(bv_);
336 bv_->text->setCursor(bv_, par, pos);
338 bv_->text->setCursor(bv_, par, pos);
339 bv_->text->selection.cursor = bv_->text->cursor;
340 bv_->text->selection.set(false);
342 // remake the inset locking
343 bv_->theLockingInset(the_locking_inset);
345 bv_->text->first = screen_->TopCursorVisible(bv_->text);
346 buffer_->resizeInsets(bv_);
347 // this will scroll the screen such that the cursor becomes visible
354 /// clear the "Formatting Document" message
357 /// get rid of the splash screen if it's not gone already
358 owner_->getDialogs()->destroySplash();
364 void BufferView::Pimpl::updateScreen()
366 // Regenerate the screen.
367 screen_.reset(new LyXScreen(workarea_));
371 void BufferView::Pimpl::updateScrollbar()
373 /* If the text is smaller than the working area, the scrollbar
374 * maximum must be the working area height. No scrolling will
378 workarea_.setScrollbar(0, 1.0);
382 static unsigned long text_height;
383 static unsigned long work_height;
385 unsigned long const tmp_text_height = bv_->text->height;
386 long const tmp_scrollbar_value = bv_->text->first;
388 // check if anything has changed.
389 if (text_height == tmp_text_height
390 && work_height == workarea_.height()
391 && current_scrollbar_value == tmp_scrollbar_value)
395 text_height = tmp_text_height;
396 work_height = workarea_.height();
397 current_scrollbar_value = tmp_scrollbar_value;
399 long const height_diff = text_height - work_height;
401 if (height_diff <= 0) {
402 workarea_.setScrollbar(0, 1.0);
407 workarea_.setScrollbarBounds(0, height_diff);
408 double const lineh = bv_->text->defaultHeight();
409 workarea_.setScrollbarIncrements(lineh);
410 double const slider_size = 1.0 / double(height_diff) ;
411 workarea_.setScrollbar(current_scrollbar_value, slider_size);
415 // Callback for scrollbar slider
416 void BufferView::Pimpl::scrollCB(double value)
418 if (!buffer_) return;
420 current_scrollbar_value = long(value);
421 if (current_scrollbar_value < 0)
422 current_scrollbar_value = 0;
427 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
429 if (!lyxrc.cursor_follows_scrollbar) {
434 LyXText * vbt = bv_->text;
436 int const height = vbt->defaultHeight();
437 int const first = static_cast<int>((bv_->text->first + height));
438 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
440 if (vbt->cursor.y() < first)
441 vbt->setCursorFromCoordinates(bv_, 0, first);
442 else if (vbt->cursor.y() > last)
443 vbt->setCursorFromCoordinates(bv_, 0, last);
449 int BufferView::Pimpl::scrollUp(long time)
451 if (!buffer_) return 0;
452 if (!screen_.get()) return 0;
454 double value = workarea_.getScrollbarValue();
456 if (value == 0) return 0;
458 float add_value = (bv_->text->defaultHeight()
459 + float(time) * float(time) * 0.125);
461 if (add_value > workarea_.height())
462 add_value = float(workarea_.height() -
463 bv_->text->defaultHeight());
470 workarea_.setScrollbarValue(value);
477 int BufferView::Pimpl::scrollDown(long time)
479 if (!buffer_) return 0;
480 if (!screen_.get()) return 0;
482 double value = workarea_.getScrollbarValue();
483 pair<float, float> p = workarea_.getScrollbarBounds();
484 double const max = p.second;
486 if (value == max) return 0;
488 float add_value = (bv_->text->defaultHeight()
489 + float(time) * float(time) * 0.125);
491 if (add_value > workarea_.height())
492 add_value = float(workarea_.height() -
493 bv_->text->defaultHeight());
500 workarea_.setScrollbarValue(value);
507 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
509 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
513 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
515 // Only use motion with button 1
516 if (!(state & Button1MotionMask))
519 if (!buffer_ || !screen_.get()) return;
521 // Check for inset locking
522 if (bv_->theLockingInset()) {
523 LyXCursor cursor = bv_->text->cursor;
524 LyXFont font = bv_->text->getFont(buffer_,
525 cursor.par(), cursor.pos());
526 int width = bv_->theLockingInset()->width(bv_, font);
527 int inset_x = font.isVisibleRightToLeft()
528 ? cursor.x() - width : cursor.x();
529 int start_x = inset_x + bv_->theLockingInset()->scroll();
530 bv_->theLockingInset()->
531 InsetMotionNotify(bv_,
533 y - cursor.y() + bv_->text->first,
538 /* The test for not selection possible is needed, that only motion
539 events are used, where the bottom press event was on
540 the drawing area too */
541 if (!selection_possible)
544 screen_->HideCursor();
546 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
548 if (!bv_->text->selection.set())
549 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
551 bv_->text->setSelection(bv_);
552 screen_->ToggleToggle(bv_->text, bv_);
553 fitCursor(bv_->text);
554 screen_->ShowCursor(bv_->text, bv_);
558 // Single-click on work area
559 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
562 if (!buffer_ || !screen_.get()) return;
564 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
566 // ok ok, this is a hack.
567 if (button == 4 || button == 5) {
570 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
573 scrollDown(lyxrc.wheel_jump);
578 if (bv_->theLockingInset()) {
579 // We are in inset locking mode
581 /* Check whether the inset was hit. If not reset mode,
582 otherwise give the event to the inset */
583 if (inset_hit == bv_->theLockingInset()) {
584 bv_->theLockingInset()->
585 InsetButtonPress(bv_,
590 bv_->unlockInset(bv_->theLockingInset());
595 selection_possible = true;
596 screen_->HideCursor();
598 int const screen_first = bv_->text->first;
600 // Middle button press pastes if we have a selection
601 bool paste_internally = false;
603 && bv_->text->selection.set()) {
604 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
605 paste_internally = true;
608 // Clear the selection
609 screen_->ToggleSelection(bv_->text, bv_);
610 bv_->text->clearSelection(bv_);
611 bv_->text->fullRebreak(bv_);
612 screen_->Update(bv_->text, bv_);
615 // Single left click in math inset?
616 if ((inset_hit != 0) &&
617 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
618 // Highly editable inset, like math
619 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
620 selection_possible = false;
621 owner_->updateLayoutChoice();
622 owner_->message(inset->EditMessage());
623 inset->InsetButtonPress(bv_, xpos, ypos, button);
624 inset->Edit(bv_, xpos, ypos, button);
628 // Right click on a footnote flag opens float menu
630 selection_possible = false;
634 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
635 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
636 bv_->text->finishUndo();
637 bv_->text->selection.cursor = bv_->text->cursor;
638 bv_->text->cursor.x_fix(bv_->text->cursor.x());
640 owner_->updateLayoutChoice();
641 if (fitCursor(bv_->text)) {
642 selection_possible = false;
645 // Insert primary selection with middle mouse
646 // if there is a local selection in the current buffer,
649 if (paste_internally)
650 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
652 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
654 selection_possible = false;
660 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
666 LyXText * text = bv_->getLyXText();
668 if (text->bv_owner && bv_->theLockingInset())
671 if (screen_.get() && button == 1) {
672 if (text->bv_owner) {
673 screen_->HideCursor();
674 screen_->ToggleSelection(text, bv_);
675 text->selectWord(bv_);
676 screen_->ToggleSelection(text, bv_, false);
678 text->selectWord(bv_);
680 /* This will fit the cursor on the screen
682 update(text, BufferView::SELECT|BufferView::FITCUR);
687 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
693 LyXText * text = bv_->getLyXText();
695 if (text->bv_owner && bv_->theLockingInset())
698 if (screen_.get() && (button == 1)) {
699 screen_->HideCursor();
700 screen_->ToggleSelection(text, bv_);
701 text->cursorHome(bv_);
702 text->selection.cursor = text->cursor;
703 text->cursorEnd(bv_);
704 text->setSelection(bv_);
705 screen_->ToggleSelection(text, bv_, false);
706 /* This will fit the cursor on the screen
708 update(text, BufferView::SELECT|BufferView::FITCUR);
713 void BufferView::Pimpl::enterView()
715 if (active() && available()) {
716 SetXtermCursor(workarea_.getWin());
717 using_xterm_cursor = true;
722 void BufferView::Pimpl::leaveView()
724 if (using_xterm_cursor) {
725 XUndefineCursor(fl_get_display(), workarea_.getWin());
726 using_xterm_cursor = false;
731 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
734 if (!buffer_ || !screen_.get()) return;
736 // If we hit an inset, we have the inset coordinates in these
737 // and inset_hit points to the inset. If we do not hit an
738 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
739 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
741 if (bv_->theLockingInset()) {
742 // We are in inset locking mode.
744 /* LyX does a kind of work-area grabbing for insets.
745 Only a ButtonPress Event outside the inset will
746 force a InsetUnlock. */
747 bv_->theLockingInset()->
748 InsetButtonRelease(bv_, x, y, button);
752 selection_possible = false;
760 // Did we hit an editable inset?
762 // Inset like error, notes and figures
763 selection_possible = false;
765 // CHECK fix this proper in 0.13
767 // Following a ref shouldn't issue
768 // a push on the undo-stack
769 // anylonger, now that we have
770 // keybindings for following
771 // references and returning from
772 // references. IMHO though, it
773 // should be the inset's own business
774 // to push or not push on the undo
775 // stack. They don't *have* to
776 // alter the document...
778 // ...or maybe the SetCursorParUndo()
779 // below isn't necessary at all anylonger?
780 if (inset_hit->LyxCode() == Inset::REF_CODE) {
781 bv_->text->setCursorParUndo(buffer_);
784 owner_->message(inset_hit->EditMessage());
786 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
787 // Highly editable inset, like math
788 UpdatableInset *inset = (UpdatableInset *)inset_hit;
789 inset->InsetButtonRelease(bv_, x, y, button);
791 inset_hit->InsetButtonRelease(bv_, x, y, button);
792 inset_hit->Edit(bv_, x, y, button);
797 // check whether we want to open a float
801 if (bv_->text->cursor.pos() <
802 bv_->text->cursor.par()->size()) {
803 c = bv_->text->cursor.par()->
804 getChar(bv_->text->cursor.pos());
806 if (bv_->text->cursor.pos() - 1 >= 0) {
807 c = bv_->text->cursor.par()->
808 getChar(bv_->text->cursor.pos() - 1);
811 selection_possible = false;
816 // Maybe we want to edit a bibitem ale970302
817 if (bv_->text->cursor.par()->bibkey && x < 20 +
818 bibitemMaxWidth(bv_, textclasslist.
820 params.textclass).defaultfont())) {
821 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
829 * Returns an inset if inset was hit. 0 otherwise.
830 * If hit, the coordinates are changed relative to the inset.
831 * Otherwise coordinates are not changed, and false is returned.
833 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
834 unsigned int /* button */)
839 int y_tmp = y + text->first;
842 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
843 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
846 if (cursor.pos() < cursor.par()->size()
847 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
848 && cursor.par()->getInset(cursor.pos())
849 && cursor.par()->getInset(cursor.pos())->Editable()) {
851 // Check whether the inset really was hit
852 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
853 LyXFont font = text->getFont(buffer_,
854 cursor.par(), cursor.pos());
855 int const width = tmpinset->width(bv_, font);
856 int const inset_x = font.isVisibleRightToLeft()
857 ? cursor.x() - width : cursor.x();
858 int const start_x = inset_x + tmpinset->scroll();
859 int const end_x = inset_x + width;
861 if (x > start_x && x < end_x
862 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
863 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
864 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
866 // The origin of an inset is on the baseline
867 y = y_tmp - (text->cursor.y());
872 if ((cursor.pos() - 1 >= 0) &&
873 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
874 (cursor.par()->getInset(cursor.pos() - 1)) &&
875 (cursor.par()->getInset(cursor.pos() - 1)->Editable())) {
876 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
877 LyXFont font = text->getFont(buffer_, cursor.par(),
879 int const width = tmpinset->width(bv_, font);
880 int const inset_x = font.isVisibleRightToLeft()
881 ? cursor.x() : cursor.x() - width;
882 int const start_x = inset_x + tmpinset->scroll();
883 int const end_x = inset_x + width;
885 if (x > start_x && x < end_x
886 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
887 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
889 if (move_cursor && (tmpinset != bv_->theLockingInset()))
891 text->setCursor(bv_, cursor.par(),
892 cursor.pos() - 1, true);
894 // The origin of an inset is on the baseline
895 y = y_tmp - (text->cursor.y());
903 void BufferView::Pimpl::workAreaExpose()
905 static int work_area_width;
906 static unsigned int work_area_height;
908 bool const widthChange = workarea_.workWidth() != work_area_width;
909 bool const heightChange = workarea_.height() != work_area_height;
911 // update from work area
912 work_area_width = workarea_.workWidth();
913 work_area_height = workarea_.height();
916 // The visible LyXView need a resize
919 // Remove all texts from the textcache
920 // This is not _really_ what we want to do. What
921 // we really want to do is to delete in textcache
922 // that does not have a BufferView with matching
923 // width, but as long as we have only one BufferView
924 // deleting all gives the same result.
925 if (lyxerr.debugging())
926 textcache.show(lyxerr, "Expose delete all");
928 } else if (heightChange) {
929 // Rebuild image of current screen
931 // fitCursor() ensures we don't jump back
932 // to the start of the document on vertical
934 fitCursor(bv_->text);
936 // The main window size has changed, repaint most stuff
938 } else if (screen_.get())
939 screen_->Redraw(bv_->text, bv_);
941 // Grey box when we don't have a buffer
945 // always make sure that the scrollbar is sane.
947 owner_->updateLayoutChoice();
952 void BufferView::Pimpl::update()
955 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
957 screen_->Update(bv_->text, bv_);
961 // Values used when calling update:
963 // -2 - update, move sel_cursor if selection, fitcursor
964 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
965 // 0 - update, move sel_cursor if selection, fitcursor
966 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
967 // 3 - update, move sel_cursor if selection
970 // a simple redraw of the parts that need refresh
972 // move sel_cursor if selection -
973 // the text's sel_cursor is moved if there is selection is progress
976 // fitCursor() is called and the scrollbar updated
979 // the buffer is marked dirty.
988 // UPDATE_ONLY = UPDATE;
989 // UPDATE_SELECT = UPDATE | SELECT;
990 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
991 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
993 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
994 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
995 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
996 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
997 // update(3) -> update(1) -> update(1) -> update(SELECT)
999 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
1001 owner_->updateLayoutChoice();
1003 if (!text->selection.set() && (f & SELECT)) {
1004 text->selection.cursor = text->cursor;
1007 text->fullRebreak(bv_);
1009 if (text->inset_owner) {
1010 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1011 updateInset(text->inset_owner, true);
1020 buffer_->markDirty();
1025 // Callback for cursor timer
1026 void BufferView::Pimpl::cursorToggle()
1028 // Quite a nice place for asyncron Inset updating, isn't it?
1029 // Actually no! This is run even if no buffer exist... so (Lgb)
1031 cursor_timeout.restart();
1036 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1037 if (pid == -1) // error find out what is wrong
1038 ; // ignore it for now.
1040 sigchldhandler(pid, &status);
1042 updatelist.update(bv_);
1044 if (!screen_.get()) {
1045 cursor_timeout.restart();
1049 if (!bv_->theLockingInset()) {
1050 screen_->CursorToggle(bv_->text, bv_);
1052 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1055 cursor_timeout.restart();
1059 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1061 if (!text->cursor.row()->previous())
1064 int y = text->first;
1065 if (text->inset_owner)
1066 y += bv_->text->first;
1067 Row * cursorrow = text->cursor.row();
1068 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1069 bv_->text->finishUndo();
1070 // This is to allow jumping over large insets
1071 if ((cursorrow == text->cursor.row()))
1072 text->cursorUp(bv_);
1074 if (text->inset_owner ||
1075 text->cursor.row()->height() < workarea_.height())
1076 screen_->Draw(bv_->text, bv_,
1078 - text->cursor.row()->baseline()
1079 + text->cursor.row()->height()
1080 - workarea_.height() + 1 );
1085 void BufferView::Pimpl::cursorNext(LyXText * text)
1087 if (!text->cursor.row()->next())
1090 int y = text->first + workarea_.height();
1091 // if (text->inset_owner)
1092 // y += bv_->text->first;
1093 text->getRowNearY(y);
1095 Row * cursorrow = text->cursor.row();
1096 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1097 bv_->text->finishUndo();
1098 // This is to allow jumping over large insets
1099 if ((cursorrow == bv_->text->cursor.row()))
1100 text->cursorDown(bv_);
1102 if (text->inset_owner ||
1103 text->cursor.row()->height() < workarea_.height())
1104 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1105 text->cursor.row()->baseline());
1110 bool BufferView::Pimpl::available() const
1112 if (buffer_ && bv_->text) return true;
1117 void BufferView::Pimpl::beforeChange(LyXText * text)
1120 text->clearSelection(bv_);
1124 void BufferView::Pimpl::savePosition(unsigned int i)
1126 if (i >= saved_positions_num)
1128 saved_positions[i] = Position(buffer_->fileName(),
1129 bv_->text->cursor.par()->id(),
1130 bv_->text->cursor.pos());
1133 str << _("Saved bookmark") << ' ' << i;
1134 owner_->message(str.str().c_str());
1139 void BufferView::Pimpl::restorePosition(unsigned int i)
1141 if (i >= saved_positions_num)
1144 string const fname = saved_positions[i].filename;
1146 beforeChange(bv_->text);
1148 if (fname != buffer_->fileName()) {
1149 Buffer * b = bufferlist.exists(fname) ?
1150 bufferlist.getBuffer(fname) :
1151 bufferlist.loadLyXFile(fname); // don't ask, just load it
1152 if (b != 0 ) buffer(b);
1155 Paragraph * par = bv_->text->getParFromID(saved_positions[i].par_id);
1159 bv_->text->setCursor(bv_, par,
1160 min(par->size(), saved_positions[i].par_pos));
1162 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1165 str << _("Moved to bookmark") << ' ' << i;
1166 owner_->message(str.str().c_str());
1171 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1173 if (i >= saved_positions_num)
1176 return !saved_positions[i].filename.empty();
1180 void BufferView::Pimpl::setState()
1182 if (!lyxrc.rtl_support)
1185 LyXText * text = bv_->getLyXText();
1186 if (text->real_current_font.isRightToLeft() &&
1187 text->real_current_font.latex() != LyXFont::ON) {
1188 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1189 owner_->getIntl()->KeyMapSec();
1191 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1192 owner_->getIntl()->KeyMapPrim();
1197 void BufferView::Pimpl::insetSleep()
1199 if (bv_->theLockingInset() && !inset_slept) {
1200 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1201 bv_->theLockingInset()->InsetUnlock(bv_);
1207 void BufferView::Pimpl::insetWakeup()
1209 if (bv_->theLockingInset() && inset_slept) {
1210 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1211 inset_slept = false;
1216 void BufferView::Pimpl::insetUnlock()
1218 if (bv_->theLockingInset()) {
1220 bv_->theLockingInset()->InsetUnlock(bv_);
1221 bv_->theLockingInset(0);
1222 bv_->text->finishUndo();
1223 inset_slept = false;
1228 bool BufferView::Pimpl::focus() const
1230 return workarea_.hasFocus();
1234 void BufferView::Pimpl::focus(bool f)
1236 if (f) workarea_.setFocus();
1240 bool BufferView::Pimpl::active() const
1242 return workarea_.active();
1246 bool BufferView::Pimpl::belowMouse() const
1248 return workarea_.belowMouse();
1252 void BufferView::Pimpl::showCursor()
1255 screen_->ShowCursor(bv_->text, bv_);
1259 void BufferView::Pimpl::hideCursor()
1262 screen_->HideCursor();
1266 void BufferView::Pimpl::toggleSelection(bool b)
1269 screen_->ToggleSelection(bv_->text, bv_, b);
1273 void BufferView::Pimpl::toggleToggle()
1276 screen_->ToggleToggle(bv_->text, bv_);
1280 void BufferView::Pimpl::center()
1282 beforeChange(bv_->text);
1283 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1284 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1286 screen_->Draw(bv_->text, bv_, 0);
1288 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1293 void BufferView::Pimpl::pasteClipboard(bool asPara)
1295 if (!buffer_) return;
1297 screen_->HideCursor();
1298 beforeChange(bv_->text);
1300 string const clip(workarea_.getClipboard());
1302 if (clip.empty()) return;
1305 bv_->text->insertStringAsParagraphs(bv_, clip);
1307 bv_->text->insertStringAsLines(bv_, clip);
1309 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1313 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1315 workarea_.putClipboard(stuff);
1320 * Dispatch functions for actions which can be valid for BufferView->text
1321 * and/or InsetText->text!!!
1326 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1328 LyXText * lt = bv_->getLyXText();
1330 if (selecting || lt->selection.mark()) {
1331 lt->setSelection(bv_);
1335 update(lt, BufferView::SELECT|BufferView::FITCUR);
1338 /* ---> Everytime the cursor is moved, show the current font state. */
1339 // should this too me moved out of this func?
1340 //owner->showState();
1345 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1347 LyXCursor cursor = bv_->getLyXText()->cursor;
1348 Buffer::inset_iterator it =
1349 find_if(Buffer::inset_iterator(
1350 cursor.par(), cursor.pos()),
1351 buffer_->inset_iterator_end(),
1352 lyx::compare_memfun(&Inset::LyxCode, code));
1353 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1357 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1359 string filename = filen;
1361 if (filename.empty()) {
1362 // Launch a file browser
1363 string initpath = lyxrc.document_path;
1366 string const trypath = owner_->buffer()->filepath;
1367 // If directory is writeable, use this as default.
1368 if (IsDirWriteable(trypath) == 1)
1372 FileDialog fileDlg(bv_->owner(),
1373 _("Select LyX document to insert"),
1375 make_pair(string(_("Documents")),
1376 string(lyxrc.document_path)),
1377 make_pair(string(_("Examples")),
1378 string(AddPath(system_lyxdir, "examples"))));
1380 FileDialog::Result result =
1381 fileDlg.Select(initpath,
1382 _("*.lyx| LyX Documents (*.lyx)"));
1384 if (result.first == FileDialog::Later)
1387 filename = result.second;
1389 // check selected filename
1390 if (filename.empty()) {
1391 owner_->message(_("Canceled."));
1396 // get absolute path of file and make sure the filename ends
1398 filename = MakeAbsPath(filename);
1399 if (!IsLyXFilename(filename))
1402 string const disp_fn(MakeDisplayPath(filename));
1406 s1 << _("Inserting document") << ' '
1407 << disp_fn << " ...";
1408 owner_->message(s1.str().c_str());
1409 bool const res = bv_->insertLyXFile(filename);
1412 str << _("Document") << ' ' << disp_fn
1413 << ' ' << _("inserted.");
1414 owner_->message(str.str().c_str());
1417 str << _("Could not insert document") << ' '
1419 owner_->message(str.str().c_str());
1424 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1427 // --- Misc -------------------------------------------
1431 LyXText * lt = bv_->getLyXText();
1432 lt->toggleAppendix(bv_);
1435 | BufferView::FITCUR
1436 | BufferView::CHANGE);
1441 case LFUN_TOC_INSERT:
1443 InsetCommandParams p;
1444 p.setCmdName("tableofcontents");
1445 Inset * inset = new InsetTOC(p);
1446 if (!insertInset(inset, "Standard"))
1451 case LFUN_TABULAR_FEATURE:
1452 case LFUN_SCROLL_INSET:
1453 // this is not handled here as this funktion is only aktive
1454 // if we have a locking_inset and that one is (or contains)
1458 case LFUN_INSET_GRAPHICS:
1460 Inset * new_inset = new InsetGraphics;
1461 if (!insertInset(new_inset)) {
1464 // this is need because you don't use a inset->Edit()
1465 updateInset(new_inset, true);
1466 new_inset->Edit(bv_, 0, 0, 0);
1476 case LFUN_PASTESELECTION:
1478 bool asPara = false;
1479 if (argument == "paragraph") asPara = true;
1480 pasteClipboard(asPara);
1492 case LFUN_LAYOUT_COPY:
1493 bv_->copyEnvironment();
1496 case LFUN_LAYOUT_PASTE:
1497 bv_->pasteEnvironment();
1501 case LFUN_GOTOERROR:
1502 gotoInset(Inset::ERROR_CODE, false);
1506 gotoInset(Inset::IGNORE_CODE, false);
1509 case LFUN_REFERENCE_GOTO:
1511 vector<Inset::Code> tmp;
1512 tmp.push_back(Inset::LABEL_CODE);
1513 tmp.push_back(Inset::REF_CODE);
1514 gotoInset(tmp, true);
1518 case LFUN_HYPHENATION:
1526 case LFUN_END_OF_SENTENCE:
1530 case LFUN_MENU_SEPARATOR:
1539 changeDepth(bv_, bv_->getLyXText(), 0);
1542 case LFUN_DEPTH_MIN:
1543 changeDepth(bv_, bv_->getLyXText(), -1);
1546 case LFUN_DEPTH_PLUS:
1547 changeDepth(bv_, bv_->getLyXText(), 1);
1551 owner_->getDialogs()->setUserFreeFont();
1557 owner_->showState();
1560 case LFUN_FILE_INSERT:
1562 MenuInsertLyXFile(argument);
1566 case LFUN_FILE_INSERT_ASCII_PARA:
1567 InsertAsciiFile(bv_, argument, true);
1570 case LFUN_FILE_INSERT_ASCII:
1571 InsertAsciiFile(bv_, argument, false);
1576 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1577 << argument << endl;
1579 // Derive layout number from given argument (string)
1580 // and current buffer's textclass (number). */
1581 LyXTextClassList::ClassList::size_type tclass =
1582 buffer_->params.textclass;
1583 pair <bool, LyXTextClass::size_type> layout =
1584 textclasslist.NumberOfLayout(tclass, argument);
1586 // If the entry is obsolete, use the new one instead.
1588 string obs = textclasslist.Style(tclass,layout.second)
1592 textclasslist.NumberOfLayout(tclass, obs);
1595 // see if we found the layout number:
1596 if (!layout.first) {
1597 owner_->getLyXFunc()->setErrorMessage(
1598 string(N_("Layout ")) + argument +
1603 if (current_layout != layout.second) {
1604 LyXText * lt = bv_->getLyXText();
1606 current_layout = layout.second;
1609 | BufferView::FITCUR);
1610 lt->setLayout(bv_, layout.second);
1611 owner_->setLayout(layout.second);
1614 | BufferView::FITCUR
1615 | BufferView::CHANGE);
1622 Lang(bv_, argument);
1624 owner_->showState();
1629 owner_->showState();
1634 owner_->showState();
1639 owner_->showState();
1644 owner_->showState();
1649 owner_->showState();
1654 owner_->showState();
1659 owner_->showState();
1662 case LFUN_UNDERLINE:
1664 owner_->showState();
1667 case LFUN_FONT_SIZE:
1668 FontSize(bv_, argument);
1669 owner_->showState();
1672 case LFUN_FONT_STATE:
1673 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1676 case LFUN_UPCASE_WORD:
1678 LyXText * lt = bv_->getLyXText();
1682 | BufferView::FITCUR);
1683 lt->changeWordCase(bv_, LyXText::text_uppercase);
1684 if (lt->inset_owner)
1685 updateInset(lt->inset_owner, true);
1688 | BufferView::FITCUR
1689 | BufferView::CHANGE);
1693 case LFUN_LOWCASE_WORD:
1695 LyXText * lt = bv_->getLyXText();
1697 update(lt, BufferView::SELECT|BufferView::FITCUR);
1698 lt->changeWordCase(bv_, LyXText::text_lowercase);
1699 if (lt->inset_owner)
1700 updateInset(lt->inset_owner, true);
1703 | BufferView::FITCUR
1704 | BufferView::CHANGE);
1708 case LFUN_CAPITALIZE_WORD:
1710 LyXText * lt = bv_->getLyXText();
1712 update(lt, BufferView::SELECT|BufferView::FITCUR);
1713 lt->changeWordCase(bv_,
1714 LyXText::text_capitalization);
1715 if (lt->inset_owner)
1716 updateInset(lt->inset_owner, true);
1719 | BufferView::FITCUR
1720 | BufferView::CHANGE);
1724 case LFUN_TRANSPOSE_CHARS:
1726 LyXText * lt = bv_->getLyXText();
1728 update(lt, BufferView::SELECT|BufferView::FITCUR);
1729 lt->transposeChars(*bv_);
1730 if (lt->inset_owner)
1731 updateInset(lt->inset_owner, true);
1734 | BufferView::FITCUR
1735 | BufferView::CHANGE);
1740 case LFUN_INSERT_LABEL:
1741 MenuInsertLabel(bv_, argument);
1744 case LFUN_REF_INSERT:
1745 if (argument.empty()) {
1746 InsetCommandParams p("ref");
1747 owner_->getDialogs()->createRef(p.getAsString());
1749 InsetCommandParams p;
1750 p.setFromString(argument);
1752 InsetRef * inset = new InsetRef(p, *buffer_);
1753 if (!insertInset(inset))
1756 updateInset(inset, true);
1760 case LFUN_BOOKMARK_SAVE:
1761 savePosition(strToUnsignedInt(argument));
1764 case LFUN_BOOKMARK_GOTO:
1765 restorePosition(strToUnsignedInt(argument));
1770 string label(argument);
1771 if (label.empty()) {
1773 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1775 label = inset->getContents();
1780 if (!label.empty()) {
1781 //bv_->savePosition(0);
1782 if (!bv_->gotoLabel(label))
1783 WriteAlert(_("Error"),
1784 _("Couldn't find this label"),
1785 _("in current document."));
1790 // --- Cursor Movements -----------------------------
1793 LyXText * lt = bv_->getLyXText();
1795 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1796 if (!lt->selection.mark())
1798 update(lt, BufferView::SELECT|BufferView::FITCUR);
1800 lt->cursorLeft(bv_, false);
1801 if (lt->cursor.pos() < lt->cursor.par()->size()
1802 && lt->cursor.par()->getChar(lt->cursor.pos())
1803 == Paragraph::META_INSET
1804 && lt->cursor.par()->getInset(lt->cursor.pos())
1805 && lt->cursor.par()->getInset(lt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1806 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1807 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1810 LyXFont const font =
1811 lt->getFont(buffer_,
1814 y = tmpinset->descent(bv_,font);
1816 tmpinset->Edit(bv_, 0, y, 0);
1820 lt->cursorRight(bv_, false);
1822 moveCursorUpdate(false);
1823 owner_->showState();
1829 // This is soooo ugly. Isn`t it possible to make
1830 // it simpler? (Lgb)
1831 LyXText * lt = bv_->getLyXText();
1832 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1833 if (!lt->selection.mark())
1835 update(lt, BufferView::SELECT|BufferView::FITCUR);
1836 LyXCursor const cur = lt->cursor;
1838 lt->cursorLeft(bv_, false);
1839 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1840 lt->cursor.pos() < lt->cursor.par()->size() &&
1841 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1842 Paragraph::META_INSET) &&
1843 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1844 (lt->cursor.par()->getInset(lt->cursor.pos())->Editable()
1845 == Inset::HIGHLY_EDITABLE))
1847 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1848 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1849 LyXFont const font = lt->getFont(buffer_,
1853 : tmpinset->descent(bv_,font);
1856 tmpinset->width(bv_,font),
1861 lt->cursorRight(bv_, false);
1864 moveCursorUpdate(false);
1865 owner_->showState();
1871 LyXText * lt = bv_->getLyXText();
1873 if (!lt->selection.mark())
1875 update(lt, BufferView::UPDATE);
1878 moveCursorUpdate(false);
1879 owner_->showState();
1885 LyXText * lt = bv_->getLyXText();
1887 if (!lt->selection.mark())
1889 update(lt, BufferView::UPDATE);
1890 lt->cursorDown(bv_);
1892 moveCursorUpdate(false);
1893 owner_->showState();
1897 case LFUN_UP_PARAGRAPH:
1899 LyXText * lt = bv_->getLyXText();
1901 if (!lt->selection.mark())
1903 update(lt, BufferView::UPDATE);
1904 lt->cursorUpParagraph(bv_);
1906 moveCursorUpdate(false);
1907 owner_->showState();
1911 case LFUN_DOWN_PARAGRAPH:
1913 LyXText * lt = bv_->getLyXText();
1915 if (!lt->selection.mark())
1917 update(lt, BufferView::UPDATE);
1918 lt->cursorDownParagraph(bv_);
1920 moveCursorUpdate(false);
1921 owner_->showState();
1927 LyXText * lt = bv_->getLyXText();
1929 if (!lt->selection.mark())
1931 update(lt, BufferView::UPDATE);
1934 moveCursorUpdate(false);
1935 owner_->showState();
1941 LyXText * lt = bv_->getLyXText();
1943 if (!lt->selection.mark())
1945 update(lt, BufferView::UPDATE);
1948 moveCursorUpdate(false);
1949 owner_->showState();
1955 LyXText * lt = bv_->getLyXText();
1957 if (!lt->selection.mark())
1959 update(lt, BufferView::SELECT|BufferView::FITCUR);
1960 lt->cursorHome(bv_);
1962 moveCursorUpdate(false);
1963 owner_->showState();
1969 LyXText * lt = bv_->getLyXText();
1971 if (!lt->selection.mark())
1974 BufferView::SELECT|BufferView::FITCUR);
1977 moveCursorUpdate(false);
1978 owner_->showState();
1982 case LFUN_SHIFT_TAB:
1985 LyXText * lt = bv_->getLyXText();
1987 if (!lt->selection.mark())
1990 BufferView::SELECT|BufferView::FITCUR);
1993 moveCursorUpdate(false);
1994 owner_->showState();
1998 case LFUN_WORDRIGHT:
2000 LyXText * lt = bv_->getLyXText();
2002 if (!lt->selection.mark())
2004 update(lt, BufferView::SELECT|BufferView::FITCUR);
2005 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2006 lt->cursorLeftOneWord(bv_);
2008 lt->cursorRightOneWord(bv_);
2010 moveCursorUpdate(false);
2011 owner_->showState();
2017 LyXText * lt = bv_->getLyXText();
2019 if (!lt->selection.mark())
2021 update(lt, BufferView::SELECT|BufferView::FITCUR);
2022 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2023 lt->cursorRightOneWord(bv_);
2025 lt->cursorLeftOneWord(bv_);
2027 moveCursorUpdate(false);
2028 owner_->showState();
2032 case LFUN_BEGINNINGBUF:
2034 LyXText * lt = bv_->getLyXText();
2036 if (!lt->selection.mark())
2039 BufferView::SELECT|BufferView::FITCUR);
2042 moveCursorUpdate(false);
2043 owner_->showState();
2049 LyXText * lt = bv_->getLyXText();
2051 if (!lt->selection.mark())
2054 BufferView::SELECT|BufferView::FITCUR);
2055 lt->cursorBottom(bv_);
2057 moveCursorUpdate(false);
2058 owner_->showState();
2062 /* cursor selection ---------------------------- */
2065 LyXText * lt = bv_->getLyXText();
2068 BufferView::SELECT|BufferView::FITCUR);
2069 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2070 lt->cursorLeft(bv_);
2072 lt->cursorRight(bv_);
2074 moveCursorUpdate(true);
2075 owner_->showState();
2081 LyXText * lt = bv_->getLyXText();
2084 BufferView::SELECT|BufferView::FITCUR);
2085 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2086 lt->cursorRight(bv_);
2088 lt->cursorLeft(bv_);
2090 moveCursorUpdate(true);
2091 owner_->showState();
2097 LyXText * lt = bv_->getLyXText();
2100 BufferView::SELECT|BufferView::FITCUR);
2103 moveCursorUpdate(true);
2104 owner_->showState();
2110 LyXText * lt = bv_->getLyXText();
2113 BufferView::SELECT|BufferView::FITCUR);
2114 lt->cursorDown(bv_);
2116 moveCursorUpdate(true);
2117 owner_->showState();
2121 case LFUN_UP_PARAGRAPHSEL:
2123 LyXText * lt = bv_->getLyXText();
2126 BufferView::SELECT|BufferView::FITCUR);
2127 lt->cursorUpParagraph(bv_);
2129 moveCursorUpdate(true);
2130 owner_->showState();
2134 case LFUN_DOWN_PARAGRAPHSEL:
2136 LyXText * lt = bv_->getLyXText();
2139 BufferView::SELECT|BufferView::FITCUR);
2140 lt->cursorDownParagraph(bv_);
2142 moveCursorUpdate(true);
2143 owner_->showState();
2149 LyXText * lt = bv_->getLyXText();
2151 update(lt, BufferView::SELECT|BufferView::FITCUR);
2154 moveCursorUpdate(true);
2155 owner_->showState();
2161 LyXText * lt = bv_->getLyXText();
2163 update(lt, BufferView::SELECT|BufferView::FITCUR);
2166 moveCursorUpdate(true);
2167 owner_->showState();
2173 LyXText * lt = bv_->getLyXText();
2175 update(lt, BufferView::SELECT|BufferView::FITCUR);
2176 lt->cursorHome(bv_);
2178 moveCursorUpdate(true);
2179 owner_->showState();
2185 LyXText * lt = bv_->getLyXText();
2187 update(lt, BufferView::SELECT|BufferView::FITCUR);
2190 moveCursorUpdate(true);
2191 owner_->showState();
2195 case LFUN_WORDRIGHTSEL:
2197 LyXText * lt = bv_->getLyXText();
2199 update(lt, BufferView::SELECT|BufferView::FITCUR);
2200 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2201 lt->cursorLeftOneWord(bv_);
2203 lt->cursorRightOneWord(bv_);
2205 moveCursorUpdate(true);
2206 owner_->showState();
2210 case LFUN_WORDLEFTSEL:
2212 LyXText * lt = bv_->getLyXText();
2214 update(lt, BufferView::SELECT|BufferView::FITCUR);
2215 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2216 lt->cursorRightOneWord(bv_);
2218 lt->cursorLeftOneWord(bv_);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2225 case LFUN_BEGINNINGBUFSEL:
2227 LyXText * lt = bv_->getLyXText();
2229 if (lt->inset_owner)
2231 update(lt, BufferView::SELECT|BufferView::FITCUR);
2234 moveCursorUpdate(true);
2235 owner_->showState();
2239 case LFUN_ENDBUFSEL:
2241 LyXText * lt = bv_->getLyXText();
2243 if (lt->inset_owner)
2246 BufferView::SELECT|BufferView::FITCUR);
2247 lt->cursorBottom(bv_);
2249 moveCursorUpdate(true);
2250 owner_->showState();
2254 // --- text changing commands ------------------------
2255 case LFUN_BREAKLINE:
2257 LyXText * lt = bv_->getLyXText();
2260 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2263 | BufferView::FITCUR
2264 | BufferView::CHANGE);
2265 moveCursorUpdate(false);
2269 case LFUN_PROTECTEDSPACE:
2271 LyXText * lt = bv_->getLyXText();
2273 LyXLayout const & style = textclasslist
2274 .Style(buffer_->params.textclass,
2275 lt->cursor.par()->getLayout());
2277 if (style.free_spacing) {
2278 lt->insertChar(bv_, ' ');
2281 | BufferView::FITCUR
2282 | BufferView::CHANGE);
2286 moveCursorUpdate(false);
2292 LyXText * lt = bv_->getLyXText();
2294 if (lt->selection.mark()) {
2298 | BufferView::FITCUR);
2299 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2302 lt->selection.mark(true);
2305 | BufferView::FITCUR);
2306 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2308 lt->selection.cursor = lt->cursor;
2314 LyXText * lt = bv_->getLyXText();
2316 if (!lt->selection.set()) {
2318 lt->selection.cursor = lt->cursor;
2321 | BufferView::FITCUR
2322 | BufferView::CHANGE);
2323 // It is possible to make it a lot faster still
2324 // just comment out the line below...
2329 moveCursorUpdate(false);
2330 owner_->showState();
2335 case LFUN_DELETE_SKIP:
2337 LyXText * lt = bv_->getLyXText();
2339 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2341 LyXCursor cursor = lt->cursor;
2343 if (!lt->selection.set()) {
2344 if (cursor.pos() == cursor.par()->size()) {
2345 lt->cursorRight(bv_);
2346 cursor = lt->cursor;
2347 if (cursor.pos() == 0
2348 && !(cursor.par()->params().spaceTop()
2349 == VSpace (VSpace::NONE))) {
2352 cursor.par()->params().lineTop(),
2353 cursor.par()->params().lineBottom(),
2354 cursor.par()->params().pagebreakTop(),
2355 cursor.par()->params().pagebreakBottom(),
2356 VSpace(VSpace::NONE),
2357 cursor.par()->params().spaceBottom(),
2358 cursor.par()->params().align(),
2359 cursor.par()->params().labelWidthString(), 0);
2360 lt->cursorLeft(bv_);
2363 | BufferView::FITCUR
2364 | BufferView::CHANGE);
2366 lt->cursorLeft(bv_);
2368 lt->selection.cursor = lt->cursor;
2371 | BufferView::FITCUR
2372 | BufferView::CHANGE);
2376 lt->selection.cursor = lt->cursor;
2379 | BufferView::FITCUR
2380 | BufferView::CHANGE);
2388 /* -------> Delete word forward. */
2389 case LFUN_DELETE_WORD_FORWARD:
2390 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2391 bv_->getLyXText()->deleteWordForward(bv_);
2392 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2393 moveCursorUpdate(false);
2394 owner_->showState();
2397 /* -------> Delete word backward. */
2398 case LFUN_DELETE_WORD_BACKWARD:
2400 LyXText * lt = bv_->getLyXText();
2402 update(lt, BufferView::SELECT|BufferView::FITCUR);
2403 lt->deleteWordBackward(bv_);
2406 | BufferView::FITCUR
2407 | BufferView::CHANGE);
2408 moveCursorUpdate(false);
2409 owner_->showState();
2413 /* -------> Kill to end of line. */
2414 case LFUN_DELETE_LINE_FORWARD:
2416 LyXText * lt = bv_->getLyXText();
2418 update(lt, BufferView::SELECT|BufferView::FITCUR);
2419 lt->deleteLineForward(bv_);
2422 | BufferView::FITCUR
2423 | BufferView::CHANGE);
2424 moveCursorUpdate(false);
2428 /* -------> Set mark off. */
2431 LyXText * lt = bv_->getLyXText();
2434 update(lt, BufferView::SELECT|BufferView::FITCUR);
2435 lt->selection.cursor = lt->cursor;
2436 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2440 /* -------> Set mark on. */
2443 LyXText * lt = bv_->getLyXText();
2446 lt->selection.mark(true);
2447 update(lt, BufferView::SELECT|BufferView::FITCUR);
2448 lt->selection.cursor = lt->cursor;
2449 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2453 case LFUN_BACKSPACE:
2455 LyXText * lt = bv_->getLyXText();
2457 if (!lt->selection.set()) {
2458 if (owner_->getIntl()->getTrans().backspace()) {
2460 lt->selection.cursor = lt->cursor;
2463 | BufferView::FITCUR
2464 | BufferView::CHANGE);
2465 // It is possible to make it a lot faster still
2466 // just comment out the line below...
2472 owner_->showState();
2477 case LFUN_BACKSPACE_SKIP:
2479 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2480 LyXText * lt = bv_->getLyXText();
2482 LyXCursor cursor = lt->cursor;
2484 if (!lt->selection.set()) {
2485 if (cursor.pos() == 0
2486 && !(cursor.par()->params().spaceTop()
2487 == VSpace (VSpace::NONE))) {
2490 cursor.par()->params().lineTop(),
2491 cursor.par()->params().lineBottom(),
2492 cursor.par()->params().pagebreakTop(),
2493 cursor.par()->params().pagebreakBottom(),
2494 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2495 cursor.par()->params().align(),
2496 cursor.par()->params().labelWidthString(), 0);
2499 | BufferView::FITCUR
2500 | BufferView::CHANGE);
2503 lt->selection.cursor = cursor;
2506 | BufferView::FITCUR
2507 | BufferView::CHANGE);
2514 case LFUN_BREAKPARAGRAPH:
2516 LyXText * lt = bv_->getLyXText();
2519 lt->breakParagraph(bv_, 0);
2522 | BufferView::FITCUR
2523 | BufferView::CHANGE);
2524 lt->selection.cursor = lt->cursor;
2526 owner_->showState();
2530 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2532 LyXText * lt = bv_->getLyXText();
2535 lt->breakParagraph(bv_, 1);
2538 | BufferView::FITCUR
2539 | BufferView::CHANGE);
2540 lt->selection.cursor = lt->cursor;
2542 owner_->showState();
2546 case LFUN_BREAKPARAGRAPH_SKIP:
2548 // When at the beginning of a paragraph, remove
2549 // indentation and add a "defskip" at the top.
2550 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2551 LyXText * lt = bv_->getLyXText();
2553 LyXCursor cursor = lt->cursor;
2556 if (cursor.pos() == 0) {
2557 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2560 cursor.par()->params().lineTop(),
2561 cursor.par()->params().lineBottom(),
2562 cursor.par()->params().pagebreakTop(),
2563 cursor.par()->params().pagebreakBottom(),
2564 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2565 cursor.par()->params().align(),
2566 cursor.par()->params().labelWidthString(), 1);
2567 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2571 lt->breakParagraph(bv_, 0);
2572 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2577 | BufferView::FITCUR
2578 | BufferView::CHANGE);
2579 lt->selection.cursor = cursor;
2581 owner_->showState();
2585 case LFUN_PARAGRAPH_SPACING:
2587 LyXText * lt = bv_->getLyXText();
2589 Paragraph * par = lt->cursor.par();
2590 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2591 float cur_value = 1.0;
2592 if (cur_spacing == Spacing::Other) {
2593 cur_value = par->params().spacing().getValue();
2596 istringstream istr(argument.c_str());
2600 Spacing::Space new_spacing = cur_spacing;
2601 float new_value = cur_value;
2603 lyxerr << "Missing argument to `paragraph-spacing'"
2605 } else if (tmp == "single") {
2606 new_spacing = Spacing::Single;
2607 } else if (tmp == "onehalf") {
2608 new_spacing = Spacing::Onehalf;
2609 } else if (tmp == "double") {
2610 new_spacing = Spacing::Double;
2611 } else if (tmp == "other") {
2612 new_spacing = Spacing::Other;
2615 lyxerr << "new_value = " << tmpval << endl;
2618 } else if (tmp == "default") {
2619 new_spacing = Spacing::Default;
2621 lyxerr << _("Unknown spacing argument: ")
2622 << argument << endl;
2624 if (cur_spacing != new_spacing || cur_value != new_value) {
2625 par->params().spacing(Spacing(new_spacing, new_value));
2626 lt->redoParagraph(bv_);
2629 | BufferView::FITCUR
2630 | BufferView::CHANGE);
2636 bv_->insertCorrectQuote();
2642 InsetCommandParams p;
2643 if (action == LFUN_HTMLURL)
2644 p.setCmdName("htmlurl");
2646 p.setCmdName("url");
2647 owner_->getDialogs()->createUrl( p.getAsString() );
2651 case LFUN_INSERT_URL:
2653 InsetCommandParams p;
2654 p.setFromString( argument );
2656 InsetUrl * inset = new InsetUrl( p );
2657 if (!insertInset(inset))
2660 updateInset( inset, true );
2664 case LFUN_INSET_TEXT:
2666 InsetText * new_inset = new InsetText;
2667 if (insertInset(new_inset))
2668 new_inset->Edit(bv_, 0, 0, 0);
2674 case LFUN_INSET_ERT:
2676 InsetERT * new_inset = new InsetERT;
2677 if (insertInset(new_inset))
2678 new_inset->Edit(bv_, 0, 0, 0);
2684 case LFUN_INSET_EXTERNAL:
2686 InsetExternal * new_inset = new InsetExternal;
2687 if (insertInset(new_inset))
2688 new_inset->Edit(bv_, 0, 0, 0);
2694 case LFUN_INSET_FOOTNOTE:
2696 InsetFoot * new_inset = new InsetFoot;
2697 if (insertInset(new_inset))
2698 new_inset->Edit(bv_, 0, 0, 0);
2704 case LFUN_INSET_MARGINAL:
2706 InsetMarginal * new_inset = new InsetMarginal;
2707 if (insertInset(new_inset))
2708 new_inset->Edit(bv_, 0, 0, 0);
2714 case LFUN_INSET_MINIPAGE:
2716 InsetMinipage * new_inset = new InsetMinipage;
2717 if (insertInset(new_inset))
2718 new_inset->Edit(bv_, 0, 0, 0);
2724 case LFUN_INSET_FLOAT:
2726 // check if the float type exist
2727 if (floatList.typeExist(argument)) {
2728 InsetFloat * new_inset = new InsetFloat(argument);
2729 if (insertInset(new_inset))
2730 new_inset->Edit(bv_, 0, 0, 0);
2734 lyxerr << "Non-existant float type: "
2735 << argument << endl;
2741 case LFUN_INSET_WIDE_FLOAT:
2743 // check if the float type exist
2744 if (floatList.typeExist(argument)) {
2745 InsetFloat * new_inset = new InsetFloat(argument);
2746 new_inset->wide(true);
2747 if (insertInset(new_inset))
2748 new_inset->Edit(bv_, 0, 0, 0);
2752 lyxerr << "Non-existant float type: "
2753 << argument << endl;
2759 case LFUN_INSET_LIST:
2761 InsetList * new_inset = new InsetList;
2762 if (insertInset(new_inset))
2763 new_inset->Edit(bv_, 0, 0, 0);
2769 case LFUN_INSET_THEOREM:
2771 InsetTheorem * new_inset = new InsetTheorem;
2772 if (insertInset(new_inset))
2773 new_inset->Edit(bv_, 0, 0, 0);
2779 case LFUN_INSET_CAPTION:
2781 // Do we have a locking inset...
2782 if (bv_->theLockingInset()) {
2783 lyxerr << "Locking inset code: "
2784 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2785 InsetCaption * new_inset = new InsetCaption;
2786 new_inset->setOwner(bv_->theLockingInset());
2787 new_inset->SetAutoBreakRows(true);
2788 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2789 new_inset->SetFrameColor(0, LColor::captionframe);
2790 if (insertInset(new_inset))
2791 new_inset->Edit(bv_, 0, 0, 0);
2798 case LFUN_INSET_TABULAR:
2802 if (!argument.empty())
2803 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2804 InsetTabular * new_inset =
2805 new InsetTabular(*buffer_, r, c);
2807 bv_->getLyXText()->real_current_font.isRightToLeft();
2808 if (!open_new_inset(new_inset, rtl))
2813 // --- lyxserver commands ----------------------------
2815 case LFUN_CHARATCURSOR:
2817 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2818 if (pos < bv_->getLyXText()->cursor.par()->size())
2819 owner_->getLyXFunc()->setMessage(
2820 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2822 owner_->getLyXFunc()->setMessage("EOF");
2827 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2829 + tostr(bv_->getLyXText()->cursor.y()));
2834 #warning Should check sscanf for errors (Lgb)
2837 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2838 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2842 case LFUN_GETLAYOUT:
2843 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2848 LyXFont & font = bv_->getLyXText()->current_font;
2849 if (font.shape() == LyXFont::ITALIC_SHAPE)
2850 owner_->getLyXFunc()->setMessage("E");
2851 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2852 owner_->getLyXFunc()->setMessage("N");
2854 owner_->getLyXFunc()->setMessage("0");
2861 LyXFont & font = bv_->getLyXText()->current_font;
2862 if (font.latex() == LyXFont::ON)
2863 owner_->getLyXFunc()->setMessage("L");
2865 owner_->getLyXFunc()->setMessage("0");
2869 // --- accented characters ---------------------------
2872 case LFUN_CIRCUMFLEX:
2882 case LFUN_SPECIAL_CARON:
2885 case LFUN_HUNG_UMLAUT:
2888 if (argument.empty()) {
2890 owner_->getLyXFunc()->handleKeyFunc(action);
2892 owner_->getLyXFunc()->handleKeyFunc(action);
2893 owner_->getIntl()->getTrans()
2894 .TranslateAndInsert(argument[0], bv_->getLyXText());
2895 update(bv_->getLyXText(),
2897 | BufferView::FITCUR
2898 | BufferView::CHANGE);
2902 // --- insert characters ----------------------------------------
2904 case LFUN_MATH_DELIM:
2905 case LFUN_INSERT_MATRIX:
2908 if (open_new_inset(new InsetFormula, false)) {
2909 bv_->theLockingInset()
2910 ->LocalDispatch(bv_, action, argument);
2916 case LFUN_INSERT_MATH:
2921 InsetFormula * f = new InsetFormula(LM_OT_EQUATION);
2923 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2927 case LFUN_MATH_DISPLAY:
2930 open_new_inset(new InsetFormula(LM_OT_EQUATION), false);
2934 case LFUN_MATH_MACRO:
2939 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2941 string const s1 = token(s, ' ', 1);
2942 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2943 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na), false);
2949 case LFUN_MATH_MODE: // Open or create a math inset
2952 open_new_inset(new InsetFormula, false);
2953 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2957 case LFUN_CITATION_INSERT:
2959 InsetCommandParams p;
2960 p.setFromString( argument );
2962 InsetCitation * inset = new InsetCitation( p );
2963 if (!insertInset(inset))
2966 updateInset( inset, true );
2970 case LFUN_INSERT_BIBTEX:
2972 // ale970405+lasgoutt970425
2973 // The argument can be up to two tokens separated
2974 // by a space. The first one is the bibstyle.
2975 string const db = token(argument, ' ', 0);
2976 string bibstyle = token(argument, ' ', 1);
2977 if (bibstyle.empty())
2980 InsetCommandParams p( "BibTeX", db, bibstyle );
2981 InsetBibtex * inset = new InsetBibtex(p);
2983 if (insertInset(inset)) {
2984 if (argument.empty())
2985 inset->Edit(bv_, 0, 0, 0);
2991 // BibTeX data bases
2992 case LFUN_BIBDB_ADD:
2994 InsetBibtex * inset =
2995 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2997 inset->addDatabase(argument);
3002 case LFUN_BIBDB_DEL:
3004 InsetBibtex * inset =
3005 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3007 inset->delDatabase(argument);
3012 case LFUN_BIBTEX_STYLE:
3014 InsetBibtex * inset =
3015 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3017 inset->setOptions(argument);
3022 case LFUN_INDEX_CREATE:
3024 InsetCommandParams p( "index" );
3026 if (argument.empty()) {
3027 // Get the word immediately preceding the cursor
3028 Paragraph::size_type curpos =
3029 bv_->getLyXText()->cursor.pos() - 1;
3033 curstring = bv_->getLyXText()
3034 ->cursor.par()->getWord(curpos);
3036 p.setContents( curstring );
3038 p.setContents( argument );
3041 owner_->getDialogs()->createIndex( p.getAsString() );
3045 case LFUN_INDEX_INSERT:
3047 InsetCommandParams p;
3048 p.setFromString(argument);
3049 InsetIndex * inset = new InsetIndex(p);
3051 if (!insertInset(inset))
3054 updateInset(inset, true);
3058 case LFUN_INDEX_INSERT_LAST:
3060 // Get word immediately preceding the cursor
3061 Paragraph::size_type curpos =
3062 bv_->getLyXText()->cursor.pos() - 1;
3063 // Can't do that at the beginning of a paragraph
3064 if (curpos < 0) break;
3066 string const curstring(bv_->getLyXText()
3067 ->cursor.par()->getWord(curpos));
3069 InsetCommandParams p("index", curstring);
3070 InsetIndex * inset = new InsetIndex(p);
3072 if (!insertInset(inset))
3075 updateInset(inset, true);
3079 case LFUN_INDEX_PRINT:
3081 InsetCommandParams p("printindex");
3082 Inset * inset = new InsetPrintIndex(p);
3083 if (!insertInset(inset, "Standard"))
3088 case LFUN_PARENTINSERT:
3090 lyxerr << "arg " << argument << endl;
3091 InsetCommandParams p( "lyxparent", argument );
3092 Inset * inset = new InsetParent(p, *buffer_);
3093 if (!insertInset(inset, "Standard"))
3099 case LFUN_CHILD_INSERT:
3101 InsetInclude::Params p;
3102 p.cparams.setFromString(argument);
3103 p.masterFilename_ = buffer_->fileName();
3105 InsetInclude * inset = new InsetInclude(p);
3106 if (!insertInset(inset))
3109 updateInset(inset, true);
3110 bv_->owner()->getDialogs()->showInclude(inset);
3115 case LFUN_FLOAT_LIST:
3117 // We should check the argument for validity. (Lgb)
3118 Inset * inset = new InsetFloatList(argument);
3119 if (!insertInset(inset, "Standard"))
3124 case LFUN_INSERT_NOTE:
3128 case LFUN_SELFINSERT:
3130 if (argument.empty()) break;
3132 /* Automatically delete the currently selected
3133 * text and replace it with what is being
3134 * typed in now. Depends on lyxrc settings
3135 * "auto_region_delete", which defaults to
3138 LyXText * lt = bv_->getLyXText();
3140 if (lyxrc.auto_region_delete) {
3141 if (lt->selection.set()) {
3142 lt->cutSelection(bv_, false);
3145 | BufferView::FITCUR
3146 | BufferView::CHANGE);
3150 bv_->beforeChange(lt);
3151 LyXFont const old_font(lt->real_current_font);
3153 string::const_iterator cit = argument.begin();
3154 string::const_iterator end = argument.end();
3155 for (; cit != end; ++cit) {
3156 if (greek_kb_flag) {
3157 if (!math_insert_greek(bv_, *cit))
3158 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3160 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3165 | BufferView::FITCUR
3166 | BufferView::CHANGE);
3168 lt->selection.cursor = lt->cursor;
3169 moveCursorUpdate(false);
3171 // real_current_font.number can change so we need to
3172 // update the minibuffer
3173 if (old_font != lt->real_current_font)
3174 owner_->showState();
3179 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3181 time_t now_time_t = time(NULL);
3182 struct tm * now_tm = localtime(&now_time_t);
3183 setlocale(LC_TIME, "");
3185 if (!argument.empty())
3188 arg = lyxrc.date_insert_format;
3190 int const datetmp_len =
3191 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3193 LyXText * lt = bv_->getLyXText();
3195 for (int i = 0; i < datetmp_len; i++) {
3196 lt->insertChar(bv_, datetmp[i]);
3199 | BufferView::FITCUR
3200 | BufferView::CHANGE);
3203 lt->selection.cursor = lt->cursor;
3204 moveCursorUpdate(false);
3208 case LFUN_UNKNOWN_ACTION:
3209 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3220 void BufferView::Pimpl::newline()
3223 LyXText * lt = bv_->getLyXText();
3227 | BufferView::FITCUR);
3228 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3231 | BufferView::FITCUR
3232 | BufferView::CHANGE);
3237 void BufferView::Pimpl::hfill()
3240 LyXText * lt = bv_->getLyXText();
3244 | BufferView::FITCUR);
3245 lt->insertChar(bv_, Paragraph::META_HFILL);
3248 | BufferView::FITCUR
3249 | BufferView::CHANGE);
3254 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3258 update(lt, BufferView::SELECT|BufferView::FITCUR);
3259 InsetSpecialChar * new_inset =
3260 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3261 if (!insertInset(new_inset))
3264 updateInset(new_inset, true);
3269 void BufferView::Pimpl::menuSeparator()
3272 LyXText * lt = bv_->getLyXText();
3275 update(lt, BufferView::SELECT|BufferView::FITCUR);
3276 InsetSpecialChar * new_inset =
3277 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3278 insertInset(new_inset);
3283 void BufferView::Pimpl::endOfSentenceDot()
3287 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3288 InsetSpecialChar * new_inset =
3289 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3290 insertInset(new_inset);
3295 void BufferView::Pimpl::ldots()
3299 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3300 InsetSpecialChar * new_inset =
3301 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3302 insertInset(new_inset);
3307 void BufferView::Pimpl::hyphenationPoint()
3311 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3312 InsetSpecialChar * new_inset =
3313 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3314 insertInset(new_inset);
3319 void BufferView::Pimpl::insertNote()
3321 InsetInfo * new_inset = new InsetInfo();
3322 insertInset(new_inset);
3323 new_inset->Edit(bv_, 0, 0, 0);
3327 // Open and lock an updatable inset
3328 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3330 LyXText * lt = bv_->getLyXText();
3334 if (!insertInset(new_inset)) {
3339 LyXFont & font = lt->real_current_font;
3340 new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
3342 new_inset->Edit(bv_, 0, 0, 0);
3347 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3349 // if we are in a locking inset we should try to insert the
3350 // inset there otherwise this is a illegal function now
3351 if (bv_->theLockingInset()) {
3352 if (bv_->theLockingInset()->InsertInsetAllowed(inset))
3353 return bv_->theLockingInset()->InsertInset(bv_, inset);
3357 // not quite sure if we want this...
3358 bv_->text->setCursorParUndo(buffer_);
3359 bv_->text->freezeUndo();
3361 beforeChange(bv_->text);
3362 if (!lout.empty()) {
3363 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3364 bv_->text->breakParagraph(bv_);
3365 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3367 if (bv_->text->cursor.par()->size()) {
3368 bv_->text->cursorLeft(bv_);
3370 bv_->text->breakParagraph(bv_);
3371 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3374 pair<bool, LyXTextClass::size_type> lres =
3375 textclasslist.NumberOfLayout(buffer_->params
3377 LyXTextClass::size_type lay;
3378 if (lres.first != false) {
3382 // layout not fount using default "Standard" (0)
3386 bv_->text->setLayout(bv_, lay);
3388 bv_->text->setParagraph(bv_, 0, 0,
3390 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3394 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3396 bv_->text->current_font.setLatex(LyXFont::OFF);
3399 bv_->text->insertInset(bv_, inset);
3400 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3402 bv_->text->unFreezeUndo();
3407 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3412 // first check for locking insets
3413 if (bv_->theLockingInset()) {
3414 if (bv_->theLockingInset() == inset) {
3415 if (bv_->text->updateInset(bv_, inset)) {
3418 buffer_->markDirty();
3423 } else if (bv_->theLockingInset()->UpdateInsetInInset(bv_, inset)) {
3424 if (bv_->text->updateInset(bv_,
3425 bv_->theLockingInset())) {
3428 buffer_->markDirty();
3436 // then check the current buffer
3439 update(bv_->text, BufferView::UPDATE);
3440 if (bv_->text->updateInset(bv_, inset)) {
3444 | BufferView::FITCUR
3445 | BufferView::CHANGE);
3447 update(bv_->text, SELECT);
3455 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3458 if (!available()) return;
3461 beforeChange(bv_->text);
3462 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3466 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3467 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3468 if (find(codes.begin(), codes.end(), inset->LyxCode())
3471 static_cast<InsetCommand const *>(inset)->getContents();
3474 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3475 if (bv_->text->cursor.pos()
3476 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3477 LyXCursor tmp = bv_->text->cursor;
3478 bv_->text->cursor.par(bv_->text->firstParagraph());
3479 bv_->text->cursor.pos(0);
3480 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3481 bv_->text->cursor = tmp;
3482 bv_->owner()->message(_("No more insets"));
3485 bv_->owner()->message(_("No more insets"));
3488 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3489 bv_->text->selection.cursor = bv_->text->cursor;
3493 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3495 gotoInset(vector<Inset::Code>(1, code), same_content);