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;
73 /* the selection possible is needed, that only motion events are
74 * used, where the bottom press event was on the drawing area too */
75 bool selection_possible = false;
77 extern BufferList bufferlist;
78 extern char ascii_type;
80 extern bool math_insert_greek(BufferView *, char);
81 extern void sigchldhandler(pid_t pid, int * status);
82 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
86 const unsigned int saved_positions_num = 20;
91 XSync(fl_get_display(), 0);
95 void SetXtermCursor(Window win)
98 static bool cursor_undefined = true;
99 if (cursor_undefined){
100 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
101 XFlush(fl_get_display());
102 cursor_undefined = false;
104 XDefineCursor(fl_get_display(), win, cursor);
105 XFlush(fl_get_display());
111 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
112 int xpos, int ypos, int width, int height)
113 : bv_(b), owner_(o), buffer_(0),
114 current_scrollbar_value(0), cursor_timeout(400),
115 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
119 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
120 workarea_.workAreaExpose
121 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
122 workarea_.workAreaEnter
123 .connect(slot(this, &BufferView::Pimpl::enterView));
124 workarea_.workAreaLeave
125 .connect(slot(this, &BufferView::Pimpl::leaveView));
126 workarea_.workAreaButtonPress
127 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
128 workarea_.workAreaButtonRelease
130 &BufferView::Pimpl::workAreaButtonRelease));
131 workarea_.workAreaMotionNotify
132 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
133 workarea_.workAreaDoubleClick
134 .connect(slot(this, &BufferView::Pimpl::doubleClick));
135 workarea_.workAreaTripleClick
136 .connect(slot(this, &BufferView::Pimpl::tripleClick));
137 workarea_.workAreaKeyPress
138 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
140 cursor_timeout.timeout.connect(slot(this,
141 &BufferView::Pimpl::cursorToggle));
142 cursor_timeout.start();
143 workarea_.setFocus();
144 saved_positions.resize(saved_positions_num);
148 Painter & BufferView::Pimpl::painter()
150 return workarea_.getPainter();
154 void BufferView::Pimpl::buffer(Buffer * b)
156 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
160 buffer_->delUser(bv_);
162 // Put the old text into the TextCache, but
163 // only if the buffer is still loaded.
164 // Also set the owner of the test to 0
165 // bv_->text->owner(0);
166 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
167 if (lyxerr.debugging())
168 textcache.show(lyxerr, "BufferView::buffer");
173 // Set current buffer
176 if (bufferlist.getState() == BufferList::CLOSING) return;
179 // screen is always deleted when the buffer is changed.
182 // If we are closing the buffer, use the first buffer as current
184 buffer_ = bufferlist.first();
188 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
189 buffer_->addUser(bv_);
190 // If we don't have a text object for this, we make one
191 if (bv_->text == 0) {
192 resizeCurrentBuffer();
197 bv_->text->first = screen_->TopCursorVisible(bv_->text);
198 owner_->updateMenubar();
199 owner_->updateToolbar();
200 // Similarly, buffer-dependent dialogs should be updated or
201 // hidden. This should go here because some dialogs (eg ToC)
202 // require bv_->text.
203 owner_->getDialogs()->updateBufferDependent(true);
207 lyxerr[Debug::INFO] << " No Buffer!" << endl;
208 owner_->updateMenubar();
209 owner_->updateToolbar();
210 owner_->getDialogs()->hideBufferDependent();
214 // Also remove all remaining text's from the testcache.
215 // (there should not be any!) (if there is any it is a
217 if (lyxerr.debugging())
218 textcache.show(lyxerr, "buffer delete all");
221 // should update layoutchoice even if we don't have a buffer.
222 owner_->updateLayoutChoice();
224 owner_->updateWindowTitle();
228 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
230 workarea_.resize(xpos, ypos, width, height);
231 update(bv_->text, SELECT);
236 void BufferView::Pimpl::resize()
239 resizeCurrentBuffer();
243 void BufferView::Pimpl::redraw()
245 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
250 bool BufferView::Pimpl::fitCursor(LyXText * text)
252 lyx::Assert(screen_.get());
254 bool const ret = screen_->FitCursor(text, bv_);
261 void BufferView::Pimpl::redoCurrentBuffer()
263 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
264 if (buffer_ && bv_->text) {
266 owner_->updateLayoutChoice();
271 int BufferView::Pimpl::resizeCurrentBuffer()
273 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
275 LyXParagraph * par = 0;
276 LyXParagraph * selstartpar = 0;
277 LyXParagraph * selendpar = 0;
278 UpdatableInset * the_locking_inset = 0;
280 LyXParagraph::size_type pos = 0;
281 LyXParagraph::size_type selstartpos = 0;
282 LyXParagraph::size_type selendpos = 0;
283 bool selection = false;
284 bool mark_set = false;
288 owner_->message(_("Formatting document..."));
291 par = bv_->text->cursor.par();
292 pos = bv_->text->cursor.pos();
293 selstartpar = bv_->text->selection.start.par();
294 selstartpos = bv_->text->selection.start.pos();
295 selendpar = bv_->text->selection.end.par();
296 selendpos = bv_->text->selection.end.pos();
297 selection = bv_->text->selection.set();
298 mark_set = bv_->text->selection.mark();
299 the_locking_inset = bv_->text->the_locking_inset;
301 bv_->text = new LyXText(bv_);
303 // See if we have a text in TextCache that fits
304 // the new buffer_ with the correct width.
305 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
307 if (lyxerr.debugging()) {
308 lyxerr << "Found a LyXText that fits:\n";
309 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
311 // Set the owner of the newly found text
312 // bv_->text->owner(bv_);
313 if (lyxerr.debugging())
314 textcache.show(lyxerr, "resizeCurrentBuffer");
316 bv_->text = new LyXText(bv_);
322 bv_->text->selection.set(true);
323 /* at this point just to avoid the Delete-Empty-Paragraph
324 * Mechanism when setting the cursor */
325 bv_->text->selection.mark(mark_set);
327 bv_->text->SetCursor(bv_, selstartpar, selstartpos);
328 bv_->text->selection.cursor = bv_->text->cursor;
329 bv_->text->SetCursor(bv_, selendpar, selendpos);
330 bv_->text->SetSelection(bv_);
331 bv_->text->SetCursor(bv_, par, pos);
333 bv_->text->SetCursor(bv_, par, pos);
334 bv_->text->selection.cursor = bv_->text->cursor;
335 bv_->text->selection.set(false);
337 // remake the inset locking
338 bv_->text->the_locking_inset = the_locking_inset;
340 bv_->text->first = screen_->TopCursorVisible(bv_->text);
341 buffer_->resizeInsets(bv_);
342 // this will scroll the screen such that the cursor becomes visible
349 /// get rid of the splash screen if it's not gone already
350 owner_->getDialogs()->destroySplash();
356 void BufferView::Pimpl::updateScreen()
358 // Regenerate the screen.
359 screen_.reset(new LyXScreen(workarea_));
363 void BufferView::Pimpl::updateScrollbar()
365 /* If the text is smaller than the working area, the scrollbar
366 * maximum must be the working area height. No scrolling will
370 workarea_.setScrollbar(0, 1.0);
374 static unsigned long text_height;
375 static unsigned long work_height;
377 unsigned long const tmp_text_height = bv_->text->height;
378 long const tmp_scrollbar_value = bv_->text->first;
380 // check if anything has changed.
381 if (text_height == tmp_text_height
382 && work_height == workarea_.height()
383 && current_scrollbar_value == tmp_scrollbar_value)
387 text_height = tmp_text_height;
388 work_height = workarea_.height();
389 current_scrollbar_value = tmp_scrollbar_value;
391 long const height_diff = text_height - work_height;
393 if (height_diff <= 0) {
394 workarea_.setScrollbar(0, 1.0);
399 workarea_.setScrollbarBounds(0, height_diff);
400 double const lineh = bv_->text->DefaultHeight();
401 workarea_.setScrollbarIncrements(lineh);
402 double const slider_size = 1.0 / double(height_diff) ;
403 workarea_.setScrollbar(current_scrollbar_value, slider_size);
407 // Callback for scrollbar slider
408 void BufferView::Pimpl::scrollCB(double value)
410 if (!buffer_) return;
412 current_scrollbar_value = long(value);
413 if (current_scrollbar_value < 0)
414 current_scrollbar_value = 0;
419 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
421 if (!lyxrc.cursor_follows_scrollbar) {
426 LyXText * vbt = bv_->text;
428 int const height = vbt->DefaultHeight();
429 int const first = static_cast<int>((bv_->text->first + height));
430 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
432 if (vbt->cursor.y() < first)
433 vbt->SetCursorFromCoordinates(bv_, 0, first);
434 else if (vbt->cursor.y() > last)
435 vbt->SetCursorFromCoordinates(bv_, 0, last);
441 int BufferView::Pimpl::scrollUp(long time)
443 if (!buffer_) return 0;
444 if (!screen_.get()) return 0;
446 double value = workarea_.getScrollbarValue();
448 if (value == 0) return 0;
450 float add_value = (bv_->text->DefaultHeight()
451 + float(time) * float(time) * 0.125);
453 if (add_value > workarea_.height())
454 add_value = float(workarea_.height() -
455 bv_->text->DefaultHeight());
462 workarea_.setScrollbarValue(value);
469 int BufferView::Pimpl::scrollDown(long time)
471 if (!buffer_) return 0;
472 if (!screen_.get()) return 0;
474 double value = workarea_.getScrollbarValue();
475 pair<float, float> p = workarea_.getScrollbarBounds();
476 double const max = p.second;
478 if (value == max) return 0;
480 float add_value = (bv_->text->DefaultHeight()
481 + float(time) * float(time) * 0.125);
483 if (add_value > workarea_.height())
484 add_value = float(workarea_.height() -
485 bv_->text->DefaultHeight());
492 workarea_.setScrollbarValue(value);
499 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
501 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
505 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
507 // Only use motion with button 1
508 if (!(state & Button1MotionMask))
511 if (!buffer_ || !screen_.get()) return;
513 // Check for inset locking
514 if (bv_->theLockingInset()) {
515 LyXCursor cursor = bv_->text->cursor;
516 LyXFont font = bv_->text->GetFont(buffer_,
517 cursor.par(), cursor.pos());
518 int width = bv_->theLockingInset()->width(bv_, font);
519 int inset_x = font.isVisibleRightToLeft()
520 ? cursor.x() - width : cursor.x();
521 int start_x = inset_x + bv_->theLockingInset()->scroll();
522 bv_->theLockingInset()->
523 InsetMotionNotify(bv_,
525 y - cursor.y() + bv_->text->first,
530 /* The test for not selection possible is needed, that only motion
531 events are used, where the bottom press event was on
532 the drawing area too */
533 if (!selection_possible)
536 screen_->HideCursor();
538 bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first);
540 if (!bv_->text->selection.set())
541 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
543 bv_->text->SetSelection(bv_);
544 screen_->ToggleToggle(bv_->text, bv_);
545 fitCursor(bv_->text);
546 screen_->ShowCursor(bv_->text, bv_);
550 // Single-click on work area
551 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
554 if (!buffer_ || !screen_.get()) return;
556 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
558 // ok ok, this is a hack.
559 if (button == 4 || button == 5) {
562 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
565 scrollDown(lyxrc.wheel_jump);
570 if (bv_->theLockingInset()) {
571 // We are in inset locking mode
573 /* Check whether the inset was hit. If not reset mode,
574 otherwise give the event to the inset */
575 if (inset_hit == bv_->theLockingInset()) {
576 bv_->theLockingInset()->
577 InsetButtonPress(bv_,
582 bv_->unlockInset(bv_->theLockingInset());
587 selection_possible = true;
588 screen_->HideCursor();
590 int const screen_first = bv_->text->first;
592 // Middle button press pastes if we have a selection
593 bool paste_internally = false;
595 && bv_->text->selection.set()) {
596 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
597 paste_internally = true;
600 // Clear the selection
601 screen_->ToggleSelection(bv_->text, bv_);
602 bv_->text->ClearSelection(bv_);
603 bv_->text->FullRebreak(bv_);
604 screen_->Update(bv_->text, bv_);
607 // Single left click in math inset?
608 if ((inset_hit != 0) &&
609 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
610 // Highly editable inset, like math
611 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
612 selection_possible = false;
613 owner_->updateLayoutChoice();
614 owner_->message(inset->EditMessage());
615 inset->InsetButtonPress(bv_, xpos, ypos, button);
616 inset->Edit(bv_, xpos, ypos, button);
620 // Right click on a footnote flag opens float menu
622 selection_possible = false;
626 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
627 bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first);
628 bv_->text->FinishUndo();
629 bv_->text->selection.cursor = bv_->text->cursor;
630 bv_->text->cursor.x_fix(bv_->text->cursor.x());
632 owner_->updateLayoutChoice();
633 if (fitCursor(bv_->text)) {
634 selection_possible = false;
637 // Insert primary selection with middle mouse
638 // if there is a local selection in the current buffer,
641 if (paste_internally)
642 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
644 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
646 selection_possible = false;
652 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
658 LyXText * text = bv_->getLyXText();
660 if (text->bv_owner && bv_->theLockingInset())
663 if (screen_.get() && button == 1) {
664 if (text->bv_owner) {
665 screen_->HideCursor();
666 screen_->ToggleSelection(text, bv_);
667 text->SelectWord(bv_);
668 screen_->ToggleSelection(text, bv_, false);
670 text->SelectWord(bv_);
672 /* This will fit the cursor on the screen
674 update(text, BufferView::SELECT|BufferView::FITCUR);
679 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
685 LyXText * text = bv_->getLyXText();
687 if (text->bv_owner && bv_->theLockingInset())
690 if (screen_.get() && (button == 1)) {
691 screen_->HideCursor();
692 screen_->ToggleSelection(text, bv_);
693 text->CursorHome(bv_);
694 text->selection.cursor = text->cursor;
695 text->CursorEnd(bv_);
696 text->SetSelection(bv_);
697 screen_->ToggleSelection(text, bv_, false);
698 /* This will fit the cursor on the screen
700 update(text, BufferView::SELECT|BufferView::FITCUR);
705 void BufferView::Pimpl::enterView()
707 if (active() && available()) {
708 SetXtermCursor(workarea_.getWin());
709 using_xterm_cursor = true;
714 void BufferView::Pimpl::leaveView()
716 if (using_xterm_cursor) {
717 XUndefineCursor(fl_get_display(), workarea_.getWin());
718 using_xterm_cursor = false;
723 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
726 if (!buffer_ || !screen_.get()) return;
728 // If we hit an inset, we have the inset coordinates in these
729 // and inset_hit points to the inset. If we do not hit an
730 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
731 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
733 if (bv_->theLockingInset()) {
734 // We are in inset locking mode.
736 /* LyX does a kind of work-area grabbing for insets.
737 Only a ButtonPress Event outside the inset will
738 force a InsetUnlock. */
739 bv_->theLockingInset()->
740 InsetButtonRelease(bv_, x, y, button);
744 selection_possible = false;
752 // Did we hit an editable inset?
754 // Inset like error, notes and figures
755 selection_possible = false;
757 // CHECK fix this proper in 0.13
759 // Following a ref shouldn't issue
760 // a push on the undo-stack
761 // anylonger, now that we have
762 // keybindings for following
763 // references and returning from
764 // references. IMHO though, it
765 // should be the inset's own business
766 // to push or not push on the undo
767 // stack. They don't *have* to
768 // alter the document...
770 // ...or maybe the SetCursorParUndo()
771 // below isn't necessary at all anylonger?
772 if (inset_hit->LyxCode() == Inset::REF_CODE) {
773 bv_->text->SetCursorParUndo(buffer_);
776 owner_->message(inset_hit->EditMessage());
778 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
779 // Highly editable inset, like math
780 UpdatableInset *inset = (UpdatableInset *)inset_hit;
781 inset->InsetButtonRelease(bv_, x, y, button);
783 inset_hit->InsetButtonRelease(bv_, x, y, button);
784 inset_hit->Edit(bv_, x, y, button);
789 // check whether we want to open a float
793 if (bv_->text->cursor.pos() <
794 bv_->text->cursor.par()->size()) {
795 c = bv_->text->cursor.par()->
796 GetChar(bv_->text->cursor.pos());
798 if (bv_->text->cursor.pos() - 1 >= 0) {
799 c = bv_->text->cursor.par()->
800 GetChar(bv_->text->cursor.pos() - 1);
803 selection_possible = false;
808 // Maybe we want to edit a bibitem ale970302
809 if (bv_->text->cursor.par()->bibkey && x < 20 +
810 bibitemMaxWidth(bv_, textclasslist.
812 params.textclass).defaultfont())) {
813 bv_->text->cursor.par()->bibkey->Edit(bv_, 0, 0, 0);
821 * Returns an inset if inset was hit. 0 otherwise.
822 * If hit, the coordinates are changed relative to the inset.
823 * Otherwise coordinates are not changed, and false is returned.
825 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
826 unsigned int /* button */)
831 int y_tmp = y + text->first;
834 text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
835 text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
838 if (cursor.pos() < cursor.par()->size()
839 && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
840 && cursor.par()->GetInset(cursor.pos())
841 && cursor.par()->GetInset(cursor.pos())->Editable()) {
843 // Check whether the inset really was hit
844 Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
845 LyXFont font = text->GetFont(buffer_,
846 cursor.par(), cursor.pos());
847 int const width = tmpinset->width(bv_, font);
848 int const inset_x = font.isVisibleRightToLeft()
849 ? cursor.x() - width : cursor.x();
850 int const start_x = inset_x + tmpinset->scroll();
851 int const end_x = inset_x + width;
853 if (x > start_x && x < end_x
854 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
855 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
856 text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
858 // The origin of an inset is on the baseline
859 y = y_tmp - (text->cursor.y());
864 if ((cursor.pos() - 1 >= 0) &&
865 (cursor.par()->GetChar(cursor.pos()-1) == LyXParagraph::META_INSET) &&
866 (cursor.par()->GetInset(cursor.pos() - 1)) &&
867 (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
868 Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
869 LyXFont font = text->GetFont(buffer_, cursor.par(),
871 int const width = tmpinset->width(bv_, font);
872 int const inset_x = font.isVisibleRightToLeft()
873 ? cursor.x() : cursor.x() - width;
874 int const start_x = inset_x + tmpinset->scroll();
875 int const end_x = inset_x + width;
877 if (x > start_x && x < end_x
878 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
879 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
881 if (move_cursor && (tmpinset != bv_->theLockingInset()))
883 text->SetCursor(bv_, cursor.par(),
884 cursor.pos() - 1, true);
886 // The origin of an inset is on the baseline
887 y = y_tmp - (text->cursor.y());
895 void BufferView::Pimpl::workAreaExpose()
897 static int work_area_width;
898 static unsigned int work_area_height;
900 bool const widthChange = workarea_.workWidth() != work_area_width;
901 bool const heightChange = workarea_.height() != work_area_height;
903 // update from work area
904 work_area_width = workarea_.workWidth();
905 work_area_height = workarea_.height();
908 // All buffers need a resize
911 // Remove all texts from the textcache
912 // This is not _really_ what we want to do. What
913 // we really want to do is to delete in textcache
914 // that does not have a BufferView with matching
915 // width, but as long as we have only one BufferView
916 // deleting all gives the same result.
917 if (lyxerr.debugging())
918 textcache.show(lyxerr, "Expose delete all");
920 } else if (heightChange) {
921 // Rebuild image of current screen
923 // fitCursor() ensures we don't jump back
924 // to the start of the document on vertical
926 fitCursor(bv_->text);
928 // The main window size has changed, repaint most stuff
930 } else if (screen_.get())
931 screen_->Redraw(bv_->text, bv_);
933 // Grey box when we don't have a buffer
937 // always make sure that the scrollbar is sane.
939 owner_->updateLayoutChoice();
944 void BufferView::Pimpl::update()
946 if (screen_.get()) screen_->Update(bv_->text, bv_);
949 // Values used when calling update:
951 // -2 - update, move sel_cursor if selection, fitcursor
952 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
953 // 0 - update, move sel_cursor if selection, fitcursor
954 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
955 // 3 - update, move sel_cursor if selection
958 // a simple redraw of the parts that need refresh
960 // move sel_cursor if selection -
961 // the text's sel_cursor is moved if there is selection is progress
964 // fitCursor() is called and the scrollbar updated
967 // the buffer is marked dirty.
976 // UPDATE_ONLY = UPDATE;
977 // UPDATE_SELECT = UPDATE | SELECT;
978 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
979 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
981 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
982 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
983 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
984 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
985 // update(3) -> update(1) -> update(1) -> update(SELECT)
987 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
989 owner_->updateLayoutChoice();
991 if (!text->selection.set() && (f & SELECT)) {
992 text->selection.cursor = text->cursor;
995 text->FullRebreak(bv_);
997 if (text->inset_owner) {
998 text->inset_owner->SetUpdateStatus(bv_, InsetText::NONE);
999 updateInset(text->inset_owner, true);
1008 buffer_->markDirty();
1013 // Callback for cursor timer
1014 void BufferView::Pimpl::cursorToggle()
1016 // Quite a nice place for asyncron Inset updating, isn't it?
1017 // Actually no! This is run even if no buffer exist... so (Lgb)
1019 cursor_timeout.restart();
1024 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1025 if (pid == -1) // error find out what is wrong
1026 ; // ignore it for now.
1028 sigchldhandler(pid, &status);
1030 updatelist.update(bv_);
1032 if (!screen_.get()) {
1033 cursor_timeout.restart();
1037 if (!bv_->theLockingInset()) {
1038 screen_->CursorToggle(bv_->text, bv_);
1040 bv_->theLockingInset()->ToggleInsetCursor(bv_);
1043 cursor_timeout.restart();
1047 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1049 if (!text->cursor.row()->previous())
1052 int y = text->first;
1053 if (text->inset_owner)
1054 y += bv_->text->first;
1055 Row * cursorrow = text->cursor.row();
1056 text->SetCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1057 bv_->text->FinishUndo();
1058 // This is to allow jumping over large insets
1059 if ((cursorrow == text->cursor.row()))
1060 text->CursorUp(bv_);
1062 if (text->inset_owner ||
1063 text->cursor.row()->height() < workarea_.height())
1064 screen_->Draw(bv_->text, bv_,
1066 - text->cursor.row()->baseline()
1067 + text->cursor.row()->height()
1068 - workarea_.height() + 1 );
1073 void BufferView::Pimpl::cursorNext(LyXText * text)
1075 if (!text->cursor.row()->next())
1078 int y = text->first + workarea_.height();
1079 // if (text->inset_owner)
1080 // y += bv_->text->first;
1081 text->GetRowNearY(y);
1083 Row * cursorrow = text->cursor.row();
1084 text->SetCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1085 bv_->text->FinishUndo();
1086 // This is to allow jumping over large insets
1087 if ((cursorrow == bv_->text->cursor.row()))
1088 text->CursorDown(bv_);
1090 if (text->inset_owner ||
1091 text->cursor.row()->height() < workarea_.height())
1092 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1093 text->cursor.row()->baseline());
1098 bool BufferView::Pimpl::available() const
1100 if (buffer_ && bv_->text) return true;
1105 void BufferView::Pimpl::beforeChange(LyXText * text)
1108 text->ClearSelection(bv_);
1112 void BufferView::Pimpl::savePosition(unsigned int i)
1114 if (i >= saved_positions_num)
1116 saved_positions[i] = Position(buffer_->fileName(),
1117 bv_->text->cursor.par()->id(),
1118 bv_->text->cursor.pos());
1120 string const str = _("Saved bookmark") + ' ' + tostr(i);
1121 owner_->message(str);
1126 void BufferView::Pimpl::restorePosition(unsigned int i)
1128 if (i >= saved_positions_num)
1131 string const fname = saved_positions[i].filename;
1133 beforeChange(bv_->text);
1135 if (fname != buffer_->fileName()) {
1136 Buffer * b = bufferlist.exists(fname) ?
1137 bufferlist.getBuffer(fname) :
1138 bufferlist.loadLyXFile(fname); // don't ask, just load it
1139 if (b != 0 ) buffer(b);
1142 LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id);
1146 bv_->text->SetCursor(bv_, par,
1147 min(par->size(), saved_positions[i].par_pos));
1149 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1151 string const str = _("Moved to bookmark") + ' ' + tostr(i);
1152 owner_->message(str);
1157 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1159 if (i >= saved_positions_num)
1162 return !saved_positions[i].filename.empty();
1166 void BufferView::Pimpl::setState()
1168 if (!lyxrc.rtl_support)
1171 LyXText * text = bv_->getLyXText();
1172 if (text->real_current_font.isRightToLeft() &&
1173 text->real_current_font.latex() != LyXFont::ON) {
1174 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1175 owner_->getIntl()->KeyMapSec();
1177 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1178 owner_->getIntl()->KeyMapPrim();
1183 void BufferView::Pimpl::insetSleep()
1185 if (bv_->theLockingInset() && !inset_slept) {
1186 bv_->theLockingInset()->GetCursorPos(bv_, bv_->slx, bv_->sly);
1187 bv_->theLockingInset()->InsetUnlock(bv_);
1193 void BufferView::Pimpl::insetWakeup()
1195 if (bv_->theLockingInset() && inset_slept) {
1196 bv_->theLockingInset()->Edit(bv_, bv_->slx, bv_->sly, 0);
1197 inset_slept = false;
1202 void BufferView::Pimpl::insetUnlock()
1204 if (bv_->theLockingInset()) {
1206 bv_->theLockingInset()->InsetUnlock(bv_);
1207 bv_->theLockingInset(0);
1208 bv_->text->FinishUndo();
1209 inset_slept = false;
1214 bool BufferView::Pimpl::focus() const
1216 return workarea_.hasFocus();
1220 void BufferView::Pimpl::focus(bool f)
1222 if (f) workarea_.setFocus();
1226 bool BufferView::Pimpl::active() const
1228 return workarea_.active();
1232 bool BufferView::Pimpl::belowMouse() const
1234 return workarea_.belowMouse();
1238 void BufferView::Pimpl::showCursor()
1241 screen_->ShowCursor(bv_->text, bv_);
1245 void BufferView::Pimpl::hideCursor()
1248 screen_->HideCursor();
1252 void BufferView::Pimpl::toggleSelection(bool b)
1255 screen_->ToggleSelection(bv_->text, bv_, b);
1259 void BufferView::Pimpl::toggleToggle()
1262 screen_->ToggleToggle(bv_->text, bv_);
1266 void BufferView::Pimpl::center()
1268 beforeChange(bv_->text);
1269 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1270 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1272 screen_->Draw(bv_->text, bv_, 0);
1274 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1279 void BufferView::Pimpl::pasteClipboard(bool asPara)
1281 if (!buffer_) return;
1283 screen_->HideCursor();
1284 beforeChange(bv_->text);
1286 string const clip(workarea_.getClipboard());
1288 if (clip.empty()) return;
1291 bv_->text->InsertStringB(bv_, clip);
1293 bv_->text->InsertStringA(bv_, clip);
1295 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1299 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1301 workarea_.putClipboard(stuff);
1306 * Dispatch functions for actions which can be valid for BufferView->text
1307 * and/or InsetText->text!!!
1312 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1314 LyXText * lt = bv_->getLyXText();
1316 if (selecting || lt->selection.mark()) {
1317 lt->SetSelection(bv_);
1321 update(lt, BufferView::SELECT|BufferView::FITCUR);
1324 /* ---> Everytime the cursor is moved, show the current font state. */
1325 // should this too me moved out of this func?
1326 //owner->showState();
1331 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1333 LyXCursor cursor = bv_->getLyXText()->cursor;
1334 Buffer::inset_iterator it =
1335 find_if(Buffer::inset_iterator(
1336 cursor.par(), cursor.pos()),
1337 buffer_->inset_iterator_end(),
1338 lyx::compare_memfun(&Inset::LyxCode, code));
1339 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1343 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1345 string filename = filen;
1347 if (filename.empty()) {
1348 // Launch a file browser
1349 string initpath = lyxrc.document_path;
1352 string const trypath = owner_->buffer()->filepath;
1353 // If directory is writeable, use this as default.
1354 if (IsDirWriteable(trypath) == 1)
1358 FileDialog fileDlg(bv_->owner(),
1359 _("Select LyX document to insert"),
1361 make_pair(string(_("Documents")),
1362 string(lyxrc.document_path)),
1363 make_pair(string(_("Examples")),
1364 string(AddPath(system_lyxdir, "examples"))));
1366 FileDialog::Result result =
1367 fileDlg.Select(initpath,
1368 _("*.lyx| LyX Documents (*.lyx)"));
1370 if (result.first == FileDialog::Later)
1373 filename = result.second;
1375 // check selected filename
1376 if (filename.empty()) {
1377 owner_->message(_("Canceled."));
1382 // get absolute path of file and make sure the filename ends
1384 filename = MakeAbsPath(filename);
1385 if (!IsLyXFilename(filename))
1389 string const s1 = _("Inserting document") + ' '
1390 + MakeDisplayPath(filename) + " ...";
1391 owner_->message(s1);
1392 bool const res = bv_->insertLyXFile(filename);
1394 string const str = _("Document") + ' '
1395 + MakeDisplayPath(filename) + ' ' + _("inserted.");
1396 owner_->message(str);
1398 string const str = _("Could not insert document") + ' '
1399 + MakeDisplayPath(filename);
1400 owner_->message(str);
1405 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1408 // --- Misc -------------------------------------------
1412 LyXText * lt = bv_->getLyXText();
1413 lt->toggleAppendix(bv_);
1416 | BufferView::FITCUR
1417 | BufferView::CHANGE);
1422 case LFUN_TOC_INSERT:
1424 InsetCommandParams p;
1425 p.setCmdName("tableofcontents");
1426 Inset * inset = new InsetTOC(p);
1427 if (!insertInset(inset, "Standard"))
1432 case LFUN_TABULAR_FEATURE:
1433 case LFUN_SCROLL_INSET:
1434 // this is not handled here as this funktion is only aktive
1435 // if we have a locking_inset and that one is (or contains)
1439 case LFUN_INSET_GRAPHICS:
1441 Inset * new_inset = new InsetGraphics;
1442 if (!insertInset(new_inset)) {
1445 // this is need because you don't use a inset->Edit()
1446 updateInset(new_inset, true);
1447 new_inset->Edit(bv_, 0, 0, 0);
1457 case LFUN_PASTESELECTION:
1459 bool asPara = false;
1460 if (argument == "paragraph") asPara = true;
1461 pasteClipboard(asPara);
1473 case LFUN_LAYOUT_COPY:
1474 bv_->copyEnvironment();
1477 case LFUN_LAYOUT_PASTE:
1478 bv_->pasteEnvironment();
1482 case LFUN_GOTOERROR:
1483 gotoInset(Inset::ERROR_CODE, false);
1487 gotoInset(Inset::IGNORE_CODE, false);
1490 case LFUN_REFERENCE_GOTO:
1492 vector<Inset::Code> tmp;
1493 tmp.push_back(Inset::LABEL_CODE);
1494 tmp.push_back(Inset::REF_CODE);
1495 gotoInset(tmp, true);
1499 case LFUN_HYPHENATION:
1507 case LFUN_END_OF_SENTENCE:
1511 case LFUN_MENU_SEPARATOR:
1520 changeDepth(bv_, bv_->getLyXText(), 0);
1523 case LFUN_DEPTH_MIN:
1524 changeDepth(bv_, bv_->getLyXText(), -1);
1527 case LFUN_DEPTH_PLUS:
1528 changeDepth(bv_, bv_->getLyXText(), 1);
1532 owner_->getDialogs()->setUserFreeFont();
1538 owner_->showState();
1541 case LFUN_FILE_INSERT:
1543 MenuInsertLyXFile(argument);
1547 case LFUN_FILE_INSERT_ASCII_PARA:
1548 InsertAsciiFile(bv_, argument, true);
1551 case LFUN_FILE_INSERT_ASCII:
1552 InsertAsciiFile(bv_, argument, false);
1557 lyxerr.debug() << "LFUN_LAYOUT: (arg) "
1558 << argument << endl;
1560 // Derive layout number from given argument (string)
1561 // and current buffer's textclass (number). */
1562 LyXTextClassList::ClassList::size_type tclass =
1563 buffer_->params.textclass;
1564 pair <bool, LyXTextClass::size_type> layout =
1565 textclasslist.NumberOfLayout(tclass, argument);
1567 // If the entry is obsolete, use the new one instead.
1569 string obs = textclasslist.Style(tclass,layout.second)
1573 textclasslist.NumberOfLayout(tclass, obs);
1576 // see if we found the layout number:
1577 if (!layout.first) {
1578 owner_->getLyXFunc()->setErrorMessage(
1579 string(N_("Layout ")) + argument +
1584 if (current_layout != layout.second) {
1585 LyXText * lt = bv_->getLyXText();
1587 current_layout = layout.second;
1590 | BufferView::FITCUR);
1591 lt->SetLayout(bv_, layout.second);
1592 owner_->setLayout(layout.second);
1595 | BufferView::FITCUR
1596 | BufferView::CHANGE);
1603 Lang(bv_, argument);
1605 owner_->showState();
1610 owner_->showState();
1615 owner_->showState();
1620 owner_->showState();
1625 owner_->showState();
1630 owner_->showState();
1635 owner_->showState();
1640 owner_->showState();
1643 case LFUN_UNDERLINE:
1645 owner_->showState();
1648 case LFUN_FONT_SIZE:
1649 FontSize(bv_, argument);
1650 owner_->showState();
1653 case LFUN_FONT_STATE:
1654 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1657 case LFUN_UPCASE_WORD:
1659 LyXText * lt = bv_->getLyXText();
1663 | BufferView::FITCUR);
1664 lt->ChangeWordCase(bv_, LyXText::text_uppercase);
1665 if (lt->inset_owner)
1666 updateInset(lt->inset_owner, true);
1669 | BufferView::FITCUR
1670 | BufferView::CHANGE);
1674 case LFUN_LOWCASE_WORD:
1676 LyXText * lt = bv_->getLyXText();
1678 update(lt, BufferView::SELECT|BufferView::FITCUR);
1679 lt->ChangeWordCase(bv_, LyXText::text_lowercase);
1680 if (lt->inset_owner)
1681 updateInset(lt->inset_owner, true);
1684 | BufferView::FITCUR
1685 | BufferView::CHANGE);
1689 case LFUN_CAPITALIZE_WORD:
1691 LyXText * lt = bv_->getLyXText();
1693 update(lt, BufferView::SELECT|BufferView::FITCUR);
1694 lt->ChangeWordCase(bv_,
1695 LyXText::text_capitalization);
1696 if (lt->inset_owner)
1697 updateInset(lt->inset_owner, true);
1700 | BufferView::FITCUR
1701 | BufferView::CHANGE);
1705 case LFUN_TRANSPOSE_CHARS:
1707 LyXText * lt = bv_->getLyXText();
1709 update(lt, BufferView::SELECT|BufferView::FITCUR);
1710 lt->TransposeChars(*bv_);
1711 if (lt->inset_owner)
1712 updateInset(lt->inset_owner, true);
1715 | BufferView::FITCUR
1716 | BufferView::CHANGE);
1721 case LFUN_INSERT_LABEL:
1722 MenuInsertLabel(bv_, argument);
1725 case LFUN_REF_INSERT:
1726 if (argument.empty()) {
1727 InsetCommandParams p("ref");
1728 owner_->getDialogs()->createRef(p.getAsString());
1730 InsetCommandParams p;
1731 p.setFromString(argument);
1733 InsetRef * inset = new InsetRef(p, *buffer_);
1734 if (!insertInset(inset))
1737 updateInset(inset, true);
1741 case LFUN_BOOKMARK_SAVE:
1742 savePosition(strToUnsignedInt(argument));
1745 case LFUN_BOOKMARK_GOTO:
1746 restorePosition(strToUnsignedInt(argument));
1751 string label(argument);
1752 if (label.empty()) {
1754 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1756 label = inset->getContents();
1761 if (!label.empty()) {
1762 //bv_->savePosition(0);
1763 if (!bv_->gotoLabel(label))
1764 WriteAlert(_("Error"),
1765 _("Couldn't find this label"),
1766 _("in current document."));
1771 // --- Cursor Movements -----------------------------
1774 LyXText * lt = bv_->getLyXText();
1776 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1777 if (!lt->selection.mark())
1779 update(lt, BufferView::SELECT|BufferView::FITCUR);
1781 lt->CursorLeft(bv_, false);
1782 if (lt->cursor.pos() < lt->cursor.par()->size()
1783 && lt->cursor.par()->GetChar(lt->cursor.pos())
1784 == LyXParagraph::META_INSET
1785 && lt->cursor.par()->GetInset(lt->cursor.pos())
1786 && lt->cursor.par()->GetInset(lt->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
1787 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1788 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1791 LyXFont const font =
1792 lt->GetFont(buffer_,
1795 y = tmpinset->descent(bv_,font);
1797 tmpinset->Edit(bv_, 0, y, 0);
1801 lt->CursorRight(bv_, false);
1803 moveCursorUpdate(false);
1804 owner_->showState();
1810 // This is soooo ugly. Isn`t it possible to make
1811 // it simpler? (Lgb)
1812 LyXText * lt = bv_->getLyXText();
1813 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1814 if (!lt->selection.mark())
1816 update(lt, BufferView::SELECT|BufferView::FITCUR);
1817 LyXCursor const cur = lt->cursor;
1819 lt->CursorLeft(bv_, false);
1820 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1821 lt->cursor.pos() < lt->cursor.par()->size() &&
1822 (lt->cursor.par()->GetChar(lt->cursor.pos()) ==
1823 LyXParagraph::META_INSET) &&
1824 lt->cursor.par()->GetInset(lt->cursor.pos()) &&
1825 (lt->cursor.par()->GetInset(lt->cursor.pos())->Editable()
1826 == Inset::HIGHLY_EDITABLE))
1828 Inset * tmpinset = lt->cursor.par()->GetInset(lt->cursor.pos());
1829 owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
1830 LyXFont const font = lt->GetFont(buffer_,
1834 : tmpinset->descent(bv_,font);
1837 tmpinset->width(bv_,font),
1842 lt->CursorRight(bv_, false);
1845 moveCursorUpdate(false);
1846 owner_->showState();
1852 LyXText * lt = bv_->getLyXText();
1854 if (!lt->selection.mark())
1856 update(lt, BufferView::UPDATE);
1859 moveCursorUpdate(false);
1860 owner_->showState();
1866 LyXText * lt = bv_->getLyXText();
1868 if (!lt->selection.mark())
1870 update(lt, BufferView::UPDATE);
1871 lt->CursorDown(bv_);
1873 moveCursorUpdate(false);
1874 owner_->showState();
1878 case LFUN_UP_PARAGRAPH:
1880 LyXText * lt = bv_->getLyXText();
1882 if (!lt->selection.mark())
1884 update(lt, BufferView::UPDATE);
1885 lt->CursorUpParagraph(bv_);
1887 moveCursorUpdate(false);
1888 owner_->showState();
1892 case LFUN_DOWN_PARAGRAPH:
1894 LyXText * lt = bv_->getLyXText();
1896 if (!lt->selection.mark())
1898 update(lt, BufferView::UPDATE);
1899 lt->CursorDownParagraph(bv_);
1901 moveCursorUpdate(false);
1902 owner_->showState();
1908 LyXText * lt = bv_->getLyXText();
1910 if (!lt->selection.mark())
1912 update(lt, BufferView::UPDATE);
1915 moveCursorUpdate(false);
1916 owner_->showState();
1922 LyXText * lt = bv_->getLyXText();
1924 if (!lt->selection.mark())
1926 update(lt, BufferView::UPDATE);
1929 moveCursorUpdate(false);
1930 owner_->showState();
1936 LyXText * lt = bv_->getLyXText();
1938 if (!lt->selection.mark())
1940 update(lt, BufferView::SELECT|BufferView::FITCUR);
1941 lt->CursorHome(bv_);
1943 moveCursorUpdate(false);
1944 owner_->showState();
1950 LyXText * lt = bv_->getLyXText();
1952 if (!lt->selection.mark())
1955 BufferView::SELECT|BufferView::FITCUR);
1958 moveCursorUpdate(false);
1959 owner_->showState();
1963 case LFUN_SHIFT_TAB:
1966 LyXText * lt = bv_->getLyXText();
1968 if (!lt->selection.mark())
1971 BufferView::SELECT|BufferView::FITCUR);
1974 moveCursorUpdate(false);
1975 owner_->showState();
1979 case LFUN_WORDRIGHT:
1981 LyXText * lt = bv_->getLyXText();
1983 if (!lt->selection.mark())
1985 update(lt, BufferView::SELECT|BufferView::FITCUR);
1986 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
1987 lt->CursorLeftOneWord(bv_);
1989 lt->CursorRightOneWord(bv_);
1991 moveCursorUpdate(false);
1992 owner_->showState();
1998 LyXText * lt = bv_->getLyXText();
2000 if (!lt->selection.mark())
2002 update(lt, BufferView::SELECT|BufferView::FITCUR);
2003 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2004 lt->CursorRightOneWord(bv_);
2006 lt->CursorLeftOneWord(bv_);
2008 moveCursorUpdate(false);
2009 owner_->showState();
2013 case LFUN_BEGINNINGBUF:
2015 LyXText * lt = bv_->getLyXText();
2017 if (!lt->selection.mark())
2020 BufferView::SELECT|BufferView::FITCUR);
2023 moveCursorUpdate(false);
2024 owner_->showState();
2030 LyXText * lt = bv_->getLyXText();
2032 if (!lt->selection.mark())
2035 BufferView::SELECT|BufferView::FITCUR);
2036 lt->CursorBottom(bv_);
2038 moveCursorUpdate(false);
2039 owner_->showState();
2043 /* cursor selection ---------------------------- */
2046 LyXText * lt = bv_->getLyXText();
2049 BufferView::SELECT|BufferView::FITCUR);
2050 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2051 lt->CursorLeft(bv_);
2053 lt->CursorRight(bv_);
2055 moveCursorUpdate(true);
2056 owner_->showState();
2062 LyXText * lt = bv_->getLyXText();
2065 BufferView::SELECT|BufferView::FITCUR);
2066 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2067 lt->CursorRight(bv_);
2069 lt->CursorLeft(bv_);
2071 moveCursorUpdate(true);
2072 owner_->showState();
2078 LyXText * lt = bv_->getLyXText();
2081 BufferView::SELECT|BufferView::FITCUR);
2084 moveCursorUpdate(true);
2085 owner_->showState();
2091 LyXText * lt = bv_->getLyXText();
2094 BufferView::SELECT|BufferView::FITCUR);
2095 lt->CursorDown(bv_);
2097 moveCursorUpdate(true);
2098 owner_->showState();
2102 case LFUN_UP_PARAGRAPHSEL:
2104 LyXText * lt = bv_->getLyXText();
2107 BufferView::SELECT|BufferView::FITCUR);
2108 lt->CursorUpParagraph(bv_);
2110 moveCursorUpdate(true);
2111 owner_->showState();
2115 case LFUN_DOWN_PARAGRAPHSEL:
2117 LyXText * lt = bv_->getLyXText();
2120 BufferView::SELECT|BufferView::FITCUR);
2121 lt->CursorDownParagraph(bv_);
2123 moveCursorUpdate(true);
2124 owner_->showState();
2130 LyXText * lt = bv_->getLyXText();
2132 update(lt, BufferView::SELECT|BufferView::FITCUR);
2135 moveCursorUpdate(true);
2136 owner_->showState();
2142 LyXText * lt = bv_->getLyXText();
2144 update(lt, BufferView::SELECT|BufferView::FITCUR);
2147 moveCursorUpdate(true);
2148 owner_->showState();
2154 LyXText * lt = bv_->getLyXText();
2156 update(lt, BufferView::SELECT|BufferView::FITCUR);
2157 lt->CursorHome(bv_);
2159 moveCursorUpdate(true);
2160 owner_->showState();
2166 LyXText * lt = bv_->getLyXText();
2168 update(lt, BufferView::SELECT|BufferView::FITCUR);
2171 moveCursorUpdate(true);
2172 owner_->showState();
2176 case LFUN_WORDRIGHTSEL:
2178 LyXText * lt = bv_->getLyXText();
2180 update(lt, BufferView::SELECT|BufferView::FITCUR);
2181 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2182 lt->CursorLeftOneWord(bv_);
2184 lt->CursorRightOneWord(bv_);
2186 moveCursorUpdate(true);
2187 owner_->showState();
2191 case LFUN_WORDLEFTSEL:
2193 LyXText * lt = bv_->getLyXText();
2195 update(lt, BufferView::SELECT|BufferView::FITCUR);
2196 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2197 lt->CursorRightOneWord(bv_);
2199 lt->CursorLeftOneWord(bv_);
2201 moveCursorUpdate(true);
2202 owner_->showState();
2206 case LFUN_BEGINNINGBUFSEL:
2208 LyXText * lt = bv_->getLyXText();
2210 if (lt->inset_owner)
2212 update(lt, BufferView::SELECT|BufferView::FITCUR);
2215 moveCursorUpdate(true);
2216 owner_->showState();
2220 case LFUN_ENDBUFSEL:
2222 LyXText * lt = bv_->getLyXText();
2224 if (lt->inset_owner)
2227 BufferView::SELECT|BufferView::FITCUR);
2228 lt->CursorBottom(bv_);
2230 moveCursorUpdate(true);
2231 owner_->showState();
2235 // --- text changing commands ------------------------
2236 case LFUN_BREAKLINE:
2238 LyXText * lt = bv_->getLyXText();
2241 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
2244 | BufferView::FITCUR
2245 | BufferView::CHANGE);
2246 moveCursorUpdate(false);
2250 case LFUN_PROTECTEDSPACE:
2252 LyXText * lt = bv_->getLyXText();
2254 LyXLayout const & style = textclasslist
2255 .Style(buffer_->params.textclass,
2256 lt->cursor.par()->GetLayout());
2258 if (style.free_spacing) {
2259 lt->InsertChar(bv_, ' ');
2262 | BufferView::FITCUR
2263 | BufferView::CHANGE);
2267 moveCursorUpdate(false);
2273 LyXText * lt = bv_->getLyXText();
2275 if (lt->selection.mark()) {
2279 | BufferView::FITCUR);
2280 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2283 lt->selection.mark(true);
2286 | BufferView::FITCUR);
2287 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2289 lt->selection.cursor = lt->cursor;
2295 LyXText * lt = bv_->getLyXText();
2297 if (!lt->selection.set()) {
2299 lt->selection.cursor = lt->cursor;
2302 | BufferView::FITCUR
2303 | BufferView::CHANGE);
2304 // It is possible to make it a lot faster still
2305 // just comment out the line below...
2310 moveCursorUpdate(false);
2311 owner_->showState();
2316 case LFUN_DELETE_SKIP:
2318 LyXText * lt = bv_->getLyXText();
2320 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2322 LyXCursor cursor = lt->cursor;
2324 if (!lt->selection.set()) {
2325 if (cursor.pos() == cursor.par()->size()) {
2326 lt->CursorRight(bv_);
2327 cursor = lt->cursor;
2328 if (cursor.pos() == 0
2329 && !(cursor.par()->params.spaceTop()
2330 == VSpace (VSpace::NONE))) {
2333 cursor.par()->params.lineTop(),
2334 cursor.par()->params.lineBottom(),
2335 cursor.par()->params.pagebreakTop(),
2336 cursor.par()->params.pagebreakBottom(),
2337 VSpace(VSpace::NONE),
2338 cursor.par()->params.spaceBottom(),
2339 cursor.par()->params.align(),
2340 cursor.par()->params.labelWidthString(), 0);
2341 lt->CursorLeft(bv_);
2344 | BufferView::FITCUR
2345 | BufferView::CHANGE);
2347 lt->CursorLeft(bv_);
2349 lt->selection.cursor = lt->cursor;
2352 | BufferView::FITCUR
2353 | BufferView::CHANGE);
2357 lt->selection.cursor = lt->cursor;
2360 | BufferView::FITCUR
2361 | BufferView::CHANGE);
2369 /* -------> Delete word forward. */
2370 case LFUN_DELETE_WORD_FORWARD:
2371 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2372 bv_->getLyXText()->DeleteWordForward(bv_);
2373 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2374 moveCursorUpdate(false);
2375 owner_->showState();
2378 /* -------> Delete word backward. */
2379 case LFUN_DELETE_WORD_BACKWARD:
2381 LyXText * lt = bv_->getLyXText();
2383 update(lt, BufferView::SELECT|BufferView::FITCUR);
2384 lt->DeleteWordBackward(bv_);
2387 | BufferView::FITCUR
2388 | BufferView::CHANGE);
2389 moveCursorUpdate(false);
2390 owner_->showState();
2394 /* -------> Kill to end of line. */
2395 case LFUN_DELETE_LINE_FORWARD:
2397 LyXText * lt = bv_->getLyXText();
2399 update(lt, BufferView::SELECT|BufferView::FITCUR);
2400 lt->DeleteLineForward(bv_);
2403 | BufferView::FITCUR
2404 | BufferView::CHANGE);
2405 moveCursorUpdate(false);
2409 /* -------> Set mark off. */
2412 LyXText * lt = bv_->getLyXText();
2415 update(lt, BufferView::SELECT|BufferView::FITCUR);
2416 lt->selection.cursor = lt->cursor;
2417 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2421 /* -------> Set mark on. */
2424 LyXText * lt = bv_->getLyXText();
2427 lt->selection.mark(true);
2428 update(lt, BufferView::SELECT|BufferView::FITCUR);
2429 lt->selection.cursor = lt->cursor;
2430 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2434 case LFUN_BACKSPACE:
2436 LyXText * lt = bv_->getLyXText();
2438 if (!lt->selection.set()) {
2439 if (owner_->getIntl()->getTrans().backspace()) {
2441 lt->selection.cursor = lt->cursor;
2444 | BufferView::FITCUR
2445 | BufferView::CHANGE);
2446 // It is possible to make it a lot faster still
2447 // just comment out the line below...
2453 owner_->showState();
2458 case LFUN_BACKSPACE_SKIP:
2460 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2461 LyXText * lt = bv_->getLyXText();
2463 LyXCursor cursor = lt->cursor;
2465 if (!lt->selection.set()) {
2466 if (cursor.pos() == 0
2467 && !(cursor.par()->params.spaceTop()
2468 == VSpace (VSpace::NONE))) {
2471 cursor.par()->params.lineTop(),
2472 cursor.par()->params.lineBottom(),
2473 cursor.par()->params.pagebreakTop(),
2474 cursor.par()->params.pagebreakBottom(),
2475 VSpace(VSpace::NONE), cursor.par()->params.spaceBottom(),
2476 cursor.par()->params.align(),
2477 cursor.par()->params.labelWidthString(), 0);
2480 | BufferView::FITCUR
2481 | BufferView::CHANGE);
2484 lt->selection.cursor = cursor;
2487 | BufferView::FITCUR
2488 | BufferView::CHANGE);
2495 case LFUN_BREAKPARAGRAPH:
2497 LyXText * lt = bv_->getLyXText();
2500 lt->BreakParagraph(bv_, 0);
2503 | BufferView::FITCUR
2504 | BufferView::CHANGE);
2505 lt->selection.cursor = lt->cursor;
2507 owner_->showState();
2511 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2513 LyXText * lt = bv_->getLyXText();
2516 lt->BreakParagraph(bv_, 1);
2519 | BufferView::FITCUR
2520 | BufferView::CHANGE);
2521 lt->selection.cursor = lt->cursor;
2523 owner_->showState();
2527 case LFUN_BREAKPARAGRAPH_SKIP:
2529 // When at the beginning of a paragraph, remove
2530 // indentation and add a "defskip" at the top.
2531 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2532 LyXText * lt = bv_->getLyXText();
2534 LyXCursor cursor = lt->cursor;
2537 if (cursor.pos() == 0) {
2538 if (cursor.par()->params.spaceTop() == VSpace(VSpace::NONE)) {
2541 cursor.par()->params.lineTop(),
2542 cursor.par()->params.lineBottom(),
2543 cursor.par()->params.pagebreakTop(),
2544 cursor.par()->params.pagebreakBottom(),
2545 VSpace(VSpace::DEFSKIP), cursor.par()->params.spaceBottom(),
2546 cursor.par()->params.align(),
2547 cursor.par()->params.labelWidthString(), 1);
2548 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2552 lt->BreakParagraph(bv_, 0);
2553 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2558 | BufferView::FITCUR
2559 | BufferView::CHANGE);
2560 lt->selection.cursor = cursor;
2562 owner_->showState();
2566 case LFUN_PARAGRAPH_SPACING:
2568 LyXText * lt = bv_->getLyXText();
2570 LyXParagraph * par = lt->cursor.par();
2571 Spacing::Space cur_spacing = par->params.spacing().getSpace();
2572 float cur_value = 1.0;
2573 if (cur_spacing == Spacing::Other) {
2574 cur_value = par->params.spacing().getValue();
2577 istringstream istr(argument.c_str());
2581 Spacing::Space new_spacing = cur_spacing;
2582 float new_value = cur_value;
2584 lyxerr << "Missing argument to `paragraph-spacing'"
2586 } else if (tmp == "single") {
2587 new_spacing = Spacing::Single;
2588 } else if (tmp == "onehalf") {
2589 new_spacing = Spacing::Onehalf;
2590 } else if (tmp == "double") {
2591 new_spacing = Spacing::Double;
2592 } else if (tmp == "other") {
2593 new_spacing = Spacing::Other;
2596 lyxerr << "new_value = " << tmpval << endl;
2599 } else if (tmp == "default") {
2600 new_spacing = Spacing::Default;
2602 lyxerr << _("Unknown spacing argument: ")
2603 << argument << endl;
2605 if (cur_spacing != new_spacing || cur_value != new_value) {
2606 par->params.spacing(Spacing(new_spacing, new_value));
2607 lt->RedoParagraph(bv_);
2610 | BufferView::FITCUR
2611 | BufferView::CHANGE);
2617 bv_->insertCorrectQuote();
2623 InsetCommandParams p;
2624 if (action == LFUN_HTMLURL)
2625 p.setCmdName("htmlurl");
2627 p.setCmdName("url");
2628 owner_->getDialogs()->createUrl( p.getAsString() );
2632 case LFUN_INSERT_URL:
2634 InsetCommandParams p;
2635 p.setFromString( argument );
2637 InsetUrl * inset = new InsetUrl( p );
2638 if (!insertInset(inset))
2641 updateInset( inset, true );
2645 case LFUN_INSET_TEXT:
2647 InsetText * new_inset = new InsetText;
2648 if (insertInset(new_inset))
2649 new_inset->Edit(bv_, 0, 0, 0);
2655 case LFUN_INSET_ERT:
2657 InsetERT * new_inset = new InsetERT;
2658 if (insertInset(new_inset))
2659 new_inset->Edit(bv_, 0, 0, 0);
2665 case LFUN_INSET_EXTERNAL:
2667 InsetExternal * new_inset = new InsetExternal;
2668 if (insertInset(new_inset))
2669 new_inset->Edit(bv_, 0, 0, 0);
2675 case LFUN_INSET_FOOTNOTE:
2677 InsetFoot * new_inset = new InsetFoot;
2678 if (insertInset(new_inset))
2679 new_inset->Edit(bv_, 0, 0, 0);
2685 case LFUN_INSET_MARGINAL:
2687 InsetMarginal * new_inset = new InsetMarginal;
2688 if (insertInset(new_inset))
2689 new_inset->Edit(bv_, 0, 0, 0);
2695 case LFUN_INSET_MINIPAGE:
2697 InsetMinipage * new_inset = new InsetMinipage;
2698 if (insertInset(new_inset))
2699 new_inset->Edit(bv_, 0, 0, 0);
2705 case LFUN_INSET_FLOAT:
2707 // check if the float type exist
2708 if (floatList.typeExist(argument)) {
2709 InsetFloat * new_inset = new InsetFloat(argument);
2710 if (insertInset(new_inset))
2711 new_inset->Edit(bv_, 0, 0, 0);
2715 lyxerr << "Non-existant float type: "
2716 << argument << endl;
2722 case LFUN_INSET_WIDE_FLOAT:
2724 // check if the float type exist
2725 if (floatList.typeExist(argument)) {
2726 InsetFloat * new_inset = new InsetFloat(argument);
2727 new_inset->wide(true);
2728 if (insertInset(new_inset))
2729 new_inset->Edit(bv_, 0, 0, 0);
2733 lyxerr << "Non-existant float type: "
2734 << argument << endl;
2740 case LFUN_INSET_LIST:
2742 InsetList * new_inset = new InsetList;
2743 if (insertInset(new_inset))
2744 new_inset->Edit(bv_, 0, 0, 0);
2750 case LFUN_INSET_THEOREM:
2752 InsetTheorem * new_inset = new InsetTheorem;
2753 if (insertInset(new_inset))
2754 new_inset->Edit(bv_, 0, 0, 0);
2760 case LFUN_INSET_CAPTION:
2762 // Do we have a locking inset...
2763 if (bv_->theLockingInset()) {
2764 lyxerr << "Locking inset code: "
2765 << static_cast<int>(bv_->theLockingInset()->LyxCode());
2766 InsetCaption * new_inset = new InsetCaption;
2767 new_inset->setOwner(bv_->theLockingInset());
2768 new_inset->SetAutoBreakRows(true);
2769 new_inset->SetDrawFrame(0, InsetText::LOCKED);
2770 new_inset->SetFrameColor(0, LColor::footnoteframe);
2771 if (insertInset(new_inset))
2772 new_inset->Edit(bv_, 0, 0, 0);
2779 case LFUN_INSET_TABULAR:
2783 if (!argument.empty())
2784 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2785 InsetTabular * new_inset =
2786 new InsetTabular(*buffer_, r, c);
2788 bv_->getLyXText()->real_current_font.isRightToLeft();
2789 if (!open_new_inset(new_inset, rtl))
2794 // --- lyxserver commands ----------------------------
2796 case LFUN_CHARATCURSOR:
2798 LyXParagraph::size_type pos = bv_->getLyXText()->cursor.pos();
2799 if (pos < bv_->getLyXText()->cursor.par()->size())
2800 owner_->getLyXFunc()->setMessage(
2801 tostr(bv_->getLyXText()->cursor.par()->GetChar(pos)));
2803 owner_->getLyXFunc()->setMessage("EOF");
2808 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2810 + tostr(bv_->getLyXText()->cursor.y()));
2815 #warning Should check sscanf for errors (Lgb)
2818 ::sscanf(argument.c_str(), " %d %d", &x, &y);
2819 bv_->getLyXText()->SetCursorFromCoordinates(bv_, x, y);
2823 case LFUN_GETLAYOUT:
2824 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2829 LyXFont & font = bv_->getLyXText()->current_font;
2830 if (font.shape() == LyXFont::ITALIC_SHAPE)
2831 owner_->getLyXFunc()->setMessage("E");
2832 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2833 owner_->getLyXFunc()->setMessage("N");
2835 owner_->getLyXFunc()->setMessage("0");
2842 LyXFont & font = bv_->getLyXText()->current_font;
2843 if (font.latex() == LyXFont::ON)
2844 owner_->getLyXFunc()->setMessage("L");
2846 owner_->getLyXFunc()->setMessage("0");
2850 // --- accented characters ---------------------------
2853 case LFUN_CIRCUMFLEX:
2863 case LFUN_SPECIAL_CARON:
2866 case LFUN_HUNG_UMLAUT:
2869 if (argument.empty()) {
2871 owner_->getLyXFunc()->handleKeyFunc(action);
2873 owner_->getLyXFunc()->handleKeyFunc(action);
2874 owner_->getIntl()->getTrans()
2875 .TranslateAndInsert(argument[0], bv_->getLyXText());
2876 update(bv_->getLyXText(),
2878 | BufferView::FITCUR
2879 | BufferView::CHANGE);
2883 // --- insert characters ----------------------------------------
2885 case LFUN_MATH_DELIM:
2886 case LFUN_INSERT_MATRIX:
2889 if (open_new_inset(new InsetFormula(false))) {
2890 bv_->theLockingInset()
2891 ->LocalDispatch(bv_, action, argument);
2897 case LFUN_INSERT_MATH:
2902 InsetFormula * f = new InsetFormula(true);
2904 f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
2908 case LFUN_MATH_DISPLAY:
2911 open_new_inset(new InsetFormula(true));
2915 case LFUN_MATH_MACRO:
2920 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2922 string const s1 = token(s, ' ', 1);
2923 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2924 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
2930 case LFUN_MATH_MODE: // Open or create a math inset
2933 open_new_inset(new InsetFormula);
2934 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2938 case LFUN_CITATION_INSERT:
2940 InsetCommandParams p;
2941 p.setFromString( argument );
2943 InsetCitation * inset = new InsetCitation( p );
2944 if (!insertInset(inset))
2947 updateInset( inset, true );
2951 case LFUN_INSERT_BIBTEX:
2953 // ale970405+lasgoutt970425
2954 // The argument can be up to two tokens separated
2955 // by a space. The first one is the bibstyle.
2956 string const db = token(argument, ' ', 0);
2957 string bibstyle = token(argument, ' ', 1);
2958 if (bibstyle.empty())
2961 InsetCommandParams p( "BibTeX", db, bibstyle );
2962 InsetBibtex * inset = new InsetBibtex(p);
2964 if (insertInset(inset)) {
2965 if (argument.empty())
2966 inset->Edit(bv_, 0, 0, 0);
2972 // BibTeX data bases
2973 case LFUN_BIBDB_ADD:
2975 InsetBibtex * inset =
2976 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2978 inset->addDatabase(argument);
2983 case LFUN_BIBDB_DEL:
2985 InsetBibtex * inset =
2986 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2988 inset->delDatabase(argument);
2993 case LFUN_BIBTEX_STYLE:
2995 InsetBibtex * inset =
2996 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
2998 inset->setOptions(argument);
3003 case LFUN_INDEX_CREATE:
3005 InsetCommandParams p( "index" );
3007 if (argument.empty()) {
3008 // Get the word immediately preceding the cursor
3009 LyXParagraph::size_type curpos =
3010 bv_->getLyXText()->cursor.pos() - 1;
3014 curstring = bv_->getLyXText()
3015 ->cursor.par()->GetWord(curpos);
3017 p.setContents( curstring );
3019 p.setContents( argument );
3022 owner_->getDialogs()->createIndex( p.getAsString() );
3026 case LFUN_INDEX_INSERT:
3028 InsetCommandParams p;
3029 p.setFromString(argument);
3030 InsetIndex * inset = new InsetIndex(p);
3032 if (!insertInset(inset))
3035 updateInset(inset, true);
3039 case LFUN_INDEX_INSERT_LAST:
3041 // Get word immediately preceding the cursor
3042 LyXParagraph::size_type curpos =
3043 bv_->getLyXText()->cursor.pos() - 1;
3044 // Can't do that at the beginning of a paragraph
3045 if (curpos < 0) break;
3047 string const curstring(bv_->getLyXText()
3048 ->cursor.par()->GetWord(curpos));
3050 InsetCommandParams p("index", curstring);
3051 InsetIndex * inset = new InsetIndex(p);
3053 if (!insertInset(inset))
3056 updateInset(inset, true);
3060 case LFUN_INDEX_PRINT:
3062 InsetCommandParams p("printindex");
3063 Inset * inset = new InsetPrintIndex(p);
3064 if (!insertInset(inset, "Standard"))
3069 case LFUN_PARENTINSERT:
3071 lyxerr << "arg " << argument << endl;
3072 InsetCommandParams p( "lyxparent", argument );
3073 Inset * inset = new InsetParent(p, *buffer_);
3074 if (!insertInset(inset, "Standard"))
3080 case LFUN_CHILD_INSERT:
3082 InsetInclude::Params p;
3083 p.cparams.setFromString(argument);
3084 p.masterFilename_ = buffer_->fileName();
3086 InsetInclude * inset = new InsetInclude(p);
3087 if (!insertInset(inset))
3090 updateInset(inset, true);
3091 bv_->owner()->getDialogs()->showInclude(inset);
3096 case LFUN_FLOAT_LIST:
3098 // We should check the argument for validity. (Lgb)
3099 Inset * inset = new InsetFloatList(argument);
3100 if (!insertInset(inset, "Standard"))
3105 case LFUN_INSERT_NOTE:
3109 case LFUN_SELFINSERT:
3111 if (argument.empty()) break;
3113 /* Automatically delete the currently selected
3114 * text and replace it with what is being
3115 * typed in now. Depends on lyxrc settings
3116 * "auto_region_delete", which defaults to
3119 LyXText * lt = bv_->getLyXText();
3121 if (lyxrc.auto_region_delete) {
3122 if (lt->selection.set()) {
3123 lt->CutSelection(bv_, false);
3126 | BufferView::FITCUR
3127 | BufferView::CHANGE);
3131 bv_->beforeChange(lt);
3132 LyXFont const old_font(lt->real_current_font);
3134 string::const_iterator cit = argument.begin();
3135 string::const_iterator end = argument.end();
3136 for (; cit != end; ++cit) {
3137 if (greek_kb_flag) {
3138 if (!math_insert_greek(bv_, *cit))
3139 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3141 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3146 | BufferView::FITCUR
3147 | BufferView::CHANGE);
3149 lt->selection.cursor = lt->cursor;
3150 moveCursorUpdate(false);
3152 // real_current_font.number can change so we need to
3153 // update the minibuffer
3154 if (old_font != lt->real_current_font)
3155 owner_->showState();
3160 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3162 time_t now_time_t = time(NULL);
3163 struct tm * now_tm = localtime(&now_time_t);
3164 setlocale(LC_TIME, "");
3166 if (!argument.empty())
3169 arg = lyxrc.date_insert_format;
3171 int const datetmp_len =
3172 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3174 LyXText * lt = bv_->getLyXText();
3176 for (int i = 0; i < datetmp_len; i++) {
3177 lt->InsertChar(bv_, datetmp[i]);
3180 | BufferView::FITCUR
3181 | BufferView::CHANGE);
3184 lt->selection.cursor = lt->cursor;
3185 moveCursorUpdate(false);
3189 case LFUN_UNKNOWN_ACTION:
3190 owner_->getLyXFunc()->setErrorMessage(N_("Unknow function!"));
3201 void BufferView::Pimpl::newline()
3204 LyXText * lt = bv_->getLyXText();
3208 | BufferView::FITCUR);
3209 lt->InsertChar(bv_, LyXParagraph::META_NEWLINE);
3212 | BufferView::FITCUR
3213 | BufferView::CHANGE);
3218 void BufferView::Pimpl::hfill()
3221 LyXText * lt = bv_->getLyXText();
3225 | BufferView::FITCUR);
3226 lt->InsertChar(bv_, LyXParagraph::META_HFILL);
3229 | BufferView::FITCUR
3230 | BufferView::CHANGE);
3235 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3239 update(lt, BufferView::SELECT|BufferView::FITCUR);
3240 InsetSpecialChar * new_inset =
3241 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3242 if (!insertInset(new_inset))
3245 updateInset(new_inset, true);
3250 void BufferView::Pimpl::menuSeparator()
3253 LyXText * lt = bv_->getLyXText();
3256 update(lt, BufferView::SELECT|BufferView::FITCUR);
3257 InsetSpecialChar * new_inset =
3258 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3259 insertInset(new_inset);
3264 void BufferView::Pimpl::endOfSentenceDot()
3268 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3269 InsetSpecialChar * new_inset =
3270 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3271 insertInset(new_inset);
3276 void BufferView::Pimpl::ldots()
3280 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3281 InsetSpecialChar * new_inset =
3282 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3283 insertInset(new_inset);
3288 void BufferView::Pimpl::hyphenationPoint()
3292 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3293 InsetSpecialChar * new_inset =
3294 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3295 insertInset(new_inset);
3300 void BufferView::Pimpl::insertNote()
3302 InsetInfo * new_inset = new InsetInfo();
3303 insertInset(new_inset);
3304 new_inset->Edit(bv_, 0, 0, 0);
3308 // Open and lock an updatable inset
3309 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3311 LyXText * lt = bv_->getLyXText();
3315 if (!insertInset(new_inset)) {
3320 LyXFont & font = lt->real_current_font;
3321 new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
3323 new_inset->Edit(bv_, 0, 0, 0);
3328 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3330 // if we are in a locking inset we should try to insert the
3331 // inset there otherwise this is a illegal function now
3332 if (bv_->theLockingInset()) {
3333 if (bv_->theLockingInset()->InsertInsetAllowed(inset))
3334 return bv_->theLockingInset()->InsertInset(bv_, inset);
3338 // not quite sure if we want this...
3339 bv_->text->SetCursorParUndo(buffer_);
3340 bv_->text->FreezeUndo();
3342 beforeChange(bv_->text);
3343 if (!lout.empty()) {
3344 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3345 bv_->text->BreakParagraph(bv_);
3346 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3348 if (bv_->text->cursor.par()->size()) {
3349 bv_->text->CursorLeft(bv_);
3351 bv_->text->BreakParagraph(bv_);
3352 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3355 pair<bool, LyXTextClass::size_type> lres =
3356 textclasslist.NumberOfLayout(buffer_->params
3358 LyXTextClass::size_type lay;
3359 if (lres.first != false) {
3363 // layout not fount using default "Standard" (0)
3367 bv_->text->SetLayout(bv_, lay);
3369 bv_->text->SetParagraph(bv_, 0, 0,
3371 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3375 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3377 bv_->text->current_font.setLatex(LyXFont::OFF);
3380 bv_->text->InsertInset(bv_, inset);
3381 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3383 bv_->text->UnFreezeUndo();
3388 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3393 // first check for locking insets
3394 if (bv_->theLockingInset()) {
3395 if (bv_->theLockingInset() == inset) {
3396 if (bv_->text->UpdateInset(bv_, inset)) {
3399 buffer_->markDirty();
3404 } else if (bv_->theLockingInset()->UpdateInsetInInset(bv_, inset)) {
3405 if (bv_->text->UpdateInset(bv_,
3406 bv_->theLockingInset())) {
3409 buffer_->markDirty();
3417 // then check the current buffer
3420 update(bv_->text, BufferView::UPDATE);
3421 if (bv_->text->UpdateInset(bv_, inset)) {
3425 | BufferView::FITCUR
3426 | BufferView::CHANGE);
3428 update(bv_->text, SELECT);
3436 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3439 if (!available()) return;
3442 beforeChange(bv_->text);
3443 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3447 bv_->text->cursor.par()->GetChar(bv_->text->cursor.pos()) == LyXParagraph::META_INSET) {
3448 Inset const * inset = bv_->text->cursor.par()->GetInset(bv_->text->cursor.pos());
3449 if (find(codes.begin(), codes.end(), inset->LyxCode())
3452 static_cast<InsetCommand const *>(inset)->getContents();
3455 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3456 if (bv_->text->cursor.pos()
3457 || bv_->text->cursor.par() != bv_->text->FirstParagraph()) {
3458 LyXCursor tmp = bv_->text->cursor;
3459 bv_->text->cursor.par(bv_->text->FirstParagraph());
3460 bv_->text->cursor.pos(0);
3461 if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
3462 bv_->text->cursor = tmp;
3463 bv_->owner()->message(_("No more insets"));
3466 bv_->owner()->message(_("No more insets"));
3469 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3470 bv_->text->selection.cursor = bv_->text->cursor;
3474 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3476 gotoInset(vector<Inset::Code>(1, code), same_content);