/* WinRT Windows.UI Implementation * * Copyright (C) 2023 Mohamad Al-Jaf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include "private.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(ui); struct uisettings { IUISettings3 IUISettings3_iface; LONG ref; }; static inline struct uisettings *impl_from_IUISettings3( IUISettings3 *iface ) { return CONTAINING_RECORD( iface, struct uisettings, IUISettings3_iface ); } static HRESULT WINAPI uisettings3_QueryInterface( IUISettings3 *iface, REFIID iid, void **out ) { struct uisettings *impl = impl_from_IUISettings3( iface ); TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); if (IsEqualGUID( iid, &IID_IUnknown ) || IsEqualGUID( iid, &IID_IInspectable ) || IsEqualGUID( iid, &IID_IAgileObject ) || IsEqualGUID( iid, &IID_IUISettings3 )) { *out = &impl->IUISettings3_iface; IInspectable_AddRef( *out ); return S_OK; } FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); *out = NULL; return E_NOINTERFACE; } static ULONG WINAPI uisettings3_AddRef( IUISettings3 *iface ) { struct uisettings *impl = impl_from_IUISettings3( iface ); ULONG ref = InterlockedIncrement( &impl->ref ); TRACE( "iface %p, ref %lu.\n", iface, ref ); return ref; } static ULONG WINAPI uisettings3_Release( IUISettings3 *iface ) { struct uisettings *impl = impl_from_IUISettings3( iface ); ULONG ref = InterlockedDecrement( &impl->ref ); TRACE( "iface %p, ref %lu.\n", iface, ref ); if (!ref) free( impl ); return ref; } static HRESULT WINAPI uisettings3_GetIids( IUISettings3 *iface, ULONG *iid_count, IID **iids ) { FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); return E_NOTIMPL; } static HRESULT WINAPI uisettings3_GetRuntimeClassName( IUISettings3 *iface, HSTRING *class_name ) { FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); return E_NOTIMPL; } static HRESULT WINAPI uisettings3_GetTrustLevel( IUISettings3 *iface, TrustLevel *trust_level ) { FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); return E_NOTIMPL; } static DWORD get_app_theme(void) { static const WCHAR *subkey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; static const WCHAR *name = L"AppsUseLightTheme"; static const HKEY root = HKEY_CURRENT_USER; DWORD ret = 0, len = sizeof(ret), type; HKEY hkey; if (RegOpenKeyExW( root, subkey, 0, KEY_QUERY_VALUE, &hkey )) return 1; if (RegQueryValueExW( hkey, name, NULL, &type, (BYTE *)&ret, &len ) || type != REG_DWORD) ret = 1; RegCloseKey( hkey ); return ret; } static void set_color_value( BYTE a, BYTE r, BYTE g, BYTE b, Color *out ) { out->A = a; out->R = r; out->G = g; out->B = b; } static HRESULT WINAPI uisettings3_GetColorValue( IUISettings3 *iface, UIColorType type, Color *value ) { DWORD theme; TRACE( "iface %p, type %d, value %p.\n", iface, type, value ); switch (type) { case UIColorType_Foreground: case UIColorType_Background: theme = get_app_theme(); break; default: FIXME( "type %d not implemented.\n", type ); return E_NOTIMPL; } if (type == UIColorType_Foreground) set_color_value( 255, theme ? 0 : 255, theme ? 0 : 255, theme ? 0 : 255, value ); else set_color_value( 255, theme ? 255 : 0, theme ? 255 : 0, theme ? 255 : 0, value ); TRACE( "Returning value.A = %d, value.R = %d, value.G = %d, value.B = %d\n", value->A, value->R, value->G, value->B ); return S_OK; } static HRESULT WINAPI uisettings3_add_ColorValuesChanged( IUISettings3 *iface, ITypedEventHandler_UISettings_IInspectable *handler, EventRegistrationToken *cookie ) { FIXME( "iface %p, handler %p, cookie %p stub!\n", iface, handler, cookie ); return E_NOTIMPL; } static HRESULT WINAPI uisettings3_remove_ColorValuesChanged( IUISettings3 *iface, EventRegistrationToken cookie ) { FIXME( "iface %p, cookie %#I64x stub!\n", iface, cookie.value ); return E_NOTIMPL; } static const struct IUISettings3Vtbl uisettings3_vtbl = { uisettings3_QueryInterface, uisettings3_AddRef, uisettings3_Release, /* IInspectable methods */ uisettings3_GetIids, uisettings3_GetRuntimeClassName, uisettings3_GetTrustLevel, /* IUISettings3 methods */ uisettings3_GetColorValue, uisettings3_add_ColorValuesChanged, uisettings3_remove_ColorValuesChanged, }; struct uisettings_statics { IActivationFactory IActivationFactory_iface; LONG ref; }; static inline struct uisettings_statics *impl_from_IActivationFactory( IActivationFactory *iface ) { return CONTAINING_RECORD( iface, struct uisettings_statics, IActivationFactory_iface ); } static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) { struct uisettings_statics *impl = impl_from_IActivationFactory( iface ); TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); if (IsEqualGUID( iid, &IID_IUnknown ) || IsEqualGUID( iid, &IID_IInspectable ) || IsEqualGUID( iid, &IID_IActivationFactory )) { *out = &impl->IActivationFactory_iface; IInspectable_AddRef( *out ); return S_OK; } FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); *out = NULL; return E_NOINTERFACE; } static ULONG WINAPI factory_AddRef( IActivationFactory *iface ) { struct uisettings_statics *impl = impl_from_IActivationFactory( iface ); ULONG ref = InterlockedIncrement( &impl->ref ); TRACE( "iface %p, ref %lu.\n", iface, ref ); return ref; } static ULONG WINAPI factory_Release( IActivationFactory *iface ) { struct uisettings_statics *impl = impl_from_IActivationFactory( iface ); ULONG ref = InterlockedDecrement( &impl->ref ); TRACE( "iface %p, ref %lu.\n", iface, ref ); return ref; } static HRESULT WINAPI factory_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids ) { FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); return E_NOTIMPL; } static HRESULT WINAPI factory_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name ) { FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); return E_NOTIMPL; } static HRESULT WINAPI factory_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level ) { FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); return E_NOTIMPL; } static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) { struct uisettings *impl; TRACE( "iface %p, instance %p.\n", iface, instance ); if (!(impl = calloc( 1, sizeof(*impl) ))) { *instance = NULL; return E_OUTOFMEMORY; } impl->IUISettings3_iface.lpVtbl = &uisettings3_vtbl; impl->ref = 1; *instance = (IInspectable *)&impl->IUISettings3_iface; return S_OK; } static const struct IActivationFactoryVtbl factory_vtbl = { factory_QueryInterface, factory_AddRef, factory_Release, /* IInspectable methods */ factory_GetIids, factory_GetRuntimeClassName, factory_GetTrustLevel, /* IActivationFactory methods */ factory_ActivateInstance, }; static struct uisettings_statics uisettings_statics = { {&factory_vtbl}, 1, }; IActivationFactory *uisettings_factory = &uisettings_statics.IActivationFactory_iface;