#include "wx/msw/private.h"
+// include <commctrl.h> "properly"
+#include "wx/msw/wrapcctl.h"
+
+#include "wx/msw/missing.h"
+
// Set this to 1 to be _absolutely_ sure that repainting will work for all
// comctl32.dll versions
#define wxUSE_COMCTL32_SAFELY 0
#include "wx/msw/treectrl.h"
#include "wx/msw/dragimag.h"
-// include <commctrl.h> "properly"
-#include "wx/msw/wrapcctl.h"
-
// macros to hide the cast ugliness
// --------------------------------
wstyle |= TVS_CHECKBOXES;
#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
-#ifndef __WXWINCE__
+#if !defined(__WXWINCE__) && defined(TVS_INFOTIP)
// Need so that TVN_GETINFOTIP messages will be sent
wstyle |= TVS_INFOTIP;
#endif
::UnselectItem(GetHwnd(), HITEM_PTR(selections[n]));
#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
}
+
+ m_htSelStart.Unset();
}
else
{
WXLRESULT rc = 0;
bool isMultiple = HasFlag(wxTR_MULTIPLE);
-#ifdef WM_CONTEXTMENU
if ( nMsg == WM_CONTEXTMENU )
{
wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_MENU, GetId() );
- event.m_item = GetSelection();
+
+ // can't use GetSelection() here as it would assert in multiselect mode
+ event.m_item = wxTreeItemId(TreeView_GetSelection(GetHwnd()));
event.SetEventObject( this );
+
if ( GetEventHandler()->ProcessEvent(event) )
processed = true;
//else: continue with generating wxEVT_CONTEXT_MENU in base class code
}
-#endif // WM_CONTEXTMENU
else if ( (nMsg >= WM_MOUSEFIRST) && (nMsg <= WM_MOUSELAST) )
{
// we only process mouse messages here and these parameters have the
bool bCtrl = wxIsCtrlDown(),
bShift = wxIsShiftDown();
- // we handle.arrows and space, but not page up/down and home/end: the
- // latter should be easy, but not the former
-
HTREEITEM htSel = (HTREEITEM)TreeView_GetSelection(GetHwnd());
- if ( !m_htSelStart )
+ switch ( wParam )
{
- m_htSelStart = htSel;
- }
-
- if ( wParam == VK_SPACE )
- {
- if ( bCtrl )
- {
- ::ToggleItemSelection(GetHwnd(), htSel);
- }
- else
- {
- UnselectAll();
-
- ::SelectItem(GetHwnd(), htSel);
- }
+ case VK_SPACE:
+ if ( bCtrl )
+ {
+ ::ToggleItemSelection(GetHwnd(), htSel);
+ }
+ else
+ {
+ UnselectAll();
- processed = true;
- }
- else if ( wParam == VK_UP || wParam == VK_DOWN )
- {
- if ( !bCtrl && !bShift )
- {
- // no modifiers, just clear selection and then let the default
- // processing to take place
- UnselectAll();
- }
- else if ( htSel )
- {
- (void)wxControl::MSWWindowProc(nMsg, wParam, lParam);
+ ::SelectItem(GetHwnd(), htSel);
+ }
- HTREEITEM htNext = (HTREEITEM)(wParam == VK_UP
- ? TreeView_GetPrevVisible(GetHwnd(), htSel)
- : TreeView_GetNextVisible(GetHwnd(), htSel));
+ processed = true;
+ break;
- if ( !htNext )
+ case VK_UP:
+ case VK_DOWN:
+ if ( !bCtrl && !bShift )
{
- // at the top/bottom
- htNext = htSel;
+ // no modifiers, just clear selection and then let the default
+ // processing to take place
+ UnselectAll();
}
-
- if ( bShift )
+ else if ( htSel )
{
- SelectRange(GetHwnd(), HITEM(m_htSelStart), htNext);
+ (void)wxControl::MSWWindowProc(nMsg, wParam, lParam);
+
+ HTREEITEM htNext = (HTREEITEM)
+ TreeView_GetNextItem
+ (
+ GetHwnd(),
+ htSel,
+ wParam == VK_UP ? TVGN_PREVIOUSVISIBLE
+ : TVGN_NEXTVISIBLE
+ );
+
+ if ( !htNext )
+ {
+ // at the top/bottom
+ htNext = htSel;
+ }
+
+ if ( bShift )
+ {
+ if ( !m_htSelStart )
+ m_htSelStart = htSel;
+
+ SelectRange(GetHwnd(), HITEM(m_htSelStart), htNext);
+ }
+ else // bCtrl
+ {
+ // without changing selection
+ ::SetFocus(GetHwnd(), htNext);
+ }
+
+ processed = true;
}
- else // bCtrl
+ break;
+
+ case VK_HOME:
+ case VK_END:
+ case VK_PRIOR:
+ case VK_NEXT:
+ // TODO: handle Shift/Ctrl with these keys
+ if ( !bCtrl && !bShift )
{
- // without changing selection
- ::SetFocus(GetHwnd(), htNext);
- }
+ UnselectAll();
- processed = true;
- }
+ m_htSelStart.Unset();
+ }
}
}
#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;
- }
- }
else if ( nMsg == WM_COMMAND )
{
// if we receive a EN_KILLFOCUS command from the in-place edit control
if ( nMsg == WM_RBUTTONDOWN )
return 0;
+ // but because of the above we don't get NM_RCLICK which is normally
+ // generated by tree window proc when the modal loop mentioned above ends
+ // because the mouse is released -- synthesize it ourselves instead
+ if ( nMsg == WM_RBUTTONUP )
+ {
+ NMHDR hdr;
+ hdr.hwndFrom = GetHwnd();
+ hdr.idFrom = GetId();
+ hdr.code = NM_RCLICK;
+
+ WXLPARAM rc;
+ MSWOnNotify(GetId(), (LPARAM)&hdr, &rc);
+
+ // continue as usual
+ }
+
+ if ( nMsg == WM_CHAR )
+ {
+ // also 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 )
+ return 0;
+ }
+
return wxControl::MSWDefWindowProc(nMsg, wParam, lParam);
}
break;
}
+#ifdef TVN_GETINFOTIP
case TVN_GETINFOTIP:
{
eventType = wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP;
break;
}
+#endif
#endif
case TVN_GETDISPINFO:
break;
#ifndef __WXWINCE__
+#ifdef TVN_GETINFOTIP
case TVN_GETINFOTIP:
{
// If the user permitted a tooltip change, change it
}
}
break;
+#endif
#endif
case TVN_SELCHANGING: