X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/21c8c5236009308b9ba88d003aae4b764875761a..1f0acb435592470b421b80df854fbbb08cd2853f:/include/wx/msw/uxtheme.h?ds=inline diff --git a/include/wx/msw/uxtheme.h b/include/wx/msw/uxtheme.h index f462ec9a0a..934fbb2949 100644 --- a/include/wx/msw/uxtheme.h +++ b/include/wx/msw/uxtheme.h @@ -1,156 +1,137 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: include/wx/msw/uxtheme.h +// Name: wx/msw/uxtheme.h // Purpose: wxUxThemeEngine class: support for XP themes // Author: John Platts, Vadim Zeitlin // Modified by: // Created: 2003 // RCS-ID: $Id$ // Copyright: (c) 2003 John Platts, Vadim Zeitlin -// License: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifndef _WX_UXTHEME_H_ #define _WX_UXTHEME_H_ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma interface "uxtheme.h" -#endif - #include "wx/defs.h" -#include "wx/msw/wrapwin.h" - -typedef void* WXHTHEME; -typedef long WXUHRESULT; -typedef WXHTHEME (__stdcall *PFNWXUOPENTHEMEDATA)(WXHWND, const wchar_t *); -typedef WXUHRESULT (__stdcall *PFNWXUCLOSETHEMEDATA)(WXHTHEME); -typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEBACKGROUND)(WXHTHEME, WXHDC, - int, int, const RECT *, const RECT *); -#define WXU_DTT_GRAYED 0x1 -typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMETEXT)(WXHTHEME, WXHDC, int, - int, const wchar_t *, int, DWORD, - DWORD, const RECT *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)(WXHTHEME, WXHDC, - int, int, const RECT *, RECT *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDEXTENT)(WXHTHEME, WXHDC, int, int, - const RECT *, RECT *); - -enum WXUTHEMESIZE -{ - WXU_TS_MIN, - WXU_TS_TRUE, - WXU_TS_DRAW -}; +#include "wx/msw/private.h" // we use GetHwndOf() +#include "wx/msw/uxthemep.h" -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPARTSIZE)(WXHTHEME, WXHDC, int, int, const RECT *, - enum WXUTHEMESIZE, SIZE *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMETEXTEXTENT)(WXHTHEME, WXHDC, int, int, const wchar_t *, - int, WXDWORD, const RECT *, RECT *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMETEXTMETRICS)(WXHTHEME, WXHDC, - int, int, TEXTMETRIC*); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDREGION)(WXHTHEME, WXHDC, - int, int, const RECT *, WXHRGN *); - -#define WXU_HTTB_BACKGROUNDSEG 0x0000 -#define WXU_HTTB_FIXEDBORDER 0x0002 -#define WXU_HTTB_CAPTION 0x0004 -#define WXU_HTTB_RESIZINGBORDER_LEFT 0x0010 -#define WXU_HTTB_RESIZINGBORDER_TOP 0x0020 -#define WXU_HTTB_RESIZINGBORDER_RIGHT 0x0040 -#define WXU_HTTB_RESIZINGBORDER_BOTTOM 0x0080 -#define WXU_HTTB_RESIZINGBORDER 0x00F0 -#define WXU_HTTB_SIZINGTEMPLATE 0x0100 -#define WXU_HTTB_SYSTEMSIZINGMARGINS 0x0200 - -typedef WXUHRESULT (__stdcall *PFNWXUHITTESTTHEMEBACKGROUND)(WXHTHEME, WXHDC, int, - int, WXDWORD, const RECT *, WXHRGN, - POINT, unsigned short *); -typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEEDGE)(WXHTHEME, WXHDC, int, int, - const RECT *, unsigned int, unsigned int, RECT *); -typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEICON)(WXHTHEME, WXHDC, int, int, - const RECT *, WXHIMAGELIST, int); -typedef BOOL (__stdcall *PFNWXUISTHEMEPARTDEFINED)(WXHTHEME, int, int); -typedef BOOL (__stdcall *PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(WXHTHEME, int, int); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMECOLOR)(WXHTHEME, int, int, int, WXCOLORREF*); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEMETRIC)(WXHTHEME, WXHDC, int, - int, int, int *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESTRING)(WXHTHEME, int, - int, int, wchar_t *, int); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBOOL)(WXHTHEME, int, int, int, BOOL *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEINT)(WXHTHEME, int, int, int, int *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEENUMVALUE)(WXHTHEME, int, int, int, int *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPOSITION)(WXHTHEME, int, int, int, POINT *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEFONT)(WXHTHEME, WXHDC, int, int, int, LOGFONT *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMERECT)(WXHTHEME, int, int, int, RECT *); -typedef struct _WXUMARGINS -{ - int cxLeftWidth; - int cxRightWidth; - int cyTopHeight; - int cyBottomHeight; -} WXUMARGINS, *PWXUMARGINS; -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEMARGINS)(WXHTHEME, WXHDC, int, - int, int, RECT *, WXUMARGINS *); - -#define WXU_MAX_INTLIST_COUNT 10 -typedef struct _WXUINTLIST -{ - int iValueCount; - int iValues[WXU_MAX_INTLIST_COUNT]; -} WXUINTLIST, *PWXUINTLIST; -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEINTLIST)(WXHTHEME, int, - int, int, WXUINTLIST*); +// Amazingly, GetThemeFont() and GetThemeSysFont() functions use LOGFONTA under +// XP but LOGFONTW (even in non-Unicode build) under later versions of Windows. +// If we declare them as taking LOGFONT below, the code would be able to +// silently pass LOGFONTA to them in ANSI build and would crash at run-time +// under Windows Vista/7 because of a buffer overrun (LOGFONTA being smaller +// than LOGFONTW expected by these functions). If we we declare them as taking +// LOGFONTW, the code wouldn't work correctly under XP. So we use a special +// wxUxThemeFont class to encapsulate this and intentionally change the LOGFONT +// output parameters of the theme functions to take it instead. -enum WXUPROPERTYORIGIN +class wxUxThemeFont { - WXU_PO_STATE, - WXU_PO_PART, - WXU_PO_CLASS, - WXU_PO_GLOBAL, - WXU_PO_NOTFOUND +public: + // Trivial default ctor. + wxUxThemeFont() { } + + // Just some unique type. + struct Ptr { }; + +#if wxUSE_UNICODE + // In Unicode build we always use LOGFONT anyhow so this class is + // completely trivial. + Ptr *GetPtr() { return reinterpret_cast(&m_lfW); } + const LOGFONTW& GetLOGFONT() { return m_lfW; } +#else // !wxUSE_UNICODE + // Return either LOGFONTA or LOGFONTW pointer as required by the current + // Windows version. + Ptr *GetPtr() + { + return UseLOGFONTW() ? reinterpret_cast(&m_lfW) + : reinterpret_cast(&m_lfA); + } + + // This method returns LOGFONT (i.e. LOGFONTA in ANSI build and LOGFONTW in + // Unicode one) which can be used with other, normal, Windows or wx + // functions. Internally it may need to transform LOGFONTW to LOGFONTA. + const LOGFONTA& GetLOGFONT() + { + if ( UseLOGFONTW() ) + { + // Most of the fields are the same in LOGFONTA and LOGFONTW so just + // copy everything by default. + memcpy(&m_lfA, &m_lfW, sizeof(m_lfA)); + + // But the face name must be converted from Unicode. + WideCharToMultiByte(CP_ACP, 0, m_lfW.lfFaceName, -1, + m_lfA.lfFaceName, sizeof(m_lfA.lfFaceName), + NULL, NULL); + } + + return m_lfA; + } + +private: + static bool UseLOGFONTW() + { + return wxGetWinVersion() >= wxWinVersion_Vista; + } + + LOGFONTA m_lfA; +#endif // wxUSE_UNICODE/!wxUSE_UNICODE + +private: + LOGFONTW m_lfW; + + wxDECLARE_NO_COPY_CLASS(wxUxThemeFont); }; -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPROPERTYORIGIN)(WXHTHEME, int, - int, int, enum WXUPROPERTYORIGIN *); -typedef WXUHRESULT (__stdcall *PFNWXUSETWINDOWTHEME)(WXHWND, const wchar_t*, const wchar_t *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEFILENAME)(WXHTHEME, int, int, int, wchar_t *, int); -typedef WXCOLORREF (__stdcall *PFNWXUGETTHEMESYSCOLOR)(WXHTHEME, int); -typedef WXHBRUSH (__stdcall *PFNWXUGETTHEMESYSCOLORBRUSH)(WXHTHEME, int); -typedef BOOL (__stdcall *PFNWXUGETTHEMESYSBOOL)(WXHTHEME, int); -typedef int (__stdcall *PFNWXUGETTHEMESYSSIZE)(WXHTHEME, int); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSFONT)(WXHTHEME, int, LOGFONT *); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSSTRING)(WXHTHEME, int, wchar_t *, int); -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSINT)(WXHTHEME, int, int *); -typedef BOOL (__stdcall *PFNWXUISTHEMEACTIVE)(); -typedef BOOL (__stdcall *PFNWXUISAPPTHEMED)(); -typedef WXHTHEME (__stdcall *PFNWXUGETWINDOWTHEME)(WXHWND); - -#define WXU_ETDT_DISABLE 0x00000001 -#define WXU_ETDT_ENABLE 0x00000002 -#define WXU_ETDT_USETABTEXTURE 0x00000004 -#define WXU_ETDT_ENABLETAB 0x00000006 - -typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMEDIALOGTEXTURE)(WXHWND, WXDWORD); -typedef BOOL (__stdcall *PFNWXUISTHEMEDIALOGTEXTUREENABLED)(WXHWND); - -#define WXU_STAP_ALLOW_NONCLIENT 1 -#define WXU_STAP_ALLOW_CONTROLS 2 -#define WXU_STAP_ALLOW_WEBCONTENT 4 - -typedef WXDWORD (__stdcall *PFNWXUGETTHEMEAPPPROPERTIES)(); -typedef void (__stdcall *PFNWXUSETTHEMEAPPPROPERTIES)(WXDWORD); -typedef WXUHRESULT (__stdcall *PFNWXUGETCURRENTTHEMENAME)(wchar_t *, int, - wchar_t *, int, wchar_t *, int); - -#define WXU_SZ_THDOCPROP_DISPLAYNAME L"DisplayName" -#define WXU_SZ_THDOCPROP_CANONICALNAME L"ThemeName" -#define WXU_SZ_THDOCPROP_TOOLTIP L"ToolTip" -#define WXU_SZ_THDOCPROP_AUTHOR L"author" - -typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)(const wchar_t *, - const wchar_t *, wchar_t *, int); -typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEPARENTBACKGROUND)(WXHWND, WXHDC, RECT *); -typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL); +typedef HTHEME (__stdcall *PFNWXUOPENTHEMEDATA)(HWND, const wchar_t *); +typedef HRESULT (__stdcall *PFNWXUCLOSETHEMEDATA)(HTHEME); +typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEBACKGROUND)(HTHEME, HDC, int, int, const RECT *, const RECT *); +typedef HRESULT (__stdcall *PFNWXUDRAWTHEMETEXT)(HTHEME, HDC, int, int, const wchar_t *, int, DWORD, DWORD, const RECT *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)(HTHEME, HDC, int, int, const RECT *, RECT *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDEXTENT)(HTHEME, HDC, int, int, const RECT *, RECT *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEPARTSIZE)(HTHEME, HDC, int, int, const RECT *, /* enum */ THEMESIZE, SIZE *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMETEXTEXTENT)(HTHEME, HDC, int, int, const wchar_t *, int, DWORD, const RECT *, RECT *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMETEXTMETRICS)(HTHEME, HDC, int, int, TEXTMETRIC*); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDREGION)(HTHEME, HDC, int, int, const RECT *, HRGN *); +typedef HRESULT (__stdcall *PFNWXUHITTESTTHEMEBACKGROUND)(HTHEME, HDC, int, int, DWORD, const RECT *, HRGN, POINT, unsigned short *); +typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEEDGE)(HTHEME, HDC, int, int, const RECT *, unsigned int, unsigned int, RECT *); +typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEICON)(HTHEME, HDC, int, int, const RECT *, HIMAGELIST, int); +typedef BOOL (__stdcall *PFNWXUISTHEMEPARTDEFINED)(HTHEME, int, int); +typedef BOOL (__stdcall *PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(HTHEME, int, int); +typedef HRESULT (__stdcall *PFNWXUGETTHEMECOLOR)(HTHEME, int, int, int, COLORREF*); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEMETRIC)(HTHEME, HDC, int, int, int, int *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMESTRING)(HTHEME, int, int, int, wchar_t *, int); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEBOOL)(HTHEME, int, int, int, BOOL *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEINT)(HTHEME, int, int, int, int *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEENUMVALUE)(HTHEME, int, int, int, int *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEPOSITION)(HTHEME, int, int, int, POINT *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEFONT)(HTHEME, HDC, int, int, int, wxUxThemeFont::Ptr *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMERECT)(HTHEME, int, int, int, RECT *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEMARGINS)(HTHEME, HDC, int, int, int, RECT *, MARGINS *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEINTLIST)(HTHEME, int, int, int, INTLIST*); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEPROPERTYORIGIN)(HTHEME, int, int, int, /* enum */ PROPERTYORIGIN *); +typedef HRESULT (__stdcall *PFNWXUSETWINDOWTHEME)(HWND, const wchar_t*, const wchar_t *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEFILENAME)(HTHEME, int, int, int, wchar_t *, int); +typedef COLORREF(__stdcall *PFNWXUGETTHEMESYSCOLOR)(HTHEME, int); +typedef HBRUSH (__stdcall *PFNWXUGETTHEMESYSCOLORBRUSH)(HTHEME, int); +typedef BOOL (__stdcall *PFNWXUGETTHEMESYSBOOL)(HTHEME, int); +typedef int (__stdcall *PFNWXUGETTHEMESYSSIZE)(HTHEME, int); +typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSFONT)(HTHEME, int, wxUxThemeFont::Ptr *); +typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSSTRING)(HTHEME, int, wchar_t *, int); +typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSINT)(HTHEME, int, int *); +typedef BOOL (__stdcall *PFNWXUISTHEMEACTIVE)(); +typedef BOOL (__stdcall *PFNWXUISAPPTHEMED)(); +typedef HTHEME (__stdcall *PFNWXUGETWINDOWTHEME)(HWND); +typedef HRESULT (__stdcall *PFNWXUENABLETHEMEDIALOGTEXTURE)(HWND, DWORD); +typedef BOOL (__stdcall *PFNWXUISTHEMEDIALOGTEXTUREENABLED)(HWND); +typedef DWORD (__stdcall *PFNWXUGETTHEMEAPPPROPERTIES)(); +typedef void (__stdcall *PFNWXUSETTHEMEAPPPROPERTIES)(DWORD); +typedef HRESULT (__stdcall *PFNWXUGETCURRENTTHEMENAME)(wchar_t *, int, wchar_t *, int, wchar_t *, int); +typedef HRESULT (__stdcall *PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)(const wchar_t *, const wchar_t *, wchar_t *, int); +typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEPARENTBACKGROUND)(HWND, HDC, RECT *); +typedef HRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL); // ---------------------------------------------------------------------------- // wxUxThemeEngine: provides all theme functions from uxtheme.dll @@ -159,14 +140,14 @@ typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL); // we always define this class, even if wxUSE_UXTHEME == 0, but we just make it // empty in this case -- this allows to use it elsewhere without any #ifdefs #if wxUSE_UXTHEME - #include "wx/dynload.h" + #include "wx/dynlib.h" #define wxUX_THEME_DECLARE(type, func) type func; #else #define wxUX_THEME_DECLARE(type, func) type func(...) { return 0; } #endif -class WXDLLEXPORT wxUxThemeEngine +class WXDLLIMPEXP_CORE wxUxThemeEngine { public: // get the theme engine or NULL if themes are not available @@ -255,7 +236,7 @@ private: friend class wxUxThemeModule; #endif // wxUSE_UXTHEME - DECLARE_NO_COPY_CLASS(wxUxThemeEngine) + wxDECLARE_NO_COPY_CLASS(wxUxThemeEngine); }; #if wxUSE_UXTHEME @@ -289,16 +270,15 @@ private: class wxUxThemeHandle { public: - wxUxThemeHandle(wxWindow *win, const wchar_t *classes) + wxUxThemeHandle(const wxWindow *win, const wchar_t *classes) { wxUxThemeEngine *engine = wxUxThemeEngine::Get(); - m_hTheme = - engine ? (WXHTHEME)engine->OpenThemeData(win->GetHWND(), classes) - : NULL; + m_hTheme = engine ? (HTHEME)engine->OpenThemeData(GetHwndOf(win), classes) + : NULL; } - operator WXHTHEME() const { return m_hTheme; } + operator HTHEME() const { return m_hTheme; } ~wxUxThemeHandle() { @@ -309,9 +289,9 @@ public: } private: - WXHTHEME m_hTheme; + HTHEME m_hTheme; - DECLARE_NO_COPY_CLASS(wxUxThemeHandle) + wxDECLARE_NO_COPY_CLASS(wxUxThemeHandle); }; #endif // _WX_UXTHEME_H_