]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Remove unused font variable which caused a warning.
[lyx.git] / src / BufferView_pimpl.C
index 16c82432c33c1bca6875ab9a95e44428268bcc2a..e3a4b0f8a13e98ecc826367dea6ad9c34d03d2c1 100644 (file)
@@ -41,7 +41,7 @@
 #include "insets/insetref.h"
 #include "insets/insetparent.h"
 #include "insets/insetindex.h"
-#include "insets/insetinfo.h"
+#include "insets/insetnote.h"
 #include "insets/insetinclude.h"
 #include "insets/insetcite.h"
 #include "insets/insetert.h"
 #include "insets/insetmarginal.h"
 #include "insets/insetminipage.h"
 #include "insets/insetfloat.h"
-#include "insets/insetlist.h"
 #include "insets/insettabular.h"
+#if 0
 #include "insets/insettheorem.h"
+#include "insets/insetlist.h"
+#endif
 #include "insets/insetcaption.h"
 #include "insets/insetfloatlist.h"
 #include "insets/insetspecialchar.h"
@@ -256,9 +258,16 @@ bool BufferView::Pimpl::fitCursor(LyXText * text)
 {
        lyx::Assert(screen_.get());
 
-       bv_->owner()->getDialogs()->updateParagraph();
+       bool ret;
+
+       if (bv_->theLockingInset()) {
+               bv_->theLockingInset()->fitInsetCursor(bv_);
+               ret = true;
+       } else {
+               ret = screen_->fitCursor(text, bv_);
+       }
 
-       bool const ret = screen_->fitCursor(text, bv_);
+       bv_->owner()->getDialogs()->updateParagraph();
        if (ret)
            updateScrollbar();
        return ret;
@@ -1004,14 +1013,15 @@ void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
        text->fullRebreak(bv_);
 
        if (text->inset_owner) {
-           text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
+               text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
            updateInset(text->inset_owner, true);
-       } else
+       } else {
            update();
-
+       }
+               
        if ((f & FITCUR)) {
                fitCursor(text);
-       }
+       }
 
        if ((f & CHANGE)) {
                buffer_->markDirty();
@@ -1252,15 +1262,23 @@ bool BufferView::Pimpl::belowMouse() const
 
 void BufferView::Pimpl::showCursor()
 {
-       if (screen_.get())
-               screen_->showCursor(bv_->text, bv_);
+       if (screen_.get()) {
+               if (bv_->theLockingInset())
+                       bv_->theLockingInset()->showInsetCursor(bv_);
+               else
+                       screen_->showCursor(bv_->text, bv_);
+       }
 }
 
 
 void BufferView::Pimpl::hideCursor()
 {
-       if (screen_.get())
-               screen_->hideCursor();
+       if (screen_.get()) {
+               if (!bv_->theLockingInset())
+//                     bv_->theLockingInset()->hideInsetCursor(bv_);
+//             else
+                       screen_->hideCursor();
+       }
 }
 
 
@@ -1467,7 +1485,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                } else {
                        // this is need because you don't use a inset->Edit()
                        updateInset(new_inset, true);
-                       new_inset->edit(bv_, 0, 0, 0);
+                       new_inset->edit(bv_);
                }
                break;
        }
@@ -1520,19 +1538,23 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
 
        case LFUN_HYPHENATION:
-               hyphenationPoint();
+               specialChar(InsetSpecialChar::HYPHENATION);
+               break;
+               
+       case LFUN_LIGATURE_BREAK:
+               specialChar(InsetSpecialChar::LIGATURE_BREAK);
                break;
                
        case LFUN_LDOTS:
-               ldots();
+               specialChar(InsetSpecialChar::LDOTS);
                break;
                
        case LFUN_END_OF_SENTENCE:
-               endOfSentenceDot();
+               specialChar(InsetSpecialChar::END_OF_SENTENCE);
                break;
 
        case LFUN_MENU_SEPARATOR:
-               menuSeparator();
+               specialChar(InsetSpecialChar::MENU_SEPARATOR);
                break;
                
        case LFUN_HFILL:
@@ -1810,15 +1832,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                    && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
                        Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
                        owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
-                       int y = 0;
-                       if (is_rtl) {
-                               LyXFont const font = 
-                                       lt->getFont(buffer_,
-                                                   lt->cursor.par(),
-                                                   lt->cursor.pos());  
-                               y = tmpinset->descent(bv_,font);
-                       }
-                       tmpinset->edit(bv_, 0, y, 0);
+                       if (is_rtl)
+                               tmpinset->edit(bv_, false);
+                       else
+                               tmpinset->edit(bv_);
                        break;
                }
                if (!is_rtl)
@@ -1851,15 +1868,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                {
                        Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
                        owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
-                       LyXFont const font = lt->getFont(buffer_,
-                                                        lt->cursor.par(),
-                                                        lt->cursor.pos());
-                       int y = is_rtl ? 0 
-                               : tmpinset->descent(bv_,font);
-                       tmpinset->edit(bv_,
-                                      tmpinset->x() +
-                                      tmpinset->width(bv_,font),
-                                      y, 0);
+                       if (is_rtl)
+                               tmpinset->edit(bv_);
+                       else
+                               tmpinset->edit(bv_, false);
                        break;
                }
                if  (is_rtl)
@@ -2650,7 +2662,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                break;
 
        case LFUN_QUOTE:
-               bv_->insertCorrectQuote();
+               smartQuote();
                break;
 
        case LFUN_HTMLURL:
@@ -2661,99 +2673,60 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        p.setCmdName("htmlurl");
                else
                        p.setCmdName("url");
-               owner_->getDialogs()->createUrl( p.getAsString() );
+               owner_->getDialogs()->createUrl(p.getAsString());
        }
        break;
        
        case LFUN_INSERT_URL:
        {
                InsetCommandParams p;
-               p.setFromString( argument );
+               p.setFromString(argument);
 
-               InsetUrl * inset = new InsetUrl( p );
+               InsetUrl * inset = new InsetUrl(p);
                if (!insertInset(inset))
                        delete inset;
                else
-                       updateInset( inset, true );
+                       updateInset(inset, true);
        }
        break;
        
        case LFUN_INSET_TEXT:
-       {
-               InsetText * new_inset = new InsetText;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetText);
+               break;
        
        case LFUN_INSET_ERT:
-       {
-               InsetERT * new_inset = new InsetERT;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetERT);
+               break;
        
        case LFUN_INSET_EXTERNAL:
-       {
-               InsetExternal * new_inset = new InsetExternal;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetExternal);
+               break;
        
        case LFUN_INSET_FOOTNOTE:
-       {
-               InsetFoot * new_inset = new InsetFoot;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetFoot);
+               break;
 
        case LFUN_INSET_MARGINAL:
-       {
-               InsetMarginal * new_inset = new InsetMarginal;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetMarginal);
+               break;
 
        case LFUN_INSET_MINIPAGE:
-       {
-               InsetMinipage * new_inset = new InsetMinipage;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetMinipage);
+               break;
+
+       case LFUN_INSERT_NOTE:
+               insertAndEditInset(new InsetNote);
+               break;
 
        case LFUN_INSET_FLOAT:
-       {
                // check if the float type exist
                if (floatList.typeExist(argument)) {
-                       InsetFloat * new_inset = new InsetFloat(argument);
-                       if (insertInset(new_inset))
-                               new_inset->edit(bv_, 0, 0, 0);
-                       else
-                               delete new_inset;
+                       insertAndEditInset(new InsetFloat(argument));
                } else {
                        lyxerr << "Non-existant float type: "
                               << argument << endl;
                }
-               
-       }
-       break;
+               break;
 
        case LFUN_INSET_WIDE_FLOAT:
        {
@@ -2762,7 +2735,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        InsetFloat * new_inset = new InsetFloat(argument);
                        new_inset->wide(true);
                        if (insertInset(new_inset))
-                               new_inset->edit(bv_, 0, 0, 0);
+                               new_inset->edit(bv_);
                        else
                                delete new_inset;
                } else {
@@ -2773,26 +2746,16 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
        break;
 
+#if 0
        case LFUN_INSET_LIST:
-       {
-               InsetList * new_inset = new InsetList;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
+               insertAndEditInset(new InsetList);
+               break;
 
        case LFUN_INSET_THEOREM:
-       {
-               InsetTheorem * new_inset = new InsetTheorem;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
-
+               insertAndEditInset(new InsetTheorem);
+               break;
+#endif
+               
        case LFUN_INSET_CAPTION:
        {
                // Do we have a locking inset...
@@ -2805,7 +2768,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        new_inset->setDrawFrame(0, InsetText::LOCKED);
                        new_inset->setFrameColor(0, LColor::captionframe);
                        if (insertInset(new_inset))
-                               new_inset->edit(bv_, 0, 0, 0);
+                               new_inset->edit(bv_);
                        else
                                delete new_inset;
                }
@@ -2976,7 +2939,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                if (insertInset(inset)) {
                        if (argument.empty())
-                               inset->edit(bv_, 0, 0, 0);
+                               inset->edit(bv_);
                } else
                        delete inset;
        }
@@ -3015,24 +2978,21 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
        case LFUN_INDEX_CREATE:
        {
-               InsetCommandParams p( "index" );
+               InsetCommandParams p("index");
                
                if (argument.empty()) {
-                       // Get the word immediately preceding the cursor
-                       Paragraph::size_type curpos = 
-                               bv_->getLyXText()->cursor.pos() - 1;
-
-                       string curstring;
-                       if (curpos >= 0 )
-                               curstring = bv_->getLyXText()
-                                       ->cursor.par()->getWord(curpos);
+                       // Get word or selection
+                       bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
+                       
+                       string const curstring = 
+                               bv_->getLyXText()->selectionAsString(buffer_);
 
-                       p.setContents( curstring );
+                       p.setContents(curstring);
                } else {
-                       p.setContents( argument );
+                       p.setContents(argument);
                }
 
-               owner_->getDialogs()->createIndex( p.getAsString() );
+               owner_->getDialogs()->createIndex(p.getAsString());
        }
        break;
                    
@@ -3051,14 +3011,11 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                    
        case LFUN_INDEX_INSERT_LAST:
        {
-               // Get word immediately preceding the cursor
-               Paragraph::size_type curpos = 
-                       bv_->getLyXText()->cursor.pos() - 1;
-               // Can't do that at the beginning of a paragraph
-               if (curpos < 0) break;
+               // Get word or selection
+               bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
 
-               string const curstring(bv_->getLyXText()
-                                      ->cursor.par()->getWord(curpos));
+               string const curstring = 
+                       bv_->getLyXText()->selectionAsString(buffer_);
 
                InsetCommandParams p("index", curstring);
                InsetIndex * inset = new InsetIndex(p);
@@ -3115,10 +3072,6 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
        break;
        
-       case LFUN_INSERT_NOTE:
-               insertNote();
-               break;
-
        case LFUN_SELFINSERT:
        {
                if (argument.empty()) break;
@@ -3141,7 +3094,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        }
                }
                
-               bv_->beforeChange(lt);
+               beforeChange(lt);
                LyXFont const old_font(lt->real_current_font);
                
                string::const_iterator cit = argument.begin();
@@ -3252,6 +3205,12 @@ void BufferView::Pimpl::protectedBlank(LyXText * lt)
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                InsetSpecialChar * new_inset =
                        new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
+#ifdef WITH_WARNINGS
+#warning Why is this code different from specialChar() below? (JMarc)
+// the code in specialChar is a generic version of what used to exist
+// for other special chars. I did not merge this case because of the
+// call to updateInset(), but what does it do?
+#endif
                if (!insertInset(new_inset))
                        delete new_inset;
                else
@@ -3260,7 +3219,7 @@ void BufferView::Pimpl::protectedBlank(LyXText * lt)
 }
 
 
-void BufferView::Pimpl::menuSeparator()
+void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
 {
        if (available()) {
                LyXText * lt = bv_->getLyXText();
@@ -3268,56 +3227,37 @@ void BufferView::Pimpl::menuSeparator()
                hideCursor();
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
-               insertInset(new_inset);
-       }
-}
-
-
-void BufferView::Pimpl::endOfSentenceDot()
-{
-       if (available()) {
-               hideCursor();
-               update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
+                       new InsetSpecialChar(kind);
                insertInset(new_inset);
        }
 }
 
 
-void BufferView::Pimpl::ldots()
+void BufferView::Pimpl::smartQuote()
 {
-       if (available())  {
-               hideCursor();
-               update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::LDOTS);
-               insertInset(new_inset);
-       }
-}
+       char c;
+       LyXText * lt = bv_->getLyXText();
 
+       if (lt->cursor.pos())
+               c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
+       else 
+               c = ' ';
 
-void BufferView::Pimpl::hyphenationPoint()
-{
-       if (available()) {
-               hideCursor();
-               update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
-               insertInset(new_inset);
-       }
+       hideCursor();
+       if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
+               Dispatch(LFUN_SELFINSERT, "\"");
 }
 
 
-void BufferView::Pimpl::insertNote()
+void BufferView::Pimpl::insertAndEditInset(Inset * inset)
 {
-       InsetInfo * new_inset = new InsetInfo();
-       insertInset(new_inset);
-       new_inset->edit(bv_, 0, 0, 0);
+       if (insertInset(inset))
+               inset->edit(bv_);
+       else
+               delete inset;
 }
 
-
 // Open and lock an updatable inset
 bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
 {
@@ -3329,11 +3269,7 @@ bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
                delete new_inset;
                return false;
        }
-       if (behind) {
-               LyXFont & font = lt->real_current_font;
-               new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
-       } else
-               new_inset->edit(bv_, 0, 0, 0);
+       new_inset->edit(bv_, !behind);
        return true;
 }