]> 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 09ef7f22d347760c062250e4d804238d751a5115..fb46ea88cc2aa86342592d0291dde68db5c37e92 100644 (file)
@@ -3,6 +3,7 @@
 #include <ctime>
 #include <unistd.h>
 #include <sys/wait.h>
+#include <locale.h>
 
 #ifdef __GNUG__
 #pragma implementation
@@ -15,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"
@@ -30,7 +29,7 @@
 #include "insets/insettext.h"
 /// added for Dispatch functions
 #include "lyx_cb.h"
-#include "filedlg.h"
+#include "frontends/FileDialog.h"
 #include "lyx_main.h"
 #include "FloatList.h"
 #include "support/filetools.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 void math_insert_symbol(BufferView *, string const &);
-extern bool math_insert_greek(BufferView *, char);
 extern int greek_kb_flag;
 
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::slot;
-#endif
-
+using std::vector;
 using std::find_if;
 using std::pair;
 using std::endl;
 using std::make_pair;
 using std::min;
+using SigC::slot;
 
 /* the selection possible is needed, that only motion events are 
  * used, where the bottom press event was on the drawing area too */
@@ -77,19 +75,21 @@ bool selection_possible = false;
 extern BufferList bufferlist;
 extern char ascii_type;
 
+extern bool math_insert_greek(BufferView *, char);
 extern void sigchldhandler(pid_t pid, int * status);
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 const unsigned int saved_positions_num = 20;
 
-static inline
+namespace {
+
+inline
 void waitForX()
 {
        XSync(fl_get_display(), 0);
 }
 
 
-static
 void SetXtermCursor(Window win)
 {
        static Cursor cursor;
@@ -103,50 +103,52 @@ void SetXtermCursor(Window win)
        XFlush(fl_get_display());
 }
 
+} // anon namespace
+
 
 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
             int xpos, int ypos, int width, int height)
-       : bv_(b), owner_(o), cursor_timeout(400)
+       : bv_(b), owner_(o), buffer_(0),
+         current_scrollbar_value(0), cursor_timeout(400),
+         workarea_(xpos, ypos, width, height), using_xterm_cursor(false)
 {
-       buffer_ = 0;
-       workarea_ = new WorkArea(xpos, ypos, width, height);
        // Setup the signals
-       workarea_->scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
-       workarea_->workAreaExpose
+       workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB));
+       workarea_.workAreaExpose
                .connect(slot(this, &BufferView::Pimpl::workAreaExpose));
-       workarea_->workAreaEnter
+       workarea_.workAreaEnter
                .connect(slot(this, &BufferView::Pimpl::enterView));
-       workarea_->workAreaLeave
+       workarea_.workAreaLeave
                .connect(slot(this, &BufferView::Pimpl::leaveView));
-       workarea_->workAreaButtonPress
+       workarea_.workAreaButtonPress
                .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress));
-       workarea_->workAreaButtonRelease
+       workarea_.workAreaButtonRelease
                .connect(slot(this,
                              &BufferView::Pimpl::workAreaButtonRelease));
-       workarea_->workAreaMotionNotify
+       workarea_.workAreaMotionNotify
                .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify));
-       workarea_->workAreaDoubleClick
+       workarea_.workAreaDoubleClick
                .connect(slot(this, &BufferView::Pimpl::doubleClick));
-       workarea_->workAreaTripleClick
+       workarea_.workAreaTripleClick
                .connect(slot(this, &BufferView::Pimpl::tripleClick));
-       workarea_->workAreaKeyPress
+       workarea_.workAreaKeyPress
                .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
        
-       screen_ = 0;
+       //screen_ = 0;
 
        cursor_timeout.timeout.connect(slot(this,
                                            &BufferView::Pimpl::cursorToggle));
-       current_scrollbar_value = 0;
+       //current_scrollbar_value = 0;
        cursor_timeout.start();
-       workarea_->setFocus();
-       using_xterm_cursor = false;
+       workarea_.setFocus();
+       //using_xterm_cursor = false;
        saved_positions.resize(saved_positions_num);
 }
 
 
 Painter & BufferView::Pimpl::painter() 
 {
-       return workarea_->getPainter();
+       return workarea_.getPainter();
 }
 
 
@@ -162,7 +164,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                // only if the buffer is still loaded.
                // Also set the owner of the test to 0
                //              bv_->text->owner(0);
-               textcache.add(buffer_, workarea_->workWidth(), bv_->text);
+               textcache.add(buffer_, workarea_.workWidth(), bv_->text);
                if (lyxerr.debugging())
                        textcache.show(lyxerr, "BufferView::buffer");
                
@@ -176,8 +178,9 @@ void BufferView::Pimpl::buffer(Buffer * b)
        
        // Nuke old image
        // screen is always deleted when the buffer is changed.
-       delete screen_;
-       screen_ = 0;
+       screen_.reset(0);
+       //delete screen_;
+       //screen_ = 0;
 
        // If we are closing the buffer, use the first buffer as current
        if (!buffer_) {
@@ -209,7 +212,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                owner_->updateToolbar();
                owner_->getDialogs()->hideBufferDependent();
                updateScrollbar();
-               workarea_->redraw();
+               workarea_.redraw();
 
                // Also remove all remaining text's from the testcache.
                // (there should not be any!) (if there is any it is a
@@ -220,14 +223,14 @@ void BufferView::Pimpl::buffer(Buffer * b)
        }
        // should update layoutchoice even if we don't have a buffer.
        owner_->updateLayoutChoice();
-       owner_->getMiniBuffer()->Init();
+
        owner_->updateWindowTitle();
 }
 
 
 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
 {
-       workarea_->resize(xpos, ypos, width, height);
+       workarea_.resize(xpos, ypos, width, height);
        update(bv_->text, SELECT);
        redraw();
 }
@@ -243,13 +246,13 @@ void BufferView::Pimpl::resize()
 void BufferView::Pimpl::redraw()
 {
        lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
-       workarea_->redraw();
+       workarea_.redraw();
 }
 
 
 bool BufferView::Pimpl::fitCursor(LyXText * text)
 {
-       Assert(screen_);
+       lyx::Assert(screen_.get());
  
        bool ret = screen_->FitCursor(text, bv_);
        if (ret)
@@ -277,15 +280,15 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        LyXParagraph * selendpar = 0;
        UpdatableInset * the_locking_inset = 0;
        
-       int pos = 0;
-       int selstartpos = 0;
-       int selendpos = 0;
-       int selection = 0;
-       int mark_set = 0;
+       LyXParagraph::size_type pos = 0;
+       LyXParagraph::size_type selstartpos = 0;
+       LyXParagraph::size_type selendpos = 0;
+       bool selection = false;
+       bool mark_set  = false;
 
        ProhibitInput(bv_);
 
-       owner_->getMiniBuffer()->Set(_("Formatting document..."));   
+       owner_->message(_("Formatting document..."));
 
        if (bv_->text) {
                par = bv_->text->cursor.par();
@@ -302,11 +305,11 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        } else {
                // See if we have a text in TextCache that fits
                // the new buffer_ with the correct width.
-               bv_->text = textcache.findFit(buffer_, workarea_->workWidth());
+               bv_->text = textcache.findFit(buffer_, workarea_.workWidth());
                if (bv_->text) {
                        if (lyxerr.debugging()) {
                                lyxerr << "Found a LyXText that fits:\n";
-                               textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_->workWidth(), bv_->text)));
+                               textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text)));
                        }
                        // Set the owner of the newly found text
                        //      bv_->text->owner(bv_);
@@ -342,11 +345,12 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        // this will scroll the screen such that the cursor becomes visible
        updateScrollbar();
        redraw();
-       owner_->getMiniBuffer()->Init();
+
        bv_->setState();
        AllowInput(bv_);
 
-       owner_->getDialogs()->hideSplash();
+       /// get rid of the splash screen if it's not gone already
+       owner_->getDialogs()->destroySplash();
  
        return 0;
 }
@@ -355,8 +359,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
 void BufferView::Pimpl::updateScreen()
 {
        // Regenerate the screen.
-       delete screen_;
-       screen_ = new LyXScreen(*workarea_);
+       screen_.reset(new LyXScreen(workarea_));
 }
 
 
@@ -367,7 +370,7 @@ void BufferView::Pimpl::updateScrollbar()
         * be possible */
 
        if (!buffer_) {
-               workarea_->setScrollbar(0, 1.0);
+               workarea_.setScrollbar(0, 1.0);
                return;
        }
        
@@ -384,31 +387,31 @@ void BufferView::Pimpl::updateScrollbar()
 
        // check if anything has changed.
        if (max2 == cbth &&
-           height2 == workarea_->height() &&
+           height2 == workarea_.height() &&
            current_scrollbar_value == cbsf)
                return; // no
        max2 = cbth;
-       height2 = workarea_->height();
+       height2 = workarea_.height();
        current_scrollbar_value = cbsf;
 
        if (cbth <= height2) { // text is smaller than screen
-               workarea_->setScrollbar(0, 1.0); // right?
+               workarea_.setScrollbar(0, 1.0); // right?
                return;
        }
 
-       long maximum_height = workarea_->height() * 3 / 4 + cbth;
+       long maximum_height = workarea_.height() * 3 / 4 + cbth;
        long value = cbsf;
 
        // set the scrollbar
-       double hfloat = workarea_->height();
+       double hfloat = workarea_.height();
        double maxfloat = maximum_height;
 
        float slider_size = 0.0;
        int slider_value = value;
 
-       workarea_->setScrollbarBounds(0, bv_->text->height - workarea_->height());
-       double lineh = bv_->text->DefaultHeight();
-       workarea_->setScrollbarIncrements(lineh);
+       workarea_.setScrollbarBounds(0, bv_->text->height - workarea_.height());
+       double const lineh = bv_->text->DefaultHeight();
+       workarea_.setScrollbarIncrements(lineh);
        if (maxfloat > 0.0) {
                if ((hfloat / maxfloat) * float(height2) < 3)
                        slider_size = 3.0/float(height2);
@@ -417,7 +420,7 @@ void BufferView::Pimpl::updateScrollbar()
        } else
                slider_size = hfloat;
 
-       workarea_->setScrollbar(slider_value, slider_size / workarea_->height());
+       workarea_.setScrollbar(slider_value, slider_size / workarea_.height());
 }
 
 
@@ -430,7 +433,7 @@ void BufferView::Pimpl::scrollCB(double value)
        if (current_scrollbar_value < 0)
                current_scrollbar_value = 0;
    
-       if (!screen_)
+       if (!screen_.get())
                return;
 
        screen_->Draw(bv_->text, bv_, current_scrollbar_value);
@@ -444,7 +447,7 @@ void BufferView::Pimpl::scrollCB(double value)
  
        int const height = vbt->DefaultHeight();
        int const first = static_cast<int>((bv_->text->first + height));
-       int const last = static_cast<int>((bv_->text->first + workarea_->height() - height));
+       int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
 
        if (vbt->cursor.y() < first)
                vbt->SetCursorFromCoordinates(bv_, 0, first);
@@ -458,17 +461,17 @@ void BufferView::Pimpl::scrollCB(double value)
 int BufferView::Pimpl::scrollUp(long time)
 {
        if (!buffer_) return 0;
-       if (!screen_) return 0;
+       if (!screen_.get()) return 0;
    
-       double value = workarea_->getScrollbarValue();
+       double value = workarea_.getScrollbarValue();
    
        if (value == 0) return 0;
 
        float add_value =  (bv_->text->DefaultHeight()
                            + float(time) * float(time) * 0.125);
    
-       if (add_value > workarea_->height())
-               add_value = float(workarea_->height() -
+       if (add_value > workarea_.height())
+               add_value = float(workarea_.height() -
                                  bv_->text->DefaultHeight());
    
        value -= add_value;
@@ -476,7 +479,7 @@ int BufferView::Pimpl::scrollUp(long time)
        if (value < 0)
                value = 0;
    
-       workarea_->setScrollbarValue(value);
+       workarea_.setScrollbarValue(value);
    
        scrollCB(value); 
        return 0;
@@ -486,10 +489,10 @@ int BufferView::Pimpl::scrollUp(long time)
 int BufferView::Pimpl::scrollDown(long time)
 {
        if (!buffer_) return 0;
-       if (!screen_) return 0;
+       if (!screen_.get()) return 0;
    
-       double value= workarea_->getScrollbarValue();
-       pair<float, float> p = workarea_->getScrollbarBounds();
+       double value = workarea_.getScrollbarValue();
+       pair<float, float> p = workarea_.getScrollbarBounds();
        double max = p.second;
        
        if (value == max) return 0;
@@ -497,8 +500,8 @@ int BufferView::Pimpl::scrollDown(long time)
        float add_value =  (bv_->text->DefaultHeight()
                            + float(time) * float(time) * 0.125);
    
-       if (add_value > workarea_->height())
-               add_value = float(workarea_->height() -
+       if (add_value > workarea_.height())
+               add_value = float(workarea_.height() -
                                  bv_->text->DefaultHeight());
    
        value += add_value;
@@ -506,7 +509,7 @@ int BufferView::Pimpl::scrollDown(long time)
        if (value > max)
                value = max;
 
-       workarea_->setScrollbarValue(value);
+       workarea_.setScrollbarValue(value);
        
        scrollCB(value); 
        return 0;
@@ -525,7 +528,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
        if (!(state & Button1MotionMask))
                return;
 
-       if (!buffer_ || !screen_) return;
+       if (!buffer_ || !screen_.get()) return;
 
        // Check for inset locking
        if (bv_->theLockingInset()) {
@@ -570,7 +573,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
        last_click_x = -1;
        last_click_y = -1;
 
-       if (!buffer_ || !screen_) return;
+       if (!buffer_ || !screen_.get()) return;
 
        Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
 
@@ -630,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;
@@ -679,7 +682,7 @@ void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button)
        if (text->bv_owner && bv_->theLockingInset())
            return;
 
-       if (screen_ && button == 1) {
+       if (screen_.get() && button == 1) {
            if (text->bv_owner) {
                screen_->HideCursor();
                screen_->ToggleSelection(text, bv_);
@@ -706,7 +709,7 @@ void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
        if (text->bv_owner && bv_->theLockingInset())
            return;
 
-       if (screen_ && (button == 1)) {
+       if (screen_.get() && (button == 1)) {
                screen_->HideCursor();
                screen_->ToggleSelection(text, bv_);
                text->CursorHome(bv_);
@@ -724,7 +727,7 @@ void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
 void BufferView::Pimpl::enterView()
 {
        if (active() && available()) {
-               SetXtermCursor(workarea_->getWin());
+               SetXtermCursor(workarea_.getWin());
                using_xterm_cursor = true;
        }
 }
@@ -733,7 +736,7 @@ void BufferView::Pimpl::enterView()
 void BufferView::Pimpl::leaveView()
 {
        if (using_xterm_cursor) {
-               XUndefineCursor(fl_get_display(), workarea_->getWin());
+               XUndefineCursor(fl_get_display(), workarea_.getWin());
                using_xterm_cursor = false;
        }
 }
@@ -742,7 +745,7 @@ void BufferView::Pimpl::leaveView()
 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                                              unsigned int button)
 {
-       if (!buffer_ || !screen_) return;
+       if (!buffer_ || !screen_.get()) return;
 
        // If we hit an inset, we have the inset coordinates in these
        // and inset_hit points to the inset.  If we do not hit an
@@ -762,7 +765,8 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
        
        selection_possible = false;
        
-       if (button >= 2) return;
+       if (button == 2)
+               return;
 
        bv_->setState();
        owner_->showState();
@@ -791,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;
@@ -808,76 +813,20 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                bool hit = false;
                char c = ' ';
                if (bv_->text->cursor.pos() <
-                   bv_->text->cursor.par()->Last()) {
+                   bv_->text->cursor.par()->size()) {
                        c = bv_->text->cursor.par()->
                                GetChar(bv_->text->cursor.pos());
                }
-#ifndef NEW_INSETS
-              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
-#endif
                        if (bv_->text->cursor.pos() - 1 >= 0) {
                        c = bv_->text->cursor.par()->
                                GetChar(bv_->text->cursor.pos() - 1);
-#ifndef NEW_INSETS
-                       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;
-                       }
-#endif
                }
                if (hit == true) {
-#ifndef NEW_INSETS
-                       bv_->toggleFloat();
-#endif
                        selection_possible = false;
                        return;
                }
        }
 
-#ifndef NEW_INSETS
-       // 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;
-               }
-       }
-#endif
-
        // Maybe we want to edit a bibitem ale970302
        if (bv_->text->cursor.par()->bibkey && x < 20 + 
            bibitemMaxWidth(bv_, textclasslist.
@@ -898,15 +847,17 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
 Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
                                         unsigned int /* button */)
 {
-       if (!screen_)
+       if (!screen_.get())
                return 0;
   
        int y_tmp = y + text->first;
   
        LyXCursor cursor;
        text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
+       text->SetCursor(bv_, cursor, cursor.par(),cursor.pos(),true);
+
 
-       if (cursor.pos() < cursor.par()->Last()
+       if (cursor.pos() < cursor.par()->size()
            && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
            && cursor.par()->GetInset(cursor.pos())
            && cursor.par()->GetInset(cursor.pos())->Editable()) {
@@ -915,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()); 
@@ -939,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)
@@ -951,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()); 
@@ -967,12 +919,12 @@ 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();
-       work_area_height = workarea_->height();
+       work_area_width = workarea_.workWidth();
+       work_area_height = workarea_.height();
        if (buffer_ != 0) {
                if (widthChange) {
                        // All buffers need a resize
@@ -997,14 +949,11 @@ void BufferView::Pimpl::workAreaExpose()
 
                        // The main window size has changed, repaint most stuff
                        redraw();
-                       // ...including the minibuffer
-                       owner_->getMiniBuffer()->Init();
-
-               } else if (screen_)
+               } else if (screen_.get())
                    screen_->Redraw(bv_->text, bv_);
        } else {
                // Grey box when we don't have a buffer
-               workarea_->greyOut();
+               workarea_.greyOut();
        }
 
        // always make sure that the scrollbar is sane.
@@ -1016,7 +965,7 @@ void BufferView::Pimpl::workAreaExpose()
 
 void BufferView::Pimpl::update()
 {
-       if (screen_) screen_->Update(bv_->text, bv_);
+       if (screen_.get()) screen_->Update(bv_->text, bv_);
 }
 
 // Values used when calling update:
@@ -1078,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();
        }
 }
 
@@ -1107,7 +1051,7 @@ void BufferView::Pimpl::cursorToggle()
 
        updatelist.update(bv_);
        
-       if (!screen_) {
+       if (!screen_.get()) {
                cursor_timeout.restart();
                return;
        }
@@ -1138,12 +1082,12 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text)
                text->CursorUp(bv_);
        
        if (text->inset_owner ||
-           text->cursor.row()->height() < workarea_->height())
+           text->cursor.row()->height() < workarea_.height())
                screen_->Draw(bv_->text, bv_,
                              text->cursor.y()
                              - text->cursor.row()->baseline()
                              + text->cursor.row()->height()
-                             - workarea_->height() + 1 );
+                             - workarea_.height() + 1 );
        updateScrollbar();
 }
 
@@ -1153,7 +1097,7 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
        if (!text->cursor.row()->next())
                return;
        
-       int y = text->first + workarea_->height();
+       int y = text->first + workarea_.height();
 //     if (text->inset_owner)
 //             y += bv_->text->first;
        text->GetRowNearY(y);
@@ -1166,7 +1110,7 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
                text->CursorDown(bv_);
        
        if (text->inset_owner ||
-           text->cursor.row()->height() < workarea_->height())
+           text->cursor.row()->height() < workarea_.height())
                screen_->Draw(bv_->text, bv_, text->cursor.y() -
                              text->cursor.row()->baseline());
        updateScrollbar();
@@ -1194,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);
+       }
 }
 
 
@@ -1204,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);
 
@@ -1220,10 +1166,13 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
                return;
 
        bv_->text->SetCursor(bv_, par,
-                            min(par->Last(), saved_positions[i].par_pos));
+                            min(par->size(), saved_positions[i].par_pos));
+
        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);
+       }
 }
 
 
@@ -1244,10 +1193,10 @@ void BufferView::Pimpl::setState()
        LyXText * text = bv_->getLyXText();
        if (text->real_current_font.isRightToLeft() &&
            text->real_current_font.latex() != LyXFont::ON) {
-               if (owner_->getIntl()->primarykeymap)
+               if (owner_->getIntl()->keymap == Intl::PRIMARY)
                        owner_->getIntl()->KeyMapSec();
        } else {
-               if (!owner_->getIntl()->primarykeymap)
+               if (owner_->getIntl()->keymap == Intl::SECONDARY)
                        owner_->getIntl()->KeyMapPrim();
        }
 }
@@ -1286,52 +1235,52 @@ void BufferView::Pimpl::insetUnlock()
 
 bool BufferView::Pimpl::focus() const
 {
-       return workarea_->hasFocus();
+       return workarea_.hasFocus();
 }
 
 
 void BufferView::Pimpl::focus(bool f)
 {
-       if (f) workarea_->setFocus();
+       if (f) workarea_.setFocus();
 }
 
 
 bool BufferView::Pimpl::active() const
 {
-       return workarea_->active();
+       return workarea_.active();
 }
 
 
 bool BufferView::Pimpl::belowMouse() const 
 {
-       return workarea_->belowMouse();
+       return workarea_.belowMouse();
 }
 
 
 void BufferView::Pimpl::showCursor()
 {
-       if (screen_)
+       if (screen_.get())
                screen_->ShowCursor(bv_->text, bv_);
 }
 
 
 void BufferView::Pimpl::hideCursor()
 {
-       if (screen_)
+       if (screen_.get())
                screen_->HideCursor();
 }
 
 
 void BufferView::Pimpl::toggleSelection(bool b)
 {
-       if (screen_)
+       if (screen_.get())
                screen_->ToggleSelection(bv_->text, bv_, b);
 }
 
 
 void BufferView::Pimpl::toggleToggle()
 {
-       if (screen_)
+       if (screen_.get())
                screen_->ToggleToggle(bv_->text, bv_);
 }
 
@@ -1339,8 +1288,8 @@ void BufferView::Pimpl::toggleToggle()
 void BufferView::Pimpl::center() 
 {
        beforeChange(bv_->text);
-       if (bv_->text->cursor.y() > static_cast<int>((workarea_->height() / 2))) {
-               screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_->height() / 2);
+       if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) {
+               screen_->Draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2);
        } else {
                screen_->Draw(bv_->text, bv_, 0);
        }
@@ -1356,7 +1305,7 @@ void BufferView::Pimpl::pasteClipboard(bool asPara)
        screen_->HideCursor();
        beforeChange(bv_->text);
        
-       string const clip(workarea_->getClipboard());
+       string const clip(workarea_.getClipboard());
        
        if (clip.empty()) return;
 
@@ -1371,7 +1320,7 @@ void BufferView::Pimpl::pasteClipboard(bool asPara)
 
 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
 {
-       workarea_->putClipboard(stuff);
+       workarea_.putClipboard(stuff);
 }
 
 
@@ -1406,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;
 }
@@ -1419,7 +1368,6 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
        if (filename.empty()) {
                // Launch a file browser
                string initpath = lyxrc.document_path;
-               LyXFileDlg fileDlg;
 
                if (available()) {
                        string const trypath = owner_->buffer()->filepath;
@@ -1428,21 +1376,24 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
                                initpath = trypath;
                }
 
-               // launches dialog
-               ProhibitInput(bv_);
-               fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-               fileDlg.SetButton(1, _("Examples"), 
-                                 AddPath(system_lyxdir, "examples"));
-               filename = fileDlg.Select(_("Select Document to Insert"),
-                                         initpath, "*.lyx");
-               AllowInput(bv_);
+               FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"),
+                       LFUN_FILE_INSERT,
+                       make_pair(string(_("Documents")), string(lyxrc.document_path)),
+                       make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
+
+               FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)"));
+               if (result.first == FileDialog::Later)
+                       return;
+
+               filename = result.second;
 
                // check selected filename
                if (filename.empty()) {
-                       owner_->getMiniBuffer()->Set(_("Canceled."));
+                       owner_->message(_("Canceled."));
                        return;
                }
-       } 
+       }
 
        // get absolute path of file and make sure the filename ends
        // with .lyx
@@ -1451,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);
        }
 }
 
@@ -1477,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;
        }
@@ -1613,12 +1554,13 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
        break;
        
+       case LFUN_FILE_INSERT_ASCII_PARA:
+               InsertAsciiFile(bv_, argument, true);
+               break;
+
        case LFUN_FILE_INSERT_ASCII:
-       {
-               bool asPara = (argument == "paragraph");
-               InsertAsciiFile(bv_, string(), asPara);
-       }
-       break;
+               InsertAsciiFile(bv_, argument, false);
+               break;
                
        case LFUN_LAYOUT:
        {
@@ -1742,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;
@@ -1802,7 +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);
-               if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last()
+               if (TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size()
                    && TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos())
                    == LyXParagraph::META_INSET
                    && TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos())
@@ -1811,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);
@@ -1840,7 +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!
-                   TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->Last() &&
+                   TEXT(bv_)->cursor.pos() < TEXT(bv_)->cursor.par()->size() &&
                    (TEXT(bv_)->cursor.par()->GetChar(TEXT(bv_)->cursor.pos()) ==
                     LyXParagraph::META_INSET) &&
                    TEXT(bv_)->cursor.par()->GetInset(TEXT(bv_)->cursor.pos()) &&
@@ -2158,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_));
                }
@@ -2175,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;
@@ -2192,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();
@@ -2211,7 +2169,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                LyXCursor cursor = TEXT(bv_)->cursor;
 
                if (!TEXT(bv_)->selection) {
-                       if (cursor.pos() == cursor.par()->Last()) {
+                       if (cursor.pos() == cursor.par()->size()) {
                                TEXT(bv_)->CursorRight(bv_);
                                cursor = TEXT(bv_)->cursor;
                                if (cursor.pos() == 0
@@ -2710,7 +2668,12 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
               
        case LFUN_INSERT_MATH:
        {
-               math_insert_symbol(bv_, argument);
+               if (!available())
+                       break;
+               InsetFormula * f = new InsetFormula(true);
+               bv_->open_new_inset(f);
+               f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
        }
        break;
        
@@ -2883,21 +2846,34 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if (!bv_->insertInset(inset, "Standard", true))
                        delete inset;
        }
+                
        break;
 
        case LFUN_CHILD_INSERT:
        {
-               InsetCommandParams p;
-               p.setFromString(argument);
+               InsetInclude::Params p;
+               p.cparams.setFromString(argument);
+               p.masterFilename_ = buffer_->fileName();
 
-               InsetInclude * inset = new InsetInclude(p, *buffer_);
+               InsetInclude * inset = new InsetInclude(p);
                if (!bv_->insertInset(inset))
                        delete inset;
-               else
+               else {
                        bv_->updateInset(inset, true);
+                       bv_->owner()->getDialogs()->showInclude(inset);
+               }
        }
        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;
@@ -2979,8 +2955,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        for (string::size_type i = 0;
                             i < argument.length(); ++i) {
                                if (greek_kb_flag) {
-                                       if (!math_insert_greek(bv_,
-                                                              argument[i]))
+                                       if (!math_insert_greek(bv_, argument[i]))
                                                owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
                                } else
                                        owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
@@ -2998,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;
        }