]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
fix memory leaks
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index d68b4cc392c34986c598ebf17b9f51940e36273b..2c53eb524ff99b995b1e6a4b8e0073ae0ffb8367 100644 (file)
 #include "BufferView.h"
 #include "CoordCache.h"
 #include "Cursor.h"
-#include "debug.h"
 #include "Font.h"
 #include "FuncRequest.h"
-#include "gettext.h"
 #include "GuiApplication.h"
 #include "GuiKeySymbol.h"
 #include "GuiPainter.h"
 #include "graphics/GraphicsImage.h"
 #include "graphics/GraphicsLoader.h"
 
+#include "support/debug.h"
+#include "support/gettext.h"
 #include "support/FileName.h"
-#include "support/ForkedcallsController.h"
+#include "support/ForkedCalls.h"
 
 #include "frontends/Application.h"
 #include "frontends/FontMetrics.h"
@@ -55,7 +55,6 @@
 #include <QTimer>
 
 #include <boost/bind.hpp>
-#include <boost/current_function.hpp>
 
 #ifdef Q_WS_X11
 #include <QX11Info>
@@ -79,7 +78,6 @@ using std::string;
 namespace lyx {
 
 using support::FileName;
-using support::ForkedcallsController;
 
 
 /// return the LyX mouse button state from Qt's
@@ -191,24 +189,17 @@ SyntheticMouseEvent::SyntheticMouseEvent()
 
 
 
-// All the below connection objects are needed because of a bug in some
-// versions of GCC (<=2.96 are on the suspects list.) By having and assigning
-// to these connections we avoid a segfault upon startup, and also at exit.
-// (Lgb)
-
-static boost::signals::connection timecon;
-
-
 GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
        : buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
-         cursor_visible_(false), cursor_timeout_(400),
+         cursor_visible_(false),
     need_resize_(false), schedule_redraw_(false),
                preedit_lines_(1)
 {
        buffer.workAreaManager().add(this);
        // Setup the signals
-       timecon = cursor_timeout_.timeout
-               .connect(boost::bind(&GuiWorkArea::toggleCursor, this));
+       cursor_timeout_.setInterval(400);
+       connect(&cursor_timeout_, SIGNAL(timeout()),
+               this, SLOT(toggleCursor()));
 
        cursor_timeout_.start();
 
@@ -246,9 +237,8 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
        // PageStep only depends on the viewport height.
        verticalScrollBar()->setPageStep(viewport()->height());
 
-       LYXERR(Debug::GUI, BOOST_CURRENT_FUNCTION
-               << "\n viewport width\t" << viewport()->width()
-               << "\n viewport height\t" << viewport()->height());
+       LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
+               << "  viewport height: " << viewport()->height());
 
        // Enables input methods for asian languages.
        // Must be set when creating custom text editing widgets.
@@ -261,6 +251,7 @@ GuiWorkArea::~GuiWorkArea()
 {
        buffer_view_->buffer().workAreaManager().remove(this);
        delete buffer_view_;
+       delete cursor_;
 }
 
 
@@ -292,7 +283,7 @@ void GuiWorkArea::stopBlinkingCursor()
 void GuiWorkArea::startBlinkingCursor()
 {
        showCursor();
-       cursor_timeout_.restart();
+       cursor_timeout_.start();
 }
 
 
@@ -323,6 +314,8 @@ void GuiWorkArea::redraw()
        updateScreen();
        update(0, 0, viewport()->width(), viewport()->height());
 
+       lyx_view_->updateStatusBar();
+
        if (lyxerr.debugging(Debug::WORKAREA))
                buffer_view_->coordCache().dump();
 }
@@ -372,7 +365,7 @@ void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
 
        // Skip these when selecting
        if (cmd.action != LFUN_MOUSE_MOTION) {
-               lyx_view_->updateLayoutChoice(false);
+               lyx_view_->updateLayoutList();
                lyx_view_->updateToolbars();
        }
 
@@ -396,7 +389,7 @@ void GuiWorkArea::resizeBufferView()
        // We are already inside a paint event.
        lyx_view_->setBusy(true);
        buffer_view_->resize(viewport()->width(), viewport()->height());
-       lyx_view_->updateLayoutChoice(false);
+       lyx_view_->updateLayoutList();
        lyx_view_->setBusy(false);
        need_resize_ = false;
 }
@@ -463,10 +456,7 @@ void GuiWorkArea::toggleCursor()
        // Use this opportunity to deal with any child processes that
        // have finished but are waiting to communicate this fact
        // to the rest of LyX.
-       ForkedcallsController & fcc = ForkedcallsController::get();
-       fcc.handleCompletedProcesses();
-
-       cursor_timeout_.restart();
+       support::ForkedCallsController::handleCompletedProcesses();
 }
 
 
@@ -502,7 +492,7 @@ void GuiWorkArea::adjustViewWithScrollBar(int action)
 
        if (lyxrc.cursor_follows_scrollbar) {
                buffer_view_->setCursorFromScrollbar();
-               lyx_view_->updateLayoutChoice(false);
+               lyx_view_->updateLayoutList();
        }
        // Show the cursor immediately after any operation.
        startBlinkingCursor();
@@ -657,18 +647,15 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
 #ifdef Q_WS_X11
        if (XEventsQueued(QX11Info::display(), 0) > 1 && ev->isAutoRepeat() 
                        && (Qt::Key_PageDown || Qt::Key_PageUp)) {
-               LYXERR(Debug::KEY, BOOST_CURRENT_FUNCTION
-                       << "\nsystem is busy: scroll key event ignored");
+               LYXERR(Debug::KEY, "system is busy: scroll key event ignored");
                ev->ignore();
                return;
        }
 #endif
 
-       LYXERR(Debug::KEY, BOOST_CURRENT_FUNCTION
-               << " count=" << ev->count()
-               << " text=" << fromqstr(ev->text())
-               << " isAutoRepeat=" << ev->isAutoRepeat()
-               << " key=" << ev->key());
+       LYXERR(Debug::KEY, " count: " << ev->count()
+               << " text: " << fromqstr(ev->text())
+               << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key());
 
        KeySymbol sym;
        setKeySymbol(&sym, ev);
@@ -710,12 +697,8 @@ void GuiWorkArea::update(int x, int y, int w, int h)
 void GuiWorkArea::paintEvent(QPaintEvent * ev)
 {
        QRect const rc = ev->rect();
-       /*
-       LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
-               << " y: " << rc.y()
-               << " w: " << rc.width()
-               << " h: " << rc.height() << endl;
-       */
+       // LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
+       //      << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
 
        if (need_resize_) {
                verticalScrollBar()->setPageStep(viewport()->height());
@@ -774,14 +757,13 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
 
        if (!commit_string.isEmpty()) {
 
-               LYXERR(Debug::KEY, BOOST_CURRENT_FUNCTION
-                       << " preeditString =" << fromqstr(e->preeditString())
-                       << " commitString  =" << fromqstr(e->commitString()));
+               LYXERR(Debug::KEY, "preeditString: " << fromqstr(e->preeditString())
+                       << " commitString: " << fromqstr(e->commitString()));
 
                int key = 0;
 
                // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
-               for (int i = 0; i < commit_string.size(); ++i) {
+               for (int i = 0; i != commit_string.size(); ++i) {
                        QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
                        keyPressEvent(&ev);
                }
@@ -829,7 +811,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
        // cursor_pos : cursor position in preedit string.
        size_t cursor_pos = 0;
        bool cursor_is_visible = false;
-       for (int i = 0; i < att.size(); ++i) {
+       for (int i = 0; i != att.size(); ++i) {
                if (att.at(i).type == QInputMethodEvent::Cursor) {
                        cursor_pos = att.at(i).start;
                        cursor_is_visible = att.at(i).length != 0;
@@ -846,7 +828,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
        // rLength : selected string length in IM.
        size_t rLength = 0;
        if (cursor_pos < preedit_length) {
-               for (int i = 0; i < att.size(); ++i) {
+               for (int i = 0; i != att.size(); ++i) {
                        if (att.at(i).type == QInputMethodEvent::TextFormat) {
                                if (att.at(i).start <= int(cursor_pos)
                                        && int(cursor_pos) < att.at(i).start + att.at(i).length) {
@@ -1060,12 +1042,14 @@ GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
 {
        GuiWorkArea * wa = new GuiWorkArea(buffer, view);
        wa->setUpdatesEnabled(false);
+       // Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
+       // when hiding it again below).
+       showBar(count() > 0);
        addTab(wa, wa->windowTitle());
        QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
                this, SLOT(updateTabText(GuiWorkArea *)));
        // Hide tabbar if there's only one tab.
        showBar(count() > 1);
-       wa->resizeBufferView();
        return wa;
 }