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.

198 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. //==============================================================================
  21. class UIAWindowProvider : public UIAProviderBase,
  22. public ComBaseClassHelper<IWindowProvider>
  23. {
  24. public:
  25. explicit UIAWindowProvider (AccessibilityNativeHandle* nativeHandle)
  26. : UIAProviderBase (nativeHandle)
  27. {
  28. }
  29. //==============================================================================
  30. JUCE_COMRESULT SetVisualState (WindowVisualState state) override
  31. {
  32. if (! isElementValid())
  33. return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
  34. if (auto* peer = getPeer())
  35. {
  36. switch (state)
  37. {
  38. case WindowVisualState_Maximized:
  39. peer->setFullScreen (true);
  40. break;
  41. case WindowVisualState_Minimized:
  42. peer->setMinimised (true);
  43. break;
  44. case WindowVisualState_Normal:
  45. peer->setFullScreen (false);
  46. peer->setMinimised (false);
  47. break;
  48. default:
  49. break;
  50. }
  51. return S_OK;
  52. }
  53. return (HRESULT) UIA_E_NOTSUPPORTED;
  54. }
  55. JUCE_COMRESULT Close() override
  56. {
  57. if (! isElementValid())
  58. return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
  59. if (auto* peer = getPeer())
  60. {
  61. peer->handleUserClosingWindow();
  62. return S_OK;
  63. }
  64. return (HRESULT) UIA_E_NOTSUPPORTED;
  65. }
  66. JUCE_COMRESULT WaitForInputIdle (int, BOOL* pRetVal) override
  67. {
  68. return withCheckedComArgs (pRetVal, *this, []
  69. {
  70. return (HRESULT) UIA_E_NOTSUPPORTED;
  71. });
  72. }
  73. JUCE_COMRESULT get_CanMaximize (BOOL* pRetVal) override
  74. {
  75. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  76. {
  77. if (auto* peer = getPeer())
  78. {
  79. *pRetVal = (peer->getStyleFlags() & ComponentPeer::windowHasMaximiseButton) != 0;
  80. return S_OK;
  81. }
  82. return (HRESULT) UIA_E_NOTSUPPORTED;
  83. });
  84. }
  85. JUCE_COMRESULT get_CanMinimize (BOOL* pRetVal) override
  86. {
  87. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  88. {
  89. if (auto* peer = getPeer())
  90. {
  91. *pRetVal = (peer->getStyleFlags() & ComponentPeer::windowHasMinimiseButton) != 0;
  92. return S_OK;
  93. }
  94. return (HRESULT) UIA_E_NOTSUPPORTED;
  95. });
  96. }
  97. JUCE_COMRESULT get_IsModal (BOOL* pRetVal) override
  98. {
  99. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  100. {
  101. if (auto* peer = getPeer())
  102. {
  103. *pRetVal = peer->getComponent().isCurrentlyModal();
  104. return S_OK;
  105. }
  106. return (HRESULT) UIA_E_NOTSUPPORTED;
  107. });
  108. }
  109. JUCE_COMRESULT get_WindowVisualState (WindowVisualState* pRetVal) override
  110. {
  111. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  112. {
  113. if (auto* peer = getPeer())
  114. {
  115. if (peer->isFullScreen())
  116. *pRetVal = WindowVisualState_Maximized;
  117. else if (peer->isMinimised())
  118. *pRetVal = WindowVisualState_Minimized;
  119. else
  120. *pRetVal = WindowVisualState_Normal;
  121. return S_OK;
  122. }
  123. return (HRESULT) UIA_E_NOTSUPPORTED;
  124. });
  125. }
  126. JUCE_COMRESULT get_WindowInteractionState (WindowInteractionState* pRetVal) override
  127. {
  128. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  129. {
  130. if (auto* peer = getPeer())
  131. {
  132. *pRetVal = peer->getComponent().isCurrentlyBlockedByAnotherModalComponent()
  133. ? WindowInteractionState::WindowInteractionState_BlockedByModalWindow
  134. : WindowInteractionState::WindowInteractionState_Running;
  135. return S_OK;
  136. }
  137. return (HRESULT) UIA_E_NOTSUPPORTED;
  138. });
  139. }
  140. JUCE_COMRESULT get_IsTopmost (BOOL* pRetVal) override
  141. {
  142. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  143. {
  144. if (auto* peer = getPeer())
  145. {
  146. *pRetVal = peer->isFocused();
  147. return S_OK;
  148. }
  149. return (HRESULT) UIA_E_NOTSUPPORTED;
  150. });
  151. }
  152. private:
  153. ComponentPeer* getPeer() const
  154. {
  155. return getHandler().getComponent().getPeer();
  156. }
  157. //==============================================================================
  158. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIAWindowProvider)
  159. };
  160. } // namespace juce