From cef14be8f046b69e2a2884fc4ea29e386c8b567d Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 8 Nov 2007 14:55:48 +0000 Subject: [PATCH] Menubar accelerators are now preserved in full screen mode, as per wxMSW and wxMac git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@49725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/gtk/toplevel.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 9d6dbb2f87..390dbbb014 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -108,6 +108,7 @@ wxGTK: a background colour bug in the gtk-qt theme under KDE. - wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) now returns the background colour of text controls. +- wxFrame::ShowFullScreen now preserves the menubar's accelerators. wxMac: diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 8e3917f161..9448c39eca 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -709,11 +709,79 @@ bool wxTopLevelWindowGTK::EnableCloseButton( bool enable ) return true; } +// 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; +} + bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long style ) { if (show == m_fsIsShowing) return false; // return what? + if (show) + { + // Preserve menubar accelerators during full-screen operation + wxFrame* frame = wxDynamicCast(this, wxFrame); + if (frame && frame->GetMenuBar()) + { + wxAcceleratorTable table(wxCreateAcceleratorTableForMenuBar(frame->GetMenuBar())); + if (table.IsOk()) + SetAcceleratorTable(table); + } + } + m_fsIsShowing = show; wxX11FullScreenMethod method =