+ if (! pTB->GetCurrentMenu() )
+ {
+ return eventNotHandledErr;
+ }
+
+ MenuRef hMenu = MAC_WXHMENU(pTB->GetCurrentMenu()->GetHMenu());
+ OSStatus result = eventNotHandledErr ;
+
+ HICommand command ;
+ OSErr err;
+
+ err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand,
+ NULL, sizeof(HICommand), NULL, &command);
+ wxASSERT(err == noErr);
+
+ MenuItemIndex menuItemIndex;
+ err = GetIndMenuItemWithCommandID(hMenu, command.commandID, 1, NULL, &menuItemIndex);
+ wxASSERT(err == noErr);
+
+
+ MenuCommand id = command.commandID ;
+ wxMenuItem* item = NULL;
+
+ // for items we don't really control
+ if ( id == kHICommandPreferences )
+ {
+ id = wxApp::s_macPreferencesMenuItemId ;
+
+ wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
+
+ if ( mbar )
+ {
+ wxMenu* menu = NULL ;
+ item = mbar->FindItem( id , &menu ) ;
+ }
+ }
+ else if (id != 0)
+ GetMenuItemRefCon( hMenu , menuItemIndex , (UInt32*) &item ) ;
+
+ if ( item )
+ {
+ if (item->IsCheckable())
+ {
+ item->Check( !item->IsChecked() ) ;
+ }
+
+ item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
+ result = noErr ;
+ }
+
+ return result ;
+ }
+
+ wxASSERT(eventClass == kEventClassApplication && eventKind == kEventAppGetDockTileMenu);
+
+ //process the right click events
+ wxTaskBarIconEvent downevt(wxEVT_TASKBAR_RIGHT_DOWN,NULL);
+ pTB->ProcessEvent(downevt);
+
+ wxTaskBarIconEvent upevt(wxEVT_TASKBAR_RIGHT_UP,NULL);
+ pTB->ProcessEvent(upevt);
+
+ //create popup menu
+ wxMenu* menu = pTB->DoCreatePopupMenu();
+
+ OSStatus err = noErr;
+
+ if(menu)
+ {
+ //note to self - a MenuRef IS A MenuHandle
+ MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu());
+
+ //When we call SetEventParameter it will decrement
+ //the reference count of the menu - we need to make
+ //sure it stays around in the wxMenu class here
+ RetainMenu(hMenu);
+
+ //set the actual dock menu
+ err = SetEventParameter((EventRef) inEvent, kEventParamMenuRef,
+ typeMenuRef, sizeof(MenuRef),
+ &hMenu);
+ wxASSERT(err == 0);
+
+ return err;
+ }
+ else
+ return eventNotHandledErr;