11#ifndef __AUDACITY_BASIC_UI__
12#define __AUDACITY_BASIC_UI__
39 virtual explicit operator bool()
const;
62 {
modalHelp = modalHelp_;
return std::move(*
this); }
65 {
log = std::move(log_);
return std::move(*
this); }
99 {
parent = parent_;
return std::move(*
this); }
102 {
caption = std::move(caption_);
return std::move(*
this); }
119 {
centered =
true;
return std::move(*
this); }
170 unsigned long long numerator,
171 unsigned long long denominator,
212 virtual std::unique_ptr<ProgressDialog>
217 virtual std::unique_ptr<GenericProgressDialog>
264BASIC_UI_API
void Yield();
280 p->DoShowErrorDialog(placement, dlogTitle, message, helpPage, options);
291 return p->DoMessageBox(message, std::move(options));
309 return p->DoMakeProgress(
title, message, flags, remainingLabelText);
325 return p->DoMakeGenericProgress(placement,
title, message,
style);
338template <
typename ItType,
typename FnType>
343 const auto numIters = std::distance(first, last);
347 parent ? [&](
double progress) { parent((count + progress) / numIters); } :
350 for (; first != last; ++first)
352 action(*first, child);
374 return p->DoMultiDialog(message,
title, buttons, helpPage, boxMsg, log);
386 if (
auto result = p->DoFindFocus())
388 return std::make_unique<WindowPlacement>();
395 p->DoSetFocus(focus);
402 return p->IsUsingRtlLayout();
410 return p->IsUiThread();
414#define ASSERT_MAIN_THREAD() \
416 BasicUI::IsUiThread() && \
417 "This function should only be called on the main thread")
std::vector< TranslatableString > TranslatableStrings
Abstraction of a progress dialog with undefined time-to-completion estimate.
virtual ProgressResult Pulse()=0
Give some visual indication of progress. Call only on the main thread.
virtual ~GenericProgressDialog()
Abstraction of a progress dialog with well defined time-to-completion estimate.
virtual ProgressResult Poll(unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
Update the bar and poll for clicks. Call only on the main thread.
virtual ~ProgressDialog()
virtual void SetMessage(const TranslatableString &message)=0
Change an existing dialog's message.
virtual void SetDialogTitle(const TranslatableString &title)=0
Change the dialog's title.
virtual void Reinit()=0
Reset the dialog state.
Abstract class defines a few user interface services, not mentioning particular toolkits.
virtual std::unique_ptr< WindowPlacement > DoFindFocus()=0
virtual void DoShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options)=0
virtual void DoSetFocus(const WindowPlacement &focus)=0
virtual std::unique_ptr< GenericProgressDialog > DoMakeGenericProgress(const WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message, int style)=0
virtual bool IsUsingRtlLayout() const =0
virtual std::unique_ptr< ProgressDialog > DoMakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flag, const TranslatableString &remainingLabelText)=0
virtual MessageBoxResult DoMessageBox(const TranslatableString &message, MessageBoxOptions options)=0
virtual int DoMultiDialog(const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log)=0
virtual void DoCallAfter(const Action &action)=0
virtual bool DoOpenInDefaultBrowser(const wxString &url)=0
virtual bool IsUiThread() const =0
Subclasses may hold information such as a parent window pointer for a dialog.
virtual ~WindowPlacement()
WindowPlacement()=default
WindowPlacement & operator=(const WindowPlacement &)=delete
Don't slice.
WindowPlacement(const WindowPlacement &)=delete
Don't slice.
Holds a msgid for the translation catalog; may also bind format arguments.
std::function< void(double)> ProgressReporter
TranslatableString DefaultCaption()
"Message", suitably translated
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
std::unique_ptr< GenericProgressDialog > MakeGenericProgress(const WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message, int style=(ProgressAppModal|ProgressShowElapsedTime|ProgressSmooth))
Create and display a progress dialog (return nullptr if Services not installed)
@ ProgressConfirmStopOrCancel
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Services * Install(Services *pInstance)
Install an implementation; return the previously installed instance.
void SplitProgress(ItType first, ItType last, FnType action, ProgressReporter parent)
Helper for the update of a task's progress bar when this task is made of a range's subtasks.
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
bool IsUiThread()
Whether the current thread is the UI thread.
@ Default
Like Ok, except maybe minor difference of dialog position.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
int ShowMultiDialog(const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log)
Display a dialog with radio buttons.
std::function< void()> Action
bool IsUsingRtlLayout()
Whether using a right-to-left language layout.
@ None
May be returned if no Services are installed.
GenericProgressDialogStyle
@ ProgressShowElapsedTime
void Yield()
Dispatch waiting events, including actions enqueued by CallAfter.
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Options for variations of error dialogs; the default is for modal dialogs.
ErrorDialogType type
Type of help dialog.
ErrorDialogOptions()=default
std::wstring log
Optional extra logging information to be shown.
ErrorDialogOptions && ModalHelp(bool modalHelp_) &&
ErrorDialogOptions && Log(std::wstring log_) &&
ErrorDialogOptions(ErrorDialogType type)
Non-explicit.
bool modalHelp
Whether the secondary help dialog with more information should be modal.
MessageBoxOptions && CancelButton() &&
MessageBoxOptions && Parent(WindowPlacement *parent_) &&
TranslatableString caption
bool yesOrOkDefaultButton
MessageBoxOptions && Caption(TranslatableString caption_) &&
MessageBoxOptions && Centered() &&
Center the dialog on its parent window, if any.
MessageBoxOptions && ButtonStyle(Button style) &&
MessageBoxOptions && DefaultIsNo() &&
Override the usual defaulting to Yes; affects only the YesNo case.
MessageBoxOptions && IconStyle(Icon style) &&