Esempio n. 1
0
// ----------------------------------------------------------------------------
// adding/deleting items to/from the list
// ----------------------------------------------------------------------------
int wxChoice::DoAppend(const wxString& item)
{
#if wxUSE_STL
    wxArrayString::iterator insertPoint;
    size_t index;
    
    if (GetWindowStyle() & wxCB_SORT)
    {
        insertPoint = std::lower_bound( m_strings.begin(), m_strings.end(), item );
        index = insertPoint - m_strings.begin();
    }
    else
    {
        insertPoint = m_strings.end();
        index = m_strings.size();
    }

    m_strings.insert( insertPoint, item );
#else
    size_t index = m_strings.Add( item ) ;
#endif
    m_datas.Insert( NULL , index ) ;
    UMAInsertMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item, m_font.GetEncoding() , index );
    DoSetItemClientData( index , NULL ) ;
    m_peer->SetMaximum( GetCount() ) ;
    return index ;
}
Esempio n. 2
0
int wxChoice::DoInsert(const wxString& item, int pos)
{
    wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
    wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));

    if (pos == GetCount())
        return DoAppend(item);

    UMAInsertMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item, m_font.GetEncoding() , pos );
    m_strings.Insert( item, pos ) ;
    m_datas.Insert( NULL, pos ) ;
    DoSetItemClientData( pos , NULL ) ;
    m_peer->SetMaximum( GetCount() ) ;
    return pos ;
}
Esempio n. 3
0
void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter)
{
    wxMenuItemList::compatibility_iterator node;
    wxMenuItem *item;
    wxMenu *subMenu = NULL ;
    bool newItems = false;

    for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext())
    {
        item = (wxMenuItem *)node->GetData();
        subMenu = item->GetSubMenu() ;
        if (subMenu)
        {
            wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0);
        }
        if ( item->IsSeparator() )
        {
            if ( wm && newItems)
                InsertMenuItemTextWithCFString( wm,
                    CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0);

            newItems = false;
        }
        else
        {
            wxAcceleratorEntry*
                entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ;

            MenuItemIndex winListPos = (MenuItemIndex)-1;
            OSStatus err = GetIndMenuItemWithCommandID(wm,
                        wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos);

            if ( wm && err == menuItemNotFoundErr )
            {
                // NB: the only way to determine whether or not we should add
                // a separator is to know if we've added menu items to the menu
                // before the separator.
                newItems = true;
                UMAInsertMenuItem(wm, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), insertAfter, entry);
                SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ;
                SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ;
            }

            delete entry ;
        }
    }
}
Esempio n. 4
0
// function appends a new item or submenu to the menu
// append a new item or submenu to the menu
bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
{
    wxASSERT_MSG( pItem != NULL, wxT("can't append NULL item to the menu") );

    if ( pItem->IsSeparator() )
    {
        if ( pos == (size_t)-1 )
            AppendMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu),
                CFSTR(""), kMenuItemAttrSeparator, 0,NULL); 
        else
            InsertMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu),
                CFSTR(""), pos, kMenuItemAttrSeparator, 0); 
    }
    else
    {
        wxMenu *pSubMenu = pItem->GetSubMenu() ;
        if ( pSubMenu != NULL )
        {
            wxASSERT_MSG( pSubMenu->m_hMenu != NULL , wxT("invalid submenu added"));
            pSubMenu->m_menuParent = this ;

            if (wxMenuBar::MacGetInstalledMenuBar() == GetMenuBar())
                pSubMenu->MacBeforeDisplay( true ) ;

            if ( pos == (size_t)-1 )
                UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetText()), wxFont::GetDefaultEncoding(), pSubMenu->m_macMenuId);
            else
                UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetText()), wxFont::GetDefaultEncoding(), pos, pSubMenu->m_macMenuId);

            pItem->UpdateItemBitmap() ;
            pItem->UpdateItemStatus() ;
        }
        else
        {
            if ( pos == (size_t)-1 )
            {
                UMAAppendMenuItem(MAC_WXHMENU(m_hMenu), wxT("a") , wxFont::GetDefaultEncoding() );
                pos = CountMenuItems(MAC_WXHMENU(m_hMenu)) ;
            }
            else
            {
                // 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
                // after however for updates to be correct
                UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), wxT("a"), wxFont::GetDefaultEncoding(), pos);
                pos += 1 ;
            }

            SetMenuItemCommandID( MAC_WXHMENU(m_hMenu) , pos , wxIdToMacCommand ( pItem->GetId() ) ) ;
            SetMenuItemRefCon( MAC_WXHMENU(m_hMenu) , pos , (URefCon) pItem ) ;
            pItem->UpdateItemText() ;
            pItem->UpdateItemBitmap() ;
            pItem->UpdateItemStatus() ;

            if ( pItem->GetId() == idMenuTitle )
                UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , pos , false ) ;
        }
    }

    // if we're already attached to the menubar, we must update it
    if ( IsAttached() && GetMenuBar()->IsAttached() )
        GetMenuBar()->Refresh();

    return true ;
}