include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / windows.globalization / main.c
blob37746ae8d523962c8497120c13cff778e378d66e
1 /* WinRT Windows.Globalization implementation
3 * Copyright 2021 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "initguid.h"
21 #include "private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(locale);
27 * IIterator<HSTRING>
31 struct iterator_hstring
33 IIterator_HSTRING IIterator_HSTRING_iface;
34 LONG ref;
36 IVectorView_HSTRING *view;
37 UINT32 index;
38 UINT32 size;
41 static inline struct iterator_hstring *impl_from_IIterator_HSTRING( IIterator_HSTRING *iface )
43 return CONTAINING_RECORD(iface, struct iterator_hstring, IIterator_HSTRING_iface);
46 static HRESULT WINAPI iterator_hstring_QueryInterface( IIterator_HSTRING *iface, REFIID iid, void **out )
48 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
50 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
52 if (IsEqualGUID(iid, &IID_IUnknown) ||
53 IsEqualGUID(iid, &IID_IInspectable) ||
54 IsEqualGUID(iid, &IID_IAgileObject) ||
55 IsEqualGUID(iid, &IID_IIterator_HSTRING))
57 IInspectable_AddRef((*out = &impl->IIterator_HSTRING_iface));
58 return S_OK;
61 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
62 *out = NULL;
63 return E_NOINTERFACE;
66 static ULONG WINAPI iterator_hstring_AddRef( IIterator_HSTRING *iface )
68 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
69 ULONG ref = InterlockedIncrement(&impl->ref);
70 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
71 return ref;
74 static ULONG WINAPI iterator_hstring_Release( IIterator_HSTRING *iface )
76 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
77 ULONG ref = InterlockedDecrement(&impl->ref);
79 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
81 if (!ref)
83 IVectorView_HSTRING_Release(impl->view);
84 free(impl);
87 return ref;
90 static HRESULT WINAPI iterator_hstring_GetIids( IIterator_HSTRING *iface, ULONG *iid_count, IID **iids )
92 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
93 return E_NOTIMPL;
96 static HRESULT WINAPI iterator_hstring_GetRuntimeClassName( IIterator_HSTRING *iface, HSTRING *class_name )
98 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
99 return E_NOTIMPL;
102 static HRESULT WINAPI iterator_hstring_GetTrustLevel( IIterator_HSTRING *iface, TrustLevel *trust_level )
104 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
105 return E_NOTIMPL;
108 static HRESULT WINAPI iterator_hstring_get_Current( IIterator_HSTRING *iface, HSTRING *value )
110 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
111 TRACE("iface %p, value %p.\n", iface, value);
112 return IVectorView_HSTRING_GetAt(impl->view, impl->index, value);
115 static HRESULT WINAPI iterator_hstring_get_HasCurrent( IIterator_HSTRING *iface, boolean *value )
117 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
119 TRACE("iface %p, value %p.\n", iface, value);
121 *value = impl->index < impl->size;
122 return S_OK;
125 static HRESULT WINAPI iterator_hstring_MoveNext( IIterator_HSTRING *iface, boolean *value )
127 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
129 TRACE("iface %p, value %p.\n", iface, value);
131 if (impl->index < impl->size) impl->index++;
132 return IIterator_HSTRING_get_HasCurrent(iface, value);
135 static HRESULT WINAPI iterator_hstring_GetMany( IIterator_HSTRING *iface, UINT32 items_size,
136 HSTRING *items, UINT *count )
138 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
139 TRACE("iface %p, items_size %u, items %p, count %p.\n", iface, items_size, items, count);
140 return IVectorView_HSTRING_GetMany(impl->view, impl->index, items_size, items, count);
143 static const IIterator_HSTRINGVtbl iterator_hstring_vtbl =
145 /* IUnknown methods */
146 iterator_hstring_QueryInterface,
147 iterator_hstring_AddRef,
148 iterator_hstring_Release,
149 /* IInspectable methods */
150 iterator_hstring_GetIids,
151 iterator_hstring_GetRuntimeClassName,
152 iterator_hstring_GetTrustLevel,
153 /* IIterator<HSTRING> methods */
154 iterator_hstring_get_Current,
155 iterator_hstring_get_HasCurrent,
156 iterator_hstring_MoveNext,
157 iterator_hstring_GetMany,
160 struct hstring_vector
162 IVectorView_HSTRING IVectorView_HSTRING_iface;
163 IIterable_HSTRING IIterable_HSTRING_iface;
164 LONG ref;
166 ULONG count;
167 HSTRING values[];
170 C_ASSERT(sizeof(struct hstring_vector) == offsetof(struct hstring_vector, values[0]));
172 static inline struct hstring_vector *impl_from_IVectorView_HSTRING(IVectorView_HSTRING *iface)
174 return CONTAINING_RECORD(iface, struct hstring_vector, IVectorView_HSTRING_iface);
177 static HRESULT STDMETHODCALLTYPE hstring_vector_QueryInterface(IVectorView_HSTRING *iface,
178 REFIID iid, void **out)
180 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
181 TRACE("iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out);
183 if (IsEqualGUID(iid, &IID_IUnknown) ||
184 IsEqualGUID(iid, &IID_IInspectable) ||
185 IsEqualGUID(iid, &IID_IAgileObject) ||
186 IsEqualGUID(iid, &IID_IVectorView_HSTRING))
188 IUnknown_AddRef(iface);
189 *out = &impl->IVectorView_HSTRING_iface;
190 return S_OK;
193 if (IsEqualGUID(iid, &IID_IIterable_HSTRING))
195 IUnknown_AddRef(iface);
196 *out = &impl->IIterable_HSTRING_iface;
197 return S_OK;
200 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
201 *out = NULL;
202 return E_NOINTERFACE;
205 static ULONG STDMETHODCALLTYPE hstring_vector_AddRef(IVectorView_HSTRING *iface)
207 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
208 ULONG ref = InterlockedIncrement(&impl->ref);
209 TRACE("iface %p, ref %lu.\n", iface, ref);
210 return ref;
213 static ULONG STDMETHODCALLTYPE hstring_vector_Release(IVectorView_HSTRING *iface)
215 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
216 ULONG ref = InterlockedDecrement(&impl->ref);
217 TRACE("iface %p, ref %lu.\n", iface, ref);
218 if (ref == 0)
220 while (impl->count--) WindowsDeleteString(impl->values[impl->count]);
221 free(impl);
223 return ref;
226 static HRESULT STDMETHODCALLTYPE hstring_vector_GetIids(IVectorView_HSTRING *iface,
227 ULONG *iid_count, IID **iids)
229 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
230 return E_NOTIMPL;
233 static HRESULT STDMETHODCALLTYPE hstring_vector_GetRuntimeClassName(IVectorView_HSTRING *iface,
234 HSTRING *class_name)
236 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
237 return E_NOTIMPL;
240 static HRESULT STDMETHODCALLTYPE hstring_vector_GetTrustLevel(IVectorView_HSTRING *iface,
241 TrustLevel *trust_level)
243 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
244 return E_NOTIMPL;
247 static HRESULT STDMETHODCALLTYPE hstring_vector_GetAt(IVectorView_HSTRING *iface,
248 UINT32 index, HSTRING *value)
250 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
252 TRACE("iface %p, index %#x, value %p.\n", iface, index, value);
254 *value = NULL;
255 if (index >= impl->count) return E_BOUNDS;
256 return WindowsDuplicateString(impl->values[index], value);
259 static HRESULT STDMETHODCALLTYPE hstring_vector_get_Size(IVectorView_HSTRING *iface,
260 UINT32 *value)
262 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
264 TRACE("iface %p, value %p.\n", iface, value);
266 *value = impl->count;
267 return S_OK;
270 static HRESULT STDMETHODCALLTYPE hstring_vector_IndexOf(IVectorView_HSTRING *iface,
271 HSTRING element, UINT32 *index, BOOLEAN *found)
273 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
274 INT32 i, order;
276 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
278 for (i = 0; i < impl->count; ++i)
279 if (SUCCEEDED(WindowsCompareStringOrdinal(impl->values[i], element, &order)) && order == 0)
280 break;
282 if (i < impl->count)
284 *found = TRUE;
285 *index = i;
287 else
289 *found = FALSE;
290 *index = 0;
293 return S_OK;
296 static HRESULT STDMETHODCALLTYPE hstring_vector_GetMany(IVectorView_HSTRING *iface,
297 UINT32 start_index, UINT32 items_size, HSTRING *items, UINT *count)
299 struct hstring_vector *impl = impl_from_IVectorView_HSTRING(iface);
300 HRESULT hr = S_OK;
301 ULONG i;
303 TRACE("iface %p, start_index %#x, items %p, count %p.\n", iface, start_index, items, count);
305 memset(items, 0, items_size * sizeof(*items));
307 for (i = start_index; i < impl->count && i < start_index + items_size; ++i)
308 if (FAILED(hr = WindowsDuplicateString(impl->values[i], items + i - start_index)))
309 break;
311 if (FAILED(hr)) while (i-- > start_index) WindowsDeleteString(items[i - start_index]);
312 *count = i - start_index;
313 return hr;
316 static const struct IVectorView_HSTRINGVtbl hstring_vector_vtbl =
318 hstring_vector_QueryInterface,
319 hstring_vector_AddRef,
320 hstring_vector_Release,
321 /* IInspectable methods */
322 hstring_vector_GetIids,
323 hstring_vector_GetRuntimeClassName,
324 hstring_vector_GetTrustLevel,
325 /* IVectorView<HSTRING> methods */
326 hstring_vector_GetAt,
327 hstring_vector_get_Size,
328 hstring_vector_IndexOf,
329 hstring_vector_GetMany,
332 static const struct IIterable_HSTRINGVtbl iterable_view_hstring_vtbl;
334 static HRESULT hstring_vector_create(HSTRING *values, SIZE_T count, IVectorView_HSTRING **out)
336 struct hstring_vector *impl;
338 if (!(impl = malloc(offsetof(struct hstring_vector, values[count])))) return E_OUTOFMEMORY;
339 impl->ref = 1;
341 impl->IVectorView_HSTRING_iface.lpVtbl = &hstring_vector_vtbl;
342 impl->IIterable_HSTRING_iface.lpVtbl = &iterable_view_hstring_vtbl;
343 impl->count = count;
344 memcpy(impl->values, values, count * sizeof(HSTRING));
346 *out = &impl->IVectorView_HSTRING_iface;
347 return S_OK;
352 * IIterable<HSTRING>
356 DEFINE_IINSPECTABLE_(iterable_view_hstring, IIterable_HSTRING, struct hstring_vector, view_impl_from_IIterable_HSTRING,
357 IIterable_HSTRING_iface, &impl->IVectorView_HSTRING_iface)
359 static HRESULT WINAPI iterable_view_hstring_First( IIterable_HSTRING *iface, IIterator_HSTRING **value )
361 struct hstring_vector *impl = view_impl_from_IIterable_HSTRING(iface);
362 struct iterator_hstring *iter;
364 TRACE("iface %p, value %p.\n", iface, value);
366 if (!(iter = calloc(1, sizeof(*iter)))) return E_OUTOFMEMORY;
367 iter->IIterator_HSTRING_iface.lpVtbl = &iterator_hstring_vtbl;
368 iter->ref = 1;
370 IVectorView_HSTRING_AddRef((iter->view = &impl->IVectorView_HSTRING_iface));
371 iter->size = impl->count;
373 *value = &iter->IIterator_HSTRING_iface;
374 return S_OK;
377 static const struct IIterable_HSTRINGVtbl iterable_view_hstring_vtbl =
379 /* IUnknown methods */
380 iterable_view_hstring_QueryInterface,
381 iterable_view_hstring_AddRef,
382 iterable_view_hstring_Release,
383 /* IInspectable methods */
384 iterable_view_hstring_GetIids,
385 iterable_view_hstring_GetRuntimeClassName,
386 iterable_view_hstring_GetTrustLevel,
387 /* IIterable<HSTRING> methods */
388 iterable_view_hstring_First,
391 struct windows_globalization
393 IActivationFactory IActivationFactory_iface;
394 IGlobalizationPreferencesStatics IGlobalizationPreferencesStatics_iface;
395 LONG ref;
398 struct language_factory
400 IActivationFactory IActivationFactory_iface;
401 ILanguageFactory ILanguageFactory_iface;
402 LONG ref;
405 struct language
407 ILanguage ILanguage_iface;
408 LONG ref;
409 WCHAR name[LOCALE_NAME_MAX_LENGTH];
412 static inline struct windows_globalization *impl_from_IActivationFactory(IActivationFactory *iface)
414 return CONTAINING_RECORD(iface, struct windows_globalization, IActivationFactory_iface);
417 static inline struct language_factory *impl_language_factory_from_IActivationFactory(IActivationFactory *iface)
419 return CONTAINING_RECORD(iface, struct language_factory, IActivationFactory_iface);
422 static inline struct windows_globalization *impl_from_IGlobalizationPreferencesStatics(IGlobalizationPreferencesStatics *iface)
424 return CONTAINING_RECORD(iface, struct windows_globalization, IGlobalizationPreferencesStatics_iface);
427 static inline struct language_factory *impl_from_ILanguageFactory(ILanguageFactory *iface)
429 return CONTAINING_RECORD(iface, struct language_factory, ILanguageFactory_iface);
432 static inline struct language *impl_from_ILanguage(ILanguage *iface)
434 return CONTAINING_RECORD(iface, struct language, ILanguage_iface);
437 static HRESULT STDMETHODCALLTYPE language_QueryInterface(
438 ILanguage *iface, REFIID iid, void **out)
440 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
442 if (IsEqualGUID(iid, &IID_IUnknown) ||
443 IsEqualGUID(iid, &IID_IInspectable) ||
444 IsEqualGUID(iid, &IID_IAgileObject) ||
445 IsEqualGUID(iid, &IID_ILanguage))
447 IUnknown_AddRef(iface);
448 *out = iface;
449 return S_OK;
452 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
453 *out = NULL;
454 return E_NOINTERFACE;
457 static ULONG STDMETHODCALLTYPE language_AddRef(
458 ILanguage *iface)
460 struct language *language = impl_from_ILanguage(iface);
461 ULONG ref = InterlockedIncrement(&language->ref);
462 TRACE("iface %p, ref %lu.\n", iface, ref);
463 return ref;
466 static ULONG STDMETHODCALLTYPE language_Release(
467 ILanguage *iface)
469 struct language *language = impl_from_ILanguage(iface);
470 ULONG ref = InterlockedDecrement(&language->ref);
472 TRACE("iface %p, ref %lu.\n", iface, ref);
474 if (!ref)
475 free(language);
477 return ref;
480 static HRESULT STDMETHODCALLTYPE language_GetIids(
481 ILanguage *iface, ULONG *iid_count, IID **iids)
483 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
484 return E_NOTIMPL;
487 static HRESULT STDMETHODCALLTYPE language_GetRuntimeClassName(
488 ILanguage *iface, HSTRING *class_name)
490 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
491 return E_NOTIMPL;
494 static HRESULT STDMETHODCALLTYPE language_GetTrustLevel(
495 ILanguage *iface, TrustLevel *trust_level)
497 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
498 return E_NOTIMPL;
501 static HRESULT STDMETHODCALLTYPE language_get_LanguageTag(
502 ILanguage *iface, HSTRING *value)
504 struct language *language = impl_from_ILanguage(iface);
506 TRACE("iface %p, value %p.\n", iface, value);
508 return WindowsCreateString(language->name, wcslen(language->name), value);
511 static HRESULT STDMETHODCALLTYPE language_get_DisplayName(
512 ILanguage *iface, HSTRING *value)
514 FIXME("iface %p, value %p stub!\n", iface, value);
515 return E_NOTIMPL;
518 static HRESULT STDMETHODCALLTYPE language_get_NativeName(
519 ILanguage *iface, HSTRING *value)
521 FIXME("iface %p, value %p stub!\n", iface, value);
522 return E_NOTIMPL;
525 static HRESULT STDMETHODCALLTYPE language_get_Script(
526 ILanguage *iface, HSTRING *value)
528 FIXME("iface %p, value %p stub!\n", iface, value);
529 return E_NOTIMPL;
532 static const struct ILanguageVtbl language_vtbl =
534 language_QueryInterface,
535 language_AddRef,
536 language_Release,
537 /* IInspectable methods */
538 language_GetIids,
539 language_GetRuntimeClassName,
540 language_GetTrustLevel,
541 /* ILanguage methods */
542 language_get_LanguageTag,
543 language_get_DisplayName,
544 language_get_NativeName,
545 language_get_Script,
548 static HRESULT STDMETHODCALLTYPE windows_globalization_QueryInterface(
549 IActivationFactory *iface, REFIID iid, void **out)
551 struct windows_globalization *impl = impl_from_IActivationFactory(iface);
552 TRACE("iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out);
554 if (IsEqualGUID(iid, &IID_IUnknown) ||
555 IsEqualGUID(iid, &IID_IInspectable) ||
556 IsEqualGUID(iid, &IID_IAgileObject) ||
557 IsEqualGUID(iid, &IID_IActivationFactory))
559 IUnknown_AddRef(iface);
560 *out = &impl->IActivationFactory_iface;
561 return S_OK;
564 if (IsEqualGUID(iid, &IID_IGlobalizationPreferencesStatics))
566 IUnknown_AddRef(iface);
567 *out = &impl->IGlobalizationPreferencesStatics_iface;
568 return S_OK;
571 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
572 *out = NULL;
573 return E_NOINTERFACE;
576 static ULONG STDMETHODCALLTYPE windows_globalization_AddRef(
577 IActivationFactory *iface)
579 struct windows_globalization *impl = impl_from_IActivationFactory(iface);
580 ULONG ref = InterlockedIncrement(&impl->ref);
581 TRACE("iface %p, ref %lu.\n", iface, ref);
582 return ref;
585 static ULONG STDMETHODCALLTYPE windows_globalization_Release(
586 IActivationFactory *iface)
588 struct windows_globalization *impl = impl_from_IActivationFactory(iface);
589 ULONG ref = InterlockedDecrement(&impl->ref);
590 TRACE("iface %p, ref %lu.\n", iface, ref);
591 return ref;
594 static HRESULT STDMETHODCALLTYPE windows_globalization_GetIids(
595 IActivationFactory *iface, ULONG *iid_count, IID **iids)
597 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
598 return E_NOTIMPL;
601 static HRESULT STDMETHODCALLTYPE windows_globalization_GetRuntimeClassName(
602 IActivationFactory *iface, HSTRING *class_name)
604 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
605 return E_NOTIMPL;
608 static HRESULT STDMETHODCALLTYPE windows_globalization_GetTrustLevel(
609 IActivationFactory *iface, TrustLevel *trust_level)
611 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
612 return E_NOTIMPL;
615 static HRESULT STDMETHODCALLTYPE windows_globalization_ActivateInstance(
616 IActivationFactory *iface, IInspectable **instance)
618 FIXME("iface %p, instance %p stub!\n", iface, instance);
619 return E_NOTIMPL;
622 static const struct IActivationFactoryVtbl activation_factory_vtbl =
624 windows_globalization_QueryInterface,
625 windows_globalization_AddRef,
626 windows_globalization_Release,
627 /* IInspectable methods */
628 windows_globalization_GetIids,
629 windows_globalization_GetRuntimeClassName,
630 windows_globalization_GetTrustLevel,
631 /* IActivationFactory methods */
632 windows_globalization_ActivateInstance,
635 static HRESULT STDMETHODCALLTYPE globalization_preferences_QueryInterface(
636 IGlobalizationPreferencesStatics *iface, REFIID iid, void **object)
638 struct windows_globalization *impl = impl_from_IGlobalizationPreferencesStatics(iface);
639 return windows_globalization_QueryInterface(&impl->IActivationFactory_iface, iid, object);
642 static ULONG STDMETHODCALLTYPE globalization_preferences_AddRef(
643 IGlobalizationPreferencesStatics *iface)
645 struct windows_globalization *impl = impl_from_IGlobalizationPreferencesStatics(iface);
646 return windows_globalization_AddRef(&impl->IActivationFactory_iface);
649 static ULONG STDMETHODCALLTYPE globalization_preferences_Release(
650 IGlobalizationPreferencesStatics *iface)
652 struct windows_globalization *impl = impl_from_IGlobalizationPreferencesStatics(iface);
653 return windows_globalization_Release(&impl->IActivationFactory_iface);
656 static HRESULT STDMETHODCALLTYPE globalization_preferences_GetIids(
657 IGlobalizationPreferencesStatics *iface, ULONG *iid_count, IID **iids)
659 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
660 return E_NOTIMPL;
663 static HRESULT STDMETHODCALLTYPE globalization_preferences_GetRuntimeClassName(
664 IGlobalizationPreferencesStatics *iface, HSTRING *class_name)
666 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
667 return E_NOTIMPL;
670 static HRESULT STDMETHODCALLTYPE globalization_preferences_GetTrustLevel(
671 IGlobalizationPreferencesStatics *iface, TrustLevel *trust_level)
673 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
674 return E_NOTIMPL;
677 static HRESULT STDMETHODCALLTYPE globalization_preferences_get_Calendars(
678 IGlobalizationPreferencesStatics *iface, IVectorView_HSTRING **out)
680 FIXME("iface %p, out %p stub!\n", iface, out);
681 return hstring_vector_create(NULL, 0, out);
684 static HRESULT STDMETHODCALLTYPE globalization_preferences_get_Clocks(
685 IGlobalizationPreferencesStatics *iface, IVectorView_HSTRING **out)
687 FIXME("iface %p, out %p stub!\n", iface, out);
688 return hstring_vector_create(NULL, 0, out);
691 static HRESULT STDMETHODCALLTYPE globalization_preferences_get_Currencies(
692 IGlobalizationPreferencesStatics *iface, IVectorView_HSTRING **out)
694 FIXME("iface %p, out %p stub!\n", iface, out);
695 return hstring_vector_create(NULL, 0, out);
698 static HRESULT STDMETHODCALLTYPE globalization_preferences_get_Languages(
699 IGlobalizationPreferencesStatics *iface, IVectorView_HSTRING **out)
701 HSTRING hstring;
702 HRESULT hr;
703 WCHAR locale[LOCALE_NAME_MAX_LENGTH];
705 TRACE("iface %p, out %p.\n", iface, out);
707 if (!GetUserDefaultLocaleName(locale, LOCALE_NAME_MAX_LENGTH))
708 return E_FAIL;
710 TRACE("returning language %s\n", debugstr_w(locale));
712 if (FAILED(hr = WindowsCreateString(locale, wcslen(locale), &hstring)))
713 return hr;
715 return hstring_vector_create(&hstring, 1, out);
718 static HRESULT STDMETHODCALLTYPE globalization_preferences_get_HomeGeographicRegion(
719 IGlobalizationPreferencesStatics *iface, HSTRING* out)
721 WCHAR country[16];
723 TRACE("iface %p, out %p.\n", iface, out);
725 if (!GetUserDefaultGeoName(country, 16))
726 return E_FAIL;
728 TRACE("returning country %s\n", debugstr_w(country));
730 return WindowsCreateString(country, wcslen(country), out);
733 static HRESULT STDMETHODCALLTYPE globalization_preferences_get_WeekStartsOn(
734 IGlobalizationPreferencesStatics *iface, enum DayOfWeek* out)
736 FIXME("iface %p, out %p stub!\n", iface, out);
737 return E_NOTIMPL;
740 static const struct IGlobalizationPreferencesStaticsVtbl globalization_preferences_vtbl =
742 globalization_preferences_QueryInterface,
743 globalization_preferences_AddRef,
744 globalization_preferences_Release,
745 /* IInspectable methods */
746 globalization_preferences_GetIids,
747 globalization_preferences_GetRuntimeClassName,
748 globalization_preferences_GetTrustLevel,
749 /* IGlobalizationPreferencesStatics methods */
750 globalization_preferences_get_Calendars,
751 globalization_preferences_get_Clocks,
752 globalization_preferences_get_Currencies,
753 globalization_preferences_get_Languages,
754 globalization_preferences_get_HomeGeographicRegion,
755 globalization_preferences_get_WeekStartsOn,
758 static struct windows_globalization userprofile_preferences =
760 {&activation_factory_vtbl},
761 {&globalization_preferences_vtbl},
765 static HRESULT STDMETHODCALLTYPE windows_globalization_language_factory_QueryInterface(
766 IActivationFactory *iface, REFIID iid, void **out)
768 struct language_factory *factory = impl_language_factory_from_IActivationFactory(iface);
770 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
772 if (IsEqualGUID(iid, &IID_IUnknown) ||
773 IsEqualGUID(iid, &IID_IInspectable) ||
774 IsEqualGUID(iid, &IID_IAgileObject) ||
775 IsEqualGUID(iid, &IID_IActivationFactory))
777 IUnknown_AddRef(iface);
778 *out = iface;
779 return S_OK;
782 if (IsEqualGUID(iid, &IID_ILanguageFactory))
784 IUnknown_AddRef(iface);
785 *out = &factory->ILanguageFactory_iface;
786 return S_OK;
789 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
790 *out = NULL;
791 return E_NOINTERFACE;
794 static ULONG STDMETHODCALLTYPE windows_globalization_language_factory_AddRef(IActivationFactory *iface)
796 struct language_factory *factory = impl_language_factory_from_IActivationFactory(iface);
797 return InterlockedIncrement(&factory->ref);
800 static ULONG STDMETHODCALLTYPE windows_globalization_language_factory_Release(IActivationFactory *iface)
802 struct language_factory *factory = impl_language_factory_from_IActivationFactory(iface);
803 return InterlockedDecrement(&factory->ref);
806 static const struct IActivationFactoryVtbl activation_factory_language_vtbl =
808 windows_globalization_language_factory_QueryInterface,
809 windows_globalization_language_factory_AddRef,
810 windows_globalization_language_factory_Release,
811 /* IInspectable methods */
812 windows_globalization_GetIids,
813 windows_globalization_GetRuntimeClassName,
814 windows_globalization_GetTrustLevel,
815 /* IActivationFactory methods */
816 windows_globalization_ActivateInstance,
819 static HRESULT STDMETHODCALLTYPE language_factory_QueryInterface(
820 ILanguageFactory *iface, REFIID iid, void **object)
822 struct language_factory *factory = impl_from_ILanguageFactory(iface);
823 return IActivationFactory_QueryInterface(&factory->IActivationFactory_iface, iid, object);
826 static ULONG STDMETHODCALLTYPE language_factory_AddRef(
827 ILanguageFactory *iface)
829 struct language_factory *factory = impl_from_ILanguageFactory(iface);
830 return IActivationFactory_AddRef(&factory->IActivationFactory_iface);
833 static ULONG STDMETHODCALLTYPE language_factory_Release(
834 ILanguageFactory *iface)
836 struct language_factory *factory = impl_from_ILanguageFactory(iface);
837 return IActivationFactory_Release(&factory->IActivationFactory_iface);
840 static HRESULT STDMETHODCALLTYPE language_factory_GetIids(
841 ILanguageFactory *iface, ULONG *iid_count, IID **iids)
843 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
844 return E_NOTIMPL;
847 static HRESULT STDMETHODCALLTYPE language_factory_GetRuntimeClassName(
848 ILanguageFactory *iface, HSTRING *class_name)
850 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
851 return E_NOTIMPL;
854 static HRESULT STDMETHODCALLTYPE language_factory_GetTrustLevel(
855 ILanguageFactory *iface, TrustLevel *trust_level)
857 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
858 return E_NOTIMPL;
861 static HRESULT STDMETHODCALLTYPE language_factory_CreateLanguage(
862 ILanguageFactory *iface, HSTRING tag, ILanguage **value)
864 const WCHAR *name = WindowsGetStringRawBuffer(tag, NULL);
865 WCHAR buffer[LOCALE_NAME_MAX_LENGTH];
866 struct language *language;
868 TRACE("iface %p, tag %p, value %p.\n", iface, tag, value);
870 if (!GetLocaleInfoEx(name, LOCALE_SNAME, buffer, ARRAY_SIZE(buffer)))
871 return E_INVALIDARG;
873 if (!(language = calloc(1, sizeof(*language))))
874 return E_OUTOFMEMORY;
876 language->ILanguage_iface.lpVtbl = &language_vtbl;
877 language->ref = 1;
878 wcscpy(language->name, buffer);
880 *value = &language->ILanguage_iface;
882 return S_OK;
885 static const struct ILanguageFactoryVtbl language_factory_vtbl =
887 language_factory_QueryInterface,
888 language_factory_AddRef,
889 language_factory_Release,
890 /* IInspectable methods */
891 language_factory_GetIids,
892 language_factory_GetRuntimeClassName,
893 language_factory_GetTrustLevel,
894 /* ILanguageFactory methods */
895 language_factory_CreateLanguage,
898 static struct language_factory language_factory =
900 {&activation_factory_language_vtbl},
901 {&language_factory_vtbl},
905 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out)
907 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out);
908 return CLASS_E_CLASSNOTAVAILABLE;
911 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
913 const WCHAR *name = WindowsGetStringRawBuffer(classid, NULL);
915 TRACE("classid %s, factory %p.\n", debugstr_hstring(classid), factory);
917 *factory = NULL;
919 if (!wcscmp(name, RuntimeClass_Windows_System_UserProfile_GlobalizationPreferences))
921 *factory = &userprofile_preferences.IActivationFactory_iface;
922 IUnknown_AddRef(*factory);
924 else if (!wcscmp(name, RuntimeClass_Windows_Globalization_Language))
926 *factory = &language_factory.IActivationFactory_iface;
927 IUnknown_AddRef(*factory);
929 else if (!wcscmp(name, RuntimeClass_Windows_Globalization_GeographicRegion))
931 *factory = geographic_region_factory;
932 IUnknown_AddRef(*factory);
935 if (*factory) return S_OK;
936 return CLASS_E_CLASSNOTAVAILABLE;