]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiClipboard.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiClipboard.cpp
index b67361fb24ae0092645255685679ddb9fc9957a4..1fa6aba835f1eb2bdc34167ae7a72a76ef7f5d54 100644 (file)
@@ -46,6 +46,7 @@
 #include <QString>
 #include <QStringList>
 #include <QTextDocument>
+#include <QTimer>
 
 #include <boost/crc.hpp>
 
@@ -61,7 +62,7 @@ namespace lyx {
 
 namespace frontend {
 
-static QMimeData const * read_clipboard() 
+static QMimeData const * read_clipboard()
 {
        LYXERR(Debug::CLIPBOARD, "Getting Clipboard");
        QMimeData const * source =
@@ -93,7 +94,7 @@ void CacheMimeData::update()
 }
 
 
-QByteArray CacheMimeData::data(QString const & mimeType) const 
+QByteArray CacheMimeData::data(QString const & mimeType) const
 {
        return read_clipboard()->data(mimeType);
 }
@@ -112,7 +113,7 @@ GuiClipboard::GuiClipboard()
        connect(qApp->clipboard(), SIGNAL(dataChanged()),
                this, SLOT(on_dataChanged()));
        // initialize clipboard status.
-       on_dataChanged();
+       update();
 }
 
 
@@ -281,10 +282,10 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
                        image.save(toqstr(filename.absFileName()), "JPEG");
                else
                        LATTEST(false);
-               
+
                return filename;
        }
-       
+
        // get mime for type
        QString mime;
        switch (type) {
@@ -294,7 +295,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
        case WmfGraphicsType: mime = wmfMimeType(); break;
        default: LASSERT(false, return FileName());
        }
-       
+
        // get data
        if (!cache_.hasFormat(mime))
                return FileName();
@@ -309,7 +310,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
                       << filename.absFileName() << " for writing");
                return FileName();
        }
-       
+
        // write the (LinkBack) PDF data
        f.write(ar);
        if (type == LinkBackGraphicsType) {
@@ -357,7 +358,7 @@ QString tidyHtml(QString input)
        converter.setHtml(input);
        return converter.toHtml("utf-8");
 }
-}
+} // namespace
 
 
 docstring const GuiClipboard::getAsText(TextType type) const
@@ -459,7 +460,7 @@ bool GuiClipboard::hasTextContents(Clipboard::TextType type) const
        case LyXTextType:
                return cache_.hasFormat(lyxMimeType());
        case PlainTextType:
-               return cache_.hasText();       
+               return cache_.hasText();
        case HtmlTextType:
                return cache_.hasHtml();
        case LaTeXTextType:
@@ -493,7 +494,7 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const
 #else
                return false;
 #endif // Q_OS_MAC
-       
+
        // get mime data
        QStringList const & formats = cache_.formats();
        LYXERR(Debug::CLIPBOARD, "We found " << formats.size() << " formats");
@@ -508,7 +509,7 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const
        case PdfGraphicsType: mime = pdfMimeType(); break;
        default: LASSERT(false, return false);
        }
-       
+
        return cache_.hasFormat(mime);
 }
 
@@ -537,7 +538,7 @@ bool GuiClipboard::isInternal() const
 bool GuiClipboard::hasInternal() const
 {
        // Windows and Mac OS X does not have the concept of ownership;
-       // the clipboard is a fully global resource so all applications 
+       // the clipboard is a fully global resource so all applications
        // are notified of changes. However, on Windows ownership is
        // emulated by Qt through the OleIsCurrentClipboard() API, while
        // on Mac OS X we deal with this issue by ourself.
@@ -550,6 +551,17 @@ bool GuiClipboard::hasInternal() const
 
 
 void GuiClipboard::on_dataChanged()
+{
+       update();
+#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
+       // Retry on Windows (#10109)
+       if (cache_.formats().count() == 0) {
+               QTimer::singleShot(100, this, SLOT(update()));
+       }
+#endif
+}
+
+void GuiClipboard::update()
 {
        //Note: we do not really need to run cache_.update() unless the
        //data has been changed *and* the GuiClipboard has been queried.