]> git.saurik.com Git - wxWidgets.git/commitdiff
Fixup clipboard usage a bit more.
authorRobin Dunn <robin@alldunn.com>
Mon, 26 Aug 2002 17:50:44 +0000 (17:50 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 26 Aug 2002 17:50:44 +0000 (17:50 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16790 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/src/stc/ScintillaWX.cpp
src/stc/ScintillaWX.cpp

index 200a36cbf0f2d6a706468549a6d3deabdbc590b1..b35314aba43a3654e7ccc8fe84ee5f542984704a 100644 (file)
@@ -321,11 +321,12 @@ void ScintillaWX::Copy() {
     if (currentPos != anchor) {
         SelectionText st;
         CopySelectionRange(&st);
-        wxTheClipboard->Open();
-        wxTheClipboard->UsePrimarySelection();
-        wxString text = stc2wx(st.s, st.len);
-        wxTheClipboard->SetData(new wxTextDataObject(text));
-        wxTheClipboard->Close();
+        if (wxTheClipboard->Open()) {
+            wxTheClipboard->UsePrimarySelection();
+            wxString text = stc2wx(st.s, st.len);
+            wxTheClipboard->SetData(new wxTextDataObject(text));
+            wxTheClipboard->Close();
+        }
     }
 }
 
@@ -335,12 +336,13 @@ void ScintillaWX::Paste() {
     ClearSelection();
 
     wxTextDataObject data;
-    bool gotData;
+    bool gotData = FALSE;
 
-    wxTheClipboard->Open();
-    wxTheClipboard->UsePrimarySelection();
-    gotData = wxTheClipboard->GetData(data);
-    wxTheClipboard->Close();
+    if (wxTheClipboard->Open()) {
+        wxTheClipboard->UsePrimarySelection();
+        gotData = wxTheClipboard->GetData(data);
+        wxTheClipboard->Close();
+    }
     if (gotData) {
         wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
         int        len = strlen(buf);
@@ -356,12 +358,16 @@ void ScintillaWX::Paste() {
 
 bool ScintillaWX::CanPaste() {
     bool canPaste = FALSE;
+    bool didOpen;
 
-    if (! wxTheClipboard->IsOpened()) {
+    if ( (didOpen = !wxTheClipboard->IsOpened()) )
         wxTheClipboard->Open();
+
+    if (wxTheClipboard->IsOpened()) {
         wxTheClipboard->UsePrimarySelection();
         canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
-        wxTheClipboard->Close();
+        if (didOpen)
+            wxTheClipboard->Close();
     }
     return canPaste;
 }
index 200a36cbf0f2d6a706468549a6d3deabdbc590b1..b35314aba43a3654e7ccc8fe84ee5f542984704a 100644 (file)
@@ -321,11 +321,12 @@ void ScintillaWX::Copy() {
     if (currentPos != anchor) {
         SelectionText st;
         CopySelectionRange(&st);
-        wxTheClipboard->Open();
-        wxTheClipboard->UsePrimarySelection();
-        wxString text = stc2wx(st.s, st.len);
-        wxTheClipboard->SetData(new wxTextDataObject(text));
-        wxTheClipboard->Close();
+        if (wxTheClipboard->Open()) {
+            wxTheClipboard->UsePrimarySelection();
+            wxString text = stc2wx(st.s, st.len);
+            wxTheClipboard->SetData(new wxTextDataObject(text));
+            wxTheClipboard->Close();
+        }
     }
 }
 
@@ -335,12 +336,13 @@ void ScintillaWX::Paste() {
     ClearSelection();
 
     wxTextDataObject data;
-    bool gotData;
+    bool gotData = FALSE;
 
-    wxTheClipboard->Open();
-    wxTheClipboard->UsePrimarySelection();
-    gotData = wxTheClipboard->GetData(data);
-    wxTheClipboard->Close();
+    if (wxTheClipboard->Open()) {
+        wxTheClipboard->UsePrimarySelection();
+        gotData = wxTheClipboard->GetData(data);
+        wxTheClipboard->Close();
+    }
     if (gotData) {
         wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
         int        len = strlen(buf);
@@ -356,12 +358,16 @@ void ScintillaWX::Paste() {
 
 bool ScintillaWX::CanPaste() {
     bool canPaste = FALSE;
+    bool didOpen;
 
-    if (! wxTheClipboard->IsOpened()) {
+    if ( (didOpen = !wxTheClipboard->IsOpened()) )
         wxTheClipboard->Open();
+
+    if (wxTheClipboard->IsOpened()) {
         wxTheClipboard->UsePrimarySelection();
         canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
-        wxTheClipboard->Close();
+        if (didOpen)
+            wxTheClipboard->Close();
     }
     return canPaste;
 }