]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/menu.cpp
fixed compilation problem with old gcc releases
[wxWidgets.git] / src / gtk1 / menu.cpp
index c41035bbc6cfdf8c4dd66e3635daaf48f8d69be7..8474b6382ee98ddec0a59c792fb235355544bece 100644 (file)
@@ -699,27 +699,20 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
                                 int id,
                                 const wxString& name,
                                 const wxString& help,
-                                bool isCheckable,
+                                wxItemKind kind,
                                 wxMenu *subMenu)
 {
-    return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+    return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
 }
 
 wxMenuItem::wxMenuItem(wxMenu *parentMenu,
                        int id,
                        const wxString& text,
                        const wxString& help,
-                       bool isCheckable,
+                       wxItemKind kind,
                        wxMenu *subMenu)
+          : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
 {
-    m_id = id;
-    m_isCheckable = isCheckable;
-    m_isChecked = FALSE;
-    m_isEnabled = TRUE;
-    m_subMenu = subMenu;
-    m_parentMenu = parentMenu;
-    m_help = help;
-
     m_labelWidget = (GtkWidget *) NULL;
     m_menuItem = (GtkWidget *) NULL;
 
@@ -847,7 +840,12 @@ void wxMenuItem::Check( bool check )
         return;
 
     wxMenuItemBase::Check( check );
-    gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check );
+
+    // GTK+ does it itself for the radio item
+    if ( GetKind() == wxItem_Check )
+    {
+        gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check );
+    }
 }
 
 void wxMenuItem::Enable( bool enable )
@@ -948,6 +946,11 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
     bool appended = FALSE;
 #endif
 
+#if GTK_CHECK_VERSION(1, 2, 0)
+    // is this a radio item?
+    bool isRadio = FALSE;
+#endif // GTK+ >= 1.2
+
     if ( mitem->IsSeparator() )
     {
 #if GTK_CHECK_VERSION(1, 2, 0)
@@ -1046,16 +1049,52 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
         /* local buffer in multibyte form */
         char buf[200];
         strcpy( buf, "/" );
-        strcat( buf, text.mb_str() );
+        strncat( buf, text.mb_str(), WXSIZEOF(buf) - 2 );
+        buf[WXSIZEOF(buf) - 1] = '\0';
 
         GtkItemFactoryEntry entry;
         entry.path = buf;
         entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
         entry.callback_action = 0;
-        if ( mitem->IsCheckable() )
-            entry.item_type = (char *)"<CheckItem>";
-        else
-            entry.item_type = (char *)"<Item>";
+
+        wxString pathRadio;
+        const char *item_type;
+        switch ( mitem->GetKind() )
+        {
+            case wxItem_Check:
+                item_type = "<CheckItem>";
+                break;
+
+            case wxItem_Radio:
+                if ( m_pathLastRadio.empty() )
+                {
+                    // start of a new radio group
+                    item_type = "<RadioItem>";
+                    m_pathLastRadio = buf + 1;
+                }
+                else // continue the radio group
+                {
+                    pathRadio = m_pathLastRadio;
+                    pathRadio.Replace("_", "");
+                    pathRadio.Prepend("<main>/");
+                    item_type = pathRadio;
+                }
+
+                // remember that this one was a radio item to avoid resetting
+                // m_pathLastRadio below
+                isRadio = TRUE;
+                break;
+
+            default:
+                wxFAIL_MSG( _T("unexpected menu item kind") );
+                // fall through
+
+            case wxItem_Normal:
+                item_type = "<Item>";
+                break;
+        }
+
+        entry.item_type = (char *)item_type; // cast needed for GTK+
         entry.accelerator = (gchar*) NULL;
 
 #if wxUSE_ACCEL
@@ -1105,6 +1144,13 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
 
     mitem->SetMenuItem(menuItem);
 
+#if GTK_CHECK_VERSION(1, 2, 0)
+    if ( !isRadio )
+    {
+        m_pathLastRadio.clear();
+    }
+#endif // GTK+ >= 1.2
+
     return TRUE;
 }