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 /// clear the "Formatting Document" message
353 /// get rid of the splash screen if it's not gone already
354 owner_->getDialogs()->destroySplash();
360 void BufferView::Pimpl::updateScreen()
362 // Regenerate the screen.
363 screen_.reset(new LyXScreen(workarea_));
367 void BufferView::Pimpl::updateScrollbar()
369 /* If the text is smaller than the working area, the scrollbar
370 * maximum must be the working area height. No scrolling will
374 workarea_.setScrollbar(0, 1.0);
378 static unsigned long text_height;
379 static unsigned long work_height;
381 unsigned long const tmp_text_height = bv_->text->height;
382 long const tmp_scrollbar_value = bv_->text->first;
384 // check if anything has changed.
385 if (text_height == tmp_text_height
386 && work_height == workarea_.height()
387 && current_scrollbar_value == tmp_scrollbar_value)
391 text_height = tmp_text_height;
392 work_height = workarea_.height();
393 current_scrollbar_value = tmp_scrollbar_value;
395 long const height_diff = text_height - work_height;
397 if (height_diff <= 0) {
398 workarea_.setScrollbar(0, 1.0);
403 workarea_.setScrollbarBounds(0, height_diff);
404 double const lineh = bv_->text->DefaultHeight();
405 workarea_.setScrollbarIncrements(lineh);
406 double const slider_size = 1.0 / double(height_diff) ;
407 workarea_.setScrollbar(current_scrollbar_value, slider_size);
411 // Callback for scrollbar slider
412 void BufferView::Pimpl::scrollCB(double value)
414 if (!buffer_) return;
416 current_scrollbar_value = long(value);
417 if (current_scrollbar_value < 0)
418 current_scrollbar_value = 0;
423 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
425 if (!lyxrc.cursor_follows_scrollbar) {
430 LyXText * vbt = bv_->text;
432 int const height = vbt->DefaultHeight();
433 int const first = static_cast<int>((bv_->text->first + height));
434 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
436 if (vbt->cursor.y() < first)
437 vbt->SetCursorFromCoordinates(bv_, 0, first);
438 else if (vbt->cursor.y() > last)
439 vbt->SetCursorFromCoordinates(bv_, 0, last);
445 int BufferView::Pimpl::scrollUp(long time)
447 if (!buffer_) return 0;
448 if (!screen_.get()) return 0;
450 double value = workarea_.getScrollbarValue();
452 if (value == 0) return 0;
454 float add_value = (bv_->text->DefaultHeight()
455 + float(time) * float(time) * 0.125);
457 if (add_value > workarea_.height())
458 add_value = float(workarea_.height() -
459 bv_->text->DefaultHeight());
466 workarea_.setScrollbarValue(value);
473 int BufferView::Pimpl::scrollDown(long time)
475 if (!buffer_) return 0;
476 if (!screen_.get()) return 0;
478 double value = workarea_.getScrollbarValue();
479 pair<float, float> p = workarea_.getScrollbarBounds();
480 double const max = p.second;
482 if (value == max) return 0;
484 float add_value = (bv_->text->DefaultHeight()
485 + float(time) * float(time) * 0.125);
487 if (add_value > workarea_.height())
488 add_value = float(workarea_.height() -
489 bv_->text->DefaultHeight());
496 workarea_.setScrollbarValue(value);
503 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
505 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
509 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
511 // Only use motion with button 1
512 if (!(state & Button1MotionMask))
515 if (!buffer_ || !screen_.get()) return;
517 // Check for inset locking
518 if (bv_->theLockingInset()) {
519 LyXCursor cursor = bv_->text->cursor;
520 LyXFont font = bv_->text->GetFont(buffer_,
521 cursor.par(), cursor.pos());
522 int width = bv_->theLockingInset()->width(bv_, font);
523 int inset_x = font.isVisibleRightToLeft()
524 ? cursor.x() - width : cursor.x();
525 int start_x = inset_x + bv_->theLockingInset()->scroll();
526 bv_->theLockingInset()->
527 InsetMotionNotify(bv_,
529 y - cursor.y() + bv_->text->first,
534 /* The test for not selection possible is needed, that only motion
535 events are used, where the bottom press event was on
536 the drawing area too */
537 if (!selection_possible)
540 screen_->HideCursor();
542 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
544 if (!bv_->text->selection.set())
545 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
547 bv_->text->SetSelection(bv_);
548 screen_->ToggleToggle(bv_->text, bv_);
549 fitCursor(bv_->text);
550 screen_->ShowCursor(bv_->text, bv_);
554 // Single-click on work area
555 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
558 if (!buffer_ || !screen_.get()) return;
560 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
562 // ok ok, this is a hack.
563 if (button == 4 || button == 5) {
566 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
569 scrollDown(lyxrc.wheel_jump);
574 if (bv_->theLockingInset()) {
575 // We are in inset locking mode
577 /* Check whether the inset was hit. If not reset mode,
578 otherwise give the event to the inset */
579 if (inset_hit == bv_->theLockingInset()) {
580 bv_->theLockingInset()->
581 InsetButtonPress(bv_,
586 bv_->unlockInset(bv_->theLockingInset());
591 selection_possible = true;
592 screen_->HideCursor();
594 int const screen_first = bv_->text->first;
596 // Middle button press pastes if we have a selection
597 bool paste_internally = false;
599 && bv_->text->selection.set()) {
600 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
601 paste_internally = true;
604 // Clear the selection
605 screen_->ToggleSelection(bv_->text, bv_);
606 bv_->text->ClearSelection(bv_);
607 bv_->text->FullRebreak(bv_);
608 screen_->Update(bv_->text, bv_);
611 // Single left click in math inset?
612 if ((inset_hit != 0) &&
613 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
614 // Highly editable inset, like math
615 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
616 selection_possible = false;
617 owner_->updateLayoutChoice();
618 owner_->message(inset->EditMessage());
619 inset->InsetButtonPress(bv_, xpos, ypos, button);
620 inset->Edit(bv_, xpos, ypos, button);
624 // Right click on a footnote flag opens float menu
626 selection_possible = false;
630 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
631 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
632 bv_->text->FinishUndo();
633 bv_->text->selection.cursor = bv_->text->cursor;
634 bv_->text->cursor.x_fix(bv_->text->cursor.x());
636 owner_->updateLayoutChoice();
637 if (fitCursor(bv_->text)) {
638 selection_possible = false;
641 // Insert primary selection with middle mouse
642 // if there is a local selection in the current buffer,
645 if (paste_internally)
646 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
648 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
650 selection_possible = false;
656 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
662 LyXText * text = bv_->getLyXText();
664 if (text->bv_owner && bv_->theLockingInset())
667 if (screen_.get() && button == 1) {
668 if (text->bv_owner) {
669 screen_->HideCursor();
670 screen_->ToggleSelection(text, bv_);
671 text->SelectWord(bv_);
672 screen_->ToggleSelection(text, bv_, false);
674 text->SelectWord(bv_);
676 /* This will fit the cursor on the screen
678 update(text, BufferView::SELECT|BufferView::FITCUR);
683 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
689 LyXText * text = bv_->getLyXText();
691 if (text->bv_owner && bv_->theLockingInset())
694 if (screen_.get() && (button == 1)) {
695 screen_->HideCursor();
696 screen_->ToggleSelection(text, bv_);
697 text->CursorHome(bv_);
698 text->selection.cursor = text->cursor;
699 text->CursorEnd(bv_);
700 text->SetSelection(bv_);
701 screen_->ToggleSelection(text, bv_, false);
702 /* This will fit the cursor on the screen
704 update(text, BufferView::SELECT|BufferView::FITCUR);
709 void BufferView::Pimpl::enterView()
711 if (active() && available()) {
712 SetXtermCursor(workarea_.getWin());
713 using_xterm_cursor = true;
718 void BufferView::Pimpl::leaveView()
720 if (using_xterm_cursor) {
721 XUndefineCursor(fl_get_display(), workarea_.getWin());
722 using_xterm_cursor = false;
727 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
730 if (!buffer_ || !screen_.get()) return;
732 // If we hit an inset, we have the inset coordinates in these
733 // and inset_hit points to the inset. If we do not hit an
734 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
735 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
737 if (bv_->theLockingInset()) {
738 // We are in inset locking mode.
740 /* LyX does a kind of work-area grabbing for insets.
741 Only a ButtonPress Event outside the inset will
742 force a InsetUnlock. */
743 bv_->theLockingInset()->
744 InsetButtonRelease(bv_, x, y, button);
748 selection_possible = false;
756 // Did we hit an editable inset?
758 // Inset like error, notes and figures
759 selection_possible = false;
761 // CHECK fix this proper in 0.13
763 // Following a ref shouldn't issue
764 // a push on the undo-stack
765 // anylonger, now that we have
766 // keybindings for following
767 // references and returning from
768 // references. IMHO though, it
769 // should be the inset's own business
770 // to push or not push on the undo
771 // stack. They don't *have* to
772 // alter the document...
774 // ...or maybe the SetCursorParUndo()
775 // below isn't necessary at all anylonger?
776 if (inset_hit->LyxCode() == Inset::REF_CODE) {
777 bv_->text->SetCursorParUndo(buffer_);
780 owner_->message(inset_hit->EditMessage());
782 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
783 // Highly editable inset, like math
784 UpdatableInset *inset = (UpdatableInset *)inset_hit;
785 inset->InsetButtonRelease(bv_, x, y, button);
787 inset_hit->InsetButtonRelease(bv_, x, y, button);
788 inset_hit->Edit(bv_, x, y, button);
793 // check whether we want to open a float
797 if (bv_->text->cursor.pos() <
798 bv_->text->cursor.par()->size()) {
799 c = bv_->text->cursor.par()->
800 GetChar(bv_->text->cursor.pos());
802 if (bv_->text->cursor.pos() - 1 >= 0) {
803 c = bv_->text->cursor.par()->
804 GetChar(bv_->text->cursor.pos() - 1);
807 selection_possible = false;
812 // Maybe we want to edit a bibitem ale970302
813 if (bv_->text->cursor.par()->bibkey && x < 20 +
814 bibitemMaxWidth(bv_, textclasslist.
816 params.textclass).defaultfont())) {
817 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
825 * Returns an inset if inset was hit. 0 otherwise.
826 * If hit, the coordinates are changed relative to the inset.
827 * Otherwise coordinates are not changed, and false is returned.
829 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
830 unsigned int /* button */)
835 int y_tmp = y + text->first;
838 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
839 text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
842 if (cursor.pos() < cursor.par()->size()
843 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
844 && cursor.par()->GetInset(cursor.pos())
845 && cursor.par()->GetInset(cursor.pos())->Editable()) {
847 // Check whether the inset really was hit
848 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
849 LyXFont font = text->GetFont(buffer_,
850 cursor.par(), cursor.pos());
851 int const width = tmpinset->width(bv_, font);
852 int const inset_x = font.isVisibleRightToLeft()
853 ? cursor.x() - width : cursor.x();
854 int const start_x = inset_x + tmpinset->scroll();
855 int const end_x = inset_x + width;
857 if (x > start_x && x < end_x
858 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
859 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
860 text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
862 // The origin of an inset is on the baseline
863 y = y_tmp - (text->cursor.y());
868 if ((cursor.pos() - 1 >= 0) &&
869 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
870 (cursor.par()->GetInset(cursor.pos() - 1)) &&
871 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
872 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
873 LyXFont font = text->GetFont(buffer_, cursor.par(),
875 int const width = tmpinset->width(bv_, font);
876 int const inset_x = font.isVisibleRightToLeft()
877 ? cursor.x() : cursor.x() - width;
878 int const start_x = inset_x + tmpinset->scroll();
879 int const end_x = inset_x + width;
881 if (x > start_x && x < end_x
882 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
883 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
885 if (move_cursor && (tmpinset != bv_->theLockingInset()))
887 text->SetCursor(bv_, cursor.par(),
888 cursor.pos() - 1, true);
890 // The origin of an inset is on the baseline
891 y = y_tmp - (text->cursor.y());
899 void BufferView::Pimpl::workAreaExpose()
901 static int work_area_width;
902 static unsigned int work_area_height;
904 bool const widthChange = workarea_.workWidth() != work_area_width;
905 bool const heightChange = workarea_.height() != work_area_height;
907 // update from work area
908 work_area_width = workarea_.workWidth();
909 work_area_height = workarea_.height();
912 // All buffers need a resize
915 // Remove all texts from the textcache
916 // This is not _really_ what we want to do. What
917 // we really want to do is to delete in textcache
918 // that does not have a BufferView with matching
919 // width, but as long as we have only one BufferView
920 // deleting all gives the same result.
921 if (lyxerr.debugging())
922 textcache.show(lyxerr, "Expose delete all");
924 } else if (heightChange) {
925 // Rebuild image of current screen
927 // fitCursor() ensures we don't jump back
928 // to the start of the document on vertical
930 fitCursor(bv_->text);
932 // The main window size has changed, repaint most stuff
934 } else if (screen_.get())
935 screen_->Redraw(bv_->text, bv_);
937 // Grey box when we don't have a buffer
941 // always make sure that the scrollbar is sane.
943 owner_->updateLayoutChoice();
948 void BufferView::Pimpl::update()
951 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
953 screen_->Update(bv_->text, bv_);
957 // Values used when calling update:
959 // -2 - update, move sel_cursor if selection, fitcursor
960 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
961 // 0 - update, move sel_cursor if selection, fitcursor
962 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
963 // 3 - update, move sel_cursor if selection
966 // a simple redraw of the parts that need refresh
968 // move sel_cursor if selection -
969 // the text's sel_cursor is moved if there is selection is progress
972 // fitCursor() is called and the scrollbar updated
975 // the buffer is marked dirty.
984 // UPDATE_ONLY = UPDATE;
985 // UPDATE_SELECT = UPDATE | SELECT;
986 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
987 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
989 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
990 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
991 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
992 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
993 // update(3) -> update(1) -> update(1) -> update(SELECT)
995 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
997 owner_->updateLayoutChoice();
999 if (!text->selection.set() && (f & SELECT)) {
1000 text->selection.cursor = text->cursor;
1003 text->FullRebreak(bv_);
1005 if (text->inset_owner) {
1006 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
1007 updateInset(text->inset_owner, true);
1016 buffer_->markDirty();
1021 // Callback for cursor timer
1022 void BufferView::Pimpl::cursorToggle()
1024 // Quite a nice place for asyncron Inset updating, isn't it?
1025 // Actually no! This is run even if no buffer exist... so (Lgb)
1027 cursor_timeout.restart();
1032 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1033 if (pid == -1) // error find out what is wrong
1034 ; // ignore it for now.
1036 sigchldhandler(pid, &status);
1038 updatelist.update(bv_);
1040 if (!screen_.get()) {
1041 cursor_timeout.restart();
1045 if (!bv_->theLockingInset()) {
1046 screen_->CursorToggle(bv_->text, bv_);
1048 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1051 cursor_timeout.restart();
1055 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1057 if (!text->cursor.row()->previous())
1060 int y = text->first;
1061 if (text->inset_owner)
1062 y += bv_->text->first;
1063 Row * cursorrow = text->cursor.row();
1064 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1065 bv_->text->FinishUndo();
1066 // This is to allow jumping over large insets
1067 if ((cursorrow == text->cursor.row()))
1068 text->CursorUp(bv_);
1070 if (text->inset_owner ||
1071 text->cursor.row()->height() < workarea_.height())
1072 screen_->Draw(bv_->text, bv_,
1074 - text->cursor.row()->baseline()
1075 + text->cursor.row()->height()
1076 - workarea_.height() + 1 );
1081 void BufferView::Pimpl::cursorNext(LyXText * text)
1083 if (!text->cursor.row()->next())
1086 int y = text->first + workarea_.height();
1087 // if (text->inset_owner)
1088 // y += bv_->text->first;
1089 text->GetRowNearY(y);
1091 Row * cursorrow = text->cursor.row();
1092 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1093 bv_->text->FinishUndo();
1094 // This is to allow jumping over large insets
1095 if ((cursorrow == bv_->text->cursor.row()))
1096 text->CursorDown(bv_);
1098 if (text->inset_owner ||
1099 text->cursor.row()->height() < workarea_.height())
1100 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1101 text->cursor.row()->baseline());
1106 bool BufferView::Pimpl::available() const
1108 if (buffer_ && bv_->text) return true;
1113 void BufferView::Pimpl::beforeChange(LyXText * text)
1116 text->ClearSelection(bv_);
1120 void BufferView::Pimpl::savePosition(unsigned int i)
1122 if (i >= saved_positions_num)
1124 saved_positions[i] = Position(buffer_->fileName(),
1125 bv_->text->cursor.par()->id(),
1126 bv_->text->cursor.pos());
1129 str << _("Saved bookmark") << ' ' << i;
1130 owner_->message(str.str().c_str());
1135 void BufferView::Pimpl::restorePosition(unsigned int i)
1137 if (i >= saved_positions_num)
1140 string const fname = saved_positions[i].filename;
1142 beforeChange(bv_->text);
1144 if (fname != buffer_->fileName()) {
1145 Buffer * b = bufferlist.exists(fname) ?
1146 bufferlist.getBuffer(fname) :
1147 bufferlist.loadLyXFile(fname); // don't ask, just load it
1148 if (b != 0 ) buffer(b);
1151 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1155 bv_->text->SetCursor(bv_, par,
1156 min(par->size(), saved_positions[i].par_pos));
1158 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1161 str << _("Moved to bookmark") << ' ' << i;
1162 owner_->message(str.str().c_str());
1167 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1169 if (i >= saved_positions_num)
1172 return !saved_positions[i].filename.empty();
1176 void BufferView::Pimpl::setState()
1178 if (!lyxrc.rtl_support)
1181 LyXText * text = bv_->getLyXText();
1182 if (text->real_current_font.isRightToLeft() &&
1183 text->real_current_font.latex() != LyXFont::ON) {
1184 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1185 owner_->getIntl()->KeyMapSec();
1187 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1188 owner_->getIntl()->KeyMapPrim();
1193 void BufferView::Pimpl::insetSleep()
1195 if (bv_->theLockingInset() && !inset_slept) {
1196 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1197 bv_->theLockingInset()->InsetUnlock(bv_);
1203 void BufferView::Pimpl::insetWakeup()
1205 if (bv_->theLockingInset() && inset_slept) {
1206 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1207 inset_slept = false;
1212 void BufferView::Pimpl::insetUnlock()
1214 if (bv_->theLockingInset()) {
1216 bv_->theLockingInset()->InsetUnlock(bv_);
1217 bv_->theLockingInset(0);
1218 bv_->text->FinishUndo();
1219 inset_slept = false;
1224 bool BufferView::Pimpl::focus() const
1226 return workarea_.hasFocus();
1230 void BufferView::Pimpl::focus(bool f)
1232 if (f) workarea_.setFocus();
1236 bool BufferView::Pimpl::active() const
1238 return workarea_.active();
1242 bool BufferView::Pimpl::belowMouse() const
1244 return workarea_.belowMouse();
1248 void BufferView::Pimpl::showCursor()
1251 screen_->ShowCursor(bv_->text, bv_);
1255 void BufferView::Pimpl::hideCursor()
1258 screen_->HideCursor();
1262 void BufferView::Pimpl::toggleSelection(bool b)
1265 screen_->ToggleSelection(bv_->text, bv_, b);
1269 void BufferView::Pimpl::toggleToggle()
1272 screen_->ToggleToggle(bv_->text, bv_);
1276 void BufferView::Pimpl::center()
1278 beforeChange(bv_->text);
1279 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1280 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1282 screen_->Draw(bv_->text, bv_, 0);
1284 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1289 void BufferView::Pimpl::pasteClipboard(bool asPara)
1291 if (!buffer_) return;
1293 screen_->HideCursor();
1294 beforeChange(bv_->text);
1296 string const clip(workarea_.getClipboard());
1298 if (clip.empty()) return;
1301 bv_->text->InsertStringB(bv_, clip);
1303 bv_->text->InsertStringA(bv_, clip);
1305 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1309 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1311 workarea_.putClipboard(stuff);
1316 * Dispatch functions for actions which can be valid for BufferView->text
1317 * and/or InsetText->text!!!
1322 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1324 LyXText * lt = bv_->getLyXText();
1326 if (selecting || lt->selection.mark()) {
1327 lt->SetSelection(bv_);
1331 update(lt, BufferView::SELECT|BufferView::FITCUR);
1334 /* ---> Everytime the cursor is moved, show the current font state. */
1335 // should this too me moved out of this func?
1336 //owner->showState();
1341 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1343 LyXCursor cursor = bv_->getLyXText()->cursor;
1344 Buffer::inset_iterator it =
1345 find_if(Buffer::inset_iterator(
1346 cursor.par(), cursor.pos()),
1347 buffer_->inset_iterator_end(),
1348 lyx::compare_memfun(&Inset::LyxCode, code));
1349 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1353 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1355 string filename = filen;
1357 if (filename.empty()) {
1358 // Launch a file browser
1359 string initpath = lyxrc.document_path;
1362 string const trypath = owner_->buffer()->filepath;
1363 // If directory is writeable, use this as default.
1364 if (IsDirWriteable(trypath) == 1)
1368 FileDialog fileDlg(bv_->owner(),
1369 _("Select LyX document to insert"),
1371 make_pair(string(_("Documents")),
1372 string(lyxrc.document_path)),
1373 make_pair(string(_("Examples")),
1374 string(AddPath(system_lyxdir, "examples"))));
1376 FileDialog::Result result =
1377 fileDlg.Select(initpath,
1378 _("*.lyx| LyX Documents (*.lyx)"));
1380 if (result.first == FileDialog::Later)
1383 filename = result.second;
1385 // check selected filename
1386 if (filename.empty()) {
1387 owner_->message(_("Canceled."));
1392 // get absolute path of file and make sure the filename ends
1394 filename = MakeAbsPath(filename);
1395 if (!IsLyXFilename(filename))
1398 string const disp_fn(MakeDisplayPath(filename));
1402 s1 << _("Inserting document") << ' '
1403 << disp_fn << " ...";
1404 owner_->message(s1.str().c_str());
1405 bool const res = bv_->insertLyXFile(filename);
1408 str << _("Document") << ' ' << disp_fn
1409 << ' ' << _("inserted.");
1410 owner_->message(str.str().c_str());
1413 str << _("Could not insert document") << ' '
1415 owner_->message(str.str().c_str());
1420 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1423 // --- Misc -------------------------------------------
1427 LyXText * lt = bv_->getLyXText();
1428 lt->toggleAppendix(bv_);
1431 | BufferView::FITCUR
1432 | BufferView::CHANGE);
1437 case LFUN_TOC_INSERT:
1439 InsetCommandParams p;
1440 p.setCmdName("tableofcontents");
1441 Inset * inset = new InsetTOC(p);
1442 if (!insertInset(inset, "Standard"))
1447 case LFUN_TABULAR_FEATURE:
1448 case LFUN_SCROLL_INSET:
1449 // this is not handled here as this funktion is only aktive
1450 // if we have a locking_inset and that one is (or contains)
1454 case LFUN_INSET_GRAPHICS:
1456 Inset * new_inset = new InsetGraphics;
1457 if (!insertInset(new_inset)) {
1460 // this is need because you don't use a inset->Edit()
1461 updateInset(new_inset, true);
1462 new_inset->Edit(bv_, 0, 0, 0);
1472 case LFUN_PASTESELECTION:
1474 bool asPara = false;
1475 if (argument == "paragraph") asPara = true;
1476 pasteClipboard(asPara);
1488 case LFUN_LAYOUT_COPY:
1489 bv_->copyEnvironment();
1492 case LFUN_LAYOUT_PASTE:
1493 bv_->pasteEnvironment();
1497 case LFUN_GOTOERROR:
1498 gotoInset(Inset::ERROR_CODE, false);
1502 gotoInset(Inset::IGNORE_CODE, false);
1505 case LFUN_REFERENCE_GOTO:
1507 vector<Inset::Code> tmp;
1508 tmp.push_back(Inset::LABEL_CODE);
1509 tmp.push_back(Inset::REF_CODE);
1510 gotoInset(tmp, true);
1514 case LFUN_HYPHENATION:
1522 case LFUN_END_OF_SENTENCE:
1526 case LFUN_MENU_SEPARATOR:
1535 changeDepth(bv_, bv_->getLyXText(), 0);
1538 case LFUN_DEPTH_MIN:
1539 changeDepth(bv_, bv_->getLyXText(), -1);
1542 case LFUN_DEPTH_PLUS:
1543 changeDepth(bv_, bv_->getLyXText(), 1);
1547 owner_->getDialogs()->setUserFreeFont();
1553 owner_->showState();
1556 case LFUN_FILE_INSERT:
1558 MenuInsertLyXFile(argument);
1562 case LFUN_FILE_INSERT_ASCII_PARA:
1563 InsertAsciiFile(bv_, argument, true);
1566 case LFUN_FILE_INSERT_ASCII:
1567 InsertAsciiFile(bv_, argument, false);
1572 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1573 << argument << endl;
1575 // Derive layout number from given argument (string)
1576 // and current buffer's textclass (number). */
1577 LyXTextClassList::ClassList::size_type tclass =
1578 buffer_->params.textclass;
1579 pair <bool, LyXTextClass::size_type> layout =
1580 textclasslist.NumberOfLayout(tclass, argument);
1582 // If the entry is obsolete, use the new one instead.
1584 string obs = textclasslist.Style(tclass,layout.second)
1588 textclasslist.NumberOfLayout(tclass, obs);
1591 // see if we found the layout number:
1592 if (!layout.first) {
1593 owner_->getLyXFunc()->setErrorMessage(
1594 string(N_("Layout ")) + argument +
1599 if (current_layout != layout.second) {
1600 LyXText * lt = bv_->getLyXText();
1602 current_layout = layout.second;
1605 | BufferView::FITCUR);
1606 lt->SetLayout(bv_, layout.second);
1607 owner_->setLayout(layout.second);
1610 | BufferView::FITCUR
1611 | BufferView::CHANGE);
1618 Lang(bv_, argument);
1620 owner_->showState();
1625 owner_->showState();
1630 owner_->showState();
1635 owner_->showState();
1640 owner_->showState();
1645 owner_->showState();
1650 owner_->showState();
1655 owner_->showState();
1658 case LFUN_UNDERLINE:
1660 owner_->showState();
1663 case LFUN_FONT_SIZE:
1664 FontSize(bv_, argument);
1665 owner_->showState();
1668 case LFUN_FONT_STATE:
1669 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1672 case LFUN_UPCASE_WORD:
1674 LyXText * lt = bv_->getLyXText();
1678 | BufferView::FITCUR);
1679 lt->ChangeWordCase(bv_, LyXText::text_uppercase);
1680 if (lt->inset_owner)
1681 updateInset(lt->inset_owner, true);
1684 | BufferView::FITCUR
1685 | BufferView::CHANGE);
1689 case LFUN_LOWCASE_WORD:
1691 LyXText * lt = bv_->getLyXText();
1693 update(lt, BufferView::SELECT|BufferView::FITCUR);
1694 lt->ChangeWordCase(bv_, LyXText::text_lowercase);
1695 if (lt->inset_owner)
1696 updateInset(lt->inset_owner, true);
1699 | BufferView::FITCUR
1700 | BufferView::CHANGE);
1704 case LFUN_CAPITALIZE_WORD:
1706 LyXText * lt = bv_->getLyXText();
1708 update(lt, BufferView::SELECT|BufferView::FITCUR);
1709 lt->ChangeWordCase(bv_,
1710 LyXText::text_capitalization);
1711 if (lt->inset_owner)
1712 updateInset(lt->inset_owner, true);
1715 | BufferView::FITCUR
1716 | BufferView::CHANGE);
1720 case LFUN_TRANSPOSE_CHARS:
1722 LyXText * lt = bv_->getLyXText();
1724 update(lt, BufferView::SELECT|BufferView::FITCUR);
1725 lt->TransposeChars(*bv_);
1726 if (lt->inset_owner)
1727 updateInset(lt->inset_owner, true);
1730 | BufferView::FITCUR
1731 | BufferView::CHANGE);
1736 case LFUN_INSERT_LABEL:
1737 MenuInsertLabel(bv_, argument);
1740 case LFUN_REF_INSERT:
1741 if (argument.empty()) {
1742 InsetCommandParams p("ref");
1743 owner_->getDialogs()->createRef(p.getAsString());
1745 InsetCommandParams p;
1746 p.setFromString(argument);
1748 InsetRef * inset = new InsetRef(p, *buffer_);
1749 if (!insertInset(inset))
1752 updateInset(inset, true);
1756 case LFUN_BOOKMARK_SAVE:
1757 savePosition(strToUnsignedInt(argument));
1760 case LFUN_BOOKMARK_GOTO:
1761 restorePosition(strToUnsignedInt(argument));
1766 string label(argument);
1767 if (label.empty()) {
1769 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1771 label = inset->getContents();
1776 if (!label.empty()) {
1777 //bv_->savePosition(0);
1778 if (!bv_->gotoLabel(label))
1779 WriteAlert(_("Error"),
1780 _("Couldn't find this label"),
1781 _("in current document."));
1786 // --- Cursor Movements -----------------------------
1789 LyXText * lt = bv_->getLyXText();
1791 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1792 if (!lt->selection.mark())
1794 update(lt, BufferView::SELECT|BufferView::FITCUR);
1796 lt->CursorLeft(bv_, false);
1797 if (lt->cursor.pos() < lt->cursor.par()->size()
1798 && lt->cursor.par()->GetChar(lt->cursor.pos())
1799 == LyXParagraph::META_INSET
1800 && lt->cursor.par()->GetInset(lt->cursor.pos())
1801 && lt->cursor.par()->GetInset(lt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1802 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1803 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1806 LyXFont const font =
1807 lt->GetFont(buffer_,
1810 y = tmpinset->descent(bv_,font);
1812 tmpinset->Edit(bv_, 0, y, 0);
1816 lt->CursorRight(bv_, false);
1818 moveCursorUpdate(false);
1819 owner_->showState();
1825 // This is soooo ugly. Isn`t it possible to make
1826 // it simpler? (Lgb)
1827 LyXText * lt = bv_->getLyXText();
1828 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1829 if (!lt->selection.mark())
1831 update(lt, BufferView::SELECT|BufferView::FITCUR);
1832 LyXCursor const cur = lt->cursor;
1834 lt->CursorLeft(bv_, false);
1835 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1836 lt->cursor.pos() < lt->cursor.par()->size() &&
1837 (lt->cursor.par()->GetChar(lt->cursor.pos()) ==
1838 LyXParagraph::META_INSET) &&
1839 lt->cursor.par()->GetInset(lt->cursor.pos()) &&
1840 (lt->cursor.par()->GetInset(lt->cursor.pos())->Editable()
1841 == Inset::HIGHLY_EDITABLE))
1843 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1844 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1845 LyXFont const font = lt->GetFont(buffer_,
1849 : tmpinset->descent(bv_,font);
1852 tmpinset->width(bv_,font),
1857 lt->CursorRight(bv_, false);
1860 moveCursorUpdate(false);
1861 owner_->showState();
1867 LyXText * lt = bv_->getLyXText();
1869 if (!lt->selection.mark())
1871 update(lt, BufferView::UPDATE);
1874 moveCursorUpdate(false);
1875 owner_->showState();
1881 LyXText * lt = bv_->getLyXText();
1883 if (!lt->selection.mark())
1885 update(lt, BufferView::UPDATE);
1886 lt->CursorDown(bv_);
1888 moveCursorUpdate(false);
1889 owner_->showState();
1893 case LFUN_UP_PARAGRAPH:
1895 LyXText * lt = bv_->getLyXText();
1897 if (!lt->selection.mark())
1899 update(lt, BufferView::UPDATE);
1900 lt->CursorUpParagraph(bv_);
1902 moveCursorUpdate(false);
1903 owner_->showState();
1907 case LFUN_DOWN_PARAGRAPH:
1909 LyXText * lt = bv_->getLyXText();
1911 if (!lt->selection.mark())
1913 update(lt, BufferView::UPDATE);
1914 lt->CursorDownParagraph(bv_);
1916 moveCursorUpdate(false);
1917 owner_->showState();
1923 LyXText * lt = bv_->getLyXText();
1925 if (!lt->selection.mark())
1927 update(lt, BufferView::UPDATE);
1930 moveCursorUpdate(false);
1931 owner_->showState();
1937 LyXText * lt = bv_->getLyXText();
1939 if (!lt->selection.mark())
1941 update(lt, BufferView::UPDATE);
1944 moveCursorUpdate(false);
1945 owner_->showState();
1951 LyXText * lt = bv_->getLyXText();
1953 if (!lt->selection.mark())
1955 update(lt, BufferView::SELECT|BufferView::FITCUR);
1956 lt->CursorHome(bv_);
1958 moveCursorUpdate(false);
1959 owner_->showState();
1965 LyXText * lt = bv_->getLyXText();
1967 if (!lt->selection.mark())
1970 BufferView::SELECT|BufferView::FITCUR);
1973 moveCursorUpdate(false);
1974 owner_->showState();
1978 case LFUN_SHIFT_TAB:
1981 LyXText * lt = bv_->getLyXText();
1983 if (!lt->selection.mark())
1986 BufferView::SELECT|BufferView::FITCUR);
1989 moveCursorUpdate(false);
1990 owner_->showState();
1994 case LFUN_WORDRIGHT:
1996 LyXText * lt = bv_->getLyXText();
1998 if (!lt->selection.mark())
2000 update(lt, BufferView::SELECT|BufferView::FITCUR);
2001 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2002 lt->CursorLeftOneWord(bv_);
2004 lt->CursorRightOneWord(bv_);
2006 moveCursorUpdate(false);
2007 owner_->showState();
2013 LyXText * lt = bv_->getLyXText();
2015 if (!lt->selection.mark())
2017 update(lt, BufferView::SELECT|BufferView::FITCUR);
2018 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2019 lt->CursorRightOneWord(bv_);
2021 lt->CursorLeftOneWord(bv_);
2023 moveCursorUpdate(false);
2024 owner_->showState();
2028 case LFUN_BEGINNINGBUF:
2030 LyXText * lt = bv_->getLyXText();
2032 if (!lt->selection.mark())
2035 BufferView::SELECT|BufferView::FITCUR);
2038 moveCursorUpdate(false);
2039 owner_->showState();
2045 LyXText * lt = bv_->getLyXText();
2047 if (!lt->selection.mark())
2050 BufferView::SELECT|BufferView::FITCUR);
2051 lt->CursorBottom(bv_);
2053 moveCursorUpdate(false);
2054 owner_->showState();
2058 /* cursor selection ---------------------------- */
2061 LyXText * lt = bv_->getLyXText();
2064 BufferView::SELECT|BufferView::FITCUR);
2065 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2066 lt->CursorLeft(bv_);
2068 lt->CursorRight(bv_);
2070 moveCursorUpdate(true);
2071 owner_->showState();
2077 LyXText * lt = bv_->getLyXText();
2080 BufferView::SELECT|BufferView::FITCUR);
2081 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2082 lt->CursorRight(bv_);
2084 lt->CursorLeft(bv_);
2086 moveCursorUpdate(true);
2087 owner_->showState();
2093 LyXText * lt = bv_->getLyXText();
2096 BufferView::SELECT|BufferView::FITCUR);
2099 moveCursorUpdate(true);
2100 owner_->showState();
2106 LyXText * lt = bv_->getLyXText();
2109 BufferView::SELECT|BufferView::FITCUR);
2110 lt->CursorDown(bv_);
2112 moveCursorUpdate(true);
2113 owner_->showState();
2117 case LFUN_UP_PARAGRAPHSEL:
2119 LyXText * lt = bv_->getLyXText();
2122 BufferView::SELECT|BufferView::FITCUR);
2123 lt->CursorUpParagraph(bv_);
2125 moveCursorUpdate(true);
2126 owner_->showState();
2130 case LFUN_DOWN_PARAGRAPHSEL:
2132 LyXText * lt = bv_->getLyXText();
2135 BufferView::SELECT|BufferView::FITCUR);
2136 lt->CursorDownParagraph(bv_);
2138 moveCursorUpdate(true);
2139 owner_->showState();
2145 LyXText * lt = bv_->getLyXText();
2147 update(lt, BufferView::SELECT|BufferView::FITCUR);
2150 moveCursorUpdate(true);
2151 owner_->showState();
2157 LyXText * lt = bv_->getLyXText();
2159 update(lt, BufferView::SELECT|BufferView::FITCUR);
2162 moveCursorUpdate(true);
2163 owner_->showState();
2169 LyXText * lt = bv_->getLyXText();
2171 update(lt, BufferView::SELECT|BufferView::FITCUR);
2172 lt->CursorHome(bv_);
2174 moveCursorUpdate(true);
2175 owner_->showState();
2181 LyXText * lt = bv_->getLyXText();
2183 update(lt, BufferView::SELECT|BufferView::FITCUR);
2186 moveCursorUpdate(true);
2187 owner_->showState();
2191 case LFUN_WORDRIGHTSEL:
2193 LyXText * lt = bv_->getLyXText();
2195 update(lt, BufferView::SELECT|BufferView::FITCUR);
2196 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2197 lt->CursorLeftOneWord(bv_);
2199 lt->CursorRightOneWord(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2206 case LFUN_WORDLEFTSEL:
2208 LyXText * lt = bv_->getLyXText();
2210 update(lt, BufferView::SELECT|BufferView::FITCUR);
2211 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2212 lt->CursorRightOneWord(bv_);
2214 lt->CursorLeftOneWord(bv_);
2216 moveCursorUpdate(true);
2217 owner_->showState();
2221 case LFUN_BEGINNINGBUFSEL:
2223 LyXText * lt = bv_->getLyXText();
2225 if (lt->inset_owner)
2227 update(lt, BufferView::SELECT|BufferView::FITCUR);
2230 moveCursorUpdate(true);
2231 owner_->showState();
2235 case LFUN_ENDBUFSEL:
2237 LyXText * lt = bv_->getLyXText();
2239 if (lt->inset_owner)
2242 BufferView::SELECT|BufferView::FITCUR);
2243 lt->CursorBottom(bv_);
2245 moveCursorUpdate(true);
2246 owner_->showState();
2250 // --- text changing commands ------------------------
2251 case LFUN_BREAKLINE:
2253 LyXText * lt = bv_->getLyXText();
2256 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2259 | BufferView::FITCUR
2260 | BufferView::CHANGE);
2261 moveCursorUpdate(false);
2265 case LFUN_PROTECTEDSPACE:
2267 LyXText * lt = bv_->getLyXText();
2269 LyXLayout const & style = textclasslist
2270 .Style(buffer_->params.textclass,
2271 lt->cursor.par()->GetLayout());
2273 if (style.free_spacing) {
2274 lt->InsertChar(bv_, ' ');
2277 | BufferView::FITCUR
2278 | BufferView::CHANGE);
2282 moveCursorUpdate(false);
2288 LyXText * lt = bv_->getLyXText();
2290 if (lt->selection.mark()) {
2294 | BufferView::FITCUR);
2295 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2298 lt->selection.mark(true);
2301 | BufferView::FITCUR);
2302 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2304 lt->selection.cursor = lt->cursor;
2310 LyXText * lt = bv_->getLyXText();
2312 if (!lt->selection.set()) {
2314 lt->selection.cursor = lt->cursor;
2317 | BufferView::FITCUR
2318 | BufferView::CHANGE);
2319 // It is possible to make it a lot faster still
2320 // just comment out the line below...
2325 moveCursorUpdate(false);
2326 owner_->showState();
2331 case LFUN_DELETE_SKIP:
2333 LyXText * lt = bv_->getLyXText();
2335 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2337 LyXCursor cursor = lt->cursor;
2339 if (!lt->selection.set()) {
2340 if (cursor.pos() == cursor.par()->size()) {
2341 lt->CursorRight(bv_);
2342 cursor = lt->cursor;
2343 if (cursor.pos() == 0
2344 && !(cursor.par()->params.spaceTop()
2345 == VSpace (VSpace::NONE))) {
2348 cursor.par()->params.lineTop(),
2349 cursor.par()->params.lineBottom(),
2350 cursor.par()->params.pagebreakTop(),
2351 cursor.par()->params.pagebreakBottom(),
2352 VSpace(VSpace::NONE),
2353 cursor.par()->params.spaceBottom(),
2354 cursor.par()->params.align(),
2355 cursor.par()->params.labelWidthString(), 0);
2356 lt->CursorLeft(bv_);
2359 | BufferView::FITCUR
2360 | BufferView::CHANGE);
2362 lt->CursorLeft(bv_);
2364 lt->selection.cursor = lt->cursor;
2367 | BufferView::FITCUR
2368 | BufferView::CHANGE);
2372 lt->selection.cursor = lt->cursor;
2375 | BufferView::FITCUR
2376 | BufferView::CHANGE);
2384 /* -------> Delete word forward. */
2385 case LFUN_DELETE_WORD_FORWARD:
2386 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2387 bv_->getLyXText()->DeleteWordForward(bv_);
2388 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2389 moveCursorUpdate(false);
2390 owner_->showState();
2393 /* -------> Delete word backward. */
2394 case LFUN_DELETE_WORD_BACKWARD:
2396 LyXText * lt = bv_->getLyXText();
2398 update(lt, BufferView::SELECT|BufferView::FITCUR);
2399 lt->DeleteWordBackward(bv_);
2402 | BufferView::FITCUR
2403 | BufferView::CHANGE);
2404 moveCursorUpdate(false);
2405 owner_->showState();
2409 /* -------> Kill to end of line. */
2410 case LFUN_DELETE_LINE_FORWARD:
2412 LyXText * lt = bv_->getLyXText();
2414 update(lt, BufferView::SELECT|BufferView::FITCUR);
2415 lt->DeleteLineForward(bv_);
2418 | BufferView::FITCUR
2419 | BufferView::CHANGE);
2420 moveCursorUpdate(false);
2424 /* -------> Set mark off. */
2427 LyXText * lt = bv_->getLyXText();
2430 update(lt, BufferView::SELECT|BufferView::FITCUR);
2431 lt->selection.cursor = lt->cursor;
2432 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2436 /* -------> Set mark on. */
2439 LyXText * lt = bv_->getLyXText();
2442 lt->selection.mark(true);
2443 update(lt, BufferView::SELECT|BufferView::FITCUR);
2444 lt->selection.cursor = lt->cursor;
2445 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2449 case LFUN_BACKSPACE:
2451 LyXText * lt = bv_->getLyXText();
2453 if (!lt->selection.set()) {
2454 if (owner_->getIntl()->getTrans().backspace()) {
2456 lt->selection.cursor = lt->cursor;
2459 | BufferView::FITCUR
2460 | BufferView::CHANGE);
2461 // It is possible to make it a lot faster still
2462 // just comment out the line below...
2468 owner_->showState();
2473 case LFUN_BACKSPACE_SKIP:
2475 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2476 LyXText * lt = bv_->getLyXText();
2478 LyXCursor cursor = lt->cursor;
2480 if (!lt->selection.set()) {
2481 if (cursor.pos() == 0
2482 && !(cursor.par()->params.spaceTop()
2483 == VSpace (VSpace::NONE))) {
2486 cursor.par()->params.lineTop(),
2487 cursor.par()->params.lineBottom(),
2488 cursor.par()->params.pagebreakTop(),
2489 cursor.par()->params.pagebreakBottom(),
2490 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2491 cursor.par()->params.align(),
2492 cursor.par()->params.labelWidthString(), 0);
2495 | BufferView::FITCUR
2496 | BufferView::CHANGE);
2499 lt->selection.cursor = cursor;
2502 | BufferView::FITCUR
2503 | BufferView::CHANGE);
2510 case LFUN_BREAKPARAGRAPH:
2512 LyXText * lt = bv_->getLyXText();
2515 lt->BreakParagraph(bv_, 0);
2518 | BufferView::FITCUR
2519 | BufferView::CHANGE);
2520 lt->selection.cursor = lt->cursor;
2522 owner_->showState();
2526 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2528 LyXText * lt = bv_->getLyXText();
2531 lt->BreakParagraph(bv_, 1);
2534 | BufferView::FITCUR
2535 | BufferView::CHANGE);
2536 lt->selection.cursor = lt->cursor;
2538 owner_->showState();
2542 case LFUN_BREAKPARAGRAPH_SKIP:
2544 // When at the beginning of a paragraph, remove
2545 // indentation and add a "defskip" at the top.
2546 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2547 LyXText * lt = bv_->getLyXText();
2549 LyXCursor cursor = lt->cursor;
2552 if (cursor.pos() == 0) {
2553 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2556 cursor.par()->params.lineTop(),
2557 cursor.par()->params.lineBottom(),
2558 cursor.par()->params.pagebreakTop(),
2559 cursor.par()->params.pagebreakBottom(),
2560 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2561 cursor.par()->params.align(),
2562 cursor.par()->params.labelWidthString(), 1);
2563 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2567 lt->BreakParagraph(bv_, 0);
2568 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2573 | BufferView::FITCUR
2574 | BufferView::CHANGE);
2575 lt->selection.cursor = cursor;
2577 owner_->showState();
2581 case LFUN_PARAGRAPH_SPACING:
2583 LyXText * lt = bv_->getLyXText();
2585 LyXParagraph * par = lt->cursor.par();
2586 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2587 float cur_value = 1.0;
2588 if (cur_spacing == Spacing::Other) {
2589 cur_value = par->params.spacing().getValue();
2592 istringstream istr(argument.c_str());
2596 Spacing::Space new_spacing = cur_spacing;
2597 float new_value = cur_value;
2599 lyxerr << "Missing argument to `paragraph-spacing'"
2601 } else if (tmp == "single") {
2602 new_spacing = Spacing::Single;
2603 } else if (tmp == "onehalf") {
2604 new_spacing = Spacing::Onehalf;
2605 } else if (tmp == "double") {
2606 new_spacing = Spacing::Double;
2607 } else if (tmp == "other") {
2608 new_spacing = Spacing::Other;
2611 lyxerr << "new_value = " << tmpval << endl;
2614 } else if (tmp == "default") {
2615 new_spacing = Spacing::Default;
2617 lyxerr << _("Unknown spacing argument: ")
2618 << argument << endl;
2620 if (cur_spacing != new_spacing || cur_value != new_value) {
2621 par->params.spacing(Spacing(new_spacing, new_value));
2622 lt->RedoParagraph(bv_);
2625 | BufferView::FITCUR
2626 | BufferView::CHANGE);
2632 bv_->insertCorrectQuote();
2638 InsetCommandParams p;
2639 if (action == LFUN_HTMLURL)
2640 p.setCmdName("htmlurl");
2642 p.setCmdName("url");
2643 owner_->getDialogs()->createUrl( p.getAsString() );
2647 case LFUN_INSERT_URL:
2649 InsetCommandParams p;
2650 p.setFromString( argument );
2652 InsetUrl * inset = new InsetUrl( p );
2653 if (!insertInset(inset))
2656 updateInset( inset, true );
2660 case LFUN_INSET_TEXT:
2662 InsetText * new_inset = new InsetText;
2663 if (insertInset(new_inset))
2664 new_inset->Edit(bv_, 0, 0, 0);
2670 case LFUN_INSET_ERT:
2672 InsetERT * new_inset = new InsetERT;
2673 if (insertInset(new_inset))
2674 new_inset->Edit(bv_, 0, 0, 0);
2680 case LFUN_INSET_EXTERNAL:
2682 InsetExternal * new_inset = new InsetExternal;
2683 if (insertInset(new_inset))
2684 new_inset->Edit(bv_, 0, 0, 0);
2690 case LFUN_INSET_FOOTNOTE:
2692 InsetFoot * new_inset = new InsetFoot;
2693 if (insertInset(new_inset))
2694 new_inset->Edit(bv_, 0, 0, 0);
2700 case LFUN_INSET_MARGINAL:
2702 InsetMarginal * new_inset = new InsetMarginal;
2703 if (insertInset(new_inset))
2704 new_inset->Edit(bv_, 0, 0, 0);
2710 case LFUN_INSET_MINIPAGE:
2712 InsetMinipage * new_inset = new InsetMinipage;
2713 if (insertInset(new_inset))
2714 new_inset->Edit(bv_, 0, 0, 0);
2720 case LFUN_INSET_FLOAT:
2722 // check if the float type exist
2723 if (floatList.typeExist(argument)) {
2724 InsetFloat * new_inset = new InsetFloat(argument);
2725 if (insertInset(new_inset))
2726 new_inset->Edit(bv_, 0, 0, 0);
2730 lyxerr << "Non-existant float type: "
2731 << argument << endl;
2737 case LFUN_INSET_WIDE_FLOAT:
2739 // check if the float type exist
2740 if (floatList.typeExist(argument)) {
2741 InsetFloat * new_inset = new InsetFloat(argument);
2742 new_inset->wide(true);
2743 if (insertInset(new_inset))
2744 new_inset->Edit(bv_, 0, 0, 0);
2748 lyxerr << "Non-existant float type: "
2749 << argument << endl;
2755 case LFUN_INSET_LIST:
2757 InsetList * new_inset = new InsetList;
2758 if (insertInset(new_inset))
2759 new_inset->Edit(bv_, 0, 0, 0);
2765 case LFUN_INSET_THEOREM:
2767 InsetTheorem * new_inset = new InsetTheorem;
2768 if (insertInset(new_inset))
2769 new_inset->Edit(bv_, 0, 0, 0);
2775 case LFUN_INSET_CAPTION:
2777 // Do we have a locking inset...
2778 if (bv_->theLockingInset()) {
2779 lyxerr << "Locking inset code: "
2780 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2781 InsetCaption * new_inset = new InsetCaption;
2782 new_inset->setOwner(bv_->theLockingInset());
2783 new_inset->SetAutoBreakRows(true);
2784 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2785 new_inset->SetFrameColor(0, LColor::captionframe);
2786 if (insertInset(new_inset))
2787 new_inset->Edit(bv_, 0, 0, 0);
2794 case LFUN_INSET_TABULAR:
2798 if (!argument.empty())
2799 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2800 InsetTabular * new_inset =
2801 new InsetTabular(*buffer_, r, c);
2803 bv_->getLyXText()->real_current_font.isRightToLeft();
2804 if (!open_new_inset(new_inset, rtl))
2809 // --- lyxserver commands ----------------------------
2811 case LFUN_CHARATCURSOR:
2813 LyXParagraph::size_type pos = bv_->getLyXText()->cursor.pos();
2814 if (pos < bv_->getLyXText()->cursor.par()->size())
2815 owner_->getLyXFunc()->setMessage(
2816 tostr(bv_->getLyXText()->cursor.par()->GetChar(pos)));
2818 owner_->getLyXFunc()->setMessage("EOF");
2823 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2825 + tostr(bv_->getLyXText()->cursor.y()));
2830 #warning Should check sscanf for errors (Lgb)
2833 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2834 bv_->getLyXText()->SetCursorFromCoordinates(bv_, x, y);
2838 case LFUN_GETLAYOUT:
2839 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2844 LyXFont & font = bv_->getLyXText()->current_font;
2845 if (font.shape() == LyXFont::ITALIC_SHAPE)
2846 owner_->getLyXFunc()->setMessage("E");
2847 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2848 owner_->getLyXFunc()->setMessage("N");
2850 owner_->getLyXFunc()->setMessage("0");
2857 LyXFont & font = bv_->getLyXText()->current_font;
2858 if (font.latex() == LyXFont::ON)
2859 owner_->getLyXFunc()->setMessage("L");
2861 owner_->getLyXFunc()->setMessage("0");
2865 // --- accented characters ---------------------------
2868 case LFUN_CIRCUMFLEX:
2878 case LFUN_SPECIAL_CARON:
2881 case LFUN_HUNG_UMLAUT:
2884 if (argument.empty()) {
2886 owner_->getLyXFunc()->handleKeyFunc(action);
2888 owner_->getLyXFunc()->handleKeyFunc(action);
2889 owner_->getIntl()->getTrans()
2890 .TranslateAndInsert(argument[0], bv_->getLyXText());
2891 update(bv_->getLyXText(),
2893 | BufferView::FITCUR
2894 | BufferView::CHANGE);
2898 // --- insert characters ----------------------------------------
2900 case LFUN_MATH_DELIM:
2901 case LFUN_INSERT_MATRIX:
2904 if (open_new_inset(new InsetFormula(false))) {
2905 bv_->theLockingInset()
2906 ->LocalDispatch(bv_, action, argument);
2912 case LFUN_INSERT_MATH:
2917 InsetFormula * f = new InsetFormula(true);
2919 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2923 case LFUN_MATH_DISPLAY:
2926 open_new_inset(new InsetFormula(true));
2930 case LFUN_MATH_MACRO:
2935 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2937 string const s1 = token(s, ' ', 1);
2938 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2939 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2945 case LFUN_MATH_MODE: // Open or create a math inset
2948 open_new_inset(new InsetFormula);
2949 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2953 case LFUN_CITATION_INSERT:
2955 InsetCommandParams p;
2956 p.setFromString( argument );
2958 InsetCitation * inset = new InsetCitation( p );
2959 if (!insertInset(inset))
2962 updateInset( inset, true );
2966 case LFUN_INSERT_BIBTEX:
2968 // ale970405+lasgoutt970425
2969 // The argument can be up to two tokens separated
2970 // by a space. The first one is the bibstyle.
2971 string const db = token(argument, ' ', 0);
2972 string bibstyle = token(argument, ' ', 1);
2973 if (bibstyle.empty())
2976 InsetCommandParams p( "BibTeX", db, bibstyle );
2977 InsetBibtex * inset = new InsetBibtex(p);
2979 if (insertInset(inset)) {
2980 if (argument.empty())
2981 inset->Edit(bv_, 0, 0, 0);
2987 // BibTeX data bases
2988 case LFUN_BIBDB_ADD:
2990 InsetBibtex * inset =
2991 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2993 inset->addDatabase(argument);
2998 case LFUN_BIBDB_DEL:
3000 InsetBibtex * inset =
3001 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3003 inset->delDatabase(argument);
3008 case LFUN_BIBTEX_STYLE:
3010 InsetBibtex * inset =
3011 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3013 inset->setOptions(argument);
3018 case LFUN_INDEX_CREATE:
3020 InsetCommandParams p( "index" );
3022 if (argument.empty()) {
3023 // Get the word immediately preceding the cursor
3024 LyXParagraph::size_type curpos =
3025 bv_->getLyXText()->cursor.pos() - 1;
3029 curstring = bv_->getLyXText()
3030 ->cursor.par()->GetWord(curpos);
3032 p.setContents( curstring );
3034 p.setContents( argument );
3037 owner_->getDialogs()->createIndex( p.getAsString() );
3041 case LFUN_INDEX_INSERT:
3043 InsetCommandParams p;
3044 p.setFromString(argument);
3045 InsetIndex * inset = new InsetIndex(p);
3047 if (!insertInset(inset))
3050 updateInset(inset, true);
3054 case LFUN_INDEX_INSERT_LAST:
3056 // Get word immediately preceding the cursor
3057 LyXParagraph::size_type curpos =
3058 bv_->getLyXText()->cursor.pos() - 1;
3059 // Can't do that at the beginning of a paragraph
3060 if (curpos < 0) break;
3062 string const curstring(bv_->getLyXText()
3063 ->cursor.par()->GetWord(curpos));
3065 InsetCommandParams p("index", curstring);
3066 InsetIndex * inset = new InsetIndex(p);
3068 if (!insertInset(inset))
3071 updateInset(inset, true);
3075 case LFUN_INDEX_PRINT:
3077 InsetCommandParams p("printindex");
3078 Inset * inset = new InsetPrintIndex(p);
3079 if (!insertInset(inset, "Standard"))
3084 case LFUN_PARENTINSERT:
3086 lyxerr << "arg " << argument << endl;
3087 InsetCommandParams p( "lyxparent", argument );
3088 Inset * inset = new InsetParent(p, *buffer_);
3089 if (!insertInset(inset, "Standard"))
3095 case LFUN_CHILD_INSERT:
3097 InsetInclude::Params p;
3098 p.cparams.setFromString(argument);
3099 p.masterFilename_ = buffer_->fileName();
3101 InsetInclude * inset = new InsetInclude(p);
3102 if (!insertInset(inset))
3105 updateInset(inset, true);
3106 bv_->owner()->getDialogs()->showInclude(inset);
3111 case LFUN_FLOAT_LIST:
3113 // We should check the argument for validity. (Lgb)
3114 Inset * inset = new InsetFloatList(argument);
3115 if (!insertInset(inset, "Standard"))
3120 case LFUN_INSERT_NOTE:
3124 case LFUN_SELFINSERT:
3126 if (argument.empty()) break;
3128 /* Automatically delete the currently selected
3129 * text and replace it with what is being
3130 * typed in now. Depends on lyxrc settings
3131 * "auto_region_delete", which defaults to
3134 LyXText * lt = bv_->getLyXText();
3136 if (lyxrc.auto_region_delete) {
3137 if (lt->selection.set()) {
3138 lt->CutSelection(bv_, false);
3141 | BufferView::FITCUR
3142 | BufferView::CHANGE);
3146 bv_->beforeChange(lt);
3147 LyXFont const old_font(lt->real_current_font);
3149 string::const_iterator cit = argument.begin();
3150 string::const_iterator end = argument.end();
3151 for (; cit != end; ++cit) {
3152 if (greek_kb_flag) {
3153 if (!math_insert_greek(bv_, *cit))
3154 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3156 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3161 | BufferView::FITCUR
3162 | BufferView::CHANGE);
3164 lt->selection.cursor = lt->cursor;
3165 moveCursorUpdate(false);
3167 // real_current_font.number can change so we need to
3168 // update the minibuffer
3169 if (old_font != lt->real_current_font)
3170 owner_->showState();
3175 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3177 time_t now_time_t = time(NULL);
3178 struct tm * now_tm = localtime(&now_time_t);
3179 setlocale(LC_TIME, "");
3181 if (!argument.empty())
3184 arg = lyxrc.date_insert_format;
3186 int const datetmp_len =
3187 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3189 LyXText * lt = bv_->getLyXText();
3191 for (int i = 0; i < datetmp_len; i++) {
3192 lt->InsertChar(bv_, datetmp[i]);
3195 | BufferView::FITCUR
3196 | BufferView::CHANGE);
3199 lt->selection.cursor = lt->cursor;
3200 moveCursorUpdate(false);
3204 case LFUN_UNKNOWN_ACTION:
3205 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3216 void BufferView::Pimpl::newline()
3219 LyXText * lt = bv_->getLyXText();
3223 | BufferView::FITCUR);
3224 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
3227 | BufferView::FITCUR
3228 | BufferView::CHANGE);
3233 void BufferView::Pimpl::hfill()
3236 LyXText * lt = bv_->getLyXText();
3240 | BufferView::FITCUR);
3241 lt->InsertChar(bv_, LyXParagraph::META_HFILL);
3244 | BufferView::FITCUR
3245 | BufferView::CHANGE);
3250 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3254 update(lt, BufferView::SELECT|BufferView::FITCUR);
3255 InsetSpecialChar * new_inset =
3256 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3257 if (!insertInset(new_inset))
3260 updateInset(new_inset, true);
3265 void BufferView::Pimpl::menuSeparator()
3268 LyXText * lt = bv_->getLyXText();
3271 update(lt, BufferView::SELECT|BufferView::FITCUR);
3272 InsetSpecialChar * new_inset =
3273 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3274 insertInset(new_inset);
3279 void BufferView::Pimpl::endOfSentenceDot()
3283 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3284 InsetSpecialChar * new_inset =
3285 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3286 insertInset(new_inset);
3291 void BufferView::Pimpl::ldots()
3295 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3296 InsetSpecialChar * new_inset =
3297 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3298 insertInset(new_inset);
3303 void BufferView::Pimpl::hyphenationPoint()
3307 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3308 InsetSpecialChar * new_inset =
3309 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3310 insertInset(new_inset);
3315 void BufferView::Pimpl::insertNote()
3317 InsetInfo * new_inset = new InsetInfo();
3318 insertInset(new_inset);
3319 new_inset->Edit(bv_, 0, 0, 0);
3323 // Open and lock an updatable inset
3324 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3326 LyXText * lt = bv_->getLyXText();
3330 if (!insertInset(new_inset)) {
3335 LyXFont & font = lt->real_current_font;
3336 new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
3338 new_inset->Edit(bv_, 0, 0, 0);
3343 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3345 // if we are in a locking inset we should try to insert the
3346 // inset there otherwise this is a illegal function now
3347 if (bv_->theLockingInset()) {
3348 if (bv_->theLockingInset()->InsertInsetAllowed(inset))
3349 return bv_->theLockingInset()->InsertInset(bv_, inset);
3353 // not quite sure if we want this...
3354 bv_->text->SetCursorParUndo(buffer_);
3355 bv_->text->FreezeUndo();
3357 beforeChange(bv_->text);
3358 if (!lout.empty()) {
3359 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3360 bv_->text->BreakParagraph(bv_);
3361 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3363 if (bv_->text->cursor.par()->size()) {
3364 bv_->text->CursorLeft(bv_);
3366 bv_->text->BreakParagraph(bv_);
3367 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3370 pair<bool, LyXTextClass::size_type> lres =
3371 textclasslist.NumberOfLayout(buffer_->params
3373 LyXTextClass::size_type lay;
3374 if (lres.first != false) {
3378 // layout not fount using default "Standard" (0)
3382 bv_->text->SetLayout(bv_, lay);
3384 bv_->text->SetParagraph(bv_, 0, 0,
3386 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3390 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3392 bv_->text->current_font.setLatex(LyXFont::OFF);
3395 bv_->text->InsertInset(bv_, inset);
3396 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3398 bv_->text->UnFreezeUndo();
3403 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3408 // first check for locking insets
3409 if (bv_->theLockingInset()) {
3410 if (bv_->theLockingInset() == inset) {
3411 if (bv_->text->UpdateInset(bv_, inset)) {
3414 buffer_->markDirty();
3419 } else if (bv_->theLockingInset()->UpdateInsetInInset(bv_, inset)) {
3420 if (bv_->text->UpdateInset(bv_,
3421 bv_->theLockingInset())) {
3424 buffer_->markDirty();
3432 // then check the current buffer
3435 update(bv_->text, BufferView::UPDATE);
3436 if (bv_->text->UpdateInset(bv_, inset)) {
3440 | BufferView::FITCUR
3441 | BufferView::CHANGE);
3443 update(bv_->text, SELECT);
3451 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3454 if (!available()) return;
3457 beforeChange(bv_->text);
3458 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3462 bv_->text->cursor.par()->GetChar(bv_->text->cursor.pos()) == LyXParagraph::META_INSET) {
3463 Inset const * inset = bv_->text->cursor.par()->GetInset(bv_->text->cursor.pos());
3464 if (find(codes.begin(), codes.end(), inset->LyxCode())
3467 static_cast<InsetCommand const *>(inset)->getContents();
3470 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3471 if (bv_->text->cursor.pos()
3472 || bv_->text->cursor.par() != bv_->text->FirstParagraph()) {
3473 LyXCursor tmp = bv_->text->cursor;
3474 bv_->text->cursor.par(bv_->text->FirstParagraph());
3475 bv_->text->cursor.pos(0);
3476 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3477 bv_->text->cursor = tmp;
3478 bv_->owner()->message(_("No more insets"));
3481 bv_->owner()->message(_("No more insets"));
3484 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3485 bv_->text->selection.cursor = bv_->text->cursor;
3489 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3491 gotoInset(vector<Inset::Code>(1, code), same_content);