]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSelection.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiSelection.cpp
index 1b405513a964fb458c5e3eeb9da7da31903e8992..362da4aba54d1c9c074c19ca974aa6fd3fdc3721 100644 (file)
 namespace lyx {
 namespace frontend {
 
-using support::internalLineEnding;
-using support::externalLineEnding;
-
 
 GuiSelection::GuiSelection()
-       : selection_supported_(qApp->clipboard()->supportsSelection())
+       : schedule_check_(true),
+       selection_supported_(qApp->clipboard()->supportsSelection())
 {
        connect(qApp->clipboard(), SIGNAL(selectionChanged()),
                this, SLOT(on_dataChanged()));
-       // initialize clipboard status.
-       on_dataChanged();
 }
 
 
@@ -55,7 +51,7 @@ void GuiSelection::haveSelection(bool own)
        // an application actually requests it.
        // This way calling Selection::have() is cheap and we can do it as
        // often as we want.
-       LYXERR(Debug::SELECTION, "GuiSelection: setting dummy selection");
+       //LYXERR(Debug::SELECTION, "GuiSelection: setting dummy selection");
        if (own)
                qApp->clipboard()->setText(QString(), QClipboard::Selection);
        // We don't need to do anything if own = false, as this case is
@@ -76,7 +72,7 @@ docstring const GuiSelection::get() const
        if (str.isNull())
                return docstring();
 
-       return internalLineEnding(qstring_to_ucs4(str));
+       return internalLineEnding(str);
 }
 
 
@@ -84,7 +80,7 @@ void GuiSelection::put(docstring const & str)
 {
        LYXERR(Debug::SELECTION, "GuiSelection::put: " << to_utf8(str));
 
-       qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
+       qApp->clipboard()->setText(externalLineEnding(str),
                                   QClipboard::Selection);
 }
 
@@ -96,22 +92,25 @@ void GuiSelection::on_dataChanged()
 }
 
 
-bool GuiSelection::empty()
+bool GuiSelection::empty() const
 {
        if (!selection_supported_)
                return true;
 
+       // Cache which is to speed up selection-status read
+       // (4 calls when open Edit menu).
+       static bool text_selection_empty;
        if (schedule_check_) {
-               text_selection_empty_ = qApp->clipboard()->
+               text_selection_empty = qApp->clipboard()->
                        text(QClipboard::Selection).isEmpty();
                schedule_check_ = false;
        }
 
-       LYXERR(Debug::SELECTION, "GuiSelection::filled: " << !text_selection_empty_);
-       return text_selection_empty_;
+       LYXERR(Debug::SELECTION, "GuiSelection::filled: " << !text_selection_empty);
+       return text_selection_empty;
 }
 
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiSelection_moc.cpp"
+#include "moc_GuiSelection.cpp"