-void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image,
- wxTreeItemIcon which)
-{
- if ( IS_VIRTUAL_ROOT(item) )
- {
- // TODO: Maybe a hidden root can still store images?
- return;
- }
-
- int imageNormal, imageSel;
- switch ( which )
- {
- default:
- wxFAIL_MSG( wxT("unknown tree item image type") );
-
- case wxTreeItemIcon_Normal:
- imageNormal = image;
- imageSel = GetItemSelectedImage(item);
- break;
-
- case wxTreeItemIcon_Selected:
- imageNormal = GetItemImage(item);
- imageSel = image;
- break;
-
- case wxTreeItemIcon_Expanded:
- case wxTreeItemIcon_SelectedExpanded:
- if ( !HasIndirectData(item) )
- {
- // we need to get the old images first, because after we create
- // the wxTreeItemIndirectData GetItemXXXImage() will use it to
- // get the images
- imageNormal = GetItemImage(item);
- imageSel = GetItemSelectedImage(item);
-
- // if it doesn't have it yet, add it
- wxTreeItemIndirectData *data = new
- wxTreeItemIndirectData(this, item);
-
- // copy the data to the new location
- data->SetImage(imageNormal, wxTreeItemIcon_Normal);
- data->SetImage(imageSel, wxTreeItemIcon_Selected);
- }
-
- DoSetItemImageFromData(item, image, which);
-
- // reset the normal/selected images because we won't use them any
- // more - now they're stored inside the indirect data
- imageNormal =
- imageSel = I_IMAGECALLBACK;
- break;
- }
-
- // NB: at least in version 5.00.0518.9 of comctl32.dll we need to always
- // change both normal and selected image - otherwise the change simply
- // doesn't take place!
- DoSetItemImages(item, imageNormal, imageSel);
-}
-
-wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const
-{
- wxTreeViewItem tvItem(item, TVIF_PARAM);
-
- // Hidden root may have data.
- if ( IS_VIRTUAL_ROOT(item) )
- {
- return GET_VIRTUAL_ROOT()->GetData();
- }
-
- // Visible node.
- if ( !DoGetItem(&tvItem) )
- {
- return NULL;
- }
-
- wxTreeItemData *data = (wxTreeItemData *)tvItem.lParam;
- if ( IsDataIndirect(data) )
- {
- data = ((wxTreeItemIndirectData *)data)->GetData();
- }
-
- return data;
-}
-
-void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data)
-{
- if ( IS_VIRTUAL_ROOT(item) )
- {
- GET_VIRTUAL_ROOT()->SetData(data);
- }
-
- // first, associate this piece of data with this item
- if ( data )
- {
- data->SetId(item);
- }
-
- wxTreeViewItem tvItem(item, TVIF_PARAM);
-
- if ( HasIndirectData(item) )
- {
- if ( DoGetItem(&tvItem) )
- {
- ((wxTreeItemIndirectData *)tvItem.lParam)->SetData(data);
- }
- else
- {
- wxFAIL_MSG( wxT("failed to change tree items data") );
- }
- }
- else
- {
- tvItem.lParam = (LPARAM)data;
- DoSetItem(&tvItem);
- }
-}
-
-void wxTreeCtrl::SetIndirectItemData(const wxTreeItemId& item,
- wxTreeItemIndirectData *data)
-{
- // this should never happen because it's unnecessary and will probably lead
- // to crash too because the code elsewhere supposes that the pointer the
- // wxTreeItemIndirectData has is a real wxItemData and not
- // wxTreeItemIndirectData as well
- wxASSERT_MSG( !HasIndirectData(item), wxT("setting indirect data twice?") );
-
- SetItemData(item, data);
-}
-
-bool wxTreeCtrl::HasIndirectData(const wxTreeItemId& item) const
-{
- // query the item itself
- wxTreeViewItem tvItem(item, TVIF_PARAM);
- if ( !DoGetItem(&tvItem) )
- {
- return FALSE;
- }
-
- wxTreeItemData *data = (wxTreeItemData *)tvItem.lParam;
-
- return data && IsDataIndirect(data);
-}
-
-void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has)