]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/menu.cpp
*** empty log message ***
[wxWidgets.git] / src / gtk1 / menu.cpp
index e1d680563e3e018ebd5246759ffa44695b94d34f..6b95c406e78b3d650ed000313c70cc37dbbc17f6 100644 (file)
@@ -38,12 +38,13 @@ wxMenuBar::wxMenuBar( long style )
     /* the parent window is known after wxFrame::SetMenu() */
     m_needParent = FALSE;
     m_style = style;
+    m_invokingWindow = (wxWindow*) NULL;
 
     if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) ||
         !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, _T("menubar") ))
     {
         wxFAIL_MSG( _T("wxMenuBar creation failed") );
-       return;
+        return;
     }
 
     m_menus.DeleteContents( TRUE );
@@ -76,12 +77,13 @@ wxMenuBar::wxMenuBar()
     /* the parent window is known after wxFrame::SetMenu() */
     m_needParent = FALSE;
     m_style = 0;
+    m_invokingWindow = (wxWindow*) NULL;
 
     if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) ||
         !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("menubar") ))
     {
         wxFAIL_MSG( _T("wxMenuBar creation failed") );
-       return;
+        return;
     }
     
     m_menus.DeleteContents( TRUE );
@@ -152,6 +154,7 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
 
 void wxMenuBar::SetInvokingWindow( wxWindow *win )
 {
+    m_invokingWindow = win;
 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
     wxWindow *top_frame = win;
     while (top_frame->GetParent())
@@ -172,6 +175,7 @@ void wxMenuBar::SetInvokingWindow( wxWindow *win )
 
 void wxMenuBar::UnsetInvokingWindow( wxWindow *win )
 {
+    m_invokingWindow = (wxWindow*) NULL;
 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
     wxWindow *top_frame = win;
     while (top_frame->GetParent())
@@ -204,14 +208,25 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
         {
 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
             str << _T('_');
-        } else
-        if (*pc == _T('/'))
+        }
+        else if (*pc == _T('/'))
         {
             str << _T('\\');
 #endif
         }
         else
-           str << *pc;
+        {
+#if __WXGTK12__
+            if ( *pc == _T('_') )
+            {
+                // underscores must be doubled to prevent them from being
+                // interpreted as accelerator character prefix by GTK
+                str << *pc;
+            }
+#endif // GTK+ 1.2
+
+            str << *pc;
+        }
     }
 
     /* this doesn't have much effect right now */
@@ -239,7 +254,11 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
     wxString tmp = _T("<main>/");
     for ( pc = str; *pc != _T('\0'); pc++ )
     {
-       if (*pc == _T('_')) pc++; /* skip it */
+       // contrary to the common sense, we must throw out _all_ underscores,
+       // (i.e. "Hello__World" => "HelloWorld" and not "Hello_World" as we
+       // might naively think). IMHO it's a bug in GTK+ (VZ) 
+       while (*pc == _T('_'))
+           pc++;
        tmp << *pc;
     }
     menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() );
@@ -254,6 +273,11 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
     gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner );
 
 #endif
+
+    // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
+    // adding menu later on.
+    if (m_invokingWindow)
+        wxMenubarSetInvokingWindow( menu, m_invokingWindow );
 }
 
 static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
@@ -572,8 +596,12 @@ void wxMenuItem::SetName( const wxString& str )
         {
 #if (GTK_MINOR_VERSION > 0)
             m_text << _T('_');
-        } else
-        if (*pc == _T('/'))      /* we have to filter out slashes ... */
+        }
+        else if ( *pc == _T('_') )    // escape underscores
+        {
+            m_text << _T("__");
+        }
+        else if (*pc == _T('/'))      /* we have to filter out slashes ... */
         {
             m_text << _T('\\');  /* ... and replace them with back slashes */
 #endif
@@ -639,8 +667,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
 void
 wxMenu::Init( const wxString& title,
               long style,
-             const wxFunction func
-             )
+              const wxFunction func
+            )
 {
     m_title = title;
     m_items.DeleteContents( TRUE );
@@ -807,7 +835,7 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
     wxString s = _T("<main>/");
     for ( const wxChar *pc = text; *pc != _T('\0'); pc++ )
     {
-        if (*pc == _T('_')) pc++; /* skip it */
+        while (*pc == _T('_')) pc++; /* skip it */
         s << *pc;
     }