]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSelection.C
* src/frontends/qt4/GuiSelection.C
[lyx.git] / src / frontends / qt4 / GuiSelection.C
index bcade1bd61c2d3876364d9ca2e29585f2cbe2cfb..3a59d515cabb4779363ca1110fa361a318fdf4a7 100644 (file)
@@ -26,7 +26,6 @@ using lyx::support::internalLineEnding;
 using lyx::support::externalLineEnding;
 
 using std::endl;
-using std::string;
 
 namespace lyx {
 namespace frontend {
@@ -36,6 +35,15 @@ void GuiSelection::haveSelection(bool own)
        if (!qApp->clipboard()->supportsSelection())
                return;
 
+       // Tell qt that we have a selection by setting a dummy selection.
+       // We don't use the interface provided by Qt for setting the
+       // selection for performance reasons (see documentation of
+       // Selection::put()). Instead we only tell here that we have a
+       // selection by setting the selection to the empty string.
+       // The real selection is set in GuiApplication::x11EventFilter when
+       // an application actually requests it.
+       // This way calling Selection::have() is cheap and we can do it as
+       // often as we want.
        if (own)
                qApp->clipboard()->setText(QString(), QClipboard::Selection);
        // We don't need to do anything if own = false, as this case is
@@ -43,21 +51,21 @@ void GuiSelection::haveSelection(bool own)
 }
 
 
-string const GuiSelection::get() const
+docstring const GuiSelection::get() const
 {
        QString const str = qApp->clipboard()->text(QClipboard::Selection);
-       lyxerr[Debug::ACTION] << "GuiSelection::get: " << (const char*) str
+       lyxerr[Debug::ACTION] << "GuiSelection::get: " << fromqstr(str)
                              << endl;
        if (str.isNull())
-               return string();
+               return docstring();
 
-       return internalLineEnding(fromqstr(str));
+       return internalLineEnding(qstring_to_ucs4(str));
 }
 
 
-void GuiSelection::put(string const & str)
+void GuiSelection::put(docstring const & str)
 {
-       lyxerr[Debug::ACTION] << "GuiSelection::put: " << str << endl;
+       lyxerr[Debug::ACTION] << "GuiSelection::put: " << lyx::to_utf8(str) << endl;
 
        qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
                                   QClipboard::Selection);