Opened 7 years ago

Closed 4 years ago

#13634 closed defect (fixed)

Side effects in wxPG if fixed IDs of wxPG subcontrols clash with menu item IDs

Reported by: frm Owned by: AW
Priority: normal Milestone:
Component: wxPropertyGrid Version: dev-latest
Keywords: id fixed Cc:
Blocked By: Blocking:
Patch: yes


wxPropertyGrid subcontrols use some "magic" ID values (1, 2, etc) as defined in propgrid.h and in other functions (e.g. wxLongStringProperty::DisplayEditorDialog).

These fixed IDs may clash with user-defined IDs leading to strange bugs/behaviours. This is undocumented and in general, is not a good practice, so wxID_ANY or wxNewId() should be used instead.

See also:!topic/wx-dev/Kg2Aw9eATLg

Attachments (1)

fixed-control-ids-replaced-with-automatic-values.patch download (7.7 KB) - added by awi 4 years ago.
Patch replacing fixed IDs of wxPG controls with automatic values.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 4 years ago by awi

  • Keywords fixed added
  • Patch set
  • Summary changed from dynamically-generated IDs in PropertyGrid subcontrols to Side effects in wxPG if fixed IDs of wxPG subcontrols clash with menu item IDs
  • Version set to dev-latest

I can confirm that when menu item ID clashes with fixed 'magic' ID (like 2, 3, 4, 11) used internally by wxPG for some controls it could lead to the unexpected results, like e.g. disabling wxPG control if menu item with the same ID is disabled in updateUI event.

Patch to propgrid sample reproducing the issue:

  • samples/propgrid/propgrid.cpp

    a b protected: 
    378     PGID = 1,
     378    PGID = 99,// = 1,
    379379    TCID,
    380     ID_ABOUT,
     380    ID_ABOUT = 2,
    381381    ID_QUIT,
    382382    ID_APPENDPROP,
    383383    ID_APPENDCAT,
    wxBEGIN_EVENT_TABLE(FormMain, wxFrame) 
    494494    EVT_MENU( ID_ENABLE, FormMain::OnEnableDisable )
    495495    EVT_MENU( ID_SETREADONLY, FormMain::OnSetReadOnly )
    496496    EVT_MENU( ID_HIDE, FormMain::OnHide )
     497    EVT_UPDATE_UI( ID_ABOUT, FormMain::OnEventUI ) /* 2 */
     498    EVT_UPDATE_UI( ID_QUIT, FormMain::OnEventUI ) /* 3 */
     499    EVT_UPDATE_UI( ID_DELETE, FormMain::OnEventUI ) /* 11 */
    498501    EVT_MENU( ID_ITERATE1, FormMain::OnIterate1Click )
    499502    EVT_MENU( ID_ITERATE2, FormMain::OnIterate2Click )
    void FormMain::OnHide( wxCommandEvent& WXUNUSED(event) ) 
    25342537    m_pPropGridManager->HideProperty( id, true );
     2540void FormMain::OnEventUI(wxUpdateUIEvent& event)
     2542    event.Enable( false );
    25372545// -----------------------------------------------------------------------
    25392547#include "wx/colordlg.h"
  • samples/propgrid/propgrid.h

    a b public: 
    186186    void OnEnableDisable( wxCommandEvent& event );
    187187    void OnSetReadOnly( wxCommandEvent& event );
    188188    void OnHide( wxCommandEvent& event );
     189    void OnEventUI(wxUpdateUIEvent& event);
    189190    void OnSetBackgroundColour( wxCommandEvent& event );
    190191    void OnClearModifyStatusClick( wxCommandEvent& event );
    191192    void OnFreezeClick( wxCommandEvent& event );

In this sample "About", "Exit", "Delete selected" menu items have the same IDs as wxPG controls and therefore properties (on the Examples page) like e.g. DateProperty, CustomColourProperty, LongStringProperty, BoolProperty with Checkbox are disabled because menu items were disabled in updateUI event handler.

Replacing fixed IDs in wxPG with automatic ones (wxID_ANY) solves the problem.
Patch fixing this issue is attached (attachment:fixed-control-ids-replaced-with-automatic-values.patch).

Changed 4 years ago by awi

Patch replacing fixed IDs of wxPG controls with automatic values.

comment:2 Changed 4 years ago by AW

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

In 76882:

Use automatically generated ID values for wxPG sub-controls.

Currently in wxPG there are used fixed "magic" ID values to identify sub-controls and this can lead to side effects if these values overlap with ID values assigned to another controls in the application (like e.g. menu items).

Closes #13634.

Note: See TracTickets for help on using tickets.