]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/treectrl.cpp
wxFileConfig ctor now (again) uses the files in the correct locations if the
[wxWidgets.git] / src / msw / treectrl.cpp
index 0cf7bb7585d7d12a62c9f31e2dc0232381341b31..549b53236f1cfcdb1cffd4b1f68696b6162b3703 100644 (file)
@@ -1,13 +1,13 @@
-/*
- * File:  TreeCtrl.cpp
- * Purpose: Tree control
- * Author:  Julian Smart
- * Created: 1997
- * Updated: 
- * Copyright:
- */
-
-/* static const char sccsid[] = "%W% %G%"; */
+/////////////////////////////////////////////////////////////////////////////
+// Name:        treectrl.cpp
+// Purpose:     wxTreeCtrl
+// Author:      Julian Smart
+// Modified by:
+// Created:     1997
+// RCS-ID:      $Id$
+// Copyright:   (c) Julian Smart
+// Licence:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 #pragma implementation "treectrl.h"
@@ -53,6 +53,7 @@ wxTreeCtrl::wxTreeCtrl(void)
 {
   m_imageListNormal = NULL;
   m_imageListState = NULL;
+  m_textCtrl = NULL;
 }
 
 bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
@@ -67,6 +68,7 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, con
 
   m_imageListNormal = NULL;
   m_imageListState = NULL;
+  m_textCtrl = NULL;
 
   int x = pos.x;
   int y = pos.y;
@@ -131,7 +133,12 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, con
 
 wxTreeCtrl::~wxTreeCtrl(void)
 {
-  m_textCtrl.SetHWND((WXHWND) NULL);
+    if (m_textCtrl)
+    {
+        m_textCtrl->UnsubclassWin();
+        m_textCtrl->SetHWND((WXHWND) 0);
+        delete m_textCtrl;
+    }
 }
 
 // Attributes
@@ -260,13 +267,15 @@ long wxTreeCtrl::GetRootItem(void) const
   return (long) ::SendMessage((HWND) GetHWND(), TVM_GETNEXTITEM, TVGN_ROOT, 0);
 }
 
-// TODO: convert mask
 bool wxTreeCtrl::GetItem(wxTreeItem& info) const
 {
   TV_ITEM tvItem;
   tvItem.hItem   = (HTREEITEM)info.m_itemId;
   tvItem.pszText = NULL;
-  tvItem.mask    = 0;
+  tvItem.mask    = 
+  tvItem.stateMask = 0;
+
+  // TODO: convert other bits in the mask
   if ( info.m_mask & wxTREE_MASK_TEXT )
   {
     tvItem.mask |= TVIF_TEXT;
@@ -275,6 +284,10 @@ bool wxTreeCtrl::GetItem(wxTreeItem& info) const
   }
   if ( info.m_mask & wxTREE_MASK_DATA )
     tvItem.mask |= TVIF_PARAM;
+  if ( info.m_stateMask & wxTREE_STATE_EXPANDED ) {
+    tvItem.mask |= TVIF_STATE;
+    tvItem.stateMask |= TVIS_EXPANDED;
+  }
 
   bool success = TreeView_GetItem((HWND)GetHWND(), &tvItem) != 0;
 
@@ -303,7 +316,7 @@ bool wxTreeCtrl::SetItem(wxTreeItem& info)
   return (::SendMessage((HWND) GetHWND(), TVM_SETITEM, 0, (LPARAM)&item) != 0);
 }
 
-int  wxTreeCtrl::GetItemState(long item, long stateMask) const
+int wxTreeCtrl::GetItemState(long item, long stateMask) const
 {
   wxTreeItem info;
 
@@ -406,11 +419,9 @@ bool wxTreeCtrl::GetItemRect(long item, wxRectangle& rect, bool textOnly) const
   return success;
 }
 
-wxTextCtrl& wxTreeCtrl::GetEditControl(void) const
+wxTextCtrl* wxTreeCtrl::GetEditControl(void) const
 {
-  HWND hWnd = (HWND) TreeView_GetEditControl((HWND) GetHWND());
-  ((wxTreeCtrl *)this)->m_textCtrl.SetHWND((WXHWND) hWnd);
-  return (wxTextCtrl&) m_textCtrl;
+    return m_textCtrl;
 }
 
 // Operations
@@ -427,17 +438,53 @@ bool wxTreeCtrl::ExpandItem(long item, int action)
     case wxTREE_EXPAND_EXPAND:
       mswAction = TVE_EXPAND;
       break;
+
     case wxTREE_EXPAND_COLLAPSE:
       mswAction = TVE_COLLAPSE;
+      break;
+
     case wxTREE_EXPAND_COLLAPSE_RESET:
+      // @@@ it should also delete all the items! currently, if you do use this
+      //     code your program will probaly crash. Feel free to remove this if
+      //     it does work
+      wxFAIL_MSG("wxTREE_EXPAND_COLLAPSE_RESET probably doesn't work.");
       mswAction = TVE_COLLAPSERESET;
+      break;
+
     case wxTREE_EXPAND_TOGGLE:
       mswAction = TVE_TOGGLE;
       break;
-    default :
-      break;
+
+    default:
+      wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
   }
-  return (TreeView_Expand((HWND) GetHWND(), (HTREEITEM) item, mswAction) != 0);
+
+  bool bOk = TreeView_Expand((HWND)GetHWND(), (HTREEITEM)item, mswAction) != 0;
+
+  // TreeView_Expand doesn't send TVN_EXPAND(ING) messages, so emulate them
+  if ( bOk ) {
+    wxTreeEvent event(wxEVT_NULL, m_windowId);
+    event.m_item.m_itemId  = item;
+    event.m_item.m_mask      =
+    event.m_item.m_stateMask = 0xffff; // get all
+    GetItem(event.m_item);
+
+    bool bIsExpanded = (event.m_item.m_state & wxTREE_STATE_EXPANDED) != 0;
+
+    event.m_code = action;
+    event.SetEventObject(this);
+
+    // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
+    event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDING
+                                   : wxEVT_COMMAND_TREE_ITEM_COLLAPSING);
+    GetEventHandler()->ProcessEvent(event);
+
+    event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDED
+                                   : wxEVT_COMMAND_TREE_ITEM_COLLAPSED);
+    GetEventHandler()->ProcessEvent(event);
+  }
+
+  return bOk;
 }
 
 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter)
@@ -485,11 +532,40 @@ bool wxTreeCtrl::DeleteAllItems(void)
   return (TreeView_DeleteAllItems((HWND) GetHWND()) != 0);
 }
 
-wxTextCtrl& wxTreeCtrl::Edit(long item)
+wxTextCtrl* wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass)
 {
-  HWND hWnd = (HWND) TreeView_EditLabel((HWND) GetHWND(), item);
-  m_textCtrl.SetHWND((WXHWND) hWnd);
-  return m_textCtrl;
+    wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
+
+    HWND hWnd = (HWND) TreeView_EditLabel((HWND) GetHWND(), item);
+
+    if (m_textCtrl)
+    {
+      m_textCtrl->UnsubclassWin();
+      m_textCtrl->SetHWND(0);
+      delete m_textCtrl;
+      m_textCtrl = NULL;
+    }
+
+    m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
+    m_textCtrl->SetHWND((WXHWND) hWnd);
+    m_textCtrl->SubclassWin((WXHWND) hWnd);
+
+    return m_textCtrl;
+}
+
+// End label editing, optionally cancelling the edit
+bool wxTreeCtrl::EndEditLabel(bool cancel)
+{
+    bool success = (TreeView_EndEditLabelNow((HWND) GetHWND(), cancel) != 0);
+
+    if (m_textCtrl)
+    {
+      m_textCtrl->UnsubclassWin();
+      m_textCtrl->SetHWND(0);
+      delete m_textCtrl;
+      m_textCtrl = NULL;
+    }
+    return success;
 }
 
 long wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
@@ -619,45 +695,44 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
     }
     case TVN_ITEMEXPANDING:
     {
-      eventType = wxEVT_COMMAND_TREE_ITEM_EXPANDING;
       NM_TREEVIEW* hdr = (NM_TREEVIEW*)lParam;
       wxConvertFromMSWTreeItem(event.m_item, hdr->itemNew, (HWND) GetHWND());
 
       switch ( hdr->action )
       {
         case TVE_EXPAND:
-          event.m_code = wxTREE_EXPAND_EXPAND;
+          eventType = wxEVT_COMMAND_TREE_ITEM_EXPANDING;
           break;
+
         case TVE_COLLAPSE:
-          event.m_code = wxTREE_EXPAND_COLLAPSE;
+          eventType = wxEVT_COMMAND_TREE_ITEM_COLLAPSING;
+          break;
+
         case TVE_COLLAPSERESET:
-          event.m_code = wxTREE_EXPAND_COLLAPSE_RESET;
         case TVE_TOGGLE:
-          event.m_code = wxTREE_EXPAND_TOGGLE;
-          break;
-        default :
+          wxLogDebug("unexpected code in TVN_ITEMEXPANDING message");
           break;
       }
       break;
     }
+
     case TVN_ITEMEXPANDED:
     {
-      eventType = wxEVT_COMMAND_TREE_ITEM_EXPANDED;
       NM_TREEVIEW* hdr = (NM_TREEVIEW*)lParam;
       wxConvertFromMSWTreeItem(event.m_item, hdr->itemNew, (HWND) GetHWND());
       switch ( hdr->action )
       {
         case TVE_EXPAND:
-          event.m_code = wxTREE_EXPAND_EXPAND;
+          eventType = wxEVT_COMMAND_TREE_ITEM_EXPANDED;
           break;
+
         case TVE_COLLAPSE:
-          event.m_code = wxTREE_EXPAND_COLLAPSE;
+          eventType = wxEVT_COMMAND_TREE_ITEM_COLLAPSED;
+          break;
+
         case TVE_COLLAPSERESET:
-          event.m_code = wxTREE_EXPAND_COLLAPSE_RESET;
         case TVE_TOGGLE:
-          event.m_code = wxTREE_EXPAND_TOGGLE;
-          break;
-        default :
+          wxLogDebug("unexpected code in TVN_ITEMEXPANDED message");
           break;
       }
       break;
@@ -699,7 +774,7 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
       break;
   }
 
-  event.SetEventObject( this );
+  event.SetEventObject(this);
   event.SetEventType(eventType);
 
   if ( !GetEventHandler()->ProcessEvent(event) )
@@ -711,7 +786,7 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
     wxConvertToMSWTreeItem(event.m_item, info->item);
   }
 
-    return TRUE;
+  return TRUE;
 }
 
 // Tree item structure