Show
Ignore:
Timestamp:
08/13/07 10:07:01 (16 months ago)
Author:
JS
Message:

Binary compatible API fixes for menu label retrieval with and without
mnemonics/accelerators.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • wxWidgets/branches/WX_2_8_BRANCH/src/gtk/menu.cpp

    r46167 r48053  
    9292} 
    9393 
     94static wxString wxConvertFromGTKToWXLabel(const wxString& gtkLabel) 
     95{ 
     96    wxString label; 
     97    for ( const wxChar *pc = gtkLabel.c_str(); *pc; pc++ ) 
     98    { 
     99        // '_' is the escape character for GTK+. 
     100 
     101        if ( *pc == wxT('_') && *(pc+1) == wxT('_')) 
     102        { 
     103            // An underscore was escaped. 
     104            label += wxT('_'); 
     105            pc++; 
     106        } 
     107        else if ( *pc == wxT('_') ) 
     108        { 
     109            // Convert GTK+ hotkey symbol to wxWidgets/Windows standard 
     110            label += wxT('&'); 
     111        } 
     112        else if ( *pc == wxT('&') ) 
     113        { 
     114            // Double the ampersand to escape it as far as wxWidgets is concerned 
     115            label += wxT("&&"); 
     116        } 
     117        else 
     118        { 
     119            // don't remove ampersands '&' since if we have them in the menu title 
     120            // it means that they were doubled to indicate "&" instead of accelerator 
     121            label += *pc; 
     122        } 
     123    } 
     124 
     125    return label; 
     126} 
     127 
    94128//----------------------------------------------------------------------------- 
    95129// activate message from GTK 
     
    426460static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) 
    427461{ 
    428     if (wxMenuItem::GetLabelFromText(menu->GetTitle()) == wxMenuItem::GetLabelFromText(menuString)) 
     462    if (wxMenuItem::GetLabelFromText(wxConvertFromGTKToWXLabel(menu->GetTitle())) == wxMenuItem::GetLabelFromText(menuString)) 
    429463    { 
    430464        int res = menu->FindItem( itemString ); 
     
    519553    wxMenu* menu = node->GetData(); 
    520554 
    521     wxString label; 
    522     wxString text( menu->GetTitle() ); 
    523     for ( const wxChar *pc = text.c_str(); *pc; pc++ ) 
    524     { 
    525         if ( *pc == wxT('_') ) 
    526         { 
    527             // '_' is the escape character for GTK+ 
    528             continue; 
    529         } 
    530  
    531         // don't remove ampersands '&' since if we have them in the menu title 
    532         // it means that they were doubled to indicate "&" instead of accelerator 
    533  
    534         label += *pc; 
    535     } 
    536  
    537     return label; 
     555    return wxStripMenuCodes(wxConvertFromGTKToWXLabel(menu->GetTitle())); 
     556} 
     557 
     558// Gets the original label at the top-level of the menubar 
     559wxString wxMenuBar::GetMenuLabel(size_t pos) const 
     560{ 
     561    wxMenuList::compatibility_iterator node = m_menus.Item( pos ); 
     562 
     563    wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") ); 
     564 
     565    wxMenu* menu = node->GetData(); 
     566 
     567    return wxConvertFromGTKToWXLabel(menu->GetTitle()); 
    538568} 
    539569 
     
    744774wxString wxMenuItemBase::GetLabelFromText(const wxString& text) 
    745775{ 
     776    // The argument to this function will now always be in wxWidgets standard label 
     777    // format, not GTK+ format, so we do what the other ports do. 
     778 
     779    return wxStripMenuCodes(text); 
     780 
     781#if 0 
    746782    wxString label; 
    747783 
     
    780816 
    781817    return label; 
     818#endif 
    782819} 
    783820 
     
    9851022 
    9861023    return ((GtkCheckMenuItem*)m_menuItem)->active != 0; 
     1024} 
     1025 
     1026wxString wxMenuItem::GetItemLabel() const 
     1027{ 
     1028    wxString label = wxConvertFromGTKToWXLabel(m_text); 
     1029    if (!m_hotKey.IsEmpty()) 
     1030        label = label + wxT("\t") + m_hotKey; 
     1031    return label; 
    9871032} 
    9881033