Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#11621 closed defect (fixed)

Problem with handling wxEVT_KEY_DOWN for navigation keys in wxTreeCtrl

Reported by: TNikolay Owned by:
Priority: normal Milestone:
Component: wxMSW Version: stable-latest
Keywords: wxTreeCtrl selection Cc:
Blocked By: Blocking:
Patch: no

Description

I use wxEVT_KEY_DOWN handler for wxTreeCtrl in order to realize add keyboard shortcuts for additional functional at my tree control. Problem is application don't receive wxEVT_KEY_DOWN event for some keys (used for navigation). I am sure that the problem is in the following code:

wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
 
    ....

        // normally we want to generate wxEVT_KEY_DOWN events from TVN_KEYDOWN
        // notification but for the keys which can be used to change selection
        // we need to do it from here so as to not apply the default behaviour
        // if the events are handled by the user code
        switch ( wParam )
        {
            case VK_RETURN:
            case VK_SPACE:
            case VK_UP:
            case VK_DOWN:
            case VK_LEFT:
            case VK_RIGHT:
            case VK_HOME:
            case VK_END:
            case VK_PRIOR:
            case VK_NEXT:
                if ( !MSWHandleTreeKeyDownEvent(wParam, lParam) )
                {
                    // use the key to update the selection if it was left
                    // unprocessed
                    MSWHandleSelectionKey(wParam);
                }

                // pretend that we did process it in any case as we already
                // generated an event for it
                processed = true;

            //default: for all the other keys leave processed as false so that
            //         the tree control generates a TVN_KEYDOWN for us
        }

It breaks compability with 2.8 branch and doesn't leave us a chance to realize own reaction at this keys.is this a bug?

Attachments (1)

tree-add-events.patch download (554 bytes) - added by TNikolay 4 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 4 years ago by TNikolay

I have fixed this problem for myself, it woks and I don't see any side affects. But I am not sure that I good understand message processing in wxWidhets, and this solution is right.

Changed 4 years ago by TNikolay

comment:2 Changed 4 years ago by vadz

  • Status changed from new to confirmed

I think a more correct patch would be to call HandleKeyDown() before MSWHandleTreeKeyDownEvent() as it should be more consistent with the events order for the other keys. Please let me know if this doesn't work for you.

And thanks for reporting this!

comment:3 Changed 4 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [63169]) Generate wxEVT_KEY_DOWN events for navigation keys in wxMSW wxTreeCtrl.

We only generated wxEVT_COMMAND_TREE_KEY_DOWN events for the keys which can be
used for tree control navigation and which are handled specially in the code
but not the wxEVT_KEY_DOWN ones. This was inconsistent with the other keys and
incompatible with wx 2.8 and other ports, so generate both events unless the
wxEVT_KEY_DOWN one was handled by the user code.

Closes #11621.

comment:4 Changed 4 years ago by TNikolay

Please let me know if this doesn't work for you.

Please forgive the delay in getting back to you. I have tested this changes and it works fine.

Note: See TracTickets for help on using tickets.