X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/acfd422afac254f4356904275656c0c15685fa1e..0c0890656219df340e90c8f3ba230c50490096aa:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 5e6b4c8b03..fd67e5ee80 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -107,12 +107,16 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) { if (*pc == _T('&')) { - pc++; /* skip it */ #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) str << _T('_'); + } else + if (*pc == _T('/')) + { + str << _T('\\'); #endif - } - str << *pc; + } + else + str << *pc; } /* this doesn't have much effect right now */ @@ -180,7 +184,7 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString return wxNOT_FOUND; } -wxMenuItem *wxMenuBar::FindItemForId(int itemId, wxMenu **menuForItem = NULL) const +wxMenuItem *wxMenuBar::FindItemForId(int itemId, wxMenu **menuForItem ) const { if ( menuForItem ) { @@ -474,18 +478,34 @@ wxMenuItem::wxMenuItem() // it's valid for this function to be called even if m_menuItem == NULL void wxMenuItem::SetName( const wxString& str ) { + /* '\t' is the deliminator indicating a hot key */ m_text = _T(""); - for ( const wxChar *pc = str; *pc != _T('\0'); pc++ ) + const wxChar *pc = str; + for (; (*pc != _T('\0')) && (*pc != _T('\t')); pc++ ) { if (*pc == _T('&')) { - pc++; /* skip it */ #if (GTK_MINOR_VERSION > 0) m_text << _T('_'); + } else + if (*pc == _T('/')) /* we have to filter out slashes ... */ + { + m_text << _T('\\'); /* ... and replace them with back slashes */ #endif } - m_text << *pc; + else + m_text << *pc; } + + /* only GTK 1.2 know about hot keys */ + m_hotKey = _T(""); +#if (GTK_MINOR_VERSION > 0) + if(*pc == _T('\t')) + { + pc++; + m_hotKey = pc; + } +#endif if (m_menuItem) { @@ -580,9 +600,23 @@ void wxMenu::AppendSeparator() wxMenuItem *mitem = new wxMenuItem(); mitem->SetId(ID_SEPARATOR); +#if (GTK_MINOR_VERSION > 0) + GtkItemFactoryEntry entry; + entry.path = "/sep"; + entry.callback = (GtkItemFactoryCallback) NULL; + entry.callback_action = 0; + entry.item_type = ""; + entry.accelerator = (gchar*) NULL; + + gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ + + /* this will be wrong for more than one separator. do we care? */ + GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, "
/sep" ); +#else GtkWidget *menuItem = gtk_menu_item_new(); gtk_menu_append( GTK_MENU(m_menu), menuItem ); gtk_widget_show( menuItem ); +#endif mitem->SetMenuItem(menuItem); m_items.Append( mitem ); @@ -607,7 +641,6 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool GtkItemFactoryEntry entry; entry.path = buf; - entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback; entry.callback_action = 0; if (checkable) @@ -615,6 +648,47 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool else entry.item_type = ""; + entry.accelerator = (gchar*) NULL; + char hotbuf[50]; + wxString hotkey( mitem->GetHotKey() ); + if (!hotkey.IsEmpty()) + { + switch (hotkey[0]) + { + case _T('a'): /* Alt */ + case _T('A'): + case _T('m'): /* Meta */ + case _T('M'): + { + strcpy( hotbuf, "" ); + wxString last = hotkey.Right(1); + strcat( hotbuf, last.mb_str() ); + entry.accelerator = hotbuf; + break; + } + case _T('c'): /* Ctrl */ + case _T('C'): + case _T('s'): /* Strg, yeah man, I'm German */ + case _T('S'): + { + strcpy( hotbuf, "" ); + wxString last = hotkey.Right(1); + strcat( hotbuf, last.mb_str() ); + entry.accelerator = hotbuf; + break; + } + case _T('F'): /* function keys */ + { + strcpy( hotbuf, hotkey.mb_str() ); + entry.accelerator = hotbuf; + break; + } + default: + { + } + } + } + gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ /* in order to get the pointer to the item we need the item text _without_ underscores */ @@ -629,8 +703,8 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool #else - GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( item.mb_str() ) - : gtk_menu_item_new_with_label( item.mb_str() ); + GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( mitem->GetText().mb_str() ) + : gtk_menu_item_new_with_label( mitem->GetText().mb_str() ); gtk_signal_connect( GTK_OBJECT(menuItem), "activate", GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),