12 #include "BufferView_pimpl.h"
14 #include "lyxscreen.h"
18 #include "commandtags.h"
21 #include "bufferview_funcs.h"
22 #include "TextCache.h"
23 #include "bufferlist.h"
24 #include "lyx_gui_misc.h"
27 #include "support/LAssert.h"
28 #include "frontends/Dialogs.h"
29 #include "insets/insetbib.h"
30 #include "insets/insettext.h"
31 /// added for Dispatch functions
33 #include "frontends/FileDialog.h"
35 #include "FloatList.h"
36 #include "support/filetools.h"
37 #include "support/lyxfunctional.h"
38 #include "insets/inseturl.h"
39 #include "insets/insetlatexaccent.h"
40 #include "insets/insettoc.h"
41 #include "insets/insetref.h"
42 #include "insets/insetparent.h"
43 #include "insets/insetindex.h"
44 #include "insets/insetinfo.h"
45 #include "insets/insetinclude.h"
46 #include "insets/insetcite.h"
47 #include "insets/insetert.h"
48 #include "insets/insetexternal.h"
49 #include "insets/insetgraphics.h"
50 #include "insets/insetfoot.h"
51 #include "insets/insetmarginal.h"
52 #include "insets/insetminipage.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetlist.h"
55 #include "insets/insettabular.h"
56 #include "insets/insettheorem.h"
57 #include "insets/insetcaption.h"
58 #include "insets/insetfloatlist.h"
59 #include "insets/insetspecialchar.h"
60 #include "mathed/formulamacro.h"
61 #include "mathed/formula.h"
63 #include "ParagraphParameters.h"
65 extern LyXTextClass::size_type current_layout;
66 extern int greek_kb_flag;
77 /* the selection possible is needed, that only motion events are
78 * used, where the bottom press event was on the drawing area too */
79 bool selection_possible = false;
81 extern BufferList bufferlist;
82 extern char ascii_type;
84 extern bool math_insert_greek(BufferView *, char);
85 extern void sigchldhandler(pid_t pid, int * status);
86 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
90 const unsigned int saved_positions_num = 20;
95 XSync(fl_get_display(), 0);
99 void SetXtermCursor(Window win)
101 static Cursor cursor;
102 static bool cursor_undefined = true;
103 if (cursor_undefined){
104 cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
105 XFlush(fl_get_display());
106 cursor_undefined = false;
108 XDefineCursor(fl_get_display(), win, cursor);
109 XFlush(fl_get_display());
115 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
116 int xpos, int ypos, int width, int height)
117 : bv_(b), owner_(o), buffer_(0),
118 current_scrollbar_value(0), cursor_timeout(400),
119 workarea_(xpos, ypos, width, height), using_xterm_cursor(false),
123 workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
124 workarea_.workAreaExpose
125 .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
126 workarea_.workAreaEnter
127 .connect(slot(this, &BufferView::Pimpl::enterView));
128 workarea_.workAreaLeave
129 .connect(slot(this, &BufferView::Pimpl::leaveView));
130 workarea_.workAreaButtonPress
131 .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
132 workarea_.workAreaButtonRelease
134 &BufferView::Pimpl::workAreaButtonRelease));
135 workarea_.workAreaMotionNotify
136 .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
137 workarea_.workAreaDoubleClick
138 .connect(slot(this, &BufferView::Pimpl::doubleClick));
139 workarea_.workAreaTripleClick
140 .connect(slot(this, &BufferView::Pimpl::tripleClick));
141 workarea_.workAreaKeyPress
142 .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
144 cursor_timeout.timeout.connect(slot(this,
145 &BufferView::Pimpl::cursorToggle));
146 cursor_timeout.start();
147 workarea_.setFocus();
148 saved_positions.resize(saved_positions_num);
152 Painter & BufferView::Pimpl::painter()
154 return workarea_.getPainter();
158 void BufferView::Pimpl::buffer(Buffer * b)
160 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
164 buffer_->delUser(bv_);
166 // Put the old text into the TextCache, but
167 // only if the buffer is still loaded.
168 // Also set the owner of the test to 0
169 // bv_->text->owner(0);
170 textcache.add(buffer_, workarea_.workWidth(), bv_->text);
171 if (lyxerr.debugging())
172 textcache.show(lyxerr, "BufferView::buffer");
177 // Set current buffer
180 if (bufferlist.getState() == BufferList::CLOSING) return;
183 // screen is always deleted when the buffer is changed.
186 // If we are closing the buffer, use the first buffer as current
188 buffer_ = bufferlist.first();
192 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
193 buffer_->addUser(bv_);
194 // If we don't have a text object for this, we make one
195 if (bv_->text == 0) {
196 resizeCurrentBuffer();
201 bv_->text->first = screen_->TopCursorVisible(bv_->text);
202 owner_->updateMenubar();
203 owner_->updateToolbar();
204 // Similarly, buffer-dependent dialogs should be updated or
205 // hidden. This should go here because some dialogs (eg ToC)
206 // require bv_->text.
207 owner_->getDialogs()->updateBufferDependent(true);
211 lyxerr[Debug::INFO] << " No Buffer!" << endl;
212 owner_->updateMenubar();
213 owner_->updateToolbar();
214 owner_->getDialogs()->hideBufferDependent();
218 // Also remove all remaining text's from the testcache.
219 // (there should not be any!) (if there is any it is a
221 if (lyxerr.debugging())
222 textcache.show(lyxerr, "buffer delete all");
225 // should update layoutchoice even if we don't have a buffer.
226 owner_->updateLayoutChoice();
228 owner_->updateWindowTitle();
232 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
234 workarea_.resize(xpos, ypos, width, height);
235 update(bv_->text, SELECT);
240 void BufferView::Pimpl::resize()
243 resizeCurrentBuffer();
247 void BufferView::Pimpl::redraw()
249 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
254 bool BufferView::Pimpl::fitCursor(LyXText * text)
256 lyx::Assert(screen_.get());
258 bv_->owner()->getDialogs()->updateParagraph();
260 bool const ret = screen_->FitCursor(text, bv_);
267 void BufferView::Pimpl::redoCurrentBuffer()
269 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
270 if (buffer_ && bv_->text) {
272 owner_->updateLayoutChoice();
277 int BufferView::Pimpl::resizeCurrentBuffer()
279 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
282 Paragraph * selstartpar = 0;
283 Paragraph * selendpar = 0;
284 UpdatableInset * the_locking_inset = 0;
286 Paragraph::size_type pos = 0;
287 Paragraph::size_type selstartpos = 0;
288 Paragraph::size_type selendpos = 0;
289 bool selection = false;
290 bool mark_set = false;
292 owner_->prohibitInput();
294 owner_->message(_("Formatting document..."));
297 par = bv_->text->cursor.par();
298 pos = bv_->text->cursor.pos();
299 selstartpar = bv_->text->selection.start.par();
300 selstartpos = bv_->text->selection.start.pos();
301 selendpar = bv_->text->selection.end.par();
302 selendpos = bv_->text->selection.end.pos();
303 selection = bv_->text->selection.set();
304 mark_set = bv_->text->selection.mark();
305 the_locking_inset = bv_->theLockingInset();
307 bv_->text = new LyXText(bv_);
309 // See if we have a text in TextCache that fits
310 // the new buffer_ with the correct width.
311 bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
313 if (lyxerr.debugging()) {
314 lyxerr << "Found a LyXText that fits:\n";
315 textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
317 // Set the owner of the newly found text
318 // bv_->text->owner(bv_);
319 if (lyxerr.debugging())
320 textcache.show(lyxerr, "resizeCurrentBuffer");
322 bv_->text = new LyXText(bv_);
328 bv_->text->selection.set(true);
329 /* at this point just to avoid the Delete-Empty-Paragraph
330 * Mechanism when setting the cursor */
331 bv_->text->selection.mark(mark_set);
333 bv_->text->setCursor(bv_, selstartpar, selstartpos);
334 bv_->text->selection.cursor = bv_->text->cursor;
335 bv_->text->setCursor(bv_, selendpar, selendpos);
336 bv_->text->setSelection(bv_);
337 bv_->text->setCursor(bv_, par, pos);
339 bv_->text->setCursor(bv_, par, pos);
340 bv_->text->selection.cursor = bv_->text->cursor;
341 bv_->text->selection.set(false);
343 // remake the inset locking
344 bv_->theLockingInset(the_locking_inset);
346 bv_->text->first = screen_->TopCursorVisible(bv_->text);
347 buffer_->resizeInsets(bv_);
348 // this will scroll the screen such that the cursor becomes visible
353 owner_->allowInput();
355 /// clear the "Formatting Document" message
358 /// get rid of the splash screen if it's not gone already
359 owner_->getDialogs()->destroySplash();
365 void BufferView::Pimpl::updateScreen()
367 // Regenerate the screen.
368 screen_.reset(new LyXScreen(workarea_));
372 void BufferView::Pimpl::updateScrollbar()
374 /* If the text is smaller than the working area, the scrollbar
375 * maximum must be the working area height. No scrolling will
379 workarea_.setScrollbar(0, 1.0);
383 unsigned long const text_height = bv_->text->height;
385 double const lineh = bv_->text->defaultHeight();
386 double const slider_size = 1.0 / double(text_height);
388 static long old_text_height;
389 static double old_lineh;
390 static double old_slider_size;
392 if (text_height != old_text_height) {
393 workarea_.setScrollbarBounds(0, text_height - workarea_.height());
394 old_text_height = text_height;
396 if (lineh != old_lineh) {
397 workarea_.setScrollbarIncrements(lineh);
400 if (current_scrollbar_value != bv_->text->first
401 || slider_size != old_slider_size) {
402 current_scrollbar_value = bv_->text->first;
403 workarea_.setScrollbar(current_scrollbar_value, slider_size);
404 old_slider_size = slider_size;
409 // Callback for scrollbar slider
410 void BufferView::Pimpl::scrollCB(double value)
412 if (!buffer_) return;
414 current_scrollbar_value = long(value);
415 if (current_scrollbar_value < 0)
416 current_scrollbar_value = 0;
421 screen_->Draw(bv_->text, bv_, current_scrollbar_value);
423 if (!lyxrc.cursor_follows_scrollbar) {
428 LyXText * vbt = bv_->text;
430 int const height = vbt->defaultHeight();
431 int const first = static_cast<int>((bv_->text->first + height));
432 int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
434 if (vbt->cursor.y() < first)
435 vbt->setCursorFromCoordinates(bv_, 0, first);
436 else if (vbt->cursor.y() > last)
437 vbt->setCursorFromCoordinates(bv_, 0, last);
443 int BufferView::Pimpl::scrollUp(long time)
445 if (!buffer_) return 0;
446 if (!screen_.get()) return 0;
448 double value = workarea_.getScrollbarValue();
450 if (value == 0) return 0;
452 float add_value = (bv_->text->defaultHeight()
453 + float(time) * float(time) * 0.125);
455 if (add_value > workarea_.height())
456 add_value = float(workarea_.height() -
457 bv_->text->defaultHeight());
464 workarea_.setScrollbarValue(value);
471 int BufferView::Pimpl::scrollDown(long time)
473 if (!buffer_) return 0;
474 if (!screen_.get()) return 0;
476 double value = workarea_.getScrollbarValue();
477 pair<float, float> p = workarea_.getScrollbarBounds();
478 double const max = p.second;
480 if (value == max) return 0;
482 float add_value = (bv_->text->defaultHeight()
483 + float(time) * float(time) * 0.125);
485 if (add_value > workarea_.height())
486 add_value = float(workarea_.height() -
487 bv_->text->defaultHeight());
494 workarea_.setScrollbarValue(value);
501 void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, unsigned int state)
503 bv_->owner()->getLyXFunc()->processKeySym(keysym, state);
507 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
509 // Only use motion with button 1
510 if (!(state & Button1MotionMask))
513 if (!buffer_ || !screen_.get()) return;
515 // Check for inset locking
516 if (bv_->theLockingInset()) {
517 LyXCursor cursor = bv_->text->cursor;
518 LyXFont font = bv_->text->getFont(buffer_,
519 cursor.par(), cursor.pos());
520 int width = bv_->theLockingInset()->width(bv_, font);
521 int inset_x = font.isVisibleRightToLeft()
522 ? cursor.x() - width : cursor.x();
523 int start_x = inset_x + bv_->theLockingInset()->scroll();
524 bv_->theLockingInset()->
525 insetMotionNotify(bv_,
527 y - cursor.y() + bv_->text->first,
532 /* The test for not selection possible is needed, that only motion
533 events are used, where the bottom press event was on
534 the drawing area too */
535 if (!selection_possible)
538 screen_->HideCursor();
540 bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
542 if (!bv_->text->selection.set())
543 update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
545 bv_->text->setSelection(bv_);
546 screen_->ToggleToggle(bv_->text, bv_);
547 fitCursor(bv_->text);
548 screen_->ShowCursor(bv_->text, bv_);
552 // Single-click on work area
553 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
556 if (!buffer_ || !screen_.get()) return;
558 Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
560 // ok ok, this is a hack.
561 if (button == 4 || button == 5) {
564 scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc
567 scrollDown(lyxrc.wheel_jump);
572 if (bv_->theLockingInset()) {
573 // We are in inset locking mode
575 /* Check whether the inset was hit. If not reset mode,
576 otherwise give the event to the inset */
577 if (inset_hit == bv_->theLockingInset()) {
578 bv_->theLockingInset()->
579 insetButtonPress(bv_,
584 bv_->unlockInset(bv_->theLockingInset());
589 selection_possible = true;
590 screen_->HideCursor();
592 int const screen_first = bv_->text->first;
594 // Middle button press pastes if we have a selection
595 bool paste_internally = false;
597 && bv_->text->selection.set()) {
598 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
599 paste_internally = true;
602 // Clear the selection
603 screen_->ToggleSelection(bv_->text, bv_);
604 bv_->text->clearSelection(bv_);
605 bv_->text->fullRebreak(bv_);
606 screen_->Update(bv_->text, bv_);
609 // Single left click in math inset?
610 if ((inset_hit != 0) &&
611 (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
612 // Highly editable inset, like math
613 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
614 selection_possible = false;
615 owner_->updateLayoutChoice();
616 owner_->message(inset->editMessage());
617 inset->insetButtonPress(bv_, xpos, ypos, button);
618 inset->edit(bv_, xpos, ypos, button);
622 // Right click on a footnote flag opens float menu
624 selection_possible = false;
628 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
629 bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
630 bv_->text->finishUndo();
631 bv_->text->selection.cursor = bv_->text->cursor;
632 bv_->text->cursor.x_fix(bv_->text->cursor.x());
634 owner_->updateLayoutChoice();
635 if (fitCursor(bv_->text)) {
636 selection_possible = false;
639 // Insert primary selection with middle mouse
640 // if there is a local selection in the current buffer,
643 if (paste_internally)
644 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
646 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
648 selection_possible = false;
654 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
660 LyXText * text = bv_->getLyXText();
662 if (text->bv_owner && bv_->theLockingInset())
665 if (screen_.get() && button == 1) {
666 if (text->bv_owner) {
667 screen_->HideCursor();
668 screen_->ToggleSelection(text, bv_);
669 text->selectWord(bv_);
670 screen_->ToggleSelection(text, bv_, false);
672 text->selectWord(bv_);
674 /* This will fit the cursor on the screen
676 update(text, BufferView::SELECT|BufferView::FITCUR);
681 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
687 LyXText * text = bv_->getLyXText();
689 if (text->bv_owner && bv_->theLockingInset())
692 if (screen_.get() && (button == 1)) {
693 screen_->HideCursor();
694 screen_->ToggleSelection(text, bv_);
695 text->cursorHome(bv_);
696 text->selection.cursor = text->cursor;
697 text->cursorEnd(bv_);
698 text->setSelection(bv_);
699 screen_->ToggleSelection(text, bv_, false);
700 /* This will fit the cursor on the screen
702 update(text, BufferView::SELECT|BufferView::FITCUR);
707 void BufferView::Pimpl::enterView()
709 if (active() && available()) {
710 SetXtermCursor(workarea_.getWin());
711 using_xterm_cursor = true;
716 void BufferView::Pimpl::leaveView()
718 if (using_xterm_cursor) {
719 XUndefineCursor(fl_get_display(), workarea_.getWin());
720 using_xterm_cursor = false;
725 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
728 if (!buffer_ || !screen_.get()) return;
730 // If we hit an inset, we have the inset coordinates in these
731 // and inset_hit points to the inset. If we do not hit an
732 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
733 Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
735 if (bv_->theLockingInset()) {
736 // We are in inset locking mode.
738 /* LyX does a kind of work-area grabbing for insets.
739 Only a ButtonPress Event outside the inset will
740 force a insetUnlock. */
741 bv_->theLockingInset()->
742 insetButtonRelease(bv_, x, y, button);
746 selection_possible = false;
754 // Did we hit an editable inset?
756 // Inset like error, notes and figures
757 selection_possible = false;
759 // CHECK fix this proper in 0.13
761 // Following a ref shouldn't issue
762 // a push on the undo-stack
763 // anylonger, now that we have
764 // keybindings for following
765 // references and returning from
766 // references. IMHO though, it
767 // should be the inset's own business
768 // to push or not push on the undo
769 // stack. They don't *have* to
770 // alter the document...
772 // ...or maybe the SetCursorParUndo()
773 // below isn't necessary at all anylonger?
774 if (inset_hit->lyxCode() == Inset::REF_CODE) {
775 bv_->text->setCursorParUndo(buffer_);
778 owner_->message(inset_hit->editMessage());
780 if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
781 // Highly editable inset, like math
782 UpdatableInset *inset = (UpdatableInset *)inset_hit;
783 inset->insetButtonRelease(bv_, x, y, button);
785 inset_hit->insetButtonRelease(bv_, x, y, button);
786 inset_hit->edit(bv_, x, y, button);
791 // check whether we want to open a float
795 if (bv_->text->cursor.pos() <
796 bv_->text->cursor.par()->size()) {
797 c = bv_->text->cursor.par()->
798 getChar(bv_->text->cursor.pos());
800 if (bv_->text->cursor.pos() - 1 >= 0) {
801 c = bv_->text->cursor.par()->
802 getChar(bv_->text->cursor.pos() - 1);
805 selection_possible = false;
810 // Maybe we want to edit a bibitem ale970302
811 if (bv_->text->cursor.par()->bibkey && x < 20 +
812 bibitemMaxWidth(bv_, textclasslist.
814 params.textclass).defaultfont())) {
815 bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
823 * Returns an inset if inset was hit. 0 otherwise.
824 * If hit, the coordinates are changed relative to the inset.
825 * Otherwise coordinates are not changed, and false is returned.
827 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
828 unsigned int /* button */)
833 int y_tmp = y + text->first;
836 text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
837 text->setCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
840 if (cursor.pos() < cursor.par()->size()
841 && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
842 && cursor.par()->getInset(cursor.pos())
843 && cursor.par()->getInset(cursor.pos())->editable()) {
845 // Check whether the inset really was hit
846 Inset * tmpinset = cursor.par()->getInset(cursor.pos());
847 LyXFont font = text->getFont(buffer_,
848 cursor.par(), cursor.pos());
849 int const width = tmpinset->width(bv_, font);
850 int const inset_x = font.isVisibleRightToLeft()
851 ? cursor.x() - width : cursor.x();
852 int const start_x = inset_x + tmpinset->scroll();
853 int const end_x = inset_x + width;
855 if (x > start_x && x < end_x
856 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
857 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
858 text->setCursor(bv_, cursor.par(),cursor.pos(), true);
860 // The origin of an inset is on the baseline
861 y = y_tmp - (text->cursor.y());
866 if ((cursor.pos() - 1 >= 0) &&
867 (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
868 (cursor.par()->getInset(cursor.pos() - 1)) &&
869 (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
870 Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
871 LyXFont font = text->getFont(buffer_, cursor.par(),
873 int const width = tmpinset->width(bv_, font);
874 int const inset_x = font.isVisibleRightToLeft()
875 ? cursor.x() : cursor.x() - width;
876 int const start_x = inset_x + tmpinset->scroll();
877 int const end_x = inset_x + width;
879 if (x > start_x && x < end_x
880 && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
881 && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
883 if (move_cursor && (tmpinset != bv_->theLockingInset()))
885 text->setCursor(bv_, cursor.par(),
886 cursor.pos() - 1, true);
888 // The origin of an inset is on the baseline
889 y = y_tmp - (text->cursor.y());
897 void BufferView::Pimpl::workAreaExpose()
899 static int work_area_width;
900 static unsigned int work_area_height;
902 bool const widthChange = workarea_.workWidth() != work_area_width;
903 bool const heightChange = workarea_.height() != work_area_height;
905 // update from work area
906 work_area_width = workarea_.workWidth();
907 work_area_height = workarea_.height();
910 // The visible LyXView need a resize
913 // Remove all texts from the textcache
914 // This is not _really_ what we want to do. What
915 // we really want to do is to delete in textcache
916 // that does not have a BufferView with matching
917 // width, but as long as we have only one BufferView
918 // deleting all gives the same result.
919 if (lyxerr.debugging())
920 textcache.show(lyxerr, "Expose delete all");
922 } else if (heightChange) {
923 // Rebuild image of current screen
925 // fitCursor() ensures we don't jump back
926 // to the start of the document on vertical
928 fitCursor(bv_->text);
930 // The main window size has changed, repaint most stuff
932 } else if (screen_.get())
933 screen_->Redraw(bv_->text, bv_);
935 // Grey box when we don't have a buffer
939 // always make sure that the scrollbar is sane.
941 owner_->updateLayoutChoice();
946 void BufferView::Pimpl::update()
949 (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()))
951 screen_->Update(bv_->text, bv_);
955 // Values used when calling update:
957 // -2 - update, move sel_cursor if selection, fitcursor
958 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
959 // 0 - update, move sel_cursor if selection, fitcursor
960 // 1 - update, move sel_cursor if selection, fitcursor, mark dirty
961 // 3 - update, move sel_cursor if selection
964 // a simple redraw of the parts that need refresh
966 // move sel_cursor if selection -
967 // the text's sel_cursor is moved if there is selection is progress
970 // fitCursor() is called and the scrollbar updated
973 // the buffer is marked dirty.
982 // UPDATE_ONLY = UPDATE;
983 // UPDATE_SELECT = UPDATE | SELECT;
984 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
985 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
987 // update(-3) -> update(0) -> update(0) -> update(UPDATE)
988 // update(-2) -> update(1 + 2) -> update(3) -> update(SELECT|FITCUR)
989 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
990 // update(1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
991 // update(3) -> update(1) -> update(1) -> update(SELECT)
993 void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
995 owner_->updateLayoutChoice();
997 if (!text->selection.set() && (f & SELECT)) {
998 text->selection.cursor = text->cursor;
1001 text->fullRebreak(bv_);
1003 if (text->inset_owner) {
1004 text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
1005 updateInset(text->inset_owner, true);
1014 buffer_->markDirty();
1019 // Callback for cursor timer
1020 void BufferView::Pimpl::cursorToggle()
1022 // Quite a nice place for asyncron Inset updating, isn't it?
1023 // Actually no! This is run even if no buffer exist... so (Lgb)
1025 cursor_timeout.restart();
1030 int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1031 if (pid == -1) // error find out what is wrong
1032 ; // ignore it for now.
1034 sigchldhandler(pid, &status);
1036 updatelist.update(bv_);
1038 if (!screen_.get()) {
1039 cursor_timeout.restart();
1043 if (!bv_->theLockingInset()) {
1044 screen_->CursorToggle(bv_->text, bv_);
1046 bv_->theLockingInset()->toggleInsetCursor(bv_);
1049 cursor_timeout.restart();
1053 void BufferView::Pimpl::cursorPrevious(LyXText * text)
1055 if (!text->cursor.row()->previous())
1058 int y = text->first;
1059 if (text->inset_owner)
1060 y += bv_->text->first;
1061 Row * cursorrow = text->cursor.row();
1062 text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
1063 bv_->text->finishUndo();
1064 // This is to allow jumping over large insets
1065 if ((cursorrow == text->cursor.row()))
1066 text->cursorUp(bv_);
1068 if (text->inset_owner ||
1069 text->cursor.row()->height() < workarea_.height())
1070 screen_->Draw(bv_->text, bv_,
1072 - text->cursor.row()->baseline()
1073 + text->cursor.row()->height()
1074 - workarea_.height() + 1 );
1079 void BufferView::Pimpl::cursorNext(LyXText * text)
1081 if (!text->cursor.row()->next())
1084 int y = text->first + workarea_.height();
1085 // if (text->inset_owner)
1086 // y += bv_->text->first;
1087 text->getRowNearY(y);
1089 Row * cursorrow = text->cursor.row();
1090 text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
1091 bv_->text->finishUndo();
1092 // This is to allow jumping over large insets
1093 if ((cursorrow == bv_->text->cursor.row()))
1094 text->cursorDown(bv_);
1096 if (text->inset_owner ||
1097 text->cursor.row()->height() < workarea_.height())
1098 screen_->Draw(bv_->text, bv_, text->cursor.y() -
1099 text->cursor.row()->baseline());
1104 bool BufferView::Pimpl::available() const
1106 if (buffer_ && bv_->text) return true;
1111 void BufferView::Pimpl::beforeChange(LyXText * text)
1114 text->clearSelection(bv_);
1118 void BufferView::Pimpl::savePosition(unsigned int i)
1120 if (i >= saved_positions_num)
1122 saved_positions[i] = Position(buffer_->fileName(),
1123 bv_->text->cursor.par()->id(),
1124 bv_->text->cursor.pos());
1127 str << _("Saved bookmark") << ' ' << i;
1128 owner_->message(str.str().c_str());
1133 void BufferView::Pimpl::restorePosition(unsigned int i)
1135 if (i >= saved_positions_num)
1138 string const fname = saved_positions[i].filename;
1140 beforeChange(bv_->text);
1142 if (fname != buffer_->fileName()) {
1143 Buffer * b = bufferlist.exists(fname) ?
1144 bufferlist.getBuffer(fname) :
1145 bufferlist.loadLyXFile(fname); // don't ask, just load it
1146 if (b != 0 ) buffer(b);
1149 Paragraph * par = bv_->text->getParFromID(saved_positions[i].par_id);
1153 bv_->text->setCursor(bv_, par,
1154 min(par->size(), saved_positions[i].par_pos));
1156 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1159 str << _("Moved to bookmark") << ' ' << i;
1160 owner_->message(str.str().c_str());
1165 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
1167 if (i >= saved_positions_num)
1170 return !saved_positions[i].filename.empty();
1174 void BufferView::Pimpl::setState()
1176 if (!lyxrc.rtl_support)
1179 LyXText * text = bv_->getLyXText();
1180 if (text->real_current_font.isRightToLeft()
1183 text->real_current_font.latex() != LyXFont::ON
1186 if (owner_->getIntl()->keymap == Intl::PRIMARY)
1187 owner_->getIntl()->KeyMapSec();
1189 if (owner_->getIntl()->keymap == Intl::SECONDARY)
1190 owner_->getIntl()->KeyMapPrim();
1195 void BufferView::Pimpl::insetSleep()
1197 if (bv_->theLockingInset() && !inset_slept) {
1198 bv_->theLockingInset()->getCursorPos(bv_, bv_->slx, bv_->sly);
1199 bv_->theLockingInset()->insetUnlock(bv_);
1205 void BufferView::Pimpl::insetWakeup()
1207 if (bv_->theLockingInset() && inset_slept) {
1208 bv_->theLockingInset()->edit(bv_, bv_->slx, bv_->sly, 0);
1209 inset_slept = false;
1214 void BufferView::Pimpl::insetUnlock()
1216 if (bv_->theLockingInset()) {
1218 bv_->theLockingInset()->insetUnlock(bv_);
1219 bv_->theLockingInset(0);
1220 bv_->text->finishUndo();
1221 inset_slept = false;
1226 bool BufferView::Pimpl::focus() const
1228 return workarea_.hasFocus();
1232 void BufferView::Pimpl::focus(bool f)
1234 if (f) workarea_.setFocus();
1238 bool BufferView::Pimpl::active() const
1240 return workarea_.active();
1244 bool BufferView::Pimpl::belowMouse() const
1246 return workarea_.belowMouse();
1250 void BufferView::Pimpl::showCursor()
1253 screen_->ShowCursor(bv_->text, bv_);
1257 void BufferView::Pimpl::hideCursor()
1260 screen_->HideCursor();
1264 void BufferView::Pimpl::toggleSelection(bool b)
1267 screen_->ToggleSelection(bv_->text, bv_, b);
1271 void BufferView::Pimpl::toggleToggle()
1274 screen_->ToggleToggle(bv_->text, bv_);
1278 void BufferView::Pimpl::center()
1280 beforeChange(bv_->text);
1281 if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
1282 screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
1284 screen_->Draw(bv_->text, bv_, 0);
1286 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
1291 void BufferView::Pimpl::pasteClipboard(bool asPara)
1293 if (!buffer_) return;
1295 screen_->HideCursor();
1296 beforeChange(bv_->text);
1298 string const clip(workarea_.getClipboard());
1300 if (clip.empty()) return;
1303 bv_->text->insertStringAsParagraphs(bv_, clip);
1305 bv_->text->insertStringAsLines(bv_, clip);
1307 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1311 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
1313 workarea_.putClipboard(stuff);
1318 * Dispatch functions for actions which can be valid for BufferView->text
1319 * and/or InsetText->text!!!
1324 void BufferView::Pimpl::moveCursorUpdate(bool selecting)
1326 LyXText * lt = bv_->getLyXText();
1328 if (selecting || lt->selection.mark()) {
1329 lt->setSelection(bv_);
1333 update(lt, BufferView::SELECT|BufferView::FITCUR);
1336 /* ---> Everytime the cursor is moved, show the current font state. */
1337 // should this too me moved out of this func?
1338 //owner->showState();
1343 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
1345 LyXCursor cursor = bv_->getLyXText()->cursor;
1346 Buffer::inset_iterator it =
1347 find_if(Buffer::inset_iterator(
1348 cursor.par(), cursor.pos()),
1349 buffer_->inset_iterator_end(),
1350 lyx::compare_memfun(&Inset::lyxCode, code));
1351 return it != buffer_->inset_iterator_end() ? (*it) : 0;
1355 void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
1357 string filename = filen;
1359 if (filename.empty()) {
1360 // Launch a file browser
1361 string initpath = lyxrc.document_path;
1364 string const trypath = owner_->buffer()->filepath;
1365 // If directory is writeable, use this as default.
1366 if (IsDirWriteable(trypath) == 1)
1370 FileDialog fileDlg(bv_->owner(),
1371 _("Select LyX document to insert"),
1373 make_pair(string(_("Documents")),
1374 string(lyxrc.document_path)),
1375 make_pair(string(_("Examples")),
1376 string(AddPath(system_lyxdir, "examples"))));
1378 FileDialog::Result result =
1379 fileDlg.Select(initpath,
1380 _("*.lyx| LyX Documents (*.lyx)"));
1382 if (result.first == FileDialog::Later)
1385 filename = result.second;
1387 // check selected filename
1388 if (filename.empty()) {
1389 owner_->message(_("Canceled."));
1394 // get absolute path of file and add ".lyx" to the filename if
1396 filename = FileSearch(string(), filename, "lyx");
1398 string const disp_fn(MakeDisplayPath(filename));
1401 s1 << _("Inserting document") << ' '
1402 << disp_fn << " ...";
1403 owner_->message(s1.str().c_str());
1404 bool const res = bv_->insertLyXFile(filename);
1407 str << _("Document") << ' ' << disp_fn
1408 << ' ' << _("inserted.");
1409 owner_->message(str.str().c_str());
1412 str << _("Could not insert document") << ' '
1414 owner_->message(str.str().c_str());
1419 bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
1421 lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch: action["
1422 << action <<"] arg[" << argument << "]" << endl;
1425 // --- Misc -------------------------------------------
1429 LyXText * lt = bv_->getLyXText();
1430 lt->toggleAppendix(bv_);
1433 | BufferView::FITCUR
1434 | BufferView::CHANGE);
1439 case LFUN_TOC_INSERT:
1441 InsetCommandParams p;
1442 p.setCmdName("tableofcontents");
1443 Inset * inset = new InsetTOC(p);
1444 if (!insertInset(inset, "Standard"))
1449 case LFUN_TABULAR_FEATURE:
1450 case LFUN_SCROLL_INSET:
1451 // this is not handled here as this funktion is only aktive
1452 // if we have a locking_inset and that one is (or contains)
1456 case LFUN_INSET_GRAPHICS:
1458 Inset * new_inset = new InsetGraphics;
1459 if (!insertInset(new_inset)) {
1462 // this is need because you don't use a inset->Edit()
1463 updateInset(new_inset, true);
1464 new_inset->edit(bv_, 0, 0, 0);
1474 case LFUN_PASTESELECTION:
1476 bool asPara = false;
1477 if (argument == "paragraph") asPara = true;
1478 pasteClipboard(asPara);
1490 case LFUN_LAYOUT_COPY:
1491 bv_->copyEnvironment();
1494 case LFUN_LAYOUT_PASTE:
1495 bv_->pasteEnvironment();
1499 case LFUN_GOTOERROR:
1500 gotoInset(Inset::ERROR_CODE, false);
1504 gotoInset(Inset::IGNORE_CODE, false);
1507 case LFUN_REFERENCE_GOTO:
1509 vector<Inset::Code> tmp;
1510 tmp.push_back(Inset::LABEL_CODE);
1511 tmp.push_back(Inset::REF_CODE);
1512 gotoInset(tmp, true);
1516 case LFUN_HYPHENATION:
1524 case LFUN_END_OF_SENTENCE:
1528 case LFUN_MENU_SEPARATOR:
1537 changeDepth(bv_, bv_->getLyXText(), 0);
1540 case LFUN_DEPTH_MIN:
1541 changeDepth(bv_, bv_->getLyXText(), -1);
1544 case LFUN_DEPTH_PLUS:
1545 changeDepth(bv_, bv_->getLyXText(), 1);
1549 owner_->getDialogs()->setUserFreeFont();
1556 owner_->showState();
1560 case LFUN_FILE_INSERT:
1562 MenuInsertLyXFile(argument);
1566 case LFUN_FILE_INSERT_ASCII_PARA:
1567 InsertAsciiFile(bv_, argument, true);
1570 case LFUN_FILE_INSERT_ASCII:
1571 InsertAsciiFile(bv_, argument, false);
1576 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1577 << argument << endl;
1579 // Derive layout number from given argument (string)
1580 // and current buffer's textclass (number). */
1581 LyXTextClassList::ClassList::size_type tclass =
1582 buffer_->params.textclass;
1583 pair <bool, LyXTextClass::size_type> layout =
1584 textclasslist.NumberOfLayout(tclass, argument);
1586 // If the entry is obsolete, use the new one instead.
1588 string obs = textclasslist.Style(tclass,layout.second)
1592 textclasslist.NumberOfLayout(tclass, obs);
1595 // see if we found the layout number:
1596 if (!layout.first) {
1597 owner_->getLyXFunc()->setErrorMessage(
1598 string(N_("Layout ")) + argument +
1603 if (current_layout != layout.second) {
1604 LyXText * lt = bv_->getLyXText();
1606 current_layout = layout.second;
1609 | BufferView::FITCUR);
1610 lt->setLayout(bv_, layout.second);
1611 owner_->setLayout(layout.second);
1614 | BufferView::FITCUR
1615 | BufferView::CHANGE);
1622 Lang(bv_, argument);
1624 owner_->showState();
1629 owner_->showState();
1634 owner_->showState();
1639 owner_->showState();
1644 owner_->showState();
1649 owner_->showState();
1654 owner_->showState();
1659 owner_->showState();
1662 case LFUN_UNDERLINE:
1664 owner_->showState();
1667 case LFUN_FONT_SIZE:
1668 FontSize(bv_, argument);
1669 owner_->showState();
1672 case LFUN_FONT_STATE:
1673 owner_->getLyXFunc()->setMessage(CurrentState(bv_));
1676 case LFUN_UPCASE_WORD:
1678 LyXText * lt = bv_->getLyXText();
1682 | BufferView::FITCUR);
1683 lt->changeCase(bv_, LyXText::text_uppercase);
1684 if (lt->inset_owner)
1685 updateInset(lt->inset_owner, true);
1688 | BufferView::FITCUR
1689 | BufferView::CHANGE);
1693 case LFUN_LOWCASE_WORD:
1695 LyXText * lt = bv_->getLyXText();
1697 update(lt, BufferView::SELECT|BufferView::FITCUR);
1698 lt->changeCase(bv_, LyXText::text_lowercase);
1699 if (lt->inset_owner)
1700 updateInset(lt->inset_owner, true);
1703 | BufferView::FITCUR
1704 | BufferView::CHANGE);
1708 case LFUN_CAPITALIZE_WORD:
1710 LyXText * lt = bv_->getLyXText();
1712 update(lt, BufferView::SELECT|BufferView::FITCUR);
1713 lt->changeCase(bv_, LyXText::text_capitalization);
1714 if (lt->inset_owner)
1715 updateInset(lt->inset_owner, true);
1718 | BufferView::FITCUR
1719 | BufferView::CHANGE);
1723 case LFUN_TRANSPOSE_CHARS:
1725 LyXText * lt = bv_->getLyXText();
1727 update(lt, BufferView::SELECT|BufferView::FITCUR);
1728 lt->transposeChars(*bv_);
1729 if (lt->inset_owner)
1730 updateInset(lt->inset_owner, true);
1733 | BufferView::FITCUR
1734 | BufferView::CHANGE);
1739 case LFUN_INSERT_LABEL:
1740 MenuInsertLabel(bv_, argument);
1743 case LFUN_REF_INSERT:
1744 if (argument.empty()) {
1745 InsetCommandParams p("ref");
1746 owner_->getDialogs()->createRef(p.getAsString());
1748 InsetCommandParams p;
1749 p.setFromString(argument);
1751 InsetRef * inset = new InsetRef(p, *buffer_);
1752 if (!insertInset(inset))
1755 updateInset(inset, true);
1759 case LFUN_BOOKMARK_SAVE:
1760 savePosition(strToUnsignedInt(argument));
1763 case LFUN_BOOKMARK_GOTO:
1764 restorePosition(strToUnsignedInt(argument));
1769 string label(argument);
1770 if (label.empty()) {
1772 static_cast<InsetRef*>(getInsetByCode(Inset::REF_CODE));
1774 label = inset->getContents();
1779 if (!label.empty()) {
1780 //bv_->savePosition(0);
1781 if (!bv_->gotoLabel(label))
1782 WriteAlert(_("Error"),
1783 _("Couldn't find this label"),
1784 _("in current document."));
1789 // --- Cursor Movements -----------------------------
1792 LyXText * lt = bv_->getLyXText();
1794 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1795 if (!lt->selection.mark())
1797 update(lt, BufferView::SELECT|BufferView::FITCUR);
1799 lt->cursorLeft(bv_, false);
1800 if (lt->cursor.pos() < lt->cursor.par()->size()
1801 && lt->cursor.par()->getChar(lt->cursor.pos())
1802 == Paragraph::META_INSET
1803 && lt->cursor.par()->getInset(lt->cursor.pos())
1804 && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
1805 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1806 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1809 LyXFont const font =
1810 lt->getFont(buffer_,
1813 y = tmpinset->descent(bv_,font);
1815 tmpinset->edit(bv_, 0, y, 0);
1819 lt->cursorRight(bv_, false);
1821 moveCursorUpdate(false);
1822 owner_->showState();
1828 // This is soooo ugly. Isn`t it possible to make
1829 // it simpler? (Lgb)
1830 LyXText * lt = bv_->getLyXText();
1831 bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params);
1832 if (!lt->selection.mark())
1834 update(lt, BufferView::SELECT|BufferView::FITCUR);
1835 LyXCursor const cur = lt->cursor;
1837 lt->cursorLeft(bv_, false);
1838 if ((is_rtl || cur != lt->cursor) && // only if really moved!
1839 lt->cursor.pos() < lt->cursor.par()->size() &&
1840 (lt->cursor.par()->getChar(lt->cursor.pos()) ==
1841 Paragraph::META_INSET) &&
1842 lt->cursor.par()->getInset(lt->cursor.pos()) &&
1843 (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
1844 == Inset::HIGHLY_EDITABLE))
1846 Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
1847 owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
1848 LyXFont const font = lt->getFont(buffer_,
1852 : tmpinset->descent(bv_,font);
1855 tmpinset->width(bv_,font),
1860 lt->cursorRight(bv_, false);
1863 moveCursorUpdate(false);
1864 owner_->showState();
1870 LyXText * lt = bv_->getLyXText();
1872 if (!lt->selection.mark())
1874 update(lt, BufferView::UPDATE);
1877 moveCursorUpdate(false);
1878 owner_->showState();
1884 LyXText * lt = bv_->getLyXText();
1886 if (!lt->selection.mark())
1888 update(lt, BufferView::UPDATE);
1889 lt->cursorDown(bv_);
1891 moveCursorUpdate(false);
1892 owner_->showState();
1896 case LFUN_UP_PARAGRAPH:
1898 LyXText * lt = bv_->getLyXText();
1900 if (!lt->selection.mark())
1902 update(lt, BufferView::UPDATE);
1903 lt->cursorUpParagraph(bv_);
1905 moveCursorUpdate(false);
1906 owner_->showState();
1910 case LFUN_DOWN_PARAGRAPH:
1912 LyXText * lt = bv_->getLyXText();
1914 if (!lt->selection.mark())
1916 update(lt, BufferView::UPDATE);
1917 lt->cursorDownParagraph(bv_);
1919 moveCursorUpdate(false);
1920 owner_->showState();
1926 LyXText * lt = bv_->getLyXText();
1928 if (!lt->selection.mark())
1930 update(lt, BufferView::UPDATE);
1933 moveCursorUpdate(false);
1934 owner_->showState();
1940 LyXText * lt = bv_->getLyXText();
1942 if (!lt->selection.mark())
1944 update(lt, BufferView::UPDATE);
1947 moveCursorUpdate(false);
1948 owner_->showState();
1954 LyXText * lt = bv_->getLyXText();
1956 if (!lt->selection.mark())
1958 update(lt, BufferView::SELECT|BufferView::FITCUR);
1959 lt->cursorHome(bv_);
1961 moveCursorUpdate(false);
1962 owner_->showState();
1968 LyXText * lt = bv_->getLyXText();
1970 if (!lt->selection.mark())
1973 BufferView::SELECT|BufferView::FITCUR);
1976 moveCursorUpdate(false);
1977 owner_->showState();
1981 case LFUN_SHIFT_TAB:
1984 LyXText * lt = bv_->getLyXText();
1986 if (!lt->selection.mark())
1989 BufferView::SELECT|BufferView::FITCUR);
1992 moveCursorUpdate(false);
1993 owner_->showState();
1997 case LFUN_WORDRIGHT:
1999 LyXText * lt = bv_->getLyXText();
2001 if (!lt->selection.mark())
2003 update(lt, BufferView::SELECT|BufferView::FITCUR);
2004 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2005 lt->cursorLeftOneWord(bv_);
2007 lt->cursorRightOneWord(bv_);
2009 moveCursorUpdate(false);
2010 owner_->showState();
2016 LyXText * lt = bv_->getLyXText();
2018 if (!lt->selection.mark())
2020 update(lt, BufferView::SELECT|BufferView::FITCUR);
2021 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2022 lt->cursorRightOneWord(bv_);
2024 lt->cursorLeftOneWord(bv_);
2026 moveCursorUpdate(false);
2027 owner_->showState();
2031 case LFUN_BEGINNINGBUF:
2033 LyXText * lt = bv_->getLyXText();
2035 if (!lt->selection.mark())
2038 BufferView::SELECT|BufferView::FITCUR);
2041 moveCursorUpdate(false);
2042 owner_->showState();
2048 LyXText * lt = bv_->getLyXText();
2050 if (!lt->selection.mark())
2053 BufferView::SELECT|BufferView::FITCUR);
2054 lt->cursorBottom(bv_);
2056 moveCursorUpdate(false);
2057 owner_->showState();
2061 /* cursor selection ---------------------------- */
2064 LyXText * lt = bv_->getLyXText();
2067 BufferView::SELECT|BufferView::FITCUR);
2068 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2069 lt->cursorLeft(bv_);
2071 lt->cursorRight(bv_);
2073 moveCursorUpdate(true);
2074 owner_->showState();
2080 LyXText * lt = bv_->getLyXText();
2083 BufferView::SELECT|BufferView::FITCUR);
2084 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2085 lt->cursorRight(bv_);
2087 lt->cursorLeft(bv_);
2089 moveCursorUpdate(true);
2090 owner_->showState();
2096 LyXText * lt = bv_->getLyXText();
2099 BufferView::SELECT|BufferView::FITCUR);
2102 moveCursorUpdate(true);
2103 owner_->showState();
2109 LyXText * lt = bv_->getLyXText();
2112 BufferView::SELECT|BufferView::FITCUR);
2113 lt->cursorDown(bv_);
2115 moveCursorUpdate(true);
2116 owner_->showState();
2120 case LFUN_UP_PARAGRAPHSEL:
2122 LyXText * lt = bv_->getLyXText();
2125 BufferView::SELECT|BufferView::FITCUR);
2126 lt->cursorUpParagraph(bv_);
2128 moveCursorUpdate(true);
2129 owner_->showState();
2133 case LFUN_DOWN_PARAGRAPHSEL:
2135 LyXText * lt = bv_->getLyXText();
2138 BufferView::SELECT|BufferView::FITCUR);
2139 lt->cursorDownParagraph(bv_);
2141 moveCursorUpdate(true);
2142 owner_->showState();
2148 LyXText * lt = bv_->getLyXText();
2150 update(lt, BufferView::SELECT|BufferView::FITCUR);
2153 moveCursorUpdate(true);
2154 owner_->showState();
2160 LyXText * lt = bv_->getLyXText();
2162 update(lt, BufferView::SELECT|BufferView::FITCUR);
2165 moveCursorUpdate(true);
2166 owner_->showState();
2172 LyXText * lt = bv_->getLyXText();
2174 update(lt, BufferView::SELECT|BufferView::FITCUR);
2175 lt->cursorHome(bv_);
2177 moveCursorUpdate(true);
2178 owner_->showState();
2184 LyXText * lt = bv_->getLyXText();
2186 update(lt, BufferView::SELECT|BufferView::FITCUR);
2189 moveCursorUpdate(true);
2190 owner_->showState();
2194 case LFUN_WORDRIGHTSEL:
2196 LyXText * lt = bv_->getLyXText();
2198 update(lt, BufferView::SELECT|BufferView::FITCUR);
2199 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2200 lt->cursorLeftOneWord(bv_);
2202 lt->cursorRightOneWord(bv_);
2204 moveCursorUpdate(true);
2205 owner_->showState();
2209 case LFUN_WORDLEFTSEL:
2211 LyXText * lt = bv_->getLyXText();
2213 update(lt, BufferView::SELECT|BufferView::FITCUR);
2214 if (lt->cursor.par()->isRightToLeftPar(buffer_->params))
2215 lt->cursorRightOneWord(bv_);
2217 lt->cursorLeftOneWord(bv_);
2219 moveCursorUpdate(true);
2220 owner_->showState();
2224 case LFUN_BEGINNINGBUFSEL:
2226 LyXText * lt = bv_->getLyXText();
2228 if (lt->inset_owner)
2230 update(lt, BufferView::SELECT|BufferView::FITCUR);
2233 moveCursorUpdate(true);
2234 owner_->showState();
2238 case LFUN_ENDBUFSEL:
2240 LyXText * lt = bv_->getLyXText();
2242 if (lt->inset_owner)
2245 BufferView::SELECT|BufferView::FITCUR);
2246 lt->cursorBottom(bv_);
2248 moveCursorUpdate(true);
2249 owner_->showState();
2253 // --- text changing commands ------------------------
2254 case LFUN_BREAKLINE:
2256 LyXText * lt = bv_->getLyXText();
2259 lt->insertChar(bv_, Paragraph::META_NEWLINE);
2262 | BufferView::FITCUR
2263 | BufferView::CHANGE);
2264 moveCursorUpdate(false);
2268 case LFUN_PROTECTEDSPACE:
2270 LyXText * lt = bv_->getLyXText();
2272 LyXLayout const & style = textclasslist
2273 .Style(buffer_->params.textclass,
2274 lt->cursor.par()->getLayout());
2276 if (style.free_spacing) {
2277 lt->insertChar(bv_, ' ');
2280 | BufferView::FITCUR
2281 | BufferView::CHANGE);
2285 moveCursorUpdate(false);
2291 LyXText * lt = bv_->getLyXText();
2293 if (lt->selection.mark()) {
2297 | BufferView::FITCUR);
2298 owner_->getLyXFunc()->setMessage(N_("Mark removed"));
2301 lt->selection.mark(true);
2304 | BufferView::FITCUR);
2305 owner_->getLyXFunc()->setMessage(N_("Mark set"));
2307 lt->selection.cursor = lt->cursor;
2313 LyXText * lt = bv_->getLyXText();
2315 if (!lt->selection.set()) {
2317 lt->selection.cursor = lt->cursor;
2320 | BufferView::FITCUR
2321 | BufferView::CHANGE);
2322 // It is possible to make it a lot faster still
2323 // just comment out the line below...
2328 moveCursorUpdate(false);
2329 owner_->showState();
2334 case LFUN_DELETE_SKIP:
2336 LyXText * lt = bv_->getLyXText();
2338 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2340 LyXCursor cursor = lt->cursor;
2342 if (!lt->selection.set()) {
2343 if (cursor.pos() == cursor.par()->size()) {
2344 lt->cursorRight(bv_);
2345 cursor = lt->cursor;
2346 if (cursor.pos() == 0
2347 && !(cursor.par()->params().spaceTop()
2348 == VSpace (VSpace::NONE))) {
2351 cursor.par()->params().lineTop(),
2352 cursor.par()->params().lineBottom(),
2353 cursor.par()->params().pagebreakTop(),
2354 cursor.par()->params().pagebreakBottom(),
2355 VSpace(VSpace::NONE),
2356 cursor.par()->params().spaceBottom(),
2357 cursor.par()->params().align(),
2358 cursor.par()->params().labelWidthString(), 0);
2359 lt->cursorLeft(bv_);
2362 | BufferView::FITCUR
2363 | BufferView::CHANGE);
2365 lt->cursorLeft(bv_);
2367 lt->selection.cursor = lt->cursor;
2370 | BufferView::FITCUR
2371 | BufferView::CHANGE);
2375 lt->selection.cursor = lt->cursor;
2378 | BufferView::FITCUR
2379 | BufferView::CHANGE);
2387 /* -------> Delete word forward. */
2388 case LFUN_DELETE_WORD_FORWARD:
2389 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
2390 bv_->getLyXText()->deleteWordForward(bv_);
2391 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2392 moveCursorUpdate(false);
2393 owner_->showState();
2396 /* -------> Delete word backward. */
2397 case LFUN_DELETE_WORD_BACKWARD:
2399 LyXText * lt = bv_->getLyXText();
2401 update(lt, BufferView::SELECT|BufferView::FITCUR);
2402 lt->deleteWordBackward(bv_);
2405 | BufferView::FITCUR
2406 | BufferView::CHANGE);
2407 moveCursorUpdate(false);
2408 owner_->showState();
2412 /* -------> Kill to end of line. */
2413 case LFUN_DELETE_LINE_FORWARD:
2415 LyXText * lt = bv_->getLyXText();
2417 update(lt, BufferView::SELECT|BufferView::FITCUR);
2418 lt->deleteLineForward(bv_);
2421 | BufferView::FITCUR
2422 | BufferView::CHANGE);
2423 moveCursorUpdate(false);
2427 /* -------> Set mark off. */
2430 LyXText * lt = bv_->getLyXText();
2433 update(lt, BufferView::SELECT|BufferView::FITCUR);
2434 lt->selection.cursor = lt->cursor;
2435 owner_->getLyXFunc()->setMessage(N_("Mark off"));
2439 /* -------> Set mark on. */
2442 LyXText * lt = bv_->getLyXText();
2445 lt->selection.mark(true);
2446 update(lt, BufferView::SELECT|BufferView::FITCUR);
2447 lt->selection.cursor = lt->cursor;
2448 owner_->getLyXFunc()->setMessage(N_("Mark on"));
2452 case LFUN_BACKSPACE:
2454 LyXText * lt = bv_->getLyXText();
2456 if (!lt->selection.set()) {
2457 if (owner_->getIntl()->getTrans().backspace()) {
2459 lt->selection.cursor = lt->cursor;
2462 | BufferView::FITCUR
2463 | BufferView::CHANGE);
2464 // It is possible to make it a lot faster still
2465 // just comment out the line below...
2471 owner_->showState();
2476 case LFUN_BACKSPACE_SKIP:
2478 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
2479 LyXText * lt = bv_->getLyXText();
2481 LyXCursor cursor = lt->cursor;
2483 if (!lt->selection.set()) {
2484 if (cursor.pos() == 0
2485 && !(cursor.par()->params().spaceTop()
2486 == VSpace (VSpace::NONE))) {
2489 cursor.par()->params().lineTop(),
2490 cursor.par()->params().lineBottom(),
2491 cursor.par()->params().pagebreakTop(),
2492 cursor.par()->params().pagebreakBottom(),
2493 VSpace(VSpace::NONE), cursor.par()->params().spaceBottom(),
2494 cursor.par()->params().align(),
2495 cursor.par()->params().labelWidthString(), 0);
2498 | BufferView::FITCUR
2499 | BufferView::CHANGE);
2502 lt->selection.cursor = cursor;
2505 | BufferView::FITCUR
2506 | BufferView::CHANGE);
2513 case LFUN_BREAKPARAGRAPH:
2515 LyXText * lt = bv_->getLyXText();
2518 lt->breakParagraph(bv_, 0);
2521 | BufferView::FITCUR
2522 | BufferView::CHANGE);
2523 lt->selection.cursor = lt->cursor;
2525 owner_->showState();
2529 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
2531 LyXText * lt = bv_->getLyXText();
2534 lt->breakParagraph(bv_, 1);
2537 | BufferView::FITCUR
2538 | BufferView::CHANGE);
2539 lt->selection.cursor = lt->cursor;
2541 owner_->showState();
2545 case LFUN_BREAKPARAGRAPH_SKIP:
2547 // When at the beginning of a paragraph, remove
2548 // indentation and add a "defskip" at the top.
2549 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
2550 LyXText * lt = bv_->getLyXText();
2552 LyXCursor cursor = lt->cursor;
2555 if (cursor.pos() == 0) {
2556 if (cursor.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
2559 cursor.par()->params().lineTop(),
2560 cursor.par()->params().lineBottom(),
2561 cursor.par()->params().pagebreakTop(),
2562 cursor.par()->params().pagebreakBottom(),
2563 VSpace(VSpace::DEFSKIP), cursor.par()->params().spaceBottom(),
2564 cursor.par()->params().align(),
2565 cursor.par()->params().labelWidthString(), 1);
2566 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2570 lt->breakParagraph(bv_, 0);
2571 //update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2576 | BufferView::FITCUR
2577 | BufferView::CHANGE);
2578 lt->selection.cursor = cursor;
2580 owner_->showState();
2584 case LFUN_PARAGRAPH_SPACING:
2586 LyXText * lt = bv_->getLyXText();
2588 Paragraph * par = lt->cursor.par();
2589 Spacing::Space cur_spacing = par->params().spacing().getSpace();
2590 float cur_value = 1.0;
2591 if (cur_spacing == Spacing::Other) {
2592 cur_value = par->params().spacing().getValue();
2595 istringstream istr(argument.c_str());
2599 Spacing::Space new_spacing = cur_spacing;
2600 float new_value = cur_value;
2602 lyxerr << "Missing argument to `paragraph-spacing'"
2604 } else if (tmp == "single") {
2605 new_spacing = Spacing::Single;
2606 } else if (tmp == "onehalf") {
2607 new_spacing = Spacing::Onehalf;
2608 } else if (tmp == "double") {
2609 new_spacing = Spacing::Double;
2610 } else if (tmp == "other") {
2611 new_spacing = Spacing::Other;
2614 lyxerr << "new_value = " << tmpval << endl;
2617 } else if (tmp == "default") {
2618 new_spacing = Spacing::Default;
2620 lyxerr << _("Unknown spacing argument: ")
2621 << argument << endl;
2623 if (cur_spacing != new_spacing || cur_value != new_value) {
2624 par->params().spacing(Spacing(new_spacing, new_value));
2625 lt->redoParagraph(bv_);
2628 | BufferView::FITCUR
2629 | BufferView::CHANGE);
2635 bv_->insertCorrectQuote();
2641 InsetCommandParams p;
2642 if (action == LFUN_HTMLURL)
2643 p.setCmdName("htmlurl");
2645 p.setCmdName("url");
2646 owner_->getDialogs()->createUrl( p.getAsString() );
2650 case LFUN_INSERT_URL:
2652 InsetCommandParams p;
2653 p.setFromString( argument );
2655 InsetUrl * inset = new InsetUrl( p );
2656 if (!insertInset(inset))
2659 updateInset( inset, true );
2663 case LFUN_INSET_TEXT:
2665 InsetText * new_inset = new InsetText;
2666 if (insertInset(new_inset))
2667 new_inset->edit(bv_, 0, 0, 0);
2673 case LFUN_INSET_ERT:
2675 InsetERT * new_inset = new InsetERT;
2676 if (insertInset(new_inset))
2677 new_inset->edit(bv_, 0, 0, 0);
2683 case LFUN_INSET_EXTERNAL:
2685 InsetExternal * new_inset = new InsetExternal;
2686 if (insertInset(new_inset))
2687 new_inset->edit(bv_, 0, 0, 0);
2693 case LFUN_INSET_FOOTNOTE:
2695 InsetFoot * new_inset = new InsetFoot;
2696 if (insertInset(new_inset))
2697 new_inset->edit(bv_, 0, 0, 0);
2703 case LFUN_INSET_MARGINAL:
2705 InsetMarginal * new_inset = new InsetMarginal;
2706 if (insertInset(new_inset))
2707 new_inset->edit(bv_, 0, 0, 0);
2713 case LFUN_INSET_MINIPAGE:
2715 InsetMinipage * new_inset = new InsetMinipage;
2716 if (insertInset(new_inset))
2717 new_inset->edit(bv_, 0, 0, 0);
2723 case LFUN_INSET_FLOAT:
2725 // check if the float type exist
2726 if (floatList.typeExist(argument)) {
2727 InsetFloat * new_inset = new InsetFloat(argument);
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_WIDE_FLOAT:
2742 // check if the float type exist
2743 if (floatList.typeExist(argument)) {
2744 InsetFloat * new_inset = new InsetFloat(argument);
2745 new_inset->wide(true);
2746 if (insertInset(new_inset))
2747 new_inset->edit(bv_, 0, 0, 0);
2751 lyxerr << "Non-existant float type: "
2752 << argument << endl;
2758 case LFUN_INSET_LIST:
2760 InsetList * new_inset = new InsetList;
2761 if (insertInset(new_inset))
2762 new_inset->edit(bv_, 0, 0, 0);
2768 case LFUN_INSET_THEOREM:
2770 InsetTheorem * new_inset = new InsetTheorem;
2771 if (insertInset(new_inset))
2772 new_inset->edit(bv_, 0, 0, 0);
2778 case LFUN_INSET_CAPTION:
2780 // Do we have a locking inset...
2781 if (bv_->theLockingInset()) {
2782 lyxerr << "Locking inset code: "
2783 << static_cast<int>(bv_->theLockingInset()->lyxCode());
2784 InsetCaption * new_inset = new InsetCaption;
2785 new_inset->setOwner(bv_->theLockingInset());
2786 new_inset->setAutoBreakRows(true);
2787 new_inset->setDrawFrame(0, InsetText::LOCKED);
2788 new_inset->setFrameColor(0, LColor::captionframe);
2789 if (insertInset(new_inset))
2790 new_inset->edit(bv_, 0, 0, 0);
2797 case LFUN_INSET_TABULAR:
2801 if (!argument.empty())
2802 ::sscanf(argument.c_str(),"%d%d", &r, &c);
2803 InsetTabular * new_inset =
2804 new InsetTabular(*buffer_, r, c);
2806 bv_->getLyXText()->real_current_font.isRightToLeft();
2807 if (!open_new_inset(new_inset, rtl))
2812 // --- lyxserver commands ----------------------------
2814 case LFUN_CHARATCURSOR:
2816 Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
2817 if (pos < bv_->getLyXText()->cursor.par()->size())
2818 owner_->getLyXFunc()->setMessage(
2819 tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
2821 owner_->getLyXFunc()->setMessage("EOF");
2826 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.x())
2828 + tostr(bv_->getLyXText()->cursor.y()));
2835 if (::sscanf(argument.c_str(), " %d %d", &x, &y) != 2) {
2836 lyxerr << "SETXY: Could not parse coordinates in '"
2837 << argument << std::endl;
2839 bv_->getLyXText()->setCursorFromCoordinates(bv_, x, y);
2843 case LFUN_GETLAYOUT:
2844 owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
2849 LyXFont & font = bv_->getLyXText()->current_font;
2850 if (font.shape() == LyXFont::ITALIC_SHAPE)
2851 owner_->getLyXFunc()->setMessage("E");
2852 else if (font.shape() == LyXFont::SMALLCAPS_SHAPE)
2853 owner_->getLyXFunc()->setMessage("N");
2855 owner_->getLyXFunc()->setMessage("0");
2863 LyXFont & font = bv_->getLyXText()->current_font;
2864 if (font.latex() == LyXFont::ON)
2865 owner_->getLyXFunc()->setMessage("L");
2868 owner_->getLyXFunc()->setMessage("0");
2872 // --- accented characters ---------------------------
2875 case LFUN_CIRCUMFLEX:
2885 case LFUN_SPECIAL_CARON:
2888 case LFUN_HUNG_UMLAUT:
2891 if (argument.empty()) {
2893 owner_->getLyXFunc()->handleKeyFunc(action);
2895 owner_->getLyXFunc()->handleKeyFunc(action);
2896 owner_->getIntl()->getTrans()
2897 .TranslateAndInsert(argument[0], bv_->getLyXText());
2898 update(bv_->getLyXText(),
2900 | BufferView::FITCUR
2901 | BufferView::CHANGE);
2905 // --- insert characters ----------------------------------------
2907 case LFUN_MATH_DELIM:
2908 case LFUN_INSERT_MATRIX:
2911 if (open_new_inset(new InsetFormula, false)) {
2912 bv_->theLockingInset()
2913 ->localDispatch(bv_, action, argument);
2919 case LFUN_INSERT_MATH:
2924 InsetFormula * f = new InsetFormula(LM_OT_EQUATION);
2926 f->localDispatch(bv_, LFUN_INSERT_MATH, argument);
2930 case LFUN_MATH_DISPLAY:
2933 open_new_inset(new InsetFormula(LM_OT_EQUATION), false);
2937 case LFUN_MATH_MACRO:
2942 owner_->getLyXFunc()->setErrorMessage(N_("Missing argument"));
2944 string const s1 = token(s, ' ', 1);
2945 int const na = s1.empty() ? 0 : lyx::atoi(s1);
2946 open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na), false);
2952 case LFUN_MATH_MODE: // Open or create a math inset
2955 open_new_inset(new InsetFormula, false);
2956 owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
2960 case LFUN_CITATION_INSERT:
2962 InsetCommandParams p;
2963 p.setFromString( argument );
2965 InsetCitation * inset = new InsetCitation( p );
2966 if (!insertInset(inset))
2969 updateInset( inset, true );
2973 case LFUN_INSERT_BIBTEX:
2975 // ale970405+lasgoutt970425
2976 // The argument can be up to two tokens separated
2977 // by a space. The first one is the bibstyle.
2978 string const db = token(argument, ' ', 0);
2979 string bibstyle = token(argument, ' ', 1);
2980 if (bibstyle.empty())
2983 InsetCommandParams p( "BibTeX", db, bibstyle );
2984 InsetBibtex * inset = new InsetBibtex(p);
2986 if (insertInset(inset)) {
2987 if (argument.empty())
2988 inset->edit(bv_, 0, 0, 0);
2994 // BibTeX data bases
2995 case LFUN_BIBDB_ADD:
2997 InsetBibtex * inset =
2998 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3000 inset->addDatabase(argument);
3005 case LFUN_BIBDB_DEL:
3007 InsetBibtex * inset =
3008 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3010 inset->delDatabase(argument);
3015 case LFUN_BIBTEX_STYLE:
3017 InsetBibtex * inset =
3018 static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
3020 inset->setOptions(argument);
3025 case LFUN_INDEX_CREATE:
3027 InsetCommandParams p( "index" );
3029 if (argument.empty()) {
3030 // Get the word immediately preceding the cursor
3031 Paragraph::size_type curpos =
3032 bv_->getLyXText()->cursor.pos() - 1;
3036 curstring = bv_->getLyXText()
3037 ->cursor.par()->getWord(curpos);
3039 p.setContents( curstring );
3041 p.setContents( argument );
3044 owner_->getDialogs()->createIndex( p.getAsString() );
3048 case LFUN_INDEX_INSERT:
3050 InsetCommandParams p;
3051 p.setFromString(argument);
3052 InsetIndex * inset = new InsetIndex(p);
3054 if (!insertInset(inset))
3057 updateInset(inset, true);
3061 case LFUN_INDEX_INSERT_LAST:
3063 // Get word immediately preceding the cursor
3064 Paragraph::size_type curpos =
3065 bv_->getLyXText()->cursor.pos() - 1;
3066 // Can't do that at the beginning of a paragraph
3067 if (curpos < 0) break;
3069 string const curstring(bv_->getLyXText()
3070 ->cursor.par()->getWord(curpos));
3072 InsetCommandParams p("index", curstring);
3073 InsetIndex * inset = new InsetIndex(p);
3075 if (!insertInset(inset))
3078 updateInset(inset, true);
3082 case LFUN_INDEX_PRINT:
3084 InsetCommandParams p("printindex");
3085 Inset * inset = new InsetPrintIndex(p);
3086 if (!insertInset(inset, "Standard"))
3091 case LFUN_PARENTINSERT:
3093 lyxerr << "arg " << argument << endl;
3094 InsetCommandParams p( "lyxparent", argument );
3095 Inset * inset = new InsetParent(p, *buffer_);
3096 if (!insertInset(inset, "Standard"))
3102 case LFUN_CHILD_INSERT:
3104 InsetInclude::Params p;
3105 p.cparams.setFromString(argument);
3106 p.masterFilename_ = buffer_->fileName();
3108 InsetInclude * inset = new InsetInclude(p);
3109 if (!insertInset(inset))
3112 updateInset(inset, true);
3113 bv_->owner()->getDialogs()->showInclude(inset);
3118 case LFUN_FLOAT_LIST:
3120 // We should check the argument for validity. (Lgb)
3121 Inset * inset = new InsetFloatList(argument);
3122 if (!insertInset(inset, "Standard"))
3127 case LFUN_INSERT_NOTE:
3131 case LFUN_SELFINSERT:
3133 if (argument.empty()) break;
3135 /* Automatically delete the currently selected
3136 * text and replace it with what is being
3137 * typed in now. Depends on lyxrc settings
3138 * "auto_region_delete", which defaults to
3141 LyXText * lt = bv_->getLyXText();
3143 if (lyxrc.auto_region_delete) {
3144 if (lt->selection.set()) {
3145 lt->cutSelection(bv_, false);
3148 | BufferView::FITCUR
3149 | BufferView::CHANGE);
3153 bv_->beforeChange(lt);
3154 LyXFont const old_font(lt->real_current_font);
3156 string::const_iterator cit = argument.begin();
3157 string::const_iterator end = argument.end();
3158 for (; cit != end; ++cit) {
3159 if (greek_kb_flag) {
3160 if (!math_insert_greek(bv_, *cit))
3161 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3163 owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
3168 | BufferView::FITCUR
3169 | BufferView::CHANGE);
3171 lt->selection.cursor = lt->cursor;
3172 moveCursorUpdate(false);
3174 // real_current_font.number can change so we need to
3175 // update the minibuffer
3176 if (old_font != lt->real_current_font)
3177 owner_->showState();
3182 case LFUN_DATE_INSERT: // jdblair: date-insert cmd
3184 time_t now_time_t = time(NULL);
3185 struct tm * now_tm = localtime(&now_time_t);
3186 setlocale(LC_TIME, "");
3188 if (!argument.empty())
3191 arg = lyxrc.date_insert_format;
3193 int const datetmp_len =
3194 ::strftime(datetmp, 32, arg.c_str(), now_tm);
3196 LyXText * lt = bv_->getLyXText();
3198 for (int i = 0; i < datetmp_len; i++) {
3199 lt->insertChar(bv_, datetmp[i]);
3202 | BufferView::FITCUR
3203 | BufferView::CHANGE);
3206 lt->selection.cursor = lt->cursor;
3207 moveCursorUpdate(false);
3211 case LFUN_UNKNOWN_ACTION:
3212 owner_->getLyXFunc()->setErrorMessage(N_("Unknown function!"));
3223 void BufferView::Pimpl::newline()
3226 LyXText * lt = bv_->getLyXText();
3230 | BufferView::FITCUR);
3231 lt->insertChar(bv_, Paragraph::META_NEWLINE);
3234 | BufferView::FITCUR
3235 | BufferView::CHANGE);
3240 void BufferView::Pimpl::hfill()
3243 LyXText * lt = bv_->getLyXText();
3247 | BufferView::FITCUR);
3248 lt->insertChar(bv_, Paragraph::META_HFILL);
3251 | BufferView::FITCUR
3252 | BufferView::CHANGE);
3257 void BufferView::Pimpl::protectedBlank(LyXText * lt)
3261 update(lt, BufferView::SELECT|BufferView::FITCUR);
3262 InsetSpecialChar * new_inset =
3263 new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
3264 if (!insertInset(new_inset))
3267 updateInset(new_inset, true);
3272 void BufferView::Pimpl::menuSeparator()
3275 LyXText * lt = bv_->getLyXText();
3278 update(lt, BufferView::SELECT|BufferView::FITCUR);
3279 InsetSpecialChar * new_inset =
3280 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
3281 insertInset(new_inset);
3286 void BufferView::Pimpl::endOfSentenceDot()
3290 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3291 InsetSpecialChar * new_inset =
3292 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
3293 insertInset(new_inset);
3298 void BufferView::Pimpl::ldots()
3302 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3303 InsetSpecialChar * new_inset =
3304 new InsetSpecialChar(InsetSpecialChar::LDOTS);
3305 insertInset(new_inset);
3310 void BufferView::Pimpl::hyphenationPoint()
3314 update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
3315 InsetSpecialChar * new_inset =
3316 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
3317 insertInset(new_inset);
3322 void BufferView::Pimpl::insertNote()
3324 InsetInfo * new_inset = new InsetInfo();
3325 insertInset(new_inset);
3326 new_inset->edit(bv_, 0, 0, 0);
3330 // Open and lock an updatable inset
3331 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
3333 LyXText * lt = bv_->getLyXText();
3337 if (!insertInset(new_inset)) {
3342 LyXFont & font = lt->real_current_font;
3343 new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
3345 new_inset->edit(bv_, 0, 0, 0);
3350 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
3352 // if we are in a locking inset we should try to insert the
3353 // inset there otherwise this is a illegal function now
3354 if (bv_->theLockingInset()) {
3355 if (bv_->theLockingInset()->insertInsetAllowed(inset))
3356 return bv_->theLockingInset()->insertInset(bv_, inset);
3360 // not quite sure if we want this...
3361 bv_->text->setCursorParUndo(buffer_);
3362 bv_->text->freezeUndo();
3364 beforeChange(bv_->text);
3365 if (!lout.empty()) {
3366 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3367 bv_->text->breakParagraph(bv_);
3368 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3370 if (bv_->text->cursor.par()->size()) {
3371 bv_->text->cursorLeft(bv_);
3373 bv_->text->breakParagraph(bv_);
3374 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3377 pair<bool, LyXTextClass::size_type> lres =
3378 textclasslist.NumberOfLayout(buffer_->params
3380 LyXTextClass::size_type lay;
3381 if (lres.first != false) {
3385 // layout not fount using default "Standard" (0)
3389 bv_->text->setLayout(bv_, lay);
3391 bv_->text->setParagraph(bv_, 0, 0,
3393 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3397 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3399 bv_->text->current_font.setLatex(LyXFont::OFF);
3403 bv_->text->insertInset(bv_, inset);
3404 update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
3406 bv_->text->unFreezeUndo();
3411 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
3416 // first check for locking insets
3417 if (bv_->theLockingInset()) {
3418 if (bv_->theLockingInset() == inset) {
3419 if (bv_->text->updateInset(bv_, inset)) {
3422 buffer_->markDirty();
3427 } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
3428 if (bv_->text->updateInset(bv_,
3429 bv_->theLockingInset())) {
3432 buffer_->markDirty();
3440 // then check the current buffer
3443 update(bv_->text, BufferView::UPDATE);
3444 if (bv_->text->updateInset(bv_, inset)) {
3448 | BufferView::FITCUR
3449 | BufferView::CHANGE);
3451 update(bv_->text, SELECT);
3459 void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
3462 if (!available()) return;
3465 beforeChange(bv_->text);
3466 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3470 bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
3471 Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
3472 if (find(codes.begin(), codes.end(), inset->lyxCode())
3475 static_cast<InsetCommand const *>(inset)->getContents();
3478 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3479 if (bv_->text->cursor.pos()
3480 || bv_->text->cursor.par() != bv_->text->firstParagraph()) {
3481 LyXCursor tmp = bv_->text->cursor;
3482 bv_->text->cursor.par(bv_->text->firstParagraph());
3483 bv_->text->cursor.pos(0);
3484 if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
3485 bv_->text->cursor = tmp;
3486 bv_->owner()->message(_("No more insets"));
3489 bv_->owner()->message(_("No more insets"));
3492 update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
3493 bv_->text->selection.cursor = bv_->text->cursor;
3497 void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
3499 gotoInset(vector<Inset::Code>(1, code), same_content);