Buggy code:
int offset = ( NMHDR . sizeof ) + 4 ; OS . MoveMemory ( tvItem , ( lParam + offset ) , TVITEM . sizeof ) ; tvItem . mask = OS . TVIF_STATE ; tvItem . stateMask = OS . TVIS_SELECTED ; tvItem . state = OS . TVIS_SELECTED ; OS . SendMessage ( handle , TVM_SETITEM , 0 , tvItem ) ; } if ( ( ! ( newSelected ) ) && ( ignoreSelect ) ) { TVITEM tvItem = new TVITEM ( ) ; int offset = ( ( NMHDR . sizeof ) + 4 ) + ( TVITEM . sizeof ) ; OS . MoveMemory ( tvItem , ( lParam + offset ) , TVITEM . sizeof ) ; tvItem . mask = OS . TVIF_STATE ; tvItem . stateMask = OS . TVIS_SELECTED ; tvItem . state = 0 ; OS . SendMessage ( handle , TVM_SETITEM , 0 , tvItem ) ; } } } if ( ! ( ignoreSelect ) ) { TVITEM tvItem = new TVITEM ( ) ; int offset = ( ( NMHDR . sizeof ) + 4 ) + ( TVITEM . sizeof ) ; OS . MoveMemory ( tvItem , ( lParam + offset ) , TVITEM . sizeof ) ; hAnchor = tvItem . hItem ; Event event = new Event ( ) ; event . item = items [ tvItem . lParam ] ; postEvent ( Selection , event ) ; } updateScrollBar ( ) ; break ; } case OS . TVN_SELCHANGINGA : case OS . TVN_SELCHANGINGW : { if ( ( ( style ) & ( SWT . MULTI ) ) != 0 ) { if ( lockSelection ) { TVITEM tvItem = new TVITEM ( ) ; int offset1 = ( NMHDR . sizeof ) + 4 ; OS . MoveMemory ( tvItem , ( lParam + offset1 ) , TVITEM . sizeof ) ; oldSelected = ( ( tvItem . state ) & ( OS . TVIS_SELECTED ) ) != 0 ; int offset2 = ( ( NMHDR . sizeof ) + 4 ) + ( TVITEM . sizeof ) ; OS . MoveMemory ( tvItem , ( lParam + offset2 ) , TVITEM . sizeof ) ; newSelected = ( ( tvItem . state ) & ( OS . TVIS_SELECTED ) ) != 0 ; } } if ( ( ! ( ignoreSelect ) ) && ( ! ( ignoreDeselect ) ) ) { hAnchor = 0 ; if ( ( ( style ) & ( SWT . MULTI ) ) != 0 ) deselectAll ( ) ; } break ; } case OS . TVN_ITEMEXPANDEDA : case OS . TVN_ITEMEXPANDEDW : { updateScrollBar ( ) ; break ; } case OS . TVN_ITEMEXPANDINGA : case OS . TVN_ITEMEXPANDINGW : { if ( ! ( ignoreExpand ) ) { TVITEM tvItem = new TVITEM ( ) ; int offset = ( ( NMHDR . sizeof ) + 4 ) + ( TVITEM . sizeof ) ; OS . MoveMemory ( tvItem , ( lParam + offset ) , TVITEM . sizeof ) ; if ( ( items ) == null ) break ; TreeItem item = items [ tvItem . lParam ] ; if ( item == null ) break ; Event event = new Event ( ) ; event . item = item ; int [ ] action = new int [ 1 ] ; OS . MoveMemory ( action , ( lParam + ( NMHDR . sizeof ) ) , 4 ) ; switch ( action [ 0 ] ) { case OS . TVE_EXPAND : if ( ( ( tvItem . state ) & ( OS . TVIS_EXPANDED ) ) == 0 ) { sendEvent ( Expand , event ) ; if ( isDisposed ( ) ) return LRESULT . ZERO ; } break ; case OS . TVE_COLLAPSE : sendEvent ( Collapse , event ) ; if ( isDisposed ( ) ) return LRESULT . ZERO ; break ; } } break ; } case OS . TVN_BEGINDRAGA : case OS . TVN_BEGINDRAGW : case OS . TVN_BEGINRDRAGA : case OS . TVN_BEGINRDRAGW : { TVITEM tvItem = new TVITEM ( ) ; int offset = ( ( NMHDR . sizeof ) + 4 ) + ( TVITEM . sizeof ) ; OS . MoveMemory ( tvItem , ( lParam + offset ) , TVITEM . sizeof ) ; if ( ( ( tvItem . hItem ) != 0 ) && ( ( ( tvItem . state ) & ( OS . TVIS_SELECTED ) ) == 0 ) ) { ignoreSelect = ignoreDeselect = true ; OS . SendMessage ( handle , TVM_SELECTITEM , TVGN_CARET , tvItem . hItem ) ; ignoreSelect = ignoreDeselect = false ; } dragStarted = true ; break ; } case OS . NM_RECOGNIZEGESTURE : { if ( OS . IsPPC ) { boolean hasMenu = ( ( menu ) != null ) && ( ! ( menu . isDisposed ( ) ) ) ; if ( ( ! hasMenu ) && ( ! ( hooks ( MenuDetect ) ) ) ) return LRESULT . ONE ; } break ; } case OS . GN_CONTEXTMENU : { if ( OS . IsPPC ) { boolean hasMenu = ( ( menu ) != null ) && ( ! ( menu . isDisposed ( ) ) ) ; if ( hasMenu || ( hooks ( MenuDetect ) ) ) { NMRGINFO nmrg = new NMRGINFO ( ) ; OS . MoveMemory ( nmrg , lParam , NMRGINFO . sizeof ) ; <START_BUG> showMenu ( menu , nmrg . x , nmrg . y ) ; <END_BUG> gestureCompleted = true ; return LRESULT . ONE ; } } break ; } } return super . wmNotifyChild ( wParam , lParam ) ; } }

Fix:
showMenu ( nmrg . x , nmrg . y ) ;