Handle checkable items the right way in all cases
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19977 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -701,25 +701,6 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
if (!menu->IsEnabled(id))
|
if (!menu->IsEnabled(id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Is this menu on a menubar? (possibly nested)
|
|
||||||
wxFrame* frame = NULL;
|
|
||||||
wxMenu* pm = menu;
|
|
||||||
while ( pm && !frame )
|
|
||||||
{
|
|
||||||
if ( pm->IsAttached() )
|
|
||||||
frame = pm->GetMenuBar()->GetFrame();
|
|
||||||
else
|
|
||||||
pm = pm->GetParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it is then let the frame send the event
|
|
||||||
if (frame)
|
|
||||||
{
|
|
||||||
frame->ProcessCommand(id);
|
|
||||||
}
|
|
||||||
// otherwise let the menu have it
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxMenuItem* item = menu->FindChildItem( id );
|
wxMenuItem* item = menu->FindChildItem( id );
|
||||||
wxCHECK_RET( item, wxT("error in menu item callback") );
|
wxCHECK_RET( item, wxT("error in menu item callback") );
|
||||||
|
|
||||||
@@ -739,10 +720,34 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the user pressed on the menu item: report the event below
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Is this menu on a menubar? (possibly nested)
|
||||||
|
wxFrame* frame = NULL;
|
||||||
|
wxMenu* pm = menu;
|
||||||
|
while ( pm && !frame )
|
||||||
|
{
|
||||||
|
if ( pm->IsAttached() )
|
||||||
|
frame = pm->GetMenuBar()->GetFrame();
|
||||||
|
pm = pm->GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame)
|
||||||
|
{
|
||||||
|
// If it is attached then let the frame send the event.
|
||||||
|
// Don't call frame->ProcessCommand(id) because it toggles
|
||||||
|
// checkable items and we've already done that above.
|
||||||
|
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
|
||||||
|
commandEvent.SetEventObject(frame);
|
||||||
|
if (item->IsCheckable())
|
||||||
|
commandEvent.SetInt(item->IsChecked());
|
||||||
|
|
||||||
|
frame->GetEventHandler()->ProcessEvent(commandEvent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// otherwise let the menu have it
|
||||||
menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
|
menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -701,25 +701,6 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
if (!menu->IsEnabled(id))
|
if (!menu->IsEnabled(id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Is this menu on a menubar? (possibly nested)
|
|
||||||
wxFrame* frame = NULL;
|
|
||||||
wxMenu* pm = menu;
|
|
||||||
while ( pm && !frame )
|
|
||||||
{
|
|
||||||
if ( pm->IsAttached() )
|
|
||||||
frame = pm->GetMenuBar()->GetFrame();
|
|
||||||
else
|
|
||||||
pm = pm->GetParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it is then let the frame send the event
|
|
||||||
if (frame)
|
|
||||||
{
|
|
||||||
frame->ProcessCommand(id);
|
|
||||||
}
|
|
||||||
// otherwise let the menu have it
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxMenuItem* item = menu->FindChildItem( id );
|
wxMenuItem* item = menu->FindChildItem( id );
|
||||||
wxCHECK_RET( item, wxT("error in menu item callback") );
|
wxCHECK_RET( item, wxT("error in menu item callback") );
|
||||||
|
|
||||||
@@ -739,10 +720,34 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the user pressed on the menu item: report the event below
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Is this menu on a menubar? (possibly nested)
|
||||||
|
wxFrame* frame = NULL;
|
||||||
|
wxMenu* pm = menu;
|
||||||
|
while ( pm && !frame )
|
||||||
|
{
|
||||||
|
if ( pm->IsAttached() )
|
||||||
|
frame = pm->GetMenuBar()->GetFrame();
|
||||||
|
pm = pm->GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame)
|
||||||
|
{
|
||||||
|
// If it is attached then let the frame send the event.
|
||||||
|
// Don't call frame->ProcessCommand(id) because it toggles
|
||||||
|
// checkable items and we've already done that above.
|
||||||
|
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
|
||||||
|
commandEvent.SetEventObject(frame);
|
||||||
|
if (item->IsCheckable())
|
||||||
|
commandEvent.SetInt(item->IsChecked());
|
||||||
|
|
||||||
|
frame->GetEventHandler()->ProcessEvent(commandEvent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// otherwise let the menu have it
|
||||||
menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
|
menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user