private:
wxTreeItemData *m_data;
+
+ DECLARE_NO_COPY_CLASS(wxVirtualNode)
};
#ifdef __VISUALC__
bool Traverse(const wxTreeItemId& root, bool recursively);
const wxTreeCtrl *m_tree;
+
+ DECLARE_NO_COPY_CLASS(wxTreeTraversal)
};
// internal class for getting the selected items
// the real client data
wxTreeItemData *m_data;
+
+ DECLARE_NO_COPY_CLASS(wxTreeItemIndirectData)
};
// ----------------------------------------------------------------------------
}
}
+wxColour wxTreeCtrl::GetItemTextColour(const wxTreeItemId& item) const
+{
+ long id = (long)(WXHTREEITEM)item;
+ wxTreeItemAttr *attr = (wxTreeItemAttr *)m_attrs.Get(id);
+ if ( !attr )
+ {
+ return wxNullColour;
+ }
+
+ return attr->GetTextColour();
+}
+
+wxColour wxTreeCtrl::GetItemBackgroundColour(const wxTreeItemId& item) const
+{
+ long id = (long)(WXHTREEITEM)item;
+ wxTreeItemAttr *attr = (wxTreeItemAttr *)m_attrs.Get(id);
+ if ( !attr )
+ {
+ return wxNullColour;
+ }
+
+ return attr->GetBackgroundColour();
+}
+
+wxFont wxTreeCtrl::GetItemFont(const wxTreeItemId& item) const
+{
+ long id = (long)(WXHTREEITEM)item;
+ wxTreeItemAttr *attr = (wxTreeItemAttr *)m_attrs.Get(id);
+ if ( !attr )
+ {
+ return wxNullFont;
+ }
+
+ return attr->GetFont();
+}
+
void wxTreeCtrl::SetItemTextColour(const wxTreeItemId& item,
const wxColour& col)
{
bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const
{
+ if ( item == wxTreeItemId(TVI_ROOT) )
+ {
+ // virtual (hidden) root is never visible
+ return FALSE;
+ }
+
// Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
RECT rect;
return wxTreeItemId((WXHTREEITEM) TreeView_GetSelection(GetHwnd()));
}
-wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const
+wxTreeItemId wxTreeCtrl::GetItemParent(const wxTreeItemId& item) const
{
HTREEITEM hItem;
void wxTreeCtrl::DeleteAllItems()
{
- // delete stored root item.
- delete GET_VIRTUAL_ROOT();
+ // delete the "virtual" root item.
+ if ( GET_VIRTUAL_ROOT() )
+ {
+ delete GET_VIRTUAL_ROOT();
+ m_pVirtualRoot = NULL;
+ }
+
+ // and all the real items
if ( !TreeView_DeleteAllItems(GetHwnd()) )
{
if ( (nMsg >= WM_MOUSEFIRST) && (nMsg <= WM_MOUSELAST) )
{
- // we only process mouse messages here and these parameters have the same
- // meaning for all of them
+ // we only process mouse messages here and these parameters have the
+ // same meaning for all of them
int x = GET_X_LPARAM(lParam),
y = GET_Y_LPARAM(lParam);
HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y);
switch ( nMsg )
{
+ case WM_RBUTTONDOWN:
+ // if the item we are about to right click on
+ // is not already select, remove the entire
+ // previous selection
+ if (!::IsItemSelected(GetHwnd(), htItem))
+ {
+ UnselectAll();
+ }
+
+ // select item and set the focus to the
+ // newly selected item
+ ::SelectItem(GetHwnd(), htItem);
+ ::SetFocus(GetHwnd(), htItem);
+ break;
+
#if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
case WM_LBUTTONDOWN:
if ( htItem && isMultiple )
}
else // normal click
{
- // clear the selection and then let the default handler
- // do the job
- UnselectAll();
-
- // prevent the click from starting in-place editing
- // when there was no selection in the control
- TreeView_SelectItem(GetHwnd(), 0);
+ // avoid doing anything if we click on the only
+ // currently selected item
+ wxArrayTreeItemIds selections;
+ size_t count = GetSelections(selections);
+ if ( count == 0 ||
+ count > 1 ||
+ HITEM(selections[0]) != htItem )
+ {
+ // clear the previously selected items
+ UnselectAll();
+
+ // prevent the click from starting in-place editing
+ // which should only happen if we click on the
+ // already selected item (and nothing else is
+ // selected)
+ TreeView_SelectItem(GetHwnd(), 0);
+ }
// reset on any click without Shift
m_htSelStart = 0;
}
}
#endif // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
+ else if ( nMsg == WM_CHAR )
+ {
+ // don't let the control process Space and Return keys because it
+ // doesn't do anything useful with them anyhow but always beeps
+ // annoyingly when it receives them and there is no way to turn it off
+ // simply if you just process TREEITEM_ACTIVATED event to which Space
+ // and Enter presses are mapped in your code
+ if ( wParam == VK_SPACE || wParam == VK_RETURN )
+ {
+ processed = true;
+ }
+ }
+
if ( !processed )
rc = wxControl::MSWWindowProc(nMsg, wParam, lParam);
event.m_item = (WXHTREEITEM) info->item.hItem;
event.m_label = info->item.pszText;
+ event.m_editCancelled = FALSE;
}
break;
event.m_item = (WXHTREEITEM)info->item.hItem;
event.m_label = info->item.pszText;
if (info->item.pszText == NULL)
- return FALSE;
+ {
+ event.m_editCancelled = TRUE;
+ }
+ else
+ {
+ event.m_editCancelled = FALSE;
+ }
break;
}
break;
}
- int how = (int)hdr->code == TVN_ITEMEXPANDING ? IDX_DOING
- : IDX_DONE;
+ int how = hdr->code == TVN_ITEMEXPANDING ? IDX_DOING
+ : IDX_DONE;
eventType = gs_expandEvents[what][how];
}
break;
- case TVN_SELCHANGED:
+ // NB: MSLU is broken and sends TVN_SELCHANGEDA instead of
+ // TVN_SELCHANGEDW in Unicode mode under Win98. Therefore
+ // we have to handle both messages:
+ case TVN_SELCHANGEDA:
+ case TVN_SELCHANGEDW:
eventType = wxEVT_COMMAND_TREE_SEL_CHANGED;
// fall through
- case TVN_SELCHANGING:
+ case TVN_SELCHANGINGA:
+ case TVN_SELCHANGINGW:
{
if ( eventType == wxEVT_NULL )
eventType = wxEVT_COMMAND_TREE_SEL_CHANGING;
//else: already set above
- NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam;
-
- event.m_item = (WXHTREEITEM) tv->itemNew.hItem;
- event.m_itemOld = (WXHTREEITEM) tv->itemOld.hItem;
+ if (hdr->code == TVN_SELCHANGINGW ||
+ hdr->code == TVN_SELCHANGEDW)
+ {
+ NM_TREEVIEWW* tv = (NM_TREEVIEWW *)lParam;
+ event.m_item = (WXHTREEITEM) tv->itemNew.hItem;
+ event.m_itemOld = (WXHTREEITEM) tv->itemOld.hItem;
+ }
+ else
+ {
+ NM_TREEVIEWA* tv = (NM_TREEVIEWA *)lParam;
+ event.m_item = (WXHTREEITEM) tv->itemNew.hItem;
+ event.m_itemOld = (WXHTREEITEM) tv->itemOld.hItem;
+ }
}
break;
}
HFONT hFont;
- wxColour colText, colBack;
if ( attr->HasFont() )
{
- wxFont font = attr->GetFont();
- hFont = (HFONT)font.GetResourceHandle();
+ hFont = GetHfontOf(attr->GetFont());
}
else
{
hFont = 0;
}
+ wxColour colText;
if ( attr->HasTextColour() )
{
colText = attr->GetTextColour();
// selection colours should override ours
if ( nmcd.uItemState & CDIS_SELECTED )
{
- DWORD clrBk = ::GetSysColor(COLOR_HIGHLIGHT);
- lptvcd->clrTextBk = clrBk;
-
- // try to make the text visible
- lptvcd->clrText = wxColourToRGB(colText);
- lptvcd->clrText |= ~clrBk;
- lptvcd->clrText &= 0x00ffffff;
+ lptvcd->clrTextBk =
+ ::GetSysColor(COLOR_HIGHLIGHT);
+ lptvcd->clrText =
+ ::GetSysColor(COLOR_HIGHLIGHTTEXT);
}
- else
+ else // !selected
{
+ wxColour colBack;
if ( attr->HasBackgroundColour() )
{
colBack = attr->GetBackgroundColour();