+#if wxUSE_MENUS && wxUSE_ACCEL
+// Helper for wxCreateAcceleratorTableForMenuBar
+static void wxAddAccelerators(wxList& accelEntries, wxMenu* menu)
+{
+ size_t i;
+ for (i = 0; i < menu->GetMenuItems().GetCount(); i++)
+ {
+ wxMenuItem* item = (wxMenuItem*) menu->GetMenuItems().Item(i)->GetData();
+ if (item->GetSubMenu())
+ {
+ wxAddAccelerators(accelEntries, item->GetSubMenu());
+ }
+ else if (!item->GetItemLabel().IsEmpty())
+ {
+ wxAcceleratorEntry* entry = wxAcceleratorEntry::Create(item->GetItemLabel());
+ if (entry)
+ {
+ entry->Set(entry->GetFlags(), entry->GetKeyCode(), item->GetId());
+ accelEntries.Append((wxObject*) entry);
+ }
+ }
+ }
+}
+
+// Create an accelerator table consisting of all the accelerators
+// from the menubar in the given menus
+static wxAcceleratorTable wxCreateAcceleratorTableForMenuBar(wxMenuBar* menuBar)
+{
+ wxList accelEntries;
+
+ size_t i;
+ for (i = 0; i < menuBar->GetMenuCount(); i++)
+ {
+ wxAddAccelerators(accelEntries, menuBar->GetMenu(i));
+ }
+
+ size_t n = accelEntries.GetCount();
+
+ if (n == 0)
+ return wxAcceleratorTable();
+
+ wxAcceleratorEntry* entries = new wxAcceleratorEntry[n];
+
+ for (i = 0; i < accelEntries.GetCount(); i++)
+ {
+ wxAcceleratorEntry* entry = (wxAcceleratorEntry*) accelEntries.Item(i)->GetData();
+ entries[i] = (*entry);
+ delete entry;
+
+ }
+
+ wxAcceleratorTable table(n, entries);
+ delete[] entries;
+
+ return table;
+}
+#endif // wxUSE_MENUS && wxUSE_ACCEL
+