Audio plugin host https://kx.studio/carla
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.

juce_gui_basics.cpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. #ifdef JUCE_GUI_BASICS_H_INCLUDED
  19. /* When you add this cpp file to your project, you mustn't include it in a file where you've
  20. already included any other headers - just put it inside a file on its own, possibly with your config
  21. flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
  22. header files that the compiler may be using.
  23. */
  24. #error "Incorrect use of JUCE cpp file"
  25. #endif
  26. #define NS_FORMAT_FUNCTION(F,A) // To avoid spurious warnings from GCC
  27. #define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
  28. #define JUCE_CORE_INCLUDE_COM_SMART_PTR 1
  29. #define JUCE_CORE_INCLUDE_JNI_HELPERS 1
  30. #define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1
  31. #define JUCE_EVENTS_INCLUDE_WIN32_MESSAGE_WINDOW 1
  32. #define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1
  33. #define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1
  34. #define JUCE_GUI_BASICS_INCLUDE_SCOPED_THREAD_DPI_AWARENESS_SETTER 1
  35. #include "juce_gui_basics.h"
  36. #include <cctype>
  37. //==============================================================================
  38. #if JUCE_MAC
  39. #import <WebKit/WebKit.h>
  40. #import <IOKit/pwr_mgt/IOPMLib.h>
  41. #import <MetalKit/MetalKit.h>
  42. #elif JUCE_IOS
  43. #if JUCE_PUSH_NOTIFICATIONS && defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  44. #import <UserNotifications/UserNotifications.h>
  45. #endif
  46. #import <MetalKit/MetalKit.h>
  47. #import <UIKit/UIActivityViewController.h>
  48. //==============================================================================
  49. #elif JUCE_WINDOWS
  50. #include <windowsx.h>
  51. #include <vfw.h>
  52. #include <commdlg.h>
  53. #include <commctrl.h>
  54. #include <sapi.h>
  55. #if JUCE_MSVC
  56. #include <Dxgi.h>
  57. #include <UIAutomation.h>
  58. #endif
  59. #if JUCE_WEB_BROWSER
  60. #include <exdisp.h>
  61. #include <exdispid.h>
  62. #endif
  63. #if JUCE_MINGW
  64. #include <imm.h>
  65. #elif ! JUCE_DONT_AUTOLINK_TO_WIN32_LIBRARIES
  66. #pragma comment(lib, "vfw32.lib")
  67. #pragma comment(lib, "imm32.lib")
  68. #pragma comment(lib, "comctl32.lib")
  69. #pragma comment(lib, "dxgi.lib")
  70. #if JUCE_OPENGL
  71. #pragma comment(lib, "OpenGL32.Lib")
  72. #pragma comment(lib, "GlU32.Lib")
  73. #endif
  74. #if JUCE_DIRECT2D
  75. #pragma comment (lib, "Dwrite.lib")
  76. #pragma comment (lib, "D2d1.lib")
  77. #endif
  78. #endif
  79. #endif
  80. //==============================================================================
  81. #define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN \
  82. jassert ((MessageManager::getInstanceWithoutCreating() != nullptr \
  83. && MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager()) \
  84. || getPeer() == nullptr);
  85. namespace juce
  86. {
  87. bool juce_areThereAnyAlwaysOnTopWindows();
  88. bool isEmbeddedInForegroundProcess (Component* c);
  89. #if ! JUCE_WINDOWS
  90. bool isEmbeddedInForegroundProcess (Component*) { return false; }
  91. #endif
  92. /* Returns true if this process is in the foreground, or if the viewComponent
  93. is embedded into a window owned by the foreground process.
  94. */
  95. static bool isForegroundOrEmbeddedProcess (Component* viewComponent)
  96. {
  97. return Process::isForegroundProcess() || isEmbeddedInForegroundProcess (viewComponent);
  98. }
  99. bool isWindowOnCurrentVirtualDesktop (void*);
  100. struct CustomMouseCursorInfo
  101. {
  102. ScaledImage image;
  103. Point<int> hotspot;
  104. };
  105. } // namespace juce
  106. #include "mouse/juce_PointerState.h"
  107. #include "accessibility/juce_AccessibilityHandler.cpp"
  108. #include "components/juce_Component.cpp"
  109. #include "components/juce_ComponentListener.cpp"
  110. #include "components/juce_FocusTraverser.cpp"
  111. #include "mouse/juce_MouseInputSource.cpp"
  112. #include "desktop/juce_Displays.cpp"
  113. #include "desktop/juce_Desktop.cpp"
  114. #include "components/juce_ModalComponentManager.cpp"
  115. #include "mouse/juce_ComponentDragger.cpp"
  116. #include "mouse/juce_DragAndDropContainer.cpp"
  117. #include "mouse/juce_MouseEvent.cpp"
  118. #include "mouse/juce_MouseInactivityDetector.cpp"
  119. #include "mouse/juce_MouseListener.cpp"
  120. #include "keyboard/juce_CaretComponent.cpp"
  121. #include "keyboard/juce_KeyboardFocusTraverser.cpp"
  122. #include "keyboard/juce_KeyListener.cpp"
  123. #include "keyboard/juce_KeyPress.cpp"
  124. #include "keyboard/juce_ModifierKeys.cpp"
  125. #include "buttons/juce_ArrowButton.cpp"
  126. #include "buttons/juce_Button.cpp"
  127. #include "buttons/juce_DrawableButton.cpp"
  128. #include "buttons/juce_HyperlinkButton.cpp"
  129. #include "buttons/juce_ImageButton.cpp"
  130. #include "buttons/juce_ShapeButton.cpp"
  131. #include "buttons/juce_TextButton.cpp"
  132. #include "buttons/juce_ToggleButton.cpp"
  133. #include "buttons/juce_ToolbarButton.cpp"
  134. #include "drawables/juce_Drawable.cpp"
  135. #include "drawables/juce_DrawableComposite.cpp"
  136. #include "drawables/juce_DrawableImage.cpp"
  137. #include "drawables/juce_DrawablePath.cpp"
  138. #include "drawables/juce_DrawableRectangle.cpp"
  139. #include "drawables/juce_DrawableShape.cpp"
  140. #include "drawables/juce_DrawableText.cpp"
  141. #include "drawables/juce_SVGParser.cpp"
  142. #include "filebrowser/juce_DirectoryContentsDisplayComponent.cpp"
  143. #include "filebrowser/juce_DirectoryContentsList.cpp"
  144. #include "filebrowser/juce_FileBrowserComponent.cpp"
  145. #include "filebrowser/juce_FileChooser.cpp"
  146. #include "filebrowser/juce_FileChooserDialogBox.cpp"
  147. #include "filebrowser/juce_FileListComponent.cpp"
  148. #include "filebrowser/juce_FilenameComponent.cpp"
  149. #include "filebrowser/juce_FileSearchPathListComponent.cpp"
  150. #include "filebrowser/juce_FileTreeComponent.cpp"
  151. #include "filebrowser/juce_ImagePreviewComponent.cpp"
  152. #include "filebrowser/juce_ContentSharer.cpp"
  153. #include "layout/juce_ComponentAnimator.cpp"
  154. #include "layout/juce_ComponentBoundsConstrainer.cpp"
  155. #include "layout/juce_ComponentBuilder.cpp"
  156. #include "layout/juce_ComponentMovementWatcher.cpp"
  157. #include "layout/juce_ConcertinaPanel.cpp"
  158. #include "layout/juce_GroupComponent.cpp"
  159. #include "layout/juce_MultiDocumentPanel.cpp"
  160. #include "layout/juce_ResizableBorderComponent.cpp"
  161. #include "layout/juce_ResizableCornerComponent.cpp"
  162. #include "layout/juce_ResizableEdgeComponent.cpp"
  163. #include "layout/juce_ScrollBar.cpp"
  164. #include "layout/juce_SidePanel.cpp"
  165. #include "layout/juce_StretchableLayoutManager.cpp"
  166. #include "layout/juce_StretchableLayoutResizerBar.cpp"
  167. #include "layout/juce_StretchableObjectResizer.cpp"
  168. #include "layout/juce_TabbedButtonBar.cpp"
  169. #include "layout/juce_TabbedComponent.cpp"
  170. #include "layout/juce_Viewport.cpp"
  171. #include "lookandfeel/juce_LookAndFeel.cpp"
  172. #include "lookandfeel/juce_LookAndFeel_V2.cpp"
  173. #include "lookandfeel/juce_LookAndFeel_V1.cpp"
  174. #include "lookandfeel/juce_LookAndFeel_V3.cpp"
  175. #include "lookandfeel/juce_LookAndFeel_V4.cpp"
  176. #include "menus/juce_MenuBarComponent.cpp"
  177. #include "menus/juce_BurgerMenuComponent.cpp"
  178. #include "menus/juce_MenuBarModel.cpp"
  179. #include "menus/juce_PopupMenu.cpp"
  180. #include "positioning/juce_MarkerList.cpp"
  181. #include "positioning/juce_RelativeCoordinate.cpp"
  182. #include "positioning/juce_RelativeCoordinatePositioner.cpp"
  183. #include "positioning/juce_RelativeParallelogram.cpp"
  184. #include "positioning/juce_RelativePoint.cpp"
  185. #include "positioning/juce_RelativePointPath.cpp"
  186. #include "positioning/juce_RelativeRectangle.cpp"
  187. #include "properties/juce_BooleanPropertyComponent.cpp"
  188. #include "properties/juce_ButtonPropertyComponent.cpp"
  189. #include "properties/juce_ChoicePropertyComponent.cpp"
  190. #include "properties/juce_PropertyComponent.cpp"
  191. #include "properties/juce_PropertyPanel.cpp"
  192. #include "properties/juce_SliderPropertyComponent.cpp"
  193. #include "properties/juce_TextPropertyComponent.cpp"
  194. #include "properties/juce_MultiChoicePropertyComponent.cpp"
  195. #include "widgets/juce_ComboBox.cpp"
  196. #include "widgets/juce_ImageComponent.cpp"
  197. #include "widgets/juce_Label.cpp"
  198. #include "widgets/juce_ListBox.cpp"
  199. #include "widgets/juce_ProgressBar.cpp"
  200. #include "widgets/juce_Slider.cpp"
  201. #include "widgets/juce_TableHeaderComponent.cpp"
  202. #include "widgets/juce_TableListBox.cpp"
  203. #include "widgets/juce_TextEditor.cpp"
  204. #include "widgets/juce_ToolbarItemComponent.cpp"
  205. #include "widgets/juce_Toolbar.cpp"
  206. #include "widgets/juce_ToolbarItemPalette.cpp"
  207. #include "widgets/juce_TreeView.cpp"
  208. #include "windows/juce_AlertWindow.cpp"
  209. #include "windows/juce_CallOutBox.cpp"
  210. #include "windows/juce_ComponentPeer.cpp"
  211. #include "windows/juce_DialogWindow.cpp"
  212. #include "windows/juce_DocumentWindow.cpp"
  213. #include "windows/juce_ResizableWindow.cpp"
  214. #include "windows/juce_ThreadWithProgressWindow.cpp"
  215. #include "windows/juce_TooltipWindow.cpp"
  216. #include "windows/juce_TopLevelWindow.cpp"
  217. #include "commands/juce_ApplicationCommandInfo.cpp"
  218. #include "commands/juce_ApplicationCommandManager.cpp"
  219. #include "commands/juce_ApplicationCommandTarget.cpp"
  220. #include "commands/juce_KeyPressMappingSet.cpp"
  221. #include "application/juce_Application.cpp"
  222. #include "misc/juce_BubbleComponent.cpp"
  223. #include "misc/juce_DropShadower.cpp"
  224. #include "misc/juce_FocusOutline.cpp"
  225. #include "layout/juce_FlexBox.cpp"
  226. #include "layout/juce_GridItem.cpp"
  227. #include "layout/juce_Grid.cpp"
  228. #if JUCE_IOS || JUCE_WINDOWS
  229. #include "native/juce_MultiTouchMapper.h"
  230. #endif
  231. #if JUCE_ANDROID || JUCE_WINDOWS || JUCE_UNIT_TESTS
  232. #include "native/accessibility/juce_AccessibilityTextHelpers.h"
  233. #endif
  234. #if JUCE_MAC || JUCE_IOS
  235. #include "native/accessibility/juce_mac_AccessibilitySharedCode.mm"
  236. #if JUCE_IOS
  237. #include "native/accessibility/juce_ios_Accessibility.mm"
  238. #include "native/juce_ios_UIViewComponentPeer.mm"
  239. #include "native/juce_ios_Windowing.mm"
  240. #include "native/juce_ios_FileChooser.mm"
  241. #if JUCE_CONTENT_SHARING
  242. #include "native/juce_ios_ContentSharer.cpp"
  243. #endif
  244. #else
  245. #include "native/accessibility/juce_mac_Accessibility.mm"
  246. #include "native/juce_mac_NSViewComponentPeer.mm"
  247. #include "native/juce_mac_Windowing.mm"
  248. #include "native/juce_mac_MainMenu.mm"
  249. #include "native/juce_mac_FileChooser.mm"
  250. #endif
  251. #include "native/juce_mac_MouseCursor.mm"
  252. #elif JUCE_WINDOWS
  253. #if JUCE_MSVC
  254. #include "native/accessibility/juce_win32_ComInterfaces.h"
  255. #include "native/accessibility/juce_win32_WindowsUIAWrapper.h"
  256. #include "native/accessibility/juce_win32_AccessibilityElement.h"
  257. #include "native/accessibility/juce_win32_UIAHelpers.h"
  258. #include "native/accessibility/juce_win32_UIAProviders.h"
  259. #include "native/accessibility/juce_win32_AccessibilityElement.cpp"
  260. #include "native/accessibility/juce_win32_Accessibility.cpp"
  261. #endif
  262. #include "native/juce_win32_Windowing.cpp"
  263. #include "native/juce_win32_DragAndDrop.cpp"
  264. #include "native/juce_win32_FileChooser.cpp"
  265. #elif JUCE_LINUX || JUCE_BSD
  266. #include "native/x11/juce_linux_X11_Symbols.cpp"
  267. #include "native/x11/juce_linux_X11_DragAndDrop.cpp"
  268. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wzero-as-null-pointer-constant")
  269. #include "native/juce_linux_Windowing.cpp"
  270. #include "native/x11/juce_linux_XWindowSystem.cpp"
  271. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  272. #include "native/juce_linux_FileChooser.cpp"
  273. #elif JUCE_ANDROID
  274. #include "juce_core/files/juce_common_MimeTypes.h"
  275. #include "native/accessibility/juce_android_Accessibility.cpp"
  276. #include "native/juce_android_Windowing.cpp"
  277. #include "native/juce_android_FileChooser.cpp"
  278. #if JUCE_CONTENT_SHARING
  279. #include "native/juce_android_ContentSharer.cpp"
  280. #endif
  281. #endif
  282. namespace juce
  283. {
  284. #if ! JUCE_NATIVE_ACCESSIBILITY_INCLUDED
  285. class AccessibilityHandler::AccessibilityNativeImpl { public: AccessibilityNativeImpl (AccessibilityHandler&) {} };
  286. void AccessibilityHandler::notifyAccessibilityEvent (AccessibilityEvent) const {}
  287. void AccessibilityHandler::postAnnouncement (const String&, AnnouncementPriority) {}
  288. AccessibilityNativeHandle* AccessibilityHandler::getNativeImplementation() const { return nullptr; }
  289. void notifyAccessibilityEventInternal (const AccessibilityHandler&, InternalAccessibilityEvent) {}
  290. std::unique_ptr<AccessibilityHandler::AccessibilityNativeImpl> AccessibilityHandler::createNativeImpl (AccessibilityHandler&)
  291. {
  292. return nullptr;
  293. }
  294. #else
  295. std::unique_ptr<AccessibilityHandler::AccessibilityNativeImpl> AccessibilityHandler::createNativeImpl (AccessibilityHandler& handler)
  296. {
  297. return std::make_unique<AccessibilityNativeImpl> (handler);
  298. }
  299. #endif
  300. }
  301. //==============================================================================
  302. #if JUCE_WINDOWS
  303. namespace juce
  304. {
  305. JUCE_COMCLASS (JuceIVirtualDesktopManager, "a5cd92ff-29be-454c-8d04-d82879fb3f1b") : public IUnknown
  306. {
  307. public:
  308. virtual HRESULT STDMETHODCALLTYPE IsWindowOnCurrentVirtualDesktop(
  309. __RPC__in HWND topLevelWindow,
  310. __RPC__out BOOL * onCurrentDesktop) = 0;
  311. virtual HRESULT STDMETHODCALLTYPE GetWindowDesktopId(
  312. __RPC__in HWND topLevelWindow,
  313. __RPC__out GUID * desktopId) = 0;
  314. virtual HRESULT STDMETHODCALLTYPE MoveWindowToDesktop(
  315. __RPC__in HWND topLevelWindow,
  316. __RPC__in REFGUID desktopId) = 0;
  317. };
  318. JUCE_COMCLASS (JuceVirtualDesktopManager, "aa509086-5ca9-4c25-8f95-589d3c07b48a");
  319. } // namespace juce
  320. #ifdef __CRT_UUID_DECL
  321. __CRT_UUID_DECL (juce::JuceIVirtualDesktopManager, 0xa5cd92ff, 0x29be, 0x454c, 0x8d, 0x04, 0xd8, 0x28, 0x79, 0xfb, 0x3f, 0x1b)
  322. __CRT_UUID_DECL (juce::JuceVirtualDesktopManager, 0xaa509086, 0x5ca9, 0x4c25, 0x8f, 0x95, 0x58, 0x9d, 0x3c, 0x07, 0xb4, 0x8a)
  323. #endif
  324. bool juce::isWindowOnCurrentVirtualDesktop (void* x)
  325. {
  326. if (x == nullptr)
  327. return false;
  328. static auto* desktopManager = []
  329. {
  330. JuceIVirtualDesktopManager* result = nullptr;
  331. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wlanguage-extension-token")
  332. if (SUCCEEDED (CoCreateInstance (__uuidof (JuceVirtualDesktopManager), nullptr, CLSCTX_ALL, IID_PPV_ARGS (&result))))
  333. return result;
  334. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  335. return static_cast<JuceIVirtualDesktopManager*> (nullptr);
  336. }();
  337. BOOL current = false;
  338. if (auto* dm = desktopManager)
  339. if (SUCCEEDED (dm->IsWindowOnCurrentVirtualDesktop (static_cast<HWND> (x), &current)))
  340. return current != false;
  341. return true;
  342. }
  343. #else
  344. bool juce::isWindowOnCurrentVirtualDesktop (void*) { return true; }
  345. juce::ScopedDPIAwarenessDisabler::ScopedDPIAwarenessDisabler() { ignoreUnused (previousContext); }
  346. juce::ScopedDPIAwarenessDisabler::~ScopedDPIAwarenessDisabler() {}
  347. #endif
  348. // Depends on types defined in platform-specific windowing files
  349. #include "mouse/juce_MouseCursor.cpp"
  350. #if JUCE_UNIT_TESTS
  351. #include "native/accessibility/juce_AccessibilityTextHelpers_test.cpp"
  352. #endif