+ // get the theme engine or NULL if themes
+ // are not available or not supported on menu
+ static wxUxThemeEngine *GetUxThemeEngine()
+ {
+ #if wxUSE_UXTHEME
+ if ( MenuLayout() == FullTheme )
+ return wxUxThemeEngine::GetIfActive();
+ #endif // wxUSE_UXTHEME
+ return NULL;
+ }
+
+
+ enum MenuLayoutType
+ {
+ FullTheme, // full menu themes (Vista or new)
+ PseudoTheme, // pseudo menu themes (on XP)
+ Classic
+ };
+
+ static MenuLayoutType MenuLayout()
+ {
+ MenuLayoutType menu = Classic;
+ #if wxUSE_UXTHEME
+ if ( wxUxThemeEngine::GetIfActive() != NULL )
+ {
+ static wxWinVersion ver = wxGetWinVersion();
+ if ( ver >= wxWinVersion_Vista )
+ menu = FullTheme;
+ else if ( ver == wxWinVersion_XP )
+ menu = PseudoTheme;
+ }
+ #endif // wxUSE_UXTHEME
+ return menu;
+ }
+
+private:
+ void Init();
+
+ static MenuDrawData* ms_instance;
+};
+
+MenuDrawData* MenuDrawData::ms_instance = NULL;
+
+void MenuDrawData::Init()
+{
+#if wxUSE_UXTHEME
+ wxUxThemeEngine* theme = GetUxThemeEngine();
+ if ( theme )
+ {
+ wxWindow* window = static_cast<wxApp*>(wxApp::GetInstance())->GetTopWindow();
+ wxUxThemeHandle hTheme(window, L"MENU");
+
+ theme->GetThemeMargins(hTheme, NULL, MENU_POPUPITEM, 0,
+ TMT_CONTENTMARGINS, NULL,
+ &ItemMargin);
+
+ theme->GetThemeMargins(hTheme, NULL, MENU_POPUPCHECK, 0,
+ TMT_CONTENTMARGINS, NULL,
+ &CheckMargin);
+ theme->GetThemeMargins(hTheme, NULL, MENU_POPUPCHECKBACKGROUND, 0,
+ TMT_CONTENTMARGINS, NULL,
+ &CheckBgMargin);
+
+ theme->GetThemeMargins(hTheme, NULL, MENU_POPUPSUBMENU, 0,
+ TMT_CONTENTMARGINS, NULL,
+ &ArrowMargin);
+
+ theme->GetThemeMargins(hTheme, NULL, MENU_POPUPSEPARATOR, 0,
+ TMT_SIZINGMARGINS, NULL,
+ &SeparatorMargin);
+
+ theme->GetThemePartSize(hTheme, NULL, MENU_POPUPCHECK, 0,
+ NULL, TS_TRUE, &CheckSize);
+
+ theme->GetThemePartSize(hTheme, NULL, MENU_POPUPSUBMENU, 0,
+ NULL, TS_TRUE, &ArrowSize);
+
+ theme->GetThemePartSize(hTheme, NULL, MENU_POPUPSEPARATOR, 0,
+ NULL, TS_TRUE, &SeparatorSize);
+
+ theme->GetThemeInt(hTheme, MENU_POPUPBACKGROUND, 0, TMT_BORDERSIZE, &TextBorder);
+
+ AccelBorder = 34;
+ ArrowBorder = 0;
+
+ Offset = -14;
+
+ wxUxThemeFont themeFont;
+ theme->GetThemeSysFont(hTheme, TMT_MENUFONT, themeFont.GetPtr());
+ Font = wxFont(themeFont.GetLOGFONT());
+
+ Theme = true;