+// ----------------------------------------------------------------------------
+// wxMenuItem
+// ----------------------------------------------------------------------------
+
+#if wxUSE_OWNER_DRAWN
+
+namespace
+{
+
+// helper class to keep information about metrics and other stuff
+// needed for measuring and drawing menu item
+class MenuDrawData
+{
+public:
+ // Wrapper around standard MARGINS structure providing some helper
+ // functions and automatically initializing the margin fields to 0.
+ struct Margins : MARGINS
+ {
+ Margins()
+ {
+ cxLeftWidth =
+ cxRightWidth =
+ cyTopHeight =
+ cyBottomHeight = 0;
+ }
+
+ int GetTotalX() const { return cxLeftWidth + cxRightWidth; }
+ int GetTotalY() const { return cyTopHeight + cyBottomHeight; }
+
+ void ApplyTo(RECT& rect) const
+ {
+ rect.top += cyTopHeight;
+ rect.left += cxLeftWidth;
+ rect.right -= cyTopHeight;
+ rect.bottom -= cyBottomHeight;
+ }
+
+ void UnapplyFrom(RECT& rect) const
+ {
+ rect.top -= cyTopHeight;
+ rect.left -= cxLeftWidth;
+ rect.right += cyTopHeight;
+ rect.bottom += cyBottomHeight;
+ }
+ };
+
+ Margins ItemMargin; // popup item margins
+
+ Margins CheckMargin; // popup check margins
+ Margins CheckBgMargin; // popup check background margins
+
+ Margins ArrowMargin; // popup submenu arrow margins
+
+ Margins SeparatorMargin; // popup separator margins
+
+ SIZE CheckSize; // popup check size metric
+ SIZE ArrowSize; // popup submenu arrow size metric
+ SIZE SeparatorSize; // popup separator size metric
+
+ int TextBorder; // popup border space between
+ // item text and gutter
+
+ int AccelBorder; // popup border space between
+ // item text and accelerator
+
+ int ArrowBorder; // popup border space between
+ // item accelerator and submenu arrow
+
+ int Offset; // system added space at the end of the menu,
+ // add this offset for remove the extra space
+
+ wxFont Font; // default menu font
+
+ bool AlwaysShowCues; // must keyboard cues always be shown?
+
+ bool Theme; // is data initialized for FullTheme?
+
+ static const MenuDrawData* Get()
+ {
+ // notice that s_menuData can't be created as a global variable because
+ // it needs a window to initialize and no windows exist at the time of
+ // globals initialization yet
+ if ( !ms_instance )
+ {
+ static MenuDrawData s_menuData;
+ ms_instance = &s_menuData;
+ }
+
+ #if wxUSE_UXTHEME
+ bool theme = MenuLayout() == FullTheme;
+ if ( ms_instance->Theme != theme )
+ ms_instance->Init();
+ #endif // wxUSE_UXTHEME
+ return ms_instance;
+ }
+
+ MenuDrawData()
+ {
+ Init();
+ }
+
+
+ // 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;