JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_DialogWindow.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
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.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 const bool escapeCloses, const bool onDesktop,
31 const float scale)
32 : DocumentWindow (name, colour, DocumentWindow::closeButton, onDesktop),
33 desktopScale (scale),
34 escapeKeyTriggersCloseButton (escapeCloses)
35{
36}
37
39
41{
42 if (escapeKeyTriggersCloseButton)
43 {
44 setVisible (false);
45 return true;
46 }
47
48 return false;
49}
50
52{
54 return true;
55
56 return DocumentWindow::keyPressed (key);
57}
58
60{
62
63 if (escapeKeyTriggersCloseButton)
64 {
65 if (auto* close = getCloseButton())
66 {
67 const KeyPress esc (KeyPress::escapeKey, 0, 0);
68
69 if (! close->isRegisteredForShortcut (esc))
70 close->addShortcut (esc);
71 }
72 }
73}
74
75//==============================================================================
77{
78public:
81 options.escapeKeyTriggersCloseButton, true,
82 options.componentToCentreAround != nullptr
84 : 1.0f)
85 {
86 if (options.content.willDeleteObject())
87 setContentOwned (options.content.release(), true);
88 else
89 setContentNonOwned (options.content.release(), true);
90
93
96 }
97
98 void closeButtonPressed() override
99 {
100 setVisible (false);
101 }
102
103private:
105};
106
107DialogWindow::LaunchOptions::LaunchOptions() noexcept {}
108
110{
111 jassert (content != nullptr); // You need to provide some kind of content for the dialog!
112
113 return new DefaultDialogWindow (*this);
114}
115
117{
118 auto* d = create();
119 d->enterModalState (true, nullptr, true);
120 return d;
121}
122
123#if JUCE_MODAL_LOOPS_PERMITTED
124int DialogWindow::LaunchOptions::runModal()
125{
126 return launchAsync()->runModalLoop();
127}
128#endif
129
130//==============================================================================
131void DialogWindow::showDialog (const String& dialogTitle,
132 Component* const contentComponent,
133 Component* const componentToCentreAround,
134 Colour backgroundColour,
135 const bool escapeKeyTriggersCloseButton,
136 const bool resizable,
137 const bool useBottomRightCornerResizer)
138{
140 o.dialogTitle = dialogTitle;
141 o.content.setNonOwned (contentComponent);
142 o.componentToCentreAround = componentToCentreAround;
143 o.dialogBackgroundColour = backgroundColour;
144 o.escapeKeyTriggersCloseButton = escapeKeyTriggersCloseButton;
145 o.useNativeTitleBar = false;
146 o.resizable = resizable;
147 o.useBottomRightCornerResizer = useBottomRightCornerResizer;
148
149 o.launchAsync();
150}
151
152#if JUCE_MODAL_LOOPS_PERMITTED
153int DialogWindow::showModalDialog (const String& dialogTitle,
154 Component* const contentComponent,
155 Component* const componentToCentreAround,
156 Colour backgroundColour,
157 const bool escapeKeyTriggersCloseButton,
158 const bool resizable,
159 const bool useBottomRightCornerResizer)
160{
161 LaunchOptions o;
162 o.dialogTitle = dialogTitle;
163 o.content.setNonOwned (contentComponent);
164 o.componentToCentreAround = componentToCentreAround;
165 o.dialogBackgroundColour = backgroundColour;
166 o.escapeKeyTriggersCloseButton = escapeKeyTriggersCloseButton;
167 o.useNativeTitleBar = false;
168 o.resizable = resizable;
169 o.useBottomRightCornerResizer = useBottomRightCornerResizer;
170
171 return o.runModal();
172}
173#endif
174
175//==============================================================================
177{
178 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::dialogWindow);
179}
180
181} // namespace juce
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
The base class for all JUCE user-interface objects.
int getHeight() const noexcept
Returns the component's height in pixels.
static float JUCE_CALLTYPE getApproximateScaleFactorForComponent(const Component *targetComponent)
Returns the approximate scale factor for a given component by traversing its parent hierarchy and app...
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
virtual void resized()
Called when this component's size has been changed.
int getWidth() const noexcept
Returns the component's width in pixels.
virtual bool keyPressed(const KeyPress &key)
Called when a key is pressed.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
void closeButtonPressed() override
This method is called when the user tries to close the window.
A dialog-box style window.
~DialogWindow() override
Destructor.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
static void showDialog(const String &dialogTitle, Component *contentComponent, Component *componentToCentreAround, Colour backgroundColour, bool escapeKeyTriggersCloseButton, bool shouldBeResizable=false, bool useBottomRightCornerResizer=false)
Easy way of quickly showing a dialog box containing a given component.
virtual bool escapeKeyPressed()
Called when the escape key is pressed.
void resized() override
Called when this component's size has been changed.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
DialogWindow(const String &name, Colour backgroundColour, bool escapeKeyTriggersCloseButton, bool addToDesktop=true, float desktopScale=1.0f)
Creates a DialogWindow.
A resizable window with a title bar and maximise, minimise and close buttons.
Button * getCloseButton() const noexcept
Returns the close button, (or nullptr if there isn't one).
Represents a key press, including any modifier keys that are needed.
static const int escapeKey
key-code for the escape key
void setResizable(bool shouldBeResizable, bool useBottomRightCornerResizer)
Make the window resizable or fixed.
void setContentOwned(Component *newContentComponent, bool resizeToFitWhenContentChangesSize)
Changes the current content component.
void setContentNonOwned(Component *newContentComponent, bool resizeToFitWhenContentChangesSize)
Changes the current content component.
The JUCE String class!
Definition juce_String.h:53
void centreAroundComponent(Component *componentToCentreAround, int width, int height)
This will set the bounds of the window so that it's centred in front of another window.
void setUsingNativeTitleBar(bool useNativeTitleBar)
Sets whether an OS-native title bar will be used, or a JUCE one.
close
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
This class defines a collection of settings to be used to open a DialogWindow.
DialogWindow * create()
Creates a new DialogWindow instance with these settings.
Component * componentToCentreAround
If this is not a nullptr, it indicates a component that you'd like to position this dialog box in fro...
Colour dialogBackgroundColour
The background colour for the window.
bool useNativeTitleBar
If true, the dialog will use a native title bar.
OptionalScopedPointer< Component > content
The content component to show in the window.
bool useBottomRightCornerResizer
Indicates whether to use a border or corner resizer component.
DialogWindow * launchAsync()
Launches a new modal dialog window.
bool resizable
If true, the window will be resizable.
bool escapeKeyTriggersCloseButton
If true, then the escape key will trigger the dialog's close button.
String dialogTitle
The title to give the window.
static bool areThereAnyAlwaysOnTopWindows()
Returns true if any windows have a z order that is higher than normal.