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"
62 extern LyXTextClass::size_type current_layout;
63 extern int greek_kb_flag;
74 /* the selection possible is needed, that only motion events are
75 * used, where the bottom press event was on the drawing area too */
76 bool selection_possible = false;
78 extern BufferList bufferlist;
79 extern char ascii_type;
81 extern bool math_insert_greek(BufferView *, char);
82 extern void sigchldhandler(pid_t pid, int * status);
83 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
87 const unsigned int saved_positions_num = 20;
92 XSync(fl_get_display(), 0);
96 void SetXtermCursor(Window win)
99 static bool cursor_undefined = true;
100 if (cursor_undefined){
101 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
102 XFlush(fl_get_display());
103 cursor_undefined = false;
105 XDefineCursor(fl_get_display(), win, cursor);
106 XFlush(fl_get_display());
112 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
113 int xpos, int ypos, int width, int height)
114 : bv_(b), owner_(o), buffer_(0),
115 current_scrollbar_value(0), cursor_timeout(400),
116 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
120 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
121 workarea_.workAreaExpose
122 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
123 workarea_.workAreaEnter
124 .connect(slot(this, &BufferView::Pimpl::enterView));
125 workarea_.workAreaLeave
126 .connect(slot(this, &BufferView::Pimpl::leaveView));
127 workarea_.workAreaButtonPress
128 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
129 workarea_.workAreaButtonRelease
131 &BufferView::Pimpl::workAreaButtonRelease));
132 workarea_.workAreaMotionNotify
133 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
134 workarea_.workAreaDoubleClick
135 .connect(slot(this, &BufferView::Pimpl::doubleClick));
136 workarea_.workAreaTripleClick
137 .connect(slot(this, &BufferView::Pimpl::tripleClick));
138 workarea_.workAreaKeyPress
139 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
141 cursor_timeout.timeout.connect(slot(this,
142 &BufferView::Pimpl::cursorToggle));
143 cursor_timeout.start();
144 workarea_.setFocus();
145 saved_positions.resize(saved_positions_num);
149 Painter & BufferView::Pimpl::painter()
151 return workarea_.getPainter();
155 void BufferView::Pimpl::buffer(Buffer * b)
157 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
161 buffer_->delUser(bv_);
163 // Put the old text into the TextCache, but
164 // only if the buffer is still loaded.
165 // Also set the owner of the test to 0
166 // bv_->text->owner(0);
167 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
168 if (lyxerr.debugging())
169 textcache.show(lyxerr, "BufferView::buffer");
174 // Set current buffer
177 if (bufferlist.getState() == BufferList::CLOSING) return;
180 // screen is always deleted when the buffer is changed.
183 // If we are closing the buffer, use the first buffer as current
185 buffer_ = bufferlist.first();
189 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
190 buffer_->addUser(bv_);
191 // If we don't have a text object for this, we make one
192 if (bv_->text == 0) {
193 resizeCurrentBuffer();
198 bv_->text->first = screen_->TopCursorVisible(bv_->text);
199 owner_->updateMenubar();
200 owner_->updateToolbar();
201 // Similarly, buffer-dependent dialogs should be updated or
202 // hidden. This should go here because some dialogs (eg ToC)
203 // require bv_->text.
204 owner_->getDialogs()->updateBufferDependent(true);
208 lyxerr[Debug::INFO] << " No Buffer!" << endl;
209 owner_->updateMenubar();
210 owner_->updateToolbar();
211 owner_->getDialogs()->hideBufferDependent();
215 // Also remove all remaining text's from the testcache.
216 // (there should not be any!) (if there is any it is a
218 if (lyxerr.debugging())
219 textcache.show(lyxerr, "buffer delete all");
222 // should update layoutchoice even if we don't have a buffer.
223 owner_->updateLayoutChoice();
225 owner_->updateWindowTitle();
229 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
231 workarea_.resize(xpos, ypos, width, height);
232 update(bv_->text, SELECT);
237 void BufferView::Pimpl::resize()
240 resizeCurrentBuffer();
244 void BufferView::Pimpl::redraw()
246 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
251 bool BufferView::Pimpl::fitCursor(LyXText * text)
253 lyx::Assert(screen_.get());
255 bool const ret = screen_->FitCursor(text, bv_);
262 void BufferView::Pimpl::redoCurrentBuffer()
264 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
265 if (buffer_ && bv_->text) {
267 owner_->updateLayoutChoice();
272 int BufferView::Pimpl::resizeCurrentBuffer()
274 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
276 LyXParagraph * par = 0;
277 LyXParagraph * selstartpar = 0;
278 LyXParagraph * selendpar = 0;
279 UpdatableInset * the_locking_inset = 0;
281 LyXParagraph::size_type pos = 0;
282 LyXParagraph::size_type selstartpos = 0;
283 LyXParagraph::size_type selendpos = 0;
284 bool selection = false;
285 bool mark_set = false;
289 owner_->message(_("Formatting document..."));
292 par = bv_->text->cursor.par();
293 pos = bv_->text->cursor.pos();
294 selstartpar = bv_->text->selection.start.par();
295 selstartpos = bv_->text->selection.start.pos();
296 selendpar = bv_->text->selection.end.par();
297 selendpos = bv_->text->selection.end.pos();
298 selection = bv_->text->selection.set();
299 mark_set = bv_->text->selection.mark();
300 the_locking_inset = bv_->text->the_locking_inset;
302 bv_->text = new LyXText(bv_);
304 // See if we have a text in TextCache that fits
305 // the new buffer_ with the correct width.
306 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
308 if (lyxerr.debugging()) {
309 lyxerr << "Found a LyXText that fits:\n";
310 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
312 // Set the owner of the newly found text
313 // bv_->text->owner(bv_);
314 if (lyxerr.debugging())
315 textcache.show(lyxerr, "resizeCurrentBuffer");
317 bv_->text = new LyXText(bv_);
323 bv_->text->selection.set(true);
324 /* at this point just to avoid the Delete-Empty-Paragraph
325 * Mechanism when setting the cursor */
326 bv_->text->selection.mark(mark_set);
328 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
329 bv_->text->selection.cursor = bv_->text->cursor;
330 bv_->text->SetCursor(bv_, selendpar, selendpos);
331 bv_->text->SetSelection(bv_);
332 bv_->text->SetCursor(bv_, par, pos);
334 bv_->text->SetCursor(bv_, par, pos);
335 bv_->text->selection.cursor = bv_->text->cursor;
336 bv_->text->selection.set(false);
338 // remake the inset locking
339 bv_->text->the_locking_inset = the_locking_inset;
341 bv_->text->first = screen_->TopCursorVisible(bv_->text);
342 buffer_->resizeInsets(bv_);
343 // this will scroll the screen such that the cursor becomes visible
350 /// get rid of the splash screen if it's not gone already
351 owner_->getDialogs()->destroySplash();
357 void BufferView::Pimpl::updateScreen()
359 // Regenerate the screen.
360 screen_.reset(new LyXScreen(workarea_));
364 void BufferView::Pimpl::updateScrollbar()
366 /* If the text is smaller than the working area, the scrollbar
367 * maximum must be the working area height. No scrolling will
371 workarea_.setScrollbar(0, 1.0);
375 static unsigned long text_height;
376 static unsigned long work_height;
378 unsigned long const tmp_text_height = bv_->text->height;
379 long const tmp_scrollbar_value = bv_->text->first;
381 // check if anything has changed.
382 if (text_height == tmp_text_height
383 && work_height == workarea_.height()
384 && current_scrollbar_value == tmp_scrollbar_value)
388 text_height = tmp_text_height;
389 work_height = workarea_.height();
390 current_scrollbar_value = tmp_scrollbar_value;
392 long const height_diff = text_height - work_height;
394 if (height_diff <= 0) {
395 workarea_.setScrollbar(0, 1.0);
400 workarea_.setScrollbarBounds(0, height_diff);
401 double const lineh = bv_->text->DefaultHeight();
402 workarea_.setScrollbarIncrements(lineh);
403 double const slider_size = 1.0 / double(height_diff) ;
404 workarea_.setScrollbar(current_scrollbar_value, slider_size);
408 // Callback for scrollbar slider
409 void BufferView::Pimpl::scrollCB(double value)
411 if (!buffer_) return;
413 current_scrollbar_value = long(value);
414 if (current_scrollbar_value < 0)
415 current_scrollbar_value = 0;
420 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
422 if (!lyxrc.cursor_follows_scrollbar) {
427 LyXText * vbt = bv_->text;
429 int const height = vbt->DefaultHeight();
430 int const first = static_cast<int>((bv_->text->first + height));
431 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
433 if (vbt->cursor.y() < first)
434 vbt->SetCursorFromCoordinates(bv_, 0, first);
435 else if (vbt->cursor.y() > last)
436 vbt->SetCursorFromCoordinates(bv_, 0, last);
442 int BufferView::Pimpl::scrollUp(long time)
444 if (!buffer_) return 0;
445 if (!screen_.get()) return 0;
447 double value = workarea_.getScrollbarValue();
449 if (value == 0) return 0;
451 float add_value = (bv_->text->DefaultHeight()
452 + float(time) * float(time) * 0.125);
454 if (add_value > workarea_.height())
455 add_value = float(workarea_.height() -
456 bv_->text->DefaultHeight());
463 workarea_.setScrollbarValue(value);
470 int BufferView::Pimpl::scrollDown(long time)
472 if (!buffer_) return 0;
473 if (!screen_.get()) return 0;
475 double value = workarea_.getScrollbarValue();
476 pair<float, float> p = workarea_.getScrollbarBounds();
477 double const max = p.second;
479 if (value == max) return 0;
481 float add_value = (bv_->text->DefaultHeight()
482 + float(time) * float(time) * 0.125);
484 if (add_value > workarea_.height())
485 add_value = float(workarea_.height() -
486 bv_->text->DefaultHeight());
493 workarea_.setScrollbarValue(value);
500 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
502 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
506 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
508 // Only use motion with button 1
509 if (!(state & Button1MotionMask))
512 if (!buffer_ || !screen_.get()) return;
514 // Check for inset locking
515 if (bv_->theLockingInset()) {
516 LyXCursor cursor = bv_->text->cursor;
517 LyXFont font = bv_->text->GetFont(buffer_,
518 cursor.par(), cursor.pos());
519 int width = bv_->theLockingInset()->width(bv_, font);
520 int inset_x = font.isVisibleRightToLeft()
521 ? cursor.x() - width : cursor.x();
522 int start_x = inset_x + bv_->theLockingInset()->scroll();
523 bv_->theLockingInset()->
524 InsetMotionNotify(bv_,
526 y - cursor.y() + bv_->text->first,
531 /* The test for not selection possible is needed, that only motion
532 events are used, where the bottom press event was on
533 the drawing area too */
534 if (!selection_possible)
537 screen_->HideCursor();
539 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
541 if (!bv_->text->selection.set())
542 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
544 bv_->text->SetSelection(bv_);
545 screen_->ToggleToggle(bv_->text, bv_);
546 fitCursor(bv_->text);
547 screen_->ShowCursor(bv_->text, bv_);
551 // Single-click on work area
552 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
555 if (!buffer_ || !screen_.get()) return;
557 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
559 // ok ok, this is a hack.
560 if (button == 4 || button == 5) {
563 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
566 scrollDown(lyxrc.wheel_jump);
571 if (bv_->theLockingInset()) {
572 // We are in inset locking mode
574 /* Check whether the inset was hit. If not reset mode,
575 otherwise give the event to the inset */
576 if (inset_hit == bv_->theLockingInset()) {
577 bv_->theLockingInset()->
578 InsetButtonPress(bv_,
583 bv_->unlockInset(bv_->theLockingInset());
588 selection_possible = true;
589 screen_->HideCursor();
591 int const screen_first = bv_->text->first;
593 // Middle button press pastes if we have a selection
594 bool paste_internally = false;
596 && bv_->text->selection.set()) {
597 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
598 paste_internally = true;
601 // Clear the selection
602 screen_->ToggleSelection(bv_->text, bv_);
603 bv_->text->ClearSelection(bv_);
604 bv_->text->FullRebreak(bv_);
605 screen_->Update(bv_->text, bv_);
608 // Single left click in math inset?
609 if ((inset_hit != 0) &&
610 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
611 // Highly editable inset, like math
612 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
613 selection_possible = false;
614 owner_->updateLayoutChoice();
615 owner_->message(inset->EditMessage());
616 inset->InsetButtonPress(bv_, xpos, ypos, button);
617 inset->Edit(bv_, xpos, ypos, button);
621 // Right click on a footnote flag opens float menu
623 selection_possible = false;
627 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
628 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
629 bv_->text->FinishUndo();
630 bv_->text->selection.cursor = bv_->text->cursor;
631 bv_->text->cursor.x_fix(bv_->text->cursor.x());
633 owner_->updateLayoutChoice();
634 if (fitCursor(bv_->text)) {
635 selection_possible = false;
638 // Insert primary selection with middle mouse
639 // if there is a local selection in the current buffer,
642 if (paste_internally)
643 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
645 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
647 selection_possible = false;
653 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
659 LyXText * text = bv_->getLyXText();
661 if (text->bv_owner && bv_->theLockingInset())
664 if (screen_.get() && button == 1) {
665 if (text->bv_owner) {
666 screen_->HideCursor();
667 screen_->ToggleSelection(text, bv_);
668 text->SelectWord(bv_);
669 screen_->ToggleSelection(text, bv_, false);
671 text->SelectWord(bv_);
673 /* This will fit the cursor on the screen
675 update(text, BufferView::SELECT|BufferView::FITCUR);
680 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
686 LyXText * text = bv_->getLyXText();
688 if (text->bv_owner && bv_->theLockingInset())
691 if (screen_.get() && (button == 1)) {
692 screen_->HideCursor();
693 screen_->ToggleSelection(text, bv_);
694 text->CursorHome(bv_);
695 text->selection.cursor = text->cursor;
696 text->CursorEnd(bv_);
697 text->SetSelection(bv_);
698 screen_->ToggleSelection(text, bv_, false);
699 /* This will fit the cursor on the screen
701 update(text, BufferView::SELECT|BufferView::FITCUR);
706 void BufferView::Pimpl::enterView()
708 if (active() && available()) {
709 SetXtermCursor(workarea_.getWin());
710 using_xterm_cursor = true;
715 void BufferView::Pimpl::leaveView()
717 if (using_xterm_cursor) {
718 XUndefineCursor(fl_get_display(), workarea_.getWin());
719 using_xterm_cursor = false;
724 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
727 if (!buffer_ || !screen_.get()) return;
729 // If we hit an inset, we have the inset coordinates in these
730 // and inset_hit points to the inset. If we do not hit an
731 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
732 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
734 if (bv_->theLockingInset()) {
735 // We are in inset locking mode.
737 /* LyX does a kind of work-area grabbing for insets.
738 Only a ButtonPress Event outside the inset will
739 force a InsetUnlock. */
740 bv_->theLockingInset()->
741 InsetButtonRelease(bv_, x, y, button);
745 selection_possible = false;
753 // Did we hit an editable inset?
755 // Inset like error, notes and figures
756 selection_possible = false;
758 // CHECK fix this proper in 0.13
760 // Following a ref shouldn't issue
761 // a push on the undo-stack
762 // anylonger, now that we have
763 // keybindings for following
764 // references and returning from
765 // references. IMHO though, it
766 // should be the inset's own business
767 // to push or not push on the undo
768 // stack. They don't *have* to
769 // alter the document...
771 // ...or maybe the SetCursorParUndo()
772 // below isn't necessary at all anylonger?
773 if (inset_hit->LyxCode() == Inset::REF_CODE) {
774 bv_->text->SetCursorParUndo(buffer_);
777 owner_->message(inset_hit->EditMessage());
779 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
780 // Highly editable inset, like math
781 UpdatableInset *inset = (UpdatableInset *)inset_hit;
782 inset->InsetButtonRelease(bv_, x, y, button);
784 inset_hit->InsetButtonRelease(bv_, x, y, button);
785 inset_hit->Edit(bv_, x, y, button);
790 // check whether we want to open a float
794 if (bv_->text->cursor.pos() <
795 bv_->text->cursor.par()->size()) {
796 c = bv_->text->cursor.par()->
797 GetChar(bv_->text->cursor.pos());
799 if (bv_->text->cursor.pos() - 1 >= 0) {
800 c = bv_->text->cursor.par()->
801 GetChar(bv_->text->cursor.pos() - 1);
804 selection_possible = false;
809 // Maybe we want to edit a bibitem ale970302
810 if (bv_->text->cursor.par()->bibkey && x < 20 +
811 bibitemMaxWidth(bv_, textclasslist.
813 params.textclass).defaultfont())) {
814 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
822 * Returns an inset if inset was hit. 0 otherwise.
823 * If hit, the coordinates are changed relative to the inset.
824 * Otherwise coordinates are not changed, and false is returned.
826 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
827 unsigned int /* button */)
832 int y_tmp = y + text->first;
835 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
836 text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
839 if (cursor.pos() < cursor.par()->size()
840 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
841 && cursor.par()->GetInset(cursor.pos())
842 && cursor.par()->GetInset(cursor.pos())->Editable()) {
844 // Check whether the inset really was hit
845 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
846 LyXFont font = text->GetFont(buffer_,
847 cursor.par(), cursor.pos());
848 int const width = tmpinset->width(bv_, font);
849 int const inset_x = font.isVisibleRightToLeft()
850 ? cursor.x() - width : cursor.x();
851 int const start_x = inset_x + tmpinset->scroll();
852 int const end_x = inset_x + width;
854 if (x > start_x && x < end_x
855 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
856 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
857 text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
859 // The origin of an inset is on the baseline
860 y = y_tmp - (text->cursor.y());
865 if ((cursor.pos() - 1 >= 0) &&
866 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
867 (cursor.par()->GetInset(cursor.pos() - 1)) &&
868 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
869 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
870 LyXFont font = text->GetFont(buffer_, cursor.par(),
872 int const width = tmpinset->width(bv_, font);
873 int const inset_x = font.isVisibleRightToLeft()
874 ? cursor.x() : cursor.x() - width;
875 int const start_x = inset_x + tmpinset->scroll();
876 int const end_x = inset_x + width;
878 if (x > start_x && x < end_x
879 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
880 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
882 if (move_cursor && (tmpinset != bv_->theLockingInset()))
884 text->SetCursor(bv_, cursor.par(),
885 cursor.pos() - 1, true);
887 // The origin of an inset is on the baseline
888 y = y_tmp - (text->cursor.y());
896 void BufferView::Pimpl::workAreaExpose()
898 static int work_area_width;
899 static unsigned int work_area_height;
901 bool const widthChange = workarea_.workWidth() != work_area_width;
902 bool const heightChange = workarea_.height() != work_area_height;
904 // update from work area
905 work_area_width = workarea_.workWidth();
906 work_area_height = workarea_.height();
909 // All buffers need a resize
912 // Remove all texts from the textcache
913 // This is not _really_ what we want to do. What
914 // we really want to do is to delete in textcache
915 // that does not have a BufferView with matching
916 // width, but as long as we have only one BufferView
917 // deleting all gives the same result.
918 if (lyxerr.debugging())
919 textcache.show(lyxerr, "Expose delete all");
921 } else if (heightChange) {
922 // Rebuild image of current screen
924 // fitCursor() ensures we don't jump back
925 // to the start of the document on vertical
927 fitCursor(bv_->text);
929 // The main window size has changed, repaint most stuff
931 } else if (screen_.get())
932 screen_->Redraw(bv_->text, bv_);
934 // Grey box when we don't have a buffer
938 // always make sure that the scrollbar is sane.
940 owner_->updateLayoutChoice();
945 void BufferView::Pimpl::update()
948 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
950 screen_->Update(bv_->text, bv_);
954 // Values used when calling update:
956 // -2 - update, move sel_cursor if selection, fitcursor
957 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
958 // 0 - update, move sel_cursor if selection, fitcursor
959 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
960 // 3 - update, move sel_cursor if selection
963 // a simple redraw of the parts that need refresh
965 // move sel_cursor if selection -
966 // the text's sel_cursor is moved if there is selection is progress
969 // fitCursor() is called and the scrollbar updated
972 // the buffer is marked dirty.
981 // UPDATE_ONLY = UPDATE;
982 // UPDATE_SELECT = UPDATE | SELECT;
983 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
984 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
986 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
987 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
988 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
989 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
990 // update(3) -> update(1) -> update(1) -> update(SELECT)
992 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
994 owner_->updateLayoutChoice();
996 if (!text->selection.set() && (f & SELECT)) {
997 text->selection.cursor = text->cursor;
1000 text->FullRebreak(bv_);
1002 if (text->inset_owner) {
1003 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1004 updateInset(text->inset_owner, true);
1013 buffer_->markDirty();
1018 // Callback for cursor timer
1019 void BufferView::Pimpl::cursorToggle()
1021 // Quite a nice place for asyncron Inset updating, isn't it?
1022 // Actually no! This is run even if no buffer exist... so (Lgb)
1024 cursor_timeout.restart();
1029 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1030 if (pid == -1) // error find out what is wrong
1031 ; // ignore it for now.
1033 sigchldhandler(pid, &status);
1035 updatelist.update(bv_);
1037 if (!screen_.get()) {
1038 cursor_timeout.restart();
1042 if (!bv_->theLockingInset()) {
1043 screen_->CursorToggle(bv_->text, bv_);
1045 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1048 cursor_timeout.restart();
1052 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1054 if (!text->cursor.row()->previous())
1057 int y = text->first;
1058 if (text->inset_owner)
1059 y += bv_->text->first;
1060 Row * cursorrow = text->cursor.row();
1061 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1062 bv_->text->FinishUndo();
1063 // This is to allow jumping over large insets
1064 if ((cursorrow == text->cursor.row()))
1065 text->CursorUp(bv_);
1067 if (text->inset_owner ||
1068 text->cursor.row()->height() < workarea_.height())
1069 screen_->Draw(bv_->text, bv_,
1071 - text->cursor.row()->baseline()
1072 + text->cursor.row()->height()
1073 - workarea_.height() + 1 );
1078 void BufferView::Pimpl::cursorNext(LyXText * text)
1080 if (!text->cursor.row()->next())
1083 int y = text->first + workarea_.height();
1084 // if (text->inset_owner)
1085 // y += bv_->text->first;
1086 text->GetRowNearY(y);
1088 Row * cursorrow = text->cursor.row();
1089 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1090 bv_->text->FinishUndo();
1091 // This is to allow jumping over large insets
1092 if ((cursorrow == bv_->text->cursor.row()))
1093 text->CursorDown(bv_);
1095 if (text->inset_owner ||
1096 text->cursor.row()->height() < workarea_.height())
1097 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1098 text->cursor.row()->baseline());
1103 bool BufferView::Pimpl::available() const
1105 if (buffer_ && bv_->text) return true;
1110 void BufferView::Pimpl::beforeChange(LyXText * text)
1113 text->ClearSelection(bv_);
1117 void BufferView::Pimpl::savePosition(unsigned int i)
1119 if (i >= saved_positions_num)
1121 saved_positions[i] = Position(buffer_->fileName(),
1122 bv_->text->cursor.par()->id(),
1123 bv_->text->cursor.pos());
1125 string const str = _("Saved bookmark") + ' ' + tostr(i);
1126 owner_->message(str);
1131 void BufferView::Pimpl::restorePosition(unsigned int i)
1133 if (i >= saved_positions_num)
1136 string const fname = saved_positions[i].filename;
1138 beforeChange(bv_->text);
1140 if (fname != buffer_->fileName()) {
1141 Buffer * b = bufferlist.exists(fname) ?
1142 bufferlist.getBuffer(fname) :
1143 bufferlist.loadLyXFile(fname); // don't ask, just load it
1144 if (b != 0 ) buffer(b);
1147 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1151 bv_->text->SetCursor(bv_, par,
1152 min(par->size(), saved_positions[i].par_pos));
1154 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1156 string const str = _("Moved to bookmark") + ' ' + tostr(i);
1157 owner_->message(str);
1162 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1164 if (i >= saved_positions_num)
1167 return !saved_positions[i].filename.empty();
1171 void BufferView::Pimpl::setState()
1173 if (!lyxrc.rtl_support)
1176 LyXText * text = bv_->getLyXText();
1177 if (text->real_current_font.isRightToLeft() &&
1178 text->real_current_font.latex() != LyXFont::ON) {
1179 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1180 owner_->getIntl()->KeyMapSec();
1182 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1183 owner_->getIntl()->KeyMapPrim();
1188 void BufferView::Pimpl::insetSleep()
1190 if (bv_->theLockingInset() && !inset_slept) {
1191 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1192 bv_->theLockingInset()->InsetUnlock(bv_);
1198 void BufferView::Pimpl::insetWakeup()
1200 if (bv_->theLockingInset() && inset_slept) {
1201 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1202 inset_slept = false;
1207 void BufferView::Pimpl::insetUnlock()
1209 if (bv_->theLockingInset()) {
1211 bv_->theLockingInset()->InsetUnlock(bv_);
1212 bv_->theLockingInset(0);
1213 bv_->text->FinishUndo();
1214 inset_slept = false;
1219 bool BufferView::Pimpl::focus() const
1221 return workarea_.hasFocus();
1225 void BufferView::Pimpl::focus(bool f)
1227 if (f) workarea_.setFocus();
1231 bool BufferView::Pimpl::active() const
1233 return workarea_.active();
1237 bool BufferView::Pimpl::belowMouse() const
1239 return workarea_.belowMouse();
1243 void BufferView::Pimpl::showCursor()
1246 screen_->ShowCursor(bv_->text, bv_);
1250 void BufferView::Pimpl::hideCursor()
1253 screen_->HideCursor();
1257 void BufferView::Pimpl::toggleSelection(bool b)
1260 screen_->ToggleSelection(bv_->text, bv_, b);
1264 void BufferView::Pimpl::toggleToggle()
1267 screen_->ToggleToggle(bv_->text, bv_);
1271 void BufferView::Pimpl::center()
1273 beforeChange(bv_->text);
1274 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1275 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1277 screen_->Draw(bv_->text, bv_, 0);
1279 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1284 void BufferView::Pimpl::pasteClipboard(bool asPara)
1286 if (!buffer_) return;
1288 screen_->HideCursor();
1289 beforeChange(bv_->text);
1291 string const clip(workarea_.getClipboard());
1293 if (clip.empty()) return;
1296 bv_->text->InsertStringB(bv_, clip);
1298 bv_->text->InsertStringA(bv_, clip);
1300 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1304 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1306 workarea_.putClipboard(stuff);
1311 * Dispatch functions for actions which can be valid for BufferView->text
1312 * and/or InsetText->text!!!
1317 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1319 LyXText * lt = bv_->getLyXText();
1321 if (selecting || lt->selection.mark()) {
1322 lt->SetSelection(bv_);
1326 update(lt, BufferView::SELECT|BufferView::FITCUR);
1329 /* ---> Everytime the cursor is moved, show the current font state. */
1330 // should this too me moved out of this func?
1331 //owner->showState();
1336 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1338 LyXCursor cursor = bv_->getLyXText()->cursor;
1339 Buffer::inset_iterator it =
1340 find_if(Buffer::inset_iterator(
1341 cursor.par(), cursor.pos()),
1342 buffer_->inset_iterator_end(),
1343 lyx::compare_memfun(&Inset::LyxCode, code));
1344 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1348 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1350 string filename = filen;
1352 if (filename.empty()) {
1353 // Launch a file browser
1354 string initpath = lyxrc.document_path;
1357 string const trypath = owner_->buffer()->filepath;
1358 // If directory is writeable, use this as default.
1359 if (IsDirWriteable(trypath) == 1)
1363 FileDialog fileDlg(bv_->owner(),
1364 _("Select LyX document to insert"),
1366 make_pair(string(_("Documents")),
1367 string(lyxrc.document_path)),
1368 make_pair(string(_("Examples")),
1369 string(AddPath(system_lyxdir, "examples"))));
1371 FileDialog::Result result =
1372 fileDlg.Select(initpath,
1373 _("*.lyx| LyX Documents (*.lyx)"));
1375 if (result.first == FileDialog::Later)
1378 filename = result.second;
1380 // check selected filename
1381 if (filename.empty()) {
1382 owner_->message(_("Canceled."));
1387 // get absolute path of file and make sure the filename ends
1389 filename = MakeAbsPath(filename);
1390 if (!IsLyXFilename(filename))
1394 string const s1 = _("Inserting document") + ' '
1395 + MakeDisplayPath(filename) + " ...";
1396 owner_->message(s1);
1397 bool const res = bv_->insertLyXFile(filename);
1399 string const str = _("Document") + ' '
1400 + MakeDisplayPath(filename) + ' ' + _("inserted.");
1401 owner_->message(str);
1403 string const str = _("Could not insert document") + ' '
1404 + MakeDisplayPath(filename);
1405 owner_->message(str);
1410 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1413 // --- Misc -------------------------------------------
1417 LyXText * lt = bv_->getLyXText();
1418 lt->toggleAppendix(bv_);
1421 | BufferView::FITCUR
1422 | BufferView::CHANGE);
1427 case LFUN_TOC_INSERT:
1429 InsetCommandParams p;
1430 p.setCmdName("tableofcontents");
1431 Inset * inset = new InsetTOC(p);
1432 if (!insertInset(inset, "Standard"))
1437 case LFUN_TABULAR_FEATURE:
1438 case LFUN_SCROLL_INSET:
1439 // this is not handled here as this funktion is only aktive
1440 // if we have a locking_inset and that one is (or contains)
1444 case LFUN_INSET_GRAPHICS:
1446 Inset * new_inset = new InsetGraphics;
1447 if (!insertInset(new_inset)) {
1450 // this is need because you don't use a inset->Edit()
1451 updateInset(new_inset, true);
1452 new_inset->Edit(bv_, 0, 0, 0);
1462 case LFUN_PASTESELECTION:
1464 bool asPara = false;
1465 if (argument == "paragraph") asPara = true;
1466 pasteClipboard(asPara);
1478 case LFUN_LAYOUT_COPY:
1479 bv_->copyEnvironment();
1482 case LFUN_LAYOUT_PASTE:
1483 bv_->pasteEnvironment();
1487 case LFUN_GOTOERROR:
1488 gotoInset(Inset::ERROR_CODE, false);
1492 gotoInset(Inset::IGNORE_CODE, false);
1495 case LFUN_REFERENCE_GOTO:
1497 vector<Inset::Code> tmp;
1498 tmp.push_back(Inset::LABEL_CODE);
1499 tmp.push_back(Inset::REF_CODE);
1500 gotoInset(tmp, true);
1504 case LFUN_HYPHENATION:
1512 case LFUN_END_OF_SENTENCE:
1516 case LFUN_MENU_SEPARATOR:
1525 changeDepth(bv_, bv_->getLyXText(), 0);
1528 case LFUN_DEPTH_MIN:
1529 changeDepth(bv_, bv_->getLyXText(), -1);
1532 case LFUN_DEPTH_PLUS:
1533 changeDepth(bv_, bv_->getLyXText(), 1);
1537 owner_->getDialogs()->setUserFreeFont();
1543 owner_->showState();
1546 case LFUN_FILE_INSERT:
1548 MenuInsertLyXFile(argument);
1552 case LFUN_FILE_INSERT_ASCII_PARA:
1553 InsertAsciiFile(bv_, argument, true);
1556 case LFUN_FILE_INSERT_ASCII:
1557 InsertAsciiFile(bv_, argument, false);
1562 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1563 << argument << endl;
1565 // Derive layout number from given argument (string)
1566 // and current buffer's textclass (number). */
1567 LyXTextClassList::ClassList::size_type tclass =
1568 buffer_->params.textclass;
1569 pair <bool, LyXTextClass::size_type> layout =
1570 textclasslist.NumberOfLayout(tclass, argument);
1572 // If the entry is obsolete, use the new one instead.
1574 string obs = textclasslist.Style(tclass,layout.second)
1578 textclasslist.NumberOfLayout(tclass, obs);
1581 // see if we found the layout number:
1582 if (!layout.first) {
1583 owner_->getLyXFunc()->setErrorMessage(
1584 string(N_("Layout ")) + argument +
1589 if (current_layout != layout.second) {
1590 LyXText * lt = bv_->getLyXText();
1592 current_layout = layout.second;
1595 | BufferView::FITCUR);
1596 lt->SetLayout(bv_, layout.second);
1597 owner_->setLayout(layout.second);
1600 | BufferView::FITCUR
1601 | BufferView::CHANGE);
1608 Lang(bv_, argument);
1610 owner_->showState();
1615 owner_->showState();
1620 owner_->showState();
1625 owner_->showState();
1630 owner_->showState();
1635 owner_->showState();
1640 owner_->showState();
1645 owner_->showState();
1648 case LFUN_UNDERLINE:
1650 owner_->showState();
1653 case LFUN_FONT_SIZE:
1654 FontSize(bv_, argument);
1655 owner_->showState();
1658 case LFUN_FONT_STATE:
1659 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1662 case LFUN_UPCASE_WORD:
1664 LyXText * lt = bv_->getLyXText();
1668 | BufferView::FITCUR);
1669 lt->ChangeWordCase(bv_, LyXText::text_uppercase);
1670 if (lt->inset_owner)
1671 updateInset(lt->inset_owner, true);
1674 | BufferView::FITCUR
1675 | BufferView::CHANGE);
1679 case LFUN_LOWCASE_WORD:
1681 LyXText * lt = bv_->getLyXText();
1683 update(lt, BufferView::SELECT|BufferView::FITCUR);
1684 lt->ChangeWordCase(bv_, LyXText::text_lowercase);
1685 if (lt->inset_owner)
1686 updateInset(lt->inset_owner, true);
1689 | BufferView::FITCUR
1690 | BufferView::CHANGE);
1694 case LFUN_CAPITALIZE_WORD:
1696 LyXText * lt = bv_->getLyXText();
1698 update(lt, BufferView::SELECT|BufferView::FITCUR);
1699 lt->ChangeWordCase(bv_,
1700 LyXText::text_capitalization);
1701 if (lt->inset_owner)
1702 updateInset(lt->inset_owner, true);
1705 | BufferView::FITCUR
1706 | BufferView::CHANGE);
1710 case LFUN_TRANSPOSE_CHARS:
1712 LyXText * lt = bv_->getLyXText();
1714 update(lt, BufferView::SELECT|BufferView::FITCUR);
1715 lt->TransposeChars(*bv_);
1716 if (lt->inset_owner)
1717 updateInset(lt->inset_owner, true);
1720 | BufferView::FITCUR
1721 | BufferView::CHANGE);
1726 case LFUN_INSERT_LABEL:
1727 MenuInsertLabel(bv_, argument);
1730 case LFUN_REF_INSERT:
1731 if (argument.empty()) {
1732 InsetCommandParams p("ref");
1733 owner_->getDialogs()->createRef(p.getAsString());
1735 InsetCommandParams p;
1736 p.setFromString(argument);
1738 InsetRef * inset = new InsetRef(p, *buffer_);
1739 if (!insertInset(inset))
1742 updateInset(inset, true);
1746 case LFUN_BOOKMARK_SAVE:
1747 savePosition(strToUnsignedInt(argument));
1750 case LFUN_BOOKMARK_GOTO:
1751 restorePosition(strToUnsignedInt(argument));
1756 string label(argument);
1757 if (label.empty()) {
1759 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1761 label = inset->getContents();
1766 if (!label.empty()) {
1767 //bv_->savePosition(0);
1768 if (!bv_->gotoLabel(label))
1769 WriteAlert(_("Error"),
1770 _("Couldn't find this label"),
1771 _("in current document."));
1776 // --- Cursor Movements -----------------------------
1779 LyXText * lt = bv_->getLyXText();
1781 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1782 if (!lt->selection.mark())
1784 update(lt, BufferView::SELECT|BufferView::FITCUR);
1786 lt->CursorLeft(bv_, false);
1787 if (lt->cursor.pos() < lt->cursor.par()->size()
1788 && lt->cursor.par()->GetChar(lt->cursor.pos())
1789 == LyXParagraph::META_INSET
1790 && lt->cursor.par()->GetInset(lt->cursor.pos())
1791 && lt->cursor.par()->GetInset(lt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1792 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1793 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1796 LyXFont const font =
1797 lt->GetFont(buffer_,
1800 y = tmpinset->descent(bv_,font);
1802 tmpinset->Edit(bv_, 0, y, 0);
1806 lt->CursorRight(bv_, false);
1808 moveCursorUpdate(false);
1809 owner_->showState();
1815 // This is soooo ugly. Isn`t it possible to make
1816 // it simpler? (Lgb)
1817 LyXText * lt = bv_->getLyXText();
1818 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1819 if (!lt->selection.mark())
1821 update(lt, BufferView::SELECT|BufferView::FITCUR);
1822 LyXCursor const cur = lt->cursor;
1824 lt->CursorLeft(bv_, false);
1825 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1826 lt->cursor.pos() < lt->cursor.par()->size() &&
1827 (lt->cursor.par()->GetChar(lt->cursor.pos()) ==
1828 LyXParagraph::META_INSET) &&
1829 lt->cursor.par()->GetInset(lt->cursor.pos()) &&
1830 (lt->cursor.par()->GetInset(lt->cursor.pos())->Editable()
1831 == Inset::HIGHLY_EDITABLE))
1833 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1834 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1835 LyXFont const font = lt->GetFont(buffer_,
1839 : tmpinset->descent(bv_,font);
1842 tmpinset->width(bv_,font),
1847 lt->CursorRight(bv_, false);
1850 moveCursorUpdate(false);
1851 owner_->showState();
1857 LyXText * lt = bv_->getLyXText();
1859 if (!lt->selection.mark())
1861 update(lt, BufferView::UPDATE);
1864 moveCursorUpdate(false);
1865 owner_->showState();
1871 LyXText * lt = bv_->getLyXText();
1873 if (!lt->selection.mark())
1875 update(lt, BufferView::UPDATE);
1876 lt->CursorDown(bv_);
1878 moveCursorUpdate(false);
1879 owner_->showState();
1883 case LFUN_UP_PARAGRAPH:
1885 LyXText * lt = bv_->getLyXText();
1887 if (!lt->selection.mark())
1889 update(lt, BufferView::UPDATE);
1890 lt->CursorUpParagraph(bv_);
1892 moveCursorUpdate(false);
1893 owner_->showState();
1897 case LFUN_DOWN_PARAGRAPH:
1899 LyXText * lt = bv_->getLyXText();
1901 if (!lt->selection.mark())
1903 update(lt, BufferView::UPDATE);
1904 lt->CursorDownParagraph(bv_);
1906 moveCursorUpdate(false);
1907 owner_->showState();
1913 LyXText * lt = bv_->getLyXText();
1915 if (!lt->selection.mark())
1917 update(lt, BufferView::UPDATE);
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::SELECT|BufferView::FITCUR);
1946 lt->CursorHome(bv_);
1948 moveCursorUpdate(false);
1949 owner_->showState();
1955 LyXText * lt = bv_->getLyXText();
1957 if (!lt->selection.mark())
1960 BufferView::SELECT|BufferView::FITCUR);
1963 moveCursorUpdate(false);
1964 owner_->showState();
1968 case LFUN_SHIFT_TAB:
1971 LyXText * lt = bv_->getLyXText();
1973 if (!lt->selection.mark())
1976 BufferView::SELECT|BufferView::FITCUR);
1979 moveCursorUpdate(false);
1980 owner_->showState();
1984 case LFUN_WORDRIGHT:
1986 LyXText * lt = bv_->getLyXText();
1988 if (!lt->selection.mark())
1990 update(lt, BufferView::SELECT|BufferView::FITCUR);
1991 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
1992 lt->CursorLeftOneWord(bv_);
1994 lt->CursorRightOneWord(bv_);
1996 moveCursorUpdate(false);
1997 owner_->showState();
2003 LyXText * lt = bv_->getLyXText();
2005 if (!lt->selection.mark())
2007 update(lt, BufferView::SELECT|BufferView::FITCUR);
2008 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2009 lt->CursorRightOneWord(bv_);
2011 lt->CursorLeftOneWord(bv_);
2013 moveCursorUpdate(false);
2014 owner_->showState();
2018 case LFUN_BEGINNINGBUF:
2020 LyXText * lt = bv_->getLyXText();
2022 if (!lt->selection.mark())
2025 BufferView::SELECT|BufferView::FITCUR);
2028 moveCursorUpdate(false);
2029 owner_->showState();
2035 LyXText * lt = bv_->getLyXText();
2037 if (!lt->selection.mark())
2040 BufferView::SELECT|BufferView::FITCUR);
2041 lt->CursorBottom(bv_);
2043 moveCursorUpdate(false);
2044 owner_->showState();
2048 /* cursor selection ---------------------------- */
2051 LyXText * lt = bv_->getLyXText();
2054 BufferView::SELECT|BufferView::FITCUR);
2055 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2056 lt->CursorLeft(bv_);
2058 lt->CursorRight(bv_);
2060 moveCursorUpdate(true);
2061 owner_->showState();
2067 LyXText * lt = bv_->getLyXText();
2070 BufferView::SELECT|BufferView::FITCUR);
2071 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2072 lt->CursorRight(bv_);
2074 lt->CursorLeft(bv_);
2076 moveCursorUpdate(true);
2077 owner_->showState();
2083 LyXText * lt = bv_->getLyXText();
2086 BufferView::SELECT|BufferView::FITCUR);
2089 moveCursorUpdate(true);
2090 owner_->showState();
2096 LyXText * lt = bv_->getLyXText();
2099 BufferView::SELECT|BufferView::FITCUR);
2100 lt->CursorDown(bv_);
2102 moveCursorUpdate(true);
2103 owner_->showState();
2107 case LFUN_UP_PARAGRAPHSEL:
2109 LyXText * lt = bv_->getLyXText();
2112 BufferView::SELECT|BufferView::FITCUR);
2113 lt->CursorUpParagraph(bv_);
2115 moveCursorUpdate(true);
2116 owner_->showState();
2120 case LFUN_DOWN_PARAGRAPHSEL:
2122 LyXText * lt = bv_->getLyXText();
2125 BufferView::SELECT|BufferView::FITCUR);
2126 lt->CursorDownParagraph(bv_);
2128 moveCursorUpdate(true);
2129 owner_->showState();
2135 LyXText * lt = bv_->getLyXText();
2137 update(lt, BufferView::SELECT|BufferView::FITCUR);
2140 moveCursorUpdate(true);
2141 owner_->showState();
2147 LyXText * lt = bv_->getLyXText();
2149 update(lt, BufferView::SELECT|BufferView::FITCUR);
2152 moveCursorUpdate(true);
2153 owner_->showState();
2159 LyXText * lt = bv_->getLyXText();
2161 update(lt, BufferView::SELECT|BufferView::FITCUR);
2162 lt->CursorHome(bv_);
2164 moveCursorUpdate(true);
2165 owner_->showState();
2171 LyXText * lt = bv_->getLyXText();
2173 update(lt, BufferView::SELECT|BufferView::FITCUR);
2176 moveCursorUpdate(true);
2177 owner_->showState();
2181 case LFUN_WORDRIGHTSEL:
2183 LyXText * lt = bv_->getLyXText();
2185 update(lt, BufferView::SELECT|BufferView::FITCUR);
2186 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2187 lt->CursorLeftOneWord(bv_);
2189 lt->CursorRightOneWord(bv_);
2191 moveCursorUpdate(true);
2192 owner_->showState();
2196 case LFUN_WORDLEFTSEL:
2198 LyXText * lt = bv_->getLyXText();
2200 update(lt, BufferView::SELECT|BufferView::FITCUR);
2201 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2202 lt->CursorRightOneWord(bv_);
2204 lt->CursorLeftOneWord(bv_);
2206 moveCursorUpdate(true);
2207 owner_->showState();
2211 case LFUN_BEGINNINGBUFSEL:
2213 LyXText * lt = bv_->getLyXText();
2215 if (lt->inset_owner)
2217 update(lt, BufferView::SELECT|BufferView::FITCUR);
2220 moveCursorUpdate(true);
2221 owner_->showState();
2225 case LFUN_ENDBUFSEL:
2227 LyXText * lt = bv_->getLyXText();
2229 if (lt->inset_owner)
2232 BufferView::SELECT|BufferView::FITCUR);
2233 lt->CursorBottom(bv_);
2235 moveCursorUpdate(true);
2236 owner_->showState();
2240 // --- text changing commands ------------------------
2241 case LFUN_BREAKLINE:
2243 LyXText * lt = bv_->getLyXText();
2246 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2249 | BufferView::FITCUR
2250 | BufferView::CHANGE);
2251 moveCursorUpdate(false);
2255 case LFUN_PROTECTEDSPACE:
2257 LyXText * lt = bv_->getLyXText();
2259 LyXLayout const & style = textclasslist
2260 .Style(buffer_->params.textclass,
2261 lt->cursor.par()->GetLayout());
2263 if (style.free_spacing) {
2264 lt->InsertChar(bv_, ' ');
2267 | BufferView::FITCUR
2268 | BufferView::CHANGE);
2272 moveCursorUpdate(false);
2278 LyXText * lt = bv_->getLyXText();
2280 if (lt->selection.mark()) {
2284 | BufferView::FITCUR);
2285 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2288 lt->selection.mark(true);
2291 | BufferView::FITCUR);
2292 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2294 lt->selection.cursor = lt->cursor;
2300 LyXText * lt = bv_->getLyXText();
2302 if (!lt->selection.set()) {
2304 lt->selection.cursor = lt->cursor;
2307 | BufferView::FITCUR
2308 | BufferView::CHANGE);
2309 // It is possible to make it a lot faster still
2310 // just comment out the line below...
2315 moveCursorUpdate(false);
2316 owner_->showState();
2321 case LFUN_DELETE_SKIP:
2323 LyXText * lt = bv_->getLyXText();
2325 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2327 LyXCursor cursor = lt->cursor;
2329 if (!lt->selection.set()) {
2330 if (cursor.pos() == cursor.par()->size()) {
2331 lt->CursorRight(bv_);
2332 cursor = lt->cursor;
2333 if (cursor.pos() == 0
2334 && !(cursor.par()->params.spaceTop()
2335 == VSpace (VSpace::NONE))) {
2338 cursor.par()->params.lineTop(),
2339 cursor.par()->params.lineBottom(),
2340 cursor.par()->params.pagebreakTop(),
2341 cursor.par()->params.pagebreakBottom(),
2342 VSpace(VSpace::NONE),
2343 cursor.par()->params.spaceBottom(),
2344 cursor.par()->params.align(),
2345 cursor.par()->params.labelWidthString(), 0);
2346 lt->CursorLeft(bv_);
2349 | BufferView::FITCUR
2350 | BufferView::CHANGE);
2352 lt->CursorLeft(bv_);
2354 lt->selection.cursor = lt->cursor;
2357 | BufferView::FITCUR
2358 | BufferView::CHANGE);
2362 lt->selection.cursor = lt->cursor;
2365 | BufferView::FITCUR
2366 | BufferView::CHANGE);
2374 /* -------> Delete word forward. */
2375 case LFUN_DELETE_WORD_FORWARD:
2376 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2377 bv_->getLyXText()->DeleteWordForward(bv_);
2378 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2379 moveCursorUpdate(false);
2380 owner_->showState();
2383 /* -------> Delete word backward. */
2384 case LFUN_DELETE_WORD_BACKWARD:
2386 LyXText * lt = bv_->getLyXText();
2388 update(lt, BufferView::SELECT|BufferView::FITCUR);
2389 lt->DeleteWordBackward(bv_);
2392 | BufferView::FITCUR
2393 | BufferView::CHANGE);
2394 moveCursorUpdate(false);
2395 owner_->showState();
2399 /* -------> Kill to end of line. */
2400 case LFUN_DELETE_LINE_FORWARD:
2402 LyXText * lt = bv_->getLyXText();
2404 update(lt, BufferView::SELECT|BufferView::FITCUR);
2405 lt->DeleteLineForward(bv_);
2408 | BufferView::FITCUR
2409 | BufferView::CHANGE);
2410 moveCursorUpdate(false);
2414 /* -------> Set mark off. */
2417 LyXText * lt = bv_->getLyXText();
2420 update(lt, BufferView::SELECT|BufferView::FITCUR);
2421 lt->selection.cursor = lt->cursor;
2422 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2426 /* -------> Set mark on. */
2429 LyXText * lt = bv_->getLyXText();
2432 lt->selection.mark(true);
2433 update(lt, BufferView::SELECT|BufferView::FITCUR);
2434 lt->selection.cursor = lt->cursor;
2435 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2439 case LFUN_BACKSPACE:
2441 LyXText * lt = bv_->getLyXText();
2443 if (!lt->selection.set()) {
2444 if (owner_->getIntl()->getTrans().backspace()) {
2446 lt->selection.cursor = lt->cursor;
2449 | BufferView::FITCUR
2450 | BufferView::CHANGE);
2451 // It is possible to make it a lot faster still
2452 // just comment out the line below...
2458 owner_->showState();
2463 case LFUN_BACKSPACE_SKIP:
2465 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2466 LyXText * lt = bv_->getLyXText();
2468 LyXCursor cursor = lt->cursor;
2470 if (!lt->selection.set()) {
2471 if (cursor.pos() == 0
2472 && !(cursor.par()->params.spaceTop()
2473 == VSpace (VSpace::NONE))) {
2476 cursor.par()->params.lineTop(),
2477 cursor.par()->params.lineBottom(),
2478 cursor.par()->params.pagebreakTop(),
2479 cursor.par()->params.pagebreakBottom(),
2480 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2481 cursor.par()->params.align(),
2482 cursor.par()->params.labelWidthString(), 0);
2485 | BufferView::FITCUR
2486 | BufferView::CHANGE);
2489 lt->selection.cursor = cursor;
2492 | BufferView::FITCUR
2493 | BufferView::CHANGE);
2500 case LFUN_BREAKPARAGRAPH:
2502 LyXText * lt = bv_->getLyXText();
2505 lt->BreakParagraph(bv_, 0);
2508 | BufferView::FITCUR
2509 | BufferView::CHANGE);
2510 lt->selection.cursor = lt->cursor;
2512 owner_->showState();
2516 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2518 LyXText * lt = bv_->getLyXText();
2521 lt->BreakParagraph(bv_, 1);
2524 | BufferView::FITCUR
2525 | BufferView::CHANGE);
2526 lt->selection.cursor = lt->cursor;
2528 owner_->showState();
2532 case LFUN_BREAKPARAGRAPH_SKIP:
2534 // When at the beginning of a paragraph, remove
2535 // indentation and add a "defskip" at the top.
2536 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2537 LyXText * lt = bv_->getLyXText();
2539 LyXCursor cursor = lt->cursor;
2542 if (cursor.pos() == 0) {
2543 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2546 cursor.par()->params.lineTop(),
2547 cursor.par()->params.lineBottom(),
2548 cursor.par()->params.pagebreakTop(),
2549 cursor.par()->params.pagebreakBottom(),
2550 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2551 cursor.par()->params.align(),
2552 cursor.par()->params.labelWidthString(), 1);
2553 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2557 lt->BreakParagraph(bv_, 0);
2558 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2563 | BufferView::FITCUR
2564 | BufferView::CHANGE);
2565 lt->selection.cursor = cursor;
2567 owner_->showState();
2571 case LFUN_PARAGRAPH_SPACING:
2573 LyXText * lt = bv_->getLyXText();
2575 LyXParagraph * par = lt->cursor.par();
2576 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2577 float cur_value = 1.0;
2578 if (cur_spacing == Spacing::Other) {
2579 cur_value = par->params.spacing().getValue();
2582 istringstream istr(argument.c_str());
2586 Spacing::Space new_spacing = cur_spacing;
2587 float new_value = cur_value;
2589 lyxerr << "Missing argument to `paragraph-spacing'"
2591 } else if (tmp == "single") {
2592 new_spacing = Spacing::Single;
2593 } else if (tmp == "onehalf") {
2594 new_spacing = Spacing::Onehalf;
2595 } else if (tmp == "double") {
2596 new_spacing = Spacing::Double;
2597 } else if (tmp == "other") {
2598 new_spacing = Spacing::Other;
2601 lyxerr << "new_value = " << tmpval << endl;
2604 } else if (tmp == "default") {
2605 new_spacing = Spacing::Default;
2607 lyxerr << _("Unknown spacing argument: ")
2608 << argument << endl;
2610 if (cur_spacing != new_spacing || cur_value != new_value) {
2611 par->params.spacing(Spacing(new_spacing, new_value));
2612 lt->RedoParagraph(bv_);
2615 | BufferView::FITCUR
2616 | BufferView::CHANGE);
2622 bv_->insertCorrectQuote();
2628 InsetCommandParams p;
2629 if (action == LFUN_HTMLURL)
2630 p.setCmdName("htmlurl");
2632 p.setCmdName("url");
2633 owner_->getDialogs()->createUrl( p.getAsString() );
2637 case LFUN_INSERT_URL:
2639 InsetCommandParams p;
2640 p.setFromString( argument );
2642 InsetUrl * inset = new InsetUrl( p );
2643 if (!insertInset(inset))
2646 updateInset( inset, true );
2650 case LFUN_INSET_TEXT:
2652 InsetText * new_inset = new InsetText;
2653 if (insertInset(new_inset))
2654 new_inset->Edit(bv_, 0, 0, 0);
2660 case LFUN_INSET_ERT:
2662 InsetERT * new_inset = new InsetERT;
2663 if (insertInset(new_inset))
2664 new_inset->Edit(bv_, 0, 0, 0);
2670 case LFUN_INSET_EXTERNAL:
2672 InsetExternal * new_inset = new InsetExternal;
2673 if (insertInset(new_inset))
2674 new_inset->Edit(bv_, 0, 0, 0);
2680 case LFUN_INSET_FOOTNOTE:
2682 InsetFoot * new_inset = new InsetFoot;
2683 if (insertInset(new_inset))
2684 new_inset->Edit(bv_, 0, 0, 0);
2690 case LFUN_INSET_MARGINAL:
2692 InsetMarginal * new_inset = new InsetMarginal;
2693 if (insertInset(new_inset))
2694 new_inset->Edit(bv_, 0, 0, 0);
2700 case LFUN_INSET_MINIPAGE:
2702 InsetMinipage * new_inset = new InsetMinipage;
2703 if (insertInset(new_inset))
2704 new_inset->Edit(bv_, 0, 0, 0);
2710 case LFUN_INSET_FLOAT:
2712 // check if the float type exist
2713 if (floatList.typeExist(argument)) {
2714 InsetFloat * new_inset = new InsetFloat(argument);
2715 if (insertInset(new_inset))
2716 new_inset->Edit(bv_, 0, 0, 0);
2720 lyxerr << "Non-existant float type: "
2721 << argument << endl;
2727 case LFUN_INSET_WIDE_FLOAT:
2729 // check if the float type exist
2730 if (floatList.typeExist(argument)) {
2731 InsetFloat * new_inset = new InsetFloat(argument);
2732 new_inset->wide(true);
2733 if (insertInset(new_inset))
2734 new_inset->Edit(bv_, 0, 0, 0);
2738 lyxerr << "Non-existant float type: "
2739 << argument << endl;
2745 case LFUN_INSET_LIST:
2747 InsetList * new_inset = new InsetList;
2748 if (insertInset(new_inset))
2749 new_inset->Edit(bv_, 0, 0, 0);
2755 case LFUN_INSET_THEOREM:
2757 InsetTheorem * new_inset = new InsetTheorem;
2758 if (insertInset(new_inset))
2759 new_inset->Edit(bv_, 0, 0, 0);
2765 case LFUN_INSET_CAPTION:
2767 // Do we have a locking inset...
2768 if (bv_->theLockingInset()) {
2769 lyxerr << "Locking inset code: "
2770 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2771 InsetCaption * new_inset = new InsetCaption;
2772 new_inset->setOwner(bv_->theLockingInset());
2773 new_inset->SetAutoBreakRows(true);
2774 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2775 new_inset->SetFrameColor(0, LColor::captionframe);
2776 if (insertInset(new_inset))
2777 new_inset->Edit(bv_, 0, 0, 0);
2784 case LFUN_INSET_TABULAR:
2788 if (!argument.empty())
2789 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2790 InsetTabular * new_inset =
2791 new InsetTabular(*buffer_, r, c);
2793 bv_->getLyXText()->real_current_font.isRightToLeft();
2794 if (!open_new_inset(new_inset, rtl))
2799 // --- lyxserver commands ----------------------------
2801 case LFUN_CHARATCURSOR:
2803 LyXParagraph::size_type pos = bv_->getLyXText()->cursor.pos();
2804 if (pos < bv_->getLyXText()->cursor.par()->size())
2805 owner_->getLyXFunc()->setMessage(
2806 tostr(bv_->getLyXText()->cursor.par()->GetChar(pos)));
2808 owner_->getLyXFunc()->setMessage("EOF");
2813 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2815 + tostr(bv_->getLyXText()->cursor.y()));
2820 #warning Should check sscanf for errors (Lgb)
2823 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2824 bv_->getLyXText()->SetCursorFromCoordinates(bv_, x, y);
2828 case LFUN_GETLAYOUT:
2829 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2834 LyXFont & font = bv_->getLyXText()->current_font;
2835 if (font.shape() == LyXFont::ITALIC_SHAPE)
2836 owner_->getLyXFunc()->setMessage("E");
2837 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2838 owner_->getLyXFunc()->setMessage("N");
2840 owner_->getLyXFunc()->setMessage("0");
2847 LyXFont & font = bv_->getLyXText()->current_font;
2848 if (font.latex() == LyXFont::ON)
2849 owner_->getLyXFunc()->setMessage("L");
2851 owner_->getLyXFunc()->setMessage("0");
2855 // --- accented characters ---------------------------
2858 case LFUN_CIRCUMFLEX:
2868 case LFUN_SPECIAL_CARON:
2871 case LFUN_HUNG_UMLAUT:
2874 if (argument.empty()) {
2876 owner_->getLyXFunc()->handleKeyFunc(action);
2878 owner_->getLyXFunc()->handleKeyFunc(action);
2879 owner_->getIntl()->getTrans()
2880 .TranslateAndInsert(argument[0], bv_->getLyXText());
2881 update(bv_->getLyXText(),
2883 | BufferView::FITCUR
2884 | BufferView::CHANGE);
2888 // --- insert characters ----------------------------------------
2890 case LFUN_MATH_DELIM:
2891 case LFUN_INSERT_MATRIX:
2894 if (open_new_inset(new InsetFormula(false))) {
2895 bv_->theLockingInset()
2896 ->LocalDispatch(bv_, action, argument);
2902 case LFUN_INSERT_MATH:
2907 InsetFormula * f = new InsetFormula(true);
2909 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2913 case LFUN_MATH_DISPLAY:
2916 open_new_inset(new InsetFormula(true));
2920 case LFUN_MATH_MACRO:
2925 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2927 string const s1 = token(s, ' ', 1);
2928 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2929 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2935 case LFUN_MATH_MODE: // Open or create a math inset
2938 open_new_inset(new InsetFormula);
2939 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2943 case LFUN_CITATION_INSERT:
2945 InsetCommandParams p;
2946 p.setFromString( argument );
2948 InsetCitation * inset = new InsetCitation( p );
2949 if (!insertInset(inset))
2952 updateInset( inset, true );
2956 case LFUN_INSERT_BIBTEX:
2958 // ale970405+lasgoutt970425
2959 // The argument can be up to two tokens separated
2960 // by a space. The first one is the bibstyle.
2961 string const db = token(argument, ' ', 0);
2962 string bibstyle = token(argument, ' ', 1);
2963 if (bibstyle.empty())
2966 InsetCommandParams p( "BibTeX", db, bibstyle );
2967 InsetBibtex * inset = new InsetBibtex(p);
2969 if (insertInset(inset)) {
2970 if (argument.empty())
2971 inset->Edit(bv_, 0, 0, 0);
2977 // BibTeX data bases
2978 case LFUN_BIBDB_ADD:
2980 InsetBibtex * inset =
2981 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2983 inset->addDatabase(argument);
2988 case LFUN_BIBDB_DEL:
2990 InsetBibtex * inset =
2991 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2993 inset->delDatabase(argument);
2998 case LFUN_BIBTEX_STYLE:
3000 InsetBibtex * inset =
3001 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3003 inset->setOptions(argument);
3008 case LFUN_INDEX_CREATE:
3010 InsetCommandParams p( "index" );
3012 if (argument.empty()) {
3013 // Get the word immediately preceding the cursor
3014 LyXParagraph::size_type curpos =
3015 bv_->getLyXText()->cursor.pos() - 1;
3019 curstring = bv_->getLyXText()
3020 ->cursor.par()->GetWord(curpos);
3022 p.setContents( curstring );
3024 p.setContents( argument );
3027 owner_->getDialogs()->createIndex( p.getAsString() );
3031 case LFUN_INDEX_INSERT:
3033 InsetCommandParams p;
3034 p.setFromString(argument);
3035 InsetIndex * inset = new InsetIndex(p);
3037 if (!insertInset(inset))
3040 updateInset(inset, true);
3044 case LFUN_INDEX_INSERT_LAST:
3046 // Get word immediately preceding the cursor
3047 LyXParagraph::size_type curpos =
3048 bv_->getLyXText()->cursor.pos() - 1;
3049 // Can't do that at the beginning of a paragraph
3050 if (curpos < 0) break;
3052 string const curstring(bv_->getLyXText()
3053 ->cursor.par()->GetWord(curpos));
3055 InsetCommandParams p("index", curstring);
3056 InsetIndex * inset = new InsetIndex(p);
3058 if (!insertInset(inset))
3061 updateInset(inset, true);
3065 case LFUN_INDEX_PRINT:
3067 InsetCommandParams p("printindex");
3068 Inset * inset = new InsetPrintIndex(p);
3069 if (!insertInset(inset, "Standard"))
3074 case LFUN_PARENTINSERT:
3076 lyxerr << "arg " << argument << endl;
3077 InsetCommandParams p( "lyxparent", argument );
3078 Inset * inset = new InsetParent(p, *buffer_);
3079 if (!insertInset(inset, "Standard"))
3085 case LFUN_CHILD_INSERT:
3087 InsetInclude::Params p;
3088 p.cparams.setFromString(argument);
3089 p.masterFilename_ = buffer_->fileName();
3091 InsetInclude * inset = new InsetInclude(p);
3092 if (!insertInset(inset))
3095 updateInset(inset, true);
3096 bv_->owner()->getDialogs()->showInclude(inset);
3101 case LFUN_FLOAT_LIST:
3103 // We should check the argument for validity. (Lgb)
3104 Inset * inset = new InsetFloatList(argument);
3105 if (!insertInset(inset, "Standard"))
3110 case LFUN_INSERT_NOTE:
3114 case LFUN_SELFINSERT:
3116 if (argument.empty()) break;
3118 /* Automatically delete the currently selected
3119 * text and replace it with what is being
3120 * typed in now. Depends on lyxrc settings
3121 * "auto_region_delete", which defaults to
3124 LyXText * lt = bv_->getLyXText();
3126 if (lyxrc.auto_region_delete) {
3127 if (lt->selection.set()) {
3128 lt->CutSelection(bv_, false);
3131 | BufferView::FITCUR
3132 | BufferView::CHANGE);
3136 bv_->beforeChange(lt);
3137 LyXFont const old_font(lt->real_current_font);
3139 string::const_iterator cit = argument.begin();
3140 string::const_iterator end = argument.end();
3141 for (; cit != end; ++cit) {
3142 if (greek_kb_flag) {
3143 if (!math_insert_greek(bv_, *cit))
3144 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3146 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3151 | BufferView::FITCUR
3152 | BufferView::CHANGE);
3154 lt->selection.cursor = lt->cursor;
3155 moveCursorUpdate(false);
3157 // real_current_font.number can change so we need to
3158 // update the minibuffer
3159 if (old_font != lt->real_current_font)
3160 owner_->showState();
3165 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3167 time_t now_time_t = time(NULL);
3168 struct tm * now_tm = localtime(&now_time_t);
3169 setlocale(LC_TIME, "");
3171 if (!argument.empty())
3174 arg = lyxrc.date_insert_format;
3176 int const datetmp_len =
3177 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3179 LyXText * lt = bv_->getLyXText();
3181 for (int i = 0; i < datetmp_len; i++) {
3182 lt->InsertChar(bv_, datetmp[i]);
3185 | BufferView::FITCUR
3186 | BufferView::CHANGE);
3189 lt->selection.cursor = lt->cursor;
3190 moveCursorUpdate(false);
3194 case LFUN_UNKNOWN_ACTION:
3195 owner_->getLyXFunc()->setErrorMessage(N_("Unknow function!"));
3206 void BufferView::Pimpl::newline()
3209 LyXText * lt = bv_->getLyXText();
3213 | BufferView::FITCUR);
3214 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
3217 | BufferView::FITCUR
3218 | BufferView::CHANGE);
3223 void BufferView::Pimpl::hfill()
3226 LyXText * lt = bv_->getLyXText();
3230 | BufferView::FITCUR);
3231 lt->InsertChar(bv_, LyXParagraph::META_HFILL);
3234 | BufferView::FITCUR
3235 | BufferView::CHANGE);
3240 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3244 update(lt, BufferView::SELECT|BufferView::FITCUR);
3245 InsetSpecialChar * new_inset =
3246 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3247 if (!insertInset(new_inset))
3250 updateInset(new_inset, true);
3255 void BufferView::Pimpl::menuSeparator()
3258 LyXText * lt = bv_->getLyXText();
3261 update(lt, BufferView::SELECT|BufferView::FITCUR);
3262 InsetSpecialChar * new_inset =
3263 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3264 insertInset(new_inset);
3269 void BufferView::Pimpl::endOfSentenceDot()
3273 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3274 InsetSpecialChar * new_inset =
3275 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3276 insertInset(new_inset);
3281 void BufferView::Pimpl::ldots()
3285 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3286 InsetSpecialChar * new_inset =
3287 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3288 insertInset(new_inset);
3293 void BufferView::Pimpl::hyphenationPoint()
3297 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3298 InsetSpecialChar * new_inset =
3299 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3300 insertInset(new_inset);
3305 void BufferView::Pimpl::insertNote()
3307 InsetInfo * new_inset = new InsetInfo();
3308 insertInset(new_inset);
3309 new_inset->Edit(bv_, 0, 0, 0);
3313 // Open and lock an updatable inset
3314 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3316 LyXText * lt = bv_->getLyXText();
3320 if (!insertInset(new_inset)) {
3325 LyXFont & font = lt->real_current_font;
3326 new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
3328 new_inset->Edit(bv_, 0, 0, 0);
3333 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3335 // if we are in a locking inset we should try to insert the
3336 // inset there otherwise this is a illegal function now
3337 if (bv_->theLockingInset()) {
3338 if (bv_->theLockingInset()->InsertInsetAllowed(inset))
3339 return bv_->theLockingInset()->InsertInset(bv_, inset);
3343 // not quite sure if we want this...
3344 bv_->text->SetCursorParUndo(buffer_);
3345 bv_->text->FreezeUndo();
3347 beforeChange(bv_->text);
3348 if (!lout.empty()) {
3349 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3350 bv_->text->BreakParagraph(bv_);
3351 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3353 if (bv_->text->cursor.par()->size()) {
3354 bv_->text->CursorLeft(bv_);
3356 bv_->text->BreakParagraph(bv_);
3357 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3360 pair<bool, LyXTextClass::size_type> lres =
3361 textclasslist.NumberOfLayout(buffer_->params
3363 LyXTextClass::size_type lay;
3364 if (lres.first != false) {
3368 // layout not fount using default "Standard" (0)
3372 bv_->text->SetLayout(bv_, lay);
3374 bv_->text->SetParagraph(bv_, 0, 0,
3376 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3380 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3382 bv_->text->current_font.setLatex(LyXFont::OFF);
3385 bv_->text->InsertInset(bv_, inset);
3386 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3388 bv_->text->UnFreezeUndo();
3393 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3398 // first check for locking insets
3399 if (bv_->theLockingInset()) {
3400 if (bv_->theLockingInset() == inset) {
3401 if (bv_->text->UpdateInset(bv_, inset)) {
3404 buffer_->markDirty();
3409 } else if (bv_->theLockingInset()->UpdateInsetInInset(bv_, inset)) {
3410 if (bv_->text->UpdateInset(bv_,
3411 bv_->theLockingInset())) {
3414 buffer_->markDirty();
3422 // then check the current buffer
3425 update(bv_->text, BufferView::UPDATE);
3426 if (bv_->text->UpdateInset(bv_, inset)) {
3430 | BufferView::FITCUR
3431 | BufferView::CHANGE);
3433 update(bv_->text, SELECT);
3441 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3444 if (!available()) return;
3447 beforeChange(bv_->text);
3448 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3452 bv_->text->cursor.par()->GetChar(bv_->text->cursor.pos()) == LyXParagraph::META_INSET) {
3453 Inset const * inset = bv_->text->cursor.par()->GetInset(bv_->text->cursor.pos());
3454 if (find(codes.begin(), codes.end(), inset->LyxCode())
3457 static_cast<InsetCommand const *>(inset)->getContents();
3460 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3461 if (bv_->text->cursor.pos()
3462 || bv_->text->cursor.par() != bv_->text->FirstParagraph()) {
3463 LyXCursor tmp = bv_->text->cursor;
3464 bv_->text->cursor.par(bv_->text->FirstParagraph());
3465 bv_->text->cursor.pos(0);
3466 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3467 bv_->text->cursor = tmp;
3468 bv_->owner()->message(_("No more insets"));
3471 bv_->owner()->message(_("No more insets"));
3474 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3475 bv_->text->selection.cursor = bv_->text->cursor;
3479 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3481 gotoInset(vector<Inset::Code>(1, code), same_content);