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.

99 lines
2.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. namespace VariantHelpers
  16. {
  17. inline void clear (VARIANT* variant)
  18. {
  19. variant->vt = VT_EMPTY;
  20. }
  21. inline void setInt (int value, VARIANT* variant)
  22. {
  23. variant->vt = VT_I4;
  24. variant->lVal = value;
  25. }
  26. inline void setBool (bool value, VARIANT* variant)
  27. {
  28. variant->vt = VT_BOOL;
  29. variant->boolVal = value ? -1 : 0;
  30. }
  31. inline void setString (const String& value, VARIANT* variant)
  32. {
  33. variant->vt = VT_BSTR;
  34. variant->bstrVal = SysAllocString ((const OLECHAR*) value.toWideCharPointer());
  35. }
  36. inline void setDouble (double value, VARIANT* variant)
  37. {
  38. variant->vt = VT_R8;
  39. variant->dblVal = value;
  40. }
  41. }
  42. inline JUCE_COMRESULT addHandlersToArray (const std::vector<const AccessibilityHandler*>& handlers, SAFEARRAY** pRetVal)
  43. {
  44. auto numHandlers = handlers.size();
  45. *pRetVal = SafeArrayCreateVector (VT_UNKNOWN, 0, (ULONG) numHandlers);
  46. if (pRetVal != nullptr)
  47. {
  48. for (LONG i = 0; i < (LONG) numHandlers; ++i)
  49. {
  50. auto* handler = handlers[(size_t) i];
  51. if (handler == nullptr)
  52. continue;
  53. ComSmartPtr<IRawElementProviderSimple> provider;
  54. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wlanguage-extension-token")
  55. handler->getNativeImplementation()->QueryInterface (IID_PPV_ARGS (provider.resetAndGetPointerAddress()));
  56. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  57. auto hr = SafeArrayPutElement (*pRetVal, &i, provider);
  58. if (FAILED (hr))
  59. return E_FAIL;
  60. }
  61. }
  62. return S_OK;
  63. }
  64. template <typename Value, typename Object, typename Callback>
  65. inline JUCE_COMRESULT withCheckedComArgs (Value* pRetVal, Object& handle, Callback&& callback)
  66. {
  67. if (pRetVal == nullptr)
  68. return E_INVALIDARG;
  69. *pRetVal = Value{};
  70. if (! handle.isElementValid())
  71. return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
  72. return callback();
  73. }
  74. } // namespace juce