- if ( tvItem.mask & TVIF_HANDLE )
- {
- info.m_mask |= wxTREE_MASK_HANDLE;
- info.m_itemId = (long) tvItem.hItem;
- }
- if ( tvItem.mask & TVIF_STATE )
- {
- info.m_mask |= wxTREE_MASK_STATE;
- if ( tvItem.stateMask & TVIS_BOLD)
- {
- info.m_stateMask |= wxTREE_STATE_BOLD ;
- if ( tvItem.state & TVIS_BOLD )
- info.m_state |= wxTREE_STATE_BOLD ;
- }
-
- if ( tvItem.stateMask & TVIS_CUT)
- {
- info.m_stateMask |= wxTREE_STATE_CUT ;
- if ( tvItem.state & TVIS_CUT )
- info.m_state |= wxTREE_STATE_CUT ;
- }
-
- if ( tvItem.stateMask & TVIS_DROPHILITED)
- {
- info.m_stateMask |= wxTREE_STATE_DROPHILITED ;
- if ( tvItem.state & TVIS_DROPHILITED )
- info.m_state |= wxTREE_STATE_DROPHILITED ;
- }
- if ( tvItem.stateMask & TVIS_EXPANDED)
- {
- info.m_stateMask |= wxTREE_STATE_EXPANDED ;
- if ( tvItem.state & TVIS_EXPANDED )
- info.m_state |= wxTREE_STATE_EXPANDED ;
- }
- if ( tvItem.stateMask & TVIS_EXPANDEDONCE)
- {
- info.m_stateMask |= wxTREE_STATE_EXPANDEDONCE ;
- if ( tvItem.state & TVIS_EXPANDEDONCE )
- info.m_state |= wxTREE_STATE_EXPANDEDONCE ;
- }
- if ( tvItem.stateMask & TVIS_FOCUSED)
- {
- info.m_stateMask |= wxTREE_STATE_FOCUSED ;
- if ( tvItem.state & TVIS_FOCUSED )
- info.m_state |= wxTREE_STATE_FOCUSED ;
- }
- if ( tvItem.stateMask & TVIS_SELECTED)
- {
- info.m_stateMask |= wxTREE_STATE_SELECTED ;
- if ( tvItem.state & TVIS_SELECTED )
- info.m_state |= wxTREE_STATE_SELECTED ;
- }
- }
-
- if ( tvItem.mask & TVIF_TEXT )
- {
- info.m_mask |= wxTREE_MASK_TEXT;
- info.m_text = tvItem.pszText;
- }
- if ( tvItem.mask & TVIF_IMAGE )
- {
- info.m_mask |= wxTREE_MASK_IMAGE;
- info.m_image = tvItem.iImage;
- }
- if ( tvItem.mask & TVIF_SELECTEDIMAGE )
- {
- info.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
- info.m_selectedImage = tvItem.iSelectedImage;
- }
- if ( tvItem.mask & TVIF_CHILDREN )
- {
- info.m_mask |= wxTREE_MASK_CHILDREN;
- info.m_children = tvItem.cChildren;
- }
- if ( tvItem.mask & TVIF_PARAM )
- info.m_mask |= wxTREE_MASK_DATA;
-
- if (needText)
- {
- if (tvItem.pszText)
- delete[] tvItem.pszText;
- }
- tvItem.mask = oldMask ;
-}
-
-static void wxConvertToMSWTreeItem(wxTreeItem& info, TV_ITEM& tvItem)
-{
- tvItem.hItem = (HTREEITEM) info.m_itemId ;
-
- tvItem.iImage = info.m_image ;
- tvItem.iSelectedImage = info.m_selectedImage;
- tvItem.cChildren = info.m_children;
- tvItem.lParam = info.m_data;
- tvItem.mask = 0;
- tvItem.stateMask = 0;
- tvItem.state = 0;
-
- if (info.m_mask & wxTREE_MASK_HANDLE)
- tvItem.mask |= TVIF_HANDLE ;
- if (info.m_mask & wxTREE_MASK_STATE)
- tvItem.mask |= TVIF_STATE ;
- if (info.m_mask & wxTREE_MASK_TEXT)
- {
- tvItem.mask |= TVIF_TEXT ;
- tvItem.pszText = (char *) (const char *)info.m_text ;
- if ( tvItem.pszText )
- tvItem.cchTextMax = info.m_text.Length();
- else
- tvItem.cchTextMax = 0;
- }
- if (info.m_mask & wxTREE_MASK_IMAGE)
- tvItem.mask |= TVIF_IMAGE ;
- if (info.m_mask & wxTREE_MASK_SELECTED_IMAGE)
- tvItem.mask |= TVIF_SELECTEDIMAGE ;
- if (info.m_mask & wxTREE_MASK_CHILDREN)
- tvItem.mask |= TVIF_CHILDREN ;
- if (info.m_mask & wxTREE_MASK_DATA)
- tvItem.mask |= TVIF_PARAM ;
-
- if (info.m_stateMask & wxTREE_STATE_BOLD)
- {
- tvItem.stateMask |= TVIS_BOLD ;
- tvItem.state |= TVIS_BOLD;
- }
- if (info.m_stateMask & wxTREE_STATE_CUT)
- {
- tvItem.stateMask |= TVIS_CUT ;
- if ( info.m_state & wxTREE_STATE_CUT )
- tvItem.state |= TVIS_CUT;
- }
- if (info.m_stateMask & wxTREE_STATE_DROPHILITED)
- {
- tvItem.stateMask |= TVIS_DROPHILITED;
- if ( info.m_state & wxTREE_STATE_DROPHILITED )
- tvItem.state |= TVIS_DROPHILITED;
- }
- if (info.m_stateMask & wxTREE_STATE_EXPANDED)
- {
- tvItem.stateMask |= TVIS_EXPANDED;
- if ( info.m_state & wxTREE_STATE_EXPANDED )
- tvItem.state |= TVIS_EXPANDED;
- }
- if (info.m_stateMask & wxTREE_STATE_EXPANDEDONCE)
- {
- tvItem.stateMask |= TVIS_EXPANDEDONCE;
- if ( info.m_state & wxTREE_STATE_EXPANDEDONCE )
- tvItem.state |= TVIS_EXPANDEDONCE;
- }
- if (info.m_stateMask & wxTREE_STATE_FOCUSED)
- {
- tvItem.stateMask |= TVIS_FOCUSED;
- if ( info.m_state & wxTREE_STATE_FOCUSED )
- tvItem.state |= TVIS_FOCUSED;
- }
- if (info.m_stateMask & wxTREE_STATE_SELECTED)
- {
- tvItem.stateMask |= TVIS_SELECTED;
- if ( info.m_state & wxTREE_STATE_SELECTED )
- tvItem.state |= TVIS_SELECTED;
- }
+ event.SetEventObject(this);
+ event.SetEventType(eventType);
+
+ bool processed = GetEventHandler()->ProcessEvent(event);
+
+ // post processing
+ switch ( hdr->code )
+ {
+ case TVN_DELETEITEM:
+ {
+ // NB: we might process this message using wxWindows event
+ // tables, but due to overhead of wxWin event system we
+ // prefer to do it here ourself (otherwise deleting a tree
+ // with many items is just too slow)
+ NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam;
+
+ wxTreeItemId item = event.m_item;
+ if ( HasIndirectData(item) )
+ {
+ wxTreeItemIndirectData *data = (wxTreeItemIndirectData *)
+ tv->itemOld.lParam;
+ delete data; // can't be NULL here
+
+ m_itemsWithIndirectData.Remove(item);
+ }
+ else
+ {
+ wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam;
+ delete data; // may be NULL, ok
+ }
+
+ processed = TRUE; // Make sure we don't get called twice
+ }
+ break;
+
+ case TVN_BEGINLABELEDIT:
+ // return TRUE to cancel label editing
+ *result = !event.IsAllowed();
+ break;
+
+ case TVN_ENDLABELEDIT:
+ // return TRUE to set the label to the new string
+ *result = event.IsAllowed();
+
+ // ensure that we don't have the text ctrl which is going to be
+ // deleted any more
+ DeleteTextCtrl();
+ break;
+
+ case TVN_SELCHANGING:
+ case TVN_ITEMEXPANDING:
+ // return TRUE to prevent the action from happening
+ *result = !event.IsAllowed();
+ break;
+
+ case TVN_GETDISPINFO:
+ // NB: so far the user can't set the image himself anyhow, so do it
+ // anyway - but this may change later
+ if ( /* !processed && */ 1 )
+ {
+ wxTreeItemId item = event.m_item;
+ TV_DISPINFO *info = (TV_DISPINFO *)lParam;
+ if ( info->item.mask & TVIF_IMAGE )
+ {
+ info->item.iImage =
+ DoGetItemImageFromData
+ (
+ item,
+ IsExpanded(item) ? wxTreeItemIcon_Expanded
+ : wxTreeItemIcon_Normal
+ );
+ }
+ if ( info->item.mask & TVIF_SELECTEDIMAGE )
+ {
+ info->item.iSelectedImage =
+ DoGetItemImageFromData
+ (
+ item,
+ IsExpanded(item) ? wxTreeItemIcon_SelectedExpanded
+ : wxTreeItemIcon_Selected
+ );
+ }
+ }
+ break;
+
+ //default:
+ // for the other messages the return value is ignored and there is
+ // nothing special to do
+ }
+
+ return processed;