]> git.saurik.com Git - wxWidgets.git/blobdiff - src/stc/ScintillaWX.cpp
better <HR> tag handling in wxHTML
[wxWidgets.git] / src / stc / ScintillaWX.cpp
index 103ce927962f45cb8b23b8421579be49116221ea..1effa1fe99d8ba60ffe677b52ad69f3cff1690ae 100644 (file)
@@ -44,7 +44,7 @@ private:
 };
 
 
-
+#if wxUSE_DRAG_AND_DROP
 bool wxSTCDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) {
     return swx->DoDropText(x, y, data);
 }
@@ -60,6 +60,7 @@ wxDragResult  wxSTCDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult def
 void  wxSTCDropTarget::OnLeave() {
     swx->DoDragLeave();
 }
+#endif
 
 
 class wxSTCCallTip : public wxWindow {
@@ -109,9 +110,11 @@ ScintillaWX::~ScintillaWX() {
 
 void ScintillaWX::Initialise() {
     //ScintillaBase::Initialise();
+#if wxUSE_DRAG_AND_DROP
     dropTarget = new wxSTCDropTarget;
     dropTarget->SetScintilla(this);
     stc->SetDropTarget(dropTarget);
+#endif
 }
 
 
@@ -121,16 +124,33 @@ void ScintillaWX::Finalise() {
 
 
 void ScintillaWX::StartDrag() {
-    wxDropSource        source(wMain.GetID());
-    wxTextDataObject    data(dragChars);
-    wxDragResult        result;
-
-    source.SetData(data);
-    result = source.DoDragDrop(TRUE);
-    if (result == wxDragMove && dropWentOutside)
-        ClearSelection();
-    inDragDrop = FALSE;
-    SetDragPosition(invalidPosition);
+#if wxUSE_DRAG_AND_DROP
+    wxString dragText(drag.s, drag.len);
+
+    // Send an event to allow the drag text to be changed
+    wxStyledTextEvent evt(wxEVT_STC_START_DRAG, stc->GetId());
+    evt.SetEventObject(stc);
+    evt.SetDragText(dragText);
+    evt.SetDragAllowMove(TRUE);
+    evt.SetPosition(wxMin(stc->GetSelectionStart(),
+                          stc->GetSelectionEnd()));
+    stc->GetEventHandler()->ProcessEvent(evt);
+    dragText = evt.GetDragText();
+
+    if (dragText.Length()) {
+        wxDropSource        source(wMain.GetID());
+        wxTextDataObject    data(dragText);
+        wxDragResult        result;
+
+        source.SetData(data);
+        dropWentOutside = TRUE;
+        result = source.DoDragDrop(evt.GetDragAllowMove());
+        if (result == wxDragMove && dropWentOutside)
+            ClearSelection();
+        inDragDrop = FALSE;
+        SetDragPosition(invalidPosition);
+    }
+#endif
 }
 
 
@@ -217,9 +237,10 @@ void ScintillaWX::NotifyParent(SCNotification scn) {
 
 void ScintillaWX::Copy() {
     if (currentPos != anchor) {
-        char* text = CopySelectionRange();
+        SelectionText st;
+        CopySelectionRange(&st);
         wxTheClipboard->Open();
-        wxTheClipboard->SetData(new wxTextDataObject(text));
+        wxTheClipboard->SetData(new wxTextDataObject(wxString(st.s, st.len)));
         wxTheClipboard->Close();
     }
 }
@@ -230,12 +251,12 @@ void ScintillaWX::Paste() {
     ClearSelection();
 
     wxTextDataObject data;
-    bool canPaste;
+    bool gotData;
 
     wxTheClipboard->Open();
-    canPaste = wxTheClipboard->GetData(data);
+    gotData = wxTheClipboard->GetData(data);
     wxTheClipboard->Close();
-    if (canPaste) {
+    if (gotData) {
         wxString str = data.GetText();
         int      len = str.Length();
         pdoc->InsertString(currentPos, str.c_str(), len);
@@ -249,11 +270,10 @@ void ScintillaWX::Paste() {
 
 
 bool ScintillaWX::CanPaste() {
-    wxTextDataObject data;
     bool canPaste;
 
     wxTheClipboard->Open();
-    canPaste = wxTheClipboard->GetData(data);
+    canPaste = wxTheClipboard->IsSupported( wxDF_TEXT );
     wxTheClipboard->Close();
 
     return canPaste;
@@ -485,30 +505,59 @@ void ScintillaWX::DoOnListBox() {
 
 //----------------------------------------------------------------------
 
+#if wxUSE_DRAG_AND_DROP
 bool ScintillaWX::DoDropText(long x, long y, const wxString& data) {
     SetDragPosition(invalidPosition);
-    int movePos = PositionFromLocation(Point(x,y));
-    DropAt(movePos, data, dragResult == wxDragMove, FALSE); // TODO: rectangular?
-    return TRUE;
+
+    // Send an event to allow the drag details to be changed
+    wxStyledTextEvent evt(wxEVT_STC_DO_DROP, stc->GetId());
+    evt.SetEventObject(stc);
+    evt.SetDragResult(dragResult);
+    evt.SetX(x);
+    evt.SetY(y);
+    evt.SetPosition(PositionFromLocation(Point(x,y)));
+    evt.SetDragText(data);
+    stc->GetEventHandler()->ProcessEvent(evt);
+
+    dragResult = evt.GetDragResult();
+    if (dragResult == wxDragMove || dragResult == wxDragCopy) {
+        DropAt(evt.GetPosition(),
+               evt.GetDragText(),
+               dragResult == wxDragMove,
+               FALSE); // TODO: rectangular?
+        return TRUE;
+    }
+    return FALSE;
 }
 
 
 wxDragResult ScintillaWX::DoDragEnter(wxCoord x, wxCoord y, wxDragResult def) {
-    return def;
+    dragResult = def;
+    return dragResult;
 }
 
 
 wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
     SetDragPosition(PositionFromLocation(Point(x, y)));
-    dragResult = def;
-    return def;
+
+    // Send an event to allow the drag result to be changed
+    wxStyledTextEvent evt(wxEVT_STC_DRAG_OVER, stc->GetId());
+    evt.SetEventObject(stc);
+    evt.SetDragResult(def);
+    evt.SetX(x);
+    evt.SetY(y);
+    evt.SetPosition(PositionFromLocation(Point(x,y)));
+    stc->GetEventHandler()->ProcessEvent(evt);
+
+    dragResult = evt.GetDragResult();
+    return dragResult;
 }
 
 
 void ScintillaWX::DoDragLeave() {
     SetDragPosition(invalidPosition);
 }
-
+#endif
 //----------------------------------------------------------------------
 
 // Redraw all of text area. This paint will not be abandoned.