From: Zhiyi Zhang <zzhang@codeweavers.com> --- dlls/windows.ui/tests/uisettings.c | 79 ++++++++++++++++++++++++++++++ dlls/windows.ui/uisettings.c | 40 ++++++++++++++- 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/dlls/windows.ui/tests/uisettings.c b/dlls/windows.ui/tests/uisettings.c index 1e9a1026cdc..9a7fe7c84ae 100644 --- a/dlls/windows.ui/tests/uisettings.c +++ b/dlls/windows.ui/tests/uisettings.c @@ -173,6 +173,77 @@ static void test_AccentColor( IUISettings3 *uisettings3 ) if (default_palette_len) set_accent_palette( default_palette, default_palette_len ); } +static void test_UIElementColor( IUISettings *uisettings ) +{ + static const struct + { + enum UIElementType type; + int syscolor_index; + } + tests[] = + { + { UIElementType_ActiveCaption, COLOR_ACTIVECAPTION }, + { UIElementType_Background, COLOR_BACKGROUND }, + { UIElementType_ButtonFace, COLOR_BTNFACE }, + { UIElementType_ButtonText, COLOR_BTNTEXT }, + { UIElementType_CaptionText, COLOR_CAPTIONTEXT }, + { UIElementType_GrayText, COLOR_GRAYTEXT }, + { UIElementType_Highlight, COLOR_HIGHLIGHT }, + { UIElementType_HighlightText, COLOR_HIGHLIGHTTEXT }, + { UIElementType_Hotlight, COLOR_HOTLIGHT }, + { UIElementType_InactiveCaption, COLOR_INACTIVECAPTION }, + { UIElementType_InactiveCaptionText, COLOR_INACTIVECAPTIONTEXT }, + { UIElementType_Window, COLOR_WINDOW }, + { UIElementType_WindowText, COLOR_WINDOWTEXT }, + { UIElementType_AccentColor, -1 }, + { UIElementType_TextHigh, -1 }, + { UIElementType_TextMedium, -1 }, + { UIElementType_TextLow, -1 }, + { UIElementType_TextContrastWithHigh, -1 }, + { UIElementType_NonTextHigh, -1 }, + { UIElementType_NonTextMediumHigh, -1 }, + { UIElementType_NonTextMedium, -1 }, + { UIElementType_NonTextMediumLow, -1 }, + { UIElementType_NonTextLow, -1 }, + { UIElementType_PageBackground, -1 }, + { UIElementType_PopupBackground, -1 }, + { UIElementType_OverlayOutsidePopup, -1 }, + { (UIElementType)12345, -1 } /* Invalid UIElementType */ + }; + Color color; + HRESULT hr; + + for (int i = 0; i < ARRAY_SIZE( tests ); i++) + { + winetest_push_context( "%d", i ); + + memset( &color, 0xff, sizeof(color) ); + hr = IUISettings_UIElementColor( uisettings, tests[i].type, &color ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + if (tests[i].syscolor_index == -1) + { + ok( color.A == 0 && color.R == 0 && color.G == 0 && color.B == 0, + "Got unexpected color %d %d %d %d.\n", color.A, color.R, color.G, color.B ); + } + else + { + COLORREF colorref = GetSysColor( tests[i].syscolor_index ); + ok( color.A == 0xff && color.R == GetRValue( colorref ) + && color.G == GetGValue( colorref ) && color.B == GetBValue( colorref ), + "Got unexpected color %d %d %d %d.\n", color.A, color.R, color.G, color.B ); + } + + winetest_pop_context(); + } + + /* Crash on Windows */ + if (0) + { + hr = IUISettings_UIElementColor( uisettings, UIElementType_ActiveCaption, NULL ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + } +} + static void test_UISettings(void) { static const WCHAR *uisettings_name = L"Windows.UI.ViewManagement.UISettings"; @@ -181,6 +252,7 @@ static void test_UISettings(void) IUISettings3 *uisettings3; IInspectable *inspectable; DOUBLE text_scale_factor; + IUISettings *uisettings; DWORD default_theme; UIColorType type; Color value; @@ -224,6 +296,8 @@ static void test_UISettings(void) check_interface( inspectable, &IID_IWeakReferenceSource, TRUE ); check_interface( inspectable, &IID_IWeakReference, FALSE ); + hr = IInspectable_QueryInterface( inspectable, &IID_IUISettings, (void **)&uisettings ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); hr = IInspectable_QueryInterface( inspectable, &IID_IUISettings2, (void **)&uisettings2 ); ok( hr == S_OK, "got hr %#lx.\n", hr ); @@ -241,6 +315,8 @@ static void test_UISettings(void) /* Light Theme */ if (!set_app_theme( 1 )) goto done; + test_UIElementColor( uisettings ); + reset_color( &value ); type = UIColorType_Foreground; hr = IUISettings3_GetColorValue( uisettings3, type, &value ); @@ -258,6 +334,8 @@ static void test_UISettings(void) /* Dark Theme */ if (!set_app_theme( 0 )) goto done; + test_UIElementColor( uisettings ); + reset_color( &value ); type = UIColorType_Foreground; hr = IUISettings3_GetColorValue( uisettings3, type, &value ); @@ -274,6 +352,7 @@ static void test_UISettings(void) done: set_app_theme( default_theme ); + IUISettings_Release( uisettings ); IUISettings3_Release( uisettings3 ); skip_uisettings3: diff --git a/dlls/windows.ui/uisettings.c b/dlls/windows.ui/uisettings.c index e94ec0916e9..ce95666723b 100644 --- a/dlls/windows.ui/uisettings.c +++ b/dlls/windows.ui/uisettings.c @@ -197,10 +197,46 @@ static HRESULT WINAPI uisettings_get_MouseHoverTime( IUISettings *iface, UINT32 return E_NOTIMPL; } +static void colorref_to_winui_color( COLORREF colorref, Color *color ) +{ + color->A = 255; + color->R = GetRValue( colorref ); + color->G = GetGValue( colorref ); + color->B = GetBValue( colorref ); +} + static HRESULT WINAPI uisettings_UIElementColor( IUISettings *iface, enum UIElementType element, struct Color *value ) { - FIXME( "iface %p, element %d value %p stub!\n", iface, element, value ); - return E_NOTIMPL; + TRACE( "iface %p, element %d value %p.\n", iface, element, value ); + + switch (element) + { +#define X( element_type, syscolor_index ) \ + case element_type: \ + colorref_to_winui_color( GetSysColor( syscolor_index ), value ); \ + break; + + X( UIElementType_ActiveCaption, COLOR_ACTIVECAPTION ) + X( UIElementType_Background, COLOR_BACKGROUND ) + X( UIElementType_ButtonFace, COLOR_BTNFACE ) + X( UIElementType_ButtonText, COLOR_BTNTEXT ) + X( UIElementType_CaptionText, COLOR_CAPTIONTEXT ) + X( UIElementType_GrayText, COLOR_GRAYTEXT ) + X( UIElementType_Highlight, COLOR_HIGHLIGHT ) + X( UIElementType_HighlightText, COLOR_HIGHLIGHTTEXT ) + X( UIElementType_Hotlight, COLOR_HOTLIGHT ) + X( UIElementType_InactiveCaption, COLOR_INACTIVECAPTION ) + X( UIElementType_InactiveCaptionText, COLOR_INACTIVECAPTIONTEXT ) + X( UIElementType_Window, COLOR_WINDOW ) + X( UIElementType_WindowText, COLOR_WINDOWTEXT ) + +#undef X + default: + memset( value, 0, sizeof(*value) ); + break; + } + + return S_OK; } static const struct IUISettingsVtbl uisettings_vtbl = -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9965