]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Fixed cut&paste bugs and added freespacing for ERT Insets.
[lyx.git] / src / BufferView_pimpl.C
index 56d4858e2a74b84cff5fc689981475d0c324dfc3..b7d44616bdab029e05c7dbc106a962d827b7b1ae 100644 (file)
@@ -14,6 +14,7 @@
 #include "lyxscreen.h"
 #include "lyxtext.h"
 #include "lyxrow.h"
+#include "paragraph.h"
 #include "LyXView.h"
 #include "commandtags.h"
 #include "lyxfunc.h"
@@ -28,6 +29,7 @@
 #include "support/LAssert.h"
 #include "support/lstrings.h"
 #include "frontends/Dialogs.h"
+#include "frontends/Alert.h"
 #include "insets/insetbib.h"
 #include "insets/insettext.h"
 /// added for Dispatch functions
@@ -66,7 +68,7 @@
 #include "undo_funcs.h"
 #include "mathed/formulabase.h"
 
-extern LyXTextClass::size_type current_layout;
+extern lyx::layout_type current_layout;
 
 using std::vector;
 using std::find_if;
@@ -76,6 +78,7 @@ using std::endl;
 using std::make_pair;
 using std::min;
 using SigC::slot;
+using lyx::pos_type;
 
 /* the selection possible is needed, that only motion events are 
  * used, where the bottom press event was on the drawing area too */
@@ -208,7 +211,6 @@ void BufferView::Pimpl::buffer(Buffer * b)
                // hidden. This should go here because some dialogs (eg ToC)
                // require bv_->text.
                owner_->getDialogs()->updateBufferDependent(true);
-               workarea_.show();
                redraw();
                insetWakeup();
        } else {
@@ -294,9 +296,9 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        Paragraph * selendpar = 0;
        UpdatableInset * the_locking_inset = 0;
        
-       Paragraph::size_type pos = 0;
-       Paragraph::size_type selstartpos = 0;
-       Paragraph::size_type selendpos = 0;
+       pos_type pos = 0;
+       pos_type selstartpos = 0;
+       pos_type selendpos = 0;
        bool selection = false;
        bool mark_set  = false;
 
@@ -565,7 +567,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
 
 // Single-click on work area
 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
-                                           unsigned int button)
+                                            unsigned int button)
 {
        if (!buffer_ || !screen_.get()) return;
 
@@ -590,9 +592,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
                   otherwise give the event to the inset */
                if (inset_hit == bv_->theLockingInset()) {
                        bv_->theLockingInset()->
-                               insetButtonPress(bv_,
-                                                xpos, ypos,
-                                                button);
+                               insetButtonPress(bv_,xpos, ypos,button);
                        return;
                } else {
                        bv_->unlockInset(bv_->theLockingInset());
@@ -625,8 +625,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
        updateScrollbar();
        
        // Single left click in math inset?
-       if ((inset_hit != 0) &&
-           (inset_hit->editable()==Inset::HIGHLY_EDITABLE)) {
+       if (isHighlyEditableInset(inset_hit)) {
                // Highly editable inset, like math
                UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
                selection_possible = false;
@@ -699,7 +698,7 @@ void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
 {
        // select a line
-       if (buffer_)
+       if (!buffer_)
                return;
 
        LyXText * text = bv_->getLyXText();
@@ -795,7 +794,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
 
                owner_->message(inset_hit->editMessage());
 
-               if (inset_hit->editable()==Inset::HIGHLY_EDITABLE) {
+               if (isHighlyEditableInset(inset_hit)) {
                        // Highly editable inset, like math
                        UpdatableInset *inset = (UpdatableInset *)inset_hit;
                        inset->insetButtonRelease(bv_, x, y, button);
@@ -859,9 +858,8 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
 
 
        if (cursor.pos() < cursor.par()->size()
-           && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
-           && cursor.par()->getInset(cursor.pos())
-           && cursor.par()->getInset(cursor.pos())->editable()) {
+           && cursor.par()->isInset(cursor.pos())
+           && isEditableInset(cursor.par()->getInset(cursor.pos()))) {
 
                // Check whether the inset really was hit
                Inset * tmpinset = cursor.par()->getInset(cursor.pos());
@@ -885,9 +883,8 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
        }
 
        if ((cursor.pos() - 1 >= 0) &&
-           (cursor.par()->getChar(cursor.pos()-1) == Paragraph::META_INSET) &&
-           (cursor.par()->getInset(cursor.pos() - 1)) &&
-           (cursor.par()->getInset(cursor.pos() - 1)->editable())) {
+           cursor.par()->isInset(cursor.pos() - 1) &&
+           isEditableInset(cursor.par()->getInset(cursor.pos() - 1))) {
                Inset * tmpinset = cursor.par()->getInset(cursor.pos()-1);
                LyXFont font = text->getFont(buffer_, cursor.par(),
                                                  cursor.pos() - 1);
@@ -1040,7 +1037,7 @@ void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
 
        if (text->inset_owner) {
                text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
-           updateInset(text->inset_owner, true);
+           updateInset(text->inset_owner, false);
        } else {
            update();
        }
@@ -1780,7 +1777,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        case LFUN_INSERT_LABEL:
                MenuInsertLabel(bv_, argument);
                break;
-               
+
        case LFUN_REF_INSERT:
                if (argument.empty()) {
                        InsetCommandParams p("ref");
@@ -1820,7 +1817,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if (!label.empty()) {
                        //bv_->savePosition(0);
                        if (!bv_->gotoLabel(label))
-                               WriteAlert(_("Error"), 
+                               Alert::alert(_("Error"), 
                                           _("Couldn't find this label"), 
                                           _("in current document."));
                }
@@ -1839,10 +1836,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if (is_rtl)
                        lt->cursorLeft(bv_, false);
                if (lt->cursor.pos() < lt->cursor.par()->size()
-                   && lt->cursor.par()->getChar(lt->cursor.pos())
-                   == Paragraph::META_INSET
-                   && lt->cursor.par()->getInset(lt->cursor.pos())
-                   && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
+                   && lt->cursor.par()->isInset(lt->cursor.pos())
+                   && isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
                        Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
                        owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
                        if (is_rtl)
@@ -1873,12 +1868,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeft(bv_, false);
                if ((is_rtl || cur != lt->cursor) && // only if really moved!
                    lt->cursor.pos() < lt->cursor.par()->size() &&
-                   (lt->cursor.par()->getChar(lt->cursor.pos()) ==
-                    Paragraph::META_INSET) &&
-                   lt->cursor.par()->getInset(lt->cursor.pos()) &&
-                   (lt->cursor.par()->getInset(lt->cursor.pos())->editable()
-                    == Inset::HIGHLY_EDITABLE))
-               {
+                   lt->cursor.par()->isInset(lt->cursor.pos()) &&
+                   isHighlyEditableInset(lt->cursor.par()->getInset(lt->cursor.pos()))) {
                        Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
                        owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
                        if (is_rtl)
@@ -2810,7 +2801,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
 
        case LFUN_CHARATCURSOR:
        {
-               Paragraph::size_type pos = bv_->getLyXText()->cursor.pos();
+               pos_type pos = bv_->getLyXText()->cursor.pos();
                if (pos < bv_->getLyXText()->cursor.par()->size())
                        owner_->getLyXFunc()->setMessage(
                                tostr(bv_->getLyXText()->cursor.par()->getChar(pos)));
@@ -2915,6 +2906,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                mathDispatchMathMode(bv_, argument);
                break;
                
+       case LFUN_GREEK:                 // Insert a single greek letter
+               mathDispatchGreek(bv_, argument);
+               break;
+               
        case LFUN_CITATION_INSERT:
        {
                InsetCommandParams p;
@@ -3249,19 +3244,23 @@ void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
 
 void BufferView::Pimpl::smartQuote()
 {
+       LyXText const * lt = bv_->getLyXText();
+       Paragraph const * par = lt->cursor.par();
+       pos_type pos = lt->cursor.pos();
        char c;
-       LyXText * lt = bv_->getLyXText();
 
-       if (lt->cursor.pos())
-               c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
-       else 
+       if (!pos
+           || (par->isInset(pos - 1)
+               && par->getInset(pos - 1)->isSpace()))
                c = ' ';
+       else
+               c = par->getChar(pos - 1);
+               
 
        hideCursor();
 
        LyXLayout const & style = textclasslist.Style(
-               bv_->buffer()->params.textclass,
-               lt->cursor.par()->getLayout());
+               bv_->buffer()->params.textclass, par->getLayout());
        
        if (style.pass_thru ||
                (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
@@ -3410,16 +3409,19 @@ void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
        beforeChange(bv_->text);
        update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
        
+       LyXCursor const & cursor = bv_->text->cursor;
        string contents;
        if (same_content &&
-           bv_->text->cursor.par()->getChar(bv_->text->cursor.pos()) == Paragraph::META_INSET) {
-               Inset const * inset = bv_->text->cursor.par()->getInset(bv_->text->cursor.pos());
+           cursor.par()->isInset(cursor.pos())) {
+               Inset const * inset = cursor.par()->getInset(cursor.pos());
                if (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
                        contents =
                                static_cast<InsetCommand const *>(inset)->getContents();
        }
        
        if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
                if (bv_->text->cursor.pos() 
                    || bv_->text->cursor.par() != bv_->text->firstParagraph()) {