From 0edeeb6d96d31d342a6a283d2a9b625a1d0a7b96 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Sep 2007 22:58:55 +0000 Subject: [PATCH] use wxWindow::NewControlId() instead of wxNewId() to avoid clashes with user-defined ids; bug fixes in wxMSW for negative menu and toolbar items ids git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48840 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/tbarbase.h | 2 +- src/common/menucmn.cpp | 2 +- src/generic/editlbox.cpp | 12 ++++++------ src/msw/listctrl.cpp | 3 ++- src/msw/menu.cpp | 6 ++++-- src/msw/radiobox.cpp | 4 +++- src/msw/tbar95.cpp | 11 ++++++++--- src/msw/treectrl.cpp | 4 +++- src/msw/wince/tbarwce.cpp | 6 ++++-- src/msw/window.cpp | 8 +++++--- src/xrc/xmlres.cpp | 2 +- 11 files changed, 38 insertions(+), 22 deletions(-) diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index 8c4b93543b..47ccd84a01 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -77,7 +77,7 @@ public: m_tbar = tbar; m_id = toolid; if (m_id == wxID_ANY) - m_id = wxNewId(); + m_id = wxWindow::NewControlId(); m_clientData = clientData; m_bmpNormal = bmpNormal; diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index edceb72cc5..884fa75167 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -67,7 +67,7 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, m_id = id; m_kind = kind; if (m_id == wxID_ANY) - m_id = wxNewId(); + m_id = wxWindow::NewControlId(); if (m_id == wxID_SEPARATOR) m_kind = wxITEM_SEPARATOR; diff --git a/src/generic/editlbox.cpp b/src/generic/editlbox.cpp index 6e0dea8563..6cc9d187c2 100644 --- a/src/generic/editlbox.cpp +++ b/src/generic/editlbox.cpp @@ -197,12 +197,12 @@ IMPLEMENT_CLASS(wxEditableListBox, wxPanel) // NB: generate the IDs at runtime to avoid conflict with XRCID values, // they could cause XRCCTRL() failures in XRC-based dialogs -const int wxID_ELB_DELETE = wxNewId(); -const int wxID_ELB_EDIT = wxNewId(); -const int wxID_ELB_NEW = wxNewId(); -const int wxID_ELB_UP = wxNewId(); -const int wxID_ELB_DOWN = wxNewId(); -const int wxID_ELB_LISTCTRL = wxNewId(); +const int wxID_ELB_DELETE = wxWindow::NewControlId(); +const int wxID_ELB_EDIT = wxWindow::NewControlId(); +const int wxID_ELB_NEW = wxWindow::NewControlId(); +const int wxID_ELB_UP = wxWindow::NewControlId(); +const int wxID_ELB_DOWN = wxWindow::NewControlId(); +const int wxID_ELB_LISTCTRL = wxWindow::NewControlId(); BEGIN_EVENT_TABLE(wxEditableListBox, wxPanel) EVT_LIST_ITEM_SELECTED(wxID_ELB_LISTCTRL, wxEditableListBox::OnItemSelected) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 221b90cd3b..b248381832 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1749,8 +1749,9 @@ bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg) return wxControl::MSWShouldPreProcessMessage(msg); } -bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) +bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id_) { + const int id = (signed short)id_; if (cmd == EN_UPDATE) { wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 915992cf08..a6956295e2 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -788,10 +788,12 @@ void wxMenu::SetTitle(const wxString& label) // event processing // --------------------------------------------------------------------------- -bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id) +bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id_) { + const int id = (signed short)id_; + // ignore commands from the menu title - if ( id != (WXWORD)idMenuTitle ) + if ( id != idMenuTitle ) { // update the check item when it's clicked wxMenuItem * const item = FindItem(id); diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index f73e2ba3c2..b29e5eb3e2 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -258,8 +258,10 @@ void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) // events generation // ---------------------------------------------------------------------------- -bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id) +bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id_) { + const int id = (signed short)id_; + if ( cmd == BN_CLICKED ) { if (id == GetId()) diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index b653a821d8..f04e66f35c 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -1185,9 +1185,14 @@ bool wxToolBar::Realize() // message handlers // ---------------------------------------------------------------------------- -bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) +bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_) { - wxToolBarToolBase *tool = FindById((int)id); + // cast to signed is important as we compare this id with (signed) ints in + // FindById() and without the cast we'd get a positive int from a + // "negative" (i.e. > 32767) WORD + const int id = (signed short)id_; + + wxToolBarToolBase *tool = FindById(id); if ( !tool ) return false; @@ -1209,7 +1214,7 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) // OnLeftClick() can veto the button state change - for buttons which // may be toggled only, of couse - if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) + if ( !OnLeftClick(id, toggled) && tool->CanBeToggled() ) { // revert back tool->Toggle(!toggled); diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index fac8ddbaee..96bf25a0b5 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -1902,8 +1902,10 @@ bool wxTreeCtrl::MSWShouldPreProcessMessage(WXMSG* msg) return wxTreeCtrlBase::MSWShouldPreProcessMessage(msg); } -bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id) +bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id_) { + const int id = (signed short)id_; + if ( cmd == EN_UPDATE ) { wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); diff --git a/src/msw/wince/tbarwce.cpp b/src/msw/wince/tbarwce.cpp index 04a1efc20f..15e6d13c34 100644 --- a/src/msw/wince/tbarwce.cpp +++ b/src/msw/wince/tbarwce.cpp @@ -482,9 +482,11 @@ bool wxToolMenuBar::Realize() return true; } -bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) +bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_) { - wxToolBarToolBase *tool = FindById((int)id); + const int id = (signed short)id_; + + wxToolBarToolBase *tool = FindById(id); if ( !tool ) { bool checked = false; diff --git a/src/msw/window.cpp b/src/msw/window.cpp index cc05d86fca..c41f9b1e61 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4871,8 +4871,11 @@ bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo)) // command messages // --------------------------------------------------------------------------- -bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) +bool wxWindowMSW::HandleCommand(WXWORD id_, WXWORD cmd, WXHWND control) { + // sign extend to int from short before comparing with the other int ids + int id = (signed short)id_; + #if wxUSE_MENUS_NATIVE if ( !cmd && wxCurrentPopupMenu ) { @@ -4895,8 +4898,7 @@ bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) // try the id if ( !win ) { - // must cast to a signed type before comparing with other ids! - win = FindItem((signed short)id); + win = FindItem(id); } if ( win ) diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 0d26338fc0..ccacf01905 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1610,7 +1610,7 @@ static int XRCID_Lookup(const char *str_id, int value_if_not_found = wxID_NONE) } else { - (*rec_var)->id = wxNewId(); + (*rec_var)->id = wxWindow::NewControlId(); } } -- 2.47.2