From: Stefan Csomor Date: Sat, 10 Jan 2009 14:43:22 +0000 (+0000) Subject: supporting PopUp on osx cocoa as well, see #10361 X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2cb5d2d2b70566c40be5578fe3db29cb3c3a34ad?ds=inline supporting PopUp on osx cocoa as well, see #10361 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57970 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index dec77345e5..d16cbfa3fc 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -152,6 +152,8 @@ public : wxMenu* GetWXPeer() { return m_peer ; } + virtual void PopUp( wxWindow *win, int x, int y ) = 0; + static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); static wxMenuImpl* CreateRootMenu( wxMenu* peer ); protected : diff --git a/src/osx/carbon/menu.cpp b/src/osx/carbon/menu.cpp index bb6b08ea2e..5db7b7bc50 100644 --- a/src/osx/carbon/menu.cpp +++ b/src/osx/carbon/menu.cpp @@ -189,7 +189,6 @@ public : virtual ~wxMenuCarbonImpl(); - virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) { // MacOS counts menu items from 1 and inserts after, therefore having the @@ -259,6 +258,24 @@ public : WXHMENU GetHMenu() { return m_osxMenu; } + virtual void PopUp( wxWindow *WXUNUSED(win), int x, int y ) + { + long menuResult = ::PopUpMenuSelect(m_osxMenu, y, x, 0) ; + if ( HiWord(menuResult) != 0 ) + { + MenuCommand macid; + GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); + int id = wxMacCommandToId( macid ); + wxMenuItem* item = NULL ; + wxMenu* realmenu ; + item = m_peer->FindItem( id, &realmenu ) ; + if ( item ) + { + m_peer->HandleCommandProcess(item, NULL ); + } + } + } + static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); static wxMenuImpl* CreateRootMenu( wxMenu* peer ); protected : diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 3bac02bfad..2222793676 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -164,6 +164,24 @@ public : [m_osxMenu setTitle:cfText.AsNSString()]; } + virtual void PopUp( wxWindow *win, int x, int y ) + { + win->ScreenToClient( &x , &y ) ; + NSView *view = win->GetPeer()->GetWXWidget(); + NSRect frame = [view frame]; + frame.origin.x = x; + frame.origin.y = y; + frame.size.width = 1; + frame.size.height = 1; + NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]; + [popUpButtonCell setAutoenablesItems:NO]; + [popUpButtonCell setAltersStateOfSelectedItem:NO]; + [popUpButtonCell setMenu:m_osxMenu]; + [popUpButtonCell selectItem:nil]; + [popUpButtonCell performClickWithFrame:frame inView:view]; + [popUpButtonCell release]; + } + WXHMENU GetHMenu() { return m_osxMenu; } static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index ebec85144e..e482f1d0a0 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -748,30 +748,8 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) { ClientToScreen( &x , &y ) ; } -#ifdef __WXOSX_CARBON__ - long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ; - if ( HiWord(menuResult) != 0 ) - { - MenuCommand macid; - GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); - int id = wxMacCommandToId( macid ); - wxMenuItem* item = NULL ; - wxMenu* realmenu ; - item = menu->FindItem( id, &realmenu ) ; - if ( item ) - { - if (item->IsCheckable()) - item->Check( !item->IsChecked() ) ; - - menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; - } - } - -#else + menu->GetPeer()->PopUp(this, x, y); menu->SetInvokingWindow( NULL ); - return false; -#endif - return true; #else // actually this shouldn't be called, because universal is having its own implementation