]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/treectrl.cpp
don't overwrite the existing local file if we failed to open it but it does exist
[wxWidgets.git] / src / msw / treectrl.cpp
index 416f0c5c42be813e975e59ff2a38b6dee3fd150a..fac8ddbaeeebe070ca79e5e5807e571ccc58c2cb 100644 (file)
@@ -618,7 +618,9 @@ void wxTreeCtrl::Init()
 {
     m_textCtrl = NULL;
     m_hasAnyAttr = false;
+#if wxUSE_DRAGIMAGE
     m_dragImage = NULL;
+#endif
     m_pVirtualRoot = NULL;
 
     // initialize the global array of events now as it can't be done statically
@@ -932,7 +934,7 @@ void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text)
     {
         if ( item == m_idEdited )
         {
-            ::SetWindowText(hwndEdit, text);
+            ::SetWindowText(hwndEdit, text.wx_str());
         }
     }
 }
@@ -1671,15 +1673,26 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
     wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, this, item);
     if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
     {
-        if ( !::SelectItem(GetHwnd(), HITEM(item), select) )
+        if ( HasFlag(wxTR_MULTIPLE) )
         {
-            wxLogLastError(wxT("TreeView_SelectItem"));
+            if ( !::SelectItem(GetHwnd(), HITEM(item), select) )
+            {
+                wxLogLastError(wxT("TreeView_SelectItem"));
+                return;
+            }
         }
-        else // ok
+        else // single selection
         {
-            event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
-            (void)GetEventHandler()->ProcessEvent(event);
+            // use TreeView_SelectItem() to deselect the previous selection
+            if ( !TreeView_SelectItem(GetHwnd(), HITEM(item)) )
+            {
+                wxLogLastError(wxT("TreeView_SelectItem"));
+                return;
+            }
         }
+
+        event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
+        (void)GetEventHandler()->ProcessEvent(event);
     }
     //else: program vetoed the change
 }
@@ -2125,6 +2138,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                 }
 #endif // __WXWINCE__
 
+#if wxUSE_DRAGIMAGE
                 if ( m_dragImage )
                 {
                     m_dragImage->Move(wxPoint(x, y));
@@ -2137,6 +2151,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                         m_dragImage->Show();
                     }
                 }
+#endif // wxUSE_DRAGIMAGE
                 break;
 
             case WM_LBUTTONUP:
@@ -2162,6 +2177,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                 // fall through
 
             case WM_RBUTTONUP:
+#if wxUSE_DRAGIMAGE
                 if ( m_dragImage )
                 {
                     m_dragImage->EndDrag();
@@ -2178,6 +2194,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                     // are selected simultaneously which is quite weird
                     TreeView_SelectDropTarget(GetHwnd(), 0);
                 }
+#endif // wxUSE_DRAGIMAGE
                 break;
         }
     }
@@ -2318,6 +2335,24 @@ wxTreeCtrl::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
         if ( wParam == VK_SPACE || wParam == VK_RETURN )
             return 0;
     }
+#if wxUSE_DRAGIMAGE
+    else if ( nMsg == WM_KEYDOWN )
+    {
+        if ( wParam == VK_ESCAPE )
+        {
+            if ( m_dragImage )
+            {
+                m_dragImage->EndDrag();
+                delete m_dragImage;
+                m_dragImage = NULL;
+
+                // if we don't do it, the tree seems to think that 2 items
+                // are selected simultaneously which is quite weird
+                TreeView_SelectDropTarget(GetHwnd(), 0);
+            }
+        }
+    }
+#endif // wxUSE_DRAGIMAGE
 
     return wxControl::MSWDefWindowProc(nMsg, wParam, lParam);
 }
@@ -2706,6 +2741,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 
         case TVN_BEGINDRAG:
         case TVN_BEGINRDRAG:
+#if wxUSE_DRAGIMAGE
             if ( event.IsAllowed() )
             {
                 // normally this is impossible because the m_dragImage is
@@ -2716,6 +2752,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
                 m_dragImage->BeginDrag(wxPoint(0,0), this);
                 m_dragImage->Show();
             }
+#endif // wxUSE_DRAGIMAGE
             break;
 
         case TVN_DELETEITEM: