// under carbon there's no such thing as a MenuItemRef, everything is done
// on the 'parent' menu via index APIs (first line having index 1 !)
-// so to make things still work, we store the wxMenuItemImpl instance as a
+// so to make things still work, we store the wxMenuItemImpl instance as a
// RefCon at the respective menu line
-class wxMenuItemCarbonImpl : public wxMenuItemImpl
+class wxMenuItemCarbonImpl : public wxMenuItemImpl
{
public :
wxMenuItemCarbonImpl( wxMenuItem* peer ) : wxMenuItemImpl(peer)
// the parent menu ref is only set, once the item has been attached
m_parentMenuRef = NULL;
}
-
+
~wxMenuItemCarbonImpl();
-
+
void SetBitmap( const wxBitmap& bitmap )
{
MenuItemIndex i = FindMenuItemIndex() ;
#endif
}
}
- }
-
- void Enable( bool enable )
+ }
+
+ void Enable( bool enable )
{
MenuItemIndex i = FindMenuItemIndex() ;
if ( i > 0 )
{
-
+
if ( GetWXPeer()->GetId() == wxApp::s_macPreferencesMenuItemId)
{
if ( enable )
EnableMenuCommand( NULL , kHICommandPreferences ) ;
else
DisableMenuCommand( NULL , kHICommandPreferences ) ;
- }
+ }
else if ( GetWXPeer()->GetId() == wxApp::s_macExitMenuItemId)
{
if ( enable )
else
DisableMenuCommand( NULL , kHICommandQuit ) ;
}
-
+
if ( enable )
EnableMenuItem(m_parentMenuRef , i);
else
DisableMenuItem(m_parentMenuRef , i);
-
+
if ( GetWXPeer()->IsSubMenu() )
{
UMAEnableMenuItem( GetWXPeer()->GetSubMenu()->GetHMenu() , 0 , enable ) ;
}
}
- }
-
- void Check( bool check )
+ }
+
+ void Check( bool check )
{
MenuItemIndex i = FindMenuItemIndex() ;
if ( i > 0 )
else
::SetItemMark( m_parentMenuRef, i, 0 ) ; // no mark
}
- }
+ }
- void Hide( bool hide )
+ void Hide( bool hide )
{
MenuItemIndex i = FindMenuItemIndex() ;
if ( i > 0 )
else
ChangeMenuItemAttributes( m_parentMenuRef, i, 0 , kMenuItemAttrHidden );
}
- }
-
- void SetLabel( const wxString& text, wxAcceleratorEntry *entry )
+ }
+
+ void SetLabel( const wxString& text, wxAcceleratorEntry *entry )
{
MenuItemIndex i = FindMenuItemIndex() ;
if ( i > 0 )
UMASetMenuItemShortcut( m_parentMenuRef, i , entry ) ;
}
}
-
+
void * GetHMenuItem() { return NULL; }
-
+
// Carbon Only
-
- void AttachToParent( MenuRef parentMenuRef, MenuItemIndex index )
+
+ void AttachToParent( MenuRef parentMenuRef, MenuItemIndex index )
{
m_parentMenuRef = parentMenuRef;
if ( m_parentMenuRef && index > 0 )
- SetMenuItemRefCon( m_parentMenuRef, index, (URefCon) this );
+ SetMenuItemRefCon( m_parentMenuRef, index, (URefCon) m_peer );
}
MenuItemIndex FindMenuItemIndex()
{
URefCon storedRef = 0;
GetMenuItemRefCon(m_parentMenuRef, i, &storedRef );
- if ( storedRef == (URefCon) this )
+ if ( storedRef == (URefCon) m_peer )
{
hit = i;
break;
// wxMenuImpl
//
-class wxMenuCarbonImpl : public wxMenuImpl
+class wxMenuCarbonImpl : public wxMenuImpl
{
public :
wxMenuCarbonImpl( wxMenu* peer , MenuRef menu) : wxMenuImpl(peer), m_osxMenu(menu)
}
virtual ~wxMenuCarbonImpl();
-
- virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos)
+ virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos)
{
// MacOS counts menu items from 1 and inserts after, therefore having the
// same effect as wx 0 based and inserting before, we must correct pos
MenuItemIndex index = pos;
if ( pos == (size_t) -1 )
index = CountMenuItems(m_osxMenu);
-
+
if ( pItem->IsSeparator() )
{
InsertMenuItemTextWithCFString( m_osxMenu, CFSTR(""), index, kMenuItemAttrSeparator, 0);
// now switch to the Carbon 1 based counting
index += 1 ;
}
- else
+ else
{
InsertMenuItemTextWithCFString( m_osxMenu, CFSTR("placeholder"), index, 0, 0 );
SetMenuItemCommandID( m_osxMenu, index , wxIdToMacCommand(pItem->GetId()) ) ;
}
}
-
+
wxMenuItemCarbonImpl* impl = (wxMenuItemCarbonImpl*) pItem->GetPeer();
impl->AttachToParent( m_osxMenu, index );
// only now can all settings be updated correctly
pItem->UpdateItemStatus();
pItem->UpdateItemBitmap();
}
-
- virtual void Remove( wxMenuItem *pItem )
+
+ virtual void Remove( wxMenuItem *pItem )
{
wxMenuItemCarbonImpl* impl = (wxMenuItemCarbonImpl*) pItem->GetPeer();
if ( impl )
}
}
}
-
+
virtual void MakeRoot()
{
SetRootMenu( m_osxMenu );
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 :
}
-wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer,
+wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer,
wxMenu * WXUNUSED(pParentMenu),
int WXUNUSED(id),
const wxString& WXUNUSED(text),