]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
small fix with footnote, use stringstream some more
[lyx.git] / src / BufferView_pimpl.C
index 9256cc994ece4c2d6b9fbdccb15c4b387c1ed896..fb46ea88cc2aa86342592d0291dde68db5c37e92 100644 (file)
@@ -16,8 +16,6 @@
 #include "lyxrow.h"
 #include "LyXView.h"
 #include "commandtags.h"
-#include "lyxfunc.h"
-#include "minibuffer.h"
 #include "font.h"
 #include "bufferview_funcs.h"
 #include "TextCache.h"
 #include "insets/insettabular.h"
 #include "insets/insettheorem.h"
 #include "insets/insetcaption.h"
+#include "insets/insetfloatlist.h"
 #include "mathed/formulamacro.h"
+#include "gettext.h"
+
 extern LyXTextClass::size_type current_layout;
 extern int greek_kb_flag;
 
@@ -82,7 +83,6 @@ const unsigned int saved_positions_num = 20;
 
 namespace {
 
-//static
 inline
 void waitForX()
 {
@@ -90,7 +90,6 @@ void waitForX()
 }
 
 
-//static
 void SetXtermCursor(Window win)
 {
        static Cursor cursor;
@@ -224,7 +223,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
        }
        // should update layoutchoice even if we don't have a buffer.
        owner_->updateLayoutChoice();
-       owner_->getMiniBuffer()->Init();
+
        owner_->updateWindowTitle();
 }
 
@@ -253,7 +252,7 @@ void BufferView::Pimpl::redraw()
 
 bool BufferView::Pimpl::fitCursor(LyXText * text)
 {
-       Assert(screen_.get());
+       lyx::Assert(screen_.get());
  
        bool ret = screen_->FitCursor(text, bv_);
        if (ret)
@@ -289,7 +288,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
 
        ProhibitInput(bv_);
 
-       owner_->getMiniBuffer()->Set(_("Formatting document..."));   
+       owner_->message(_("Formatting document..."));
 
        if (bv_->text) {
                par = bv_->text->cursor.par();
@@ -346,7 +345,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        // this will scroll the screen such that the cursor becomes visible
        updateScrollbar();
        redraw();
-       owner_->getMiniBuffer()->Init();
+
        bv_->setState();
        AllowInput(bv_);
 
@@ -361,8 +360,6 @@ void BufferView::Pimpl::updateScreen()
 {
        // Regenerate the screen.
        screen_.reset(new LyXScreen(workarea_));
-       //delete screen_;
-       //screen_ = new LyXScreen(workarea_);
 }
 
 
@@ -636,7 +633,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
                UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
                selection_possible = false;
                owner_->updateLayoutChoice();
-               owner_->getMiniBuffer()->Set(inset->EditMessage());
+               owner_->message(inset->EditMessage());
                inset->InsetButtonPress(bv_, xpos, ypos, button);
                inset->Edit(bv_, xpos, ypos, button);
                return;
@@ -798,7 +795,8 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                        bv_->text->SetCursorParUndo(bv_->buffer());
                }
 
-               owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
+               owner_->message(inset_hit->EditMessage());
+
                if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
                        // Highly editable inset, like math
                        UpdatableInset *inset = (UpdatableInset *)inset_hit;
@@ -810,73 +808,6 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                return;
        }
 
-#ifndef NEW_INSETS
-       // check whether we want to open a float
-       if (bv_->text) {
-               bool hit = false;
-               char c = ' ';
-               if (bv_->text->cursor.pos() <
-                   bv_->text->cursor.par()->Last()) {
-                       c = bv_->text->cursor.par()->
-                               GetChar(bv_->text->cursor.pos());
-               }
-              if(!bv_->text->selection)
-               if (c == LyXParagraph::META_FOOTNOTE
-                   || c == LyXParagraph::META_MARGIN
-                   || c == LyXParagraph::META_FIG
-                   || c == LyXParagraph::META_TAB
-                   || c == LyXParagraph::META_WIDE_FIG
-                   || c == LyXParagraph::META_WIDE_TAB
-                    || c == LyXParagraph::META_ALGORITHM){
-                       hit = true;
-               } else
-                       if (bv_->text->cursor.pos() - 1 >= 0) {
-                       c = bv_->text->cursor.par()->
-                               GetChar(bv_->text->cursor.pos() - 1);
-                       if (c == LyXParagraph::META_FOOTNOTE
-                           || c == LyXParagraph::META_MARGIN
-                           || c == LyXParagraph::META_FIG
-                           || c == LyXParagraph::META_TAB
-                           || c == LyXParagraph::META_WIDE_FIG 
-                           || c == LyXParagraph::META_WIDE_TAB
-                           || c == LyXParagraph::META_ALGORITHM){
-                               // We are one step too far to the right
-                               bv_->text->CursorLeft(bv_);
-                               hit = true;
-                       }
-               }
-               if (hit == true) {
-                       bv_->toggleFloat();
-                       selection_possible = false;
-                       return;
-               }
-       }
-       // Do we want to close a float? (click on the float-label)
-       if (bv_->text->cursor.row()->par()->footnoteflag == 
-           LyXParagraph::OPEN_FOOTNOTE
-           && bv_->text->cursor.row()->previous() &&
-           bv_->text->cursor.row()->previous()->par()->
-           footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
-               LyXFont font(LyXFont::ALL_SANE);
-               font.setSize(LyXFont::SIZE_FOOTNOTE);
-
-               int box_x = 20; // LYX_PAPER_MARGIN;
-               box_x += lyxfont::width(" wide-tab ", font);
-
-               unsigned int screen_first = bv_->text->first;
-
-               if (x < box_x
-                   && y + screen_first > bv_->text->cursor.y() -
-                   bv_->text->cursor.row()->baseline()
-                   && y + screen_first < bv_->text->cursor.y() -
-                   bv_->text->cursor.row()->baseline()
-                   + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
-                       bv_->toggleFloat();
-                       selection_possible = false;
-                       return;
-               }
-       }
-#else
        // check whether we want to open a float
        if (bv_->text) {
                bool hit = false;
@@ -895,7 +826,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                        return;
                }
        }
-#endif
+
        // Maybe we want to edit a bibitem ale970302
        if (bv_->text->cursor.par()->bibkey && x < 20 + 
            bibitemMaxWidth(bv_, textclasslist.
@@ -923,12 +854,10 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
   
        LyXCursor cursor;
        text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
+       text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
+
 
-#ifndef NEW_INSETS
-       if (cursor.pos() < cursor.par()->Last()
-#else
        if (cursor.pos() < cursor.par()->size()
-#endif
            && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
            && cursor.par()->GetInset(cursor.pos())
            && cursor.par()->GetInset(cursor.pos())->Editable()) {
@@ -937,16 +866,16 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
                Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
                LyXFont font = text->GetFont(bv_->buffer(),
                                                  cursor.par(), cursor.pos());
-               int width = tmpinset->width(bv_, font);
-               int inset_x = font.isVisibleRightToLeft()
+               int const width = tmpinset->width(bv_, font);
+               int const inset_x = font.isVisibleRightToLeft()
                        ? cursor.x() - width : cursor.x();
-               int start_x = inset_x + tmpinset->scroll();
-               int end_x = inset_x + width;
+               int const start_x = inset_x + tmpinset->scroll();
+               int const end_x = inset_x + width;
 
                if (x > start_x && x < end_x
                    && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
                    && y_tmp < cursor.y() + tmpinset->descent(bv_, font)) {
-                       text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
+                       text->SetCursor(bv_, cursor.par(),cursor.pos(), true);
                        x = x - start_x;
                        // The origin of an inset is on the baseline
                        y = y_tmp - (text->cursor.y()); 
@@ -961,11 +890,11 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
                Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
                LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
                                                  cursor.pos()-1);
-               int width = tmpinset->width(bv_, font);
-               int inset_x = font.isVisibleRightToLeft()
+               int const width = tmpinset->width(bv_, font);
+               int const inset_x = font.isVisibleRightToLeft()
                        ? cursor.x() : cursor.x() - width;
-               int start_x = inset_x + tmpinset->scroll();
-               int end_x = inset_x + width;
+               int const start_x = inset_x + tmpinset->scroll();
+               int const end_x = inset_x + width;
 
                if (x > start_x && x < end_x
                    && y_tmp > cursor.y() - tmpinset->ascent(bv_, font)
@@ -973,7 +902,8 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
 #if 0
                        if (move_cursor && (tmpinset != bv_->theLockingInset()))
 #endif
-                               text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
+                               text->SetCursor(bv_, cursor.par(),
+                                               cursor.pos() - 1, true);
                        x = x - start_x;
                        // The origin of an inset is on the baseline
                        y = y_tmp - (text->cursor.y()); 
@@ -989,8 +919,8 @@ void BufferView::Pimpl::workAreaExpose()
        static int work_area_width = 0;
        static unsigned int work_area_height = 0;
 
-       bool widthChange = workarea_.workWidth() != work_area_width;
-       bool heightChange = workarea_.height() != work_area_height;
+       bool const widthChange = workarea_.workWidth() != work_area_width;
+       bool const heightChange = workarea_.height() != work_area_height;
 
        // update from work area
        work_area_width = workarea_.workWidth();
@@ -1019,9 +949,6 @@ void BufferView::Pimpl::workAreaExpose()
 
                        // The main window size has changed, repaint most stuff
                        redraw();
-                       // ...including the minibuffer
-                       owner_->getMiniBuffer()->Init();
-
                } else if (screen_.get())
                    screen_->Redraw(bv_->text, bv_);
        } else {
@@ -1100,12 +1027,7 @@ void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
        }
 
        if ((f & CHANGE)) {
-               if (buffer_->isLyxClean()) {
-                       buffer_->markDirty();
-                       owner_->getMiniBuffer()->setTimer(4);
-               } else {
-                       buffer_->markDirty();
-               }
+               buffer_->markDirty();
        }
 }
 
@@ -1216,8 +1138,10 @@ void BufferView::Pimpl::savePosition(unsigned int i)
        saved_positions[i] = Position(buffer_->fileName(),
                                      bv_->text->cursor.par()->id(),
                                      bv_->text->cursor.pos());
-       if (i > 0)
-               owner_->getMiniBuffer()->Set(_("Saved bookmark ") + tostr(i));
+       if (i > 0) {
+               string const str = _("Saved bookmark") + ' ' + tostr(i);
+               owner_->message(str);
+       }
 }
 
 
@@ -1226,7 +1150,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        if (i >= saved_positions_num)
                return;
 
-       string fname = saved_positions[i].filename;
+       string const fname = saved_positions[i].filename;
 
        beforeChange(bv_->text);
 
@@ -1241,16 +1165,14 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        if (!par)
                return;
 
-#ifndef NEW_INSETS
-       bv_->text->SetCursor(bv_, par,
-                            min(par->Last(), saved_positions[i].par_pos));
-#else
        bv_->text->SetCursor(bv_, par,
                             min(par->size(), saved_positions[i].par_pos));
-#endif
+
        update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
-       if (i > 0)
-               owner_->getMiniBuffer()->Set(_("Moved to bookmark ") + tostr(i));
+       if (i > 0) {
+               string const str = _("Moved to bookmark") + ' ' + tostr(i);
+               owner_->message(str);
+       }
 }
 
 
@@ -1433,7 +1355,7 @@ Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
                find_if(Buffer::inset_iterator(
                        cursor.par(), cursor.pos()),
                        buffer_->inset_iterator_end(),
-                       compare_memfun(&Inset::LyxCode, code)
+                       lyx::compare_memfun(&Inset::LyxCode, code)
                        );
        return it != buffer_->inset_iterator_end() ? (*it) : 0;
 }
@@ -1468,7 +1390,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
 
                // check selected filename
                if (filename.empty()) {
-                       owner_->getMiniBuffer()->Set(_("Canceled."));
+                       owner_->message(_("Canceled."));
                        return;
                }
        }
@@ -1480,16 +1402,18 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
                filename += ".lyx";
 
        // Inserts document
-       owner_->getMiniBuffer()->Set(_("Inserting document"),
-                                    MakeDisplayPath(filename), "...");
+       string const s1 = _("Inserting document") + ' '
+               + MakeDisplayPath(filename) + " ...";
+       owner_->message(s1);
        bool const res = bv_->insertLyXFile(filename);
        if (res) {
-               owner_->getMiniBuffer()->Set(_("Document"),
-                                            MakeDisplayPath(filename),
-                                            _("inserted."));
+               string const str = _("Document") + ' '
+                       + MakeDisplayPath(filename) + ' ' + _("inserted.");
+               owner_->message(str);
        } else {
-               owner_->getMiniBuffer()->Set(_("Could not insert document"),
-                                            MakeDisplayPath(filename));
+               string const str = _("Could not insert document") + ' '
+                       + MakeDisplayPath(filename);
+               owner_->message(str);
        }
 }
 
@@ -1506,23 +1430,11 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                break;
 
        case LFUN_TOC_INSERT:
-       case LFUN_LOA_INSERT:
-       case LFUN_LOF_INSERT:
-       case LFUN_LOT_INSERT:
        {
                InsetCommandParams p;
-               
-               if (action == LFUN_TOC_INSERT )
-                       p.setCmdName( "tableofcontents" );
-               else if (action == LFUN_LOA_INSERT )
-                       p.setCmdName( "listofalgorithms" );
-               else if (action == LFUN_LOF_INSERT )
-                       p.setCmdName( "listoffigures" );
-               else
-                       p.setCmdName( "listoftables" );
-
-               Inset * inset = new InsetTOC( p );
-               if (!bv_->insertInset( inset, "Standard", true ) )
+               p.setCmdName("tableofcontents");
+               Inset * inset = new InsetTOC(p);
+               if (!bv_->insertInset(inset, "Standard", true))
                        delete inset;
                break;
        }
@@ -1772,7 +1684,16 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        bv_->updateInset(TEXT(bv_)->inset_owner, true);
                update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                break;
+
+       case LFUN_TRANSPOSE_CHARS:
+               update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
+               TEXT(bv_)->TransposeChars(*bv_);
+               if (TEXT(bv_)->inset_owner)
+                       bv_->updateInset(TEXT(bv_)->inset_owner, true);
+               update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+               break;
                
+                                         
        case LFUN_INSERT_LABEL:
                MenuInsertLabel(bv_, argument);
                break;
@@ -1832,11 +1753,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
                if (is_rtl)
                        TEXT(bv_)->CursorLeft(bv_, false);
-#ifndef NEW_INSETS
-               if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
-#else
                if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
-#endif
                    && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
                    == LyXParagraph::META_INSET
                    && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
@@ -1845,10 +1762,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        owner_->getLyXFunc()->setMessage(tmpinset->EditMessage());
                        int y = 0;
                        if (is_rtl) {
-                               LyXFont font = 
+                               LyXFont const font = 
                                        TEXT(bv_)->GetFont(buffer_,
-                                                             TEXT(bv_)->cursor.par(),
-                                                             TEXT(bv_)->cursor.pos()); 
+                                                          TEXT(bv_)->cursor.par(),
+                                                          TEXT(bv_)->cursor.pos());    
                                y = tmpinset->descent(bv_,font);
                        }
                        tmpinset->Edit(bv_, 0, y, 0);
@@ -1874,11 +1791,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if (!is_rtl)
                        TEXT(bv_)->CursorLeft(bv_, false);
                if ((is_rtl || cur != TEXT(bv_)->cursor) && // only if really moved!
-#ifndef NEW_INSETS
-                   TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
-#else
                    TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
-#endif
                    (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
                     LyXParagraph::META_INSET) &&
                    TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
@@ -2196,13 +2109,16 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
        case LFUN_PROTECTEDSPACE:
        {
-               LyXLayout const & style =
-                       textclasslist.Style(buffer_->params.textclass,
-                                           TEXT(bv_)->cursor.par()->GetLayout());
+               LyXLayout const & style = textclasslist
+                       .Style(buffer_->params.textclass,
+                              TEXT(bv_)->cursor.par()->GetLayout());
 
                if (style.free_spacing) {
                        TEXT(bv_)->InsertChar(bv_, ' ');
-                       update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+                       update(TEXT(bv_),
+                              BufferView::SELECT
+                              | BufferView::FITCUR
+                              | BufferView::CHANGE);
                } else {
                        bv_->protectedBlank(TEXT(bv_));
                }
@@ -2213,12 +2129,14 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        case LFUN_SETMARK:
                if (TEXT(bv_)->mark_set) {
                        beforeChange(TEXT(bv_));
-                       update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
+                       update(TEXT(bv_),
+                              BufferView::SELECT|BufferView::FITCUR);
                        owner_->getLyXFunc()->setMessage(N_("Mark removed"));
                } else {
                        beforeChange(TEXT(bv_));
                        TEXT(bv_)->mark_set = 1;
-                       update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR);
+                       update(TEXT(bv_),
+                              BufferView::SELECT|BufferView::FITCUR);
                        owner_->getLyXFunc()->setMessage(N_("Mark set"));
                }
                TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
@@ -2230,7 +2148,9 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        TEXT(bv_)->sel_cursor = 
                                TEXT(bv_)->cursor;
                        update(TEXT(bv_),
-                              BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+                              BufferView::SELECT
+                              | BufferView::FITCUR
+                              | BufferView::CHANGE);
                        // It is possible to make it a lot faster still
                        // just comment out the line below...
                        showCursor();
@@ -2249,11 +2169,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                LyXCursor cursor = TEXT(bv_)->cursor;
 
                if (!TEXT(bv_)->selection) {
-#ifndef NEW_INSETS
-                       if (cursor.pos() == cursor.par()->Last()) {
-#else
                        if (cursor.pos() == cursor.par()->size()) {
-#endif
                                TEXT(bv_)->CursorRight(bv_);
                                cursor = TEXT(bv_)->cursor;
                                if (cursor.pos() == 0
@@ -2930,13 +2846,14 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if (!bv_->insertInset(inset, "Standard", true))
                        delete inset;
        }
+                
        break;
 
        case LFUN_CHILD_INSERT:
        {
-               InsetInclude::InsetIncludeParams p;
+               InsetInclude::Params p;
                p.cparams.setFromString(argument);
-               p.buffer = buffer_;
+               p.masterFilename_ = buffer_->fileName();
 
                InsetInclude * inset = new InsetInclude(p);
                if (!bv_->insertInset(inset))
@@ -2948,6 +2865,15 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
        break; 
 
+       case LFUN_FLOAT_LIST:
+       {
+               // We should check the argument for validity. (Lgb)
+               Inset * inset = new InsetFloatList(argument);
+               if (!bv_->insertInset(inset, "Standard", true))
+                       delete inset;
+       }
+       break;
+       
        case LFUN_INSERT_NOTE:
                bv_->insertNote();
                break;
@@ -3047,7 +2973,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                } else {
                        // if we don't have an argument there was something
                        // strange going on so we just tell this to someone!
-                       owner_->getLyXFunc()->setErrorMessage(N_("No argument givven"));
+                       owner_->getLyXFunc()->setErrorMessage(N_("No argument given"));
                }
                break;
        }