/////////////////////////////////////////////////////////////////////////////
-// Name: menu.cpp
+// Name: src/msw/menu.cpp
// Purpose: wxMenu, wxMenuBar, wxMenuItem
// Author: Julian Smart
// Modified by: Vadim Zeitlin
// headers
// ---------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "menu.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// other standard headers
#include <string.h>
+#if wxUSE_OWNER_DRAWN && defined(MIIM_BITMAP)
+ #include "wx/dynlib.h"
+#endif
+
+#ifndef MNS_CHECKORBMP
+ #define MNS_CHECKORBMP 0x04000000
+#endif
+#ifndef MIM_STYLE
+ #define MIM_STYLE 0x00000010
+#endif
+
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// make the given menu item default
-static void SetDefaultMenuItem(HMENU hmenu, UINT id)
+static void SetDefaultMenuItem(HMENU WXUNUSED_IN_WINCE(hmenu),
+ UINT WXUNUSED_IN_WINCE(id))
{
#ifndef __WXWINCE__
MENUITEMINFO mii;
{
wxLogLastError(wxT("SetMenuItemInfo"));
}
-#else
- wxUnusedVar(hmenu);
- wxUnusedVar(id);
#endif
}
// implementation
// ============================================================================
-#include <wx/listimpl.cpp>
+#include "wx/listimpl.cpp"
-WX_DEFINE_LIST( wxMenuInfoList ) ;
+WX_DEFINE_LIST( wxMenuInfoList )
#if wxUSE_EXTENDED_RTTI
}
else if ( !item->IsSeparator() )
{
+ // recurse upwards: we should only modify m_accels of the top level
+ // menus, not of the submenus as wxMenuBar doesn't look at them
+ // (alternative and arguable cleaner solution would be to recurse
+ // downwards in GetAccelCount() and CopyAccels())
+ if ( GetParent() )
+ {
+ GetParent()->UpdateAccel(item);
+ return;
+ }
+
// find the (new) accel for this item
wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText());
if ( accel )
LPCTSTR pData = NULL;
if ( pos == (size_t)-1 )
{
- // append at the end
- pos = ::GetMenuItemCount(GetHmenu());
+ // append at the end (note that the item is already appended to
+ // internal data structures)
+ pos = GetMenuItemCount() - 1;
}
+ // adjust position to account for the title, if any
+ if ( !m_title.empty() )
+ pos += 2; // for the title itself and its separator
+
BOOL ok = false;
// check if we have something more than a simple text item
WinStruct<MENUITEMINFO> mii;
// now run-time one: MIIM_BITMAP only works under WinME/2000+
- if ( wxGetWinVersion() >= wxWinVersion_5 )
+ if ( wxGetWinVersion() >= wxWinVersion_98 )
{
mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | MIIM_BITMAP;
mii.wID = id;
// case in wx API
WinStruct<MENUINFO> mi;
- mi.fMask = MIM_STYLE;
- mi.dwStyle = MNS_CHECKORBMP;
- if ( !::SetMenuInfo(GetHmenu(), &mi) )
- wxLogLastError(_T("SetMenuInfo(MNS_NOCHECK)"));
+ // don't call SetMenuInfo() directly, this would prevent
+ // the app from starting up under Windows 95/NT 4
+ typedef BOOL (WINAPI *SetMenuInfo_t)(HMENU, MENUINFO *);
+
+ wxDynamicLibrary dllUser(_T("user32"));
+ wxDYNLIB_FUNCTION(SetMenuInfo_t, SetMenuInfo, dllUser);
+ if ( pfnSetMenuInfo )
+ {
+ mi.fMask = MIM_STYLE;
+ mi.dwStyle = MNS_CHECKORBMP;
+ if ( !(*pfnSetMenuInfo)(GetHmenu(), &mi) )
+ wxLogLastError(_T("SetMenuInfo(MNS_NOCHECK)"));
+ }
// tell the item that it's not really owner-drawn but only
// needs to draw its bitmap, the rest is done by Windows
info.cbSize = sizeof(info);
info.fMask = MIIM_TYPE;
info.fType = MFT_STRING;
- info.cch = m_title.Length();
+ info.cch = m_title.length();
info.dwTypeData = (LPTSTR) m_title.c_str();
if ( !SetMenuItemInfo(hMenu, 0, TRUE, & info) )
{
info.cbSize = sizeof(info);
info.fMask = MIIM_TYPE;
info.fType = MFT_STRING;
- info.cch = label.Length();
+ info.cch = label.length();
info.dwTypeData = (LPTSTR) label.c_str();
if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) )
{