Opened 8 months ago

Closed 6 months ago

#15748 closed defect (fixed)

Initial "checked" state not set when adding a wxMenuItem to a menu

Reported by: benke_g Owned by:
Priority: normal Milestone: 3.0.1
Component: wxMSW Version: 3.0.0
Keywords: wxMenu wxMenuItem Cc:
Blocked By: Blocking:
Patch: no

Description

If you create a wxMenuItem with wxITEM_CHECK kind and make it checked by calling its Check() method before inserting it into a wxMenu the checked state is not transfered to Windows.

I patched msw/menu.cpp to make this work, but I don't think this patch is good enough to cover all the cases, the #ifdef userdraw stuff makes it really hard to read the code...

After the wxITEM_RADIO handling I added (after line 528 in the 3.0.0 codebase):

	if ( pItem->GetKind() == wxITEM_CHECK && pItem->wxMenuItemBase::IsChecked() )
	{
		//checkInitially = true;
		flags |= MF_CHECKED;
	}

The setting of checkInitially was my first try. This causes a call to Check() at the end of the same method, but as the menuitem is already checked the code to affect Windows inside wxMenuItem::Check() is short-circuited. Anyway using the flags is of course faster than doing the checking afterwards. However, as stated above, I saw that 'flags' is not used in all routes through the if and ifdefs further down in the method. Someone with more insight in this code should review the solution.

Note also that I had to call wxMenuItemBase::IsChecked() as the subclass method calls Windows to get the checked state, where the item is of course not set (it doesn't even exist in Windows yet!).

Also there may be more properties of the wxMenuItem which are not properly transferred to Windows if set initially.

Change History (4)

comment:1 Changed 7 months ago by VZ

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

(In [75448]) Fix handling of menu items checked before being attached in wxMSW.

Calling wxMenuItem::Check() before appending the item to a menu didn't have
any effect, fix this by checking the item state when actually attaching it.

Closes #15748.

comment:2 Changed 7 months ago by vadz

  • Resolution changed from fixed to port to stable
  • Status changed from closed to portneeded

This could be backported to 3.0.x if no problems are found.

comment:3 Changed 7 months ago by vadz

I managed to omit the important part of the patch (wxMenuItemBase:: one), even though it was explicitly mentioned, so a problem was indeed found and if this is backported both r75448 and r75570 should be backported.

comment:4 Changed 6 months ago by VZ

  • Resolution changed from port to stable to fixed
  • Status changed from portneeded to closed

(In [75767]) Fix handling of menu items checked before being attached in wxMSW.

Calling wxMenuItem::Check() before appending the item to a menu didn't have
any effect, fix this by checking the item state when actually attaching it.

Closes #15748.

Note: See TracTickets for help on using tickets.