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_AlertWindow.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
29static juce_wchar getDefaultPasswordChar() noexcept
30{
31 #if JUCE_LINUX || JUCE_BSD
32 return 0x2022;
33 #else
34 return 0x25cf;
35 #endif
36}
37
38static int showAlertWindowUnmanaged (const MessageBoxOptions& opts, ModalComponentManager::Callback* cb)
39{
40 return detail::ConcreteScopedMessageBoxImpl::showUnmanaged (detail::AlertWindowHelpers::create (opts), cb);
41}
42
43//==============================================================================
45 const String& message,
46 MessageBoxIconType iconType,
47 Component* comp)
48 : TopLevelWindow (title, true),
49 alertIconType (iconType),
50 associatedComponent (comp),
51 desktopScale (comp != nullptr ? Component::getApproximateScaleFactorForComponent (comp) : 1.0f)
52{
54
55 accessibleMessageLabel.setColour (Label::textColourId, Colours::transparentBlack);
56 accessibleMessageLabel.setColour (Label::backgroundColourId, Colours::transparentBlack);
57 accessibleMessageLabel.setColour (Label::outlineColourId, Colours::transparentBlack);
58 accessibleMessageLabel.setInterceptsMouseClicks (false, false);
59 addAndMakeVisible (accessibleMessageLabel);
60
61 if (message.isEmpty())
62 text = " "; // to force an update if the message is empty
63
64 setMessage (message);
65
67 constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
68}
69
71{
72 // Ensure that the focus does not jump to another TextEditor while we
73 // remove children.
74 for (auto* t : textBoxes)
75 t->setWantsKeyboardFocus (false);
76
77 // Give away focus before removing the editors, so that any TextEditor
78 // with focus has a chance to dismiss native keyboard if shown.
80
82}
83
85{
86 if (escapeKeyCancels || buttons.size() > 0)
88}
89
90//==============================================================================
91void AlertWindow::setMessage (const String& message)
92{
93 auto newMessage = message.substring (0, 2048);
94
95 if (text != newMessage)
96 {
97 text = newMessage;
98
99 auto accessibleText = getName() + ". " + text;
102
103 updateLayout (true);
104 repaint();
105 }
106}
107
108//==============================================================================
109void AlertWindow::exitAlert (Button* button)
110{
111 if (auto* parent = button->getParentComponent())
112 parent->exitModalState (button->getCommandID());
113}
114
115//==============================================================================
117 const int returnValue,
118 const KeyPress& shortcutKey1,
119 const KeyPress& shortcutKey2)
120{
121 auto* b = new TextButton (name, {});
122 buttons.add (b);
123
124 b->setWantsKeyboardFocus (true);
125 b->setExplicitFocusOrder (1);
126 b->setMouseClickGrabsKeyboardFocus (false);
127 b->setCommandToTrigger (nullptr, returnValue, false);
128 b->addShortcut (shortcutKey1);
129 b->addShortcut (shortcutKey2);
130 b->onClick = [this, b] { exitAlert (b); };
131
132 Array<TextButton*> buttonsArray (buttons.begin(), buttons.size());
133 auto& lf = getLookAndFeel();
134
135 auto buttonHeight = lf.getAlertWindowButtonHeight();
136 auto buttonWidths = lf.getWidthsForTextButtons (*this, buttonsArray);
137
138 jassert (buttonWidths.size() == buttons.size());
139 int i = 0;
140
141 for (auto* button : buttons)
142 button->setSize (buttonWidths[i++], buttonHeight);
143
144 addAndMakeVisible (b, 0);
145 updateLayout (false);
146}
147
149{
150 return buttons.size();
151}
152
154{
155 return buttons[index];
156}
157
159{
160 for (auto* button : buttons)
161 if (buttonName == button->getName())
162 return button;
163
164 return nullptr;
165}
166
168{
169 if (auto* button = getButton (buttonName))
170 button->triggerClick();
171}
172
177
178//==============================================================================
180 const String& initialContents,
181 const String& onScreenLabel,
182 const bool isPasswordBox)
183{
184 auto* ed = new TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0);
185 ed->setSelectAllWhenFocused (true);
186 ed->setEscapeAndReturnKeysConsumed (false);
187 textBoxes.add (ed);
188 allComps.add (ed);
189
191 ed->setFont (getLookAndFeel().getAlertWindowMessageFont());
193 ed->setText (initialContents);
194 ed->setCaretPosition (initialContents.length());
195 textboxNames.add (onScreenLabel);
196
197 updateLayout (false);
198}
199
201{
202 for (auto* tb : textBoxes)
203 if (tb->getName() == nameOfTextEditor)
204 return tb;
205
206 return nullptr;
207}
208
210{
211 if (auto* t = getTextEditor (nameOfTextEditor))
212 return t->getText();
213
214 return {};
215}
216
217
218//==============================================================================
220 const StringArray& items,
221 const String& onScreenLabel)
222{
223 auto* cb = new ComboBox (name);
224 comboBoxes.add (cb);
225 allComps.add (cb);
226
227 cb->addItemList (items, 1);
228
230 cb->setSelectedItemIndex (0);
231
232 comboBoxNames.add (onScreenLabel);
233 updateLayout (false);
234}
235
237{
238 for (auto* cb : comboBoxes)
239 if (cb->getName() == nameOfList)
240 return cb;
241
242 return nullptr;
243}
244
245//==============================================================================
247{
248public:
249 AlertTextComp (AlertWindow& owner, const String& message, const Font& font)
250 {
253
254 setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
255 setColour (TextEditor::outlineColourId, Colours::transparentBlack);
256 setColour (TextEditor::shadowColourId, Colours::transparentBlack);
257
258 setReadOnly (true);
259 setMultiLine (true, true);
260 setCaretVisible (false);
261 setScrollbarsShown (true);
263 setWantsKeyboardFocus (false);
264 setFont (font);
265 setText (message, false);
266
267 bestWidth = 2 * (int) std::sqrt (font.getHeight() * (float) font.getStringWidth (message));
268 }
269
270 void updateLayout (const int width)
271 {
274 s.append (getText(), getFont());
275
276 TextLayout text;
277 text.createLayoutWithBalancedLineLengths (s, (float) width - 8.0f);
278 setSize (width, jmin (width, (int) (text.getHeight() + getFont().getHeight())));
279 }
280
281 int bestWidth;
282
284};
285
287{
288 auto* c = new AlertTextComp (*this, textBlock, getLookAndFeel().getAlertWindowMessageFont());
289 textBlocks.add (c);
290 allComps.add (c);
292
293 updateLayout (false);
294}
295
296//==============================================================================
298{
299 auto* pb = new ProgressBar (progressValue, style);
300 progressBars.add (pb);
301 allComps.add (pb);
303
304 updateLayout (false);
305}
306
307//==============================================================================
309{
310 customComps.add (component);
311 allComps.add (component);
312 addAndMakeVisible (component);
313
314 updateLayout (false);
315}
316
317int AlertWindow::getNumCustomComponents() const { return customComps.size(); }
318Component* AlertWindow::getCustomComponent (int index) const { return customComps [index]; }
319
321{
322 auto* c = getCustomComponent (index);
323
324 if (c != nullptr)
325 {
326 customComps.removeFirstMatchingValue (c);
327 allComps.removeFirstMatchingValue (c);
329
330 updateLayout (false);
331 }
332
333 return c;
334}
335
336//==============================================================================
338{
339 auto& lf = getLookAndFeel();
340 lf.drawAlertBox (g, *this, textArea, textLayout);
341
343 g.setFont (lf.getAlertWindowFont());
344
345 for (int i = textBoxes.size(); --i >= 0;)
346 {
347 auto* te = textBoxes.getUnchecked (i);
348
349 g.drawFittedText (textboxNames[i],
350 te->getX(), te->getY() - 14,
351 te->getWidth(), 14,
353 }
354
355 for (int i = comboBoxNames.size(); --i >= 0;)
356 {
357 auto* cb = comboBoxes.getUnchecked (i);
358
359 g.drawFittedText (comboBoxNames[i],
360 cb->getX(), cb->getY() - 14,
361 cb->getWidth(), 14,
363 }
364
365 for (auto* c : customComps)
366 g.drawFittedText (c->getName(),
367 c->getX(), c->getY() - 14,
368 c->getWidth(), 14,
370}
371
372void AlertWindow::updateLayout (const bool onlyIncreaseSize)
373{
374 const int titleH = 24;
375 const int iconWidth = 80;
376
377 auto& lf = getLookAndFeel();
378 auto messageFont (lf.getAlertWindowMessageFont());
379
380 auto wid = jmax (messageFont.getStringWidth (text),
381 messageFont.getStringWidth (getName()));
382
383 auto sw = (int) std::sqrt (messageFont.getHeight() * (float) wid);
384 auto w = jmin (300 + sw * 2, (int) ((float) getParentWidth() * 0.7f));
385 const int edgeGap = 10;
386 const int labelHeight = 18;
387 int iconSpace = 0;
388
390 attributedText.append (getName(), lf.getAlertWindowTitleFont());
391
392 if (text.isNotEmpty())
393 attributedText.append ("\n\n" + text, messageFont);
394
396
397 if (alertIconType == NoIcon)
398 {
399 attributedText.setJustification (Justification::centredTop);
401 }
402 else
403 {
404 attributedText.setJustification (Justification::topLeft);
407 }
408
409 w = jmax (350, (int) textLayout.getWidth() + iconSpace + edgeGap * 4);
410 w = jmin (w, (int) ((float) getParentWidth() * 0.7f));
411
412 auto textLayoutH = (int) textLayout.getHeight();
413 auto textBottom = 16 + titleH + textLayoutH;
414 int h = textBottom;
415
416 int buttonW = 40;
417
418 for (auto* b : buttons)
419 buttonW += 16 + b->getWidth();
420
421 w = jmax (buttonW, w);
422
423 h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
424
425 if (auto* b = buttons[0])
426 h += 20 + b->getHeight();
427
428 for (auto* c : customComps)
429 {
430 w = jmax (w, (c->getWidth() * 100) / 80);
431 h += 10 + c->getHeight();
432
433 if (c->getName().isNotEmpty())
434 h += labelHeight;
435 }
436
437 for (auto* tb : textBlocks)
438 w = jmax (w, static_cast<const AlertTextComp*> (tb)->bestWidth);
439
440 w = jmin (w, (int) ((float) getParentWidth() * 0.7f));
441
442 for (auto* tb : textBlocks)
443 {
444 auto* ac = static_cast<AlertTextComp*> (tb);
445 ac->updateLayout ((int) ((float) w * 0.8f));
446 h += ac->getHeight() + 10;
447 }
448
449 h = jmin (getParentHeight() - 50, h);
450
452 {
453 w = jmax (w, getWidth());
454 h = jmax (h, getHeight());
455 }
456
457 if (! isVisible())
458 centreAroundComponent (associatedComponent, w, h);
459 else
460 setBounds (getBounds().withSizeKeepingCentre (w, h));
461
462 textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
463 accessibleMessageLabel.setBounds (textArea);
464
465 const int spacer = 16;
466 int totalWidth = -spacer;
467
468 for (auto* b : buttons)
469 totalWidth += b->getWidth() + spacer;
470
471 auto x = (w - totalWidth) / 2;
472 auto y = (int) ((float) getHeight() * 0.95f);
473
474 for (auto* c : buttons)
475 {
476 int ny = proportionOfHeight (0.95f) - c->getHeight();
477 c->setTopLeftPosition (x, ny);
478 if (ny < y)
479 y = ny;
480
481 x += c->getWidth() + spacer;
482
483 c->toFront (false);
484 }
485
486 y = textBottom;
487
488 for (auto* c : allComps)
489 {
490 h = 22;
491
492 const int comboIndex = comboBoxes.indexOf (dynamic_cast<ComboBox*> (c));
493 if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
494 y += labelHeight;
495
496 const int tbIndex = textBoxes.indexOf (dynamic_cast<TextEditor*> (c));
497 if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
498 y += labelHeight;
499
500 if (customComps.contains (c))
501 {
502 if (c->getName().isNotEmpty())
503 y += labelHeight;
504
505 c->setTopLeftPosition (proportionOfWidth (0.1f), y);
506 h = c->getHeight();
507 }
508 else if (textBlocks.contains (c))
509 {
510 c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
511 h = c->getHeight();
512 }
513 else
514 {
515 c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
516 }
517
518 y += h + 10;
519 }
520
522}
523
525{
526 return allComps.size() > 0;
527}
528
529//==============================================================================
531{
532 dragger.startDraggingComponent (this, e);
533}
534
536{
537 dragger.dragComponent (this, e, &constrainer);
538}
539
541{
542 for (auto* b : buttons)
543 {
544 if (b->isRegisteredForShortcut (key))
545 {
546 b->triggerClick();
547 return true;
548 }
549 }
550
551 if (key.isKeyCode (KeyPress::escapeKey) && escapeKeyCancels)
552 {
553 exitModalState (0);
554 return true;
555 }
556
557 if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
558 {
559 buttons.getUnchecked (0)->triggerClick();
560 return true;
561 }
562
563 return false;
564}
565
567{
568 const int newFlags = getLookAndFeel().getAlertBoxWindowFlags();
569
572 updateLayout (false);
573}
574
575int AlertWindow::getDesktopWindowStyleFlags() const
576{
577 return getLookAndFeel().getAlertBoxWindowFlags();
578}
579
580//==============================================================================
581#if JUCE_MODAL_LOOPS_PERMITTED
582void AlertWindow::showMessageBox (MessageBoxIconType iconType,
583 const String& title,
584 const String& message,
585 const String& buttonText,
586 Component* associatedComponent)
587{
588 show (MessageBoxOptions()
589 .withIconType (iconType)
590 .withTitle (title)
591 .withMessage (message)
592 .withButton (buttonText.isEmpty() ? TRANS ("OK") : buttonText)
593 .withAssociatedComponent (associatedComponent));
594}
595
596int AlertWindow::show (const MessageBoxOptions& options)
597{
598 if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
599 return NativeMessageBox::show (options);
600
601 return showAlertWindowUnmanaged (options, nullptr);
602}
603
604bool AlertWindow::showNativeDialogBox (const String& title,
605 const String& bodyText,
606 bool isOkCancel)
607{
608 if (isOkCancel)
609 return NativeMessageBox::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
610
611 NativeMessageBox::showMessageBox (AlertWindow::NoIcon, title, bodyText);
612 return true;
613}
614#endif
615
617{
618 if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
619 NativeMessageBox::showAsync (options, callback);
620 else
621 showAlertWindowUnmanaged (options, callback);
622}
623
624void AlertWindow::showAsync (const MessageBoxOptions& options, std::function<void (int)> callback)
625{
626 showAsync (options, ModalCallbackFunction::create (callback));
627}
628
630 const String& title,
631 const String& message,
632 const String& buttonText,
633 Component* associatedComponent,
635{
636 auto options = MessageBoxOptions::makeOptionsOk (iconType,
637 title,
638 message,
640 associatedComponent);
641 showAsync (options, callback);
642}
643
644static int showMaybeAsync (const MessageBoxOptions& options,
646{
647 if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
648 return showNativeBoxUnmanaged (options, callbackIn, ResultCodeMappingMode::alertWindow);
649
650 return showAlertWindowUnmanaged (options, callbackIn);
651}
652
654 const String& title,
655 const String& message,
656 const String& button1Text,
657 const String& button2Text,
658 Component* associatedComponent,
660{
661 auto options = MessageBoxOptions::makeOptionsOkCancel (iconType,
662 title,
663 message,
666 associatedComponent);
667 return showMaybeAsync (options, callback) == 1;
668}
669
671 const String& title,
672 const String& message,
673 const String& button1Text,
674 const String& button2Text,
675 const String& button3Text,
676 Component* associatedComponent,
678{
679 auto options = MessageBoxOptions::makeOptionsYesNoCancel (iconType,
680 title,
681 message,
685 associatedComponent);
686 return showMaybeAsync (options, callback);
687}
688
690{
691 if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
692 return NativeMessageBox::showScopedAsync (options, std::move (callback));
693
694 return detail::ConcreteScopedMessageBoxImpl::show (detail::AlertWindowHelpers::create (options), std::move (callback));
695}
696
697//==============================================================================
699{
700 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::dialogWindow);
701}
702
703} // namespace juce
A window that displays a message and has buttons for the user to react to it.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
@ textColourId
The colour for the text.
void setEscapeKeyCancels(bool shouldEscapeKeyCancel)
If set to true and the window contains no buttons, then pressing the escape key will make the alert c...
void addButton(const String &name, int returnValue, const KeyPress &shortcutKey1=KeyPress(), const KeyPress &shortcutKey2=KeyPress())
Adds a button to the window.
void addComboBox(const String &name, const StringArray &items, const String &onScreenLabel=String())
Adds a drop-down list of choices to the box.
static int JUCE_CALLTYPE showYesNoCancelBox(MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text, const String &button2Text, const String &button3Text, Component *associatedComponent, ModalComponentManager::Callback *callback)
Shows a dialog box with three buttons.
void addTextEditor(const String &name, const String &initialContents, const String &onScreenLabel=String(), bool isPasswordBox=false)
Adds a textbox to the window for entering strings.
int getNumButtons() const
Returns the number of buttons that the window currently has.
static bool JUCE_CALLTYPE showOkCancelBox(MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text, const String &button2Text, Component *associatedComponent, ModalComponentManager::Callback *callback)
Shows a dialog box with two buttons.
void setMessage(const String &message)
Changes the dialog box's message.
static ScopedMessageBox showScopedAsync(const MessageBoxOptions &options, std::function< void(int)> callback)
Shows an alert window using the specified options.
static void JUCE_CALLTYPE showAsync(const MessageBoxOptions &options, ModalComponentManager::Callback *callback)
Shows a dialog box using the specified options.
void addTextBlock(const String &text)
Adds a block of text.
int getNumCustomComponents() const
Returns the number of custom components in the dialog box.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
bool containsAnyExtraComponents() const
Returns true if the window contains any components other than just buttons.
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
static void JUCE_CALLTYPE showMessageBoxAsync(MessageBoxIconType iconType, const String &title, const String &message, const String &buttonText=String(), Component *associatedComponent=nullptr, ModalComponentManager::Callback *callback=nullptr)
Shows a dialog box that just has a message and a single button to get rid of it.
void addProgressBarComponent(double &progressValue, std::optional< ProgressBar::Style > style=std::nullopt)
Adds a progress-bar to the window.
Component * getCustomComponent(int index) const
Returns one of the custom components in the dialog box.
Button * getButton(int index) const
Returns a Button that was added to the AlertWindow.
void paint(Graphics &) override
Components can override this method to draw their content.
TextEditor * getTextEditor(const String &nameOfTextEditor) const
Returns a pointer to a textbox that was added with addTextEditor().
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void triggerButtonClick(const String &buttonName)
Invokes a click of one of the buttons.
Component * removeCustomComponent(int index)
Removes one of the custom components in the dialog box.
void addCustomComponent(Component *component)
Adds a user-defined component to the dialog box.
AlertWindow(const String &title, const String &message, MessageBoxIconType iconType, Component *associatedComponent=nullptr)
Creates an AlertWindow.
String getTextEditorContents(const String &nameOfTextEditor) const
Returns the contents of a named textbox.
~AlertWindow() override
Destroys the AlertWindow.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
ComboBox * getComboBoxComponent(const String &nameOfList) const
Returns a drop-down list that was added to the AlertWindow.
void userTriedToCloseWindow() override
For components on the desktop, this is called if the system wants to close the window.
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
A text string with a set of colour/font settings that are associated with sub-ranges of the text.
void append(const String &textToAppend)
Appends some text (with a default font and colour).
void setJustification(Justification newJustification) noexcept
Sets the justification that should be used for laying-out the text.
A base class for buttons.
Definition juce_Button.h:43
A component that lets the user choose from a drop-down list of choices.
@ outlineColourId
The colour for an outline around the box.
void setMinimumOnscreenAmounts(int minimumWhenOffTheTop, int minimumWhenOffTheLeft, int minimumWhenOffTheBottom, int minimumWhenOffTheRight) noexcept
Sets the amount by which the component is allowed to go off-screen.
void dragComponent(Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)
Call this from your mouseDrag() callback to move the component.
void startDraggingComponent(Component *componentToDrag, const MouseEvent &e)
Call this from your component's mouseDown() method, to prepare for dragging.
@ windowHasDropShadow
Indicates that the window should have a drop-shadow (this may not be possible on all platforms).
@ windowHasTitleBar
Indicates that the window should have a normal OS-specific title bar and frame.
The base class for all JUCE user-interface objects.
bool isColourSpecified(int colourID) const
Returns true if the specified colour ID has been explicitly set for this component using the setColou...
int proportionOfWidth(float proportion) const noexcept
Returns a proportion of the component's width.
void giveAwayKeyboardFocus()
If this component or any of its children currently have the keyboard focus, this will defocus it,...
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
bool isVisible() const noexcept
Tests whether the component is visible or not.
int getNumChildComponents() const noexcept
Returns the number of child components that this component contains.
int proportionOfHeight(float proportion) const noexcept
Returns a proportion of the component's height.
void exitModalState(int returnValue=0)
Ends a component's modal state.
bool isOpaque() const noexcept
Returns true if no parts of this component are transparent.
int getHeight() const noexcept
Returns the component's height in pixels.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
void setDescription(const String &newDescription)
Sets the description for this component.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
void removeAllChildren()
Removes all this component's children.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
void setColour(int colourID, Colour newColour)
Registers a colour to be used for a particular purpose.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
int getParentWidth() const noexcept
Returns the width of the component's parent.
int getParentHeight() const noexcept
Returns the height of the component's parent.
String getName() const noexcept
Returns the name of this component.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
float getHeight() const noexcept
Returns the total height of this font, in pixels.
int getStringWidth(const String &text) const
Returns the total width of a string as it would be drawn using this font.
A graphics context, used for drawing a component or image.
void drawFittedText(const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
Tries to draw a text string inside a given space.
void setFont(const Font &newFont)
Changes the font to use for subsequent text-drawing functions.
void setColour(Colour newColour)
Changes the current drawing colour.
@ centredLeft
Indicates that the item should be centred vertically but placed on the left hand side.
@ centredTop
Indicates that the item should be centred horizontally and placed at the top.
@ topLeft
Indicates that the item should be placed in the top-left corner.
Represents a key press, including any modifier keys that are needed.
bool isKeyCode(int keyCodeToCompare) const noexcept
Checks whether the KeyPress's key is the same as the one provided, without checking the modifiers.
static const int escapeKey
key-code for the escape key
static const int returnKey
key-code for the return key
@ outlineColourId
An optional colour to use to draw a border around the label.
Definition juce_Label.h:108
@ backgroundColourId
The background colour to fill the label with.
Definition juce_Label.h:106
@ textColourId
The colour for the text.
Definition juce_Label.h:107
void setText(const String &newText, NotificationType notification)
Changes the label text.
static LookAndFeel & getDefaultLookAndFeel() noexcept
Returns the current default look-and-feel for a component to use when it hasn't got one explicitly se...
Class used to create a set of options to pass to the AlertWindow and NativeMessageBox methods for sho...
static MessageBoxOptions makeOptionsYesNoCancel(MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text=String(), const String &button2Text=String(), const String &button3Text=String(), Component *associatedComponent=nullptr)
Creates options suitable for a message box with three buttons.
static MessageBoxOptions makeOptionsOkCancel(MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text=String(), const String &button2Text=String(), Component *associatedComponent=nullptr)
Creates options suitable for a message box with two buttons.
static MessageBoxOptions makeOptionsOk(MessageBoxIconType iconType, const String &title, const String &message, const String &buttonText=String(), Component *associatedComponent=nullptr)
Creates options suitable for a message box with a single button.
static ModalComponentManager::Callback * create(CallbackFn &&fn)
This is a utility function to create a ModalComponentManager::Callback that will call a callable obje...
Receives callbacks when a modal component is dismissed.
Contains position and status information about a mouse event.
static bool JUCE_CALLTYPE showOkCancelBox(MessageBoxIconType iconType, const String &title, const String &message, Component *associatedComponent, ModalComponentManager::Callback *callback)
Shows a dialog box with two buttons.
static ScopedMessageBox showScopedAsync(const MessageBoxOptions &options, std::function< void(int)> callback)
Shows a dialog box using the specified options.
static void JUCE_CALLTYPE showAsync(const MessageBoxOptions &options, ModalComponentManager::Callback *callback)
Shows a dialog box using the specified options.
A progress bar component.
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Changes all the rectangle's coordinates.
Objects of this type can be used to programmatically close message boxes.
A special array for holding a list of strings.
int size() const noexcept
Returns the number of strings in the array.
void add(String stringToAdd)
Appends a string at the end of the array.
The JUCE String class!
Definition juce_String.h:53
bool isEmpty() const noexcept
Returns true if the string contains no characters.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
A button that uses the standard lozenge-shaped background with a line of text on it.
An editable text box.
void setScrollbarsShown(bool shouldBeEnabled)
Enables or disables scrollbars (this only applies when in multi-line mode).
void setMultiLine(bool shouldBeMultiLine, bool shouldWordWrap=true)
Puts the editor into either multi- or single-line mode.
@ backgroundColourId
The colour to use for the text component's background - this can be transparent if necessary.
@ textColourId
The colour that will be used when text is added to the editor.
@ outlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component.
@ shadowColourId
If this is non-transparent, it'll be used to draw an inner shadow around the edge of the editor.
const Font & getFont() const noexcept
Returns the font that's currently being used for new text.
void setFont(const Font &newFont)
Sets the font to use for newly added text.
void setText(const String &newText, bool sendTextChangeMessage=true)
Sets the entire content of the editor.
void setReadOnly(bool shouldBeReadOnly)
Changes the editor to read-only mode.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void setCaretVisible(bool shouldBeVisible)
Makes the caret visible or invisible.
String getText() const
Returns the entire contents of the editor.
void setSelectAllWhenFocused(bool shouldSelectAll)
If set to true, focusing on the editor will highlight all its text.
A Pre-formatted piece of text, which may contain multiple fonts and colours.
void createLayoutWithBalancedLineLengths(const AttributedString &, float maxWidth)
Creates a layout, attempting to choose a width which results in lines of a similar length.
float getWidth() const noexcept
Returns the maximum width of the content.
float getHeight() const noexcept
Returns the maximum height of the content.
A base class for top-level windows.
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 setDropShadowEnabled(bool useShadow)
Turns the drop-shadow on and off.
void setUsingNativeTitleBar(bool useNativeTitleBar)
Sets whether an OS-native title bar will be used, or a JUCE one.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
#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.
typedef int
typedef float
JUCE Namespace.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
MessageBoxIconType
The type of icon to show in the dialog box.
@ dontSendNotification
No notification message should be sent.
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
T sqrt(T... args)
static bool areThereAnyAlwaysOnTopWindows()
Returns true if any windows have a z order that is higher than normal.