#include "wx/msw/gnuwin32/extra.h"
#endif
-#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
+#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
#include <commctrl.h>
#endif
{
Init();
+ if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
+ style |= wxBORDER_SUNKEN;
+
if ( !CreateControl(parent, id, pos, size, style, validator, name) )
return false;
- DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
- TVS_SHOWSELALWAYS;
-
- if ( m_windowStyle & wxCLIP_SIBLINGS )
- wstyle |= WS_CLIPSIBLINGS;
+ DWORD exStyle = 0;
+ DWORD wstyle = MSWGetStyle(m_windowStyle, & exStyle);
+ wstyle |= WS_TABSTOP | TVS_SHOWSELALWAYS;
if ((m_windowStyle & wxTR_NO_LINES) == 0)
wstyle |= TVS_HASLINES;
// delete any attributes
if ( m_hasAnyAttr )
{
- for ( wxNode *node = m_attrs.Next(); node; node = m_attrs.Next() )
+ for ( wxHashTable::compatibility_iterator node = m_attrs.Next();
+ node; node = m_attrs.Next() )
{
delete (wxTreeItemAttr *)node->GetData();
}
wxImageList *wxTreeCtrl::GetStateImageList() const
{
- return m_imageListNormal;
+ return m_imageListState;
}
void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
return;
}
- int imageNormal, imageSel;
+ int imageNormal,
+ imageSel;
+
switch ( which )
{
default:
wxFAIL_MSG( wxT("unknown tree item image type") );
+ // fall through
case wxTreeItemIcon_Normal:
- imageNormal = image;
- imageSel = GetItemSelectedImage(item);
+ {
+ const int imageNormalOld = GetItemImage(item);
+ const int imageSelOld = GetItemSelectedImage(item);
+
+ // always set the normal image
+ imageNormal = image;
+
+ // if the selected and normal images were the same, they should
+ // be the same after the update, otherwise leave the selected
+ // image as it was
+ imageSel = imageNormalOld == imageSelOld ? image : imageSelOld;
+ }
break;
case wxTreeItemIcon_Selected:
bool textOnly) const
{
RECT rc;
+
+ // Virtual root items have no bounding rectangle
+ if ( IS_VIRTUAL_ROOT(item) )
+ {
+ return false;
+ }
+
if ( TreeView_GetItemRect(GetHwnd(), HITEM(item),
&rc, textOnly) )
{
{
// 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 )
+ 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);
+ // clear the previously selected items, if the
+ // user clicked outside of the present selection.
+ // otherwise, perform the deselection on mouse-up.
+ // this allows multiple drag and drop to work.
+
+ if (IsItemSelected(GetHwnd(), htItem))
+ {
+ ::SetFocus(GetHwnd(), htItem);
+ }
+ else
+ {
+ 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);
+ ::SelectItem(GetHwnd(), htItem);
+ }
}
// reset on any click without Shift
break;
case WM_LBUTTONUP:
+
+ // facilitates multiple drag-and-drop
+ if (htItem && isMultiple)
+ {
+ wxArrayTreeItemIds selections;
+ size_t count = GetSelections(selections);
+
+ if (count > 1 &&
+ !(wParam & MK_CONTROL) &&
+ !(wParam & MK_SHIFT))
+ {
+ UnselectAll();
+ TreeView_SelectItem(GetHwnd(), htItem);
+ }
+ }
+
+ // fall through
+
case WM_RBUTTONUP:
if ( m_dragImage )
{
// similar to the ones from a "real" WM_KEYDOWN so that
// CreateKeyEvent() works correctly
WXLPARAM lParam =
- (::GetKeyState(VK_MENU) & 0x100 ? KF_ALTDOWN : 0) << 16;
+// (::GetKeyState(VK_MENU) & 0x100 ? KF_ALTDOWN : 0) << 16;
+ // Returns different negative values on WinME and WinNT,
+ // so simply test for negative value.
+ (::GetKeyState(VK_MENU) < 0 ? KF_ALTDOWN : 0) << 16;
WXWPARAM wParam = info->wVKey;
return true;
#endif // _WIN32_IE >= 0x300
+ case NM_CLICK:
+ {
+ DWORD pos = GetMessagePos();
+ POINT point;
+ point.x = LOWORD(pos);
+ point.y = HIWORD(pos);
+ ::MapWindowPoints(HWND_DESKTOP, GetHwnd(), &point, 1);
+ int flags = 0;
+ wxTreeItemId item = HitTest(wxPoint(point.x, point.y), flags);
+ if (flags & wxTREE_HITTEST_ONITEMSTATEICON)
+ {
+ event.m_item = item;
+ eventType = wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK;
+ }
+ break;
+ }
+
case NM_DBLCLK:
case NM_RCLICK:
{
return processed;
}
+// ----------------------------------------------------------------------------
+// State control.
+// ----------------------------------------------------------------------------
+
+// why do they define INDEXTOSTATEIMAGEMASK but not the inverse?
+#define STATEIMAGEMASKTOINDEX(state) (((state) & TVIS_STATEIMAGEMASK) >> 12)
+
+void wxTreeCtrl::SetState(const wxTreeItemId& node, int state)
+{
+ TV_ITEM tvi;
+ tvi.hItem = (HTREEITEM)node.m_pItem;
+ tvi.mask = TVIF_STATE;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+
+ // Select the specified state, or -1 == cycle to the next one.
+ if ( state == -1 )
+ {
+ TreeView_GetItem(GetHwnd(), &tvi);
+
+ state = STATEIMAGEMASKTOINDEX(tvi.state) + 1;
+ if ( state == m_imageListState->GetImageCount() )
+ state = 1;
+ }
+
+ wxCHECK_RET( state < m_imageListState->GetImageCount(),
+ _T("wxTreeCtrl::SetState(): item index out of bounds") );
+
+ tvi.state = INDEXTOSTATEIMAGEMASK(state);
+
+ TreeView_SetItem(GetHwnd(), &tvi);
+}
+
+int wxTreeCtrl::GetState(const wxTreeItemId& node)
+{
+ TV_ITEM tvi;
+ tvi.hItem = (HTREEITEM)node.m_pItem;
+ tvi.mask = TVIF_STATE;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+ TreeView_GetItem(GetHwnd(), &tvi);
+
+ return STATEIMAGEMASKTOINDEX(tvi.state);
+}
+
#endif // __WIN95__
#endif // wxUSE_TREECTRL
+