From: Helix Graziani helix.graziani@hotmail.com
--- dlls/windows.globalization/main.c | 181 +++++++++++++++++++++--------- 1 file changed, 128 insertions(+), 53 deletions(-)
diff --git a/dlls/windows.globalization/main.c b/dlls/windows.globalization/main.c index 324e0a42291..37746ae8d52 100644 --- a/dlls/windows.globalization/main.c +++ b/dlls/windows.globalization/main.c @@ -22,110 +22,141 @@
WINE_DEFAULT_DEBUG_CHANNEL(locale);
-struct hstring_iterable { - IIterable_HSTRING IIterable_HSTRING_iface; - LONG ref; +/* + * + * IIterator<HSTRING> + * + */ + +struct iterator_hstring +{ + IIterator_HSTRING IIterator_HSTRING_iface; + LONG ref; + + IVectorView_HSTRING *view; + UINT32 index; + UINT32 size; };
-static inline struct hstring_iterable *impl_from_IIterable_HSTRING(IIterable_HSTRING *iface) +static inline struct iterator_hstring *impl_from_IIterator_HSTRING( IIterator_HSTRING *iface ) { - return CONTAINING_RECORD(iface, struct hstring_iterable, IIterable_HSTRING_iface); + return CONTAINING_RECORD(iface, struct iterator_hstring, IIterator_HSTRING_iface); }
-static HRESULT STDMETHODCALLTYPE hstring_iterable_QueryInterface(IIterable_HSTRING *iface, - REFIID iid, void **out) +static HRESULT WINAPI iterator_hstring_QueryInterface( IIterator_HSTRING *iface, REFIID iid, void **out ) { - struct hstring_iterable *impl = impl_from_IIterable_HSTRING(iface); - TRACE("iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out); + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
- if (IsEqualGUID(iid, &IID_IUnknown) || - IsEqualGUID(iid, &IID_IInspectable) || - IsEqualGUID(iid, &IID_IAgileObject) || - IsEqualGUID(iid, &IID_IIterable_HSTRING)) + 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_IIterator_HSTRING)) { - IUnknown_AddRef(iface); - *out = &impl->IIterable_HSTRING_iface; - return S_OK; + IInspectable_AddRef((*out = &impl->IIterator_HSTRING_iface)); + return S_OK; }
- FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); *out = NULL; return E_NOINTERFACE; }
-static ULONG STDMETHODCALLTYPE hstring_iterable_AddRef(IIterable_HSTRING *iface) +static ULONG WINAPI iterator_hstring_AddRef( IIterator_HSTRING *iface ) { - struct hstring_iterable *impl = impl_from_IIterable_HSTRING(iface); + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface); ULONG ref = InterlockedIncrement(&impl->ref); - TRACE("iface %p, ref %lu.\n", iface, ref); + TRACE("iface %p increasing refcount to %lu.\n", iface, ref); return ref; }
-static ULONG STDMETHODCALLTYPE hstring_iterable_Release(IIterable_HSTRING *iface) +static ULONG WINAPI iterator_hstring_Release( IIterator_HSTRING *iface ) { - struct hstring_iterable *impl = impl_from_IIterable_HSTRING(iface); + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface); ULONG ref = InterlockedDecrement(&impl->ref); - TRACE("iface %p, ref %lu.\n", iface, ref); - if (ref == 0) + + TRACE("iface %p decreasing refcount to %lu.\n", iface, ref); + + if (!ref) { + IVectorView_HSTRING_Release(impl->view); free(impl); } + return ref; }
-static HRESULT STDMETHODCALLTYPE hstring_iterable_GetIids(IIterable_HSTRING *iface, - ULONG *iid_count, IID **iids) +static HRESULT WINAPI iterator_hstring_GetIids( IIterator_HSTRING *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 STDMETHODCALLTYPE hstring_iterable_GetRuntimeClassName(IIterable_HSTRING *iface, - HSTRING *class_name) +static HRESULT WINAPI iterator_hstring_GetRuntimeClassName( IIterator_HSTRING *iface, HSTRING *class_name ) { FIXME("iface %p, class_name %p stub!\n", iface, class_name); return E_NOTIMPL; }
-static HRESULT STDMETHODCALLTYPE hstring_iterable_GetTrustLevel(IIterable_HSTRING *iface, - TrustLevel *trust_level) +static HRESULT WINAPI iterator_hstring_GetTrustLevel( IIterator_HSTRING *iface, TrustLevel *trust_level ) { FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); return E_NOTIMPL; }
-static HRESULT STDMETHODCALLTYPE hstring_iterable_First(IIterable_HSTRING *iface, - IIterator_HSTRING **value) +static HRESULT WINAPI iterator_hstring_get_Current( IIterator_HSTRING *iface, HSTRING *value ) { - FIXME("iface %p, value %p stub!\n", iface, value); - return E_NOTIMPL; + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface); + TRACE("iface %p, value %p.\n", iface, value); + return IVectorView_HSTRING_GetAt(impl->view, impl->index, value); }
-static const struct IIterable_HSTRINGVtbl hstring_iterable_vtbl = { - hstring_iterable_QueryInterface, - hstring_iterable_AddRef, - hstring_iterable_Release, - /* IInspectable methods */ - hstring_iterable_GetIids, - hstring_iterable_GetRuntimeClassName, - hstring_iterable_GetTrustLevel, - /* IIterable<HSTRING> methods */ - hstring_iterable_First, -}; +static HRESULT WINAPI iterator_hstring_get_HasCurrent( IIterator_HSTRING *iface, boolean *value ) +{ + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
-static HRESULT hstring_iterable_create(void **out) + TRACE("iface %p, value %p.\n", iface, value); + + *value = impl->index < impl->size; + return S_OK; +} + +static HRESULT WINAPI iterator_hstring_MoveNext( IIterator_HSTRING *iface, boolean *value ) { - struct hstring_iterable *impl; + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
- if (!(impl = malloc(sizeof(struct hstring_iterable)))) return E_OUTOFMEMORY; - impl->ref = 1; + TRACE("iface %p, value %p.\n", iface, value);
- impl->IIterable_HSTRING_iface.lpVtbl = &hstring_iterable_vtbl; + if (impl->index < impl->size) impl->index++; + return IIterator_HSTRING_get_HasCurrent(iface, value); +}
- *out = &impl->IIterable_HSTRING_iface; - return S_OK; +static HRESULT WINAPI iterator_hstring_GetMany( IIterator_HSTRING *iface, UINT32 items_size, + HSTRING *items, UINT *count ) +{ + struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface); + TRACE("iface %p, items_size %u, items %p, count %p.\n", iface, items_size, items, count); + return IVectorView_HSTRING_GetMany(impl->view, impl->index, items_size, items, count); }
+static const IIterator_HSTRINGVtbl iterator_hstring_vtbl = +{ + /* IUnknown methods */ + iterator_hstring_QueryInterface, + iterator_hstring_AddRef, + iterator_hstring_Release, + /* IInspectable methods */ + iterator_hstring_GetIids, + iterator_hstring_GetRuntimeClassName, + iterator_hstring_GetTrustLevel, + /* IIterator<HSTRING> methods */ + iterator_hstring_get_Current, + iterator_hstring_get_HasCurrent, + iterator_hstring_MoveNext, + iterator_hstring_GetMany, +}; + struct hstring_vector { IVectorView_HSTRING IVectorView_HSTRING_iface; @@ -162,7 +193,7 @@ static HRESULT STDMETHODCALLTYPE hstring_vector_QueryInterface(IVectorView_HSTRI if (IsEqualGUID(iid, &IID_IIterable_HSTRING)) { IUnknown_AddRef(iface); - hstring_iterable_create(out); + *out = &impl->IIterable_HSTRING_iface; return S_OK; }
@@ -298,6 +329,8 @@ static const struct IVectorView_HSTRINGVtbl hstring_vector_vtbl = hstring_vector_GetMany, };
+static const struct IIterable_HSTRINGVtbl iterable_view_hstring_vtbl; + static HRESULT hstring_vector_create(HSTRING *values, SIZE_T count, IVectorView_HSTRING **out) { struct hstring_vector *impl; @@ -306,6 +339,7 @@ static HRESULT hstring_vector_create(HSTRING *values, SIZE_T count, IVectorView_ impl->ref = 1;
impl->IVectorView_HSTRING_iface.lpVtbl = &hstring_vector_vtbl; + impl->IIterable_HSTRING_iface.lpVtbl = &iterable_view_hstring_vtbl; impl->count = count; memcpy(impl->values, values, count * sizeof(HSTRING));
@@ -313,6 +347,47 @@ static HRESULT hstring_vector_create(HSTRING *values, SIZE_T count, IVectorView_ return S_OK; }
+/* + * + * IIterable<HSTRING> + * + */ + +DEFINE_IINSPECTABLE_(iterable_view_hstring, IIterable_HSTRING, struct hstring_vector, view_impl_from_IIterable_HSTRING, + IIterable_HSTRING_iface, &impl->IVectorView_HSTRING_iface) + +static HRESULT WINAPI iterable_view_hstring_First( IIterable_HSTRING *iface, IIterator_HSTRING **value ) +{ + struct hstring_vector *impl = view_impl_from_IIterable_HSTRING(iface); + struct iterator_hstring *iter; + + TRACE("iface %p, value %p.\n", iface, value); + + if (!(iter = calloc(1, sizeof(*iter)))) return E_OUTOFMEMORY; + iter->IIterator_HSTRING_iface.lpVtbl = &iterator_hstring_vtbl; + iter->ref = 1; + + IVectorView_HSTRING_AddRef((iter->view = &impl->IVectorView_HSTRING_iface)); + iter->size = impl->count; + + *value = &iter->IIterator_HSTRING_iface; + return S_OK; +} + +static const struct IIterable_HSTRINGVtbl iterable_view_hstring_vtbl = +{ + /* IUnknown methods */ + iterable_view_hstring_QueryInterface, + iterable_view_hstring_AddRef, + iterable_view_hstring_Release, + /* IInspectable methods */ + iterable_view_hstring_GetIids, + iterable_view_hstring_GetRuntimeClassName, + iterable_view_hstring_GetTrustLevel, + /* IIterable<HSTRING> methods */ + iterable_view_hstring_First, +}; + struct windows_globalization { IActivationFactory IActivationFactory_iface;