The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. namespace VariantHelpers
  21. {
  22. namespace Detail
  23. {
  24. template <typename Fn, typename ValueType>
  25. inline VARIANT getWithValueGeneric (Fn&& setter, ValueType value)
  26. {
  27. VARIANT result{};
  28. setter (value, &result);
  29. return result;
  30. }
  31. }
  32. inline void clear (VARIANT* variant)
  33. {
  34. variant->vt = VT_EMPTY;
  35. }
  36. inline void setInt (int value, VARIANT* variant)
  37. {
  38. variant->vt = VT_I4;
  39. variant->lVal = value;
  40. }
  41. inline void setBool (bool value, VARIANT* variant)
  42. {
  43. variant->vt = VT_BOOL;
  44. variant->boolVal = value ? -1 : 0;
  45. }
  46. inline void setString (const String& value, VARIANT* variant)
  47. {
  48. variant->vt = VT_BSTR;
  49. variant->bstrVal = SysAllocString ((const OLECHAR*) value.toWideCharPointer());
  50. }
  51. inline void setDouble (double value, VARIANT* variant)
  52. {
  53. variant->vt = VT_R8;
  54. variant->dblVal = value;
  55. }
  56. inline VARIANT getWithValue (double value) { return Detail::getWithValueGeneric (&setDouble, value); }
  57. inline VARIANT getWithValue (const String& value) { return Detail::getWithValueGeneric (&setString, value); }
  58. }
  59. inline JUCE_COMRESULT addHandlersToArray (const std::vector<const AccessibilityHandler*>& handlers, SAFEARRAY** pRetVal)
  60. {
  61. auto numHandlers = handlers.size();
  62. *pRetVal = SafeArrayCreateVector (VT_UNKNOWN, 0, (ULONG) numHandlers);
  63. if (pRetVal != nullptr)
  64. {
  65. for (LONG i = 0; i < (LONG) numHandlers; ++i)
  66. {
  67. auto* handler = handlers[(size_t) i];
  68. if (handler == nullptr)
  69. continue;
  70. ComSmartPtr<IRawElementProviderSimple> provider;
  71. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wlanguage-extension-token")
  72. handler->getNativeImplementation()->QueryInterface (IID_PPV_ARGS (provider.resetAndGetPointerAddress()));
  73. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  74. auto hr = SafeArrayPutElement (*pRetVal, &i, provider);
  75. if (FAILED (hr))
  76. return E_FAIL;
  77. }
  78. }
  79. return S_OK;
  80. }
  81. template <typename Value, typename Object, typename Callback>
  82. inline JUCE_COMRESULT withCheckedComArgs (Value* pRetVal, Object& handle, Callback&& callback)
  83. {
  84. if (pRetVal == nullptr)
  85. return E_INVALIDARG;
  86. *pRetVal = Value{};
  87. if (! handle.isElementValid())
  88. return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
  89. return callback();
  90. }
  91. } // namespace juce