/////////////////////////////////////////////////////////////////////////////
-// 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"
// implementation
// ============================================================================
-#include <wx/listimpl.cpp>
+#include "wx/listimpl.cpp"
-WX_DEFINE_LIST( wxMenuInfoList ) ;
+WX_DEFINE_LIST( wxMenuInfoList )
#if wxUSE_EXTENDED_RTTI
if ( pItem->GetBitmap().Ok() &&
!pItem->GetTextColour().Ok() &&
!pItem->GetBackgroundColour().Ok() &&
- !pItem->GetFont().Ok() )
+ !pItem->GetFont().Ok() &&
+ !pItem->GetBitmap(true).Ok() )
{
// try to use InsertMenuItem() as it's guaranteed to look correctly
// while our owner-drawning code is not
// now run-time one: MIIM_BITMAP only works under WinME/2000+
if ( wxGetWinVersion() >= wxWinVersion_98 )
{
- mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | MIIM_BITMAP;
- mii.wID = id;
+ mii.fMask = MIIM_STRING | MIIM_DATA | MIIM_BITMAP;
mii.cch = itemText.length();
mii.dwTypeData = wx_const_cast(wxChar *, itemText.c_str());
+ if (flags & MF_POPUP)
+ {
+ mii.fMask |= MIIM_SUBMENU;
+ mii.hSubMenu = (HMENU)pItem->GetSubMenu()->GetHMenu();
+ }
+ else
+ {
+ mii.fMask |= MIIM_ID;
+ mii.wID = id;
+ }
+
// we can't pass HBITMAP directly as hbmpItem for 2 reasons:
// 1. we can't draw it with transparency then (this is not
// very important now but would be with themed menu bg)
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) )
{
HWND hCommandBar = (HWND) GetToolBar()->GetHWND();
HMENU hMenu = (HMENU)::SendMessage(hCommandBar, SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);
- if (hMenu)
+
+ // hMenu may be zero on Windows Mobile 5. So add the menus anyway.
+ if (1) // (hMenu)
{
TBBUTTON tbButton;
memset(&tbButton, 0, sizeof(TBBUTTON));
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) )
{
m_titles[pos] = title;
- if ( IsAttached() )
+#if defined(WINCE_WITHOUT_COMMANDBAR)
+ if (IsAttached())
+#else
+ if (GetHmenu())
+#endif
{
int mswpos = MSWPositionForWxMenu(menuOld,pos);
}
#endif // wxUSE_ACCEL
- Refresh();
+ if (IsAttached())
+ Refresh();
}
return menuOld;
// Find out which MSW item before which we'll be inserting before
// wxMenuBarBase::Insert is called and GetMenu(pos) is the new menu.
// If IsAttached() is false this won't be used anyway
- int mswpos = (!IsAttached() || (pos == m_menus.GetCount()))
+ bool isAttached =
+#if defined(WINCE_WITHOUT_COMMANDBAR)
+ IsAttached();
+#else
+ (GetHmenu() != 0);
+#endif
+
+ int mswpos = (!isAttached || (pos == m_menus.GetCount()))
? -1 // append the menu
: MSWPositionForWxMenu(GetMenu(pos),pos);
m_titles.Insert(title, pos);
- if ( IsAttached() )
+ if ( isAttached )
{
-#if defined(WINCE_WITHOUT_COMMANDAR)
+#if defined(WINCE_WITHOUT_COMMANDBAR)
if (!GetToolBar())
return false;
TBBUTTON tbButton;
wxLogLastError(wxT("TB_INSERTBUTTON"));
return false;
}
+ wxUnusedVar(mswpos);
#else
if ( !::InsertMenu(GetHmenu(), mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,
}
#endif // wxUSE_ACCEL
- Refresh();
+ if (IsAttached())
+ Refresh();
}
return true;
m_titles.Add(title);
- if ( IsAttached() )
+#if defined(WINCE_WITHOUT_COMMANDBAR)
+ if (IsAttached())
+#else
+ if (GetHmenu())
+#endif
{
-#if defined(WINCE_WITHOUT_COMMANDAR)
+#if defined(WINCE_WITHOUT_COMMANDBAR)
if (!GetToolBar())
return false;
TBBUTTON tbButton;
}
#endif // wxUSE_ACCEL
- Refresh();
+ if (IsAttached())
+ Refresh();
}
return true;
if ( !menu )
return NULL;
- if ( IsAttached() )
+#if defined(WINCE_WITHOUT_COMMANDBAR)
+ if (IsAttached())
+#else
+ if (GetHmenu())
+#endif
{
-#if defined(WINCE_WITHOUT_COMMANDAR)
+#if defined(WINCE_WITHOUT_COMMANDBAR)
if (GetToolBar())
{
if (!::SendMessage((HWND) GetToolBar()->GetHWND(), TB_DELETEBUTTON, (UINT) pos, (LPARAM) 0))
}
#endif // wxUSE_ACCEL
- Refresh();
+ if (IsAttached())
+ Refresh();
}
-
m_titles.RemoveAt(pos);
return menu;