diff --git a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp index debb2384c3..a4eee17559 100644 --- a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp +++ b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.cpp @@ -40,15 +40,23 @@ struct Spinner : public Component, private Timer struct OnlineUnlockForm::OverlayComp : public Component, private Thread, - private Timer + private Timer, + private Button::Listener { - OverlayComp (OnlineUnlockForm& f) : Thread (String()), form (f) + OverlayComp (OnlineUnlockForm& f, bool hasCancelButton = false) + : Thread (String()), form (f) { result.succeeded = false; email = form.emailBox.getText(); password = form.passwordBox.getText(); addAndMakeVisible (spinner); + if (hasCancelButton) + { + addAndMakeVisible (cancelButton = new TextButton (TRANS ("Cancel"))); + cancelButton->addListener (this); + } + startThread (4); } @@ -73,6 +81,9 @@ struct OnlineUnlockForm::OverlayComp : public Component, { const int spinnerSize = 40; spinner.setBounds ((getWidth() - spinnerSize) / 2, proportionOfHeight (0.6f), spinnerSize, spinnerSize); + + if (cancelButton != nullptr) + cancelButton->setBounds (getLocalBounds().removeFromBottom (50).reduced (getWidth() / 4, 5)); } void run() override @@ -114,11 +125,24 @@ struct OnlineUnlockForm::OverlayComp : public Component, f.dismiss(); } + void buttonClicked (Button* button) override + { + if (button == cancelButton) + { + spinner.setVisible (false); + stopTimer(); + + delete this; + } + } + OnlineUnlockForm& form; Spinner spinner; OnlineUnlockStatus::UnlockResult result; String email, password; + ScopedPointer cancelButton; + JUCE_LEAK_DETECTOR (OnlineUnlockForm::OverlayComp) }; @@ -133,12 +157,14 @@ static juce_wchar getDefaultPasswordChar() noexcept OnlineUnlockForm::OnlineUnlockForm (OnlineUnlockStatus& s, const String& userInstructions, - bool hasCancelButton) + bool hasCancelButton, + bool overlayHasCancelButton) : message (String(), userInstructions), passwordBox (String(), getDefaultPasswordChar()), registerButton (TRANS("Register")), cancelButton (TRANS ("Cancel")), - status (s) + status (s), + showOverlayCancelButton (overlayHasCancelButton) { // Please supply a message to tell your users what to do! jassert (userInstructions.isNotEmpty()); @@ -276,7 +302,7 @@ void OnlineUnlockForm::attemptRegistration() status.setUserEmail (emailBox.getText()); - addAndMakeVisible (unlockingOverlay = new OverlayComp (*this)); + addAndMakeVisible (unlockingOverlay = new OverlayComp (*this, showOverlayCancelButton)); resized(); unlockingOverlay->enterModalState(); } diff --git a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.h b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.h index bc9dd492a5..f1cc22b1dc 100644 --- a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.h +++ b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockForm.h @@ -55,7 +55,8 @@ public: */ OnlineUnlockForm (OnlineUnlockStatus&, const String& userInstructions, - bool hasCancelButton = true); + bool hasCancelButton = true, + bool overlayHasCancelButton = false); /** Destructor. */ ~OnlineUnlockForm(); @@ -81,6 +82,8 @@ private: OnlineUnlockStatus& status; ScopedPointer bubble; + bool showOverlayCancelButton; + struct OverlayComp; friend struct OverlayComp; Component::SafePointer unlockingOverlay;