mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
169 lines
5.8 KiB
C++
169 lines
5.8 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
|
Copyright 2004-11 by Raw Material Software Ltd.
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
JUCE can be redistributed and/or modified under the terms of the GNU General
|
|
Public License (Version 2), as published by the Free Software Foundation.
|
|
A copy of the license is included in the JUCE distribution, or can be found
|
|
online at www.gnu.org/licenses.
|
|
|
|
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
To release a closed-source product which uses JUCE, commercial licenses are
|
|
available: visit www.rawmaterialsoftware.com/juce for more information.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
DialogWindow::DialogWindow (const String& name, const Colour& colour,
|
|
const bool escapeCloses, const bool onDesktop)
|
|
: DocumentWindow (name, colour, DocumentWindow::closeButton, onDesktop),
|
|
escapeKeyTriggersCloseButton (escapeCloses)
|
|
{
|
|
}
|
|
|
|
DialogWindow::~DialogWindow()
|
|
{
|
|
}
|
|
|
|
bool DialogWindow::keyPressed (const KeyPress& key)
|
|
{
|
|
if (escapeKeyTriggersCloseButton && key == KeyPress::escapeKey)
|
|
{
|
|
setVisible (false);
|
|
return true;
|
|
}
|
|
|
|
return DocumentWindow::keyPressed (key);
|
|
}
|
|
|
|
void DialogWindow::resized()
|
|
{
|
|
DocumentWindow::resized();
|
|
|
|
if (escapeKeyTriggersCloseButton)
|
|
{
|
|
if (Button* const close = getCloseButton())
|
|
{
|
|
const KeyPress esc (KeyPress::escapeKey, 0, 0);
|
|
|
|
if (! close->isRegisteredForShortcut (esc))
|
|
close->addShortcut (esc);
|
|
}
|
|
}
|
|
}
|
|
|
|
//==============================================================================
|
|
class DefaultDialogWindow : public DialogWindow
|
|
{
|
|
public:
|
|
DefaultDialogWindow (LaunchOptions& options)
|
|
: DialogWindow (options.dialogTitle, options.dialogBackgroundColour,
|
|
options.escapeKeyTriggersCloseButton, true)
|
|
{
|
|
setUsingNativeTitleBar (options.useNativeTitleBar);
|
|
|
|
if (! JUCEApplication::isStandaloneApp())
|
|
setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
|
|
|
|
if (options.content.willDeleteObject())
|
|
setContentOwned (options.content.release(), true);
|
|
else
|
|
setContentNonOwned (options.content.release(), true);
|
|
|
|
centreAroundComponent (options.componentToCentreAround, getWidth(), getHeight());
|
|
setResizable (options.resizable, options.useBottomRightCornerResizer);
|
|
}
|
|
|
|
void closeButtonPressed()
|
|
{
|
|
setVisible (false);
|
|
}
|
|
|
|
private:
|
|
JUCE_DECLARE_NON_COPYABLE (DefaultDialogWindow)
|
|
};
|
|
|
|
DialogWindow::LaunchOptions::LaunchOptions() noexcept
|
|
: dialogBackgroundColour (Colours::lightgrey),
|
|
componentToCentreAround (nullptr),
|
|
escapeKeyTriggersCloseButton (true),
|
|
useNativeTitleBar (true),
|
|
resizable (true),
|
|
useBottomRightCornerResizer (false)
|
|
{
|
|
}
|
|
|
|
DialogWindow* DialogWindow::LaunchOptions::create()
|
|
{
|
|
jassert (content != nullptr); // You need to provide some kind of content for the dialog!
|
|
|
|
return new DefaultDialogWindow (*this);
|
|
}
|
|
|
|
DialogWindow* DialogWindow::LaunchOptions::launchAsync()
|
|
{
|
|
DialogWindow* const d = create();
|
|
d->enterModalState (true, nullptr, true);
|
|
return d;
|
|
}
|
|
|
|
#if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
|
|
int DialogWindow::LaunchOptions::runModal()
|
|
{
|
|
return launchAsync()->runModalLoop();
|
|
}
|
|
#endif
|
|
|
|
//==============================================================================
|
|
void DialogWindow::showDialog (const String& dialogTitle,
|
|
Component* const contentComponent,
|
|
Component* const componentToCentreAround,
|
|
const Colour& backgroundColour,
|
|
const bool escapeKeyTriggersCloseButton,
|
|
const bool resizable,
|
|
const bool useBottomRightCornerResizer)
|
|
{
|
|
LaunchOptions o;
|
|
o.dialogTitle = dialogTitle;
|
|
o.content.setNonOwned (contentComponent);
|
|
o.componentToCentreAround = componentToCentreAround;
|
|
o.dialogBackgroundColour = backgroundColour;
|
|
o.escapeKeyTriggersCloseButton = escapeKeyTriggersCloseButton;
|
|
o.useNativeTitleBar = false;
|
|
o.resizable = resizable;
|
|
o.useBottomRightCornerResizer = useBottomRightCornerResizer;
|
|
|
|
o.launchAsync();
|
|
}
|
|
|
|
#if JUCE_MODAL_LOOPS_PERMITTED
|
|
int DialogWindow::showModalDialog (const String& dialogTitle,
|
|
Component* const contentComponent,
|
|
Component* const componentToCentreAround,
|
|
const Colour& backgroundColour,
|
|
const bool escapeKeyTriggersCloseButton,
|
|
const bool resizable,
|
|
const bool useBottomRightCornerResizer)
|
|
{
|
|
LaunchOptions o;
|
|
o.dialogTitle = dialogTitle;
|
|
o.content.setNonOwned (contentComponent);
|
|
o.componentToCentreAround = componentToCentreAround;
|
|
o.dialogBackgroundColour = backgroundColour;
|
|
o.escapeKeyTriggersCloseButton = escapeKeyTriggersCloseButton;
|
|
o.useNativeTitleBar = false;
|
|
o.resizable = resizable;
|
|
o.useBottomRightCornerResizer = useBottomRightCornerResizer;
|
|
|
|
return o.runModal();
|
|
}
|
|
#endif
|