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