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
This commit is contained in:
Vadim Zeitlin
2007-09-20 22:58:55 +00:00
parent 5bd01f2048
commit 0edeeb6d96
11 changed files with 38 additions and 22 deletions

View File

@@ -77,7 +77,7 @@ public:
m_tbar = tbar; m_tbar = tbar;
m_id = toolid; m_id = toolid;
if (m_id == wxID_ANY) if (m_id == wxID_ANY)
m_id = wxNewId(); m_id = wxWindow::NewControlId();
m_clientData = clientData; m_clientData = clientData;
m_bmpNormal = bmpNormal; m_bmpNormal = bmpNormal;

View File

@@ -67,7 +67,7 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
m_id = id; m_id = id;
m_kind = kind; m_kind = kind;
if (m_id == wxID_ANY) if (m_id == wxID_ANY)
m_id = wxNewId(); m_id = wxWindow::NewControlId();
if (m_id == wxID_SEPARATOR) if (m_id == wxID_SEPARATOR)
m_kind = wxITEM_SEPARATOR; m_kind = wxITEM_SEPARATOR;

View File

@@ -197,12 +197,12 @@ IMPLEMENT_CLASS(wxEditableListBox, wxPanel)
// NB: generate the IDs at runtime to avoid conflict with XRCID values, // NB: generate the IDs at runtime to avoid conflict with XRCID values,
// they could cause XRCCTRL() failures in XRC-based dialogs // they could cause XRCCTRL() failures in XRC-based dialogs
const int wxID_ELB_DELETE = wxNewId(); const int wxID_ELB_DELETE = wxWindow::NewControlId();
const int wxID_ELB_EDIT = wxNewId(); const int wxID_ELB_EDIT = wxWindow::NewControlId();
const int wxID_ELB_NEW = wxNewId(); const int wxID_ELB_NEW = wxWindow::NewControlId();
const int wxID_ELB_UP = wxNewId(); const int wxID_ELB_UP = wxWindow::NewControlId();
const int wxID_ELB_DOWN = wxNewId(); const int wxID_ELB_DOWN = wxWindow::NewControlId();
const int wxID_ELB_LISTCTRL = wxNewId(); const int wxID_ELB_LISTCTRL = wxWindow::NewControlId();
BEGIN_EVENT_TABLE(wxEditableListBox, wxPanel) BEGIN_EVENT_TABLE(wxEditableListBox, wxPanel)
EVT_LIST_ITEM_SELECTED(wxID_ELB_LISTCTRL, wxEditableListBox::OnItemSelected) EVT_LIST_ITEM_SELECTED(wxID_ELB_LISTCTRL, wxEditableListBox::OnItemSelected)

View File

@@ -1749,8 +1749,9 @@ bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
return wxControl::MSWShouldPreProcessMessage(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) if (cmd == EN_UPDATE)
{ {
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);

View File

@@ -788,10 +788,12 @@ void wxMenu::SetTitle(const wxString& label)
// event processing // 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 // ignore commands from the menu title
if ( id != (WXWORD)idMenuTitle ) if ( id != idMenuTitle )
{ {
// update the check item when it's clicked // update the check item when it's clicked
wxMenuItem * const item = FindItem(id); wxMenuItem * const item = FindItem(id);

View File

@@ -258,8 +258,10 @@ void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
// events generation // 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 ( cmd == BN_CLICKED )
{ {
if (id == GetId()) if (id == GetId())

View File

@@ -1185,9 +1185,14 @@ bool wxToolBar::Realize()
// message handlers // 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 ) if ( !tool )
return false; return false;
@@ -1209,7 +1214,7 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id)
// OnLeftClick() can veto the button state change - for buttons which // OnLeftClick() can veto the button state change - for buttons which
// may be toggled only, of couse // may be toggled only, of couse
if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) if ( !OnLeftClick(id, toggled) && tool->CanBeToggled() )
{ {
// revert back // revert back
tool->Toggle(!toggled); tool->Toggle(!toggled);

View File

@@ -1902,8 +1902,10 @@ bool wxTreeCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
return wxTreeCtrlBase::MSWShouldPreProcessMessage(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 ) if ( cmd == EN_UPDATE )
{ {
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id); wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, id);

View File

@@ -482,9 +482,11 @@ bool wxToolMenuBar::Realize()
return true; 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 ) if ( !tool )
{ {
bool checked = false; bool checked = false;

View File

@@ -4871,8 +4871,11 @@ bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo))
// command messages // 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 wxUSE_MENUS_NATIVE
if ( !cmd && wxCurrentPopupMenu ) if ( !cmd && wxCurrentPopupMenu )
{ {
@@ -4895,8 +4898,7 @@ bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
// try the id // try the id
if ( !win ) if ( !win )
{ {
// must cast to a signed type before comparing with other ids! win = FindItem(id);
win = FindItem((signed short)id);
} }
if ( win ) if ( win )

View File

@@ -1610,7 +1610,7 @@ static int XRCID_Lookup(const char *str_id, int value_if_not_found = wxID_NONE)
} }
else else
{ {
(*rec_var)->id = wxNewId(); (*rec_var)->id = wxWindow::NewControlId();
} }
} }